X-Git-Url: https://git.kengrimes.com/?p=watForth.git;a=blobdiff_plain;f=forth.wat;h=61cbb2238a83b51ed204844b6302a1d782a55e92;hp=0c4b767e5706af4487112c17cd8ea279d22e4331;hb=63e17ddc993a5a04cc6ae55bad8420b61c37d1bf;hpb=1b642df6dc1da4bdbe2c389899bb4be072bc0b1e diff --git a/forth.wat b/forth.wat index 0c4b767..61cbb22 100644 --- a/forth.wat +++ b/forth.wat @@ -15,8 +15,10 @@ (type $FUNCSIGii (func (param i32))) (type $FUNCSIGiii (func)) (type $FUNCSIGiv (func (param i32 i32) (result i32))) - (type $FUNCSIG$v (func (param i32) (result i32))) - (type $FUNCSIG$vi (func (param i32 i32 i32) (result i32))) + (type $FUNCSIGv (func (param i32) (result i32))) + (type $FUNCSIGvi (func (param i32 i32 i32) (result i32))) + (type $FUNCSIGvii (func (param i32 i32))) + (type $FUNCSIGviii (func (param i32 i32 i32))) (import "env" "pop" (func $pop (result i32))) (import "env" "push" (func $push (param i32))) (import "env" "rinit" (func $rinit)) @@ -30,7 +32,9 @@ (import "env" "sys_echochar" (func $sys_echochar (param i32))) (import "env" "sys_reflect" (func $sys_reflect (param i32))) (import "env" "vocab_get" (func $vocab_get (param i32 i32) (result i32))) - (import "env" "vocab_set" (func $vocab_set (param i32 i32 i32) (result i32))) + (import "env" "vocab_set" (func $vocab_set (param i32 i32 i32))) + (import "env" "does_get" (func $does_get (param i32) (result i32))) + (import "env" "does_set" (func $does_set (param i32 i32))) (import "env" "is_whitespace" (func $is_whitespace (param i32) (result i32))) (import "env" "sys_parsenum" (func $sys_parsenum (param i32 i32 i32) (result i32))) (import "env" "sys_stack" (func $sys_stack)) @@ -46,7 +50,7 @@ (data (i32.const 12288) "\f8\07\00\00") ;; 2040 len (data (i32.const 14336) "\28\41\00\00") ;; MODE (data (i32.const 14340) "\04\42\00\00") ;; HERE - (data (i32.const 14344) "\00\40\00\00") ;; START + (data (i32.const 14344) "\00\40\00\00") ;; START (16384) (Quit) (data (i32.const 14348) "\0a\00\00\00") ;; BASE (data (i32.const 14352) "\00\00\00\00") ;; STRINGBELT_TAIL (data (i32.const 14356) "\00\00\00\00") ;; STRINGBELT_HEAD @@ -108,13 +112,13 @@ (data (i32.const 16628) "\17\00\00\00") ;; WORDFINISH (data (i32.const 16632) "\01\00\00\00") ;; RET (; Exec Mode ;) - (data (i32.const 16680) "\1e\00\00\00") ;; DUP2 + (data (i32.const 16680) "\1e\00\00\00") ;; 2DUP (data (i32.const 16684) "\15\00\00\00") ;; DICT_GET (data (i32.const 16688) "\06\00\00\00") ;; DUP (data (i32.const 16692) "\0e\00\00\00") ;; JZ: (data (i32.const 16696) "\4c\41\00\00") ;; donum -1 (16716) (data (i32.const 16700) "\1f\00\00\00") ;; ROT - (data (i32.const 16704) "\20\00\00\00") ;; DROP2 + (data (i32.const 16704) "\20\00\00\00") ;; 2DROP (data (i32.const 16708) "\0c\00\00\00") ;; EXECUTE (data (i32.const 16712) "\01\00\00\00") ;; RET (data (i32.const 16716) "\10\00\00\00") ;; DROP (xt from dictionary) @@ -124,9 +128,17 @@ (data (i32.const 16732) "\68\41\00\00") ;; donum_err (16744) (data (i32.const 16736) "\10\00\00\00") ;; DROP (data (i32.const 16740) "\01\00\00\00") ;; RET - (data (i32.const 16744) "\10\00\00\00") ;; PARSE_ERR <-- donum_err - (data (i32.const 16748) "\10\00\00\00") ;; ( DROP DROP ) - (data (i32.const 16752) "\19\00\00\00") ;; BYE + (data (i32.const 16744) "\20\00\00\00") ;; 2DROP <-- donum_err + (data (i32.const 16748) "\02\00\00\00") ;; LIT + (data (i32.const 16752) "\04\30\00\00") ;; INBUFSIZE LOCATION + (data (i32.const 16756) "\02\00\00\00") ;; LIT + (data (i32.const 16760) "\00\00\00\00") ;; 0 + (data (i32.const 16764) "\0b\00\00\00") ;; ! + (data (i32.const 16768) "\19\00\00\00") ;; BYE + (data (i32.const 16772) "\00\00\00\00") ;; + (data (i32.const 16776) "\00\00\00\00") ;; + (data (i32.const 16780) "\00\00\00\00") ;; + (data (i32.const 16784) "\00\00\00\00") ;; (; Do Backslash ;) (data (i32.const 16788) "\05\00\00\00") ;; KEY (data (i32.const 16792) "\11\00\00\00") ;; WS? @@ -202,7 +214,8 @@ block $dictget block $parsenum block $wordfinish block $jneg1 block $swap block $words block $here block $dictset block $dup2 block $rot block $drop2 block $comma block $subtract block $keychan block $sethere block $eqbool - block $echostring block $strstart block $strput block $strend + block $echostring block $strstart block $strput block $strend block $fetchinc + block $setinc block $finddoes block $definedoes get_local $eax br_table $op0 $ret (;2;)$lit $rinit (;4;)$word $key (;6;)$dup $plus (;8;)$jmp $emit (;10;)$fetch $set (;12;)$execute $noop (;14;)$jz $jnz @@ -210,7 +223,42 @@ (;22;)$parsenum $wordfinish (;24;)$jneg1 $bye (;26;)$swap $words (;28;)$here $dictset (;30;)$dup2 $rot (;32;)$drop2 $comma (;34;)$subtract $keychan (;36;)$sethere $eqbool (;38;)$echostring $strstart - (;40;)$strput $strend $default + (;40;)$strput $strend (;42;)$fetchinc $setinc (;44;)$finddoes $definedoes + (;46;)$default + end ;; definedoes + call $pop + set_local $eax + call $pop + get_local $eax + call $does_set + br $next + end ;; finddoes + call $pop + call $does_get + call $push + br $next + end ;; setinc + call $pop + call $rpush + call $pop + tee_local $eax + call $rpop + i32.store + get_local $eax + i32.const 4 + i32.add + call $push + br $next + end ;; fetchinc + call $pop + tee_local $eax + i32.const 4 + i32.add + call $push + get_local $eax + i32.load + call $push + br $next end ;; strend get_local $stringbelt_tail get_local $stringbelt_head @@ -395,7 +443,6 @@ get_local $eax call $rpop call $vocab_set - drop br $next end ;; here get_local $here @@ -691,7 +738,7 @@ br $next end ;; op0 get_local $esi - call $sys_reflect + call $rpush br $bye end ;; default get_local $esi @@ -700,7 +747,7 @@ set_local $esi br $next end ;; execloop - end ;; nextl + end ;; next loop end ;; bye i32.const 14340 get_local $here @@ -721,5 +768,6 @@ get_local $channel i32.store i32.const 0 + return ) )