Make 3 + 4 working, though the code is rather messy
...and needs a lot of cleanup. There are no checks for error cases,
no debug info, etc...
"{ Package: 'jv:tea/compiler' }"
"{ NameSpace: Smalltalk }"
TCompilerPass subclass:#TSemanticAnalyser
instanceVariableNames:''
classVariableNames:''
poolDictionaries:''
category:'Languages-Tea-Compiler'
!
!TSemanticAnalyser class methodsFor:'documentation'!
documentation
"
This pass analyzes the tree, creates scopes and
initializes variable bindings.
[author:]
Jan Vrany <jan.vrany@fit.cvut.cz>
[instance variables:]
[class variables:]
[see also:]
"
! !
!TSemanticAnalyser methodsFor:'visitor-double dispatching'!
acceptBlockNode: aBlockNode
aBlockNode scope: (currentScope subScope: aBlockNode).
super acceptBlockNode: aBlockNode
"Created: / 25-08-2015 / 22:30:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 02-09-2015 / 07:20:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
acceptLiteralNode: aRBLiteralNode
super acceptLiteralNode: aRBLiteralNode.
aRBLiteralNode binding: (TConstantBinding value: aRBLiteralNode value).
"Created: / 25-08-2015 / 23:17:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 02-09-2015 / 10:34:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
acceptMethodNode: aMethodNode
| binding scope bindingSelf |
binding := TMethodBinding class: currentClass binding selector: aMethodNode selector.
scope := TScope node: aMethodNode.
bindingSelf := TArgumentBinding name:'self'.
bindingSelf index: self.
scope addVariable: bindingSelf.
aMethodNode binding: binding.
aMethodNode scope: scope.
super acceptMethodNode: aMethodNode
"Created: / 25-08-2015 / 22:29:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 02-09-2015 / 08:44:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
acceptVariableNode: aVariableNode
aVariableNode binding: (aVariableNode scope lookupVariable: aVariableNode name).
super acceptVariableNode: aVariableNode
"Created: / 25-08-2015 / 23:00:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
visitArgument: anRBVariableNode
| binding |
anRBVariableNode parent isSequence ifTrue:[
binding := TLocalBinding name:anRBVariableNode name.
] ifFalse:[
binding := TArgumentBinding name:anRBVariableNode name.
binding index: (anRBVariableNode parent arguments indexOf: anRBVariableNode)
+ (currentScope isMethodScope ifTrue:[1] ifFalse:[0])
].
anRBVariableNode parent scope addVariable: binding.
super visitArgument: anRBVariableNode.
"Created: / 25-08-2015 / 22:51:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 02-09-2015 / 08:58:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!TSemanticAnalyser class methodsFor:'documentation'!
version
^ 'Path: jv/tea/compiler/TSemanticAnalyzer.st, Version: 1.0, User: jv, Time: 2015-08-31T13:47:58.729+01'
!
version_HG
^ 'Path: jv/tea/compiler/TSemanticAnalyzer.st, Version: 1.0, User: jv, Time: 2015-08-31T13:47:58.729+01'
! !