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