}
close :: ($T: type_expr, fi: ^FilterIterator(T)) {
- fi.iterator.close(fi.iterator.data);
+ if fi.iterator.close != null_proc do fi.iterator.close(fi.iterator.data);
cfree(fi);
}
}
close :: ($T: type_expr, $R: type_expr, mi: ^MapIterator(T, R)) {
- mi.iterator.close(mi.iterator.data);
+ if mi.iterator.close != null_proc do mi.iterator.close(mi.iterator.data);
cfree(mi);
}
}
close :: ($T: type_expr, ti: ^TakeIterator(T)) {
- ti.iterator.close(ti.iterator.data);
+ if ti.iterator.close != null_proc do ti.iterator.close(ti.iterator.data);
cfree(ti);
}
}
close :: ($T: type_expr, si: ^SkipIterator(T)) {
- si.iterator.close(si.iterator.data);
+ if si.iterator.close != null_proc do si.iterator.close(si.iterator.data);
cfree(si);
}
}
close :: ($T: type_expr, $R: type_expr, zi: ^ZippedIterator(T, R)) {
- zi.iterator1.close(zi.iterator1.data);
- zi.iterator2.close(zi.iterator2.data);
+ if zi.iterator1.close != null_proc do zi.iterator1.close(zi.iterator1.data);
+ if zi.iterator2.close != null_proc do zi.iterator2.close(zi.iterator2.data);
cfree(zi);
}
};
}
+#private_file Enumeration_Value :: struct (T: type_expr) {
+ index: i32;
+ value: T;
+}
+
+enumerate :: (it: Iterator($T), start_index: i32 = 0) -> Iterator(Enumeration_Value(T)) {
+ Enumeration_Context :: struct (T: type_expr) {
+ iterator: Iterator(T);
+ current_index: i32;
+ }
+
+ ec := make(#type Enumeration_Context(T));
+ ec.iterator = it;
+ ec.current_index = start_index;
+
+ next :: ($T: type_expr, use data: ^Enumeration_Context(T)) -> (Enumeration_Value(T), bool) {
+ value, cont := iterator.next(iterator.data);
+
+ if !cont do return .{ current_index, __zero_value(T) }, false;
+
+ defer current_index += 1;
+ return .{ current_index, value }, true;
+ }
+
+ close :: ($T: type_expr, use data: ^Enumeration_Context(T)) {
+ if iterator.close != null_proc do iterator.close(iterator.data);
+ cfree(data);
+ }
+
+ return .{
+ data = ec,
+ next = #solidify next { T = T },
+ close = #solidify close { T = T },
+ };
+}
+
+from_array :: (arr: [..] $T) -> Iterator(^T) {
+ return from_slice((#type [] T).{ arr.data, arr.count });
+}
+
+from_slice :: (arr: [] $T) -> Iterator(^T) {
+ Context :: struct (T: type_expr) {
+ data: ^T;
+ count: u32;
+ current: u32;
+ }
+
+ c := make(#type Context(T));
+ c.data = arr.data;
+ c.count = arr.count;
+ c.current = 0;
+
+ next :: ($T: type_expr, use _: ^Context(T)) -> (^T, bool) {
+ if current < count {
+ defer current += 1;
+ return ^data[current], true;
+
+ } else {
+ return null, false;
+ }
+ }
+
+ close :: (data: rawptr) {
+ cfree(data);
+ }
+
+ return .{
+ data = c,
+ next = #solidify next { T = T },
+ close = close,
+ };
+}
+
fold :: (it: Iterator($T), initial_value: R, combine: (T, $R) -> R) -> R {
for value: it {
initial_value = combine(value, initial_value);
.scope = solidified_func.poly_scope,
};
- entity_bring_to_state(&func_header_entity, Entity_State_Code_Gen);
+ b32 successful = entity_bring_to_state(&func_header_entity, Entity_State_Code_Gen);
if (onyx_has_errors()) {
onyx_clear_errors();
return NULL;
// NOTE: Overload is not something that is known to be overloadable.
if (overload == NULL) continue;
if (overload->kind != Ast_Kind_Function) continue;
- if (overload->type == NULL) continue;
- assert(overload->type->kind == Type_Kind_Function);
+ // if (overload->type == NULL) continue;
+ // assert(overload->type->kind == Type_Kind_Function);
// NOTE: If the arguments cannot be placed successfully in the parameters list
if (!fill_in_arguments(&args, (AstNode *) overload, NULL)) continue;
return NULL;
}
-void entity_bring_to_state(Entity* ent, EntityState state) {
+b32 entity_bring_to_state(Entity* ent, EntityState state) {
EntityState last_state = ent->state;
while (ent->state != state) {
case Entity_State_Check_Types: check_entity(ent); break;
case Entity_State_Code_Gen: emit_entity(ent); break;
- default: return;
+ default: return 0;
}
- if (ent->state == last_state) break;
+ if (ent->state == last_state) return 0;
last_state = ent->state;
- if (onyx_has_errors()) return;
+ if (onyx_has_errors()) return 0;
}
+
+ return 1;
}