carry constants through in reference slots. resolve functions with it

This commit is contained in:
Torsten Ruger 2014-09-15 12:08:37 +03:00
parent bdd4a3d6ad
commit c92b165a3f
3 changed files with 42 additions and 36 deletions

View File

@ -13,32 +13,36 @@ module Ast
class IntegerExpression < Expression
# attr_reader :value
def compile method , message
to = Virtual::NewReturn.new(Virtual::Integer)
method.add_code Virtual::Set.new( to , Virtual::IntegerConstant.new(value))
int = Virtual::IntegerConstant.new(value)
to = Virtual::NewReturn.new(Virtual::Integer , int)
method.add_code Virtual::Set.new( to , int)
to
end
end
class TrueExpression
def compile method , message
to = Virtual::Return.new(Virtual::Reference)
method.add_code Virtual::Set.new( to , Virtual::TrueConstant.new )
value = Virtual::TrueConstant.new
to = Virtual::Return.new(Virtual::Reference , value)
method.add_code Virtual::Set.new( to , value )
to
end
end
class FalseExpression
def compile method , message
to = Virtual::Return.new(Virtual::Reference)
method.add_code Virtual::Set.new( to , Virtual::FalseConstant.new )
value = Virtual::FalseConstant.new
to = Virtual::Return.new(Virtual::Reference , value)
method.add_code Virtual::Set.new( to , value )
to
end
end
class NilExpression
def compile method , message
to = Virtual::Return.new(Virtual::Reference)
method.add_code Virtual::Set.new( to , Virtual::NilConstant.new )
value = Virtual::NilConstant.new
to = Virtual::Return.new(Virtual::Reference , value)
method.add_code Virtual::Set.new( to , value )
to
end
end
@ -63,9 +67,9 @@ module Ast
class ModuleName < NameExpression
def compile method , message
to = Virtual::Return.new(Virtual::Reference)
clazz = Virtual::BootSpace.space.get_or_create_class name
raise "uups #{clazz}.#{name}" unless clazz
to = Virtual::Return.new(Virtual::Reference , clazz )
method.add_code Virtual::Set.new( to , clazz )
to
end
@ -74,8 +78,8 @@ module Ast
class StringExpression < Expression
# attr_reader :string
def compile method , message
to = Virtual::Return.new(Virtual::Reference)
value = Virtual::StringConstant.new(string)
to = Virtual::Return.new(Virtual::Reference , value)
Virtual::BootSpace.space.add_object value
method.add_code Virtual::Set.new( to , value )
to

View File

@ -6,14 +6,15 @@ module Virtual
def run block
block.codes.dup.each do |code|
next unless code.is_a? MessageSend
me = code.me
raise "ahm" unless ( me.type == Reference)
if( me.is_a? Constant)
ref = code.me
raise "only refs implemented #{me.inspect}" unless ( ref.type == Reference)
if(ref.value)
me = ref.value
if( me.is_a? BootClass )
raise "unimplemented #{code}"
elsif( me.is_a? ObjectConstant )
clazz = me.clazz
method = clazz.get_instance_method code.name
# get the function from my class. easy peasy
method = me.clazz.get_instance_method(code.name)
raise "Method not implemented #{clazz.name}.#{code.name}" unless method
call = FunctionCall.new( method )
block.replace(code , call )
@ -21,7 +22,7 @@ module Virtual
raise "unimplemented #{code}"
end
else
raise "unimplemented #{code.me}"
raise "not constant/ known object for send #{me.inspect}"
end
end
end

View File

@ -15,64 +15,65 @@ module Virtual
NAME = 3
MESSAGE_PAYLOAD = 4
attr_accessor :index , :type
attr_accessor :index , :type , :value
private #abstract base class
def initialize index , type
def initialize index , type , value
@index = index
@type = type
@value = value
end
end
class MessageSlot < Slot
def initialize index , type = Mystery
super(index + MESSAGE_PAYLOAD ,type)
def initialize index , type = Mystery , value = nil
super(index + MESSAGE_PAYLOAD ,type , value )
end
end
class FrameSlot < Slot
def initialize index , type = Mystery
def initialize index , type = Mystery, value = nil
super
end
end
class SelfSlot < Slot
def initialize index , type = Mystery
def initialize index , type = Mystery, value = nil
super
end
end
class NewMessageSlot < Slot
def initialize index , type = Mystery
super(index + MESSAGE_PAYLOAD , type)
def initialize index , type = Mystery, value = nil
super(index + MESSAGE_PAYLOAD , type , value )
end
end
class Return < MessageSlot
def initialize type = Mystery
super( RETURN - MESSAGE_PAYLOAD, type )
def initialize type = Mystery, value = nil
super( RETURN - MESSAGE_PAYLOAD, type , value )
end
end
class Self < MessageSlot
def initialize type = Mystery
super( SELF - MESSAGE_PAYLOAD , type )
def initialize type = Mystery, value = nil
super( SELF - MESSAGE_PAYLOAD , type , value )
end
end
class Name < MessageSlot
def initialize type = Mystery
super( NAME - MESSAGE_PAYLOAD , type )
def initialize type = Mystery, value = nil
super( NAME - MESSAGE_PAYLOAD , type , value )
end
end
class NewReturn < NewMessageSlot
def initialize type = Mystery
super( RETURN - MESSAGE_PAYLOAD, type )
def initialize type = Mystery, value = nil
super( RETURN - MESSAGE_PAYLOAD, type , value )
end
end
class NewSelf < NewMessageSlot
def initialize type = Mystery
super( SELF - MESSAGE_PAYLOAD , type )
def initialize type = Mystery, value = nil
super( SELF - MESSAGE_PAYLOAD , type , value )
end
end
class NewName < NewMessageSlot
def initialize type = Mystery
super( NAME - MESSAGE_PAYLOAD , type )
def initialize type = Mystery, value = nil
super( NAME - MESSAGE_PAYLOAD , type , value )
end
end