some cleaning of scratches

This commit is contained in:
Torsten Ruger 2014-07-16 22:36:24 +03:00
parent efeb910843
commit 58298ab62b
3 changed files with 20 additions and 88 deletions

View File

@ -70,6 +70,26 @@ module Ast
r = right.compile(frame , method)
frame.compile_set( method , left.name , r )
end
def old_scratch
if operator == "=" # assignment, value based
if(left.is_a? VariableExpression)
left.make_setter
l_val = left.compile(context)
elsif left.is_a?(NameExpression)
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
raise "Can only assign variables, not #{left}"
end
return l_val
end
end
end
class VariableExpression < NameExpression

View File

@ -26,41 +26,5 @@ module Ast
#TODO should return the union of the true and false types
last
end
def old
f = context.function
# to execute the logic as the if states it, the blocks are the other way around
# so we can the jump over the else if true ,and the else joins unconditionally after the true_block
merge_block = f.new_block "if_merge"
true_block = f.new_block "if_true"
false_block = f.new_block "if_false"
puts "compiling if condition #{cond}"
cond_val = cond.compile(context)
unless cond_val.is_a? Virtual::BranchCondition
cond_val = cond_val.is_true? f
end
f.b true_block , condition_code: cond_val.operator
f.insertion_point.branch = true_block
f.insert_at false_block
if_false.each do |part|
puts "compiling in if false #{part}"
last = part.compile(context )
end
f.b merge_block
f.insertion_point.branch = false_block
f.insert_at true_block
last = nil
if_true.each do |part|
puts "compiling in if true #{part}"
last = part.compile(context )
end
puts "compiled if: end"
f.insert_at merge_block
return last
end
end
end

View File

@ -5,57 +5,5 @@ module Ast
call = CallSiteExpression.new( operator , [right] , left )
call.compile(frame , method)
end
def scratch
into = context.function
puts "compiling operator #{to_s}"
r_val = right.compile(context)
#puts "compiled right #{r_val.inspect}"
if operator == "=" # assignment, value based
if(left.is_a? VariableExpression)
left.make_setter
l_val = left.compile(context)
elsif left.is_a?(NameExpression)
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
raise "Can only assign variables, not #{left}"
end
return l_val
end
l_val = left.compile(context)
case operator
when ">"
code = l_val.greater_than into , r_val
when "<"
code = l_val.less_than into , r_val
when ">="
code = l_val.greater_or_equal into , r_val
when "<="
code = l_val.less_or_equal into , r_val
when "=="
code = l_val.equals into , r_val
when "+"
res = context.function.new_local
into.add res , l_val , r_val
code = res
when "-"
res = context.function.new_local
code = res.minus into , l_val , r_val
when "<<"
res = context.function.new_local
code = res.left_shift into , l_val , r_val
else
raise "unimplemented operator #{operator} #{self}"
end
code
end
end
end