@shd101wyy/yo 0.0.13 → 0.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -1
- package/out/cjs/index.cjs +5598 -45
- package/out/cjs/yo-cli.cjs +755 -764
- package/out/esm/index.mjs +5595 -42
- package/out/types/src/codegen/async/state-code-gen.d.ts +3 -3
- package/out/types/src/codegen/async/state-machine.d.ts +4 -4
- package/out/types/src/codegen/c/collection.d.ts +1 -1
- package/out/types/src/codegen/codegen-c.d.ts +1 -1
- package/out/types/src/codegen/constants.d.ts +1 -1
- package/out/types/src/codegen/exprs/{and_or.d.ts → and-or.d.ts} +2 -2
- package/out/types/src/codegen/exprs/{array_fns.d.ts → array-fns.d.ts} +2 -2
- package/out/types/src/codegen/exprs/assignment.d.ts +2 -2
- package/out/types/src/codegen/exprs/async.d.ts +2 -2
- package/out/types/src/codegen/exprs/atom.d.ts +2 -2
- package/out/types/src/codegen/exprs/await.d.ts +2 -2
- package/out/types/src/codegen/exprs/begin.d.ts +2 -2
- package/out/types/src/codegen/exprs/binding.d.ts +2 -2
- package/out/types/src/codegen/exprs/closures.d.ts +3 -3
- package/out/types/src/codegen/exprs/comptime-value.d.ts +4 -0
- package/out/types/src/codegen/exprs/cond.d.ts +2 -2
- package/out/types/src/codegen/exprs/consume.d.ts +2 -2
- package/out/types/src/codegen/exprs/{drop_dup.d.ts → drop-dup.d.ts} +4 -4
- package/out/types/src/codegen/exprs/dyn.d.ts +2 -2
- package/out/types/src/codegen/exprs/expr.d.ts +2 -2
- package/out/types/src/codegen/exprs/gc.d.ts +2 -2
- package/out/types/src/codegen/exprs/generation.d.ts +2 -2
- package/out/types/src/codegen/exprs/{initialization_assignment.d.ts → initialization-assignment.d.ts} +2 -2
- package/out/types/src/codegen/exprs/{inline_fns.d.ts → inline-fns.d.ts} +2 -2
- package/out/types/src/codegen/exprs/iso.d.ts +2 -2
- package/out/types/src/codegen/exprs/match.d.ts +2 -2
- package/out/types/src/codegen/exprs/open.d.ts +2 -2
- package/out/types/src/codegen/exprs/{other_fn_call.d.ts → other-fn-call.d.ts} +2 -2
- package/out/types/src/codegen/exprs/panic.d.ts +2 -2
- package/out/types/src/codegen/exprs/parallelism.d.ts +2 -2
- package/out/types/src/codegen/exprs/{property_access.d.ts → property-access.d.ts} +2 -2
- package/out/types/src/codegen/exprs/{ptr_fns.d.ts → ptr-fns.d.ts} +2 -2
- package/out/types/src/codegen/exprs/{rc_fns.d.ts → rc-fns.d.ts} +2 -2
- package/out/types/src/codegen/exprs/recur.d.ts +2 -2
- package/out/types/src/codegen/exprs/return.d.ts +2 -2
- package/out/types/src/codegen/exprs/sizeof.d.ts +2 -2
- package/out/types/src/codegen/exprs/{tuple_fn.d.ts → tuple-fn.d.ts} +2 -2
- package/out/types/src/codegen/exprs/while.d.ts +2 -2
- package/out/types/src/codegen/functions/collection.d.ts +4 -3
- package/out/types/src/codegen/functions/context.d.ts +6 -6
- package/out/types/src/codegen/functions/declarations.d.ts +4 -4
- package/out/types/src/codegen/functions/dyn.d.ts +1 -1
- package/out/types/src/codegen/functions/generation.d.ts +5 -5
- package/out/types/src/codegen/types/collection.d.ts +4 -4
- package/out/types/src/codegen/types/dyn.d.ts +2 -2
- package/out/types/src/codegen/types/generation.d.ts +2 -2
- package/out/types/src/codegen/utils/fixup.d.ts +1 -1
- package/out/types/src/codegen/utils/index.d.ts +6 -6
- package/out/types/src/env.d.ts +34 -5
- package/out/types/src/error.d.ts +1 -1
- package/out/types/src/evaluator/async/await-analysis-types.d.ts +1 -1
- package/out/types/src/evaluator/async/await-analysis.d.ts +1 -1
- package/out/types/src/evaluator/builtins/alignof.d.ts +3 -3
- package/out/types/src/evaluator/builtins/{and_or.d.ts → and-or.d.ts} +3 -3
- package/out/types/src/evaluator/builtins/{array_fns.d.ts → array-fns.d.ts} +3 -3
- package/out/types/src/evaluator/builtins/as.d.ts +3 -3
- package/out/types/src/evaluator/builtins/{async_fns.d.ts → async-fns.d.ts} +3 -3
- package/out/types/src/evaluator/builtins/comptime-assert.d.ts +8 -0
- package/out/types/src/evaluator/builtins/comptime-bool-fns.d.ts +8 -0
- package/out/types/src/evaluator/builtins/comptime-expect-error.d.ts +8 -0
- package/out/types/src/evaluator/builtins/comptime-fn.d.ts +8 -0
- package/out/types/src/evaluator/builtins/comptime-list-fns.d.ts +33 -0
- package/out/types/src/evaluator/builtins/comptime-numeric-fns.d.ts +8 -0
- package/out/types/src/evaluator/builtins/comptime-print.d.ts +8 -0
- package/out/types/src/evaluator/builtins/comptime-string-fns.d.ts +8 -0
- package/out/types/src/evaluator/builtins/consume.d.ts +3 -3
- package/out/types/src/evaluator/builtins/drop.d.ts +3 -3
- package/out/types/src/evaluator/builtins/dup.d.ts +3 -3
- package/out/types/src/evaluator/builtins/{expr_fns.d.ts → expr-fns.d.ts} +3 -3
- package/out/types/src/evaluator/builtins/{future_fns.d.ts → future-fns.d.ts} +3 -3
- package/out/types/src/evaluator/builtins/gc.d.ts +3 -3
- package/out/types/src/evaluator/builtins/gensym.d.ts +3 -3
- package/out/types/src/evaluator/builtins/{impl_constraint.d.ts → impl-constraint.d.ts} +3 -3
- package/out/types/src/evaluator/builtins/{macro_expand.d.ts → macro-expand.d.ts} +3 -3
- package/out/types/src/evaluator/builtins/panic.d.ts +3 -3
- package/out/types/src/evaluator/builtins/process.d.ts +3 -3
- package/out/types/src/evaluator/builtins/{ptr_fns.d.ts → ptr-fns.d.ts} +3 -3
- package/out/types/src/evaluator/builtins/quote.d.ts +3 -3
- package/out/types/src/evaluator/builtins/{rc_fns.d.ts → rc-fns.d.ts} +3 -3
- package/out/types/src/evaluator/builtins/rc.d.ts +3 -3
- package/out/types/src/evaluator/builtins/sizeof.d.ts +3 -3
- package/out/types/src/evaluator/builtins/the.d.ts +3 -3
- package/out/types/src/evaluator/builtins/{type_fns.d.ts → type-fns.d.ts} +3 -3
- package/out/types/src/evaluator/builtins/{va_start.d.ts → va-start.d.ts} +3 -3
- package/out/types/src/evaluator/builtins/{var_fns.d.ts → var-fns.d.ts} +3 -3
- package/out/types/src/evaluator/calls/{array_type.d.ts → array-type.d.ts} +4 -4
- package/out/types/src/evaluator/calls/array.d.ts +5 -5
- package/out/types/src/evaluator/calls/{closure_type.d.ts → closure-type.d.ts} +4 -4
- package/out/types/src/evaluator/calls/comptime-fn.d.ts +19 -0
- package/out/types/src/evaluator/calls/comptime-list-type.d.ts +11 -0
- package/out/types/src/evaluator/calls/{function_type.d.ts → function-type.d.ts} +5 -5
- package/out/types/src/evaluator/calls/function.d.ts +6 -6
- package/out/types/src/evaluator/calls/helper.d.ts +6 -6
- package/out/types/src/evaluator/calls/iso.d.ts +4 -4
- package/out/types/src/evaluator/calls/{module_type.d.ts → module-type.d.ts} +4 -4
- package/out/types/src/evaluator/calls/{numeric_type.d.ts → numeric-type.d.ts} +4 -4
- package/out/types/src/evaluator/calls/{pointer_type.d.ts → pointer-type.d.ts} +4 -4
- package/out/types/src/evaluator/calls/pointer.d.ts +3 -3
- package/out/types/src/evaluator/calls/{trait_type.d.ts → trait-type.d.ts} +4 -4
- package/out/types/src/evaluator/calls/type.d.ts +4 -4
- package/out/types/src/evaluator/context.d.ts +6 -6
- package/out/types/src/evaluator/ctfe/ctfe-analysis.d.ts +5 -5
- package/out/types/src/evaluator/exprs/_expr.d.ts +3 -3
- package/out/types/src/evaluator/exprs/assignment.d.ts +3 -3
- package/out/types/src/evaluator/exprs/begin.d.ts +3 -3
- package/out/types/src/evaluator/exprs/binding.d.ts +3 -3
- package/out/types/src/evaluator/exprs/{c_include.d.ts → c-include.d.ts} +3 -3
- package/out/types/src/evaluator/exprs/cond.d.ts +3 -3
- package/out/types/src/evaluator/exprs/{destructuring_assignment.d.ts → destructuring-assignment.d.ts} +5 -5
- package/out/types/src/evaluator/exprs/expr.d.ts +3 -3
- package/out/types/src/evaluator/exprs/extern.d.ts +3 -3
- package/out/types/src/evaluator/exprs/{identifer_and_operator.d.ts → identifer-and-operator.d.ts} +3 -3
- package/out/types/src/evaluator/exprs/import.d.ts +3 -3
- package/out/types/src/evaluator/exprs/{initialization_assignment.d.ts → initialization-assignment.d.ts} +3 -3
- package/out/types/src/evaluator/exprs/match.d.ts +3 -3
- package/out/types/src/evaluator/exprs/open.d.ts +3 -3
- package/out/types/src/evaluator/exprs/{property_access.d.ts → property-access.d.ts} +3 -3
- package/out/types/src/evaluator/exprs/recur.d.ts +3 -3
- package/out/types/src/evaluator/exprs/runtime.d.ts +3 -3
- package/out/types/src/evaluator/exprs/subtype-of.d.ts +8 -0
- package/out/types/src/evaluator/exprs/test.d.ts +3 -3
- package/out/types/src/evaluator/exprs/typeof.d.ts +3 -3
- package/out/types/src/evaluator/exprs/while.d.ts +3 -3
- package/out/types/src/evaluator/index.d.ts +4 -4
- package/out/types/src/evaluator/trait-checking.d.ts +31 -0
- package/out/types/src/evaluator/types/array.d.ts +3 -3
- package/out/types/src/evaluator/types/closure.d.ts +3 -3
- package/out/types/src/evaluator/types/comptime-list.d.ts +8 -0
- package/out/types/src/evaluator/types/{concrete_trait.d.ts → concrete-trait.d.ts} +3 -3
- package/out/types/src/evaluator/types/dyn.d.ts +3 -3
- package/out/types/src/evaluator/types/enum.d.ts +3 -3
- package/out/types/src/evaluator/types/{expr_synthesizer.d.ts → expr-synthesizer.d.ts} +4 -4
- package/out/types/src/evaluator/types/field.d.ts +4 -4
- package/out/types/src/evaluator/types/{fn_trait.d.ts → fn-trait.d.ts} +3 -3
- package/out/types/src/evaluator/types/function.d.ts +16 -10
- package/out/types/src/evaluator/types/{future_trait.d.ts → future-trait.d.ts} +3 -3
- package/out/types/src/evaluator/types/module.d.ts +4 -4
- package/out/types/src/evaluator/types/newtype.d.ts +3 -3
- package/out/types/src/evaluator/types/object.d.ts +3 -3
- package/out/types/src/evaluator/types/slice.d.ts +3 -3
- package/out/types/src/evaluator/types/struct.d.ts +3 -3
- package/out/types/src/evaluator/types/synthesizer.d.ts +2 -2
- package/out/types/src/evaluator/types/trait.d.ts +4 -4
- package/out/types/src/evaluator/types/tuple.d.ts +4 -4
- package/out/types/src/evaluator/types/union.d.ts +3 -3
- package/out/types/src/evaluator/types/utils.d.ts +84 -5
- package/out/types/src/evaluator/types/validation.d.ts +2 -2
- package/out/types/src/evaluator/utils/closure.d.ts +7 -7
- package/out/types/src/evaluator/utils.d.ts +2 -2
- package/out/types/src/evaluator/values/{anonymous_function.d.ts → anonymous-function.d.ts} +3 -3
- package/out/types/src/evaluator/values/{anonymous_module.d.ts → anonymous-module.d.ts} +5 -5
- package/out/types/src/evaluator/values/{anonymous_struct.d.ts → anonymous-struct.d.ts} +3 -3
- package/out/types/src/evaluator/values/array.d.ts +3 -3
- package/out/types/src/evaluator/values/boolean.d.ts +2 -2
- package/out/types/src/evaluator/values/char.d.ts +2 -2
- package/out/types/src/evaluator/values/{clone_value.d.ts → clone-value.d.ts} +1 -1
- package/out/types/src/evaluator/values/comptime-list.d.ts +8 -0
- package/out/types/src/evaluator/values/dyn.d.ts +3 -3
- package/out/types/src/evaluator/values/float.d.ts +3 -3
- package/out/types/src/evaluator/values/impl.d.ts +5 -5
- package/out/types/src/evaluator/values/integer.d.ts +3 -3
- package/out/types/src/evaluator/values/string.d.ts +2 -2
- package/out/types/src/evaluator/values/tuple.d.ts +5 -5
- package/out/types/src/expr.d.ts +283 -283
- package/out/types/src/function-value.d.ts +6 -6
- package/out/types/src/index.d.ts +3 -0
- package/out/types/src/lexer.d.ts +1 -1
- package/out/types/src/module-manager.d.ts +1 -1
- package/out/types/src/parser.d.ts +2 -2
- package/out/types/src/test-runner.d.ts +1 -1
- package/out/types/src/type-value.d.ts +1 -1
- package/out/types/src/types/compatibility.d.ts +2 -2
- package/out/types/src/types/creators.d.ts +29 -16
- package/out/types/src/types/definitions.d.ts +29 -26
- package/out/types/src/types/env-lookup.d.ts +4 -0
- package/out/types/src/types/guards.d.ts +6 -6
- package/out/types/src/types/hierarchy.d.ts +2 -2
- package/out/types/src/types/tags.d.ts +4 -4
- package/out/types/src/types/utils.d.ts +13 -38
- package/out/types/src/unit-value.d.ts +1 -1
- package/out/types/src/value-tag.d.ts +4 -4
- package/out/types/src/value.d.ts +32 -26
- package/out/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -1
- package/std/allocator.yo +5 -5
- package/std/collections/array_list.yo +394 -390
- package/std/collections/hash_map.yo +411 -406
- package/std/collections/hash_set.yo +646 -642
- package/std/collections/linked_list.yo +347 -341
- package/std/io.yo +55 -53
- package/std/path.yo +17 -16
- package/std/prelude.yo +1587 -1455
- package/std/string/rune.yo +25 -24
- package/std/string/string.yo +46 -43
- package/std/sync.yo +50 -30
- package/std/thread.yo +6 -5
- package/std/time.yo +1 -1
- package/out/types/src/codegen/exprs/compt_value.d.ts +0 -4
- package/out/types/src/codegen/types/index.d.ts +0 -3
- package/out/types/src/codegen/values/index.d.ts +0 -1
- package/out/types/src/evaluator/builtins/compt_assert.d.ts +0 -8
- package/out/types/src/evaluator/builtins/compt_boolean_fns.d.ts +0 -8
- package/out/types/src/evaluator/builtins/compt_expect_error.d.ts +0 -8
- package/out/types/src/evaluator/builtins/compt_fn.d.ts +0 -8
- package/out/types/src/evaluator/builtins/compt_list_fns.d.ts +0 -33
- package/out/types/src/evaluator/builtins/compt_numeric_fns.d.ts +0 -8
- package/out/types/src/evaluator/builtins/compt_print.d.ts +0 -8
- package/out/types/src/evaluator/builtins/compt_string_fns.d.ts +0 -8
- package/out/types/src/evaluator/calls/compt_function.d.ts +0 -19
- package/out/types/src/evaluator/calls/compt_list_type.d.ts +0 -11
- package/out/types/src/evaluator/exprs/subtype_of.d.ts +0 -21
- package/out/types/src/evaluator/types/compt_list.d.ts +0 -8
- package/out/types/src/evaluator/values/anonymous_trait.d.ts +0 -17
- package/out/types/src/evaluator/values/compt_list.d.ts +0 -8
- package/out/types/src/types/constants.d.ts +0 -5
- package/out/types/src/types/index.d.ts +0 -8
- package/std/allocators/c_allocator.yo +0 -118
- package/std/index.yo +0 -12
|
@@ -28,414 +28,418 @@ ArrayListError :: enum(
|
|
|
28
28
|
* - _length: current number of elements
|
|
29
29
|
* - _capacity: total capacity of the buffer
|
|
30
30
|
*/
|
|
31
|
-
ArrayList :: (fn(
|
|
31
|
+
ArrayList :: (fn(comptime(T): Type) -> comptime(Type))(
|
|
32
32
|
object(
|
|
33
33
|
_ptr : ?*(T),
|
|
34
34
|
_length : usize,
|
|
35
|
-
_capacity : usize
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return self._capacity;
|
|
43
|
-
}),
|
|
35
|
+
_capacity : usize
|
|
36
|
+
)
|
|
37
|
+
);
|
|
38
|
+
impl(forall(T : Type), ArrayList(T),
|
|
39
|
+
len : (fn(self: Self) -> usize)({
|
|
40
|
+
return self._length;
|
|
41
|
+
}),
|
|
44
42
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
*/
|
|
49
|
-
ptr :: (fn(self: Self) -> ?*(T))(
|
|
50
|
-
self._ptr
|
|
51
|
-
),
|
|
43
|
+
capacity : (fn(self: Self) -> usize)({
|
|
44
|
+
return self._capacity;
|
|
45
|
+
}),
|
|
52
46
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
// .None => (*(T))(*(void)(usize(0))) // NULL for empty list
|
|
61
|
-
// );
|
|
62
|
-
// return [T](ptr, self._length);
|
|
63
|
-
// }),
|
|
47
|
+
/**
|
|
48
|
+
* Get a pointer to the underlying data buffer
|
|
49
|
+
* Returns .None if the list is empty or has no allocated buffer
|
|
50
|
+
*/
|
|
51
|
+
ptr : (fn(self: Self) -> ?*(T))(
|
|
52
|
+
self._ptr
|
|
53
|
+
),
|
|
64
54
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
55
|
+
/**
|
|
56
|
+
* Get a slice view of the ArrayList
|
|
57
|
+
* Returns a fat pointer [T] with data pointer and length
|
|
58
|
+
* This allows passing ArrayList to functions expecting slices
|
|
59
|
+
*/
|
|
60
|
+
// as_slice :: (fn(self: Self) -> [T])({
|
|
61
|
+
// ptr := match(self._ptr,
|
|
62
|
+
// .Some(p) => p,
|
|
63
|
+
// .None => (*(T))(*(void)(usize(0))) // NULL for empty list
|
|
64
|
+
// );
|
|
65
|
+
// return [T](ptr, self._length);
|
|
66
|
+
// }),
|
|
77
67
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
68
|
+
/** * Directly set the length of the ArrayList
|
|
69
|
+
* UNSAFE: This does not initialize new elements or free removed elements
|
|
70
|
+
* Only use when you've manually populated the buffer (e.g., via direct memory writes)
|
|
71
|
+
*/
|
|
72
|
+
set_len : (fn(self: Self, new_len: usize) -> unit)({
|
|
73
|
+
cond(
|
|
74
|
+
(new_len <= self._capacity) => {
|
|
75
|
+
self._length = new_len;
|
|
76
|
+
},
|
|
77
|
+
true => panic("set_len: new length exceeds capacity")
|
|
78
|
+
);
|
|
79
|
+
}),
|
|
87
80
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
match(ptr_result,
|
|
98
|
-
.Some(ptr) =>
|
|
99
|
-
Self(
|
|
100
|
-
_ptr: .Some((*(T))(ptr)),
|
|
101
|
-
_length: usize(0),
|
|
102
|
-
_capacity: capacity
|
|
103
|
-
),
|
|
104
|
-
.None => panic("malloc returned None")
|
|
105
|
-
)
|
|
106
|
-
}
|
|
107
|
-
)
|
|
108
|
-
),
|
|
81
|
+
/**
|
|
82
|
+
* Create a new empty ArrayList
|
|
83
|
+
*/
|
|
84
|
+
new : (fn() -> Self)(
|
|
85
|
+
Self(
|
|
86
|
+
_ptr: .None,
|
|
87
|
+
_length: usize(0),
|
|
88
|
+
_capacity: usize(0)
|
|
89
|
+
)),
|
|
109
90
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
(
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
.Some(new_ptr) => {
|
|
132
|
-
typed_ptr := (*(T))(new_ptr);
|
|
133
|
-
self._ptr = .Some(typed_ptr);
|
|
134
|
-
self._capacity = new_capacity;
|
|
135
|
-
// Now add the element at position length
|
|
136
|
-
target_ptr := (typed_ptr &+ self._length);
|
|
137
|
-
consume(target_ptr.* = value);
|
|
138
|
-
self._length = (self._length + usize(1));
|
|
139
|
-
.Ok(())
|
|
140
|
-
},
|
|
141
|
-
.None => .Err(.AllocError(.OutOfMemory))
|
|
142
|
-
)
|
|
143
|
-
},
|
|
144
|
-
true =>
|
|
145
|
-
// Have capacity - just add the element
|
|
146
|
-
match(self._ptr,
|
|
147
|
-
.Some(ptr) => {
|
|
148
|
-
target_ptr := (ptr &+ self._length);
|
|
149
|
-
consume(target_ptr.* = value);
|
|
150
|
-
self._length = (self._length + usize(1));
|
|
151
|
-
.Ok(())
|
|
152
|
-
},
|
|
153
|
-
.None => panic("ArrayList has capacity but no ptr")
|
|
154
|
-
)
|
|
155
|
-
)
|
|
156
|
-
),
|
|
91
|
+
/**
|
|
92
|
+
* Create an ArrayList with a specific initial cap
|
|
93
|
+
*/
|
|
94
|
+
with_capacity : (fn(cap: usize) -> Self)(
|
|
95
|
+
cond(
|
|
96
|
+
(cap == usize(0)) =>
|
|
97
|
+
Self.new(),
|
|
98
|
+
true => {
|
|
99
|
+
ptr_result := malloc(sizeof(T) * cap);
|
|
100
|
+
match(ptr_result,
|
|
101
|
+
.Some(_ptr) =>
|
|
102
|
+
Self(
|
|
103
|
+
_ptr: .Some((*(T))(_ptr)),
|
|
104
|
+
_length: usize(0),
|
|
105
|
+
_capacity: cap
|
|
106
|
+
),
|
|
107
|
+
.None => panic("malloc returned None")
|
|
108
|
+
)
|
|
109
|
+
}
|
|
110
|
+
)
|
|
111
|
+
),
|
|
157
112
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
)
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
113
|
+
/**
|
|
114
|
+
* Add an element to the end of the ArrayList
|
|
115
|
+
*/
|
|
116
|
+
push : (fn(self: Self, value: T) -> Result(unit, ArrayListError))(
|
|
117
|
+
// Check if we need to grow
|
|
118
|
+
cond(
|
|
119
|
+
(self._length >= self._capacity) => {
|
|
120
|
+
// Need to grow - calculate new capacity
|
|
121
|
+
new_capacity := cond
|
|
122
|
+
(self._capacity == usize(0)) => usize(4),
|
|
123
|
+
true => (self._capacity * usize(2));
|
|
124
|
+
|
|
125
|
+
// Allocate or reallocate
|
|
126
|
+
new_some_ptr := match self._ptr,
|
|
127
|
+
.None => GlobalAllocator.malloc(sizeof(T) * new_capacity),
|
|
128
|
+
.Some(old_ptr) => GlobalAllocator.realloc(
|
|
129
|
+
.Some((*(void))(old_ptr)),
|
|
130
|
+
sizeof(T) * new_capacity
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
match(new_some_ptr,
|
|
134
|
+
.Some(new_ptr) => {
|
|
135
|
+
typed_ptr := *(T)(new_ptr);
|
|
136
|
+
self._ptr = .Some(typed_ptr);
|
|
137
|
+
self._capacity = new_capacity;
|
|
138
|
+
// Now add the element at position length
|
|
139
|
+
target_ptr := (typed_ptr &+ self._length);
|
|
140
|
+
consume(target_ptr.* = value);
|
|
141
|
+
self._length = (self._length + usize(1));
|
|
142
|
+
.Ok(())
|
|
143
|
+
},
|
|
144
|
+
.None => .Err(.AllocError(.OutOfMemory))
|
|
145
|
+
)
|
|
146
|
+
},
|
|
147
|
+
true =>
|
|
148
|
+
// Have capacity - just add the element
|
|
149
|
+
match(self._ptr,
|
|
150
|
+
.Some(_ptr) => {
|
|
151
|
+
target_ptr := (_ptr &+ self._length);
|
|
152
|
+
consume(target_ptr.* = value);
|
|
153
|
+
self._length = (self._length + usize(1));
|
|
154
|
+
.Ok(())
|
|
155
|
+
},
|
|
156
|
+
.None => panic("ArrayList has capacity but no ptr")
|
|
157
|
+
)
|
|
158
|
+
)
|
|
159
|
+
),
|
|
180
160
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
)
|
|
192
|
-
|
|
193
|
-
|
|
161
|
+
/**
|
|
162
|
+
* Remove and return the last element
|
|
163
|
+
*/
|
|
164
|
+
pop : (fn(self: Self) -> Option(T))(
|
|
165
|
+
cond(
|
|
166
|
+
(self._length == usize(0)) => .None,
|
|
167
|
+
true => {
|
|
168
|
+
self._length = (self._length - usize(1));
|
|
169
|
+
match(self._ptr,
|
|
170
|
+
.None => .None,
|
|
171
|
+
.Some(_ptr) => {
|
|
172
|
+
last_element_ptr := (_ptr &+ self._length);
|
|
173
|
+
last_element := last_element_ptr.*;
|
|
174
|
+
// Drop the slot's reference since it's no longer tracked
|
|
175
|
+
// (length was decremented, so dispose won't reach this slot)
|
|
176
|
+
unsafe.drop(last_element_ptr.*);
|
|
177
|
+
.Some(last_element)
|
|
178
|
+
}
|
|
179
|
+
)
|
|
180
|
+
}
|
|
181
|
+
)
|
|
182
|
+
),
|
|
194
183
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
target_ptr.* = value;
|
|
209
|
-
.Ok(())
|
|
210
|
-
}
|
|
211
|
-
)
|
|
212
|
-
)
|
|
213
|
-
),
|
|
184
|
+
/**
|
|
185
|
+
* Get an element by index (bounds checked)
|
|
186
|
+
*/
|
|
187
|
+
get : (fn(self: Self, index: usize) -> Option(T))(
|
|
188
|
+
cond(
|
|
189
|
+
(index >= self._length) => .None,
|
|
190
|
+
true =>
|
|
191
|
+
match(self._ptr,
|
|
192
|
+
.None => .None,
|
|
193
|
+
.Some(_ptr) => .Some((_ptr &+ index).*)
|
|
194
|
+
)
|
|
195
|
+
)
|
|
196
|
+
),
|
|
214
197
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
((
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
.Ok(())
|
|
235
|
-
},
|
|
236
|
-
true =>
|
|
237
|
-
// Otherwise, reallocate to exact size
|
|
238
|
-
match(self._ptr,
|
|
239
|
-
.None => panic("ArrayList has capacity but no ptr"),
|
|
240
|
-
.Some(old_ptr) => {
|
|
241
|
-
new_some_ptr := GlobalAllocator.realloc(
|
|
242
|
-
.Some(*(void)(old_ptr)),
|
|
243
|
-
sizeof(T) * self._length
|
|
244
|
-
);
|
|
245
|
-
match(new_some_ptr,
|
|
246
|
-
.Some(new_ptr) => {
|
|
247
|
-
self._ptr = .Some(*(T)(new_ptr));
|
|
248
|
-
self._capacity = self._length;
|
|
249
|
-
.Ok(())
|
|
250
|
-
},
|
|
251
|
-
.None => .Err(.AllocError(.OutOfMemory))
|
|
252
|
-
)
|
|
253
|
-
}
|
|
254
|
-
)
|
|
255
|
-
)
|
|
256
|
-
)
|
|
257
|
-
),
|
|
198
|
+
/**
|
|
199
|
+
* Set an element at a specific index (bounds checked)
|
|
200
|
+
* Returns Ok(()) on success, or Error with bounds information
|
|
201
|
+
*/
|
|
202
|
+
set : (fn(self: Self, index: usize, value: T) -> Result(unit, ArrayListError))(
|
|
203
|
+
cond(
|
|
204
|
+
(index >= self._length) =>
|
|
205
|
+
.Err(.IndexOutOfBounds(index: index, length: self._length)),
|
|
206
|
+
true =>
|
|
207
|
+
match(self._ptr,
|
|
208
|
+
.None => panic("ArrayList has length but no ptr"),
|
|
209
|
+
.Some(_ptr) => {
|
|
210
|
+
target_ptr := (_ptr &+ index);
|
|
211
|
+
target_ptr.* = value;
|
|
212
|
+
.Ok(())
|
|
213
|
+
}
|
|
214
|
+
)
|
|
215
|
+
)
|
|
216
|
+
),
|
|
258
217
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
218
|
+
/**
|
|
219
|
+
* Shrink the capacity to match the current length
|
|
220
|
+
* This reduces memory usage but may cause reallocation on next push
|
|
221
|
+
*/
|
|
222
|
+
shrink_to_fit : ((fn(self: Self) -> Result(unit, ArrayListError))
|
|
223
|
+
// If length equals capacity or both are zero, nothing to do
|
|
224
|
+
cond(
|
|
225
|
+
((self._length == self._capacity) || (self._capacity == usize(0))) => .Ok(()),
|
|
226
|
+
true =>
|
|
227
|
+
// If length is zero, free the buffer
|
|
228
|
+
cond(
|
|
229
|
+
(self._length == usize(0)) => {
|
|
230
|
+
match(self._ptr,
|
|
231
|
+
.Some(_ptr) => {
|
|
232
|
+
GlobalAllocator.free(.Some(*(void)(_ptr)));
|
|
233
|
+
self._ptr = .None;
|
|
234
|
+
self._capacity = usize(0);
|
|
235
|
+
},
|
|
236
|
+
.None => ());
|
|
237
|
+
.Ok(())
|
|
238
|
+
},
|
|
239
|
+
true =>
|
|
240
|
+
// Otherwise, reallocate to exact size
|
|
241
|
+
match(self._ptr,
|
|
242
|
+
.None => panic("ArrayList has capacity but no ptr"),
|
|
243
|
+
.Some(old_ptr) => {
|
|
244
|
+
new_some_ptr := GlobalAllocator.realloc(
|
|
245
|
+
.Some(*(void)(old_ptr)),
|
|
246
|
+
sizeof(T) * self._length
|
|
247
|
+
);
|
|
248
|
+
match(new_some_ptr,
|
|
249
|
+
.Some(new_ptr) => {
|
|
250
|
+
self._ptr = .Some(*(T)(new_ptr));
|
|
251
|
+
self._capacity = self._length;
|
|
252
|
+
.Ok(())
|
|
253
|
+
},
|
|
254
|
+
.None => .Err(.AllocError(.OutOfMemory))
|
|
255
|
+
)
|
|
256
|
+
}
|
|
257
|
+
)
|
|
258
|
+
)
|
|
259
|
+
)
|
|
260
|
+
),
|
|
272
261
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
actual_count := cond(
|
|
287
|
-
(count > available) => available,
|
|
288
|
-
true => count
|
|
289
|
-
);
|
|
290
|
-
|
|
291
|
-
// If removing 0 elements, just return success
|
|
292
|
-
cond(
|
|
293
|
-
(actual_count == usize(0)) => .Ok(usize(0)),
|
|
294
|
-
true =>
|
|
295
|
-
match(self._ptr,
|
|
296
|
-
.None => panic("ArrayList has length but no ptr"),
|
|
297
|
-
.Some(ptr) => {
|
|
298
|
-
// Shift remaining elements left to fill the gap
|
|
299
|
-
// We need to move elements from [start + actual_count, length) to [start, ...)
|
|
300
|
-
elements_after := ((self._length - start) - actual_count);
|
|
301
|
-
new_length := (self._length - actual_count);
|
|
302
|
-
cond(
|
|
303
|
-
(elements_after > usize(0)) => {
|
|
304
|
-
src_ptr := (ptr &+ (start + actual_count));
|
|
305
|
-
dst_ptr := (ptr &+ start);
|
|
306
|
-
|
|
307
|
-
cond(
|
|
308
|
-
Type.contains_rc_type(T) => {
|
|
309
|
-
// For RC types, iterate and properly manage RC
|
|
310
|
-
// The assignment dst.* = src.* will:
|
|
311
|
-
// 1. Dup src.* (RC+1)
|
|
312
|
-
// 2. Drop old dst.* (either element being removed, or previous iteration's copy)
|
|
313
|
-
// 3. Write to dst.*
|
|
314
|
-
i := usize(0);
|
|
315
|
-
while(i < elements_after, i = (i + usize(1)), {
|
|
316
|
-
dst := (dst_ptr &+ i);
|
|
317
|
-
src := (src_ptr &+ i);
|
|
318
|
-
dst.* = src.*;
|
|
319
|
-
});
|
|
320
|
-
// Drop the non-overlapping tail stale pointers
|
|
321
|
-
j := usize(0);
|
|
322
|
-
tail_start := (start + elements_after);
|
|
323
|
-
tail_count := actual_count;
|
|
324
|
-
while(j < tail_count, j = (j + usize(1)), {
|
|
325
|
-
tail_ptr := (ptr &+ (tail_start + j));
|
|
326
|
-
unsafe.drop(tail_ptr.*);
|
|
327
|
-
});
|
|
328
|
-
},
|
|
329
|
-
true => {
|
|
330
|
-
// For non-RC types, use fast memmove
|
|
331
|
-
element_size := sizeof(T);
|
|
332
|
-
bytes_to_move := (elements_after * element_size);
|
|
333
|
-
dst_void := *(void)(dst_ptr);
|
|
334
|
-
src_void := *(void)(src_ptr);
|
|
335
|
-
memmove(dst_void, src_void, bytes_to_move);
|
|
336
|
-
}
|
|
337
|
-
);
|
|
338
|
-
},
|
|
339
|
-
true => {
|
|
340
|
-
// No elements to shift, just drop the removed elements
|
|
341
|
-
cond(
|
|
342
|
-
Type.contains_rc_type(T) => {
|
|
343
|
-
i := usize(0);
|
|
344
|
-
while(i < actual_count, i = (i + usize(1)), {
|
|
345
|
-
element_ptr := (ptr &+ (start + i));
|
|
346
|
-
unsafe.drop(element_ptr.*);
|
|
347
|
-
});
|
|
348
|
-
},
|
|
349
|
-
true => ()
|
|
350
|
-
);
|
|
351
|
-
}
|
|
352
|
-
);
|
|
353
|
-
|
|
354
|
-
// Update length
|
|
355
|
-
self._length = new_length;
|
|
356
|
-
.Ok(actual_count)
|
|
357
|
-
}
|
|
358
|
-
)
|
|
359
|
-
)
|
|
360
|
-
}
|
|
361
|
-
)
|
|
362
|
-
),
|
|
262
|
+
_free_elements : ((fn(self : Self) -> unit)
|
|
263
|
+
cond(
|
|
264
|
+
Type.contains_rc_type(T) => {
|
|
265
|
+
i := usize(0);
|
|
266
|
+
base_ptr := self._ptr.unwrap();
|
|
267
|
+
while(i < self._length, i = (i + usize(1)), {
|
|
268
|
+
element_ptr := (base_ptr &+ i);
|
|
269
|
+
unsafe.drop(element_ptr.*);
|
|
270
|
+
});
|
|
271
|
+
},
|
|
272
|
+
true => ()
|
|
273
|
+
)
|
|
274
|
+
),
|
|
363
275
|
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
(start
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
(
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
276
|
+
/**
|
|
277
|
+
* Remove elements from the ArrayList starting at index, removing count elements
|
|
278
|
+
* Returns the number of elements actually removed
|
|
279
|
+
*/
|
|
280
|
+
remove : (fn(self: Self, start: usize, (count : usize) ?= 1) -> Result(usize, ArrayListError))(
|
|
281
|
+
// Check if start index is valid
|
|
282
|
+
cond(
|
|
283
|
+
(start >= self._length) =>
|
|
284
|
+
.Err(.IndexOutOfBounds(index: start, length: self._length)),
|
|
285
|
+
true => {
|
|
286
|
+
// Calculate actual number of elements to remove
|
|
287
|
+
// (can't remove more than what's available)
|
|
288
|
+
available := (self._length - start);
|
|
289
|
+
actual_count := cond(
|
|
290
|
+
(count > available) => available,
|
|
291
|
+
true => count
|
|
292
|
+
);
|
|
293
|
+
|
|
294
|
+
// If removing 0 elements, just return success
|
|
295
|
+
cond(
|
|
296
|
+
(actual_count == usize(0)) => .Ok(usize(0)),
|
|
297
|
+
true =>
|
|
298
|
+
match(self._ptr,
|
|
299
|
+
.None => panic("ArrayList has length but no ptr"),
|
|
300
|
+
.Some(_ptr) => {
|
|
301
|
+
// Shift remaining elements left to fill the gap
|
|
302
|
+
// We need to move elements from [start + actual_count, length) to [start, ...)
|
|
303
|
+
elements_after := ((self._length - start) - actual_count);
|
|
304
|
+
new_length := (self._length - actual_count);
|
|
305
|
+
cond(
|
|
306
|
+
(elements_after > usize(0)) => {
|
|
307
|
+
src_ptr := (_ptr &+ (start + actual_count));
|
|
308
|
+
dst_ptr := (_ptr &+ start);
|
|
309
|
+
|
|
310
|
+
cond(
|
|
311
|
+
Type.contains_rc_type(T) => {
|
|
312
|
+
// For RC types, iterate and properly manage RC
|
|
313
|
+
// The assignment dst.* = src.* will:
|
|
314
|
+
// 1. Dup src.* (RC+1)
|
|
315
|
+
// 2. Drop old dst.* (either element being removed, or previous iteration's copy)
|
|
316
|
+
// 3. Write to dst.*
|
|
317
|
+
i := usize(0);
|
|
318
|
+
while(i < elements_after, i = (i + usize(1)), {
|
|
319
|
+
dst := (dst_ptr &+ i);
|
|
320
|
+
src := (src_ptr &+ i);
|
|
321
|
+
dst.* = src.*;
|
|
322
|
+
});
|
|
323
|
+
// Drop the non-overlapping tail stale pointers
|
|
324
|
+
j := usize(0);
|
|
325
|
+
tail_start := (start + elements_after);
|
|
326
|
+
tail_count := actual_count;
|
|
327
|
+
while(j < tail_count, j = (j + usize(1)), {
|
|
328
|
+
tail_ptr := (_ptr &+ (tail_start + j));
|
|
329
|
+
unsafe.drop(tail_ptr.*);
|
|
330
|
+
});
|
|
331
|
+
},
|
|
332
|
+
true => {
|
|
333
|
+
// For non-RC types, use fast memmove
|
|
334
|
+
element_size := sizeof(T);
|
|
335
|
+
bytes_to_move := (elements_after * element_size);
|
|
336
|
+
dst_void := *(void)(dst_ptr);
|
|
337
|
+
src_void := *(void)(src_ptr);
|
|
338
|
+
memmove(dst_void, src_void, bytes_to_move);
|
|
339
|
+
}
|
|
340
|
+
);
|
|
341
|
+
},
|
|
342
|
+
true => {
|
|
343
|
+
// No elements to shift, just drop the removed elements
|
|
344
|
+
cond(
|
|
345
|
+
Type.contains_rc_type(T) => {
|
|
346
|
+
i := usize(0);
|
|
347
|
+
while(i < actual_count, i = (i + usize(1)), {
|
|
348
|
+
element_ptr := (_ptr &+ (start + i));
|
|
349
|
+
unsafe.drop(element_ptr.*);
|
|
350
|
+
});
|
|
351
|
+
},
|
|
352
|
+
true => ()
|
|
353
|
+
);
|
|
354
|
+
}
|
|
355
|
+
);
|
|
356
|
+
|
|
357
|
+
// Update length
|
|
358
|
+
self._length = new_length;
|
|
359
|
+
.Ok(actual_count)
|
|
360
|
+
}
|
|
361
|
+
)
|
|
362
|
+
)
|
|
363
|
+
}
|
|
364
|
+
)
|
|
365
|
+
),
|
|
414
366
|
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
367
|
+
/**
|
|
368
|
+
* Create a new ArrayList containing a slice of elements from start to end (exclusive)
|
|
369
|
+
* Similar to array slicing in many languages: array[start:end]
|
|
370
|
+
* Returns a new ArrayList with copied elements
|
|
371
|
+
*/
|
|
372
|
+
slice : (fn(self: Self, start: usize, end: usize) -> Result(Self, ArrayListError))(
|
|
373
|
+
// Validate indices
|
|
374
|
+
cond(
|
|
375
|
+
(start > self._length) =>
|
|
376
|
+
.Err(.IndexOutOfBounds(index: start, length: self._length)),
|
|
377
|
+
(end > self._length) =>
|
|
378
|
+
.Err(.IndexOutOfBounds(index: end, length: self._length)),
|
|
379
|
+
(start > end) =>
|
|
380
|
+
.Err(.IndexOutOfBounds(index: start, length: end)),
|
|
381
|
+
true => {
|
|
382
|
+
slice_length := (end - start);
|
|
383
|
+
|
|
384
|
+
// If slice is empty, return empty ArrayList
|
|
385
|
+
cond(
|
|
386
|
+
(slice_length == usize(0)) =>
|
|
387
|
+
.Ok(Self.new()),
|
|
388
|
+
true =>
|
|
389
|
+
match(self._ptr,
|
|
390
|
+
.None => panic("ArrayList has length but no ptr"),
|
|
391
|
+
.Some(src_ptr) => {
|
|
392
|
+
// Create new ArrayList with exact capacity
|
|
393
|
+
new_list := Self.with_capacity(slice_length);
|
|
394
|
+
|
|
395
|
+
match(new_list._ptr,
|
|
396
|
+
.None => .Err(.AllocError(.OutOfMemory)),
|
|
397
|
+
.Some(dst_ptr) => {
|
|
398
|
+
// Copy elements
|
|
399
|
+
i := usize(0);
|
|
400
|
+
while(i < slice_length, i = (i + usize(1)), {
|
|
401
|
+
src := (src_ptr &+ (start + i));
|
|
402
|
+
dst := (dst_ptr &+ i);
|
|
403
|
+
dst.* = src.*;
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
// Set the length of the new list
|
|
407
|
+
new_list._length = slice_length;
|
|
408
|
+
.Ok(new_list)
|
|
409
|
+
}
|
|
410
|
+
)
|
|
411
|
+
}
|
|
412
|
+
)
|
|
413
|
+
)
|
|
414
|
+
}
|
|
415
|
+
)
|
|
416
|
+
),
|
|
422
417
|
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
418
|
+
/**
|
|
419
|
+
* Clear all elements but keep capacity
|
|
420
|
+
*/
|
|
421
|
+
clear : (fn(self: Self) -> unit)({
|
|
422
|
+
Self._free_elements(self);
|
|
423
|
+
self._length = usize(0);
|
|
424
|
+
})
|
|
425
|
+
);
|
|
426
|
+
impl(forall(T : Type), ArrayList(T), Dispose(
|
|
427
|
+
/**
|
|
428
|
+
* RAII destructor - automatically called when ArrayList goes out of scope
|
|
429
|
+
* For `object`, this is called when the reference count drops to zero
|
|
430
|
+
*/
|
|
431
|
+
dispose : (fn(self: Self) -> unit)({
|
|
432
|
+
match(self._ptr,
|
|
433
|
+
.Some(_ptr) => {
|
|
434
|
+
Self._free_elements(self);
|
|
435
|
+
self._length = usize(0);
|
|
436
|
+
GlobalAllocator.free(.Some(*(void)(_ptr)));
|
|
437
|
+
self._ptr = .None;
|
|
438
|
+
},
|
|
439
|
+
.None => ()
|
|
440
|
+
);
|
|
441
|
+
})
|
|
442
|
+
));
|
|
439
443
|
|
|
440
444
|
export
|
|
441
445
|
ArrayList,
|