goscript 0.1.0 → 0.1.1
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 +193 -0
- package/cmd/goscript/cmd-test_test.go +76 -0
- package/cmd/goscript/main.go +1 -0
- package/compiler/build-flags.go +38 -0
- package/compiler/compile-request.go +2 -0
- package/compiler/compliance_test.go +0 -8
- package/compiler/gotest/owner.go +24 -0
- package/compiler/gotest/package-result.go +67 -0
- package/compiler/gotest/request.go +145 -0
- package/compiler/gotest/result.go +28 -0
- package/compiler/gotest/runner.go +588 -0
- package/compiler/gotest/runner_test.go +627 -0
- package/compiler/gotest/test.go +9 -0
- package/compiler/index.test.ts +1 -1
- package/compiler/lowered-program.go +71 -19
- package/compiler/lowering.go +5065 -569
- package/compiler/override-facts.go +307 -0
- package/compiler/override-registry.go +50 -189
- package/compiler/override-registry_test.go +47 -0
- package/compiler/package-graph.go +50 -27
- package/compiler/package-graph_test.go +37 -2
- package/compiler/package-test-function.go +9 -0
- package/compiler/package-test-graph-package.go +40 -0
- package/compiler/package-test-graph-variant.go +105 -0
- package/compiler/package-test-graph.go +117 -0
- package/compiler/package-test-graph_test.go +144 -0
- package/compiler/runtime-contract.go +189 -29
- package/compiler/runtime-contract_test.go +44 -30
- package/compiler/semantic-model-types.go +9 -6
- package/compiler/semantic-model.go +538 -38
- package/compiler/semantic-model_test.go +55 -0
- package/compiler/service.go +1 -1
- package/compiler/skeleton_test.go +679 -49
- package/compiler/tsworkspace/owner.go +334 -0
- package/compiler/tsworkspace/owner_test.go +93 -0
- package/compiler/tsworkspace/result.go +17 -0
- package/compiler/typescript-emitter.go +459 -82
- 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 +20 -2
- package/dist/gs/builtin/builtin.js +194 -6
- package/dist/gs/builtin/builtin.js.map +1 -1
- package/dist/gs/builtin/channel.d.ts +8 -0
- package/dist/gs/builtin/channel.js +12 -0
- package/dist/gs/builtin/channel.js.map +1 -1
- package/dist/gs/builtin/slice.d.ts +22 -2
- package/dist/gs/builtin/slice.js +216 -44
- package/dist/gs/builtin/slice.js.map +1 -1
- package/dist/gs/builtin/type.d.ts +5 -2
- package/dist/gs/builtin/type.js +83 -24
- package/dist/gs/builtin/type.js.map +1 -1
- package/dist/gs/builtin/varRef.d.ts +5 -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 +48 -44
- package/dist/gs/bytes/buffer.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/context/context.d.ts +5 -4
- package/dist/gs/context/context.js +10 -10
- package/dist/gs/context/context.js.map +1 -1
- 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/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 +1 -0
- package/dist/gs/encoding/json/index.js +18 -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 +81 -0
- 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 +35 -0
- package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/index.js +211 -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 +825 -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 +163 -0
- package/dist/gs/github.com/aperturerobotics/starpc/srpc/index.js +449 -0
- package/dist/gs/github.com/aperturerobotics/starpc/srpc/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 +71 -0
- package/dist/gs/github.com/klauspost/compress/internal/le/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 +500 -4
- package/dist/gs/go/token/index.js.map +1 -1
- 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 +64 -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/maps/iter.d.ts +3 -3
- package/dist/gs/maps/iter.js +3 -3
- package/dist/gs/maps/iter.js.map +1 -1
- package/dist/gs/maps/maps.d.ts +2 -2
- 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 +66 -34
- 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 +50 -0
- package/dist/gs/mime/index.js.map +1 -0
- package/dist/gs/net/http/httptest/index.d.ts +11 -0
- package/dist/gs/net/http/httptest/index.js +21 -0
- package/dist/gs/net/http/httptest/index.js.map +1 -0
- package/dist/gs/net/http/index.d.ts +27 -0
- package/dist/gs/net/http/index.js +61 -0
- package/dist/gs/net/http/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/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 +3 -1
- package/dist/gs/path/filepath/path.js +133 -4
- 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 +1 -1
- package/dist/gs/reflect/index.js +1 -1
- package/dist/gs/reflect/index.js.map +1 -1
- package/dist/gs/reflect/map.js +3 -0
- package/dist/gs/reflect/map.js.map +1 -1
- package/dist/gs/reflect/type.d.ts +7 -4
- package/dist/gs/reflect/type.js +148 -7
- package/dist/gs/reflect/type.js.map +1 -1
- package/dist/gs/runtime/debug/index.d.ts +2 -0
- package/dist/gs/runtime/debug/index.js +8 -0
- package/dist/gs/runtime/debug/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/slices/slices.d.ts +24 -5
- package/dist/gs/slices/slices.js +214 -5
- package/dist/gs/slices/slices.js.map +1 -1
- package/dist/gs/sort/slice.gs.d.ts +3 -3
- package/dist/gs/sort/slice.gs.js +6 -6
- 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 +3 -2
- package/dist/gs/strings/builder.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 +2 -0
- package/dist/gs/sync/sync.js +27 -0
- 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 +2 -0
- package/dist/gs/syscall/errors.js +8 -0
- package/dist/gs/syscall/errors.js.map +1 -1
- package/dist/gs/syscall/fs.d.ts +43 -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 +375 -0
- package/dist/gs/syscall/js/index.js.map +1 -0
- package/dist/gs/syscall/types.d.ts +22 -0
- 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 +77 -0
- package/dist/gs/testing/testing.js +301 -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 +205 -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 +71 -0
- package/dist/gs/unique/index.js.map +1 -0
- package/go.sum +9 -0
- package/gs/builtin/builtin.ts +239 -8
- package/gs/builtin/channel.ts +22 -0
- package/gs/builtin/runtime-contract.test.ts +126 -0
- package/gs/builtin/slice.ts +259 -50
- package/gs/builtin/type.ts +109 -34
- package/gs/builtin/varRef.ts +38 -1
- package/gs/bytes/buffer.gs.ts +48 -44
- package/gs/bytes/meta.json +8 -3
- package/gs/bytes/reader.gs.ts +20 -19
- package/gs/context/context.test.ts +41 -0
- package/gs/context/context.ts +22 -26
- package/gs/crypto/internal/fips140deps/byteorder/index.ts +1 -0
- package/gs/crypto/internal/fips140deps/godebug/index.ts +1 -0
- package/gs/embed/index.ts +20 -0
- package/gs/embed/meta.json +5 -0
- package/gs/encoding/json/index.test.ts +15 -1
- package/gs/encoding/json/index.ts +24 -0
- package/gs/errors/errors.test.ts +82 -0
- package/gs/errors/errors.ts +104 -0
- package/gs/fmt/fmt.ts +56 -16
- package/gs/github.com/aperturerobotics/protobuf-go-lite/index.test.ts +73 -1
- package/gs/github.com/aperturerobotics/protobuf-go-lite/index.ts +297 -1
- package/gs/github.com/aperturerobotics/protobuf-go-lite/json/index.test.ts +159 -0
- package/gs/github.com/aperturerobotics/protobuf-go-lite/json/index.ts +1005 -0
- package/gs/github.com/aperturerobotics/starpc/srpc/index.ts +719 -0
- package/gs/github.com/aperturerobotics/starpc/srpc/meta.json +40 -0
- package/gs/github.com/klauspost/compress/internal/le/index.test.ts +36 -0
- package/gs/github.com/klauspost/compress/internal/le/index.ts +114 -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 +570 -4
- 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 +77 -0
- package/gs/io/fs/walk.test.ts +61 -0
- package/gs/io/fs/walk.ts +9 -9
- package/gs/io/io.ts +174 -31
- package/gs/io/meta.json +10 -2
- package/gs/maps/iter.ts +12 -6
- package/gs/maps/maps.ts +8 -6
- package/gs/math/bits/index.ts +103 -47
- package/gs/math/const.gs.test.ts +11 -5
- package/gs/math/const.gs.ts +5 -6
- package/gs/mime/index.ts +54 -0
- package/gs/net/http/httptest/index.ts +25 -0
- package/gs/net/http/index.test.ts +20 -0
- package/gs/net/http/index.ts +81 -0
- package/gs/os/dir_unix.gs.ts +2 -3
- package/gs/os/types_js.gs.ts +2 -2
- package/gs/path/filepath/match.test.ts +31 -12
- package/gs/path/filepath/match.ts +178 -3
- package/gs/path/filepath/path.test.ts +25 -0
- package/gs/path/filepath/path.ts +159 -5
- package/gs/path/path.ts +20 -5
- package/gs/reflect/index.ts +1 -0
- package/gs/reflect/map.test.ts +19 -0
- package/gs/reflect/map.ts +4 -0
- package/gs/reflect/type.ts +197 -17
- package/gs/runtime/debug/index.test.ts +24 -0
- package/gs/runtime/debug/index.ts +8 -0
- package/gs/runtime/runtime.test.ts +19 -0
- package/gs/runtime/runtime.ts +98 -3
- package/gs/slices/slices.test.ts +94 -0
- package/gs/slices/slices.ts +245 -5
- package/gs/sort/meta.json +7 -0
- package/gs/sort/slice.gs.ts +16 -7
- package/gs/sort/sort.gs.ts +16 -13
- package/gs/strings/builder.ts +4 -3
- package/gs/sync/atomic/type.gs.ts +13 -14
- package/gs/sync/meta.json +3 -1
- package/gs/sync/sync.test.ts +13 -1
- package/gs/sync/sync.ts +27 -0
- package/gs/syscall/constants.ts +39 -24
- package/gs/syscall/errors.ts +10 -0
- package/gs/syscall/fs.ts +195 -0
- package/gs/syscall/js/index.ts +458 -0
- package/gs/syscall/js/meta.json +4 -0
- package/gs/syscall/net.test.ts +85 -0
- package/gs/syscall/types.ts +56 -0
- package/gs/testing/index.ts +1 -0
- package/gs/testing/meta.json +5 -0
- package/gs/testing/testing.test.ts +90 -0
- package/gs/testing/testing.ts +382 -0
- package/gs/time/time.test.ts +106 -0
- package/gs/time/time.ts +278 -57
- package/gs/unicode/unicode.test.ts +25 -0
- package/gs/unicode/unicode.ts +119 -9
- package/gs/unicode/utf8/utf8.test.ts +13 -0
- package/gs/unicode/utf8/utf8.ts +28 -16
- package/gs/unique/index.ts +91 -0
- package/package.json +2 -1
|
@@ -4,6 +4,8 @@ import { AddInt64, AddUint64, AndInt64, AndUint64, CompareAndSwapInt64, CompareA
|
|
|
4
4
|
|
|
5
5
|
import * as unsafe from "@goscript/unsafe/index.js"
|
|
6
6
|
|
|
7
|
+
export type PointerValue<T> = T | $.VarRef<T> | null
|
|
8
|
+
|
|
7
9
|
export class Bool {
|
|
8
10
|
public get v(): number {
|
|
9
11
|
return this._fields.v.value
|
|
@@ -74,18 +76,18 @@ export function b32(b: boolean): number {
|
|
|
74
76
|
|
|
75
77
|
|
|
76
78
|
export class Pointer<T> {
|
|
77
|
-
public get v():
|
|
79
|
+
public get v(): PointerValue<T> {
|
|
78
80
|
return this._fields.v.value
|
|
79
81
|
}
|
|
80
|
-
public set v(value:
|
|
82
|
+
public set v(value: PointerValue<T>) {
|
|
81
83
|
this._fields.v.value = value
|
|
82
84
|
}
|
|
83
85
|
|
|
84
86
|
public _fields: {
|
|
85
|
-
v: $.VarRef
|
|
87
|
+
v: $.VarRef<PointerValue<T>>;
|
|
86
88
|
}
|
|
87
89
|
|
|
88
|
-
constructor(init?: Partial<{v?:
|
|
90
|
+
constructor(init?: Partial<{v?: PointerValue<T>}>) {
|
|
89
91
|
this._fields = {
|
|
90
92
|
v: $.varRef(init?.v ?? null)
|
|
91
93
|
}
|
|
@@ -100,14 +102,13 @@ export class Pointer<T> {
|
|
|
100
102
|
}
|
|
101
103
|
|
|
102
104
|
// Load atomically loads and returns the value stored in x.
|
|
103
|
-
public Load():
|
|
105
|
+
public Load(): PointerValue<T> {
|
|
104
106
|
const x = this
|
|
105
|
-
return LoadPointer(x._fields.v) as
|
|
107
|
+
return LoadPointer(x._fields.v) as PointerValue<T>
|
|
106
108
|
}
|
|
107
109
|
|
|
108
110
|
// Store atomically stores val into x.
|
|
109
|
-
|
|
110
|
-
public Store(val: $.VarRef<T> | null): void {
|
|
111
|
+
public Store(val: PointerValue<T>): void {
|
|
111
112
|
const x = this
|
|
112
113
|
if (val === null) {
|
|
113
114
|
StorePointer(x._fields.v, null)
|
|
@@ -117,17 +118,16 @@ export class Pointer<T> {
|
|
|
117
118
|
}
|
|
118
119
|
|
|
119
120
|
// Swap atomically stores new into x and returns the previous value.
|
|
120
|
-
|
|
121
|
-
public Swap(_new: $.VarRef<T> | null): $.VarRef<T> | null {
|
|
121
|
+
public Swap(_new: PointerValue<T>): PointerValue<T> {
|
|
122
122
|
const x = this
|
|
123
123
|
if (_new === null) {
|
|
124
|
-
return SwapPointer(x._fields.v, null) as
|
|
124
|
+
return SwapPointer(x._fields.v, null) as PointerValue<T>
|
|
125
125
|
}
|
|
126
|
-
return SwapPointer(x._fields.v, unsafe.Pointer(_new)) as
|
|
126
|
+
return SwapPointer(x._fields.v, unsafe.Pointer(_new)) as PointerValue<T>
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
// CompareAndSwap executes the compare-and-swap operation for x.
|
|
130
|
-
public CompareAndSwap(old:
|
|
130
|
+
public CompareAndSwap(old: PointerValue<T>, _new: PointerValue<T>): boolean {
|
|
131
131
|
const x = this
|
|
132
132
|
return CompareAndSwapPointer(x._fields.v, old ? unsafe.Pointer(old) : null, _new ? unsafe.Pointer(_new) : null)
|
|
133
133
|
}
|
|
@@ -598,4 +598,3 @@ class align64 {
|
|
|
598
598
|
{}
|
|
599
599
|
);
|
|
600
600
|
}
|
|
601
|
-
|
package/gs/sync/meta.json
CHANGED
|
@@ -9,11 +9,13 @@
|
|
|
9
9
|
"WaitGroup.Wait": true,
|
|
10
10
|
"Once.Do": true,
|
|
11
11
|
"Cond.Wait": true,
|
|
12
|
+
"Map.CompareAndDelete": true,
|
|
12
13
|
"Map.Delete": true,
|
|
13
14
|
"Map.Load": true,
|
|
14
15
|
"Map.LoadAndDelete": true,
|
|
15
16
|
"Map.LoadOrStore": true,
|
|
16
17
|
"Map.Range": true,
|
|
17
|
-
"Map.Store": true
|
|
18
|
+
"Map.Store": true,
|
|
19
|
+
"Map.Swap": true
|
|
18
20
|
}
|
|
19
21
|
}
|
package/gs/sync/sync.test.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest'
|
|
2
2
|
|
|
3
|
-
import { WaitGroup } from './sync.js'
|
|
3
|
+
import { Map, WaitGroup } from './sync.js'
|
|
4
4
|
|
|
5
5
|
describe('sync.WaitGroup', () => {
|
|
6
6
|
it('Go tracks scheduled work and unblocks Wait after completion', async () => {
|
|
@@ -22,3 +22,15 @@ describe('sync.WaitGroup', () => {
|
|
|
22
22
|
expect(events).toEqual(['worker start', 'worker done', 'wait done'])
|
|
23
23
|
})
|
|
24
24
|
})
|
|
25
|
+
|
|
26
|
+
describe('sync.Map', () => {
|
|
27
|
+
it('CompareAndDelete deletes only matching entries', async () => {
|
|
28
|
+
const m = new Map()
|
|
29
|
+
|
|
30
|
+
await m.Store('key', 'value')
|
|
31
|
+
expect(await m.CompareAndDelete('key', 'other')).toBe(false)
|
|
32
|
+
expect(await m.Load('key')).toEqual(['value', true])
|
|
33
|
+
expect(await m.CompareAndDelete('key', 'value')).toBe(true)
|
|
34
|
+
expect(await m.Load('key')).toEqual([undefined, false])
|
|
35
|
+
})
|
|
36
|
+
})
|
package/gs/sync/sync.ts
CHANGED
|
@@ -321,6 +321,20 @@ export class Map {
|
|
|
321
321
|
}
|
|
322
322
|
}
|
|
323
323
|
|
|
324
|
+
// CompareAndDelete deletes the entry for key if its value is equal to old.
|
|
325
|
+
public async CompareAndDelete(key: any, old: any): Promise<boolean> {
|
|
326
|
+
await this._m.Lock()
|
|
327
|
+
try {
|
|
328
|
+
if (!this._data.has(key) || this._data.get(key) !== old) {
|
|
329
|
+
return false
|
|
330
|
+
}
|
|
331
|
+
this._data.delete(key)
|
|
332
|
+
return true
|
|
333
|
+
} finally {
|
|
334
|
+
this._m.Unlock()
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
324
338
|
// Load returns the value stored in the map for a key, or nil if no value is present
|
|
325
339
|
public async Load(key: any): Promise<[any, boolean]> {
|
|
326
340
|
await this._m.RLock()
|
|
@@ -383,6 +397,19 @@ export class Map {
|
|
|
383
397
|
}
|
|
384
398
|
}
|
|
385
399
|
|
|
400
|
+
// Swap swaps the value for a key and returns the previous value if any
|
|
401
|
+
public async Swap(key: any, value: any): Promise<[any, boolean]> {
|
|
402
|
+
await this._m.Lock()
|
|
403
|
+
try {
|
|
404
|
+
const previous = this._data.get(key)
|
|
405
|
+
const loaded = this._data.has(key)
|
|
406
|
+
this._data.set(key, value)
|
|
407
|
+
return [previous, loaded]
|
|
408
|
+
} finally {
|
|
409
|
+
this._m.Unlock()
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
|
|
386
413
|
// clone returns a copy of this Map instance
|
|
387
414
|
public clone(): Map {
|
|
388
415
|
return new Map()
|
package/gs/syscall/constants.ts
CHANGED
|
@@ -1,29 +1,44 @@
|
|
|
1
1
|
// Essential syscall constants
|
|
2
|
-
export const O_RDONLY = 0
|
|
3
|
-
export const O_WRONLY = 1
|
|
4
|
-
export const O_RDWR = 2
|
|
5
|
-
export const O_APPEND = 8
|
|
6
|
-
export const O_CREATE = 64
|
|
7
|
-
export const O_EXCL = 128
|
|
8
|
-
export const O_SYNC = 256
|
|
9
|
-
export const O_TRUNC = 512
|
|
2
|
+
export const O_RDONLY: number = 0
|
|
3
|
+
export const O_WRONLY: number = 1
|
|
4
|
+
export const O_RDWR: number = 2
|
|
5
|
+
export const O_APPEND: number = 8
|
|
6
|
+
export const O_CREATE: number = 64
|
|
7
|
+
export const O_EXCL: number = 128
|
|
8
|
+
export const O_SYNC: number = 256
|
|
9
|
+
export const O_TRUNC: number = 512
|
|
10
10
|
|
|
11
|
-
export const Stdin = 0
|
|
12
|
-
export const Stdout = 1
|
|
13
|
-
export const Stderr = 2
|
|
11
|
+
export const Stdin: number = 0
|
|
12
|
+
export const Stdout: number = 1
|
|
13
|
+
export const Stderr: number = 2
|
|
14
14
|
|
|
15
|
-
export const SIGINT = 2
|
|
16
|
-
export const SIGTERM = 15
|
|
15
|
+
export const SIGINT: number = 2
|
|
16
|
+
export const SIGTERM: number = 15
|
|
17
|
+
|
|
18
|
+
export const AF_UNIX: number = 1
|
|
19
|
+
export const AF_INET: number = 2
|
|
20
|
+
export const AF_INET6: number = 10
|
|
21
|
+
|
|
22
|
+
export const SOCK_STREAM: number = 1
|
|
23
|
+
export const SOCK_DGRAM: number = 2
|
|
24
|
+
export const SOCK_RAW: number = 3
|
|
25
|
+
export const SOCK_SEQPACKET: number = 5
|
|
26
|
+
|
|
27
|
+
export const IPPROTO_IPV6: number = 0x29
|
|
28
|
+
export const IPPROTO_TCP: number = 6
|
|
29
|
+
export const IPV6_V6ONLY: number = 0x1a
|
|
30
|
+
export const SOMAXCONN: number = 0x80
|
|
31
|
+
export const F_DUPFD_CLOEXEC: number = 1
|
|
17
32
|
|
|
18
33
|
// File mode constants
|
|
19
|
-
export const S_IFMT = 0o170000
|
|
20
|
-
export const S_IFREG = 0o100000
|
|
21
|
-
export const S_IFDIR = 0o040000
|
|
22
|
-
export const S_IFLNK = 0o120000
|
|
23
|
-
export const S_IFBLK = 0o060000
|
|
24
|
-
export const S_IFCHR = 0o020000
|
|
25
|
-
export const S_IFIFO = 0o010000
|
|
26
|
-
export const S_IFSOCK = 0o140000
|
|
27
|
-
export const S_ISUID = 0o004000
|
|
28
|
-
export const S_ISGID = 0o002000
|
|
29
|
-
export const S_ISVTX = 0o001000
|
|
34
|
+
export const S_IFMT: number = 0o170000
|
|
35
|
+
export const S_IFREG: number = 0o100000
|
|
36
|
+
export const S_IFDIR: number = 0o040000
|
|
37
|
+
export const S_IFLNK: number = 0o120000
|
|
38
|
+
export const S_IFBLK: number = 0o060000
|
|
39
|
+
export const S_IFCHR: number = 0o020000
|
|
40
|
+
export const S_IFIFO: number = 0o010000
|
|
41
|
+
export const S_IFSOCK: number = 0o140000
|
|
42
|
+
export const S_ISUID: number = 0o004000
|
|
43
|
+
export const S_ISGID: number = 0o002000
|
|
44
|
+
export const S_ISVTX: number = 0o001000
|
package/gs/syscall/errors.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import * as $ from '@goscript/builtin/index.js'
|
|
2
2
|
import { Errno } from './types.js'
|
|
3
3
|
|
|
4
|
+
export function Errno_Error(errno: Errno): string {
|
|
5
|
+
return errno.Error()
|
|
6
|
+
}
|
|
7
|
+
|
|
4
8
|
export const EPERM: Errno = {
|
|
5
9
|
Error: () => 'operation not permitted',
|
|
6
10
|
Is: (target: $.GoError) => target === EPERM,
|
|
@@ -217,6 +221,12 @@ export const ENOSYS: Errno = {
|
|
|
217
221
|
Errno: () => 38,
|
|
218
222
|
}
|
|
219
223
|
|
|
224
|
+
export const ENOTSUP: Errno = {
|
|
225
|
+
Error: () => 'operation not supported',
|
|
226
|
+
Is: (target: $.GoError) => target === ENOTSUP,
|
|
227
|
+
Errno: () => 95,
|
|
228
|
+
}
|
|
229
|
+
|
|
220
230
|
export const ENOTEMPTY: Errno = {
|
|
221
231
|
Error: () => 'directory not empty',
|
|
222
232
|
Is: (target: $.GoError) => target === ENOTEMPTY,
|
package/gs/syscall/fs.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import * as $ from '@goscript/builtin/index.js'
|
|
2
|
+
import { RWMutex } from '@goscript/sync/index.js'
|
|
2
3
|
import { ENOSYS } from './errors.js'
|
|
4
|
+
import type { Iovec, Sockaddr } from './types.js'
|
|
3
5
|
|
|
4
6
|
// Dirent structure with Reclen field
|
|
5
7
|
export class Dirent {
|
|
@@ -54,9 +56,202 @@ export function Sysctl(_name: string): [string, $.GoError] {
|
|
|
54
56
|
return ['', ENOSYS]
|
|
55
57
|
}
|
|
56
58
|
|
|
59
|
+
export function Unlink(_path: string): $.GoError {
|
|
60
|
+
return ENOSYS
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export const ForkLock = new RWMutex()
|
|
64
|
+
|
|
65
|
+
export function Close(_fd: number): $.GoError {
|
|
66
|
+
return null
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function CloseOnExec(_fd: number): void {}
|
|
70
|
+
|
|
71
|
+
export function SetNonblock(_fd: number, _nonblocking: boolean): $.GoError {
|
|
72
|
+
return null
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function Fchdir(_fd: number): $.GoError {
|
|
76
|
+
return ENOSYS
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function Fchmod(_fd: number, _mode: number): $.GoError {
|
|
80
|
+
return ENOSYS
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function Fchown(_fd: number, _uid: number, _gid: number): $.GoError {
|
|
84
|
+
return ENOSYS
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function Fstat(
|
|
88
|
+
_fd: number,
|
|
89
|
+
_stat: Stat_t | $.VarRef<Stat_t> | null,
|
|
90
|
+
): $.GoError {
|
|
91
|
+
return ENOSYS
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function Fsync(_fd: number): $.GoError {
|
|
95
|
+
return ENOSYS
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function Ftruncate(_fd: number, _length: number): $.GoError {
|
|
99
|
+
return ENOSYS
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function Read(_fd: number, _b: $.Bytes | null): [number, $.GoError] {
|
|
103
|
+
return [0, ENOSYS]
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function ReadDirent(
|
|
107
|
+
_fd: number,
|
|
108
|
+
_buf: $.Bytes | null,
|
|
109
|
+
): [number, $.GoError] {
|
|
110
|
+
return [0, ENOSYS]
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function Pread(
|
|
114
|
+
_fd: number,
|
|
115
|
+
_b: $.Bytes | null,
|
|
116
|
+
_offset: number,
|
|
117
|
+
): [number, $.GoError] {
|
|
118
|
+
return [0, ENOSYS]
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export function Pwrite(
|
|
122
|
+
_fd: number,
|
|
123
|
+
_b: $.Bytes | null,
|
|
124
|
+
_offset: number,
|
|
125
|
+
): [number, $.GoError] {
|
|
126
|
+
return [0, ENOSYS]
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export function Seek(
|
|
130
|
+
_fd: number,
|
|
131
|
+
_offset: number,
|
|
132
|
+
_whence: number,
|
|
133
|
+
): [number, $.GoError] {
|
|
134
|
+
return [0, ENOSYS]
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function Write(_fd: number, _b: $.Bytes | null): [number, $.GoError] {
|
|
138
|
+
return [0, ENOSYS]
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export function Dup(_fd: number): [number, $.GoError] {
|
|
142
|
+
return [0, ENOSYS]
|
|
143
|
+
}
|
|
144
|
+
|
|
57
145
|
// Getpagesize returns the underlying system's memory page size.
|
|
58
146
|
export function Getpagesize(): number {
|
|
59
147
|
// Return a standard page size for JavaScript environment
|
|
60
148
|
// Most systems use 4096 bytes as the default page size
|
|
61
149
|
return 4096
|
|
62
150
|
}
|
|
151
|
+
|
|
152
|
+
export function Socket(
|
|
153
|
+
_domain: number,
|
|
154
|
+
_typ: number,
|
|
155
|
+
_proto: number,
|
|
156
|
+
): [number, $.GoError] {
|
|
157
|
+
return [-1, ENOSYS]
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export function Connect(_fd: number, _sa: Sockaddr | null): $.GoError {
|
|
161
|
+
return ENOSYS
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export function Listen(_fd: number, _backlog: number): $.GoError {
|
|
165
|
+
return ENOSYS
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export function Bind(_fd: number, _sa: Sockaddr | null): $.GoError {
|
|
169
|
+
return ENOSYS
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export function StopIO(_fd: number): $.GoError {
|
|
173
|
+
return ENOSYS
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export function Accept(_fd: number): [number, Sockaddr | null, $.GoError] {
|
|
177
|
+
return [0, null, ENOSYS]
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export function Recvfrom(
|
|
181
|
+
_fd: number,
|
|
182
|
+
_p: $.Bytes | null,
|
|
183
|
+
_flags: number,
|
|
184
|
+
): [number, Sockaddr | null, $.GoError] {
|
|
185
|
+
return [0, null, ENOSYS]
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export function Sendto(
|
|
189
|
+
_fd: number,
|
|
190
|
+
_p: $.Bytes | null,
|
|
191
|
+
_flags: number,
|
|
192
|
+
_to: Sockaddr | null,
|
|
193
|
+
): $.GoError {
|
|
194
|
+
return ENOSYS
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export function Recvmsg(
|
|
198
|
+
_fd: number,
|
|
199
|
+
_p: $.Bytes | null,
|
|
200
|
+
_oob: $.Bytes | null,
|
|
201
|
+
_flags: number,
|
|
202
|
+
): [number, number, number, Sockaddr | null, $.GoError] {
|
|
203
|
+
return [0, 0, 0, null, ENOSYS]
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export function SendmsgN(
|
|
207
|
+
_fd: number,
|
|
208
|
+
_p: $.Bytes | null,
|
|
209
|
+
_oob: $.Bytes | null,
|
|
210
|
+
_to: Sockaddr | null,
|
|
211
|
+
_flags: number,
|
|
212
|
+
): [number, $.GoError] {
|
|
213
|
+
return [0, ENOSYS]
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export function SetReadDeadline(_fd: number, _t: number): $.GoError {
|
|
217
|
+
return ENOSYS
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
export function SetWriteDeadline(_fd: number, _t: number): $.GoError {
|
|
221
|
+
return ENOSYS
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export function Shutdown(_fd: number, _how: number): $.GoError {
|
|
225
|
+
return ENOSYS
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export function GetsockoptInt(
|
|
229
|
+
_fd: number,
|
|
230
|
+
_level: number,
|
|
231
|
+
_opt: number,
|
|
232
|
+
): [number, $.GoError] {
|
|
233
|
+
return [0, ENOSYS]
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export function SetsockoptInt(
|
|
237
|
+
_fd: number,
|
|
238
|
+
_level: number,
|
|
239
|
+
_opt: number,
|
|
240
|
+
_value: number,
|
|
241
|
+
): $.GoError {
|
|
242
|
+
return null
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export function readv(_fd: number, _iovecs: $.Slice<Iovec> | null): [
|
|
246
|
+
number,
|
|
247
|
+
$.GoError,
|
|
248
|
+
] {
|
|
249
|
+
return [0, ENOSYS]
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export function writev(_fd: number, _iovecs: $.Slice<Iovec> | null): [
|
|
253
|
+
number,
|
|
254
|
+
$.GoError,
|
|
255
|
+
] {
|
|
256
|
+
return [0, ENOSYS]
|
|
257
|
+
}
|