goscript 0.0.35 → 0.0.37
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/expr-call.go +26 -0
- package/compiler/spec-struct.go +41 -8
- package/compiler/spec-value.go +4 -0
- package/compiler/spec.go +1 -1
- package/compiler/stmt.go +26 -8
- package/dist/gs/internal/byteorder/index.d.ts +8 -0
- package/dist/gs/internal/byteorder/index.js +34 -0
- package/dist/gs/internal/byteorder/index.js.map +1 -0
- package/dist/gs/internal/testlog/index.d.ts +1 -0
- package/dist/gs/internal/testlog/index.js +5 -0
- package/dist/gs/internal/testlog/index.js.map +1 -0
- package/dist/gs/maps/iter.d.ts +1 -1
- package/dist/gs/os/dir.gs.d.ts +6 -0
- package/dist/gs/os/dir.gs.js +35 -0
- package/dist/gs/os/dir.gs.js.map +1 -0
- package/dist/gs/os/dir_unix.gs.d.ts +7 -0
- package/dist/gs/os/dir_unix.gs.js +113 -0
- package/dist/gs/os/dir_unix.gs.js.map +1 -0
- package/dist/gs/os/dirent_js.gs.d.ts +5 -0
- package/dist/gs/os/dirent_js.gs.js +20 -0
- package/dist/gs/os/dirent_js.gs.js.map +1 -0
- package/dist/gs/os/env.gs.d.ts +12 -0
- package/dist/gs/os/env.gs.js +157 -0
- package/dist/gs/os/env.gs.js.map +1 -0
- package/dist/gs/os/error.gs.d.ts +40 -0
- package/dist/gs/os/error.gs.js +158 -0
- package/dist/gs/os/error.gs.js.map +1 -0
- package/dist/gs/os/error_errno.gs.d.ts +1 -0
- package/dist/gs/os/error_errno.gs.js +5 -0
- package/dist/gs/os/error_errno.gs.js.map +1 -0
- package/dist/gs/os/exec.gs.d.ts +60 -0
- package/dist/gs/os/exec.gs.js +136 -0
- package/dist/gs/os/exec.gs.js.map +1 -0
- package/dist/gs/os/exec_nohandle.gs.d.ts +1 -0
- package/dist/gs/os/exec_nohandle.gs.js +2 -0
- package/dist/gs/os/exec_nohandle.gs.js.map +1 -0
- package/dist/gs/os/exec_posix.gs.d.ts +25 -0
- package/dist/gs/os/exec_posix.gs.js +67 -0
- package/dist/gs/os/exec_posix.gs.js.map +1 -0
- package/dist/gs/os/exec_unix.gs.d.ts +4 -0
- package/dist/gs/os/exec_unix.gs.js +46 -0
- package/dist/gs/os/exec_unix.gs.js.map +1 -0
- package/dist/gs/os/executable.gs.d.ts +2 -0
- package/dist/gs/os/executable.gs.js +16 -0
- package/dist/gs/os/executable.gs.js.map +1 -0
- package/dist/gs/os/executable_js.gs.d.ts +2 -0
- package/dist/gs/os/executable_js.gs.js +5 -0
- package/dist/gs/os/executable_js.gs.js.map +1 -0
- package/dist/gs/os/executable_wasm.gs.d.ts +2 -0
- package/dist/gs/os/executable_wasm.gs.js +6 -0
- package/dist/gs/os/executable_wasm.gs.js.map +1 -0
- package/dist/gs/os/file_constants_js.gs.d.ts +41 -0
- package/dist/gs/os/file_constants_js.gs.js +78 -0
- package/dist/gs/os/file_constants_js.gs.js.map +1 -0
- package/dist/gs/os/file_js.gs.d.ts +22 -0
- package/dist/gs/os/file_js.gs.js +73 -0
- package/dist/gs/os/file_js.gs.js.map +1 -0
- package/dist/gs/os/file_open_unix.gs.d.ts +6 -0
- package/dist/gs/os/file_open_unix.gs.js +10 -0
- package/dist/gs/os/file_open_unix.gs.js.map +1 -0
- package/dist/gs/os/file_posix_js.gs.d.ts +8 -0
- package/dist/gs/os/file_posix_js.gs.js +32 -0
- package/dist/gs/os/file_posix_js.gs.js.map +1 -0
- package/dist/gs/os/file_unix_js.gs.d.ts +27 -0
- package/dist/gs/os/file_unix_js.gs.js +64 -0
- package/dist/gs/os/file_unix_js.gs.js.map +1 -0
- package/dist/gs/os/getwd_js.gs.d.ts +6 -0
- package/dist/gs/os/getwd_js.gs.js +21 -0
- package/dist/gs/os/getwd_js.gs.js.map +1 -0
- package/dist/gs/os/index.d.ts +19 -0
- package/dist/gs/os/index.js +20 -0
- package/dist/gs/os/index.js.map +1 -0
- package/dist/gs/os/path.gs.d.ts +4 -0
- package/dist/gs/os/path.gs.js +32 -0
- package/dist/gs/os/path.gs.js.map +1 -0
- package/dist/gs/os/path_unix.gs.d.ts +4 -0
- package/dist/gs/os/path_unix.gs.js +40 -0
- package/dist/gs/os/path_unix.gs.js.map +1 -0
- package/dist/gs/os/pidfd_js.gs.d.ts +6 -0
- package/dist/gs/os/pidfd_js.gs.js +14 -0
- package/dist/gs/os/pidfd_js.gs.js.map +1 -0
- package/dist/gs/os/pipe_wasm.gs.d.ts +2 -0
- package/dist/gs/os/pipe_wasm.gs.js +14 -0
- package/dist/gs/os/pipe_wasm.gs.js.map +1 -0
- package/dist/gs/os/proc.gs.d.ts +11 -0
- package/dist/gs/os/proc.gs.js +68 -0
- package/dist/gs/os/proc.gs.js.map +1 -0
- package/dist/gs/os/proc_js.gs.d.ts +3 -0
- package/dist/gs/os/proc_js.gs.js +12 -0
- package/dist/gs/os/proc_js.gs.js.map +1 -0
- package/dist/gs/os/rawconn_js.gs.d.ts +10 -0
- package/dist/gs/os/rawconn_js.gs.js +26 -0
- package/dist/gs/os/rawconn_js.gs.js.map +1 -0
- package/dist/gs/os/removeall_js.gs.d.ts +2 -0
- package/dist/gs/os/removeall_js.gs.js +7 -0
- package/dist/gs/os/removeall_js.gs.js.map +1 -0
- package/dist/gs/os/root_js.gs.d.ts +23 -0
- package/dist/gs/os/root_js.gs.js +80 -0
- package/dist/gs/os/root_js.gs.js.map +1 -0
- package/dist/gs/os/root_nonwindows.gs.d.ts +2 -0
- package/dist/gs/os/root_nonwindows.gs.js +4 -0
- package/dist/gs/os/root_nonwindows.gs.js.map +1 -0
- package/dist/gs/os/root_noopenat.gs.d.ts +11 -0
- package/dist/gs/os/root_noopenat.gs.js +31 -0
- package/dist/gs/os/root_noopenat.gs.js.map +1 -0
- package/dist/gs/os/stat.gs.d.ts +24 -0
- package/dist/gs/os/stat.gs.js +20 -0
- package/dist/gs/os/stat.gs.js.map +1 -0
- package/dist/gs/os/stat_js.gs.d.ts +6 -0
- package/dist/gs/os/stat_js.gs.js +23 -0
- package/dist/gs/os/stat_js.gs.js.map +1 -0
- package/dist/gs/os/stat_unix_js.gs.d.ts +8 -0
- package/dist/gs/os/stat_unix_js.gs.js +16 -0
- package/dist/gs/os/stat_unix_js.gs.js.map +1 -0
- package/dist/gs/os/sticky_bsd.gs.d.ts +1 -0
- package/dist/gs/os/sticky_bsd.gs.js +3 -0
- package/dist/gs/os/sticky_bsd.gs.js.map +1 -0
- package/dist/gs/os/sys.gs.d.ts +2 -0
- package/dist/gs/os/sys.gs.js +10 -0
- package/dist/gs/os/sys.gs.js.map +1 -0
- package/dist/gs/os/sys_bsd.gs.d.ts +2 -0
- package/dist/gs/os/sys_bsd.gs.js +15 -0
- package/dist/gs/os/sys_bsd.gs.js.map +1 -0
- package/dist/gs/os/sys_js.gs.d.ts +2 -0
- package/dist/gs/os/sys_js.gs.js +6 -0
- package/dist/gs/os/sys_js.gs.js.map +1 -0
- package/dist/gs/os/tempfile.gs.d.ts +5 -0
- package/dist/gs/os/tempfile.gs.js +30 -0
- package/dist/gs/os/tempfile.gs.js.map +1 -0
- package/dist/gs/os/types.gs.d.ts +59 -0
- package/dist/gs/os/types.gs.js +123 -0
- package/dist/gs/os/types.gs.js.map +1 -0
- package/dist/gs/os/types_js.gs.d.ts +74 -0
- package/dist/gs/os/types_js.gs.js +147 -0
- package/dist/gs/os/types_js.gs.js.map +1 -0
- package/dist/gs/os/types_unix.gs.d.ts +40 -0
- package/dist/gs/os/types_unix.gs.js +87 -0
- package/dist/gs/os/types_unix.gs.js.map +1 -0
- package/dist/gs/os/wait_unimp.gs.d.ts +1 -0
- package/dist/gs/os/wait_unimp.gs.js +2 -0
- package/dist/gs/os/wait_unimp.gs.js.map +1 -0
- package/dist/gs/os/zero_copy_posix.gs.d.ts +4 -0
- package/dist/gs/os/zero_copy_posix.gs.js +27 -0
- package/dist/gs/os/zero_copy_posix.gs.js.map +1 -0
- package/dist/gs/os/zero_copy_stub.gs.d.ts +1 -0
- package/dist/gs/os/zero_copy_stub.gs.js +2 -0
- package/dist/gs/os/zero_copy_stub.gs.js.map +1 -0
- 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/syscall/index.d.ts +80 -0
- package/dist/gs/syscall/index.js +163 -0
- package/dist/gs/syscall/index.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/internal/byteorder/index.ts +40 -0
- package/gs/internal/testlog/index.ts +7 -0
- 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/os/dir.gs.ts +42 -0
- package/gs/os/dir_unix.gs.ts +155 -0
- package/gs/os/dirent_js.gs.ts +27 -0
- package/gs/os/env.gs.ts +179 -0
- package/gs/os/error.gs.ts +205 -0
- package/gs/os/error_errno.gs.ts +12 -0
- package/gs/os/exec.gs.ts +198 -0
- package/gs/os/exec_nohandle.gs.ts +2 -0
- package/gs/os/exec_posix.gs.ts +95 -0
- package/gs/os/exec_unix.gs.ts +64 -0
- package/gs/os/executable.gs.ts +18 -0
- package/gs/os/executable_js.gs.ts +6 -0
- package/gs/os/executable_wasm.gs.ts +10 -0
- package/gs/os/file_constants_js.gs.ts +98 -0
- package/gs/os/file_js.gs.ts +99 -0
- package/gs/os/file_open_unix.gs.ts +15 -0
- package/gs/os/file_posix_js.gs.ts +40 -0
- package/gs/os/file_unix_js.gs.ts +94 -0
- package/gs/os/getwd_js.gs.ts +28 -0
- package/gs/os/index.ts +19 -0
- package/gs/os/path.gs.ts +35 -0
- package/gs/os/path_unix.gs.ts +49 -0
- package/gs/os/pidfd_js.gs.ts +25 -0
- package/gs/os/pipe_wasm.gs.ts +17 -0
- package/gs/os/proc.gs.ts +84 -0
- package/gs/os/proc_js.gs.ts +15 -0
- package/gs/os/rawconn_js.gs.ts +30 -0
- package/gs/os/removeall_js.gs.ts +9 -0
- package/gs/os/root_js.gs.ts +111 -0
- package/gs/os/root_nonwindows.gs.ts +6 -0
- package/gs/os/root_noopenat.gs.ts +45 -0
- package/gs/os/stat.gs.ts +38 -0
- package/gs/os/stat_js.gs.ts +30 -0
- package/gs/os/stat_unix_js.gs.ts +27 -0
- package/gs/os/sticky_bsd.gs.ts +4 -0
- package/gs/os/sys.gs.ts +12 -0
- package/gs/os/sys_bsd.gs.ts +17 -0
- package/gs/os/sys_js.gs.ts +9 -0
- package/gs/os/tempfile.gs.ts +34 -0
- package/gs/os/types.gs.ts +170 -0
- package/gs/os/types_js.gs.ts +205 -0
- package/gs/os/types_unix.gs.ts +118 -0
- package/gs/os/wait_unimp.gs.ts +2 -0
- package/gs/os/zero_copy_posix.gs.ts +35 -0
- package/gs/os/zero_copy_stub.gs.ts +4 -0
- 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/syscall/index.ts +204 -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
|
+
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import * as $ from "@goscript/builtin/builtin.js";
|
|
2
|
+
|
|
3
|
+
// Essential type aliases
|
|
4
|
+
export type uintptr = number
|
|
5
|
+
|
|
6
|
+
// Errno type for syscall errors
|
|
7
|
+
export interface Errno {
|
|
8
|
+
Error(): string
|
|
9
|
+
Is(target: $.GoError): boolean
|
|
10
|
+
Errno(): number
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// Essential syscall constants
|
|
14
|
+
export const O_RDONLY = 0
|
|
15
|
+
export const O_WRONLY = 1
|
|
16
|
+
export const O_RDWR = 2
|
|
17
|
+
export const O_APPEND = 8
|
|
18
|
+
export const O_CREATE = 64
|
|
19
|
+
export const O_EXCL = 128
|
|
20
|
+
export const O_SYNC = 256
|
|
21
|
+
export const O_TRUNC = 512
|
|
22
|
+
|
|
23
|
+
export const Stdin = 0
|
|
24
|
+
export const Stdout = 1
|
|
25
|
+
export const Stderr = 2
|
|
26
|
+
|
|
27
|
+
export const SIGINT = 2
|
|
28
|
+
export const SIGTERM = 15
|
|
29
|
+
|
|
30
|
+
// File mode constants
|
|
31
|
+
export const S_IFMT = 0o170000
|
|
32
|
+
export const S_IFREG = 0o100000
|
|
33
|
+
export const S_IFDIR = 0o040000
|
|
34
|
+
export const S_IFLNK = 0o120000
|
|
35
|
+
export const S_IFBLK = 0o060000
|
|
36
|
+
export const S_IFCHR = 0o020000
|
|
37
|
+
export const S_IFIFO = 0o010000
|
|
38
|
+
export const S_IFSOCK = 0o140000
|
|
39
|
+
export const S_ISUID = 0o004000
|
|
40
|
+
export const S_ISGID = 0o002000
|
|
41
|
+
export const S_ISVTX = 0o001000
|
|
42
|
+
|
|
43
|
+
// Environment variable functions using Node.js/browser APIs
|
|
44
|
+
export function Getenv(key: string): [string, boolean] {
|
|
45
|
+
if (typeof process !== 'undefined' && process.env) {
|
|
46
|
+
const value = process.env[key]
|
|
47
|
+
return value !== undefined ? [value, true] : ["", false]
|
|
48
|
+
}
|
|
49
|
+
return ["", false]
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function Setenv(key: string, value: string): $.GoError {
|
|
53
|
+
if (typeof process !== 'undefined' && process.env) {
|
|
54
|
+
process.env[key] = value
|
|
55
|
+
return null
|
|
56
|
+
}
|
|
57
|
+
return { Error: () => "setenv not supported" }
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function Unsetenv(key: string): $.GoError {
|
|
61
|
+
if (typeof process !== 'undefined' && process.env) {
|
|
62
|
+
delete process.env[key]
|
|
63
|
+
return null
|
|
64
|
+
}
|
|
65
|
+
return { Error: () => "unsetenv not supported" }
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function Clearenv(): void {
|
|
69
|
+
if (typeof process !== 'undefined' && process.env) {
|
|
70
|
+
for (const key in process.env) {
|
|
71
|
+
delete process.env[key]
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function Environ(): $.Slice<string> {
|
|
77
|
+
if (typeof process !== 'undefined' && process.env) {
|
|
78
|
+
const env: string[] = []
|
|
79
|
+
for (const [key, value] of Object.entries(process.env)) {
|
|
80
|
+
if (value !== undefined) {
|
|
81
|
+
env.push(`${key}=${value}`)
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return $.arrayToSlice(env)
|
|
85
|
+
}
|
|
86
|
+
return $.arrayToSlice([])
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Dirent structure with Reclen field
|
|
90
|
+
export class Dirent {
|
|
91
|
+
public Name: $.Bytes = new Uint8Array(0)
|
|
92
|
+
public Reclen: number = 0
|
|
93
|
+
constructor(init?: any) {
|
|
94
|
+
if (init?.Name) this.Name = init.Name
|
|
95
|
+
if (init?.Reclen) this.Reclen = init.Reclen
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Stat_t structure stub
|
|
100
|
+
export class Stat_t {
|
|
101
|
+
public Dev: number = 0
|
|
102
|
+
public Ino: number = 0
|
|
103
|
+
public Mode: number = 0
|
|
104
|
+
public Nlink: number = 0
|
|
105
|
+
public Uid: number = 0
|
|
106
|
+
public Gid: number = 0
|
|
107
|
+
public Rdev: number = 0
|
|
108
|
+
public Size: number = 0
|
|
109
|
+
public Blksize: number = 0
|
|
110
|
+
public Blocks: number = 0
|
|
111
|
+
public Atime: number = 0
|
|
112
|
+
public Mtime: number = 0
|
|
113
|
+
public Ctime: number = 0
|
|
114
|
+
public AtimeNsec: number = 0
|
|
115
|
+
public MtimeNsec: number = 0
|
|
116
|
+
public CtimeNsec: number = 0
|
|
117
|
+
|
|
118
|
+
constructor(init?: any) {
|
|
119
|
+
if (init) {
|
|
120
|
+
Object.assign(this, init)
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
public clone(): Stat_t {
|
|
125
|
+
return new Stat_t(this)
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// RawConn interface - stub implementation for JavaScript environment
|
|
130
|
+
export interface RawConn {
|
|
131
|
+
Control(f: (fd: uintptr) => void): $.GoError
|
|
132
|
+
Read(f: (fd: uintptr) => boolean): $.GoError
|
|
133
|
+
Write(f: (fd: uintptr) => boolean): $.GoError
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Stub implementation of RawConn that always returns ErrUnimplemented
|
|
137
|
+
export class StubRawConn implements RawConn {
|
|
138
|
+
Control(f: (fd: uintptr) => void): $.GoError {
|
|
139
|
+
return { Error: () => "operation not implemented in JavaScript environment" }
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
Read(f: (fd: uintptr) => boolean): $.GoError {
|
|
143
|
+
return { Error: () => "operation not implemented in JavaScript environment" }
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
Write(f: (fd: uintptr) => boolean): $.GoError {
|
|
147
|
+
return { Error: () => "operation not implemented in JavaScript environment" }
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Additional error constants - implement as Errno type
|
|
152
|
+
export const ENOSYS: Errno = {
|
|
153
|
+
Error: () => "function not implemented",
|
|
154
|
+
Is: (target: $.GoError) => target === ENOSYS,
|
|
155
|
+
Errno: () => 38
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export const EISDIR: Errno = {
|
|
159
|
+
Error: () => "is a directory",
|
|
160
|
+
Is: (target: $.GoError) => target === EISDIR,
|
|
161
|
+
Errno: () => 21
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export const ENOTDIR: Errno = {
|
|
165
|
+
Error: () => "not a directory",
|
|
166
|
+
Is: (target: $.GoError) => target === ENOTDIR,
|
|
167
|
+
Errno: () => 20
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export const ERANGE: Errno = {
|
|
171
|
+
Error: () => "result too large",
|
|
172
|
+
Is: (target: $.GoError) => target === ERANGE,
|
|
173
|
+
Errno: () => 34
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export const ENOMEM: Errno = {
|
|
177
|
+
Error: () => "out of memory",
|
|
178
|
+
Is: (target: $.GoError) => target === ENOMEM,
|
|
179
|
+
Errno: () => 12
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export const ESRCH: Errno = {
|
|
183
|
+
Error: () => "no such process",
|
|
184
|
+
Is: (target: $.GoError) => target === ESRCH,
|
|
185
|
+
Errno: () => 3
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// Additional missing syscall functions
|
|
189
|
+
export function Open(path: string, flag: number, perm: number): [number, $.GoError] {
|
|
190
|
+
return [-1, ENOSYS]
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export function Sysctl(name: string): [string, $.GoError] {
|
|
194
|
+
return ["", ENOSYS]
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
// Getpagesize returns the underlying system's memory page size.
|
|
200
|
+
export function Getpagesize(): number {
|
|
201
|
+
// Return a standard page size for JavaScript environment
|
|
202
|
+
// Most systems use 4096 bytes as the default page size
|
|
203
|
+
return 4096
|
|
204
|
+
}
|
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
|
+
}
|