stop pinning self and frame
before: r0-message , r1-self , r2-frame , r3-new_message , r4 + tmps now: r0-message , r1-new_message , r2 + tmps programs got smaller, less fuss also fix in return implementation that got the address from the wrong message
This commit is contained in:
parent
da5502e301
commit
6c7e4c0fe2
@ -16,7 +16,9 @@ module Phisol
|
|||||||
index = @method.has_local( name )
|
index = @method.has_local( name )
|
||||||
if(index)
|
if(index)
|
||||||
# TODO, check type @method.locals[index].type
|
# TODO, check type @method.locals[index].type
|
||||||
code = Register.set_slot(statement , v , :frame , index )
|
frame = use_reg(:Frame)
|
||||||
|
@method.source.add_code Register.get_slot(statement , :message , :frame , frame )
|
||||||
|
code = Register.set_slot(statement , v , frame , index )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if( code )
|
if( code )
|
||||||
|
@ -7,14 +7,15 @@ module Phisol
|
|||||||
name = name.to_a.first
|
name = name.to_a.first
|
||||||
raise "not inside method " unless @method
|
raise "not inside method " unless @method
|
||||||
reset_regs
|
reset_regs
|
||||||
if receiver
|
|
||||||
me = process( receiver.to_a.first )
|
|
||||||
else
|
|
||||||
me = Register.self_reg @method.for_class.name
|
|
||||||
end
|
|
||||||
#move the new message (that we need to populate to make a call) to std register
|
#move the new message (that we need to populate to make a call) to std register
|
||||||
new_message = Register.resolve_to_register(:new_message)
|
new_message = Register.resolve_to_register(:new_message)
|
||||||
@method.source.add_code Register.get_slot(@method, :message , :next_message , new_message )
|
@method.source.add_code Register.get_slot(@method, :message , :next_message , new_message )
|
||||||
|
if receiver
|
||||||
|
me = process( receiver.to_a.first )
|
||||||
|
else
|
||||||
|
me = use_reg @method.for_class.name
|
||||||
|
@method.source.add_code Register.get_slot(@method, :message , :receiver , me )
|
||||||
|
end
|
||||||
# move our receiver there
|
# move our receiver there
|
||||||
@method.source.add_code Register.set_slot( statement , me , :new_message , :receiver)
|
@method.source.add_code Register.set_slot( statement , me , :new_message , :receiver)
|
||||||
# load method name and set to new message (for exceptions/debug)
|
# load method name and set to new message (for exceptions/debug)
|
||||||
|
@ -11,8 +11,10 @@ module Phisol
|
|||||||
when :self
|
when :self
|
||||||
index = @clazz.object_layout.variable_index(field_name)
|
index = @clazz.object_layout.variable_index(field_name)
|
||||||
raise "field access, but no such field:#{field_name} for class #{@clazz.name}" unless index
|
raise "field access, but no such field:#{field_name} for class #{@clazz.name}" unless index
|
||||||
value = use_reg(:Integer) #TODO, need types in layout
|
value = use_reg(@clazz.name) #TODO incorrect, this is the self, but should be the type of variable at index
|
||||||
move = Register.get_slot(statement, :self , index , value )
|
@method.source.add_code Register.get_slot(statement , :message , :receiver , value )
|
||||||
|
# reuse the register for next move
|
||||||
|
move = Register.get_slot(statement, value , index , value )
|
||||||
@method.source.add_code move
|
@method.source.add_code move
|
||||||
return value
|
return value
|
||||||
when :message
|
when :message
|
||||||
|
@ -7,7 +7,11 @@ module Phisol
|
|||||||
# whichever way this goes the result is stored in the return slot (as all compiles)
|
# whichever way this goes the result is stored in the return slot (as all compiles)
|
||||||
def on_name statement
|
def on_name statement
|
||||||
name = statement.to_a.first
|
name = statement.to_a.first
|
||||||
return Register.self_reg(@clazz.name ) if(name == :self)
|
if( name == :self)
|
||||||
|
ret = use_reg @clazz.name
|
||||||
|
@method.source.add_code Register.get_slot(statement , :message , :receiver , ret )
|
||||||
|
return ret
|
||||||
|
end
|
||||||
# either an argument, so it's stored in message
|
# either an argument, so it's stored in message
|
||||||
if( index = @method.has_arg(name))
|
if( index = @method.has_arg(name))
|
||||||
ret = use_reg @method.arguments[index].type
|
ret = use_reg @method.arguments[index].type
|
||||||
@ -16,8 +20,10 @@ module Phisol
|
|||||||
else # or a local so it is in the frame
|
else # or a local so it is in the frame
|
||||||
index = @method.has_local( name )
|
index = @method.has_local( name )
|
||||||
if(index)
|
if(index)
|
||||||
|
frame = use_reg :Frame
|
||||||
|
@method.source.add_code Register.get_slot(statement , :message , :frame , frame )
|
||||||
ret = use_reg @method.locals[index].type
|
ret = use_reg @method.locals[index].type
|
||||||
@method.source.add_code Register.get_slot(statement , :frame , index , ret )
|
@method.source.add_code Register.get_slot(statement , frame , index , ret )
|
||||||
return ret
|
return ret
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -3,6 +3,7 @@ module Register
|
|||||||
module Builtin
|
module Builtin
|
||||||
module Integer
|
module Integer
|
||||||
module ClassMethods
|
module ClassMethods
|
||||||
|
include AST::Sexp
|
||||||
def plus c
|
def plus c
|
||||||
plus_function = Virtual::MethodSource.create_method(:Integer,:Integer,:plus , [:Integer] )
|
plus_function = Virtual::MethodSource.create_method(:Integer,:Integer,:plus , [:Integer] )
|
||||||
plus_function.source.set_return_type :Integer
|
plus_function.source.set_return_type :Integer
|
||||||
@ -11,8 +12,12 @@ module Register
|
|||||||
tmp = Register.tmp_reg :Integer
|
tmp = Register.tmp_reg :Integer
|
||||||
index = Register.arg_index 1
|
index = Register.arg_index 1
|
||||||
plus_function.source.add_code Register.get_slot( plus_function , :message , index , tmp )
|
plus_function.source.add_code Register.get_slot( plus_function , :message , index , tmp )
|
||||||
add = Register::OperatorInstruction.new( plus_function, :add , Register.self_reg(:Integer) , tmp )
|
|
||||||
|
me = Register.tmp_reg :Integer
|
||||||
|
plus_function.source.add_code Register.get_slot(plus_function , :message , :receiver , me )
|
||||||
|
add = Register::OperatorInstruction.new( plus_function, :add , me , tmp )
|
||||||
plus_function.source.add_code add
|
plus_function.source.add_code add
|
||||||
|
plus_function.source.add_code Register.set_slot(plus_function , me , :message , :return_value )
|
||||||
return plus_function
|
return plus_function
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -13,12 +13,13 @@ module Register
|
|||||||
function.source.blocks.last.codes.pop # no Method return
|
function.source.blocks.last.codes.pop # no Method return
|
||||||
#Set up the Space as self upon init
|
#Set up the Space as self upon init
|
||||||
space = Parfait::Space.object_space
|
space = Parfait::Space.object_space
|
||||||
function.source.add_code LoadConstant.new(function, space , Register.self_reg(:Space))
|
space_reg = Register.tmp_reg(:Space)
|
||||||
|
function.source.add_code LoadConstant.new(function, space , space_reg)
|
||||||
message_ind = Register.resolve_index( :space , :first_message )
|
message_ind = Register.resolve_index( :space , :first_message )
|
||||||
# Load the message to new message register (r3)
|
# Load the message to new message register (r1)
|
||||||
function.source.add_code Register.get_slot( function , :self , message_ind , :new_message)
|
function.source.add_code Register.get_slot( function , space_reg , message_ind , :new_message)
|
||||||
# And store the space as the new self (so the call can move it back as self)
|
# And store the space as the new self (so the call can move it back as self)
|
||||||
function.source.add_code Register.set_slot( function, :self , :new_message , :receiver)
|
function.source.add_code Register.set_slot( function, space_reg , :new_message , :receiver)
|
||||||
# now we are set up to issue a call to the main
|
# now we are set up to issue a call to the main
|
||||||
function.source.add_code Virtual::MethodCall.new(Virtual.machine.space.get_main)
|
function.source.add_code Virtual::MethodCall.new(Virtual.machine.space.get_main)
|
||||||
emit_syscall( function , :exit )
|
emit_syscall( function , :exit )
|
||||||
@ -63,8 +64,6 @@ module Register
|
|||||||
# save the return value into the message
|
# save the return value into the message
|
||||||
function.source.add_code Register.set_slot( function, return_tmp , :message , :return_value )
|
function.source.add_code Register.set_slot( function, return_tmp , :message , :return_value )
|
||||||
# and "unroll" self and frame
|
# and "unroll" self and frame
|
||||||
function.source.add_code Register.get_slot(function, :message , :receiver, :self )
|
|
||||||
function.source.add_code Register.get_slot(function, :message , :frame , :frame)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
extend ClassMethods
|
extend ClassMethods
|
||||||
|
@ -4,6 +4,7 @@ module Register
|
|||||||
module ClassMethods
|
module ClassMethods
|
||||||
def putstring context
|
def putstring context
|
||||||
function = Virtual::MethodSource.create_method(:Word,:Integer , :putstring , [] )
|
function = Virtual::MethodSource.create_method(:Word,:Integer , :putstring , [] )
|
||||||
|
function.source.add_code Register.get_slot( function , :message , :receiver , :new_message )
|
||||||
Kernel.emit_syscall( function , :putstring )
|
Kernel.emit_syscall( function , :putstring )
|
||||||
function
|
function
|
||||||
end
|
end
|
||||||
|
@ -14,8 +14,6 @@ module Register
|
|||||||
new_codes = []
|
new_codes = []
|
||||||
# move the current new_message to message
|
# move the current new_message to message
|
||||||
new_codes << RegisterTransfer.new(code, Register.new_message_reg , Register.message_reg )
|
new_codes << RegisterTransfer.new(code, Register.new_message_reg , Register.message_reg )
|
||||||
# "roll out" self into its register
|
|
||||||
new_codes << Register.get_slot( code , :message , :receiver, :self )
|
|
||||||
# do the register call
|
# do the register call
|
||||||
new_codes << FunctionCall.new( code , code.method )
|
new_codes << FunctionCall.new( code , code.method )
|
||||||
block.replace(code , new_codes )
|
block.replace(code , new_codes )
|
||||||
|
@ -8,11 +8,8 @@ module Register
|
|||||||
new_codes << RegisterTransfer.new(code, Register.message_reg , Register.new_message_reg )
|
new_codes << RegisterTransfer.new(code, Register.message_reg , Register.new_message_reg )
|
||||||
# and restore the message from saved value in new_message
|
# and restore the message from saved value in new_message
|
||||||
new_codes << Register.get_slot(code,:new_message , :caller , :message )
|
new_codes << Register.get_slot(code,:new_message , :caller , :message )
|
||||||
# "roll out" self and frame into their registers
|
|
||||||
new_codes << Register.get_slot(code, :message , :receiver , :self )
|
|
||||||
new_codes << Register.get_slot(code, :message , :frame , :frame )
|
|
||||||
#load the return address into pc, affecting return. (other cpus have commands for this, but not arm)
|
#load the return address into pc, affecting return. (other cpus have commands for this, but not arm)
|
||||||
new_codes << FunctionReturn.new( code , Register.message_reg , Register.resolve_index(:message , :return_address) )
|
new_codes << FunctionReturn.new( code , Register.new_message_reg , Register.resolve_index(:message , :return_address) )
|
||||||
block.replace(code , new_codes )
|
block.replace(code , new_codes )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -65,27 +65,16 @@ module Register
|
|||||||
RegisterValue.new :r0 , :Message
|
RegisterValue.new :r0 , :Message
|
||||||
end
|
end
|
||||||
|
|
||||||
# A register to hold the receiver of the current message, in oo terms the self. :r1
|
|
||||||
def self.self_reg type
|
|
||||||
RegisterValue.new :r1 , type
|
|
||||||
end
|
|
||||||
|
|
||||||
# The register to hold a possible frame of the currently executing method. :r2
|
|
||||||
# May be nil if the method has no local variables
|
|
||||||
def self.frame_reg
|
|
||||||
RegisterValue.new :r2 , :Frame
|
|
||||||
end
|
|
||||||
|
|
||||||
# The register we use to store the new message object is :r3
|
# The register we use to store the new message object is :r3
|
||||||
# The new message is the one being built, to be sent
|
# The new message is the one being built, to be sent
|
||||||
def self.new_message_reg
|
def self.new_message_reg
|
||||||
RegisterValue.new :r3 , :Message
|
RegisterValue.new :r1 , :Message
|
||||||
end
|
end
|
||||||
|
|
||||||
# The first scratch register. There is a next_reg_use to get a next and next.
|
# The first scratch register. There is a next_reg_use to get a next and next.
|
||||||
# Current thinking is that scratch is schatch between instructions
|
# Current thinking is that scratch is schatch between instructions
|
||||||
def self.tmp_reg type , value = nil
|
def self.tmp_reg type , value = nil
|
||||||
RegisterValue.new :r4 , type , value
|
RegisterValue.new :r2 , type , value
|
||||||
end
|
end
|
||||||
|
|
||||||
# The first arg is a class name (possibly lowercase) and the second an instance variable name.
|
# The first arg is a class name (possibly lowercase) and the second an instance variable name.
|
||||||
@ -116,8 +105,10 @@ module Register
|
|||||||
when :new_message
|
when :new_message
|
||||||
register = new_message_reg
|
register = new_message_reg
|
||||||
when :self
|
when :self
|
||||||
|
raise "self good?"
|
||||||
register = self_reg(:Object) #TODO , probably have to get rid of this resolve method
|
register = self_reg(:Object) #TODO , probably have to get rid of this resolve method
|
||||||
when :frame
|
when :frame
|
||||||
|
raise "frame good?"
|
||||||
register = frame_reg
|
register = frame_reg
|
||||||
else
|
else
|
||||||
raise "not recognized register reference #{reference}"
|
raise "not recognized register reference #{reference}"
|
||||||
|
@ -7,10 +7,6 @@ module Virtual
|
|||||||
new_codes = []
|
new_codes = []
|
||||||
# save return register to the message at instance return_address
|
# save return register to the message at instance return_address
|
||||||
new_codes << Register.save_return(code, :message , :return_address)
|
new_codes << Register.save_return(code, :message , :return_address)
|
||||||
# and create a new frame if needed
|
|
||||||
unless code.method.locals.empty?
|
|
||||||
new_codes << Register.get_slot( code, :message , :frame , Register.resolve_to_register(:frame))
|
|
||||||
end
|
|
||||||
block.replace(code , new_codes )
|
block.replace(code , new_codes )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -29,7 +29,7 @@ class Object
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
HERE
|
HERE
|
||||||
@expect = [[Virtual::MethodEnter,LoadConstant,SetSlot] , [Virtual::MethodReturn]]
|
@expect = [[Virtual::MethodEnter,LoadConstant,GetSlot,SetSlot] , [Virtual::MethodReturn]]
|
||||||
check
|
check
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ end
|
|||||||
end
|
end
|
||||||
HERE
|
HERE
|
||||||
@expect = [[Virtual::MethodEnter,LoadConstant,LoadConstant,
|
@expect = [[Virtual::MethodEnter,LoadConstant,LoadConstant,
|
||||||
OperatorInstruction,SetSlot],[Virtual::MethodReturn]]
|
OperatorInstruction,GetSlot,SetSlot],[Virtual::MethodReturn]]
|
||||||
check
|
check
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ class Object
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
HERE
|
HERE
|
||||||
@expect = [[Virtual::MethodEnter,LoadConstant,SetSlot] , [Virtual::MethodReturn]]
|
@expect = [[Virtual::MethodEnter,LoadConstant,GetSlot,SetSlot] , [Virtual::MethodReturn]]
|
||||||
check
|
check
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ class Object
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
HERE
|
HERE
|
||||||
@expect = [[Virtual::MethodEnter,LoadConstant, SetSlot] , [Virtual::MethodReturn]]
|
@expect = [[Virtual::MethodEnter,LoadConstant, GetSlot,SetSlot] , [Virtual::MethodReturn]]
|
||||||
check
|
check
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -79,8 +79,8 @@ class Object
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
HERE
|
HERE
|
||||||
@expect = [[Virtual::MethodEnter,GetSlot,SetSlot, LoadConstant,
|
@expect = [[Virtual::MethodEnter,GetSlot,GetSlot,SetSlot, LoadConstant,SetSlot,
|
||||||
SetSlot,Virtual::MethodCall,GetSlot,SetSlot] , [Virtual::MethodReturn]]
|
Virtual::MethodCall,GetSlot,GetSlot,SetSlot] , [Virtual::MethodReturn]]
|
||||||
check
|
check
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -17,7 +17,7 @@ class Object
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
HERE
|
HERE
|
||||||
@expect = [[Virtual::MethodEnter,LoadConstant,GetSlot,
|
@expect = [[Virtual::MethodEnter,GetSlot,LoadConstant,
|
||||||
SetSlot,LoadConstant,SetSlot,Virtual::MethodCall,GetSlot] ,
|
SetSlot,LoadConstant,SetSlot,Virtual::MethodCall,GetSlot] ,
|
||||||
[Virtual::MethodReturn]]
|
[Virtual::MethodReturn]]
|
||||||
check
|
check
|
||||||
@ -37,7 +37,7 @@ class Object
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
HERE
|
HERE
|
||||||
@expect = [[Virtual::MethodEnter,LoadConstant,GetSlot,
|
@expect = [[Virtual::MethodEnter,GetSlot,LoadConstant,
|
||||||
SetSlot,LoadConstant,SetSlot,Virtual::MethodCall,GetSlot] ,
|
SetSlot,LoadConstant,SetSlot,Virtual::MethodCall,GetSlot] ,
|
||||||
[Virtual::MethodReturn]]
|
[Virtual::MethodReturn]]
|
||||||
check
|
check
|
||||||
@ -57,8 +57,8 @@ class Object
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
HERE
|
HERE
|
||||||
@expect = [ [Virtual::MethodEnter,LoadConstant,SetSlot,GetSlot,
|
@expect = [ [Virtual::MethodEnter,LoadConstant,GetSlot,SetSlot,GetSlot,
|
||||||
GetSlot,SetSlot,LoadConstant,SetSlot,Virtual::MethodCall,
|
GetSlot,GetSlot,SetSlot,LoadConstant,SetSlot,Virtual::MethodCall,
|
||||||
GetSlot] ,[Virtual::MethodReturn] ]
|
GetSlot] ,[Virtual::MethodReturn] ]
|
||||||
check
|
check
|
||||||
end
|
end
|
||||||
@ -77,13 +77,13 @@ class Object
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
HERE
|
HERE
|
||||||
@expect = [ [Virtual::MethodEnter,GetSlot,GetSlot,SetSlot,
|
@expect = [ [Virtual::MethodEnter,GetSlot,GetSlot,GetSlot,SetSlot,
|
||||||
LoadConstant,SetSlot,Virtual::MethodCall,
|
LoadConstant,SetSlot,Virtual::MethodCall,
|
||||||
GetSlot] ,[Virtual::MethodReturn] ]
|
GetSlot] ,[Virtual::MethodReturn] ]
|
||||||
check
|
check
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_puts_string
|
def test_call_puts
|
||||||
@string_input = <<HERE
|
@string_input = <<HERE
|
||||||
class Object
|
class Object
|
||||||
int puts(Word str)
|
int puts(Word str)
|
||||||
@ -94,7 +94,7 @@ int main()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
HERE
|
HERE
|
||||||
@expect = [ [Virtual::MethodEnter , GetSlot,SetSlot,LoadConstant,SetSlot,LoadConstant,
|
@expect = [ [Virtual::MethodEnter , GetSlot,GetSlot,SetSlot,LoadConstant,SetSlot,LoadConstant,
|
||||||
SetSlot,Virtual::MethodCall,GetSlot],
|
SetSlot,Virtual::MethodCall,GetSlot],
|
||||||
[Virtual::MethodReturn]]
|
[Virtual::MethodReturn]]
|
||||||
check
|
check
|
||||||
|
@ -26,7 +26,7 @@ class Object
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
HERE
|
HERE
|
||||||
@expect = [[Virtual::MethodEnter,GetSlot] , [Virtual::MethodReturn]]
|
@expect = [[Virtual::MethodEnter,GetSlot,GetSlot] , [Virtual::MethodReturn]]
|
||||||
check
|
check
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ class Object
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
HERE
|
HERE
|
||||||
@expect = [[Virtual::MethodEnter,LoadConstant, SetSlot,GetSlot] , [Virtual::MethodReturn]]
|
@expect = [[Virtual::MethodEnter,LoadConstant,GetSlot,SetSlot,GetSlot,GetSlot] , [Virtual::MethodReturn]]
|
||||||
check
|
check
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -52,7 +52,7 @@ class Object
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
HERE
|
HERE
|
||||||
@expect = [[Virtual::MethodEnter,GetSlot] , [Virtual::MethodReturn]]
|
@expect = [[Virtual::MethodEnter,GetSlot,GetSlot] , [Virtual::MethodReturn]]
|
||||||
check
|
check
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -64,7 +64,7 @@ class Object
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
HERE
|
HERE
|
||||||
@expect = [[Virtual::MethodEnter,GetSlot,SetSlot, LoadConstant,
|
@expect = [[Virtual::MethodEnter,GetSlot,GetSlot,SetSlot, LoadConstant,
|
||||||
SetSlot,Virtual::MethodCall,GetSlot] , [Virtual::MethodReturn]]
|
SetSlot,Virtual::MethodCall,GetSlot] , [Virtual::MethodReturn]]
|
||||||
check
|
check
|
||||||
end
|
end
|
||||||
|
@ -31,8 +31,8 @@ class Object
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
HERE
|
HERE
|
||||||
@expect = [[Virtual::MethodEnter,LoadConstant,SetSlot],[GetSlot,LoadConstant,OperatorInstruction,
|
@expect = [[Virtual::MethodEnter,LoadConstant,GetSlot,SetSlot],[GetSlot,GetSlot,LoadConstant,OperatorInstruction,
|
||||||
IsZeroBranch,GetSlot,LoadConstant,OperatorInstruction,SetSlot,AlwaysBranch],
|
IsZeroBranch,GetSlot,GetSlot,LoadConstant,OperatorInstruction,GetSlot,SetSlot,AlwaysBranch],
|
||||||
[],[Virtual::MethodReturn]]
|
[],[Virtual::MethodReturn]]
|
||||||
check
|
check
|
||||||
end
|
end
|
||||||
@ -50,9 +50,9 @@ class Object
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
HERE
|
HERE
|
||||||
@expect = [[Virtual::MethodEnter,LoadConstant,SetSlot],
|
@expect = [[Virtual::MethodEnter,LoadConstant,GetSlot,SetSlot],
|
||||||
[GetSlot,LoadConstant,OperatorInstruction,IsZeroBranch,
|
[GetSlot,GetSlot,LoadConstant,OperatorInstruction,IsZeroBranch,GetSlot,
|
||||||
GetSlot,LoadConstant,OperatorInstruction,SetSlot,
|
GetSlot,LoadConstant,OperatorInstruction,GetSlot,SetSlot,GetSlot,
|
||||||
GetSlot,AlwaysBranch] ,
|
GetSlot,AlwaysBranch] ,
|
||||||
[],[Virtual::MethodReturn]]
|
[],[Virtual::MethodReturn]]
|
||||||
check
|
check
|
||||||
|
@ -27,6 +27,7 @@ module Ticker
|
|||||||
puts e
|
puts e
|
||||||
end
|
end
|
||||||
classes = classes.collect {|c| '"' + c.name.sub("Register::","") + '",' }
|
classes = classes.collect {|c| '"' + c.name.sub("Register::","") + '",' }
|
||||||
|
classes << "length = #{classes.length}"
|
||||||
classes.each_slice(5).each do |line|
|
classes.each_slice(5).each do |line|
|
||||||
puts " " + line.join
|
puts " " + line.join
|
||||||
end
|
end
|
||||||
|
@ -31,13 +31,13 @@ class AddTest < MiniTest::Test
|
|||||||
end
|
end
|
||||||
def test_load
|
def test_load
|
||||||
assert_equal Register::LoadConstant , ticks(2).class
|
assert_equal Register::LoadConstant , ticks(2).class
|
||||||
assert_equal Parfait::Space , Virtual.machine.objects[ @interpreter.get_register(:r1)].class
|
assert_equal Parfait::Space , Virtual.machine.objects[ @interpreter.get_register(:r2)].class
|
||||||
assert_equal :r1, @interpreter.instruction.array.symbol
|
assert_equal :r2, @interpreter.instruction.array.symbol
|
||||||
end
|
end
|
||||||
def test_get
|
def test_get
|
||||||
assert_equal Register::GetSlot , ticks(3).class
|
assert_equal Register::GetSlot , ticks(3).class
|
||||||
assert @interpreter.get_register( :r3 )
|
assert @interpreter.get_register( :r2 )
|
||||||
assert @interpreter.get_register( :r3 ).is_a? Integer
|
assert @interpreter.get_register( :r2 ).is_a? Integer
|
||||||
end
|
end
|
||||||
def test_transfer
|
def test_transfer
|
||||||
transfer = ticks 5
|
transfer = ticks 5
|
||||||
@ -45,11 +45,11 @@ class AddTest < MiniTest::Test
|
|||||||
assert_equal @interpreter.get_register(transfer.to) , @interpreter.get_register(transfer.from)
|
assert_equal @interpreter.get_register(transfer.to) , @interpreter.get_register(transfer.from)
|
||||||
end
|
end
|
||||||
def test_call
|
def test_call
|
||||||
assert_equal Register::FunctionCall , ticks(7).class
|
assert_equal Register::FunctionCall , ticks(6).class
|
||||||
assert @interpreter.link
|
assert @interpreter.link
|
||||||
end
|
end
|
||||||
def test_adding
|
def test_adding
|
||||||
done_op = ticks(11)
|
done_op = ticks(10)
|
||||||
assert_equal Register::OperatorInstruction , done_op.class
|
assert_equal Register::OperatorInstruction , done_op.class
|
||||||
left = @interpreter.get_register(done_op.left)
|
left = @interpreter.get_register(done_op.left)
|
||||||
rr = done_op.right
|
rr = done_op.right
|
||||||
@ -65,9 +65,11 @@ class AddTest < MiniTest::Test
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_chain
|
def test_chain
|
||||||
|
#show_ticks # get output of what is
|
||||||
["Branch","LoadConstant","GetSlot","SetSlot","RegisterTransfer",
|
["Branch","LoadConstant","GetSlot","SetSlot","RegisterTransfer",
|
||||||
"GetSlot","FunctionCall","SaveReturn","LoadConstant","LoadConstant",
|
"FunctionCall","SaveReturn","LoadConstant","LoadConstant","OperatorInstruction",
|
||||||
"OperatorInstruction","RegisterTransfer","GetSlot"].each_with_index do |name , index|
|
"RegisterTransfer","GetSlot","FunctionReturn","RegisterTransfer","Syscall",
|
||||||
|
"NilClass"].each_with_index do |name , index|
|
||||||
got = ticks(1)
|
got = ticks(1)
|
||||||
assert got.class.name.index(name) , "Wrong class for #{index+1}, expect #{name} , got #{got}"
|
assert got.class.name.index(name) , "Wrong class for #{index+1}, expect #{name} , got #{got}"
|
||||||
end
|
end
|
||||||
|
@ -51,7 +51,7 @@ HERE
|
|||||||
Virtual.machine.boot
|
Virtual.machine.boot
|
||||||
syntax = Parser::Salama.new.parse_with_debug(@string_input)
|
syntax = Parser::Salama.new.parse_with_debug(@string_input)
|
||||||
parts = Parser::Transform.new.apply(syntax)
|
parts = Parser::Transform.new.apply(syntax)
|
||||||
puts parts.inspect
|
#puts parts.inspect
|
||||||
Phisol::Compiler.compile( parts )
|
Phisol::Compiler.compile( parts )
|
||||||
|
|
||||||
# statements = Virtual.machine.boot.parse_and_compile @string_input
|
# statements = Virtual.machine.boot.parse_and_compile @string_input
|
||||||
@ -59,16 +59,18 @@ HERE
|
|||||||
Virtual.machine.run_before "Register::CallImplementation"
|
Virtual.machine.run_before "Register::CallImplementation"
|
||||||
@interpreter = Interpreter::Interpreter.new
|
@interpreter = Interpreter::Interpreter.new
|
||||||
@interpreter.start Virtual.machine.init
|
@interpreter.start Virtual.machine.init
|
||||||
|
#show_ticks # get output of what is
|
||||||
["Branch","LoadConstant","GetSlot","SetSlot","RegisterTransfer",
|
["Branch","LoadConstant","GetSlot","SetSlot","RegisterTransfer",
|
||||||
"GetSlot","FunctionCall","SaveReturn","LoadConstant","GetSlot",
|
|
||||||
"SetSlot","LoadConstant","SetSlot","RegisterTransfer","GetSlot",
|
|
||||||
"FunctionCall","SaveReturn","GetSlot","LoadConstant","SetSlot",
|
"FunctionCall","SaveReturn","GetSlot","LoadConstant","SetSlot",
|
||||||
"GetSlot","SetSlot","LoadConstant","SetSlot","GetSlot",
|
"LoadConstant","SetSlot","RegisterTransfer","FunctionCall","SaveReturn",
|
||||||
"SetSlot","RegisterTransfer","GetSlot","FunctionCall","SaveReturn",
|
"LoadConstant","GetSlot","SetSlot","GetSlot","GetSlot",
|
||||||
"GetSlot","LoadConstant","OperatorInstruction","SetSlot","GetSlot",
|
"SetSlot","LoadConstant","SetSlot","GetSlot","GetSlot",
|
||||||
"OperatorInstruction","SetSlot","GetSlot","LoadConstant","OperatorInstruction",
|
"SetSlot","RegisterTransfer","FunctionCall","SaveReturn","GetSlot",
|
||||||
"IsZeroBranch","GetSlot","SetSlot","LoadConstant","SetSlot",
|
"LoadConstant","OperatorInstruction","GetSlot","SetSlot","GetSlot",
|
||||||
"GetSlot","SetSlot","RegisterTransfer","GetSlot","FunctionCall",
|
"GetSlot","GetSlot","OperatorInstruction","GetSlot","SetSlot",
|
||||||
|
"GetSlot","GetSlot","LoadConstant","OperatorInstruction","IsZeroBranch",
|
||||||
|
"GetSlot","GetSlot","SetSlot","LoadConstant","SetSlot",
|
||||||
|
"GetSlot","GetSlot","SetSlot","RegisterTransfer","FunctionCall",
|
||||||
"SaveReturn","GetSlot","LoadConstant","OperatorInstruction","IsZeroBranch",
|
"SaveReturn","GetSlot","LoadConstant","OperatorInstruction","IsZeroBranch",
|
||||||
"LoadConstant","GetSlot","LoadConstant","OperatorInstruction","IsZeroBranch",
|
"LoadConstant","GetSlot","LoadConstant","OperatorInstruction","IsZeroBranch",
|
||||||
"LoadConstant","GetSlot","LoadConstant","OperatorInstruction","IsZeroBranch",
|
"LoadConstant","GetSlot","LoadConstant","OperatorInstruction","IsZeroBranch",
|
||||||
|
@ -31,13 +31,13 @@ class TestPuts < MiniTest::Test
|
|||||||
end
|
end
|
||||||
def test_load
|
def test_load
|
||||||
assert_equal Register::LoadConstant , ticks(2).class
|
assert_equal Register::LoadConstant , ticks(2).class
|
||||||
assert_equal Parfait::Space , Virtual.machine.objects[ @interpreter.get_register(:r1)].class
|
assert_equal Parfait::Space , Virtual.machine.objects[ @interpreter.get_register(:r2)].class
|
||||||
assert_equal :r1, @interpreter.instruction.array.symbol
|
assert_equal :r2, @interpreter.instruction.array.symbol
|
||||||
end
|
end
|
||||||
def test_get
|
def test_get
|
||||||
assert_equal Register::GetSlot , ticks(3).class
|
assert_equal Register::GetSlot , ticks(3).class
|
||||||
assert @interpreter.get_register( :r3 )
|
assert @interpreter.get_register( :r1 )
|
||||||
assert @interpreter.get_register( :r3 ).is_a? Integer
|
assert @interpreter.get_register( :r1 ).is_a? Integer
|
||||||
end
|
end
|
||||||
def test_transfer
|
def test_transfer
|
||||||
transfer = ticks 5
|
transfer = ticks 5
|
||||||
@ -45,23 +45,24 @@ class TestPuts < MiniTest::Test
|
|||||||
assert_equal @interpreter.get_register(transfer.to) , @interpreter.get_register(transfer.from)
|
assert_equal @interpreter.get_register(transfer.to) , @interpreter.get_register(transfer.from)
|
||||||
end
|
end
|
||||||
def test_call
|
def test_call
|
||||||
assert_equal Register::FunctionCall , ticks(7).class
|
assert_equal Register::FunctionCall , ticks(6).class
|
||||||
assert @interpreter.link
|
assert @interpreter.link
|
||||||
end
|
end
|
||||||
def test_save
|
def test_save
|
||||||
done = ticks(8)
|
done = ticks(7)
|
||||||
assert_equal Register::SaveReturn , done.class
|
assert_equal Register::SaveReturn , done.class
|
||||||
assert @interpreter.get_register done.register.symbol
|
assert @interpreter.get_register done.register.symbol
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_chain
|
def test_chain
|
||||||
|
#show_ticks # get output of what is
|
||||||
["Branch","LoadConstant","GetSlot","SetSlot","RegisterTransfer",
|
["Branch","LoadConstant","GetSlot","SetSlot","RegisterTransfer",
|
||||||
"GetSlot","FunctionCall","SaveReturn","LoadConstant","GetSlot",
|
"FunctionCall","SaveReturn","GetSlot","LoadConstant","SetSlot",
|
||||||
"SetSlot","LoadConstant","SetSlot","RegisterTransfer","GetSlot",
|
"LoadConstant","SetSlot","RegisterTransfer","FunctionCall","SaveReturn",
|
||||||
"FunctionCall","SaveReturn","RegisterTransfer","Syscall","RegisterTransfer",
|
"GetSlot","RegisterTransfer","Syscall","RegisterTransfer","RegisterTransfer",
|
||||||
"RegisterTransfer","SetSlot","GetSlot","GetSlot","RegisterTransfer",
|
"SetSlot","RegisterTransfer","GetSlot","FunctionReturn","GetSlot",
|
||||||
"GetSlot","GetSlot","GetSlot","FunctionReturn","RegisterTransfer",
|
"RegisterTransfer","GetSlot","FunctionReturn","RegisterTransfer","Syscall",
|
||||||
"Syscall","NilClass"].each_with_index do |name , index|
|
"NilClass"].each_with_index do |name , index|
|
||||||
got = ticks(1)
|
got = ticks(1)
|
||||||
#puts "TICK #{index}"
|
#puts "TICK #{index}"
|
||||||
assert got.class.name.index(name) , "Wrong class for #{index+1}, expect #{name} , got #{got}"
|
assert got.class.name.index(name) , "Wrong class for #{index+1}, expect #{name} , got #{got}"
|
||||||
@ -69,20 +70,20 @@ class TestPuts < MiniTest::Test
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_putstring
|
def test_putstring
|
||||||
done = ticks(19)
|
done = ticks(18)
|
||||||
assert_equal Register::Syscall , done.class
|
assert_equal Register::Syscall , done.class
|
||||||
assert_equal "Hello again" , @interpreter.stdout
|
assert_equal "Hello again" , @interpreter.stdout
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_return
|
def test_return
|
||||||
done = ticks(29)
|
done = ticks(24)
|
||||||
assert_equal Register::FunctionReturn , done.class
|
assert_equal Register::FunctionReturn , done.class
|
||||||
assert @interpreter.block.is_a?(Virtual::Block)
|
assert @interpreter.block.is_a?(Virtual::Block)
|
||||||
assert @interpreter.instruction.is_a?(Register::Instruction) , "not instruction #{@interpreter.instruction}"
|
assert @interpreter.instruction.is_a?(Register::Instruction) , "not instruction #{@interpreter.instruction}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_exit
|
def test_exit
|
||||||
done = ticks(32)
|
done = ticks(31)
|
||||||
assert_equal NilClass , done.class
|
assert_equal NilClass , done.class
|
||||||
assert_equal "Hello again" , @interpreter.stdout
|
assert_equal "Hello again" , @interpreter.stdout
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user