113 lines
2.4 KiB
C
113 lines
2.4 KiB
C
#ifndef INTERNALS_OPCODE_H
|
|
#define INTERNALS_OPCODE_H
|
|
|
|
#include "vm/fzl_vm.h"
|
|
#include <stddef.h>
|
|
|
|
// Opcode handler descriptor
|
|
typedef int (*opcode_handler)(fzl_vm_t *);
|
|
|
|
extern char last_err[512];
|
|
extern size_t last_jmp_ip;
|
|
extern size_t total_jmp_on_same;
|
|
|
|
void print_object(fzl_vm_object_t *obj);
|
|
void print_err_data(fzl_vm_t *vm);
|
|
void escape_recursive(fzl_vm_env_t *current, fzl_vm_env_t *parent,
|
|
fzl_vm_object_t *obj);
|
|
|
|
// --- stack ---
|
|
|
|
extern const opcode_handler group_stack[];
|
|
|
|
int op_loadconst(fzl_vm_t *vm);
|
|
int op_call_builtin(fzl_vm_t *vm);
|
|
int op_pushnum(fzl_vm_t *vm);
|
|
int op_pushbool(fzl_vm_t *vm);
|
|
|
|
// --- context ---
|
|
|
|
extern const opcode_handler group_ctx[];
|
|
|
|
int op_mk_envtable(fzl_vm_t *vm);
|
|
int op_rm_envtable(fzl_vm_t *vm);
|
|
int op_store(fzl_vm_t *vm);
|
|
int op_lookup_env(fzl_vm_t *vm);
|
|
int op_write(fzl_vm_t *vm);
|
|
int op_load_local(fzl_vm_t *vm);
|
|
int op_store_local(fzl_vm_t *vm);
|
|
|
|
// --- flow ---
|
|
|
|
extern const opcode_handler group_flow[];
|
|
|
|
int op_jmp(fzl_vm_t *vm);
|
|
int op_jz(fzl_vm_t *vm);
|
|
|
|
// --- functions ---
|
|
|
|
extern const opcode_handler group_fn[];
|
|
|
|
int op_call(fzl_vm_t *vm);
|
|
int op_ret(fzl_vm_t *vm);
|
|
int op_call_extern(fzl_vm_t *vm);
|
|
|
|
// --- objects ---
|
|
|
|
extern const opcode_handler group_obj[];
|
|
|
|
int op_alloc_object(fzl_vm_t *vm);
|
|
int op_get_field(fzl_vm_t *vm);
|
|
int op_set_field(fzl_vm_t *vm);
|
|
int op_escape_object(fzl_vm_t *vm);
|
|
int op_dereference(fzl_vm_t *vm);
|
|
|
|
// --- math ---
|
|
|
|
extern const opcode_handler group_math[];
|
|
|
|
int op_add(fzl_vm_t *vm);
|
|
int op_sub(fzl_vm_t *vm);
|
|
int op_mul(fzl_vm_t *vm);
|
|
int op_div(fzl_vm_t *vm);
|
|
int op_pow(fzl_vm_t *vm);
|
|
int op_mod(fzl_vm_t *vm);
|
|
int op_neg(fzl_vm_t *vm);
|
|
|
|
// --- strings ---
|
|
|
|
extern const opcode_handler group_str[];
|
|
|
|
int op_build_str(fzl_vm_t *vm);
|
|
|
|
// --- conditions ---
|
|
|
|
extern const opcode_handler group_cmp[];
|
|
int op_cmp_eq(fzl_vm_t *vm);
|
|
int op_cmp_neq(fzl_vm_t *vm);
|
|
int op_cmp_lt(fzl_vm_t *vm);
|
|
int op_cmp_lteq(fzl_vm_t *vm);
|
|
int op_cmp_gt(fzl_vm_t *vm);
|
|
int op_cmp_gteq(fzl_vm_t *vm);
|
|
|
|
extern const opcode_handler group_strcmp[];
|
|
int op_cmp_eq_str(fzl_vm_t *vm);
|
|
int op_cmp_neq_str(fzl_vm_t *vm);
|
|
|
|
extern const opcode_handler group_objcmp[];
|
|
int op_cmp_eq_obj(fzl_vm_t *vm);
|
|
int op_cmp_neq_obj(fzl_vm_t *vm);
|
|
|
|
extern const opcode_handler group_and_or[];
|
|
int op_and(fzl_vm_t *vm);
|
|
int op_or(fzl_vm_t *vm);
|
|
|
|
extern const opcode_handler group_not[];
|
|
int op_not(fzl_vm_t *vm);
|
|
|
|
// ------------------------
|
|
|
|
extern const opcode_handler *const master_tbl[];
|
|
|
|
#endif // INTERNALS_OPCODE_H
|