manual c function interop

This commit is contained in:
2026-06-11 22:46:12 +02:00
parent 2a79010a57
commit a5ceb727c1
20 changed files with 725 additions and 74 deletions
+24 -4
View File
@@ -385,10 +385,29 @@ parse_function :: proc(parser: ^Parser, name: token.Token, c_abi: bool) {
}
skip_newlines(parser)
result := parse_type(parser)
skip_newlines(parser)
if _, ok := allow(parser, .Left_Brace); !ok {
source.add(parser.diagnostics, current(parser).span, "expected '{' before function body")
end := previous(parser)
ended_by_newline := current(parser).kind == .Newline
if current(parser).kind == .Newline {
skip_newlines(parser)
}
if current(parser).kind != .Left_Brace {
if !ended_by_newline && current(parser).kind != .Eof {
_ = finish_statement(parser)
}
append(&parser.module.functions, ast.Function{
span=span_from(name.span, end.span),
name=name.symbol,
pkg=parser.pkg,
file=parser.file,
c_abi=c_abi,
has_body=false,
params=params,
result=result,
diagnostic=-1,
})
return
}
advance(parser)
body: [dynamic]int
body.allocator = parser.module.allocator
@@ -406,7 +425,7 @@ parse_function :: proc(parser: ^Parser, name: token.Token, c_abi: bool) {
append(&body, statement_id)
}
}
end := current(parser)
end = current(parser)
if _, ok := allow(parser, .Right_Brace); !ok {
source.add(parser.diagnostics, current(parser).span, "expected '}' after function body")
end = func_token
@@ -417,6 +436,7 @@ parse_function :: proc(parser: ^Parser, name: token.Token, c_abi: bool) {
pkg=parser.pkg,
file=parser.file,
c_abi=c_abi,
has_body=true,
params=params,
result=result,
body=body[:],