~lattis/muon

3723275e6adc226fe811bd88bf3480b8df9a84de — Stone Tickle a month ago 02cb03e
fix array flattening iterator
4 files changed, 13 insertions(+), 9 deletions(-)

M include/lang/object_iterators.h
M src/lang/vm.c
M tests/lang/array.meson
M tests/lang/dict.meson
M include/lang/object_iterators.h => include/lang/object_iterators.h +1 -4
@@ 79,7 79,6 @@ struct obj_array_flat_for_helper {
	struct workspace *wk;
	struct obj_array *a;
	uint32_t stack_base;
	bool empty;
};

#define obj_array_flat_for_begin(__wk, __arr, __val)                                                                  \


@@ 89,18 88,16 @@ struct obj_array_flat_for_helper {
			.a = get_obj_array(__wk, __arr),                                                              \
			.stack_base = __wk->stack.len,                                                                \
		};                                                                                                    \
		__flat_iter.empty = __flat_iter.a->len == 0;                                                          \
                                                                                                                      \
		while (true) {                                                                                        \
			__val = __flat_iter.a->val;                                                                   \
			if (get_obj_type(__flat_iter.wk, __val) == obj_array) {                                       \
				stack_push(                                                                           \
					&__flat_iter.wk->stack, __flat_iter.a, get_obj_array(__flat_iter.wk, __val)); \
				__flat_iter.empty = __flat_iter.a->len == 0;                                          \
				continue;                                                                             \
			}                                                                                             \
                                                                                                                      \
			if (!__flat_iter.empty)
			if (__val)

#define obj_array_flat_for_end                                                                            \
	}                                                                                                 \

M src/lang/vm.c => src/lang/vm.c +1 -0
@@ 256,6 256,7 @@ typecheck_function_arg(struct workspace *wk, uint32_t ip, obj *val, type_tag typ
				}

				obj_array_push(wk, arr, v);

				obj_array_flat_for_end;
			}
		} else {

M tests/lang/array.meson => tests/lang/array.meson +6 -0
@@ 1,6 1,12 @@
# SPDX-FileCopyrightText: Stone Tickle <lattis@mochiro.moe>
# SPDX-License-Identifier: GPL-3.0-only

func listify(a glob[int]) -> list[int]
    return a
endfunc

assert(p(listify([[1, [], [2], [[], [], [], [], [[]]]], [[[]]], 4])) == [1, 2, 4])

assert(1 not in [2, 3, 4])

assert([1, 2, 3, 4, 5].contains(3))

M tests/lang/dict.meson => tests/lang/dict.meson +5 -5
@@ 43,12 43,12 @@ d = d + {'a': 4, 'b': 3, 'e': 5}
assert(d.keys() == ['b', 'c', 'a', 'e'])

func big_dict(n int) -> dict[int]
	d = {}
	foreach i : range(n)
            d += {f'@i@': i}
	endforeach
    d = {}
    foreach i : range(n)
        d += {f'@i@': i}
    endforeach

        return d
    return d
endfunc

n = 128