diff --git a/Qrakhen.Qamp.Core/Compilation/ExpressionParser.cs b/Qrakhen.Qamp.Core/Compilation/ExpressionParser.cs index d466950..c984cb2 100644 --- a/Qrakhen.Qamp.Core/Compilation/ExpressionParser.cs +++ b/Qrakhen.Qamp.Core/Compilation/ExpressionParser.cs @@ -210,6 +210,13 @@ public static class ExpressionParser if (canAssign && digester.Match(TokenType.Assignment, false)) { var token = digester.Previous.Type; + + if (token != TokenType.Equal) { + // Get the variable's value for the operation + digester.Emit(Get); + digester.EmitDynamic(variable); + } + if (token == TokenType.Increment || token == TokenType.Decrement) { // In the case of atomic change, we just forge the value ourselves. digester.EmitConstant(new Value(1L)); @@ -218,13 +225,8 @@ public static class ExpressionParser digester.ParseExpression(); } - // Check whether this is just an assignment. if (token != TokenType.Equal) { - // Get the variable's value for the operation - digester.Emit(Get); - digester.EmitDynamic(variable); - // Append the operator OpCode op = token switch { diff --git a/Qrakhen.Qamp.Core/Execution/Runner.cs b/Qrakhen.Qamp.Core/Execution/Runner.cs index b96f06c..073a3c1 100644 --- a/Qrakhen.Qamp.Core/Execution/Runner.cs +++ b/Qrakhen.Qamp.Core/Execution/Runner.cs @@ -87,7 +87,7 @@ public class Runner : IDisposable _logger.Verbose($"OpCode: {opCode}"); #endif - IO.Console.Write($"{opCode}: \n - {string.Join("\n - ", Stack.ToArray().Subset(0, Stack.Count))}"); + //IO.Console.Write($"{opCode}: \n - {string.Join("\n - ", Stack.ToArray().Subset(0, Stack.Count))}"); if (TestFlag(opCode, Op.F_Operation)) { Value result = ValueOperation.Resolve(PopOperation(opCode)); @@ -138,7 +138,7 @@ public class Runner : IDisposable return Error($"tried to set global variable with empty name"); if (!Globals.Has(name)) return Error($"tried to set a value of non-existing global variable"); - Globals[name] = Pop(); + Globals[name] = Peek(); #if LOG _logger.Verbose($"set global {name} = {Globals[name]}"); #endif @@ -349,11 +349,16 @@ public class Runner : IDisposable } case Op.Return: { - Value result = Pop(); + Value result = Pop(); CloseOuters(call.StackPtr.Branch()); Calls.Pop(); if (Calls.Count == 0) { - Pop(); + if (Stack.Count > 0) { + // todo: very bad fix for our stack problem + Pop(); + } else { + _logger.Warn($"Critical issue at end of execution detected - stack was empty at return."); + } return ExecutionResult.OK; } Stack.Decimate(call.StackPtr.Cursor);