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_fetch" (func $sys_fetch (param i32 i32 i32) (result i32)))
29 (import "env" "sys_listen" (func $sys_listen (param i32 i32 i32) (result i32)))
30 (import "env" "sys_write" (func $sys_write (param i32 i32 i32) (result i32)))
31 (import "env" "sys_echo" (func $sys_echo (param i32 i32)))
32 (import "env" "sys_echochar" (func $sys_echochar (param i32)))
33 (import "env" "sys_reflect" (func $sys_reflect (param i32)))
34 (import "env" "vocab_get" (func $vocab_get (param i32 i32) (result i32)))
35 (import "env" "vocab_set" (func $vocab_set (param i32 i32 i32)))
36 (import "env" "does_get" (func $does_get (param i32 i32) (result i32)))
37 (import "env" "does_set" (func $does_set (param i32 i32 i32)))
38 (import "env" "is_whitespace" (func $is_whitespace (param i32) (result i32)))
39 (import "env" "sys_parsenum" (func $sys_parsenum (param i32 i32 i32) (result i32)))
40 (import "env" "sys_stack" (func $sys_stack))
41 (import "env" "sys_words" (func $sys_words))
42 (table (;0;) 0 anyfunc)
44 (; String Belt ;) ;; 0x0000 Size: 8192
45 (global $wordbelt i32 (i32.const 8192)) ;; 0x2000 Size: 4096
46 (global $inbuf i32 (i32.const 12288)) ;; 0x3000 Size: 2048
47 (global $inbuf_size i32 (i32.const 12292))
48 (global $inbuf_data i32 (i32.const 12296))
49 (global $kvars i32 (i32.const 14336)) ;; 0x3800 Size: 2048
50 (data (i32.const 12288) "\f8\07\00\00") ;; 2040 len
51 (global $mode_p i32 (i32.const 14336))
52 (global $here_p i32 (i32.const 14340))
53 (global $start_p i32 (i32.const 14344))
54 (global $base_p i32 (i32.const 14348))
55 (global $stringbelt_tail_p i32 (i32.const 14352))
56 (global $stringbelt_head_p i32 (i32.const 14356))
57 (global $wordbelt_tail_p i32 (i32.const 14360))
58 (global $wordbelt_head_p i32 (i32.const 14364))
59 (global $channel_in_p i32 (i32.const 14368))
60 (global $channel_out_p i32 (i32.const 14372))
61 (data (i32.const 14336) "\28\41\00\00") ;; MODE
62 (data (i32.const 14340) "\04\42\00\00") ;; HERE
63 (data (i32.const 14344) "\00\40\00\00") ;; START (16384) (Quit)
64 (data (i32.const 14348) "\0a\00\00\00") ;; BASE
65 (data (i32.const 14352) "\00\00\00\00") ;; STRINGBELT_TAIL
66 (data (i32.const 14356) "\00\00\00\00") ;; STRINGBELT_HEAD
67 (data (i32.const 14360) "\00\20\00\00") ;; WORDBELT_TAIL
68 (data (i32.const 14364) "\00\20\00\00") ;; WORDBELT_HEAD
69 (data (i32.const 14368) "\00\00\00\00") ;; CHANNEL-IN
70 (data (i32.const 14372) "\01\00\00\00") ;; CHANNEL-OUT
71 (; channel listeners 0x3c00 ;)
72 (global $channel_listeners_p i32 (i32.const 15360))
73 (data (i32.const 15360) "\00\40\00\00") ;; CHANNEL LISTENER 0 (quit)
75 (global $quit_p i32 (i32.const 16384))
76 (data (i32.const 16384) "\01\00\00\00") ;; RINIT xt
77 (global $quit_ret_p i32 (i32.const 16388))
78 (data (i32.const 16388) "\10\40\00\00") ;; INTERPRET xt
79 (data (i32.const 16392) "\12\00\00\00") ;; JMP xt
80 (data (i32.const 16396) "\00\40\00\00") ;; quit location (16384)
82 (data (i32.const 16400) "\74\40\00\00") ;; WORD xt (16500)
83 (data (i32.const 16404) "\06\00\00\00") ;; DUP
84 (data (i32.const 16408) "\0e\00\00\00") ;; JZ:
85 (data (i32.const 16412) "\38\40\00\00") ;; INTERP-END addr (16444)
86 (data (i32.const 16416) "\02\00\00\00") ;; LIT xt
87 (data (i32.const 16420) "\00\38\00\00") ;; MODE addr (14336)
88 (data (i32.const 16424) "\0a\00\00\00") ;; @ (fetch) xt
89 (data (i32.const 16428) "\0c\00\00\00") ;; EXECUTE xt
90 (data (i32.const 16432) "\0d\00\00\00") ;; NOOP xt
91 (data (i32.const 16436) "\01\00\00\00") ;; RET
92 (data (i32.const 16440) "\10\00\00\00") ;; DROP <-- INTERP-END
93 (data (i32.const 16444) "\10\00\00\00") ;; DROP
94 (data (i32.const 16448) "\19\00\00\00") ;; BYE
96 (data (i32.const 16500) "\14\00\00\00") ;; WORDSTART
97 (data (i32.const 16504) "\05\00\00\00") ;; KEY <-- KEYLOOP
98 (data (i32.const 16508) "\06\00\00\00") ;; DUP
99 (data (i32.const 16512) "\18\00\00\00") ;; J-1: 18
100 (data (i32.const 16516) "\f0\40\00\00") ;; addr of WORDEND
101 (data (i32.const 16520) "\11\00\00\00") ;; WS?
102 (data (i32.const 16524) "\0f\00\00\00") ;; JNZ:
103 (data (i32.const 16528) "\bc\40\00\00") ;; addr of KEYDROP
104 (data (i32.const 16532) "\02\00\00\00") ;; LIT
105 (data (i32.const 16536) "\5c\00\00\00") ;; 92 (\ character)
106 (data (i32.const 16540) "\25\00\00\00") ;; =?
107 (data (i32.const 16544) "\0e\00\00\00") ;; JZ:
108 (data (i32.const 16548) "\e4\40\00\00") ;; addr of DOCHAR
109 (data (i32.const 16552) "\10\00\00\00") ;; DROP
110 (data (i32.const 16556) "\94\41\00\00") ;; DO-BACKSLASH (continue using this wbuf we started)
111 (data (i32.const 16560) "\0d\00\00\00") ;; NOOP
112 (data (i32.const 16564) "\12\00\00\00") ;; JMP:
113 (data (i32.const 16568) "\74\40\00\00") ;; addr of KEYLOOP-1 (get a new wbuf, call to wbuf+1 ate ours)
114 (data (i32.const 16572) "\10\00\00\00") ;; DROP <-- KEYDROP
115 (data (i32.const 16576) "\12\00\00\00") ;; JMP:
116 (data (i32.const 16580) "\78\40\00\00") ;; addr of KEYLOOP
117 (data (i32.const 16584) "\05\00\00\00") ;; KEY <-- WORDLOOP
118 (data (i32.const 16588) "\11\00\00\00") ;; WS?
119 (data (i32.const 16592) "\0f\00\00\00") ;; JNZ:
120 (data (i32.const 16596) "\f0\40\00\00") ;; addr of WORDEND
121 (data (i32.const 16600) "\06\00\00\00") ;; DUP
122 (data (i32.const 16604) "\18\00\00\00") ;; J-1:
123 (data (i32.const 16608) "\f0\40\00\00") ;; addr of WORDEND
124 (data (i32.const 16612) "\13\00\00\00") ;; WORDPUTC <-- DOCHAR
125 (data (i32.const 16616) "\12\00\00\00") ;; JMP:
126 (data (i32.const 16620) "\c8\40\00\00") ;; addr of WORDLOOP
127 (data (i32.const 16624) "\10\00\00\00") ;; DROP <-- WORDEND
128 (data (i32.const 16628) "\17\00\00\00") ;; WORDFINISH
129 (data (i32.const 16632) "\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 (export "memory" (memory $0))
179 (export "main" (func $main))
180 (func $main (param $event_channel i32) (result i32)
181 block $use_current_channel
182 (; rstack contains channel barriers (numbers lower than 256)
183 which will reset channel to 0 when returning to the quit loop.
184 if an interrupt event is happening, load its handler and set
185 the input channel. ;)
186 get_local $event_channel
188 br_if $use_current_channel
189 get_local $event_channel
192 br_if $use_current_channel
193 get_global $channel_in_p
194 get_local $event_channel
197 get_global $channel_listeners_p
198 get_local $event_channel
205 (func $interpret (param $esi i32) (result i32)
208 (local $inbuf_head i32)
209 (local $stringbelt_tail i32)
210 (local $stringbelt_head i32)
211 (local $wordbelt_tail i32)
212 (local $wordbelt_head i32)
213 (local $channel_in i32)
214 (local $channel_out i32)
218 get_global $inbuf_data
219 set_local $inbuf_head
220 get_global $stringbelt_tail_p
222 set_local $stringbelt_tail
223 get_global $stringbelt_head_p
225 set_local $stringbelt_head
226 get_global $wordbelt_tail_p
228 set_local $wordbelt_tail
229 get_global $wordbelt_head_p
231 set_local $wordbelt_head
232 get_global $channel_in_p
234 set_local $channel_in
235 get_global $channel_out_p
237 set_local $channel_out
250 block $default block $op0 block $ret block $lit block $rinit
251 block $word block $key block $dup block $plus block $noop2 block $emit
252 block $fetch block $set block $execute block $noop block $jz block $jnz
253 block $drop block $wsbool block $jmp block $wordputc block $wordstart
254 block $dictget block $parsenum block $wordfinish block $jneg1 block $swap
255 block $words block $here block $dictset block $dup2 block $rot block $drop2
256 block $comma block $subtract block $inchan block $sethere block $eqbool
257 block $echostring block $strstart block $strput block $strend block $fetchinc
258 block $setinc block $finddoes block $definedoes block $stacktrace block $webfetch
259 block $outchan block $read
261 br_table $op0 $ret (;2;)$lit $rinit (;4;)$word $key (;6;)$dup $plus
262 (;8;)$jmp $emit (;10;)$fetch $set (;12;)$execute $noop (;14;)$jz $jnz
263 (;16;)$drop $wsbool (;18;)$jmp $wordputc (;20;)$wordstart $dictget
264 (;22;)$parsenum $wordfinish (;24;)$jneg1 $bye (;26;)$swap $words
265 (;28;)$here $dictset (;30;)$dup2 $rot (;32;)$drop2 $comma
266 (;34;)$subtract $inchan (;36;)$sethere $eqbool (;38;)$echostring $strstart
267 (;40;)$strput $strend (;42;)$fetchinc $setinc (;44;)$finddoes $definedoes
268 (;46;)$stacktrace $webfetch (;48;)$outchan $read (;50;)$default
270 get_local $channel_in
271 call $pop ;; location to write
279 set_local $channel_out
337 get_local $stringbelt_tail
338 get_local $stringbelt_head
339 get_local $stringbelt_tail
343 tee_local $eax (; n bytes ;)
345 (; align to 32-bit ;)
346 get_local $stringbelt_head
351 set_local $stringbelt_head
353 get_local $stringbelt_tail
362 get_local $stringbelt_head
367 tee_local $stringbelt_head
368 get_local $stringbelt_tail
371 get_local $stringbelt_head
374 set_local $stringbelt_head
375 get_local $stringbelt_tail
378 set_local $stringbelt_tail
379 loop $copystringtostart
380 get_local $stringbelt_head
381 get_local $stringbelt_tail
384 get_local $stringbelt_head
387 set_local $stringbelt_head
388 get_local $stringbelt_tail
391 tee_local $stringbelt_tail
394 br_if $copystringtostart
397 set_local $stringbelt_tail
399 get_local $stringbelt_head
402 get_local $stringbelt_head
405 set_local $stringbelt_head
409 get_local $stringbelt_head
416 set_local $stringbelt_head
418 get_local $stringbelt_head
419 get_local $stringbelt_head
420 tee_local $stringbelt_tail
425 set_local $stringbelt_head
428 get_local $channel_out
457 set_local $channel_in
553 get_local $wordbelt_tail
554 get_local $wordbelt_head
555 get_local $wordbelt_tail
559 tee_local $eax (; n bytes ;)
561 (; align to 32-bit ;)
562 get_local $wordbelt_head
567 set_local $wordbelt_head
569 get_local $wordbelt_tail
600 get_local $wordbelt_head
607 set_local $wordbelt_head
609 get_local $wordbelt_head
610 get_local $wordbelt_head
611 tee_local $wordbelt_tail
616 set_local $wordbelt_head
620 get_local $wordbelt_head
625 tee_local $wordbelt_head
626 get_local $wordbelt_tail
629 get_local $wordbelt_head
632 set_local $wordbelt_head
633 get_local $wordbelt_tail
636 set_local $wordbelt_tail
637 loop $copywordtostart
638 get_local $wordbelt_head
639 get_local $wordbelt_tail
642 get_local $wordbelt_head
645 set_local $wordbelt_head
646 get_local $wordbelt_tail
649 tee_local $wordbelt_tail
652 br_if $copywordtostart
655 set_local $wordbelt_tail
657 get_local $wordbelt_head
660 get_local $wordbelt_head
663 set_local $wordbelt_head
761 get_global $inbuf_size
763 get_local $inbuf_head
764 get_global $inbuf_data
768 get_local $inbuf_head
771 get_local $inbuf_head
774 set_local $inbuf_head
777 get_global $inbuf_size
778 i32.const 0 (; stdin hardcode ;)
779 get_global $inbuf_data
785 get_global $inbuf_size
789 get_global $inbuf_data
790 set_local $inbuf_head
793 i32.const -1 ;; <- keyval sent if sz == 0
804 set_local $channel_in
817 (; cannot jump lower than 256 because it is reserved for
818 opcodes, so overload popping that kind of retval with
819 a channel selector, for when an event handler yields and
820 is interrupted by another event handler. there are also
821 a max of 255 channels, which is the same as the opcode space ;)
828 set_local $channel_in
851 get_global $stringbelt_tail_p
852 get_local $stringbelt_tail
854 get_global $stringbelt_head_p
855 get_local $stringbelt_head
857 get_global $wordbelt_tail_p
858 get_local $wordbelt_tail
860 get_global $wordbelt_head_p
861 get_local $wordbelt_head
863 get_global $channel_in_p
864 get_local $channel_in
866 get_global $channel_out_p
867 get_local $channel_out