compiler/TSemanticAnalysisPass.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Mon, 31 Aug 2015 13:53:40 +0100
changeset 4 3d80069ea3e2
parent 3 compiler/TSemanticAnalyzer.st@97ee341d3e9f
permissions -rw-r--r--
More work on basic infrastructure - types, bindings & compilation. At this point it actually can compile a simple method returning an integer value. However, full of hacks here and there and full of #notYetImplemented.

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

"{ NameSpace: Smalltalk }"

TCompilerPass subclass:#TSemanticAnalysisPass
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'Languages-Tea-Compiler'
!

!TSemanticAnalysisPass 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:]

"
! !

!TSemanticAnalysisPass methodsFor:'visiting'!

visitArgument: anRBVariableNode
    | binding |

    anRBVariableNode parent isSequence ifTrue:[ 
        binding := TLocalBinding type:anRBVariableNode typeSpec asType
                         name:anRBVariableNode name.
    ] ifFalse:[ 
        binding := TArgumentBinding type:anRBVariableNode typeSpec asType
                         name:anRBVariableNode name.
    ].
    anRBVariableNode parent scope addVariable: binding.
    super visitArgument: anRBVariableNode.

    "Created: / 25-08-2015 / 22:51:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!TSemanticAnalysisPass methodsFor:'visitor-double dispatching'!

acceptBlockNode: aBlockNode 
    aBlockNode scope: (aBlockNode parent scope subScope: aBlockNode).
    super acceptBlockNode: aBlockNode

    "Created: / 25-08-2015 / 22:30:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

acceptClassDefinition: aTClassDefinition
    aTClassDefinition binding: (TClassBinding name: aTClassDefinition name).
    super acceptClassDefinition: aTClassDefinition

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

acceptLiteralNode: aRBLiteralNode
    aRBLiteralNode binding: (TConstantBinding value: aRBLiteralNode value).
    super acceptLiteralNode: aRBLiteralNode

    "Created: / 25-08-2015 / 23:17:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

acceptMetaclassDefinition: aTClassDefinition
    aTClassDefinition binding: (TClassBinding name: aTClassDefinition name).
    super acceptMetaclassDefinition: aTClassDefinition

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

acceptMethodNode: aMethodNode 
    aMethodNode binding: (TMethodBinding class: currentClass binding selector: aMethodNode selector).
    aMethodNode scope: (TScope node: aMethodNode).
    super acceptMethodNode: aMethodNode

    "Created: / 25-08-2015 / 22:29:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 31-08-2015 / 11:47:44 / 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>"
! !

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