lean4-htt/tests/lean/run/toExpr.lean
Cameron Zwarich 85560da3e4
chore: remove functions for compiling decls from Environment (#6600)
This PR removes functions from compiling decls from Environment, and
moves all users to functions on CoreM. This is required for supporting
the new code generator, since its implementation uses CoreM.
2025-01-13 18:51:06 +00:00

32 lines
772 B
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import Lean
open Lean
unsafe def test {α : Type} [ToString α] [ToExpr α] [BEq α] (a : α) : CoreM Unit := do
let env ← getEnv;
let auxName := `_toExpr._test;
let decl := Declaration.defnDecl {
name := auxName,
levelParams := [],
value := toExpr a,
type := toTypeExpr α,
hints := ReducibilityHints.abbrev,
safety := DefinitionSafety.safe
};
IO.println (toExpr a);
let oldEnv ← getEnv;
addAndCompile decl;
let newEnv ← getEnv
setEnv oldEnv
match newEnv.evalConst α {} auxName with
| Except.error ex => throwError ex
| Except.ok b => do
IO.println b;
unless a == b do
throwError "toExpr failed";
pure ()
#eval test #[(1, 2), (3, 4)]
#eval test ['a', 'b', 'c']
#eval test ("hello", true)
#eval test ((), 10)