working class

This commit is contained in:
2026-05-05 19:40:45 +02:00
parent cf99ef58c3
commit efa9d51eb6
2 changed files with 17 additions and 3 deletions
+15 -2
View File
@@ -372,15 +372,28 @@ impl ToRust for TopLevelKind {
));
cg.indent += 1;
cg.add_indentedln("let this: Self = unsafe { std::mem::zeroed() };");
cg.add_indentedln("let mut this: Self = unsafe { std::mem::MaybeUninit::<Self>::zeroed().assume_init() };");
constructor.body.to_rust(cg);
cg.add_indentedln("this.construct_class();");
cg.add_indentedln("this");
cg.indent -= 1;
cg.add_indentedln("}\n");
// Constructor function
cg.add_indentedln(&format!(
"{}fn construct_class(&mut self, {}) {{",
if constructor.export { "pub " } else { "" },
params_str
));
cg.indent += 1;
constructor.body.to_rust(cg);
cg.indent -= 1;
cg.add_indentedln("}\n");
cg.indent -= 1;
cg.addln("}\n");
}
+2 -1
View File
@@ -2,10 +2,11 @@ class MyClass {
String my_item;
constructor() {
self.my_item = "Hello World!".to_string();
}
}
void main() {
var my_class = MyClass::new();
println!("{}", my_class.my_item);
}