From f34fddd3832b0528894253a452194e6ec9212266 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Mon, 19 May 2014 21:28:18 +0300 Subject: [PATCH] minor --- lib/ast/call_site_expression.rb | 9 +++++---- lib/ast/function_expression.rb | 2 +- lib/elf/object_writer.rb | 3 ++- test/runners/fibo_while.rb | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/ast/call_site_expression.rb b/lib/ast/call_site_expression.rb index 8e6d7020..61c06987 100644 --- a/lib/ast/call_site_expression.rb +++ b/lib/ast/call_site_expression.rb @@ -14,18 +14,19 @@ module Ast save_locals context , into call.load_args into call.do_call into - resore_locals context , into + restore_locals context , into + function.return_type end def save_locals context , into into.instance_eval do - push [:r0, :r1 , :r2] + push [:r1 , :r2 , :r3] end end - def resore_locals context , into + def restore_locals context , into into.instance_eval do - pop [:r0, :r1 , :r2] + pop [:r1, :r2 , :r3] end end diff --git a/lib/ast/function_expression.rb b/lib/ast/function_expression.rb index d103b2bf..539690c2 100644 --- a/lib/ast/function_expression.rb +++ b/lib/ast/function_expression.rb @@ -38,7 +38,7 @@ module Ast body.each do |b| compiled = b.compile(context , into) function.return_type = compiled - puts "compiled in function #{compiled.inspect}" + puts "compiled in function #{compiled.class}" raise "alarm #{compiled} \n #{b}" unless compiled.is_a? Vm::Word end context.locals = parent_locals diff --git a/lib/elf/object_writer.rb b/lib/elf/object_writer.rb index 8ed57d61..e16d1e94 100644 --- a/lib/elf/object_writer.rb +++ b/lib/elf/object_writer.rb @@ -21,7 +21,8 @@ module Elf binary = program.assemble(StringIO.new ) - blocks = program.functions.collect{ |f| [f.entry , f.exit , f.body] } +# blocks = program.functions.collect{ |f| [f.entry , f.exit , f.body] } + blocks = program.functions.collect{ |f| [f.body] } blocks += [program.entry , program.exit , program.main] blocks.flatten.each do |b| add_symbol b.name.to_s , b.position diff --git a/test/runners/fibo_while.rb b/test/runners/fibo_while.rb index 399f0aa5..2a1e430a 100644 --- a/test/runners/fibo_while.rb +++ b/test/runners/fibo_while.rb @@ -5,9 +5,9 @@ def fibonaccit(n) # n == r0 tmp = a # r3 <- r1 a = b # r1 <- r2 b = tmp + b # r4 = r2 + r3 (r4 transient) r2 <- r4 - putint(b) n = n - 1 # r0 <- r2 for call, #call ok end #r5 <- r0 - 1 n=n-1 through r5 tmp + putint(b) end # r0 <- r5 fibonaccit( 10 )