goscript 0.1.0 → 0.1.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/README.md +267 -255
- package/cmd/goscript/cmd-test.go +286 -0
- package/cmd/goscript/cmd-test_test.go +76 -0
- package/cmd/goscript/cmd_compile.go +9 -0
- package/cmd/goscript/main.go +1 -0
- package/compiler/build-flags.go +38 -0
- package/compiler/compile-request.go +33 -0
- package/compiler/compiler.go +1 -1
- package/compiler/compliance_test.go +0 -10
- package/compiler/config.go +2 -0
- package/compiler/gotest/owner.go +24 -0
- package/compiler/gotest/package-result.go +69 -0
- package/compiler/gotest/request.go +210 -0
- package/compiler/gotest/result.go +28 -0
- package/compiler/gotest/runner.go +1225 -0
- package/compiler/gotest/runner_test.go +1271 -0
- package/compiler/gotest/test.go +9 -0
- package/compiler/index.test.ts +1 -1
- package/compiler/lowered-program.go +80 -21
- package/compiler/lowering.go +6754 -602
- package/compiler/override-facts.go +357 -0
- package/compiler/override-registry.go +52 -190
- package/compiler/override-registry_test.go +182 -0
- package/compiler/package-graph.go +50 -27
- package/compiler/package-graph_test.go +99 -9
- package/compiler/package-test-function.go +9 -0
- package/compiler/package-test-graph-package.go +40 -0
- package/compiler/package-test-graph-variant.go +129 -0
- package/compiler/package-test-graph.go +112 -0
- package/compiler/package-test-graph_test.go +202 -0
- package/compiler/runtime-contract.go +229 -29
- package/compiler/runtime-contract_test.go +44 -30
- package/compiler/semantic-model-types.go +25 -6
- package/compiler/semantic-model.go +819 -74
- package/compiler/semantic-model_test.go +104 -0
- package/compiler/service.go +10 -4
- package/compiler/skeleton_test.go +2777 -524
- package/compiler/tsworkspace/owner-process-unix_test.go +72 -0
- package/compiler/tsworkspace/owner.go +342 -0
- package/compiler/tsworkspace/owner_test.go +93 -0
- package/compiler/tsworkspace/result.go +17 -0
- package/compiler/tsworkspace/tool-process-other.go +14 -0
- package/compiler/tsworkspace/tool-process-unix.go +19 -0
- package/compiler/typescript-emitter.go +576 -86
- package/compiler/wasm/compile.go +1 -1
- package/compiler/wasm/compile_test.go +61 -11
- package/compiler/wasm_api.go +172 -7
- package/dist/gs/builtin/builtin.d.ts +40 -3
- package/dist/gs/builtin/builtin.js +430 -22
- package/dist/gs/builtin/builtin.js.map +1 -1
- package/dist/gs/builtin/channel.d.ts +32 -10
- package/dist/gs/builtin/channel.js +119 -25
- package/dist/gs/builtin/channel.js.map +1 -1
- package/dist/gs/builtin/defer.d.ts +1 -0
- package/dist/gs/builtin/defer.js +12 -2
- package/dist/gs/builtin/defer.js.map +1 -1
- package/dist/gs/builtin/hostio.d.ts +9 -0
- package/dist/gs/builtin/hostio.js +25 -0
- package/dist/gs/builtin/hostio.js.map +1 -1
- package/dist/gs/builtin/map.js +40 -6
- package/dist/gs/builtin/map.js.map +1 -1
- package/dist/gs/builtin/print.js.map +1 -1
- package/dist/gs/builtin/slice.d.ts +64 -10
- package/dist/gs/builtin/slice.js +619 -244
- package/dist/gs/builtin/slice.js.map +1 -1
- package/dist/gs/builtin/type.d.ts +7 -2
- package/dist/gs/builtin/type.js +128 -29
- package/dist/gs/builtin/type.js.map +1 -1
- package/dist/gs/builtin/varRef.d.ts +7 -0
- package/dist/gs/builtin/varRef.js +23 -0
- package/dist/gs/builtin/varRef.js.map +1 -1
- package/dist/gs/bytes/buffer.gs.js +74 -70
- package/dist/gs/bytes/buffer.gs.js.map +1 -1
- package/dist/gs/bytes/iter.gs.js +13 -13
- package/dist/gs/bytes/iter.gs.js.map +1 -1
- package/dist/gs/bytes/reader.gs.js +20 -18
- package/dist/gs/bytes/reader.gs.js.map +1 -1
- package/dist/gs/compress/zlib/index.d.ts +26 -0
- package/dist/gs/compress/zlib/index.js +168 -0
- package/dist/gs/compress/zlib/index.js.map +1 -0
- package/dist/gs/context/context.d.ts +6 -5
- package/dist/gs/context/context.js +17 -12
- package/dist/gs/context/context.js.map +1 -1
- package/dist/gs/crypto/ecdh/index.d.ts +52 -0
- package/dist/gs/crypto/ecdh/index.js +226 -0
- package/dist/gs/crypto/ecdh/index.js.map +1 -0
- package/dist/gs/crypto/ed25519/index.d.ts +34 -0
- package/dist/gs/crypto/ed25519/index.js +160 -0
- package/dist/gs/crypto/ed25519/index.js.map +1 -0
- package/dist/gs/crypto/internal/constanttime/index.d.ts +4 -0
- package/dist/gs/crypto/internal/constanttime/index.js +18 -0
- package/dist/gs/crypto/internal/constanttime/index.js.map +1 -0
- package/dist/gs/crypto/internal/fips140deps/byteorder/index.d.ts +1 -0
- package/dist/gs/crypto/internal/fips140deps/byteorder/index.js +2 -0
- package/dist/gs/crypto/internal/fips140deps/byteorder/index.js.map +1 -0
- package/dist/gs/crypto/internal/fips140deps/godebug/index.d.ts +1 -0
- package/dist/gs/crypto/internal/fips140deps/godebug/index.js +2 -0
- package/dist/gs/crypto/internal/fips140deps/godebug/index.js.map +1 -0
- package/dist/gs/crypto/rand/index.d.ts +2 -0
- package/dist/gs/crypto/rand/index.js +85 -0
- package/dist/gs/crypto/rand/index.js.map +1 -1
- package/dist/gs/crypto/sha256/index.d.ts +8 -0
- package/dist/gs/crypto/sha256/index.js +118 -0
- package/dist/gs/crypto/sha256/index.js.map +1 -0
- package/dist/gs/crypto/sha512/index.d.ts +14 -0
- package/dist/gs/crypto/sha512/index.js +129 -0
- package/dist/gs/crypto/sha512/index.js.map +1 -0
- package/dist/gs/embed/index.d.ts +7 -0
- package/dist/gs/embed/index.js +16 -0
- package/dist/gs/embed/index.js.map +1 -0
- package/dist/gs/encoding/json/index.d.ts +4 -0
- package/dist/gs/encoding/json/index.js +33 -0
- package/dist/gs/encoding/json/index.js.map +1 -1
- package/dist/gs/errors/errors.d.ts +4 -0
- package/dist/gs/errors/errors.js +108 -4
- package/dist/gs/errors/errors.js.map +1 -1
- package/dist/gs/fmt/fmt.d.ts +4 -4
- package/dist/gs/fmt/fmt.js +42 -11
- package/dist/gs/fmt/fmt.js.map +1 -1
- package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/index.d.ts +37 -2
- package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/index.js +245 -1
- package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/index.js.map +1 -1
- package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/json/index.d.ts +189 -0
- package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/json/index.js +861 -0
- package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/json/index.js.map +1 -0
- package/dist/gs/github.com/aperturerobotics/starpc/srpc/index.d.ts +217 -0
- package/dist/gs/github.com/aperturerobotics/starpc/srpc/index.js +814 -0
- package/dist/gs/github.com/aperturerobotics/starpc/srpc/index.js.map +1 -0
- package/dist/gs/github.com/aperturerobotics/util/conc/index.d.ts +20 -0
- package/dist/gs/github.com/aperturerobotics/util/conc/index.js +134 -0
- package/dist/gs/github.com/aperturerobotics/util/conc/index.js.map +1 -0
- package/dist/gs/github.com/aperturerobotics/wasivm/wazero/kernel/runtime/browser/browser.js.map +1 -1
- package/dist/gs/github.com/hack-pad/safejs/internal/catch/index.d.ts +3 -0
- package/dist/gs/github.com/hack-pad/safejs/internal/catch/index.js +50 -0
- package/dist/gs/github.com/hack-pad/safejs/internal/catch/index.js.map +1 -0
- package/dist/gs/github.com/klauspost/compress/internal/le/index.d.ts +9 -0
- package/dist/gs/github.com/klauspost/compress/internal/le/index.js +72 -0
- package/dist/gs/github.com/klauspost/compress/internal/le/index.js.map +1 -0
- package/dist/gs/github.com/mr-tron/base58/base58/index.d.ts +27 -0
- package/dist/gs/github.com/mr-tron/base58/base58/index.js +172 -0
- package/dist/gs/github.com/mr-tron/base58/base58/index.js.map +1 -0
- package/dist/gs/github.com/zeebo/blake3/internal/consts/index.d.ts +21 -0
- package/dist/gs/github.com/zeebo/blake3/internal/consts/index.js +22 -0
- package/dist/gs/github.com/zeebo/blake3/internal/consts/index.js.map +1 -0
- package/dist/gs/go/internal/scannerhooks/index.d.ts +3 -0
- package/dist/gs/go/internal/scannerhooks/index.js +5 -0
- package/dist/gs/go/internal/scannerhooks/index.js.map +1 -0
- package/dist/gs/go/scanner/index.d.ts +13 -0
- package/dist/gs/go/scanner/index.js +35 -0
- package/dist/gs/go/scanner/index.js.map +1 -1
- package/dist/gs/go/token/index.d.ts +156 -0
- package/dist/gs/go/token/index.js +507 -4
- package/dist/gs/go/token/index.js.map +1 -1
- package/dist/gs/hash/fnv/index.d.ts +57 -0
- package/dist/gs/hash/fnv/index.js +299 -0
- package/dist/gs/hash/fnv/index.js.map +1 -0
- package/dist/gs/hash/index.d.ts +17 -0
- package/dist/gs/hash/index.js +94 -0
- package/dist/gs/hash/index.js.map +1 -0
- package/dist/gs/internal/abi/index.d.ts +4 -0
- package/dist/gs/internal/abi/index.js +10 -0
- package/dist/gs/internal/abi/index.js.map +1 -1
- package/dist/gs/internal/bytealg/index.d.ts +2 -0
- package/dist/gs/internal/bytealg/index.js +14 -0
- package/dist/gs/internal/bytealg/index.js.map +1 -1
- package/dist/gs/internal/byteorder/index.d.ts +8 -2
- package/dist/gs/internal/byteorder/index.js +56 -25
- package/dist/gs/internal/byteorder/index.js.map +1 -1
- package/dist/gs/internal/godebug/index.d.ts +12 -0
- package/dist/gs/internal/godebug/index.js +30 -0
- package/dist/gs/internal/godebug/index.js.map +1 -0
- package/dist/gs/io/fs/index.d.ts +1 -0
- package/dist/gs/io/fs/index.js +1 -0
- package/dist/gs/io/fs/index.js.map +1 -1
- package/dist/gs/io/fs/readlink.d.ts +8 -0
- package/dist/gs/io/fs/readlink.js +60 -0
- package/dist/gs/io/fs/readlink.js.map +1 -0
- package/dist/gs/io/fs/walk.d.ts +3 -3
- package/dist/gs/io/fs/walk.js +7 -7
- package/dist/gs/io/fs/walk.js.map +1 -1
- package/dist/gs/io/io.d.ts +40 -6
- package/dist/gs/io/io.js +151 -26
- package/dist/gs/io/io.js.map +1 -1
- package/dist/gs/iter/iter.d.ts +3 -2
- package/dist/gs/iter/iter.js.map +1 -1
- package/dist/gs/maps/iter.d.ts +5 -5
- package/dist/gs/maps/iter.js +48 -21
- package/dist/gs/maps/iter.js.map +1 -1
- package/dist/gs/maps/maps.d.ts +6 -6
- package/dist/gs/maps/maps.js +1 -1
- package/dist/gs/maps/maps.js.map +1 -1
- package/dist/gs/math/bits/index.d.ts +13 -4
- package/dist/gs/math/bits/index.js +70 -48
- package/dist/gs/math/bits/index.js.map +1 -1
- package/dist/gs/math/const.gs.d.ts +5 -5
- package/dist/gs/math/const.gs.js +4 -4
- package/dist/gs/math/const.gs.js.map +1 -1
- package/dist/gs/mime/index.d.ts +1 -0
- package/dist/gs/mime/index.js +52 -0
- package/dist/gs/mime/index.js.map +1 -0
- package/dist/gs/net/http/httptest/index.d.ts +30 -0
- package/dist/gs/net/http/httptest/index.js +101 -0
- package/dist/gs/net/http/httptest/index.js.map +1 -0
- package/dist/gs/net/http/index.d.ts +131 -0
- package/dist/gs/net/http/index.js +307 -0
- package/dist/gs/net/http/index.js.map +1 -0
- package/dist/gs/net/http/pprof/index.d.ts +8 -0
- package/dist/gs/net/http/pprof/index.js +59 -0
- package/dist/gs/net/http/pprof/index.js.map +1 -0
- package/dist/gs/os/dir_unix.gs.js +2 -2
- package/dist/gs/os/dir_unix.gs.js.map +1 -1
- package/dist/gs/os/error.gs.js +9 -7
- package/dist/gs/os/error.gs.js.map +1 -1
- package/dist/gs/os/types_js.gs.js +95 -15
- package/dist/gs/os/types_js.gs.js.map +1 -1
- package/dist/gs/path/filepath/match.js +165 -3
- package/dist/gs/path/filepath/match.js.map +1 -1
- package/dist/gs/path/filepath/path.d.ts +8 -4
- package/dist/gs/path/filepath/path.js +192 -8
- package/dist/gs/path/filepath/path.js.map +1 -1
- package/dist/gs/path/path.d.ts +4 -1
- package/dist/gs/path/path.js +16 -4
- package/dist/gs/path/path.js.map +1 -1
- package/dist/gs/reflect/index.d.ts +4 -3
- package/dist/gs/reflect/index.js +3 -2
- package/dist/gs/reflect/index.js.map +1 -1
- package/dist/gs/reflect/iter.js +2 -2
- package/dist/gs/reflect/iter.js.map +1 -1
- package/dist/gs/reflect/map.js +29 -0
- package/dist/gs/reflect/map.js.map +1 -1
- package/dist/gs/reflect/type.d.ts +31 -9
- package/dist/gs/reflect/type.js +536 -43
- package/dist/gs/reflect/type.js.map +1 -1
- package/dist/gs/reflect/types.d.ts +1 -0
- package/dist/gs/reflect/types.js +3 -1
- package/dist/gs/reflect/types.js.map +1 -1
- package/dist/gs/reflect/value.d.ts +4 -1
- package/dist/gs/reflect/value.js +39 -1
- package/dist/gs/reflect/value.js.map +1 -1
- package/dist/gs/reflect/visiblefields.js +1 -1
- package/dist/gs/reflect/visiblefields.js.map +1 -1
- package/dist/gs/runtime/debug/index.d.ts +41 -0
- package/dist/gs/runtime/debug/index.js +66 -0
- package/dist/gs/runtime/debug/index.js.map +1 -0
- package/dist/gs/runtime/pprof/index.d.ts +20 -0
- package/dist/gs/runtime/pprof/index.js +85 -0
- package/dist/gs/runtime/pprof/index.js.map +1 -0
- package/dist/gs/runtime/runtime.d.ts +35 -3
- package/dist/gs/runtime/runtime.js +72 -0
- package/dist/gs/runtime/runtime.js.map +1 -1
- package/dist/gs/runtime/trace/index.d.ts +19 -0
- package/dist/gs/runtime/trace/index.js +64 -0
- package/dist/gs/runtime/trace/index.js.map +1 -0
- package/dist/gs/slices/slices.d.ts +42 -8
- package/dist/gs/slices/slices.js +425 -11
- package/dist/gs/slices/slices.js.map +1 -1
- package/dist/gs/sort/slice.gs.d.ts +5 -3
- package/dist/gs/sort/slice.gs.js +60 -22
- package/dist/gs/sort/slice.gs.js.map +1 -1
- package/dist/gs/sort/sort.gs.d.ts +4 -4
- package/dist/gs/sort/sort.gs.js +11 -8
- package/dist/gs/sort/sort.gs.js.map +1 -1
- package/dist/gs/strings/builder.d.ts +1 -1
- package/dist/gs/strings/builder.js +29 -19
- package/dist/gs/strings/builder.js.map +1 -1
- package/dist/gs/strings/iter.js +140 -75
- package/dist/gs/strings/iter.js.map +1 -1
- package/dist/gs/strings/replace.js +2 -2
- package/dist/gs/strings/replace.js.map +1 -1
- package/dist/gs/strings/strings.js +52 -6
- package/dist/gs/strings/strings.js.map +1 -1
- package/dist/gs/sync/atomic/type.gs.d.ts +9 -8
- package/dist/gs/sync/atomic/type.gs.js +0 -2
- package/dist/gs/sync/atomic/type.gs.js.map +1 -1
- package/dist/gs/sync/sync.d.ts +8 -3
- package/dist/gs/sync/sync.js +66 -11
- package/dist/gs/sync/sync.js.map +1 -1
- package/dist/gs/syscall/constants.d.ts +36 -24
- package/dist/gs/syscall/constants.js +12 -0
- package/dist/gs/syscall/constants.js.map +1 -1
- package/dist/gs/syscall/errors.d.ts +117 -111
- package/dist/gs/syscall/errors.js +45 -0
- package/dist/gs/syscall/errors.js.map +1 -1
- package/dist/gs/syscall/fs.d.ts +37 -0
- package/dist/gs/syscall/fs.js +102 -0
- package/dist/gs/syscall/fs.js.map +1 -1
- package/dist/gs/syscall/js/index.d.ts +90 -0
- package/dist/gs/syscall/js/index.js +383 -0
- package/dist/gs/syscall/js/index.js.map +1 -0
- package/dist/gs/syscall/types.d.ts +26 -1
- package/dist/gs/syscall/types.js +45 -1
- package/dist/gs/syscall/types.js.map +1 -1
- package/dist/gs/testing/index.d.ts +1 -0
- package/dist/gs/testing/index.js +2 -0
- package/dist/gs/testing/index.js.map +1 -0
- package/dist/gs/testing/testing.d.ts +78 -0
- package/dist/gs/testing/testing.js +318 -0
- package/dist/gs/testing/testing.js.map +1 -0
- package/dist/gs/time/time.d.ts +41 -4
- package/dist/gs/time/time.js +227 -36
- package/dist/gs/time/time.js.map +1 -1
- package/dist/gs/unicode/unicode.d.ts +23 -1
- package/dist/gs/unicode/unicode.js +79 -10
- package/dist/gs/unicode/unicode.js.map +1 -1
- package/dist/gs/unicode/utf8/utf8.d.ts +4 -4
- package/dist/gs/unicode/utf8/utf8.js +24 -11
- package/dist/gs/unicode/utf8/utf8.js.map +1 -1
- package/dist/gs/unique/index.d.ts +11 -0
- package/dist/gs/unique/index.js +76 -0
- package/dist/gs/unique/index.js.map +1 -0
- package/go.mod +8 -8
- package/go.sum +14 -14
- package/gs/builtin/builtin.ts +585 -27
- package/gs/builtin/channel.ts +183 -29
- package/gs/builtin/defer.ts +13 -2
- package/gs/builtin/hostio.test.ts +1 -0
- package/gs/builtin/hostio.ts +38 -0
- package/gs/builtin/map.ts +46 -6
- package/gs/builtin/print.ts +12 -3
- package/gs/builtin/runtime-contract.test.ts +383 -10
- package/gs/builtin/slice.test.ts +70 -0
- package/gs/builtin/slice.ts +785 -265
- package/gs/builtin/type.ts +160 -41
- package/gs/builtin/varRef.ts +40 -1
- package/gs/bytes/buffer.gs.ts +74 -70
- package/gs/bytes/iter.gs.ts +13 -14
- package/gs/bytes/meta.json +8 -3
- package/gs/bytes/reader.gs.ts +20 -19
- package/gs/compress/zlib/index.test.ts +28 -0
- package/gs/compress/zlib/index.ts +200 -0
- package/gs/compress/zlib/meta.json +3 -0
- package/gs/context/context.test.ts +71 -0
- package/gs/context/context.ts +30 -29
- package/gs/crypto/ecdh/index.test.ts +43 -0
- package/gs/crypto/ecdh/index.ts +274 -0
- package/gs/crypto/ed25519/index.test.ts +41 -0
- package/gs/crypto/ed25519/index.ts +238 -0
- package/gs/crypto/ed25519/meta.json +13 -0
- package/gs/crypto/internal/constanttime/index.test.ts +25 -0
- package/gs/crypto/internal/constanttime/index.ts +22 -0
- package/gs/crypto/internal/fips140deps/byteorder/index.ts +1 -0
- package/gs/crypto/internal/fips140deps/godebug/index.ts +1 -0
- package/gs/crypto/rand/index.test.ts +89 -1
- package/gs/crypto/rand/index.ts +103 -1
- package/gs/crypto/rand/meta.json +4 -1
- package/gs/crypto/sha256/index.test.ts +78 -0
- package/gs/crypto/sha256/index.ts +150 -0
- package/gs/crypto/sha256/meta.json +9 -0
- package/gs/crypto/sha512/index.test.ts +31 -0
- package/gs/crypto/sha512/index.ts +161 -0
- package/gs/crypto/sha512/meta.json +11 -0
- package/gs/embed/index.ts +20 -0
- package/gs/embed/meta.json +5 -0
- package/gs/encoding/json/index.test.ts +39 -3
- package/gs/encoding/json/index.ts +45 -3
- package/gs/errors/errors.test.ts +85 -0
- package/gs/errors/errors.ts +132 -4
- package/gs/fmt/fmt.test.ts +3 -1
- package/gs/fmt/fmt.ts +55 -19
- package/gs/github.com/aperturerobotics/protobuf-go-lite/index.test.ts +128 -1
- package/gs/github.com/aperturerobotics/protobuf-go-lite/index.ts +342 -4
- package/gs/github.com/aperturerobotics/protobuf-go-lite/json/index.test.ts +180 -0
- package/gs/github.com/aperturerobotics/protobuf-go-lite/json/index.ts +1084 -0
- package/gs/github.com/aperturerobotics/starpc/srpc/index.test.ts +31 -0
- package/gs/github.com/aperturerobotics/starpc/srpc/index.ts +1233 -0
- package/gs/github.com/aperturerobotics/starpc/srpc/meta.json +46 -0
- package/gs/github.com/aperturerobotics/util/conc/index.test.ts +30 -0
- package/gs/github.com/aperturerobotics/util/conc/index.ts +172 -0
- package/gs/github.com/aperturerobotics/util/conc/meta.json +9 -0
- package/gs/github.com/aperturerobotics/wasivm/wazero/kernel/runtime/browser/browser.ts +1 -4
- package/gs/github.com/hack-pad/safejs/internal/catch/index.test.ts +35 -0
- package/gs/github.com/hack-pad/safejs/internal/catch/index.ts +65 -0
- package/gs/github.com/hack-pad/safejs/internal/catch/meta.json +9 -0
- package/gs/github.com/klauspost/compress/internal/le/index.test.ts +37 -0
- package/gs/github.com/klauspost/compress/internal/le/index.ts +115 -0
- package/gs/github.com/mr-tron/base58/base58/index.test.ts +70 -0
- package/gs/github.com/mr-tron/base58/base58/index.ts +231 -0
- package/gs/github.com/mr-tron/base58/base58/meta.json +3 -0
- package/gs/github.com/zeebo/blake3/internal/consts/index.test.ts +46 -0
- package/gs/github.com/zeebo/blake3/internal/consts/index.ts +26 -0
- package/gs/go/internal/scannerhooks/index.test.ts +14 -0
- package/gs/go/internal/scannerhooks/index.ts +9 -0
- package/gs/go/scanner/index.test.ts +22 -0
- package/gs/go/scanner/index.ts +47 -0
- package/gs/go/token/index.test.ts +47 -1
- package/gs/go/token/index.ts +583 -4
- package/gs/hash/fnv/index.test.ts +67 -0
- package/gs/hash/fnv/index.ts +351 -0
- package/gs/hash/fnv/meta.json +3 -0
- package/gs/hash/index.test.ts +37 -0
- package/gs/hash/index.ts +118 -0
- package/gs/hash/meta.json +5 -0
- package/gs/internal/abi/index.test.ts +18 -0
- package/gs/internal/abi/index.ts +14 -0
- package/gs/internal/bytealg/index.test.ts +18 -0
- package/gs/internal/bytealg/index.ts +16 -0
- package/gs/internal/byteorder/index.test.ts +39 -0
- package/gs/internal/byteorder/index.ts +100 -27
- package/gs/internal/godebug/index.test.ts +16 -0
- package/gs/internal/godebug/index.ts +35 -0
- package/gs/io/fs/index.ts +1 -0
- package/gs/io/fs/meta.json +5 -0
- package/gs/io/fs/readlink.test.ts +43 -0
- package/gs/io/fs/readlink.ts +69 -0
- package/gs/io/fs/walk.test.ts +61 -0
- package/gs/io/fs/walk.ts +17 -9
- package/gs/io/io.ts +177 -31
- package/gs/io/meta.json +10 -2
- package/gs/iter/iter.ts +8 -2
- package/gs/maps/iter.ts +75 -26
- package/gs/maps/maps.test.ts +23 -0
- package/gs/maps/maps.ts +13 -11
- package/gs/math/bits/index.test.ts +20 -0
- package/gs/math/bits/index.ts +107 -64
- package/gs/math/const.gs.test.ts +11 -5
- package/gs/math/const.gs.ts +5 -6
- package/gs/mime/index.ts +60 -0
- package/gs/net/http/httptest/index.test.ts +53 -0
- package/gs/net/http/httptest/index.ts +120 -0
- package/gs/net/http/index.test.ts +148 -0
- package/gs/net/http/index.ts +432 -0
- package/gs/net/http/meta.json +6 -0
- package/gs/net/http/pprof/index.test.ts +47 -0
- package/gs/net/http/pprof/index.ts +65 -0
- package/gs/os/dir_unix.gs.ts +2 -3
- package/gs/os/error.gs.ts +9 -10
- package/gs/os/error.test.ts +41 -0
- package/gs/os/file_unix_js.test.ts +55 -0
- package/gs/os/tempfile.gs.test.ts +37 -10
- package/gs/os/types_js.gs.ts +96 -17
- package/gs/path/filepath/match.test.ts +31 -12
- package/gs/path/filepath/match.ts +181 -3
- package/gs/path/filepath/meta.json +6 -0
- package/gs/path/filepath/path.test.ts +80 -0
- package/gs/path/filepath/path.ts +244 -11
- package/gs/path/path.ts +20 -5
- package/gs/reflect/field.test.ts +63 -0
- package/gs/reflect/index.ts +5 -1
- package/gs/reflect/iter.ts +2 -2
- package/gs/reflect/map.test.ts +42 -1
- package/gs/reflect/map.ts +39 -0
- package/gs/reflect/type.ts +728 -65
- package/gs/reflect/typefor.test.ts +100 -0
- package/gs/reflect/types.ts +3 -1
- package/gs/reflect/value.ts +50 -1
- package/gs/reflect/visiblefields.ts +1 -1
- package/gs/runtime/debug/index.test.ts +45 -0
- package/gs/runtime/debug/index.ts +96 -0
- package/gs/runtime/pprof/index.test.ts +36 -0
- package/gs/runtime/pprof/index.ts +104 -0
- package/gs/runtime/pprof/meta.json +6 -0
- package/gs/runtime/runtime.test.ts +19 -0
- package/gs/runtime/runtime.ts +98 -3
- package/gs/runtime/trace/index.test.ts +45 -0
- package/gs/runtime/trace/index.ts +97 -0
- package/gs/runtime/trace/meta.json +7 -0
- package/gs/slices/meta.json +2 -1
- package/gs/slices/slices.test.ts +180 -0
- package/gs/slices/slices.ts +502 -15
- package/gs/sort/meta.json +7 -0
- package/gs/sort/slice.gs.ts +85 -26
- package/gs/sort/slice.test.ts +40 -0
- package/gs/sort/sort.gs.ts +16 -13
- package/gs/strings/builder.test.ts +8 -0
- package/gs/strings/builder.ts +33 -20
- package/gs/strings/iter.test.ts +5 -7
- package/gs/strings/iter.ts +146 -71
- package/gs/strings/replace.test.ts +1 -4
- package/gs/strings/replace.ts +6 -6
- package/gs/strings/strings.test.ts +4 -0
- package/gs/strings/strings.ts +54 -6
- package/gs/sync/atomic/type.gs.ts +13 -14
- package/gs/sync/meta.json +3 -1
- package/gs/sync/sync.test.ts +69 -1
- package/gs/sync/sync.ts +72 -13
- package/gs/syscall/constants.ts +39 -24
- package/gs/syscall/errors.ts +165 -112
- package/gs/syscall/fs.ts +195 -0
- package/gs/syscall/js/index.ts +485 -0
- package/gs/syscall/js/meta.json +4 -0
- package/gs/syscall/net.test.ts +111 -0
- package/gs/syscall/types.ts +63 -2
- package/gs/testing/index.ts +1 -0
- package/gs/testing/meta.json +5 -0
- package/gs/testing/testing.test.ts +146 -0
- package/gs/testing/testing.ts +399 -0
- package/gs/time/meta.json +2 -2
- package/gs/time/time.test.ts +110 -0
- package/gs/time/time.ts +309 -57
- package/gs/unicode/unicode.test.ts +36 -0
- package/gs/unicode/unicode.ts +115 -9
- package/gs/unicode/utf8/utf8.test.ts +13 -0
- package/gs/unicode/utf8/utf8.ts +28 -16
- package/gs/unique/index.ts +98 -0
- package/package.json +3 -2
|
@@ -1,12 +1,29 @@
|
|
|
1
1
|
import { describe, it, expect } from 'vitest'
|
|
2
2
|
import {
|
|
3
|
+
makeMap,
|
|
4
|
+
mapGet,
|
|
5
|
+
mapSet,
|
|
3
6
|
TypeKind,
|
|
4
7
|
registerInterfaceType,
|
|
5
8
|
registerStructType,
|
|
6
9
|
} from '../builtin/index.js'
|
|
10
|
+
import { StructField } from './types.js'
|
|
7
11
|
import { Int, Struct, TypeFor } from './type.js'
|
|
8
12
|
|
|
9
13
|
describe('TypeFor', () => {
|
|
14
|
+
it('exposes StructField PkgPath and exported semantics', () => {
|
|
15
|
+
const exported = new StructField({ Name: 'Field' })
|
|
16
|
+
const unexported = new StructField({
|
|
17
|
+
Name: 'field',
|
|
18
|
+
PkgPath: 'example.test/pkg',
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
expect(exported.PkgPath).toBe('')
|
|
22
|
+
expect(exported.IsExported()).toBe(true)
|
|
23
|
+
expect(unexported.IsExported()).toBe(false)
|
|
24
|
+
expect(unexported.clone().PkgPath).toBe('example.test/pkg')
|
|
25
|
+
})
|
|
26
|
+
|
|
10
27
|
it('uses generic runtime type descriptors', () => {
|
|
11
28
|
const intType = TypeFor({
|
|
12
29
|
T: {
|
|
@@ -17,6 +34,18 @@ describe('TypeFor', () => {
|
|
|
17
34
|
|
|
18
35
|
expect(intType.String()).toBe('int')
|
|
19
36
|
expect(intType.Kind()).toBe(Int)
|
|
37
|
+
expect(intType.PkgPath()).toBe('')
|
|
38
|
+
|
|
39
|
+
const namedIntType = TypeFor({
|
|
40
|
+
T: {
|
|
41
|
+
type: { kind: TypeKind.Basic, name: 'int', typeName: 'gob.typeId' },
|
|
42
|
+
zero: () => 0,
|
|
43
|
+
},
|
|
44
|
+
})
|
|
45
|
+
expect(namedIntType.String()).toBe('gob.typeId')
|
|
46
|
+
expect(namedIntType.Name()).toBe('typeId')
|
|
47
|
+
expect(namedIntType.PkgPath()).toBe('gob')
|
|
48
|
+
expect(namedIntType.Kind()).toBe(Int)
|
|
20
49
|
})
|
|
21
50
|
|
|
22
51
|
it('formats literal interface methods from type metadata', () => {
|
|
@@ -50,6 +79,7 @@ describe('TypeFor', () => {
|
|
|
50
79
|
|
|
51
80
|
it('resolves registered type names from descriptors', () => {
|
|
52
81
|
class RegisteredStruct {}
|
|
82
|
+
class RegisteredWithFields {}
|
|
53
83
|
registerStructType(
|
|
54
84
|
'main.RegisteredStruct',
|
|
55
85
|
new RegisteredStruct(),
|
|
@@ -57,6 +87,24 @@ describe('TypeFor', () => {
|
|
|
57
87
|
RegisteredStruct,
|
|
58
88
|
{},
|
|
59
89
|
)
|
|
90
|
+
registerStructType(
|
|
91
|
+
'main.RegisteredWithFields',
|
|
92
|
+
new RegisteredWithFields(),
|
|
93
|
+
[],
|
|
94
|
+
RegisteredWithFields,
|
|
95
|
+
{
|
|
96
|
+
Name: { kind: TypeKind.Basic, name: 'string' },
|
|
97
|
+
Count: {
|
|
98
|
+
name: 'Total',
|
|
99
|
+
type: { kind: TypeKind.Basic, name: 'int' },
|
|
100
|
+
tag: 'json:"total"',
|
|
101
|
+
},
|
|
102
|
+
Items: {
|
|
103
|
+
kind: TypeKind.Slice,
|
|
104
|
+
elemType: 'main.RegisteredStruct',
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
)
|
|
60
108
|
registerInterfaceType('main.RegisteredInterface', null, [
|
|
61
109
|
{ name: 'SomeMethod', args: [], returns: [] },
|
|
62
110
|
])
|
|
@@ -71,5 +119,57 @@ describe('TypeFor', () => {
|
|
|
71
119
|
expect(structType.String()).toBe('main.RegisteredStruct')
|
|
72
120
|
expect(structType.Kind()).toBe(Struct)
|
|
73
121
|
expect(ifaceType.String()).toBe('interface { SomeMethod() }')
|
|
122
|
+
|
|
123
|
+
const fieldsType = TypeFor({
|
|
124
|
+
T: {
|
|
125
|
+
type: 'main.RegisteredWithFields',
|
|
126
|
+
zero: () => new RegisteredWithFields(),
|
|
127
|
+
},
|
|
128
|
+
})
|
|
129
|
+
expect(fieldsType.NumField()).toBe(3)
|
|
130
|
+
expect(fieldsType.Field(0).Name).toBe('Name')
|
|
131
|
+
expect(fieldsType.Field(0).Type.String()).toBe('string')
|
|
132
|
+
expect(fieldsType.Field(1).Name).toBe('Total')
|
|
133
|
+
expect(fieldsType.Field(1).Tag.Get('json')).toBe('total')
|
|
134
|
+
expect(fieldsType.Field(2).Type.String()).toBe('[]main.RegisteredStruct')
|
|
135
|
+
expect(fieldsType.Field(2).Type.Elem().String()).toBe('main.RegisteredStruct')
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
it('interns runtime type descriptors for reflect.Type map keys', () => {
|
|
139
|
+
const first = TypeFor({
|
|
140
|
+
T: { type: 'gob.wireType', zero: () => ({}) },
|
|
141
|
+
})
|
|
142
|
+
const second = TypeFor({
|
|
143
|
+
T: { type: 'gob.wireType', zero: () => ({}) },
|
|
144
|
+
})
|
|
145
|
+
const arrayType = TypeFor({
|
|
146
|
+
T: {
|
|
147
|
+
type: {
|
|
148
|
+
kind: TypeKind.Array,
|
|
149
|
+
elemType: { kind: TypeKind.Basic, name: 'uint8' },
|
|
150
|
+
length: 16,
|
|
151
|
+
},
|
|
152
|
+
zero: () => new Uint8Array(16),
|
|
153
|
+
},
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
expect(second).toBe(first)
|
|
157
|
+
expect(arrayType).toBe(
|
|
158
|
+
TypeFor({
|
|
159
|
+
T: {
|
|
160
|
+
type: {
|
|
161
|
+
kind: TypeKind.Array,
|
|
162
|
+
elemType: { kind: TypeKind.Basic, name: 'uint8' },
|
|
163
|
+
length: 16,
|
|
164
|
+
},
|
|
165
|
+
zero: () => new Uint8Array(16),
|
|
166
|
+
},
|
|
167
|
+
}),
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
const m = makeMap<typeof first, string>()
|
|
171
|
+
mapSet(m, first, 'wire')
|
|
172
|
+
|
|
173
|
+
expect(mapGet(m, second, '')).toEqual(['wire', true])
|
|
74
174
|
})
|
|
75
175
|
})
|
package/gs/reflect/types.ts
CHANGED
|
@@ -40,6 +40,7 @@ import { Type, Kind, Value, Kind_String, ChanDir } from './type.js'
|
|
|
40
40
|
// Struct field representation
|
|
41
41
|
export class StructField {
|
|
42
42
|
public Name: string = ''
|
|
43
|
+
public PkgPath: string = ''
|
|
43
44
|
public Type!: Type
|
|
44
45
|
public Tag: StructTag = new StructTag('')
|
|
45
46
|
public Offset: uintptr = 0
|
|
@@ -55,6 +56,7 @@ export class StructField {
|
|
|
55
56
|
public clone(): StructField {
|
|
56
57
|
return new StructField({
|
|
57
58
|
Name: this.Name,
|
|
59
|
+
PkgPath: this.PkgPath,
|
|
58
60
|
Type: this.Type,
|
|
59
61
|
Tag: this.Tag,
|
|
60
62
|
Offset: this.Offset,
|
|
@@ -64,7 +66,7 @@ export class StructField {
|
|
|
64
66
|
}
|
|
65
67
|
|
|
66
68
|
public IsExported(): boolean {
|
|
67
|
-
return this.
|
|
69
|
+
return this.PkgPath === ''
|
|
68
70
|
}
|
|
69
71
|
}
|
|
70
72
|
|
package/gs/reflect/value.ts
CHANGED
|
@@ -26,7 +26,13 @@ import {
|
|
|
26
26
|
BasicType,
|
|
27
27
|
Invalid,
|
|
28
28
|
} from './type.js'
|
|
29
|
-
import {
|
|
29
|
+
import {
|
|
30
|
+
Pointer,
|
|
31
|
+
ReflectValue,
|
|
32
|
+
SelectCase,
|
|
33
|
+
SelectRecv,
|
|
34
|
+
SelectDefault,
|
|
35
|
+
} from './types.js'
|
|
30
36
|
|
|
31
37
|
interface ChannelObject {
|
|
32
38
|
_sendQueue?: unknown[]
|
|
@@ -142,6 +148,33 @@ export function New(typ: Type | null): Value {
|
|
|
142
148
|
return new Value(null, ptrType) // null represents the pointer value
|
|
143
149
|
}
|
|
144
150
|
|
|
151
|
+
// NewAt returns a Value representing a pointer to the value at p.
|
|
152
|
+
export function NewAt(typ: Type | null, p: Pointer | unknown): Value {
|
|
153
|
+
if (typ === null) {
|
|
154
|
+
return new Value()
|
|
155
|
+
}
|
|
156
|
+
const ptrType = PointerTo(typ)
|
|
157
|
+
if (
|
|
158
|
+
p &&
|
|
159
|
+
typeof p === 'object' &&
|
|
160
|
+
'value' in p &&
|
|
161
|
+
(p as { value?: unknown }).value instanceof Value
|
|
162
|
+
) {
|
|
163
|
+
const target = (p as { value: Value }).value
|
|
164
|
+
const ref: $.VarRef<ReflectValue> = {
|
|
165
|
+
get value(): ReflectValue {
|
|
166
|
+
return target.Interface() as ReflectValue
|
|
167
|
+
},
|
|
168
|
+
set value(value: ReflectValue) {
|
|
169
|
+
target.Set(new Value(value, typ))
|
|
170
|
+
},
|
|
171
|
+
__isVarRef: true,
|
|
172
|
+
}
|
|
173
|
+
return new Value(ref, ptrType)
|
|
174
|
+
}
|
|
175
|
+
return new Value($.unsupportedPointerRef<ReflectValue>(p), ptrType)
|
|
176
|
+
}
|
|
177
|
+
|
|
145
178
|
// MakeSlice returns a Value representing a new slice with the specified type, length, and capacity.
|
|
146
179
|
export function MakeSlice(typ: Type | null, len: number, _cap: number): Value {
|
|
147
180
|
if (typ === null || typ.Kind() !== Slice) {
|
|
@@ -171,6 +204,10 @@ export function MakeMap(typ: Type | null): Value {
|
|
|
171
204
|
return new Value(map, typ)
|
|
172
205
|
}
|
|
173
206
|
|
|
207
|
+
export function MakeMapWithSize(typ: Type | null, _n: number): Value {
|
|
208
|
+
return MakeMap(typ)
|
|
209
|
+
}
|
|
210
|
+
|
|
174
211
|
// Append appends the values x to a slice and returns the resulting slice.
|
|
175
212
|
export function Append(s: Value, x: Value): Value {
|
|
176
213
|
if (s.Kind() !== Slice) {
|
|
@@ -188,6 +225,18 @@ export function Append(s: Value, x: Value): Value {
|
|
|
188
225
|
return new Value(newArray, s.Type())
|
|
189
226
|
}
|
|
190
227
|
|
|
228
|
+
export function AppendSlice(s: Value, t: Value): Value {
|
|
229
|
+
if (s.Kind() !== Slice || t.Kind() !== Slice) {
|
|
230
|
+
throw new Error('reflect.AppendSlice of non-slice')
|
|
231
|
+
}
|
|
232
|
+
const left = getArrayFromValue(s)
|
|
233
|
+
const right = getArrayFromValue(t)
|
|
234
|
+
if (!left || !right) {
|
|
235
|
+
throw new Error('cannot get array from slice value')
|
|
236
|
+
}
|
|
237
|
+
return new Value([...left, ...right], s.Type())
|
|
238
|
+
}
|
|
239
|
+
|
|
191
240
|
// MakeChan returns a Value representing a new channel with the specified type.
|
|
192
241
|
export function MakeChan(typ: Type, buffer: number): Value {
|
|
193
242
|
if (typ.Kind() !== Chan) {
|
|
@@ -131,7 +131,7 @@ class visibleFieldsWalker {
|
|
|
131
131
|
const field = t!.Field(i)
|
|
132
132
|
if (field) {
|
|
133
133
|
const f = field.clone()
|
|
134
|
-
f.Index = $.append(null, w.index) as number[]
|
|
134
|
+
f.Index = $.append(null, ...(w.index ?? [])) as number[]
|
|
135
135
|
if (f.Anonymous) {
|
|
136
136
|
if (f.Type && f.Type.Kind() === Ptr) {
|
|
137
137
|
const elemType = f.Type.Elem!()
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest'
|
|
2
|
+
|
|
3
|
+
import { BuildInfo, BuildSetting, Module, PrintStack, ReadBuildInfo, Stack } from './index.js'
|
|
4
|
+
|
|
5
|
+
describe('runtime/debug override', () => {
|
|
6
|
+
it('returns a stack trace as bytes', () => {
|
|
7
|
+
const stack = Stack()
|
|
8
|
+
|
|
9
|
+
expect(stack).toBeInstanceOf(Uint8Array)
|
|
10
|
+
expect(new TextDecoder().decode(stack)).toContain('Error')
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
it('prints the current stack trace', () => {
|
|
14
|
+
const consoleError = vi.spyOn(console, 'error').mockImplementation(() => {})
|
|
15
|
+
|
|
16
|
+
try {
|
|
17
|
+
PrintStack()
|
|
18
|
+
expect(consoleError).toHaveBeenCalledTimes(1)
|
|
19
|
+
expect(consoleError.mock.calls[0][0]).toContain('Error')
|
|
20
|
+
} finally {
|
|
21
|
+
consoleError.mockRestore()
|
|
22
|
+
}
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
it('exposes build info structs and reports no embedded module table', () => {
|
|
26
|
+
const module = new Module({
|
|
27
|
+
Path: 'example.test/module',
|
|
28
|
+
Version: 'v1.2.3',
|
|
29
|
+
Sum: 'h1:sum',
|
|
30
|
+
Replace: new Module({ Path: '../module' }),
|
|
31
|
+
})
|
|
32
|
+
const info = new BuildInfo({
|
|
33
|
+
GoVersion: 'go1.26.3',
|
|
34
|
+
Path: 'example.test/main',
|
|
35
|
+
Main: module,
|
|
36
|
+
Deps: [module],
|
|
37
|
+
Settings: [new BuildSetting({ Key: 'GOOS', Value: 'js' })],
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
expect(info.Main.Path).toBe('example.test/module')
|
|
41
|
+
expect(info.Deps?.[0]).toBe(module)
|
|
42
|
+
expect(info.Settings?.[0]?.Value).toBe('js')
|
|
43
|
+
expect(ReadBuildInfo()).toEqual([null, false])
|
|
44
|
+
})
|
|
45
|
+
})
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import * as $ from '@goscript/builtin/index.js'
|
|
2
|
+
|
|
3
|
+
export class BuildSetting {
|
|
4
|
+
public Key: string
|
|
5
|
+
public Value: string
|
|
6
|
+
|
|
7
|
+
constructor(init?: Partial<{ Key: string; Value: string }>) {
|
|
8
|
+
this.Key = init?.Key ?? ''
|
|
9
|
+
this.Value = init?.Value ?? ''
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
public clone(): BuildSetting {
|
|
13
|
+
return $.markAsStructValue(new BuildSetting({ Key: this.Key, Value: this.Value }))
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export class Module {
|
|
18
|
+
public Path: string
|
|
19
|
+
public Version: string
|
|
20
|
+
public Sum: string
|
|
21
|
+
public Replace: Module | $.VarRef<Module> | null
|
|
22
|
+
|
|
23
|
+
constructor(
|
|
24
|
+
init?: Partial<{
|
|
25
|
+
Path: string
|
|
26
|
+
Version: string
|
|
27
|
+
Sum: string
|
|
28
|
+
Replace: Module | $.VarRef<Module> | null
|
|
29
|
+
}>,
|
|
30
|
+
) {
|
|
31
|
+
this.Path = init?.Path ?? ''
|
|
32
|
+
this.Version = init?.Version ?? ''
|
|
33
|
+
this.Sum = init?.Sum ?? ''
|
|
34
|
+
this.Replace = init?.Replace ?? null
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public clone(): Module {
|
|
38
|
+
return $.markAsStructValue(
|
|
39
|
+
new Module({
|
|
40
|
+
Path: this.Path,
|
|
41
|
+
Version: this.Version,
|
|
42
|
+
Sum: this.Sum,
|
|
43
|
+
Replace: this.Replace,
|
|
44
|
+
}),
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export class BuildInfo {
|
|
50
|
+
public GoVersion: string
|
|
51
|
+
public Path: string
|
|
52
|
+
public Main: Module
|
|
53
|
+
public Deps: $.Slice<Module | $.VarRef<Module> | null>
|
|
54
|
+
public Settings: $.Slice<BuildSetting>
|
|
55
|
+
|
|
56
|
+
constructor(
|
|
57
|
+
init?: Partial<{
|
|
58
|
+
GoVersion: string
|
|
59
|
+
Path: string
|
|
60
|
+
Main: Module
|
|
61
|
+
Deps: $.Slice<Module | $.VarRef<Module> | null>
|
|
62
|
+
Settings: $.Slice<BuildSetting>
|
|
63
|
+
}>,
|
|
64
|
+
) {
|
|
65
|
+
this.GoVersion = init?.GoVersion ?? ''
|
|
66
|
+
this.Path = init?.Path ?? ''
|
|
67
|
+
this.Main = init?.Main ?? new Module()
|
|
68
|
+
this.Deps = init?.Deps ?? null
|
|
69
|
+
this.Settings = init?.Settings ?? null
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
public clone(): BuildInfo {
|
|
73
|
+
return $.markAsStructValue(
|
|
74
|
+
new BuildInfo({
|
|
75
|
+
GoVersion: this.GoVersion,
|
|
76
|
+
Path: this.Path,
|
|
77
|
+
Main: this.Main.clone(),
|
|
78
|
+
Deps: this.Deps,
|
|
79
|
+
Settings: this.Settings,
|
|
80
|
+
}),
|
|
81
|
+
)
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function Stack(): Uint8Array {
|
|
86
|
+
const stack = new Error().stack ?? 'stack trace unavailable'
|
|
87
|
+
return new TextEncoder().encode(stack)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function PrintStack(): void {
|
|
91
|
+
console.error(new TextDecoder().decode(Stack()))
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function ReadBuildInfo(): [BuildInfo | null, boolean] {
|
|
95
|
+
return [null, false]
|
|
96
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
|
|
3
|
+
import { Lookup, StartCPUProfile, StopCPUProfile } from './index.js'
|
|
4
|
+
|
|
5
|
+
describe('runtime/pprof override', () => {
|
|
6
|
+
it('writes deterministic CPU profile bytes', () => {
|
|
7
|
+
const chunks: Uint8Array[] = []
|
|
8
|
+
const writer = {
|
|
9
|
+
Write(p: Uint8Array): [number, null] {
|
|
10
|
+
chunks.push(new Uint8Array(p))
|
|
11
|
+
return [p.length, null]
|
|
12
|
+
},
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
expect(StartCPUProfile(writer)).toBeNull()
|
|
16
|
+
StopCPUProfile()
|
|
17
|
+
|
|
18
|
+
expect(chunks.reduce((total, chunk) => total + chunk.length, 0)).toBeGreaterThan(0)
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
it('writes deterministic memory profile bytes', () => {
|
|
22
|
+
const chunks: Uint8Array[] = []
|
|
23
|
+
const writer = {
|
|
24
|
+
Write(p: Uint8Array): [number, null] {
|
|
25
|
+
chunks.push(new Uint8Array(p))
|
|
26
|
+
return [p.length, null]
|
|
27
|
+
},
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const profile = Lookup('allocs')
|
|
31
|
+
|
|
32
|
+
expect(profile).not.toBeNull()
|
|
33
|
+
expect(profile!.WriteTo(writer, 0)).toBeNull()
|
|
34
|
+
expect(chunks.reduce((total, chunk) => total + chunk.length, 0)).toBeGreaterThan(0)
|
|
35
|
+
})
|
|
36
|
+
})
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import * as $ from '@goscript/builtin/index.js'
|
|
2
|
+
import * as errors from '@goscript/errors/index.js'
|
|
3
|
+
import * as io from '@goscript/io/index.js'
|
|
4
|
+
|
|
5
|
+
type WriterArg = io.Writer | $.VarRef<io.Writer> | null | undefined
|
|
6
|
+
|
|
7
|
+
let activeCPUWriter: io.Writer | null = null
|
|
8
|
+
|
|
9
|
+
export class Profile {
|
|
10
|
+
public name: string
|
|
11
|
+
|
|
12
|
+
constructor(name = '') {
|
|
13
|
+
this.name = name
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
public Name(): string {
|
|
17
|
+
return this.name
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public Count(): number {
|
|
21
|
+
return this.name === '' ? 0 : 1
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public WriteTo(w: WriterArg, debug: number): $.GoError {
|
|
25
|
+
return writeProfile(w, `goscript pprof ${this.name} debug=${debug}\n`)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function Lookup(name: string): Profile | null {
|
|
30
|
+
switch (name) {
|
|
31
|
+
case 'heap':
|
|
32
|
+
case 'allocs':
|
|
33
|
+
case 'goroutine':
|
|
34
|
+
case 'threadcreate':
|
|
35
|
+
case 'block':
|
|
36
|
+
case 'mutex':
|
|
37
|
+
return new Profile(name)
|
|
38
|
+
default:
|
|
39
|
+
return null
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function Profiles(): $.Slice<Profile | null> {
|
|
44
|
+
return $.arrayToSlice([
|
|
45
|
+
new Profile('allocs'),
|
|
46
|
+
new Profile('block'),
|
|
47
|
+
new Profile('goroutine'),
|
|
48
|
+
new Profile('heap'),
|
|
49
|
+
new Profile('mutex'),
|
|
50
|
+
new Profile('threadcreate'),
|
|
51
|
+
])
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function StartCPUProfile(w: WriterArg): $.GoError {
|
|
55
|
+
const writer = writerFromArg(w)
|
|
56
|
+
if (writer == null) {
|
|
57
|
+
return errors.New('runtime/pprof: nil profile writer')
|
|
58
|
+
}
|
|
59
|
+
if (activeCPUWriter != null) {
|
|
60
|
+
return errors.New('runtime/pprof: CPU profiling already active')
|
|
61
|
+
}
|
|
62
|
+
activeCPUWriter = writer
|
|
63
|
+
return writeProfile(writer, 'goscript cpu profile start\n')
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function StopCPUProfile(): void {
|
|
67
|
+
if (activeCPUWriter != null) {
|
|
68
|
+
writeProfile(activeCPUWriter, 'goscript cpu profile stop\n')
|
|
69
|
+
activeCPUWriter = null
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function SetGoroutineLabels(_ctx: unknown): void {}
|
|
74
|
+
|
|
75
|
+
export function Do(_ctx: unknown, _labels: unknown, fn: (() => void) | null): void {
|
|
76
|
+
fn?.()
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function ForLabels(_ctx: unknown, _f: unknown): void {}
|
|
80
|
+
|
|
81
|
+
export function WithLabels(ctx: unknown, _labels: unknown): unknown {
|
|
82
|
+
return ctx
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function Labels(...args: string[]): Map<string, string> {
|
|
86
|
+
const labels = new Map<string, string>()
|
|
87
|
+
for (let i = 0; i + 1 < args.length; i += 2) {
|
|
88
|
+
labels.set(args[i], args[i + 1])
|
|
89
|
+
}
|
|
90
|
+
return labels
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function writerFromArg(w: WriterArg): io.Writer | null {
|
|
94
|
+
return $.pointerValueOrNil(w)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function writeProfile(w: WriterArg, text: string): $.GoError {
|
|
98
|
+
const writer = writerFromArg(w)
|
|
99
|
+
if (writer == null) {
|
|
100
|
+
return errors.New('runtime/pprof: nil profile writer')
|
|
101
|
+
}
|
|
102
|
+
const [, err] = writer.Write($.stringToBytes(text))
|
|
103
|
+
return err
|
|
104
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
Compiler,
|
|
5
|
+
FuncForPC,
|
|
6
|
+
ReadTrace,
|
|
7
|
+
StartTrace,
|
|
8
|
+
StopTrace,
|
|
9
|
+
} from './runtime.js'
|
|
10
|
+
|
|
11
|
+
describe('runtime override', () => {
|
|
12
|
+
it('exposes stack and trace compatibility helpers', () => {
|
|
13
|
+
expect(Compiler).toBe('gc')
|
|
14
|
+
expect(FuncForPC(0)).toBeNull()
|
|
15
|
+
expect(StartTrace()).toBeNull()
|
|
16
|
+
expect(ReadTrace()).toBeNull()
|
|
17
|
+
expect(() => StopTrace()).not.toThrow()
|
|
18
|
+
})
|
|
19
|
+
})
|
package/gs/runtime/runtime.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import * as $ from '@goscript/builtin/index.js'
|
|
2
|
+
|
|
1
3
|
// Runtime constants for the JavaScript/WebAssembly target
|
|
2
|
-
export const GOOS = 'js'
|
|
3
|
-
export const GOARCH = 'wasm'
|
|
4
|
+
export const GOOS: string = 'js'
|
|
5
|
+
export const GOARCH: string = 'wasm'
|
|
6
|
+
export const Compiler: string = 'gc'
|
|
4
7
|
|
|
5
8
|
// Version returns the Go version as a string
|
|
6
|
-
export const GOVERSION = 'go1.25.3'
|
|
9
|
+
export const GOVERSION: string = 'go1.25.3'
|
|
7
10
|
export function Version(): string {
|
|
8
11
|
return GOVERSION
|
|
9
12
|
}
|
|
@@ -79,6 +82,79 @@ export function Caller(_skip: number): [number, string, number, boolean] {
|
|
|
79
82
|
return [pc, file, line, ok]
|
|
80
83
|
}
|
|
81
84
|
|
|
85
|
+
// Func represents metadata for a function in a stack frame.
|
|
86
|
+
export class Func {
|
|
87
|
+
public Entry(): number {
|
|
88
|
+
return 0
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
public FileLine(_pc: number): [string, number] {
|
|
92
|
+
return ['', 0]
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
public Name(): string {
|
|
96
|
+
return ''
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// FuncForPC returns function metadata for a program counter.
|
|
101
|
+
export function FuncForPC(_pc: number): Func | null {
|
|
102
|
+
return null
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// StartTrace enables execution tracing.
|
|
106
|
+
export function StartTrace(): $.GoError {
|
|
107
|
+
return null
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// StopTrace stops execution tracing.
|
|
111
|
+
export function StopTrace(): void {}
|
|
112
|
+
|
|
113
|
+
// ReadTrace returns the next execution trace chunk.
|
|
114
|
+
export function ReadTrace(): $.Slice<number> {
|
|
115
|
+
return null
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Frame represents a single call frame.
|
|
119
|
+
export class Frame {
|
|
120
|
+
public PC = 0
|
|
121
|
+
public Func: Func | null = null
|
|
122
|
+
public Function = ''
|
|
123
|
+
public File = ''
|
|
124
|
+
public Line = 0
|
|
125
|
+
public Entry = 0
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Frames iterates over call frames.
|
|
129
|
+
export class Frames {
|
|
130
|
+
private readonly frames: Frame[]
|
|
131
|
+
private index = 0
|
|
132
|
+
|
|
133
|
+
constructor(frames: Frame[] = []) {
|
|
134
|
+
this.frames = frames
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
public Next(): [Frame, boolean] {
|
|
138
|
+
if (this.index >= this.frames.length) {
|
|
139
|
+
return [new Frame(), false]
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const frame = this.frames[this.index]
|
|
143
|
+
this.index++
|
|
144
|
+
return [frame, this.index < this.frames.length]
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// Callers fills pc with return program counters from the current stack.
|
|
149
|
+
export function Callers(_skip: number, _pc: $.Slice<number>): number {
|
|
150
|
+
return 0
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// CallersFrames returns an iterator over call frames for pcs.
|
|
154
|
+
export function CallersFrames(_callers: $.Slice<number>): Frames {
|
|
155
|
+
return new Frames()
|
|
156
|
+
}
|
|
157
|
+
|
|
82
158
|
// Stack returns a formatted stack trace of the calling goroutine.
|
|
83
159
|
// In JavaScript, we use Error.stack
|
|
84
160
|
export function Stack(): Uint8Array {
|
|
@@ -167,6 +243,25 @@ export function SetFinalizer(
|
|
|
167
243
|
)
|
|
168
244
|
}
|
|
169
245
|
|
|
246
|
+
// Cleanup is a handle to a cleanup call for a specific object.
|
|
247
|
+
export class Cleanup {
|
|
248
|
+
public Stop(): void {}
|
|
249
|
+
|
|
250
|
+
public clone(): Cleanup {
|
|
251
|
+
return new Cleanup()
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// AddCleanup registers cleanup to run when ptr is no longer reachable.
|
|
256
|
+
export function AddCleanup<T, S>(
|
|
257
|
+
_ptr: T,
|
|
258
|
+
_cleanup: (arg: S) => void | Promise<void>,
|
|
259
|
+
_arg: S,
|
|
260
|
+
): Cleanup {
|
|
261
|
+
// JavaScript runtimes do not provide Go's cleanup scheduling contract here.
|
|
262
|
+
return new Cleanup()
|
|
263
|
+
}
|
|
264
|
+
|
|
170
265
|
// KeepAlive keeps obj reachable until the point where KeepAlive is called
|
|
171
266
|
export function KeepAlive(obj: any): void {
|
|
172
267
|
// In JavaScript, just accessing the object keeps it alive for this call
|