modules: 'rebase' from byterun_with_modules, initial impl, without verification

This commit is contained in:
ProgramSnail 2025-01-08 23:52:39 +03:00
parent 73d3fbc388
commit eb1ddfa447
14 changed files with 420 additions and 115 deletions

View file

@ -10,13 +10,15 @@
/* The unpacked representation of bytecode file */
typedef struct {
char *string_ptr; /* A pointer to the beginning of the string table */
int *imports_ptr; /* A pointer to the beginning of imports table */
int *public_ptr; /* A pointer to the beginning of publics table */
char *code_ptr; /* A pointer to the bytecode itself */
int *global_ptr; /* A pointer to the global area */
int code_size; /* The size (in bytes) of code */
uint stringtab_size; /* The size (in bytes) of the string table */
uint global_area_size; /* The size (in words) of global area */
uint public_symbols_number; /* The number of public symbols */
uint imports_number; /* The number of imports */
uint public_symbols_number; /* The number of public symbols */
char buffer[0];
} Bytefile;
@ -35,6 +37,14 @@ static inline const char *get_string_unsafe(const Bytefile *bf, size_t pos) {
return &bf->string_ptr[pos];
}
/* Gets import */
static inline const char *get_import_unsafe(const Bytefile *f, size_t i) {
if (i >= f->imports_number) {
failure("import pos is out of range: %zu >= %i\n", i, f->imports_number);
}
return get_string_unsafe(f, f->imports_ptr[i]);
}
/* Gets a name offset for a public symbol */
static inline size_t get_public_name_offset_unsafe(const Bytefile *bf,
size_t i) {
@ -80,6 +90,14 @@ static inline const char *get_string_safe(const Bytefile *f, size_t pos) {
return get_string_unsafe(f, pos);
}
/* Gets import */
static inline const char *get_import_safe(const Bytefile *f, size_t i) {
if (i >= f->imports_number) {
failure("import pos is out of range: %zu >= %i\n", i, f->imports_number);
}
return get_string_safe(f, f->imports_ptr[i]);
}
/* Gets a name offset for a public symbol */
static inline size_t get_public_name_offset_safe(const Bytefile *f, size_t i) {
if (i >= f->public_symbols_number) {