plum
git clone https://git.pyrossh.dev/plum
A statically typed, imperative programming language inspired by rust, python
d169ae7
— Peter John
2026-11-03T16:45:22+05:30
tail calls: wire trmc::rewrite into typedSource; plum-core test dev-deps
Generated files not shown: Cargo.lock
- plum-checker/src/lib.rs +21 -3
- plum-core/Cargo.toml +4 -0
plum-checker/src/lib.rs
CHANGED
|
@@ -1179,9 +1179,27 @@ pub fn checkSource(source: &ast::Source) -> CheckResult<()> {
|
|
|
1179
1179
|
/// instantiated type of every expression (keyed by expression address) and the
|
|
1180
1180
|
/// set of generic instantiations (see `TypedInfo`) for codegen.
|
|
1181
1181
|
pub fn typedSource(source: &ast::Source) -> CheckResult<TypedInfo> {
|
|
1182
|
-
let (result, mut info) = checkSourceFull(source);
|
|
1182
|
+
let (mut result, mut info) = checkSourceFull(source);
|
|
1183
|
-
//
|
|
1183
|
+
// Tail recursion modulo cons: rewrite the lowered program, then check the
|
|
1184
|
-
//
|
|
1184
|
+
// rewrite again (types are recorded per expression address). If the rewrite
|
|
1185
|
+
// does not check, keep the original program.
|
|
1186
|
+
if result.is_ok() {
|
|
1187
|
+
if let Some(lowered) = info.lowered.as_ref() {
|
|
1188
|
+
let mut copy = (**lowered).clone();
|
|
1189
|
+
if !plum_core::trmc::rewrite(&mut copy).is_empty() {
|
|
1190
|
+
let saved = plum_core::unions::takePlan();
|
|
1191
|
+
plum_core::unions::beginPlan();
|
|
1192
|
+
let (r2, mut i2) = checkSourceOnce(©);
|
|
1193
|
+
plum_core::unions::takePlan();
|
|
1194
|
+
unions::restorePlan(&saved);
|
|
1195
|
+
if r2.is_ok() {
|
|
1196
|
+
i2.lowered = Some(std::rc::Rc::new(copy));
|
|
1197
|
+
result = r2;
|
|
1198
|
+
info = i2;
|
|
1199
|
+
}
|
|
1200
|
+
}
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1185
1203
|
// Mark tail calls on the final lowered program codegen compiles. Flags are set
|
|
1186
1204
|
// in place, so the address-keyed type info stays valid.
|
|
1187
1205
|
if let Some(lowered) = info.lowered.as_mut().and_then(std::rc::Rc::get_mut) {
|
plum-core/Cargo.toml
CHANGED
|
@@ -11,3 +11,7 @@ topiary-tree-sitter-facade = "0.7.3"
|
|
|
11
11
|
|
|
12
12
|
[dev-dependencies]
|
|
13
13
|
tempfile = "3"
|
|
14
|
+
plum-checker = { path = "../plum-checker" }
|
|
15
|
+
plum-wasm-codegen = { path = "../plum-wasm-codegen" }
|
|
16
|
+
wasmparser = "0.220"
|
|
17
|
+
wasmtime = "47"
|