@ -35,6 +35,7 @@
: _input 4 cells ;
: _input 4 cells ;
: decimal 1 1+ base ! 1010 base ! ;
: decimal 1 1+ base ! 1010 base ! ;
: hex 1 1+ base ! 10000 base ! ;
: ['] ' postpone literal ; i m m
: ['] ' postpone literal ; i m m
: [ 0 state ! ; i m m
: [ 0 state ! ; i m m
@ -42,6 +43,7 @@
: 2r> ['] r> , ['] r> , ['] swap , ; i m m
: 2r> ['] r> , ['] r> , ['] swap , ; i m m
: 2>r ['] swap , ['] >r , ['] >r , ; i m m
: 2>r ['] swap , ['] >r , ['] >r , ; i m m
: 2r@ ['] r> , ['] r> , ['] 2dup , ['] >r , ['] >r , ['] swap , ; i m m
: r@ ['] r> , ['] dup , ['] >r , ; i m m
: r@ ['] r> , ['] dup , ['] >r , ; i m m
: 2! swap over ! cell+ ! ;
: 2! swap over ! cell+ ! ;
@ -53,6 +55,8 @@
: <= - 1- 0< ;
: <= - 1- 0< ;
: > <= 0= ;
: > <= 0= ;
: <> = 0= ;
: <> = 0= ;
: 0<> 0= 0= ;
: 0> 0 > ;
: if ['] _jmp0 , here 0 , ; i m m
: if ['] _jmp0 , here 0 , ; i m m
: then here swap ! ; i m m
: then here swap ! ; i m m
@ -62,6 +66,7 @@
: while swap 1+ swap postpone if -rot ; i m m
: while swap 1+ swap postpone if -rot ; i m m
: repeat ['] _jmp , , if postpone then then ; i m m
: repeat ['] _jmp , , if postpone then then ; i m m
: until ['] _jmp0 , , drop ; i m m
: until ['] _jmp0 , , drop ; i m m
: again postpone repeat ; i m m
: do postpone 2>r here ; i m m
: do postpone 2>r here ; i m m
: unloop postpone 2r> ['] 2drop , ; i m m
: unloop postpone 2r> ['] 2drop , ; i m m
@ -105,6 +110,7 @@
: [char] char postpone literal ; i m m
: [char] char postpone literal ; i m m
: ( begin [char] ) key <> while repeat ; i m m
: ( begin [char] ) key <> while repeat ; i m m
: \ _input @ begin dup 0 > while key drop 1- repeat drop ; i m m
: type begin dup 0 > while swap dup c@ emit char+ swap 1- repeat 2drop ;
: type begin dup 0 > while swap dup c@ emit char+ swap 1- repeat 2drop ;
: s" state @ if ['] _jmp , here 0 , t h e n
: s" state @ if ['] _jmp , here 0 , t h e n
@ -116,18 +122,27 @@
: ." postpone s" state @ if ['] type , else type then ; imm
: ." postpone s" state @ if ['] type , else type then ; imm
: create align here bl word count nip cell+ allot a l i g n
: create align here bl word count nip cell+ allot a l i g n
['] _lit , here 3 cells + , ['] exit , 0 ,
['] _lit , here 3 cells + , ['] exit dup , ,
dup @ 31 & over _latest @ - 6 << or over ! _latest ! ;
dup @ 31 & over _latest @ - 6 << or over ! _latest ! ;
: _latword _latest @
: _latword _latest @
dup @ 31 & + cell+ aligned ;
dup @ 31 & + cell+ aligned ;
: does> _latword 2 cells +
: _ does> _latword 2 cells +
['] _jmp over ! c e l l +
['] _jmp over ! c e l l +
here swap ! ] ;
r@ 1 cells - @ swap ! ;
: does> ['] _jmp , here 2 cells + dup , 2 cells + ,
['] _does> , ['] exit , ; i m m
: >body cell+ @ ;
: >body cell+ @ ;
: compile, postpone literal postpone execute ;
: variable create 1 cells allot ;
: variable create 1 cells allot ;
: constant create , does> ['] @ , postpone ; ;
: constant create , does> @ ;
( TODO fix compile-time does>... above should simply be "does> @ ;" )
: value constant ;
: to ' 4 cells + state @ if postpone literal ['] ! , else ! then ; i m m
: defer create does> @ execute ;
: defer@ >body @ ;
: defer! >body ! ;
: is state @ if postpone ['] postpone defer! else ' defer! then ; i m m
: action-of state @ if postpone ['] postpone defer@ else ' defer@ then ; i m m
-1 constant true
-1 constant true
0 constant false
0 constant false
@ -144,15 +159,17 @@
rot dup @ >r c e l l +
rot dup @ >r c e l l +
rot r> over ! c e l l +
rot r> over ! c e l l +
rot 1- repeat drop 2drop ;
rot 1- repeat drop 2drop ;
: fill ( c-addr u char -- )
: fill -rot begin dup 0 > w h i l e
-rot begin dup 0 > w h i l e
>r 2dup c! char+ r> 1- r e p e a t
>r 2dup c! char+ r> 1- r e p e a t
2drop drop ;
2drop drop ;
: roll dup if swap >r 1- recurse r> swap exit then drop ;
: environment? 2drop false ;
: environment? 2drop false ;
: accept over >r begin dup 0 > w h i l e
: accept over >r begin dup 0 > w h i l e
key dup 32 < i f
key dup 32 < if 2drop 0
2drop r> - 1 chars / 0 e l s e
else dup emit rot 2dup c! char+ nip swap 1- t h e n
dup emit rot 2dup c! char+ nip swap 1- t h e n
repeat drop r> - 1 chars / ;
repeat drop ;
: marker create _latest @ , here , d o e s >
dup @ _latest ! cell+ @ here swap - allot ;