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-- |
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 |
||
0 | 14 |
StatementNode subclass:#PrimitiveNode |
261 | 15 |
instanceVariableNames:'code primNumber optional' |
16 |
classVariableNames:'' |
|
17 |
poolDictionaries:'' |
|
18 |
category:'System-Compiler-Support' |
|
0 | 19 |
! |
20 |
||
20 | 21 |
!PrimitiveNode class methodsFor:'documentation'! |
22 |
||
23 |
copyright |
|
24 |
" |
|
25 |
COPYRIGHT (c) 1990 by Claus Gittinger |
|
53 | 26 |
All Rights Reserved |
0 | 27 |
|
20 | 28 |
This software is furnished under a license and may be used |
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
! |
|
0 | 36 |
|
20 | 37 |
documentation |
38 |
" |
|
39 |
node for parse-trees, representing primitive code |
|
261 | 40 |
This is a helper class for the compiler. |
0 | 41 |
|
126 | 42 |
Primitives are (currently) not always supported by the incremental compiler |
20 | 43 |
- if you want a primitive, you must use the stc-compiler and |
44 |
link a new smalltalk. |
|
45 |
||
126 | 46 |
On system which support dynamic object loading, methods with primitives are passed |
47 |
to stc and the resulting binary is loaded into the image |
|
48 |
(also a limited set of numeric primitives could be implemented for more ST-80 |
|
49 |
compatibility - if there is a need). |
|
50 |
||
51 |
To allow autoloaded/filedIn code to be written for best performance, an optional |
|
52 |
primitive directive (in the primitives first lines comment) may specify an |
|
53 |
optional primitive; these are compiled on systems which do support binary code |
|
54 |
loading, and ignored completely on others. |
|
263 | 55 |
|
56 |
[author:] |
|
57 |
Claus Gittinger |
|
20 | 58 |
" |
59 |
! ! |
|
0 | 60 |
|
61 |
!PrimitiveNode class methodsFor:'instance creation'! |
|
62 |
||
63 |
code:aString |
|
64 |
^ self basicNew code:aString |
|
65 |
! |
|
66 |
||
67 |
primitiveNumber:anInteger |
|
68 |
^ self basicNew primitiveNumber:anInteger |
|
69 |
! ! |
|
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 | 77 |
!PrimitiveNode methodsFor:'accessing'! |
78 |
||
79 |
code:aString |
|
126 | 80 |
"set the primitives code - check for the 'OPTIONAL' directive" |
81 |
||
82 |
|firstLine commentPos words| |
|
83 |
||
84 |
code := aString. |
|
85 |
optional := false. |
|
86 |
||
87 |
firstLine := aString readStream nextLine. |
|
88 |
commentPos := firstLine indexOfSubCollection:'/*'. |
|
89 |
commentPos ~~ 0 ifTrue:[ |
|
90 |
words := (firstLine copyFrom:(commentPos + 2)) asCollectionOfWords. |
|
91 |
(words includes:'OPTIONAL') ifTrue:[ |
|
92 |
optional := true |
|
93 |
] |
|
94 |
] |
|
95 |
||
96 |
"Modified: 24.10.1995 / 11:29:51 / cg" |
|
0 | 97 |
! |
98 |
||
99 |
primitiveNumber:anInteger |
|
126 | 100 |
optional := false. |
0 | 101 |
primNumber := anInteger |
102 |
! ! |
|
103 |
||
104 |
!PrimitiveNode methodsFor:'code generation'! |
|
105 |
||
104 | 106 |
codeForSideEffectOn:aStream inBlock:b for:aCompiler |
0 | 107 |
"catch code generation" |
108 |
||
126 | 109 |
optional ifTrue:[^ self]. |
1049 | 110 |
aCompiler class newPrimitives == true ifTrue:[^ self]. |
940 | 111 |
self error:'cannot compile primitives (as yet)' mayProceed:true |
0 | 112 |
! |
113 |
||
104 | 114 |
codeOn:aStream inBlock:b for:aCompiler |
0 | 115 |
"catch code generation" |
116 |
||
126 | 117 |
optional ifTrue:[^ self]. |
1049 | 118 |
aCompiler class newPrimitives == true ifTrue:[^ self]. |
940 | 119 |
self error:'cannot compile primitives (as yet)' mayProceed:true |
0 | 120 |
! ! |
140 | 121 |
|
1585 | 122 |
!PrimitiveNode methodsFor:'enumerating'! |
123 |
||
124 |
nodeDo:anEnumerator |
|
125 |
"helper for parse tree walking" |
|
126 |
||
127 |
^ anEnumerator doPrimitive:self code:code primitiveIndex:primNumber |
|
128 |
! ! |
|
129 |
||
1035 | 130 |
!PrimitiveNode methodsFor:'evaluation'! |
140 | 131 |
|
1383 | 132 |
evaluateExpressionIn:anEnvironment |
140 | 133 |
"catch evaluation" |
134 |
||
135 |
optional ifTrue:[^ nil]. |
|
940 | 136 |
self error:'cannot evaluate primitives' mayProceed:true |
140 | 137 |
! |
138 |
||
1383 | 139 |
evaluateIn:anEnvironment |
140 | 140 |
"catch evaluation" |
141 |
||
142 |
optional ifTrue:[^ nil]. |
|
940 | 143 |
self error:'cannot evaluate primitives' mayProceed:true |
140 | 144 |
! ! |
145 |
||
146 |
!PrimitiveNode methodsFor:'queries'! |
|
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 | 157 |
isConstant |
158 |
^ false |
|
159 |
! |
|
160 |
||
161 |
isOptional |
|
162 |
^ optional |
|
2104 | 163 |
! |
164 |
||
165 |
isSimpleConstant |
|
166 |
^ false |
|
167 |
! |
|
168 |
||
169 |
isSimpleExpression |
|
170 |
^ false |
|
171 |
! |
|
172 |
||
173 |
isSimpleVariable |
|
174 |
^ false |
|
140 | 175 |
! ! |
176 |
||
148 | 177 |
!PrimitiveNode class methodsFor:'documentation'! |
178 |
||
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 | 181 |
! ! |