store three versions of the code in method
source, instructions and binary
This commit is contained in:
parent
e0c5bc4c11
commit
897e11ce80
@ -23,7 +23,7 @@ module Parfait
|
|||||||
raise "No class #{name}" unless clazz
|
raise "No class #{name}" unless clazz
|
||||||
self.for_class = clazz
|
self.for_class = clazz
|
||||||
self.name = name
|
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
|
raise "Wrong type, expect List not #{arguments.class}" unless arguments.is_a? List
|
||||||
arguments.each do |var|
|
arguments.each do |var|
|
||||||
raise "Must be variable argument, not #{var}" unless var.is_a? Variable
|
raise "Must be variable argument, not #{var}" unless var.is_a? Variable
|
||||||
@ -31,7 +31,7 @@ module Parfait
|
|||||||
self.arguments = arguments
|
self.arguments = arguments
|
||||||
self.locals = List.new
|
self.locals = List.new
|
||||||
end
|
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
|
# determine whether this method has an argument by the name
|
||||||
|
@ -28,7 +28,7 @@ module Register
|
|||||||
@machine.objects.each do |id , objekt|
|
@machine.objects.each do |id , objekt|
|
||||||
next unless objekt.is_a? Parfait::Method
|
next unless objekt.is_a? Parfait::Method
|
||||||
# should be fill_to_length (with zeros)
|
# 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
|
end
|
||||||
#need the initial jump at 0 and then functions
|
#need the initial jump at 0 and then functions
|
||||||
@machine.init.set_position(at)
|
@machine.init.set_position(at)
|
||||||
@ -47,7 +47,7 @@ module Register
|
|||||||
# have to tell the code that will be assembled where it is to
|
# have to tell the code that will be assembled where it is to
|
||||||
# get the jumps/calls right
|
# get the jumps/calls right
|
||||||
if objekt.is_a? Parfait::Method
|
if objekt.is_a? Parfait::Method
|
||||||
objekt.source.set_position( objekt.code.position )
|
objekt.source.set_position( objekt.binary.position )
|
||||||
end
|
end
|
||||||
next if objekt.is_a? Parfait::BinaryCode
|
next if objekt.is_a? Parfait::BinaryCode
|
||||||
objekt.set_position at
|
objekt.set_position at
|
||||||
@ -117,14 +117,14 @@ module Register
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
method.code.fill_with 0
|
method.binary.fill_with 0
|
||||||
index = 1
|
index = 1
|
||||||
stream.rewind
|
stream.rewind
|
||||||
#puts "Assembled #{method.name} with length #{stream.length}"
|
#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
|
raise "length error #{stream.length} != #{method.source.byte_length}" if method.source.byte_length != stream.length
|
||||||
stream.each_byte do |b|
|
stream.each_byte do |b|
|
||||||
method.code.set_char(index , b )
|
method.binary.set_char(index , b )
|
||||||
index = index + 1
|
index = index + 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -130,7 +130,7 @@ module Register
|
|||||||
# instances are copied (shame on you)
|
# instances are copied (shame on you)
|
||||||
:Class => [:object_layout , :name , :instance_methods , :super_class , :meta_class],
|
:Class => [:object_layout , :name , :instance_methods , :super_class , :meta_class],
|
||||||
:Dictionary => [:keys , :values ] ,
|
:Dictionary => [:keys , :values ] ,
|
||||||
:Method => [:name , :code ,:arguments , :for_class, :locals ] ,
|
:Method => [:name , :source , :instructions , :binary ,:arguments , :for_class, :locals ] ,
|
||||||
:Variable => [:type , :name , :value ] ,
|
:Variable => [:type , :name , :value ] ,
|
||||||
:Module => [:name , :instance_methods , :super_class , :meta_class ]
|
:Module => [:name , :instance_methods , :super_class , :meta_class ]
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ class HelloTest < MiniTest::Test
|
|||||||
writer.save "hello.o"
|
writer.save "hello.o"
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_string_put
|
def pest_string_put
|
||||||
@string_input = <<HERE
|
@string_input = <<HERE
|
||||||
class Object
|
class Object
|
||||||
int main()
|
int main()
|
||||||
|
Loading…
Reference in New Issue
Block a user