porffor 0.58.0 → 0.58.2
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/README.md +6 -11
- package/compiler/builtins.js +9 -0
- package/compiler/codegen.js +2 -3
- package/compiler/index.js +1 -1
- package/compiler/pgo.js +14 -13
- package/compiler/wrap.js +11 -3
- package/jsr.json +28 -0
- package/package.json +1 -1
- package/runtime/index.js +5 -5
- package/.editorconfig +0 -12
- package/asur/README.md +0 -2
- package/asur/index.js +0 -1262
- package/regex_notes.md +0 -74
- package/richards_direct.js +0 -558
package/regex_notes.md
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
**ES3 (1999)**
|
2
|
-
* Basic regex syntax (Perl-inspired)
|
3
|
-
* `RegExp` object
|
4
|
-
* `test()`, `exec()` methods for `RegExp`
|
5
|
-
* `match()`, `replace()`, `search()`, `split()` methods for `String`
|
6
|
-
* **Flags:**
|
7
|
-
* `g` (global)
|
8
|
-
* `i` (ignore case)
|
9
|
-
* `m` (multiline) - `^` and `$` match start/end of lines, not just start/end of string.
|
10
|
-
* **Special Characters/Constructs:**
|
11
|
-
* `.` (wildcard - matches any character except newline)
|
12
|
-
* `\d`, `\D` (digit, non-digit)
|
13
|
-
* `\w`, `\W` (word character, non-word character)
|
14
|
-
* `\s`, `\S` (whitespace, non-whitespace)
|
15
|
-
* `\t`, `\r`, `\n`, `\v`, `\f` (tab, carriage return, line feed, vertical tab, form feed)
|
16
|
-
* `[...]`, `[^...]` (character classes)
|
17
|
-
* `^`, `$` (start/end of string/line - see `m` flag)
|
18
|
-
* `\b`, `\B` (word boundary, non-word boundary)
|
19
|
-
* `(...)` (capturing group)
|
20
|
-
* `(?:...)` (non-capturing group)
|
21
|
-
* `\1`, `\2`, ... (backreferences to capturing groups)
|
22
|
-
* `|` (alternation/OR)
|
23
|
-
* `*`, `+`, `?` (quantifiers: zero or more, one or more, zero or one)
|
24
|
-
* `{n}`, `{n,}`, `{n,m}` (quantifiers: exactly n, at least n, between n and m)
|
25
|
-
* `*?`, `+?`, `??`, `{n}?`, `{n,}?`, `{n,m}?` (lazy quantifiers)
|
26
|
-
* `(?=...)` (positive lookahead)
|
27
|
-
* `(?!...)` (negative lookahead)
|
28
|
-
|
29
|
-
**ES5 (2009)**
|
30
|
-
* Regex literals `(/abc/)` now create a new object each time they are evaluated.
|
31
|
-
* Unescaped forward slashes allowed within character classes (e.g., `/[/]/`).
|
32
|
-
|
33
|
-
**ES6/ES2015**
|
34
|
-
* **New Flags:**
|
35
|
-
* `u` (unicode): Enables stricter parsing, improved handling of Unicode surrogate pairs, and allows `\u{...}` for Unicode code points.
|
36
|
-
* `y` (sticky): The match must start at the `lastIndex` property of the `RegExp`.
|
37
|
-
* `RegExp.prototype.flags` getter: Returns a string containing the flags of the regex.
|
38
|
-
* Support for subclassing `RegExp`.
|
39
|
-
* Ability to copy a regex while changing its flags: `new RegExp(/ab+c/, 'i')`.
|
40
|
-
|
41
|
-
**ES2018 (ES9)**
|
42
|
-
* **New Flag:**
|
43
|
-
* `s` (dotAll/singleline): Causes `.` to match newline characters as well.
|
44
|
-
* **Lookbehind Assertions:**
|
45
|
-
* `(?<=...)` (positive lookbehind)
|
46
|
-
* `(?<!...)` (negative lookbehind)
|
47
|
-
* **Named Capture Groups:**
|
48
|
-
* `(?<name>...)` (defines a named capture group)
|
49
|
-
* `\k<name>` (backreference to a named capture group)
|
50
|
-
* Named groups are accessible via the `groups` property of the match object.
|
51
|
-
* **Unicode Property Escapes:** (Requires `u` or `v` flag)
|
52
|
-
* `\p{PropertyName}` (e.g., `\p{Script=Greek}`, `\p{Number}`, `\p{Alphabetic}`)
|
53
|
-
* `\P{PropertyName}` (negated version)
|
54
|
-
|
55
|
-
**ES2020 (ES11)**
|
56
|
-
* `String.prototype.matchAll()`: Returns an iterator of all results matching a global regular expression against a string. (Requires the `g` flag).
|
57
|
-
|
58
|
-
**ES2021 (ES12)**
|
59
|
-
* `String.prototype.replaceAll()`: Replaces all occurrences of a substring (can be a regex). If a regex is used, it must have the `g` flag.
|
60
|
-
|
61
|
-
**ES2022 (ES13)**
|
62
|
-
* **New Flag:**
|
63
|
-
* `d` (hasIndices): Provides start and end indices for matched substrings (and capturing groups) via the `indices` property on the match object.
|
64
|
-
|
65
|
-
**ES2024 (ES15)**
|
66
|
-
* **New Flag:**
|
67
|
-
* `v` (unicodeSets): An upgrade to the `u` flag (cannot be used with `u`).
|
68
|
-
* Adds set notation for strings of characters to `\p{...}` and `\q{...}` (matching literal strings) within character classes.
|
69
|
-
* Nested character classes.
|
70
|
-
* Set operations within character classes:
|
71
|
-
* Subtraction: `[A--B]` (characters in A but not in B)
|
72
|
-
* Intersection: `[A&&B]` (characters in both A and B)
|
73
|
-
* Improved case-insensitive matching for Unicode properties within negated sets `[^...]`.
|
74
|
-
* `\p{RGI_Emoji}` for matching complete emojis.
|
package/richards_direct.js
DELETED
@@ -1,558 +0,0 @@
|
|
1
|
-
// Copyright 2006-2008 the V8 project authors. All rights reserved.
|
2
|
-
// Redistribution and use in source and binary forms, with or without
|
3
|
-
// modification, are permitted provided that the following conditions are
|
4
|
-
// met:
|
5
|
-
//
|
6
|
-
// * Redistributions of source code must retain the above copyright
|
7
|
-
// notice, this list of conditions and the following disclaimer.
|
8
|
-
// * Redistributions in binary form must reproduce the above
|
9
|
-
// copyright notice, this list of conditions and the following
|
10
|
-
// disclaimer in the documentation and/or other materials provided
|
11
|
-
// with the distribution.
|
12
|
-
// * Neither the name of Google Inc. nor the names of its
|
13
|
-
// contributors may be used to endorse or promote products derived
|
14
|
-
// from this software without specific prior written permission.
|
15
|
-
//
|
16
|
-
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
17
|
-
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
18
|
-
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
19
|
-
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
20
|
-
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
21
|
-
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
22
|
-
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
23
|
-
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
24
|
-
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
25
|
-
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
26
|
-
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27
|
-
|
28
|
-
// This is a JavaScript implementation of the Richards
|
29
|
-
// benchmark from:
|
30
|
-
//
|
31
|
-
// http://www.cl.cam.ac.uk/~mr10/Bench.html
|
32
|
-
//
|
33
|
-
// The benchmark was originally implemented in BCPL by
|
34
|
-
// Martin Richards.
|
35
|
-
|
36
|
-
/**
|
37
|
-
* The Richards benchmark simulates the task dispatcher of an
|
38
|
-
* operating system.
|
39
|
-
**/
|
40
|
-
function runRichards() {
|
41
|
-
var scheduler = new Scheduler();
|
42
|
-
scheduler_addIdleTask.call(scheduler, ID_IDLE, 0, null, COUNT);
|
43
|
-
|
44
|
-
var queue = new Packet(null, ID_WORKER, KIND_WORK);
|
45
|
-
queue = new Packet(queue, ID_WORKER, KIND_WORK);
|
46
|
-
scheduler_addWorkerTask.call(scheduler, ID_WORKER, 1000, queue);
|
47
|
-
|
48
|
-
queue = new Packet(null, ID_DEVICE_A, KIND_DEVICE);
|
49
|
-
queue = new Packet(queue, ID_DEVICE_A, KIND_DEVICE);
|
50
|
-
queue = new Packet(queue, ID_DEVICE_A, KIND_DEVICE);
|
51
|
-
scheduler_addHandlerTask.call(scheduler, ID_HANDLER_A, 2000, queue);
|
52
|
-
|
53
|
-
queue = new Packet(null, ID_DEVICE_B, KIND_DEVICE);
|
54
|
-
queue = new Packet(queue, ID_DEVICE_B, KIND_DEVICE);
|
55
|
-
queue = new Packet(queue, ID_DEVICE_B, KIND_DEVICE);
|
56
|
-
scheduler_addHandlerTask.call(scheduler, ID_HANDLER_B, 3000, queue);
|
57
|
-
|
58
|
-
scheduler_addDeviceTask.call(scheduler, ID_DEVICE_A, 4000, null);
|
59
|
-
|
60
|
-
scheduler_addDeviceTask.call(scheduler, ID_DEVICE_B, 5000, null);
|
61
|
-
|
62
|
-
scheduler_schedule.call(scheduler);
|
63
|
-
|
64
|
-
if (scheduler.queueCount != EXPECTED_QUEUE_COUNT || scheduler.holdCount != EXPECTED_HOLD_COUNT) {
|
65
|
-
var msg =
|
66
|
-
"Error during execution: queueCount = " + scheduler.queueCount + ", holdCount = " + scheduler.holdCount + ".";
|
67
|
-
throw new Error(msg);
|
68
|
-
}
|
69
|
-
}
|
70
|
-
|
71
|
-
var COUNT = 1000;
|
72
|
-
|
73
|
-
/**
|
74
|
-
* These two constants specify how many times a packet is queued and
|
75
|
-
* how many times a task is put on hold in a correct run of richards.
|
76
|
-
* They don't have any meaning a such but are characteristic of a
|
77
|
-
* correct run so if the actual queue or hold count is different from
|
78
|
-
* the expected there must be a bug in the implementation.
|
79
|
-
**/
|
80
|
-
var EXPECTED_QUEUE_COUNT = 2322;
|
81
|
-
var EXPECTED_HOLD_COUNT = 928;
|
82
|
-
|
83
|
-
/**
|
84
|
-
* A scheduler can be used to schedule a set of tasks based on their relative
|
85
|
-
* priorities. Scheduling is done by maintaining a list of task control blocks
|
86
|
-
* which holds tasks and the data queue they are processing.
|
87
|
-
* @constructor
|
88
|
-
*/
|
89
|
-
function Scheduler() {
|
90
|
-
this.queueCount = 0;
|
91
|
-
this.holdCount = 0;
|
92
|
-
this.blocks = new Array(NUMBER_OF_IDS);
|
93
|
-
this.list = null;
|
94
|
-
this.currentTcb = null;
|
95
|
-
this.currentId = null;
|
96
|
-
}
|
97
|
-
|
98
|
-
var ID_IDLE = 0;
|
99
|
-
var ID_WORKER = 1;
|
100
|
-
var ID_HANDLER_A = 2;
|
101
|
-
var ID_HANDLER_B = 3;
|
102
|
-
var ID_DEVICE_A = 4;
|
103
|
-
var ID_DEVICE_B = 5;
|
104
|
-
var NUMBER_OF_IDS = 6;
|
105
|
-
|
106
|
-
var KIND_DEVICE = 0;
|
107
|
-
var KIND_WORK = 1;
|
108
|
-
|
109
|
-
/**
|
110
|
-
* Add an idle task to this scheduler.
|
111
|
-
* @param {int} id the identity of the task
|
112
|
-
* @param {int} priority the task's priority
|
113
|
-
* @param {Packet} queue the queue of work to be processed by the task
|
114
|
-
* @param {int} count the number of times to schedule the task
|
115
|
-
*/
|
116
|
-
function scheduler_addIdleTask(id, priority, queue, count) {
|
117
|
-
scheduler_addRunningTask.call(this, id, priority, queue, new IdleTask(this, 1, count));
|
118
|
-
};
|
119
|
-
|
120
|
-
/**
|
121
|
-
* Add a work task to this scheduler.
|
122
|
-
* @param {int} id the identity of the task
|
123
|
-
* @param {int} priority the task's priority
|
124
|
-
* @param {Packet} queue the queue of work to be processed by the task
|
125
|
-
*/
|
126
|
-
function scheduler_addWorkerTask(id, priority, queue) {
|
127
|
-
scheduler_addTask.call(this, id, priority, queue, new WorkerTask(this, ID_HANDLER_A, 0));
|
128
|
-
};
|
129
|
-
|
130
|
-
/**
|
131
|
-
* Add a handler task to this scheduler.
|
132
|
-
* @param {int} id the identity of the task
|
133
|
-
* @param {int} priority the task's priority
|
134
|
-
* @param {Packet} queue the queue of work to be processed by the task
|
135
|
-
*/
|
136
|
-
function scheduler_addHandlerTask(id, priority, queue) {
|
137
|
-
scheduler_addTask.call(this, id, priority, queue, new HandlerTask(this));
|
138
|
-
};
|
139
|
-
|
140
|
-
/**
|
141
|
-
* Add a handler task to this scheduler.
|
142
|
-
* @param {int} id the identity of the task
|
143
|
-
* @param {int} priority the task's priority
|
144
|
-
* @param {Packet} queue the queue of work to be processed by the task
|
145
|
-
*/
|
146
|
-
function scheduler_addDeviceTask(id, priority, queue) {
|
147
|
-
scheduler_addTask.call(this, id, priority, queue, new DeviceTask(this));
|
148
|
-
};
|
149
|
-
|
150
|
-
/**
|
151
|
-
* Add the specified task and mark it as running.
|
152
|
-
* @param {int} id the identity of the task
|
153
|
-
* @param {int} priority the task's priority
|
154
|
-
* @param {Packet} queue the queue of work to be processed by the task
|
155
|
-
* @param {Task} task the task to add
|
156
|
-
*/
|
157
|
-
function scheduler_addRunningTask(id, priority, queue, task) {
|
158
|
-
scheduler_addTask.call(this, id, priority, queue, task);
|
159
|
-
tcb_setRunning.call(this.currentTcb);
|
160
|
-
};
|
161
|
-
|
162
|
-
/**
|
163
|
-
* Add the specified task to this scheduler.
|
164
|
-
* @param {int} id the identity of the task
|
165
|
-
* @param {int} priority the task's priority
|
166
|
-
* @param {Packet} queue the queue of work to be processed by the task
|
167
|
-
* @param {Task} task the task to add
|
168
|
-
*/
|
169
|
-
function scheduler_addTask(id, priority, queue, task) {
|
170
|
-
this.currentTcb = new TaskControlBlock(this.list, id, priority, queue, task);
|
171
|
-
this.list = this.currentTcb;
|
172
|
-
this.blocks[id] = this.currentTcb;
|
173
|
-
};
|
174
|
-
|
175
|
-
/**
|
176
|
-
* Execute the tasks managed by this scheduler.
|
177
|
-
*/
|
178
|
-
function scheduler_schedule() {
|
179
|
-
this.currentTcb = this.list;
|
180
|
-
while (this.currentTcb != null) {
|
181
|
-
if (tcb_isHeldOrSuspended.call(this.currentTcb)) {
|
182
|
-
this.currentTcb = this.currentTcb.link;
|
183
|
-
} else {
|
184
|
-
this.currentId = this.currentTcb.id;
|
185
|
-
this.currentTcb = tcb_run.call(this.currentTcb);
|
186
|
-
}
|
187
|
-
}
|
188
|
-
};
|
189
|
-
|
190
|
-
/**
|
191
|
-
* Release a task that is currently blocked and return the next block to run.
|
192
|
-
* @param {int} id the id of the task to suspend
|
193
|
-
*/
|
194
|
-
function scheduler_release(id) {
|
195
|
-
var tcb = this.blocks[id];
|
196
|
-
if (tcb == null) return tcb;
|
197
|
-
tcb_markAsNotHeld.call(tcb);
|
198
|
-
if (tcb.priority > this.currentTcb.priority) {
|
199
|
-
return tcb;
|
200
|
-
} else {
|
201
|
-
return this.currentTcb;
|
202
|
-
}
|
203
|
-
};
|
204
|
-
|
205
|
-
/**
|
206
|
-
* Block the currently executing task and return the next task control block
|
207
|
-
* to run. The blocked task will not be made runnable until it is explicitly
|
208
|
-
* released, even if new work is added to it.
|
209
|
-
*/
|
210
|
-
function scheduler_holdCurrent() {
|
211
|
-
this.holdCount++;
|
212
|
-
tcb_markAsHeld.call(this.currentTcb);
|
213
|
-
return this.currentTcb.link;
|
214
|
-
};
|
215
|
-
|
216
|
-
/**
|
217
|
-
* Suspend the currently executing task and return the next task control block
|
218
|
-
* to run. If new work is added to the suspended task it will be made runnable.
|
219
|
-
*/
|
220
|
-
function scheduler_suspendCurrent() {
|
221
|
-
tcb_markAsSuspended.call(this.currentTcb);
|
222
|
-
return this.currentTcb;
|
223
|
-
};
|
224
|
-
|
225
|
-
/**
|
226
|
-
* Add the specified packet to the end of the worklist used by the task
|
227
|
-
* associated with the packet and make the task runnable if it is currently
|
228
|
-
* suspended.
|
229
|
-
* @param {Packet} packet the packet to add
|
230
|
-
*/
|
231
|
-
function scheduler_queue(packet) {
|
232
|
-
var t = this.blocks[packet.id];
|
233
|
-
if (t == null) return t;
|
234
|
-
this.queueCount++;
|
235
|
-
packet.link = null;
|
236
|
-
packet.id = this.currentId;
|
237
|
-
return tcb_checkPriorityAdd.call(t, this.currentTcb, packet);
|
238
|
-
};
|
239
|
-
|
240
|
-
/**
|
241
|
-
* A task control block manages a task and the queue of work packages associated
|
242
|
-
* with it.
|
243
|
-
* @param {TaskControlBlock} link the preceding block in the linked block list
|
244
|
-
* @param {int} id the id of this block
|
245
|
-
* @param {int} priority the priority of this block
|
246
|
-
* @param {Packet} queue the queue of packages to be processed by the task
|
247
|
-
* @param {Task} task the task
|
248
|
-
* @constructor
|
249
|
-
*/
|
250
|
-
function TaskControlBlock(link, id, priority, queue, task) {
|
251
|
-
this.link = link;
|
252
|
-
this.id = id;
|
253
|
-
this.priority = priority;
|
254
|
-
this.queue = queue;
|
255
|
-
this.task = task;
|
256
|
-
if (queue == null) {
|
257
|
-
this.state = STATE_SUSPENDED;
|
258
|
-
} else {
|
259
|
-
this.state = STATE_SUSPENDED_RUNNABLE;
|
260
|
-
}
|
261
|
-
}
|
262
|
-
|
263
|
-
/**
|
264
|
-
* The task is running and is currently scheduled.
|
265
|
-
*/
|
266
|
-
var STATE_RUNNING = 0;
|
267
|
-
|
268
|
-
/**
|
269
|
-
* The task has packets left to process.
|
270
|
-
*/
|
271
|
-
var STATE_RUNNABLE = 1;
|
272
|
-
|
273
|
-
/**
|
274
|
-
* The task is not currently running. The task is not blocked as such and may
|
275
|
-
* be started by the scheduler.
|
276
|
-
*/
|
277
|
-
var STATE_SUSPENDED = 2;
|
278
|
-
|
279
|
-
/**
|
280
|
-
* The task is blocked and cannot be run until it is explicitly released.
|
281
|
-
*/
|
282
|
-
var STATE_HELD = 4;
|
283
|
-
|
284
|
-
var STATE_SUSPENDED_RUNNABLE = STATE_SUSPENDED | STATE_RUNNABLE;
|
285
|
-
var STATE_NOT_HELD = ~STATE_HELD;
|
286
|
-
|
287
|
-
function tcb_setRunning() {
|
288
|
-
this.state = STATE_RUNNING;
|
289
|
-
};
|
290
|
-
|
291
|
-
function tcb_markAsNotHeld() {
|
292
|
-
this.state = this.state & STATE_NOT_HELD;
|
293
|
-
};
|
294
|
-
|
295
|
-
function tcb_markAsHeld() {
|
296
|
-
this.state = this.state | STATE_HELD;
|
297
|
-
};
|
298
|
-
|
299
|
-
function tcb_isHeldOrSuspended() {
|
300
|
-
return (this.state & STATE_HELD) != 0 || this.state == STATE_SUSPENDED;
|
301
|
-
};
|
302
|
-
|
303
|
-
function tcb_markAsSuspended() {
|
304
|
-
this.state = this.state | STATE_SUSPENDED;
|
305
|
-
};
|
306
|
-
|
307
|
-
function tcb_markAsRunnable() {
|
308
|
-
this.state = this.state | STATE_RUNNABLE;
|
309
|
-
};
|
310
|
-
|
311
|
-
/**
|
312
|
-
* Runs this task, if it is ready to be run, and returns the next task to run.
|
313
|
-
*/
|
314
|
-
function tcb_run() {
|
315
|
-
var packet;
|
316
|
-
if (this.state == STATE_SUSPENDED_RUNNABLE) {
|
317
|
-
packet = this.queue;
|
318
|
-
this.queue = packet.link;
|
319
|
-
if (this.queue == null) {
|
320
|
-
this.state = STATE_RUNNING;
|
321
|
-
} else {
|
322
|
-
this.state = STATE_RUNNABLE;
|
323
|
-
}
|
324
|
-
} else {
|
325
|
-
packet = null;
|
326
|
-
}
|
327
|
-
// Note: This remains a dynamic dispatch call as the task type isn't
|
328
|
-
// known statically here.
|
329
|
-
return this.task.run(packet);
|
330
|
-
};
|
331
|
-
|
332
|
-
/**
|
333
|
-
* Adds a packet to the worklist of this block's task, marks this as runnable if
|
334
|
-
* necessary, and returns the next runnable object to run (the one
|
335
|
-
* with the highest priority).
|
336
|
-
*/
|
337
|
-
function tcb_checkPriorityAdd(task, packet) {
|
338
|
-
if (this.queue == null) {
|
339
|
-
this.queue = packet;
|
340
|
-
tcb_markAsRunnable.call(this);
|
341
|
-
if (this.priority > task.priority) return this;
|
342
|
-
} else {
|
343
|
-
this.queue = packet_addTo.call(packet, this.queue);
|
344
|
-
}
|
345
|
-
return task;
|
346
|
-
};
|
347
|
-
|
348
|
-
function tcb_toString() {
|
349
|
-
return "tcb { " + this.task + "@" + this.state + " }";
|
350
|
-
};
|
351
|
-
|
352
|
-
/**
|
353
|
-
* An idle task doesn't do any work itself but cycles control between the two
|
354
|
-
* device tasks.
|
355
|
-
* @param {Scheduler} scheduler the scheduler that manages this task
|
356
|
-
* @param {int} v1 a seed value that controls how the device tasks are scheduled
|
357
|
-
* @param {int} count the number of times this task should be scheduled
|
358
|
-
* @constructor
|
359
|
-
*/
|
360
|
-
function IdleTask(scheduler, v1, count) {
|
361
|
-
this.scheduler = scheduler;
|
362
|
-
this.v1 = v1;
|
363
|
-
this.count = count;
|
364
|
-
}
|
365
|
-
|
366
|
-
function idleTask_run(packet) {
|
367
|
-
this.count--;
|
368
|
-
if (this.count == 0) return scheduler_holdCurrent.call(this.scheduler);
|
369
|
-
if ((this.v1 & 1) == 0) {
|
370
|
-
this.v1 = this.v1 >> 1;
|
371
|
-
return scheduler_release.call(this.scheduler, ID_DEVICE_A);
|
372
|
-
} else {
|
373
|
-
this.v1 = (this.v1 >> 1) ^ 0xd008;
|
374
|
-
return scheduler_release.call(this.scheduler, ID_DEVICE_B);
|
375
|
-
}
|
376
|
-
};
|
377
|
-
// Assign the run method to the prototype for dynamic dispatch in tcb_run
|
378
|
-
IdleTask.prototype.run = idleTask_run;
|
379
|
-
|
380
|
-
|
381
|
-
function idleTask_toString() {
|
382
|
-
return "IdleTask";
|
383
|
-
};
|
384
|
-
IdleTask.prototype.toString = idleTask_toString;
|
385
|
-
|
386
|
-
/**
|
387
|
-
* A task that suspends itself after each time it has been run to simulate
|
388
|
-
* waiting for data from an external device.
|
389
|
-
* @param {Scheduler} scheduler the scheduler that manages this task
|
390
|
-
* @constructor
|
391
|
-
*/
|
392
|
-
function DeviceTask(scheduler) {
|
393
|
-
this.scheduler = scheduler;
|
394
|
-
this.v1 = null;
|
395
|
-
}
|
396
|
-
|
397
|
-
function deviceTask_run(packet) {
|
398
|
-
if (packet == null) {
|
399
|
-
if (this.v1 == null) return scheduler_suspendCurrent.call(this.scheduler);
|
400
|
-
var v = this.v1;
|
401
|
-
this.v1 = null;
|
402
|
-
return scheduler_queue.call(this.scheduler, v);
|
403
|
-
} else {
|
404
|
-
this.v1 = packet;
|
405
|
-
return scheduler_holdCurrent.call(this.scheduler);
|
406
|
-
}
|
407
|
-
};
|
408
|
-
// Assign the run method to the prototype for dynamic dispatch in tcb_run
|
409
|
-
DeviceTask.prototype.run = deviceTask_run;
|
410
|
-
|
411
|
-
|
412
|
-
function deviceTask_toString() {
|
413
|
-
return "DeviceTask";
|
414
|
-
};
|
415
|
-
DeviceTask.prototype.toString = deviceTask_toString;
|
416
|
-
|
417
|
-
/**
|
418
|
-
* A task that manipulates work packets.
|
419
|
-
* @param {Scheduler} scheduler the scheduler that manages this task
|
420
|
-
* @param {int} v1 a seed used to specify how work packets are manipulated
|
421
|
-
* @param {int} v2 another seed used to specify how work packets are manipulated
|
422
|
-
* @constructor
|
423
|
-
*/
|
424
|
-
function WorkerTask(scheduler, v1, v2) {
|
425
|
-
this.scheduler = scheduler;
|
426
|
-
this.v1 = v1;
|
427
|
-
this.v2 = v2;
|
428
|
-
}
|
429
|
-
|
430
|
-
function workerTask_run(packet) {
|
431
|
-
if (packet == null) {
|
432
|
-
return scheduler_suspendCurrent.call(this.scheduler);
|
433
|
-
} else {
|
434
|
-
if (this.v1 == ID_HANDLER_A) {
|
435
|
-
this.v1 = ID_HANDLER_B;
|
436
|
-
} else {
|
437
|
-
this.v1 = ID_HANDLER_A;
|
438
|
-
}
|
439
|
-
packet.id = this.v1;
|
440
|
-
packet.a1 = 0;
|
441
|
-
for (var i = 0; i < DATA_SIZE; i++) {
|
442
|
-
this.v2++;
|
443
|
-
if (this.v2 > 26) this.v2 = 1;
|
444
|
-
packet.a2[i] = this.v2;
|
445
|
-
}
|
446
|
-
return scheduler_queue.call(this.scheduler, packet);
|
447
|
-
}
|
448
|
-
};
|
449
|
-
// Assign the run method to the prototype for dynamic dispatch in tcb_run
|
450
|
-
WorkerTask.prototype.run = workerTask_run;
|
451
|
-
|
452
|
-
|
453
|
-
function workerTask_toString() {
|
454
|
-
return "WorkerTask";
|
455
|
-
};
|
456
|
-
WorkerTask.prototype.toString = workerTask_toString;
|
457
|
-
|
458
|
-
/**
|
459
|
-
* A task that manipulates work packets and then suspends itself.
|
460
|
-
* @param {Scheduler} scheduler the scheduler that manages this task
|
461
|
-
* @constructor
|
462
|
-
*/
|
463
|
-
function HandlerTask(scheduler) {
|
464
|
-
this.scheduler = scheduler;
|
465
|
-
this.v1 = null;
|
466
|
-
this.v2 = null;
|
467
|
-
}
|
468
|
-
|
469
|
-
function handlerTask_run(packet) {
|
470
|
-
if (packet != null) {
|
471
|
-
if (packet.kind == KIND_WORK) {
|
472
|
-
this.v1 = packet_addTo.call(packet, this.v1);
|
473
|
-
} else {
|
474
|
-
this.v2 = packet_addTo.call(packet, this.v2);
|
475
|
-
}
|
476
|
-
}
|
477
|
-
if (this.v1 != null) {
|
478
|
-
var count = this.v1.a1;
|
479
|
-
var v;
|
480
|
-
if (count < DATA_SIZE) {
|
481
|
-
if (this.v2 != null) {
|
482
|
-
v = this.v2;
|
483
|
-
this.v2 = this.v2.link;
|
484
|
-
v.a1 = this.v1.a2[count];
|
485
|
-
this.v1.a1 = count + 1;
|
486
|
-
return scheduler_queue.call(this.scheduler, v);
|
487
|
-
}
|
488
|
-
} else {
|
489
|
-
v = this.v1;
|
490
|
-
this.v1 = this.v1.link;
|
491
|
-
return scheduler_queue.call(this.scheduler, v);
|
492
|
-
}
|
493
|
-
}
|
494
|
-
return scheduler_suspendCurrent.call(this.scheduler);
|
495
|
-
};
|
496
|
-
// Assign the run method to the prototype for dynamic dispatch in tcb_run
|
497
|
-
HandlerTask.prototype.run = handlerTask_run;
|
498
|
-
|
499
|
-
|
500
|
-
function handlerTask_toString() {
|
501
|
-
return "HandlerTask";
|
502
|
-
};
|
503
|
-
HandlerTask.prototype.toString = handlerTask_toString;
|
504
|
-
|
505
|
-
|
506
|
-
/* --- *
|
507
|
-
* P a c k e t
|
508
|
-
* --- */
|
509
|
-
|
510
|
-
var DATA_SIZE = 4;
|
511
|
-
|
512
|
-
/**
|
513
|
-
* A simple package of data that is manipulated by the tasks. The exact layout
|
514
|
-
* of the payload data carried by a packet is not importaint, and neither is the
|
515
|
-
* nature of the work performed on packets by the tasks.
|
516
|
-
*
|
517
|
-
* Besides carrying data, packets form linked lists and are hence used both as
|
518
|
-
* data and worklists.
|
519
|
-
* @param {Packet} link the tail of the linked list of packets
|
520
|
-
* @param {int} id an ID for this packet
|
521
|
-
* @param {int} kind the type of this packet
|
522
|
-
* @constructor
|
523
|
-
*/
|
524
|
-
function Packet(link, id, kind) {
|
525
|
-
this.link = link;
|
526
|
-
this.id = id;
|
527
|
-
this.kind = kind;
|
528
|
-
this.a1 = 0;
|
529
|
-
this.a2 = new Array(DATA_SIZE);
|
530
|
-
}
|
531
|
-
|
532
|
-
/**
|
533
|
-
* Add this packet to the end of a worklist, and return the worklist.
|
534
|
-
* @param {Packet} queue the worklist to add this packet to
|
535
|
-
*/
|
536
|
-
function packet_addTo(queue) {
|
537
|
-
this.link = null;
|
538
|
-
if (queue == null) return this;
|
539
|
-
var peek,
|
540
|
-
next = queue;
|
541
|
-
while ((peek = next.link) != null) next = peek;
|
542
|
-
next.link = this;
|
543
|
-
return queue;
|
544
|
-
};
|
545
|
-
|
546
|
-
|
547
|
-
function packet_toString() {
|
548
|
-
return "Packet";
|
549
|
-
};
|
550
|
-
Packet.prototype.toString = packet_toString;
|
551
|
-
|
552
|
-
|
553
|
-
const start = Date.now();
|
554
|
-
for (let i = 0; i < 100; i++) {
|
555
|
-
runRichards();
|
556
|
-
}
|
557
|
-
|
558
|
-
console.log(Date.now() - start);
|