some refactorings, analyzer global var publics fix, include publics into merged bytefile

This commit is contained in:
ProgramSnail 2025-05-11 12:34:13 +03:00
parent 1f42c9ff4b
commit b1ab8ee4b3
8 changed files with 73 additions and 141 deletions

View file

@ -8,6 +8,9 @@ extern "C" {
#include "utils.h"
}
static const constexpr char *GLOBAL_VAR_TAG = "global_";
static const size_t GLOBAL_VAR_TAG_LEN = strlen(GLOBAL_VAR_TAG);
enum class Cmd : int8_t {
BINOP,
CONST,

View file

@ -48,10 +48,6 @@ static inline void **s_peek() {
s_failure(&s, "peek: empty function stack");
}
#endif
#ifdef DEBUG_VERSION
printf("--> peek\n");
#endif
return (void **)__gc_stack_top;
}
@ -62,9 +58,6 @@ static inline void s_push(void *val) {
if ((void **)__gc_stack_top == s.stack) {
s_failure(&s, "stack overflow");
}
#endif
#ifdef DEBUG_VERSION
printf("--> push\n");
#endif
__gc_stack_top -= sizeof(void *);
*(void **)__gc_stack_top = val;
@ -79,9 +72,6 @@ static inline void s_pushn_nil(size_t n) {
if ((void **)__gc_stack_top + (aint)n - 1 <= s.stack) {
s_failure(&s, "pushn: stack overflow");
}
#endif
#ifdef DEBUG_VERSION
printf("--> push %zu\n", n);
#endif
for (size_t i = 0; i < n; ++i) {
__gc_stack_top -= sizeof(void *);
@ -97,9 +87,6 @@ static inline void *s_pop() {
if (s.fp != NULL && (void **)__gc_stack_top == f_locals(s.fp)) {
s_failure(&s, "pop: empty function stack");
}
#endif
#ifdef DEBUG_VERSION
printf("--> pop\n");
#endif
void *value = *(void **)__gc_stack_top;
__gc_stack_top += sizeof(void *);
@ -116,9 +103,6 @@ static inline void s_popn(size_t n) {
if (s.fp != NULL && (void **)__gc_stack_top + (aint)n - 1 >= f_locals(s.fp)) {
s_failure(&s, "popn: empty function stack");
}
#endif
#ifdef DEBUG_VERSION
printf("--> popn %zu\n", n);
#endif
__gc_stack_top += n * sizeof(void *);
}
@ -180,11 +164,6 @@ static inline void s_rotate_n(size_t n) {
// location before / after new frame added
static inline void s_enter_f(char *rp, bool is_closure_call, auint args_sz,
auint locals_sz) {
#ifdef DEBUG_VERSION
printf("-> %i args sz\n", args_sz);
printf("-> %i locals sz\n", locals_sz);
#endif
// check that params count is valid
if ((void **)__gc_stack_top + (aint)args_sz - (is_closure_call ? 0 : 1) >=
s_top()) {
@ -232,15 +211,9 @@ static inline void s_exit_f() {
// drop stack entities, locals, frame
size_t to_pop = f_args(s.fp) - (void **)__gc_stack_top;
s.fp = (struct Frame *)f_prev_fp(&frame);
#ifdef DEBUG_VERSION
printf("-> %zu to pop\n", to_pop);
#endif
s_popn(to_pop);
// drop args
#ifdef DEBUG_VERSION
printf("-> + %zu to pop\n", f_args_sz(&frame));
#endif
s_popn(f_args_sz(&frame));
if (frame.closure) {
@ -321,9 +294,6 @@ static inline void **var_by_category(enum VarCategory category, size_t id) {
}
data *d = TO_DATA(s.fp->closure);
int count = get_len(d) - 1;
#ifdef DEBUG_VERSION
printf("id is %i, count is %i\n", id, count);
#endif
if ((int64_t)id >= count) {
s_failure(&s,
"can't read arguments: too big id"); //, %i >= %ul", id, count);

View file

@ -54,6 +54,12 @@ static inline size_t get_public_name_offset_unsafe(const Bytefile *bf,
return bf->public_ptr[i * 2];
}
/* Sets a name offset for a public symbol */
static inline void set_public_name_offset_unsafe(size_t offset,
const Bytefile *bf, size_t i) {
bf->public_ptr[i * 2] = offset;
}
/* Gets a name for a public symbol */
static inline const char *get_public_name_unsafe(const Bytefile *bf, size_t i) {
return get_string_unsafe(bf, get_public_name_offset_unsafe(bf, i));
@ -64,6 +70,12 @@ static inline size_t get_public_offset_unsafe(const Bytefile *bf, size_t i) {
return bf->public_ptr[i * 2 + 1];
}
/* Sets an offset for a publie symbol */
static inline void set_public_offset_unsafe(size_t offset, const Bytefile *bf,
size_t i) {
bf->public_ptr[i * 2 + 1] = offset;
}
// read from ip
static inline void ip_write_int_unsafe(char *ip, int32_t x) {