json testing
[watForth.git] / forth.forth
index fb04e4d..8f609d7 100644 (file)
@@ -34,11 +34,15 @@ word DEFINE-DOES 45 define
 word QUIT 16384 define
 word BYE 25 define
 word WORDS 27 define
-word !CHANNEL 35 define
+word CHANNEL-IN 35 define
+word CHANNEL-OUT 48 define
+word CHANNEL-OPEN 51 define
+word CHANNEL-AWAIT 50 define
 word !HERE 36 define
 word HERE 28 define
 
 word STACKTRACE 46 define
+word FETCH 47 define
 
 word ; 1 define
 word JZ: 14 define
@@ -53,6 +57,7 @@ word WS? 17 define
 word . 9 define
 word .S 38 define
 word @ 10 define
+word @8_u 53 define
 word @+ 42 define
 word ! 11 define
 word !+ 43 define
@@ -83,18 +88,19 @@ word ::> here define
 ' word , ' 2dup , ' here , ' define-does , ' here , ' define , ' ; ,
 
 \ write the execution semantics of a word to memory
-: MEMORIZE-WORD ' dup , ' JNZ: , here 12 + , ' 2drop , ' ; ,
+: MEMORIZE-WORD ' dup , ' JNZ: , here 12 + , ' 2drop , ' ; , 
 ' 2dup , ' find , ' dup , ' JZ: , here 16 + , ' , , ' 2drop , ' ; ,
-' drop , ' lit , ' lit , ' , , ' execute-num , ' , , ' ; ,
+' drop , ' lit , ' lit , ' , , ' execute-num , ' , , ' ; , 
 
 \ change interpreter semantics to "memorize-word"
-: memorizing ' lit , ' mode , ' lit , ' memorize-word , ' ! , ' ; ,
+::> MEMORIZING ' lit , ' mode , ' lit , ' memorize-word , ' ! , ' ; ,
 
 \ memorize the compiler
 \memorizing
 \: executing lit mode lit execute-word ! ;
 \: FINISH-" drop string-end ;
-\: " string-start \: KLOOP key 34 =? JNZ: finish-" string-put JMP: KLOOP
+\: 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 ! ;
@@ -134,13 +140,45 @@ 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 ! ;
-
 (
   End of bootstrap process
   beyond this point, all hope is lost
 )
 
+\ Set the number conversion base
+: BASE 14348 swap ! ;
+: BASE10 10 base ;
+
+\ TICK compilation semantics
+:> ' lit lit , word find , ;
+\ "TICK DOES" (get compilation semantics execution token)
+: '> word find-does ;
+:> '> word find-does , ;
+
+\ CHAR 
+: CHAR: word drop @8_u ;
+:> CHAR: lit lit , ' char: execute , ;
+
+\ JSON Compiler
+: JSON-CTRL-CHAR? char: { =? if 1 ;; then
+                  char: } =? if 1 ;; then
+                  char: [ =? if 1 ;; then
+                  char: ] =? if 1 ;; then
+                  0 ;
+: JSON-PARSE-V ;
+: JSON-PARSE-" ;
+: JSON-PARSE-[ ;
+: JSON-PARSE-{ ;
+: JSON-WORD word-start key JSON-CTRL-CHAR? if word-end ;; then ws?   ;
+
+: JSON{ key ; 
+
+\ 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