compact compiler ids and spans to reduce memory usage
This commit is contained in:
+80
-26
@@ -4,9 +4,63 @@ import "../source"
|
||||
import "../symbol"
|
||||
import "core:mem"
|
||||
|
||||
INVALID_ID :: -1
|
||||
Expr_Id :: distinct u32
|
||||
Stmt_Id :: distinct u32
|
||||
Function_Id :: distinct u32
|
||||
Global_Id :: distinct u32
|
||||
Import_Id :: distinct u32
|
||||
File_Id :: distinct u32
|
||||
Package_Id :: distinct u32
|
||||
|
||||
Type_Syntax :: enum {
|
||||
INVALID_EXPR :: Expr_Id(0xffff_ffff)
|
||||
INVALID_STMT :: Stmt_Id(0xffff_ffff)
|
||||
INVALID_FUNCTION :: Function_Id(0xffff_ffff)
|
||||
INVALID_GLOBAL :: Global_Id(0xffff_ffff)
|
||||
INVALID_IMPORT :: Import_Id(0xffff_ffff)
|
||||
INVALID_FILE :: File_Id(0xffff_ffff)
|
||||
INVALID_PACKAGE :: Package_Id(0xffff_ffff)
|
||||
|
||||
expr_id :: proc(index: int) -> Expr_Id {
|
||||
assert(index >= 0 && u64(index) < u64(INVALID_EXPR))
|
||||
return Expr_Id(index)
|
||||
}
|
||||
|
||||
stmt_id :: proc(index: int) -> Stmt_Id {
|
||||
assert(index >= 0 && u64(index) < u64(INVALID_STMT))
|
||||
return Stmt_Id(index)
|
||||
}
|
||||
|
||||
function_id :: proc(index: int) -> Function_Id {
|
||||
assert(index >= 0 && u64(index) < u64(INVALID_FUNCTION))
|
||||
return Function_Id(index)
|
||||
}
|
||||
|
||||
global_id :: proc(index: int) -> Global_Id {
|
||||
assert(index >= 0 && u64(index) < u64(INVALID_GLOBAL))
|
||||
return Global_Id(index)
|
||||
}
|
||||
|
||||
import_id :: proc(index: int) -> Import_Id {
|
||||
assert(index >= 0 && u64(index) < u64(INVALID_IMPORT))
|
||||
return Import_Id(index)
|
||||
}
|
||||
|
||||
file_id :: proc(index: int) -> File_Id {
|
||||
assert(index >= 0 && u64(index) < u64(INVALID_FILE))
|
||||
return File_Id(index)
|
||||
}
|
||||
|
||||
package_id :: proc(index: int) -> Package_Id {
|
||||
assert(index >= 0 && u64(index) < u64(INVALID_PACKAGE))
|
||||
return Package_Id(index)
|
||||
}
|
||||
|
||||
index :: proc(id: $T, invalid: T, count: int) -> (int, bool) {
|
||||
value := int(id)
|
||||
return value, id != invalid && value < count
|
||||
}
|
||||
|
||||
Type_Syntax :: enum u8 {
|
||||
Invalid,
|
||||
Int,
|
||||
I8,
|
||||
@@ -16,7 +70,7 @@ Type_Syntax :: enum {
|
||||
Void,
|
||||
}
|
||||
|
||||
Expr_Kind :: enum {
|
||||
Expr_Kind :: enum u8 {
|
||||
Invalid,
|
||||
Integer,
|
||||
Name,
|
||||
@@ -25,15 +79,15 @@ Expr_Kind :: enum {
|
||||
}
|
||||
|
||||
Expr :: struct {
|
||||
kind: Expr_Kind,
|
||||
span: source.Span,
|
||||
integer: i64,
|
||||
args: []Expr_Id,
|
||||
qualifier: symbol.Id,
|
||||
name: symbol.Id,
|
||||
integer: i64,
|
||||
left: int,
|
||||
right: int,
|
||||
args: []int,
|
||||
diagnostic: int,
|
||||
left: Expr_Id,
|
||||
right: Expr_Id,
|
||||
diagnostic: source.Diagnostic_Id,
|
||||
kind: Expr_Kind,
|
||||
}
|
||||
|
||||
Param :: struct {
|
||||
@@ -42,7 +96,7 @@ Param :: struct {
|
||||
type: Type_Syntax,
|
||||
}
|
||||
|
||||
Stmt_Kind :: enum {
|
||||
Stmt_Kind :: enum u8 {
|
||||
Invalid,
|
||||
Declaration,
|
||||
Assignment,
|
||||
@@ -56,49 +110,49 @@ Stmt :: struct {
|
||||
name: symbol.Id,
|
||||
type: Type_Syntax,
|
||||
immutable: bool,
|
||||
expr: int,
|
||||
diagnostic: int,
|
||||
expr: Expr_Id,
|
||||
diagnostic: source.Diagnostic_Id,
|
||||
}
|
||||
|
||||
Function :: struct {
|
||||
span: source.Span,
|
||||
name: symbol.Id,
|
||||
pkg: int,
|
||||
file: int,
|
||||
pkg: Package_Id,
|
||||
file: File_Id,
|
||||
c_abi: bool,
|
||||
has_body: bool,
|
||||
params: []Param,
|
||||
result: Type_Syntax,
|
||||
body: []int,
|
||||
diagnostic: int,
|
||||
body: []Stmt_Id,
|
||||
diagnostic: source.Diagnostic_Id,
|
||||
}
|
||||
|
||||
Global :: struct {
|
||||
span: source.Span,
|
||||
name: symbol.Id,
|
||||
pkg: int,
|
||||
file: int,
|
||||
pkg: Package_Id,
|
||||
file: File_Id,
|
||||
type: Type_Syntax,
|
||||
immutable: bool,
|
||||
expr: int,
|
||||
diagnostic: int,
|
||||
expr: Expr_Id,
|
||||
diagnostic: source.Diagnostic_Id,
|
||||
}
|
||||
|
||||
Import :: struct {
|
||||
span: source.Span,
|
||||
alias: symbol.Id,
|
||||
path: string,
|
||||
pkg: int,
|
||||
file: int,
|
||||
target: int,
|
||||
pkg: Package_Id,
|
||||
file: File_Id,
|
||||
target: Package_Id,
|
||||
valid: bool,
|
||||
used: bool,
|
||||
diagnostic: int,
|
||||
diagnostic: source.Diagnostic_Id,
|
||||
}
|
||||
|
||||
File :: struct {
|
||||
source: int,
|
||||
pkg: int,
|
||||
source: source.Source_Id,
|
||||
pkg: Package_Id,
|
||||
}
|
||||
|
||||
Package :: struct {
|
||||
|
||||
Reference in New Issue
Block a user