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

Method compute

chapter24/src/test/java/com/seaofnodes/simple/Eval2.java:253–289  ·  view source on GitHub ↗
( Node n )

Source from the content-addressed store, hash-verified

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