From 5c362d8e13cdd9b59220e2781dd8029422ce25f6 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Sat, 28 Jul 2018 18:58:04 -0700 Subject: [PATCH] "Fix" register allocation. --- src/chalk/codegen.cr | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/chalk/codegen.cr b/src/chalk/codegen.cr index 3615a5f..334850a 100644 --- a/src/chalk/codegen.cr +++ b/src/chalk/codegen.cr @@ -86,16 +86,17 @@ module Chalk when TreeBlock table = Table.new(table) tree.children.each do |child| - free += generate! child, table, free, free + free += generate! child, table, free, free + 1 end when TreeVar entry = table[tree.name]? if entry == nil entry = VarEntry.new free + free += 1 table[tree.name] = entry end raise "Unknown variable" unless entry.is_a?(VarEntry) - generate! tree.expr, table, entry.register, free + 1 + generate! tree.expr, table, entry.register, free return 1 when TreeAssign entry = table[tree.name]? @@ -118,7 +119,7 @@ module Chalk when TreeWhile before_cond = @instructions.size generate! tree.condition, table, free, free + 1 - sne target, 0 + sne free, 0 cond_jump = jr 0 old_size = @instructions.size