diff options
Diffstat (limited to 'src/stdlib/integers.c')
| -rw-r--r-- | src/stdlib/integers.c | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/src/stdlib/integers.c b/src/stdlib/integers.c index 863bb42d..e7a58ef3 100644 --- a/src/stdlib/integers.c +++ b/src/stdlib/integers.c @@ -674,43 +674,43 @@ void Int32$deserialize(FILE *in, void *outval, List_t *pointers, const TypeInfo_ } KindOfInt##Range_t; \ static Optional##KindOfInt##_t _next_##KindOfInt(KindOfInt##Range_t *info) { \ Optional##KindOfInt##_t i = info->current; \ - if (!i.is_none) { \ + if (i.has_value) { \ KindOfInt##_t next; \ bool overflow = __builtin_add_overflow(i.value, info->step, &next); \ if (overflow \ - || (!info->last.is_none && (info->step >= 0 ? next > info->last.value : next < info->last.value))) \ - info->current = (Optional##KindOfInt##_t){.is_none = true}; \ - else info->current = (Optional##KindOfInt##_t){.value = next}; \ + || (info->last.has_value && (info->step >= 0 ? next > info->last.value : next < info->last.value))) \ + info->current = (Optional##KindOfInt##_t){.has_value = false}; \ + else info->current = (Optional##KindOfInt##_t){.has_value = true, .value = next}; \ } \ return i; \ } \ public \ to_attr Closure_t KindOfInt##$to(c_type first, c_type last, Optional##KindOfInt##_t step) { \ KindOfInt##Range_t *range = GC_MALLOC(sizeof(KindOfInt##Range_t)); \ - range->current = (Optional##KindOfInt##_t){.value = first}; \ - range->last = (Optional##KindOfInt##_t){.value = last}; \ - range->step = step.is_none ? (last >= first ? 1 : -1) : step.value; \ + range->current = (Optional##KindOfInt##_t){.has_value = true, .value = first}; \ + range->last = (Optional##KindOfInt##_t){.has_value = true, .value = last}; \ + range->step = step.has_value ? step.value : (last >= first ? 1 : -1); \ return (Closure_t){.fn = _next_##KindOfInt, .userdata = range}; \ } \ public \ to_attr Closure_t KindOfInt##$onward(c_type first, c_type step) { \ KindOfInt##Range_t *range = GC_MALLOC(sizeof(KindOfInt##Range_t)); \ - range->current = (Optional##KindOfInt##_t){.value = first}; \ - range->last = (Optional##KindOfInt##_t){.is_none = true}; \ + range->current = (Optional##KindOfInt##_t){.has_value = true, .value = first}; \ + range->last = (Optional##KindOfInt##_t){.has_value = false}; \ range->step = step; \ return (Closure_t){.fn = _next_##KindOfInt, .userdata = range}; \ } \ public \ PUREFUNC Optional##KindOfInt##_t KindOfInt##$parse(Text_t text, Text_t *remainder) { \ OptionalInt_t full_int = Int$parse(text, remainder); \ - if (full_int.small == 0L) return (Optional##KindOfInt##_t){.is_none = true}; \ + if (full_int.small == 0L) return (Optional##KindOfInt##_t){.has_value = false}; \ if (Int$compare_value(full_int, I(min_val)) < 0) { \ - return (Optional##KindOfInt##_t){.is_none = true}; \ + return (Optional##KindOfInt##_t){.has_value = false}; \ } \ if (Int$compare_value(full_int, I(max_val)) > 0) { \ - return (Optional##KindOfInt##_t){.is_none = true}; \ + return (Optional##KindOfInt##_t){.has_value = false}; \ } \ - return (Optional##KindOfInt##_t){.value = KindOfInt##$from_int(full_int, true)}; \ + return (Optional##KindOfInt##_t){.has_value = true, .value = KindOfInt##$from_int(full_int, true)}; \ } \ public \ CONSTFUNC c_type KindOfInt##$gcd(c_type x, c_type y) { \ |
