Introducing hopping in the ast-walk interpreter

In the ast-walk interpreter, the code is executed by node on node. How can I implement functions like goto, break or continue? Am I stopping current execution and moving to another node? Are there any better methods?

+4
source share
1 answer

Best practice is "do not interpret AST for languages ​​with gotos".

In essence, any type of gap in a tree leads to a serious slowdown if the language processes mainly scalars. (If your language processes complex values ​​mainly, for example, the APL of an array, that doesn't matter).

The best you can hope for is to first deal with the tree and determine where the actual addresses go to the AST, and write it in the associative cache to the side. Then, when you come across goto, just consult the cache, not look at it.

But this is the first step down the path to compilation, for example, to pre-compute what you can before you execute.

+4
source

All Articles