3 ms·
I put together this example after reading the article: https://github.com/skx/simple-vm https://github.com/skx/simple-vm Simpler than the full gomacro codebas
by stevekemp 2y ago
I put together this example after reading the article:
https://github.com/skx/simple-vm https://github.com/skx/simple-vm
Simpler than the full gomacro codebase, but perhaps helpful.
- cosmos0072 2y agoFor optimal speed, you should move as much code as possible outside the closures. In particular, you should do the `switch op` at https://github.com/skx/simple-vm/blob/b3917aef0bd6c4178eed0c2be3cd0ab26b5be803/main.go#L81 https://github.com/skx/simple-vm/blob/b3917aef0bd6c4178eed0c... outside the closure, and create a different, specialised closure for each case. Otherwise the "fast interpreter" may be almost as slow as a vanilla AST walker.
- stevekemp 2y agoThat's fair, thanks for taking the time to look and giving the feedback.