compiler/TMethodBinding.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Fri, 25 Sep 2015 21:58:10 +0100
changeset 17 ee807ff2f897
parent 16 17a2d1d9f205
permissions -rw-r--r--
Removed dependency on SUnit

"
    Copyright (C) 2015-now Jan Vrany

    This code is not an open-source (yet). You may use this code
    for your own experiments and projects, given that:

    * all modification to the code will be sent to the
      original author for inclusion in future releases
    * this is not used in any commercial software

    This license is provisional and may (will) change in
    a future.
"
"{ Package: 'jv:tea/compiler' }"

"{ NameSpace: Smalltalk }"

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

!TMethodBinding class methodsFor:'documentation'!

copyright
"
    Copyright (C) 2015-now Jan Vrany

    This code is not an open-source (yet). You may use this code
    for your own experiments and projects, given that:

    * all modification to the code will be sent to the
      original author for inclusion in future releases
    * this is not used in any commercial software

    This license is provisional and may (will) change in
    a future.
"
! !

!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> $'
! !