goscript 0.0.60 → 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.
Files changed (87) hide show
  1. package/README.md +9 -0
  2. package/compiler/analysis.go +974 -369
  3. package/compiler/assignment.go +72 -0
  4. package/compiler/compiler.go +74 -15
  5. package/compiler/composite-lit.go +29 -8
  6. package/compiler/decl.go +67 -98
  7. package/compiler/expr-call-async.go +26 -1
  8. package/compiler/expr-call-builtins.go +60 -4
  9. package/compiler/expr-call-helpers.go +182 -0
  10. package/compiler/expr-call-type-conversion.go +37 -5
  11. package/compiler/expr-call.go +25 -33
  12. package/compiler/expr-selector.go +71 -1
  13. package/compiler/expr-type.go +49 -3
  14. package/compiler/expr.go +37 -28
  15. package/compiler/index.test.ts +3 -1
  16. package/compiler/lit.go +13 -4
  17. package/compiler/spec-struct.go +42 -9
  18. package/compiler/spec-value.go +2 -2
  19. package/compiler/spec.go +42 -5
  20. package/compiler/stmt-assign.go +71 -0
  21. package/compiler/stmt-range.go +2 -2
  22. package/compiler/stmt.go +130 -10
  23. package/compiler/type-utils.go +40 -16
  24. package/compiler/type.go +50 -12
  25. package/dist/gs/builtin/builtin.d.ts +8 -1
  26. package/dist/gs/builtin/builtin.js +26 -1
  27. package/dist/gs/builtin/builtin.js.map +1 -1
  28. package/dist/gs/builtin/errors.d.ts +1 -0
  29. package/dist/gs/builtin/errors.js +8 -0
  30. package/dist/gs/builtin/errors.js.map +1 -1
  31. package/dist/gs/builtin/slice.d.ts +5 -4
  32. package/dist/gs/builtin/slice.js +51 -21
  33. package/dist/gs/builtin/slice.js.map +1 -1
  34. package/dist/gs/builtin/type.d.ts +28 -2
  35. package/dist/gs/builtin/type.js +132 -0
  36. package/dist/gs/builtin/type.js.map +1 -1
  37. package/dist/gs/bytes/reader.gs.d.ts +1 -1
  38. package/dist/gs/bytes/reader.gs.js +1 -1
  39. package/dist/gs/bytes/reader.gs.js.map +1 -1
  40. package/dist/gs/internal/byteorder/index.d.ts +6 -0
  41. package/dist/gs/internal/byteorder/index.js +34 -0
  42. package/dist/gs/internal/byteorder/index.js.map +1 -1
  43. package/dist/gs/reflect/index.d.ts +3 -3
  44. package/dist/gs/reflect/index.js +2 -2
  45. package/dist/gs/reflect/index.js.map +1 -1
  46. package/dist/gs/reflect/map.d.ts +3 -2
  47. package/dist/gs/reflect/map.js +37 -3
  48. package/dist/gs/reflect/map.js.map +1 -1
  49. package/dist/gs/reflect/type.d.ts +55 -8
  50. package/dist/gs/reflect/type.js +889 -23
  51. package/dist/gs/reflect/type.js.map +1 -1
  52. package/dist/gs/reflect/types.d.ts +11 -12
  53. package/dist/gs/reflect/types.js +26 -15
  54. package/dist/gs/reflect/types.js.map +1 -1
  55. package/dist/gs/reflect/value.d.ts +4 -4
  56. package/dist/gs/reflect/value.js +8 -2
  57. package/dist/gs/reflect/value.js.map +1 -1
  58. package/dist/gs/slices/slices.d.ts +32 -0
  59. package/dist/gs/slices/slices.js +81 -0
  60. package/dist/gs/slices/slices.js.map +1 -1
  61. package/dist/gs/sync/atomic/type.gs.d.ts +2 -2
  62. package/dist/gs/sync/atomic/type.gs.js +12 -2
  63. package/dist/gs/sync/atomic/type.gs.js.map +1 -1
  64. package/dist/gs/unicode/utf8/utf8.d.ts +2 -2
  65. package/dist/gs/unicode/utf8/utf8.js +10 -6
  66. package/dist/gs/unicode/utf8/utf8.js.map +1 -1
  67. package/go.mod +4 -4
  68. package/go.sum +8 -16
  69. package/gs/builtin/builtin.ts +27 -2
  70. package/gs/builtin/errors.ts +12 -0
  71. package/gs/builtin/slice.ts +77 -14
  72. package/gs/builtin/type.ts +167 -2
  73. package/gs/bytes/reader.gs.ts +2 -2
  74. package/gs/internal/byteorder/index.ts +40 -0
  75. package/gs/math/hypot.gs.test.ts +3 -1
  76. package/gs/math/pow10.gs.test.ts +5 -4
  77. package/gs/reflect/index.ts +6 -3
  78. package/gs/reflect/map.test.ts +7 -6
  79. package/gs/reflect/map.ts +49 -7
  80. package/gs/reflect/type.ts +1139 -43
  81. package/gs/reflect/types.ts +34 -21
  82. package/gs/reflect/value.ts +12 -6
  83. package/gs/slices/slices.ts +92 -0
  84. package/gs/sync/atomic/type.gs.ts +14 -5
  85. package/gs/sync/meta.json +1 -1
  86. package/gs/unicode/utf8/utf8.ts +12 -8
  87. package/package.json +13 -13
@@ -1,5 +1,7 @@
1
1
  import { ReflectValue, StructField } from './types.js';
2
+ export { StructField };
2
3
  import { MapIter } from './map.js';
4
+ import * as $ from '../builtin/index.js';
3
5
  export declare class rtype {
4
6
  kind: Kind;
5
7
  constructor(kind: Kind);
@@ -61,16 +63,24 @@ export interface Type {
61
63
  String(): string;
62
64
  Kind(): Kind;
63
65
  Size(): number;
64
- Elem(): Type | null;
66
+ Elem(): Type;
65
67
  NumField(): number;
66
68
  PkgPath?(): string;
67
- Field?(i: number): StructField | null;
69
+ Field(i: number): StructField;
70
+ Key(): Type;
71
+ Name(): string;
72
+ Implements(u: Type | null): boolean;
68
73
  common?(): rtype;
74
+ OverflowInt(x: number): boolean;
75
+ OverflowUint(x: number): boolean;
76
+ OverflowFloat(x: number): boolean;
77
+ NumMethod(): number;
78
+ Bits(): number;
69
79
  }
70
80
  export declare class Value {
71
81
  private _value;
72
82
  private _type;
73
- constructor(_value: ReflectValue, _type: Type);
83
+ constructor(value?: ReflectValue | Record<string, never>, type?: Type | null);
74
84
  clone(): Value;
75
85
  Int(): number;
76
86
  Uint(): number;
@@ -86,12 +96,18 @@ export declare class Value {
86
96
  Bytes(): Uint8Array;
87
97
  Elem(): Value;
88
98
  NumField(): number;
89
- Field(_i: number): Value;
99
+ Field(i: number): Value;
90
100
  UnsafePointer(): unknown;
91
101
  pointer(): unknown;
92
102
  get ptr(): unknown;
93
103
  get value(): ReflectValue;
94
104
  Convert(t: Type): Value;
105
+ CanAddr(): boolean;
106
+ Addr(): Value;
107
+ CanSet(): boolean;
108
+ Set(x: Value): void;
109
+ Interface(): any;
110
+ IsZero(): boolean;
95
111
  typ(): rtype | null;
96
112
  get flag(): number;
97
113
  MapRange(): MapIter<unknown, unknown> | null;
@@ -101,6 +117,23 @@ export declare class Value {
101
117
  imag: number;
102
118
  } | null;
103
119
  Send(x: Value): void;
120
+ SetString(x: string): void;
121
+ SetInt(x: number): void;
122
+ SetUint(x: number): void;
123
+ SetBool(x: boolean): void;
124
+ SetFloat(x: number): void;
125
+ SetBytes(x: $.Slice<number>): void;
126
+ SetZero(): void;
127
+ SetLen(n: number): void;
128
+ SetMapIndex(key: Value, elem: Value): void;
129
+ Grow(n: number): void;
130
+ Cap(): number;
131
+ NumMethod(): number;
132
+ Equal(u: Value): boolean;
133
+ CanInterface(): boolean;
134
+ OverflowInt(x: number): boolean;
135
+ OverflowUint(x: number): boolean;
136
+ OverflowFloat(x: number): boolean;
104
137
  }
105
138
  export declare class BasicType implements Type {
106
139
  private _kind;
@@ -110,20 +143,34 @@ export declare class BasicType implements Type {
110
143
  String(): string;
111
144
  Kind(): Kind;
112
145
  Size(): number;
113
- Elem(): Type | null;
146
+ Elem(): Type;
114
147
  NumField(): number;
115
148
  PkgPath?(): string;
116
- Field?(_i: number): StructField | null;
149
+ Name(): string;
150
+ Field(_i: number): StructField;
151
+ Key(): Type;
152
+ Implements(u: Type | null): boolean;
117
153
  common?(): rtype;
154
+ OverflowInt(x: number): boolean;
155
+ OverflowUint(x: number): boolean;
156
+ OverflowFloat(x: number): boolean;
157
+ NumMethod(): number;
158
+ Bits(): number;
118
159
  }
119
160
  export declare function TypeOf(i: ReflectValue): Type;
120
161
  export declare function ValueOf(i: ReflectValue): Value;
121
162
  export declare function ArrayOf(length: number, elem: Type): Type;
122
163
  export declare function SliceOf(t: Type): Type;
123
- export declare function PointerTo(t: Type): Type;
124
- export declare function PtrTo(t: Type): Type;
164
+ export declare function PointerTo(t: Type | null): Type | null;
165
+ export declare function PtrTo(t: Type | null): Type | null;
125
166
  export declare function MapOf(key: Type, elem: Type): Type;
126
167
  export declare function ChanOf(dir: ChanDir, t: Type): Type;
168
+ export declare function TypeFor(): Type;
169
+ /**
170
+ * getInterfaceTypeByName looks up a registered interface type by name
171
+ * and returns a Type for it. Returns an interface{} type if not found.
172
+ */
173
+ export declare function getInterfaceTypeByName(name: string): Type;
127
174
  export declare function canRangeFunc(t: Type): boolean;
128
175
  export declare function canRangeFunc2(t: Type): boolean;
129
176
  export declare function funcLayout(_t: Type, _rcvr: Type | null): {