make block replace take array or single instruction
This commit is contained in:
parent
48b33e5f9d
commit
6d67c03cc9
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user