c1/DragonFly__C1CompilerTests.st
changeset 18 81ed8ce0852f
parent 17 54798ae989cc
child 26 8eb6716029aa
equal deleted inserted replaced
17:54798ae989cc 18:81ed8ce0852f
     3 "{ NameSpace: DragonFly }"
     3 "{ NameSpace: DragonFly }"
     4 
     4 
     5 TestCase subclass:#C1CompilerTests
     5 TestCase subclass:#C1CompilerTests
     6 	instanceVariableNames:''
     6 	instanceVariableNames:''
     7 	classVariableNames:''
     7 	classVariableNames:''
     8 	poolDictionaries:'DragonFly::C1LLVMMTypes LLVMIntPredicate VMData VMOffsets'
     8 	poolDictionaries:'DragonFly::C1LLVMTypes LLVMIntPredicate VMData VMOffsets'
     9 	category:'DragonFly-C1-Tests'
     9 	category:'DragonFly-C1-Tests'
    10 !
    10 !
    11 
    11 
    12 !C1CompilerTests methodsFor:'tests'!
    12 !C1CompilerTests methodsFor:'tests'!
    13 
       
    14 test_fetchClassOf
       
    15     | compiler module function asm jit test |
       
    16 
       
    17     compiler := C1Compiler new.
       
    18     module := LLVMModule newWithName: testSelector.
       
    19     function := module addFunctionNamed: 'test'
       
    20                                    type: (LLVMType function: { TyOBJ } returning: TyOBJ).
       
    21     asm := function builder.
       
    22     compiler 
       
    23         instVarNamed: #module put: module;
       
    24         instVarNamed: #function put: function;
       
    25         instVarNamed: #asm put: asm.
       
    26 
       
    27     asm ret: (compiler fetchClassOf: (function parameterAt: 1)).
       
    28 
       
    29     jit := LLVMExecutionEngine newForModule: module.  
       
    30     test := jit externalOfFunction: function. 
       
    31 
       
    32     self assert: (test callOWith: 1) == SmallInteger.
       
    33     self assert: (test callOWith: self) == self class.
       
    34     self assert: (test callOWith: 1.0) == 1.0 class.
       
    35 
       
    36     "Created: / 12-02-2016 / 12:27:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    37 !
       
    38 
       
    39 test_fetchClassSmallInteger
       
    40     | compiler module function asm jit test |
       
    41 
       
    42     compiler := C1Compiler new.
       
    43     module := LLVMModule newWithName: testSelector.
       
    44     function := module addFunctionNamed: 'test'
       
    45                                    type: (LLVMType function: { } returning: TyOBJ).
       
    46     asm := function builder.
       
    47     compiler 
       
    48         instVarNamed: #module put: module;
       
    49         instVarNamed: #function put: function;
       
    50         instVarNamed: #asm put: asm.
       
    51 
       
    52     asm ret: (compiler fetchClassSmallInteger).
       
    53 
       
    54     jit := LLVMExecutionEngine newForModule: module.  
       
    55     test := jit externalOfFunction: function. 
       
    56 
       
    57     self assert: (test callO) == SmallInteger.
       
    58 
       
    59     "Created: / 12-02-2016 / 12:26:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    60 !
       
    61 
    13 
    62 test_isSmallIntegerObject
    14 test_isSmallIntegerObject
    63     | compiler module function asm jit test |
    15     | compiler module function asm jit test |
    64 
    16 
    65     compiler := C1Compiler new.
    17     compiler := C1Compiler new.
    79 
    31 
    80     self assert: (test callWith: 1) == 1.
    32     self assert: (test callWith: 1) == 1.
    81     self assert: (test callWith: self) == 0.
    33     self assert: (test callWith: self) == 0.
    82 
    34 
    83     "Created: / 12-02-2016 / 12:17:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    35     "Created: / 12-02-2016 / 12:17:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    36 !
       
    37 
       
    38 test_loadClassOf
       
    39     | compiler  module  function  asm  jit  test |
       
    40 
       
    41     compiler := C1Compiler new.
       
    42     module := LLVMModule newWithName:testSelector.
       
    43     function := module addFunctionNamed:'test'
       
    44             type:(LLVMType function:{ TyOBJ } returning:TyOBJ).
       
    45     asm := function builder.
       
    46     compiler
       
    47         instVarNamed:#module put:module;
       
    48         instVarNamed:#function put:function;
       
    49         instVarNamed:#asm put:asm.
       
    50     asm ret:(compiler loadClassOf: compiler loadReceiver).
       
    51     jit := LLVMExecutionEngine newForModule:module.
       
    52     test := jit externalOfFunction:function.
       
    53     self assert:(test callOWith:1) == SmallInteger.
       
    54     self assert:(test callOWith:self) == self class.
       
    55     self assert:(test callOWith:1.0) == 1.0 class.
       
    56 
       
    57     "Created: / 12-02-2016 / 12:27:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    58     "Modified: / 20-04-2016 / 22:23:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    59 !
       
    60 
       
    61 test_loadClassSmallInteger
       
    62     | compiler  module  function  asm  jit  test |
       
    63 
       
    64     compiler := C1Compiler new.
       
    65     module := LLVMModule newWithName:testSelector.
       
    66     function := module addFunctionNamed:'test'
       
    67             type:(LLVMType function:{} returning:TyOBJ).
       
    68     asm := function builder.
       
    69     compiler
       
    70         instVarNamed:#module put:module;
       
    71         instVarNamed:#function put:function;
       
    72         instVarNamed:#asm put:asm.
       
    73     asm ret:(compiler loadClassSmallInteger).
       
    74     jit := LLVMExecutionEngine newForModule:module.
       
    75     test := jit externalOfFunction:function.
       
    76     self assert:(test callO) == SmallInteger.
       
    77 
       
    78     "Created: / 12-02-2016 / 12:26:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    79     "Modified: / 20-04-2016 / 22:20:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    84 ! !
    80 ! !
    85 
    81