refactored to remove AstAlias; have a better use for that name
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Wed, 7 Jul 2021 04:00:13 +0000 (23:00 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Wed, 7 Jul 2021 04:00:13 +0000 (23:00 -0500)
bin/onyx
core/type_info/helper.onyx
include/onyxastnodes.h
modules/immediate_mode/immediate_renderer.onyx
src/onyxastnodes.c
src/onyxclone.c
src/onyxparser.c
src/onyxsymres.c

index b37e2794e5ad0a34958e90106686feab3e134304..668b963666db02cdcea07df7675b85be0e436c91 100755 (executable)
Binary files a/bin/onyx and b/bin/onyx differ
index faa0704b8e0616ce02fd4070b44a9b082e9614e3..7801d82d4617bbf6e3605f57888f411e3cddd2c8 100644 (file)
@@ -113,3 +113,18 @@ write_type_name :: (writer: ^io.Writer, t: type_expr) {
         }            
     }
 }
+
+
+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
index 2dd0327c75f8dd2ffd2939bf624e901ea675c318..cf57b922d540e4db9fbbca778a03db30af7b77c6 100644 (file)
@@ -71,7 +71,6 @@
     NODE(MemRes)               \
     NODE(Include)              \
     NODE(UsePackage)           \
-    NODE(Alias)                \
     NODE(Global)               \
     NODE(Param)                \
     NODE(Function)             \
@@ -106,7 +105,6 @@ typedef enum AstKind {
     Ast_Kind_Package,
     Ast_Kind_Load_File,
     Ast_Kind_Load_Path,
-    Ast_Kind_Alias,
     Ast_Kind_Memres,
 
     Ast_Kind_Binding,
@@ -616,11 +614,16 @@ struct AstDirectiveSolidify {
 // 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
@@ -1065,6 +1068,9 @@ typedef struct Entity {
     Package *package;
     Scope *scope;
 
+    // TODO: This is incomplete. Add proper cycle detection and halting.
+    // struct Entity *waiting_on;
+
     union {
         AstDirectiveError     *error;
         AstInclude            *include;
index 1f750c503855683660e12a1d0165f4d28697c775..98f751aedb4d70b5c973c476048ef7c5cd7709e8 100644 (file)
@@ -94,17 +94,19 @@ Immediate_Renderer :: struct {
 
         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);
 
index 09168c19b32dd6473a75588e36c5ca0ab4a5fa4f..94a60c457265e03e4e3fbe536b79e993c3ab0bc5 100644 (file)
@@ -7,7 +7,6 @@ static const char* ast_node_names[] = {
     "PACKAGE",
     "INCLUDE FILE",
     "INCLUDE FOLDER",
-    "ALIAS",
     "MEMORY RESERVATION",
 
     "BINDING",
index 2d4145d4a3cc2dda55d574e07cbe68057ce3732b..bef0eec6e2943c582b3980ad82b24159c9ff88d0 100644 (file)
@@ -27,7 +27,6 @@ static inline i32 ast_kind_to_size(AstNode* node) {
         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);
index 4dfee9d5c4c07158e07f2a2e0504075c9c031e9c..e42fc8604a35ffbef72a687505fde73699d46388 100644 (file)
@@ -1215,15 +1215,15 @@ static AstNode* parse_use_stmt(OnyxParser* parser) {
         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, ',');
index 410444d57aecd21a8a5195a26ab9056a09f63ef8..b5e7c2fb764556f468c40adc082d6e726fc79372 100644 (file)
@@ -9,15 +9,14 @@ static Scope*       curr_scope    = NULL;
 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,
@@ -598,20 +597,20 @@ static SymresStatus symres_use(AstUse* use) {
             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);
             }
         }
 
@@ -637,16 +636,16 @@ static SymresStatus symres_use(AstUse* use) {
             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);
             }
         }