get binary code to work
This commit is contained in:
parent
5845bde33a
commit
c28430698c
@ -10,5 +10,17 @@ module Parfait
|
|||||||
# obviously not a "Word" but a ByteArray , but no such class yet
|
# 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
|
# As on the other hand has no encoding (yet) it is close enough
|
||||||
class BinaryCode < Word
|
class BinaryCode < Word
|
||||||
|
def initialize name
|
||||||
|
super(0)
|
||||||
|
@name = name
|
||||||
|
end
|
||||||
|
# this is a sof check if there are instance variables or "structure"
|
||||||
|
# have to override false, as word answers true
|
||||||
|
def is_value?
|
||||||
|
false
|
||||||
|
end
|
||||||
|
def to_s
|
||||||
|
"BinaryCode #{@name}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -24,7 +24,7 @@ module Parfait
|
|||||||
raise "No class #{name}" unless clazz
|
raise "No class #{name}" unless clazz
|
||||||
@for_class = clazz
|
@for_class = clazz
|
||||||
@name = name
|
@name = name
|
||||||
@code = BinaryCode.new_object 0
|
@code = BinaryCode.new_object name
|
||||||
@arg_names = arg_names
|
@arg_names = arg_names
|
||||||
@locals = []
|
@locals = []
|
||||||
@tmps = []
|
@tmps = []
|
||||||
|
@ -41,6 +41,21 @@ module Parfait
|
|||||||
return obj_len
|
return obj_len
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# make every char equal the given one
|
||||||
|
def fill_with char
|
||||||
|
fill_from_with(0 , char)
|
||||||
|
end
|
||||||
|
|
||||||
|
def fill_from_with from , char
|
||||||
|
len = self.length()
|
||||||
|
return if from <= 0
|
||||||
|
while( from <= len)
|
||||||
|
set_char( from , char)
|
||||||
|
from = from + 1
|
||||||
|
end
|
||||||
|
from
|
||||||
|
end
|
||||||
|
|
||||||
# true if no characters
|
# true if no characters
|
||||||
def empty?
|
def empty?
|
||||||
return self.length == 0
|
return self.length == 0
|
||||||
@ -53,11 +68,7 @@ module Parfait
|
|||||||
counter = self.length()
|
counter = self.length()
|
||||||
return if counter >= len
|
return if counter >= len
|
||||||
internal_object_grow( len + 1)
|
internal_object_grow( len + 1)
|
||||||
counter = counter + 1
|
fill_from_with( counter + 1 , fill_char )
|
||||||
while( counter <= len)
|
|
||||||
set_char( counter , fill_char)
|
|
||||||
counter = counter + 1
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# set the character at the given index to the given character
|
# set the character at the given index to the given character
|
||||||
@ -120,10 +131,5 @@ module Parfait
|
|||||||
def mem_length
|
def mem_length
|
||||||
padded(1 + string.length)
|
padded(1 + string.length)
|
||||||
end
|
end
|
||||||
def position
|
|
||||||
return @position if @position
|
|
||||||
return @string.position if @string.position
|
|
||||||
super
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -21,7 +21,7 @@ module Register
|
|||||||
def link
|
def link
|
||||||
# want to have the methods first in the executable
|
# want to have the methods first in the executable
|
||||||
# so first we determine the code length for the methods and set the
|
# so first we determine the code length for the methods and set the
|
||||||
# code array to right length
|
# binary code (array) to right length
|
||||||
@space.objects.each do |objekt|
|
@space.objects.each do |objekt|
|
||||||
next unless objekt.is_a? Parfait::Method
|
next unless objekt.is_a? Parfait::Method
|
||||||
objekt.code.set_length(objekt.info.mem_length / 4 , 0)
|
objekt.code.set_length(objekt.info.mem_length / 4 , 0)
|
||||||
@ -35,6 +35,11 @@ module Register
|
|||||||
end
|
end
|
||||||
# and then everything else
|
# and then everything else
|
||||||
@space.objects.each do | objekt|
|
@space.objects.each do | objekt|
|
||||||
|
# have to tell the code that will be assembled where it is to
|
||||||
|
# get the jumps/calls right
|
||||||
|
if objekt.is_a? Parfait::Method
|
||||||
|
objekt.info.set_position( objekt.code.position )
|
||||||
|
end
|
||||||
next if objekt.is_a? Parfait::BinaryCode
|
next if objekt.is_a? Parfait::BinaryCode
|
||||||
objekt.set_position at
|
objekt.set_position at
|
||||||
at += objekt.mem_length
|
at += objekt.mem_length
|
||||||
@ -83,7 +88,7 @@ module Register
|
|||||||
code.assemble( stream )
|
code.assemble( stream )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
method.code.clear
|
method.code.fill_with 0
|
||||||
index = 1
|
index = 1
|
||||||
stream.each_byte do |b|
|
stream.each_byte do |b|
|
||||||
method.set_char(index , b )
|
method.set_char(index , b )
|
||||||
|
Loading…
Reference in New Issue
Block a user