more renaming of frame
This commit is contained in:
parent
0040baae28
commit
93ba5543b3
@ -2,7 +2,7 @@ require_relative "attributed"
|
|||||||
|
|
||||||
module Arm
|
module Arm
|
||||||
|
|
||||||
# A Machines main responsibility in the framework is to instantiate Instructions
|
# A Machines main responsibility in the named_listwork is to instantiate Instructions
|
||||||
|
|
||||||
# Value functions are mapped to machines by concatenating the values class name + the methd name
|
# Value functions are mapped to machines by concatenating the values class name + the methd name
|
||||||
# Example: IntegerValue.plus( value ) -> Machine.signed_plus (value )
|
# Example: IntegerValue.plus( value ) -> Machine.signed_plus (value )
|
||||||
|
@ -115,7 +115,7 @@ module Register
|
|||||||
def type_names
|
def type_names
|
||||||
{ :Word => {:char_length => :Integer} ,
|
{ :Word => {:char_length => :Integer} ,
|
||||||
:List => {:indexed_length => :Integer} ,
|
:List => {:indexed_length => :Integer} ,
|
||||||
:Message => { :next_message => :Message, :receiver => :Object, :frame => :NamedList ,
|
:Message => { :next_message => :Message, :receiver => :Object, :named_list => :NamedList ,
|
||||||
:return_address => :Integer, :return_value => :Integer,
|
:return_address => :Integer, :return_value => :Integer,
|
||||||
:caller => :Message , :name => :Word , :indexed_length => :Integer },
|
:caller => :Message , :name => :Word , :indexed_length => :Integer },
|
||||||
:MetaClass => {:object => :Object},
|
:MetaClass => {:object => :Object},
|
||||||
|
@ -99,7 +99,7 @@ module Register
|
|||||||
|
|
||||||
# if a symbol is given, it may be one of the four objects that the vm knows.
|
# if a symbol is given, it may be one of the four objects that the vm knows.
|
||||||
# These are mapped to register references.
|
# These are mapped to register references.
|
||||||
# The valid symbols (:message, :self,:frame,:new_message) are the same that are returned
|
# The valid symbols (:message, :self,:named_list,:new_message) are the same that are returned
|
||||||
# by the slots. All data (at any time) is in one of the instance variables of these four
|
# by the slots. All data (at any time) is in one of the instance variables of these four
|
||||||
# objects. Register defines module methods with the same names (and _reg)
|
# objects. Register defines module methods with the same names (and _reg)
|
||||||
def self.resolve_to_register reference
|
def self.resolve_to_register reference
|
||||||
|
@ -19,13 +19,13 @@ module Typed
|
|||||||
# TODO, check type @method.arguments[index].type
|
# TODO, check type @method.arguments[index].type
|
||||||
return Register.set_slot(statement , value , :message , Parfait::Message.get_indexed(index) )
|
return Register.set_slot(statement , value , :message , Parfait::Message.get_indexed(index) )
|
||||||
end
|
end
|
||||||
# or a local so it is in the frame
|
# or a local so it is in the named_list
|
||||||
index = @method.has_local( name )
|
index = @method.has_local( name )
|
||||||
return nil unless index
|
return nil unless index
|
||||||
# TODO, check type @method.locals[index].type
|
# TODO, check type @method.locals[index].type
|
||||||
frame = use_reg(:NamedList)
|
named_list = use_reg(:NamedList)
|
||||||
add_code Register.get_slot(statement , :message , :frame , frame )
|
add_code Register.get_slot(statement , :message , :named_list , named_list )
|
||||||
return Register.set_slot(statement , value , frame , Parfait::NamedList.get_indexed(index) )
|
return Register.set_slot(statement , value , named_list , Parfait::NamedList.get_indexed(index) )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -17,7 +17,7 @@ module Typed
|
|||||||
add_code Register.get_slot(statement , :message , Parfait::Message.get_indexed(index), ret )
|
add_code Register.get_slot(statement , :message , Parfait::Message.get_indexed(index), ret )
|
||||||
return ret
|
return ret
|
||||||
end
|
end
|
||||||
# or a local so it is in the frame
|
# or a local so it is in the named_list
|
||||||
handle_local(statement)
|
handle_local(statement)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -26,10 +26,10 @@ module Typed
|
|||||||
def handle_local statement
|
def handle_local statement
|
||||||
index = @method.has_local( statement.name )
|
index = @method.has_local( statement.name )
|
||||||
raise "must define variable '#{statement.name}' before using it" unless index
|
raise "must define variable '#{statement.name}' before using it" unless index
|
||||||
frame = use_reg :NamedList
|
named_list = use_reg :NamedList
|
||||||
add_code Register.get_slot(statement , :message , :frame , frame )
|
add_code Register.get_slot(statement , :message , :named_list , named_list )
|
||||||
ret = use_reg @method.locals_type( index )
|
ret = use_reg @method.locals_type( index )
|
||||||
add_code Register.get_slot(statement , frame , Parfait::NamedList.get_indexed(index), ret )
|
add_code Register.get_slot(statement , named_list , Parfait::NamedList.get_indexed(index), ret )
|
||||||
return ret
|
return ret
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
module Parfait
|
module Parfait
|
||||||
class Message < Object
|
class Message < Object
|
||||||
attributes [:next_message , :receiver , :frame , :return_address ]
|
attributes [:next_message , :receiver , :named_list , :return_address ]
|
||||||
attributes [:return_value, :caller , :name ]
|
attributes [:return_value, :caller , :name ]
|
||||||
|
|
||||||
include Indexed
|
include Indexed
|
||||||
@ -17,7 +17,7 @@ module Parfait
|
|||||||
|
|
||||||
def initialize next_m
|
def initialize next_m
|
||||||
self.next_message = next_m
|
self.next_message = next_m
|
||||||
self.frame = NamedList.new()
|
self.named_list = NamedList.new()
|
||||||
self.caller = nil
|
self.caller = nil
|
||||||
super()
|
super()
|
||||||
end
|
end
|
||||||
|
@ -8,10 +8,10 @@
|
|||||||
# A Message with is arguments, and a NamedList make up the two sides of message passing:
|
# A Message with is arguments, and a NamedList make up the two sides of message passing:
|
||||||
# A Message (see details there) is created by the caller and control is transferred
|
# A Message (see details there) is created by the caller and control is transferred
|
||||||
# A NamedList is created by the receiver
|
# A NamedList is created by the receiver
|
||||||
# PS: it turns out that both messages and frames are created at compile, not run-time, and
|
# PS: it turns out that both messages and named_lists are created at compile, not run-time, and
|
||||||
# just constantly reused. Each message has a frame object ready and is also linked
|
# just constantly reused. Each message has a named_list object ready and is also linked
|
||||||
# to the next message.
|
# to the next message.
|
||||||
# The better way to say above is that a message is *used* by the caller, and a frame by the callee.
|
# The better way to say above is that a message is *used* by the caller, and a named_list by the callee.
|
||||||
|
|
||||||
# Also at runtime Messages and NamedLists remain completely "normal" objects.
|
# Also at runtime Messages and NamedLists remain completely "normal" objects.
|
||||||
# Ie they have have type and instances and so on.*
|
# Ie they have have type and instances and so on.*
|
||||||
|
@ -2,7 +2,7 @@ module Register
|
|||||||
# So when an object calls a method, or sends a message, this is what it sends: a Message
|
# So when an object calls a method, or sends a message, this is what it sends: a Message
|
||||||
|
|
||||||
# A message contains the sender, return and exceptional return addresses,the arguments,
|
# A message contains the sender, return and exceptional return addresses,the arguments,
|
||||||
# and a slot for the frame.
|
# and a slot for the named_list.
|
||||||
|
|
||||||
# As such it is a very run-time object, deep in the machinery as it were, and does not have
|
# As such it is a very run-time object, deep in the machinery as it were, and does not have
|
||||||
# meaningful methods you could call at compile time.
|
# meaningful methods you could call at compile time.
|
||||||
@ -19,7 +19,7 @@ module Register
|
|||||||
# but as there is a guaranteed result (be it method_missing) it does not matter to the passing
|
# but as there is a guaranteed result (be it method_missing) it does not matter to the passing
|
||||||
# mechanism described
|
# mechanism described
|
||||||
|
|
||||||
# During compilation Message and frame objects are created to do type analysis
|
# During compilation Message and named_list objects are created to do type analysis
|
||||||
|
|
||||||
class Message
|
class Message
|
||||||
|
|
||||||
@ -28,10 +28,10 @@ module Register
|
|||||||
@next_normal = normal
|
@next_normal = normal
|
||||||
@next_exception = exceptional
|
@next_exception = exceptional
|
||||||
@arguments = arguments
|
@arguments = arguments
|
||||||
# a frame represents the local and temporary variables at a point in the program.
|
# a named_list represents the local and temporary variables at a point in the program.
|
||||||
@frame = nil
|
@named_list = nil
|
||||||
end
|
end
|
||||||
attr_reader :me, :next_normal, :next_exception, :arguments , :frame
|
attr_reader :me, :next_normal, :next_exception, :arguments , :named_list
|
||||||
|
|
||||||
#
|
#
|
||||||
end
|
end
|
||||||
|
@ -7,11 +7,11 @@ module Register
|
|||||||
|
|
||||||
# Four known objects exist and those correspond to subclasses:
|
# Four known objects exist and those correspond to subclasses:
|
||||||
# - the message that has been received: MessageSlot
|
# - the message that has been received: MessageSlot
|
||||||
# - the frame of the method that is executing (local variables): NamedListSlot
|
# - the named_list of the method that is executing (local variables): NamedListSlot
|
||||||
# - self as an object: SelfsSlot
|
# - self as an object: SelfsSlot
|
||||||
# - a message that will be sent, NewMessageSlot
|
# - a message that will be sent, NewMessageSlot
|
||||||
|
|
||||||
# additionally frame, self and return are slots in Message and NewMessage
|
# additionally named_list, self and return are slots in Message and NewMessage
|
||||||
|
|
||||||
# Slot has a lot of small subclasses
|
# Slot has a lot of small subclasses
|
||||||
# Names for the slots avoid indexes
|
# Names for the slots avoid indexes
|
||||||
|
@ -3,17 +3,17 @@ require_relative "../helper"
|
|||||||
class TestNamedLists < MiniTest::Test
|
class TestNamedLists < MiniTest::Test
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@frame = Register.machine.boot.space.first_message.frame
|
@named_list = Register.machine.boot.space.first_message.named_list
|
||||||
@type = @frame.get_type
|
@type = @named_list.get_type
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_frame_get_type
|
def test_named_list_get_type
|
||||||
assert_equal Parfait::Type , @type.class
|
assert_equal Parfait::Type , @type.class
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_frame_next_set
|
def test_named_list_next_set
|
||||||
@frame.next_list = :next_list
|
@named_list.next_list = :next_list
|
||||||
assert_equal :next_list , @frame.next_list
|
assert_equal :next_list , @named_list.next_list
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -60,7 +60,7 @@ class TestSpace < MiniTest::Test
|
|||||||
all = []
|
all = []
|
||||||
while mess
|
while mess
|
||||||
all << mess
|
all << mess
|
||||||
assert mess.frame
|
assert mess.named_list
|
||||||
mess = mess.next_message
|
mess = mess.next_message
|
||||||
end
|
end
|
||||||
assert_equal all.length , all.uniq.length
|
assert_equal all.length , all.uniq.length
|
||||||
|
@ -40,7 +40,7 @@ class TestAssignStatement < MiniTest::Test
|
|||||||
check
|
check
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_frame_get
|
def test_named_list_get
|
||||||
Register.machine.space.get_main.add_local(:r , :Integer)
|
Register.machine.space.get_main.add_local(:r , :Integer)
|
||||||
@input = s(:statements, s(:assignment, s(:name, :r), s(:int, 5)), s(:return, s(:name, :r)))
|
@input = s(:statements, s(:assignment, s(:name, :r), s(:int, 5)), s(:return, s(:name, :r)))
|
||||||
@expect = [Label, LoadConstant, GetSlot, SetSlot, GetSlot, GetSlot, SetSlot ,
|
@expect = [Label, LoadConstant, GetSlot, SetSlot, GetSlot, GetSlot, SetSlot ,
|
||||||
@ -48,7 +48,7 @@ class TestAssignStatement < MiniTest::Test
|
|||||||
was = check
|
was = check
|
||||||
get = was.next(5)
|
get = was.next(5)
|
||||||
assert_equal GetSlot , get.class
|
assert_equal GetSlot , get.class
|
||||||
assert_equal 4, get.index , "Get to frame index must be offset, not #{get.index}"
|
assert_equal 4, get.index , "Get to named_list index must be offset, not #{get.index}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_assign_int
|
def test_assign_int
|
||||||
@ -58,7 +58,7 @@ class TestAssignStatement < MiniTest::Test
|
|||||||
was = check
|
was = check
|
||||||
set = was.next(3)
|
set = was.next(3)
|
||||||
assert_equal SetSlot , set.class
|
assert_equal SetSlot , set.class
|
||||||
assert_equal 4, set.index , "Set to frame index must be offset, not #{set.index}"
|
assert_equal 4, set.index , "Set to named_list index must be offset, not #{set.index}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_assign_arg
|
def test_assign_arg
|
||||||
@ -79,7 +79,7 @@ class TestAssignStatement < MiniTest::Test
|
|||||||
was = check
|
was = check
|
||||||
get = was.next(1)
|
get = was.next(1)
|
||||||
assert_equal GetSlot , get.class
|
assert_equal GetSlot , get.class
|
||||||
assert_equal 10, get.index , "Get to frame index must be offset, not #{get.index}"
|
assert_equal 10, get.index , "Get to named_list index must be offset, not #{get.index}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -5,7 +5,7 @@ module Register
|
|||||||
class TestFieldStatement < MiniTest::Test
|
class TestFieldStatement < MiniTest::Test
|
||||||
include Statements
|
include Statements
|
||||||
|
|
||||||
def test_field_frame
|
def test_field_named_list
|
||||||
Register.machine.space.get_main.add_local( :m , :Message)
|
Register.machine.space.get_main.add_local( :m , :Message)
|
||||||
@input = s(:statements, s(:return, s(:field_access,
|
@input = s(:statements, s(:return, s(:field_access,
|
||||||
s(:receiver, s(:name, :m)), s(:field, s(:name, :name)))))
|
s(:receiver, s(:name, :m)), s(:field, s(:name, :name)))))
|
||||||
|
Loading…
Reference in New Issue
Block a user