Implement basic integer math operations

This commit is contained in:
2026-08-01 13:50:24 -05:00
parent e728c3fdfa
commit 6e0eb2786e
8 changed files with 521 additions and 166 deletions

29
src/vm/commands/times.ts Normal file
View File

@@ -0,0 +1,29 @@
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),
}))
}
}