goscript 0.1.0 → 0.1.1

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 (327) hide show
  1. package/README.md +267 -255
  2. package/cmd/goscript/cmd-test.go +193 -0
  3. package/cmd/goscript/cmd-test_test.go +76 -0
  4. package/cmd/goscript/main.go +1 -0
  5. package/compiler/build-flags.go +38 -0
  6. package/compiler/compile-request.go +2 -0
  7. package/compiler/compliance_test.go +0 -8
  8. package/compiler/gotest/owner.go +24 -0
  9. package/compiler/gotest/package-result.go +67 -0
  10. package/compiler/gotest/request.go +145 -0
  11. package/compiler/gotest/result.go +28 -0
  12. package/compiler/gotest/runner.go +588 -0
  13. package/compiler/gotest/runner_test.go +627 -0
  14. package/compiler/gotest/test.go +9 -0
  15. package/compiler/index.test.ts +1 -1
  16. package/compiler/lowered-program.go +71 -19
  17. package/compiler/lowering.go +5065 -569
  18. package/compiler/override-facts.go +307 -0
  19. package/compiler/override-registry.go +50 -189
  20. package/compiler/override-registry_test.go +47 -0
  21. package/compiler/package-graph.go +50 -27
  22. package/compiler/package-graph_test.go +37 -2
  23. package/compiler/package-test-function.go +9 -0
  24. package/compiler/package-test-graph-package.go +40 -0
  25. package/compiler/package-test-graph-variant.go +105 -0
  26. package/compiler/package-test-graph.go +117 -0
  27. package/compiler/package-test-graph_test.go +144 -0
  28. package/compiler/runtime-contract.go +189 -29
  29. package/compiler/runtime-contract_test.go +44 -30
  30. package/compiler/semantic-model-types.go +9 -6
  31. package/compiler/semantic-model.go +538 -38
  32. package/compiler/semantic-model_test.go +55 -0
  33. package/compiler/service.go +1 -1
  34. package/compiler/skeleton_test.go +679 -49
  35. package/compiler/tsworkspace/owner.go +334 -0
  36. package/compiler/tsworkspace/owner_test.go +93 -0
  37. package/compiler/tsworkspace/result.go +17 -0
  38. package/compiler/typescript-emitter.go +459 -82
  39. package/compiler/wasm/compile.go +1 -1
  40. package/compiler/wasm/compile_test.go +61 -11
  41. package/compiler/wasm_api.go +172 -7
  42. package/dist/gs/builtin/builtin.d.ts +20 -2
  43. package/dist/gs/builtin/builtin.js +194 -6
  44. package/dist/gs/builtin/builtin.js.map +1 -1
  45. package/dist/gs/builtin/channel.d.ts +8 -0
  46. package/dist/gs/builtin/channel.js +12 -0
  47. package/dist/gs/builtin/channel.js.map +1 -1
  48. package/dist/gs/builtin/slice.d.ts +22 -2
  49. package/dist/gs/builtin/slice.js +216 -44
  50. package/dist/gs/builtin/slice.js.map +1 -1
  51. package/dist/gs/builtin/type.d.ts +5 -2
  52. package/dist/gs/builtin/type.js +83 -24
  53. package/dist/gs/builtin/type.js.map +1 -1
  54. package/dist/gs/builtin/varRef.d.ts +5 -0
  55. package/dist/gs/builtin/varRef.js +23 -0
  56. package/dist/gs/builtin/varRef.js.map +1 -1
  57. package/dist/gs/bytes/buffer.gs.js +48 -44
  58. package/dist/gs/bytes/buffer.gs.js.map +1 -1
  59. package/dist/gs/bytes/reader.gs.js +20 -18
  60. package/dist/gs/bytes/reader.gs.js.map +1 -1
  61. package/dist/gs/context/context.d.ts +5 -4
  62. package/dist/gs/context/context.js +10 -10
  63. package/dist/gs/context/context.js.map +1 -1
  64. package/dist/gs/crypto/internal/fips140deps/byteorder/index.d.ts +1 -0
  65. package/dist/gs/crypto/internal/fips140deps/byteorder/index.js +2 -0
  66. package/dist/gs/crypto/internal/fips140deps/byteorder/index.js.map +1 -0
  67. package/dist/gs/crypto/internal/fips140deps/godebug/index.d.ts +1 -0
  68. package/dist/gs/crypto/internal/fips140deps/godebug/index.js +2 -0
  69. package/dist/gs/crypto/internal/fips140deps/godebug/index.js.map +1 -0
  70. package/dist/gs/embed/index.d.ts +7 -0
  71. package/dist/gs/embed/index.js +16 -0
  72. package/dist/gs/embed/index.js.map +1 -0
  73. package/dist/gs/encoding/json/index.d.ts +1 -0
  74. package/dist/gs/encoding/json/index.js +18 -0
  75. package/dist/gs/encoding/json/index.js.map +1 -1
  76. package/dist/gs/errors/errors.d.ts +4 -0
  77. package/dist/gs/errors/errors.js +81 -0
  78. package/dist/gs/errors/errors.js.map +1 -1
  79. package/dist/gs/fmt/fmt.d.ts +4 -4
  80. package/dist/gs/fmt/fmt.js +42 -11
  81. package/dist/gs/fmt/fmt.js.map +1 -1
  82. package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/index.d.ts +35 -0
  83. package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/index.js +211 -1
  84. package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/index.js.map +1 -1
  85. package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/json/index.d.ts +189 -0
  86. package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/json/index.js +825 -0
  87. package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/json/index.js.map +1 -0
  88. package/dist/gs/github.com/aperturerobotics/starpc/srpc/index.d.ts +163 -0
  89. package/dist/gs/github.com/aperturerobotics/starpc/srpc/index.js +449 -0
  90. package/dist/gs/github.com/aperturerobotics/starpc/srpc/index.js.map +1 -0
  91. package/dist/gs/github.com/klauspost/compress/internal/le/index.d.ts +9 -0
  92. package/dist/gs/github.com/klauspost/compress/internal/le/index.js +71 -0
  93. package/dist/gs/github.com/klauspost/compress/internal/le/index.js.map +1 -0
  94. package/dist/gs/go/internal/scannerhooks/index.d.ts +3 -0
  95. package/dist/gs/go/internal/scannerhooks/index.js +5 -0
  96. package/dist/gs/go/internal/scannerhooks/index.js.map +1 -0
  97. package/dist/gs/go/scanner/index.d.ts +13 -0
  98. package/dist/gs/go/scanner/index.js +35 -0
  99. package/dist/gs/go/scanner/index.js.map +1 -1
  100. package/dist/gs/go/token/index.d.ts +156 -0
  101. package/dist/gs/go/token/index.js +500 -4
  102. package/dist/gs/go/token/index.js.map +1 -1
  103. package/dist/gs/internal/abi/index.d.ts +4 -0
  104. package/dist/gs/internal/abi/index.js +10 -0
  105. package/dist/gs/internal/abi/index.js.map +1 -1
  106. package/dist/gs/internal/bytealg/index.d.ts +2 -0
  107. package/dist/gs/internal/bytealg/index.js +14 -0
  108. package/dist/gs/internal/bytealg/index.js.map +1 -1
  109. package/dist/gs/internal/byteorder/index.d.ts +8 -2
  110. package/dist/gs/internal/byteorder/index.js +56 -25
  111. package/dist/gs/internal/byteorder/index.js.map +1 -1
  112. package/dist/gs/internal/godebug/index.d.ts +12 -0
  113. package/dist/gs/internal/godebug/index.js +30 -0
  114. package/dist/gs/internal/godebug/index.js.map +1 -0
  115. package/dist/gs/io/fs/index.d.ts +1 -0
  116. package/dist/gs/io/fs/index.js +1 -0
  117. package/dist/gs/io/fs/index.js.map +1 -1
  118. package/dist/gs/io/fs/readlink.d.ts +8 -0
  119. package/dist/gs/io/fs/readlink.js +64 -0
  120. package/dist/gs/io/fs/readlink.js.map +1 -0
  121. package/dist/gs/io/fs/walk.d.ts +3 -3
  122. package/dist/gs/io/fs/walk.js +7 -7
  123. package/dist/gs/io/fs/walk.js.map +1 -1
  124. package/dist/gs/io/io.d.ts +40 -6
  125. package/dist/gs/io/io.js +151 -26
  126. package/dist/gs/io/io.js.map +1 -1
  127. package/dist/gs/maps/iter.d.ts +3 -3
  128. package/dist/gs/maps/iter.js +3 -3
  129. package/dist/gs/maps/iter.js.map +1 -1
  130. package/dist/gs/maps/maps.d.ts +2 -2
  131. package/dist/gs/maps/maps.js +1 -1
  132. package/dist/gs/maps/maps.js.map +1 -1
  133. package/dist/gs/math/bits/index.d.ts +13 -4
  134. package/dist/gs/math/bits/index.js +66 -34
  135. package/dist/gs/math/bits/index.js.map +1 -1
  136. package/dist/gs/math/const.gs.d.ts +5 -5
  137. package/dist/gs/math/const.gs.js +4 -4
  138. package/dist/gs/math/const.gs.js.map +1 -1
  139. package/dist/gs/mime/index.d.ts +1 -0
  140. package/dist/gs/mime/index.js +50 -0
  141. package/dist/gs/mime/index.js.map +1 -0
  142. package/dist/gs/net/http/httptest/index.d.ts +11 -0
  143. package/dist/gs/net/http/httptest/index.js +21 -0
  144. package/dist/gs/net/http/httptest/index.js.map +1 -0
  145. package/dist/gs/net/http/index.d.ts +27 -0
  146. package/dist/gs/net/http/index.js +61 -0
  147. package/dist/gs/net/http/index.js.map +1 -0
  148. package/dist/gs/os/dir_unix.gs.js +2 -2
  149. package/dist/gs/os/dir_unix.gs.js.map +1 -1
  150. package/dist/gs/os/types_js.gs.js.map +1 -1
  151. package/dist/gs/path/filepath/match.js +165 -3
  152. package/dist/gs/path/filepath/match.js.map +1 -1
  153. package/dist/gs/path/filepath/path.d.ts +3 -1
  154. package/dist/gs/path/filepath/path.js +133 -4
  155. package/dist/gs/path/filepath/path.js.map +1 -1
  156. package/dist/gs/path/path.d.ts +4 -1
  157. package/dist/gs/path/path.js +16 -4
  158. package/dist/gs/path/path.js.map +1 -1
  159. package/dist/gs/reflect/index.d.ts +1 -1
  160. package/dist/gs/reflect/index.js +1 -1
  161. package/dist/gs/reflect/index.js.map +1 -1
  162. package/dist/gs/reflect/map.js +3 -0
  163. package/dist/gs/reflect/map.js.map +1 -1
  164. package/dist/gs/reflect/type.d.ts +7 -4
  165. package/dist/gs/reflect/type.js +148 -7
  166. package/dist/gs/reflect/type.js.map +1 -1
  167. package/dist/gs/runtime/debug/index.d.ts +2 -0
  168. package/dist/gs/runtime/debug/index.js +8 -0
  169. package/dist/gs/runtime/debug/index.js.map +1 -0
  170. package/dist/gs/runtime/runtime.d.ts +35 -3
  171. package/dist/gs/runtime/runtime.js +72 -0
  172. package/dist/gs/runtime/runtime.js.map +1 -1
  173. package/dist/gs/slices/slices.d.ts +24 -5
  174. package/dist/gs/slices/slices.js +214 -5
  175. package/dist/gs/slices/slices.js.map +1 -1
  176. package/dist/gs/sort/slice.gs.d.ts +3 -3
  177. package/dist/gs/sort/slice.gs.js +6 -6
  178. package/dist/gs/sort/slice.gs.js.map +1 -1
  179. package/dist/gs/sort/sort.gs.d.ts +4 -4
  180. package/dist/gs/sort/sort.gs.js +11 -8
  181. package/dist/gs/sort/sort.gs.js.map +1 -1
  182. package/dist/gs/strings/builder.d.ts +1 -1
  183. package/dist/gs/strings/builder.js +3 -2
  184. package/dist/gs/strings/builder.js.map +1 -1
  185. package/dist/gs/sync/atomic/type.gs.d.ts +9 -8
  186. package/dist/gs/sync/atomic/type.gs.js +0 -2
  187. package/dist/gs/sync/atomic/type.gs.js.map +1 -1
  188. package/dist/gs/sync/sync.d.ts +2 -0
  189. package/dist/gs/sync/sync.js +27 -0
  190. package/dist/gs/sync/sync.js.map +1 -1
  191. package/dist/gs/syscall/constants.d.ts +36 -24
  192. package/dist/gs/syscall/constants.js +12 -0
  193. package/dist/gs/syscall/constants.js.map +1 -1
  194. package/dist/gs/syscall/errors.d.ts +2 -0
  195. package/dist/gs/syscall/errors.js +8 -0
  196. package/dist/gs/syscall/errors.js.map +1 -1
  197. package/dist/gs/syscall/fs.d.ts +43 -0
  198. package/dist/gs/syscall/fs.js +102 -0
  199. package/dist/gs/syscall/fs.js.map +1 -1
  200. package/dist/gs/syscall/js/index.d.ts +90 -0
  201. package/dist/gs/syscall/js/index.js +375 -0
  202. package/dist/gs/syscall/js/index.js.map +1 -0
  203. package/dist/gs/syscall/types.d.ts +22 -0
  204. package/dist/gs/syscall/types.js +45 -1
  205. package/dist/gs/syscall/types.js.map +1 -1
  206. package/dist/gs/testing/index.d.ts +1 -0
  207. package/dist/gs/testing/index.js +2 -0
  208. package/dist/gs/testing/index.js.map +1 -0
  209. package/dist/gs/testing/testing.d.ts +77 -0
  210. package/dist/gs/testing/testing.js +301 -0
  211. package/dist/gs/testing/testing.js.map +1 -0
  212. package/dist/gs/time/time.d.ts +41 -4
  213. package/dist/gs/time/time.js +205 -36
  214. package/dist/gs/time/time.js.map +1 -1
  215. package/dist/gs/unicode/unicode.d.ts +23 -1
  216. package/dist/gs/unicode/unicode.js +79 -10
  217. package/dist/gs/unicode/unicode.js.map +1 -1
  218. package/dist/gs/unicode/utf8/utf8.d.ts +4 -4
  219. package/dist/gs/unicode/utf8/utf8.js +24 -11
  220. package/dist/gs/unicode/utf8/utf8.js.map +1 -1
  221. package/dist/gs/unique/index.d.ts +11 -0
  222. package/dist/gs/unique/index.js +71 -0
  223. package/dist/gs/unique/index.js.map +1 -0
  224. package/go.sum +9 -0
  225. package/gs/builtin/builtin.ts +239 -8
  226. package/gs/builtin/channel.ts +22 -0
  227. package/gs/builtin/runtime-contract.test.ts +126 -0
  228. package/gs/builtin/slice.ts +259 -50
  229. package/gs/builtin/type.ts +109 -34
  230. package/gs/builtin/varRef.ts +38 -1
  231. package/gs/bytes/buffer.gs.ts +48 -44
  232. package/gs/bytes/meta.json +8 -3
  233. package/gs/bytes/reader.gs.ts +20 -19
  234. package/gs/context/context.test.ts +41 -0
  235. package/gs/context/context.ts +22 -26
  236. package/gs/crypto/internal/fips140deps/byteorder/index.ts +1 -0
  237. package/gs/crypto/internal/fips140deps/godebug/index.ts +1 -0
  238. package/gs/embed/index.ts +20 -0
  239. package/gs/embed/meta.json +5 -0
  240. package/gs/encoding/json/index.test.ts +15 -1
  241. package/gs/encoding/json/index.ts +24 -0
  242. package/gs/errors/errors.test.ts +82 -0
  243. package/gs/errors/errors.ts +104 -0
  244. package/gs/fmt/fmt.ts +56 -16
  245. package/gs/github.com/aperturerobotics/protobuf-go-lite/index.test.ts +73 -1
  246. package/gs/github.com/aperturerobotics/protobuf-go-lite/index.ts +297 -1
  247. package/gs/github.com/aperturerobotics/protobuf-go-lite/json/index.test.ts +159 -0
  248. package/gs/github.com/aperturerobotics/protobuf-go-lite/json/index.ts +1005 -0
  249. package/gs/github.com/aperturerobotics/starpc/srpc/index.ts +719 -0
  250. package/gs/github.com/aperturerobotics/starpc/srpc/meta.json +40 -0
  251. package/gs/github.com/klauspost/compress/internal/le/index.test.ts +36 -0
  252. package/gs/github.com/klauspost/compress/internal/le/index.ts +114 -0
  253. package/gs/go/internal/scannerhooks/index.test.ts +14 -0
  254. package/gs/go/internal/scannerhooks/index.ts +9 -0
  255. package/gs/go/scanner/index.test.ts +22 -0
  256. package/gs/go/scanner/index.ts +47 -0
  257. package/gs/go/token/index.test.ts +47 -1
  258. package/gs/go/token/index.ts +570 -4
  259. package/gs/internal/abi/index.test.ts +18 -0
  260. package/gs/internal/abi/index.ts +14 -0
  261. package/gs/internal/bytealg/index.test.ts +18 -0
  262. package/gs/internal/bytealg/index.ts +16 -0
  263. package/gs/internal/byteorder/index.test.ts +39 -0
  264. package/gs/internal/byteorder/index.ts +100 -27
  265. package/gs/internal/godebug/index.test.ts +16 -0
  266. package/gs/internal/godebug/index.ts +35 -0
  267. package/gs/io/fs/index.ts +1 -0
  268. package/gs/io/fs/meta.json +5 -0
  269. package/gs/io/fs/readlink.test.ts +43 -0
  270. package/gs/io/fs/readlink.ts +77 -0
  271. package/gs/io/fs/walk.test.ts +61 -0
  272. package/gs/io/fs/walk.ts +9 -9
  273. package/gs/io/io.ts +174 -31
  274. package/gs/io/meta.json +10 -2
  275. package/gs/maps/iter.ts +12 -6
  276. package/gs/maps/maps.ts +8 -6
  277. package/gs/math/bits/index.ts +103 -47
  278. package/gs/math/const.gs.test.ts +11 -5
  279. package/gs/math/const.gs.ts +5 -6
  280. package/gs/mime/index.ts +54 -0
  281. package/gs/net/http/httptest/index.ts +25 -0
  282. package/gs/net/http/index.test.ts +20 -0
  283. package/gs/net/http/index.ts +81 -0
  284. package/gs/os/dir_unix.gs.ts +2 -3
  285. package/gs/os/types_js.gs.ts +2 -2
  286. package/gs/path/filepath/match.test.ts +31 -12
  287. package/gs/path/filepath/match.ts +178 -3
  288. package/gs/path/filepath/path.test.ts +25 -0
  289. package/gs/path/filepath/path.ts +159 -5
  290. package/gs/path/path.ts +20 -5
  291. package/gs/reflect/index.ts +1 -0
  292. package/gs/reflect/map.test.ts +19 -0
  293. package/gs/reflect/map.ts +4 -0
  294. package/gs/reflect/type.ts +197 -17
  295. package/gs/runtime/debug/index.test.ts +24 -0
  296. package/gs/runtime/debug/index.ts +8 -0
  297. package/gs/runtime/runtime.test.ts +19 -0
  298. package/gs/runtime/runtime.ts +98 -3
  299. package/gs/slices/slices.test.ts +94 -0
  300. package/gs/slices/slices.ts +245 -5
  301. package/gs/sort/meta.json +7 -0
  302. package/gs/sort/slice.gs.ts +16 -7
  303. package/gs/sort/sort.gs.ts +16 -13
  304. package/gs/strings/builder.ts +4 -3
  305. package/gs/sync/atomic/type.gs.ts +13 -14
  306. package/gs/sync/meta.json +3 -1
  307. package/gs/sync/sync.test.ts +13 -1
  308. package/gs/sync/sync.ts +27 -0
  309. package/gs/syscall/constants.ts +39 -24
  310. package/gs/syscall/errors.ts +10 -0
  311. package/gs/syscall/fs.ts +195 -0
  312. package/gs/syscall/js/index.ts +458 -0
  313. package/gs/syscall/js/meta.json +4 -0
  314. package/gs/syscall/net.test.ts +85 -0
  315. package/gs/syscall/types.ts +56 -0
  316. package/gs/testing/index.ts +1 -0
  317. package/gs/testing/meta.json +5 -0
  318. package/gs/testing/testing.test.ts +90 -0
  319. package/gs/testing/testing.ts +382 -0
  320. package/gs/time/time.test.ts +106 -0
  321. package/gs/time/time.ts +278 -57
  322. package/gs/unicode/unicode.test.ts +25 -0
  323. package/gs/unicode/unicode.ts +119 -9
  324. package/gs/unicode/utf8/utf8.test.ts +13 -0
  325. package/gs/unicode/utf8/utf8.ts +28 -16
  326. package/gs/unique/index.ts +91 -0
  327. package/package.json +2 -1
@@ -4,6 +4,8 @@ import { AddInt64, AddUint64, AndInt64, AndUint64, CompareAndSwapInt64, CompareA
4
4
 
5
5
  import * as unsafe from "@goscript/unsafe/index.js"
6
6
 
7
+ export type PointerValue<T> = T | $.VarRef<T> | null
8
+
7
9
  export class Bool {
8
10
  public get v(): number {
9
11
  return this._fields.v.value
@@ -74,18 +76,18 @@ export function b32(b: boolean): number {
74
76
 
75
77
 
76
78
  export class Pointer<T> {
77
- public get v(): $.VarRef<T> | null {
79
+ public get v(): PointerValue<T> {
78
80
  return this._fields.v.value
79
81
  }
80
- public set v(value: $.VarRef<T> | null) {
82
+ public set v(value: PointerValue<T>) {
81
83
  this._fields.v.value = value
82
84
  }
83
85
 
84
86
  public _fields: {
85
- v: $.VarRef<$.VarRef<T> | null>;
87
+ v: $.VarRef<PointerValue<T>>;
86
88
  }
87
89
 
88
- constructor(init?: Partial<{v?: $.VarRef<T> | null}>) {
90
+ constructor(init?: Partial<{v?: PointerValue<T>}>) {
89
91
  this._fields = {
90
92
  v: $.varRef(init?.v ?? null)
91
93
  }
@@ -100,14 +102,13 @@ export class Pointer<T> {
100
102
  }
101
103
 
102
104
  // Load atomically loads and returns the value stored in x.
103
- public Load(): $.VarRef<T> | null {
105
+ public Load(): PointerValue<T> {
104
106
  const x = this
105
- return LoadPointer(x._fields.v) as $.VarRef<T> | null
107
+ return LoadPointer(x._fields.v) as PointerValue<T>
106
108
  }
107
109
 
108
110
  // Store atomically stores val into x.
109
- // In Go, this takes *T which can be nil, so we accept VarRef<T> | null
110
- public Store(val: $.VarRef<T> | null): void {
111
+ public Store(val: PointerValue<T>): void {
111
112
  const x = this
112
113
  if (val === null) {
113
114
  StorePointer(x._fields.v, null)
@@ -117,17 +118,16 @@ export class Pointer<T> {
117
118
  }
118
119
 
119
120
  // Swap atomically stores new into x and returns the previous value.
120
- // In Go, this takes *T which can be nil, so we accept VarRef<T> | null
121
- public Swap(_new: $.VarRef<T> | null): $.VarRef<T> | null {
121
+ public Swap(_new: PointerValue<T>): PointerValue<T> {
122
122
  const x = this
123
123
  if (_new === null) {
124
- return SwapPointer(x._fields.v, null) as $.VarRef<T> | null
124
+ return SwapPointer(x._fields.v, null) as PointerValue<T>
125
125
  }
126
- return SwapPointer(x._fields.v, unsafe.Pointer(_new)) as $.VarRef<T> | null
126
+ return SwapPointer(x._fields.v, unsafe.Pointer(_new)) as PointerValue<T>
127
127
  }
128
128
 
129
129
  // CompareAndSwap executes the compare-and-swap operation for x.
130
- public CompareAndSwap(old: $.VarRef<T> | null, _new: $.VarRef<T> | null): boolean {
130
+ public CompareAndSwap(old: PointerValue<T>, _new: PointerValue<T>): boolean {
131
131
  const x = this
132
132
  return CompareAndSwapPointer(x._fields.v, old ? unsafe.Pointer(old) : null, _new ? unsafe.Pointer(_new) : null)
133
133
  }
@@ -598,4 +598,3 @@ class align64 {
598
598
  {}
599
599
  );
600
600
  }
601
-
package/gs/sync/meta.json CHANGED
@@ -9,11 +9,13 @@
9
9
  "WaitGroup.Wait": true,
10
10
  "Once.Do": true,
11
11
  "Cond.Wait": true,
12
+ "Map.CompareAndDelete": true,
12
13
  "Map.Delete": true,
13
14
  "Map.Load": true,
14
15
  "Map.LoadAndDelete": true,
15
16
  "Map.LoadOrStore": true,
16
17
  "Map.Range": true,
17
- "Map.Store": true
18
+ "Map.Store": true,
19
+ "Map.Swap": true
18
20
  }
19
21
  }
@@ -1,6 +1,6 @@
1
1
  import { describe, expect, it } from 'vitest'
2
2
 
3
- import { WaitGroup } from './sync.js'
3
+ import { Map, WaitGroup } from './sync.js'
4
4
 
5
5
  describe('sync.WaitGroup', () => {
6
6
  it('Go tracks scheduled work and unblocks Wait after completion', async () => {
@@ -22,3 +22,15 @@ describe('sync.WaitGroup', () => {
22
22
  expect(events).toEqual(['worker start', 'worker done', 'wait done'])
23
23
  })
24
24
  })
25
+
26
+ describe('sync.Map', () => {
27
+ it('CompareAndDelete deletes only matching entries', async () => {
28
+ const m = new Map()
29
+
30
+ await m.Store('key', 'value')
31
+ expect(await m.CompareAndDelete('key', 'other')).toBe(false)
32
+ expect(await m.Load('key')).toEqual(['value', true])
33
+ expect(await m.CompareAndDelete('key', 'value')).toBe(true)
34
+ expect(await m.Load('key')).toEqual([undefined, false])
35
+ })
36
+ })
package/gs/sync/sync.ts CHANGED
@@ -321,6 +321,20 @@ export class Map {
321
321
  }
322
322
  }
323
323
 
324
+ // CompareAndDelete deletes the entry for key if its value is equal to old.
325
+ public async CompareAndDelete(key: any, old: any): Promise<boolean> {
326
+ await this._m.Lock()
327
+ try {
328
+ if (!this._data.has(key) || this._data.get(key) !== old) {
329
+ return false
330
+ }
331
+ this._data.delete(key)
332
+ return true
333
+ } finally {
334
+ this._m.Unlock()
335
+ }
336
+ }
337
+
324
338
  // Load returns the value stored in the map for a key, or nil if no value is present
325
339
  public async Load(key: any): Promise<[any, boolean]> {
326
340
  await this._m.RLock()
@@ -383,6 +397,19 @@ export class Map {
383
397
  }
384
398
  }
385
399
 
400
+ // Swap swaps the value for a key and returns the previous value if any
401
+ public async Swap(key: any, value: any): Promise<[any, boolean]> {
402
+ await this._m.Lock()
403
+ try {
404
+ const previous = this._data.get(key)
405
+ const loaded = this._data.has(key)
406
+ this._data.set(key, value)
407
+ return [previous, loaded]
408
+ } finally {
409
+ this._m.Unlock()
410
+ }
411
+ }
412
+
386
413
  // clone returns a copy of this Map instance
387
414
  public clone(): Map {
388
415
  return new Map()
@@ -1,29 +1,44 @@
1
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
2
+ export const O_RDONLY: number = 0
3
+ export const O_WRONLY: number = 1
4
+ export const O_RDWR: number = 2
5
+ export const O_APPEND: number = 8
6
+ export const O_CREATE: number = 64
7
+ export const O_EXCL: number = 128
8
+ export const O_SYNC: number = 256
9
+ export const O_TRUNC: number = 512
10
10
 
11
- export const Stdin = 0
12
- export const Stdout = 1
13
- export const Stderr = 2
11
+ export const Stdin: number = 0
12
+ export const Stdout: number = 1
13
+ export const Stderr: number = 2
14
14
 
15
- export const SIGINT = 2
16
- export const SIGTERM = 15
15
+ export const SIGINT: number = 2
16
+ export const SIGTERM: number = 15
17
+
18
+ export const AF_UNIX: number = 1
19
+ export const AF_INET: number = 2
20
+ export const AF_INET6: number = 10
21
+
22
+ export const SOCK_STREAM: number = 1
23
+ export const SOCK_DGRAM: number = 2
24
+ export const SOCK_RAW: number = 3
25
+ export const SOCK_SEQPACKET: number = 5
26
+
27
+ export const IPPROTO_IPV6: number = 0x29
28
+ export const IPPROTO_TCP: number = 6
29
+ export const IPV6_V6ONLY: number = 0x1a
30
+ export const SOMAXCONN: number = 0x80
31
+ export const F_DUPFD_CLOEXEC: number = 1
17
32
 
18
33
  // 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
34
+ export const S_IFMT: number = 0o170000
35
+ export const S_IFREG: number = 0o100000
36
+ export const S_IFDIR: number = 0o040000
37
+ export const S_IFLNK: number = 0o120000
38
+ export const S_IFBLK: number = 0o060000
39
+ export const S_IFCHR: number = 0o020000
40
+ export const S_IFIFO: number = 0o010000
41
+ export const S_IFSOCK: number = 0o140000
42
+ export const S_ISUID: number = 0o004000
43
+ export const S_ISGID: number = 0o002000
44
+ export const S_ISVTX: number = 0o001000
@@ -1,6 +1,10 @@
1
1
  import * as $ from '@goscript/builtin/index.js'
2
2
  import { Errno } from './types.js'
3
3
 
4
+ export function Errno_Error(errno: Errno): string {
5
+ return errno.Error()
6
+ }
7
+
4
8
  export const EPERM: Errno = {
5
9
  Error: () => 'operation not permitted',
6
10
  Is: (target: $.GoError) => target === EPERM,
@@ -217,6 +221,12 @@ export const ENOSYS: Errno = {
217
221
  Errno: () => 38,
218
222
  }
219
223
 
224
+ export const ENOTSUP: Errno = {
225
+ Error: () => 'operation not supported',
226
+ Is: (target: $.GoError) => target === ENOTSUP,
227
+ Errno: () => 95,
228
+ }
229
+
220
230
  export const ENOTEMPTY: Errno = {
221
231
  Error: () => 'directory not empty',
222
232
  Is: (target: $.GoError) => target === ENOTEMPTY,
package/gs/syscall/fs.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import * as $ from '@goscript/builtin/index.js'
2
+ import { RWMutex } from '@goscript/sync/index.js'
2
3
  import { ENOSYS } from './errors.js'
4
+ import type { Iovec, Sockaddr } from './types.js'
3
5
 
4
6
  // Dirent structure with Reclen field
5
7
  export class Dirent {
@@ -54,9 +56,202 @@ export function Sysctl(_name: string): [string, $.GoError] {
54
56
  return ['', ENOSYS]
55
57
  }
56
58
 
59
+ export function Unlink(_path: string): $.GoError {
60
+ return ENOSYS
61
+ }
62
+
63
+ export const ForkLock = new RWMutex()
64
+
65
+ export function Close(_fd: number): $.GoError {
66
+ return null
67
+ }
68
+
69
+ export function CloseOnExec(_fd: number): void {}
70
+
71
+ export function SetNonblock(_fd: number, _nonblocking: boolean): $.GoError {
72
+ return null
73
+ }
74
+
75
+ export function Fchdir(_fd: number): $.GoError {
76
+ return ENOSYS
77
+ }
78
+
79
+ export function Fchmod(_fd: number, _mode: number): $.GoError {
80
+ return ENOSYS
81
+ }
82
+
83
+ export function Fchown(_fd: number, _uid: number, _gid: number): $.GoError {
84
+ return ENOSYS
85
+ }
86
+
87
+ export function Fstat(
88
+ _fd: number,
89
+ _stat: Stat_t | $.VarRef<Stat_t> | null,
90
+ ): $.GoError {
91
+ return ENOSYS
92
+ }
93
+
94
+ export function Fsync(_fd: number): $.GoError {
95
+ return ENOSYS
96
+ }
97
+
98
+ export function Ftruncate(_fd: number, _length: number): $.GoError {
99
+ return ENOSYS
100
+ }
101
+
102
+ export function Read(_fd: number, _b: $.Bytes | null): [number, $.GoError] {
103
+ return [0, ENOSYS]
104
+ }
105
+
106
+ export function ReadDirent(
107
+ _fd: number,
108
+ _buf: $.Bytes | null,
109
+ ): [number, $.GoError] {
110
+ return [0, ENOSYS]
111
+ }
112
+
113
+ export function Pread(
114
+ _fd: number,
115
+ _b: $.Bytes | null,
116
+ _offset: number,
117
+ ): [number, $.GoError] {
118
+ return [0, ENOSYS]
119
+ }
120
+
121
+ export function Pwrite(
122
+ _fd: number,
123
+ _b: $.Bytes | null,
124
+ _offset: number,
125
+ ): [number, $.GoError] {
126
+ return [0, ENOSYS]
127
+ }
128
+
129
+ export function Seek(
130
+ _fd: number,
131
+ _offset: number,
132
+ _whence: number,
133
+ ): [number, $.GoError] {
134
+ return [0, ENOSYS]
135
+ }
136
+
137
+ export function Write(_fd: number, _b: $.Bytes | null): [number, $.GoError] {
138
+ return [0, ENOSYS]
139
+ }
140
+
141
+ export function Dup(_fd: number): [number, $.GoError] {
142
+ return [0, ENOSYS]
143
+ }
144
+
57
145
  // Getpagesize returns the underlying system's memory page size.
58
146
  export function Getpagesize(): number {
59
147
  // Return a standard page size for JavaScript environment
60
148
  // Most systems use 4096 bytes as the default page size
61
149
  return 4096
62
150
  }
151
+
152
+ export function Socket(
153
+ _domain: number,
154
+ _typ: number,
155
+ _proto: number,
156
+ ): [number, $.GoError] {
157
+ return [-1, ENOSYS]
158
+ }
159
+
160
+ export function Connect(_fd: number, _sa: Sockaddr | null): $.GoError {
161
+ return ENOSYS
162
+ }
163
+
164
+ export function Listen(_fd: number, _backlog: number): $.GoError {
165
+ return ENOSYS
166
+ }
167
+
168
+ export function Bind(_fd: number, _sa: Sockaddr | null): $.GoError {
169
+ return ENOSYS
170
+ }
171
+
172
+ export function StopIO(_fd: number): $.GoError {
173
+ return ENOSYS
174
+ }
175
+
176
+ export function Accept(_fd: number): [number, Sockaddr | null, $.GoError] {
177
+ return [0, null, ENOSYS]
178
+ }
179
+
180
+ export function Recvfrom(
181
+ _fd: number,
182
+ _p: $.Bytes | null,
183
+ _flags: number,
184
+ ): [number, Sockaddr | null, $.GoError] {
185
+ return [0, null, ENOSYS]
186
+ }
187
+
188
+ export function Sendto(
189
+ _fd: number,
190
+ _p: $.Bytes | null,
191
+ _flags: number,
192
+ _to: Sockaddr | null,
193
+ ): $.GoError {
194
+ return ENOSYS
195
+ }
196
+
197
+ export function Recvmsg(
198
+ _fd: number,
199
+ _p: $.Bytes | null,
200
+ _oob: $.Bytes | null,
201
+ _flags: number,
202
+ ): [number, number, number, Sockaddr | null, $.GoError] {
203
+ return [0, 0, 0, null, ENOSYS]
204
+ }
205
+
206
+ export function SendmsgN(
207
+ _fd: number,
208
+ _p: $.Bytes | null,
209
+ _oob: $.Bytes | null,
210
+ _to: Sockaddr | null,
211
+ _flags: number,
212
+ ): [number, $.GoError] {
213
+ return [0, ENOSYS]
214
+ }
215
+
216
+ export function SetReadDeadline(_fd: number, _t: number): $.GoError {
217
+ return ENOSYS
218
+ }
219
+
220
+ export function SetWriteDeadline(_fd: number, _t: number): $.GoError {
221
+ return ENOSYS
222
+ }
223
+
224
+ export function Shutdown(_fd: number, _how: number): $.GoError {
225
+ return ENOSYS
226
+ }
227
+
228
+ export function GetsockoptInt(
229
+ _fd: number,
230
+ _level: number,
231
+ _opt: number,
232
+ ): [number, $.GoError] {
233
+ return [0, ENOSYS]
234
+ }
235
+
236
+ export function SetsockoptInt(
237
+ _fd: number,
238
+ _level: number,
239
+ _opt: number,
240
+ _value: number,
241
+ ): $.GoError {
242
+ return null
243
+ }
244
+
245
+ export function readv(_fd: number, _iovecs: $.Slice<Iovec> | null): [
246
+ number,
247
+ $.GoError,
248
+ ] {
249
+ return [0, ENOSYS]
250
+ }
251
+
252
+ export function writev(_fd: number, _iovecs: $.Slice<Iovec> | null): [
253
+ number,
254
+ $.GoError,
255
+ ] {
256
+ return [0, ENOSYS]
257
+ }