MCPcopy Create free account
hub / github.com/argumentcomputer/ix / compile_expr

Function compile_expr

crates/compile/src/compile.rs:619–1453  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

617
618pub 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.
650pub 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).

Callers 15

compile_definitionFunction · 0.85
compile_recursor_ruleFunction · 0.85
compile_recursorFunction · 0.85
compile_constructorFunction · 0.85
compile_inductiveFunction · 0.85
compile_axiomFunction · 0.85
compile_quotientFunction · 0.85
test_compile_expr_bvarFunction · 0.85
test_compile_expr_sortFunction · 0.85
test_compile_expr_appFunction · 0.85
test_compile_expr_lamFunction · 0.85

Calls 15

CacheClass · 0.85
compile_univ_idxFunction · 0.85
sortFunction · 0.85
compile_univ_indicesFunction · 0.85
compile_nameFunction · 0.85
collect_lean_telescopeFunction · 0.85
adapt_split_minorFunction · 0.85
store_natFunction · 0.85
store_stringFunction · 0.85
compile_data_valueFunction · 0.85
let_Function · 0.85
get_hashMethod · 0.80