]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/constants/ShortConstant.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / constants / ShortConstant.java
1 package org.simantics.scl.compiler.constants;
2
3 import org.cojen.classfile.TypeDesc;
4 import org.objectweb.asm.Label;
5 import org.simantics.scl.compiler.internal.codegen.continuations.Cont;
6 import org.simantics.scl.compiler.internal.codegen.references.IVal;
7 import org.simantics.scl.compiler.internal.codegen.utils.MethodBuilder;
8 import org.simantics.scl.compiler.internal.codegen.utils.TransientClassBuilder;
9 import org.simantics.scl.compiler.types.Types;
10
11 public class ShortConstant extends Constant {
12     public static final ShortConstant ZERO = new ShortConstant((short)0);
13     public static final ShortConstant ONE = new ShortConstant((short)1);
14     public static final ShortConstant MINUS_ONE = new ShortConstant((short)-1);
15     
16     short value;
17
18     public ShortConstant(short value) {
19         super(Types.SHORT);
20         this.value = value;
21     }
22     
23     @Override
24     public void push(MethodBuilder mb) {
25         mb.loadConstant(value);
26     }
27     
28     @Override
29     public String toString() {
30         return String.valueOf(value);
31     }
32     
33     public short getValue() {
34         return value;
35     }
36
37     @Override
38     public int hashCode() {
39         return value;
40     }
41
42     @Override
43     public boolean equals(Object obj) {
44         if (this == obj)
45             return true;
46         if (obj == null)
47             return false;
48         if (getClass() != obj.getClass())
49             return false;
50         ShortConstant other = (ShortConstant) obj;
51         if (value != other.value)
52             return false;
53         return true;
54     }
55     
56     @Override
57     public void deconstruct(MethodBuilder mb, IVal parameter, Cont success,
58             Label failure) {
59         mb.push(parameter, Types.SHORT);
60         mb.loadConstant(value);
61         mb.ifComparisonBranch(failure, "!=", TypeDesc.SHORT);
62         mb.jump(success);
63     }
64     
65     public int constructorTag() {
66         return 0;
67     }
68
69     @Override
70     public Object realizeValue(TransientClassBuilder classBuilder) {
71         return value;
72     }
73 }