: istype? ( obj type -- obj bool )
over = ;
-\ ------ Memory ------
+\ ------ Cons cell memory ------
1000 constant N
create car-cells N allot
cdr-type-cells + @
;
+: set-car! ( obj pair-obj -- )
+ drop dup
+ rot swap car-type-cells + !
+ car-cells + !
+;
+
+: set-cdr! ( obj pair-obj -- )
+ drop dup
+ rot swap cdr-type-cells + !
+ cdr-cells + !
+;
+
: caar car car ;
: cadr cdr car ;
: cdar car cdr ;
: nil 0 nil-type ;
: nil? nil-type istype? ;
-: objvar create 0 , 0 , ;
+: objvar create nil swap , , ;
: value@ ( objvar -- val ) @ ;
: type@ ( objvar -- type ) 1+ @ ;
: setobj ( newobj objvar -- ) dup rot swap 1+ ! ! ;
: fetchobj ( objvar -- obj ) dup @ swap 1+ @ ;
-objvar symbol-table
-nil symbol-table setobj
-
: objeq? ( obj obj -- bool )
rot = -rot = and ;
\ ---- Pre-defined symbols ----
+objvar symbol-table
+
: (create-symbol) ( addr n -- symbol-obj )
dup 0= if
2drop nil
does> dup @ swap 1+ @
;
-create-symbol quote quote
+create-symbol quote quote-symbol
+create-symbol define define-symbol
+create-symbol set! set!-symbol
+
+\ ---- Environments ----
+
+objvar global-environment
+
+: enclosing-env ( env -- env )
+ cdr ;
+
+: first-frame ( env -- frame )
+ car ;
+
+: make-frame ( vars vals -- frame )
+ cons ;
+
+: frame-vars ( frame -- vars )
+ car ;
+
+: frame-vals ( frame -- vals )
+ cdr ;
+
+: add-binding ( var val frame -- )
+;
+
\ ---- Read ----
nextchar [char] ' = if
inc-parse-idx
- quote recurse nil cons cons exit
+ quote-symbol recurse nil cons cons exit
then
eof? if
then ;
: quote? ( obj -- obj bool )
- quote tagged-list? ;
+ quote-symbol tagged-list? ;
: quote-body ( quote-obj -- quote-body-obj )
cadr ;