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.
|
||||
def to_risc(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
|
||||
risc = builder.build { typed_method << from }
|
||||
build_message_data(builder)
|
||||
compiler.reset_regs
|
||||
builder.compiler.reset_regs
|
||||
return risc
|
||||
end
|
||||
|
||||
private
|
||||
def source
|
||||
"method setup "
|
||||
|
@ -6,11 +6,6 @@ class String
|
||||
self[0].capitalize + self[1..-1]
|
||||
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
|
||||
|
@ -2,7 +2,7 @@ module Risc
|
||||
|
||||
class Builder
|
||||
|
||||
attr_reader :built
|
||||
attr_reader :built , :compiler
|
||||
|
||||
def initialize(compiler)
|
||||
@compiler = compiler
|
||||
@ -75,7 +75,7 @@ module Risc
|
||||
when Parfait::Object
|
||||
type = Parfait.object_space.get_class_by_name( object.class.name.split("::").last.to_sym).instance_type
|
||||
when Symbol
|
||||
object = object.camelize
|
||||
object = object.to_s.camelize.to_sym
|
||||
clazz = Parfait.object_space.get_class_by_name(object)
|
||||
raise "Not implemented/found object #{object}:#{object.class}" unless clazz
|
||||
type = clazz.instance_type
|
||||
|
@ -46,17 +46,22 @@ module Risc
|
||||
def __init__ context
|
||||
compiler = Risc::MethodCompiler.create_method(:Object,:__init__ ,
|
||||
Parfait::NamedList.type_for({}) , Parfait::NamedList.type_for({}))
|
||||
space_reg = compiler.use_reg(:Space) #Set up the Space as self upon init
|
||||
compiler.add_load_constant("__init__ load Space", Parfait.object_space , space_reg)
|
||||
message_ind = Risc.resolve_to_index( :Space , :first_message )
|
||||
#load the first_message (instance of space)
|
||||
compiler.add_slot_to_reg( "__init__ load 1st message" , space_reg , message_ind , :message)
|
||||
compiler.add_mom( Mom::MessageSetup.new(Parfait.object_space.get_main))
|
||||
# but use it's next message, so main can return normally
|
||||
compiler.add_slot_to_reg( "__init__ load 2nd message" , :message , :next_message , :message)
|
||||
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)
|
||||
#fixme: should add arg type here, as done in call_site (which this sort of is)
|
||||
builder = Risc::Builder.new(compiler)
|
||||
risc = builder.build do
|
||||
space << Parfait.object_space
|
||||
message << space[:first_message]
|
||||
next_message << message[:next_message]
|
||||
space[:first_message] << next_message
|
||||
end
|
||||
compiler.add_code(risc)
|
||||
|
||||
Mom::MessageSetup.new(Parfait.object_space.get_main).build_with( builder )
|
||||
|
||||
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}" )
|
||||
ret_tmp = compiler.use_reg(:Label)
|
||||
compiler.add_load_constant("__init__ load return", exit_label , ret_tmp)
|
||||
|
@ -79,6 +79,7 @@ module Risc
|
||||
instruction = instruction.next
|
||||
end
|
||||
end
|
||||
|
||||
# add a risc instruction after the current (insertion point)
|
||||
# the added instruction will become the new insertion point
|
||||
def add_code( instruction )
|
||||
|
Loading…
Reference in New Issue
Block a user