Implement ||
This commit is contained in:
@@ -2583,6 +2583,29 @@ class LogicalAnd : Code
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class LogicalOr : Code
|
||||
{
|
||||
int addr;
|
||||
override void execute(VM vm)
|
||||
{
|
||||
if (vm.stacki == 0)
|
||||
{
|
||||
throw new StackUnderFlow();
|
||||
}
|
||||
//FALSE->POP
|
||||
//TRUE->JUMP
|
||||
if (vm.stack[vm.stacki - 1].boolValue)
|
||||
{
|
||||
vm.pc = addr - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
vm.decSP;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ConvertBool : Code
|
||||
{
|
||||
//0 => 0(int)
|
||||
|
||||
@@ -512,6 +512,16 @@ class Compiler
|
||||
jmp.addr = cast(int)code.length;
|
||||
break;
|
||||
}
|
||||
if (binop.operator == TokenType.LogicalOr)
|
||||
{
|
||||
compileExpression(binop.item1, sc);
|
||||
auto jmp = new LogicalOr();
|
||||
genCode(jmp);
|
||||
compileExpression(binop.item2, sc);
|
||||
jmp.addr = cast(int)code.length;
|
||||
genCode(new ConvertBool());
|
||||
break;
|
||||
}
|
||||
compileExpression(binop.item1, sc);
|
||||
compileExpression(binop.item2, sc);
|
||||
if(binop.operator == TokenType.LBracket)
|
||||
|
||||
Reference in New Issue
Block a user