From c92b165a3f474f84b62f88332fb326fb90075815 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Mon, 15 Sep 2014 12:08:37 +0300 Subject: [PATCH] carry constants through in reference slots. resolve functions with it --- lib/ast/basic_expressions.rb | 24 +++++++++-------- lib/virtual/send_implementation.rb | 13 +++++----- lib/virtual/slot.rb | 41 +++++++++++++++--------------- 3 files changed, 42 insertions(+), 36 deletions(-) diff --git a/lib/ast/basic_expressions.rb b/lib/ast/basic_expressions.rb index e7c52806..c0e58080 100644 --- a/lib/ast/basic_expressions.rb +++ b/lib/ast/basic_expressions.rb @@ -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 diff --git a/lib/virtual/send_implementation.rb b/lib/virtual/send_implementation.rb index 83941b62..e75d1959 100644 --- a/lib/virtual/send_implementation.rb +++ b/lib/virtual/send_implementation.rb @@ -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 diff --git a/lib/virtual/slot.rb b/lib/virtual/slot.rb index a7ea2c1b..f22393be 100644 --- a/lib/virtual/slot.rb +++ b/lib/virtual/slot.rb @@ -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