The Lambda Lab
/
projects
/
scheme.forth.jl.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
df155ab
)
Adding environments.
author
Tim Vaughan
<tgvaughan@gmail.com>
Sat, 16 Jul 2016 02:04:05 +0000
(14:04 +1200)
committer
Tim Vaughan
<tgvaughan@gmail.com>
Sat, 16 Jul 2016 23:46:27 +0000
(11:46 +1200)
scheme.4th
patch
|
blob
|
history
diff --git
a/scheme.4th
b/scheme.4th
index
6d56d64
..
825ba58
100644
(file)
--- a/
scheme.4th
+++ b/
scheme.4th
@@
-16,7
+16,7
@@
include defer-is.4th
: istype? ( obj type -- obj bool )
over = ;
: istype? ( obj type -- obj bool )
over = ;
-\ ------
M
emory ------
+\ ------
Cons cell m
emory ------
1000 constant N
create car-cells N allot
1000 constant N
create car-cells N allot
@@
-50,6
+50,18
@@
variable nextfree
cdr-type-cells + @
;
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 ;
: caar car car ;
: cadr cdr car ;
: cdar car cdr ;
@@
-58,7
+70,7
@@
variable nextfree
: nil 0 nil-type ;
: nil? nil-type istype? ;
: nil 0 nil-type ;
: nil? nil-type istype? ;
-: objvar create
0 , 0
, ;
+: objvar create
nil swap ,
, ;
: value@ ( objvar -- val ) @ ;
: type@ ( objvar -- type ) 1+ @ ;
: value@ ( objvar -- val ) @ ;
: type@ ( objvar -- type ) 1+ @ ;
@@
-67,14
+79,13
@@
variable nextfree
: setobj ( newobj objvar -- ) dup rot swap 1+ ! ! ;
: fetchobj ( objvar -- obj ) dup @ swap 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 ----
: objeq? ( obj obj -- bool )
rot = -rot = and ;
\ ---- Pre-defined symbols ----
+objvar symbol-table
+
: (create-symbol) ( addr n -- symbol-obj )
dup 0= if
2drop nil
: (create-symbol) ( addr n -- symbol-obj )
dup 0= if
2drop nil
@@
-104,7
+115,32
@@
nil symbol-table setobj
does> dup @ swap 1+ @
;
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 ----
\ ---- Read ----
@@
-514,7
+550,7
@@
defer read
nextchar [char] ' = if
inc-parse-idx
nextchar [char] ' = if
inc-parse-idx
- quote recurse nil cons cons exit
+ quote
-symbol
recurse nil cons cons exit
then
eof? if
then
eof? if
@@
-548,7
+584,7
@@
defer read
then ;
: quote? ( obj -- obj bool )
then ;
: quote? ( obj -- obj bool )
- quote tagged-list? ;
+ quote
-symbol
tagged-list? ;
: quote-body ( quote-obj -- quote-body-obj )
cadr ;
: quote-body ( quote-obj -- quote-body-obj )
cadr ;