Compile a Lean expression to an Ixon expression. Builds arena-based metadata in cache.arena with bottom-up allocation.
( expr: &LeanExpr, univ_params: &[Name], mut_ctx: &MutCtx, cache: &mut BlockCache, stt: &CompileState, )
| 617 | |
| 618 | pub fn collect_mut_const_exprs<'a>( |
| 619 | cnst: &'a MutConst, |
| 620 | exprs: &mut Vec<(&'a LeanExpr, &'a [Name])>, |
| 621 | ) { |
| 622 | match cnst { |
| 623 | MutConst::Defn(def) => { |
| 624 | let lvls = def.level_params.as_slice(); |
| 625 | exprs.push((&def.typ, lvls)); |
| 626 | exprs.push((&def.value, lvls)); |
| 627 | }, |
| 628 | MutConst::Indc(ind) => { |
| 629 | exprs.push((&ind.ind.cnst.typ, ind.ind.cnst.level_params.as_slice())); |
| 630 | for ctor in &ind.ctors { |
| 631 | exprs.push((&ctor.cnst.typ, ctor.cnst.level_params.as_slice())); |
| 632 | } |
| 633 | }, |
| 634 | MutConst::Recr(rec) => { |
| 635 | let lvls = rec.cnst.level_params.as_slice(); |
| 636 | exprs.push((&rec.cnst.typ, lvls)); |
| 637 | for rule in &rec.rules { |
| 638 | exprs.push((&rule.rhs, lvls)); |
| 639 | } |
| 640 | }, |
| 641 | } |
| 642 | } |
| 643 | |
| 644 | // =========================================================================== |
| 645 | // Expression compilation |
| 646 | // =========================================================================== |
| 647 | |
| 648 | /// Compile a Lean expression to an Ixon expression. |
| 649 | /// Builds arena-based metadata in cache.arena with bottom-up allocation. |
| 650 | pub fn compile_expr( |
| 651 | expr: &LeanExpr, |
| 652 | univ_params: &[Name], |
| 653 | mut_ctx: &MutCtx, |
| 654 | cache: &mut BlockCache, |
| 655 | stt: &CompileState, |
| 656 | ) -> Result<Arc<Expr>, CompileError> { |
| 657 | use ixon::metadata::CallSiteEntry; |
| 658 | |
| 659 | // Stack-based iterative compilation to avoid stack overflow |
| 660 | enum Frame { |
| 661 | Compile(LeanExpr), |
| 662 | BuildApp, |
| 663 | BuildLam(Address, BinderInfo), |
| 664 | BuildAll(Address, BinderInfo), |
| 665 | BuildLet(Address, bool), |
| 666 | BuildProj(u64, u64, Address), // type_ref_idx, field_idx, struct_name_addr |
| 667 | WrapMdata(Vec<KVMap>), |
| 668 | Cache(LeanExpr), |
| 669 | /// Build a surgered call-site from compiled head + canonical args + collapsed args. |
| 670 | BuildCallSite { |
| 671 | name_addr: Address, |
| 672 | /// Source-order entries. `meta` fields are placeholder 0 — filled during build. |
| 673 | entries: Vec<CallSiteEntry>, |
| 674 | /// Number of canonical (kept) args on the results stack. |
| 675 | n_canonical: usize, |
| 676 | /// Number of collapsed args on the results stack (after canonical args). |