porffor 0.2.0-664913c → 0.2.0-6922552
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/CONTRIBUTING.md +12 -4
- package/README.md +0 -7
- package/compiler/builtins/annexb_string.js +1 -1
- package/compiler/builtins/annexb_string.ts +4 -4
- package/compiler/builtins/array.ts +9 -9
- package/compiler/builtins/boolean.ts +6 -0
- package/compiler/builtins/date.ts +50 -51
- package/compiler/builtins/escape.ts +1 -1
- package/compiler/builtins/int.ts +2 -2
- package/compiler/builtins/number.ts +8 -1
- package/compiler/builtins/string.ts +36 -21
- package/compiler/builtins/tostring.ts +3 -3
- package/compiler/builtins.js +4 -4
- package/compiler/codegen.js +30 -30
- package/compiler/generated_builtins.js +145 -109
- package/compiler/precompile.js +1 -1
- package/compiler/prefs.js +1 -1
- package/compiler/prototype.js +14 -14
- package/compiler/types.js +1 -1
- package/compiler/wrap.js +3 -3
- package/package.json +1 -1
@@ -37,7 +37,7 @@ export const __String_prototype_toUpperCase = (_this: string) => {
|
|
37
37
|
return out;
|
38
38
|
};
|
39
39
|
|
40
|
-
export const
|
40
|
+
export const __ByteString_prototype_toUpperCase = (_this: bytestring) => {
|
41
41
|
const len: i32 = _this.length;
|
42
42
|
|
43
43
|
let out: bytestring = '';
|
@@ -83,7 +83,7 @@ export const __String_prototype_toLowerCase = (_this: string) => {
|
|
83
83
|
return out;
|
84
84
|
};
|
85
85
|
|
86
|
-
export const
|
86
|
+
export const __ByteString_prototype_toLowerCase = (_this: bytestring) => {
|
87
87
|
const len: i32 = _this.length;
|
88
88
|
|
89
89
|
let out: bytestring = '';
|
@@ -134,10 +134,10 @@ export const __String_prototype_startsWith = (_this: string, searchString: strin
|
|
134
134
|
return true;
|
135
135
|
};
|
136
136
|
|
137
|
-
export const
|
137
|
+
export const __ByteString_prototype_startsWith = (_this: bytestring, searchString: bytestring, position: number) => {
|
138
138
|
// if searching non-bytestring, bytestring will not start with it
|
139
139
|
// todo: change this to just check if = string and ToString others
|
140
|
-
if (Porffor.wasm`local.get ${searchString+1}` != Porffor.TYPES.
|
140
|
+
if (Porffor.wasm`local.get ${searchString+1}` != Porffor.TYPES.bytestring) return false;
|
141
141
|
|
142
142
|
// todo/perf: investigate whether for counter vs while ++s are faster
|
143
143
|
|
@@ -204,10 +204,10 @@ export const __String_prototype_endsWith = (_this: string, searchString: string,
|
|
204
204
|
return true;
|
205
205
|
};
|
206
206
|
|
207
|
-
export const
|
207
|
+
export const __ByteString_prototype_endsWith = (_this: bytestring, searchString: bytestring, endPosition: number) => {
|
208
208
|
// if searching non-bytestring, bytestring will not start with it
|
209
209
|
// todo: change this to just check if = string and ToString others
|
210
|
-
if (Porffor.wasm`local.get ${searchString+1}` != Porffor.TYPES.
|
210
|
+
if (Porffor.wasm`local.get ${searchString+1}` != Porffor.TYPES.bytestring) return false;
|
211
211
|
|
212
212
|
let i: i32 = Porffor.wasm`local.get ${_this}`,
|
213
213
|
j: i32 = Porffor.wasm`local.get ${searchString}`;
|
@@ -282,10 +282,10 @@ export const __String_prototype_indexOf = (_this: string, searchString: string,
|
|
282
282
|
return -1;
|
283
283
|
};
|
284
284
|
|
285
|
-
export const
|
285
|
+
export const __ByteString_prototype_indexOf = (_this: bytestring, searchString: bytestring, position: number) => {
|
286
286
|
// if searching non-bytestring, bytestring will not start with it
|
287
287
|
// todo: change this to just check if = string and ToString others
|
288
|
-
if (Porffor.wasm`local.get ${searchString+1}` != Porffor.TYPES.
|
288
|
+
if (Porffor.wasm`local.get ${searchString+1}` != Porffor.TYPES.bytestring) return -1;
|
289
289
|
|
290
290
|
let thisPtr: i32 = Porffor.wasm`local.get ${_this}`;
|
291
291
|
const searchPtr: i32 = Porffor.wasm`local.get ${searchString}`;
|
@@ -369,10 +369,10 @@ export const __String_prototype_lastIndexOf = (_this: string, searchString: stri
|
|
369
369
|
return -1;
|
370
370
|
};
|
371
371
|
|
372
|
-
export const
|
372
|
+
export const __ByteString_prototype_lastIndexOf = (_this: bytestring, searchString: bytestring, position: number) => {
|
373
373
|
// if searching non-bytestring, bytestring will not start with it
|
374
374
|
// todo: change this to just check if = string and ToString others
|
375
|
-
if (Porffor.wasm`local.get ${searchString+1}` != Porffor.TYPES.
|
375
|
+
if (Porffor.wasm`local.get ${searchString+1}` != Porffor.TYPES.bytestring) return -1;
|
376
376
|
|
377
377
|
let thisPtr: i32 = Porffor.wasm`local.get ${_this}`;
|
378
378
|
const searchPtr: i32 = Porffor.wasm`local.get ${searchString}`;
|
@@ -455,10 +455,10 @@ export const __String_prototype_includes = (_this: string, searchString: string,
|
|
455
455
|
return false;
|
456
456
|
};
|
457
457
|
|
458
|
-
export const
|
458
|
+
export const __ByteString_prototype_includes = (_this: bytestring, searchString: bytestring, position: number) => {
|
459
459
|
// if searching non-bytestring, bytestring will not start with it
|
460
460
|
// todo: change this to just check if = string and ToString others
|
461
|
-
if (Porffor.wasm`local.get ${searchString+1}` != Porffor.TYPES.
|
461
|
+
if (Porffor.wasm`local.get ${searchString+1}` != Porffor.TYPES.bytestring) return -1;
|
462
462
|
|
463
463
|
let thisPtr: i32 = Porffor.wasm`local.get ${_this}`;
|
464
464
|
const searchPtr: i32 = Porffor.wasm`local.get ${searchString}`;
|
@@ -542,7 +542,7 @@ export const __String_prototype_padStart = (_this: string, targetLength: number,
|
|
542
542
|
return out;
|
543
543
|
};
|
544
544
|
|
545
|
-
export const
|
545
|
+
export const __ByteString_prototype_padStart = (_this: bytestring, targetLength: number, padString: bytestring) => {
|
546
546
|
// todo: handle padString being non-bytestring
|
547
547
|
|
548
548
|
let out: bytestring = Porffor.bs``;
|
@@ -631,7 +631,7 @@ export const __String_prototype_padEnd = (_this: string, targetLength: number, p
|
|
631
631
|
return out;
|
632
632
|
};
|
633
633
|
|
634
|
-
export const
|
634
|
+
export const __ByteString_prototype_padEnd = (_this: bytestring, targetLength: number, padString: bytestring) => {
|
635
635
|
// todo: handle padString being non-bytestring
|
636
636
|
|
637
637
|
let out: bytestring = Porffor.bs``;
|
@@ -713,7 +713,7 @@ export const __String_prototype_substring = (_this: string, start: number, end:
|
|
713
713
|
return out;
|
714
714
|
};
|
715
715
|
|
716
|
-
export const
|
716
|
+
export const __ByteString_prototype_substring = (_this: bytestring, start: number, end: number) => {
|
717
717
|
const len: i32 = _this.length;
|
718
718
|
if (Porffor.wasm`local.get ${end+1}` == Porffor.TYPES.undefined) end = len;
|
719
719
|
else if (start > end) {
|
@@ -786,7 +786,7 @@ export const __String_prototype_substr = (_this: string, start: number, length:
|
|
786
786
|
return out;
|
787
787
|
};
|
788
788
|
|
789
|
-
export const
|
789
|
+
export const __ByteString_prototype_substr = (_this: string, start: number, length: number) => {
|
790
790
|
const len: i32 = _this.length;
|
791
791
|
|
792
792
|
start |= 0;
|
@@ -862,7 +862,7 @@ export const __String_prototype_slice = (_this: string, start: number, end: numb
|
|
862
862
|
return out;
|
863
863
|
};
|
864
864
|
|
865
|
-
export const
|
865
|
+
export const __ByteString_prototype_slice = (_this: bytestring, start: number, end: number) => {
|
866
866
|
const len: i32 = _this.length;
|
867
867
|
if (Porffor.wasm`local.get ${end+1}` == Porffor.TYPES.undefined) end = len;
|
868
868
|
|
@@ -935,7 +935,7 @@ export const __String_prototype_trimStart = (_this: string) => {
|
|
935
935
|
return out;
|
936
936
|
};
|
937
937
|
|
938
|
-
export const
|
938
|
+
export const __ByteString_prototype_trimStart = (_this: bytestring) => {
|
939
939
|
let out: bytestring = Porffor.bs``;
|
940
940
|
|
941
941
|
let outPtr: i32 = Porffor.wasm`local.get ${out}`;
|
@@ -1006,7 +1006,7 @@ export const __String_prototype_trimEnd = (_this: string) => {
|
|
1006
1006
|
return out;
|
1007
1007
|
};
|
1008
1008
|
|
1009
|
-
export const
|
1009
|
+
export const __ByteString_prototype_trimEnd = (_this: bytestring) => {
|
1010
1010
|
let out: bytestring = Porffor.bs``;
|
1011
1011
|
|
1012
1012
|
let outPtr: i32 = Porffor.wasm`local.get ${out}`;
|
@@ -1049,7 +1049,22 @@ export const __String_prototype_trim = (_this: string) => {
|
|
1049
1049
|
return __String_prototype_trimStart(__String_prototype_trimEnd(_this));
|
1050
1050
|
};
|
1051
1051
|
|
1052
|
-
export const
|
1052
|
+
export const __ByteString_prototype_trim = (_this: bytestring) => {
|
1053
1053
|
// todo/perf: optimize and not just reuse
|
1054
|
-
return
|
1054
|
+
return __ByteString_prototype_trimStart(__ByteString_prototype_trimEnd(_this));
|
1055
|
+
};
|
1056
|
+
|
1057
|
+
|
1058
|
+
// 22.1.3.35 String.prototype.valueOf ()
|
1059
|
+
// https://tc39.es/ecma262/#sec-string.prototype.valueof
|
1060
|
+
export const __String_prototype_valueOf = (_this: string) => {
|
1061
|
+
// 1. Return ? ThisStringValue(this value).
|
1062
|
+
return _this;
|
1063
|
+
};
|
1064
|
+
|
1065
|
+
// 22.1.3.35 String.prototype.valueOf ()
|
1066
|
+
// https://tc39.es/ecma262/#sec-string.prototype.valueof
|
1067
|
+
export const __ByteString_prototype_valueOf = (_this: bytestring) => {
|
1068
|
+
// 1. Return ? ThisStringValue(this value).
|
1069
|
+
return _this;
|
1055
1070
|
};
|
@@ -14,7 +14,7 @@ export const __String_prototype_toString = (_this: string) => {
|
|
14
14
|
return out;
|
15
15
|
};
|
16
16
|
|
17
|
-
export const
|
17
|
+
export const __ByteString_prototype_toString = (_this: bytestring) => {
|
18
18
|
let out: bytestring = Porffor.bs``;
|
19
19
|
Porffor.clone(_this, out);
|
20
20
|
return out;
|
@@ -36,10 +36,10 @@ export const __Function_prototype_toString = (_this: Function) => {
|
|
36
36
|
};
|
37
37
|
|
38
38
|
|
39
|
-
// // export const
|
39
|
+
// // export const __Array_prototype_toString = (_this: any[]) => {
|
40
40
|
// // return _this.join();
|
41
41
|
// // };
|
42
42
|
|
43
|
-
// // export const
|
43
|
+
// // export const __RegExp_prototype_toString = (_this: number) => {
|
44
44
|
|
45
45
|
// // };
|
package/compiler/builtins.js
CHANGED
@@ -141,7 +141,7 @@ export const BuiltinVars = function() {
|
|
141
141
|
|
142
142
|
// wintercg(tm)
|
143
143
|
this.__navigator_userAgent = (scope, { makeString }) => makeString(scope, `Porffor/0.2.0`, false, '__navigator_userAgent');
|
144
|
-
this.__navigator_userAgent.type = Prefs.bytestring ? TYPES.
|
144
|
+
this.__navigator_userAgent.type = Prefs.bytestring ? TYPES.bytestring : TYPES.string;
|
145
145
|
|
146
146
|
for (const x in TYPES) {
|
147
147
|
this['__Porffor_TYPES_' + x] = number(TYPES[x]);
|
@@ -273,7 +273,7 @@ export const BuiltinFuncs = function() {
|
|
273
273
|
|
274
274
|
[ Opcodes.end ]
|
275
275
|
],
|
276
|
-
[TYPES.
|
276
|
+
[TYPES.bytestring]: [
|
277
277
|
// simply print a (byte)string :))
|
278
278
|
// cache input pointer as i32
|
279
279
|
[ Opcodes.local_get, 0 ],
|
@@ -307,7 +307,7 @@ export const BuiltinFuncs = function() {
|
|
307
307
|
|
308
308
|
[ Opcodes.end ]
|
309
309
|
],
|
310
|
-
[TYPES.
|
310
|
+
[TYPES.array]: [
|
311
311
|
...printStaticStr('[ '),
|
312
312
|
|
313
313
|
// cache input pointer as i32
|
@@ -1039,7 +1039,7 @@ export const BuiltinFuncs = function() {
|
|
1039
1039
|
typedParams: true,
|
1040
1040
|
locals: [ Valtype.i32, Valtype.i32 ],
|
1041
1041
|
returns: [ valtypeBinary ],
|
1042
|
-
returnType: Prefs.bytestring ? TYPES.
|
1042
|
+
returnType: Prefs.bytestring ? TYPES.bytestring : TYPES.string,
|
1043
1043
|
wasm: (scope, { TYPE_NAMES, typeSwitch, makeString }) => {
|
1044
1044
|
const bc = {};
|
1045
1045
|
for (const x in TYPE_NAMES) {
|
package/compiler/codegen.js
CHANGED
@@ -219,8 +219,8 @@ const generate = (scope, decl, global = false, name = undefined, valueUnused = f
|
|
219
219
|
__Porffor_bs: str => [
|
220
220
|
...makeString(scope, str, global, name, true),
|
221
221
|
|
222
|
-
...(name ? setType(scope, name, TYPES.
|
223
|
-
...number(TYPES.
|
222
|
+
...(name ? setType(scope, name, TYPES.bytestring) : [
|
223
|
+
...number(TYPES.bytestring, Valtype.i32),
|
224
224
|
...setLastType(scope)
|
225
225
|
])
|
226
226
|
],
|
@@ -723,7 +723,7 @@ const truthy = (scope, wasm, type, intIn = false, intOut = false) => {
|
|
723
723
|
|
724
724
|
...typeSwitch(scope, type, {
|
725
725
|
// [TYPES.number]: def,
|
726
|
-
[TYPES.
|
726
|
+
[TYPES.array]: [
|
727
727
|
// arrays are always truthy
|
728
728
|
...number(1, intOut ? Valtype.i32 : valtypeBinary)
|
729
729
|
],
|
@@ -739,7 +739,7 @@ const truthy = (scope, wasm, type, intIn = false, intOut = false) => {
|
|
739
739
|
[ Opcodes.i32_eqz ], */
|
740
740
|
...(intOut ? [] : [ Opcodes.i32_from_u ])
|
741
741
|
],
|
742
|
-
[TYPES.
|
742
|
+
[TYPES.bytestring]: [ // duplicate of string
|
743
743
|
...(!useTmp ? [] : [ [ Opcodes.local_get, tmp ] ]),
|
744
744
|
...(intIn ? [] : [ Opcodes.i32_to_u ]),
|
745
745
|
|
@@ -762,7 +762,7 @@ const falsy = (scope, wasm, type, intIn = false, intOut = false) => {
|
|
762
762
|
...(!useTmp ? [] : [ [ Opcodes.local_set, tmp ] ]),
|
763
763
|
|
764
764
|
...typeSwitch(scope, type, {
|
765
|
-
[TYPES.
|
765
|
+
[TYPES.array]: [
|
766
766
|
// arrays are always truthy
|
767
767
|
...number(0, intOut ? Valtype.i32 : valtypeBinary)
|
768
768
|
],
|
@@ -777,7 +777,7 @@ const falsy = (scope, wasm, type, intIn = false, intOut = false) => {
|
|
777
777
|
[ Opcodes.i32_eqz ],
|
778
778
|
...(intOut ? [] : [ Opcodes.i32_from_u ])
|
779
779
|
],
|
780
|
-
[TYPES.
|
780
|
+
[TYPES.bytestring]: [ // duplicate of string
|
781
781
|
...(!useTmp ? [] : [ [ Opcodes.local_get, tmp ] ]),
|
782
782
|
...(intIn ? [] : [ Opcodes.i32_to_u ]),
|
783
783
|
|
@@ -922,7 +922,7 @@ const performOp = (scope, op, left, right, leftType, rightType, _global = false,
|
|
922
922
|
}
|
923
923
|
}
|
924
924
|
|
925
|
-
if (knownLeft === TYPES.
|
925
|
+
if (knownLeft === TYPES.bytestring || knownRight === TYPES.bytestring) {
|
926
926
|
if (op === '+') {
|
927
927
|
// todo: this should be dynamic too but for now only static
|
928
928
|
// string concat (a + b)
|
@@ -1041,12 +1041,12 @@ const performOp = (scope, op, left, right, leftType, rightType, _global = false,
|
|
1041
1041
|
|
1042
1042
|
// if left is bytestring
|
1043
1043
|
...leftType,
|
1044
|
-
...number(TYPES.
|
1044
|
+
...number(TYPES.bytestring, Valtype.i32),
|
1045
1045
|
[ Opcodes.i32_eq ],
|
1046
1046
|
|
1047
1047
|
// if right is bytestring
|
1048
1048
|
...rightType,
|
1049
|
-
...number(TYPES.
|
1049
|
+
...number(TYPES.bytestring, Valtype.i32),
|
1050
1050
|
[ Opcodes.i32_eq ],
|
1051
1051
|
|
1052
1052
|
// if both are true
|
@@ -1188,7 +1188,7 @@ const generateLogicExp = (scope, decl) => {
|
|
1188
1188
|
// 5: pointer
|
1189
1189
|
|
1190
1190
|
const isExistingProtoFunc = name => {
|
1191
|
-
if (name.startsWith('__Array_prototype')) return !!prototypeFuncs[TYPES.
|
1191
|
+
if (name.startsWith('__Array_prototype')) return !!prototypeFuncs[TYPES.array][name.slice(18)];
|
1192
1192
|
if (name.startsWith('__String_prototype_')) return !!prototypeFuncs[TYPES.string][name.slice(19)];
|
1193
1193
|
|
1194
1194
|
return false;
|
@@ -1247,9 +1247,9 @@ const setLastType = scope => {
|
|
1247
1247
|
const getNodeType = (scope, node) => {
|
1248
1248
|
const inner = () => {
|
1249
1249
|
if (node.type === 'Literal') {
|
1250
|
-
if (node.regex) return TYPES.
|
1250
|
+
if (node.regex) return TYPES.regexp;
|
1251
1251
|
|
1252
|
-
if (typeof node.value === 'string' && byteStringable(node.value)) return TYPES.
|
1252
|
+
if (typeof node.value === 'string' && byteStringable(node.value)) return TYPES.bytestring;
|
1253
1253
|
|
1254
1254
|
return TYPES[typeof node.value];
|
1255
1255
|
}
|
@@ -1303,7 +1303,7 @@ const getNodeType = (scope, node) => {
|
|
1303
1303
|
const spl = name.slice(2).split('_');
|
1304
1304
|
|
1305
1305
|
const func = spl[spl.length - 1];
|
1306
|
-
const protoFuncs = Object.keys(prototypeFuncs).filter(x => x != TYPES.
|
1306
|
+
const protoFuncs = Object.keys(prototypeFuncs).filter(x => x != TYPES.bytestring && prototypeFuncs[x][func] != null);
|
1307
1307
|
if (protoFuncs.length === 1) return protoFuncs[0].returnType ?? TYPES.number;
|
1308
1308
|
}
|
1309
1309
|
|
@@ -1355,7 +1355,7 @@ const getNodeType = (scope, node) => {
|
|
1355
1355
|
}
|
1356
1356
|
|
1357
1357
|
if (node.type === 'ArrayExpression') {
|
1358
|
-
return TYPES.
|
1358
|
+
return TYPES.array;
|
1359
1359
|
}
|
1360
1360
|
|
1361
1361
|
if (node.type === 'BinaryExpression') {
|
@@ -1367,7 +1367,7 @@ const getNodeType = (scope, node) => {
|
|
1367
1367
|
|
1368
1368
|
// todo: this should be dynamic but for now only static
|
1369
1369
|
if (knownLeft === TYPES.string || knownRight === TYPES.string) return TYPES.string;
|
1370
|
-
if (knownLeft === TYPES.
|
1370
|
+
if (knownLeft === TYPES.bytestring || knownRight === TYPES.bytestring) return TYPES.bytestring;
|
1371
1371
|
|
1372
1372
|
return TYPES.number;
|
1373
1373
|
|
@@ -1393,7 +1393,7 @@ const getNodeType = (scope, node) => {
|
|
1393
1393
|
if (node.operator === '!') return TYPES.boolean;
|
1394
1394
|
if (node.operator === 'void') return TYPES.undefined;
|
1395
1395
|
if (node.operator === 'delete') return TYPES.boolean;
|
1396
|
-
if (node.operator === 'typeof') return Prefs.bytestring ? TYPES.
|
1396
|
+
if (node.operator === 'typeof') return Prefs.bytestring ? TYPES.bytestring : TYPES.string;
|
1397
1397
|
|
1398
1398
|
return TYPES.number;
|
1399
1399
|
}
|
@@ -1404,8 +1404,8 @@ const getNodeType = (scope, node) => {
|
|
1404
1404
|
|
1405
1405
|
// ts hack
|
1406
1406
|
if (scope.locals[node.object.name]?.metadata?.type === TYPES.string) return TYPES.string;
|
1407
|
-
if (scope.locals[node.object.name]?.metadata?.type === TYPES.
|
1408
|
-
if (scope.locals[node.object.name]?.metadata?.type === TYPES.
|
1407
|
+
if (scope.locals[node.object.name]?.metadata?.type === TYPES.bytestring) return TYPES.bytestring;
|
1408
|
+
if (scope.locals[node.object.name]?.metadata?.type === TYPES.array) return TYPES.number;
|
1409
1409
|
|
1410
1410
|
if (scope.locals['#last_type']) return getLastType(scope);
|
1411
1411
|
|
@@ -2092,7 +2092,7 @@ const brTable = (input, bc, returns) => {
|
|
2092
2092
|
};
|
2093
2093
|
|
2094
2094
|
const typeSwitch = (scope, type, bc, returns = valtypeBinary) => {
|
2095
|
-
if (!Prefs.bytestring) delete bc[TYPES.
|
2095
|
+
if (!Prefs.bytestring) delete bc[TYPES.bytestring];
|
2096
2096
|
|
2097
2097
|
const known = knownType(scope, type);
|
2098
2098
|
if (known != null) {
|
@@ -2195,7 +2195,7 @@ const extractTypeAnnotation = decl => {
|
|
2195
2195
|
const typeName = type;
|
2196
2196
|
type = typeAnnoToPorfType(type);
|
2197
2197
|
|
2198
|
-
if (type === TYPES.
|
2198
|
+
if (type === TYPES.bytestring && !Prefs.bytestring) type = TYPES.string;
|
2199
2199
|
|
2200
2200
|
// if (decl.name) console.log(decl.name, { type, elementType });
|
2201
2201
|
|
@@ -2325,7 +2325,7 @@ const generateAssign = (scope, decl, _global, _name, valueUnused = false) => {
|
|
2325
2325
|
|
2326
2326
|
return [
|
2327
2327
|
...typeSwitch(scope, getNodeType(scope, decl.left.object), {
|
2328
|
-
[TYPES.
|
2328
|
+
[TYPES.array]: [
|
2329
2329
|
...(aotPointer ? [] : [
|
2330
2330
|
...generate(scope, decl.left.object),
|
2331
2331
|
Opcodes.i32_to_u
|
@@ -2527,7 +2527,7 @@ const generateUnary = (scope, decl) => {
|
|
2527
2527
|
[TYPES.undefined]: makeString(scope, 'undefined', false, '#typeof_result'),
|
2528
2528
|
[TYPES.function]: makeString(scope, 'function', false, '#typeof_result'),
|
2529
2529
|
|
2530
|
-
[TYPES.
|
2530
|
+
[TYPES.bytestring]: makeString(scope, 'string', false, '#typeof_result'),
|
2531
2531
|
|
2532
2532
|
// object and internal types
|
2533
2533
|
default: makeString(scope, 'object', false, '#typeof_result'),
|
@@ -2763,7 +2763,7 @@ const generateForOf = (scope, decl) => {
|
|
2763
2763
|
// set type for local
|
2764
2764
|
// todo: optimize away counter and use end pointer
|
2765
2765
|
out.push(...typeSwitch(scope, getNodeType(scope, decl.right), {
|
2766
|
-
[TYPES.
|
2766
|
+
[TYPES.array]: [
|
2767
2767
|
...setType(scope, leftName, TYPES.number),
|
2768
2768
|
|
2769
2769
|
[ Opcodes.loop, Blocktype.void ],
|
@@ -2846,8 +2846,8 @@ const generateForOf = (scope, decl) => {
|
|
2846
2846
|
[ Opcodes.end ],
|
2847
2847
|
[ Opcodes.end ]
|
2848
2848
|
],
|
2849
|
-
[TYPES.
|
2850
|
-
...setType(scope, leftName, TYPES.
|
2849
|
+
[TYPES.bytestring]: [
|
2850
|
+
...setType(scope, leftName, TYPES.bytestring),
|
2851
2851
|
|
2852
2852
|
[ Opcodes.loop, Blocktype.void ],
|
2853
2853
|
|
@@ -3266,7 +3266,7 @@ export const generateMember = (scope, decl, _global, _name) => {
|
|
3266
3266
|
}
|
3267
3267
|
|
3268
3268
|
return typeSwitch(scope, getNodeType(scope, decl.object), {
|
3269
|
-
[TYPES.
|
3269
|
+
[TYPES.array]: [
|
3270
3270
|
// get index as valtype
|
3271
3271
|
...property,
|
3272
3272
|
|
@@ -3319,7 +3319,7 @@ export const generateMember = (scope, decl, _global, _name) => {
|
|
3319
3319
|
...number(TYPES.string, Valtype.i32),
|
3320
3320
|
...setLastType(scope)
|
3321
3321
|
],
|
3322
|
-
[TYPES.
|
3322
|
+
[TYPES.bytestring]: [
|
3323
3323
|
// setup new/out array
|
3324
3324
|
...newOut,
|
3325
3325
|
[ Opcodes.drop ],
|
@@ -3344,7 +3344,7 @@ export const generateMember = (scope, decl, _global, _name) => {
|
|
3344
3344
|
// return new string (page)
|
3345
3345
|
...number(newPointer),
|
3346
3346
|
|
3347
|
-
...number(TYPES.
|
3347
|
+
...number(TYPES.bytestring, Valtype.i32),
|
3348
3348
|
...setLastType(scope)
|
3349
3349
|
],
|
3350
3350
|
|
@@ -3513,7 +3513,7 @@ const internalConstrs = {
|
|
3513
3513
|
...number(pointer)
|
3514
3514
|
];
|
3515
3515
|
},
|
3516
|
-
type: TYPES.
|
3516
|
+
type: TYPES.array,
|
3517
3517
|
length: 1
|
3518
3518
|
},
|
3519
3519
|
|
@@ -3525,7 +3525,7 @@ const internalConstrs = {
|
|
3525
3525
|
elements: decl.arguments
|
3526
3526
|
}, global, name);
|
3527
3527
|
},
|
3528
|
-
type: TYPES.
|
3528
|
+
type: TYPES.array,
|
3529
3529
|
notConstr: true,
|
3530
3530
|
length: 0
|
3531
3531
|
},
|