Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #555 #683

Merged
merged 3 commits into from
Oct 28, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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