add the addresses from labels as constants
This commit is contained in:
parent
ea7f3c9653
commit
dc12c1d70b
@ -12,7 +12,7 @@ module Mom
|
||||
@label = label
|
||||
end
|
||||
def to_risc(compiler)
|
||||
compiler.add_code Risc::Branch.new(self , @label.risc_label)
|
||||
compiler.add_code Risc::Branch.new(self , @label.risc_label(compiler))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -32,19 +32,16 @@ module Mom
|
||||
end
|
||||
|
||||
# generate the risc label lazily
|
||||
def risc_label
|
||||
def risc_label(comiler)
|
||||
@risc_label ||= Risc.label(self,name)
|
||||
comiler.add_constant(@risc_label.address)
|
||||
@risc_label
|
||||
end
|
||||
|
||||
# add the risc_label to the compiler (instruction flow)
|
||||
# should only be called once
|
||||
def to_risc(compiler)
|
||||
if( @added )
|
||||
raise "added already #{@added}"
|
||||
else
|
||||
@added = true
|
||||
compiler.add_code( risc_label )
|
||||
end
|
||||
compiler.add_code( risc_label(compiler) )
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -26,7 +26,7 @@ module Mom
|
||||
l_reg = left.to_register(compiler, self)
|
||||
r_reg = right.to_register(compiler, self)
|
||||
compiler.add_code Risc.op( self , :- , l_reg , r_reg)
|
||||
compiler.add_code Risc::IsZero.new( self, false_jump.risc_label)
|
||||
compiler.add_code Risc::IsZero.new( self, false_jump.risc_label(compiler))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -19,7 +19,7 @@ module Mom
|
||||
end
|
||||
|
||||
def to_risc(compiler)
|
||||
false_label = @false_jump.risc_label
|
||||
false_label = @false_jump.risc_label(compiler)
|
||||
builder = compiler.builder("TruthCheck")
|
||||
condition_reg = @condition.to_register(compiler,self)
|
||||
builder.build do
|
||||
|
@ -134,8 +134,14 @@ module Risc
|
||||
# - an RValue, resulting in an SlotToReg
|
||||
def <<( right )
|
||||
case right
|
||||
when Parfait::Object , Symbol , Label
|
||||
when Symbol
|
||||
ins = Risc.load_constant("#{right.class} to #{self.type}" , right , self)
|
||||
when Parfait::Object
|
||||
ins = Risc.load_constant("#{right.class} to #{self.type}" , right , self)
|
||||
builder.compiler.add_constant(right) if builder
|
||||
when Label
|
||||
ins = Risc.load_constant("#{right.class} to #{self.type}" , right , self)
|
||||
builder.compiler.add_constant(right.address) if builder
|
||||
when Fixnum
|
||||
ins = Risc.load_data("#{right.class} to #{self.type}" , right , self)
|
||||
when RegisterValue
|
||||
|
@ -22,7 +22,7 @@ module Mom
|
||||
assert_equal Array , @comp.constants.class
|
||||
end
|
||||
def test_has_constant
|
||||
assert_equal "Hi" , @comp.constants.first.to_string
|
||||
assert_equal "Hi" , @comp.constants[1].to_string
|
||||
end
|
||||
def test_has_translate
|
||||
assert @comp.translate(:interpreter)
|
||||
|
Loading…
Reference in New Issue
Block a user