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

Method alloc

chapter23/src/test/java/com/seaofnodes/simple/Eval2.java:334–359  ·  view source on GitHub ↗
(NewNode alloc)

Source from the content-addressed store, hash-verified

332
333 // Builds and returns a pointer Object
334 private static Object alloc(NewNode alloc) {
335 TypeStruct type = alloc._ptr._obj;
336 if( type.isAry() ) {
337 long sz = (Long)val(alloc.in(1));
338 long x = offToIdx(sz, type);
339 int n = (int)x;
340 if( n!=x || n<0 )
341 throw new NegativeArraySizeException(""+n);
342 Object[] ary = new Object[n]; // Array body
343 var elem = type._fields[1]._t;
344 if (elem instanceof TypeInteger) {
345 Arrays.fill( ary, 0L );
346 } else if (elem instanceof TypeFloat) {
347 Arrays.fill( ary, 0D );
348 } else {
349 assert elem instanceof TypeMemPtr || elem instanceof TypeFunPtr;
350 }
351 return ary;
352 }
353
354 int num = type._fields.length;
355 Object[] ptr = new Object[num];
356 for( int i=0; i<num; i++ )
357 ptr[i] = con(type._fields[i]._t.makeZero());
358 return ptr;
359 }
360
361 private static Object load( LoadNode ld ) {
362 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