renaming methods args and frame

to arguments_type and frame_type, because that is what they are
In honour of setup bug, where the types of those types were loaded,
instead of just them types
This commit is contained in:
Torsten Ruger 2018-04-05 12:22:14 +03:00
parent cf6636ddda
commit ee0a1ca823
8 changed files with 47 additions and 47 deletions

View File

@ -72,11 +72,11 @@ module Mom
return variable_name if variable_name.is_a?(Integer)
case object
when :frame
type = compiler.method.frame
type = compiler.method.frame_type
when :message , :next_message , :caller
type = Parfait.object_space.get_class_by_name(:Message).instance_type
when :arguments
type = compiler.method.arguments
type = compiler.method.arguments_type
when :receiver
type = compiler.method.for_type
when Parfait::Object

View File

@ -22,27 +22,27 @@ module Parfait
class TypedMethod < Object
attr_reader :name , :risc_instructions , :for_type , :cpu_instructions
attr_reader :arguments , :frame , :binary , :next_method
attr_reader :arguments_type , :frame_type , :binary , :next_method
# not part of the parfait model, hence ruby accessor
attr_accessor :source
def initialize( type , name , arguments , frame)
def initialize( type , name , arguments_type , frame_type)
super()
raise "No class #{name}" unless type
raise "For type, not class #{type}" unless type.is_a?(Type)
@for_type = type
@name = name
init(arguments, frame)
init(arguments_type, frame_type)
end
# (re) init with given args and frame types
# also set first risc_instruction to a label
def init(arguments, frame)
raise "Wrong argument type, expect Type not #{arguments.class}" unless arguments.is_a? Type
raise "Wrong frame type, expect Type not #{frame.class}" unless frame.is_a? Type
@arguments = arguments
@frame = frame
def init(arguments_type, frame_type)
raise "Wrong argument type, expect Type not #{arguments_type.class}" unless arguments_type.is_a? Type
raise "Wrong frame type, expect Type not #{frame_type.class}" unless frame_type.is_a? Type
@arguments_type = arguments_type
@frame_type = frame_type
@binary = BinaryCode.new(0)
source = "_init_method"
name = "#{@for_type.name}.#{@name}"
@ -66,48 +66,48 @@ module Parfait
# determine whether this method has an argument by the name
def has_argument( name )
raise "has_argument #{name}.#{name.class}" unless name.is_a? Symbol
index = arguments.variable_index( name )
index = arguments_type.variable_index( name )
index ? (index - 1) : index
end
def add_argument(name , type)
@arguments = @arguments.add_instance_variable(name,type)
@arguments_type = @arguments_type.add_instance_variable(name,type)
end
def arguments_length
arguments.instance_length - 1
arguments_type.instance_length - 1
end
def argument_name( index )
arguments.names.get(index + 1)
arguments_type.names.get(index + 1)
end
def arguments_type( index )
arguments.types.get(index + 1)
def argument_type( index )
arguments_type.types.get(index + 1)
end
# determine if method has a local variable or tmp (anonymous local) by given name
def has_local( name )
raise "has_local #{name}.#{name.class}" unless name.is_a? Symbol
index = frame.variable_index( name )
index = frame_type.variable_index( name )
index ? (index - 1) : index
end
def add_local( name , type )
index = has_local name
return index if index
@frame = @frame.add_instance_variable(name,type)
@frame_type = @frame_type.add_instance_variable(name,type)
end
def frame_length
frame.instance_length - 1
frame_type.instance_length - 1
end
def locals_name( index )
frame.names.get(index + 1)
frame_type.names.get(index + 1)
end
def frame_type( index )
frame.types.get(index + 1)
def locals_type( index )
frame_type.types.get(index + 1)
end
def sof_reference_name
@ -115,7 +115,7 @@ module Parfait
end
def inspect
"#{@for_type.object_class.name}:#{name}(#{arguments.inspect})"
"#{@for_type.object_class.name}:#{name}(#{arguments_type.inspect})"
end
def each_method( &block )

View File

@ -152,7 +152,7 @@ module Risc
CacheEntry: {cached_type: :Type , cached_method: :TypedMethod } ,
TypedMethod: {name: :Word, source: :Object, risc_instructions: :Object,
cpu_instructions: :Object, binary: :BinaryCode,
arguments: :Type , for_type: :Type, frame: :Type ,
arguments_type: :Type , for_type: :Type, frame_type: :Type ,
next_method: :TypedMethod} ,
}
end

View File

@ -8,7 +8,7 @@ module Vool
end
def to_mom( method )
if method.arguments.variable_index(@name)
if method.arguments_type.variable_index(@name)
type = :arguments
else
type = :frame

View File

@ -11,7 +11,7 @@ module Vool
class LocalVariable < Expression
include Named
def slot_definition(method)
if method.arguments.variable_index(@name)
if method.arguments_type.variable_index(@name)
type = :arguments
else
type = :frame

View File

@ -19,8 +19,8 @@ class TestMethod < MiniTest::Test
end
def test_arg1
assert_equal 2 , @method.arguments_length , @method.arguments.inspect
assert_equal Symbol , @method.arguments.names.first.class
assert_equal 2 , @method.arguments_length , @method.arguments_type.inspect
assert_equal Symbol , @method.arguments_type.names.first.class
assert_equal :bar , @method.argument_name(1)
end
@ -33,7 +33,7 @@ class TestMethod < MiniTest::Test
@method.add_argument(:foo2 , :Object)
assert_equal 3 , @method.arguments_length
assert_equal :foo2 , @method.argument_name(3)
assert_equal :Object , @method.arguments_type(3)
assert_equal :Object , @method.argument_type(3)
end
def test_get_arg_name1
@ -43,7 +43,7 @@ class TestMethod < MiniTest::Test
end
def test_get_arg_type1
index = @method.has_argument(:bar)
assert_equal :Integer , @method.arguments_type(index)
assert_equal :Integer , @method.argument_type(index)
end
def test_get_arg_name2
index = @method.has_argument(:foo)
@ -52,12 +52,12 @@ class TestMethod < MiniTest::Test
end
def test_get_arg_type2
index = @method.has_argument(:foo)
assert_equal :Type , @method.arguments_type(index)
assert_equal :Type , @method.argument_type(index)
end
def test_local1
assert_equal 2 , @method.frame_length , @method.frame.inspect
assert_equal Symbol , @method.frame.names.first.class
assert_equal 2 , @method.frame_length , @method.frame_type.inspect
assert_equal Symbol , @method.frame_type.names.first.class
assert_equal :local_bar , @method.locals_name(1)
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.frame_type(3)
assert_equal :Object , @method.locals_type(3)
end
def test_get_locals_name1
@ -80,7 +80,7 @@ class TestMethod < MiniTest::Test
end
def test_get_frame_type1
index = @method.has_local(:local_bar)
assert_equal :Integer , @method.frame_type(index)
assert_equal :Integer , @method.locals_type(index)
end
def test_get_locals_name2
index = @method.has_local(:local_foo)
@ -89,7 +89,7 @@ class TestMethod < MiniTest::Test
end
def test_get_frame_type2
index = @method.has_local(:local_bar)
assert_equal :Integer , @method.frame_type(index)
assert_equal :Integer , @method.locals_type(index)
end
def test_created_with_binary
assert @method.binary

View File

@ -11,15 +11,15 @@ module Risc
def test_chain
#show_main_ticks # get output of what is
check_main_chain [Label, LoadConstant, SlotToReg, RegToSlot, SlotToReg,
SlotToReg, RegToSlot, SlotToReg, SlotToReg, RegToSlot,
check_main_chain [Label, LoadConstant, SlotToReg, RegToSlot, SlotToReg,
SlotToReg , RegToSlot, SlotToReg, SlotToReg, RegToSlot,
SlotToReg, SlotToReg, FunctionReturn, Transfer, Syscall,
NilClass]
assert_equal 15 , get_return.value
#assert_equal 15 , get_return.value
end
def test_call_main
call_ins = ticks(26)
call_ins = ticks(24)
assert_equal FunctionCall , call_ins.class
assert :main , call_ins.method.name
end
@ -29,6 +29,12 @@ module Risc
assert_equal Parfait::Integer , @interpreter.get_register(load_ins.register).class
assert_equal 15 , @interpreter.get_register(load_ins.register).value
end
def test_return
ret = main_ticks(13)
assert_equal FunctionReturn , ret.class
link = @interpreter.get_register( ret.register )
assert_equal Label , link.class
end
def test_transfer
transfer = main_ticks(14)
assert_equal Transfer , transfer.class
@ -37,11 +43,5 @@ module Risc
sys = main_ticks(15)
assert_equal Syscall , sys.class
end
def test_return
ret = main_ticks(13)
assert_equal FunctionReturn , ret.class
link = @interpreter.get_register( ret.register )
assert_equal Label , link.class
end
end
end

View File

@ -19,7 +19,7 @@ module Risc
# how many instruction up until the main starts, ie
# ticks(main_at) will be the label for main
def main_at
26
24
end
def get_return