Merge pull request #35 from jhwgh1968/plugins

Convert args length check to debug assert
This commit is contained in:
Stephen Chung 2020-08-16 11:29:03 +08:00 committed by GitHub
commit 7eb75f6790
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 60 deletions

View File

@ -499,11 +499,9 @@ impl ExportedFn {
fn call(&self, fn call(&self,
args: &mut [&mut Dynamic], pos: Position args: &mut [&mut Dynamic], pos: Position
) -> Result<Dynamic, Box<EvalAltResult>> { ) -> Result<Dynamic, Box<EvalAltResult>> {
if args.len() != #arg_count { debug_assert_eq!(args.len(), #arg_count,
return Err(Box::new(EvalAltResult::ErrorRuntime( "wrong arg count: {} != {}",
format!("wrong arg count: {} != {}", args.len(), #arg_count);
args.len(), #arg_count), Position::none())));
}
#(#unpack_stmts)* #(#unpack_stmts)*
#return_expr #return_expr
} }
@ -792,11 +790,8 @@ mod generate_tests {
fn call(&self, fn call(&self,
args: &mut [&mut Dynamic], pos: Position args: &mut [&mut Dynamic], pos: Position
) -> Result<Dynamic, Box<EvalAltResult>> { ) -> Result<Dynamic, Box<EvalAltResult>> {
if args.len() != 0usize { debug_assert_eq!(args.len(), 0usize,
return Err(Box::new(EvalAltResult::ErrorRuntime( "wrong arg count: {} != {}", args.len(), 0usize);
format!("wrong arg count: {} != {}",
args.len(), 0usize), Position::none())));
}
Ok(Dynamic::from(do_nothing())) Ok(Dynamic::from(do_nothing()))
} }
@ -839,11 +834,8 @@ mod generate_tests {
fn call(&self, fn call(&self,
args: &mut [&mut Dynamic], pos: Position args: &mut [&mut Dynamic], pos: Position
) -> Result<Dynamic, Box<EvalAltResult>> { ) -> Result<Dynamic, Box<EvalAltResult>> {
if args.len() != 1usize { debug_assert_eq!(args.len(), 1usize,
return Err(Box::new(EvalAltResult::ErrorRuntime( "wrong arg count: {} != {}", args.len(), 1usize);
format!("wrong arg count: {} != {}",
args.len(), 1usize), Position::none())));
}
let arg0 = mem::take(args[0usize]).clone().cast::<usize>(); let arg0 = mem::take(args[0usize]).clone().cast::<usize>();
Ok(Dynamic::from(do_something(arg0))) Ok(Dynamic::from(do_something(arg0)))
} }
@ -883,11 +875,8 @@ mod generate_tests {
fn call(&self, fn call(&self,
args: &mut [&mut Dynamic], pos: Position args: &mut [&mut Dynamic], pos: Position
) -> Result<Dynamic, Box<EvalAltResult>> { ) -> Result<Dynamic, Box<EvalAltResult>> {
if args.len() != 1usize { debug_assert_eq!(args.len(), 1usize,
return Err(Box::new(EvalAltResult::ErrorRuntime( "wrong arg count: {} != {}", args.len(), 1usize);
format!("wrong arg count: {} != {}",
args.len(), 1usize), Position::none())));
}
let arg0 = mem::take(args[0usize]).clone().cast::<usize>(); let arg0 = mem::take(args[0usize]).clone().cast::<usize>();
Ok(Dynamic::from(do_something(arg0))) Ok(Dynamic::from(do_something(arg0)))
} }
@ -920,11 +909,8 @@ mod generate_tests {
fn call(&self, fn call(&self,
args: &mut [&mut Dynamic], pos: Position args: &mut [&mut Dynamic], pos: Position
) -> Result<Dynamic, Box<EvalAltResult>> { ) -> Result<Dynamic, Box<EvalAltResult>> {
if args.len() != 2usize { debug_assert_eq!(args.len(), 2usize,
return Err(Box::new(EvalAltResult::ErrorRuntime( "wrong arg count: {} != {}", args.len(), 2usize);
format!("wrong arg count: {} != {}",
args.len(), 2usize), Position::none())));
}
let arg0 = mem::take(args[0usize]).clone().cast::<usize>(); let arg0 = mem::take(args[0usize]).clone().cast::<usize>();
let arg1 = mem::take(args[1usize]).clone().cast::<usize>(); let arg1 = mem::take(args[1usize]).clone().cast::<usize>();
Ok(Dynamic::from(add_together(arg0, arg1))) Ok(Dynamic::from(add_together(arg0, arg1)))
@ -970,11 +956,8 @@ mod generate_tests {
fn call(&self, fn call(&self,
args: &mut [&mut Dynamic], pos: Position args: &mut [&mut Dynamic], pos: Position
) -> Result<Dynamic, Box<EvalAltResult>> { ) -> Result<Dynamic, Box<EvalAltResult>> {
if args.len() != 2usize { debug_assert_eq!(args.len(), 2usize,
return Err(Box::new(EvalAltResult::ErrorRuntime( "wrong arg count: {} != {}", args.len(), 2usize);
format!("wrong arg count: {} != {}",
args.len(), 2usize), Position::none())));
}
let arg1 = mem::take(args[1usize]).clone().cast::<usize>(); let arg1 = mem::take(args[1usize]).clone().cast::<usize>();
let arg0: &mut _ = &mut args[0usize].write_lock::<usize>().unwrap(); let arg0: &mut _ = &mut args[0usize].write_lock::<usize>().unwrap();
Ok(Dynamic::from(increment(arg0, arg1))) Ok(Dynamic::from(increment(arg0, arg1)))
@ -1021,11 +1004,8 @@ mod generate_tests {
fn call(&self, fn call(&self,
args: &mut [&mut Dynamic], pos: Position args: &mut [&mut Dynamic], pos: Position
) -> Result<Dynamic, Box<EvalAltResult>> { ) -> Result<Dynamic, Box<EvalAltResult>> {
if args.len() != 1usize { debug_assert_eq!(args.len(), 1usize,
return Err(Box::new(EvalAltResult::ErrorRuntime( "wrong arg count: {} != {}", args.len(), 1usize);
format!("wrong arg count: {} != {}",
args.len(), 1usize), Position::none())));
}
let arg0 = mem::take(args[0usize]).clone().cast::<ImmutableString>(); let arg0 = mem::take(args[0usize]).clone().cast::<ImmutableString>();
Ok(Dynamic::from(special_print(&arg0))) Ok(Dynamic::from(special_print(&arg0)))
} }

View File

@ -348,11 +348,8 @@ mod generate_tests {
fn call(&self, fn call(&self,
args: &mut [&mut Dynamic], pos: Position args: &mut [&mut Dynamic], pos: Position
) -> Result<Dynamic, Box<EvalAltResult>> { ) -> Result<Dynamic, Box<EvalAltResult>> {
if args.len() != 0usize { debug_assert_eq!(args.len(), 0usize,
return Err(Box::new(EvalAltResult::ErrorRuntime( "wrong arg count: {} != {}", args.len(), 0usize);
format!("wrong arg count: {} != {}",
args.len(), 0usize), Position::none())));
}
Ok(Dynamic::from(get_mystic_number())) Ok(Dynamic::from(get_mystic_number()))
} }
@ -408,11 +405,8 @@ mod generate_tests {
fn call(&self, fn call(&self,
args: &mut [&mut Dynamic], pos: Position args: &mut [&mut Dynamic], pos: Position
) -> Result<Dynamic, Box<EvalAltResult>> { ) -> Result<Dynamic, Box<EvalAltResult>> {
if args.len() != 1usize { debug_assert_eq!(args.len(), 1usize,
return Err(Box::new(EvalAltResult::ErrorRuntime( "wrong arg count: {} != {}", args.len(), 1usize);
format!("wrong arg count: {} != {}",
args.len(), 1usize), Position::none())));
}
let arg0 = mem::take(args[0usize]).clone().cast::<INT>(); let arg0 = mem::take(args[0usize]).clone().cast::<INT>();
Ok(Dynamic::from(add_one_to(arg0))) Ok(Dynamic::from(add_one_to(arg0)))
} }
@ -470,11 +464,8 @@ mod generate_tests {
fn call(&self, fn call(&self,
args: &mut [&mut Dynamic], pos: Position args: &mut [&mut Dynamic], pos: Position
) -> Result<Dynamic, Box<EvalAltResult>> { ) -> Result<Dynamic, Box<EvalAltResult>> {
if args.len() != 2usize { debug_assert_eq!(args.len(), 2usize,
return Err(Box::new(EvalAltResult::ErrorRuntime( "wrong arg count: {} != {}", args.len(), 2usize);
format!("wrong arg count: {} != {}",
args.len(), 2usize), Position::none())));
}
let arg0 = mem::take(args[0usize]).clone().cast::<INT>(); let arg0 = mem::take(args[0usize]).clone().cast::<INT>();
let arg1 = mem::take(args[1usize]).clone().cast::<INT>(); let arg1 = mem::take(args[1usize]).clone().cast::<INT>();
Ok(Dynamic::from(add_together(arg0, arg1))) Ok(Dynamic::from(add_together(arg0, arg1)))
@ -672,11 +663,8 @@ mod generate_tests {
fn call(&self, fn call(&self,
args: &mut [&mut Dynamic], pos: Position args: &mut [&mut Dynamic], pos: Position
) -> Result<Dynamic, Box<EvalAltResult>> { ) -> Result<Dynamic, Box<EvalAltResult>> {
if args.len() != 1usize { debug_assert_eq!(args.len(), 1usize,
return Err(Box::new(EvalAltResult::ErrorRuntime( "wrong arg count: {} != {}", args.len(), 1usize);
format!("wrong arg count: {} != {}",
args.len(), 1usize), Position::none())));
}
let arg0 = mem::take(args[0usize]).clone().cast::<ImmutableString>(); let arg0 = mem::take(args[0usize]).clone().cast::<ImmutableString>();
Ok(Dynamic::from(print_out_to(&arg0))) Ok(Dynamic::from(print_out_to(&arg0)))
} }
@ -734,11 +722,8 @@ mod generate_tests {
fn call(&self, fn call(&self,
args: &mut [&mut Dynamic], pos: Position args: &mut [&mut Dynamic], pos: Position
) -> Result<Dynamic, Box<EvalAltResult>> { ) -> Result<Dynamic, Box<EvalAltResult>> {
if args.len() != 1usize { debug_assert_eq!(args.len(), 1usize,
return Err(Box::new(EvalAltResult::ErrorRuntime( "wrong arg count: {} != {}", args.len(), 1usize);
format!("wrong arg count: {} != {}",
args.len(), 1usize), Position::none())));
}
let arg0: &mut _ = &mut args[0usize].write_lock::<FLOAT>().unwrap(); let arg0: &mut _ = &mut args[0usize].write_lock::<FLOAT>().unwrap();
Ok(Dynamic::from(increment(arg0))) Ok(Dynamic::from(increment(arg0)))
} }