MCPcopy Create free account
hub / github.com/SeaOfNodes/Simple / compute

Method compute

chapter19/src/test/java/com/seaofnodes/simple/Eval2.java:250–286  ·  view source on GitHub ↗
( Node n )

Source from the content-addressed store, hash-verified

248
249 // From here down shamelessly copied from Evaluator, written by @Xmilia
250 private static Object compute( Node n ) {
251 return switch( n ) {
252 case AddFNode adf -> d(adf.in(1)) + d(adf.in(2));
253 case AddNode add -> x(add.in(1)) + x(add.in(2));
254 case AndNode and -> x(and.in(1)) & x(and.in(2));
255 case BoolNode.EQF eqf -> d(eqf.in(1)) == d(eqf.in(2)) ? 1L : 0L;
256 case BoolNode.LEF lef -> d(lef.in(1)) <= d(lef.in(2)) ? 1L : 0L;
257 case BoolNode.LTF ltf -> d(ltf.in(1)) < d(ltf.in(2)) ? 1L : 0L;
258 case BoolNode.EQ eq -> Objects.equals(val(eq.in(1)), val(eq.in(2))) ? 1L : 0L; // Bool EQ supports pointers, nil, and integers
259 case BoolNode.LE le -> x(le .in(1)) <= x(le .in(2)) ? 1L : 0L;
260 case BoolNode.LT lt -> x(lt .in(1)) < x(lt .in(2)) ? 1L : 0L;
261 case CastNode cast -> val(cast.in(1));
262 case ConstantNode con -> con(con._con);
263 case DivFNode dvf -> d(dvf.in(2))==0 ? 0D : d(dvf.in(1)) / d(dvf.in(2));
264 case DivNode div -> x(div.in(2))==0 ? 0L : x(div.in(1)) / x(div.in(2));
265 case LoadNode ld -> load(ld);
266 case MinusFNode mnf -> - d(mnf.in(1));
267 case MinusNode sub -> - x(sub.in(1));
268 case MulFNode mlf -> d(mlf.in(1)) * d(mlf.in(2));
269 case MulNode mul -> x(mul.in(1)) * x(mul.in(2));
270 case NewNode alloc-> alloc(alloc);
271 case NotNode not -> x(not.in(1)) == 0 ? 1L : 0L;
272 case OrNode or -> x(or .in(1)) | x(or .in(2));
273 case ProjNode proj -> proj._type instanceof TypeMem ? "$mem" : val(proj.in(0));
274 case ReadOnlyNode read -> val(read.in(1));
275 case SarNode sar -> x(sar.in(1)) >> x(sar.in(2));
276 case MemMergeNode merge-> "$mem";
277 case ShlNode shl -> x(shl.in(1)) << x(shl.in(2));
278 case ShrNode shr -> x(shr.in(1)) >>>x(shr.in(2));
279 case StoreNode st -> store(st);
280 case SubNode sub -> x(sub.in(1)) - x(sub.in(2));
281 case SubFNode sbf -> d(sbf.in(1)) - d(sbf.in(2));
282 case ToFloatNode toflt-> (double)x(toflt.in(1));
283 case XorNode xor -> x(xor.in(1)) ^ x(xor.in(2));
284 default -> throw Utils.TODO();
285 };
286 }
287
288 // Fetch without unboxing, searching up-Frame
289 static Object val( Node n ) { return F.get(n); }

Callers 4

stepMethod · 0.95
consMethod · 0.45
evaluateMethod · 0.45
isNotXCtrlMethod · 0.45

Calls 10

dMethod · 0.95
xMethod · 0.95
valMethod · 0.95
conMethod · 0.95
loadMethod · 0.95
allocMethod · 0.95
storeMethod · 0.95
TODOMethod · 0.95
inMethod · 0.45
equalsMethod · 0.45

Tested by

no test coverage detected