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