goscript 0.0.26 → 0.0.29

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/README.md +4 -4
  2. package/cmd/goscript/cmd_compile.go +0 -3
  3. package/cmd/goscript/deps.go +11 -0
  4. package/compiler/analysis.go +298 -55
  5. package/compiler/assignment.go +2 -2
  6. package/compiler/builtin_test.go +1 -1
  7. package/compiler/compiler.go +200 -68
  8. package/compiler/compiler_test.go +17 -24
  9. package/compiler/composite-lit.go +32 -8
  10. package/compiler/decl.go +6 -6
  11. package/compiler/expr-call.go +170 -15
  12. package/compiler/expr-selector.go +100 -0
  13. package/compiler/expr.go +1 -1
  14. package/compiler/protobuf.go +557 -0
  15. package/compiler/spec-struct.go +4 -0
  16. package/compiler/spec-value.go +89 -10
  17. package/compiler/spec.go +254 -1
  18. package/compiler/stmt-assign.go +35 -0
  19. package/compiler/type-assert.go +87 -0
  20. package/compiler/type.go +4 -1
  21. package/dist/gs/builtin/builtin.d.ts +20 -1
  22. package/dist/gs/builtin/builtin.js +95 -4
  23. package/dist/gs/builtin/builtin.js.map +1 -1
  24. package/dist/gs/builtin/slice.d.ts +1 -1
  25. package/dist/gs/builtin/slice.js +21 -2
  26. package/dist/gs/builtin/slice.js.map +1 -1
  27. package/dist/gs/errors/errors.d.ts +5 -6
  28. package/dist/gs/errors/errors.js.map +1 -1
  29. package/dist/gs/internal/oserror/errors.d.ts +6 -0
  30. package/dist/gs/internal/oserror/errors.js +7 -0
  31. package/dist/gs/internal/oserror/errors.js.map +1 -0
  32. package/dist/gs/internal/oserror/index.d.ts +1 -0
  33. package/dist/gs/internal/oserror/index.js +2 -0
  34. package/dist/gs/internal/oserror/index.js.map +1 -0
  35. package/dist/gs/io/fs/format.d.ts +3 -0
  36. package/dist/gs/io/fs/format.js +56 -0
  37. package/dist/gs/io/fs/format.js.map +1 -0
  38. package/dist/gs/io/fs/fs.d.ts +79 -0
  39. package/dist/gs/io/fs/fs.js +200 -0
  40. package/dist/gs/io/fs/fs.js.map +1 -0
  41. package/dist/gs/io/fs/glob.d.ts +10 -0
  42. package/dist/gs/io/fs/glob.js +141 -0
  43. package/dist/gs/io/fs/glob.js.map +1 -0
  44. package/dist/gs/io/fs/index.d.ts +8 -0
  45. package/dist/gs/io/fs/index.js +9 -0
  46. package/dist/gs/io/fs/index.js.map +1 -0
  47. package/dist/gs/io/fs/readdir.d.ts +7 -0
  48. package/dist/gs/io/fs/readdir.js +152 -0
  49. package/dist/gs/io/fs/readdir.js.map +1 -0
  50. package/dist/gs/io/fs/readfile.d.ts +6 -0
  51. package/dist/gs/io/fs/readfile.js +118 -0
  52. package/dist/gs/io/fs/readfile.js.map +1 -0
  53. package/dist/gs/io/fs/stat.d.ts +6 -0
  54. package/dist/gs/io/fs/stat.js +87 -0
  55. package/dist/gs/io/fs/stat.js.map +1 -0
  56. package/dist/gs/io/fs/sub.d.ts +6 -0
  57. package/dist/gs/io/fs/sub.js +172 -0
  58. package/dist/gs/io/fs/sub.js.map +1 -0
  59. package/dist/gs/io/fs/walk.d.ts +7 -0
  60. package/dist/gs/io/fs/walk.js +76 -0
  61. package/dist/gs/io/fs/walk.js.map +1 -0
  62. package/dist/gs/io/index.d.ts +1 -0
  63. package/dist/gs/io/index.js +2 -0
  64. package/dist/gs/io/index.js.map +1 -0
  65. package/dist/gs/io/io.d.ts +107 -0
  66. package/dist/gs/io/io.js +385 -0
  67. package/dist/gs/io/io.js.map +1 -0
  68. package/dist/gs/path/index.d.ts +2 -0
  69. package/dist/gs/path/index.js +3 -0
  70. package/dist/gs/path/index.js.map +1 -0
  71. package/dist/gs/path/match.d.ts +6 -0
  72. package/dist/gs/path/match.js +281 -0
  73. package/dist/gs/path/match.js.map +1 -0
  74. package/dist/gs/path/path.d.ts +7 -0
  75. package/dist/gs/path/path.js +256 -0
  76. package/dist/gs/path/path.js.map +1 -0
  77. package/dist/gs/strings/builder.d.ts +18 -0
  78. package/dist/gs/strings/builder.js +205 -0
  79. package/dist/gs/strings/builder.js.map +1 -0
  80. package/dist/gs/strings/clone.d.ts +1 -0
  81. package/dist/gs/strings/clone.js +16 -0
  82. package/dist/gs/strings/clone.js.map +1 -0
  83. package/dist/gs/strings/compare.d.ts +1 -0
  84. package/dist/gs/strings/compare.js +14 -0
  85. package/dist/gs/strings/compare.js.map +1 -0
  86. package/dist/gs/strings/index.d.ts +2 -0
  87. package/dist/gs/strings/index.js +3 -0
  88. package/dist/gs/strings/index.js.map +1 -0
  89. package/dist/gs/strings/iter.d.ts +8 -0
  90. package/dist/gs/strings/iter.js +160 -0
  91. package/dist/gs/strings/iter.js.map +1 -0
  92. package/dist/gs/strings/reader.d.ts +34 -0
  93. package/dist/gs/strings/reader.js +418 -0
  94. package/dist/gs/strings/reader.js.map +1 -0
  95. package/dist/gs/strings/replace.d.ts +106 -0
  96. package/dist/gs/strings/replace.js +1136 -0
  97. package/dist/gs/strings/replace.js.map +1 -0
  98. package/dist/gs/strings/search.d.ts +24 -0
  99. package/dist/gs/strings/search.js +169 -0
  100. package/dist/gs/strings/search.js.map +1 -0
  101. package/dist/gs/strings/strings.d.ts +47 -0
  102. package/dist/gs/strings/strings.js +418 -0
  103. package/dist/gs/strings/strings.js.map +1 -0
  104. package/dist/gs/stringslite/index.d.ts +1 -0
  105. package/dist/gs/stringslite/index.js +2 -0
  106. package/dist/gs/stringslite/index.js.map +1 -0
  107. package/dist/gs/stringslite/strings.d.ts +11 -0
  108. package/dist/gs/stringslite/strings.js +67 -0
  109. package/dist/gs/stringslite/strings.js.map +1 -0
  110. package/dist/gs/sync/index.d.ts +1 -0
  111. package/dist/gs/sync/index.js +2 -0
  112. package/dist/gs/sync/index.js.map +1 -0
  113. package/dist/gs/sync/sync.d.ts +79 -0
  114. package/dist/gs/sync/sync.js +392 -0
  115. package/dist/gs/sync/sync.js.map +1 -0
  116. package/dist/gs/time/time.d.ts +11 -2
  117. package/dist/gs/time/time.js +337 -12
  118. package/dist/gs/time/time.js.map +1 -1
  119. package/dist/gs/unicode/index.d.ts +1 -0
  120. package/dist/gs/unicode/index.js +2 -0
  121. package/dist/gs/unicode/index.js.map +1 -0
  122. package/dist/gs/unicode/unicode.d.ts +105 -0
  123. package/dist/gs/unicode/unicode.js +332 -0
  124. package/dist/gs/unicode/unicode.js.map +1 -0
  125. package/dist/gs/unicode/utf8/index.d.ts +1 -0
  126. package/dist/gs/unicode/utf8/index.js +3 -0
  127. package/dist/gs/unicode/utf8/index.js.map +1 -0
  128. package/dist/gs/unicode/utf8/utf8.d.ts +20 -0
  129. package/dist/gs/unicode/utf8/utf8.js +196 -0
  130. package/dist/gs/unicode/utf8/utf8.js.map +1 -0
  131. package/dist/gs/unsafe/index.d.ts +1 -0
  132. package/dist/gs/unsafe/index.js +2 -0
  133. package/dist/gs/unsafe/index.js.map +1 -0
  134. package/dist/gs/unsafe/unsafe.d.ts +11 -0
  135. package/dist/gs/unsafe/unsafe.js +44 -0
  136. package/dist/gs/unsafe/unsafe.js.map +1 -0
  137. package/go.mod +2 -1
  138. package/go.sum +6 -2
  139. package/gs/README.md +6 -0
  140. package/gs/builtin/builtin.ts +171 -0
  141. package/gs/builtin/channel.ts +683 -0
  142. package/gs/builtin/defer.ts +58 -0
  143. package/gs/builtin/index.ts +1 -0
  144. package/gs/builtin/io.ts +22 -0
  145. package/gs/builtin/map.ts +50 -0
  146. package/gs/builtin/slice.ts +1030 -0
  147. package/gs/builtin/type.ts +1106 -0
  148. package/gs/builtin/varRef.ts +25 -0
  149. package/gs/cmp/godoc.txt +8 -0
  150. package/gs/cmp/index.ts +29 -0
  151. package/gs/context/context.ts +401 -0
  152. package/gs/context/godoc.txt +69 -0
  153. package/gs/context/index.ts +1 -0
  154. package/gs/errors/errors.ts +223 -0
  155. package/gs/errors/godoc.txt +63 -0
  156. package/gs/errors/index.ts +1 -0
  157. package/gs/internal/goarch/godoc.txt +39 -0
  158. package/gs/internal/goarch/index.ts +18 -0
  159. package/gs/internal/oserror/errors.ts +14 -0
  160. package/gs/internal/oserror/index.ts +1 -0
  161. package/gs/io/fs/format.ts +65 -0
  162. package/gs/io/fs/fs.ts +359 -0
  163. package/gs/io/fs/glob.ts +167 -0
  164. package/gs/io/fs/godoc.txt +35 -0
  165. package/gs/io/fs/index.ts +8 -0
  166. package/gs/io/fs/readdir.ts +126 -0
  167. package/gs/io/fs/readfile.ts +77 -0
  168. package/gs/io/fs/stat.ts +38 -0
  169. package/gs/io/fs/sub.ts +208 -0
  170. package/gs/io/fs/walk.ts +89 -0
  171. package/gs/io/godoc.txt +61 -0
  172. package/gs/io/index.ts +1 -0
  173. package/gs/io/io.go +75 -0
  174. package/gs/io/io.ts +546 -0
  175. package/gs/iter/godoc.txt +203 -0
  176. package/gs/iter/index.ts +1 -0
  177. package/gs/iter/iter.ts +117 -0
  178. package/gs/math/bits/index.ts +356 -0
  179. package/gs/math/godoc.txt +76 -0
  180. package/gs/path/index.ts +2 -0
  181. package/gs/path/match.ts +307 -0
  182. package/gs/path/path.ts +301 -0
  183. package/gs/runtime/godoc.txt +331 -0
  184. package/gs/runtime/index.ts +1 -0
  185. package/gs/runtime/runtime.ts +178 -0
  186. package/gs/slices/godoc.txt +44 -0
  187. package/gs/slices/index.ts +1 -0
  188. package/gs/slices/slices.ts +22 -0
  189. package/gs/strings/builder.test.ts +121 -0
  190. package/gs/strings/builder.ts +223 -0
  191. package/gs/strings/clone.test.ts +43 -0
  192. package/gs/strings/clone.ts +17 -0
  193. package/gs/strings/compare.test.ts +84 -0
  194. package/gs/strings/compare.ts +13 -0
  195. package/gs/strings/godoc.txt +66 -0
  196. package/gs/strings/index.ts +2 -0
  197. package/gs/strings/iter.test.ts +343 -0
  198. package/gs/strings/iter.ts +171 -0
  199. package/gs/strings/reader.test.ts +242 -0
  200. package/gs/strings/reader.ts +451 -0
  201. package/gs/strings/replace.test.ts +181 -0
  202. package/gs/strings/replace.ts +1310 -0
  203. package/gs/strings/search.test.ts +214 -0
  204. package/gs/strings/search.ts +213 -0
  205. package/gs/strings/strings.test.ts +477 -0
  206. package/gs/strings/strings.ts +510 -0
  207. package/gs/stringslite/godoc.txt +17 -0
  208. package/gs/stringslite/index.ts +1 -0
  209. package/gs/stringslite/strings.ts +82 -0
  210. package/gs/sync/godoc.txt +21 -0
  211. package/gs/sync/index.ts +1 -0
  212. package/gs/sync/sync.go +64 -0
  213. package/gs/sync/sync.ts +449 -0
  214. package/gs/time/godoc.txt +116 -0
  215. package/gs/time/index.ts +1 -0
  216. package/gs/time/time.ts +585 -0
  217. package/gs/unicode/godoc.txt +52 -0
  218. package/gs/unicode/index.ts +1 -0
  219. package/gs/unicode/unicode.go +38 -0
  220. package/gs/unicode/unicode.ts +418 -0
  221. package/gs/unicode/utf8/godoc.txt +22 -0
  222. package/gs/unicode/utf8/index.ts +2 -0
  223. package/gs/unicode/utf8/utf8.ts +227 -0
  224. package/gs/unsafe/godoc.txt +19 -0
  225. package/gs/unsafe/index.ts +1 -0
  226. package/gs/unsafe/unsafe.test.ts +68 -0
  227. package/gs/unsafe/unsafe.ts +77 -0
  228. package/package.json +4 -3
@@ -0,0 +1,331 @@
1
+ package runtime // import "runtime"
2
+
3
+ Package runtime contains operations that interact with Go's runtime system,
4
+ such as functions to control goroutines. It also includes the low-level type
5
+ information used by the reflect package; see reflect's documentation for the
6
+ programmable interface to the run-time type system.
7
+
8
+ # Environment Variables
9
+
10
+ The following environment variables ($name or %name%, depending on the host
11
+ operating system) control the run-time behavior of Go programs. The meanings and
12
+ use may change from release to release.
13
+
14
+ The GOGC variable sets the initial garbage collection target percentage.
15
+ A collection is triggered when the ratio of freshly allocated data to live
16
+ data remaining after the previous collection reaches this percentage. The
17
+ default is GOGC=100. Setting GOGC=off disables the garbage collector entirely.
18
+ runtime/debug.SetGCPercent allows changing this percentage at run time.
19
+
20
+ The GOMEMLIMIT variable sets a soft memory limit for the runtime. This memory
21
+ limit includes the Go heap and all other memory managed by the runtime, and
22
+ excludes external memory sources such as mappings of the binary itself, memory
23
+ managed in other languages, and memory held by the operating system on behalf
24
+ of the Go program. GOMEMLIMIT is a numeric value in bytes with an optional unit
25
+ suffix. The supported suffixes include B, KiB, MiB, GiB, and TiB. These suffixes
26
+ represent quantities of bytes as defined by the IEC 80000-13 standard. That is,
27
+ they are based on powers of two: KiB means 2^10 bytes, MiB means 2^20 bytes,
28
+ and so on. The default setting is math.MaxInt64, which effectively disables the
29
+ memory limit. runtime/debug.SetMemoryLimit allows changing this limit at run
30
+ time.
31
+
32
+ The GODEBUG variable controls debugging variables within the runtime. It is a
33
+ comma-separated list of name=val pairs setting these named variables:
34
+
35
+ clobberfree: setting clobberfree=1 causes the garbage collector to
36
+ clobber the memory content of an object with bad content when it frees
37
+ the object.
38
+
39
+ cpu.*: cpu.all=off disables the use of all optional instruction set extensions.
40
+ cpu.extension=off disables use of instructions from the specified instruction set extension.
41
+ extension is the lower case name for the instruction set extension such as sse41 or avx
42
+ as listed in internal/cpu package. As an example cpu.avx=off disables runtime detection
43
+ and thereby use of AVX instructions.
44
+
45
+ cgocheck: setting cgocheck=0 disables all checks for packages
46
+ using cgo to incorrectly pass Go pointers to non-Go code.
47
+ Setting cgocheck=1 (the default) enables relatively cheap
48
+ checks that may miss some errors. A more complete, but slow,
49
+ cgocheck mode can be enabled using GOEXPERIMENT (which
50
+ requires a rebuild), see https://pkg.go.dev/internal/goexperiment for details.
51
+
52
+ disablethp: setting disablethp=1 on Linux disables transparent huge pages for the heap.
53
+ It has no effect on other platforms. disablethp is meant for compatibility with versions
54
+ of Go before 1.21, which stopped working around a Linux kernel default that can result
55
+ in significant memory overuse. See https://go.dev/issue/64332. This setting will be
56
+ removed in a future release, so operators should tweak their Linux configuration to suit
57
+ their needs before then. See https://go.dev/doc/gc-guide#Linux_transparent_huge_pages.
58
+
59
+ dontfreezetheworld: by default, the start of a fatal panic or throw
60
+ "freezes the world", preempting all threads to stop all running
61
+ goroutines, which makes it possible to traceback all goroutines, and
62
+ keeps their state close to the point of panic. Setting
63
+ dontfreezetheworld=1 disables this preemption, allowing goroutines to
64
+ continue executing during panic processing. Note that goroutines that
65
+ naturally enter the scheduler will still stop. This can be useful when
66
+ debugging the runtime scheduler, as freezetheworld perturbs scheduler
67
+ state and thus may hide problems.
68
+
69
+ efence: setting efence=1 causes the allocator to run in a mode
70
+ where each object is allocated on a unique page and addresses are
71
+ never recycled.
72
+
73
+ gccheckmark: setting gccheckmark=1 enables verification of the
74
+ garbage collector's concurrent mark phase by performing a
75
+ second mark pass while the world is stopped. If the second
76
+ pass finds a reachable object that was not found by concurrent
77
+ mark, the garbage collector will panic.
78
+
79
+ gcpacertrace: setting gcpacertrace=1 causes the garbage collector to
80
+ print information about the internal state of the concurrent pacer.
81
+
82
+ gcshrinkstackoff: setting gcshrinkstackoff=1 disables moving goroutines
83
+ onto smaller stacks. In this mode, a goroutine's stack can only grow.
84
+
85
+ gcstoptheworld: setting gcstoptheworld=1 disables concurrent garbage collection,
86
+ making every garbage collection a stop-the-world event. Setting gcstoptheworld=2
87
+ also disables concurrent sweeping after the garbage collection finishes.
88
+
89
+ gctrace: setting gctrace=1 causes the garbage collector to emit a single line to standard
90
+ error at each collection, summarizing the amount of memory collected and the
91
+ length of the pause. The format of this line is subject to change. Included in
92
+ the explanation below is also the relevant runtime/metrics metric for each field.
93
+ Currently, it is:
94
+ gc # @#s #%: #+#+# ms clock, #+#/#/#+# ms cpu, #->#-># MB, # MB goal, # MB stacks, #MB globals, # P
95
+ where the fields are as follows:
96
+ gc # the GC number, incremented at each GC
97
+ @#s time in seconds since program start
98
+ #% percentage of time spent in GC since program start
99
+ #+...+# wall-clock/CPU times for the phases of the GC
100
+ #->#-># MB heap size at GC start, at GC end, and live heap, or /gc/scan/heap:bytes
101
+ # MB goal goal heap size, or /gc/heap/goal:bytes
102
+ # MB stacks estimated scannable stack size, or /gc/scan/stack:bytes
103
+ # MB globals scannable global size, or /gc/scan/globals:bytes
104
+ # P number of processors used, or /sched/gomaxprocs:threads
105
+ The phases are stop-the-world (STW) sweep termination, concurrent
106
+ mark and scan, and STW mark termination. The CPU times
107
+ for mark/scan are broken down in to assist time (GC performed in
108
+ line with allocation), background GC time, and idle GC time.
109
+ If the line ends with "(forced)", this GC was forced by a
110
+ runtime.GC() call.
111
+
112
+ harddecommit: setting harddecommit=1 causes memory that is returned to the OS to
113
+ also have protections removed on it. This is the only mode of operation on Windows,
114
+ but is helpful in debugging scavenger-related issues on other platforms. Currently,
115
+ only supported on Linux.
116
+
117
+ inittrace: setting inittrace=1 causes the runtime to emit a single line to standard
118
+ error for each package with init work, summarizing the execution time and memory
119
+ allocation. No information is printed for inits executed as part of plugin loading
120
+ and for packages without both user defined and compiler generated init work.
121
+ The format of this line is subject to change. Currently, it is:
122
+ init # @#ms, # ms clock, # bytes, # allocs
123
+ where the fields are as follows:
124
+ init # the package name
125
+ @# ms time in milliseconds when the init started since program start
126
+ # clock wall-clock time for package initialization work
127
+ # bytes memory allocated on the heap
128
+ # allocs number of heap allocations
129
+
130
+ madvdontneed: setting madvdontneed=0 will use MADV_FREE
131
+ instead of MADV_DONTNEED on Linux when returning memory to the
132
+ kernel. This is more efficient, but means RSS numbers will
133
+ drop only when the OS is under memory pressure. On the BSDs and
134
+ Illumos/Solaris, setting madvdontneed=1 will use MADV_DONTNEED instead
135
+ of MADV_FREE. This is less efficient, but causes RSS numbers to drop
136
+ more quickly.
137
+
138
+ memprofilerate: setting memprofilerate=X will update the value of runtime.MemProfileRate.
139
+ When set to 0 memory profiling is disabled. Refer to the description of
140
+ MemProfileRate for the default value.
141
+
142
+ profstackdepth: profstackdepth=128 (the default) will set the maximum stack
143
+ depth used by all pprof profilers except for the CPU profiler to 128 frames.
144
+ Stack traces that exceed this limit will be truncated to the limit starting
145
+ from the leaf frame. Setting profstackdepth to any value above 1024 will
146
+ silently default to 1024. Future versions of Go may remove this limitation
147
+ and extend profstackdepth to apply to the CPU profiler and execution tracer.
148
+
149
+ pagetrace: setting pagetrace=/path/to/file will write out a trace of page events
150
+ that can be viewed, analyzed, and visualized using the x/debug/cmd/pagetrace tool.
151
+ Build your program with GOEXPERIMENT=pagetrace to enable this functionality. Do not
152
+ enable this functionality if your program is a setuid binary as it introduces a security
153
+ risk in that scenario. Currently not supported on Windows, plan9 or js/wasm. Setting this
154
+ option for some applications can produce large traces, so use with care.
155
+
156
+ panicnil: setting panicnil=1 disables the runtime error when calling panic with nil
157
+ interface value or an untyped nil.
158
+
159
+ runtimecontentionstacks: setting runtimecontentionstacks=1 enables inclusion of call stacks
160
+ related to contention on runtime-internal locks in the "mutex" profile, subject to the
161
+ MutexProfileFraction setting. When runtimecontentionstacks=0, contention on
162
+ runtime-internal locks will report as "runtime._LostContendedRuntimeLock". When
163
+ runtimecontentionstacks=1, the call stacks will correspond to the unlock call that released
164
+ the lock. But instead of the value corresponding to the amount of contention that call
165
+ stack caused, it corresponds to the amount of time the caller of unlock had to wait in its
166
+ original call to lock. A future release is expected to align those and remove this setting.
167
+
168
+ invalidptr: invalidptr=1 (the default) causes the garbage collector and stack
169
+ copier to crash the program if an invalid pointer value (for example, 1)
170
+ is found in a pointer-typed location. Setting invalidptr=0 disables this check.
171
+ This should only be used as a temporary workaround to diagnose buggy code.
172
+ The real fix is to not store integers in pointer-typed locations.
173
+
174
+ sbrk: setting sbrk=1 replaces the memory allocator and garbage collector
175
+ with a trivial allocator that obtains memory from the operating system and
176
+ never reclaims any memory.
177
+
178
+ scavtrace: setting scavtrace=1 causes the runtime to emit a single line to standard
179
+ error, roughly once per GC cycle, summarizing the amount of work done by the
180
+ scavenger as well as the total amount of memory returned to the operating system
181
+ and an estimate of physical memory utilization. The format of this line is subject
182
+ to change, but currently it is:
183
+ scav # KiB work (bg), # KiB work (eager), # KiB total, #% util
184
+ where the fields are as follows:
185
+ # KiB work (bg) the amount of memory returned to the OS in the background since
186
+ the last line
187
+ # KiB work (eager) the amount of memory returned to the OS eagerly since the last line
188
+ # KiB now the amount of address space currently returned to the OS
189
+ #% util the fraction of all unscavenged heap memory which is in-use
190
+ If the line ends with "(forced)", then scavenging was forced by a
191
+ debug.FreeOSMemory() call.
192
+
193
+ scheddetail: setting schedtrace=X and scheddetail=1 causes the scheduler to emit
194
+ detailed multiline info every X milliseconds, describing state of the scheduler,
195
+ processors, threads and goroutines.
196
+
197
+ schedtrace: setting schedtrace=X causes the scheduler to emit a single line to standard
198
+ error every X milliseconds, summarizing the scheduler state.
199
+
200
+ tracebackancestors: setting tracebackancestors=N extends tracebacks with the stacks at
201
+ which goroutines were created, where N limits the number of ancestor goroutines to
202
+ report. This also extends the information returned by runtime.Stack.
203
+ Setting N to 0 will report no ancestry information.
204
+
205
+ tracefpunwindoff: setting tracefpunwindoff=1 forces the execution tracer to
206
+ use the runtime's default stack unwinder instead of frame pointer unwinding.
207
+ This increases tracer overhead, but could be helpful as a workaround or for
208
+ debugging unexpected regressions caused by frame pointer unwinding.
209
+
210
+ traceadvanceperiod: the approximate period in nanoseconds between trace generations. Only
211
+ applies if a program is built with GOEXPERIMENT=exectracer2. Used primarily for testing
212
+ and debugging the execution tracer.
213
+
214
+ tracecheckstackownership: setting tracecheckstackownership=1 enables a debug check in the
215
+ execution tracer to double-check stack ownership before taking a stack trace.
216
+
217
+ asyncpreemptoff: asyncpreemptoff=1 disables signal-based
218
+ asynchronous goroutine preemption. This makes some loops
219
+ non-preemptible for long periods, which may delay GC and
220
+ goroutine scheduling. This is useful for debugging GC issues
221
+ because it also disables the conservative stack scanning used
222
+ for asynchronously preempted goroutines.
223
+
224
+ The net and net/http packages also refer to debugging variables in GODEBUG.
225
+ See the documentation for those packages for details.
226
+
227
+ The GOMAXPROCS variable limits the number of operating system threads that can
228
+ execute user-level Go code simultaneously. There is no limit to the number of
229
+ threads that can be blocked in system calls on behalf of Go code; those do not
230
+ count against the GOMAXPROCS limit. This package's GOMAXPROCS function queries
231
+ and changes the limit.
232
+
233
+ The GORACE variable configures the race detector, for programs built using
234
+ -race. See the Race Detector article for details.
235
+
236
+ The GOTRACEBACK variable controls the amount of output generated when a Go
237
+ program fails due to an unrecovered panic or an unexpected runtime condition.
238
+ By default, a failure prints a stack trace for the current goroutine, eliding
239
+ functions internal to the run-time system, and then exits with exit code 2.
240
+ The failure prints stack traces for all goroutines if there is no current
241
+ goroutine or the failure is internal to the run-time. GOTRACEBACK=none omits
242
+ the goroutine stack traces entirely. GOTRACEBACK=single (the default) behaves
243
+ as described above. GOTRACEBACK=all adds stack traces for all user-created
244
+ goroutines. GOTRACEBACK=system is like “all” but adds stack frames for
245
+ run-time functions and shows goroutines created internally by the run-time.
246
+ GOTRACEBACK=crash is like “system” but crashes in an operating system-specific
247
+ manner instead of exiting. For example, on Unix systems, the crash raises
248
+ SIGABRT to trigger a core dump. GOTRACEBACK=wer is like “crash” but doesn't
249
+ disable Windows Error Reporting (WER). For historical reasons, the GOTRACEBACK
250
+ settings 0, 1, and 2 are synonyms for none, all, and system, respectively.
251
+ The runtime/debug.SetTraceback function allows increasing the amount of output
252
+ at run time, but it cannot reduce the amount below that specified by the
253
+ environment variable.
254
+
255
+ The GOARCH, GOOS, GOPATH, and GOROOT environment variables complete the set of
256
+ Go environment variables. They influence the building of Go programs (see cmd/go
257
+ and go/build). GOARCH, GOOS, and GOROOT are recorded at compile time and made
258
+ available by constants or functions in this package, but they do not influence
259
+ the execution of the run-time system.
260
+
261
+ # Security
262
+
263
+ On Unix platforms, Go's runtime system behaves slightly differently when
264
+ a binary is setuid/setgid or executed with setuid/setgid-like properties,
265
+ in order to prevent dangerous behaviors. On Linux this is determined by checking
266
+ for the AT_SECURE flag in the auxiliary vector, on the BSDs and Solaris/Illumos
267
+ it is determined by checking the issetugid syscall, and on AIX it is determined
268
+ by checking if the uid/gid match the effective uid/gid.
269
+
270
+ When the runtime determines the binary is setuid/setgid-like, it does three main
271
+ things:
272
+ - The standard input/output file descriptors (0, 1, 2) are checked to be open.
273
+ If any of them are closed, they are opened pointing at /dev/null.
274
+ - The value of the GOTRACEBACK environment variable is set to 'none'.
275
+ - When a signal is received that terminates the program, or the program
276
+ encounters an unrecoverable panic that would otherwise override the value
277
+ of GOTRACEBACK, the goroutine stack, registers, and other memory related
278
+ information are omitted.
279
+
280
+ [Race Detector article]: https://go.dev/doc/articles/race_detector
281
+
282
+ const Compiler = "gc"
283
+ const GOARCH string = goarch.GOARCH
284
+ const GOOS string = goos.GOOS
285
+ var MemProfileRate int = 512 * 1024
286
+ func BlockProfile(p []BlockProfileRecord) (n int, ok bool)
287
+ func Breakpoint()
288
+ func CPUProfile() []byte
289
+ func Caller(skip int) (pc uintptr, file string, line int, ok bool)
290
+ func Callers(skip int, pc []uintptr) int
291
+ func GC()
292
+ func GOMAXPROCS(n int) int
293
+ func GOROOT() string
294
+ func Goexit()
295
+ func GoroutineProfile(p []StackRecord) (n int, ok bool)
296
+ func Gosched()
297
+ func KeepAlive(x any)
298
+ func LockOSThread()
299
+ func MemProfile(p []MemProfileRecord, inuseZero bool) (n int, ok bool)
300
+ func MutexProfile(p []BlockProfileRecord) (n int, ok bool)
301
+ func NumCPU() int
302
+ func NumCgoCall() int64
303
+ func NumGoroutine() int
304
+ func ReadMemStats(m *MemStats)
305
+ func ReadTrace() []byte
306
+ func SetBlockProfileRate(rate int)
307
+ func SetCPUProfileRate(hz int)
308
+ func SetCgoTraceback(version int, traceback, context, symbolizer unsafe.Pointer)
309
+ func SetFinalizer(obj any, finalizer any)
310
+ func SetMutexProfileFraction(rate int) int
311
+ func Stack(buf []byte, all bool) int
312
+ func StartTrace() error
313
+ func StopTrace()
314
+ func ThreadCreateProfile(p []StackRecord) (n int, ok bool)
315
+ func UnlockOSThread()
316
+ func Version() string
317
+ type BlockProfileRecord struct{ ... }
318
+ type Cleanup struct{ ... }
319
+ func AddCleanup[T, S any](ptr *T, cleanup func(S), arg S) Cleanup
320
+ type Error interface{ ... }
321
+ type Frame struct{ ... }
322
+ type Frames struct{ ... }
323
+ func CallersFrames(callers []uintptr) *Frames
324
+ type Func struct{ ... }
325
+ func FuncForPC(pc uintptr) *Func
326
+ type MemProfileRecord struct{ ... }
327
+ type MemStats struct{ ... }
328
+ type PanicNilError struct{ ... }
329
+ type Pinner struct{ ... }
330
+ type StackRecord struct{ ... }
331
+ type TypeAssertionError struct{ ... }
@@ -0,0 +1 @@
1
+ export * from './runtime.js'
@@ -0,0 +1,178 @@
1
+ // Runtime constants for the JavaScript/WebAssembly target
2
+ export const GOOS = 'js'
3
+ export const GOARCH = 'wasm'
4
+
5
+ // Version returns the Go version as a string
6
+ export const GOVERSION = 'go1.24.3'
7
+ export function Version(): string {
8
+ return GOVERSION
9
+ }
10
+
11
+ // GOMAXPROCS sets the maximum number of operating system threads
12
+ //
13
+ // JavaScript is single threaded so this always returns 1.
14
+ export function GOMAXPROCS(n: number): number {
15
+ // In a full implementation, we would set the max procs
16
+ // Since JavaScript only supports 1, just return 1.
17
+ return 1
18
+ }
19
+
20
+ // NumCPU returns the number of logical CPUs on the system.
21
+ export function NumCPU(): number {
22
+ // In browser environment, use navigator.hardwareConcurrency if available
23
+ if (typeof navigator !== 'undefined' && navigator.hardwareConcurrency) {
24
+ return navigator.hardwareConcurrency
25
+ }
26
+
27
+ // Default to 1 if we can't determine
28
+ return 1
29
+ }
30
+
31
+ // GC runs a garbage collection and blocks the caller until the
32
+ // garbage collection is complete. In JavaScript, we can suggest GC but not force it.
33
+ export function GC(): void {
34
+ // In JavaScript, we can't force garbage collection
35
+ // Some engines have gc() function in development, but it's not standard
36
+ if (typeof globalThis.gc === 'function') {
37
+ ;(globalThis as any).gc()
38
+ }
39
+ // Otherwise, this is a no-op
40
+ }
41
+
42
+ // Gosched yields the processor, allowing other goroutines to run.
43
+ // In JavaScript, we can use setTimeout(0) or queueMicrotask for similar effect
44
+ export function Gosched(): Promise<void> {
45
+ return new Promise((resolve) => {
46
+ queueMicrotask(resolve)
47
+ })
48
+ }
49
+
50
+ // NumGoroutine returns the number of goroutines that currently exist.
51
+ // In goscript, this is informational only
52
+ let goroutineCount = 1 // Start with main goroutine
53
+
54
+ export function NumGoroutine(): number {
55
+ return goroutineCount
56
+ }
57
+
58
+ // Internal function to track goroutine creation (called by goscript runtime)
59
+ export function _incrementGoroutineCount(): void {
60
+ goroutineCount++
61
+ }
62
+
63
+ // Internal function to track goroutine completion (called by goscript runtime)
64
+ export function _decrementGoroutineCount(): void {
65
+ if (goroutineCount > 0) {
66
+ goroutineCount--
67
+ }
68
+ }
69
+
70
+ // Caller returns details about the calling goroutine's stack.
71
+ // This is a simplified version for goscript
72
+ export function Caller(skip: number): [number, string, number, boolean] {
73
+ // In JavaScript, we can use Error stack trace, but it's limited
74
+ // Return dummy values for goscript compatibility
75
+ const pc = 0 // program counter (not meaningful in JS)
76
+ const file = 'unknown'
77
+ const line = 0
78
+ const ok = false // indicate we don't have real stack info
79
+ return [pc, file, line, ok]
80
+ }
81
+
82
+ // Stack returns a formatted stack trace of the calling goroutine.
83
+ // In JavaScript, we use Error.stack
84
+ export function Stack(): Uint8Array {
85
+ const stack = new Error().stack || 'stack trace unavailable'
86
+ const encoder = new TextEncoder()
87
+ return encoder.encode(stack)
88
+ }
89
+
90
+ // MemStats represents memory allocation statistics
91
+ export class MemStats {
92
+ // Simplified memory stats for goscript
93
+ public Alloc: number = 0 // bytes allocated and not yet freed
94
+ public TotalAlloc: number = 0 // bytes allocated (even if freed)
95
+ public Sys: number = 0 // bytes obtained from system
96
+ public Lookups: number = 0 // number of pointer lookups
97
+ public Mallocs: number = 0 // number of mallocs
98
+ public Frees: number = 0 // number of frees
99
+
100
+ constructor() {
101
+ // Initialize with some default values
102
+ // In a real environment, these would be obtained from the JS runtime
103
+ this.updateMemoryStats()
104
+ }
105
+
106
+ private updateMemoryStats(): void {
107
+ // Use performance.memory if available (Chrome/Edge)
108
+ if (typeof performance !== 'undefined' && (performance as any).memory) {
109
+ const mem = (performance as any).memory
110
+ this.Alloc = mem.usedJSHeapSize || 0
111
+ this.Sys = mem.totalJSHeapSize || 0
112
+ this.TotalAlloc = this.Alloc // Simplified
113
+ }
114
+ }
115
+ }
116
+
117
+ // ReadMemStats populates m with memory allocator statistics
118
+ export function ReadMemStats(m: MemStats): void {
119
+ // Update the provided MemStats object with current values
120
+ if (typeof performance !== 'undefined' && (performance as any).memory) {
121
+ const mem = (performance as any).memory
122
+ m.Alloc = mem.usedJSHeapSize || 0
123
+ m.Sys = mem.totalJSHeapSize || 0
124
+ m.TotalAlloc = m.Alloc // Simplified
125
+ }
126
+ }
127
+
128
+ // Error interface for runtime errors
129
+ export interface Error {
130
+ Error(): string
131
+ }
132
+
133
+ // TypeAssertionError represents a failed type assertion
134
+ export class TypeAssertionError implements Error {
135
+ constructor(
136
+ public readonly interfaceType: string,
137
+ public readonly concrete: string,
138
+ public readonly assertedType: string,
139
+ public readonly missingMethod?: string,
140
+ ) {}
141
+
142
+ Error(): string {
143
+ if (this.missingMethod) {
144
+ return `interface conversion: ${this.interfaceType} is ${this.concrete}, not ${this.assertedType} (missing ${this.missingMethod} method)`
145
+ }
146
+ return `interface conversion: ${this.interfaceType} is ${this.concrete}, not ${this.assertedType}`
147
+ }
148
+ }
149
+
150
+ // PanicError represents a panic
151
+ export class PanicError implements Error {
152
+ constructor(public readonly value: any) {}
153
+
154
+ Error(): string {
155
+ return `panic: ${this.value}`
156
+ }
157
+ }
158
+
159
+ // SetFinalizer sets the finalizer associated with obj to the provided finalizer function.
160
+ // In goscript/TypeScript environment, finalizers are not supported, so this throws an error.
161
+ export function SetFinalizer(
162
+ obj: object,
163
+ finalizer: ((obj: object) => void) | null,
164
+ ): void {
165
+ throw new Error(
166
+ 'runtime.SetFinalizer is not supported in goscript TypeScript environment',
167
+ )
168
+ }
169
+
170
+ // KeepAlive keeps obj reachable until the point where KeepAlive is called
171
+ export function KeepAlive(obj: any): void {
172
+ // In JavaScript, just accessing the object keeps it alive for this call
173
+ // This is mostly a no-op but we touch the object to ensure it's not optimized away
174
+ if (obj !== null && obj !== undefined) {
175
+ // Touch the object to keep it alive
176
+ void obj
177
+ }
178
+ }
@@ -0,0 +1,44 @@
1
+ package slices // import "slices"
2
+
3
+ Package slices defines various functions useful with slices of any type.
4
+
5
+ func All[Slice ~[]E, E any](s Slice) iter.Seq2[int, E]
6
+ func AppendSeq[Slice ~[]E, E any](s Slice, seq iter.Seq[E]) Slice
7
+ func Backward[Slice ~[]E, E any](s Slice) iter.Seq2[int, E]
8
+ func BinarySearch[S ~[]E, E cmp.Ordered](x S, target E) (int, bool)
9
+ func BinarySearchFunc[S ~[]E, E, T any](x S, target T, cmp func(E, T) int) (int, bool)
10
+ func Chunk[Slice ~[]E, E any](s Slice, n int) iter.Seq[Slice]
11
+ func Clip[S ~[]E, E any](s S) S
12
+ func Clone[S ~[]E, E any](s S) S
13
+ func Collect[E any](seq iter.Seq[E]) []E
14
+ func Compact[S ~[]E, E comparable](s S) S
15
+ func CompactFunc[S ~[]E, E any](s S, eq func(E, E) bool) S
16
+ func Compare[S ~[]E, E cmp.Ordered](s1, s2 S) int
17
+ func CompareFunc[S1 ~[]E1, S2 ~[]E2, E1, E2 any](s1 S1, s2 S2, cmp func(E1, E2) int) int
18
+ func Concat[S ~[]E, E any](slices ...S) S
19
+ func Contains[S ~[]E, E comparable](s S, v E) bool
20
+ func ContainsFunc[S ~[]E, E any](s S, f func(E) bool) bool
21
+ func Delete[S ~[]E, E any](s S, i, j int) S
22
+ func DeleteFunc[S ~[]E, E any](s S, del func(E) bool) S
23
+ func Equal[S ~[]E, E comparable](s1, s2 S) bool
24
+ func EqualFunc[S1 ~[]E1, S2 ~[]E2, E1, E2 any](s1 S1, s2 S2, eq func(E1, E2) bool) bool
25
+ func Grow[S ~[]E, E any](s S, n int) S
26
+ func Index[S ~[]E, E comparable](s S, v E) int
27
+ func IndexFunc[S ~[]E, E any](s S, f func(E) bool) int
28
+ func Insert[S ~[]E, E any](s S, i int, v ...E) S
29
+ func IsSorted[S ~[]E, E cmp.Ordered](x S) bool
30
+ func IsSortedFunc[S ~[]E, E any](x S, cmp func(a, b E) int) bool
31
+ func Max[S ~[]E, E cmp.Ordered](x S) E
32
+ func MaxFunc[S ~[]E, E any](x S, cmp func(a, b E) int) E
33
+ func Min[S ~[]E, E cmp.Ordered](x S) E
34
+ func MinFunc[S ~[]E, E any](x S, cmp func(a, b E) int) E
35
+ func Repeat[S ~[]E, E any](x S, count int) S
36
+ func Replace[S ~[]E, E any](s S, i, j int, v ...E) S
37
+ func Reverse[S ~[]E, E any](s S)
38
+ func Sort[S ~[]E, E cmp.Ordered](x S)
39
+ func SortFunc[S ~[]E, E any](x S, cmp func(a, b E) int)
40
+ func SortStableFunc[S ~[]E, E any](x S, cmp func(a, b E) int)
41
+ func Sorted[E cmp.Ordered](seq iter.Seq[E]) []E
42
+ func SortedFunc[E any](seq iter.Seq[E], cmp func(E, E) int) []E
43
+ func SortedStableFunc[E any](seq iter.Seq[E], cmp func(E, E) int) []E
44
+ func Values[Slice ~[]E, E any](s Slice) iter.Seq[E]
@@ -0,0 +1 @@
1
+ export * from './slices.js'
@@ -0,0 +1,22 @@
1
+ // TypeScript implementation of Go's slices package
2
+ import * as $ from '@goscript/builtin/builtin.js'
3
+
4
+ /**
5
+ * All returns an iterator over index-value pairs in the slice.
6
+ * This is equivalent to Go's slices.All function.
7
+ * @param s The slice to iterate over
8
+ * @returns An iterator function that yields index-value pairs
9
+ */
10
+ export function All<T>(
11
+ s: $.Slice<T>,
12
+ ): (yieldFunc: (index: number, value: T) => boolean) => void {
13
+ return function (_yield: (index: number, value: T) => boolean): void {
14
+ const length = $.len(s)
15
+ for (let i = 0; i < length; i++) {
16
+ const value = (s as any)[i] as T // Use proper indexing to avoid type issues
17
+ if (!_yield(i, value)) {
18
+ break
19
+ }
20
+ }
21
+ }
22
+ }