From b5d3c8725335d18c69e84c4a01adb7ef27a5d473 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Sun, 9 Jul 2023 21:28:08 -0500 Subject: [PATCH] Add new opcode subtract immediate. --- src/core/asm.c | 1 + src/core/bytecode.c | 2 ++ src/core/cfuns.c | 2 +- src/core/vm.c | 5 ++++- src/include/janet.h | 1 + 5 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/core/asm.c b/src/core/asm.c index e5712cc1..14fa28c0 100644 --- a/src/core/asm.c +++ b/src/core/asm.c @@ -138,6 +138,7 @@ static const JanetInstructionDef janet_ops[] = { {"sru", JOP_SHIFT_RIGHT_UNSIGNED}, {"sruim", JOP_SHIFT_RIGHT_UNSIGNED_IMMEDIATE}, {"sub", JOP_SUBTRACT}, + {"subim", JOP_SUBTRACT_IMMEDIATE}, {"tcall", JOP_TAILCALL}, {"tchck", JOP_TYPECHECK} }; diff --git a/src/core/bytecode.c b/src/core/bytecode.c index 821bf42d..e0b25cfd 100644 --- a/src/core/bytecode.c +++ b/src/core/bytecode.c @@ -37,6 +37,7 @@ enum JanetInstructionType janet_instructions[JOP_INSTRUCTION_COUNT] = { JINT_0, /* JOP_RETURN_NIL, */ JINT_SSI, /* JOP_ADD_IMMEDIATE, */ JINT_SSS, /* JOP_ADD, */ + JINT_SSI, /* JOP_SUBTRACT_IMMEDIATE, */ JINT_SSS, /* JOP_SUBTRACT, */ JINT_SSI, /* JOP_MULTIPLY_IMMEDIATE, */ JINT_SSS, /* JOP_MULTIPLY, */ @@ -251,6 +252,7 @@ void janet_bytecode_movopt(JanetFuncDef *def) { case JOP_SIGNAL: /* Write A, Read B */ case JOP_ADD_IMMEDIATE: + case JOP_SUBTRACT_IMMEDIATE: case JOP_MULTIPLY_IMMEDIATE: case JOP_DIVIDE_IMMEDIATE: case JOP_SHIFT_LEFT_IMMEDIATE: diff --git a/src/core/cfuns.c b/src/core/cfuns.c index be61da80..13c86dec 100644 --- a/src/core/cfuns.c +++ b/src/core/cfuns.c @@ -260,7 +260,7 @@ static JanetSlot do_add(JanetFopts opts, JanetSlot *args) { return opreduce(opts, args, JOP_ADD, JOP_ADD_IMMEDIATE, janet_wrap_integer(0), janet_wrap_integer(0)); } static JanetSlot do_sub(JanetFopts opts, JanetSlot *args) { - return opreduce(opts, args, JOP_SUBTRACT, -JOP_ADD_IMMEDIATE, janet_wrap_integer(0), janet_wrap_integer(0)); + return opreduce(opts, args, JOP_SUBTRACT, JOP_SUBTRACT_IMMEDIATE, janet_wrap_integer(0), janet_wrap_integer(0)); } static JanetSlot do_mul(JanetFopts opts, JanetSlot *args) { return opreduce(opts, args, JOP_MULTIPLY, JOP_MULTIPLY_IMMEDIATE, janet_wrap_integer(1), janet_wrap_integer(1)); diff --git a/src/core/vm.c b/src/core/vm.c index 132d8c09..5e881772 100644 --- a/src/core/vm.c +++ b/src/core/vm.c @@ -347,6 +347,7 @@ static JanetSignal run_vm(JanetFiber *fiber, Janet in) { &&label_JOP_RETURN_NIL, &&label_JOP_ADD_IMMEDIATE, &&label_JOP_ADD, + &&label_JOP_SUBTRACT_IMMEDIATE, &&label_JOP_SUBTRACT, &&label_JOP_MULTIPLY_IMMEDIATE, &&label_JOP_MULTIPLY, @@ -593,7 +594,6 @@ static JanetSignal run_vm(JanetFiber *fiber, Janet in) { &&label_unknown_op, &&label_unknown_op, &&label_unknown_op, - &&label_unknown_op, &&label_unknown_op }; #endif @@ -683,6 +683,9 @@ static JanetSignal run_vm(JanetFiber *fiber, Janet in) { VM_OP(JOP_ADD) vm_binop(+); + VM_OP(JOP_SUBTRACT_IMMEDIATE) + vm_binop_immediate(-); + VM_OP(JOP_SUBTRACT) vm_binop(-); diff --git a/src/include/janet.h b/src/include/janet.h index ada92277..e59318f1 100644 --- a/src/include/janet.h +++ b/src/include/janet.h @@ -1262,6 +1262,7 @@ enum JanetOpCode { JOP_RETURN_NIL, JOP_ADD_IMMEDIATE, JOP_ADD, + JOP_SUBTRACT_IMMEDIATE, JOP_SUBTRACT, JOP_MULTIPLY_IMMEDIATE, JOP_MULTIPLY,