fix mod4 name
really did div4
This commit is contained in:
parent
8e1efa3993
commit
3a50b7dd0e
@ -20,6 +20,9 @@ module Mom
|
|||||||
@cache_entry = cache_entry
|
@cache_entry = cache_entry
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def to_s
|
||||||
|
"ResolveMethod #{name}"
|
||||||
|
end
|
||||||
|
|
||||||
# When the method is resolved, a cache_entry is used to hold the result.
|
# When the method is resolved, a cache_entry is used to hold the result.
|
||||||
# That cache_entry (holding type and method) is checked before, and
|
# That cache_entry (holding type and method) is checked before, and
|
||||||
|
@ -44,10 +44,9 @@ module Parfait
|
|||||||
@arguments_type = arguments_type
|
@arguments_type = arguments_type
|
||||||
@frame_type = frame_type
|
@frame_type = frame_type
|
||||||
@binary = BinaryCode.new(0)
|
@binary = BinaryCode.new(0)
|
||||||
source = "_init_method"
|
|
||||||
name = "#{@for_type.name}.#{@name}"
|
name = "#{@for_type.name}.#{@name}"
|
||||||
@risc_instructions = Risc.label(source, name)
|
@risc_instructions = Risc.label(self, name)
|
||||||
@risc_instructions << Risc.label( source, "unreachable")
|
@risc_instructions << Risc.label( self, "unreachable")
|
||||||
end
|
end
|
||||||
|
|
||||||
def translate_cpu(translator)
|
def translate_cpu(translator)
|
||||||
|
@ -181,7 +181,7 @@ module Risc
|
|||||||
end
|
end
|
||||||
|
|
||||||
obj = space.get_class_by_name(:Integer)
|
obj = space.get_class_by_name(:Integer)
|
||||||
[ :putint, :mod4, :div10, :+ , :- , :*].each do |f| #mod4 is just a forward declaration
|
[ :putint, :div4, :div10, :+ , :- , :*].each do |f| #div4 is just a forward declaration
|
||||||
obj.instance_type.add_method Builtin::Integer.send(f , nil)
|
obj.instance_type.add_method Builtin::Integer.send(f , nil)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -5,9 +5,9 @@ module Risc
|
|||||||
module ClassMethods
|
module ClassMethods
|
||||||
include CompileHelper
|
include CompileHelper
|
||||||
|
|
||||||
def mod4(context)
|
def div4(context)
|
||||||
source = "mod4"
|
source = "div4"
|
||||||
compiler = compiler_for(:Integer,:mod4 ,{})
|
compiler = compiler_for(:Integer,:div4 ,{})
|
||||||
builder = compiler.builder(true, compiler.method)
|
builder = compiler.builder(true, compiler.method)
|
||||||
me = builder.add_known( :receiver )
|
me = builder.add_known( :receiver )
|
||||||
builder.reduce_int( source , me )
|
builder.reduce_int( source , me )
|
||||||
|
@ -3,28 +3,28 @@ require_relative 'helper'
|
|||||||
class TestPutiRT < MiniTest::Test
|
class TestPutiRT < MiniTest::Test
|
||||||
include ParfaitTests
|
include ParfaitTests
|
||||||
|
|
||||||
def test_mod4_2
|
def test_div4_2
|
||||||
@main = "return 2.mod4()"
|
@main = "return 2.div4()"
|
||||||
check 2 % 4
|
check 2 % 4
|
||||||
end
|
end
|
||||||
def test_mod4_3
|
def test_div4_3
|
||||||
@main = "return 3.mod4()"
|
@main = "return 3.div4()"
|
||||||
check 3 % 4
|
check 3 % 4
|
||||||
end
|
end
|
||||||
def test_mod4_4
|
def test_div4_4
|
||||||
@main = "return 4.mod4()"
|
@main = "return 4.div4()"
|
||||||
check 4 % 4
|
check 4 % 4
|
||||||
end
|
end
|
||||||
def test_mod4_5
|
def test_div4_5
|
||||||
@main = "return 5.mod4()"
|
@main = "return 5.div4()"
|
||||||
check 5 % 4
|
check 5 % 4
|
||||||
end
|
end
|
||||||
def test_mod4_12
|
def test_div4_12
|
||||||
@main = "return 12.mod4()"
|
@main = "return 12.div4()"
|
||||||
check 12 % 4
|
check 12 % 4
|
||||||
end
|
end
|
||||||
def test_mod4_10
|
def test_div4_10
|
||||||
@main = "return 10.mod4()"
|
@main = "return 10.div4()"
|
||||||
check 10 % 4
|
check 10 % 4
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ class Integer < Value
|
|||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
int mod4()
|
int div4()
|
||||||
return self & 3
|
return self & 3
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ module Risc
|
|||||||
|
|
||||||
def setup
|
def setup
|
||||||
super
|
super
|
||||||
@input = "r = 5.mod4"
|
@input = "r = 5.div4"
|
||||||
@expect = [LoadConstant, LoadConstant, SlotToReg, RegToSlot, RegToSlot,
|
@expect = [LoadConstant, LoadConstant, SlotToReg, RegToSlot, RegToSlot,
|
||||||
SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
|
SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
|
||||||
RegToSlot, SlotToReg, RegToSlot, SlotToReg, RegToSlot,
|
RegToSlot, SlotToReg, RegToSlot, SlotToReg, RegToSlot,
|
||||||
|
@ -6,7 +6,7 @@ module Risc
|
|||||||
|
|
||||||
def setup
|
def setup
|
||||||
super
|
super
|
||||||
@input = "@a.mod4"
|
@input = "@a.div4"
|
||||||
@expect = [LoadConstant, SlotToReg, SlotToReg, SlotToReg, SlotToReg,
|
@expect = [LoadConstant, SlotToReg, SlotToReg, SlotToReg, SlotToReg,
|
||||||
OperatorInstruction, IsZero, SlotToReg, SlotToReg, SlotToReg,
|
OperatorInstruction, IsZero, SlotToReg, SlotToReg, SlotToReg,
|
||||||
LoadConstant, RegToSlot, LoadConstant, LoadConstant, SlotToReg,
|
LoadConstant, RegToSlot, LoadConstant, LoadConstant, SlotToReg,
|
||||||
|
@ -6,7 +6,7 @@ module Risc
|
|||||||
|
|
||||||
def setup
|
def setup
|
||||||
super
|
super
|
||||||
@input = "5.mod4"
|
@input = "5.div4"
|
||||||
@expect = [LoadConstant, LoadConstant, SlotToReg, RegToSlot, RegToSlot,
|
@expect = [LoadConstant, LoadConstant, SlotToReg, RegToSlot, RegToSlot,
|
||||||
SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
|
SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
|
||||||
RegToSlot, SlotToReg, RegToSlot, SlotToReg, RegToSlot,
|
RegToSlot, SlotToReg, RegToSlot, SlotToReg, RegToSlot,
|
||||||
@ -32,7 +32,7 @@ module Risc
|
|||||||
def test_function_call
|
def test_function_call
|
||||||
produced = produce_body
|
produced = produce_body
|
||||||
assert_equal FunctionCall , produced.next(23).class
|
assert_equal FunctionCall , produced.next(23).class
|
||||||
assert_equal :mod4 , produced.next(23).method.name
|
assert_equal :div4 , produced.next(23).method.name
|
||||||
end
|
end
|
||||||
def test_check_continue
|
def test_check_continue
|
||||||
produced = produce_body
|
produced = produce_body
|
||||||
|
@ -7,7 +7,7 @@ module Risc
|
|||||||
|
|
||||||
def setup
|
def setup
|
||||||
super
|
super
|
||||||
@input = "5.mod4"
|
@input = "5.div4"
|
||||||
@expect = [LoadConstant, LoadConstant, SlotToReg, RegToSlot, RegToSlot,
|
@expect = [LoadConstant, LoadConstant, SlotToReg, RegToSlot, RegToSlot,
|
||||||
SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
|
SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
|
||||||
RegToSlot, SlotToReg, RegToSlot, SlotToReg, RegToSlot,
|
RegToSlot, SlotToReg, RegToSlot, SlotToReg, RegToSlot,
|
||||||
@ -22,7 +22,7 @@ module Risc
|
|||||||
def test_load_method
|
def test_load_method
|
||||||
method = @produced
|
method = @produced
|
||||||
assert_load( method, Parfait::TypedMethod ,:r1)
|
assert_load( method, Parfait::TypedMethod ,:r1)
|
||||||
assert_equal :mod4 , method.constant.name
|
assert_equal :div4 , method.constant.name
|
||||||
end
|
end
|
||||||
def test_load_space
|
def test_load_space
|
||||||
space = @produced.next(1)
|
space = @produced.next(1)
|
||||||
|
@ -6,7 +6,7 @@ module Risc
|
|||||||
|
|
||||||
def setup
|
def setup
|
||||||
super
|
super
|
||||||
@input = "return 5.mod4"
|
@input = "return 5.div4"
|
||||||
@expect = [LoadConstant, LoadConstant, SlotToReg, RegToSlot, RegToSlot,
|
@expect = [LoadConstant, LoadConstant, SlotToReg, RegToSlot, RegToSlot,
|
||||||
SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
|
SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
|
||||||
RegToSlot, SlotToReg, RegToSlot, SlotToReg, RegToSlot,
|
RegToSlot, SlotToReg, RegToSlot, SlotToReg, RegToSlot,
|
||||||
|
@ -6,7 +6,7 @@ module Risc
|
|||||||
|
|
||||||
def setup
|
def setup
|
||||||
super
|
super
|
||||||
@input = "return @a.mod4"
|
@input = "return @a.div4"
|
||||||
@expect = [LoadConstant, SlotToReg, SlotToReg, SlotToReg, OperatorInstruction,
|
@expect = [LoadConstant, SlotToReg, SlotToReg, SlotToReg, OperatorInstruction,
|
||||||
IsZero, SlotToReg, SlotToReg, LoadConstant, RegToSlot,
|
IsZero, SlotToReg, SlotToReg, LoadConstant, RegToSlot,
|
||||||
LoadConstant, LoadConstant, SlotToReg, RegToSlot, RegToSlot,
|
LoadConstant, LoadConstant, SlotToReg, RegToSlot, RegToSlot,
|
||||||
|
@ -5,7 +5,7 @@ module Risc
|
|||||||
include Ticker
|
include Ticker
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@string_input = as_main("a = 5 ; return a.mod4")
|
@string_input = as_main("a = 5 ; return a.div4")
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ module Risc
|
|||||||
include Ticker
|
include Ticker
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@string_input = as_main "return 9.mod4"
|
@string_input = as_main "return 9.div4"
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ module Vool
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_int_receiver
|
def test_int_receiver
|
||||||
sent = RubyCompiler.compile( "5.mod4")
|
sent = RubyCompiler.compile( "5.div4")
|
||||||
assert_equal Parfait::Type , sent.receiver.ct_type.class
|
assert_equal Parfait::Type , sent.receiver.ct_type.class
|
||||||
assert_equal "Integer_Type" , sent.receiver.ct_type.name
|
assert_equal "Integer_Type" , sent.receiver.ct_type.name
|
||||||
end
|
end
|
||||||
|
@ -7,7 +7,7 @@ module Vool
|
|||||||
|
|
||||||
def setup
|
def setup
|
||||||
Risc.machine.boot
|
Risc.machine.boot
|
||||||
@ins = compile_first_method( "a = 5; a.mod4")
|
@ins = compile_first_method( "a = 5; a.div4")
|
||||||
end
|
end
|
||||||
def test_check_type
|
def test_check_type
|
||||||
assert_equal NotSameCheck , @ins.next.class , @ins
|
assert_equal NotSameCheck , @ins.next.class , @ins
|
||||||
|
@ -8,13 +8,13 @@ module Vool
|
|||||||
|
|
||||||
def setup
|
def setup
|
||||||
Risc.machine.boot
|
Risc.machine.boot
|
||||||
@ins = compile_first_method( "5.mod4")
|
@ins = compile_first_method( "5.div4")
|
||||||
end
|
end
|
||||||
def receiver
|
def receiver
|
||||||
[Mom::IntegerConstant , 5]
|
[Mom::IntegerConstant , 5]
|
||||||
end
|
end
|
||||||
def test_call_has_right_method
|
def test_call_has_right_method
|
||||||
assert_equal :mod4, @ins.next(2).method.name
|
assert_equal :div4, @ins.next(2).method.name
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -8,7 +8,7 @@ module Vool
|
|||||||
|
|
||||||
def setup
|
def setup
|
||||||
Risc.machine.boot
|
Risc.machine.boot
|
||||||
@ins = compile_first_method( "5.mod4(1,2)")
|
@ins = compile_first_method( "5.div4(1,2)")
|
||||||
end
|
end
|
||||||
|
|
||||||
def receiver
|
def receiver
|
||||||
|
@ -8,7 +8,7 @@ module Vool
|
|||||||
|
|
||||||
def setup
|
def setup
|
||||||
Risc.machine.boot
|
Risc.machine.boot
|
||||||
@ins = compile_first_method( "if(5.mod4) ; @a = 6 ; else; @a = 5 ; end")
|
@ins = compile_first_method( "if(5.div4) ; @a = 6 ; else; @a = 5 ; end")
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_condition
|
def test_condition
|
||||||
@ -19,7 +19,7 @@ module Vool
|
|||||||
end
|
end
|
||||||
def test_hoisted_dynamic_call
|
def test_hoisted_dynamic_call
|
||||||
assert_equal SimpleCall , @ins.next(2).class
|
assert_equal SimpleCall , @ins.next(2).class
|
||||||
assert_equal :mod4 , @ins.next(2).method.name
|
assert_equal :div4 , @ins.next(2).method.name
|
||||||
end
|
end
|
||||||
def test_array
|
def test_array
|
||||||
check_array [MessageSetup, ArgumentTransfer, SimpleCall, SlotLoad, TruthCheck, Label ,
|
check_array [MessageSetup, ArgumentTransfer, SimpleCall, SlotLoad, TruthCheck, Label ,
|
||||||
|
@ -44,7 +44,7 @@ module Vool
|
|||||||
|
|
||||||
def setup
|
def setup
|
||||||
Risc.machine.boot
|
Risc.machine.boot
|
||||||
@ins = compile_first_method( "return 5.mod4")
|
@ins = compile_first_method( "return 5.div4")
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_return_is_last
|
def test_return_is_last
|
||||||
|
@ -8,7 +8,7 @@ module Vool
|
|||||||
|
|
||||||
def setup
|
def setup
|
||||||
Risc.machine.boot
|
Risc.machine.boot
|
||||||
@ins = compile_first_method( "while(5.mod4) ; 5.mod4 ; end")
|
@ins = compile_first_method( "while(5.div4) ; 5.div4 ; end")
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_condition_compiles_to_check
|
def test_condition_compiles_to_check
|
||||||
|
Loading…
Reference in New Issue
Block a user