feat: optimize VM using dispatch table
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
#include <string.h>
|
||||
#include <vm/fzl_vm.h>
|
||||
#include <vm/internals/opcode.h>
|
||||
|
||||
int op_cmp_eq_str(fzl_vm_t *vm)
|
||||
{
|
||||
if (vm->dtop < 2)
|
||||
{
|
||||
snprintf(last_err, sizeof(last_err),
|
||||
"runtime error - expected two values in data stack");
|
||||
print_err_data(vm);
|
||||
return -1;
|
||||
}
|
||||
fzl_value_t left = vm->dstack[--vm->dtop];
|
||||
fzl_value_t right = vm->dstack[--vm->dtop];
|
||||
|
||||
int result = strcmp(left.as.s.value, right.as.s.value);
|
||||
vm->dstack[vm->dtop++] =
|
||||
(fzl_value_t){.type = FZL_TYPE_BOOL, .as.b = result == 0};
|
||||
return 0;
|
||||
}
|
||||
|
||||
int op_cmp_neq_str(fzl_vm_t *vm)
|
||||
{
|
||||
if (vm->dtop < 2)
|
||||
{
|
||||
snprintf(last_err, sizeof(last_err),
|
||||
"runtime error - expected two values in data stack");
|
||||
print_err_data(vm);
|
||||
return -1;
|
||||
}
|
||||
fzl_value_t left = vm->dstack[--vm->dtop];
|
||||
fzl_value_t right = vm->dstack[--vm->dtop];
|
||||
|
||||
int result = strcmp(left.as.s.value, right.as.s.value);
|
||||
vm->dstack[vm->dtop++] =
|
||||
(fzl_value_t){.type = FZL_TYPE_BOOL, .as.b = result != 0};
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user