diff options
-rw-r--r-- | lib/LSL.lua | 16 | ||||
-rw-r--r-- | src/LuaSL/LuaSL_compile.c | 30 |
2 files changed, 24 insertions, 22 deletions
diff --git a/lib/LSL.lua b/lib/LSL.lua index 4ec64b5..e783087 100644 --- a/lib/LSL.lua +++ b/lib/LSL.lua | |||
@@ -986,7 +986,7 @@ end | |||
986 | 986 | ||
987 | -- Misc support functions. | 987 | -- Misc support functions. |
988 | 988 | ||
989 | function LSL.listAddList(a, b) | 989 | function LSL.listAdd(a, b) |
990 | local i = 1 | 990 | local i = 1 |
991 | local result = {} | 991 | local result = {} |
992 | 992 | ||
@@ -1007,20 +1007,6 @@ function LSL.listAddList(a, b) | |||
1007 | return result; | 1007 | return result; |
1008 | end | 1008 | end |
1009 | 1009 | ||
1010 | function LSL.listAdd(a, b) | ||
1011 | local i = 1 | ||
1012 | local result = {} | ||
1013 | |||
1014 | for j, v in ipairs(a) do | ||
1015 | i = i + 1 | ||
1016 | table.insert(result, i, v) | ||
1017 | end | ||
1018 | |||
1019 | table.insert(result, i, b) | ||
1020 | |||
1021 | return result; | ||
1022 | end | ||
1023 | |||
1024 | function LSL.listConcat(a, b) | 1010 | function LSL.listConcat(a, b) |
1025 | local i = table.maxn(a) | 1011 | local i = table.maxn(a) |
1026 | local result = a | 1012 | local result = a |
diff --git a/src/LuaSL/LuaSL_compile.c b/src/LuaSL/LuaSL_compile.c index fb9a5be..c1b119e 100644 --- a/src/LuaSL/LuaSL_compile.c +++ b/src/LuaSL/LuaSL_compile.c | |||
@@ -478,25 +478,41 @@ LSL_Leaf *addOperation(LuaSL_compiler *compiler, LSL_Leaf *left, LSL_Leaf *lval, | |||
478 | break; | 478 | break; |
479 | 479 | ||
480 | case ST_ADD : | 480 | case ST_ADD : |
481 | // someList = (list) notAList + someList -> someList = _LSL.listAddList( _LSL.listTypecast(notAList), someList) | ||
482 | // someList = aList + bList -> someList = _LSL.listAddList(aList, bList) | ||
481 | if (OT_listList == lval->basicType) | 483 | if (OT_listList == lval->basicType) |
482 | { | 484 | { |
483 | lval->basicType = OT_list; | 485 | lval->basicType = OT_list; |
484 | lval->toKen = tokens[LSL_LIST_ADD_LIST - lowestToken]; | 486 | lval->toKen = tokens[LSL_LIST_ADD_LIST - lowestToken]; |
485 | } | 487 | } |
486 | else if (OT_list == lType) | 488 | // This one is not turning up in my test code, so not tested. |
489 | // someList = notAList + someList -> someList = _LSL.listAddList( notAList, someList) | ||
490 | // someList = someList + notAList -> someList = _LSL.listAddList( someList, notAList) | ||
491 | else if ((OT_list == lType) || (OT_list == rType)) | ||
487 | { | 492 | { |
493 | |||
494 | if ((left) && (right)) | ||
495 | printf("LA LINE %d - %s %s %s\n", lval->line, left->toKen->toKen, lval->toKen->toKen, right->toKen->toKen); | ||
496 | else if (left) | ||
497 | printf("LA LINE %d - %s %s NORIGHT\n", lval->line, left->toKen->toKen, lval->toKen->toKen); | ||
498 | else if (right) | ||
499 | printf("LA LINE %d - NOLEFT %s %s\n", lval->line, lval->toKen->toKen, right->toKen->toKen); | ||
500 | else | ||
501 | printf("LA LINE %d - NOLEFT %s NORIGHT\n", lval->line, lval->toKen->toKen); | ||
502 | |||
488 | lval->basicType = OT_list; | 503 | lval->basicType = OT_list; |
489 | lval->toKen = tokens[LSL_LIST_ADD - lowestToken]; | 504 | lval->toKen = tokens[LSL_LIST_ADD_LIST - lowestToken]; |
490 | } | 505 | } |
491 | break; | 506 | break; |
492 | 507 | ||
493 | case ST_CONCATENATION : | 508 | case ST_CONCATENATION : |
494 | // This is if the right side has been cast to a list. | 509 | // someList += (list) notAList -> someList = _LSL.listAddList(someList, _LSL.listTypecast(notAList)) |
495 | if ((LSL_ASSIGNMENT_PLAIN != lval->toKen->type) && (OT_listList == lval->basicType)) | 510 | if ((LSL_ASSIGNMENT_PLAIN != lval->toKen->type) && (OT_listList == lval->basicType)) |
496 | { | 511 | { |
497 | lval->basicType = OT_list; | 512 | lval->basicType = OT_list; |
498 | lval->toKen = tokens[LSL_LIST_ADD_LIST - lowestToken]; | 513 | lval->toKen = tokens[LSL_LIST_ADD - lowestToken]; |
499 | } | 514 | } |
515 | // someList += notAList -> someList = _LSL.listConcat(someList, notAList) | ||
500 | else if ((OT_list == lType) && (OT_list != rType)) | 516 | else if ((OT_list == lType) && (OT_list != rType)) |
501 | { | 517 | { |
502 | lval->basicType = OT_list; | 518 | lval->basicType = OT_list; |
@@ -1382,7 +1398,7 @@ static void outputLeaf(FILE *file, outputMode mode, LSL_Leaf *leaf) | |||
1382 | { | 1398 | { |
1383 | if (leaf) | 1399 | if (leaf) |
1384 | { | 1400 | { |
1385 | if ((OM_LUA == mode) && (ST_BITWISE != leaf->toKen->subType) && (LSL_LIST_ADD != leaf->toKen->type) && (LSL_LIST_ADD_LIST != leaf->toKen->type)) | 1401 | if ((OM_LUA == mode) && (ST_BITWISE != leaf->toKen->subType) /*&& (LSL_LIST_ADD != leaf->toKen->type)*/ && (LSL_LIST_ADD_LIST != leaf->toKen->type)) |
1386 | outputLeaf(file, mode, leaf->left); | 1402 | outputLeaf(file, mode, leaf->left); |
1387 | #if LUASL_DIFF_CHECK | 1403 | #if LUASL_DIFF_CHECK |
1388 | if ((!(LSL_NOIGNORE & leaf->toKen->flags)) && (leaf->ignorable)) | 1404 | if ((!(LSL_NOIGNORE & leaf->toKen->flags)) && (leaf->ignorable)) |
@@ -1439,7 +1455,7 @@ else | |||
1439 | fprintf(file, " ~= "); | 1455 | fprintf(file, " ~= "); |
1440 | else if (LSL_LIST_ADD == leaf->toKen->type) | 1456 | else if (LSL_LIST_ADD == leaf->toKen->type) |
1441 | { | 1457 | { |
1442 | fprintf(file, " _LSL.listAdd("); | 1458 | fprintf(file, " = _LSL.listAdd("); |
1443 | outputLeaf(file, mode, leaf->left); | 1459 | outputLeaf(file, mode, leaf->left); |
1444 | fprintf(file, ", "); | 1460 | fprintf(file, ", "); |
1445 | outputLeaf(file, mode, leaf->right); | 1461 | outputLeaf(file, mode, leaf->right); |
@@ -1447,7 +1463,7 @@ else | |||
1447 | } | 1463 | } |
1448 | else if (LSL_LIST_ADD_LIST == leaf->toKen->type) | 1464 | else if (LSL_LIST_ADD_LIST == leaf->toKen->type) |
1449 | { | 1465 | { |
1450 | fprintf(file, " _LSL.listAddList("); | 1466 | fprintf(file, " _LSL.listAdd("); |
1451 | outputLeaf(file, mode, leaf->left); | 1467 | outputLeaf(file, mode, leaf->left); |
1452 | fprintf(file, ", "); | 1468 | fprintf(file, ", "); |
1453 | outputLeaf(file, mode, leaf->right); | 1469 | outputLeaf(file, mode, leaf->right); |