aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/LuaSL
diff options
context:
space:
mode:
authorDavid Walter Seikel2012-02-05 12:29:07 +1000
committerDavid Walter Seikel2012-02-05 12:29:07 +1000
commite3095c8fd6480a60fedef3a66d0c7f2870f621d0 (patch)
treefc846c0eaa49d2e161d2870225977ec414621f81 /LuaSL
parentRemove a lot of old cruft that is no longer needed. Including the eveluator,... (diff)
downloadSledjHamr-e3095c8fd6480a60fedef3a66d0c7f2870f621d0.zip
SledjHamr-e3095c8fd6480a60fedef3a66d0c7f2870f621d0.tar.gz
SledjHamr-e3095c8fd6480a60fedef3a66d0c7f2870f621d0.tar.bz2
SledjHamr-e3095c8fd6480a60fedef3a66d0c7f2870f621d0.tar.xz
Commentry clean ups.
Diffstat (limited to 'LuaSL')
-rw-r--r--LuaSL/src/LuaSL_compile.c27
1 files changed, 11 insertions, 16 deletions
diff --git a/LuaSL/src/LuaSL_compile.c b/LuaSL/src/LuaSL_compile.c
index e2577fe..c2c0638 100644
--- a/LuaSL/src/LuaSL_compile.c
+++ b/LuaSL/src/LuaSL_compile.c
@@ -42,7 +42,6 @@ LSL_Token LSL_Tokens[] =
42 {LSL_BOOL_AND, ST_BOOLEAN, "&&", LSL_RIGHT2LEFT, NULL}, 42 {LSL_BOOL_AND, ST_BOOLEAN, "&&", LSL_RIGHT2LEFT, NULL},
43// QUIRK - Seems to be some disagreement about BOOL_AND/BOOL_OR precedence. Either they are equal, or OR is higher. 43// QUIRK - Seems to be some disagreement about BOOL_AND/BOOL_OR precedence. Either they are equal, or OR is higher.
44// QUIRK - No boolean short circuiting. 44// QUIRK - No boolean short circuiting.
45// QUIRK - Booleans and conditionals are executed right to left. Or maybe not, depending on who you believe.
46// LUA - Short circiuts boolean operations, and goes left to right. 45// LUA - Short circiuts boolean operations, and goes left to right.
47// LUA - "and" returns its first argument if it is false, otherwise, it returns its second argument. "or" returns its first argument if it is not false, otherwise it returns its second argument. 46// LUA - "and" returns its first argument if it is false, otherwise, it returns its second argument. "or" returns its first argument if it is not false, otherwise it returns its second argument.
48// Note that the above means that "and/or" can return any type. 47// Note that the above means that "and/or" can return any type.
@@ -57,7 +56,7 @@ LSL_Token LSL_Tokens[] =
57 {LSL_LESS_EQUAL, ST_COMPARISON, "<=", LSL_RIGHT2LEFT, NULL}, 56 {LSL_LESS_EQUAL, ST_COMPARISON, "<=", LSL_RIGHT2LEFT, NULL},
58 {LSL_GREATER_THAN, ST_COMPARISON, ">", LSL_RIGHT2LEFT, NULL}, 57 {LSL_GREATER_THAN, ST_COMPARISON, ">", LSL_RIGHT2LEFT, NULL},
59 {LSL_LESS_THAN, ST_COMPARISON, "<", LSL_RIGHT2LEFT, NULL}, 58 {LSL_LESS_THAN, ST_COMPARISON, "<", LSL_RIGHT2LEFT, NULL},
60// LUA - comparisons are always false if they are different types. Tables, userdata, and functions are compared by reference. Strings campare in alphabetical order, depending on current locale. 59// LUA - comparisons are always false if they are different types. Tables, userdata, and functions are compared by reference. Strings compare in alphabetical order, depending on current locale.
61// LUA - really only has three conditionals, as it translates a ~= b to not (a == b), a > b to b < a, and a >= b to b <= a. 60// LUA - really only has three conditionals, as it translates a ~= b to not (a == b), a > b to b < a, and a >= b to b <= a.
62 {LSL_RIGHT_SHIFT, ST_BITWISE, ">>", LSL_LEFT2RIGHT, outputBitOp}, 61 {LSL_RIGHT_SHIFT, ST_BITWISE, ">>", LSL_LEFT2RIGHT, outputBitOp},
63 {LSL_LEFT_SHIFT, ST_BITWISE, "<<", LSL_LEFT2RIGHT, outputBitOp}, 62 {LSL_LEFT_SHIFT, ST_BITWISE, "<<", LSL_LEFT2RIGHT, outputBitOp},
@@ -73,7 +72,7 @@ LSL_Token LSL_Tokens[] =
73 {LSL_BOOL_NOT, ST_BOOL_NOT, "!", LSL_RIGHT2LEFT | LSL_UNARY, NULL}, 72 {LSL_BOOL_NOT, ST_BOOL_NOT, "!", LSL_RIGHT2LEFT | LSL_UNARY, NULL},
74 {LSL_BIT_NOT, ST_BIT_NOT, "~", LSL_RIGHT2LEFT | LSL_UNARY, outputBitOp}, 73 {LSL_BIT_NOT, ST_BIT_NOT, "~", LSL_RIGHT2LEFT | LSL_UNARY, outputBitOp},
75 74
76// LUA precedence - (it has no bit operators, at least not until 5.2, but LuaJIT has them.) 75// LUA precedence - (it has no bit operators, at least not until 5.2, but LuaJIT has them as table functions.)
77// or 76// or
78// and 77// and
79// < > <= >= ~= == 78// < > <= >= ~= ==
@@ -906,7 +905,7 @@ LSL_Leaf *addParenthesis(LSL_Leaf *lval, LSL_Leaf *expr, LSL_Type type, LSL_Leaf
906 if (expr) 905 if (expr)
907 { 906 {
908 lval->basicType = expr->basicType; 907 lval->basicType = expr->basicType;
909 // Propagate these flag inwards and outwards. 908 // Propagate these flags inwards and outwards.
910 if (MF_ASSIGNEXP & expr->flags) 909 if (MF_ASSIGNEXP & expr->flags)
911 lval->flags |= MF_ASSIGNEXP; 910 lval->flags |= MF_ASSIGNEXP;
912 if (MF_WRAPFUNC & expr->flags) 911 if (MF_WRAPFUNC & expr->flags)
@@ -1219,7 +1218,7 @@ QUIRK - I have seen cases where a double explicit typecast was needed in SL, but
1219Any binary operation involving a float and an integer implicitly casts the integer to float. 1218Any binary operation involving a float and an integer implicitly casts the integer to float.
1220 1219
1221A boolean operation deals with TRUE (1) and FALSE (0). Any non zero value is a TRUE (generally sigh). 1220A boolean operation deals with TRUE (1) and FALSE (0). Any non zero value is a TRUE (generally sigh).
1222On the other hand, in Lua, only false and nil are false, everything else is true. 1221On the other hand, in Lua, only false and nil are false, everything else is true. 0 is true. sigh
1223Bitwise operations only apply to integers. The shifts are arithmatic, not logical. Right shifted bits are dropped, left shifts the sign bit. 1222Bitwise operations only apply to integers. The shifts are arithmatic, not logical. Right shifted bits are dropped, left shifts the sign bit.
1224 1223
1225integer = integer0 % integer1; // Apparently only applies to integers, but works fine on floats in OS. 1224integer = integer0 % integer1; // Apparently only applies to integers, but works fine on floats in OS.
@@ -1446,6 +1445,7 @@ static void outputRawBlock(FILE *file, outputMode mode, LSL_Block *block, boolea
1446 } 1445 }
1447} 1446}
1448 1447
1448// TODO - should clean this up by refactoring the bits in the switch outside.
1449static void outputRawParenthesisToken(FILE *file, outputMode mode, LSL_Parenthesis *parenthesis, const char *typeName) 1449static void outputRawParenthesisToken(FILE *file, outputMode mode, LSL_Parenthesis *parenthesis, const char *typeName)
1450{ 1450{
1451 if ((OM_LUA == mode) && (LSL_TYPECAST_OPEN == parenthesis->type)) 1451 if ((OM_LUA == mode) && (LSL_TYPECAST_OPEN == parenthesis->type))
@@ -1757,11 +1757,6 @@ static void outputBitOp(FILE *file, outputMode mode, LSL_Leaf *leaf)
1757 outputLeaf(file, mode, leaf); 1757 outputLeaf(file, mode, leaf);
1758 else if (OM_LUA == mode) 1758 else if (OM_LUA == mode)
1759 { 1759 {
1760/*
1761swap = (integer)((string)pkey) & 1;
1762bit.band(swap= --[[(integer)]] ( --[[(string)]] pkey), 1) ;
1763*/
1764
1765 switch (leaf->toKen->type) 1760 switch (leaf->toKen->type)
1766 { 1761 {
1767 case LSL_BIT_AND : fprintf(file, " _bit.band("); break; 1762 case LSL_BIT_AND : fprintf(file, " _bit.band("); break;
@@ -1830,8 +1825,8 @@ static void outputCrementsToken(FILE *file, outputMode mode, LSL_Leaf *content)
1830 fprintf(file, " _LSL."); 1825 fprintf(file, " _LSL.");
1831 switch (content->toKen->type) 1826 switch (content->toKen->type)
1832 { 1827 {
1833 case LSL_DECREMENT_PRE : fprintf(file, "preDecrement"); break; 1828 case LSL_DECREMENT_PRE : fprintf(file, "preDecrement"); break;
1834 case LSL_INCREMENT_PRE : fprintf(file, "preIncrement"); break; 1829 case LSL_INCREMENT_PRE : fprintf(file, "preIncrement"); break;
1835 case LSL_DECREMENT_POST : fprintf(file, "postDecrement"); break; 1830 case LSL_DECREMENT_POST : fprintf(file, "postDecrement"); break;
1836 case LSL_INCREMENT_POST : fprintf(file, "postIncrement"); break; 1831 case LSL_INCREMENT_POST : fprintf(file, "postIncrement"); break;
1837 default : 1832 default :
@@ -2145,7 +2140,7 @@ static boolean doneParsing(LuaSL_compiler *compiler)
2145 fprintf(out, "local _bit = require(\"bit\")\n"); 2140 fprintf(out, "local _bit = require(\"bit\")\n");
2146 fprintf(out, "local _LSL = require(\"LSL\")\n\n"); 2141 fprintf(out, "local _LSL = require(\"LSL\")\n\n");
2147 outputLeaf(out, OM_LUA, compiler->ast); 2142 outputLeaf(out, OM_LUA, compiler->ast);
2148 fprintf(out, "\n\n_LSL.stateChange(_defaultState)\n"); // This actually starts the script running. Not ready for that yet, gotta implement some ll*() functions first. So commented it out in Lua. 2143 fprintf(out, "\n\n_LSL.stateChange(_defaultState)\n"); // This actually starts the script running.
2149 fprintf(out, "\n--// End of generated code.\n\n"); 2144 fprintf(out, "\n--// End of generated code.\n\n");
2150 fclose(out); 2145 fclose(out);
2151 sprintf(buffer, "../../libraries/luajit-2.0/src/luajit \"%s\"", luaName); 2146 sprintf(buffer, "../../libraries/luajit-2.0/src/luajit \"%s\"", luaName);
@@ -2216,8 +2211,8 @@ boolean compileLSL(gameGlobals *game, char *script, boolean doConstants)
2216 void *pParser = ParseAlloc(malloc); 2211 void *pParser = ParseAlloc(malloc);
2217 int yv; 2212 int yv;
2218 2213
2219// Parse the LSL script, validating it and reporting errors. 2214// Parse the LSL script, validating it and reporting errors.
2220// Just pass all constants and function names through to Lua, assume they are globals there. 2215// Just pass all LSL constants and ll*() )function names through to Lua, assume they are globals there.
2221 2216
2222 memset(&compiler, 0, sizeof(LuaSL_compiler)); 2217 memset(&compiler, 0, sizeof(LuaSL_compiler));
2223 compiler.game = game; 2218 compiler.game = game;
@@ -2241,7 +2236,7 @@ boolean compileLSL(gameGlobals *game, char *script, boolean doConstants)
2241 PD("Compiling %s.", compiler.fileName); 2236 PD("Compiling %s.", compiler.fileName);
2242 compiler.ast = NULL; 2237 compiler.ast = NULL;
2243 compiler.lval = newLeaf(LSL_UNKNOWN, NULL, NULL); 2238 compiler.lval = newLeaf(LSL_UNKNOWN, NULL, NULL);
2244 // Text editors usually start counting at 1, even programmers editors. 2239 // Text editors usually start counting at 1, even programmers editors. mcedit is an exception, but you can deal with that yourself.
2245 compiler.column = 1; 2240 compiler.column = 1;
2246 compiler.line = 1; 2241 compiler.line = 1;
2247 2242