fix the stack issue for now by simply peeking the stack rather than popping it for global assignments.

This commit is contained in:
Qrakhen 2025-12-04 14:46:35 +01:00
parent 9ec6f49450
commit db68d9e9ce
2 changed files with 16 additions and 9 deletions

View File

@ -210,6 +210,13 @@ public static class ExpressionParser
if (canAssign && digester.Match(TokenType.Assignment, false)) { if (canAssign && digester.Match(TokenType.Assignment, false)) {
var token = digester.Previous.Type; 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) { if (token == TokenType.Increment || token == TokenType.Decrement) {
// In the case of atomic change, we just forge the value ourselves. // In the case of atomic change, we just forge the value ourselves.
digester.EmitConstant(new Value(1L)); digester.EmitConstant(new Value(1L));
@ -218,13 +225,8 @@ public static class ExpressionParser
digester.ParseExpression(); digester.ParseExpression();
} }
// Check whether this is just an assignment.
if (token != TokenType.Equal) if (token != TokenType.Equal)
{ {
// Get the variable's value for the operation
digester.Emit(Get);
digester.EmitDynamic(variable);
// Append the operator // Append the operator
OpCode op = token switch OpCode op = token switch
{ {

View File

@ -87,7 +87,7 @@ public class Runner : IDisposable
_logger.Verbose($"OpCode: {opCode}"); _logger.Verbose($"OpCode: {opCode}");
#endif #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)) { if (TestFlag(opCode, Op.F_Operation)) {
Value result = ValueOperation.Resolve(PopOperation(opCode)); Value result = ValueOperation.Resolve(PopOperation(opCode));
@ -138,7 +138,7 @@ public class Runner : IDisposable
return Error($"tried to set global variable with empty name"); return Error($"tried to set global variable with empty name");
if (!Globals.Has(name)) if (!Globals.Has(name))
return Error($"tried to set a value of non-existing global variable"); return Error($"tried to set a value of non-existing global variable");
Globals[name] = Pop(); Globals[name] = Peek();
#if LOG #if LOG
_logger.Verbose($"set global {name} = {Globals[name]}"); _logger.Verbose($"set global {name} = {Globals[name]}");
#endif #endif
@ -353,7 +353,12 @@ public class Runner : IDisposable
CloseOuters(call.StackPtr.Branch()); CloseOuters(call.StackPtr.Branch());
Calls.Pop(); Calls.Pop();
if (Calls.Count == 0) { 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; return ExecutionResult.OK;
} }
Stack.Decimate(call.StackPtr.Cursor); Stack.Decimate(call.StackPtr.Cursor);