4 ; Main entry point for the interpreter
9 ;----- Standard Header ------------------------------------------------------
16 ;----- External dependencies ------------------------------------------------
28 ;----- Main code ------------------------------------------------------------
30 AREA |TermScript$$Code|,CODE,READONLY
32 ; --- interp_start ---
34 ; On entry: R12 == pointer to our anchor block
36 ; On exit: R7-R9 == next token
38 ; Use: Prepares for execution, and even does some too.
43 LDR R10,tsc_tokAnchor ;Load the anchor
44 LDR R10,[R10] ;I hate wimp_extension
46 MOV R14,#1 ;The current line number
47 STR R14,tsc_line ;Store it
48 MOV R9,#-1 ;Prepare for the first line
49 BL getToken ;Get the first token ready
50 SWI OS_ReadMonotonicTime ;Read the current time
51 STR R0,tsc_timeSoFar ;Remember this time
52 B interp_exec ;Do some execution
58 ; On entry: R7-R9 == token to deal with
59 ; R11 == offset in file to execute from
60 ; R12 == pointer to the anchor block
62 ; On exit: R0 == type code (eg. 0 == we are still executing
63 ; R7-R9 == next token to deal with
65 ; Use: Executes some of the file.
70 SWI OS_ReadMonotonicTime ;Read the current time
71 LDR R14,tsc_timeSoFar ;Load the time we started
72 SUB R0,R0,R14 ;Thie we have been executing
73 CMP R0,#5 ;5cs up yet?
74 BCC %10interp_exec ;No -- keep on going then
76 ; --- Return control for a little while then ---
78 00interp_exec BL tsc_wait ;Yes -- wait some then
79 SWI OS_ReadMonotonicTime ;Read the current time
80 STR R0,tsc_timeSoFar ;Remember this time
82 10interp_exec CMP R7,#tClass_instr ;Is this an instruction?
83 BNE %50interp_exec ;No -- could be other things
85 ; --- We have an instruction ---
87 MOV R0,R8 ;Look after index
88 BL getToken ;Get the next tokem
89 ADD PC,PC,R0,LSL #2 ;Branch to the correct code
92 ; --- The main dispatch table ---
105 B interp_next ;ENDCASE
128 ; --- Handle pseudo varaible and the like ---
130 50interp_exec SUBS R4,R9,#'_' ;Is it an underscore?
134 SUBNE R4,R9,#'A' ;Or a capital letter?
136 SUBCS R4,R9,#'a' ;Or a lowercase letter?
138 BCC ctrl_let ;If so, assume assignment
140 CMP R9,#tok_time ;Is this a TIME pseudovar?
141 BLEQ getToken ;Yes -- done with this token
142 BEQ ctrl_timeEq ;Yes -- assign that then
144 CMP R9,#tok_lnewlineS ;Is this another pseudovar?
145 BLEQ getToken ;Yes -- done with this token
146 BEQ termite_lnewline ;Yes -- assign that then
148 CMP R9,#tok_rnewlineS ;Is this anotehr pseudovar?
149 BLEQ getToken ;Yes -- done with this token
150 BEQ termite_rnewline ;Yes -- assign that then
152 CMP R7,#tClass_streamOp ;Is it a streamOp?
153 BNE %60interp_exec ;No -- jump ahead
155 MOV R0,R9 ;Remember the tokoen
156 BL getToken ;Get another token
157 CMP R9,#'#' ;Do we have a hash next?
158 MOVNE R0,#err_expHash ;No -- complain then
159 BNE error_report ;And report an error
160 BL getToken ;Get the next token
161 CMP R0,#tok_ptr ;Setting of pointer?
162 BEQ ctrl_ptr ;Yes -- do that then
163 CMP R0,#tok_ext ;Setting of extent?
164 BEQ ctrl_ext ;Yes -- do that
165 BNE interp_next ;Probably emtpy statement
167 60interp_exec CMP R7,#tClass_multArg ;A multiple argument thing?
168 BNE %70interp_exec ;No -- jump ahead
170 ; --- Deal with a multiple argument command ---
172 CMP R9,#tok_leftS ;Is it LEFT$?
173 BLEQ getToken ;Yes -- get a token
174 BEQ ctrl_leftS ;Yes -- deal with it
175 CMP R9,#tok_midS ;Is it MID$?
176 BLEQ getToken ;Yes -- get a token
177 BEQ ctrl_midS ;Yes -- deal with it
178 CMP R9,#tok_rightS ;Is it RIGHT$?
179 BLEQ getToken ;Yes -- get a token
180 BEQ ctrl_rightS ;Yes -- deal with it
181 BNE interp_next ;Probably emtpy statement
183 70interp_exec CMP R9,#'=' ;Is it a return-from-fn?
184 BLEQ getToken ;Yes -- gobble it then
185 BEQ ctrl_equals ;Yes -- return then
187 CMP R9,#'*' ;Is this a star command?
188 BNE interp_next ;Probably emtpy statement
190 ; --- We have a star command ---
192 ; We copy the command into a buffer, until we reach
193 ; a terminating character.
195 ADR R0,tsc_misc ;Point to the destination
196 00 BL getToken ;Get a token
197 CMP R9,#10 ;Is this the end of the line?
198 CMPNE R9,#&FF ;Or the end of the file
199 STRNEB R9,[R0],#1 ;No -- store the byte
200 BNE %b00 ;And keep on going
202 ; --- We have the string in the buffer ---
204 MOV R14,#0 ;We had better terminate it
205 STRB R14,[R0],#1 ;By store a NULL char
206 ADR R0,tsc_misc ;Point to the command
207 SWI Wimp_StartTask ;Perform the command
209 B interp_next ;Just keep on goin' then
213 ; --- interp_notImpl ---
215 EXPORT interp_notImpl
216 interp_notImpl MOV R0,#err_lazy
220 ; --- interp_next ---
222 ; On entry: R7-R9 == token to deal with
223 ; R11 == offset in file to execute from
224 ; R12 == pointer to the anchor block
226 ; On exit: R0 == type code (eg. 0 == we are still executing)
227 ; R7-R9 == next token to deal with
229 ; Use: Checks the next instruction and acts approriately.
234 CMP R9,#10 ;Is this newline?
235 LDR R14,tsc_flags ;Load the flags word
236 ORREQ R14,R14,#tscFlag_nl ;Newline just arrived
237 BICNE R14,R14,#tscFlag_nl ;Or maybe not
238 STR R14,tsc_flags ;Store the new flags back
239 CMPNE R9,#':' ;Is this a ':'?
240 BLEQ getToken ;Either -- get a token
241 BEQ interp_exec ;...and keep on looping
243 CMP R9,#tok_else ;Is this an ELSE?
244 BLEQ getToken ;Yes -- read a token
245 BEQ ctrl_else ;...and branch to else ctrl
246 SUBS R0,R9,#&FF ;Is this the end?
247 BEQ tsc_end ;Yes -- just end then
248 MOV R0,#err_syntax ;This is a synatx error
249 B error_report ;So report it
253 ;----- That's all, folks ----------------------------------------------------