diff options
author | David Walter Seikel | 2012-01-30 19:14:57 +1000 |
---|---|---|
committer | David Walter Seikel | 2012-01-30 19:14:57 +1000 |
commit | df174dd2c6ab38df55cfd4f367a347c9885f1c49 (patch) | |
tree | 3a452aa0074a6563c987e91b4e3dfea9f6682422 /LuaSL/src | |
parent | Track function type ignorable, and no need to store the leaf. (diff) | |
download | SledjHamr-df174dd2c6ab38df55cfd4f367a347c9885f1c49.zip SledjHamr-df174dd2c6ab38df55cfd4f367a347c9885f1c49.tar.gz SledjHamr-df174dd2c6ab38df55cfd4f367a347c9885f1c49.tar.bz2 SledjHamr-df174dd2c6ab38df55cfd4f367a347c9885f1c49.tar.xz |
No longer storing blocks as leaves. This one required a whole heap of function reordering.
Diffstat (limited to 'LuaSL/src')
-rw-r--r-- | LuaSL/src/LuaSL_LSL_tree.h | 6 | ||||
-rw-r--r-- | LuaSL/src/LuaSL_compile.c | 239 |
2 files changed, 125 insertions, 120 deletions
diff --git a/LuaSL/src/LuaSL_LSL_tree.h b/LuaSL/src/LuaSL_LSL_tree.h index 104ba45..875e1b9 100644 --- a/LuaSL/src/LuaSL_LSL_tree.h +++ b/LuaSL/src/LuaSL_LSL_tree.h | |||
@@ -224,7 +224,7 @@ struct _LSL_Statement | |||
224 | // } stuff; // Nothing has an identifier AND parenthesis, and there will be LOTS of statements, so save some space. | 224 | // } stuff; // Nothing has an identifier AND parenthesis, and there will be LOTS of statements, so save some space. |
225 | // Damn, function identifiers do. | 225 | // Damn, function identifiers do. |
226 | LSL_Leaf *expressions; // A for statement will have three expressions, everything else has zero or one. | 226 | LSL_Leaf *expressions; // A for statement will have three expressions, everything else has zero or one. |
227 | LSL_Leaf *block; | 227 | LSL_Block *block; |
228 | LSL_Type type; // Expression type. | 228 | LSL_Type type; // Expression type. |
229 | /* | 229 | /* |
230 | LSL_Leaf *addStatement(LSL_Leaf *lval, LSL_Type type, LSL_Leaf *left, LSL_Leaf *expr, LSL_Leaf *right, LSL_Leaf *block); | 230 | LSL_Leaf *addStatement(LSL_Leaf *lval, LSL_Type type, LSL_Leaf *left, LSL_Leaf *expr, LSL_Leaf *right, LSL_Leaf *block); |
@@ -262,7 +262,7 @@ struct _LSL_Function | |||
262 | // This points to the params leaf, which is a function, pointing to this structure. The actual params are in vars. | 262 | // This points to the params leaf, which is a function, pointing to this structure. The actual params are in vars. |
263 | #endif | 263 | #endif |
264 | Eina_Inarray vars; // Eina Inarray has not been released yet (Eina 1.2). | 264 | Eina_Inarray vars; // Eina Inarray has not been released yet (Eina 1.2). |
265 | LSL_Leaf *block; | 265 | LSL_Block *block; |
266 | }; | 266 | }; |
267 | 267 | ||
268 | struct _LSL_FunctionCall | 268 | struct _LSL_FunctionCall |
@@ -277,7 +277,7 @@ struct _LSL_State | |||
277 | { | 277 | { |
278 | LSL_Text name; | 278 | LSL_Text name; |
279 | LSL_Text state; | 279 | LSL_Text state; |
280 | LSL_Leaf *block; | 280 | LSL_Block *block; |
281 | Eina_Hash *handlers; | 281 | Eina_Hash *handlers; |
282 | }; | 282 | }; |
283 | 283 | ||
diff --git a/LuaSL/src/LuaSL_compile.c b/LuaSL/src/LuaSL_compile.c index b10ae07..a9cc733 100644 --- a/LuaSL/src/LuaSL_compile.c +++ b/LuaSL/src/LuaSL_compile.c | |||
@@ -565,7 +565,7 @@ LSL_Leaf *addFunctionBody(LuaSL_compiler *compiler, LSL_Leaf *function, LSL_Leaf | |||
565 | 565 | ||
566 | if (function) | 566 | if (function) |
567 | { | 567 | { |
568 | function->value.functionValue->block = block; | 568 | function->value.functionValue->block = block->value.blockValue; |
569 | statement = addStatement(compiler, NULL, LSL_FUNCTION, NULL, function, NULL, NULL, NULL); | 569 | statement = addStatement(compiler, NULL, LSL_FUNCTION, NULL, function, NULL, NULL, NULL); |
570 | } | 570 | } |
571 | 571 | ||
@@ -638,7 +638,7 @@ LSL_Leaf *addState(LuaSL_compiler *compiler, LSL_Leaf *state, LSL_Leaf *identifi | |||
638 | { | 638 | { |
639 | result->name.text = identifier->value.stringValue; | 639 | result->name.text = identifier->value.stringValue; |
640 | result->name.ignorableText = identifier->ignorableText; | 640 | result->name.ignorableText = identifier->ignorableText; |
641 | result->block = block; | 641 | result->block = block->value.blockValue; |
642 | if (state) | 642 | if (state) |
643 | { | 643 | { |
644 | result->state.text = state->toKen->toKen; | 644 | result->state.text = state->toKen->toKen; |
@@ -664,7 +664,8 @@ LSL_Leaf *addStatement(LuaSL_compiler *compiler, LSL_Leaf *lval, LSL_Type type, | |||
664 | { | 664 | { |
665 | stat->type = type; | 665 | stat->type = type; |
666 | stat->expressions = expr; | 666 | stat->expressions = expr; |
667 | stat->block = block; | 667 | if (block) |
668 | stat->block = block->value.blockValue; | ||
668 | eina_clist_element_init(&(stat->statement)); | 669 | eina_clist_element_init(&(stat->statement)); |
669 | if (identifier) | 670 | if (identifier) |
670 | stat->identifier = identifier->value.identifierValue; | 671 | stat->identifier = identifier->value.identifierValue; |
@@ -1187,18 +1188,6 @@ static LSL_Leaf *evaluateStatementToken(LSL_Leaf *content, LSL_Leaf *left, LSL_L | |||
1187 | return result; | 1188 | return result; |
1188 | } | 1189 | } |
1189 | 1190 | ||
1190 | static void outputText(FILE *file, LSL_Text *text, boolean ignore) | ||
1191 | { | ||
1192 | if (text->text) | ||
1193 | { | ||
1194 | #if LUASL_DIFF_CHECK | ||
1195 | if (ignore && (text->ignorableText)) | ||
1196 | fwrite(eina_strbuf_string_get(text->ignorableText), 1, eina_strbuf_length_get(text->ignorableText), file); | ||
1197 | #endif | ||
1198 | fprintf(file, "%s", text->text); | ||
1199 | } | ||
1200 | } | ||
1201 | |||
1202 | static void outputLeaf(FILE *file, outputMode mode, LSL_Leaf *leaf) | 1191 | static void outputLeaf(FILE *file, outputMode mode, LSL_Leaf *leaf) |
1203 | { | 1192 | { |
1204 | if (leaf) | 1193 | if (leaf) |
@@ -1216,70 +1205,28 @@ static void outputLeaf(FILE *file, outputMode mode, LSL_Leaf *leaf) | |||
1216 | } | 1205 | } |
1217 | } | 1206 | } |
1218 | 1207 | ||
1219 | static void outputFloatToken(FILE *file, outputMode mode, LSL_Leaf *content) | 1208 | // Circular references, so declare this one first. |
1220 | { | 1209 | static void outputRawStatement(FILE *file, outputMode mode, LSL_Statement *statement); |
1221 | if (content) | ||
1222 | fprintf(file, "%g", content->value.floatValue); | ||
1223 | } | ||
1224 | 1210 | ||
1225 | static void outputFunctionToken(FILE *file, outputMode mode, LSL_Leaf *content) | 1211 | static void outputRawBlock(FILE *file, outputMode mode, LSL_Block *block) |
1226 | { | 1212 | { |
1227 | if (content) | 1213 | if (LUASL_DIFF_CHECK) |
1214 | fprintf(file, "\n{"); | ||
1215 | else | ||
1216 | fprintf(file, "\n{\n"); | ||
1217 | if (block) | ||
1228 | { | 1218 | { |
1229 | LSL_Function *func = content->value.functionValue; | 1219 | LSL_Statement *stat = NULL; |
1230 | LSL_Leaf *param = NULL; | ||
1231 | int first = TRUE; | ||
1232 | 1220 | ||
1233 | outputText(file, &(func->type), !(LSL_NOIGNORE & content->toKen->flags)); | 1221 | EINA_CLIST_FOR_EACH_ENTRY(stat, &(block->statements), LSL_Statement, statement) |
1234 | outputText(file, &(func->name), !(LSL_NOIGNORE & content->toKen->flags)); | ||
1235 | // TODO - should print comma and parenthesis ignorables. | ||
1236 | fprintf(file, "("); | ||
1237 | EINA_INARRAY_FOREACH((&(func->vars)), param) | ||
1238 | { | 1222 | { |
1239 | if (!LUASL_DIFF_CHECK) | 1223 | outputRawStatement(file, mode, stat); |
1240 | { | ||
1241 | if (!first) | ||
1242 | fprintf(file, ", "); | ||
1243 | } | ||
1244 | outputLeaf(file, mode, param); | ||
1245 | first = FALSE; | ||
1246 | } | 1224 | } |
1247 | fprintf(file, ")"); | ||
1248 | outputLeaf(file, mode, func->block); | ||
1249 | if (!LUASL_DIFF_CHECK) | ||
1250 | fprintf(file, "\n"); | ||
1251 | } | ||
1252 | } | ||
1253 | |||
1254 | static void outputFunctionCallToken(FILE *file, outputMode mode, LSL_Leaf *content) | ||
1255 | { | ||
1256 | if (content) | ||
1257 | { | ||
1258 | LSL_FunctionCall *call = content->value.functionCallValue; | ||
1259 | LSL_Function *func = call->function; | ||
1260 | outputText(file, &(func->name), !(LSL_NOIGNORE & content->toKen->flags)); | ||
1261 | fprintf(file, "("); | ||
1262 | // TODO - print params here. | ||
1263 | fprintf(file, ")"); | ||
1264 | } | 1225 | } |
1265 | } | 1226 | if (LUASL_DIFF_CHECK) |
1266 | 1227 | fprintf(file, "\n}"); | |
1267 | static void outputIntegerToken(FILE *file, outputMode mode, LSL_Leaf *content) | 1228 | else |
1268 | { | 1229 | fprintf(file, "}"); |
1269 | if (content) | ||
1270 | fprintf(file, "%d", content->value.integerValue); | ||
1271 | } | ||
1272 | |||
1273 | static void outputIdentifierToken(FILE *file, outputMode mode, LSL_Leaf *content) | ||
1274 | { | ||
1275 | if (content) | ||
1276 | outputText(file, &(content->value.identifierValue->name), !(LSL_NOIGNORE & content->toKen->flags)); | ||
1277 | } | ||
1278 | |||
1279 | static void outputParameterListToken(FILE *file, outputMode mode, LSL_Leaf *content) | ||
1280 | { | ||
1281 | if (content) | ||
1282 | outputLeaf(file, mode, content->value.listValue); | ||
1283 | } | 1230 | } |
1284 | 1231 | ||
1285 | static void outputRawParenthesisToken(FILE *file, outputMode mode, LSL_Parenthesis *parenthesis, const char *typeName) | 1232 | static void outputRawParenthesisToken(FILE *file, outputMode mode, LSL_Parenthesis *parenthesis, const char *typeName) |
@@ -1299,31 +1246,6 @@ static void outputRawParenthesisToken(FILE *file, outputMode mode, LSL_Parenthes | |||
1299 | outputLeaf(file, mode, parenthesis->contents); | 1246 | outputLeaf(file, mode, parenthesis->contents); |
1300 | } | 1247 | } |
1301 | 1248 | ||
1302 | static void outputParenthesisToken(FILE *file, outputMode mode, LSL_Leaf *content) | ||
1303 | { | ||
1304 | if (content) | ||
1305 | outputRawParenthesisToken(file, mode, content->value.parenthesis, allowed[content->basicType].name); | ||
1306 | } | ||
1307 | |||
1308 | static void outputStateToken(FILE *file, outputMode mode, LSL_Leaf *content) | ||
1309 | { | ||
1310 | if (content) | ||
1311 | { | ||
1312 | LSL_State *state = content->value.stateValue; | ||
1313 | |||
1314 | if (state) | ||
1315 | { | ||
1316 | outputText(file, &(state->state), !(LSL_NOIGNORE & content->toKen->flags)); | ||
1317 | outputText(file, &(state->name), !(LSL_NOIGNORE & content->toKen->flags)); | ||
1318 | outputLeaf(file, mode, state->block); | ||
1319 | fprintf(file, "\n"); | ||
1320 | } | ||
1321 | } | ||
1322 | } | ||
1323 | |||
1324 | // Circular references, so declare this one first. | ||
1325 | static void outputBlockToken(FILE *file, outputMode mode, LSL_Leaf *content); | ||
1326 | |||
1327 | static void outputRawStatement(FILE *file, outputMode mode, LSL_Statement *statement) | 1249 | static void outputRawStatement(FILE *file, outputMode mode, LSL_Statement *statement) |
1328 | { | 1250 | { |
1329 | boolean isBlock = FALSE; | 1251 | boolean isBlock = FALSE; |
@@ -1401,7 +1323,7 @@ static void outputRawStatement(FILE *file, outputMode mode, LSL_Statement *state | |||
1401 | outputLeaf(file, mode, statement->expressions); | 1323 | outputLeaf(file, mode, statement->expressions); |
1402 | 1324 | ||
1403 | if (statement->block) | 1325 | if (statement->block) |
1404 | outputBlockToken(file, mode, statement->block); | 1326 | outputRawBlock(file, mode, statement->block); |
1405 | 1327 | ||
1406 | if (!isBlock) | 1328 | if (!isBlock) |
1407 | { | 1329 | { |
@@ -1412,6 +1334,107 @@ static void outputRawStatement(FILE *file, outputMode mode, LSL_Statement *state | |||
1412 | } | 1334 | } |
1413 | } | 1335 | } |
1414 | 1336 | ||
1337 | static void outputText(FILE *file, LSL_Text *text, boolean ignore) | ||
1338 | { | ||
1339 | if (text->text) | ||
1340 | { | ||
1341 | #if LUASL_DIFF_CHECK | ||
1342 | if (ignore && (text->ignorableText)) | ||
1343 | fwrite(eina_strbuf_string_get(text->ignorableText), 1, eina_strbuf_length_get(text->ignorableText), file); | ||
1344 | #endif | ||
1345 | fprintf(file, "%s", text->text); | ||
1346 | } | ||
1347 | } | ||
1348 | |||
1349 | static void outputFloatToken(FILE *file, outputMode mode, LSL_Leaf *content) | ||
1350 | { | ||
1351 | if (content) | ||
1352 | fprintf(file, "%g", content->value.floatValue); | ||
1353 | } | ||
1354 | |||
1355 | static void outputFunctionToken(FILE *file, outputMode mode, LSL_Leaf *content) | ||
1356 | { | ||
1357 | if (content) | ||
1358 | { | ||
1359 | LSL_Function *func = content->value.functionValue; | ||
1360 | LSL_Leaf *param = NULL; | ||
1361 | int first = TRUE; | ||
1362 | |||
1363 | outputText(file, &(func->type), !(LSL_NOIGNORE & content->toKen->flags)); | ||
1364 | outputText(file, &(func->name), !(LSL_NOIGNORE & content->toKen->flags)); | ||
1365 | // TODO - should print comma and parenthesis ignorables. | ||
1366 | fprintf(file, "("); | ||
1367 | EINA_INARRAY_FOREACH((&(func->vars)), param) | ||
1368 | { | ||
1369 | if (!LUASL_DIFF_CHECK) | ||
1370 | { | ||
1371 | if (!first) | ||
1372 | fprintf(file, ", "); | ||
1373 | } | ||
1374 | outputLeaf(file, mode, param); | ||
1375 | first = FALSE; | ||
1376 | } | ||
1377 | fprintf(file, ")"); | ||
1378 | outputRawBlock(file, mode, func->block); | ||
1379 | if (!LUASL_DIFF_CHECK) | ||
1380 | fprintf(file, "\n"); | ||
1381 | } | ||
1382 | } | ||
1383 | |||
1384 | static void outputFunctionCallToken(FILE *file, outputMode mode, LSL_Leaf *content) | ||
1385 | { | ||
1386 | if (content) | ||
1387 | { | ||
1388 | LSL_FunctionCall *call = content->value.functionCallValue; | ||
1389 | LSL_Function *func = call->function; | ||
1390 | outputText(file, &(func->name), !(LSL_NOIGNORE & content->toKen->flags)); | ||
1391 | fprintf(file, "("); | ||
1392 | // TODO - print params here. | ||
1393 | fprintf(file, ")"); | ||
1394 | } | ||
1395 | } | ||
1396 | |||
1397 | static void outputIntegerToken(FILE *file, outputMode mode, LSL_Leaf *content) | ||
1398 | { | ||
1399 | if (content) | ||
1400 | fprintf(file, "%d", content->value.integerValue); | ||
1401 | } | ||
1402 | |||
1403 | static void outputIdentifierToken(FILE *file, outputMode mode, LSL_Leaf *content) | ||
1404 | { | ||
1405 | if (content) | ||
1406 | outputText(file, &(content->value.identifierValue->name), !(LSL_NOIGNORE & content->toKen->flags)); | ||
1407 | } | ||
1408 | |||
1409 | static void outputParameterListToken(FILE *file, outputMode mode, LSL_Leaf *content) | ||
1410 | { | ||
1411 | if (content) | ||
1412 | outputLeaf(file, mode, content->value.listValue); | ||
1413 | } | ||
1414 | |||
1415 | static void outputParenthesisToken(FILE *file, outputMode mode, LSL_Leaf *content) | ||
1416 | { | ||
1417 | if (content) | ||
1418 | outputRawParenthesisToken(file, mode, content->value.parenthesis, allowed[content->basicType].name); | ||
1419 | } | ||
1420 | |||
1421 | static void outputStateToken(FILE *file, outputMode mode, LSL_Leaf *content) | ||
1422 | { | ||
1423 | if (content) | ||
1424 | { | ||
1425 | LSL_State *state = content->value.stateValue; | ||
1426 | |||
1427 | if (state) | ||
1428 | { | ||
1429 | outputText(file, &(state->state), !(LSL_NOIGNORE & content->toKen->flags)); | ||
1430 | outputText(file, &(state->name), !(LSL_NOIGNORE & content->toKen->flags)); | ||
1431 | outputRawBlock(file, mode, state->block); | ||
1432 | fprintf(file, "\n"); | ||
1433 | } | ||
1434 | } | ||
1435 | } | ||
1436 | |||
1437 | |||
1415 | static void outputStatementToken(FILE *file, outputMode mode, LSL_Leaf *content) | 1438 | static void outputStatementToken(FILE *file, outputMode mode, LSL_Leaf *content) |
1416 | { | 1439 | { |
1417 | if (content) | 1440 | if (content) |
@@ -1427,25 +1450,7 @@ static void outputStatementToken(FILE *file, outputMode mode, LSL_Leaf *content) | |||
1427 | static void outputBlockToken(FILE *file, outputMode mode, LSL_Leaf *content) | 1450 | static void outputBlockToken(FILE *file, outputMode mode, LSL_Leaf *content) |
1428 | { | 1451 | { |
1429 | if (content) | 1452 | if (content) |
1430 | { | 1453 | outputRawBlock(file, mode, content->value.blockValue); |
1431 | if (LUASL_DIFF_CHECK) | ||
1432 | fprintf(file, "\n{"); | ||
1433 | else | ||
1434 | fprintf(file, "\n{\n"); | ||
1435 | if (content->value.blockValue) | ||
1436 | { | ||
1437 | LSL_Statement *stat = NULL; | ||
1438 | |||
1439 | EINA_CLIST_FOR_EACH_ENTRY(stat, &(content->value.blockValue->statements), LSL_Statement, statement) | ||
1440 | { | ||
1441 | outputRawStatement(file, mode, stat); | ||
1442 | } | ||
1443 | } | ||
1444 | if (LUASL_DIFF_CHECK) | ||
1445 | fprintf(file, "\n}"); | ||
1446 | else | ||
1447 | fprintf(file, "}"); | ||
1448 | } | ||
1449 | } | 1454 | } |
1450 | 1455 | ||
1451 | static boolean doneParsing(LuaSL_compiler *compiler) | 1456 | static boolean doneParsing(LuaSL_compiler *compiler) |