channels working
[watForth.git] / forth.forth
index dce37c5..2f9ff87 100644 (file)
@@ -57,6 +57,7 @@ word WS? 17 define
 word . 9 define
 word .S 38 define
 word @ 10 define
+word @8u 53 define
 word @+ 42 define
 word ! 11 define
 word !+ 43 define
@@ -67,6 +68,7 @@ word DROP 16 define
 word 2DROP 32 define
 word SWAP 26 define
 word ROT 31 define
+word -ROT 54 define
 
 \ ' "TICK" returns address of word's execution semantics
 word ' here define
@@ -92,18 +94,18 @@ word ::> here define
 ' drop , ' lit , ' lit , ' , , ' execute-num , ' , , ' ; , 
 
 \ change interpreter semantics to "memorize-word"
-: memorizing ' lit , ' mode , ' lit , ' memorize-word , ' ! , ' ; ,
+::> MEMORIZING ' lit , ' memorize-word , ' lit , ' mode , ' ! , ' ; ,
 
 \ memorize the compiler
 \memorizing
-\: executing lit mode lit execute-word ! ;
+\: executing lit execute-word lit mode ! ;
 \: FINISH-" drop string-end ;
 \: BSLASH-" drop key string-put JMP: \here \8 \+ \,
 \: " string-start \: KLOOP key 92 =? JNZ: bslash-" 34 =? JNZ: finish-" string-put JMP: KLOOP
 \: DO"    \:> " " swap lit lit , , lit lit , , ;
 \: DOIF   \:> IF lit JZ: , here dup , ;
-\: DOELSE \:> ELSE lit JMP: , here dup , swap here ! ;
-\: DOTHEN \:> THEN here ! ;
+\: DOELSE \:> ELSE lit JMP: , here dup , here -rot ! ;
+\: DOTHEN \:> THEN here swap ! ;
 \: COMPILE-WORD dup
 \doif 2dup find-does dup
   \doif rot 2drop execute ;
@@ -111,7 +113,7 @@ word ::> here define
   \doif , 2drop ;
   \dothen drop lit lit , execute-num , ;
 \dothen 2drop \do" Compilation Error: null word" .s bye
-\: compiling lit mode lit compile-word ! ;
+\: compiling lit compile-word lit mode ! ;
 
 \ compile the rest of the compiler
 \compiling
@@ -139,15 +141,27 @@ here define-does then compiling ;
 \ Multi-line comments
 ::> ( key 41 =? swap -1 =? swap drop + if ;; then JMP: \' ( \, ;
 
-\ Set the number conversion base
-: BASE 14348 swap ! ;
-: BASE10 10 base ;
-
 (
   End of bootstrap process
   beyond this point, all hope is lost
 )
 
+\ Set the number conversion base
+: BASE 14348 ! ;
+: BASE10 10 base ;
+
+\ TICK compilation semantics
+:> ' lit lit , word find , ;
+\ "TICK DOES" (get compilation semantics execution token)
+: '> word find-does ;
+:> '> word find-does , ;
+
+\ Include a remote file
+: REQUIRE" ' quit channel-open dup \' " \, fetch channel-await ;
+
+\ Let's try it
+REQUIRE" { \"url\": \"forth/test-watfor.forth\" }"
+
 \ Print intro string
 " watForth-32 Interactive CLI:
 " .s