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
|
||||
|
||||
# for debug add labels for labels
|
||||
Register.machine.space.types.values.each do |type|
|
||||
type.instance_methods.each do |f|
|
||||
Parfait::Space.object_space.types.values.each do |type|
|
||||
type.methods.each do |f|
|
||||
f.instructions.each_label do |label|
|
||||
add_symbol "#{clazz.name}::#{f.name}:#{label.name}" , label.position
|
||||
end
|
||||
|
@ -47,15 +47,15 @@ module Register
|
||||
# - create the Class objects and assign them to the types
|
||||
def boot_parfait!
|
||||
types = boot_types
|
||||
boot_boot_space(types)
|
||||
classes = boot_classes(types)
|
||||
fix_types(types , classes)
|
||||
boot_boot_space( types )
|
||||
classes = boot_classes( types )
|
||||
fix_types( types , classes )
|
||||
|
||||
@space = Parfait::Space.new(classes)
|
||||
Parfait::Space.set_object_space @space
|
||||
space = Parfait::Space.new( classes )
|
||||
Parfait::Space.set_object_space( space )
|
||||
|
||||
#puts Sof.write(@space)
|
||||
boot_functions!
|
||||
boot_functions!( space )
|
||||
end
|
||||
|
||||
# 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
|
||||
# implementation of the method (ie a method object), not actually try to implement it
|
||||
# (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
|
||||
# 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
|
||||
space = @space.get_class_by_name(:Space)
|
||||
space.instance_type.add_method Builtin::Space.send(:main, nil)
|
||||
space_class = space.get_class_by_name(:Space)
|
||||
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|
|
||||
obj.instance_type.add_method Builtin::Object.send(f , nil)
|
||||
end
|
||||
obj = @space.get_class_by_name(:Kernel)
|
||||
obj = space.get_class_by_name(:Kernel)
|
||||
# create __init__ main first, __init__ calls it
|
||||
[:exit , :__init__ ].each do |f|
|
||||
obj.instance_type.add_method Builtin::Kernel.send(f , nil)
|
||||
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|
|
||||
obj.instance_type.add_method Builtin::Word.send(f , nil)
|
||||
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
|
||||
obj.instance_type.add_method Builtin::Integer.send(f , nil)
|
||||
end
|
||||
|
@ -21,7 +21,7 @@ module Register
|
||||
ret_tmp = compiler.use_reg(:Label)
|
||||
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_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
|
||||
emit_syscall( compiler , :exit )
|
||||
return compiler.method
|
||||
|
@ -21,29 +21,18 @@ module Register
|
||||
@booted = false
|
||||
@constants = []
|
||||
end
|
||||
attr_reader :constants
|
||||
attr_reader :space , :class_mappings , :init , :objects , :booted
|
||||
attr_reader :constants , :init , :objects , :booted
|
||||
|
||||
# idea being that later method missing could catch translate_xxx and translate to target xxx
|
||||
# now we just instantiate ArmTranslater and pass instructions
|
||||
def translate_arm
|
||||
methods = collect_methods
|
||||
methods = Parfait::Space.object_space.collect_methods
|
||||
translate_methods( methods )
|
||||
label = @init.next
|
||||
@init = Arm::Translator.new.translate( @init )
|
||||
@init.append label
|
||||
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)
|
||||
translator = Arm::Translator.new
|
||||
methods.each do |method|
|
||||
@ -75,7 +64,7 @@ module Register
|
||||
def boot
|
||||
initialize
|
||||
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
|
||||
self
|
||||
end
|
||||
|
@ -108,7 +108,7 @@ module Typed
|
||||
# class_name and method_name are pretty clear, args are given as a ruby array
|
||||
def create_method( class_name , method_name , args = {})
|
||||
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)
|
||||
end
|
||||
|
||||
|
@ -46,7 +46,7 @@ module Typed
|
||||
when Parfait::Type
|
||||
type = me.type
|
||||
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
|
||||
raise me.inspect
|
||||
end
|
||||
|
@ -52,6 +52,23 @@ module Parfait
|
||||
@@object_space = space
|
||||
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
|
||||
kernel = get_class_by_name :Space
|
||||
kernel.instance_type.get_method :main
|
||||
|
@ -7,7 +7,7 @@ class Symbol
|
||||
true
|
||||
end
|
||||
def get_type
|
||||
l = Register.machine.space.classes[:Word].instance_type
|
||||
l = Parfait::Space.object_space.classes[:Word].instance_type
|
||||
#puts "LL #{l.class}"
|
||||
l
|
||||
end
|
||||
|
@ -4,7 +4,7 @@ module ExpressionHelper
|
||||
|
||||
def check
|
||||
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
|
||||
assert code.to_s , @input
|
||||
produced = compiler.process( code )
|
||||
@ -15,7 +15,7 @@ module ExpressionHelper
|
||||
|
||||
# test hack to in place change object 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)
|
||||
end
|
||||
end
|
||||
|
@ -16,20 +16,20 @@ module Register
|
||||
end
|
||||
|
||||
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)))
|
||||
check
|
||||
end
|
||||
|
||||
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") ))
|
||||
check
|
||||
end
|
||||
|
||||
def test_call_main_op
|
||||
Register.machine.space.get_main.add_local(:bar , :Integer)
|
||||
Register.machine.space.get_main.add_argument(:blar , :Integer)
|
||||
Parfait::Space.object_space.get_main.add_local(:bar , :Integer)
|
||||
Parfait::Space.object_space.get_main.add_argument(:blar , :Integer)
|
||||
@input =s(:call,s(:name, :main),s(:arguments , s(:name, :bar) ))
|
||||
check
|
||||
end
|
||||
|
@ -21,12 +21,12 @@ module Register
|
||||
end
|
||||
end
|
||||
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))
|
||||
check
|
||||
end
|
||||
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))
|
||||
check
|
||||
end
|
||||
|
@ -10,7 +10,7 @@ module Register
|
||||
end
|
||||
|
||||
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)
|
||||
@output = Register::RegisterValue
|
||||
check
|
||||
@ -24,7 +24,7 @@ module Register
|
||||
end
|
||||
|
||||
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)
|
||||
@output = Register::RegisterValue
|
||||
check
|
||||
|
@ -3,7 +3,9 @@ require_relative "../helper"
|
||||
class TestAttributes < MiniTest::Test
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
|
@ -3,7 +3,8 @@ require_relative "../helper"
|
||||
class TestClass < MiniTest::Test
|
||||
|
||||
def setup
|
||||
@space = Register.machine.boot.space
|
||||
Register.machine.boot
|
||||
@space = Parfait::Space.object_space
|
||||
@try = @space.create_class :Try , :Object
|
||||
end
|
||||
|
||||
|
@ -10,10 +10,10 @@ class TestList < MiniTest::Test
|
||||
assert @list.is_a? Parfait::Indexed
|
||||
end
|
||||
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
|
||||
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
|
||||
end
|
||||
def test_new_type
|
||||
@ -28,7 +28,7 @@ class TestList < MiniTest::Test
|
||||
assert_equal 1 , type.variable_index(:type)
|
||||
end
|
||||
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)
|
||||
end
|
||||
|
||||
|
@ -3,7 +3,9 @@ require_relative "../helper"
|
||||
class TestMessage < MiniTest::Test
|
||||
|
||||
def setup
|
||||
@mess = Register.machine.boot.space.first_message
|
||||
Register.machine.boot
|
||||
@space = Parfait::Space.object_space
|
||||
@mess = @space.first_message
|
||||
end
|
||||
|
||||
def test_length
|
||||
|
@ -3,7 +3,9 @@ require_relative "../helper"
|
||||
class TestNamedLists < MiniTest::Test
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
|
@ -4,6 +4,7 @@ class TestSpace < MiniTest::Test
|
||||
|
||||
def setup
|
||||
@machine = Register.machine.boot
|
||||
@space = Parfait::Space.object_space
|
||||
end
|
||||
def classes
|
||||
[:Kernel,:Word,:List,:Message,:NamedList,:Type,:Object,:Class,:Dictionary,:TypedMethod , :Integer]
|
||||
@ -11,9 +12,7 @@ class TestSpace < MiniTest::Test
|
||||
def test_booted
|
||||
assert_equal true , @machine.booted
|
||||
end
|
||||
def test_machine_space
|
||||
assert_equal Parfait::Space , @machine.space.class
|
||||
end
|
||||
|
||||
def test_global_space
|
||||
assert_equal Parfait::Space , Parfait::Space.object_space.class
|
||||
end
|
||||
@ -24,30 +23,36 @@ class TestSpace < MiniTest::Test
|
||||
|
||||
def test_classes_class
|
||||
classes.each do |name|
|
||||
assert_equal :Class , @machine.space.classes[name].get_class.name
|
||||
assert_equal Parfait::Class , @machine.space.classes[name].class
|
||||
assert_equal :Class , @space.classes[name].get_class.name
|
||||
assert_equal Parfait::Class , @space.classes[name].class
|
||||
end
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
def test_classes_type
|
||||
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
|
||||
|
||||
def test_classes_name
|
||||
classes.each do |name|
|
||||
assert_equal name , @machine.space.classes[name].name
|
||||
assert_equal name , @space.classes[name].name
|
||||
end
|
||||
end
|
||||
|
||||
def test_method_name
|
||||
classes.each do |name|
|
||||
cl = @machine.space.classes[name]
|
||||
cl = @space.classes[name]
|
||||
cl.method_names.each do |mname|
|
||||
method = cl.get_instance_method(mname)
|
||||
assert_equal mname , method.name
|
||||
@ -56,7 +61,7 @@ class TestSpace < MiniTest::Test
|
||||
end
|
||||
end
|
||||
def test_messages
|
||||
mess = @machine.space.first_message
|
||||
mess = @space.first_message
|
||||
all = []
|
||||
while mess
|
||||
all << mess
|
||||
@ -68,19 +73,19 @@ class TestSpace < MiniTest::Test
|
||||
assert_equal 50 + 1 , all.length
|
||||
end
|
||||
def test_message_vars
|
||||
mess = @machine.space.first_message
|
||||
mess = @space.first_message
|
||||
all = mess.get_instance_variables
|
||||
assert all
|
||||
assert all.include?(:next_message)
|
||||
end
|
||||
|
||||
def test_create_class
|
||||
assert @machine.space.create_class( :NewClass )
|
||||
assert @space.create_class( :NewClass )
|
||||
end
|
||||
|
||||
def test_created_class_is_stored
|
||||
@machine.space.create_class( :NewerClass )
|
||||
assert @machine.space.get_class_by_name(:NewerClass)
|
||||
@space.create_class( :NewerClass )
|
||||
assert @space.get_class_by_name(:NewerClass)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -3,7 +3,7 @@ require_relative "../helper"
|
||||
class TestMethod < MiniTest::Test
|
||||
|
||||
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})
|
||||
@method = ::Parfait::TypedMethod.new obj , :meth , args
|
||||
@method.add_local :local_bar , :Integer
|
||||
|
@ -16,7 +16,7 @@ module Statements
|
||||
code = Typed.ast_to_code( @input )
|
||||
assert code.to_s , @input
|
||||
produced = compiler.process( code )
|
||||
produced = Register.machine.space.get_main.instructions
|
||||
produced = Parfait::Space.object_space.get_main.instructions
|
||||
compare_instructions produced , @expect
|
||||
produced
|
||||
end
|
||||
|
@ -5,7 +5,7 @@ class TestAssignStatement < MiniTest::Test
|
||||
include Statements
|
||||
|
||||
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))))
|
||||
|
||||
@ -15,7 +15,7 @@ class TestAssignStatement < MiniTest::Test
|
||||
end
|
||||
|
||||
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)))
|
||||
|
||||
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn]
|
||||
@ -23,7 +23,7 @@ class TestAssignStatement < MiniTest::Test
|
||||
end
|
||||
|
||||
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)))
|
||||
|
||||
@ -32,7 +32,7 @@ class TestAssignStatement < MiniTest::Test
|
||||
end
|
||||
|
||||
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))))
|
||||
@expect = [Label, SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, LoadConstant ,
|
||||
SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall ,
|
||||
@ -42,7 +42,7 @@ class TestAssignStatement < MiniTest::Test
|
||||
end
|
||||
|
||||
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)))
|
||||
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, SlotToReg, SlotToReg, RegToSlot ,
|
||||
Label, FunctionReturn]
|
||||
@ -53,7 +53,7 @@ class TestAssignStatement < MiniTest::Test
|
||||
end
|
||||
|
||||
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)) )
|
||||
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn]
|
||||
was = check
|
||||
@ -63,14 +63,14 @@ class TestAssignStatement < MiniTest::Test
|
||||
end
|
||||
|
||||
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")) )
|
||||
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn]
|
||||
assert_raises {check }
|
||||
end
|
||||
|
||||
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)))
|
||||
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn]
|
||||
was = check
|
||||
@ -80,7 +80,7 @@ class TestAssignStatement < MiniTest::Test
|
||||
end
|
||||
|
||||
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")))
|
||||
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn]
|
||||
assert_raises {check }
|
||||
@ -88,7 +88,7 @@ class TestAssignStatement < MiniTest::Test
|
||||
|
||||
def test_arg_get
|
||||
# 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)))
|
||||
@expect = [Label, SlotToReg, SlotToReg, RegToSlot, Label, FunctionReturn]
|
||||
was = check
|
||||
|
@ -25,7 +25,7 @@ class TestCallStatement < MiniTest::Test
|
||||
end
|
||||
|
||||
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)))
|
||||
@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
|
||||
|
||||
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)))
|
||||
|
||||
@input =s(:statements, s(:call, s(:name, :add), s(:arguments), s(:receiver, s(:name, :test_l))))
|
||||
|
@ -6,7 +6,7 @@ module Register
|
||||
include Statements
|
||||
|
||||
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,
|
||||
s(:receiver, s(:name, :m)), s(:field, s(:name, :name)))))
|
||||
@expect = [Label, SlotToReg, SlotToReg, SlotToReg, RegToSlot, Label, FunctionReturn]
|
||||
@ -14,7 +14,7 @@ module Register
|
||||
end
|
||||
|
||||
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},
|
||||
s(:statements, s(:return, s(:field_access,
|
||||
s(:receiver, s(:name, :main)), s(:field, s(:name, :name)))))
|
||||
@ -28,7 +28,7 @@ module Register
|
||||
end
|
||||
|
||||
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)))
|
||||
|
||||
@expect = [Label, RegisterTransfer, SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg ,
|
||||
|
@ -11,14 +11,14 @@ class TestReturnStatement < MiniTest::Test
|
||||
end
|
||||
|
||||
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)))
|
||||
@expect = [Label, SlotToReg,SlotToReg ,RegToSlot,Label,FunctionReturn]
|
||||
check
|
||||
end
|
||||
|
||||
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)))
|
||||
@expect = [Label, LoadConstant,SlotToReg,RegToSlot,SlotToReg,SlotToReg ,RegToSlot,
|
||||
Label,FunctionReturn]
|
||||
@ -34,7 +34,7 @@ class TestReturnStatement < MiniTest::Test
|
||||
end
|
||||
|
||||
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)))))
|
||||
@expect = [Label, SlotToReg,SlotToReg ,RegToSlot,Label,FunctionReturn]
|
||||
check
|
||||
|
@ -14,7 +14,7 @@ module Register
|
||||
end
|
||||
|
||||
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)))
|
||||
|
||||
@ -26,7 +26,7 @@ module Register
|
||||
|
||||
|
||||
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)))))
|
||||
|
||||
|
@ -3,7 +3,9 @@ require_relative "../helper"
|
||||
class BasicType < MiniTest::Test
|
||||
|
||||
def setup
|
||||
@mess = Register.machine.boot.space.first_message
|
||||
Register.machine.boot
|
||||
@space = Parfait::Space.object_space
|
||||
@mess = @space.first_message
|
||||
assert @mess
|
||||
@type = @mess.get_type()
|
||||
end
|
||||
@ -36,7 +38,7 @@ class BasicType < MiniTest::Test
|
||||
|
||||
def test_type_length_index
|
||||
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)
|
||||
end
|
||||
|
||||
|
@ -3,7 +3,9 @@ require_relative "../helper"
|
||||
class TypeHash < MiniTest::Test
|
||||
|
||||
def setup
|
||||
@types = Register.machine.boot.space.types
|
||||
Register.machine.boot
|
||||
@space = Parfait::Space.object_space
|
||||
@types = @space.types
|
||||
@first = @types.values.first
|
||||
end
|
||||
|
||||
|
@ -3,7 +3,9 @@ require_relative "../helper"
|
||||
class TypeMessages < MiniTest::Test
|
||||
|
||||
def setup
|
||||
@mess = Register.machine.boot.space.first_message
|
||||
Register.machine.boot
|
||||
@space = Parfait::Space.object_space
|
||||
@mess = @space.first_message
|
||||
end
|
||||
|
||||
def test_message_type
|
||||
|
@ -3,7 +3,8 @@ require_relative "../helper"
|
||||
class TestMethodApi < MiniTest::Test
|
||||
|
||||
def setup
|
||||
@space = Register.machine.boot.space
|
||||
Register.machine.boot
|
||||
@space = Parfait::Space.object_space
|
||||
@try_class = @space.create_class( :Try )
|
||||
@try_type = @try_class.instance_type
|
||||
end
|
||||
|
@ -3,7 +3,9 @@ require_relative "../helper"
|
||||
class TypeApi < MiniTest::Test
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
@ -12,7 +14,7 @@ class TypeApi < MiniTest::Test
|
||||
end
|
||||
|
||||
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
|
||||
type = oc.instance_type
|
||||
assert_equal Parfait::Type , type.class
|
||||
@ -21,7 +23,7 @@ class TypeApi < MiniTest::Test
|
||||
end
|
||||
|
||||
def test_class_space
|
||||
space = Register.machine.space
|
||||
space = Parfait::Space.object_space
|
||||
assert_equal Parfait::Space , space.class
|
||||
type = space.get_type
|
||||
assert_equal Parfait::Type , type.class
|
||||
|
Loading…
Reference in New Issue
Block a user