diff --git a/src/kOS.Safe/Compilation/KS/Compiler.cs b/src/kOS.Safe/Compilation/KS/Compiler.cs index 2de644b33..b31533f8c 100644 --- a/src/kOS.Safe/Compilation/KS/Compiler.cs +++ b/src/kOS.Safe/Compilation/KS/Compiler.cs @@ -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()); diff --git a/src/kOS.Safe/Compilation/Opcode.cs b/src/kOS.Safe/Compilation/Opcode.cs index d7a65a8d1..17a5b8f02 100644 --- a/src/kOS.Safe/Compilation/Opcode.cs +++ b/src/kOS.Safe/Compilation/Opcode.cs @@ -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)); + } } } @@ -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)); + } } }