chiark / gitweb /
Initial revision
[ssr] / StraySrc / Libraries / Sapphire / sail / _s / interp
1 ;
2 ; interp.s
3 ;
4 ; Main entry point for the interpreter
5 ;
6 ; © 1995 Straylight
7 ;
8
9 ;----- Standard Header ------------------------------------------------------
10
11                 GET     libs:header
12                 GET     libs:swis
13
14                 GET     libs:stream
15
16 ;----- External dependencies ------------------------------------------------
17
18                 GET     sh.anchor
19                 GET     sh.ctrl
20                 GET     sh.errNum
21                 GET     sh.error
22                 GET     sh.express
23                 GET     sh.getToken
24                 GET     sh.termScript
25                 GET     sh.tokens
26                 GET     sh.upcalls
27
28 ;----- Main code ------------------------------------------------------------
29
30                 AREA    |TermScript$$Code|,CODE,READONLY
31
32 ; --- interp_start ---
33 ;
34 ; On entry:     R12 == pointer to our anchor block
35 ;
36 ; On exit:      R7-R9 == next token
37 ;
38 ; Use:          Prepares for execution, and even does some too.
39
40                 EXPORT  interp_start
41 interp_start    ROUT
42
43                 LDR     R10,tsc_tokAnchor       ;Load the anchor
44                 LDR     R10,[R10]               ;I hate wimp_extension
45
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
53
54                 LTORG
55
56 ; --- interp_exec ---
57 ;
58 ; On entry:     R7-R9 == token to deal with
59 ;               R11 == offset in file to execute from
60 ;               R12 == pointer to the anchor block
61 ;
62 ; On exit:      R0 == type code (eg. 0 == we are still executing
63 ;               R7-R9 == next token to deal with
64 ;
65 ; Use:          Executes some of the file.
66
67                 EXPORT  interp_exec
68 interp_exec     ROUT
69
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
75
76                 ; --- Return control for a little while then ---
77
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
81
82 10interp_exec   CMP     R7,#tClass_instr        ;Is this an instruction?
83                 BNE     %50interp_exec          ;No -- could be other things
84
85                 ; --- We have an instruction ---
86
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
90                 DCB     "Jive"
91
92                 ; --- The main dispatch table ---
93
94                 B       ctrl_bput
95                 B       ctrl_case
96                 B       ctrl_close
97                 ;B      ctrl_call               ;CALL
98                 B       ctrl_data
99                 B       ctrl_def
100                 B       ctrl_dim
101                 B       ctrl_end
102                 B       ctrl_endproc
103                 B       ctrl_endwhile
104                 B       interp_next             ;ENDIF
105                 B       interp_next             ;ENDCASE
106                 B       ctrl_else
107                 ;B      ctrl_error              ;ERROR
108                 B       ctrl_for
109                 B       ctrl_goto
110                 B       ctrl_gosub
111                 B       ctrl_if
112                 B       ctrl_let
113                 B       ctrl_local
114                 B       ctrl_next
115                 ;B      ctrl_oscli              ;OSCLI
116                 B       ctrl_otherwise
117                 B       ctrl_proc
118                 B       ctrl_return
119                 B       ctrl_repeat
120                 B       ctrl_read
121                 B       ctrl_restore
122                 B       ctrl_swap
123                 B       ctrl_sys
124                 B       ctrl_until
125                 B       ctrl_while
126                 B       ctrl_when
127
128                 ; --- Handle pseudo varaible and the like ---
129
130 50interp_exec   SUBS    R4,R9,#'_'              ;Is it an underscore?
131                 SUBNES  R4,R9,#'!'
132                 SUBNES  R4,R9,#'?'
133                 SUBNES  R4,R9,#'$'
134                 SUBNE   R4,R9,#'A'              ;Or a capital letter?
135                 CMP     R4,#26
136                 SUBCS   R4,R9,#'a'              ;Or a lowercase letter?
137                 CMPCS   R4,#26
138                 BCC     ctrl_let                ;If so, assume assignment
139
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
143
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
147
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
151
152                 CMP     R7,#tClass_streamOp     ;Is it a streamOp?
153                 BNE     %60interp_exec          ;No -- jump ahead
154
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
166
167 60interp_exec   CMP     R7,#tClass_multArg      ;A multiple argument thing?
168                 BNE     %70interp_exec          ;No -- jump ahead
169
170                 ; --- Deal with a multiple argument command ---
171
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
182
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
186
187                 CMP     R9,#'*'                 ;Is this a star command?
188                 BNE     interp_next             ;Probably emtpy statement
189
190                 ; --- We have a star command ---
191                 ;
192                 ; We copy the command into a buffer, until we reach
193                 ; a terminating character.
194
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
201
202                 ; --- We have the string in the buffer ---
203
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
208
209                 B       interp_next             ;Just keep on goin' then
210
211                 LTORG
212
213 ; --- interp_notImpl ---
214
215                 EXPORT  interp_notImpl
216 interp_notImpl  MOV     R0,#err_lazy
217
218                 B       error_report
219
220 ; --- interp_next ---
221 ;
222 ; On entry:     R7-R9 == token to deal with
223 ;               R11 == offset in file to execute from
224 ;               R12 == pointer to the anchor block
225 ;
226 ; On exit:      R0 == type code (eg. 0 == we are still executing)
227 ;               R7-R9 == next token to deal with
228 ;
229 ; Use:          Checks the next instruction and acts approriately.
230
231                 EXPORT  interp_next
232 interp_next     ROUT
233
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
242
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
250
251                 LTORG
252
253 ;----- That's all, folks ----------------------------------------------------
254
255                 END