@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,82 @@
|
|
|
1
|
+
rune :: newtype(
|
|
2
|
+
c : u32,
|
|
3
|
+
|
|
4
|
+
from_u32 :: ((fn(value: u32) -> Option(Self))
|
|
5
|
+
cond(
|
|
6
|
+
((value <= u32(0x10FFFF)) && (((value < 0xD800) || (value > 0xDFFF)))) => .Some(Self(c: value)),
|
|
7
|
+
true => .None
|
|
8
|
+
)
|
|
9
|
+
),
|
|
10
|
+
|
|
11
|
+
to_u32 :: ((fn(self: Self) -> u32)
|
|
12
|
+
self.c
|
|
13
|
+
),
|
|
14
|
+
|
|
15
|
+
is_ascii :: ((fn(self: Self) -> bool)
|
|
16
|
+
(self.c <= 0x7F)
|
|
17
|
+
),
|
|
18
|
+
|
|
19
|
+
is_whitespace :: ((fn(self: Self) -> bool)
|
|
20
|
+
(((self.c == 0x20) || (self.c == 0x09)) || ((self.c == 0x0A) || (self.c == 0x0D)))
|
|
21
|
+
),
|
|
22
|
+
|
|
23
|
+
is_digit :: ((fn(self: Self) -> bool)
|
|
24
|
+
((self.c >= 0x30) && (self.c <= 0x39))
|
|
25
|
+
),
|
|
26
|
+
|
|
27
|
+
is_alphabetic :: ((fn(self: Self) -> bool)
|
|
28
|
+
(((self.c >= 0x41) && (self.c <= 0x5A)) || ((self.c >= 0x61) && (self.c <= 0x7A)))
|
|
29
|
+
),
|
|
30
|
+
|
|
31
|
+
is_uppercase :: ((fn(self: Self) -> bool)
|
|
32
|
+
((self.c >= 0x41) && (self.c <= 0x5A))
|
|
33
|
+
),
|
|
34
|
+
|
|
35
|
+
is_lowercase :: ((fn(self: Self) -> bool)
|
|
36
|
+
((self.c >= 0x61) && (self.c <= 0x7A))
|
|
37
|
+
),
|
|
38
|
+
|
|
39
|
+
to_lowercase :: ((fn(self: Self) -> Self)
|
|
40
|
+
cond(
|
|
41
|
+
self.is_uppercase() => Self(c: (self.c + 32)),
|
|
42
|
+
true => self
|
|
43
|
+
)
|
|
44
|
+
),
|
|
45
|
+
|
|
46
|
+
to_uppercase :: ((fn(self: Self) -> Self)
|
|
47
|
+
cond(
|
|
48
|
+
self.is_lowercase() => Self(c: (self.c - 32)),
|
|
49
|
+
true => self
|
|
50
|
+
)
|
|
51
|
+
),
|
|
52
|
+
|
|
53
|
+
// Some constants
|
|
54
|
+
NUL :: Self(c: 0x00),
|
|
55
|
+
TAB :: Self(c: 0x09),
|
|
56
|
+
NEWLINE :: Self(c: 0x0A),
|
|
57
|
+
SPACE :: Self(c: 0x20),
|
|
58
|
+
ZERO :: Self(c: 0x30),
|
|
59
|
+
NINE :: Self(c: 0x39),
|
|
60
|
+
UPPERCASE_A :: Self(c: 0x41),
|
|
61
|
+
UPPERCASE_Z :: Self(c: 0x5A),
|
|
62
|
+
LOWERCASE_A :: Self(c: 0x61),
|
|
63
|
+
LOWERCASE_Z :: Self(c: 0x7A)
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
impl(rune, Eq(rune)(
|
|
67
|
+
(==) : ((a, b) -> (a.c == b.c)),
|
|
68
|
+
(!=) : ((a, b) -> (a.c != b.c))
|
|
69
|
+
));
|
|
70
|
+
|
|
71
|
+
impl(rune, Ord(rune)(
|
|
72
|
+
(<) : ((a, b) -> (a.c < b.c)),
|
|
73
|
+
(<=) : ((a, b) -> (a.c <= b.c)),
|
|
74
|
+
(>) : ((a, b) -> (a.c > b.c)),
|
|
75
|
+
(>=) : ((a, b) -> (a.c >= b.c))
|
|
76
|
+
));
|
|
77
|
+
|
|
78
|
+
impl(rune, Send());
|
|
79
|
+
|
|
80
|
+
export
|
|
81
|
+
rune
|
|
82
|
+
;
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
{ ArrayList } :: import "../collections/array_list.yo";
|
|
2
|
+
{ rune } :: import "./rune.yo";
|
|
3
|
+
|
|
4
|
+
StringError :: enum(
|
|
5
|
+
InvalidUtf8,
|
|
6
|
+
IndexOutOfBounds(index: usize, length: usize)
|
|
7
|
+
);
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* String - Immutable UTF-8 encoded string
|
|
11
|
+
*
|
|
12
|
+
* Similar to JavaScript String, Python str, and Rust String.
|
|
13
|
+
* Strings are immutable - all operations return new strings.
|
|
14
|
+
*
|
|
15
|
+
* Internal storage uses ArrayList(u8) for UTF-8 bytes.
|
|
16
|
+
*/
|
|
17
|
+
String :: object(
|
|
18
|
+
_bytes: ArrayList(u8),
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Create a new empty string
|
|
22
|
+
*/
|
|
23
|
+
new :: (fn() -> Self)(
|
|
24
|
+
Self(_bytes: ArrayList(u8).new())
|
|
25
|
+
),
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Create a string from raw bytes (assumes valid UTF-8)
|
|
29
|
+
* No validation is performed - the caller must ensure bytes are valid UTF-8
|
|
30
|
+
*/
|
|
31
|
+
from_bytes :: (fn(bytes: ArrayList(u8)) -> Self)(
|
|
32
|
+
Self(_bytes: bytes)
|
|
33
|
+
),
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Create a string from a slice of bytes [u8]
|
|
37
|
+
* The slice is a fat pointer containing data pointer and length
|
|
38
|
+
* Example: String.from(slice) where slice is [u8]
|
|
39
|
+
*/
|
|
40
|
+
from :: (fn(slice: [u8]) -> Self)({
|
|
41
|
+
// Create a new ArrayList and copy bytes from the slice
|
|
42
|
+
bytes := ArrayList(u8).with_capacity(slice.len());
|
|
43
|
+
|
|
44
|
+
i := usize(0);
|
|
45
|
+
while ((i < slice.len())),
|
|
46
|
+
(i = (i + usize(1))),
|
|
47
|
+
{
|
|
48
|
+
byte := slice(i);
|
|
49
|
+
bytes.push(byte);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
return Self(_bytes: bytes);
|
|
53
|
+
}),
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Create a string from a C null-terminated string *(u8)
|
|
57
|
+
* Copies bytes until it finds a null byte (0)
|
|
58
|
+
* Example: String.from_cstr(c_string_ptr)
|
|
59
|
+
*
|
|
60
|
+
* Note: We manually search for the null terminator by iterating
|
|
61
|
+
*/
|
|
62
|
+
from_cstr :: (fn(cstr: *(u8)) -> Result(Self, StringError))({
|
|
63
|
+
// Create a new ArrayList to store the bytes
|
|
64
|
+
bytes := ArrayList(u8).new();
|
|
65
|
+
|
|
66
|
+
// Iterate through the C string until we find the null terminator
|
|
67
|
+
i := usize(0);
|
|
68
|
+
// FIXME: This is causing infinite loop during compile-time evaluation.
|
|
69
|
+
// We need to check if the loop body has runtime expr, then we shouldn't consider it as infinite loop.
|
|
70
|
+
while {f := true; f}, (i = (i + usize(1))), {
|
|
71
|
+
// Access byte at index i using pointer arithmetic/
|
|
72
|
+
byte_ptr := (cstr &+ i);
|
|
73
|
+
byte := byte_ptr.*;
|
|
74
|
+
|
|
75
|
+
// Stop when we find the null terminator
|
|
76
|
+
cond(
|
|
77
|
+
(byte == u8(0)) => break,
|
|
78
|
+
true => bytes.push(byte)
|
|
79
|
+
);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
return .Ok(Self(_bytes: bytes));
|
|
83
|
+
}),
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Get the length of the string in Unicode characters (runes)
|
|
87
|
+
* For "你好世界", this returns 4
|
|
88
|
+
*/
|
|
89
|
+
len :: (fn(self: Self) -> usize)({
|
|
90
|
+
count := usize(0);
|
|
91
|
+
byte_index := usize(0);
|
|
92
|
+
total_bytes := self._bytes.len();
|
|
93
|
+
|
|
94
|
+
while ((byte_index < total_bytes)),
|
|
95
|
+
(byte_index = (byte_index + usize(1))),
|
|
96
|
+
{
|
|
97
|
+
byte_opt := self._bytes.get(byte_index);
|
|
98
|
+
match(byte_opt,
|
|
99
|
+
.Some(byte) => {
|
|
100
|
+
// Count UTF-8 character start bytes (not continuation bytes)
|
|
101
|
+
// Continuation bytes have pattern 10xxxxxx (0x80-0xBF)
|
|
102
|
+
cond(
|
|
103
|
+
((byte < u8(0x80)) || (byte >= u8(0xC0))) => {
|
|
104
|
+
count = (count + usize(1));
|
|
105
|
+
},
|
|
106
|
+
true => ()
|
|
107
|
+
);
|
|
108
|
+
},
|
|
109
|
+
.None => ()
|
|
110
|
+
);
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
return count;
|
|
114
|
+
}),
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Check if the string is empty
|
|
118
|
+
*/
|
|
119
|
+
is_empty :: ((fn(self: Self) -> bool)
|
|
120
|
+
(self._bytes.len() == usize(0))
|
|
121
|
+
),
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Get a reference to the internal byte array
|
|
125
|
+
*/
|
|
126
|
+
as_bytes :: (fn(self: Self) -> ArrayList(u8))(
|
|
127
|
+
self._bytes
|
|
128
|
+
),
|
|
129
|
+
// as_bytes :: (fn(self: Self) -> ArrayList(u8))({
|
|
130
|
+
// return self._bytes;
|
|
131
|
+
// }),
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Decode a UTF-8 encoded rune starting at the given byte index
|
|
135
|
+
* Internal helper method
|
|
136
|
+
*/
|
|
137
|
+
_decode_rune_at :: (fn(self: Self, byte_index: usize) -> Option(rune))({
|
|
138
|
+
first_byte_opt := self._bytes.get(byte_index);
|
|
139
|
+
match(first_byte_opt,
|
|
140
|
+
.Some(first_byte) => {
|
|
141
|
+
// Determine how many bytes this UTF-8 character uses
|
|
142
|
+
(res : Option(rune)) = cond(
|
|
143
|
+
// 1-byte character: 0xxxxxxx (ASCII)
|
|
144
|
+
(first_byte < u8(0x80)) => {
|
|
145
|
+
codepoint := u32(first_byte);
|
|
146
|
+
rune.from_u32(codepoint)
|
|
147
|
+
},
|
|
148
|
+
// 2-byte character: 110xxxxx 10xxxxxx
|
|
149
|
+
((first_byte >= u8(0xC0)) && (first_byte < u8(0xE0))) => {
|
|
150
|
+
second_opt := self._bytes.get((byte_index + usize(1)));
|
|
151
|
+
match(second_opt,
|
|
152
|
+
.Some(second) => {
|
|
153
|
+
codepoint := (((u32(first_byte) & u32(0x1F)) << u32(6)) | (u32(second) & u32(0x3F)));
|
|
154
|
+
rune.from_u32(codepoint)
|
|
155
|
+
},
|
|
156
|
+
.None => .None
|
|
157
|
+
)
|
|
158
|
+
},
|
|
159
|
+
// 3-byte character: 1110xxxx 10xxxxxx 10xxxxxx
|
|
160
|
+
((first_byte >= u8(0xE0)) && (first_byte < u8(0xF0))) => {
|
|
161
|
+
second_opt := self._bytes.get((byte_index + usize(1)));
|
|
162
|
+
third_opt := self._bytes.get((byte_index + usize(2)));
|
|
163
|
+
match(second_opt,
|
|
164
|
+
.Some(second) =>
|
|
165
|
+
match(third_opt,
|
|
166
|
+
.Some(third) => {
|
|
167
|
+
codepoint := ((((u32(first_byte) & u32(0x0F)) << u32(12)) | ((u32(second) & u32(0x3F)) << u32(6))) | (u32(third) & u32(0x3F)));
|
|
168
|
+
rune.from_u32(codepoint)
|
|
169
|
+
},
|
|
170
|
+
.None => .None
|
|
171
|
+
),
|
|
172
|
+
.None => .None
|
|
173
|
+
)
|
|
174
|
+
},
|
|
175
|
+
// 4-byte character: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
|
|
176
|
+
((first_byte >= u8(0xF0)) && (first_byte < u8(0xF8))) => {
|
|
177
|
+
second_opt := self._bytes.get((byte_index + usize(1)));
|
|
178
|
+
third_opt := self._bytes.get((byte_index + usize(2)));
|
|
179
|
+
fourth_opt := self._bytes.get((byte_index + usize(3)));
|
|
180
|
+
match(second_opt,
|
|
181
|
+
.Some(second) =>
|
|
182
|
+
match(third_opt,
|
|
183
|
+
.Some(third) =>
|
|
184
|
+
match(fourth_opt,
|
|
185
|
+
.Some(fourth) => {
|
|
186
|
+
codepoint := (((((u32(first_byte) & u32(0x07)) << u32(18)) | ((u32(second) & u32(0x3F)) << u32(12))) | ((u32(third) & u32(0x3F)) << u32(6))) | (u32(fourth) & u32(0x3F)));
|
|
187
|
+
rune.from_u32(codepoint)
|
|
188
|
+
},
|
|
189
|
+
.None => .None
|
|
190
|
+
),
|
|
191
|
+
.None => .None
|
|
192
|
+
),
|
|
193
|
+
.None => .None
|
|
194
|
+
)
|
|
195
|
+
},
|
|
196
|
+
// Invalid UTF-8 start byte
|
|
197
|
+
true => .None
|
|
198
|
+
);
|
|
199
|
+
return res;
|
|
200
|
+
},
|
|
201
|
+
.None => .None
|
|
202
|
+
)
|
|
203
|
+
}),
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Get the rune at the specified character index (0-based)
|
|
207
|
+
* Returns None if index is out of bounds
|
|
208
|
+
* For "你好世界", at(0) returns '你', at(1) returns '好', etc.
|
|
209
|
+
*/
|
|
210
|
+
at :: (fn(self: Self, index: usize) -> Option(rune))({
|
|
211
|
+
char_count := usize(0);
|
|
212
|
+
byte_index := usize(0);
|
|
213
|
+
total_bytes := self._bytes.len();
|
|
214
|
+
|
|
215
|
+
// Find the byte position of the character at the given index
|
|
216
|
+
while ((byte_index < total_bytes)),
|
|
217
|
+
(byte_index = (byte_index + usize(1))),
|
|
218
|
+
{
|
|
219
|
+
byte_opt := self._bytes.get(byte_index);
|
|
220
|
+
match(byte_opt,
|
|
221
|
+
.Some(byte) => {
|
|
222
|
+
// Check if this is a UTF-8 character start byte
|
|
223
|
+
is_start := ((byte < u8(0x80)) || (byte >= u8(0xC0)));
|
|
224
|
+
cond(
|
|
225
|
+
is_start => {
|
|
226
|
+
// Found a character start byte
|
|
227
|
+
cond(
|
|
228
|
+
(char_count == index) => {
|
|
229
|
+
// This is the character we want, decode it
|
|
230
|
+
return self._decode_rune_at(byte_index);
|
|
231
|
+
},
|
|
232
|
+
true => {
|
|
233
|
+
// Not the right character yet, keep counting
|
|
234
|
+
char_count = (char_count + usize(1));
|
|
235
|
+
}
|
|
236
|
+
);
|
|
237
|
+
},
|
|
238
|
+
true => ()
|
|
239
|
+
);
|
|
240
|
+
},
|
|
241
|
+
.None => ()
|
|
242
|
+
);
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
// Index out of bounds
|
|
246
|
+
return .None;
|
|
247
|
+
}),
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Concatenate two strings (like JavaScript +)
|
|
251
|
+
*/
|
|
252
|
+
concat :: (fn(self: Self, other: Self) -> Self)({
|
|
253
|
+
self_len := self._bytes.len();
|
|
254
|
+
other_len := other._bytes.len();
|
|
255
|
+
new_bytes := ArrayList(u8).with_capacity((self_len + other_len));
|
|
256
|
+
|
|
257
|
+
// Copy bytes from self
|
|
258
|
+
i := usize(0);
|
|
259
|
+
while ((i < self_len)),
|
|
260
|
+
(i = (i + usize(1))),
|
|
261
|
+
{
|
|
262
|
+
byte_opt := self._bytes.get(i);
|
|
263
|
+
match(byte_opt,
|
|
264
|
+
.Some(byte) => { new_bytes.push(byte); },
|
|
265
|
+
.None => { panic("String.concat: failed to get byte from self"); }
|
|
266
|
+
);
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
// Copy bytes from other
|
|
270
|
+
j := usize(0);
|
|
271
|
+
while ((j < other_len)),
|
|
272
|
+
(j = (j + usize(1))),
|
|
273
|
+
{
|
|
274
|
+
byte_opt := other._bytes.get(j);
|
|
275
|
+
match(byte_opt,
|
|
276
|
+
.Some(byte) => { new_bytes.push(byte); },
|
|
277
|
+
.None => { panic("String.concat: failed to get byte from other"); }
|
|
278
|
+
);
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
return Self(_bytes: new_bytes);
|
|
282
|
+
})
|
|
283
|
+
);
|
|
284
|
+
|
|
285
|
+
export
|
|
286
|
+
String,
|
|
287
|
+
StringError
|
|
288
|
+
;
|
package/std/sync.yo
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
extern "Yo",
|
|
2
|
+
YO_THREAD_SYNC_TYPE : Type,
|
|
3
|
+
YO_COND_TYPE : Type,
|
|
4
|
+
yo_mutex_create : (fn() -> YO_THREAD_SYNC_TYPE),
|
|
5
|
+
yo_cond_create : (fn() -> YO_COND_TYPE),
|
|
6
|
+
yo_mutex_lock : (fn(mutex : *(YO_THREAD_SYNC_TYPE)) -> unit),
|
|
7
|
+
yo_mutex_unlock : (fn(mutex : *(YO_THREAD_SYNC_TYPE)) -> unit),
|
|
8
|
+
yo_mutex_destroy : (fn(mutex : *(YO_THREAD_SYNC_TYPE)) -> unit),
|
|
9
|
+
yo_cond_wait : (fn(cv : *(YO_COND_TYPE), mutex : *(YO_THREAD_SYNC_TYPE)) -> unit),
|
|
10
|
+
yo_cond_signal : (fn(cv : *(YO_COND_TYPE)) -> unit),
|
|
11
|
+
yo_cond_broadcast : (fn(cv : *(YO_COND_TYPE)) -> unit),
|
|
12
|
+
yo_cond_destroy : (fn(cv : *(YO_COND_TYPE)) -> unit)
|
|
13
|
+
;
|
|
14
|
+
|
|
15
|
+
mutex_t :: newtype(
|
|
16
|
+
mutex : YO_THREAD_SYNC_TYPE,
|
|
17
|
+
|
|
18
|
+
new :: ((fn() -> Self) {
|
|
19
|
+
return Self(yo_mutex_create());
|
|
20
|
+
}),
|
|
21
|
+
lock :: ((fn(self : *(Self))-> unit) {
|
|
22
|
+
return yo_mutex_lock(&(self.mutex));
|
|
23
|
+
}),
|
|
24
|
+
unlock :: ((fn(self : *(Self)) -> unit) {
|
|
25
|
+
return yo_mutex_unlock(&(self.mutex));
|
|
26
|
+
}),
|
|
27
|
+
destroy :: ((fn(self : *(Self)) -> unit) {
|
|
28
|
+
return yo_mutex_destroy(&(self.mutex));
|
|
29
|
+
})
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
// GC managed
|
|
33
|
+
Mutex :: object(
|
|
34
|
+
mutex : YO_THREAD_SYNC_TYPE,
|
|
35
|
+
|
|
36
|
+
new :: ((fn() -> Self) {
|
|
37
|
+
return Self(yo_mutex_create());
|
|
38
|
+
}),
|
|
39
|
+
lock :: ((fn(self : Self)-> unit) {
|
|
40
|
+
return yo_mutex_lock(&(self.mutex));
|
|
41
|
+
}),
|
|
42
|
+
unlock :: ((fn(self : Self) -> unit) {
|
|
43
|
+
return yo_mutex_unlock(&(self.mutex));
|
|
44
|
+
}),
|
|
45
|
+
dispose :: ((fn(self : Self) -> unit) {
|
|
46
|
+
return yo_mutex_destroy(&(self.mutex));
|
|
47
|
+
})
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
cond_t :: newtype(
|
|
51
|
+
cv : YO_COND_TYPE,
|
|
52
|
+
|
|
53
|
+
new :: ((fn() -> Self) {
|
|
54
|
+
return Self(yo_cond_create());
|
|
55
|
+
}),
|
|
56
|
+
wait :: ((fn(self : *(Self), mutex : *(mutex_t)) -> unit) {
|
|
57
|
+
return yo_cond_wait(&(self.cv), &(mutex.mutex));
|
|
58
|
+
}),
|
|
59
|
+
signal :: ((fn(self : *(Self)) -> unit) {
|
|
60
|
+
return yo_cond_signal(&(self.cv));
|
|
61
|
+
}),
|
|
62
|
+
broadcast :: ((fn(self : *(Self)) -> unit) {
|
|
63
|
+
return yo_cond_broadcast(&(self.cv));
|
|
64
|
+
}),
|
|
65
|
+
destroy :: ((fn(self : *(Self)) -> unit) {
|
|
66
|
+
return yo_cond_destroy(&(self.cv));
|
|
67
|
+
})
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
Cond :: object(
|
|
71
|
+
cv : YO_COND_TYPE,
|
|
72
|
+
|
|
73
|
+
new :: ((fn() -> Self) {
|
|
74
|
+
return Self(yo_cond_create());
|
|
75
|
+
}),
|
|
76
|
+
wait :: ((fn(self : Self, mutex : Mutex) -> unit) {
|
|
77
|
+
return yo_cond_wait(&(self.cv), &(mutex.mutex));
|
|
78
|
+
}),
|
|
79
|
+
signal :: ((fn(self : Self) -> unit) {
|
|
80
|
+
return yo_cond_signal(&(self.cv));
|
|
81
|
+
}),
|
|
82
|
+
broadcast :: ((fn(self : Self) -> unit) {
|
|
83
|
+
return yo_cond_broadcast(&(self.cv));
|
|
84
|
+
}),
|
|
85
|
+
dispose :: ((fn(self : Self) -> unit) {
|
|
86
|
+
return yo_cond_destroy(&(self.cv));
|
|
87
|
+
})
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
export
|
|
91
|
+
mutex_t,
|
|
92
|
+
Mutex,
|
|
93
|
+
cond_t,
|
|
94
|
+
Cond
|
|
95
|
+
;
|
package/std/thread.yo
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
extern "Yo",
|
|
2
|
+
// Thread utilities
|
|
3
|
+
__yo_thread_get_hardware_threads: (fn() -> usize),
|
|
4
|
+
__yo_get_thread_id : (fn() -> usize),
|
|
5
|
+
__yo_get_cpu_id : (fn() -> i32)
|
|
6
|
+
;
|
|
7
|
+
|
|
8
|
+
// Low-level runtime types and functions for Thread
|
|
9
|
+
extern "Yo",
|
|
10
|
+
__yo_thread_t : Type,
|
|
11
|
+
__yo_thread_spawn : (fn(cb : Impl(Fn() -> unit, Send)) -> __yo_thread_t),
|
|
12
|
+
__yo_thread_join : (fn(t : __yo_thread_t) -> unit)
|
|
13
|
+
;
|
|
14
|
+
|
|
15
|
+
// High-level Thread wrapper - a simple struct (stack allocated)
|
|
16
|
+
Thread :: struct(
|
|
17
|
+
handle : __yo_thread_t,
|
|
18
|
+
|
|
19
|
+
// Spawn a new OS thread running the given closure
|
|
20
|
+
spawn :: (fn(cb : Impl(Fn() -> unit, Send)) -> Self)({
|
|
21
|
+
raw := __yo_thread_spawn(cb);
|
|
22
|
+
Self(raw)
|
|
23
|
+
}),
|
|
24
|
+
|
|
25
|
+
// Wait for the thread to complete (blocking)
|
|
26
|
+
join :: (fn(self : *(Self)) -> unit)(
|
|
27
|
+
__yo_thread_join(self.handle)
|
|
28
|
+
)
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
export
|
|
32
|
+
get_hardware_threads : __yo_thread_get_hardware_threads,
|
|
33
|
+
get_thread_id : __yo_get_thread_id,
|
|
34
|
+
get_cpu_id : __yo_get_cpu_id,
|
|
35
|
+
Thread
|
|
36
|
+
;
|
package/std/time.yo
ADDED
package/std/worker.yo
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// Worker - Thread Pool with Thread Affinity
|
|
2
|
+
// ==========================================
|
|
3
|
+
// Worker spawns tasks on a thread pool. Each task has thread affinity:
|
|
4
|
+
// tasks are distributed round-robin to worker threads and stay on their
|
|
5
|
+
// assigned thread (no work stealing).
|
|
6
|
+
//
|
|
7
|
+
// Thread-per-core: By default, one worker thread per CPU core.
|
|
8
|
+
// Thread affinity: Each task runs on a specific worker thread.
|
|
9
|
+
// Thread-local GC: Each worker thread has its own GC heap.
|
|
10
|
+
|
|
11
|
+
extern "Yo",
|
|
12
|
+
__yo_worker_spawn : (fn(cb : Impl(Fn() -> unit, Send)) -> unit),
|
|
13
|
+
__yo_worker_get_num_threads : (fn() -> usize),
|
|
14
|
+
__yo_worker_set_num_threads : (fn(num: usize) -> unit)
|
|
15
|
+
;
|
|
16
|
+
|
|
17
|
+
// Spawn a task on the thread pool.
|
|
18
|
+
// Returns immediately, task runs in background.
|
|
19
|
+
// Tasks are distributed round-robin to worker threads.
|
|
20
|
+
spawn :: (fn(cb : Impl(Fn() -> unit, Send)) -> unit)({
|
|
21
|
+
__yo_worker_spawn(cb);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
// Get number of threads in pool.
|
|
25
|
+
// Default: number of hardware threads (CPU cores).
|
|
26
|
+
get_num_threads :: (fn() -> usize)(
|
|
27
|
+
__yo_worker_get_num_threads()
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
// Configure thread pool size.
|
|
31
|
+
// Must be called before first spawn to take effect.
|
|
32
|
+
set_num_threads :: (fn(num: usize) -> unit)(
|
|
33
|
+
__yo_worker_set_num_threads(num)
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
export spawn, get_num_threads, set_num_threads;
|