remove the space instance from register machine
bad design, probably from the booting
This commit is contained in:
parent
ef872edd7a
commit
a00f6be3ba
@ -21,8 +21,8 @@ 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
|
||||||
Register.machine.space.types.values.each do |type|
|
Parfait::Space.object_space.types.values.each do |type|
|
||||||
type.instance_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
|
||||||
end
|
end
|
||||||
|
@ -47,15 +47,15 @@ module Register
|
|||||||
# - create the Class objects and assign them to the types
|
# - create the Class objects and assign them to the types
|
||||||
def boot_parfait!
|
def boot_parfait!
|
||||||
types = boot_types
|
types = boot_types
|
||||||
boot_boot_space(types)
|
boot_boot_space( types )
|
||||||
classes = boot_classes(types)
|
classes = boot_classes( types )
|
||||||
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::Space.set_object_space( space )
|
||||||
|
|
||||||
#puts Sof.write(@space)
|
#puts Sof.write(@space)
|
||||||
boot_functions!
|
boot_functions!( space )
|
||||||
end
|
end
|
||||||
|
|
||||||
# types is where the snake bites its tail. Every chain ends at a type and then it
|
# types is where the snake bites its tail. Every chain ends at a type and then it
|
||||||
@ -158,29 +158,29 @@ module Register
|
|||||||
# Methods are grabbed from respective modules by sending the method name. This should return the
|
# Methods are grabbed from respective modules by sending the method name. This should return the
|
||||||
# implementation of the method (ie a method object), not actually try to implement it
|
# implementation of the method (ie a method object), not actually try to implement it
|
||||||
# (as that's impossible in ruby)
|
# (as that's impossible in ruby)
|
||||||
def boot_functions!
|
def boot_functions!( space )
|
||||||
# very fiddly chicken 'n egg problem. Functions need to be in the right order, and in fact we
|
# very fiddly chicken 'n egg problem. Functions need to be in the right order, and in fact we
|
||||||
# have to define some dummies, just for the others to compile
|
# have to define some dummies, just for the others to compile
|
||||||
# TODO go through the virtual parfait layer and adjust function names to what they really are
|
# TODO go through the virtual parfait layer and adjust function names to what they really are
|
||||||
space = @space.get_class_by_name(:Space)
|
space_class = space.get_class_by_name(:Space)
|
||||||
space.instance_type.add_method Builtin::Space.send(:main, nil)
|
space_class.instance_type.add_method Builtin::Space.send(:main, nil)
|
||||||
|
|
||||||
obj = @space.get_class_by_name(:Object)
|
obj = space.get_class_by_name(:Object)
|
||||||
[ :get_internal_word , :set_internal_word ].each do |f|
|
[ :get_internal_word , :set_internal_word ].each do |f|
|
||||||
obj.instance_type.add_method Builtin::Object.send(f , nil)
|
obj.instance_type.add_method Builtin::Object.send(f , nil)
|
||||||
end
|
end
|
||||||
obj = @space.get_class_by_name(:Kernel)
|
obj = space.get_class_by_name(:Kernel)
|
||||||
# create __init__ main first, __init__ calls it
|
# create __init__ main first, __init__ calls it
|
||||||
[:exit , :__init__ ].each do |f|
|
[:exit , :__init__ ].each do |f|
|
||||||
obj.instance_type.add_method Builtin::Kernel.send(f , nil)
|
obj.instance_type.add_method Builtin::Kernel.send(f , nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
obj = @space.get_class_by_name(:Word)
|
obj = space.get_class_by_name(:Word)
|
||||||
[:putstring , :get_internal_byte , :set_internal_byte ].each do |f|
|
[:putstring , :get_internal_byte , :set_internal_byte ].each do |f|
|
||||||
obj.instance_type.add_method Builtin::Word.send(f , nil)
|
obj.instance_type.add_method Builtin::Word.send(f , nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
obj = @space.get_class_by_name(:Integer)
|
obj = space.get_class_by_name(:Integer)
|
||||||
[ :putint, :mod4, :div10].each do |f| #mod4 is just a forward declaration
|
[ :putint, :mod4, :div10].each do |f| #mod4 is just a forward declaration
|
||||||
obj.instance_type.add_method Builtin::Integer.send(f , nil)
|
obj.instance_type.add_method Builtin::Integer.send(f , nil)
|
||||||
end
|
end
|
||||||
|
@ -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" , Register.machine.space.get_main )
|
compiler.add_code Register.function_call( "__init__ issue call" , Parfait::Space.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
|
||||||
|
@ -21,29 +21,18 @@ module Register
|
|||||||
@booted = false
|
@booted = false
|
||||||
@constants = []
|
@constants = []
|
||||||
end
|
end
|
||||||
attr_reader :constants
|
attr_reader :constants , :init , :objects , :booted
|
||||||
attr_reader :space , :class_mappings , :init , :objects , :booted
|
|
||||||
|
|
||||||
# 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 = collect_methods
|
methods = Parfait::Space.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 )
|
||||||
@init.append label
|
@init.append label
|
||||||
end
|
end
|
||||||
|
|
||||||
def collect_methods
|
|
||||||
methods = []
|
|
||||||
self.space.types.each do |hash , t|
|
|
||||||
t.methods.each do |f|
|
|
||||||
methods << f
|
|
||||||
end
|
|
||||||
end
|
|
||||||
methods
|
|
||||||
end
|
|
||||||
|
|
||||||
def translate_methods(methods)
|
def translate_methods(methods)
|
||||||
translator = Arm::Translator.new
|
translator = Arm::Translator.new
|
||||||
methods.each do |method|
|
methods.each do |method|
|
||||||
@ -75,7 +64,7 @@ module Register
|
|||||||
def boot
|
def boot
|
||||||
initialize
|
initialize
|
||||||
boot_parfait!
|
boot_parfait!
|
||||||
@init = Branch.new( "__initial_branch__" , self.space.get_init.instructions )
|
@init = Branch.new( "__initial_branch__" , Parfait::Space.object_space.get_init.instructions )
|
||||||
@booted = true
|
@booted = true
|
||||||
self
|
self
|
||||||
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 = Register.machine.space.get_class_by_name! class_name
|
clazz = Parfait::Space.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
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ module Typed
|
|||||||
when Parfait::Type
|
when Parfait::Type
|
||||||
type = me.type
|
type = me.type
|
||||||
when Symbol
|
when Symbol
|
||||||
type = Register.machine.space.get_class_by_name(me.type).instance_type
|
type = Parfait::Space.object_space.get_class_by_name(me.type).instance_type
|
||||||
else
|
else
|
||||||
raise me.inspect
|
raise me.inspect
|
||||||
end
|
end
|
||||||
|
@ -52,6 +52,23 @@ module Parfait
|
|||||||
@@object_space = space
|
@@object_space = space
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def each_type
|
||||||
|
@types.values.each do |type|
|
||||||
|
yield(type)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# all methods form all types
|
||||||
|
def collect_methods
|
||||||
|
methods = []
|
||||||
|
each_type do | type |
|
||||||
|
type.methods.each do |meth|
|
||||||
|
methods << meth
|
||||||
|
end
|
||||||
|
end
|
||||||
|
methods
|
||||||
|
end
|
||||||
|
|
||||||
def get_main
|
def get_main
|
||||||
kernel = get_class_by_name :Space
|
kernel = get_class_by_name :Space
|
||||||
kernel.instance_type.get_method :main
|
kernel.instance_type.get_method :main
|
||||||
|
@ -7,7 +7,7 @@ class Symbol
|
|||||||
true
|
true
|
||||||
end
|
end
|
||||||
def get_type
|
def get_type
|
||||||
l = Register.machine.space.classes[:Word].instance_type
|
l = Parfait::Space.object_space.classes[:Word].instance_type
|
||||||
#puts "LL #{l.class}"
|
#puts "LL #{l.class}"
|
||||||
l
|
l
|
||||||
end
|
end
|
||||||
|
@ -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 Register.machine.space.get_main
|
compiler = Typed::MethodCompiler.new Parfait::Space.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 = Register.machine.space.get_class_by_name(:Space).instance_type
|
class_type = Parfait::Space.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
|
||||||
|
@ -16,20 +16,20 @@ module Register
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_call_main_int
|
def test_call_main_int
|
||||||
Register.machine.space.get_main.add_argument(:blar , :Integer)
|
Parfait::Space.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
|
||||||
Register.machine.space.get_main.add_argument(:blar , :Word)
|
Parfait::Space.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
|
||||||
Register.machine.space.get_main.add_local(:bar , :Integer)
|
Parfait::Space.object_space.get_main.add_local(:bar , :Integer)
|
||||||
Register.machine.space.get_main.add_argument(:blar , :Integer)
|
Parfait::Space.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
|
||||||
|
@ -21,12 +21,12 @@ module Register
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
def test_local_int
|
def test_local_int
|
||||||
Register.machine.space.get_main.add_local(:bar , :Integer)
|
Parfait::Space.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
|
||||||
Register.machine.space.get_main.add_local(:bar , :Integer)
|
Parfait::Space.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
|
||||||
|
@ -10,7 +10,7 @@ module Register
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_local
|
def test_local
|
||||||
Register.machine.space.get_main.add_local(:bar , :Integer)
|
Parfait::Space.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
|
||||||
Register.machine.space.get_main.add_argument(:bar , :Integer)
|
Parfait::Space.object_space.get_main.add_argument(:bar , :Integer)
|
||||||
@input = s(:name, :bar)
|
@input = s(:name, :bar)
|
||||||
@output = Register::RegisterValue
|
@output = Register::RegisterValue
|
||||||
check
|
check
|
||||||
|
@ -3,7 +3,9 @@ require_relative "../helper"
|
|||||||
class TestAttributes < MiniTest::Test
|
class TestAttributes < MiniTest::Test
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@mess = Register.machine.boot.space.first_message
|
Register.machine.boot
|
||||||
|
@space = Parfait::Space.object_space
|
||||||
|
@mess = @space.first_message
|
||||||
@type = @mess.get_type
|
@type = @mess.get_type
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -3,7 +3,8 @@ require_relative "../helper"
|
|||||||
class TestClass < MiniTest::Test
|
class TestClass < MiniTest::Test
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@space = Register.machine.boot.space
|
Register.machine.boot
|
||||||
|
@space = Parfait::Space.object_space
|
||||||
@try = @space.create_class :Try , :Object
|
@try = @space.create_class :Try , :Object
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -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 , Register.machine.space.classes.keys.get_type.class
|
assert_equal Parfait::Type , Parfait::Space.object_space.classes.keys.get_type.class
|
||||||
end
|
end
|
||||||
def test_old_type_push
|
def test_old_type_push
|
||||||
list = Register.machine.space.classes.keys
|
list = Parfait::Space.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 = Register.machine.space.classes.keys.get_type
|
type = Parfait::Space.object_space.classes.keys.get_type
|
||||||
assert_equal 1 , type.variable_index(:type)
|
assert_equal 1 , type.variable_index(:type)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -3,7 +3,9 @@ require_relative "../helper"
|
|||||||
class TestMessage < MiniTest::Test
|
class TestMessage < MiniTest::Test
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@mess = Register.machine.boot.space.first_message
|
Register.machine.boot
|
||||||
|
@space = Parfait::Space.object_space
|
||||||
|
@mess = @space.first_message
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_length
|
def test_length
|
||||||
|
@ -3,7 +3,9 @@ require_relative "../helper"
|
|||||||
class TestNamedLists < MiniTest::Test
|
class TestNamedLists < MiniTest::Test
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@named_list = Register.machine.boot.space.first_message.locals
|
Register.machine.boot
|
||||||
|
@space = Parfait::Space.object_space
|
||||||
|
@named_list = @space.first_message.locals
|
||||||
@type = @named_list.get_type
|
@type = @named_list.get_type
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ class TestSpace < MiniTest::Test
|
|||||||
|
|
||||||
def setup
|
def setup
|
||||||
@machine = Register.machine.boot
|
@machine = Register.machine.boot
|
||||||
|
@space = Parfait::Space.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]
|
||||||
@ -11,9 +12,7 @@ class TestSpace < MiniTest::Test
|
|||||||
def test_booted
|
def test_booted
|
||||||
assert_equal true , @machine.booted
|
assert_equal true , @machine.booted
|
||||||
end
|
end
|
||||||
def test_machine_space
|
|
||||||
assert_equal Parfait::Space , @machine.space.class
|
|
||||||
end
|
|
||||||
def test_global_space
|
def test_global_space
|
||||||
assert_equal Parfait::Space , Parfait::Space.object_space.class
|
assert_equal Parfait::Space , Parfait::Space.object_space.class
|
||||||
end
|
end
|
||||||
@ -24,30 +23,36 @@ class TestSpace < MiniTest::Test
|
|||||||
|
|
||||||
def test_classes_class
|
def test_classes_class
|
||||||
classes.each do |name|
|
classes.each do |name|
|
||||||
assert_equal :Class , @machine.space.classes[name].get_class.name
|
assert_equal :Class , @space.classes[name].get_class.name
|
||||||
assert_equal Parfait::Class , @machine.space.classes[name].class
|
assert_equal Parfait::Class , @space.classes[name].class
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_types
|
def test_types
|
||||||
assert @machine.space.types.is_a? Parfait::Dictionary
|
assert @space.types.is_a? Parfait::Dictionary
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_types_each
|
||||||
|
@space.each_type do |type|
|
||||||
|
assert type.is_a?(Parfait::Type)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_classes_type
|
def test_classes_type
|
||||||
classes.each do |name|
|
classes.each do |name|
|
||||||
assert_equal Parfait::Type , @machine.space.classes[name].get_type.class
|
assert_equal Parfait::Type , @space.classes[name].get_type.class
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_classes_name
|
def test_classes_name
|
||||||
classes.each do |name|
|
classes.each do |name|
|
||||||
assert_equal name , @machine.space.classes[name].name
|
assert_equal name , @space.classes[name].name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_method_name
|
def test_method_name
|
||||||
classes.each do |name|
|
classes.each do |name|
|
||||||
cl = @machine.space.classes[name]
|
cl = @space.classes[name]
|
||||||
cl.method_names.each do |mname|
|
cl.method_names.each do |mname|
|
||||||
method = cl.get_instance_method(mname)
|
method = cl.get_instance_method(mname)
|
||||||
assert_equal mname , method.name
|
assert_equal mname , method.name
|
||||||
@ -56,7 +61,7 @@ class TestSpace < MiniTest::Test
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
def test_messages
|
def test_messages
|
||||||
mess = @machine.space.first_message
|
mess = @space.first_message
|
||||||
all = []
|
all = []
|
||||||
while mess
|
while mess
|
||||||
all << mess
|
all << mess
|
||||||
@ -68,19 +73,19 @@ class TestSpace < MiniTest::Test
|
|||||||
assert_equal 50 + 1 , all.length
|
assert_equal 50 + 1 , all.length
|
||||||
end
|
end
|
||||||
def test_message_vars
|
def test_message_vars
|
||||||
mess = @machine.space.first_message
|
mess = @space.first_message
|
||||||
all = mess.get_instance_variables
|
all = mess.get_instance_variables
|
||||||
assert all
|
assert all
|
||||||
assert all.include?(:next_message)
|
assert all.include?(:next_message)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_create_class
|
def test_create_class
|
||||||
assert @machine.space.create_class( :NewClass )
|
assert @space.create_class( :NewClass )
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_created_class_is_stored
|
def test_created_class_is_stored
|
||||||
@machine.space.create_class( :NewerClass )
|
@space.create_class( :NewerClass )
|
||||||
assert @machine.space.get_class_by_name(:NewerClass)
|
assert @space.get_class_by_name(:NewerClass)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -3,7 +3,7 @@ require_relative "../helper"
|
|||||||
class TestMethod < MiniTest::Test
|
class TestMethod < MiniTest::Test
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
obj = Register.machine.space.get_class_by_name(:Object).instance_type
|
obj = Parfait::Space.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
|
||||||
|
@ -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 = Register.machine.space.get_main.instructions
|
produced = Parfait::Space.object_space.get_main.instructions
|
||||||
compare_instructions produced , @expect
|
compare_instructions produced , @expect
|
||||||
produced
|
produced
|
||||||
end
|
end
|
||||||
|
@ -5,7 +5,7 @@ class TestAssignStatement < MiniTest::Test
|
|||||||
include Statements
|
include Statements
|
||||||
|
|
||||||
def test_assign_op
|
def test_assign_op
|
||||||
Register.machine.space.get_main.add_local(:r , :Integer)
|
Parfait::Space.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
|
||||||
Register.machine.space.get_main.add_local(:r , :Integer)
|
Parfait::Space.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
|
||||||
Register.machine.space.get_main.add_local(:r , :Integer)
|
Parfait::Space.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
|
||||||
Register.machine.space.get_main.add_local(:r , :Integer)
|
Parfait::Space.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
|
||||||
Register.machine.space.get_main.add_local(:r , :Integer)
|
Parfait::Space.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
|
||||||
Register.machine.space.get_main.add_local(:r , :Integer)
|
Parfait::Space.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
|
||||||
Register.machine.space.get_main.add_local(:r , :Integer)
|
Parfait::Space.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
|
||||||
Register.machine.space.get_main.add_argument(:blar , :Integer)
|
Parfait::Space.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
|
||||||
Register.machine.space.get_main.add_argument(:blar , :Integer)
|
Parfait::Space.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
|
||||||
Register.machine.space.get_main.add_argument(:balr , :Integer)
|
Parfait::Space.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
|
||||||
|
@ -25,7 +25,7 @@ class TestCallStatement < MiniTest::Test
|
|||||||
end
|
end
|
||||||
|
|
||||||
def _test_call_local_int
|
def _test_call_local_int
|
||||||
Register.machine.space.get_main.add_local(:testi , :Integer)
|
Parfait::Space.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
|
||||||
Register.machine.space.get_main.add_local(:test_l , :List)
|
Parfait::Space.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))))
|
||||||
|
@ -6,7 +6,7 @@ module Register
|
|||||||
include Statements
|
include Statements
|
||||||
|
|
||||||
def test_field_named_list
|
def test_field_named_list
|
||||||
Register.machine.space.get_main.add_local( :m , :Message)
|
Parfait::Space.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
|
||||||
Register.machine.space.get_main.add_local( :m , :Message)
|
Parfait::Space.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
|
||||||
Register.machine.space.get_main.add_local(:name , :Word)
|
Parfait::Space.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 ,
|
||||||
|
@ -11,14 +11,14 @@ class TestReturnStatement < MiniTest::Test
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_return_local
|
def test_return_local
|
||||||
Register.machine.space.get_main.add_local(:runner , :Integer)
|
Parfait::Space.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
|
||||||
Register.machine.space.get_main.add_local(:runner , :Integer)
|
Parfait::Space.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
|
||||||
Register.machine.space.get_main.add_local(:l , :Type)
|
Parfait::Space.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
|
||||||
|
@ -14,7 +14,7 @@ module Register
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_while_assign
|
def test_while_assign
|
||||||
Register.machine.space.get_main.add_local(:n , :Integer)
|
Parfait::Space.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
|
||||||
Register.machine.space.get_main.add_local(:n , :Integer)
|
Parfait::Space.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)))))
|
||||||
|
|
||||||
|
@ -3,7 +3,9 @@ require_relative "../helper"
|
|||||||
class BasicType < MiniTest::Test
|
class BasicType < MiniTest::Test
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@mess = Register.machine.boot.space.first_message
|
Register.machine.boot
|
||||||
|
@space = Parfait::Space.object_space
|
||||||
|
@mess = @space.first_message
|
||||||
assert @mess
|
assert @mess
|
||||||
@type = @mess.get_type()
|
@type = @mess.get_type()
|
||||||
end
|
end
|
||||||
@ -36,7 +38,7 @@ class BasicType < MiniTest::Test
|
|||||||
|
|
||||||
def test_type_length_index
|
def test_type_length_index
|
||||||
type = @mess.get_type.get_type
|
type = @mess.get_type.get_type
|
||||||
assert_equal 5 , type.variable_index(:instance_methods)
|
assert_equal 5 , type.variable_index(:methods)
|
||||||
assert_equal type.object_class , type.get_internal_word(4)
|
assert_equal type.object_class , type.get_internal_word(4)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -3,7 +3,9 @@ require_relative "../helper"
|
|||||||
class TypeHash < MiniTest::Test
|
class TypeHash < MiniTest::Test
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@types = Register.machine.boot.space.types
|
Register.machine.boot
|
||||||
|
@space = Parfait::Space.object_space
|
||||||
|
@types = @space.types
|
||||||
@first = @types.values.first
|
@first = @types.values.first
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -3,7 +3,9 @@ require_relative "../helper"
|
|||||||
class TypeMessages < MiniTest::Test
|
class TypeMessages < MiniTest::Test
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@mess = Register.machine.boot.space.first_message
|
Register.machine.boot
|
||||||
|
@space = Parfait::Space.object_space
|
||||||
|
@mess = @space.first_message
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_message_type
|
def test_message_type
|
||||||
|
@ -3,7 +3,8 @@ require_relative "../helper"
|
|||||||
class TestMethodApi < MiniTest::Test
|
class TestMethodApi < MiniTest::Test
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@space = Register.machine.boot.space
|
Register.machine.boot
|
||||||
|
@space = Parfait::Space.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
|
||||||
|
@ -3,7 +3,9 @@ require_relative "../helper"
|
|||||||
class TypeApi < MiniTest::Test
|
class TypeApi < MiniTest::Test
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
tc = Register.machine.boot.space.get_class_by_name( :Type )
|
Register.machine.boot
|
||||||
|
@space = Parfait::Space.object_space
|
||||||
|
tc = @space.get_class_by_name( :Type )
|
||||||
@type = Parfait::Type.new tc
|
@type = Parfait::Type.new tc
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -12,7 +14,7 @@ class TypeApi < MiniTest::Test
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_class_type
|
def test_class_type
|
||||||
oc = Register.machine.boot.space.get_class_by_name( :Object )
|
oc = @space.get_class_by_name( :Object )
|
||||||
assert_equal Parfait::Class , oc.class
|
assert_equal Parfait::Class , oc.class
|
||||||
type = oc.instance_type
|
type = oc.instance_type
|
||||||
assert_equal Parfait::Type , type.class
|
assert_equal Parfait::Type , type.class
|
||||||
@ -21,7 +23,7 @@ class TypeApi < MiniTest::Test
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_class_space
|
def test_class_space
|
||||||
space = Register.machine.space
|
space = Parfait::Space.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
|
||||||
|
Loading…
Reference in New Issue
Block a user