diff --git a/src/codegen_c.rs b/src/codegen_c.rs index d42e3e7..740e47b 100644 --- a/src/codegen_c.rs +++ b/src/codegen_c.rs @@ -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)));