PrimitiveNode.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Tue, 19 Jul 2011 21:17:45 +0200
changeset 2565 918b43d03a00
parent 2104 6bd4cdfdb2b1
child 2602 abf07802e67f
permissions -rw-r--r--
- parse tree nodes are no longer shared - initial support for rembembering positions in code, not yet finished
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
     1
"
4
f6fd83437415 *** empty log message ***
claus
parents: 3
diff changeset
     2
 COPYRIGHT (c) 1990 by Claus Gittinger
53
c5dd7abf8431 *** empty log message ***
claus
parents: 33
diff changeset
     3
	      All Rights Reserved
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
     4
7ad01559b262 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
7ad01559b262 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
7ad01559b262 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
7ad01559b262 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
7ad01559b262 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
7ad01559b262 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
7ad01559b262 Initial revision
claus
parents:
diff changeset
    11
"
1046
8e5818442eb9 newCode (for rel5)
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
    12
"{ Package: 'stx:libcomp' }"
8e5818442eb9 newCode (for rel5)
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
    13
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    14
StatementNode subclass:#PrimitiveNode
261
0372e948ca2d commentary
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    15
	instanceVariableNames:'code primNumber optional'
0372e948ca2d commentary
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    16
	classVariableNames:''
0372e948ca2d commentary
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    17
	poolDictionaries:''
0372e948ca2d commentary
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    18
	category:'System-Compiler-Support'
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    19
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
    20
20
f8dd8ba75205 *** empty log message ***
claus
parents: 4
diff changeset
    21
!PrimitiveNode class methodsFor:'documentation'!
f8dd8ba75205 *** empty log message ***
claus
parents: 4
diff changeset
    22
f8dd8ba75205 *** empty log message ***
claus
parents: 4
diff changeset
    23
copyright
f8dd8ba75205 *** empty log message ***
claus
parents: 4
diff changeset
    24
"
f8dd8ba75205 *** empty log message ***
claus
parents: 4
diff changeset
    25
 COPYRIGHT (c) 1990 by Claus Gittinger
53
c5dd7abf8431 *** empty log message ***
claus
parents: 33
diff changeset
    26
	      All Rights Reserved
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    27
20
f8dd8ba75205 *** empty log message ***
claus
parents: 4
diff changeset
    28
 This software is furnished under a license and may be used
f8dd8ba75205 *** empty log message ***
claus
parents: 4
diff changeset
    29
 only in accordance with the terms of that license and with the
f8dd8ba75205 *** empty log message ***
claus
parents: 4
diff changeset
    30
 inclusion of the above copyright notice.   This software may not
f8dd8ba75205 *** empty log message ***
claus
parents: 4
diff changeset
    31
 be provided or otherwise made available to, or used by, any
f8dd8ba75205 *** empty log message ***
claus
parents: 4
diff changeset
    32
 other person.  No title to or ownership of the software is
f8dd8ba75205 *** empty log message ***
claus
parents: 4
diff changeset
    33
 hereby transferred.
f8dd8ba75205 *** empty log message ***
claus
parents: 4
diff changeset
    34
"
f8dd8ba75205 *** empty log message ***
claus
parents: 4
diff changeset
    35
!
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    36
20
f8dd8ba75205 *** empty log message ***
claus
parents: 4
diff changeset
    37
documentation
f8dd8ba75205 *** empty log message ***
claus
parents: 4
diff changeset
    38
"
f8dd8ba75205 *** empty log message ***
claus
parents: 4
diff changeset
    39
    node for parse-trees, representing primitive code
261
0372e948ca2d commentary
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    40
    This is a helper class for the compiler.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    41
126
Claus Gittinger <cg@exept.de>
parents: 104
diff changeset
    42
    Primitives are (currently) not always supported by the incremental compiler 
20
f8dd8ba75205 *** empty log message ***
claus
parents: 4
diff changeset
    43
    - if you want a primitive, you must use the stc-compiler and 
f8dd8ba75205 *** empty log message ***
claus
parents: 4
diff changeset
    44
    link a new smalltalk.
f8dd8ba75205 *** empty log message ***
claus
parents: 4
diff changeset
    45
126
Claus Gittinger <cg@exept.de>
parents: 104
diff changeset
    46
    On system which support dynamic object loading, methods with primitives are passed 
Claus Gittinger <cg@exept.de>
parents: 104
diff changeset
    47
    to stc and the resulting binary is loaded into the image 
Claus Gittinger <cg@exept.de>
parents: 104
diff changeset
    48
    (also a limited set of numeric primitives could be implemented for more ST-80 
Claus Gittinger <cg@exept.de>
parents: 104
diff changeset
    49
     compatibility - if there is a need).
Claus Gittinger <cg@exept.de>
parents: 104
diff changeset
    50
Claus Gittinger <cg@exept.de>
parents: 104
diff changeset
    51
    To allow autoloaded/filedIn code to be written for best performance, an optional
Claus Gittinger <cg@exept.de>
parents: 104
diff changeset
    52
    primitive directive (in the primitives first lines comment) may specify an
Claus Gittinger <cg@exept.de>
parents: 104
diff changeset
    53
    optional primitive; these are compiled on systems which do support binary code
Claus Gittinger <cg@exept.de>
parents: 104
diff changeset
    54
    loading, and ignored completely on others.
263
3b21d0991eff documentation
Claus Gittinger <cg@exept.de>
parents: 261
diff changeset
    55
3b21d0991eff documentation
Claus Gittinger <cg@exept.de>
parents: 261
diff changeset
    56
    [author:]
3b21d0991eff documentation
Claus Gittinger <cg@exept.de>
parents: 261
diff changeset
    57
        Claus Gittinger
20
f8dd8ba75205 *** empty log message ***
claus
parents: 4
diff changeset
    58
"
f8dd8ba75205 *** empty log message ***
claus
parents: 4
diff changeset
    59
! !
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    60
7ad01559b262 Initial revision
claus
parents:
diff changeset
    61
!PrimitiveNode class methodsFor:'instance creation'!
7ad01559b262 Initial revision
claus
parents:
diff changeset
    62
7ad01559b262 Initial revision
claus
parents:
diff changeset
    63
code:aString
7ad01559b262 Initial revision
claus
parents:
diff changeset
    64
    ^ self basicNew code:aString
7ad01559b262 Initial revision
claus
parents:
diff changeset
    65
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
    66
7ad01559b262 Initial revision
claus
parents:
diff changeset
    67
primitiveNumber:anInteger
7ad01559b262 Initial revision
claus
parents:
diff changeset
    68
    ^ self basicNew primitiveNumber:anInteger
7ad01559b262 Initial revision
claus
parents:
diff changeset
    69
! !
7ad01559b262 Initial revision
claus
parents:
diff changeset
    70
2565
918b43d03a00 - parse tree nodes are no longer shared
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2104
diff changeset
    71
!PrimitiveNode class methodsFor:'others'!
918b43d03a00 - parse tree nodes are no longer shared
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2104
diff changeset
    72
918b43d03a00 - parse tree nodes are no longer shared
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2104
diff changeset
    73
version_CVS
918b43d03a00 - parse tree nodes are no longer shared
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2104
diff changeset
    74
    ^ '$Header: /cvs/stx/stx/libcomp/PrimitiveNode.st,v 1.23 2011-07-19 19:17:45 vrany Exp $'
918b43d03a00 - parse tree nodes are no longer shared
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2104
diff changeset
    75
! !
918b43d03a00 - parse tree nodes are no longer shared
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2104
diff changeset
    76
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    77
!PrimitiveNode methodsFor:'accessing'!
7ad01559b262 Initial revision
claus
parents:
diff changeset
    78
7ad01559b262 Initial revision
claus
parents:
diff changeset
    79
code:aString
126
Claus Gittinger <cg@exept.de>
parents: 104
diff changeset
    80
    "set the primitives code - check for the 'OPTIONAL' directive"
Claus Gittinger <cg@exept.de>
parents: 104
diff changeset
    81
Claus Gittinger <cg@exept.de>
parents: 104
diff changeset
    82
    |firstLine commentPos words|
Claus Gittinger <cg@exept.de>
parents: 104
diff changeset
    83
Claus Gittinger <cg@exept.de>
parents: 104
diff changeset
    84
    code := aString.
Claus Gittinger <cg@exept.de>
parents: 104
diff changeset
    85
    optional := false.
Claus Gittinger <cg@exept.de>
parents: 104
diff changeset
    86
Claus Gittinger <cg@exept.de>
parents: 104
diff changeset
    87
    firstLine := aString readStream nextLine.
Claus Gittinger <cg@exept.de>
parents: 104
diff changeset
    88
    commentPos := firstLine indexOfSubCollection:'/*'.
Claus Gittinger <cg@exept.de>
parents: 104
diff changeset
    89
    commentPos ~~ 0 ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 104
diff changeset
    90
	words := (firstLine copyFrom:(commentPos + 2)) asCollectionOfWords.
Claus Gittinger <cg@exept.de>
parents: 104
diff changeset
    91
	(words includes:'OPTIONAL') ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 104
diff changeset
    92
	    optional := true
Claus Gittinger <cg@exept.de>
parents: 104
diff changeset
    93
	]
Claus Gittinger <cg@exept.de>
parents: 104
diff changeset
    94
    ]
Claus Gittinger <cg@exept.de>
parents: 104
diff changeset
    95
Claus Gittinger <cg@exept.de>
parents: 104
diff changeset
    96
    "Modified: 24.10.1995 / 11:29:51 / cg"
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    97
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
    98
7ad01559b262 Initial revision
claus
parents:
diff changeset
    99
primitiveNumber:anInteger 
126
Claus Gittinger <cg@exept.de>
parents: 104
diff changeset
   100
    optional := false.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   101
    primNumber := anInteger
7ad01559b262 Initial revision
claus
parents:
diff changeset
   102
! !
7ad01559b262 Initial revision
claus
parents:
diff changeset
   103
7ad01559b262 Initial revision
claus
parents:
diff changeset
   104
!PrimitiveNode methodsFor:'code generation'!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   105
104
claus
parents: 103
diff changeset
   106
codeForSideEffectOn:aStream inBlock:b for:aCompiler
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   107
    "catch code generation"
7ad01559b262 Initial revision
claus
parents:
diff changeset
   108
126
Claus Gittinger <cg@exept.de>
parents: 104
diff changeset
   109
    optional ifTrue:[^ self].
1049
0b69b110f150 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1046
diff changeset
   110
    aCompiler class newPrimitives == true ifTrue:[^ self].
940
84c858922dc3 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   111
    self error:'cannot compile primitives (as yet)' mayProceed:true
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   112
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   113
104
claus
parents: 103
diff changeset
   114
codeOn:aStream inBlock:b for:aCompiler
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   115
    "catch code generation"
7ad01559b262 Initial revision
claus
parents:
diff changeset
   116
126
Claus Gittinger <cg@exept.de>
parents: 104
diff changeset
   117
    optional ifTrue:[^ self].
1049
0b69b110f150 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1046
diff changeset
   118
    aCompiler class newPrimitives == true ifTrue:[^ self].
940
84c858922dc3 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   119
    self error:'cannot compile primitives (as yet)' mayProceed:true
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   120
! !
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   121
1585
63f4b846bf3d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1383
diff changeset
   122
!PrimitiveNode methodsFor:'enumerating'!
63f4b846bf3d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1383
diff changeset
   123
63f4b846bf3d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1383
diff changeset
   124
nodeDo:anEnumerator
63f4b846bf3d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1383
diff changeset
   125
    "helper for parse tree walking"
63f4b846bf3d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1383
diff changeset
   126
63f4b846bf3d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1383
diff changeset
   127
    ^ anEnumerator doPrimitive:self code:code primitiveIndex:primNumber
63f4b846bf3d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1383
diff changeset
   128
! !
63f4b846bf3d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1383
diff changeset
   129
1035
8848672cb893 category rename
Claus Gittinger <cg@exept.de>
parents: 940
diff changeset
   130
!PrimitiveNode methodsFor:'evaluation'!
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   131
1383
3d485eefbb36 evaluate -> evaluateIn:
Claus Gittinger <cg@exept.de>
parents: 1049
diff changeset
   132
evaluateExpressionIn:anEnvironment
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   133
    "catch evaluation"
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   134
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   135
    optional ifTrue:[^ nil].
940
84c858922dc3 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   136
    self error:'cannot evaluate primitives' mayProceed:true
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   137
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   138
1383
3d485eefbb36 evaluate -> evaluateIn:
Claus Gittinger <cg@exept.de>
parents: 1049
diff changeset
   139
evaluateIn:anEnvironment
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   140
    "catch evaluation"
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   141
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   142
    optional ifTrue:[^ nil].
940
84c858922dc3 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   143
    self error:'cannot evaluate primitives' mayProceed:true
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   144
! !
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   145
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   146
!PrimitiveNode methodsFor:'queries'!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   147
2565
918b43d03a00 - parse tree nodes are no longer shared
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2104
diff changeset
   148
containsReturn
918b43d03a00 - parse tree nodes are no longer shared
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2104
diff changeset
   149
918b43d03a00 - parse tree nodes are no longer shared
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2104
diff changeset
   150
    "/JV@2011-07-19: I'm not quite sure that this is OK..."
918b43d03a00 - parse tree nodes are no longer shared
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2104
diff changeset
   151
    ^(code includesString: 'return') 
918b43d03a00 - parse tree nodes are no longer shared
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2104
diff changeset
   152
        or: [code includesString: 'RETURN']
918b43d03a00 - parse tree nodes are no longer shared
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2104
diff changeset
   153
918b43d03a00 - parse tree nodes are no longer shared
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2104
diff changeset
   154
    "Created: / 19-07-2011 / 18:47:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
918b43d03a00 - parse tree nodes are no longer shared
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2104
diff changeset
   155
!
918b43d03a00 - parse tree nodes are no longer shared
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2104
diff changeset
   156
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   157
isConstant
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   158
    ^ false
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   159
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   160
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   161
isOptional
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   162
    ^ optional
2104
6bd4cdfdb2b1 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   163
!
6bd4cdfdb2b1 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   164
6bd4cdfdb2b1 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   165
isSimpleConstant
6bd4cdfdb2b1 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   166
    ^ false
6bd4cdfdb2b1 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   167
!
6bd4cdfdb2b1 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   168
6bd4cdfdb2b1 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   169
isSimpleExpression
6bd4cdfdb2b1 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   170
    ^ false
6bd4cdfdb2b1 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   171
!
6bd4cdfdb2b1 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   172
6bd4cdfdb2b1 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   173
isSimpleVariable
6bd4cdfdb2b1 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   174
    ^ false
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   175
! !
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   176
148
ef0e604209ec version method at the end
Claus Gittinger <cg@exept.de>
parents: 140
diff changeset
   177
!PrimitiveNode class methodsFor:'documentation'!
ef0e604209ec version method at the end
Claus Gittinger <cg@exept.de>
parents: 140
diff changeset
   178
ef0e604209ec version method at the end
Claus Gittinger <cg@exept.de>
parents: 140
diff changeset
   179
version
2565
918b43d03a00 - parse tree nodes are no longer shared
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2104
diff changeset
   180
    ^ '$Header: /cvs/stx/stx/libcomp/PrimitiveNode.st,v 1.23 2011-07-19 19:17:45 vrany Exp $'
148
ef0e604209ec version method at the end
Claus Gittinger <cg@exept.de>
parents: 140
diff changeset
   181
! !