aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/LuaSL
diff options
context:
space:
mode:
authorDavid Walter Seikel2012-02-05 12:13:18 +1000
committerDavid Walter Seikel2012-02-05 12:13:18 +1000
commit4213ddfa3c5e3fc6ed3cb01f5eb342276df3fc0b (patch)
treeba5c84b55662d4dc6f79c30dd4faa54e33aa9f1e /LuaSL
parentWhite space clean up. (diff)
downloadSledjHamr-4213ddfa3c5e3fc6ed3cb01f5eb342276df3fc0b.zip
SledjHamr-4213ddfa3c5e3fc6ed3cb01f5eb342276df3fc0b.tar.gz
SledjHamr-4213ddfa3c5e3fc6ed3cb01f5eb342276df3fc0b.tar.bz2
SledjHamr-4213ddfa3c5e3fc6ed3cb01f5eb342276df3fc0b.tar.xz
Remove a lot of old cruft that is no longer needed. Including the eveluator, we can do that with test scripts now.
Diffstat (limited to 'LuaSL')
-rw-r--r--LuaSL/src/LuaSL_LSL_tree.h2
-rw-r--r--LuaSL/src/LuaSL_compile.c774
2 files changed, 157 insertions, 619 deletions
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
62} outputMode; 62} outputMode;
63 63
64typedef void (*outputToken) (FILE *file, outputMode mode, LSL_Leaf *content); 64typedef void (*outputToken) (FILE *file, outputMode mode, LSL_Leaf *content);
65typedef LSL_Leaf * (*evaluateToken) (LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right);
66 65
67//#ifndef FALSE 66//#ifndef FALSE
68//typedef enum 67//typedef enum
@@ -175,7 +174,6 @@ struct _LSL_Token
175 const char *toKen; 174 const char *toKen;
176 LSL_Flags flags; 175 LSL_Flags flags;
177 outputToken output; 176 outputToken output;
178 evaluateToken evaluate;
179}; 177};
180 178
181struct _LSL_Text 179struct _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 @@
5*/ 5*/
6 6
7 7
8static LSL_Leaf *evaluateFloatToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right);
9static LSL_Leaf *evaluateIntegerToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right);
10static LSL_Leaf *evaluateNoToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right);
11static LSL_Leaf *evaluateOperationToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right);
12static LSL_Leaf *eveluateParenthesisToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right);
13static LSL_Leaf *evaluateStatementToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right);
14static void outputBitOp(FILE *file, outputMode mode, LSL_Leaf *leaf); 8static void outputBitOp(FILE *file, outputMode mode, LSL_Leaf *leaf);
15static void outputBlockToken(FILE *file, outputMode mode, LSL_Leaf *content); 9static void outputBlockToken(FILE *file, outputMode mode, LSL_Leaf *content);
16static void outputCrementsToken(FILE *file, outputMode mode, LSL_Leaf *content); 10static void outputCrementsToken(FILE *file, outputMode mode, LSL_Leaf *content);
@@ -29,55 +23,55 @@ static void outputStringToken(FILE *file, outputMode mode, LSL_Leaf *content);
29LSL_Token LSL_Tokens[] = 23LSL_Token LSL_Tokens[] =
30{ 24{
31 // Various forms of "space". 25 // Various forms of "space".
32 {LSL_COMMENT, ST_NONE, "/*", LSL_NONE, NULL, NULL}, 26 {LSL_COMMENT, ST_NONE, "/*", LSL_NONE, NULL},
33 {LSL_COMMENT_LINE, ST_NONE, "//", LSL_NONE, NULL, NULL}, 27 {LSL_COMMENT_LINE, ST_NONE, "//", LSL_NONE, NULL},
34 {LSL_SPACE, ST_NONE, " ", LSL_NONE, NULL, NULL}, 28 {LSL_SPACE, ST_NONE, " ", LSL_NONE, NULL},
35 29
36 // Operators, in order of precedence, low to high 30 // Operators, in order of precedence, low to high
37 // Left to right, unless otherwise stated. 31 // Left to right, unless otherwise stated.
38 // 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. 32 // 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.
39 33
40 {LSL_ASSIGNMENT_CONCATENATE,ST_CONCATENATION, "+=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, NULL, evaluateOperationToken}, 34 {LSL_ASSIGNMENT_CONCATENATE,ST_CONCATENATION, "+=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, NULL},
41 {LSL_ASSIGNMENT_ADD, ST_CONCATENATION, "+=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, NULL, evaluateOperationToken}, 35 {LSL_ASSIGNMENT_ADD, ST_CONCATENATION, "+=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, NULL},
42 {LSL_ASSIGNMENT_SUBTRACT, ST_ASSIGNMENT, "-=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, NULL, evaluateOperationToken}, 36 {LSL_ASSIGNMENT_SUBTRACT, ST_ASSIGNMENT, "-=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, NULL},
43 {LSL_ASSIGNMENT_MULTIPLY, ST_ASSIGNMENT, "*=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, NULL, evaluateOperationToken}, 37 {LSL_ASSIGNMENT_MULTIPLY, ST_ASSIGNMENT, "*=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, NULL},
44 {LSL_ASSIGNMENT_MODULO, ST_MODULO, "%=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, NULL, evaluateOperationToken}, 38 {LSL_ASSIGNMENT_MODULO, ST_MODULO, "%=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, NULL},
45 {LSL_ASSIGNMENT_DIVIDE, ST_ASSIGNMENT, "/=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, NULL, evaluateOperationToken}, 39 {LSL_ASSIGNMENT_DIVIDE, ST_ASSIGNMENT, "/=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, NULL},
46 {LSL_ASSIGNMENT_PLAIN, ST_CONCATENATION, "=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, NULL, evaluateOperationToken}, 40 {LSL_ASSIGNMENT_PLAIN, ST_CONCATENATION, "=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, NULL},
47 41
48 {LSL_BOOL_AND, ST_BOOLEAN, "&&", LSL_RIGHT2LEFT, NULL, evaluateOperationToken}, 42 {LSL_BOOL_AND, ST_BOOLEAN, "&&", LSL_RIGHT2LEFT, NULL},
49// 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.
50// QUIRK - No boolean short circuiting. 44// QUIRK - No boolean short circuiting.
51// QUIRK - Booleans and conditionals are executed right to left. Or maybe not, depending on who you believe. 45// QUIRK - Booleans and conditionals are executed right to left. Or maybe not, depending on who you believe.
52// LUA - Short circiuts boolean operations, and goes left to right. 46// LUA - Short circiuts boolean operations, and goes left to right.
53// 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. 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.
54// Note that the above means that "and/or" can return any type. 48// Note that the above means that "and/or" can return any type.
55 {LSL_BOOL_OR, ST_BOOLEAN, "||", LSL_RIGHT2LEFT, NULL, evaluateOperationToken}, 49 {LSL_BOOL_OR, ST_BOOLEAN, "||", LSL_RIGHT2LEFT, NULL},
56 {LSL_BIT_OR, ST_BITWISE, "|", LSL_LEFT2RIGHT, outputBitOp, evaluateOperationToken}, 50 {LSL_BIT_OR, ST_BITWISE, "|", LSL_LEFT2RIGHT, outputBitOp},
57 {LSL_BIT_XOR, ST_BITWISE, "^", LSL_LEFT2RIGHT, outputBitOp, evaluateOperationToken}, 51 {LSL_BIT_XOR, ST_BITWISE, "^", LSL_LEFT2RIGHT, outputBitOp},
58 {LSL_BIT_AND, ST_BITWISE, "&", LSL_LEFT2RIGHT, outputBitOp, evaluateOperationToken}, 52 {LSL_BIT_AND, ST_BITWISE, "&", LSL_LEFT2RIGHT, outputBitOp},
59// QUIRK - Booleans and conditionals are executed right to left. Or maybe not, depending on who you believe. 53// QUIRK - Booleans and conditionals are executed right to left. Or maybe not, depending on who you believe.
60 {LSL_NOT_EQUAL, ST_EQUALITY, "!=", LSL_RIGHT2LEFT, NULL, evaluateOperationToken}, 54 {LSL_NOT_EQUAL, ST_EQUALITY, "!=", LSL_RIGHT2LEFT, NULL},
61 {LSL_EQUAL, ST_EQUALITY, "==", LSL_RIGHT2LEFT, NULL, evaluateOperationToken}, 55 {LSL_EQUAL, ST_EQUALITY, "==", LSL_RIGHT2LEFT, NULL},
62 {LSL_GREATER_EQUAL, ST_COMPARISON, ">=", LSL_RIGHT2LEFT, NULL, evaluateOperationToken}, 56 {LSL_GREATER_EQUAL, ST_COMPARISON, ">=", LSL_RIGHT2LEFT, NULL},
63 {LSL_LESS_EQUAL, ST_COMPARISON, "<=", LSL_RIGHT2LEFT, NULL, evaluateOperationToken}, 57 {LSL_LESS_EQUAL, ST_COMPARISON, "<=", LSL_RIGHT2LEFT, NULL},
64 {LSL_GREATER_THAN, ST_COMPARISON, ">", LSL_RIGHT2LEFT, NULL, evaluateOperationToken}, 58 {LSL_GREATER_THAN, ST_COMPARISON, ">", LSL_RIGHT2LEFT, NULL},
65 {LSL_LESS_THAN, ST_COMPARISON, "<", LSL_RIGHT2LEFT, NULL, evaluateOperationToken}, 59 {LSL_LESS_THAN, ST_COMPARISON, "<", LSL_RIGHT2LEFT, NULL},
66// 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. 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.
67// 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. 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.
68 {LSL_RIGHT_SHIFT, ST_BITWISE, ">>", LSL_LEFT2RIGHT, outputBitOp, evaluateOperationToken}, 62 {LSL_RIGHT_SHIFT, ST_BITWISE, ">>", LSL_LEFT2RIGHT, outputBitOp},
69 {LSL_LEFT_SHIFT, ST_BITWISE, "<<", LSL_LEFT2RIGHT, outputBitOp, evaluateOperationToken}, 63 {LSL_LEFT_SHIFT, ST_BITWISE, "<<", LSL_LEFT2RIGHT, outputBitOp},
70 {LSL_CONCATENATE, ST_ADD, "+", LSL_LEFT2RIGHT, NULL, evaluateOperationToken}, 64 {LSL_CONCATENATE, ST_ADD, "+", LSL_LEFT2RIGHT, NULL},
71 {LSL_ADD, ST_ADD, "+", LSL_LEFT2RIGHT, NULL, evaluateOperationToken}, 65 {LSL_ADD, ST_ADD, "+", LSL_LEFT2RIGHT, NULL},
72 {LSL_SUBTRACT, ST_SUBTRACT, "-", LSL_LEFT2RIGHT, NULL, evaluateOperationToken}, 66 {LSL_SUBTRACT, ST_SUBTRACT, "-", LSL_LEFT2RIGHT, NULL},
73 {LSL_CROSS_PRODUCT, ST_NONE, "%", LSL_LEFT2RIGHT, NULL, evaluateOperationToken}, 67 {LSL_CROSS_PRODUCT, ST_NONE, "%", LSL_LEFT2RIGHT, NULL},
74 {LSL_DOT_PRODUCT, ST_NONE, "*", LSL_LEFT2RIGHT, NULL, evaluateOperationToken}, 68 {LSL_DOT_PRODUCT, ST_NONE, "*", LSL_LEFT2RIGHT, NULL},
75 {LSL_MULTIPLY, ST_MULTIPLY, "*", LSL_LEFT2RIGHT, NULL, evaluateOperationToken}, 69 {LSL_MULTIPLY, ST_MULTIPLY, "*", LSL_LEFT2RIGHT, NULL},
76 {LSL_MODULO, ST_MODULO, "%", LSL_LEFT2RIGHT, NULL, evaluateOperationToken}, 70 {LSL_MODULO, ST_MODULO, "%", LSL_LEFT2RIGHT, NULL},
77 {LSL_DIVIDE, ST_MULTIPLY, "/", LSL_LEFT2RIGHT, NULL, evaluateOperationToken}, 71 {LSL_DIVIDE, ST_MULTIPLY, "/", LSL_LEFT2RIGHT, NULL},
78 {LSL_NEGATION, ST_NEGATE, "-", LSL_RIGHT2LEFT | LSL_UNARY, NULL, evaluateOperationToken}, 72 {LSL_NEGATION, ST_NEGATE, "-", LSL_RIGHT2LEFT | LSL_UNARY, NULL},
79 {LSL_BOOL_NOT, ST_BOOL_NOT, "!", LSL_RIGHT2LEFT | LSL_UNARY, NULL, evaluateOperationToken}, 73 {LSL_BOOL_NOT, ST_BOOL_NOT, "!", LSL_RIGHT2LEFT | LSL_UNARY, NULL},
80 {LSL_BIT_NOT, ST_BIT_NOT, "~", LSL_RIGHT2LEFT | LSL_UNARY, outputBitOp, evaluateOperationToken}, 74 {LSL_BIT_NOT, ST_BIT_NOT, "~", LSL_RIGHT2LEFT | LSL_UNARY, outputBitOp},
81 75
82// LUA precedence - (it has no bit operators, at least not until 5.2, but LuaJIT has them.) 76// LUA precedence - (it has no bit operators, at least not until 5.2, but LuaJIT has them.)
83// or 77// or
@@ -89,72 +83,72 @@ LSL_Token LSL_Tokens[] =
89// not negate 83// not negate
90// exponentiation (^) 84// exponentiation (^)
91 85
92 {LSL_TYPECAST_CLOSE, ST_NONE, ")", LSL_RIGHT2LEFT | LSL_UNARY, NULL, evaluateNoToken}, 86 {LSL_TYPECAST_CLOSE, ST_NONE, ")", LSL_RIGHT2LEFT | LSL_UNARY, NULL},
93 {LSL_TYPECAST_OPEN, ST_NONE, "(", LSL_RIGHT2LEFT | LSL_UNARY, outputParenthesisToken, evaluateOperationToken}, 87 {LSL_TYPECAST_OPEN, ST_NONE, "(", LSL_RIGHT2LEFT | LSL_UNARY, outputParenthesisToken},
94 {LSL_ANGLE_CLOSE, ST_NONE, ">", LSL_LEFT2RIGHT | LSL_CREATION, NULL, evaluateNoToken}, 88 {LSL_ANGLE_CLOSE, ST_NONE, ">", LSL_LEFT2RIGHT | LSL_CREATION, NULL},
95 {LSL_ANGLE_OPEN, ST_NONE, "<", LSL_LEFT2RIGHT | LSL_CREATION, NULL, evaluateOperationToken}, 89 {LSL_ANGLE_OPEN, ST_NONE, "<", LSL_LEFT2RIGHT | LSL_CREATION, NULL},
96 {LSL_BRACKET_CLOSE, ST_NONE, "]", LSL_INNER2OUTER | LSL_CREATION, NULL, evaluateNoToken}, 90 {LSL_BRACKET_CLOSE, ST_NONE, "]", LSL_INNER2OUTER | LSL_CREATION, NULL},
97 {LSL_BRACKET_OPEN, ST_NONE, "[", LSL_INNER2OUTER | LSL_CREATION, NULL, evaluateOperationToken}, 91 {LSL_BRACKET_OPEN, ST_NONE, "[", LSL_INNER2OUTER | LSL_CREATION, NULL},
98 {LSL_PARENTHESIS_CLOSE, ST_NONE, ")", LSL_INNER2OUTER, NULL, evaluateNoToken}, 92 {LSL_PARENTHESIS_CLOSE, ST_NONE, ")", LSL_INNER2OUTER, NULL},
99 {LSL_PARENTHESIS_OPEN, ST_NONE, "(", LSL_INNER2OUTER, outputParenthesisToken, eveluateParenthesisToken}, 93 {LSL_PARENTHESIS_OPEN, ST_NONE, "(", LSL_INNER2OUTER, outputParenthesisToken},
100 {LSL_DOT, ST_NONE, ".", LSL_RIGHT2LEFT, NULL, evaluateOperationToken}, 94 {LSL_DOT, ST_NONE, ".", LSL_RIGHT2LEFT, NULL},
101 {LSL_DECREMENT_POST, ST_NONE, "--", LSL_RIGHT2LEFT | LSL_UNARY, outputCrementsToken, evaluateOperationToken}, 95 {LSL_DECREMENT_POST, ST_NONE, "--", LSL_RIGHT2LEFT | LSL_UNARY, outputCrementsToken},
102 {LSL_DECREMENT_PRE, ST_NONE, "--", LSL_RIGHT2LEFT | LSL_UNARY, outputCrementsToken, evaluateOperationToken}, 96 {LSL_DECREMENT_PRE, ST_NONE, "--", LSL_RIGHT2LEFT | LSL_UNARY, outputCrementsToken},
103 {LSL_INCREMENT_POST, ST_NONE, "++", LSL_RIGHT2LEFT | LSL_UNARY, outputCrementsToken, evaluateOperationToken}, 97 {LSL_INCREMENT_POST, ST_NONE, "++", LSL_RIGHT2LEFT | LSL_UNARY, outputCrementsToken},
104 {LSL_INCREMENT_PRE, ST_NONE, "++", LSL_RIGHT2LEFT | LSL_UNARY, outputCrementsToken, evaluateOperationToken}, 98 {LSL_INCREMENT_PRE, ST_NONE, "++", LSL_RIGHT2LEFT | LSL_UNARY, outputCrementsToken},
105 {LSL_COMMA, ST_NONE, ",", LSL_LEFT2RIGHT, NULL, evaluateOperationToken}, 99 {LSL_COMMA, ST_NONE, ",", LSL_LEFT2RIGHT, NULL},
106 100
107 {LSL_EXPRESSION, ST_NONE, "expression", LSL_NONE , NULL, NULL}, 101 {LSL_EXPRESSION, ST_NONE, "expression", LSL_NONE , NULL},
108 102
109 // Types. 103 // Types.
110 {LSL_FLOAT, ST_NONE, "float", LSL_NONE, outputFloatToken, evaluateFloatToken}, 104 {LSL_FLOAT, ST_NONE, "float", LSL_NONE, outputFloatToken},
111 {LSL_INTEGER, ST_NONE, "integer", LSL_NONE, outputIntegerToken, evaluateIntegerToken}, 105 {LSL_INTEGER, ST_NONE, "integer", LSL_NONE, outputIntegerToken},
112 {LSL_KEY, ST_NONE, "key", LSL_NONE, outputStringToken, NULL}, 106 {LSL_KEY, ST_NONE, "key", LSL_NONE, outputStringToken},
113 {LSL_LIST, ST_NONE, "list", LSL_NONE, outputListToken, NULL}, 107 {LSL_LIST, ST_NONE, "list", LSL_NONE, outputListToken},
114 {LSL_ROTATION, ST_NONE, "rotation", LSL_NONE, outputListToken, NULL}, 108 {LSL_ROTATION, ST_NONE, "rotation", LSL_NONE, outputListToken},
115 {LSL_STRING, ST_NONE, "string", LSL_NONE, outputStringToken, NULL}, 109 {LSL_STRING, ST_NONE, "string", LSL_NONE, outputStringToken},
116 {LSL_VECTOR, ST_NONE, "vector", LSL_NONE, outputListToken, NULL}, 110 {LSL_VECTOR, ST_NONE, "vector", LSL_NONE, outputListToken},
117 111
118 // Types names. 112 // Types names.
119 {LSL_TYPE_FLOAT, ST_NONE, "float", LSL_TYPE, NULL, NULL}, 113 {LSL_TYPE_FLOAT, ST_NONE, "float", LSL_TYPE, NULL},
120 {LSL_TYPE_INTEGER, ST_NONE, "integer", LSL_TYPE, NULL, NULL}, 114 {LSL_TYPE_INTEGER, ST_NONE, "integer", LSL_TYPE, NULL},
121 {LSL_TYPE_KEY, ST_NONE, "key", LSL_TYPE, NULL, NULL}, 115 {LSL_TYPE_KEY, ST_NONE, "key", LSL_TYPE, NULL},
122 {LSL_TYPE_LIST, ST_NONE, "list", LSL_TYPE, NULL, NULL}, 116 {LSL_TYPE_LIST, ST_NONE, "list", LSL_TYPE, NULL},
123 {LSL_TYPE_ROTATION, ST_NONE, "rotation", LSL_TYPE, NULL, NULL}, 117 {LSL_TYPE_ROTATION, ST_NONE, "rotation", LSL_TYPE, NULL},
124 {LSL_TYPE_STRING, ST_NONE, "string", LSL_TYPE, NULL, NULL}, 118 {LSL_TYPE_STRING, ST_NONE, "string", LSL_TYPE, NULL},
125 {LSL_TYPE_VECTOR, ST_NONE, "vector", LSL_TYPE, NULL, NULL}, 119 {LSL_TYPE_VECTOR, ST_NONE, "vector", LSL_TYPE, NULL},
126 120
127 // Then the rest of the syntax tokens. 121 // Then the rest of the syntax tokens.
128 {LSL_FUNCTION_CALL, ST_NONE, "funccall", LSL_NONE, outputFunctionCallToken, NULL}, 122 {LSL_FUNCTION_CALL, ST_NONE, "funccall", LSL_NONE, outputFunctionCallToken},
129 {LSL_IDENTIFIER, ST_NONE, "identifier", LSL_NONE, outputIdentifierToken, NULL}, 123 {LSL_IDENTIFIER, ST_NONE, "identifier", LSL_NONE, outputIdentifierToken},
130 {LSL_VARIABLE, ST_NONE, "variable", LSL_NONE, outputIdentifierToken, NULL}, 124 {LSL_VARIABLE, ST_NONE, "variable", LSL_NONE, outputIdentifierToken},
131 125
132 {LSL_LABEL, ST_NONE, "@", LSL_NONE, NULL, NULL}, 126 {LSL_LABEL, ST_NONE, "@", LSL_NONE, NULL},
133 127
134 {LSL_DO, ST_NONE, "do", LSL_NONE, NULL, NULL}, 128 {LSL_DO, ST_NONE, "do", LSL_NONE, NULL},
135 {LSL_FOR, ST_NONE, "for", LSL_NONE, NULL, NULL}, 129 {LSL_FOR, ST_NONE, "for", LSL_NONE, NULL},
136 {LSL_ELSE, ST_NONE, "else", LSL_NONE, NULL, NULL}, 130 {LSL_ELSE, ST_NONE, "else", LSL_NONE, NULL},
137 {LSL_ELSEIF, ST_NONE, "elseif", LSL_NONE, NULL, NULL}, 131 {LSL_ELSEIF, ST_NONE, "elseif", LSL_NONE, NULL},
138 {LSL_IF, ST_NONE, "if", LSL_NONE, NULL, NULL}, 132 {LSL_IF, ST_NONE, "if", LSL_NONE, NULL},
139 {LSL_JUMP, ST_NONE, "jump", LSL_NONE, NULL, NULL}, 133 {LSL_JUMP, ST_NONE, "jump", LSL_NONE, NULL},
140 {LSL_RETURN, ST_NONE, "return", LSL_NONE, NULL, NULL}, 134 {LSL_RETURN, ST_NONE, "return", LSL_NONE, NULL},
141 {LSL_STATE_CHANGE, ST_NONE, "state", LSL_NONE, NULL, NULL}, 135 {LSL_STATE_CHANGE, ST_NONE, "state", LSL_NONE, NULL},
142 {LSL_WHILE, ST_NONE, "while", LSL_NONE, NULL, NULL}, 136 {LSL_WHILE, ST_NONE, "while", LSL_NONE, NULL},
143 {LSL_STATEMENT, ST_NONE, ";", LSL_NOIGNORE, outputStatementToken, evaluateStatementToken}, 137 {LSL_STATEMENT, ST_NONE, ";", LSL_NOIGNORE, outputStatementToken},
144 138
145 {LSL_BLOCK_CLOSE, ST_NONE, "}", LSL_NONE, NULL, NULL}, 139 {LSL_BLOCK_CLOSE, ST_NONE, "}", LSL_NONE, NULL},
146 {LSL_BLOCK_OPEN, ST_NONE, "{", LSL_NONE, outputBlockToken, NULL}, 140 {LSL_BLOCK_OPEN, ST_NONE, "{", LSL_NONE, outputBlockToken},
147 {LSL_PARAMETER, ST_NONE, "parameter", LSL_NONE, outputIdentifierToken, NULL}, 141 {LSL_PARAMETER, ST_NONE, "parameter", LSL_NONE, outputIdentifierToken},
148 {LSL_PARAMETER_LIST, ST_NONE, "plist", LSL_NONE, outputParameterListToken, NULL}, 142 {LSL_PARAMETER_LIST, ST_NONE, "plist", LSL_NONE, outputParameterListToken},
149 {LSL_FUNCTION, ST_NONE, "function", LSL_NONE, outputFunctionToken, NULL}, 143 {LSL_FUNCTION, ST_NONE, "function", LSL_NONE, outputFunctionToken},
150 {LSL_DEFAULT, ST_NONE, "default", LSL_NONE, outputStateToken, NULL}, 144 {LSL_DEFAULT, ST_NONE, "default", LSL_NONE, outputStateToken},
151 {LSL_STATE, ST_NONE, "state", LSL_NONE, outputStateToken, NULL}, 145 {LSL_STATE, ST_NONE, "state", LSL_NONE, outputStateToken},
152 {LSL_SCRIPT, ST_NONE, "", LSL_NONE, NULL, NULL}, 146 {LSL_SCRIPT, ST_NONE, "", LSL_NONE, NULL},
153 147
154 {LSL_UNKNOWN, ST_NONE, "unknown", LSL_NONE, NULL, NULL}, 148 {LSL_UNKNOWN, ST_NONE, "unknown", LSL_NONE, NULL},
155 149
156 // A sentinal. 150 // A sentinal.
157 {999999, ST_NONE, NULL, LSL_NONE, NULL, NULL} 151 {999999, ST_NONE, NULL, LSL_NONE, NULL}
158}; 152};
159 153
160// VERY IMPORTANT to keep this in sync with enum opType from LuaSL_LSL_tree.h! 154// 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 *
1196 return list; 1190 return list;
1197} 1191}
1198 1192
1193/* Typecasting
1194
1195LSL is statically typed, so stored values are not converted, only the values used in expressions are.
1196Lua is dynamically typed, so stored values are changed (sometimes I think).
1197
1198LSL implicitly typecasts - There is a shitload of QUIRKs about this. Apparently some don't work anyway.
1199 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.)
1200 string -> key
1201 Some functions need help with this or the other way around.
1202 string -> vector (Maybe, should test that.)
1203 vector -> string (Maybe, should test that.)
1204 Also happens when getting stuff from lists.
1205
1206Explicit type casting -
1207 string -> integer
1208 Leading spaces are ignored, as are any characters after the run of digits.
1209 All other strings convert to 0.
1210 Which means "" and " " convert to 0.
1211 Strings in hexadecimal format will work, same in Lua (though Lua can't handle "0x", but "0x0" is fine).
1212 keys <-> string
1213 No other typecasting can be done with keys.
1214 float -> string
1215 You get a bunch of trailing 0s.
1216
1217QUIRK - I have seen cases where a double explicit typecast was needed in SL, but was considered to be invalid syntax in OS.
1218
1219Any binary operation involving a float and an integer implicitly casts the integer to float.
1220
1221A 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.
1223Bitwise operations only apply to integers. The shifts are arithmatic, not logical. Right shifted bits are dropped, left shifts the sign bit.
1224
1225integer = integer0 % integer1; // Apparently only applies to integers, but works fine on floats in OS.
1226string = string0 + string1; // Concatenation.
1227list = list0 + list1; // Concatenation. Also works if either is not a list, it's promoted to a list first.
1228list = (list=[]) + list + ["new_item"]; // Voodoo needed for old LSL, works in Mono but not needed, does not work in OS. Works for strings to.
1229bool = list == != int // Only compares the lengths, probably applies to the other conditionals to.
1230vector = vector0 + vector1; // Add elements together.
1231vector = vector0 - vector1; // Subtract elements of vector1 from elements of vector0.
1232float = vector0 * vector1; // A dot product of the vectors.
1233vector = vector0 % vector1; // A cross product of the vectors.
1234vector = 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.
1235vector = 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.
1236vector = vector * rotation; // Rotate the vector by the rotation. Other way around wont compile.
1237vector = vector / rotation; // Rotate the vector by the rotation, in the opposite direction. Other way around wont compile.
1238rotation = llGetRot() * rotation; // Rotate an object around the global axis.
1239rotation = rotation * llGetLocalRot(); // Rotate an object around the local axis.
1240rotation = rotation0 * rotation1; // Add two rotations, so the result is as if you applied each rotation one after the other.
1241 // Division rotates in the opposite direction.
1242rotation = rotation0 + rotation1; // Similar to vector, but it's a meaningless thing as far as rotations go.
1243rotation = rotation0 - rotation1; // Similar to vector, but it's a meaningless thing as far as rotations go.
1244
1245A boolean operator results in a boolean value. (any types)
1246A comparison operator results in a boolean value. (any types)
1247A bitwise operator results in an integer value. (intInt or int)
1248A dot product operator results in a float value. (vector * vector)
1249A vectorFloat results in a vector value.
1250
1251*/
1252
1199LSL_Leaf *addTypecast(LSL_Leaf *lval, LSL_Leaf *type, LSL_Leaf *rval, LSL_Leaf *expr) 1253LSL_Leaf *addTypecast(LSL_Leaf *lval, LSL_Leaf *type, LSL_Leaf *rval, LSL_Leaf *expr)
1200{ 1254{
1201 addParenthesis(lval, expr, LSL_TYPECAST_OPEN, rval); 1255 addParenthesis(lval, expr, LSL_TYPECAST_OPEN, rval);
@@ -1295,372 +1349,6 @@ static void secondPass(LuaSL_compiler *compiler, LSL_Leaf *leaf)
1295 } 1349 }
1296} 1350}
1297 1351
1298static LSL_Leaf *evaluateLeaf(LSL_Leaf *leaf, LSL_Leaf *left, LSL_Leaf *right)
1299{
1300 LSL_Leaf *result = NULL;
1301
1302 if (leaf)
1303 {
1304 LSL_Leaf *lresult = NULL;
1305 LSL_Leaf *rresult = NULL;
1306
1307 if (LSL_RIGHT2LEFT & leaf->toKen->flags)
1308 {
1309 rresult = evaluateLeaf(leaf->right, left, right);
1310 if (!(LSL_UNARY & leaf->toKen->flags))
1311 lresult = evaluateLeaf(leaf->left, left, right);
1312 }
1313 else // Assume left to right.
1314 {
1315 lresult = evaluateLeaf(leaf->left, left, right);
1316 if (!(LSL_UNARY & leaf->toKen->flags))
1317 rresult = evaluateLeaf(leaf->right, left, right);
1318 }
1319
1320 if (leaf->toKen->evaluate)
1321 result = leaf->toKen->evaluate(leaf, lresult, rresult);
1322 else
1323 {
1324 result = newLeaf(LSL_UNKNOWN, NULL, NULL);
1325 if (rresult && result)
1326 memcpy(result, rresult, sizeof(LSL_Leaf));
1327 }
1328
1329 if (lresult)
1330 free(lresult);
1331 if (rresult)
1332 free(rresult);
1333 }
1334
1335 return result;
1336}
1337
1338static LSL_Leaf *evaluateFloatToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right)
1339{
1340 LSL_Leaf *result = newLeaf(LSL_FLOAT, NULL, NULL);
1341
1342 if (content && result)
1343 {
1344 memcpy(result, content, sizeof(LSL_Leaf));
1345 result->value.floatValue = content->value.numbyValue->value.floatValue;
1346 result->basicType = OT_float;
1347 if (LUASL_DEBUG)
1348 printf(" <%g> ", content->value.floatValue);
1349 }
1350 return result;
1351}
1352
1353static LSL_Leaf *evaluateIntegerToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right)
1354{
1355 LSL_Leaf *result = newLeaf(LSL_INTEGER, NULL, NULL);
1356
1357 if (content && result)
1358 {
1359 memcpy(result, content, sizeof(LSL_Leaf));
1360 result->value.integerValue = content->value.numbyValue->value.integerValue;
1361 result->basicType = OT_integer;
1362 if (LUASL_DEBUG)
1363 printf(" <%d> ", result->value.integerValue);
1364 }
1365 return result;
1366}
1367
1368static LSL_Leaf *evaluateNoToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right)
1369{
1370 // Do nothing, that's the point.
1371
1372 return content;
1373}
1374
1375/* Typecasting
1376
1377LSL is statically typed, so stored values are not converted, only the values used in expressions are.
1378Lua is dynamically typed, so stored values are changed (sometimes I think).
1379
1380LSL implicitly typecasts - There is a shitload of QUIRKs about this. Apparently some don't work anyway.
1381 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.)
1382 string -> key
1383 Some functions need help with this or the other way around.
1384 string -> vector (Maybe, should test that.)
1385 vector -> string (Maybe, should test that.)
1386 Also happens when getting stuff from lists.
1387
1388Explicit type casting -
1389 string -> integer
1390 Leading spaces are ignored, as are any characters after the run of digits.
1391 All other strings convert to 0.
1392 Which means "" and " " convert to 0.
1393 Strings in hexadecimal format will work, same in Lua (though Lua can't handle "0x", but "0x0" is fine).
1394 keys <-> string
1395 No other typecasting can be done with keys.
1396 float -> string
1397 You get a bunch of trailing 0s.
1398
1399QUIRK - I have seen cases where a double explicit typecast was needed in SL, but was considered to be invalid syntax in OS.
1400
1401Any binary operation involving a float and an integer implicitly casts the integer to float.
1402
1403A boolean operation deals with TRUE (1) and FALSE (0). Any non zero value is a TRUE (generally sigh).
1404On the other hand, in Lua, only false and nil are false, everything else is true.
1405Bitwise operations only apply to integers. The shifts are arithmatic, not logical. Right shifted bits are dropped, left shifts the sign bit.
1406
1407integer = integer0 % integer1; // Apparently only applies to integers, but works fine on floats in OS.
1408string = string0 + string1; // Concatenation.
1409list = list0 + list1; // Concatenation. Also works if either is not a list, it's promoted to a list first.
1410list = (list=[]) + list + ["new_item"]; // Voodoo needed for old LSL, works in Mono but not needed, does not work in OS. Works for strings to.
1411bool = list == != int // Only compares the lengths, probably applies to the other conditionals to.
1412vector = vector0 + vector1; // Add elements together.
1413vector = vector0 - vector1; // Subtract elements of vector1 from elements of vector0.
1414float = vector0 * vector1; // A dot product of the vectors.
1415vector = vector0 % vector1; // A cross product of the vectors.
1416vector = 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.
1417vector = 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.
1418vector = vector * rotation; // Rotate the vector by the rotation. Other way around wont compile.
1419vector = vector / rotation; // Rotate the vector by the rotation, in the opposite direction. Other way around wont compile.
1420rotation = llGetRot() * rotation; // Rotate an object around the global axis.
1421rotation = rotation * llGetLocalRot(); // Rotate an object around the local axis.
1422rotation = rotation0 * rotation1; // Add two rotations, so the result is as if you applied each rotation one after the other.
1423 // Division rotates in the opposite direction.
1424rotation = rotation0 + rotation1; // Similar to vector, but it's a meaningless thing as far as rotations go.
1425rotation = rotation0 - rotation1; // Similar to vector, but it's a meaningless thing as far as rotations go.
1426
1427A boolean operator results in a boolean value. (any types)
1428A comparison operator results in a boolean value. (any types)
1429A bitwise operator results in an integer value. (intInt or int)
1430A dot product operator results in a float value. (vector * vector)
1431A vectorFloat results in a vector value.
1432
1433*/
1434
1435static LSL_Leaf *evaluateOperationToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right)
1436{
1437 LSL_Leaf *result = newLeaf(LSL_UNKNOWN, NULL, NULL);
1438
1439 if (content && result)
1440 {
1441 if (LUASL_DEBUG)
1442 printf(" [%s] ", content->toKen->toKen);
1443
1444 memcpy(result, content, sizeof(LSL_Leaf));
1445
1446 // Figure out the type of the operation.
1447 if (OT_vector < result->basicType)
1448 result->basicType = allowed[result->basicType].result;
1449
1450 switch (result->basicType)
1451 {
1452 case OT_float :
1453 {
1454 float fleft = left->value.floatValue;
1455 float fright = right->value.floatValue;
1456
1457 // Do the casting.
1458 if (OT_floatInt == content->basicType)
1459 fright = right->value.integerValue;
1460 if (OT_intFloat == content->basicType)
1461 fleft = left->value.integerValue;
1462 switch (result->toKen->type)
1463 {
1464 case LSL_COMMA :
1465 case LSL_INCREMENT_PRE :
1466 case LSL_INCREMENT_POST :
1467 case LSL_DECREMENT_PRE :
1468 case LSL_DECREMENT_POST :
1469 case LSL_ASSIGNMENT_PLAIN :
1470 case LSL_ASSIGNMENT_DIVIDE :
1471 case LSL_ASSIGNMENT_MULTIPLY :
1472 case LSL_ASSIGNMENT_SUBTRACT :
1473 case LSL_ASSIGNMENT_ADD :
1474 case LSL_BRACKET_OPEN :
1475 case LSL_BRACKET_CLOSE :
1476 case LSL_ANGLE_OPEN :
1477 case LSL_ANGLE_CLOSE :
1478 case LSL_TYPECAST_OPEN :
1479 case LSL_TYPECAST_CLOSE :
1480 case LSL_DOT_PRODUCT :
1481 break;
1482 case LSL_NEGATION : result->value.floatValue = 0 - fright; break;
1483 case LSL_DIVIDE : result->value.floatValue = fleft / fright; break;
1484 case LSL_MULTIPLY : result->value.floatValue = fleft * fright; break;
1485 case LSL_SUBTRACT : result->value.floatValue = fleft - fright; break;
1486 case LSL_ADD : result->value.floatValue = fleft + fright; break;
1487 case LSL_LESS_THAN : result->value.floatValue = fleft < fright; break;
1488 case LSL_GREATER_THAN : result->value.floatValue = fleft > fright; break;
1489 case LSL_LESS_EQUAL : result->value.floatValue = fleft <= fright; break;
1490 case LSL_GREATER_EQUAL : result->value.floatValue = fleft >= fright; break;
1491 case LSL_EQUAL : result->value.floatValue = fleft == fright; break;
1492 case LSL_NOT_EQUAL : result->value.floatValue = fleft != fright; break;
1493 }
1494 if (LUASL_DEBUG)
1495 printf(" (=%g) ", result->value.floatValue);
1496 break;
1497 }
1498
1499 case OT_integer :
1500 {
1501 switch (result->toKen->type)
1502 {
1503 case LSL_COMMA :
1504 case LSL_INCREMENT_PRE :
1505 case LSL_INCREMENT_POST :
1506 case LSL_DECREMENT_PRE :
1507 case LSL_DECREMENT_POST :
1508 case LSL_DOT :
1509 case LSL_ASSIGNMENT_PLAIN :
1510 case LSL_ASSIGNMENT_DIVIDE :
1511 case LSL_ASSIGNMENT_MODULO :
1512 case LSL_ASSIGNMENT_MULTIPLY :
1513 case LSL_ASSIGNMENT_SUBTRACT :
1514 case LSL_ASSIGNMENT_ADD :
1515 case LSL_BRACKET_OPEN :
1516 case LSL_BRACKET_CLOSE :
1517 case LSL_ANGLE_OPEN :
1518 case LSL_ANGLE_CLOSE :
1519 case LSL_TYPECAST_OPEN :
1520 case LSL_TYPECAST_CLOSE :
1521 break;
1522 case LSL_BIT_NOT : result->value.integerValue = ~ right->value.integerValue; break;
1523 case LSL_BOOL_NOT : result->value.integerValue = ! right->value.integerValue; break;
1524 case LSL_NEGATION : result->value.integerValue = 0 - right->value.integerValue; break;
1525 case LSL_DIVIDE : result->value.integerValue = left->value.integerValue / right->value.integerValue; break;
1526 case LSL_MODULO : result->value.integerValue = left->value.integerValue % right->value.integerValue; break;
1527 case LSL_MULTIPLY : result->value.integerValue = left->value.integerValue * right->value.integerValue; break;
1528 case LSL_SUBTRACT : result->value.integerValue = left->value.integerValue - right->value.integerValue; break;
1529 case LSL_ADD : result->value.integerValue = left->value.integerValue + right->value.integerValue; break;
1530 case LSL_LEFT_SHIFT : result->value.integerValue = left->value.integerValue << right->value.integerValue; break;
1531 case LSL_RIGHT_SHIFT : result->value.integerValue = left->value.integerValue >> right->value.integerValue; break;
1532 case LSL_LESS_THAN : result->value.integerValue = left->value.integerValue < right->value.integerValue; break;
1533 case LSL_GREATER_THAN : result->value.integerValue = left->value.integerValue > right->value.integerValue; break;
1534 case LSL_LESS_EQUAL : result->value.integerValue = left->value.integerValue <= right->value.integerValue; break;
1535 case LSL_GREATER_EQUAL : result->value.integerValue = left->value.integerValue >= right->value.integerValue; break;
1536 case LSL_EQUAL : result->value.integerValue = left->value.integerValue == right->value.integerValue; break;
1537 case LSL_NOT_EQUAL : result->value.integerValue = left->value.integerValue != right->value.integerValue; break;
1538 case LSL_BIT_AND : result->value.integerValue = left->value.integerValue & right->value.integerValue; break;
1539 case LSL_BIT_XOR : result->value.integerValue = left->value.integerValue ^ right->value.integerValue; break;
1540 case LSL_BIT_OR : result->value.integerValue = left->value.integerValue | right->value.integerValue; break;
1541 case LSL_BOOL_OR : result->value.integerValue = left->value.integerValue || right->value.integerValue; break;
1542 case LSL_BOOL_AND : result->value.integerValue = left->value.integerValue && right->value.integerValue; break;
1543 }
1544 if (LUASL_DEBUG)
1545 printf(" (=%d) ", result->value.integerValue);
1546 break;
1547 }
1548
1549 default :
1550 break;
1551 }
1552 }
1553 return result;
1554}
1555
1556static LSL_Leaf *eveluateParenthesisToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right)
1557{
1558 LSL_Leaf *result = NULL;
1559
1560 if (content)
1561 {
1562 if ((LSL_PARAMETER_LIST != content->value.parenthesis->type) && (LSL_LIST != content->value.parenthesis->type))
1563 result = evaluateLeaf(content->value.parenthesis->contents, left, right);
1564 }
1565 return result;
1566}
1567
1568static LSL_Leaf *evaluateStatementToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right)
1569{
1570 LSL_Leaf *result = NULL;
1571
1572 if (content)
1573 {
1574 switch (content->value.statementValue->type)
1575 {
1576 case LSL_EXPRESSION :
1577 {
1578 result = evaluateLeaf(content->value.statementValue->expressions, left, right);
1579 break;
1580 }
1581 case LSL_FUNCTION :
1582 {
1583 break;
1584 }
1585 case LSL_DO :
1586 {
1587 break;
1588 }
1589 case LSL_FOR :
1590 {
1591 break;
1592 }
1593 case LSL_IF :
1594 {
1595 break;
1596 }
1597 case LSL_ELSE :
1598 {
1599 break;
1600 }
1601 case LSL_ELSEIF :
1602 {
1603 break;
1604 }
1605 case LSL_JUMP :
1606 {
1607 break;
1608 }
1609 case LSL_LABEL :
1610 {
1611 break;
1612 }
1613 case LSL_RETURN :
1614 {
1615 break;
1616 }
1617 case LSL_STATE_CHANGE :
1618 {
1619 break;
1620 }
1621 case LSL_STATEMENT :
1622 {
1623 result = evaluateLeaf(content->value.statementValue->expressions, left, right);
1624 break;
1625 }
1626 case LSL_WHILE :
1627 {
1628 break;
1629 }
1630 case LSL_IDENTIFIER :
1631 {
1632 break;
1633 }
1634 case LSL_VARIABLE :
1635 {
1636 break;
1637 }
1638 default :
1639 {
1640// PE("Should not be here %d.", type);
1641 break;
1642 }
1643 }
1644
1645 if (result)
1646 {
1647 switch (result->basicType)
1648 {
1649 case OT_float : printf("Result is the float %g.\n", result->value.floatValue); break;
1650 case OT_integer : printf("Result is the integer %d.\n", result->value.integerValue); break;
1651 default : /*printf("\nResult of an unknown type [%d] %d!\n", result->basicType, result->value.integerValue);*/ break;
1652 }
1653 free(result);
1654 result = NULL;
1655 }
1656 if (left)
1657 left->value.integerValue = 0;
1658 if (right)
1659 right->value.integerValue = 0;
1660 }
1661 return result;
1662}
1663
1664static void outputLeaf(FILE *file, outputMode mode, LSL_Leaf *leaf) 1352static void outputLeaf(FILE *file, outputMode mode, LSL_Leaf *leaf)
1665{ 1353{
1666 if (leaf) 1354 if (leaf)
@@ -2425,11 +2113,6 @@ static boolean doneParsing(LuaSL_compiler *compiler)
2425 char luaName[PATH_MAX]; 2113 char luaName[PATH_MAX];
2426 int count; 2114 int count;
2427 2115
2428// outputLeaf(stdout, OM_LSL, compiler->ast);
2429// printf("\n");
2430 evaluateLeaf(compiler->ast, NULL, NULL);
2431// printf("\n");
2432
2433 if (LUASL_DIFF_CHECK) 2116 if (LUASL_DIFF_CHECK)
2434 { 2117 {
2435 strcpy(outName, compiler->fileName); 2118 strcpy(outName, compiler->fileName);
@@ -2444,11 +2127,11 @@ static boolean doneParsing(LuaSL_compiler *compiler)
2444 outputLeaf(out, OM_LSL, compiler->ast); 2127 outputLeaf(out, OM_LSL, compiler->ast);
2445 fclose(out); 2128 fclose(out);
2446 sprintf(buffer, "diff -u \"%s\" \"%s\" > \"%s\"", compiler->fileName, outName, diffName); 2129 sprintf(buffer, "diff -u \"%s\" \"%s\" > \"%s\"", compiler->fileName, outName, diffName);
2447// count = system(buffer); 2130 count = system(buffer);
2448// if (0 != count) 2131 if (0 != count)
2449// PE("LSL output file is different - %s!", outName); 2132 PE("LSL output file is different - %s!", outName);
2450// else 2133 else
2451// result = TRUE; 2134 result = TRUE;
2452 } 2135 }
2453 else 2136 else
2454 PC("Unable to open file %s for writing!", outName); 2137 PC("Unable to open file %s for writing!", outName);
@@ -2616,18 +2299,8 @@ boolean compileLSL(gameGlobals *game, char *script, boolean doConstants)
2616 result = TRUE; 2299 result = TRUE;
2617 } 2300 }
2618 else 2301 else
2619 {
2620 result = doneParsing(&compiler); 2302 result = doneParsing(&compiler);
2621 2303
2622// Take the result of the parse, and convert it into Lua source.
2623// Each LSL script becomes a Lua state.
2624// LSL states are handled as Lua tables, with each LSL state function being a table function in a common metatable.
2625// LL and OS functions are likely to be C functions.
2626
2627// Compile the Lua source by the Lua compiler.
2628
2629 }
2630
2631 if (NULL != compiler.file) 2304 if (NULL != compiler.file)
2632 { 2305 {
2633 fclose(compiler.file); 2306 fclose(compiler.file);
@@ -2639,136 +2312,3 @@ boolean compileLSL(gameGlobals *game, char *script, boolean doConstants)
2639 2312
2640 return result; 2313 return result;
2641} 2314}
2642
2643
2644// Code for running it stand alone, and with files input on the command line.
2645#if 0
2646static int nextFile(LuaSL_yyparseParam *param)
2647{
2648 if (NULL != param->file)
2649 {
2650 fclose(param->file);
2651 param->file = NULL;
2652 }
2653 if (--(param->argc) > 0 && *++(param->argv) != '\0')
2654 {
2655 strncpy(param->fileName, *(param->argv), PATH_MAX - 1);
2656 param->fileName[PATH_MAX - 1] = '\0';
2657 param->file = fopen(param->fileName, "r");
2658 if (NULL == param->file)
2659 {
2660 PE(stderr, "Error opening file %s.", param->fileName);
2661 return FALSE;
2662 }
2663 PE("Opened %s.", param->fileName);
2664 burnLeaf(param->ast);
2665 param->ast = NULL;
2666 param->lval = newLeaf(LSL_UNKNOWN, NULL, NULL);
2667 // Text editors usually start counting at 1, even programmers editors.
2668 param->column = 1;
2669 param->line = 1;
2670 return TRUE;
2671 }
2672/*
2673 if ('\0' == fileName[0])
2674 {
2675//strcpy(fileName, "test.lsl");
2676
2677 count = read(STDIN_FILENO, fileName, PATH_MAX - 1);
2678 if (0 > count)
2679 {
2680 printf("Error in stdin!\n");
2681 return 1;
2682 }
2683 else if (0 == count)
2684 {
2685 printf("No bytes in stdin!\n");
2686 return 1;
2687 }
2688 else
2689 {
2690 fileName[count] = '\0';
2691 printf("Filename %s in stdin.\n", fileName);
2692 }
2693
2694 }
2695*/
2696
2697 return FALSE;
2698}
2699
2700char *test[] = {"test2.lsl", "test2.lsl"};
2701
2702int main(int argc, char **argv)
2703{
2704// char *programName = argv[0];
2705 int i;
2706
2707 // Figure out what numbers yacc gave to our tokens.
2708 for (i = 0; LSL_Tokens[i].toKen != NULL; i++)
2709 {
2710 if (lowestToken > LSL_Tokens[i].type)
2711 lowestToken = LSL_Tokens[i].type;
2712 }
2713 tokens = calloc(i + 1, sizeof(LSL_Token *));
2714 if (tokens)
2715 {
2716 LuaSL_yyparseParam param;
2717
2718 // Sort the token table.
2719 for (i = 0; LSL_Tokens[i].toKen != NULL; i++)
2720 {
2721 int j = LSL_Tokens[i].type - lowestToken;
2722
2723 tokens[j] = &(LSL_Tokens[i]);
2724 }
2725
2726 // First time setup.
2727 if (1 == argc)
2728 {
2729 // Fake a test file if there is none. Mostly for ddd.
2730 argc++;
2731 argv = test;
2732 }
2733 memset(&param, 0, sizeof(param));
2734 param.argc = argc;
2735 param.argv = argv;
2736
2737 // Loop through the files.
2738 while (nextFile(&param))
2739 {
2740 void *pParser = ParseAlloc(malloc);
2741 int yv;
2742
2743 if (yylex_init_extra(&param, &(param.scanner)))
2744 return 1;
2745 if (LUASL_DEBUG)
2746 {
2747 yyset_debug(1, param.scanner);
2748 ParseTrace(stdout, "LSL_lemon ");
2749 }
2750 yyset_in(param.file, param.scanner);
2751 // on EOF yylex will return 0
2752 while((yv = yylex(param.lval, param.scanner)) != 0)
2753 {
2754 Parse(pParser, yv, param.lval, &param);
2755 if (LSL_SCRIPT == yv)
2756 break;
2757 param.lval = newLeaf(LSL_UNKNOWN, NULL, NULL);
2758 }
2759
2760 yylex_destroy(param.scanner);
2761 Parse (pParser, 0, param.lval, &param);
2762 ParseFree(pParser, free);
2763 doneParsing(&param);
2764 }
2765 }
2766 else
2767 {
2768 fprintf(stderr, "No memory for tokens!");
2769 return 1;
2770 }
2771
2772 return 0;
2773}
2774#endif