keep risc and cpu instructions separate in method
that overwriting was a bit of thorn
This commit is contained in:
parent
a50368c3aa
commit
3090ccffea
@ -26,7 +26,7 @@ module Elf
|
|||||||
# for debug add labels for labels
|
# for debug add labels for labels
|
||||||
Parfait.object_space.each_type do |type|
|
Parfait.object_space.each_type do |type|
|
||||||
type.methods.each do |f|
|
type.methods.each do |f|
|
||||||
f.instructions.each_label do |label|
|
f.risc_instructions.each_label do |label|
|
||||||
add_symbol "#{type.name}::#{f.name}:#{label.name}" , Positioned.position(label)
|
add_symbol "#{type.name}::#{f.name}:#{label.name}" , Positioned.position(label)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -15,7 +15,7 @@ module Parfait
|
|||||||
end
|
end
|
||||||
|
|
||||||
# TODO Must get rid of the setter (move the boot process ?)
|
# 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
|
@@object_space = space
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -31,7 +31,7 @@ module Parfait
|
|||||||
|
|
||||||
class Space < Object
|
class Space < Object
|
||||||
|
|
||||||
def initialize(classes )
|
def initialize( classes )
|
||||||
@classes = classes
|
@classes = classes
|
||||||
@types = Dictionary.new
|
@types = Dictionary.new
|
||||||
message = Message.new(nil)
|
message = Message.new(nil)
|
||||||
@ -54,7 +54,7 @@ module Parfait
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_type(type)
|
def add_type( type )
|
||||||
hash = type.hash
|
hash = type.hash
|
||||||
raise "upps #{hash} #{hash.class}" unless hash.is_a?(Fixnum)
|
raise "upps #{hash} #{hash.class}" unless hash.is_a?(Fixnum)
|
||||||
was = @types[hash]
|
was = @types[hash]
|
||||||
|
@ -21,7 +21,8 @@ module Parfait
|
|||||||
|
|
||||||
class TypedMethod < Object
|
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
|
# not part of the parfait model, hence ruby accessor
|
||||||
attr_accessor :source
|
attr_accessor :source
|
||||||
@ -35,19 +36,32 @@ module Parfait
|
|||||||
init(arguments, frame)
|
init(arguments, frame)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# (re) init with given args and frame types
|
||||||
|
# also set first risc_instruction to a label
|
||||||
def init(arguments, frame)
|
def init(arguments, frame)
|
||||||
raise "Wrong argument type, expect Type not #{arguments.class}" unless arguments.is_a? Type
|
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
|
raise "Wrong frame type, expect Type not #{frame.class}" unless frame.is_a? Type
|
||||||
@arguments = arguments
|
@arguments = arguments
|
||||||
@frame = frame
|
@frame = frame
|
||||||
|
source = "_init_method"
|
||||||
|
name = "#{@for_type.name}.#{@name}"
|
||||||
|
@risc_instructions = Risc.label(source, name)
|
||||||
|
@risc_instructions << Risc.label( source, "unreachable")
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_instructions(inst)
|
def translate_cpu(translator)
|
||||||
@instructions = inst
|
@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
|
end
|
||||||
|
|
||||||
def create_binary
|
def create_binary
|
||||||
total = @instructions.total_byte_length / 4 + 1
|
total = @cpu_instructions.total_byte_length / 4 + 1
|
||||||
@binary = BinaryCode.new( total )
|
@binary = BinaryCode.new( total )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -149,9 +149,9 @@ module Risc
|
|||||||
super_class_name: :Word , instance_names: :List },
|
super_class_name: :Word , instance_names: :List },
|
||||||
Dictionary: {keys: :List , values: :List } ,
|
Dictionary: {keys: :List , values: :List } ,
|
||||||
CacheEntry: {cached_type: :Type , cached_method: :TypedMethod } ,
|
CacheEntry: {cached_type: :Type , cached_method: :TypedMethod } ,
|
||||||
TypedMethod: {name: :Word, source: :Object, instructions: :Object,
|
TypedMethod: {name: :Word, source: :Object, risc_instructions: :Object,
|
||||||
binary: :BinaryCode, arguments: :Type , for_type: :Type,
|
cpu_instructions: :Object, binary: :BinaryCode,
|
||||||
frame: :Type } ,
|
arguments: :Type , for_type: :Type, frame: :Type } ,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ module Risc
|
|||||||
def start( instruction )
|
def start( instruction )
|
||||||
initialize
|
initialize
|
||||||
set_state(:running)
|
set_state(:running)
|
||||||
set_instruction instruction
|
set_instruction( instruction )
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_state( state )
|
def set_state( state )
|
||||||
@ -54,7 +54,7 @@ module Risc
|
|||||||
end
|
end
|
||||||
|
|
||||||
def set_instruction( i )
|
def set_instruction( i )
|
||||||
raise "set to same instruction #{i}" if @instruction == i
|
raise "set to same instruction #{i}:#{i.class}" if @instruction == i
|
||||||
old = @instruction
|
old = @instruction
|
||||||
@instruction = i
|
@instruction = i
|
||||||
trigger(:instruction_changed, old , i)
|
trigger(:instruction_changed, old , i)
|
||||||
@ -195,7 +195,7 @@ module Risc
|
|||||||
end
|
end
|
||||||
|
|
||||||
def execute_FunctionCall
|
def execute_FunctionCall
|
||||||
set_instruction @instruction.method.instructions
|
set_instruction @instruction.method.risc_instructions
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ module Risc
|
|||||||
assert @expect , "No output given"
|
assert @expect , "No output given"
|
||||||
Vool::VoolCompiler.ruby_to_vool "class Test; def main(arg);#{@input};end;end"
|
Vool::VoolCompiler.ruby_to_vool "class Test; def main(arg);#{@input};end;end"
|
||||||
test = Parfait.object_space.get_class_by_name :Test
|
test = Parfait.object_space.get_class_by_name :Test
|
||||||
test.instance_type.get_method( :main).instructions
|
test.instance_type.get_method( :main).risc_instructions
|
||||||
end
|
end
|
||||||
def check_nil
|
def check_nil
|
||||||
produced = produce_instructions
|
produced = produce_instructions
|
||||||
|
Loading…
x
Reference in New Issue
Block a user