compiler/TSemanticAnalyser.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Mon, 14 Sep 2015 11:19:10 +0100
changeset 8 eec72263ed75
parent 7 7556e3d41d80
child 9 569bf5707c7e
permissions -rw-r--r--
Introduced TEnvironment, a container object that keeps all (class) definition requiref for a compilation
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3
97ee341d3e9f Initial shot of scopes & bindings and type checking. Must be rethought.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     1
"{ Package: 'jv:tea/compiler' }"
97ee341d3e9f Initial shot of scopes & bindings and type checking. Must be rethought.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     2
97ee341d3e9f Initial shot of scopes & bindings and type checking. Must be rethought.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     3
"{ NameSpace: Smalltalk }"
97ee341d3e9f Initial shot of scopes & bindings and type checking. Must be rethought.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     4
6
0c806a7f1888 Initial support for inline assembly
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
     5
TCompilerPass subclass:#TSemanticAnalyser
3
97ee341d3e9f Initial shot of scopes & bindings and type checking. Must be rethought.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     6
	instanceVariableNames:''
97ee341d3e9f Initial shot of scopes & bindings and type checking. Must be rethought.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     7
	classVariableNames:''
97ee341d3e9f Initial shot of scopes & bindings and type checking. Must be rethought.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     8
	poolDictionaries:''
4
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
     9
	category:'Languages-Tea-Compiler'
3
97ee341d3e9f Initial shot of scopes & bindings and type checking. Must be rethought.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    10
!
97ee341d3e9f Initial shot of scopes & bindings and type checking. Must be rethought.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    11
6
0c806a7f1888 Initial support for inline assembly
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
    12
!TSemanticAnalyser class methodsFor:'documentation'!
3
97ee341d3e9f Initial shot of scopes & bindings and type checking. Must be rethought.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    13
97ee341d3e9f Initial shot of scopes & bindings and type checking. Must be rethought.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    14
documentation
97ee341d3e9f Initial shot of scopes & bindings and type checking. Must be rethought.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    15
"
97ee341d3e9f Initial shot of scopes & bindings and type checking. Must be rethought.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    16
    This pass analyzes the tree, creates scopes and
97ee341d3e9f Initial shot of scopes & bindings and type checking. Must be rethought.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    17
    initializes variable bindings.
97ee341d3e9f Initial shot of scopes & bindings and type checking. Must be rethought.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    18
97ee341d3e9f Initial shot of scopes & bindings and type checking. Must be rethought.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    19
    [author:]
97ee341d3e9f Initial shot of scopes & bindings and type checking. Must be rethought.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    20
        Jan Vrany <jan.vrany@fit.cvut.cz>
97ee341d3e9f Initial shot of scopes & bindings and type checking. Must be rethought.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    21
97ee341d3e9f Initial shot of scopes & bindings and type checking. Must be rethought.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    22
    [instance variables:]
97ee341d3e9f Initial shot of scopes & bindings and type checking. Must be rethought.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    23
97ee341d3e9f Initial shot of scopes & bindings and type checking. Must be rethought.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    24
    [class variables:]
97ee341d3e9f Initial shot of scopes & bindings and type checking. Must be rethought.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    25
97ee341d3e9f Initial shot of scopes & bindings and type checking. Must be rethought.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    26
    [see also:]
97ee341d3e9f Initial shot of scopes & bindings and type checking. Must be rethought.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    27
97ee341d3e9f Initial shot of scopes & bindings and type checking. Must be rethought.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    28
"
97ee341d3e9f Initial shot of scopes & bindings and type checking. Must be rethought.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    29
! !
97ee341d3e9f Initial shot of scopes & bindings and type checking. Must be rethought.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    30
6
0c806a7f1888 Initial support for inline assembly
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
    31
!TSemanticAnalyser methodsFor:'visitor-double dispatching'!
3
97ee341d3e9f Initial shot of scopes & bindings and type checking. Must be rethought.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    32
6
0c806a7f1888 Initial support for inline assembly
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
    33
acceptBlockNode: aBlockNode
0c806a7f1888 Initial support for inline assembly
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
    34
    aBlockNode scope: (currentScope subScope: aBlockNode).
3
97ee341d3e9f Initial shot of scopes & bindings and type checking. Must be rethought.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    35
    super acceptBlockNode: aBlockNode
97ee341d3e9f Initial shot of scopes & bindings and type checking. Must be rethought.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    36
97ee341d3e9f Initial shot of scopes & bindings and type checking. Must be rethought.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    37
    "Created: / 25-08-2015 / 22:30:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
6
0c806a7f1888 Initial support for inline assembly
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
    38
    "Modified: / 02-09-2015 / 07:20:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
3
97ee341d3e9f Initial shot of scopes & bindings and type checking. Must be rethought.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    39
!
97ee341d3e9f Initial shot of scopes & bindings and type checking. Must be rethought.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    40
97ee341d3e9f Initial shot of scopes & bindings and type checking. Must be rethought.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    41
acceptLiteralNode: aRBLiteralNode
7
7556e3d41d80 Make 3 + 4 working, though the code is rather messy
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6
diff changeset
    42
    super acceptLiteralNode: aRBLiteralNode.
3
97ee341d3e9f Initial shot of scopes & bindings and type checking. Must be rethought.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    43
    aRBLiteralNode binding: (TConstantBinding value: aRBLiteralNode value).
97ee341d3e9f Initial shot of scopes & bindings and type checking. Must be rethought.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    44
97ee341d3e9f Initial shot of scopes & bindings and type checking. Must be rethought.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    45
    "Created: / 25-08-2015 / 23:17:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
7
7556e3d41d80 Make 3 + 4 working, though the code is rather messy
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6
diff changeset
    46
    "Modified: / 02-09-2015 / 10:34:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
4
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
    47
!
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
    48
6
0c806a7f1888 Initial support for inline assembly
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
    49
acceptMethodNode: aMethodNode
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
    50
    | scope bindingSelf |
6
0c806a7f1888 Initial support for inline assembly
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
    51
0c806a7f1888 Initial support for inline assembly
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
    52
    scope   := TScope node: aMethodNode.
0c806a7f1888 Initial support for inline assembly
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
    53
    bindingSelf := TArgumentBinding name:'self'.
0c806a7f1888 Initial support for inline assembly
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
    54
    bindingSelf index: self.
0c806a7f1888 Initial support for inline assembly
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
    55
    scope addVariable: bindingSelf.
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
    56
6
0c806a7f1888 Initial support for inline assembly
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
    57
    aMethodNode scope: scope.
0c806a7f1888 Initial support for inline assembly
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
    58
3
97ee341d3e9f Initial shot of scopes & bindings and type checking. Must be rethought.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    59
    super acceptMethodNode: aMethodNode
97ee341d3e9f Initial shot of scopes & bindings and type checking. Must be rethought.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    60
97ee341d3e9f Initial shot of scopes & bindings and type checking. Must be rethought.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    61
    "Created: / 25-08-2015 / 22:29:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
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
    62
    "Modified: / 13-09-2015 / 09:30:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
3
97ee341d3e9f Initial shot of scopes & bindings and type checking. Must be rethought.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    63
!
97ee341d3e9f Initial shot of scopes & bindings and type checking. Must be rethought.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    64
97ee341d3e9f Initial shot of scopes & bindings and type checking. Must be rethought.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    65
acceptVariableNode: aVariableNode
97ee341d3e9f Initial shot of scopes & bindings and type checking. Must be rethought.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    66
    aVariableNode binding: (aVariableNode scope lookupVariable: aVariableNode name).
97ee341d3e9f Initial shot of scopes & bindings and type checking. Must be rethought.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    67
    super acceptVariableNode: aVariableNode
97ee341d3e9f Initial shot of scopes & bindings and type checking. Must be rethought.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    68
97ee341d3e9f Initial shot of scopes & bindings and type checking. Must be rethought.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    69
    "Created: / 25-08-2015 / 23:00:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
6
0c806a7f1888 Initial support for inline assembly
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
    70
!
0c806a7f1888 Initial support for inline assembly
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
    71
0c806a7f1888 Initial support for inline assembly
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
    72
visitArgument: anRBVariableNode
0c806a7f1888 Initial support for inline assembly
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
    73
    | binding |
0c806a7f1888 Initial support for inline assembly
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
    74
0c806a7f1888 Initial support for inline assembly
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
    75
    anRBVariableNode parent isSequence ifTrue:[ 
0c806a7f1888 Initial support for inline assembly
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
    76
        binding := TLocalBinding name:anRBVariableNode name.
0c806a7f1888 Initial support for inline assembly
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
    77
    ] ifFalse:[ 
0c806a7f1888 Initial support for inline assembly
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
    78
        binding := TArgumentBinding name:anRBVariableNode name.
0c806a7f1888 Initial support for inline assembly
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
    79
        binding index: (anRBVariableNode parent arguments indexOf: anRBVariableNode)                                
0c806a7f1888 Initial support for inline assembly
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
    80
                       + (currentScope isMethodScope ifTrue:[1] ifFalse:[0])     
0c806a7f1888 Initial support for inline assembly
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
    81
    ].
0c806a7f1888 Initial support for inline assembly
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
    82
    anRBVariableNode parent scope addVariable: binding.
0c806a7f1888 Initial support for inline assembly
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
    83
    super visitArgument: anRBVariableNode.
0c806a7f1888 Initial support for inline assembly
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
    84
0c806a7f1888 Initial support for inline assembly
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
    85
    "Created: / 25-08-2015 / 22:51:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
0c806a7f1888 Initial support for inline assembly
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
    86
    "Modified: / 02-09-2015 / 08:58:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
3
97ee341d3e9f Initial shot of scopes & bindings and type checking. Must be rethought.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    87
! !
97ee341d3e9f Initial shot of scopes & bindings and type checking. Must be rethought.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    88
6
0c806a7f1888 Initial support for inline assembly
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
    89
!TSemanticAnalyser class methodsFor:'documentation'!
4
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
    90
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
    91
version
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
    92
    ^ 'Path: jv/tea/compiler/TSemanticAnalyzer.st, Version: 1.0, User: jv, Time: 2015-08-31T13:47:58.729+01'
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
    93
!
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
    94
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
    95
version_HG
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
    96
    ^ 'Path: jv/tea/compiler/TSemanticAnalyzer.st, Version: 1.0, User: jv, Time: 2015-08-31T13:47:58.729+01'
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
    97
! !
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
    98