aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--vm/runtime.c14
-rw-r--r--vm/runtime.h7
2 files changed, 17 insertions, 4 deletions
diff --git a/vm/runtime.c b/vm/runtime.c
index 8a3ce2e..67c288c 100644
--- a/vm/runtime.c
+++ b/vm/runtime.c
@@ -60,7 +60,7 @@ const char *err_as_cstr(err_t err)
err_t vm_execute(vm_t *vm)
{
- static_assert(NUMBER_OF_OPCODES == 83, "vm_execute: Out of date");
+ static_assert(NUMBER_OF_OPCODES == 84, "vm_execute: Out of date");
struct Program *prog = &vm->program;
if (prog->ptr >= prog->max)
return ERR_END_OF_PROGRAM;
@@ -113,7 +113,7 @@ err_t vm_execute(vm_t *vm)
OPCODE_IS_TYPE(instruction.opcode, OP_GTE) ||
OPCODE_IS_TYPE(instruction.opcode, OP_PLUS) ||
OPCODE_IS_TYPE(instruction.opcode, OP_MULT) ||
- instruction.opcode == OP_MDELETE)
+ instruction.opcode == OP_MDELETE || instruction.opcode == OP_MSIZE)
{
prog->ptr++;
return STACK_ROUTINES[instruction.opcode](vm);
@@ -817,6 +817,16 @@ err_t vm_mdelete(vm_t *vm)
return ERR_OK;
}
+err_t vm_msize(vm_t *vm)
+{
+ data_t ptr = {0};
+ err_t err = vm_pop_word(vm, &ptr);
+ if (err)
+ return err;
+ page_t *page = (page_t *)ptr.as_word;
+ return vm_push_word(vm, DWORD(page->available));
+}
+
#define VM_NOT_TYPE(TYPEL, TYPEU) \
err_t vm_not_##TYPEL(vm_t *vm) \
{ \
diff --git a/vm/runtime.h b/vm/runtime.h
index c8f5d49..9bb61bc 100644
--- a/vm/runtime.h
+++ b/vm/runtime.h
@@ -138,6 +138,7 @@ static const word_f WORD_ROUTINES[] = {
};
err_t vm_mdelete(vm_t *);
+err_t vm_msize(vm_t *);
err_t vm_not_byte(vm_t *);
err_t vm_not_hword(vm_t *);
@@ -200,8 +201,10 @@ err_t vm_mult_word(vm_t *);
typedef err_t (*stack_f)(vm_t *);
static const stack_f STACK_ROUTINES[] = {
- [OP_MDELETE] = vm_mdelete, [OP_NOT_BYTE] = vm_not_byte,
- [OP_NOT_HWORD] = vm_not_hword, [OP_NOT_WORD] = vm_not_word,
+ [OP_MDELETE] = vm_mdelete, [OP_MSIZE] = vm_msize,
+
+ [OP_NOT_BYTE] = vm_not_byte, [OP_NOT_HWORD] = vm_not_hword,
+ [OP_NOT_WORD] = vm_not_word,
[OP_OR_BYTE] = vm_or_byte, [OP_OR_HWORD] = vm_or_hword,
[OP_OR_WORD] = vm_or_word,