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
|
@@ -6,7 +6,9 @@ describe('Nextafter', () => {
|
|
|
6
6
|
expect(Nextafter(1.0, 1.0)).toBe(1.0)
|
|
7
7
|
expect(Nextafter(0.0, 0.0)).toBe(0.0)
|
|
8
8
|
expect(Nextafter(-1.0, -1.0)).toBe(-1.0)
|
|
9
|
-
expect(Nextafter(Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY)).toBe(
|
|
9
|
+
expect(Nextafter(Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY)).toBe(
|
|
10
|
+
Number.POSITIVE_INFINITY,
|
|
11
|
+
)
|
|
10
12
|
})
|
|
11
13
|
|
|
12
14
|
it('should return NaN when either input is NaN', () => {
|
|
@@ -18,7 +20,7 @@ describe('Nextafter', () => {
|
|
|
18
20
|
it('should handle zero correctly', () => {
|
|
19
21
|
const nextPos = Nextafter(0, 1)
|
|
20
22
|
const nextNeg = Nextafter(0, -1)
|
|
21
|
-
|
|
23
|
+
|
|
22
24
|
expect(nextPos).toBeGreaterThan(0)
|
|
23
25
|
expect(nextNeg).toBeLessThan(0)
|
|
24
26
|
expect(Math.abs(nextPos)).toBe(Number.MIN_VALUE)
|
|
@@ -70,7 +72,7 @@ describe('Nextafter32', () => {
|
|
|
70
72
|
it('should handle zero correctly', () => {
|
|
71
73
|
const nextPos = Nextafter32(0, 1)
|
|
72
74
|
const nextNeg = Nextafter32(0, -1)
|
|
73
|
-
|
|
75
|
+
|
|
74
76
|
expect(nextPos).toBeGreaterThan(0)
|
|
75
77
|
expect(nextNeg).toBeLessThan(0)
|
|
76
78
|
// For float32, the smallest positive value is different
|
|
@@ -82,7 +84,7 @@ describe('Nextafter32', () => {
|
|
|
82
84
|
const x = 1.0
|
|
83
85
|
const nextUp = Nextafter32(x, 2.0)
|
|
84
86
|
const nextDown = Nextafter32(x, 0.0)
|
|
85
|
-
|
|
87
|
+
|
|
86
88
|
expect(nextUp).toBeGreaterThan(x)
|
|
87
89
|
expect(nextDown).toBeLessThan(x)
|
|
88
90
|
})
|
|
@@ -91,7 +93,7 @@ describe('Nextafter32', () => {
|
|
|
91
93
|
const x = 1.0
|
|
92
94
|
const nextUp = Nextafter32(x, Number.POSITIVE_INFINITY)
|
|
93
95
|
const nextDown = Nextafter32(x, 0.0)
|
|
94
|
-
|
|
96
|
+
|
|
95
97
|
expect(nextUp).toBeGreaterThan(x)
|
|
96
98
|
expect(nextDown).toBeLessThan(x)
|
|
97
99
|
})
|
|
@@ -100,8 +102,8 @@ describe('Nextafter32', () => {
|
|
|
100
102
|
const x = -1.0
|
|
101
103
|
const nextUp = Nextafter32(x, 0.0)
|
|
102
104
|
const nextDown = Nextafter32(x, -2.0)
|
|
103
|
-
|
|
105
|
+
|
|
104
106
|
expect(nextUp).toBeGreaterThan(x)
|
|
105
107
|
expect(nextDown).toBeLessThan(x)
|
|
106
108
|
})
|
|
107
|
-
})
|
|
109
|
+
})
|
package/gs/math/pow.gs.test.ts
CHANGED
|
@@ -37,7 +37,7 @@ describe('Pow', () => {
|
|
|
37
37
|
expect(Pow(2, Number.NEGATIVE_INFINITY)).toBe(0)
|
|
38
38
|
expect(Pow(0.5, Number.POSITIVE_INFINITY)).toBe(0)
|
|
39
39
|
expect(Pow(0.5, Number.NEGATIVE_INFINITY)).toBe(Number.POSITIVE_INFINITY)
|
|
40
|
-
|
|
40
|
+
|
|
41
41
|
expect(Pow(Number.POSITIVE_INFINITY, 1)).toBe(Number.POSITIVE_INFINITY)
|
|
42
42
|
expect(Pow(Number.POSITIVE_INFINITY, -1)).toBe(0)
|
|
43
43
|
expect(Pow(Number.NEGATIVE_INFINITY, 2)).toBe(Number.POSITIVE_INFINITY)
|
|
@@ -59,7 +59,7 @@ describe('Pow', () => {
|
|
|
59
59
|
|
|
60
60
|
it('should handle fractional exponents', () => {
|
|
61
61
|
expect(Pow(4, 0.5)).toBe(2)
|
|
62
|
-
expect(Pow(8, 1/3)).toBeCloseTo(2, 15)
|
|
62
|
+
expect(Pow(8, 1 / 3)).toBeCloseTo(2, 15)
|
|
63
63
|
expect(Pow(16, 0.25)).toBe(2)
|
|
64
64
|
})
|
|
65
65
|
})
|
|
@@ -69,7 +69,9 @@ describe('pow', () => {
|
|
|
69
69
|
expect(pow(2, 3)).toBe(Pow(2, 3))
|
|
70
70
|
expect(pow(0, 1)).toBe(Pow(0, 1))
|
|
71
71
|
expect(pow(-2, 2)).toBe(Pow(-2, 2))
|
|
72
|
-
expect(pow(Number.POSITIVE_INFINITY, 1)).toBe(
|
|
72
|
+
expect(pow(Number.POSITIVE_INFINITY, 1)).toBe(
|
|
73
|
+
Pow(Number.POSITIVE_INFINITY, 1),
|
|
74
|
+
)
|
|
73
75
|
})
|
|
74
76
|
})
|
|
75
77
|
|
|
@@ -100,4 +102,4 @@ describe('isOddInt', () => {
|
|
|
100
102
|
expect(isOddInt(1 << 53)).toBe(false) // too large
|
|
101
103
|
expect(isOddInt((1 << 53) - 1)).toBe(true) // largest odd integer
|
|
102
104
|
})
|
|
103
|
-
})
|
|
105
|
+
})
|
package/gs/math/pow10.gs.test.ts
CHANGED
package/gs/math/sin.gs.test.ts
CHANGED
|
@@ -6,7 +6,7 @@ describe('Sincos', () => {
|
|
|
6
6
|
const [sin, cos] = Sincos(0)
|
|
7
7
|
expect(sin).toBe(0)
|
|
8
8
|
expect(cos).toBe(1)
|
|
9
|
-
|
|
9
|
+
|
|
10
10
|
const [sinNeg, cosNeg] = Sincos(-0)
|
|
11
11
|
expect(sinNeg).toBe(-0)
|
|
12
12
|
expect(cosNeg).toBe(1)
|
|
@@ -16,15 +16,15 @@ describe('Sincos', () => {
|
|
|
16
16
|
const [sin1, cos1] = Sincos(Math.PI / 2)
|
|
17
17
|
expect(sin1).toBeCloseTo(1, 15)
|
|
18
18
|
expect(cos1).toBeCloseTo(0, 15)
|
|
19
|
-
|
|
19
|
+
|
|
20
20
|
const [sin2, cos2] = Sincos(-Math.PI / 2)
|
|
21
21
|
expect(sin2).toBeCloseTo(-1, 15)
|
|
22
22
|
expect(cos2).toBeCloseTo(0, 15)
|
|
23
|
-
|
|
23
|
+
|
|
24
24
|
const [sin3, cos3] = Sincos(Math.PI)
|
|
25
25
|
expect(sin3).toBeCloseTo(0, 15)
|
|
26
26
|
expect(cos3).toBeCloseTo(-1, 15)
|
|
27
|
-
|
|
27
|
+
|
|
28
28
|
const [sin4, cos4] = Sincos(-Math.PI)
|
|
29
29
|
expect(sin4).toBeCloseTo(0, 15)
|
|
30
30
|
expect(cos4).toBeCloseTo(-1, 15)
|
|
@@ -34,11 +34,11 @@ describe('Sincos', () => {
|
|
|
34
34
|
const [sin1, cos1] = Sincos(Math.PI / 6)
|
|
35
35
|
expect(sin1).toBeCloseTo(0.5, 15)
|
|
36
36
|
expect(cos1).toBeCloseTo(Math.sqrt(3) / 2, 15)
|
|
37
|
-
|
|
37
|
+
|
|
38
38
|
const [sin2, cos2] = Sincos(Math.PI / 4)
|
|
39
39
|
expect(sin2).toBeCloseTo(Math.sqrt(2) / 2, 15)
|
|
40
40
|
expect(cos2).toBeCloseTo(Math.sqrt(2) / 2, 15)
|
|
41
|
-
|
|
41
|
+
|
|
42
42
|
const [sin3, cos3] = Sincos(Math.PI / 3)
|
|
43
43
|
expect(sin3).toBeCloseTo(Math.sqrt(3) / 2, 15)
|
|
44
44
|
expect(cos3).toBeCloseTo(0.5, 15)
|
|
@@ -48,19 +48,29 @@ describe('Sincos', () => {
|
|
|
48
48
|
const [sin1, cos1] = Sincos(Number.POSITIVE_INFINITY)
|
|
49
49
|
expect(Number.isNaN(sin1)).toBe(true)
|
|
50
50
|
expect(Number.isNaN(cos1)).toBe(true)
|
|
51
|
-
|
|
51
|
+
|
|
52
52
|
const [sin2, cos2] = Sincos(Number.NEGATIVE_INFINITY)
|
|
53
53
|
expect(Number.isNaN(sin2)).toBe(true)
|
|
54
54
|
expect(Number.isNaN(cos2)).toBe(true)
|
|
55
|
-
|
|
55
|
+
|
|
56
56
|
const [sin3, cos3] = Sincos(Number.NaN)
|
|
57
57
|
expect(Number.isNaN(sin3)).toBe(true)
|
|
58
58
|
expect(Number.isNaN(cos3)).toBe(true)
|
|
59
59
|
})
|
|
60
60
|
|
|
61
61
|
it('should satisfy the Pythagorean identity', () => {
|
|
62
|
-
const testValues = [
|
|
63
|
-
|
|
62
|
+
const testValues = [
|
|
63
|
+
0,
|
|
64
|
+
Math.PI / 6,
|
|
65
|
+
Math.PI / 4,
|
|
66
|
+
Math.PI / 3,
|
|
67
|
+
Math.PI / 2,
|
|
68
|
+
Math.PI,
|
|
69
|
+
1.5,
|
|
70
|
+
2.7,
|
|
71
|
+
-1.2,
|
|
72
|
+
]
|
|
73
|
+
|
|
64
74
|
for (const x of testValues) {
|
|
65
75
|
const [sin, cos] = Sincos(x)
|
|
66
76
|
expect(sin * sin + cos * cos).toBeCloseTo(1, 14)
|
|
@@ -72,7 +82,7 @@ describe('Sincos', () => {
|
|
|
72
82
|
const [sin1, cos1] = Sincos(x)
|
|
73
83
|
const [sin2, cos2] = Sincos(x + 2 * Math.PI)
|
|
74
84
|
const [sin3, cos3] = Sincos(x + 4 * Math.PI)
|
|
75
|
-
|
|
85
|
+
|
|
76
86
|
expect(sin1).toBeCloseTo(sin2, 14)
|
|
77
87
|
expect(cos1).toBeCloseTo(cos2, 14)
|
|
78
88
|
expect(sin1).toBeCloseTo(sin3, 14)
|
|
@@ -80,12 +90,21 @@ describe('Sincos', () => {
|
|
|
80
90
|
})
|
|
81
91
|
|
|
82
92
|
it('should match individual Math.sin and Math.cos calls', () => {
|
|
83
|
-
const testValues = [
|
|
84
|
-
|
|
93
|
+
const testValues = [
|
|
94
|
+
0,
|
|
95
|
+
Math.PI / 6,
|
|
96
|
+
Math.PI / 4,
|
|
97
|
+
Math.PI / 3,
|
|
98
|
+
Math.PI / 2,
|
|
99
|
+
Math.PI,
|
|
100
|
+
1.5,
|
|
101
|
+
-1.2,
|
|
102
|
+
]
|
|
103
|
+
|
|
85
104
|
for (const x of testValues) {
|
|
86
105
|
const [sin, cos] = Sincos(x)
|
|
87
106
|
expect(sin).toBeCloseTo(Math.sin(x), 15)
|
|
88
107
|
expect(cos).toBeCloseTo(Math.cos(x), 15)
|
|
89
108
|
}
|
|
90
109
|
})
|
|
91
|
-
})
|
|
110
|
+
})
|
package/gs/math/sinh.gs.test.ts
CHANGED
package/gs/math/sqrt.gs.test.ts
CHANGED
package/gs/math/tan.gs.test.ts
CHANGED
|
@@ -22,8 +22,8 @@ describe('Tan', () => {
|
|
|
22
22
|
it('should approach infinity near asymptotes', () => {
|
|
23
23
|
const nearPiOver2 = Math.PI / 2 - 1e-10
|
|
24
24
|
expect(Math.abs(Tan(nearPiOver2))).toBeGreaterThan(1e9)
|
|
25
|
-
|
|
26
|
-
const near3PiOver2 = 3 * Math.PI / 2 - 1e-10
|
|
25
|
+
|
|
26
|
+
const near3PiOver2 = (3 * Math.PI) / 2 - 1e-10
|
|
27
27
|
expect(Math.abs(Tan(near3PiOver2))).toBeGreaterThan(1e9)
|
|
28
28
|
})
|
|
29
29
|
|
|
@@ -47,4 +47,4 @@ describe('tan', () => {
|
|
|
47
47
|
expect(tan(Math.PI)).toBe(Tan(Math.PI))
|
|
48
48
|
expect(Number.isNaN(tan(Number.NaN))).toBe(Number.isNaN(Tan(Number.NaN)))
|
|
49
49
|
})
|
|
50
|
-
})
|
|
50
|
+
})
|
package/gs/math/tanh.gs.test.ts
CHANGED
package/gs/os/dir.gs.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import * as $ from "@goscript/builtin/builtin.js";
|
|
2
|
+
import { ErrUnimplemented } from "./error.gs.js";
|
|
3
|
+
|
|
4
|
+
import * as fs from "@goscript/io/fs/index.js"
|
|
5
|
+
|
|
6
|
+
type DirEntry = fs.DirEntry;
|
|
7
|
+
|
|
8
|
+
// ReadDir reads the named directory,
|
|
9
|
+
// returning all its directory entries sorted by filename.
|
|
10
|
+
// If an error occurs reading the directory,
|
|
11
|
+
// ReadDir returns the entries it was able to read before the error,
|
|
12
|
+
// along with the error.
|
|
13
|
+
export function ReadDir(name: string): [$.Slice<DirEntry>, $.GoError] {
|
|
14
|
+
// Directory reading not supported in JavaScript environment
|
|
15
|
+
return [null, ErrUnimplemented]
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// CopyFS copies the file system fsys into the directory dir,
|
|
19
|
+
// creating dir if necessary.
|
|
20
|
+
//
|
|
21
|
+
// Files are created with mode 0o666 plus any execute permissions
|
|
22
|
+
// from the source, and directories are created with mode 0o777
|
|
23
|
+
// (before umask).
|
|
24
|
+
//
|
|
25
|
+
// CopyFS will not overwrite existing files. If a file name in fsys
|
|
26
|
+
// already exists in the destination, CopyFS will return an error
|
|
27
|
+
// such that errors.Is(err, fs.ErrExist) will be true.
|
|
28
|
+
//
|
|
29
|
+
// Symbolic links in fsys are not supported. A *PathError with Err set
|
|
30
|
+
// to ErrInvalid is returned when copying from a symbolic link.
|
|
31
|
+
//
|
|
32
|
+
// Symbolic links in dir are followed.
|
|
33
|
+
//
|
|
34
|
+
// New files added to fsys (including if dir is a subdirectory of fsys)
|
|
35
|
+
// while CopyFS is running are not guaranteed to be copied.
|
|
36
|
+
//
|
|
37
|
+
// Copying stops at and returns the first error encountered.
|
|
38
|
+
export function CopyFS(dir: string, fsys: fs.FS): $.GoError {
|
|
39
|
+
// File system copying not supported in JavaScript environment
|
|
40
|
+
return ErrUnimplemented
|
|
41
|
+
}
|
|
42
|
+
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import * as $ from "@goscript/builtin/builtin.js";
|
|
2
|
+
import { direntIno, direntNamlen, direntReclen, direntType } from "./dirent_js.gs.js";
|
|
3
|
+
import { IsNotExist } from "./error.gs.js";
|
|
4
|
+
import { newUnixDirent } from "./file_unix_js.gs.js";
|
|
5
|
+
|
|
6
|
+
import * as byteorder from "@goscript/internal/byteorder/index.js"
|
|
7
|
+
|
|
8
|
+
import * as goarch from "@goscript/internal/goarch/index.js"
|
|
9
|
+
|
|
10
|
+
import * as io from "@goscript/io/index.js"
|
|
11
|
+
|
|
12
|
+
import * as runtime from "@goscript/runtime/index.js"
|
|
13
|
+
|
|
14
|
+
import * as sync from "@goscript/sync/index.js"
|
|
15
|
+
|
|
16
|
+
import * as syscall from "@goscript/syscall/index.js"
|
|
17
|
+
|
|
18
|
+
import * as unsafe from "@goscript/unsafe/index.js"
|
|
19
|
+
|
|
20
|
+
// Import uintptr type
|
|
21
|
+
type uintptr = syscall.uintptr
|
|
22
|
+
|
|
23
|
+
class dirInfo {
|
|
24
|
+
public get mu(): sync.Mutex {
|
|
25
|
+
return this._fields.mu.value
|
|
26
|
+
}
|
|
27
|
+
public set mu(value: sync.Mutex) {
|
|
28
|
+
this._fields.mu.value = value
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// buffer for directory I/O
|
|
32
|
+
public get buf(): $.VarRef<$.Bytes> | null {
|
|
33
|
+
return this._fields.buf.value
|
|
34
|
+
}
|
|
35
|
+
public set buf(value: $.VarRef<$.Bytes> | null) {
|
|
36
|
+
this._fields.buf.value = value
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// length of buf; return value from Getdirentries
|
|
40
|
+
public get nbuf(): number {
|
|
41
|
+
return this._fields.nbuf.value
|
|
42
|
+
}
|
|
43
|
+
public set nbuf(value: number) {
|
|
44
|
+
this._fields.nbuf.value = value
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// location of next record in buf.
|
|
48
|
+
public get bufp(): number {
|
|
49
|
+
return this._fields.bufp.value
|
|
50
|
+
}
|
|
51
|
+
public set bufp(value: number) {
|
|
52
|
+
this._fields.bufp.value = value
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
public _fields: {
|
|
56
|
+
mu: $.VarRef<sync.Mutex>;
|
|
57
|
+
buf: $.VarRef<$.VarRef<$.Bytes> | null>;
|
|
58
|
+
nbuf: $.VarRef<number>;
|
|
59
|
+
bufp: $.VarRef<number>;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
constructor(init?: Partial<{buf?: $.VarRef<$.Bytes> | null, bufp?: number, mu?: sync.Mutex, nbuf?: number}>) {
|
|
63
|
+
this._fields = {
|
|
64
|
+
mu: $.varRef(init?.mu?.clone() ?? new sync.Mutex()),
|
|
65
|
+
buf: $.varRef(init?.buf ?? null),
|
|
66
|
+
nbuf: $.varRef(init?.nbuf ?? 0),
|
|
67
|
+
bufp: $.varRef(init?.bufp ?? 0)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
public clone(): dirInfo {
|
|
72
|
+
const cloned = new dirInfo()
|
|
73
|
+
cloned._fields = {
|
|
74
|
+
mu: $.varRef(this._fields.mu.value?.clone() ?? null),
|
|
75
|
+
buf: $.varRef(this._fields.buf.value),
|
|
76
|
+
nbuf: $.varRef(this._fields.nbuf.value),
|
|
77
|
+
bufp: $.varRef(this._fields.bufp.value)
|
|
78
|
+
}
|
|
79
|
+
return cloned
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
public close(): void {
|
|
83
|
+
const d = this
|
|
84
|
+
if (d.buf != null) {
|
|
85
|
+
dirBufPool.Put(d.buf)
|
|
86
|
+
d.buf = null
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Register this type with the runtime type system
|
|
91
|
+
static __typeInfo = $.registerStructType(
|
|
92
|
+
'dirInfo',
|
|
93
|
+
new dirInfo(),
|
|
94
|
+
[{ name: "close", args: [], returns: [] }],
|
|
95
|
+
dirInfo,
|
|
96
|
+
{"mu": "Mutex", "buf": { kind: $.TypeKind.Pointer, elemType: { kind: $.TypeKind.Slice, elemType: { kind: $.TypeKind.Basic, name: "number" } } }, "nbuf": { kind: $.TypeKind.Basic, name: "number" }, "bufp": { kind: $.TypeKind.Basic, name: "number" }}
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// More than 5760 to work around https://golang.org/issue/24015.
|
|
101
|
+
let blockSize: number = 8192
|
|
102
|
+
|
|
103
|
+
let dirBufPool: sync.Pool = new sync.Pool({New: (): null | any => {
|
|
104
|
+
// The buffer must be at least a block long.
|
|
105
|
+
let buf = new Uint8Array(8192)
|
|
106
|
+
return buf
|
|
107
|
+
}})
|
|
108
|
+
|
|
109
|
+
// readInt returns the size-bytes unsigned integer in native byte order at offset off.
|
|
110
|
+
export function readInt(b: $.Bytes, off: uintptr, size: uintptr): [number, boolean] {
|
|
111
|
+
let u: number = 0
|
|
112
|
+
let ok: boolean = false
|
|
113
|
+
{
|
|
114
|
+
if ($.len(b) < $.int(off + size)) {
|
|
115
|
+
return [0, false]
|
|
116
|
+
}
|
|
117
|
+
if (goarch.BigEndian) {
|
|
118
|
+
return [readIntBE($.goSlice(b, off, undefined), size), true]
|
|
119
|
+
}
|
|
120
|
+
return [readIntLE($.goSlice(b, off, undefined), size), true]
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export function readIntBE(b: $.Bytes, size: uintptr): number {
|
|
125
|
+
switch (size) {
|
|
126
|
+
case 1:
|
|
127
|
+
return (b![0] as number)
|
|
128
|
+
case 2:
|
|
129
|
+
return (byteorder.BEUint16(b) as number)
|
|
130
|
+
case 4:
|
|
131
|
+
return (byteorder.BEUint32(b) as number)
|
|
132
|
+
case 8:
|
|
133
|
+
return (byteorder.BEUint64(b) as number)
|
|
134
|
+
default:
|
|
135
|
+
$.panic("syscall: readInt with unsupported size")
|
|
136
|
+
return 0 // This line will never be reached due to panic, but satisfies TypeScript
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export function readIntLE(b: $.Bytes, size: uintptr): number {
|
|
141
|
+
switch (size) {
|
|
142
|
+
case 1:
|
|
143
|
+
return (b![0] as number)
|
|
144
|
+
case 2:
|
|
145
|
+
return (byteorder.LEUint16(b) as number)
|
|
146
|
+
case 4:
|
|
147
|
+
return (byteorder.LEUint32(b) as number)
|
|
148
|
+
case 8:
|
|
149
|
+
return (byteorder.LEUint64(b) as number)
|
|
150
|
+
default:
|
|
151
|
+
$.panic("syscall: readInt with unsupported size")
|
|
152
|
+
return 0 // This line will never be reached due to panic, but satisfies TypeScript
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as $ from "@goscript/builtin/builtin.js";
|
|
2
|
+
import { readInt } from "./dir_unix.gs.js";
|
|
3
|
+
|
|
4
|
+
import * as syscall from "@goscript/syscall/index.js"
|
|
5
|
+
|
|
6
|
+
import * as unsafe from "@goscript/unsafe/index.js"
|
|
7
|
+
|
|
8
|
+
export function direntIno(buf: $.Bytes): [number, boolean] {
|
|
9
|
+
return [1, true]
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function direntReclen(buf: $.Bytes): [number, boolean] {
|
|
13
|
+
return readInt(buf, unsafe.Offsetof(new syscall.Dirent({}).Reclen), unsafe.Sizeof(new syscall.Dirent({}).Reclen))
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function direntNamlen(buf: $.Bytes): [number, boolean] {
|
|
17
|
+
let [reclen, ok] = direntReclen(buf)
|
|
18
|
+
if (!ok) {
|
|
19
|
+
return [0, false]
|
|
20
|
+
}
|
|
21
|
+
return [reclen - (unsafe.Offsetof(new syscall.Dirent({}).Name) as number), true]
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function direntType(buf: $.Bytes): number {
|
|
25
|
+
return ~(0 as number)
|
|
26
|
+
}
|
|
27
|
+
|
package/gs/os/env.gs.ts
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import * as $ from "@goscript/builtin/builtin.js";
|
|
2
|
+
import { NewSyscallError } from "./error.gs.js";
|
|
3
|
+
|
|
4
|
+
import * as syscall from "@goscript/syscall/index.js"
|
|
5
|
+
|
|
6
|
+
// Expand replaces ${var} or $var in the string based on the mapping function.
|
|
7
|
+
// For example, [os.ExpandEnv](s) is equivalent to [os.Expand](s, [os.Getenv]).
|
|
8
|
+
export function Expand(s: string, mapping: ((p0: string) => string) | null): string {
|
|
9
|
+
let buf: $.Bytes = new Uint8Array(0)
|
|
10
|
+
// ${} is all ASCII, so bytes are fine for this operation.
|
|
11
|
+
let i = 0
|
|
12
|
+
|
|
13
|
+
// Encountered invalid syntax; eat the
|
|
14
|
+
// characters.
|
|
15
|
+
|
|
16
|
+
// Valid syntax, but $ was not followed by a
|
|
17
|
+
// name. Leave the dollar character untouched.
|
|
18
|
+
for (let j = 0; j < $.len(s); j++) {
|
|
19
|
+
|
|
20
|
+
// Encountered invalid syntax; eat the
|
|
21
|
+
// characters.
|
|
22
|
+
|
|
23
|
+
// Valid syntax, but $ was not followed by a
|
|
24
|
+
// name. Leave the dollar character untouched.
|
|
25
|
+
if ($.indexString(s, j) == 36 && j + 1 < $.len(s)) {
|
|
26
|
+
if (buf == null) {
|
|
27
|
+
buf = $.makeSlice<number>(0, 2 * $.len(s), 'byte')
|
|
28
|
+
}
|
|
29
|
+
buf = $.append(buf, ...$.stringToBytes($.sliceString(s, i, j)))
|
|
30
|
+
let [name, w] = getShellName($.sliceString(s, j + 1, undefined))
|
|
31
|
+
|
|
32
|
+
// Encountered invalid syntax; eat the
|
|
33
|
+
// characters.
|
|
34
|
+
|
|
35
|
+
// Valid syntax, but $ was not followed by a
|
|
36
|
+
// name. Leave the dollar character untouched.
|
|
37
|
+
if (name == "" && w > 0) {
|
|
38
|
+
|
|
39
|
+
} else if (name == "") {
|
|
40
|
+
// Valid syntax, but $ was not followed by a
|
|
41
|
+
// name. Leave the dollar character untouched.
|
|
42
|
+
buf = $.append(buf, $.indexString(s, j))
|
|
43
|
+
} else {
|
|
44
|
+
buf = $.append(buf, ...$.stringToBytes(mapping!(name)))
|
|
45
|
+
}
|
|
46
|
+
j += w
|
|
47
|
+
i = j + 1
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (buf == null) {
|
|
51
|
+
return s
|
|
52
|
+
}
|
|
53
|
+
return $.bytesToString(buf) + $.sliceString(s, i, undefined)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// ExpandEnv replaces ${var} or $var in the string according to the values
|
|
57
|
+
// of the current environment variables. References to undefined
|
|
58
|
+
// variables are replaced by the empty string.
|
|
59
|
+
export function ExpandEnv(s: string): string {
|
|
60
|
+
return Expand(s, Getenv)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// isShellSpecialVar reports whether the character identifies a special
|
|
64
|
+
// shell variable such as $*.
|
|
65
|
+
export function isShellSpecialVar(c: number): boolean {
|
|
66
|
+
switch (c) {
|
|
67
|
+
case 42:
|
|
68
|
+
case 35:
|
|
69
|
+
case 36:
|
|
70
|
+
case 64:
|
|
71
|
+
case 33:
|
|
72
|
+
case 63:
|
|
73
|
+
case 45:
|
|
74
|
+
case 48:
|
|
75
|
+
case 49:
|
|
76
|
+
case 50:
|
|
77
|
+
case 51:
|
|
78
|
+
case 52:
|
|
79
|
+
case 53:
|
|
80
|
+
case 54:
|
|
81
|
+
case 55:
|
|
82
|
+
case 56:
|
|
83
|
+
case 57:
|
|
84
|
+
return true
|
|
85
|
+
break
|
|
86
|
+
}
|
|
87
|
+
return false
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// isAlphaNum reports whether the byte is an ASCII letter, number, or underscore.
|
|
91
|
+
export function isAlphaNum(c: number): boolean {
|
|
92
|
+
return c == 95 || 48 <= c && c <= 57 || 97 <= c && c <= 122 || 65 <= c && c <= 90
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// getShellName returns the name that begins the string and the number of bytes
|
|
96
|
+
// consumed to extract it. If the name is enclosed in {}, it's part of a ${}
|
|
97
|
+
// expansion and two more bytes are needed than the length of the name.
|
|
98
|
+
export function getShellName(s: string): [string, number] {
|
|
99
|
+
|
|
100
|
+
// Scan to closing brace
|
|
101
|
+
|
|
102
|
+
// Bad syntax; eat "${}"
|
|
103
|
+
|
|
104
|
+
// Bad syntax; eat "${"
|
|
105
|
+
switch (true) {
|
|
106
|
+
case $.indexString(s, 0) == 123:
|
|
107
|
+
if ($.len(s) > 2 && isShellSpecialVar($.indexString(s, 1)) && $.indexString(s, 2) == 125) {
|
|
108
|
+
return [$.sliceString(s, 1, 2), 3]
|
|
109
|
+
}
|
|
110
|
+
for (let i = 1; i < $.len(s); i++) {
|
|
111
|
+
|
|
112
|
+
// Bad syntax; eat "${}"
|
|
113
|
+
if ($.indexString(s, i) == 125) {
|
|
114
|
+
|
|
115
|
+
// Bad syntax; eat "${}"
|
|
116
|
+
if (i == 1) {
|
|
117
|
+
return ["", 2]
|
|
118
|
+
}
|
|
119
|
+
return [$.sliceString(s, 1, i), i + 1]
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return ["", 1]
|
|
123
|
+
break
|
|
124
|
+
case isShellSpecialVar($.indexString(s, 0)):
|
|
125
|
+
return [$.sliceString(s, 0, 1), 1]
|
|
126
|
+
break
|
|
127
|
+
}
|
|
128
|
+
// Scan alphanumerics.
|
|
129
|
+
let i: number = 0
|
|
130
|
+
for (i = 0; i < $.len(s) && isAlphaNum($.indexString(s, i)); i++) {
|
|
131
|
+
}
|
|
132
|
+
return [$.sliceString(s, undefined, i), i]
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Getenv retrieves the value of the environment variable named by the key.
|
|
136
|
+
// It returns the value, which will be empty if the variable is not present.
|
|
137
|
+
// To distinguish between an empty value and an unset value, use [LookupEnv].
|
|
138
|
+
export function Getenv(key: string): string {
|
|
139
|
+
// testlog.Getenv(key) // Testlog not available in JavaScript
|
|
140
|
+
let [v, ] = syscall.Getenv(key)
|
|
141
|
+
return v
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// LookupEnv retrieves the value of the environment variable named
|
|
145
|
+
// by the key. If the variable is present in the environment the
|
|
146
|
+
// value (which may be empty) is returned and the boolean is true.
|
|
147
|
+
// Otherwise the returned value will be empty and the boolean will
|
|
148
|
+
// be false.
|
|
149
|
+
export function LookupEnv(key: string): [string, boolean] {
|
|
150
|
+
// testlog.Getenv(key) // Testlog not available in JavaScript
|
|
151
|
+
return syscall.Getenv(key)
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// Setenv sets the value of the environment variable named by the key.
|
|
155
|
+
// It returns an error, if any.
|
|
156
|
+
export function Setenv(key: string, value: string): $.GoError {
|
|
157
|
+
let err = syscall.Setenv(key, value)
|
|
158
|
+
if (err != null) {
|
|
159
|
+
return NewSyscallError("setenv", err)
|
|
160
|
+
}
|
|
161
|
+
return null
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// Unsetenv unsets a single environment variable.
|
|
165
|
+
export function Unsetenv(key: string): $.GoError {
|
|
166
|
+
return syscall.Unsetenv(key)
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Clearenv deletes all environment variables.
|
|
170
|
+
export function Clearenv(): void {
|
|
171
|
+
syscall.Clearenv()
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Environ returns a copy of strings representing the environment,
|
|
175
|
+
// in the form "key=value".
|
|
176
|
+
export function Environ(): $.Slice<string> {
|
|
177
|
+
return syscall.Environ()
|
|
178
|
+
}
|
|
179
|
+
|