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

Function compile_univ

crates/compile/src/compile.rs:379–423  ·  view source on GitHub ↗

Compile a Lean Level to an Ixon Univ.

(
  level: &Level,
  univ_params: &[Name],
  cache: &mut BlockCache,
)

Source from the content-addressed store, hash-verified

377 if let Some(mut entry) = self.env.named.get_mut(name) {
378 entry.value_mut().set_original(orig_addr, orig_meta);
379 }
380 Ok(())
381 }
382}
383
384// ===========================================================================
385// Helper functions
386// ===========================================================================
387
388/// Convert a Nat to u64, returning an error if the value is too large.
389fn nat_to_u64(n: &Nat, context: &'static str) -> Result<u64, CompileError> {
390 n.to_u64().ok_or(CompileError::UnsupportedExpr { desc: context.into() })
391}
392
393// ===========================================================================
394// Name compilation
395// ===========================================================================
396
397/// Store a string as a blob and return its address.
398pub fn store_string(s: &str, stt: &CompileState) -> Address {
399 stt.env.store_blob(s.as_bytes().to_vec())
400}
401
402/// Store a Nat as a blob and return its address.
403pub fn store_nat(n: &Nat, stt: &CompileState) -> Address {
404 stt.env.store_blob(n.to_le_bytes())
405}
406
407/// Compile a Lean Name to an address (stored in env.names).
408/// Uses the Name's internal hash as the address.
409/// String components are stored in blobs.
410pub fn compile_name(name: &Name, stt: &CompileState) -> Address {
411 // Use the Name's internal hash as the address
412 let addr = Address::from_blake3_hash(*name.get_hash());
413
414 // Check if already stored
415 if stt.env.names.contains_key(&addr) {
416 return addr;
417 }
418
419 // Recurse on parent first (ensures parent is stored)
420 match name.as_data() {
421 NameData::Anonymous(_) => {},
422 NameData::Str(parent, s, _) => {
423 compile_name(parent, stt);
424 store_string(s, stt); // string data in blobs
425 },
426 NameData::Num(parent, _, _) => {

Callers 6

compile_univ_idxFunction · 0.85
collect_expr_tablesFunction · 0.85
test_compile_univ_zeroFunction · 0.85
test_compile_univ_succFunction · 0.85
test_compile_univ_paramFunction · 0.85
test_compile_univ_maxFunction · 0.85

Calls 7

as_dataMethod · 0.80
prettyMethod · 0.80
varFunction · 0.50
getMethod · 0.45
cloneMethod · 0.45
iterMethod · 0.45
insertMethod · 0.45

Tested by 4

test_compile_univ_zeroFunction · 0.68
test_compile_univ_succFunction · 0.68
test_compile_univ_paramFunction · 0.68
test_compile_univ_maxFunction · 0.68