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

Method func

chapter24/src/main/java/com/seaofnodes/simple/Parser.java:1653–1682  ·  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

1651 * </pre>
1652 */
1653 private Node func() {
1654 Ary<Type> ts = new Ary<>(Type.class);
1655 Ary<String> ids = new Ary<>(String.class);
1656
1657 // Defined in constructor? Add `self` argument. "static" calls still
1658 // add a `self` they just ignore it.
1659 if( _scope._kinds.last() instanceof Kind.Define define ) {
1660 // Upgrade defined struct to latest fields
1661 TypeMemPtr tmp = (TypeMemPtr)TYPES.get(define._tmp._obj._name);
1662 ts .push(tmp);
1663 ids.push("self");
1664 }
1665
1666 // Parse other arguments
1667 _lexer.skipWhiteSpace();
1668 Lexer loc = loc(); // First argument location
1669 while( true ) {
1670 Type t = type(); // Arg type
1671 if( t==null ) break;
1672 String id = requireId();
1673 ts .push(t ); // Push type/arg pairs
1674 ids.push(id);
1675 match(",");
1676 }
1677 require("->");
1678 // Make a concrete function type, with a fidx
1679 TypeFunPtr tfp = _code.makeFun(TypeFunPtr.make(false,false,ts.asAry(),Type.BOTTOM));
1680 ReturnNode ret = parseFunctionBody(tfp,loc,ids.asAry());
1681 return con(ret._fun.sig());
1682 }
1683
1684 /**
1685 * 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