From 1b6340e7a64921a4a24523ca3d6fd1a7dbc31c56 Mon Sep 17 00:00:00 2001 From: Selimaj Dev Date: Tue, 9 Jun 2026 20:24:57 +0200 Subject: [PATCH] ptr write assignments --- crates/codegen/src/expr.rs | 16 ++++++++++++---- crates/parser/src/grammar.pest | 1 + mist-test/src/items/class_test.mist | 8 ++------ mist-test/src/main.mist | 25 +++++++++++++++---------- 4 files changed, 30 insertions(+), 20 deletions(-) diff --git a/crates/codegen/src/expr.rs b/crates/codegen/src/expr.rs index f6fb129..5de4435 100644 --- a/crates/codegen/src/expr.rs +++ b/crates/codegen/src/expr.rs @@ -111,11 +111,19 @@ impl GenRust for Expression { postfix.gen_rust(ctx, cg); } } - // Safely integrated to handle the tree structure built by the Pratt Parser + Expression::Binary { lhs, op, rhs } => { - lhs.gen_rust(ctx, cg); - cg.add(op); - rhs.gen_rust(ctx, cg); + if op == "->" { + cg.add("unsafe { std::ptr::write(&mut "); + lhs.gen_rust(ctx, cg); + cg.add(", "); + rhs.gen_rust(ctx, cg); + cg.add(") }"); + } else { + lhs.gen_rust(ctx, cg); + cg.add(op); + rhs.gen_rust(ctx, cg); + } } Expression::Closure { diff --git a/crates/parser/src/grammar.pest b/crates/parser/src/grammar.pest index 67ab7d8..6207f89 100644 --- a/crates/parser/src/grammar.pest +++ b/crates/parser/src/grammar.pest @@ -620,6 +620,7 @@ bin_op = { | "!=" | "&&" | "||" + | "->" | "+" | "-" | "*" diff --git a/mist-test/src/items/class_test.mist b/mist-test/src/items/class_test.mist index 9c74c73..db6b7ec 100644 --- a/mist-test/src/items/class_test.mist +++ b/mist-test/src/items/class_test.mist @@ -17,9 +17,7 @@ pub class Animal { pub class Mammal : Animal { constructor() { - unsafe { - std::ptr::write(&mut super, Super::new()); - } + super -> Super::new(); } pub fn args_test(*self, x i32, y *str) {} @@ -31,9 +29,7 @@ pub class Mammal : Animal { pub class Dog : Mammal { constructor() { - unsafe { - std::ptr::write(&mut super, Super::new()); - } + super -> Super::new(); } pub override(Animal) fn speak(*self) { diff --git a/mist-test/src/main.mist b/mist-test/src/main.mist index 5c3d822..e2761cb 100644 --- a/mist-test/src/main.mist +++ b/mist-test/src/main.mist @@ -1,13 +1,18 @@ -pub class Player { - pub name String; - pub hp i32; +fn main() { + println!("running common tests..."); + common::expr_test::run_tests(); + common::statement_test::run_tests(); + common::decl_test::run_tests(); + common::types_test::run_tests(); - pub constructor(name *str) { - self.hp = 100; - self.name.to_string(); - } + println!("running items tests..."); + items::function_test::run_tests(); + items::struct_test::run_tests(); + items::enum_test::run_tests(); + items::class_test::run_tests(); + items::trait_test::run_tests(); + items::impl_test::run_tests(); + items::attribute_test::run_tests(); - pub fn is_dead(*self) bool { - self.hp <= 0 - } + println!("\x1b[32m\nAll tests passed!\x1b[0m"); } \ No newline at end of file