make block replace take array or single instruction

This commit is contained in:
Torsten Ruger 2014-08-30 16:57:56 +03:00
parent 48b33e5f9d
commit 6d67c03cc9
5 changed files with 13 additions and 6 deletions

View File

@ -11,7 +11,7 @@ module Register
block.codes.dup.each do |code|
next unless code.is_a? Virtual::FunctionCall
call = RegisterMachine.instance.call( code.method )
block.replace(code , [call] )
block.replace(code , call )
end
end
end

View File

@ -10,7 +10,7 @@ module Register
to = RegisterReference.new(:r0)
tmp = RegisterReference.new(:r5)
move = RegisterMachine.instance.ldr( to , tmp , code.to.index )
block.replace(code , [move] )
block.replace(code , move )
else
raise "Start coding #{code.inspect}"
end

View File

@ -38,7 +38,11 @@ module Virtual
index = @codes.index code
raise "Code not found #{code} in #{self}" unless index
@codes.delete_at(index)
@codes.insert(index , *new_codes)
if( new_codes.is_a? Array)
new_codes.reverse.each {|c| @codes.insert(index , c)}
else
@codes.insert(index , new_codes)
end
end
# returns if this is a block that ends in a call (and thus needs local variable handling)
@ -53,6 +57,10 @@ module Virtual
# Note: this will have to change for plocks and maybe anyway. back to oo, no more visitors
def set_position at
@position = at
@codes.each do |code|
code.position = at
at += code.length
end
end
def length

View File

@ -42,10 +42,9 @@ module Virtual
@tmps = []
@receiver = receiver
@return_type = return_type
@blocks = []
# first block we have to create with .new , as new_block assumes a current
enter = Block.new( name , self ).add_code(MethodEnter.new())
@blocks << enter
@blocks = [enter]
@current = enter
new_block("return").add_code(MethodReturn.new)
end

View File

@ -16,7 +16,7 @@ module Virtual
method = clazz.get_instance_method code.name
raise "Method not implemented #{clazz.name}.#{code.name}" unless method
call = FunctionCall.new( method )
block.replace(code , [call] )
block.replace(code , call )
else
raise "unimplemented"
end