revert macro

This commit is contained in:
ricky han
2019-02-26 17:46:06 -05:00
parent 0a2aa1e64b
commit 830cc7e990

View File

@@ -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
};