Skip to content

Commit

Permalink
Merge pull request #683 from goby-lang/fix-#555
Browse files Browse the repository at this point in the history
Fix #555
  • Loading branch information
st0012 committed Oct 28, 2019
2 parents 444cb91 + a7a0a5d commit 2600940
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
2 changes: 2 additions & 0 deletions compiler/bytecode/expression_generation.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ func (g *Generator) compilePrefixExpression(is *InstructionSet, exp *ast.PrefixE
is.define(PutObject, exp.Line(), 0)
g.compileExpression(is, exp.Right, scope, table)
is.define(Send, exp.Line(), exp.Operator, 1, "", &ArgSet{})
case "+":
g.compileExpression(is, exp.Right, scope, table)
}
}

Expand Down
3 changes: 2 additions & 1 deletion compiler/parser/expression_parsing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,8 @@ func TestArithmeticExpressionFail(t *testing.T) {
input string
error string
}{
{`{ 1 ++ 1 }`, `unexpected + Line: 0`},
{`{ 1 ++ 1 }`, `expected next token to be }, got +(+) instead. Line: 0`},
{`{ 1 -- 1 }`, `expected next token to be }, got -(-) instead. Line: 0`},
{`{ 1 * * 1 }`, `unexpected * Line: 0`},
{`{ 1 ** [1, 2] }`, `expected next token to be }, got **(**) instead. Line: 0`},
}
Expand Down
1 change: 1 addition & 0 deletions compiler/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func New(l *lexer.Lexer) *Parser {
p.registerPrefix(token.False, p.parseBooleanLiteral)
p.registerPrefix(token.Null, p.parseNilExpression)
p.registerPrefix(token.Minus, p.parsePrefixExpression)
p.registerPrefix(token.Plus, p.parsePrefixExpression)
p.registerPrefix(token.Asterisk, p.parsePrefixExpression)
p.registerPrefix(token.Bang, p.parsePrefixExpression)
p.registerPrefix(token.LParen, p.parseGroupedExpression)
Expand Down
20 changes: 20 additions & 0 deletions vm/evaluation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2242,6 +2242,26 @@ func TestMinusPrefixMethodCall(t *testing.T) {
}
}

func TestPlusPrefixMethodCall(t *testing.T) {
tests := []struct {
input string
expected int
}{
{"+5", 5},
{"+10", 10},
{"+(-10)", -10},
{"+(-5)", -5},
}

for i, tt := range tests {
v := initTestVM()
evaluated := v.testEval(t, tt.input, getFilename())
VerifyExpected(t, i, evaluated, tt.expected)
v.checkCFP(t, i, 0)
v.checkSP(t, i, 1)
}
}

func TestMultiVarAssignment(t *testing.T) {
tests := []struct {
input string
Expand Down

0 comments on commit 2600940

Please sign in to comment.