stage1 修复bug

This commit is contained in:
zzy
2026-07-13 21:50:28 +08:00
parent b67edc5cee
commit f7f71c5f52
5 changed files with 75 additions and 44 deletions

View File

@@ -133,9 +133,34 @@ spl_type_t spl_type_emit_type(spl_type_info_t *type) {
return type->basic_type;
if (type->kind == TYPE_PTR)
return SPL_PTR;
if (type->kind == TYPE_ENUM) {
/* Simple enum (no data variants): tag is I32 */
vec_for(type->variants, i) {
if (vec_at(type->variants, i).data_type)
return SPL_PTR; /* has data — treat as aggregate */
}
return SPL_I32;
}
return SPL_PTR;
}
/* Scalar types fit in one slot, are auto-loaded on field access,
* and support == / != comparison directly. */
int spl_type_is_scalar(spl_type_info_t *type) {
if (!type)
return 1;
if (type->kind == TYPE_BASIC || type->kind == TYPE_PTR)
return 1;
if (type->kind == TYPE_ENUM) {
vec_for(type->variants, i) {
if (vec_at(type->variants, i).data_type)
return 0; /* has data — aggregate */
}
return 1; /* simple enum — scalar */
}
return 0;
}
/* ---- Load from [saved_ptr+offset], store to local var ---- */
void spl_emit_load_to_var(spl_comp_t *ctx, int ptr_slot_offset, usize byte_offset,