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.
Files changed (228) hide show
  1. package/compiler/expr-call.go +26 -0
  2. package/compiler/spec-struct.go +41 -8
  3. package/compiler/spec-value.go +4 -0
  4. package/compiler/spec.go +1 -1
  5. package/compiler/stmt.go +26 -8
  6. package/dist/gs/internal/byteorder/index.d.ts +8 -0
  7. package/dist/gs/internal/byteorder/index.js +34 -0
  8. package/dist/gs/internal/byteorder/index.js.map +1 -0
  9. package/dist/gs/internal/testlog/index.d.ts +1 -0
  10. package/dist/gs/internal/testlog/index.js +5 -0
  11. package/dist/gs/internal/testlog/index.js.map +1 -0
  12. package/dist/gs/maps/iter.d.ts +1 -1
  13. package/dist/gs/os/dir.gs.d.ts +6 -0
  14. package/dist/gs/os/dir.gs.js +35 -0
  15. package/dist/gs/os/dir.gs.js.map +1 -0
  16. package/dist/gs/os/dir_unix.gs.d.ts +7 -0
  17. package/dist/gs/os/dir_unix.gs.js +113 -0
  18. package/dist/gs/os/dir_unix.gs.js.map +1 -0
  19. package/dist/gs/os/dirent_js.gs.d.ts +5 -0
  20. package/dist/gs/os/dirent_js.gs.js +20 -0
  21. package/dist/gs/os/dirent_js.gs.js.map +1 -0
  22. package/dist/gs/os/env.gs.d.ts +12 -0
  23. package/dist/gs/os/env.gs.js +157 -0
  24. package/dist/gs/os/env.gs.js.map +1 -0
  25. package/dist/gs/os/error.gs.d.ts +40 -0
  26. package/dist/gs/os/error.gs.js +158 -0
  27. package/dist/gs/os/error.gs.js.map +1 -0
  28. package/dist/gs/os/error_errno.gs.d.ts +1 -0
  29. package/dist/gs/os/error_errno.gs.js +5 -0
  30. package/dist/gs/os/error_errno.gs.js.map +1 -0
  31. package/dist/gs/os/exec.gs.d.ts +60 -0
  32. package/dist/gs/os/exec.gs.js +136 -0
  33. package/dist/gs/os/exec.gs.js.map +1 -0
  34. package/dist/gs/os/exec_nohandle.gs.d.ts +1 -0
  35. package/dist/gs/os/exec_nohandle.gs.js +2 -0
  36. package/dist/gs/os/exec_nohandle.gs.js.map +1 -0
  37. package/dist/gs/os/exec_posix.gs.d.ts +25 -0
  38. package/dist/gs/os/exec_posix.gs.js +67 -0
  39. package/dist/gs/os/exec_posix.gs.js.map +1 -0
  40. package/dist/gs/os/exec_unix.gs.d.ts +4 -0
  41. package/dist/gs/os/exec_unix.gs.js +46 -0
  42. package/dist/gs/os/exec_unix.gs.js.map +1 -0
  43. package/dist/gs/os/executable.gs.d.ts +2 -0
  44. package/dist/gs/os/executable.gs.js +16 -0
  45. package/dist/gs/os/executable.gs.js.map +1 -0
  46. package/dist/gs/os/executable_js.gs.d.ts +2 -0
  47. package/dist/gs/os/executable_js.gs.js +5 -0
  48. package/dist/gs/os/executable_js.gs.js.map +1 -0
  49. package/dist/gs/os/executable_wasm.gs.d.ts +2 -0
  50. package/dist/gs/os/executable_wasm.gs.js +6 -0
  51. package/dist/gs/os/executable_wasm.gs.js.map +1 -0
  52. package/dist/gs/os/file_constants_js.gs.d.ts +41 -0
  53. package/dist/gs/os/file_constants_js.gs.js +78 -0
  54. package/dist/gs/os/file_constants_js.gs.js.map +1 -0
  55. package/dist/gs/os/file_js.gs.d.ts +22 -0
  56. package/dist/gs/os/file_js.gs.js +73 -0
  57. package/dist/gs/os/file_js.gs.js.map +1 -0
  58. package/dist/gs/os/file_open_unix.gs.d.ts +6 -0
  59. package/dist/gs/os/file_open_unix.gs.js +10 -0
  60. package/dist/gs/os/file_open_unix.gs.js.map +1 -0
  61. package/dist/gs/os/file_posix_js.gs.d.ts +8 -0
  62. package/dist/gs/os/file_posix_js.gs.js +32 -0
  63. package/dist/gs/os/file_posix_js.gs.js.map +1 -0
  64. package/dist/gs/os/file_unix_js.gs.d.ts +27 -0
  65. package/dist/gs/os/file_unix_js.gs.js +64 -0
  66. package/dist/gs/os/file_unix_js.gs.js.map +1 -0
  67. package/dist/gs/os/getwd_js.gs.d.ts +6 -0
  68. package/dist/gs/os/getwd_js.gs.js +21 -0
  69. package/dist/gs/os/getwd_js.gs.js.map +1 -0
  70. package/dist/gs/os/index.d.ts +19 -0
  71. package/dist/gs/os/index.js +20 -0
  72. package/dist/gs/os/index.js.map +1 -0
  73. package/dist/gs/os/path.gs.d.ts +4 -0
  74. package/dist/gs/os/path.gs.js +32 -0
  75. package/dist/gs/os/path.gs.js.map +1 -0
  76. package/dist/gs/os/path_unix.gs.d.ts +4 -0
  77. package/dist/gs/os/path_unix.gs.js +40 -0
  78. package/dist/gs/os/path_unix.gs.js.map +1 -0
  79. package/dist/gs/os/pidfd_js.gs.d.ts +6 -0
  80. package/dist/gs/os/pidfd_js.gs.js +14 -0
  81. package/dist/gs/os/pidfd_js.gs.js.map +1 -0
  82. package/dist/gs/os/pipe_wasm.gs.d.ts +2 -0
  83. package/dist/gs/os/pipe_wasm.gs.js +14 -0
  84. package/dist/gs/os/pipe_wasm.gs.js.map +1 -0
  85. package/dist/gs/os/proc.gs.d.ts +11 -0
  86. package/dist/gs/os/proc.gs.js +68 -0
  87. package/dist/gs/os/proc.gs.js.map +1 -0
  88. package/dist/gs/os/proc_js.gs.d.ts +3 -0
  89. package/dist/gs/os/proc_js.gs.js +12 -0
  90. package/dist/gs/os/proc_js.gs.js.map +1 -0
  91. package/dist/gs/os/rawconn_js.gs.d.ts +10 -0
  92. package/dist/gs/os/rawconn_js.gs.js +26 -0
  93. package/dist/gs/os/rawconn_js.gs.js.map +1 -0
  94. package/dist/gs/os/removeall_js.gs.d.ts +2 -0
  95. package/dist/gs/os/removeall_js.gs.js +7 -0
  96. package/dist/gs/os/removeall_js.gs.js.map +1 -0
  97. package/dist/gs/os/root_js.gs.d.ts +23 -0
  98. package/dist/gs/os/root_js.gs.js +80 -0
  99. package/dist/gs/os/root_js.gs.js.map +1 -0
  100. package/dist/gs/os/root_nonwindows.gs.d.ts +2 -0
  101. package/dist/gs/os/root_nonwindows.gs.js +4 -0
  102. package/dist/gs/os/root_nonwindows.gs.js.map +1 -0
  103. package/dist/gs/os/root_noopenat.gs.d.ts +11 -0
  104. package/dist/gs/os/root_noopenat.gs.js +31 -0
  105. package/dist/gs/os/root_noopenat.gs.js.map +1 -0
  106. package/dist/gs/os/stat.gs.d.ts +24 -0
  107. package/dist/gs/os/stat.gs.js +20 -0
  108. package/dist/gs/os/stat.gs.js.map +1 -0
  109. package/dist/gs/os/stat_js.gs.d.ts +6 -0
  110. package/dist/gs/os/stat_js.gs.js +23 -0
  111. package/dist/gs/os/stat_js.gs.js.map +1 -0
  112. package/dist/gs/os/stat_unix_js.gs.d.ts +8 -0
  113. package/dist/gs/os/stat_unix_js.gs.js +16 -0
  114. package/dist/gs/os/stat_unix_js.gs.js.map +1 -0
  115. package/dist/gs/os/sticky_bsd.gs.d.ts +1 -0
  116. package/dist/gs/os/sticky_bsd.gs.js +3 -0
  117. package/dist/gs/os/sticky_bsd.gs.js.map +1 -0
  118. package/dist/gs/os/sys.gs.d.ts +2 -0
  119. package/dist/gs/os/sys.gs.js +10 -0
  120. package/dist/gs/os/sys.gs.js.map +1 -0
  121. package/dist/gs/os/sys_bsd.gs.d.ts +2 -0
  122. package/dist/gs/os/sys_bsd.gs.js +15 -0
  123. package/dist/gs/os/sys_bsd.gs.js.map +1 -0
  124. package/dist/gs/os/sys_js.gs.d.ts +2 -0
  125. package/dist/gs/os/sys_js.gs.js +6 -0
  126. package/dist/gs/os/sys_js.gs.js.map +1 -0
  127. package/dist/gs/os/tempfile.gs.d.ts +5 -0
  128. package/dist/gs/os/tempfile.gs.js +30 -0
  129. package/dist/gs/os/tempfile.gs.js.map +1 -0
  130. package/dist/gs/os/types.gs.d.ts +59 -0
  131. package/dist/gs/os/types.gs.js +123 -0
  132. package/dist/gs/os/types.gs.js.map +1 -0
  133. package/dist/gs/os/types_js.gs.d.ts +74 -0
  134. package/dist/gs/os/types_js.gs.js +147 -0
  135. package/dist/gs/os/types_js.gs.js.map +1 -0
  136. package/dist/gs/os/types_unix.gs.d.ts +40 -0
  137. package/dist/gs/os/types_unix.gs.js +87 -0
  138. package/dist/gs/os/types_unix.gs.js.map +1 -0
  139. package/dist/gs/os/wait_unimp.gs.d.ts +1 -0
  140. package/dist/gs/os/wait_unimp.gs.js +2 -0
  141. package/dist/gs/os/wait_unimp.gs.js.map +1 -0
  142. package/dist/gs/os/zero_copy_posix.gs.d.ts +4 -0
  143. package/dist/gs/os/zero_copy_posix.gs.js +27 -0
  144. package/dist/gs/os/zero_copy_posix.gs.js.map +1 -0
  145. package/dist/gs/os/zero_copy_stub.gs.d.ts +1 -0
  146. package/dist/gs/os/zero_copy_stub.gs.js +2 -0
  147. package/dist/gs/os/zero_copy_stub.gs.js.map +1 -0
  148. package/dist/gs/sync/atomic/doc.gs.d.ts +28 -0
  149. package/dist/gs/sync/atomic/doc.gs.js +265 -0
  150. package/dist/gs/sync/atomic/doc.gs.js.map +1 -0
  151. package/dist/gs/sync/atomic/doc_64.gs.d.ts +15 -0
  152. package/dist/gs/sync/atomic/doc_64.gs.js +165 -0
  153. package/dist/gs/sync/atomic/doc_64.gs.js.map +1 -0
  154. package/dist/gs/sync/atomic/index.d.ts +4 -0
  155. package/dist/gs/sync/atomic/index.js +5 -0
  156. package/dist/gs/sync/atomic/index.js.map +1 -0
  157. package/dist/gs/sync/atomic/type.gs.d.ts +130 -0
  158. package/dist/gs/sync/atomic/type.gs.js +433 -0
  159. package/dist/gs/sync/atomic/type.gs.js.map +1 -0
  160. package/dist/gs/sync/atomic/value.gs.d.ts +19 -0
  161. package/dist/gs/sync/atomic/value.gs.js +116 -0
  162. package/dist/gs/sync/atomic/value.gs.js.map +1 -0
  163. package/dist/gs/syscall/index.d.ts +80 -0
  164. package/dist/gs/syscall/index.js +163 -0
  165. package/dist/gs/syscall/index.js.map +1 -0
  166. package/dist/gs/unsafe/unsafe.d.ts +1 -0
  167. package/dist/gs/unsafe/unsafe.js +5 -0
  168. package/dist/gs/unsafe/unsafe.js.map +1 -1
  169. package/gs/internal/byteorder/index.ts +40 -0
  170. package/gs/internal/testlog/index.ts +7 -0
  171. package/gs/maps/iter.ts +1 -1
  172. package/gs/math/erfinv.gs.test.ts +2 -2
  173. package/gs/math/fma.gs.test.ts +5 -5
  174. package/gs/math/ldexp.gs.test.ts +5 -5
  175. package/gs/math/lgamma.gs.test.ts +2 -2
  176. package/gs/os/dir.gs.ts +42 -0
  177. package/gs/os/dir_unix.gs.ts +155 -0
  178. package/gs/os/dirent_js.gs.ts +27 -0
  179. package/gs/os/env.gs.ts +179 -0
  180. package/gs/os/error.gs.ts +205 -0
  181. package/gs/os/error_errno.gs.ts +12 -0
  182. package/gs/os/exec.gs.ts +198 -0
  183. package/gs/os/exec_nohandle.gs.ts +2 -0
  184. package/gs/os/exec_posix.gs.ts +95 -0
  185. package/gs/os/exec_unix.gs.ts +64 -0
  186. package/gs/os/executable.gs.ts +18 -0
  187. package/gs/os/executable_js.gs.ts +6 -0
  188. package/gs/os/executable_wasm.gs.ts +10 -0
  189. package/gs/os/file_constants_js.gs.ts +98 -0
  190. package/gs/os/file_js.gs.ts +99 -0
  191. package/gs/os/file_open_unix.gs.ts +15 -0
  192. package/gs/os/file_posix_js.gs.ts +40 -0
  193. package/gs/os/file_unix_js.gs.ts +94 -0
  194. package/gs/os/getwd_js.gs.ts +28 -0
  195. package/gs/os/index.ts +19 -0
  196. package/gs/os/path.gs.ts +35 -0
  197. package/gs/os/path_unix.gs.ts +49 -0
  198. package/gs/os/pidfd_js.gs.ts +25 -0
  199. package/gs/os/pipe_wasm.gs.ts +17 -0
  200. package/gs/os/proc.gs.ts +84 -0
  201. package/gs/os/proc_js.gs.ts +15 -0
  202. package/gs/os/rawconn_js.gs.ts +30 -0
  203. package/gs/os/removeall_js.gs.ts +9 -0
  204. package/gs/os/root_js.gs.ts +111 -0
  205. package/gs/os/root_nonwindows.gs.ts +6 -0
  206. package/gs/os/root_noopenat.gs.ts +45 -0
  207. package/gs/os/stat.gs.ts +38 -0
  208. package/gs/os/stat_js.gs.ts +30 -0
  209. package/gs/os/stat_unix_js.gs.ts +27 -0
  210. package/gs/os/sticky_bsd.gs.ts +4 -0
  211. package/gs/os/sys.gs.ts +12 -0
  212. package/gs/os/sys_bsd.gs.ts +17 -0
  213. package/gs/os/sys_js.gs.ts +9 -0
  214. package/gs/os/tempfile.gs.ts +34 -0
  215. package/gs/os/types.gs.ts +170 -0
  216. package/gs/os/types_js.gs.ts +205 -0
  217. package/gs/os/types_unix.gs.ts +118 -0
  218. package/gs/os/wait_unimp.gs.ts +2 -0
  219. package/gs/os/zero_copy_posix.gs.ts +35 -0
  220. package/gs/os/zero_copy_stub.gs.ts +4 -0
  221. package/gs/sync/atomic/doc.gs.ts +276 -0
  222. package/gs/sync/atomic/doc_64.gs.ts +168 -0
  223. package/gs/sync/atomic/index.ts +4 -0
  224. package/gs/sync/atomic/type.gs.ts +596 -0
  225. package/gs/sync/atomic/value.gs.ts +158 -0
  226. package/gs/syscall/index.ts +204 -0
  227. package/gs/unsafe/unsafe.ts +6 -0
  228. package/package.json +1 -1
@@ -0,0 +1,94 @@
1
+ import * as $ from "@goscript/builtin/builtin.js";
2
+ import { ErrUnimplemented } from "./error.gs.js";
3
+ import { File } from "./types_js.gs.js";
4
+
5
+ import * as fs from "@goscript/io/fs/index.js"
6
+
7
+ // JavaScript-specific implementations for Unix file operations
8
+ // These functions stub Unix-specific operations that cannot be implemented in JavaScript
9
+
10
+ // Device null path - stub for JavaScript
11
+ export const DevNull = "/dev/null"
12
+
13
+ // Stdin, Stdout, Stderr - stub implementations
14
+ export const Stdin: File | null = null
15
+ export const Stdout: File | null = null
16
+ export const Stderr: File | null = null
17
+
18
+ // NewFile creates a File from a file descriptor - stub implementation
19
+ export function NewFile(fd: number, name: string): File | null {
20
+ return null
21
+ }
22
+
23
+ // File operations that need to be stubbed
24
+ export function Remove(name: string): $.GoError {
25
+ return ErrUnimplemented
26
+ }
27
+
28
+ export function Link(oldname: string, newname: string): $.GoError {
29
+ return ErrUnimplemented
30
+ }
31
+
32
+ export function Symlink(oldname: string, newname: string): $.GoError {
33
+ return ErrUnimplemented
34
+ }
35
+
36
+ export function Truncate(name: string, size: number): $.GoError {
37
+ return ErrUnimplemented
38
+ }
39
+
40
+ // Internal stub functions that may be referenced by other files
41
+ export function rename(oldname: string, newname: string): $.GoError {
42
+ return ErrUnimplemented
43
+ }
44
+
45
+ export function openFileNolog(name: string, flag: number, perm: number): [File | null, $.GoError] {
46
+ return [null, ErrUnimplemented]
47
+ }
48
+
49
+ export function openDirNolog(name: string): [File | null, $.GoError] {
50
+ return [null, ErrUnimplemented]
51
+ }
52
+
53
+ export function tempDir(): string {
54
+ return "/tmp"
55
+ }
56
+
57
+ export function readlink(name: string): [string, $.GoError] {
58
+ return ["", ErrUnimplemented]
59
+ }
60
+
61
+ // File class methods that need to be stubbed for unix compatibility
62
+ export function fixLongPath(path: string): string {
63
+ return path
64
+ }
65
+
66
+ export function sigpipe(): void {
67
+ // No-op in JavaScript
68
+ }
69
+
70
+ export function epipecheck(file: File | null, e: $.GoError): void {
71
+ // No-op in JavaScript
72
+ }
73
+
74
+ // dirInfo stub for compatibility
75
+ export interface dirInfo {
76
+ close(): void
77
+ }
78
+
79
+ // Network file creation stub
80
+ export function net_newUnixFile(fd: number, name: string): File | null {
81
+ return null
82
+ }
83
+
84
+ // File kind enum for compatibility
85
+ export type newFileKind = number
86
+
87
+ export function newFile(fd: number, name: string, kind: newFileKind, nonBlocking: boolean): File | null {
88
+ return null
89
+ }
90
+
91
+ // Directory entry stubs
92
+ export function newUnixDirent(parent: string, name: string, typ: number): [fs.DirEntry | null, $.GoError] {
93
+ return [null, ErrUnimplemented]
94
+ }
@@ -0,0 +1,28 @@
1
+ import * as $ from "@goscript/builtin/builtin.js";
2
+
3
+ import * as fs from "@goscript/io/fs/index.js"
4
+
5
+ // JavaScript-specific implementation of Getwd
6
+ // Working directories are not a concept in JavaScript environments
7
+ // Store working directory in a global variable
8
+
9
+ // Global working directory variable, defaults to test directory
10
+ let currentWorkingDir: string = "/"
11
+
12
+ export function Getwd(): [string, $.GoError] {
13
+ return [currentWorkingDir, null]
14
+ }
15
+
16
+ // Set the working directory (for internal use)
17
+ export function setWorkingDir(dir: string): void {
18
+ currentWorkingDir = dir
19
+ }
20
+
21
+ // Additional functions that may be imported by other files
22
+ export function statNolog(name: string): [fs.FileInfo | null, $.GoError] {
23
+ return [null, fs.ErrNotExist]
24
+ }
25
+
26
+ export function lstatNolog(name: string): [fs.FileInfo | null, $.GoError] {
27
+ return [null, fs.ErrNotExist]
28
+ }
package/gs/os/index.ts ADDED
@@ -0,0 +1,19 @@
1
+ export { CopyFS, ReadDir } from "./dir.gs.js"
2
+ export { Clearenv, Environ, Expand, ExpandEnv, Getenv, LookupEnv, Setenv, Unsetenv } from "./env.gs.js"
3
+ export { ErrClosed, ErrDeadlineExceeded, ErrExist, ErrInvalid, ErrNoDeadline, ErrNotExist, ErrPermission, ErrUnimplemented, IsExist, IsNotExist, IsPermission, IsTimeout, NewSyscallError, PathError, SyscallError } from "./error.gs.js"
4
+ export { ErrProcessDone, FindProcess, Getpid, Getppid, ProcAttr, Process, Signal, StartProcess } from "./exec.gs.js"
5
+ export { Interrupt, Kill, ProcessState } from "./exec_posix.gs.js"
6
+ export { Executable } from "./executable.gs.js"
7
+ export { Chdir, Chmod, Create, DirFS, Mkdir, Open, OpenFile, ReadFile, Rename, WriteFile, MkdirAll, RemoveAll } from "./file_js.gs.js"
8
+ export { LinkError, O_APPEND, O_CREATE, O_EXCL, O_RDONLY, O_RDWR, O_SYNC, O_TRUNC, O_WRONLY, Readlink, SEEK_CUR, SEEK_END, SEEK_SET, TempDir, UserCacheDir, UserConfigDir, UserHomeDir } from "./file_constants_js.gs.js"
9
+ export { DevNull, Link, NewFile, Remove, Stderr, Stdin, Stdout, Symlink, Truncate } from "./file_unix_js.gs.js"
10
+ export { Chown, Chtimes, Lchown } from "./file_posix_js.gs.js"
11
+ export { Getwd } from "./getwd_js.gs.js"
12
+ export { IsPathSeparator, PathListSeparator, PathSeparator } from "./path_unix.gs.js"
13
+ export { Pipe } from "./pipe_wasm.gs.js"
14
+ export { Args, Exit, Getegid, Geteuid, Getgid, Getgroups, Getuid } from "./proc.gs.js"
15
+ export { OpenInRoot, OpenRoot, Root } from "./root_js.gs.js"
16
+ export { Lstat, Stat } from "./stat_js.gs.js"
17
+ export { Hostname } from "./sys.gs.js"
18
+ export { CreateTemp, MkdirTemp } from "./tempfile.gs.js"
19
+ export { DirEntry, File, FileInfo, FileMode, Getpagesize, ModeAppend, ModeCharDevice, ModeDevice, ModeDir, ModeExclusive, ModeIrregular, ModeNamedPipe, ModePerm, ModeSetgid, ModeSetuid, ModeSocket, ModeSticky, ModeSymlink, ModeTemporary, ModeType, SameFile } from "./types_js.gs.js"
@@ -0,0 +1,35 @@
1
+ import * as $ from "@goscript/builtin/builtin.js";
2
+ import { ErrUnimplemented } from "./error.gs.js";
3
+ import { IsPathSeparator } from "./path_unix.gs.js";
4
+
5
+ // MkdirAll creates a directory named path,
6
+ // along with any necessary parents, and returns nil,
7
+ // or else returns an error.
8
+ // The permission bits perm (before umask) are used for all
9
+ // directories that MkdirAll creates.
10
+ // If path is already a directory, MkdirAll does nothing
11
+ // and returns nil.
12
+ export function MkdirAll(path: string, perm: number): $.GoError {
13
+ return ErrUnimplemented
14
+ }
15
+
16
+ // RemoveAll removes path and any children it contains.
17
+ // It removes everything it can but returns the first error
18
+ // it encounters. If the path does not exist, RemoveAll
19
+ // returns nil (no error).
20
+ // If there is an error, it will be of type [*PathError].
21
+ export function RemoveAll(path: string): $.GoError {
22
+ return ErrUnimplemented
23
+ }
24
+
25
+ // endsWithDot reports whether the final component of path is ".".
26
+ export function endsWithDot(path: string): boolean {
27
+ if (path == ".") {
28
+ return true
29
+ }
30
+ if ($.len(path) >= 2 && $.indexString(path, $.len(path) - 1) == 46 && IsPathSeparator($.indexString(path, $.len(path) - 2))) {
31
+ return true
32
+ }
33
+ return false
34
+ }
35
+
@@ -0,0 +1,49 @@
1
+ import * as $ from "@goscript/builtin/builtin.js";
2
+
3
+ // OS-specific path separator
4
+ export let PathSeparator: number = 47
5
+
6
+ // OS-specific path list separator
7
+ export let PathListSeparator: number = 58
8
+
9
+ // IsPathSeparator reports whether c is a directory separator character.
10
+ export function IsPathSeparator(c: number): boolean {
11
+ return 47 == c
12
+ }
13
+
14
+ // splitPath returns the base name and parent directory.
15
+ export function splitPath(path: string): [string, string] {
16
+ // if no better parent is found, the path is relative from "here"
17
+ let dirname = "."
18
+
19
+ // Remove all but one leading slash.
20
+ for (; $.len(path) > 1 && $.indexString(path, 0) == 47 && $.indexString(path, 1) == 47; ) {
21
+ path = $.sliceString(path, 1, undefined)
22
+ }
23
+
24
+ let i = $.len(path) - 1
25
+
26
+ // Remove trailing slashes.
27
+ for (; i > 0 && $.indexString(path, i) == 47; i--) {
28
+ path = $.sliceString(path, undefined, i)
29
+ }
30
+
31
+ // if no slashes in path, base is path
32
+ let basename = path
33
+
34
+ // Remove leading directory path
35
+ for (i--; i >= 0; i--) {
36
+ if ($.indexString(path, i) == 47) {
37
+ if (i == 0) {
38
+ dirname = $.sliceString(path, undefined, 1)
39
+ } else {
40
+ dirname = $.sliceString(path, undefined, i)
41
+ }
42
+ basename = $.sliceString(path, i + 1, undefined)
43
+ break
44
+ }
45
+ }
46
+
47
+ return [dirname, basename]
48
+ }
49
+
@@ -0,0 +1,25 @@
1
+ import * as $ from "@goscript/builtin/builtin.js";
2
+ import { ErrUnimplemented } from "./error.gs.js";
3
+
4
+ // JavaScript-specific stubs for pidfd operations
5
+ // These operations are Linux-specific and not available in JavaScript
6
+
7
+ // SysProcAttr stub for compatibility
8
+ export interface SysProcAttr {
9
+ // Stub interface for process attributes
10
+ }
11
+
12
+ // ensurePidfd ensures pidfd support - stub implementation
13
+ export function ensurePidfd(sysAttr: SysProcAttr | null): [SysProcAttr | null, boolean] {
14
+ return [null, false]
15
+ }
16
+
17
+ // getPidfd gets a process file descriptor - stub implementation
18
+ export function getPidfd(_: SysProcAttr | null, _usePidfd: boolean): [number, boolean] {
19
+ return [0, false]
20
+ }
21
+
22
+ // pidfdFind finds a process by pidfd - stub implementation
23
+ export function pidfdFind(_: number): [number, $.GoError] {
24
+ return [0, ErrUnimplemented]
25
+ }
@@ -0,0 +1,17 @@
1
+ import * as $ from "@goscript/builtin/builtin.js";
2
+ import { NewSyscallError } from "./error.gs.js";
3
+
4
+ import * as syscall from "@goscript/syscall/index.js"
5
+
6
+ // Pipe returns a connected pair of Files; reads from r return bytes written to w.
7
+ // It returns the files and an error, if any.
8
+ export function Pipe(): [File | null, File | null, $.GoError] {
9
+ let r: File | null = null
10
+ let w: File | null = null
11
+ let err: $.GoError = null
12
+ {
13
+ // Neither GOOS=js nor GOOS=wasip1 have pipes.
14
+ return [null, null, NewSyscallError("pipe", syscall.ENOSYS)]
15
+ }
16
+ }
17
+
@@ -0,0 +1,84 @@
1
+ import * as $ from "@goscript/builtin/builtin.js";
2
+ import { NewSyscallError, ErrUnimplemented } from "./error.gs.js";
3
+
4
+ import * as runtime from "@goscript/runtime/index.js"
5
+
6
+ import * as syscall from "@goscript/syscall/index.js"
7
+
8
+ export let Args: $.Slice<string> = null
9
+
10
+ export function init(): void {
11
+ // In JavaScript environment, just initialize with empty args
12
+ Args = runtime_args()
13
+ }
14
+
15
+ export function runtime_args(): $.Slice<string> {
16
+ return $.arrayToSlice<string>([])
17
+ }
18
+
19
+ // Getuid returns the numeric user id of the caller.
20
+ //
21
+ // On Windows, it returns -1.
22
+ export function Getuid(): number {
23
+ return -1 // Not available in JavaScript
24
+ }
25
+
26
+ // Geteuid returns the numeric effective user id of the caller.
27
+ //
28
+ // On Windows, it returns -1.
29
+ export function Geteuid(): number {
30
+ return -1 // Not available in JavaScript
31
+ }
32
+
33
+ // Getgid returns the numeric group id of the caller.
34
+ //
35
+ // On Windows, it returns -1.
36
+ export function Getgid(): number {
37
+ return -1 // Not available in JavaScript
38
+ }
39
+
40
+ // Getegid returns the numeric effective group id of the caller.
41
+ //
42
+ // On Windows, it returns -1.
43
+ export function Getegid(): number {
44
+ return -1 // Not available in JavaScript
45
+ }
46
+
47
+ // Getgroups returns a list of the numeric ids of groups that the caller belongs to.
48
+ //
49
+ // On Windows, it returns [syscall.EWINDOWS]. See the [os/user] package
50
+ // for a possible alternative.
51
+ export function Getgroups(): [$.Slice<number>, $.GoError] {
52
+ return [$.arrayToSlice<number>([]), ErrUnimplemented]
53
+ }
54
+
55
+ // Exit causes the current program to exit with the given status code.
56
+ // Conventionally, code zero indicates success, non-zero an error.
57
+ // The program terminates immediately; deferred functions are not run.
58
+ //
59
+ // For portability, the status code should be in the range [0, 125].
60
+ export function Exit(code: number): void {
61
+
62
+ // Testlog functionality not available in JavaScript - stub
63
+ // if (code == 0 && testlog.PanicOnExit0()) {
64
+ // $.panic("unexpected call to os.Exit(0) during test")
65
+ // }
66
+
67
+ // Inform the runtime that os.Exit is being called. If -race is
68
+ // enabled, this will give race detector a chance to fail the
69
+ // program (racy programs do not have the right to finish
70
+ // successfully). If coverage is enabled, then this call will
71
+ // enable us to write out a coverage data file.
72
+ runtime_beforeExit(code)
73
+
74
+ // In JavaScript environment, use process.exit if available
75
+ if (typeof process !== 'undefined' && process.exit) {
76
+ process.exit(code)
77
+ } else {
78
+ // Fallback: just return (can't really exit in browser)
79
+ return
80
+ }
81
+ }
82
+
83
+ export function runtime_beforeExit(exitCode: number): void {}
84
+
@@ -0,0 +1,15 @@
1
+ import * as $ from "@goscript/builtin/builtin.js";
2
+ import { ErrUnimplemented } from "./error.gs.js";
3
+
4
+ // JavaScript-specific process functions
5
+
6
+ // runtime_args returns command line arguments (stub for JS)
7
+ export function runtime_args(): $.Slice<string> {
8
+ // In JavaScript environment, return empty args or process.argv equivalent
9
+ return $.arrayToSlice<string>([])
10
+ }
11
+
12
+ // runtime_beforeExit is called before exit (stub for JS)
13
+ export function runtime_beforeExit(exitCode: number): void {
14
+ // No-op in JavaScript
15
+ }
@@ -0,0 +1,30 @@
1
+ import * as $ from "@goscript/builtin/builtin.js";
2
+ import { ErrUnimplemented } from "./error.gs.js";
3
+ import { File } from "./types_js.gs.js";
4
+
5
+ // JavaScript-specific stub for raw connection operations
6
+ // These operations are not available in JavaScript environments
7
+
8
+ export class rawConn {
9
+ constructor(private file: File | null) {}
10
+
11
+ // Control calls fn with the file descriptor - stub implementation
12
+ public Control(f: ((fd: number) => void) | null): $.GoError {
13
+ return ErrUnimplemented
14
+ }
15
+
16
+ // Read calls fn when the file descriptor is ready for reading - stub implementation
17
+ public Read(f: ((fd: number) => boolean) | null): $.GoError {
18
+ return ErrUnimplemented
19
+ }
20
+
21
+ // Write calls fn when the file descriptor is ready for writing - stub implementation
22
+ public Write(f: ((fd: number) => boolean) | null): $.GoError {
23
+ return ErrUnimplemented
24
+ }
25
+ }
26
+
27
+ // newRawConn creates a new raw connection - stub implementation
28
+ export function newRawConn(file: File | null): rawConn {
29
+ return new rawConn(file)
30
+ }
@@ -0,0 +1,9 @@
1
+ import * as $ from "@goscript/builtin/builtin.js";
2
+ import { ErrUnimplemented } from "./error.gs.js";
3
+
4
+ // JavaScript-specific stub for removeall operations
5
+ // These operations cannot be implemented in JavaScript environments
6
+
7
+ export function RemoveAll(path: string): $.GoError {
8
+ return ErrUnimplemented
9
+ }
@@ -0,0 +1,111 @@
1
+ import * as $ from "@goscript/builtin/builtin.js";
2
+ import { ErrUnimplemented } from "./error.gs.js";
3
+ import { File } from "./types_js.gs.js";
4
+
5
+ import * as fs from "@goscript/io/fs/index.js"
6
+
7
+ // JavaScript-specific implementations for root filesystem operations
8
+ // These functions stub operations that cannot be implemented in JavaScript
9
+
10
+ // OpenInRoot opens the file name in the directory dir - stub implementation
11
+ export function OpenInRoot(dir: string, name: string): [File | null, $.GoError] {
12
+ return [null, ErrUnimplemented]
13
+ }
14
+
15
+ // Root represents a root filesystem - stub implementation
16
+ export class Root {
17
+ constructor() {}
18
+
19
+ // Name returns the name of the directory presented to OpenRoot
20
+ public Name(): string {
21
+ return ""
22
+ }
23
+
24
+ // Close closes the Root
25
+ public Close(): $.GoError {
26
+ return ErrUnimplemented
27
+ }
28
+
29
+ // Open opens the named file in the root for reading
30
+ public Open(name: string): [File | null, $.GoError] {
31
+ return [null, ErrUnimplemented]
32
+ }
33
+
34
+ // Create creates or truncates the named file in the root
35
+ public Create(name: string): [File | null, $.GoError] {
36
+ return [null, ErrUnimplemented]
37
+ }
38
+
39
+ // OpenFile opens the named file in the root
40
+ public OpenFile(name: string, flag: number, perm: number): [File | null, $.GoError] {
41
+ return [null, ErrUnimplemented]
42
+ }
43
+
44
+ // OpenRoot opens the named directory in the root
45
+ public OpenRoot(name: string): [RootType | null, $.GoError] {
46
+ return [null, ErrUnimplemented]
47
+ }
48
+
49
+ // Mkdir creates a new directory in the root
50
+ public Mkdir(name: string, perm: number): $.GoError {
51
+ return ErrUnimplemented
52
+ }
53
+
54
+ // Remove removes the named file or directory in the root
55
+ public Remove(name: string): $.GoError {
56
+ return ErrUnimplemented
57
+ }
58
+
59
+ // Stat returns a FileInfo describing the named file in the root
60
+ public Stat(name: string): [fs.FileInfo | null, $.GoError] {
61
+ return [null, ErrUnimplemented]
62
+ }
63
+
64
+ // Lstat returns a FileInfo describing the named file in the root
65
+ public Lstat(name: string): [fs.FileInfo | null, $.GoError] {
66
+ return [null, ErrUnimplemented]
67
+ }
68
+
69
+ // FS returns a file system for the tree of files in the root
70
+ public FS(): fs.FS {
71
+ return new stubFS()
72
+ }
73
+
74
+ // Register this type with the runtime type system
75
+ static __typeInfo = $.registerStructType(
76
+ 'Root',
77
+ new Root(),
78
+ [
79
+ { name: "Name", args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }] },
80
+ { name: "Close", args: [], returns: [{ type: { kind: $.TypeKind.Interface, name: 'GoError', methods: [{ name: 'Error', args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }] }] } }] }
81
+ ],
82
+ Root,
83
+ {}
84
+ );
85
+ }
86
+
87
+ // Type alias to avoid conflicts
88
+ export type RootType = Root
89
+
90
+ // OpenRoot opens a root filesystem - stub implementation
91
+ export function OpenRoot(name: string): [Root | null, $.GoError] {
92
+ return [null, ErrUnimplemented]
93
+ }
94
+
95
+ // splitPathInRoot splits a path in root - stub implementation
96
+ export function splitPathInRoot(s: string, prefix: $.Slice<string> | null, suffix: $.Slice<string> | null): [$.Slice<string>, string, $.GoError] {
97
+ return [null, "", ErrUnimplemented]
98
+ }
99
+
100
+ // isValidRootFSPath checks if a path is valid for root filesystem - stub implementation
101
+ export function isValidRootFSPath(name: string): boolean {
102
+ return false
103
+ }
104
+
105
+ // Internal stub filesystem
106
+ class stubFS {
107
+ public Open(name: string): [fs.File, $.GoError] {
108
+ return [null, ErrUnimplemented]
109
+ }
110
+ }
111
+
@@ -0,0 +1,6 @@
1
+ import * as $ from "@goscript/builtin/builtin.js";
2
+
3
+ export function rootCleanPath(s: string, prefix: $.Slice<string>, suffix: $.Slice<string>): [string, $.GoError] {
4
+ return [s, null]
5
+ }
6
+
@@ -0,0 +1,45 @@
1
+ import * as $ from "@goscript/builtin/builtin.js";
2
+ import { underlyingError, ErrUnimplemented } from "./error.gs.js";
3
+ import { Root } from "./root_js.gs.js";
4
+ import { File } from "./types_js.gs.js";
5
+
6
+ import * as errors from "@goscript/errors/index.js"
7
+ import * as fs from "@goscript/io/fs/index.js"
8
+
9
+ // Stub functions for JavaScript environment - these operations cannot be implemented properly
10
+
11
+ // openRootNolog is OpenRoot - stub implementation
12
+ export function openRootNolog(name: string): [Root | null, $.GoError] {
13
+ return [null, ErrUnimplemented]
14
+ }
15
+
16
+ // openRootInRoot is Root.OpenRoot - stub implementation
17
+ export function openRootInRoot(r: Root | null, name: string): [Root | null, $.GoError] {
18
+ return [null, ErrUnimplemented]
19
+ }
20
+
21
+ // newRoot returns a new Root - stub implementation
22
+ export function newRoot(name: string): [Root | null, $.GoError] {
23
+ return [null, ErrUnimplemented]
24
+ }
25
+
26
+ // rootOpenFileNolog is Root.OpenFile - stub implementation
27
+ export function rootOpenFileNolog(r: Root | null, name: string, flag: number, perm: number): [File | null, $.GoError] {
28
+ return [null, ErrUnimplemented]
29
+ }
30
+
31
+ // rootStat - stub implementation
32
+ export function rootStat(r: Root | null, name: string, lstat: boolean): [fs.FileInfo | null, $.GoError] {
33
+ return [null, ErrUnimplemented]
34
+ }
35
+
36
+ // rootMkdir - stub implementation
37
+ export function rootMkdir(r: Root | null, name: string, perm: number): $.GoError {
38
+ return ErrUnimplemented
39
+ }
40
+
41
+ // rootRemove - stub implementation
42
+ export function rootRemove(r: Root | null, name: string): $.GoError {
43
+ return ErrUnimplemented
44
+ }
45
+
@@ -0,0 +1,38 @@
1
+ import * as $ from "@goscript/builtin/builtin.js";
2
+ import { lstatNolog, statNolog } from "./stat_js.gs.js";
3
+ import { Time, FileMode } from "./types_js.gs.js";
4
+
5
+ // Stat returns a [FileInfo] describing the named file.
6
+ // If there is an error, it will be of type [*PathError].
7
+ export function Stat(name: string): [null | {
8
+ IsDir(): boolean
9
+ ModTime(): any
10
+ Mode(): any
11
+ Name(): string
12
+ Size(): number
13
+ Sys(): null | any
14
+ }, $.GoError] {
15
+ // testlog.Stat(name) // Testlog not available in JavaScript
16
+ return statNolog(name)
17
+ }
18
+
19
+ // Lstat returns a [FileInfo] describing the named file.
20
+ // If the file is a symbolic link, the returned FileInfo
21
+ // describes the symbolic link. Lstat makes no attempt to follow the link.
22
+ // If there is an error, it will be of type [*PathError].
23
+ //
24
+ // On Windows, if the file is a reparse point that is a surrogate for another
25
+ // named entity (such as a symbolic link or mounted folder), the returned
26
+ // FileInfo describes the reparse point, and makes no attempt to resolve it.
27
+ export function Lstat(name: string): [null | {
28
+ IsDir(): boolean
29
+ ModTime(): Time
30
+ Mode(): FileMode
31
+ Name(): string
32
+ Size(): number
33
+ Sys(): null | any
34
+ }, $.GoError] {
35
+ // testlog.Stat(name) // Testlog not available in JavaScript
36
+ return lstatNolog(name)
37
+ }
38
+
@@ -0,0 +1,30 @@
1
+ import * as $ from "@goscript/builtin/builtin.js";
2
+ import { ErrUnimplemented } from "./error.gs.js";
3
+
4
+ import * as fs from "@goscript/io/fs/index.js"
5
+
6
+ // JavaScript-specific stubs for stat operations
7
+
8
+ // Stat returns a [FileInfo] describing the named file.
9
+ // If there is an error, it will be of type [*PathError].
10
+ export function Stat(name: string): [fs.FileInfo, $.GoError] {
11
+ return [null, ErrUnimplemented]
12
+ }
13
+
14
+ // Lstat returns a [FileInfo] describing the named file.
15
+ // If the file is a symbolic link, the returned FileInfo
16
+ // describes the symbolic link. Lstat makes no attempt to follow the link.
17
+ // If there is an error, it will be of type [*PathError].
18
+ export function Lstat(name: string): [fs.FileInfo, $.GoError] {
19
+ return [null, ErrUnimplemented]
20
+ }
21
+
22
+ // statNolog is the same as Stat, for use in DirFS.
23
+ export function statNolog(name: string): [fs.FileInfo, $.GoError] {
24
+ return [null, ErrUnimplemented]
25
+ }
26
+
27
+ // lstatNolog is the same as Lstat, for use in DirFS.
28
+ export function lstatNolog(name: string): [fs.FileInfo, $.GoError] {
29
+ return [null, ErrUnimplemented]
30
+ }
@@ -0,0 +1,27 @@
1
+ import * as $ from "@goscript/builtin/builtin.js";
2
+ import { ErrUnimplemented } from "./error.gs.js";
3
+
4
+ import * as fs from "@goscript/io/fs/index.js"
5
+
6
+ // JavaScript-specific stub implementations for Unix stat operations
7
+ // These operations cannot be implemented in JavaScript environments
8
+
9
+ // statNolog stats a file with no test logging - stub implementation
10
+ export function statNolog(name: string): [fs.FileInfo | null, $.GoError] {
11
+ return [null, ErrUnimplemented]
12
+ }
13
+
14
+ // lstatNolog lstats a file with no test logging - stub implementation
15
+ export function lstatNolog(name: string): [fs.FileInfo | null, $.GoError] {
16
+ return [null, ErrUnimplemented]
17
+ }
18
+
19
+ // Additional compatibility exports
20
+ export function fillFileStatFromSys(fs: any, name: string): void {
21
+ // No-op in JavaScript
22
+ }
23
+
24
+ // fileStat stub for compatibility
25
+ export interface fileStat {
26
+ sys: any
27
+ }