adds multiplication
without overflow testing, like the others
This commit is contained in:
parent
1d57c59dab
commit
3a9539a071
@ -184,7 +184,7 @@ module Risc
|
||||
end
|
||||
|
||||
obj = space.get_class_by_name(:Integer)
|
||||
[ :putint, :mod4, :div10, :+ , :-].each do |f| #mod4 is just a forward declaration
|
||||
[ :putint, :mod4, :div10, :+ , :- , :*].each do |f| #mod4 is just a forward declaration
|
||||
obj.instance_type.add_method Builtin::Integer.send(f , nil)
|
||||
end
|
||||
end
|
||||
|
@ -23,6 +23,9 @@ module Risc
|
||||
compiler.add_mom( Mom::ReturnSequence.new)
|
||||
return compiler.method
|
||||
end
|
||||
def *( context )
|
||||
operator_method( "mult" , :*)
|
||||
end
|
||||
def +( context )
|
||||
operator_method( "plus" , :+)
|
||||
end
|
||||
|
@ -34,7 +34,7 @@ class TestSpace < MiniTest::Test
|
||||
|
||||
def test_integer
|
||||
int = Parfait.object_space.get_class_by_name :Integer
|
||||
assert_equal 5, int.instance_type.method_names.get_length
|
||||
assert_equal 6, int.instance_type.method_names.get_length
|
||||
end
|
||||
|
||||
def test_classes_class
|
||||
|
52
test/risc/interpreter/test_mult.rb
Normal file
52
test/risc/interpreter/test_mult.rb
Normal file
@ -0,0 +1,52 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Risc
|
||||
class InterpreterMultTest < MiniTest::Test
|
||||
include Ticker
|
||||
|
||||
def setup
|
||||
@string_input = as_main "return #{2**31} * #{2**31}"
|
||||
super
|
||||
end
|
||||
|
||||
def test_mult
|
||||
#show_ticks # get output of what is
|
||||
check_chain [Branch, Label, LoadConstant, SlotToReg, LoadConstant,
|
||||
SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg,
|
||||
SlotToReg, SlotToReg, SlotToReg, RegToSlot, LoadConstant,
|
||||
SlotToReg, SlotToReg, SlotToReg, SlotToReg, RegToSlot,
|
||||
SlotToReg, RegToSlot, LoadConstant, RegToSlot, FunctionCall,
|
||||
Label, LoadConstant, SlotToReg, SlotToReg, RegToSlot,
|
||||
LoadConstant, SlotToReg, SlotToReg, SlotToReg, SlotToReg,
|
||||
RegToSlot, LoadConstant, SlotToReg, SlotToReg, SlotToReg,
|
||||
SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot,
|
||||
LoadConstant, SlotToReg, SlotToReg, RegToSlot, LoadConstant,
|
||||
SlotToReg, RegToSlot, SlotToReg, LoadConstant, FunctionCall,
|
||||
Label, SlotToReg, SlotToReg, SlotToReg, SlotToReg,
|
||||
SlotToReg, OperatorInstruction, LoadConstant, SlotToReg, SlotToReg,
|
||||
RegToSlot, RegToSlot, RegToSlot, SlotToReg, SlotToReg,
|
||||
RegToSlot, SlotToReg, SlotToReg, FunctionReturn, SlotToReg,
|
||||
SlotToReg, RegToSlot, SlotToReg, SlotToReg, RegToSlot,
|
||||
SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
|
||||
FunctionReturn, Transfer, Syscall, NilClass]
|
||||
assert_equal Parfait::Integer , get_return.class
|
||||
assert_equal 0 , get_return.value
|
||||
end
|
||||
def test_op
|
||||
op = ticks(62)
|
||||
assert_equal OperatorInstruction , op.class
|
||||
assert_equal :r1 , op.left.symbol
|
||||
assert_equal :r2 , op.right.symbol
|
||||
assert_equal 2**31 , @interpreter.get_register(:r2)
|
||||
assert_equal 0 , @interpreter.get_register(:r1)
|
||||
end
|
||||
def test_overflow
|
||||
ticks( 62 )
|
||||
assert @interpreter.flags[:overflow]
|
||||
end
|
||||
def test_zero
|
||||
ticks( 12 )
|
||||
assert @interpreter.flags[:zero]
|
||||
end
|
||||
end
|
||||
end
|
@ -1,40 +0,0 @@
|
||||
require_relative "../helper"
|
||||
|
||||
module Risc
|
||||
class MultTest < MiniTest::Test
|
||||
include Ticker
|
||||
include AST::Sexp
|
||||
|
||||
def setup
|
||||
@string_input = <<HERE
|
||||
class Space
|
||||
int main()
|
||||
return #{2**31} * #{2**31}
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@input = s(:statements, s(:return, s(:operator_value, :*, s(:int, 2147483648), s(:int, 2147483648))))
|
||||
super
|
||||
end
|
||||
|
||||
def pest_mult
|
||||
#show_ticks # get output of what is
|
||||
check_chain [Branch, Label, LoadConstant, SlotToReg, RegToSlot,
|
||||
LoadConstant, RegToSlot, FunctionCall, Label, LoadConstant,
|
||||
LoadConstant, OperatorInstruction, RegToSlot, LoadConstant, SlotToReg,
|
||||
RegToSlot, Label, FunctionReturn, Transfer, Syscall,
|
||||
NilClass]
|
||||
check_return 0
|
||||
end
|
||||
def pest_overflow
|
||||
ticks( 12 )
|
||||
assert @interpreter.flags[:overflow]
|
||||
end
|
||||
|
||||
def pest_zero
|
||||
ticks( 12 )
|
||||
assert @interpreter.flags[:zero]
|
||||
end
|
||||
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user