add branches to builder
This commit is contained in:
parent
695ae5ad99
commit
5d4b9d4834
@ -32,6 +32,16 @@ module Risc
|
|||||||
reg
|
reg
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def if_zero( label )
|
||||||
|
add Risc::IsZero.new("jump if zero" , label)
|
||||||
|
end
|
||||||
|
def if_not_zero( label )
|
||||||
|
add Risc::IsNotZero.new("jump if not zero" , label)
|
||||||
|
end
|
||||||
|
def branch( label )
|
||||||
|
add Risc::Branch.new("jump to" , label)
|
||||||
|
end
|
||||||
|
|
||||||
# build code using dsl (see __init__ or MessageSetup for examples)
|
# build code using dsl (see __init__ or MessageSetup for examples)
|
||||||
# names (that ruby would resolve to a variable/method) are converted
|
# names (that ruby would resolve to a variable/method) are converted
|
||||||
# to registers. << means assignment and [] is supported both on
|
# to registers. << means assignment and [] is supported both on
|
||||||
|
@ -70,11 +70,11 @@ module Risc
|
|||||||
space << space[:nil_object]
|
space << space[:nil_object]
|
||||||
|
|
||||||
add Risc.op(source + "if method is nil", :- , space , typed_method )
|
add Risc.op(source + "if method is nil", :- , space , typed_method )
|
||||||
add Risc::IsZero.new(source + "jump if nil" , exit_label)
|
if_zero exit_label
|
||||||
|
|
||||||
name << typed_method[:name]
|
name << typed_method[:name]
|
||||||
add Risc.op(source + " compare name with me", :- , name , word )
|
add Risc.op(source + " compare name with me", :- , name , word )
|
||||||
add Risc::IsNotZero.new(source + "jump if not same" , false_label)
|
if_not_zero false_label
|
||||||
|
|
||||||
typed_method << typed_method[:binary]
|
typed_method << typed_method[:binary]
|
||||||
message[:return_value] << typed_method
|
message[:return_value] << typed_method
|
||||||
@ -83,7 +83,7 @@ module Risc
|
|||||||
|
|
||||||
add false_label
|
add false_label
|
||||||
typed_method << typed_method[:next_method]
|
typed_method << typed_method[:next_method]
|
||||||
add Risc::Branch.new(source + "back to while", while_start_label)
|
branch while_start_label
|
||||||
|
|
||||||
add exit_label
|
add exit_label
|
||||||
end
|
end
|
||||||
|
@ -6,6 +6,7 @@ module Risc
|
|||||||
def setup
|
def setup
|
||||||
Risc.machine.boot
|
Risc.machine.boot
|
||||||
init = Parfait.object_space.get_init
|
init = Parfait.object_space.get_init
|
||||||
|
@label = Risc::Label.new("source","name")
|
||||||
@builder = Risc::MethodCompiler.new( init ).builder
|
@builder = Risc::MethodCompiler.new( init ).builder
|
||||||
end
|
end
|
||||||
def test_has_build
|
def test_has_build
|
||||||
@ -74,5 +75,20 @@ module Risc
|
|||||||
label2 = @builder.exit_label
|
label2 = @builder.exit_label
|
||||||
assert_equal label1 , label2
|
assert_equal label1 , label2
|
||||||
end
|
end
|
||||||
|
def test_if_zero
|
||||||
|
ret = @builder.if_zero @label
|
||||||
|
assert_equal IsZero , ret.class
|
||||||
|
assert_equal @label , ret.label
|
||||||
|
end
|
||||||
|
def test_if_not_zero
|
||||||
|
ret = @builder.if_not_zero @label
|
||||||
|
assert_equal IsNotZero , ret.class
|
||||||
|
assert_equal @label , ret.label
|
||||||
|
end
|
||||||
|
def test_branch
|
||||||
|
ret = @builder.branch @label
|
||||||
|
assert_equal Branch , ret.class
|
||||||
|
assert_equal @label , ret.label
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user