summaryrefslogtreecommitdiff
path: root/sources/scalac/backend/Primitive.java
blob: e2c51289f7152ea83698147dd83713a7a6320fb4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*     ____ ____  ____ ____  ______                                     *\
**    / __// __ \/ __// __ \/ ____/    SOcos COmpiles Scala             **
**  __\_ \/ /_/ / /__/ /_/ /\_ \       (c) 2002, LAMP/EPFL              **
** /_____/\____/\___/\____/____/                                        **
\*                                                                      */

// Old$Id$
// $Id$

package scalac.backend;

import scalac.util.Debug;

/**
 * Primitive functions.
 *
 * @author Michel Schinz, Philippe Altherr
 * @version 1.0
 */

public class Primitive {
    public int tag;

    // Non-primitive operations
    public case NOT_A_PRIMITIVE { tag =  0; } // not a primitive

    // Arithmetic unary operations
    public case POS             { tag =  1; } // +x
    public case NEG             { tag =  2; } // -x
    public case NOT             { tag =  3; } // ~x

    // Arithmetic binary operations
    public case ADD             { tag =  4; } // x + y
    public case SUB             { tag =  5; } // x - y
    public case MUL             { tag =  6; } // x * y
    public case DIV             { tag =  7; } // x / y
    public case MOD             { tag =  8; } // x % y

    // Bitwise operations
    public case OR              { tag =  9; } // x | y
    public case XOR             { tag = 10; } // x ^ y
    public case AND             { tag = 11; } // x & y

    // Shift operations
    public case LSL             { tag = 12; } // x << y
    public case LSR             { tag = 13; } // x >>> y
    public case ASR             { tag = 14; } // x >> y

    // Comparison operations
    public case EQ              { tag = 15; } // x == y
    public case NE              { tag = 16; } // x != y
    public case LT              { tag = 17; } // x < y
    public case LE              { tag = 18; } // x <= y
    public case GE              { tag = 19; } // x > y
    public case GT              { tag = 20; } // x >= y

    // Boolean unary operations
    public case ZNOT            { tag = 21; } // !x

    // Boolean binary operations
    public case ZOR             { tag = 22; } // x || y
    public case ZAND            { tag = 23; } // x && y

    // Array operations
    public case LENGTH          { tag = 24; } // x.length
    public case APPLY           { tag = 25; } // x(y)
    public case UPDATE          { tag = 26; } // x(y) = z

    // Conversion operations
    public case AS_UVALUE       { tag = 27; } // x.asUnit()
    public case AS_ZVALUE       { tag = 28; } // x.asBoolean()
    public case AS_BVALUE       { tag = 29; } // x.asByte()
    public case AS_SVALUE       { tag = 30; } // x.asShort()
    public case AS_CVALUE       { tag = 31; } // x.asChar()
    public case AS_IVALUE       { tag = 32; } // x.asInt()
    public case AS_LVALUE       { tag = 33; } // x.asLong()
    public case AS_FVALUE       { tag = 34; } // x.asFloat()
    public case AS_DVALUE       { tag = 35; } // x.asDouble()
    public case AS_ZARRAY       { tag = 36; } // x.asBooleanArray()
    public case AS_BARRAY       { tag = 37; } // x.asByteArray()
    public case AS_SARRAY       { tag = 38; } // x.asShortArray()
    public case AS_CARRAY       { tag = 39; } // x.asCharArray()
    public case AS_IARRAY       { tag = 40; } // x.asIntArray()
    public case AS_LARRAY       { tag = 41; } // x.asLongArray()
    public case AS_FARRAY       { tag = 42; } // x.asFloatArray()
    public case AS_DARRAY       { tag = 43; } // x.asDoubleArray()
    public case AS_OARRAY       { tag = 44; } // x.asObjectArray()

    // Any operations
    public case IS              { tag = 45; } // x.is[y]
    public case AS              { tag = 46; } // x.as[y]
    public case EQUALS          { tag = 47; } // x.equals(y)
    public case HASHCODE        { tag = 48; } // x.hashcode()
    public case TOSTRING        { tag = 49; } // x.toString()

    // String operations
    public case CONCAT          { tag = 50; } // String.valueOf(x)+String.valueOf(y)

    // Throwable operations
    public case THROW           { tag = 51; } // throw x

    // RunTime operations
    public case BOX             { tag = 52; } // RunTime.box(x)
    public case NEW_ZARRAY      { tag = 53; } // RunTime.zarray(x)
    public case NEW_BARRAY      { tag = 54; } // RunTime.barray(x)
    public case NEW_SARRAY      { tag = 55; } // RunTime.sarray(x)
    public case NEW_CARRAY      { tag = 56; } // RunTime.carray(x)
    public case NEW_IARRAY      { tag = 57; } // RunTime.iarray(x)
    public case NEW_LARRAY      { tag = 58; } // RunTime.larray(x)
    public case NEW_FARRAY      { tag = 59; } // RunTime.farray(x)
    public case NEW_DARRAY      { tag = 60; } // RunTime.darray(x)
    public case NEW_OARRAY      { tag = 61; } // RunTime.oarray(x)
    public case ZARRAY_GET      { tag = 62; } // RunTime.zarray_get(x,y)
    public case BARRAY_GET      { tag = 63; } // RunTime.barray_get(x,y)
    public case SARRAY_GET      { tag = 64; } // RunTime.sarray_get(x,y)
    public case CARRAY_GET      { tag = 65; } // RunTime.carray_get(x,y)
    public case IARRAY_GET      { tag = 66; } // RunTime.iarray_get(x,y)
    public case LARRAY_GET      { tag = 67; } // RunTime.larray_get(x,y)
    public case FARRAY_GET      { tag = 68; } // RunTime.farray_get(x,y)
    public case DARRAY_GET      { tag = 69; } // RunTime.darray_get(x,y)
    public case OARRAY_GET      { tag = 70; } // RunTime.oarray_get(x,y)
    public case ZARRAY_SET      { tag = 71; } // RunTime.zarray(x,y,z)
    public case BARRAY_SET      { tag = 72; } // RunTime.barray(x,y,z)
    public case SARRAY_SET      { tag = 73; } // RunTime.sarray(x,y,z)
    public case CARRAY_SET      { tag = 74; } // RunTime.carray(x,y,z)
    public case IARRAY_SET      { tag = 75; } // RunTime.iarray(x,y,z)
    public case LARRAY_SET      { tag = 76; } // RunTime.larray(x,y,z)
    public case FARRAY_SET      { tag = 77; } // RunTime.farray(x,y,z)
    public case DARRAY_SET      { tag = 78; } // RunTime.darray(x,y,z)
    public case OARRAY_SET      { tag = 79; } // RunTime.oarray(x,y,z)

    /** Return negated version of comparison primitive. */
    public Primitive negate() {
        switch (this) {
        case LT: return Primitive.GE;
        case LE: return Primitive.GT;
        case EQ: return Primitive.NE;
        case NE: return Primitive.EQ;
        case GE: return Primitive.LT;
        case GT: return Primitive.LE;
        default: throw Debug.abort("unknown primitive", this);
        }
    }

    /** Return primitive with arguments swapped (e.g. <= is turned
     ** into =>). */
    public Primitive swap() {
        switch (this) {
        case LT: return Primitive.GT;
        case LE: return Primitive.GE;
        case EQ: return Primitive.EQ;
        case NE: return Primitive.NE;
        case GE: return Primitive.LE;
        case GT: return Primitive.LT;
        default: throw Debug.abort("unknown primitive", this);
        }
    }
}