make mom:method_compiler a list
Compilers forms alist by Util::CompilerList Change Collection to use the list instead of array
This commit is contained in:
@ -4,7 +4,8 @@ module Mom
|
||||
# and to instantiate the methods correctly.
|
||||
|
||||
class MethodCompiler < CallableCompiler
|
||||
|
||||
include Util::CompilerList
|
||||
|
||||
def initialize( method )
|
||||
super(method)
|
||||
end
|
||||
|
@ -11,32 +11,46 @@ module Mom
|
||||
|
||||
# Initialize with an array of risc MethodCompilers
|
||||
def initialize(compilers = [])
|
||||
@method_compilers = compilers
|
||||
@method_compilers = nil
|
||||
compilers.each{|c| add_compiler(c)}
|
||||
end
|
||||
|
||||
# lazily instantiate the compiler for __init__ function and __method_missing__
|
||||
def init_compiler
|
||||
@init_compilers ||= [
|
||||
MomCollection.create_init_compiler ,
|
||||
MomCollection.create_mm_compiler ,
|
||||
]
|
||||
def init_compilers
|
||||
return if @init_compilers
|
||||
@init_compilers = true
|
||||
add_compiler MomCollection.create_init_compiler
|
||||
add_compiler MomCollection.create_mm_compiler
|
||||
self
|
||||
end
|
||||
|
||||
# Return all compilers, namely the MethodCompilers passed in, plus the
|
||||
# boot_function's compilers (boot_compilers)
|
||||
def compilers
|
||||
@method_compilers + init_compiler
|
||||
init_compilers
|
||||
@method_compilers
|
||||
end
|
||||
|
||||
def add_compiler(compiler)
|
||||
if(@method_compilers)
|
||||
@method_compilers.add_method_compiler(compiler)
|
||||
else
|
||||
@method_compilers = compiler
|
||||
end
|
||||
self
|
||||
end
|
||||
|
||||
# Append another MomCompilers method_compilers to this one.
|
||||
def append(mom_compiler)
|
||||
@method_compilers += mom_compiler.method_compilers
|
||||
def append(collection)
|
||||
@method_compilers.add_method_compiler( collection.method_compilers)
|
||||
self
|
||||
end
|
||||
|
||||
def to_risc( )
|
||||
riscs = compilers.collect do | mom_c |
|
||||
mom_c.to_risc
|
||||
init_compilers
|
||||
riscs =[]
|
||||
@method_compilers.each_compiler do | mom_c |
|
||||
riscs << mom_c.to_risc
|
||||
end
|
||||
# to_risc all compilers
|
||||
# for each suffling constnts and fist label, then all instructions (see below)
|
||||
|
@ -5,7 +5,7 @@ module Util
|
||||
attr_reader :next_compiler
|
||||
|
||||
def add_method_compiler(comp)
|
||||
raise "not compiler #{comp.class}" unless comp.is_a?(MethodCompiler)
|
||||
raise "not compiler #{comp.class}" unless comp.respond_to?(:find_compiler)
|
||||
if(@next_compiler)
|
||||
@next_compiler.add_method_compiler(comp)
|
||||
else
|
||||
@ -15,7 +15,7 @@ module Util
|
||||
|
||||
def each_compiler &block
|
||||
block.yield(self)
|
||||
@next_compiler.each(&block) if @next_compiler
|
||||
@next_compiler.each_compiler(&block) if @next_compiler
|
||||
end
|
||||
|
||||
def find_compiler &block
|
||||
|
Reference in New Issue
Block a user