rename locals to frame

This commit is contained in:
Torsten Ruger 2018-03-14 20:24:47 +05:30
parent 7db329fa6b
commit 559a797100
9 changed files with 25 additions and 25 deletions

View File

@ -78,14 +78,14 @@ module Parfait
end end
def frame_length def frame_length
locals.instance_length - 1 frame.instance_length - 1
end end
def locals_name( index ) def locals_name( index )
frame.names.get(index + 1) frame.names.get(index + 1)
end end
def locals_type( index ) def frame_type( index )
frame.types.get(index + 1) frame.types.get(index + 1)
end end

View File

@ -14,11 +14,11 @@ module Parfait
attr_reader :name , :args_type , :frame_type , :source attr_reader :name , :args_type , :frame_type , :source
def initialize(name , args_type , locals_type , source ) def initialize(name , args_type , frame_type , source )
@name , @args_type , @locals_type , @source = name , args_type, locals_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 "Name must be symbol" unless name.is_a?(Symbol)
raise "args_type must be type" unless args_type.is_a?(Parfait::Type) 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) raise "source must be vool" unless source.is_a?(Vool::Statement)
end end
@ -28,12 +28,12 @@ module Parfait
def create_parfait_method( type ) def create_parfait_method( type )
raise "create_method #{type.inspect} is not a Type" unless type.is_a? Parfait::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 end
def create_tmp def create_tmp
tmp_name = "tmp_#{@locals_type.instance_length}".to_sym tmp_name = "tmp_#{@frame_type.instance_length}".to_sym
@locals_type = @locals_type.add_instance_variable( tmp_name , :Object ) @frame_type = @frame_type.add_instance_variable( tmp_name , :Object )
tmp_name tmp_name
end end
end end

View File

@ -30,8 +30,8 @@ module Vool
def create_objects def create_objects
args_type = make_type args_type = make_type
locals_type = make_locals frame_type = make_frame
method = Parfait::VoolMethod.new(name , args_type , locals_type , body ) method = Parfait::VoolMethod.new(name , args_type , frame_type , body )
@clazz.add_method( method ) @clazz.add_method( method )
typed_method = method.create_parfait_method(clazz.instance_type) typed_method = method.create_parfait_method(clazz.instance_type)
compiler = Risc::MethodCompiler.new( typed_method ).init_method compiler = Risc::MethodCompiler.new( typed_method ).init_method
@ -47,7 +47,7 @@ module Vool
Parfait::NamedList.type_for( type_hash ) Parfait::NamedList.type_for( type_hash )
end end
def make_locals def make_frame
type_hash = {} type_hash = {}
vars = [] vars = []
@body.collect([]).each { |node| node.add_local(vars) } @body.collect([]).each { |node| node.add_local(vars) }

View File

@ -15,8 +15,8 @@ module Rubyx
def on_def(statement) def on_def(statement)
name , args , body = *statement name , args , body = *statement
args_type = make_type(args) args_type = make_type(args)
locals_type = make_locals(body) frame_type = make_locals(body)
@methods << Vool::VoolMethod.new(name , args_type , locals_type , body ) @methods << Vool::VoolMethod.new(name , args_type , frame_type , body )
end end
private private

View File

@ -31,7 +31,7 @@ module Rubyx
def test_one_local def test_one_local
method = parse_collect("def meth2(arg1); foo = 2 ;end").first 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
end end

View File

@ -44,7 +44,7 @@ module Rubyx
def test_method_has_no_locals def test_method_has_no_locals
method = create_method method = create_method
assert_equal 1 , method.locals_type.instance_length assert_equal 1 , method.frame_type.instance_length
end end
def test_method_has_args def test_method_has_args
@ -54,7 +54,7 @@ module Rubyx
def test_method_has_locals def test_method_has_locals
method = create_method_local method = create_method_local
assert_equal 2 , method.locals_type.instance_length assert_equal 2 , method.frame_type.instance_length
end end
def test_method_create_tmp def test_method_create_tmp
@ -65,7 +65,7 @@ module Rubyx
def test_method_add_tmp def test_method_add_tmp
method = create_method_local method = create_method_local
method.create_tmp method.create_tmp
assert_equal 3 , method.locals_type.instance_length assert_equal 3 , method.frame_type.instance_length
end end
end end

View File

@ -31,7 +31,7 @@ module Vm
raise "must define local '#{name}' before using it" unless index raise "must define local '#{name}' before using it" unless index
named_list = use_reg :NamedList named_list = use_reg :NamedList
add_slot_to_reg("#{name} load locals" , :message , :frame , named_list ) 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 ) add_slot_to_reg("#{name} load from locals" , named_list , index + 1, ret )
return ret return ret
end end

View File

@ -70,7 +70,7 @@ class TestMethod < MiniTest::Test
@method.add_local(:foo2 , :Object) @method.add_local(:foo2 , :Object)
assert_equal 3 , @method.frame_length assert_equal 3 , @method.frame_length
assert_equal :foo2 , @method.locals_name(3) assert_equal :foo2 , @method.locals_name(3)
assert_equal :Object , @method.locals_type(3) assert_equal :Object , @method.frame_type(3)
end end
def test_get_locals_name1 def test_get_locals_name1
@ -78,18 +78,18 @@ class TestMethod < MiniTest::Test
assert_equal 1 , index assert_equal 1 , index
assert_equal :local_bar , @method.locals_name(index) assert_equal :local_bar , @method.locals_name(index)
end end
def test_get_locals_type1 def test_get_frame_type1
index = @method.has_local(:local_bar) index = @method.has_local(:local_bar)
assert_equal :Integer , @method.locals_type(index) assert_equal :Integer , @method.frame_type(index)
end end
def test_get_locals_name2 def test_get_locals_name2
index = @method.has_local(:local_foo) index = @method.has_local(:local_foo)
assert_equal 2 , index assert_equal 2 , index
assert_equal :local_foo , @method.locals_name(index) assert_equal :local_foo , @method.locals_name(index)
end end
def test_get_locals_type2 def test_get_frame_type2
index = @method.has_local(:local_bar) index = @method.has_local(:local_bar)
assert_equal :Integer , @method.locals_type(index) assert_equal :Integer , @method.frame_type(index)
end end
end end

View File

@ -22,7 +22,7 @@ module Vool
def test_method_has_no_locals def test_method_has_no_locals
method = create_method method = create_method
assert_equal 1 , method.locals_type.instance_length assert_equal 1 , method.frame_type.instance_length
end end
def test_method_has_no_args def test_method_has_no_args
@ -60,7 +60,7 @@ module Vool
VoolCompiler.ruby_to_vool in_Test("def meth; local = 5 ;end") VoolCompiler.ruby_to_vool in_Test("def meth; local = 5 ;end")
test = Parfait.object_space.get_class_by_name(:Test) test = Parfait.object_space.get_class_by_name(:Test)
method = test.get_method(:meth) method = test.get_method(:meth)
assert_equal 2 , method.locals_type.instance_length assert_equal 2 , method.frame_type.instance_length
end end
end end