misc to_s and small fixes

This commit is contained in:
Torsten Ruger 2018-07-04 08:28:29 +03:00
parent 8b9fd29ce9
commit 6f936f190d
13 changed files with 46 additions and 21 deletions

View File

@ -33,7 +33,7 @@ module Mom
end end
def to_s def to_s
"ReturnSequence" "ReturnSequence in (#{compiler.method.name})"
end end
end end

View File

@ -39,5 +39,8 @@ module Parfait
index = @type.get_index(name) index = @type.get_index(name)
get_at(index) get_at(index)
end end
def to_s
"Message:#{name}(#{arguments.get_length})"
end
end end
end end

View File

@ -23,6 +23,13 @@
module Parfait module Parfait
class NamedList < Object class NamedList < Object
def to_s
str = "NamedList len= #{get_length}"
str += " at #{Risc::Position.get(self)}" if Risc::Position.set?(self)
end
def get_length
get_type.get_length - 1
end
def self.type_for( arguments ) def self.type_for( arguments )
my_class = Parfait.object_space.classes[:NamedList] my_class = Parfait.object_space.classes[:NamedList]
Type.for_hash( my_class , {type: my_class.instance_type}.merge(arguments)) Type.for_hash( my_class , {type: my_class.instance_type}.merge(arguments))

View File

@ -33,8 +33,7 @@ module Risc
end end
def start_program(linker = nil) def start_program(linker = nil)
@linker = linker || @linker initialize(linker || @linker)
initialize(@linker)
init = @linker.cpu_init init = @linker.cpu_init
set_state(:running) set_state(:running)
set_pc( Position.get(init).at ) set_pc( Position.get(init).at )
@ -51,12 +50,7 @@ module Risc
raise "Not int #{pos}" unless pos.is_a? Numeric raise "Not int #{pos}" unless pos.is_a? Numeric
position = Position.at(pos) position = Position.at(pos)
raise "No position at 0x#{pos.to_s(16)}" unless position raise "No position at 0x#{pos.to_s(16)}" unless position
if position.is_a?(CodeListener)
raise "Setting Code #{clock}-#{position}, #{position.method}"
#return set_pc(position.at + Parfait::BinaryCode.byte_offset)
end
log.debug "Setting Position #{clock}-#{position}, " log.debug "Setting Position #{clock}-#{position}, "
#raise "not instruction position #{position}-#{position.class}-#{position.object.class}" unless position.is_a?(InstructionPosition)
set_instruction( position.object ) set_instruction( position.object )
@clock += 1 @clock += 1
@pc = position.at @pc = position.at
@ -166,7 +160,7 @@ module Risc
else else
value = object.get_internal_word( index ) value = object.get_internal_word( index )
end end
log.debug "#{@instruction} == #{object}(#{object.class}) (#{value}|#{index})" log.debug "#{@instruction} == #{object}(#{Position.get(object)}) (#{value}|#{index})"
set_register( @instruction.register , value ) set_register( @instruction.register , value )
true true
end end
@ -219,16 +213,15 @@ module Risc
def execute_FunctionCall def execute_FunctionCall
meth = @instruction.method meth = @instruction.method
at = Position.get(meth.binary).at at = Position.get(meth.binary)
log.debug "Call to #{meth.name} at:#{at}" log.debug "Call to #{meth.name} at:#{at}"
set_pc(at + Parfait::BinaryCode.byte_offset) set_pc(at + Parfait::BinaryCode.byte_offset)
#set_instruction @instruction.method.risc_instructions
false false
end end
def execute_FunctionReturn def execute_FunctionReturn
link = get_register( @instruction.register ) link = get_register( @instruction.register )
log.debug "Return to #{link} #{link.class}" log.debug "Return to #{link.to_s(16)}"
set_pc link set_pc link
false false
end end

View File

@ -82,7 +82,6 @@ module Risc
# start at code_start. # start at code_start.
def position_code(code_start) def position_code(code_start)
assemblers.each do |asm| assemblers.each do |asm|
#next unless method.name == :main or method.name == :__init__
Position.log.debug "Method start #{code_start.to_s(16)} #{asm.method.name}" Position.log.debug "Method start #{code_start.to_s(16)} #{asm.method.name}"
code_pos = CodeListener.init(asm.method.binary, platform) code_pos = CodeListener.init(asm.method.binary, platform)
instructions = asm.instructions instructions = asm.instructions

View File

@ -7,7 +7,7 @@ module Risc
@branch = branch @branch = branch
end end
# incoming position is the labels # incoming position is the label
def position_changed(position) def position_changed(position)
@branch.precheck @branch.precheck
end end

View File

@ -11,6 +11,7 @@ module RubyX
def ruby_to_vool def ruby_to_vool
vool = RubyCompiler.compile( source ) vool = RubyCompiler.compile( source )
vool = vool.normalize vool = vool.normalize
#puts vool
vool vool
end end

View File

@ -38,6 +38,9 @@ module Vool
def slot_definition(method) def slot_definition(method)
return Mom::SlotDefinition.new(Parfait.object_space.true_object , []) return Mom::SlotDefinition.new(Parfait.object_space.true_object , [])
end end
def to_s(depth = 0)
"true"
end
end end
class FalseConstant < Constant class FalseConstant < Constant
def ct_type def ct_type
@ -46,6 +49,9 @@ module Vool
def slot_definition(method) def slot_definition(method)
return Mom::SlotDefinition.new(Parfait.object_space.false_object , []) return Mom::SlotDefinition.new(Parfait.object_space.false_object , [])
end end
def to_s(depth = 0)
"false"
end
end end
class NilConstant < Constant class NilConstant < Constant
def ct_type def ct_type
@ -54,6 +60,9 @@ module Vool
def slot_definition(method) def slot_definition(method)
return Mom::SlotDefinition.new(Parfait.object_space.nil_object , []) return Mom::SlotDefinition.new(Parfait.object_space.nil_object , [])
end end
def to_s(depth = 0)
"nil"
end
end end
class SelfExpression < Expression class SelfExpression < Expression
attr_reader :my_type attr_reader :my_type
@ -67,11 +76,14 @@ module Vool
def ct_type def ct_type
@my_type @my_type
end end
def to_s def to_s(depth = 0)
"self" "self"
end end
end end
class SuperExpression < Statement class SuperExpression < Statement
def to_s(depth = 0)
"super"
end
end end
class StringConstant < Constant class StringConstant < Constant
attr_reader :value attr_reader :value
@ -84,6 +96,9 @@ module Vool
def ct_type def ct_type
Parfait.object_space.get_class_by_name(:Word).instance_type Parfait.object_space.get_class_by_name(:Word).instance_type
end end
def to_s(depth = 0)
"'#{@value}'"
end
end end
class SymbolConstant < StringConstant class SymbolConstant < StringConstant
def ct_type def ct_type

View File

@ -54,7 +54,7 @@ module Risc
end end
def test_pc1 def test_pc1
@interpreter.tick @interpreter.tick
assert_equal 21304 , @interpreter.pc assert_equal 21432 , @interpreter.pc
end end
def test_tick2 def test_tick2
@interpreter.tick @interpreter.tick
@ -68,7 +68,7 @@ module Risc
def test_pc2 def test_pc2
@interpreter.tick @interpreter.tick
@interpreter.tick @interpreter.tick
assert_equal 21308 , @interpreter.pc assert_equal 21436 , @interpreter.pc
end end
def test_tick_14_jump def test_tick_14_jump
14.times {@interpreter.tick} 14.times {@interpreter.tick}

View File

@ -1,7 +1,7 @@
require_relative "helper" require_relative "helper"
module Risc module Risc
class TestMachineObjects < MiniTest::Test class TestLinkerObjects < MiniTest::Test
def setup def setup
Parfait.boot! Parfait.boot!
@ -17,7 +17,7 @@ module Risc
assert_raises {@machine.add_constant( 1 )} assert_raises {@machine.add_constant( 1 )}
end end
end end
class TestMachineInit < MiniTest::Test class TestLinkerInit < MiniTest::Test
def setup def setup
Parfait.boot! Parfait.boot!
Risc.boot! Risc.boot!

View File

@ -13,5 +13,12 @@ module Risc
assert Position.get(obj).valid? , "#{Position.get(obj)} , #{obj.object_id.to_s(16)}" assert Position.get(obj).valid? , "#{Position.get(obj)} , #{obj.object_id.to_s(16)}"
end end
end end
def test_one_main
mains = @linker.assemblers.find_all{|asm| asm.method.name == :main }
assert_equal 1 , mains.length
end
def test_assembler_num
assert_equal 23 , @linker.assemblers.length
end
end end
end end

View File

@ -14,7 +14,7 @@ module RubyX
assert_equal Risc::Linker , @linker.class assert_equal Risc::Linker , @linker.class
end end
def test_method def test_method
assert_equal :main , @linker.assemblers.last.method.name assert_equal :main , @linker.assemblers.first.method.name
end end
end end
end end

View File

@ -10,7 +10,7 @@ module ScopeHelper
end end
def as_main(statements) def as_main(statements)
in_Space("def main ; #{statements}; end") in_Space("def main(arg) ; #{statements}; end")
end end
def as_test_main( statements ) def as_test_main( statements )