stage1 修复类型体内部函数前向引用时 CALL 地址错误
This commit is contained in:
@@ -57,17 +57,18 @@ typedef VEC(spl_method_info_t) spl_method_info_vec_t;
|
||||
|
||||
struct spl_type_info {
|
||||
spl_type_kind_t kind;
|
||||
spl_type_t basic_type; /* for TYPE_BASIC */
|
||||
spl_type_info_t *elem; /* for PTR/ARRAY/SLICE element type */
|
||||
usize array_len; /* for TYPE_ARRAY */
|
||||
char *name; /* type name for TYPE_NAME/STRUCT/ENUM */
|
||||
spl_field_vec_t fields; /* for TYPE_STRUCT */
|
||||
spl_enum_variant_vec_t variants; /* for TYPE_ENUM */
|
||||
spl_method_info_vec_t methods; /* methods */
|
||||
usize byte_size; /* total byte size (cached) */
|
||||
usize slot_count; /* stack slot count */
|
||||
int is_pub; /* public visibility */
|
||||
int resolved; /* type fully resolved */
|
||||
spl_type_t basic_type; /* for TYPE_BASIC */
|
||||
spl_type_info_t *elem; /* for PTR/ARRAY/SLICE element type */
|
||||
usize array_len; /* for TYPE_ARRAY */
|
||||
char *name; /* type name for TYPE_NAME/STRUCT/ENUM */
|
||||
spl_field_vec_t fields; /* for TYPE_STRUCT */
|
||||
spl_enum_variant_vec_t variants; /* for TYPE_ENUM */
|
||||
spl_method_info_vec_t methods; /* methods */
|
||||
MAP(const char *, spl_type_info_t *) children; /* nested type namespace */
|
||||
usize byte_size; /* total byte size (cached) */
|
||||
usize slot_count; /* stack slot count */
|
||||
int is_pub; /* public visibility */
|
||||
int resolved; /* type fully resolved */
|
||||
};
|
||||
|
||||
/* Type constructor helpers */
|
||||
@@ -171,10 +172,9 @@ typedef struct spl_comp {
|
||||
/* Current function context */
|
||||
int current_func_idx;
|
||||
spl_type_info_t *current_ret_type;
|
||||
int current_local_bytes; /* next free local byte offset */
|
||||
int peak_local_bytes; /* peak current_local_bytes for ALLOC sizing */
|
||||
const char *current_type_name; /* name of type whose body we're parsing (for method short-name
|
||||
lookup) */
|
||||
int current_local_bytes; /* next free local byte offset */
|
||||
int peak_local_bytes; /* peak current_local_bytes for ALLOC sizing */
|
||||
VEC(spl_type_info_t *) ns_chain; /* type namespace scope chain */
|
||||
|
||||
/* Loop context for break/continue */
|
||||
int in_loop;
|
||||
@@ -194,6 +194,12 @@ typedef struct spl_comp {
|
||||
MAP(const char *, spl_val_t) const_values;
|
||||
|
||||
int addr_of_mode; /* 1 = inside & operator, suppress loads */
|
||||
|
||||
/* Fixup list: PUSH instructions whose immediate (function address) must
|
||||
* be patched after ALL function bodies are compiled. This handles forward
|
||||
* references — method A calling method B defined later in the same type. */
|
||||
VEC(spl_val_t) call_fixups; /* instruction indices of PUSH insns to patch */
|
||||
VEC(int) call_fixup_funcs; /* prog->funcs index for each fixup */
|
||||
} spl_comp_t;
|
||||
|
||||
/* Initialize/destroy compiler context */
|
||||
@@ -303,9 +309,16 @@ int spl_add_global_data(spl_comp_t *ctx, void *data, usize size);
|
||||
void spl_push_scope(spl_comp_t *ctx);
|
||||
void spl_pop_scope(spl_comp_t *ctx);
|
||||
|
||||
/* Namespace chain management */
|
||||
void spl_ns_push(spl_comp_t *ctx, spl_type_info_t *type);
|
||||
void spl_ns_pop(spl_comp_t *ctx);
|
||||
|
||||
/* Register runtime natives */
|
||||
void spl_comp_register(spl_prog_t *prog);
|
||||
|
||||
/* Patch all CALL fixups after all function bodies are compiled */
|
||||
void spl_patch_call_fixups(spl_comp_t *ctx);
|
||||
|
||||
/* Defer */
|
||||
void spl_emit_defer(spl_comp_t *ctx);
|
||||
void spl_emit_defer_epilogue(spl_comp_t *ctx, int depth);
|
||||
|
||||
Reference in New Issue
Block a user