diff options
-rw-r--r-- | lib/LSL.lua | 41 | ||||
-rw-r--r-- | src/LuaSL/LuaSL_compile.c | 56 | ||||
-rw-r--r-- | src/LuaSL/LuaSL_lemon_yaccer.y | 2 |
3 files changed, 96 insertions, 3 deletions
diff --git a/lib/LSL.lua b/lib/LSL.lua index 695c05d..092c3d9 100644 --- a/lib/LSL.lua +++ b/lib/LSL.lua | |||
@@ -871,5 +871,46 @@ function LSL.gimmeLSL() | |||
871 | end | 871 | end |
872 | end | 872 | end |
873 | 873 | ||
874 | -- Misc support functions. | ||
875 | |||
876 | function LSL.listAddList(a, b) | ||
877 | local i = 1 | ||
878 | local result = {} | ||
879 | |||
880 | for j, v in ipairs(a) do | ||
881 | i = i + 1 | ||
882 | table.insert(result, i, v) | ||
883 | end | ||
884 | |||
885 | for j, v in ipairs(b) do | ||
886 | i = i + 1 | ||
887 | table.insert(result, i, v) | ||
888 | end | ||
889 | |||
890 | return result; | ||
891 | end | ||
892 | |||
893 | function LSL.listAdd(a, b) | ||
894 | local i = 1 | ||
895 | local result = {} | ||
896 | |||
897 | for j, v in ipairs(a) do | ||
898 | i = i + 1 | ||
899 | table.insert(result, i, v) | ||
900 | end | ||
901 | |||
902 | table.insert(result, i, b) | ||
903 | |||
904 | return result; | ||
905 | end | ||
906 | |||
907 | function LSL.listConcat(a, b) | ||
908 | local i = table.maxn(a) | ||
909 | local result = a | ||
910 | |||
911 | table.insert(result, i + 1, b) | ||
912 | |||
913 | return result; | ||
914 | end | ||
874 | 915 | ||
875 | return LSL; | 916 | return LSL; |
diff --git a/src/LuaSL/LuaSL_compile.c b/src/LuaSL/LuaSL_compile.c index bab94f3..f2fa37e 100644 --- a/src/LuaSL/LuaSL_compile.c +++ b/src/LuaSL/LuaSL_compile.c | |||
@@ -145,6 +145,10 @@ LSL_Token LSL_Tokens[] = | |||
145 | {LSL_STATE, ST_NONE, "state", LSL_NONE, outputStateToken}, | 145 | {LSL_STATE, ST_NONE, "state", LSL_NONE, outputStateToken}, |
146 | {LSL_SCRIPT, ST_NONE, "", LSL_NONE, NULL}, | 146 | {LSL_SCRIPT, ST_NONE, "", LSL_NONE, NULL}, |
147 | 147 | ||
148 | {LSL_LIST_CONCAT, ST_CONCATENATION,"listconcat", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, NULL}, | ||
149 | {LSL_LIST_ADD, ST_ADD, "listadd", LSL_LEFT2RIGHT, NULL}, | ||
150 | {LSL_LIST_ADD_LIST, ST_ADD, "listaddlist", LSL_LEFT2RIGHT, NULL}, | ||
151 | |||
148 | {LSL_UNKNOWN, ST_NONE, "unknown", LSL_NONE, NULL}, | 152 | {LSL_UNKNOWN, ST_NONE, "unknown", LSL_NONE, NULL}, |
149 | 153 | ||
150 | // A sentinal. | 154 | // A sentinal. |
@@ -472,6 +476,28 @@ LSL_Leaf *addOperation(LuaSL_compiler *compiler, LSL_Leaf *left, LSL_Leaf *lval, | |||
472 | lval->basicType = OT_vector; | 476 | lval->basicType = OT_vector; |
473 | } | 477 | } |
474 | break; | 478 | break; |
479 | |||
480 | case ST_ADD : | ||
481 | // TODO - This doesn't work if the right side has been cast to a list. | ||
482 | if (OT_listList == lval->basicType) | ||
483 | { | ||
484 | lval->basicType = OT_list; | ||
485 | lval->toKen = tokens[LSL_LIST_ADD_LIST - lowestToken]; | ||
486 | } | ||
487 | else if (OT_list == lType) | ||
488 | { | ||
489 | lval->basicType = OT_list; | ||
490 | lval->toKen = tokens[LSL_LIST_ADD - lowestToken]; | ||
491 | } | ||
492 | break; | ||
493 | |||
494 | case ST_CONCATENATION : | ||
495 | if ((OT_list == lType) && (OT_list != rType)) | ||
496 | { | ||
497 | lval->basicType = OT_list; | ||
498 | lval->toKen = tokens[LSL_LIST_CONCAT - lowestToken]; | ||
499 | } | ||
500 | break; | ||
475 | default : | 501 | default : |
476 | break; | 502 | break; |
477 | } | 503 | } |
@@ -1349,7 +1375,7 @@ static void outputLeaf(FILE *file, outputMode mode, LSL_Leaf *leaf) | |||
1349 | { | 1375 | { |
1350 | if (leaf) | 1376 | if (leaf) |
1351 | { | 1377 | { |
1352 | if ((OM_LUA == mode) &&(ST_BITWISE != leaf->toKen->subType)) | 1378 | if ((OM_LUA == mode) && (ST_BITWISE != leaf->toKen->subType) && (LSL_LIST_ADD != leaf->toKen->type) && (LSL_LIST_ADD_LIST != leaf->toKen->type)) |
1353 | outputLeaf(file, mode, leaf->left); | 1379 | outputLeaf(file, mode, leaf->left); |
1354 | #if LUASL_DIFF_CHECK | 1380 | #if LUASL_DIFF_CHECK |
1355 | if ((!(LSL_NOIGNORE & leaf->toKen->flags)) && (leaf->ignorable)) | 1381 | if ((!(LSL_NOIGNORE & leaf->toKen->flags)) && (leaf->ignorable)) |
@@ -1375,7 +1401,15 @@ else | |||
1375 | } | 1401 | } |
1376 | if ((LSL_ASSIGNMENT & leaf->toKen->flags) && (LSL_ASSIGNMENT_PLAIN != leaf->toKen->type)) | 1402 | if ((LSL_ASSIGNMENT & leaf->toKen->flags) && (LSL_ASSIGNMENT_PLAIN != leaf->toKen->type)) |
1377 | { | 1403 | { |
1378 | if (leaf->left->value.identifierValue->sub) | 1404 | if (LSL_LIST_CONCAT == leaf->toKen->type) |
1405 | { | ||
1406 | fprintf(file, " = _LSL.listConcat("); | ||
1407 | outputLeaf(file, mode, leaf->left); | ||
1408 | fprintf(file, ", "); | ||
1409 | outputLeaf(file, mode, leaf->right); | ||
1410 | fprintf(file, ") "); | ||
1411 | } | ||
1412 | else if (leaf->left->value.identifierValue->sub) | ||
1379 | fprintf(file, " --[[%s]] = %s.%s %.1s ", leaf->toKen->toKen, leaf->left->value.identifierValue->name.text, leaf->left->value.identifierValue->sub, leaf->toKen->toKen); | 1413 | fprintf(file, " --[[%s]] = %s.%s %.1s ", leaf->toKen->toKen, leaf->left->value.identifierValue->name.text, leaf->left->value.identifierValue->sub, leaf->toKen->toKen); |
1380 | else | 1414 | else |
1381 | fprintf(file, " --[[%s]] = %s %.1s ", leaf->toKen->toKen, leaf->left->value.identifierValue->name.text, leaf->toKen->toKen); | 1415 | fprintf(file, " --[[%s]] = %s %.1s ", leaf->toKen->toKen, leaf->left->value.identifierValue->name.text, leaf->toKen->toKen); |
@@ -1396,13 +1430,29 @@ else | |||
1396 | fprintf(file, " .. "); | 1430 | fprintf(file, " .. "); |
1397 | else if (LSL_NOT_EQUAL == leaf->toKen->type) | 1431 | else if (LSL_NOT_EQUAL == leaf->toKen->type) |
1398 | fprintf(file, " ~= "); | 1432 | fprintf(file, " ~= "); |
1433 | else if (LSL_LIST_ADD == leaf->toKen->type) | ||
1434 | { | ||
1435 | fprintf(file, " _LSL.listAdd("); | ||
1436 | outputLeaf(file, mode, leaf->left); | ||
1437 | fprintf(file, ", "); | ||
1438 | outputLeaf(file, mode, leaf->right); | ||
1439 | fprintf(file, ") "); | ||
1440 | } | ||
1441 | else if (LSL_LIST_ADD_LIST == leaf->toKen->type) | ||
1442 | { | ||
1443 | fprintf(file, " _LSL.listAddList("); | ||
1444 | outputLeaf(file, mode, leaf->left); | ||
1445 | fprintf(file, ", "); | ||
1446 | outputLeaf(file, mode, leaf->right); | ||
1447 | fprintf(file, ") "); | ||
1448 | } | ||
1399 | else | 1449 | else |
1400 | fprintf(file, "%s", leaf->toKen->toKen); | 1450 | fprintf(file, "%s", leaf->toKen->toKen); |
1401 | } | 1451 | } |
1402 | else | 1452 | else |
1403 | fprintf(file, "%s", leaf->toKen->toKen); | 1453 | fprintf(file, "%s", leaf->toKen->toKen); |
1404 | } | 1454 | } |
1405 | if ((OM_LUA == mode) &&(ST_BITWISE != leaf->toKen->subType)) | 1455 | if ((OM_LUA == mode) && (ST_BITWISE != leaf->toKen->subType) && (LSL_LIST_ADD != leaf->toKen->type) && (LSL_LIST_CONCAT != leaf->toKen->type) && (LSL_LIST_ADD_LIST != leaf->toKen->type)) |
1406 | outputLeaf(file, mode, leaf->right); | 1456 | outputLeaf(file, mode, leaf->right); |
1407 | } | 1457 | } |
1408 | } | 1458 | } |
diff --git a/src/LuaSL/LuaSL_lemon_yaccer.y b/src/LuaSL/LuaSL_lemon_yaccer.y index 72c4479..f03837e 100644 --- a/src/LuaSL/LuaSL_lemon_yaccer.y +++ b/src/LuaSL/LuaSL_lemon_yaccer.y | |||
@@ -165,6 +165,8 @@ expr(A) ::= LSL_BIT_NOT(B) expr(C). { A = addOperation(compiler, NULL, B, C | |||
165 | expr(A) ::= LSL_BOOL_NOT(B) expr(C). { A = addOperation(compiler, NULL, B, C); } | 165 | expr(A) ::= LSL_BOOL_NOT(B) expr(C). { A = addOperation(compiler, NULL, B, C); } |
166 | expr(A) ::= LSL_SUBTRACT(B) expr(C). [LSL_NEGATION] { A = addOperation(compiler, NULL, B, C); } | 166 | expr(A) ::= LSL_SUBTRACT(B) expr(C). [LSL_NEGATION] { A = addOperation(compiler, NULL, B, C); } |
167 | 167 | ||
168 | %left LSL_LIST_CONCAT LSL_LIST_ADD LSL_LIST_ADD_LIST. | ||
169 | |||
168 | // Types, typecasts, and expression reordering. | 170 | // Types, typecasts, and expression reordering. |
169 | 171 | ||
170 | %right LSL_TYPECAST_OPEN LSL_TYPECAST_CLOSE. | 172 | %right LSL_TYPECAST_OPEN LSL_TYPECAST_CLOSE. |