1 (; This program is free software: you can redistribute it and/or modify
2 it under the terms of the GNU General Public License as published by
3 the Free Software Foundation, either version 3 of the License, or
4 (at your option) any later version.
6 This program is distributed in the hope that it will be useful,
7 but WITHOUT ANY WARRANTY; without even the implied warranty of
8 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 GNU General Public License for more details.
11 You should have received a copy of the GNU General Public License
12 along with this program. If not, see <http://www.gnu.org/licenses/>. ;)
14 (type $FUNCSIGi (func (result i32)))
15 (type $FUNCSIGii (func (param i32)))
16 (type $FUNCSIGiii (func))
17 (type $FUNCSIGiv (func (param i32 i32) (result i32)))
18 (type $FUNCSIGv (func (param i32) (result i32)))
19 (type $FUNCSIGvi (func (param i32 i32 i32) (result i32)))
20 (type $FUNCSIGvii (func (param i32 i32)))
21 (type $FUNCSIGviii (func (param i32 i32 i32)))
22 (import "env" "pop" (func $pop (result i32)))
23 (import "env" "push" (func $push (param i32)))
24 (import "env" "rinit" (func $rinit))
25 (import "env" "rpop" (func $rpop (result i32)))
26 (import "env" "rpush" (func $rpush (param i32)))
27 (import "env" "sys_read" (func $sys_read (param i32 i32 i32) (result i32)))
28 (import "env" "sys_write" (func $sys_write (param i32 i32 i32)))
29 (import "env" "sys_send" (func $sys_send (param i32 i32 i32)))
30 (import "env" "sys_open" (func $sys_open (result i32)))
31 (import "env" "sys_close" (func $sys_close (param i32)))
32 (import "env" "sys_fetch" (func $sys_fetch (param i32 i32 i32) (result i32)))
33 (import "env" "sys_connect" (func $sys_connect (param i32 i32) (result i32)))
34 (import "env" "sys_echo" (func $sys_echo (param i32)))
35 (import "env" "sys_log" (func $sys_log (param i32 i32)))
36 (import "env" "sys_reflect" (func $sys_reflect (param i32)))
37 (import "env" "vocab_get" (func $vocab_get (param i32 i32) (result i32)))
38 (import "env" "vocab_set" (func $vocab_set (param i32 i32 i32)))
39 (import "env" "does_get" (func $does_get (param i32 i32) (result i32)))
40 (import "env" "does_set" (func $does_set (param i32 i32 i32)))
41 (import "env" "is_whitespace" (func $is_whitespace (param i32) (result i32)))
42 (import "env" "sys_parsenum" (func $sys_parsenum (param i32 i32) (result i32)))
43 (import "env" "sys_stack" (func $sys_stack))
44 (import "env" "sys_words" (func $sys_words))
45 (table (;0;) 0 anyfunc)
47 (; String Belt ;) ;; 0x0000 Size: 8192
48 (global $wordbelt_base i32 (i32.const 8192) ) ;; 0x2000 Size: 4096
49 (global $wordbelt_bound i32 (i32.const 12288)) ;; 0x3000
50 (global $stdin_base i32 (i32.const 12288)) ;; 0x3000 Size: 2048
51 (global $kvars i32 (i32.const 14336)) ;; 0x3800 Size: 2048
52 (global $mode_p i32 (i32.const 14336))
53 (global $here_p i32 (i32.const 14340))
54 (global $start_p i32 (i32.const 14344))
55 (global $base_p i32 (i32.const 14348))
56 (global $stringbelt_tail_p i32 (i32.const 14352))
57 (global $stringbelt_head_p i32 (i32.const 14356))
58 (global $wordbelt_tail_p i32 (i32.const 14360))
59 (global $wordbelt_head_p i32 (i32.const 14364))
60 (data (i32.const 14336) "\28\41\00\00") ;; MODE
61 (data (i32.const 14340) "\04\5e\00\00") ;; HERE
62 (data (i32.const 14344) "\00\40\00\00") ;; START (16384) (Quit)
63 (data (i32.const 14348) "\0a\00\00\00") ;; BASE
64 (data (i32.const 14352) "\00\00\00\00") ;; STRINGBELT_TAIL
65 (data (i32.const 14356) "\00\00\00\00") ;; STRINGBELT_HEAD
66 (data (i32.const 14360) "\00\20\00\00") ;; WORDBELT_TAIL
67 (data (i32.const 14364) "\00\20\00\00") ;; WORDBELT_HEAD
69 (global $quit_p i32 (i32.const 16384)) ;; 0x4000
70 (data (i32.const 16384) "\03\00\00\00") ;; RINIT xt
71 (global $quit_ret_p i32 (i32.const 16388))
72 (data (i32.const 16388) "\10\40\00\00") ;; INTERPRET xt
73 (data (i32.const 16392) "\12\00\00\00") ;; JMP xt
74 (data (i32.const 16396) "\00\40\00\00") ;; quit location (16384)
76 (data (i32.const 16400) "\74\40\00\00") ;; WORD xt (16500)
77 (data (i32.const 16404) "\0d\00\00\00") ;; (data (i32.const 16404) "\1e\00\00\00") ;; 2DUP
78 (data (i32.const 16408) "\0d\00\00\00") ;; (data (i32.const 16408) "\04\00\00\00") ;; SYS-LOG
79 (data (i32.const 16412) "\06\00\00\00") ;; DUP
80 (data (i32.const 16416) "\0e\00\00\00") ;; JZ:
81 (data (i32.const 16420) "\40\40\00\00") ;; INTERP-END addr (16444)
82 (data (i32.const 16424) "\02\00\00\00") ;; LIT xt
83 (data (i32.const 16428) "\00\38\00\00") ;; MODE addr (14336)
84 (data (i32.const 16432) "\0a\00\00\00") ;; @ (fetch) xt
85 (data (i32.const 16436) "\0c\00\00\00") ;; EXECUTE xt
86 (data (i32.const 16440) "\0d\00\00\00") ;; NOOP xt
87 (data (i32.const 16444) "\01\00\00\00") ;; RET
88 (data (i32.const 16448) "\10\00\00\00") ;; DROP <-- INTERP-END
89 (data (i32.const 16452) "\10\00\00\00") ;; DROP
90 ;; (data (i32.const 16456) "\01\00\00\00") ;; RET
91 (global $holy_bye i32 (i32.const 16456))
92 (data (i32.const 16456) "\19\00\00\00") ;; BYE <-- the Holy BYE
94 (data (i32.const 16500) "\14\00\00\00") ;; WORDSTART
95 (data (i32.const 16504) "\05\00\00\00") ;; KEY <-- KEYLOOP
96 (data (i32.const 16508) "\06\00\00\00") ;; DUP
97 (data (i32.const 16512) "\18\00\00\00") ;; J-1: 18
98 (data (i32.const 16516) "\f0\40\00\00") ;; addr of WORDEND
99 (data (i32.const 16520) "\11\00\00\00") ;; WS?
100 (data (i32.const 16524) "\0f\00\00\00") ;; JNZ:
101 (data (i32.const 16528) "\bc\40\00\00") ;; addr of KEYDROP
102 (data (i32.const 16532) "\02\00\00\00") ;; LIT
103 (data (i32.const 16536) "\5c\00\00\00") ;; 92 (\ character)
104 (data (i32.const 16540) "\25\00\00\00") ;; =?
105 (data (i32.const 16544) "\0e\00\00\00") ;; JZ:
106 (data (i32.const 16548) "\e4\40\00\00") ;; addr of DOCHAR
107 (data (i32.const 16552) "\10\00\00\00") ;; DROP
108 (data (i32.const 16556) "\94\41\00\00") ;; DO-BACKSLASH (continue using this wbuf we started)
109 (data (i32.const 16560) "\0d\00\00\00") ;; NOOP
110 (data (i32.const 16564) "\12\00\00\00") ;; JMP:
111 (data (i32.const 16568) "\74\40\00\00") ;; addr of KEYLOOP-1 (get a new wbuf, call to wbuf+1 ate ours)
112 (data (i32.const 16572) "\10\00\00\00") ;; DROP <-- KEYDROP
113 (data (i32.const 16576) "\12\00\00\00") ;; JMP:
114 (data (i32.const 16580) "\78\40\00\00") ;; addr of KEYLOOP
115 (data (i32.const 16584) "\05\00\00\00") ;; KEY <-- WORDLOOP
116 (data (i32.const 16588) "\11\00\00\00") ;; WS?
117 (data (i32.const 16592) "\0f\00\00\00") ;; JNZ:
118 (data (i32.const 16596) "\f0\40\00\00") ;; addr of WORDEND
119 (data (i32.const 16600) "\06\00\00\00") ;; DUP
120 (data (i32.const 16604) "\18\00\00\00") ;; J-1:
121 (data (i32.const 16608) "\f0\40\00\00") ;; addr of WORDEND
122 (data (i32.const 16612) "\13\00\00\00") ;; WORDPUTC <-- DOCHAR
123 (data (i32.const 16616) "\12\00\00\00") ;; JMP:
124 (data (i32.const 16620) "\c8\40\00\00") ;; addr of WORDLOOP
125 (data (i32.const 16624) "\10\00\00\00") ;; DROP <-- WORDEND
126 (data (i32.const 16628) "\17\00\00\00") ;; WORDFINISH
127 (data (i32.const 16632) "\01\00\00\00") ;; 2DUP //RET
128 (data (i32.const 16636) "\04\00\00\00") ;; .S
129 (data (i32.const 16640) "\01\00\00\00") ;; RET
131 (data (i32.const 16680) "\1e\00\00\00") ;; 2DUP
132 (data (i32.const 16684) "\15\00\00\00") ;; DICT_GET
133 (data (i32.const 16688) "\06\00\00\00") ;; DUP
134 (data (i32.const 16692) "\0e\00\00\00") ;; JZ:
135 (data (i32.const 16696) "\4c\41\00\00") ;; donum -1 (16716)
136 (data (i32.const 16700) "\1f\00\00\00") ;; ROT
137 (data (i32.const 16704) "\20\00\00\00") ;; 2DROP
138 (data (i32.const 16708) "\0c\00\00\00") ;; EXECUTE
139 (data (i32.const 16712) "\01\00\00\00") ;; RET
140 (data (i32.const 16716) "\10\00\00\00") ;; DROP (xt from dictionary)
141 (data (i32.const 16720) "\16\00\00\00") ;; NUMBER <-- donum, pushes NUM, UNPARSED
142 (data (i32.const 16724) "\06\00\00\00") ;; DUP
143 (data (i32.const 16728) "\0f\00\00\00") ;; JNZ:
144 (data (i32.const 16732) "\68\41\00\00") ;; donum_err (16744)
145 (data (i32.const 16736) "\10\00\00\00") ;; DROP
146 (data (i32.const 16740) "\01\00\00\00") ;; RET
147 (data (i32.const 16744) "\20\00\00\00") ;; 2DROP <-- donum_err
148 (data (i32.const 16748) "\02\00\00\00") ;; LIT
149 (data (i32.const 16752) "\04\30\00\00") ;; INBUFSIZE LOCATION
150 (data (i32.const 16756) "\02\00\00\00") ;; LIT
151 (data (i32.const 16760) "\00\00\00\00") ;; 0
152 (data (i32.const 16764) "\0b\00\00\00") ;; !
153 (data (i32.const 16768) "\19\00\00\00") ;; BYE
154 (data (i32.const 16772) "\00\00\00\00") ;;
155 (data (i32.const 16776) "\00\00\00\00") ;;
156 (data (i32.const 16780) "\00\00\00\00") ;;
157 (data (i32.const 16784) "\00\00\00\00") ;;
159 (data (i32.const 16788) "\05\00\00\00") ;; KEY
160 (data (i32.const 16792) "\11\00\00\00") ;; WS?
161 (data (i32.const 16796) "\0f\00\00\00") ;; JNZ:
162 (data (i32.const 16800) "\c8\41\00\00") ;; addr of keypump + 3
163 (data (i32.const 16804) "\cc\40\00\00") ;; WORDLOOP + 1
164 (data (i32.const 16808) "\28\41\00\00") ;; EXECUTE-MODE
165 (data (i32.const 16812) "\01\00\00\00") ;; RET
167 (data (i32.const 16828) "\18\00\00\00") ;; j-1: <-- keypump
168 (data (i32.const 16832) "\e0\41\00\00") ;; addr of end
169 (data (i32.const 16836) "\05\00\00\00") ;; KEY
170 (data (i32.const 16840) "\02\00\00\00") ;; LIT
171 (data (i32.const 16844) "\0a\00\00\00") ;; 10 (line feed)
172 (data (i32.const 16848) "\25\00\00\00") ;; =?
173 (data (i32.const 16852) "\0e\00\00\00") ;; JZ:
174 (data (i32.const 16856) "\bc\41\00\00") ;; addr of keypump
175 (data (i32.const 16860) "\10\00\00\00") ;; DROP
176 (data (i32.const 16864) "\01\00\00\00") ;; RET
178 (; 1 FLAGS: AWAITER | RUNNING ]LSB ;)
180 (; 1 AWAITER CHANNEL ;)
182 (; 8 START | START-DEFAULT ;)
183 (; 16 BUFFER ADDRESSES: BASE, TAIL, HEAD, BOUND ;)
184 (global $channel_table_p i32 (i32.const 16900))
185 (global $channel_entry_size i32 (i32.const 28))
186 (global $channel_max i32 (i32.const 255))
187 (data (i32.const 16900) "\00\00\00\01") ;; STDIN (COUT: 1)
188 (data (i32.const 16904) "\00\40\00\00") ;; STDIN-START (QUIT)
189 (data (i32.const 16908) "\00\40\00\00") ;; STDIN-START-DEFAULT
190 (data (i32.const 16912) "\00\30\00\00") ;; STDIN-BUFFER-BASE
191 (data (i32.const 16916) "\00\30\00\00") ;; STDIN-BUFFER-TAIL
192 (data (i32.const 16920) "\00\30\00\00") ;; STDIN-BUFFER-HEAD
193 (data (i32.const 16924) "\00\38\00\00") ;; STDIN-BUFFER-BOUND
194 (data (i32.const 16928) "\00\00\00\00") ;; STDOUT
195 (data (i32.const 16932) "\00\00\00\00") ;; STDOUT (TODO: error handler)
196 (data (i32.const 16936) "\00\00\00\00") ;; STDOUT
197 (data (i32.const 16940) "\00\00\00\00") ;; STDOUT
198 (data (i32.const 16944) "\00\00\00\00") ;; STDOUT
199 (data (i32.const 16948) "\00\00\00\00") ;; STDOUT
200 (data (i32.const 16952) "\00\00\00\00") ;; STDOUT
201 (data (i32.const 16956) "\00\00\00\00") ;; STDERR (null)
202 (data (i32.const 16960) "\00\00\00\00") ;; STDERR (TODO: error handler)
203 (; 16900 + ((4 * 7)=>28 * 256)=>7168 = 24068 | 0x5e04 === HERE ;)
204 (export "memory" (memory $0))
205 (func $lit_rstack (param $here i32) (param $start i32) (result i32)
206 (local $eax i32) (local $ecx i32)
244 i32.const 52 ;; rpush_op
267 (func $close_channel (param $channel_p i32)
276 get_global $channel_table_p
277 get_global $channel_entry_size
288 i32.store ;; restore awaiter's "start" to original
291 i32.store8 ;; clear target thread's flags
293 (func $forth_min (param $i1 i32) (param $i2 i32) (result i32)
305 (export "main" (func $main))
306 (func $main (param $event_channel i32) (result i32)
307 get_local $event_channel
314 (func $interpret (param $channel_in i32) (result i32)
318 (local $inbuf_base i32)
319 (local $inbuf_tail i32)
320 (local $inbuf_head i32)
321 (local $inbuf_bound i32)
322 (local $stringbelt_tail i32)
323 (local $stringbelt_head i32)
324 (local $wordbelt_tail i32)
325 (local $wordbelt_head i32)
326 (local $channel_out i32)
332 block $close_yield_channel
335 br_if $close_yield_channel
339 (; channel in setup ;)
340 get_global $channel_table_p
341 get_global $channel_entry_size
342 get_global $channel_max
343 get_local $channel_in
353 i32.eqz ;; (FLAGS & 1) => running, return 0
363 i32.store8 ;; set running flag
368 set_local $channel_out
379 set_local $inbuf_base
384 set_local $inbuf_tail
389 set_local $inbuf_head
394 set_local $inbuf_bound
395 (; /channel in setup ;)
399 get_global $stringbelt_tail_p
401 set_local $stringbelt_tail
402 get_global $stringbelt_head_p
404 set_local $stringbelt_head
405 get_global $wordbelt_tail_p
407 set_local $wordbelt_tail
408 get_global $wordbelt_head_p
410 set_local $wordbelt_head
423 block $default block $op0 block $ret block $lit block $rinit
424 block $logword block $key block $dup block $plus block $noop2 block $emit
425 block $fetch block $set block $execute block $noop block $jz block $jnz
426 block $drop block $wsbool block $jmp block $wordputc block $wordstart
427 block $dictget block $parsenum block $wordfinish block $jneg1 block $swap
428 block $words block $here block $dictset block $dup2 block $rot block $drop2
429 block $comma block $subtract block $inchan block $sethere block $eqbool
430 block $echostring block $strstart block $strput block $strend block $fetchinc
431 block $setinc block $finddoes block $definedoes block $stacktrace block $webfetch
432 block $outchan block $read block $openchannel block $rpush_op
434 br_table $op0 $ret (;2;)$lit $rinit (;4;)$logword $key (;6;)$dup $plus
435 (;8;)$jmp $emit (;10;)$fetch $set (;12;)$execute $noop (;14;)$jz $jnz
436 (;16;)$drop $wsbool (;18;)$jmp $wordputc (;20;)$wordstart $dictget
437 (;22;)$parsenum $wordfinish (;24;)$jneg1 $bye (;26;)$swap $words
438 (;28;)$here $dictset (;30;)$dup2 $rot (;32;)$drop2 $comma
439 (;34;)$subtract $inchan (;36;)$sethere $eqbool (;38;)$echostring $strstart
440 (;40;)$strput $strend (;42;)$fetchinc $setinc (;44;)$finddoes $definedoes
441 (;46;)$stacktrace $webfetch (;48;)$outchan $read (;50;)$awaiting $openchannel
442 (;52;)$rpush_op $default
448 (; Get addr of channel block ;)
449 get_global $channel_table_p
450 get_global $channel_entry_size
453 call $rpush ;;save to rstack
457 (; Set Out-Channel to 1 by default ;)
460 i32.add ;; out channel
463 (; leave a copy of channel_p on stack ;)
465 (; Get addr of ch-start and ch-default-start ;)
468 i32.add ;; addr of channel start
472 i32.add ;; addr of channel default start
473 (; Store the user-provided address in both ;)
479 (; go bo buf-base (channel_p + 12), put HERE in it ;)
501 (; set buf-bound = here += 512 ;)
507 (; return channel number ;)
512 get_local $channel_in
513 call $pop ;; location to write
521 set_local $channel_out
528 call $pop ;; callback
584 get_local $stringbelt_tail
585 get_local $stringbelt_head
586 get_local $stringbelt_tail
590 tee_local $eax (; n bytes ;)
592 (; align to 32-bit ;)
593 get_local $stringbelt_head
598 set_local $stringbelt_head
600 get_local $stringbelt_tail
609 get_local $stringbelt_head
610 get_global $wordbelt_base
614 tee_local $stringbelt_head
615 get_local $stringbelt_tail
618 get_local $stringbelt_head
621 set_local $stringbelt_head
622 get_local $stringbelt_tail
625 set_local $stringbelt_tail
626 loop $copystringtostart
627 get_local $stringbelt_head
628 get_local $stringbelt_tail
631 get_local $stringbelt_head
634 set_local $stringbelt_head
635 get_local $stringbelt_tail
638 tee_local $stringbelt_tail
639 get_global $wordbelt_base
641 br_if $copystringtostart
644 set_local $stringbelt_tail
646 get_local $stringbelt_head
649 get_local $stringbelt_head
652 set_local $stringbelt_head
656 get_local $stringbelt_head
657 get_global $wordbelt_base
663 set_local $stringbelt_head
665 get_local $stringbelt_head
666 get_local $stringbelt_head
667 tee_local $stringbelt_tail
672 set_local $stringbelt_head
675 get_local $channel_out
704 set_local $channel_in
800 get_local $wordbelt_head
801 get_local $wordbelt_tail
803 set_local $eax (; n bytes ;)
804 (; align to 32-bit ;)
805 get_local $wordbelt_head
810 set_local $wordbelt_head
812 get_local $wordbelt_tail
839 get_local $wordbelt_head
840 get_global $wordbelt_bound
845 get_global $wordbelt_base
846 set_local $wordbelt_head
848 get_local $wordbelt_head
849 set_local $wordbelt_tail
853 get_local $wordbelt_head
854 get_global $wordbelt_bound
857 get_global $wordbelt_base
858 set_local $wordbelt_head
859 loop $copywordtostart
860 get_local $wordbelt_head
861 get_local $wordbelt_tail
864 get_local $wordbelt_head
867 set_local $wordbelt_head
868 get_local $wordbelt_tail
871 tee_local $wordbelt_tail
872 get_global $wordbelt_bound
874 br_if $copywordtostart
876 get_global $wordbelt_base
877 set_local $wordbelt_tail
879 get_local $wordbelt_head
882 get_local $wordbelt_head
885 set_local $wordbelt_head
981 get_local $inbuf_head
982 get_local $inbuf_tail
986 get_local $channel_out
990 (; if current channel's default start is QUIT ;)
991 get_global $channel_table_p
992 get_global $channel_entry_size
993 get_local $channel_in
1003 get_local $inbuf_head
1007 get_local $inbuf_head
1010 get_local $inbuf_head
1013 set_local $inbuf_head
1016 get_local $channel_in
1017 get_local $inbuf_base
1018 get_local $inbuf_bound
1019 get_local $inbuf_base
1023 get_local $inbuf_base
1025 set_local $inbuf_tail
1026 get_local $inbuf_base
1027 set_local $inbuf_head
1035 get_local $wordbelt_head
1036 get_local $wordbelt_tail
1053 end ;; rinit (unused)
1055 get_global $holy_bye
1085 (; set provided channel's waiter to this channel ;)
1086 get_global $channel_table_p
1087 get_global $channel_entry_size
1094 get_local $channel_in
1096 (; set awaiter flag ;)
1104 (; channel status save ;)
1105 get_global $channel_table_p
1106 get_global $channel_entry_size
1107 get_local $channel_in
1111 (; set buffer base ;)
1114 get_local $inbuf_base
1116 (; set buffer tail ;)
1120 get_local $inbuf_tail
1122 (; set buffer head ;)
1126 get_local $inbuf_head
1128 (; set buffer bound ;)
1132 get_local $inbuf_bound
1135 (; set buffer buffer start ;)
1141 (; backup return stack here, returning to esi ;)
1148 set_local $inbuf_base ;; temporary bool "await-exit"
1153 get_global $channel_table_p
1154 get_global $channel_entry_size
1155 get_local $channel_in
1161 get_local $channel_out
1169 i32.store8 (; toggle off running ;)
1174 get_global $stringbelt_tail_p
1175 get_local $stringbelt_tail
1177 get_global $stringbelt_head_p
1178 get_local $stringbelt_head
1180 get_global $wordbelt_tail_p
1181 get_local $wordbelt_tail
1183 get_global $wordbelt_head_p
1184 get_local $wordbelt_head
1187 block $check_awaiter
1188 get_local $inbuf_base
1190 i32.eq ;; don't check if "await-exit" is true
1191 br_if $check_awaiter
1196 i32.eqz ;; (FLAGS & 2) => awaiter, run it
1197 br_if $check_awaiter
1202 get_local $channel_in
1204 set_local $channel_in
1208 get_local $channel_in