[WIP] Implement save, load, over, infile, outfile, on, lipsum, help + start implementing undo, redo, exit, edit
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import {Command, CommandData, ParseContext, StrLVal} from "./command.js";
|
||||
import {Executable} from "../parse.js";
|
||||
import {LexInput} from "../lexer.js";
|
||||
import {StrVM} from "../vm.js";
|
||||
|
||||
export type OverData = {
|
||||
subject: StrLVal,
|
||||
@@ -22,4 +23,18 @@ export class Over extends Command<OverData> {
|
||||
isParseCandidate(token: LexInput): boolean {
|
||||
return this.isKeyword(token, 'over')
|
||||
}
|
||||
|
||||
async execute(vm: StrVM, data: OverData): Promise<StrVM> {
|
||||
return vm.tapInPlace(async parentCtx => {
|
||||
const oldValue = parentCtx.resolveRequired(data.subject)
|
||||
const newValue = await vm.runInChild(async (child, childCtx) => {
|
||||
await childCtx.replaceSubject(() => oldValue)
|
||||
await data.exec.command.execute(child, data.exec.data)
|
||||
return childCtx.getSubject()
|
||||
})
|
||||
|
||||
parentCtx.inScope(scope =>
|
||||
scope.setOrShadowValue(data.subject, newValue))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user