initial draft

This commit is contained in:
2026-06-09 17:28:28 +02:00
commit 087fdb45d5
40 changed files with 4371 additions and 0 deletions
+110
View File
@@ -0,0 +1,110 @@
package ast
import "../source"
import "core:mem"
INVALID_ID :: -1
Type_Syntax :: enum {
Invalid,
Int,
I8,
I16,
I32,
I64,
Void,
}
Expr_Kind :: enum {
Invalid,
Integer,
Name,
Add,
Call,
}
Expr :: struct {
kind: Expr_Kind,
span: source.Span,
text: string,
integer: i64,
left: int,
right: int,
args: []int,
diagnostic: int,
}
Param :: struct {
name: string,
span: source.Span,
type: Type_Syntax,
}
Stmt_Kind :: enum {
Invalid,
Declaration,
Assignment,
Return,
Expression,
}
Stmt :: struct {
kind: Stmt_Kind,
span: source.Span,
name: string,
type: Type_Syntax,
immutable: bool,
expr: int,
diagnostic: int,
}
Function :: struct {
span: source.Span,
name: string,
c_abi: bool,
params: []Param,
result: Type_Syntax,
body: []int,
diagnostic: int,
}
Global :: struct {
span: source.Span,
name: string,
type: Type_Syntax,
immutable: bool,
expr: int,
diagnostic: int,
}
Module :: struct {
exprs: [dynamic]Expr,
statements: [dynamic]Stmt,
functions: [dynamic]Function,
globals: [dynamic]Global,
allocator: mem.Allocator,
}
init_module :: proc(allocator := context.allocator) -> Module {
module: Module
module.allocator = allocator
module.exprs.allocator = allocator
module.statements.allocator = allocator
module.functions.allocator = allocator
module.globals.allocator = allocator
return module
}
destroy_module :: proc(module: ^Module) {
for expr in module.exprs {
delete(expr.args, module.allocator)
}
for function in module.functions {
delete(function.params, module.allocator)
delete(function.body, module.allocator)
}
delete(module.exprs)
delete(module.statements)
delete(module.functions)
delete(module.globals)
}