wip: working on extern in VM

- Feat: add writer externs writing fns
- Feat: add VM reader functions
This commit is contained in:
samsonium
2026-11-05 21:48:40 +03:00
parent 84572edb0d
commit 1db42c1e8e
17 changed files with 608 additions and 16 deletions
+43
View File
@@ -0,0 +1,43 @@
#ifndef FZL_VM_READER_H
#define FZL_VM_READER_H
#include <common/fzl_extern.h>
#include <common/fzl_value.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
// Binary file reader descriptor
typedef struct
{
char *filepath;
fzl_value_t *consts;
uint16_t consts_count;
size_t *ops;
size_t ops_count;
char **extern_libs;
uint16_t extern_libs_count;
fzl_extern_type_t *extern_types;
uint16_t extern_types_count;
fzl_extern_fn_t *extern_fns;
uint16_t extern_fns_count;
} fzl_vm_reader_t;
// Allocate binary file reader
fzl_vm_reader_t *fzl_vm_mkreader(char *filepath);
// Read the file
bool fzl_vm_read(fzl_vm_reader_t *reader);
// Get last error message from the reader
char *fzl_vm_getreadererror();
// Free file reader
void fzl_vm_freereader(fzl_vm_reader_t *reader);
#endif // FZL_VM_READER_H
+22
View File
@@ -0,0 +1,22 @@
#ifndef INTERNALS_VM_READER_H
#define INTERNALS_VM_READER_H
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <vm/fzl_vm_reader.h>
bool vm_rd_char(FILE *fd, size_t count, char *outbuf);
bool vm_rd_u16(FILE *fd, size_t count, uint16_t *outbuf);
bool vm_rd_word(FILE *fd, size_t count, size_t *outbuf);
bool vm_rd_header(fzl_vm_reader_t *reader, FILE *fd);
bool vm_rd_sections_sz(fzl_vm_reader_t *reader, FILE *fd);
bool vm_rd_consts(fzl_vm_reader_t *reader, FILE *fd);
bool vm_rd_extern_libs(fzl_vm_reader_t *reader, FILE *fd);
bool vm_rd_extern_types(fzl_vm_reader_t *reader, FILE *fd);
bool vm_rd_extern_fns(fzl_vm_reader_t *reader, FILE *fd);
bool vm_rd_ops(fzl_vm_reader_t *reader, FILE *fd);
#endif // INTERNALS_VM_READER_H