goscript 0.0.61 → 0.0.62
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/README.md +9 -0
- package/compiler/analysis.go +536 -15
- package/compiler/assignment.go +72 -0
- package/compiler/compiler.go +64 -11
- package/compiler/composite-lit.go +29 -8
- package/compiler/decl.go +20 -11
- package/compiler/expr-call-async.go +26 -1
- package/compiler/expr-call-builtins.go +60 -4
- package/compiler/expr-call-type-conversion.go +37 -5
- package/compiler/expr-call.go +16 -3
- package/compiler/expr-selector.go +35 -2
- package/compiler/expr-type.go +12 -2
- package/compiler/expr.go +37 -0
- package/compiler/index.test.ts +3 -1
- package/compiler/lit.go +13 -4
- package/compiler/spec-struct.go +30 -8
- package/compiler/spec-value.go +2 -2
- package/compiler/spec.go +21 -4
- package/compiler/stmt-assign.go +71 -0
- package/compiler/stmt-range.go +2 -2
- package/compiler/stmt.go +128 -0
- package/compiler/type-utils.go +40 -1
- package/compiler/type.go +50 -12
- package/dist/gs/builtin/builtin.d.ts +8 -1
- package/dist/gs/builtin/builtin.js +26 -1
- package/dist/gs/builtin/builtin.js.map +1 -1
- package/dist/gs/builtin/errors.d.ts +1 -0
- package/dist/gs/builtin/errors.js +8 -0
- package/dist/gs/builtin/errors.js.map +1 -1
- package/dist/gs/builtin/slice.d.ts +5 -4
- package/dist/gs/builtin/slice.js +45 -14
- package/dist/gs/builtin/slice.js.map +1 -1
- package/dist/gs/builtin/type.d.ts +23 -2
- package/dist/gs/builtin/type.js +125 -0
- package/dist/gs/builtin/type.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/reflect/index.d.ts +2 -2
- package/dist/gs/reflect/index.js +1 -1
- package/dist/gs/reflect/index.js.map +1 -1
- package/dist/gs/reflect/map.d.ts +3 -2
- package/dist/gs/reflect/map.js +37 -3
- package/dist/gs/reflect/map.js.map +1 -1
- package/dist/gs/reflect/type.d.ts +50 -12
- package/dist/gs/reflect/type.js +820 -27
- package/dist/gs/reflect/type.js.map +1 -1
- package/dist/gs/reflect/types.d.ts +11 -12
- package/dist/gs/reflect/types.js +26 -15
- package/dist/gs/reflect/types.js.map +1 -1
- package/dist/gs/reflect/value.d.ts +4 -4
- package/dist/gs/reflect/value.js +8 -2
- package/dist/gs/reflect/value.js.map +1 -1
- package/dist/gs/slices/slices.d.ts +21 -0
- package/dist/gs/slices/slices.js +48 -0
- package/dist/gs/slices/slices.js.map +1 -1
- package/dist/gs/sync/atomic/type.gs.d.ts +2 -2
- package/dist/gs/sync/atomic/type.gs.js +12 -2
- package/dist/gs/sync/atomic/type.gs.js.map +1 -1
- package/dist/gs/unicode/utf8/utf8.d.ts +2 -2
- package/dist/gs/unicode/utf8/utf8.js +10 -6
- package/dist/gs/unicode/utf8/utf8.js.map +1 -1
- package/go.mod +4 -4
- package/go.sum +8 -8
- package/gs/builtin/builtin.ts +27 -2
- package/gs/builtin/errors.ts +12 -0
- package/gs/builtin/slice.ts +71 -7
- package/gs/builtin/type.ts +159 -2
- package/gs/bytes/reader.gs.ts +2 -2
- package/gs/math/hypot.gs.test.ts +3 -1
- package/gs/math/pow10.gs.test.ts +5 -4
- package/gs/reflect/index.ts +3 -2
- package/gs/reflect/map.test.ts +7 -6
- package/gs/reflect/map.ts +49 -7
- package/gs/reflect/type.ts +1053 -54
- package/gs/reflect/types.ts +34 -21
- package/gs/reflect/value.ts +12 -6
- package/gs/slices/slices.ts +55 -0
- package/gs/sync/atomic/type.gs.ts +14 -5
- package/gs/unicode/utf8/utf8.ts +12 -8
- package/package.json +13 -13
package/gs/math/hypot.gs.test.ts
CHANGED
|
@@ -43,7 +43,9 @@ describe('Hypot', () => {
|
|
|
43
43
|
it('should handle very large values without overflow', () => {
|
|
44
44
|
const large = 1e150
|
|
45
45
|
const result = Hypot(large, large)
|
|
46
|
-
|
|
46
|
+
const expected = large * Math.sqrt(2)
|
|
47
|
+
// Use relative tolerance for very large numbers
|
|
48
|
+
expect(Math.abs(result - expected) / expected).toBeLessThan(1e-10)
|
|
47
49
|
expect(IsInf(result, 0)).toBe(false)
|
|
48
50
|
})
|
|
49
51
|
|
package/gs/math/pow10.gs.test.ts
CHANGED
|
@@ -26,10 +26,11 @@ describe('Pow10', () => {
|
|
|
26
26
|
})
|
|
27
27
|
|
|
28
28
|
it('should handle large positive exponents', () => {
|
|
29
|
-
|
|
30
|
-
expect(Pow10(
|
|
31
|
-
expect(Pow10(
|
|
32
|
-
expect(Pow10(
|
|
29
|
+
// Use relative tolerance for very large numbers
|
|
30
|
+
expect(Math.abs(Pow10(100) - 1e100) / 1e100).toBeLessThan(1e-10)
|
|
31
|
+
expect(Math.abs(Pow10(200) - 1e200) / 1e200).toBeLessThan(1e-10)
|
|
32
|
+
expect(Math.abs(Pow10(300) - 1e300) / 1e300).toBeLessThan(1e-10)
|
|
33
|
+
expect(Math.abs(Pow10(308) - 1e308) / 1e308).toBeLessThan(1e-10)
|
|
33
34
|
expect(Pow10(309)).toBe(Number.POSITIVE_INFINITY)
|
|
34
35
|
expect(Pow10(400)).toBe(Number.POSITIVE_INFINITY)
|
|
35
36
|
})
|
package/gs/reflect/index.ts
CHANGED
|
@@ -35,19 +35,20 @@ export { Swapper } from './swapper.js'
|
|
|
35
35
|
// Export new types and constants
|
|
36
36
|
export {
|
|
37
37
|
StructTag,
|
|
38
|
+
StructTag_Get,
|
|
38
39
|
StructField,
|
|
39
40
|
ValueError,
|
|
40
|
-
SelectDir,
|
|
41
41
|
SelectSend,
|
|
42
42
|
SelectRecv,
|
|
43
43
|
SelectDefault,
|
|
44
|
+
SelectCase,
|
|
44
45
|
bitVector,
|
|
45
46
|
} from './types.js'
|
|
46
47
|
export type {
|
|
47
48
|
uintptr,
|
|
48
49
|
Pointer,
|
|
49
50
|
Method,
|
|
50
|
-
|
|
51
|
+
SelectDir,
|
|
51
52
|
SliceHeader,
|
|
52
53
|
StringHeader,
|
|
53
54
|
MapIter,
|
package/gs/reflect/map.test.ts
CHANGED
|
@@ -11,20 +11,21 @@ describe('MapIter', () => {
|
|
|
11
11
|
const iter = new MapIter<string, number>(map)
|
|
12
12
|
|
|
13
13
|
expect(iter.current?.done === false).toBe(true)
|
|
14
|
-
|
|
15
|
-
expect(iter.
|
|
14
|
+
// Key() and Value() return reflect.Value objects now
|
|
15
|
+
expect(iter.Key().Interface()).toBe('one')
|
|
16
|
+
expect(iter.Value().Interface()).toBe(1)
|
|
16
17
|
|
|
17
18
|
expect(iter.Next()).toBe(true)
|
|
18
19
|
expect(iter.current?.done === false).toBe(true)
|
|
19
|
-
expect(
|
|
20
|
-
expect(
|
|
20
|
+
expect(iter.Key().Kind()).toBe(24) // String kind
|
|
21
|
+
expect(iter.Value().Kind()).toBe(2) // Int kind
|
|
21
22
|
|
|
22
23
|
const newMap = new Map<string, number>()
|
|
23
24
|
newMap.set('reset', 100)
|
|
24
25
|
iter.Reset(newMap)
|
|
25
26
|
|
|
26
27
|
expect(iter.current?.done === false).toBe(true)
|
|
27
|
-
expect(iter.Key()).toBe('reset')
|
|
28
|
-
expect(iter.Value()).toBe(100)
|
|
28
|
+
expect(iter.Key().Interface()).toBe('reset')
|
|
29
|
+
expect(iter.Value().Interface()).toBe(100)
|
|
29
30
|
})
|
|
30
31
|
})
|
package/gs/reflect/map.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Type, Kind, Value, Map as MapKind } from './type.js'
|
|
1
|
+
import { Type, Kind, Value, Map as MapKind, StructField, TypeOf } from './type.js'
|
|
2
2
|
|
|
3
3
|
// Simple MapOf implementation using JavaScript Map
|
|
4
4
|
export function MapOf(key: Type, elem: Type): Type {
|
|
@@ -20,26 +20,66 @@ class MapType implements Type {
|
|
|
20
20
|
return MapKind // Map kind
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
public Name(): string {
|
|
24
|
+
return '' // Map types are unnamed composite types
|
|
25
|
+
}
|
|
26
|
+
|
|
23
27
|
public Size(): number {
|
|
24
28
|
return 8 // pointer size
|
|
25
29
|
}
|
|
26
30
|
|
|
27
|
-
public Elem(): Type
|
|
31
|
+
public Elem(): Type {
|
|
28
32
|
return this._elemType
|
|
29
33
|
}
|
|
30
34
|
|
|
31
|
-
public Key(): Type
|
|
35
|
+
public Key(): Type {
|
|
32
36
|
return this._keyType
|
|
33
37
|
}
|
|
34
38
|
|
|
35
39
|
public NumField(): number {
|
|
36
40
|
return 0
|
|
37
41
|
}
|
|
42
|
+
|
|
43
|
+
public Field(_i: number): StructField {
|
|
44
|
+
throw new Error('reflect: Field of non-struct type map')
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public Implements(u: Type | null): boolean {
|
|
48
|
+
if (!u) {
|
|
49
|
+
return false
|
|
50
|
+
}
|
|
51
|
+
if (u.Kind() !== 20) {
|
|
52
|
+
// Interface kind
|
|
53
|
+
throw new Error('reflect: non-interface type passed to Type.Implements')
|
|
54
|
+
}
|
|
55
|
+
return false
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public OverflowInt(_x: number): boolean {
|
|
59
|
+
throw new Error('reflect: OverflowInt of non-integer type map')
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
public OverflowUint(_x: number): boolean {
|
|
63
|
+
throw new Error('reflect: OverflowUint of non-integer type map')
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
public OverflowFloat(_x: number): boolean {
|
|
67
|
+
throw new Error('reflect: OverflowFloat of non-float type map')
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
public NumMethod(): number {
|
|
71
|
+
return 0
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
public Bits(): number {
|
|
75
|
+
throw new Error('reflect: Bits of non-sized type map')
|
|
76
|
+
}
|
|
38
77
|
}
|
|
39
78
|
|
|
40
79
|
/**
|
|
41
80
|
* MapIter provides an iterator interface for Go maps.
|
|
42
81
|
* It wraps a JavaScript Map iterator and provides methods to iterate over key-value pairs.
|
|
82
|
+
* Returns reflect.Value for Key() and Value() to match Go's reflect.MapIter.
|
|
43
83
|
* @template K - The type of keys in the map
|
|
44
84
|
* @template V - The type of values in the map
|
|
45
85
|
*/
|
|
@@ -57,12 +97,14 @@ export class MapIter<K = unknown, V = unknown> {
|
|
|
57
97
|
return !this.current.done
|
|
58
98
|
}
|
|
59
99
|
|
|
60
|
-
public Key():
|
|
61
|
-
|
|
100
|
+
public Key(): Value {
|
|
101
|
+
const rawKey = this.current?.value?.[0] ?? null
|
|
102
|
+
return new Value(rawKey, TypeOf(rawKey))
|
|
62
103
|
}
|
|
63
104
|
|
|
64
|
-
public Value():
|
|
65
|
-
|
|
105
|
+
public Value(): Value {
|
|
106
|
+
const rawVal = this.current?.value?.[1] ?? null
|
|
107
|
+
return new Value(rawVal, TypeOf(rawVal))
|
|
66
108
|
}
|
|
67
109
|
|
|
68
110
|
public Reset(m: Map<K, V>): void {
|