keep risc and cpu instructions separate in method

that overwriting was a bit of thorn
This commit is contained in:
Torsten Ruger
2018-03-25 19:33:50 +03:00
parent a50368c3aa
commit 3090ccffea
6 changed files with 29 additions and 15 deletions

View File

@ -15,7 +15,7 @@ module Parfait
end
# TODO Must get rid of the setter (move the boot process ?)
def self.set_object_space space
def self.set_object_space( space )
@@object_space = space
end
@ -31,7 +31,7 @@ module Parfait
class Space < Object
def initialize(classes )
def initialize( classes )
@classes = classes
@types = Dictionary.new
message = Message.new(nil)
@ -54,7 +54,7 @@ module Parfait
end
end
def add_type(type)
def add_type( type )
hash = type.hash
raise "upps #{hash} #{hash.class}" unless hash.is_a?(Fixnum)
was = @types[hash]

View File

@ -21,7 +21,8 @@ module Parfait
class TypedMethod < Object
attr_reader :name , :instructions , :for_type ,:arguments , :frame , :binary
attr_reader :name , :risc_instructions , :for_type , :cpu_instructions
attr_reader :arguments , :frame , :binary
# not part of the parfait model, hence ruby accessor
attr_accessor :source
@ -35,19 +36,32 @@ module Parfait
init(arguments, frame)
end
# (re) init with given args and frame types
# also set first risc_instruction to a label
def init(arguments, frame)
raise "Wrong argument type, expect Type not #{arguments.class}" unless arguments.is_a? Type
raise "Wrong frame type, expect Type not #{frame.class}" unless frame.is_a? Type
@arguments = arguments
@frame = frame
source = "_init_method"
name = "#{@for_type.name}.#{@name}"
@risc_instructions = Risc.label(source, name)
@risc_instructions << Risc.label( source, "unreachable")
end
def set_instructions(inst)
@instructions = inst
def translate_cpu(translator)
@cpu_instructions = translator.translate(@risc_instructions)
nekst = @risc_instructions.next
while(nekst)
cpu = nekst.to_cpu(translator) # returning nil means no replace
@cpu_instructions << cpu if cpu
nekst = nekst.next
end
@cpu_instructions
end
def create_binary
total = @instructions.total_byte_length / 4 + 1
total = @cpu_instructions.total_byte_length / 4 + 1
@binary = BinaryCode.new( total )
end