Added some initial directive code. Don't quite like the way it's done

This commit is contained in:
2025-09-03 21:05:00 +02:00
parent 603b625e21
commit 4924b01eac
4 changed files with 50 additions and 29 deletions

39
AST.jai
View File

@@ -14,6 +14,8 @@ AST_Kind :: enum {
Meta; Meta;
Instance; Instance;
//== //==
// Directives
If_Directive;
// Hint; // Hint;
// Type; // Type;
@@ -191,7 +193,13 @@ pretty_print_children :: (parent : *AST_Node, indentation : int, builder : *Stri
ind = 0; ind = 0;
} }
// skip := ifx it_index > 0 then false else true; // skip := ifx it_index > 0 then false else true;
pretty_print_node(child, ind, builder);
if child.kind == .Function {
pretty_print_declaration(child, ind, builder);
} else {
pretty_print_node(child, ind, builder);
}
if it_index != children.count - 1 { if it_index != children.count - 1 {
if flags & .Separator { if flags & .Separator {
@@ -434,6 +442,10 @@ pretty_print_declaration :: (declaration : *AST_Node, indentation : int, builder
append(builder, "pixel "); append(builder, "pixel ");
} }
if declaration.kind == .If_Directive {
append(builder, "#if ");
}
if declaration.kind == .Properties { if declaration.kind == .Properties {
append(builder, "properties"); append(builder, "properties");
if declaration.name.count > 0 { if declaration.name.count > 0 {
@@ -463,24 +475,15 @@ pretty_print_declaration :: (declaration : *AST_Node, indentation : int, builder
} }
if declaration.children.count > 0 { if declaration.children.count > 0 {
// print_to_builder(builder, "\n"); if declaration.kind == .If_Directive {
// if declaration.kind == .Function { pretty_print_node(declaration.children[0], 0, builder);
// field_list := declaration.children[0]; append(builder, "\n");
// pretty_print_fieldlist(field_list, indentation + 1, builder); pretty_print_node(declaration.children[1], indentation + 5, builder);
// append(builder, "\n"); } else {
print_to_builder(builder, "\n");
pretty_print_children(declaration, indentation + 1, builder, flags = .NewLine);
}
// if declaration.children.count > 1 {
// body := declaration.children[1];
// pretty_print_node(body, indentation + 1, builder, true);
// }
// } else if declaration.kind == .Struct {
// pretty_print_node(declaration.children[0], indentation + 1, builder);
// } else {
// pretty_print_node(declaration.children[0], indentation + 1, builder);
// }
print_to_builder(builder, "\n");
pretty_print_children(declaration, indentation + 1, builder, flags = .NewLine);
} }
append(builder, ")"); append(builder, ")");

View File

@@ -19,15 +19,6 @@ Parse_State :: struct {
//////////////////////////// ////////////////////////////
//@nb - Result and error handling //@nb - Result and error handling
// Parse_Result :: struct {
// root : *AST_Node;
// nodes : [..]AST_Node;
// had_error : bool;
// messages : [..]Compiler_Message;
// }
Parse_Error_Kind :: enum { Parse_Error_Kind :: enum {
Parse_Error_Type_Missing; Parse_Error_Type_Missing;
Parse_Error_Expected_Expression; Parse_Error_Expected_Expression;
@@ -616,6 +607,23 @@ directive :: (state : *Parse_State) -> *AST_Node {
func := function_declaration(state, identifier_token, .None, false, false); func := function_declaration(state, identifier_token, .None, false, false);
func.foreign_declaration = true; func.foreign_declaration = true;
return func; return func;
} else if state.current.ident_value == "if" {
if_directive := make_node(state, .If_Directive);
source_location : Source_Range;
// source_location.begin = state.previous;
advance(state);
cond := expression(state);
add_child(if_directive, cond);
if_body := block(state);
add_child(if_directive, if_body);
if_directive.source_location = source_location;
return if_directive;
} }
return null; return null;

View File

@@ -55,6 +55,9 @@ Typenames :: string.[
"bool" , "bool" ,
]; ];
//@Incomplete(niels): We can vastly simplify type handling
// There's really no reason to have these type variables anymore now that we don't do union find
// We can just have the built-in types and then we can declare structs, functions, buffers etc. as one time things.
Type_Variable :: struct { Type_Variable :: struct {
type : Type_Kind; type : Type_Kind;
kind : Type_Variable_Kind; kind : Type_Variable_Kind;
@@ -1432,8 +1435,6 @@ check_node :: (checker : *Semantic_Checker, node : *AST_Node) -> Type_Variable_H
lhs_type := from_handle(checker, lhs_var); lhs_type := from_handle(checker, lhs_var);
rhs_type := from_handle(checker, rhs_var); rhs_type := from_handle(checker, rhs_var);
variable.type = lhs_type.type; variable.type = lhs_type.type;
variable.typename = lhs_type.typename; variable.typename = lhs_type.typename;
variable.scope = lhs_type.scope; variable.scope = lhs_type.scope;
@@ -1532,6 +1533,10 @@ check_node :: (checker : *Semantic_Checker, node : *AST_Node) -> Type_Variable_H
} }
} }
} }
case .If_Directive; {
cond_var := check_node(checker, node.children[0]);
assert(false, "Not implemented yet\n");
}
case .Variable; { case .Variable; {
return check_variable(checker, node); return check_variable(checker, node);
} }

5
test/ifdefs.ink Normal file
View File

@@ -0,0 +1,5 @@
#if Defines.Skinning {
vertex main :: () {
// Stub
}
}