store three versions of the code in method

source, instructions and binary
This commit is contained in:
Torsten Ruger 2015-10-23 14:41:47 +03:00
parent e0c5bc4c11
commit 897e11ce80
4 changed files with 9 additions and 9 deletions

View File

@ -23,7 +23,7 @@ module Parfait
raise "No class #{name}" unless clazz
self.for_class = clazz
self.name = name
self.code = BinaryCode.new name
self.binary = BinaryCode.new name
raise "Wrong type, expect List not #{arguments.class}" unless arguments.is_a? List
arguments.each do |var|
raise "Must be variable argument, not #{var}" unless var.is_a? Variable
@ -31,7 +31,7 @@ module Parfait
self.arguments = arguments
self.locals = List.new
end
attributes [:name , :arguments , :for_class , :code , :locals ]
attributes [:name , :source , :instructions , :binary ,:arguments , :for_class, :locals ]
# determine whether this method has an argument by the name

View File

@ -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.code.set_length(objekt.source.byte_length , 0)
objekt.binary.set_length(objekt.source.byte_length , 0)
end
#need the initial jump at 0 and then functions
@machine.init.set_position(at)
@ -47,7 +47,7 @@ module Register
# 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.source.set_position( objekt.code.position )
objekt.source.set_position( objekt.binary.position )
end
next if objekt.is_a? Parfait::BinaryCode
objekt.set_position at
@ -117,14 +117,14 @@ module Register
end
end
end
method.code.fill_with 0
method.binary.fill_with 0
index = 1
stream.rewind
#puts "Assembled #{method.name} with length #{stream.length}"
raise "length error #{method.code.length} != #{method.source.byte_length}" if method.code.length != method.source.byte_length
raise "length error #{method.binary.length} != #{method.source.byte_length}" if method.binary.length != method.source.byte_length
raise "length error #{stream.length} != #{method.source.byte_length}" if method.source.byte_length != stream.length
stream.each_byte do |b|
method.code.set_char(index , b )
method.binary.set_char(index , b )
index = index + 1
end
end

View File

@ -130,7 +130,7 @@ module Register
# instances are copied (shame on you)
:Class => [:object_layout , :name , :instance_methods , :super_class , :meta_class],
:Dictionary => [:keys , :values ] ,
:Method => [:name , :code ,:arguments , :for_class, :locals ] ,
:Method => [:name , :source , :instructions , :binary ,:arguments , :for_class, :locals ] ,
:Variable => [:type , :name , :value ] ,
:Module => [:name , :instance_methods , :super_class , :meta_class ]
}

View File

@ -17,7 +17,7 @@ class HelloTest < MiniTest::Test
writer.save "hello.o"
end
def test_string_put
def pest_string_put
@string_input = <<HERE
class Object
int main()