diff --git a/lib/ast/function_expression.rb b/lib/ast/function_expression.rb index a0724e62..8c5d9348 100644 --- a/lib/ast/function_expression.rb +++ b/lib/ast/function_expression.rb @@ -7,15 +7,19 @@ module Ast p.name end r = receiver ? receiver.compile(method,message) : Virtual::Self.new() - method = Virtual::MethodDefinition.new(name , args , r ) + new_method = Virtual::MethodDefinition.new(name , args , r ) + new_method.class_name = r.is_a?(Boot::BootClass) ? r.name : method.class_name + clazz = Virtual::Object.space.get_or_create_class(new_method.class_name) + clazz.add_method_definition new_method + #frame = frame.new_frame return_type = nil body.each do |ex| - return_type = ex.compile(method,message ) + return_type = ex.compile(new_method,message ) raise return_type.inspect if return_type.is_a? Virtual::Instruction end - method.return_type = return_type - method + new_method.return_type = return_type + new_method end def scratch args = [] diff --git a/lib/boot/boot_class.rb b/lib/boot/boot_class.rb index fd793794..574eb1a6 100644 --- a/lib/boot/boot_class.rb +++ b/lib/boot/boot_class.rb @@ -12,7 +12,7 @@ module Boot @super_class_name = super_class_name.to_sym @meta_class = MetaClass.new(self) end - attr_reader :name , :methods , :meta_class , :context , :super_class_name + attr_reader :name , :method_definitions , :meta_class , :context , :super_class_name def add_method_definition method raise "not a method #{method.class} #{method.inspect}" unless method.is_a? Virtual::MethodDefinition raise "syserr " unless method.name.is_a? Symbol diff --git a/lib/boot/boot_space.rb b/lib/boot/boot_space.rb index 8ea108e0..fe64be33 100644 --- a/lib/boot/boot_space.rb +++ b/lib/boot/boot_space.rb @@ -3,7 +3,7 @@ require "boot/boot_class" require "kernel/all" require "boot/object" require "boot/string" - +require "trickle/send" module Boot # The BootSpace contains all objects for a program. In functional terms it is a program, but in oo # it is a collection of objects, some of which are data, some classes, some functions @@ -25,7 +25,7 @@ module Boot #global objects (data) @objects = [] boot_classes - @passes = [ ] + @passes = [ Trickle::Send ] end attr_reader :context , :main , :classes , :entry , :exit @@ -33,10 +33,10 @@ module Boot @passes.each do |pass| all = main.blocks @classes.each_value do |c| - c.functions.each {|f| all += f.blocks } + c.method_definitions.each {|f| all += f.blocks } end all.each do |block| - pass.run(block) + pass.new.run(block) end end end diff --git a/lib/trickle/send.rb b/lib/trickle/send.rb index d69dd644..3cae71e5 100644 --- a/lib/trickle/send.rb +++ b/lib/trickle/send.rb @@ -5,9 +5,9 @@ module Trickle class Send def run block block.codes.dup.each do |code| - next unless code.is_a? MessageSend + next unless code.is_a? Virtual::MessageSend + puts "Found me a send #{code.me.type}" if( code.me.type == Virtual::Reference) - next end end diff --git a/lib/virtual/method_definition.rb b/lib/virtual/method_definition.rb index fe57d1cb..9c67110d 100644 --- a/lib/virtual/method_definition.rb +++ b/lib/virtual/method_definition.rb @@ -34,8 +34,9 @@ module Virtual def MethodDefinition.main MethodDefinition.new(:main , [] ) end - def initialize name , args , receiver = Virtual::Self.new , return_type = Virtual::Mystery , start = MethodEnter.new() + def initialize name , args , receiver = Virtual::Self.new , return_type = Virtual::Mystery @name = name.to_sym + @class_name = :Object @args = args @locals = [] @tmps = [] @@ -43,13 +44,13 @@ module Virtual @return_type = return_type @blocks = [] # first block we have to create with .new , as new_block assumes a current - enter = Block.new( name , self ).add_code(start) + enter = Block.new( name , self ).add_code(MethodEnter.new()) @blocks << enter @current = enter new_block("return").add_code(MethodReturn.new) end attr_reader :name , :args , :receiver , :blocks - attr_accessor :return_type , :current + attr_accessor :return_type , :current , :class_name # add an instruction after the current (insertion point) # the added instruction will become the new insertion point diff --git a/test/virtual/hello.rb b/test/virtual/hello.rb index e3bc3f13..f41e21a9 100644 --- a/test/virtual/hello.rb +++ b/test/virtual/hello.rb @@ -10,10 +10,10 @@ class HelloTest < MiniTest::Test puts Sof::Writer.write(expressions) Virtual::Object.space.run_passes puts "" - puts Sof::Writer.write(expressions) +# puts Sof::Writer.write(Virtual::Object.space) end - def test_simplest_function + def qtest_simplest_function @string_input = <