2019-08-06 17:33:27 +02:00
|
|
|
module Mom
|
|
|
|
# The Compiler/Collection for the Mom level is a collection of Mom level Method
|
|
|
|
# compilers These will transform to Risc MethodCompilers on the way down.
|
|
|
|
#
|
|
|
|
# As RubyCompiler pools source at the vool level, when several classes are compiled
|
|
|
|
# from vool to mom, several MomCompilers get instantiated. They must be merged before
|
|
|
|
# proceeding with translate. Thus we have a append method.
|
|
|
|
#
|
|
|
|
class MomCollection
|
|
|
|
attr_reader :method_compilers
|
|
|
|
|
|
|
|
# Initialize with an array of risc MethodCompilers
|
|
|
|
def initialize(compilers = [])
|
|
|
|
@method_compilers = compilers
|
|
|
|
end
|
|
|
|
|
|
|
|
# lazily instantiate the compilers for boot functions
|
|
|
|
# (in the hope of only booting the functions once)
|
|
|
|
def boot_compilers
|
2019-08-12 15:12:17 +02:00
|
|
|
@boot_compilers ||= Mom::Builtin.boot_functions
|
2019-08-06 17:33:27 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
# Return all compilers, namely the MethodCompilers passed in, plus the
|
|
|
|
# boot_function's compilers (boot_compilers)
|
|
|
|
def compilers
|
2019-08-12 15:12:17 +02:00
|
|
|
@method_compilers + boot_compilers
|
2019-08-06 17:33:27 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
# Append another MomCompilers method_compilers to this one.
|
|
|
|
def append(mom_compiler)
|
|
|
|
@method_compilers += mom_compiler.method_compilers
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
2019-08-12 15:12:17 +02:00
|
|
|
def to_risc( )
|
|
|
|
riscs = compilers.collect do | mom_c |
|
2019-08-10 20:30:00 +02:00
|
|
|
mom_c.to_risc
|
|
|
|
end
|
2019-08-08 11:19:27 +02:00
|
|
|
# to_risc all compilers
|
|
|
|
# for each suffling constnts and fist label, then all instructions (see below)
|
|
|
|
# then create risc collection
|
|
|
|
Risc::RiscCollection.new(riscs)
|
|
|
|
end
|
|
|
|
|
2019-08-06 17:33:27 +02:00
|
|
|
|
|
|
|
end
|
|
|
|
end
|