ptr write assignments
This commit is contained in:
@@ -111,12 +111,20 @@ impl GenRust for Expression {
|
|||||||
postfix.gen_rust(ctx, cg);
|
postfix.gen_rust(ctx, cg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Safely integrated to handle the tree structure built by the Pratt Parser
|
|
||||||
Expression::Binary { lhs, op, rhs } => {
|
Expression::Binary { lhs, op, rhs } => {
|
||||||
|
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);
|
lhs.gen_rust(ctx, cg);
|
||||||
cg.add(op);
|
cg.add(op);
|
||||||
rhs.gen_rust(ctx, cg);
|
rhs.gen_rust(ctx, cg);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Expression::Closure {
|
Expression::Closure {
|
||||||
return_type,
|
return_type,
|
||||||
|
|||||||
@@ -620,6 +620,7 @@ bin_op = {
|
|||||||
| "!="
|
| "!="
|
||||||
| "&&"
|
| "&&"
|
||||||
| "||"
|
| "||"
|
||||||
|
| "->"
|
||||||
| "+"
|
| "+"
|
||||||
| "-"
|
| "-"
|
||||||
| "*"
|
| "*"
|
||||||
|
|||||||
@@ -17,9 +17,7 @@ pub class Animal<T> {
|
|||||||
|
|
||||||
pub class Mammal<T> : Animal<T> {
|
pub class Mammal<T> : Animal<T> {
|
||||||
constructor() {
|
constructor() {
|
||||||
unsafe {
|
super -> Super::new();
|
||||||
std::ptr::write(&mut super, Super::new());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn args_test(*self, x i32, y *str) {}
|
pub fn args_test(*self, x i32, y *str) {}
|
||||||
@@ -31,9 +29,7 @@ pub class Mammal<T> : Animal<T> {
|
|||||||
|
|
||||||
pub class Dog : Mammal<i32> {
|
pub class Dog : Mammal<i32> {
|
||||||
constructor() {
|
constructor() {
|
||||||
unsafe {
|
super -> Super::new();
|
||||||
std::ptr::write(&mut super, Super::new());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub override(Animal<i32>) fn speak(*self) {
|
pub override(Animal<i32>) fn speak(*self) {
|
||||||
|
|||||||
+15
-10
@@ -1,13 +1,18 @@
|
|||||||
pub class Player {
|
fn main() {
|
||||||
pub name String;
|
println!("running common tests...");
|
||||||
pub hp i32;
|
common::expr_test::run_tests();
|
||||||
|
common::statement_test::run_tests();
|
||||||
|
common::decl_test::run_tests();
|
||||||
|
common::types_test::run_tests();
|
||||||
|
|
||||||
pub constructor(name *str) {
|
println!("running items tests...");
|
||||||
self.hp = 100;
|
items::function_test::run_tests();
|
||||||
self.name.to_string();
|
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 {
|
println!("\x1b[32m\nAll tests passed!\x1b[0m");
|
||||||
self.hp <= 0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user