Mercurial > hg > graal-compiler
comparison graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/ArithmeticNode.java @ 8247:5b08b0f4d338
Updated some Truffle-SL classes to new naming convention.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Wed, 06 Mar 2013 18:33:52 +0100 |
parents | d81ff782fa1a |
children | ac2204c05a02 |
comparison
equal
deleted
inserted
replaced
8246:3862508afe2f | 8247:5b08b0f4d338 |
---|---|
35 | 35 |
36 protected ArithmeticNode(ArithmeticNode node) { | 36 protected ArithmeticNode(ArithmeticNode node) { |
37 super(node); | 37 super(node); |
38 } | 38 } |
39 | 39 |
40 @Generic | |
41 public Object doGeneric(Object left, Object right) { | |
42 throw new RuntimeException("Arithmetic not defined for types " + left.getClass().getSimpleName() + ", " + right.getClass().getSimpleName()); | |
43 } | |
44 | |
45 public abstract static class AddNode extends ArithmeticNode { | 40 public abstract static class AddNode extends ArithmeticNode { |
46 | 41 |
47 public AddNode(TypedNode left, TypedNode right) { | 42 public AddNode(TypedNode left, TypedNode right) { |
48 super(left, right); | 43 super(left, right); |
49 } | 44 } |
51 protected AddNode(AddNode node) { | 46 protected AddNode(AddNode node) { |
52 super(node); | 47 super(node); |
53 } | 48 } |
54 | 49 |
55 @Specialization(rewriteOn = ArithmeticException.class) | 50 @Specialization(rewriteOn = ArithmeticException.class) |
56 int doInteger(int left, int right) { | 51 int doInt(int left, int right) { |
57 return ExactMath.addExact(left, right); | 52 return ExactMath.addExact(left, right); |
58 } | 53 } |
59 | 54 |
60 @Specialization | 55 @Specialization |
61 BigInteger doBigInteger(BigInteger left, BigInteger right) { | 56 BigInteger doBigInteger(BigInteger left, BigInteger right) { |
62 return left.add(right); | 57 return left.add(right); |
63 } | 58 } |
64 | 59 |
65 @Specialization | 60 @Specialization |
66 String doStringDirect(String left, String right) { | 61 String doString(String left, String right) { |
67 return left + right; | 62 return left + right; |
68 } | 63 } |
69 | 64 |
70 @Specialization(guards = "isString") | 65 @Specialization(guards = "isString") |
71 String doString(Object left, Object right) { | 66 String add(Object left, Object right) { |
72 return left.toString() + right.toString(); | 67 return left.toString() + right.toString(); |
68 } | |
69 | |
70 @Generic | |
71 public Object addGeneric(Object left, Object right) { | |
72 throw new RuntimeException("Arithmetic not defined for types " + left.getClass().getSimpleName() + ", " + right.getClass().getSimpleName()); | |
73 } | 73 } |
74 } | 74 } |
75 | 75 |
76 public abstract static class SubNode extends ArithmeticNode { | 76 public abstract static class SubNode extends ArithmeticNode { |
77 | 77 |
82 protected SubNode(SubNode node) { | 82 protected SubNode(SubNode node) { |
83 super(node); | 83 super(node); |
84 } | 84 } |
85 | 85 |
86 @Specialization(rewriteOn = ArithmeticException.class) | 86 @Specialization(rewriteOn = ArithmeticException.class) |
87 int doInteger(int left, int right) { | 87 int sub(int left, int right) { |
88 return ExactMath.subtractExact(left, right); | 88 return ExactMath.subtractExact(left, right); |
89 } | 89 } |
90 | 90 |
91 @Specialization | 91 @Specialization |
92 BigInteger doBigInteger(BigInteger left, BigInteger right) { | 92 BigInteger sub(BigInteger left, BigInteger right) { |
93 return left.subtract(right); | 93 return left.subtract(right); |
94 } | |
95 | |
96 @Generic | |
97 public Object sub(Object left, Object right) { | |
98 throw new RuntimeException("Arithmetic not defined for types " + left.getClass().getSimpleName() + ", " + right.getClass().getSimpleName()); | |
94 } | 99 } |
95 } | 100 } |
96 | 101 |
97 public abstract static class DivNode extends ArithmeticNode { | 102 public abstract static class DivNode extends ArithmeticNode { |
98 | 103 |
103 protected DivNode(DivNode node) { | 108 protected DivNode(DivNode node) { |
104 super(node); | 109 super(node); |
105 } | 110 } |
106 | 111 |
107 @Specialization(rewriteOn = ArithmeticException.class) | 112 @Specialization(rewriteOn = ArithmeticException.class) |
108 int doInteger(int left, int right) { | 113 int div(int left, int right) { |
109 return left / right; | 114 return left / right; |
110 } | 115 } |
111 | 116 |
112 @Specialization | 117 @Specialization |
113 BigInteger doBigInteger(BigInteger left, BigInteger right) { | 118 BigInteger div(BigInteger left, BigInteger right) { |
114 return left.divide(right); | 119 return left.divide(right); |
120 } | |
121 | |
122 @Generic | |
123 public Object div(Object left, Object right) { | |
124 throw new RuntimeException("Arithmetic not defined for types " + left.getClass().getSimpleName() + ", " + right.getClass().getSimpleName()); | |
115 } | 125 } |
116 } | 126 } |
117 | 127 |
118 public abstract static class MulNode extends ArithmeticNode { | 128 public abstract static class MulNode extends ArithmeticNode { |
119 | 129 |
124 protected MulNode(MulNode node) { | 134 protected MulNode(MulNode node) { |
125 super(node); | 135 super(node); |
126 } | 136 } |
127 | 137 |
128 @Specialization(rewriteOn = ArithmeticException.class) | 138 @Specialization(rewriteOn = ArithmeticException.class) |
129 int doInteger(int left, int right) { | 139 int mul(int left, int right) { |
130 return ExactMath.multiplyExact(left, right); | 140 return ExactMath.multiplyExact(left, right); |
131 } | 141 } |
132 | 142 |
133 @Specialization | 143 @Specialization |
134 BigInteger doBigInteger(BigInteger left, BigInteger right) { | 144 BigInteger mul(BigInteger left, BigInteger right) { |
135 return left.multiply(right); | 145 return left.multiply(right); |
146 } | |
147 | |
148 @Generic | |
149 public Object mul(Object left, Object right) { | |
150 throw new RuntimeException("Arithmetic not defined for types " + left.getClass().getSimpleName() + ", " + right.getClass().getSimpleName()); | |
136 } | 151 } |
137 } | 152 } |
138 | 153 |
139 } | 154 } |