shaves an instruction off resolve_method

by loading nil directly,  not space first
This commit is contained in:
Torsten Ruger 2018-09-01 11:20:59 +03:00
parent c3b026a180
commit 0a390cc5a9
7 changed files with 61 additions and 66 deletions

View File

@ -101,9 +101,6 @@ module Arm
right = Risc::Position.get(left) - 8
right -= Risc::Position.get(self).at
if( (right < 0) && ((opcode == :add) || (opcode == :sub)) )
puts "Inverting, was #{right} , new #{-1*right}"
puts "left #{left.class} #{Risc::Position.get(left)}"
puts "self #{Risc::Position.get(self)}"
right *= -1 # this works as we never issue sub only add
set_opcode :sub # so (as we can't change the sign permanently) we can change the opcode
end # and the sign even for sub (beucase we created them)

View File

@ -45,9 +45,8 @@ module Mom
add_code while_start_label
space! << Parfait.object_space
space << space[:nil_object]
space - callable_method
object! << Parfait.object_space.nil_object
object - callable_method
if_zero exit_label
name! << callable_method[:name]

View File

@ -103,7 +103,9 @@ module Risc
def prerun
assemblers.each do |asm|
asm.instructions.each {|i| i.precheck }
asm.instructions.each do |ins|
ins.precheck
end
end
end

View File

@ -10,16 +10,15 @@ module Risc
@expect = [LoadConstant, SlotToReg, SlotToReg, SlotToReg, SlotToReg,
OperatorInstruction, IsZero, SlotToReg, SlotToReg, SlotToReg,
LoadConstant, RegToSlot, LoadConstant, LoadConstant, SlotToReg,
SlotToReg, Label, LoadConstant, SlotToReg, OperatorInstruction,
IsZero, SlotToReg, OperatorInstruction, IsZero, SlotToReg,
Branch, Label, Transfer, Syscall, Transfer,
Transfer, LoadConstant, SlotToReg, SlotToReg, RegToSlot,
RegToSlot, RegToSlot, Label, RegToSlot, Label,
LoadConstant, SlotToReg, LoadConstant, SlotToReg, SlotToReg,
RegToSlot, RegToSlot, RegToSlot, RegToSlot, SlotToReg,
SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg,
RegToSlot, SlotToReg, LoadConstant, SlotToReg, DynamicJump,
Label]
SlotToReg, Label, LoadConstant, OperatorInstruction, IsZero,
SlotToReg, OperatorInstruction, IsZero, SlotToReg, Branch,
Label, Transfer, Syscall, Transfer, Transfer,
LoadConstant, SlotToReg, SlotToReg, RegToSlot, RegToSlot,
RegToSlot, Label, RegToSlot, Label, LoadConstant,
SlotToReg, LoadConstant, SlotToReg, SlotToReg, RegToSlot,
RegToSlot, RegToSlot, RegToSlot, SlotToReg, SlotToReg,
SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot,
SlotToReg, LoadConstant, SlotToReg, DynamicJump, Label]
end
def test_send_instructions
@ -27,23 +26,23 @@ module Risc
end
def test_sys
produced = produce_body
assert_equal Syscall , produced.next(28).class
assert_equal :exit , produced.next(28).name
assert_equal Syscall , produced.next(27).class
assert_equal :exit , produced.next(27).name
end
def test_load_address
produced = produce_body
assert_equal LoadConstant , produced.next(40).class
assert_equal Parfait::CacheEntry , produced.next(40).constant.class
assert_equal LoadConstant , produced.next(41).class
assert_equal Parfait::Factory , produced.next(41).constant.class
end
def test_function_call
produced = produce_body
assert_equal DynamicJump , produced.next(59).class
assert_equal DynamicJump , produced.next(58).class
end
def test_cache_check
produced = produce_body
assert_equal IsZero , produced.next(6).class
assert_equal Label , produced.next(39).class
assert_equal produced.next(39) , produced.next(6).label
assert_equal Label , produced.next(38).class
assert_equal produced.next(38) , produced.next(6).label
end
end
end

View File

@ -10,17 +10,17 @@ module Risc
@expect = [LoadConstant, SlotToReg, SlotToReg, SlotToReg, SlotToReg,
OperatorInstruction, IsZero, SlotToReg, SlotToReg, SlotToReg,
LoadConstant, RegToSlot, LoadConstant, LoadConstant, SlotToReg,
SlotToReg, Label, LoadConstant, SlotToReg, OperatorInstruction,
IsZero, SlotToReg, OperatorInstruction, IsZero, SlotToReg,
Branch, Label, Transfer, Syscall, Transfer,
Transfer, LoadConstant, SlotToReg, SlotToReg, RegToSlot,
RegToSlot, RegToSlot, Label, RegToSlot, Label,
LoadConstant, SlotToReg, LoadConstant, SlotToReg, SlotToReg,
RegToSlot, RegToSlot, RegToSlot, RegToSlot, SlotToReg,
SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg,
RegToSlot, SlotToReg, LoadConstant, SlotToReg, DynamicJump,
Label, SlotToReg, SlotToReg, RegToSlot, SlotToReg,
SlotToReg, RegToSlot, Branch]
SlotToReg, Label, LoadConstant, OperatorInstruction, IsZero,
SlotToReg, OperatorInstruction, IsZero, SlotToReg, Branch,
Label, Transfer, Syscall, Transfer, Transfer,
LoadConstant, SlotToReg, SlotToReg, RegToSlot, RegToSlot,
RegToSlot, Label, RegToSlot, Label, LoadConstant,
SlotToReg, LoadConstant, SlotToReg, SlotToReg, RegToSlot,
RegToSlot, RegToSlot, RegToSlot, SlotToReg, SlotToReg,
SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot,
SlotToReg, LoadConstant, SlotToReg, DynamicJump, Label,
SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
RegToSlot, Branch]
end
def test_return_instructions
@ -28,7 +28,7 @@ module Risc
end
def test_function_return
produced = produce_body
assert_equal Branch , produced.next(67).class
assert_equal Branch , produced.next(66).class
end
def test_cache_check
produced = produce_body

View File

@ -15,32 +15,30 @@ module Risc
SlotToReg, SlotToReg, SlotToReg, OperatorInstruction, IsZero, # 10
SlotToReg, SlotToReg, SlotToReg, Branch, LoadConstant,
RegToSlot, LoadConstant, LoadConstant, SlotToReg, SlotToReg, # 20
LoadConstant, SlotToReg, OperatorInstruction, IsZero, SlotToReg,
OperatorInstruction, IsZero, Branch, SlotToReg, Branch, # 30
LoadConstant, SlotToReg, OperatorInstruction, IsZero, SlotToReg,
OperatorInstruction, IsZero, Branch, SlotToReg, Branch, # 40
LoadConstant, SlotToReg, OperatorInstruction, IsZero, SlotToReg,
OperatorInstruction, IsZero, Branch, SlotToReg, Branch, # 50
LoadConstant, SlotToReg, OperatorInstruction, IsZero, SlotToReg,
OperatorInstruction, IsZero, Branch, SlotToReg, Branch, # 60
LoadConstant, SlotToReg, OperatorInstruction, IsZero, SlotToReg,
OperatorInstruction, IsZero, Branch, SlotToReg, Branch, # 70
LoadConstant, SlotToReg, OperatorInstruction, IsZero, SlotToReg,
OperatorInstruction, IsZero, RegToSlot, Branch, LoadConstant, # 80
SlotToReg, LoadConstant, SlotToReg, SlotToReg, RegToSlot,
RegToSlot, RegToSlot, RegToSlot, SlotToReg, SlotToReg, # 90
SlotToReg, RegToSlot, Branch, LoadConstant, SlotToReg,
RegToSlot, SlotToReg, LoadConstant, SlotToReg, DynamicJump, # 100
SlotToReg, SlotToReg, LoadData, OperatorInstruction, LoadConstant,
SlotToReg, SlotToReg, RegToSlot, RegToSlot, RegToSlot, # 110
SlotToReg, SlotToReg, RegToSlot, Branch, LoadConstant,
SlotToReg, RegToSlot, RegToSlot, SlotToReg, SlotToReg, # 120
SlotToReg, FunctionReturn, SlotToReg, SlotToReg, RegToSlot,
SlotToReg, SlotToReg, RegToSlot, Branch, Branch, # 130
SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg,
RegToSlot, RegToSlot, SlotToReg, SlotToReg, SlotToReg, # 140
FunctionReturn, Transfer, SlotToReg, SlotToReg, Syscall,
NilClass, ]
LoadConstant, OperatorInstruction, IsZero, SlotToReg, OperatorInstruction,
IsZero, SlotToReg, Branch, Branch, LoadConstant, # 30
OperatorInstruction, IsZero, SlotToReg, OperatorInstruction, IsZero,
SlotToReg, Branch, Branch, LoadConstant, OperatorInstruction, # 40
IsZero, SlotToReg, OperatorInstruction, IsZero, SlotToReg,
Branch, Branch, LoadConstant, OperatorInstruction, IsZero, # 50
SlotToReg, OperatorInstruction, IsZero, SlotToReg, Branch,
Branch, LoadConstant, OperatorInstruction, IsZero, SlotToReg, # 60
OperatorInstruction, IsZero, SlotToReg, Branch, Branch,
LoadConstant, OperatorInstruction, IsZero, SlotToReg, OperatorInstruction, # 70
IsZero, RegToSlot, LoadConstant, Branch, SlotToReg,
LoadConstant, SlotToReg, SlotToReg, RegToSlot, RegToSlot, # 80
RegToSlot, RegToSlot, SlotToReg, SlotToReg, SlotToReg,
RegToSlot, LoadConstant, Branch, SlotToReg, RegToSlot, # 90
SlotToReg, LoadConstant, SlotToReg, DynamicJump, SlotToReg,
SlotToReg, LoadData, OperatorInstruction, LoadConstant, SlotToReg, # 100
SlotToReg, RegToSlot, RegToSlot, RegToSlot, SlotToReg,
SlotToReg, RegToSlot, Branch, LoadConstant, SlotToReg, # 110
RegToSlot, RegToSlot, SlotToReg, SlotToReg, SlotToReg,
FunctionReturn, SlotToReg, SlotToReg, RegToSlot, SlotToReg, # 120
SlotToReg, RegToSlot, Branch, SlotToReg, SlotToReg,
RegToSlot, LoadConstant, SlotToReg, RegToSlot, RegToSlot, # 130
SlotToReg, SlotToReg, SlotToReg, FunctionReturn, Transfer,
SlotToReg, SlotToReg, Syscall, NilClass, ]
assert_equal Fixnum , get_return.class
assert_equal 1 , get_return
end
@ -57,17 +55,17 @@ module Risc
end
def test_dyn
cal = main_ticks(100)
cal = main_ticks(94)
assert_equal DynamicJump , cal.class
end
def test_return
ret = main_ticks(141)
ret = main_ticks(134)
assert_equal FunctionReturn , ret.class
link = @interpreter.get_register( ret.register )
assert_equal Fixnum , link.class
end
def test_sys
sys = main_ticks(145)
sys = main_ticks(138)
assert_equal Syscall , sys.class
end
end

View File

@ -1,7 +1,7 @@
require_relative "../helper"
module Risc
class TestRegisterValue < MiniTest::Test
class TestRegisterValue1 < MiniTest::Test
def setup
Parfait.boot!