(*member)->type = type_build_from_ast(alloc, (*member)->type_node);
if ((*member)->type == NULL) {
+ if (context.cycle_detected) {
+ onyx_report_error((* member)->token->pos, Error_Critical, "Unable to figure out the type of this structure member.");
+ }
+
s_node->pending_type_is_valid = 0;
return accept_partial_types ? s_node->pending_type : NULL;
}
smem->token = (*member)->token;
smem->initial_value = &(*member)->initial_value;
smem->meta_tags = (*member)->meta_tags;
+ smem->member_node = *member;
smem->included_through_use = 0;
smem->used = (*member)->is_used;
case Ast_Kind_Alias: {
AstAlias* alias = (AstAlias *) type_node;
- return type_build_from_ast(alloc, (AstType *) alias->alias);
+ return type_build_from_ast_inner(alloc, (AstType *) alias->alias, accept_partial_types);
}
case Ast_Kind_Typeof: {
smem->included_through_use = 0;
smem->used = 0;
smem->use_through_pointer_index = -1;
+ smem->member_node = NULL;
// Having this present caused more issues than its
// worth. I don't think this is necessary, and it allows
new_smem->meta_tags = nsmem->meta_tags;
new_smem->used = nsmem->used;
new_smem->included_through_use = 1;
+ new_smem->member_node = nsmem->member_node;
if (type_is_pointer) {
new_smem->offset = nsmem->offset;
use core
-@conv.Custom_Format.{_format}
-@conv.Custom_Parse.{_parse}
Date :: struct {
year: i32;
- // Note that `month` and `day` are 0-based.
+ // Note that `month` is 0-based.
month, day: i32;
}
month_durations := u32.[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
make :: (year, month, day: i32) -> Date {
- return .{ year, month - 1, day - 1 };
+ return .{ year, month - 1, day };
+ }
+
+ today :: () -> Date {
+ return now()->as_date();
}
add_months :: (d: Date, days: i32) -> Date {
nd := d;
nd.day += days;
- while nd.day >= Date.month_durations[nd.month] {
+ while nd.day > Date.month_durations[nd.month] {
nd.day -= Date.month_durations[nd.month];
// February leap year case
return nd;
}
- before :: (d1, d2: Date) -> bool {
+ is_before :: (d1, d2: Date) -> bool {
if d1.year != d2.year do return d1.year < d2.year;
if d1.month != d2.month do return d1.month < d2.month;
return d1.day < d2.day;
}
- after :: (d1, d2: Date) -> bool {
+ is_after :: (d1, d2: Date) -> bool {
if d1.year != d2.year do return d1.year > d2.year;
if d1.month != d2.month do return d1.month > d2.month;
return d1.day > d2.day;
}
- _parse :: (d: ^Date, text: str, _: Allocator) -> bool {
- year, t := string.bisect(text, #char "-");
- month, t' := string.bisect(t, #char "-");
- day, t' := string.bisect(t, #char "-");
+}
+
+@conv.Custom_Format_Proc.{ Date }
+(output: ^conv.Format_Output, format: ^conv.Format, date: ^Date) {
+ conv.format(output, "{}-{w2}-{w2}", date.year, date.month + 1, date.day);
+}
- d.year = ~~ conv.str_to_i64(year);
- d.month = ~~ (conv.str_to_i64(month) - 1);
- d.day = ~~ (conv.str_to_i64(day) - 1);
+@conv.Custom_Parse_Proc.{ Date }
+(d: ^Date, text: str, _: Allocator) -> bool {
+ year, t := string.bisect(text, #char "-");
+ month, t' := string.bisect(t, #char "-");
+ day, t' := string.bisect(t, #char "-");
- return true;
- }
+ d.year = ~~ conv.str_to_i64(year);
+ d.month = ~~ (conv.str_to_i64(month) - 1);
+ d.day = ~~ conv.str_to_i64(day);
- _format :: (output: ^conv.Format_Output, format: ^conv.Format, date: ^Date) {
- conv.format(output, "{}-{w2}-{w2}", date.year, date.month + 1, date.day + 1);
- }
+ return true;
}
+
#operator + macro (d: Date, days: i32) => d->add_days(days);
#operator - macro (d: Date, days: i32) => d->add_days(-days);
}
return working;
-}
-#local
-parse_number_and_advance :: (buf: ^[] u8, result: ^i32, low, high, offset: i32) -> bool {
- use core {string}
+ //
+ // Helper function used above
+ parse_number_and_advance :: (buf: ^[] u8, result: ^i32, low, high, offset: i32) -> bool {
+ use core {string}
+
+ n := 0;
+ while buf.count > 0 {
+ c := buf.data[0];
+ if c < #char "0" || c > #char "9" {
+ break;
+ }
- n := 0;
- while buf.count > 0 {
- c := buf.data[0];
- if c < #char "0" || c > #char "9" {
- break;
+ n *= 10;
+ n += ~~(c - #char "0");
+ string.advance(buf);
}
- n *= 10;
- n += ~~(c - #char "0");
- string.advance(buf);
- }
+ if n >= low && n <= high {
+ *result = n + offset;
+ return true;
+ }
- if n >= low && n <= high {
- *result = n + offset;
- return true;
+ return false;
}
-
- return false;
}
#local {