From ec098a72dabb9070423beaff025a98b69c8bec8e Mon Sep 17 00:00:00 2001 From: profan Date: Sat, 6 Jun 2026 22:59:13 +0100 Subject: [PATCH] ensure eval and compilation do not conflict/overlap, add pending indicator --- Program.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Program.cs b/Program.cs index 712d169..82f8cd6 100644 --- a/Program.cs +++ b/Program.cs @@ -100,7 +100,7 @@ void Main() shouldEvaluate = false; } - if (shouldRecompile) + if (shouldRecompile && !isEvaluating) { Compiler.CompilerCache>.CachedPrograms.Clear(); Compiler.CompilerCache.CachedPrograms.Clear(); @@ -169,7 +169,7 @@ void Main() double nanoSecondsPerPixel = evaluationTimeNanoSeconds / (currentOutputImageSize * currentOutputImageSize); Raylib.DrawText( shouldUseCompiler - ? $" - evaluation took: {lastEvaluationTimeTook:0.0} s ({nanoSecondsPerPixel:0.0} ns / pixel) (compilation: {lastCompilationTimeTook:0.0} s)" + ? $" - evaluation took: {lastEvaluationTimeTook:0.0} s ({nanoSecondsPerPixel:0.0} ns / pixel) (compilation: {lastCompilationTimeTook:0.0} s{(shouldRecompile ? " (pending)" : string.Empty)})" : $" - evaluation took: {lastEvaluationTimeTook:0.0} s ({nanoSecondsPerPixel:0.0} ns / pixel)", 12, 52, 20, Color.White); } @@ -204,6 +204,7 @@ void Main() if (Raylib.IsKeyPressed(KeyboardKey.C)) { shouldUseCompiler = !shouldUseCompiler; + shouldRecompile = shouldUseCompiler; if (shouldUseCompiler) { shouldRecompile = true; @@ -1003,7 +1004,7 @@ internal static class Interpreter } T results = shouldCompileInnerLoop - ? EvaluateCompiled(evaluationInstructions,GetValues(xs), GetValues(ys)) + ? EvaluateCompiled(evaluationInstructions, GetValues(xs), GetValues(ys)) : EvaluateInterpreted(evaluationInstructions, GetValues(xs), GetValues(ys)); for (int idx = 0; idx < chunkSize; ++idx) @@ -1021,7 +1022,6 @@ internal static class Interpreter public static T EvaluateCompiled(EvaluationInstructions evaluationInstructions, T xs, T ys) where T : unmanaged { - // #TODO: this construction is just a little bit unhinged lol Span variables = stackalloc T[evaluationInstructions.Instructions.Length]; // compile if we've not already cached this instruction set, and evaluate! @@ -1034,7 +1034,6 @@ internal static class Interpreter public static T EvaluateInterpreted(EvaluationInstructions evaluationInstructions, T xs, T ys) where T : unmanaged { - // #TODO: this construction is just a little bit unhinged lol Span variables = stackalloc T[evaluationInstructions.Instructions.Length]; foreach (ref Instruction instruction in evaluationInstructions.Instructions.AsSpan())