mirror of
https://github.com/kanaka/mal.git
synced 2024-10-26 22:28:26 +03:00
8a19f60386
- Reorder README to have implementation list after "learning tool" bullet. - This also moves tests/ and libs/ into impls. It would be preferrable to have these directories at the top level. However, this causes difficulties with the wasm implementations which need pre-open directories and have trouble with paths starting with "../../". So in lieu of that, symlink those directories to the top-level. - Move the run_argv_test.sh script into the tests directory for general hygiene.
39 lines
828 B
Forth
39 lines
828 B
Forth
require types.fs
|
|
|
|
MalType%
|
|
cell% field MalEnv/outer
|
|
cell% field MalEnv/data
|
|
deftype MalEnv
|
|
|
|
: MalEnv. { outer -- env }
|
|
MalEnv new { env }
|
|
outer env MalEnv/outer !
|
|
MalMap/Empty env MalEnv/data !
|
|
env ;
|
|
|
|
: env/set { key val env -- }
|
|
key val env MalEnv/data @ assoc
|
|
env MalEnv/data ! ;
|
|
|
|
: env/get-addr { key env -- val-addr }
|
|
env
|
|
begin ( env )
|
|
key over MalEnv/data @ MalMap/get-addr ( env addr-or-0 )
|
|
?dup 0= if ( env )
|
|
MalEnv/outer @ dup 0= ( env-or-0 done-looping? )
|
|
else ( env addr )
|
|
nip -1 \ found it! ( addr -1 )
|
|
endif
|
|
until ;
|
|
|
|
MalEnv
|
|
extend pr-buf { env }
|
|
env MalEnv/data @ pr-buf
|
|
a-space s" outer: " str-append
|
|
env MalEnv/outer @ ?dup 0= if
|
|
s" <none>" str-append
|
|
else
|
|
pr-buf
|
|
endif ;;
|
|
drop
|