fix many tests with preloading

preloading, something akin to builtin, loads some very small predefined (macro) methods for the tests to work (ie call)
This commit is contained in:
2019-09-12 22:27:10 +03:00
parent e33b9f565d
commit 4bf23defc8
42 changed files with 98 additions and 126 deletions

View File

@ -5,8 +5,7 @@ module Risc
include Statements
def setup
super
@input = "@ivar = 5;return"
@input = "@nil_object = 5;return"
@expect = [LoadConstant, SlotToReg, RegToSlot, LoadConstant, RegToSlot, Branch]
end

View File

@ -5,7 +5,6 @@ module Risc
include Statements
def setup
super
@input = "local = arg; return local"
@expect = [SlotToReg, RegToSlot, SlotToReg, RegToSlot, Branch] #4
end

View File

@ -5,7 +5,6 @@ module Risc
include Statements
def setup
super
@input = "r = false;return"
@expect = [LoadConstant, RegToSlot,LoadConstant, RegToSlot, Branch]
end

View File

@ -5,7 +5,6 @@ module Risc
include Statements
def setup
super
@input = "r = 5;return"
@expect = [LoadConstant, RegToSlot, LoadConstant, RegToSlot, Branch]
end

View File

@ -5,8 +5,7 @@ module Risc
include Statements
def setup
super
@input = "@ivar = 5 ; r = @ivar;return"
@input = "@nil_object = 5 ; r = @nil_object;return"
@expect = [LoadConstant, SlotToReg, RegToSlot, SlotToReg, SlotToReg, #4
RegToSlot, LoadConstant, RegToSlot, Branch] #9
end

View File

@ -5,7 +5,7 @@ module Risc
include Statements
def setup
super
@preload = "Integer.div4"
@input = "r = 5.div4;return"
@expect = [LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #5
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, #10

View File

@ -5,7 +5,6 @@ module Risc
include Statements
def setup
super
@input = as_block("a = 5")
@expect = [LoadConstant, RegToSlot]
end

View File

@ -5,7 +5,6 @@ module Risc
include Statements
def setup
super
@input = as_block("return 5")
@mom = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_mom(as_main)
end

View File

@ -5,7 +5,7 @@ module Risc
include Statements
def setup
super
@input = as_block("return 5")
@expect = [LoadConstant, RegToSlot, LoadConstant, SlotToReg, RegToSlot, #5
SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #10

View File

@ -5,7 +5,6 @@ module Risc
include Statements
def setup
super
@class_input = "def self.simple_return; return 1 ; end;"
@input = "return Test.simple_return"
@expect = [LoadConstant, RegToSlot, Branch]

View File

@ -3,8 +3,7 @@ require_relative '../helper'
module Risc
module Statements
include Output
def setup
end
include Preloader
def preamble
[ Label ]
@ -23,7 +22,7 @@ module Risc
"#{method_input} ; self.main{|val| #{block_input}}"
end
def as_main
"class Space; #{@class_input if @class_input};def main(arg);#{@input};end;end"
"#{preload}class Space; #{@class_input};def main(arg);#{@input};end;end"
end
def to_target
assert @expect , "No output given"

View File

@ -5,8 +5,8 @@ module Risc
include Statements
def setup
super
@input = "@a.div4"
@preload = "Integer.div4"
@input = "@classes.div4"
@expect = [LoadConstant, SlotToReg, SlotToReg, SlotToReg, SlotToReg, #5
OperatorInstruction, IsZero, SlotToReg, SlotToReg, SlotToReg, #10
LoadConstant, RegToSlot, LoadConstant, LoadConstant, SlotToReg, #15

View File

@ -5,7 +5,7 @@ module Risc
include Statements
def setup
super
@preload = "Integer.div4"
@input = "5.div4"
@expect = [LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #5
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, #10

View File

@ -5,7 +5,7 @@ module Risc
include Statements
def setup
super
@preload = "Object.get"
@input = "5.get_internal_word(1)"
@expect = [LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #5
RegToSlot, LoadConstant, SlotToReg, RegToSlot, LoadConstant, #10

View File

@ -5,7 +5,7 @@ module Risc
include Statements
def setup
super
@preload = "Integer.div4"
@input = "return 5.div4"
@expect = [LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #5
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, #10

View File

@ -5,8 +5,7 @@ module Risc
include Statements
def setup
super
@input = "if(@a) ; arg = 5 ; else; arg = 6; end;return"
@input = "if(@true_object) ; arg = 5 ; else; arg = 6; end;return"
@expect = [SlotToReg, SlotToReg, LoadConstant, OperatorInstruction, IsZero, #4
LoadConstant, OperatorInstruction, IsZero, Label, LoadConstant, #9
RegToSlot, Branch, Label, LoadConstant, RegToSlot, #14

View File

@ -5,8 +5,7 @@ module Risc
include Statements
def setup
super
@input = "if(@a) ; arg = 5 ; end;return"
@input = "if(@true_object) ; arg = 5 ; end;return"
@expect = [SlotToReg, SlotToReg, LoadConstant, OperatorInstruction, IsZero, #4
LoadConstant, OperatorInstruction, IsZero, Label, LoadConstant, #9
RegToSlot, Label, LoadConstant, RegToSlot, Branch] #14

View File

@ -6,7 +6,7 @@ module Risc
def setup
super
@input = "unless(@a) ; arg = 5 ; end;return"
@input = "unless(@true_object) ; arg = 5 ; end;return"
@expect = [SlotToReg, SlotToReg, LoadConstant, OperatorInstruction, IsZero, #4
LoadConstant, OperatorInstruction, IsZero, Label, Branch, #9
Label, LoadConstant, RegToSlot, Label, LoadConstant, #14

View File

@ -5,7 +5,7 @@ module Risc
include Statements
def setup
super
@preload = "Integer.div4"
@input = "return 5.div4"
@expect = [LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #5
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, #10

View File

@ -5,8 +5,8 @@ module Risc
include Statements
def setup
super
@input = "return @a.div4"
@preload = "Integer.div4"
@input = "return @nil_object.div4"
@expect = [LoadConstant, SlotToReg, SlotToReg, SlotToReg, SlotToReg, #5
OperatorInstruction, IsZero, SlotToReg, SlotToReg, SlotToReg, #10
LoadConstant, RegToSlot, LoadConstant, LoadConstant, SlotToReg, #15

View File

@ -5,7 +5,7 @@ module Risc
include Statements
def setup
super
@preload = "Integer.div4"
@input = "return 5.div4"
@expect = "something"
end

View File

@ -5,7 +5,6 @@ module Risc
include Statements
def setup
super
@input = "return 5"
@expect = [LoadConstant, RegToSlot, Branch]
end

View File

@ -5,8 +5,8 @@ module Risc
include Statements
def setup
super
@input = "while(5 > 0) ; @a = true; end;return"
@preload = "Integer.ge"
@input = "while(5 > 0) ; @false_object = true; end;return"
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, LoadConstant, #5
SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot, #10
LoadConstant, SlotToReg, RegToSlot, SlotToReg, FunctionCall, #15

View File

@ -5,8 +5,7 @@ module Risc
include Statements
def setup
super
@input = "while(@a) ; arg = 5 end;return"
@input = "while(@true_object) ; arg = 5 end;return"
@expect = [Label, SlotToReg, SlotToReg, LoadConstant, OperatorInstruction, #4
IsZero, LoadConstant, OperatorInstruction, IsZero, LoadConstant, #9
RegToSlot, Branch, Label, LoadConstant, RegToSlot, #14