91961bcec5
1. (list ...) 2. string-* functions 3. (native str) to resolve native functions at runtime 4. Memory fuckups in compiler core unit loading 5. Now can call non-identifiers in compiler
41 lines
942 B
C
41 lines
942 B
C
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
|
|
#include "vmval.h"
|
|
#include "unit.h"
|
|
|
|
struct vm_ref_entry *unit_add_ref(struct vm_unit *u) {
|
|
return vector_append(&u->ref_table);
|
|
}
|
|
|
|
struct vm_func_entry *unit_add_function(struct vm_unit *u) {
|
|
return vector_append(&u->functions);
|
|
}
|
|
|
|
char **unit_add_string(struct vm_unit *u) {
|
|
return vector_append(&u->strtab);
|
|
}
|
|
|
|
void unit_free(struct vm_unit *u) {
|
|
struct vm_func_entry *func;
|
|
|
|
vector_free(&u->ref_table);
|
|
for (size_t i = 0; i < u->functions.size; ++i) {
|
|
func = vector_ref(&u->functions, i);
|
|
free(func->bytecode);
|
|
}
|
|
vector_free(&u->functions);
|
|
for (size_t i = 0; i < u->strtab.size; ++i) {
|
|
char **ref = vector_ref(&u->strtab, i);
|
|
free(*ref);
|
|
}
|
|
vector_free(&u->strtab);
|
|
|
|
for (size_t i = 0; i < u->global_pool_size; ++i) {
|
|
vm_unref(u->global_pool[i]);
|
|
}
|
|
|
|
free(u->global_pool);
|
|
u->global_pool = NULL;
|
|
}
|