ConstantNode.st
author Claus Gittinger <cg@exept.de>
Tue, 25 Feb 2020 13:40:16 +0100
changeset 4643 e305b814a348
parent 4602 b422ca3ad101
child 4691 792a4618488c
permissions -rw-r--r--
#BUGFIX by cg class: SyntaxHighlighter comment/format in: #markParenthesisAt:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4602
b422ca3ad101 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4588
diff changeset
     1
"{ Encoding: utf8 }"
b422ca3ad101 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4588
diff changeset
     2
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
     3
"
4
f6fd83437415 *** empty log message ***
claus
parents: 3
diff changeset
     4
 COPYRIGHT (c) 1989 by Claus Gittinger
47
f861ad42703e *** empty log message ***
claus
parents: 33
diff changeset
     5
	      All Rights Reserved
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
     6
7ad01559b262 Initial revision
claus
parents:
diff changeset
     7
 This software is furnished under a license and may be used
7ad01559b262 Initial revision
claus
parents:
diff changeset
     8
 only in accordance with the terms of that license and with the
7ad01559b262 Initial revision
claus
parents:
diff changeset
     9
 inclusion of the above copyright notice.   This software may not
7ad01559b262 Initial revision
claus
parents:
diff changeset
    10
 be provided or otherwise made available to, or used by, any
7ad01559b262 Initial revision
claus
parents:
diff changeset
    11
 other person.  No title to or ownership of the software is
7ad01559b262 Initial revision
claus
parents:
diff changeset
    12
 hereby transferred.
7ad01559b262 Initial revision
claus
parents:
diff changeset
    13
"
1080
bd3f19f6009a category change
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
    14
"{ Package: 'stx:libcomp' }"
bd3f19f6009a category change
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
    15
3811
ebeffc3fcf61 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 3503
diff changeset
    16
"{ NameSpace: Smalltalk }"
ebeffc3fcf61 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 3503
diff changeset
    17
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    18
PrimaryNode subclass:#ConstantNode
4351
bdd0b93eca81 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4278
diff changeset
    19
	instanceVariableNames:'originalString'
3246
d0c8d1d6bad7 class: ConstantNode
Claus Gittinger <cg@exept.de>
parents: 2895
diff changeset
    20
	classVariableNames:'TrueNode FalseNode NilNode Const0Node Const1Node Float0Node'
242
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    21
	poolDictionaries:''
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    22
	category:'System-Compiler-Support'
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    23
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
    24
20
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    25
!ConstantNode class methodsFor:'documentation'!
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    26
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    27
copyright
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    28
"
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    29
 COPYRIGHT (c) 1989 by Claus Gittinger
47
f861ad42703e *** empty log message ***
claus
parents: 33
diff changeset
    30
	      All Rights Reserved
20
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    31
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    32
 This software is furnished under a license and may be used
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    33
 only in accordance with the terms of that license and with the
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    34
 inclusion of the above copyright notice.   This software may not
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    35
 be provided or otherwise made available to, or used by, any
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    36
 other person.  No title to or ownership of the software is
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    37
 hereby transferred.
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    38
"
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    39
!
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    40
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    41
documentation
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    42
"
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    43
    node for parse-trees, representing literal constants
261
0372e948ca2d commentary
Claus Gittinger <cg@exept.de>
parents: 242
diff changeset
    44
    This is a helper class for the compiler.
263
3b21d0991eff documentation
Claus Gittinger <cg@exept.de>
parents: 261
diff changeset
    45
3b21d0991eff documentation
Claus Gittinger <cg@exept.de>
parents: 261
diff changeset
    46
    [author:]
3b21d0991eff documentation
Claus Gittinger <cg@exept.de>
parents: 261
diff changeset
    47
        Claus Gittinger
20
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    48
"
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    49
! !
7ad01559b262 Initial revision
claus
parents:
diff changeset
    50
7ad01559b262 Initial revision
claus
parents:
diff changeset
    51
!ConstantNode class methodsFor:'instance creation'!
7ad01559b262 Initial revision
claus
parents:
diff changeset
    52
7ad01559b262 Initial revision
claus
parents:
diff changeset
    53
type:t value:val
2608
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
    54
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
    55
    "/JV@2011-07-19: Changed not to share the nodes
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
    56
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    57
    ^ (self basicNew) type:t value:val
2608
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
    58
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
    59
"/    Old code    
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
    60
"/    "some constant nodes are used so often, its worth caching them"
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
    61
"/
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
    62
"/    (t == #True) ifTrue:[
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
    63
"/        TrueNode isNil ifTrue:[
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
    64
"/            TrueNode := (self basicNew) type:t value:val
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
    65
"/        ].
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
    66
"/        ^ TrueNode
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
    67
"/    ].
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
    68
"/    (t == #False) ifTrue:[
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
    69
"/        FalseNode isNil ifTrue:[
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
    70
"/            FalseNode := (self basicNew) type:t value:val
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
    71
"/        ].
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
    72
"/        ^ FalseNode
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
    73
"/    ].
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
    74
"/    (t == #Nil) ifTrue:[
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
    75
"/        NilNode isNil ifTrue:[
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
    76
"/            NilNode := (self basicNew) type:t value:val
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
    77
"/        ].
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
    78
"/        ^ NilNode
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
    79
"/    ].
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
    80
"/    (t == #Integer) ifTrue:[
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
    81
"/        (val == 0) ifTrue:[
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
    82
"/            Const0Node isNil ifTrue:[
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
    83
"/                Const0Node := (self basicNew) type:t value:val
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
    84
"/            ].
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
    85
"/            ^ Const0Node
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
    86
"/        ].
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
    87
"/        (val == 1) ifTrue:[
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
    88
"/            Const1Node isNil ifTrue:[
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
    89
"/                Const1Node := (self basicNew) type:t value:val
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
    90
"/            ].
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
    91
"/            ^ Const1Node
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
    92
"/        ]
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
    93
"/    ].
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
    94
"/    (t == #Float) ifTrue:[
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
    95
"/        (val = 0.0) ifTrue:[
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
    96
"/            "/ care for negative0 (which compares = to 0.0)
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
    97
"/            val isNegativeZero ifFalse:[
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
    98
"/                Float0Node isNil ifTrue:[
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
    99
"/                    Float0Node := (self basicNew) type:t value:val
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
   100
"/                ].
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
   101
"/                ^ Float0Node
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
   102
"/            ]
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
   103
"/        ]
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
   104
"/    ].
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
   105
"/    ^ (self basicNew) type:t value:val
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
   106
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
   107
    "Modified: / 19-07-2011 / 17:24:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   108
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   109
4351
bdd0b93eca81 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4278
diff changeset
   110
type:t value:val from:startPos to:endPos
2566
a39e9ce2610f - parse tree nodes are no longer shared
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2500
diff changeset
   111
4351
bdd0b93eca81 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4278
diff changeset
   112
    ^ (self basicNew)
bdd0b93eca81 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4278
diff changeset
   113
        type:t value:val;
bdd0b93eca81 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4278
diff changeset
   114
        startPosition:startPos endPosition:endPos;
2566
a39e9ce2610f - parse tree nodes are no longer shared
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2500
diff changeset
   115
        yourself
a39e9ce2610f - parse tree nodes are no longer shared
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2500
diff changeset
   116
a39e9ce2610f - parse tree nodes are no longer shared
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2500
diff changeset
   117
    "Created: / 19-07-2011 / 17:50:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
4351
bdd0b93eca81 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4278
diff changeset
   118
    "Modified (format): / 15-02-2019 / 14:50:59 / Claus Gittinger"
2566
a39e9ce2610f - parse tree nodes are no longer shared
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2500
diff changeset
   119
!
a39e9ce2610f - parse tree nodes are no longer shared
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2500
diff changeset
   120
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   121
value:val
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   122
    ^ self type:(self typeOfConstant:val) value:val 
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   123
! !
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
!ConstantNode class methodsFor:'queries'!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   126
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   127
typeOfConstant:anObject
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   128
    "return the constantNode type for an object"
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
    "the most common case first ..."
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   131
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   132
    (anObject isMemberOf:SmallInteger) ifTrue:[
1381
695fa03a5795 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1348
diff changeset
   133
        ^ #Integer
140
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
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   136
    anObject isNil ifTrue:[
1381
695fa03a5795 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1348
diff changeset
   137
        ^ #Nil
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   138
    ].
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
    anObject isNumber ifTrue:[
1381
695fa03a5795 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1348
diff changeset
   141
        "the most common case first ..."
695fa03a5795 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1348
diff changeset
   142
        (anObject isMemberOf:Float) ifTrue:[
695fa03a5795 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1348
diff changeset
   143
            ^ #Float
695fa03a5795 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1348
diff changeset
   144
        ].
695fa03a5795 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1348
diff changeset
   145
        anObject isInteger ifTrue:[
695fa03a5795 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1348
diff changeset
   146
            ^ #Integer
695fa03a5795 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1348
diff changeset
   147
        ].
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   148
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   149
    (anObject == true) ifTrue:[
1381
695fa03a5795 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1348
diff changeset
   150
        ^ #True
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   151
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   152
    (anObject == false) ifTrue:[
1381
695fa03a5795 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1348
diff changeset
   153
        ^ #False
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   154
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   155
    ^ #Literal
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   156
! !
7ad01559b262 Initial revision
claus
parents:
diff changeset
   157
4473
ebf6d10fe12f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4351
diff changeset
   158
!ConstantNode methodsFor:'RBParser compatibility'!
ebf6d10fe12f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4351
diff changeset
   159
ebf6d10fe12f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4351
diff changeset
   160
token
ebf6d10fe12f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4351
diff changeset
   161
    "for RB compatibility, I implement some of its protocol"
ebf6d10fe12f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4351
diff changeset
   162
ebf6d10fe12f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4351
diff changeset
   163
    ^ self
ebf6d10fe12f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4351
diff changeset
   164
! !
ebf6d10fe12f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4351
diff changeset
   165
13
30e69e21d1d1 *** empty log message ***
claus
parents: 10
diff changeset
   166
!ConstantNode methodsFor:'accessing'!
30e69e21d1d1 *** empty log message ***
claus
parents: 10
diff changeset
   167
711
25b9a501b97d lineNr -> lineNumber
Claus Gittinger <cg@exept.de>
parents: 710
diff changeset
   168
lineNumber:ignoredLineNumber
710
fc74f135494d ignore lineNumber assignment
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
   169
711
25b9a501b97d lineNr -> lineNumber
Claus Gittinger <cg@exept.de>
parents: 710
diff changeset
   170
    "Created: / 14.5.1998 / 19:31:48 / cg"
4351
bdd0b93eca81 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4278
diff changeset
   171
!
bdd0b93eca81 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4278
diff changeset
   172
bdd0b93eca81 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4278
diff changeset
   173
originalString
bdd0b93eca81 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4278
diff changeset
   174
    ^ originalString
bdd0b93eca81 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4278
diff changeset
   175
!
bdd0b93eca81 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4278
diff changeset
   176
bdd0b93eca81 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4278
diff changeset
   177
originalString:aString
bdd0b93eca81 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4278
diff changeset
   178
    "to remember the original string from scanning
bdd0b93eca81 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4278
diff changeset
   179
     (in case of a radix-number or a c-string)"
bdd0b93eca81 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4278
diff changeset
   180
     
bdd0b93eca81 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4278
diff changeset
   181
    originalString := aString.
bdd0b93eca81 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4278
diff changeset
   182
bdd0b93eca81 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4278
diff changeset
   183
    "Modified (comment): / 15-02-2019 / 14:35:50 / Claus Gittinger"
4511
3649ce5c5127 #OTHER by exept
Claus Gittinger <cg@exept.de>
parents: 4473
diff changeset
   184
!
3649ce5c5127 #OTHER by exept
Claus Gittinger <cg@exept.de>
parents: 4473
diff changeset
   185
3649ce5c5127 #OTHER by exept
Claus Gittinger <cg@exept.de>
parents: 4473
diff changeset
   186
radix
4602
b422ca3ad101 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4588
diff changeset
   187
    "the constant's original radix;
b422ca3ad101 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4588
diff changeset
   188
     remembered so that we can prettyprint it later in the same radix"
b422ca3ad101 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4588
diff changeset
   189
4511
3649ce5c5127 #OTHER by exept
Claus Gittinger <cg@exept.de>
parents: 4473
diff changeset
   190
    value isInteger ifFalse:[
3649ce5c5127 #OTHER by exept
Claus Gittinger <cg@exept.de>
parents: 4473
diff changeset
   191
        self error.
3649ce5c5127 #OTHER by exept
Claus Gittinger <cg@exept.de>
parents: 4473
diff changeset
   192
        ^ nil.
3649ce5c5127 #OTHER by exept
Claus Gittinger <cg@exept.de>
parents: 4473
diff changeset
   193
    ].
3649ce5c5127 #OTHER by exept
Claus Gittinger <cg@exept.de>
parents: 4473
diff changeset
   194
    originalString isNil ifTrue:[
3649ce5c5127 #OTHER by exept
Claus Gittinger <cg@exept.de>
parents: 4473
diff changeset
   195
        ^ 10
3649ce5c5127 #OTHER by exept
Claus Gittinger <cg@exept.de>
parents: 4473
diff changeset
   196
    ].
3649ce5c5127 #OTHER by exept
Claus Gittinger <cg@exept.de>
parents: 4473
diff changeset
   197
    originalString size < 2 ifTrue:[^ 10].
3649ce5c5127 #OTHER by exept
Claus Gittinger <cg@exept.de>
parents: 4473
diff changeset
   198
    (originalString at:2) == $r ifTrue:[
3649ce5c5127 #OTHER by exept
Claus Gittinger <cg@exept.de>
parents: 4473
diff changeset
   199
        ^ Integer readFrom:originalString readStream.
3649ce5c5127 #OTHER by exept
Claus Gittinger <cg@exept.de>
parents: 4473
diff changeset
   200
    ].
3649ce5c5127 #OTHER by exept
Claus Gittinger <cg@exept.de>
parents: 4473
diff changeset
   201
    originalString size < 3 ifTrue:[^ 10].
3649ce5c5127 #OTHER by exept
Claus Gittinger <cg@exept.de>
parents: 4473
diff changeset
   202
    (originalString at:3) == $r ifTrue:[
3649ce5c5127 #OTHER by exept
Claus Gittinger <cg@exept.de>
parents: 4473
diff changeset
   203
        ^ Integer readFrom:originalString readStream.
3649ce5c5127 #OTHER by exept
Claus Gittinger <cg@exept.de>
parents: 4473
diff changeset
   204
    ].
3649ce5c5127 #OTHER by exept
Claus Gittinger <cg@exept.de>
parents: 4473
diff changeset
   205
    (originalString startsWith:'0x') ifTrue:[^ 16].
3649ce5c5127 #OTHER by exept
Claus Gittinger <cg@exept.de>
parents: 4473
diff changeset
   206
    (originalString startsWith:'0b') ifTrue:[^ 2].
3649ce5c5127 #OTHER by exept
Claus Gittinger <cg@exept.de>
parents: 4473
diff changeset
   207
    (originalString startsWith:'0o') ifTrue:[^ 8].
3649ce5c5127 #OTHER by exept
Claus Gittinger <cg@exept.de>
parents: 4473
diff changeset
   208
    ^ 10
13
30e69e21d1d1 *** empty log message ***
claus
parents: 10
diff changeset
   209
! !
30e69e21d1d1 *** empty log message ***
claus
parents: 10
diff changeset
   210
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   211
!ConstantNode methodsFor:'code generation'!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   212
1560
a3be357f8c4d symbolic literal constants are remeembered,
Claus Gittinger <cg@exept.de>
parents: 1552
diff changeset
   213
codeForSideEffectOn:aStream inBlock:b for:aCompiler
a3be357f8c4d symbolic literal constants are remeembered,
Claus Gittinger <cg@exept.de>
parents: 1552
diff changeset
   214
    "no code at all"
4588
f080c93ec4e8 #UI_ENHANCEMENT by exept
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   215
    |msg|
f080c93ec4e8 #UI_ENHANCEMENT by exept
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   216
f080c93ec4e8 #UI_ENHANCEMENT by exept
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   217
    msg := 'Useless constant reference'.
1560
a3be357f8c4d symbolic literal constants are remeembered,
Claus Gittinger <cg@exept.de>
parents: 1552
diff changeset
   218
1995
dad0adb22a38 comment
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
   219
    "/ but remember symbolic literals (such as #TODO)
1560
a3be357f8c4d symbolic literal constants are remeembered,
Claus Gittinger <cg@exept.de>
parents: 1552
diff changeset
   220
    value isSymbol ifTrue:[
a3be357f8c4d symbolic literal constants are remeembered,
Claus Gittinger <cg@exept.de>
parents: 1552
diff changeset
   221
        aCompiler addLiteral:value.
4588
f080c93ec4e8 #UI_ENHANCEMENT by exept
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   222
f080c93ec4e8 #UI_ENHANCEMENT by exept
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   223
        ((#fixme sameAs:value) or:[#todo sameAs:value]) ifTrue:[
f080c93ec4e8 #UI_ENHANCEMENT by exept
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   224
            msg := 'Reminder in code: ',value  
f080c93ec4e8 #UI_ENHANCEMENT by exept
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   225
        ].
1560
a3be357f8c4d symbolic literal constants are remeembered,
Claus Gittinger <cg@exept.de>
parents: 1552
diff changeset
   226
    ].
4547
3596e4bcee1b #UI_ENHANCEMENT by exept
Claus Gittinger <cg@exept.de>
parents: 4511
diff changeset
   227
4588
f080c93ec4e8 #UI_ENHANCEMENT by exept
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   228
    aCompiler warning:msg position:startPosition to:endPosition.    
1995
dad0adb22a38 comment
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
   229
dad0adb22a38 comment
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
   230
    "Modified: / 04-03-2007 / 15:29:54 / cg"
1560
a3be357f8c4d symbolic literal constants are remeembered,
Claus Gittinger <cg@exept.de>
parents: 1552
diff changeset
   231
!
a3be357f8c4d symbolic literal constants are remeembered,
Claus Gittinger <cg@exept.de>
parents: 1552
diff changeset
   232
843
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   233
codeForSimpleReturnOn:aStream inBlock:b lineNumber:lineNrOrNil for:aCompiler
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   234
    lineNrOrNil notNil ifTrue:[
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   235
        self codeLineNumber:lineNrOrNil on:aStream for:aCompiler
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   236
    ].
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   237
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   238
    (type == #Nil) ifTrue:[
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   239
        aStream nextPut:#retNil.
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   240
        ^self
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   241
    ].
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   242
    (type == #True) ifTrue:[
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   243
        aStream nextPut:#retTrue.
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   244
        ^self
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   245
    ].
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   246
    (type == #False) ifTrue:[
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   247
        aStream nextPut:#retFalse.
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   248
        ^self
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   249
    ].
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   250
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   251
    (type == #Integer) ifTrue:[
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   252
        (value between: -128 and:127) ifTrue:[
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   253
            (value == 0) ifTrue:[
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   254
                aStream nextPut:#ret0.
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   255
                ^ self.
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   256
            ].
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   257
            aStream nextPut:#retNum; nextPut:value.
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   258
            ^ self
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   259
        ].
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   260
    ].
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   261
1401
d9a2949c6229 Fix typos
Stefan Vogel <sv@exept.de>
parents: 1384
diff changeset
   262
    "/ anything else must be pushed, then top returned
843
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   263
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   264
    self codeOn:aStream inBlock:b for:aCompiler.
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   265
    aStream nextPut:#retTop
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   266
!
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   267
104
claus
parents: 103
diff changeset
   268
codeOn:aStream inBlock:b for:aCompiler
843
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   269
    "generate code for the constant"
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   270
104
claus
parents: 103
diff changeset
   271
    |code index|
96
claus
parents: 62
diff changeset
   272
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   273
    (type == #Integer) ifTrue:[
843
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   274
        (value between: -128 and:127) ifTrue:[
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   275
            (value == 0) ifTrue:[
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   276
                code := #push0
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   277
            ].
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   278
            (value == 1) ifTrue:[
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   279
                code := #push1.
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   280
            ].
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   281
            (value == 2) ifTrue:[
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   282
                code := #push2.
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   283
            ].
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   284
            (value == -1) ifTrue:[
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   285
                code := #pushMinus1.
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   286
            ].
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   287
            code notNil ifTrue:[
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   288
                aStream nextPut:code. ^ self
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   289
            ].
96
claus
parents: 62
diff changeset
   290
843
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   291
            aStream nextPut:#pushNum; nextPut:value.
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   292
            ^ self
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   293
        ].
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   294
        (value between:16r-8000 and:16r7FFF) ifTrue:[
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   295
            aStream nextPut:#pushNum16; nextPut:value; nextPut:0. 
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   296
            ^ self
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   297
        ]
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   298
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   299
    (type == #Nil) ifTrue:[
843
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   300
        code := #pushNil.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   301
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   302
    (type == #True) ifTrue:[
843
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   303
        code := #pushTrue.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   304
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   305
    (type == #False) ifTrue:[
843
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   306
        code := #pushFalse.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   307
    ].
96
claus
parents: 62
diff changeset
   308
    code notNil ifTrue:[
843
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   309
        aStream nextPut:code. ^ self
96
claus
parents: 62
diff changeset
   310
    ].
106
claus
parents: 104
diff changeset
   311
claus
parents: 104
diff changeset
   312
    "/ kludge for backward compatibility
claus
parents: 104
diff changeset
   313
    aCompiler isNil ifTrue:[
2118
Claus Gittinger <cg@exept.de>
parents: 1995
diff changeset
   314
        self halt:'strange literal constant'.
843
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   315
        aStream nextPut:#pushLit; nextPut:value.
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   316
        ^ self.
106
claus
parents: 104
diff changeset
   317
    ].
claus
parents: 104
diff changeset
   318
1805
d8f8075615dc some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   319
    self emitPushLiteral:value on:aStream for:aCompiler
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   320
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   321
104
claus
parents: 103
diff changeset
   322
codeStoreOn:aStream inBlock:codeBlock valueNeeded:valueNeeded for:aCompiler
13
30e69e21d1d1 *** empty log message ***
claus
parents: 10
diff changeset
   323
    "not sent - parser checks for this"
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   324
7ad01559b262 Initial revision
claus
parents:
diff changeset
   325
    ^ self error:'assignment to literals not allowed'
7ad01559b262 Initial revision
claus
parents:
diff changeset
   326
! !
7ad01559b262 Initial revision
claus
parents:
diff changeset
   327
1035
8848672cb893 category rename
Claus Gittinger <cg@exept.de>
parents: 843
diff changeset
   328
!ConstantNode methodsFor:'enumerating'!
539
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   329
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   330
nodeDo:anEnumerator
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   331
    "helper for parse tree walking"
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   332
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   333
    ^ anEnumerator doLiteral:self value:value
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   334
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   335
    "Modified: 19.6.1997 / 16:40:59 / cg"
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   336
! !
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   337
1035
8848672cb893 category rename
Claus Gittinger <cg@exept.de>
parents: 843
diff changeset
   338
!ConstantNode methodsFor:'evaluation'!
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   339
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   340
evaluate
1384
0db9682870d9 evaluate -> evaluateIn:
Claus Gittinger <cg@exept.de>
parents: 1381
diff changeset
   341
    "exists for performance only"
0db9682870d9 evaluate -> evaluateIn:
Claus Gittinger <cg@exept.de>
parents: 1381
diff changeset
   342
    ^ value
0db9682870d9 evaluate -> evaluateIn:
Claus Gittinger <cg@exept.de>
parents: 1381
diff changeset
   343
!
0db9682870d9 evaluate -> evaluateIn:
Claus Gittinger <cg@exept.de>
parents: 1381
diff changeset
   344
0db9682870d9 evaluate -> evaluateIn:
Claus Gittinger <cg@exept.de>
parents: 1381
diff changeset
   345
evaluateIn:anEnvironment
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   346
    ^ value
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   347
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   348
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   349
store:aValue
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   350
    "not reached - parser checks for this"
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   351
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   352
    self error:'store not allowed'.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   353
    ^ aValue
3811
ebeffc3fcf61 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 3503
diff changeset
   354
!
ebeffc3fcf61 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 3503
diff changeset
   355
ebeffc3fcf61 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 3503
diff changeset
   356
value
ebeffc3fcf61 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 3503
diff changeset
   357
    "for compatibility with RB-AST"
ebeffc3fcf61 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 3503
diff changeset
   358
    ^ value
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   359
! !
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   360
1080
bd3f19f6009a category change
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   361
!ConstantNode methodsFor:'printing & storing'!
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   362
2895
fe7143fbfdbe Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents: 2616
diff changeset
   363
displayOn:aGCOrStream
fe7143fbfdbe Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents: 2616
diff changeset
   364
    "Compatibility
fe7143fbfdbe Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents: 2616
diff changeset
   365
     append a printed desription on some stream (Dolphin,  Squeak)
fe7143fbfdbe Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents: 2616
diff changeset
   366
     OR:
fe7143fbfdbe Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents: 2616
diff changeset
   367
     display the receiver in a graphicsContext at 0@0 (ST80).
fe7143fbfdbe Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents: 2616
diff changeset
   368
     This method allows for any object to be displayed in some view
fe7143fbfdbe Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents: 2616
diff changeset
   369
     (although the fallBack is to display its printString ...)"
612
2748896a66c8 comments
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
   370
2895
fe7143fbfdbe Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents: 2616
diff changeset
   371
    "/ what a kludge - Dolphin and Squeak mean: printOn: a stream;
4132
87074db8370f #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 3811
diff changeset
   372
    "/ old ST80 means: draw-yourself on a GC.
2895
fe7143fbfdbe Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents: 2616
diff changeset
   373
    aGCOrStream isStream ifFalse:[
fe7143fbfdbe Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents: 2616
diff changeset
   374
        ^ super displayOn:aGCOrStream.
fe7143fbfdbe Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents: 2616
diff changeset
   375
    ].
612
2748896a66c8 comments
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
   376
4132
87074db8370f #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 3811
diff changeset
   377
    value displayOn:aGCOrStream.
87074db8370f #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 3811
diff changeset
   378
87074db8370f #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 3811
diff changeset
   379
    "Modified (comment): / 22-02-2017 / 16:50:02 / cg"
13
30e69e21d1d1 *** empty log message ***
claus
parents: 10
diff changeset
   380
!
30e69e21d1d1 *** empty log message ***
claus
parents: 10
diff changeset
   381
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   382
printOn:aStream indent:i
4351
bdd0b93eca81 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4278
diff changeset
   383
    originalString notNil ifTrue:[
bdd0b93eca81 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4278
diff changeset
   384
        aStream nextPutAll:originalString.
bdd0b93eca81 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4278
diff changeset
   385
        ^ self.
bdd0b93eca81 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4278
diff changeset
   386
    ].    
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   387
    value storeOn:aStream
4351
bdd0b93eca81 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4278
diff changeset
   388
bdd0b93eca81 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4278
diff changeset
   389
    "Modified: / 15-02-2019 / 14:37:33 / Claus Gittinger"
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   390
! !
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   391
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   392
!ConstantNode methodsFor:'queries'!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   393
242
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   394
canReuseAsArg:anotherNode
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   395
    |otherValue|
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   396
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   397
    anotherNode isConstant ifTrue:[
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   398
        anotherNode type ~~ type ifTrue:[^ false].
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   399
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   400
        otherValue := anotherNode evaluate.
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   401
        (value isMemberOf:SmallInteger) ifTrue:[
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   402
            (value == 0) ifTrue:[^ false].
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   403
            (value == 1) ifTrue:[^ false].
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   404
            (value == 2) ifTrue:[^ false].
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   405
            (value == -1) ifTrue:[^ false].
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   406
            ^ otherValue == value
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   407
        ].
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   408
        (value isMemberOf:Float) ifTrue:[
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   409
            ^ (otherValue isMemberOf:Float)
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   410
              and:[otherValue = value]
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   411
        ].
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   412
        (value isMemberOf:Symbol) ifTrue:[
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   413
            ^ otherValue == value
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   414
        ].
3503
53d41ce411e1 class: ConstantNode
Claus Gittinger <cg@exept.de>
parents: 3246
diff changeset
   415
        (value isSingleByteString) ifTrue:[
53d41ce411e1 class: ConstantNode
Claus Gittinger <cg@exept.de>
parents: 3246
diff changeset
   416
            ^ (otherValue isSingleByteString)
242
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   417
              and:[otherValue = value]
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   418
        ].
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   419
    ].
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   420
    ^ false
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   421
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   422
    "Created: 14.4.1996 / 00:43:14 / cg"
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   423
    "Modified: 14.4.1996 / 01:00:29 / cg"
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   424
!
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   425
2266
Claus Gittinger <cg@exept.de>
parents: 2118
diff changeset
   426
withConstantValueDo:aBlock
Claus Gittinger <cg@exept.de>
parents: 2118
diff changeset
   427
    "return true, if this evaluates to a constant value
Claus Gittinger <cg@exept.de>
parents: 2118
diff changeset
   428
     and evaluate aBlock with it"
Claus Gittinger <cg@exept.de>
parents: 2118
diff changeset
   429
Claus Gittinger <cg@exept.de>
parents: 2118
diff changeset
   430
    aBlock value:value.
Claus Gittinger <cg@exept.de>
parents: 2118
diff changeset
   431
    ^ true
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   432
! !
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   433
2320
4e58d12c5c1a category change
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
   434
!ConstantNode methodsFor:'testing'!
4e58d12c5c1a category change
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
   435
4e58d12c5c1a category change
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
   436
isConstant
4e58d12c5c1a category change
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
   437
    ^ true
4278
d756ed6a7120 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
   438
!
d756ed6a7120 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
   439
d756ed6a7120 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
   440
isConstantNumber
d756ed6a7120 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
   441
    ^ value isNumber
d756ed6a7120 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
   442
d756ed6a7120 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
   443
    "Created: / 16-06-2018 / 08:46:53 / Claus Gittinger"
4473
ebf6d10fe12f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4351
diff changeset
   444
!
ebf6d10fe12f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4351
diff changeset
   445
ebf6d10fe12f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4351
diff changeset
   446
isLiteralArray
ebf6d10fe12f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4351
diff changeset
   447
    ^ value isArray
ebf6d10fe12f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4351
diff changeset
   448
ebf6d10fe12f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4351
diff changeset
   449
    "Created: / 16-06-2018 / 08:46:53 / Claus Gittinger"
ebf6d10fe12f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4351
diff changeset
   450
!
ebf6d10fe12f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4351
diff changeset
   451
ebf6d10fe12f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4351
diff changeset
   452
isLiteralCString
ebf6d10fe12f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4351
diff changeset
   453
    ^ value isString and:[originalString notNil and:[originalString startsWith:'c''']]
ebf6d10fe12f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4351
diff changeset
   454
ebf6d10fe12f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4351
diff changeset
   455
    "Created: / 16-06-2018 / 08:46:53 / Claus Gittinger"
2320
4e58d12c5c1a category change
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
   456
! !
4e58d12c5c1a category change
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
   457
2608
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
   458
!ConstantNode methodsFor:'visiting'!
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
   459
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
   460
acceptVisitor:aVisitor 
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
   461
    "Double dispatch back to the visitor, passing my type encoded in
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
   462
     the selector (visitor pattern)"
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
   463
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
   464
    "stub code automatically generated - please change if required"
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
   465
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
   466
    ^ aVisitor visitConstantNode:self
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
   467
! !
02cf4816ae5e - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2566
diff changeset
   468
148
ef0e604209ec version method at the end
Claus Gittinger <cg@exept.de>
parents: 140
diff changeset
   469
!ConstantNode class methodsFor:'documentation'!
ef0e604209ec version method at the end
Claus Gittinger <cg@exept.de>
parents: 140
diff changeset
   470
2500
3178ecc11a5e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2320
diff changeset
   471
version_CVS
3811
ebeffc3fcf61 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 3503
diff changeset
   472
    ^ '$Header$'
2266
Claus Gittinger <cg@exept.de>
parents: 2118
diff changeset
   473
!
Claus Gittinger <cg@exept.de>
parents: 2118
diff changeset
   474
2500
3178ecc11a5e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2320
diff changeset
   475
version_SVN
3246
d0c8d1d6bad7 class: ConstantNode
Claus Gittinger <cg@exept.de>
parents: 2895
diff changeset
   476
    ^ '$ Id $'
148
ef0e604209ec version method at the end
Claus Gittinger <cg@exept.de>
parents: 140
diff changeset
   477
! !
3246
d0c8d1d6bad7 class: ConstantNode
Claus Gittinger <cg@exept.de>
parents: 2895
diff changeset
   478