A tree-walk interpreter for the Lox language, based on the first half of the book, Crafting Interpreters by Robert Nystorm.
cabal run liquid-oxygencabal run liquid-oxygen <script>Will be optimized further.
[Char](String) is just a linked list of characters, which is inefficient.- Alternatives like
Text(fromtext) orByteString(frombytestring) are much faster and more memory-efficient. - Similarly, for other linked list operations, other structures like
VectororSeqcan offer better performance depending on use case.
- The original implementation uses a
localsmap to track only local variable resolutions. - My implementation uses
distances, which uniformly tracks local and global by their scope depth.
- Only
modifyIORef(lazy) works forinitializedue to Functions, because closures depend on lazily init envs and may involve cyclic refs (mdo/fixIO). atomicModifyIORef(strict) seems to work safely forassignAt, since assignment happens after eval and does not involve cyclic structs.