extern variables and object-like macro consts
This commit is contained in:
@@ -134,6 +134,7 @@ Function :: struct {
|
||||
params: []Param,
|
||||
result: Type_Syntax,
|
||||
body: []Stmt_Id,
|
||||
link_name: string,
|
||||
unsupported_reason: string,
|
||||
diagnostic: source.Diagnostic_Id,
|
||||
}
|
||||
@@ -141,10 +142,13 @@ Function :: struct {
|
||||
Global :: struct {
|
||||
span: source.Span,
|
||||
name: symbol.Id,
|
||||
link_name: string,
|
||||
pkg: Package_Id,
|
||||
file: File_Id,
|
||||
type: Type_Syntax,
|
||||
immutable: bool,
|
||||
external: bool,
|
||||
writable: bool,
|
||||
expr: Expr_Id,
|
||||
diagnostic: source.Diagnostic_Id,
|
||||
}
|
||||
@@ -184,6 +188,16 @@ Unsupported :: struct {
|
||||
reason: string,
|
||||
}
|
||||
|
||||
// Trampoline is a generated C wrapper source that must be compiled and linked
|
||||
// alongside the program so an internal-linkage (`static inline`) C function can
|
||||
// be called through an external symbol. `source` is the wrapper function only;
|
||||
// `header` is the absolute path it must `#include` (emitted once per header).
|
||||
Trampoline :: struct {
|
||||
symbol: string,
|
||||
source: string,
|
||||
header: string,
|
||||
}
|
||||
|
||||
Module :: struct {
|
||||
exprs: [dynamic]Expr,
|
||||
statements: [dynamic]Stmt,
|
||||
@@ -193,6 +207,7 @@ Module :: struct {
|
||||
files: [dynamic]File,
|
||||
packages: [dynamic]Package,
|
||||
unsupported: [dynamic]Unsupported,
|
||||
c_trampolines: [dynamic]Trampoline,
|
||||
strings: [dynamic]string,
|
||||
type_store: types.Store,
|
||||
allocator: mem.Allocator,
|
||||
@@ -210,6 +225,7 @@ init_module :: proc(allocator := context.allocator) -> Module {
|
||||
module.files.allocator = allocator
|
||||
module.packages.allocator = allocator
|
||||
module.unsupported.allocator = allocator
|
||||
module.c_trampolines.allocator = allocator
|
||||
module.strings.allocator = allocator
|
||||
return module
|
||||
}
|
||||
@@ -221,17 +237,26 @@ destroy_module :: proc(module: ^Module) {
|
||||
for function in module.functions {
|
||||
delete(function.params, module.allocator)
|
||||
delete(function.body, module.allocator)
|
||||
delete(function.link_name, module.allocator)
|
||||
delete(function.unsupported_reason, module.allocator)
|
||||
}
|
||||
for import_item in module.imports {
|
||||
delete(import_item.path, module.allocator)
|
||||
}
|
||||
for global in module.globals {
|
||||
delete(global.link_name, module.allocator)
|
||||
}
|
||||
for pkg in module.packages {
|
||||
delete(pkg.path, module.allocator)
|
||||
}
|
||||
for item in module.unsupported {
|
||||
delete(item.reason, module.allocator)
|
||||
}
|
||||
for trampoline in module.c_trampolines {
|
||||
delete(trampoline.symbol, module.allocator)
|
||||
delete(trampoline.source, module.allocator)
|
||||
delete(trampoline.header, module.allocator)
|
||||
}
|
||||
for value in module.strings {
|
||||
delete(value, module.allocator)
|
||||
}
|
||||
@@ -243,6 +268,7 @@ destroy_module :: proc(module: ^Module) {
|
||||
delete(module.files)
|
||||
delete(module.packages)
|
||||
delete(module.unsupported)
|
||||
delete(module.c_trampolines)
|
||||
delete(module.strings)
|
||||
types.destroy_store(&module.type_store)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user