carry constants through in reference slots. resolve functions with it
This commit is contained in:
parent
bdd4a3d6ad
commit
c92b165a3f
@ -13,32 +13,36 @@ module Ast
|
|||||||
class IntegerExpression < Expression
|
class IntegerExpression < Expression
|
||||||
# attr_reader :value
|
# attr_reader :value
|
||||||
def compile method , message
|
def compile method , message
|
||||||
to = Virtual::NewReturn.new(Virtual::Integer)
|
int = Virtual::IntegerConstant.new(value)
|
||||||
method.add_code Virtual::Set.new( to , Virtual::IntegerConstant.new(value))
|
to = Virtual::NewReturn.new(Virtual::Integer , int)
|
||||||
|
method.add_code Virtual::Set.new( to , int)
|
||||||
to
|
to
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class TrueExpression
|
class TrueExpression
|
||||||
def compile method , message
|
def compile method , message
|
||||||
to = Virtual::Return.new(Virtual::Reference)
|
value = Virtual::TrueConstant.new
|
||||||
method.add_code Virtual::Set.new( to , Virtual::TrueConstant.new )
|
to = Virtual::Return.new(Virtual::Reference , value)
|
||||||
|
method.add_code Virtual::Set.new( to , value )
|
||||||
to
|
to
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class FalseExpression
|
class FalseExpression
|
||||||
def compile method , message
|
def compile method , message
|
||||||
to = Virtual::Return.new(Virtual::Reference)
|
value = Virtual::FalseConstant.new
|
||||||
method.add_code Virtual::Set.new( to , Virtual::FalseConstant.new )
|
to = Virtual::Return.new(Virtual::Reference , value)
|
||||||
|
method.add_code Virtual::Set.new( to , value )
|
||||||
to
|
to
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class NilExpression
|
class NilExpression
|
||||||
def compile method , message
|
def compile method , message
|
||||||
to = Virtual::Return.new(Virtual::Reference)
|
value = Virtual::NilConstant.new
|
||||||
method.add_code Virtual::Set.new( to , Virtual::NilConstant.new )
|
to = Virtual::Return.new(Virtual::Reference , value)
|
||||||
|
method.add_code Virtual::Set.new( to , value )
|
||||||
to
|
to
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -63,9 +67,9 @@ module Ast
|
|||||||
class ModuleName < NameExpression
|
class ModuleName < NameExpression
|
||||||
|
|
||||||
def compile method , message
|
def compile method , message
|
||||||
to = Virtual::Return.new(Virtual::Reference)
|
|
||||||
clazz = Virtual::BootSpace.space.get_or_create_class name
|
clazz = Virtual::BootSpace.space.get_or_create_class name
|
||||||
raise "uups #{clazz}.#{name}" unless clazz
|
raise "uups #{clazz}.#{name}" unless clazz
|
||||||
|
to = Virtual::Return.new(Virtual::Reference , clazz )
|
||||||
method.add_code Virtual::Set.new( to , clazz )
|
method.add_code Virtual::Set.new( to , clazz )
|
||||||
to
|
to
|
||||||
end
|
end
|
||||||
@ -74,8 +78,8 @@ module Ast
|
|||||||
class StringExpression < Expression
|
class StringExpression < Expression
|
||||||
# attr_reader :string
|
# attr_reader :string
|
||||||
def compile method , message
|
def compile method , message
|
||||||
to = Virtual::Return.new(Virtual::Reference)
|
|
||||||
value = Virtual::StringConstant.new(string)
|
value = Virtual::StringConstant.new(string)
|
||||||
|
to = Virtual::Return.new(Virtual::Reference , value)
|
||||||
Virtual::BootSpace.space.add_object value
|
Virtual::BootSpace.space.add_object value
|
||||||
method.add_code Virtual::Set.new( to , value )
|
method.add_code Virtual::Set.new( to , value )
|
||||||
to
|
to
|
||||||
|
@ -6,14 +6,15 @@ module Virtual
|
|||||||
def run block
|
def run block
|
||||||
block.codes.dup.each do |code|
|
block.codes.dup.each do |code|
|
||||||
next unless code.is_a? MessageSend
|
next unless code.is_a? MessageSend
|
||||||
me = code.me
|
ref = code.me
|
||||||
raise "ahm" unless ( me.type == Reference)
|
raise "only refs implemented #{me.inspect}" unless ( ref.type == Reference)
|
||||||
if( me.is_a? Constant)
|
if(ref.value)
|
||||||
|
me = ref.value
|
||||||
if( me.is_a? BootClass )
|
if( me.is_a? BootClass )
|
||||||
raise "unimplemented #{code}"
|
raise "unimplemented #{code}"
|
||||||
elsif( me.is_a? ObjectConstant )
|
elsif( me.is_a? ObjectConstant )
|
||||||
clazz = me.clazz
|
# get the function from my class. easy peasy
|
||||||
method = clazz.get_instance_method code.name
|
method = me.clazz.get_instance_method(code.name)
|
||||||
raise "Method not implemented #{clazz.name}.#{code.name}" unless method
|
raise "Method not implemented #{clazz.name}.#{code.name}" unless method
|
||||||
call = FunctionCall.new( method )
|
call = FunctionCall.new( method )
|
||||||
block.replace(code , call )
|
block.replace(code , call )
|
||||||
@ -21,7 +22,7 @@ module Virtual
|
|||||||
raise "unimplemented #{code}"
|
raise "unimplemented #{code}"
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
raise "unimplemented #{code.me}"
|
raise "not constant/ known object for send #{me.inspect}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -15,64 +15,65 @@ module Virtual
|
|||||||
NAME = 3
|
NAME = 3
|
||||||
MESSAGE_PAYLOAD = 4
|
MESSAGE_PAYLOAD = 4
|
||||||
|
|
||||||
attr_accessor :index , :type
|
attr_accessor :index , :type , :value
|
||||||
private #abstract base class
|
private #abstract base class
|
||||||
def initialize index , type
|
def initialize index , type , value
|
||||||
@index = index
|
@index = index
|
||||||
@type = type
|
@type = type
|
||||||
|
@value = value
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class MessageSlot < Slot
|
class MessageSlot < Slot
|
||||||
def initialize index , type = Mystery
|
def initialize index , type = Mystery , value = nil
|
||||||
super(index + MESSAGE_PAYLOAD ,type)
|
super(index + MESSAGE_PAYLOAD ,type , value )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
class FrameSlot < Slot
|
class FrameSlot < Slot
|
||||||
def initialize index , type = Mystery
|
def initialize index , type = Mystery, value = nil
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
class SelfSlot < Slot
|
class SelfSlot < Slot
|
||||||
def initialize index , type = Mystery
|
def initialize index , type = Mystery, value = nil
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
class NewMessageSlot < Slot
|
class NewMessageSlot < Slot
|
||||||
def initialize index , type = Mystery
|
def initialize index , type = Mystery, value = nil
|
||||||
super(index + MESSAGE_PAYLOAD , type)
|
super(index + MESSAGE_PAYLOAD , type , value )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Return < MessageSlot
|
class Return < MessageSlot
|
||||||
def initialize type = Mystery
|
def initialize type = Mystery, value = nil
|
||||||
super( RETURN - MESSAGE_PAYLOAD, type )
|
super( RETURN - MESSAGE_PAYLOAD, type , value )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
class Self < MessageSlot
|
class Self < MessageSlot
|
||||||
def initialize type = Mystery
|
def initialize type = Mystery, value = nil
|
||||||
super( SELF - MESSAGE_PAYLOAD , type )
|
super( SELF - MESSAGE_PAYLOAD , type , value )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
class Name < MessageSlot
|
class Name < MessageSlot
|
||||||
def initialize type = Mystery
|
def initialize type = Mystery, value = nil
|
||||||
super( NAME - MESSAGE_PAYLOAD , type )
|
super( NAME - MESSAGE_PAYLOAD , type , value )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class NewReturn < NewMessageSlot
|
class NewReturn < NewMessageSlot
|
||||||
def initialize type = Mystery
|
def initialize type = Mystery, value = nil
|
||||||
super( RETURN - MESSAGE_PAYLOAD, type )
|
super( RETURN - MESSAGE_PAYLOAD, type , value )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
class NewSelf < NewMessageSlot
|
class NewSelf < NewMessageSlot
|
||||||
def initialize type = Mystery
|
def initialize type = Mystery, value = nil
|
||||||
super( SELF - MESSAGE_PAYLOAD , type )
|
super( SELF - MESSAGE_PAYLOAD , type , value )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
class NewName < NewMessageSlot
|
class NewName < NewMessageSlot
|
||||||
def initialize type = Mystery
|
def initialize type = Mystery, value = nil
|
||||||
super( NAME - MESSAGE_PAYLOAD , type )
|
super( NAME - MESSAGE_PAYLOAD , type , value )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user