mirror of
https://github.com/Nexoniarz/Finch.git
synced 2026-11-03 00:44:27 +00:00
Reads functions (with variadics and why one is unsupported), enum and #define constants, extern variables and structs with their layout, the same as src/cimport.cpp. It calls libclang through Finch's own C import, so compiling it is what the bootstrap will have to do. Checked with the C++ compiler: stdio.h gives 90 functions and 347 constants; EOF is -1, stdout is ptr[C.FILE].
18 lines
932 B
Text
18 lines
932 B
Text
import ast
|
|
import cimport
|
|
|
|
fn main() -> ! {
|
|
headers := [cimport.Header(path: "stdio.h", where: "test:1:1"), cimport.Header(path: "/home/nexoniarz/.claude/jobs/4af40c6f/tmp/cx/h.h", where: "test:2:1")]
|
|
c := try cimport.importHeaders(headers, [])
|
|
print("functions", c.fns.len, "consts", c.consts.len, "globals", c.globals.len, "structs", c.structs.len)
|
|
f := c.fns["add"]
|
|
print(f.name, ast.show(f.ret), f.params.len, f.unsupported)
|
|
m := c.fns["many"]
|
|
print(m.name, ast.show(m.ret), m.params.len, ast.show(m.params[0]), ast.show(m.params[1]), m.unsupported)
|
|
print(c.consts["N"].i, c.consts["Green"].i, c.consts["EOF"].i)
|
|
print(ast.show(c.globals["counter"]), ast.show(c.globals["stdout"]))
|
|
s := c.structs["Vec2"]
|
|
print(s.name, s.size, s.align, s.fields.len, s.unsupported)
|
|
printf := c.fns["printf"]
|
|
print(printf.name, printf.variadic, printf.params.len, ast.show(printf.params[0]))
|
|
}
|