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) }