goscript 0.0.38 → 0.0.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. package/compiler/expr-call.go +12 -0
  2. package/compiler/lit.go +17 -6
  3. package/dist/gs/builtin/builtin.d.ts +45 -0
  4. package/dist/gs/builtin/builtin.js +197 -0
  5. package/dist/gs/builtin/builtin.js.map +1 -1
  6. package/dist/gs/bytes/buffer.gs.d.ts +56 -0
  7. package/dist/gs/bytes/buffer.gs.js +611 -0
  8. package/dist/gs/bytes/buffer.gs.js.map +1 -0
  9. package/dist/gs/bytes/bytes.gs.d.ts +78 -0
  10. package/dist/gs/bytes/bytes.gs.js +1011 -0
  11. package/dist/gs/bytes/bytes.gs.js.map +1 -0
  12. package/dist/gs/bytes/index.d.ts +4 -0
  13. package/dist/gs/bytes/index.js +5 -0
  14. package/dist/gs/bytes/index.js.map +1 -0
  15. package/dist/gs/bytes/iter.gs.d.ts +9 -0
  16. package/dist/gs/bytes/iter.gs.js +143 -0
  17. package/dist/gs/bytes/iter.gs.js.map +1 -0
  18. package/dist/gs/bytes/reader.gs.d.ts +34 -0
  19. package/dist/gs/bytes/reader.gs.js +198 -0
  20. package/dist/gs/bytes/reader.gs.js.map +1 -0
  21. package/dist/gs/internal/bytealg/index.d.ts +14 -2
  22. package/dist/gs/internal/bytealg/index.js +114 -8
  23. package/dist/gs/internal/bytealg/index.js.map +1 -1
  24. package/dist/gs/reflect/deepequal.d.ts +2 -1
  25. package/dist/gs/reflect/deepequal.js +5 -53
  26. package/dist/gs/reflect/deepequal.js.map +1 -1
  27. package/dist/gs/reflect/map.d.ts +14 -8
  28. package/dist/gs/reflect/map.js +15 -11
  29. package/dist/gs/reflect/map.js.map +1 -1
  30. package/dist/gs/reflect/type.d.ts +17 -9
  31. package/dist/gs/reflect/type.js +1 -1
  32. package/dist/gs/reflect/type.js.map +1 -1
  33. package/dist/gs/reflect/value.js +2 -1
  34. package/dist/gs/reflect/value.js.map +1 -1
  35. package/dist/gs/reflect/visiblefields.js +18 -12
  36. package/dist/gs/reflect/visiblefields.js.map +1 -1
  37. package/dist/gs/unicode/utf8/utf8.d.ts +1 -1
  38. package/dist/gs/unicode/utf8/utf8.js +4 -2
  39. package/dist/gs/unicode/utf8/utf8.js.map +1 -1
  40. package/gs/builtin/builtin.ts +219 -0
  41. package/gs/bytes/buffer.gs.ts +614 -0
  42. package/gs/bytes/bytes.gs.ts +1180 -0
  43. package/gs/bytes/godoc.txt +69 -0
  44. package/gs/bytes/index.ts +69 -0
  45. package/gs/bytes/iter.gs.ts +149 -0
  46. package/gs/bytes/reader.gs.ts +230 -0
  47. package/gs/internal/bytealg/index.ts +125 -10
  48. package/gs/reflect/deepequal.test.ts +41 -0
  49. package/gs/reflect/deepequal.ts +19 -4
  50. package/gs/reflect/map.test.ts +30 -0
  51. package/gs/reflect/map.ts +22 -18
  52. package/gs/reflect/type.ts +19 -15
  53. package/gs/reflect/value.ts +8 -2
  54. package/gs/reflect/visiblefields.ts +17 -13
  55. package/gs/unicode/utf8/utf8.ts +8 -5
  56. package/package.json +1 -1
  57. package/dist/gs/internal/testlog/index.d.ts +0 -1
  58. package/dist/gs/internal/testlog/index.js +0 -5
  59. package/dist/gs/internal/testlog/index.js.map +0 -1
  60. package/dist/gs/maps/iter.gs.d.ts +0 -7
  61. package/dist/gs/maps/iter.gs.js +0 -65
  62. package/dist/gs/maps/iter.gs.js.map +0 -1
  63. package/dist/gs/maps/maps.gs.d.ts +0 -7
  64. package/dist/gs/maps/maps.gs.js +0 -79
  65. package/dist/gs/maps/maps.gs.js.map +0 -1
  66. package/dist/gs/reflect/abi.d.ts +0 -59
  67. package/dist/gs/reflect/abi.gs.d.ts +0 -59
  68. package/dist/gs/reflect/abi.gs.js +0 -79
  69. package/dist/gs/reflect/abi.gs.js.map +0 -1
  70. package/dist/gs/reflect/abi.js +0 -79
  71. package/dist/gs/reflect/abi.js.map +0 -1
  72. package/dist/gs/reflect/badlinkname.d.ts +0 -52
  73. package/dist/gs/reflect/badlinkname.gs.d.ts +0 -52
  74. package/dist/gs/reflect/badlinkname.gs.js +0 -72
  75. package/dist/gs/reflect/badlinkname.gs.js.map +0 -1
  76. package/dist/gs/reflect/badlinkname.js +0 -72
  77. package/dist/gs/reflect/badlinkname.js.map +0 -1
  78. package/dist/gs/reflect/deepequal.gs.d.ts +0 -25
  79. package/dist/gs/reflect/deepequal.gs.js +0 -308
  80. package/dist/gs/reflect/deepequal.gs.js.map +0 -1
  81. package/dist/gs/reflect/float32reg_generic.gs.d.ts +0 -2
  82. package/dist/gs/reflect/float32reg_generic.gs.js +0 -10
  83. package/dist/gs/reflect/float32reg_generic.gs.js.map +0 -1
  84. package/dist/gs/reflect/index.gs.d.ts +0 -1
  85. package/dist/gs/reflect/index.gs.js +0 -3
  86. package/dist/gs/reflect/index.gs.js.map +0 -1
  87. package/dist/gs/reflect/iter.gs.d.ts +0 -3
  88. package/dist/gs/reflect/iter.gs.js +0 -24
  89. package/dist/gs/reflect/iter.gs.js.map +0 -1
  90. package/dist/gs/reflect/makefunc.gs.d.ts +0 -34
  91. package/dist/gs/reflect/makefunc.gs.js +0 -288
  92. package/dist/gs/reflect/makefunc.gs.js.map +0 -1
  93. package/dist/gs/reflect/map_swiss.gs.d.ts +0 -14
  94. package/dist/gs/reflect/map_swiss.gs.js +0 -70
  95. package/dist/gs/reflect/map_swiss.gs.js.map +0 -1
  96. package/dist/gs/reflect/reflect.gs.d.ts +0 -132
  97. package/dist/gs/reflect/reflect.gs.js +0 -437
  98. package/dist/gs/reflect/reflect.gs.js.map +0 -1
  99. package/dist/gs/reflect/swapper.gs.d.ts +0 -1
  100. package/dist/gs/reflect/swapper.gs.js +0 -32
  101. package/dist/gs/reflect/swapper.gs.js.map +0 -1
  102. package/dist/gs/reflect/type.gs.d.ts +0 -4
  103. package/dist/gs/reflect/type.gs.js +0 -21
  104. package/dist/gs/reflect/type.gs.js.map +0 -1
  105. package/dist/gs/reflect/value.gs.d.ts +0 -4
  106. package/dist/gs/reflect/value.gs.js +0 -12
  107. package/dist/gs/reflect/value.gs.js.map +0 -1
  108. package/dist/gs/reflect/visiblefields.gs.d.ts +0 -3
  109. package/dist/gs/reflect/visiblefields.gs.js +0 -123
  110. package/dist/gs/reflect/visiblefields.gs.js.map +0 -1
  111. package/dist/gs/stringslite/index.d.ts +0 -1
  112. package/dist/gs/stringslite/index.js +0 -2
  113. package/dist/gs/stringslite/index.js.map +0 -1
  114. package/dist/gs/stringslite/strings.d.ts +0 -11
  115. package/dist/gs/stringslite/strings.js +0 -67
  116. package/dist/gs/stringslite/strings.js.map +0 -1
@@ -0,0 +1,69 @@
1
+ package bytes // import "bytes"
2
+
3
+ Package bytes implements functions for the manipulation of byte slices. It is
4
+ analogous to the facilities of the strings package.
5
+
6
+ const MinRead = 512
7
+ var ErrTooLarge = errors.New("bytes.Buffer: too large")
8
+ func Clone(b []byte) []byte
9
+ func Compare(a, b []byte) int
10
+ func Contains(b, subslice []byte) bool
11
+ func ContainsAny(b []byte, chars string) bool
12
+ func ContainsFunc(b []byte, f func(rune) bool) bool
13
+ func ContainsRune(b []byte, r rune) bool
14
+ func Count(s, sep []byte) int
15
+ func Cut(s, sep []byte) (before, after []byte, found bool)
16
+ func CutPrefix(s, prefix []byte) (after []byte, found bool)
17
+ func CutSuffix(s, suffix []byte) (before []byte, found bool)
18
+ func Equal(a, b []byte) bool
19
+ func EqualFold(s, t []byte) bool
20
+ func Fields(s []byte) [][]byte
21
+ func FieldsFunc(s []byte, f func(rune) bool) [][]byte
22
+ func FieldsFuncSeq(s []byte, f func(rune) bool) iter.Seq[[]byte]
23
+ func FieldsSeq(s []byte) iter.Seq[[]byte]
24
+ func HasPrefix(s, prefix []byte) bool
25
+ func HasSuffix(s, suffix []byte) bool
26
+ func Index(s, sep []byte) int
27
+ func IndexAny(s []byte, chars string) int
28
+ func IndexByte(b []byte, c byte) int
29
+ func IndexFunc(s []byte, f func(r rune) bool) int
30
+ func IndexRune(s []byte, r rune) int
31
+ func Join(s [][]byte, sep []byte) []byte
32
+ func LastIndex(s, sep []byte) int
33
+ func LastIndexAny(s []byte, chars string) int
34
+ func LastIndexByte(s []byte, c byte) int
35
+ func LastIndexFunc(s []byte, f func(r rune) bool) int
36
+ func Lines(s []byte) iter.Seq[[]byte]
37
+ func Map(mapping func(r rune) rune, s []byte) []byte
38
+ func Repeat(b []byte, count int) []byte
39
+ func Replace(s, old, new []byte, n int) []byte
40
+ func ReplaceAll(s, old, new []byte) []byte
41
+ func Runes(s []byte) []rune
42
+ func Split(s, sep []byte) [][]byte
43
+ func SplitAfter(s, sep []byte) [][]byte
44
+ func SplitAfterN(s, sep []byte, n int) [][]byte
45
+ func SplitAfterSeq(s, sep []byte) iter.Seq[[]byte]
46
+ func SplitN(s, sep []byte, n int) [][]byte
47
+ func SplitSeq(s, sep []byte) iter.Seq[[]byte]
48
+ func Title(s []byte) []byte
49
+ func ToLower(s []byte) []byte
50
+ func ToLowerSpecial(c unicode.SpecialCase, s []byte) []byte
51
+ func ToTitle(s []byte) []byte
52
+ func ToTitleSpecial(c unicode.SpecialCase, s []byte) []byte
53
+ func ToUpper(s []byte) []byte
54
+ func ToUpperSpecial(c unicode.SpecialCase, s []byte) []byte
55
+ func ToValidUTF8(s, replacement []byte) []byte
56
+ func Trim(s []byte, cutset string) []byte
57
+ func TrimFunc(s []byte, f func(r rune) bool) []byte
58
+ func TrimLeft(s []byte, cutset string) []byte
59
+ func TrimLeftFunc(s []byte, f func(r rune) bool) []byte
60
+ func TrimPrefix(s, prefix []byte) []byte
61
+ func TrimRight(s []byte, cutset string) []byte
62
+ func TrimRightFunc(s []byte, f func(r rune) bool) []byte
63
+ func TrimSpace(s []byte) []byte
64
+ func TrimSuffix(s, suffix []byte) []byte
65
+ type Buffer struct{ ... }
66
+ func NewBuffer(buf []byte) *Buffer
67
+ func NewBufferString(s string) *Buffer
68
+ type Reader struct{ ... }
69
+ func NewReader(b []byte) *Reader
@@ -0,0 +1,69 @@
1
+ export {
2
+ Buffer,
3
+ ErrTooLarge,
4
+ MinRead,
5
+ NewBuffer,
6
+ NewBufferString,
7
+ } from './buffer.gs.js'
8
+ export {
9
+ Clone,
10
+ Compare,
11
+ Contains,
12
+ ContainsAny,
13
+ ContainsFunc,
14
+ ContainsRune,
15
+ Count,
16
+ Cut,
17
+ CutPrefix,
18
+ CutSuffix,
19
+ Equal,
20
+ EqualFold,
21
+ Fields,
22
+ FieldsFunc,
23
+ HasPrefix,
24
+ HasSuffix,
25
+ Index,
26
+ IndexAny,
27
+ IndexByte,
28
+ IndexFunc,
29
+ IndexRune,
30
+ Join,
31
+ LastIndex,
32
+ LastIndexAny,
33
+ LastIndexByte,
34
+ LastIndexFunc,
35
+ Map,
36
+ Repeat,
37
+ Replace,
38
+ ReplaceAll,
39
+ Runes,
40
+ Split,
41
+ SplitAfter,
42
+ SplitAfterN,
43
+ SplitN,
44
+ Title,
45
+ ToLower,
46
+ ToLowerSpecial,
47
+ ToTitle,
48
+ ToTitleSpecial,
49
+ ToUpper,
50
+ ToUpperSpecial,
51
+ ToValidUTF8,
52
+ Trim,
53
+ TrimFunc,
54
+ TrimLeft,
55
+ TrimLeftFunc,
56
+ TrimPrefix,
57
+ TrimRight,
58
+ TrimRightFunc,
59
+ TrimSpace,
60
+ TrimSuffix,
61
+ } from './bytes.gs.js'
62
+ export {
63
+ FieldsFuncSeq,
64
+ FieldsSeq,
65
+ Lines,
66
+ SplitAfterSeq,
67
+ SplitSeq,
68
+ } from './iter.gs.js'
69
+ export { NewReader, Reader } from './reader.gs.js'
@@ -0,0 +1,149 @@
1
+ import * as $ from "@goscript/builtin/builtin.js";
2
+ import { Index, IndexByte, asciiSpace } from "./bytes.gs.js";
3
+
4
+ import * as iter from "@goscript/iter/index.js"
5
+
6
+ import * as unicode from "@goscript/unicode/index.js"
7
+
8
+ import * as utf8 from "@goscript/unicode/utf8/index.js"
9
+
10
+ // Lines returns an iterator over the newline-terminated lines in the byte slice s.
11
+ // The lines yielded by the iterator include their terminating newlines.
12
+ // If s is empty, the iterator yields no lines at all.
13
+ // If s does not end in a newline, the final yielded line will not end in a newline.
14
+ // It returns a single-use iterator.
15
+ export function Lines(s: $.Bytes): iter.Seq<$.Bytes> {
16
+ return (_yield: ((p0: $.Bytes) => boolean) | null): void => {
17
+ for (; $.len(s) > 0; ) {
18
+ let line: $.Bytes = new Uint8Array(0)
19
+ {
20
+ let i = IndexByte(s, 10)
21
+ if (i >= 0) {
22
+ [line, s] = [$.goSlice(s, undefined, i + 1), $.goSlice(s, i + 1, undefined)]
23
+ } else {
24
+ [line, s] = [s, null]
25
+ }
26
+ }
27
+ if (!_yield!($.goSlice(line, undefined, $.len(line), $.len(line)))) {
28
+ return
29
+ }
30
+ }
31
+ return
32
+ }
33
+ }
34
+
35
+ // explodeSeq returns an iterator over the runes in s.
36
+ export function explodeSeq(s: $.Bytes): iter.Seq<$.Bytes> {
37
+ return (_yield: ((p0: $.Bytes) => boolean) | null): void => {
38
+ for (; $.len(s) > 0; ) {
39
+ let [, size] = utf8.DecodeRune(s)
40
+ if (!_yield!($.goSlice(s, undefined, size, size))) {
41
+ return
42
+ }
43
+ s = $.goSlice(s, size, undefined)
44
+ }
45
+ }
46
+ }
47
+
48
+ // splitSeq is SplitSeq or SplitAfterSeq, configured by how many
49
+ // bytes of sep to include in the results (none or all).
50
+ export function splitSeq(s: $.Bytes, sep: $.Bytes, sepSave: number): iter.Seq<$.Bytes> {
51
+ if ($.len(sep) == 0) {
52
+ return explodeSeq(s)
53
+ }
54
+ return (_yield: ((p0: $.Bytes) => boolean) | null): void => {
55
+ for (; ; ) {
56
+ let i = Index(s, sep)
57
+ if (i < 0) {
58
+ break
59
+ }
60
+ let frag = $.goSlice(s, undefined, i + sepSave)
61
+ if (!_yield!($.goSlice(frag, undefined, $.len(frag), $.len(frag)))) {
62
+ return
63
+ }
64
+ s = $.goSlice(s, i + $.len(sep), undefined)
65
+ }
66
+ _yield!($.goSlice(s, undefined, $.len(s), $.len(s)))
67
+ }
68
+ }
69
+
70
+ // SplitSeq returns an iterator over all subslices of s separated by sep.
71
+ // The iterator yields the same subslices that would be returned by [Split](s, sep),
72
+ // but without constructing a new slice containing the subslices.
73
+ // It returns a single-use iterator.
74
+ export function SplitSeq(s: $.Bytes, sep: $.Bytes): iter.Seq<$.Bytes> {
75
+ return splitSeq(s, sep, 0)
76
+ }
77
+
78
+ // SplitAfterSeq returns an iterator over subslices of s split after each instance of sep.
79
+ // The iterator yields the same subslices that would be returned by [SplitAfter](s, sep),
80
+ // but without constructing a new slice containing the subslices.
81
+ // It returns a single-use iterator.
82
+ export function SplitAfterSeq(s: $.Bytes, sep: $.Bytes): iter.Seq<$.Bytes> {
83
+ return splitSeq(s, sep, $.len(sep))
84
+ }
85
+
86
+ // FieldsSeq returns an iterator over subslices of s split around runs of
87
+ // whitespace characters, as defined by [unicode.IsSpace].
88
+ // The iterator yields the same subslices that would be returned by [Fields](s),
89
+ // but without constructing a new slice containing the subslices.
90
+ export function FieldsSeq(s: $.Bytes): iter.Seq<$.Bytes> {
91
+ return (_yield: ((p0: $.Bytes) => boolean) | null): void => {
92
+ let start = -1
93
+ for (let i = 0; i < $.len(s); ) {
94
+ let size = 1
95
+ let r = (s![i] as number)
96
+ let isSpace = asciiSpace![s![i]] != 0
97
+ if (r >= utf8.RuneSelf) {
98
+ ;[r, size] = utf8.DecodeRune($.goSlice(s, i, undefined))
99
+ isSpace = unicode.IsSpace(r)
100
+ }
101
+ if (isSpace) {
102
+ if (start >= 0) {
103
+ if (!_yield!($.goSlice(s, start, i, i))) {
104
+ return
105
+ }
106
+ start = -1
107
+ }
108
+ } else if (start < 0) {
109
+ start = i
110
+ }
111
+ i += size
112
+ }
113
+ if (start >= 0) {
114
+ _yield!($.goSlice(s, start, $.len(s), $.len(s)))
115
+ }
116
+ }
117
+ }
118
+
119
+ // FieldsFuncSeq returns an iterator over subslices of s split around runs of
120
+ // Unicode code points satisfying f(c).
121
+ // The iterator yields the same subslices that would be returned by [FieldsFunc](s),
122
+ // but without constructing a new slice containing the subslices.
123
+ export function FieldsFuncSeq(s: $.Bytes, f: ((p0: number) => boolean) | null): iter.Seq<$.Bytes> {
124
+ return (_yield: ((p0: $.Bytes) => boolean) | null): void => {
125
+ let start = -1
126
+ for (let i = 0; i < $.len(s); ) {
127
+ let size = 1
128
+ let r = (s![i] as number)
129
+ if (r >= utf8.RuneSelf) {
130
+ ;[r, size] = utf8.DecodeRune($.goSlice(s, i, undefined))
131
+ }
132
+ if (f!(r)) {
133
+ if (start >= 0) {
134
+ if (!_yield!($.goSlice(s, start, i, i))) {
135
+ return
136
+ }
137
+ start = -1
138
+ }
139
+ } else if (start < 0) {
140
+ start = i
141
+ }
142
+ i += size
143
+ }
144
+ if (start >= 0) {
145
+ _yield!($.goSlice(s, start, $.len(s), $.len(s)))
146
+ }
147
+ }
148
+ }
149
+
@@ -0,0 +1,230 @@
1
+ import * as $ from "@goscript/builtin/builtin.js";
2
+ const { copy } = $;
3
+
4
+ import * as errors from "@goscript/errors/index.js"
5
+
6
+ import * as io from "@goscript/io/index.js"
7
+
8
+ import * as utf8 from "@goscript/unicode/utf8/index.js"
9
+
10
+ export class Reader {
11
+ public get s(): $.Bytes {
12
+ return this._fields.s.value
13
+ }
14
+ public set s(value: $.Bytes) {
15
+ this._fields.s.value = value
16
+ }
17
+
18
+ // current reading index
19
+ public get i(): number {
20
+ return this._fields.i.value
21
+ }
22
+ public set i(value: number) {
23
+ this._fields.i.value = value
24
+ }
25
+
26
+ // index of previous rune; or < 0
27
+ public get prevRune(): number {
28
+ return this._fields.prevRune.value
29
+ }
30
+ public set prevRune(value: number) {
31
+ this._fields.prevRune.value = value
32
+ }
33
+
34
+ public _fields: {
35
+ s: $.VarRef<$.Bytes>;
36
+ i: $.VarRef<number>;
37
+ prevRune: $.VarRef<number>;
38
+ }
39
+
40
+ constructor(init?: Partial<{i?: number, prevRune?: number, s?: $.Bytes}>) {
41
+ this._fields = {
42
+ s: $.varRef(init?.s ?? new Uint8Array(0)),
43
+ i: $.varRef(init?.i ?? 0),
44
+ prevRune: $.varRef(init?.prevRune ?? 0)
45
+ }
46
+ }
47
+
48
+ public clone(): Reader {
49
+ const cloned = new Reader()
50
+ cloned._fields = {
51
+ s: $.varRef(this._fields.s.value),
52
+ i: $.varRef(this._fields.i.value),
53
+ prevRune: $.varRef(this._fields.prevRune.value)
54
+ }
55
+ return cloned
56
+ }
57
+
58
+ // Len returns the number of bytes of the unread portion of the
59
+ // slice.
60
+ public Len(): number {
61
+ const r = this
62
+ if (r.i >= ($.len(r.s) as number)) {
63
+ return 0
64
+ }
65
+ return $.int(($.len(r.s) as number) - r.i)
66
+ }
67
+
68
+ // Size returns the original length of the underlying byte slice.
69
+ // Size is the number of bytes available for reading via [Reader.ReadAt].
70
+ // The result is unaffected by any method calls except [Reader.Reset].
71
+ public Size(): number {
72
+ const r = this
73
+ return ($.len(r.s) as number)
74
+ }
75
+
76
+ // Read implements the [io.Reader] interface.
77
+ public Read(b: $.Bytes): [number, $.GoError] {
78
+ const r = this
79
+ if (r.i >= ($.len(r.s) as number)) {
80
+ return [0, io.EOF]
81
+ }
82
+ r.prevRune = -1
83
+ const n = $.copy($.bytesToUint8Array(b), $.bytesToUint8Array($.goSlice(r.s, r.i, undefined)))
84
+ r.i += (n as number)
85
+ return [n, null]
86
+ }
87
+
88
+ // ReadAt implements the [io.ReaderAt] interface.
89
+ public ReadAt(b: $.Bytes, off: number): [number, $.GoError] {
90
+ const r = this
91
+ if (off < 0) {
92
+ return [0, errors.New("bytes.Reader.ReadAt: negative offset")]
93
+ }
94
+ if (off >= ($.len(r.s) as number)) {
95
+ return [0, io.EOF]
96
+ }
97
+ const n = $.copy($.bytesToUint8Array(b), $.bytesToUint8Array($.goSlice(r.s, off, undefined)))
98
+ let err: $.GoError = null
99
+ if (n < $.len(b)) {
100
+ err = io.EOF
101
+ }
102
+ return [n, err]
103
+ }
104
+
105
+ // ReadByte implements the [io.ByteReader] interface.
106
+ public ReadByte(): [number, $.GoError] {
107
+ const r = this
108
+ r.prevRune = -1
109
+ if (r.i >= ($.len(r.s) as number)) {
110
+ return [0, io.EOF]
111
+ }
112
+ let b = r.s![r.i]
113
+ r.i++
114
+ return [b, null]
115
+ }
116
+
117
+ // UnreadByte complements [Reader.ReadByte] in implementing the [io.ByteScanner] interface.
118
+ public UnreadByte(): $.GoError {
119
+ const r = this
120
+ if (r.i <= 0) {
121
+ return errors.New("bytes.Reader.UnreadByte: at beginning of slice")
122
+ }
123
+ r.prevRune = -1
124
+ r.i--
125
+ return null
126
+ }
127
+
128
+ // ReadRune implements the [io.RuneReader] interface.
129
+ public ReadRune(): [number, number, $.GoError] {
130
+ const r = this
131
+ if (r.i >= ($.len(r.s) as number)) {
132
+ r.prevRune = -1
133
+ return [0, 0, io.EOF]
134
+ }
135
+ r.prevRune = $.int(r.i)
136
+ {
137
+ let c = r.s![r.i]
138
+ if (c < utf8.RuneSelf) {
139
+ r.i++
140
+ return [(c as number), 1, null]
141
+ }
142
+ }
143
+ const [ch, size] = utf8.DecodeRune($.goSlice(r.s, r.i, undefined))
144
+ r.i += (size as number)
145
+ return [ch, size, null]
146
+ }
147
+
148
+ // UnreadRune complements [Reader.ReadRune] in implementing the [io.RuneScanner] interface.
149
+ public UnreadRune(): $.GoError {
150
+ const r = this
151
+ if (r.i <= 0) {
152
+ return errors.New("bytes.Reader.UnreadRune: at beginning of slice")
153
+ }
154
+ if (r.prevRune < 0) {
155
+ return errors.New("bytes.Reader.UnreadRune: previous operation was not ReadRune")
156
+ }
157
+ r.i = (r.prevRune as number)
158
+ r.prevRune = -1
159
+ return null
160
+ }
161
+
162
+ // Seek implements the [io.Seeker] interface.
163
+ public Seek(offset: number, whence: number): [number, $.GoError] {
164
+ const r = this
165
+ r.prevRune = -1
166
+ let abs: number = 0
167
+ switch (whence) {
168
+ case io.SeekStart:
169
+ abs = offset
170
+ break
171
+ case io.SeekCurrent:
172
+ abs = r.i + offset
173
+ break
174
+ case io.SeekEnd:
175
+ abs = ($.len(r.s) as number) + offset
176
+ break
177
+ default:
178
+ return [0, errors.New("bytes.Reader.Seek: invalid whence")]
179
+ break
180
+ }
181
+ if (abs < 0) {
182
+ return [0, errors.New("bytes.Reader.Seek: negative position")]
183
+ }
184
+ r.i = abs
185
+ return [abs, null]
186
+ }
187
+
188
+ // WriteTo implements the [io.WriterTo] interface.
189
+ public WriteTo(w: io.Writer): [number, $.GoError] {
190
+ const r = this
191
+ r.prevRune = -1
192
+ if (r.i >= ($.len(r.s) as number)) {
193
+ return [0, null]
194
+ }
195
+ const b = $.goSlice(r.s, r.i, undefined)
196
+ const [m, err] = w!.Write($.bytesToUint8Array(b))
197
+ if (m > $.len(b)) {
198
+ $.panic("bytes.Reader.WriteTo: invalid Write count")
199
+ }
200
+ r.i += (m as number)
201
+ const n = (m as number)
202
+ if (m != $.len(b) && err == null) {
203
+ return [n, io.ErrShortWrite]
204
+ }
205
+ return [n, err]
206
+ }
207
+
208
+ // Reset resets the [Reader] to be reading from b.
209
+ public Reset(b: $.Bytes): void {
210
+ const r = this
211
+ r.s = b
212
+ r.i = 0
213
+ r.prevRune = -1
214
+ }
215
+
216
+ // Register this type with the runtime type system
217
+ static __typeInfo = $.registerStructType(
218
+ 'Reader',
219
+ new Reader(),
220
+ [{ name: "Len", args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: "number" } }] }, { name: "Size", args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: "number" } }] }, { name: "Read", args: [{ name: "b", type: { kind: $.TypeKind.Slice, elemType: { kind: $.TypeKind.Basic, name: "number" } } }], returns: [{ type: { kind: $.TypeKind.Basic, name: "number" } }, { type: { kind: $.TypeKind.Interface, name: 'GoError', methods: [{ name: 'Error', args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }] }] } }] }, { name: "ReadAt", args: [{ name: "b", type: { kind: $.TypeKind.Slice, elemType: { kind: $.TypeKind.Basic, name: "number" } } }, { name: "off", type: { kind: $.TypeKind.Basic, name: "number" } }], returns: [{ type: { kind: $.TypeKind.Basic, name: "number" } }, { type: { kind: $.TypeKind.Interface, name: 'GoError', methods: [{ name: 'Error', args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }] }] } }] }, { name: "ReadByte", args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: "number" } }, { type: { kind: $.TypeKind.Interface, name: 'GoError', methods: [{ name: 'Error', args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }] }] } }] }, { name: "UnreadByte", args: [], returns: [{ type: { kind: $.TypeKind.Interface, name: 'GoError', methods: [{ name: 'Error', args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }] }] } }] }, { name: "ReadRune", args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: "number" } }, { type: { kind: $.TypeKind.Basic, name: "number" } }, { type: { kind: $.TypeKind.Interface, name: 'GoError', methods: [{ name: 'Error', args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }] }] } }] }, { name: "UnreadRune", args: [], returns: [{ type: { kind: $.TypeKind.Interface, name: 'GoError', methods: [{ name: 'Error', args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }] }] } }] }, { name: "Seek", args: [{ name: "offset", type: { kind: $.TypeKind.Basic, name: "number" } }, { name: "whence", type: { kind: $.TypeKind.Basic, name: "number" } }], returns: [{ type: { kind: $.TypeKind.Basic, name: "number" } }, { type: { kind: $.TypeKind.Interface, name: 'GoError', methods: [{ name: 'Error', args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }] }] } }] }, { name: "WriteTo", args: [{ name: "w", type: "Writer" }], returns: [{ type: { kind: $.TypeKind.Basic, name: "number" } }, { type: { kind: $.TypeKind.Interface, name: 'GoError', methods: [{ name: 'Error', args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }] }] } }] }, { name: "Reset", args: [{ name: "b", type: { kind: $.TypeKind.Slice, elemType: { kind: $.TypeKind.Basic, name: "number" } } }], returns: [] }],
221
+ Reader,
222
+ {"s": { kind: $.TypeKind.Slice, elemType: { kind: $.TypeKind.Basic, name: "number" } }, "i": { kind: $.TypeKind.Basic, name: "number" }, "prevRune": { kind: $.TypeKind.Basic, name: "number" }}
223
+ );
224
+ }
225
+
226
+ // NewReader returns a new [Reader] reading from b.
227
+ export function NewReader(b: $.Bytes): Reader | null {
228
+ return new Reader({})
229
+ }
230
+
@@ -1,12 +1,31 @@
1
1
  // Placeholder bytealg module for reflect package compatibility
2
2
 
3
+ // Helper function to normalize bytes input
4
+ function normalizeBytes(b: any): any[] {
5
+ if (b === null || b === undefined) {
6
+ return []
7
+ }
8
+ if (Array.isArray(b)) {
9
+ return b
10
+ }
11
+ if (b instanceof Uint8Array) {
12
+ return Array.from(b)
13
+ }
14
+ if (b && typeof b === 'object' && 'data' in b && Array.isArray(b.data)) {
15
+ return b.data
16
+ }
17
+ return []
18
+ }
19
+
3
20
  // Equal reports whether a and b are the same length and contain the same bytes.
4
- export function Equal(a: Uint8Array | any[], b: Uint8Array | any[]): boolean {
5
- if (a.length !== b.length) {
21
+ export function Equal(a: any, b: any): boolean {
22
+ const aNorm = normalizeBytes(a)
23
+ const bNorm = normalizeBytes(b)
24
+ if (aNorm.length !== bNorm.length) {
6
25
  return false
7
26
  }
8
- for (let i = 0; i < a.length; i++) {
9
- if (a[i] !== b[i]) {
27
+ for (let i = 0; i < aNorm.length; i++) {
28
+ if (aNorm[i] !== bNorm[i]) {
10
29
  return false
11
30
  }
12
31
  }
@@ -14,21 +33,117 @@ export function Equal(a: Uint8Array | any[], b: Uint8Array | any[]): boolean {
14
33
  }
15
34
 
16
35
  // Compare returns an integer comparing two byte slices lexicographically.
17
- export function Compare(a: Uint8Array | any[], b: Uint8Array | any[]): number {
18
- const minLen = Math.min(a.length, b.length)
36
+ export function Compare(a: any, b: any): number {
37
+ const aNorm = normalizeBytes(a)
38
+ const bNorm = normalizeBytes(b)
39
+ const minLen = Math.min(aNorm.length, bNorm.length)
19
40
  for (let i = 0; i < minLen; i++) {
20
- if (a[i] < b[i]) {
41
+ if (aNorm[i] < bNorm[i]) {
21
42
  return -1
22
43
  }
23
- if (a[i] > b[i]) {
44
+ if (aNorm[i] > bNorm[i]) {
24
45
  return 1
25
46
  }
26
47
  }
27
- if (a.length < b.length) {
48
+ if (aNorm.length < bNorm.length) {
28
49
  return -1
29
50
  }
30
- if (a.length > b.length) {
51
+ if (aNorm.length > bNorm.length) {
31
52
  return 1
32
53
  }
33
54
  return 0
34
55
  }
56
+
57
+ // Additional functions needed by bytes package
58
+ export function Count(s: any, b: number): number {
59
+ const sNorm = normalizeBytes(s)
60
+ let count = 0
61
+ for (let i = 0; i < sNorm.length; i++) {
62
+ if (sNorm[i] === b) {
63
+ count++
64
+ }
65
+ }
66
+ return count
67
+ }
68
+
69
+ export function IndexByte(s: any, b: number): number {
70
+ const sNorm = normalizeBytes(s)
71
+ for (let i = 0; i < sNorm.length; i++) {
72
+ if (sNorm[i] === b) {
73
+ return i
74
+ }
75
+ }
76
+ return -1
77
+ }
78
+
79
+ export function LastIndexByte(s: any, b: number): number {
80
+ const sNorm = normalizeBytes(s)
81
+ for (let i = sNorm.length - 1; i >= 0; i--) {
82
+ if (sNorm[i] === b) {
83
+ return i
84
+ }
85
+ }
86
+ return -1
87
+ }
88
+
89
+ export function Index(s: any, sep: any): number {
90
+ const sNorm = normalizeBytes(s)
91
+ const sepNorm = normalizeBytes(sep)
92
+ if (sepNorm.length === 0) return 0
93
+ if (sepNorm.length > sNorm.length) return -1
94
+
95
+ for (let i = 0; i <= sNorm.length - sepNorm.length; i++) {
96
+ let found = true
97
+ for (let j = 0; j < sepNorm.length; j++) {
98
+ if (sNorm[i + j] !== sepNorm[j]) {
99
+ found = false
100
+ break
101
+ }
102
+ }
103
+ if (found) return i
104
+ }
105
+ return -1
106
+ }
107
+
108
+ export function LastIndexRabinKarp(s: any, sep: any): number {
109
+ const sNorm = normalizeBytes(s)
110
+ const sepNorm = normalizeBytes(sep)
111
+ // Simple implementation
112
+ for (let i = sNorm.length - sepNorm.length; i >= 0; i--) {
113
+ let found = true
114
+ for (let j = 0; j < sepNorm.length; j++) {
115
+ if (sNorm[i + j] !== sepNorm[j]) {
116
+ found = false
117
+ break
118
+ }
119
+ }
120
+ if (found) return i
121
+ }
122
+ return -1
123
+ }
124
+
125
+ export function IndexRabinKarp(s: any, sep: any): number {
126
+ return Index(s, sep)
127
+ }
128
+
129
+ export function IndexByteString(s: string, b: number): number {
130
+ const char = String.fromCharCode(b)
131
+ return s.indexOf(char)
132
+ }
133
+
134
+ export function IndexString(s: string, substr: string): number {
135
+ return s.indexOf(substr)
136
+ }
137
+
138
+ export function MakeNoZero(n: number): Uint8Array {
139
+ return new Uint8Array(n)
140
+ }
141
+
142
+ export function Cutover(_n: number): number {
143
+ // TODO: Implement Cutover function
144
+ return 10 // Simple threshold
145
+ }
146
+
147
+ // Constants needed by bytes package
148
+ export const MaxBruteForce = 64
149
+ export const MaxLen = 32