From 4213ddfa3c5e3fc6ed3cb01f5eb342276df3fc0b Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Sun, 5 Feb 2012 12:13:18 +1000 Subject: Remove a lot of old cruft that is no longer needed. Including the eveluator, we can do that with test scripts now. --- LuaSL/src/LuaSL_LSL_tree.h | 2 - LuaSL/src/LuaSL_compile.c | 774 +++++++++------------------------------------ 2 files changed, 157 insertions(+), 619 deletions(-) (limited to 'LuaSL') diff --git a/LuaSL/src/LuaSL_LSL_tree.h b/LuaSL/src/LuaSL_LSL_tree.h index ca5f844..f21b51c 100644 --- a/LuaSL/src/LuaSL_LSL_tree.h +++ b/LuaSL/src/LuaSL_LSL_tree.h @@ -62,7 +62,6 @@ typedef enum } outputMode; typedef void (*outputToken) (FILE *file, outputMode mode, LSL_Leaf *content); -typedef LSL_Leaf * (*evaluateToken) (LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right); //#ifndef FALSE //typedef enum @@ -175,7 +174,6 @@ struct _LSL_Token const char *toKen; LSL_Flags flags; outputToken output; - evaluateToken evaluate; }; struct _LSL_Text diff --git a/LuaSL/src/LuaSL_compile.c b/LuaSL/src/LuaSL_compile.c index dbc7031..e2577fe 100644 --- a/LuaSL/src/LuaSL_compile.c +++ b/LuaSL/src/LuaSL_compile.c @@ -5,12 +5,6 @@ */ -static LSL_Leaf *evaluateFloatToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right); -static LSL_Leaf *evaluateIntegerToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right); -static LSL_Leaf *evaluateNoToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right); -static LSL_Leaf *evaluateOperationToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right); -static LSL_Leaf *eveluateParenthesisToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right); -static LSL_Leaf *evaluateStatementToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right); static void outputBitOp(FILE *file, outputMode mode, LSL_Leaf *leaf); static void outputBlockToken(FILE *file, outputMode mode, LSL_Leaf *content); static void outputCrementsToken(FILE *file, outputMode mode, LSL_Leaf *content); @@ -29,55 +23,55 @@ static void outputStringToken(FILE *file, outputMode mode, LSL_Leaf *content); LSL_Token LSL_Tokens[] = { // Various forms of "space". - {LSL_COMMENT, ST_NONE, "/*", LSL_NONE, NULL, NULL}, - {LSL_COMMENT_LINE, ST_NONE, "//", LSL_NONE, NULL, NULL}, - {LSL_SPACE, ST_NONE, " ", LSL_NONE, NULL, NULL}, + {LSL_COMMENT, ST_NONE, "/*", LSL_NONE, NULL}, + {LSL_COMMENT_LINE, ST_NONE, "//", LSL_NONE, NULL}, + {LSL_SPACE, ST_NONE, " ", LSL_NONE, NULL}, // Operators, in order of precedence, low to high // Left to right, unless otherwise stated. // According to http://wiki.secondlife.com/wiki/Category:LSL_Operators, which was obsoleted by http://wiki.secondlife.com/wiki/LSL_Operators but that has less info. - {LSL_ASSIGNMENT_CONCATENATE,ST_CONCATENATION, "+=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, NULL, evaluateOperationToken}, - {LSL_ASSIGNMENT_ADD, ST_CONCATENATION, "+=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, NULL, evaluateOperationToken}, - {LSL_ASSIGNMENT_SUBTRACT, ST_ASSIGNMENT, "-=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, NULL, evaluateOperationToken}, - {LSL_ASSIGNMENT_MULTIPLY, ST_ASSIGNMENT, "*=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, NULL, evaluateOperationToken}, - {LSL_ASSIGNMENT_MODULO, ST_MODULO, "%=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, NULL, evaluateOperationToken}, - {LSL_ASSIGNMENT_DIVIDE, ST_ASSIGNMENT, "/=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, NULL, evaluateOperationToken}, - {LSL_ASSIGNMENT_PLAIN, ST_CONCATENATION, "=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, NULL, evaluateOperationToken}, + {LSL_ASSIGNMENT_CONCATENATE,ST_CONCATENATION, "+=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, NULL}, + {LSL_ASSIGNMENT_ADD, ST_CONCATENATION, "+=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, NULL}, + {LSL_ASSIGNMENT_SUBTRACT, ST_ASSIGNMENT, "-=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, NULL}, + {LSL_ASSIGNMENT_MULTIPLY, ST_ASSIGNMENT, "*=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, NULL}, + {LSL_ASSIGNMENT_MODULO, ST_MODULO, "%=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, NULL}, + {LSL_ASSIGNMENT_DIVIDE, ST_ASSIGNMENT, "/=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, NULL}, + {LSL_ASSIGNMENT_PLAIN, ST_CONCATENATION, "=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, NULL}, - {LSL_BOOL_AND, ST_BOOLEAN, "&&", LSL_RIGHT2LEFT, NULL, evaluateOperationToken}, + {LSL_BOOL_AND, ST_BOOLEAN, "&&", LSL_RIGHT2LEFT, NULL}, // QUIRK - Seems to be some disagreement about BOOL_AND/BOOL_OR precedence. Either they are equal, or OR is higher. // QUIRK - No boolean short circuiting. // QUIRK - Booleans and conditionals are executed right to left. Or maybe not, depending on who you believe. // LUA - Short circiuts boolean operations, and goes left to right. // 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. // Note that the above means that "and/or" can return any type. - {LSL_BOOL_OR, ST_BOOLEAN, "||", LSL_RIGHT2LEFT, NULL, evaluateOperationToken}, - {LSL_BIT_OR, ST_BITWISE, "|", LSL_LEFT2RIGHT, outputBitOp, evaluateOperationToken}, - {LSL_BIT_XOR, ST_BITWISE, "^", LSL_LEFT2RIGHT, outputBitOp, evaluateOperationToken}, - {LSL_BIT_AND, ST_BITWISE, "&", LSL_LEFT2RIGHT, outputBitOp, evaluateOperationToken}, + {LSL_BOOL_OR, ST_BOOLEAN, "||", LSL_RIGHT2LEFT, NULL}, + {LSL_BIT_OR, ST_BITWISE, "|", LSL_LEFT2RIGHT, outputBitOp}, + {LSL_BIT_XOR, ST_BITWISE, "^", LSL_LEFT2RIGHT, outputBitOp}, + {LSL_BIT_AND, ST_BITWISE, "&", LSL_LEFT2RIGHT, outputBitOp}, // QUIRK - Booleans and conditionals are executed right to left. Or maybe not, depending on who you believe. - {LSL_NOT_EQUAL, ST_EQUALITY, "!=", LSL_RIGHT2LEFT, NULL, evaluateOperationToken}, - {LSL_EQUAL, ST_EQUALITY, "==", LSL_RIGHT2LEFT, NULL, evaluateOperationToken}, - {LSL_GREATER_EQUAL, ST_COMPARISON, ">=", LSL_RIGHT2LEFT, NULL, evaluateOperationToken}, - {LSL_LESS_EQUAL, ST_COMPARISON, "<=", LSL_RIGHT2LEFT, NULL, evaluateOperationToken}, - {LSL_GREATER_THAN, ST_COMPARISON, ">", LSL_RIGHT2LEFT, NULL, evaluateOperationToken}, - {LSL_LESS_THAN, ST_COMPARISON, "<", LSL_RIGHT2LEFT, NULL, evaluateOperationToken}, + {LSL_NOT_EQUAL, ST_EQUALITY, "!=", LSL_RIGHT2LEFT, NULL}, + {LSL_EQUAL, ST_EQUALITY, "==", LSL_RIGHT2LEFT, NULL}, + {LSL_GREATER_EQUAL, ST_COMPARISON, ">=", LSL_RIGHT2LEFT, NULL}, + {LSL_LESS_EQUAL, ST_COMPARISON, "<=", LSL_RIGHT2LEFT, NULL}, + {LSL_GREATER_THAN, ST_COMPARISON, ">", LSL_RIGHT2LEFT, NULL}, + {LSL_LESS_THAN, ST_COMPARISON, "<", LSL_RIGHT2LEFT, NULL}, // 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. // 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. - {LSL_RIGHT_SHIFT, ST_BITWISE, ">>", LSL_LEFT2RIGHT, outputBitOp, evaluateOperationToken}, - {LSL_LEFT_SHIFT, ST_BITWISE, "<<", LSL_LEFT2RIGHT, outputBitOp, evaluateOperationToken}, - {LSL_CONCATENATE, ST_ADD, "+", LSL_LEFT2RIGHT, NULL, evaluateOperationToken}, - {LSL_ADD, ST_ADD, "+", LSL_LEFT2RIGHT, NULL, evaluateOperationToken}, - {LSL_SUBTRACT, ST_SUBTRACT, "-", LSL_LEFT2RIGHT, NULL, evaluateOperationToken}, - {LSL_CROSS_PRODUCT, ST_NONE, "%", LSL_LEFT2RIGHT, NULL, evaluateOperationToken}, - {LSL_DOT_PRODUCT, ST_NONE, "*", LSL_LEFT2RIGHT, NULL, evaluateOperationToken}, - {LSL_MULTIPLY, ST_MULTIPLY, "*", LSL_LEFT2RIGHT, NULL, evaluateOperationToken}, - {LSL_MODULO, ST_MODULO, "%", LSL_LEFT2RIGHT, NULL, evaluateOperationToken}, - {LSL_DIVIDE, ST_MULTIPLY, "/", LSL_LEFT2RIGHT, NULL, evaluateOperationToken}, - {LSL_NEGATION, ST_NEGATE, "-", LSL_RIGHT2LEFT | LSL_UNARY, NULL, evaluateOperationToken}, - {LSL_BOOL_NOT, ST_BOOL_NOT, "!", LSL_RIGHT2LEFT | LSL_UNARY, NULL, evaluateOperationToken}, - {LSL_BIT_NOT, ST_BIT_NOT, "~", LSL_RIGHT2LEFT | LSL_UNARY, outputBitOp, evaluateOperationToken}, + {LSL_RIGHT_SHIFT, ST_BITWISE, ">>", LSL_LEFT2RIGHT, outputBitOp}, + {LSL_LEFT_SHIFT, ST_BITWISE, "<<", LSL_LEFT2RIGHT, outputBitOp}, + {LSL_CONCATENATE, ST_ADD, "+", LSL_LEFT2RIGHT, NULL}, + {LSL_ADD, ST_ADD, "+", LSL_LEFT2RIGHT, NULL}, + {LSL_SUBTRACT, ST_SUBTRACT, "-", LSL_LEFT2RIGHT, NULL}, + {LSL_CROSS_PRODUCT, ST_NONE, "%", LSL_LEFT2RIGHT, NULL}, + {LSL_DOT_PRODUCT, ST_NONE, "*", LSL_LEFT2RIGHT, NULL}, + {LSL_MULTIPLY, ST_MULTIPLY, "*", LSL_LEFT2RIGHT, NULL}, + {LSL_MODULO, ST_MODULO, "%", LSL_LEFT2RIGHT, NULL}, + {LSL_DIVIDE, ST_MULTIPLY, "/", LSL_LEFT2RIGHT, NULL}, + {LSL_NEGATION, ST_NEGATE, "-", LSL_RIGHT2LEFT | LSL_UNARY, NULL}, + {LSL_BOOL_NOT, ST_BOOL_NOT, "!", LSL_RIGHT2LEFT | LSL_UNARY, NULL}, + {LSL_BIT_NOT, ST_BIT_NOT, "~", LSL_RIGHT2LEFT | LSL_UNARY, outputBitOp}, // LUA precedence - (it has no bit operators, at least not until 5.2, but LuaJIT has them.) // or @@ -89,72 +83,72 @@ LSL_Token LSL_Tokens[] = // not negate // exponentiation (^) - {LSL_TYPECAST_CLOSE, ST_NONE, ")", LSL_RIGHT2LEFT | LSL_UNARY, NULL, evaluateNoToken}, - {LSL_TYPECAST_OPEN, ST_NONE, "(", LSL_RIGHT2LEFT | LSL_UNARY, outputParenthesisToken, evaluateOperationToken}, - {LSL_ANGLE_CLOSE, ST_NONE, ">", LSL_LEFT2RIGHT | LSL_CREATION, NULL, evaluateNoToken}, - {LSL_ANGLE_OPEN, ST_NONE, "<", LSL_LEFT2RIGHT | LSL_CREATION, NULL, evaluateOperationToken}, - {LSL_BRACKET_CLOSE, ST_NONE, "]", LSL_INNER2OUTER | LSL_CREATION, NULL, evaluateNoToken}, - {LSL_BRACKET_OPEN, ST_NONE, "[", LSL_INNER2OUTER | LSL_CREATION, NULL, evaluateOperationToken}, - {LSL_PARENTHESIS_CLOSE, ST_NONE, ")", LSL_INNER2OUTER, NULL, evaluateNoToken}, - {LSL_PARENTHESIS_OPEN, ST_NONE, "(", LSL_INNER2OUTER, outputParenthesisToken, eveluateParenthesisToken}, - {LSL_DOT, ST_NONE, ".", LSL_RIGHT2LEFT, NULL, evaluateOperationToken}, - {LSL_DECREMENT_POST, ST_NONE, "--", LSL_RIGHT2LEFT | LSL_UNARY, outputCrementsToken, evaluateOperationToken}, - {LSL_DECREMENT_PRE, ST_NONE, "--", LSL_RIGHT2LEFT | LSL_UNARY, outputCrementsToken, evaluateOperationToken}, - {LSL_INCREMENT_POST, ST_NONE, "++", LSL_RIGHT2LEFT | LSL_UNARY, outputCrementsToken, evaluateOperationToken}, - {LSL_INCREMENT_PRE, ST_NONE, "++", LSL_RIGHT2LEFT | LSL_UNARY, outputCrementsToken, evaluateOperationToken}, - {LSL_COMMA, ST_NONE, ",", LSL_LEFT2RIGHT, NULL, evaluateOperationToken}, - - {LSL_EXPRESSION, ST_NONE, "expression", LSL_NONE , NULL, NULL}, + {LSL_TYPECAST_CLOSE, ST_NONE, ")", LSL_RIGHT2LEFT | LSL_UNARY, NULL}, + {LSL_TYPECAST_OPEN, ST_NONE, "(", LSL_RIGHT2LEFT | LSL_UNARY, outputParenthesisToken}, + {LSL_ANGLE_CLOSE, ST_NONE, ">", LSL_LEFT2RIGHT | LSL_CREATION, NULL}, + {LSL_ANGLE_OPEN, ST_NONE, "<", LSL_LEFT2RIGHT | LSL_CREATION, NULL}, + {LSL_BRACKET_CLOSE, ST_NONE, "]", LSL_INNER2OUTER | LSL_CREATION, NULL}, + {LSL_BRACKET_OPEN, ST_NONE, "[", LSL_INNER2OUTER | LSL_CREATION, NULL}, + {LSL_PARENTHESIS_CLOSE, ST_NONE, ")", LSL_INNER2OUTER, NULL}, + {LSL_PARENTHESIS_OPEN, ST_NONE, "(", LSL_INNER2OUTER, outputParenthesisToken}, + {LSL_DOT, ST_NONE, ".", LSL_RIGHT2LEFT, NULL}, + {LSL_DECREMENT_POST, ST_NONE, "--", LSL_RIGHT2LEFT | LSL_UNARY, outputCrementsToken}, + {LSL_DECREMENT_PRE, ST_NONE, "--", LSL_RIGHT2LEFT | LSL_UNARY, outputCrementsToken}, + {LSL_INCREMENT_POST, ST_NONE, "++", LSL_RIGHT2LEFT | LSL_UNARY, outputCrementsToken}, + {LSL_INCREMENT_PRE, ST_NONE, "++", LSL_RIGHT2LEFT | LSL_UNARY, outputCrementsToken}, + {LSL_COMMA, ST_NONE, ",", LSL_LEFT2RIGHT, NULL}, + + {LSL_EXPRESSION, ST_NONE, "expression", LSL_NONE , NULL}, // Types. - {LSL_FLOAT, ST_NONE, "float", LSL_NONE, outputFloatToken, evaluateFloatToken}, - {LSL_INTEGER, ST_NONE, "integer", LSL_NONE, outputIntegerToken, evaluateIntegerToken}, - {LSL_KEY, ST_NONE, "key", LSL_NONE, outputStringToken, NULL}, - {LSL_LIST, ST_NONE, "list", LSL_NONE, outputListToken, NULL}, - {LSL_ROTATION, ST_NONE, "rotation", LSL_NONE, outputListToken, NULL}, - {LSL_STRING, ST_NONE, "string", LSL_NONE, outputStringToken, NULL}, - {LSL_VECTOR, ST_NONE, "vector", LSL_NONE, outputListToken, NULL}, + {LSL_FLOAT, ST_NONE, "float", LSL_NONE, outputFloatToken}, + {LSL_INTEGER, ST_NONE, "integer", LSL_NONE, outputIntegerToken}, + {LSL_KEY, ST_NONE, "key", LSL_NONE, outputStringToken}, + {LSL_LIST, ST_NONE, "list", LSL_NONE, outputListToken}, + {LSL_ROTATION, ST_NONE, "rotation", LSL_NONE, outputListToken}, + {LSL_STRING, ST_NONE, "string", LSL_NONE, outputStringToken}, + {LSL_VECTOR, ST_NONE, "vector", LSL_NONE, outputListToken}, // Types names. - {LSL_TYPE_FLOAT, ST_NONE, "float", LSL_TYPE, NULL, NULL}, - {LSL_TYPE_INTEGER, ST_NONE, "integer", LSL_TYPE, NULL, NULL}, - {LSL_TYPE_KEY, ST_NONE, "key", LSL_TYPE, NULL, NULL}, - {LSL_TYPE_LIST, ST_NONE, "list", LSL_TYPE, NULL, NULL}, - {LSL_TYPE_ROTATION, ST_NONE, "rotation", LSL_TYPE, NULL, NULL}, - {LSL_TYPE_STRING, ST_NONE, "string", LSL_TYPE, NULL, NULL}, - {LSL_TYPE_VECTOR, ST_NONE, "vector", LSL_TYPE, NULL, NULL}, + {LSL_TYPE_FLOAT, ST_NONE, "float", LSL_TYPE, NULL}, + {LSL_TYPE_INTEGER, ST_NONE, "integer", LSL_TYPE, NULL}, + {LSL_TYPE_KEY, ST_NONE, "key", LSL_TYPE, NULL}, + {LSL_TYPE_LIST, ST_NONE, "list", LSL_TYPE, NULL}, + {LSL_TYPE_ROTATION, ST_NONE, "rotation", LSL_TYPE, NULL}, + {LSL_TYPE_STRING, ST_NONE, "string", LSL_TYPE, NULL}, + {LSL_TYPE_VECTOR, ST_NONE, "vector", LSL_TYPE, NULL}, // Then the rest of the syntax tokens. - {LSL_FUNCTION_CALL, ST_NONE, "funccall", LSL_NONE, outputFunctionCallToken, NULL}, - {LSL_IDENTIFIER, ST_NONE, "identifier", LSL_NONE, outputIdentifierToken, NULL}, - {LSL_VARIABLE, ST_NONE, "variable", LSL_NONE, outputIdentifierToken, NULL}, - - {LSL_LABEL, ST_NONE, "@", LSL_NONE, NULL, NULL}, - - {LSL_DO, ST_NONE, "do", LSL_NONE, NULL, NULL}, - {LSL_FOR, ST_NONE, "for", LSL_NONE, NULL, NULL}, - {LSL_ELSE, ST_NONE, "else", LSL_NONE, NULL, NULL}, - {LSL_ELSEIF, ST_NONE, "elseif", LSL_NONE, NULL, NULL}, - {LSL_IF, ST_NONE, "if", LSL_NONE, NULL, NULL}, - {LSL_JUMP, ST_NONE, "jump", LSL_NONE, NULL, NULL}, - {LSL_RETURN, ST_NONE, "return", LSL_NONE, NULL, NULL}, - {LSL_STATE_CHANGE, ST_NONE, "state", LSL_NONE, NULL, NULL}, - {LSL_WHILE, ST_NONE, "while", LSL_NONE, NULL, NULL}, - {LSL_STATEMENT, ST_NONE, ";", LSL_NOIGNORE, outputStatementToken, evaluateStatementToken}, - - {LSL_BLOCK_CLOSE, ST_NONE, "}", LSL_NONE, NULL, NULL}, - {LSL_BLOCK_OPEN, ST_NONE, "{", LSL_NONE, outputBlockToken, NULL}, - {LSL_PARAMETER, ST_NONE, "parameter", LSL_NONE, outputIdentifierToken, NULL}, - {LSL_PARAMETER_LIST, ST_NONE, "plist", LSL_NONE, outputParameterListToken, NULL}, - {LSL_FUNCTION, ST_NONE, "function", LSL_NONE, outputFunctionToken, NULL}, - {LSL_DEFAULT, ST_NONE, "default", LSL_NONE, outputStateToken, NULL}, - {LSL_STATE, ST_NONE, "state", LSL_NONE, outputStateToken, NULL}, - {LSL_SCRIPT, ST_NONE, "", LSL_NONE, NULL, NULL}, - - {LSL_UNKNOWN, ST_NONE, "unknown", LSL_NONE, NULL, NULL}, + {LSL_FUNCTION_CALL, ST_NONE, "funccall", LSL_NONE, outputFunctionCallToken}, + {LSL_IDENTIFIER, ST_NONE, "identifier", LSL_NONE, outputIdentifierToken}, + {LSL_VARIABLE, ST_NONE, "variable", LSL_NONE, outputIdentifierToken}, + + {LSL_LABEL, ST_NONE, "@", LSL_NONE, NULL}, + + {LSL_DO, ST_NONE, "do", LSL_NONE, NULL}, + {LSL_FOR, ST_NONE, "for", LSL_NONE, NULL}, + {LSL_ELSE, ST_NONE, "else", LSL_NONE, NULL}, + {LSL_ELSEIF, ST_NONE, "elseif", LSL_NONE, NULL}, + {LSL_IF, ST_NONE, "if", LSL_NONE, NULL}, + {LSL_JUMP, ST_NONE, "jump", LSL_NONE, NULL}, + {LSL_RETURN, ST_NONE, "return", LSL_NONE, NULL}, + {LSL_STATE_CHANGE, ST_NONE, "state", LSL_NONE, NULL}, + {LSL_WHILE, ST_NONE, "while", LSL_NONE, NULL}, + {LSL_STATEMENT, ST_NONE, ";", LSL_NOIGNORE, outputStatementToken}, + + {LSL_BLOCK_CLOSE, ST_NONE, "}", LSL_NONE, NULL}, + {LSL_BLOCK_OPEN, ST_NONE, "{", LSL_NONE, outputBlockToken}, + {LSL_PARAMETER, ST_NONE, "parameter", LSL_NONE, outputIdentifierToken}, + {LSL_PARAMETER_LIST, ST_NONE, "plist", LSL_NONE, outputParameterListToken}, + {LSL_FUNCTION, ST_NONE, "function", LSL_NONE, outputFunctionToken}, + {LSL_DEFAULT, ST_NONE, "default", LSL_NONE, outputStateToken}, + {LSL_STATE, ST_NONE, "state", LSL_NONE, outputStateToken}, + {LSL_SCRIPT, ST_NONE, "", LSL_NONE, NULL}, + + {LSL_UNKNOWN, ST_NONE, "unknown", LSL_NONE, NULL}, // A sentinal. - {999999, ST_NONE, NULL, LSL_NONE, NULL, NULL} + {999999, ST_NONE, NULL, LSL_NONE, NULL} }; // VERY IMPORTANT to keep this in sync with enum opType from LuaSL_LSL_tree.h! @@ -1196,6 +1190,66 @@ LSL_Leaf *collectStatements(LuaSL_compiler *compiler, LSL_Leaf *list, LSL_Leaf * return list; } +/* Typecasting + +LSL is statically typed, so stored values are not converted, only the values used in expressions are. +Lua is dynamically typed, so stored values are changed (sometimes I think). + +LSL implicitly typecasts - There is a shitload of QUIRKs about this. Apparently some don't work anyway. + integer -> float (Says in lslwiki that precision is never lost, which is bullshit, since they are both 32 bit. Would be true if the float is 64 bit. Lua suggest to use 64 bit floats to emulate 32 bit integers.) + string -> key + Some functions need help with this or the other way around. + string -> vector (Maybe, should test that.) + vector -> string (Maybe, should test that.) + Also happens when getting stuff from lists. + +Explicit type casting - + string -> integer + Leading spaces are ignored, as are any characters after the run of digits. + All other strings convert to 0. + Which means "" and " " convert to 0. + Strings in hexadecimal format will work, same in Lua (though Lua can't handle "0x", but "0x0" is fine). + keys <-> string + No other typecasting can be done with keys. + float -> string + You get a bunch of trailing 0s. + +QUIRK - I have seen cases where a double explicit typecast was needed in SL, but was considered to be invalid syntax in OS. + +Any binary operation involving a float and an integer implicitly casts the integer to float. + +A boolean operation deals with TRUE (1) and FALSE (0). Any non zero value is a TRUE (generally sigh). +On the other hand, in Lua, only false and nil are false, everything else is true. +Bitwise operations only apply to integers. The shifts are arithmatic, not logical. Right shifted bits are dropped, left shifts the sign bit. + +integer = integer0 % integer1; // Apparently only applies to integers, but works fine on floats in OS. +string = string0 + string1; // Concatenation. +list = list0 + list1; // Concatenation. Also works if either is not a list, it's promoted to a list first. +list = (list=[]) + list + ["new_item"]; // Voodoo needed for old LSL, works in Mono but not needed, does not work in OS. Works for strings to. +bool = list == != int // Only compares the lengths, probably applies to the other conditionals to. +vector = vector0 + vector1; // Add elements together. +vector = vector0 - vector1; // Subtract elements of vector1 from elements of vector0. +float = vector0 * vector1; // A dot product of the vectors. +vector = vector0 % vector1; // A cross product of the vectors. +vector = vector * float; // Scale the vector, works the other way around I think. Works for integer to, but it will end up being cast to float. +vector = vector / float; // Scale the vector, works the other way around I think. Works for integer to, but it will end up being cast to float. +vector = vector * rotation; // Rotate the vector by the rotation. Other way around wont compile. +vector = vector / rotation; // Rotate the vector by the rotation, in the opposite direction. Other way around wont compile. +rotation = llGetRot() * rotation; // Rotate an object around the global axis. +rotation = rotation * llGetLocalRot(); // Rotate an object around the local axis. +rotation = rotation0 * rotation1; // Add two rotations, so the result is as if you applied each rotation one after the other. + // Division rotates in the opposite direction. +rotation = rotation0 + rotation1; // Similar to vector, but it's a meaningless thing as far as rotations go. +rotation = rotation0 - rotation1; // Similar to vector, but it's a meaningless thing as far as rotations go. + +A boolean operator results in a boolean value. (any types) +A comparison operator results in a boolean value. (any types) +A bitwise operator results in an integer value. (intInt or int) +A dot product operator results in a float value. (vector * vector) +A vectorFloat results in a vector value. + +*/ + LSL_Leaf *addTypecast(LSL_Leaf *lval, LSL_Leaf *type, LSL_Leaf *rval, LSL_Leaf *expr) { addParenthesis(lval, expr, LSL_TYPECAST_OPEN, rval); @@ -1295,372 +1349,6 @@ static void secondPass(LuaSL_compiler *compiler, LSL_Leaf *leaf) } } -static LSL_Leaf *evaluateLeaf(LSL_Leaf *leaf, LSL_Leaf *left, LSL_Leaf *right) -{ - LSL_Leaf *result = NULL; - - if (leaf) - { - LSL_Leaf *lresult = NULL; - LSL_Leaf *rresult = NULL; - - if (LSL_RIGHT2LEFT & leaf->toKen->flags) - { - rresult = evaluateLeaf(leaf->right, left, right); - if (!(LSL_UNARY & leaf->toKen->flags)) - lresult = evaluateLeaf(leaf->left, left, right); - } - else // Assume left to right. - { - lresult = evaluateLeaf(leaf->left, left, right); - if (!(LSL_UNARY & leaf->toKen->flags)) - rresult = evaluateLeaf(leaf->right, left, right); - } - - if (leaf->toKen->evaluate) - result = leaf->toKen->evaluate(leaf, lresult, rresult); - else - { - result = newLeaf(LSL_UNKNOWN, NULL, NULL); - if (rresult && result) - memcpy(result, rresult, sizeof(LSL_Leaf)); - } - - if (lresult) - free(lresult); - if (rresult) - free(rresult); - } - - return result; -} - -static LSL_Leaf *evaluateFloatToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right) -{ - LSL_Leaf *result = newLeaf(LSL_FLOAT, NULL, NULL); - - if (content && result) - { - memcpy(result, content, sizeof(LSL_Leaf)); - result->value.floatValue = content->value.numbyValue->value.floatValue; - result->basicType = OT_float; - if (LUASL_DEBUG) - printf(" <%g> ", content->value.floatValue); - } - return result; -} - -static LSL_Leaf *evaluateIntegerToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right) -{ - LSL_Leaf *result = newLeaf(LSL_INTEGER, NULL, NULL); - - if (content && result) - { - memcpy(result, content, sizeof(LSL_Leaf)); - result->value.integerValue = content->value.numbyValue->value.integerValue; - result->basicType = OT_integer; - if (LUASL_DEBUG) - printf(" <%d> ", result->value.integerValue); - } - return result; -} - -static LSL_Leaf *evaluateNoToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right) -{ - // Do nothing, that's the point. - - return content; -} - -/* Typecasting - -LSL is statically typed, so stored values are not converted, only the values used in expressions are. -Lua is dynamically typed, so stored values are changed (sometimes I think). - -LSL implicitly typecasts - There is a shitload of QUIRKs about this. Apparently some don't work anyway. - integer -> float (Says in lslwiki that precision is never lost, which is bullshit, since they are both 32 bit. Would be true if the float is 64 bit. Lua suggest to use 64 bit floats to emulate 32 bit integers.) - string -> key - Some functions need help with this or the other way around. - string -> vector (Maybe, should test that.) - vector -> string (Maybe, should test that.) - Also happens when getting stuff from lists. - -Explicit type casting - - string -> integer - Leading spaces are ignored, as are any characters after the run of digits. - All other strings convert to 0. - Which means "" and " " convert to 0. - Strings in hexadecimal format will work, same in Lua (though Lua can't handle "0x", but "0x0" is fine). - keys <-> string - No other typecasting can be done with keys. - float -> string - You get a bunch of trailing 0s. - -QUIRK - I have seen cases where a double explicit typecast was needed in SL, but was considered to be invalid syntax in OS. - -Any binary operation involving a float and an integer implicitly casts the integer to float. - -A boolean operation deals with TRUE (1) and FALSE (0). Any non zero value is a TRUE (generally sigh). -On the other hand, in Lua, only false and nil are false, everything else is true. -Bitwise operations only apply to integers. The shifts are arithmatic, not logical. Right shifted bits are dropped, left shifts the sign bit. - -integer = integer0 % integer1; // Apparently only applies to integers, but works fine on floats in OS. -string = string0 + string1; // Concatenation. -list = list0 + list1; // Concatenation. Also works if either is not a list, it's promoted to a list first. -list = (list=[]) + list + ["new_item"]; // Voodoo needed for old LSL, works in Mono but not needed, does not work in OS. Works for strings to. -bool = list == != int // Only compares the lengths, probably applies to the other conditionals to. -vector = vector0 + vector1; // Add elements together. -vector = vector0 - vector1; // Subtract elements of vector1 from elements of vector0. -float = vector0 * vector1; // A dot product of the vectors. -vector = vector0 % vector1; // A cross product of the vectors. -vector = vector * float; // Scale the vector, works the other way around I think. Works for integer to, but it will end up being cast to float. -vector = vector / float; // Scale the vector, works the other way around I think. Works for integer to, but it will end up being cast to float. -vector = vector * rotation; // Rotate the vector by the rotation. Other way around wont compile. -vector = vector / rotation; // Rotate the vector by the rotation, in the opposite direction. Other way around wont compile. -rotation = llGetRot() * rotation; // Rotate an object around the global axis. -rotation = rotation * llGetLocalRot(); // Rotate an object around the local axis. -rotation = rotation0 * rotation1; // Add two rotations, so the result is as if you applied each rotation one after the other. - // Division rotates in the opposite direction. -rotation = rotation0 + rotation1; // Similar to vector, but it's a meaningless thing as far as rotations go. -rotation = rotation0 - rotation1; // Similar to vector, but it's a meaningless thing as far as rotations go. - -A boolean operator results in a boolean value. (any types) -A comparison operator results in a boolean value. (any types) -A bitwise operator results in an integer value. (intInt or int) -A dot product operator results in a float value. (vector * vector) -A vectorFloat results in a vector value. - -*/ - -static LSL_Leaf *evaluateOperationToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right) -{ - LSL_Leaf *result = newLeaf(LSL_UNKNOWN, NULL, NULL); - - if (content && result) - { - if (LUASL_DEBUG) - printf(" [%s] ", content->toKen->toKen); - - memcpy(result, content, sizeof(LSL_Leaf)); - - // Figure out the type of the operation. - if (OT_vector < result->basicType) - result->basicType = allowed[result->basicType].result; - - switch (result->basicType) - { - case OT_float : - { - float fleft = left->value.floatValue; - float fright = right->value.floatValue; - - // Do the casting. - if (OT_floatInt == content->basicType) - fright = right->value.integerValue; - if (OT_intFloat == content->basicType) - fleft = left->value.integerValue; - switch (result->toKen->type) - { - case LSL_COMMA : - case LSL_INCREMENT_PRE : - case LSL_INCREMENT_POST : - case LSL_DECREMENT_PRE : - case LSL_DECREMENT_POST : - case LSL_ASSIGNMENT_PLAIN : - case LSL_ASSIGNMENT_DIVIDE : - case LSL_ASSIGNMENT_MULTIPLY : - case LSL_ASSIGNMENT_SUBTRACT : - case LSL_ASSIGNMENT_ADD : - case LSL_BRACKET_OPEN : - case LSL_BRACKET_CLOSE : - case LSL_ANGLE_OPEN : - case LSL_ANGLE_CLOSE : - case LSL_TYPECAST_OPEN : - case LSL_TYPECAST_CLOSE : - case LSL_DOT_PRODUCT : - break; - case LSL_NEGATION : result->value.floatValue = 0 - fright; break; - case LSL_DIVIDE : result->value.floatValue = fleft / fright; break; - case LSL_MULTIPLY : result->value.floatValue = fleft * fright; break; - case LSL_SUBTRACT : result->value.floatValue = fleft - fright; break; - case LSL_ADD : result->value.floatValue = fleft + fright; break; - case LSL_LESS_THAN : result->value.floatValue = fleft < fright; break; - case LSL_GREATER_THAN : result->value.floatValue = fleft > fright; break; - case LSL_LESS_EQUAL : result->value.floatValue = fleft <= fright; break; - case LSL_GREATER_EQUAL : result->value.floatValue = fleft >= fright; break; - case LSL_EQUAL : result->value.floatValue = fleft == fright; break; - case LSL_NOT_EQUAL : result->value.floatValue = fleft != fright; break; - } - if (LUASL_DEBUG) - printf(" (=%g) ", result->value.floatValue); - break; - } - - case OT_integer : - { - switch (result->toKen->type) - { - case LSL_COMMA : - case LSL_INCREMENT_PRE : - case LSL_INCREMENT_POST : - case LSL_DECREMENT_PRE : - case LSL_DECREMENT_POST : - case LSL_DOT : - case LSL_ASSIGNMENT_PLAIN : - case LSL_ASSIGNMENT_DIVIDE : - case LSL_ASSIGNMENT_MODULO : - case LSL_ASSIGNMENT_MULTIPLY : - case LSL_ASSIGNMENT_SUBTRACT : - case LSL_ASSIGNMENT_ADD : - case LSL_BRACKET_OPEN : - case LSL_BRACKET_CLOSE : - case LSL_ANGLE_OPEN : - case LSL_ANGLE_CLOSE : - case LSL_TYPECAST_OPEN : - case LSL_TYPECAST_CLOSE : - break; - case LSL_BIT_NOT : result->value.integerValue = ~ right->value.integerValue; break; - case LSL_BOOL_NOT : result->value.integerValue = ! right->value.integerValue; break; - case LSL_NEGATION : result->value.integerValue = 0 - right->value.integerValue; break; - case LSL_DIVIDE : result->value.integerValue = left->value.integerValue / right->value.integerValue; break; - case LSL_MODULO : result->value.integerValue = left->value.integerValue % right->value.integerValue; break; - case LSL_MULTIPLY : result->value.integerValue = left->value.integerValue * right->value.integerValue; break; - case LSL_SUBTRACT : result->value.integerValue = left->value.integerValue - right->value.integerValue; break; - case LSL_ADD : result->value.integerValue = left->value.integerValue + right->value.integerValue; break; - case LSL_LEFT_SHIFT : result->value.integerValue = left->value.integerValue << right->value.integerValue; break; - case LSL_RIGHT_SHIFT : result->value.integerValue = left->value.integerValue >> right->value.integerValue; break; - case LSL_LESS_THAN : result->value.integerValue = left->value.integerValue < right->value.integerValue; break; - case LSL_GREATER_THAN : result->value.integerValue = left->value.integerValue > right->value.integerValue; break; - case LSL_LESS_EQUAL : result->value.integerValue = left->value.integerValue <= right->value.integerValue; break; - case LSL_GREATER_EQUAL : result->value.integerValue = left->value.integerValue >= right->value.integerValue; break; - case LSL_EQUAL : result->value.integerValue = left->value.integerValue == right->value.integerValue; break; - case LSL_NOT_EQUAL : result->value.integerValue = left->value.integerValue != right->value.integerValue; break; - case LSL_BIT_AND : result->value.integerValue = left->value.integerValue & right->value.integerValue; break; - case LSL_BIT_XOR : result->value.integerValue = left->value.integerValue ^ right->value.integerValue; break; - case LSL_BIT_OR : result->value.integerValue = left->value.integerValue | right->value.integerValue; break; - case LSL_BOOL_OR : result->value.integerValue = left->value.integerValue || right->value.integerValue; break; - case LSL_BOOL_AND : result->value.integerValue = left->value.integerValue && right->value.integerValue; break; - } - if (LUASL_DEBUG) - printf(" (=%d) ", result->value.integerValue); - break; - } - - default : - break; - } - } - return result; -} - -static LSL_Leaf *eveluateParenthesisToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right) -{ - LSL_Leaf *result = NULL; - - if (content) - { - if ((LSL_PARAMETER_LIST != content->value.parenthesis->type) && (LSL_LIST != content->value.parenthesis->type)) - result = evaluateLeaf(content->value.parenthesis->contents, left, right); - } - return result; -} - -static LSL_Leaf *evaluateStatementToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right) -{ - LSL_Leaf *result = NULL; - - if (content) - { - switch (content->value.statementValue->type) - { - case LSL_EXPRESSION : - { - result = evaluateLeaf(content->value.statementValue->expressions, left, right); - break; - } - case LSL_FUNCTION : - { - break; - } - case LSL_DO : - { - break; - } - case LSL_FOR : - { - break; - } - case LSL_IF : - { - break; - } - case LSL_ELSE : - { - break; - } - case LSL_ELSEIF : - { - break; - } - case LSL_JUMP : - { - break; - } - case LSL_LABEL : - { - break; - } - case LSL_RETURN : - { - break; - } - case LSL_STATE_CHANGE : - { - break; - } - case LSL_STATEMENT : - { - result = evaluateLeaf(content->value.statementValue->expressions, left, right); - break; - } - case LSL_WHILE : - { - break; - } - case LSL_IDENTIFIER : - { - break; - } - case LSL_VARIABLE : - { - break; - } - default : - { -// PE("Should not be here %d.", type); - break; - } - } - - if (result) - { - switch (result->basicType) - { - case OT_float : printf("Result is the float %g.\n", result->value.floatValue); break; - case OT_integer : printf("Result is the integer %d.\n", result->value.integerValue); break; - default : /*printf("\nResult of an unknown type [%d] %d!\n", result->basicType, result->value.integerValue);*/ break; - } - free(result); - result = NULL; - } - if (left) - left->value.integerValue = 0; - if (right) - right->value.integerValue = 0; - } - return result; -} - static void outputLeaf(FILE *file, outputMode mode, LSL_Leaf *leaf) { if (leaf) @@ -2425,11 +2113,6 @@ static boolean doneParsing(LuaSL_compiler *compiler) char luaName[PATH_MAX]; int count; -// outputLeaf(stdout, OM_LSL, compiler->ast); -// printf("\n"); - evaluateLeaf(compiler->ast, NULL, NULL); -// printf("\n"); - if (LUASL_DIFF_CHECK) { strcpy(outName, compiler->fileName); @@ -2444,11 +2127,11 @@ static boolean doneParsing(LuaSL_compiler *compiler) outputLeaf(out, OM_LSL, compiler->ast); fclose(out); sprintf(buffer, "diff -u \"%s\" \"%s\" > \"%s\"", compiler->fileName, outName, diffName); -// count = system(buffer); -// if (0 != count) -// PE("LSL output file is different - %s!", outName); -// else -// result = TRUE; + count = system(buffer); + if (0 != count) + PE("LSL output file is different - %s!", outName); + else + result = TRUE; } else PC("Unable to open file %s for writing!", outName); @@ -2616,18 +2299,8 @@ boolean compileLSL(gameGlobals *game, char *script, boolean doConstants) result = TRUE; } else - { result = doneParsing(&compiler); -// Take the result of the parse, and convert it into Lua source. -// Each LSL script becomes a Lua state. -// LSL states are handled as Lua tables, with each LSL state function being a table function in a common metatable. -// LL and OS functions are likely to be C functions. - -// Compile the Lua source by the Lua compiler. - - } - if (NULL != compiler.file) { fclose(compiler.file); @@ -2639,136 +2312,3 @@ boolean compileLSL(gameGlobals *game, char *script, boolean doConstants) return result; } - - -// Code for running it stand alone, and with files input on the command line. -#if 0 -static int nextFile(LuaSL_yyparseParam *param) -{ - if (NULL != param->file) - { - fclose(param->file); - param->file = NULL; - } - if (--(param->argc) > 0 && *++(param->argv) != '\0') - { - strncpy(param->fileName, *(param->argv), PATH_MAX - 1); - param->fileName[PATH_MAX - 1] = '\0'; - param->file = fopen(param->fileName, "r"); - if (NULL == param->file) - { - PE(stderr, "Error opening file %s.", param->fileName); - return FALSE; - } - PE("Opened %s.", param->fileName); - burnLeaf(param->ast); - param->ast = NULL; - param->lval = newLeaf(LSL_UNKNOWN, NULL, NULL); - // Text editors usually start counting at 1, even programmers editors. - param->column = 1; - param->line = 1; - return TRUE; - } -/* - if ('\0' == fileName[0]) - { -//strcpy(fileName, "test.lsl"); - - count = read(STDIN_FILENO, fileName, PATH_MAX - 1); - if (0 > count) - { - printf("Error in stdin!\n"); - return 1; - } - else if (0 == count) - { - printf("No bytes in stdin!\n"); - return 1; - } - else - { - fileName[count] = '\0'; - printf("Filename %s in stdin.\n", fileName); - } - - } -*/ - - return FALSE; -} - -char *test[] = {"test2.lsl", "test2.lsl"}; - -int main(int argc, char **argv) -{ -// char *programName = argv[0]; - int i; - - // Figure out what numbers yacc gave to our tokens. - for (i = 0; LSL_Tokens[i].toKen != NULL; i++) - { - if (lowestToken > LSL_Tokens[i].type) - lowestToken = LSL_Tokens[i].type; - } - tokens = calloc(i + 1, sizeof(LSL_Token *)); - if (tokens) - { - LuaSL_yyparseParam param; - - // Sort the token table. - for (i = 0; LSL_Tokens[i].toKen != NULL; i++) - { - int j = LSL_Tokens[i].type - lowestToken; - - tokens[j] = &(LSL_Tokens[i]); - } - - // First time setup. - if (1 == argc) - { - // Fake a test file if there is none. Mostly for ddd. - argc++; - argv = test; - } - memset(¶m, 0, sizeof(param)); - param.argc = argc; - param.argv = argv; - - // Loop through the files. - while (nextFile(¶m)) - { - void *pParser = ParseAlloc(malloc); - int yv; - - if (yylex_init_extra(¶m, &(param.scanner))) - return 1; - if (LUASL_DEBUG) - { - yyset_debug(1, param.scanner); - ParseTrace(stdout, "LSL_lemon "); - } - yyset_in(param.file, param.scanner); - // on EOF yylex will return 0 - while((yv = yylex(param.lval, param.scanner)) != 0) - { - Parse(pParser, yv, param.lval, ¶m); - if (LSL_SCRIPT == yv) - break; - param.lval = newLeaf(LSL_UNKNOWN, NULL, NULL); - } - - yylex_destroy(param.scanner); - Parse (pParser, 0, param.lval, ¶m); - ParseFree(pParser, free); - doneParsing(¶m); - } - } - else - { - fprintf(stderr, "No memory for tokens!"); - return 1; - } - - return 0; -} -#endif -- cgit v1.1