compiler/TCompilerTests.st
changeset 9 569bf5707c7e
parent 8 eec72263ed75
child 10 2b9beeac547e
equal deleted inserted replaced
8:eec72263ed75 9:569bf5707c7e
     1 "{ Package: 'jv:tea/compiler' }"
       
     2 
       
     3 "{ NameSpace: Smalltalk }"
       
     4 
       
     5 TestCase subclass:#TCompilerTests
       
     6 	instanceVariableNames:''
       
     7 	classVariableNames:''
       
     8 	poolDictionaries:''
       
     9 	category:'Languages-Tea-Compiler-Tests'
       
    10 !
       
    11 
       
    12 !TCompilerTests methodsFor:'tests'!
       
    13 
       
    14 test_01
       
    15     | class method compiler |
       
    16 
       
    17     class := TClassDefinition newClass.
       
    18     class name: 'tSmallInteger'.
       
    19 
       
    20     method := TMethodDefinition class: class theMetaclass.
       
    21     method source: 'one <^ tSmallInteger> ^ 1'.
       
    22     class addMethod: method.
       
    23 
       
    24     compiler := TCompiler new.
       
    25     compiler compile: class in: nil.
       
    26     self halt.
       
    27     "
       
    28     compiler context module
       
    29     "
       
    30 
       
    31     "Created: / 29-08-2015 / 21:15:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    32     "Modified: / 01-09-2015 / 21:55:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    33 !
       
    34 
       
    35 test_02
       
    36     | class method compiler |
       
    37 
       
    38     class := TClassDefinition newClass.
       
    39     class name: 'tSmallInteger'.
       
    40 
       
    41     method := TMethodDefinition class: class.
       
    42     method source: '+ another <tSmallInteger> <^ tSmallInteger> 
       
    43         %[:asm | 
       
    44             asm ret: (asm add: self _: another)
       
    45         %].
       
    46         ^ self + another
       
    47     '.
       
    48     class addMethod: method.
       
    49 
       
    50     compiler := TCompiler new.
       
    51     compiler compile: class in: nil.
       
    52     self halt.
       
    53     "
       
    54     compiler context module
       
    55     "
       
    56 
       
    57     "Created: / 02-09-2015 / 07:00:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    58 !
       
    59 
       
    60 test_three_plus_four
       
    61     | environment unit compiler|
       
    62 
       
    63     environment := TNamespaceDefinition new.
       
    64     unit := TSourceReader read:'
       
    65 nil subclass: #tSmallInteger
       
    66     category: ''tKernel''
       
    67 !!
       
    68 !!tSmallInteger methodsFor:''arithmetic''!!
       
    69 + another <tSmallInteger> <^ tSmallInteger> 
       
    70     %[:asm | 
       
    71         asm ret: (asm add: self _: another)
       
    72     %].
       
    73     "Following code is actually used only in hosted environment"
       
    74     ^ self + another
       
    75 !! !!
       
    76 
       
    77 !!tSmallInteger methodsFor:''test''!!
       
    78 threePlusFour <^ tSmallInteger> 
       
    79         ^ 3 + 4
       
    80 
       
    81 !! !!
       
    82     '.
       
    83 
       
    84     compiler := TCompiler new.
       
    85     compiler compile: unit in: environment.
       
    86     self halt.
       
    87     "
       
    88     compiler context module
       
    89     "
       
    90 
       
    91     "Created: / 02-09-2015 / 10:25:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    92     "Modified: / 14-09-2015 / 11:08:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    93 ! !
       
    94