assemble risc to it's position (not itself)

So in the next step the interpreter can use positions as program counter
and would be much more like the real thing
This commit is contained in:
Torsten Ruger 2018-05-17 09:49:01 +03:00
parent 49c4d170ce
commit 37d62d298e
6 changed files with 15 additions and 34 deletions

View File

@ -19,10 +19,11 @@ module Risc
4 4
end end
def assemble(io) def assemble(io)
io.write_unsigned_int_32(self) pos = Position.get(self).at
io.write_unsigned_int_32(pos)
end end
class Branch < Instruction class Branch < Instruction
def first def first #some logging assumes arm
self self
end end
end end

View File

@ -62,7 +62,7 @@ module Risc
case object case object
when Parfait::BinaryCode when Parfait::BinaryCode
CodePosition.new(object,at , extra) CodePosition.new(object,at , extra)
when Arm::Instruction , Risc::Label when Arm::Instruction , Risc::Instruction
InstructionPosition.new(object,at , extra) InstructionPosition.new(object,at , extra)
else else
ObjectPosition.new(at,object) ObjectPosition.new(at,object)

View File

@ -22,15 +22,5 @@ module Risc
produced = produce_body produced = produce_body
assert_equal 5 , produced.constant.value assert_equal 5 , produced.constant.value
end end
def pest_cache_check
produced = produce_body
assert_equal NotSame , produced.next(3).class
assert_equal produced.next(34) , produced.next(3).label
end
def pest_check_resolve
produced = produce_body
assert_equal FunctionCall , produced.next(30).class
assert_equal :resolve_method ,produced.next(30).method.name
end
end end
end end

View File

@ -49,10 +49,6 @@ module Risc
assert_equal Risc::LoadConstant , produced.next(38).class assert_equal Risc::LoadConstant , produced.next(38).class
assert_equal Parfait::NilClass , produced.next(38).constant.class assert_equal Parfait::NilClass , produced.next(38).constant.class
end end
def pest_nil_check
produced = produce_body
assert_equal produced.next(13) , produced.next(8).label
end
def test_back_jump # should jump back to condition label def test_back_jump # should jump back to condition label
produced = produce_body produced = produce_body
@ -60,11 +56,5 @@ module Risc
assert_equal produced , produced.next(44).label assert_equal produced , produced.next(44).label
end end
def test_merge_label
produced = produce_body
assert_equal Risc::Label , produced.next(45).class
assert produced.next(45).name.start_with?("merge_") , produced.next(29).name
end
end end
end end

View File

@ -18,7 +18,7 @@ module Risc
assert IdentityTranslator.new assert IdentityTranslator.new
end end
end end
class TestTranslator < MiniTest::Test class TestIdentityTranslator < MiniTest::Test
def setup def setup
@machine = Risc.machine.boot @machine = Risc.machine.boot
@ -44,7 +44,7 @@ module Risc
all << ins all << ins
end end
end end
def test_no_risc #by assembling, risc doesnt have assemble method def test_no_risc
@machine.translate(:interpreter) @machine.translate(:interpreter)
@machine.position_all @machine.position_all
@machine.create_binary @machine.create_binary

View File

@ -64,14 +64,14 @@ module Vool
assert_equal "Word_Type" , compile( ":symbol").name assert_equal "Word_Type" , compile( ":symbol").name
end end
# classes fot these are not implemented in parfait yet # classes fot these are not implemented in parfait yet
# def pest_nil def pest_nil
# assert_equal "Nil_Type" , compile( "nil").name assert_equal "Nil_Type" , compile( "nil").name
# end end
# def pest_false def pest_false
# assert_equal "False_Type" , compile( "false").name assert_equal "False_Type" , compile( "false").name
# end end
# def pest_true def pest_true
# assert_equal "True_Type" , compile( "true").name assert_equal "True_Type" , compile( "true").name
# end end
end end
end end