25 lines
567 B
TypeScript
25 lines
567 B
TypeScript
import {Command} from "./command.js";
|
|
import {LexInput} from "../lexer.js";
|
|
import {StrVM} from "../vm.js";
|
|
import {Awaitable} from "../../util/types.js";
|
|
|
|
export class Abs extends Command<{}> {
|
|
attemptParse(): Awaitable<{}> {
|
|
return {}
|
|
}
|
|
|
|
getDisplayName(): string {
|
|
return 'abs'
|
|
}
|
|
|
|
isParseCandidate(token: LexInput): boolean {
|
|
return this.isKeyword(token, 'abs')
|
|
}
|
|
|
|
async execute(vm: StrVM): Promise<StrVM> {
|
|
return vm.replaceContextMatchingTerm({
|
|
int: sub => Math.abs(sub),
|
|
})
|
|
}
|
|
}
|