@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,334 @@
|
|
|
1
|
+
/* ----------------------------------------------------------------------------
|
|
2
|
+
Copyright (c) 2018-2023, Microsoft Research, Daan Leijen
|
|
3
|
+
This is free software; you can redistribute it and/or modify it under the
|
|
4
|
+
terms of the MIT license. A copy of the license can be found in the file
|
|
5
|
+
"LICENSE" at the root of this distribution.
|
|
6
|
+
-----------------------------------------------------------------------------*/
|
|
7
|
+
|
|
8
|
+
// --------------------------------------------------------
|
|
9
|
+
// This module defines various std libc functions to reduce
|
|
10
|
+
// the dependency on libc, and also prevent errors caused
|
|
11
|
+
// by some libc implementations when called before `main`
|
|
12
|
+
// executes (due to malloc redirection)
|
|
13
|
+
// --------------------------------------------------------
|
|
14
|
+
|
|
15
|
+
#include "mimalloc.h"
|
|
16
|
+
#include "mimalloc/internal.h"
|
|
17
|
+
#include "mimalloc/prim.h" // mi_prim_getenv
|
|
18
|
+
|
|
19
|
+
char _mi_toupper(char c) {
|
|
20
|
+
if (c >= 'a' && c <= 'z') return (c - 'a' + 'A');
|
|
21
|
+
else return c;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
int _mi_strnicmp(const char* s, const char* t, size_t n) {
|
|
25
|
+
if (n == 0) return 0;
|
|
26
|
+
for (; *s != 0 && *t != 0 && n > 0; s++, t++, n--) {
|
|
27
|
+
if (_mi_toupper(*s) != _mi_toupper(*t)) break;
|
|
28
|
+
}
|
|
29
|
+
return (n == 0 ? 0 : *s - *t);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
void _mi_strlcpy(char* dest, const char* src, size_t dest_size) {
|
|
33
|
+
if (dest==NULL || src==NULL || dest_size == 0) return;
|
|
34
|
+
// copy until end of src, or when dest is (almost) full
|
|
35
|
+
while (*src != 0 && dest_size > 1) {
|
|
36
|
+
*dest++ = *src++;
|
|
37
|
+
dest_size--;
|
|
38
|
+
}
|
|
39
|
+
// always zero terminate
|
|
40
|
+
*dest = 0;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
void _mi_strlcat(char* dest, const char* src, size_t dest_size) {
|
|
44
|
+
if (dest==NULL || src==NULL || dest_size == 0) return;
|
|
45
|
+
// find end of string in the dest buffer
|
|
46
|
+
while (*dest != 0 && dest_size > 1) {
|
|
47
|
+
dest++;
|
|
48
|
+
dest_size--;
|
|
49
|
+
}
|
|
50
|
+
// and catenate
|
|
51
|
+
_mi_strlcpy(dest, src, dest_size);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
size_t _mi_strlen(const char* s) {
|
|
55
|
+
if (s==NULL) return 0;
|
|
56
|
+
size_t len = 0;
|
|
57
|
+
while(s[len] != 0) { len++; }
|
|
58
|
+
return len;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
size_t _mi_strnlen(const char* s, size_t max_len) {
|
|
62
|
+
if (s==NULL) return 0;
|
|
63
|
+
size_t len = 0;
|
|
64
|
+
while(s[len] != 0 && len < max_len) { len++; }
|
|
65
|
+
return len;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
#ifdef MI_NO_GETENV
|
|
69
|
+
bool _mi_getenv(const char* name, char* result, size_t result_size) {
|
|
70
|
+
MI_UNUSED(name);
|
|
71
|
+
MI_UNUSED(result);
|
|
72
|
+
MI_UNUSED(result_size);
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
#else
|
|
76
|
+
bool _mi_getenv(const char* name, char* result, size_t result_size) {
|
|
77
|
+
if (name==NULL || result == NULL || result_size < 64) return false;
|
|
78
|
+
return _mi_prim_getenv(name,result,result_size);
|
|
79
|
+
}
|
|
80
|
+
#endif
|
|
81
|
+
|
|
82
|
+
// --------------------------------------------------------
|
|
83
|
+
// Define our own limited `_mi_vsnprintf` and `_mi_snprintf`
|
|
84
|
+
// This is mostly to avoid calling these when libc is not yet
|
|
85
|
+
// initialized (and to reduce dependencies)
|
|
86
|
+
//
|
|
87
|
+
// format: d i, p x u, s
|
|
88
|
+
// prec: z l ll L
|
|
89
|
+
// width: 10
|
|
90
|
+
// align-left: -
|
|
91
|
+
// fill: 0
|
|
92
|
+
// plus: +
|
|
93
|
+
// --------------------------------------------------------
|
|
94
|
+
|
|
95
|
+
static void mi_outc(char c, char** out, char* end) {
|
|
96
|
+
char* p = *out;
|
|
97
|
+
if (p >= end) return;
|
|
98
|
+
*p = c;
|
|
99
|
+
*out = p + 1;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
static void mi_outs(const char* s, char** out, char* end) {
|
|
103
|
+
if (s == NULL) return;
|
|
104
|
+
char* p = *out;
|
|
105
|
+
while (*s != 0 && p < end) {
|
|
106
|
+
*p++ = *s++;
|
|
107
|
+
}
|
|
108
|
+
*out = p;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
static void mi_out_fill(char fill, size_t len, char** out, char* end) {
|
|
112
|
+
char* p = *out;
|
|
113
|
+
for (size_t i = 0; i < len && p < end; i++) {
|
|
114
|
+
*p++ = fill;
|
|
115
|
+
}
|
|
116
|
+
*out = p;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
static void mi_out_alignright(char fill, char* start, size_t len, size_t extra, char* end) {
|
|
120
|
+
if (len == 0 || extra == 0) return;
|
|
121
|
+
if (start + len + extra >= end) return;
|
|
122
|
+
// move `len` characters to the right (in reverse since it can overlap)
|
|
123
|
+
for (size_t i = 1; i <= len; i++) {
|
|
124
|
+
start[len + extra - i] = start[len - i];
|
|
125
|
+
}
|
|
126
|
+
// and fill the start
|
|
127
|
+
for (size_t i = 0; i < extra; i++) {
|
|
128
|
+
start[i] = fill;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
static void mi_out_num(uintmax_t x, size_t base, char prefix, char** out, char* end)
|
|
134
|
+
{
|
|
135
|
+
if (x == 0 || base == 0 || base > 16) {
|
|
136
|
+
if (prefix != 0) { mi_outc(prefix, out, end); }
|
|
137
|
+
mi_outc('0',out,end);
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
// output digits in reverse
|
|
141
|
+
char* start = *out;
|
|
142
|
+
while (x > 0) {
|
|
143
|
+
char digit = (char)(x % base);
|
|
144
|
+
mi_outc((digit <= 9 ? '0' + digit : 'A' + digit - 10),out,end);
|
|
145
|
+
x = x / base;
|
|
146
|
+
}
|
|
147
|
+
if (prefix != 0) {
|
|
148
|
+
mi_outc(prefix, out, end);
|
|
149
|
+
}
|
|
150
|
+
size_t len = *out - start;
|
|
151
|
+
// and reverse in-place
|
|
152
|
+
for (size_t i = 0; i < (len / 2); i++) {
|
|
153
|
+
char c = start[len - i - 1];
|
|
154
|
+
start[len - i - 1] = start[i];
|
|
155
|
+
start[i] = c;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
#define MI_NEXTC() c = *in; if (c==0) break; in++;
|
|
162
|
+
|
|
163
|
+
int _mi_vsnprintf(char* buf, size_t bufsize, const char* fmt, va_list args) {
|
|
164
|
+
if (buf == NULL || bufsize == 0 || fmt == NULL) return 0;
|
|
165
|
+
buf[bufsize - 1] = 0;
|
|
166
|
+
char* const end = buf + (bufsize - 1);
|
|
167
|
+
const char* in = fmt;
|
|
168
|
+
char* out = buf;
|
|
169
|
+
while (true) {
|
|
170
|
+
if (out >= end) break;
|
|
171
|
+
char c;
|
|
172
|
+
MI_NEXTC();
|
|
173
|
+
if (c != '%') {
|
|
174
|
+
if ((c >= ' ' && c <= '~') || c=='\n' || c=='\r' || c=='\t') { // output visible ascii or standard control only
|
|
175
|
+
mi_outc(c, &out, end);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
MI_NEXTC();
|
|
180
|
+
char fill = ' ';
|
|
181
|
+
size_t width = 0;
|
|
182
|
+
char numtype = 'd';
|
|
183
|
+
char numplus = 0;
|
|
184
|
+
bool alignright = true;
|
|
185
|
+
if (c == '+' || c == ' ') { numplus = c; MI_NEXTC(); }
|
|
186
|
+
if (c == '-') { alignright = false; MI_NEXTC(); }
|
|
187
|
+
if (c == '0') { fill = '0'; MI_NEXTC(); }
|
|
188
|
+
if (c >= '1' && c <= '9') {
|
|
189
|
+
width = (c - '0'); MI_NEXTC();
|
|
190
|
+
while (c >= '0' && c <= '9') {
|
|
191
|
+
width = (10 * width) + (c - '0'); MI_NEXTC();
|
|
192
|
+
}
|
|
193
|
+
if (c == 0) break; // extra check due to while
|
|
194
|
+
}
|
|
195
|
+
if (c == 'z' || c == 't' || c == 'L') { numtype = c; MI_NEXTC(); }
|
|
196
|
+
else if (c == 'l') {
|
|
197
|
+
numtype = c; MI_NEXTC();
|
|
198
|
+
if (c == 'l') { numtype = 'L'; MI_NEXTC(); }
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
char* start = out;
|
|
202
|
+
if (c == 's') {
|
|
203
|
+
// string
|
|
204
|
+
const char* s = va_arg(args, const char*);
|
|
205
|
+
mi_outs(s, &out, end);
|
|
206
|
+
}
|
|
207
|
+
else if (c == 'p' || c == 'x' || c == 'u') {
|
|
208
|
+
// unsigned
|
|
209
|
+
uintmax_t x = 0;
|
|
210
|
+
if (c == 'x' || c == 'u') {
|
|
211
|
+
if (numtype == 'z') x = va_arg(args, size_t);
|
|
212
|
+
else if (numtype == 't') x = va_arg(args, uintptr_t); // unsigned ptrdiff_t
|
|
213
|
+
else if (numtype == 'L') x = va_arg(args, unsigned long long);
|
|
214
|
+
else if (numtype == 'l') x = va_arg(args, unsigned long);
|
|
215
|
+
else x = va_arg(args, unsigned int);
|
|
216
|
+
}
|
|
217
|
+
else if (c == 'p') {
|
|
218
|
+
x = va_arg(args, uintptr_t);
|
|
219
|
+
mi_outs("0x", &out, end);
|
|
220
|
+
start = out;
|
|
221
|
+
width = (width >= 2 ? width - 2 : 0);
|
|
222
|
+
}
|
|
223
|
+
if (width == 0 && (c == 'x' || c == 'p')) {
|
|
224
|
+
if (c == 'p') { width = 2 * (x <= UINT32_MAX ? 4 : ((x >> 16) <= UINT32_MAX ? 6 : sizeof(void*))); }
|
|
225
|
+
if (width == 0) { width = 2; }
|
|
226
|
+
fill = '0';
|
|
227
|
+
}
|
|
228
|
+
mi_out_num(x, (c == 'x' || c == 'p' ? 16 : 10), numplus, &out, end);
|
|
229
|
+
}
|
|
230
|
+
else if (c == 'i' || c == 'd') {
|
|
231
|
+
// signed
|
|
232
|
+
intmax_t x = 0;
|
|
233
|
+
if (numtype == 'z') x = va_arg(args, intptr_t );
|
|
234
|
+
else if (numtype == 't') x = va_arg(args, ptrdiff_t);
|
|
235
|
+
else if (numtype == 'L') x = va_arg(args, long long);
|
|
236
|
+
else if (numtype == 'l') x = va_arg(args, long);
|
|
237
|
+
else x = va_arg(args, int);
|
|
238
|
+
char pre = 0;
|
|
239
|
+
if (x < 0) {
|
|
240
|
+
pre = '-';
|
|
241
|
+
if (x > INTMAX_MIN) { x = -x; }
|
|
242
|
+
}
|
|
243
|
+
else if (numplus != 0) {
|
|
244
|
+
pre = numplus;
|
|
245
|
+
}
|
|
246
|
+
mi_out_num((uintmax_t)x, 10, pre, &out, end);
|
|
247
|
+
}
|
|
248
|
+
else if (c >= ' ' && c <= '~') {
|
|
249
|
+
// unknown format
|
|
250
|
+
mi_outc('%', &out, end);
|
|
251
|
+
mi_outc(c, &out, end);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// fill & align
|
|
255
|
+
mi_assert_internal(out <= end);
|
|
256
|
+
mi_assert_internal(out >= start);
|
|
257
|
+
const size_t len = out - start;
|
|
258
|
+
if (len < width) {
|
|
259
|
+
mi_out_fill(fill, width - len, &out, end);
|
|
260
|
+
if (alignright && out <= end) {
|
|
261
|
+
mi_out_alignright(fill, start, len, width - len, end);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
mi_assert_internal(out <= end);
|
|
267
|
+
*out = 0;
|
|
268
|
+
return (int)(out - buf);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
int _mi_snprintf(char* buf, size_t buflen, const char* fmt, ...) {
|
|
272
|
+
va_list args;
|
|
273
|
+
va_start(args, fmt);
|
|
274
|
+
const int written = _mi_vsnprintf(buf, buflen, fmt, args);
|
|
275
|
+
va_end(args);
|
|
276
|
+
return written;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
#if MI_SIZE_SIZE == 4
|
|
281
|
+
#define mi_mask_even_bits32 (0x55555555)
|
|
282
|
+
#define mi_mask_even_pairs32 (0x33333333)
|
|
283
|
+
#define mi_mask_even_nibbles32 (0x0F0F0F0F)
|
|
284
|
+
|
|
285
|
+
// sum of all the bytes in `x` if it is guaranteed that the sum < 256!
|
|
286
|
+
static size_t mi_byte_sum32(uint32_t x) {
|
|
287
|
+
// perform `x * 0x01010101`: the highest byte contains the sum of all bytes.
|
|
288
|
+
x += (x << 8);
|
|
289
|
+
x += (x << 16);
|
|
290
|
+
return (size_t)(x >> 24);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
static size_t mi_popcount_generic32(uint32_t x) {
|
|
294
|
+
// first count each 2-bit group `a`, where: a==0b00 -> 00, a==0b01 -> 01, a==0b10 -> 01, a==0b11 -> 10
|
|
295
|
+
// in other words, `a - (a>>1)`; to do this in parallel, we need to mask to prevent spilling a bit pair
|
|
296
|
+
// into the lower bit-pair:
|
|
297
|
+
x = x - ((x >> 1) & mi_mask_even_bits32);
|
|
298
|
+
// add the 2-bit pair results
|
|
299
|
+
x = (x & mi_mask_even_pairs32) + ((x >> 2) & mi_mask_even_pairs32);
|
|
300
|
+
// add the 4-bit nibble results
|
|
301
|
+
x = (x + (x >> 4)) & mi_mask_even_nibbles32;
|
|
302
|
+
// each byte now has a count of its bits, we can sum them now:
|
|
303
|
+
return mi_byte_sum32(x);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
mi_decl_noinline size_t _mi_popcount_generic(size_t x) {
|
|
307
|
+
return mi_popcount_generic32(x);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
#else
|
|
311
|
+
#define mi_mask_even_bits64 (0x5555555555555555)
|
|
312
|
+
#define mi_mask_even_pairs64 (0x3333333333333333)
|
|
313
|
+
#define mi_mask_even_nibbles64 (0x0F0F0F0F0F0F0F0F)
|
|
314
|
+
|
|
315
|
+
// sum of all the bytes in `x` if it is guaranteed that the sum < 256!
|
|
316
|
+
static size_t mi_byte_sum64(uint64_t x) {
|
|
317
|
+
x += (x << 8);
|
|
318
|
+
x += (x << 16);
|
|
319
|
+
x += (x << 32);
|
|
320
|
+
return (size_t)(x >> 56);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
static size_t mi_popcount_generic64(uint64_t x) {
|
|
324
|
+
x = x - ((x >> 1) & mi_mask_even_bits64);
|
|
325
|
+
x = (x & mi_mask_even_pairs64) + ((x >> 2) & mi_mask_even_pairs64);
|
|
326
|
+
x = (x + (x >> 4)) & mi_mask_even_nibbles64;
|
|
327
|
+
return mi_byte_sum64(x);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
mi_decl_noinline size_t _mi_popcount_generic(size_t x) {
|
|
331
|
+
return mi_popcount_generic64(x);
|
|
332
|
+
}
|
|
333
|
+
#endif
|
|
334
|
+
|