diff --git a/lib/ast/basic_expressions.rb b/lib/ast/basic_expressions.rb index c8b6a2c4..596243a9 100644 --- a/lib/ast/basic_expressions.rb +++ b/lib/ast/basic_expressions.rb @@ -98,7 +98,7 @@ module Ast class VariableExpression < NameExpression def compile method , message - method.add_code Virtual::ObjectGet.new(name) + method.add_code Virtual::InstanceGet.new(name) Virtual::Return.new( Virtual::Mystery ) end end diff --git a/lib/boot/boot_space.rb b/lib/boot/boot_space.rb index e1f00356..b6102b4f 100644 --- a/lib/boot/boot_space.rb +++ b/lib/boot/boot_space.rb @@ -3,7 +3,6 @@ require_relative "boot_class" require "kernel/all" require_relative "object" require_relative "string" -require "virtual/send_implementation" module Boot # The BootSpace contains all objects for a program. In functional terms it is a program, but in oo diff --git a/lib/virtual/get_implementation.rb b/lib/virtual/get_implementation.rb new file mode 100644 index 00000000..26a2f01a --- /dev/null +++ b/lib/virtual/get_implementation.rb @@ -0,0 +1,14 @@ +module Virtual + # This implements the send logic + # Send is so complicated that we actually code it in ruby and stick it in + # That off course opens up an endless loop possibility that we stop by reducing to Class and Module methods + class GetImplementation + def run block + block.codes.dup.each do |code| + next unless code.is_a? InstanceGet + raise "Start coding" + end + end + end + Object.space.add_pass_after GetImplementation, SendImplementation +end diff --git a/lib/virtual/instruction.rb b/lib/virtual/instruction.rb index 404adf53..26d28a04 100644 --- a/lib/virtual/instruction.rb +++ b/lib/virtual/instruction.rb @@ -83,7 +83,9 @@ module Virtual end # class for Set instructions, A set is basically a mem move. - # to and from are indexes into the known objects(frame,message,self and new_message), or from may be a constant + # to and from are indexes into the known objects(frame,message,self and new_message), these are represented as slots + # (see there) + # from may be a Constant (Object,Integer,String,Class) class Set < Instruction def initialize to , from @to = to @@ -91,8 +93,10 @@ module Virtual end attr_reader :to , :from end - - class ObjectGet < Instruction + + # Get a instance variable by _name_ . So we have to resolve the name to an index to trnsform into a Slot + # The slot may the be used in a set on left or right hand. The transformation is done by GetImplementation + class InstanceGet < Instruction def initialize name @name = name.to_sym end diff --git a/lib/virtual/machine.rb b/lib/virtual/machine.rb index 442d8241..c8a4fd06 100644 --- a/lib/virtual/machine.rb +++ b/lib/virtual/machine.rb @@ -83,4 +83,6 @@ require_relative "value" require_relative "type" require_relative "object" require_relative "constants" -require "boot/boot_space" \ No newline at end of file +require "boot/boot_space" +require_relative "send_implementation" +require_relative "get_implementation" diff --git a/lib/virtual/send_implementation.rb b/lib/virtual/send_implementation.rb index 124e19d5..129877d3 100644 --- a/lib/virtual/send_implementation.rb +++ b/lib/virtual/send_implementation.rb @@ -26,3 +26,4 @@ module Virtual end end end +require_relative "get_implementation" \ No newline at end of file diff --git a/test/virtual/test_methods.rb b/test/virtual/test_methods.rb index 073ee9d5..0b2a95c3 100644 --- a/test/virtual/test_methods.rb +++ b/test/virtual/test_methods.rb @@ -30,7 +30,7 @@ def String.length(x) @length end HERE - @output = "---RETURN_MARKER- &7 !ruby/object:Virtual::MethodDefinitionRETURN_MARKER name: :lengthRETURN_MARKER args:RETURN_MARKER - :xRETURN_MARKER locals: []RETURN_MARKER tmps: []RETURN_MARKER receiver: &6 !ruby/object:Boot::BootClassRETURN_MARKER method_definitions:RETURN_MARKER - &2 !ruby/object:Virtual::MethodDefinitionRETURN_MARKER name: :getRETURN_MARKER args:RETURN_MARKER - &1 !ruby/class 'Virtual::Integer'RETURN_MARKER locals: []RETURN_MARKER tmps: []RETURN_MARKER receiver: *1RETURN_MARKER return_type: *1RETURN_MARKER blocks:RETURN_MARKER - &3 !ruby/object:Virtual::BlockRETURN_MARKER method: *2RETURN_MARKER name: :getRETURN_MARKER branch: RETURN_MARKER codes:RETURN_MARKER - !ruby/object:Virtual::MethodEnter {}RETURN_MARKER - !ruby/object:Virtual::BlockRETURN_MARKER method: *2RETURN_MARKER name: :get_returnRETURN_MARKER branch: RETURN_MARKER codes:RETURN_MARKER - !ruby/object:Virtual::MethodReturn {}RETURN_MARKER current: *3RETURN_MARKER - &4 !ruby/object:Virtual::MethodDefinitionRETURN_MARKER name: :setRETURN_MARKER args:RETURN_MARKER - *1RETURN_MARKER - *1RETURN_MARKER locals: []RETURN_MARKER tmps: []RETURN_MARKER receiver: *1RETURN_MARKER return_type: *1RETURN_MARKER blocks:RETURN_MARKER - &5 !ruby/object:Virtual::BlockRETURN_MARKER method: *4RETURN_MARKER name: :setRETURN_MARKER branch: RETURN_MARKER codes:RETURN_MARKER - !ruby/object:Virtual::MethodEnter {}RETURN_MARKER - !ruby/object:Virtual::BlockRETURN_MARKER method: *4RETURN_MARKER name: :set_returnRETURN_MARKER branch: RETURN_MARKER codes:RETURN_MARKER - !ruby/object:Virtual::MethodReturn {}RETURN_MARKER current: *5RETURN_MARKER name: :StringRETURN_MARKER super_class_name: :ObjectRETURN_MARKER meta_class: !ruby/object:Boot::MetaClassRETURN_MARKER functions: []RETURN_MARKER me_self: *6RETURN_MARKER return_type: !ruby/object:Virtual::ReturnRETURN_MARKER index: 0RETURN_MARKER type: !ruby/class 'Virtual::Mystery'RETURN_MARKER blocks:RETURN_MARKER - &8 !ruby/object:Virtual::BlockRETURN_MARKER method: *7RETURN_MARKER name: :lengthRETURN_MARKER branch: RETURN_MARKER codes:RETURN_MARKER - !ruby/object:Virtual::MethodEnter {}RETURN_MARKER - !ruby/object:Virtual::ObjectGetRETURN_MARKER name: :lengthRETURN_MARKER - !ruby/object:Virtual::BlockRETURN_MARKER method: *7RETURN_MARKER name: :length_returnRETURN_MARKER branch: RETURN_MARKER codes:RETURN_MARKER - !ruby/object:Virtual::MethodReturn {}RETURN_MARKER current: *8RETURN_MARKER" + @output = "---RETURN_MARKER- &7 !ruby/object:Virtual::MethodDefinitionRETURN_MARKER name: :lengthRETURN_MARKER args:RETURN_MARKER - :xRETURN_MARKER locals: []RETURN_MARKER tmps: []RETURN_MARKER receiver: &6 !ruby/object:Boot::BootClassRETURN_MARKER method_definitions:RETURN_MARKER - &2 !ruby/object:Virtual::MethodDefinitionRETURN_MARKER name: :getRETURN_MARKER args:RETURN_MARKER - &1 !ruby/class 'Virtual::Integer'RETURN_MARKER locals: []RETURN_MARKER tmps: []RETURN_MARKER receiver: *1RETURN_MARKER return_type: *1RETURN_MARKER blocks:RETURN_MARKER - &3 !ruby/object:Virtual::BlockRETURN_MARKER method: *2RETURN_MARKER name: :getRETURN_MARKER branch: RETURN_MARKER codes:RETURN_MARKER - !ruby/object:Virtual::MethodEnter {}RETURN_MARKER - !ruby/object:Virtual::BlockRETURN_MARKER method: *2RETURN_MARKER name: :get_returnRETURN_MARKER branch: RETURN_MARKER codes:RETURN_MARKER - !ruby/object:Virtual::MethodReturn {}RETURN_MARKER current: *3RETURN_MARKER - &4 !ruby/object:Virtual::MethodDefinitionRETURN_MARKER name: :setRETURN_MARKER args:RETURN_MARKER - *1RETURN_MARKER - *1RETURN_MARKER locals: []RETURN_MARKER tmps: []RETURN_MARKER receiver: *1RETURN_MARKER return_type: *1RETURN_MARKER blocks:RETURN_MARKER - &5 !ruby/object:Virtual::BlockRETURN_MARKER method: *4RETURN_MARKER name: :setRETURN_MARKER branch: RETURN_MARKER codes:RETURN_MARKER - !ruby/object:Virtual::MethodEnter {}RETURN_MARKER - !ruby/object:Virtual::BlockRETURN_MARKER method: *4RETURN_MARKER name: :set_returnRETURN_MARKER branch: RETURN_MARKER codes:RETURN_MARKER - !ruby/object:Virtual::MethodReturn {}RETURN_MARKER current: *5RETURN_MARKER name: :StringRETURN_MARKER super_class_name: :ObjectRETURN_MARKER meta_class: !ruby/object:Boot::MetaClassRETURN_MARKER functions: []RETURN_MARKER me_self: *6RETURN_MARKER return_type: !ruby/object:Virtual::ReturnRETURN_MARKER index: 0RETURN_MARKER type: !ruby/class 'Virtual::Mystery'RETURN_MARKER blocks:RETURN_MARKER - &8 !ruby/object:Virtual::BlockRETURN_MARKER method: *7RETURN_MARKER name: :lengthRETURN_MARKER branch: RETURN_MARKER codes:RETURN_MARKER - !ruby/object:Virtual::MethodEnter {}RETURN_MARKER - !ruby/object:Virtual::InstanceGetRETURN_MARKER name: :lengthRETURN_MARKER - !ruby/object:Virtual::BlockRETURN_MARKER method: *7RETURN_MARKER name: :length_returnRETURN_MARKER branch: RETURN_MARKER codes:RETURN_MARKER - !ruby/object:Virtual::MethodReturn {}RETURN_MARKER current: *8RETURN_MARKER" check end