summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--readme.md12
-rw-r--r--sanctuary.fs8
-rw-r--r--sanctuary.s1
3 files changed, 19 insertions, 2 deletions
diff --git a/readme.md b/readme.md
index c9e5323..d21df82 100644
--- a/readme.md
+++ b/readme.md
@@ -253,6 +253,14 @@ bytes are copied in high memory to low memory order.
### `compile, ( xt -- )`
compile a call to xt into user memory.
+### `constant ( u "name" -- )`
+create a word that pushes a cell value u to the stack.
+
+### `create ( "name" -- )`
+create a word in the dictionary that, by default,
+pushes the address directly following the header to the stack.
+this behaviour can be modified with `does>`.
+
### `d, ( n -- )`
write a 32 bit value to user memory and increment the user memory pointer.
@@ -262,6 +270,10 @@ store the 32 bit value u into the memory address a.
### `decimal ( -- )`
set current base to decimal.
+### `does> ( -- )`
+modify the behaviour of the most recent `create`d word.
+(non-`create`d words will be corrupted.)
+
### `dp ( -- a )`
a variable that contains the lowest free byte of memory in user memory.
diff --git a/sanctuary.fs b/sanctuary.fs
index b0867d1..eea702f 100644
--- a/sanctuary.fs
+++ b/sanctuary.fs
@@ -32,7 +32,11 @@
: postpone 'h ( word ) dup immediate? if >body compile,
else >body [compile] literal ['] compile, compile, then ; immediate
-\ my plan is that (CREATE) is followed by a dummy zero cell
-\ which (DOES>) uses. waste of 8 bytes but it's simpler
: create parse-name (header) latest ! ['] (create) compile, 0 , ;
+: does> latest @ >body 2 + ['] (does>) over ! \ replace call loc
+ ( replace destination ) 11 + r> swap ! ;
+ ( the lone r> means we don't execute the rest of the word now, )
+ ( but it is actually compiled into the definition and is jumped to )
+ ( by a create does> made word )
+: constant create , does> @ ;
bye
diff --git a/sanctuary.s b/sanctuary.s
index 8fe545d..a209303 100644
--- a/sanctuary.s
+++ b/sanctuary.s
@@ -48,6 +48,7 @@
%2: dq %4
defdict %1, %2, %3
pspush qword %2
+ ret
%endmacro
; }}}