move the send to send_implementation, functions to add passes

This commit is contained in:
Torsten Ruger 2014-08-23 10:25:55 +03:00
parent 4783e6c326
commit 0fcb1c8f68
2 changed files with 34 additions and 13 deletions

View File

@ -1,9 +1,10 @@
require "boot/boot_class" require_relative "boot_class"
#require "vm/call_site" #require "vm/call_site"
require "kernel/all" require "kernel/all"
require "boot/object" require_relative "object"
require "boot/string" require_relative "string"
require "trickle/send" require "virtual/send_implementation"
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,9 +26,9 @@ module Boot
#global objects (data) #global objects (data)
@objects = [] @objects = []
boot_classes boot_classes
@passes = [ Trickle::Send ] @passes = [ Virtual::SendImplementation ]
end end
attr_reader :context , :main , :classes , :entry , :exit attr_reader :main , :classes , :objects
def run_passes def run_passes
@passes.each do |pass| @passes.each do |pass|
@ -41,6 +42,26 @@ module Boot
end end
end end
# Passes are initiated empty and added to by anyone who want (basically)
# Even linking and assembly are passes and so there are quite a few system passes neccesary to result in a
# working binary. Other than that, this is intentionally quite flexible
def add_pass_after( pass , after)
index = @passes.index(after)
raise "No such pass to add after: #{after}" unless index
@passes.insert(index+1 , pass)
end
def add_pass_before( pass , after)
index = @passes.index(after)
raise "No such pass to add after: #{after}" unless index
@passes.insert(index , pass)
end
def add_pass_after( pass , after)
index = @passes.index(after)
raise "No such pass to add after: #{after}" unless index
@passes.insert(index , pass)
end
# boot the classes, ie create a minimal set of classes with a minimal set of functions # boot the classes, ie create a minimal set of classes with a minimal set of functions
# minimal means only that which can not be coded in ruby # minimal means only that which can not be coded in ruby
# MethodDefinitions are grabbed from respective modules by sending the method name. This should return the # MethodDefinitions are grabbed from respective modules by sending the method name. This should return the

View File

@ -1,22 +1,22 @@
module Trickle module Virtual
# This implements the send logic # This implements the send logic
# Send is so complicated that we actually code it in ruby and stick it in # 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 # That off course opens up an endless loop possibility that we stop by reducing to Class and Module methods
class Send class SendImplementation
def run block def run block
block.codes.dup.each do |code| block.codes.dup.each do |code|
next unless code.is_a? Virtual::MessageSend next unless code.is_a? MessageSend
me = code.me me = code.me
next unless ( me.type == Virtual::Reference) next unless ( me.type == Reference)
if( me.is_a? Virtual::Constant) if( me.is_a? Constant)
Boot::BootClass Boot::BootClass
if( me.is_a? Boot::BootClass ) if( me.is_a? Boot::BootClass )
raise "unimplemented" raise "unimplemented"
elsif( me.is_a? Virtual::ObjectConstant ) elsif( me.is_a? ObjectConstant )
clazz = me.clazz clazz = me.clazz
method = clazz.get_method_definition code.name method = clazz.get_method_definition code.name
raise "Method not implemented #{clazz.name}.#{code.name}" unless method raise "Method not implemented #{clazz.name}.#{code.name}" unless method
call = Virtual::FunctionCall.new( method ) call = FunctionCall.new( method )
block.replace(code , [call] ) block.replace(code , [call] )
else else
raise "unimplemented" raise "unimplemented"