Remove separate block_compiler lists

both in mom and risc method complers
alll just compilers now, all linked
Required to move some code down into callable_compiler but all in all quite little. cleaner
This commit is contained in:
2019-09-28 17:24:10 +03:00
parent dcbc3e17be
commit 1e5073200c
9 changed files with 25 additions and 42 deletions

View File

@ -1,6 +1,7 @@
module Risc
# A BlockCompiler is much like a Mehtodcompiler, exept for blocks
# A BlockCompiler is much like a MethodCompiler, exept for it's for blocks
# This only changes scoping for variables, lsee slot_type
#
class BlockCompiler < CallableCompiler

View File

@ -10,6 +10,7 @@ module Risc
# - current instruction is where addidion happens
#
class CallableCompiler
include Util::CompilerList
# Must pass the callable (method/block)
# Also start instuction, usually a label is mandatory
@ -18,11 +19,10 @@ module Risc
@callable = callable
@regs = []
@constants = []
@block_compilers = []
@current = @risc_instructions = mom_label.risc_label(self)
reset_regs
end
attr_reader :risc_instructions , :constants , :block_compilers , :callable , :current
attr_reader :risc_instructions , :constants , :callable , :current
def return_label
@risc_instructions.each do |ins|
@ -138,5 +138,12 @@ module Risc
Risc::Assembler.new(@callable , cpu_instructions )
end
# translate this method, which means the method itself and all blocks inside it
# returns the array (of assemblers) that you pass in as collection
def translate_method( translator , collection)
collection << translate_cpu( translator )
collection
end
end
end

View File

@ -4,7 +4,6 @@ module Risc
# and to instantiate the methods correctly.
class MethodCompiler < CallableCompiler
include Util::CompilerList
# Methods starts with a Label, both in risc and mom.
# Pass in the callable(method) and the mom label that the method starts with
@ -12,11 +11,6 @@ module Risc
super(method , mom_label)
end
#include block_compilers constants
def constants
block_compilers.inject(@constants.dup){|all, compiler| all += compiler.constants}
end
def source_name
"#{@callable.self_type.name}.#{@callable.name}"
end
@ -26,18 +20,5 @@ module Risc
@callable
end
def add_block_compiler(compiler)
@block_compilers << compiler
end
# translate this method, which means the method itself and all blocks inside it
# returns the array (of assemblers) that you pass in as collection
def translate_method( translator , collection)
collection << translate_cpu( translator )
@block_compilers.each do |block_compiler|
collection << block_compiler.translate_cpu(translator)
end
collection
end
end
end