Implement basic integer math operations
This commit is contained in:
24
src/vm/commands/abs.ts
Normal file
24
src/vm/commands/abs.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
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),
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user