also redid the get/set internal byte with builder
had to pimp register value to use a semblance of the dsl using <= for bytes and << for words
This commit is contained in:
parent
7002956e81
commit
99a95d40a6
@ -21,15 +21,16 @@ module Risc
|
|||||||
# return (and word sized int) is stored in return_value
|
# return (and word sized int) is stored in return_value
|
||||||
def get_internal_byte( context)
|
def get_internal_byte( context)
|
||||||
compiler = compiler_for(:Word , :get_internal_byte , {at: :Integer})
|
compiler = compiler_for(:Word , :get_internal_byte , {at: :Integer})
|
||||||
source = "get_internal_byte"
|
compiler.compiler_builder(compiler.source).build do
|
||||||
builder = compiler.compiler_builder(compiler.source)
|
object << message[:receiver]
|
||||||
me , index = builder.self_and_int_arg(source)
|
integer << message[:arguments]
|
||||||
builder.reduce_int( source + " fix arg", index )
|
integer << integer[1]
|
||||||
# reduce me to me[index]
|
integer.reduce_int
|
||||||
builder.add_byte_to_reg( source , me , index , me)
|
object <= object[integer]
|
||||||
builder.add_new_int(source, me , index)
|
add_new_int("get_internal_byte", object , integer)
|
||||||
# and put it back into the return value
|
message[:return_value] << integer
|
||||||
builder.add_reg_to_slot( source , index , Risc.message_reg , :return_value)
|
end
|
||||||
|
|
||||||
compiler.add_mom( Mom::ReturnSequence.new)
|
compiler.add_mom( Mom::ReturnSequence.new)
|
||||||
return compiler
|
return compiler
|
||||||
end
|
end
|
||||||
@ -39,15 +40,18 @@ module Risc
|
|||||||
# return self
|
# return self
|
||||||
def set_internal_byte( context )
|
def set_internal_byte( context )
|
||||||
compiler = compiler_for(:Word, :set_internal_byte , {at: :Integer , :value => :Integer} )
|
compiler = compiler_for(:Word, :set_internal_byte , {at: :Integer , :value => :Integer} )
|
||||||
source = "set_internal_byte"
|
compiler.compiler_builder(compiler.source).build do
|
||||||
builder = compiler.compiler_builder(compiler.source)
|
word << message[:receiver]
|
||||||
me , index = builder.self_and_int_arg(source)
|
integer << message[:arguments]
|
||||||
value = builder.load_int_arg_at(source , 1 )
|
integer << integer[1]
|
||||||
builder.reduce_int( source + " fix me", value )
|
integer_reg << message[:arguments]
|
||||||
builder.reduce_int( source + " fix arg", index )
|
integer_obj << integer_reg[2]
|
||||||
builder.add_reg_to_byte( source , value , me , index)
|
integer_reg << integer_reg[2]
|
||||||
value = builder.load_int_arg_at(source , 1 )
|
integer.reduce_int
|
||||||
builder.add_reg_to_slot( source , value , Risc.message_reg , :return_value)
|
integer_reg.reduce_int
|
||||||
|
word[integer] <= integer_reg
|
||||||
|
message[:return_value] << integer_obj
|
||||||
|
end
|
||||||
compiler.add_mom( Mom::ReturnSequence.new)
|
compiler.add_mom( Mom::ReturnSequence.new)
|
||||||
return compiler
|
return compiler
|
||||||
end
|
end
|
||||||
|
@ -140,6 +140,15 @@ module Risc
|
|||||||
return ins
|
return ins
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# similar to above (<< which produces slot_to_reg), this produces byte_to_reg
|
||||||
|
# since << covers all other cases, this must have a RValue as the right
|
||||||
|
def <=( right )
|
||||||
|
raise "not implemented for #{right.class}:#{right}" unless right.is_a?( RValue )
|
||||||
|
ins = Risc.byte_to_reg("#{right.register.type}[#{right.index}] -> #{self.type}" , right.register , right.index , self)
|
||||||
|
builder.add_code(ins) if builder
|
||||||
|
return ins
|
||||||
|
end
|
||||||
|
|
||||||
def -( right )
|
def -( right )
|
||||||
raise "operators only on registers, not #{right.class}" unless right.is_a? RegisterValue
|
raise "operators only on registers, not #{right.class}" unless right.is_a? RegisterValue
|
||||||
op = Risc.op("#{self.type} - #{right.type}", :- , self , right )
|
op = Risc.op("#{self.type} - #{right.type}", :- , self , right )
|
||||||
@ -187,6 +196,15 @@ module Risc
|
|||||||
reg_to_slot
|
reg_to_slot
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# similar to above (<< which produces reg_to_slot), this produces reg_to_byte
|
||||||
|
# from itself (the slot) and the register given
|
||||||
|
def <=( reg )
|
||||||
|
raise "not reg #{reg}" unless reg.is_a?(RegisterValue)
|
||||||
|
reg_to_byte = Risc.reg_to_byte("#{reg.class_name} -> #{register.class_name}[#{index}]" , reg , register, index)
|
||||||
|
builder.add_code(reg_to_byte) if builder
|
||||||
|
reg_to_byte
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# The register we use to store the current message object is :r0
|
# The register we use to store the current message object is :r0
|
||||||
|
@ -18,19 +18,19 @@ module Risc
|
|||||||
SlotToReg, RegToSlot, LoadConstant, SlotToReg, SlotToReg,
|
SlotToReg, RegToSlot, LoadConstant, SlotToReg, SlotToReg,
|
||||||
RegToSlot, LoadConstant, Branch, SlotToReg, RegToSlot,
|
RegToSlot, LoadConstant, Branch, SlotToReg, RegToSlot,
|
||||||
SlotToReg, FunctionCall, SlotToReg, SlotToReg, SlotToReg,
|
SlotToReg, FunctionCall, SlotToReg, SlotToReg, SlotToReg,
|
||||||
SlotToReg, SlotToReg, SlotToReg, SlotToReg, RegToByte,
|
SlotToReg, SlotToReg, SlotToReg, SlotToReg, SlotToReg,
|
||||||
SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
|
RegToByte, RegToSlot, SlotToReg, SlotToReg, RegToSlot,
|
||||||
Branch, RegToSlot, LoadConstant, SlotToReg, RegToSlot,
|
Branch, LoadConstant, SlotToReg, RegToSlot, RegToSlot,
|
||||||
RegToSlot, SlotToReg, SlotToReg, SlotToReg, FunctionReturn,
|
SlotToReg, SlotToReg, SlotToReg, FunctionReturn, SlotToReg,
|
||||||
SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
|
SlotToReg, RegToSlot, SlotToReg, SlotToReg, RegToSlot,
|
||||||
RegToSlot, Branch, SlotToReg, SlotToReg, Branch,
|
Branch, SlotToReg, SlotToReg, Branch, RegToSlot,
|
||||||
RegToSlot, LoadConstant, SlotToReg, RegToSlot, RegToSlot,
|
LoadConstant, SlotToReg, RegToSlot, RegToSlot, SlotToReg,
|
||||||
SlotToReg, SlotToReg, SlotToReg, FunctionReturn, Transfer,
|
SlotToReg, SlotToReg, FunctionReturn, Transfer, SlotToReg,
|
||||||
SlotToReg, SlotToReg, Branch, Syscall, NilClass]
|
SlotToReg, Branch, Syscall, NilClass]
|
||||||
assert_equal "K".ord , get_return
|
assert_equal "K".ord , get_return
|
||||||
end
|
end
|
||||||
def test_reg_to_byte
|
def test_reg_to_byte
|
||||||
done = main_ticks(40)
|
done = main_ticks(41)
|
||||||
assert_equal RegToByte , done.class
|
assert_equal RegToByte , done.class
|
||||||
assert_equal "K".ord , @interpreter.get_register(done.register)
|
assert_equal "K".ord , @interpreter.get_register(done.register)
|
||||||
end
|
end
|
||||||
|
@ -59,6 +59,13 @@ module Risc
|
|||||||
assert_equal @r1 , ret.right
|
assert_equal @r1 , ret.right
|
||||||
assert_equal :<< , ret.operator
|
assert_equal :<< , ret.operator
|
||||||
end
|
end
|
||||||
|
def test_byte_to_reg
|
||||||
|
instr = @r0 <= @r1[1]
|
||||||
|
assert_equal ByteToReg , instr.class
|
||||||
|
assert_equal @r1 , instr.array
|
||||||
|
assert_equal @r0 , instr.register
|
||||||
|
assert_equal 1 , instr.index
|
||||||
|
end
|
||||||
def test_slot_to_reg
|
def test_slot_to_reg
|
||||||
instr = @r0 << @r1[:next_message]
|
instr = @r0 << @r1[:next_message]
|
||||||
assert_equal SlotToReg , instr.class
|
assert_equal SlotToReg , instr.class
|
||||||
@ -66,6 +73,13 @@ module Risc
|
|||||||
assert_equal @r0 , instr.register
|
assert_equal @r0 , instr.register
|
||||||
assert_equal 3 , instr.index
|
assert_equal 3 , instr.index
|
||||||
end
|
end
|
||||||
|
def test_reg_to_byte
|
||||||
|
instr = @r1[1] <= @r0
|
||||||
|
assert_equal RegToByte , instr.class
|
||||||
|
assert_equal @r1 , instr.array
|
||||||
|
assert_equal @r0 , instr.register
|
||||||
|
assert_equal 1 , instr.index
|
||||||
|
end
|
||||||
def test_reg_to_slot
|
def test_reg_to_slot
|
||||||
instr = @r1[:next_message] << @r0
|
instr = @r1[:next_message] << @r0
|
||||||
assert_equal RegToSlot , instr.class
|
assert_equal RegToSlot , instr.class
|
||||||
|
Loading…
Reference in New Issue
Block a user