IRTransformTest.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Sat, 07 May 2011 13:19:45 +0000
changeset 34 4c372f8296b9
parent 26 db19d89eef60
child 37 be8c2dd09dff
permissions -rw-r--r--
IRTransformTest: test fixes (do not use Squeaks curly arrays)

"{ Package: 'cvut:stx/goodies/newcompiler' }"

TestCase subclass:#IRTransformTest
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'NewCompiler-IR-Tests'
!


!IRTransformTest methodsFor:'testing'!

testAdd
    |iRMethod aCompiledMethod|

    iRMethod := (IRBuilder new)
                numRargs:1;
                addTemps:#( #self );
                pushLiteral:1;
                returnTop;
                ir.
    (iRMethod allSequences last) last delete.
    (iRMethod allSequences last) last delete.
    (iRMethod allSequences last) add:(IRInstruction pushLiteral:2).
    (iRMethod allSequences last) add:(IRInstruction returnTop).
    aCompiledMethod := iRMethod compiledCode.
    self should:[ (aCompiledMethod valueWithReceiver:nil arguments:#()) = 2 ].
!

testAddBefore
    |iRMethod aCompiledMethod ret|

    iRMethod := (IRBuilder new)
                numRargs:1;
                addTemps:#( #self );
                pushLiteral:1;
                returnTop;
                ir.
    (iRMethod allSequences last) last delete.
    (iRMethod allSequences last) last delete.
    ret := (IRInstruction returnTop).
    (iRMethod allSequences last) add:ret.
    (iRMethod allSequences last) add:(IRInstruction pushLiteral:2) before:ret.
    aCompiledMethod := iRMethod compiledCode.
    self should:[ (aCompiledMethod valueWithReceiver:nil arguments:#()) = 2 ].
!

testAddIntructions
        
        | iRMethod aCompiledMethod |

        iRMethod := IRBuilder new
                numRargs: 1;
                addTemps: #(self);              "receiver and args declarations"
                pushLiteral: 1;                                 
                returnTop;
                ir.

        (iRMethod allSequences last) last delete.
        (iRMethod allSequences last) last delete.

        (iRMethod allSequences last)
                        addInstructions: (Array with:(IRInstruction pushLiteral: 2) with: (IRInstruction returnTop)).

        aCompiledMethod := iRMethod compiledCode.
        self should: [(aCompiledMethod valueWithReceiver: nil arguments: #() ) = 2].

    "Modified: / 30-03-2009 / 19:40:10 / Jan Vrany <vranyj1@fel.cvut.cz>"
    "Modified: / 07-05-2011 / 14:17:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

testAddIntructionsBefore
        
        | iRMethod aCompiledMethod push |

        iRMethod := IRBuilder new
                numRargs: 1;
                addTemps: #(self);              "receiver and args declarations"
                pushLiteral: 1;                                 
                returnTop;
                ir.

        push := (iRMethod allSequences last) at: (iRMethod allSequences size - 1) .

        (iRMethod allSequences last)
                        addInstructions: (Array with:(IRInstruction pushLiteral: 2) with: (IRInstruction returnTop)) before: push.

        aCompiledMethod := iRMethod compiledCode.
        self should: [(aCompiledMethod valueWithReceiver: nil arguments: #() ) = 2].

    "Modified: / 30-03-2009 / 19:40:21 / Jan Vrany <vranyj1@fel.cvut.cz>"
    "Modified: / 07-05-2011 / 14:18:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

testAddIntructionsBeforeFromLList
    |iRMethod aCompiledMethod push llist col|

    iRMethod := (IRBuilder new)
                numRargs:1;
                addTemps:#( #self );
                pushLiteral:1;
                returnTop;
                ir.
    push := (iRMethod allSequences last) at:(iRMethod allSequences size - 1).
    llist := LinkedList new.
    llist add:(IRInstruction pushLiteral:2).
    llist add:(IRInstruction returnTop).
    col := llist asOrderedCollection.
    (iRMethod allSequences last) addInstructions:col before:push.
    aCompiledMethod := iRMethod compiledCode.
    self should:[ (aCompiledMethod valueWithReceiver:nil arguments:#()) = 2 ].
!

testDelete
    |iRMethod aCompiledMethod|

    iRMethod := (IRBuilder new)
                numRargs:1;
                addTemps:#( #self );
                pushLiteral:1;
                pushLiteral:2;
                returnTop;
                ir.
    ((iRMethod allSequences last) 
        detect:[:each | each isConstant:[:c | c == 2 ] ]) delete.
    aCompiledMethod := iRMethod compiledCode.
    self should:[ (aCompiledMethod valueWithReceiver:nil arguments:#()) = 1 ].
!

testReplace
    |iRMethod aCompiledMethod|

    iRMethod := (IRBuilder new)
                numRargs:1;
                addTemps:#( #self );
                pushLiteral:1;
                returnTop;
                ir.
    (iRMethod allSequences last at:1) 
        replaceWith:(IRInstruction pushLiteral:2).
    aCompiledMethod := iRMethod compiledCode.
    self should:[ (aCompiledMethod valueWithReceiver:nil arguments:#()) = 2 ].
!

testReplaceInstr
        
        | iRMethod aCompiledMethod |

        iRMethod := IRBuilder new
                numRargs: 1;
                addTemps: #(self);              "receiver and args declarations"
                pushLiteral: 1;                                 
                returnTop;
                ir.
        
        (iRMethod allSequences last at: 1) 
                        replaceWithInstructions: {(IRInstruction pushLiteral: 2)}.

        aCompiledMethod := iRMethod compiledCode.
        self should: [(aCompiledMethod valueWithReceiver: nil arguments: #() ) = 2].

    "Modified: / 30-03-2009 / 19:40:30 / Jan Vrany <vranyj1@fel.cvut.cz>"
! !

!IRTransformTest class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/cvut/stx/goodies/newcompiler/IRTransformTest.st,v 1.3 2009/10/08 11:56:52 fm Exp $'
!

version_CVS
    ^ '$Header: /cvs/stx/cvut/stx/goodies/newcompiler/IRTransformTest.st,v 1.3 2009/10/08 11:56:52 fm Exp $'
!

version_SVN
    ^ '$Id$'
! !