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

Method con

chapter24/src/test/java/com/seaofnodes/simple/Eval2.java:303–332  ·  view source on GitHub ↗
( Type t )

Source from the content-addressed store, hash-verified

301
302 // Java box ints and floats. Other things can just be null or some informative string
303 private static Object con( Type t ) {
304 return switch ( t ) {
305 case TypeInteger i -> i.isConstant() ? (Long )i.value() : "INT";
306 case TypeFloat f -> f.isConstant() ? (Double)f.value() : "FLT";
307 case TypeFunPtr tfp -> tfp;
308 case TypeMem mem -> "MEM";
309 case TypeMemPtr tmp -> {
310 if( tmp._obj.isAry() ) { // Constant array ptr
311 Type elem = tmp._obj.field("[]")._t;
312 if( elem instanceof TypeConAry con ) {
313 Object[] xs = new Object[con.len()];
314 for( int i=0; i<con.len(); i++ )
315 xs[i] = con.at8(i);
316 yield xs;
317 } else {
318 // Generic constant array, used as a default input to a
319 // function; should never execute.
320 yield new Object[0];
321 }
322
323 } else {
324 // Generic TMP (since Simple is not currently making actual
325 // memory constants), used as a default input to a function;
326 // should never execute.
327 yield tmp.toString();
328 }
329 }
330 default -> null;
331 };
332 }
333
334 // Convert array size to array element count
335 private static int offToIdx( long off, TypeStruct t) {

Callers 2

computeMethod · 0.95
allocMethod · 0.95

Calls 7

isConstantMethod · 0.45
valueMethod · 0.45
isAryMethod · 0.45
fieldMethod · 0.45
lenMethod · 0.45
at8Method · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected