fix compiler locking so it only compiles once

don't call execute() from compile(), call separately
This commit is contained in:
zzz
2024-01-08 12:05:26 -05:00
parent 0fc9a639d4
commit de1cba49a9
2 changed files with 12 additions and 21 deletions

View File

@ -32,7 +32,7 @@ class Compiler {
}
/*
* Compile and execute
* Compile only. Call execute() on success.
*
* @return success
*/
@ -69,18 +69,7 @@ class Compiler {
if (!PRESERVE_PROGRAM)
src.delete();
}
try {
return execute(ctx, r);
} catch (Throwable t) {
synchronized(ctx) {
can_compile = false;
ctx.request_compile = false;
ctx.compiled = false;
ctx.compile_failed = true;
}
t.printStackTrace();
return false;
}
return true;
}
}

View File

@ -64,16 +64,18 @@ public class HashX {
//print_registers("R", r, 8);
if (ctx.code.length != GenCtx.REQUIREMENT_SIZE)
throw new IllegalArgumentException();
boolean executed = false;
if (ctx.compiled) {
executed = Compiler.execute(ctx, r);
}
if (!executed && ctx.request_compile && !ctx.compile_failed) {
executed = Compiler.compile(ctx, r);
if (!executed) {
System.out.println("FAILED compiling program " + input);
boolean compiled;
synchronized(ctx) {
compiled = ctx.compiled;
if (!compiled && ctx.request_compile && !ctx.compile_failed) {
compiled = Compiler.compile(ctx, r);
if (!compiled)
System.out.println("FAILED compiling program " + input);
}
}
boolean executed = false;
if (compiled)
executed = Compiler.execute(ctx, r);
if (!executed) {
Exec.execute(ctx.code, r);
}