mirror of
https://github.com/HigherOrderCO/Kind1.git
synced 2024-09-11 08:45:32 +03:00
Fix: fix kdl compilation of Lets, Apps and rule lhs
This commit is contained in:
parent
242f5324dc
commit
3030c0c6c3
@ -133,7 +133,7 @@ pub fn compile_rule(ctx: &mut CompileCtx, rule: &untyped::Rule) -> kindelia_lang
|
||||
let arg = compile_expr(ctx, pat);
|
||||
args.push(arg);
|
||||
}
|
||||
let lhs = kdl::Term::ctr(name, args);
|
||||
let lhs = kdl::Term::fun(name, args);
|
||||
let rhs = compile_expr(ctx, &rule.body);
|
||||
let rule = kdl::Rule { lhs, rhs };
|
||||
rule
|
||||
@ -330,9 +330,9 @@ pub fn compile_expr(ctx: &mut CompileCtx, expr: &untyped::Expr) -> kindelia_lang
|
||||
From::Let { name, val, next } => {
|
||||
let res_name = kdl::Name::from_str(name.to_str());
|
||||
if let Ok(name) = res_name {
|
||||
let expr = Box::new(compile_expr(ctx, &val));
|
||||
let expr = Box::new(compile_expr(ctx, next));
|
||||
let func = Box::new(To::Lam { name, body: expr });
|
||||
let argm = Box::new(compile_expr(ctx, next));
|
||||
let argm = Box::new(compile_expr(ctx, &val));
|
||||
To::App { func, argm }
|
||||
} else {
|
||||
ctx.send_err(Box::new(KdlError::InvalidVarName(name.range)));
|
||||
|
@ -23,8 +23,6 @@ pub fn compile_book(
|
||||
|
||||
let file = compile::compile_book(&flattened, sender, namespace)?;
|
||||
|
||||
println!("{}", file);
|
||||
|
||||
let file = linearize::linearize_file(file);
|
||||
Some(file)
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ impl LinearizeCtx {
|
||||
// for every variable found in the style described before with
|
||||
// the fresh function. Also checks if rule's left side is valid.
|
||||
fn create_param_names(&mut self, rule: &Rule) {
|
||||
if let Term::Ctr { name: _, args } = &rule.lhs {
|
||||
if let Term::Fun { name: _, args } = &rule.lhs {
|
||||
for arg in args {
|
||||
match arg {
|
||||
Term::Var { name } => {
|
||||
@ -237,7 +237,9 @@ pub fn linearize_term(ctx: &mut LinearizeCtx, term: &Term, lhs: bool) -> Box<Ter
|
||||
args: new_args,
|
||||
}
|
||||
}
|
||||
Term::Num { numb } => Term::Num { numb: *numb },
|
||||
Term::Num { numb } => {
|
||||
Term::Num { numb: *numb }
|
||||
}
|
||||
Term::Op2 { oper, val0, val1 } => {
|
||||
let val0 = linearize_term(ctx, val0, lhs);
|
||||
let val1 = linearize_term(ctx, val1, lhs);
|
||||
@ -273,8 +275,8 @@ pub fn dup_var(ctx: &mut LinearizeCtx, name: &Name, expr: Box<Term>, body: Box<T
|
||||
// if used once just make a let (lambda then app)
|
||||
1 => {
|
||||
let name = Name::from_str(&format!("{}.0", name)).unwrap(); // TODO: handle err
|
||||
let func = Box::new(Term::Lam { name, body: expr });
|
||||
let term = Term::App { func, argm: body };
|
||||
let func = Box::new(Term::Lam { name, body });
|
||||
let term = Term::App { func, argm: expr };
|
||||
Box::new(term)
|
||||
}
|
||||
// if used more than once, duplicate
|
||||
|
Loading…
Reference in New Issue
Block a user