Skip to content

Commit

Permalink
AdventureSample - refactor binary operator
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbymcr committed Apr 22, 2018
1 parent e72d20c commit ffbe4dc
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions projects/AdventureSample/src/GWBas2CS/BasicVisitor.cs
Expand Up @@ -299,7 +299,7 @@ public void Operator(string name, BasicExpression[] operands)
switch (name)
{
case "Add":
this.Value = this.DoAdd(operands[0], operands[1]);
this.Value = this.Binary(this.generator.AddExpression, operands[0], operands[1]);
break;
default:
throw new NotSupportedException("Operator:" + name);
Expand All @@ -311,13 +311,13 @@ public void Variable(BasicType type, string name)
this.Value = this.vars.Add(type, name);
}

private SyntaxNode DoAdd(BasicExpression left, BasicExpression right)
private SyntaxNode Binary(Func<SyntaxNode, SyntaxNode, SyntaxNode> op, BasicExpression left, BasicExpression right)
{
left.Accept(this);
SyntaxNode x = this.Value;
right.Accept(this);
SyntaxNode y = this.Value;
return this.generator.AddExpression(x, y);
return op(x, y);
}
}

Expand Down

0 comments on commit ffbe4dc

Please sign in to comment.