Backup, new approach to ast

This commit is contained in:
Krzosa Karol
2022-05-02 09:29:21 +02:00
parent c5498b03ad
commit 6d68fd07aa
8 changed files with 882 additions and 125 deletions

149
ast.h
View File

@@ -1,5 +1,16 @@
#if 0
OS_Memory:struct{
data: void*;
commit: SizeU;
reserve: SizeU;
}
Arena:struct{
@using memory: OS_Memory;
len: U64;
alignment: U64;
}
String:struct{
str: U8*;
@@ -7,6 +18,8 @@ String:struct{
}
Intern_String:typedef String;
@stringify
@prefix="TK_"
Token_Kind:enum{
@str="End of stream" End,
@str="*" Mul,
@@ -73,13 +86,9 @@ Token_Kind:enum{
Keyword,
}
Token:struct{
kind:Token_Kind;
union:{
string:String;
struct:{str:U8*; len:U64;}
}
@using string:String;
union:{
int_val:S64;
error_val:String;
@@ -90,17 +99,79 @@ Token:struct{
line_begin:U8*;
}
Tokens:struct{
@array tokens: Token*;
iter : S64;
}
Lex_Stream:struct{
stream: U8*;
line_begin: U8*;
filename: String;
line: S64;
}
@prefix="EK_"
Expr_Kind: enum{
None,
Atom,
Unary,
Binary,
Ternary,
Cast,
List,
Call,
Index,
}
/*
Expr: struct{
kind: Expr_Kind;
token: Token*;
next : Expr*;
union:{
cast: struct{
type: AST_Node*;
expr: Expr*;
}
list: struct{
first: Expr *;
last: Expr *;
}
call: struct{
atom: Expr *;
list: Expr *;
}
index: struct{
atom: Expr *;
index: Expr *;
}
unary: struct{
expr: Expr* ;
}
binary: struct{
left: Expr* ;
right: Expr* ;
}
ternary: struct{
cond: Expr* ;
on_true: Expr*;
on_false: Expr*;
}
}
}
*/
@prefix="AK_"
AST_Kind:enum{
None,
BaseType,
Typedef,
Enum,
Struct,
Union,
Note,
List,
Pointer,
Array,
Function,
@@ -110,7 +181,8 @@ AST_Kind:enum{
AST_Node:struct{
kind: AST_Kind;
node: AST_Node[16];
pos : Token*;
name: Intern_String;
next: AST_Node*;
next_scope: AST_Node*;
@@ -129,6 +201,66 @@ AST_Node:struct{
}
}
Parser_Error: struct{
next: Parser_Error*;
message: String;
token : Token *;
}
Scope: struct{
next : Scope*;
first: AST_Node*;
last : AST_Node*;
}
Parser: struct{
main_arena: Arena;
intern_table_arena: Arena;
symbol_table_arena: Arena;
scope_free_list: Scope *;
scope_stack: Scope *;
global_scope: Scope *;
symbols_inserted: S64;
symbols_count: S64;
symbols: AST_Node *;
interns: Intern_String *;
interns_in_bytes: S64;
interns_inserted: S64;
interns_count: S64;
first_keyword: U8 *;
last_keyword: U8 *;
//@map(type="sparse") symbols: AST_Node;
// @Todo(Krzosa): This adds default to function name currently
// And it's hard to anything else sort of except adding
// a variable of _var_name_lower_with_ or something
@sllqueue default: Parser_Error;
// This works ok
@sllqueue error: Parser_Error;
@using token_array: Tokens;
}
/*
@register_tag(sllqueue)
@params(next=next,last=last,first=first)
function void
struct_type_lower_var_name_lower_push(struct_type *parent, var_type *child){
if(parent->first == 0){
- parent->first = parent->last = child;
}
else{
- parent->last = parent->last->next = child;
}
}
*/
#endif
@@ -144,6 +276,7 @@ typedef enum AST_Kind{
AK_Struct,
AK_Union,
AK_Identifier,
AK_Note,
AK_List,