git @ Cat's Eye Technologies Matchbox / 597b645
Allow program to contain comments (semicolon in first column.) Chris Pressey 10 years ago
2 changed file(s) with 38 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
1313 which they write to and read from is shared between them.
1414
1515 It then computes all possible interleavings of these two programs, and
16 executes them all. Unless _all_ the interleavings leave the memory in exactly
17 the same state after execution, the programs have a race condition.
16 executes them all, each on a freshly-zeroed shared memory. Unless _all_
17 the interleavings leave the memory in exactly the same state after execution,
18 the programs have a race condition.
19
20 Example
21 -------
22
23 These two programs do not have a race condition. The reason is that
24 Matchbox's `INC` instruction atomically updates memory; two `INC`s cannot
25 run at the same time.
26
27 PROG 0
28
29 INC M0
30
31 PROG 1
32
33 INC M1
34
35 But the following two programs _do_ have a race condition:
36
37 PROG 0
38
39 MOV M0, R0
40 INC R0
41 MOV R0, M0
42
43 PROG 1
44
45 MOV M0, R0
46 INC R0
47 MOV R0, M0
48
49 The reason is that the second program's `MOV M0, R0` might happen before
50 the first program's `MOV R0, M0` — in which case M0 = 1 at the end — or it
51 might happen after — in which case M0 = 2.
1852
1953 TODO
2054 ----
2458 * discard impossible run traces (once we have WAIT)
2559 * ability to break on first inconsistent result (for long programs)
2660 * more instructions
27 * allow comments in programs
61 * better error handling
2862 * load both programs from single source file
2963 * write a few words about atomic operations
3064 * implement some of those classic race-condition-free algorithms w/o
194194 var lines = str.split("\n");
195195 this.code = [];
196196 for (var i = 0; i < lines.length; i++) {
197 if (!lines[i] || lines[i].charAt(0) === ';') continue;
197198 var instr = (new Instruction()).init({
198199 'reg': reg
199200 });
200 if (!lines[i]) continue;
201201 if (instr.parse(lines[i])) {
202202 this.code.push(instr);
203203 } else {