fix the init also, was using first message twice
not advancing after first load
This commit is contained in:
parent
3c90eb31c6
commit
dd0d162ebf
@ -28,12 +28,19 @@ module Mom
|
|||||||
# Get the message from Space and link it.
|
# Get the message from Space and link it.
|
||||||
def to_risc(compiler)
|
def to_risc(compiler)
|
||||||
builder = Risc::Builder.new(compiler)
|
builder = Risc::Builder.new(compiler)
|
||||||
|
build_with(builder)
|
||||||
|
end
|
||||||
|
|
||||||
|
# directly called by to_risc
|
||||||
|
# but also used directly in __init
|
||||||
|
def build_with(builder)
|
||||||
from = method_source
|
from = method_source
|
||||||
risc = builder.build { typed_method << from }
|
risc = builder.build { typed_method << from }
|
||||||
build_message_data(builder)
|
build_message_data(builder)
|
||||||
compiler.reset_regs
|
builder.compiler.reset_regs
|
||||||
return risc
|
return risc
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def source
|
def source
|
||||||
"method setup "
|
"method setup "
|
||||||
|
@ -6,11 +6,6 @@ class String
|
|||||||
self[0].capitalize + self[1..-1]
|
self[0].capitalize + self[1..-1]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
class Symbol
|
|
||||||
def camelize
|
|
||||||
self.to_s.camelize.to_sym
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
# The RiscMachine, is an abstract machine with registers. Think of it as an arm machine with
|
# The RiscMachine, is an abstract machine with registers. Think of it as an arm machine with
|
||||||
|
@ -2,7 +2,7 @@ module Risc
|
|||||||
|
|
||||||
class Builder
|
class Builder
|
||||||
|
|
||||||
attr_reader :built
|
attr_reader :built , :compiler
|
||||||
|
|
||||||
def initialize(compiler)
|
def initialize(compiler)
|
||||||
@compiler = compiler
|
@compiler = compiler
|
||||||
@ -75,7 +75,7 @@ module Risc
|
|||||||
when Parfait::Object
|
when Parfait::Object
|
||||||
type = Parfait.object_space.get_class_by_name( object.class.name.split("::").last.to_sym).instance_type
|
type = Parfait.object_space.get_class_by_name( object.class.name.split("::").last.to_sym).instance_type
|
||||||
when Symbol
|
when Symbol
|
||||||
object = object.camelize
|
object = object.to_s.camelize.to_sym
|
||||||
clazz = Parfait.object_space.get_class_by_name(object)
|
clazz = Parfait.object_space.get_class_by_name(object)
|
||||||
raise "Not implemented/found object #{object}:#{object.class}" unless clazz
|
raise "Not implemented/found object #{object}:#{object.class}" unless clazz
|
||||||
type = clazz.instance_type
|
type = clazz.instance_type
|
||||||
|
@ -46,17 +46,22 @@ module Risc
|
|||||||
def __init__ context
|
def __init__ context
|
||||||
compiler = Risc::MethodCompiler.create_method(:Object,:__init__ ,
|
compiler = Risc::MethodCompiler.create_method(:Object,:__init__ ,
|
||||||
Parfait::NamedList.type_for({}) , Parfait::NamedList.type_for({}))
|
Parfait::NamedList.type_for({}) , Parfait::NamedList.type_for({}))
|
||||||
space_reg = compiler.use_reg(:Space) #Set up the Space as self upon init
|
builder = Risc::Builder.new(compiler)
|
||||||
compiler.add_load_constant("__init__ load Space", Parfait.object_space , space_reg)
|
risc = builder.build do
|
||||||
message_ind = Risc.resolve_to_index( :Space , :first_message )
|
space << Parfait.object_space
|
||||||
#load the first_message (instance of space)
|
message << space[:first_message]
|
||||||
compiler.add_slot_to_reg( "__init__ load 1st message" , space_reg , message_ind , :message)
|
next_message << message[:next_message]
|
||||||
compiler.add_mom( Mom::MessageSetup.new(Parfait.object_space.get_main))
|
space[:first_message] << next_message
|
||||||
# but use it's next message, so main can return normally
|
end
|
||||||
compiler.add_slot_to_reg( "__init__ load 2nd message" , :message , :next_message , :message)
|
compiler.add_code(risc)
|
||||||
compiler.add_load_constant("__init__ load Space", Parfait.object_space , space_reg)
|
|
||||||
compiler.add_reg_to_slot( "__init__ store Space in message", space_reg , :message , :receiver)
|
Mom::MessageSetup.new(Parfait.object_space.get_main).build_with( builder )
|
||||||
#fixme: should add arg type here, as done in call_site (which this sort of is)
|
|
||||||
|
builder.build do
|
||||||
|
message << message[:next_message]
|
||||||
|
message[:receiver] << space
|
||||||
|
end
|
||||||
|
|
||||||
exit_label = Risc.label("_exit_label for __init__" , "#{compiler.type.object_class.name}.#{compiler.method.name}" )
|
exit_label = Risc.label("_exit_label for __init__" , "#{compiler.type.object_class.name}.#{compiler.method.name}" )
|
||||||
ret_tmp = compiler.use_reg(:Label)
|
ret_tmp = compiler.use_reg(:Label)
|
||||||
compiler.add_load_constant("__init__ load return", exit_label , ret_tmp)
|
compiler.add_load_constant("__init__ load return", exit_label , ret_tmp)
|
||||||
|
@ -79,6 +79,7 @@ module Risc
|
|||||||
instruction = instruction.next
|
instruction = instruction.next
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# add a risc instruction after the current (insertion point)
|
# add a risc instruction after the current (insertion point)
|
||||||
# the added instruction will become the new insertion point
|
# the added instruction will become the new insertion point
|
||||||
def add_code( instruction )
|
def add_code( instruction )
|
||||||
|
Loading…
Reference in New Issue
Block a user