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