diff --git a/crates/erg_common/serialize.rs b/crates/erg_common/serialize.rs index d95eb8ade..d14d9bd4d 100644 --- a/crates/erg_common/serialize.rs +++ b/crates/erg_common/serialize.rs @@ -33,6 +33,7 @@ pub const fn get_ver_from_magic_num(magic_num: u32) -> PythonVersion { 3420..=3425 => PythonVersion::new(3, Some(9), Some(0)), 3430..=3439 => PythonVersion::new(3, Some(10), Some(0)), // main: 3439 3495 => PythonVersion::new(3, Some(11), Some(0)), + 3531 => PythonVersion::new(3, Some(12), Some(0)), _ => panic!("unknown magic number"), } } diff --git a/crates/erg_compiler/codegen.rs b/crates/erg_compiler/codegen.rs index e73a0e472..64fc3bbe2 100644 --- a/crates/erg_compiler/codegen.rs +++ b/crates/erg_compiler/codegen.rs @@ -775,7 +775,7 @@ impl PyCodeGenerator { let kind = RegisterNameKind::from_ident(&ident); let escaped = escape_ident(ident); match &escaped[..] { - "if__" | "for__" | "while__" | "with__" | "discard__" => { + "if__" | "for__" | "while__" | "with__" | "discard__" | "assert__" => { self.load_control(); } "int__" | "nat__" | "str__" | "float__" => { diff --git a/crates/erg_compiler/context/initialize/funcs.rs b/crates/erg_compiler/context/initialize/funcs.rs index 303aaecf2..02543c7d4 100644 --- a/crates/erg_compiler/context/initialize/funcs.rs +++ b/crates/erg_compiler/context/initialize/funcs.rs @@ -292,7 +292,8 @@ impl Context { self.register_py_builtin(FUNC_ARRAY, t_array, Some(FUNC_LIST), 215); self.register_py_builtin(FUNC_ASCII, t_ascii, Some(FUNC_ASCII), 53); // Leave as `Const`, as it may negatively affect assert casting. - self.register_builtin_erg_impl(FUNC_ASSERT, t_assert, Const, vis.clone()); + let name = if PYTHON_MODE { "assert" } else { "assert__" }; + self.register_builtin_py_impl(FUNC_ASSERT, t_assert, Const, vis.clone(), Some(name)); self.register_builtin_py_impl(FUNC_BIN, t_bin, Immutable, vis.clone(), Some(FUNC_BIN)); self.register_builtin_py_impl( FUNC_BYTES, diff --git a/crates/erg_compiler/lib/std/exception.er b/crates/erg_compiler/lib/std/exception.er index 0c9ced34d..6ae183467 100644 --- a/crates/erg_compiler/lib/std/exception.er +++ b/crates/erg_compiler/lib/std/exception.er @@ -3,15 +3,16 @@ unsound = import "unsound" # TODO: exception: Exception unsound.pyexec(""" def try_(p, exc=lambda _: None, els=lambda: None, fin=lambda: None): + __result = None try: - res = p() + __result = p() except Exception as e: - res = exc(e) + __result = exc(e) else: els() finally: fin() - return res + return __result """) .try! = unsound.pyeval("try_") assert .try! in |T, U|(