goscript 0.0.34 → 0.0.36
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/compiler/analysis.go +28 -20
- package/compiler/analysis_test.go +14 -0
- package/compiler/assignment.go +19 -7
- package/compiler/compiler.go +15 -99
- package/compiler/composite-lit.go +60 -17
- package/compiler/decl.go +1 -1
- package/compiler/expr-call.go +233 -35
- package/compiler/expr-selector.go +28 -2
- package/compiler/expr.go +13 -37
- package/compiler/lit.go +111 -2
- package/compiler/primitive.go +6 -6
- package/compiler/protobuf.go +0 -5
- package/compiler/sanitize.go +101 -0
- package/compiler/spec-struct.go +41 -8
- package/compiler/spec-value.go +29 -18
- package/compiler/stmt-assign.go +22 -1
- package/compiler/stmt.go +26 -9
- package/compiler/type.go +3 -3
- package/dist/gs/builtin/builtin.d.ts +3 -2
- package/dist/gs/builtin/builtin.js +2 -1
- package/dist/gs/builtin/builtin.js.map +1 -1
- package/dist/gs/builtin/map.js.map +1 -1
- package/dist/gs/builtin/slice.d.ts +7 -1
- package/dist/gs/builtin/slice.js +112 -22
- package/dist/gs/builtin/slice.js.map +1 -1
- package/dist/gs/github.com/pkg/errors/errors.d.ts +13 -0
- package/dist/gs/github.com/pkg/errors/errors.js +232 -0
- package/dist/gs/github.com/pkg/errors/errors.js.map +1 -0
- package/dist/gs/github.com/pkg/errors/go113.d.ts +4 -0
- package/dist/gs/github.com/pkg/errors/go113.js +34 -0
- package/dist/gs/github.com/pkg/errors/go113.js.map +1 -0
- package/dist/gs/github.com/pkg/errors/index.d.ts +3 -0
- package/dist/gs/github.com/pkg/errors/index.js +4 -0
- package/dist/gs/github.com/pkg/errors/index.js.map +1 -0
- package/dist/gs/github.com/pkg/errors/stack.d.ts +32 -0
- package/dist/gs/github.com/pkg/errors/stack.js +111 -0
- package/dist/gs/github.com/pkg/errors/stack.js.map +1 -0
- package/dist/gs/maps/index.d.ts +2 -2
- package/dist/gs/maps/index.js +2 -2
- package/dist/gs/maps/index.js.map +1 -1
- package/dist/gs/maps/iter.d.ts +7 -0
- package/dist/gs/maps/iter.js +57 -0
- package/dist/gs/maps/iter.js.map +1 -0
- package/dist/gs/maps/maps.d.ts +7 -0
- package/dist/gs/maps/maps.js +67 -0
- package/dist/gs/maps/maps.js.map +1 -0
- package/dist/gs/math/abs.gs.d.ts +1 -0
- package/dist/gs/math/abs.gs.js +10 -0
- package/dist/gs/math/abs.gs.js.map +1 -0
- package/dist/gs/math/acosh.gs.d.ts +2 -0
- package/dist/gs/math/acosh.gs.js +14 -0
- package/dist/gs/math/acosh.gs.js.map +1 -0
- package/dist/gs/math/asin.gs.d.ts +4 -0
- package/dist/gs/math/asin.gs.js +24 -0
- package/dist/gs/math/asin.gs.js.map +1 -0
- package/dist/gs/math/asinh.gs.d.ts +2 -0
- package/dist/gs/math/asinh.gs.js +14 -0
- package/dist/gs/math/asinh.gs.js.map +1 -0
- package/dist/gs/math/atan.gs.d.ts +4 -0
- package/dist/gs/math/atan.gs.js +22 -0
- package/dist/gs/math/atan.gs.js.map +1 -0
- package/dist/gs/math/atan2.gs.d.ts +2 -0
- package/dist/gs/math/atan2.gs.js +30 -0
- package/dist/gs/math/atan2.gs.js.map +1 -0
- package/dist/gs/math/atanh.gs.d.ts +2 -0
- package/dist/gs/math/atanh.gs.js +16 -0
- package/dist/gs/math/atanh.gs.js.map +1 -0
- package/dist/gs/math/bits.gs.d.ts +5 -0
- package/dist/gs/math/bits.gs.js +46 -0
- package/dist/gs/math/bits.gs.js.map +1 -0
- package/dist/gs/math/cbrt.gs.d.ts +2 -0
- package/dist/gs/math/cbrt.gs.js +14 -0
- package/dist/gs/math/cbrt.gs.js.map +1 -0
- package/dist/gs/math/const.gs.d.ts +30 -0
- package/dist/gs/math/const.gs.js +61 -0
- package/dist/gs/math/const.gs.js.map +1 -0
- package/dist/gs/math/copysign.gs.d.ts +1 -0
- package/dist/gs/math/copysign.gs.js +20 -0
- package/dist/gs/math/copysign.gs.js.map +1 -0
- package/dist/gs/math/dim.gs.d.ts +5 -0
- package/dist/gs/math/dim.gs.js +69 -0
- package/dist/gs/math/dim.gs.js.map +1 -0
- package/dist/gs/math/erf.gs.d.ts +4 -0
- package/dist/gs/math/erf.gs.js +336 -0
- package/dist/gs/math/erf.gs.js.map +1 -0
- package/dist/gs/math/erfinv.gs.d.ts +2 -0
- package/dist/gs/math/erfinv.gs.js +118 -0
- package/dist/gs/math/erfinv.gs.js.map +1 -0
- package/dist/gs/math/exp.gs.d.ts +5 -0
- package/dist/gs/math/exp.gs.js +30 -0
- package/dist/gs/math/exp.gs.js.map +1 -0
- package/dist/gs/math/expm1.gs.d.ts +2 -0
- package/dist/gs/math/expm1.gs.js +17 -0
- package/dist/gs/math/expm1.gs.js.map +1 -0
- package/dist/gs/math/floor.gs.d.ts +8 -0
- package/dist/gs/math/floor.gs.js +75 -0
- package/dist/gs/math/floor.gs.js.map +1 -0
- package/dist/gs/math/fma.gs.d.ts +1 -0
- package/dist/gs/math/fma.gs.js +8 -0
- package/dist/gs/math/fma.gs.js.map +1 -0
- package/dist/gs/math/frexp.gs.d.ts +2 -0
- package/dist/gs/math/frexp.gs.js +28 -0
- package/dist/gs/math/frexp.gs.js.map +1 -0
- package/dist/gs/math/gamma.gs.d.ts +3 -0
- package/dist/gs/math/gamma.gs.js +149 -0
- package/dist/gs/math/gamma.gs.js.map +1 -0
- package/dist/gs/math/hypot.gs.d.ts +2 -0
- package/dist/gs/math/hypot.gs.js +16 -0
- package/dist/gs/math/hypot.gs.js.map +1 -0
- package/dist/gs/math/index.d.ts +44 -0
- package/dist/gs/math/index.js +45 -0
- package/dist/gs/math/index.js.map +1 -0
- package/dist/gs/math/j0.gs.d.ts +4 -0
- package/dist/gs/math/j0.gs.js +228 -0
- package/dist/gs/math/j0.gs.js.map +1 -0
- package/dist/gs/math/j1.gs.d.ts +4 -0
- package/dist/gs/math/j1.gs.js +211 -0
- package/dist/gs/math/j1.gs.js.map +1 -0
- package/dist/gs/math/jn.gs.d.ts +2 -0
- package/dist/gs/math/jn.gs.js +412 -0
- package/dist/gs/math/jn.gs.js.map +1 -0
- package/dist/gs/math/ldexp.gs.d.ts +2 -0
- package/dist/gs/math/ldexp.gs.js +20 -0
- package/dist/gs/math/ldexp.gs.js.map +1 -0
- package/dist/gs/math/lgamma.gs.d.ts +2 -0
- package/dist/gs/math/lgamma.gs.js +243 -0
- package/dist/gs/math/lgamma.gs.js.map +1 -0
- package/dist/gs/math/log.gs.d.ts +2 -0
- package/dist/gs/math/log.gs.js +16 -0
- package/dist/gs/math/log.gs.js.map +1 -0
- package/dist/gs/math/log10.gs.d.ts +4 -0
- package/dist/gs/math/log10.gs.js +17 -0
- package/dist/gs/math/log10.gs.js.map +1 -0
- package/dist/gs/math/log1p.gs.d.ts +2 -0
- package/dist/gs/math/log1p.gs.js +17 -0
- package/dist/gs/math/log1p.gs.js.map +1 -0
- package/dist/gs/math/logb.gs.d.ts +3 -0
- package/dist/gs/math/logb.gs.js +43 -0
- package/dist/gs/math/logb.gs.js.map +1 -0
- package/dist/gs/math/mod.gs.d.ts +2 -0
- package/dist/gs/math/mod.gs.js +26 -0
- package/dist/gs/math/mod.gs.js.map +1 -0
- package/dist/gs/math/modf.gs.d.ts +2 -0
- package/dist/gs/math/modf.gs.js +24 -0
- package/dist/gs/math/modf.gs.js.map +1 -0
- package/dist/gs/math/nextafter.gs.d.ts +2 -0
- package/dist/gs/math/nextafter.gs.js +66 -0
- package/dist/gs/math/nextafter.gs.js.map +1 -0
- package/dist/gs/math/pow.gs.d.ts +3 -0
- package/dist/gs/math/pow.gs.js +40 -0
- package/dist/gs/math/pow.gs.js.map +1 -0
- package/dist/gs/math/pow10.gs.d.ts +1 -0
- package/dist/gs/math/pow10.gs.js +14 -0
- package/dist/gs/math/pow10.gs.js.map +1 -0
- package/dist/gs/math/remainder.gs.d.ts +2 -0
- package/dist/gs/math/remainder.gs.js +25 -0
- package/dist/gs/math/remainder.gs.js.map +1 -0
- package/dist/gs/math/signbit.gs.d.ts +1 -0
- package/dist/gs/math/signbit.gs.js +5 -0
- package/dist/gs/math/signbit.gs.js.map +1 -0
- package/dist/gs/math/sin.gs.d.ts +4 -0
- package/dist/gs/math/sin.gs.js +29 -0
- package/dist/gs/math/sin.gs.js.map +1 -0
- package/dist/gs/math/sincos.gs.d.ts +1 -0
- package/dist/gs/math/sincos.gs.js +11 -0
- package/dist/gs/math/sincos.gs.js.map +1 -0
- package/dist/gs/math/sinh.gs.d.ts +4 -0
- package/dist/gs/math/sinh.gs.js +27 -0
- package/dist/gs/math/sinh.gs.js.map +1 -0
- package/dist/gs/math/sqrt.gs.d.ts +2 -0
- package/dist/gs/math/sqrt.gs.js +15 -0
- package/dist/gs/math/sqrt.gs.js.map +1 -0
- package/dist/gs/math/tan.gs.d.ts +2 -0
- package/dist/gs/math/tan.gs.js +17 -0
- package/dist/gs/math/tan.gs.js.map +1 -0
- package/dist/gs/math/tanh.gs.d.ts +2 -0
- package/dist/gs/math/tanh.gs.js +17 -0
- package/dist/gs/math/tanh.gs.js.map +1 -0
- package/dist/gs/math/trig_reduce.gs.d.ts +1 -0
- package/dist/gs/math/trig_reduce.gs.js +62 -0
- package/dist/gs/math/trig_reduce.gs.js.map +1 -0
- package/dist/gs/math/unsafe.gs.d.ts +4 -0
- package/dist/gs/math/unsafe.gs.js +47 -0
- package/dist/gs/math/unsafe.gs.js.map +1 -0
- package/dist/gs/strconv/atob.gs.d.ts +4 -0
- package/dist/gs/strconv/atob.gs.js +42 -0
- package/dist/gs/strconv/atob.gs.js.map +1 -0
- package/dist/gs/strconv/atof.gs.d.ts +2 -0
- package/dist/gs/strconv/atof.gs.js +51 -0
- package/dist/gs/strconv/atof.gs.js.map +1 -0
- package/dist/gs/strconv/atoi.gs.d.ts +33 -0
- package/dist/gs/strconv/atoi.gs.js +200 -0
- package/dist/gs/strconv/atoi.gs.js.map +1 -0
- package/dist/gs/strconv/doc.gs.d.ts +1 -0
- package/dist/gs/strconv/doc.gs.js +2 -0
- package/dist/gs/strconv/doc.gs.js.map +1 -0
- package/dist/gs/strconv/ftoa.gs.d.ts +3 -0
- package/dist/gs/strconv/ftoa.gs.js +58 -0
- package/dist/gs/strconv/ftoa.gs.js.map +1 -0
- package/dist/gs/strconv/index.d.ts +6 -0
- package/dist/gs/strconv/index.js +7 -0
- package/dist/gs/strconv/index.js.map +1 -0
- package/dist/gs/strconv/itoa.gs.d.ts +6 -0
- package/dist/gs/strconv/itoa.gs.js +37 -0
- package/dist/gs/strconv/itoa.gs.js.map +1 -0
- package/dist/gs/strconv/quote.gs.d.ts +19 -0
- package/dist/gs/strconv/quote.gs.js +217 -0
- package/dist/gs/strconv/quote.gs.js.map +1 -0
- package/dist/gs/strings/index.d.ts +3 -0
- package/dist/gs/strings/index.js +4 -0
- package/dist/gs/strings/index.js.map +1 -1
- package/dist/gs/strings/replace.d.ts +0 -74
- package/dist/gs/strings/replace.js +6 -204
- package/dist/gs/strings/replace.js.map +1 -1
- package/dist/gs/strings/search.d.ts +0 -1
- package/dist/gs/strings/search.js +0 -21
- package/dist/gs/strings/search.js.map +1 -1
- package/dist/gs/sync/atomic/doc.gs.d.ts +28 -0
- package/dist/gs/sync/atomic/doc.gs.js +265 -0
- package/dist/gs/sync/atomic/doc.gs.js.map +1 -0
- package/dist/gs/sync/atomic/doc_64.gs.d.ts +15 -0
- package/dist/gs/sync/atomic/doc_64.gs.js +165 -0
- package/dist/gs/sync/atomic/doc_64.gs.js.map +1 -0
- package/dist/gs/sync/atomic/index.d.ts +4 -0
- package/dist/gs/sync/atomic/index.js +5 -0
- package/dist/gs/sync/atomic/index.js.map +1 -0
- package/dist/gs/sync/atomic/type.gs.d.ts +130 -0
- package/dist/gs/sync/atomic/type.gs.js +433 -0
- package/dist/gs/sync/atomic/type.gs.js.map +1 -0
- package/dist/gs/sync/atomic/value.gs.d.ts +19 -0
- package/dist/gs/sync/atomic/value.gs.js +116 -0
- package/dist/gs/sync/atomic/value.gs.js.map +1 -0
- package/dist/gs/unsafe/unsafe.d.ts +1 -0
- package/dist/gs/unsafe/unsafe.js +5 -0
- package/dist/gs/unsafe/unsafe.js.map +1 -1
- package/gs/builtin/builtin.ts +9 -7
- package/gs/builtin/map.ts +5 -1
- package/gs/builtin/slice.ts +152 -24
- package/gs/github.com/pkg/errors/errors.ts +307 -0
- package/gs/github.com/pkg/errors/go113.ts +39 -0
- package/gs/github.com/pkg/errors/index.ts +3 -0
- package/gs/github.com/pkg/errors/stack.ts +127 -0
- package/gs/maps/index.ts +2 -2
- package/gs/maps/iter.ts +67 -0
- package/gs/maps/maps.ts +89 -0
- package/gs/math/TODO.md +156 -0
- package/gs/math/abs.gs.test.ts +29 -0
- package/gs/math/abs.gs.ts +13 -0
- package/gs/math/acosh.gs.test.ts +39 -0
- package/gs/math/acosh.gs.ts +21 -0
- package/gs/math/asin.gs.test.ts +66 -0
- package/gs/math/asin.gs.ts +27 -0
- package/gs/math/asinh.gs.test.ts +37 -0
- package/gs/math/asinh.gs.ts +21 -0
- package/gs/math/atan.gs.test.ts +49 -0
- package/gs/math/atan.gs.ts +27 -0
- package/gs/math/atan2.gs.test.ts +55 -0
- package/gs/math/atan2.gs.ts +37 -0
- package/gs/math/atanh.gs.test.ts +47 -0
- package/gs/math/atanh.gs.ts +21 -0
- package/gs/math/bits.gs.test.ts +88 -0
- package/gs/math/bits.gs.ts +61 -0
- package/gs/math/cbrt.gs.test.ts +57 -0
- package/gs/math/cbrt.gs.ts +20 -0
- package/gs/math/const.gs.test.ts +54 -0
- package/gs/math/const.gs.ts +93 -0
- package/gs/math/copysign.gs.test.ts +44 -0
- package/gs/math/copysign.gs.ts +27 -0
- package/gs/math/dim.gs.test.ts +102 -0
- package/gs/math/dim.gs.ts +84 -0
- package/gs/math/erf.gs.test.ts +92 -0
- package/gs/math/erf.gs.ts +409 -0
- package/gs/math/erfinv.gs.test.ts +104 -0
- package/gs/math/erfinv.gs.ts +169 -0
- package/gs/math/exp.gs.test.ts +82 -0
- package/gs/math/exp.gs.ts +39 -0
- package/gs/math/expm1.gs.test.ts +48 -0
- package/gs/math/expm1.gs.ts +23 -0
- package/gs/math/floor.gs.test.ts +146 -0
- package/gs/math/floor.gs.ts +88 -0
- package/gs/math/fma.gs.test.ts +83 -0
- package/gs/math/fma.gs.ts +7 -0
- package/gs/math/frexp.gs.test.ts +146 -0
- package/gs/math/frexp.gs.ts +37 -0
- package/gs/math/gamma.gs.test.ts +66 -0
- package/gs/math/gamma.gs.ts +158 -0
- package/gs/math/hypot.gs.test.ts +73 -0
- package/gs/math/hypot.gs.ts +23 -0
- package/gs/math/index.ts +44 -0
- package/gs/math/j0.gs.test.ts +74 -0
- package/gs/math/j0.gs.ts +257 -0
- package/gs/math/j1.gs.test.ts +81 -0
- package/gs/math/j1.gs.ts +231 -0
- package/gs/math/jn.gs.test.ts +133 -0
- package/gs/math/jn.gs.ts +447 -0
- package/gs/math/ldexp.gs.test.ts +128 -0
- package/gs/math/ldexp.gs.ts +28 -0
- package/gs/math/lgamma.gs.test.ts +102 -0
- package/gs/math/lgamma.gs.ts +251 -0
- package/gs/math/log.gs.test.ts +40 -0
- package/gs/math/log.gs.ts +21 -0
- package/gs/math/log10.gs.test.ts +80 -0
- package/gs/math/log10.gs.ts +25 -0
- package/gs/math/log1p.gs.test.ts +55 -0
- package/gs/math/log1p.gs.ts +24 -0
- package/gs/math/logb.gs.test.ts +87 -0
- package/gs/math/logb.gs.ts +54 -0
- package/gs/math/mod.gs.test.ts +64 -0
- package/gs/math/mod.gs.ts +36 -0
- package/gs/math/modf.gs.test.ts +80 -0
- package/gs/math/modf.gs.ts +32 -0
- package/gs/math/nextafter.gs.test.ts +107 -0
- package/gs/math/nextafter.gs.ts +71 -0
- package/gs/math/pow.gs.test.ts +103 -0
- package/gs/math/pow.gs.ts +55 -0
- package/gs/math/pow10.gs.test.ts +58 -0
- package/gs/math/pow10.gs.ts +19 -0
- package/gs/math/remainder.gs.test.ts +70 -0
- package/gs/math/remainder.gs.ts +33 -0
- package/gs/math/signbit.gs.test.ts +33 -0
- package/gs/math/signbit.gs.ts +8 -0
- package/gs/math/sin.gs.test.ts +83 -0
- package/gs/math/sin.gs.ts +38 -0
- package/gs/math/sincos.gs.test.ts +91 -0
- package/gs/math/sincos.gs.ts +15 -0
- package/gs/math/sinh.gs.test.ts +66 -0
- package/gs/math/sinh.gs.ts +34 -0
- package/gs/math/sqrt.gs.test.ts +49 -0
- package/gs/math/sqrt.gs.ts +20 -0
- package/gs/math/tan.gs.test.ts +50 -0
- package/gs/math/tan.gs.ts +23 -0
- package/gs/math/tanh.gs.test.ts +52 -0
- package/gs/math/tanh.gs.ts +23 -0
- package/gs/math/trig_reduce.gs.ts +66 -0
- package/gs/math/unsafe.gs.ts +52 -0
- package/gs/strconv/atob.gs.ts +45 -0
- package/gs/strconv/atof.gs.ts +60 -0
- package/gs/strconv/atoi.gs.ts +243 -0
- package/gs/strconv/doc.gs.ts +2 -0
- package/gs/strconv/ftoa.gs.ts +66 -0
- package/gs/strconv/index.ts +6 -0
- package/gs/strconv/itoa.gs.ts +41 -0
- package/gs/strconv/quote.gs.ts +245 -0
- package/gs/strings/index.ts +4 -0
- package/gs/strings/replace.ts +9 -237
- package/gs/strings/search.ts +0 -28
- package/gs/sync/atomic/doc.gs.ts +276 -0
- package/gs/sync/atomic/doc_64.gs.ts +168 -0
- package/gs/sync/atomic/index.ts +4 -0
- package/gs/sync/atomic/type.gs.ts +596 -0
- package/gs/sync/atomic/value.gs.ts +158 -0
- package/gs/unsafe/unsafe.ts +6 -0
- package/package.json +1 -1
- package/gs/maps/iter.gs.ts +0 -71
- package/gs/maps/maps.gs.ts +0 -87
- package/gs/stringslite/godoc.txt +0 -17
- package/gs/stringslite/index.ts +0 -1
- package/gs/stringslite/strings.ts +0 -82
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import * as $ from "@goscript/builtin/builtin.js";
|
|
2
|
+
import { CompareAndSwapPointer, LoadPointer, StorePointer, SwapPointer } from "./doc.gs.js";
|
|
3
|
+
|
|
4
|
+
import * as unsafe from "@goscript/unsafe/index.js"
|
|
5
|
+
|
|
6
|
+
// Pointer type for use in efaceWords
|
|
7
|
+
type Pointer = any;
|
|
8
|
+
|
|
9
|
+
// firstStoreInProgress is a placeholder value used during the first store operation
|
|
10
|
+
const firstStoreInProgress = Symbol('firstStoreInProgress');
|
|
11
|
+
|
|
12
|
+
export class Value {
|
|
13
|
+
public get v(): null | any {
|
|
14
|
+
return this._fields.v.value
|
|
15
|
+
}
|
|
16
|
+
public set v(value: null | any) {
|
|
17
|
+
this._fields.v.value = value
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public _fields: {
|
|
21
|
+
v: $.VarRef<null | any>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
constructor(init?: Partial<{v?: null | any}>) {
|
|
25
|
+
this._fields = {
|
|
26
|
+
v: $.varRef(init?.v ?? null)
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public clone(): Value {
|
|
31
|
+
const cloned = new Value()
|
|
32
|
+
cloned._fields = {
|
|
33
|
+
v: $.varRef(this._fields.v.value)
|
|
34
|
+
}
|
|
35
|
+
return cloned
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Load returns the value set by the most recent Store.
|
|
39
|
+
// It returns nil if there has been no call to Store for this Value.
|
|
40
|
+
public Load(): null | any {
|
|
41
|
+
const v = this
|
|
42
|
+
// For JavaScript, we can simplify this since we're single-threaded
|
|
43
|
+
// Just return the stored value directly
|
|
44
|
+
return v._fields.v.value
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Store sets the value of the [Value] v to val.
|
|
48
|
+
// All calls to Store for a given Value must use values of the same concrete type.
|
|
49
|
+
// Store of an inconsistent type panics, as does Store(nil).
|
|
50
|
+
public Store(val: null | any): void {
|
|
51
|
+
const v = this
|
|
52
|
+
if (val == null) {
|
|
53
|
+
$.panic("sync/atomic: store of nil value into Value")
|
|
54
|
+
}
|
|
55
|
+
// For JavaScript, store the value directly
|
|
56
|
+
v._fields.v.value = val
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Swap stores new into Value and returns the previous value. It returns nil if
|
|
60
|
+
// the Value is empty.
|
|
61
|
+
//
|
|
62
|
+
// All calls to Swap for a given Value must use values of the same concrete
|
|
63
|
+
// type. Swap of an inconsistent type panics, as does Swap(nil).
|
|
64
|
+
public Swap(_new: null | any): null | any {
|
|
65
|
+
const v = this
|
|
66
|
+
if (_new == null) {
|
|
67
|
+
$.panic("sync/atomic: swap of nil value into Value")
|
|
68
|
+
}
|
|
69
|
+
// For JavaScript, swap the values directly
|
|
70
|
+
const old = v._fields.v.value
|
|
71
|
+
v._fields.v.value = _new
|
|
72
|
+
return old
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// CompareAndSwap executes the compare-and-swap operation for the [Value].
|
|
76
|
+
//
|
|
77
|
+
// All calls to CompareAndSwap for a given Value must use values of the same
|
|
78
|
+
// concrete type. CompareAndSwap of an inconsistent type panics, as does
|
|
79
|
+
// CompareAndSwap(old, nil).
|
|
80
|
+
public CompareAndSwap(old: null | any, _new: null | any): boolean {
|
|
81
|
+
const v = this
|
|
82
|
+
if (_new == null) {
|
|
83
|
+
$.panic("sync/atomic: compare and swap of nil value into Value")
|
|
84
|
+
}
|
|
85
|
+
// For JavaScript, compare and swap directly
|
|
86
|
+
if (v._fields.v.value === old) {
|
|
87
|
+
v._fields.v.value = _new
|
|
88
|
+
return true
|
|
89
|
+
}
|
|
90
|
+
return false
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Register this type with the runtime type system
|
|
94
|
+
static __typeInfo = $.registerStructType(
|
|
95
|
+
'Value',
|
|
96
|
+
new Value(),
|
|
97
|
+
[{ name: "Load", args: [], returns: [{ type: { kind: $.TypeKind.Interface, methods: [] } }] }, { name: "Store", args: [{ name: "val", type: { kind: $.TypeKind.Interface, methods: [] } }], returns: [] }, { name: "Swap", args: [{ name: "new", type: { kind: $.TypeKind.Interface, methods: [] } }], returns: [{ type: { kind: $.TypeKind.Interface, methods: [] } }] }, { name: "CompareAndSwap", args: [{ name: "old", type: { kind: $.TypeKind.Interface, methods: [] } }, { name: "new", type: { kind: $.TypeKind.Interface, methods: [] } }], returns: [{ type: { kind: $.TypeKind.Basic, name: "boolean" } }] }],
|
|
98
|
+
Value,
|
|
99
|
+
{"v": { kind: $.TypeKind.Interface, methods: [] }}
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
class efaceWords {
|
|
105
|
+
public get typ(): Pointer {
|
|
106
|
+
return this._fields.typ.value
|
|
107
|
+
}
|
|
108
|
+
public set typ(value: Pointer) {
|
|
109
|
+
this._fields.typ.value = value
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
public get data(): Pointer {
|
|
113
|
+
return this._fields.data.value
|
|
114
|
+
}
|
|
115
|
+
public set data(value: Pointer) {
|
|
116
|
+
this._fields.data.value = value
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
public _fields: {
|
|
120
|
+
typ: $.VarRef<Pointer>;
|
|
121
|
+
data: $.VarRef<Pointer>;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
constructor(init?: Partial<{data?: Pointer, typ?: Pointer}>) {
|
|
125
|
+
this._fields = {
|
|
126
|
+
typ: $.varRef(init?.typ ?? null),
|
|
127
|
+
data: $.varRef(init?.data ?? null)
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
public clone(): efaceWords {
|
|
132
|
+
const cloned = new efaceWords()
|
|
133
|
+
cloned._fields = {
|
|
134
|
+
typ: $.varRef(this._fields.typ.value),
|
|
135
|
+
data: $.varRef(this._fields.data.value)
|
|
136
|
+
}
|
|
137
|
+
return cloned
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Register this type with the runtime type system
|
|
141
|
+
static __typeInfo = $.registerStructType(
|
|
142
|
+
'efaceWords',
|
|
143
|
+
new efaceWords(),
|
|
144
|
+
[],
|
|
145
|
+
efaceWords,
|
|
146
|
+
{"data": { kind: $.TypeKind.Basic, name: "Pointer" }, "typ": { kind: $.TypeKind.Basic, name: "Pointer" }}
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// Runtime functions for pinning/unpinning (no-ops in JavaScript)
|
|
151
|
+
export function runtime_procPin(): number {
|
|
152
|
+
return 0; // No-op in JavaScript
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export function runtime_procUnpin(): void {
|
|
156
|
+
// No-op in JavaScript
|
|
157
|
+
}
|
|
158
|
+
|
package/gs/unsafe/unsafe.ts
CHANGED
|
@@ -75,3 +75,9 @@ export function StringData(_str: string): Pointer {
|
|
|
75
75
|
'unsafe.StringData is not supported in JavaScript/TypeScript: direct memory access is not available in JavaScript',
|
|
76
76
|
)
|
|
77
77
|
}
|
|
78
|
+
|
|
79
|
+
// Pointer converts a value to an unsafe.Pointer for atomic operations
|
|
80
|
+
// In JavaScript/TypeScript, this is just a pass-through function
|
|
81
|
+
export function Pointer(value: any): Pointer {
|
|
82
|
+
return value;
|
|
83
|
+
}
|
package/package.json
CHANGED
package/gs/maps/iter.gs.ts
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import * as $ from "@goscript/builtin/builtin.js";
|
|
2
|
-
|
|
3
|
-
import * as iter from "@goscript/iter/index.js"
|
|
4
|
-
|
|
5
|
-
// All returns an iterator over key-value pairs from m.
|
|
6
|
-
// The iteration order is not specified and is not guaranteed
|
|
7
|
-
// to be the same from one call to the next.
|
|
8
|
-
export function All<K extends $.Comparable, V>(m: Map<K, V>): iter.Seq2<K, V> {
|
|
9
|
-
return (_yield: ((p0: K, p1: V) => boolean) | null): void => {
|
|
10
|
-
for (const [k, v] of m.entries()) {
|
|
11
|
-
{
|
|
12
|
-
if (!_yield!(k, v)) {
|
|
13
|
-
return
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// Keys returns an iterator over keys in m.
|
|
21
|
-
// The iteration order is not specified and is not guaranteed
|
|
22
|
-
// to be the same from one call to the next.
|
|
23
|
-
export function Keys<K extends $.Comparable, V>(m: Map<K, V>): iter.Seq<K> {
|
|
24
|
-
return (_yield: ((p0: K) => boolean) | null): void => {
|
|
25
|
-
for (const [k, _v] of m.entries()) {
|
|
26
|
-
{
|
|
27
|
-
if (!_yield!(k)) {
|
|
28
|
-
return
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// Values returns an iterator over values in m.
|
|
36
|
-
// The iteration order is not specified and is not guaranteed
|
|
37
|
-
// to be the same from one call to the next.
|
|
38
|
-
export function Values<K extends $.Comparable, V>(m: Map<K, V>): iter.Seq<V> {
|
|
39
|
-
return (_yield: ((p0: V) => boolean) | null): void => {
|
|
40
|
-
for (const [_k, v] of m.entries()) {
|
|
41
|
-
{
|
|
42
|
-
if (!_yield!(v)) {
|
|
43
|
-
return
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// Insert adds the key-value pairs from seq to m.
|
|
51
|
-
// If a key in seq already exists in m, its value will be overwritten.
|
|
52
|
-
export function Insert<K extends $.Comparable, V>(m: Map<K, V>, seq: iter.Seq2<K, V>): void {
|
|
53
|
-
;(() => {
|
|
54
|
-
let shouldContinue = true
|
|
55
|
-
seq!((k, v) => {
|
|
56
|
-
{
|
|
57
|
-
$.mapSet(m, k, v)
|
|
58
|
-
}
|
|
59
|
-
return shouldContinue
|
|
60
|
-
})
|
|
61
|
-
})()
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// Collect collects key-value pairs from seq into a new map
|
|
65
|
-
// and returns it.
|
|
66
|
-
export function Collect<K extends $.Comparable, V extends any>(seq: iter.Seq2<K, V>): Map<K, V> {
|
|
67
|
-
let m = $.makeMap<K, V>()
|
|
68
|
-
Insert(m, seq)
|
|
69
|
-
return m
|
|
70
|
-
}
|
|
71
|
-
|
package/gs/maps/maps.gs.ts
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import * as $ from "@goscript/builtin/builtin.js";
|
|
2
|
-
|
|
3
|
-
import * as _ from "@goscript/unsafe/index.js"
|
|
4
|
-
|
|
5
|
-
// Equal reports whether two maps contain the same key/value pairs.
|
|
6
|
-
// Values are compared using ==.
|
|
7
|
-
export function Equal<K extends $.Comparable, V extends $.Comparable>(m1: Map<K, V>, m2: Map<K, V>): boolean {
|
|
8
|
-
if ($.len(m1) != $.len(m2)) {
|
|
9
|
-
return false
|
|
10
|
-
}
|
|
11
|
-
for (const [k, v1] of m1.entries()) {
|
|
12
|
-
{
|
|
13
|
-
{
|
|
14
|
-
let [v2, ok] = $.mapGet(m2, k, null as any)
|
|
15
|
-
if (!ok || v1 != v2) {
|
|
16
|
-
return false
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return true
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// EqualFunc is like Equal, but compares values using eq.
|
|
25
|
-
// Keys are still compared with ==.
|
|
26
|
-
export function EqualFunc<K extends $.Comparable, V1, V2>(m1: Map<K, V1>, m2: Map<K, V2>, eq: ((p0: V1, p1: V2) => boolean) | null): boolean {
|
|
27
|
-
if ($.len(m1) != $.len(m2)) {
|
|
28
|
-
return false
|
|
29
|
-
}
|
|
30
|
-
for (const [k, v1] of m1.entries()) {
|
|
31
|
-
{
|
|
32
|
-
{
|
|
33
|
-
let [v2, ok] = $.mapGet(m2, k, null as any)
|
|
34
|
-
if (!ok || !eq!(v1, v2)) {
|
|
35
|
-
return false
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return true
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// clone returns a shallow copy of the map.
|
|
44
|
-
export function clone<K extends $.Comparable, V>(m: Map<K, V> | null): Map<K, V> | null {
|
|
45
|
-
if (m == null) {
|
|
46
|
-
return null
|
|
47
|
-
}
|
|
48
|
-
const result = $.makeMap<K, V>()
|
|
49
|
-
for (const [k, v] of m.entries()) {
|
|
50
|
-
$.mapSet(result, k, v)
|
|
51
|
-
}
|
|
52
|
-
return result
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// Clone returns a copy of m. This is a shallow clone:
|
|
56
|
-
// the new keys and values are set using ordinary assignment.
|
|
57
|
-
export function Clone<K extends $.Comparable, V>(m: Map<K, V>): Map<K, V> {
|
|
58
|
-
// Preserve nil in case it matters.
|
|
59
|
-
if (m == null) {
|
|
60
|
-
return null as unknown as Map<K, V>
|
|
61
|
-
}
|
|
62
|
-
return clone(m)!
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// Copy copies all key/value pairs in src adding them to dst.
|
|
66
|
-
// When a key in src is already present in dst,
|
|
67
|
-
// the value in dst will be overwritten by the value associated
|
|
68
|
-
// with the key in src.
|
|
69
|
-
export function Copy<K extends $.Comparable, V>(dst: Map<K, V>, src: Map<K, V>): void {
|
|
70
|
-
for (const [k, v] of src.entries()) {
|
|
71
|
-
{
|
|
72
|
-
$.mapSet(dst, k, v)
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// DeleteFunc deletes any key/value pairs from m for which del returns true.
|
|
78
|
-
export function DeleteFunc<K extends $.Comparable, V>(m: Map<K, V>, del: ((p0: K, p1: V) => boolean) | null): void {
|
|
79
|
-
for (const [k, v] of m.entries()) {
|
|
80
|
-
{
|
|
81
|
-
if (del!(k, v)) {
|
|
82
|
-
$.deleteMapEntry(m, k)
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
package/gs/stringslite/godoc.txt
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
package stringslite // import "internal/stringslite"
|
|
2
|
-
|
|
3
|
-
Package stringslite implements a subset of strings, only using packages that may
|
|
4
|
-
be imported by "os".
|
|
5
|
-
|
|
6
|
-
Tests for these functions are in the strings package.
|
|
7
|
-
|
|
8
|
-
func Clone(s string) string
|
|
9
|
-
func Cut(s, sep string) (before, after string, found bool)
|
|
10
|
-
func CutPrefix(s, prefix string) (after string, found bool)
|
|
11
|
-
func CutSuffix(s, suffix string) (before string, found bool)
|
|
12
|
-
func HasPrefix(s, prefix string) bool
|
|
13
|
-
func HasSuffix(s, suffix string) bool
|
|
14
|
-
func Index(s, substr string) int
|
|
15
|
-
func IndexByte(s string, c byte) int
|
|
16
|
-
func TrimPrefix(s, prefix string) string
|
|
17
|
-
func TrimSuffix(s, suffix string) string
|
package/gs/stringslite/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './strings'
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import * as $ from '@goscript/builtin/builtin.js'
|
|
2
|
-
|
|
3
|
-
import * as unsafe from '@goscript/unsafe/index.js'
|
|
4
|
-
|
|
5
|
-
export function HasPrefix(s: string, prefix: string): boolean {
|
|
6
|
-
return (
|
|
7
|
-
$.len(s) >= $.len(prefix) &&
|
|
8
|
-
$.sliceString(s, undefined, $.len(prefix)) == prefix
|
|
9
|
-
)
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function HasSuffix(s: string, suffix: string): boolean {
|
|
13
|
-
return (
|
|
14
|
-
$.len(s) >= $.len(suffix) &&
|
|
15
|
-
$.sliceString(s, $.len(s) - $.len(suffix), undefined) == suffix
|
|
16
|
-
)
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function IndexByte(s: string, c: number): number {
|
|
20
|
-
const char = String.fromCharCode(c)
|
|
21
|
-
return s.indexOf(char)
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function Index(s: string, substr: string): number {
|
|
25
|
-
if (substr === '') {
|
|
26
|
-
return 0
|
|
27
|
-
}
|
|
28
|
-
return s.indexOf(substr)
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function Cut(s: string, sep: string): [string, string, boolean] {
|
|
32
|
-
let i = Index(s, sep)
|
|
33
|
-
if (i >= 0) {
|
|
34
|
-
return [
|
|
35
|
-
$.sliceString(s, undefined, i),
|
|
36
|
-
$.sliceString(s, i + $.len(sep), undefined),
|
|
37
|
-
true,
|
|
38
|
-
]
|
|
39
|
-
}
|
|
40
|
-
return [s, '', false]
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export function CutPrefix(s: string, prefix: string): [string, boolean] {
|
|
44
|
-
if (!HasPrefix(s, prefix)) {
|
|
45
|
-
return [s, false]
|
|
46
|
-
}
|
|
47
|
-
return [$.sliceString(s, $.len(prefix), undefined), true]
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export function CutSuffix(s: string, suffix: string): [string, boolean] {
|
|
51
|
-
if (!HasSuffix(s, suffix)) {
|
|
52
|
-
return [s, false]
|
|
53
|
-
}
|
|
54
|
-
return [$.sliceString(s, undefined, $.len(s) - $.len(suffix)), true]
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export function TrimPrefix(s: string, prefix: string): string {
|
|
58
|
-
if (HasPrefix(s, prefix)) {
|
|
59
|
-
return $.sliceString(s, $.len(prefix), undefined)
|
|
60
|
-
}
|
|
61
|
-
return s
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export function TrimSuffix(s: string, suffix: string): string {
|
|
65
|
-
if (HasSuffix(s, suffix)) {
|
|
66
|
-
return $.sliceString(s, undefined, $.len(s) - $.len(suffix))
|
|
67
|
-
}
|
|
68
|
-
return s
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export function Clone(s: string): string {
|
|
72
|
-
if ($.len(s) == 0) {
|
|
73
|
-
return ''
|
|
74
|
-
}
|
|
75
|
-
let b = new Uint8Array($.len(s))
|
|
76
|
-
$.copy(b, s)
|
|
77
|
-
return unsafe.String(b![0], $.len(b))
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export function CopyBytes(b: Uint8Array, s: string): number {
|
|
81
|
-
return $.copy(b, s)
|
|
82
|
-
}
|