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

Method alloc

chapter19/src/test/java/com/seaofnodes/simple/Eval2.java:321–346  ·  view source on GitHub ↗
(NewNode alloc)

Source from the content-addressed store, hash-verified

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