Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/kOS.Safe/Compilation/KS/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2386,8 +2386,7 @@ private void VisitUntilStatement(ParseNode node)
string conditionLabel = GetNextLabel(false);
PushBreakList(braceNestLevel);
VisitNode(node.Nodes[1]);
AddOpcode(new OpcodeLogicNot());
Opcode branch = AddOpcode(new OpcodeBranchIfFalse());
Opcode branch = AddOpcode(new OpcodeBranchIfTrue());
AddToBreakList(branch);
VisitNode(node.Nodes[2]);
Opcode jump = AddOpcode(new OpcodeBranchJump());
Expand Down
23 changes: 18 additions & 5 deletions src/kOS.Safe/Compilation/Opcode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1058,9 +1058,15 @@ public class OpcodeBranchIfFalse : BranchOpcode

public override void Execute(ICpu cpu)
{
bool condition = Convert.ToBoolean(cpu.PopValueArgument());

DeltaInstructionPointer = !condition ? Distance : 1;
try
{
bool condition = Convert.ToBoolean(cpu.PopValueArgument());
DeltaInstructionPointer = !condition ? Distance : 1;
}
catch
{
throw new KOSCastException(value.GetType(), typeof(BooleanValue));
}
}
}

Expand All @@ -1079,8 +1085,15 @@ public class OpcodeBranchIfTrue : BranchOpcode

public override void Execute(ICpu cpu)
{
bool condition = Convert.ToBoolean(cpu.PopValueArgument());
DeltaInstructionPointer = condition ? Distance : 1;
try
{
bool condition = Convert.ToBoolean(cpu.PopValueArgument());
DeltaInstructionPointer = condition ? Distance : 1;
}
catch
{
throw new KOSCastException(value.GetType(), typeof(BooleanValue));
}
}
}

Expand Down