author | Jan Vrany <jan.vrany@labware.com> |
Thu, 27 Oct 2022 14:53:59 +0100 | |
branch | jv |
changeset 4735 | 3b11fb3ede98 |
parent 3836 | fa78fd27bebf |
permissions | -rw-r--r-- |
0 | 1 |
" |
4 | 2 |
COPYRIGHT (c) 1990 by Claus Gittinger |
53 | 3 |
All Rights Reserved |
0 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
1046 | 12 |
"{ Package: 'stx:libcomp' }" |
13 |
||
3836 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
0 | 16 |
StatementNode subclass:#PrimitiveNode |
261 | 17 |
instanceVariableNames:'code primNumber optional' |
18 |
classVariableNames:'' |
|
19 |
poolDictionaries:'' |
|
20 |
category:'System-Compiler-Support' |
|
0 | 21 |
! |
22 |
||
20 | 23 |
!PrimitiveNode class methodsFor:'documentation'! |
24 |
||
25 |
copyright |
|
26 |
" |
|
27 |
COPYRIGHT (c) 1990 by Claus Gittinger |
|
53 | 28 |
All Rights Reserved |
0 | 29 |
|
20 | 30 |
This software is furnished under a license and may be used |
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
! |
|
0 | 38 |
|
20 | 39 |
documentation |
40 |
" |
|
41 |
node for parse-trees, representing primitive code |
|
261 | 42 |
This is a helper class for the compiler. |
0 | 43 |
|
126 | 44 |
Primitives are (currently) not always supported by the incremental compiler |
20 | 45 |
- if you want a primitive, you must use the stc-compiler and |
46 |
link a new smalltalk. |
|
47 |
||
126 | 48 |
On system which support dynamic object loading, methods with primitives are passed |
49 |
to stc and the resulting binary is loaded into the image |
|
50 |
(also a limited set of numeric primitives could be implemented for more ST-80 |
|
51 |
compatibility - if there is a need). |
|
52 |
||
53 |
To allow autoloaded/filedIn code to be written for best performance, an optional |
|
54 |
primitive directive (in the primitives first lines comment) may specify an |
|
55 |
optional primitive; these are compiled on systems which do support binary code |
|
56 |
loading, and ignored completely on others. |
|
263 | 57 |
|
58 |
[author:] |
|
59 |
Claus Gittinger |
|
20 | 60 |
" |
61 |
! ! |
|
0 | 62 |
|
63 |
!PrimitiveNode class methodsFor:'instance creation'! |
|
64 |
||
65 |
code:aString |
|
66 |
^ self basicNew code:aString |
|
67 |
! |
|
68 |
||
69 |
primitiveNumber:anInteger |
|
70 |
^ self basicNew primitiveNumber:anInteger |
|
71 |
! ! |
|
72 |
||
73 |
!PrimitiveNode methodsFor:'accessing'! |
|
74 |
||
75 |
code:aString |
|
126 | 76 |
"set the primitives code - check for the 'OPTIONAL' directive" |
77 |
||
78 |
|firstLine commentPos words| |
|
79 |
||
80 |
code := aString. |
|
81 |
optional := false. |
|
82 |
||
83 |
firstLine := aString readStream nextLine. |
|
84 |
commentPos := firstLine indexOfSubCollection:'/*'. |
|
85 |
commentPos ~~ 0 ifTrue:[ |
|
86 |
words := (firstLine copyFrom:(commentPos + 2)) asCollectionOfWords. |
|
87 |
(words includes:'OPTIONAL') ifTrue:[ |
|
88 |
optional := true |
|
89 |
] |
|
90 |
] |
|
91 |
||
92 |
"Modified: 24.10.1995 / 11:29:51 / cg" |
|
0 | 93 |
! |
94 |
||
95 |
primitiveNumber:anInteger |
|
126 | 96 |
optional := false. |
0 | 97 |
primNumber := anInteger |
98 |
! ! |
|
99 |
||
3836 | 100 |
|
0 | 101 |
!PrimitiveNode methodsFor:'code generation'! |
102 |
||
104 | 103 |
codeForSideEffectOn:aStream inBlock:b for:aCompiler |
0 | 104 |
"catch code generation" |
105 |
||
126 | 106 |
optional ifTrue:[^ self]. |
1049 | 107 |
aCompiler class newPrimitives == true ifTrue:[^ self]. |
940 | 108 |
self error:'cannot compile primitives (as yet)' mayProceed:true |
0 | 109 |
! |
110 |
||
104 | 111 |
codeOn:aStream inBlock:b for:aCompiler |
0 | 112 |
"catch code generation" |
113 |
||
126 | 114 |
optional ifTrue:[^ self]. |
1049 | 115 |
aCompiler class newPrimitives == true ifTrue:[^ self]. |
940 | 116 |
self error:'cannot compile primitives (as yet)' mayProceed:true |
0 | 117 |
! ! |
140 | 118 |
|
1585 | 119 |
!PrimitiveNode methodsFor:'enumerating'! |
120 |
||
121 |
nodeDo:anEnumerator |
|
122 |
"helper for parse tree walking" |
|
123 |
||
124 |
^ anEnumerator doPrimitive:self code:code primitiveIndex:primNumber |
|
125 |
! ! |
|
126 |
||
1035 | 127 |
!PrimitiveNode methodsFor:'evaluation'! |
140 | 128 |
|
1383 | 129 |
evaluateExpressionIn:anEnvironment |
140 | 130 |
"catch evaluation" |
131 |
||
132 |
optional ifTrue:[^ nil]. |
|
940 | 133 |
self error:'cannot evaluate primitives' mayProceed:true |
140 | 134 |
! |
135 |
||
1383 | 136 |
evaluateIn:anEnvironment |
140 | 137 |
"catch evaluation" |
138 |
||
139 |
optional ifTrue:[^ nil]. |
|
940 | 140 |
self error:'cannot evaluate primitives' mayProceed:true |
140 | 141 |
! ! |
142 |
||
143 |
!PrimitiveNode methodsFor:'queries'! |
|
144 |
||
2565
918b43d03a00
- parse tree nodes are no longer shared
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2104
diff
changeset
|
145 |
containsReturn |
918b43d03a00
- parse tree nodes are no longer shared
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2104
diff
changeset
|
146 |
|
918b43d03a00
- parse tree nodes are no longer shared
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2104
diff
changeset
|
147 |
"/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
|
148 |
^(code includesString: 'return') |
918b43d03a00
- parse tree nodes are no longer shared
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2104
diff
changeset
|
149 |
or: [code includesString: 'RETURN'] |
918b43d03a00
- parse tree nodes are no longer shared
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2104
diff
changeset
|
150 |
|
918b43d03a00
- parse tree nodes are no longer shared
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2104
diff
changeset
|
151 |
"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
|
152 |
! |
918b43d03a00
- parse tree nodes are no longer shared
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2104
diff
changeset
|
153 |
|
140 | 154 |
isConstant |
155 |
^ false |
|
156 |
! |
|
157 |
||
158 |
isOptional |
|
159 |
^ optional |
|
2104 | 160 |
! |
161 |
||
162 |
isSimpleConstant |
|
163 |
^ false |
|
164 |
! |
|
165 |
||
166 |
isSimpleExpression |
|
167 |
^ false |
|
168 |
! |
|
169 |
||
170 |
isSimpleVariable |
|
171 |
^ false |
|
140 | 172 |
! ! |
173 |
||
2602 | 174 |
!PrimitiveNode methodsFor:'visiting'! |
175 |
||
176 |
acceptVisitor:aVisitor |
|
177 |
"Double dispatch back to the visitor, passing my type encoded in |
|
178 |
the selector (visitor pattern)" |
|
179 |
||
180 |
"stub code automatically generated - please change if required" |
|
181 |
||
182 |
^ aVisitor visitPrimitiveNode:self |
|
183 |
! ! |
|
184 |
||
148 | 185 |
!PrimitiveNode class methodsFor:'documentation'! |
186 |
||
187 |
version |
|
3836 | 188 |
^ '$Header$' |
189 |
! |
|
190 |
||
191 |
version_CVS |
|
192 |
^ '$Header$' |
|
148 | 193 |
! ! |
3836 | 194 |