ref: e3ea9b9b3ff5b87f50cb7990ccdc5004a35caddc scheme-vm/spec/compiler_spec.rb -rw-r--r-- 38.4 KiB
Fix the map function so it handles multiple list args

This work exposed a serious flaw in my approach to the compiler. Up
until now I could get away with fundamentals like `car`, `cdr`, etc.
being macros, compiled directly into vm instructions. But that's not
right; these can be passed around like lambdas in Scheme, so I need to
rethink my approach.

The dirty hack I used here is to wrap the macro in a lambda, but that is
SLOW! The test suite now takes nearly twice as long to run.
Some small fixes to loading/including libraries
Refactor for easier porting/debugging

* Remove code paths that allow parsing/compiling/executing *additional* code
  subsequent to initializing the object.
* Remove caching of standard library in specs to feel the full pain of slow
* Move parsing of code responsibility back up to the Program object --
  Compiler delegates back up to the parent Program if it needs to parse
  new code. This separation of concerns could be further improved.
Support all character names in the spec
Fix bug compiling an empty list
Add continuations and call/cc
Give macro definitions referential transparency

...and fix a handful of other variable and macro scoping issues
Fix bug when importing a name that doesn't exist
Rearrange vm opcodes

* Rename ops to better match how they are used.
* Arrange opcodes alphabetically because I'm tired of
  agonizing over their ordering :-)
Build Char from stack value
Remove CMP_EQV from vm -- implemented in scheme now
Remove CMP_EQ_NUM vm instruction
Don't leave strings on the stack if unused
Improve spec
Add undefined to vm

Also make `if` without an else value return undefined (Ruby nil for now),
which ensures unrelated values are not popped off the stack.
Consolidate specs
Speed up specs with cached compiler
Make assert a library and fix some namespace bugs
Move if and some math stuff into base library
Move define-syntax into base library
Move apply into base library