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

Method func

chapter23/src/main/java/com/seaofnodes/simple/Parser.java:1593–1622  ·  view source on GitHub ↗

Parse a function body; the caller will parse the surrounding "{}" { [type arg,] -> expr } { expr } // The no-argument function

()

Source from the content-addressed store, hash-verified

1591
1592 expr.keep();
1593 // Field offset; fixed for structs, computed for arrays
1594 Node off = (name.equals("[]") // If field is an array body
1595 // Array index math
1596 ? peep(new AddNode(off(base,"[]"),peep(new ShlNode(null,require(parseAsgn(),"]"),con(base.aryScale())))))
1597 // Struct field offsets are hardwired
1598 : off(base,name)).keep();
1599
1600 // Disambiguate "obj.fld==x" boolean test from "obj.fld=x" field assignment
1601 if( pre==0 && matchOpx('=','=') ) {
1602 Node val = parseAsgn().keep();
1603 Node lift = liftExpr( val, tf, false );
1604
1605 store(name,f._alias,tf,expr.unkeep(),off.unkeep(),lift,false,base.isAry() ? ctrl() : null);
1606 return val.unkeep(); // "obj.a = expr" returns the expression while updating memory
1607 }
1608
1609 // Load field
1610 Node load = f._one && INITS.containsKey( base._name )
1611 ? INITS.get(base._name).in(base.find(name))
1612 : new LoadNode(loc(),name, f._alias, tf, mem(), expr, off);
1613 // Arrays include control, as a proxy for a safety range check
1614 // Structs don't need this; they only need a NPE check which is
1615 // done via the type system.
1616 if( base.isAry() && !name.equals("#") ) load.setDef(0,ctrl());
1617 load = peep(load);
1618
1619 // Check for assign-update, "ptr.fld += expr" or "ary[idx]++"
1620 char ch = pre==0 ? _lexer.matchOperAssign() : (char)pre;
1621 if( ch!=0 ) {
1622 Node op = opAssign(ch,load,tf);
1623 // A narrow Store may drop its conversion; prefix still returns it.
1624 if( pre!=0 ) op.keep();
1625 store(name,f._alias,tf,expr.unkeep(),off.unkeep(),op,false,base.isAry() ? ctrl() : null);

Callers 1

parsePrimaryMethod · 0.95

Calls 15

pushMethod · 0.95
locMethod · 0.95
typeMethod · 0.95
requireIdMethod · 0.95
matchMethod · 0.95
requireMethod · 0.95
makeMethod · 0.95
asAryMethod · 0.95
parseFunctionBodyMethod · 0.95
conMethod · 0.95
lastMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected