From 830cc7e9900cf3149aba69972ef33566de14fc66 Mon Sep 17 00:00:00 2001 From: ricky han Date: Tue, 26 Feb 2019 17:46:06 -0500 Subject: [PATCH] revert macro --- vm/src/macros.rs | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/vm/src/macros.rs b/vm/src/macros.rs index cd6546e5d..a05972961 100644 --- a/vm/src/macros.rs +++ b/vm/src/macros.rs @@ -14,12 +14,12 @@ macro_rules! count_tts { #[macro_export] macro_rules! type_check { - - ($vm:ident, $arg:expr, $arg_count: expr, $arg_name:ident, $arg_type:expr) => { + ($vm:ident, $args:ident, $arg_count:ident, $arg_name:ident, $arg_type:expr) => { // None indicates that we have no type requirement (i.e. we accept any type) if let Some(expected_type) = $arg_type { - if !$crate::obj::objtype::isinstance($arg, &expected_type) { - let arg_typ = $arg.typ(); + let arg = &$args.args[$arg_count]; + if !$crate::obj::objtype::isinstance(arg, &expected_type) { + let arg_typ = arg.typ(); let expected_type_name = $vm.to_pystr(&expected_type)?; let actual_type = $vm.to_pystr(&arg_typ)?; return Err($vm.new_type_error(format!( @@ -71,7 +71,7 @@ macro_rules! arg_check { // check if the type matches. If not, return with error // assign the arg to a variable $( - type_check!($vm, &$args.args[arg_count], arg_count, $arg_name, $arg_type); + type_check!($vm, $args, arg_count, $arg_name, $arg_type); let $arg_name = &$args.args[arg_count]; #[allow(unused_assignments)] { @@ -83,21 +83,14 @@ macro_rules! arg_check { // check if the type matches. If not, return with error // assign the arg to a variable $( - let len = $args.args.len(); - let klen = $args.kwargs.len(); - let $optional_arg_name = if arg_count >= len && (arg_count - len) < $args.kwargs.len() { - let idx = klen - (arg_count-len) - 1; - type_check!($vm, &$args.kwargs[idx].1, arg_count-len, $optional_arg_name, $optional_arg_type); - let kwarg = &$args.kwargs[idx]; - if &kwarg.0 == stringify!($optional_arg_name) { - #[allow(unused_assignments)] - { - arg_count += 1; - } - Some(&kwarg.1) - } else { - None + let $optional_arg_name = if arg_count < $args.args.len() { + type_check!($vm, $args, arg_count, $optional_arg_name, $optional_arg_type); + let ret = Some(&$args.args[arg_count]); + #[allow(unused_assignments)] + { + arg_count += 1; } + ret } else { None };