rename set_slot
set_slot was clear about the target, but not the source. Better with reg_to_slot (and soon it’s inverse slot_to_reg)
This commit is contained in:
parent
1b8d6149dd
commit
35adf9a5e6
@ -41,7 +41,7 @@ module Arm
|
|||||||
ArmMachine.ldr( *slot_args_for(code) )
|
ArmMachine.ldr( *slot_args_for(code) )
|
||||||
end
|
end
|
||||||
|
|
||||||
def translate_SetSlot( code )
|
def translate_RegToSlot( code )
|
||||||
ArmMachine.str( *slot_args_for(code) )
|
ArmMachine.str( *slot_args_for(code) )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ module Register
|
|||||||
compiler.add_code Register.op( s , ">>" , tmp , const )
|
compiler.add_code Register.op( s , ">>" , tmp , const )
|
||||||
# return q + tmp
|
# return q + tmp
|
||||||
compiler.add_code Register.op( s , "+" , q , tmp )
|
compiler.add_code Register.op( s , "+" , q , tmp )
|
||||||
compiler.add_code Register.set_slot( s , q , :message , :return_value)
|
compiler.add_code Register.reg_to_slot( s , q , :message , :return_value)
|
||||||
return compiler.method
|
return compiler.method
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -21,11 +21,11 @@ module Register
|
|||||||
# Load the message to new message register (r1)
|
# Load the message to new message register (r1)
|
||||||
compiler.add_code Register.get_slot( source , space_reg , message_ind , :message)
|
compiler.add_code Register.get_slot( source , space_reg , message_ind , :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)
|
||||||
compiler.add_code Register.set_slot( source, space_reg , :message , :receiver)
|
compiler.add_code Register.reg_to_slot( source, space_reg , :message , :receiver)
|
||||||
exit_label = Label.new("_exit_label" , "#{compiler.type.object_class.name}.#{compiler.method.name}" )
|
exit_label = Label.new("_exit_label" , "#{compiler.type.object_class.name}.#{compiler.method.name}" )
|
||||||
ret_tmp = compiler.use_reg(:Label)
|
ret_tmp = compiler.use_reg(:Label)
|
||||||
compiler.add_code Register::LoadConstant.new(source, exit_label , ret_tmp)
|
compiler.add_code Register::LoadConstant.new(source, exit_label , ret_tmp)
|
||||||
compiler.add_code Register.set_slot(source, ret_tmp , :message , :return_address)
|
compiler.add_code Register.reg_to_slot(source, ret_tmp , :message , :return_address)
|
||||||
# do the register call
|
# do the register call
|
||||||
compiler.add_code FunctionCall.new( source , Register.machine.space.get_main )
|
compiler.add_code FunctionCall.new( source , Register.machine.space.get_main )
|
||||||
compiler.add_code exit_label
|
compiler.add_code exit_label
|
||||||
@ -65,7 +65,7 @@ module Register
|
|||||||
# load the stored message into the base RegisterMachine
|
# load the stored message into the base RegisterMachine
|
||||||
compiler.add_code RegisterTransfer.new(source, r8 , Register.message_reg )
|
compiler.add_code RegisterTransfer.new(source, r8 , Register.message_reg )
|
||||||
# save the return value into the message
|
# save the return value into the message
|
||||||
compiler.add_code Register.set_slot( source , return_tmp , :message , :return_value )
|
compiler.add_code Register.reg_to_slot( source , return_tmp , :message , :return_value )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
extend ClassMethods
|
extend ClassMethods
|
||||||
|
@ -16,7 +16,7 @@ module Register
|
|||||||
# reduce me to me[index]
|
# reduce me to me[index]
|
||||||
compiler.add_code GetSlot.new( source , me , index , me)
|
compiler.add_code GetSlot.new( source , me , index , me)
|
||||||
# and put it back into the return value
|
# and put it back into the return value
|
||||||
compiler.add_code Register.set_slot( source , me , :message , :return_value)
|
compiler.add_code Register.reg_to_slot( source , me , :message , :return_value)
|
||||||
return compiler.method
|
return compiler.method
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ module Register
|
|||||||
value = load_arg_at(compiler,source , 2)
|
value = load_arg_at(compiler,source , 2)
|
||||||
|
|
||||||
# do the set
|
# do the set
|
||||||
compiler.add_code SetSlot.new( source , value , me , index)
|
compiler.add_code RegToSlot.new( source , value , me , index)
|
||||||
return compiler.method
|
return compiler.method
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ module Register
|
|||||||
# reduce me to me[index]
|
# reduce me to me[index]
|
||||||
compiler.add_code GetByte.new( source , me , index , me)
|
compiler.add_code GetByte.new( source , me , index , me)
|
||||||
# and put it back into the return value
|
# and put it back into the return value
|
||||||
compiler.add_code Register.set_slot( source , me , :message , :return_value)
|
compiler.add_code Register.reg_to_slot( source , me , :message , :return_value)
|
||||||
return compiler.method
|
return compiler.method
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -119,7 +119,7 @@ end
|
|||||||
|
|
||||||
require_relative "instructions/setter"
|
require_relative "instructions/setter"
|
||||||
require_relative "instructions/getter"
|
require_relative "instructions/getter"
|
||||||
require_relative "instructions/set_slot"
|
require_relative "instructions/reg_to_slot"
|
||||||
require_relative "instructions/get_slot"
|
require_relative "instructions/get_slot"
|
||||||
require_relative "instructions/set_byte"
|
require_relative "instructions/set_byte"
|
||||||
require_relative "instructions/get_byte"
|
require_relative "instructions/get_byte"
|
||||||
|
@ -20,7 +20,7 @@ module Register
|
|||||||
return_label = Label.new("_return_label" , "#{compiler.type.object_class.name}.#{compiler.method.name}" )
|
return_label = Label.new("_return_label" , "#{compiler.type.object_class.name}.#{compiler.method.name}" )
|
||||||
ret_tmp = compiler.use_reg(:Label)
|
ret_tmp = compiler.use_reg(:Label)
|
||||||
compiler.add_code Register::LoadConstant.new(source, return_label , ret_tmp)
|
compiler.add_code Register::LoadConstant.new(source, return_label , ret_tmp)
|
||||||
compiler.add_code Register.set_slot(source, ret_tmp , :new_message , :return_address)
|
compiler.add_code Register.reg_to_slot(source, ret_tmp , :new_message , :return_address)
|
||||||
# move the current new_message to message
|
# move the current new_message to message
|
||||||
compiler.add_code RegisterTransfer.new(source, Register.new_message_reg , Register.message_reg )
|
compiler.add_code RegisterTransfer.new(source, Register.new_message_reg , Register.message_reg )
|
||||||
# do the register call
|
# do the register call
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
module Register
|
module Register
|
||||||
|
|
||||||
# GetSlot moves data into a register from memory.
|
# GetSlot moves data into a register from memory.
|
||||||
# SetSlot moves data into memory from a register.
|
# RegToSlot moves data into memory from a register.
|
||||||
# Both use a base memory (a register)
|
# Both use a base memory (a register)
|
||||||
|
|
||||||
# This is because that is what cpu's can do. In programming terms this would be accessing
|
# This is because that is what cpu's can do. In programming terms this would be accessing
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
module Register
|
module Register
|
||||||
|
|
||||||
# SetSlot moves data into memory from a register.
|
# RegToSlot moves data into memory from a register.
|
||||||
# GetSlot moves data into a register from memory.
|
# GetSlot moves data into a register from memory.
|
||||||
# Both use a base memory (a register)
|
# Both use a base memory (a register)
|
||||||
|
|
||||||
# This is because that is what cpu's can do. In programming terms this would be accessing
|
# This is because that is what cpu's can do. In programming terms this would be accessing
|
||||||
# an element in an array, in the case of SetSlot setting the register in the array.
|
# an element in an array, in the case of RegToSlot setting the register in the array.
|
||||||
|
|
||||||
# btw: to move data between registers, use RegisterTransfer
|
# btw: to move data between registers, use RegisterTransfer
|
||||||
|
|
||||||
class SetSlot < Setter
|
class RegToSlot < Setter
|
||||||
|
|
||||||
# If you had a c array and index offset
|
# If you had a c array and index offset
|
||||||
# the instruction would do array[index] = register
|
# the instruction would do array[index] = register
|
||||||
# So SetSlot means the register (first argument) moves to the slot (array and index)
|
# So RegToSlot means the register (first argument) moves to the slot (array and index)
|
||||||
|
|
||||||
# def initialize source , register , array , index
|
# def initialize source , register , array , index
|
||||||
# super
|
# super
|
||||||
@ -22,14 +22,14 @@ module Register
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Produce a SetSlot instruction.
|
# Produce a RegToSlot instruction.
|
||||||
# From and to are registers or symbols that can be transformed to a register by resolve_to_register
|
# From and to are registers or symbols that can be transformed to a register by resolve_to_register
|
||||||
# index resolves with resolve_index.
|
# index resolves with resolve_index.
|
||||||
def self.set_slot source , from , to , index
|
def self.reg_to_slot source , from , to , index
|
||||||
from = resolve_to_register from
|
from = resolve_to_register from
|
||||||
index = resolve_index( to , index)
|
index = resolve_index( to , index)
|
||||||
to = resolve_to_register to
|
to = resolve_to_register to
|
||||||
SetSlot.new( source, from , to , index)
|
RegToSlot.new( source, from , to , index)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
@ -3,7 +3,7 @@ module Register
|
|||||||
# transfer the constents of one register to another.
|
# transfer the constents of one register to another.
|
||||||
# possibly called move in some cpus
|
# possibly called move in some cpus
|
||||||
|
|
||||||
# There are other instructions to move data from / to memory, namely GetSlot and SetSlot
|
# There are other instructions to move data from / to memory, namely GetSlot and RegToSlot
|
||||||
|
|
||||||
# Get/Set Slot move data around in vm objects, but transfer moves the objects (in the machine)
|
# Get/Set Slot move data around in vm objects, but transfer moves the objects (in the machine)
|
||||||
#
|
#
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
module Register
|
module Register
|
||||||
# Setter is a base class for set instructions (SetSlot and SetByte , possibly more coming)
|
# Setter is a base class for set instructions (RegToSlot and SetByte , possibly more coming)
|
||||||
#
|
#
|
||||||
# The instruction that is modelled is loading data from a register into an array
|
# The instruction that is modelled is loading data from a register into an array
|
||||||
#
|
#
|
||||||
|
@ -144,7 +144,7 @@ module Register
|
|||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
def execute_SetSlot
|
def execute_RegToSlot
|
||||||
value = get_register( @instruction.register )
|
value = get_register( @instruction.register )
|
||||||
object = get_register( @instruction.array )
|
object = get_register( @instruction.array )
|
||||||
if( @instruction.index.is_a?(Numeric) )
|
if( @instruction.index.is_a?(Numeric) )
|
||||||
|
@ -27,7 +27,7 @@ module Typed
|
|||||||
end
|
end
|
||||||
# TODO, check type @method.locals[index].type
|
# TODO, check type @method.locals[index].type
|
||||||
add_code Register.get_slot(statement , :message , type , named_list )
|
add_code Register.get_slot(statement , :message , type , named_list )
|
||||||
return Register.set_slot(statement , value , named_list , index )
|
return Register.reg_to_slot(statement , value , named_list , index )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -11,7 +11,7 @@ module Typed
|
|||||||
me = get_me( statement )
|
me = get_me( statement )
|
||||||
type = get_my_type(me)
|
type = get_my_type(me)
|
||||||
# move our receiver there
|
# move our receiver there
|
||||||
add_code Register.set_slot( statement , me , :new_message , :receiver)
|
add_code Register.reg_to_slot( statement , me , :new_message , :receiver)
|
||||||
|
|
||||||
set_message_details(statement , statement.arguments)
|
set_message_details(statement , statement.arguments)
|
||||||
set_arguments(statement.arguments)
|
set_arguments(statement.arguments)
|
||||||
@ -62,18 +62,18 @@ module Typed
|
|||||||
name = name_s.name
|
name = name_s.name
|
||||||
name_tmp = use_reg(:Word)
|
name_tmp = use_reg(:Word)
|
||||||
add_code Register::LoadConstant.new(name_s, name , name_tmp)
|
add_code Register::LoadConstant.new(name_s, name , name_tmp)
|
||||||
add_code Register.set_slot( name_s , name_tmp , :new_message , :name)
|
add_code Register.reg_to_slot( name_s , name_tmp , :new_message , :name)
|
||||||
# next arg and local types
|
# next arg and local types
|
||||||
args_reg = use_reg(:Type , @method.arguments )
|
args_reg = use_reg(:Type , @method.arguments )
|
||||||
list_reg = use_reg(:NamedList , arguments )
|
list_reg = use_reg(:NamedList , arguments )
|
||||||
add_code Register::LoadConstant.new(name_s, @method , args_reg)
|
add_code Register::LoadConstant.new(name_s, @method , args_reg)
|
||||||
add_code Register.get_slot( name_s , :message , :arguments , list_reg )
|
add_code Register.get_slot( name_s , :message , :arguments , list_reg )
|
||||||
add_code Register.set_slot( name_s , args_reg , list_reg , 1 )
|
add_code Register.reg_to_slot( name_s , args_reg , list_reg , 1 )
|
||||||
|
|
||||||
#FIXME need to set type of locals too. sama sama
|
#FIXME need to set type of locals too. sama sama
|
||||||
# len_tmp = use_reg(:Integer , arguments.to_a.length )
|
# len_tmp = use_reg(:Integer , arguments.to_a.length )
|
||||||
# add_code Register::LoadConstant.new(name_s, arguments.to_a.length , len_tmp)
|
# add_code Register::LoadConstant.new(name_s, arguments.to_a.length , len_tmp)
|
||||||
# add_code Register.set_slot( name_s , len_tmp , :new_message , :indexed_length)
|
# add_code Register.reg_to_slot( name_s , len_tmp , :new_message , :indexed_length)
|
||||||
end
|
end
|
||||||
def set_arguments arguments
|
def set_arguments arguments
|
||||||
# reset tmp regs for each and load result into new_message
|
# reset tmp regs for each and load result into new_message
|
||||||
@ -85,7 +85,7 @@ module Typed
|
|||||||
list_reg = use_reg(:NamedList , arguments )
|
list_reg = use_reg(:NamedList , arguments )
|
||||||
add_code Register.get_slot( "Set arg #{i}#{arg}" , :message , :arguments , list_reg )
|
add_code Register.get_slot( "Set arg #{i}#{arg}" , :message , :arguments , list_reg )
|
||||||
# which we load int the new_message at the argument's index (the one comes from c index)
|
# which we load int the new_message at the argument's index (the one comes from c index)
|
||||||
set = Register.set_slot( arg , val , list_reg , i + 1 )
|
set = Register.reg_to_slot( arg , val , list_reg , i + 1 )
|
||||||
add_code set
|
add_code set
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -3,7 +3,7 @@ module Typed
|
|||||||
|
|
||||||
def on_ReturnStatement statement
|
def on_ReturnStatement statement
|
||||||
reg = process(statement.return_value)
|
reg = process(statement.return_value)
|
||||||
add_code Register.set_slot( statement, reg , :message , :return_value)
|
add_code Register.reg_to_slot( statement, reg , :message , :return_value)
|
||||||
nil # statements don't return
|
nil # statements don't return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -17,9 +17,9 @@ HERE
|
|||||||
|
|
||||||
def test_chain
|
def test_chain
|
||||||
#show_ticks # get output of what is
|
#show_ticks # get output of what is
|
||||||
check_chain ["Branch","Label","LoadConstant","GetSlot","SetSlot",
|
check_chain ["Branch","Label","LoadConstant","GetSlot","RegToSlot",
|
||||||
"LoadConstant","SetSlot","FunctionCall","Label","LoadConstant",
|
"LoadConstant","RegToSlot","FunctionCall","Label","LoadConstant",
|
||||||
"LoadConstant","OperatorInstruction","SetSlot","Label","FunctionReturn",
|
"LoadConstant","OperatorInstruction","RegToSlot","Label","FunctionReturn",
|
||||||
"RegisterTransfer","Syscall","NilClass"]
|
"RegisterTransfer","Syscall","NilClass"]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -36,9 +36,9 @@ class AddChange < MiniTest::Test
|
|||||||
|
|
||||||
def test_chain
|
def test_chain
|
||||||
#show_ticks # get output of what is
|
#show_ticks # get output of what is
|
||||||
check_chain ["Branch","Label","LoadConstant","GetSlot","SetSlot",
|
check_chain ["Branch","Label","LoadConstant","GetSlot","RegToSlot",
|
||||||
"LoadConstant","SetSlot","FunctionCall","Label","LoadConstant",
|
"LoadConstant","RegToSlot","FunctionCall","Label","LoadConstant",
|
||||||
"LoadConstant","OperatorInstruction","SetSlot","Label","FunctionReturn",
|
"LoadConstant","OperatorInstruction","RegToSlot","Label","FunctionReturn",
|
||||||
"RegisterTransfer","Syscall","NilClass"]
|
"RegisterTransfer","Syscall","NilClass"]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -20,11 +20,11 @@ HERE
|
|||||||
|
|
||||||
def test_chain
|
def test_chain
|
||||||
#show_ticks # get output of what is
|
#show_ticks # get output of what is
|
||||||
check_chain ["Branch","Label","LoadConstant","GetSlot","SetSlot",
|
check_chain ["Branch","Label","LoadConstant","GetSlot","RegToSlot",
|
||||||
"LoadConstant","SetSlot","FunctionCall","Label","GetSlot",
|
"LoadConstant","RegToSlot","FunctionCall","Label","GetSlot",
|
||||||
"LoadConstant","SetSlot","LoadConstant","SetSlot","LoadConstant",
|
"LoadConstant","RegToSlot","LoadConstant","RegToSlot","LoadConstant",
|
||||||
"SetSlot","LoadConstant","SetSlot","LoadConstant","SetSlot",
|
"RegToSlot","LoadConstant","RegToSlot","LoadConstant","RegToSlot",
|
||||||
"LoadConstant","SetSlot","RegisterTransfer","FunctionCall","Label",
|
"LoadConstant","RegToSlot","RegisterTransfer","FunctionCall","Label",
|
||||||
"GetSlot","GetSlot","GetSlot","SetByte","Label",
|
"GetSlot","GetSlot","GetSlot","SetByte","Label",
|
||||||
"FunctionReturn","RegisterTransfer","GetSlot","GetSlot","Label",
|
"FunctionReturn","RegisterTransfer","GetSlot","GetSlot","Label",
|
||||||
"FunctionReturn","RegisterTransfer","Syscall","NilClass"]
|
"FunctionReturn","RegisterTransfer","Syscall","NilClass"]
|
||||||
|
@ -32,17 +32,17 @@ HERE
|
|||||||
s(:false_statements, s(:call, s(:name, :putstring), s(:arguments), s(:receiver, s(:string, "else"))))))
|
s(:false_statements, s(:call, s(:name, :putstring), s(:arguments), s(:receiver, s(:string, "else"))))))
|
||||||
end
|
end
|
||||||
def test_if
|
def test_if
|
||||||
show_ticks # get output of what is
|
#show_ticks # get output of what is
|
||||||
check_chain ["Branch","Label","LoadConstant","GetSlot","SetSlot",
|
check_chain ["Branch","Label","LoadConstant","GetSlot","RegToSlot",
|
||||||
"LoadConstant","SetSlot","FunctionCall","Label","GetSlot",
|
"LoadConstant","RegToSlot","FunctionCall","Label","GetSlot",
|
||||||
"GetSlot","SetSlot","LoadConstant","SetSlot","LoadConstant",
|
"GetSlot","RegToSlot","LoadConstant","RegToSlot","LoadConstant",
|
||||||
"SetSlot","LoadConstant","SetSlot","LoadConstant","SetSlot",
|
"RegToSlot","LoadConstant","RegToSlot","LoadConstant","RegToSlot",
|
||||||
"RegisterTransfer","FunctionCall","Label","GetSlot","LoadConstant",
|
"RegisterTransfer","FunctionCall","Label","GetSlot","LoadConstant",
|
||||||
"OperatorInstruction","IsZero","GetSlot","LoadConstant","SetSlot",
|
"OperatorInstruction","IsZero","GetSlot","LoadConstant","RegToSlot",
|
||||||
"LoadConstant","SetSlot","LoadConstant","SetSlot","LoadConstant",
|
"LoadConstant","RegToSlot","LoadConstant","RegToSlot","LoadConstant",
|
||||||
"SetSlot","RegisterTransfer","FunctionCall","Label","GetSlot",
|
"RegToSlot","RegisterTransfer","FunctionCall","Label","GetSlot",
|
||||||
"GetSlot","RegisterTransfer","Syscall","RegisterTransfer","RegisterTransfer",
|
"GetSlot","RegisterTransfer","Syscall","RegisterTransfer","RegisterTransfer",
|
||||||
"SetSlot","Label","FunctionReturn","RegisterTransfer","GetSlot",
|
"RegToSlot","Label","FunctionReturn","RegisterTransfer","GetSlot",
|
||||||
"GetSlot","Branch","Label","Label","FunctionReturn",
|
"GetSlot","Branch","Label","Label","FunctionReturn",
|
||||||
"RegisterTransfer","GetSlot","GetSlot","Label","FunctionReturn",
|
"RegisterTransfer","GetSlot","GetSlot","Label","FunctionReturn",
|
||||||
"RegisterTransfer","Syscall","NilClass"]
|
"RegisterTransfer","Syscall","NilClass"]
|
||||||
|
@ -19,9 +19,9 @@ HERE
|
|||||||
|
|
||||||
def test_mult
|
def test_mult
|
||||||
#show_ticks # get output of what is
|
#show_ticks # get output of what is
|
||||||
check_chain ["Branch","Label","LoadConstant","GetSlot","SetSlot",
|
check_chain ["Branch","Label","LoadConstant","GetSlot","RegToSlot",
|
||||||
"LoadConstant","SetSlot","FunctionCall","Label","LoadConstant",
|
"LoadConstant","RegToSlot","FunctionCall","Label","LoadConstant",
|
||||||
"LoadConstant","OperatorInstruction","SetSlot","Label","FunctionReturn",
|
"LoadConstant","OperatorInstruction","RegToSlot","Label","FunctionReturn",
|
||||||
"RegisterTransfer","Syscall","NilClass"]
|
"RegisterTransfer","Syscall","NilClass"]
|
||||||
check_return 0
|
check_return 0
|
||||||
end
|
end
|
||||||
|
@ -17,9 +17,9 @@ HERE
|
|||||||
|
|
||||||
def test_add
|
def test_add
|
||||||
#show_ticks # get output of what is
|
#show_ticks # get output of what is
|
||||||
check_chain ["Branch","Label","LoadConstant","GetSlot","SetSlot",
|
check_chain ["Branch","Label","LoadConstant","GetSlot","RegToSlot",
|
||||||
"LoadConstant","SetSlot","FunctionCall","Label","LoadConstant",
|
"LoadConstant","RegToSlot","FunctionCall","Label","LoadConstant",
|
||||||
"LoadConstant","OperatorInstruction","SetSlot","Label","FunctionReturn",
|
"LoadConstant","OperatorInstruction","RegToSlot","Label","FunctionReturn",
|
||||||
"RegisterTransfer","Syscall","NilClass"]
|
"RegisterTransfer","Syscall","NilClass"]
|
||||||
check_return 0
|
check_return 0
|
||||||
end
|
end
|
||||||
|
@ -17,12 +17,12 @@ HERE
|
|||||||
|
|
||||||
def test_chain
|
def test_chain
|
||||||
#show_ticks # get output of what is
|
#show_ticks # get output of what is
|
||||||
check_chain ["Branch","Label","LoadConstant","GetSlot","SetSlot",
|
check_chain ["Branch","Label","LoadConstant","GetSlot","RegToSlot",
|
||||||
"LoadConstant","SetSlot","FunctionCall","Label","GetSlot",
|
"LoadConstant","RegToSlot","FunctionCall","Label","GetSlot",
|
||||||
"LoadConstant","SetSlot","LoadConstant","SetSlot","LoadConstant",
|
"LoadConstant","RegToSlot","LoadConstant","RegToSlot","LoadConstant",
|
||||||
"SetSlot","LoadConstant","SetSlot","RegisterTransfer","FunctionCall",
|
"RegToSlot","LoadConstant","RegToSlot","RegisterTransfer","FunctionCall",
|
||||||
"Label","GetSlot","GetSlot","RegisterTransfer","Syscall",
|
"Label","GetSlot","GetSlot","RegisterTransfer","Syscall",
|
||||||
"RegisterTransfer","RegisterTransfer","SetSlot","Label","FunctionReturn",
|
"RegisterTransfer","RegisterTransfer","RegToSlot","Label","FunctionReturn",
|
||||||
"RegisterTransfer","GetSlot","GetSlot","Label","FunctionReturn",
|
"RegisterTransfer","GetSlot","GetSlot","Label","FunctionReturn",
|
||||||
"RegisterTransfer","Syscall","NilClass"]
|
"RegisterTransfer","Syscall","NilClass"]
|
||||||
end
|
end
|
||||||
|
@ -20,12 +20,12 @@ HERE
|
|||||||
|
|
||||||
def test_chain
|
def test_chain
|
||||||
#show_ticks # get output of what is
|
#show_ticks # get output of what is
|
||||||
check_chain ["Branch","Label","LoadConstant","GetSlot","SetSlot",
|
check_chain ["Branch","Label","LoadConstant","GetSlot","RegToSlot",
|
||||||
"LoadConstant","SetSlot","FunctionCall","Label","GetSlot",
|
"LoadConstant","RegToSlot","FunctionCall","Label","GetSlot",
|
||||||
"LoadConstant","SetSlot","LoadConstant","SetSlot","LoadConstant",
|
"LoadConstant","RegToSlot","LoadConstant","RegToSlot","LoadConstant",
|
||||||
"SetSlot","LoadConstant","SetSlot","LoadConstant","SetSlot",
|
"RegToSlot","LoadConstant","RegToSlot","LoadConstant","RegToSlot",
|
||||||
"RegisterTransfer","FunctionCall","Label","GetSlot","GetSlot",
|
"RegisterTransfer","FunctionCall","Label","GetSlot","GetSlot",
|
||||||
"GetByte","SetSlot","Label","FunctionReturn","RegisterTransfer",
|
"GetByte","RegToSlot","Label","FunctionReturn","RegisterTransfer",
|
||||||
"GetSlot","GetSlot","Label","FunctionReturn","RegisterTransfer",
|
"GetSlot","GetSlot","Label","FunctionReturn","RegisterTransfer",
|
||||||
"Syscall","NilClass"]
|
"Syscall","NilClass"]
|
||||||
end
|
end
|
||||||
|
@ -9,6 +9,8 @@ class TestNamedLists < MiniTest::Test
|
|||||||
|
|
||||||
def test_named_list_get_type
|
def test_named_list_get_type
|
||||||
assert_equal Parfait::Type , @type.class
|
assert_equal Parfait::Type , @type.class
|
||||||
|
assert @type.instance_names
|
||||||
|
assert @named_list.get_instance_variables
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_named_list_next_set
|
def test_named_list_next_set
|
||||||
@ -16,4 +18,13 @@ class TestNamedLists < MiniTest::Test
|
|||||||
assert_equal :next_list , @named_list.next_list
|
assert_equal :next_list , @named_list.next_list
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_new
|
||||||
|
list = Parfait::NamedList.new
|
||||||
|
assert list.get_type
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_var_names
|
||||||
|
list = Parfait::NamedList.new
|
||||||
|
assert list.get_instance_variables
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -9,7 +9,7 @@ class TestAssignStatement < MiniTest::Test
|
|||||||
|
|
||||||
@input = s(:statements, s(:assignment, s(:name, :r), s(:operator_value, :+, s(:int, 10), s(:int, 1))))
|
@input = s(:statements, s(:assignment, s(:name, :r), s(:operator_value, :+, s(:int, 10), s(:int, 1))))
|
||||||
|
|
||||||
@expect = [Label, LoadConstant, LoadConstant, OperatorInstruction, GetSlot, SetSlot, Label ,
|
@expect = [Label, LoadConstant, LoadConstant, OperatorInstruction, GetSlot, RegToSlot, Label ,
|
||||||
FunctionReturn]
|
FunctionReturn]
|
||||||
check
|
check
|
||||||
end
|
end
|
||||||
@ -18,7 +18,7 @@ class TestAssignStatement < MiniTest::Test
|
|||||||
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)))
|
@input =s(:statements, s(:assignment, s(:name, :r), s(:int, 5)))
|
||||||
|
|
||||||
@expect = [Label, LoadConstant, GetSlot, SetSlot, Label, FunctionReturn]
|
@expect = [Label, LoadConstant, GetSlot, RegToSlot, Label, FunctionReturn]
|
||||||
check
|
check
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -27,23 +27,23 @@ class TestAssignStatement < MiniTest::Test
|
|||||||
|
|
||||||
@input = s(:statements, s(:assignment, s(:name, :r), s(:int, 5)))
|
@input = s(:statements, s(:assignment, s(:name, :r), s(:int, 5)))
|
||||||
|
|
||||||
@expect = [Label, LoadConstant, GetSlot, SetSlot, Label, FunctionReturn]
|
@expect = [Label, LoadConstant, GetSlot, RegToSlot, Label, FunctionReturn]
|
||||||
check
|
check
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_assign_call
|
def test_assign_call
|
||||||
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(:call, s(:name, :main), s(:arguments))))
|
@input = s(:statements, s(:assignment, s(:name, :r), s(:call, s(:name, :main), s(:arguments))))
|
||||||
@expect = [Label, GetSlot, GetSlot, SetSlot, LoadConstant, SetSlot, LoadConstant ,
|
@expect = [Label, GetSlot, GetSlot, RegToSlot, LoadConstant, RegToSlot, LoadConstant ,
|
||||||
SetSlot, LoadConstant, SetSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer ,
|
RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer ,
|
||||||
GetSlot, GetSlot, GetSlot, SetSlot, Label, FunctionReturn]
|
GetSlot, GetSlot, GetSlot, RegToSlot, Label, FunctionReturn]
|
||||||
check
|
check
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_named_list_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, RegToSlot, GetSlot, GetSlot, RegToSlot ,
|
||||||
Label, FunctionReturn]
|
Label, FunctionReturn]
|
||||||
was = check
|
was = check
|
||||||
get = was.next(5)
|
get = was.next(5)
|
||||||
@ -54,20 +54,20 @@ class TestAssignStatement < MiniTest::Test
|
|||||||
def test_assign_int
|
def test_assign_int
|
||||||
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)) )
|
@input = s(:statements, s(:assignment, s(:name, :r), s(:int, 5)) )
|
||||||
@expect = [Label, LoadConstant, GetSlot, SetSlot, Label, FunctionReturn]
|
@expect = [Label, LoadConstant, GetSlot, RegToSlot, Label, FunctionReturn]
|
||||||
was = check
|
was = check
|
||||||
set = was.next(3)
|
set = was.next(3)
|
||||||
assert_equal SetSlot , set.class
|
assert_equal RegToSlot , set.class
|
||||||
assert_equal 1, set.index , "Set to named_list index must be offset, not #{set.index}"
|
assert_equal 1, set.index , "Set to named_list index must be offset, not #{set.index}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_assign_arg
|
def test_assign_arg
|
||||||
Register.machine.space.get_main.add_argument(:blar , :Integer)
|
Register.machine.space.get_main.add_argument(:blar , :Integer)
|
||||||
@input = s(:statements, s(:assignment, s(:name, :blar), s(:int, 5)))
|
@input = s(:statements, s(:assignment, s(:name, :blar), s(:int, 5)))
|
||||||
@expect = [Label, LoadConstant, SetSlot, Label, FunctionReturn]
|
@expect = [Label, LoadConstant, RegToSlot, Label, FunctionReturn]
|
||||||
was = check
|
was = check
|
||||||
set = was.next(2)
|
set = was.next(2)
|
||||||
assert_equal SetSlot , set.class
|
assert_equal RegToSlot , set.class
|
||||||
assert_equal 10, set.index , "Set to args index must be offset, not #{set.index}"
|
assert_equal 10, set.index , "Set to args index must be offset, not #{set.index}"
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -75,7 +75,7 @@ class TestAssignStatement < MiniTest::Test
|
|||||||
# have to define bar externally, just because redefining main. Otherwise that would be automatic
|
# have to define bar externally, just because redefining main. Otherwise that would be automatic
|
||||||
Register.machine.space.get_main.add_argument(:balr , :Integer)
|
Register.machine.space.get_main.add_argument(:balr , :Integer)
|
||||||
@input = s(:statements, s(:return, s(:name, :balr)))
|
@input = s(:statements, s(:return, s(:name, :balr)))
|
||||||
@expect = [Label, GetSlot, SetSlot, Label, FunctionReturn]
|
@expect = [Label, GetSlot, RegToSlot, Label, FunctionReturn]
|
||||||
was = check
|
was = check
|
||||||
get = was.next(1)
|
get = was.next(1)
|
||||||
assert_equal GetSlot , get.class
|
assert_equal GetSlot , get.class
|
||||||
|
@ -7,8 +7,8 @@ class TestCallStatement < MiniTest::Test
|
|||||||
def test_call_constant_int
|
def test_call_constant_int
|
||||||
clean_compile :Integer, :puti, {}, s(:statements, s(:return, s(:int, 1)))
|
clean_compile :Integer, :puti, {}, s(:statements, s(:return, s(:int, 1)))
|
||||||
@input = s(:call, s(:name, :puti), s(:arguments), s(:receiver, s(:int, 42)))
|
@input = s(:call, s(:name, :puti), s(:arguments), s(:receiver, s(:int, 42)))
|
||||||
@expect = [Label, GetSlot, LoadConstant, SetSlot, LoadConstant, SetSlot, LoadConstant ,
|
@expect = [Label, GetSlot, LoadConstant, RegToSlot, LoadConstant, RegToSlot, LoadConstant ,
|
||||||
SetSlot, LoadConstant, SetSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer ,
|
RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer ,
|
||||||
GetSlot, GetSlot, Label, FunctionReturn]
|
GetSlot, GetSlot, Label, FunctionReturn]
|
||||||
check
|
check
|
||||||
end
|
end
|
||||||
@ -18,8 +18,8 @@ class TestCallStatement < MiniTest::Test
|
|||||||
clean_compile :Word, :putstr,{}, s(:statements, s(:return, s(:int, 1)))
|
clean_compile :Word, :putstr,{}, s(:statements, s(:return, s(:int, 1)))
|
||||||
|
|
||||||
@input =s(:call, s(:name, :putstr), s(:arguments), s(:receiver, s(:string, "Hello")))
|
@input =s(:call, s(:name, :putstr), s(:arguments), s(:receiver, s(:string, "Hello")))
|
||||||
@expect = [Label, GetSlot, LoadConstant, SetSlot, LoadConstant, SetSlot, LoadConstant ,
|
@expect = [Label, GetSlot, LoadConstant, RegToSlot, LoadConstant, RegToSlot, LoadConstant ,
|
||||||
SetSlot, LoadConstant, SetSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer ,
|
RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer ,
|
||||||
GetSlot, GetSlot, Label, FunctionReturn]
|
GetSlot, GetSlot, Label, FunctionReturn]
|
||||||
check
|
check
|
||||||
end
|
end
|
||||||
@ -29,8 +29,8 @@ class TestCallStatement < MiniTest::Test
|
|||||||
clean_compile :Integer, :putint, {}, s(:statements, s(:return, s(:int, 1)))
|
clean_compile :Integer, :putint, {}, s(:statements, s(:return, s(:int, 1)))
|
||||||
@input = s(:statements, s(:assignment, s(:name, :testi), s(:int, 20)), s(:call, s(:name, :putint), s(:arguments), s(:receiver, s(:name, :testi))))
|
@input = s(:statements, s(:assignment, s(:name, :testi), s(:int, 20)), s(:call, s(:name, :putint), s(:arguments), s(:receiver, s(:name, :testi))))
|
||||||
|
|
||||||
@expect = [Label, LoadConstant, GetSlot, SetSlot, GetSlot, GetSlot, GetSlot ,
|
@expect = [Label, LoadConstant, GetSlot, RegToSlot, GetSlot, GetSlot, GetSlot ,
|
||||||
SetSlot, LoadConstant, SetSlot, LoadConstant, SetSlot, LoadConstant, SetSlot ,
|
RegToSlot, LoadConstant, RegToSlot, LoadConstant, RegToSlot, LoadConstant, RegToSlot ,
|
||||||
RegisterTransfer, FunctionCall, Label, RegisterTransfer, GetSlot, GetSlot, Label ,
|
RegisterTransfer, FunctionCall, Label, RegisterTransfer, GetSlot, GetSlot, Label ,
|
||||||
FunctionReturn]
|
FunctionReturn]
|
||||||
check
|
check
|
||||||
@ -41,8 +41,8 @@ class TestCallStatement < MiniTest::Test
|
|||||||
clean_compile :List, :add, {}, s(:statements, s(:return, s(:int, 1)))
|
clean_compile :List, :add, {}, s(:statements, s(:return, s(:int, 1)))
|
||||||
|
|
||||||
@input =s(:statements, s(:call, s(:name, :add), s(:arguments), s(:receiver, s(:name, :test_l))))
|
@input =s(:statements, s(:call, s(:name, :add), s(:arguments), s(:receiver, s(:name, :test_l))))
|
||||||
@expect = [Label, GetSlot, GetSlot, GetSlot, SetSlot, LoadConstant, SetSlot ,
|
@expect = [Label, GetSlot, GetSlot, GetSlot, RegToSlot, LoadConstant, RegToSlot ,
|
||||||
LoadConstant, SetSlot, LoadConstant, SetSlot, RegisterTransfer, FunctionCall, Label ,
|
LoadConstant, RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall, Label ,
|
||||||
RegisterTransfer, GetSlot, GetSlot, Label, FunctionReturn]
|
RegisterTransfer, GetSlot, GetSlot, Label, FunctionReturn]
|
||||||
check
|
check
|
||||||
end
|
end
|
||||||
@ -58,12 +58,12 @@ int main()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
HERE
|
HERE
|
||||||
@expect = [Label, GetSlot, GetSlot, SetSlot, LoadConstant, SetSlot, LoadConstant ,
|
@expect = [Label, GetSlot, GetSlot, RegToSlot, LoadConstant, RegToSlot, LoadConstant ,
|
||||||
SetSlot, LoadConstant, SetSlot, LoadConstant, SetSlot, RegisterTransfer, FunctionCall ,
|
RegToSlot, LoadConstant, RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall ,
|
||||||
Label, RegisterTransfer, GetSlot, GetSlot, Label, FunctionReturn]
|
Label, RegisterTransfer, GetSlot, GetSlot, Label, FunctionReturn]
|
||||||
was = check
|
was = check
|
||||||
set = was.next(7)
|
set = was.next(7)
|
||||||
assert_equal SetSlot , set.class
|
assert_equal RegToSlot , set.class
|
||||||
assert_equal 9, set.index , "Set to message must be offset, not #{set.index}"
|
assert_equal 9, set.index , "Set to message must be offset, not #{set.index}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -11,7 +11,7 @@ class TestClassStatements < MiniTest::Test
|
|||||||
def test_class_defs
|
def test_class_defs
|
||||||
class_def
|
class_def
|
||||||
@input =s(:statements, s(:return, s(:int, 1)))
|
@input =s(:statements, s(:return, s(:int, 1)))
|
||||||
@expect = [Label, LoadConstant,SetSlot,Label,FunctionReturn]
|
@expect = [Label, LoadConstant,RegToSlot,Label,FunctionReturn]
|
||||||
check
|
check
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -20,9 +20,9 @@ class TestClassStatements < MiniTest::Test
|
|||||||
# class_def
|
# class_def
|
||||||
# @input = s(:statements, s(:return, s(:call, s(:name, :buh), s(:arguments), s(:receiver, s(:class_name, :Bar)))))
|
# @input = s(:statements, s(:return, s(:call, s(:name, :buh), s(:arguments), s(:receiver, s(:class_name, :Bar)))))
|
||||||
#
|
#
|
||||||
# @expect = [Label, GetSlot, LoadConstant, SetSlot, LoadConstant, SetSlot, LoadConstant ,
|
# @expect = [Label, GetSlot, LoadConstant, RegToSlot, LoadConstant, RegToSlot, LoadConstant ,
|
||||||
# SetSlot, LoadConstant, SetSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer ,
|
# RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer ,
|
||||||
# GetSlot, GetSlot, SetSlot, Label, FunctionReturn]
|
# GetSlot, GetSlot, RegToSlot, Label, FunctionReturn]
|
||||||
# check
|
# check
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -31,7 +31,7 @@ class TestClassStatements < MiniTest::Test
|
|||||||
#FIXME class_field handling unclear at the moment
|
#FIXME class_field handling unclear at the moment
|
||||||
# @input =s(:statements, s(:return, s(:field_access, s(:receiver, s(:name, :self)),
|
# @input =s(:statements, s(:return, s(:field_access, s(:receiver, s(:name, :self)),
|
||||||
# s(:field,s(:name, :boo2)))))
|
# s(:field,s(:name, :boo2)))))
|
||||||
# @expect = [Label, GetSlot,GetSlot,SetSlot,Label,FunctionReturn]
|
# @expect = [Label, GetSlot,GetSlot,RegToSlot,Label,FunctionReturn]
|
||||||
# check
|
# check
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -9,7 +9,7 @@ module Register
|
|||||||
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)))))
|
||||||
@expect = [Label, GetSlot, GetSlot, GetSlot, SetSlot, Label, FunctionReturn]
|
@expect = [Label, GetSlot, GetSlot, GetSlot, RegToSlot, Label, FunctionReturn]
|
||||||
check
|
check
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -20,9 +20,9 @@ module Register
|
|||||||
s(:receiver, s(:name, :main)), s(:field, s(:name, :name)))))
|
s(:receiver, s(:name, :main)), s(:field, s(:name, :name)))))
|
||||||
@input =s(:statements, s(:return, s(:call, s(:name, :get_name), s(:arguments, s(:name, :m)))))
|
@input =s(:statements, s(:return, s(:call, s(:name, :get_name), s(:arguments, s(:name, :m)))))
|
||||||
|
|
||||||
@expect = [Label, GetSlot, GetSlot, SetSlot, LoadConstant, SetSlot, LoadConstant ,
|
@expect = [Label, GetSlot, GetSlot, RegToSlot, LoadConstant, RegToSlot, LoadConstant ,
|
||||||
SetSlot, GetSlot, GetSlot, SetSlot, LoadConstant, SetSlot, RegisterTransfer ,
|
RegToSlot, GetSlot, GetSlot, RegToSlot, LoadConstant, RegToSlot, RegisterTransfer ,
|
||||||
FunctionCall, Label, RegisterTransfer, GetSlot, GetSlot, SetSlot, Label ,
|
FunctionCall, Label, RegisterTransfer, GetSlot, GetSlot, RegToSlot, Label ,
|
||||||
FunctionReturn]
|
FunctionReturn]
|
||||||
check
|
check
|
||||||
end
|
end
|
||||||
@ -31,8 +31,8 @@ module Register
|
|||||||
Register.machine.space.get_main.add_local(:name , :Word)
|
Register.machine.space.get_main.add_local(:name , :Word)
|
||||||
@input = s(:statements, s(:assignment, s(:name, :name), s(:field_access, s(:receiver, s(:name, :message)), s(:field, s(:name, :name)))), s(:return, s(:name, :name)))
|
@input = s(:statements, s(:assignment, s(:name, :name), s(:field_access, s(:receiver, s(:name, :message)), s(:field, s(:name, :name)))), s(:return, s(:name, :name)))
|
||||||
|
|
||||||
@expect = [Label, RegisterTransfer, GetSlot, GetSlot, SetSlot, GetSlot, GetSlot ,
|
@expect = [Label, RegisterTransfer, GetSlot, GetSlot, RegToSlot, GetSlot, GetSlot ,
|
||||||
SetSlot, Label, FunctionReturn]
|
RegToSlot, Label, FunctionReturn]
|
||||||
check
|
check
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -8,7 +8,7 @@ class TestIfStatement < MiniTest::Test
|
|||||||
@input = s(:statements, s(:if_statement, :plus, s(:condition, s(:operator_value, :-, s(:int, 10), s(:int, 12))), s(:true_statements, s(:return, s(:int, 3))), s(:false_statements, s(:return, s(:int, 4)))))
|
@input = s(:statements, s(:if_statement, :plus, s(:condition, s(:operator_value, :-, s(:int, 10), s(:int, 12))), s(:true_statements, s(:return, s(:int, 3))), s(:false_statements, s(:return, s(:int, 4)))))
|
||||||
|
|
||||||
@expect = [Label, LoadConstant,LoadConstant, OperatorInstruction,IsPlus ,
|
@expect = [Label, LoadConstant,LoadConstant, OperatorInstruction,IsPlus ,
|
||||||
LoadConstant,SetSlot,Branch , Label , LoadConstant ,SetSlot,
|
LoadConstant,RegToSlot,Branch , Label , LoadConstant ,RegToSlot,
|
||||||
Label,Label,FunctionReturn]
|
Label,Label,FunctionReturn]
|
||||||
check
|
check
|
||||||
end
|
end
|
||||||
@ -18,7 +18,7 @@ class TestIfStatement < MiniTest::Test
|
|||||||
@input = s(:statements, s(:if_statement, :minus, s(:condition, s(:operator_value, :-, s(:int, 10), s(:int, 12))), s(:true_statements, s(:return, s(:int, 3))), s(:false_statements, nil)))
|
@input = s(:statements, s(:if_statement, :minus, s(:condition, s(:operator_value, :-, s(:int, 10), s(:int, 12))), s(:true_statements, s(:return, s(:int, 3))), s(:false_statements, nil)))
|
||||||
|
|
||||||
@expect = [Label, LoadConstant, LoadConstant, OperatorInstruction, IsMinus, Branch, Label ,
|
@expect = [Label, LoadConstant, LoadConstant, OperatorInstruction, IsMinus, Branch, Label ,
|
||||||
LoadConstant, SetSlot, Label, Label, FunctionReturn]
|
LoadConstant, RegToSlot, Label, Label, FunctionReturn]
|
||||||
check
|
check
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ class TestIfStatement < MiniTest::Test
|
|||||||
@input = s(:statements, s(:if_statement, :zero, s(:condition, s(:operator_value, :-, s(:int, 10), s(:int, 12))), s(:true_statements, s(:return, s(:int, 3))), s(:false_statements, nil)))
|
@input = s(:statements, s(:if_statement, :zero, s(:condition, s(:operator_value, :-, s(:int, 10), s(:int, 12))), s(:true_statements, s(:return, s(:int, 3))), s(:false_statements, nil)))
|
||||||
|
|
||||||
@expect = [Label, LoadConstant,LoadConstant,OperatorInstruction,IsZero ,
|
@expect = [Label, LoadConstant,LoadConstant,OperatorInstruction,IsZero ,
|
||||||
Branch , Label , LoadConstant ,SetSlot,
|
Branch , Label , LoadConstant ,RegToSlot,
|
||||||
Label,Label, FunctionReturn]
|
Label,Label, FunctionReturn]
|
||||||
check
|
check
|
||||||
end
|
end
|
||||||
|
@ -6,37 +6,37 @@ class TestReturnStatement < MiniTest::Test
|
|||||||
|
|
||||||
def test_return_int
|
def test_return_int
|
||||||
@input = s(:statements, s(:return, s(:int, 5)))
|
@input = s(:statements, s(:return, s(:int, 5)))
|
||||||
@expect = [Label, LoadConstant ,SetSlot,Label,FunctionReturn]
|
@expect = [Label, LoadConstant ,RegToSlot,Label,FunctionReturn]
|
||||||
check
|
check
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_return_local
|
def test_return_local
|
||||||
Register.machine.space.get_main.add_local(:runner , :Integer)
|
Register.machine.space.get_main.add_local(:runner , :Integer)
|
||||||
@input = s(:statements, s(:return, s(:name, :runner)))
|
@input = s(:statements, s(:return, s(:name, :runner)))
|
||||||
@expect = [Label, GetSlot,GetSlot ,SetSlot,Label,FunctionReturn]
|
@expect = [Label, GetSlot,GetSlot ,RegToSlot,Label,FunctionReturn]
|
||||||
check
|
check
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_return_local_assign
|
def test_return_local_assign
|
||||||
Register.machine.space.get_main.add_local(:runner , :Integer)
|
Register.machine.space.get_main.add_local(:runner , :Integer)
|
||||||
@input = s(:statements, s(:assignment, s(:name, :runner), s(:int, 5)), s(:return, s(:name, :runner)))
|
@input = s(:statements, s(:assignment, s(:name, :runner), s(:int, 5)), s(:return, s(:name, :runner)))
|
||||||
@expect = [Label, LoadConstant,GetSlot,SetSlot,GetSlot,GetSlot ,SetSlot,
|
@expect = [Label, LoadConstant,GetSlot,RegToSlot,GetSlot,GetSlot ,RegToSlot,
|
||||||
Label,FunctionReturn]
|
Label,FunctionReturn]
|
||||||
check
|
check
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_return_call
|
def test_return_call
|
||||||
@input =s(:statements, s(:return, s(:call, s(:name, :main), s(:arguments))))
|
@input =s(:statements, s(:return, s(:call, s(:name, :main), s(:arguments))))
|
||||||
@expect = [Label, GetSlot, GetSlot, SetSlot, LoadConstant, SetSlot, LoadConstant ,
|
@expect = [Label, GetSlot, GetSlot, RegToSlot, LoadConstant, RegToSlot, LoadConstant ,
|
||||||
SetSlot, LoadConstant, SetSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer ,
|
RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer ,
|
||||||
GetSlot, GetSlot, SetSlot, Label, FunctionReturn]
|
GetSlot, GetSlot, RegToSlot, Label, FunctionReturn]
|
||||||
check
|
check
|
||||||
end
|
end
|
||||||
|
|
||||||
def pest_return_space_length # need to add runtime first
|
def pest_return_space_length # need to add runtime first
|
||||||
Register.machine.space.get_main.add_local(:l , :Type)
|
Register.machine.space.get_main.add_local(:l , :Type)
|
||||||
@input = s(:statements, s(:assignment, s(:name, :l), s(:call, s(:name, :get_type), s(:arguments), s(:receiver, s(:name, :space)))), s(:return, s(:field_access, s(:receiver, s(:name, :self)), s(:field, s(:name, :runner)))))
|
@input = s(:statements, s(:assignment, s(:name, :l), s(:call, s(:name, :get_type), s(:arguments), s(:receiver, s(:name, :space)))), s(:return, s(:field_access, s(:receiver, s(:name, :self)), s(:field, s(:name, :runner)))))
|
||||||
@expect = [Label, GetSlot,GetSlot ,SetSlot,Label,FunctionReturn]
|
@expect = [Label, GetSlot,GetSlot ,RegToSlot,Label,FunctionReturn]
|
||||||
check
|
check
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ module Register
|
|||||||
def test_while_mini
|
def test_while_mini
|
||||||
@input = s(:statements, s(:while_statement, :plus, s(:conditional, s(:int, 1)), s(:statements, s(:return, s(:int, 3)))))
|
@input = s(:statements, s(:while_statement, :plus, s(:conditional, s(:int, 1)), s(:statements, s(:return, s(:int, 3)))))
|
||||||
|
|
||||||
@expect = [Label, Branch, Label, LoadConstant, SetSlot, Label, LoadConstant ,
|
@expect = [Label, Branch, Label, LoadConstant, RegToSlot, Label, LoadConstant ,
|
||||||
IsPlus, Label, FunctionReturn]
|
IsPlus, Label, FunctionReturn]
|
||||||
check
|
check
|
||||||
end
|
end
|
||||||
@ -18,9 +18,9 @@ module Register
|
|||||||
|
|
||||||
@input = s(:statements, s(:assignment, s(:name, :n), s(:int, 5)), s(:while_statement, :plus, s(:conditional, s(:name, :n)), s(:statements, s(:assignment, s(:name, :n), s(:operator_value, :-, s(:name, :n), s(:int, 1))))), s(:return, s(:name, :n)))
|
@input = s(:statements, s(:assignment, s(:name, :n), s(:int, 5)), s(:while_statement, :plus, s(:conditional, s(:name, :n)), s(:statements, s(:assignment, s(:name, :n), s(:operator_value, :-, s(:name, :n), s(:int, 1))))), s(:return, s(:name, :n)))
|
||||||
|
|
||||||
@expect = [Label, LoadConstant, GetSlot, SetSlot, Branch, Label, GetSlot ,
|
@expect = [Label, LoadConstant, GetSlot, RegToSlot, Branch, Label, GetSlot ,
|
||||||
GetSlot, LoadConstant, OperatorInstruction, GetSlot, SetSlot, Label, GetSlot ,
|
GetSlot, LoadConstant, OperatorInstruction, GetSlot, RegToSlot, Label, GetSlot ,
|
||||||
GetSlot, IsPlus, GetSlot, GetSlot, SetSlot, Label, FunctionReturn]
|
GetSlot, IsPlus, GetSlot, GetSlot, RegToSlot, Label, FunctionReturn]
|
||||||
check
|
check
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -30,9 +30,9 @@ module Register
|
|||||||
|
|
||||||
@input = s(:statements, s(:assignment, s(:name, :n), s(:int, 10)), s(:while_statement, :plus, s(:conditional, s(:operator_value, :-, s(:name, :n), s(:int, 5))), s(:statements, s(:assignment, s(:name, :n), s(:operator_value, :+, s(:name, :n), s(:int, 1))), s(:return, s(:name, :n)))))
|
@input = s(:statements, s(:assignment, s(:name, :n), s(:int, 10)), s(:while_statement, :plus, s(:conditional, s(:operator_value, :-, s(:name, :n), s(:int, 5))), s(:statements, s(:assignment, s(:name, :n), s(:operator_value, :+, s(:name, :n), s(:int, 1))), s(:return, s(:name, :n)))))
|
||||||
|
|
||||||
@expect = [Label, LoadConstant, GetSlot, SetSlot, Branch, Label, GetSlot ,
|
@expect = [Label, LoadConstant, GetSlot, RegToSlot, Branch, Label, GetSlot ,
|
||||||
GetSlot, LoadConstant, OperatorInstruction, GetSlot, SetSlot, GetSlot, GetSlot ,
|
GetSlot, LoadConstant, OperatorInstruction, GetSlot, RegToSlot, GetSlot, GetSlot ,
|
||||||
SetSlot, Label, GetSlot, GetSlot, LoadConstant, OperatorInstruction, IsPlus ,
|
RegToSlot, Label, GetSlot, GetSlot, LoadConstant, OperatorInstruction, IsPlus ,
|
||||||
Label, FunctionReturn]
|
Label, FunctionReturn]
|
||||||
check
|
check
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user