"Fix" register allocation.

This commit is contained in:
Danila Fedorin 2018-07-28 18:58:04 -07:00
parent 946db467ee
commit 5c362d8e13
1 changed files with 4 additions and 3 deletions

View File

@ -86,16 +86,17 @@ module Chalk
when TreeBlock when TreeBlock
table = Table.new(table) table = Table.new(table)
tree.children.each do |child| tree.children.each do |child|
free += generate! child, table, free, free free += generate! child, table, free, free + 1
end end
when TreeVar when TreeVar
entry = table[tree.name]? entry = table[tree.name]?
if entry == nil if entry == nil
entry = VarEntry.new free entry = VarEntry.new free
free += 1
table[tree.name] = entry table[tree.name] = entry
end end
raise "Unknown variable" unless entry.is_a?(VarEntry) 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 return 1
when TreeAssign when TreeAssign
entry = table[tree.name]? entry = table[tree.name]?
@ -118,7 +119,7 @@ module Chalk
when TreeWhile when TreeWhile
before_cond = @instructions.size before_cond = @instructions.size
generate! tree.condition, table, free, free + 1 generate! tree.condition, table, free, free + 1
sne target, 0 sne free, 0
cond_jump = jr 0 cond_jump = jr 0
old_size = @instructions.size old_size = @instructions.size