Files
str/src/vm/commands/times.ts

30 lines
729 B
TypeScript

import {Command, ParseContext, StrTerm} from "./command.js";
import {LexInput} from "../lexer.js";
import {StrVM} from "../vm.js";
export type TimesData = {
val: StrTerm,
}
export class Times extends Command<TimesData> {
async attemptParse(context: ParseContext): Promise<TimesData> {
return {
val: await context.popTerm(),
}
}
getDisplayName(): string {
return 'times'
}
isParseCandidate(token: LexInput): boolean {
return this.isKeyword(token, 'times')
}
async execute(vm: StrVM, data: TimesData): Promise<StrVM> {
return vm.replaceContextMatchingTerm(ctx => ({
int: sub => sub * ctx.resolveInt(data.val),
}))
}
}