scheme.forth.jl
---------------
-A hobby scheme implementation for FORTH 83. Specifically it is targeted at
+A hobby scheme interpreter for FORTH 83. Specifically it is targeted at
[forth.jl](http://github.com/tgvaughan/forth.jl) which is an implementation
of FORTH on top of [Julia](http://www.julialang.org), hence the name.
At the moment it is a fairly direct port of Peter Micheaux's [Bootstrap
;
: pairlike-marked? ( obj -- obj bool )
- over nextfrees + 0=
+ over nextfrees + @ 0=
;
: mark-pairlike ( obj -- obj )
over nextfrees + 0 swap !
;
+: gc-unmark ( -- )
+ scheme-memsize 0 do
+ 1 nextfrees i + !
+ loop
+;
+
+defer gc-mark-trace
: gc-mark-obj ( obj -- )
+ gc-mark-trace
+
pairlike? invert if 2drop exit then
pairlike-marked? if 2drop exit then
nextfree @ nextfrees i + !
i nextfree !
then
- -1 +loop ;
+ -1 +loop
+;
\ }}}
+
+
\ ---- Pre-defined symbols ---- {{{
objvar symbol-table
\ }}}
+\ ---- DEBUGGING ---- {{{
+
+false value debug-mode
+
+:noname
+ debug-mode if
+ ." Object: " 2dup cr print cr
+ ." Pairlike: " pairlike? if
+ ." TRUE"
+ pairlike-marked? if
+ ." (Marked)"
+ else
+ ." (Unmarked)"
+ then
+ else
+ ." FALSE"
+ then
+ cr ." [paused]"
+ key drop cr
+ then
+; is gc-mark-trace
+
+: gc-mark-sweep
+ gc-unmark
+ symbol-table obj@ gc-mark-obj
+ global-env obj@ gc-mark-obj
+ gc-sweep
+;
+
+: gc-count-marked
+ 0
+ scheme-memsize 0 do
+ nextfrees i + @ 0= if 1+ then
+ loop
+;
+
+: gc-zero-unmarked
+ scheme-memsize 0 do
+ nextfrees i + @ 0<> if
+ 0 car-cells i + !
+ 0 cdr-cells i + !
+ then
+ loop
+;
+
+\ }}}
+
+
\ ---- REPL ----
: repl