]> code.bitgloo.com Git - clyne/sprit-forth.git/commitdiff
add CREATE, DOES>
authorClyne Sullivan <clyne@bitgloo.com>
Sat, 25 Nov 2023 17:40:45 +0000 (12:40 -0500)
committerClyne Sullivan <clyne@bitgloo.com>
Sat, 25 Nov 2023 17:40:45 +0000 (12:40 -0500)
core.fth

index 0650811c127d019429a1ed1dfc855a5c4a262e2c..ec34191713c9ebb8454fc90903b10eace67cd5d2 100644 (file)
--- a/core.fth
+++ b/core.fth
@@ -16,6 +16,7 @@
 : base     [ 0 _d ] literal ;
 : here     [ 1 cells _d ] literal @ ;
 : allot    [ 1 cells _d ] literal +! ;
+: _latest  [ 2 cells _d ] literal ;
 : state    [ 3 cells _d ] literal ;
 : _compxt  [ 4 cells _d ] literal ;
 : _source  [ 5 cells _d ] literal ;
            swap postpone literal postpone literal ; imm
 : ."       postpone s" state @ if ['] type compile, else type then ; imm
 
+: create   : here [ 4 cells ] literal + postpone literal postpone ; 0 , ;
+: >body    cell+ @ ;
+
+: _does>   _latest @ @ [ 4 cells ] literal +
+           ['] _jmp @ over !
+           r@ [ 2 cells ] literal +
+           swap cell+ ! ;
+
+: does>    ['] _does> compile, ['] exit compile, ; imm
+
+: variable create [ 1 cells ] literal allot ;
+: constant create , does> @ ;
+
 : move     dup 0 <= if drop 2drop exit then
            >r 2dup < r> swap if
            1- 0 swap do over i + c@ over i + c! -1 +loop
 
 : fibs 10 0 do i fib . loop cr ;
 
+5 constant five
+five .
 fibs ." hello world"