checkpointing on the mad road to register allocation

This commit is contained in:
Torsten Ruger
2014-05-13 18:21:24 +03:00
parent b0302948dd
commit f6711ea49c
12 changed files with 86 additions and 76 deletions

View File

@ -34,11 +34,7 @@ module Vm
end
def add_code(kode)
if( kode.is_a? Array )
kode.each { |code| @codes << code }
else
@codes << kode
end
@codes << kode
self
end

View File

@ -11,7 +11,7 @@ module Vm
class IntegerConstant < Constant
def init int
def initialize int
@integer = int
end
attr_reader :integer

View File

@ -12,6 +12,6 @@ module Vm
@attributes = {}
@attributes[:program] = program
end
attr_reader :attributes
end
end

View File

@ -22,24 +22,24 @@ module Vm
super()
@name = name
@args = args
@entry = Core::Kernel::function_entry( name )
@exit = Core::Kernel::function_exit( name )
@body = Block.new("#{name}_body")
@entry = Core::Kernel::function_entry( Vm::Block.new("#{name}_exit") ,name )
@exit = Core::Kernel::function_exit( Vm::Block.new("#{name}_entry") , name )
@body = Block.new("#{name}_body")
@reg_count = 0
branch_body
end
attr_reader :args , :entry , :exit , :body , :name
# this creates a branch from entry here and from here to exit
# unless there is a link existing, in which you are resposible
def set_body body
@body = body
branch_body
end
def arity
@args.length
end
def next_register
next_free = @reg_count
@reg_count += 1
next_free + args.length
end
def link_at address , context
raise "undefined code #{inspect}" if @body.nil?
super #just sets the position
@ -66,10 +66,5 @@ module Vm
@entry.set_next(@body)
@body.set_next(@exit) if @body and !@body.next
end
def add_arg value
# TODO check
@args << value
end
end
end

View File

@ -12,9 +12,9 @@ module Vm
attr_reader :function , :args , :name
def load_args into
raise args.inspect
args.each_with_index do |arg , index|
into.add_code arg.load("r#{index}".to_sym)
puts "load " + arg.inspect
into.add_code arg.move("r#{index}".to_sym)
end
end

View File

@ -31,10 +31,10 @@ module Vm
@objects = []
# global functions
@functions = []
@entry = Core::Kernel::main_start
@entry = Core::Kernel::main_start Vm::Block.new("main_entry")
#main gets executed between entry and exit
@main = Block.new("main")
@exit = Core::Kernel::main_exit
@exit = Core::Kernel::main_exit Vm::Block.new("main_exit")
end
attr_reader :context , :main , :functions
@ -58,9 +58,7 @@ module Vm
fun = get_function name
unless fun
puts @functions.inspect
fun = Function.new(name)
block = Core::Kernel.send(name)
fun.set_body block
fun = Core::Kernel.send(name)
@functions << fun
end
fun

View File

@ -27,6 +27,11 @@ module Vm
end
end
# Just a nice way to write branches
class Bool < Value
end
# This is what it is when we don't know what it is.
# Must be promoted to A Word-Value to to anything
# remembering that our oo machine is typed, no overloading or stuff
@ -34,10 +39,12 @@ module Vm
attr_accessor :register
def initialize reg
register = reg
def inspect
self.class.name + ":reg:#{register}:"
end
def initialize reg
@register = reg
end
def length
4
end
@ -45,19 +52,23 @@ module Vm
class Unsigned < Word
def plus unsigned
Machine.instance.unsigned_plus self , unsigned
def plus block , unsigned
CMachine.instance.unsigned_plus self , unsigned
end
end
class Integer < Word
def less_or_equal right
Machine.instance.integer_less_or_equal self , right
def less_or_equal block , right
CMachine.instance.integer_less_or_equal block , self , right
end
def plus right
Machine.instance.integer_plus self , right
def plus block , right
CMachine.instance.integer_plus block , self , right
end
def load block , right
CMachine.instance.integer_load block , self , right
end
end
end