From 6d67c03cc92ec27f930e70cba5c3bf948650b574 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sat, 30 Aug 2014 16:57:56 +0300 Subject: [PATCH] make block replace take array or single instruction --- lib/register/call_implementation.rb | 2 +- lib/register/set_implementation.rb | 2 +- lib/virtual/block.rb | 10 +++++++++- lib/virtual/compiled_method.rb | 3 +-- lib/virtual/send_implementation.rb | 2 +- 5 files changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/register/call_implementation.rb b/lib/register/call_implementation.rb index bc002bc1..138e3b8d 100644 --- a/lib/register/call_implementation.rb +++ b/lib/register/call_implementation.rb @@ -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 diff --git a/lib/register/set_implementation.rb b/lib/register/set_implementation.rb index 0e9d71e2..c2e9774f 100644 --- a/lib/register/set_implementation.rb +++ b/lib/register/set_implementation.rb @@ -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 diff --git a/lib/virtual/block.rb b/lib/virtual/block.rb index cab0c7f8..453664ad 100644 --- a/lib/virtual/block.rb +++ b/lib/virtual/block.rb @@ -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 diff --git a/lib/virtual/compiled_method.rb b/lib/virtual/compiled_method.rb index b9dc0e0f..f55266db 100644 --- a/lib/virtual/compiled_method.rb +++ b/lib/virtual/compiled_method.rb @@ -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 diff --git a/lib/virtual/send_implementation.rb b/lib/virtual/send_implementation.rb index 89330769..76bc841d 100644 --- a/lib/virtual/send_implementation.rb +++ b/lib/virtual/send_implementation.rb @@ -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