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.
@@ -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
+
@@ -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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "goscript",
3
3
  "description": "Go to TypeScript transpiler",
4
- "version": "0.0.35",
4
+ "version": "0.0.36",
5
5
  "author": {
6
6
  "name": "Aperture Robotics LLC.",
7
7
  "email": "support@aperture.us",