wip: working on extern in VM
- Feat: add usage of vm reader instead of old way in vm.c - Ref: update debug opcodes printing
This commit is contained in:
+21
-20
@@ -1,4 +1,5 @@
|
||||
#include <common/fzl_opcodes.h>
|
||||
#include <common/fzl_value.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <vm/fzl_vm.h>
|
||||
@@ -8,36 +9,36 @@ void fzl_vm_print_ops(fzl_vm_t *vm)
|
||||
if (!vm)
|
||||
return;
|
||||
|
||||
if (vm->ops_count < 1)
|
||||
if (vm->reader->ops_count < 1)
|
||||
{
|
||||
printf("no opcodes\n");
|
||||
return;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < vm->ops_count; i++)
|
||||
for (size_t i = 0; i < vm->reader->ops_count; i++)
|
||||
{
|
||||
printf("%04ld: ", i);
|
||||
|
||||
switch (vm->ops[i])
|
||||
switch (vm->reader->ops[i])
|
||||
{
|
||||
case FZL_OPCODE_STORE_LOCAL:
|
||||
{
|
||||
size_t depth = vm->ops[++i];
|
||||
size_t slot = vm->ops[++i];
|
||||
size_t depth = vm->reader->ops[++i];
|
||||
size_t slot = vm->reader->ops[++i];
|
||||
printf("STORE_LOCAL D=%zu S=%zu\n", depth, slot);
|
||||
break;
|
||||
}
|
||||
|
||||
case FZL_OPCODE_LOAD_LOCAL:
|
||||
{
|
||||
size_t depth = vm->ops[++i];
|
||||
size_t slot = vm->ops[++i];
|
||||
size_t depth = vm->reader->ops[++i];
|
||||
size_t slot = vm->reader->ops[++i];
|
||||
printf("LOAD_LOCAL D=%zu S=%zu\n", depth, slot);
|
||||
break;
|
||||
}
|
||||
|
||||
case FZL_OPCODE_BUILD_STR:
|
||||
printf("BUILD_STR %zu\n", vm->ops[++i]);
|
||||
printf("BUILD_STR %zu\n", vm->reader->ops[++i]);
|
||||
break;
|
||||
|
||||
case FZL_OPCODE_DEREFERENCE:
|
||||
@@ -65,20 +66,20 @@ void fzl_vm_print_ops(fzl_vm_t *vm)
|
||||
break;
|
||||
|
||||
case FZL_OPCODE_ALLOC_OBJECT:
|
||||
printf("ALLOC_OBJECT: %lu fields\n", vm->ops[++i]);
|
||||
printf("ALLOC_OBJECT: %lu fields\n", vm->reader->ops[++i]);
|
||||
break;
|
||||
|
||||
case FZL_OPCODE_GET_FIELD:
|
||||
printf("GET_FIELD #%lu\n", vm->ops[++i]);
|
||||
printf("GET_FIELD #%lu\n", vm->reader->ops[++i]);
|
||||
break;
|
||||
|
||||
case FZL_OPCODE_SET_FIELD:
|
||||
printf("SET_FIELD #%lu\n", vm->ops[++i]);
|
||||
printf("SET_FIELD #%lu\n", vm->reader->ops[++i]);
|
||||
break;
|
||||
|
||||
case FZL_OPCODE_CALL:
|
||||
{
|
||||
size_t ip = vm->ops[++i];
|
||||
size_t ip = vm->reader->ops[++i];
|
||||
printf("CALL IP: %lu\n", ip);
|
||||
break;
|
||||
}
|
||||
@@ -89,22 +90,22 @@ void fzl_vm_print_ops(fzl_vm_t *vm)
|
||||
|
||||
case FZL_OPCODE_LOADCONST:
|
||||
{
|
||||
size_t const_n = vm->ops[++i];
|
||||
fzl_const_t c = vm->consts[const_n];
|
||||
printf("LOADCONST #%lu ('%s')\n", const_n, c.as.string.chars);
|
||||
size_t const_n = vm->reader->ops[++i];
|
||||
fzl_value_t c = vm->reader->consts[const_n];
|
||||
printf("LOADCONST #%lu ('%s')\n", const_n, c.as.s.value);
|
||||
break;
|
||||
}
|
||||
|
||||
case FZL_OPCODE_CALL_BUILTIN:
|
||||
printf("CALL_BUILTIN #%lu\n", vm->ops[++i]);
|
||||
printf("CALL_BUILTIN #%lu\n", vm->reader->ops[++i]);
|
||||
break;
|
||||
|
||||
case FZL_OPCODE_PUSHNUM:
|
||||
printf("PUSHNUM %lu\n", vm->ops[++i]);
|
||||
printf("PUSHNUM %lu\n", vm->reader->ops[++i]);
|
||||
break;
|
||||
|
||||
case FZL_OPCODE_PUSHBOOL:
|
||||
printf("PUSHBOOL %s\n", vm->ops[++i] ? "true" : "false");
|
||||
printf("PUSHBOOL %s\n", vm->reader->ops[++i] ? "true" : "false");
|
||||
break;
|
||||
|
||||
case FZL_OPCODE_MK_ENVTABLE:
|
||||
@@ -177,11 +178,11 @@ void fzl_vm_print_ops(fzl_vm_t *vm)
|
||||
break;
|
||||
|
||||
case FZL_OPCODE_JZ:
|
||||
printf("JZ IP: %ld\n", vm->ops[++i]);
|
||||
printf("JZ IP: %ld\n", vm->reader->ops[++i]);
|
||||
break;
|
||||
|
||||
case FZL_OPCODE_JMP:
|
||||
printf("JMP IP: %ld\n", vm->ops[++i]);
|
||||
printf("JMP IP: %ld\n", vm->reader->ops[++i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user