Builder: reserve slots for user-defined instance methods (start at 4)\n- Deterministic per-type slot assignment via sorted names\n- Enables method_id emission for user boxes when type known\n- Docs updated
This commit is contained in:
@ -9,6 +9,7 @@ use super::{
|
||||
FunctionSignature, ValueId, ConstValue, BinaryOp, UnaryOp, CompareOp,
|
||||
MirType, EffectMask, Effect, BasicBlockIdGenerator, ValueIdGenerator
|
||||
};
|
||||
use super::slot_registry::{get_or_assign_type_id, reserve_method_slot};
|
||||
use super::slot_registry::resolve_slot_by_type_name;
|
||||
use crate::ast::{ASTNode, LiteralValue, BinaryOperator};
|
||||
use std::collections::HashMap;
|
||||
@ -1424,6 +1425,22 @@ impl MirBuilder {
|
||||
self.weak_fields_by_box.insert(name.clone(), set);
|
||||
}
|
||||
|
||||
// Reserve method slots for user-defined instance methods (deterministic, starts at 4)
|
||||
let mut instance_methods: Vec<String> = Vec::new();
|
||||
for (mname, mast) in &methods {
|
||||
if let ASTNode::FunctionDeclaration { is_static, .. } = mast {
|
||||
if !*is_static { instance_methods.push(mname.clone()); }
|
||||
}
|
||||
}
|
||||
instance_methods.sort();
|
||||
if !instance_methods.is_empty() {
|
||||
let tyid = get_or_assign_type_id(&name);
|
||||
for (i, m) in instance_methods.iter().enumerate() {
|
||||
let slot = 4u16.saturating_add(i as u16);
|
||||
reserve_method_slot(tyid, m, slot);
|
||||
}
|
||||
}
|
||||
|
||||
// Process methods - now methods is a HashMap
|
||||
for (method_name, method_ast) in methods {
|
||||
if let ASTNode::FunctionDeclaration { .. } = method_ast {
|
||||
|
||||
Reference in New Issue
Block a user