c interop type foundation
This commit is contained in:
+25
-9
@@ -2,6 +2,7 @@ package ast
|
||||
|
||||
import "../source"
|
||||
import "../symbol"
|
||||
import "../types"
|
||||
import "core:mem"
|
||||
|
||||
Expr_Id :: distinct u32
|
||||
@@ -60,20 +61,25 @@ index :: proc(id: $T, invalid: T, count: int) -> (int, bool) {
|
||||
return value, id != invalid && value < count
|
||||
}
|
||||
|
||||
Type_Syntax :: enum u8 {
|
||||
Invalid,
|
||||
Int,
|
||||
I8,
|
||||
I16,
|
||||
I32,
|
||||
I64,
|
||||
Void,
|
||||
}
|
||||
Type_Syntax :: types.Type
|
||||
|
||||
Expr_Kind :: enum u8 {
|
||||
Invalid,
|
||||
Integer,
|
||||
Float,
|
||||
String,
|
||||
Array,
|
||||
None,
|
||||
Name,
|
||||
Address,
|
||||
Deref,
|
||||
Index,
|
||||
Slice,
|
||||
Field,
|
||||
Unwrap,
|
||||
Orelse,
|
||||
Struct_Literal,
|
||||
Keyed,
|
||||
Negate,
|
||||
Add,
|
||||
Call,
|
||||
@@ -111,6 +117,7 @@ Stmt :: struct {
|
||||
name: symbol.Id,
|
||||
type: Type_Syntax,
|
||||
immutable: bool,
|
||||
target: Expr_Id,
|
||||
expr: Expr_Id,
|
||||
diagnostic: source.Diagnostic_Id,
|
||||
}
|
||||
@@ -170,12 +177,15 @@ Module :: struct {
|
||||
imports: [dynamic]Import,
|
||||
files: [dynamic]File,
|
||||
packages: [dynamic]Package,
|
||||
strings: [dynamic]string,
|
||||
type_store: types.Store,
|
||||
allocator: mem.Allocator,
|
||||
}
|
||||
|
||||
init_module :: proc(allocator := context.allocator) -> Module {
|
||||
module: Module
|
||||
module.allocator = allocator
|
||||
module.type_store = types.init_store(allocator)
|
||||
module.exprs.allocator = allocator
|
||||
module.statements.allocator = allocator
|
||||
module.functions.allocator = allocator
|
||||
@@ -183,6 +193,7 @@ init_module :: proc(allocator := context.allocator) -> Module {
|
||||
module.imports.allocator = allocator
|
||||
module.files.allocator = allocator
|
||||
module.packages.allocator = allocator
|
||||
module.strings.allocator = allocator
|
||||
return module
|
||||
}
|
||||
|
||||
@@ -200,6 +211,9 @@ destroy_module :: proc(module: ^Module) {
|
||||
for pkg in module.packages {
|
||||
delete(pkg.path, module.allocator)
|
||||
}
|
||||
for value in module.strings {
|
||||
delete(value, module.allocator)
|
||||
}
|
||||
delete(module.exprs)
|
||||
delete(module.statements)
|
||||
delete(module.functions)
|
||||
@@ -207,4 +221,6 @@ destroy_module :: proc(module: ^Module) {
|
||||
delete(module.imports)
|
||||
delete(module.files)
|
||||
delete(module.packages)
|
||||
delete(module.strings)
|
||||
types.destroy_store(&module.type_store)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user