restricted c header imports

This commit is contained in:
2026-06-14 14:42:38 +02:00
parent 4e860b033e
commit 638ca57f5c
24 changed files with 1377 additions and 45 deletions
+21
View File
@@ -128,10 +128,12 @@ Function :: struct {
pkg: Package_Id,
file: File_Id,
c_abi: bool,
imported: bool,
has_body: bool,
params: []Param,
result: Type_Syntax,
body: []Stmt_Id,
unsupported_reason: string,
diagnostic: source.Diagnostic_Id,
}
@@ -167,6 +169,18 @@ Package :: struct {
path: string,
name: symbol.Id,
available: bool,
kind: Package_Kind,
}
Package_Kind :: enum u8 {
Native,
C_Header,
}
Unsupported :: struct {
pkg: Package_Id,
name: symbol.Id,
reason: string,
}
Module :: struct {
@@ -177,6 +191,7 @@ Module :: struct {
imports: [dynamic]Import,
files: [dynamic]File,
packages: [dynamic]Package,
unsupported: [dynamic]Unsupported,
strings: [dynamic]string,
type_store: types.Store,
allocator: mem.Allocator,
@@ -193,6 +208,7 @@ init_module :: proc(allocator := context.allocator) -> Module {
module.imports.allocator = allocator
module.files.allocator = allocator
module.packages.allocator = allocator
module.unsupported.allocator = allocator
module.strings.allocator = allocator
return module
}
@@ -204,6 +220,7 @@ destroy_module :: proc(module: ^Module) {
for function in module.functions {
delete(function.params, module.allocator)
delete(function.body, module.allocator)
delete(function.unsupported_reason, module.allocator)
}
for import_item in module.imports {
delete(import_item.path, module.allocator)
@@ -211,6 +228,9 @@ destroy_module :: proc(module: ^Module) {
for pkg in module.packages {
delete(pkg.path, module.allocator)
}
for item in module.unsupported {
delete(item.reason, module.allocator)
}
for value in module.strings {
delete(value, module.allocator)
}
@@ -221,6 +241,7 @@ destroy_module :: proc(module: ^Module) {
delete(module.imports)
delete(module.files)
delete(module.packages)
delete(module.unsupported)
delete(module.strings)
types.destroy_store(&module.type_store)
}