diff options
| author | Zuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian> | 2026-01-17 17:34:48 +0000 |
|---|---|---|
| committer | Zuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian> | 2026-01-17 17:34:48 +0000 |
| commit | 661a71defc66cfeea1681dddd944ba017087f78a (patch) | |
| tree | 58fab93bde052d53930a5ab2fbe3ac105d0136d9 | |
| parent | 6b2545224752be74de35166c3dcda9ff5bdb79e3 (diff) | |
Fix for #62
| -rw-r--r-- | src/codegen/codegen_main.c | 12 | ||||
| -rw-r--r-- | std/vec.zc | 4 |
2 files changed, 8 insertions, 8 deletions
diff --git a/src/codegen/codegen_main.c b/src/codegen/codegen_main.c index 3634af3..ea90131 100644 --- a/src/codegen/codegen_main.c +++ b/src/codegen/codegen_main.c @@ -52,12 +52,12 @@ static ASTNode *topo_sort_structs(ASTNode *head) return NULL; } - // Count all nodes (structs + enums). + // Count all nodes (structs + enums + traits). int count = 0; ASTNode *n = head; while (n) { - if (n->type == NODE_STRUCT || n->type == NODE_ENUM) + if (n->type == NODE_STRUCT || n->type == NODE_ENUM || n->type == NODE_TRAIT) { count++; } @@ -75,7 +75,7 @@ static ASTNode *topo_sort_structs(ASTNode *head) int idx = 0; while (n) { - if (n->type == NODE_STRUCT || n->type == NODE_ENUM) + if (n->type == NODE_STRUCT || n->type == NODE_ENUM || n->type == NODE_TRAIT) { nodes[idx++] = n; } @@ -102,8 +102,8 @@ static ASTNode *topo_sort_structs(ASTNode *head) continue; } - // Enums have no dependencies, emit first. - if (nodes[i]->type == NODE_ENUM) + // Enums and traits have no dependencies, emit first. + if (nodes[i]->type == NODE_ENUM || nodes[i]->type == NODE_TRAIT) { order[order_idx++] = i; emitted[i] = 1; @@ -334,12 +334,12 @@ void codegen_node(ParserContext *ctx, ASTNode *node, FILE *out) print_type_defs(ctx, out, sorted); emit_enum_protos(sorted, out); + emit_trait_defs(kids, out); if (sorted) { emit_struct_defs(ctx, sorted, out); } - emit_trait_defs(kids, out); ASTNode *raw_iter = kids; while (raw_iter) @@ -90,7 +90,7 @@ impl Vec<T> { fn contains(self, item: T) -> bool { var i: usize = 0; while i < self.len { - if self.data[i] == item { return true; } + if memcmp(&self.data[i], &item, sizeof(T)) == 0 { return true; } i++; } return false; @@ -143,7 +143,7 @@ impl Vec<T> { if self.len != other.len { return false; } var i: usize = 0; while i < self.len { - if self.data[i] != other.data[i] { return false; } + if memcmp(&self.data[i], &other.data[i], sizeof(T)) != 0 { return false; } i = i + 1; } return true; |
