more setter work

This commit is contained in:
Torsten Ruger 2014-06-24 12:20:59 +03:00
parent dc198ac79f
commit 25c5b2da6e

View File

@ -7,15 +7,21 @@ module Ast
r_val = right.compile(context) r_val = right.compile(context)
#puts "compiled right #{r_val.inspect}" #puts "compiled right #{r_val.inspect}"
if operator == "=" # assignment, value based if operator == "=" # assignment, value based
raise "Can only assign variables, not #{left}" unless left.is_a?(NameExpression) if(left.is_a? VariableExpression)
puts context.inspect unless context.locals left.make_setter
l_val = context.locals[left.name] l_val = left.compile(context)
if( l_val ) #variable existed, move data there elsif left.is_a?(NameExpression)
l_val = l_val.move( into , r_val) puts context.inspect unless context.locals
l_val = context.locals[left.name]
if( l_val ) #variable existed, move data there
l_val = l_val.move( into , r_val)
else
l_val = context.function.new_local.move( into , r_val )
end
context.locals[left.name] = l_val
else else
l_val = context.function.new_local.move( into , r_val ) raise "Can only assign variables, not #{left}"
end end
context.locals[left.name] = l_val
return l_val return l_val
end end