aboutsummaryrefslogtreecommitdiffstats
path: root/MOOCodeSequences.txt
blob: 7f325b20d3215edbb6b8cd0f92ca3fd611c03830 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
This file documents, in very terse fashion, the opcode sequences emitted by the
MOO compiler and accepted by the MOO decompiler.  It is an invaluable reference
while reading the code in either `code_gen.c' or `decompile.c'.

NOTE: Since MOO database files contain suspended tasks, and since the file
      representation of those tasks includes both source code and a current PC
      for each frame on the stack, IT IS CRITICALLY IMPORTANT that these code
      sequences not change between releases of the server.  Otherwise, when the
      code for a frame was recompiled at server start-up, its associated saved
      PC value might no longer be valid, leading to almost certain catastrophe.
      If the database file format were at some point changed to contain the
      bytecodes (and not the source code) for suspended task frames, then this
      restriction could (at least one release later) be relaxed.

stmt:
	  {[ELSE]IF ( expr ) stmts}+ [ELSE stmts] ENDIF

		<expr>		; Once for each arm
		IF / EIF next	;
		<stmts>		;
		JUMP done	;
	    next:		;

		<stmts>		; If there's an ELSE part

	    done:

	| FOR id IN ( expr ) stmts ENDFOR

		<expr>
		NUM 1
	    top:
		FOR_LIST id done
		<stmts>
		JUMP top
	    done:

	| FOR id IN [ expr1 .. expr2 ] stmts ENDFOR

		<expr1>
		<expr2>
	    top:
		FOR_RANGE id done
		<stmts>
		JUMP top
	    done:

	| WHILE [id] ( expr ) stmts ENDWHILE

	    top:
		<expr>

		WHILE done		; if there is no ID
		WHILE_ID id done	; if there is an ID

		<stmts>
		JUMP top
	    done:

	| FORK [id] ( expr ) stmts ENDFORK

		<expr>
		FORK / FORK_WITH_ID vector [id]

		{vector: <stmts>}

	| expr ;

		<expr>
		POP

	| RETURN ;

		RETURN0

	| RETURN expr ;

		<expr>
		RETURN

    	| TRY stmts_b {EXCEPT [id_i] ( codes_i ) stmts_i}+ ENDTRY

		<codes_1>
		PUSH_LABEL handler_1
		...
		<codes_N>
		PUSH_LABEL handler_N
		TRY_EXCEPT N
		<stmts_b>
		END_EXCEPT done
		...
	    handler_i:
		PUT id_i	; if <id_i> is supplied
		POP
		<stmts_i>
		JUMP done	; all but last handler
		...
	    done:

    	| TRY stmts_b FINALLY stmts_h ENDTRY

		TRY_FINALLY handler
		<stmts_b>
		END_FINALLY
	    handler:
		<stmts_h>
		CONTINUE

	| BREAK [id];
	| CONTINUE [id];

		EXIT <stack-level> <label>	; if there is no ID
		EXIT_ID <stack-level> <label>	; if there is an ID
	;

expr:
	  NUMBER
	| STRING
	| # NUMBER
	| # - NUMBER
	| ERROR

		NUM n		; if NUMBER and IN_OPTIM_NUM_RANGE(n)

		IMM v		; otherwise

	| id

		PUSH id

	| expr1 && expr2
	| expr1 || expr2

		<expr1>
		AND / OR done
		<expr2>
	    done:

	| - expr
	| ! expr

		<expr>
		UNARY_MINUS / NOT

	| $ id
	| expr1 . id
	| expr1 . ( expr2 )

		<expr1>
		<expr2>
		GET_PROP

	| expr1 == expr2
	| expr1 != expr2
	| expr1 < expr2
	| expr1 <= expr2
	| expr1 > expr2
	| expr1 >= expr2
	| expr1 IN expr2
	| expr1 + expr2
	| expr1 - expr2
	| expr1 * expr2
	| expr1 / expr2
	| expr1 % expr2
	| expr1 [ expr2 ]

		<expr1>
		<expr2>
		EQ / NE / LT / LE / GT / GE / IN / ADD / MINUS / MULT / DIV
		   / MOD / REF

	| expr1 [ expr2 .. expr3 ]

		<expr1>
		<expr2>
		<expr3>
		RANGE_REF

	| { arglist }

		<arglist>

	| id ( arglist )

		<arglist>
		BI_FUNC_CALL fn

	| expr1 : id ( arglist )
	| expr1 : ( expr2 ) ( arglist )

		<expr1>
		<expr2>
		<arglist>
		CALL_VERB

	| expr1 ? expr2 | expr3

		<expr1>
		IF_QUES else
		<expr2>
		JUMP done
	    else:
		<expr3>
	    done:
		
	| {id | expr_l1 . ( expr_l2 )}
			{[ expr_i ]}*
			{[ expr_r1 .. expr_r2 ]}? = expr_r

		PUSH id		; if id and indexed/subranged

		<expr_l1>	; if expr.expr
		<expr_l2>	;
		PUSH_GET_PROP	; if expr.expr and indexed/subranged

		...		; if indexed
		<expr_i>	;
		PUSH_REF	; if indexed/subranged further
		...		;

		<expr_r1>	; if subranged
		<expr_r2>	;

		<expr_r>

		PUT_TEMP	; if indexed/subranged

		RANGESET	; if subranged

		...		; if indexed
		INDEXSET	;
		...		;

		PUT		; if id

		PUT_PROP	; if expr.expr

		POP		; if indexed/subranged
		PUSH_TEMP	;

	| { scatter } = expr_r

		/* Example:
		 *    {a, ?b, ?c = expr_c, @d, ?e = expr_e, f} = expr_r
		 */

		<expr_r>
		SCATTER 6, 2, 4: a/0, b/1, c/default_c, d/0, e/default_e,
			^  ^  ^	 f/0, done
			|  |  |  ^
			|  |  |  |
			|  |  |  +-- list of id/label pairs + done label
			|  |  +----- 1-index of `@' argument (or # of args)
			|  +-------- number of required arguments
			+----------- number of arguments
	    default_c:
		<expr_c>
		PUT c
		POP
	    default_e:
		<expr_e>
		PUT e
		POP
	    done:

	| ` expr ! codes [=> expr_d] '

		<codes>
		PUSH_LABEL handler
		CATCH
		<expr>
		END_CATCH done
	    handler:
		NUM 1		; if <expr_d> is omitted
		REF		;

		POP		; if <expr_d> is supplied
		<expr_d>	;
	    done:

	;

codes:
	  ANY

		NUM 0

	| ne_arglist

		<ne_arglist>

arglist:
	  /* NOTHING */

		MAKE_EMPTY_LIST

        | ne_arglist

		<ne_arglist>

	;

ne_arglist:
	expr

		<expr>
		MAKE_SINGLETON_LIST

	| @ expr

		<expr>
		CHECK_LIST_FOR_SPLICE

	| ne_arglist , expr

		<ne_arglist>
		<expr>
		LIST_ADD_TAIL

	| ne_arglist , @ expr

		<ne_arglist>
		<expr>
		LIST_APPEND

	;


# $Log$
# Revision 1.1  1997/03/03 03:45:06  nop
# Initial revision
#
# Revision 2.3  1996/03/10  01:25:45  pavel
# Fixed a grammar problem.  Release 1.8.0.
#
# Revision 2.2  1996/02/08  05:43:09  pavel
# Added named WHILE loops and the BREAK and CONTINUE statements.
# Release 1.8.0beta1.
#
# Revision 2.1  1996/01/16  07:15:25  pavel
# Add support for scattering assignment.  Release 1.8.0alpha6.
#
# Revision 2.0  1995/11/30  05:41:16  pavel
# New baseline version, corresponding to release 1.8.0alpha1.
#
# Revision 1.1  1995/11/30  05:36:21  pavel
# Initial revision