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

Method alloc

chapter22/src/test/java/com/seaofnodes/simple/Eval2.java:322–347  ·  view source on GitHub ↗
(NewNode alloc)

Source from the content-addressed store, hash-verified

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