51 lines
914 B
C
51 lines
914 B
C
#ifndef FZL_VM_H
|
|
#define FZL_VM_H
|
|
|
|
#include <common/fzl_value.h>
|
|
#include <compiler/utils/fzl_const_pool.h> // NOTE: move outside compiler scope to common
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
#include <vm/fzl_vm_env.h>
|
|
#include <vm/fzl_vm_object.h>
|
|
|
|
// VM descriptor
|
|
typedef struct
|
|
{
|
|
fzl_const_t *consts;
|
|
size_t consts_count;
|
|
|
|
uint64_t *ops;
|
|
size_t ops_count;
|
|
|
|
size_t ip;
|
|
|
|
// Data stack
|
|
fzl_value_t dstack[256];
|
|
size_t dtop;
|
|
|
|
// Call stack
|
|
size_t cstack[256];
|
|
size_t ctop;
|
|
|
|
// Environment stack
|
|
fzl_vm_env_t *estack[256];
|
|
size_t etop;
|
|
} fzl_vm_t;
|
|
|
|
// Allocate FZL VM
|
|
fzl_vm_t *fzl_mkvm(const char *filepath);
|
|
|
|
// Load and run code
|
|
int fzl_vm_run(fzl_vm_t *vm, bool allow_infinite, uint64_t max_iter);
|
|
|
|
// Get last VM error message
|
|
char *fzl_vm_geterror();
|
|
|
|
// Print opcodes sequence
|
|
void fzl_vm_print_ops(fzl_vm_t *vm);
|
|
|
|
// Free VM
|
|
void fzl_freevm(fzl_vm_t *vm);
|
|
|
|
#endif // FZL_VM_H
|