Skip to content

Commit

Permalink
Initial commit of foo[bar] += baz, support
Browse files Browse the repository at this point in the history
  • Loading branch information
adambeynon committed Oct 24, 2013
1 parent 45f2c92 commit c723073
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/opal/cli.rb
Expand Up @@ -213,7 +213,7 @@ def prepare_eval_code
# SOURCE

def sexp
Opal::Grammar.new.parse(source)
Opal::Parser.new.parse(source)
end
end
end
21 changes: 21 additions & 0 deletions lib/opal/nodes/call_special.rb
Expand Up @@ -66,6 +66,27 @@ def first_arg
end

def compile
case op.to_s
when '||' then compile_or
when '&&' then compile_and
else compile_operator
end
end

def compile_operator
with_temp do |a| # args
with_temp do |r| # recv
cur = s(:call, s(:js_tmp, r), :[], s(:arglist, s(:js_tmp, a)))
rhs = s(:call, cur, :+, s(:arglist, self.rhs))
call = s(:call, s(:js_tmp, r), :[]=, s(:arglist, s(:js_tmp, a), rhs))

push "(#{a} = ", expr(first_arg), ", #{r} = ", expr(lhs)
push ", ", expr(call), ")"
end
end
end

def compile_or
with_temp do |a| # args
with_temp do |r| # recv
aref = s(:call, s(:js_tmp, r), :[], s(:arglist, s(:js_tmp, a)))
Expand Down

0 comments on commit c723073

Please sign in to comment.