rename typed_method to callable_method
seems to make the essence clearer also extracted base class
This commit is contained in:
parent
acd5cd8f30
commit
9005513368
@ -69,7 +69,7 @@ module Arm
|
|||||||
ArmMachine.mov( :pc , code.register)
|
ArmMachine.mov( :pc , code.register)
|
||||||
end
|
end
|
||||||
def translate_DynamicJump(code)
|
def translate_DynamicJump(code)
|
||||||
index = Parfait.object_space.get_class_by_name(:TypedMethod).instance_type.variable_index(:binary)
|
index = Parfait.object_space.get_class_by_name(:CallableMethod).instance_type.variable_index(:binary)
|
||||||
codes = ArmMachine.ldr( code.register , code.register , arm_index(index) )
|
codes = ArmMachine.ldr( code.register , code.register , arm_index(index) )
|
||||||
codes << ArmMachine.mov( :pc , code.register)
|
codes << ArmMachine.mov( :pc , code.register)
|
||||||
codes
|
codes
|
||||||
|
@ -35,12 +35,12 @@ module Mom
|
|||||||
# but also used directly in __init
|
# but also used directly in __init
|
||||||
def build_with(builder)
|
def build_with(builder)
|
||||||
case from = method_source
|
case from = method_source
|
||||||
when Parfait::TypedMethod
|
when Parfait::CallableMethod
|
||||||
builder.build { typed_method << from }
|
builder.build { callable_method << from }
|
||||||
when Parfait::CacheEntry
|
when Parfait::CacheEntry
|
||||||
builder.build do
|
builder.build do
|
||||||
cache_entry << from
|
cache_entry << from
|
||||||
typed_method << cache_entry[:cached_method]
|
callable_method << cache_entry[:cached_method]
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
raise "unknown source #{method_source}"
|
raise "unknown source #{method_source}"
|
||||||
@ -64,15 +64,15 @@ module Mom
|
|||||||
message[:next_message] << next_message
|
message[:next_message] << next_message
|
||||||
next_message[:caller] << message
|
next_message[:caller] << message
|
||||||
|
|
||||||
type << typed_method[:arguments_type]
|
type << callable_method[:arguments_type]
|
||||||
named_list << next_message[:arguments]
|
named_list << next_message[:arguments]
|
||||||
named_list[:type] << type
|
named_list[:type] << type
|
||||||
|
|
||||||
type << typed_method[:frame_type]
|
type << callable_method[:frame_type]
|
||||||
named_list << next_message[:frame]
|
named_list << next_message[:frame]
|
||||||
named_list[:type] << type
|
named_list[:type] << type
|
||||||
|
|
||||||
name << typed_method[:name]
|
name << callable_method[:name]
|
||||||
next_message[:name] << name
|
next_message[:name] << name
|
||||||
|
|
||||||
#store next.next back into space
|
#store next.next back into space
|
||||||
|
@ -41,28 +41,28 @@ module Mom
|
|||||||
cache_entry << cache_entry_
|
cache_entry << cache_entry_
|
||||||
|
|
||||||
type << cache_entry[:cached_type]
|
type << cache_entry[:cached_type]
|
||||||
typed_method << type[:methods]
|
callable_method << type[:methods]
|
||||||
|
|
||||||
add_code while_start_label
|
add_code while_start_label
|
||||||
|
|
||||||
space << Parfait.object_space
|
space << Parfait.object_space
|
||||||
space << space[:nil_object]
|
space << space[:nil_object]
|
||||||
space - typed_method
|
space - callable_method
|
||||||
if_zero exit_label
|
if_zero exit_label
|
||||||
|
|
||||||
name << typed_method[:name]
|
name << callable_method[:name]
|
||||||
name - word
|
name - word
|
||||||
|
|
||||||
if_zero ok_label
|
if_zero ok_label
|
||||||
|
|
||||||
typed_method << typed_method[:next_method]
|
callable_method << callable_method[:next]
|
||||||
branch while_start_label
|
branch while_start_label
|
||||||
|
|
||||||
add_code exit_label
|
add_code exit_label
|
||||||
Risc::Builtin::Object.emit_syscall( builder , :exit )
|
Risc::Builtin::Object.emit_syscall( builder , :exit )
|
||||||
|
|
||||||
add_code ok_label
|
add_code ok_label
|
||||||
cache_entry[:cached_method] << typed_method
|
cache_entry[:cached_method] << callable_method
|
||||||
end
|
end
|
||||||
return builder.built
|
return builder.built
|
||||||
end
|
end
|
||||||
|
@ -10,7 +10,8 @@ require_relative "parfait/class"
|
|||||||
require_relative "parfait/list"
|
require_relative "parfait/list"
|
||||||
require_relative "parfait/word"
|
require_relative "parfait/word"
|
||||||
require_relative "parfait/binary_code"
|
require_relative "parfait/binary_code"
|
||||||
require_relative "parfait/typed_method"
|
require_relative "parfait/callable"
|
||||||
|
require_relative "parfait/callable_method"
|
||||||
require_relative "parfait/vool_method"
|
require_relative "parfait/vool_method"
|
||||||
require_relative "parfait/dictionary"
|
require_relative "parfait/dictionary"
|
||||||
require_relative "parfait/type"
|
require_relative "parfait/type"
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
# we resolve the method at runtime, and then cache it. Aaron has shown that over 99%
|
# we resolve the method at runtime, and then cache it. Aaron has shown that over 99%
|
||||||
# of call sites are type stable, so one cache entry at the moment
|
# of call sites are type stable, so one cache entry at the moment
|
||||||
#
|
#
|
||||||
# A cache entry stores the type of the object and the TypedMethod that is to be called
|
# A cache entry stores the type of the object and the CallableMethod that is to be called
|
||||||
# This is used in DynamicCall, see there
|
# This is used in DynamicCall, see there
|
||||||
#
|
#
|
||||||
module Parfait
|
module Parfait
|
||||||
|
@ -8,11 +8,12 @@ module Parfait
|
|||||||
# - frame_type: A type object describing the local variables that the method has
|
# - frame_type: A type object describing the local variables that the method has
|
||||||
# - binary: The binary (jumpable) code that instructions get assembled into
|
# - binary: The binary (jumpable) code that instructions get assembled into
|
||||||
# - blocks: linked list of blocks inside this method/block
|
# - blocks: linked list of blocks inside this method/block
|
||||||
|
# - next: next block/method at same level
|
||||||
#
|
#
|
||||||
class Callable < Object
|
class Callable < Object
|
||||||
|
|
||||||
attr_reader :self_type , :arguments_type , :frame_type , :binary , :blocks
|
attr_reader :self_type , :arguments_type , :frame_type , :binary
|
||||||
|
attr_reader :blocks, :next
|
||||||
def initialize( self_type , arguments_type , frame_type)
|
def initialize( self_type , arguments_type , frame_type)
|
||||||
super()
|
super()
|
||||||
raise "No class #{self}" unless self_type
|
raise "No class #{self}" unless self_type
|
||||||
@ -53,5 +54,10 @@ module Parfait
|
|||||||
bin = bin.next
|
bin = bin.next
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def set_next( method )
|
||||||
|
@next = method
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
40
lib/parfait/callable_method.rb
Normal file
40
lib/parfait/callable_method.rb
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
# A CallableMethod is static object that primarily holds the executable code.
|
||||||
|
# It is callable through it's binary code
|
||||||
|
# Additionally to the base class it has a name
|
||||||
|
#
|
||||||
|
# It's relation to the method a ruby programmer knows (called VoolMethod) is many to one,
|
||||||
|
# meaning one VoolMethod (untyped) has many CallableMethod implementations.
|
||||||
|
# The VoolMethod only holds vool code, no binary.
|
||||||
|
|
||||||
|
|
||||||
|
module Parfait
|
||||||
|
|
||||||
|
class CallableMethod < Callable
|
||||||
|
|
||||||
|
attr_reader :name
|
||||||
|
|
||||||
|
def initialize( self_type , name , arguments_type , frame_type)
|
||||||
|
@name = name
|
||||||
|
super(self_type , arguments_type , frame_type)
|
||||||
|
end
|
||||||
|
|
||||||
|
def ==(other)
|
||||||
|
return false unless other.is_a?(CallableMethod)
|
||||||
|
return false if @name != other.name
|
||||||
|
super
|
||||||
|
end
|
||||||
|
|
||||||
|
def rxf_reference_name
|
||||||
|
"Method: " + @name.to_s
|
||||||
|
end
|
||||||
|
|
||||||
|
def inspect
|
||||||
|
"#{@self_type.object_class.name}:#{name}(#{arguments_type.inspect})"
|
||||||
|
end
|
||||||
|
|
||||||
|
def each_method( &block )
|
||||||
|
block.call( self )
|
||||||
|
@next.each_method( &block ) if @next
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -12,7 +12,7 @@
|
|||||||
# An Object carries the data for the instance variables it has.
|
# An Object carries the data for the instance variables it has.
|
||||||
# The Type lists the names of the instance variables
|
# The Type lists the names of the instance variables
|
||||||
# The Class keeps a list of instance methods, these have a name and (vool) code
|
# The Class keeps a list of instance methods, these have a name and (vool) code
|
||||||
# Each type in turn has a list of TypedMethods that hold binary code
|
# Each type in turn has a list of CallableMethods that hold binary code
|
||||||
|
|
||||||
module Parfait
|
module Parfait
|
||||||
class Class < Object
|
class Class < Object
|
||||||
|
@ -87,12 +87,12 @@ module Parfait
|
|||||||
found.init(arguments , frame)
|
found.init(arguments , frame)
|
||||||
return found
|
return found
|
||||||
else
|
else
|
||||||
add_method TypedMethod.new( self , method_name , arguments , frame )
|
add_method CallableMethod.new( self , method_name , arguments , frame )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_method( method )
|
def add_method( method )
|
||||||
raise "not a method #{method.class} #{method.inspect}" unless method.is_a? TypedMethod
|
raise "not a method #{method.class} #{method.inspect}" unless method.is_a? CallableMethod
|
||||||
raise "syserr #{method.name.class}" unless method.name.is_a? Symbol
|
raise "syserr #{method.name.class}" unless method.name.is_a? Symbol
|
||||||
if self.is_a?(Class) and (method.self_type != self)
|
if self.is_a?(Class) and (method.self_type != self)
|
||||||
raise "Adding to wrong class, should be #{method.for_class}"
|
raise "Adding to wrong class, should be #{method.for_class}"
|
||||||
@ -109,16 +109,16 @@ module Parfait
|
|||||||
def remove_method( method_name )
|
def remove_method( method_name )
|
||||||
raise "No such method #{method_name} in #{self.name}" unless @methods
|
raise "No such method #{method_name} in #{self.name}" unless @methods
|
||||||
if( @methods.name == method_name)
|
if( @methods.name == method_name)
|
||||||
@methods = @methods.next_method
|
@methods = @methods.next
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
method = @methods
|
method = @methods
|
||||||
while(method && method.next_method)
|
while(method && method.next)
|
||||||
if( method.next_method.name == method_name)
|
if( method.next.name == method_name)
|
||||||
method.set_next( method.next_method.next_method )
|
method.set_next( method.next.next )
|
||||||
return true
|
return true
|
||||||
else
|
else
|
||||||
method = method.next_method
|
method = method.next
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
raise "No such method #{method_name} in #{self.name}"
|
raise "No such method #{method_name} in #{self.name}"
|
||||||
@ -144,6 +144,7 @@ module Parfait
|
|||||||
return method if method
|
return method if method
|
||||||
sup = object_class.super_class
|
sup = object_class.super_class
|
||||||
return nil unless sup
|
return nil unless sup
|
||||||
|
return nil if object_class.name == :Object
|
||||||
sup.instance_type.resolve_method(fname)
|
sup.instance_type.resolve_method(fname)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,53 +0,0 @@
|
|||||||
require_relative "callable"
|
|
||||||
# A TypedMethod is static object that primarily holds the executable code.
|
|
||||||
# It is called typed, because all arguments and variables it uses are "typed",
|
|
||||||
# that is to say the names are known and form a type (not that the types of the
|
|
||||||
# variables are known). The object's type is known too, which means all instances
|
|
||||||
# variable names are known (not their respective type).
|
|
||||||
|
|
||||||
# It's relation to the method a ruby programmer knows (called VoolMethod) is many to one,
|
|
||||||
# meaning one VoolMethod (untyped) has many TypedMethod implementations.
|
|
||||||
# The VoolMethod only holds vool code, no binary.
|
|
||||||
|
|
||||||
# The Typed method has the following instance variables
|
|
||||||
# - name : This is the same as the ruby method name it implements
|
|
||||||
# - binary: The binary (jumpable) code that the instructions get assembled into
|
|
||||||
# - arguments_type: A type object describing the arguments (name+types) to be passed
|
|
||||||
# - frame_type: A type object describing the local variables that the method has
|
|
||||||
# - self_type: The Type the Method is for
|
|
||||||
|
|
||||||
|
|
||||||
module Parfait
|
|
||||||
|
|
||||||
class TypedMethod < Callable
|
|
||||||
|
|
||||||
attr_reader :name , :next_method
|
|
||||||
|
|
||||||
def initialize( self_type , name , arguments_type , frame_type)
|
|
||||||
@name = name
|
|
||||||
super(self_type , arguments_type , frame_type)
|
|
||||||
end
|
|
||||||
|
|
||||||
def ==(other)
|
|
||||||
return false unless other.is_a?(TypedMethod)
|
|
||||||
return false if @name != other.name
|
|
||||||
super
|
|
||||||
end
|
|
||||||
|
|
||||||
def rxf_reference_name
|
|
||||||
"Method: " + @name.to_s
|
|
||||||
end
|
|
||||||
|
|
||||||
def inspect
|
|
||||||
"#{@self_type.object_class.name}:#{name}(#{arguments_type.inspect})"
|
|
||||||
end
|
|
||||||
|
|
||||||
def each_method( &block )
|
|
||||||
block.call( self )
|
|
||||||
next_method.each_method( &block ) if next_method
|
|
||||||
end
|
|
||||||
def set_next( method )
|
|
||||||
@next_method = method
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
@ -5,7 +5,7 @@ module Parfait
|
|||||||
# Type objects are already created for args and locals, but the main attribute
|
# Type objects are already created for args and locals, but the main attribute
|
||||||
# is the source, which is a Vool::Statement
|
# is the source, which is a Vool::Statement
|
||||||
#
|
#
|
||||||
# Classes store VoolMethods, while Types store TypedMethod
|
# Classes store VoolMethods, while Types store CallableMethod
|
||||||
# A Type referes to a Class , but a Class (interface) is implemented by many types
|
# A Type referes to a Class , but a Class (interface) is implemented by many types
|
||||||
# as it changes during the course of it's life. Types do not change. Objects have
|
# as it changes during the course of it's life. Types do not change. Objects have
|
||||||
# type, and so only indirectly a class.
|
# type, and so only indirectly a class.
|
||||||
@ -23,14 +23,14 @@ module Parfait
|
|||||||
raise "Empty bod" if(source.is_a?(Vool::Statements) and source.empty?)
|
raise "Empty bod" if(source.is_a?(Vool::Statements) and source.empty?)
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_typed_method( type )
|
def create_callable_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 , @frame_type)
|
type.create_method( @name , @args_type , @frame_type)
|
||||||
end
|
end
|
||||||
|
|
||||||
def compiler_for(self_type)
|
def compiler_for(self_type)
|
||||||
typed_method = create_typed_method(self_type)
|
callable_method = create_callable_method(self_type)
|
||||||
compiler = Risc::MethodCompiler.new( typed_method )
|
compiler = Risc::MethodCompiler.new( callable_method )
|
||||||
head = source.to_mom( compiler )
|
head = source.to_mom( compiler )
|
||||||
compiler.add_mom(head)
|
compiler.add_mom(head)
|
||||||
compiler
|
compiler
|
||||||
|
@ -6,7 +6,7 @@ It is the other side of the parfait coin, part of the runtime.
|
|||||||
The functions are organised by their respective classes and get loaded in boot_classes! ,
|
The functions are organised by their respective classes and get loaded in boot_classes! ,
|
||||||
right at the start. (see register/boot.rb)
|
right at the start. (see register/boot.rb)
|
||||||
|
|
||||||
These functions return their code, ie a Parfait::TypedMethod with a MethodSource object,
|
These functions return their code, ie a Parfait::CallableMethod with a MethodSource object,
|
||||||
which can then be called by ruby code as if it were a "normal" function.
|
which can then be called by ruby code as if it were a "normal" function.
|
||||||
|
|
||||||
A normal ruby function is one that is parsed and transformed to code. But not all
|
A normal ruby function is one that is parsed and transformed to code. But not all
|
||||||
|
@ -35,11 +35,11 @@ module Risc
|
|||||||
return true if objekt.is_a? Fixnum
|
return true if objekt.is_a? Fixnum
|
||||||
return true if objekt.is_a?( Risc::Label)
|
return true if objekt.is_a?( Risc::Label)
|
||||||
#puts message(objekt , depth)
|
#puts message(objekt , depth)
|
||||||
#puts "ADD #{objekt.inspect}, #{objekt.name}" if objekt.is_a? Parfait::TypedMethod
|
#puts "ADD #{objekt.inspect}, #{objekt.name}" if objekt.is_a? Parfait::CallableMethod
|
||||||
unless objekt.is_a?( Parfait::Object) or objekt.is_a?( Symbol)
|
unless objekt.is_a?( Parfait::Object) or objekt.is_a?( Symbol)
|
||||||
raise "adding non parfait #{objekt.class}:#{objekt}"
|
raise "adding non parfait #{objekt.class}:#{objekt}"
|
||||||
end
|
end
|
||||||
#raise "Method #{objekt.name}" if objekt.is_a? Parfait::TypedMethod
|
#raise "Method #{objekt.name}" if objekt.is_a? Parfait::CallableMethod
|
||||||
Position.get_or_create(objekt)
|
Position.get_or_create(objekt)
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
@ -27,7 +27,7 @@ module Risc
|
|||||||
@next = nekst
|
@next = nekst
|
||||||
return unless source
|
return unless source
|
||||||
raise "Source must be string or Instruction, not #{source.class}" unless source.is_a?(String) or
|
raise "Source must be string or Instruction, not #{source.class}" unless source.is_a?(String) or
|
||||||
source.is_a?(Mom::Instruction) or source.is_a?(Parfait::TypedMethod)
|
source.is_a?(Mom::Instruction) or source.is_a?(Parfait::CallableMethod)
|
||||||
end
|
end
|
||||||
attr_reader :source
|
attr_reader :source
|
||||||
|
|
||||||
|
@ -115,48 +115,56 @@ module Parfait
|
|||||||
|
|
||||||
# superclasses other than default object
|
# superclasses other than default object
|
||||||
def self.super_class_names
|
def self.super_class_names
|
||||||
{ Data4: :DataObject , Data8: :DataObject ,Data16: :DataObject ,
|
{ Data4: :DataObject ,
|
||||||
|
Data8: :DataObject ,
|
||||||
|
Data16: :DataObject ,
|
||||||
Data32: :DataObject ,
|
Data32: :DataObject ,
|
||||||
BinaryCode: :Data16 , Integer: :Data4 , Word: :Data8 ,
|
BinaryCode: :Data16 ,
|
||||||
Object: :BasicObject, List: :Data16 , ReturnAddress: :Integer}
|
Integer: :Data4 ,
|
||||||
|
Word: :Data8 ,
|
||||||
|
List: :Data16 ,
|
||||||
|
CallableMethod: :Callable,
|
||||||
|
ReturnAddress: :Integer}
|
||||||
end
|
end
|
||||||
|
|
||||||
# the function really just returns a constant (just avoiding the constant)
|
# the function really just returns a constant (just avoiding the constant)
|
||||||
# unfortuantely that constant condenses every detail about the system, class names
|
# unfortuantely that constant condenses every detail about the system, class names
|
||||||
# and all instance variable names. Really have to find a better way
|
# and all instance variable names. Really have to find a better way
|
||||||
def self.type_names
|
def self.type_names
|
||||||
{ Word: {char_length: :Integer , next_word: :Word} ,
|
{BinaryCode: {next: :BinaryCode} ,
|
||||||
List: {indexed_length: :Integer , next_list: :List} ,
|
CacheEntry: {cached_type: :Type , cached_method: :CallableMethod } ,
|
||||||
Message: { next_message: :Message, receiver: :Object, frame: :NamedList ,
|
Callable: {binary: :BinaryCode,next: :Callable ,
|
||||||
return_address: :Integer, return_value: :Object,
|
arguments_type: :Type , self_type: :Type, frame_type: :Type } ,
|
||||||
caller: :Message , name: :Word , arguments: :NamedList },
|
CallableMethod: {name: :Word, binary: :BinaryCode,
|
||||||
Integer: {next_integer: :Integer},
|
arguments_type: :Type , self_type: :Type, frame_type: :Type ,
|
||||||
ReturnAddress: {next_integer: :ReturnAddress},
|
next: :CallableMethod} ,
|
||||||
DataObject: {},
|
Class: {instance_methods: :List, instance_type: :Type,
|
||||||
Data4: {},
|
name: :Word, super_class_name: :Word },
|
||||||
Data8: {},
|
DataObject: {},
|
||||||
TrueClass: {},
|
Data4: {},
|
||||||
FalseClass: {},
|
Data8: {},
|
||||||
NilClass: {},
|
Data16: {},
|
||||||
Object: {},
|
Dictionary: {keys: :List , values: :List } ,
|
||||||
BinaryCode: {next: :BinaryCode} ,
|
Integer: {next_integer: :Integer},
|
||||||
Space: {classes: :Dictionary , types: :Dictionary ,
|
FalseClass: {},
|
||||||
next_message: :Message , messages: :Message ,
|
List: {indexed_length: :Integer , next_list: :List} ,
|
||||||
next_integer: :Integer, integers: :Integer ,
|
Message: { next_message: :Message, receiver: :Object, frame: :NamedList ,
|
||||||
next_address: :ReturnAddress ,addresses: :ReturnAddress ,
|
return_address: :Integer, return_value: :Object,
|
||||||
true_object: :TrueClass, false_object: :FalseClass , nil_object: :NilClass},
|
caller: :Message , name: :Word , arguments: :NamedList },
|
||||||
NamedList: {},
|
NamedList: {},
|
||||||
Type: {names: :List , types: :List ,
|
NilClass: {},
|
||||||
object_class: :Class, methods: :TypedMethod } ,
|
Object: {},
|
||||||
Class: {instance_methods: :List, instance_type: :Type,
|
ReturnAddress: {next_integer: :ReturnAddress},
|
||||||
name: :Word, super_class_name: :Word },
|
Space: {classes: :Dictionary , types: :Dictionary ,
|
||||||
Dictionary: {keys: :List , values: :List } ,
|
next_message: :Message , messages: :Message ,
|
||||||
CacheEntry: {cached_type: :Type , cached_method: :TypedMethod } ,
|
next_integer: :Integer, integers: :Integer ,
|
||||||
TypedMethod: {name: :Word, risc_instructions: :Object,
|
next_address: :ReturnAddress ,addresses: :ReturnAddress ,
|
||||||
cpu_instructions: :Object, binary: :BinaryCode,
|
true_object: :TrueClass, false_object: :FalseClass , nil_object: :NilClass},
|
||||||
arguments_type: :Type , self_type: :Type, frame_type: :Type ,
|
TrueClass: {},
|
||||||
next_method: :TypedMethod} ,
|
Type: {names: :List , types: :List ,
|
||||||
VoolMethod: { name: :Word , args_type: :Type , frame_type: :Type } ,
|
object_class: :Class, methods: :CallableMethod } ,
|
||||||
|
VoolMethod: { name: :Word , args_type: :Type , frame_type: :Type } ,
|
||||||
|
Word: {char_length: :Integer , next_word: :Word} ,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -18,7 +18,7 @@ module Arm
|
|||||||
assert_equal :r1 , @codes.left
|
assert_equal :r1 , @codes.left
|
||||||
end
|
end
|
||||||
def test_slot_right
|
def test_slot_right
|
||||||
assert_equal 16 , @codes.right
|
assert_equal 8 , @codes.right
|
||||||
end
|
end
|
||||||
def test_next_from
|
def test_next_from
|
||||||
assert_equal :r1 , @codes.next.from.symbol
|
assert_equal :r1 , @codes.next.from.symbol
|
||||||
|
@ -21,7 +21,7 @@ module Risc
|
|||||||
end
|
end
|
||||||
def test_load_method
|
def test_load_method
|
||||||
method = @produced
|
method = @produced
|
||||||
assert_load( method, Parfait::TypedMethod ,:r1)
|
assert_load( method, Parfait::CallableMethod ,:r1)
|
||||||
assert_equal :div4 , method.constant.name
|
assert_equal :div4 , method.constant.name
|
||||||
end
|
end
|
||||||
def test_load_space
|
def test_load_space
|
||||||
@ -43,7 +43,7 @@ module Risc
|
|||||||
|
|
||||||
def test_get_args_type #from method in r1
|
def test_get_args_type #from method in r1
|
||||||
sl = @produced.next( 5 )
|
sl = @produced.next( 5 )
|
||||||
assert_slot_to_reg( sl , :r1 , 5 , :r4 )
|
assert_slot_to_reg( sl , :r1 , 3 , :r4 )
|
||||||
end
|
end
|
||||||
def test_get_args #from message
|
def test_get_args #from message
|
||||||
sl = @produced.next( 6 )
|
sl = @produced.next( 6 )
|
||||||
@ -56,7 +56,7 @@ module Risc
|
|||||||
|
|
||||||
def test_get_frame_type #from method in r1
|
def test_get_frame_type #from method in r1
|
||||||
sl = @produced.next( 8 )
|
sl = @produced.next( 8 )
|
||||||
assert_slot_to_reg( sl , :r1 , 7 , :r4 )
|
assert_slot_to_reg( sl , :r1 , 5 , :r4 )
|
||||||
end
|
end
|
||||||
def test_get_frame #from message
|
def test_get_frame #from message
|
||||||
sl = @produced.next( 9 )
|
sl = @produced.next( 9 )
|
||||||
|
@ -8,7 +8,7 @@ module Parfait
|
|||||||
@obj = Parfait.object_space.get_class_by_name(:Object).instance_type
|
@obj = Parfait.object_space.get_class_by_name(:Object).instance_type
|
||||||
@args = Parfait::Type.for_hash( @obj.object_class , { bar: :Integer , foo: :Type})
|
@args = Parfait::Type.for_hash( @obj.object_class , { bar: :Integer , foo: :Type})
|
||||||
@frame = Parfait::Type.for_hash( @obj.object_class , { local_bar: :Integer , local_foo: :Type})
|
@frame = Parfait::Type.for_hash( @obj.object_class , { local_bar: :Integer , local_foo: :Type})
|
||||||
@method = Parfait::TypedMethod.new( @obj , :meth , @args , @frame)
|
@method = Parfait::CallableMethod.new( @obj , :meth , @args , @frame)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_method_name
|
def test_method_name
|
||||||
@ -99,7 +99,7 @@ module Parfait
|
|||||||
assert_equal @method , @method
|
assert_equal @method , @method
|
||||||
end
|
end
|
||||||
def test_not_equal
|
def test_not_equal
|
||||||
method = Parfait::TypedMethod.new( @obj , :other , @args , @frame)
|
method = Parfait::CallableMethod.new( @obj , :other , @args , @frame)
|
||||||
assert @method != method
|
assert @method != method
|
||||||
end
|
end
|
||||||
end
|
end
|
@ -4,9 +4,10 @@ module Parfait
|
|||||||
class TestSpace < ParfaitTest
|
class TestSpace < ParfaitTest
|
||||||
|
|
||||||
def classes
|
def classes
|
||||||
[:Word,:List,:Message,:Integer,:ReturnAddress,:DataObject,:Data4,:Data8,
|
[:BinaryCode,:CacheEntry,:Callable,:CallableMethod,:Class,
|
||||||
:TrueClass,:FalseClass,:NilClass,:Object,:BinaryCode,:Space,:NamedList,
|
:DataObject,:Data4,:Data8,:Data16,:Dictionary,:Integer,:FalseClass,
|
||||||
:Type,:Class,:Dictionary,:CacheEntry,:TypedMethod,:VoolMethod]
|
:List,:Message,:NamedList,:NilClass,:Object,:ReturnAddress,
|
||||||
|
:Space,:TrueClass,:Type,:VoolMethod,:Word]
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_space_length
|
def test_space_length
|
||||||
|
@ -22,13 +22,13 @@ module Parfait
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_name
|
def test_name
|
||||||
assert_equal "Word_Type" , @types.values.first.name
|
assert_equal "BinaryCode_Type" , @types.values.first.name
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_to_hash
|
def test_to_hash
|
||||||
hash = @first.to_hash
|
hash = @first.to_hash
|
||||||
assert_equal hash[:type] , :Type
|
assert_equal hash[:type] , :Type
|
||||||
assert_equal 3 , hash.length
|
assert_equal 2 , hash.length
|
||||||
end
|
end
|
||||||
def test_add_is_different
|
def test_add_is_different
|
||||||
type = @first.add_instance_variable :random , :Integer
|
type = @first.add_instance_variable :random , :Integer
|
||||||
|
@ -14,7 +14,7 @@ module Parfait
|
|||||||
end
|
end
|
||||||
def foo_method( for_class = :Try)
|
def foo_method( for_class = :Try)
|
||||||
args = Parfait::Type.for_hash( @try_class , { bar: :Integer})
|
args = Parfait::Type.for_hash( @try_class , { bar: :Integer})
|
||||||
::Parfait::TypedMethod.new( @space.get_class_by_name(for_class).instance_type , :foo , args,empty_frame)
|
::Parfait::CallableMethod.new( @space.get_class_by_name(for_class).instance_type , :foo , args,empty_frame)
|
||||||
end
|
end
|
||||||
def add_foo_to( clazz = :Try )
|
def add_foo_to( clazz = :Try )
|
||||||
foo = foo_method( clazz )
|
foo = foo_method( clazz )
|
||||||
@ -50,7 +50,7 @@ module Parfait
|
|||||||
end
|
end
|
||||||
def test_method_get
|
def test_method_get
|
||||||
add_foo_to
|
add_foo_to
|
||||||
assert_equal Parfait::TypedMethod , @try_type.get_method(:foo).class
|
assert_equal Parfait::CallableMethod , @try_type.get_method(:foo).class
|
||||||
end
|
end
|
||||||
def test_method_get_nothere
|
def test_method_get_nothere
|
||||||
assert_nil @try_type.get_method(:foo)
|
assert_nil @try_type.get_method(:foo)
|
||||||
|
@ -45,7 +45,7 @@ module Risc
|
|||||||
ret = main_ticks(63)
|
ret = main_ticks(63)
|
||||||
assert_equal FunctionReturn , ret.class
|
assert_equal FunctionReturn , ret.class
|
||||||
assert_equal :r1 , ret.register.symbol
|
assert_equal :r1 , ret.register.symbol
|
||||||
assert_equal 21924 , @interpreter.get_register(ret.register)
|
assert_equal 21476 , @interpreter.get_register(ret.register)
|
||||||
end
|
end
|
||||||
def test_sys
|
def test_sys
|
||||||
sys = main_ticks(68)
|
sys = main_ticks(68)
|
||||||
|
@ -92,7 +92,7 @@ module Risc
|
|||||||
assert_equal @label , ret.label
|
assert_equal @label , ret.label
|
||||||
end
|
end
|
||||||
def test_minus
|
def test_minus
|
||||||
op = @builder.build {space - typed_method}
|
op = @builder.build {space - callable_method}
|
||||||
assert_equal OperatorInstruction , op.class
|
assert_equal OperatorInstruction , op.class
|
||||||
assert_equal :- , op.operator
|
assert_equal :- , op.operator
|
||||||
assert_equal :Space , op.left.type
|
assert_equal :Space , op.left.type
|
||||||
|
@ -54,7 +54,7 @@ module Risc
|
|||||||
end
|
end
|
||||||
def test_pc1
|
def test_pc1
|
||||||
@interpreter.tick
|
@interpreter.tick
|
||||||
assert_equal 21432 , @interpreter.pc
|
assert_equal 21048 , @interpreter.pc
|
||||||
end
|
end
|
||||||
def test_tick2
|
def test_tick2
|
||||||
@interpreter.tick
|
@interpreter.tick
|
||||||
@ -68,7 +68,7 @@ module Risc
|
|||||||
def test_pc2
|
def test_pc2
|
||||||
@interpreter.tick
|
@interpreter.tick
|
||||||
@interpreter.tick
|
@interpreter.tick
|
||||||
assert_equal 21436 , @interpreter.pc
|
assert_equal 21052 , @interpreter.pc
|
||||||
end
|
end
|
||||||
def test_tick_14_jump
|
def test_tick_14_jump
|
||||||
14.times {@interpreter.tick}
|
14.times {@interpreter.tick}
|
||||||
|
@ -25,7 +25,7 @@ module Risc
|
|||||||
assert_equal 0 , Position.get(@linker.cpu_init).at
|
assert_equal 0 , Position.get(@linker.cpu_init).at
|
||||||
end
|
end
|
||||||
def test_cpu_at
|
def test_cpu_at
|
||||||
assert_equal "0x626c" , Position.get(@linker.cpu_init.first).to_s
|
assert_equal "0x60ec" , Position.get(@linker.cpu_init.first).to_s
|
||||||
end
|
end
|
||||||
def test_cpu_label
|
def test_cpu_label
|
||||||
assert_equal Position , Position.get(@linker.cpu_init.first).class
|
assert_equal Position , Position.get(@linker.cpu_init.first).class
|
||||||
|
@ -59,14 +59,14 @@ module Risc
|
|||||||
assert_equal Parfait::Class , vool.body.first.clazz.class
|
assert_equal Parfait::Class , vool.body.first.clazz.class
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_typed_method_instance_type
|
def test_callable_method_instance_type
|
||||||
in_test_vool("def meth; @ivar = 5; @ibar = 4;end")
|
in_test_vool("def meth; @ivar = 5; @ibar = 4;end")
|
||||||
test = Parfait.object_space.get_class_by_name(:Test)
|
test = Parfait.object_space.get_class_by_name(:Test)
|
||||||
method = test.instance_type.get_method(:meth)
|
method = test.instance_type.get_method(:meth)
|
||||||
assert_equal 1, method.self_type.variable_index(:ivar)
|
assert_equal 1, method.self_type.variable_index(:ivar)
|
||||||
assert_equal 2, method.self_type.variable_index(:ibar)
|
assert_equal 2, method.self_type.variable_index(:ibar)
|
||||||
end
|
end
|
||||||
def test_typed_method_has_one_local
|
def test_callable_method_has_one_local
|
||||||
in_test_vool("def meth; local = 5 ; a = 6;end")
|
in_test_vool("def meth; local = 5 ; a = 6;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)
|
||||||
|
@ -35,7 +35,7 @@ module Vool
|
|||||||
assert_equal Mom::SimpleCall, @ins.next(2).class
|
assert_equal Mom::SimpleCall, @ins.next(2).class
|
||||||
end
|
end
|
||||||
def test_call_has_method
|
def test_call_has_method
|
||||||
assert_equal Parfait::TypedMethod, @ins.next(2).method.class
|
assert_equal Parfait::CallableMethod, @ins.next(2).method.class
|
||||||
end
|
end
|
||||||
def test_array
|
def test_array
|
||||||
check_array [Mom::MessageSetup,Mom::ArgumentTransfer,Mom::SimpleCall] , @ins
|
check_array [Mom::MessageSetup,Mom::ArgumentTransfer,Mom::SimpleCall] , @ins
|
||||||
|
@ -18,7 +18,7 @@ module Vool
|
|||||||
assert_equal SimpleCall, @ins.next(2).class
|
assert_equal SimpleCall, @ins.next(2).class
|
||||||
end
|
end
|
||||||
def test_call_has_method
|
def test_call_has_method
|
||||||
assert_equal Parfait::TypedMethod, @ins.next(2).method.class
|
assert_equal Parfait::CallableMethod, @ins.next(2).method.class
|
||||||
end
|
end
|
||||||
def test_call_has_right_method
|
def test_call_has_right_method
|
||||||
assert_equal :get_internal_word, @ins.next(2).method.name
|
assert_equal :get_internal_word, @ins.next(2).method.name
|
||||||
|
Loading…
Reference in New Issue
Block a user