Implement push command

This commit is contained in:
2026-07-07 09:22:22 -05:00
parent faf3a16767
commit e728c3fdfa
4 changed files with 39 additions and 1 deletions

View File

@@ -59,6 +59,7 @@ import {Unless} from "./unless.js";
import {Convert} from "./convert.js";
import {While} from "./while.js";
import {Table} from "./table.js";
import {Push} from "./push.js";
export type Commands = Command<CommandData>[]
export const commands: Commands = [
@@ -96,6 +97,7 @@ export const commands: Commands = [
new Over,
new Paste,
new Prefix,
new Push,
new Quote,
new Redo,
new Replace,

32
src/vm/commands/push.ts Normal file
View File

@@ -0,0 +1,32 @@
import {Command, ParseContext, StrTerm} from "./command.js";
import {LexInput} from "../lexer.js";
import {StrVM} from "../vm.js";
export type PushData = {
val: StrTerm,
}
export class Push extends Command<PushData> {
async attemptParse(context: ParseContext): Promise<PushData> {
return {
val: await context.popTerm(),
}
}
getDisplayName(): string {
return 'push'
}
isParseCandidate(token: LexInput): boolean {
return this.isKeyword(token, 'push')
}
async execute(vm: StrVM, data: PushData): Promise<StrVM> {
return vm.replaceContextMatchingTerm(ctx => ({
destructured: parts => [
...parts,
{ value: ctx.resolveRequired(data.val) },
],
}))
}
}