JavaScriptInnerFunctionNode.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Tue, 24 Sep 2013 23:18:24 +0200
branchinitialV
changeset 1180 01c6be61f29c
parent 652 e55b2faa8385
child 848 239f8d260f0e
permissions -rw-r--r--
checkin from stx browser
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
155
8941ab2fe811 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 133
diff changeset
     1
"
8941ab2fe811 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 133
diff changeset
     2
 COPYRIGHT (c) 2005 by eXept Software AG
8941ab2fe811 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 133
diff changeset
     3
              All Rights Reserved
8941ab2fe811 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 133
diff changeset
     4
8941ab2fe811 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 133
diff changeset
     5
 This software is furnished under a license and may be used
8941ab2fe811 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 133
diff changeset
     6
 only in accordance with the terms of that license and with the
8941ab2fe811 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 133
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
8941ab2fe811 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 133
diff changeset
     8
 be provided or otherwise made available to, or used by, any
8941ab2fe811 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 133
diff changeset
     9
 other person.  No title to or ownership of the software is
8941ab2fe811 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 133
diff changeset
    10
 hereby transferred.
8941ab2fe811 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 133
diff changeset
    11
"
123
22e2dd938ccd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
"{ Package: 'stx:libjavascript' }"
22e2dd938ccd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
22e2dd938ccd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
JavaScriptFunctionNode subclass:#JavaScriptInnerFunctionNode
133
097c71ec28c9 inner function calling
Claus Gittinger <cg@exept.de>
parents: 131
diff changeset
    15
	instanceVariableNames:'indexOfFirstTemp'
123
22e2dd938ccd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
	classVariableNames:''
22e2dd938ccd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
	poolDictionaries:''
22e2dd938ccd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
	category:'Languages-JavaScript-Compiling & Parsing'
22e2dd938ccd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
!
22e2dd938ccd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
155
8941ab2fe811 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 133
diff changeset
    21
!JavaScriptInnerFunctionNode class methodsFor:'documentation'!
8941ab2fe811 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 133
diff changeset
    22
8941ab2fe811 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 133
diff changeset
    23
copyright
8941ab2fe811 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 133
diff changeset
    24
"
8941ab2fe811 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 133
diff changeset
    25
 COPYRIGHT (c) 2005 by eXept Software AG
8941ab2fe811 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 133
diff changeset
    26
              All Rights Reserved
8941ab2fe811 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 133
diff changeset
    27
8941ab2fe811 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 133
diff changeset
    28
 This software is furnished under a license and may be used
8941ab2fe811 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 133
diff changeset
    29
 only in accordance with the terms of that license and with the
8941ab2fe811 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 133
diff changeset
    30
 inclusion of the above copyright notice.   This software may not
8941ab2fe811 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 133
diff changeset
    31
 be provided or otherwise made available to, or used by, any
8941ab2fe811 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 133
diff changeset
    32
 other person.  No title to or ownership of the software is
8941ab2fe811 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 133
diff changeset
    33
 hereby transferred.
8941ab2fe811 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 133
diff changeset
    34
"
8941ab2fe811 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 133
diff changeset
    35
! !
123
22e2dd938ccd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
22e2dd938ccd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
!JavaScriptInnerFunctionNode methodsFor:'accessing'!
22e2dd938ccd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
22e2dd938ccd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
blockArgAccessed:aBoolean
22e2dd938ccd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
!
22e2dd938ccd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
133
097c71ec28c9 inner function calling
Claus Gittinger <cg@exept.de>
parents: 131
diff changeset
    42
home:anEnvironment
097c71ec28c9 inner function calling
Claus Gittinger <cg@exept.de>
parents: 131
diff changeset
    43
    environment := anEnvironment
097c71ec28c9 inner function calling
Claus Gittinger <cg@exept.de>
parents: 131
diff changeset
    44
!
097c71ec28c9 inner function calling
Claus Gittinger <cg@exept.de>
parents: 131
diff changeset
    45
097c71ec28c9 inner function calling
Claus Gittinger <cg@exept.de>
parents: 131
diff changeset
    46
indexOfFirstTemp
596
0efa73ee44b0 JavaScript
Claus Gittinger <cg@exept.de>
parents: 465
diff changeset
    47
    indexOfFirstTemp isNil ifTrue:[ ^ self numVars ].
133
097c71ec28c9 inner function calling
Claus Gittinger <cg@exept.de>
parents: 131
diff changeset
    48
    ^ indexOfFirstTemp
097c71ec28c9 inner function calling
Claus Gittinger <cg@exept.de>
parents: 131
diff changeset
    49
!
097c71ec28c9 inner function calling
Claus Gittinger <cg@exept.de>
parents: 131
diff changeset
    50
097c71ec28c9 inner function calling
Claus Gittinger <cg@exept.de>
parents: 131
diff changeset
    51
indexOfFirstTemp:index
097c71ec28c9 inner function calling
Claus Gittinger <cg@exept.de>
parents: 131
diff changeset
    52
    indexOfFirstTemp := index
123
22e2dd938ccd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
! !
22e2dd938ccd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
22e2dd938ccd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
!JavaScriptInnerFunctionNode methodsFor:'code generation'!
22e2dd938ccd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
22e2dd938ccd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
codeOn:aStream inBlock:b for:aCompiler
131
bb82bf09b928 oops - return is a local return
Claus Gittinger <cg@exept.de>
parents: 123
diff changeset
    58
    "this generates a block for the inner function;
bb82bf09b928 oops - return is a local return
Claus Gittinger <cg@exept.de>
parents: 123
diff changeset
    59
     Difference from block:
bb82bf09b928 oops - return is a local return
Claus Gittinger <cg@exept.de>
parents: 123
diff changeset
    60
        return is a local return;
bb82bf09b928 oops - return is a local return
Claus Gittinger <cg@exept.de>
parents: 123
diff changeset
    61
        if return is missing, retval is nil"
123
22e2dd938ccd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
22e2dd938ccd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
    |pos thisStatement nextStatement lastStatement code
22e2dd938ccd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
     maxNumTemp|
22e2dd938ccd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
22e2dd938ccd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
    maxNumTemp := 10.
22e2dd938ccd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
637
bfb2c2642b7b class: JavaScriptInnerFunctionNode
Stefan Vogel <sv@exept.de>
parents: 596
diff changeset
    68
    pos := aStream position + 1.
123
22e2dd938ccd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
22e2dd938ccd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
    aStream nextPut:#makeBlock.                                 "+0"
22e2dd938ccd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
    aStream nextPut:0.                                          "+1"
596
0efa73ee44b0 JavaScript
Claus Gittinger <cg@exept.de>
parents: 465
diff changeset
    72
    aStream nextPut:(self numVars + maxNumTemp).                 "+2"
123
22e2dd938ccd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    73
    aStream nextPut:(arguments size).                           "+3"
22e2dd938ccd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    74
596
0efa73ee44b0 JavaScript
Claus Gittinger <cg@exept.de>
parents: 465
diff changeset
    75
    self codeVariableSetupOn:aStream for:self.
0efa73ee44b0 JavaScript
Claus Gittinger <cg@exept.de>
parents: 465
diff changeset
    76
123
22e2dd938ccd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    77
    statements isEmptyOrNil ifTrue:[
22e2dd938ccd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
        aStream nextPut:#retNil.
131
bb82bf09b928 oops - return is a local return
Claus Gittinger <cg@exept.de>
parents: 123
diff changeset
    79
    ] ifFalse:[
bb82bf09b928 oops - return is a local return
Claus Gittinger <cg@exept.de>
parents: 123
diff changeset
    80
        lastStatement := nil.                                                                "+4"
123
22e2dd938ccd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
        thisStatement := statements.
22e2dd938ccd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
        [thisStatement notNil] whileTrue:[
22e2dd938ccd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
            nextStatement := thisStatement nextStatement.
131
bb82bf09b928 oops - return is a local return
Claus Gittinger <cg@exept.de>
parents: 123
diff changeset
    84
            thisStatement codeForSideEffectOn:aStream inBlock:self for:aCompiler.
bb82bf09b928 oops - return is a local return
Claus Gittinger <cg@exept.de>
parents: 123
diff changeset
    85
            lastStatement := thisStatement.     
123
22e2dd938ccd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
            thisStatement := nextStatement
22e2dd938ccd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
        ].
22e2dd938ccd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
131
bb82bf09b928 oops - return is a local return
Claus Gittinger <cg@exept.de>
parents: 123
diff changeset
    89
        lastStatement isReturnNode ifFalse:[
bb82bf09b928 oops - return is a local return
Claus Gittinger <cg@exept.de>
parents: 123
diff changeset
    90
            aStream nextPut:#retNil.
bb82bf09b928 oops - return is a local return
Claus Gittinger <cg@exept.de>
parents: 123
diff changeset
    91
        ].
bb82bf09b928 oops - return is a local return
Claus Gittinger <cg@exept.de>
parents: 123
diff changeset
    92
"/
bb82bf09b928 oops - return is a local return
Claus Gittinger <cg@exept.de>
parents: 123
diff changeset
    93
"/        lastStatement 
bb82bf09b928 oops - return is a local return
Claus Gittinger <cg@exept.de>
parents: 123
diff changeset
    94
"/                codeForSimpleReturnOn:aStream
bb82bf09b928 oops - return is a local return
Claus Gittinger <cg@exept.de>
parents: 123
diff changeset
    95
"/                inBlock:self 
bb82bf09b928 oops - return is a local return
Claus Gittinger <cg@exept.de>
parents: 123
diff changeset
    96
"/                lineNumber:lastStatement lineNumber 
bb82bf09b928 oops - return is a local return
Claus Gittinger <cg@exept.de>
parents: 123
diff changeset
    97
"/                for:aCompiler.
123
22e2dd938ccd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
    ].
22e2dd938ccd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
22e2dd938ccd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   100
    code := (aStream contents).
22e2dd938ccd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   101
    "/ sigh - during coding, inlined subBlocks may have added more
22e2dd938ccd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   102
    "/ tempVars; patch the nvar byte ...
22e2dd938ccd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   103
596
0efa73ee44b0 JavaScript
Claus Gittinger <cg@exept.de>
parents: 465
diff changeset
   104
    code at:pos+2 put:(self numVars + maxNumTemp).
123
22e2dd938ccd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   105
22e2dd938ccd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   106
    "set the end of the block's code"
637
bfb2c2642b7b class: JavaScriptInnerFunctionNode
Stefan Vogel <sv@exept.de>
parents: 596
diff changeset
   107
    code at:pos+1 put:(aStream position + 1)
133
097c71ec28c9 inner function calling
Claus Gittinger <cg@exept.de>
parents: 131
diff changeset
   108
!
097c71ec28c9 inner function calling
Claus Gittinger <cg@exept.de>
parents: 131
diff changeset
   109
097c71ec28c9 inner function calling
Claus Gittinger <cg@exept.de>
parents: 131
diff changeset
   110
rememberOuterBlockVarAccess:aVariableNode
097c71ec28c9 inner function calling
Claus Gittinger <cg@exept.de>
parents: 131
diff changeset
   111
"/    accessedOuterBlockVars isNil ifTrue:[
097c71ec28c9 inner function calling
Claus Gittinger <cg@exept.de>
parents: 131
diff changeset
   112
"/        accessedOuterBlockVars := OrderedCollection new.
097c71ec28c9 inner function calling
Claus Gittinger <cg@exept.de>
parents: 131
diff changeset
   113
"/    ].
097c71ec28c9 inner function calling
Claus Gittinger <cg@exept.de>
parents: 131
diff changeset
   114
"/    accessedOuterBlockVars add:aVariableNode
123
22e2dd938ccd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   115
! !
22e2dd938ccd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   116
465
4709e087f850 added: #evaluateIn:
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   117
!JavaScriptInnerFunctionNode methodsFor:'evaluation'!
4709e087f850 added: #evaluateIn:
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   118
4709e087f850 added: #evaluateIn:
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   119
evaluateIn:anEnvironment
4709e087f850 added: #evaluateIn:
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   120
    ^ self
4709e087f850 added: #evaluateIn:
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   121
! !
4709e087f850 added: #evaluateIn:
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   122
123
22e2dd938ccd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   123
!JavaScriptInnerFunctionNode methodsFor:'queries'!
22e2dd938ccd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   124
133
097c71ec28c9 inner function calling
Claus Gittinger <cg@exept.de>
parents: 131
diff changeset
   125
home
097c71ec28c9 inner function calling
Claus Gittinger <cg@exept.de>
parents: 131
diff changeset
   126
    ^ environment
097c71ec28c9 inner function calling
Claus Gittinger <cg@exept.de>
parents: 131
diff changeset
   127
!
097c71ec28c9 inner function calling
Claus Gittinger <cg@exept.de>
parents: 131
diff changeset
   128
123
22e2dd938ccd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   129
isInlineBlock
22e2dd938ccd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   130
    ^ false
133
097c71ec28c9 inner function calling
Claus Gittinger <cg@exept.de>
parents: 131
diff changeset
   131
!
097c71ec28c9 inner function calling
Claus Gittinger <cg@exept.de>
parents: 131
diff changeset
   132
596
0efa73ee44b0 JavaScript
Claus Gittinger <cg@exept.de>
parents: 465
diff changeset
   133
isInnerFunction
0efa73ee44b0 JavaScript
Claus Gittinger <cg@exept.de>
parents: 465
diff changeset
   134
    ^ true
0efa73ee44b0 JavaScript
Claus Gittinger <cg@exept.de>
parents: 465
diff changeset
   135
!
0efa73ee44b0 JavaScript
Claus Gittinger <cg@exept.de>
parents: 465
diff changeset
   136
133
097c71ec28c9 inner function calling
Claus Gittinger <cg@exept.de>
parents: 131
diff changeset
   137
isJavaScriptBlock
097c71ec28c9 inner function calling
Claus Gittinger <cg@exept.de>
parents: 131
diff changeset
   138
    ^ true
123
22e2dd938ccd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   139
! !
22e2dd938ccd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   140
652
e55b2faa8385 Added JavaScriptParseNodeVisitor
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 637
diff changeset
   141
!JavaScriptInnerFunctionNode methodsFor:'visiting'!
e55b2faa8385 Added JavaScriptParseNodeVisitor
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 637
diff changeset
   142
e55b2faa8385 Added JavaScriptParseNodeVisitor
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 637
diff changeset
   143
acceptVisitor:visitor 
e55b2faa8385 Added JavaScriptParseNodeVisitor
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 637
diff changeset
   144
    "Double dispatch back to the visitor, passing my type encoded in
e55b2faa8385 Added JavaScriptParseNodeVisitor
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 637
diff changeset
   145
     the selector (visitor pattern)"
e55b2faa8385 Added JavaScriptParseNodeVisitor
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 637
diff changeset
   146
e55b2faa8385 Added JavaScriptParseNodeVisitor
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 637
diff changeset
   147
    "stub code automatically generated - please change if required"
e55b2faa8385 Added JavaScriptParseNodeVisitor
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 637
diff changeset
   148
e55b2faa8385 Added JavaScriptParseNodeVisitor
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 637
diff changeset
   149
    ^ visitor visitJavaScriptInnerFunctionNode:self 
e55b2faa8385 Added JavaScriptParseNodeVisitor
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 637
diff changeset
   150
! !
e55b2faa8385 Added JavaScriptParseNodeVisitor
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 637
diff changeset
   151
123
22e2dd938ccd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   152
!JavaScriptInnerFunctionNode class methodsFor:'documentation'!
22e2dd938ccd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   153
22e2dd938ccd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   154
version
22e2dd938ccd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   155
    ^ '$Header$'
465
4709e087f850 added: #evaluateIn:
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   156
!
4709e087f850 added: #evaluateIn:
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   157
4709e087f850 added: #evaluateIn:
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   158
version_CVS
4709e087f850 added: #evaluateIn:
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   159
    ^ '$Header$'
123
22e2dd938ccd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   160
! !
596
0efa73ee44b0 JavaScript
Claus Gittinger <cg@exept.de>
parents: 465
diff changeset
   161