From 642e3b2bad6b8f4f688c66bb91d1f774910b92f9 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Thu, 17 Mar 2022 00:04:49 +0800 Subject: [PATCH] nac3core: moved all builtin errors to nac3artiq code This remove the need for hard-coding those definition IDs. --- nac3artiq/src/lib.rs | 2 ++ nac3core/src/toplevel/builtins.rs | 25 ++----------------------- 2 files changed, 4 insertions(+), 23 deletions(-) diff --git a/nac3artiq/src/lib.rs b/nac3artiq/src/lib.rs index 343c86e5..c34f2438 100644 --- a/nac3artiq/src/lib.rs +++ b/nac3artiq/src/lib.rs @@ -464,6 +464,8 @@ impl Nac3 { let pyid_to_type = Arc::new(RwLock::new(HashMap::::new())); let exception_names = [ + "ZeroDivisionError", + "IndexError", "ValueError", "RuntimeError" ]; diff --git a/nac3core/src/toplevel/builtins.rs b/nac3core/src/toplevel/builtins.rs index 64a52ea0..da314735 100644 --- a/nac3core/src/toplevel/builtins.rs +++ b/nac3core/src/toplevel/builtins.rs @@ -79,22 +79,6 @@ pub fn get_exn_constructor( } pub fn get_builtins(primitives: &mut (PrimitiveStore, Unifier)) -> BuiltinInfo { - // please refer to the top_level_def_list below for the definition IDs - let (div_by_zero_fun, div_by_zero_class, _, _) = get_exn_constructor( - "DivisionByZeroError", - 12, - 10, - &mut primitives.1, - &primitives.0, - ); - let (index_err_fun, index_err_class, _, _) = get_exn_constructor( - "IndexError", - 13, - 11, - &mut primitives.1, - &primitives.0, - ); - let int32 = primitives.0.int32; let int64 = primitives.0.int64; let uint32 = primitives.0.uint32; @@ -121,7 +105,7 @@ pub fn get_builtins(primitives: &mut (PrimitiveStore, Unifier)) -> BuiltinInfo { ("__param2__".into(), int64, true), ]; - let top_level_def_list = vec![ + let mut top_level_def_list = vec![ Arc::new(RwLock::new(TopLevelComposer::make_top_level_class_def( 0, None, @@ -196,10 +180,6 @@ pub fn get_builtins(primitives: &mut (PrimitiveStore, Unifier)) -> BuiltinInfo { None, None, ))), - Arc::new(RwLock::new(div_by_zero_fun)), - Arc::new(RwLock::new(index_err_fun)), - Arc::new(RwLock::new(div_by_zero_class)), - Arc::new(RwLock::new(index_err_class)), Arc::new(RwLock::new(TopLevelDef::Function { name: "int32".into(), simple_name: "int32".into(), @@ -1119,13 +1099,12 @@ pub fn get_builtins(primitives: &mut (PrimitiveStore, Unifier)) -> BuiltinInfo { loc: None, })), ]; + let ast_list: Vec>> = (0..top_level_def_list.len()).map(|_| None).collect(); ( izip!(top_level_def_list, ast_list).collect_vec(), &[ - "ZeroDivisionError", - "IndexError", "int32", "int64", "uint32",