PrimitiveNode.st
author Claus Gittinger <cg@exept.de>
Mon, 20 Oct 2008 17:10:47 +0200
changeset 2118 8ba726417c70
parent 2104 6bd4cdfdb2b1
child 2565 918b43d03a00
permissions -rw-r--r--
halt
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
7ad01559b262 Initial revision
claus
parents:
diff changeset
    71
!PrimitiveNode methodsFor:'accessing'!
7ad01559b262 Initial revision
claus
parents:
diff changeset
    72
7ad01559b262 Initial revision
claus
parents:
diff changeset
    73
code:aString
126
Claus Gittinger <cg@exept.de>
parents: 104
diff changeset
    74
    "set the primitives code - check for the 'OPTIONAL' directive"
Claus Gittinger <cg@exept.de>
parents: 104
diff changeset
    75
Claus Gittinger <cg@exept.de>
parents: 104
diff changeset
    76
    |firstLine commentPos words|
Claus Gittinger <cg@exept.de>
parents: 104
diff changeset
    77
Claus Gittinger <cg@exept.de>
parents: 104
diff changeset
    78
    code := aString.
Claus Gittinger <cg@exept.de>
parents: 104
diff changeset
    79
    optional := false.
Claus Gittinger <cg@exept.de>
parents: 104
diff changeset
    80
Claus Gittinger <cg@exept.de>
parents: 104
diff changeset
    81
    firstLine := aString readStream nextLine.
Claus Gittinger <cg@exept.de>
parents: 104
diff changeset
    82
    commentPos := firstLine indexOfSubCollection:'/*'.
Claus Gittinger <cg@exept.de>
parents: 104
diff changeset
    83
    commentPos ~~ 0 ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 104
diff changeset
    84
	words := (firstLine copyFrom:(commentPos + 2)) asCollectionOfWords.
Claus Gittinger <cg@exept.de>
parents: 104
diff changeset
    85
	(words includes:'OPTIONAL') ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 104
diff changeset
    86
	    optional := true
Claus Gittinger <cg@exept.de>
parents: 104
diff changeset
    87
	]
Claus Gittinger <cg@exept.de>
parents: 104
diff changeset
    88
    ]
Claus Gittinger <cg@exept.de>
parents: 104
diff changeset
    89
Claus Gittinger <cg@exept.de>
parents: 104
diff changeset
    90
    "Modified: 24.10.1995 / 11:29:51 / cg"
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    91
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
    92
7ad01559b262 Initial revision
claus
parents:
diff changeset
    93
primitiveNumber:anInteger 
126
Claus Gittinger <cg@exept.de>
parents: 104
diff changeset
    94
    optional := false.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    95
    primNumber := anInteger
7ad01559b262 Initial revision
claus
parents:
diff changeset
    96
! !
7ad01559b262 Initial revision
claus
parents:
diff changeset
    97
7ad01559b262 Initial revision
claus
parents:
diff changeset
    98
!PrimitiveNode methodsFor:'code generation'!
7ad01559b262 Initial revision
claus
parents:
diff changeset
    99
104
claus
parents: 103
diff changeset
   100
codeForSideEffectOn:aStream inBlock:b for:aCompiler
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   101
    "catch code generation"
7ad01559b262 Initial revision
claus
parents:
diff changeset
   102
126
Claus Gittinger <cg@exept.de>
parents: 104
diff changeset
   103
    optional ifTrue:[^ self].
1049
0b69b110f150 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1046
diff changeset
   104
    aCompiler class newPrimitives == true ifTrue:[^ self].
940
84c858922dc3 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   105
    self error:'cannot compile primitives (as yet)' mayProceed:true
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   106
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   107
104
claus
parents: 103
diff changeset
   108
codeOn:aStream inBlock:b for:aCompiler
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   109
    "catch code generation"
7ad01559b262 Initial revision
claus
parents:
diff changeset
   110
126
Claus Gittinger <cg@exept.de>
parents: 104
diff changeset
   111
    optional ifTrue:[^ self].
1049
0b69b110f150 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1046
diff changeset
   112
    aCompiler class newPrimitives == true ifTrue:[^ self].
940
84c858922dc3 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   113
    self error:'cannot compile primitives (as yet)' mayProceed:true
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   114
! !
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   115
1585
63f4b846bf3d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1383
diff changeset
   116
!PrimitiveNode methodsFor:'enumerating'!
63f4b846bf3d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1383
diff changeset
   117
63f4b846bf3d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1383
diff changeset
   118
nodeDo:anEnumerator
63f4b846bf3d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1383
diff changeset
   119
    "helper for parse tree walking"
63f4b846bf3d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1383
diff changeset
   120
63f4b846bf3d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1383
diff changeset
   121
    ^ anEnumerator doPrimitive:self code:code primitiveIndex:primNumber
63f4b846bf3d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1383
diff changeset
   122
! !
63f4b846bf3d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1383
diff changeset
   123
1035
8848672cb893 category rename
Claus Gittinger <cg@exept.de>
parents: 940
diff changeset
   124
!PrimitiveNode methodsFor:'evaluation'!
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   125
1383
3d485eefbb36 evaluate -> evaluateIn:
Claus Gittinger <cg@exept.de>
parents: 1049
diff changeset
   126
evaluateExpressionIn:anEnvironment
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   127
    "catch evaluation"
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   128
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   129
    optional ifTrue:[^ nil].
940
84c858922dc3 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   130
    self error:'cannot evaluate primitives' mayProceed:true
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   131
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   132
1383
3d485eefbb36 evaluate -> evaluateIn:
Claus Gittinger <cg@exept.de>
parents: 1049
diff changeset
   133
evaluateIn:anEnvironment
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   134
    "catch evaluation"
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   135
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   136
    optional ifTrue:[^ nil].
940
84c858922dc3 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   137
    self error:'cannot evaluate primitives' mayProceed:true
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   138
! !
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   139
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   140
!PrimitiveNode methodsFor:'queries'!
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
isConstant
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   143
    ^ false
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
isOptional
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   147
    ^ optional
2104
6bd4cdfdb2b1 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   148
!
6bd4cdfdb2b1 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   149
6bd4cdfdb2b1 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   150
isSimpleConstant
6bd4cdfdb2b1 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   151
    ^ false
6bd4cdfdb2b1 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   152
!
6bd4cdfdb2b1 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   153
6bd4cdfdb2b1 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   154
isSimpleExpression
6bd4cdfdb2b1 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   155
    ^ false
6bd4cdfdb2b1 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   156
!
6bd4cdfdb2b1 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   157
6bd4cdfdb2b1 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   158
isSimpleVariable
6bd4cdfdb2b1 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   159
    ^ false
140
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
148
ef0e604209ec version method at the end
Claus Gittinger <cg@exept.de>
parents: 140
diff changeset
   162
!PrimitiveNode class methodsFor:'documentation'!
ef0e604209ec version method at the end
Claus Gittinger <cg@exept.de>
parents: 140
diff changeset
   163
ef0e604209ec version method at the end
Claus Gittinger <cg@exept.de>
parents: 140
diff changeset
   164
version
2104
6bd4cdfdb2b1 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   165
    ^ '$Header: /cvs/stx/stx/libcomp/PrimitiveNode.st,v 1.22 2008-07-25 12:45:50 cg Exp $'
148
ef0e604209ec version method at the end
Claus Gittinger <cg@exept.de>
parents: 140
diff changeset
   166
! !