porffor 0.49.5 → 0.49.6
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/console.ts +8 -6
- package/compiler/builtins/math.ts +49 -11
- package/compiler/builtins_precompiled.js +752 -752
- package/compiler/codegen.js +58 -52
- package/compiler/precompile.js +1 -1
- package/package.json +1 -1
- package/richards.js +91 -129
- package/runner/index.js +1 -1
package/compiler/codegen.js
CHANGED
@@ -622,7 +622,6 @@ const performLogicOp = (scope, op, left, right, leftType, rightType) => {
|
|
622
622
|
if (!checks[op]) return todo(scope, `logic operator ${op} not implemented yet`, true);
|
623
623
|
|
624
624
|
// generic structure for {a} OP {b}
|
625
|
-
// -->
|
626
625
|
// _ = {a}; if (OP_CHECK) {b} else _
|
627
626
|
|
628
627
|
// if we can, use int tmp and convert at the end to help prevent unneeded conversions
|
@@ -1891,7 +1890,6 @@ const createThisArg = (scope, decl) => {
|
|
1891
1890
|
// create new object with __proto__ set to callee prototype
|
1892
1891
|
const tmp = localTmp(scope, '#this_create_tmp');
|
1893
1892
|
const proto = getObjProp(decl.callee, 'prototype');
|
1894
|
-
localTmp(scope, '#member_prop_assign');
|
1895
1893
|
|
1896
1894
|
return [
|
1897
1895
|
...makeObject(scope, {}),
|
@@ -1903,7 +1901,7 @@ const createThisArg = (scope, decl) => {
|
|
1903
1901
|
...generate(scope, {
|
1904
1902
|
type: 'Literal',
|
1905
1903
|
value: '__proto__'
|
1906
|
-
}
|
1904
|
+
}),
|
1907
1905
|
Opcodes.i32_to_u,
|
1908
1906
|
...number(TYPES.bytestring, Valtype.i32),
|
1909
1907
|
|
@@ -2418,12 +2416,14 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
|
|
2418
2416
|
}
|
2419
2417
|
|
2420
2418
|
let knownThis = undefined, getCallee = undefined;
|
2421
|
-
|
2419
|
+
|
2420
|
+
const tmpName = '#indirect' + uniqId() + '_';
|
2421
|
+
const calleeLocal = localTmp(scope, tmpName + 'callee');
|
2422
2422
|
|
2423
2423
|
// hack: this should be more thorough, Function.bind, etc
|
2424
2424
|
if (decl.callee.type === 'MemberExpression' && !decl._new) {
|
2425
|
-
const thisLocal = localTmp(scope, '
|
2426
|
-
const thisLocalType = localTmp(scope, '#
|
2425
|
+
const thisLocal = localTmp(scope, tmpName + 'caller');
|
2426
|
+
const thisLocalType = localTmp(scope, tmpName + 'caller#type', Valtype.i32);
|
2427
2427
|
|
2428
2428
|
knownThis = [
|
2429
2429
|
[ Opcodes.local_get, thisLocal ],
|
@@ -2437,7 +2437,7 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
|
|
2437
2437
|
|
2438
2438
|
...generate(scope, {
|
2439
2439
|
type: 'MemberExpression',
|
2440
|
-
object: { type: 'Identifier', name: '
|
2440
|
+
object: { type: 'Identifier', name: tmpName + 'caller' },
|
2441
2441
|
property: decl.callee.property,
|
2442
2442
|
computed: decl.callee.computed,
|
2443
2443
|
optional: decl.callee.optional
|
@@ -3363,6 +3363,23 @@ const isIdentAssignable = (scope, name, op = '=') => {
|
|
3363
3363
|
return false;
|
3364
3364
|
};
|
3365
3365
|
|
3366
|
+
const memberTmpNames = scope => {
|
3367
|
+
const id = uniqId();
|
3368
|
+
|
3369
|
+
const objectTmpName = '#member_obj' + id;
|
3370
|
+
const objectTmp = localTmp(scope, objectTmpName);
|
3371
|
+
|
3372
|
+
const propTmpName = '#member_prop' + id;
|
3373
|
+
const propertyTmp = localTmp(scope, propTmpName);
|
3374
|
+
|
3375
|
+
return {
|
3376
|
+
objectTmpName, propTmpName,
|
3377
|
+
objectTmp, propertyTmp,
|
3378
|
+
objectGet: [ Opcodes.local_get, localTmp(scope, objectTmpName) ],
|
3379
|
+
propertyGet: [ Opcodes.local_get, localTmp(scope, propTmpName) ]
|
3380
|
+
};
|
3381
|
+
};
|
3382
|
+
|
3366
3383
|
const generateAssign = (scope, decl, _global, _name, valueUnused = false) => {
|
3367
3384
|
const { type, name } = decl.left;
|
3368
3385
|
const [ local, isGlobal ] = lookupName(scope, name);
|
@@ -3454,25 +3471,24 @@ const generateAssign = (scope, decl, _global, _name, valueUnused = false) => {
|
|
3454
3471
|
const property = getProperty(decl.left);
|
3455
3472
|
|
3456
3473
|
// todo/perf: use i32 object (and prop?) locals
|
3457
|
-
const
|
3458
|
-
const propertyWasm = [ [ Opcodes.local_get, localTmp(scope, '#member_prop_assign') ] ];
|
3474
|
+
const { objectTmp, propertyTmp, objectGet, propertyGet } = memberTmpNames(scope);
|
3459
3475
|
|
3460
3476
|
return [
|
3461
3477
|
...generate(scope, object),
|
3462
|
-
[ Opcodes.local_set,
|
3478
|
+
[ Opcodes.local_set, objectTmp ],
|
3463
3479
|
|
3464
|
-
...generate(scope, property
|
3465
|
-
[ Opcodes.local_set,
|
3480
|
+
...generate(scope, property),
|
3481
|
+
[ Opcodes.local_set, propertyTmp ],
|
3466
3482
|
|
3467
3483
|
// todo: review last type usage here
|
3468
3484
|
...typeSwitch(scope, getNodeType(scope, object), {
|
3469
3485
|
...(decl.left.computed ? {
|
3470
3486
|
[TYPES.array]: () => [
|
3471
|
-
|
3487
|
+
objectGet,
|
3472
3488
|
Opcodes.i32_to_u,
|
3473
3489
|
|
3474
3490
|
// get index as valtype
|
3475
|
-
|
3491
|
+
propertyGet,
|
3476
3492
|
Opcodes.i32_to_u,
|
3477
3493
|
|
3478
3494
|
// turn into byte offset by * valtypeSize + 1
|
@@ -3641,11 +3657,11 @@ const generateAssign = (scope, decl, _global, _name, valueUnused = false) => {
|
|
3641
3657
|
],
|
3642
3658
|
}, {
|
3643
3659
|
prelude: [
|
3644
|
-
|
3660
|
+
objectGet,
|
3645
3661
|
Opcodes.i32_to_u,
|
3646
3662
|
[ Opcodes.i32_load, 0, 4 ],
|
3647
3663
|
|
3648
|
-
|
3664
|
+
propertyGet,
|
3649
3665
|
Opcodes.i32_to_u,
|
3650
3666
|
],
|
3651
3667
|
postlude: [
|
@@ -3659,12 +3675,12 @@ const generateAssign = (scope, decl, _global, _name, valueUnused = false) => {
|
|
3659
3675
|
|
3660
3676
|
// default: internalThrow(scope, 'TypeError', `Cannot assign member with this type`)
|
3661
3677
|
default: () => [
|
3662
|
-
|
3678
|
+
objectGet,
|
3663
3679
|
Opcodes.i32_to,
|
3664
3680
|
...(op === '=' ? [] : [ [ Opcodes.local_tee, localTmp(scope, '#objset_object', Valtype.i32) ] ]),
|
3665
3681
|
...getNodeType(scope, object),
|
3666
3682
|
|
3667
|
-
...toPropertyKey(scope,
|
3683
|
+
...toPropertyKey(scope, [ propertyGet ], getNodeType(scope, property), decl.left.computed, op === '='),
|
3668
3684
|
...(op === '=' ? [] : [ [ Opcodes.local_set, localTmp(scope, '#objset_property_type', Valtype.i32) ] ]),
|
3669
3685
|
...(op === '=' ? [] : [
|
3670
3686
|
Opcodes.i32_to_u,
|
@@ -5403,15 +5419,15 @@ const generateMember = (scope, decl, _global, _name) => {
|
|
5403
5419
|
}
|
5404
5420
|
}
|
5405
5421
|
|
5422
|
+
// todo/perf: use i32 object (and prop?) locals
|
5423
|
+
const { objectTmp, propertyTmp, objectGet, propertyGet } = memberTmpNames(scope);
|
5424
|
+
|
5406
5425
|
// todo: generate this array procedurally during builtinFuncs creation
|
5407
5426
|
if (['size', 'description', 'byteLength', 'byteOffset', 'buffer', 'detached', 'resizable', 'growable', 'maxByteLength'].includes(decl.property.name)) {
|
5408
5427
|
// todo: support optional
|
5409
5428
|
const bc = {};
|
5410
5429
|
const cands = Object.keys(builtinFuncs).filter(x => x.startsWith('__') && x.endsWith('_prototype_' + decl.property.name + '$get'));
|
5411
5430
|
|
5412
|
-
localTmp(scope, '#member_obj');
|
5413
|
-
localTmp(scope, '#member_obj#type', Valtype.i32);
|
5414
|
-
|
5415
5431
|
const known = knownType(scope, getNodeType(scope, object));
|
5416
5432
|
if (cands.length > 0) {
|
5417
5433
|
for (const x of cands) {
|
@@ -5435,7 +5451,10 @@ const generateMember = (scope, decl, _global, _name) => {
|
|
5435
5451
|
name: x
|
5436
5452
|
},
|
5437
5453
|
arguments: [
|
5438
|
-
|
5454
|
+
[
|
5455
|
+
objectGet,
|
5456
|
+
...number(type, Valtype.i32)
|
5457
|
+
]
|
5439
5458
|
],
|
5440
5459
|
_protoInternalCall: true
|
5441
5460
|
});
|
@@ -5499,14 +5518,10 @@ const generateMember = (scope, decl, _global, _name) => {
|
|
5499
5518
|
}
|
5500
5519
|
}
|
5501
5520
|
|
5502
|
-
// todo/perf: use i32 object (and prop?) locals
|
5503
|
-
const objectWasm = [ [ Opcodes.local_get, localTmp(scope, '#member_obj') ] ];
|
5504
|
-
const propertyWasm = [ [ Opcodes.local_get, localTmp(scope, '#member_prop') ] ];
|
5505
|
-
|
5506
5521
|
const out = typeSwitch(scope, getNodeType(scope, object), {
|
5507
5522
|
...(decl.computed ? {
|
5508
5523
|
[TYPES.array]: () => [
|
5509
|
-
...loadArray(scope,
|
5524
|
+
...loadArray(scope, [ objectGet ], [ propertyGet ]),
|
5510
5525
|
...setLastType(scope)
|
5511
5526
|
],
|
5512
5527
|
|
@@ -5523,13 +5538,13 @@ const generateMember = (scope, decl, _global, _name) => {
|
|
5523
5538
|
// use as pointer for store later
|
5524
5539
|
[ Opcodes.local_get, localTmp(scope, '#member_allocd', Valtype.i32) ],
|
5525
5540
|
|
5526
|
-
|
5541
|
+
propertyGet,
|
5527
5542
|
Opcodes.i32_to_u,
|
5528
5543
|
|
5529
5544
|
...number(ValtypeSize.i16, Valtype.i32),
|
5530
5545
|
[ Opcodes.i32_mul ],
|
5531
5546
|
|
5532
|
-
|
5547
|
+
objectGet,
|
5533
5548
|
Opcodes.i32_to_u,
|
5534
5549
|
[ Opcodes.i32_add ],
|
5535
5550
|
|
@@ -5558,10 +5573,10 @@ const generateMember = (scope, decl, _global, _name) => {
|
|
5558
5573
|
// use as pointer for store later
|
5559
5574
|
[ Opcodes.local_get, localTmp(scope, '#member_allocd', Valtype.i32) ],
|
5560
5575
|
|
5561
|
-
|
5576
|
+
propertyGet,
|
5562
5577
|
Opcodes.i32_to_u,
|
5563
5578
|
|
5564
|
-
|
5579
|
+
objectGet,
|
5565
5580
|
Opcodes.i32_to_u,
|
5566
5581
|
[ Opcodes.i32_add ],
|
5567
5582
|
|
@@ -5645,11 +5660,11 @@ const generateMember = (scope, decl, _global, _name) => {
|
|
5645
5660
|
],
|
5646
5661
|
}, {
|
5647
5662
|
prelude: [
|
5648
|
-
|
5663
|
+
objectGet,
|
5649
5664
|
Opcodes.i32_to_u,
|
5650
5665
|
[ Opcodes.i32_load, 0, 4 ],
|
5651
5666
|
|
5652
|
-
|
5667
|
+
propertyGet,
|
5653
5668
|
Opcodes.i32_to_u
|
5654
5669
|
],
|
5655
5670
|
postlude: setLastType(scope, TYPES.number)
|
@@ -5660,11 +5675,11 @@ const generateMember = (scope, decl, _global, _name) => {
|
|
5660
5675
|
|
5661
5676
|
// default: internalThrow(scope, 'TypeError', 'Unsupported member expression object', true)
|
5662
5677
|
default: () => [
|
5663
|
-
|
5678
|
+
objectGet,
|
5664
5679
|
Opcodes.i32_to,
|
5665
5680
|
...getNodeType(scope, object),
|
5666
5681
|
|
5667
|
-
...toPropertyKey(scope,
|
5682
|
+
...toPropertyKey(scope, [ propertyGet ], getNodeType(scope, property), decl.computed, true),
|
5668
5683
|
|
5669
5684
|
[ Opcodes.call, includeBuiltin(scope, '__Porffor_object_get').index ],
|
5670
5685
|
...setLastType(scope)
|
@@ -5675,23 +5690,19 @@ const generateMember = (scope, decl, _global, _name) => {
|
|
5675
5690
|
|
5676
5691
|
if (decl.optional) {
|
5677
5692
|
out.unshift(
|
5693
|
+
...generate(scope, property),
|
5694
|
+
[ Opcodes.local_set, propertyTmp ],
|
5695
|
+
|
5678
5696
|
[ Opcodes.block, valtypeBinary ],
|
5679
5697
|
...generate(scope, object),
|
5680
|
-
[ Opcodes.local_tee,
|
5681
|
-
...(scope.locals['#member_obj#type'] ? [
|
5682
|
-
...getNodeType(scope, object),
|
5683
|
-
[ Opcodes.local_set, localTmp(scope, '#member_obj#type', Valtype.i32) ],
|
5684
|
-
] : []),
|
5698
|
+
[ Opcodes.local_tee, objectTmp ],
|
5685
5699
|
|
5686
5700
|
...nullish(scope, [], getNodeType(scope, object), false, true),
|
5687
5701
|
[ Opcodes.if, Blocktype.void ],
|
5688
5702
|
...setLastType(scope, TYPES.undefined),
|
5689
5703
|
...number(0),
|
5690
5704
|
[ Opcodes.br, chainCount ],
|
5691
|
-
[ Opcodes.end ]
|
5692
|
-
|
5693
|
-
...generate(scope, property, false, '#member_prop'),
|
5694
|
-
[ Opcodes.local_set, localTmp(scope, '#member_prop') ]
|
5705
|
+
[ Opcodes.end ]
|
5695
5706
|
);
|
5696
5707
|
|
5697
5708
|
out.push(
|
@@ -5699,15 +5710,10 @@ const generateMember = (scope, decl, _global, _name) => {
|
|
5699
5710
|
);
|
5700
5711
|
} else {
|
5701
5712
|
out.unshift(
|
5713
|
+
...generate(scope, property),
|
5714
|
+
[ Opcodes.local_set, propertyTmp ],
|
5702
5715
|
...generate(scope, object),
|
5703
|
-
[ Opcodes.local_set,
|
5704
|
-
...(scope.locals['#member_obj#type'] ? [
|
5705
|
-
...getNodeType(scope, object),
|
5706
|
-
[ Opcodes.local_set, localTmp(scope, '#member_obj#type', Valtype.i32) ],
|
5707
|
-
] : []),
|
5708
|
-
|
5709
|
-
...generate(scope, property, false, '#member_prop'),
|
5710
|
-
[ Opcodes.local_set, localTmp(scope, '#member_prop') ]
|
5716
|
+
[ Opcodes.local_set, objectTmp ]
|
5711
5717
|
);
|
5712
5718
|
|
5713
5719
|
// todo: maybe this just needs 1 block?
|
package/compiler/precompile.js
CHANGED
@@ -128,7 +128,7 @@ const compile = async (file, _funcs) => {
|
|
128
128
|
|
129
129
|
const alloc = l => {
|
130
130
|
if (!l) return;
|
131
|
-
if (![
|
131
|
+
if (![TYPES.array].includes(l.metadata?.type)) return;
|
132
132
|
if (!x.pages) return;
|
133
133
|
|
134
134
|
const pageName = [...x.pages.keys()].find(z => z.endsWith(l.name));
|
package/package.json
CHANGED
package/richards.js
CHANGED
@@ -25,14 +25,6 @@
|
|
25
25
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
26
26
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27
27
|
|
28
|
-
// Performance.now is used in latency benchmarks, the fallback is Date.now.
|
29
|
-
var performance = performance || {};
|
30
|
-
performance.now = (function () {
|
31
|
-
return (
|
32
|
-
performance.now || performance.mozNow || performance.msNow || performance.oNow || performance.webkitNow || Date.now
|
33
|
-
);
|
34
|
-
})();
|
35
|
-
|
36
28
|
// Simple framework for running the benchmark suites and
|
37
29
|
// computing a score based on the timing measurements.
|
38
30
|
|
@@ -135,33 +127,30 @@ BenchmarkSuite.RunSuites = function (runner, skipBenchmarks) {
|
|
135
127
|
var length = suites.length;
|
136
128
|
BenchmarkSuite.scores = [];
|
137
129
|
var index = 0;
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
130
|
+
while (continuation || index < length) {
|
131
|
+
if (continuation) {
|
132
|
+
continuation = continuation();
|
133
|
+
} else {
|
134
|
+
var suite = suites[index++];
|
135
|
+
if (runner.NotifyStart) runner.NotifyStart(suite.name);
|
136
|
+
if (skipBenchmarks.indexOf(suite.name) > -1) {
|
137
|
+
suite.NotifySkipped(runner);
|
142
138
|
} else {
|
143
|
-
|
144
|
-
if (runner.NotifyStart) runner.NotifyStart(suite.name);
|
145
|
-
if (skipBenchmarks.indexOf(suite.name) > -1) {
|
146
|
-
suite.NotifySkipped(runner);
|
147
|
-
} else {
|
148
|
-
continuation = suite.RunStep(runner);
|
149
|
-
}
|
150
|
-
}
|
151
|
-
if (continuation && typeof window != "undefined" && window.setTimeout) {
|
152
|
-
window.setTimeout(RunStep, 25);
|
153
|
-
return;
|
139
|
+
continuation = suite.RunStep(runner);
|
154
140
|
}
|
155
141
|
}
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
var score = BenchmarkSuite.GeometricMean(BenchmarkSuite.scores);
|
160
|
-
var formatted = BenchmarkSuite.FormatScore(100 * score);
|
161
|
-
runner.NotifyScore(formatted);
|
142
|
+
if (continuation && typeof window != "undefined" && window.setTimeout) {
|
143
|
+
window.setTimeout(RunStep, 25);
|
144
|
+
return;
|
162
145
|
}
|
163
146
|
}
|
164
|
-
|
147
|
+
|
148
|
+
// show final result
|
149
|
+
if (runner.NotifyScore) {
|
150
|
+
var score = BenchmarkSuite.GeometricMean(BenchmarkSuite.scores);
|
151
|
+
var formatted = BenchmarkSuite.FormatScore(100 * score);
|
152
|
+
runner.NotifyScore(formatted);
|
153
|
+
}
|
165
154
|
};
|
166
155
|
|
167
156
|
// Counts the total number of registered benchmarks. Useful for
|
@@ -213,11 +202,7 @@ BenchmarkSuite.GeometricMeanLatency = function (measurements) {
|
|
213
202
|
// Converts a score value to a string with at least three significant
|
214
203
|
// digits.
|
215
204
|
BenchmarkSuite.FormatScore = function (value) {
|
216
|
-
|
217
|
-
return value.toFixed(0);
|
218
|
-
} else {
|
219
|
-
return value.toPrecision(3);
|
220
|
-
}
|
205
|
+
return value.toFixed(0);
|
221
206
|
};
|
222
207
|
|
223
208
|
// Notifies the runner that we're done running a single benchmark in
|
@@ -274,39 +259,36 @@ BenchmarkSuite.prototype.RunSingleBenchmark = function (benchmark, data) {
|
|
274
259
|
var doWarmup = config.doWarmup !== undefined ? config.doWarmup : benchmark.doWarmup;
|
275
260
|
var doDeterministic = config.doDeterministic !== undefined ? config.doDeterministic : benchmark.doDeterministic;
|
276
261
|
|
277
|
-
|
278
|
-
|
279
|
-
var start = new Date();
|
262
|
+
var elapsed = 0;
|
263
|
+
var runs = 0;
|
280
264
|
|
265
|
+
// Run either for 1 second or for the number of iterations specified
|
266
|
+
// by minIterations, depending on the config flag doDeterministic.
|
267
|
+
// for (var i = 0; doDeterministic ? i < benchmark.deterministicIterations : elapsed < 1000; i++) {
|
268
|
+
// benchmark.run();
|
269
|
+
// elapsed = performance.now() - start;
|
270
|
+
// }
|
271
|
+
|
272
|
+
// If we've run too few iterations, we continue for another second.
|
273
|
+
while (runs < benchmark.minIterations) {
|
281
274
|
// Run either for 1 second or for the number of iterations specified
|
282
275
|
// by minIterations, depending on the config flag doDeterministic.
|
283
|
-
|
276
|
+
var i = 0;
|
277
|
+
for (; doDeterministic ? i < benchmark.deterministicIterations : elapsed < 1000; i++) {
|
278
|
+
var start = performance.now();
|
284
279
|
benchmark.run();
|
285
|
-
elapsed
|
286
|
-
}
|
287
|
-
if (data != null) {
|
288
|
-
data.runs += i;
|
289
|
-
data.elapsed += elapsed;
|
280
|
+
elapsed += performance.now() - start;
|
290
281
|
}
|
291
|
-
}
|
292
282
|
|
293
|
-
|
294
|
-
if (!doWarmup && data == null) {
|
295
|
-
data = { runs: 0, elapsed: 0 };
|
283
|
+
runs += i;
|
296
284
|
}
|
297
285
|
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
if (data.runs < benchmark.minIterations) return data;
|
305
|
-
var usec = (data.elapsed * 1000) / data.runs;
|
306
|
-
var rms = benchmark.rmsResult != null ? benchmark.rmsResult() : 0;
|
307
|
-
this.NotifyStep(new BenchmarkResult(benchmark, usec, rms));
|
308
|
-
return null;
|
309
|
-
}
|
286
|
+
console.log('did', runs, 'runs in', elapsed, 'ms');
|
287
|
+
var usec = (elapsed * 1000) / runs;
|
288
|
+
var rms = benchmark.rmsResult != null ? benchmark.rmsResult() : 0;
|
289
|
+
this.NotifyStep(new BenchmarkResult(benchmark, usec, rms));
|
290
|
+
|
291
|
+
return null;
|
310
292
|
};
|
311
293
|
|
312
294
|
// This function starts running a suite, but stops between each
|
@@ -326,43 +308,17 @@ BenchmarkSuite.prototype.RunStep = function (runner) {
|
|
326
308
|
// separate steps to allow the framework to yield between any of the
|
327
309
|
// steps.
|
328
310
|
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
return null;
|
336
|
-
}
|
337
|
-
return RunNextBenchmark;
|
338
|
-
}
|
339
|
-
suite.NotifyResult();
|
311
|
+
try {
|
312
|
+
suite.benchmarks[index].Setup();
|
313
|
+
data = suite.RunSingleBenchmark(suite.benchmarks[index], data);
|
314
|
+
suite.benchmarks[index++].TearDown();
|
315
|
+
} catch (e) {
|
316
|
+
suite.NotifyError(e);
|
340
317
|
return null;
|
341
318
|
}
|
342
319
|
|
343
|
-
|
344
|
-
|
345
|
-
data = suite.RunSingleBenchmark(suite.benchmarks[index], data);
|
346
|
-
} catch (e) {
|
347
|
-
suite.NotifyError(e);
|
348
|
-
return null;
|
349
|
-
}
|
350
|
-
// If data is null, we're done with this benchmark.
|
351
|
-
return data == null ? RunNextTearDown : RunNextBenchmark();
|
352
|
-
}
|
353
|
-
|
354
|
-
function RunNextTearDown() {
|
355
|
-
try {
|
356
|
-
suite.benchmarks[index++].TearDown();
|
357
|
-
} catch (e) {
|
358
|
-
suite.NotifyError(e);
|
359
|
-
return null;
|
360
|
-
}
|
361
|
-
return RunNextSetup;
|
362
|
-
}
|
363
|
-
|
364
|
-
// Start out running the setup.
|
365
|
-
return RunNextSetup();
|
320
|
+
suite.NotifyResult();
|
321
|
+
return null;
|
366
322
|
};
|
367
323
|
// Copyright 2006-2008 the V8 project authors. All rights reserved.
|
368
324
|
// Redistribution and use in source and binary forms, with or without
|
@@ -401,41 +357,6 @@ BenchmarkSuite.prototype.RunStep = function (runner) {
|
|
401
357
|
|
402
358
|
var Richards = new BenchmarkSuite("Richards", [35302], [new Benchmark("Richards", true, false, 8200, runRichards)]);
|
403
359
|
|
404
|
-
/**
|
405
|
-
* The Richards benchmark simulates the task dispatcher of an
|
406
|
-
* operating system.
|
407
|
-
**/
|
408
|
-
function runRichards() {
|
409
|
-
var scheduler = new Scheduler();
|
410
|
-
scheduler.addIdleTask(ID_IDLE, 0, null, COUNT);
|
411
|
-
|
412
|
-
var queue = new Packet(null, ID_WORKER, KIND_WORK);
|
413
|
-
queue = new Packet(queue, ID_WORKER, KIND_WORK);
|
414
|
-
scheduler.addWorkerTask(ID_WORKER, 1000, queue);
|
415
|
-
|
416
|
-
queue = new Packet(null, ID_DEVICE_A, KIND_DEVICE);
|
417
|
-
queue = new Packet(queue, ID_DEVICE_A, KIND_DEVICE);
|
418
|
-
queue = new Packet(queue, ID_DEVICE_A, KIND_DEVICE);
|
419
|
-
scheduler.addHandlerTask(ID_HANDLER_A, 2000, queue);
|
420
|
-
|
421
|
-
queue = new Packet(null, ID_DEVICE_B, KIND_DEVICE);
|
422
|
-
queue = new Packet(queue, ID_DEVICE_B, KIND_DEVICE);
|
423
|
-
queue = new Packet(queue, ID_DEVICE_B, KIND_DEVICE);
|
424
|
-
scheduler.addHandlerTask(ID_HANDLER_B, 3000, queue);
|
425
|
-
|
426
|
-
scheduler.addDeviceTask(ID_DEVICE_A, 4000, null);
|
427
|
-
|
428
|
-
scheduler.addDeviceTask(ID_DEVICE_B, 5000, null);
|
429
|
-
|
430
|
-
scheduler.schedule();
|
431
|
-
|
432
|
-
if (scheduler.queueCount != EXPECTED_QUEUE_COUNT || scheduler.holdCount != EXPECTED_HOLD_COUNT) {
|
433
|
-
var msg =
|
434
|
-
"Error during execution: queueCount = " + scheduler.queueCount + ", holdCount = " + scheduler.holdCount + ".";
|
435
|
-
throw new Error(msg);
|
436
|
-
}
|
437
|
-
}
|
438
|
-
|
439
360
|
var COUNT = 1000;
|
440
361
|
|
441
362
|
/**
|
@@ -535,6 +456,7 @@ Scheduler.prototype.addRunningTask = function (id, priority, queue, task) {
|
|
535
456
|
* @param {Task} task the task to add
|
536
457
|
*/
|
537
458
|
Scheduler.prototype.addTask = function (id, priority, queue, task) {
|
459
|
+
// console.log('Scheduler.addTask', id);
|
538
460
|
this.currentTcb = new TaskControlBlock(this.list, id, priority, queue, task);
|
539
461
|
this.list = this.currentTcb;
|
540
462
|
this.blocks[id] = this.currentTcb;
|
@@ -546,6 +468,7 @@ Scheduler.prototype.addTask = function (id, priority, queue, task) {
|
|
546
468
|
Scheduler.prototype.schedule = function () {
|
547
469
|
this.currentTcb = this.list;
|
548
470
|
while (this.currentTcb != null) {
|
471
|
+
// console.log('Scheduler.schedule', this.currentTcb.task.__proto__.constructor.name, this.currentTcb.id, this.currentTcb.isHeldOrSuspended());
|
549
472
|
if (this.currentTcb.isHeldOrSuspended()) {
|
550
473
|
this.currentTcb = this.currentTcb.link;
|
551
474
|
} else {
|
@@ -598,6 +521,7 @@ Scheduler.prototype.suspendCurrent = function () {
|
|
598
521
|
*/
|
599
522
|
Scheduler.prototype.queue = function (packet) {
|
600
523
|
var t = this.blocks[packet.id];
|
524
|
+
// console.log('Scheduler.queue', packet.id, t == null);
|
601
525
|
if (t == null) return t;
|
602
526
|
this.queueCount++;
|
603
527
|
packet.link = null;
|
@@ -786,6 +710,7 @@ function WorkerTask(scheduler, v1, v2) {
|
|
786
710
|
}
|
787
711
|
|
788
712
|
WorkerTask.prototype.run = function (packet) {
|
713
|
+
// console.log('WorkerTask.run', packet == null);
|
789
714
|
if (packet == null) {
|
790
715
|
return this.scheduler.suspendCurrent();
|
791
716
|
} else {
|
@@ -895,6 +820,41 @@ Packet.prototype.addTo = function (queue) {
|
|
895
820
|
Packet.prototype.toString = function () {
|
896
821
|
return "Packet";
|
897
822
|
};
|
823
|
+
|
824
|
+
/**
|
825
|
+
* The Richards benchmark simulates the task dispatcher of an
|
826
|
+
* operating system.
|
827
|
+
**/
|
828
|
+
function runRichards() {
|
829
|
+
var scheduler = new Scheduler();
|
830
|
+
scheduler.addIdleTask(ID_IDLE, 0, null, COUNT);
|
831
|
+
|
832
|
+
var queue = new Packet(null, ID_WORKER, KIND_WORK);
|
833
|
+
queue = new Packet(queue, ID_WORKER, KIND_WORK);
|
834
|
+
scheduler.addWorkerTask(ID_WORKER, 1000, queue);
|
835
|
+
|
836
|
+
queue = new Packet(null, ID_DEVICE_A, KIND_DEVICE);
|
837
|
+
queue = new Packet(queue, ID_DEVICE_A, KIND_DEVICE);
|
838
|
+
queue = new Packet(queue, ID_DEVICE_A, KIND_DEVICE);
|
839
|
+
scheduler.addHandlerTask(ID_HANDLER_A, 2000, queue);
|
840
|
+
|
841
|
+
queue = new Packet(null, ID_DEVICE_B, KIND_DEVICE);
|
842
|
+
queue = new Packet(queue, ID_DEVICE_B, KIND_DEVICE);
|
843
|
+
queue = new Packet(queue, ID_DEVICE_B, KIND_DEVICE);
|
844
|
+
scheduler.addHandlerTask(ID_HANDLER_B, 3000, queue);
|
845
|
+
|
846
|
+
scheduler.addDeviceTask(ID_DEVICE_A, 4000, null);
|
847
|
+
|
848
|
+
scheduler.addDeviceTask(ID_DEVICE_B, 5000, null);
|
849
|
+
|
850
|
+
scheduler.schedule();
|
851
|
+
|
852
|
+
if (scheduler.queueCount != EXPECTED_QUEUE_COUNT || scheduler.holdCount != EXPECTED_HOLD_COUNT) {
|
853
|
+
var msg =
|
854
|
+
"Error during execution: queueCount = " + scheduler.queueCount + ", holdCount = " + scheduler.holdCount + ".";
|
855
|
+
throw new Error(msg);
|
856
|
+
}
|
857
|
+
}
|
898
858
|
// Copyright 2014 the V8 project authors. All rights reserved.
|
899
859
|
// Redistribution and use in source and binary forms, with or without
|
900
860
|
// modification, are permitted provided that the following conditions are
|
@@ -935,6 +895,7 @@ function PrintError(name, error) {
|
|
935
895
|
}
|
936
896
|
|
937
897
|
function PrintScore(score) {
|
898
|
+
return;
|
938
899
|
if (success) {
|
939
900
|
console.log("----");
|
940
901
|
console.log("Score (version " + BenchmarkSuite.version + "): " + score);
|
@@ -946,6 +907,7 @@ BenchmarkSuite.config.doDeterministic = undefined;
|
|
946
907
|
|
947
908
|
function main() {
|
948
909
|
BenchmarkSuite.RunSuites({ NotifyResult: PrintResult, NotifyError: PrintError, NotifyScore: PrintScore });
|
910
|
+
// runRichards();
|
949
911
|
}
|
950
912
|
|
951
913
|
main();
|