With the recent addition of compile time if statements, there should be a set of variables
that give information about the current compilation. These would include things such as:
- - Chosen backend (JS, WASI, others in the future)
+ - Chosen runtime (JS, WASI, others in the future)
- 32-Bit pointers are enabled
The standard library will be rewritten to use these variables to conditionally include file
typedef struct AstDirectiveSolidify AstDirectiveSolidify;
typedef struct AstStaticIf AstStaticIf;
+typedef struct AstDirectiveError AstDirectiveError;
typedef struct AstReturn AstReturn;
typedef struct AstJump AstJump;
Ast_Kind_Directive_Solidify,
Ast_Kind_Static_If,
+ Ast_Kind_Directive_Error,
Ast_Kind_Count
} AstKind;
bh_arr(struct Entity *) false_entities;
};
+struct AstDirectiveError {
+ AstNode_base;
+ OnyxToken* error_msg;
+};
extern AstNode empty_node;
typedef enum EntityType {
Entity_Type_Unknown,
+ Entity_Type_Error,
Entity_Type_Load_Path,
Entity_Type_Load_File,
Entity_Type_Binding,
Scope *scope;
union {
+ AstDirectiveError *error;
AstInclude *include;
AstUsePackage *use_package;
AstBinding *binding;
EntityState before_state = ent->state;
switch (before_state) {
+ case Entity_State_Error:
+ if (ent->type != Entity_Type_Error) {
+ onyx_report_error(ent->expr->token->pos, "Error entity unexpected. This is definitely a compiler bug");
+ } else {
+ onyx_report_error(ent->error->token->pos, "Static error occured: '%b'", ent->error->error_msg->text, ent->error->error_msg->length);
+ }
+ break;
+
case Entity_State_Parse_Builtin:
process_load_entity(ent);
ent->state = Entity_State_Finalized;
"SOLIDIFY",
"STATIC IF",
+ "STATIC ERROR",
"AST_NODE_KIND_COUNT",
};
ENTITY_INSERT(ent);
break;
}
+
+ case Ast_Kind_Directive_Error: {
+ ent.state = Entity_State_Error;
+ ent.type = Entity_Type_Error;
+ ent.error = (AstDirectiveError *) node;
+ ENTITY_INSERT(ent);
+ break;
+ }
default: {
ent.type = Entity_Type_Expression;
static_if_node->cond = parse_expression(parser, 0);
- // TODO: Add else statements to static ifs
bh_arr_new(global_heap_allocator, static_if_node->true_entities, 2);
bh_arr_push(parser->alternate_entity_placement_stack, &static_if_node->true_entities);
ENTITY_SUBMIT(include);
return;
}
+ else if (parse_possible_directive(parser, "error")) {
+ AstDirectiveError *error = make_node(AstDirectiveError, Ast_Kind_Directive_Error);
+ error->token = dir_token;
+ error->error_msg = expect_token(parser, Token_Type_Literal_String);
+
+ ENTITY_SUBMIT(error);
+ return;
+ }
else {
OnyxToken* directive_token = expect_token(parser, '#');
OnyxToken* symbol_token = expect_token(parser, Token_Type_Symbol);