feat: implement conditions

This commit is contained in:
samsonium
2026-10-14 19:56:27 +03:00
parent 4a908f9fd8
commit 83ff0b5774
11 changed files with 731 additions and 25 deletions
+56 -2
View File
@@ -1,4 +1,5 @@
#include "common/fzl_opcodes.h"
#include <stdbool.h>
#include <stdio.h>
#include <vm/fzl_vm.h>
@@ -15,11 +16,17 @@ void fzl_vm_print_ops(fzl_vm_t *vm)
for (size_t i = 0; i < vm->ops_count; i++)
{
printf("%04ld: ", i);
switch (vm->ops[i])
{
case FZL_OPCODE_LOADCONST:
printf("LOADCONST #%lu\n", vm->ops[++i]);
{
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);
break;
}
case FZL_OPCODE_CALL_BUILTIN:
printf("CALL_BUILTIN #%lu\n", vm->ops[++i]);
@@ -29,6 +36,10 @@ void fzl_vm_print_ops(fzl_vm_t *vm)
printf("PUSHNUM %lu\n", vm->ops[++i]);
break;
case FZL_OPCODE_PUSHBOOL:
printf("PUSHBOOL %s\n", vm->ops[++i] ? "true" : "false");
break;
case FZL_OPCODE_MK_ENVTABLE:
printf("MK_ENVTABLE\n");
break;
@@ -58,12 +69,55 @@ void fzl_vm_print_ops(fzl_vm_t *vm)
printf("Math opcode\n");
break;
case FZL_OPCODE_AND:
printf("AND\n");
break;
case FZL_OPCODE_OR:
printf("OR\n");
break;
case FZL_OPCODE_CMP_EQ:
printf("CMP_EQ\n");
case FZL_OPCODE_CMP_NEQ:
printf("CMP_NEQ\n");
break;
case FZL_OPCODE_CMP_LT:
printf("CMP_LT\n");
break;
case FZL_OPCODE_CMP_LTEQ:
printf("CMP_LTEQ\n");
break;
case FZL_OPCODE_CMP_GT:
printf("CMP_GT\n");
break;
case FZL_OPCODE_CMP_GTEQ:
printf("CMP_GTEQ\n");
break;
case FZL_OPCODE_NOT:
printf("CMP_NOT\n");
break;
case FZL_OPCODE_NEG:
printf("NEG\n");
break;
case FZL_OPCODE_JZ:
printf("JZ IP: %ld\n", vm->ops[++i]);
break;
case FZL_OPCODE_JMP:
printf("JMP IP %ld\n", vm->ops[++i]);
break;
default:
printf("Unknown");
printf("<Unknown>\n");
}
}
}