Declare shared and box typedefs before interfaces
An interface method may take a `shared T`, so its vtable needs those types declared first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
15da1e2379
commit
18cd3aacf7
1 file changed
+7
-6
+7
-6
@@ -182,6 +182,13 @@ fn generate_with(p: &HProgram, tests: Option<&[String]>) -> String {
|
||||
ps.join(", ")
|
||||
));
|
||||
}
|
||||
// declared before the interfaces: an interface method may take a `shared T`
|
||||
for b in &boxes {
|
||||
g.out.push_str(&format!("typedef struct {0} {0};\n", box_name(*b)));
|
||||
}
|
||||
for s in &shareds {
|
||||
g.out.push_str(&format!("typedef struct {0} {0};\n", c_ty(*s)));
|
||||
}
|
||||
for (name, methods) in &p.ifaces {
|
||||
let c = c_ty(Ty::Iface(Box::leak(name.clone().into_boxed_str())));
|
||||
g.out.push_str(&format!("typedef struct {0} {0};\n", c));
|
||||
@@ -196,12 +203,6 @@ fn generate_with(p: &HProgram, tests: Option<&[String]>) -> String {
|
||||
struct {c} {{ void *data; const struct VT_{c} *vt; }};\n"
|
||||
));
|
||||
}
|
||||
for b in &boxes {
|
||||
g.out.push_str(&format!("typedef struct {0} {0};\n", box_name(*b)));
|
||||
}
|
||||
for s in &shareds {
|
||||
g.out.push_str(&format!("typedef struct {0} {0};\n", c_ty(*s)));
|
||||
}
|
||||
for s in &shareds {
|
||||
let (Ty::Shared(i) | Ty::Weak(i)) = s else { unreachable!() };
|
||||
g.out.push_str(&format!("struct {} {{ {} *p; }};\n", c_ty(*s), box_name(**i)));
|
||||
|
||||
Reference in new issue
Block a user