compiler/TMethodBinding.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Fri, 25 Sep 2015 03:51:15 +0100
changeset 16 17a2d1d9f205
parent 11 6d39860d0fdb
permissions -rw-r--r--
Added standalone Tea compiler - teak It allows for compilation of .tea files from the command line.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16
17a2d1d9f205 Added standalone Tea compiler - teak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
     1
"
17a2d1d9f205 Added standalone Tea compiler - teak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
     2
    Copyright (C) 2015-now Jan Vrany
17a2d1d9f205 Added standalone Tea compiler - teak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
     3
17a2d1d9f205 Added standalone Tea compiler - teak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
     4
    This code is not an open-source (yet). You may use this code
17a2d1d9f205 Added standalone Tea compiler - teak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
     5
    for your own experiments and projects, given that:
17a2d1d9f205 Added standalone Tea compiler - teak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
     6
17a2d1d9f205 Added standalone Tea compiler - teak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
     7
    * all modification to the code will be sent to the
17a2d1d9f205 Added standalone Tea compiler - teak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
     8
      original author for inclusion in future releases
17a2d1d9f205 Added standalone Tea compiler - teak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
     9
    * this is not used in any commercial software
17a2d1d9f205 Added standalone Tea compiler - teak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    10
17a2d1d9f205 Added standalone Tea compiler - teak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    11
    This license is provisional and may (will) change in
17a2d1d9f205 Added standalone Tea compiler - teak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    12
    a future.
17a2d1d9f205 Added standalone Tea compiler - teak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    13
"
4
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    14
"{ Package: 'jv:tea/compiler' }"
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    15
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    16
"{ NameSpace: Smalltalk }"
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    17
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    18
TFunctionBinding subclass:#TMethodBinding
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    19
	instanceVariableNames:'mclass selector'
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    20
	classVariableNames:''
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    21
	poolDictionaries:''
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    22
	category:'Languages-Tea-Compiler-Bindings'
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    23
!
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    24
16
17a2d1d9f205 Added standalone Tea compiler - teak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    25
!TMethodBinding class methodsFor:'documentation'!
17a2d1d9f205 Added standalone Tea compiler - teak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    26
17a2d1d9f205 Added standalone Tea compiler - teak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    27
copyright
17a2d1d9f205 Added standalone Tea compiler - teak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    28
"
17a2d1d9f205 Added standalone Tea compiler - teak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    29
    Copyright (C) 2015-now Jan Vrany
17a2d1d9f205 Added standalone Tea compiler - teak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    30
17a2d1d9f205 Added standalone Tea compiler - teak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    31
    This code is not an open-source (yet). You may use this code
17a2d1d9f205 Added standalone Tea compiler - teak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    32
    for your own experiments and projects, given that:
17a2d1d9f205 Added standalone Tea compiler - teak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    33
17a2d1d9f205 Added standalone Tea compiler - teak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    34
    * all modification to the code will be sent to the
17a2d1d9f205 Added standalone Tea compiler - teak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    35
      original author for inclusion in future releases
17a2d1d9f205 Added standalone Tea compiler - teak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    36
    * this is not used in any commercial software
17a2d1d9f205 Added standalone Tea compiler - teak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    37
17a2d1d9f205 Added standalone Tea compiler - teak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    38
    This license is provisional and may (will) change in
17a2d1d9f205 Added standalone Tea compiler - teak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    39
    a future.
17a2d1d9f205 Added standalone Tea compiler - teak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    40
"
17a2d1d9f205 Added standalone Tea compiler - teak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    41
! !
7
7556e3d41d80 Make 3 + 4 working, though the code is rather messy
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
    42
4
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    43
!TMethodBinding class methodsFor:'instance creation'!
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    44
8
eec72263ed75 Introduced TEnvironment, a container object that keeps all (class) definition requiref for a compilation
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7
diff changeset
    45
class: aTClassBinding selector: aSymbol
eec72263ed75 Introduced TEnvironment, a container object that keeps all (class) definition requiref for a compilation
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7
diff changeset
    46
    ^ self new initializeWithClass: aTClassBinding selector: aSymbol
4
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    47
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    48
    "Created: / 31-08-2015 / 12:04:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    49
! !
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    50
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    51
!TMethodBinding methodsFor:'accessing'!
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    52
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    53
mclass
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    54
    ^ mclass
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    55
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    56
    "Created: / 31-08-2015 / 12:14:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    57
!
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    58
7
7556e3d41d80 Make 3 + 4 working, though the code is rather messy
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
    59
receiverType
7556e3d41d80 Make 3 + 4 working, though the code is rather messy
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
    60
    ^ mclass type
7556e3d41d80 Make 3 + 4 working, though the code is rather messy
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
    61
7556e3d41d80 Make 3 + 4 working, though the code is rather messy
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
    62
    "Created: / 02-09-2015 / 21:30:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
7556e3d41d80 Make 3 + 4 working, though the code is rather messy
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
    63
!
7556e3d41d80 Make 3 + 4 working, though the code is rather messy
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
    64
4
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    65
selector
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    66
    ^ selector
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    67
! !
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    68
11
6d39860d0fdb First shot on #ifTrie:ifFalse: special form
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
    69
!TMethodBinding methodsFor:'converting'!
6d39860d0fdb First shot on #ifTrie:ifFalse: special form
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
    70
6d39860d0fdb First shot on #ifTrie:ifFalse: special form
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
    71
asLLVMValueInModule: aLLVMModule
6d39860d0fdb First shot on #ifTrie:ifFalse: special form
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
    72
    | name function |
6d39860d0fdb First shot on #ifTrie:ifFalse: special form
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
    73
6d39860d0fdb First shot on #ifTrie:ifFalse: special form
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
    74
    name := TLLVMCodeGenerator llvmFunctionNameForClass: mclass clazz selector: selector.
6d39860d0fdb First shot on #ifTrie:ifFalse: special form
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
    75
    function := aLLVMModule getFunctionNamed: name.
6d39860d0fdb First shot on #ifTrie:ifFalse: special form
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
    76
    function isNil ifTrue:[ 
6d39860d0fdb First shot on #ifTrie:ifFalse: special form
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
    77
        | type |
6d39860d0fdb First shot on #ifTrie:ifFalse: special form
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
    78
6d39860d0fdb First shot on #ifTrie:ifFalse: special form
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
    79
        mclass isMetaclass ifTrue:[
6d39860d0fdb First shot on #ifTrie:ifFalse: special form
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
    80
            type := LLVMType 
6d39860d0fdb First shot on #ifTrie:ifFalse: special form
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
    81
                        function:  (parameterTypes collect:[:t|t asLLVMTypeInModule: aLLVMModule ])
6d39860d0fdb First shot on #ifTrie:ifFalse: special form
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
    82
                        returning: (returnType asLLVMTypeInModule: aLLVMModule).                 
6d39860d0fdb First shot on #ifTrie:ifFalse: special form
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
    83
        ] ifFalse:[ 
6d39860d0fdb First shot on #ifTrie:ifFalse: special form
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
    84
            type := LLVMType
6d39860d0fdb First shot on #ifTrie:ifFalse: special form
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
    85
                    function:  {mclass type asLLVMTypeInModule:  aLLVMModule } ,
6d39860d0fdb First shot on #ifTrie:ifFalse: special form
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
    86
                               (parameterTypes collect:[:t|t asLLVMTypeInModule: aLLVMModule])
6d39860d0fdb First shot on #ifTrie:ifFalse: special form
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
    87
                    returning: (returnType asLLVMTypeInModule: aLLVMModule).
6d39860d0fdb First shot on #ifTrie:ifFalse: special form
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
    88
        ].
6d39860d0fdb First shot on #ifTrie:ifFalse: special form
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
    89
        function := aLLVMModule addFunctionNamed: name type: type.
6d39860d0fdb First shot on #ifTrie:ifFalse: special form
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
    90
        mclass isMetaclass ifFalse:[
6d39860d0fdb First shot on #ifTrie:ifFalse: special form
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
    91
            (function parameterAt: 1) name: 'self'.
6d39860d0fdb First shot on #ifTrie:ifFalse: special form
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
    92
        ]
6d39860d0fdb First shot on #ifTrie:ifFalse: special form
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
    93
    ].
6d39860d0fdb First shot on #ifTrie:ifFalse: special form
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
    94
    ^ function
6d39860d0fdb First shot on #ifTrie:ifFalse: special form
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
    95
6d39860d0fdb First shot on #ifTrie:ifFalse: special form
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
    96
    "Created: / 15-09-2015 / 07:04:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
6d39860d0fdb First shot on #ifTrie:ifFalse: special form
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
    97
! !
6d39860d0fdb First shot on #ifTrie:ifFalse: special form
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
    98
4
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    99
!TMethodBinding methodsFor:'initialization'!
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   100
8
eec72263ed75 Introduced TEnvironment, a container object that keeps all (class) definition requiref for a compilation
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7
diff changeset
   101
initializeWithClass: aTClassBinding selector: aSymbol
eec72263ed75 Introduced TEnvironment, a container object that keeps all (class) definition requiref for a compilation
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7
diff changeset
   102
    mclass := aTClassBinding.
4
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   103
    selector := aSymbol
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   104
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   105
    "Created: / 31-08-2015 / 11:20:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   106
! !
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   107
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   108
!TMethodBinding methodsFor:'testing'!
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   109
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   110
isMethodBinding
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   111
    ^ true
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   112
! !
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   113
7
7556e3d41d80 Make 3 + 4 working, though the code is rather messy
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
   114
!TMethodBinding class methodsFor:'documentation'!
7556e3d41d80 Make 3 + 4 working, though the code is rather messy
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
   115
7556e3d41d80 Make 3 + 4 working, though the code is rather messy
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
   116
version_HG
7556e3d41d80 Make 3 + 4 working, though the code is rather messy
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
   117
7556e3d41d80 Make 3 + 4 working, though the code is rather messy
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
   118
    ^ '$Changeset: <not expanded> $'
7556e3d41d80 Make 3 + 4 working, though the code is rather messy
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
   119
! !
7556e3d41d80 Make 3 + 4 working, though the code is rather messy
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
   120