From 1a236aa50ed869e47cff94e44e9d54a1a86d74b1 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Mon, 26 Oct 2015 12:24:47 +0200 Subject: [PATCH] make binary code indexed (not derive from word) still some work to be done there, as we should really have a byte buffer --- lib/parfait/binary_code.rb | 17 ++++++++--------- lib/register/assembler.rb | 7 +++---- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/lib/parfait/binary_code.rb b/lib/parfait/binary_code.rb index cfd4d0d9..2d4bfd94 100644 --- a/lib/parfait/binary_code.rb +++ b/lib/parfait/binary_code.rb @@ -9,18 +9,17 @@ module Parfait # obviously not a "Word" but a ByteArray , but no such class yet # As on the other hand has no encoding (yet) it is close enough - class BinaryCode < Word - def initialize name - super(0) - self.name = name - end + class BinaryCode < Object attribute :name - # this is a sof check if there are instance variables or "structure" - # have to override false, as word answers true - def is_value? - false + include Indexed + self.offset(2) + + def initialize name + super() + self.name = name end + def to_s "BinaryCode #{self.name}" end diff --git a/lib/register/assembler.rb b/lib/register/assembler.rb index 5552d094..03919621 100644 --- a/lib/register/assembler.rb +++ b/lib/register/assembler.rb @@ -28,7 +28,7 @@ module Register @machine.objects.each do |id , objekt| next unless objekt.is_a? Parfait::Method # should be fill_to_length (with zeros) - objekt.binary.set_length(objekt.source.total_byte_length , 0) + objekt.binary.set_length(objekt.source.total_byte_length ) end #need the initial jump at 0 and then functions @machine.init.set_position(at) @@ -112,14 +112,13 @@ module Register puts "Assembly error #{method.name}\n#{Sof.write(method.source.instructions).to_s[0...2000]}" raise e end - method.binary.fill_with 0 index = 1 stream.rewind #puts "Assembled #{method.name} with length #{stream.length}" - raise "length error #{method.binary.length} != #{method.source.total_byte_length}" if method.binary.length != method.source.total_byte_length + raise "length error #{method.binary.length} != #{method.source.total_byte_length}" if method.binary.get_length != method.source.total_byte_length raise "length error #{stream.length} != #{method.source.total_byte_length}" if method.source.total_byte_length != stream.length stream.each_byte do |b| - method.binary.set_char(index , b ) + method.binary.set(index , b ) index = index + 1 end end