MCPcopy Index your code
hub / github.com/SeaOfNodes/Simple / alloc

Method alloc

chapter21/src/test/java/com/seaofnodes/simple/Eval2.java:323–348  ·  view source on GitHub ↗
(NewNode alloc)

Source from the content-addressed store, hash-verified

321
322 // Builds and returns a pointer Object
323 private static Object alloc(NewNode alloc) {
324 TypeStruct type = alloc._ptr._obj;
325 if( type.isAry() ) {
326 long sz = (Long)val(alloc.in(1));
327 long x = offToIdx(sz, type);
328 int n = (int)x;
329 if( n!=x || n<0 )
330 throw new NegativeArraySizeException(""+n);
331 Object[] ary = new Object[n]; // Array body
332 var elem = type._fields[1]._type;
333 if (elem instanceof TypeInteger) {
334 Arrays.fill( ary, 0L );
335 } else if (elem instanceof TypeFloat) {
336 Arrays.fill( ary, 0D );
337 } else {
338 assert elem instanceof TypeMemPtr || elem instanceof TypeFunPtr;
339 }
340 return ary;
341 }
342
343 int num = type._fields.length;
344 Object[] ptr = new Object[num];
345 for( int i=0; i<num; i++ )
346 ptr[i] = con(type._fields[i]._type.makeZero());
347 return ptr;
348 }
349
350 private static Object load( LoadNode ld ) {
351 TypeMemPtr tmp = (TypeMemPtr)ld.ptr()._type;

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