mirror of
https://github.com/Nexoniarz/Finch.git
synced 2026-11-03 00:44:27 +00:00
boot: cimport.fch, the C header importer written in Finch on libclang
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].
This commit is contained in:
parent
e4ad3540f1
commit
f71ae8b1ef
3 changed files with 579 additions and 1 deletions
|
|
@ -9,6 +9,7 @@ struct Type {
|
|||
[]Type elem
|
||||
str name
|
||||
str module
|
||||
int count // "fixed": [N]T, only inside C structs
|
||||
}
|
||||
|
||||
fn simple(str kind) -> Type {
|
||||
|
|
@ -42,7 +43,10 @@ fn same(Type a, Type b) -> bool {
|
|||
if a.kind == "struct" || a.kind == "named" {
|
||||
return a.name == b.name && a.module == b.module
|
||||
}
|
||||
if a.kind == "array" || a.kind == "ptr" || a.kind == "map" {
|
||||
if a.kind == "fixed" && a.count != b.count {
|
||||
return false
|
||||
}
|
||||
if a.kind == "array" || a.kind == "ptr" || a.kind == "map" || a.kind == "fixed" {
|
||||
if a.elem.len != b.elem.len {
|
||||
return false
|
||||
}
|
||||
|
|
@ -60,6 +64,9 @@ fn show(Type t) -> str {
|
|||
if t.kind == "array" {
|
||||
return "[]" + show(t.elem[0])
|
||||
}
|
||||
if t.kind == "fixed" {
|
||||
return "[" + str(t.count) + "]" + show(t.elem[0])
|
||||
}
|
||||
if t.kind == "map" {
|
||||
return "map[" + show(t.elem[0]) + "]" + show(t.elem[1])
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue