rename locals to frame
This commit is contained in:
parent
7db329fa6b
commit
559a797100
@ -78,14 +78,14 @@ module Parfait
|
||||
end
|
||||
|
||||
def frame_length
|
||||
locals.instance_length - 1
|
||||
frame.instance_length - 1
|
||||
end
|
||||
|
||||
def locals_name( index )
|
||||
frame.names.get(index + 1)
|
||||
end
|
||||
|
||||
def locals_type( index )
|
||||
def frame_type( index )
|
||||
frame.types.get(index + 1)
|
||||
end
|
||||
|
||||
|
@ -14,11 +14,11 @@ module Parfait
|
||||
|
||||
attr_reader :name , :args_type , :frame_type , :source
|
||||
|
||||
def initialize(name , args_type , locals_type , source )
|
||||
@name , @args_type , @locals_type , @source = name , args_type, locals_type , source
|
||||
def initialize(name , args_type , frame_type , source )
|
||||
@name , @args_type , @frame_type , @source = name , args_type, frame_type , source
|
||||
raise "Name must be symbol" unless name.is_a?(Symbol)
|
||||
raise "args_type must be type" unless args_type.is_a?(Parfait::Type)
|
||||
raise "locals_type must be type" unless locals_type.is_a?(Parfait::Type)
|
||||
raise "frame_type must be type" unless frame_type.is_a?(Parfait::Type)
|
||||
raise "source must be vool" unless source.is_a?(Vool::Statement)
|
||||
end
|
||||
|
||||
@ -28,12 +28,12 @@ module Parfait
|
||||
|
||||
def create_parfait_method( type )
|
||||
raise "create_method #{type.inspect} is not a Type" unless type.is_a? Parfait::Type
|
||||
type.create_method( @name , @args_type )#FIXME, @locals_type)
|
||||
type.create_method( @name , @args_type )#FIXME, @frame_type)
|
||||
end
|
||||
|
||||
def create_tmp
|
||||
tmp_name = "tmp_#{@locals_type.instance_length}".to_sym
|
||||
@locals_type = @locals_type.add_instance_variable( tmp_name , :Object )
|
||||
tmp_name = "tmp_#{@frame_type.instance_length}".to_sym
|
||||
@frame_type = @frame_type.add_instance_variable( tmp_name , :Object )
|
||||
tmp_name
|
||||
end
|
||||
end
|
||||
|
@ -30,8 +30,8 @@ module Vool
|
||||
|
||||
def create_objects
|
||||
args_type = make_type
|
||||
locals_type = make_locals
|
||||
method = Parfait::VoolMethod.new(name , args_type , locals_type , body )
|
||||
frame_type = make_frame
|
||||
method = Parfait::VoolMethod.new(name , args_type , frame_type , body )
|
||||
@clazz.add_method( method )
|
||||
typed_method = method.create_parfait_method(clazz.instance_type)
|
||||
compiler = Risc::MethodCompiler.new( typed_method ).init_method
|
||||
@ -47,7 +47,7 @@ module Vool
|
||||
Parfait::NamedList.type_for( type_hash )
|
||||
end
|
||||
|
||||
def make_locals
|
||||
def make_frame
|
||||
type_hash = {}
|
||||
vars = []
|
||||
@body.collect([]).each { |node| node.add_local(vars) }
|
||||
|
@ -15,8 +15,8 @@ module Rubyx
|
||||
def on_def(statement)
|
||||
name , args , body = *statement
|
||||
args_type = make_type(args)
|
||||
locals_type = make_locals(body)
|
||||
@methods << Vool::VoolMethod.new(name , args_type , locals_type , body )
|
||||
frame_type = make_locals(body)
|
||||
@methods << Vool::VoolMethod.new(name , args_type , frame_type , body )
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -31,7 +31,7 @@ module Rubyx
|
||||
|
||||
def test_one_local
|
||||
method = parse_collect("def meth2(arg1); foo = 2 ;end").first
|
||||
assert method.locals_type.variable_index(:foo) , method.locals_type.inspect
|
||||
assert method.frame_type.variable_index(:foo) , method.frame_type.inspect
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -44,7 +44,7 @@ module Rubyx
|
||||
|
||||
def test_method_has_no_locals
|
||||
method = create_method
|
||||
assert_equal 1 , method.locals_type.instance_length
|
||||
assert_equal 1 , method.frame_type.instance_length
|
||||
end
|
||||
|
||||
def test_method_has_args
|
||||
@ -54,7 +54,7 @@ module Rubyx
|
||||
|
||||
def test_method_has_locals
|
||||
method = create_method_local
|
||||
assert_equal 2 , method.locals_type.instance_length
|
||||
assert_equal 2 , method.frame_type.instance_length
|
||||
end
|
||||
|
||||
def test_method_create_tmp
|
||||
@ -65,7 +65,7 @@ module Rubyx
|
||||
def test_method_add_tmp
|
||||
method = create_method_local
|
||||
method.create_tmp
|
||||
assert_equal 3 , method.locals_type.instance_length
|
||||
assert_equal 3 , method.frame_type.instance_length
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -31,7 +31,7 @@ module Vm
|
||||
raise "must define local '#{name}' before using it" unless index
|
||||
named_list = use_reg :NamedList
|
||||
add_slot_to_reg("#{name} load locals" , :message , :frame , named_list )
|
||||
ret = use_reg @method.locals_type( index )
|
||||
ret = use_reg @method.frame_type( index )
|
||||
add_slot_to_reg("#{name} load from locals" , named_list , index + 1, ret )
|
||||
return ret
|
||||
end
|
||||
|
@ -70,7 +70,7 @@ class TestMethod < MiniTest::Test
|
||||
@method.add_local(:foo2 , :Object)
|
||||
assert_equal 3 , @method.frame_length
|
||||
assert_equal :foo2 , @method.locals_name(3)
|
||||
assert_equal :Object , @method.locals_type(3)
|
||||
assert_equal :Object , @method.frame_type(3)
|
||||
end
|
||||
|
||||
def test_get_locals_name1
|
||||
@ -78,18 +78,18 @@ class TestMethod < MiniTest::Test
|
||||
assert_equal 1 , index
|
||||
assert_equal :local_bar , @method.locals_name(index)
|
||||
end
|
||||
def test_get_locals_type1
|
||||
def test_get_frame_type1
|
||||
index = @method.has_local(:local_bar)
|
||||
assert_equal :Integer , @method.locals_type(index)
|
||||
assert_equal :Integer , @method.frame_type(index)
|
||||
end
|
||||
def test_get_locals_name2
|
||||
index = @method.has_local(:local_foo)
|
||||
assert_equal 2 , index
|
||||
assert_equal :local_foo , @method.locals_name(index)
|
||||
end
|
||||
def test_get_locals_type2
|
||||
def test_get_frame_type2
|
||||
index = @method.has_local(:local_bar)
|
||||
assert_equal :Integer , @method.locals_type(index)
|
||||
assert_equal :Integer , @method.frame_type(index)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -22,7 +22,7 @@ module Vool
|
||||
|
||||
def test_method_has_no_locals
|
||||
method = create_method
|
||||
assert_equal 1 , method.locals_type.instance_length
|
||||
assert_equal 1 , method.frame_type.instance_length
|
||||
end
|
||||
|
||||
def test_method_has_no_args
|
||||
@ -60,7 +60,7 @@ module Vool
|
||||
VoolCompiler.ruby_to_vool in_Test("def meth; local = 5 ;end")
|
||||
test = Parfait.object_space.get_class_by_name(:Test)
|
||||
method = test.get_method(:meth)
|
||||
assert_equal 2 , method.locals_type.instance_length
|
||||
assert_equal 2 , method.frame_type.instance_length
|
||||
end
|
||||
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user