same renames for bytes (set/get_byte)
This commit is contained in:
parent
f648bf7bd5
commit
a5946cb644
@ -59,11 +59,11 @@ module Arm
|
|||||||
args
|
args
|
||||||
end
|
end
|
||||||
|
|
||||||
def translate_GetByte code
|
def translate_ByteToReg code
|
||||||
ArmMachine.ldrb( *byte_args_for(code) )
|
ArmMachine.ldrb( *byte_args_for(code) )
|
||||||
end
|
end
|
||||||
|
|
||||||
def translate_SetByte code
|
def translate_RegToByte code
|
||||||
ArmMachine.strb( *byte_args_for(code) )
|
ArmMachine.strb( *byte_args_for(code) )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ module Register
|
|||||||
source = "get_internal_byte"
|
source = "get_internal_byte"
|
||||||
me , index = self_and_int_arg(compiler,source)
|
me , index = self_and_int_arg(compiler,source)
|
||||||
# reduce me to me[index]
|
# reduce me to me[index]
|
||||||
compiler.add_code GetByte.new( source , me , index , me)
|
compiler.add_code ByteToReg.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.reg_to_slot( source , me , :message , :return_value)
|
compiler.add_code Register.reg_to_slot( source , me , :message , :return_value)
|
||||||
return compiler.method
|
return compiler.method
|
||||||
@ -38,7 +38,7 @@ module Register
|
|||||||
me , index = self_and_int_arg(compiler,source)
|
me , index = self_and_int_arg(compiler,source)
|
||||||
value = load_arg_at(compiler , source , 2 )
|
value = load_arg_at(compiler , source , 2 )
|
||||||
# do the set
|
# do the set
|
||||||
compiler.add_code SetByte.new( source , value , me , index)
|
compiler.add_code RegToByte.new( source , value , me , index)
|
||||||
return compiler.method
|
return compiler.method
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -121,8 +121,8 @@ require_relative "instructions/setter"
|
|||||||
require_relative "instructions/getter"
|
require_relative "instructions/getter"
|
||||||
require_relative "instructions/reg_to_slot"
|
require_relative "instructions/reg_to_slot"
|
||||||
require_relative "instructions/slot_to_reg"
|
require_relative "instructions/slot_to_reg"
|
||||||
require_relative "instructions/set_byte"
|
require_relative "instructions/reg_to_byte"
|
||||||
require_relative "instructions/get_byte"
|
require_relative "instructions/byte_to_reg"
|
||||||
require_relative "instructions/load_constant"
|
require_relative "instructions/load_constant"
|
||||||
require_relative "instructions/syscall"
|
require_relative "instructions/syscall"
|
||||||
require_relative "instructions/function_call"
|
require_relative "instructions/function_call"
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
module Register
|
module Register
|
||||||
|
|
||||||
# GetByte moves a single byte into a register from memory.
|
# ByteToReg moves a single byte into a register from memory.
|
||||||
|
|
||||||
# indexes are 1 based (as for slots) , which means we sacrifice a byte of every word
|
# indexes are 1 based (as for slots) , which means we sacrifice a byte of every word
|
||||||
# for our sanity
|
# for our sanity
|
||||||
|
|
||||||
class GetByte < Getter
|
class ByteToReg < Getter
|
||||||
|
|
||||||
# If you had a c array (of int8) and index offset
|
# If you had a c array (of int8) and index offset
|
||||||
# the instruction would do register = array[index]
|
# the instruction would do register = array[index]
|
||||||
@ -18,12 +18,12 @@ module Register
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Produce a GetByte instruction.
|
# Produce a ByteToReg instruction.
|
||||||
# from and to are translated (from symbol to register if neccessary)
|
# from and to are translated (from symbol to register if neccessary)
|
||||||
# but index is left as is.
|
# but index is left as is.
|
||||||
# def self.get_byte source , array , index , to
|
# def self.byte_to_reg source , array , index , to
|
||||||
# from = resolve_to_register from
|
# from = resolve_to_register from
|
||||||
# to = resolve_to_register to
|
# to = resolve_to_register to
|
||||||
# GetByte.new( source , array , index , to)
|
# ByteToReg.new( source , array , index , to)
|
||||||
# end
|
# end
|
||||||
end
|
end
|
@ -1,6 +1,6 @@
|
|||||||
module Register
|
module Register
|
||||||
|
|
||||||
# Getter is a base class for get instructions (SlotToReg and GetByte , possibly more coming)
|
# Getter is a base class for get instructions (SlotToReg and ByteToReg , possibly more coming)
|
||||||
#
|
#
|
||||||
# The instruction that is modelled is loading data from an array into a register
|
# The instruction that is modelled is loading data from an array into a register
|
||||||
#
|
#
|
||||||
|
@ -1,21 +1,21 @@
|
|||||||
module Register
|
module Register
|
||||||
|
|
||||||
# SetByte moves a byte into memory from a register.
|
# RegToByte moves a byte into memory from a register.
|
||||||
|
|
||||||
# indexes are 1 based !
|
# indexes are 1 based !
|
||||||
|
|
||||||
class SetByte < Setter
|
class RegToByte < Setter
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Produce a SetByte instruction.
|
# Produce a RegToByte instruction.
|
||||||
# from and to are translated (from symbol to register if neccessary)
|
# from and to are translated (from symbol to register if neccessary)
|
||||||
# but index is left as is.
|
# but index is left as is.
|
||||||
# def self.set_byte source , from , to , index
|
# def self.reg_to_byte 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
|
||||||
# SetByte.new( source, from , to , index)
|
# RegToByte.new( source, from , to , index)
|
||||||
# end
|
# end
|
||||||
|
|
||||||
end
|
end
|
@ -1,5 +1,5 @@
|
|||||||
module Register
|
module Register
|
||||||
# Setter is a base class for set instructions (RegToSlot and SetByte , possibly more coming)
|
# Setter is a base class for set instructions (RegToSlot and RegToByte , 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
|
||||||
#
|
#
|
||||||
|
@ -157,7 +157,7 @@ module Register
|
|||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
def execute_GetByte
|
def execute_ByteToReg
|
||||||
object = get_register( @instruction.array )
|
object = get_register( @instruction.array )
|
||||||
if( @instruction.index.is_a?(Numeric) )
|
if( @instruction.index.is_a?(Numeric) )
|
||||||
index = @instruction.index
|
index = @instruction.index
|
||||||
@ -171,7 +171,7 @@ module Register
|
|||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
def execute_SetByte
|
def execute_RegToByte
|
||||||
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) )
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
require_relative "test_add"
|
require_relative "test_add"
|
||||||
require_relative "test_change"
|
require_relative "test_change"
|
||||||
require_relative "test_get_byte"
|
require_relative "test_byte_to_reg"
|
||||||
require_relative "test_if"
|
require_relative "test_if"
|
||||||
require_relative "test_puts"
|
require_relative "test_puts"
|
||||||
require_relative "test_plus"
|
require_relative "test_plus"
|
||||||
require_relative "test_mult"
|
require_relative "test_mult"
|
||||||
require_relative "test_set_byte"
|
require_relative "test_reg_to_byte"
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
require_relative "helper"
|
require_relative "helper"
|
||||||
|
|
||||||
class TestInterpretSetByte < MiniTest::Test
|
class TestInterpretRegToByte < MiniTest::Test
|
||||||
include Ticker
|
include Ticker
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@ -25,7 +25,7 @@ HERE
|
|||||||
"LoadConstant","RegToSlot","LoadConstant","RegToSlot","LoadConstant",
|
"LoadConstant","RegToSlot","LoadConstant","RegToSlot","LoadConstant",
|
||||||
"RegToSlot","LoadConstant","RegToSlot","LoadConstant","RegToSlot",
|
"RegToSlot","LoadConstant","RegToSlot","LoadConstant","RegToSlot",
|
||||||
"LoadConstant","RegToSlot","RegisterTransfer","FunctionCall","Label",
|
"LoadConstant","RegToSlot","RegisterTransfer","FunctionCall","Label",
|
||||||
"SlotToReg","SlotToReg","SlotToReg","SetByte","Label",
|
"SlotToReg","SlotToReg","SlotToReg","RegToByte","Label",
|
||||||
"FunctionReturn","RegisterTransfer","SlotToReg","SlotToReg","Label",
|
"FunctionReturn","RegisterTransfer","SlotToReg","SlotToReg","Label",
|
||||||
"FunctionReturn","RegisterTransfer","Syscall","NilClass"]
|
"FunctionReturn","RegisterTransfer","Syscall","NilClass"]
|
||||||
end
|
end
|
||||||
@ -54,9 +54,9 @@ HERE
|
|||||||
assert_equal NilClass , done.class
|
assert_equal NilClass , done.class
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_set_byte
|
def test_reg_to_byte
|
||||||
done = ticks(29)
|
done = ticks(29)
|
||||||
assert_equal Register::SetByte , done.class
|
assert_equal Register::RegToByte , done.class
|
||||||
assert_equal "h".ord , @interpreter.get_register(done.register)
|
assert_equal "h".ord , @interpreter.get_register(done.register)
|
||||||
end
|
end
|
||||||
|
|
@ -1,6 +1,6 @@
|
|||||||
require_relative "helper"
|
require_relative "helper"
|
||||||
|
|
||||||
class TestInterpretGetByte < MiniTest::Test
|
class TestInterpretByteToReg < MiniTest::Test
|
||||||
include Ticker
|
include Ticker
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@ -25,7 +25,7 @@ HERE
|
|||||||
"LoadConstant","RegToSlot","LoadConstant","RegToSlot","LoadConstant",
|
"LoadConstant","RegToSlot","LoadConstant","RegToSlot","LoadConstant",
|
||||||
"RegToSlot","LoadConstant","RegToSlot","LoadConstant","RegToSlot",
|
"RegToSlot","LoadConstant","RegToSlot","LoadConstant","RegToSlot",
|
||||||
"RegisterTransfer","FunctionCall","Label","SlotToReg","SlotToReg",
|
"RegisterTransfer","FunctionCall","Label","SlotToReg","SlotToReg",
|
||||||
"GetByte","RegToSlot","Label","FunctionReturn","RegisterTransfer",
|
"ByteToReg","RegToSlot","Label","FunctionReturn","RegisterTransfer",
|
||||||
"SlotToReg","SlotToReg","Label","FunctionReturn","RegisterTransfer",
|
"SlotToReg","SlotToReg","Label","FunctionReturn","RegisterTransfer",
|
||||||
"Syscall","NilClass"]
|
"Syscall","NilClass"]
|
||||||
end
|
end
|
||||||
@ -54,9 +54,9 @@ HERE
|
|||||||
assert_equal NilClass , done.class
|
assert_equal NilClass , done.class
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_get_byte
|
def test_byte_to_reg
|
||||||
done = ticks(26)
|
done = ticks(26)
|
||||||
assert_equal Register::GetByte , done.class
|
assert_equal Register::ByteToReg , done.class
|
||||||
assert_equal "H".ord , @interpreter.get_register(done.register)
|
assert_equal "H".ord , @interpreter.get_register(done.register)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user