From ab9ef458956c74ee459265e15ab769dc222ceac6 Mon Sep 17 00:00:00 2001 From: ketmar Date: Thu, 15 Mar 2012 05:02:49 +0200 Subject: [PATCH] VM: extended BSR command --- src/awasm.c | 21 ++++++++++++++++++++- src/vm.c | 19 ++++++++++++++++--- vm.txt | 2 +- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/awasm.c b/src/awasm.c index 1c58498..81305fd 100644 --- a/src/awasm.c +++ b/src/awasm.c @@ -687,6 +687,25 @@ static void doBranch (int opcode) { } +static void doBSR (int opcode) { + OperandInfo op0, op1, op2; + // + op0.var = op1.var = op2.var = -1; + if (hasOperand()) { + getOperand(&op0, 1); + if (token == ',') { + nextToken(); + getOperand(&op1, 0); + if (token == ',') { + nextToken(); + getOperand(&op2, 0); + } + } + } + emitInstruction(opcode, &op0, &op1, &op2); +} + + static void doMap (int opcode, int lastMBV) { OperandInfo op0, op1, op2; // @@ -1380,7 +1399,7 @@ static void process (void) { doNoOperands(opc); break; case VM_BSR: - doBranch(opc); + doBSR(opc); break; case VM_NEW: doNew(opc); diff --git a/src/vm.c b/src/vm.c index 10a9054..a4f26ac 100644 --- a/src/vm.c +++ b/src/vm.c @@ -338,9 +338,22 @@ static int vmExecuteOne (int tid) { break; case VM_BSR: - if (argc == 0) { - STACK_WANT(1); - argv[0] = STACK_POP(); + switch (argc) { + case 0: + STACK_WANT(1); + argv[0] = STACK_POP(); + break; + case 1: + break; + case 2: + STACK_FSPC(1); + STACK_PUSH(argv[1]); + break; + case 3: + STACK_FSPC(2); + STACK_PUSH(argv[1]); + STACK_PUSH(argv[2]); + break; } STACK_FSPC(1); STACK_PUSH(trd->pc); diff --git a/vm.txt b/vm.txt index b54284c..e0e4710 100644 --- a/vm.txt +++ b/vm.txt @@ -61,7 +61,7 @@ opcodes: ; opcode 15 ; no args: pc=pop - ; 1-3 args: pc=arg0 + ; 1-3 args: pc=arg0, arg1 and arg2 will be pushed on stack VM_BSR ; 'call'; use JMP w/o args to return (asm understands RET mnemonics) ; opcode 16 -- 2.11.4.GIT