Compiler: add local function statements and expressions#393
Compiler: add local function statements and expressions#393chqrlie wants to merge 1 commit intoc2lang:masterfrom
Conversation
chqrlie
commented
Nov 5, 2025
- local functions are defined using the standard syntax in the body of a function.
- they cannot be templates nor type functions
- they can be named or anonymous
- accept a capture list between square backets fater the parameter list (currently ignored)
|
I'm not really fond of the name mangling. Cant we do: and then disallow double underscores in normal names? Another issue is the AST printing. The local function body is not printed. You could add test cases, they dont depend on the bootstrap. I tried this and it works... If you generate the C code and check what GCC/Clang make of that, the call completely disappears :) |
|
Disallowing double underscores and using them for mangled names, especially Yet the mangling for making local symbols global must handle the case of duplicates: it is quite common in the code to use the same local name in non intersecting scopes. The same could happen for local functions, and should be allowed, so AST printing is on the way, I need to add a new AST node type for this. I'm glad the optimizer does a good job on these things. |
6c6a97f to
516ed00
Compare
c6cc10b to
f5f822b
Compare
f5f822b to
9c55ef4
Compare
5b34fb9 to
16bed9d
Compare
75be438 to
45b9c92
Compare
0637b82 to
1f35010
Compare
29d7820 to
54db774
Compare
54db774 to
6df5fae
Compare
41ba545 to
7137952
Compare
* local functions are defined using the standard syntax in the body of a function. * they cannot be templates nor type functions * they can be named or anonymous * accept a capture list between square backets fater the parameter list (currently ignored)
7137952 to
a9c57e6
Compare