compile from mom compiler to risc
This commit is contained in:
@ -33,9 +33,9 @@ module Mom
|
||||
end
|
||||
|
||||
# generate the risc label lazily
|
||||
def risc_label(comiler)
|
||||
def risc_label(compiler)
|
||||
@risc_label ||= Risc.label(self,name)
|
||||
comiler.add_constant(@risc_label.address)
|
||||
compiler.add_constant(@risc_label.address)
|
||||
@risc_label
|
||||
end
|
||||
|
||||
|
@ -27,6 +27,21 @@ module Mom
|
||||
@callable
|
||||
end
|
||||
|
||||
# drop down to risc
|
||||
def to_risc
|
||||
risc_comp = Risc::MethodCompiler.new(@callable , mom_instructions)
|
||||
instruction = mom_instructions.next
|
||||
while( instruction )
|
||||
raise "whats this a #{instruction}" unless instruction.is_a?(Mom::Instruction)
|
||||
#puts "adding mom #{instruction.to_s}:#{instruction.next.to_s}"
|
||||
instruction.to_risc( risc_comp )
|
||||
risc_comp.reset_regs
|
||||
#puts "adding risc #{risc.to_s}:#{risc.next.to_s}"
|
||||
instruction = instruction.next
|
||||
end
|
||||
risc_comp
|
||||
end
|
||||
|
||||
# helper method for builtin mainly
|
||||
# the class_name is a symbol, which is resolved to the instance_type of that class
|
||||
#
|
||||
|
@ -45,19 +45,6 @@ module Mom
|
||||
Risc::RiscCollection.new(riscs)
|
||||
end
|
||||
|
||||
# convert the given mom instruction to_risc and then add it (see add_code)
|
||||
# continue down the instruction chain unti depleted
|
||||
# (adding moves the insertion point so the whole mom chain is added as a risc chain)
|
||||
def add_mom( instruction )
|
||||
while( instruction )
|
||||
raise "whats this a #{instruction}" unless instruction.is_a?(Mom::Instruction)
|
||||
#puts "adding mom #{instruction.to_s}:#{instruction.next.to_s}"
|
||||
instruction.to_risc( self )
|
||||
reset_regs
|
||||
#puts "adding risc #{risc.to_s}:#{risc.next.to_s}"
|
||||
instruction = instruction.next
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
@ -11,14 +11,14 @@ module Risc
|
||||
#
|
||||
class CallableCompiler
|
||||
|
||||
# Must pass the callable (method/block) and the constants that were parsed
|
||||
# Must pass the callable (method/block)
|
||||
# Also start instuction, usually a label is mandatory
|
||||
def initialize( callable , constants , start)
|
||||
def initialize( callable , mom_label)
|
||||
@callable = callable
|
||||
@regs = []
|
||||
@constants = constants
|
||||
@constants = []
|
||||
@block_compilers = []
|
||||
@current = @risc_instructions = start
|
||||
@current = @risc_instructions = mom_label.risc_label(self)
|
||||
reset_regs
|
||||
end
|
||||
attr_reader :risc_instructions , :constants , :block_compilers , :callable , :current
|
||||
|
@ -5,8 +5,10 @@ module Risc
|
||||
|
||||
class MethodCompiler < CallableCompiler
|
||||
|
||||
def initialize( method )
|
||||
super(method)
|
||||
# Methods starts with a Label, both in risc and mom.
|
||||
# Pass in the callable(method) and the mom label that the method starts with
|
||||
def initialize( method , mom_label)
|
||||
super(method , mom_label)
|
||||
end
|
||||
|
||||
#include block_compilers constants
|
||||
|
Reference in New Issue
Block a user