proxy.golang.org : github.com/skx/simple-vm
package main contains a simple brainfuck interpreter which compiles a program into a series of closures which can then be iterated over in turn and executed. The intent behind this implementation is to show how a reasonably fast and compact interpreter might work, despite being built without the traditional approach of compiling to bytecode and then walking that bytecode via a switch-operation. Bytecode interpreters are certainly faster than AST-walking interpreters however they have the downside that their implementation requires the generation and execution halves to be keep in sync: * Some part of the code emits bytecode for each operation. * Some part of the code "does stuff" for each bytecode opcode. Keeping those two things in sync is annoying overhead, and also the traditional "switch-based" interpretation of bytecode opcodes is slow, especially in golang. The idea implemented here is that we switch our core interpreter loop into merely executing a series of function-pointers over and over again until the program is complete. These function-pointers refer to a series of generated closures which our "compiler" has prepared/created. As each individual closure is short, and almost exclusively branchless, we gain a speedup based on the absence of the cache-busting switch statement we would otherwise be hit by, and we _also_ gain from the lack of code duplication.
Registry
-
Source
- Documentation
- JSON
purl: pkg:golang/github.com/skx/simple-vm
License: BSD-3-Clause
Latest release: 19 days ago
Namespace: github.com/skx
Stars: 13 on GitHub
Forks: 0 on GitHub
See more repository details: repos.ecosyste.ms
Last synced: 19 days ago