porffor 0.34.10 → 0.34.11
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/builtins/string.ts +35 -0
- package/compiler/builtins_precompiled.js +10 -0
- package/compiler/prototype.js +0 -87
- package/package.json +1 -1
- package/runner/index.js +1 -1
@@ -1495,6 +1495,41 @@ export const __ByteString_prototype_localeCompare = (_this: bytestring, compareS
|
|
1495
1495
|
};
|
1496
1496
|
|
1497
1497
|
|
1498
|
+
export const __String_prototype_isWellFormed = (_this: string) => {
|
1499
|
+
let ptr: i32 = Porffor.wasm`local.get ${_this}`;
|
1500
|
+
const endPtr: i32 = ptr + _this.length * 2;
|
1501
|
+
while (ptr < endPtr) {
|
1502
|
+
const c1: i32 = Porffor.wasm.i32.load16_u(ptr, 0, 4);
|
1503
|
+
|
1504
|
+
if (Porffor.fastAnd(c1 >= 0xDC00, c1 <= 0xDFFF)) {
|
1505
|
+
// lone trailing surrogate, bad
|
1506
|
+
return false;
|
1507
|
+
}
|
1508
|
+
|
1509
|
+
if (Porffor.fastAnd(c1 >= 0xD800, c1 <= 0xDBFF)) {
|
1510
|
+
// leading surrogate, peek if next is trailing
|
1511
|
+
const c2: i32 = ptr + 2 < endPtr ? Porffor.wasm.i32.load16_u(ptr + 2, 0, 4) : 0;
|
1512
|
+
|
1513
|
+
if (Porffor.fastAnd(c2 >= 0xDC00, c2 <= 0xDFFF)) {
|
1514
|
+
// next is trailing surrogate, skip it too
|
1515
|
+
ptr += 2;
|
1516
|
+
} else {
|
1517
|
+
// lone leading surrogate, bad
|
1518
|
+
return false;
|
1519
|
+
}
|
1520
|
+
}
|
1521
|
+
|
1522
|
+
ptr += 2;
|
1523
|
+
}
|
1524
|
+
|
1525
|
+
return true;
|
1526
|
+
};
|
1527
|
+
|
1528
|
+
export const __ByteString_prototype_isWellFormed = (_this: bytestring) => {
|
1529
|
+
// bytestrings cannot have surrogates, so always true
|
1530
|
+
return true;
|
1531
|
+
};
|
1532
|
+
|
1498
1533
|
export const __String_prototype_toWellFormed = (_this: string) => {
|
1499
1534
|
let out: string = Porffor.allocate();
|
1500
1535
|
Porffor.clone(_this, out);
|
@@ -2253,6 +2253,16 @@ wasm:(_,{builtin,internalThrow})=>[[32,2],[184],[32,3],[16,builtin('__ecma262_To
|
|
2253
2253
|
params:[127,127,127,127],typedParams:1,returns:[127,127],typedReturns:1,
|
2254
2254
|
locals:[127,127,127,127,127,127,127,127,127,127,127],localNames:["_this","_this#type","compareString","compareString#type","#last_type","thisLen","compareLen","maxLen","i","a","__proto_length_cache","__proto_pointer_cache","__charCodeAt_tmp","b","#typeswitch_tmp1"],
|
2255
2255
|
};
|
2256
|
+
this.__String_prototype_isWellFormed = {
|
2257
|
+
wasm:()=>[[32,0],[34,2],[32,0],[40,1,0],[65,2],[108],[106],[33,3],[3,64],[32,2],[32,3],[72],[4,64],[32,2],[47,0,4],[34,4],[65,128,184,3],[78],[32,4],[65,255,191,3],[76],[113],[4,64],[65,0],[65,2],[15],[11],[32,4],[65,128,176,3],[78],[32,4],[65,255,183,3],[76],[113],[4,64],[32,2],[65,2],[106],[32,3],[72],[4,127],[32,2],[65,2],[106],[47,0,4],[65,1],[33,6],[5],[65,0],[65,1],[33,6],[11],[34,5],[65,128,184,3],[78],[32,5],[65,255,191,3],[76],[113],[4,64],[32,2],[65,2],[106],[33,2],[5],[65,0],[65,2],[15],[11],[11],[32,2],[65,2],[106],[33,2],[12,1],[11],[11],[65,1],[65,2],[15]],
|
2258
|
+
params:[127,127],typedParams:1,returns:[127,127],typedReturns:1,
|
2259
|
+
locals:[127,127,127,127,127],localNames:["_this","_this#type","ptr","endPtr","c1","c2","#last_type"],
|
2260
|
+
};
|
2261
|
+
this.__ByteString_prototype_isWellFormed = {
|
2262
|
+
wasm:()=>[[65,1],[65,2],[15]],
|
2263
|
+
params:[127,127],typedParams:1,returns:[127,127],typedReturns:1,
|
2264
|
+
locals:[],localNames:["_this","_this#type"],
|
2265
|
+
};
|
2256
2266
|
this.__String_prototype_toWellFormed = {
|
2257
2267
|
wasm:(_,{builtin})=>[[16,builtin('__Porffor_allocate')],[33,2],[32,0],[32,2],[16,builtin('__Porffor_clone')],[32,2],[34,3],[32,2],[40,1,0],[65,2],[108],[106],[33,4],[3,64],[32,3],[32,4],[72],[4,64],[32,3],[47,0,4],[34,5],[65,128,184,3],[78],[32,5],[65,255,191,3],[76],[113],[4,64],[32,3],[65,253,255,3],[59,0,4],[11],[32,5],[65,128,176,3],[78],[32,5],[65,255,183,3],[76],[113],[4,64],[32,3],[65,2],[106],[32,4],[72],[4,127],[32,3],[65,2],[106],[47,0,4],[65,1],[33,7],[5],[65,0],[65,1],[33,7],[11],[34,6],[65,128,184,3],[78],[32,6],[65,255,191,3],[76],[113],[4,64],[32,3],[65,2],[106],[33,3],[5],[32,3],[65,253,255,3],[59,0,4],[11],[11],[32,3],[65,2],[106],[33,3],[12,1],[11],[11],[32,2],[65,195,0],[15]],
|
2258
2268
|
params:[127,127],typedParams:1,returns:[127,127],typedReturns:1,
|
package/compiler/prototype.js
CHANGED
@@ -296,80 +296,6 @@ export const PrototypeFuncs = function() {
|
|
296
296
|
// load current string ind {arg}
|
297
297
|
[ Opcodes.i32_load16_u, Math.log2(ValtypeSize.i16) - 1, ValtypeSize.i32 ],
|
298
298
|
Opcodes.i32_from_u
|
299
|
-
],
|
300
|
-
|
301
|
-
isWellFormed: (pointer, length, _1, _2, iTmp, iTmp2) => [
|
302
|
-
// note: we cannot presume it begins as 0 in case it was used previously
|
303
|
-
...pointer,
|
304
|
-
[ Opcodes.local_set, iTmp ],
|
305
|
-
|
306
|
-
// use cached length as end pointer
|
307
|
-
...length.getCachedI32(),
|
308
|
-
...number(ValtypeSize.i16, Valtype.i32),
|
309
|
-
[ Opcodes.i32_mul ],
|
310
|
-
...pointer,
|
311
|
-
[ Opcodes.i32_add ],
|
312
|
-
...length.setCachedI32(),
|
313
|
-
|
314
|
-
[ Opcodes.loop, Blocktype.void ],
|
315
|
-
|
316
|
-
[ Opcodes.block, Blocktype.void ],
|
317
|
-
|
318
|
-
[ Opcodes.local_get, iTmp ],
|
319
|
-
[ Opcodes.i32_load16_u, Math.log2(ValtypeSize.i16) - 1, ValtypeSize.i32 ],
|
320
|
-
[ Opcodes.local_set, iTmp2 ],
|
321
|
-
|
322
|
-
// if not surrogate, continue
|
323
|
-
[ Opcodes.local_get, iTmp2 ],
|
324
|
-
...number(0xF800, Valtype.i32),
|
325
|
-
[ Opcodes.i32_and ],
|
326
|
-
...number(0xD800, Valtype.i32),
|
327
|
-
[ Opcodes.i32_ne ],
|
328
|
-
[ Opcodes.br_if, 0 ],
|
329
|
-
|
330
|
-
// if not leading surrogate, return false
|
331
|
-
[ Opcodes.local_get, iTmp2 ],
|
332
|
-
...number(0xDC00, Valtype.i32),
|
333
|
-
[ Opcodes.i32_ge_s ],
|
334
|
-
[ Opcodes.if, Blocktype.void ],
|
335
|
-
...number(0),
|
336
|
-
[ Opcodes.br, 3 ],
|
337
|
-
[ Opcodes.end ],
|
338
|
-
|
339
|
-
// if not followed by trailing surrogate, return false
|
340
|
-
[ Opcodes.local_get, iTmp ],
|
341
|
-
[ Opcodes.i32_load16_u, Math.log2(ValtypeSize.i16) - 1, ValtypeSize.i32 + ValtypeSize.i16 ],
|
342
|
-
...number(0xFC00, Valtype.i32),
|
343
|
-
[ Opcodes.i32_and ],
|
344
|
-
...number(0xDC00, Valtype.i32),
|
345
|
-
[ Opcodes.i32_ne ],
|
346
|
-
[ Opcodes.if, Blocktype.void ],
|
347
|
-
...number(0),
|
348
|
-
[ Opcodes.br, 3 ],
|
349
|
-
[ Opcodes.end ],
|
350
|
-
|
351
|
-
// bump index again since gone through two valid chars
|
352
|
-
[ Opcodes.local_get, iTmp ],
|
353
|
-
...number(ValtypeSize.i16, Valtype.i32),
|
354
|
-
[ Opcodes.i32_add ],
|
355
|
-
[ Opcodes.local_set, iTmp ],
|
356
|
-
|
357
|
-
[ Opcodes.end ],
|
358
|
-
|
359
|
-
// bump pointer and loop if not at the end
|
360
|
-
[ Opcodes.local_get, iTmp ],
|
361
|
-
...number(ValtypeSize.i16, Valtype.i32),
|
362
|
-
[ Opcodes.i32_add ],
|
363
|
-
[ Opcodes.local_tee, iTmp ],
|
364
|
-
|
365
|
-
...length.getCachedI32(), // end pointer
|
366
|
-
[ Opcodes.i32_ne ],
|
367
|
-
[ Opcodes.br_if, 0 ],
|
368
|
-
|
369
|
-
[ Opcodes.end ],
|
370
|
-
|
371
|
-
// return true
|
372
|
-
...number(1)
|
373
299
|
]
|
374
300
|
};
|
375
301
|
|
@@ -380,10 +306,6 @@ export const PrototypeFuncs = function() {
|
|
380
306
|
this[TYPES.string].charCodeAt.local = Valtype.i32;
|
381
307
|
this[TYPES.string].charCodeAt.noPointerCache = zeroChecks.charcodeat;
|
382
308
|
|
383
|
-
this[TYPES.string].isWellFormed.local = Valtype.i32;
|
384
|
-
this[TYPES.string].isWellFormed.local2 = Valtype.i32;
|
385
|
-
this[TYPES.string].isWellFormed.returnType = TYPES.boolean;
|
386
|
-
|
387
309
|
if (Prefs.bytestring) {
|
388
310
|
this[TYPES.bytestring] = {
|
389
311
|
at: (pointer, length, wIndex, wType, iTmp, _, arrayShell) => {
|
@@ -499,11 +421,6 @@ export const PrototypeFuncs = function() {
|
|
499
421
|
// load current string ind {arg}
|
500
422
|
[ Opcodes.i32_load8_u, 0, ValtypeSize.i32 ],
|
501
423
|
Opcodes.i32_from_u
|
502
|
-
],
|
503
|
-
|
504
|
-
isWellFormed: () => [
|
505
|
-
// we know it must be true as it is a bytestring lol
|
506
|
-
...number(1)
|
507
424
|
]
|
508
425
|
};
|
509
426
|
|
@@ -513,9 +430,5 @@ export const PrototypeFuncs = function() {
|
|
513
430
|
this[TYPES.bytestring].charCodeAt.returnType = TYPES.number;
|
514
431
|
this[TYPES.bytestring].charCodeAt.local = Valtype.i32;
|
515
432
|
this[TYPES.bytestring].charCodeAt.noPointerCache = zeroChecks.charcodeat;
|
516
|
-
|
517
|
-
this[TYPES.bytestring].isWellFormed.local = Valtype.i32;
|
518
|
-
this[TYPES.bytestring].isWellFormed.local2 = Valtype.i32;
|
519
|
-
this[TYPES.bytestring].isWellFormed.returnType = TYPES.boolean;
|
520
433
|
}
|
521
434
|
};
|
package/package.json
CHANGED