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) return variable_name if variable_name.is_a?(Integer)
case object case object
when :frame when :frame
type = compiler.method.frame type = compiler.method.frame_type
when :message , :next_message , :caller when :message , :next_message , :caller
type = Parfait.object_space.get_class_by_name(:Message).instance_type type = Parfait.object_space.get_class_by_name(:Message).instance_type
when :arguments when :arguments
type = compiler.method.arguments type = compiler.method.arguments_type
when :receiver when :receiver
type = compiler.method.for_type type = compiler.method.for_type
when Parfait::Object when Parfait::Object

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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