give labels an integer that will end up being the position at runtime
Since integers are first class objects, we need to use an integer object as the return address. The actual address can not be stored in an instance variable since it is not an object. The address is unique to the label and never changes after positioning (using the int is next up)
This commit is contained in:
@ -7,7 +7,7 @@ module Risc
|
||||
Risc.machine.boot
|
||||
@binary = Parfait::BinaryCode.new(1)
|
||||
@method = Parfait.object_space.types.values.first.methods
|
||||
@label = Label.new("hi","ho")
|
||||
@label = Risc.label("hi","ho")
|
||||
end
|
||||
def test_set_bin
|
||||
pos = Position.set( @binary , 0 , @method)
|
||||
@ -29,7 +29,7 @@ module Risc
|
||||
machine.translate(:interpreter)
|
||||
@binary = Parfait::BinaryCode.new(1)
|
||||
@method = Parfait.object_space.types.values.first.methods
|
||||
@label = Label.new("hi","ho")
|
||||
@label = Risc.label("hi","ho")
|
||||
end
|
||||
|
||||
def test_bin_propagates_existing
|
||||
|
@ -8,7 +8,7 @@ module Risc
|
||||
Risc.machine.boot
|
||||
@binary = Parfait::BinaryCode.new(1)
|
||||
Position.set(@binary , 0 , Parfait.object_space.get_main)
|
||||
@label = Label.new("hi","ho")
|
||||
@label = Risc.label("hi","ho")
|
||||
end
|
||||
def test_set_instr
|
||||
pos = Position.set( @label , 8 , @binary)
|
||||
|
@ -7,7 +7,7 @@ module Risc
|
||||
Risc.machine.boot
|
||||
init = Parfait.object_space.get_init
|
||||
@builder = Risc::MethodCompiler.new( init ).builder(false , init)
|
||||
@label = Risc::Label.new("source","name")
|
||||
@label = Risc.label("source","name")
|
||||
end
|
||||
def test_has_build
|
||||
assert @builder.respond_to?(:build)
|
||||
|
@ -3,7 +3,7 @@ require_relative "../helper"
|
||||
module Risc
|
||||
class TestInstructions < MiniTest::Test
|
||||
def setup
|
||||
@label = Label.new("test" , "test")
|
||||
@label = Label.new("test" , "test",nil)
|
||||
@branch = Branch.new("test" , @label)
|
||||
@instruction = Instruction.new("test")
|
||||
end
|
||||
@ -19,7 +19,7 @@ module Risc
|
||||
assert @label.to_s.include?("Label")
|
||||
end
|
||||
def test_label_tos2
|
||||
assert Label.new(nil,nil).to_s.include?("Label")
|
||||
assert Label.new(nil,nil,nil).to_s.include?("Label")
|
||||
end
|
||||
def test_last_empty
|
||||
assert_equal @instruction, @instruction.last
|
||||
@ -55,7 +55,7 @@ module Risc
|
||||
assert_nil @instruction.next(2)
|
||||
end
|
||||
def test_label_is_method
|
||||
label = Label.new("test" , "Object.test")
|
||||
label = Label.new("test" , "Object.test" , nil)
|
||||
assert label.is_method
|
||||
end
|
||||
def test_label_is_not_method
|
||||
|
@ -26,7 +26,7 @@ module Risc
|
||||
end
|
||||
|
||||
def test_load_translates_label
|
||||
label = Label.new("test" , "test")
|
||||
label = Risc.label("test" , "test",nil)
|
||||
load = Risc.load_constant("source" , label , :r1)
|
||||
translated = @translator.translate(load)
|
||||
assert label != translated.constant
|
||||
|
Reference in New Issue
Block a user