Move the space instance to the parfait module
A better fit, maybe even a pattern for singletons
This commit is contained in:
parent
a00f6be3ba
commit
f0350601a7
@ -21,7 +21,7 @@ module Elf
|
||||
set_text assembler.write_as_string
|
||||
|
||||
# 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|
|
||||
f.instructions.each_label do |label|
|
||||
add_symbol "#{clazz.name}::#{f.name}:#{label.name}" , label.position
|
||||
|
@ -21,7 +21,7 @@ module Melon
|
||||
|
||||
def on_class 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)
|
||||
clazz.set_instance_type( Parfait::Type.for_hash( clazz , ivar_hash ) )
|
||||
|
||||
|
@ -21,7 +21,7 @@ module Melon
|
||||
private
|
||||
|
||||
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|
|
||||
type = type.add_instance_variable( arg.children[0] , :Object )
|
||||
end
|
||||
@ -30,7 +30,7 @@ module Melon
|
||||
|
||||
def make_locals(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 |
|
||||
type = type.add_instance_variable( name , local_type )
|
||||
end
|
||||
|
@ -52,7 +52,7 @@ module Register
|
||||
fix_types( types , classes )
|
||||
|
||||
space = Parfait::Space.new( classes )
|
||||
Parfait::Space.set_object_space( space )
|
||||
Parfait.set_object_space( space )
|
||||
|
||||
#puts Sof.write(@space)
|
||||
boot_functions!( space )
|
||||
@ -91,7 +91,7 @@ module Register
|
||||
clazz = BootClass.new(type)
|
||||
boot_space.classes[name] = clazz
|
||||
end
|
||||
Parfait::Space.set_object_space boot_space
|
||||
Parfait.set_object_space boot_space
|
||||
end
|
||||
|
||||
# superclasses other than default object
|
||||
|
@ -11,7 +11,7 @@ module Register
|
||||
compiler.method.set_instructions( 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
|
||||
compiler.add_load_constant("__init__ load Space", space , space_reg)
|
||||
message_ind = Register.resolve_to_index( :space , :first_message )
|
||||
@ -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" , 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
|
||||
emit_syscall( compiler , :exit )
|
||||
return compiler.method
|
||||
|
@ -4,7 +4,7 @@ module Register
|
||||
module Collector
|
||||
def collect
|
||||
self.objects.clear
|
||||
keep Parfait::Space.object_space , 0
|
||||
keep Parfait.object_space , 0
|
||||
constants.each {|o| keep(o,0)}
|
||||
end
|
||||
|
||||
|
@ -26,7 +26,7 @@ module Register
|
||||
# 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 = Parfait::Space.object_space.collect_methods
|
||||
methods = Parfait.object_space.collect_methods
|
||||
translate_methods( methods )
|
||||
label = @init.next
|
||||
@init = Arm::Translator.new.translate( @init )
|
||||
@ -64,7 +64,7 @@ module Register
|
||||
def boot
|
||||
initialize
|
||||
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
|
||||
self
|
||||
end
|
||||
|
@ -85,7 +85,7 @@ module Register
|
||||
def self.resolve_to_index( clazz_name , instance_name )
|
||||
return instance_name unless instance_name.is_a? Symbol
|
||||
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
|
||||
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)
|
||||
|
@ -71,7 +71,7 @@ module Typed
|
||||
@method = method
|
||||
@type = method.for_type
|
||||
else
|
||||
@type = Parfait::Space.object_space.get_type()
|
||||
@type = Parfait.object_space.get_type()
|
||||
@method = @type.get_method( :main )
|
||||
@method = @type.create_method( :main ,{}) unless @method
|
||||
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 = 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)
|
||||
end
|
||||
|
||||
|
@ -46,7 +46,7 @@ module Typed
|
||||
when Parfait::Type
|
||||
type = me.type
|
||||
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
|
||||
raise me.inspect
|
||||
end
|
||||
|
@ -7,7 +7,7 @@ module Typed
|
||||
|
||||
type = receiver.type
|
||||
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
|
||||
field_name = statement.field.name
|
||||
|
||||
|
@ -45,7 +45,7 @@ module Typed
|
||||
end
|
||||
|
||||
def load_special_space(statement)
|
||||
space = Parfait::Space.object_space
|
||||
space = Parfait.object_space
|
||||
reg = use_reg :Space , space
|
||||
add_load_constant( "#{statement} load space", space , reg )
|
||||
return reg
|
||||
|
@ -45,7 +45,7 @@ module Parfait
|
||||
|
||||
def super_class
|
||||
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
|
||||
s
|
||||
end
|
||||
|
@ -23,7 +23,7 @@ module Parfait
|
||||
object = self.allocate
|
||||
|
||||
# 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
|
||||
object.set_type cl.instance_type
|
||||
|
@ -9,6 +9,16 @@
|
||||
# recycles objects.
|
||||
|
||||
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
|
||||
# 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
|
||||
|
||||
# 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
|
||||
@types.values.each do |type|
|
||||
yield(type)
|
||||
|
@ -7,7 +7,7 @@ class Symbol
|
||||
true
|
||||
end
|
||||
def get_type
|
||||
l = Parfait::Space.object_space.classes[:Word].instance_type
|
||||
l = Parfait.object_space.classes[:Word].instance_type
|
||||
#puts "LL #{l.class}"
|
||||
l
|
||||
end
|
||||
|
@ -42,7 +42,7 @@ module Parfait
|
||||
def self.for_hash( object_class , hash)
|
||||
new_type = Type.new( object_class , hash)
|
||||
code = hash_code_for_hash( hash )
|
||||
Space.object_space.types[code] = new_type
|
||||
Parfait.object_space.types[code] = new_type
|
||||
new_type
|
||||
end
|
||||
|
||||
@ -154,7 +154,7 @@ module Parfait
|
||||
hash = to_hash
|
||||
hash[name] = type
|
||||
code = Type.hash_code_for_hash( hash )
|
||||
existing = Space.object_space.types[code]
|
||||
existing = Parfait.object_space.types[code]
|
||||
if existing
|
||||
return existing
|
||||
else
|
||||
|
@ -40,7 +40,7 @@ module Parfait
|
||||
@name = name
|
||||
@binary = BinaryCode.new 0
|
||||
@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
|
||||
|
||||
def set_instructions(inst)
|
||||
|
@ -29,7 +29,7 @@ module Melon
|
||||
|
||||
def test_compile_class
|
||||
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
|
||||
end
|
||||
|
||||
|
@ -9,13 +9,13 @@ module Melon
|
||||
|
||||
def test_creates_class_without_deriviation
|
||||
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
|
||||
end
|
||||
|
||||
def test_creates_class_with_deriviation
|
||||
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
|
||||
end
|
||||
|
||||
|
@ -17,7 +17,7 @@ class TestPositioning < MiniTest::Test
|
||||
assert_equal 32 , list.padded_length
|
||||
end
|
||||
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 )
|
||||
assert_equal 32 , type.padded_length
|
||||
end
|
||||
|
@ -4,7 +4,7 @@ module ExpressionHelper
|
||||
|
||||
def check
|
||||
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
|
||||
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 = 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)
|
||||
end
|
||||
end
|
||||
|
@ -16,20 +16,20 @@ module Register
|
||||
end
|
||||
|
||||
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)))
|
||||
check
|
||||
end
|
||||
|
||||
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") ))
|
||||
check
|
||||
end
|
||||
|
||||
def test_call_main_op
|
||||
Parfait::Space.object_space.get_main.add_local(:bar , :Integer)
|
||||
Parfait::Space.object_space.get_main.add_argument(:blar , :Integer)
|
||||
Parfait.object_space.get_main.add_local(:bar , :Integer)
|
||||
Parfait.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
|
||||
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))
|
||||
check
|
||||
end
|
||||
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))
|
||||
check
|
||||
end
|
||||
|
@ -10,7 +10,7 @@ module Register
|
||||
end
|
||||
|
||||
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)
|
||||
@output = Register::RegisterValue
|
||||
check
|
||||
@ -24,7 +24,7 @@ module Register
|
||||
end
|
||||
|
||||
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)
|
||||
@output = Register::RegisterValue
|
||||
check
|
||||
|
@ -4,7 +4,7 @@ class TestAttributes < MiniTest::Test
|
||||
|
||||
def setup
|
||||
Register.machine.boot
|
||||
@space = Parfait::Space.object_space
|
||||
@space = Parfait.object_space
|
||||
@mess = @space.first_message
|
||||
@type = @mess.get_type
|
||||
end
|
||||
|
@ -4,7 +4,7 @@ class TestClass < MiniTest::Test
|
||||
|
||||
def setup
|
||||
Register.machine.boot
|
||||
@space = Parfait::Space.object_space
|
||||
@space = Parfait.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 , Parfait::Space.object_space.classes.keys.get_type.class
|
||||
assert_equal Parfait::Type , Parfait.object_space.classes.keys.get_type.class
|
||||
end
|
||||
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
|
||||
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 = Parfait::Space.object_space.classes.keys.get_type
|
||||
type = Parfait.object_space.classes.keys.get_type
|
||||
assert_equal 1 , type.variable_index(:type)
|
||||
end
|
||||
|
||||
|
@ -4,7 +4,7 @@ class TestMessage < MiniTest::Test
|
||||
|
||||
def setup
|
||||
Register.machine.boot
|
||||
@space = Parfait::Space.object_space
|
||||
@space = Parfait.object_space
|
||||
@mess = @space.first_message
|
||||
end
|
||||
|
||||
|
@ -4,7 +4,7 @@ class TestNamedLists < MiniTest::Test
|
||||
|
||||
def setup
|
||||
Register.machine.boot
|
||||
@space = Parfait::Space.object_space
|
||||
@space = Parfait.object_space
|
||||
@named_list = @space.first_message.locals
|
||||
@type = @named_list.get_type
|
||||
end
|
||||
|
@ -4,7 +4,7 @@ class TestSpace < MiniTest::Test
|
||||
|
||||
def setup
|
||||
@machine = Register.machine.boot
|
||||
@space = Parfait::Space.object_space
|
||||
@space = Parfait.object_space
|
||||
end
|
||||
def classes
|
||||
[:Kernel,:Word,:List,:Message,:NamedList,:Type,:Object,:Class,:Dictionary,:TypedMethod , :Integer]
|
||||
@ -14,10 +14,10 @@ class TestSpace < MiniTest::Test
|
||||
end
|
||||
|
||||
def test_global_space
|
||||
assert_equal Parfait::Space , Parfait::Space.object_space.class
|
||||
assert_equal Parfait::Space , Parfait.object_space.class
|
||||
end
|
||||
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
|
||||
end
|
||||
|
||||
|
@ -3,7 +3,7 @@ require_relative "../helper"
|
||||
class TestMethod < MiniTest::Test
|
||||
|
||||
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})
|
||||
@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 = Parfait::Space.object_space.get_main.instructions
|
||||
produced = Parfait.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
|
||||
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))))
|
||||
|
||||
@ -15,7 +15,7 @@ class TestAssignStatement < MiniTest::Test
|
||||
end
|
||||
|
||||
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)))
|
||||
|
||||
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn]
|
||||
@ -23,7 +23,7 @@ class TestAssignStatement < MiniTest::Test
|
||||
end
|
||||
|
||||
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)))
|
||||
|
||||
@ -32,7 +32,7 @@ class TestAssignStatement < MiniTest::Test
|
||||
end
|
||||
|
||||
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))))
|
||||
@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
|
||||
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)))
|
||||
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, SlotToReg, SlotToReg, RegToSlot ,
|
||||
Label, FunctionReturn]
|
||||
@ -53,7 +53,7 @@ class TestAssignStatement < MiniTest::Test
|
||||
end
|
||||
|
||||
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)) )
|
||||
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn]
|
||||
was = check
|
||||
@ -63,14 +63,14 @@ class TestAssignStatement < MiniTest::Test
|
||||
end
|
||||
|
||||
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")) )
|
||||
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn]
|
||||
assert_raises {check }
|
||||
end
|
||||
|
||||
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)))
|
||||
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn]
|
||||
was = check
|
||||
@ -80,7 +80,7 @@ class TestAssignStatement < MiniTest::Test
|
||||
end
|
||||
|
||||
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")))
|
||||
@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
|
||||
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)))
|
||||
@expect = [Label, SlotToReg, SlotToReg, RegToSlot, Label, FunctionReturn]
|
||||
was = check
|
||||
|
@ -25,7 +25,7 @@ class TestCallStatement < MiniTest::Test
|
||||
end
|
||||
|
||||
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)))
|
||||
@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
|
||||
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)))
|
||||
|
||||
@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
|
||||
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,
|
||||
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
|
||||
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},
|
||||
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
|
||||
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)))
|
||||
|
||||
@expect = [Label, RegisterTransfer, SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg ,
|
||||
|
@ -11,14 +11,14 @@ class TestReturnStatement < MiniTest::Test
|
||||
end
|
||||
|
||||
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)))
|
||||
@expect = [Label, SlotToReg,SlotToReg ,RegToSlot,Label,FunctionReturn]
|
||||
check
|
||||
end
|
||||
|
||||
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)))
|
||||
@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
|
||||
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)))))
|
||||
@expect = [Label, SlotToReg,SlotToReg ,RegToSlot,Label,FunctionReturn]
|
||||
check
|
||||
|
@ -14,7 +14,7 @@ module Register
|
||||
end
|
||||
|
||||
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)))
|
||||
|
||||
@ -26,7 +26,7 @@ module Register
|
||||
|
||||
|
||||
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)))))
|
||||
|
||||
|
@ -4,7 +4,7 @@ class BasicType < MiniTest::Test
|
||||
|
||||
def setup
|
||||
Register.machine.boot
|
||||
@space = Parfait::Space.object_space
|
||||
@space = Parfait.object_space
|
||||
@mess = @space.first_message
|
||||
assert @mess
|
||||
@type = @mess.get_type()
|
||||
|
@ -4,7 +4,7 @@ class TypeHash < MiniTest::Test
|
||||
|
||||
def setup
|
||||
Register.machine.boot
|
||||
@space = Parfait::Space.object_space
|
||||
@space = Parfait.object_space
|
||||
@types = @space.types
|
||||
@first = @types.values.first
|
||||
end
|
||||
|
@ -4,7 +4,7 @@ class TypeMessages < MiniTest::Test
|
||||
|
||||
def setup
|
||||
Register.machine.boot
|
||||
@space = Parfait::Space.object_space
|
||||
@space = Parfait.object_space
|
||||
@mess = @space.first_message
|
||||
end
|
||||
|
||||
|
@ -4,7 +4,7 @@ class TestMethodApi < MiniTest::Test
|
||||
|
||||
def setup
|
||||
Register.machine.boot
|
||||
@space = Parfait::Space.object_space
|
||||
@space = Parfait.object_space
|
||||
@try_class = @space.create_class( :Try )
|
||||
@try_type = @try_class.instance_type
|
||||
end
|
||||
|
@ -4,7 +4,7 @@ class TypeApi < MiniTest::Test
|
||||
|
||||
def setup
|
||||
Register.machine.boot
|
||||
@space = Parfait::Space.object_space
|
||||
@space = Parfait.object_space
|
||||
tc = @space.get_class_by_name( :Type )
|
||||
@type = Parfait::Type.new tc
|
||||
end
|
||||
@ -23,7 +23,7 @@ class TypeApi < MiniTest::Test
|
||||
end
|
||||
|
||||
def test_class_space
|
||||
space = Parfait::Space.object_space
|
||||
space = Parfait.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