more work on send
This commit is contained in:
parent
5b1e86da49
commit
b305a56576
@ -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 = []
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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 = <<HERE
|
||||
def foo(x)
|
||||
5
|
||||
|
Loading…
Reference in New Issue
Block a user