This week has mainly been working on the compiler. Turns out that a pile of assumptions I had about the architecture are just wrong now I want to easily implement the flow analyzer. I'll rant roughly what is going on below :)
So I have a tree of code that needs compiling. The compiler walks down the tree and compiles each form (which is generally some value, variable or function call). So the compiler can remember what variables and functions exist at that point in the program you have an object called the environment. To implement variables scope I simply copy the environment as it was at the start of the scope, add the new variable/s and then throw it away at the end. Because the stuff outside the scope only see's the original environment it can't accidentally access variables that are out of scope.
This has worked great for ages but now by flow analyser wants the answer to the question "what scope was this variable made in?" and that data has been thrown away.
So to counter that I have been rewriting the compiler to use a tree of environments, something like this:
[o|o]---[o|/] | | ENV-0 [o|o]---[o|/] | | ENV-1 [o|o]---[o|/] | | ENV-2 ENV-3
each environment knows about it's parent, so we can walk up the tree to the environment node where the variable was defined.
Right now I have made the big changes to the compiler to support this and I'm now hunting down bugs, I'm doing this by writing basic tests, so this week is also the first that I am using a proper test framework stefil...which whilst looking for a link I have learned is obsolete :D shit. I'll need to switch again this week then
Last Edited on Mon Nov 16 2015 19:43:33 GMT-0500 (EST)
Super fun little rant-read, will be awesome to see the flow analyzer and the position/space's stuff come together. This little compiler's getting exciting :D
on Tue Nov 17 2015 17:16:18 GMT-0500 (EST)