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 * </pre>
1592 */
1593 private Node func() {
1594 Ary<Type> ts = new Ary<>(Type.class);
1595 Ary<String> ids = new Ary<>(String.class);
1596
1597 // Defined in constructor? Add `self` argument. "static" calls still
1598 // add a `self` they just ignore it.
1599 if( _scope._kinds.last() instanceof Kind.Define define ) {
1600 // Upgrade defined struct to latest fields
1601 TypeMemPtr tmp = (TypeMemPtr)TYPES.get(define._tmp._obj._name);
1602 ts .push(tmp);
1603 ids.push("self");
1604 }
1605
1606 // Parse other arguments
1607 _lexer.skipWhiteSpace();
1608 Lexer loc = loc(); // First argument location
1609 while( true ) {
1610 Type t = type(); // Arg type
1611 if( t==null ) break;
1612 String id = requireId();
1613 ts .push(t ); // Push type/arg pairs
1614 ids.push(id);
1615 match(",");
1616 }
1617 require("->");
1618 // Make a concrete function type, with a fidx
1619 TypeFunPtr tfp = _code.makeFun(TypeFunPtr.make(false,false,ts.asAry(),Type.BOTTOM));
1620 ReturnNode ret = parseFunctionBody(tfp,loc,ids.asAry());
1621 return con(ret._fun.sig());
1622 }
1623
1624 /**
1625 * Parse function call arguments; caller will parse the surrounding "()"

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