goscript 0.0.50 → 0.0.51

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.
Files changed (41) hide show
  1. package/compiler/analysis.go +18 -4
  2. package/compiler/compiler.go +8 -4
  3. package/compiler/expr-call-async.go +218 -13
  4. package/compiler/sanitize.go +1 -2
  5. package/compiler/spec-struct.go +3 -3
  6. package/compiler/spec.go +0 -21
  7. package/compiler/stmt-select.go +52 -1
  8. package/compiler/type.go +3 -3
  9. package/dist/gs/builtin/channel.d.ts +2 -2
  10. package/dist/gs/builtin/channel.js +12 -7
  11. package/dist/gs/builtin/channel.js.map +1 -1
  12. package/dist/gs/syscall/constants.d.ts +24 -0
  13. package/dist/gs/syscall/constants.js +27 -0
  14. package/dist/gs/syscall/constants.js.map +1 -0
  15. package/dist/gs/syscall/env.d.ts +6 -0
  16. package/dist/gs/syscall/env.js +43 -0
  17. package/dist/gs/syscall/env.js.map +1 -0
  18. package/dist/gs/syscall/errors.d.ts +111 -0
  19. package/dist/gs/syscall/errors.js +547 -0
  20. package/dist/gs/syscall/errors.js.map +1 -0
  21. package/dist/gs/syscall/fs.d.ts +29 -0
  22. package/dist/gs/syscall/fs.js +53 -0
  23. package/dist/gs/syscall/fs.js.map +1 -0
  24. package/dist/gs/syscall/index.d.ts +6 -80
  25. package/dist/gs/syscall/index.js +12 -168
  26. package/dist/gs/syscall/index.js.map +1 -1
  27. package/dist/gs/syscall/rawconn.d.ts +7 -0
  28. package/dist/gs/syscall/rawconn.js +19 -0
  29. package/dist/gs/syscall/rawconn.js.map +1 -0
  30. package/dist/gs/syscall/types.d.ts +12 -0
  31. package/dist/gs/syscall/types.js +2 -0
  32. package/dist/gs/syscall/types.js.map +1 -0
  33. package/gs/builtin/channel.ts +18 -12
  34. package/gs/syscall/constants.ts +29 -0
  35. package/gs/syscall/env.ts +47 -0
  36. package/gs/syscall/errors.ts +658 -0
  37. package/gs/syscall/fs.ts +62 -0
  38. package/gs/syscall/index.ts +12 -207
  39. package/gs/syscall/rawconn.ts +23 -0
  40. package/gs/syscall/types.ts +18 -0
  41. package/package.json +1 -1
@@ -1,80 +1,6 @@
1
- import * as $ from '@goscript/builtin/index.js';
2
- export type uintptr = number;
3
- export interface Errno {
4
- Error(): string;
5
- Is(target: $.GoError): boolean;
6
- Errno(): number;
7
- }
8
- export declare const O_RDONLY = 0;
9
- export declare const O_WRONLY = 1;
10
- export declare const O_RDWR = 2;
11
- export declare const O_APPEND = 8;
12
- export declare const O_CREATE = 64;
13
- export declare const O_EXCL = 128;
14
- export declare const O_SYNC = 256;
15
- export declare const O_TRUNC = 512;
16
- export declare const Stdin = 0;
17
- export declare const Stdout = 1;
18
- export declare const Stderr = 2;
19
- export declare const SIGINT = 2;
20
- export declare const SIGTERM = 15;
21
- export declare const S_IFMT = 61440;
22
- export declare const S_IFREG = 32768;
23
- export declare const S_IFDIR = 16384;
24
- export declare const S_IFLNK = 40960;
25
- export declare const S_IFBLK = 24576;
26
- export declare const S_IFCHR = 8192;
27
- export declare const S_IFIFO = 4096;
28
- export declare const S_IFSOCK = 49152;
29
- export declare const S_ISUID = 2048;
30
- export declare const S_ISGID = 1024;
31
- export declare const S_ISVTX = 512;
32
- export declare function Getenv(key: string): [string, boolean];
33
- export declare function Setenv(key: string, value: string): $.GoError;
34
- export declare function Unsetenv(key: string): $.GoError;
35
- export declare function Clearenv(): void;
36
- export declare function Environ(): $.Slice<string>;
37
- export declare class Dirent {
38
- Name: $.Bytes;
39
- Reclen: number;
40
- constructor(init?: any);
41
- }
42
- export declare class Stat_t {
43
- Dev: number;
44
- Ino: number;
45
- Mode: number;
46
- Nlink: number;
47
- Uid: number;
48
- Gid: number;
49
- Rdev: number;
50
- Size: number;
51
- Blksize: number;
52
- Blocks: number;
53
- Atime: number;
54
- Mtime: number;
55
- Ctime: number;
56
- AtimeNsec: number;
57
- MtimeNsec: number;
58
- CtimeNsec: number;
59
- constructor(init?: any);
60
- clone(): Stat_t;
61
- }
62
- export interface RawConn {
63
- Control(f: (fd: uintptr) => void): $.GoError;
64
- Read(f: (fd: uintptr) => boolean): $.GoError;
65
- Write(f: (fd: uintptr) => boolean): $.GoError;
66
- }
67
- export declare class StubRawConn implements RawConn {
68
- Control(_f: (fd: uintptr) => void): $.GoError;
69
- Read(_f: (fd: uintptr) => boolean): $.GoError;
70
- Write(_f: (fd: uintptr) => boolean): $.GoError;
71
- }
72
- export declare const ENOSYS: Errno;
73
- export declare const EISDIR: Errno;
74
- export declare const ENOTDIR: Errno;
75
- export declare const ERANGE: Errno;
76
- export declare const ENOMEM: Errno;
77
- export declare const ESRCH: Errno;
78
- export declare function Open(_path: string, _flag: number, _perm: number): [number, $.GoError];
79
- export declare function Sysctl(_name: string): [string, $.GoError];
80
- export declare function Getpagesize(): number;
1
+ export * from './types.js';
2
+ export * from './constants.js';
3
+ export * from './env.js';
4
+ export * from './fs.js';
5
+ export * from './errors.js';
6
+ export * from './rawconn.js';
@@ -1,169 +1,13 @@
1
- import * as $ from '@goscript/builtin/index.js';
2
- // Essential syscall constants
3
- export const O_RDONLY = 0;
4
- export const O_WRONLY = 1;
5
- export const O_RDWR = 2;
6
- export const O_APPEND = 8;
7
- export const O_CREATE = 64;
8
- export const O_EXCL = 128;
9
- export const O_SYNC = 256;
10
- export const O_TRUNC = 512;
11
- export const Stdin = 0;
12
- export const Stdout = 1;
13
- export const Stderr = 2;
14
- export const SIGINT = 2;
15
- export const SIGTERM = 15;
16
- // File mode constants
17
- export const S_IFMT = 0o170000;
18
- export const S_IFREG = 0o100000;
19
- export const S_IFDIR = 0o040000;
20
- export const S_IFLNK = 0o120000;
21
- export const S_IFBLK = 0o060000;
22
- export const S_IFCHR = 0o020000;
23
- export const S_IFIFO = 0o010000;
24
- export const S_IFSOCK = 0o140000;
25
- export const S_ISUID = 0o004000;
26
- export const S_ISGID = 0o002000;
27
- export const S_ISVTX = 0o001000;
28
- // Environment variable functions using Node.js/browser APIs
29
- export function Getenv(key) {
30
- if (typeof process !== 'undefined' && process.env) {
31
- const value = process.env[key];
32
- return value !== undefined ? [value, true] : ['', false];
33
- }
34
- return ['', false];
35
- }
36
- export function Setenv(key, value) {
37
- if (typeof process !== 'undefined' && process.env) {
38
- process.env[key] = value;
39
- return null;
40
- }
41
- return { Error: () => 'setenv not supported' };
42
- }
43
- export function Unsetenv(key) {
44
- if (typeof process !== 'undefined' && process.env) {
45
- delete process.env[key];
46
- return null;
47
- }
48
- return { Error: () => 'unsetenv not supported' };
49
- }
50
- export function Clearenv() {
51
- if (typeof process !== 'undefined' && process.env) {
52
- for (const key in process.env) {
53
- delete process.env[key];
54
- }
55
- }
56
- }
57
- export function Environ() {
58
- if (typeof process !== 'undefined' && process.env) {
59
- const env = [];
60
- for (const [key, value] of Object.entries(process.env)) {
61
- if (value !== undefined) {
62
- env.push(`${key}=${value}`);
63
- }
64
- }
65
- return $.arrayToSlice(env);
66
- }
67
- return $.arrayToSlice([]);
68
- }
69
- // Dirent structure with Reclen field
70
- export class Dirent {
71
- Name = new Uint8Array(0);
72
- Reclen = 0;
73
- constructor(init) {
74
- if (init?.Name)
75
- this.Name = init.Name;
76
- if (init?.Reclen)
77
- this.Reclen = init.Reclen;
78
- }
79
- }
80
- // Stat_t structure stub
81
- export class Stat_t {
82
- Dev = 0;
83
- Ino = 0;
84
- Mode = 0;
85
- Nlink = 0;
86
- Uid = 0;
87
- Gid = 0;
88
- Rdev = 0;
89
- Size = 0;
90
- Blksize = 0;
91
- Blocks = 0;
92
- Atime = 0;
93
- Mtime = 0;
94
- Ctime = 0;
95
- AtimeNsec = 0;
96
- MtimeNsec = 0;
97
- CtimeNsec = 0;
98
- constructor(init) {
99
- if (init) {
100
- Object.assign(this, init);
101
- }
102
- }
103
- clone() {
104
- return new Stat_t(this);
105
- }
106
- }
107
- // Stub implementation of RawConn that always returns ErrUnimplemented
108
- export class StubRawConn {
109
- Control(_f) {
110
- return {
111
- Error: () => 'operation not implemented in JavaScript environment',
112
- };
113
- }
114
- Read(_f) {
115
- return {
116
- Error: () => 'operation not implemented in JavaScript environment',
117
- };
118
- }
119
- Write(_f) {
120
- return {
121
- Error: () => 'operation not implemented in JavaScript environment',
122
- };
123
- }
124
- }
125
- // Additional error constants - implement as Errno type
126
- export const ENOSYS = {
127
- Error: () => 'function not implemented',
128
- Is: (target) => target === ENOSYS,
129
- Errno: () => 38,
130
- };
131
- export const EISDIR = {
132
- Error: () => 'is a directory',
133
- Is: (target) => target === EISDIR,
134
- Errno: () => 21,
135
- };
136
- export const ENOTDIR = {
137
- Error: () => 'not a directory',
138
- Is: (target) => target === ENOTDIR,
139
- Errno: () => 20,
140
- };
141
- export const ERANGE = {
142
- Error: () => 'result too large',
143
- Is: (target) => target === ERANGE,
144
- Errno: () => 34,
145
- };
146
- export const ENOMEM = {
147
- Error: () => 'out of memory',
148
- Is: (target) => target === ENOMEM,
149
- Errno: () => 12,
150
- };
151
- export const ESRCH = {
152
- Error: () => 'no such process',
153
- Is: (target) => target === ESRCH,
154
- Errno: () => 3,
155
- };
156
- // Additional missing syscall functions
157
- export function Open(_path, _flag, _perm) {
158
- return [-1, ENOSYS];
159
- }
160
- export function Sysctl(_name) {
161
- return ['', ENOSYS];
162
- }
163
- // Getpagesize returns the underlying system's memory page size.
164
- export function Getpagesize() {
165
- // Return a standard page size for JavaScript environment
166
- // Most systems use 4096 bytes as the default page size
167
- return 4096;
168
- }
1
+ // Re-export all types
2
+ export * from './types.js';
3
+ // Re-export all constants
4
+ export * from './constants.js';
5
+ // Re-export environment functions
6
+ export * from './env.js';
7
+ // Re-export file system structures and functions
8
+ export * from './fs.js';
9
+ // Re-export error constants
10
+ export * from './errors.js';
11
+ // Re-export RawConn implementation
12
+ export * from './rawconn.js';
169
13
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../gs/syscall/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,4BAA4B,CAAA;AAY/C,8BAA8B;AAC9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,aAAa,CAAA;AAE3B,mCAAmC;AACnC,cAAc,cAAc,CAAA"}
@@ -0,0 +1,7 @@
1
+ import * as $ from '@goscript/builtin/index.js';
2
+ import { RawConn, uintptr } from './types.js';
3
+ export declare class StubRawConn implements RawConn {
4
+ Control(_f: (fd: uintptr) => void): $.GoError;
5
+ Read(_f: (fd: uintptr) => boolean): $.GoError;
6
+ Write(_f: (fd: uintptr) => boolean): $.GoError;
7
+ }
@@ -0,0 +1,19 @@
1
+ // Stub implementation of RawConn that always returns ErrUnimplemented
2
+ export class StubRawConn {
3
+ Control(_f) {
4
+ return {
5
+ Error: () => 'operation not implemented in JavaScript environment',
6
+ };
7
+ }
8
+ Read(_f) {
9
+ return {
10
+ Error: () => 'operation not implemented in JavaScript environment',
11
+ };
12
+ }
13
+ Write(_f) {
14
+ return {
15
+ Error: () => 'operation not implemented in JavaScript environment',
16
+ };
17
+ }
18
+ }
19
+ //# sourceMappingURL=rawconn.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rawconn.js","sourceRoot":"","sources":["../../../gs/syscall/rawconn.ts"],"names":[],"mappings":"AAGA,sEAAsE;AACtE,MAAM,OAAO,WAAW;IACtB,OAAO,CAAC,EAAyB;QAC/B,OAAO;YACL,KAAK,EAAE,GAAG,EAAE,CAAC,qDAAqD;SACnE,CAAA;IACH,CAAC;IAED,IAAI,CAAC,EAA4B;QAC/B,OAAO;YACL,KAAK,EAAE,GAAG,EAAE,CAAC,qDAAqD;SACnE,CAAA;IACH,CAAC;IAED,KAAK,CAAC,EAA4B;QAChC,OAAO;YACL,KAAK,EAAE,GAAG,EAAE,CAAC,qDAAqD;SACnE,CAAA;IACH,CAAC;CACF"}
@@ -0,0 +1,12 @@
1
+ import * as $ from '@goscript/builtin/index.js';
2
+ export type uintptr = number;
3
+ export interface Errno {
4
+ Error(): string;
5
+ Is(target: $.GoError): boolean;
6
+ Errno(): number;
7
+ }
8
+ export interface RawConn {
9
+ Control(f: (fd: uintptr) => void): $.GoError;
10
+ Read(f: (fd: uintptr) => boolean): $.GoError;
11
+ Write(f: (fd: uintptr) => boolean): $.GoError;
12
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../gs/syscall/types.ts"],"names":[],"mappings":""}
@@ -88,7 +88,7 @@ export interface SelectCase<T> {
88
88
  channel: Channel<any> | ChannelRef<any> | null // Allow null and ChannelRef
89
89
  value?: any // Value to send for send cases
90
90
  // Optional handlers for when this case is selected
91
- onSelected?: (result: SelectResult<T>) => Promise<void>
91
+ onSelected?: (result: SelectResult<T>) => Promise<any>
92
92
  }
93
93
 
94
94
  /**
@@ -99,14 +99,14 @@ export interface SelectCase<T> {
99
99
  * @param hasDefault Whether there is a default case
100
100
  * @returns A promise that resolves with the result of the selected case
101
101
  */
102
- export async function selectStatement<T>(
102
+ export async function selectStatement<T, V=void>(
103
103
  cases: SelectCase<T>[],
104
104
  hasDefault: boolean = false,
105
- ): Promise<void> {
105
+ ): Promise<[boolean, V]> {
106
106
  if (cases.length === 0 && !hasDefault) {
107
107
  // Go spec: If there are no cases, the select statement blocks forever.
108
108
  // Emulate blocking forever with a promise that never resolves.
109
- return new Promise<void>(() => {}) // Promise never resolves
109
+ return new Promise<[boolean, V]>(() => {}) // Promise never resolves
110
110
  }
111
111
 
112
112
  // 1. Check for ready (non-blocking) operations
@@ -143,19 +143,21 @@ export async function selectStatement<T>(
143
143
  selectedCase.id,
144
144
  )
145
145
  if (selectedCase.onSelected) {
146
- await selectedCase.onSelected(result as SelectResult<T>) // Await the handler
146
+ const handlerResult = await selectedCase.onSelected(result as SelectResult<T>)
147
+ return [handlerResult !== undefined, handlerResult as V]
147
148
  }
148
149
  } else {
149
150
  const result = await selectedCase.channel.selectReceive(selectedCase.id)
150
151
  if (selectedCase.onSelected) {
151
- await selectedCase.onSelected(result) // Await the handler
152
+ const handlerResult = await selectedCase.onSelected(result)
153
+ return [handlerResult !== undefined, handlerResult as V]
152
154
  }
153
155
  }
154
156
  } else {
155
157
  // This case should ideally not happen if channel is required for non-default cases
156
158
  console.error('Selected case without a channel:', selectedCase)
157
159
  }
158
- return // Return after executing a ready case
160
+ return [false, undefined as V] // Return after executing a ready case
159
161
  }
160
162
 
161
163
  // 2. If no operations are ready and there's a default case, select default
@@ -164,13 +166,14 @@ export async function selectStatement<T>(
164
166
  const defaultCase = cases.find((c) => c.id === -1)
165
167
  if (defaultCase && defaultCase.onSelected) {
166
168
  // Execute the onSelected handler for the default case
167
- await defaultCase.onSelected({
169
+ const handlerResult = await defaultCase.onSelected({
168
170
  value: undefined,
169
171
  ok: false,
170
172
  id: -1,
171
- } as SelectResult<T>) // Await the handler
173
+ } as SelectResult<T>)
174
+ return [handlerResult !== undefined, handlerResult as V]
172
175
  }
173
- return // Return after executing the default case
176
+ return [false, undefined as V] // Return after executing the default case
174
177
  }
175
178
 
176
179
  // 3. If no operations are ready and no default case, block until one is ready
@@ -190,16 +193,19 @@ export async function selectStatement<T>(
190
193
  // If all non-default cases have nil channels, we effectively block forever
191
194
  if (blockingPromises.length === 0) {
192
195
  // No valid channels to operate on, block forever (unless there's a default)
193
- return new Promise<void>(() => {}) // Promise never resolves
196
+ return new Promise<[boolean, V]>(() => {}) // Promise never resolves
194
197
  }
195
198
 
196
199
  const result = await Promise.race(blockingPromises)
197
200
  // Execute onSelected handler for the selected case
198
201
  const selectedCase = cases.find((c) => c.id === result.id)
199
202
  if (selectedCase && selectedCase.onSelected) {
200
- await selectedCase.onSelected(result) // Await the handler
203
+ const handlerResult = await selectedCase.onSelected(result)
204
+ return [handlerResult !== undefined, handlerResult as V]
201
205
  }
206
+
202
207
  // No explicit return needed here, as the function will implicitly return after the await
208
+ return [false, undefined as V]
203
209
  }
204
210
 
205
211
  /**
@@ -0,0 +1,29 @@
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
10
+
11
+ export const Stdin = 0
12
+ export const Stdout = 1
13
+ export const Stderr = 2
14
+
15
+ export const SIGINT = 2
16
+ export const SIGTERM = 15
17
+
18
+ // 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
@@ -0,0 +1,47 @@
1
+ import * as $ from '@goscript/builtin/index.js'
2
+
3
+ // Environment variable functions using Node.js/browser APIs
4
+ export function Getenv(key: string): [string, boolean] {
5
+ if (typeof process !== 'undefined' && process.env) {
6
+ const value = process.env[key]
7
+ return value !== undefined ? [value, true] : ['', false]
8
+ }
9
+ return ['', false]
10
+ }
11
+
12
+ export function Setenv(key: string, value: string): $.GoError {
13
+ if (typeof process !== 'undefined' && process.env) {
14
+ process.env[key] = value
15
+ return null
16
+ }
17
+ return { Error: () => 'setenv not supported' }
18
+ }
19
+
20
+ export function Unsetenv(key: string): $.GoError {
21
+ if (typeof process !== 'undefined' && process.env) {
22
+ delete process.env[key]
23
+ return null
24
+ }
25
+ return { Error: () => 'unsetenv not supported' }
26
+ }
27
+
28
+ export function Clearenv(): void {
29
+ if (typeof process !== 'undefined' && process.env) {
30
+ for (const key in process.env) {
31
+ delete process.env[key]
32
+ }
33
+ }
34
+ }
35
+
36
+ export function Environ(): $.Slice<string> {
37
+ if (typeof process !== 'undefined' && process.env) {
38
+ const env: string[] = []
39
+ for (const [key, value] of Object.entries(process.env)) {
40
+ if (value !== undefined) {
41
+ env.push(`${key}=${value}`)
42
+ }
43
+ }
44
+ return $.arrayToSlice(env)
45
+ }
46
+ return $.arrayToSlice([])
47
+ }