goscript 0.0.39 → 0.0.41
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 +15 -6
- package/compiler/compiler.go +185 -35
- package/compiler/expr-call.go +7 -9
- package/compiler/expr-type.go +25 -0
- package/compiler/field.go +21 -7
- package/compiler/gs_dependencies_test.go +80 -0
- package/compiler/lit.go +1 -6
- package/compiler/output.go +10 -4
- package/compiler/spec.go +16 -3
- package/compiler/type-assert.go +111 -21
- package/compiler/type.go +56 -12
- package/dist/gs/builtin/builtin.d.ts +20 -8
- package/dist/gs/builtin/builtin.js +30 -53
- package/dist/gs/builtin/builtin.js.map +1 -1
- package/dist/gs/builtin/errors.d.ts +8 -0
- package/dist/gs/builtin/errors.js +18 -0
- package/dist/gs/builtin/errors.js.map +1 -0
- package/dist/gs/builtin/index.d.ts +7 -0
- package/dist/gs/builtin/index.js +7 -0
- package/dist/gs/builtin/index.js.map +1 -1
- package/dist/gs/builtin/slice.d.ts +5 -2
- package/dist/gs/builtin/slice.js +123 -77
- package/dist/gs/builtin/slice.js.map +1 -1
- package/dist/gs/bytes/buffer.gs.d.ts +1 -1
- package/dist/gs/bytes/buffer.gs.js +1 -1
- package/dist/gs/bytes/buffer.gs.js.map +1 -1
- package/dist/gs/bytes/bytes.gs.d.ts +1 -1
- package/dist/gs/bytes/bytes.gs.js +111 -15
- package/dist/gs/bytes/bytes.gs.js.map +1 -1
- package/dist/gs/bytes/iter.gs.d.ts +1 -1
- package/dist/gs/bytes/iter.gs.js +1 -1
- package/dist/gs/bytes/iter.gs.js.map +1 -1
- package/dist/gs/bytes/reader.gs.d.ts +1 -1
- package/dist/gs/bytes/reader.gs.js +1 -1
- package/dist/gs/bytes/reader.gs.js.map +1 -1
- package/dist/gs/context/context.d.ts +1 -1
- package/dist/gs/context/context.js +1 -1
- package/dist/gs/context/context.js.map +1 -1
- package/dist/gs/errors/errors.d.ts +1 -1
- package/dist/gs/errors/errors.js +3 -15
- package/dist/gs/errors/errors.js.map +1 -1
- package/dist/gs/fmt/fmt.d.ts +49 -0
- package/dist/gs/fmt/fmt.js +322 -0
- package/dist/gs/fmt/fmt.js.map +1 -0
- package/dist/gs/fmt/index.d.ts +1 -0
- package/dist/gs/fmt/index.js +2 -0
- package/dist/gs/fmt/index.js.map +1 -0
- package/dist/gs/github.com/pkg/errors/errors.d.ts +1 -1
- package/dist/gs/github.com/pkg/errors/errors.js +1 -1
- 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/stack.d.ts +1 -1
- package/dist/gs/github.com/pkg/errors/stack.js +1 -1
- package/dist/gs/github.com/pkg/errors/stack.js.map +1 -1
- package/dist/gs/internal/byteorder/index.d.ts +1 -1
- package/dist/gs/internal/byteorder/index.js +1 -1
- package/dist/gs/internal/byteorder/index.js.map +1 -1
- package/dist/gs/internal/oserror/errors.d.ts +1 -1
- package/dist/gs/io/fs/format.js +1 -1
- package/dist/gs/io/fs/format.js.map +1 -1
- package/dist/gs/io/fs/fs.d.ts +1 -1
- package/dist/gs/io/fs/fs.js +1 -1
- package/dist/gs/io/fs/fs.js.map +1 -1
- package/dist/gs/io/fs/glob.d.ts +1 -1
- package/dist/gs/io/fs/glob.js +1 -1
- package/dist/gs/io/fs/glob.js.map +1 -1
- package/dist/gs/io/fs/readdir.d.ts +1 -1
- package/dist/gs/io/fs/readdir.js +1 -1
- package/dist/gs/io/fs/readdir.js.map +1 -1
- package/dist/gs/io/fs/readfile.d.ts +1 -1
- package/dist/gs/io/fs/readfile.js +1 -1
- package/dist/gs/io/fs/readfile.js.map +1 -1
- package/dist/gs/io/fs/stat.d.ts +1 -1
- package/dist/gs/io/fs/stat.js +1 -1
- package/dist/gs/io/fs/stat.js.map +1 -1
- package/dist/gs/io/fs/sub.d.ts +1 -1
- package/dist/gs/io/fs/sub.js +1 -1
- package/dist/gs/io/fs/sub.js.map +1 -1
- package/dist/gs/io/fs/walk.d.ts +1 -1
- package/dist/gs/io/fs/walk.js +1 -1
- package/dist/gs/io/fs/walk.js.map +1 -1
- package/dist/gs/io/io.d.ts +1 -1
- package/dist/gs/maps/iter.d.ts +1 -1
- package/dist/gs/maps/iter.js +1 -1
- package/dist/gs/maps/iter.js.map +1 -1
- package/dist/gs/maps/maps.d.ts +1 -1
- package/dist/gs/maps/maps.js +1 -1
- package/dist/gs/maps/maps.js.map +1 -1
- package/dist/gs/math/erfinv.gs.js +1 -1
- package/dist/gs/math/erfinv.gs.js.map +1 -1
- package/dist/gs/math/gamma.gs.js +1 -1
- package/dist/gs/math/gamma.gs.js.map +1 -1
- package/dist/gs/math/j0.gs.js +1 -1
- package/dist/gs/math/j0.gs.js.map +1 -1
- package/dist/gs/math/j1.gs.js +1 -1
- package/dist/gs/math/j1.gs.js.map +1 -1
- package/dist/gs/math/lgamma.gs.js +1 -1
- package/dist/gs/math/lgamma.gs.js.map +1 -1
- package/dist/gs/math/pow10.gs.js +1 -1
- package/dist/gs/math/pow10.gs.js.map +1 -1
- package/dist/gs/math/sin.gs.js +1 -1
- package/dist/gs/math/sin.gs.js.map +1 -1
- package/dist/gs/math/tan.gs.js +1 -1
- package/dist/gs/math/tan.gs.js.map +1 -1
- package/dist/gs/math/tanh.gs.js +1 -1
- package/dist/gs/math/tanh.gs.js.map +1 -1
- package/dist/gs/math/trig_reduce.gs.js +1 -1
- package/dist/gs/math/trig_reduce.gs.js.map +1 -1
- package/dist/gs/os/dir.gs.d.ts +1 -1
- package/dist/gs/os/dir_unix.gs.d.ts +1 -1
- package/dist/gs/os/dir_unix.gs.js +1 -1
- package/dist/gs/os/dir_unix.gs.js.map +1 -1
- package/dist/gs/os/dirent_js.gs.d.ts +1 -1
- package/dist/gs/os/env.gs.d.ts +1 -1
- package/dist/gs/os/env.gs.js +1 -1
- package/dist/gs/os/env.gs.js.map +1 -1
- package/dist/gs/os/error.gs.d.ts +1 -1
- package/dist/gs/os/error.gs.js +1 -1
- package/dist/gs/os/error.gs.js.map +1 -1
- package/dist/gs/os/exec.gs.d.ts +1 -1
- package/dist/gs/os/exec.gs.js +1 -1
- package/dist/gs/os/exec.gs.js.map +1 -1
- package/dist/gs/os/exec_posix.gs.d.ts +1 -1
- package/dist/gs/os/exec_posix.gs.js +1 -1
- package/dist/gs/os/exec_posix.gs.js.map +1 -1
- package/dist/gs/os/exec_unix.gs.d.ts +1 -1
- package/dist/gs/os/executable.gs.d.ts +1 -1
- package/dist/gs/os/executable_js.gs.d.ts +1 -1
- package/dist/gs/os/executable_wasm.gs.d.ts +1 -1
- package/dist/gs/os/file_constants_js.gs.d.ts +1 -1
- package/dist/gs/os/file_constants_js.gs.js +1 -1
- package/dist/gs/os/file_constants_js.gs.js.map +1 -1
- package/dist/gs/os/file_js.gs.d.ts +1 -1
- package/dist/gs/os/file_open_unix.gs.d.ts +1 -1
- package/dist/gs/os/file_posix_js.gs.d.ts +1 -1
- package/dist/gs/os/file_unix_js.gs.d.ts +1 -1
- package/dist/gs/os/getwd_js.gs.d.ts +1 -1
- package/dist/gs/os/path.gs.d.ts +1 -1
- package/dist/gs/os/path.gs.js +1 -1
- package/dist/gs/os/path.gs.js.map +1 -1
- package/dist/gs/os/path_unix.gs.js +1 -1
- package/dist/gs/os/path_unix.gs.js.map +1 -1
- package/dist/gs/os/pidfd_js.gs.d.ts +1 -1
- package/dist/gs/os/pipe_wasm.gs.d.ts +1 -1
- package/dist/gs/os/proc.gs.d.ts +1 -1
- package/dist/gs/os/proc.gs.js +1 -1
- package/dist/gs/os/proc.gs.js.map +1 -1
- package/dist/gs/os/proc_js.gs.d.ts +1 -1
- package/dist/gs/os/proc_js.gs.js +1 -1
- package/dist/gs/os/proc_js.gs.js.map +1 -1
- package/dist/gs/os/rawconn_js.gs.d.ts +1 -1
- package/dist/gs/os/removeall_js.gs.d.ts +1 -1
- package/dist/gs/os/root_js.gs.d.ts +1 -1
- package/dist/gs/os/root_js.gs.js +1 -1
- package/dist/gs/os/root_js.gs.js.map +1 -1
- package/dist/gs/os/root_nonwindows.gs.d.ts +1 -1
- package/dist/gs/os/root_noopenat.gs.d.ts +1 -1
- package/dist/gs/os/stat.gs.d.ts +1 -1
- package/dist/gs/os/stat_js.gs.d.ts +1 -1
- package/dist/gs/os/stat_unix_js.gs.d.ts +1 -1
- package/dist/gs/os/sys.gs.d.ts +1 -1
- package/dist/gs/os/sys_bsd.gs.d.ts +1 -1
- package/dist/gs/os/sys_js.gs.d.ts +1 -1
- package/dist/gs/os/tempfile.gs.d.ts +1 -1
- package/dist/gs/os/types.gs.d.ts +1 -1
- package/dist/gs/os/types.gs.js +1 -1
- package/dist/gs/os/types.gs.js.map +1 -1
- package/dist/gs/os/types_js.gs.d.ts +1 -1
- package/dist/gs/os/types_js.gs.js +1 -1
- package/dist/gs/os/types_js.gs.js.map +1 -1
- package/dist/gs/os/types_unix.gs.d.ts +1 -1
- package/dist/gs/os/types_unix.gs.js +1 -1
- package/dist/gs/os/types_unix.gs.js.map +1 -1
- package/dist/gs/os/zero_copy_posix.gs.d.ts +1 -1
- package/dist/gs/os/zero_copy_posix.gs.js +1 -1
- package/dist/gs/os/zero_copy_posix.gs.js.map +1 -1
- package/dist/gs/path/filepath/index.d.ts +3 -0
- package/dist/gs/path/filepath/index.js +3 -0
- package/dist/gs/path/filepath/index.js.map +1 -0
- package/dist/gs/path/filepath/match.d.ts +3 -0
- package/dist/gs/path/filepath/match.js +212 -0
- package/dist/gs/path/filepath/match.js.map +1 -0
- package/dist/gs/path/filepath/path.d.ts +26 -0
- package/dist/gs/path/filepath/path.js +266 -0
- package/dist/gs/path/filepath/path.js.map +1 -0
- package/dist/gs/path/match.d.ts +1 -1
- package/dist/gs/path/match.js +1 -1
- package/dist/gs/path/match.js.map +1 -1
- package/dist/gs/path/path.js +1 -1
- package/dist/gs/path/path.js.map +1 -1
- package/dist/gs/reflect/value.d.ts +1 -1
- package/dist/gs/reflect/value.js +14 -6
- package/dist/gs/reflect/value.js.map +1 -1
- package/dist/gs/reflect/visiblefields.d.ts +1 -1
- package/dist/gs/reflect/visiblefields.js +1 -1
- package/dist/gs/reflect/visiblefields.js.map +1 -1
- package/dist/gs/slices/slices.d.ts +1 -1
- package/dist/gs/slices/slices.js +1 -1
- package/dist/gs/slices/slices.js.map +1 -1
- package/dist/gs/sort/index.d.ts +4 -0
- package/dist/gs/sort/index.js +4 -0
- package/dist/gs/sort/index.js.map +1 -0
- package/dist/gs/sort/search.gs.d.ts +6 -0
- package/dist/gs/sort/search.gs.js +125 -0
- package/dist/gs/sort/search.gs.js.map +1 -0
- package/dist/gs/sort/slice.gs.d.ts +4 -0
- package/dist/gs/sort/slice.gs.js +49 -0
- package/dist/gs/sort/slice.gs.js.map +1 -0
- package/dist/gs/sort/sort.gs.d.ts +37 -0
- package/dist/gs/sort/sort.gs.js +203 -0
- package/dist/gs/sort/sort.gs.js.map +1 -0
- package/dist/gs/strconv/atob.gs.d.ts +1 -1
- package/dist/gs/strconv/atob.gs.js +1 -1
- package/dist/gs/strconv/atob.gs.js.map +1 -1
- package/dist/gs/strconv/atof.gs.d.ts +1 -1
- package/dist/gs/strconv/atoi.gs.d.ts +1 -1
- package/dist/gs/strconv/atoi.gs.js +5 -6
- package/dist/gs/strconv/atoi.gs.js.map +1 -1
- package/dist/gs/strconv/ftoa.gs.d.ts +1 -1
- package/dist/gs/strconv/ftoa.gs.js +1 -1
- package/dist/gs/strconv/ftoa.gs.js.map +1 -1
- package/dist/gs/strconv/itoa.gs.d.ts +1 -1
- package/dist/gs/strconv/itoa.gs.js +1 -1
- package/dist/gs/strconv/itoa.gs.js.map +1 -1
- package/dist/gs/strconv/quote.gs.d.ts +1 -1
- package/dist/gs/strconv/quote.gs.js +1 -1
- package/dist/gs/strconv/quote.gs.js.map +1 -1
- package/dist/gs/strings/builder.d.ts +1 -1
- package/dist/gs/strings/builder.js +1 -1
- package/dist/gs/strings/builder.js.map +1 -1
- package/dist/gs/strings/iter.js +1 -1
- package/dist/gs/strings/iter.js.map +1 -1
- package/dist/gs/strings/reader.d.ts +1 -1
- package/dist/gs/strings/reader.js +7 -8
- package/dist/gs/strings/reader.js.map +1 -1
- package/dist/gs/strings/replace.d.ts +1 -1
- package/dist/gs/strings/replace.js +1 -1
- package/dist/gs/strings/replace.js.map +1 -1
- package/dist/gs/strings/strings.d.ts +1 -1
- package/dist/gs/strings/strings.js +1 -1
- package/dist/gs/strings/strings.js.map +1 -1
- package/dist/gs/sync/atomic/doc.gs.d.ts +1 -1
- package/dist/gs/sync/atomic/doc_64.gs.d.ts +1 -1
- package/dist/gs/sync/atomic/type.gs.d.ts +1 -1
- package/dist/gs/sync/atomic/type.gs.js +1 -1
- package/dist/gs/sync/atomic/type.gs.js.map +1 -1
- package/dist/gs/sync/atomic/value.gs.d.ts +1 -1
- package/dist/gs/sync/atomic/value.gs.js +1 -1
- package/dist/gs/sync/atomic/value.gs.js.map +1 -1
- package/dist/gs/syscall/index.d.ts +1 -1
- package/dist/gs/syscall/index.js +1 -1
- package/dist/gs/syscall/index.js.map +1 -1
- package/dist/gs/unicode/utf8/utf8.d.ts +1 -1
- package/dist/gs/unicode/utf8/utf8.js +1 -1
- package/dist/gs/unicode/utf8/utf8.js.map +1 -1
- package/gs/builtin/builtin.ts +33 -64
- package/gs/builtin/errors.ts +25 -0
- package/gs/builtin/index.ts +7 -0
- package/gs/builtin/slice.ts +142 -71
- package/gs/bytes/buffer.gs.ts +1 -1
- package/gs/bytes/bytes.gs.ts +123 -15
- package/gs/bytes/iter.gs.ts +1 -1
- package/gs/bytes/metadata.go +12 -0
- package/gs/bytes/reader.gs.ts +1 -1
- package/gs/context/context.ts +1 -1
- package/gs/errors/errors.ts +3 -16
- package/gs/fmt/fmt.ts +407 -0
- package/gs/fmt/godoc.txt +382 -0
- package/gs/fmt/index.ts +31 -0
- package/gs/fmt/metadata.go +7 -0
- package/gs/github.com/pkg/errors/errors.ts +1 -1
- package/gs/github.com/pkg/errors/go113.ts +2 -2
- package/gs/github.com/pkg/errors/stack.ts +1 -1
- package/gs/internal/byteorder/index.ts +1 -1
- package/gs/internal/metadata.go +7 -0
- package/gs/internal/oserror/errors.ts +1 -1
- package/gs/io/fs/format.ts +1 -1
- package/gs/io/fs/fs.ts +1 -1
- package/gs/io/fs/glob.ts +1 -1
- package/gs/io/fs/readdir.ts +1 -1
- package/gs/io/fs/readfile.ts +1 -1
- package/gs/io/fs/stat.ts +1 -1
- package/gs/io/fs/sub.ts +1 -1
- package/gs/io/fs/walk.ts +1 -1
- package/gs/io/io.ts +1 -1
- package/gs/io/metadata.go +11 -0
- package/gs/maps/iter.ts +1 -1
- package/gs/maps/maps.ts +1 -1
- package/gs/maps/metadata.go +8 -0
- package/gs/math/abs.gs.ts +1 -1
- package/gs/math/acosh.gs.ts +1 -1
- package/gs/math/asinh.gs.ts +1 -1
- package/gs/math/atan.gs.ts +1 -1
- package/gs/math/atan2.gs.ts +1 -1
- package/gs/math/atanh.gs.ts +1 -1
- package/gs/math/bits.gs.ts +1 -1
- package/gs/math/cbrt.gs.ts +1 -1
- package/gs/math/const.gs.ts +1 -1
- package/gs/math/copysign.gs.ts +1 -1
- package/gs/math/dim.gs.ts +1 -1
- package/gs/math/erf.gs.ts +1 -1
- package/gs/math/erfinv.gs.ts +1 -1
- package/gs/math/exp.gs.ts +1 -1
- package/gs/math/expm1.gs.ts +1 -1
- package/gs/math/floor.gs.ts +1 -1
- package/gs/math/frexp.gs.ts +1 -1
- package/gs/math/gamma.gs.ts +1 -1
- package/gs/math/hypot.gs.ts +1 -1
- package/gs/math/j0.gs.ts +1 -1
- package/gs/math/j1.gs.ts +1 -1
- package/gs/math/jn.gs.ts +1 -1
- package/gs/math/ldexp.gs.ts +1 -1
- package/gs/math/lgamma.gs.ts +1 -1
- package/gs/math/log.gs.ts +1 -1
- package/gs/math/log10.gs.ts +1 -1
- package/gs/math/log1p.gs.ts +1 -1
- package/gs/math/logb.gs.ts +1 -1
- package/gs/math/metadata.go +7 -0
- package/gs/math/mod.gs.ts +1 -1
- package/gs/math/modf.gs.ts +1 -1
- package/gs/math/nextafter.gs.ts +1 -1
- package/gs/math/pow.gs.ts +1 -1
- package/gs/math/pow10.gs.ts +1 -1
- package/gs/math/remainder.gs.ts +1 -1
- package/gs/math/signbit.gs.ts +1 -1
- package/gs/math/sin.gs.ts +1 -1
- package/gs/math/sincos.gs.ts +1 -1
- package/gs/math/sinh.gs.ts +1 -1
- package/gs/math/sqrt.gs.ts +1 -1
- package/gs/math/tan.gs.ts +1 -1
- package/gs/math/tanh.gs.ts +1 -1
- package/gs/math/trig_reduce.gs.ts +1 -1
- package/gs/math/unsafe.gs.ts +1 -1
- package/gs/os/dir.gs.ts +1 -1
- package/gs/os/dir_unix.gs.ts +1 -1
- package/gs/os/dirent_js.gs.ts +1 -1
- package/gs/os/env.gs.ts +1 -1
- package/gs/os/error.gs.ts +1 -1
- package/gs/os/error_errno.gs.ts +1 -1
- package/gs/os/exec.gs.ts +1 -1
- package/gs/os/exec_nohandle.gs.ts +1 -1
- package/gs/os/exec_posix.gs.ts +1 -1
- package/gs/os/exec_unix.gs.ts +1 -1
- package/gs/os/executable.gs.ts +1 -1
- package/gs/os/executable_js.gs.ts +1 -1
- package/gs/os/executable_wasm.gs.ts +1 -1
- package/gs/os/file_constants_js.gs.ts +1 -1
- package/gs/os/file_js.gs.ts +1 -1
- package/gs/os/file_open_unix.gs.ts +1 -1
- package/gs/os/file_posix_js.gs.ts +1 -1
- package/gs/os/file_unix_js.gs.ts +1 -1
- package/gs/os/getwd_js.gs.ts +1 -1
- package/gs/os/metadata.go +17 -0
- package/gs/os/path.gs.ts +1 -1
- package/gs/os/path_unix.gs.ts +1 -1
- package/gs/os/pidfd_js.gs.ts +1 -1
- package/gs/os/pipe_wasm.gs.ts +1 -1
- package/gs/os/proc.gs.ts +1 -1
- package/gs/os/proc_js.gs.ts +1 -1
- package/gs/os/rawconn_js.gs.ts +1 -1
- package/gs/os/removeall_js.gs.ts +1 -1
- package/gs/os/root_js.gs.ts +1 -1
- package/gs/os/root_nonwindows.gs.ts +1 -1
- package/gs/os/root_noopenat.gs.ts +1 -1
- package/gs/os/stat.gs.ts +1 -1
- package/gs/os/stat_js.gs.ts +1 -1
- package/gs/os/stat_unix_js.gs.ts +1 -1
- package/gs/os/sticky_bsd.gs.ts +1 -1
- package/gs/os/sys.gs.ts +1 -1
- package/gs/os/sys_bsd.gs.ts +1 -1
- package/gs/os/sys_js.gs.ts +1 -1
- package/gs/os/tempfile.gs.ts +1 -1
- package/gs/os/types.gs.ts +1 -1
- package/gs/os/types_js.gs.ts +1 -1
- package/gs/os/types_unix.gs.ts +1 -1
- package/gs/os/wait_unimp.gs.ts +1 -1
- package/gs/os/zero_copy_posix.gs.ts +1 -1
- package/gs/os/zero_copy_stub.gs.ts +1 -1
- package/gs/path/filepath/godoc.txt +35 -0
- package/gs/path/filepath/index.ts +27 -0
- package/gs/path/filepath/match.test.ts +274 -0
- package/gs/path/filepath/match.ts +249 -0
- package/gs/path/filepath/path.test.ts +246 -0
- package/gs/path/filepath/path.ts +329 -0
- package/gs/path/match.ts +1 -1
- package/gs/path/metadata.go +8 -0
- package/gs/path/path.ts +1 -1
- package/gs/reflect/metadata.go +7 -0
- package/gs/reflect/value.ts +14 -6
- package/gs/reflect/visiblefields.ts +1 -1
- package/gs/slices/slices.ts +1 -1
- package/gs/sort/godoc.txt +27 -0
- package/gs/sort/index.ts +24 -0
- package/gs/sort/search.gs.ts +128 -0
- package/gs/sort/slice.gs.ts +59 -0
- package/gs/sort/sort.gs.ts +227 -0
- package/gs/strconv/atob.gs.ts +1 -1
- package/gs/strconv/atof.gs.ts +1 -1
- package/gs/strconv/atoi.gs.ts +5 -6
- package/gs/strconv/doc.gs.ts +1 -1
- package/gs/strconv/ftoa.gs.ts +1 -1
- package/gs/strconv/itoa.gs.ts +1 -1
- package/gs/strconv/metadata.go +7 -0
- package/gs/strconv/quote.gs.ts +1 -1
- package/gs/strings/builder.ts +1 -1
- package/gs/strings/iter.ts +1 -1
- package/gs/strings/metadata.go +11 -0
- package/gs/strings/reader.ts +7 -9
- package/gs/strings/replace.ts +1 -1
- package/gs/strings/strings.ts +1 -1
- package/gs/sync/atomic/doc.gs.ts +1 -1
- package/gs/sync/atomic/doc_64.gs.ts +1 -1
- package/gs/sync/atomic/type.gs.ts +1 -1
- package/gs/sync/atomic/value.gs.ts +1 -1
- package/gs/sync/metadata.go +7 -0
- package/gs/syscall/index.ts +1 -1
- package/gs/unicode/utf8/utf8.ts +1 -1
- package/package.json +3 -3
- package/gs/builtin/io.ts +0 -22
package/gs/sort/index.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export {
|
|
2
|
+
Find,
|
|
3
|
+
Search,
|
|
4
|
+
SearchFloat64s,
|
|
5
|
+
SearchInts,
|
|
6
|
+
SearchStrings,
|
|
7
|
+
} from './search.gs'
|
|
8
|
+
export { Slice, SliceIsSorted, SliceStable } from './slice.gs'
|
|
9
|
+
export {
|
|
10
|
+
Float64Slice,
|
|
11
|
+
Float64s,
|
|
12
|
+
Float64sAreSorted,
|
|
13
|
+
IntSlice,
|
|
14
|
+
Ints,
|
|
15
|
+
IntsAreSorted,
|
|
16
|
+
IsSorted,
|
|
17
|
+
Reverse,
|
|
18
|
+
Sort,
|
|
19
|
+
Stable,
|
|
20
|
+
StringSlice,
|
|
21
|
+
Strings,
|
|
22
|
+
StringsAreSorted,
|
|
23
|
+
} from './sort.gs'
|
|
24
|
+
export type { Interface } from './sort.gs'
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import * as $ from "@goscript/builtin/index.js";
|
|
2
|
+
|
|
3
|
+
// Search uses binary search to find and return the smallest index i
|
|
4
|
+
// in [0, n) at which f(i) is true, assuming that on the range [0, n),
|
|
5
|
+
// f(i) == true implies f(i+1) == true. That is, Search requires that
|
|
6
|
+
// f is false for some (possibly empty) prefix of the input range [0, n)
|
|
7
|
+
// and then true for the (possibly empty) remainder; Search returns
|
|
8
|
+
// the first true index. If there is no such index, Search returns n.
|
|
9
|
+
// (Note that the "not found" return value is not -1 as in, for instance,
|
|
10
|
+
// strings.Index.)
|
|
11
|
+
// Search calls f(i) only for i in the range [0, n).
|
|
12
|
+
//
|
|
13
|
+
// A common use of Search is to find the index i for a value x in
|
|
14
|
+
// a sorted, indexable data structure such as an array or slice.
|
|
15
|
+
// In this case, the argument f, typically a closure, captures the value
|
|
16
|
+
// to be searched for, and how the data structure is indexed and
|
|
17
|
+
// ordered.
|
|
18
|
+
//
|
|
19
|
+
// For instance, given a slice data sorted in ascending order,
|
|
20
|
+
// the call Search(len(data), func(i int) bool { return data[i] >= 23 })
|
|
21
|
+
// returns the smallest index i such that data[i] >= 23. If the caller
|
|
22
|
+
// wants to find whether 23 is in the slice, it must test data[i] == 23
|
|
23
|
+
// separately.
|
|
24
|
+
//
|
|
25
|
+
// Searching data sorted in descending order would use the <=
|
|
26
|
+
// operator instead of the >= operator.
|
|
27
|
+
//
|
|
28
|
+
// To complete the example above, the following code tries to find the value
|
|
29
|
+
// x in an integer slice data sorted in ascending order:
|
|
30
|
+
//
|
|
31
|
+
// x := 23
|
|
32
|
+
// i := sort.Search(len(data), func(i int) bool { return data[i] >= x })
|
|
33
|
+
// if i < len(data) && data[i] == x {
|
|
34
|
+
// // x is present at data[i]
|
|
35
|
+
// } else {
|
|
36
|
+
// // x is not present in data,
|
|
37
|
+
// // but i is the index where it would be inserted.
|
|
38
|
+
// }
|
|
39
|
+
//
|
|
40
|
+
// As a more whimsical example, this program guesses your number:
|
|
41
|
+
//
|
|
42
|
+
// func GuessingGame() {
|
|
43
|
+
// var s string
|
|
44
|
+
// fmt.Printf("Pick an integer from 0 to 100.\n")
|
|
45
|
+
// answer := sort.Search(100, func(i int) bool {
|
|
46
|
+
// fmt.Printf("Is your number <= %d? ", i)
|
|
47
|
+
// fmt.Scanf("%s", &s)
|
|
48
|
+
// return s != "" && s[0] == 'y'
|
|
49
|
+
// })
|
|
50
|
+
// fmt.Printf("Your number is %d.\n", answer)
|
|
51
|
+
// }
|
|
52
|
+
export function Search(n: number, f: (i: number) => boolean): number {
|
|
53
|
+
let left = 0
|
|
54
|
+
let right = n
|
|
55
|
+
while (left < right) {
|
|
56
|
+
const mid = Math.floor((left + right) / 2)
|
|
57
|
+
if (f(mid)) {
|
|
58
|
+
right = mid
|
|
59
|
+
} else {
|
|
60
|
+
left = mid + 1
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return left
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Find uses binary search to find and return the smallest index i in [0, n)
|
|
67
|
+
// at which cmp(i) <= 0. If there is no such index i, Find returns i = n.
|
|
68
|
+
// The found result is true if i < n and cmp(i) == 0.
|
|
69
|
+
// Find calls cmp(i) only for i in the range [0, n).
|
|
70
|
+
//
|
|
71
|
+
// To permit binary search, Find requires that cmp(i) > 0 for a leading
|
|
72
|
+
// prefix of the range, cmp(i) == 0 in the middle, and cmp(i) < 0 for
|
|
73
|
+
// the final suffix of the range. (Each subrange could be empty.)
|
|
74
|
+
// The usual way to establish this condition is to interpret cmp(i)
|
|
75
|
+
// as a comparison of a desired target value t against entry i in an
|
|
76
|
+
// underlying indexed data structure x, returning <0, 0, and >0
|
|
77
|
+
// when t < x[i], t == x[i], and t > x[i], respectively.
|
|
78
|
+
//
|
|
79
|
+
// For example, to look for a particular string in a sorted, random-access
|
|
80
|
+
// list of strings:
|
|
81
|
+
//
|
|
82
|
+
// i, found := sort.Find(x.Len(), func(i int) int {
|
|
83
|
+
// return strings.Compare(target, x.At(i))
|
|
84
|
+
// })
|
|
85
|
+
// if found {
|
|
86
|
+
// fmt.Printf("found %s at entry %d\n", target, i)
|
|
87
|
+
// } else {
|
|
88
|
+
// fmt.Printf("%s not found, would insert at %d", target, i)
|
|
89
|
+
// }
|
|
90
|
+
export function Find(n: number, cmp: (i: number) => number): [number, boolean] {
|
|
91
|
+
let left = 0
|
|
92
|
+
let right = n
|
|
93
|
+
while (left < right) {
|
|
94
|
+
const mid = Math.floor((left + right) / 2)
|
|
95
|
+
if (cmp(mid) <= 0) {
|
|
96
|
+
right = mid
|
|
97
|
+
} else {
|
|
98
|
+
left = mid + 1
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
const found = left < n && cmp(left) === 0
|
|
102
|
+
return [left, found]
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// SearchInts searches for x in a sorted slice of ints and returns the index
|
|
106
|
+
// as specified by Search. The return value is the index to insert x if x is
|
|
107
|
+
// not present (it could be len(a)).
|
|
108
|
+
// The slice must be sorted in ascending order.
|
|
109
|
+
export function SearchInts(a: $.Slice<number>, x: number): number {
|
|
110
|
+
return Search($.len(a), (i: number) => ($.index(a, i) as number) >= x)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// SearchFloat64s searches for x in a sorted slice of float64s and returns the index
|
|
114
|
+
// as specified by Search. The return value is the index to insert x if x is not
|
|
115
|
+
// present (it could be len(a)).
|
|
116
|
+
// The slice must be sorted in ascending order.
|
|
117
|
+
export function SearchFloat64s(a: $.Slice<number>, x: number): number {
|
|
118
|
+
return Search($.len(a), (i: number) => ($.index(a, i) as number) >= x)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// SearchStrings searches for x in a sorted slice of strings and returns the index
|
|
122
|
+
// as specified by Search. The return value is the index to insert x if x is not
|
|
123
|
+
// present (it could be len(a)).
|
|
124
|
+
// The slice must be sorted in ascending order.
|
|
125
|
+
export function SearchStrings(a: $.Slice<string>, x: string): number {
|
|
126
|
+
return Search($.len(a), (i: number) => ($.index(a, i) as string) >= x)
|
|
127
|
+
}
|
|
128
|
+
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import * as $ from "@goscript/builtin/index.js";
|
|
2
|
+
|
|
3
|
+
// Helper type for slice metadata
|
|
4
|
+
interface SliceMetadata<T> {
|
|
5
|
+
backing: T[]
|
|
6
|
+
offset: number
|
|
7
|
+
length: number
|
|
8
|
+
capacity: number
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// Helper function to swap elements in a slice
|
|
12
|
+
function swapInSlice<T>(slice: $.Slice<T>, i: number, j: number): void {
|
|
13
|
+
if (!slice) return
|
|
14
|
+
|
|
15
|
+
const temp = $.index(slice, i)
|
|
16
|
+
if (Array.isArray(slice)) {
|
|
17
|
+
const val_j = $.index(slice, j)
|
|
18
|
+
const val_i = temp
|
|
19
|
+
slice[i] = val_j as T
|
|
20
|
+
slice[j] = val_i as T
|
|
21
|
+
} else if (typeof slice === 'object' && '__meta__' in slice) {
|
|
22
|
+
const meta = (slice as any).__meta__ as SliceMetadata<T>
|
|
23
|
+
const backing = meta.backing
|
|
24
|
+
backing[meta.offset + i] = $.index(slice, j) as T
|
|
25
|
+
backing[meta.offset + j] = temp as T
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Slice sorts the slice x given the provided less function
|
|
30
|
+
export function Slice(x: $.Slice<any>, less: (i: number, j: number) => boolean): void {
|
|
31
|
+
if (!x) return
|
|
32
|
+
|
|
33
|
+
// Simple insertion sort using the provided less function
|
|
34
|
+
const n = $.len(x)
|
|
35
|
+
for (let i = 1; i < n; i++) {
|
|
36
|
+
for (let j = i; j > 0 && less(j, j - 1); j--) {
|
|
37
|
+
swapInSlice(x, j, j - 1)
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// SliceIsSorted reports whether the slice x is sorted according to the provided less function
|
|
43
|
+
export function SliceIsSorted(x: $.Slice<any>, less: (i: number, j: number) => boolean): boolean {
|
|
44
|
+
if (!x) return true
|
|
45
|
+
|
|
46
|
+
const n = $.len(x)
|
|
47
|
+
for (let i = n - 1; i > 0; i--) {
|
|
48
|
+
if (less(i, i - 1)) {
|
|
49
|
+
return false
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return true
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// SliceStable sorts the slice x while keeping the original order of equal elements
|
|
56
|
+
export function SliceStable(x: $.Slice<any>, less: (i: number, j: number) => boolean): void {
|
|
57
|
+
// For simplicity, use the same sort - can be improved later
|
|
58
|
+
Slice(x, less)
|
|
59
|
+
}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import * as $ from '@goscript/builtin/index.js'
|
|
2
|
+
|
|
3
|
+
// Interface defines the methods required for sorting
|
|
4
|
+
export interface Interface {
|
|
5
|
+
Len(): number
|
|
6
|
+
Less(i: number, j: number): boolean
|
|
7
|
+
Swap(i: number, j: number): void
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// Helper type for slice metadata
|
|
11
|
+
interface SliceMetadata<T> {
|
|
12
|
+
backing: T[]
|
|
13
|
+
offset: number
|
|
14
|
+
length: number
|
|
15
|
+
capacity: number
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// IntSlice type for sorting integers
|
|
19
|
+
export class IntSlice {
|
|
20
|
+
constructor(private _value: $.Slice<number>) {}
|
|
21
|
+
|
|
22
|
+
Len(): number {
|
|
23
|
+
return $.len(this._value)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
Less(i: number, j: number): boolean {
|
|
27
|
+
return ($.index(this._value, i) as number) < ($.index(this._value, j) as number)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
Swap(i: number, j: number): void {
|
|
31
|
+
const temp = $.index(this._value, i) as number
|
|
32
|
+
if (Array.isArray(this._value)) {
|
|
33
|
+
this._value[i] = $.index(this._value, j) as number
|
|
34
|
+
this._value[j] = temp
|
|
35
|
+
} else if (this._value && typeof this._value === 'object' && '__meta__' in this._value) {
|
|
36
|
+
const meta = (this._value as any).__meta__ as SliceMetadata<number>
|
|
37
|
+
const backing = meta.backing
|
|
38
|
+
backing[meta.offset + i] = $.index(this._value, j) as number
|
|
39
|
+
backing[meta.offset + j] = temp
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Float64Slice type for sorting float64s
|
|
45
|
+
export class Float64Slice {
|
|
46
|
+
constructor(private _value: $.Slice<number>) {}
|
|
47
|
+
|
|
48
|
+
Len(): number {
|
|
49
|
+
return $.len(this._value)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
Less(i: number, j: number): boolean {
|
|
53
|
+
return ($.index(this._value, i) as number) < ($.index(this._value, j) as number)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
Swap(i: number, j: number): void {
|
|
57
|
+
const temp = $.index(this._value, i) as number
|
|
58
|
+
if (Array.isArray(this._value)) {
|
|
59
|
+
this._value[i] = $.index(this._value, j) as number
|
|
60
|
+
this._value[j] = temp
|
|
61
|
+
} else if (this._value && typeof this._value === 'object' && '__meta__' in this._value) {
|
|
62
|
+
const meta = (this._value as any).__meta__ as SliceMetadata<number>
|
|
63
|
+
const backing = meta.backing
|
|
64
|
+
backing[meta.offset + i] = $.index(this._value, j) as number
|
|
65
|
+
backing[meta.offset + j] = temp
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// StringSlice type for sorting strings
|
|
71
|
+
export class StringSlice {
|
|
72
|
+
constructor(private _value: $.Slice<string>) {}
|
|
73
|
+
|
|
74
|
+
Len(): number {
|
|
75
|
+
return $.len(this._value)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
Less(i: number, j: number): boolean {
|
|
79
|
+
return ($.index(this._value, i) as string) < ($.index(this._value, j) as string)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
Swap(i: number, j: number): void {
|
|
83
|
+
const temp = $.index(this._value, i) as string
|
|
84
|
+
if (Array.isArray(this._value)) {
|
|
85
|
+
this._value[i] = $.index(this._value, j) as string
|
|
86
|
+
this._value[j] = temp
|
|
87
|
+
} else if (this._value && typeof this._value === 'object' && '__meta__' in this._value) {
|
|
88
|
+
const meta = (this._value as any).__meta__ as SliceMetadata<string>
|
|
89
|
+
const backing = meta.backing
|
|
90
|
+
backing[meta.offset + i] = $.index(this._value, j) as string
|
|
91
|
+
backing[meta.offset + j] = temp
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Sort sorts data in ascending order as determined by the Less method
|
|
97
|
+
export function Sort(data: Interface): void {
|
|
98
|
+
// Use a simple insertion sort for now - can be optimized later
|
|
99
|
+
const n = data.Len()
|
|
100
|
+
for (let i = 1; i < n; i++) {
|
|
101
|
+
for (let j = i; j > 0 && data.Less(j, j - 1); j--) {
|
|
102
|
+
data.Swap(j, j - 1)
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Stable sorts data while keeping the original order of equal elements
|
|
108
|
+
export function Stable(data: Interface): void {
|
|
109
|
+
// For simplicity, use the same sort - can be improved later
|
|
110
|
+
Sort(data)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// IsSorted reports whether data is sorted
|
|
114
|
+
export function IsSorted(data: Interface): boolean {
|
|
115
|
+
const n = data.Len()
|
|
116
|
+
for (let i = n - 1; i > 0; i--) {
|
|
117
|
+
if (data.Less(i, i - 1)) {
|
|
118
|
+
return false
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return true
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Reverse returns the reverse order for data
|
|
125
|
+
export function Reverse(data: Interface): Interface {
|
|
126
|
+
return {
|
|
127
|
+
Len: () => data.Len(),
|
|
128
|
+
Less: (i: number, j: number) => data.Less(j, i),
|
|
129
|
+
Swap: (i: number, j: number) => data.Swap(i, j)
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Helper function to swap elements in a slice
|
|
134
|
+
function swapInSlice<T>(slice: $.Slice<T>, i: number, j: number): void {
|
|
135
|
+
if (!slice) return
|
|
136
|
+
|
|
137
|
+
const temp = $.index(slice, i)
|
|
138
|
+
if (Array.isArray(slice)) {
|
|
139
|
+
const val_j = $.index(slice, j)
|
|
140
|
+
const val_i = temp
|
|
141
|
+
slice[i] = val_j as T
|
|
142
|
+
slice[j] = val_i as T
|
|
143
|
+
} else if (typeof slice === 'object' && '__meta__' in slice) {
|
|
144
|
+
const meta = (slice as any).__meta__ as SliceMetadata<T>
|
|
145
|
+
const backing = meta.backing
|
|
146
|
+
backing[meta.offset + i] = $.index(slice, j) as T
|
|
147
|
+
backing[meta.offset + j] = temp as T
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Ints sorts a slice of ints in increasing order
|
|
152
|
+
export function Ints(x: $.Slice<number>): void {
|
|
153
|
+
if (!x) return
|
|
154
|
+
|
|
155
|
+
const n = $.len(x)
|
|
156
|
+
// Simple insertion sort
|
|
157
|
+
for (let i = 1; i < n; i++) {
|
|
158
|
+
for (let j = i; j > 0 && ($.index(x, j) as number) < ($.index(x, j - 1) as number); j--) {
|
|
159
|
+
swapInSlice(x, j, j - 1)
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// IntsAreSorted reports whether the slice x is sorted in increasing order
|
|
165
|
+
export function IntsAreSorted(x: $.Slice<number>): boolean {
|
|
166
|
+
if (!x) return true
|
|
167
|
+
|
|
168
|
+
const n = $.len(x)
|
|
169
|
+
for (let i = n - 1; i > 0; i--) {
|
|
170
|
+
if (($.index(x, i) as number) < ($.index(x, i - 1) as number)) {
|
|
171
|
+
return false
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return true
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// Float64s sorts a slice of float64s in increasing order
|
|
178
|
+
export function Float64s(x: $.Slice<number>): void {
|
|
179
|
+
if (!x) return
|
|
180
|
+
|
|
181
|
+
const n = $.len(x)
|
|
182
|
+
// Simple insertion sort
|
|
183
|
+
for (let i = 1; i < n; i++) {
|
|
184
|
+
for (let j = i; j > 0 && ($.index(x, j) as number) < ($.index(x, j - 1) as number); j--) {
|
|
185
|
+
swapInSlice(x, j, j - 1)
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// Float64sAreSorted reports whether the slice x is sorted in increasing order
|
|
191
|
+
export function Float64sAreSorted(x: $.Slice<number>): boolean {
|
|
192
|
+
if (!x) return true
|
|
193
|
+
|
|
194
|
+
const n = $.len(x)
|
|
195
|
+
for (let i = n - 1; i > 0; i--) {
|
|
196
|
+
if (($.index(x, i) as number) < ($.index(x, i - 1) as number)) {
|
|
197
|
+
return false
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return true
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// Strings sorts a slice of strings in increasing order
|
|
204
|
+
export function Strings(x: $.Slice<string>): void {
|
|
205
|
+
if (!x) return
|
|
206
|
+
|
|
207
|
+
const n = $.len(x)
|
|
208
|
+
// Simple insertion sort
|
|
209
|
+
for (let i = 1; i < n; i++) {
|
|
210
|
+
for (let j = i; j > 0 && ($.index(x, j) as string) < ($.index(x, j - 1) as string); j--) {
|
|
211
|
+
swapInSlice(x, j, j - 1)
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// StringsAreSorted reports whether the slice x is sorted in increasing order
|
|
217
|
+
export function StringsAreSorted(x: $.Slice<string>): boolean {
|
|
218
|
+
if (!x) return true
|
|
219
|
+
|
|
220
|
+
const n = $.len(x)
|
|
221
|
+
for (let i = n - 1; i > 0; i--) {
|
|
222
|
+
if (($.index(x, i) as string) < ($.index(x, i - 1) as string)) {
|
|
223
|
+
return false
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return true
|
|
227
|
+
}
|
package/gs/strconv/atob.gs.ts
CHANGED
package/gs/strconv/atof.gs.ts
CHANGED
package/gs/strconv/atoi.gs.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import * as $ from "@goscript/builtin/
|
|
2
|
-
import * as errors from "@goscript/errors/index.js";
|
|
1
|
+
import * as $ from "@goscript/builtin/index.js";
|
|
3
2
|
|
|
4
|
-
export let ErrRange: $.GoError =
|
|
5
|
-
export let ErrSyntax: $.GoError =
|
|
3
|
+
export let ErrRange: $.GoError = $.newError("value out of range");
|
|
4
|
+
export let ErrSyntax: $.GoError = $.newError("invalid syntax");
|
|
6
5
|
|
|
7
6
|
export class NumError {
|
|
8
7
|
// the failing function (ParseBool, ParseInt, ParseUint, ParseFloat, ParseComplex)
|
|
@@ -82,11 +81,11 @@ export function rangeError(fn: string, str: string): NumError {
|
|
|
82
81
|
}
|
|
83
82
|
|
|
84
83
|
export function baseError(fn: string, str: string, base: number): NumError {
|
|
85
|
-
return new NumError({Func: fn, Num: str, Err:
|
|
84
|
+
return new NumError({Func: fn, Num: str, Err: $.newError("invalid base " + base)});
|
|
86
85
|
}
|
|
87
86
|
|
|
88
87
|
export function bitSizeError(fn: string, str: string, bitSize: number): NumError {
|
|
89
|
-
return new NumError({Func: fn, Num: str, Err:
|
|
88
|
+
return new NumError({Func: fn, Num: str, Err: $.newError("invalid bit size " + bitSize)});
|
|
90
89
|
}
|
|
91
90
|
|
|
92
91
|
export let IntSize: number = 64;
|
package/gs/strconv/doc.gs.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import * as $ from "@goscript/builtin/
|
|
1
|
+
import * as $ from "@goscript/builtin/index.js";
|
|
2
2
|
|
package/gs/strconv/ftoa.gs.ts
CHANGED
package/gs/strconv/itoa.gs.ts
CHANGED
package/gs/strconv/quote.gs.ts
CHANGED
package/gs/strings/builder.ts
CHANGED
package/gs/strings/iter.ts
CHANGED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
package strings
|
|
2
|
+
|
|
3
|
+
// GsDependencies lists the import paths that this gs/ package requires
|
|
4
|
+
// These dependencies will be automatically copied when this package is included
|
|
5
|
+
var GsDependencies = []string{
|
|
6
|
+
"errors",
|
|
7
|
+
"io",
|
|
8
|
+
"iter",
|
|
9
|
+
"unicode",
|
|
10
|
+
"unicode/utf8",
|
|
11
|
+
}
|
package/gs/strings/reader.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import * as $ from '@goscript/builtin/
|
|
2
|
-
|
|
3
|
-
import * as errors from '@goscript/errors/index.js'
|
|
1
|
+
import * as $ from '@goscript/builtin/index.js'
|
|
4
2
|
|
|
5
3
|
import * as io from '@goscript/io/index.js'
|
|
6
4
|
|
|
@@ -90,7 +88,7 @@ export class Reader {
|
|
|
90
88
|
public ReadAt(b: Uint8Array, off: number): [number, $.GoError] {
|
|
91
89
|
const r = this
|
|
92
90
|
if (off < 0) {
|
|
93
|
-
return [0,
|
|
91
|
+
return [0, $.newError('strings.Reader.ReadAt: negative offset')]
|
|
94
92
|
}
|
|
95
93
|
if (off >= ($.len(r!.s) as number)) {
|
|
96
94
|
return [0, io.EOF]
|
|
@@ -119,7 +117,7 @@ export class Reader {
|
|
|
119
117
|
public UnreadByte(): $.GoError {
|
|
120
118
|
const r = this
|
|
121
119
|
if (r!.i <= 0) {
|
|
122
|
-
return
|
|
120
|
+
return $.newError('strings.Reader.UnreadByte: at beginning of string')
|
|
123
121
|
}
|
|
124
122
|
r!.prevRune = -1
|
|
125
123
|
r!.i--
|
|
@@ -151,10 +149,10 @@ export class Reader {
|
|
|
151
149
|
public UnreadRune(): $.GoError {
|
|
152
150
|
const r = this
|
|
153
151
|
if (r!.i <= 0) {
|
|
154
|
-
return
|
|
152
|
+
return $.newError('strings.Reader.UnreadRune: at beginning of string')
|
|
155
153
|
}
|
|
156
154
|
if (r!.prevRune < 0) {
|
|
157
|
-
return
|
|
155
|
+
return $.newError(
|
|
158
156
|
'strings.Reader.UnreadRune: previous operation was not ReadRune',
|
|
159
157
|
)
|
|
160
158
|
}
|
|
@@ -179,11 +177,11 @@ export class Reader {
|
|
|
179
177
|
abs = ($.len(r!.s) as number) + offset
|
|
180
178
|
break
|
|
181
179
|
default:
|
|
182
|
-
return [0,
|
|
180
|
+
return [0, $.newError('strings.Reader.Seek: invalid whence')]
|
|
183
181
|
break
|
|
184
182
|
}
|
|
185
183
|
if (abs < 0) {
|
|
186
|
-
return [0,
|
|
184
|
+
return [0, $.newError('strings.Reader.Seek: negative position')]
|
|
187
185
|
}
|
|
188
186
|
r!.i = abs
|
|
189
187
|
return [abs, null]
|
package/gs/strings/replace.ts
CHANGED
package/gs/strings/strings.ts
CHANGED
package/gs/sync/atomic/doc.gs.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as $ from "@goscript/builtin/
|
|
1
|
+
import * as $ from "@goscript/builtin/index.js";
|
|
2
2
|
import { AddInt32, AddUint32, AddUintptr, AndInt32, AndUint32, AndUintptr, CompareAndSwapInt32, CompareAndSwapPointer, CompareAndSwapUint32, CompareAndSwapUintptr, LoadInt32, LoadPointer, LoadUint32, LoadUintptr, OrInt32, OrUint32, OrUintptr, StoreInt32, StorePointer, StoreUint32, StoreUintptr, SwapInt32, SwapPointer, SwapUint32, SwapUintptr, uintptr } from "./doc.gs.js";
|
|
3
3
|
import { AddInt64, AddUint64, AndInt64, AndUint64, CompareAndSwapInt64, CompareAndSwapUint64, LoadInt64, LoadUint64, OrInt64, OrUint64, StoreInt64, StoreUint64, SwapInt64, SwapUint64 } from "./doc_64.gs.js";
|
|
4
4
|
|
package/gs/syscall/index.ts
CHANGED
package/gs/unicode/utf8/utf8.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Package utf8 implements functions and constants to support text encoded in UTF-8.
|
|
2
2
|
|
|
3
|
-
import * as $ from '@goscript/builtin/
|
|
3
|
+
import * as $ from '@goscript/builtin/index.js'
|
|
4
4
|
|
|
5
5
|
// RuneError is the "error" Rune or "Unicode replacement character"
|
|
6
6
|
export const RuneError = 0xfffd
|