fix the stack issue for now by simply peeking the stack rather than popping it for global assignments.
This commit is contained in:
parent
9ec6f49450
commit
db68d9e9ce
|
|
@ -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
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue