goscript 0.0.35 → 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/spec-struct.go +41 -8
- package/compiler/spec-value.go +4 -0
- package/dist/gs/maps/iter.d.ts +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/maps/iter.ts +1 -1
- package/gs/math/erfinv.gs.test.ts +2 -2
- package/gs/math/fma.gs.test.ts +5 -5
- package/gs/math/ldexp.gs.test.ts +5 -5
- package/gs/math/lgamma.gs.test.ts +2 -2
- 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
|
@@ -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
|
+
}
|