progress on the builder front

mainly tests for now
This commit is contained in:
Torsten Ruger
2018-04-06 14:54:24 +03:00
parent e396807ee5
commit 44d661fe56
4 changed files with 76 additions and 6 deletions

View File

@ -2,6 +2,8 @@ module Risc
class Builder
attr_reader :built
def initialize(compiler)
@compiler = compiler
end
@ -11,15 +13,28 @@ module Risc
name = args[0].to_s.capitalize.to_sym
type = Risc.resolve_type(name , @compiler)
reg = @compiler.use_reg( type )
reg.builder = self
puts reg
reg
end
def build(&block)
instance_eval(&block)
return built
end
def add_instruction(ins)
if(built)
built << ins
else
@built = ins
end
end
end
class RValue
end
def self.build(compiler, &block)
Builder.new(compiler).instance_eval( &block )
Builder.new(compiler).build( &block )
end
# if a symbol is given, it may be the message or the new_message.

View File

@ -4,9 +4,11 @@ module Risc
class RiscValue
attr_accessor :symbol , :type , :value
attr_reader :symbol , :type , :value
def initialize r , type , value = nil
attr_accessor :builder
def initialize( r , type , value = nil)
raise "wrong type for register init #{r}" unless r.is_a? Symbol
raise "double r #{r}" if r.to_s[0,1] == "rr"
raise "not reg #{r}" unless self.class.look_like_reg r
@ -62,10 +64,14 @@ module Risc
when RValue
raise "not yet"
when Parfait::Object
Risc.load_constant("#{load.class} to #{self.type}" , load , self)
ins = Risc.load_constant("#{load.class} to #{self.type}" , load , self)
when RiscValue
ins = Risc.transfer("#{load.type} to #{self.type}" , load , self)
else
raise "not implemented"
end
builder.add_instruction(ins) if builder
return ins
end
end