Skip to content

Commit

Permalink
Implement opassign statements.
Browse files Browse the repository at this point in the history
  • Loading branch information
utkarshkukreti committed Jun 1, 2011
1 parent c2c0538 commit 166917a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/phaad/generator.rb
Expand Up @@ -102,6 +102,11 @@ def process(sexp)
process r
emit ";\n"
end
when :opassign
raise NotImplementedError, sexp.inspect unless sexp[2][0] == :@op
process(sexp[1])
emit " #{sexp[2][1]} "
process(sexp[3])
when :return
emit "return "
process sexp[1]
Expand Down
21 changes: 21 additions & 0 deletions spec/generator/binary_spec.rb
Expand Up @@ -52,4 +52,25 @@
it "should parse << as ." do
compile("'foo' << 'bar'").should == '"foo" . "bar";'
end

context "operator assign" do
it "should parse += -= *= /= %=" do
compile("a += 1").should == "$a += 1;"
compile("a -= 1").should == "$a -= 1;"
compile("a *= 1").should == "$a *= 1;"
compile("a /= 1").should == "$a /= 1;"
compile("a %= 1").should == "$a %= 1;"
end

it "should parse |= &= ^=" do
compile("a |= 1").should == "$a |= 1;"
compile("a &= 1").should == "$a &= 1;"
compile("a ^= 1").should == "$a ^= 1;"
end

it "should parse && ||" do
compile("a &&= false").should == "$a &&= FALSE;"
compile("a ||= false").should == "$a ||= FALSE;"
end
end
end

0 comments on commit 166917a

Please sign in to comment.