#![allow(clippy::print_stdout, clippy::expect_used, clippy::unwrap_used)]
#[path = "../tests/support/mox_oop.rs"]
mod oop;
use intern_lang::Interner;
use oop::{W, X};
fn main() {
let mut w = W::new();
w.open(X::File);
w.class("Point", None, |w| {
w.property("x", None);
w.function(X::Method, &[X::PublicKw], "__construct", &["x"], |w| {
w.stmt(|w| {
w.assign(
|w| {
w.prop("this", "x");
},
|w| {
w.var("x");
},
);
});
});
w.function(X::Method, &[X::PublicKw], "adder", &[], |w| {
w.ret(|w| {
w.closure(false, &["n"], &[], |w| {
w.ret(|w| {
w.bin(
X::Plus,
|w| {
w.prop("this", "x");
},
|w| {
w.var("n");
},
);
});
});
});
});
});
w.class("Point3", Some("Point"), |w| {
w.function(X::Method, &[X::PublicKw], "__construct", &["x"], |w| {
w.stmt(|w| {
w.call(
|w| {
w.open(X::StaticMember)
.t(X::ParentKw, "parent")
.t(X::ColonColon, "::")
.t(X::Ident, "__construct")
.close();
},
1,
&[],
|w, _| {
w.bin(
X::Plus,
|w| {
w.var("x");
},
|w| {
w.num(1);
},
);
},
);
});
});
});
w.stmt(|w| {
w.assign(
|w| {
w.var("cls");
},
|w| {
w.t(X::Str, "'Point3'");
},
);
});
w.stmt(|w| {
w.assign(
|w| {
w.var("p");
},
|w| {
w.open(X::New).t(X::NewKw, "new").var("cls");
w.args(1, &[], |w, _| {
w.num(41);
});
w.close();
},
);
});
w.echo(|w| {
w.call(
|w| {
w.mcall(
|w| {
w.var("p");
},
"adder",
0,
|_, _| {},
);
},
1,
&[],
|w, _| {
w.num(100);
},
);
});
w.stmt(|w| {
w.assign(
|w| {
w.var("i");
},
|w| {
w.num(0);
},
);
});
w.while_(
|w| {
w.bin(
X::Lt,
|w| {
w.var("i");
},
|w| {
w.num(5);
},
);
},
|w| {
w.stmt(|w| {
w.assign(
|w| {
w.var("i");
},
|w| {
w.bin(
X::Plus,
|w| {
w.var("i");
},
|w| {
w.num(1);
},
);
},
);
});
w.open(X::Loop).t(X::LoopKw, "loop");
w.block(|w| {
w.if_(
|w| {
w.bin(
X::Lt,
|w| {
w.var("i");
},
|w| {
w.num(3);
},
);
},
|w| {
w.jump(X::ContinueKw, Some("2"));
},
);
w.jump(X::BreakKw, Some("2"));
});
w.close();
},
);
w.echo(|w| {
w.var("i");
});
w.close();
let (tree, src) = w.finish();
let mapping = oop::mapping();
let mut names = Interner::new();
let out = lower_lang::lower(&tree, &src, &mapping, &mut names).expect("within budget");
assert!(out.problems.is_empty(), "{:?}", out.problems);
println!("{}\n", hir_lang::print(&out.hir, &names));
let (hir, diags) = oop::resolve(&out, &names);
assert!(diags.is_empty(), "{diags:?}");
match oop::execute(&hir, &names) {
oop::Run::Printed(lines) => println!("prints: {lines:?}"),
oop::Run::Failed(e, lines) => println!("failed: {e} after {lines:?}"),
}
}