compiler/TMethodBinding.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Wed, 16 Sep 2015 05:29:43 +0100
changeset 11 6d39860d0fdb
parent 8 eec72263ed75
child 16 17a2d1d9f205
permissions -rw-r--r--
First shot on #ifTrie:ifFalse: special form

"{ Package: 'jv:tea/compiler' }"

"{ NameSpace: Smalltalk }"

TFunctionBinding subclass:#TMethodBinding
	instanceVariableNames:'mclass selector'
	classVariableNames:''
	poolDictionaries:''
	category:'Languages-Tea-Compiler-Bindings'
!


!TMethodBinding class methodsFor:'instance creation'!

class: aTClassBinding selector: aSymbol
    ^ self new initializeWithClass: aTClassBinding selector: aSymbol

    "Created: / 31-08-2015 / 12:04:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!TMethodBinding methodsFor:'accessing'!

mclass
    ^ mclass

    "Created: / 31-08-2015 / 12:14:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

receiverType
    ^ mclass type

    "Created: / 02-09-2015 / 21:30:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

selector
    ^ selector
! !

!TMethodBinding methodsFor:'converting'!

asLLVMValueInModule: aLLVMModule
    | name function |

    name := TLLVMCodeGenerator llvmFunctionNameForClass: mclass clazz selector: selector.
    function := aLLVMModule getFunctionNamed: name.
    function isNil ifTrue:[ 
        | type |

        mclass isMetaclass ifTrue:[
            type := LLVMType 
                        function:  (parameterTypes collect:[:t|t asLLVMTypeInModule: aLLVMModule ])
                        returning: (returnType asLLVMTypeInModule: aLLVMModule).                 
        ] ifFalse:[ 
            type := LLVMType
                    function:  {mclass type asLLVMTypeInModule:  aLLVMModule } ,
                               (parameterTypes collect:[:t|t asLLVMTypeInModule: aLLVMModule])
                    returning: (returnType asLLVMTypeInModule: aLLVMModule).
        ].
        function := aLLVMModule addFunctionNamed: name type: type.
        mclass isMetaclass ifFalse:[
            (function parameterAt: 1) name: 'self'.
        ]
    ].
    ^ function

    "Created: / 15-09-2015 / 07:04:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!TMethodBinding methodsFor:'initialization'!

initializeWithClass: aTClassBinding selector: aSymbol
    mclass := aTClassBinding.
    selector := aSymbol

    "Created: / 31-08-2015 / 11:20:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!TMethodBinding methodsFor:'testing'!

isMethodBinding
    ^ true
! !

!TMethodBinding class methodsFor:'documentation'!

version_HG

    ^ '$Changeset: <not expanded> $'
! !