@shd101wyy/yo 0.0.2
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/LICENSE.md +17 -0
- package/README.md +80 -0
- package/out/cjs/index.cjs +51 -0
- package/out/cjs/yo-cli.cjs +2158 -0
- package/out/esm/index.mjs +51 -0
- package/out/types/src/codegen/async/runtime.d.ts +2 -0
- package/out/types/src/codegen/async/state-code-gen.d.ts +10 -0
- package/out/types/src/codegen/async/state-machine.d.ts +13 -0
- package/out/types/src/codegen/c/collection.d.ts +3 -0
- package/out/types/src/codegen/codegen-c.d.ts +12 -0
- package/out/types/src/codegen/constants.d.ts +3 -0
- package/out/types/src/codegen/expressions/array.d.ts +4 -0
- package/out/types/src/codegen/expressions/generation.d.ts +11 -0
- package/out/types/src/codegen/expressions/index.d.ts +2 -0
- package/out/types/src/codegen/functions/collection.d.ts +5 -0
- package/out/types/src/codegen/functions/context.d.ts +57 -0
- package/out/types/src/codegen/functions/generation.d.ts +25 -0
- package/out/types/src/codegen/functions/index.d.ts +2 -0
- package/out/types/src/codegen/index.d.ts +20 -0
- package/out/types/src/codegen/parallelism/runtime.d.ts +2 -0
- package/out/types/src/codegen/types/collection.d.ts +8 -0
- package/out/types/src/codegen/types/generation.d.ts +13 -0
- package/out/types/src/codegen/types/index.d.ts +2 -0
- package/out/types/src/codegen/utils/fixup.d.ts +2 -0
- package/out/types/src/codegen/utils/index.d.ts +77 -0
- package/out/types/src/codegen/values/index.d.ts +1 -0
- package/out/types/src/emitter.d.ts +11 -0
- package/out/types/src/env.d.ts +85 -0
- package/out/types/src/error.d.ts +45 -0
- package/out/types/src/evaluator/async/await-analysis-types.d.ts +23 -0
- package/out/types/src/evaluator/async/await-analysis.d.ts +5 -0
- package/out/types/src/evaluator/builtins/alignof.d.ts +8 -0
- package/out/types/src/evaluator/builtins/and_or.d.ts +8 -0
- package/out/types/src/evaluator/builtins/arc_fns.d.ts +58 -0
- package/out/types/src/evaluator/builtins/array_fns.d.ts +0 -0
- package/out/types/src/evaluator/builtins/as.d.ts +8 -0
- package/out/types/src/evaluator/builtins/async_fns.d.ts +8 -0
- package/out/types/src/evaluator/builtins/compt_assert.d.ts +8 -0
- package/out/types/src/evaluator/builtins/compt_boolean_fns.d.ts +8 -0
- package/out/types/src/evaluator/builtins/compt_expect_error.d.ts +8 -0
- package/out/types/src/evaluator/builtins/compt_list_fns.d.ts +33 -0
- package/out/types/src/evaluator/builtins/compt_print.d.ts +8 -0
- package/out/types/src/evaluator/builtins/compt_string_fns.d.ts +8 -0
- package/out/types/src/evaluator/builtins/consume.d.ts +8 -0
- package/out/types/src/evaluator/builtins/drop.d.ts +8 -0
- package/out/types/src/evaluator/builtins/dup.d.ts +8 -0
- package/out/types/src/evaluator/builtins/expr_fns.d.ts +33 -0
- package/out/types/src/evaluator/builtins/future_fns.d.ts +8 -0
- package/out/types/src/evaluator/builtins/gc.d.ts +8 -0
- package/out/types/src/evaluator/builtins/gensym.d.ts +8 -0
- package/out/types/src/evaluator/builtins/impl_constraint.d.ts +8 -0
- package/out/types/src/evaluator/builtins/macro_expand.d.ts +8 -0
- package/out/types/src/evaluator/builtins/numeric_fns.d.ts +8 -0
- package/out/types/src/evaluator/builtins/panic.d.ts +8 -0
- package/out/types/src/evaluator/builtins/ptr_fns.d.ts +8 -0
- package/out/types/src/evaluator/builtins/quote.d.ts +13 -0
- package/out/types/src/evaluator/builtins/rc.d.ts +8 -0
- package/out/types/src/evaluator/builtins/sizeof.d.ts +8 -0
- package/out/types/src/evaluator/builtins/the.d.ts +8 -0
- package/out/types/src/evaluator/builtins/type_fns.d.ts +28 -0
- package/out/types/src/evaluator/builtins/va_start.d.ts +8 -0
- package/out/types/src/evaluator/builtins/var_fns.d.ts +18 -0
- package/out/types/src/evaluator/calls/array.d.ts +13 -0
- package/out/types/src/evaluator/calls/array_type.d.ts +11 -0
- package/out/types/src/evaluator/calls/closure_type.d.ts +11 -0
- package/out/types/src/evaluator/calls/compt_function.d.ts +19 -0
- package/out/types/src/evaluator/calls/compt_list_type.d.ts +11 -0
- package/out/types/src/evaluator/calls/function.d.ts +16 -0
- package/out/types/src/evaluator/calls/function_type.d.ts +15 -0
- package/out/types/src/evaluator/calls/helper.d.ts +42 -0
- package/out/types/src/evaluator/calls/iso.d.ts +15 -0
- package/out/types/src/evaluator/calls/module_type.d.ts +11 -0
- package/out/types/src/evaluator/calls/numeric_type.d.ts +15 -0
- package/out/types/src/evaluator/calls/pointer.d.ts +8 -0
- package/out/types/src/evaluator/calls/pointer_type.d.ts +14 -0
- package/out/types/src/evaluator/calls/type.d.ts +12 -0
- package/out/types/src/evaluator/context.d.ts +169 -0
- package/out/types/src/evaluator/exprs/_expr.d.ts +8 -0
- package/out/types/src/evaluator/exprs/assignment.d.ts +9 -0
- package/out/types/src/evaluator/exprs/begin.d.ts +10 -0
- package/out/types/src/evaluator/exprs/binding.d.ts +12 -0
- package/out/types/src/evaluator/exprs/c_include.d.ts +8 -0
- package/out/types/src/evaluator/exprs/cond.d.ts +8 -0
- package/out/types/src/evaluator/exprs/destructuring_assignment.d.ts +33 -0
- package/out/types/src/evaluator/exprs/exists.d.ts +0 -0
- package/out/types/src/evaluator/exprs/expr.d.ts +9 -0
- package/out/types/src/evaluator/exprs/extern.d.ts +8 -0
- package/out/types/src/evaluator/exprs/identifer_and_operator.d.ts +9 -0
- package/out/types/src/evaluator/exprs/import.d.ts +9 -0
- package/out/types/src/evaluator/exprs/initialization_assignment.d.ts +8 -0
- package/out/types/src/evaluator/exprs/match.d.ts +8 -0
- package/out/types/src/evaluator/exprs/open.d.ts +8 -0
- package/out/types/src/evaluator/exprs/property_access.d.ts +8 -0
- package/out/types/src/evaluator/exprs/recur.d.ts +8 -0
- package/out/types/src/evaluator/exprs/subtype_of.d.ts +21 -0
- package/out/types/src/evaluator/exprs/test.d.ts +8 -0
- package/out/types/src/evaluator/exprs/typeof.d.ts +8 -0
- package/out/types/src/evaluator/exprs/while.d.ts +8 -0
- package/out/types/src/evaluator/index.d.ts +26 -0
- package/out/types/src/evaluator/types/array.d.ts +8 -0
- package/out/types/src/evaluator/types/closure.d.ts +8 -0
- package/out/types/src/evaluator/types/compt_list.d.ts +8 -0
- package/out/types/src/evaluator/types/concrete_module.d.ts +8 -0
- package/out/types/src/evaluator/types/dyn.d.ts +8 -0
- package/out/types/src/evaluator/types/enum.d.ts +8 -0
- package/out/types/src/evaluator/types/expr_synthesizer.d.ts +14 -0
- package/out/types/src/evaluator/types/field.d.ts +14 -0
- package/out/types/src/evaluator/types/fn_module.d.ts +8 -0
- package/out/types/src/evaluator/types/function.d.ts +58 -0
- package/out/types/src/evaluator/types/future_module.d.ts +8 -0
- package/out/types/src/evaluator/types/module.d.ts +19 -0
- package/out/types/src/evaluator/types/newtype.d.ts +8 -0
- package/out/types/src/evaluator/types/object.d.ts +8 -0
- package/out/types/src/evaluator/types/proofs.d.ts +0 -0
- package/out/types/src/evaluator/types/slice.d.ts +8 -0
- package/out/types/src/evaluator/types/struct.d.ts +8 -0
- package/out/types/src/evaluator/types/synthesizer.d.ts +16 -0
- package/out/types/src/evaluator/types/tuple.d.ts +18 -0
- package/out/types/src/evaluator/types/union.d.ts +8 -0
- package/out/types/src/evaluator/types/utils.d.ts +71 -0
- package/out/types/src/evaluator/types/validation.d.ts +3 -0
- package/out/types/src/evaluator/utils/array-utils.d.ts +15 -0
- package/out/types/src/evaluator/utils/closure.d.ts +35 -0
- package/out/types/src/evaluator/utils.d.ts +4 -0
- package/out/types/src/evaluator/values/anonymous_function.d.ts +8 -0
- package/out/types/src/evaluator/values/anonymous_module.d.ts +17 -0
- package/out/types/src/evaluator/values/anonymous_struct.d.ts +8 -0
- package/out/types/src/evaluator/values/array.d.ts +8 -0
- package/out/types/src/evaluator/values/boolean.d.ts +3 -0
- package/out/types/src/evaluator/values/char.d.ts +3 -0
- package/out/types/src/evaluator/values/compt_list.d.ts +8 -0
- package/out/types/src/evaluator/values/dyn.d.ts +8 -0
- package/out/types/src/evaluator/values/float.d.ts +4 -0
- package/out/types/src/evaluator/values/integer.d.ts +4 -0
- package/out/types/src/evaluator/values/module.d.ts +58 -0
- package/out/types/src/evaluator/values/string.d.ts +3 -0
- package/out/types/src/evaluator/values/tuple.d.ts +32 -0
- package/out/types/src/expr.d.ts +456 -0
- package/out/types/src/function-value.d.ts +42 -0
- package/out/types/src/index.d.ts +4 -0
- package/out/types/src/lexer.d.ts +2 -0
- package/out/types/src/logger.d.ts +1 -0
- package/out/types/src/module-manager.d.ts +30 -0
- package/out/types/src/naming-checker.d.ts +4 -0
- package/out/types/src/parser.d.ts +33 -0
- package/out/types/src/test-runner.d.ts +30 -0
- package/out/types/src/tests/codegen.test.d.ts +1 -0
- package/out/types/src/tests/fixme.test.d.ts +1 -0
- package/out/types/src/tests/module-manager.test.d.ts +1 -0
- package/out/types/src/tests/parser.test.d.ts +1 -0
- package/out/types/src/tests/sample.test.d.ts +0 -0
- package/out/types/src/tests/std.test.d.ts +1 -0
- package/out/types/src/token.d.ts +40 -0
- package/out/types/src/type-value.d.ts +7 -0
- package/out/types/src/types/compatibility.d.ts +16 -0
- package/out/types/src/types/creators.d.ts +73 -0
- package/out/types/src/types/definitions.d.ts +218 -0
- package/out/types/src/types/guards.d.ts +70 -0
- package/out/types/src/types/hierarchy.d.ts +4 -0
- package/out/types/src/types/index.d.ts +7 -0
- package/out/types/src/types/module_field.d.ts +2 -0
- package/out/types/src/types/tags.d.ts +45 -0
- package/out/types/src/types/utils.d.ts +50 -0
- package/out/types/src/unit-value.d.ts +7 -0
- package/out/types/src/utils.d.ts +6 -0
- package/out/types/src/value-tag.d.ts +29 -0
- package/out/types/src/value.d.ts +110 -0
- package/out/types/src/yo-cli.d.ts +1 -0
- package/out/types/tsconfig.tsbuildinfo +1 -0
- package/package.json +57 -0
- package/scripts/check-liburing.js +76 -0
- package/std/alg/hash.yo +50 -0
- package/std/allocator.yo +113 -0
- package/std/allocators/c_allocator.yo +118 -0
- package/std/async.yo +13 -0
- package/std/collections/array_list.yo +415 -0
- package/std/collections/hash_map.yo +482 -0
- package/std/collections/hash_set.yo +706 -0
- package/std/collections/index.yo +11 -0
- package/std/collections/linked_list.yo +439 -0
- package/std/error.yo +0 -0
- package/std/gc.yo +10 -0
- package/std/index.yo +12 -0
- package/std/io/file.yo +191 -0
- package/std/io/index.yo +5 -0
- package/std/libc/assert.yo +39 -0
- package/std/libc/ctype.yo +57 -0
- package/std/libc/errno.yo +182 -0
- package/std/libc/float.yo +87 -0
- package/std/libc/index.yo +29 -0
- package/std/libc/limits.yo +65 -0
- package/std/libc/math.yo +679 -0
- package/std/libc/signal.yo +101 -0
- package/std/libc/stdatomic.yo +213 -0
- package/std/libc/stdint.yo +214 -0
- package/std/libc/stdio.yo +225 -0
- package/std/libc/stdlib.yo +204 -0
- package/std/libc/string.yo +151 -0
- package/std/libc/time.yo +92 -0
- package/std/libc/unistd.yo +130 -0
- package/std/monad.yo +152 -0
- package/std/prelude.yo +3094 -0
- package/std/string/index.yo +8 -0
- package/std/string/rune.yo +82 -0
- package/std/string/string.yo +288 -0
- package/std/sync.yo +95 -0
- package/std/thread.yo +36 -0
- package/std/time.yo +13 -0
- package/std/worker.yo +36 -0
- package/vendor/mimalloc/.gitattributes +12 -0
- package/vendor/mimalloc/CMakeLists.txt +763 -0
- package/vendor/mimalloc/LICENSE +21 -0
- package/vendor/mimalloc/SECURITY.md +41 -0
- package/vendor/mimalloc/azure-pipelines.yml +251 -0
- package/vendor/mimalloc/bin/mimalloc-redirect-arm64.dll +0 -0
- package/vendor/mimalloc/bin/mimalloc-redirect-arm64.lib +0 -0
- package/vendor/mimalloc/bin/mimalloc-redirect-arm64ec.dll +0 -0
- package/vendor/mimalloc/bin/mimalloc-redirect-arm64ec.lib +0 -0
- package/vendor/mimalloc/bin/mimalloc-redirect.dll +0 -0
- package/vendor/mimalloc/bin/mimalloc-redirect.lib +0 -0
- package/vendor/mimalloc/bin/mimalloc-redirect32.dll +0 -0
- package/vendor/mimalloc/bin/mimalloc-redirect32.lib +0 -0
- package/vendor/mimalloc/bin/minject-arm64.exe +0 -0
- package/vendor/mimalloc/bin/minject.exe +0 -0
- package/vendor/mimalloc/bin/minject32.exe +0 -0
- package/vendor/mimalloc/bin/readme.md +118 -0
- package/vendor/mimalloc/cmake/JoinPaths.cmake +23 -0
- package/vendor/mimalloc/cmake/mimalloc-config-version.cmake +19 -0
- package/vendor/mimalloc/cmake/mimalloc-config.cmake +14 -0
- package/vendor/mimalloc/contrib/docker/alpine/Dockerfile +23 -0
- package/vendor/mimalloc/contrib/docker/alpine-arm32v7/Dockerfile +28 -0
- package/vendor/mimalloc/contrib/docker/alpine-x86/Dockerfile +28 -0
- package/vendor/mimalloc/contrib/docker/manylinux-x64/Dockerfile +23 -0
- package/vendor/mimalloc/contrib/docker/readme.md +10 -0
- package/vendor/mimalloc/contrib/vcpkg/portfile.cmake +64 -0
- package/vendor/mimalloc/contrib/vcpkg/readme.md +40 -0
- package/vendor/mimalloc/contrib/vcpkg/usage +20 -0
- package/vendor/mimalloc/contrib/vcpkg/vcpkg-cmake-wrapper.cmake +20 -0
- package/vendor/mimalloc/contrib/vcpkg/vcpkg.json +48 -0
- package/vendor/mimalloc/doc/bench-2020/bench-c5-18xlarge-2020-01-20-a.svg +887 -0
- package/vendor/mimalloc/doc/bench-2020/bench-c5-18xlarge-2020-01-20-b.svg +1185 -0
- package/vendor/mimalloc/doc/bench-2020/bench-c5-18xlarge-2020-01-20-rss-a.svg +757 -0
- package/vendor/mimalloc/doc/bench-2020/bench-c5-18xlarge-2020-01-20-rss-b.svg +1028 -0
- package/vendor/mimalloc/doc/bench-2020/bench-r5a-1.svg +769 -0
- package/vendor/mimalloc/doc/bench-2020/bench-r5a-12xlarge-2020-01-16-a.svg +868 -0
- package/vendor/mimalloc/doc/bench-2020/bench-r5a-12xlarge-2020-01-16-b.svg +1157 -0
- package/vendor/mimalloc/doc/bench-2020/bench-r5a-2.svg +983 -0
- package/vendor/mimalloc/doc/bench-2020/bench-r5a-rss-1.svg +683 -0
- package/vendor/mimalloc/doc/bench-2020/bench-r5a-rss-2.svg +854 -0
- package/vendor/mimalloc/doc/bench-2020/bench-spec-rss.svg +713 -0
- package/vendor/mimalloc/doc/bench-2020/bench-spec.svg +713 -0
- package/vendor/mimalloc/doc/bench-2020/bench-z4-1.svg +890 -0
- package/vendor/mimalloc/doc/bench-2020/bench-z4-2.svg +1146 -0
- package/vendor/mimalloc/doc/bench-2020/bench-z4-rss-1.svg +796 -0
- package/vendor/mimalloc/doc/bench-2020/bench-z4-rss-2.svg +974 -0
- package/vendor/mimalloc/doc/bench-2021/bench-amd5950x-2021-01-30-a.svg +952 -0
- package/vendor/mimalloc/doc/bench-2021/bench-amd5950x-2021-01-30-b.svg +1255 -0
- package/vendor/mimalloc/doc/bench-2021/bench-c5-18xlarge-2021-01-30-a.svg +955 -0
- package/vendor/mimalloc/doc/bench-2021/bench-c5-18xlarge-2021-01-30-b.svg +1269 -0
- package/vendor/mimalloc/doc/bench-2021/bench-c5-18xlarge-2021-01-30-rss-a.svg +836 -0
- package/vendor/mimalloc/doc/bench-2021/bench-c5-18xlarge-2021-01-30-rss-b.svg +1131 -0
- package/vendor/mimalloc/doc/bench-2021/bench-macmini-2021-01-30.svg +766 -0
- package/vendor/mimalloc/doc/doxyfile +2895 -0
- package/vendor/mimalloc/doc/ds-logo.jpg +0 -0
- package/vendor/mimalloc/doc/ds-logo.png +0 -0
- package/vendor/mimalloc/doc/mimalloc-doc.h +1452 -0
- package/vendor/mimalloc/doc/mimalloc-doxygen.css +60 -0
- package/vendor/mimalloc/doc/mimalloc-logo-100.png +0 -0
- package/vendor/mimalloc/doc/mimalloc-logo.png +0 -0
- package/vendor/mimalloc/doc/mimalloc-logo.svg +161 -0
- package/vendor/mimalloc/doc/spades-logo.png +0 -0
- package/vendor/mimalloc/doc/unreal-logo.svg +43 -0
- package/vendor/mimalloc/ide/vs2022/mimalloc-lib.vcxproj +500 -0
- package/vendor/mimalloc/ide/vs2022/mimalloc-lib.vcxproj.filters +108 -0
- package/vendor/mimalloc/ide/vs2022/mimalloc-override-dll.vcxproj +508 -0
- package/vendor/mimalloc/ide/vs2022/mimalloc-override-dll.vcxproj.filters +111 -0
- package/vendor/mimalloc/ide/vs2022/mimalloc-override-test-dep.vcxproj +355 -0
- package/vendor/mimalloc/ide/vs2022/mimalloc-override-test.vcxproj +360 -0
- package/vendor/mimalloc/ide/vs2022/mimalloc-test-api.vcxproj +295 -0
- package/vendor/mimalloc/ide/vs2022/mimalloc-test-stress.vcxproj +292 -0
- package/vendor/mimalloc/ide/vs2022/mimalloc-test.vcxproj +289 -0
- package/vendor/mimalloc/ide/vs2022/mimalloc.sln +151 -0
- package/vendor/mimalloc/include/mimalloc/atomic.h +557 -0
- package/vendor/mimalloc/include/mimalloc/internal.h +1153 -0
- package/vendor/mimalloc/include/mimalloc/prim.h +421 -0
- package/vendor/mimalloc/include/mimalloc/track.h +145 -0
- package/vendor/mimalloc/include/mimalloc/types.h +685 -0
- package/vendor/mimalloc/include/mimalloc-new-delete.h +66 -0
- package/vendor/mimalloc/include/mimalloc-override.h +68 -0
- package/vendor/mimalloc/include/mimalloc-stats.h +103 -0
- package/vendor/mimalloc/include/mimalloc.h +612 -0
- package/vendor/mimalloc/mimalloc.pc.in +11 -0
- package/vendor/mimalloc/readme.md +946 -0
- package/vendor/mimalloc/src/alloc-aligned.c +360 -0
- package/vendor/mimalloc/src/alloc-override.c +316 -0
- package/vendor/mimalloc/src/alloc-posix.c +185 -0
- package/vendor/mimalloc/src/alloc.c +692 -0
- package/vendor/mimalloc/src/arena-abandon.c +346 -0
- package/vendor/mimalloc/src/arena.c +1043 -0
- package/vendor/mimalloc/src/bitmap.c +441 -0
- package/vendor/mimalloc/src/bitmap.h +119 -0
- package/vendor/mimalloc/src/free.c +572 -0
- package/vendor/mimalloc/src/heap.c +733 -0
- package/vendor/mimalloc/src/init.c +714 -0
- package/vendor/mimalloc/src/libc.c +334 -0
- package/vendor/mimalloc/src/options.c +663 -0
- package/vendor/mimalloc/src/os.c +770 -0
- package/vendor/mimalloc/src/page-queue.c +390 -0
- package/vendor/mimalloc/src/page.c +1049 -0
- package/vendor/mimalloc/src/prim/emscripten/prim.c +249 -0
- package/vendor/mimalloc/src/prim/osx/alloc-override-zone.c +461 -0
- package/vendor/mimalloc/src/prim/osx/prim.c +9 -0
- package/vendor/mimalloc/src/prim/prim.c +76 -0
- package/vendor/mimalloc/src/prim/readme.md +9 -0
- package/vendor/mimalloc/src/prim/unix/prim.c +934 -0
- package/vendor/mimalloc/src/prim/wasi/prim.c +284 -0
- package/vendor/mimalloc/src/prim/windows/etw-mimalloc.wprp +61 -0
- package/vendor/mimalloc/src/prim/windows/etw.h +905 -0
- package/vendor/mimalloc/src/prim/windows/etw.man +0 -0
- package/vendor/mimalloc/src/prim/windows/prim.c +878 -0
- package/vendor/mimalloc/src/prim/windows/readme.md +17 -0
- package/vendor/mimalloc/src/random.c +258 -0
- package/vendor/mimalloc/src/segment-map.c +142 -0
- package/vendor/mimalloc/src/segment.c +1702 -0
- package/vendor/mimalloc/src/static.c +41 -0
- package/vendor/mimalloc/src/stats.c +635 -0
- package/vendor/mimalloc/test/CMakeLists.txt +56 -0
- package/vendor/mimalloc/test/main-override-dep.cpp +51 -0
- package/vendor/mimalloc/test/main-override-dep.h +11 -0
- package/vendor/mimalloc/test/main-override-static.c +539 -0
- package/vendor/mimalloc/test/main-override.c +36 -0
- package/vendor/mimalloc/test/main-override.cpp +497 -0
- package/vendor/mimalloc/test/main.c +46 -0
- package/vendor/mimalloc/test/readme.md +16 -0
- package/vendor/mimalloc/test/test-api-fill.c +343 -0
- package/vendor/mimalloc/test/test-api.c +466 -0
- package/vendor/mimalloc/test/test-stress.c +428 -0
- package/vendor/mimalloc/test/test-wrong.c +92 -0
- package/vendor/mimalloc/test/testhelper.h +49 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
open import "../allocator.yo";
|
|
2
|
+
open import "../libc/stdlib.yo";
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
CAllocator :: struct(
|
|
6
|
+
CustomAllocator :: (CustomAllocator(
|
|
7
|
+
alloc : ((self, T, count) -> {
|
|
8
|
+
// Check for overflow
|
|
9
|
+
if size_would_overflow(T, count), {
|
|
10
|
+
return .Error(.InvalidSize);
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
size := (usize(count * sizeof(T)));
|
|
14
|
+
some_ptr := malloc(size);
|
|
15
|
+
match some_ptr,
|
|
16
|
+
.Some(ptr) => {
|
|
17
|
+
// Cast the void pointer to the correct type
|
|
18
|
+
typed_ptr := ptr.cast(*(T));
|
|
19
|
+
.Ok(.Some(typed_ptr))
|
|
20
|
+
},
|
|
21
|
+
.None => .Error(.OutOfMemory)
|
|
22
|
+
}),
|
|
23
|
+
|
|
24
|
+
alloc_zeroed : ((self, T, count) -> {
|
|
25
|
+
// Check for overflow
|
|
26
|
+
if size_would_overflow(T, count), {
|
|
27
|
+
return .Error(.InvalidSize);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
some_ptr := calloc(count, usize(sizeof(T)));
|
|
31
|
+
match some_ptr,
|
|
32
|
+
.Some(ptr) => {
|
|
33
|
+
typed_ptr := ptr.cast(*(T));
|
|
34
|
+
.Ok(.Some(typed_ptr))
|
|
35
|
+
},
|
|
36
|
+
.None => .Error(.OutOfMemory)
|
|
37
|
+
}),
|
|
38
|
+
|
|
39
|
+
alloc_aligned : ((self, T, count, alignment) -> {
|
|
40
|
+
// Check for overflow
|
|
41
|
+
if size_would_overflow(T, count), {
|
|
42
|
+
return .Error(.InvalidSize);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// Check if alignment is valid (power of 2)
|
|
46
|
+
if (
|
|
47
|
+
(alignment == usize(0)) ||
|
|
48
|
+
((alignment & (alignment - usize(1))) != usize(0))
|
|
49
|
+
), {
|
|
50
|
+
return .Error(.InvalidAlignment);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// Check if alignment is at least as large as the type's natural alignment
|
|
54
|
+
natural_alignment := alignof(T);
|
|
55
|
+
if (alignment < natural_alignment), {
|
|
56
|
+
return .Error(.InvalidAlignment);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
// For now, fall back to regular malloc (would need aligned_alloc in real implementation)
|
|
60
|
+
size := (usize(count * sizeof(T)));
|
|
61
|
+
some_ptr := malloc(size);
|
|
62
|
+
match some_ptr,
|
|
63
|
+
.Some(ptr) => {
|
|
64
|
+
typed_ptr := ptr.cast(*(T));
|
|
65
|
+
.Ok(.Some(typed_ptr))
|
|
66
|
+
},
|
|
67
|
+
.None => .Error(.OutOfMemory)
|
|
68
|
+
}),
|
|
69
|
+
|
|
70
|
+
realloc : ((forall(T), self, some_old_ptr, new_count) -> {
|
|
71
|
+
// Check for overflow
|
|
72
|
+
if (size_would_overflow(T, new_count)), {
|
|
73
|
+
return .Error(.InvalidSize);
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
// Handle null pointer case
|
|
77
|
+
match some_old_ptr,
|
|
78
|
+
.None => {
|
|
79
|
+
// Realloc with null pointer behaves like malloc
|
|
80
|
+
size := (new_usize(count * sizeof(T)));
|
|
81
|
+
some_ptr := malloc(size);
|
|
82
|
+
match some_ptr,
|
|
83
|
+
.Some(ptr) => {
|
|
84
|
+
typed_ptr := ptr.cast(*(T));
|
|
85
|
+
.Ok(.Some(typed_ptr))
|
|
86
|
+
},
|
|
87
|
+
.None => .Error(.OutOfMemory)
|
|
88
|
+
},
|
|
89
|
+
.Some(old_ptr) => {
|
|
90
|
+
raw_old := old_ptr.cast(*(void));
|
|
91
|
+
|
|
92
|
+
// Handle zero size case
|
|
93
|
+
if (new_count == usize(0)), {
|
|
94
|
+
free(.Some(raw_old));
|
|
95
|
+
return .Ok(.None);
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
new_size := (new_usize(count * sizeof(T)));
|
|
99
|
+
some_new_ptr := realloc(.Some(raw_old), new_size);
|
|
100
|
+
match some_new_ptr,
|
|
101
|
+
.Some(new_ptr) => {
|
|
102
|
+
typed_ptr := new_ptr.cast(*(T));
|
|
103
|
+
.Ok(.Some(typed_ptr))
|
|
104
|
+
},
|
|
105
|
+
.None => .Error(.OutOfMemory)
|
|
106
|
+
}
|
|
107
|
+
}),
|
|
108
|
+
|
|
109
|
+
dealloc : ((forall(T), self, ptr) -> {
|
|
110
|
+
raw_ptr := ptr.cast(*(void));
|
|
111
|
+
free(.Some(raw_ptr));
|
|
112
|
+
.Ok(())
|
|
113
|
+
})
|
|
114
|
+
))
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
export CAllocator;
|
|
118
|
+
*/
|
package/std/async.yo
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Async yield - suspends current task and allows other tasks to run
|
|
2
|
+
// Implemented as an immediately-completing async block that forces a suspension point
|
|
3
|
+
yield :: (fn() -> Impl(Future(unit)))
|
|
4
|
+
async {
|
|
5
|
+
// Empty async block that just completes immediately
|
|
6
|
+
// The act of awaiting this will cause the current task to suspend and re-enqueue
|
|
7
|
+
return ();
|
|
8
|
+
}
|
|
9
|
+
;
|
|
10
|
+
|
|
11
|
+
export
|
|
12
|
+
yield
|
|
13
|
+
;
|
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ArrayList - A dynamic array implementation for Yo language
|
|
3
|
+
*
|
|
4
|
+
* Similar to Rust's Vec<T> and Zig's ArrayList, this ArrayList provides:
|
|
5
|
+
* - Dynamic resizing
|
|
6
|
+
* - ~~Memory management via custom allocator~~
|
|
7
|
+
* - Type safety
|
|
8
|
+
* - RAII for automatic cleanup
|
|
9
|
+
*/
|
|
10
|
+
{ GlobalAllocator, AllocError } :: import "../allocator.yo";
|
|
11
|
+
{ malloc, calloc, realloc, free, aligned_alloc } :: GlobalAllocator;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* ArrayList error types
|
|
15
|
+
*/
|
|
16
|
+
ArrayListError :: enum(
|
|
17
|
+
AllocError(error : AllocError),
|
|
18
|
+
IndexOutOfBounds(index: usize, length: usize),
|
|
19
|
+
EmptyList
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* ArrayList type - a growable array
|
|
24
|
+
*
|
|
25
|
+
* Memory layout:
|
|
26
|
+
* - ptr: pointer to the heap-allocated buffer
|
|
27
|
+
* - _length: current number of elements
|
|
28
|
+
* - _capacity: total capacity of the buffer
|
|
29
|
+
*/
|
|
30
|
+
ArrayList :: (fn(compt(T): Type) -> compt(Type))
|
|
31
|
+
object(
|
|
32
|
+
_ptr : ?*(T),
|
|
33
|
+
_length : usize,
|
|
34
|
+
_capacity : usize,
|
|
35
|
+
|
|
36
|
+
len :: (fn(self: Self) -> usize)({
|
|
37
|
+
return self._length;
|
|
38
|
+
}),
|
|
39
|
+
|
|
40
|
+
capacity :: (fn(self: Self) -> usize)({
|
|
41
|
+
return self._capacity;
|
|
42
|
+
}),
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Get a pointer to the underlying data buffer
|
|
46
|
+
* Returns .None if the list is empty or has no allocated buffer
|
|
47
|
+
*/
|
|
48
|
+
ptr :: (fn(self: Self) -> ?*(T))(
|
|
49
|
+
self._ptr
|
|
50
|
+
),
|
|
51
|
+
|
|
52
|
+
/** * Get a slice view of the ArrayList
|
|
53
|
+
* Returns a fat pointer [T] with data pointer and length
|
|
54
|
+
* This allows passing ArrayList to functions expecting slices
|
|
55
|
+
*/
|
|
56
|
+
// as_slice :: (fn(self: Self) -> [T])({
|
|
57
|
+
// ptr := match(self._ptr,
|
|
58
|
+
// .Some(p) => p,
|
|
59
|
+
// .None => (*(T))(*(void)(usize(0))) // NULL for empty list
|
|
60
|
+
// );
|
|
61
|
+
// return [T](ptr, self._length);
|
|
62
|
+
// }),
|
|
63
|
+
|
|
64
|
+
/** * Directly set the length of the ArrayList
|
|
65
|
+
* UNSAFE: This does not initialize new elements or free removed elements
|
|
66
|
+
* Only use when you've manually populated the buffer (e.g., via direct memory writes)
|
|
67
|
+
*/
|
|
68
|
+
set_len :: (fn(self: Self, new_len: usize) -> unit)({
|
|
69
|
+
cond(
|
|
70
|
+
(new_len <= self._capacity) => {
|
|
71
|
+
self._length = new_len;
|
|
72
|
+
},
|
|
73
|
+
true => panic("set_len: new length exceeds capacity")
|
|
74
|
+
);
|
|
75
|
+
}),
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Create a new empty ArrayList
|
|
79
|
+
*/
|
|
80
|
+
new :: (fn() -> Self)(
|
|
81
|
+
Self(
|
|
82
|
+
_ptr: .None,
|
|
83
|
+
_length: usize(0),
|
|
84
|
+
_capacity: usize(0)
|
|
85
|
+
)),
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Create an ArrayList with a specific initial capacity
|
|
89
|
+
*/
|
|
90
|
+
with_capacity :: (fn(capacity: usize) -> Self)(
|
|
91
|
+
cond(
|
|
92
|
+
(capacity == usize(0)) =>
|
|
93
|
+
Self.new(),
|
|
94
|
+
true => {
|
|
95
|
+
ptr_result := malloc(sizeof(T) * capacity);
|
|
96
|
+
match(ptr_result,
|
|
97
|
+
.Some(ptr) =>
|
|
98
|
+
Self(
|
|
99
|
+
_ptr: .Some((*(T))(ptr)),
|
|
100
|
+
_length: usize(0),
|
|
101
|
+
_capacity: capacity
|
|
102
|
+
),
|
|
103
|
+
.None => panic("malloc returned None")
|
|
104
|
+
)
|
|
105
|
+
}
|
|
106
|
+
)
|
|
107
|
+
),
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Add an element to the end of the ArrayList
|
|
111
|
+
*/
|
|
112
|
+
push :: (fn(self: Self, value: T) -> Result(unit, ArrayListError))(
|
|
113
|
+
// Check if we need to grow
|
|
114
|
+
cond(
|
|
115
|
+
(self._length >= self._capacity) => {
|
|
116
|
+
// Need to grow - calculate new capacity
|
|
117
|
+
new_capacity := cond
|
|
118
|
+
(self._capacity == usize(0)) => usize(4),
|
|
119
|
+
true => (self._capacity * usize(2));
|
|
120
|
+
|
|
121
|
+
// Allocate or reallocate
|
|
122
|
+
new_some_ptr := match self._ptr,
|
|
123
|
+
.None => GlobalAllocator.malloc(sizeof(T) * new_capacity),
|
|
124
|
+
.Some(old_ptr) => GlobalAllocator.realloc(
|
|
125
|
+
.Some((*(void))(old_ptr)),
|
|
126
|
+
sizeof(T) * new_capacity
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
match(new_some_ptr,
|
|
130
|
+
.Some(new_ptr) => {
|
|
131
|
+
typed_ptr := (*(T))(new_ptr);
|
|
132
|
+
self._ptr = .Some(typed_ptr);
|
|
133
|
+
self._capacity = new_capacity;
|
|
134
|
+
// Now add the element at position length
|
|
135
|
+
target_ptr := (typed_ptr &+ self._length);
|
|
136
|
+
consume(target_ptr.* = value);
|
|
137
|
+
self._length = (self._length + usize(1));
|
|
138
|
+
.Ok(())
|
|
139
|
+
},
|
|
140
|
+
.None => .Err(.AllocError(.OutOfMemory))
|
|
141
|
+
)
|
|
142
|
+
},
|
|
143
|
+
true =>
|
|
144
|
+
// Have capacity - just add the element
|
|
145
|
+
match(self._ptr,
|
|
146
|
+
.Some(ptr) => {
|
|
147
|
+
target_ptr := (ptr &+ self._length);
|
|
148
|
+
consume(target_ptr.* = value);
|
|
149
|
+
self._length = (self._length + usize(1));
|
|
150
|
+
.Ok(())
|
|
151
|
+
},
|
|
152
|
+
.None => panic("ArrayList has capacity but no ptr")
|
|
153
|
+
)
|
|
154
|
+
)
|
|
155
|
+
),
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Remove and return the last element
|
|
159
|
+
*/
|
|
160
|
+
pop :: (fn(self: Self) -> Option(T))(
|
|
161
|
+
cond(
|
|
162
|
+
(self._length == usize(0)) => .None,
|
|
163
|
+
true => {
|
|
164
|
+
self._length = (self._length - usize(1));
|
|
165
|
+
match(self._ptr,
|
|
166
|
+
.None => .None,
|
|
167
|
+
.Some(ptr) => {
|
|
168
|
+
last_element_ptr := (ptr &+ self._length);
|
|
169
|
+
last_element := last_element_ptr.*;
|
|
170
|
+
.Some(last_element)
|
|
171
|
+
}
|
|
172
|
+
)
|
|
173
|
+
}
|
|
174
|
+
)
|
|
175
|
+
),
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Get an element by index (bounds checked)
|
|
179
|
+
*/
|
|
180
|
+
get :: (fn(self: Self, index: usize) -> Option(T))(
|
|
181
|
+
cond(
|
|
182
|
+
(index >= self._length) => .None,
|
|
183
|
+
true =>
|
|
184
|
+
match(self._ptr,
|
|
185
|
+
.None => .None,
|
|
186
|
+
.Some(ptr) => .Some((ptr &+ index).*)
|
|
187
|
+
)
|
|
188
|
+
)
|
|
189
|
+
),
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Set an element at a specific index (bounds checked)
|
|
193
|
+
* Returns Ok(()) on success, or Error with bounds information
|
|
194
|
+
*/
|
|
195
|
+
set :: (fn(self: Self, index: usize, value: T) -> Result(unit, ArrayListError))(
|
|
196
|
+
cond(
|
|
197
|
+
(index >= self._length) =>
|
|
198
|
+
.Err(.IndexOutOfBounds(index: index, length: self._length)),
|
|
199
|
+
true =>
|
|
200
|
+
match(self._ptr,
|
|
201
|
+
.None => panic("ArrayList has length but no ptr"),
|
|
202
|
+
.Some(ptr) => {
|
|
203
|
+
target_ptr := (ptr &+ index);
|
|
204
|
+
target_ptr.* = value;
|
|
205
|
+
.Ok(())
|
|
206
|
+
}
|
|
207
|
+
)
|
|
208
|
+
)
|
|
209
|
+
),
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Shrink the capacity to match the current length
|
|
213
|
+
* This reduces memory usage but may cause reallocation on next push
|
|
214
|
+
*/
|
|
215
|
+
shrink_to_fit :: ((fn(self: Self) -> Result(unit, ArrayListError))
|
|
216
|
+
// If length equals capacity or both are zero, nothing to do
|
|
217
|
+
cond(
|
|
218
|
+
((self._length == self._capacity) || (self._capacity == usize(0))) => .Ok(()),
|
|
219
|
+
true =>
|
|
220
|
+
// If length is zero, free the buffer
|
|
221
|
+
cond(
|
|
222
|
+
(self._length == usize(0)) => {
|
|
223
|
+
match(self._ptr,
|
|
224
|
+
.Some(ptr) => {
|
|
225
|
+
GlobalAllocator.free(.Some(*(void)(ptr)));
|
|
226
|
+
self._ptr = .None;
|
|
227
|
+
self._capacity = usize(0);
|
|
228
|
+
},
|
|
229
|
+
.None => ());
|
|
230
|
+
.Ok(())
|
|
231
|
+
},
|
|
232
|
+
true =>
|
|
233
|
+
// Otherwise, reallocate to exact size
|
|
234
|
+
match(self._ptr,
|
|
235
|
+
.None => panic("ArrayList has capacity but no ptr"),
|
|
236
|
+
.Some(old_ptr) => {
|
|
237
|
+
new_some_ptr := GlobalAllocator.realloc(
|
|
238
|
+
.Some(*(void)(old_ptr)),
|
|
239
|
+
sizeof(T) * self._length
|
|
240
|
+
);
|
|
241
|
+
match(new_some_ptr,
|
|
242
|
+
.Some(new_ptr) => {
|
|
243
|
+
self._ptr = .Some(*(T)(new_ptr));
|
|
244
|
+
self._capacity = self._length;
|
|
245
|
+
.Ok(())
|
|
246
|
+
},
|
|
247
|
+
.None => .Err(.AllocError(.OutOfMemory))
|
|
248
|
+
)
|
|
249
|
+
}
|
|
250
|
+
)
|
|
251
|
+
)
|
|
252
|
+
)
|
|
253
|
+
),
|
|
254
|
+
|
|
255
|
+
_free_elements :: ((fn(self : Self) -> unit)
|
|
256
|
+
cond(
|
|
257
|
+
Type.contains_gc_type(T) => {
|
|
258
|
+
i := usize(0);
|
|
259
|
+
base_ptr := self._ptr.unwrap();
|
|
260
|
+
while(i < self._length, i = (i + usize(1)), {
|
|
261
|
+
element_ptr := (base_ptr &+ i);
|
|
262
|
+
element := element_ptr.*;
|
|
263
|
+
// element will be automatically dropped here
|
|
264
|
+
});
|
|
265
|
+
},
|
|
266
|
+
true => ()
|
|
267
|
+
)
|
|
268
|
+
),
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Remove elements from the ArrayList starting at index, removing count elements
|
|
272
|
+
* Returns the number of elements actually removed
|
|
273
|
+
*/
|
|
274
|
+
remove :: (fn(self: Self, start: usize, count: usize) -> Result(usize, ArrayListError))(
|
|
275
|
+
// Check if start index is valid
|
|
276
|
+
cond(
|
|
277
|
+
(start >= self._length) =>
|
|
278
|
+
.Err(.IndexOutOfBounds(index: start, length: self._length)),
|
|
279
|
+
true => {
|
|
280
|
+
// Calculate actual number of elements to remove
|
|
281
|
+
// (can't remove more than what's available)
|
|
282
|
+
available := (self._length - start);
|
|
283
|
+
actual_count := cond(
|
|
284
|
+
(count > available) => available,
|
|
285
|
+
true => count
|
|
286
|
+
);
|
|
287
|
+
|
|
288
|
+
// If removing 0 elements, just return success
|
|
289
|
+
cond(
|
|
290
|
+
(actual_count == usize(0)) => .Ok(usize(0)),
|
|
291
|
+
true =>
|
|
292
|
+
match(self._ptr,
|
|
293
|
+
.None => panic("ArrayList has length but no ptr"),
|
|
294
|
+
.Some(ptr) => {
|
|
295
|
+
// Free elements that will be removed if they contain ARC types
|
|
296
|
+
cond(
|
|
297
|
+
Type.contains_gc_type(T) => {
|
|
298
|
+
i := usize(0);
|
|
299
|
+
while(i < actual_count, i = (i + usize(1)), {
|
|
300
|
+
element_ptr := (ptr &+ (start + i));
|
|
301
|
+
element := element_ptr.*;
|
|
302
|
+
// element will be automatically dropped here
|
|
303
|
+
});
|
|
304
|
+
},
|
|
305
|
+
true => ()
|
|
306
|
+
);
|
|
307
|
+
|
|
308
|
+
// Shift remaining elements left to fill the gap
|
|
309
|
+
// We need to move elements from [start + actual_count, length) to [start, ...)
|
|
310
|
+
elements_after := ((self._length - start) - actual_count);
|
|
311
|
+
cond(
|
|
312
|
+
(elements_after > usize(0)) => {
|
|
313
|
+
src_ptr := (ptr &+ (start + actual_count));
|
|
314
|
+
dst_ptr := (ptr &+ start);
|
|
315
|
+
// Move memory
|
|
316
|
+
i := usize(0);
|
|
317
|
+
while(i < elements_after, i = (i + usize(1)), {
|
|
318
|
+
src := (src_ptr &+ i);
|
|
319
|
+
dst := (dst_ptr &+ i);
|
|
320
|
+
dst.* = src.*;
|
|
321
|
+
});
|
|
322
|
+
},
|
|
323
|
+
true => ()
|
|
324
|
+
);
|
|
325
|
+
|
|
326
|
+
// Update length
|
|
327
|
+
self._length = (self._length - actual_count);
|
|
328
|
+
.Ok(actual_count)
|
|
329
|
+
}
|
|
330
|
+
)
|
|
331
|
+
)
|
|
332
|
+
}
|
|
333
|
+
)
|
|
334
|
+
),
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Create a new ArrayList containing a slice of elements from start to end (exclusive)
|
|
338
|
+
* Similar to array slicing in many languages: array[start:end]
|
|
339
|
+
* Returns a new ArrayList with copied elements
|
|
340
|
+
*/
|
|
341
|
+
slice :: (fn(self: Self, start: usize, end: usize) -> Result(Self, ArrayListError))(
|
|
342
|
+
// Validate indices
|
|
343
|
+
cond(
|
|
344
|
+
(start > self._length) =>
|
|
345
|
+
.Err(.IndexOutOfBounds(index: start, length: self._length)),
|
|
346
|
+
(end > self._length) =>
|
|
347
|
+
.Err(.IndexOutOfBounds(index: end, length: self._length)),
|
|
348
|
+
(start > end) =>
|
|
349
|
+
.Err(.IndexOutOfBounds(index: start, length: end)),
|
|
350
|
+
true => {
|
|
351
|
+
slice_length := (end - start);
|
|
352
|
+
|
|
353
|
+
// If slice is empty, return empty ArrayList
|
|
354
|
+
cond(
|
|
355
|
+
(slice_length == usize(0)) =>
|
|
356
|
+
.Ok(Self.new()),
|
|
357
|
+
true =>
|
|
358
|
+
match(self._ptr,
|
|
359
|
+
.None => panic("ArrayList has length but no ptr"),
|
|
360
|
+
.Some(src_ptr) => {
|
|
361
|
+
// Create new ArrayList with exact capacity
|
|
362
|
+
new_list := Self.with_capacity(slice_length);
|
|
363
|
+
|
|
364
|
+
match(new_list._ptr,
|
|
365
|
+
.None => .Err(.AllocError(.OutOfMemory)),
|
|
366
|
+
.Some(dst_ptr) => {
|
|
367
|
+
// Copy elements
|
|
368
|
+
i := usize(0);
|
|
369
|
+
while(i < slice_length, i = (i + usize(1)), {
|
|
370
|
+
src := (src_ptr &+ (start + i));
|
|
371
|
+
dst := (dst_ptr &+ i);
|
|
372
|
+
dst.* = src.*;
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
// Set the length of the new list
|
|
376
|
+
new_list._length = slice_length;
|
|
377
|
+
.Ok(new_list)
|
|
378
|
+
}
|
|
379
|
+
)
|
|
380
|
+
}
|
|
381
|
+
)
|
|
382
|
+
)
|
|
383
|
+
}
|
|
384
|
+
)
|
|
385
|
+
),
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* Clear all elements but keep capacity
|
|
389
|
+
*/
|
|
390
|
+
clear :: (fn(self: Self) -> unit)({
|
|
391
|
+
self._free_elements();
|
|
392
|
+
self._length = usize(0);
|
|
393
|
+
}),
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* RAII destructor - automatically called when ArrayList goes out of scope
|
|
397
|
+
* For `object`, this is called when the reference count drops to zero
|
|
398
|
+
*/
|
|
399
|
+
dispose :: (fn(self: Self) -> unit)({
|
|
400
|
+
match(self._ptr,
|
|
401
|
+
.Some(ptr) => {
|
|
402
|
+
self._free_elements();
|
|
403
|
+
self._length = usize(0);
|
|
404
|
+
GlobalAllocator.free(.Some(*(void)(ptr)));
|
|
405
|
+
self._ptr = .None;
|
|
406
|
+
},
|
|
407
|
+
.None => ()
|
|
408
|
+
);
|
|
409
|
+
})
|
|
410
|
+
);
|
|
411
|
+
|
|
412
|
+
export
|
|
413
|
+
ArrayList,
|
|
414
|
+
ArrayListError
|
|
415
|
+
;
|