aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/LuaSL/src
diff options
context:
space:
mode:
authorDavid Walter Seikel2012-02-05 12:45:45 +1000
committerDavid Walter Seikel2012-02-05 12:45:45 +1000
commitb96559307de15cecad751a2f91a0e8f7016a3938 (patch)
treed49a3856703e28a19678b46c59d167ad1ab3917d /LuaSL/src
parentRight shifts are arithmetic shifts. (diff)
downloadSledjHamr-b96559307de15cecad751a2f91a0e8f7016a3938.zip
SledjHamr-b96559307de15cecad751a2f91a0e8f7016a3938.tar.gz
SledjHamr-b96559307de15cecad751a2f91a0e8f7016a3938.tar.bz2
SledjHamr-b96559307de15cecad751a2f91a0e8f7016a3938.tar.xz
Merge doneParsing(), it's only used once.
Diffstat (limited to 'LuaSL/src')
-rw-r--r--LuaSL/src/LuaSL_compile.c145
1 files changed, 70 insertions, 75 deletions
diff --git a/LuaSL/src/LuaSL_compile.c b/LuaSL/src/LuaSL_compile.c
index 9009264..140fafa 100644
--- a/LuaSL/src/LuaSL_compile.c
+++ b/LuaSL/src/LuaSL_compile.c
@@ -2095,80 +2095,6 @@ static void outputStringToken(FILE *file, outputMode mode, LSL_Leaf *content)
2095 fprintf(file, "%s", content->value.stringValue); // The quotes are part of the string value already. 2095 fprintf(file, "%s", content->value.stringValue); // The quotes are part of the string value already.
2096} 2096}
2097 2097
2098static boolean doneParsing(LuaSL_compiler *compiler)
2099{
2100 gameGlobals *game = compiler->game;
2101 boolean result = FALSE;
2102
2103 if (compiler->ast)
2104 {
2105 FILE *out;
2106 char buffer[PATH_MAX];
2107 char outName[PATH_MAX];
2108 char luaName[PATH_MAX];
2109 int count;
2110
2111 if (LUASL_DIFF_CHECK)
2112 {
2113 strcpy(outName, compiler->fileName);
2114 strcat(outName, "2");
2115 out = fopen(outName, "w");
2116 if (out)
2117 {
2118 char diffName[PATH_MAX];
2119
2120 strcpy(diffName, compiler->fileName);
2121 strcat(diffName, ".diff");
2122 outputLeaf(out, OM_LSL, compiler->ast);
2123 fclose(out);
2124 sprintf(buffer, "diff -u \"%s\" \"%s\" > \"%s\"", compiler->fileName, outName, diffName);
2125 count = system(buffer);
2126 if (0 != count)
2127 PE("LSL output file is different - %s!", outName);
2128 else
2129 result = TRUE;
2130 }
2131 else
2132 PC("Unable to open file %s for writing!", outName);
2133 }
2134 strcpy(luaName, compiler->fileName);
2135 strcat(luaName, ".lua");
2136 out = fopen(luaName, "w");
2137 if (out)
2138 {
2139 fprintf(out, "--// Generated code goes here.\n\n");
2140 fprintf(out, "local _bit = require(\"bit\")\n");
2141 fprintf(out, "local _LSL = require(\"LSL\")\n\n");
2142 outputLeaf(out, OM_LUA, compiler->ast);
2143 fprintf(out, "\n\n_LSL.stateChange(_defaultState)\n"); // This actually starts the script running.
2144 fprintf(out, "\n--// End of generated code.\n\n");
2145 fclose(out);
2146 sprintf(buffer, "../../libraries/luajit-2.0/src/luajit \"%s\"", luaName);
2147 count = system(buffer);
2148 if (0 != count)
2149 {
2150 compiler->script.bugCount++;
2151 PE("Lua compile stage failed for %s!", compiler->fileName);
2152 }
2153 }
2154 else
2155 PC("Unable to open file %s for writing!", luaName);
2156 }
2157
2158 if (compiler->script.bugCount)
2159 PE("%d errors and %d warnings in %s", compiler->script.bugCount, compiler->script.warningCount, compiler->fileName);
2160 else
2161 {
2162 if (compiler->script.warningCount)
2163 PW("%d errors and %d warnings in %s", compiler->script.bugCount, compiler->script.warningCount, compiler->fileName);
2164 else
2165 PI("%d errors and %d warnings in %s", compiler->script.bugCount, compiler->script.warningCount, compiler->fileName);
2166 result = TRUE;
2167 }
2168
2169 return result;
2170}
2171
2172boolean compilerSetup(gameGlobals *game) 2098boolean compilerSetup(gameGlobals *game)
2173{ 2099{
2174 int i; 2100 int i;
@@ -2294,7 +2220,76 @@ boolean compileLSL(gameGlobals *game, char *script, boolean doConstants)
2294 result = TRUE; 2220 result = TRUE;
2295 } 2221 }
2296 else 2222 else
2297 result = doneParsing(&compiler); 2223 {
2224 result = FALSE;
2225
2226 if (compiler.ast)
2227 {
2228 FILE *out;
2229 char buffer[PATH_MAX];
2230 char outName[PATH_MAX];
2231 char luaName[PATH_MAX];
2232 int count;
2233
2234 if (LUASL_DIFF_CHECK)
2235 {
2236 strcpy(outName, compiler.fileName);
2237 strcat(outName, "2");
2238 out = fopen(outName, "w");
2239 if (out)
2240 {
2241 char diffName[PATH_MAX];
2242
2243 strcpy(diffName, compiler.fileName);
2244 strcat(diffName, ".diff");
2245 outputLeaf(out, OM_LSL, compiler.ast);
2246 fclose(out);
2247 sprintf(buffer, "diff -u \"%s\" \"%s\" > \"%s\"", compiler.fileName, outName, diffName);
2248 count = system(buffer);
2249 if (0 != count)
2250 PE("LSL output file is different - %s!", outName);
2251 else
2252 result = TRUE;
2253 }
2254 else
2255 PC("Unable to open file %s for writing!", outName);
2256 }
2257 strcpy(luaName, compiler.fileName);
2258 strcat(luaName, ".lua");
2259 out = fopen(luaName, "w");
2260 // Generate the Lua source code.
2261 if (out)
2262 {
2263 fprintf(out, "--// Generated code goes here.\n\n");
2264 fprintf(out, "local _bit = require(\"bit\")\n");
2265 fprintf(out, "local _LSL = require(\"LSL\")\n\n");
2266 outputLeaf(out, OM_LUA, compiler.ast);
2267 fprintf(out, "\n\n_LSL.stateChange(_defaultState)\n"); // This actually starts the script running.
2268 fprintf(out, "\n--// End of generated code.\n\n");
2269 fclose(out);
2270 sprintf(buffer, "../../libraries/luajit-2.0/src/luajit \"%s\"", luaName);
2271 count = system(buffer);
2272 if (0 != count)
2273 {
2274 compiler.script.bugCount++;
2275 PE("Lua compile stage failed for %s!", compiler.fileName);
2276 }
2277 }
2278 else
2279 PC("Unable to open file %s for writing!", luaName);
2280 }
2281
2282 if (compiler.script.bugCount)
2283 PE("%d errors and %d warnings in %s", compiler.script.bugCount, compiler.script.warningCount, compiler.fileName);
2284 else
2285 {
2286 if (compiler.script.warningCount)
2287 PW("%d errors and %d warnings in %s", compiler.script.bugCount, compiler.script.warningCount, compiler.fileName);
2288 else
2289 PI("%d errors and %d warnings in %s", compiler.script.bugCount, compiler.script.warningCount, compiler.fileName);
2290 result = TRUE;
2291 }
2292 }
2298 2293
2299 if (NULL != compiler.file) 2294 if (NULL != compiler.file)
2300 { 2295 {