@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,439 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LinkedList - A doubly-linked list implementation for Yo language
|
|
3
|
+
*
|
|
4
|
+
* Features:
|
|
5
|
+
* - O(1) push/pop from front and back
|
|
6
|
+
* - O(1) insertion/removal at known positions (with node reference)
|
|
7
|
+
* - RAII for automatic cleanup
|
|
8
|
+
* - True linked list using object indirection
|
|
9
|
+
*
|
|
10
|
+
* Memory layout:
|
|
11
|
+
* - Each node is an object (reference-counted)
|
|
12
|
+
* - Nodes contain: value, optional next node, optional prev node
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* LinkedList error types
|
|
17
|
+
*/
|
|
18
|
+
LinkedListError :: enum(
|
|
19
|
+
IndexOutOfBounds(index: usize, length: usize),
|
|
20
|
+
EmptyList
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Node - Internal structure for linked list nodes
|
|
25
|
+
* Since Node is an object (reference-counted), no Box needed
|
|
26
|
+
*/
|
|
27
|
+
Node :: (fn(compt(T): Type) -> compt(Type))
|
|
28
|
+
object(
|
|
29
|
+
value : T,
|
|
30
|
+
next : Option(Self),
|
|
31
|
+
prev : Option(Self)
|
|
32
|
+
)
|
|
33
|
+
;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* LinkedList - Doubly-linked list with O(1) operations at both ends
|
|
37
|
+
*/
|
|
38
|
+
LinkedList :: (fn(compt(T): Type) -> compt(Type))
|
|
39
|
+
object(
|
|
40
|
+
head : Option(Node(T)),
|
|
41
|
+
tail : Option(Node(T)),
|
|
42
|
+
length : usize,
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Create a new empty LinkedList
|
|
46
|
+
*/
|
|
47
|
+
new :: (fn() -> Self)(
|
|
48
|
+
Self(
|
|
49
|
+
head: .None,
|
|
50
|
+
tail: .None,
|
|
51
|
+
length: usize(0)
|
|
52
|
+
)
|
|
53
|
+
),
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Get the number of elements in the list
|
|
57
|
+
*/
|
|
58
|
+
len :: (fn(self: Self) -> usize)(
|
|
59
|
+
self.length
|
|
60
|
+
),
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Check if the list is empty
|
|
64
|
+
*/
|
|
65
|
+
is_empty :: (fn(self: Self) -> bool)(
|
|
66
|
+
(self.length == usize(0))
|
|
67
|
+
),
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Push an element to the front of the list
|
|
71
|
+
* O(1) time complexity
|
|
72
|
+
*/
|
|
73
|
+
push_front :: (fn(self: Self, value: T) -> unit)(
|
|
74
|
+
{
|
|
75
|
+
new_node := Node(T)(
|
|
76
|
+
value: value,
|
|
77
|
+
next: self.head,
|
|
78
|
+
prev: .None
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
match(self.head,
|
|
82
|
+
.None => {
|
|
83
|
+
self.tail = .Some(new_node);
|
|
84
|
+
},
|
|
85
|
+
.Some(old_head) => {
|
|
86
|
+
old_head.prev = .Some(new_node);
|
|
87
|
+
}
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
self.head = .Some(new_node);
|
|
91
|
+
self.length = (self.length + usize(1));
|
|
92
|
+
}
|
|
93
|
+
),
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Push an element to the back of the list
|
|
97
|
+
* O(1) time complexity
|
|
98
|
+
*/
|
|
99
|
+
push_back :: (fn(self: Self, value: T) -> unit)(
|
|
100
|
+
{
|
|
101
|
+
new_node := Node(T)(
|
|
102
|
+
value: value,
|
|
103
|
+
next: .None,
|
|
104
|
+
prev: self.tail
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
match(self.tail,
|
|
108
|
+
.None => {
|
|
109
|
+
self.head = .Some(new_node);
|
|
110
|
+
},
|
|
111
|
+
.Some(old_tail) => {
|
|
112
|
+
old_tail.next = .Some(new_node);
|
|
113
|
+
}
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
self.tail = .Some(new_node);
|
|
117
|
+
self.length = (self.length + usize(1));
|
|
118
|
+
}
|
|
119
|
+
),
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Remove and return the element from the front
|
|
123
|
+
* O(1) time complexity
|
|
124
|
+
*/
|
|
125
|
+
pop_front :: (fn(self: Self) -> Option(T))(
|
|
126
|
+
match(self.head,
|
|
127
|
+
.None => .None,
|
|
128
|
+
.Some(old_head) => {
|
|
129
|
+
value := old_head.value;
|
|
130
|
+
new_head_opt := old_head.next;
|
|
131
|
+
|
|
132
|
+
match(new_head_opt,
|
|
133
|
+
.None => {
|
|
134
|
+
self.head = .None;
|
|
135
|
+
self.tail = .None;
|
|
136
|
+
},
|
|
137
|
+
.Some(new_head) => {
|
|
138
|
+
new_head.prev = .None;
|
|
139
|
+
self.head = .Some(new_head);
|
|
140
|
+
}
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
self.length = (self.length - usize(1));
|
|
144
|
+
.Some(value)
|
|
145
|
+
}
|
|
146
|
+
)
|
|
147
|
+
),
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Remove and return the element from the back
|
|
151
|
+
* O(1) time complexity
|
|
152
|
+
*/
|
|
153
|
+
pop_back :: (fn(self: Self) -> Option(T))(
|
|
154
|
+
match(self.tail,
|
|
155
|
+
.None => .None,
|
|
156
|
+
.Some(old_tail) => {
|
|
157
|
+
value := old_tail.value;
|
|
158
|
+
new_tail_opt := old_tail.prev;
|
|
159
|
+
|
|
160
|
+
match(new_tail_opt,
|
|
161
|
+
.None => {
|
|
162
|
+
self.head = .None;
|
|
163
|
+
self.tail = .None;
|
|
164
|
+
},
|
|
165
|
+
.Some(new_tail) => {
|
|
166
|
+
new_tail.next = .None;
|
|
167
|
+
self.tail = .Some(new_tail);
|
|
168
|
+
}
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
self.length = (self.length - usize(1));
|
|
172
|
+
.Some(value)
|
|
173
|
+
}
|
|
174
|
+
)
|
|
175
|
+
),
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Get reference to the front element without removing it
|
|
179
|
+
*/
|
|
180
|
+
front :: (fn(self: Self) -> Option(T))(
|
|
181
|
+
match(self.head,
|
|
182
|
+
.None => .None,
|
|
183
|
+
.Some(head_node) => .Some(head_node.value)
|
|
184
|
+
)
|
|
185
|
+
),
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Get reference to the back element without removing it
|
|
189
|
+
*/
|
|
190
|
+
back :: (fn(self: Self) -> Option(T))(
|
|
191
|
+
match(self.tail,
|
|
192
|
+
.None => .None,
|
|
193
|
+
.Some(tail_node) => .Some(tail_node.value)
|
|
194
|
+
)
|
|
195
|
+
),
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Get element at a specific index
|
|
199
|
+
* O(n) time complexity
|
|
200
|
+
*/
|
|
201
|
+
get :: (fn(self: Self, index: usize) -> Option(T))(
|
|
202
|
+
cond(
|
|
203
|
+
(index >= self.length) => .None,
|
|
204
|
+
true => {
|
|
205
|
+
current_opt := self.head;
|
|
206
|
+
i := usize(0);
|
|
207
|
+
|
|
208
|
+
while(i < index, i = (i + usize(1)), {
|
|
209
|
+
match(current_opt,
|
|
210
|
+
.None => {
|
|
211
|
+
return .None;
|
|
212
|
+
},
|
|
213
|
+
.Some(current) => {
|
|
214
|
+
current_opt = current.next;
|
|
215
|
+
()
|
|
216
|
+
}
|
|
217
|
+
);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
match(current_opt,
|
|
221
|
+
.None => .None,
|
|
222
|
+
.Some(node) => .Some(node.value)
|
|
223
|
+
)
|
|
224
|
+
}
|
|
225
|
+
)
|
|
226
|
+
),
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Insert element at a specific index
|
|
230
|
+
* O(n) time complexity
|
|
231
|
+
*/
|
|
232
|
+
insert :: (fn(self: Self, index: usize, value: T) -> Result(unit, LinkedListError))(
|
|
233
|
+
cond(
|
|
234
|
+
(index > self.length) => .Err(.IndexOutOfBounds(index: index, length: self.length)),
|
|
235
|
+
(index == usize(0)) => {
|
|
236
|
+
self.push_front(value);
|
|
237
|
+
.Ok(())
|
|
238
|
+
},
|
|
239
|
+
(index == self.length) => {
|
|
240
|
+
self.push_back(value);
|
|
241
|
+
.Ok(())
|
|
242
|
+
},
|
|
243
|
+
true => {
|
|
244
|
+
current_opt := self.head;
|
|
245
|
+
i := usize(0);
|
|
246
|
+
|
|
247
|
+
while(i < index, i = (i + usize(1)), {
|
|
248
|
+
match(current_opt,
|
|
249
|
+
.None => {
|
|
250
|
+
return .Err(.IndexOutOfBounds(index: index, length: self.length));
|
|
251
|
+
},
|
|
252
|
+
.Some(current) => {
|
|
253
|
+
current_opt = current.next;
|
|
254
|
+
}
|
|
255
|
+
);
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
match(current_opt,
|
|
259
|
+
.None => .Err(.IndexOutOfBounds(index: index, length: self.length)),
|
|
260
|
+
.Some(current) => {
|
|
261
|
+
prev_opt := current.prev;
|
|
262
|
+
|
|
263
|
+
new_node := Node(T)(
|
|
264
|
+
value: value,
|
|
265
|
+
next: .Some(current),
|
|
266
|
+
prev: prev_opt
|
|
267
|
+
);
|
|
268
|
+
|
|
269
|
+
current.prev = .Some(new_node);
|
|
270
|
+
|
|
271
|
+
match(prev_opt,
|
|
272
|
+
.None => {
|
|
273
|
+
self.head = .Some(new_node);
|
|
274
|
+
},
|
|
275
|
+
.Some(prev_node) => {
|
|
276
|
+
prev_node.next = .Some(new_node);
|
|
277
|
+
}
|
|
278
|
+
);
|
|
279
|
+
|
|
280
|
+
self.length = (self.length + usize(1));
|
|
281
|
+
.Ok(())
|
|
282
|
+
}
|
|
283
|
+
)
|
|
284
|
+
}
|
|
285
|
+
)
|
|
286
|
+
),
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Remove element at a specific index
|
|
290
|
+
* O(n) time complexity
|
|
291
|
+
*/
|
|
292
|
+
remove :: (fn(self: Self, index: usize) -> Result(T, LinkedListError))(
|
|
293
|
+
cond(
|
|
294
|
+
(index >= self.length) => .Err(.IndexOutOfBounds(index: index, length: self.length)),
|
|
295
|
+
(index == usize(0)) =>
|
|
296
|
+
match(self.pop_front(),
|
|
297
|
+
.Some(value) => .Ok(value),
|
|
298
|
+
.None => .Err(.EmptyList)
|
|
299
|
+
),
|
|
300
|
+
(index == (self.length - usize(1))) =>
|
|
301
|
+
match(self.pop_back(),
|
|
302
|
+
.Some(value) => .Ok(value),
|
|
303
|
+
.None => .Err(.EmptyList)
|
|
304
|
+
),
|
|
305
|
+
true => {
|
|
306
|
+
current_opt := self.head;
|
|
307
|
+
i := usize(0);
|
|
308
|
+
|
|
309
|
+
while(i < index, i = (i + usize(1)), {
|
|
310
|
+
match(current_opt,
|
|
311
|
+
.None => {
|
|
312
|
+
return .Err(.IndexOutOfBounds(index: index, length: self.length));
|
|
313
|
+
},
|
|
314
|
+
.Some(current) => {
|
|
315
|
+
current_opt = current.next;
|
|
316
|
+
}
|
|
317
|
+
);
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
match(current_opt,
|
|
321
|
+
.None => .Err(.IndexOutOfBounds(index: index, length: self.length)),
|
|
322
|
+
.Some(node_to_remove) => {
|
|
323
|
+
value := node_to_remove.value;
|
|
324
|
+
prev_opt := node_to_remove.prev;
|
|
325
|
+
next_opt := node_to_remove.next;
|
|
326
|
+
|
|
327
|
+
match(prev_opt,
|
|
328
|
+
.Some(prev_node) => {
|
|
329
|
+
prev_node.next = next_opt;
|
|
330
|
+
},
|
|
331
|
+
.None => {
|
|
332
|
+
self.head = next_opt;
|
|
333
|
+
}
|
|
334
|
+
);
|
|
335
|
+
|
|
336
|
+
match(next_opt,
|
|
337
|
+
.Some(next_node) => {
|
|
338
|
+
next_node.prev = prev_opt;
|
|
339
|
+
},
|
|
340
|
+
.None => {
|
|
341
|
+
self.tail = prev_opt;
|
|
342
|
+
}
|
|
343
|
+
);
|
|
344
|
+
|
|
345
|
+
self.length = (self.length - usize(1));
|
|
346
|
+
.Ok(value)
|
|
347
|
+
}
|
|
348
|
+
)
|
|
349
|
+
}
|
|
350
|
+
)
|
|
351
|
+
),
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* Clear all elements from the list
|
|
355
|
+
*/
|
|
356
|
+
clear :: (fn(self: Self) -> unit)(
|
|
357
|
+
{
|
|
358
|
+
while((self.length > usize(0)), {
|
|
359
|
+
_ := self.pop_front();
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
),
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Check if the list contains a value
|
|
366
|
+
* O(n) time complexity
|
|
367
|
+
*/
|
|
368
|
+
has :: (fn(
|
|
369
|
+
self: Self,
|
|
370
|
+
value: T,
|
|
371
|
+
where(T <: Eq(T))
|
|
372
|
+
) -> bool)(
|
|
373
|
+
{
|
|
374
|
+
current_opt := self.head;
|
|
375
|
+
i := usize(0);
|
|
376
|
+
|
|
377
|
+
while(i < self.length, i = (i + usize(1)), {
|
|
378
|
+
match(current_opt,
|
|
379
|
+
.None => {
|
|
380
|
+
return false;
|
|
381
|
+
},
|
|
382
|
+
.Some(current) => {
|
|
383
|
+
cond(
|
|
384
|
+
(current.value == value) => {
|
|
385
|
+
return true;
|
|
386
|
+
},
|
|
387
|
+
true => {
|
|
388
|
+
current_opt = current.next;
|
|
389
|
+
}
|
|
390
|
+
);
|
|
391
|
+
}
|
|
392
|
+
);
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
false
|
|
396
|
+
}
|
|
397
|
+
),
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* Reverse the list in place
|
|
401
|
+
* O(n) time complexity
|
|
402
|
+
*/
|
|
403
|
+
reverse :: (fn(self: Self) -> unit)(
|
|
404
|
+
{
|
|
405
|
+
current_opt := self.head;
|
|
406
|
+
i := usize(0);
|
|
407
|
+
|
|
408
|
+
while(i < self.length, i = (i + usize(1)), {
|
|
409
|
+
match(current_opt,
|
|
410
|
+
.None => {
|
|
411
|
+
return;
|
|
412
|
+
},
|
|
413
|
+
.Some(current) => {
|
|
414
|
+
temp := current.next;
|
|
415
|
+
current.next = current.prev;
|
|
416
|
+
current.prev = temp;
|
|
417
|
+
current_opt = temp;
|
|
418
|
+
}
|
|
419
|
+
);
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
temp_head := self.head;
|
|
423
|
+
self.head = self.tail;
|
|
424
|
+
self.tail = temp_head;
|
|
425
|
+
}
|
|
426
|
+
),
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* RAII destructor - automatically called when LinkedList goes out of scope
|
|
430
|
+
*/
|
|
431
|
+
dispose :: (fn(self: Self) -> unit)(
|
|
432
|
+
self.clear()
|
|
433
|
+
)
|
|
434
|
+
);
|
|
435
|
+
|
|
436
|
+
export
|
|
437
|
+
LinkedList,
|
|
438
|
+
LinkedListError
|
|
439
|
+
;
|
package/std/error.yo
ADDED
|
File without changes
|
package/std/gc.yo
ADDED
package/std/index.yo
ADDED
package/std/io/file.yo
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
{ ArrayList } :: import "../collections/array_list.yo";
|
|
2
|
+
{ String } :: import "../string/string.yo";
|
|
3
|
+
|
|
4
|
+
// File I/O constants (from fcntl.h)
|
|
5
|
+
extern "C",
|
|
6
|
+
O_RDONLY : i32,
|
|
7
|
+
O_WRONLY : i32,
|
|
8
|
+
O_RDWR : i32,
|
|
9
|
+
O_CREAT : i32,
|
|
10
|
+
O_TRUNC : i32,
|
|
11
|
+
O_APPEND : i32
|
|
12
|
+
;
|
|
13
|
+
|
|
14
|
+
// Extern type for I/O Future - maps to yo_io_future_t in C
|
|
15
|
+
// This is the concrete type for futures returned by __yo_async_read_start and __yo_async_write_start
|
|
16
|
+
extern "Yo",
|
|
17
|
+
yo_io_future_t : Type
|
|
18
|
+
;
|
|
19
|
+
|
|
20
|
+
// I/O Future types - opaque handles to C future structs
|
|
21
|
+
// These are returned by __yo_async_read_start and __yo_async_write_start
|
|
22
|
+
// They are awaitable futures implemented in C
|
|
23
|
+
// Concrete(yo_io_future_t) explicitly sets resolvedConcreteType for codegen
|
|
24
|
+
IOReadFuture :: Impl(Concrete(yo_io_future_t), Future(i32));
|
|
25
|
+
IOWriteFuture :: Impl(Concrete(yo_io_future_t), Future(i32));
|
|
26
|
+
|
|
27
|
+
// C runtime functions (generated by codegen in runtime.ts)
|
|
28
|
+
extern "Yo",
|
|
29
|
+
__yo_file_open : (fn(path: *(u8), flags: i32, mode: i32) -> i32),
|
|
30
|
+
__yo_file_close : (fn(fd: i32) -> unit),
|
|
31
|
+
__yo_file_size : (fn(fd: i32) -> i64),
|
|
32
|
+
// Async I/O operations - these return IOReadFuture/IOWriteFuture
|
|
33
|
+
__yo_async_read_start : (fn(fd: i32, buffer: *(u8), size: u32, offset: u64) -> IOReadFuture),
|
|
34
|
+
__yo_async_write_start : (fn(fd: i32, buffer: *(u8), size: u32, offset: u64) -> IOWriteFuture)
|
|
35
|
+
;
|
|
36
|
+
|
|
37
|
+
// I/O Error type
|
|
38
|
+
IOError :: enum(
|
|
39
|
+
NotFound,
|
|
40
|
+
PermissionDenied,
|
|
41
|
+
IsADirectory,
|
|
42
|
+
NoSpaceLeft,
|
|
43
|
+
InvalidUtf8,
|
|
44
|
+
Other(code: i32),
|
|
45
|
+
|
|
46
|
+
from_errno :: (fn(errno: i32) -> Self)(
|
|
47
|
+
cond(
|
|
48
|
+
(errno == 2) => .NotFound, // ENOENT
|
|
49
|
+
(errno == 13) => .PermissionDenied, // EACCES
|
|
50
|
+
(errno == 21) => .IsADirectory, // EISDIR
|
|
51
|
+
(errno == 28) => .NoSpaceLeft, // ENOSPC
|
|
52
|
+
true => .Other(errno)
|
|
53
|
+
)
|
|
54
|
+
),
|
|
55
|
+
|
|
56
|
+
to_string :: (fn(self: Self) -> String)({
|
|
57
|
+
str := match(self,
|
|
58
|
+
.NotFound => String.from_cstr("File not found").unwrap(),
|
|
59
|
+
.PermissionDenied => String.from_cstr("Permission denied").unwrap(),
|
|
60
|
+
.IsADirectory => String.from_cstr("Is a directory").unwrap(),
|
|
61
|
+
.NoSpaceLeft => String.from_cstr("No space left on device").unwrap(),
|
|
62
|
+
.InvalidUtf8 => String.from_cstr("Invalid UTF-8 encoding").unwrap(),
|
|
63
|
+
.Other(code) =>
|
|
64
|
+
// TODO: Format "I/O error: {code}" once we have string formatting
|
|
65
|
+
String.from_cstr("I/O error").unwrap()
|
|
66
|
+
);
|
|
67
|
+
return str;
|
|
68
|
+
})
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
// File handle (reference-counted object)
|
|
72
|
+
File :: object(
|
|
73
|
+
_fd : i32,
|
|
74
|
+
|
|
75
|
+
// Open file (synchronous - fast syscall)
|
|
76
|
+
open :: (fn(path: *(u8), flags: i32) -> Result(Self, IOError))({
|
|
77
|
+
fd := __yo_file_open(path, flags, i32(0o644));
|
|
78
|
+
cond(
|
|
79
|
+
(fd >= i32(0)) => .Ok(Self(_fd: fd)),
|
|
80
|
+
true => .Err(IOError.from_errno((i32(0) - fd)))
|
|
81
|
+
)
|
|
82
|
+
}),
|
|
83
|
+
|
|
84
|
+
// Get file descriptor (for internal use)
|
|
85
|
+
fd :: (fn(self: Self) -> i32)(
|
|
86
|
+
self._fd
|
|
87
|
+
),
|
|
88
|
+
|
|
89
|
+
// Get file size (synchronous)
|
|
90
|
+
size :: (fn(self: Self) -> Result(i64, IOError))({
|
|
91
|
+
result := __yo_file_size(self._fd);
|
|
92
|
+
cond(
|
|
93
|
+
(result >= i64(0)) => .Ok(result),
|
|
94
|
+
true => .Err(IOError.from_errno((i32(0) - (i32(result)))))
|
|
95
|
+
)
|
|
96
|
+
}),
|
|
97
|
+
|
|
98
|
+
// Close file (synchronous)
|
|
99
|
+
// Note: Called automatically by drop when File goes out of scope
|
|
100
|
+
close :: (fn(self: Self) -> unit)({
|
|
101
|
+
__yo_file_close(self._fd);
|
|
102
|
+
}),
|
|
103
|
+
|
|
104
|
+
// Read entire file asynchronously (returns bytes as ArrayList)
|
|
105
|
+
read_bytes_async :: (fn(self: Self) -> Impl Future(Result(ArrayList(u8), IOError)))(async {
|
|
106
|
+
// Get file size first
|
|
107
|
+
size_result := self.size();
|
|
108
|
+
size := match(size_result,
|
|
109
|
+
.Ok(s) => s,
|
|
110
|
+
.Err(e) => return Result(ArrayList(u8), IOError).Err(e)
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
// Allocate buffer
|
|
114
|
+
buffer := ArrayList(u8).with_capacity(usize(size));
|
|
115
|
+
|
|
116
|
+
// Get pointer to buffer
|
|
117
|
+
buffer_ptr := match(buffer.ptr(),
|
|
118
|
+
.Some(ptr) => ptr,
|
|
119
|
+
.None => return Result(ArrayList(u8), IOError).Err(.Other(i32(-12))) // ENOMEM
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
// Start async read (reads entire file from offset 0)
|
|
123
|
+
io_future := __yo_async_read_start(self._fd, buffer_ptr, u32(size), u64(0));
|
|
124
|
+
|
|
125
|
+
// Await the I/O completion
|
|
126
|
+
bytes_read := await io_future;
|
|
127
|
+
|
|
128
|
+
// Check result
|
|
129
|
+
cond(
|
|
130
|
+
(bytes_read < i32(0)) => .Err(IOError.from_errno((i32(0) - bytes_read))),
|
|
131
|
+
true => {
|
|
132
|
+
// Set the buffer length to bytes actually read
|
|
133
|
+
buffer.set_len(usize(bytes_read));
|
|
134
|
+
return .Ok(buffer);
|
|
135
|
+
}
|
|
136
|
+
)
|
|
137
|
+
}),
|
|
138
|
+
|
|
139
|
+
// Read entire file as UTF-8 string asynchronously
|
|
140
|
+
read_string_async :: (fn(self: Self) -> Impl Future(Result(String, IOError)))(async {
|
|
141
|
+
// Read bytes first
|
|
142
|
+
bytes_result := await self.read_bytes_async();
|
|
143
|
+
|
|
144
|
+
match(bytes_result,
|
|
145
|
+
.Ok(bytes) => {
|
|
146
|
+
// Convert to string - validates UTF-8
|
|
147
|
+
string_result := String.from_bytes(bytes);
|
|
148
|
+
.Ok(string_result)
|
|
149
|
+
},
|
|
150
|
+
.Err(e) => .Err(e)
|
|
151
|
+
)
|
|
152
|
+
}),
|
|
153
|
+
|
|
154
|
+
// Write bytes to file asynchronously
|
|
155
|
+
write_bytes_async :: (fn(self: Self, data: ArrayList(u8)) -> Impl Future(Result(unit, IOError)))(async {
|
|
156
|
+
// Get pointer to buffer
|
|
157
|
+
buffer_ptr := match(data.ptr(),
|
|
158
|
+
.Some(ptr) => ptr,
|
|
159
|
+
.None => return Result(unit, IOError).Err(.Other(i32(-22))) // EINVAL - empty buffer
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
// Start async write (writes to offset 0)
|
|
163
|
+
io_future := __yo_async_write_start(self._fd, buffer_ptr, u32(data.len()), u64(0));
|
|
164
|
+
|
|
165
|
+
// Await the I/O completion
|
|
166
|
+
bytes_written := await io_future;
|
|
167
|
+
|
|
168
|
+
// Check result
|
|
169
|
+
cond(
|
|
170
|
+
(bytes_written < i32(0)) => .Err(IOError.from_errno((i32(0) - bytes_written))),
|
|
171
|
+
(bytes_written != i32(data.len())) => .Err(.Other(i32(-5))), // EIO
|
|
172
|
+
true => .Ok(())
|
|
173
|
+
)
|
|
174
|
+
}),
|
|
175
|
+
|
|
176
|
+
// Write string to file asynchronously
|
|
177
|
+
write_string_async :: (fn(self: Self, s: String) -> Impl Future(Result(unit, IOError)))(async {
|
|
178
|
+
// Convert string to bytes
|
|
179
|
+
bytes := s.as_bytes();
|
|
180
|
+
|
|
181
|
+
// Write bytes
|
|
182
|
+
result := await self.write_bytes_async(bytes);
|
|
183
|
+
return result;
|
|
184
|
+
})
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
export
|
|
188
|
+
IOError,
|
|
189
|
+
File,
|
|
190
|
+
O_RDONLY, O_WRONLY, O_RDWR, O_CREAT, O_TRUNC, O_APPEND
|
|
191
|
+
;
|
package/std/io/index.yo
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// C11 assert.h - Assertion debugging facility
|
|
2
|
+
// Provides runtime assertion checking for debugging
|
|
3
|
+
|
|
4
|
+
c_include "<assert.h>",
|
|
5
|
+
// The actual assertion function called by the assert macro
|
|
6
|
+
// This is typically called __assert_fail or similar in libc implementations
|
|
7
|
+
__assert_fail :
|
|
8
|
+
fn(assertion : *(char), file : *(char), line : uint, function : *(char)) -> unit,
|
|
9
|
+
|
|
10
|
+
// Alternative assertion function (some implementations)
|
|
11
|
+
__assert :
|
|
12
|
+
fn(assertion : *(char), file : *(char), line : int) -> unit,
|
|
13
|
+
|
|
14
|
+
// C11 static_assert is handled by the compiler, not runtime
|
|
15
|
+
// But some implementations provide a function version for diagnostics
|
|
16
|
+
_Static_assert_fail :
|
|
17
|
+
fn(message : *(char)) -> unit
|
|
18
|
+
;
|
|
19
|
+
|
|
20
|
+
// Note: In C, assert is typically implemented as a macro:
|
|
21
|
+
// #ifdef NDEBUG
|
|
22
|
+
// #define assert(expr) ((void)0)
|
|
23
|
+
// #else
|
|
24
|
+
// #define assert(expr) \
|
|
25
|
+
// ((expr) ? (void)0 : __assert_fail(#expr, __FILE__, __LINE__, __func__))
|
|
26
|
+
// #endif
|
|
27
|
+
//
|
|
28
|
+
// Since Yo doesn't have preprocessor macros, users would need to:
|
|
29
|
+
// 1. Call __assert_fail directly when assertions fail
|
|
30
|
+
// 2. Use conditional compilation at the language level
|
|
31
|
+
// 3. Or implement assertion logic in their application code
|
|
32
|
+
|
|
33
|
+
// Export assert functionality
|
|
34
|
+
export
|
|
35
|
+
// Low-level assertion functions from C runtime
|
|
36
|
+
__assert_fail,
|
|
37
|
+
__assert,
|
|
38
|
+
_Static_assert_fail
|
|
39
|
+
;
|