PrimNd.st
author Claus Gittinger <cg@exept.de>
Tue, 12 Nov 1996 13:18:57 +0100
changeset 441 fa5637faa969
parent 263 3b21d0991eff
child 940 84c858922dc3
permissions -rw-r--r--
*** empty log message ***

"
 COPYRIGHT (c) 1990 by Claus Gittinger
	      All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"

StatementNode subclass:#PrimitiveNode
	instanceVariableNames:'code primNumber optional'
	classVariableNames:''
	poolDictionaries:''
	category:'System-Compiler-Support'
!

!PrimitiveNode class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1990 by Claus Gittinger
	      All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
!

documentation
"
    node for parse-trees, representing primitive code
    This is a helper class for the compiler.

    Primitives are (currently) not always supported by the incremental compiler 
    - if you want a primitive, you must use the stc-compiler and 
    link a new smalltalk.

    On system which support dynamic object loading, methods with primitives are passed 
    to stc and the resulting binary is loaded into the image 
    (also a limited set of numeric primitives could be implemented for more ST-80 
     compatibility - if there is a need).

    To allow autoloaded/filedIn code to be written for best performance, an optional
    primitive directive (in the primitives first lines comment) may specify an
    optional primitive; these are compiled on systems which do support binary code
    loading, and ignored completely on others.

    [author:]
        Claus Gittinger
"
! !

!PrimitiveNode class methodsFor:'instance creation'!

code:aString
    ^ self basicNew code:aString
!

primitiveNumber:anInteger
    ^ self basicNew primitiveNumber:anInteger
! !

!PrimitiveNode methodsFor:'accessing'!

code:aString
    "set the primitives code - check for the 'OPTIONAL' directive"

    |firstLine commentPos words|

    code := aString.
    optional := false.

    firstLine := aString readStream nextLine.
    commentPos := firstLine indexOfSubCollection:'/*'.
    commentPos ~~ 0 ifTrue:[
	words := (firstLine copyFrom:(commentPos + 2)) asCollectionOfWords.
	(words includes:'OPTIONAL') ifTrue:[
	    optional := true
	]
    ]

    "Modified: 24.10.1995 / 11:29:51 / cg"
!

primitiveNumber:anInteger 
    optional := false.
    primNumber := anInteger
! !

!PrimitiveNode methodsFor:'code generation'!

codeForSideEffectOn:aStream inBlock:b for:aCompiler
    "catch code generation"

    optional ifTrue:[^ self].
    self error:'cannot compile primitives (as yet)'
!

codeOn:aStream inBlock:b for:aCompiler
    "catch code generation"

    optional ifTrue:[^ self].
    self error:'cannot compile primitives (as yet)'
! !

!PrimitiveNode methodsFor:'evaluating'!

evaluate
    "catch evaluation"

    optional ifTrue:[^ nil].
    self error:'cannot evaluate primitives'
!

evaluateExpression
    "catch evaluation"

    optional ifTrue:[^ nil].
    self error:'cannot evaluate primitives'
! !

!PrimitiveNode methodsFor:'queries'!

isConstant
    ^ false
!

isOptional
    ^ optional
! !

!PrimitiveNode class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libcomp/Attic/PrimNd.st,v 1.15 1996-04-25 17:08:39 cg Exp $'
! !