add rewriting of operator assignment

foo += 1 becomes foo = foo + 1 in vool
This commit is contained in:
Torsten Ruger
2018-06-25 16:32:20 +03:00
parent 70d7e654c4
commit 67a6ef9f67
6 changed files with 56 additions and 3 deletions

View File

@ -10,6 +10,7 @@ module Vool
# The next step is then to normalize the code and then finally to compile
# to the next level down, MOM (Minimal Object Machine)
class RubyCompiler < AST::Processor
include AST::Sexp
def self.compile(input)
ast = Parser::Ruby22.parse( input )
@ -132,6 +133,16 @@ module Vool
IvarAssignment.new(instance_name(name),value)
end
def on_op_asgn(expression)
ass , op , exp = *expression
name = ass.children[0]
a_type = ass.type.to_s[0,3]
rewrite = s( a_type + "sgn" ,
name ,
s(:send , s( a_type + "r" , name ) , op , exp ) )
process(rewrite)
end
def on_return statement
return_value = process(statement.children.first)
ReturnStatement.new( return_value )