}
}
}
+
+
+offset_of :: (T: type_expr, member: str) -> u32 {
+ info := get_type_info(T);
+ if info == null do return 0;
+ if info.kind != .Struct do return 0;
+
+ struct_info := cast(^Type_Info_Struct) info;
+ for ^m: struct_info.members {
+ if m.name == member do return m.offset;
+ }
+
+ // Should this return something else if the member was not found?
+ return 0;
+}
\ No newline at end of file
NODE(MemRes) \
NODE(Include) \
NODE(UsePackage) \
- NODE(Alias) \
NODE(Global) \
NODE(Param) \
NODE(Function) \
Ast_Kind_Package,
Ast_Kind_Load_File,
Ast_Kind_Load_Path,
- Ast_Kind_Alias,
Ast_Kind_Memres,
Ast_Kind_Binding,
// Intruction Node
struct AstReturn { AstNode_base; AstTyped* expr; };
struct AstJump { AstNode_base; JumpType jump; u32 count; };
+
+typedef struct QualifiedUse {
+ OnyxToken* symbol_name;
+ OnyxToken* as_name;
+} QualifiedUse;
struct AstUse {
AstNode_base;
AstTyped* expr;
- bh_arr(AstAlias *) only;
+ bh_arr(QualifiedUse) only;
};
// Structure Nodes
Package *package;
Scope *scope;
+ // TODO: This is incomplete. Add proper cycle detection and halting.
+ // struct Entity *waiting_on;
+
union {
AstDirectiveError *error;
AstInclude *include;
gl.bindBuffer(gl.ARRAY_BUFFER, vertex_buffer);
+ use package builtin.type_info { offset_of };
+
// Position
gl.enableVertexAttribArray(0);
- gl.vertexAttribPointer(0, 2, gl.FLOAT, false, sizeof Immediate_Vertex, 0);
+ gl.vertexAttribPointer(0, 2, gl.FLOAT, false, sizeof Immediate_Vertex, offset_of(Immediate_Vertex, "position"));
// Color
gl.enableVertexAttribArray(1);
- gl.vertexAttribPointer(1, 4, gl.FLOAT, false, sizeof Immediate_Vertex, 2 * sizeof f32);
+ gl.vertexAttribPointer(1, 4, gl.FLOAT, false, sizeof Immediate_Vertex, offset_of(Immediate_Vertex, "color"));
// Texture
gl.enableVertexAttribArray(2);
- gl.vertexAttribPointer(2, 2, gl.FLOAT, false, sizeof Immediate_Vertex, 6 * sizeof f32);
+ gl.vertexAttribPointer(2, 2, gl.FLOAT, false, sizeof Immediate_Vertex, offset_of(Immediate_Vertex, "texture"));
gl.bindBuffer(gl.ARRAY_BUFFER, -1);
"PACKAGE",
"INCLUDE FILE",
"INCLUDE FOLDER",
- "ALIAS",
"MEMORY RESERVATION",
"BINDING",
case Ast_Kind_Package: return sizeof(AstPackage);
case Ast_Kind_Load_File: return sizeof(AstInclude);
case Ast_Kind_Load_Path: return sizeof(AstInclude);
- case Ast_Kind_Alias: return sizeof(AstAlias);
case Ast_Kind_Memres: return sizeof(AstMemRes);
case Ast_Kind_Binding: return sizeof(AstBinding);
case Ast_Kind_Function: return sizeof(AstFunction);
while (!consume_token_if_next(parser, '}')) {
if (parser->hit_unexpected_token) return NULL;
- AstAlias* alias = make_node(AstAlias, Ast_Kind_Alias);
- alias->token = expect_token(parser, Token_Type_Symbol);
+ QualifiedUse qu;
+ qu.symbol_name = expect_token(parser, Token_Type_Symbol);
if (consume_token_if_next(parser, Token_Type_Keyword_As))
- alias->alias = expect_token(parser, Token_Type_Symbol);
+ qu.as_name = expect_token(parser, Token_Type_Symbol);
else
- alias->alias = alias->token;
+ qu.as_name = qu.symbol_name;
- bh_arr_push(use_node->only, alias);
+ bh_arr_push(use_node->only, qu);
if (parser->curr->type != '}')
expect_token(parser, ',');
bh_arr(AstBlock *) block_stack = NULL;
static b32 report_unresolved_symbols = 1;
+// Everything related to waiting on is imcomplete at the moment.
+static Entity* waiting_on = NULL;
+
#define SYMRES(kind, ...) do { \
SymresStatus ss = symres_ ## kind (__VA_ARGS__); \
if (ss > Symres_Errors_Start) return ss; \
} while (0)
-#define SYMRES_IF_SYMBOL(node_ptr) do { \
- if ((*(node_ptr))->kind == Ast_Kind_Symbol) SYMRES(expression, node_ptr); \
- } while (0);
-
typedef enum SymresStatus {
Symres_Success,
Symres_Complete,
scope_include(curr_scope, package->package->scope, pos);
} else {
- bh_arr_each(AstAlias *, alias, use->only) {
- AstNode* thing = symbol_resolve(package->package->scope, (*alias)->token);
+ bh_arr_each(QualifiedUse, qu, use->only) {
+ AstNode* thing = symbol_resolve(package->package->scope, qu->symbol_name);
if (thing == NULL) { // :SymresStall
if (report_unresolved_symbols) {
- onyx_report_error((*alias)->token->pos,
+ onyx_report_error(qu->symbol_name->pos,
"The symbol '%b' was not found in this package.",
- (*alias)->token->text, (*alias)->token->length);
+ qu->symbol_name->text, qu->symbol_name->length);
return Symres_Error;
} else {
return Symres_Yield_Macro;
}
}
- symbol_introduce(curr_scope, (*alias)->alias, thing);
+ symbol_introduce(curr_scope, qu->as_name, thing);
}
}
scope_include(curr_scope, st->scope, use->token->pos);
} else {
- bh_arr_each(AstAlias *, alias, use->only) {
- AstNode* thing = symbol_resolve(st->scope, (*alias)->token);
+ bh_arr_each(QualifiedUse, qu, use->only) {
+ AstNode* thing = symbol_resolve(st->scope, qu->symbol_name);
if (thing == NULL) {
- onyx_report_error((*alias)->token->pos,
+ onyx_report_error(qu->symbol_name->pos,
"The symbol '%b' was not found in this scope.",
- (*alias)->token->text, (*alias)->token->length);
+ qu->symbol_name->text, qu->symbol_name->length);
return Symres_Error;
}
- symbol_introduce(curr_scope, (*alias)->alias, thing);
+ symbol_introduce(curr_scope, qu->as_name, thing);
}
}