goscript 0.0.36 → 0.0.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/compiler/analysis.go +129 -8
- package/compiler/compiler.go +4 -1
- package/compiler/composite-lit.go +2 -4
- package/compiler/expr-call.go +26 -0
- package/compiler/lit.go +83 -0
- package/compiler/protobuf.go +2 -2
- package/compiler/spec-value.go +3 -3
- package/compiler/spec.go +7 -4
- package/compiler/stmt-assign.go +1 -1
- package/compiler/stmt.go +26 -8
- package/dist/gs/builtin/slice.js +2 -1
- package/dist/gs/builtin/slice.js.map +1 -1
- package/dist/gs/github.com/pkg/errors/errors.d.ts +1 -1
- package/dist/gs/github.com/pkg/errors/errors.js +182 -23
- package/dist/gs/github.com/pkg/errors/errors.js.map +1 -1
- package/dist/gs/github.com/pkg/errors/go113.d.ts +1 -1
- package/dist/gs/github.com/pkg/errors/go113.js +1 -1
- package/dist/gs/github.com/pkg/errors/go113.js.map +1 -1
- package/dist/gs/github.com/pkg/errors/index.d.ts +3 -3
- package/dist/gs/github.com/pkg/errors/index.js +3 -3
- package/dist/gs/github.com/pkg/errors/index.js.map +1 -1
- package/dist/gs/github.com/pkg/errors/stack.d.ts +1 -1
- package/dist/gs/github.com/pkg/errors/stack.js +8 -5
- package/dist/gs/github.com/pkg/errors/stack.js.map +1 -1
- package/dist/gs/internal/abi/index.d.ts +20 -0
- package/dist/gs/internal/abi/index.js +20 -0
- package/dist/gs/internal/abi/index.js.map +1 -0
- package/dist/gs/internal/bytealg/index.d.ts +2 -0
- package/dist/gs/internal/bytealg/index.js +33 -0
- package/dist/gs/internal/bytealg/index.js.map +1 -0
- package/dist/gs/internal/byteorder/index.d.ts +8 -0
- package/dist/gs/internal/byteorder/index.js +34 -0
- package/dist/gs/internal/byteorder/index.js.map +1 -0
- package/dist/gs/internal/testlog/index.d.ts +1 -0
- package/dist/gs/internal/testlog/index.js +5 -0
- package/dist/gs/internal/testlog/index.js.map +1 -0
- package/dist/gs/math/index.d.ts +44 -44
- package/dist/gs/math/index.js +44 -44
- package/dist/gs/math/index.js.map +1 -1
- package/dist/gs/os/dir.gs.d.ts +6 -0
- package/dist/gs/os/dir.gs.js +35 -0
- package/dist/gs/os/dir.gs.js.map +1 -0
- package/dist/gs/os/dir_unix.gs.d.ts +7 -0
- package/dist/gs/os/dir_unix.gs.js +113 -0
- package/dist/gs/os/dir_unix.gs.js.map +1 -0
- package/dist/gs/os/dirent_js.gs.d.ts +5 -0
- package/dist/gs/os/dirent_js.gs.js +20 -0
- package/dist/gs/os/dirent_js.gs.js.map +1 -0
- package/dist/gs/os/env.gs.d.ts +12 -0
- package/dist/gs/os/env.gs.js +157 -0
- package/dist/gs/os/env.gs.js.map +1 -0
- package/dist/gs/os/error.gs.d.ts +40 -0
- package/dist/gs/os/error.gs.js +158 -0
- package/dist/gs/os/error.gs.js.map +1 -0
- package/dist/gs/os/error_errno.gs.d.ts +1 -0
- package/dist/gs/os/error_errno.gs.js +5 -0
- package/dist/gs/os/error_errno.gs.js.map +1 -0
- package/dist/gs/os/exec.gs.d.ts +60 -0
- package/dist/gs/os/exec.gs.js +136 -0
- package/dist/gs/os/exec.gs.js.map +1 -0
- package/dist/gs/os/exec_nohandle.gs.d.ts +1 -0
- package/dist/gs/os/exec_nohandle.gs.js +2 -0
- package/dist/gs/os/exec_nohandle.gs.js.map +1 -0
- package/dist/gs/os/exec_posix.gs.d.ts +25 -0
- package/dist/gs/os/exec_posix.gs.js +67 -0
- package/dist/gs/os/exec_posix.gs.js.map +1 -0
- package/dist/gs/os/exec_unix.gs.d.ts +4 -0
- package/dist/gs/os/exec_unix.gs.js +46 -0
- package/dist/gs/os/exec_unix.gs.js.map +1 -0
- package/dist/gs/os/executable.gs.d.ts +2 -0
- package/dist/gs/os/executable.gs.js +16 -0
- package/dist/gs/os/executable.gs.js.map +1 -0
- package/dist/gs/os/executable_js.gs.d.ts +2 -0
- package/dist/gs/os/executable_js.gs.js +5 -0
- package/dist/gs/os/executable_js.gs.js.map +1 -0
- package/dist/gs/os/executable_wasm.gs.d.ts +2 -0
- package/dist/gs/os/executable_wasm.gs.js +6 -0
- package/dist/gs/os/executable_wasm.gs.js.map +1 -0
- package/dist/gs/os/file_constants_js.gs.d.ts +41 -0
- package/dist/gs/os/file_constants_js.gs.js +78 -0
- package/dist/gs/os/file_constants_js.gs.js.map +1 -0
- package/dist/gs/os/file_js.gs.d.ts +22 -0
- package/dist/gs/os/file_js.gs.js +73 -0
- package/dist/gs/os/file_js.gs.js.map +1 -0
- package/dist/gs/os/file_open_unix.gs.d.ts +6 -0
- package/dist/gs/os/file_open_unix.gs.js +10 -0
- package/dist/gs/os/file_open_unix.gs.js.map +1 -0
- package/dist/gs/os/file_posix_js.gs.d.ts +8 -0
- package/dist/gs/os/file_posix_js.gs.js +32 -0
- package/dist/gs/os/file_posix_js.gs.js.map +1 -0
- package/dist/gs/os/file_unix_js.gs.d.ts +27 -0
- package/dist/gs/os/file_unix_js.gs.js +64 -0
- package/dist/gs/os/file_unix_js.gs.js.map +1 -0
- package/dist/gs/os/getwd_js.gs.d.ts +6 -0
- package/dist/gs/os/getwd_js.gs.js +21 -0
- package/dist/gs/os/getwd_js.gs.js.map +1 -0
- package/dist/gs/os/index.d.ts +19 -0
- package/dist/gs/os/index.js +20 -0
- package/dist/gs/os/index.js.map +1 -0
- package/dist/gs/os/path.gs.d.ts +4 -0
- package/dist/gs/os/path.gs.js +32 -0
- package/dist/gs/os/path.gs.js.map +1 -0
- package/dist/gs/os/path_unix.gs.d.ts +4 -0
- package/dist/gs/os/path_unix.gs.js +40 -0
- package/dist/gs/os/path_unix.gs.js.map +1 -0
- package/dist/gs/os/pidfd_js.gs.d.ts +6 -0
- package/dist/gs/os/pidfd_js.gs.js +14 -0
- package/dist/gs/os/pidfd_js.gs.js.map +1 -0
- package/dist/gs/os/pipe_wasm.gs.d.ts +2 -0
- package/dist/gs/os/pipe_wasm.gs.js +14 -0
- package/dist/gs/os/pipe_wasm.gs.js.map +1 -0
- package/dist/gs/os/proc.gs.d.ts +11 -0
- package/dist/gs/os/proc.gs.js +68 -0
- package/dist/gs/os/proc.gs.js.map +1 -0
- package/dist/gs/os/proc_js.gs.d.ts +3 -0
- package/dist/gs/os/proc_js.gs.js +12 -0
- package/dist/gs/os/proc_js.gs.js.map +1 -0
- package/dist/gs/os/rawconn_js.gs.d.ts +10 -0
- package/dist/gs/os/rawconn_js.gs.js +26 -0
- package/dist/gs/os/rawconn_js.gs.js.map +1 -0
- package/dist/gs/os/removeall_js.gs.d.ts +2 -0
- package/dist/gs/os/removeall_js.gs.js +7 -0
- package/dist/gs/os/removeall_js.gs.js.map +1 -0
- package/dist/gs/os/root_js.gs.d.ts +23 -0
- package/dist/gs/os/root_js.gs.js +80 -0
- package/dist/gs/os/root_js.gs.js.map +1 -0
- package/dist/gs/os/root_nonwindows.gs.d.ts +2 -0
- package/dist/gs/os/root_nonwindows.gs.js +4 -0
- package/dist/gs/os/root_nonwindows.gs.js.map +1 -0
- package/dist/gs/os/root_noopenat.gs.d.ts +11 -0
- package/dist/gs/os/root_noopenat.gs.js +31 -0
- package/dist/gs/os/root_noopenat.gs.js.map +1 -0
- package/dist/gs/os/stat.gs.d.ts +24 -0
- package/dist/gs/os/stat.gs.js +20 -0
- package/dist/gs/os/stat.gs.js.map +1 -0
- package/dist/gs/os/stat_js.gs.d.ts +6 -0
- package/dist/gs/os/stat_js.gs.js +23 -0
- package/dist/gs/os/stat_js.gs.js.map +1 -0
- package/dist/gs/os/stat_unix_js.gs.d.ts +8 -0
- package/dist/gs/os/stat_unix_js.gs.js +16 -0
- package/dist/gs/os/stat_unix_js.gs.js.map +1 -0
- package/dist/gs/os/sticky_bsd.gs.d.ts +1 -0
- package/dist/gs/os/sticky_bsd.gs.js +3 -0
- package/dist/gs/os/sticky_bsd.gs.js.map +1 -0
- package/dist/gs/os/sys.gs.d.ts +2 -0
- package/dist/gs/os/sys.gs.js +10 -0
- package/dist/gs/os/sys.gs.js.map +1 -0
- package/dist/gs/os/sys_bsd.gs.d.ts +2 -0
- package/dist/gs/os/sys_bsd.gs.js +15 -0
- package/dist/gs/os/sys_bsd.gs.js.map +1 -0
- package/dist/gs/os/sys_js.gs.d.ts +2 -0
- package/dist/gs/os/sys_js.gs.js +6 -0
- package/dist/gs/os/sys_js.gs.js.map +1 -0
- package/dist/gs/os/tempfile.gs.d.ts +5 -0
- package/dist/gs/os/tempfile.gs.js +30 -0
- package/dist/gs/os/tempfile.gs.js.map +1 -0
- package/dist/gs/os/types.gs.d.ts +59 -0
- package/dist/gs/os/types.gs.js +123 -0
- package/dist/gs/os/types.gs.js.map +1 -0
- package/dist/gs/os/types_js.gs.d.ts +74 -0
- package/dist/gs/os/types_js.gs.js +147 -0
- package/dist/gs/os/types_js.gs.js.map +1 -0
- package/dist/gs/os/types_unix.gs.d.ts +40 -0
- package/dist/gs/os/types_unix.gs.js +87 -0
- package/dist/gs/os/types_unix.gs.js.map +1 -0
- package/dist/gs/os/wait_unimp.gs.d.ts +1 -0
- package/dist/gs/os/wait_unimp.gs.js +2 -0
- package/dist/gs/os/wait_unimp.gs.js.map +1 -0
- package/dist/gs/os/zero_copy_posix.gs.d.ts +4 -0
- package/dist/gs/os/zero_copy_posix.gs.js +27 -0
- package/dist/gs/os/zero_copy_posix.gs.js.map +1 -0
- package/dist/gs/os/zero_copy_stub.gs.d.ts +1 -0
- package/dist/gs/os/zero_copy_stub.gs.js +2 -0
- package/dist/gs/os/zero_copy_stub.gs.js.map +1 -0
- package/dist/gs/reflect/abi.d.ts +59 -0
- package/dist/gs/reflect/abi.gs.d.ts +59 -0
- package/dist/gs/reflect/abi.gs.js +79 -0
- package/dist/gs/reflect/abi.gs.js.map +1 -0
- package/dist/gs/reflect/abi.js +79 -0
- package/dist/gs/reflect/abi.js.map +1 -0
- package/dist/gs/reflect/badlinkname.d.ts +52 -0
- package/dist/gs/reflect/badlinkname.gs.d.ts +52 -0
- package/dist/gs/reflect/badlinkname.gs.js +72 -0
- package/dist/gs/reflect/badlinkname.gs.js.map +1 -0
- package/dist/gs/reflect/badlinkname.js +72 -0
- package/dist/gs/reflect/badlinkname.js.map +1 -0
- package/dist/gs/reflect/deepequal.d.ts +1 -0
- package/dist/gs/reflect/deepequal.gs.d.ts +25 -0
- package/dist/gs/reflect/deepequal.gs.js +308 -0
- package/dist/gs/reflect/deepequal.gs.js.map +1 -0
- package/dist/gs/reflect/deepequal.js +139 -0
- package/dist/gs/reflect/deepequal.js.map +1 -0
- package/dist/gs/reflect/float32reg_generic.gs.d.ts +2 -0
- package/dist/gs/reflect/float32reg_generic.gs.js +10 -0
- package/dist/gs/reflect/float32reg_generic.gs.js.map +1 -0
- package/dist/gs/reflect/index.d.ts +8 -0
- package/dist/gs/reflect/index.gs.d.ts +1 -0
- package/dist/gs/reflect/index.gs.js +3 -0
- package/dist/gs/reflect/index.gs.js.map +1 -0
- package/dist/gs/reflect/index.js +10 -0
- package/dist/gs/reflect/index.js.map +1 -0
- package/dist/gs/reflect/iter.d.ts +4 -0
- package/dist/gs/reflect/iter.gs.d.ts +3 -0
- package/dist/gs/reflect/iter.gs.js +24 -0
- package/dist/gs/reflect/iter.gs.js.map +1 -0
- package/dist/gs/reflect/iter.js +24 -0
- package/dist/gs/reflect/iter.js.map +1 -0
- package/dist/gs/reflect/makefunc.gs.d.ts +34 -0
- package/dist/gs/reflect/makefunc.gs.js +288 -0
- package/dist/gs/reflect/makefunc.gs.js.map +1 -0
- package/dist/gs/reflect/map.d.ts +14 -0
- package/dist/gs/reflect/map.js +70 -0
- package/dist/gs/reflect/map.js.map +1 -0
- package/dist/gs/reflect/map_swiss.gs.d.ts +14 -0
- package/dist/gs/reflect/map_swiss.gs.js +70 -0
- package/dist/gs/reflect/map_swiss.gs.js.map +1 -0
- package/dist/gs/reflect/reflect.gs.d.ts +132 -0
- package/dist/gs/reflect/reflect.gs.js +437 -0
- package/dist/gs/reflect/reflect.gs.js.map +1 -0
- package/dist/gs/reflect/swapper.d.ts +2 -0
- package/dist/gs/reflect/swapper.gs.d.ts +1 -0
- package/dist/gs/reflect/swapper.gs.js +32 -0
- package/dist/gs/reflect/swapper.gs.js.map +1 -0
- package/dist/gs/reflect/swapper.js +46 -0
- package/dist/gs/reflect/swapper.js.map +1 -0
- package/dist/gs/reflect/type.d.ts +126 -0
- package/dist/gs/reflect/type.gs.d.ts +4 -0
- package/dist/gs/reflect/type.gs.js +21 -0
- package/dist/gs/reflect/type.gs.js.map +1 -0
- package/dist/gs/reflect/type.js +825 -0
- package/dist/gs/reflect/type.js.map +1 -0
- package/dist/gs/reflect/types.d.ts +90 -0
- package/dist/gs/reflect/types.js +119 -0
- package/dist/gs/reflect/types.js.map +1 -0
- package/dist/gs/reflect/value.d.ts +13 -0
- package/dist/gs/reflect/value.gs.d.ts +4 -0
- package/dist/gs/reflect/value.gs.js +12 -0
- package/dist/gs/reflect/value.gs.js.map +1 -0
- package/dist/gs/reflect/value.js +201 -0
- package/dist/gs/reflect/value.js.map +1 -0
- package/dist/gs/reflect/visiblefields.d.ts +4 -0
- package/dist/gs/reflect/visiblefields.gs.d.ts +3 -0
- package/dist/gs/reflect/visiblefields.gs.js +123 -0
- package/dist/gs/reflect/visiblefields.gs.js.map +1 -0
- package/dist/gs/reflect/visiblefields.js +143 -0
- package/dist/gs/reflect/visiblefields.js.map +1 -0
- package/dist/gs/strconv/index.d.ts +6 -6
- package/dist/gs/strconv/index.js +6 -6
- package/dist/gs/strconv/index.js.map +1 -1
- package/dist/gs/strings/index.d.ts +1 -1
- package/dist/gs/strings/index.js +1 -1
- package/dist/gs/strings/index.js.map +1 -1
- package/dist/gs/strings/replace.js.map +1 -1
- package/dist/gs/sync/atomic/index.d.ts +4 -4
- package/dist/gs/sync/atomic/index.js +4 -4
- package/dist/gs/sync/atomic/index.js.map +1 -1
- package/dist/gs/syscall/index.d.ts +80 -0
- package/dist/gs/syscall/index.js +169 -0
- package/dist/gs/syscall/index.js.map +1 -0
- package/dist/gs/unsafe/unsafe.js.map +1 -1
- package/gs/builtin/slice.ts +2 -1
- package/gs/github.com/pkg/errors/errors.ts +408 -238
- package/gs/github.com/pkg/errors/go113.ts +5 -6
- package/gs/github.com/pkg/errors/index.ts +12 -3
- package/gs/github.com/pkg/errors/stack.ts +107 -105
- package/gs/internal/abi/index.ts +37 -0
- package/gs/internal/bytealg/index.ts +34 -0
- package/gs/internal/byteorder/index.ts +40 -0
- package/gs/math/abs.gs.test.ts +1 -1
- package/gs/math/acosh.gs.test.ts +4 -2
- package/gs/math/asin.gs.test.ts +1 -1
- package/gs/math/asinh.gs.test.ts +7 -3
- package/gs/math/atan.gs.test.ts +1 -1
- package/gs/math/atan2.gs.test.ts +17 -9
- package/gs/math/atanh.gs.test.ts +1 -1
- package/gs/math/bits.gs.test.ts +1 -1
- package/gs/math/cbrt.gs.test.ts +1 -1
- package/gs/math/const.gs.test.ts +34 -8
- package/gs/math/copysign.gs.test.ts +7 -3
- package/gs/math/dim.gs.test.ts +19 -7
- package/gs/math/erf.gs.test.ts +1 -1
- package/gs/math/erfinv.gs.test.ts +4 -2
- package/gs/math/exp.gs.test.ts +1 -1
- package/gs/math/expm1.gs.test.ts +6 -4
- package/gs/math/floor.gs.test.ts +17 -4
- package/gs/math/fma.gs.test.ts +53 -53
- package/gs/math/frexp.gs.test.ts +112 -117
- package/gs/math/gamma.gs.test.ts +1 -1
- package/gs/math/hypot.gs.test.ts +53 -53
- package/gs/math/index.ts +80 -44
- package/gs/math/j0.gs.test.ts +6 -2
- package/gs/math/j1.gs.test.ts +6 -2
- package/gs/math/jn.gs.test.ts +9 -5
- package/gs/math/ldexp.gs.test.ts +103 -86
- package/gs/math/lgamma.gs.test.ts +10 -10
- package/gs/math/log.gs.test.ts +1 -1
- package/gs/math/log10.gs.test.ts +1 -1
- package/gs/math/log1p.gs.test.ts +2 -2
- package/gs/math/logb.gs.test.ts +1 -1
- package/gs/math/mod.gs.test.ts +2 -2
- package/gs/math/modf.gs.test.ts +7 -7
- package/gs/math/nextafter.gs.test.ts +9 -7
- package/gs/math/pow.gs.test.ts +6 -4
- package/gs/math/pow10.gs.test.ts +1 -1
- package/gs/math/remainder.gs.test.ts +1 -1
- package/gs/math/signbit.gs.test.ts +1 -1
- package/gs/math/sin.gs.test.ts +1 -1
- package/gs/math/sincos.gs.test.ts +33 -14
- package/gs/math/sinh.gs.test.ts +1 -1
- package/gs/math/sqrt.gs.test.ts +1 -1
- package/gs/math/tan.gs.test.ts +3 -3
- package/gs/math/tanh.gs.test.ts +1 -1
- package/gs/os/dir.gs.ts +42 -0
- package/gs/os/dir_unix.gs.ts +155 -0
- package/gs/os/dirent_js.gs.ts +27 -0
- package/gs/os/env.gs.ts +179 -0
- package/gs/os/error.gs.ts +205 -0
- package/gs/os/error_errno.gs.ts +12 -0
- package/gs/os/exec.gs.ts +198 -0
- package/gs/os/exec_nohandle.gs.ts +2 -0
- package/gs/os/exec_posix.gs.ts +95 -0
- package/gs/os/exec_unix.gs.ts +64 -0
- package/gs/os/executable.gs.ts +18 -0
- package/gs/os/executable_js.gs.ts +6 -0
- package/gs/os/executable_wasm.gs.ts +10 -0
- package/gs/os/file_constants_js.gs.ts +98 -0
- package/gs/os/file_js.gs.ts +99 -0
- package/gs/os/file_open_unix.gs.ts +15 -0
- package/gs/os/file_posix_js.gs.ts +40 -0
- package/gs/os/file_unix_js.gs.ts +94 -0
- package/gs/os/getwd_js.gs.ts +28 -0
- package/gs/os/index.ts +128 -0
- package/gs/os/path.gs.ts +35 -0
- package/gs/os/path_unix.gs.ts +49 -0
- package/gs/os/pidfd_js.gs.ts +25 -0
- package/gs/os/pipe_wasm.gs.ts +17 -0
- package/gs/os/proc.gs.ts +84 -0
- package/gs/os/proc_js.gs.ts +15 -0
- package/gs/os/rawconn_js.gs.ts +30 -0
- package/gs/os/removeall_js.gs.ts +9 -0
- package/gs/os/root_js.gs.ts +111 -0
- package/gs/os/root_nonwindows.gs.ts +6 -0
- package/gs/os/root_noopenat.gs.ts +45 -0
- package/gs/os/stat.gs.ts +38 -0
- package/gs/os/stat_js.gs.ts +30 -0
- package/gs/os/stat_unix_js.gs.ts +27 -0
- package/gs/os/sticky_bsd.gs.ts +4 -0
- package/gs/os/sys.gs.ts +12 -0
- package/gs/os/sys_bsd.gs.ts +17 -0
- package/gs/os/sys_js.gs.ts +9 -0
- package/gs/os/tempfile.gs.ts +34 -0
- package/gs/os/types.gs.ts +170 -0
- package/gs/os/types_js.gs.ts +205 -0
- package/gs/os/types_unix.gs.ts +118 -0
- package/gs/os/wait_unimp.gs.ts +2 -0
- package/gs/os/zero_copy_posix.gs.ts +35 -0
- package/gs/os/zero_copy_stub.gs.ts +4 -0
- package/gs/reflect/ANALYSIS.md +278 -0
- package/gs/reflect/deepequal.ts +154 -0
- package/gs/reflect/function-types.test.ts +146 -0
- package/gs/reflect/godoc.txt +67 -0
- package/gs/reflect/index.ts +83 -0
- package/gs/reflect/iter.ts +44 -0
- package/gs/reflect/map.ts +81 -0
- package/gs/reflect/swapper.ts +52 -0
- package/gs/reflect/type.ts +1012 -0
- package/gs/reflect/types.ts +214 -0
- package/gs/reflect/value.ts +264 -0
- package/gs/reflect/visiblefields.ts +173 -0
- package/gs/strconv/index.ts +39 -6
- package/gs/strings/index.ts +7 -1
- package/gs/strings/replace.ts +1 -9
- package/gs/sync/atomic/index.ts +53 -4
- package/gs/syscall/index.ts +212 -0
- package/gs/unsafe/unsafe.ts +1 -1
- package/package.json +2 -1
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
// Common types used throughout the reflect module
|
|
2
|
+
|
|
3
|
+
// Basic Go types that need TypeScript equivalents
|
|
4
|
+
export type uintptr = number
|
|
5
|
+
|
|
6
|
+
// Define a proper type-safe Pointer type
|
|
7
|
+
export interface UnsafePointer {
|
|
8
|
+
readonly __unsafePointerBrand: unique symbol
|
|
9
|
+
value: unknown
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type Pointer = UnsafePointer | null
|
|
13
|
+
|
|
14
|
+
// Define the possible JavaScript values that can be reflected
|
|
15
|
+
export type ReflectValue =
|
|
16
|
+
| null
|
|
17
|
+
| undefined
|
|
18
|
+
| boolean
|
|
19
|
+
| number
|
|
20
|
+
| bigint
|
|
21
|
+
| string
|
|
22
|
+
| symbol
|
|
23
|
+
| Function //eslint-disable-line @typescript-eslint/no-unsafe-function-type
|
|
24
|
+
| object
|
|
25
|
+
| unknown[]
|
|
26
|
+
| Map<unknown, unknown>
|
|
27
|
+
| Set<unknown>
|
|
28
|
+
| Uint8Array
|
|
29
|
+
| Int8Array
|
|
30
|
+
| Uint16Array
|
|
31
|
+
| Int16Array
|
|
32
|
+
| Uint32Array
|
|
33
|
+
| Int32Array
|
|
34
|
+
| Float32Array
|
|
35
|
+
| Float64Array
|
|
36
|
+
|
|
37
|
+
// Channel direction constants and type
|
|
38
|
+
export class ChanDir {
|
|
39
|
+
constructor(private _value: number) {}
|
|
40
|
+
|
|
41
|
+
valueOf(): number {
|
|
42
|
+
return this._value
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
toString(): string {
|
|
46
|
+
switch (this._value) {
|
|
47
|
+
case 1:
|
|
48
|
+
return 'RecvDir'
|
|
49
|
+
case 2:
|
|
50
|
+
return 'SendDir'
|
|
51
|
+
case 3:
|
|
52
|
+
return 'BothDir'
|
|
53
|
+
default:
|
|
54
|
+
return 'InvalidDir'
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export const RecvDir = new ChanDir(1)
|
|
60
|
+
export const SendDir = new ChanDir(2)
|
|
61
|
+
export const BothDir = new ChanDir(3)
|
|
62
|
+
|
|
63
|
+
// Import Type and Kind from the main type module
|
|
64
|
+
import { Type, Kind, Value } from './type.js'
|
|
65
|
+
|
|
66
|
+
// Struct field representation
|
|
67
|
+
export class StructField {
|
|
68
|
+
public Name: string = ''
|
|
69
|
+
public Type!: Type
|
|
70
|
+
public Tag?: StructTag
|
|
71
|
+
public Offset?: uintptr
|
|
72
|
+
public Index?: number[]
|
|
73
|
+
public Anonymous?: boolean
|
|
74
|
+
|
|
75
|
+
constructor(init?: Partial<StructField>) {
|
|
76
|
+
if (init) {
|
|
77
|
+
Object.assign(this, init)
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
public clone(): StructField {
|
|
82
|
+
return new StructField({
|
|
83
|
+
Name: this.Name,
|
|
84
|
+
Type: this.Type,
|
|
85
|
+
Tag: this.Tag,
|
|
86
|
+
Offset: this.Offset,
|
|
87
|
+
Index: this.Index ? [...this.Index] : undefined,
|
|
88
|
+
Anonymous: this.Anonymous,
|
|
89
|
+
})
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Struct tag type
|
|
94
|
+
export class StructTag {
|
|
95
|
+
constructor(private _value: string) {}
|
|
96
|
+
|
|
97
|
+
toString(): string {
|
|
98
|
+
return this._value
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
Get(key: string): string {
|
|
102
|
+
// Simple tag parsing - in a real implementation this would be more sophisticated
|
|
103
|
+
const parts = this._value.split(' ')
|
|
104
|
+
for (const part of parts) {
|
|
105
|
+
if (part.startsWith(key + ':')) {
|
|
106
|
+
const value = part.substring(key.length + 1)
|
|
107
|
+
if (value.startsWith('"') && value.endsWith('"')) {
|
|
108
|
+
return value.slice(1, -1)
|
|
109
|
+
}
|
|
110
|
+
return value
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return ''
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Method representation
|
|
118
|
+
export interface Method {
|
|
119
|
+
Name: string
|
|
120
|
+
Type: Type
|
|
121
|
+
Func: Function //eslint-disable-line @typescript-eslint/no-unsafe-function-type
|
|
122
|
+
Index: number
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Channel type for reflection
|
|
126
|
+
export interface Channel<T = unknown> {
|
|
127
|
+
readonly __channelBrand: unique symbol
|
|
128
|
+
direction: ChanDir
|
|
129
|
+
elementType: Type
|
|
130
|
+
buffer: T[]
|
|
131
|
+
closed: boolean
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Select case for channel operations
|
|
135
|
+
export interface SelectCase {
|
|
136
|
+
Dir: SelectDir
|
|
137
|
+
Chan?: Value // Value representing a channel - optional since default cases don't need it
|
|
138
|
+
Send?: Value // Value to send (if Dir is SendDir) - optional since only needed for send cases
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Select direction constants
|
|
142
|
+
export class SelectDir {
|
|
143
|
+
constructor(private _value: number) {}
|
|
144
|
+
|
|
145
|
+
valueOf(): number {
|
|
146
|
+
return this._value
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export const SelectSend = new SelectDir(1)
|
|
151
|
+
export const SelectRecv = new SelectDir(2)
|
|
152
|
+
export const SelectDefault = new SelectDir(3)
|
|
153
|
+
|
|
154
|
+
// Slice header (internal representation)
|
|
155
|
+
export interface SliceHeader {
|
|
156
|
+
Data: uintptr
|
|
157
|
+
Len: number
|
|
158
|
+
Cap: number
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// String header (internal representation)
|
|
162
|
+
export interface StringHeader {
|
|
163
|
+
Data: uintptr
|
|
164
|
+
Len: number
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// Map iterator with proper typing
|
|
168
|
+
export interface MapIter<K = unknown, V = unknown> {
|
|
169
|
+
map: Map<K, V>
|
|
170
|
+
iterator: Iterator<[K, V]>
|
|
171
|
+
current: IteratorResult<[K, V]> | null
|
|
172
|
+
Key(): K | null
|
|
173
|
+
Value(): V | null
|
|
174
|
+
Next(): boolean
|
|
175
|
+
Reset(m: Map<K, V>): void
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// Bit vector for tracking pointers
|
|
179
|
+
export class bitVector {
|
|
180
|
+
private bits: number[] = []
|
|
181
|
+
|
|
182
|
+
Set(index: number): void {
|
|
183
|
+
const wordIndex = Math.floor(index / 32)
|
|
184
|
+
const bitIndex = index % 32
|
|
185
|
+
while (this.bits.length <= wordIndex) {
|
|
186
|
+
this.bits.push(0)
|
|
187
|
+
}
|
|
188
|
+
this.bits[wordIndex] |= 1 << bitIndex
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
Get(index: number): boolean {
|
|
192
|
+
const wordIndex = Math.floor(index / 32)
|
|
193
|
+
const bitIndex = index % 32
|
|
194
|
+
if (wordIndex >= this.bits.length) {
|
|
195
|
+
return false
|
|
196
|
+
}
|
|
197
|
+
return (this.bits[wordIndex] & (1 << bitIndex)) !== 0
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// Value error type
|
|
202
|
+
export class ValueError extends Error {
|
|
203
|
+
public Kind: Kind
|
|
204
|
+
public Method: string
|
|
205
|
+
|
|
206
|
+
constructor(init: { Kind: Kind; Method: string }) {
|
|
207
|
+
super(
|
|
208
|
+
`reflect: call of reflect.Value.${init.Method} on ${init.Kind.String()} Value`,
|
|
209
|
+
)
|
|
210
|
+
this.Kind = init.Kind
|
|
211
|
+
this.Method = init.Method
|
|
212
|
+
this.name = 'ValueError'
|
|
213
|
+
}
|
|
214
|
+
}
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Array,
|
|
3
|
+
Bool,
|
|
4
|
+
Float32,
|
|
5
|
+
Float64,
|
|
6
|
+
Int,
|
|
7
|
+
Int16,
|
|
8
|
+
Int32,
|
|
9
|
+
Int64,
|
|
10
|
+
Int8,
|
|
11
|
+
Map,
|
|
12
|
+
PointerTo,
|
|
13
|
+
Ptr,
|
|
14
|
+
Slice,
|
|
15
|
+
String,
|
|
16
|
+
Type,
|
|
17
|
+
Uint,
|
|
18
|
+
Uint16,
|
|
19
|
+
Uint32,
|
|
20
|
+
Uint64,
|
|
21
|
+
Uint8,
|
|
22
|
+
Uintptr,
|
|
23
|
+
Value,
|
|
24
|
+
Chan,
|
|
25
|
+
BasicType,
|
|
26
|
+
Invalid,
|
|
27
|
+
} from './type.js'
|
|
28
|
+
import { ReflectValue, SelectCase, SelectRecv, SelectDefault } from './types.js'
|
|
29
|
+
import * as $ from '@goscript/builtin/builtin.js'
|
|
30
|
+
|
|
31
|
+
// Re-export ValueOf from type.ts for compatibility
|
|
32
|
+
export { ValueOf } from './type'
|
|
33
|
+
|
|
34
|
+
// Zero returns a Value representing the zero value for the specified type.
|
|
35
|
+
export function Zero(typ: Type): Value {
|
|
36
|
+
let zeroValue: ReflectValue
|
|
37
|
+
|
|
38
|
+
switch (typ.Kind().valueOf()) {
|
|
39
|
+
case Bool.valueOf():
|
|
40
|
+
zeroValue = false
|
|
41
|
+
break
|
|
42
|
+
case Int.valueOf():
|
|
43
|
+
case Int8.valueOf():
|
|
44
|
+
case Int16.valueOf():
|
|
45
|
+
case Int32.valueOf():
|
|
46
|
+
case Int64.valueOf():
|
|
47
|
+
case Uint.valueOf():
|
|
48
|
+
case Uint8.valueOf():
|
|
49
|
+
case Uint16.valueOf():
|
|
50
|
+
case Uint32.valueOf():
|
|
51
|
+
case Uint64.valueOf():
|
|
52
|
+
case Uintptr.valueOf():
|
|
53
|
+
case Float32.valueOf():
|
|
54
|
+
case Float64.valueOf():
|
|
55
|
+
zeroValue = 0
|
|
56
|
+
break
|
|
57
|
+
case String.valueOf():
|
|
58
|
+
zeroValue = ''
|
|
59
|
+
break
|
|
60
|
+
case Slice.valueOf():
|
|
61
|
+
case Array.valueOf():
|
|
62
|
+
zeroValue = []
|
|
63
|
+
break
|
|
64
|
+
default:
|
|
65
|
+
zeroValue = null
|
|
66
|
+
break
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return new Value(zeroValue, typ)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Copy copies the contents of src to dst until either dst has been filled
|
|
73
|
+
// or src has been exhausted. It returns the number of elements copied.
|
|
74
|
+
export function Copy(dst: Value, src: Value): number {
|
|
75
|
+
// Extract the underlying arrays from the Value objects
|
|
76
|
+
const dstArray = getArrayFromValue(dst)
|
|
77
|
+
const srcArray = getArrayFromValue(src)
|
|
78
|
+
|
|
79
|
+
if (!dstArray || !srcArray) {
|
|
80
|
+
return 0
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const count = Math.min(dstArray.length, srcArray.length)
|
|
84
|
+
for (let i = 0; i < count; i++) {
|
|
85
|
+
dstArray[i] = srcArray[i]
|
|
86
|
+
}
|
|
87
|
+
return count
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Helper function to extract the underlying array from a Value
|
|
91
|
+
function getArrayFromValue(value: Value): unknown[] | null {
|
|
92
|
+
const val = (value as unknown as { value: ReflectValue }).value
|
|
93
|
+
|
|
94
|
+
// Check for GoScript slice objects created by $.arrayToSlice
|
|
95
|
+
if (val && typeof val === 'object' && '__meta__' in val) {
|
|
96
|
+
const meta = (val as { __meta__?: { backing?: unknown[] } }).__meta__
|
|
97
|
+
if (meta && meta.backing && globalThis.Array.isArray(meta.backing)) {
|
|
98
|
+
return meta.backing
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Check for regular JavaScript arrays
|
|
103
|
+
if (globalThis.Array.isArray(val)) {
|
|
104
|
+
return val
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return null
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Indirect returns the value that v points to.
|
|
111
|
+
export function Indirect(v: Value): Value {
|
|
112
|
+
// Check if this is a pointer type
|
|
113
|
+
const type = v.Type()
|
|
114
|
+
if (type.Kind().valueOf() === Ptr.valueOf()) {
|
|
115
|
+
// Ptr kind
|
|
116
|
+
const elemType = type.Elem()
|
|
117
|
+
if (elemType) {
|
|
118
|
+
// Return a new Value with the same underlying value but the element type
|
|
119
|
+
return new Value(
|
|
120
|
+
(v as unknown as { value: ReflectValue }).value,
|
|
121
|
+
elemType,
|
|
122
|
+
)
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
// For non-pointer types, just return the value as-is
|
|
126
|
+
return v
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// New returns a Value representing a pointer to a new zero value for the specified type.
|
|
130
|
+
export function New(typ: Type): Value {
|
|
131
|
+
const ptrType = PointerTo(typ)
|
|
132
|
+
// For the pointer value, we'll use the zero value but with pointer type
|
|
133
|
+
// In a real implementation, this would be a pointer to the zero value
|
|
134
|
+
return new Value(null, ptrType) // null represents the pointer value
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// MakeSlice returns a Value representing a new slice with the specified type, length, and capacity.
|
|
138
|
+
export function MakeSlice(typ: Type, len: number, _cap: number): Value {
|
|
139
|
+
if (typ.Kind().valueOf() !== Slice.valueOf()) {
|
|
140
|
+
throw new Error('reflect.MakeSlice of non-slice type')
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Create a slice with the specified length, filled with zero values
|
|
144
|
+
const elemType = typ.Elem()
|
|
145
|
+
if (!elemType) {
|
|
146
|
+
throw new Error('slice type missing element type')
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const zeroValue = Zero(elemType)
|
|
150
|
+
const zeroVal = (zeroValue as unknown as { value: ReflectValue }).value
|
|
151
|
+
const array = new globalThis.Array(len).fill(zeroVal)
|
|
152
|
+
|
|
153
|
+
return new Value(array, typ)
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// MakeMap returns a Value representing a new map with the specified type.
|
|
157
|
+
export function MakeMap(typ: Type): Value {
|
|
158
|
+
if (typ.Kind().valueOf() !== Map.valueOf()) {
|
|
159
|
+
throw new Error('reflect.MakeMap of non-map type')
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const map = new globalThis.Map()
|
|
163
|
+
return new Value(map, typ)
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Append appends the values x to a slice and returns the resulting slice.
|
|
167
|
+
export function Append(s: Value, x: Value): Value {
|
|
168
|
+
if (s.Kind().valueOf() !== Slice.valueOf()) {
|
|
169
|
+
throw new Error('reflect.Append of non-slice')
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const array = getArrayFromValue(s)
|
|
173
|
+
if (!array) {
|
|
174
|
+
throw new Error('cannot get array from slice value')
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const newValue = (x as unknown as { value: ReflectValue }).value
|
|
178
|
+
const newArray = [...array, newValue]
|
|
179
|
+
|
|
180
|
+
return new Value(newArray, s.Type())
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// MakeChan returns a Value representing a new channel with the specified type.
|
|
184
|
+
export function MakeChan(typ: Type, buffer: number): Value {
|
|
185
|
+
if (typ.Kind().valueOf() !== Chan.valueOf()) {
|
|
186
|
+
throw new Error('reflect.MakeChan of non-chan type')
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const elemType = typ.Elem()
|
|
190
|
+
if (!elemType) {
|
|
191
|
+
throw new Error('channel type missing element type')
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// Get the zero value for the channel element type
|
|
195
|
+
const zeroValue = Zero(elemType)
|
|
196
|
+
const zeroVal = (zeroValue as unknown as { value: ReflectValue }).value
|
|
197
|
+
|
|
198
|
+
// Create a channel using the builtin makeChannel function
|
|
199
|
+
const channel = $.makeChannel(buffer, zeroVal)
|
|
200
|
+
return new Value(channel, typ)
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// Select executes a select operation on the provided cases.
|
|
204
|
+
// It returns the index of the chosen case, the received value (if applicable), and whether the receive was successful.
|
|
205
|
+
export function Select(cases: $.Slice<SelectCase>): [number, Value, boolean] {
|
|
206
|
+
// Extract the backing array from the GoScript slice
|
|
207
|
+
let selectCases: SelectCase[] = []
|
|
208
|
+
if (cases && typeof cases === 'object' && '__meta__' in cases) {
|
|
209
|
+
// This is a GoScript slice, extract the backing array
|
|
210
|
+
const meta = (cases as { __meta__?: { backing?: SelectCase[] } }).__meta__
|
|
211
|
+
if (meta && meta.backing) {
|
|
212
|
+
selectCases = meta.backing
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// Check for ready channels (channels with queued values)
|
|
217
|
+
for (let i = 0; i < selectCases.length; i++) {
|
|
218
|
+
const selectCase = selectCases[i]
|
|
219
|
+
if (selectCase.Dir.valueOf() === SelectRecv.valueOf() && selectCase.Chan) {
|
|
220
|
+
const channelValue = selectCase.Chan
|
|
221
|
+
const channelObj = (channelValue as unknown as { value: any }).value
|
|
222
|
+
|
|
223
|
+
// Check if there are queued values to receive
|
|
224
|
+
if (
|
|
225
|
+
channelObj &&
|
|
226
|
+
channelObj._sendQueue &&
|
|
227
|
+
channelObj._sendQueue.length > 0
|
|
228
|
+
) {
|
|
229
|
+
const receivedValue = channelObj._sendQueue.shift() // Remove from queue
|
|
230
|
+
const elemType = channelValue.Type().Elem()
|
|
231
|
+
if (elemType) {
|
|
232
|
+
const recvVal = new Value(receivedValue, elemType)
|
|
233
|
+
return [i, recvVal, true]
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// Look for default case if no channels are ready
|
|
240
|
+
for (let i = 0; i < selectCases.length; i++) {
|
|
241
|
+
const selectCase = selectCases[i]
|
|
242
|
+
if (selectCase.Dir.valueOf() === SelectDefault.valueOf()) {
|
|
243
|
+
// Default case is immediately available
|
|
244
|
+
return [i, new Value(null, new BasicType(Invalid, 'invalid')), false]
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// If no channels are ready and no default case, return first case as fallback
|
|
249
|
+
if (selectCases.length > 0) {
|
|
250
|
+
const firstCase = selectCases[0]
|
|
251
|
+
if (firstCase.Dir.valueOf() === SelectRecv.valueOf() && firstCase.Chan) {
|
|
252
|
+
// Simulate receiving a zero value
|
|
253
|
+
const elemType = firstCase.Chan.Type().Elem()
|
|
254
|
+
if (elemType) {
|
|
255
|
+
const zeroVal = Zero(elemType)
|
|
256
|
+
return [0, zeroVal, true]
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return [0, new Value(null, new BasicType(Invalid, 'invalid')), false]
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// Fallback
|
|
263
|
+
return [0, new Value(null, new BasicType(Invalid, 'invalid')), false]
|
|
264
|
+
}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import * as $ from '@goscript/builtin/builtin.js'
|
|
2
|
+
import { Type } from './type.js'
|
|
3
|
+
import { StructField } from './types.js'
|
|
4
|
+
|
|
5
|
+
// VisibleFields returns all the visible fields in t, which must be a
|
|
6
|
+
// struct type. A field is defined as visible if it's accessible
|
|
7
|
+
// directly with a FieldByName call. The returned fields include fields
|
|
8
|
+
// inside anonymous struct members and unexported fields. They follow
|
|
9
|
+
// the same order found in the struct, with anonymous fields followed
|
|
10
|
+
// immediately by their promoted fields.
|
|
11
|
+
//
|
|
12
|
+
// For each element e of the returned slice, the corresponding field
|
|
13
|
+
// can be retrieved from a value v of type t by calling v.FieldByIndex(e.Index).
|
|
14
|
+
export function VisibleFields(t: Type): $.Slice<StructField> {
|
|
15
|
+
if (t == null) {
|
|
16
|
+
$.panic('reflect: VisibleFields(nil)')
|
|
17
|
+
}
|
|
18
|
+
if (t!.Kind().valueOf() != 25) {
|
|
19
|
+
$.panic('reflect.VisibleFields of non-struct type ' + t!.String())
|
|
20
|
+
}
|
|
21
|
+
let w = new visibleFieldsWalker({
|
|
22
|
+
byName: $.makeMap<string, number>(),
|
|
23
|
+
fields: $.makeSlice<StructField>(0, t!.NumField!()),
|
|
24
|
+
index: $.makeSlice<number>(0, 2, 'number'),
|
|
25
|
+
visiting: $.makeMap<Type, boolean>(),
|
|
26
|
+
})
|
|
27
|
+
w.walk(t)
|
|
28
|
+
// Remove all the fields that have been hidden.
|
|
29
|
+
// Use an in-place removal that avoids copying in
|
|
30
|
+
// the common case that there are no hidden fields.
|
|
31
|
+
let j = 0
|
|
32
|
+
|
|
33
|
+
// A field has been removed. We need to shuffle
|
|
34
|
+
// all the subsequent elements up.
|
|
35
|
+
for (let i = 0; i < $.len(w.fields); i++) {
|
|
36
|
+
{
|
|
37
|
+
let f = w.fields![i]
|
|
38
|
+
if (f!.Name == '') {
|
|
39
|
+
continue
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// A field has been removed. We need to shuffle
|
|
43
|
+
// all the subsequent elements up.
|
|
44
|
+
if (i != j) {
|
|
45
|
+
// A field has been removed. We need to shuffle
|
|
46
|
+
// all the subsequent elements up.
|
|
47
|
+
w.fields![j] = f!.clone()
|
|
48
|
+
}
|
|
49
|
+
j++
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return $.goSlice(w.fields, undefined, j)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
class visibleFieldsWalker {
|
|
56
|
+
public get byName(): Map<string, number> {
|
|
57
|
+
return this._fields.byName.value
|
|
58
|
+
}
|
|
59
|
+
public set byName(value: Map<string, number>) {
|
|
60
|
+
this._fields.byName.value = value
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public get visiting(): Map<Type, boolean> {
|
|
64
|
+
return this._fields.visiting.value
|
|
65
|
+
}
|
|
66
|
+
public set visiting(value: Map<Type, boolean>) {
|
|
67
|
+
this._fields.visiting.value = value
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
public get fields(): $.Slice<StructField> {
|
|
71
|
+
return this._fields.fields.value
|
|
72
|
+
}
|
|
73
|
+
public set fields(value: $.Slice<StructField>) {
|
|
74
|
+
this._fields.fields.value = value
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
public get index(): $.Slice<number> {
|
|
78
|
+
return this._fields.index.value
|
|
79
|
+
}
|
|
80
|
+
public set index(value: $.Slice<number>) {
|
|
81
|
+
this._fields.index.value = value
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
public _fields: {
|
|
85
|
+
byName: $.VarRef<Map<string, number>>
|
|
86
|
+
visiting: $.VarRef<Map<Type, boolean>>
|
|
87
|
+
fields: $.VarRef<$.Slice<StructField>>
|
|
88
|
+
index: $.VarRef<$.Slice<number>>
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
constructor(
|
|
92
|
+
init?: Partial<{
|
|
93
|
+
byName?: Map<string, number>
|
|
94
|
+
fields?: $.Slice<StructField>
|
|
95
|
+
index?: $.Slice<number>
|
|
96
|
+
visiting?: Map<Type, boolean>
|
|
97
|
+
}>,
|
|
98
|
+
) {
|
|
99
|
+
this._fields = {
|
|
100
|
+
byName: $.varRef(init?.byName ?? $.makeMap<string, number>()),
|
|
101
|
+
visiting: $.varRef(init?.visiting ?? $.makeMap<Type, boolean>()),
|
|
102
|
+
fields: $.varRef(init?.fields ?? $.makeSlice<StructField>(0, 0)),
|
|
103
|
+
index: $.varRef(init?.index ?? $.makeSlice<number>(0, 2, 'number')),
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
public clone(): visibleFieldsWalker {
|
|
108
|
+
const cloned = new visibleFieldsWalker()
|
|
109
|
+
cloned._fields = {
|
|
110
|
+
byName: $.varRef(this._fields.byName.value),
|
|
111
|
+
visiting: $.varRef(this._fields.visiting.value),
|
|
112
|
+
fields: $.varRef(this._fields.fields.value),
|
|
113
|
+
index: $.varRef(this._fields.index.value),
|
|
114
|
+
}
|
|
115
|
+
return cloned
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// walk walks all the fields in the struct type t, visiting
|
|
119
|
+
// fields in index preorder and appending them to w.fields
|
|
120
|
+
// (this maintains the required ordering).
|
|
121
|
+
// Fields that have been overridden have their
|
|
122
|
+
// Name field cleared.
|
|
123
|
+
public walk(t: Type): void {
|
|
124
|
+
const w = this
|
|
125
|
+
if ($.mapGet(w.visiting, t, false)[0]) {
|
|
126
|
+
return
|
|
127
|
+
}
|
|
128
|
+
$.mapSet(w.visiting, t, true)
|
|
129
|
+
for (let i = 0; i < t!.NumField!(); i++) {
|
|
130
|
+
let f = t!.Field!(i).clone()
|
|
131
|
+
f.Index = $.append(null, w.index) as number[]
|
|
132
|
+
if (f.Anonymous) {
|
|
133
|
+
if (f.Type!.Kind().valueOf() == 22) {
|
|
134
|
+
const elemType = f.Type!.Elem!()
|
|
135
|
+
if (elemType) {
|
|
136
|
+
f.Type = elemType
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (f.Type!.Kind().valueOf() == 25) {
|
|
140
|
+
w.walk(f.Type)
|
|
141
|
+
}
|
|
142
|
+
} else {
|
|
143
|
+
w.fields = $.append(w.fields, f)
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
$.deleteMapEntry(w.visiting, t)
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Register this type with the runtime type system
|
|
150
|
+
static __typeInfo = $.registerStructType(
|
|
151
|
+
'visibleFieldsWalker',
|
|
152
|
+
new visibleFieldsWalker(),
|
|
153
|
+
[{ name: 'walk', args: [{ name: 't', type: 'Type' }], returns: [] }],
|
|
154
|
+
visibleFieldsWalker,
|
|
155
|
+
{
|
|
156
|
+
byName: {
|
|
157
|
+
kind: $.TypeKind.Map,
|
|
158
|
+
keyType: { kind: $.TypeKind.Basic, name: 'string' },
|
|
159
|
+
elemType: { kind: $.TypeKind.Basic, name: 'number' },
|
|
160
|
+
},
|
|
161
|
+
visiting: {
|
|
162
|
+
kind: $.TypeKind.Map,
|
|
163
|
+
keyType: 'Type',
|
|
164
|
+
elemType: { kind: $.TypeKind.Basic, name: 'boolean' },
|
|
165
|
+
},
|
|
166
|
+
fields: { kind: $.TypeKind.Slice, elemType: 'StructField' },
|
|
167
|
+
index: {
|
|
168
|
+
kind: $.TypeKind.Slice,
|
|
169
|
+
elemType: { kind: $.TypeKind.Basic, name: 'number' },
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
)
|
|
173
|
+
}
|
package/gs/strconv/index.ts
CHANGED
|
@@ -1,6 +1,39 @@
|
|
|
1
|
-
export { AppendBool, FormatBool, ParseBool } from
|
|
2
|
-
export { ParseFloat } from
|
|
3
|
-
export {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
export { AppendBool, FormatBool, ParseBool } from './atob.gs.js'
|
|
2
|
+
export { ParseFloat } from './atof.gs.js'
|
|
3
|
+
export {
|
|
4
|
+
Atoi,
|
|
5
|
+
ErrRange,
|
|
6
|
+
ErrSyntax,
|
|
7
|
+
IntSize,
|
|
8
|
+
NumError,
|
|
9
|
+
ParseInt,
|
|
10
|
+
ParseUint,
|
|
11
|
+
} from './atoi.gs.js'
|
|
12
|
+
export { AppendFloat, FormatFloat } from './ftoa.gs.js'
|
|
13
|
+
export {
|
|
14
|
+
AppendInt,
|
|
15
|
+
AppendUint,
|
|
16
|
+
FormatInt,
|
|
17
|
+
FormatUint,
|
|
18
|
+
Itoa,
|
|
19
|
+
} from './itoa.gs.js'
|
|
20
|
+
export {
|
|
21
|
+
AppendQuote,
|
|
22
|
+
AppendQuoteRune,
|
|
23
|
+
AppendQuoteRuneToASCII,
|
|
24
|
+
AppendQuoteRuneToGraphic,
|
|
25
|
+
AppendQuoteToASCII,
|
|
26
|
+
AppendQuoteToGraphic,
|
|
27
|
+
CanBackquote,
|
|
28
|
+
IsGraphic,
|
|
29
|
+
IsPrint,
|
|
30
|
+
Quote,
|
|
31
|
+
QuoteRune,
|
|
32
|
+
QuoteRuneToASCII,
|
|
33
|
+
QuoteRuneToGraphic,
|
|
34
|
+
QuoteToASCII,
|
|
35
|
+
QuoteToGraphic,
|
|
36
|
+
QuotedPrefix,
|
|
37
|
+
Unquote,
|
|
38
|
+
UnquoteChar,
|
|
39
|
+
} from './quote.gs.js'
|
package/gs/strings/index.ts
CHANGED
|
@@ -2,5 +2,11 @@ export * from './builder.js'
|
|
|
2
2
|
export * from './strings.js'
|
|
3
3
|
export * from './reader.js'
|
|
4
4
|
export { Replacer, NewReplacer } from './replace.js'
|
|
5
|
-
export {
|
|
5
|
+
export {
|
|
6
|
+
Lines,
|
|
7
|
+
FieldsSeq,
|
|
8
|
+
FieldsFuncSeq,
|
|
9
|
+
SplitSeq,
|
|
10
|
+
SplitAfterSeq,
|
|
11
|
+
} from './iter.js'
|
|
6
12
|
// Clone and Compare are already exported from strings.js, so we don't re-export them
|