more work on send

This commit is contained in:
Torsten Ruger 2014-08-22 09:21:59 +03:00
parent 5b1e86da49
commit b305a56576
6 changed files with 21 additions and 16 deletions

View File

@ -7,15 +7,19 @@ module Ast
p.name p.name
end end
r = receiver ? receiver.compile(method,message) : Virtual::Self.new() 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 #frame = frame.new_frame
return_type = nil return_type = nil
body.each do |ex| 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 raise return_type.inspect if return_type.is_a? Virtual::Instruction
end end
method.return_type = return_type new_method.return_type = return_type
method new_method
end end
def scratch def scratch
args = [] args = []

View File

@ -12,7 +12,7 @@ module Boot
@super_class_name = super_class_name.to_sym @super_class_name = super_class_name.to_sym
@meta_class = MetaClass.new(self) @meta_class = MetaClass.new(self)
end 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 def add_method_definition method
raise "not a method #{method.class} #{method.inspect}" unless method.is_a? Virtual::MethodDefinition raise "not a method #{method.class} #{method.inspect}" unless method.is_a? Virtual::MethodDefinition
raise "syserr " unless method.name.is_a? Symbol raise "syserr " unless method.name.is_a? Symbol

View File

@ -3,7 +3,7 @@ require "boot/boot_class"
require "kernel/all" require "kernel/all"
require "boot/object" require "boot/object"
require "boot/string" require "boot/string"
require "trickle/send"
module Boot module Boot
# The BootSpace contains all objects for a program. In functional terms it is a program, but in oo # 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 # it is a collection of objects, some of which are data, some classes, some functions
@ -25,7 +25,7 @@ module Boot
#global objects (data) #global objects (data)
@objects = [] @objects = []
boot_classes boot_classes
@passes = [ ] @passes = [ Trickle::Send ]
end end
attr_reader :context , :main , :classes , :entry , :exit attr_reader :context , :main , :classes , :entry , :exit
@ -33,10 +33,10 @@ module Boot
@passes.each do |pass| @passes.each do |pass|
all = main.blocks all = main.blocks
@classes.each_value do |c| @classes.each_value do |c|
c.functions.each {|f| all += f.blocks } c.method_definitions.each {|f| all += f.blocks }
end end
all.each do |block| all.each do |block|
pass.run(block) pass.new.run(block)
end end
end end
end end

View File

@ -5,9 +5,9 @@ module Trickle
class Send class Send
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? Virtual::MessageSend
puts "Found me a send #{code.me.type}"
if( code.me.type == Virtual::Reference) if( code.me.type == Virtual::Reference)
next next
end end
end end

View File

@ -34,8 +34,9 @@ module Virtual
def MethodDefinition.main def MethodDefinition.main
MethodDefinition.new(:main , [] ) MethodDefinition.new(:main , [] )
end 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 @name = name.to_sym
@class_name = :Object
@args = args @args = args
@locals = [] @locals = []
@tmps = [] @tmps = []
@ -43,13 +44,13 @@ module Virtual
@return_type = return_type @return_type = return_type
@blocks = [] @blocks = []
# first block we have to create with .new , as new_block assumes a current # 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 @blocks << enter
@current = enter @current = enter
new_block("return").add_code(MethodReturn.new) new_block("return").add_code(MethodReturn.new)
end end
attr_reader :name , :args , :receiver , :blocks 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) # add an instruction after the current (insertion point)
# the added instruction will become the new insertion point # the added instruction will become the new insertion point

View File

@ -10,10 +10,10 @@ class HelloTest < MiniTest::Test
puts Sof::Writer.write(expressions) puts Sof::Writer.write(expressions)
Virtual::Object.space.run_passes Virtual::Object.space.run_passes
puts "" puts ""
puts Sof::Writer.write(expressions) # puts Sof::Writer.write(Virtual::Object.space)
end end
def test_simplest_function def qtest_simplest_function
@string_input = <<HERE @string_input = <<HERE
def foo(x) def foo(x)
5 5