whitespace and code style

This commit is contained in:
Torsten Ruger 2016-12-30 19:17:15 +02:00
parent db798d1a4a
commit 83b6628f1a
6 changed files with 12 additions and 11 deletions

View File

@ -32,11 +32,12 @@ module Register
def asseble_code_from( at )
@machine.objects.each do |id , objekt|
next unless objekt.is_a? Parfait::TypedMethod
log.debug "CODE1 #{objekt.name}"
binary = objekt.binary
binary.set_position( at )
objekt.instructions.set_position( at + 12 )# BinaryCode header
len = objekt.instructions.total_byte_length
log.debug "CODE #{objekt.name} at #{binary.position} len: #{len}"
log.debug "CODE2 #{objekt.name} at #{binary.position} len: #{len}"
binary.set_length(len , 0)
at += binary.padded_length
end

View File

@ -5,14 +5,14 @@ module Register
def collect_space
@objects.clear
keep Parfait.object_space , 0
constants.each {|o| keep(o,0)}
constants.each {|obj| keep(obj,0)}
end
def keep object , depth
return if object.nil?
#puts "adding #{' ' * depth}:#{object.class}"
#puts "ADD #{object.first.class}, #{object.last.class}" if object.is_a? Array
return unless self.add_object object
#puts "ADD #{object.inspect}, #{object.hash}" if object.is_a? Parfait::Type
return unless add_object( object )
# probably should make labels or even instructions derive from Parfait::Object, but . .
if object.is_a? Register::Label
object.each_label { |l| self.add_object(l)}

View File

@ -51,7 +51,7 @@ module Register
end
# Objects are data and get assembled after functions
def add_object objekt
def add_object( objekt )
return false if @objects[objekt.object_id]
return true if objekt.is_a? Fixnum
unless objekt.is_a?( Parfait::Object) or objekt.is_a?( Symbol) or objekt.is_a?( Register::Label)

View File

@ -122,8 +122,7 @@ module Typed
raise "create_method #{type.inspect} is not a Type" unless type.is_a? Parfait::Type
raise "Args must be Hash #{args}" unless args.is_a?(Hash)
raise "create_method #{method_name}.#{method_name.class}" unless method_name.is_a? Symbol
arguments = Parfait::Type.for_hash( type.object_class , args )
@method = type.create_method( method_name , arguments)
@method = type.create_method( method_name , args)
self
end

View File

@ -211,7 +211,7 @@ module Parfait
# Word from string
def self.new_word( string )
string = string.to_s if string.is_a? Symbol
word = Parfait::Word.new( string.length )
word = Word.new( string.length )
string.codepoints.each_with_index do |code , index |
word.set_char(index + 1 , code)
end

View File

@ -3,7 +3,8 @@ require_relative "../helper"
class TestEmptyWord < MiniTest::Test
def setup
@word = ::Parfait::Word.new(0)
Register.machine.boot
@word = Parfait::Word.new(0)
end
def test_word_create
assert @word.empty?
@ -28,8 +29,8 @@ end
class TestWord < MiniTest::Test
def setup
Register.machine.boot unless Register.machine.booted
@word = ::Parfait::Word.new(5)
Register.machine.boot
@word = Parfait::Word.new(5)
end
def test_len
assert_equal 5 , @word.length