Skip to content

Commit

Permalink
Fix or/and expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
Raudius committed Nov 22, 2022
1 parent f07d749 commit 2bbdd0e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
24 changes: 14 additions & 10 deletions src/Interpreter/LuarExpressionVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,19 +249,23 @@ public function visitExpPower(Context\ExpPowerContext $context): LuarObject {
}

public function visitExpOr(Context\ExpOrContext $context): LuarObject {
$v1 = $this->visitExp($context->exp(0))->getValue();
if ($v1) return new Literal($v1);
$v2 = $this->visitExp($context->exp(1))->getValue();
if ($v2) return new Literal($v2);
return new Literal(false);
$o1 = $this->visitExp($context->exp(0));
$o2 = $this->visitExp($context->exp(1));

if ($this->isTrue($o1->getValue())) return $o1;
if ($this->isTrue($o2->getValue())) return $o2;

return new Literal(null);
}

public function visitExpAnd(Context\ExpAndContext $context): LuarObject {
$v1 = $this->visitExp($context->exp(0))->getValue();
if (!$v1) return new Literal(false);
$v2 = $this->visitExp($context->exp(1))->getValue();
if (!$v2) return new Literal(false);
return new Literal(true);
$o1 = $this->visitExp($context->exp(0));
$o2 = $this->visitExp($context->exp(1));

if (!$this->isTrue($o1->getValue())) return new Literal(null);
if (!$this->isTrue($o2->getValue())) return new Literal(null);

return $o2;
}

public function visitExpConcat(Context\ExpConcatContext $context): LuarObject {
Expand Down
1 change: 0 additions & 1 deletion src/Interpreter/LuarStatementVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ public function visitStatRepeat(Context\StatRepeatContext $context) {
throw new LuarRuntimeException('[INTERNAL ERROR] Could not parse while loop', $context);
}


do {
$newScope = new Scope($this->interpreter->getScope());
$newScope->setExpectedExit(Scope::EXIT_EXPECT_BREAK_CONTINUE);
Expand Down

0 comments on commit 2bbdd0e

Please sign in to comment.