diff options
author | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
commit | 38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch) | |
tree | adca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/lscript/lscript_compile/lscript_tree.cpp | |
parent | README.txt (diff) | |
download | meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2 meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz |
Second Life viewer sources 1.13.2.12
Diffstat (limited to 'linden/indra/lscript/lscript_compile/lscript_tree.cpp')
-rw-r--r-- | linden/indra/lscript/lscript_compile/lscript_tree.cpp | 10017 |
1 files changed, 10017 insertions, 0 deletions
diff --git a/linden/indra/lscript/lscript_compile/lscript_tree.cpp b/linden/indra/lscript/lscript_compile/lscript_tree.cpp new file mode 100644 index 0000000..bda09dd --- /dev/null +++ b/linden/indra/lscript/lscript_compile/lscript_tree.cpp | |||
@@ -0,0 +1,10017 @@ | |||
1 | /** | ||
2 | * @file lscript_tree.cpp | ||
3 | * @brief implements methods for lscript_tree.h classes | ||
4 | * | ||
5 | * Copyright (c) 2002-2007, Linden Research, Inc. | ||
6 | * | ||
7 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
8 | * to you under the terms of the GNU General Public License, version 2.0 | ||
9 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
10 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
11 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
12 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
13 | * | ||
14 | * There are special exceptions to the terms and conditions of the GPL as | ||
15 | * it is applied to this Source Code. View the full text of the exception | ||
16 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
17 | * online at http://secondlife.com/developers/opensource/flossexception | ||
18 | * | ||
19 | * By copying, modifying or distributing this software, you acknowledge | ||
20 | * that you have read and understood your obligations described above, | ||
21 | * and agree to abide by those obligations. | ||
22 | * | ||
23 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
24 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
25 | * COMPLETENESS OR PERFORMANCE. | ||
26 | */ | ||
27 | |||
28 | // TO DO: Move print functionality from .h file to here | ||
29 | |||
30 | #include "linden_common.h" | ||
31 | |||
32 | #include "lscript_tree.h" | ||
33 | #include "lscript_typecheck.h" | ||
34 | #include "lscript_resource.h" | ||
35 | #include "lscript_bytecode.h" | ||
36 | #include "lscript_heap.h" | ||
37 | #include "lscript_library.h" | ||
38 | #include "lscript_alloc.h" | ||
39 | |||
40 | //#define LSL_INCLUDE_DEBUG_INFO | ||
41 | |||
42 | void print_cil_box(FILE* fp, LSCRIPTType type) | ||
43 | { | ||
44 | switch(type) | ||
45 | { | ||
46 | case LST_INTEGER: | ||
47 | fprintf(fp, "box [mscorlib]System.Int32\n"); | ||
48 | break; | ||
49 | case LST_FLOATINGPOINT: | ||
50 | fprintf(fp, "box [mscorlib]System.Double\n"); | ||
51 | break; | ||
52 | case LST_STRING: | ||
53 | case LST_KEY: | ||
54 | fprintf(fp, "box [mscorlib]System.String\n"); | ||
55 | break; | ||
56 | case LST_VECTOR: | ||
57 | fprintf(fp, "box [LScriptLibrary]LLVector\n"); | ||
58 | break; | ||
59 | case LST_QUATERNION: | ||
60 | fprintf(fp, "box [LScriptLibrary]LLQuaternion\n"); | ||
61 | break; | ||
62 | default: | ||
63 | break; | ||
64 | } | ||
65 | } | ||
66 | |||
67 | void print_cil_type(FILE* fp, LSCRIPTType type) | ||
68 | { | ||
69 | switch(type) | ||
70 | { | ||
71 | case LST_INTEGER: | ||
72 | fprintf(fp, "int32"); | ||
73 | break; | ||
74 | case LST_FLOATINGPOINT: | ||
75 | fprintf(fp, "float32"); | ||
76 | break; | ||
77 | case LST_STRING: | ||
78 | case LST_KEY: | ||
79 | fprintf(fp, "string"); | ||
80 | break; | ||
81 | case LST_VECTOR: | ||
82 | fprintf(fp, "valuetype [LScriptLibrary]LLVector"); | ||
83 | break; | ||
84 | case LST_QUATERNION: | ||
85 | fprintf(fp, "valuetype [LScriptLibrary]LLQuaternion"); | ||
86 | break; | ||
87 | case LST_LIST: | ||
88 | fprintf(fp, "class [mscorlib]System.Collections.ArrayList"); | ||
89 | break; | ||
90 | case LST_NULL: | ||
91 | fprintf(fp, "void"); | ||
92 | break; | ||
93 | default: | ||
94 | break; | ||
95 | } | ||
96 | } | ||
97 | |||
98 | void LLScriptType::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
99 | { | ||
100 | if (gErrorToText.getErrors()) | ||
101 | { | ||
102 | return; | ||
103 | } | ||
104 | switch(pass) | ||
105 | { | ||
106 | case LSCP_PRETTY_PRINT: | ||
107 | case LSCP_EMIT_ASSEMBLY: | ||
108 | fprintf(fp,"%s",LSCRIPTTypeNames[mType]); | ||
109 | break; | ||
110 | case LSCP_TYPE: | ||
111 | type = mType; | ||
112 | break; | ||
113 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
114 | print_cil_type(fp, mType); | ||
115 | break; | ||
116 | default: | ||
117 | break; | ||
118 | } | ||
119 | } | ||
120 | |||
121 | S32 LLScriptType::getSize() | ||
122 | { | ||
123 | return LSCRIPTDataSize[mType]; | ||
124 | } | ||
125 | |||
126 | void LLScriptConstant::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
127 | { | ||
128 | if (gErrorToText.getErrors()) | ||
129 | { | ||
130 | return; | ||
131 | } | ||
132 | switch(pass) | ||
133 | { | ||
134 | case LSCP_PRETTY_PRINT: | ||
135 | case LSCP_EMIT_ASSEMBLY: | ||
136 | fprintf(fp,"Script Constant Base class -- should never get here!\n"); | ||
137 | break; | ||
138 | default: | ||
139 | break; | ||
140 | } | ||
141 | } | ||
142 | |||
143 | S32 LLScriptConstant::getSize() | ||
144 | { | ||
145 | printf("Script Constant Base class -- should never get here!\n"); | ||
146 | return 0; | ||
147 | } | ||
148 | |||
149 | |||
150 | |||
151 | void LLScriptConstantInteger::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
152 | { | ||
153 | if (gErrorToText.getErrors()) | ||
154 | { | ||
155 | return; | ||
156 | } | ||
157 | switch(pass) | ||
158 | { | ||
159 | case LSCP_PRETTY_PRINT: | ||
160 | fprintf(fp, "%d", mValue); | ||
161 | break; | ||
162 | case LSCP_EMIT_ASSEMBLY: | ||
163 | fprintf(fp, "PUSHARGI %d\n", mValue); | ||
164 | break; | ||
165 | case LSCP_TYPE: | ||
166 | type = mType; | ||
167 | break; | ||
168 | case LSCP_EMIT_BYTE_CODE: | ||
169 | { | ||
170 | chunk->addInteger(mValue); | ||
171 | type = mType; | ||
172 | } | ||
173 | break; | ||
174 | case LSCP_TO_STACK: | ||
175 | { | ||
176 | chunk->addByte(LSCRIPTOpCodes[LOPC_PUSHARGI]); | ||
177 | chunk->addInteger(mValue); | ||
178 | type = mType; | ||
179 | } | ||
180 | break; | ||
181 | case LSCP_LIST_BUILD_SIMPLE: | ||
182 | { | ||
183 | *ldata = new LLScriptLibData(mValue); | ||
184 | } | ||
185 | break; | ||
186 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
187 | fprintf(fp, "ldc.i4 %d\n", mValue); | ||
188 | break; | ||
189 | default: | ||
190 | break; | ||
191 | } | ||
192 | } | ||
193 | |||
194 | S32 LLScriptConstantInteger::getSize() | ||
195 | { | ||
196 | return LSCRIPTDataSize[LST_INTEGER]; | ||
197 | } | ||
198 | |||
199 | void LLScriptConstantFloat::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
200 | { | ||
201 | if (gErrorToText.getErrors()) | ||
202 | { | ||
203 | return; | ||
204 | } | ||
205 | switch(pass) | ||
206 | { | ||
207 | case LSCP_PRETTY_PRINT: | ||
208 | fprintf(fp, "%5.5f", mValue); | ||
209 | break; | ||
210 | case LSCP_EMIT_ASSEMBLY: | ||
211 | fprintf(fp, "PUSHARGF %5.5f\n", mValue); | ||
212 | break; | ||
213 | case LSCP_TYPE: | ||
214 | type = mType; | ||
215 | break; | ||
216 | case LSCP_EMIT_BYTE_CODE: | ||
217 | { | ||
218 | chunk->addFloat(mValue); | ||
219 | type = mType; | ||
220 | } | ||
221 | break; | ||
222 | case LSCP_TO_STACK: | ||
223 | { | ||
224 | chunk->addByte(LSCRIPTOpCodes[LOPC_PUSHARGF]); | ||
225 | chunk->addFloat(mValue); | ||
226 | type = mType; | ||
227 | } | ||
228 | break; | ||
229 | case LSCP_LIST_BUILD_SIMPLE: | ||
230 | { | ||
231 | *ldata = new LLScriptLibData(mValue); | ||
232 | } | ||
233 | break; | ||
234 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
235 | fprintf(fp, "ldc.r8 %5.5f\n", mValue); // NOTE: Precision? | ||
236 | default: | ||
237 | break; | ||
238 | } | ||
239 | } | ||
240 | |||
241 | S32 LLScriptConstantFloat::getSize() | ||
242 | { | ||
243 | return LSCRIPTDataSize[LST_FLOATINGPOINT]; | ||
244 | } | ||
245 | |||
246 | void print_escape_quotes(FILE* fp, const char* str) | ||
247 | { | ||
248 | putc('"', fp); | ||
249 | for(const char* c = str; *c != '\0'; ++c) | ||
250 | { | ||
251 | if(*c == '"') | ||
252 | { | ||
253 | putc('\\', fp); | ||
254 | } | ||
255 | putc(*c, fp); | ||
256 | } | ||
257 | putc('"', fp); | ||
258 | } | ||
259 | |||
260 | void LLScriptConstantString::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
261 | { | ||
262 | if (gErrorToText.getErrors()) | ||
263 | { | ||
264 | return; | ||
265 | } | ||
266 | switch(pass) | ||
267 | { | ||
268 | case LSCP_PRETTY_PRINT: | ||
269 | fprintf(fp, "\"%s\"", mValue); | ||
270 | break; | ||
271 | case LSCP_EMIT_ASSEMBLY: | ||
272 | fprintf(fp, "PUSHARGS \"%s\"\n", mValue); | ||
273 | fprintf(fp, "STACKTOS %lu\n", strlen(mValue) + 1); | ||
274 | break; | ||
275 | case LSCP_TYPE: | ||
276 | type = mType; | ||
277 | break; | ||
278 | case LSCP_EMIT_BYTE_CODE: | ||
279 | { | ||
280 | chunk->addInteger(heap->mCurrentOffset + 1); | ||
281 | LLScriptLibData *data = new LLScriptLibData(mValue); | ||
282 | U8 *temp; | ||
283 | S32 size = lsa_create_data_block(&temp, data, heap->mCurrentOffset); | ||
284 | |||
285 | heap->addBytes(temp, size); | ||
286 | delete [] temp; | ||
287 | delete data; | ||
288 | } | ||
289 | break; | ||
290 | case LSCP_TO_STACK: | ||
291 | { | ||
292 | chunk->addByte(LSCRIPTOpCodes[LOPC_PUSHARGS]); | ||
293 | chunk->addBytes(mValue, (S32)strlen(mValue) + 1); | ||
294 | type = mType; | ||
295 | } | ||
296 | break; | ||
297 | case LSCP_LIST_BUILD_SIMPLE: | ||
298 | { | ||
299 | *ldata = new LLScriptLibData(mValue); | ||
300 | } | ||
301 | break; | ||
302 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
303 | fprintf(fp, "ldstr "); | ||
304 | print_escape_quotes(fp, mValue); | ||
305 | fprintf(fp, "\n"); | ||
306 | default: | ||
307 | break; | ||
308 | } | ||
309 | } | ||
310 | |||
311 | S32 LLScriptConstantString::getSize() | ||
312 | { | ||
313 | return (S32)strlen(mValue) + 1; | ||
314 | } | ||
315 | |||
316 | |||
317 | void LLScriptIdentifier::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
318 | { | ||
319 | if (gErrorToText.getErrors()) | ||
320 | { | ||
321 | return; | ||
322 | } | ||
323 | switch(pass) | ||
324 | { | ||
325 | case LSCP_PRETTY_PRINT: | ||
326 | fprintf(fp, "%s", mName); | ||
327 | break; | ||
328 | case LSCP_EMIT_ASSEMBLY: | ||
329 | if (mScopeEntry) | ||
330 | { | ||
331 | if (mScopeEntry->mIDType == LIT_VARIABLE) | ||
332 | { | ||
333 | fprintf(fp, "$BP + %d [%s]", mScopeEntry->mOffset, mName); | ||
334 | } | ||
335 | else if (mScopeEntry->mIDType == LIT_GLOBAL) | ||
336 | { | ||
337 | fprintf(fp, "$GVR + %d [%s]", mScopeEntry->mOffset, mName); | ||
338 | } | ||
339 | else | ||
340 | { | ||
341 | fprintf(fp, "%s", mName); | ||
342 | } | ||
343 | } | ||
344 | break; | ||
345 | case LSCP_TYPE: | ||
346 | if (mScopeEntry) | ||
347 | type = mScopeEntry->mType; | ||
348 | else | ||
349 | type = LST_NULL; | ||
350 | break; | ||
351 | case LSCP_RESOURCE: | ||
352 | if (mScopeEntry) | ||
353 | { | ||
354 | if (mScopeEntry->mIDType == LIT_VARIABLE) | ||
355 | { | ||
356 | // fprintf(fp, "LOCAL : %d : %d : %s\n", mScopeEntry->mOffset, mScopeEntry->mSize, mName); | ||
357 | } | ||
358 | else if (mScopeEntry->mIDType == LIT_GLOBAL) | ||
359 | { | ||
360 | // fprintf(fp, "GLOBAL: %d : %d : %s\n", mScopeEntry->mOffset, mScopeEntry->mSize, mName); | ||
361 | } | ||
362 | } | ||
363 | break; | ||
364 | case LSCP_LIST_BUILD_SIMPLE: | ||
365 | { | ||
366 | if (mScopeEntry) | ||
367 | { | ||
368 | if (mScopeEntry->mType == LST_LIST) | ||
369 | { | ||
370 | gErrorToText.writeError(fp, this, LSERROR_NO_LISTS_IN_LISTS); | ||
371 | } | ||
372 | else if (mScopeEntry->mAssignable) | ||
373 | { | ||
374 | mScopeEntry->mAssignable->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, ldata); | ||
375 | } | ||
376 | else | ||
377 | { | ||
378 | gErrorToText.writeError(fp, this, LSERROR_NO_UNITIALIZED_VARIABLES_IN_LISTS); | ||
379 | } | ||
380 | } | ||
381 | else | ||
382 | { | ||
383 | gErrorToText.writeError(fp, this, LSERROR_UNDEFINED_NAME); | ||
384 | } | ||
385 | } | ||
386 | break; | ||
387 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
388 | fprintf(fp, "%s", mName); | ||
389 | break; | ||
390 | default: | ||
391 | break; | ||
392 | } | ||
393 | } | ||
394 | |||
395 | S32 LLScriptIdentifier::getSize() | ||
396 | { | ||
397 | |||
398 | return 0; | ||
399 | } | ||
400 | |||
401 | |||
402 | |||
403 | void LLScriptSimpleAssignable::addAssignable(LLScriptSimpleAssignable *assign) | ||
404 | { | ||
405 | if (mNextp) | ||
406 | { | ||
407 | assign->mNextp = mNextp; | ||
408 | } | ||
409 | mNextp = assign; | ||
410 | } | ||
411 | |||
412 | void LLScriptSimpleAssignable::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
413 | { | ||
414 | if (gErrorToText.getErrors()) | ||
415 | { | ||
416 | return; | ||
417 | } | ||
418 | fprintf(fp, "Simple Assignable Base Class -- should never get here!\n"); | ||
419 | } | ||
420 | |||
421 | S32 LLScriptSimpleAssignable::getSize() | ||
422 | { | ||
423 | |||
424 | printf("Simple Assignable Base Class -- should never get here!\n"); | ||
425 | return 0; | ||
426 | } | ||
427 | |||
428 | void LLScriptSAIdentifier::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
429 | { | ||
430 | if (gErrorToText.getErrors()) | ||
431 | { | ||
432 | return; | ||
433 | } | ||
434 | switch(pass) | ||
435 | { | ||
436 | case LSCP_PRETTY_PRINT: | ||
437 | case LSCP_EMIT_ASSEMBLY: | ||
438 | mIdentifier->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
439 | if (mNextp) | ||
440 | { | ||
441 | fprintf(fp, ", "); | ||
442 | mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
443 | } | ||
444 | break; | ||
445 | case LSCP_SCOPE_PASS1: | ||
446 | { | ||
447 | LLScriptScopeEntry *entry = scope->findEntry(mIdentifier->mName); | ||
448 | if (!entry) | ||
449 | { | ||
450 | gErrorToText.writeError(fp, this, LSERROR_UNDEFINED_NAME); | ||
451 | } | ||
452 | else | ||
453 | { | ||
454 | // if we did find it, make sure this identifier is associated with the correct scope entry | ||
455 | mIdentifier->mScopeEntry = entry; | ||
456 | } | ||
457 | if (mNextp) | ||
458 | { | ||
459 | mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
460 | } | ||
461 | } | ||
462 | break; | ||
463 | case LSCP_EMIT_BYTE_CODE: | ||
464 | { | ||
465 | if (mIdentifier->mScopeEntry) | ||
466 | { | ||
467 | if(mIdentifier->mScopeEntry->mAssignable) | ||
468 | { | ||
469 | mIdentifier->mScopeEntry->mAssignable->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
470 | } | ||
471 | else | ||
472 | { | ||
473 | // Babbage: 29/8/06: If the scope entry has no mAssignable, | ||
474 | // set the default type and add the default 0 value to the | ||
475 | // chunk. Without this SAVectors and SAQuaternions will | ||
476 | // assume the arbitrary current type is the assignable type | ||
477 | // and may attempt to access a null chunk. (SL-20156) | ||
478 | type = mIdentifier->mScopeEntry->mType; | ||
479 | chunk->addBytes(LSCRIPTDataSize[type]); | ||
480 | } | ||
481 | } | ||
482 | if (mNextp) | ||
483 | { | ||
484 | mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
485 | } | ||
486 | } | ||
487 | break; | ||
488 | case LSCP_LIST_BUILD_SIMPLE: | ||
489 | { | ||
490 | mIdentifier->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, ldata); | ||
491 | if (mNextp) | ||
492 | { | ||
493 | mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, &(*ldata)->mListp); | ||
494 | } | ||
495 | } | ||
496 | break; | ||
497 | default: | ||
498 | mIdentifier->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
499 | if (mNextp) | ||
500 | { | ||
501 | mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
502 | } | ||
503 | break; | ||
504 | } | ||
505 | } | ||
506 | |||
507 | S32 LLScriptSAIdentifier::getSize() | ||
508 | { | ||
509 | return mIdentifier->getSize(); | ||
510 | } | ||
511 | |||
512 | void LLScriptSAConstant::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
513 | { | ||
514 | if (gErrorToText.getErrors()) | ||
515 | { | ||
516 | return; | ||
517 | } | ||
518 | switch(pass) | ||
519 | { | ||
520 | case LSCP_PRETTY_PRINT: | ||
521 | case LSCP_EMIT_ASSEMBLY: | ||
522 | mConstant->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
523 | if (mNextp) | ||
524 | { | ||
525 | fprintf(fp, ", "); | ||
526 | mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
527 | } | ||
528 | break; | ||
529 | case LSCP_LIST_BUILD_SIMPLE: | ||
530 | { | ||
531 | mConstant->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, ldata); | ||
532 | if (mNextp) | ||
533 | { | ||
534 | mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, &(*ldata)->mListp); | ||
535 | } | ||
536 | } | ||
537 | break; | ||
538 | default: | ||
539 | mConstant->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
540 | if (mNextp) | ||
541 | { | ||
542 | mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
543 | } | ||
544 | break; | ||
545 | } | ||
546 | } | ||
547 | |||
548 | S32 LLScriptSAConstant::getSize() | ||
549 | { | ||
550 | return mConstant->getSize(); | ||
551 | } | ||
552 | |||
553 | void print_cil_cast(FILE* fp, LSCRIPTType srcType, LSCRIPTType targetType) | ||
554 | { | ||
555 | switch(srcType) | ||
556 | { | ||
557 | case LST_INTEGER: | ||
558 | switch(targetType) | ||
559 | { | ||
560 | case LST_FLOATINGPOINT: | ||
561 | fprintf(fp, "conv.r8\n"); | ||
562 | break; | ||
563 | case LST_STRING: | ||
564 | fprintf(fp, "call string class [mscorlib]System.Convert::ToString(int32)\n"); | ||
565 | break; | ||
566 | case LST_LIST: | ||
567 | fprintf(fp, "box [mscorlib]System.Int32\n"); | ||
568 | fprintf(fp, "call class [mscorlib]System.Collections.ArrayList class [LScriptLibrary]LScriptInternal::CreateList()\n"); | ||
569 | fprintf(fp, "call class [mscorlib]System.Collections.ArrayList class [LScriptLibrary]LScriptInternal::AddReturnList(object, class [mscorlib]System.Collections.ArrayList)\n"); | ||
570 | break; | ||
571 | default: | ||
572 | break; | ||
573 | } | ||
574 | break; | ||
575 | case LST_FLOATINGPOINT: | ||
576 | switch(targetType) | ||
577 | { | ||
578 | case LST_INTEGER: | ||
579 | fprintf(fp, "conv.i4\n"); | ||
580 | break; | ||
581 | case LST_STRING: | ||
582 | fprintf(fp, "call string class [mscorlib]System.Convert::ToString(float32)\n"); | ||
583 | break; | ||
584 | case LST_LIST: | ||
585 | fprintf(fp, "call class [mscorlib]System.Collections.ArrayList [LScriptLibrary]LScriptInternal::CreateList(object)\n"); | ||
586 | break; | ||
587 | default: | ||
588 | break; | ||
589 | } | ||
590 | break; | ||
591 | case LST_STRING: | ||
592 | switch(targetType) | ||
593 | { | ||
594 | case LST_INTEGER: | ||
595 | fprintf(fp, "call int32 valuetype [mscorlib]System.Int32::Parse(string)\n"); | ||
596 | break; | ||
597 | case LST_FLOATINGPOINT: | ||
598 | fprintf(fp, "call float64 valuetype [mscorlib]System.Double::Parse(string)\n"); | ||
599 | break; | ||
600 | case LST_LIST: | ||
601 | fprintf(fp, "call class [mscorlib]System.Collections.ArrayList [LScriptLibrary]LScriptInternal::CreateList(object)\n"); | ||
602 | break; | ||
603 | case LST_VECTOR: | ||
604 | fprintf(fp, "call valuetype [LScriptLibrary]LLVector valuetype [LScriptLibrary]LLVector::'Parse'(string)\n"); | ||
605 | break; | ||
606 | case LST_QUATERNION: | ||
607 | fprintf(fp, "call valuetype [LScriptLibrary]LLQuaternion valuetype [LScriptLibrary]LLQuaternion::'Parse'(string)\n"); | ||
608 | break; | ||
609 | default: | ||
610 | break; | ||
611 | } | ||
612 | break; | ||
613 | case LST_KEY: | ||
614 | switch(targetType) | ||
615 | { | ||
616 | case LST_KEY: | ||
617 | break; | ||
618 | case LST_STRING: | ||
619 | break; | ||
620 | case LST_LIST: | ||
621 | fprintf(fp, "call class [mscorlib]System.Collections.ArrayList [LScriptLibrary]LScriptInternal::CreateList(object)\n"); | ||
622 | break; | ||
623 | default: | ||
624 | break; | ||
625 | } | ||
626 | break; | ||
627 | case LST_VECTOR: | ||
628 | switch(targetType) | ||
629 | { | ||
630 | case LST_VECTOR: | ||
631 | break; | ||
632 | case LST_STRING: | ||
633 | fprintf(fp, "call string valuetype [LScriptLibrary]LLVector::'ToString'(valuetype [LScriptLibrary]LLVector)\n"); | ||
634 | break; | ||
635 | case LST_LIST: | ||
636 | fprintf(fp, "call class [mscorlib]System.Collections.ArrayList [LScriptLibrary]LScriptInternal::CreateList(object)\n"); | ||
637 | break; | ||
638 | default: | ||
639 | break; | ||
640 | } | ||
641 | break; | ||
642 | case LST_QUATERNION: | ||
643 | switch(targetType) | ||
644 | { | ||
645 | case LST_QUATERNION: | ||
646 | break; | ||
647 | case LST_STRING: | ||
648 | fprintf(fp, "call string valuetype [LScriptLibrary]LLQuaternion::'ToString'(valuetype [LScriptLibrary]LLQuaternion)\n"); | ||
649 | break; | ||
650 | case LST_LIST: | ||
651 | fprintf(fp, "call class [mscorlib]System.Collections.ArrayList [LScriptLibrary]LScriptInternal::CreateList(object)\n"); | ||
652 | break; | ||
653 | default: | ||
654 | break; | ||
655 | } | ||
656 | break; | ||
657 | case LST_LIST: | ||
658 | switch(targetType) | ||
659 | { | ||
660 | case LST_LIST: | ||
661 | break; | ||
662 | case LST_STRING: | ||
663 | fprintf(fp, "call string [LScriptLibrary]LScriptInternal::ListToString(class [mscorlib]System.Collections.ArrayList)\n"); | ||
664 | break; | ||
665 | default: | ||
666 | break; | ||
667 | } | ||
668 | break; | ||
669 | default: | ||
670 | break; | ||
671 | } | ||
672 | } | ||
673 | |||
674 | bool is_SA_constant_integer(LLScriptSimpleAssignable* sa) | ||
675 | { | ||
676 | // HACK: Downcast based on type. | ||
677 | return (sa->mType == LSSAT_CONSTANT && ((LLScriptSAConstant*) sa)->mConstant->mType == LST_INTEGER); | ||
678 | } | ||
679 | |||
680 | void LLScriptSAVector::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
681 | { | ||
682 | if (gErrorToText.getErrors()) | ||
683 | { | ||
684 | return; | ||
685 | } | ||
686 | switch(pass) | ||
687 | { | ||
688 | case LSCP_PRETTY_PRINT: | ||
689 | case LSCP_EMIT_ASSEMBLY: | ||
690 | fprintf(fp, "< "); | ||
691 | mEntry3->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
692 | fprintf(fp, ", "); | ||
693 | mEntry2->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
694 | fprintf(fp, ", "); | ||
695 | mEntry1->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
696 | fprintf(fp, " >"); | ||
697 | if (mNextp) | ||
698 | { | ||
699 | fprintf(fp, ", "); | ||
700 | mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
701 | } | ||
702 | break; | ||
703 | case LSCP_TYPE: | ||
704 | // vector's take floats | ||
705 | mEntry3->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
706 | if (!legal_assignment(LST_FLOATINGPOINT, type)) | ||
707 | { | ||
708 | gErrorToText.writeError(fp, this, LSERROR_TYPE_MISMATCH); | ||
709 | } | ||
710 | mEntry2->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
711 | if (!legal_assignment(LST_FLOATINGPOINT, type)) | ||
712 | { | ||
713 | gErrorToText.writeError(fp, this, LSERROR_TYPE_MISMATCH); | ||
714 | } | ||
715 | mEntry1->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
716 | if (!legal_assignment(LST_FLOATINGPOINT, type)) | ||
717 | { | ||
718 | gErrorToText.writeError(fp, this, LSERROR_TYPE_MISMATCH); | ||
719 | } | ||
720 | type = LST_VECTOR; | ||
721 | if (mNextp) | ||
722 | { | ||
723 | mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
724 | } | ||
725 | break; | ||
726 | case LSCP_EMIT_BYTE_CODE: | ||
727 | mEntry3->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
728 | if (type == LST_INTEGER) | ||
729 | { | ||
730 | S32 offset = chunk->mCurrentOffset - 4; | ||
731 | bytestream_int2float(chunk->mCodeChunk, offset); | ||
732 | } | ||
733 | mEntry2->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
734 | if (type == LST_INTEGER) | ||
735 | { | ||
736 | S32 offset = chunk->mCurrentOffset - 4; | ||
737 | bytestream_int2float(chunk->mCodeChunk, offset); | ||
738 | } | ||
739 | mEntry1->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
740 | if (type == LST_INTEGER) | ||
741 | { | ||
742 | S32 offset = chunk->mCurrentOffset - 4; | ||
743 | bytestream_int2float(chunk->mCodeChunk, offset); | ||
744 | } | ||
745 | if (mNextp) | ||
746 | { | ||
747 | mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
748 | } | ||
749 | break; | ||
750 | case LSCP_LIST_BUILD_SIMPLE: | ||
751 | { | ||
752 | LLScriptByteCodeChunk *list = new LLScriptByteCodeChunk(FALSE); | ||
753 | mEntry3->recurse(fp, tabs, tabsize, LSCP_EMIT_BYTE_CODE, ptype, prunearg, scope, type, basetype, count, list, heap, stacksize, entry, entrycount, NULL); | ||
754 | if (type == LST_INTEGER) | ||
755 | { | ||
756 | S32 offset = list->mCurrentOffset - 4; | ||
757 | bytestream_int2float(list->mCodeChunk, offset); | ||
758 | } | ||
759 | mEntry2->recurse(fp, tabs, tabsize, LSCP_EMIT_BYTE_CODE, ptype, prunearg, scope, type, basetype, count, list, heap, stacksize, entry, entrycount, NULL); | ||
760 | if (type == LST_INTEGER) | ||
761 | { | ||
762 | S32 offset = list->mCurrentOffset - 4; | ||
763 | bytestream_int2float(list->mCodeChunk, offset); | ||
764 | } | ||
765 | mEntry1->recurse(fp, tabs, tabsize, LSCP_EMIT_BYTE_CODE, ptype, prunearg, scope, type, basetype, count, list, heap, stacksize, entry, entrycount, NULL); | ||
766 | if (type == LST_INTEGER) | ||
767 | { | ||
768 | S32 offset = list->mCurrentOffset - 4; | ||
769 | bytestream_int2float(list->mCodeChunk, offset); | ||
770 | } | ||
771 | LLVector3 vec; | ||
772 | S32 offset = 0; | ||
773 | bytestream2vector(vec, list->mCodeChunk, offset); | ||
774 | *ldata = new LLScriptLibData(vec); | ||
775 | delete list; | ||
776 | if (mNextp) | ||
777 | { | ||
778 | mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, &(*ldata)->mListp); | ||
779 | } | ||
780 | } | ||
781 | break; | ||
782 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
783 | |||
784 | // Load arguments. | ||
785 | mEntry1->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
786 | if(is_SA_constant_integer(mEntry1)) | ||
787 | { | ||
788 | print_cil_cast(fp, LST_INTEGER, LST_FLOATINGPOINT); | ||
789 | } | ||
790 | mEntry2->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
791 | if(is_SA_constant_integer(mEntry3)) | ||
792 | { | ||
793 | print_cil_cast(fp, LST_INTEGER, LST_FLOATINGPOINT); | ||
794 | } | ||
795 | mEntry3->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
796 | if(is_SA_constant_integer(mEntry3)) | ||
797 | { | ||
798 | print_cil_cast(fp, LST_INTEGER, LST_FLOATINGPOINT); | ||
799 | } | ||
800 | |||
801 | // Call named ctor, which leaves new Vector on stack, so it can be saved in to local or argument just like a primitive type. | ||
802 | fprintf(fp, "call valuetype [LScriptLibrary]LLVector valuetype [LScriptLibrary]LLVector::'create'(float32, float32, float32)\n"); | ||
803 | |||
804 | // Next. | ||
805 | if (mNextp) | ||
806 | { | ||
807 | mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
808 | } | ||
809 | break; | ||
810 | default: | ||
811 | mEntry3->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
812 | mEntry2->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
813 | mEntry1->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
814 | if (mNextp) | ||
815 | { | ||
816 | mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
817 | } | ||
818 | break; | ||
819 | } | ||
820 | } | ||
821 | |||
822 | S32 LLScriptSAVector::getSize() | ||
823 | { | ||
824 | return mEntry1->getSize() + mEntry2->getSize() + mEntry3->getSize(); | ||
825 | } | ||
826 | |||
827 | void LLScriptSAQuaternion::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
828 | { | ||
829 | if (gErrorToText.getErrors()) | ||
830 | { | ||
831 | return; | ||
832 | } | ||
833 | switch(pass) | ||
834 | { | ||
835 | case LSCP_PRETTY_PRINT: | ||
836 | case LSCP_EMIT_ASSEMBLY: | ||
837 | fprintf(fp, "< "); | ||
838 | mEntry4->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
839 | fprintf(fp, ", "); | ||
840 | mEntry3->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
841 | fprintf(fp, ", "); | ||
842 | mEntry2->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
843 | fprintf(fp, ", "); | ||
844 | mEntry1->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
845 | fprintf(fp, " >"); | ||
846 | if (mNextp) | ||
847 | { | ||
848 | fprintf(fp, ", "); | ||
849 | mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
850 | } | ||
851 | break; | ||
852 | case LSCP_TYPE: | ||
853 | // vector's take floats | ||
854 | mEntry4->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
855 | if (!legal_assignment(LST_FLOATINGPOINT, type)) | ||
856 | { | ||
857 | gErrorToText.writeError(fp, this, LSERROR_TYPE_MISMATCH); | ||
858 | } | ||
859 | mEntry3->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
860 | if (!legal_assignment(LST_FLOATINGPOINT, type)) | ||
861 | { | ||
862 | gErrorToText.writeError(fp, this, LSERROR_TYPE_MISMATCH); | ||
863 | } | ||
864 | mEntry2->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
865 | if (!legal_assignment(LST_FLOATINGPOINT, type)) | ||
866 | { | ||
867 | gErrorToText.writeError(fp, this, LSERROR_TYPE_MISMATCH); | ||
868 | } | ||
869 | mEntry1->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
870 | if (!legal_assignment(LST_FLOATINGPOINT, type)) | ||
871 | { | ||
872 | gErrorToText.writeError(fp, this, LSERROR_TYPE_MISMATCH); | ||
873 | } | ||
874 | type = LST_QUATERNION; | ||
875 | if (mNextp) | ||
876 | { | ||
877 | mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
878 | } | ||
879 | break; | ||
880 | case LSCP_EMIT_BYTE_CODE: | ||
881 | mEntry4->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
882 | if (type == LST_INTEGER) | ||
883 | { | ||
884 | S32 offset = chunk->mCurrentOffset - 4; | ||
885 | bytestream_int2float(chunk->mCodeChunk, offset); | ||
886 | } | ||
887 | mEntry3->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
888 | if (type == LST_INTEGER) | ||
889 | { | ||
890 | S32 offset = chunk->mCurrentOffset - 4; | ||
891 | bytestream_int2float(chunk->mCodeChunk, offset); | ||
892 | } | ||
893 | mEntry2->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
894 | if (type == LST_INTEGER) | ||
895 | { | ||
896 | S32 offset = chunk->mCurrentOffset - 4; | ||
897 | bytestream_int2float(chunk->mCodeChunk, offset); | ||
898 | } | ||
899 | mEntry1->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
900 | if (type == LST_INTEGER) | ||
901 | { | ||
902 | S32 offset = chunk->mCurrentOffset - 4; | ||
903 | bytestream_int2float(chunk->mCodeChunk, offset); | ||
904 | } | ||
905 | if (mNextp) | ||
906 | { | ||
907 | mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
908 | } | ||
909 | break; | ||
910 | case LSCP_LIST_BUILD_SIMPLE: | ||
911 | { | ||
912 | LLScriptByteCodeChunk *list = new LLScriptByteCodeChunk(FALSE); | ||
913 | mEntry4->recurse(fp, tabs, tabsize, LSCP_EMIT_BYTE_CODE, ptype, prunearg, scope, type, basetype, count, list, heap, stacksize, entry, entrycount, NULL); | ||
914 | if (type == LST_INTEGER) | ||
915 | { | ||
916 | S32 offset = list->mCurrentOffset - 4; | ||
917 | bytestream_int2float(list->mCodeChunk, offset); | ||
918 | } | ||
919 | mEntry3->recurse(fp, tabs, tabsize, LSCP_EMIT_BYTE_CODE, ptype, prunearg, scope, type, basetype, count, list, heap, stacksize, entry, entrycount, NULL); | ||
920 | if (type == LST_INTEGER) | ||
921 | { | ||
922 | S32 offset = list->mCurrentOffset - 4; | ||
923 | bytestream_int2float(list->mCodeChunk, offset); | ||
924 | } | ||
925 | mEntry2->recurse(fp, tabs, tabsize, LSCP_EMIT_BYTE_CODE, ptype, prunearg, scope, type, basetype, count, list, heap, stacksize, entry, entrycount, NULL); | ||
926 | if (type == LST_INTEGER) | ||
927 | { | ||
928 | S32 offset = list->mCurrentOffset - 4; | ||
929 | bytestream_int2float(list->mCodeChunk, offset); | ||
930 | } | ||
931 | mEntry1->recurse(fp, tabs, tabsize, LSCP_EMIT_BYTE_CODE, ptype, prunearg, scope, type, basetype, count, list, heap, stacksize, entry, entrycount, NULL); | ||
932 | if (type == LST_INTEGER) | ||
933 | { | ||
934 | S32 offset = list->mCurrentOffset - 4; | ||
935 | bytestream_int2float(list->mCodeChunk, offset); | ||
936 | } | ||
937 | LLQuaternion quat; | ||
938 | S32 offset = 0; | ||
939 | bytestream2quaternion(quat, list->mCodeChunk, offset); | ||
940 | *ldata = new LLScriptLibData(quat); | ||
941 | delete list; | ||
942 | if (mNextp) | ||
943 | { | ||
944 | mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, &(*ldata)->mListp); | ||
945 | } | ||
946 | } | ||
947 | break; | ||
948 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
949 | |||
950 | // Load arguments. | ||
951 | mEntry1->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
952 | if(is_SA_constant_integer(mEntry1)) | ||
953 | { | ||
954 | print_cil_cast(fp, LST_INTEGER, LST_FLOATINGPOINT); | ||
955 | } | ||
956 | mEntry2->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
957 | if(is_SA_constant_integer(mEntry2)) | ||
958 | { | ||
959 | print_cil_cast(fp, LST_INTEGER, LST_FLOATINGPOINT); | ||
960 | } | ||
961 | mEntry3->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
962 | if(is_SA_constant_integer(mEntry3)) | ||
963 | { | ||
964 | print_cil_cast(fp, LST_INTEGER, LST_FLOATINGPOINT); | ||
965 | } | ||
966 | mEntry4->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
967 | if(is_SA_constant_integer(mEntry4)) | ||
968 | { | ||
969 | print_cil_cast(fp, LST_INTEGER, LST_FLOATINGPOINT); | ||
970 | } | ||
971 | |||
972 | // Call named ctor, which leaves new Vector on stack, so it can be saved in to local or argument just like a primitive type. | ||
973 | fprintf(fp, "call valuetype [LScriptLibrary]LLQuaternion valuetype [LScriptLibrary]LLQuaternion::'create'(float32, float32, float32, float32)\n"); | ||
974 | |||
975 | // Next. | ||
976 | if (mNextp) | ||
977 | { | ||
978 | mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
979 | } | ||
980 | break; | ||
981 | default: | ||
982 | mEntry4->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
983 | mEntry3->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
984 | mEntry2->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
985 | mEntry1->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
986 | if (mNextp) | ||
987 | { | ||
988 | mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
989 | } | ||
990 | break; | ||
991 | } | ||
992 | } | ||
993 | |||
994 | S32 LLScriptSAQuaternion::getSize() | ||
995 | { | ||
996 | return mEntry1->getSize() + mEntry2->getSize() + mEntry3->getSize() + mEntry4->getSize(); | ||
997 | } | ||
998 | |||
999 | void LLScriptSAList::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
1000 | { | ||
1001 | if (gErrorToText.getErrors()) | ||
1002 | { | ||
1003 | return; | ||
1004 | } | ||
1005 | switch(pass) | ||
1006 | { | ||
1007 | case LSCP_PRETTY_PRINT: | ||
1008 | case LSCP_EMIT_ASSEMBLY: | ||
1009 | fprintf(fp, "[ "); | ||
1010 | if (mEntryList) | ||
1011 | mEntryList->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
1012 | fprintf(fp, " ]"); | ||
1013 | if (mNextp) | ||
1014 | { | ||
1015 | fprintf(fp, ", "); | ||
1016 | mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
1017 | } | ||
1018 | break; | ||
1019 | case LSCP_TYPE: | ||
1020 | if (mEntryList) | ||
1021 | mEntryList->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
1022 | type = LST_LIST; | ||
1023 | if (mNextp) | ||
1024 | { | ||
1025 | mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
1026 | } | ||
1027 | break; | ||
1028 | case LSCP_EMIT_BYTE_CODE: | ||
1029 | { | ||
1030 | LLScriptLibData *list_data = new LLScriptLibData; | ||
1031 | |||
1032 | list_data->mType = LST_LIST; | ||
1033 | if (mEntryList) | ||
1034 | mEntryList->recurse(fp, tabs, tabsize, LSCP_LIST_BUILD_SIMPLE, ptype, prunearg, scope, type, basetype, count, chunk, NULL, stacksize, entry, entrycount, &(list_data->mListp)); | ||
1035 | |||
1036 | U8 *temp; | ||
1037 | chunk->addInteger(heap->mCurrentOffset + 1); | ||
1038 | S32 size = lsa_create_data_block(&temp, list_data, heap->mCurrentOffset); | ||
1039 | heap->addBytes(temp, size); | ||
1040 | delete list_data; | ||
1041 | delete [] temp; | ||
1042 | |||
1043 | if (mNextp) | ||
1044 | { | ||
1045 | mNextp->recurse(fp, tabs, tabsize, LSCP_EMIT_BYTE_CODE, ptype, prunearg, scope, type, basetype, count, chunk, NULL, stacksize, entry, entrycount, NULL); | ||
1046 | } | ||
1047 | } | ||
1048 | break; | ||
1049 | default: | ||
1050 | if (mEntryList) | ||
1051 | mEntryList->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, ldata); | ||
1052 | if (mNextp) | ||
1053 | { | ||
1054 | mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, ldata); | ||
1055 | } | ||
1056 | break; | ||
1057 | } | ||
1058 | } | ||
1059 | |||
1060 | S32 LLScriptSAList::getSize() | ||
1061 | { | ||
1062 | return mEntryList->getSize(); | ||
1063 | } | ||
1064 | |||
1065 | void LLScriptGlobalVariable::addGlobal(LLScriptGlobalVariable *global) | ||
1066 | { | ||
1067 | if (mNextp) | ||
1068 | { | ||
1069 | global->mNextp = mNextp; | ||
1070 | } | ||
1071 | mNextp = global; | ||
1072 | } | ||
1073 | |||
1074 | void LLScriptGlobalVariable::gonext(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
1075 | { | ||
1076 | switch(pass) | ||
1077 | { | ||
1078 | case LSCP_PRETTY_PRINT: | ||
1079 | if (mNextp) | ||
1080 | { | ||
1081 | mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
1082 | } | ||
1083 | break; | ||
1084 | default: | ||
1085 | if (mNextp) | ||
1086 | { | ||
1087 | mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
1088 | } | ||
1089 | break; | ||
1090 | } | ||
1091 | } | ||
1092 | |||
1093 | void LLScriptGlobalVariable::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
1094 | { | ||
1095 | if (gErrorToText.getErrors()) | ||
1096 | { | ||
1097 | return; | ||
1098 | } | ||
1099 | switch(pass) | ||
1100 | { | ||
1101 | case LSCP_PRETTY_PRINT: | ||
1102 | mType->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
1103 | fprintf(fp,"\t"); | ||
1104 | mIdentifier->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
1105 | if (mAssignable) | ||
1106 | { | ||
1107 | fprintf(fp, " = "); | ||
1108 | mAssignable->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
1109 | } | ||
1110 | fprintf(fp, ";\n"); | ||
1111 | break; | ||
1112 | case LSCP_EMIT_ASSEMBLY: | ||
1113 | mType->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
1114 | fprintf(fp,"\t"); | ||
1115 | mIdentifier->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
1116 | if (mAssignable) | ||
1117 | { | ||
1118 | fprintf(fp, " = "); | ||
1119 | mAssignable->recurse(fp, tabs, tabsize, LSCP_PRETTY_PRINT, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
1120 | fprintf(fp, "\n"); | ||
1121 | fprintf(fp, "Offset: %d Type: %d\n", mIdentifier->mScopeEntry->mOffset, (S32)LSCRIPTTypeByte[mType->mType]); | ||
1122 | } | ||
1123 | else | ||
1124 | { | ||
1125 | fprintf(fp, "\n"); | ||
1126 | fprintf(fp, "Offset: %d Type: %d\n", mIdentifier->mScopeEntry->mOffset, (S32)LSCRIPTTypeByte[mType->mType]); | ||
1127 | } | ||
1128 | break; | ||
1129 | case LSCP_SCOPE_PASS1: | ||
1130 | if (scope->checkEntry(mIdentifier->mName)) | ||
1131 | { | ||
1132 | gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME); | ||
1133 | } | ||
1134 | else | ||
1135 | { | ||
1136 | if (mAssignable) | ||
1137 | { | ||
1138 | mAssignable->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
1139 | } | ||
1140 | // this needs to go after expression decent to make sure that we don't add ourselves or something silly | ||
1141 | mIdentifier->mScopeEntry = scope->addEntry(mIdentifier->mName, LIT_GLOBAL, mType->mType); | ||
1142 | if (mIdentifier->mScopeEntry && mAssignable) | ||
1143 | mIdentifier->mScopeEntry->mAssignable = mAssignable; | ||
1144 | } | ||
1145 | break; | ||
1146 | case LSCP_TYPE: | ||
1147 | // if the variable has an assignable, it must assignable to the variable's type | ||
1148 | if (mAssignable) | ||
1149 | { | ||
1150 | mAssignable->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
1151 | mAssignableType = type; | ||
1152 | if (!legal_assignment(mType->mType, mAssignableType)) | ||
1153 | { | ||
1154 | gErrorToText.writeError(fp, this, LSERROR_TYPE_MISMATCH); | ||
1155 | } | ||
1156 | } | ||
1157 | break; | ||
1158 | case LSCP_RESOURCE: | ||
1159 | { | ||
1160 | // we're just tryng to determine how much space the variable needs | ||
1161 | // it also includes the name of the variable as well as the type | ||
1162 | // plus 4 bytes of offset from it's apparent address to the actual data | ||
1163 | #ifdef LSL_INCLUDE_DEBUG_INFO | ||
1164 | count += strlen(mIdentifier->mName) + 1 + 1 + 4; | ||
1165 | #else | ||
1166 | count += 1 + 1 + 4; | ||
1167 | #endif | ||
1168 | mIdentifier->mScopeEntry->mOffset = (S32)count; | ||
1169 | mIdentifier->mScopeEntry->mSize = mType->getSize(); | ||
1170 | count += mIdentifier->mScopeEntry->mSize; | ||
1171 | mIdentifier->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
1172 | } | ||
1173 | break; | ||
1174 | case LSCP_EMIT_BYTE_CODE: | ||
1175 | { | ||
1176 | // order for global variables | ||
1177 | // 0 - 4: offset to actual data | ||
1178 | S32 offsetoffset = chunk->mCurrentOffset; | ||
1179 | S32 offsetdelta = 0; | ||
1180 | chunk->addBytes(4); | ||
1181 | // type | ||
1182 | char vtype; | ||
1183 | vtype = LSCRIPTTypeByte[mType->mType]; | ||
1184 | chunk->addBytes(&vtype, 1); | ||
1185 | // null terminated name | ||
1186 | #ifdef LSL_INCLUDE_DEBUG_INFO | ||
1187 | chunk->addBytes(mIdentifier->mName, strlen(mIdentifier->mName) + 1); | ||
1188 | #else | ||
1189 | chunk->addBytes(1); | ||
1190 | #endif | ||
1191 | // put correct offset delta in | ||
1192 | offsetdelta = chunk->mCurrentOffset - offsetoffset; | ||
1193 | integer2bytestream(chunk->mCodeChunk, offsetoffset, offsetdelta); | ||
1194 | |||
1195 | // now we need space for the variable itself | ||
1196 | LLScriptByteCodeChunk *value = new LLScriptByteCodeChunk(FALSE); | ||
1197 | if (mAssignable) | ||
1198 | { | ||
1199 | mAssignable->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, value, heap, stacksize, entry, entrycount, NULL); | ||
1200 | // need to put sneaky type conversion here | ||
1201 | if (mAssignableType != mType->mType) | ||
1202 | { | ||
1203 | // the only legal case that is a problem is int->float | ||
1204 | if (mType->mType == LST_FLOATINGPOINT && mAssignableType == LST_INTEGER) | ||
1205 | { | ||
1206 | S32 offset = value->mCurrentOffset - 4; | ||
1207 | bytestream_int2float(value->mCodeChunk, offset); | ||
1208 | } | ||
1209 | } | ||
1210 | } | ||
1211 | else | ||
1212 | { | ||
1213 | if ( (mType->mType == LST_STRING) | ||
1214 | ||(mType->mType == LST_KEY)) | ||
1215 | { | ||
1216 | // string and keys (even empty ones) need heap entries | ||
1217 | chunk->addInteger(heap->mCurrentOffset + 1); | ||
1218 | LLScriptLibData *data = new LLScriptLibData(""); | ||
1219 | U8 *temp; | ||
1220 | S32 size = lsa_create_data_block(&temp, data, heap->mCurrentOffset); | ||
1221 | |||
1222 | heap->addBytes(temp, size); | ||
1223 | delete [] temp; | ||
1224 | delete data; | ||
1225 | } | ||
1226 | else if (mType->mType == LST_LIST) | ||
1227 | { | ||
1228 | chunk->addInteger(heap->mCurrentOffset + 1); | ||
1229 | LLScriptLibData *data = new LLScriptLibData; | ||
1230 | data->mType = LST_LIST; | ||
1231 | U8 *temp; | ||
1232 | S32 size = lsa_create_data_block(&temp, data, heap->mCurrentOffset); | ||
1233 | |||
1234 | heap->addBytes(temp, size); | ||
1235 | delete [] temp; | ||
1236 | delete data; | ||
1237 | } | ||
1238 | else if (mType->mType == LST_QUATERNION) | ||
1239 | { | ||
1240 | chunk->addFloat(1.f); | ||
1241 | chunk->addFloat(0.f); | ||
1242 | chunk->addFloat(0.f); | ||
1243 | chunk->addFloat(0.f); | ||
1244 | } | ||
1245 | else | ||
1246 | { | ||
1247 | value->addBytes(LSCRIPTDataSize[mType->mType]); | ||
1248 | } | ||
1249 | } | ||
1250 | chunk->addBytes(value->mCodeChunk, value->mCurrentOffset); | ||
1251 | delete value; | ||
1252 | } | ||
1253 | break; | ||
1254 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
1255 | |||
1256 | // Initialisation inside ctor. | ||
1257 | if (mAssignable) | ||
1258 | { | ||
1259 | fprintf(fp, "ldarg.0\n"); | ||
1260 | mAssignable->recurse(fp, tabs, tabsize, LSCP_EMIT_CIL_ASSEMBLY, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
1261 | fprintf(fp, "stfld "); | ||
1262 | mType->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
1263 | fprintf(fp," LSL::"); | ||
1264 | mIdentifier->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
1265 | fprintf(fp, "\n"); | ||
1266 | } | ||
1267 | break; | ||
1268 | default: | ||
1269 | mType->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
1270 | mIdentifier->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
1271 | if (mAssignable) | ||
1272 | { | ||
1273 | mAssignable->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
1274 | } | ||
1275 | break; | ||
1276 | } | ||
1277 | gonext(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
1278 | } | ||
1279 | |||
1280 | S32 LLScriptGlobalVariable::getSize() | ||
1281 | { | ||
1282 | S32 return_size; | ||
1283 | |||
1284 | return_size = mType->getSize(); | ||
1285 | return return_size; | ||
1286 | } | ||
1287 | |||
1288 | void LLScriptEvent::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
1289 | { | ||
1290 | fprintf(fp, "Event Base Class -- should never get here!\n"); | ||
1291 | } | ||
1292 | |||
1293 | S32 LLScriptEvent::getSize() | ||
1294 | { | ||
1295 | printf("Event Base Class -- should never get here!\n"); | ||
1296 | return 0; | ||
1297 | } | ||
1298 | |||
1299 | void LLScriptStateEntryEvent::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
1300 | { | ||
1301 | if (gErrorToText.getErrors()) | ||
1302 | { | ||
1303 | return; | ||
1304 | } | ||
1305 | switch(pass) | ||
1306 | { | ||
1307 | case LSCP_PRETTY_PRINT: | ||
1308 | fdotabs(fp, tabs, tabsize); | ||
1309 | fprintf(fp, "state_entry()\n"); | ||
1310 | break; | ||
1311 | case LSCP_EMIT_ASSEMBLY: | ||
1312 | fprintf(fp, "state_entry()\n"); | ||
1313 | break; | ||
1314 | case LSCP_EMIT_BYTE_CODE: | ||
1315 | { | ||
1316 | #ifdef LSL_INCLUDE_DEBUG_INFO | ||
1317 | char name[] = "state_entry"; | ||
1318 | chunk->addBytes(name, strlen(name) + 1); | ||
1319 | #endif | ||
1320 | } | ||
1321 | break; | ||
1322 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
1323 | fprintf(fp, "state_entry()"); | ||
1324 | break; | ||
1325 | default: | ||
1326 | break; | ||
1327 | } | ||
1328 | } | ||
1329 | |||
1330 | S32 LLScriptStateEntryEvent::getSize() | ||
1331 | { | ||
1332 | return 0; | ||
1333 | } | ||
1334 | |||
1335 | void LLScriptStateExitEvent::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
1336 | { | ||
1337 | if (gErrorToText.getErrors()) | ||
1338 | { | ||
1339 | return; | ||
1340 | } | ||
1341 | switch(pass) | ||
1342 | { | ||
1343 | case LSCP_PRETTY_PRINT: | ||
1344 | fdotabs(fp, tabs, tabsize); | ||
1345 | fprintf(fp, "state_exit()\n"); | ||
1346 | break; | ||
1347 | case LSCP_EMIT_ASSEMBLY: | ||
1348 | fprintf(fp, "state_exit()\n"); | ||
1349 | break; | ||
1350 | case LSCP_EMIT_BYTE_CODE: | ||
1351 | { | ||
1352 | #ifdef LSL_INCLUDE_DEBUG_INFO | ||
1353 | char name[] = "state_exit"; | ||
1354 | chunk->addBytes(name, strlen(name) + 1); | ||
1355 | #endif | ||
1356 | } | ||
1357 | break; | ||
1358 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
1359 | fprintf(fp, "state_exit()"); | ||
1360 | break; | ||
1361 | default: | ||
1362 | break; | ||
1363 | } | ||
1364 | } | ||
1365 | |||
1366 | S32 LLScriptStateExitEvent::getSize() | ||
1367 | { | ||
1368 | return 0; | ||
1369 | } | ||
1370 | |||
1371 | void LLScriptTouchStartEvent::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
1372 | { | ||
1373 | if (gErrorToText.getErrors()) | ||
1374 | { | ||
1375 | return; | ||
1376 | } | ||
1377 | switch(pass) | ||
1378 | { | ||
1379 | case LSCP_PRETTY_PRINT: | ||
1380 | case LSCP_EMIT_ASSEMBLY: | ||
1381 | fdotabs(fp, tabs, tabsize); | ||
1382 | fprintf(fp, "touch_start( integer "); | ||
1383 | mCount->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
1384 | fprintf(fp, " )\n"); | ||
1385 | break; | ||
1386 | break; | ||
1387 | case LSCP_SCOPE_PASS1: | ||
1388 | if (scope->checkEntry(mCount->mName)) | ||
1389 | { | ||
1390 | gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME); | ||
1391 | } | ||
1392 | else | ||
1393 | { | ||
1394 | mCount->mScopeEntry = scope->addEntry(mCount->mName, LIT_VARIABLE, LST_INTEGER); | ||
1395 | } | ||
1396 | break; | ||
1397 | case LSCP_RESOURCE: | ||
1398 | { | ||
1399 | // we're just tryng to determine how much space the variable needs | ||
1400 | if (mCount->mScopeEntry) | ||
1401 | { | ||
1402 | mCount->mScopeEntry->mOffset = (S32)count; | ||
1403 | mCount->mScopeEntry->mSize = 4; | ||
1404 | count += mCount->mScopeEntry->mSize; | ||
1405 | } | ||
1406 | } | ||
1407 | break; | ||
1408 | case LSCP_EMIT_BYTE_CODE: | ||
1409 | { | ||
1410 | #ifdef LSL_INCLUDE_DEBUG_INFO | ||
1411 | char name[] = "touch_start"; | ||
1412 | chunk->addBytes(name, strlen(name) + 1); | ||
1413 | chunk->addBytes(mCount->mName, strlen(mCount->mName) + 1); | ||
1414 | #endif | ||
1415 | } | ||
1416 | break; | ||
1417 | default: | ||
1418 | mCount->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
1419 | break; | ||
1420 | } | ||
1421 | } | ||
1422 | |||
1423 | S32 LLScriptTouchStartEvent::getSize() | ||
1424 | { | ||
1425 | // integer = 4 | ||
1426 | return 4; | ||
1427 | } | ||
1428 | |||
1429 | void LLScriptTouchEvent::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
1430 | { | ||
1431 | if (gErrorToText.getErrors()) | ||
1432 | { | ||
1433 | return; | ||
1434 | } | ||
1435 | switch(pass) | ||
1436 | { | ||
1437 | case LSCP_PRETTY_PRINT: | ||
1438 | case LSCP_EMIT_ASSEMBLY: | ||
1439 | fdotabs(fp, tabs, tabsize); | ||
1440 | fprintf(fp, "touch( integer "); | ||
1441 | mCount->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
1442 | fprintf(fp, " )\n"); | ||
1443 | break; | ||
1444 | break; | ||
1445 | case LSCP_SCOPE_PASS1: | ||
1446 | if (scope->checkEntry(mCount->mName)) | ||
1447 | { | ||
1448 | gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME); | ||
1449 | } | ||
1450 | else | ||
1451 | { | ||
1452 | mCount->mScopeEntry = scope->addEntry(mCount->mName, LIT_VARIABLE, LST_INTEGER); | ||
1453 | } | ||
1454 | break; | ||
1455 | case LSCP_RESOURCE: | ||
1456 | { | ||
1457 | // we're just tryng to determine how much space the variable needs | ||
1458 | if (mCount->mScopeEntry) | ||
1459 | { | ||
1460 | mCount->mScopeEntry->mOffset = (S32)count; | ||
1461 | mCount->mScopeEntry->mSize = 4; | ||
1462 | count += mCount->mScopeEntry->mSize; | ||
1463 | } | ||
1464 | } | ||
1465 | break; | ||
1466 | case LSCP_EMIT_BYTE_CODE: | ||
1467 | { | ||
1468 | #ifdef LSL_INCLUDE_DEBUG_INFO | ||
1469 | char name[] = "touch"; | ||
1470 | chunk->addBytes(name, strlen(name) + 1); | ||
1471 | chunk->addBytes(mCount->mName, strlen(mCount->mName) + 1); | ||
1472 | #endif | ||
1473 | } | ||
1474 | break; | ||
1475 | default: | ||
1476 | mCount->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
1477 | break; | ||
1478 | } | ||
1479 | } | ||
1480 | |||
1481 | S32 LLScriptTouchEvent::getSize() | ||
1482 | { | ||
1483 | // integer = 4 | ||
1484 | return 4; | ||
1485 | } | ||
1486 | |||
1487 | void LLScriptTouchEndEvent::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
1488 | { | ||
1489 | if (gErrorToText.getErrors()) | ||
1490 | { | ||
1491 | return; | ||
1492 | } | ||
1493 | switch(pass) | ||
1494 | { | ||
1495 | case LSCP_PRETTY_PRINT: | ||
1496 | case LSCP_EMIT_ASSEMBLY: | ||
1497 | fdotabs(fp, tabs, tabsize); | ||
1498 | fprintf(fp, "touch_end( integer "); | ||
1499 | mCount->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
1500 | fprintf(fp, " )\n"); | ||
1501 | break; | ||
1502 | break; | ||
1503 | case LSCP_SCOPE_PASS1: | ||
1504 | if (scope->checkEntry(mCount->mName)) | ||
1505 | { | ||
1506 | gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME); | ||
1507 | } | ||
1508 | else | ||
1509 | { | ||
1510 | mCount->mScopeEntry = scope->addEntry(mCount->mName, LIT_VARIABLE, LST_INTEGER); | ||
1511 | } | ||
1512 | break; | ||
1513 | case LSCP_RESOURCE: | ||
1514 | { | ||
1515 | // we're just tryng to determine how much space the variable needs | ||
1516 | if (mCount->mScopeEntry) | ||
1517 | { | ||
1518 | mCount->mScopeEntry->mOffset = (S32)count; | ||
1519 | mCount->mScopeEntry->mSize = 4; | ||
1520 | count += mCount->mScopeEntry->mSize; | ||
1521 | } | ||
1522 | } | ||
1523 | break; | ||
1524 | case LSCP_EMIT_BYTE_CODE: | ||
1525 | { | ||
1526 | #ifdef LSL_INCLUDE_DEBUG_INFO | ||
1527 | char name[] = "touch_end"; | ||
1528 | chunk->addBytes(name, strlen(name) + 1); | ||
1529 | chunk->addBytes(mCount->mName, strlen(mCount->mName) + 1); | ||
1530 | #endif | ||
1531 | } | ||
1532 | break; | ||
1533 | default: | ||
1534 | mCount->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
1535 | break; | ||
1536 | } | ||
1537 | } | ||
1538 | |||
1539 | S32 LLScriptTouchEndEvent::getSize() | ||
1540 | { | ||
1541 | // integer = 4 | ||
1542 | return 4; | ||
1543 | } | ||
1544 | |||
1545 | void LLScriptCollisionStartEvent::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
1546 | { | ||
1547 | if (gErrorToText.getErrors()) | ||
1548 | { | ||
1549 | return; | ||
1550 | } | ||
1551 | switch(pass) | ||
1552 | { | ||
1553 | case LSCP_PRETTY_PRINT: | ||
1554 | case LSCP_EMIT_ASSEMBLY: | ||
1555 | fdotabs(fp, tabs, tabsize); | ||
1556 | fprintf(fp, "collision_start( integer "); | ||
1557 | mCount->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
1558 | fprintf(fp, " )\n"); | ||
1559 | break; | ||
1560 | break; | ||
1561 | case LSCP_SCOPE_PASS1: | ||
1562 | if (scope->checkEntry(mCount->mName)) | ||
1563 | { | ||
1564 | gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME); | ||
1565 | } | ||
1566 | else | ||
1567 | { | ||
1568 | mCount->mScopeEntry = scope->addEntry(mCount->mName, LIT_VARIABLE, LST_INTEGER); | ||
1569 | } | ||
1570 | break; | ||
1571 | case LSCP_RESOURCE: | ||
1572 | { | ||
1573 | // we're just tryng to determine how much space the variable needs | ||
1574 | if (mCount->mScopeEntry) | ||
1575 | { | ||
1576 | mCount->mScopeEntry->mOffset = (S32)count; | ||
1577 | mCount->mScopeEntry->mSize = 4; | ||
1578 | count += mCount->mScopeEntry->mSize; | ||
1579 | } | ||
1580 | } | ||
1581 | break; | ||
1582 | case LSCP_EMIT_BYTE_CODE: | ||
1583 | { | ||
1584 | #ifdef LSL_INCLUDE_DEBUG_INFO | ||
1585 | char name[] = "collision_start"; | ||
1586 | chunk->addBytes(name, (S32)strlen(name) + 1); | ||
1587 | chunk->addBytes(mCount->mName, (S32)strlen(mCount->mName) + 1); | ||
1588 | #endif | ||
1589 | } | ||
1590 | break; | ||
1591 | default: | ||
1592 | mCount->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
1593 | break; | ||
1594 | } | ||
1595 | } | ||
1596 | |||
1597 | S32 LLScriptCollisionStartEvent::getSize() | ||
1598 | { | ||
1599 | // integer = 4 | ||
1600 | return 4; | ||
1601 | } | ||
1602 | |||
1603 | void LLScriptCollisionEvent::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
1604 | { | ||
1605 | if (gErrorToText.getErrors()) | ||
1606 | { | ||
1607 | return; | ||
1608 | } | ||
1609 | switch(pass) | ||
1610 | { | ||
1611 | case LSCP_PRETTY_PRINT: | ||
1612 | case LSCP_EMIT_ASSEMBLY: | ||
1613 | fdotabs(fp, tabs, tabsize); | ||
1614 | fprintf(fp, "collision( integer "); | ||
1615 | mCount->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
1616 | fprintf(fp, " )\n"); | ||
1617 | break; | ||
1618 | break; | ||
1619 | case LSCP_SCOPE_PASS1: | ||
1620 | if (scope->checkEntry(mCount->mName)) | ||
1621 | { | ||
1622 | gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME); | ||
1623 | } | ||
1624 | else | ||
1625 | { | ||
1626 | mCount->mScopeEntry = scope->addEntry(mCount->mName, LIT_VARIABLE, LST_INTEGER); | ||
1627 | } | ||
1628 | break; | ||
1629 | case LSCP_RESOURCE: | ||
1630 | { | ||
1631 | // we're just tryng to determine how much space the variable needs | ||
1632 | if (mCount->mScopeEntry) | ||
1633 | { | ||
1634 | mCount->mScopeEntry->mOffset = (S32)count; | ||
1635 | mCount->mScopeEntry->mSize = 4; | ||
1636 | count += mCount->mScopeEntry->mSize; | ||
1637 | } | ||
1638 | } | ||
1639 | break; | ||
1640 | case LSCP_EMIT_BYTE_CODE: | ||
1641 | { | ||
1642 | #ifdef LSL_INCLUDE_DEBUG_INFO | ||
1643 | char name[] = "collision"; | ||
1644 | chunk->addBytes(name, strlen(name) + 1); | ||
1645 | chunk->addBytes(mCount->mName, strlen(mCount->mName) + 1); | ||
1646 | #endif | ||
1647 | } | ||
1648 | break; | ||
1649 | default: | ||
1650 | mCount->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
1651 | break; | ||
1652 | } | ||
1653 | } | ||
1654 | |||
1655 | S32 LLScriptCollisionEvent::getSize() | ||
1656 | { | ||
1657 | // integer = 4 | ||
1658 | return 4; | ||
1659 | } | ||
1660 | |||
1661 | void LLScriptCollisionEndEvent::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
1662 | { | ||
1663 | if (gErrorToText.getErrors()) | ||
1664 | { | ||
1665 | return; | ||
1666 | } | ||
1667 | switch(pass) | ||
1668 | { | ||
1669 | case LSCP_PRETTY_PRINT: | ||
1670 | case LSCP_EMIT_ASSEMBLY: | ||
1671 | fdotabs(fp, tabs, tabsize); | ||
1672 | fprintf(fp, "collision_end( integer "); | ||
1673 | mCount->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
1674 | fprintf(fp, " )\n"); | ||
1675 | break; | ||
1676 | break; | ||
1677 | case LSCP_SCOPE_PASS1: | ||
1678 | if (scope->checkEntry(mCount->mName)) | ||
1679 | { | ||
1680 | gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME); | ||
1681 | } | ||
1682 | else | ||
1683 | { | ||
1684 | mCount->mScopeEntry = scope->addEntry(mCount->mName, LIT_VARIABLE, LST_INTEGER); | ||
1685 | } | ||
1686 | break; | ||
1687 | case LSCP_RESOURCE: | ||
1688 | { | ||
1689 | // we're just tryng to determine how much space the variable needs | ||
1690 | if (mCount->mScopeEntry) | ||
1691 | { | ||
1692 | mCount->mScopeEntry->mOffset = (S32)count; | ||
1693 | mCount->mScopeEntry->mSize = 4; | ||
1694 | count += mCount->mScopeEntry->mSize; | ||
1695 | } | ||
1696 | } | ||
1697 | break; | ||
1698 | case LSCP_EMIT_BYTE_CODE: | ||
1699 | { | ||
1700 | #ifdef LSL_INCLUDE_DEBUG_INFO | ||
1701 | char name[] = "collision_end"; | ||
1702 | chunk->addBytes(name, strlen(name) + 1); | ||
1703 | chunk->addBytes(mCount->mName, strlen(mCount->mName) + 1); | ||
1704 | #endif | ||
1705 | } | ||
1706 | break; | ||
1707 | default: | ||
1708 | mCount->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
1709 | break; | ||
1710 | } | ||
1711 | } | ||
1712 | |||
1713 | S32 LLScriptCollisionEndEvent::getSize() | ||
1714 | { | ||
1715 | // integer = 4 | ||
1716 | return 4; | ||
1717 | } | ||
1718 | |||
1719 | void LLScriptLandCollisionStartEvent::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
1720 | { | ||
1721 | if (gErrorToText.getErrors()) | ||
1722 | { | ||
1723 | return; | ||
1724 | } | ||
1725 | switch(pass) | ||
1726 | { | ||
1727 | case LSCP_PRETTY_PRINT: | ||
1728 | case LSCP_EMIT_ASSEMBLY: | ||
1729 | fdotabs(fp, tabs, tabsize); | ||
1730 | fprintf(fp, "land_collision_start( vector "); | ||
1731 | mPosition->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
1732 | fprintf(fp, " )\n"); | ||
1733 | break; | ||
1734 | case LSCP_SCOPE_PASS1: | ||
1735 | if (scope->checkEntry(mPosition->mName)) | ||
1736 | { | ||
1737 | gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME); | ||
1738 | } | ||
1739 | else | ||
1740 | { | ||
1741 | mPosition->mScopeEntry = scope->addEntry(mPosition->mName, LIT_VARIABLE, LST_VECTOR); | ||
1742 | } | ||
1743 | break; | ||
1744 | case LSCP_RESOURCE: | ||
1745 | { | ||
1746 | // we're just tryng to determine how much space the variable needs | ||
1747 | if (mPosition->mScopeEntry) | ||
1748 | { | ||
1749 | mPosition->mScopeEntry->mOffset = (S32)count; | ||
1750 | mPosition->mScopeEntry->mSize = 12; | ||
1751 | count += mPosition->mScopeEntry->mSize; | ||
1752 | } | ||
1753 | } | ||
1754 | break; | ||
1755 | case LSCP_EMIT_BYTE_CODE: | ||
1756 | { | ||
1757 | #ifdef LSL_INCLUDE_DEBUG_INFO | ||
1758 | char name[] = "land_collision_start"; | ||
1759 | chunk->addBytes(name, strlen(name) + 1); | ||
1760 | chunk->addBytes(mPosition->mName, strlen(mPosition->mName) + 1); | ||
1761 | #endif | ||
1762 | } | ||
1763 | break; | ||
1764 | default: | ||
1765 | mPosition->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
1766 | break; | ||
1767 | } | ||
1768 | } | ||
1769 | |||
1770 | S32 LLScriptLandCollisionStartEvent::getSize() | ||
1771 | { | ||
1772 | // vector = 12 | ||
1773 | return 12; | ||
1774 | } | ||
1775 | |||
1776 | |||
1777 | |||
1778 | void LLScriptLandCollisionEvent::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
1779 | { | ||
1780 | if (gErrorToText.getErrors()) | ||
1781 | { | ||
1782 | return; | ||
1783 | } | ||
1784 | switch(pass) | ||
1785 | { | ||
1786 | case LSCP_PRETTY_PRINT: | ||
1787 | case LSCP_EMIT_ASSEMBLY: | ||
1788 | fdotabs(fp, tabs, tabsize); | ||
1789 | fprintf(fp, "land_collision( vector "); | ||
1790 | mPosition->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
1791 | fprintf(fp, " )\n"); | ||
1792 | break; | ||
1793 | case LSCP_SCOPE_PASS1: | ||
1794 | if (scope->checkEntry(mPosition->mName)) | ||
1795 | { | ||
1796 | gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME); | ||
1797 | } | ||
1798 | else | ||
1799 | { | ||
1800 | mPosition->mScopeEntry = scope->addEntry(mPosition->mName, LIT_VARIABLE, LST_VECTOR); | ||
1801 | } | ||
1802 | break; | ||
1803 | case LSCP_RESOURCE: | ||
1804 | { | ||
1805 | // we're just tryng to determine how much space the variable needs | ||
1806 | if (mPosition->mScopeEntry) | ||
1807 | { | ||
1808 | mPosition->mScopeEntry->mOffset = (S32)count; | ||
1809 | mPosition->mScopeEntry->mSize = 12; | ||
1810 | count += mPosition->mScopeEntry->mSize; | ||
1811 | } | ||
1812 | } | ||
1813 | break; | ||
1814 | case LSCP_EMIT_BYTE_CODE: | ||
1815 | { | ||
1816 | #ifdef LSL_INCLUDE_DEBUG_INFO | ||
1817 | char name[] = "land_collision"; | ||
1818 | chunk->addBytes(name, strlen(name) + 1); | ||
1819 | chunk->addBytes(mPosition->mName, strlen(mPosition->mName) + 1); | ||
1820 | #endif | ||
1821 | } | ||
1822 | break; | ||
1823 | default: | ||
1824 | mPosition->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
1825 | break; | ||
1826 | } | ||
1827 | } | ||
1828 | |||
1829 | S32 LLScriptLandCollisionEvent::getSize() | ||
1830 | { | ||
1831 | // vector = 12 | ||
1832 | return 12; | ||
1833 | } | ||
1834 | |||
1835 | |||
1836 | void LLScriptLandCollisionEndEvent::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
1837 | { | ||
1838 | if (gErrorToText.getErrors()) | ||
1839 | { | ||
1840 | return; | ||
1841 | } | ||
1842 | switch(pass) | ||
1843 | { | ||
1844 | case LSCP_PRETTY_PRINT: | ||
1845 | case LSCP_EMIT_ASSEMBLY: | ||
1846 | fdotabs(fp, tabs, tabsize); | ||
1847 | fprintf(fp, "land_collision_end( vector "); | ||
1848 | mPosition->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
1849 | fprintf(fp, " )\n"); | ||
1850 | break; | ||
1851 | case LSCP_SCOPE_PASS1: | ||
1852 | if (scope->checkEntry(mPosition->mName)) | ||
1853 | { | ||
1854 | gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME); | ||
1855 | } | ||
1856 | else | ||
1857 | { | ||
1858 | mPosition->mScopeEntry = scope->addEntry(mPosition->mName, LIT_VARIABLE, LST_VECTOR); | ||
1859 | } | ||
1860 | break; | ||
1861 | case LSCP_RESOURCE: | ||
1862 | { | ||
1863 | // we're just tryng to determine how much space the variable needs | ||
1864 | if (mPosition->mScopeEntry) | ||
1865 | { | ||
1866 | mPosition->mScopeEntry->mOffset = (S32)count; | ||
1867 | mPosition->mScopeEntry->mSize = 12; | ||
1868 | count += mPosition->mScopeEntry->mSize; | ||
1869 | } | ||
1870 | } | ||
1871 | break; | ||
1872 | case LSCP_EMIT_BYTE_CODE: | ||
1873 | { | ||
1874 | #ifdef LSL_INCLUDE_DEBUG_INFO | ||
1875 | char name[] = "land_collision_end"; | ||
1876 | chunk->addBytes(name, strlen(name) + 1); | ||
1877 | chunk->addBytes(mPosition->mName, strlen(mPosition->mName) + 1); | ||
1878 | #endif | ||
1879 | } | ||
1880 | break; | ||
1881 | default: | ||
1882 | mPosition->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
1883 | break; | ||
1884 | } | ||
1885 | } | ||
1886 | |||
1887 | S32 LLScriptLandCollisionEndEvent::getSize() | ||
1888 | { | ||
1889 | // vector = 12 | ||
1890 | return 12; | ||
1891 | } | ||
1892 | |||
1893 | |||
1894 | void LLScriptInventoryEvent::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
1895 | { | ||
1896 | if (gErrorToText.getErrors()) | ||
1897 | { | ||
1898 | return; | ||
1899 | } | ||
1900 | switch(pass) | ||
1901 | { | ||
1902 | case LSCP_PRETTY_PRINT: | ||
1903 | case LSCP_EMIT_ASSEMBLY: | ||
1904 | fdotabs(fp, tabs, tabsize); | ||
1905 | fprintf(fp, "changed( integer "); | ||
1906 | mChange->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
1907 | fprintf(fp, " )\n"); | ||
1908 | break; | ||
1909 | case LSCP_SCOPE_PASS1: | ||
1910 | if (scope->checkEntry(mChange->mName)) | ||
1911 | { | ||
1912 | gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME); | ||
1913 | } | ||
1914 | else | ||
1915 | { | ||
1916 | mChange->mScopeEntry = scope->addEntry(mChange->mName, LIT_VARIABLE, LST_INTEGER); | ||
1917 | } | ||
1918 | break; | ||
1919 | case LSCP_RESOURCE: | ||
1920 | { | ||
1921 | // we're just tryng to determine how much space the variable needs | ||
1922 | if (mChange->mScopeEntry) | ||
1923 | { | ||
1924 | mChange->mScopeEntry->mOffset = (S32)count; | ||
1925 | mChange->mScopeEntry->mSize = 4; | ||
1926 | count += mChange->mScopeEntry->mSize; | ||
1927 | } | ||
1928 | } | ||
1929 | break; | ||
1930 | case LSCP_EMIT_BYTE_CODE: | ||
1931 | { | ||
1932 | #ifdef LSL_INCLUDE_DEBUG_INFO | ||
1933 | char name[] = "changed"; | ||
1934 | chunk->addBytes(name, strlen(name) + 1); | ||
1935 | chunk->addBytes(mChange->mName, strlen(mChange->mName) + 1); | ||
1936 | #endif | ||
1937 | } | ||
1938 | break; | ||
1939 | default: | ||
1940 | mChange->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
1941 | break; | ||
1942 | } | ||
1943 | } | ||
1944 | |||
1945 | S32 LLScriptInventoryEvent::getSize() | ||
1946 | { | ||
1947 | // integer = 4 | ||
1948 | return 4; | ||
1949 | } | ||
1950 | |||
1951 | void LLScriptAttachEvent::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
1952 | { | ||
1953 | if (gErrorToText.getErrors()) | ||
1954 | { | ||
1955 | return; | ||
1956 | } | ||
1957 | switch(pass) | ||
1958 | { | ||
1959 | case LSCP_PRETTY_PRINT: | ||
1960 | case LSCP_EMIT_ASSEMBLY: | ||
1961 | fdotabs(fp, tabs, tabsize); | ||
1962 | fprintf(fp, "attach( key "); | ||
1963 | mAttach->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
1964 | fprintf(fp, " )\n"); | ||
1965 | break; | ||
1966 | case LSCP_SCOPE_PASS1: | ||
1967 | if (scope->checkEntry(mAttach->mName)) | ||
1968 | { | ||
1969 | gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME); | ||
1970 | } | ||
1971 | else | ||
1972 | { | ||
1973 | mAttach->mScopeEntry = scope->addEntry(mAttach->mName, LIT_VARIABLE, LST_KEY); | ||
1974 | } | ||
1975 | break; | ||
1976 | case LSCP_RESOURCE: | ||
1977 | { | ||
1978 | // we're just tryng to determine how much space the variable needs | ||
1979 | if (mAttach->mScopeEntry) | ||
1980 | { | ||
1981 | mAttach->mScopeEntry->mOffset = (S32)count; | ||
1982 | mAttach->mScopeEntry->mSize = 4; | ||
1983 | count += mAttach->mScopeEntry->mSize; | ||
1984 | } | ||
1985 | } | ||
1986 | break; | ||
1987 | case LSCP_EMIT_BYTE_CODE: | ||
1988 | { | ||
1989 | #ifdef LSL_INCLUDE_DEBUG_INFO | ||
1990 | char name[] = "attach"; | ||
1991 | chunk->addBytes(name, strlen(name) + 1); | ||
1992 | chunk->addBytes(mAttach->mName, strlen(mAttach->mName) + 1); | ||
1993 | #endif | ||
1994 | } | ||
1995 | break; | ||
1996 | default: | ||
1997 | mAttach->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
1998 | break; | ||
1999 | } | ||
2000 | } | ||
2001 | |||
2002 | S32 LLScriptAttachEvent::getSize() | ||
2003 | { | ||
2004 | // key = 4 | ||
2005 | return 4; | ||
2006 | } | ||
2007 | |||
2008 | void LLScriptDataserverEvent::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
2009 | { | ||
2010 | if (gErrorToText.getErrors()) | ||
2011 | { | ||
2012 | return; | ||
2013 | } | ||
2014 | switch(pass) | ||
2015 | { | ||
2016 | case LSCP_PRETTY_PRINT: | ||
2017 | case LSCP_EMIT_ASSEMBLY: | ||
2018 | fdotabs(fp, tabs, tabsize); | ||
2019 | fprintf(fp, "dataserver( key "); | ||
2020 | mID->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2021 | fprintf(fp, ", string "); | ||
2022 | mData->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2023 | fprintf(fp, " )\n"); | ||
2024 | break; | ||
2025 | case LSCP_SCOPE_PASS1: | ||
2026 | if (scope->checkEntry(mID->mName)) | ||
2027 | { | ||
2028 | gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME); | ||
2029 | } | ||
2030 | else | ||
2031 | { | ||
2032 | mID->mScopeEntry = scope->addEntry(mID->mName, LIT_VARIABLE, LST_KEY); | ||
2033 | } | ||
2034 | if (scope->checkEntry(mData->mName)) | ||
2035 | { | ||
2036 | gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME); | ||
2037 | } | ||
2038 | else | ||
2039 | { | ||
2040 | mData->mScopeEntry = scope->addEntry(mData->mName, LIT_VARIABLE, LST_STRING); | ||
2041 | } | ||
2042 | break; | ||
2043 | case LSCP_RESOURCE: | ||
2044 | { | ||
2045 | // we're just tryng to determine how much space the variable needs | ||
2046 | if (mID->mScopeEntry) | ||
2047 | { | ||
2048 | mID->mScopeEntry->mOffset = (S32)count; | ||
2049 | mID->mScopeEntry->mSize = 4; | ||
2050 | count += mID->mScopeEntry->mSize; | ||
2051 | mData->mScopeEntry->mOffset = (S32)count; | ||
2052 | mData->mScopeEntry->mSize = 4; | ||
2053 | count += mData->mScopeEntry->mSize; | ||
2054 | } | ||
2055 | } | ||
2056 | break; | ||
2057 | case LSCP_EMIT_BYTE_CODE: | ||
2058 | { | ||
2059 | #ifdef LSL_INCLUDE_DEBUG_INFO | ||
2060 | char name[] = "dataserver"; | ||
2061 | chunk->addBytes(name, strlen(name) + 1); | ||
2062 | chunk->addBytes(mID->mName, strlen(mID->mName) + 1); | ||
2063 | chunk->addBytes(mData->mName, strlen(mData->mName) + 1); | ||
2064 | #endif | ||
2065 | } | ||
2066 | break; | ||
2067 | default: | ||
2068 | mID->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2069 | mData->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2070 | break; | ||
2071 | } | ||
2072 | } | ||
2073 | |||
2074 | S32 LLScriptDataserverEvent::getSize() | ||
2075 | { | ||
2076 | // key + string = 8 | ||
2077 | return 8; | ||
2078 | } | ||
2079 | |||
2080 | void LLScriptTimerEvent::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
2081 | { | ||
2082 | if (gErrorToText.getErrors()) | ||
2083 | { | ||
2084 | return; | ||
2085 | } | ||
2086 | switch(pass) | ||
2087 | { | ||
2088 | case LSCP_PRETTY_PRINT: | ||
2089 | fdotabs(fp, tabs, tabsize); | ||
2090 | fprintf(fp, "timer()\n"); | ||
2091 | break; | ||
2092 | case LSCP_EMIT_ASSEMBLY: | ||
2093 | fprintf(fp, "timer()\n"); | ||
2094 | break; | ||
2095 | case LSCP_EMIT_BYTE_CODE: | ||
2096 | { | ||
2097 | #ifdef LSL_INCLUDE_DEBUG_INFO | ||
2098 | char name[] = "timer"; | ||
2099 | chunk->addBytes(name, strlen(name) + 1); | ||
2100 | #endif | ||
2101 | } | ||
2102 | break; | ||
2103 | default: | ||
2104 | break; | ||
2105 | } | ||
2106 | } | ||
2107 | |||
2108 | S32 LLScriptTimerEvent::getSize() | ||
2109 | { | ||
2110 | return 0; | ||
2111 | } | ||
2112 | |||
2113 | void LLScriptMovingStartEvent::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
2114 | { | ||
2115 | if (gErrorToText.getErrors()) | ||
2116 | { | ||
2117 | return; | ||
2118 | } | ||
2119 | switch(pass) | ||
2120 | { | ||
2121 | case LSCP_PRETTY_PRINT: | ||
2122 | case LSCP_EMIT_ASSEMBLY: | ||
2123 | fdotabs(fp, tabs, tabsize); | ||
2124 | fprintf(fp, "moving_start()\n"); | ||
2125 | break; | ||
2126 | case LSCP_EMIT_BYTE_CODE: | ||
2127 | { | ||
2128 | #ifdef LSL_INCLUDE_DEBUG_INFO | ||
2129 | char name[] = "moving_start"; | ||
2130 | chunk->addBytes(name, strlen(name) + 1); | ||
2131 | #endif | ||
2132 | } | ||
2133 | break; | ||
2134 | default: | ||
2135 | break; | ||
2136 | } | ||
2137 | } | ||
2138 | |||
2139 | S32 LLScriptMovingStartEvent::getSize() | ||
2140 | { | ||
2141 | return 0; | ||
2142 | } | ||
2143 | |||
2144 | void LLScriptMovingEndEvent::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
2145 | { | ||
2146 | if (gErrorToText.getErrors()) | ||
2147 | { | ||
2148 | return; | ||
2149 | } | ||
2150 | switch(pass) | ||
2151 | { | ||
2152 | case LSCP_PRETTY_PRINT: | ||
2153 | case LSCP_EMIT_ASSEMBLY: | ||
2154 | fdotabs(fp, tabs, tabsize); | ||
2155 | fprintf(fp, "moving_end()\n"); | ||
2156 | break; | ||
2157 | case LSCP_EMIT_BYTE_CODE: | ||
2158 | { | ||
2159 | #ifdef LSL_INCLUDE_DEBUG_INFO | ||
2160 | char name[] = "moving_end"; | ||
2161 | chunk->addBytes(name, strlen(name) + 1); | ||
2162 | #endif | ||
2163 | } | ||
2164 | break; | ||
2165 | default: | ||
2166 | break; | ||
2167 | } | ||
2168 | } | ||
2169 | |||
2170 | S32 LLScriptMovingEndEvent::getSize() | ||
2171 | { | ||
2172 | return 0; | ||
2173 | } | ||
2174 | |||
2175 | void LLScriptRTPEvent::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
2176 | { | ||
2177 | if (gErrorToText.getErrors()) | ||
2178 | { | ||
2179 | return; | ||
2180 | } | ||
2181 | switch(pass) | ||
2182 | { | ||
2183 | case LSCP_PRETTY_PRINT: | ||
2184 | case LSCP_EMIT_ASSEMBLY: | ||
2185 | fdotabs(fp, tabs, tabsize); | ||
2186 | fprintf(fp, "chat( integer "); | ||
2187 | mRTPermissions->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2188 | fprintf(fp, " )\n"); | ||
2189 | break; | ||
2190 | case LSCP_SCOPE_PASS1: | ||
2191 | if (scope->checkEntry(mRTPermissions->mName)) | ||
2192 | { | ||
2193 | gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME); | ||
2194 | } | ||
2195 | else | ||
2196 | { | ||
2197 | mRTPermissions->mScopeEntry = scope->addEntry(mRTPermissions->mName, LIT_VARIABLE, LST_INTEGER); | ||
2198 | } | ||
2199 | break; | ||
2200 | case LSCP_RESOURCE: | ||
2201 | { | ||
2202 | // we're just tryng to determine how much space the variable needs | ||
2203 | if (mRTPermissions->mScopeEntry) | ||
2204 | { | ||
2205 | mRTPermissions->mScopeEntry->mOffset = (S32)count; | ||
2206 | mRTPermissions->mScopeEntry->mSize = 4; | ||
2207 | count += mRTPermissions->mScopeEntry->mSize; | ||
2208 | } | ||
2209 | } | ||
2210 | break; | ||
2211 | case LSCP_EMIT_BYTE_CODE: | ||
2212 | { | ||
2213 | #ifdef LSL_INCLUDE_DEBUG_INFO | ||
2214 | char name[] = "chat"; | ||
2215 | chunk->addBytes(name, strlen(name) + 1); | ||
2216 | chunk->addBytes(mRTPermissions->mName, strlen(mRTPermissions->mName) + 1); | ||
2217 | #endif | ||
2218 | } | ||
2219 | break; | ||
2220 | default: | ||
2221 | mRTPermissions->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2222 | break; | ||
2223 | } | ||
2224 | } | ||
2225 | |||
2226 | S32 LLScriptRTPEvent::getSize() | ||
2227 | { | ||
2228 | // integer = 4 | ||
2229 | return 4; | ||
2230 | } | ||
2231 | |||
2232 | void LLScriptChatEvent::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
2233 | { | ||
2234 | if (gErrorToText.getErrors()) | ||
2235 | { | ||
2236 | return; | ||
2237 | } | ||
2238 | switch(pass) | ||
2239 | { | ||
2240 | case LSCP_PRETTY_PRINT: | ||
2241 | case LSCP_EMIT_ASSEMBLY: | ||
2242 | fdotabs(fp, tabs, tabsize); | ||
2243 | fprintf(fp, "chat( integer "); | ||
2244 | mChannel->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2245 | fprintf(fp, ", string "); | ||
2246 | mName->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2247 | fprintf(fp, ", key "); | ||
2248 | mID->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2249 | fprintf(fp, ", string "); | ||
2250 | mMessage->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2251 | fprintf(fp, " )\n"); | ||
2252 | break; | ||
2253 | case LSCP_SCOPE_PASS1: | ||
2254 | if (scope->checkEntry(mChannel->mName)) | ||
2255 | { | ||
2256 | gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME); | ||
2257 | } | ||
2258 | else | ||
2259 | { | ||
2260 | mChannel->mScopeEntry = scope->addEntry(mChannel->mName, LIT_VARIABLE, LST_INTEGER); | ||
2261 | } | ||
2262 | if (scope->checkEntry(mName->mName)) | ||
2263 | { | ||
2264 | gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME); | ||
2265 | } | ||
2266 | else | ||
2267 | { | ||
2268 | mName->mScopeEntry = scope->addEntry(mName->mName, LIT_VARIABLE, LST_STRING); | ||
2269 | } | ||
2270 | if (scope->checkEntry(mID->mName)) | ||
2271 | { | ||
2272 | gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME); | ||
2273 | } | ||
2274 | else | ||
2275 | { | ||
2276 | mID->mScopeEntry = scope->addEntry(mID->mName, LIT_VARIABLE, LST_KEY); | ||
2277 | } | ||
2278 | if (scope->checkEntry(mMessage->mName)) | ||
2279 | { | ||
2280 | gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME); | ||
2281 | } | ||
2282 | else | ||
2283 | { | ||
2284 | mMessage->mScopeEntry = scope->addEntry(mMessage->mName, LIT_VARIABLE, LST_STRING); | ||
2285 | } | ||
2286 | break; | ||
2287 | case LSCP_RESOURCE: | ||
2288 | { | ||
2289 | // we're just tryng to determine how much space the variable needs | ||
2290 | if (mName->mScopeEntry) | ||
2291 | { | ||
2292 | mChannel->mScopeEntry->mOffset = (S32)count; | ||
2293 | mChannel->mScopeEntry->mSize = 4; | ||
2294 | count += mChannel->mScopeEntry->mSize; | ||
2295 | mName->mScopeEntry->mOffset = (S32)count; | ||
2296 | mName->mScopeEntry->mSize = 4; | ||
2297 | count += mName->mScopeEntry->mSize; | ||
2298 | mID->mScopeEntry->mOffset = (S32)count; | ||
2299 | mID->mScopeEntry->mSize = 4; | ||
2300 | count += mID->mScopeEntry->mSize; | ||
2301 | mMessage->mScopeEntry->mOffset = (S32)count; | ||
2302 | mMessage->mScopeEntry->mSize = 4; | ||
2303 | count += mMessage->mScopeEntry->mSize; | ||
2304 | } | ||
2305 | } | ||
2306 | break; | ||
2307 | case LSCP_EMIT_BYTE_CODE: | ||
2308 | { | ||
2309 | #ifdef LSL_INCLUDE_DEBUG_INFO | ||
2310 | char name[] = "chat"; | ||
2311 | chunk->addBytes(name, strlen(name) + 1); | ||
2312 | chunk->addBytes(mChannel->mName, strlen(mChannel->mName) + 1); | ||
2313 | chunk->addBytes(mName->mName, strlen(mName->mName) + 1); | ||
2314 | chunk->addBytes(mID->mName, strlen(mID->mName) + 1); | ||
2315 | chunk->addBytes(mMessage->mName, strlen(mMessage->mName) + 1); | ||
2316 | #endif | ||
2317 | } | ||
2318 | break; | ||
2319 | default: | ||
2320 | mChannel->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2321 | mName->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2322 | mID->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2323 | mMessage->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2324 | break; | ||
2325 | } | ||
2326 | } | ||
2327 | |||
2328 | S32 LLScriptChatEvent::getSize() | ||
2329 | { | ||
2330 | // integer + key + string + string = 16 | ||
2331 | return 16; | ||
2332 | } | ||
2333 | |||
2334 | void LLScriptSensorEvent::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
2335 | { | ||
2336 | if (gErrorToText.getErrors()) | ||
2337 | { | ||
2338 | return; | ||
2339 | } | ||
2340 | switch(pass) | ||
2341 | { | ||
2342 | case LSCP_PRETTY_PRINT: | ||
2343 | case LSCP_EMIT_ASSEMBLY: | ||
2344 | fdotabs(fp, tabs, tabsize); | ||
2345 | fprintf(fp, "sensor( integer "); | ||
2346 | mNumber->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2347 | fprintf(fp, " )\n"); | ||
2348 | break; | ||
2349 | case LSCP_SCOPE_PASS1: | ||
2350 | if (scope->checkEntry(mNumber->mName)) | ||
2351 | { | ||
2352 | gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME); | ||
2353 | } | ||
2354 | else | ||
2355 | { | ||
2356 | mNumber->mScopeEntry = scope->addEntry(mNumber->mName, LIT_VARIABLE, LST_INTEGER); | ||
2357 | } | ||
2358 | break; | ||
2359 | case LSCP_RESOURCE: | ||
2360 | { | ||
2361 | // we're just tryng to determine how much space the variable needs | ||
2362 | if (mNumber->mScopeEntry) | ||
2363 | { | ||
2364 | mNumber->mScopeEntry->mOffset = (S32)count; | ||
2365 | mNumber->mScopeEntry->mSize = 4; | ||
2366 | count += mNumber->mScopeEntry->mSize; | ||
2367 | } | ||
2368 | } | ||
2369 | break; | ||
2370 | case LSCP_EMIT_BYTE_CODE: | ||
2371 | { | ||
2372 | #ifdef LSL_INCLUDE_DEBUG_INFO | ||
2373 | char name[] = "sensor"; | ||
2374 | chunk->addBytes(name, strlen(name) + 1); | ||
2375 | chunk->addBytes(mNumber->mName, strlen(mNumber->mName) + 1); | ||
2376 | #endif | ||
2377 | } | ||
2378 | break; | ||
2379 | default: | ||
2380 | mNumber->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2381 | break; | ||
2382 | } | ||
2383 | } | ||
2384 | |||
2385 | S32 LLScriptSensorEvent::getSize() | ||
2386 | { | ||
2387 | // integer = 4 | ||
2388 | return 4; | ||
2389 | } | ||
2390 | |||
2391 | void LLScriptObjectRezEvent::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
2392 | { | ||
2393 | if (gErrorToText.getErrors()) | ||
2394 | { | ||
2395 | return; | ||
2396 | } | ||
2397 | switch(pass) | ||
2398 | { | ||
2399 | case LSCP_PRETTY_PRINT: | ||
2400 | case LSCP_EMIT_ASSEMBLY: | ||
2401 | fdotabs(fp, tabs, tabsize); | ||
2402 | fprintf(fp, "object_rez( key "); | ||
2403 | mID->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2404 | fprintf(fp, " )\n"); | ||
2405 | break; | ||
2406 | case LSCP_SCOPE_PASS1: | ||
2407 | if (scope->checkEntry(mID->mName)) | ||
2408 | { | ||
2409 | gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME); | ||
2410 | } | ||
2411 | else | ||
2412 | { | ||
2413 | mID->mScopeEntry = scope->addEntry(mID->mName, LIT_VARIABLE, LST_KEY); | ||
2414 | } | ||
2415 | break; | ||
2416 | case LSCP_RESOURCE: | ||
2417 | { | ||
2418 | // we're just tryng to determine how much space the variable needs | ||
2419 | if (mID->mScopeEntry) | ||
2420 | { | ||
2421 | mID->mScopeEntry->mOffset = (S32)count; | ||
2422 | mID->mScopeEntry->mSize = 4; | ||
2423 | count += mID->mScopeEntry->mSize; | ||
2424 | } | ||
2425 | } | ||
2426 | break; | ||
2427 | case LSCP_EMIT_BYTE_CODE: | ||
2428 | { | ||
2429 | #ifdef LSL_INCLUDE_DEBUG_INFO | ||
2430 | char name[] = "sensor"; | ||
2431 | chunk->addBytes(name, strlen(name) + 1); | ||
2432 | chunk->addBytes(mID->mName, strlen(mID->mName) + 1); | ||
2433 | #endif | ||
2434 | } | ||
2435 | break; | ||
2436 | default: | ||
2437 | mID->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2438 | break; | ||
2439 | } | ||
2440 | } | ||
2441 | |||
2442 | S32 LLScriptObjectRezEvent::getSize() | ||
2443 | { | ||
2444 | // key = 4 | ||
2445 | return 4; | ||
2446 | } | ||
2447 | |||
2448 | void LLScriptControlEvent::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
2449 | { | ||
2450 | if (gErrorToText.getErrors()) | ||
2451 | { | ||
2452 | return; | ||
2453 | } | ||
2454 | switch(pass) | ||
2455 | { | ||
2456 | case LSCP_PRETTY_PRINT: | ||
2457 | case LSCP_EMIT_ASSEMBLY: | ||
2458 | fdotabs(fp, tabs, tabsize); | ||
2459 | fprintf(fp, "control( key "); | ||
2460 | mName->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2461 | fprintf(fp, ", integer "); | ||
2462 | mLevels->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2463 | fprintf(fp, ", integer "); | ||
2464 | mEdges->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2465 | fprintf(fp, " )\n"); | ||
2466 | break; | ||
2467 | case LSCP_SCOPE_PASS1: | ||
2468 | if (scope->checkEntry(mName->mName)) | ||
2469 | { | ||
2470 | gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME); | ||
2471 | } | ||
2472 | else | ||
2473 | { | ||
2474 | mName->mScopeEntry = scope->addEntry(mName->mName, LIT_VARIABLE, LST_KEY); | ||
2475 | } | ||
2476 | if (scope->checkEntry(mLevels->mName)) | ||
2477 | { | ||
2478 | gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME); | ||
2479 | } | ||
2480 | else | ||
2481 | { | ||
2482 | mLevels->mScopeEntry = scope->addEntry(mLevels->mName, LIT_VARIABLE, LST_INTEGER); | ||
2483 | } | ||
2484 | if (scope->checkEntry(mEdges->mName)) | ||
2485 | { | ||
2486 | gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME); | ||
2487 | } | ||
2488 | else | ||
2489 | { | ||
2490 | mEdges->mScopeEntry = scope->addEntry(mEdges->mName, LIT_VARIABLE, LST_INTEGER); | ||
2491 | } | ||
2492 | break; | ||
2493 | case LSCP_RESOURCE: | ||
2494 | { | ||
2495 | // we're just tryng to determine how much space the variable needs | ||
2496 | if (mName->mScopeEntry) | ||
2497 | { | ||
2498 | mName->mScopeEntry->mOffset = (S32)count; | ||
2499 | mName->mScopeEntry->mSize = 4; | ||
2500 | count += mName->mScopeEntry->mSize; | ||
2501 | mLevels->mScopeEntry->mOffset = (S32)count; | ||
2502 | mLevels->mScopeEntry->mSize = 4; | ||
2503 | count += mLevels->mScopeEntry->mSize; | ||
2504 | mEdges->mScopeEntry->mOffset = (S32)count; | ||
2505 | mEdges->mScopeEntry->mSize = 4; | ||
2506 | count += mEdges->mScopeEntry->mSize; | ||
2507 | } | ||
2508 | } | ||
2509 | break; | ||
2510 | case LSCP_EMIT_BYTE_CODE: | ||
2511 | { | ||
2512 | #ifdef LSL_INCLUDE_DEBUG_INFO | ||
2513 | char name[] = "control"; | ||
2514 | chunk->addBytes(name, strlen(name) + 1); | ||
2515 | chunk->addBytes(mName->mName, strlen(mName->mName) + 1); | ||
2516 | chunk->addBytes(mLevels->mName, strlen(mLevels->mName) + 1); | ||
2517 | chunk->addBytes(mEdges->mName, strlen(mEdges->mName) + 1); | ||
2518 | #endif | ||
2519 | } | ||
2520 | break; | ||
2521 | default: | ||
2522 | mName->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2523 | mLevels->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2524 | mEdges->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2525 | break; | ||
2526 | } | ||
2527 | } | ||
2528 | |||
2529 | S32 LLScriptControlEvent::getSize() | ||
2530 | { | ||
2531 | // key + integer + integer = 12 | ||
2532 | return 12; | ||
2533 | } | ||
2534 | |||
2535 | void LLScriptLinkMessageEvent::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
2536 | { | ||
2537 | if (gErrorToText.getErrors()) | ||
2538 | { | ||
2539 | return; | ||
2540 | } | ||
2541 | switch(pass) | ||
2542 | { | ||
2543 | case LSCP_PRETTY_PRINT: | ||
2544 | case LSCP_EMIT_ASSEMBLY: | ||
2545 | fdotabs(fp, tabs, tabsize); | ||
2546 | fprintf(fp, "link_message( integer "); | ||
2547 | mSender->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2548 | fprintf(fp, ", integer "); | ||
2549 | mNum->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2550 | fprintf(fp, ", string "); | ||
2551 | mStr->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2552 | fprintf(fp, ", key "); | ||
2553 | mID->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2554 | fprintf(fp, " )\n"); | ||
2555 | break; | ||
2556 | case LSCP_SCOPE_PASS1: | ||
2557 | if (scope->checkEntry(mSender->mName)) | ||
2558 | { | ||
2559 | gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME); | ||
2560 | } | ||
2561 | else | ||
2562 | { | ||
2563 | mSender->mScopeEntry = scope->addEntry(mSender->mName, LIT_VARIABLE, LST_INTEGER); | ||
2564 | } | ||
2565 | if (scope->checkEntry(mNum->mName)) | ||
2566 | { | ||
2567 | gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME); | ||
2568 | } | ||
2569 | else | ||
2570 | { | ||
2571 | mNum->mScopeEntry = scope->addEntry(mNum->mName, LIT_VARIABLE, LST_INTEGER); | ||
2572 | } | ||
2573 | if (scope->checkEntry(mStr->mName)) | ||
2574 | { | ||
2575 | gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME); | ||
2576 | } | ||
2577 | else | ||
2578 | { | ||
2579 | mStr->mScopeEntry = scope->addEntry(mStr->mName, LIT_VARIABLE, LST_STRING); | ||
2580 | } | ||
2581 | if (scope->checkEntry(mID->mName)) | ||
2582 | { | ||
2583 | gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME); | ||
2584 | } | ||
2585 | else | ||
2586 | { | ||
2587 | mID->mScopeEntry = scope->addEntry(mID->mName, LIT_VARIABLE, LST_KEY); | ||
2588 | } | ||
2589 | break; | ||
2590 | case LSCP_RESOURCE: | ||
2591 | { | ||
2592 | // we're just tryng to determine how much space the variable needs | ||
2593 | if (mSender->mScopeEntry) | ||
2594 | { | ||
2595 | mSender->mScopeEntry->mOffset = (S32)count; | ||
2596 | mSender->mScopeEntry->mSize = 4; | ||
2597 | count += mSender->mScopeEntry->mSize; | ||
2598 | mNum->mScopeEntry->mOffset = (S32)count; | ||
2599 | mNum->mScopeEntry->mSize = 4; | ||
2600 | count += mNum->mScopeEntry->mSize; | ||
2601 | mStr->mScopeEntry->mOffset = (S32)count; | ||
2602 | mStr->mScopeEntry->mSize = 4; | ||
2603 | count += mStr->mScopeEntry->mSize; | ||
2604 | mID->mScopeEntry->mOffset = (S32)count; | ||
2605 | mID->mScopeEntry->mSize = 4; | ||
2606 | count += mID->mScopeEntry->mSize; | ||
2607 | } | ||
2608 | } | ||
2609 | break; | ||
2610 | case LSCP_EMIT_BYTE_CODE: | ||
2611 | { | ||
2612 | #ifdef LSL_INCLUDE_DEBUG_INFO | ||
2613 | char name[] = "link_message"; | ||
2614 | chunk->addBytes(name, strlen(name) + 1); | ||
2615 | chunk->addBytes(mSender->mName, strlen(mSender->mName) + 1); | ||
2616 | chunk->addBytes(mNum->mName, strlen(mNum->mName) + 1); | ||
2617 | chunk->addBytes(mStr->mName, strlen(mStr->mName) + 1); | ||
2618 | chunk->addBytes(mID->mName, strlen(mID->mName) + 1); | ||
2619 | #endif | ||
2620 | } | ||
2621 | break; | ||
2622 | default: | ||
2623 | mSender->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2624 | mNum->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2625 | mStr->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2626 | mID->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2627 | break; | ||
2628 | } | ||
2629 | } | ||
2630 | |||
2631 | S32 LLScriptLinkMessageEvent::getSize() | ||
2632 | { | ||
2633 | // integer + key + integer + string = 16 | ||
2634 | return 16; | ||
2635 | } | ||
2636 | |||
2637 | void LLScriptRemoteEvent::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
2638 | { | ||
2639 | if (gErrorToText.getErrors()) | ||
2640 | { | ||
2641 | return; | ||
2642 | } | ||
2643 | switch(pass) | ||
2644 | { | ||
2645 | case LSCP_PRETTY_PRINT: | ||
2646 | case LSCP_EMIT_ASSEMBLY: | ||
2647 | fdotabs(fp, tabs, tabsize); | ||
2648 | fprintf(fp, "remote_event( integer "); | ||
2649 | mType->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2650 | fprintf(fp, ", key "); | ||
2651 | mChannel->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2652 | fprintf(fp, ", key "); | ||
2653 | mMessageID->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2654 | fprintf(fp, ", string "); | ||
2655 | mSender->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2656 | fprintf(fp, ", integer "); | ||
2657 | mIntVal->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2658 | fprintf(fp, ", string "); | ||
2659 | mStrVal->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2660 | fprintf(fp, " )\n"); | ||
2661 | break; | ||
2662 | case LSCP_SCOPE_PASS1: | ||
2663 | if (scope->checkEntry(mType->mName)) | ||
2664 | { | ||
2665 | gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME); | ||
2666 | } | ||
2667 | else | ||
2668 | { | ||
2669 | mType->mScopeEntry = scope->addEntry(mType->mName, LIT_VARIABLE, LST_INTEGER); | ||
2670 | } | ||
2671 | if (scope->checkEntry(mChannel->mName)) | ||
2672 | { | ||
2673 | gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME); | ||
2674 | } | ||
2675 | else | ||
2676 | { | ||
2677 | mChannel->mScopeEntry = scope->addEntry(mChannel->mName, LIT_VARIABLE, LST_KEY); | ||
2678 | } | ||
2679 | if (scope->checkEntry(mMessageID->mName)) | ||
2680 | { | ||
2681 | gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME); | ||
2682 | } | ||
2683 | else | ||
2684 | { | ||
2685 | mMessageID->mScopeEntry = scope->addEntry(mMessageID->mName, LIT_VARIABLE, LST_KEY); | ||
2686 | } | ||
2687 | if (scope->checkEntry(mSender->mName)) | ||
2688 | { | ||
2689 | gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME); | ||
2690 | } | ||
2691 | else | ||
2692 | { | ||
2693 | mSender->mScopeEntry = scope->addEntry(mSender->mName, LIT_VARIABLE, LST_STRING); | ||
2694 | } | ||
2695 | if (scope->checkEntry(mIntVal->mName)) | ||
2696 | { | ||
2697 | gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME); | ||
2698 | } | ||
2699 | else | ||
2700 | { | ||
2701 | mIntVal->mScopeEntry = scope->addEntry(mIntVal->mName, LIT_VARIABLE, LST_INTEGER); | ||
2702 | } | ||
2703 | if (scope->checkEntry(mStrVal->mName)) | ||
2704 | { | ||
2705 | gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME); | ||
2706 | } | ||
2707 | else | ||
2708 | { | ||
2709 | mStrVal->mScopeEntry = scope->addEntry(mStrVal->mName, LIT_VARIABLE, LST_STRING); | ||
2710 | } | ||
2711 | break; | ||
2712 | case LSCP_RESOURCE: | ||
2713 | { | ||
2714 | // we're just tryng to determine how much space the variable needs | ||
2715 | if (mType->mScopeEntry) | ||
2716 | { | ||
2717 | mType->mScopeEntry->mOffset = (S32)count; | ||
2718 | mType->mScopeEntry->mSize = 4; | ||
2719 | count += mType->mScopeEntry->mSize; | ||
2720 | mChannel->mScopeEntry->mOffset = (S32)count; | ||
2721 | mChannel->mScopeEntry->mSize = 4; | ||
2722 | count += mChannel->mScopeEntry->mSize; | ||
2723 | mMessageID->mScopeEntry->mOffset = (S32)count; | ||
2724 | mMessageID->mScopeEntry->mSize = 4; | ||
2725 | count += mMessageID->mScopeEntry->mSize; | ||
2726 | mSender->mScopeEntry->mOffset = (S32)count; | ||
2727 | mSender->mScopeEntry->mSize = 4; | ||
2728 | count += mSender->mScopeEntry->mSize; | ||
2729 | mIntVal->mScopeEntry->mOffset = (S32)count; | ||
2730 | mIntVal->mScopeEntry->mSize = 4; | ||
2731 | count += mIntVal->mScopeEntry->mSize; | ||
2732 | mStrVal->mScopeEntry->mOffset = (S32)count; | ||
2733 | mStrVal->mScopeEntry->mSize = 4; | ||
2734 | count += mStrVal->mScopeEntry->mSize; | ||
2735 | } | ||
2736 | } | ||
2737 | break; | ||
2738 | case LSCP_EMIT_BYTE_CODE: | ||
2739 | { | ||
2740 | #ifdef LSL_INCLUDE_DEBUG_INFO | ||
2741 | char name[] = "remote_event"; | ||
2742 | chunk->addBytes(name, strlen(name) + 1); | ||
2743 | chunk->addBytes(mType->mName, strlen(mType->mName) + 1); | ||
2744 | chunk->addBytes(mChannel->mName, strlen(mChannel->mName) + 1); | ||
2745 | chunk->addBytes(mMessageID->mName, strlen(mMessageID->mName) + 1); | ||
2746 | chunk->addBytes(mSender->mName, strlen(mSender->mName) + 1); | ||
2747 | chunk->addBytes(mIntVal->mName, strlen(mIntVal->mName) + 1); | ||
2748 | chunk->addBytes(mStrVal->mName, strlen(mStrVal->mName) + 1); | ||
2749 | #endif | ||
2750 | } | ||
2751 | break; | ||
2752 | default: | ||
2753 | mType->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2754 | mChannel->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2755 | mMessageID->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2756 | mSender->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2757 | mIntVal->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2758 | mStrVal->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2759 | break; | ||
2760 | } | ||
2761 | } | ||
2762 | |||
2763 | S32 LLScriptRemoteEvent::getSize() | ||
2764 | { | ||
2765 | // integer + key + key + string + integer + string = 24 | ||
2766 | return 24; | ||
2767 | } | ||
2768 | |||
2769 | void LLScriptHTTPResponseEvent::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
2770 | { | ||
2771 | if (gErrorToText.getErrors()) | ||
2772 | { | ||
2773 | return; | ||
2774 | } | ||
2775 | switch(pass) | ||
2776 | { | ||
2777 | case LSCP_PRETTY_PRINT: | ||
2778 | case LSCP_EMIT_ASSEMBLY: | ||
2779 | fdotabs(fp, tabs, tabsize); | ||
2780 | fprintf(fp, "http_response( key "); | ||
2781 | mRequestId->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2782 | fprintf(fp, ", integer "); | ||
2783 | mStatus->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2784 | fprintf(fp, ", list "); | ||
2785 | mMetadata->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2786 | fprintf(fp, ", string "); | ||
2787 | mBody->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2788 | fprintf(fp, " )\n"); | ||
2789 | break; | ||
2790 | |||
2791 | case LSCP_SCOPE_PASS1: | ||
2792 | if (scope->checkEntry(mRequestId->mName)) | ||
2793 | { | ||
2794 | gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME); | ||
2795 | } | ||
2796 | else | ||
2797 | { | ||
2798 | mRequestId->mScopeEntry = scope->addEntry(mRequestId->mName, LIT_VARIABLE, LST_KEY); | ||
2799 | } | ||
2800 | |||
2801 | if (scope->checkEntry(mStatus->mName)) | ||
2802 | { | ||
2803 | gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME); | ||
2804 | } | ||
2805 | else | ||
2806 | { | ||
2807 | mStatus->mScopeEntry = scope->addEntry(mStatus->mName, LIT_VARIABLE, LST_INTEGER); | ||
2808 | } | ||
2809 | |||
2810 | if (scope->checkEntry(mMetadata->mName)) | ||
2811 | { | ||
2812 | gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME); | ||
2813 | } | ||
2814 | else | ||
2815 | { | ||
2816 | mMetadata->mScopeEntry = scope->addEntry(mMetadata->mName, LIT_VARIABLE, LST_LIST); | ||
2817 | } | ||
2818 | |||
2819 | if (scope->checkEntry(mBody->mName)) | ||
2820 | { | ||
2821 | gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME); | ||
2822 | } | ||
2823 | else | ||
2824 | { | ||
2825 | mBody->mScopeEntry = scope->addEntry(mBody->mName, LIT_VARIABLE, LST_STRING); | ||
2826 | } | ||
2827 | break; | ||
2828 | |||
2829 | case LSCP_RESOURCE: | ||
2830 | { | ||
2831 | // we're just tryng to determine how much space the variable needs | ||
2832 | if (mRequestId->mScopeEntry) | ||
2833 | { | ||
2834 | mRequestId->mScopeEntry->mOffset = (S32)count; | ||
2835 | mRequestId->mScopeEntry->mSize = 4; | ||
2836 | count += mRequestId->mScopeEntry->mSize; | ||
2837 | |||
2838 | mStatus->mScopeEntry->mOffset = (S32)count; | ||
2839 | mStatus->mScopeEntry->mSize = 4; | ||
2840 | count += mStatus->mScopeEntry->mSize; | ||
2841 | |||
2842 | mMetadata->mScopeEntry->mOffset = (S32)count; | ||
2843 | mMetadata->mScopeEntry->mSize = 4; | ||
2844 | count += mMetadata->mScopeEntry->mSize; | ||
2845 | |||
2846 | mBody->mScopeEntry->mOffset = (S32)count; | ||
2847 | mBody->mScopeEntry->mSize = 4; | ||
2848 | count += mBody->mScopeEntry->mSize; | ||
2849 | } | ||
2850 | } | ||
2851 | break; | ||
2852 | |||
2853 | case LSCP_EMIT_BYTE_CODE: | ||
2854 | { | ||
2855 | #ifdef LSL_INCLUDE_DEBUG_INFO | ||
2856 | char name[] = "http_response"; | ||
2857 | chunk->addBytes(name, strlen(name) + 1); | ||
2858 | chunk->addBytes(mRequestId->mName, strlen(mRequestId->mName) + 1); | ||
2859 | chunk->addBytes(mStatus->mName, strlen(mStatus->mName) + 1); | ||
2860 | chunk->addBytes(mMetadata->mName, strlen(mMetadata->mName) + 1); | ||
2861 | chunk->addBytes(mBody->mName, strlen(mBody->mName) + 1); | ||
2862 | #endif | ||
2863 | } | ||
2864 | break; | ||
2865 | |||
2866 | default: | ||
2867 | mRequestId->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2868 | mStatus->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2869 | mMetadata->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2870 | mBody->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2871 | break; | ||
2872 | } | ||
2873 | } | ||
2874 | |||
2875 | S32 LLScriptHTTPResponseEvent::getSize() | ||
2876 | { | ||
2877 | // key + integer + list + string = 16 | ||
2878 | return 16; | ||
2879 | } | ||
2880 | |||
2881 | |||
2882 | void LLScriptMoneyEvent::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
2883 | { | ||
2884 | if (gErrorToText.getErrors()) | ||
2885 | { | ||
2886 | return; | ||
2887 | } | ||
2888 | switch(pass) | ||
2889 | { | ||
2890 | case LSCP_PRETTY_PRINT: | ||
2891 | case LSCP_EMIT_ASSEMBLY: | ||
2892 | fdotabs(fp, tabs, tabsize); | ||
2893 | fprintf(fp, "money( key "); | ||
2894 | mName->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2895 | fprintf(fp, ", integer "); | ||
2896 | mAmount->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2897 | fprintf(fp, " )\n"); | ||
2898 | break; | ||
2899 | case LSCP_SCOPE_PASS1: | ||
2900 | if (scope->checkEntry(mName->mName)) | ||
2901 | { | ||
2902 | gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME); | ||
2903 | } | ||
2904 | else | ||
2905 | { | ||
2906 | mName->mScopeEntry = scope->addEntry(mName->mName, LIT_VARIABLE, LST_KEY); | ||
2907 | } | ||
2908 | if (scope->checkEntry(mAmount->mName)) | ||
2909 | { | ||
2910 | gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME); | ||
2911 | } | ||
2912 | else | ||
2913 | { | ||
2914 | mAmount->mScopeEntry = scope->addEntry(mAmount->mName, LIT_VARIABLE, LST_INTEGER); | ||
2915 | } | ||
2916 | break; | ||
2917 | case LSCP_RESOURCE: | ||
2918 | { | ||
2919 | // we're just tryng to determine how much space the variable needs | ||
2920 | if (mName->mScopeEntry) | ||
2921 | { | ||
2922 | mName->mScopeEntry->mOffset = (S32)count; | ||
2923 | mName->mScopeEntry->mSize = 4; | ||
2924 | count += mName->mScopeEntry->mSize; | ||
2925 | mAmount->mScopeEntry->mOffset = (S32)count; | ||
2926 | mAmount->mScopeEntry->mSize = 4; | ||
2927 | count += mAmount->mScopeEntry->mSize; | ||
2928 | } | ||
2929 | } | ||
2930 | break; | ||
2931 | case LSCP_EMIT_BYTE_CODE: | ||
2932 | { | ||
2933 | #ifdef LSL_INCLUDE_DEBUG_INFO | ||
2934 | char name[] = "money"; | ||
2935 | chunk->addBytes(name, strlen(name) + 1); | ||
2936 | chunk->addBytes(mName->mName, strlen(mName->mName) + 1); | ||
2937 | chunk->addBytes(mAmount->mName, strlen(mAmount->mName) + 1); | ||
2938 | #endif | ||
2939 | } | ||
2940 | break; | ||
2941 | default: | ||
2942 | mName->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2943 | mAmount->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2944 | break; | ||
2945 | } | ||
2946 | } | ||
2947 | |||
2948 | S32 LLScriptMoneyEvent::getSize() | ||
2949 | { | ||
2950 | // key + integer = 8 | ||
2951 | return 8; | ||
2952 | } | ||
2953 | |||
2954 | void LLScriptEmailEvent::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
2955 | { | ||
2956 | if (gErrorToText.getErrors()) | ||
2957 | { | ||
2958 | return; | ||
2959 | } | ||
2960 | switch(pass) | ||
2961 | { | ||
2962 | case LSCP_PRETTY_PRINT: | ||
2963 | case LSCP_EMIT_ASSEMBLY: | ||
2964 | fdotabs(fp, tabs, tabsize); | ||
2965 | fprintf(fp, "email( string "); | ||
2966 | mTime->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2967 | fprintf(fp, ", string "); | ||
2968 | mAddress->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2969 | fprintf(fp, ", string "); | ||
2970 | mSubject->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2971 | fprintf(fp, ", string "); | ||
2972 | mBody->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2973 | fprintf(fp, ", integer "); | ||
2974 | mNumber->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
2975 | fprintf(fp, " )\n"); | ||
2976 | break; | ||
2977 | case LSCP_SCOPE_PASS1: | ||
2978 | if (scope->checkEntry(mTime->mName)) | ||
2979 | { | ||
2980 | gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME); | ||
2981 | } | ||
2982 | else | ||
2983 | { | ||
2984 | mTime->mScopeEntry = scope->addEntry(mTime->mName, LIT_VARIABLE, LST_STRING); | ||
2985 | } | ||
2986 | if (scope->checkEntry(mAddress->mName)) | ||
2987 | { | ||
2988 | gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME); | ||
2989 | } | ||
2990 | else | ||
2991 | { | ||
2992 | mAddress->mScopeEntry = scope->addEntry(mAddress->mName, LIT_VARIABLE, LST_STRING); | ||
2993 | } | ||
2994 | if (scope->checkEntry(mSubject->mName)) | ||
2995 | { | ||
2996 | gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME); | ||
2997 | } | ||
2998 | else | ||
2999 | { | ||
3000 | mSubject->mScopeEntry = scope->addEntry(mSubject->mName, LIT_VARIABLE, LST_STRING); | ||
3001 | } | ||
3002 | if (scope->checkEntry(mBody->mName)) | ||
3003 | { | ||
3004 | gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME); | ||
3005 | } | ||
3006 | else | ||
3007 | { | ||
3008 | mBody->mScopeEntry = scope->addEntry(mBody->mName, LIT_VARIABLE, LST_STRING); | ||
3009 | } | ||
3010 | if (scope->checkEntry(mNumber->mName)) | ||
3011 | { | ||
3012 | gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME); | ||
3013 | } | ||
3014 | else | ||
3015 | { | ||
3016 | mNumber->mScopeEntry = scope->addEntry(mNumber->mName, LIT_VARIABLE, LST_INTEGER); | ||
3017 | } | ||
3018 | break; | ||
3019 | case LSCP_RESOURCE: | ||
3020 | { | ||
3021 | // we're just tryng to determine how much space the variable needs | ||
3022 | if (mAddress->mScopeEntry) | ||
3023 | { | ||
3024 | mTime->mScopeEntry->mOffset = (S32)count; | ||
3025 | mTime->mScopeEntry->mSize = 4; | ||
3026 | count += mTime->mScopeEntry->mSize; | ||
3027 | mAddress->mScopeEntry->mOffset = (S32)count; | ||
3028 | mAddress->mScopeEntry->mSize = 4; | ||
3029 | count += mAddress->mScopeEntry->mSize; | ||
3030 | mSubject->mScopeEntry->mOffset = (S32)count; | ||
3031 | mSubject->mScopeEntry->mSize = 4; | ||
3032 | count += mSubject->mScopeEntry->mSize; | ||
3033 | mBody->mScopeEntry->mOffset = (S32)count; | ||
3034 | mBody->mScopeEntry->mSize = 4; | ||
3035 | count += mBody->mScopeEntry->mSize; | ||
3036 | mNumber->mScopeEntry->mOffset = (S32)count; | ||
3037 | mNumber->mScopeEntry->mSize = 4; | ||
3038 | count += mNumber->mScopeEntry->mSize; | ||
3039 | } | ||
3040 | } | ||
3041 | break; | ||
3042 | case LSCP_EMIT_BYTE_CODE: | ||
3043 | { | ||
3044 | #ifdef LSL_INCLUDE_DEBUG_INFO | ||
3045 | char name[] = "email"; | ||
3046 | chunk->addBytes(name, strlen(name) + 1); | ||
3047 | chunk->addBytes(mTime->mName, strlen(mTime->mName) + 1); | ||
3048 | chunk->addBytes(mAddress->mName, strlen(mAddress->mName) + 1); | ||
3049 | chunk->addBytes(mSubject->mName, strlen(mSubject->mName) + 1); | ||
3050 | chunk->addBytes(mBody->mName, strlen(mBody->mName) + 1); | ||
3051 | chunk->addBytes(mNumber->mName, strlen(mNumber->mName) + 1); | ||
3052 | #endif | ||
3053 | } | ||
3054 | break; | ||
3055 | default: | ||
3056 | mTime->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
3057 | mAddress->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
3058 | mSubject->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
3059 | mBody->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
3060 | mNumber->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
3061 | break; | ||
3062 | } | ||
3063 | } | ||
3064 | |||
3065 | S32 LLScriptEmailEvent::getSize() | ||
3066 | { | ||
3067 | // string + string + string + string + integer = 16 | ||
3068 | return 20; | ||
3069 | } | ||
3070 | |||
3071 | void LLScriptRezEvent::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
3072 | { | ||
3073 | if (gErrorToText.getErrors()) | ||
3074 | { | ||
3075 | return; | ||
3076 | } | ||
3077 | switch(pass) | ||
3078 | { | ||
3079 | case LSCP_PRETTY_PRINT: | ||
3080 | case LSCP_EMIT_ASSEMBLY: | ||
3081 | fdotabs(fp, tabs, tabsize); | ||
3082 | fprintf(fp, "rez( integer "); | ||
3083 | mStartParam->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
3084 | fprintf(fp, " )\n"); | ||
3085 | break; | ||
3086 | case LSCP_SCOPE_PASS1: | ||
3087 | if (scope->checkEntry(mStartParam->mName)) | ||
3088 | { | ||
3089 | gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME); | ||
3090 | } | ||
3091 | else | ||
3092 | { | ||
3093 | mStartParam->mScopeEntry = scope->addEntry(mStartParam->mName, LIT_VARIABLE, LST_INTEGER); | ||
3094 | } | ||
3095 | break; | ||
3096 | case LSCP_RESOURCE: | ||
3097 | { | ||
3098 | // we're just tryng to determine how much space the variable needs | ||
3099 | if (mStartParam->mScopeEntry) | ||
3100 | { | ||
3101 | mStartParam->mScopeEntry->mOffset = (S32)count; | ||
3102 | mStartParam->mScopeEntry->mSize = 4; | ||
3103 | count += mStartParam->mScopeEntry->mSize; | ||
3104 | } | ||
3105 | } | ||
3106 | break; | ||
3107 | case LSCP_EMIT_BYTE_CODE: | ||
3108 | { | ||
3109 | #ifdef LSL_INCLUDE_DEBUG_INFO | ||
3110 | char name[] = "rez"; | ||
3111 | chunk->addBytes(name, strlen(name) + 1); | ||
3112 | chunk->addBytes(mStartParam->mName, strlen(mStartParam->mName) + 1); | ||
3113 | #endif | ||
3114 | } | ||
3115 | break; | ||
3116 | default: | ||
3117 | mStartParam->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
3118 | break; | ||
3119 | } | ||
3120 | } | ||
3121 | |||
3122 | S32 LLScriptRezEvent::getSize() | ||
3123 | { | ||
3124 | // integer = 4 | ||
3125 | return 4; | ||
3126 | } | ||
3127 | |||
3128 | void LLScriptNoSensorEvent::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
3129 | { | ||
3130 | if (gErrorToText.getErrors()) | ||
3131 | { | ||
3132 | return; | ||
3133 | } | ||
3134 | switch(pass) | ||
3135 | { | ||
3136 | case LSCP_PRETTY_PRINT: | ||
3137 | fdotabs(fp, tabs, tabsize); | ||
3138 | fprintf(fp, "no_sensor()\n"); | ||
3139 | break; | ||
3140 | case LSCP_EMIT_ASSEMBLY: | ||
3141 | fprintf(fp, "no_sensor()\n"); | ||
3142 | break; | ||
3143 | case LSCP_EMIT_BYTE_CODE: | ||
3144 | { | ||
3145 | #ifdef LSL_INCLUDE_DEBUG_INFO | ||
3146 | char name[] = "no_sensor"; | ||
3147 | chunk->addBytes(name, strlen(name) + 1); | ||
3148 | #endif | ||
3149 | } | ||
3150 | break; | ||
3151 | default: | ||
3152 | break; | ||
3153 | } | ||
3154 | } | ||
3155 | |||
3156 | S32 LLScriptNoSensorEvent::getSize() | ||
3157 | { | ||
3158 | return 0; | ||
3159 | } | ||
3160 | |||
3161 | void LLScriptAtTarget::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
3162 | { | ||
3163 | if (gErrorToText.getErrors()) | ||
3164 | { | ||
3165 | return; | ||
3166 | } | ||
3167 | switch(pass) | ||
3168 | { | ||
3169 | case LSCP_PRETTY_PRINT: | ||
3170 | case LSCP_EMIT_ASSEMBLY: | ||
3171 | fdotabs(fp, tabs, tabsize); | ||
3172 | fprintf(fp, "at_target( integer "); | ||
3173 | mTargetNumber->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
3174 | fprintf(fp, ", vector "); | ||
3175 | mTargetPosition->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
3176 | fprintf(fp, ", vector "); | ||
3177 | mOurPosition->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
3178 | fprintf(fp, " )\n"); | ||
3179 | break; | ||
3180 | case LSCP_SCOPE_PASS1: | ||
3181 | if (scope->checkEntry(mTargetNumber->mName)) | ||
3182 | { | ||
3183 | gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME); | ||
3184 | } | ||
3185 | else | ||
3186 | { | ||
3187 | mTargetNumber->mScopeEntry = scope->addEntry(mTargetNumber->mName, LIT_VARIABLE, LST_INTEGER); | ||
3188 | } | ||
3189 | if (scope->checkEntry(mTargetPosition->mName)) | ||
3190 | { | ||
3191 | gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME); | ||
3192 | } | ||
3193 | else | ||
3194 | { | ||
3195 | mTargetPosition->mScopeEntry = scope->addEntry(mTargetPosition->mName, LIT_VARIABLE, LST_VECTOR); | ||
3196 | } | ||
3197 | if (scope->checkEntry(mOurPosition->mName)) | ||
3198 | { | ||
3199 | gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME); | ||
3200 | } | ||
3201 | else | ||
3202 | { | ||
3203 | mOurPosition->mScopeEntry = scope->addEntry(mOurPosition->mName, LIT_VARIABLE, LST_VECTOR); | ||
3204 | } | ||
3205 | break; | ||
3206 | case LSCP_RESOURCE: | ||
3207 | { | ||
3208 | // we're just tryng to determine how much space the variable needs | ||
3209 | if (mTargetNumber->mScopeEntry) | ||
3210 | { | ||
3211 | mTargetNumber->mScopeEntry->mOffset = (S32)count; | ||
3212 | mTargetNumber->mScopeEntry->mSize = 4; | ||
3213 | count += mTargetNumber->mScopeEntry->mSize; | ||
3214 | mTargetPosition->mScopeEntry->mOffset = (S32)count; | ||
3215 | mTargetPosition->mScopeEntry->mSize = 12; | ||
3216 | count += mTargetPosition->mScopeEntry->mSize; | ||
3217 | mOurPosition->mScopeEntry->mOffset = (S32)count; | ||
3218 | mOurPosition->mScopeEntry->mSize = 12; | ||
3219 | count += mOurPosition->mScopeEntry->mSize; | ||
3220 | } | ||
3221 | } | ||
3222 | break; | ||
3223 | case LSCP_EMIT_BYTE_CODE: | ||
3224 | { | ||
3225 | #ifdef LSL_INCLUDE_DEBUG_INFO | ||
3226 | char name[] = "at_target"; | ||
3227 | chunk->addBytes(name, strlen(name) + 1); | ||
3228 | chunk->addBytes(mTargetNumber->mName, strlen(mTargetNumber->mName) + 1); | ||
3229 | chunk->addBytes(mTargetPosition->mName, strlen(mTargetPosition->mName) + 1); | ||
3230 | chunk->addBytes(mOurPosition->mName, strlen(mOurPosition->mName) + 1); | ||
3231 | #endif | ||
3232 | } | ||
3233 | break; | ||
3234 | default: | ||
3235 | mTargetNumber->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
3236 | mTargetPosition->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
3237 | mOurPosition->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
3238 | break; | ||
3239 | } | ||
3240 | } | ||
3241 | |||
3242 | S32 LLScriptAtTarget::getSize() | ||
3243 | { | ||
3244 | // integer + vector + vector = 28 | ||
3245 | return 28; | ||
3246 | } | ||
3247 | |||
3248 | |||
3249 | |||
3250 | void LLScriptNotAtTarget::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
3251 | { | ||
3252 | if (gErrorToText.getErrors()) | ||
3253 | { | ||
3254 | return; | ||
3255 | } | ||
3256 | switch(pass) | ||
3257 | { | ||
3258 | case LSCP_PRETTY_PRINT: | ||
3259 | fdotabs(fp, tabs, tabsize); | ||
3260 | fprintf(fp, "not_at_target()\n"); | ||
3261 | break; | ||
3262 | case LSCP_EMIT_ASSEMBLY: | ||
3263 | fprintf(fp, "not_at_target()\n"); | ||
3264 | break; | ||
3265 | case LSCP_EMIT_BYTE_CODE: | ||
3266 | { | ||
3267 | #ifdef LSL_INCLUDE_DEBUG_INFO | ||
3268 | char name[] = "not_at_target"; | ||
3269 | chunk->addBytes(name, strlen(name) + 1); | ||
3270 | #endif | ||
3271 | } | ||
3272 | break; | ||
3273 | default: | ||
3274 | break; | ||
3275 | } | ||
3276 | } | ||
3277 | |||
3278 | S32 LLScriptNotAtTarget::getSize() | ||
3279 | { | ||
3280 | return 0; | ||
3281 | } | ||
3282 | |||
3283 | void LLScriptAtRotTarget::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
3284 | { | ||
3285 | if (gErrorToText.getErrors()) | ||
3286 | { | ||
3287 | return; | ||
3288 | } | ||
3289 | switch(pass) | ||
3290 | { | ||
3291 | case LSCP_PRETTY_PRINT: | ||
3292 | case LSCP_EMIT_ASSEMBLY: | ||
3293 | fdotabs(fp, tabs, tabsize); | ||
3294 | fprintf(fp, "at_target( integer "); | ||
3295 | mTargetNumber->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
3296 | fprintf(fp, ", quaternion "); | ||
3297 | mTargetRotation->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
3298 | fprintf(fp, ", quaternion "); | ||
3299 | mOurRotation->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
3300 | fprintf(fp, " )\n"); | ||
3301 | break; | ||
3302 | case LSCP_SCOPE_PASS1: | ||
3303 | if (scope->checkEntry(mTargetNumber->mName)) | ||
3304 | { | ||
3305 | gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME); | ||
3306 | } | ||
3307 | else | ||
3308 | { | ||
3309 | mTargetNumber->mScopeEntry = scope->addEntry(mTargetNumber->mName, LIT_VARIABLE, LST_INTEGER); | ||
3310 | } | ||
3311 | if (scope->checkEntry(mTargetRotation->mName)) | ||
3312 | { | ||
3313 | gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME); | ||
3314 | } | ||
3315 | else | ||
3316 | { | ||
3317 | mTargetRotation->mScopeEntry = scope->addEntry(mTargetRotation->mName, LIT_VARIABLE, LST_QUATERNION); | ||
3318 | } | ||
3319 | if (scope->checkEntry(mOurRotation->mName)) | ||
3320 | { | ||
3321 | gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME); | ||
3322 | } | ||
3323 | else | ||
3324 | { | ||
3325 | mOurRotation->mScopeEntry = scope->addEntry(mOurRotation->mName, LIT_VARIABLE, LST_QUATERNION); | ||
3326 | } | ||
3327 | break; | ||
3328 | case LSCP_RESOURCE: | ||
3329 | { | ||
3330 | // we're just tryng to determine how much space the variable needs | ||
3331 | if (mTargetNumber->mScopeEntry) | ||
3332 | { | ||
3333 | mTargetNumber->mScopeEntry->mOffset = (S32)count; | ||
3334 | mTargetNumber->mScopeEntry->mSize = 4; | ||
3335 | count += mTargetNumber->mScopeEntry->mSize; | ||
3336 | mTargetRotation->mScopeEntry->mOffset = (S32)count; | ||
3337 | mTargetRotation->mScopeEntry->mSize = 16; | ||
3338 | count += mTargetRotation->mScopeEntry->mSize; | ||
3339 | mOurRotation->mScopeEntry->mOffset = (S32)count; | ||
3340 | mOurRotation->mScopeEntry->mSize = 16; | ||
3341 | count += mOurRotation->mScopeEntry->mSize; | ||
3342 | } | ||
3343 | } | ||
3344 | break; | ||
3345 | case LSCP_EMIT_BYTE_CODE: | ||
3346 | { | ||
3347 | #ifdef LSL_INCLUDE_DEBUG_INFO | ||
3348 | char name[] = "at_rot_target"; | ||
3349 | chunk->addBytes(name, strlen(name) + 1); | ||
3350 | chunk->addBytes(mTargetNumber->mName, strlen(mTargetNumber->mName) + 1); | ||
3351 | chunk->addBytes(mTargetRotation->mName, strlen(mTargetRotation->mName) + 1); | ||
3352 | chunk->addBytes(mOurRotation->mName, strlen(mOurRotation->mName) + 1); | ||
3353 | #endif | ||
3354 | } | ||
3355 | break; | ||
3356 | default: | ||
3357 | mTargetNumber->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
3358 | mTargetRotation->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
3359 | mOurRotation->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
3360 | break; | ||
3361 | } | ||
3362 | } | ||
3363 | |||
3364 | S32 LLScriptAtRotTarget::getSize() | ||
3365 | { | ||
3366 | // integer + quaternion + quaternion = 36 | ||
3367 | return 36; | ||
3368 | } | ||
3369 | |||
3370 | |||
3371 | |||
3372 | void LLScriptNotAtRotTarget::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
3373 | { | ||
3374 | if (gErrorToText.getErrors()) | ||
3375 | { | ||
3376 | return; | ||
3377 | } | ||
3378 | switch(pass) | ||
3379 | { | ||
3380 | case LSCP_PRETTY_PRINT: | ||
3381 | fdotabs(fp, tabs, tabsize); | ||
3382 | fprintf(fp, "not_at_rot_target()\n"); | ||
3383 | break; | ||
3384 | case LSCP_EMIT_ASSEMBLY: | ||
3385 | fprintf(fp, "not_at_rot_target()\n"); | ||
3386 | break; | ||
3387 | case LSCP_EMIT_BYTE_CODE: | ||
3388 | { | ||
3389 | #ifdef LSL_INCLUDE_DEBUG_INFO | ||
3390 | char name[] = "not_at_rot_target"; | ||
3391 | chunk->addBytes(name, strlen(name) + 1); | ||
3392 | #endif | ||
3393 | } | ||
3394 | break; | ||
3395 | default: | ||
3396 | break; | ||
3397 | } | ||
3398 | } | ||
3399 | |||
3400 | S32 LLScriptNotAtRotTarget::getSize() | ||
3401 | { | ||
3402 | return 0; | ||
3403 | } | ||
3404 | |||
3405 | |||
3406 | |||
3407 | void LLScriptExpression::addExpression(LLScriptExpression *expression) | ||
3408 | { | ||
3409 | if (mNextp) | ||
3410 | { | ||
3411 | expression->mNextp = mNextp; | ||
3412 | } | ||
3413 | mNextp = expression; | ||
3414 | } | ||
3415 | |||
3416 | void LLScriptExpression::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
3417 | { | ||
3418 | fprintf(fp, "Expression Base Class -- should never get here!\n"); | ||
3419 | } | ||
3420 | |||
3421 | S32 LLScriptExpression::getSize() | ||
3422 | { | ||
3423 | printf("Expression Base Class -- should never get here!\n"); | ||
3424 | return 0; | ||
3425 | } | ||
3426 | |||
3427 | void LLScriptExpression::gonext(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
3428 | { | ||
3429 | if (gErrorToText.getErrors()) | ||
3430 | { | ||
3431 | return; | ||
3432 | } | ||
3433 | switch(pass) | ||
3434 | { | ||
3435 | case LSCP_PRETTY_PRINT: | ||
3436 | if (mNextp) | ||
3437 | { | ||
3438 | fprintf(fp, ", "); | ||
3439 | mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
3440 | } | ||
3441 | break; | ||
3442 | default: | ||
3443 | if (mNextp) | ||
3444 | { | ||
3445 | mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
3446 | } | ||
3447 | break; | ||
3448 | } | ||
3449 | } | ||
3450 | |||
3451 | void LLScriptForExpressionList::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
3452 | { | ||
3453 | if (gErrorToText.getErrors()) | ||
3454 | { | ||
3455 | return; | ||
3456 | } | ||
3457 | switch(pass) | ||
3458 | { | ||
3459 | case LSCP_PRETTY_PRINT: | ||
3460 | mFirstp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
3461 | if (mSecondp) | ||
3462 | { | ||
3463 | fprintf(fp, ", "); | ||
3464 | mSecondp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
3465 | } | ||
3466 | break; | ||
3467 | case LSCP_EMIT_ASSEMBLY: | ||
3468 | mFirstp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
3469 | if (mFirstp->mReturnType) | ||
3470 | { | ||
3471 | fprintf(fp, "%s\n", LSCRIPTTypePop[mFirstp->mReturnType]); | ||
3472 | } | ||
3473 | if (mSecondp) | ||
3474 | { | ||
3475 | mSecondp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
3476 | if (mSecondp->mReturnType) | ||
3477 | { | ||
3478 | fprintf(fp, "%s\n", LSCRIPTTypePop[mSecondp->mReturnType]); | ||
3479 | } | ||
3480 | } | ||
3481 | break; | ||
3482 | case LSCP_TO_STACK: | ||
3483 | mFirstp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
3484 | switch(mFirstp->mReturnType) | ||
3485 | { | ||
3486 | case LST_INTEGER: | ||
3487 | case LST_FLOATINGPOINT: | ||
3488 | chunk->addByte(LSCRIPTOpCodes[LOPC_POP]); | ||
3489 | break; | ||
3490 | case LST_STRING: | ||
3491 | case LST_KEY: | ||
3492 | chunk->addByte(LSCRIPTOpCodes[LOPC_POPS]); | ||
3493 | break; | ||
3494 | case LST_LIST: | ||
3495 | chunk->addByte(LSCRIPTOpCodes[LOPC_POPL]); | ||
3496 | break; | ||
3497 | case LST_VECTOR: | ||
3498 | chunk->addByte(LSCRIPTOpCodes[LOPC_POPV]); | ||
3499 | break; | ||
3500 | case LST_QUATERNION: | ||
3501 | chunk->addByte(LSCRIPTOpCodes[LOPC_POPQ]); | ||
3502 | break; | ||
3503 | default: | ||
3504 | break; | ||
3505 | } | ||
3506 | if (mSecondp) | ||
3507 | { | ||
3508 | mSecondp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
3509 | switch(mSecondp->mReturnType) | ||
3510 | { | ||
3511 | case LST_INTEGER: | ||
3512 | case LST_FLOATINGPOINT: | ||
3513 | chunk->addByte(LSCRIPTOpCodes[LOPC_POP]); | ||
3514 | break; | ||
3515 | case LST_STRING: | ||
3516 | case LST_KEY: | ||
3517 | chunk->addByte(LSCRIPTOpCodes[LOPC_POPS]); | ||
3518 | break; | ||
3519 | case LST_LIST: | ||
3520 | chunk->addByte(LSCRIPTOpCodes[LOPC_POPL]); | ||
3521 | break; | ||
3522 | case LST_VECTOR: | ||
3523 | chunk->addByte(LSCRIPTOpCodes[LOPC_POPV]); | ||
3524 | break; | ||
3525 | case LST_QUATERNION: | ||
3526 | chunk->addByte(LSCRIPTOpCodes[LOPC_POPQ]); | ||
3527 | break; | ||
3528 | default: | ||
3529 | break; | ||
3530 | } | ||
3531 | } | ||
3532 | break; | ||
3533 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
3534 | mFirstp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
3535 | if (mFirstp->mReturnType) | ||
3536 | { | ||
3537 | fprintf(fp, "pop\n"); | ||
3538 | } | ||
3539 | if (mSecondp) | ||
3540 | { | ||
3541 | mSecondp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
3542 | if (mSecondp->mReturnType) | ||
3543 | { | ||
3544 | fprintf(fp, "pop\n"); | ||
3545 | } | ||
3546 | } | ||
3547 | break; | ||
3548 | default: | ||
3549 | mFirstp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
3550 | if (mSecondp) | ||
3551 | { | ||
3552 | mSecondp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
3553 | } | ||
3554 | break; | ||
3555 | } | ||
3556 | } | ||
3557 | |||
3558 | S32 LLScriptForExpressionList::getSize() | ||
3559 | { | ||
3560 | return 0; | ||
3561 | } | ||
3562 | |||
3563 | void LLScriptFuncExpressionList::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
3564 | { | ||
3565 | if (gErrorToText.getErrors()) | ||
3566 | { | ||
3567 | return; | ||
3568 | } | ||
3569 | switch(pass) | ||
3570 | { | ||
3571 | case LSCP_PRETTY_PRINT: | ||
3572 | mFirstp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
3573 | if (mSecondp) | ||
3574 | { | ||
3575 | fprintf(fp, ", "); | ||
3576 | mSecondp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
3577 | } | ||
3578 | break; | ||
3579 | case LSCP_TYPE: | ||
3580 | { | ||
3581 | mFirstp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
3582 | if (!entry->mFunctionArgs.getType(entrycount)) | ||
3583 | { | ||
3584 | gErrorToText.writeError(fp, this, LSERROR_FUNCTION_TYPE_ERROR); | ||
3585 | } | ||
3586 | if (!legal_assignment(entry->mFunctionArgs.getType(entrycount), mFirstp->mReturnType)) | ||
3587 | { | ||
3588 | gErrorToText.writeError(fp, this, LSERROR_FUNCTION_TYPE_ERROR); | ||
3589 | } | ||
3590 | count++; | ||
3591 | entrycount++; | ||
3592 | if (mSecondp) | ||
3593 | { | ||
3594 | mSecondp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
3595 | if (mSecondp->mReturnType) | ||
3596 | { | ||
3597 | count++; | ||
3598 | if (!entry->mFunctionArgs.getType(entrycount)) | ||
3599 | { | ||
3600 | gErrorToText.writeError(fp, this, LSERROR_FUNCTION_TYPE_ERROR); | ||
3601 | } | ||
3602 | if (!legal_assignment(entry->mFunctionArgs.getType(entrycount), mSecondp->mReturnType)) | ||
3603 | { | ||
3604 | gErrorToText.writeError(fp, this, LSERROR_FUNCTION_TYPE_ERROR); | ||
3605 | } | ||
3606 | } | ||
3607 | } | ||
3608 | } | ||
3609 | break; | ||
3610 | case LSCP_EMIT_ASSEMBLY: | ||
3611 | { | ||
3612 | mFirstp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
3613 | LSCRIPTType argtype = entry->mFunctionArgs.getType(entrycount); | ||
3614 | if (argtype != mFirstp->mReturnType) | ||
3615 | { | ||
3616 | fprintf(fp, "CAST %s->%s\n", LSCRIPTTypeNames[mFirstp->mReturnType], LSCRIPTTypeNames[argtype]); | ||
3617 | } | ||
3618 | entrycount++; | ||
3619 | if (mSecondp) | ||
3620 | { | ||
3621 | mSecondp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
3622 | if (mSecondp->mReturnType) | ||
3623 | { | ||
3624 | argtype = entry->mFunctionArgs.getType(entrycount); | ||
3625 | if (argtype != mSecondp->mReturnType) | ||
3626 | { | ||
3627 | fprintf(fp, "CAST %s->%s\n", LSCRIPTTypeNames[mSecondp->mReturnType], LSCRIPTTypeNames[argtype]); | ||
3628 | } | ||
3629 | } | ||
3630 | } | ||
3631 | } | ||
3632 | break; | ||
3633 | case LSCP_TO_STACK: | ||
3634 | { | ||
3635 | mFirstp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
3636 | LSCRIPTType argtype = entry->mFunctionArgs.getType(entrycount); | ||
3637 | if (argtype != mFirstp->mReturnType) | ||
3638 | { | ||
3639 | chunk->addByte(LSCRIPTOpCodes[LOPC_CAST]); | ||
3640 | U8 castbyte = LSCRIPTTypeByte[argtype] | LSCRIPTTypeHi4Bits[mFirstp->mReturnType]; | ||
3641 | chunk->addByte(castbyte); | ||
3642 | } | ||
3643 | entrycount++; | ||
3644 | if (mSecondp) | ||
3645 | { | ||
3646 | mSecondp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
3647 | if (mSecondp->mReturnType) | ||
3648 | { | ||
3649 | argtype = entry->mFunctionArgs.getType(entrycount); | ||
3650 | if (argtype != mSecondp->mReturnType) | ||
3651 | { | ||
3652 | chunk->addByte(LSCRIPTOpCodes[LOPC_CAST]); | ||
3653 | U8 castbyte = LSCRIPTTypeByte[argtype] | LSCRIPTTypeHi4Bits[mSecondp->mReturnType]; | ||
3654 | chunk->addByte(castbyte); | ||
3655 | } | ||
3656 | } | ||
3657 | } | ||
3658 | } | ||
3659 | break; | ||
3660 | /* TODO: Fix conflict between global/local variable determination needing caller scope and cast determination here needs callee scope... | ||
3661 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
3662 | { | ||
3663 | mFirstp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
3664 | LSCRIPTType argtype = entry->mFunctionArgs.getType(entrycount); | ||
3665 | if (argtype != mFirstp->mReturnType) | ||
3666 | { | ||
3667 | print_cil_cast(fp, mFirstp->mReturnType, argtype); | ||
3668 | } | ||
3669 | entrycount++; | ||
3670 | if (mSecondp) | ||
3671 | { | ||
3672 | mSecondp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
3673 | if (mSecondp->mReturnType) | ||
3674 | { | ||
3675 | argtype = entry->mFunctionArgs.getType(entrycount); | ||
3676 | if (argtype != mSecondp->mReturnType) | ||
3677 | { | ||
3678 | print_cil_cast(fp, mFirstp->mReturnType, argtype); | ||
3679 | } | ||
3680 | } | ||
3681 | } | ||
3682 | } | ||
3683 | break; | ||
3684 | */ | ||
3685 | default: | ||
3686 | mFirstp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
3687 | if (mSecondp) | ||
3688 | { | ||
3689 | mSecondp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
3690 | } | ||
3691 | break; | ||
3692 | } | ||
3693 | } | ||
3694 | |||
3695 | S32 LLScriptFuncExpressionList::getSize() | ||
3696 | { | ||
3697 | return 0; | ||
3698 | } | ||
3699 | |||
3700 | void LLScriptListExpressionList::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
3701 | { | ||
3702 | if (gErrorToText.getErrors()) | ||
3703 | { | ||
3704 | return; | ||
3705 | } | ||
3706 | switch(pass) | ||
3707 | { | ||
3708 | case LSCP_PRETTY_PRINT: | ||
3709 | mFirstp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
3710 | if (mSecondp) | ||
3711 | { | ||
3712 | fprintf(fp, ", "); | ||
3713 | mSecondp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
3714 | } | ||
3715 | break; | ||
3716 | case LSCP_EMIT_ASSEMBLY: | ||
3717 | mFirstp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
3718 | if (mFirstp->mType != LET_LIST_EXPRESSION_LIST) | ||
3719 | { | ||
3720 | fprintf(fp, "%s\n", LSCRIPTListDescription[mFirstp->mReturnType]); | ||
3721 | count++; | ||
3722 | } | ||
3723 | if (mSecondp) | ||
3724 | { | ||
3725 | mSecondp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
3726 | if (mSecondp->mType != LET_LIST_EXPRESSION_LIST) | ||
3727 | { | ||
3728 | fprintf(fp, "%s\n", LSCRIPTListDescription[mSecondp->mReturnType]); | ||
3729 | count++; | ||
3730 | } | ||
3731 | } | ||
3732 | break; | ||
3733 | case LSCP_TO_STACK: | ||
3734 | mFirstp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
3735 | if (mFirstp->mType != LET_LIST_EXPRESSION_LIST) | ||
3736 | { | ||
3737 | chunk->addByte(LSCRIPTOpCodes[LOPC_PUSHARGB]); | ||
3738 | chunk->addByte(LSCRIPTTypeByte[mFirstp->mReturnType]); | ||
3739 | count++; | ||
3740 | } | ||
3741 | if (mSecondp) | ||
3742 | { | ||
3743 | mSecondp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
3744 | if (mSecondp->mType != LET_LIST_EXPRESSION_LIST) | ||
3745 | { | ||
3746 | chunk->addByte(LSCRIPTOpCodes[LOPC_PUSHARGB]); | ||
3747 | chunk->addByte(LSCRIPTTypeByte[mSecondp->mReturnType]); | ||
3748 | count++; | ||
3749 | } | ||
3750 | } | ||
3751 | break; | ||
3752 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
3753 | // Evaluate expressions in reverse order so first expression is on top of stack. | ||
3754 | // Results can then be popped and appended to list to result in list with correct order. | ||
3755 | if (mSecondp) | ||
3756 | { | ||
3757 | mSecondp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
3758 | if (mSecondp->mType != LET_LIST_EXPRESSION_LIST) | ||
3759 | { | ||
3760 | // Box value. | ||
3761 | print_cil_box(fp, mSecondp->mReturnType); | ||
3762 | |||
3763 | ++count; | ||
3764 | } | ||
3765 | } | ||
3766 | mFirstp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
3767 | if (mFirstp->mType != LET_LIST_EXPRESSION_LIST) | ||
3768 | { | ||
3769 | // Box value. | ||
3770 | print_cil_box(fp, mFirstp->mReturnType); | ||
3771 | |||
3772 | ++count; | ||
3773 | } | ||
3774 | break; | ||
3775 | default: | ||
3776 | mFirstp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
3777 | if (mSecondp) | ||
3778 | { | ||
3779 | mSecondp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
3780 | } | ||
3781 | break; | ||
3782 | } | ||
3783 | } | ||
3784 | |||
3785 | S32 LLScriptListExpressionList::getSize() | ||
3786 | { | ||
3787 | return 0; | ||
3788 | } | ||
3789 | |||
3790 | // Returns true if identifier is a parameter and false if identifier is a local variable within function_scope. | ||
3791 | bool is_parameter(LLScriptIdentifier* identifier, LLScriptScopeEntry* function_scope) | ||
3792 | { | ||
3793 | // Function offset stores offset of first local. | ||
3794 | // Compare variable offset with function offset to | ||
3795 | // determine whether variable is local or parameter. | ||
3796 | return (identifier->mScopeEntry->mOffset < function_scope->mOffset); | ||
3797 | } | ||
3798 | |||
3799 | // If assignment is to global variable, pushes this pointer on to stack. | ||
3800 | void print_cil_load_address(FILE* fp, LLScriptExpression* exp, LLScriptScopeEntry* function_scope) | ||
3801 | { | ||
3802 | LLScriptLValue *lvalue = (LLScriptLValue *) exp; | ||
3803 | LLScriptIdentifier *ident = lvalue->mIdentifier; | ||
3804 | |||
3805 | // If global (member), load this pointer. | ||
3806 | if(ident->mScopeEntry->mIDType == LIT_GLOBAL) | ||
3807 | { | ||
3808 | fprintf(fp, "ldarg.0\n"); | ||
3809 | } | ||
3810 | |||
3811 | // If accessor, load address of object. | ||
3812 | if(lvalue->mAccessor) | ||
3813 | { | ||
3814 | if(ident->mScopeEntry->mIDType == LIT_VARIABLE) | ||
3815 | { | ||
3816 | if(is_parameter(ident, function_scope)) | ||
3817 | { | ||
3818 | // Parameter, load by name. | ||
3819 | fprintf(fp, "ldarga.s %s\n", ident->mScopeEntry->mIdentifier); | ||
3820 | } | ||
3821 | else | ||
3822 | { | ||
3823 | // Local, load by index. | ||
3824 | fprintf(fp, "ldloca.s %d\n", ident->mScopeEntry->mCount); | ||
3825 | } | ||
3826 | } | ||
3827 | else if (ident->mScopeEntry->mIDType == LIT_GLOBAL) | ||
3828 | { | ||
3829 | fprintf(fp, "ldflda "); | ||
3830 | print_cil_type(fp, ident->mScopeEntry->mType); | ||
3831 | fprintf(fp, " LSL::%s\n", ident->mScopeEntry->mIdentifier); | ||
3832 | } | ||
3833 | } | ||
3834 | } | ||
3835 | |||
3836 | void print_cil_accessor(FILE* fp, LLScriptLValue *lvalue) | ||
3837 | { | ||
3838 | LLScriptIdentifier *ident = lvalue->mIdentifier; | ||
3839 | print_cil_type(fp, lvalue->mReturnType); | ||
3840 | fprintf(fp, " "); | ||
3841 | print_cil_type(fp, ident->mScopeEntry->mType); | ||
3842 | fprintf(fp, "::%s\n", lvalue->mAccessor->mName); | ||
3843 | } | ||
3844 | |||
3845 | void print_cil_member(FILE* fp, LLScriptIdentifier *ident) | ||
3846 | { | ||
3847 | print_cil_type(fp, ident->mScopeEntry->mType); | ||
3848 | fprintf(fp, " LSL::%s\n", ident->mScopeEntry->mIdentifier); | ||
3849 | } | ||
3850 | |||
3851 | void LLScriptLValue::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
3852 | { | ||
3853 | if (gErrorToText.getErrors()) | ||
3854 | { | ||
3855 | return; | ||
3856 | } | ||
3857 | switch(pass) | ||
3858 | { | ||
3859 | case LSCP_PRETTY_PRINT: | ||
3860 | mIdentifier->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
3861 | if (mAccessor) | ||
3862 | { | ||
3863 | fprintf(fp, "."); | ||
3864 | mAccessor->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
3865 | } | ||
3866 | break; | ||
3867 | case LSCP_EMIT_ASSEMBLY: | ||
3868 | if (mIdentifier->mScopeEntry->mIDType == LIT_VARIABLE) | ||
3869 | { | ||
3870 | if (mAccessor) | ||
3871 | { | ||
3872 | fprintf(fp, "%s%d [%s.%s]\n", LSCRIPTTypeLocalPush[mReturnType], mIdentifier->mScopeEntry->mOffset + mOffset, mIdentifier->mName, mAccessor->mName); | ||
3873 | } | ||
3874 | else | ||
3875 | { | ||
3876 | fprintf(fp, "%s%d [%s]\n", LSCRIPTTypeLocalPush[mIdentifier->mScopeEntry->mType], mIdentifier->mScopeEntry->mOffset, mIdentifier->mName); | ||
3877 | } | ||
3878 | } | ||
3879 | else if (mIdentifier->mScopeEntry->mIDType == LIT_GLOBAL) | ||
3880 | { | ||
3881 | if (mAccessor) | ||
3882 | { | ||
3883 | fprintf(fp, "%s%d [%s.%s]\n", LSCRIPTTypeGlobalPush[mReturnType], mIdentifier->mScopeEntry->mOffset + mOffset, mIdentifier->mName, mAccessor->mName); | ||
3884 | } | ||
3885 | else | ||
3886 | { | ||
3887 | fprintf(fp, "%s%d [%s]\n", LSCRIPTTypeGlobalPush[mIdentifier->mScopeEntry->mType], mIdentifier->mScopeEntry->mOffset, mIdentifier->mName); | ||
3888 | } | ||
3889 | } | ||
3890 | else | ||
3891 | { | ||
3892 | fprintf(fp, "Unexpected LValue!\n"); | ||
3893 | } | ||
3894 | break; | ||
3895 | case LSCP_SCOPE_PASS1: | ||
3896 | { | ||
3897 | LLScriptScopeEntry *entry = scope->findEntry(mIdentifier->mName); | ||
3898 | if (!entry || ( (entry->mIDType != LIT_GLOBAL) && (entry->mIDType != LIT_VARIABLE))) | ||
3899 | { | ||
3900 | gErrorToText.writeError(fp, this, LSERROR_UNDEFINED_NAME); | ||
3901 | } | ||
3902 | else | ||
3903 | { | ||
3904 | // if we did find it, make sure this identifier is associated with the correct scope entry | ||
3905 | mIdentifier->mScopeEntry = entry; | ||
3906 | } | ||
3907 | } | ||
3908 | break; | ||
3909 | case LSCP_TYPE: | ||
3910 | // if we have an accessor, we need to change what type our identifier returns and set our offset value | ||
3911 | if (mIdentifier->mScopeEntry) | ||
3912 | { | ||
3913 | if (mAccessor) | ||
3914 | { | ||
3915 | BOOL b_ok = FALSE; | ||
3916 | if (mIdentifier->mScopeEntry->mIDType == LIT_VARIABLE) | ||
3917 | { | ||
3918 | if (mIdentifier->mScopeEntry->mType == LST_VECTOR) | ||
3919 | { | ||
3920 | if (!strcmp("x", mAccessor->mName)) | ||
3921 | { | ||
3922 | mOffset = 0; | ||
3923 | b_ok = TRUE; | ||
3924 | } | ||
3925 | else if (!strcmp("y", mAccessor->mName)) | ||
3926 | { | ||
3927 | mOffset = 4; | ||
3928 | b_ok = TRUE; | ||
3929 | } | ||
3930 | else if (!strcmp("z", mAccessor->mName)) | ||
3931 | { | ||
3932 | mOffset = 8; | ||
3933 | b_ok = TRUE; | ||
3934 | } | ||
3935 | } | ||
3936 | else if (mIdentifier->mScopeEntry->mType == LST_QUATERNION) | ||
3937 | { | ||
3938 | if (!strcmp("x", mAccessor->mName)) | ||
3939 | { | ||
3940 | mOffset = 0; | ||
3941 | b_ok = TRUE; | ||
3942 | } | ||
3943 | else if (!strcmp("y", mAccessor->mName)) | ||
3944 | { | ||
3945 | mOffset = 4; | ||
3946 | b_ok = TRUE; | ||
3947 | } | ||
3948 | else if (!strcmp("z", mAccessor->mName)) | ||
3949 | { | ||
3950 | mOffset = 8; | ||
3951 | b_ok = TRUE; | ||
3952 | } | ||
3953 | else if (!strcmp("s", mAccessor->mName)) | ||
3954 | { | ||
3955 | mOffset = 12; | ||
3956 | b_ok = TRUE; | ||
3957 | } | ||
3958 | } | ||
3959 | } | ||
3960 | else | ||
3961 | { | ||
3962 | if (mIdentifier->mScopeEntry->mType == LST_VECTOR) | ||
3963 | { | ||
3964 | if (!strcmp("x", mAccessor->mName)) | ||
3965 | { | ||
3966 | mOffset = 8; | ||
3967 | b_ok = TRUE; | ||
3968 | } | ||
3969 | else if (!strcmp("y", mAccessor->mName)) | ||
3970 | { | ||
3971 | mOffset = 4; | ||
3972 | b_ok = TRUE; | ||
3973 | } | ||
3974 | else if (!strcmp("z", mAccessor->mName)) | ||
3975 | { | ||
3976 | mOffset = 0; | ||
3977 | b_ok = TRUE; | ||
3978 | } | ||
3979 | } | ||
3980 | else if (mIdentifier->mScopeEntry->mType == LST_QUATERNION) | ||
3981 | { | ||
3982 | if (!strcmp("x", mAccessor->mName)) | ||
3983 | { | ||
3984 | mOffset = 12; | ||
3985 | b_ok = TRUE; | ||
3986 | } | ||
3987 | else if (!strcmp("y", mAccessor->mName)) | ||
3988 | { | ||
3989 | mOffset = 8; | ||
3990 | b_ok = TRUE; | ||
3991 | } | ||
3992 | else if (!strcmp("z", mAccessor->mName)) | ||
3993 | { | ||
3994 | mOffset = 4; | ||
3995 | b_ok = TRUE; | ||
3996 | } | ||
3997 | else if (!strcmp("s", mAccessor->mName)) | ||
3998 | { | ||
3999 | mOffset = 0; | ||
4000 | b_ok = TRUE; | ||
4001 | } | ||
4002 | } | ||
4003 | } | ||
4004 | if (b_ok) | ||
4005 | { | ||
4006 | mReturnType = type = LST_FLOATINGPOINT; | ||
4007 | } | ||
4008 | else | ||
4009 | { | ||
4010 | gErrorToText.writeError(fp, this, LSERROR_VECTOR_METHOD_ERROR); | ||
4011 | } | ||
4012 | } | ||
4013 | else | ||
4014 | { | ||
4015 | mReturnType = type = mIdentifier->mScopeEntry->mType; | ||
4016 | } | ||
4017 | } | ||
4018 | else | ||
4019 | { | ||
4020 | mReturnType = type = LST_UNDEFINED; | ||
4021 | } | ||
4022 | break; | ||
4023 | case LSCP_TO_STACK: | ||
4024 | { | ||
4025 | switch(mReturnType) | ||
4026 | { | ||
4027 | case LST_INTEGER: | ||
4028 | case LST_FLOATINGPOINT: | ||
4029 | if (mIdentifier->mScopeEntry->mIDType == LIT_VARIABLE) | ||
4030 | { | ||
4031 | chunk->addByte(LSCRIPTOpCodes[LOPC_PUSH]); | ||
4032 | } | ||
4033 | else | ||
4034 | { | ||
4035 | chunk->addByte(LSCRIPTOpCodes[LOPC_PUSHG]); | ||
4036 | } | ||
4037 | break; | ||
4038 | case LST_KEY: | ||
4039 | case LST_STRING: | ||
4040 | if (mIdentifier->mScopeEntry->mIDType == LIT_VARIABLE) | ||
4041 | { | ||
4042 | chunk->addByte(LSCRIPTOpCodes[LOPC_PUSHS]); | ||
4043 | } | ||
4044 | else | ||
4045 | { | ||
4046 | chunk->addByte(LSCRIPTOpCodes[LOPC_PUSHGS]); | ||
4047 | } | ||
4048 | break; | ||
4049 | case LST_LIST: | ||
4050 | if (mIdentifier->mScopeEntry->mIDType == LIT_VARIABLE) | ||
4051 | { | ||
4052 | chunk->addByte(LSCRIPTOpCodes[LOPC_PUSHL]); | ||
4053 | } | ||
4054 | else | ||
4055 | { | ||
4056 | chunk->addByte(LSCRIPTOpCodes[LOPC_PUSHGL]); | ||
4057 | } | ||
4058 | break; | ||
4059 | case LST_VECTOR: | ||
4060 | if (mIdentifier->mScopeEntry->mIDType == LIT_VARIABLE) | ||
4061 | { | ||
4062 | chunk->addByte(LSCRIPTOpCodes[LOPC_PUSHV]); | ||
4063 | } | ||
4064 | else | ||
4065 | { | ||
4066 | chunk->addByte(LSCRIPTOpCodes[LOPC_PUSHGV]); | ||
4067 | } | ||
4068 | break; | ||
4069 | case LST_QUATERNION: | ||
4070 | if (mIdentifier->mScopeEntry->mIDType == LIT_VARIABLE) | ||
4071 | { | ||
4072 | chunk->addByte(LSCRIPTOpCodes[LOPC_PUSHQ]); | ||
4073 | } | ||
4074 | else | ||
4075 | { | ||
4076 | chunk->addByte(LSCRIPTOpCodes[LOPC_PUSHGQ]); | ||
4077 | } | ||
4078 | break; | ||
4079 | default: | ||
4080 | if (mIdentifier->mScopeEntry->mIDType == LIT_VARIABLE) | ||
4081 | { | ||
4082 | chunk->addByte(LSCRIPTOpCodes[LOPC_PUSH]); | ||
4083 | } | ||
4084 | else | ||
4085 | { | ||
4086 | chunk->addByte(LSCRIPTOpCodes[LOPC_PUSHG]); | ||
4087 | } | ||
4088 | break; | ||
4089 | } | ||
4090 | S32 address = mIdentifier->mScopeEntry->mOffset + mOffset; | ||
4091 | chunk->addInteger(address); | ||
4092 | } | ||
4093 | break; | ||
4094 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
4095 | print_cil_load_address(fp, this, entry); | ||
4096 | if(mAccessor) | ||
4097 | { | ||
4098 | fprintf(fp, "ldfld "); | ||
4099 | print_cil_accessor(fp, this); | ||
4100 | } | ||
4101 | else if(mIdentifier->mScopeEntry->mIDType == LIT_VARIABLE) | ||
4102 | { | ||
4103 | if(is_parameter(mIdentifier, entry)) | ||
4104 | { | ||
4105 | // Parameter, load by name. | ||
4106 | fprintf(fp, "ldarg.s %s\n", mIdentifier->mScopeEntry->mIdentifier); | ||
4107 | } | ||
4108 | else | ||
4109 | { | ||
4110 | // Local, load by index. | ||
4111 | fprintf(fp, "ldloc.s %d\n", mIdentifier->mScopeEntry->mCount); | ||
4112 | } | ||
4113 | } | ||
4114 | else if (mIdentifier->mScopeEntry->mIDType == LIT_GLOBAL) | ||
4115 | { | ||
4116 | fprintf(fp, "ldfld "); | ||
4117 | print_cil_member(fp, mIdentifier); | ||
4118 | } | ||
4119 | else | ||
4120 | { | ||
4121 | fprintf(fp, "Unexpected LValue!\n"); | ||
4122 | } | ||
4123 | break; | ||
4124 | default: | ||
4125 | mIdentifier->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4126 | break; | ||
4127 | } | ||
4128 | gonext(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4129 | } | ||
4130 | |||
4131 | S32 LLScriptLValue::getSize() | ||
4132 | { | ||
4133 | return 0; | ||
4134 | } | ||
4135 | |||
4136 | void print_asignment(FILE *fp, LLScriptExpression *exp) | ||
4137 | { | ||
4138 | LLScriptLValue *lvalue = (LLScriptLValue *)exp; | ||
4139 | LLScriptIdentifier *ident = lvalue->mIdentifier; | ||
4140 | if (lvalue->mAccessor) | ||
4141 | { | ||
4142 | if (ident->mScopeEntry->mIDType == LIT_VARIABLE) | ||
4143 | { | ||
4144 | fprintf(fp, "%s%d [%s.%s]\n", LSCRIPTTypeLocalStore[ident->mScopeEntry->mType], ident->mScopeEntry->mOffset + lvalue->mOffset, ident->mName, lvalue->mAccessor->mName); | ||
4145 | } | ||
4146 | else if (ident->mScopeEntry->mIDType == LIT_GLOBAL) | ||
4147 | { | ||
4148 | fprintf(fp, "%s%d [%s.%s]\n", LSCRIPTTypeGlobalStore[ident->mScopeEntry->mType], ident->mScopeEntry->mOffset + lvalue->mOffset, ident->mName, lvalue->mAccessor->mName); | ||
4149 | } | ||
4150 | } | ||
4151 | else | ||
4152 | { | ||
4153 | if (ident->mScopeEntry->mIDType == LIT_VARIABLE) | ||
4154 | { | ||
4155 | fprintf(fp, "%s%d [%s]\n", LSCRIPTTypeLocalStore[ident->mScopeEntry->mType], ident->mScopeEntry->mOffset, ident->mName); | ||
4156 | } | ||
4157 | else if (ident->mScopeEntry->mIDType == LIT_GLOBAL) | ||
4158 | { | ||
4159 | fprintf(fp, "%s%d [%s]\n", LSCRIPTTypeGlobalStore[ident->mScopeEntry->mType], ident->mScopeEntry->mOffset, ident->mName); | ||
4160 | } | ||
4161 | } | ||
4162 | } | ||
4163 | |||
4164 | void print_cil_asignment(FILE *fp, LLScriptExpression *exp, LLScriptScopeEntry* function_scope) | ||
4165 | { | ||
4166 | LLScriptLValue *lvalue = (LLScriptLValue *) exp; | ||
4167 | LLScriptIdentifier *ident = lvalue->mIdentifier; | ||
4168 | if (lvalue->mAccessor) | ||
4169 | { | ||
4170 | // Object address loaded, store in to field. | ||
4171 | fprintf(fp, "stfld "); | ||
4172 | print_cil_accessor(fp, lvalue); | ||
4173 | |||
4174 | // Load object address. | ||
4175 | print_cil_load_address(fp, exp, function_scope); | ||
4176 | |||
4177 | // Load field. | ||
4178 | fprintf(fp, "ldfld "); | ||
4179 | print_cil_accessor(fp, lvalue); | ||
4180 | } | ||
4181 | else | ||
4182 | { | ||
4183 | if (ident->mScopeEntry->mIDType == LIT_VARIABLE) | ||
4184 | { | ||
4185 | // Language semantics require value of assignment to be left on stack. | ||
4186 | // TODO: Optimise away redundant dup/pop pairs. | ||
4187 | fprintf(fp, "dup\n"); | ||
4188 | if(is_parameter(ident, function_scope)) | ||
4189 | { | ||
4190 | // Parameter, store by name. | ||
4191 | fprintf(fp, "starg.s %s\n", ident->mScopeEntry->mIdentifier); | ||
4192 | } | ||
4193 | else | ||
4194 | { | ||
4195 | // Local, store by index. | ||
4196 | fprintf(fp, "stloc.s %d\n", ident->mScopeEntry->mCount); | ||
4197 | } | ||
4198 | } | ||
4199 | else if (ident->mScopeEntry->mIDType == LIT_GLOBAL) | ||
4200 | { | ||
4201 | // Object address loaded, store in to field. | ||
4202 | fprintf(fp, "stfld "); | ||
4203 | print_cil_member(fp, ident); | ||
4204 | |||
4205 | // Load object address. | ||
4206 | print_cil_load_address(fp, exp, function_scope); | ||
4207 | |||
4208 | // Load field. | ||
4209 | fprintf(fp, "ldfld "); | ||
4210 | print_cil_member(fp, ident); | ||
4211 | } | ||
4212 | } | ||
4213 | } | ||
4214 | |||
4215 | void print_cast(FILE *fp, LSCRIPTType ret_type, LSCRIPTType right_type) | ||
4216 | { | ||
4217 | if (right_type != ret_type) | ||
4218 | { | ||
4219 | fprintf(fp, "CAST %s->%s\n", LSCRIPTTypeNames[right_type], LSCRIPTTypeNames[ret_type]); | ||
4220 | } | ||
4221 | } | ||
4222 | |||
4223 | void cast2stack(LLScriptByteCodeChunk *chunk, LSCRIPTType ret_type, LSCRIPTType right_type) | ||
4224 | { | ||
4225 | if (right_type != ret_type) | ||
4226 | { | ||
4227 | chunk->addByte(LSCRIPTOpCodes[LOPC_CAST]); | ||
4228 | U8 castbyte = LSCRIPTTypeByte[right_type] | LSCRIPTTypeHi4Bits[ret_type]; | ||
4229 | chunk->addByte(castbyte); | ||
4230 | } | ||
4231 | } | ||
4232 | |||
4233 | void operation2stack(LLScriptByteCodeChunk *chunk, LSCRIPTType ret_type, LSCRIPTType right_type) | ||
4234 | { | ||
4235 | U8 typebyte = LSCRIPTTypeByte[right_type] | LSCRIPTTypeHi4Bits[ret_type]; | ||
4236 | chunk->addByte(typebyte); | ||
4237 | } | ||
4238 | |||
4239 | void store2stack(LLScriptExpression *exp, LLScriptExpression *lv, LLScriptByteCodeChunk *chunk, LSCRIPTType right_type) | ||
4240 | { | ||
4241 | LLScriptLValue *lvalue = (LLScriptLValue *)lv; | ||
4242 | LLScriptIdentifier *ident = lvalue->mIdentifier; | ||
4243 | LSCRIPTType rettype = exp->mReturnType; | ||
4244 | |||
4245 | if (exp->mRightType != LST_NULL) | ||
4246 | { | ||
4247 | if (legal_binary_expression(rettype, exp->mLeftType, exp->mRightType, exp->mType)) | ||
4248 | cast2stack(chunk, right_type, exp->mReturnType); | ||
4249 | } | ||
4250 | switch(exp->mReturnType) | ||
4251 | { | ||
4252 | case LST_INTEGER: | ||
4253 | case LST_FLOATINGPOINT: | ||
4254 | if (ident->mScopeEntry->mIDType == LIT_VARIABLE) | ||
4255 | { | ||
4256 | chunk->addByte(LSCRIPTOpCodes[LOPC_STORE]); | ||
4257 | } | ||
4258 | else | ||
4259 | { | ||
4260 | chunk->addByte(LSCRIPTOpCodes[LOPC_STOREG]); | ||
4261 | } | ||
4262 | break; | ||
4263 | case LST_KEY: | ||
4264 | case LST_STRING: | ||
4265 | if (ident->mScopeEntry->mIDType == LIT_VARIABLE) | ||
4266 | { | ||
4267 | chunk->addByte(LSCRIPTOpCodes[LOPC_STORES]); | ||
4268 | } | ||
4269 | else | ||
4270 | { | ||
4271 | chunk->addByte(LSCRIPTOpCodes[LOPC_STOREGS]); | ||
4272 | } | ||
4273 | break; | ||
4274 | case LST_LIST: | ||
4275 | if (ident->mScopeEntry->mIDType == LIT_VARIABLE) | ||
4276 | { | ||
4277 | chunk->addByte(LSCRIPTOpCodes[LOPC_STOREL]); | ||
4278 | } | ||
4279 | else | ||
4280 | { | ||
4281 | chunk->addByte(LSCRIPTOpCodes[LOPC_STOREGL]); | ||
4282 | } | ||
4283 | break; | ||
4284 | case LST_VECTOR: | ||
4285 | if (ident->mScopeEntry->mIDType == LIT_VARIABLE) | ||
4286 | { | ||
4287 | chunk->addByte(LSCRIPTOpCodes[LOPC_STOREV]); | ||
4288 | } | ||
4289 | else | ||
4290 | { | ||
4291 | chunk->addByte(LSCRIPTOpCodes[LOPC_STOREGV]); | ||
4292 | } | ||
4293 | break; | ||
4294 | case LST_QUATERNION: | ||
4295 | if (ident->mScopeEntry->mIDType == LIT_VARIABLE) | ||
4296 | { | ||
4297 | chunk->addByte(LSCRIPTOpCodes[LOPC_STOREQ]); | ||
4298 | } | ||
4299 | else | ||
4300 | { | ||
4301 | chunk->addByte(LSCRIPTOpCodes[LOPC_STOREGQ]); | ||
4302 | } | ||
4303 | break; | ||
4304 | default: | ||
4305 | if (ident->mScopeEntry->mIDType == LIT_VARIABLE) | ||
4306 | { | ||
4307 | chunk->addByte(LSCRIPTOpCodes[LOPC_STORE]); | ||
4308 | } | ||
4309 | else | ||
4310 | { | ||
4311 | chunk->addByte(LSCRIPTOpCodes[LOPC_STOREG]); | ||
4312 | } | ||
4313 | break; | ||
4314 | } | ||
4315 | S32 address = ident->mScopeEntry->mOffset + lvalue->mOffset; | ||
4316 | chunk->addInteger(address); | ||
4317 | } | ||
4318 | |||
4319 | void print_cil_numeric_cast(FILE* fp, LSCRIPTType currentArg, LSCRIPTType otherArg) | ||
4320 | { | ||
4321 | if((currentArg == LST_INTEGER) && (otherArg == LST_FLOATINGPOINT)) | ||
4322 | { | ||
4323 | print_cil_cast(fp, LST_INTEGER, LST_FLOATINGPOINT); | ||
4324 | } | ||
4325 | } | ||
4326 | |||
4327 | void LLScriptAssignment::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
4328 | { | ||
4329 | if (gErrorToText.getErrors()) | ||
4330 | { | ||
4331 | return; | ||
4332 | } | ||
4333 | switch(pass) | ||
4334 | { | ||
4335 | case LSCP_PRETTY_PRINT: | ||
4336 | mLValue->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4337 | fprintf(fp, " = "); | ||
4338 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4339 | break; | ||
4340 | case LSCP_EMIT_ASSEMBLY: | ||
4341 | { | ||
4342 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4343 | print_cast(fp, mReturnType, mRightType); | ||
4344 | print_asignment(fp, mLValue); | ||
4345 | } | ||
4346 | break; | ||
4347 | case LSCP_TYPE: | ||
4348 | { | ||
4349 | mLValue->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4350 | mLeftType = type; | ||
4351 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4352 | mRightType = type; | ||
4353 | if (!legal_assignment(mLeftType, mRightType)) | ||
4354 | { | ||
4355 | gErrorToText.writeError(fp, this, LSERROR_TYPE_MISMATCH); | ||
4356 | } | ||
4357 | type = mReturnType = mLeftType; | ||
4358 | } | ||
4359 | break; | ||
4360 | case LSCP_TO_STACK: | ||
4361 | { | ||
4362 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4363 | store2stack(this, mLValue, chunk, mRightType); | ||
4364 | } | ||
4365 | break; | ||
4366 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
4367 | { | ||
4368 | print_cil_load_address(fp, mLValue, entry); | ||
4369 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4370 | print_cil_numeric_cast(fp, mRightType, mReturnType); | ||
4371 | print_cil_asignment(fp, mLValue, entry); | ||
4372 | } | ||
4373 | break; | ||
4374 | default: | ||
4375 | mLValue->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4376 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4377 | break; | ||
4378 | } | ||
4379 | gonext(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4380 | } | ||
4381 | |||
4382 | S32 LLScriptAssignment::getSize() | ||
4383 | { | ||
4384 | return 0; | ||
4385 | } | ||
4386 | |||
4387 | void print_cil_add(FILE* fp, LSCRIPTType left_type, LSCRIPTType right_type) | ||
4388 | { | ||
4389 | switch(left_type) | ||
4390 | { | ||
4391 | case LST_INTEGER: | ||
4392 | case LST_FLOATINGPOINT: | ||
4393 | |||
4394 | // Numeric addition. | ||
4395 | fprintf(fp, "add\n"); | ||
4396 | break; | ||
4397 | |||
4398 | case LST_STRING: | ||
4399 | case LST_KEY: | ||
4400 | |||
4401 | // String concatenation. | ||
4402 | fprintf(fp, "call string valuetype [mscorlib]System.String::Concat(string, string)"); | ||
4403 | break; | ||
4404 | |||
4405 | case LST_VECTOR: | ||
4406 | |||
4407 | // Vector addition. | ||
4408 | // TODO: Inline (requires temporary variables, which must be identified in earlier pass). | ||
4409 | fprintf(fp, "call valuetype [LScriptLibrary]LLVector valuetype [LScriptLibrary]LLVector::'add_vec'(valuetype [LScriptLibrary]LLVector, valuetype [LScriptLibrary]LLVector)\n"); | ||
4410 | break; | ||
4411 | |||
4412 | case LST_QUATERNION: | ||
4413 | |||
4414 | // Rotation addition. | ||
4415 | // TODO: Inline (requires temporary variables, which must be identified in earlier pass). | ||
4416 | fprintf(fp, "call valuetype [LScriptLibrary]LLQuaternion valuetype [LScriptLibrary]LLQuaternion::'add_quat'(valuetype [LScriptLibrary]LLQuaternion, valuetype [LScriptLibrary]LLQuaternion)\n"); | ||
4417 | break; | ||
4418 | |||
4419 | case LST_LIST: | ||
4420 | print_cil_box(fp, right_type); | ||
4421 | fprintf(fp, "call class [mscorlib]System.Collections.ArrayList class [LScriptLibrary]LScriptInternal::AddReturnList(class [mscorlib]System.Collections.ArrayList, object)\n"); | ||
4422 | break; | ||
4423 | |||
4424 | default: | ||
4425 | break; | ||
4426 | } | ||
4427 | } | ||
4428 | |||
4429 | void LLScriptAddAssignment::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
4430 | { | ||
4431 | if (gErrorToText.getErrors()) | ||
4432 | { | ||
4433 | return; | ||
4434 | } | ||
4435 | switch(pass) | ||
4436 | { | ||
4437 | case LSCP_PRETTY_PRINT: | ||
4438 | mLValue->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4439 | fprintf(fp, " += "); | ||
4440 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4441 | break; | ||
4442 | case LSCP_EMIT_ASSEMBLY: | ||
4443 | { | ||
4444 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4445 | mLValue->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4446 | fprintf(fp, "ADD %s, %s\n", LSCRIPTTypeNames[mRightType], LSCRIPTTypeNames[mLeftType]); | ||
4447 | print_asignment(fp, mLValue); | ||
4448 | } | ||
4449 | break; | ||
4450 | case LSCP_TYPE: | ||
4451 | { | ||
4452 | mLValue->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4453 | mLeftType = type; | ||
4454 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4455 | mRightType = type; | ||
4456 | if (!legal_binary_expression(mReturnType, mLeftType, mRightType, mType)) | ||
4457 | { | ||
4458 | gErrorToText.writeError(fp, this, LSERROR_TYPE_MISMATCH); | ||
4459 | } | ||
4460 | type = mReturnType; | ||
4461 | } | ||
4462 | break; | ||
4463 | case LSCP_TO_STACK: | ||
4464 | { | ||
4465 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4466 | mLValue->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4467 | chunk->addByte(LSCRIPTOpCodes[LOPC_ADD]); | ||
4468 | operation2stack(chunk, mReturnType, mRightType); | ||
4469 | store2stack(this, mLValue, chunk, mReturnType); | ||
4470 | } | ||
4471 | break; | ||
4472 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
4473 | { | ||
4474 | print_cil_load_address(fp, mLValue, entry); | ||
4475 | mLValue->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4476 | print_cil_numeric_cast(fp, mLValue->mReturnType, mRightSide->mReturnType); | ||
4477 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4478 | print_cil_numeric_cast(fp, mRightSide->mReturnType, mLValue->mReturnType); | ||
4479 | print_cil_add(fp, mLValue->mReturnType, mRightSide->mReturnType); | ||
4480 | print_cil_asignment(fp, mLValue, entry); | ||
4481 | } | ||
4482 | break; | ||
4483 | default: | ||
4484 | mLValue->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4485 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4486 | break; | ||
4487 | } | ||
4488 | gonext(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4489 | } | ||
4490 | |||
4491 | S32 LLScriptAddAssignment::getSize() | ||
4492 | { | ||
4493 | return 0; | ||
4494 | } | ||
4495 | |||
4496 | void print_cil_sub(FILE* fp, LSCRIPTType left_type, LSCRIPTType right_type) | ||
4497 | { | ||
4498 | switch(left_type) | ||
4499 | { | ||
4500 | case LST_INTEGER: | ||
4501 | case LST_FLOATINGPOINT: | ||
4502 | |||
4503 | // Numeric subtraction. | ||
4504 | fprintf(fp, "sub\n"); | ||
4505 | break; | ||
4506 | |||
4507 | case LST_VECTOR: | ||
4508 | |||
4509 | // Vector subtraction. | ||
4510 | // TODO: Inline (requires temporary variables, which must be identified in earlier pass). | ||
4511 | fprintf(fp, "call valuetype [LScriptLibrary]LLVector valuetype [LScriptLibrary]LLVector::'subtract_vec'(valuetype [LScriptLibrary]LLVector, valuetype [LScriptLibrary]LLVector)\n"); | ||
4512 | break; | ||
4513 | |||
4514 | case LST_QUATERNION: | ||
4515 | |||
4516 | // Rotation subtraction. | ||
4517 | // TODO: Inline (requires temporary variables, which must be identified in earlier pass). | ||
4518 | fprintf(fp, "call valuetype [LScriptLibrary]LLQuaternion valuetype [LScriptLibrary]LLQuaternion::'subtract_quat'(valuetype [LScriptLibrary]LLQuaternion, valuetype [LScriptLibrary]LLQuaternion)\n"); | ||
4519 | break; | ||
4520 | |||
4521 | default: | ||
4522 | |||
4523 | // Error. | ||
4524 | break; | ||
4525 | } | ||
4526 | } | ||
4527 | |||
4528 | void LLScriptSubAssignment::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
4529 | { | ||
4530 | if (gErrorToText.getErrors()) | ||
4531 | { | ||
4532 | return; | ||
4533 | } | ||
4534 | switch(pass) | ||
4535 | { | ||
4536 | case LSCP_PRETTY_PRINT: | ||
4537 | mLValue->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4538 | fprintf(fp, " -= "); | ||
4539 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4540 | break; | ||
4541 | case LSCP_EMIT_ASSEMBLY: | ||
4542 | { | ||
4543 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4544 | mLValue->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4545 | fprintf(fp, "SUB %s, %s\n", LSCRIPTTypeNames[mRightType], LSCRIPTTypeNames[mLeftType]); | ||
4546 | print_asignment(fp, mLValue); | ||
4547 | } | ||
4548 | break; | ||
4549 | case LSCP_TYPE: | ||
4550 | { | ||
4551 | mLValue->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4552 | mLeftType = type; | ||
4553 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4554 | mRightType = type; | ||
4555 | if (!legal_binary_expression(mReturnType, mLeftType, mRightType, mType)) | ||
4556 | { | ||
4557 | gErrorToText.writeError(fp, this, LSERROR_TYPE_MISMATCH); | ||
4558 | } | ||
4559 | type = mReturnType; | ||
4560 | } | ||
4561 | break; | ||
4562 | case LSCP_TO_STACK: | ||
4563 | { | ||
4564 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4565 | mLValue->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4566 | chunk->addByte(LSCRIPTOpCodes[LOPC_SUB]); | ||
4567 | operation2stack(chunk, mReturnType, mRightType); | ||
4568 | store2stack(this, mLValue, chunk, mReturnType); | ||
4569 | } | ||
4570 | break; | ||
4571 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
4572 | { | ||
4573 | print_cil_load_address(fp, mLValue, entry); | ||
4574 | mLValue->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4575 | print_cil_numeric_cast(fp, mLValue->mReturnType, mRightSide->mReturnType); | ||
4576 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4577 | print_cil_numeric_cast(fp, mRightSide->mReturnType, mLValue->mReturnType); | ||
4578 | print_cil_sub(fp, mLValue->mReturnType, mRightSide->mReturnType); | ||
4579 | print_cil_asignment(fp, mLValue, entry); | ||
4580 | } | ||
4581 | break; | ||
4582 | default: | ||
4583 | mLValue->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4584 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4585 | break; | ||
4586 | } | ||
4587 | gonext(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4588 | } | ||
4589 | |||
4590 | S32 LLScriptSubAssignment::getSize() | ||
4591 | { | ||
4592 | return 0; | ||
4593 | } | ||
4594 | |||
4595 | void print_cil_mul(FILE* fp, LSCRIPTType left_type, LSCRIPTType right_type) | ||
4596 | { | ||
4597 | switch(left_type) | ||
4598 | { | ||
4599 | case LST_INTEGER: | ||
4600 | case LST_FLOATINGPOINT: | ||
4601 | |||
4602 | // Numeric multiplication. | ||
4603 | fprintf(fp, "mul\n"); | ||
4604 | break; | ||
4605 | |||
4606 | case LST_VECTOR: | ||
4607 | |||
4608 | switch(right_type) | ||
4609 | { | ||
4610 | case LST_INTEGER: | ||
4611 | |||
4612 | print_cil_cast(fp, LST_INTEGER, LST_FLOATINGPOINT); | ||
4613 | |||
4614 | case LST_FLOATINGPOINT: | ||
4615 | |||
4616 | // Vector scaling. | ||
4617 | fprintf(fp, "call valuetype [LScriptLibrary]LLVector valuetype [LScriptLibrary]LLVector::'multiply_float'(valuetype [LScriptLibrary]LLVector, float32)\n"); | ||
4618 | break; | ||
4619 | |||
4620 | case LST_VECTOR: | ||
4621 | |||
4622 | // Dot product. | ||
4623 | fprintf(fp, "call float32 valuetype [LScriptLibrary]LLVector::'multiply_vec'(valuetype [LScriptLibrary]LLVector, valuetype [LScriptLibrary]LLVector)\n"); | ||
4624 | break; | ||
4625 | |||
4626 | case LST_QUATERNION: | ||
4627 | |||
4628 | // Vector rotation. | ||
4629 | fprintf(fp, "call valuetype [LScriptLibrary]LLVector valuetype [LScriptLibrary]LLVector::'multiply_quat'(valuetype [LScriptLibrary]LLVector, valuetype [LScriptLibrary]LLQuaternion)\n"); | ||
4630 | break; | ||
4631 | |||
4632 | default: | ||
4633 | break; | ||
4634 | } | ||
4635 | break; | ||
4636 | |||
4637 | case LST_QUATERNION: | ||
4638 | |||
4639 | // Rotation multiplication. | ||
4640 | fprintf(fp, "call valuetype [LScriptLibrary]LLQuaternion valuetype [LScriptLibrary]LLQuaternion::'multiply_quat'(valuetype [LScriptLibrary]LLQuaternion, valuetype [LScriptLibrary]LLQuaternion)\n"); | ||
4641 | break; | ||
4642 | |||
4643 | default: | ||
4644 | |||
4645 | // Error. | ||
4646 | break; | ||
4647 | } | ||
4648 | } | ||
4649 | |||
4650 | void LLScriptMulAssignment::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
4651 | { | ||
4652 | if (gErrorToText.getErrors()) | ||
4653 | { | ||
4654 | return; | ||
4655 | } | ||
4656 | switch(pass) | ||
4657 | { | ||
4658 | case LSCP_PRETTY_PRINT: | ||
4659 | mLValue->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4660 | fprintf(fp, " *= "); | ||
4661 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4662 | break; | ||
4663 | case LSCP_EMIT_ASSEMBLY: | ||
4664 | { | ||
4665 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4666 | mLValue->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4667 | fprintf(fp, "MUL %s, %s\n", LSCRIPTTypeNames[mRightType], LSCRIPTTypeNames[mLeftType]); | ||
4668 | print_asignment(fp, mLValue); | ||
4669 | } | ||
4670 | break; | ||
4671 | case LSCP_TYPE: | ||
4672 | { | ||
4673 | mLValue->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4674 | mLeftType = type; | ||
4675 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4676 | mRightType = type; | ||
4677 | if (!legal_binary_expression(mReturnType, mLeftType, mRightType, mType)) | ||
4678 | { | ||
4679 | gErrorToText.writeError(fp, this, LSERROR_TYPE_MISMATCH); | ||
4680 | } | ||
4681 | type = mReturnType; | ||
4682 | } | ||
4683 | break; | ||
4684 | case LSCP_TO_STACK: | ||
4685 | { | ||
4686 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4687 | mLValue->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4688 | chunk->addByte(LSCRIPTOpCodes[LOPC_MUL]); | ||
4689 | operation2stack(chunk, mReturnType, mRightType); | ||
4690 | store2stack(this, mLValue, chunk, mReturnType); | ||
4691 | } | ||
4692 | break; | ||
4693 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
4694 | { | ||
4695 | print_cil_load_address(fp, mLValue, entry); | ||
4696 | mLValue->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4697 | print_cil_numeric_cast(fp, mLValue->mReturnType, mRightSide->mReturnType); | ||
4698 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4699 | print_cil_numeric_cast(fp, mRightSide->mReturnType, mLValue->mReturnType); | ||
4700 | print_cil_mul(fp, mLValue->mReturnType, mRightSide->mReturnType); | ||
4701 | print_cil_asignment(fp, mLValue, entry); | ||
4702 | } | ||
4703 | break; | ||
4704 | default: | ||
4705 | mLValue->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4706 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4707 | break; | ||
4708 | } | ||
4709 | gonext(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4710 | } | ||
4711 | |||
4712 | S32 LLScriptMulAssignment::getSize() | ||
4713 | { | ||
4714 | return 0; | ||
4715 | } | ||
4716 | |||
4717 | void print_cil_div(FILE* fp, LSCRIPTType left_type, LSCRIPTType right_type) | ||
4718 | { | ||
4719 | switch(left_type) | ||
4720 | { | ||
4721 | case LST_INTEGER: | ||
4722 | case LST_FLOATINGPOINT: | ||
4723 | |||
4724 | // Numeric addition. | ||
4725 | fprintf(fp, "div\n"); | ||
4726 | break; | ||
4727 | |||
4728 | case LST_VECTOR: | ||
4729 | |||
4730 | switch(right_type) | ||
4731 | { | ||
4732 | case LST_INTEGER: | ||
4733 | |||
4734 | print_cil_cast(fp, LST_INTEGER, LST_FLOATINGPOINT); | ||
4735 | |||
4736 | case LST_FLOATINGPOINT: | ||
4737 | |||
4738 | // Scale. | ||
4739 | fprintf(fp, "call valuetype [LScriptLibrary]LLVector valuetype [LScriptLibrary]LLVector::'divide_float'(valuetype [LScriptLibrary]LLVector, float32)\n"); | ||
4740 | break; | ||
4741 | |||
4742 | case LST_QUATERNION: | ||
4743 | |||
4744 | // Inverse rotation. | ||
4745 | fprintf(fp, "call valuetype [LScriptLibrary]LLVector valuetype [LScriptLibrary]LLVector::'divide_quat'(valuetype [LScriptLibrary]LLVector, valuetype [LScriptLibrary]LLQuaternion)\n"); | ||
4746 | break; | ||
4747 | |||
4748 | default: | ||
4749 | break; | ||
4750 | } | ||
4751 | break; | ||
4752 | |||
4753 | case LST_QUATERNION: | ||
4754 | |||
4755 | fprintf(fp, "call valuetype [LScriptLibrary]LLQuaternion valuetype [LScriptLibrary]LLQuaternion::'divide_quat'(valuetype [LScriptLibrary]LLQuaternion, valuetype [LScriptLibrary]LLQuaternion)\n"); | ||
4756 | break; | ||
4757 | |||
4758 | default: | ||
4759 | |||
4760 | // Error. | ||
4761 | break; | ||
4762 | } | ||
4763 | } | ||
4764 | |||
4765 | void LLScriptDivAssignment::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
4766 | { | ||
4767 | if (gErrorToText.getErrors()) | ||
4768 | { | ||
4769 | return; | ||
4770 | } | ||
4771 | switch(pass) | ||
4772 | { | ||
4773 | case LSCP_PRETTY_PRINT: | ||
4774 | mLValue->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4775 | fprintf(fp, " /= "); | ||
4776 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4777 | break; | ||
4778 | case LSCP_EMIT_ASSEMBLY: | ||
4779 | { | ||
4780 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4781 | mLValue->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4782 | fprintf(fp, "DIV %s, %s\n", LSCRIPTTypeNames[mRightType], LSCRIPTTypeNames[mLeftType]); | ||
4783 | print_asignment(fp, mLValue); | ||
4784 | } | ||
4785 | break; | ||
4786 | case LSCP_TYPE: | ||
4787 | { | ||
4788 | mLValue->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4789 | mLeftType = type; | ||
4790 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4791 | mRightType = type; | ||
4792 | if (!legal_binary_expression(mReturnType, mLeftType, mRightType, mType)) | ||
4793 | { | ||
4794 | gErrorToText.writeError(fp, this, LSERROR_TYPE_MISMATCH); | ||
4795 | } | ||
4796 | type = mReturnType; | ||
4797 | } | ||
4798 | break; | ||
4799 | case LSCP_TO_STACK: | ||
4800 | { | ||
4801 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4802 | mLValue->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4803 | chunk->addByte(LSCRIPTOpCodes[LOPC_DIV]); | ||
4804 | operation2stack(chunk, mReturnType, mRightType); | ||
4805 | store2stack(this, mLValue, chunk, mReturnType); | ||
4806 | } | ||
4807 | break; | ||
4808 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
4809 | { | ||
4810 | print_cil_load_address(fp, mLValue, entry); | ||
4811 | mLValue->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4812 | print_cil_numeric_cast(fp, mLValue->mReturnType, mRightSide->mReturnType); | ||
4813 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4814 | print_cil_numeric_cast(fp, mRightSide->mReturnType, mLValue->mReturnType); | ||
4815 | print_cil_div(fp, mLValue->mReturnType, mRightSide->mReturnType); | ||
4816 | print_cil_asignment(fp, mLValue, entry); | ||
4817 | } | ||
4818 | break; | ||
4819 | default: | ||
4820 | mLValue->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4821 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4822 | break; | ||
4823 | } | ||
4824 | gonext(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4825 | } | ||
4826 | |||
4827 | S32 LLScriptDivAssignment::getSize() | ||
4828 | { | ||
4829 | return 0; | ||
4830 | } | ||
4831 | |||
4832 | void print_cil_mod(FILE* fp, LSCRIPTType left_type, LSCRIPTType right_type) | ||
4833 | { | ||
4834 | switch(left_type) | ||
4835 | { | ||
4836 | case LST_INTEGER: | ||
4837 | |||
4838 | // Numeric remainder. | ||
4839 | fprintf(fp, "rem\n"); | ||
4840 | break; | ||
4841 | |||
4842 | case LST_VECTOR: | ||
4843 | |||
4844 | // Vector cross product. | ||
4845 | fprintf(fp, "call valuetype [LScriptLibrary]LLVector valuetype [LScriptLibrary]LLVector::'mod_vec'(valuetype [LScriptLibrary]LLVector, valuetype [LScriptLibrary]LLVector)\n"); | ||
4846 | break; | ||
4847 | |||
4848 | default: | ||
4849 | |||
4850 | // Error. | ||
4851 | break; | ||
4852 | } | ||
4853 | } | ||
4854 | |||
4855 | void LLScriptModAssignment::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
4856 | { | ||
4857 | if (gErrorToText.getErrors()) | ||
4858 | { | ||
4859 | return; | ||
4860 | } | ||
4861 | switch(pass) | ||
4862 | { | ||
4863 | case LSCP_PRETTY_PRINT: | ||
4864 | mLValue->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4865 | fprintf(fp, " %%= "); | ||
4866 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4867 | break; | ||
4868 | case LSCP_EMIT_ASSEMBLY: | ||
4869 | { | ||
4870 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4871 | mLValue->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4872 | fprintf(fp, "MOD %s, %s\n", LSCRIPTTypeNames[mRightType], LSCRIPTTypeNames[mLeftType]); | ||
4873 | print_asignment(fp, mLValue); | ||
4874 | } | ||
4875 | break; | ||
4876 | case LSCP_TYPE: | ||
4877 | { | ||
4878 | mLValue->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4879 | mLeftType = type; | ||
4880 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4881 | mRightType = type; | ||
4882 | if (!legal_binary_expression(mReturnType, mLeftType, mRightType, mType)) | ||
4883 | { | ||
4884 | gErrorToText.writeError(fp, this, LSERROR_TYPE_MISMATCH); | ||
4885 | } | ||
4886 | type = mReturnType; | ||
4887 | } | ||
4888 | break; | ||
4889 | case LSCP_TO_STACK: | ||
4890 | { | ||
4891 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4892 | mLValue->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4893 | chunk->addByte(LSCRIPTOpCodes[LOPC_MOD]); | ||
4894 | operation2stack(chunk, mReturnType, mRightType); | ||
4895 | store2stack(this, mLValue, chunk, mReturnType); | ||
4896 | } | ||
4897 | break; | ||
4898 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
4899 | { | ||
4900 | print_cil_load_address(fp, mLValue, entry); | ||
4901 | mLValue->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4902 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4903 | print_cil_mod(fp, mLValue->mReturnType, mRightSide->mReturnType); | ||
4904 | print_cil_asignment(fp, mLValue, entry); | ||
4905 | } | ||
4906 | break; | ||
4907 | default: | ||
4908 | mLValue->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4909 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4910 | break; | ||
4911 | } | ||
4912 | gonext(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4913 | } | ||
4914 | |||
4915 | S32 LLScriptModAssignment::getSize() | ||
4916 | { | ||
4917 | return 0; | ||
4918 | } | ||
4919 | |||
4920 | void print_cil_eq(FILE* fp, LSCRIPTType left_type, LSCRIPTType right_type) | ||
4921 | { | ||
4922 | switch(left_type) | ||
4923 | { | ||
4924 | case LST_INTEGER: | ||
4925 | case LST_FLOATINGPOINT: | ||
4926 | |||
4927 | // Numeric equality. | ||
4928 | fprintf(fp, "ceq\n"); | ||
4929 | break; | ||
4930 | |||
4931 | case LST_STRING: | ||
4932 | case LST_KEY: | ||
4933 | |||
4934 | // String equality. | ||
4935 | fprintf(fp, "call bool valuetype [mscorlib]System.String::op_Equality(string, string)\n"); | ||
4936 | break; | ||
4937 | |||
4938 | case LST_VECTOR: | ||
4939 | |||
4940 | // Vector equality. | ||
4941 | fprintf(fp, "call bool [LScriptLibrary]LLVector::'equals_vec'(valuetype [LScriptLibrary]LLVector, valuetype [LScriptLibrary]LLVector)\n"); | ||
4942 | break; | ||
4943 | |||
4944 | case LST_QUATERNION: | ||
4945 | |||
4946 | // Rotation equality. | ||
4947 | fprintf(fp, "call bool [LScriptLibrary]LLQuaternion::'equals_quat'(valuetype [LScriptLibrary]LLQuaternion, valuetype [LScriptLibrary]LLQuaternion)\n"); | ||
4948 | break; | ||
4949 | |||
4950 | case LST_LIST: | ||
4951 | fprintf(fp, "call bool [LScriptLibrary]LScriptInternal::EqualsList(class [mscorlib]System.Collections.ArrayList, class [mscorlib]System.Collections.ArrayList)\n"); | ||
4952 | break; | ||
4953 | |||
4954 | default: | ||
4955 | |||
4956 | // Error. | ||
4957 | break; | ||
4958 | } | ||
4959 | } | ||
4960 | |||
4961 | void LLScriptEquality::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
4962 | { | ||
4963 | if (gErrorToText.getErrors()) | ||
4964 | { | ||
4965 | return; | ||
4966 | } | ||
4967 | switch(pass) | ||
4968 | { | ||
4969 | case LSCP_PRETTY_PRINT: | ||
4970 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4971 | fprintf(fp, " == "); | ||
4972 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4973 | break; | ||
4974 | case LSCP_EMIT_ASSEMBLY: | ||
4975 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4976 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4977 | fprintf(fp, "EQ %s, %s\n", LSCRIPTTypeNames[mRightType], LSCRIPTTypeNames[mLeftType]); | ||
4978 | break; | ||
4979 | case LSCP_TYPE: | ||
4980 | { | ||
4981 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4982 | mLeftType = type; | ||
4983 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4984 | mRightType = type; | ||
4985 | if (!legal_binary_expression(mReturnType, mLeftType, mRightType, mType)) | ||
4986 | { | ||
4987 | gErrorToText.writeError(fp, this, LSERROR_TYPE_MISMATCH); | ||
4988 | } | ||
4989 | type = mReturnType; | ||
4990 | } | ||
4991 | break; | ||
4992 | case LSCP_TO_STACK: | ||
4993 | { | ||
4994 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4995 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
4996 | U8 typebyte = LSCRIPTTypeByte[mRightType] | LSCRIPTTypeHi4Bits[mLeftType]; | ||
4997 | chunk->addByte(LSCRIPTOpCodes[LOPC_EQ]); | ||
4998 | chunk->addByte(typebyte); | ||
4999 | } | ||
5000 | break; | ||
5001 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
5002 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5003 | print_cil_numeric_cast(fp, mLeftSide->mReturnType, mRightSide->mReturnType); | ||
5004 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5005 | print_cil_numeric_cast(fp, mRightSide->mReturnType, mLeftSide->mReturnType); | ||
5006 | print_cil_eq(fp, mLeftSide->mReturnType, mRightSide->mReturnType); | ||
5007 | break; | ||
5008 | default: | ||
5009 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5010 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5011 | break; | ||
5012 | } | ||
5013 | gonext(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5014 | } | ||
5015 | |||
5016 | S32 LLScriptEquality::getSize() | ||
5017 | { | ||
5018 | return 0; | ||
5019 | } | ||
5020 | |||
5021 | void LLScriptNotEquals::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
5022 | { | ||
5023 | if (gErrorToText.getErrors()) | ||
5024 | { | ||
5025 | return; | ||
5026 | } | ||
5027 | switch(pass) | ||
5028 | { | ||
5029 | case LSCP_PRETTY_PRINT: | ||
5030 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5031 | fprintf(fp, " != "); | ||
5032 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5033 | break; | ||
5034 | case LSCP_EMIT_ASSEMBLY: | ||
5035 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5036 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5037 | fprintf(fp, "NEQ %s, %s\n", LSCRIPTTypeNames[mRightType], LSCRIPTTypeNames[mLeftType]); | ||
5038 | break; | ||
5039 | case LSCP_TYPE: | ||
5040 | { | ||
5041 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5042 | mLeftType = type; | ||
5043 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5044 | mRightType = type; | ||
5045 | if (!legal_binary_expression(mReturnType, mLeftType, mRightType, mType)) | ||
5046 | { | ||
5047 | gErrorToText.writeError(fp, this, LSERROR_TYPE_MISMATCH); | ||
5048 | } | ||
5049 | type = mReturnType; | ||
5050 | } | ||
5051 | break; | ||
5052 | case LSCP_TO_STACK: | ||
5053 | { | ||
5054 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5055 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5056 | U8 typebyte = LSCRIPTTypeByte[mRightType] | LSCRIPTTypeHi4Bits[mLeftType]; | ||
5057 | chunk->addByte(LSCRIPTOpCodes[LOPC_NEQ]); | ||
5058 | chunk->addByte(typebyte); | ||
5059 | } | ||
5060 | break; | ||
5061 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
5062 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5063 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5064 | fprintf(fp, "ceq\n"); | ||
5065 | fprintf(fp, "ldc.i4.0\n"); | ||
5066 | fprintf(fp, "ceq\n"); // Compare result of first compare equal with 0 to get compare not equal. | ||
5067 | break; | ||
5068 | default: | ||
5069 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5070 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5071 | break; | ||
5072 | } | ||
5073 | gonext(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5074 | } | ||
5075 | |||
5076 | S32 LLScriptNotEquals::getSize() | ||
5077 | { | ||
5078 | return 0; | ||
5079 | } | ||
5080 | |||
5081 | void LLScriptLessEquals::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
5082 | { | ||
5083 | if (gErrorToText.getErrors()) | ||
5084 | { | ||
5085 | return; | ||
5086 | } | ||
5087 | switch(pass) | ||
5088 | { | ||
5089 | case LSCP_PRETTY_PRINT: | ||
5090 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5091 | fprintf(fp, " <= "); | ||
5092 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5093 | break; | ||
5094 | case LSCP_EMIT_ASSEMBLY: | ||
5095 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5096 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5097 | fprintf(fp, "LEQ %s, %s\n", LSCRIPTTypeNames[mRightType], LSCRIPTTypeNames[mLeftType]); | ||
5098 | break; | ||
5099 | case LSCP_TYPE: | ||
5100 | { | ||
5101 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5102 | mLeftType = type; | ||
5103 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5104 | mRightType = type; | ||
5105 | if (!legal_binary_expression(mReturnType, mLeftType, mRightType, mType)) | ||
5106 | { | ||
5107 | gErrorToText.writeError(fp, this, LSERROR_TYPE_MISMATCH); | ||
5108 | } | ||
5109 | type = mReturnType; | ||
5110 | } | ||
5111 | break; | ||
5112 | case LSCP_TO_STACK: | ||
5113 | { | ||
5114 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5115 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5116 | U8 typebyte = LSCRIPTTypeByte[mRightType] | LSCRIPTTypeHi4Bits[mLeftType]; | ||
5117 | chunk->addByte(LSCRIPTOpCodes[LOPC_LEQ]); | ||
5118 | chunk->addByte(typebyte); | ||
5119 | } | ||
5120 | break; | ||
5121 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
5122 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5123 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5124 | fprintf(fp, "cgt\n"); // Test greater than. | ||
5125 | fprintf(fp, "ldc.i4.0\n"); // Use (b == 0) implementation of boolean not. | ||
5126 | fprintf(fp, "ceq\n"); // Apply boolean not to greater than. If not greater than, then less or equal. | ||
5127 | break; | ||
5128 | default: | ||
5129 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5130 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5131 | break; | ||
5132 | } | ||
5133 | gonext(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5134 | } | ||
5135 | |||
5136 | S32 LLScriptLessEquals::getSize() | ||
5137 | { | ||
5138 | return 0; | ||
5139 | } | ||
5140 | |||
5141 | void LLScriptGreaterEquals::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
5142 | { | ||
5143 | if (gErrorToText.getErrors()) | ||
5144 | { | ||
5145 | return; | ||
5146 | } | ||
5147 | switch(pass) | ||
5148 | { | ||
5149 | case LSCP_PRETTY_PRINT: | ||
5150 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5151 | fprintf(fp, " >= "); | ||
5152 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5153 | break; | ||
5154 | case LSCP_EMIT_ASSEMBLY: | ||
5155 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5156 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5157 | fprintf(fp, "GEQ %s, %s\n", LSCRIPTTypeNames[mRightType], LSCRIPTTypeNames[mLeftType]); | ||
5158 | break; | ||
5159 | case LSCP_TYPE: | ||
5160 | { | ||
5161 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5162 | mLeftType = type; | ||
5163 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5164 | mRightType = type; | ||
5165 | if (!legal_binary_expression(mReturnType, mLeftType, mRightType, mType)) | ||
5166 | { | ||
5167 | gErrorToText.writeError(fp, this, LSERROR_TYPE_MISMATCH); | ||
5168 | } | ||
5169 | type = mReturnType; | ||
5170 | } | ||
5171 | break; | ||
5172 | case LSCP_TO_STACK: | ||
5173 | { | ||
5174 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5175 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5176 | U8 typebyte = LSCRIPTTypeByte[mRightType] | LSCRIPTTypeHi4Bits[mLeftType]; | ||
5177 | chunk->addByte(LSCRIPTOpCodes[LOPC_GEQ]); | ||
5178 | chunk->addByte(typebyte); | ||
5179 | } | ||
5180 | break; | ||
5181 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
5182 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5183 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5184 | fprintf(fp, "clt\n"); // Test less than. | ||
5185 | fprintf(fp, "ldc.i4.0\n"); // Use (b == 0) implementation of boolean not. | ||
5186 | fprintf(fp, "ceq\n"); // Apply boolean not to less than. If not less than, then greater or equal. | ||
5187 | break; | ||
5188 | default: | ||
5189 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5190 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5191 | break; | ||
5192 | } | ||
5193 | gonext(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5194 | } | ||
5195 | |||
5196 | S32 LLScriptGreaterEquals::getSize() | ||
5197 | { | ||
5198 | return 0; | ||
5199 | } | ||
5200 | |||
5201 | void LLScriptLessThan::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
5202 | { | ||
5203 | if (gErrorToText.getErrors()) | ||
5204 | { | ||
5205 | return; | ||
5206 | } | ||
5207 | switch(pass) | ||
5208 | { | ||
5209 | case LSCP_PRETTY_PRINT: | ||
5210 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5211 | fprintf(fp, " < "); | ||
5212 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5213 | break; | ||
5214 | case LSCP_EMIT_ASSEMBLY: | ||
5215 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5216 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5217 | fprintf(fp, "LESS %s, %s\n", LSCRIPTTypeNames[mRightType], LSCRIPTTypeNames[mLeftType]); | ||
5218 | break; | ||
5219 | case LSCP_TYPE: | ||
5220 | { | ||
5221 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5222 | mLeftType = type; | ||
5223 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5224 | mRightType = type; | ||
5225 | if (!legal_binary_expression(mReturnType, mLeftType, mRightType, mType)) | ||
5226 | { | ||
5227 | gErrorToText.writeError(fp, this, LSERROR_TYPE_MISMATCH); | ||
5228 | } | ||
5229 | type = mReturnType; | ||
5230 | } | ||
5231 | break; | ||
5232 | case LSCP_TO_STACK: | ||
5233 | { | ||
5234 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5235 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5236 | U8 typebyte = LSCRIPTTypeByte[mRightType] | LSCRIPTTypeHi4Bits[mLeftType]; | ||
5237 | chunk->addByte(LSCRIPTOpCodes[LOPC_LESS]); | ||
5238 | chunk->addByte(typebyte); | ||
5239 | } | ||
5240 | break; | ||
5241 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
5242 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5243 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5244 | fprintf(fp, "clt\n"); | ||
5245 | break; | ||
5246 | default: | ||
5247 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5248 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5249 | break; | ||
5250 | } | ||
5251 | gonext(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5252 | } | ||
5253 | |||
5254 | S32 LLScriptLessThan::getSize() | ||
5255 | { | ||
5256 | return 0; | ||
5257 | } | ||
5258 | |||
5259 | void LLScriptGreaterThan::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
5260 | { | ||
5261 | if (gErrorToText.getErrors()) | ||
5262 | { | ||
5263 | return; | ||
5264 | } | ||
5265 | switch(pass) | ||
5266 | { | ||
5267 | case LSCP_PRETTY_PRINT: | ||
5268 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5269 | fprintf(fp, " > "); | ||
5270 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5271 | break; | ||
5272 | case LSCP_EMIT_ASSEMBLY: | ||
5273 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5274 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5275 | fprintf(fp, "GREATER %s, %s\n", LSCRIPTTypeNames[mRightType], LSCRIPTTypeNames[mLeftType]); | ||
5276 | break; | ||
5277 | case LSCP_TYPE: | ||
5278 | { | ||
5279 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5280 | mLeftType = type; | ||
5281 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5282 | mRightType = type; | ||
5283 | if (!legal_binary_expression(mReturnType, mLeftType, mRightType, mType)) | ||
5284 | { | ||
5285 | gErrorToText.writeError(fp, this, LSERROR_TYPE_MISMATCH); | ||
5286 | } | ||
5287 | type = mReturnType; | ||
5288 | } | ||
5289 | break; | ||
5290 | case LSCP_TO_STACK: | ||
5291 | { | ||
5292 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5293 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5294 | U8 typebyte = LSCRIPTTypeByte[mRightType] | LSCRIPTTypeHi4Bits[mLeftType]; | ||
5295 | chunk->addByte(LSCRIPTOpCodes[LOPC_GREATER]); | ||
5296 | chunk->addByte(typebyte); | ||
5297 | } | ||
5298 | break; | ||
5299 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
5300 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5301 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5302 | fprintf(fp, "cgt\n"); | ||
5303 | break; | ||
5304 | default: | ||
5305 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5306 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5307 | break; | ||
5308 | } | ||
5309 | gonext(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5310 | } | ||
5311 | |||
5312 | S32 LLScriptGreaterThan::getSize() | ||
5313 | { | ||
5314 | return 0; | ||
5315 | } | ||
5316 | |||
5317 | void LLScriptPlus::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
5318 | { | ||
5319 | if (gErrorToText.getErrors()) | ||
5320 | { | ||
5321 | return; | ||
5322 | } | ||
5323 | switch(pass) | ||
5324 | { | ||
5325 | case LSCP_PRETTY_PRINT: | ||
5326 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5327 | fprintf(fp, " + "); | ||
5328 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5329 | break; | ||
5330 | case LSCP_EMIT_ASSEMBLY: | ||
5331 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5332 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5333 | fprintf(fp, "ADD %s, %s\n", LSCRIPTTypeNames[mRightType], LSCRIPTTypeNames[mLeftType]); | ||
5334 | break; | ||
5335 | case LSCP_TYPE: | ||
5336 | { | ||
5337 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5338 | mLeftType = type; | ||
5339 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5340 | mRightType = type; | ||
5341 | if (!legal_binary_expression(mReturnType, mLeftType, mRightType, mType)) | ||
5342 | { | ||
5343 | gErrorToText.writeError(fp, this, LSERROR_TYPE_MISMATCH); | ||
5344 | } | ||
5345 | type = mReturnType; | ||
5346 | } | ||
5347 | break; | ||
5348 | case LSCP_TO_STACK: | ||
5349 | { | ||
5350 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5351 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5352 | U8 typebyte = LSCRIPTTypeByte[mRightType] | LSCRIPTTypeHi4Bits[mLeftType]; | ||
5353 | chunk->addByte(LSCRIPTOpCodes[LOPC_ADD]); | ||
5354 | chunk->addByte(typebyte); | ||
5355 | } | ||
5356 | break; | ||
5357 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
5358 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5359 | print_cil_numeric_cast(fp, mLeftSide->mReturnType, mRightSide->mReturnType); | ||
5360 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5361 | print_cil_numeric_cast(fp, mRightSide->mReturnType, mLeftSide->mReturnType); | ||
5362 | print_cil_add(fp, mLeftSide->mReturnType, mRightSide->mReturnType); | ||
5363 | break; | ||
5364 | default: | ||
5365 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5366 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5367 | break; | ||
5368 | } | ||
5369 | gonext(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5370 | } | ||
5371 | |||
5372 | S32 LLScriptPlus::getSize() | ||
5373 | { | ||
5374 | return 0; | ||
5375 | } | ||
5376 | |||
5377 | void LLScriptMinus::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
5378 | { | ||
5379 | if (gErrorToText.getErrors()) | ||
5380 | { | ||
5381 | return; | ||
5382 | } | ||
5383 | switch(pass) | ||
5384 | { | ||
5385 | case LSCP_PRETTY_PRINT: | ||
5386 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5387 | fprintf(fp, " - "); | ||
5388 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5389 | break; | ||
5390 | case LSCP_EMIT_ASSEMBLY: | ||
5391 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5392 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5393 | fprintf(fp, "SUB %s, %s\n", LSCRIPTTypeNames[mRightType], LSCRIPTTypeNames[mLeftType]); | ||
5394 | break; | ||
5395 | case LSCP_TYPE: | ||
5396 | { | ||
5397 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5398 | mLeftType = type; | ||
5399 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5400 | mRightType = type; | ||
5401 | if (!legal_binary_expression(mReturnType, mLeftType, mRightType, mType)) | ||
5402 | { | ||
5403 | gErrorToText.writeError(fp, this, LSERROR_TYPE_MISMATCH); | ||
5404 | } | ||
5405 | type = mReturnType; | ||
5406 | } | ||
5407 | break; | ||
5408 | case LSCP_TO_STACK: | ||
5409 | { | ||
5410 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5411 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5412 | U8 typebyte = LSCRIPTTypeByte[mRightType] | LSCRIPTTypeHi4Bits[mLeftType]; | ||
5413 | chunk->addByte(LSCRIPTOpCodes[LOPC_SUB]); | ||
5414 | chunk->addByte(typebyte); | ||
5415 | } | ||
5416 | break; | ||
5417 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
5418 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5419 | print_cil_numeric_cast(fp, mLeftSide->mReturnType, mRightSide->mReturnType); | ||
5420 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5421 | print_cil_numeric_cast(fp, mRightSide->mReturnType, mLeftSide->mReturnType); | ||
5422 | print_cil_sub(fp, mLeftSide->mReturnType, mRightSide->mReturnType); | ||
5423 | break; | ||
5424 | default: | ||
5425 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5426 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5427 | break; | ||
5428 | } | ||
5429 | gonext(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5430 | } | ||
5431 | |||
5432 | S32 LLScriptMinus::getSize() | ||
5433 | { | ||
5434 | return 0; | ||
5435 | } | ||
5436 | |||
5437 | void LLScriptTimes::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
5438 | { | ||
5439 | if (gErrorToText.getErrors()) | ||
5440 | { | ||
5441 | return; | ||
5442 | } | ||
5443 | switch(pass) | ||
5444 | { | ||
5445 | case LSCP_PRETTY_PRINT: | ||
5446 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5447 | fprintf(fp, " * "); | ||
5448 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5449 | break; | ||
5450 | case LSCP_EMIT_ASSEMBLY: | ||
5451 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5452 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5453 | fprintf(fp, "MUL %s, %s\n", LSCRIPTTypeNames[mRightType], LSCRIPTTypeNames[mLeftType]); | ||
5454 | break; | ||
5455 | case LSCP_TYPE: | ||
5456 | { | ||
5457 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5458 | mLeftType = type; | ||
5459 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5460 | mRightType = type; | ||
5461 | if (!legal_binary_expression(mReturnType, mLeftType, mRightType, mType)) | ||
5462 | { | ||
5463 | gErrorToText.writeError(fp, this, LSERROR_TYPE_MISMATCH); | ||
5464 | } | ||
5465 | type = mReturnType; | ||
5466 | } | ||
5467 | break; | ||
5468 | case LSCP_TO_STACK: | ||
5469 | { | ||
5470 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5471 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5472 | U8 typebyte = LSCRIPTTypeByte[mRightType] | LSCRIPTTypeHi4Bits[mLeftType]; | ||
5473 | chunk->addByte(LSCRIPTOpCodes[LOPC_MUL]); | ||
5474 | chunk->addByte(typebyte); | ||
5475 | } | ||
5476 | break; | ||
5477 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
5478 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5479 | print_cil_numeric_cast(fp, mLeftSide->mReturnType, mRightSide->mReturnType); | ||
5480 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5481 | print_cil_numeric_cast(fp, mRightSide->mReturnType, mLeftSide->mReturnType); | ||
5482 | print_cil_mul(fp, mLeftSide->mReturnType, mRightSide->mReturnType); | ||
5483 | break; | ||
5484 | default: | ||
5485 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5486 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5487 | break; | ||
5488 | } | ||
5489 | gonext(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5490 | } | ||
5491 | |||
5492 | S32 LLScriptTimes::getSize() | ||
5493 | { | ||
5494 | return 0; | ||
5495 | } | ||
5496 | |||
5497 | void LLScriptDivide::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
5498 | { | ||
5499 | if (gErrorToText.getErrors()) | ||
5500 | { | ||
5501 | return; | ||
5502 | } | ||
5503 | switch(pass) | ||
5504 | { | ||
5505 | case LSCP_PRETTY_PRINT: | ||
5506 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5507 | fprintf(fp, " / "); | ||
5508 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5509 | break; | ||
5510 | case LSCP_EMIT_ASSEMBLY: | ||
5511 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5512 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5513 | fprintf(fp, "DIV %s, %s\n", LSCRIPTTypeNames[mRightType], LSCRIPTTypeNames[mLeftType]); | ||
5514 | break; | ||
5515 | case LSCP_TYPE: | ||
5516 | { | ||
5517 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5518 | mLeftType = type; | ||
5519 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5520 | mRightType = type; | ||
5521 | if (!legal_binary_expression(mReturnType, mLeftType, mRightType, mType)) | ||
5522 | { | ||
5523 | gErrorToText.writeError(fp, this, LSERROR_TYPE_MISMATCH); | ||
5524 | } | ||
5525 | type = mReturnType; | ||
5526 | } | ||
5527 | break; | ||
5528 | case LSCP_TO_STACK: | ||
5529 | { | ||
5530 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5531 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5532 | U8 typebyte = LSCRIPTTypeByte[mRightType] | LSCRIPTTypeHi4Bits[mLeftType]; | ||
5533 | chunk->addByte(LSCRIPTOpCodes[LOPC_DIV]); | ||
5534 | chunk->addByte(typebyte); | ||
5535 | } | ||
5536 | break; | ||
5537 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
5538 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5539 | print_cil_numeric_cast(fp, mLeftSide->mReturnType, mRightSide->mReturnType); | ||
5540 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5541 | print_cil_numeric_cast(fp, mRightSide->mReturnType, mLeftSide->mReturnType); | ||
5542 | print_cil_div(fp, mLeftSide->mReturnType, mRightSide->mReturnType); | ||
5543 | break; | ||
5544 | default: | ||
5545 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5546 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5547 | break; | ||
5548 | } | ||
5549 | gonext(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5550 | } | ||
5551 | |||
5552 | S32 LLScriptDivide::getSize() | ||
5553 | { | ||
5554 | return 0; | ||
5555 | } | ||
5556 | |||
5557 | void LLScriptMod::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
5558 | { | ||
5559 | if (gErrorToText.getErrors()) | ||
5560 | { | ||
5561 | return; | ||
5562 | } | ||
5563 | switch(pass) | ||
5564 | { | ||
5565 | case LSCP_PRETTY_PRINT: | ||
5566 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5567 | fprintf(fp, " %% "); | ||
5568 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5569 | break; | ||
5570 | case LSCP_EMIT_ASSEMBLY: | ||
5571 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5572 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5573 | fprintf(fp, "MOD %s, %s\n", LSCRIPTTypeNames[mRightType], LSCRIPTTypeNames[mLeftType]); | ||
5574 | break; | ||
5575 | case LSCP_TYPE: | ||
5576 | { | ||
5577 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5578 | mLeftType = type; | ||
5579 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5580 | mRightType = type; | ||
5581 | if (!legal_binary_expression(mReturnType, mLeftType, mRightType, mType)) | ||
5582 | { | ||
5583 | gErrorToText.writeError(fp, this, LSERROR_TYPE_MISMATCH); | ||
5584 | } | ||
5585 | type = mReturnType; | ||
5586 | } | ||
5587 | break; | ||
5588 | case LSCP_TO_STACK: | ||
5589 | { | ||
5590 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5591 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5592 | U8 typebyte = LSCRIPTTypeByte[mRightType] | LSCRIPTTypeHi4Bits[mLeftType]; | ||
5593 | chunk->addByte(LSCRIPTOpCodes[LOPC_MOD]); | ||
5594 | chunk->addByte(typebyte); | ||
5595 | } | ||
5596 | break; | ||
5597 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
5598 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5599 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5600 | print_cil_mod(fp, mLeftSide->mReturnType, mRightSide->mReturnType); | ||
5601 | break; | ||
5602 | default: | ||
5603 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5604 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5605 | break; | ||
5606 | } | ||
5607 | gonext(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5608 | } | ||
5609 | |||
5610 | S32 LLScriptMod::getSize() | ||
5611 | { | ||
5612 | return 0; | ||
5613 | } | ||
5614 | |||
5615 | void LLScriptBitAnd::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
5616 | { | ||
5617 | if (gErrorToText.getErrors()) | ||
5618 | { | ||
5619 | return; | ||
5620 | } | ||
5621 | switch(pass) | ||
5622 | { | ||
5623 | case LSCP_PRETTY_PRINT: | ||
5624 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5625 | fprintf(fp, " & "); | ||
5626 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5627 | break; | ||
5628 | case LSCP_EMIT_ASSEMBLY: | ||
5629 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5630 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5631 | fprintf(fp, "BITAND\n"); | ||
5632 | break; | ||
5633 | case LSCP_TYPE: | ||
5634 | { | ||
5635 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5636 | mLeftType = type; | ||
5637 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5638 | mRightType = type; | ||
5639 | if (!legal_binary_expression(mReturnType, mLeftType, mRightType, mType)) | ||
5640 | { | ||
5641 | gErrorToText.writeError(fp, this, LSERROR_TYPE_MISMATCH); | ||
5642 | } | ||
5643 | type = mReturnType; | ||
5644 | } | ||
5645 | break; | ||
5646 | case LSCP_TO_STACK: | ||
5647 | { | ||
5648 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5649 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5650 | chunk->addByte(LSCRIPTOpCodes[LOPC_BITAND]); | ||
5651 | } | ||
5652 | break; | ||
5653 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
5654 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5655 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5656 | fprintf(fp, "and\n"); | ||
5657 | break; | ||
5658 | default: | ||
5659 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5660 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5661 | break; | ||
5662 | } | ||
5663 | gonext(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5664 | } | ||
5665 | |||
5666 | S32 LLScriptBitAnd::getSize() | ||
5667 | { | ||
5668 | return 0; | ||
5669 | } | ||
5670 | |||
5671 | void LLScriptBitOr::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
5672 | { | ||
5673 | if (gErrorToText.getErrors()) | ||
5674 | { | ||
5675 | return; | ||
5676 | } | ||
5677 | switch(pass) | ||
5678 | { | ||
5679 | case LSCP_PRETTY_PRINT: | ||
5680 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5681 | fprintf(fp, " | "); | ||
5682 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5683 | break; | ||
5684 | case LSCP_EMIT_ASSEMBLY: | ||
5685 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5686 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5687 | fprintf(fp, "BITOR\n"); | ||
5688 | break; | ||
5689 | case LSCP_TYPE: | ||
5690 | { | ||
5691 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5692 | mLeftType = type; | ||
5693 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5694 | mRightType = type; | ||
5695 | if (!legal_binary_expression(mReturnType, mLeftType, mRightType, mType)) | ||
5696 | { | ||
5697 | gErrorToText.writeError(fp, this, LSERROR_TYPE_MISMATCH); | ||
5698 | } | ||
5699 | type = mReturnType; | ||
5700 | } | ||
5701 | break; | ||
5702 | case LSCP_TO_STACK: | ||
5703 | { | ||
5704 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5705 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5706 | chunk->addByte(LSCRIPTOpCodes[LOPC_BITOR]); | ||
5707 | } | ||
5708 | break; | ||
5709 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
5710 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5711 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5712 | fprintf(fp, "or\n"); | ||
5713 | break; | ||
5714 | default: | ||
5715 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5716 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5717 | break; | ||
5718 | } | ||
5719 | gonext(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5720 | } | ||
5721 | |||
5722 | S32 LLScriptBitOr::getSize() | ||
5723 | { | ||
5724 | return 0; | ||
5725 | } | ||
5726 | |||
5727 | void LLScriptBitXor::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
5728 | { | ||
5729 | if (gErrorToText.getErrors()) | ||
5730 | { | ||
5731 | return; | ||
5732 | } | ||
5733 | switch(pass) | ||
5734 | { | ||
5735 | case LSCP_PRETTY_PRINT: | ||
5736 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5737 | fprintf(fp, " ^ "); | ||
5738 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5739 | break; | ||
5740 | case LSCP_EMIT_ASSEMBLY: | ||
5741 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5742 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5743 | fprintf(fp, "BITXOR\n"); | ||
5744 | break; | ||
5745 | case LSCP_TYPE: | ||
5746 | { | ||
5747 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5748 | mLeftType = type; | ||
5749 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5750 | mRightType = type; | ||
5751 | if (!legal_binary_expression(mReturnType, mLeftType, mRightType, mType)) | ||
5752 | { | ||
5753 | gErrorToText.writeError(fp, this, LSERROR_TYPE_MISMATCH); | ||
5754 | } | ||
5755 | type = mReturnType; | ||
5756 | } | ||
5757 | break; | ||
5758 | case LSCP_TO_STACK: | ||
5759 | { | ||
5760 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5761 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5762 | chunk->addByte(LSCRIPTOpCodes[LOPC_BITXOR]); | ||
5763 | } | ||
5764 | break; | ||
5765 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
5766 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5767 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5768 | fprintf(fp, "xor\n"); | ||
5769 | break; | ||
5770 | default: | ||
5771 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5772 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5773 | break; | ||
5774 | } | ||
5775 | gonext(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5776 | } | ||
5777 | |||
5778 | S32 LLScriptBitXor::getSize() | ||
5779 | { | ||
5780 | return 0; | ||
5781 | } | ||
5782 | |||
5783 | void LLScriptBooleanAnd::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
5784 | { | ||
5785 | if (gErrorToText.getErrors()) | ||
5786 | { | ||
5787 | return; | ||
5788 | } | ||
5789 | switch(pass) | ||
5790 | { | ||
5791 | case LSCP_PRETTY_PRINT: | ||
5792 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5793 | fprintf(fp, " && "); | ||
5794 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5795 | break; | ||
5796 | case LSCP_EMIT_ASSEMBLY: | ||
5797 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5798 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5799 | fprintf(fp, "BOOLAND\n"); | ||
5800 | break; | ||
5801 | case LSCP_TYPE: | ||
5802 | { | ||
5803 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5804 | mLeftType = type; | ||
5805 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5806 | mRightType = type; | ||
5807 | if (!legal_binary_expression(mReturnType, mLeftType, mRightType, mType)) | ||
5808 | { | ||
5809 | gErrorToText.writeError(fp, this, LSERROR_TYPE_MISMATCH); | ||
5810 | } | ||
5811 | type = mReturnType; | ||
5812 | } | ||
5813 | break; | ||
5814 | case LSCP_TO_STACK: | ||
5815 | { | ||
5816 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5817 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5818 | chunk->addByte(LSCRIPTOpCodes[LOPC_BOOLAND]); | ||
5819 | } | ||
5820 | break; | ||
5821 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
5822 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5823 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5824 | fprintf(fp, "and\n"); | ||
5825 | break; | ||
5826 | default: | ||
5827 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5828 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5829 | break; | ||
5830 | } | ||
5831 | gonext(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5832 | } | ||
5833 | |||
5834 | S32 LLScriptBooleanAnd::getSize() | ||
5835 | { | ||
5836 | return 0; | ||
5837 | } | ||
5838 | |||
5839 | void LLScriptBooleanOr::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
5840 | { | ||
5841 | if (gErrorToText.getErrors()) | ||
5842 | { | ||
5843 | return; | ||
5844 | } | ||
5845 | switch(pass) | ||
5846 | { | ||
5847 | case LSCP_PRETTY_PRINT: | ||
5848 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5849 | fprintf(fp, " || "); | ||
5850 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5851 | break; | ||
5852 | case LSCP_EMIT_ASSEMBLY: | ||
5853 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5854 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5855 | fprintf(fp, "BOOLOR\n"); | ||
5856 | break; | ||
5857 | case LSCP_TYPE: | ||
5858 | { | ||
5859 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5860 | mLeftType = type; | ||
5861 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5862 | mRightType = type; | ||
5863 | if (!legal_binary_expression(mReturnType, mLeftType, mRightType, mType)) | ||
5864 | { | ||
5865 | gErrorToText.writeError(fp, this, LSERROR_TYPE_MISMATCH); | ||
5866 | } | ||
5867 | type = mReturnType; | ||
5868 | } | ||
5869 | break; | ||
5870 | case LSCP_TO_STACK: | ||
5871 | { | ||
5872 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5873 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5874 | chunk->addByte(LSCRIPTOpCodes[LOPC_BOOLOR]); | ||
5875 | } | ||
5876 | break; | ||
5877 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
5878 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5879 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5880 | fprintf(fp, "or\n"); | ||
5881 | break; | ||
5882 | default: | ||
5883 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5884 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5885 | break; | ||
5886 | } | ||
5887 | gonext(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5888 | } | ||
5889 | |||
5890 | S32 LLScriptBooleanOr::getSize() | ||
5891 | { | ||
5892 | return 0; | ||
5893 | } | ||
5894 | |||
5895 | void LLScriptShiftLeft::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
5896 | { | ||
5897 | if (gErrorToText.getErrors()) | ||
5898 | { | ||
5899 | return; | ||
5900 | } | ||
5901 | switch(pass) | ||
5902 | { | ||
5903 | case LSCP_PRETTY_PRINT: | ||
5904 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5905 | fprintf(fp, " << "); | ||
5906 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5907 | break; | ||
5908 | case LSCP_EMIT_ASSEMBLY: | ||
5909 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5910 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5911 | fprintf(fp, "SHL\n"); | ||
5912 | break; | ||
5913 | case LSCP_TYPE: | ||
5914 | { | ||
5915 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5916 | mLeftType = type; | ||
5917 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5918 | mRightType = type; | ||
5919 | if (!legal_binary_expression(mReturnType, mLeftType, mRightType, mType)) | ||
5920 | { | ||
5921 | gErrorToText.writeError(fp, this, LSERROR_TYPE_MISMATCH); | ||
5922 | } | ||
5923 | type = mReturnType; | ||
5924 | } | ||
5925 | break; | ||
5926 | case LSCP_TO_STACK: | ||
5927 | { | ||
5928 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5929 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5930 | chunk->addByte(LSCRIPTOpCodes[LOPC_SHL]); | ||
5931 | } | ||
5932 | break; | ||
5933 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
5934 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5935 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5936 | fprintf(fp, "shl\n"); | ||
5937 | break; | ||
5938 | default: | ||
5939 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5940 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5941 | break; | ||
5942 | } | ||
5943 | gonext(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5944 | } | ||
5945 | |||
5946 | S32 LLScriptShiftLeft::getSize() | ||
5947 | { | ||
5948 | return 0; | ||
5949 | } | ||
5950 | |||
5951 | |||
5952 | void LLScriptShiftRight::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
5953 | { | ||
5954 | if (gErrorToText.getErrors()) | ||
5955 | { | ||
5956 | return; | ||
5957 | } | ||
5958 | switch(pass) | ||
5959 | { | ||
5960 | case LSCP_PRETTY_PRINT: | ||
5961 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5962 | fprintf(fp, " >> "); | ||
5963 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5964 | break; | ||
5965 | case LSCP_EMIT_ASSEMBLY: | ||
5966 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5967 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5968 | fprintf(fp, "SHR\n"); | ||
5969 | break; | ||
5970 | case LSCP_TYPE: | ||
5971 | { | ||
5972 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5973 | mLeftType = type; | ||
5974 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5975 | mRightType = type; | ||
5976 | if (!legal_binary_expression(mReturnType, mLeftType, mRightType, mType)) | ||
5977 | { | ||
5978 | gErrorToText.writeError(fp, this, LSERROR_TYPE_MISMATCH); | ||
5979 | } | ||
5980 | type = mReturnType; | ||
5981 | } | ||
5982 | break; | ||
5983 | case LSCP_TO_STACK: | ||
5984 | { | ||
5985 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5986 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5987 | chunk->addByte(LSCRIPTOpCodes[LOPC_SHR]); | ||
5988 | } | ||
5989 | break; | ||
5990 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
5991 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5992 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5993 | fprintf(fp, "shr\n"); | ||
5994 | break; | ||
5995 | default: | ||
5996 | mLeftSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5997 | mRightSide->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
5998 | break; | ||
5999 | } | ||
6000 | gonext(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6001 | } | ||
6002 | |||
6003 | S32 LLScriptShiftRight::getSize() | ||
6004 | { | ||
6005 | return 0; | ||
6006 | } | ||
6007 | |||
6008 | void LLScriptParenthesis::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
6009 | { | ||
6010 | if (gErrorToText.getErrors()) | ||
6011 | { | ||
6012 | return; | ||
6013 | } | ||
6014 | switch(pass) | ||
6015 | { | ||
6016 | case LSCP_PRETTY_PRINT: | ||
6017 | fprintf(fp, "( "); | ||
6018 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6019 | fprintf(fp, " )"); | ||
6020 | break; | ||
6021 | case LSCP_TYPE: | ||
6022 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6023 | mReturnType = mLeftType = type; | ||
6024 | break; | ||
6025 | case LSCP_EMIT_ASSEMBLY: | ||
6026 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6027 | mReturnType = mLeftType = type; | ||
6028 | break; | ||
6029 | default: | ||
6030 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6031 | break; | ||
6032 | } | ||
6033 | gonext(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6034 | } | ||
6035 | |||
6036 | S32 LLScriptParenthesis::getSize() | ||
6037 | { | ||
6038 | return 0; | ||
6039 | } | ||
6040 | |||
6041 | void LLScriptUnaryMinus::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
6042 | { | ||
6043 | if (gErrorToText.getErrors()) | ||
6044 | { | ||
6045 | return; | ||
6046 | } | ||
6047 | switch(pass) | ||
6048 | { | ||
6049 | case LSCP_PRETTY_PRINT: | ||
6050 | fprintf(fp, "-"); | ||
6051 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6052 | break; | ||
6053 | case LSCP_EMIT_ASSEMBLY: | ||
6054 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6055 | fprintf(fp, "NEG %s\n", LSCRIPTTypeNames[mLeftType]); | ||
6056 | break; | ||
6057 | case LSCP_TYPE: | ||
6058 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6059 | if (!legal_unary_expression(type, type, mType)) | ||
6060 | { | ||
6061 | gErrorToText.writeError(fp, this, LSERROR_TYPE_MISMATCH); | ||
6062 | } | ||
6063 | else | ||
6064 | { | ||
6065 | mReturnType = mLeftType = type; | ||
6066 | } | ||
6067 | break; | ||
6068 | case LSCP_TO_STACK: | ||
6069 | { | ||
6070 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6071 | U8 typebyte = LSCRIPTTypeByte[mLeftType]; | ||
6072 | chunk->addByte(LSCRIPTOpCodes[LOPC_NEG]); | ||
6073 | chunk->addByte(typebyte); | ||
6074 | } | ||
6075 | break; | ||
6076 | default: | ||
6077 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6078 | break; | ||
6079 | } | ||
6080 | gonext(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6081 | } | ||
6082 | |||
6083 | S32 LLScriptUnaryMinus::getSize() | ||
6084 | { | ||
6085 | return 0; | ||
6086 | } | ||
6087 | |||
6088 | void LLScriptBooleanNot::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
6089 | { | ||
6090 | if (gErrorToText.getErrors()) | ||
6091 | { | ||
6092 | return; | ||
6093 | } | ||
6094 | switch(pass) | ||
6095 | { | ||
6096 | case LSCP_PRETTY_PRINT: | ||
6097 | fprintf(fp, "!"); | ||
6098 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6099 | break; | ||
6100 | case LSCP_EMIT_ASSEMBLY: | ||
6101 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6102 | fprintf(fp, "BOOLNOT\n"); | ||
6103 | break; | ||
6104 | case LSCP_TYPE: | ||
6105 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6106 | if (!legal_unary_expression(type, type, mType)) | ||
6107 | { | ||
6108 | gErrorToText.writeError(fp, this, LSERROR_TYPE_MISMATCH); | ||
6109 | } | ||
6110 | else | ||
6111 | { | ||
6112 | mReturnType = mLeftType = type; | ||
6113 | } | ||
6114 | break; | ||
6115 | case LSCP_TO_STACK: | ||
6116 | { | ||
6117 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6118 | chunk->addByte(LSCRIPTOpCodes[LOPC_BOOLNOT]); | ||
6119 | } | ||
6120 | break; | ||
6121 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
6122 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6123 | fprintf(fp, "ldc.i4.0\n"); | ||
6124 | fprintf(fp, "ceq\n"); // If f(e) is (e == 0), f(e) returns 1 if e is 0 and 0 otherwise, therefore f(e) implements boolean not. | ||
6125 | break; | ||
6126 | default: | ||
6127 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6128 | break; | ||
6129 | } | ||
6130 | gonext(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6131 | } | ||
6132 | |||
6133 | S32 LLScriptBooleanNot::getSize() | ||
6134 | { | ||
6135 | return 0; | ||
6136 | } | ||
6137 | |||
6138 | void LLScriptBitNot::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
6139 | { | ||
6140 | if (gErrorToText.getErrors()) | ||
6141 | { | ||
6142 | return; | ||
6143 | } | ||
6144 | switch(pass) | ||
6145 | { | ||
6146 | case LSCP_PRETTY_PRINT: | ||
6147 | fprintf(fp, "~"); | ||
6148 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6149 | break; | ||
6150 | case LSCP_EMIT_ASSEMBLY: | ||
6151 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6152 | fprintf(fp, "BITNOT\n"); | ||
6153 | break; | ||
6154 | case LSCP_TYPE: | ||
6155 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6156 | if (!legal_unary_expression(type, type, mType)) | ||
6157 | { | ||
6158 | gErrorToText.writeError(fp, this, LSERROR_TYPE_MISMATCH); | ||
6159 | } | ||
6160 | else | ||
6161 | { | ||
6162 | mReturnType = mLeftType = type; | ||
6163 | } | ||
6164 | break; | ||
6165 | case LSCP_TO_STACK: | ||
6166 | { | ||
6167 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6168 | chunk->addByte(LSCRIPTOpCodes[LOPC_BITNOT]); | ||
6169 | } | ||
6170 | break; | ||
6171 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
6172 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6173 | fprintf(fp, "not\n"); | ||
6174 | break; | ||
6175 | default: | ||
6176 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6177 | break; | ||
6178 | } | ||
6179 | gonext(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6180 | } | ||
6181 | |||
6182 | S32 LLScriptBitNot::getSize() | ||
6183 | { | ||
6184 | return 0; | ||
6185 | } | ||
6186 | |||
6187 | void LLScriptPreIncrement::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
6188 | { | ||
6189 | if (gErrorToText.getErrors()) | ||
6190 | { | ||
6191 | return; | ||
6192 | } | ||
6193 | switch(pass) | ||
6194 | { | ||
6195 | case LSCP_PRETTY_PRINT: | ||
6196 | fprintf(fp, "++"); | ||
6197 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6198 | break; | ||
6199 | case LSCP_EMIT_ASSEMBLY: | ||
6200 | { | ||
6201 | if (mReturnType == LST_INTEGER) | ||
6202 | { | ||
6203 | fprintf(fp, "PUSHARGI 1\n"); | ||
6204 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6205 | fprintf(fp, "\n"); | ||
6206 | fprintf(fp, "ADD integer, integer\n"); | ||
6207 | } | ||
6208 | else if (mReturnType == LST_FLOATINGPOINT) | ||
6209 | { | ||
6210 | fprintf(fp, "PUSHARGF 1\n"); | ||
6211 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6212 | fprintf(fp, "\n"); | ||
6213 | fprintf(fp, "ADD float, float\n"); | ||
6214 | } | ||
6215 | else | ||
6216 | { | ||
6217 | fprintf(fp, "Unexpected Type\n"); | ||
6218 | } | ||
6219 | print_asignment(fp, mExpression); | ||
6220 | } | ||
6221 | break; | ||
6222 | case LSCP_TYPE: | ||
6223 | if (mExpression->mType != LET_LVALUE) | ||
6224 | { | ||
6225 | gErrorToText.writeError(fp, this, LSERROR_EXPRESSION_ON_LVALUE); | ||
6226 | } | ||
6227 | else | ||
6228 | { | ||
6229 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6230 | if (!legal_unary_expression(type, type, mType)) | ||
6231 | { | ||
6232 | gErrorToText.writeError(fp, this, LSERROR_TYPE_MISMATCH); | ||
6233 | } | ||
6234 | else | ||
6235 | { | ||
6236 | mReturnType = mLeftType = type; | ||
6237 | } | ||
6238 | } | ||
6239 | break; | ||
6240 | case LSCP_TO_STACK: | ||
6241 | { | ||
6242 | if (mReturnType == LST_INTEGER) | ||
6243 | { | ||
6244 | chunk->addByte(LSCRIPTOpCodes[LOPC_PUSHARGI]); | ||
6245 | chunk->addInteger(1); | ||
6246 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6247 | chunk->addByte(LSCRIPTOpCodes[LOPC_ADD]); | ||
6248 | chunk->addByte(LSCRIPTTypeByte[LST_INTEGER] | LSCRIPTTypeHi4Bits[LST_INTEGER]); | ||
6249 | } | ||
6250 | else if (mReturnType == LST_FLOATINGPOINT) | ||
6251 | { | ||
6252 | chunk->addByte(LSCRIPTOpCodes[LOPC_PUSHARGF]); | ||
6253 | chunk->addFloat(1.f); | ||
6254 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6255 | chunk->addByte(LSCRIPTOpCodes[LOPC_ADD]); | ||
6256 | chunk->addByte(LSCRIPTTypeByte[LST_FLOATINGPOINT] | LSCRIPTTypeHi4Bits[LST_FLOATINGPOINT]); | ||
6257 | } | ||
6258 | store2stack(this, mExpression, chunk, mReturnType); | ||
6259 | } | ||
6260 | break; | ||
6261 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
6262 | { | ||
6263 | print_cil_load_address(fp, mExpression, entry); | ||
6264 | if (mReturnType == LST_INTEGER) | ||
6265 | { | ||
6266 | fprintf(fp, "ldc.i4.1\n"); | ||
6267 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6268 | fprintf(fp, "add\n"); | ||
6269 | } | ||
6270 | else if (mReturnType == LST_FLOATINGPOINT) | ||
6271 | { | ||
6272 | fprintf(fp, "ldc.r8.1\n"); | ||
6273 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6274 | fprintf(fp, "add\n"); | ||
6275 | } | ||
6276 | else | ||
6277 | { | ||
6278 | fprintf(fp, "Unexpected Type\n"); | ||
6279 | } | ||
6280 | print_cil_asignment(fp, mExpression, entry); | ||
6281 | } | ||
6282 | break; | ||
6283 | default: | ||
6284 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6285 | break; | ||
6286 | } | ||
6287 | gonext(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6288 | } | ||
6289 | |||
6290 | S32 LLScriptPreIncrement::getSize() | ||
6291 | { | ||
6292 | return 0; | ||
6293 | } | ||
6294 | |||
6295 | void LLScriptPreDecrement::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
6296 | { | ||
6297 | if (gErrorToText.getErrors()) | ||
6298 | { | ||
6299 | return; | ||
6300 | } | ||
6301 | switch(pass) | ||
6302 | { | ||
6303 | case LSCP_PRETTY_PRINT: | ||
6304 | fprintf(fp, "--"); | ||
6305 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6306 | break; | ||
6307 | case LSCP_EMIT_ASSEMBLY: | ||
6308 | { | ||
6309 | if (mReturnType == LST_INTEGER) | ||
6310 | { | ||
6311 | fprintf(fp, "PUSHARGI 1\n"); | ||
6312 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6313 | fprintf(fp, "\n"); | ||
6314 | fprintf(fp, "SUB integer, integer\n"); | ||
6315 | } | ||
6316 | else if (mReturnType == LST_FLOATINGPOINT) | ||
6317 | { | ||
6318 | fprintf(fp, "PUSHARGF 1\n"); | ||
6319 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6320 | fprintf(fp, "\n"); | ||
6321 | fprintf(fp, "SUB float, float\n"); | ||
6322 | } | ||
6323 | else | ||
6324 | { | ||
6325 | fprintf(fp, "Unexpected Type\n"); | ||
6326 | } | ||
6327 | print_asignment(fp, mExpression); | ||
6328 | } | ||
6329 | break; | ||
6330 | case LSCP_TYPE: | ||
6331 | if (mExpression->mType != LET_LVALUE) | ||
6332 | { | ||
6333 | gErrorToText.writeError(fp, this, LSERROR_EXPRESSION_ON_LVALUE); | ||
6334 | } | ||
6335 | else | ||
6336 | { | ||
6337 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6338 | if (!legal_unary_expression(type, type, mType)) | ||
6339 | { | ||
6340 | gErrorToText.writeError(fp, this, LSERROR_TYPE_MISMATCH); | ||
6341 | } | ||
6342 | else | ||
6343 | { | ||
6344 | mReturnType = mLeftType = type; | ||
6345 | } | ||
6346 | } | ||
6347 | break; | ||
6348 | case LSCP_TO_STACK: | ||
6349 | { | ||
6350 | if (mReturnType == LST_INTEGER) | ||
6351 | { | ||
6352 | chunk->addByte(LSCRIPTOpCodes[LOPC_PUSHARGI]); | ||
6353 | chunk->addInteger(1); | ||
6354 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6355 | chunk->addByte(LSCRIPTOpCodes[LOPC_SUB]); | ||
6356 | chunk->addByte(LSCRIPTTypeByte[LST_INTEGER] | LSCRIPTTypeHi4Bits[LST_INTEGER]); | ||
6357 | } | ||
6358 | else if (mReturnType == LST_FLOATINGPOINT) | ||
6359 | { | ||
6360 | chunk->addByte(LSCRIPTOpCodes[LOPC_PUSHARGF]); | ||
6361 | chunk->addFloat(1.f); | ||
6362 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6363 | chunk->addByte(LSCRIPTOpCodes[LOPC_SUB]); | ||
6364 | chunk->addByte(LSCRIPTTypeByte[LST_FLOATINGPOINT] | LSCRIPTTypeHi4Bits[LST_FLOATINGPOINT]); | ||
6365 | } | ||
6366 | store2stack(this, mExpression, chunk, mReturnType); | ||
6367 | } | ||
6368 | break; | ||
6369 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
6370 | { | ||
6371 | print_cil_load_address(fp, mExpression, entry); | ||
6372 | if (mReturnType == LST_INTEGER) | ||
6373 | { | ||
6374 | fprintf(fp, "ldc.i4.1\n"); | ||
6375 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6376 | fprintf(fp, "sub\n"); | ||
6377 | } | ||
6378 | else if (mReturnType == LST_FLOATINGPOINT) | ||
6379 | { | ||
6380 | fprintf(fp, "ldc.r8.1\n"); | ||
6381 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6382 | fprintf(fp, "sub\n"); | ||
6383 | } | ||
6384 | else | ||
6385 | { | ||
6386 | fprintf(fp, "Unexpected Type\n"); | ||
6387 | } | ||
6388 | print_cil_asignment(fp, mExpression, entry); | ||
6389 | } | ||
6390 | break; | ||
6391 | default: | ||
6392 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6393 | break; | ||
6394 | } | ||
6395 | gonext(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6396 | } | ||
6397 | |||
6398 | S32 LLScriptPreDecrement::getSize() | ||
6399 | { | ||
6400 | return 0; | ||
6401 | } | ||
6402 | |||
6403 | void LLScriptTypeCast::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
6404 | { | ||
6405 | if (gErrorToText.getErrors()) | ||
6406 | { | ||
6407 | return; | ||
6408 | } | ||
6409 | switch(pass) | ||
6410 | { | ||
6411 | case LSCP_PRETTY_PRINT: | ||
6412 | fprintf(fp, "( "); | ||
6413 | mType->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6414 | fprintf(fp, ") "); | ||
6415 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6416 | break; | ||
6417 | case LSCP_EMIT_ASSEMBLY: | ||
6418 | fprintf(fp, "CAST %s->%s\n", LSCRIPTTypeNames[mRightType], LSCRIPTTypeNames[mType->mType]); | ||
6419 | break; | ||
6420 | case LSCP_TYPE: | ||
6421 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6422 | mRightType = type; | ||
6423 | if (!legal_casts(mType->mType, type)) | ||
6424 | { | ||
6425 | gErrorToText.writeError(fp, this, LSERROR_TYPE_MISMATCH); | ||
6426 | } | ||
6427 | type = mType->mType; | ||
6428 | mReturnType = mLeftType = type; | ||
6429 | break; | ||
6430 | case LSCP_TO_STACK: | ||
6431 | { | ||
6432 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6433 | chunk->addByte(LSCRIPTOpCodes[LOPC_CAST]); | ||
6434 | U8 castbyte = LSCRIPTTypeByte[mType->mType] | LSCRIPTTypeHi4Bits[mRightType]; | ||
6435 | chunk->addByte(castbyte); | ||
6436 | } | ||
6437 | break; | ||
6438 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
6439 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6440 | print_cil_cast(fp, mRightType, mType->mType); | ||
6441 | break; | ||
6442 | default: | ||
6443 | mType->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6444 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6445 | break; | ||
6446 | } | ||
6447 | gonext(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6448 | } | ||
6449 | |||
6450 | S32 LLScriptTypeCast::getSize() | ||
6451 | { | ||
6452 | return 0; | ||
6453 | } | ||
6454 | |||
6455 | void LLScriptVectorInitializer::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
6456 | { | ||
6457 | if (gErrorToText.getErrors()) | ||
6458 | { | ||
6459 | return; | ||
6460 | } | ||
6461 | switch(pass) | ||
6462 | { | ||
6463 | case LSCP_PRETTY_PRINT: | ||
6464 | fprintf(fp, "< "); | ||
6465 | mExpression1->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6466 | fprintf(fp, ", "); | ||
6467 | mExpression2->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6468 | fprintf(fp, ", "); | ||
6469 | mExpression3->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6470 | fprintf(fp, " >"); | ||
6471 | break; | ||
6472 | case LSCP_EMIT_ASSEMBLY: | ||
6473 | mExpression1->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6474 | if (mExpression1->mReturnType != LST_FLOATINGPOINT) | ||
6475 | { | ||
6476 | fprintf(fp, "CAST %s->%s\n", LSCRIPTTypeNames[mExpression1->mReturnType], LSCRIPTTypeNames[LST_FLOATINGPOINT]); | ||
6477 | } | ||
6478 | mExpression2->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6479 | if (mExpression2->mReturnType != LST_FLOATINGPOINT) | ||
6480 | { | ||
6481 | fprintf(fp, "CAST %s->%s\n", LSCRIPTTypeNames[mExpression2->mReturnType], LSCRIPTTypeNames[LST_FLOATINGPOINT]); | ||
6482 | } | ||
6483 | mExpression3->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6484 | if (mExpression3->mReturnType != LST_FLOATINGPOINT) | ||
6485 | { | ||
6486 | fprintf(fp, "CAST %s->%s\n", LSCRIPTTypeNames[mExpression3->mReturnType], LSCRIPTTypeNames[LST_FLOATINGPOINT]); | ||
6487 | } | ||
6488 | break; | ||
6489 | case LSCP_TYPE: | ||
6490 | // vector's take floats | ||
6491 | mExpression1->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6492 | if (!legal_assignment(LST_FLOATINGPOINT, type)) | ||
6493 | { | ||
6494 | gErrorToText.writeError(fp, this, LSERROR_TYPE_MISMATCH); | ||
6495 | } | ||
6496 | mExpression2->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6497 | if (!legal_assignment(LST_FLOATINGPOINT, type)) | ||
6498 | { | ||
6499 | gErrorToText.writeError(fp, this, LSERROR_TYPE_MISMATCH); | ||
6500 | } | ||
6501 | mExpression3->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6502 | if (!legal_assignment(LST_FLOATINGPOINT, type)) | ||
6503 | { | ||
6504 | gErrorToText.writeError(fp, this, LSERROR_TYPE_MISMATCH); | ||
6505 | } | ||
6506 | mReturnType = type = LST_VECTOR; | ||
6507 | if (mNextp) | ||
6508 | { | ||
6509 | mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6510 | } | ||
6511 | break; | ||
6512 | case LSCP_TO_STACK: | ||
6513 | pass = LSCP_TO_STACK; | ||
6514 | mExpression1->recurse(fp, tabs, tabsize, LSCP_TO_STACK, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6515 | if (mExpression1->mReturnType != LST_FLOATINGPOINT) | ||
6516 | { | ||
6517 | chunk->addByte(LSCRIPTOpCodes[LOPC_CAST]); | ||
6518 | U8 castbyte = LSCRIPTTypeByte[LST_FLOATINGPOINT] | LSCRIPTTypeHi4Bits[mExpression1->mReturnType]; | ||
6519 | chunk->addByte(castbyte); | ||
6520 | } | ||
6521 | mExpression2->recurse(fp, tabs, tabsize, LSCP_TO_STACK, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6522 | if (mExpression2->mReturnType != LST_FLOATINGPOINT) | ||
6523 | { | ||
6524 | chunk->addByte(LSCRIPTOpCodes[LOPC_CAST]); | ||
6525 | U8 castbyte = LSCRIPTTypeByte[LST_FLOATINGPOINT] | LSCRIPTTypeHi4Bits[mExpression2->mReturnType]; | ||
6526 | chunk->addByte(castbyte); | ||
6527 | } | ||
6528 | mExpression3->recurse(fp, tabs, tabsize, LSCP_TO_STACK, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6529 | if (mExpression3->mReturnType != LST_FLOATINGPOINT) | ||
6530 | { | ||
6531 | chunk->addByte(LSCRIPTOpCodes[LOPC_CAST]); | ||
6532 | U8 castbyte = LSCRIPTTypeByte[LST_FLOATINGPOINT] | LSCRIPTTypeHi4Bits[mExpression3->mReturnType]; | ||
6533 | chunk->addByte(castbyte); | ||
6534 | } | ||
6535 | break; | ||
6536 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
6537 | |||
6538 | // Load arguments. | ||
6539 | mExpression1->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6540 | if (mExpression1->mReturnType != LST_FLOATINGPOINT) | ||
6541 | { | ||
6542 | print_cil_cast(fp, mExpression1->mReturnType, LST_FLOATINGPOINT); | ||
6543 | } | ||
6544 | mExpression2->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6545 | if (mExpression2->mReturnType != LST_FLOATINGPOINT) | ||
6546 | { | ||
6547 | print_cil_cast(fp, mExpression2->mReturnType, LST_FLOATINGPOINT); | ||
6548 | } | ||
6549 | mExpression3->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6550 | if (mExpression3->mReturnType != LST_FLOATINGPOINT) | ||
6551 | { | ||
6552 | print_cil_cast(fp, mExpression3->mReturnType, LST_FLOATINGPOINT); | ||
6553 | } | ||
6554 | // Call named ctor, which leaves new Vector on stack, so it can be saved in to local or argument just like a primitive type. | ||
6555 | fprintf(fp, "call valuetype [LScriptLibrary]LLVector valuetype [LScriptLibrary]LLVector::'create'(float32, float32, float32)\n"); | ||
6556 | break; | ||
6557 | default: | ||
6558 | mExpression1->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6559 | mExpression2->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6560 | mExpression3->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6561 | break; | ||
6562 | } | ||
6563 | gonext(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6564 | } | ||
6565 | |||
6566 | S32 LLScriptVectorInitializer::getSize() | ||
6567 | { | ||
6568 | return 0; | ||
6569 | } | ||
6570 | |||
6571 | void LLScriptQuaternionInitializer::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
6572 | { | ||
6573 | if (gErrorToText.getErrors()) | ||
6574 | { | ||
6575 | return; | ||
6576 | } | ||
6577 | switch(pass) | ||
6578 | { | ||
6579 | case LSCP_PRETTY_PRINT: | ||
6580 | fprintf(fp, "< "); | ||
6581 | mExpression1->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6582 | fprintf(fp, ", "); | ||
6583 | mExpression2->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6584 | fprintf(fp, ", "); | ||
6585 | mExpression3->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6586 | fprintf(fp, ", "); | ||
6587 | mExpression4->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6588 | fprintf(fp, " >"); | ||
6589 | break; | ||
6590 | case LSCP_EMIT_ASSEMBLY: | ||
6591 | mExpression1->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6592 | if (mExpression1->mReturnType != LST_FLOATINGPOINT) | ||
6593 | { | ||
6594 | fprintf(fp, "CAST %s->%s\n", LSCRIPTTypeNames[mExpression1->mReturnType], LSCRIPTTypeNames[LST_FLOATINGPOINT]); | ||
6595 | } | ||
6596 | mExpression2->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6597 | if (mExpression2->mReturnType != LST_FLOATINGPOINT) | ||
6598 | { | ||
6599 | fprintf(fp, "CAST %s->%s\n", LSCRIPTTypeNames[mExpression2->mReturnType], LSCRIPTTypeNames[LST_FLOATINGPOINT]); | ||
6600 | } | ||
6601 | mExpression3->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6602 | if (mExpression3->mReturnType != LST_FLOATINGPOINT) | ||
6603 | { | ||
6604 | fprintf(fp, "CAST %s->%s\n", LSCRIPTTypeNames[mExpression3->mReturnType], LSCRIPTTypeNames[LST_FLOATINGPOINT]); | ||
6605 | } | ||
6606 | mExpression4->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6607 | if (mExpression4->mReturnType != LST_FLOATINGPOINT) | ||
6608 | { | ||
6609 | fprintf(fp, "CAST %s->%s\n", LSCRIPTTypeNames[mExpression4->mReturnType], LSCRIPTTypeNames[LST_FLOATINGPOINT]); | ||
6610 | } | ||
6611 | break; | ||
6612 | case LSCP_TYPE: | ||
6613 | // vector's take floats | ||
6614 | mExpression1->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6615 | if (!legal_assignment(LST_FLOATINGPOINT, type)) | ||
6616 | { | ||
6617 | gErrorToText.writeError(fp, this, LSERROR_TYPE_MISMATCH); | ||
6618 | } | ||
6619 | mExpression2->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6620 | if (!legal_assignment(LST_FLOATINGPOINT, type)) | ||
6621 | { | ||
6622 | gErrorToText.writeError(fp, this, LSERROR_TYPE_MISMATCH); | ||
6623 | } | ||
6624 | mExpression3->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6625 | if (!legal_assignment(LST_FLOATINGPOINT, type)) | ||
6626 | { | ||
6627 | gErrorToText.writeError(fp, this, LSERROR_TYPE_MISMATCH); | ||
6628 | } | ||
6629 | mExpression4->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6630 | if (!legal_assignment(LST_FLOATINGPOINT, type)) | ||
6631 | { | ||
6632 | gErrorToText.writeError(fp, this, LSERROR_TYPE_MISMATCH); | ||
6633 | } | ||
6634 | mReturnType = type = LST_QUATERNION; | ||
6635 | if (mNextp) | ||
6636 | { | ||
6637 | mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6638 | } | ||
6639 | break; | ||
6640 | case LSCP_TO_STACK: | ||
6641 | pass = LSCP_TO_STACK; | ||
6642 | mExpression1->recurse(fp, tabs, tabsize, LSCP_TO_STACK, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6643 | if (mExpression1->mReturnType != LST_FLOATINGPOINT) | ||
6644 | { | ||
6645 | chunk->addByte(LSCRIPTOpCodes[LOPC_CAST]); | ||
6646 | U8 castbyte = LSCRIPTTypeByte[LST_FLOATINGPOINT] | LSCRIPTTypeHi4Bits[mExpression1->mReturnType]; | ||
6647 | chunk->addByte(castbyte); | ||
6648 | } | ||
6649 | mExpression2->recurse(fp, tabs, tabsize, LSCP_TO_STACK, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6650 | if (mExpression2->mReturnType != LST_FLOATINGPOINT) | ||
6651 | { | ||
6652 | chunk->addByte(LSCRIPTOpCodes[LOPC_CAST]); | ||
6653 | U8 castbyte = LSCRIPTTypeByte[LST_FLOATINGPOINT] | LSCRIPTTypeHi4Bits[mExpression2->mReturnType]; | ||
6654 | chunk->addByte(castbyte); | ||
6655 | } | ||
6656 | mExpression3->recurse(fp, tabs, tabsize, LSCP_TO_STACK, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6657 | if (mExpression3->mReturnType != LST_FLOATINGPOINT) | ||
6658 | { | ||
6659 | chunk->addByte(LSCRIPTOpCodes[LOPC_CAST]); | ||
6660 | U8 castbyte = LSCRIPTTypeByte[LST_FLOATINGPOINT] | LSCRIPTTypeHi4Bits[mExpression3->mReturnType]; | ||
6661 | chunk->addByte(castbyte); | ||
6662 | } | ||
6663 | mExpression4->recurse(fp, tabs, tabsize, LSCP_TO_STACK, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6664 | if (mExpression4->mReturnType != LST_FLOATINGPOINT) | ||
6665 | { | ||
6666 | chunk->addByte(LSCRIPTOpCodes[LOPC_CAST]); | ||
6667 | U8 castbyte = LSCRIPTTypeByte[LST_FLOATINGPOINT] | LSCRIPTTypeHi4Bits[mExpression4->mReturnType]; | ||
6668 | chunk->addByte(castbyte); | ||
6669 | } | ||
6670 | break; | ||
6671 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
6672 | |||
6673 | // Load arguments. | ||
6674 | mExpression1->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6675 | if (mExpression1->mReturnType != LST_FLOATINGPOINT) | ||
6676 | { | ||
6677 | print_cil_cast(fp, mExpression1->mReturnType, LST_FLOATINGPOINT); | ||
6678 | } | ||
6679 | mExpression2->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6680 | if (mExpression2->mReturnType != LST_FLOATINGPOINT) | ||
6681 | { | ||
6682 | print_cil_cast(fp, mExpression2->mReturnType, LST_FLOATINGPOINT); | ||
6683 | } | ||
6684 | mExpression3->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6685 | if (mExpression3->mReturnType != LST_FLOATINGPOINT) | ||
6686 | { | ||
6687 | print_cil_cast(fp, mExpression3->mReturnType, LST_FLOATINGPOINT); | ||
6688 | } | ||
6689 | mExpression4->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6690 | if (mExpression4->mReturnType != LST_FLOATINGPOINT) | ||
6691 | { | ||
6692 | print_cil_cast(fp, mExpression4->mReturnType, LST_FLOATINGPOINT); | ||
6693 | } | ||
6694 | |||
6695 | // Call named ctor, which leaves new Vector on stack, so it can be saved in to local or argument just like a primitive type. | ||
6696 | fprintf(fp, "call valuetype [LScriptLibrary]LLQuaternion valuetype [LScriptLibrary]LLQuaternion::'create'(float32, float32, float32, float32)\n"); | ||
6697 | break; | ||
6698 | default: | ||
6699 | mExpression1->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6700 | mExpression2->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6701 | mExpression3->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6702 | mExpression4->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6703 | break; | ||
6704 | } | ||
6705 | gonext(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6706 | } | ||
6707 | |||
6708 | S32 LLScriptQuaternionInitializer::getSize() | ||
6709 | { | ||
6710 | return 0; | ||
6711 | } | ||
6712 | |||
6713 | void LLScriptListInitializer::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
6714 | { | ||
6715 | if (gErrorToText.getErrors()) | ||
6716 | { | ||
6717 | return; | ||
6718 | } | ||
6719 | switch(pass) | ||
6720 | { | ||
6721 | case LSCP_PRETTY_PRINT: | ||
6722 | fprintf(fp, "[ "); | ||
6723 | mExpressionList->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6724 | fprintf(fp, " ]"); | ||
6725 | break; | ||
6726 | case LSCP_EMIT_ASSEMBLY: | ||
6727 | count = 0; | ||
6728 | if (mExpressionList) | ||
6729 | { | ||
6730 | mExpressionList->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6731 | fprintf(fp, "STACKTOL %llu\n", count); | ||
6732 | } | ||
6733 | break; | ||
6734 | case LSCP_TYPE: | ||
6735 | if (mExpressionList) | ||
6736 | { | ||
6737 | mExpressionList->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6738 | mReturnType = type = LST_LIST; | ||
6739 | } | ||
6740 | mReturnType = type = LST_LIST; | ||
6741 | break; | ||
6742 | case LSCP_TO_STACK: | ||
6743 | if (mExpressionList) | ||
6744 | { | ||
6745 | pass = LSCP_TO_STACK; | ||
6746 | count = 0; | ||
6747 | mExpressionList->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6748 | chunk->addByte(LSCRIPTOpCodes[LOPC_STACKTOL]); | ||
6749 | chunk->addInteger((S32)count); | ||
6750 | count = 0; | ||
6751 | } | ||
6752 | else | ||
6753 | { | ||
6754 | chunk->addByte(LSCRIPTOpCodes[LOPC_STACKTOL]); | ||
6755 | chunk->addInteger(0); | ||
6756 | } | ||
6757 | break; | ||
6758 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
6759 | |||
6760 | // Push boxed elements on stack. | ||
6761 | count = 0; | ||
6762 | if (mExpressionList) | ||
6763 | { | ||
6764 | mExpressionList->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6765 | } | ||
6766 | |||
6767 | // Create list on stack, consuming first boxed element. | ||
6768 | fprintf(fp, "call class [mscorlib]System.Collections.ArrayList class [LScriptLibrary]LScriptInternal::CreateList()\n"); | ||
6769 | |||
6770 | // Call AddReturnList to add remaining boxed expressions. | ||
6771 | for(U64 i = 0; i < count; i++) | ||
6772 | { | ||
6773 | fprintf(fp, "call class [mscorlib]System.Collections.ArrayList class [LScriptLibrary]LScriptInternal::AddReturnList(object, class [mscorlib]System.Collections.ArrayList)\n"); | ||
6774 | } | ||
6775 | count = 0; | ||
6776 | |||
6777 | break; | ||
6778 | default: | ||
6779 | if (mExpressionList) | ||
6780 | { | ||
6781 | mExpressionList->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6782 | } | ||
6783 | break; | ||
6784 | } | ||
6785 | gonext(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6786 | } | ||
6787 | |||
6788 | S32 LLScriptListInitializer::getSize() | ||
6789 | { | ||
6790 | return 0; | ||
6791 | } | ||
6792 | |||
6793 | void LLScriptPostIncrement::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
6794 | { | ||
6795 | if (gErrorToText.getErrors()) | ||
6796 | { | ||
6797 | return; | ||
6798 | } | ||
6799 | switch(pass) | ||
6800 | { | ||
6801 | case LSCP_PRETTY_PRINT: | ||
6802 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6803 | fprintf(fp, "++"); | ||
6804 | break; | ||
6805 | case LSCP_EMIT_ASSEMBLY: | ||
6806 | { | ||
6807 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6808 | if (mReturnType == LST_INTEGER) | ||
6809 | { | ||
6810 | fprintf(fp, "PUSHARGI 1\n"); | ||
6811 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6812 | fprintf(fp, "ADD integer, integer\n"); | ||
6813 | } | ||
6814 | else if (mReturnType == LST_FLOATINGPOINT) | ||
6815 | { | ||
6816 | fprintf(fp, "PUSHARGF 1\n"); | ||
6817 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6818 | fprintf(fp, "ADD float, float\n"); | ||
6819 | } | ||
6820 | else | ||
6821 | { | ||
6822 | fprintf(fp, "Unexpected Type\n"); | ||
6823 | } | ||
6824 | print_asignment(fp, mExpression); | ||
6825 | fprintf(fp, "%s\n", LSCRIPTTypePop[mReturnType]); | ||
6826 | } | ||
6827 | break; | ||
6828 | case LSCP_TYPE: | ||
6829 | if (mExpression->mType != LET_LVALUE) | ||
6830 | { | ||
6831 | gErrorToText.writeError(fp, this, LSERROR_EXPRESSION_ON_LVALUE); | ||
6832 | } | ||
6833 | else | ||
6834 | { | ||
6835 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6836 | if (!legal_unary_expression(type, type, mType)) | ||
6837 | { | ||
6838 | gErrorToText.writeError(fp, this, LSERROR_TYPE_MISMATCH); | ||
6839 | } | ||
6840 | else | ||
6841 | { | ||
6842 | mReturnType = mLeftType = type; | ||
6843 | } | ||
6844 | } | ||
6845 | break; | ||
6846 | case LSCP_TO_STACK: | ||
6847 | { | ||
6848 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6849 | if (mReturnType == LST_INTEGER) | ||
6850 | { | ||
6851 | chunk->addByte(LSCRIPTOpCodes[LOPC_PUSHARGI]); | ||
6852 | chunk->addInteger(1); | ||
6853 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6854 | chunk->addByte(LSCRIPTOpCodes[LOPC_ADD]); | ||
6855 | chunk->addByte(LSCRIPTTypeByte[LST_INTEGER] | LSCRIPTTypeHi4Bits[LST_INTEGER]); | ||
6856 | } | ||
6857 | else if (mReturnType == LST_FLOATINGPOINT) | ||
6858 | { | ||
6859 | chunk->addByte(LSCRIPTOpCodes[LOPC_PUSHARGF]); | ||
6860 | chunk->addFloat(1.f); | ||
6861 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6862 | chunk->addByte(LSCRIPTOpCodes[LOPC_ADD]); | ||
6863 | chunk->addByte(LSCRIPTTypeByte[LST_FLOATINGPOINT] | LSCRIPTTypeHi4Bits[LST_FLOATINGPOINT]); | ||
6864 | } | ||
6865 | store2stack(this, mExpression, chunk, mReturnType); | ||
6866 | switch(mReturnType) | ||
6867 | { | ||
6868 | case LST_INTEGER: | ||
6869 | case LST_FLOATINGPOINT: | ||
6870 | chunk->addByte(LSCRIPTOpCodes[LOPC_POP]); | ||
6871 | break; | ||
6872 | case LST_KEY: | ||
6873 | case LST_STRING: | ||
6874 | chunk->addByte(LSCRIPTOpCodes[LOPC_POPS]); | ||
6875 | break; | ||
6876 | case LST_LIST: | ||
6877 | chunk->addByte(LSCRIPTOpCodes[LOPC_POPL]); | ||
6878 | break; | ||
6879 | case LST_VECTOR: | ||
6880 | chunk->addByte(LSCRIPTOpCodes[LOPC_POPV]); | ||
6881 | break; | ||
6882 | case LST_QUATERNION: | ||
6883 | chunk->addByte(LSCRIPTOpCodes[LOPC_POPQ]); | ||
6884 | break; | ||
6885 | default: | ||
6886 | chunk->addByte(LSCRIPTOpCodes[LOPC_POP]); | ||
6887 | break; | ||
6888 | } | ||
6889 | } | ||
6890 | break; | ||
6891 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
6892 | { | ||
6893 | print_cil_load_address(fp, mExpression, entry); | ||
6894 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6895 | fprintf(fp,"dup\n"); // Copy expression result to use as increment operand. | ||
6896 | if (mReturnType == LST_INTEGER) | ||
6897 | { | ||
6898 | fprintf(fp, "ldc.i4.1\n"); | ||
6899 | } | ||
6900 | else if (mReturnType == LST_FLOATINGPOINT) | ||
6901 | { | ||
6902 | fprintf(fp, "ldc.r8.1\n"); | ||
6903 | } | ||
6904 | else | ||
6905 | { | ||
6906 | fprintf(fp, "Unexpected Type\n"); | ||
6907 | } | ||
6908 | fprintf(fp, "add\n"); | ||
6909 | print_cil_asignment(fp, mExpression, entry); | ||
6910 | fprintf(fp, "pop\n"); // Pop assignment result to leave original expression result on stack. TODO: Optimise away redundant pop/dup pairs. | ||
6911 | } | ||
6912 | break; | ||
6913 | default: | ||
6914 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6915 | break; | ||
6916 | } | ||
6917 | gonext(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6918 | } | ||
6919 | |||
6920 | S32 LLScriptPostIncrement::getSize() | ||
6921 | { | ||
6922 | return 0; | ||
6923 | } | ||
6924 | |||
6925 | void LLScriptPostDecrement::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
6926 | { | ||
6927 | if (gErrorToText.getErrors()) | ||
6928 | { | ||
6929 | return; | ||
6930 | } | ||
6931 | switch(pass) | ||
6932 | { | ||
6933 | case LSCP_PRETTY_PRINT: | ||
6934 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6935 | fprintf(fp, "--"); | ||
6936 | break; | ||
6937 | case LSCP_EMIT_ASSEMBLY: | ||
6938 | { | ||
6939 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6940 | if (mReturnType == LST_INTEGER) | ||
6941 | { | ||
6942 | fprintf(fp, "PUSHARGI 1\n"); | ||
6943 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6944 | fprintf(fp, "SUB integer, integer\n"); | ||
6945 | } | ||
6946 | else if (mReturnType == LST_FLOATINGPOINT) | ||
6947 | { | ||
6948 | fprintf(fp, "PUSHARGF 1\n"); | ||
6949 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6950 | fprintf(fp, "SUB float, float\n"); | ||
6951 | } | ||
6952 | else | ||
6953 | { | ||
6954 | fprintf(fp, "Unexpected Type\n"); | ||
6955 | } | ||
6956 | print_asignment(fp, mExpression); | ||
6957 | fprintf(fp, "%s\n", LSCRIPTTypePop[mReturnType]); | ||
6958 | } | ||
6959 | break; | ||
6960 | case LSCP_TYPE: | ||
6961 | if (mExpression->mType != LET_LVALUE) | ||
6962 | { | ||
6963 | gErrorToText.writeError(fp, this, LSERROR_EXPRESSION_ON_LVALUE); | ||
6964 | } | ||
6965 | else | ||
6966 | { | ||
6967 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6968 | if (!legal_unary_expression(type, type, mType)) | ||
6969 | { | ||
6970 | gErrorToText.writeError(fp, this, LSERROR_TYPE_MISMATCH); | ||
6971 | } | ||
6972 | else | ||
6973 | { | ||
6974 | mReturnType = mLeftType = type; | ||
6975 | } | ||
6976 | } | ||
6977 | break; | ||
6978 | case LSCP_TO_STACK: | ||
6979 | { | ||
6980 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6981 | if (mReturnType == LST_INTEGER) | ||
6982 | { | ||
6983 | chunk->addByte(LSCRIPTOpCodes[LOPC_PUSHARGI]); | ||
6984 | chunk->addInteger(1); | ||
6985 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6986 | chunk->addByte(LSCRIPTOpCodes[LOPC_SUB]); | ||
6987 | chunk->addByte(LSCRIPTTypeByte[LST_INTEGER] | LSCRIPTTypeHi4Bits[LST_INTEGER]); | ||
6988 | } | ||
6989 | else if (mReturnType == LST_FLOATINGPOINT) | ||
6990 | { | ||
6991 | chunk->addByte(LSCRIPTOpCodes[LOPC_PUSHARGF]); | ||
6992 | chunk->addFloat(1.f); | ||
6993 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
6994 | chunk->addByte(LSCRIPTOpCodes[LOPC_SUB]); | ||
6995 | chunk->addByte(LSCRIPTTypeByte[LST_FLOATINGPOINT] | LSCRIPTTypeHi4Bits[LST_FLOATINGPOINT]); | ||
6996 | } | ||
6997 | store2stack(this, mExpression, chunk, mReturnType); | ||
6998 | switch(mReturnType) | ||
6999 | { | ||
7000 | case LST_INTEGER: | ||
7001 | case LST_FLOATINGPOINT: | ||
7002 | chunk->addByte(LSCRIPTOpCodes[LOPC_POP]); | ||
7003 | break; | ||
7004 | case LST_KEY: | ||
7005 | case LST_STRING: | ||
7006 | chunk->addByte(LSCRIPTOpCodes[LOPC_POPS]); | ||
7007 | break; | ||
7008 | case LST_LIST: | ||
7009 | chunk->addByte(LSCRIPTOpCodes[LOPC_POPL]); | ||
7010 | break; | ||
7011 | case LST_VECTOR: | ||
7012 | chunk->addByte(LSCRIPTOpCodes[LOPC_POPV]); | ||
7013 | break; | ||
7014 | case LST_QUATERNION: | ||
7015 | chunk->addByte(LSCRIPTOpCodes[LOPC_POPQ]); | ||
7016 | break; | ||
7017 | default: | ||
7018 | chunk->addByte(LSCRIPTOpCodes[LOPC_POP]); | ||
7019 | break; | ||
7020 | } | ||
7021 | } | ||
7022 | break; | ||
7023 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
7024 | { | ||
7025 | print_cil_load_address(fp, mExpression, entry); | ||
7026 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7027 | fprintf(fp,"dup\n"); // Copy expression result to use as decrement operand. | ||
7028 | if (mReturnType == LST_INTEGER) | ||
7029 | { | ||
7030 | fprintf(fp, "ldc.i4.1\n"); | ||
7031 | } | ||
7032 | else if (mReturnType == LST_FLOATINGPOINT) | ||
7033 | { | ||
7034 | fprintf(fp, "ldc.r8.1\n"); | ||
7035 | } | ||
7036 | else | ||
7037 | { | ||
7038 | fprintf(fp, "Unexpected Type\n"); | ||
7039 | } | ||
7040 | fprintf(fp, "sub\n"); | ||
7041 | print_cil_asignment(fp, mExpression, entry); | ||
7042 | fprintf(fp, "pop\n"); // Pop assignment result to leave original expression result on stack. TODO: Optimise away redundant pop/dup pairs. | ||
7043 | } | ||
7044 | break; | ||
7045 | default: | ||
7046 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7047 | break; | ||
7048 | } | ||
7049 | gonext(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7050 | } | ||
7051 | |||
7052 | S32 LLScriptPostDecrement::getSize() | ||
7053 | { | ||
7054 | return 0; | ||
7055 | } | ||
7056 | |||
7057 | // Generate arg list. | ||
7058 | void print_cil_arg_list(FILE *fp, LLScriptFuncExpressionList* exp_list) | ||
7059 | { | ||
7060 | // Print first argument. | ||
7061 | print_cil_type(fp, exp_list->mFirstp->mReturnType); | ||
7062 | |||
7063 | // Recursively print next arguments. | ||
7064 | if(exp_list->mSecondp != NULL) | ||
7065 | { | ||
7066 | fprintf(fp, ", "); | ||
7067 | print_cil_arg_list(fp, (LLScriptFuncExpressionList*) exp_list->mSecondp); | ||
7068 | } | ||
7069 | } | ||
7070 | |||
7071 | void LLScriptFunctionCall::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
7072 | { | ||
7073 | if (gErrorToText.getErrors()) | ||
7074 | { | ||
7075 | return; | ||
7076 | } | ||
7077 | switch(pass) | ||
7078 | { | ||
7079 | case LSCP_PRETTY_PRINT: | ||
7080 | mIdentifier->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7081 | fprintf(fp, "( "); | ||
7082 | if (mExpressionList) | ||
7083 | mExpressionList->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7084 | fprintf(fp, " )"); | ||
7085 | break; | ||
7086 | case LSCP_EMIT_ASSEMBLY: | ||
7087 | if (mIdentifier->mScopeEntry->mType) | ||
7088 | fprintf(fp, "%s\n", LSCRIPTTypePush[mIdentifier->mScopeEntry->mType]); | ||
7089 | fprintf(fp,"PUSHE\n"); | ||
7090 | fprintf(fp, "PUSHBP\n"); | ||
7091 | if (mExpressionList) | ||
7092 | mExpressionList->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, mIdentifier->mScopeEntry, 0, NULL); | ||
7093 | fprintf(fp, "PUSHARGE %d\n", mIdentifier->mScopeEntry->mSize - mIdentifier->mScopeEntry->mOffset); | ||
7094 | fprintf(fp, "PUSHSP\n"); | ||
7095 | fprintf(fp, "PUSHARGI %d\n", mIdentifier->mScopeEntry->mSize); | ||
7096 | fprintf(fp, "ADD integer, integer\n"); | ||
7097 | fprintf(fp, "POPBP\n"); | ||
7098 | if (mIdentifier->mScopeEntry->mIDType != LIT_LIBRARY_FUNCTION) | ||
7099 | { | ||
7100 | fprintf(fp, "CALL "); | ||
7101 | mIdentifier->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7102 | } | ||
7103 | else | ||
7104 | { | ||
7105 | fprintf(fp, "CALLLID "); | ||
7106 | mIdentifier->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7107 | fprintf(fp, ", %d", (U32)mIdentifier->mScopeEntry->mLibraryNumber); | ||
7108 | } | ||
7109 | fprintf(fp, "\n"); | ||
7110 | fprintf(fp, "POPBP\n"); | ||
7111 | break; | ||
7112 | case LSCP_SCOPE_PASS1: | ||
7113 | if (mExpressionList) | ||
7114 | mExpressionList->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7115 | break; | ||
7116 | case LSCP_SCOPE_PASS2: | ||
7117 | { | ||
7118 | LLScriptScopeEntry *entry = scope->findEntryTyped(mIdentifier->mName, LIT_FUNCTION); | ||
7119 | if (!entry) | ||
7120 | { | ||
7121 | gErrorToText.writeError(fp, this, LSERROR_UNDEFINED_NAME); | ||
7122 | } | ||
7123 | else | ||
7124 | { | ||
7125 | // if we did find it, make sure this identifier is associated with the correct scope entry | ||
7126 | mIdentifier->mScopeEntry = entry; | ||
7127 | } | ||
7128 | if (mExpressionList) | ||
7129 | mExpressionList->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7130 | } | ||
7131 | break; | ||
7132 | case LSCP_TYPE: | ||
7133 | if (mIdentifier->mScopeEntry) | ||
7134 | { | ||
7135 | U64 argcount = 0; | ||
7136 | if (mExpressionList) | ||
7137 | mExpressionList->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, argcount, chunk, heap, stacksize, mIdentifier->mScopeEntry, 0, NULL); | ||
7138 | |||
7139 | if (!mIdentifier->mScopeEntry->mFunctionArgs.mString) | ||
7140 | { | ||
7141 | if (argcount) | ||
7142 | { | ||
7143 | gErrorToText.writeError(fp, this, LSERROR_FUNCTION_TYPE_ERROR); | ||
7144 | } | ||
7145 | } | ||
7146 | else if (argcount != strlen(mIdentifier->mScopeEntry->mFunctionArgs.mString)) | ||
7147 | { | ||
7148 | gErrorToText.writeError(fp, this, LSERROR_FUNCTION_TYPE_ERROR); | ||
7149 | } | ||
7150 | } | ||
7151 | |||
7152 | if (mIdentifier->mScopeEntry) | ||
7153 | type = mIdentifier->mScopeEntry->mType; | ||
7154 | else | ||
7155 | type = LST_NULL; | ||
7156 | mReturnType = type; | ||
7157 | break; | ||
7158 | case LSCP_TO_STACK: | ||
7159 | switch(mIdentifier->mScopeEntry->mType) | ||
7160 | { | ||
7161 | case LST_INTEGER: | ||
7162 | case LST_FLOATINGPOINT: | ||
7163 | case LST_STRING: | ||
7164 | case LST_KEY: | ||
7165 | case LST_LIST: | ||
7166 | chunk->addByte(LSCRIPTOpCodes[LOPC_PUSHE]); | ||
7167 | break; | ||
7168 | case LST_VECTOR: | ||
7169 | chunk->addByte(LSCRIPTOpCodes[LOPC_PUSHEV]); | ||
7170 | break; | ||
7171 | case LST_QUATERNION: | ||
7172 | chunk->addByte(LSCRIPTOpCodes[LOPC_PUSHEQ]); | ||
7173 | break; | ||
7174 | default: | ||
7175 | break; | ||
7176 | } | ||
7177 | chunk->addByte(LSCRIPTOpCodes[LOPC_PUSHE]); | ||
7178 | chunk->addByte(LSCRIPTOpCodes[LOPC_PUSHBP]); | ||
7179 | if (mExpressionList) | ||
7180 | { | ||
7181 | // Don't let this change the count. | ||
7182 | U64 dummy_count = 0; | ||
7183 | mExpressionList->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, dummy_count, chunk, heap, stacksize, mIdentifier->mScopeEntry, 0, NULL); | ||
7184 | //mExpressionList->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, mIdentifier->mScopeEntry, 0, NULL); | ||
7185 | } | ||
7186 | chunk->addByte(LSCRIPTOpCodes[LOPC_PUSHARGE]); | ||
7187 | chunk->addInteger(mIdentifier->mScopeEntry->mSize - mIdentifier->mScopeEntry->mOffset); | ||
7188 | chunk->addByte(LSCRIPTOpCodes[LOPC_PUSHSP]); | ||
7189 | chunk->addByte(LSCRIPTOpCodes[LOPC_PUSHARGI]); | ||
7190 | chunk->addInteger(mIdentifier->mScopeEntry->mSize); | ||
7191 | chunk->addByte(LSCRIPTOpCodes[LOPC_ADD]); | ||
7192 | chunk->addByte(LSCRIPTTypeByte[LST_INTEGER] | LSCRIPTTypeHi4Bits[LST_INTEGER]); | ||
7193 | chunk->addByte(LSCRIPTOpCodes[LOPC_POPBP]); | ||
7194 | if (mIdentifier->mScopeEntry->mIDType != LIT_LIBRARY_FUNCTION) | ||
7195 | { | ||
7196 | chunk->addByte(LSCRIPTOpCodes[LOPC_CALL]); | ||
7197 | chunk->addInteger(mIdentifier->mScopeEntry->mCount); | ||
7198 | } | ||
7199 | else | ||
7200 | { | ||
7201 | chunk->addByte(LSCRIPTOpCodes[LOPC_CALLLIB_TWO_BYTE]); | ||
7202 | chunk->addU16(mIdentifier->mScopeEntry->mLibraryNumber); | ||
7203 | } | ||
7204 | break; | ||
7205 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
7206 | { | ||
7207 | bool library_call = (mIdentifier->mScopeEntry->mIDType == LIT_LIBRARY_FUNCTION); | ||
7208 | if(! library_call) | ||
7209 | { | ||
7210 | // Load this pointer. | ||
7211 | fprintf(fp, "ldarg.0\n"); | ||
7212 | } | ||
7213 | |||
7214 | // Load args on to stack. | ||
7215 | if (mExpressionList) | ||
7216 | { | ||
7217 | mExpressionList->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry /* Needed for is_parameter calls */, 0, NULL); | ||
7218 | } | ||
7219 | |||
7220 | // Make call. | ||
7221 | if (! library_call) | ||
7222 | { | ||
7223 | fprintf(fp, "callvirt instance "); | ||
7224 | } | ||
7225 | else | ||
7226 | { | ||
7227 | fprintf(fp, "call "); | ||
7228 | } | ||
7229 | print_cil_type(fp, mIdentifier->mScopeEntry->mType); | ||
7230 | fprintf(fp, " class "); | ||
7231 | if (library_call) | ||
7232 | { | ||
7233 | fprintf(fp, "[LScriptLibrary]LScriptLibrary"); | ||
7234 | } | ||
7235 | else | ||
7236 | { | ||
7237 | fprintf(fp, "LSL"); | ||
7238 | } | ||
7239 | fprintf(fp, "::"); | ||
7240 | mIdentifier->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7241 | fprintf(fp, "("); | ||
7242 | if (mExpressionList) {print_cil_arg_list(fp, (LLScriptFuncExpressionList*) mExpressionList);} | ||
7243 | fprintf(fp, ")\n"); | ||
7244 | } | ||
7245 | break; | ||
7246 | default: | ||
7247 | mIdentifier->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7248 | if (mExpressionList) | ||
7249 | mExpressionList->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7250 | break; | ||
7251 | } | ||
7252 | gonext(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7253 | } | ||
7254 | |||
7255 | S32 LLScriptFunctionCall::getSize() | ||
7256 | { | ||
7257 | return 0; | ||
7258 | } | ||
7259 | |||
7260 | void LLScriptPrint::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
7261 | { | ||
7262 | if (gErrorToText.getErrors()) | ||
7263 | { | ||
7264 | return; | ||
7265 | } | ||
7266 | switch(pass) | ||
7267 | { | ||
7268 | case LSCP_PRETTY_PRINT: | ||
7269 | fprintf(fp, " PRINT ( "); | ||
7270 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7271 | fprintf(fp, " )"); | ||
7272 | break; | ||
7273 | case LSCP_EMIT_ASSEMBLY: | ||
7274 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7275 | fprintf(fp, "PRINT %s\n", LSCRIPTTypeNames[mLeftType]); | ||
7276 | break; | ||
7277 | case LSCP_TYPE: | ||
7278 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7279 | mLeftType = type; | ||
7280 | mReturnType = LST_NULL; | ||
7281 | break; | ||
7282 | case LSCP_TO_STACK: | ||
7283 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7284 | chunk->addByte(LSCRIPTOpCodes[LOPC_PRINT]); | ||
7285 | chunk->addByte(LSCRIPTTypeByte[mLeftType]); | ||
7286 | break; | ||
7287 | default: | ||
7288 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7289 | break; | ||
7290 | } | ||
7291 | gonext(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7292 | } | ||
7293 | |||
7294 | S32 LLScriptPrint::getSize() | ||
7295 | { | ||
7296 | return 0; | ||
7297 | } | ||
7298 | |||
7299 | void LLScriptConstantExpression::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
7300 | { | ||
7301 | if (gErrorToText.getErrors()) | ||
7302 | { | ||
7303 | return; | ||
7304 | } | ||
7305 | switch(pass) | ||
7306 | { | ||
7307 | case LSCP_PRETTY_PRINT: | ||
7308 | mConstant->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7309 | break; | ||
7310 | case LSCP_TYPE: | ||
7311 | mConstant->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7312 | mReturnType = type; | ||
7313 | break; | ||
7314 | case LSCP_TO_STACK: | ||
7315 | mConstant->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7316 | break; | ||
7317 | default: | ||
7318 | mConstant->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7319 | break; | ||
7320 | } | ||
7321 | gonext(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7322 | } | ||
7323 | |||
7324 | S32 LLScriptConstantExpression::getSize() | ||
7325 | { | ||
7326 | return 0; | ||
7327 | } | ||
7328 | |||
7329 | void LLScriptStatement::addStatement(LLScriptStatement *event) | ||
7330 | { | ||
7331 | if (mNextp) | ||
7332 | { | ||
7333 | event->mNextp = mNextp; | ||
7334 | } | ||
7335 | mNextp = event; | ||
7336 | } | ||
7337 | |||
7338 | void LLScriptStatement::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
7339 | { | ||
7340 | fprintf(fp, "Statement Base Class -- should never get here!\n"); | ||
7341 | } | ||
7342 | |||
7343 | S32 LLScriptStatement::getSize() | ||
7344 | { | ||
7345 | printf("Statement Base Class -- should never get here!\n"); | ||
7346 | return 0; | ||
7347 | } | ||
7348 | |||
7349 | void LLScriptStatement::gonext(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
7350 | { | ||
7351 | if (gErrorToText.getErrors()) | ||
7352 | { | ||
7353 | return; | ||
7354 | } | ||
7355 | switch(pass) | ||
7356 | { | ||
7357 | case LSCP_PRETTY_PRINT: | ||
7358 | if (mNextp) | ||
7359 | { | ||
7360 | fprintf(fp, ", "); | ||
7361 | mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7362 | } | ||
7363 | break; | ||
7364 | case LSCP_EMIT_ASSEMBLY: | ||
7365 | if (mNextp) | ||
7366 | { | ||
7367 | mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7368 | } | ||
7369 | break; | ||
7370 | default: | ||
7371 | if (mNextp) | ||
7372 | { | ||
7373 | mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7374 | } | ||
7375 | break; | ||
7376 | } | ||
7377 | } | ||
7378 | |||
7379 | S32 LLScriptStatementSequence::getSize() | ||
7380 | { | ||
7381 | return 0; | ||
7382 | } | ||
7383 | |||
7384 | void LLScriptStatementSequence::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
7385 | { | ||
7386 | if (gErrorToText.getErrors()) | ||
7387 | { | ||
7388 | return; | ||
7389 | } | ||
7390 | switch(pass) | ||
7391 | { | ||
7392 | case LSCP_PRETTY_PRINT: | ||
7393 | mFirstp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7394 | mSecondp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7395 | break; | ||
7396 | case LSCP_EMIT_ASSEMBLY: | ||
7397 | mFirstp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7398 | mSecondp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7399 | break; | ||
7400 | case LSCP_PRUNE: | ||
7401 | mFirstp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7402 | if (prunearg) | ||
7403 | { | ||
7404 | ptype = LSPRUNE_DEAD_CODE; | ||
7405 | gErrorToText.writeWarning(fp, this, LSWARN_DEAD_CODE); | ||
7406 | } | ||
7407 | mSecondp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7408 | break; | ||
7409 | case LSCP_TYPE: | ||
7410 | // pass the return type into all statements so we can check returns | ||
7411 | { | ||
7412 | LSCRIPTType return_type = type; | ||
7413 | mFirstp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, return_type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7414 | return_type = type; | ||
7415 | mSecondp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, return_type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7416 | } | ||
7417 | break; | ||
7418 | default: | ||
7419 | mFirstp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7420 | mSecondp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7421 | break; | ||
7422 | } | ||
7423 | gonext(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7424 | } | ||
7425 | |||
7426 | S32 LLScriptNOOP::getSize() | ||
7427 | { | ||
7428 | return 0; | ||
7429 | } | ||
7430 | |||
7431 | void LLScriptNOOP::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
7432 | { | ||
7433 | if (gErrorToText.getErrors()) | ||
7434 | { | ||
7435 | return; | ||
7436 | } | ||
7437 | switch(pass) | ||
7438 | { | ||
7439 | case LSCP_PRETTY_PRINT: | ||
7440 | fdotabs(fp, tabs, tabsize); | ||
7441 | fprintf(fp, ";\n"); | ||
7442 | break; | ||
7443 | case LSCP_PRUNE: | ||
7444 | if (ptype == LSPRUNE_DEAD_CODE) | ||
7445 | prunearg = TRUE; | ||
7446 | else | ||
7447 | prunearg = FALSE; | ||
7448 | break; | ||
7449 | default: | ||
7450 | break; | ||
7451 | } | ||
7452 | gonext(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7453 | } | ||
7454 | |||
7455 | void add_exit_pops(LLScriptByteCodeChunk *chunk, LLScriptScopeEntry *entry) | ||
7456 | { | ||
7457 | // remember that we need to pop in reverse order | ||
7458 | S32 number, i; | ||
7459 | |||
7460 | if (entry->mLocals.mString) | ||
7461 | { | ||
7462 | number = (S32)strlen(entry->mLocals.mString); | ||
7463 | for (i = number - 1; i >= 0; i--) | ||
7464 | { | ||
7465 | switch(entry->mLocals.getType(i)) | ||
7466 | { | ||
7467 | case LST_INTEGER: | ||
7468 | chunk->addByte(LSCRIPTOpCodes[LOPC_POP]); | ||
7469 | break; | ||
7470 | case LST_FLOATINGPOINT: | ||
7471 | chunk->addByte(LSCRIPTOpCodes[LOPC_POP]); | ||
7472 | break; | ||
7473 | case LST_STRING: | ||
7474 | case LST_KEY: | ||
7475 | chunk->addByte(LSCRIPTOpCodes[LOPC_POPS]); | ||
7476 | break; | ||
7477 | case LST_VECTOR: | ||
7478 | chunk->addByte(LSCRIPTOpCodes[LOPC_POPV]); | ||
7479 | break; | ||
7480 | case LST_QUATERNION: | ||
7481 | chunk->addByte(LSCRIPTOpCodes[LOPC_POPQ]); | ||
7482 | break; | ||
7483 | case LST_LIST: | ||
7484 | chunk->addByte(LSCRIPTOpCodes[LOPC_POPL]); | ||
7485 | break; | ||
7486 | |||
7487 | default: | ||
7488 | break; | ||
7489 | } | ||
7490 | } | ||
7491 | } | ||
7492 | |||
7493 | if (entry->mFunctionArgs.mString) | ||
7494 | { | ||
7495 | number = (S32)strlen(entry->mFunctionArgs.mString); | ||
7496 | for (i = number - 1; i >= 0; i--) | ||
7497 | { | ||
7498 | switch(entry->mFunctionArgs.getType(i)) | ||
7499 | { | ||
7500 | case LST_INTEGER: | ||
7501 | chunk->addByte(LSCRIPTOpCodes[LOPC_POP]); | ||
7502 | break; | ||
7503 | case LST_FLOATINGPOINT: | ||
7504 | chunk->addByte(LSCRIPTOpCodes[LOPC_POP]); | ||
7505 | break; | ||
7506 | case LST_STRING: | ||
7507 | case LST_KEY: | ||
7508 | chunk->addByte(LSCRIPTOpCodes[LOPC_POPS]); | ||
7509 | break; | ||
7510 | case LST_VECTOR: | ||
7511 | chunk->addByte(LSCRIPTOpCodes[LOPC_POPV]); | ||
7512 | break; | ||
7513 | case LST_QUATERNION: | ||
7514 | chunk->addByte(LSCRIPTOpCodes[LOPC_POPQ]); | ||
7515 | break; | ||
7516 | case LST_LIST: | ||
7517 | chunk->addByte(LSCRIPTOpCodes[LOPC_POPL]); | ||
7518 | break; | ||
7519 | |||
7520 | default: | ||
7521 | break; | ||
7522 | } | ||
7523 | } | ||
7524 | } | ||
7525 | } | ||
7526 | |||
7527 | void print_exit_pops(FILE *fp, LLScriptScopeEntry *entry) | ||
7528 | { | ||
7529 | // remember that we need to pop in reverse order | ||
7530 | S32 number, i; | ||
7531 | |||
7532 | if (entry->mLocals.mString) | ||
7533 | { | ||
7534 | number = (S32)strlen(entry->mLocals.mString); | ||
7535 | for (i = number - 1; i >= 0; i--) | ||
7536 | { | ||
7537 | fprintf(fp, "%s", LSCRIPTTypePop[entry->mLocals.getType(i)]); | ||
7538 | } | ||
7539 | } | ||
7540 | |||
7541 | if (entry->mFunctionArgs.mString) | ||
7542 | { | ||
7543 | number = (S32)strlen(entry->mFunctionArgs.mString); | ||
7544 | for (i = number - 1; i >= 0; i--) | ||
7545 | { | ||
7546 | fprintf(fp, "%s", LSCRIPTTypePop[entry->mFunctionArgs.getType(i)]); | ||
7547 | } | ||
7548 | } | ||
7549 | } | ||
7550 | |||
7551 | |||
7552 | S32 LLScriptStateChange::getSize() | ||
7553 | { | ||
7554 | return 0; | ||
7555 | } | ||
7556 | |||
7557 | void LLScriptStateChange::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
7558 | { | ||
7559 | if (gErrorToText.getErrors()) | ||
7560 | { | ||
7561 | return; | ||
7562 | } | ||
7563 | switch(pass) | ||
7564 | { | ||
7565 | case LSCP_PRETTY_PRINT: | ||
7566 | fdotabs(fp, tabs, tabsize); | ||
7567 | fprintf(fp, "state "); | ||
7568 | mIdentifier->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7569 | fprintf(fp, ";\n"); | ||
7570 | break; | ||
7571 | case LSCP_EMIT_ASSEMBLY: | ||
7572 | print_exit_pops(fp, entry); | ||
7573 | fprintf(fp, "STATE "); | ||
7574 | mIdentifier->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7575 | fprintf(fp, "\n"); | ||
7576 | break; | ||
7577 | case LSCP_PRUNE: | ||
7578 | if ( (ptype == LSPRUNE_GLOBAL_VOIDS) | ||
7579 | ||(ptype == LSPRUNE_GLOBAL_NON_VOIDS)) | ||
7580 | { | ||
7581 | gErrorToText.writeError(fp, this, LSERROR_STATE_CHANGE_IN_GLOBAL); | ||
7582 | } | ||
7583 | if (ptype == LSPRUNE_DEAD_CODE) | ||
7584 | prunearg = TRUE; | ||
7585 | else | ||
7586 | prunearg = FALSE; | ||
7587 | break; | ||
7588 | case LSCP_SCOPE_PASS2: | ||
7589 | { | ||
7590 | LLScriptScopeEntry *entry = scope->findEntryTyped(mIdentifier->mName, LIT_STATE); | ||
7591 | if (!entry) | ||
7592 | { | ||
7593 | gErrorToText.writeError(fp, this, LSERROR_UNDEFINED_NAME); | ||
7594 | } | ||
7595 | else | ||
7596 | { | ||
7597 | // if we did find it, make sure this identifier is associated with the correct scope entry | ||
7598 | mIdentifier->mScopeEntry = entry; | ||
7599 | } | ||
7600 | } | ||
7601 | break; | ||
7602 | case LSCP_EMIT_BYTE_CODE: | ||
7603 | { | ||
7604 | add_exit_pops(chunk, entry); | ||
7605 | chunk->addByte(LSCRIPTOpCodes[LOPC_STATE]); | ||
7606 | chunk->addInteger(mIdentifier->mScopeEntry->mCount); | ||
7607 | } | ||
7608 | break; | ||
7609 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
7610 | fprintf(fp, "ldstr \""); | ||
7611 | mIdentifier->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7612 | fprintf(fp, "\"\n"); | ||
7613 | fprintf(fp, "call void class [LScriptLibrary]LScriptInternal::change_state(string)\n"); | ||
7614 | break; | ||
7615 | default: | ||
7616 | mIdentifier->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7617 | break; | ||
7618 | } | ||
7619 | gonext(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7620 | } | ||
7621 | |||
7622 | S32 LLScriptJump::getSize() | ||
7623 | { | ||
7624 | return 0; | ||
7625 | } | ||
7626 | |||
7627 | void LLScriptJump::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
7628 | { | ||
7629 | if (gErrorToText.getErrors()) | ||
7630 | { | ||
7631 | return; | ||
7632 | } | ||
7633 | switch(pass) | ||
7634 | { | ||
7635 | case LSCP_PRETTY_PRINT: | ||
7636 | fdotabs(fp, tabs, tabsize); | ||
7637 | fprintf(fp, "jump "); | ||
7638 | mIdentifier->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7639 | fprintf(fp, ";\n"); | ||
7640 | break; | ||
7641 | case LSCP_EMIT_ASSEMBLY: | ||
7642 | fprintf(fp, "JUMP "); | ||
7643 | mIdentifier->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7644 | fprintf(fp, "\n"); | ||
7645 | break; | ||
7646 | case LSCP_PRUNE: | ||
7647 | if (ptype == LSPRUNE_DEAD_CODE) | ||
7648 | prunearg = TRUE; | ||
7649 | else | ||
7650 | prunearg = FALSE; | ||
7651 | break; | ||
7652 | case LSCP_SCOPE_PASS2: | ||
7653 | { | ||
7654 | LLScriptScopeEntry *entry = scope->findEntryTyped(mIdentifier->mName, LIT_LABEL); | ||
7655 | if (!entry) | ||
7656 | { | ||
7657 | gErrorToText.writeError(fp, this, LSERROR_UNDEFINED_NAME); | ||
7658 | } | ||
7659 | else | ||
7660 | { | ||
7661 | // if we did find it, make sure this identifier is associated with the correct scope entry | ||
7662 | mIdentifier->mScopeEntry = entry; | ||
7663 | } | ||
7664 | } | ||
7665 | break; | ||
7666 | case LSCP_EMIT_BYTE_CODE: | ||
7667 | { | ||
7668 | chunk->addByte(LSCRIPTOpCodes[LOPC_JUMP]); | ||
7669 | chunk->addBytes(LSCRIPTDataSize[LST_INTEGER]); | ||
7670 | chunk->addJump(mIdentifier->mName); | ||
7671 | } | ||
7672 | break; | ||
7673 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
7674 | fprintf(fp, "br "); | ||
7675 | mIdentifier->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7676 | fprintf(fp, "\n"); | ||
7677 | break; | ||
7678 | default: | ||
7679 | mIdentifier->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7680 | break; | ||
7681 | } | ||
7682 | gonext(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7683 | } | ||
7684 | |||
7685 | S32 LLScriptLabel::getSize() | ||
7686 | { | ||
7687 | return 0; | ||
7688 | } | ||
7689 | |||
7690 | void LLScriptLabel::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
7691 | { | ||
7692 | if (gErrorToText.getErrors()) | ||
7693 | { | ||
7694 | return; | ||
7695 | } | ||
7696 | switch(pass) | ||
7697 | { | ||
7698 | case LSCP_PRETTY_PRINT: | ||
7699 | fdotabs(fp, tabs, tabsize); | ||
7700 | fprintf(fp, "@"); | ||
7701 | mIdentifier->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7702 | fprintf(fp, ";\n"); | ||
7703 | break; | ||
7704 | case LSCP_EMIT_ASSEMBLY: | ||
7705 | fprintf(fp, "LABEL "); | ||
7706 | mIdentifier->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7707 | fprintf(fp, "\n"); | ||
7708 | break; | ||
7709 | case LSCP_PRUNE: | ||
7710 | // Always clear this flag, to stop pruning after return statements. A jump | ||
7711 | // might start up code at this label, so we need to stop pruning. | ||
7712 | prunearg = FALSE; | ||
7713 | break; | ||
7714 | case LSCP_SCOPE_PASS1: | ||
7715 | // add labels to scope | ||
7716 | if (scope->checkEntry(mIdentifier->mName)) | ||
7717 | { | ||
7718 | gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME); | ||
7719 | } | ||
7720 | else | ||
7721 | { | ||
7722 | mIdentifier->mScopeEntry = scope->addEntry(mIdentifier->mName, LIT_LABEL, LST_NULL); | ||
7723 | } | ||
7724 | break; | ||
7725 | case LSCP_EMIT_BYTE_CODE: | ||
7726 | { | ||
7727 | chunk->addLabel(mIdentifier->mName); | ||
7728 | } | ||
7729 | break; | ||
7730 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
7731 | mIdentifier->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7732 | fprintf(fp, ":\n"); | ||
7733 | break; | ||
7734 | default: | ||
7735 | mIdentifier->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7736 | break; | ||
7737 | } | ||
7738 | gonext(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7739 | } | ||
7740 | |||
7741 | void add_return(LLScriptByteCodeChunk *chunk, LLScriptScopeEntry *entry) | ||
7742 | { | ||
7743 | add_exit_pops(chunk, entry); | ||
7744 | chunk->addByte(LSCRIPTOpCodes[LOPC_RETURN]); | ||
7745 | } | ||
7746 | |||
7747 | void print_return(FILE *fp, LLScriptScopeEntry *entry) | ||
7748 | { | ||
7749 | print_exit_pops(fp, entry); | ||
7750 | fprintf(fp, "RETURN\n"); | ||
7751 | } | ||
7752 | |||
7753 | |||
7754 | S32 LLScriptReturn::getSize() | ||
7755 | { | ||
7756 | return 0; | ||
7757 | } | ||
7758 | |||
7759 | void LLScriptReturn::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
7760 | { | ||
7761 | if (gErrorToText.getErrors()) | ||
7762 | { | ||
7763 | return; | ||
7764 | } | ||
7765 | switch(pass) | ||
7766 | { | ||
7767 | case LSCP_PRETTY_PRINT: | ||
7768 | if (mExpression) | ||
7769 | { | ||
7770 | fdotabs(fp, tabs, tabsize); | ||
7771 | fprintf(fp, "return "); | ||
7772 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7773 | fprintf(fp, ";\n"); | ||
7774 | } | ||
7775 | else | ||
7776 | { | ||
7777 | fdotabs(fp, tabs, tabsize); | ||
7778 | fprintf(fp, "return;\n"); | ||
7779 | } | ||
7780 | break; | ||
7781 | case LSCP_EMIT_ASSEMBLY: | ||
7782 | if (mExpression) | ||
7783 | { | ||
7784 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7785 | fprintf(fp, "%s\n", LSCRIPTTypeReturn[mType]); | ||
7786 | } | ||
7787 | print_return(fp, entry); | ||
7788 | break; | ||
7789 | case LSCP_PRUNE: | ||
7790 | if ( (ptype == LSPRUNE_GLOBAL_VOIDS) | ||
7791 | ||(ptype == LSPRUNE_EVENTS)) | ||
7792 | { | ||
7793 | if (mExpression) | ||
7794 | { | ||
7795 | gErrorToText.writeError(fp, this, LSERROR_INVALID_RETURN); | ||
7796 | } | ||
7797 | } | ||
7798 | else if (ptype == LSPRUNE_GLOBAL_NON_VOIDS) | ||
7799 | { | ||
7800 | if (!mExpression) | ||
7801 | { | ||
7802 | gErrorToText.writeError(fp, this, LSERROR_INVALID_VOID_RETURN); | ||
7803 | } | ||
7804 | } | ||
7805 | prunearg = TRUE; | ||
7806 | case LSCP_TYPE: | ||
7807 | // if there is a return expression, it must be promotable to the return type of the function | ||
7808 | if (mExpression) | ||
7809 | { | ||
7810 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7811 | if (!legal_assignment(basetype, type)) | ||
7812 | { | ||
7813 | gErrorToText.writeError(fp, this, LSERROR_TYPE_MISMATCH); | ||
7814 | } | ||
7815 | else | ||
7816 | { | ||
7817 | mType = basetype; | ||
7818 | } | ||
7819 | } | ||
7820 | break; | ||
7821 | case LSCP_EMIT_BYTE_CODE: | ||
7822 | if (mExpression) | ||
7823 | { | ||
7824 | mExpression->recurse(fp, tabs, tabsize, LSCP_TO_STACK, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7825 | switch(mType) | ||
7826 | { | ||
7827 | case LST_INTEGER: | ||
7828 | case LST_FLOATINGPOINT: | ||
7829 | chunk->addByte(LSCRIPTOpCodes[LOPC_LOADP]); | ||
7830 | chunk->addInteger(-12); | ||
7831 | break; | ||
7832 | case LST_STRING: | ||
7833 | case LST_KEY: | ||
7834 | // use normal store for reference counted types | ||
7835 | chunk->addByte(LSCRIPTOpCodes[LOPC_LOADSP]); | ||
7836 | chunk->addInteger(-12); | ||
7837 | break; | ||
7838 | case LST_LIST: | ||
7839 | // use normal store for reference counted types | ||
7840 | chunk->addByte(LSCRIPTOpCodes[LOPC_LOADLP]); | ||
7841 | chunk->addInteger(-12); | ||
7842 | break; | ||
7843 | case LST_VECTOR: | ||
7844 | chunk->addByte(LSCRIPTOpCodes[LOPC_LOADVP]); | ||
7845 | chunk->addInteger(-20); | ||
7846 | break; | ||
7847 | case LST_QUATERNION: | ||
7848 | chunk->addByte(LSCRIPTOpCodes[LOPC_LOADQP]); | ||
7849 | chunk->addInteger(-24); | ||
7850 | break; | ||
7851 | default: | ||
7852 | chunk->addByte(LSCRIPTOpCodes[LOPC_LOADP]); | ||
7853 | chunk->addInteger(-12); | ||
7854 | break; | ||
7855 | } | ||
7856 | } | ||
7857 | add_return(chunk, entry); | ||
7858 | break; | ||
7859 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
7860 | if (mExpression) | ||
7861 | { | ||
7862 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7863 | } | ||
7864 | fprintf(fp, "ret\n"); | ||
7865 | break; | ||
7866 | default: | ||
7867 | if (mExpression) | ||
7868 | { | ||
7869 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7870 | } | ||
7871 | break; | ||
7872 | } | ||
7873 | gonext(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7874 | } | ||
7875 | |||
7876 | S32 LLScriptExpressionStatement::getSize() | ||
7877 | { | ||
7878 | return 0; | ||
7879 | } | ||
7880 | |||
7881 | void LLScriptExpressionStatement::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
7882 | { | ||
7883 | if (gErrorToText.getErrors()) | ||
7884 | { | ||
7885 | return; | ||
7886 | } | ||
7887 | switch(pass) | ||
7888 | { | ||
7889 | case LSCP_PRETTY_PRINT: | ||
7890 | fdotabs(fp, tabs, tabsize); | ||
7891 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7892 | fprintf(fp, ";\n"); | ||
7893 | break; | ||
7894 | case LSCP_EMIT_ASSEMBLY: | ||
7895 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7896 | if (mExpression->mReturnType) | ||
7897 | { | ||
7898 | fprintf(fp, "%s\n", LSCRIPTTypePop[mExpression->mReturnType]); | ||
7899 | } | ||
7900 | break; | ||
7901 | case LSCP_PRUNE: | ||
7902 | if (ptype == LSPRUNE_DEAD_CODE) | ||
7903 | prunearg = TRUE; | ||
7904 | else | ||
7905 | prunearg = FALSE; | ||
7906 | break; | ||
7907 | case LSCP_EMIT_BYTE_CODE: | ||
7908 | mExpression->recurse(fp, tabs, tabsize, LSCP_TO_STACK, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7909 | switch(mExpression->mReturnType) | ||
7910 | { | ||
7911 | case LST_INTEGER: | ||
7912 | case LST_FLOATINGPOINT: | ||
7913 | chunk->addByte(LSCRIPTOpCodes[LOPC_POP]); | ||
7914 | break; | ||
7915 | case LST_STRING: | ||
7916 | case LST_KEY: | ||
7917 | chunk->addByte(LSCRIPTOpCodes[LOPC_POPS]); | ||
7918 | break; | ||
7919 | case LST_LIST: | ||
7920 | chunk->addByte(LSCRIPTOpCodes[LOPC_POPL]); | ||
7921 | break; | ||
7922 | case LST_VECTOR: | ||
7923 | chunk->addByte(LSCRIPTOpCodes[LOPC_POPV]); | ||
7924 | break; | ||
7925 | case LST_QUATERNION: | ||
7926 | chunk->addByte(LSCRIPTOpCodes[LOPC_POPQ]); | ||
7927 | break; | ||
7928 | default: | ||
7929 | break; | ||
7930 | } | ||
7931 | break; | ||
7932 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
7933 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7934 | if(mExpression->mReturnType) | ||
7935 | { | ||
7936 | fprintf(fp, "pop\n"); | ||
7937 | } | ||
7938 | break; | ||
7939 | default: | ||
7940 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7941 | break; | ||
7942 | } | ||
7943 | gonext(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7944 | } | ||
7945 | |||
7946 | S32 LLScriptIf::getSize() | ||
7947 | { | ||
7948 | return 0; | ||
7949 | } | ||
7950 | |||
7951 | void LLScriptIf::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
7952 | { | ||
7953 | if (gErrorToText.getErrors()) | ||
7954 | { | ||
7955 | return; | ||
7956 | } | ||
7957 | switch(pass) | ||
7958 | { | ||
7959 | case LSCP_PRETTY_PRINT: | ||
7960 | fdotabs(fp, tabs, tabsize); | ||
7961 | fprintf(fp, "if ( "); | ||
7962 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7963 | fprintf(fp, " )\n"); | ||
7964 | mStatement->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7965 | break; | ||
7966 | case LSCP_EMIT_ASSEMBLY: | ||
7967 | { | ||
7968 | S32 tjump = gTempJumpCount++; | ||
7969 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7970 | fprintf(fp, "JUMPNIF ##Temp Jump %d##\n", tjump); | ||
7971 | mStatement->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7972 | fprintf(fp, "LABEL ##Temp Jump %d##\n", tjump); | ||
7973 | } | ||
7974 | break; | ||
7975 | case LSCP_PRUNE: | ||
7976 | if (ptype == LSPRUNE_DEAD_CODE) | ||
7977 | prunearg = TRUE; | ||
7978 | else | ||
7979 | prunearg = FALSE; | ||
7980 | break; | ||
7981 | case LSCP_TYPE: | ||
7982 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7983 | mType = type; | ||
7984 | mStatement->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7985 | break; | ||
7986 | case LSCP_EMIT_BYTE_CODE: | ||
7987 | { | ||
7988 | char jumpname[32]; | ||
7989 | sprintf(jumpname, "##Temp Jump %d##", gTempJumpCount++); | ||
7990 | |||
7991 | mExpression->recurse(fp, tabs, tabsize, LSCP_TO_STACK, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7992 | chunk->addByte(LSCRIPTOpCodes[LOPC_JUMPNIF]); | ||
7993 | chunk->addByte(LSCRIPTTypeByte[mType]); | ||
7994 | chunk->addBytes(LSCRIPTDataSize[LST_INTEGER]); | ||
7995 | chunk->addJump(jumpname); | ||
7996 | mStatement->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
7997 | chunk->addLabel(jumpname); | ||
7998 | } | ||
7999 | break; | ||
8000 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
8001 | { | ||
8002 | S32 tjump = gTempJumpCount++; | ||
8003 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8004 | fprintf(fp, "brfalse LabelTempJump%d\n", tjump); | ||
8005 | mStatement->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8006 | fprintf(fp, "LabelTempJump%d:\n", tjump); | ||
8007 | } | ||
8008 | break; | ||
8009 | default: | ||
8010 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8011 | mStatement->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8012 | break; | ||
8013 | } | ||
8014 | gonext(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8015 | } | ||
8016 | |||
8017 | S32 LLScriptIfElse::getSize() | ||
8018 | { | ||
8019 | return 0; | ||
8020 | } | ||
8021 | |||
8022 | void LLScriptIfElse::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
8023 | { | ||
8024 | if (gErrorToText.getErrors()) | ||
8025 | { | ||
8026 | return; | ||
8027 | } | ||
8028 | switch(pass) | ||
8029 | { | ||
8030 | case LSCP_PRETTY_PRINT: | ||
8031 | fdotabs(fp, tabs, tabsize); | ||
8032 | fprintf(fp, "if ( "); | ||
8033 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8034 | fprintf(fp, " )\n"); | ||
8035 | mStatement1->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8036 | fdotabs(fp, tabs, tabsize); | ||
8037 | fprintf(fp, "else\n"); | ||
8038 | mStatement2->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8039 | break; | ||
8040 | case LSCP_EMIT_ASSEMBLY: | ||
8041 | { | ||
8042 | S32 tjump1 = gTempJumpCount++; | ||
8043 | S32 tjump2 = gTempJumpCount++; | ||
8044 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8045 | fprintf(fp, "JUMPNIF ##Temp Jump %d##\n", tjump1); | ||
8046 | mStatement1->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8047 | fprintf(fp, "JUMP ##Temp Jump %d##\n", tjump2); | ||
8048 | fprintf(fp, "LABEL ##Temp Jump %d##\n", tjump1); | ||
8049 | mStatement2->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8050 | fprintf(fp, "LABEL ##Temp Jump %d##\n", tjump2); | ||
8051 | } | ||
8052 | break; | ||
8053 | case LSCP_PRUNE: | ||
8054 | { | ||
8055 | BOOL arg1 = TRUE, arg2 = TRUE; | ||
8056 | mStatement1->recurse(fp, tabs, tabsize, pass, ptype, arg1, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8057 | mStatement2->recurse(fp, tabs, tabsize, pass, ptype, arg2, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8058 | prunearg = arg1 && arg2; | ||
8059 | } | ||
8060 | break; | ||
8061 | case LSCP_TYPE: | ||
8062 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8063 | mType = type; | ||
8064 | mStatement1->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8065 | mStatement2->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8066 | break; | ||
8067 | case LSCP_EMIT_BYTE_CODE: | ||
8068 | { | ||
8069 | char jumpname1[32]; | ||
8070 | sprintf(jumpname1, "##Temp Jump %d##", gTempJumpCount++); | ||
8071 | char jumpname2[32]; | ||
8072 | sprintf(jumpname2, "##Temp Jump %d##", gTempJumpCount++); | ||
8073 | |||
8074 | mExpression->recurse(fp, tabs, tabsize, LSCP_TO_STACK, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8075 | chunk->addByte(LSCRIPTOpCodes[LOPC_JUMPNIF]); | ||
8076 | chunk->addByte(LSCRIPTTypeByte[mType]); | ||
8077 | chunk->addBytes(LSCRIPTDataSize[LST_INTEGER]); | ||
8078 | chunk->addJump(jumpname1); | ||
8079 | mStatement1->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8080 | chunk->addByte(LSCRIPTOpCodes[LOPC_JUMP]); | ||
8081 | chunk->addBytes(LSCRIPTDataSize[LST_INTEGER]); | ||
8082 | chunk->addJump(jumpname2); | ||
8083 | chunk->addLabel(jumpname1); | ||
8084 | mStatement2->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8085 | chunk->addLabel(jumpname2); | ||
8086 | } | ||
8087 | break; | ||
8088 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
8089 | { | ||
8090 | S32 tjump1 = gTempJumpCount++; | ||
8091 | S32 tjump2 = gTempJumpCount++; | ||
8092 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8093 | fprintf(fp, "brfalse LabelTempJump%d\n", tjump1); | ||
8094 | mStatement1->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8095 | fprintf(fp, "br LabelTempJump%d\n", tjump2); | ||
8096 | fprintf(fp, "LabelTempJump%d:\n", tjump1); | ||
8097 | mStatement2->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8098 | fprintf(fp, "LabelTempJump%d:\n", tjump2); | ||
8099 | } | ||
8100 | break; | ||
8101 | default: | ||
8102 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8103 | mStatement1->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8104 | mStatement2->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8105 | break; | ||
8106 | }; | ||
8107 | gonext(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8108 | } | ||
8109 | |||
8110 | S32 LLScriptFor::getSize() | ||
8111 | { | ||
8112 | return 0; | ||
8113 | } | ||
8114 | |||
8115 | void LLScriptFor::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
8116 | { | ||
8117 | if (gErrorToText.getErrors()) | ||
8118 | { | ||
8119 | return; | ||
8120 | } | ||
8121 | switch(pass) | ||
8122 | { | ||
8123 | case LSCP_PRETTY_PRINT: | ||
8124 | fdotabs(fp, tabs, tabsize); | ||
8125 | fprintf(fp, "for ( "); | ||
8126 | if(mSequence) | ||
8127 | mSequence->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8128 | fprintf(fp, " ; "); | ||
8129 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8130 | fprintf(fp, " ; "); | ||
8131 | if(mExpressionList) | ||
8132 | mExpressionList->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8133 | fprintf(fp, " )\n"); | ||
8134 | if(mStatement) | ||
8135 | mStatement->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8136 | break; | ||
8137 | case LSCP_EMIT_ASSEMBLY: | ||
8138 | { | ||
8139 | S32 tjump1 = gTempJumpCount++; | ||
8140 | S32 tjump2 = gTempJumpCount++; | ||
8141 | if(mSequence) | ||
8142 | mSequence->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8143 | fprintf(fp, "LABEL ##Temp Jump %d##\n", tjump1); | ||
8144 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8145 | fprintf(fp, "JUMPNIF ##Temp Jump %d##\n", tjump2); | ||
8146 | if(mStatement) | ||
8147 | mStatement->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8148 | if(mExpressionList) | ||
8149 | mExpressionList->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8150 | fprintf(fp, "JUMP ##Temp Jump %d##\n", tjump1); | ||
8151 | fprintf(fp, "LABEL ##Temp Jump %d##\n", tjump2); | ||
8152 | } | ||
8153 | break; | ||
8154 | case LSCP_PRUNE: | ||
8155 | if (ptype == LSPRUNE_DEAD_CODE) | ||
8156 | prunearg = TRUE; | ||
8157 | else | ||
8158 | prunearg = FALSE; | ||
8159 | break; | ||
8160 | case LSCP_TYPE: | ||
8161 | if(mSequence) | ||
8162 | mSequence->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8163 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8164 | mType = type; | ||
8165 | if(mExpressionList) | ||
8166 | mExpressionList->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8167 | if(mStatement) | ||
8168 | mStatement->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8169 | break; | ||
8170 | case LSCP_EMIT_BYTE_CODE: | ||
8171 | { | ||
8172 | char jumpname1[32]; | ||
8173 | sprintf(jumpname1, "##Temp Jump %d##", gTempJumpCount++); | ||
8174 | char jumpname2[32]; | ||
8175 | sprintf(jumpname2, "##Temp Jump %d##", gTempJumpCount++); | ||
8176 | |||
8177 | if(mSequence) | ||
8178 | mSequence->recurse(fp, tabs, tabsize, LSCP_TO_STACK, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8179 | chunk->addLabel(jumpname1); | ||
8180 | mExpression->recurse(fp, tabs, tabsize, LSCP_TO_STACK, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8181 | chunk->addByte(LSCRIPTOpCodes[LOPC_JUMPNIF]); | ||
8182 | chunk->addByte(LSCRIPTTypeByte[mType]); | ||
8183 | chunk->addBytes(LSCRIPTDataSize[LST_INTEGER]); | ||
8184 | chunk->addJump(jumpname2); | ||
8185 | if(mStatement) | ||
8186 | mStatement->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8187 | if(mExpressionList) | ||
8188 | mExpressionList->recurse(fp, tabs, tabsize, LSCP_TO_STACK, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8189 | chunk->addByte(LSCRIPTOpCodes[LOPC_JUMP]); | ||
8190 | chunk->addBytes(LSCRIPTDataSize[LST_INTEGER]); | ||
8191 | chunk->addJump(jumpname1); | ||
8192 | chunk->addLabel(jumpname2); | ||
8193 | } | ||
8194 | break; | ||
8195 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
8196 | { | ||
8197 | S32 tjump1 = gTempJumpCount++; | ||
8198 | S32 tjump2 = gTempJumpCount++; | ||
8199 | if(mSequence) | ||
8200 | mSequence->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8201 | fprintf(fp, "LabelTempJump%d:\n", tjump1); | ||
8202 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8203 | fprintf(fp, "brfalse LabelTempJump%d\n", tjump2); | ||
8204 | if(mStatement) | ||
8205 | mStatement->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8206 | if(mExpressionList) | ||
8207 | mExpressionList->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8208 | fprintf(fp, "br LabelTempJump%d\n", tjump1); | ||
8209 | fprintf(fp, "LabelTempJump%d:\n", tjump2); | ||
8210 | } | ||
8211 | break; | ||
8212 | default: | ||
8213 | if(mSequence) | ||
8214 | mSequence->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8215 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8216 | if(mExpressionList) | ||
8217 | mExpressionList->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8218 | if(mStatement) | ||
8219 | mStatement->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8220 | break; | ||
8221 | } | ||
8222 | gonext(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8223 | } | ||
8224 | |||
8225 | S32 LLScriptDoWhile::getSize() | ||
8226 | { | ||
8227 | return 0; | ||
8228 | } | ||
8229 | |||
8230 | void LLScriptDoWhile::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
8231 | { | ||
8232 | if (gErrorToText.getErrors()) | ||
8233 | { | ||
8234 | return; | ||
8235 | } | ||
8236 | switch(pass) | ||
8237 | { | ||
8238 | case LSCP_PRETTY_PRINT: | ||
8239 | fdotabs(fp, tabs, tabsize); | ||
8240 | fprintf(fp, "do\n"); | ||
8241 | mStatement->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8242 | fdotabs(fp, tabs, tabsize); | ||
8243 | fprintf(fp, "while( "); | ||
8244 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8245 | fprintf(fp, " );\n"); | ||
8246 | break; | ||
8247 | case LSCP_EMIT_ASSEMBLY: | ||
8248 | { | ||
8249 | S32 tjump1 = gTempJumpCount++; | ||
8250 | fprintf(fp, "LABEL ##Temp Jump %d##\n", tjump1); | ||
8251 | mStatement->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8252 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8253 | fprintf(fp, "JUMPIF ##Temp Jump %d##\n", tjump1); | ||
8254 | } | ||
8255 | break; | ||
8256 | case LSCP_PRUNE: | ||
8257 | if (ptype == LSPRUNE_DEAD_CODE) | ||
8258 | prunearg = TRUE; | ||
8259 | else | ||
8260 | prunearg = FALSE; | ||
8261 | break; | ||
8262 | case LSCP_TYPE: | ||
8263 | mStatement->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8264 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8265 | mType = type; | ||
8266 | break; | ||
8267 | case LSCP_EMIT_BYTE_CODE: | ||
8268 | { | ||
8269 | char jumpname1[32]; | ||
8270 | sprintf(jumpname1, "##Temp Jump %d##", gTempJumpCount++); | ||
8271 | |||
8272 | chunk->addLabel(jumpname1); | ||
8273 | mStatement->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8274 | mExpression->recurse(fp, tabs, tabsize, LSCP_TO_STACK, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8275 | chunk->addByte(LSCRIPTOpCodes[LOPC_JUMPIF]); | ||
8276 | chunk->addByte(LSCRIPTTypeByte[mType]); | ||
8277 | chunk->addBytes(LSCRIPTDataSize[LST_INTEGER]); | ||
8278 | chunk->addJump(jumpname1); | ||
8279 | } | ||
8280 | break; | ||
8281 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
8282 | { | ||
8283 | S32 tjump1 = gTempJumpCount++; | ||
8284 | fprintf(fp, "LabelTempJump%d:\n", tjump1); | ||
8285 | mStatement->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8286 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8287 | fprintf(fp, "brtrue LabelTempJump%d\n", tjump1); | ||
8288 | } | ||
8289 | break; | ||
8290 | default: | ||
8291 | mStatement->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8292 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8293 | break; | ||
8294 | } | ||
8295 | gonext(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8296 | } | ||
8297 | |||
8298 | S32 LLScriptWhile::getSize() | ||
8299 | { | ||
8300 | return 0; | ||
8301 | } | ||
8302 | |||
8303 | void LLScriptWhile::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
8304 | { | ||
8305 | if (gErrorToText.getErrors()) | ||
8306 | { | ||
8307 | return; | ||
8308 | } | ||
8309 | switch(pass) | ||
8310 | { | ||
8311 | case LSCP_PRETTY_PRINT: | ||
8312 | fdotabs(fp, tabs, tabsize); | ||
8313 | fprintf(fp, "while( "); | ||
8314 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8315 | fprintf(fp, " )\n"); | ||
8316 | mStatement->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8317 | break; | ||
8318 | case LSCP_EMIT_ASSEMBLY: | ||
8319 | { | ||
8320 | S32 tjump1 = gTempJumpCount++; | ||
8321 | S32 tjump2 = gTempJumpCount++; | ||
8322 | fprintf(fp, "LABEL ##Temp Jump %d##\n", tjump1); | ||
8323 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8324 | fprintf(fp, "JUMPNIF ##Temp Jump %d##\n", tjump2); | ||
8325 | mStatement->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8326 | fprintf(fp, "JUMP ##Temp Jump %d##\n", tjump1); | ||
8327 | fprintf(fp, "LABEL ##Temp Jump %d##\n", tjump2); | ||
8328 | } | ||
8329 | break; | ||
8330 | case LSCP_PRUNE: | ||
8331 | if (ptype == LSPRUNE_DEAD_CODE) | ||
8332 | prunearg = TRUE; | ||
8333 | else | ||
8334 | prunearg = FALSE; | ||
8335 | break; | ||
8336 | case LSCP_TYPE: | ||
8337 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8338 | mType = type; | ||
8339 | mStatement->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8340 | break; | ||
8341 | case LSCP_EMIT_BYTE_CODE: | ||
8342 | { | ||
8343 | char jumpname1[32]; | ||
8344 | sprintf(jumpname1, "##Temp Jump %d##", gTempJumpCount++); | ||
8345 | char jumpname2[32]; | ||
8346 | sprintf(jumpname2, "##Temp Jump %d##", gTempJumpCount++); | ||
8347 | |||
8348 | chunk->addLabel(jumpname1); | ||
8349 | mExpression->recurse(fp, tabs, tabsize, LSCP_TO_STACK, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8350 | chunk->addByte(LSCRIPTOpCodes[LOPC_JUMPNIF]); | ||
8351 | chunk->addByte(LSCRIPTTypeByte[mType]); | ||
8352 | chunk->addBytes(LSCRIPTDataSize[LST_INTEGER]); | ||
8353 | chunk->addJump(jumpname2); | ||
8354 | mStatement->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8355 | chunk->addByte(LSCRIPTOpCodes[LOPC_JUMP]); | ||
8356 | chunk->addBytes(LSCRIPTDataSize[LST_INTEGER]); | ||
8357 | chunk->addJump(jumpname1); | ||
8358 | chunk->addLabel(jumpname2); | ||
8359 | } | ||
8360 | break; | ||
8361 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
8362 | { | ||
8363 | S32 tjump1 = gTempJumpCount++; | ||
8364 | S32 tjump2 = gTempJumpCount++; | ||
8365 | fprintf(fp, "LabelTempJump%d:\n", tjump1); | ||
8366 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8367 | fprintf(fp, "brfalse LabelTempJump%d\n", tjump2); | ||
8368 | mStatement->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8369 | fprintf(fp, "br LabelTempJump%d\n", tjump1); | ||
8370 | fprintf(fp, "LabelTempJump%d:\n", tjump2); | ||
8371 | } | ||
8372 | break; | ||
8373 | default: | ||
8374 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8375 | mStatement->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8376 | break; | ||
8377 | } | ||
8378 | gonext(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8379 | } | ||
8380 | |||
8381 | S32 LLScriptDeclaration::getSize() | ||
8382 | { | ||
8383 | return mType->getSize(); | ||
8384 | } | ||
8385 | |||
8386 | void LLScriptDeclaration::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
8387 | { | ||
8388 | if (gErrorToText.getErrors()) | ||
8389 | { | ||
8390 | return; | ||
8391 | } | ||
8392 | switch(pass) | ||
8393 | { | ||
8394 | case LSCP_PRETTY_PRINT: | ||
8395 | if (mExpression) | ||
8396 | { | ||
8397 | fdotabs(fp, tabs, tabsize); | ||
8398 | mType->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8399 | fprintf(fp, "\t"); | ||
8400 | mIdentifier->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8401 | fprintf(fp, " = "); | ||
8402 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8403 | fprintf(fp, ";\n"); | ||
8404 | } | ||
8405 | else | ||
8406 | { | ||
8407 | fdotabs(fp, tabs, tabsize); | ||
8408 | mType->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8409 | fprintf(fp, "\t"); | ||
8410 | mIdentifier->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8411 | fprintf(fp, ";\n"); | ||
8412 | } | ||
8413 | break; | ||
8414 | case LSCP_EMIT_ASSEMBLY: | ||
8415 | if (mExpression) | ||
8416 | { | ||
8417 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8418 | if (mIdentifier->mScopeEntry->mIDType == LIT_VARIABLE) | ||
8419 | { | ||
8420 | fprintf(fp, "%s%d [%s]\n", LSCRIPTTypeLocalDeclaration[mIdentifier->mScopeEntry->mType], mIdentifier->mScopeEntry->mOffset, mIdentifier->mName); | ||
8421 | } | ||
8422 | else if (mIdentifier->mScopeEntry->mIDType == LIT_GLOBAL) | ||
8423 | { | ||
8424 | gErrorToText.writeError(fp, this, LSERROR_UNDEFINED_NAME); | ||
8425 | } | ||
8426 | } | ||
8427 | break; | ||
8428 | case LSCP_PRUNE: | ||
8429 | if (ptype == LSPRUNE_DEAD_CODE) | ||
8430 | prunearg = TRUE; | ||
8431 | else | ||
8432 | prunearg = FALSE; | ||
8433 | break; | ||
8434 | case LSCP_SCOPE_PASS1: | ||
8435 | // Check to see if a declaration is valid here. | ||
8436 | if (!mAllowDeclarations) | ||
8437 | { | ||
8438 | gErrorToText.writeError(fp, this, LSERROR_NEED_NEW_SCOPE); | ||
8439 | } | ||
8440 | // add labels to scope | ||
8441 | else if (scope->checkEntry(mIdentifier->mName)) | ||
8442 | { | ||
8443 | gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME); | ||
8444 | } | ||
8445 | else | ||
8446 | { | ||
8447 | if (mExpression) | ||
8448 | { | ||
8449 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8450 | } | ||
8451 | // this needs to go after expression decent to make sure that we don't add ourselves or something silly | ||
8452 | // check expression if it exists | ||
8453 | mIdentifier->mScopeEntry = scope->addEntry(mIdentifier->mName, LIT_VARIABLE, mType->mType); | ||
8454 | } | ||
8455 | break; | ||
8456 | case LSCP_TYPE: | ||
8457 | // if there is an expression, it must be promotable to variable type | ||
8458 | if (mExpression && mIdentifier->mScopeEntry) | ||
8459 | { | ||
8460 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8461 | if (!legal_assignment(mIdentifier->mScopeEntry->mType, type)) | ||
8462 | { | ||
8463 | gErrorToText.writeError(fp, this, LSERROR_TYPE_MISMATCH); | ||
8464 | } | ||
8465 | } | ||
8466 | break; | ||
8467 | case LSCP_RESOURCE: | ||
8468 | { | ||
8469 | mIdentifier->mScopeEntry->mOffset = (S32)count; | ||
8470 | mIdentifier->mScopeEntry->mSize = mType->getSize(); | ||
8471 | count += mIdentifier->mScopeEntry->mSize; | ||
8472 | // Index into locals is current number of locals. Stored in mCount member of mScopeEntry. | ||
8473 | mIdentifier->mScopeEntry->mCount = entry->mLocals.getNumber(); | ||
8474 | entry->mLocals.addType(mType->mType); | ||
8475 | mIdentifier->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8476 | } | ||
8477 | break; | ||
8478 | case LSCP_EMIT_BYTE_CODE: | ||
8479 | if (mExpression) | ||
8480 | { | ||
8481 | mExpression->recurse(fp, tabs, tabsize, LSCP_TO_STACK, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8482 | if (mExpression->mReturnType != mIdentifier->mScopeEntry->mType) | ||
8483 | { | ||
8484 | cast2stack(chunk, mExpression->mReturnType, mIdentifier->mScopeEntry->mType); | ||
8485 | } | ||
8486 | switch(mExpression->mReturnType) | ||
8487 | { | ||
8488 | case LST_INTEGER: | ||
8489 | case LST_FLOATINGPOINT: | ||
8490 | if (mIdentifier->mScopeEntry->mIDType == LIT_VARIABLE) | ||
8491 | { | ||
8492 | chunk->addByte(LSCRIPTOpCodes[LOPC_LOADP]); | ||
8493 | } | ||
8494 | break; | ||
8495 | case LST_STRING: | ||
8496 | case LST_KEY: | ||
8497 | if (mIdentifier->mScopeEntry->mIDType == LIT_VARIABLE) | ||
8498 | { | ||
8499 | chunk->addByte(LSCRIPTOpCodes[LOPC_LOADSP]); | ||
8500 | } | ||
8501 | break; | ||
8502 | case LST_LIST: | ||
8503 | if (mIdentifier->mScopeEntry->mIDType == LIT_VARIABLE) | ||
8504 | { | ||
8505 | chunk->addByte(LSCRIPTOpCodes[LOPC_LOADLP]); | ||
8506 | } | ||
8507 | break; | ||
8508 | case LST_VECTOR: | ||
8509 | if (mIdentifier->mScopeEntry->mIDType == LIT_VARIABLE) | ||
8510 | { | ||
8511 | chunk->addByte(LSCRIPTOpCodes[LOPC_LOADVP]); | ||
8512 | } | ||
8513 | break; | ||
8514 | case LST_QUATERNION: | ||
8515 | if (mIdentifier->mScopeEntry->mIDType == LIT_VARIABLE) | ||
8516 | { | ||
8517 | chunk->addByte(LSCRIPTOpCodes[LOPC_LOADQP]); | ||
8518 | } | ||
8519 | break; | ||
8520 | default: | ||
8521 | if (mIdentifier->mScopeEntry->mIDType == LIT_VARIABLE) | ||
8522 | { | ||
8523 | chunk->addByte(LSCRIPTOpCodes[LOPC_LOADP]); | ||
8524 | } | ||
8525 | break; | ||
8526 | } | ||
8527 | if (mIdentifier->mScopeEntry->mIDType == LIT_VARIABLE) | ||
8528 | { | ||
8529 | S32 address = mIdentifier->mScopeEntry->mOffset; | ||
8530 | chunk->addInteger(address); | ||
8531 | } | ||
8532 | } | ||
8533 | else | ||
8534 | { | ||
8535 | switch(mIdentifier->mScopeEntry->mType) | ||
8536 | { | ||
8537 | case LST_INTEGER: | ||
8538 | case LST_FLOATINGPOINT: | ||
8539 | if (mIdentifier->mScopeEntry->mIDType == LIT_VARIABLE) | ||
8540 | { | ||
8541 | chunk->addByte(LSCRIPTOpCodes[LOPC_PUSHARGI]); | ||
8542 | chunk->addInteger(0); | ||
8543 | chunk->addByte(LSCRIPTOpCodes[LOPC_LOADP]); | ||
8544 | } | ||
8545 | break; | ||
8546 | case LST_STRING: | ||
8547 | case LST_KEY: | ||
8548 | if (mIdentifier->mScopeEntry->mIDType == LIT_VARIABLE) | ||
8549 | { | ||
8550 | chunk->addByte(LSCRIPTOpCodes[LOPC_PUSHARGS]); | ||
8551 | chunk->addBytes("", 1); | ||
8552 | chunk->addByte(LSCRIPTOpCodes[LOPC_LOADSP]); | ||
8553 | } | ||
8554 | break; | ||
8555 | case LST_LIST: | ||
8556 | if (mIdentifier->mScopeEntry->mIDType == LIT_VARIABLE) | ||
8557 | { | ||
8558 | chunk->addByte(LSCRIPTOpCodes[LOPC_STACKTOL]); | ||
8559 | chunk->addInteger(0); | ||
8560 | chunk->addByte(LSCRIPTOpCodes[LOPC_LOADLP]); | ||
8561 | } | ||
8562 | break; | ||
8563 | case LST_VECTOR: | ||
8564 | if (mIdentifier->mScopeEntry->mIDType == LIT_VARIABLE) | ||
8565 | { | ||
8566 | chunk->addByte(LSCRIPTOpCodes[LOPC_PUSHARGV]); | ||
8567 | chunk->addFloat(0); | ||
8568 | chunk->addFloat(0); | ||
8569 | chunk->addFloat(0); | ||
8570 | chunk->addByte(LSCRIPTOpCodes[LOPC_LOADVP]); | ||
8571 | } | ||
8572 | break; | ||
8573 | case LST_QUATERNION: | ||
8574 | if (mIdentifier->mScopeEntry->mIDType == LIT_VARIABLE) | ||
8575 | { | ||
8576 | chunk->addByte(LSCRIPTOpCodes[LOPC_PUSHARGQ]); | ||
8577 | chunk->addFloat(1); | ||
8578 | chunk->addFloat(0); | ||
8579 | chunk->addFloat(0); | ||
8580 | chunk->addFloat(0); | ||
8581 | chunk->addByte(LSCRIPTOpCodes[LOPC_LOADQP]); | ||
8582 | } | ||
8583 | break; | ||
8584 | default: | ||
8585 | if (mIdentifier->mScopeEntry->mIDType == LIT_VARIABLE) | ||
8586 | { | ||
8587 | chunk->addByte(LSCRIPTOpCodes[LOPC_PUSHARGI]); | ||
8588 | chunk->addInteger(0); | ||
8589 | chunk->addByte(LSCRIPTOpCodes[LOPC_LOADP]); | ||
8590 | } | ||
8591 | break; | ||
8592 | } | ||
8593 | if (mIdentifier->mScopeEntry->mIDType == LIT_VARIABLE) | ||
8594 | { | ||
8595 | S32 address = mIdentifier->mScopeEntry->mOffset; | ||
8596 | chunk->addInteger(address); | ||
8597 | } | ||
8598 | } | ||
8599 | break; | ||
8600 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
8601 | if (mExpression) | ||
8602 | { | ||
8603 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8604 | if (mIdentifier->mScopeEntry->mIDType == LIT_VARIABLE) | ||
8605 | { | ||
8606 | if(is_parameter(mIdentifier, entry)) | ||
8607 | { | ||
8608 | // Parameter, store by name. | ||
8609 | fprintf(fp, "starg.s %s\n", mIdentifier->mScopeEntry->mIdentifier); | ||
8610 | } | ||
8611 | else | ||
8612 | { | ||
8613 | // Local, store by index. | ||
8614 | fprintf(fp, "stloc.s %d\n", mIdentifier->mScopeEntry->mCount); | ||
8615 | } | ||
8616 | } | ||
8617 | else if (mIdentifier->mScopeEntry->mIDType == LIT_GLOBAL) | ||
8618 | { | ||
8619 | gErrorToText.writeError(fp, this, LSERROR_UNDEFINED_NAME); | ||
8620 | } | ||
8621 | } | ||
8622 | break; | ||
8623 | default: | ||
8624 | if (mExpression) | ||
8625 | { | ||
8626 | mType->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8627 | mIdentifier->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8628 | mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8629 | } | ||
8630 | else | ||
8631 | { | ||
8632 | mType->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8633 | mIdentifier->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8634 | } | ||
8635 | break; | ||
8636 | } | ||
8637 | gonext(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8638 | } | ||
8639 | |||
8640 | S32 LLScriptCompoundStatement::getSize() | ||
8641 | { | ||
8642 | return 0; | ||
8643 | } | ||
8644 | |||
8645 | void LLScriptCompoundStatement::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
8646 | { | ||
8647 | if (gErrorToText.getErrors()) | ||
8648 | { | ||
8649 | return; | ||
8650 | } | ||
8651 | switch(pass) | ||
8652 | { | ||
8653 | case LSCP_PRETTY_PRINT: | ||
8654 | if (mStatement) | ||
8655 | { | ||
8656 | fdotabs(fp, tabs, tabsize); | ||
8657 | fprintf(fp, "{\n"); | ||
8658 | mStatement->recurse(fp, tabs + 1, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8659 | fdotabs(fp, tabs, tabsize); | ||
8660 | fprintf(fp, "}\n"); | ||
8661 | } | ||
8662 | else | ||
8663 | { | ||
8664 | fdotabs(fp, tabs, tabsize); | ||
8665 | fprintf(fp, "{\n"); | ||
8666 | fdotabs(fp, tabs, tabsize); | ||
8667 | fprintf(fp, "}\n"); | ||
8668 | } | ||
8669 | break; | ||
8670 | case LSCP_EMIT_ASSEMBLY: | ||
8671 | if (mStatement) | ||
8672 | { | ||
8673 | mStatement->recurse(fp, tabs + 1, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8674 | } | ||
8675 | break; | ||
8676 | case LSCP_PRUNE: | ||
8677 | if (mStatement) | ||
8678 | { | ||
8679 | mStatement->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8680 | } | ||
8681 | else | ||
8682 | { | ||
8683 | prunearg = FALSE; | ||
8684 | } | ||
8685 | break; | ||
8686 | case LSCP_SCOPE_PASS1: | ||
8687 | // compound statements create a new scope | ||
8688 | if (mStatement) | ||
8689 | { | ||
8690 | mStatementScope = new LLScriptScope(gScopeStringTable); | ||
8691 | mStatementScope->addParentScope(scope); | ||
8692 | mStatement->recurse(fp, tabs, tabsize, pass, ptype, prunearg, mStatementScope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8693 | } | ||
8694 | break; | ||
8695 | case LSCP_SCOPE_PASS2: | ||
8696 | // compound statements create a new scope | ||
8697 | if (mStatement) | ||
8698 | { | ||
8699 | mStatement->recurse(fp, tabs, tabsize, pass, ptype, prunearg, mStatementScope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8700 | } | ||
8701 | break; | ||
8702 | default: | ||
8703 | if (mStatement) | ||
8704 | { | ||
8705 | mStatement->recurse(fp, tabs + 1, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8706 | } | ||
8707 | break; | ||
8708 | } | ||
8709 | gonext(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8710 | } | ||
8711 | |||
8712 | void LLScriptEventHandler::addEvent(LLScriptEventHandler *event) | ||
8713 | { | ||
8714 | if (mNextp) | ||
8715 | { | ||
8716 | event->mNextp = mNextp; | ||
8717 | } | ||
8718 | mNextp = event; | ||
8719 | } | ||
8720 | |||
8721 | void LLScriptEventHandler::gonext(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
8722 | { | ||
8723 | if (gErrorToText.getErrors()) | ||
8724 | { | ||
8725 | return; | ||
8726 | } | ||
8727 | switch(pass) | ||
8728 | { | ||
8729 | case LSCP_PRETTY_PRINT: | ||
8730 | if (mNextp) | ||
8731 | { | ||
8732 | mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8733 | } | ||
8734 | break; | ||
8735 | default: | ||
8736 | if (mNextp) | ||
8737 | { | ||
8738 | mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8739 | } | ||
8740 | break; | ||
8741 | } | ||
8742 | } | ||
8743 | |||
8744 | S32 LLScriptEventHandler::getSize() | ||
8745 | { | ||
8746 | return mStackSpace; | ||
8747 | } | ||
8748 | |||
8749 | U64 gCurrentHandler = 0; | ||
8750 | |||
8751 | void print_cil_local_init(FILE* fp, LLScriptScopeEntry* scopeEntry) | ||
8752 | { | ||
8753 | if(scopeEntry->mLocals.getNumber() > 0) | ||
8754 | { | ||
8755 | fprintf(fp, ".locals init ("); | ||
8756 | for(int local = 0; local < scopeEntry->mLocals.getNumber(); ++local) | ||
8757 | { | ||
8758 | if(local > 0) | ||
8759 | { | ||
8760 | fprintf(fp, ", "); | ||
8761 | } | ||
8762 | print_cil_type(fp, scopeEntry->mLocals.getType(local)); | ||
8763 | } | ||
8764 | fprintf(fp, ")\n"); | ||
8765 | } | ||
8766 | } | ||
8767 | |||
8768 | void LLScriptEventHandler::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
8769 | { | ||
8770 | if (gErrorToText.getErrors()) | ||
8771 | { | ||
8772 | return; | ||
8773 | } | ||
8774 | switch(pass) | ||
8775 | { | ||
8776 | case LSCP_PRETTY_PRINT: | ||
8777 | mEventp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8778 | if (mStatement) | ||
8779 | { | ||
8780 | mStatement->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8781 | } | ||
8782 | else | ||
8783 | { | ||
8784 | fdotabs(fp, tabs, tabsize); | ||
8785 | fprintf(fp, "{\n"); | ||
8786 | fdotabs(fp, tabs, tabsize); | ||
8787 | fprintf(fp, "}\n"); | ||
8788 | } | ||
8789 | break; | ||
8790 | case LSCP_EMIT_ASSEMBLY: | ||
8791 | mEventp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8792 | if (mStatement) | ||
8793 | { | ||
8794 | mStatement->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, getSize(), mScopeEntry, entrycount, NULL); | ||
8795 | } | ||
8796 | if (mbNeedTrailingReturn) | ||
8797 | { | ||
8798 | print_return(fp, mScopeEntry); | ||
8799 | } | ||
8800 | fprintf(fp, "\n"); | ||
8801 | break; | ||
8802 | case LSCP_PRUNE: | ||
8803 | mbNeedTrailingReturn = FALSE; | ||
8804 | prunearg = TRUE; | ||
8805 | mStatement->recurse(fp, tabs, tabsize, pass, LSPRUNE_EVENTS, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8806 | if (!prunearg) | ||
8807 | { | ||
8808 | // this means that we didn't end with a return statement, need to add one | ||
8809 | mbNeedTrailingReturn = TRUE; | ||
8810 | } | ||
8811 | break; | ||
8812 | case LSCP_SCOPE_PASS1: | ||
8813 | // create event level scope | ||
8814 | mEventScope = new LLScriptScope(gScopeStringTable); | ||
8815 | mEventScope->addParentScope(scope); | ||
8816 | |||
8817 | // add event parameters | ||
8818 | mEventp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, mEventScope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8819 | |||
8820 | mStatement->recurse(fp, tabs, tabsize, pass, ptype, prunearg, mEventScope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8821 | break; | ||
8822 | case LSCP_SCOPE_PASS2: | ||
8823 | mStatement->recurse(fp, tabs, tabsize, pass, ptype, prunearg, mEventScope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8824 | break; | ||
8825 | case LSCP_TYPE: | ||
8826 | mScopeEntry = new LLScriptScopeEntry("Event", LIT_HANDLER, LST_NULL); | ||
8827 | switch(mEventp->mType) | ||
8828 | { | ||
8829 | case LSTT_STATE_ENTRY: | ||
8830 | break; | ||
8831 | case LSTT_STATE_EXIT: | ||
8832 | break; | ||
8833 | case LSTT_TOUCH_START: | ||
8834 | mScopeEntry->mFunctionArgs.addType(LST_INTEGER); | ||
8835 | break; | ||
8836 | case LSTT_TOUCH: | ||
8837 | mScopeEntry->mFunctionArgs.addType(LST_INTEGER); | ||
8838 | break; | ||
8839 | case LSTT_TOUCH_END: | ||
8840 | mScopeEntry->mFunctionArgs.addType(LST_INTEGER); | ||
8841 | break; | ||
8842 | case LSTT_COLLISION_START: | ||
8843 | mScopeEntry->mFunctionArgs.addType(LST_INTEGER); | ||
8844 | break; | ||
8845 | case LSTT_COLLISION: | ||
8846 | mScopeEntry->mFunctionArgs.addType(LST_INTEGER); | ||
8847 | break; | ||
8848 | case LSTT_COLLISION_END: | ||
8849 | mScopeEntry->mFunctionArgs.addType(LST_INTEGER); | ||
8850 | break; | ||
8851 | case LSTT_LAND_COLLISION_START: | ||
8852 | mScopeEntry->mFunctionArgs.addType(LST_VECTOR); | ||
8853 | break; | ||
8854 | case LSTT_LAND_COLLISION: | ||
8855 | mScopeEntry->mFunctionArgs.addType(LST_VECTOR); | ||
8856 | break; | ||
8857 | case LSTT_LAND_COLLISION_END: | ||
8858 | mScopeEntry->mFunctionArgs.addType(LST_VECTOR); | ||
8859 | break; | ||
8860 | case LSTT_INVENTORY: | ||
8861 | mScopeEntry->mFunctionArgs.addType(LST_INTEGER); | ||
8862 | break; | ||
8863 | case LSTT_ATTACH: | ||
8864 | mScopeEntry->mFunctionArgs.addType(LST_KEY); | ||
8865 | break; | ||
8866 | case LSTT_DATASERVER: | ||
8867 | mScopeEntry->mFunctionArgs.addType(LST_KEY); | ||
8868 | mScopeEntry->mFunctionArgs.addType(LST_STRING); | ||
8869 | break; | ||
8870 | case LSTT_TIMER: | ||
8871 | break; | ||
8872 | case LSTT_MOVING_START: | ||
8873 | break; | ||
8874 | case LSTT_MOVING_END: | ||
8875 | break; | ||
8876 | case LSTT_OBJECT_REZ: | ||
8877 | mScopeEntry->mFunctionArgs.addType(LST_KEY); | ||
8878 | break; | ||
8879 | case LSTT_REMOTE_DATA: | ||
8880 | mScopeEntry->mFunctionArgs.addType(LST_INTEGER); | ||
8881 | mScopeEntry->mFunctionArgs.addType(LST_KEY); | ||
8882 | mScopeEntry->mFunctionArgs.addType(LST_KEY); | ||
8883 | mScopeEntry->mFunctionArgs.addType(LST_STRING); | ||
8884 | mScopeEntry->mFunctionArgs.addType(LST_INTEGER); | ||
8885 | mScopeEntry->mFunctionArgs.addType(LST_STRING); | ||
8886 | break; | ||
8887 | case LSTT_CHAT: | ||
8888 | mScopeEntry->mFunctionArgs.addType(LST_INTEGER); | ||
8889 | mScopeEntry->mFunctionArgs.addType(LST_STRING); | ||
8890 | mScopeEntry->mFunctionArgs.addType(LST_KEY); | ||
8891 | mScopeEntry->mFunctionArgs.addType(LST_STRING); | ||
8892 | break; | ||
8893 | case LSTT_SENSOR: | ||
8894 | mScopeEntry->mFunctionArgs.addType(LST_INTEGER); | ||
8895 | break; | ||
8896 | case LSTT_CONTROL: | ||
8897 | mScopeEntry->mFunctionArgs.addType(LST_KEY); | ||
8898 | mScopeEntry->mFunctionArgs.addType(LST_INTEGER); | ||
8899 | mScopeEntry->mFunctionArgs.addType(LST_INTEGER); | ||
8900 | break; | ||
8901 | case LSTT_LINK_MESSAGE: | ||
8902 | mScopeEntry->mFunctionArgs.addType(LST_INTEGER); | ||
8903 | mScopeEntry->mFunctionArgs.addType(LST_INTEGER); | ||
8904 | mScopeEntry->mFunctionArgs.addType(LST_STRING); | ||
8905 | mScopeEntry->mFunctionArgs.addType(LST_KEY); | ||
8906 | break; | ||
8907 | case LSTT_MONEY: | ||
8908 | mScopeEntry->mFunctionArgs.addType(LST_KEY); | ||
8909 | mScopeEntry->mFunctionArgs.addType(LST_INTEGER); | ||
8910 | break; | ||
8911 | case LSTT_EMAIL: | ||
8912 | mScopeEntry->mFunctionArgs.addType(LST_STRING); | ||
8913 | mScopeEntry->mFunctionArgs.addType(LST_STRING); | ||
8914 | mScopeEntry->mFunctionArgs.addType(LST_STRING); | ||
8915 | mScopeEntry->mFunctionArgs.addType(LST_STRING); | ||
8916 | mScopeEntry->mFunctionArgs.addType(LST_INTEGER); | ||
8917 | break; | ||
8918 | case LSTT_REZ: | ||
8919 | mScopeEntry->mFunctionArgs.addType(LST_INTEGER); | ||
8920 | break; | ||
8921 | case LSTT_NO_SENSOR: | ||
8922 | break; | ||
8923 | case LSTT_AT_TARGET: | ||
8924 | mScopeEntry->mFunctionArgs.addType(LST_INTEGER); | ||
8925 | mScopeEntry->mFunctionArgs.addType(LST_VECTOR); | ||
8926 | mScopeEntry->mFunctionArgs.addType(LST_VECTOR); | ||
8927 | break; | ||
8928 | case LSTT_NOT_AT_TARGET: | ||
8929 | break; | ||
8930 | case LSTT_AT_ROT_TARGET: | ||
8931 | mScopeEntry->mFunctionArgs.addType(LST_INTEGER); | ||
8932 | mScopeEntry->mFunctionArgs.addType(LST_QUATERNION); | ||
8933 | mScopeEntry->mFunctionArgs.addType(LST_QUATERNION); | ||
8934 | break; | ||
8935 | case LSTT_NOT_AT_ROT_TARGET: | ||
8936 | break; | ||
8937 | case LSTT_RTPERMISSIONS: | ||
8938 | mScopeEntry->mFunctionArgs.addType(LST_INTEGER); | ||
8939 | break; | ||
8940 | case LSTT_HTTP_RESPONSE: | ||
8941 | mScopeEntry->mFunctionArgs.addType(LST_KEY); | ||
8942 | mScopeEntry->mFunctionArgs.addType(LST_INTEGER); | ||
8943 | mScopeEntry->mFunctionArgs.addType(LST_LIST); | ||
8944 | mScopeEntry->mFunctionArgs.addType(LST_STRING); | ||
8945 | break; | ||
8946 | |||
8947 | default: | ||
8948 | break; | ||
8949 | } | ||
8950 | mStatement->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8951 | break; | ||
8952 | case LSCP_RESOURCE: | ||
8953 | // first determine resource counts for globals | ||
8954 | count = 0; | ||
8955 | mEventp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
8956 | if (mStatement) | ||
8957 | { | ||
8958 | entrycount = 0; | ||
8959 | mStatement->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, mScopeEntry, entrycount, NULL); | ||
8960 | fprintf(fp, "Function Args: %s\n", mScopeEntry->mFunctionArgs.mString); | ||
8961 | fprintf(fp, "Local List: %s\n", mScopeEntry->mLocals.mString); | ||
8962 | } | ||
8963 | mStackSpace = (S32)count; | ||
8964 | break; | ||
8965 | case LSCP_DETERMINE_HANDLERS: | ||
8966 | count |= LSCRIPTStateBitField[mEventp->mType]; | ||
8967 | break; | ||
8968 | case LSCP_EMIT_BYTE_CODE: | ||
8969 | { | ||
8970 | // order for event handler | ||
8971 | // set jump table value | ||
8972 | S32 jumpoffset; | ||
8973 | jumpoffset = LSCRIPTDataSize[LST_INTEGER]*get_event_handler_jump_position(gCurrentHandler, mEventp->mType)*2; | ||
8974 | |||
8975 | integer2bytestream(chunk->mCodeChunk, jumpoffset, chunk->mCurrentOffset); | ||
8976 | |||
8977 | // 0 - 3: offset to actual data | ||
8978 | S32 offsetoffset = chunk->mCurrentOffset; | ||
8979 | S32 offsetdelta = 0; | ||
8980 | chunk->addBytes(4); | ||
8981 | |||
8982 | // null terminated event name and null terminated parameters | ||
8983 | if (mEventp) | ||
8984 | { | ||
8985 | LLScriptByteCodeChunk *event = new LLScriptByteCodeChunk(FALSE); | ||
8986 | mEventp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, event, heap, stacksize, entry, entrycount, NULL); | ||
8987 | chunk->addBytes(event->mCodeChunk, event->mCurrentOffset); | ||
8988 | delete event; | ||
8989 | } | ||
8990 | chunk->addBytes(1); | ||
8991 | |||
8992 | // now we're at the first opcode | ||
8993 | offsetdelta = chunk->mCurrentOffset - offsetoffset; | ||
8994 | integer2bytestream(chunk->mCodeChunk, offsetoffset, offsetdelta); | ||
8995 | |||
8996 | // get ready to compute the number of bytes of opcode | ||
8997 | offsetdelta = chunk->mCurrentOffset; | ||
8998 | |||
8999 | if (mStatement) | ||
9000 | { | ||
9001 | LLScriptByteCodeChunk *statements = new LLScriptByteCodeChunk(TRUE); | ||
9002 | mStatement->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, statements, heap, getSize(), mScopeEntry, entrycount, NULL); | ||
9003 | statements->connectJumps(); | ||
9004 | chunk->addBytes(statements->mCodeChunk, statements->mCurrentOffset); | ||
9005 | delete statements; | ||
9006 | } | ||
9007 | if (mbNeedTrailingReturn) | ||
9008 | { | ||
9009 | add_return(chunk, mScopeEntry); | ||
9010 | } | ||
9011 | // now stuff in the number of bytes of stack space that this routine needs | ||
9012 | integer2bytestream(chunk->mCodeChunk, jumpoffset, getSize()); | ||
9013 | } | ||
9014 | break; | ||
9015 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
9016 | |||
9017 | // Method signature prefix. | ||
9018 | fprintf(fp, ".method public hidebysig instance default void "); | ||
9019 | |||
9020 | // Mangle event handler name by prefixing it with state name. Allows state changing by finding handlers prefixed with new state name. | ||
9021 | fprintf(fp, entry->mIdentifier); | ||
9022 | |||
9023 | // Handler name and arguments. | ||
9024 | mEventp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9025 | |||
9026 | // Method signature postfix. | ||
9027 | fprintf(fp, " cil managed\n"); | ||
9028 | |||
9029 | // Function header. | ||
9030 | fprintf(fp,"{\n"); | ||
9031 | fprintf(fp, ".maxstack 500\n"); // TODO: Calculated stack size... | ||
9032 | |||
9033 | // Allocate space for locals. | ||
9034 | print_cil_local_init(fp, mScopeEntry); | ||
9035 | |||
9036 | if (mStatement) | ||
9037 | { | ||
9038 | // Pass scope so identifiers can determine parameter or local. | ||
9039 | mStatement->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, mScopeEntry, entrycount, NULL); | ||
9040 | } | ||
9041 | |||
9042 | // Function footer. | ||
9043 | fprintf(fp, "\nret\n"); // TODO: Check whether return needed? | ||
9044 | fprintf(fp, "}\n"); | ||
9045 | |||
9046 | break; | ||
9047 | default: | ||
9048 | mEventp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9049 | if (mStatement) | ||
9050 | { | ||
9051 | mStatement->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9052 | } | ||
9053 | break; | ||
9054 | } | ||
9055 | gonext(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9056 | } | ||
9057 | |||
9058 | void LLScriptFunctionDec::addFunctionParameter(LLScriptFunctionDec *dec) | ||
9059 | { | ||
9060 | if (mNextp) | ||
9061 | { | ||
9062 | dec->mNextp = mNextp; | ||
9063 | } | ||
9064 | mNextp = dec; | ||
9065 | } | ||
9066 | |||
9067 | void LLScriptFunctionDec::gonext(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
9068 | { | ||
9069 | if (gErrorToText.getErrors()) | ||
9070 | { | ||
9071 | return; | ||
9072 | } | ||
9073 | switch(pass) | ||
9074 | { | ||
9075 | case LSCP_PRETTY_PRINT: | ||
9076 | if (mNextp) | ||
9077 | { | ||
9078 | fprintf(fp, ", "); | ||
9079 | mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9080 | } | ||
9081 | break; | ||
9082 | case LSCP_EMIT_ASSEMBLY: | ||
9083 | if (mNextp) | ||
9084 | { | ||
9085 | fprintf(fp, ", "); | ||
9086 | mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9087 | } | ||
9088 | break; | ||
9089 | default: | ||
9090 | if (mNextp) | ||
9091 | { | ||
9092 | mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9093 | } | ||
9094 | break; | ||
9095 | } | ||
9096 | |||
9097 | } | ||
9098 | |||
9099 | S32 LLScriptFunctionDec::getSize() | ||
9100 | { | ||
9101 | return 0; | ||
9102 | } | ||
9103 | |||
9104 | void LLScriptFunctionDec::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
9105 | { | ||
9106 | if (gErrorToText.getErrors()) | ||
9107 | { | ||
9108 | return; | ||
9109 | } | ||
9110 | switch(pass) | ||
9111 | { | ||
9112 | case LSCP_PRETTY_PRINT: | ||
9113 | fdotabs(fp, tabs, tabsize); | ||
9114 | mType->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9115 | fprintf(fp, " "); | ||
9116 | mIdentifier->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9117 | break; | ||
9118 | case LSCP_EMIT_ASSEMBLY: | ||
9119 | mType->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9120 | fprintf(fp, " "); | ||
9121 | mIdentifier->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9122 | break; | ||
9123 | case LSCP_SCOPE_PASS1: | ||
9124 | // add function names into global scope | ||
9125 | if (scope->checkEntry(mIdentifier->mName)) | ||
9126 | { | ||
9127 | gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME); | ||
9128 | } | ||
9129 | else | ||
9130 | { | ||
9131 | mIdentifier->mScopeEntry = scope->addEntry(mIdentifier->mName, LIT_VARIABLE, mType->mType); | ||
9132 | } | ||
9133 | break; | ||
9134 | case LSCP_RESOURCE: | ||
9135 | { | ||
9136 | // we're just tryng to determine how much space the variable needs | ||
9137 | mIdentifier->mScopeEntry->mOffset = (S32)count; | ||
9138 | mIdentifier->mScopeEntry->mSize = mType->getSize(); | ||
9139 | count += mIdentifier->mScopeEntry->mSize; | ||
9140 | } | ||
9141 | break; | ||
9142 | case LSCP_EMIT_BYTE_CODE: | ||
9143 | { | ||
9144 | // return type | ||
9145 | char typereturn; | ||
9146 | if (mType) | ||
9147 | { | ||
9148 | typereturn = LSCRIPTTypeByte[mType->mType]; | ||
9149 | } | ||
9150 | else | ||
9151 | { | ||
9152 | typereturn = LSCRIPTTypeByte[LST_NULL]; | ||
9153 | } | ||
9154 | chunk->addBytes(&typereturn, 1); | ||
9155 | // name | ||
9156 | #ifdef LSL_INCLUDE_DEBUG_INFO | ||
9157 | chunk->addBytes(mIdentifier->mName, strlen(mIdentifier->mName) + 1); | ||
9158 | #else | ||
9159 | chunk->addBytes(1); | ||
9160 | #endif | ||
9161 | } | ||
9162 | break; | ||
9163 | case LSCP_BUILD_FUNCTION_ARGS: | ||
9164 | { | ||
9165 | entry->mFunctionArgs.addType(mType->mType); | ||
9166 | } | ||
9167 | break; | ||
9168 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
9169 | mType->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9170 | fprintf(fp, " "); | ||
9171 | mIdentifier->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9172 | break; | ||
9173 | default: | ||
9174 | mType->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9175 | mIdentifier->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9176 | break; | ||
9177 | } | ||
9178 | gonext(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9179 | } | ||
9180 | |||
9181 | void LLScriptGlobalFunctions::addGlobalFunction(LLScriptGlobalFunctions *global) | ||
9182 | { | ||
9183 | if (mNextp) | ||
9184 | { | ||
9185 | global->mNextp = mNextp; | ||
9186 | } | ||
9187 | mNextp = global; | ||
9188 | } | ||
9189 | |||
9190 | void LLScriptGlobalFunctions::gonext(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
9191 | { | ||
9192 | if (gErrorToText.getErrors()) | ||
9193 | { | ||
9194 | return; | ||
9195 | } | ||
9196 | switch(pass) | ||
9197 | { | ||
9198 | case LSCP_PRETTY_PRINT: | ||
9199 | if (mNextp) | ||
9200 | { | ||
9201 | mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9202 | } | ||
9203 | break; | ||
9204 | default: | ||
9205 | if (mNextp) | ||
9206 | { | ||
9207 | mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9208 | } | ||
9209 | break; | ||
9210 | } | ||
9211 | } | ||
9212 | |||
9213 | S32 LLScriptGlobalFunctions::getSize() | ||
9214 | { | ||
9215 | return 0; | ||
9216 | } | ||
9217 | |||
9218 | void LLScriptGlobalFunctions::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
9219 | { | ||
9220 | if (gErrorToText.getErrors()) | ||
9221 | { | ||
9222 | return; | ||
9223 | } | ||
9224 | switch(pass) | ||
9225 | { | ||
9226 | case LSCP_PRETTY_PRINT: | ||
9227 | fdotabs(fp, tabs, tabsize); | ||
9228 | if (mType) | ||
9229 | { | ||
9230 | mType->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9231 | fprintf(fp, "\t"); | ||
9232 | } | ||
9233 | mIdentifier->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9234 | if (mParameters) | ||
9235 | { | ||
9236 | fprintf(fp, "( "); | ||
9237 | mParameters->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9238 | fprintf(fp, " )\n"); | ||
9239 | } | ||
9240 | else | ||
9241 | { | ||
9242 | fprintf(fp, "()\n"); | ||
9243 | } | ||
9244 | if (mStatements) | ||
9245 | { | ||
9246 | fdotabs(fp, tabs, tabsize); | ||
9247 | mStatements->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, mIdentifier->mScopeEntry, entrycount, NULL); | ||
9248 | } | ||
9249 | else | ||
9250 | { | ||
9251 | fdotabs(fp, tabs, tabsize); | ||
9252 | fprintf(fp, "{\n"); | ||
9253 | fdotabs(fp, tabs, tabsize); | ||
9254 | fprintf(fp, "}\n"); | ||
9255 | } | ||
9256 | break; | ||
9257 | case LSCP_EMIT_ASSEMBLY: | ||
9258 | mIdentifier->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9259 | if (mParameters) | ||
9260 | { | ||
9261 | fprintf(fp, "( "); | ||
9262 | mParameters->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9263 | fprintf(fp, " )\n"); | ||
9264 | } | ||
9265 | else | ||
9266 | { | ||
9267 | fprintf(fp, "()\n"); | ||
9268 | } | ||
9269 | if (mStatements) | ||
9270 | { | ||
9271 | mStatements->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, mIdentifier->mScopeEntry->mSize, mIdentifier->mScopeEntry, entrycount, NULL); | ||
9272 | } | ||
9273 | if (mbNeedTrailingReturn) | ||
9274 | { | ||
9275 | print_return(fp, mIdentifier->mScopeEntry); | ||
9276 | } | ||
9277 | fprintf(fp, "\n"); | ||
9278 | break; | ||
9279 | case LSCP_PRUNE: | ||
9280 | mbNeedTrailingReturn = FALSE; | ||
9281 | if (mType) | ||
9282 | { | ||
9283 | prunearg = TRUE; | ||
9284 | mStatements->recurse(fp, tabs, tabsize, pass, LSPRUNE_GLOBAL_NON_VOIDS, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9285 | if (!prunearg) | ||
9286 | { | ||
9287 | gErrorToText.writeError(fp, this, LSERROR_NO_RETURN); | ||
9288 | } | ||
9289 | } | ||
9290 | else | ||
9291 | { | ||
9292 | prunearg = TRUE; | ||
9293 | mStatements->recurse(fp, tabs, tabsize, pass, LSPRUNE_GLOBAL_VOIDS, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9294 | if (!prunearg) | ||
9295 | { | ||
9296 | // this means that we didn't end with a return statement, need to add one | ||
9297 | mbNeedTrailingReturn = TRUE; | ||
9298 | } | ||
9299 | } | ||
9300 | break; | ||
9301 | case LSCP_SCOPE_PASS1: | ||
9302 | // add function names into global scope | ||
9303 | if (scope->checkEntry(mIdentifier->mName)) | ||
9304 | { | ||
9305 | gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME); | ||
9306 | } | ||
9307 | else | ||
9308 | { | ||
9309 | if (mType) | ||
9310 | { | ||
9311 | mIdentifier->mScopeEntry = scope->addEntry(mIdentifier->mName, LIT_FUNCTION, mType->mType); | ||
9312 | } | ||
9313 | else | ||
9314 | { | ||
9315 | mIdentifier->mScopeEntry = scope->addEntry(mIdentifier->mName, LIT_FUNCTION, LST_NULL); | ||
9316 | } | ||
9317 | } | ||
9318 | |||
9319 | // create function level scope | ||
9320 | mFunctionScope = new LLScriptScope(gScopeStringTable); | ||
9321 | mFunctionScope->addParentScope(scope); | ||
9322 | |||
9323 | // function parameters | ||
9324 | if (mParameters) | ||
9325 | { | ||
9326 | mParameters->recurse(fp, tabs, tabsize, pass, ptype, prunearg, mFunctionScope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9327 | } | ||
9328 | |||
9329 | mStatements->recurse(fp, tabs, tabsize, pass, ptype, prunearg, mFunctionScope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9330 | break; | ||
9331 | case LSCP_SCOPE_PASS2: | ||
9332 | mStatements->recurse(fp, tabs, tabsize, pass, ptype, prunearg, mFunctionScope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9333 | |||
9334 | if (mParameters) | ||
9335 | { | ||
9336 | if (mIdentifier->mScopeEntry) | ||
9337 | { | ||
9338 | mParameters->recurse(fp, tabs, tabsize, LSCP_BUILD_FUNCTION_ARGS, ptype, prunearg, mFunctionScope, type, basetype, count, chunk, heap, stacksize, mIdentifier->mScopeEntry, 0, NULL); | ||
9339 | } | ||
9340 | } | ||
9341 | break; | ||
9342 | case LSCP_TYPE: | ||
9343 | if (mType) | ||
9344 | { | ||
9345 | mStatements->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, mType->mType, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9346 | } | ||
9347 | else | ||
9348 | { | ||
9349 | type = LST_NULL; | ||
9350 | mStatements->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9351 | } | ||
9352 | break; | ||
9353 | case LSCP_RESOURCE: | ||
9354 | // first determine resource counts for globals | ||
9355 | count = 0; | ||
9356 | |||
9357 | if (mParameters) | ||
9358 | { | ||
9359 | mParameters->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9360 | } | ||
9361 | |||
9362 | if (mIdentifier->mScopeEntry) | ||
9363 | { | ||
9364 | // this isn't a bug . . . Offset is used to determine how much is params vs locals | ||
9365 | mIdentifier->mScopeEntry->mOffset = (S32)count; | ||
9366 | } | ||
9367 | |||
9368 | if (mStatements) | ||
9369 | { | ||
9370 | entrycount = 0; | ||
9371 | mStatements->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, mIdentifier->mScopeEntry, entrycount, NULL); | ||
9372 | fprintf(fp, "Function Args: %s\n", mIdentifier->mScopeEntry->mFunctionArgs.mString); | ||
9373 | fprintf(fp, "Local List: %s\n", mIdentifier->mScopeEntry->mLocals.mString); | ||
9374 | if (mIdentifier->mScopeEntry) | ||
9375 | { | ||
9376 | mIdentifier->mScopeEntry->mSize = (S32)count; | ||
9377 | } | ||
9378 | } | ||
9379 | break; | ||
9380 | case LSCP_EMIT_BYTE_CODE: | ||
9381 | { | ||
9382 | // order for global functions | ||
9383 | // set jump table value | ||
9384 | S32 jumpoffset = LSCRIPTDataSize[LST_INTEGER]*mIdentifier->mScopeEntry->mCount + LSCRIPTDataSize[LST_INTEGER]; | ||
9385 | integer2bytestream(chunk->mCodeChunk, jumpoffset, chunk->mCurrentOffset); | ||
9386 | |||
9387 | // 0 - 3: offset to actual data | ||
9388 | S32 offsetoffset = chunk->mCurrentOffset; | ||
9389 | S32 offsetdelta = 0; | ||
9390 | chunk->addBytes(4); | ||
9391 | |||
9392 | // null terminated function name | ||
9393 | #ifdef LSL_INCLUDE_DEBUG_INFO | ||
9394 | chunk->addBytes(mIdentifier->mName, strlen(mIdentifier->mName) + 1); | ||
9395 | #else | ||
9396 | chunk->addBytes(1); | ||
9397 | #endif | ||
9398 | // return type | ||
9399 | char typereturn; | ||
9400 | if (mType) | ||
9401 | { | ||
9402 | typereturn = LSCRIPTTypeByte[mType->mType]; | ||
9403 | } | ||
9404 | else | ||
9405 | { | ||
9406 | typereturn = LSCRIPTTypeByte[LST_NULL]; | ||
9407 | } | ||
9408 | chunk->addBytes(&typereturn, 1); | ||
9409 | |||
9410 | // null terminated parameters, followed by type | ||
9411 | if (mParameters) | ||
9412 | { | ||
9413 | LLScriptByteCodeChunk *params = new LLScriptByteCodeChunk(FALSE); | ||
9414 | mParameters->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, params, heap, stacksize, entry, entrycount, NULL); | ||
9415 | chunk->addBytes(params->mCodeChunk, params->mCurrentOffset); | ||
9416 | delete params; | ||
9417 | } | ||
9418 | chunk->addBytes(1); | ||
9419 | |||
9420 | // now we're at the first opcode | ||
9421 | offsetdelta = chunk->mCurrentOffset - offsetoffset; | ||
9422 | integer2bytestream(chunk->mCodeChunk, offsetoffset, offsetdelta); | ||
9423 | |||
9424 | if (mStatements) | ||
9425 | { | ||
9426 | LLScriptByteCodeChunk *statements = new LLScriptByteCodeChunk(TRUE); | ||
9427 | mStatements->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, statements, heap, mIdentifier->mScopeEntry->mSize, mIdentifier->mScopeEntry, entrycount, NULL); | ||
9428 | statements->connectJumps(); | ||
9429 | chunk->addBytes(statements->mCodeChunk, statements->mCurrentOffset); | ||
9430 | delete statements; | ||
9431 | } | ||
9432 | if (mbNeedTrailingReturn) | ||
9433 | { | ||
9434 | add_return(chunk, mIdentifier->mScopeEntry); | ||
9435 | } | ||
9436 | } | ||
9437 | break; | ||
9438 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
9439 | { | ||
9440 | // Function header. | ||
9441 | fprintf(fp, ".method public hidebysig instance default "); | ||
9442 | print_cil_type(fp, mType ? mType->mType : LST_NULL); | ||
9443 | fprintf(fp, " "); | ||
9444 | mIdentifier->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9445 | if (mParameters) | ||
9446 | { | ||
9447 | fprintf(fp, "( "); | ||
9448 | mParameters->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9449 | fprintf(fp, " )"); | ||
9450 | } | ||
9451 | else | ||
9452 | { | ||
9453 | fprintf(fp, "()"); | ||
9454 | } | ||
9455 | fprintf(fp, " cil managed\n{\n"); | ||
9456 | fprintf(fp, ".maxstack 500\n"); // TODO: Calculated stack size... | ||
9457 | |||
9458 | // Allocate space for locals. | ||
9459 | print_cil_local_init(fp, mIdentifier->mScopeEntry); | ||
9460 | |||
9461 | if (mStatements) | ||
9462 | { | ||
9463 | mStatements->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, mIdentifier->mScopeEntry->mSize, mIdentifier->mScopeEntry, entrycount, NULL); | ||
9464 | } | ||
9465 | |||
9466 | // Function footer. | ||
9467 | if (mbNeedTrailingReturn) | ||
9468 | { | ||
9469 | fprintf(fp, "ret\n"); | ||
9470 | } | ||
9471 | fprintf(fp, "}\n"); | ||
9472 | fprintf(fp, "\n"); | ||
9473 | } | ||
9474 | break; | ||
9475 | default: | ||
9476 | if (mType) | ||
9477 | { | ||
9478 | mType->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9479 | } | ||
9480 | mIdentifier->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9481 | if (mParameters) | ||
9482 | { | ||
9483 | mParameters->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9484 | } | ||
9485 | if (mStatements) | ||
9486 | { | ||
9487 | mStatements->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9488 | } | ||
9489 | break; | ||
9490 | } | ||
9491 | gonext(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9492 | } | ||
9493 | |||
9494 | void LLScriptState::addState(LLScriptState *state) | ||
9495 | { | ||
9496 | if (mNextp) | ||
9497 | { | ||
9498 | state->mNextp = mNextp; | ||
9499 | } | ||
9500 | mNextp = state; | ||
9501 | } | ||
9502 | |||
9503 | void LLScriptState::gonext(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
9504 | { | ||
9505 | if (gErrorToText.getErrors()) | ||
9506 | { | ||
9507 | return; | ||
9508 | } | ||
9509 | switch(pass) | ||
9510 | { | ||
9511 | case LSCP_PRETTY_PRINT: | ||
9512 | if (mNextp) | ||
9513 | { | ||
9514 | mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9515 | } | ||
9516 | break; | ||
9517 | default: | ||
9518 | if (mNextp) | ||
9519 | { | ||
9520 | mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9521 | } | ||
9522 | break; | ||
9523 | } | ||
9524 | } | ||
9525 | |||
9526 | S32 LLScriptState::getSize() | ||
9527 | { | ||
9528 | return 0; | ||
9529 | } | ||
9530 | |||
9531 | void LLScriptState::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
9532 | { | ||
9533 | if (gErrorToText.getErrors()) | ||
9534 | { | ||
9535 | return; | ||
9536 | } | ||
9537 | switch(pass) | ||
9538 | { | ||
9539 | case LSCP_PRETTY_PRINT: | ||
9540 | fdotabs(fp, tabs, tabsize); | ||
9541 | if (mType == LSSTYPE_DEFAULT) | ||
9542 | { | ||
9543 | mIdentifier->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9544 | fprintf(fp, "\n"); | ||
9545 | fdotabs(fp, tabs, tabsize); | ||
9546 | fprintf(fp, "{\n"); | ||
9547 | } | ||
9548 | else | ||
9549 | { | ||
9550 | fprintf(fp, "state "); | ||
9551 | mIdentifier->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9552 | fprintf(fp, "\n"); | ||
9553 | fdotabs(fp, tabs, tabsize); | ||
9554 | fprintf(fp, "{\n"); | ||
9555 | } | ||
9556 | if (mEvent) | ||
9557 | { | ||
9558 | mEvent->recurse(fp, tabs + 1, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9559 | } | ||
9560 | fdotabs(fp, tabs, tabsize); | ||
9561 | fprintf(fp, "}\n"); | ||
9562 | break; | ||
9563 | case LSCP_EMIT_ASSEMBLY: | ||
9564 | mIdentifier->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9565 | fprintf(fp, ":\n"); | ||
9566 | if (mEvent) | ||
9567 | { | ||
9568 | fprintf(fp, "EVENTS\n"); | ||
9569 | mEvent->recurse(fp, tabs + 1, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9570 | fprintf(fp, "\n"); | ||
9571 | } | ||
9572 | break; | ||
9573 | case LSCP_SCOPE_PASS1: | ||
9574 | // add state name | ||
9575 | if (scope->checkEntry(mIdentifier->mName)) | ||
9576 | { | ||
9577 | gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME); | ||
9578 | } | ||
9579 | else | ||
9580 | { | ||
9581 | mIdentifier->mScopeEntry = scope->addEntry(mIdentifier->mName, LIT_STATE, LST_NULL); | ||
9582 | } | ||
9583 | // now do the events | ||
9584 | if (mEvent) | ||
9585 | { | ||
9586 | mEvent->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9587 | } | ||
9588 | break; | ||
9589 | case LSCP_SCOPE_PASS2: | ||
9590 | if (mEvent) | ||
9591 | { | ||
9592 | mEvent->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9593 | } | ||
9594 | break; | ||
9595 | case LSCP_TYPE: | ||
9596 | if (mEvent) | ||
9597 | { | ||
9598 | mEvent->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9599 | } | ||
9600 | break; | ||
9601 | case LSCP_EMIT_BYTE_CODE: | ||
9602 | { | ||
9603 | // order for states | ||
9604 | // set jump table value | ||
9605 | |||
9606 | S32 jumpoffset; | ||
9607 | if (LSL2_CURRENT_MAJOR_VERSION == LSL2_MAJOR_VERSION_TWO) | ||
9608 | { | ||
9609 | jumpoffset = LSCRIPTDataSize[LST_INTEGER]*3*mIdentifier->mScopeEntry->mCount + LSCRIPTDataSize[LST_INTEGER]; | ||
9610 | } | ||
9611 | else | ||
9612 | { | ||
9613 | jumpoffset = LSCRIPTDataSize[LST_INTEGER]*2*mIdentifier->mScopeEntry->mCount + LSCRIPTDataSize[LST_INTEGER]; | ||
9614 | } | ||
9615 | integer2bytestream(chunk->mCodeChunk, jumpoffset, chunk->mCurrentOffset); | ||
9616 | |||
9617 | // need to figure out what handlers this state has registered | ||
9618 | // we'll use to count to find it | ||
9619 | count = 0; | ||
9620 | |||
9621 | if (mEvent) | ||
9622 | { | ||
9623 | mEvent->recurse(fp, tabs, tabsize, LSCP_DETERMINE_HANDLERS, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9624 | gCurrentHandler = count; | ||
9625 | } | ||
9626 | |||
9627 | // add description word into chunk | ||
9628 | if (LSL2_CURRENT_MAJOR_VERSION == LSL2_MAJOR_VERSION_TWO) | ||
9629 | { | ||
9630 | u642bytestream(chunk->mCodeChunk, jumpoffset, gCurrentHandler); | ||
9631 | } | ||
9632 | else | ||
9633 | { | ||
9634 | integer2bytestream(chunk->mCodeChunk, jumpoffset, (S32)gCurrentHandler); | ||
9635 | } | ||
9636 | |||
9637 | |||
9638 | // 0 - 3: offset to event jump table | ||
9639 | S32 offsetoffset = chunk->mCurrentOffset; | ||
9640 | S32 offsetdelta = 0; | ||
9641 | chunk->addBytes(4); | ||
9642 | |||
9643 | // null terminated state name | ||
9644 | #ifdef LSL_INCLUDE_DEBUG_INFO | ||
9645 | chunk->addBytes(mIdentifier->mName, strlen(mIdentifier->mName) + 1); | ||
9646 | #else | ||
9647 | chunk->addBytes(1); | ||
9648 | #endif | ||
9649 | // now we're at the jump table | ||
9650 | offsetdelta = chunk->mCurrentOffset - offsetoffset; | ||
9651 | integer2bytestream(chunk->mCodeChunk, offsetoffset, offsetdelta); | ||
9652 | |||
9653 | // add the events themselves | ||
9654 | if (mEvent) | ||
9655 | { | ||
9656 | LLScriptByteCodeChunk *events = new LLScriptByteCodeChunk(FALSE); | ||
9657 | // make space for event jump table | ||
9658 | events->addBytes(LSCRIPTDataSize[LST_INTEGER]*get_number_of_event_handlers(gCurrentHandler)*2); | ||
9659 | mEvent->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, events, heap, stacksize, entry, entrycount, NULL); | ||
9660 | chunk->addBytes(events->mCodeChunk, events->mCurrentOffset); | ||
9661 | delete events; | ||
9662 | } | ||
9663 | } | ||
9664 | break; | ||
9665 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
9666 | if (mEvent) | ||
9667 | { | ||
9668 | // Entry not used at this level, so pass state scope as entry parameter, to allow event handlers to do name mangling. | ||
9669 | mEvent->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, mIdentifier->mScopeEntry, entrycount, NULL); | ||
9670 | } | ||
9671 | break; | ||
9672 | default: | ||
9673 | if (mType == LSSTYPE_DEFAULT) | ||
9674 | { | ||
9675 | } | ||
9676 | else | ||
9677 | { | ||
9678 | mIdentifier->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9679 | } | ||
9680 | if (mEvent) | ||
9681 | { | ||
9682 | mEvent->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9683 | } | ||
9684 | break; | ||
9685 | } | ||
9686 | gonext(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9687 | } | ||
9688 | |||
9689 | S32 LLScriptScript::getSize() | ||
9690 | { | ||
9691 | return 0; | ||
9692 | } | ||
9693 | |||
9694 | LLScriptScript::LLScriptScript(LLScritpGlobalStorage *globals, | ||
9695 | LLScriptState *states) : | ||
9696 | LLScriptFilePosition(0, 0), | ||
9697 | mStates(states), mGlobalScope(NULL), mGlobals(NULL), mGlobalFunctions(NULL), mGodLike(FALSE) | ||
9698 | { | ||
9699 | const char DEFAULT_BYTECODE_FILENAME[] = "lscript.lso"; | ||
9700 | strcpy(mBytecodeDest, DEFAULT_BYTECODE_FILENAME); | ||
9701 | |||
9702 | LLScriptGlobalVariable *tvar; | ||
9703 | LLScriptGlobalFunctions *tfunc; | ||
9704 | LLScritpGlobalStorage *temp; | ||
9705 | |||
9706 | temp = globals; | ||
9707 | while(temp) | ||
9708 | { | ||
9709 | if (temp->mbGlobalFunction) | ||
9710 | { | ||
9711 | if (!mGlobalFunctions) | ||
9712 | { | ||
9713 | mGlobalFunctions = (LLScriptGlobalFunctions *)temp->mGlobal; | ||
9714 | } | ||
9715 | else | ||
9716 | { | ||
9717 | tfunc = mGlobalFunctions; | ||
9718 | while(tfunc->mNextp) | ||
9719 | { | ||
9720 | tfunc = tfunc->mNextp; | ||
9721 | } | ||
9722 | tfunc->mNextp = (LLScriptGlobalFunctions *)temp->mGlobal; | ||
9723 | } | ||
9724 | } | ||
9725 | else | ||
9726 | { | ||
9727 | if (!mGlobals) | ||
9728 | { | ||
9729 | mGlobals = (LLScriptGlobalVariable *)temp->mGlobal; | ||
9730 | } | ||
9731 | else | ||
9732 | { | ||
9733 | tvar = mGlobals; | ||
9734 | while(tvar->mNextp) | ||
9735 | { | ||
9736 | tvar = tvar->mNextp; | ||
9737 | } | ||
9738 | tvar->mNextp = (LLScriptGlobalVariable *)temp->mGlobal; | ||
9739 | } | ||
9740 | } | ||
9741 | temp = temp->mNextp; | ||
9742 | } | ||
9743 | } | ||
9744 | |||
9745 | void LLScriptScript::setBytecodeDest(const char* dst_filename) | ||
9746 | { | ||
9747 | strncpy(mBytecodeDest, dst_filename, MAX_STRING); | ||
9748 | mBytecodeDest[MAX_STRING-1] = '\0'; | ||
9749 | } | ||
9750 | |||
9751 | void print_cil_globals(FILE* fp, LLScriptGlobalVariable* global) | ||
9752 | { | ||
9753 | fprintf(fp, ".field private "); | ||
9754 | print_cil_type(fp, global->mType->mType); | ||
9755 | fprintf(fp, " "); | ||
9756 | fprintf(fp, global->mIdentifier->mName); | ||
9757 | fprintf(fp, "\n"); | ||
9758 | if(NULL != global->mNextp) | ||
9759 | { | ||
9760 | print_cil_globals(fp, global->mNextp); | ||
9761 | } | ||
9762 | } | ||
9763 | |||
9764 | void LLScriptScript::recurse(FILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) | ||
9765 | { | ||
9766 | if (gErrorToText.getErrors()) | ||
9767 | { | ||
9768 | return; | ||
9769 | } | ||
9770 | switch(pass) | ||
9771 | { | ||
9772 | case LSCP_PRETTY_PRINT: | ||
9773 | if (mGlobals) | ||
9774 | { | ||
9775 | fdotabs(fp, tabs, tabsize); | ||
9776 | mGlobals->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9777 | } | ||
9778 | |||
9779 | if (mGlobalFunctions) | ||
9780 | { | ||
9781 | fdotabs(fp, tabs, tabsize); | ||
9782 | mGlobalFunctions->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9783 | } | ||
9784 | |||
9785 | fdotabs(fp, tabs, tabsize); | ||
9786 | mStates->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9787 | break; | ||
9788 | case LSCP_PRUNE: | ||
9789 | if (mGlobalFunctions) | ||
9790 | { | ||
9791 | mGlobalFunctions->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9792 | } | ||
9793 | mStates->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9794 | break; | ||
9795 | case LSCP_SCOPE_PASS1: | ||
9796 | { | ||
9797 | mGlobalScope = new LLScriptScope(gScopeStringTable); | ||
9798 | // zeroth, add library functions to global scope | ||
9799 | S32 i; | ||
9800 | char *arg; | ||
9801 | LLScriptScopeEntry *sentry; | ||
9802 | for (i = 0; i < gScriptLibrary.mNextNumber; i++) | ||
9803 | { | ||
9804 | // First, check to make sure this isn't a god only function, or that the viewer's agent is a god. | ||
9805 | if (!gScriptLibrary.mFunctions[i]->mGodOnly || mGodLike) | ||
9806 | { | ||
9807 | if (gScriptLibrary.mFunctions[i]->mReturnType) | ||
9808 | sentry = mGlobalScope->addEntry(gScriptLibrary.mFunctions[i]->mName, LIT_LIBRARY_FUNCTION, char2type(*gScriptLibrary.mFunctions[i]->mReturnType)); | ||
9809 | else | ||
9810 | sentry = mGlobalScope->addEntry(gScriptLibrary.mFunctions[i]->mName, LIT_LIBRARY_FUNCTION, LST_NULL); | ||
9811 | sentry->mLibraryNumber = i; | ||
9812 | arg = gScriptLibrary.mFunctions[i]->mArgs; | ||
9813 | if (arg) | ||
9814 | { | ||
9815 | while (*arg) | ||
9816 | { | ||
9817 | sentry->mFunctionArgs.addType(char2type(*arg)); | ||
9818 | sentry->mSize += LSCRIPTDataSize[char2type(*arg)]; | ||
9819 | sentry->mOffset += LSCRIPTDataSize[char2type(*arg)]; | ||
9820 | arg++; | ||
9821 | } | ||
9822 | } | ||
9823 | } | ||
9824 | } | ||
9825 | // first go and collect all the global variables | ||
9826 | if (mGlobals) | ||
9827 | mGlobals->recurse(fp, tabs, tabsize, pass, ptype, prunearg, mGlobalScope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9828 | // second, do the global functions | ||
9829 | if (mGlobalFunctions) | ||
9830 | mGlobalFunctions->recurse(fp, tabs, tabsize, pass, ptype, prunearg, mGlobalScope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9831 | // now do states | ||
9832 | mStates->recurse(fp, tabs, tabsize, pass, ptype, prunearg, mGlobalScope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9833 | break; | ||
9834 | } | ||
9835 | case LSCP_SCOPE_PASS2: | ||
9836 | // now we're checking jumps, function calls, and state transitions | ||
9837 | if (mGlobalFunctions) | ||
9838 | mGlobalFunctions->recurse(fp, tabs, tabsize, pass, ptype, prunearg, mGlobalScope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9839 | mStates->recurse(fp, tabs, tabsize, pass, ptype, prunearg, mGlobalScope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9840 | break; | ||
9841 | case LSCP_TYPE: | ||
9842 | // first we need to check global variables | ||
9843 | if (mGlobals) | ||
9844 | mGlobals->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9845 | // now do global functions and states | ||
9846 | if (mGlobalFunctions) | ||
9847 | mGlobalFunctions->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9848 | mStates->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9849 | break; | ||
9850 | case LSCP_RESOURCE: | ||
9851 | // first determine resource counts for globals | ||
9852 | count = 0; | ||
9853 | if (mGlobals) | ||
9854 | mGlobals->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9855 | // now do locals | ||
9856 | if (mGlobalFunctions) | ||
9857 | mGlobalFunctions->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9858 | mStates->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9859 | break; | ||
9860 | case LSCP_EMIT_ASSEMBLY: | ||
9861 | |||
9862 | if (mGlobals) | ||
9863 | { | ||
9864 | fprintf(fp, "GLOBALS\n"); | ||
9865 | fdotabs(fp, tabs, tabsize); | ||
9866 | mGlobals->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9867 | fprintf(fp, "\n"); | ||
9868 | } | ||
9869 | |||
9870 | if (mGlobalFunctions) | ||
9871 | { | ||
9872 | fprintf(fp, "GLOBAL FUNCTIONS\n"); | ||
9873 | fdotabs(fp, tabs, tabsize); | ||
9874 | mGlobalFunctions->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9875 | fprintf(fp, "\n"); | ||
9876 | } | ||
9877 | |||
9878 | fprintf(fp, "STATES\n"); | ||
9879 | fdotabs(fp, tabs, tabsize); | ||
9880 | mStates->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9881 | fprintf(fp, "\n"); | ||
9882 | break; | ||
9883 | case LSCP_EMIT_BYTE_CODE: | ||
9884 | { | ||
9885 | // first, create data structure to hold the whole shebang | ||
9886 | LLScriptScriptCodeChunk *code = new LLScriptScriptCodeChunk(TOP_OF_MEMORY); | ||
9887 | |||
9888 | // ok, let's add the registers, all zeroes for now | ||
9889 | S32 i; | ||
9890 | S32 nooffset = 0; | ||
9891 | |||
9892 | for (i = LREG_IP; i < LREG_EOF; i++) | ||
9893 | { | ||
9894 | if (i < LREG_NCE) | ||
9895 | code->mRegisters->addBytes(4); | ||
9896 | else if (LSL2_CURRENT_MAJOR_VERSION == LSL2_MAJOR_VERSION_TWO) | ||
9897 | code->mRegisters->addBytes(8); | ||
9898 | } | ||
9899 | // global variables | ||
9900 | if (mGlobals) | ||
9901 | mGlobals->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, code->mGlobalVariables, code->mHeap, stacksize, entry, entrycount, NULL); | ||
9902 | |||
9903 | // put the ending heap block onto the heap | ||
9904 | U8 *temp; | ||
9905 | S32 size = lsa_create_data_block(&temp, NULL, 0); | ||
9906 | code->mHeap->addBytes(temp, size); | ||
9907 | delete [] temp; | ||
9908 | |||
9909 | // global functions | ||
9910 | // make space for global function jump table | ||
9911 | if (mGlobalFunctions) | ||
9912 | { | ||
9913 | code->mGlobalFunctions->addBytes(LSCRIPTDataSize[LST_INTEGER]*mGlobalScope->mFunctionCount + LSCRIPTDataSize[LST_INTEGER]); | ||
9914 | integer2bytestream(code->mGlobalFunctions->mCodeChunk, nooffset, mGlobalScope->mFunctionCount); | ||
9915 | mGlobalFunctions->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, code->mGlobalFunctions, NULL, stacksize, entry, entrycount, NULL); | ||
9916 | } | ||
9917 | |||
9918 | |||
9919 | nooffset = 0; | ||
9920 | // states | ||
9921 | // make space for state jump/info table | ||
9922 | if (LSL2_CURRENT_MAJOR_VERSION == LSL2_MAJOR_VERSION_TWO) | ||
9923 | { | ||
9924 | code->mStates->addBytes(LSCRIPTDataSize[LST_INTEGER]*3*mGlobalScope->mStateCount + LSCRIPTDataSize[LST_INTEGER]); | ||
9925 | } | ||
9926 | else | ||
9927 | { | ||
9928 | code->mStates->addBytes(LSCRIPTDataSize[LST_INTEGER]*2*mGlobalScope->mStateCount + LSCRIPTDataSize[LST_INTEGER]); | ||
9929 | } | ||
9930 | integer2bytestream(code->mStates->mCodeChunk, nooffset, mGlobalScope->mStateCount); | ||
9931 | mStates->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, code->mStates, NULL, stacksize, entry, entrycount, NULL); | ||
9932 | |||
9933 | // now, put it all together and spit it out | ||
9934 | // we need | ||
9935 | FILE *bcfp = LLFile::fopen(mBytecodeDest, "wb"); | ||
9936 | |||
9937 | code->build(fp, bcfp); | ||
9938 | fclose(bcfp); | ||
9939 | } | ||
9940 | break; | ||
9941 | case LSCP_EMIT_CIL_ASSEMBLY: | ||
9942 | |||
9943 | // Output dependencies. | ||
9944 | fprintf(fp, ".assembly extern mscorlib {.ver 1:0:5000:0}\n"); | ||
9945 | fprintf(fp, ".assembly extern LScriptLibrary {.ver 0:0:0:0}\n"); | ||
9946 | |||
9947 | // Output assembly name. | ||
9948 | fprintf(fp, ".assembly 'lsl' {.ver 0:0:0:0}\n"); | ||
9949 | |||
9950 | // Output class header. | ||
9951 | fprintf(fp, ".class public auto ansi beforefieldinit LSL extends [mscorlib]System.Object\n"); | ||
9952 | fprintf(fp, "{\n"); | ||
9953 | |||
9954 | // Output globals as members. | ||
9955 | if(NULL != mGlobals) | ||
9956 | { | ||
9957 | print_cil_globals(fp, mGlobals); | ||
9958 | } | ||
9959 | |||
9960 | // Output "runtime". Only needed to allow stand alone execution. Not needed when compiling to DLL and using embedded runtime. | ||
9961 | fprintf(fp, ".method public static hidebysig default void Main () cil managed\n"); | ||
9962 | fprintf(fp, "{\n"); | ||
9963 | fprintf(fp, ".entrypoint\n"); | ||
9964 | fprintf(fp, ".maxstack 2\n"); | ||
9965 | fprintf(fp, ".locals init (class LSL V_0)\n"); | ||
9966 | fprintf(fp, "newobj instance void class LSL::.ctor()\n"); | ||
9967 | fprintf(fp, "stloc.0\n"); | ||
9968 | fprintf(fp, "ldloc.0\n"); | ||
9969 | fprintf(fp, "callvirt instance void class LSL::defaultstate_entry()\n"); | ||
9970 | fprintf(fp, "ret\n"); | ||
9971 | fprintf(fp, "}\n"); | ||
9972 | |||
9973 | // Output ctor header. | ||
9974 | fprintf(fp, ".method public hidebysig specialname rtspecialname instance default void .ctor () cil managed\n"); | ||
9975 | fprintf(fp, "{\n"); | ||
9976 | fprintf(fp, ".maxstack 500\n"); | ||
9977 | |||
9978 | // Initialise globals as members in ctor. | ||
9979 | if (mGlobals) | ||
9980 | { | ||
9981 | fdotabs(fp, tabs, tabsize); | ||
9982 | mGlobals->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9983 | fprintf(fp, "\n"); | ||
9984 | } | ||
9985 | |||
9986 | // Output ctor footer. | ||
9987 | fprintf(fp, "ldarg.0\n"); | ||
9988 | fprintf(fp, "call instance void valuetype [mscorlib]System.Object::.ctor()\n"); | ||
9989 | fprintf(fp, "ret\n"); | ||
9990 | fprintf(fp, "}\n"); | ||
9991 | |||
9992 | // Output functions as methods. | ||
9993 | if (mGlobalFunctions) | ||
9994 | { | ||
9995 | fdotabs(fp, tabs, tabsize); | ||
9996 | mGlobalFunctions->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
9997 | fprintf(fp, "\n"); | ||
9998 | } | ||
9999 | |||
10000 | // Output states as name mangled methods. | ||
10001 | fdotabs(fp, tabs, tabsize); | ||
10002 | mStates->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
10003 | fprintf(fp, "\n"); | ||
10004 | |||
10005 | // Output class footer. | ||
10006 | fprintf(fp, "}\n"); | ||
10007 | |||
10008 | break; | ||
10009 | default: | ||
10010 | if (mGlobals) | ||
10011 | mGlobals->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
10012 | if (mGlobalFunctions) | ||
10013 | mGlobalFunctions->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
10014 | mStates->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); | ||
10015 | break; | ||
10016 | } | ||
10017 | } | ||