Move the space instance to the parfait module

A better fit, maybe even a pattern for singletons
This commit is contained in:
Torsten Ruger 2016-12-30 14:10:49 +02:00
parent a00f6be3ba
commit f0350601a7
43 changed files with 85 additions and 85 deletions

View File

@ -21,7 +21,7 @@ module Elf
set_text assembler.write_as_string set_text assembler.write_as_string
# for debug add labels for labels # for debug add labels for labels
Parfait::Space.object_space.types.values.each do |type| Parfait.object_space.types.values.each do |type|
type.methods.each do |f| type.methods.each do |f|
f.instructions.each_label do |label| f.instructions.each_label do |label|
add_symbol "#{clazz.name}::#{f.name}:#{label.name}" , label.position add_symbol "#{clazz.name}::#{f.name}:#{label.name}" , label.position

View File

@ -21,7 +21,7 @@ module Melon
def on_class statement def on_class statement
name , sup , body = *statement name , sup , body = *statement
clazz = Parfait::Space.object_space.create_class(get_name(name) , get_name(sup) ) clazz = Parfait.object_space.create_class(get_name(name) , get_name(sup) )
ivar_hash = TypeCollector.new.collect(body) ivar_hash = TypeCollector.new.collect(body)
clazz.set_instance_type( Parfait::Type.for_hash( clazz , ivar_hash ) ) clazz.set_instance_type( Parfait::Type.for_hash( clazz , ivar_hash ) )

View File

@ -21,7 +21,7 @@ module Melon
private private
def make_type( statement ) def make_type( statement )
type = Parfait::Space.object_space.get_class_by_name(:Message ).instance_type type = Parfait.object_space.get_class_by_name(:Message ).instance_type
statement.children.each do |arg| statement.children.each do |arg|
type = type.add_instance_variable( arg.children[0] , :Object ) type = type.add_instance_variable( arg.children[0] , :Object )
end end
@ -30,7 +30,7 @@ module Melon
def make_locals(body) def make_locals(body)
locals = LocalsCollector.new.collect(body) locals = LocalsCollector.new.collect(body)
type = Parfait::Space.object_space.get_class_by_name(:NamedList ).instance_type type = Parfait.object_space.get_class_by_name(:NamedList ).instance_type
locals.each do |name , local_type | locals.each do |name , local_type |
type = type.add_instance_variable( name , local_type ) type = type.add_instance_variable( name , local_type )
end end

View File

@ -52,7 +52,7 @@ module Register
fix_types( types , classes ) fix_types( types , classes )
space = Parfait::Space.new( classes ) space = Parfait::Space.new( classes )
Parfait::Space.set_object_space( space ) Parfait.set_object_space( space )
#puts Sof.write(@space) #puts Sof.write(@space)
boot_functions!( space ) boot_functions!( space )
@ -91,7 +91,7 @@ module Register
clazz = BootClass.new(type) clazz = BootClass.new(type)
boot_space.classes[name] = clazz boot_space.classes[name] = clazz
end end
Parfait::Space.set_object_space boot_space Parfait.set_object_space boot_space
end end
# superclasses other than default object # superclasses other than default object

View File

@ -11,7 +11,7 @@ module Register
compiler.method.set_instructions( new_start) compiler.method.set_instructions( new_start)
compiler.set_current new_start compiler.set_current new_start
space = Parfait::Space.object_space space = Parfait.object_space
space_reg = compiler.use_reg(:Space) #Set up the Space as self upon init space_reg = compiler.use_reg(:Space) #Set up the Space as self upon init
compiler.add_load_constant("__init__ load Space", space , space_reg) compiler.add_load_constant("__init__ load Space", space , space_reg)
message_ind = Register.resolve_to_index( :space , :first_message ) message_ind = Register.resolve_to_index( :space , :first_message )
@ -21,7 +21,7 @@ module Register
ret_tmp = compiler.use_reg(:Label) ret_tmp = compiler.use_reg(:Label)
compiler.add_load_constant("__init__ load return", exit_label , ret_tmp) compiler.add_load_constant("__init__ load return", exit_label , ret_tmp)
compiler.add_reg_to_slot("__init__ store return", ret_tmp , :message , :return_address) compiler.add_reg_to_slot("__init__ store return", ret_tmp , :message , :return_address)
compiler.add_code Register.function_call( "__init__ issue call" , Parfait::Space.object_space.get_main ) compiler.add_code Register.function_call( "__init__ issue call" , Parfait.object_space.get_main )
compiler.add_code exit_label compiler.add_code exit_label
emit_syscall( compiler , :exit ) emit_syscall( compiler , :exit )
return compiler.method return compiler.method

View File

@ -4,7 +4,7 @@ module Register
module Collector module Collector
def collect def collect
self.objects.clear self.objects.clear
keep Parfait::Space.object_space , 0 keep Parfait.object_space , 0
constants.each {|o| keep(o,0)} constants.each {|o| keep(o,0)}
end end

View File

@ -26,7 +26,7 @@ module Register
# idea being that later method missing could catch translate_xxx and translate to target xxx # idea being that later method missing could catch translate_xxx and translate to target xxx
# now we just instantiate ArmTranslater and pass instructions # now we just instantiate ArmTranslater and pass instructions
def translate_arm def translate_arm
methods = Parfait::Space.object_space.collect_methods methods = Parfait.object_space.collect_methods
translate_methods( methods ) translate_methods( methods )
label = @init.next label = @init.next
@init = Arm::Translator.new.translate( @init ) @init = Arm::Translator.new.translate( @init )
@ -64,7 +64,7 @@ module Register
def boot def boot
initialize initialize
boot_parfait! boot_parfait!
@init = Branch.new( "__initial_branch__" , Parfait::Space.object_space.get_init.instructions ) @init = Branch.new( "__initial_branch__" , Parfait.object_space.get_init.instructions )
@booted = true @booted = true
self self
end end

View File

@ -85,7 +85,7 @@ module Register
def self.resolve_to_index( clazz_name , instance_name ) def self.resolve_to_index( clazz_name , instance_name )
return instance_name unless instance_name.is_a? Symbol return instance_name unless instance_name.is_a? Symbol
real_name = clazz_name.to_s.split('_').last.capitalize.to_sym real_name = clazz_name.to_s.split('_').last.capitalize.to_sym
clazz = Parfait::Space.object_space.get_class_by_name(real_name) clazz = Parfait.object_space.get_class_by_name(real_name)
raise "Class name not given #{real_name}" unless clazz raise "Class name not given #{real_name}" unless clazz
index = clazz.instance_type.variable_index( instance_name ) index = clazz.instance_type.variable_index( instance_name )
raise "Instance name=#{instance_name} not found on #{real_name}:#{clazz.instance_type}" unless index.is_a?(Numeric) raise "Instance name=#{instance_name} not found on #{real_name}:#{clazz.instance_type}" unless index.is_a?(Numeric)

View File

@ -71,7 +71,7 @@ module Typed
@method = method @method = method
@type = method.for_type @type = method.for_type
else else
@type = Parfait::Space.object_space.get_type() @type = Parfait.object_space.get_type()
@method = @type.get_method( :main ) @method = @type.get_method( :main )
@method = @type.create_method( :main ,{}) unless @method @method = @type.create_method( :main ,{}) unless @method
end end
@ -108,7 +108,7 @@ module Typed
# class_name and method_name are pretty clear, args are given as a ruby array # class_name and method_name are pretty clear, args are given as a ruby array
def create_method( class_name , method_name , args = {}) def create_method( class_name , method_name , args = {})
raise "create_method #{class_name}.#{class_name.class}" unless class_name.is_a? Symbol raise "create_method #{class_name}.#{class_name.class}" unless class_name.is_a? Symbol
clazz = Parfait::Space.object_space.get_class_by_name! class_name clazz = Parfait.object_space.get_class_by_name! class_name
create_method_for( clazz.instance_type , method_name , args) create_method_for( clazz.instance_type , method_name , args)
end end

View File

@ -46,7 +46,7 @@ module Typed
when Parfait::Type when Parfait::Type
type = me.type type = me.type
when Symbol when Symbol
type = Parfait::Space.object_space.get_class_by_name(me.type).instance_type type = Parfait.object_space.get_class_by_name(me.type).instance_type
else else
raise me.inspect raise me.inspect
end end

View File

@ -7,7 +7,7 @@ module Typed
type = receiver.type type = receiver.type
if(type.is_a?(Symbol)) if(type.is_a?(Symbol))
type = Parfait::Space.object_space.get_class_by_name(type).instance_type type = Parfait.object_space.get_class_by_name(type).instance_type
end end
field_name = statement.field.name field_name = statement.field.name

View File

@ -45,7 +45,7 @@ module Typed
end end
def load_special_space(statement) def load_special_space(statement)
space = Parfait::Space.object_space space = Parfait.object_space
reg = use_reg :Space , space reg = use_reg :Space , space
add_load_constant( "#{statement} load space", space , reg ) add_load_constant( "#{statement} load space", space , reg )
return reg return reg

View File

@ -45,7 +45,7 @@ module Parfait
def super_class def super_class
raise "No super_class for class #{@name}" unless @super_class_name raise "No super_class for class #{@name}" unless @super_class_name
s = Parfait::Space.object_space.get_class_by_name(@super_class_name) s = Parfait.object_space.get_class_by_name(@super_class_name)
raise "superclass not found for class #{@name} (#{@super_class_name})" unless s raise "superclass not found for class #{@name} (#{@super_class_name})" unless s
s s
end end

View File

@ -23,7 +23,7 @@ module Parfait
object = self.allocate object = self.allocate
# have to grab the class, because we are in the ruby class not the parfait one # have to grab the class, because we are in the ruby class not the parfait one
cl = Space.object_space.get_class_by_name( self.name.split("::").last.to_sym) cl = Parfait.object_space.get_class_by_name( self.name.split("::").last.to_sym)
# and have to set the type before we let the object do anything. otherwise boom # and have to set the type before we let the object do anything. otherwise boom
object.set_type cl.instance_type object.set_type cl.instance_type

View File

@ -9,6 +9,16 @@
# recycles objects. # recycles objects.
module Parfait module Parfait
# Make the object space globally available
def self.object_space
@@object_space
end
# TODO Must get rid of the setter (move the boot process ?)
def self.set_object_space space
@@object_space = space
end
# The Space contains all objects for a program. In functional terms it is a program, but in oo # The Space contains all objects for a program. In functional terms it is a program, but in oo
# it is a collection of objects, some of which are data, some classes, some functions # it is a collection of objects, some of which are data, some classes, some functions
@ -42,16 +52,6 @@ module Parfait
attr_reader :types , :classes , :first_message attr_reader :types , :classes , :first_message
# Make the object space globally available
def self.object_space
@@object_space
end
# TODO Must get rid of the setter
def self.set_object_space space
@@object_space = space
end
def each_type def each_type
@types.values.each do |type| @types.values.each do |type|
yield(type) yield(type)

View File

@ -7,7 +7,7 @@ class Symbol
true true
end end
def get_type def get_type
l = Parfait::Space.object_space.classes[:Word].instance_type l = Parfait.object_space.classes[:Word].instance_type
#puts "LL #{l.class}" #puts "LL #{l.class}"
l l
end end

View File

@ -42,7 +42,7 @@ module Parfait
def self.for_hash( object_class , hash) def self.for_hash( object_class , hash)
new_type = Type.new( object_class , hash) new_type = Type.new( object_class , hash)
code = hash_code_for_hash( hash ) code = hash_code_for_hash( hash )
Space.object_space.types[code] = new_type Parfait.object_space.types[code] = new_type
new_type new_type
end end
@ -154,7 +154,7 @@ module Parfait
hash = to_hash hash = to_hash
hash[name] = type hash[name] = type
code = Type.hash_code_for_hash( hash ) code = Type.hash_code_for_hash( hash )
existing = Space.object_space.types[code] existing = Parfait.object_space.types[code]
if existing if existing
return existing return existing
else else

View File

@ -40,7 +40,7 @@ module Parfait
@name = name @name = name
@binary = BinaryCode.new 0 @binary = BinaryCode.new 0
@arguments = arguments @arguments = arguments
@locals = Type.new Space.object_space.get_class_by_name( :Object ) @locals = Type.new Parfait.object_space.get_class_by_name( :Object )
end end
def set_instructions(inst) def set_instructions(inst)

View File

@ -29,7 +29,7 @@ module Melon
def test_compile_class def test_compile_class
Compiler.compile "class TestIvar < Object ; def meth; @ivar;end; end" Compiler.compile "class TestIvar < Object ; def meth; @ivar;end; end"
itest = Parfait::Space.object_space.get_class_by_name(:TestIvar) itest = Parfait.object_space.get_class_by_name(:TestIvar)
assert itest.instance_type.names.include?(:ivar) , itest.instance_type.names.inspect assert itest.instance_type.names.include?(:ivar) , itest.instance_type.names.inspect
end end

View File

@ -9,13 +9,13 @@ module Melon
def test_creates_class_without_deriviation def test_creates_class_without_deriviation
Compiler.compile "class Testing ; end" Compiler.compile "class Testing ; end"
assert t = Parfait::Space.object_space.get_class_by_name(:Testing) , "No classes created" assert t = Parfait.object_space.get_class_by_name(:Testing) , "No classes created"
assert_equal :Object , t.super_class_name assert_equal :Object , t.super_class_name
end end
def test_creates_class_with_deriviation def test_creates_class_with_deriviation
Compiler.compile "class Test2 < List ;end" Compiler.compile "class Test2 < List ;end"
assert t = Parfait::Space.object_space.get_class_by_name(:Test2) , "No classes created" assert t = Parfait.object_space.get_class_by_name(:Test2) , "No classes created"
assert_equal :List , t.super_class_name assert_equal :List , t.super_class_name
end end

View File

@ -17,7 +17,7 @@ class TestPositioning < MiniTest::Test
assert_equal 32 , list.padded_length assert_equal 32 , list.padded_length
end end
def test_type def test_type
type = Parfait::Type.new Parfait::Space.object_space.get_class_by_name(:Object) type = Parfait::Type.new Parfait.object_space.get_class_by_name(:Object)
type.set_type( type ) type.set_type( type )
assert_equal 32 , type.padded_length assert_equal 32 , type.padded_length
end end

View File

@ -4,7 +4,7 @@ module ExpressionHelper
def check def check
Register.machine.boot unless Register.machine.booted Register.machine.boot unless Register.machine.booted
compiler = Typed::MethodCompiler.new Parfait::Space.object_space.get_main compiler = Typed::MethodCompiler.new Parfait.object_space.get_main
code = Typed.ast_to_code @input code = Typed.ast_to_code @input
assert code.to_s , @input assert code.to_s , @input
produced = compiler.process( code ) produced = compiler.process( code )
@ -15,7 +15,7 @@ module ExpressionHelper
# test hack to in place change object type # test hack to in place change object type
def add_space_field(name,type) def add_space_field(name,type)
class_type = Parfait::Space.object_space.get_class_by_name(:Space).instance_type class_type = Parfait.object_space.get_class_by_name(:Space).instance_type
class_type.send(:private_add_instance_variable, name , type) class_type.send(:private_add_instance_variable, name , type)
end end
end end

View File

@ -16,20 +16,20 @@ module Register
end end
def test_call_main_int def test_call_main_int
Parfait::Space.object_space.get_main.add_argument(:blar , :Integer) Parfait.object_space.get_main.add_argument(:blar , :Integer)
@input =s(:call,s(:name, :main),s(:arguments , s(:int, 1))) @input =s(:call,s(:name, :main),s(:arguments , s(:int, 1)))
check check
end end
def test_call_main_string def test_call_main_string
Parfait::Space.object_space.get_main.add_argument(:blar , :Word) Parfait.object_space.get_main.add_argument(:blar , :Word)
@input =s(:call,s(:name, :main),s(:arguments , s(:string, "1") )) @input =s(:call,s(:name, :main),s(:arguments , s(:string, "1") ))
check check
end end
def test_call_main_op def test_call_main_op
Parfait::Space.object_space.get_main.add_local(:bar , :Integer) Parfait.object_space.get_main.add_local(:bar , :Integer)
Parfait::Space.object_space.get_main.add_argument(:blar , :Integer) Parfait.object_space.get_main.add_argument(:blar , :Integer)
@input =s(:call,s(:name, :main),s(:arguments , s(:name, :bar) )) @input =s(:call,s(:name, :main),s(:arguments , s(:name, :bar) ))
check check
end end

View File

@ -21,12 +21,12 @@ module Register
end end
end end
def test_local_int def test_local_int
Parfait::Space.object_space.get_main.add_local(:bar , :Integer) Parfait.object_space.get_main.add_local(:bar , :Integer)
@input = s(:operator_value, :+, s(:name, :bar), s(:int, 3)) @input = s(:operator_value, :+, s(:name, :bar), s(:int, 3))
check check
end end
def test_int_local def test_int_local
Parfait::Space.object_space.get_main.add_local(:bar , :Integer) Parfait.object_space.get_main.add_local(:bar , :Integer)
@input = s(:operator_value, :+, s(:int, 3), s(:name, :bar)) @input = s(:operator_value, :+, s(:int, 3), s(:name, :bar))
check check
end end

View File

@ -10,7 +10,7 @@ module Register
end end
def test_local def test_local
Parfait::Space.object_space.get_main.add_local(:bar , :Integer) Parfait.object_space.get_main.add_local(:bar , :Integer)
@input = s(:name, :bar) @input = s(:name, :bar)
@output = Register::RegisterValue @output = Register::RegisterValue
check check
@ -24,7 +24,7 @@ module Register
end end
def test_args def test_args
Parfait::Space.object_space.get_main.add_argument(:bar , :Integer) Parfait.object_space.get_main.add_argument(:bar , :Integer)
@input = s(:name, :bar) @input = s(:name, :bar)
@output = Register::RegisterValue @output = Register::RegisterValue
check check

View File

@ -4,7 +4,7 @@ class TestAttributes < MiniTest::Test
def setup def setup
Register.machine.boot Register.machine.boot
@space = Parfait::Space.object_space @space = Parfait.object_space
@mess = @space.first_message @mess = @space.first_message
@type = @mess.get_type @type = @mess.get_type
end end

View File

@ -4,7 +4,7 @@ class TestClass < MiniTest::Test
def setup def setup
Register.machine.boot Register.machine.boot
@space = Parfait::Space.object_space @space = Parfait.object_space
@try = @space.create_class :Try , :Object @try = @space.create_class :Try , :Object
end end

View File

@ -10,10 +10,10 @@ class TestList < MiniTest::Test
assert @list.is_a? Parfait::Indexed assert @list.is_a? Parfait::Indexed
end end
def test_old_type def test_old_type
assert_equal Parfait::Type , Parfait::Space.object_space.classes.keys.get_type.class assert_equal Parfait::Type , Parfait.object_space.classes.keys.get_type.class
end end
def test_old_type_push def test_old_type_push
list = Parfait::Space.object_space.classes.keys list = Parfait.object_space.classes.keys
assert_equal Parfait::Type , list.get_type.class assert_equal Parfait::Type , list.get_type.class
end end
def test_new_type def test_new_type
@ -28,7 +28,7 @@ class TestList < MiniTest::Test
assert_equal 1 , type.variable_index(:type) assert_equal 1 , type.variable_index(:type)
end end
def notest_type_is_first_old def notest_type_is_first_old
type = Parfait::Space.object_space.classes.keys.get_type type = Parfait.object_space.classes.keys.get_type
assert_equal 1 , type.variable_index(:type) assert_equal 1 , type.variable_index(:type)
end end

View File

@ -4,7 +4,7 @@ class TestMessage < MiniTest::Test
def setup def setup
Register.machine.boot Register.machine.boot
@space = Parfait::Space.object_space @space = Parfait.object_space
@mess = @space.first_message @mess = @space.first_message
end end

View File

@ -4,7 +4,7 @@ class TestNamedLists < MiniTest::Test
def setup def setup
Register.machine.boot Register.machine.boot
@space = Parfait::Space.object_space @space = Parfait.object_space
@named_list = @space.first_message.locals @named_list = @space.first_message.locals
@type = @named_list.get_type @type = @named_list.get_type
end end

View File

@ -4,7 +4,7 @@ class TestSpace < MiniTest::Test
def setup def setup
@machine = Register.machine.boot @machine = Register.machine.boot
@space = Parfait::Space.object_space @space = Parfait.object_space
end end
def classes def classes
[:Kernel,:Word,:List,:Message,:NamedList,:Type,:Object,:Class,:Dictionary,:TypedMethod , :Integer] [:Kernel,:Word,:List,:Message,:NamedList,:Type,:Object,:Class,:Dictionary,:TypedMethod , :Integer]
@ -14,10 +14,10 @@ class TestSpace < MiniTest::Test
end end
def test_global_space def test_global_space
assert_equal Parfait::Space , Parfait::Space.object_space.class assert_equal Parfait::Space , Parfait.object_space.class
end end
def test_integer def test_integer
int = Parfait::Space.object_space.get_class_by_name :Integer int = Parfait.object_space.get_class_by_name :Integer
assert_equal 3, int.instance_type.method_names.get_length assert_equal 3, int.instance_type.method_names.get_length
end end

View File

@ -3,7 +3,7 @@ require_relative "../helper"
class TestMethod < MiniTest::Test class TestMethod < MiniTest::Test
def setup def setup
obj = Parfait::Space.object_space.get_class_by_name(:Object).instance_type obj = Parfait.object_space.get_class_by_name(:Object).instance_type
args = Parfait::Type.for_hash( obj.object_class , { bar: :Integer , foo: :Type}) args = Parfait::Type.for_hash( obj.object_class , { bar: :Integer , foo: :Type})
@method = ::Parfait::TypedMethod.new obj , :meth , args @method = ::Parfait::TypedMethod.new obj , :meth , args
@method.add_local :local_bar , :Integer @method.add_local :local_bar , :Integer

View File

@ -16,7 +16,7 @@ module Statements
code = Typed.ast_to_code( @input ) code = Typed.ast_to_code( @input )
assert code.to_s , @input assert code.to_s , @input
produced = compiler.process( code ) produced = compiler.process( code )
produced = Parfait::Space.object_space.get_main.instructions produced = Parfait.object_space.get_main.instructions
compare_instructions produced , @expect compare_instructions produced , @expect
produced produced
end end

View File

@ -5,7 +5,7 @@ class TestAssignStatement < MiniTest::Test
include Statements include Statements
def test_assign_op def test_assign_op
Parfait::Space.object_space.get_main.add_local(:r , :Integer) Parfait.object_space.get_main.add_local(:r , :Integer)
@input = s(:statements, s(:assignment, s(:name, :r), s(:operator_value, :+, s(:int, 10), s(:int, 1)))) @input = s(:statements, s(:assignment, s(:name, :r), s(:operator_value, :+, s(:int, 10), s(:int, 1))))
@ -15,7 +15,7 @@ class TestAssignStatement < MiniTest::Test
end end
def test_assign_local def test_assign_local
Parfait::Space.object_space.get_main.add_local(:r , :Integer) Parfait.object_space.get_main.add_local(:r , :Integer)
@input =s(:statements, s(:assignment, s(:name, :r), s(:int, 5))) @input =s(:statements, s(:assignment, s(:name, :r), s(:int, 5)))
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn] @expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn]
@ -23,7 +23,7 @@ class TestAssignStatement < MiniTest::Test
end end
def test_assign_local_assign def test_assign_local_assign
Parfait::Space.object_space.get_main.add_local(:r , :Integer) Parfait.object_space.get_main.add_local(:r , :Integer)
@input = s(:statements, s(:assignment, s(:name, :r), s(:int, 5))) @input = s(:statements, s(:assignment, s(:name, :r), s(:int, 5)))
@ -32,7 +32,7 @@ class TestAssignStatement < MiniTest::Test
end end
def test_assign_call def test_assign_call
Parfait::Space.object_space.get_main.add_local(:r , :Integer) Parfait.object_space.get_main.add_local(:r , :Integer)
@input = s(:statements, s(:assignment, s(:name, :r), s(:call, s(:name, :main), s(:arguments)))) @input = s(:statements, s(:assignment, s(:name, :r), s(:call, s(:name, :main), s(:arguments))))
@expect = [Label, SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, LoadConstant , @expect = [Label, SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, LoadConstant ,
SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall , SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall ,
@ -42,7 +42,7 @@ class TestAssignStatement < MiniTest::Test
end end
def test_named_list_get def test_named_list_get
Parfait::Space.object_space.get_main.add_local(:r , :Integer) Parfait.object_space.get_main.add_local(:r , :Integer)
@input = s(:statements, s(:assignment, s(:name, :r), s(:int, 5)), s(:return, s(:name, :r))) @input = s(:statements, s(:assignment, s(:name, :r), s(:int, 5)), s(:return, s(:name, :r)))
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, SlotToReg, SlotToReg, RegToSlot , @expect = [Label, LoadConstant, SlotToReg, RegToSlot, SlotToReg, SlotToReg, RegToSlot ,
Label, FunctionReturn] Label, FunctionReturn]
@ -53,7 +53,7 @@ class TestAssignStatement < MiniTest::Test
end end
def test_assign_local_int def test_assign_local_int
Parfait::Space.object_space.get_main.add_local(:r , :Integer) Parfait.object_space.get_main.add_local(:r , :Integer)
@input = s(:statements, s(:assignment, s(:name, :r), s(:int, 5)) ) @input = s(:statements, s(:assignment, s(:name, :r), s(:int, 5)) )
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn] @expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn]
was = check was = check
@ -63,14 +63,14 @@ class TestAssignStatement < MiniTest::Test
end end
def test_misassign_local def test_misassign_local
Parfait::Space.object_space.get_main.add_local(:r , :Integer) Parfait.object_space.get_main.add_local(:r , :Integer)
@input = s(:statements, s(:assignment, s(:name, :r), s(:string, "5")) ) @input = s(:statements, s(:assignment, s(:name, :r), s(:string, "5")) )
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn] @expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn]
assert_raises {check } assert_raises {check }
end end
def test_assign_arg def test_assign_arg
Parfait::Space.object_space.get_main.add_argument(:blar , :Integer) Parfait.object_space.get_main.add_argument(:blar , :Integer)
@input = s(:statements, s(:assignment, s(:name, :blar), s(:int, 5))) @input = s(:statements, s(:assignment, s(:name, :blar), s(:int, 5)))
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn] @expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn]
was = check was = check
@ -80,7 +80,7 @@ class TestAssignStatement < MiniTest::Test
end end
def test_misassign_arg def test_misassign_arg
Parfait::Space.object_space.get_main.add_argument(:blar , :Integer) Parfait.object_space.get_main.add_argument(:blar , :Integer)
@input = s(:statements, s(:assignment, s(:name, :blar), s(:string, "5"))) @input = s(:statements, s(:assignment, s(:name, :blar), s(:string, "5")))
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn] @expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn]
assert_raises {check } assert_raises {check }
@ -88,7 +88,7 @@ class TestAssignStatement < MiniTest::Test
def test_arg_get def test_arg_get
# have to define bar externally, just because redefining main. Otherwise that would be automatic # have to define bar externally, just because redefining main. Otherwise that would be automatic
Parfait::Space.object_space.get_main.add_argument(:balr , :Integer) Parfait.object_space.get_main.add_argument(:balr , :Integer)
@input = s(:statements, s(:return, s(:name, :balr))) @input = s(:statements, s(:return, s(:name, :balr)))
@expect = [Label, SlotToReg, SlotToReg, RegToSlot, Label, FunctionReturn] @expect = [Label, SlotToReg, SlotToReg, RegToSlot, Label, FunctionReturn]
was = check was = check

View File

@ -25,7 +25,7 @@ class TestCallStatement < MiniTest::Test
end end
def _test_call_local_int def _test_call_local_int
Parfait::Space.object_space.get_main.add_local(:testi , :Integer) Parfait.object_space.get_main.add_local(:testi , :Integer)
clean_compile :Integer, :putint, {}, s(:statements, s(:return, s(:int, 1))) clean_compile :Integer, :putint, {}, s(:statements, s(:return, s(:int, 1)))
@input = s(:statements, s(:assignment, s(:name, :testi), s(:int, 20)), s(:call, s(:name, :putint), s(:arguments), s(:receiver, s(:name, :testi)))) @input = s(:statements, s(:assignment, s(:name, :testi), s(:int, 20)), s(:call, s(:name, :putint), s(:arguments), s(:receiver, s(:name, :testi))))
@ -37,7 +37,7 @@ class TestCallStatement < MiniTest::Test
end end
def test_call_local_class def test_call_local_class
Parfait::Space.object_space.get_main.add_local(:test_l , :List) Parfait.object_space.get_main.add_local(:test_l , :List)
clean_compile :List, :add, {}, s(:statements, s(:return, s(:int, 1))) clean_compile :List, :add, {}, s(:statements, s(:return, s(:int, 1)))
@input =s(:statements, s(:call, s(:name, :add), s(:arguments), s(:receiver, s(:name, :test_l)))) @input =s(:statements, s(:call, s(:name, :add), s(:arguments), s(:receiver, s(:name, :test_l))))

View File

@ -6,7 +6,7 @@ module Register
include Statements include Statements
def test_field_named_list def test_field_named_list
Parfait::Space.object_space.get_main.add_local( :m , :Message) Parfait.object_space.get_main.add_local( :m , :Message)
@input = s(:statements, s(:return, s(:field_access, @input = s(:statements, s(:return, s(:field_access,
s(:receiver, s(:name, :m)), s(:field, s(:name, :name))))) s(:receiver, s(:name, :m)), s(:field, s(:name, :name)))))
@expect = [Label, SlotToReg, SlotToReg, SlotToReg, RegToSlot, Label, FunctionReturn] @expect = [Label, SlotToReg, SlotToReg, SlotToReg, RegToSlot, Label, FunctionReturn]
@ -14,7 +14,7 @@ module Register
end end
def test_field_arg def test_field_arg
Parfait::Space.object_space.get_main.add_local( :m , :Message) Parfait.object_space.get_main.add_local( :m , :Message)
clean_compile :Space, :get_name, { :main => :Message}, clean_compile :Space, :get_name, { :main => :Message},
s(:statements, s(:return, s(:field_access, s(:statements, s(:return, s(:field_access,
s(:receiver, s(:name, :main)), s(:field, s(:name, :name))))) s(:receiver, s(:name, :main)), s(:field, s(:name, :name)))))
@ -28,7 +28,7 @@ module Register
end end
def test_message_field def test_message_field
Parfait::Space.object_space.get_main.add_local(:name , :Word) Parfait.object_space.get_main.add_local(:name , :Word)
@input = s(:statements, s(:assignment, s(:name, :name), s(:field_access, s(:receiver, s(:name, :message)), s(:field, s(:name, :name)))), s(:return, s(:name, :name))) @input = s(:statements, s(:assignment, s(:name, :name), s(:field_access, s(:receiver, s(:name, :message)), s(:field, s(:name, :name)))), s(:return, s(:name, :name)))
@expect = [Label, RegisterTransfer, SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg , @expect = [Label, RegisterTransfer, SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg ,

View File

@ -11,14 +11,14 @@ class TestReturnStatement < MiniTest::Test
end end
def test_return_local def test_return_local
Parfait::Space.object_space.get_main.add_local(:runner , :Integer) Parfait.object_space.get_main.add_local(:runner , :Integer)
@input = s(:statements, s(:return, s(:name, :runner))) @input = s(:statements, s(:return, s(:name, :runner)))
@expect = [Label, SlotToReg,SlotToReg ,RegToSlot,Label,FunctionReturn] @expect = [Label, SlotToReg,SlotToReg ,RegToSlot,Label,FunctionReturn]
check check
end end
def test_return_local_assign def test_return_local_assign
Parfait::Space.object_space.get_main.add_local(:runner , :Integer) Parfait.object_space.get_main.add_local(:runner , :Integer)
@input = s(:statements, s(:assignment, s(:name, :runner), s(:int, 5)), s(:return, s(:name, :runner))) @input = s(:statements, s(:assignment, s(:name, :runner), s(:int, 5)), s(:return, s(:name, :runner)))
@expect = [Label, LoadConstant,SlotToReg,RegToSlot,SlotToReg,SlotToReg ,RegToSlot, @expect = [Label, LoadConstant,SlotToReg,RegToSlot,SlotToReg,SlotToReg ,RegToSlot,
Label,FunctionReturn] Label,FunctionReturn]
@ -34,7 +34,7 @@ class TestReturnStatement < MiniTest::Test
end end
def pest_return_space_length # need to add runtime first def pest_return_space_length # need to add runtime first
Parfait::Space.object_space.get_main.add_local(:l , :Type) Parfait.object_space.get_main.add_local(:l , :Type)
@input = s(:statements, s(:assignment, s(:name, :l), s(:call, s(:name, :get_type), s(:arguments), s(:receiver, s(:name, :space)))), s(:return, s(:field_access, s(:receiver, s(:name, :self)), s(:field, s(:name, :runner))))) @input = s(:statements, s(:assignment, s(:name, :l), s(:call, s(:name, :get_type), s(:arguments), s(:receiver, s(:name, :space)))), s(:return, s(:field_access, s(:receiver, s(:name, :self)), s(:field, s(:name, :runner)))))
@expect = [Label, SlotToReg,SlotToReg ,RegToSlot,Label,FunctionReturn] @expect = [Label, SlotToReg,SlotToReg ,RegToSlot,Label,FunctionReturn]
check check

View File

@ -14,7 +14,7 @@ module Register
end end
def test_while_assign def test_while_assign
Parfait::Space.object_space.get_main.add_local(:n , :Integer) Parfait.object_space.get_main.add_local(:n , :Integer)
@input = s(:statements, s(:assignment, s(:name, :n), s(:int, 5)), s(:while_statement, :plus, s(:conditional, s(:name, :n)), s(:statements, s(:assignment, s(:name, :n), s(:operator_value, :-, s(:name, :n), s(:int, 1))))), s(:return, s(:name, :n))) @input = s(:statements, s(:assignment, s(:name, :n), s(:int, 5)), s(:while_statement, :plus, s(:conditional, s(:name, :n)), s(:statements, s(:assignment, s(:name, :n), s(:operator_value, :-, s(:name, :n), s(:int, 1))))), s(:return, s(:name, :n)))
@ -26,7 +26,7 @@ module Register
def test_while_return def test_while_return
Parfait::Space.object_space.get_main.add_local(:n , :Integer) Parfait.object_space.get_main.add_local(:n , :Integer)
@input = s(:statements, s(:assignment, s(:name, :n), s(:int, 10)), s(:while_statement, :plus, s(:conditional, s(:operator_value, :-, s(:name, :n), s(:int, 5))), s(:statements, s(:assignment, s(:name, :n), s(:operator_value, :+, s(:name, :n), s(:int, 1))), s(:return, s(:name, :n))))) @input = s(:statements, s(:assignment, s(:name, :n), s(:int, 10)), s(:while_statement, :plus, s(:conditional, s(:operator_value, :-, s(:name, :n), s(:int, 5))), s(:statements, s(:assignment, s(:name, :n), s(:operator_value, :+, s(:name, :n), s(:int, 1))), s(:return, s(:name, :n)))))

View File

@ -4,7 +4,7 @@ class BasicType < MiniTest::Test
def setup def setup
Register.machine.boot Register.machine.boot
@space = Parfait::Space.object_space @space = Parfait.object_space
@mess = @space.first_message @mess = @space.first_message
assert @mess assert @mess
@type = @mess.get_type() @type = @mess.get_type()

View File

@ -4,7 +4,7 @@ class TypeHash < MiniTest::Test
def setup def setup
Register.machine.boot Register.machine.boot
@space = Parfait::Space.object_space @space = Parfait.object_space
@types = @space.types @types = @space.types
@first = @types.values.first @first = @types.values.first
end end

View File

@ -4,7 +4,7 @@ class TypeMessages < MiniTest::Test
def setup def setup
Register.machine.boot Register.machine.boot
@space = Parfait::Space.object_space @space = Parfait.object_space
@mess = @space.first_message @mess = @space.first_message
end end

View File

@ -4,7 +4,7 @@ class TestMethodApi < MiniTest::Test
def setup def setup
Register.machine.boot Register.machine.boot
@space = Parfait::Space.object_space @space = Parfait.object_space
@try_class = @space.create_class( :Try ) @try_class = @space.create_class( :Try )
@try_type = @try_class.instance_type @try_type = @try_class.instance_type
end end

View File

@ -4,7 +4,7 @@ class TypeApi < MiniTest::Test
def setup def setup
Register.machine.boot Register.machine.boot
@space = Parfait::Space.object_space @space = Parfait.object_space
tc = @space.get_class_by_name( :Type ) tc = @space.get_class_by_name( :Type )
@type = Parfait::Type.new tc @type = Parfait::Type.new tc
end end
@ -23,7 +23,7 @@ class TypeApi < MiniTest::Test
end end
def test_class_space def test_class_space
space = Parfait::Space.object_space space = Parfait.object_space
assert_equal Parfait::Space , space.class assert_equal Parfait::Space , space.class
type = space.get_type type = space.get_type
assert_equal Parfait::Type , type.class assert_equal Parfait::Type , type.class