Added standalone Tea compiler - teak
It allows for compilation of .tea files from the command line.
"
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 }"
TObjectWithProperties subclass:#TScope
instanceVariableNames:'node parent children variables'
classVariableNames:''
poolDictionaries:''
category:'Languages-Tea-Compiler-Bindings'
!
!TScope 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.
"
! !
!TScope class methodsFor:'instance creation'!
node: node
^ self node: node parent: nil.
"Created: / 25-08-2015 / 22:28:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
node: node parent: parent
^ self new initializeWithNode: node parent: parent
"Created: / 25-08-2015 / 22:24:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!TScope methodsFor:'accessing'!
children
^ children ? #()
"Modified: / 25-08-2015 / 22:28:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
node
^ node
!
parent
^ parent
!
variables
^ variables ? #()
"Modified: / 19-09-2015 / 05:56:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!TScope methodsFor:'accesssing - llvm'!
llvmAllocas
^ self propertyAt: #llvmAllocas
ifAbsent: [ parent notNil ifTrue:[ parent llvmAllocas ] ifFalse:[nil] ]
"Created: / 23-09-2015 / 21:42:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
llvmAllocas: anLLVMBasicBlock
self propertyAt: #llvmAllocas put: anLLVMBasicBlock
"Created: / 23-09-2015 / 21:40:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!TScope methodsFor:'adding & removing'!
addSubScope: aTScope
children isNil ifTrue:[
children := OrderedCollection new: 5.
].
children add: aTScope
"Created: / 19-09-2015 / 06:05:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
addVariable: aTVariableBinding
variables isNil ifTrue:[
variables := OrderedCollection new.
].
variables add: aTVariableBinding
"Created: / 25-08-2015 / 22:42:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!TScope methodsFor:'initialization'!
initializeWithNode: n parent: p
node := n.
parent := p.
parent notNil ifTrue:[
parent addSubScope: self.
].
"Created: / 25-08-2015 / 22:25:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 19-09-2015 / 06:06:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!TScope methodsFor:'lookup'!
lookupVariable: name
"Return binding for variable with given name or nil if not found"
| variable |
variables notNil ifTrue:[
variable := variables detect:[:binding | binding name = name ] ifNone:[ nil ].
].
(variable isNil and:[parent notNil]) ifTrue:[
variable := parent lookupVariable: name.
].
^ variable
"Created: / 25-08-2015 / 22:58:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 20-09-2015 / 06:11:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!TScope methodsFor:'testing'!
hasSelfArgument
^ (node isMethod and:[node binding mclass isMetaclass not])
"Created: / 23-09-2015 / 18:48:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
isBlockScope
^ node isBlock
"Created: / 02-09-2015 / 08:57:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
isMethodScope
^ node isMethod
"Created: / 02-09-2015 / 08:58:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !