porffor 0.37.21 → 0.37.23
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/object.ts +2 -4
- package/compiler/builtins_precompiled.js +44 -44
- package/compiler/codegen.js +294 -289
- package/package.json +1 -1
- package/runner/index.js +1 -1
package/compiler/codegen.js
CHANGED
@@ -3166,13 +3166,14 @@ const generateVarDstr = (scope, kind, pattern, init, defaultValue, global) => {
|
|
3166
3166
|
if (prop.type == 'Property') { // let { foo } = {}
|
3167
3167
|
usedProps.push(getProperty(prop));
|
3168
3168
|
|
3169
|
+
const memberComputed = prop.computed || prop.key.type === 'Literal';
|
3169
3170
|
if (prop.value.type === 'AssignmentPattern') { // let { foo = defaultValue } = {}
|
3170
3171
|
decls.push(
|
3171
3172
|
...generateVarDstr(scope, kind, prop.value.left, {
|
3172
3173
|
type: 'MemberExpression',
|
3173
3174
|
object: { type: 'Identifier', name: tmpName },
|
3174
3175
|
property: prop.key,
|
3175
|
-
computed:
|
3176
|
+
computed: memberComputed
|
3176
3177
|
}, prop.value.right, global)
|
3177
3178
|
);
|
3178
3179
|
} else {
|
@@ -3181,7 +3182,7 @@ const generateVarDstr = (scope, kind, pattern, init, defaultValue, global) => {
|
|
3181
3182
|
type: 'MemberExpression',
|
3182
3183
|
object: { type: 'Identifier', name: tmpName },
|
3183
3184
|
property: prop.key,
|
3184
|
-
computed:
|
3185
|
+
computed: memberComputed
|
3185
3186
|
}, undefined, global)
|
3186
3187
|
);
|
3187
3188
|
}
|
@@ -3370,192 +3371,194 @@ const generateAssign = (scope, decl, _global, _name, valueUnused = false) => {
|
|
3370
3371
|
|
3371
3372
|
// todo: review last type usage here
|
3372
3373
|
...typeSwitch(scope, getNodeType(scope, object), {
|
3373
|
-
|
3374
|
-
|
3375
|
-
|
3376
|
-
|
3377
|
-
// get index as valtype
|
3378
|
-
...propertyWasm,
|
3379
|
-
Opcodes.i32_to_u,
|
3380
|
-
|
3381
|
-
// turn into byte offset by * valtypeSize + 1
|
3382
|
-
...number(ValtypeSize[valtype] + 1, Valtype.i32),
|
3383
|
-
[ Opcodes.i32_mul ],
|
3384
|
-
[ Opcodes.i32_add ],
|
3385
|
-
[ Opcodes.local_tee, pointerTmp ],
|
3386
|
-
|
3387
|
-
...(op === '=' ? generate(scope, decl.right) : performOp(scope, op, [
|
3388
|
-
[ Opcodes.local_get, pointerTmp ],
|
3389
|
-
[ Opcodes.load, 0, ValtypeSize.i32 ]
|
3390
|
-
], generate(scope, decl.right), [
|
3391
|
-
[ Opcodes.local_get, pointerTmp ],
|
3392
|
-
[ Opcodes.i32_load8_u, 0, ValtypeSize.i32 + ValtypeSize[valtype] ]
|
3393
|
-
], getNodeType(scope, decl.right), false, name, true)),
|
3394
|
-
[ Opcodes.local_tee, newValueTmp ],
|
3395
|
-
[ Opcodes.store, 0, ValtypeSize.i32 ],
|
3396
|
-
|
3397
|
-
[ Opcodes.local_get, pointerTmp ],
|
3398
|
-
...getNodeType(scope, decl),
|
3399
|
-
[ Opcodes.i32_store8, 0, ValtypeSize.i32 + ValtypeSize[valtype] ],
|
3400
|
-
|
3401
|
-
[ Opcodes.local_get, newValueTmp ]
|
3402
|
-
],
|
3403
|
-
|
3404
|
-
...wrapBC({
|
3405
|
-
[TYPES.uint8array]: () => [
|
3406
|
-
[ Opcodes.i32_add ],
|
3407
|
-
...(op === '=' ? [] : [ [ Opcodes.local_tee, pointerTmp ] ]),
|
3408
|
-
|
3409
|
-
...(op === '=' ? generate(scope, decl.right) : performOp(scope, op, [
|
3410
|
-
[ Opcodes.local_get, pointerTmp ],
|
3411
|
-
[ Opcodes.i32_load8_u, 0, 4 ],
|
3412
|
-
Opcodes.i32_from_u
|
3413
|
-
], generate(scope, decl.right), number(TYPES.number, Valtype.i32), getNodeType(scope, decl.right), false, name, true)),
|
3414
|
-
[ Opcodes.local_tee, newValueTmp ],
|
3415
|
-
|
3374
|
+
...(decl.left.computed ? {
|
3375
|
+
[TYPES.array]: () => [
|
3376
|
+
...objectWasm,
|
3416
3377
|
Opcodes.i32_to_u,
|
3417
|
-
[ Opcodes.i32_store8, 0, 4 ]
|
3418
|
-
],
|
3419
|
-
[TYPES.uint8clampedarray]: () => [
|
3420
|
-
[ Opcodes.i32_add ],
|
3421
|
-
...(op === '=' ? [] : [ [ Opcodes.local_tee, pointerTmp ] ]),
|
3422
|
-
|
3423
|
-
...(op === '=' ? generate(scope, decl.right) : performOp(scope, op, [
|
3424
|
-
[ Opcodes.local_get, pointerTmp ],
|
3425
|
-
[ Opcodes.i32_load8_u, 0, 4 ],
|
3426
|
-
Opcodes.i32_from_u
|
3427
|
-
], generate(scope, decl.right), number(TYPES.number, Valtype.i32), getNodeType(scope, decl.right), false, name, true)),
|
3428
|
-
[ Opcodes.local_tee, newValueTmp ],
|
3429
3378
|
|
3430
|
-
|
3431
|
-
|
3432
|
-
...number(255),
|
3433
|
-
[ Opcodes.f64_min ],
|
3379
|
+
// get index as valtype
|
3380
|
+
...propertyWasm,
|
3434
3381
|
Opcodes.i32_to_u,
|
3435
|
-
[ Opcodes.i32_store8, 0, 4 ]
|
3436
|
-
],
|
3437
|
-
[TYPES.int8array]: () => [
|
3438
|
-
[ Opcodes.i32_add ],
|
3439
|
-
...(op === '=' ? [] : [ [ Opcodes.local_tee, pointerTmp ] ]),
|
3440
3382
|
|
3441
|
-
|
3442
|
-
|
3443
|
-
[ Opcodes.i32_load8_s, 0, 4 ],
|
3444
|
-
Opcodes.i32_from
|
3445
|
-
], generate(scope, decl.right), number(TYPES.number, Valtype.i32), getNodeType(scope, decl.right), false, name, true)),
|
3446
|
-
[ Opcodes.local_tee, newValueTmp ],
|
3447
|
-
|
3448
|
-
Opcodes.i32_to,
|
3449
|
-
[ Opcodes.i32_store8, 0, 4 ]
|
3450
|
-
],
|
3451
|
-
[TYPES.uint16array]: () => [
|
3452
|
-
...number(2, Valtype.i32),
|
3383
|
+
// turn into byte offset by * valtypeSize + 1
|
3384
|
+
...number(ValtypeSize[valtype] + 1, Valtype.i32),
|
3453
3385
|
[ Opcodes.i32_mul ],
|
3454
3386
|
[ Opcodes.i32_add ],
|
3455
|
-
|
3387
|
+
[ Opcodes.local_tee, pointerTmp ],
|
3456
3388
|
|
3457
3389
|
...(op === '=' ? generate(scope, decl.right) : performOp(scope, op, [
|
3458
3390
|
[ Opcodes.local_get, pointerTmp ],
|
3459
|
-
[ Opcodes.
|
3460
|
-
|
3461
|
-
], generate(scope, decl.right), number(TYPES.number, Valtype.i32), getNodeType(scope, decl.right), false, name, true)),
|
3462
|
-
[ Opcodes.local_tee, newValueTmp ],
|
3463
|
-
|
3464
|
-
Opcodes.i32_to_u,
|
3465
|
-
[ Opcodes.i32_store16, 0, 4 ]
|
3466
|
-
],
|
3467
|
-
[TYPES.int16array]: () => [
|
3468
|
-
...number(2, Valtype.i32),
|
3469
|
-
[ Opcodes.i32_mul ],
|
3470
|
-
[ Opcodes.i32_add ],
|
3471
|
-
...(op === '=' ? [] : [ [ Opcodes.local_tee, pointerTmp ] ]),
|
3472
|
-
|
3473
|
-
...(op === '=' ? generate(scope, decl.right) : performOp(scope, op, [
|
3391
|
+
[ Opcodes.load, 0, ValtypeSize.i32 ]
|
3392
|
+
], generate(scope, decl.right), [
|
3474
3393
|
[ Opcodes.local_get, pointerTmp ],
|
3475
|
-
[ Opcodes.
|
3476
|
-
|
3477
|
-
], generate(scope, decl.right), number(TYPES.number, Valtype.i32), getNodeType(scope, decl.right), false, name, true)),
|
3394
|
+
[ Opcodes.i32_load8_u, 0, ValtypeSize.i32 + ValtypeSize[valtype] ]
|
3395
|
+
], getNodeType(scope, decl.right), false, name, true)),
|
3478
3396
|
[ Opcodes.local_tee, newValueTmp ],
|
3397
|
+
[ Opcodes.store, 0, ValtypeSize.i32 ],
|
3398
|
+
|
3399
|
+
[ Opcodes.local_get, pointerTmp ],
|
3400
|
+
...getNodeType(scope, decl),
|
3401
|
+
[ Opcodes.i32_store8, 0, ValtypeSize.i32 + ValtypeSize[valtype] ],
|
3479
3402
|
|
3480
|
-
Opcodes.
|
3481
|
-
[ Opcodes.i32_store16, 0, 4 ]
|
3403
|
+
[ Opcodes.local_get, newValueTmp ]
|
3482
3404
|
],
|
3483
|
-
[TYPES.uint32array]: () => [
|
3484
|
-
...number(4, Valtype.i32),
|
3485
|
-
[ Opcodes.i32_mul ],
|
3486
|
-
[ Opcodes.i32_add ],
|
3487
|
-
...(op === '=' ? [] : [ [ Opcodes.local_tee, pointerTmp ] ]),
|
3488
3405
|
|
3489
|
-
|
3490
|
-
|
3491
|
-
[ Opcodes.
|
3492
|
-
Opcodes.
|
3493
|
-
], generate(scope, decl.right), number(TYPES.number, Valtype.i32), getNodeType(scope, decl.right), false, name, true)),
|
3494
|
-
[ Opcodes.local_tee, newValueTmp ],
|
3406
|
+
...wrapBC({
|
3407
|
+
[TYPES.uint8array]: () => [
|
3408
|
+
[ Opcodes.i32_add ],
|
3409
|
+
...(op === '=' ? [] : [ [ Opcodes.local_tee, pointerTmp ] ]),
|
3495
3410
|
|
3496
|
-
|
3497
|
-
|
3498
|
-
|
3499
|
-
|
3500
|
-
|
3501
|
-
|
3502
|
-
[ Opcodes.i32_add ],
|
3503
|
-
...(op === '=' ? [] : [ [ Opcodes.local_tee, pointerTmp ] ]),
|
3411
|
+
...(op === '=' ? generate(scope, decl.right) : performOp(scope, op, [
|
3412
|
+
[ Opcodes.local_get, pointerTmp ],
|
3413
|
+
[ Opcodes.i32_load8_u, 0, 4 ],
|
3414
|
+
Opcodes.i32_from_u
|
3415
|
+
], generate(scope, decl.right), number(TYPES.number, Valtype.i32), getNodeType(scope, decl.right), false, name, true)),
|
3416
|
+
[ Opcodes.local_tee, newValueTmp ],
|
3504
3417
|
|
3505
|
-
|
3506
|
-
[ Opcodes.
|
3507
|
-
|
3508
|
-
|
3509
|
-
|
3510
|
-
|
3418
|
+
Opcodes.i32_to_u,
|
3419
|
+
[ Opcodes.i32_store8, 0, 4 ]
|
3420
|
+
],
|
3421
|
+
[TYPES.uint8clampedarray]: () => [
|
3422
|
+
[ Opcodes.i32_add ],
|
3423
|
+
...(op === '=' ? [] : [ [ Opcodes.local_tee, pointerTmp ] ]),
|
3424
|
+
|
3425
|
+
...(op === '=' ? generate(scope, decl.right) : performOp(scope, op, [
|
3426
|
+
[ Opcodes.local_get, pointerTmp ],
|
3427
|
+
[ Opcodes.i32_load8_u, 0, 4 ],
|
3428
|
+
Opcodes.i32_from_u
|
3429
|
+
], generate(scope, decl.right), number(TYPES.number, Valtype.i32), getNodeType(scope, decl.right), false, name, true)),
|
3430
|
+
[ Opcodes.local_tee, newValueTmp ],
|
3431
|
+
|
3432
|
+
...number(0),
|
3433
|
+
[ Opcodes.f64_max ],
|
3434
|
+
...number(255),
|
3435
|
+
[ Opcodes.f64_min ],
|
3436
|
+
Opcodes.i32_to_u,
|
3437
|
+
[ Opcodes.i32_store8, 0, 4 ]
|
3438
|
+
],
|
3439
|
+
[TYPES.int8array]: () => [
|
3440
|
+
[ Opcodes.i32_add ],
|
3441
|
+
...(op === '=' ? [] : [ [ Opcodes.local_tee, pointerTmp ] ]),
|
3442
|
+
|
3443
|
+
...(op === '=' ? generate(scope, decl.right) : performOp(scope, op, [
|
3444
|
+
[ Opcodes.local_get, pointerTmp ],
|
3445
|
+
[ Opcodes.i32_load8_s, 0, 4 ],
|
3446
|
+
Opcodes.i32_from
|
3447
|
+
], generate(scope, decl.right), number(TYPES.number, Valtype.i32), getNodeType(scope, decl.right), false, name, true)),
|
3448
|
+
[ Opcodes.local_tee, newValueTmp ],
|
3449
|
+
|
3450
|
+
Opcodes.i32_to,
|
3451
|
+
[ Opcodes.i32_store8, 0, 4 ]
|
3452
|
+
],
|
3453
|
+
[TYPES.uint16array]: () => [
|
3454
|
+
...number(2, Valtype.i32),
|
3455
|
+
[ Opcodes.i32_mul ],
|
3456
|
+
[ Opcodes.i32_add ],
|
3457
|
+
...(op === '=' ? [] : [ [ Opcodes.local_tee, pointerTmp ] ]),
|
3511
3458
|
|
3512
|
-
|
3513
|
-
|
3514
|
-
|
3515
|
-
|
3516
|
-
|
3517
|
-
|
3518
|
-
[ Opcodes.i32_add ],
|
3519
|
-
...(op === '=' ? [] : [ [ Opcodes.local_tee, pointerTmp ] ]),
|
3459
|
+
...(op === '=' ? generate(scope, decl.right) : performOp(scope, op, [
|
3460
|
+
[ Opcodes.local_get, pointerTmp ],
|
3461
|
+
[ Opcodes.i32_load16_u, 0, 4 ],
|
3462
|
+
Opcodes.i32_from_u
|
3463
|
+
], generate(scope, decl.right), number(TYPES.number, Valtype.i32), getNodeType(scope, decl.right), false, name, true)),
|
3464
|
+
[ Opcodes.local_tee, newValueTmp ],
|
3520
3465
|
|
3521
|
-
|
3522
|
-
[ Opcodes.
|
3523
|
-
|
3524
|
-
|
3525
|
-
|
3526
|
-
|
3466
|
+
Opcodes.i32_to_u,
|
3467
|
+
[ Opcodes.i32_store16, 0, 4 ]
|
3468
|
+
],
|
3469
|
+
[TYPES.int16array]: () => [
|
3470
|
+
...number(2, Valtype.i32),
|
3471
|
+
[ Opcodes.i32_mul ],
|
3472
|
+
[ Opcodes.i32_add ],
|
3473
|
+
...(op === '=' ? [] : [ [ Opcodes.local_tee, pointerTmp ] ]),
|
3474
|
+
|
3475
|
+
...(op === '=' ? generate(scope, decl.right) : performOp(scope, op, [
|
3476
|
+
[ Opcodes.local_get, pointerTmp ],
|
3477
|
+
[ Opcodes.i32_load16_s, 0, 4 ],
|
3478
|
+
Opcodes.i32_from
|
3479
|
+
], generate(scope, decl.right), number(TYPES.number, Valtype.i32), getNodeType(scope, decl.right), false, name, true)),
|
3480
|
+
[ Opcodes.local_tee, newValueTmp ],
|
3481
|
+
|
3482
|
+
Opcodes.i32_to,
|
3483
|
+
[ Opcodes.i32_store16, 0, 4 ]
|
3484
|
+
],
|
3485
|
+
[TYPES.uint32array]: () => [
|
3486
|
+
...number(4, Valtype.i32),
|
3487
|
+
[ Opcodes.i32_mul ],
|
3488
|
+
[ Opcodes.i32_add ],
|
3489
|
+
...(op === '=' ? [] : [ [ Opcodes.local_tee, pointerTmp ] ]),
|
3527
3490
|
|
3528
|
-
|
3529
|
-
|
3530
|
-
|
3531
|
-
|
3532
|
-
|
3533
|
-
|
3534
|
-
[ Opcodes.i32_add ],
|
3535
|
-
...(op === '=' ? [] : [ [ Opcodes.local_tee, pointerTmp ] ]),
|
3491
|
+
...(op === '=' ? generate(scope, decl.right) : performOp(scope, op, [
|
3492
|
+
[ Opcodes.local_get, pointerTmp ],
|
3493
|
+
[ Opcodes.i32_load, 0, 4 ],
|
3494
|
+
Opcodes.i32_from_u
|
3495
|
+
], generate(scope, decl.right), number(TYPES.number, Valtype.i32), getNodeType(scope, decl.right), false, name, true)),
|
3496
|
+
[ Opcodes.local_tee, newValueTmp ],
|
3536
3497
|
|
3537
|
-
|
3538
|
-
[ Opcodes.
|
3539
|
-
|
3540
|
-
|
3541
|
-
|
3498
|
+
Opcodes.i32_to_u,
|
3499
|
+
[ Opcodes.i32_store, 0, 4 ]
|
3500
|
+
],
|
3501
|
+
[TYPES.int32array]: () => [
|
3502
|
+
...number(4, Valtype.i32),
|
3503
|
+
[ Opcodes.i32_mul ],
|
3504
|
+
[ Opcodes.i32_add ],
|
3505
|
+
...(op === '=' ? [] : [ [ Opcodes.local_tee, pointerTmp ] ]),
|
3506
|
+
|
3507
|
+
...(op === '=' ? generate(scope, decl.right) : performOp(scope, op, [
|
3508
|
+
[ Opcodes.local_get, pointerTmp ],
|
3509
|
+
[ Opcodes.i32_load, 0, 4 ],
|
3510
|
+
Opcodes.i32_from
|
3511
|
+
], generate(scope, decl.right), number(TYPES.number, Valtype.i32), getNodeType(scope, decl.right), false, name, true)),
|
3512
|
+
[ Opcodes.local_tee, newValueTmp ],
|
3513
|
+
|
3514
|
+
Opcodes.i32_to,
|
3515
|
+
[ Opcodes.i32_store, 0, 4 ]
|
3516
|
+
],
|
3517
|
+
[TYPES.float32array]: () => [
|
3518
|
+
...number(4, Valtype.i32),
|
3519
|
+
[ Opcodes.i32_mul ],
|
3520
|
+
[ Opcodes.i32_add ],
|
3521
|
+
...(op === '=' ? [] : [ [ Opcodes.local_tee, pointerTmp ] ]),
|
3522
|
+
|
3523
|
+
...(op === '=' ? generate(scope, decl.right) : performOp(scope, op, [
|
3524
|
+
[ Opcodes.local_get, pointerTmp ],
|
3525
|
+
[ Opcodes.f32_load, 0, 4 ],
|
3526
|
+
[ Opcodes.f64_promote_f32 ]
|
3527
|
+
], generate(scope, decl.right), number(TYPES.number, Valtype.i32), getNodeType(scope, decl.right), false, name, true)),
|
3528
|
+
[ Opcodes.local_tee, newValueTmp ],
|
3529
|
+
|
3530
|
+
[ Opcodes.f32_demote_f64 ],
|
3531
|
+
[ Opcodes.f32_store, 0, 4 ]
|
3532
|
+
],
|
3533
|
+
[TYPES.float64array]: () => [
|
3534
|
+
...number(8, Valtype.i32),
|
3535
|
+
[ Opcodes.i32_mul ],
|
3536
|
+
[ Opcodes.i32_add ],
|
3537
|
+
...(op === '=' ? [] : [ [ Opcodes.local_tee, pointerTmp ] ]),
|
3542
3538
|
|
3543
|
-
|
3544
|
-
|
3545
|
-
|
3546
|
-
|
3547
|
-
|
3548
|
-
Opcodes.i32_to_u,
|
3549
|
-
[ Opcodes.i32_load, 0, 4 ],
|
3539
|
+
...(op === '=' ? generate(scope, decl.right) : performOp(scope, op, [
|
3540
|
+
[ Opcodes.local_get, pointerTmp ],
|
3541
|
+
[ Opcodes.f64_load, 0, 4 ]
|
3542
|
+
], generate(scope, decl.right), number(TYPES.number, Valtype.i32), getNodeType(scope, decl.right), false, name, true)),
|
3543
|
+
[ Opcodes.local_tee, newValueTmp ],
|
3550
3544
|
|
3551
|
-
|
3552
|
-
|
3553
|
-
|
3554
|
-
|
3555
|
-
|
3556
|
-
|
3557
|
-
|
3558
|
-
|
3545
|
+
[ Opcodes.f64_store, 0, 4 ]
|
3546
|
+
],
|
3547
|
+
}, {
|
3548
|
+
prelude: [
|
3549
|
+
...objectWasm,
|
3550
|
+
Opcodes.i32_to_u,
|
3551
|
+
[ Opcodes.i32_load, 0, 4 ],
|
3552
|
+
|
3553
|
+
...propertyWasm,
|
3554
|
+
Opcodes.i32_to_u,
|
3555
|
+
],
|
3556
|
+
postlude: [
|
3557
|
+
// setLastType(scope, TYPES.number)
|
3558
|
+
[ Opcodes.local_get, newValueTmp ]
|
3559
|
+
]
|
3560
|
+
}),
|
3561
|
+
} : {}),
|
3559
3562
|
|
3560
3563
|
[TYPES.undefined]: internalThrow(scope, 'TypeError', 'Cannot set property of undefined', true),
|
3561
3564
|
|
@@ -4014,11 +4017,11 @@ const generateForOf = (scope, decl) => {
|
|
4014
4017
|
let setVar;
|
4015
4018
|
if (decl.left.type === 'Identifier') {
|
4016
4019
|
if (scope.strict) return internalThrow(scope, 'ReferenceError', `${decl.left.name} is not defined`);
|
4017
|
-
setVar = generateVarDstr(scope,
|
4020
|
+
setVar = generateVarDstr(scope, decl.left.kind, decl.left, { type: 'Identifier', name: tmpName }, undefined, true);
|
4018
4021
|
} else {
|
4019
4022
|
// todo: verify this is correct
|
4020
4023
|
const global = scope.name === 'main' && decl.left.kind === 'var';
|
4021
|
-
setVar = generateVarDstr(scope,
|
4024
|
+
setVar = generateVarDstr(scope, decl.left.kind, decl.left?.declarations?.[0]?.id ?? decl.left, { type: 'Identifier', name: tmpName }, undefined, global);
|
4022
4025
|
}
|
4023
4026
|
|
4024
4027
|
|
@@ -4372,11 +4375,11 @@ const generateForIn = (scope, decl) => {
|
|
4372
4375
|
let setVar;
|
4373
4376
|
if (decl.left.type === 'Identifier') {
|
4374
4377
|
if (scope.strict) return internalThrow(scope, 'ReferenceError', `${decl.left.name} is not defined`);
|
4375
|
-
setVar = generateVarDstr(scope,
|
4378
|
+
setVar = generateVarDstr(scope, decl.left.kind, decl.left, { type: 'Identifier', name: tmpName }, undefined, true);
|
4376
4379
|
} else {
|
4377
4380
|
// todo: verify this is correct
|
4378
4381
|
const global = scope.name === 'main' && decl.left.kind === 'var';
|
4379
|
-
setVar = generateVarDstr(scope,
|
4382
|
+
setVar = generateVarDstr(scope, decl.left.kind, decl.left?.declarations?.[0]?.id ?? decl.left, { type: 'Identifier', name: tmpName }, undefined, global);
|
4380
4383
|
}
|
4381
4384
|
|
4382
4385
|
// set type for local
|
@@ -5416,153 +5419,155 @@ const generateMember = (scope, decl, _global, _name, _objectWasm = undefined) =>
|
|
5416
5419
|
const propertyWasm = [ [ Opcodes.local_get, localTmp(scope, '#member_prop') ] ];
|
5417
5420
|
|
5418
5421
|
const out = typeSwitch(scope, getNodeType(scope, object), {
|
5419
|
-
|
5420
|
-
|
5421
|
-
|
5422
|
-
|
5422
|
+
...(decl.computed ? {
|
5423
|
+
[TYPES.array]: () => [
|
5424
|
+
...loadArray(scope, objectWasm, propertyWasm),
|
5425
|
+
...setLastType(scope)
|
5426
|
+
],
|
5423
5427
|
|
5424
|
-
|
5425
|
-
|
5426
|
-
|
5427
|
-
|
5428
|
+
[TYPES.string]: () => [
|
5429
|
+
// allocate out string
|
5430
|
+
[ Opcodes.call, includeBuiltin(scope, '__Porffor_allocate').index ],
|
5431
|
+
[ Opcodes.local_tee, localTmp(scope, '#member_allocd', Valtype.i32) ],
|
5428
5432
|
|
5429
|
-
|
5430
|
-
|
5431
|
-
|
5433
|
+
// set length to 1
|
5434
|
+
...number(1, Valtype.i32),
|
5435
|
+
[ Opcodes.i32_store, 0, 0 ],
|
5432
5436
|
|
5433
|
-
|
5434
|
-
|
5437
|
+
// use as pointer for store later
|
5438
|
+
[ Opcodes.local_get, localTmp(scope, '#member_allocd', Valtype.i32) ],
|
5435
5439
|
|
5436
|
-
|
5437
|
-
|
5440
|
+
...propertyWasm,
|
5441
|
+
Opcodes.i32_to_u,
|
5438
5442
|
|
5439
|
-
|
5440
|
-
|
5443
|
+
...number(ValtypeSize.i16, Valtype.i32),
|
5444
|
+
[ Opcodes.i32_mul ],
|
5441
5445
|
|
5442
|
-
|
5443
|
-
|
5444
|
-
|
5446
|
+
...objectWasm,
|
5447
|
+
Opcodes.i32_to_u,
|
5448
|
+
[ Opcodes.i32_add ],
|
5445
5449
|
|
5446
|
-
|
5447
|
-
|
5450
|
+
// load current string ind {arg}
|
5451
|
+
[ Opcodes.i32_load16_u, Math.log2(ValtypeSize.i16) - 1, ValtypeSize.i32 ],
|
5448
5452
|
|
5449
|
-
|
5450
|
-
|
5453
|
+
// store to new string ind 0
|
5454
|
+
[ Opcodes.i32_store16, Math.log2(ValtypeSize.i16) - 1, ValtypeSize.i32 ],
|
5451
5455
|
|
5452
|
-
|
5453
|
-
|
5454
|
-
|
5455
|
-
|
5456
|
-
|
5456
|
+
// return new string (page)
|
5457
|
+
[ Opcodes.local_get, localTmp(scope, '#member_allocd', Valtype.i32) ],
|
5458
|
+
Opcodes.i32_from_u,
|
5459
|
+
...setLastType(scope, TYPES.string)
|
5460
|
+
],
|
5457
5461
|
|
5458
|
-
|
5459
|
-
|
5460
|
-
|
5461
|
-
|
5462
|
+
[TYPES.bytestring]: () => [
|
5463
|
+
// allocate out string
|
5464
|
+
[ Opcodes.call, includeBuiltin(scope, '__Porffor_allocate').index ],
|
5465
|
+
[ Opcodes.local_tee, localTmp(scope, '#member_allocd', Valtype.i32) ],
|
5462
5466
|
|
5463
|
-
|
5464
|
-
|
5465
|
-
|
5467
|
+
// set length to 1
|
5468
|
+
...number(1, Valtype.i32),
|
5469
|
+
[ Opcodes.i32_store, 0, 0 ],
|
5466
5470
|
|
5467
|
-
|
5468
|
-
|
5471
|
+
// use as pointer for store later
|
5472
|
+
[ Opcodes.local_get, localTmp(scope, '#member_allocd', Valtype.i32) ],
|
5469
5473
|
|
5470
|
-
|
5471
|
-
|
5474
|
+
...propertyWasm,
|
5475
|
+
Opcodes.i32_to_u,
|
5472
5476
|
|
5473
|
-
|
5474
|
-
|
5475
|
-
|
5477
|
+
...objectWasm,
|
5478
|
+
Opcodes.i32_to_u,
|
5479
|
+
[ Opcodes.i32_add ],
|
5476
5480
|
|
5477
|
-
|
5478
|
-
|
5481
|
+
// load current string ind {arg}
|
5482
|
+
[ Opcodes.i32_load8_u, 0, ValtypeSize.i32 ],
|
5479
5483
|
|
5480
|
-
|
5481
|
-
|
5484
|
+
// store to new string ind 0
|
5485
|
+
[ Opcodes.i32_store8, 0, ValtypeSize.i32 ],
|
5482
5486
|
|
5483
|
-
|
5484
|
-
|
5485
|
-
|
5486
|
-
|
5487
|
-
|
5487
|
+
// return new string (page)
|
5488
|
+
[ Opcodes.local_get, localTmp(scope, '#member_allocd', Valtype.i32) ],
|
5489
|
+
Opcodes.i32_from_u,
|
5490
|
+
...setLastType(scope, TYPES.bytestring)
|
5491
|
+
],
|
5488
5492
|
|
5489
|
-
|
5490
|
-
|
5491
|
-
|
5493
|
+
...wrapBC({
|
5494
|
+
[TYPES.uint8array]: [
|
5495
|
+
[ Opcodes.i32_add ],
|
5492
5496
|
|
5493
|
-
|
5494
|
-
|
5495
|
-
|
5496
|
-
|
5497
|
-
|
5497
|
+
[ Opcodes.i32_load8_u, 0, 4 ],
|
5498
|
+
Opcodes.i32_from_u
|
5499
|
+
],
|
5500
|
+
[TYPES.uint8clampedarray]: [
|
5501
|
+
[ Opcodes.i32_add ],
|
5498
5502
|
|
5499
|
-
|
5500
|
-
|
5501
|
-
|
5502
|
-
|
5503
|
-
|
5503
|
+
[ Opcodes.i32_load8_u, 0, 4 ],
|
5504
|
+
Opcodes.i32_from_u
|
5505
|
+
],
|
5506
|
+
[TYPES.int8array]: [
|
5507
|
+
[ Opcodes.i32_add ],
|
5504
5508
|
|
5505
|
-
|
5506
|
-
|
5507
|
-
|
5508
|
-
|
5509
|
-
|
5510
|
-
|
5511
|
-
|
5509
|
+
[ Opcodes.i32_load8_s, 0, 4 ],
|
5510
|
+
Opcodes.i32_from
|
5511
|
+
],
|
5512
|
+
[TYPES.uint16array]: [
|
5513
|
+
...number(2, Valtype.i32),
|
5514
|
+
[ Opcodes.i32_mul ],
|
5515
|
+
[ Opcodes.i32_add ],
|
5512
5516
|
|
5513
|
-
|
5514
|
-
|
5515
|
-
|
5516
|
-
|
5517
|
-
|
5518
|
-
|
5519
|
-
|
5517
|
+
[ Opcodes.i32_load16_u, 0, 4 ],
|
5518
|
+
Opcodes.i32_from_u
|
5519
|
+
],
|
5520
|
+
[TYPES.int16array]: [
|
5521
|
+
...number(2, Valtype.i32),
|
5522
|
+
[ Opcodes.i32_mul ],
|
5523
|
+
[ Opcodes.i32_add ],
|
5520
5524
|
|
5521
|
-
|
5522
|
-
|
5523
|
-
|
5524
|
-
|
5525
|
-
|
5526
|
-
|
5527
|
-
|
5525
|
+
[ Opcodes.i32_load16_s, 0, 4 ],
|
5526
|
+
Opcodes.i32_from
|
5527
|
+
],
|
5528
|
+
[TYPES.uint32array]: [
|
5529
|
+
...number(4, Valtype.i32),
|
5530
|
+
[ Opcodes.i32_mul ],
|
5531
|
+
[ Opcodes.i32_add ],
|
5528
5532
|
|
5529
|
-
|
5530
|
-
|
5531
|
-
|
5532
|
-
|
5533
|
-
|
5534
|
-
|
5535
|
-
|
5533
|
+
[ Opcodes.i32_load, 0, 4 ],
|
5534
|
+
Opcodes.i32_from_u
|
5535
|
+
],
|
5536
|
+
[TYPES.int32array]: [
|
5537
|
+
...number(4, Valtype.i32),
|
5538
|
+
[ Opcodes.i32_mul ],
|
5539
|
+
[ Opcodes.i32_add ],
|
5536
5540
|
|
5537
|
-
|
5538
|
-
|
5539
|
-
|
5540
|
-
|
5541
|
-
|
5542
|
-
|
5543
|
-
|
5541
|
+
[ Opcodes.i32_load, 0, 4 ],
|
5542
|
+
Opcodes.i32_from
|
5543
|
+
],
|
5544
|
+
[TYPES.float32array]: [
|
5545
|
+
...number(4, Valtype.i32),
|
5546
|
+
[ Opcodes.i32_mul ],
|
5547
|
+
[ Opcodes.i32_add ],
|
5544
5548
|
|
5545
|
-
|
5546
|
-
|
5547
|
-
|
5548
|
-
|
5549
|
-
|
5550
|
-
|
5551
|
-
|
5549
|
+
[ Opcodes.f32_load, 0, 4 ],
|
5550
|
+
[ Opcodes.f64_promote_f32 ]
|
5551
|
+
],
|
5552
|
+
[TYPES.float64array]: [
|
5553
|
+
...number(8, Valtype.i32),
|
5554
|
+
[ Opcodes.i32_mul ],
|
5555
|
+
[ Opcodes.i32_add ],
|
5552
5556
|
|
5553
|
-
|
5554
|
-
|
5555
|
-
|
5556
|
-
|
5557
|
-
|
5558
|
-
|
5559
|
-
|
5557
|
+
[ Opcodes.f64_load, 0, 4 ]
|
5558
|
+
],
|
5559
|
+
}, {
|
5560
|
+
prelude: [
|
5561
|
+
...objectWasm,
|
5562
|
+
Opcodes.i32_to_u,
|
5563
|
+
[ Opcodes.i32_load, 0, 4 ],
|
5560
5564
|
|
5561
|
-
|
5562
|
-
|
5563
|
-
|
5564
|
-
|
5565
|
-
|
5565
|
+
...propertyWasm,
|
5566
|
+
Opcodes.i32_to_u
|
5567
|
+
],
|
5568
|
+
postlude: setLastType(scope, TYPES.number)
|
5569
|
+
}),
|
5570
|
+
} : {}),
|
5566
5571
|
|
5567
5572
|
[TYPES.undefined]: internalThrow(scope, 'TypeError', 'Cannot read property of undefined', true),
|
5568
5573
|
|