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

Method alloc

chapter24/src/test/java/com/seaofnodes/simple/Eval2.java:343–368  ·  view source on GitHub ↗
(NewNode alloc)

Source from the content-addressed store, hash-verified

341
342 // Builds and returns a pointer Object
343 private static Object alloc(NewNode alloc) {
344 TypeStruct type = alloc._ptr._obj;
345 if( type.isAry() ) {
346 long sz = (Long)val(alloc.in(1));
347 long x = offToIdx(sz, type);
348 int n = (int)x;
349 if( n!=x || n<0 )
350 throw new NegativeArraySizeException(""+n);
351 Object[] ary = new Object[n]; // Array body
352 var elem = type._fields[1]._t;
353 if (elem instanceof TypeInteger) {
354 Arrays.fill( ary, 0L );
355 } else if (elem instanceof TypeFloat) {
356 Arrays.fill( ary, 0D );
357 } else {
358 assert elem instanceof TypeMemPtr || elem instanceof TypeFunPtr;
359 }
360 return ary;
361 }
362
363 int num = type._fields.length;
364 Object[] ptr = new Object[num];
365 for( int i=0; i<num; i++ )
366 ptr[i] = con(type._fields[i]._t.makeZero());
367 return ptr;
368 }
369
370 private static Object load( LoadNode ld ) {
371 Object f = val(ld.ptr());

Callers 3

computeMethod · 0.95
leFunction · 0.45
leFunction · 0.45

Calls 6

isAryMethod · 0.95
valMethod · 0.95
offToIdxMethod · 0.95
conMethod · 0.95
inMethod · 0.45
makeZeroMethod · 0.45

Tested by

no test coverage detected