Skip to content

Commit

Permalink
Implement resetRam test command (#462)
Browse files Browse the repository at this point in the history
  • Loading branch information
netalondon authored Sep 17, 2024
1 parent fab8cec commit 752ce6f
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 2 deletions.
3 changes: 3 additions & 0 deletions simulator/src/languages/grammars/tst.ohm
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Tst <: Base {
| TstEchoOperation
| TstClearEchoOperation
| TstLoadROMOperation
| TstResetRAMOperation

TstLoadROMOperation = ROM32K Load FileName
TstFileOperation = FileOperation FileName?
Expand All @@ -31,6 +32,7 @@ Tst <: Base {
TstOutputOperation = Output
TstEchoOperation = Echo String
TstClearEchoOperation = ClearEcho
TstResetRAMOperation = ResetRAM

FileName = Name
FileOperation = "load" | "output-file" | "compare-to"
Expand All @@ -50,6 +52,7 @@ Tst <: Base {
ROM32K = "ROM32K"
Load = "load"
While = "while"
ResetRAM = "resetRam"

CompareOp = "<>" | "<=" | ">=" | "=" | "<" | ">"
}
3 changes: 3 additions & 0 deletions simulator/src/languages/grammars/tst.ohm.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Tst <: Base {
| TstEchoOperation
| TstClearEchoOperation
| TstLoadROMOperation
| TstResetRAMOperation
TstLoadROMOperation = ROM32K Load FileName
TstFileOperation = FileOperation FileName?
Expand All @@ -32,6 +33,7 @@ Tst <: Base {
TstOutputOperation = Output
TstEchoOperation = Echo String
TstClearEchoOperation = ClearEcho
TstResetRAMOperation = ResetRAM
FileName = Name
FileOperation = "load" | "output-file" | "compare-to"
Expand All @@ -51,6 +53,7 @@ Tst <: Base {
ROM32K = "ROM32K"
Load = "load"
While = "while"
ResetRAM = "resetRam"
CompareOp = "<>" | "<=" | ">=" | "=" | "<" | ">"
}`;
Expand Down
12 changes: 11 additions & 1 deletion simulator/src/languages/tst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ export interface TstFileOperation {
file?: string;
}

export interface TstResetRamOperation {
op: "resetRam";
}

export type TstOperation =
| TstFileOperation
| TstEvalOperation
Expand All @@ -64,7 +68,8 @@ export type TstOperation =
| TstOutputOperation
| TstSetOperation
| TstOutputListOperation
| TstLoadROMOperation;
| TstLoadROMOperation
| TstResetRamOperation;

export type Separator = "," | ";" | "!";

Expand Down Expand Up @@ -198,6 +203,11 @@ tstSemantics.addAttribute<TstOperation>("operation", {
file: file?.sourceString,
};
},
TstResetRAMOperation(_) {
return {
op: "resetRam",
};
},
});

tstSemantics.addAttribute<TstCommand>("command", {
Expand Down
4 changes: 3 additions & 1 deletion simulator/src/test/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
TestTickInstruction,
TestTockInstruction,
} from "./chiptst.js";
import { TestTickTockInstruction } from "./cputst.js";
import { TestResetRamInstruction, TestTickTockInstruction } from "./cputst.js";
import {
Condition,
TestBreakInstruction,
Expand Down Expand Up @@ -69,6 +69,8 @@ function makeInstruction(inst: TstOperation) {
case "output-file":
case "compare-to":
return undefined;
case "resetRam":
return new TestResetRamInstruction();
default:
checkExhaustive(op, `Unknown tst operation ${op}`);
}
Expand Down
11 changes: 11 additions & 0 deletions simulator/src/test/cputst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,14 @@ export class TestTickTockInstruction implements CPUTestInstruction {
yield this;
}
}

export class TestResetRamInstruction implements CPUTestInstruction {
readonly _cpuTestInstruction_ = true;
async do(test: CPUTest) {
test.cpu.RAM.reset();
}

*steps() {
yield this;
}
}
1 change: 1 addition & 0 deletions web/src/languages/tst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const TstLanguage: monaco.languages.IMonarchLanguage = {
"repeat",
"while",
"load",
"resetRam",
],

// The main tokenizer for our languages
Expand Down

0 comments on commit 752ce6f

Please sign in to comment.