;; M-Eval input:
At this point you can start entering Scheme commands... but be prepared to wait
-a while for the result. After all, when evaluating commands in the MCE you are
+a while for each result. After all, when evaluating commands in the MCE you are
running a program in a Scheme interpreter running inside another Scheme
interpreter which is itself running on a Forth system that is implemented atop
-the Julia numerical computing environment. **That's three levels of
-abstraction more than a native Julia program experiences**, so some delay is to
-be expected!
+a virtual register machine running in the Julia numerical computing
+environment. **That's four levels of abstraction more than a native Julia
+program experiences**, so some delay is to be expected!
For instance, the following example from SICP defines and demonstrates a
recursive list append procedure:
defer read
defer expand
+defer analyze
defer eval
defer print
\ }}}
+\ ---- Analyze ----
+
+: evaluate-eproc ( env eproc --- res )
+ begin
+ nil? invert
+ while
+ 2dup car
+ 2swap cdr
+ repeat
+
+ 2drop \ get rid of null
+
+ \ Final element of eproc list is primitive procedure
+ drop \ dump type signifier
+ R> drop >body >R \ GOTO primitive procedure (executor)
+;
+
+: self-evaluating-executor ( env exp -- exp )
+ 2swap 2drop ;
+
+: analyze-self-evaluating ( exp --- eproc )
+ ['] self-evaluating-executor primitive-proc-type
+ nil cons cons
+;
+
+: quote-executor ( env exp -- exp )
+ 2swap 2drop ;
+
+: analyze-quoted ( exp -- eproc )
+ quote-body
+
+ ['] quote-executor primitive-proc-type
+ nil cons cons
+;
+
+: variable-executor ( env var -- val )
+ 2swap lookup-var ;
+
+: analyze-variable ( exp -- eproc )
+ ['] variable-executor primitive-proc-type
+ nil cons cons
+;
+
+: assignment-executor ( env var val-eproc -- ok )
+ 2rot 2dup 2rot ( var env env val-eproc )
+ evaluate-eproc 2swap ( var val env )
+ set-var
+ ok-symbol ;
+
+: analyze-assignment ( exp -- eproc )
+ 2dup assignment-var
+ 2swap assignment-val analyze ( var val-eproc )
+
+ ['] assignment-executor primitive-proc-type
+ nil cons cons cons
+;
+
+:noname ( exp --- eproc )
+
+ self-evaluating? if
+ analyze-self-evaluating
+ exit
+ then
+
+ quote? if
+ analyze-quoted
+ exit
+ then
+
+ variable? if
+ analyze-variable
+ exit
+ then
+
+ assignment? if
+ analyze-assignment
+ exit
+ then
+
+; is analyze
+
+
\ ---- Macro Expansion ---- {{{
( Simply evaluates the given procedure with expbody as its argument. )
include scheme-primitives.4th
- s" scheme-library.scm" load 2drop
+ \ s" scheme-library.scm" load 2drop
\ }}}
enable-gc
\ Display welcome message
- welcome-symbol nil cons global-env obj@ eval 2drop
+ \ welcome-symbol nil cons global-env obj@ eval 2drop
begin
['] repl-body catch