5 .include 'languages/forth/words.pir'
8 # load the libraries we depend on
9 load_bytecode 'languages/forth/tokenstream.pbc'
10 load_bytecode 'languages/forth/variablestack.pbc'
11 load_bytecode 'languages/forth/virtualstack.pbc'
13 # initialize the rstack
15 stack = new 'ResizablePMCArray'
16 set_hll_global ' stack', stack
18 # word dictionary - used for compilation
21 set_hll_global ' dict', dict
23 .local pmc vars, vstack
25 vstack = new 'VariableStack'
26 set_hll_global ' variables', vars
27 set_hll_global ' vstack', vstack
29 # register the actual compiler
31 compiler = get_hll_global ' compile'
32 compreg 'forth', compiler
41 if argc == 0 goto prompt
50 .local pmc stdin, stdout, forth
53 forth = compreg 'forth'
56 print "Parrot Forth\n"
74 get_results '0, 0', $P0, $S0
85 .local pmc code, stream, stack
86 code = new 'CodeString'
87 stream = new 'TokenStream', input
88 stack = new 'VirtualStack'
90 code.emit(<<"END_PIR")
93 stack = get_hll_global " stack"
98 unless stream goto done
101 ' dispatch'(code, stream, stack, token)
106 $S0 = stack.consolidate_to_cstack()
108 code.emit(<<"END_PIR")
123 $I0 = isa token, 'Integer'
126 .local pmc dict, vars
127 dict = get_hll_global ' dict'
128 vars = get_hll_global ' variables'
131 $I0 = exists dict[$S0]
132 if $I0 goto user_word
133 $I0 = exists vars[$S0]
136 $P0 = get_hll_global $S0
137 if null $P0 goto undefined
138 $P0(code, stream, stack)
142 $S1 = stack.consolidate_to_cstack()
145 code.emit(" '%0'(stack)", $S0)
150 $S0 = code.unique('$P')
151 code.emit(<<'END_PIR', $S0, $I0)
160 $S0 = "undefined symbol: " . $S0
161 $P0 = new 'Exception'
166 $S0 = code.unique('$P')
167 code.emit(<<"END_PIR", $S0, token)
179 # vim: expandtab shiftwidth=4 ft=pir: