Fix codegen and tests to new API changes.
This commit is contained in:
parent
4465a44673
commit
dd6b6cd49f
@ -150,7 +150,7 @@ impl ExportedFn {
|
||||
|
||||
pub fn generate(self) -> proc_macro2::TokenStream {
|
||||
let name: syn::Ident = syn::Ident::new(
|
||||
&format!("rhai_fn__{}", self.name().to_string()),
|
||||
&format!("rhai_fn_{}", self.name().to_string()),
|
||||
self.name().span(),
|
||||
);
|
||||
let impl_block = self.generate_impl("Token");
|
||||
@ -171,8 +171,9 @@ impl ExportedFn {
|
||||
pub fn generate_callable(&self, on_type_name: &str) -> proc_macro2::TokenStream {
|
||||
let token_name: syn::Ident = syn::Ident::new(on_type_name, self.name().span());
|
||||
let callable_fn_name: syn::Ident = syn::Ident::new(
|
||||
format!("{}__callable", on_type_name).as_str(),
|
||||
self.name().span());
|
||||
format!("{}_callable", on_type_name.to_lowercase()).as_str(),
|
||||
self.name().span(),
|
||||
);
|
||||
quote! {
|
||||
pub fn #callable_fn_name() -> CallableFunction {
|
||||
CallableFunction::from_plugin(#token_name())
|
||||
@ -183,8 +184,9 @@ impl ExportedFn {
|
||||
pub fn generate_input_types(&self, on_type_name: &str) -> proc_macro2::TokenStream {
|
||||
let token_name: syn::Ident = syn::Ident::new(on_type_name, self.name().span());
|
||||
let input_types_fn_name: syn::Ident = syn::Ident::new(
|
||||
format!("{}__input_types", on_type_name).as_str(),
|
||||
self.name().span());
|
||||
format!("{}_input_types", on_type_name.to_lowercase()).as_str(),
|
||||
self.name().span(),
|
||||
);
|
||||
quote! {
|
||||
pub fn #input_types_fn_name() -> Box<[std::any::TypeId]> {
|
||||
#token_name().input_types()
|
||||
@ -218,7 +220,7 @@ impl ExportedFn {
|
||||
}
|
||||
};
|
||||
let downcast_span = quote_spanned!(
|
||||
arg_type.span()=> args[0usize].downcast_mut::<#arg_type>().unwrap());
|
||||
arg_type.span()=> &mut *args[0usize].write_lock::<#arg_type>().unwrap());
|
||||
unpack_stmts.push(
|
||||
syn::parse2::<syn::Stmt>(quote! {
|
||||
let #var: &mut _ = #downcast_span;
|
||||
@ -603,7 +605,7 @@ mod generate_tests {
|
||||
|
||||
let expected_tokens = quote! {
|
||||
#[allow(unused)]
|
||||
pub mod rhai_fn__do_nothing {
|
||||
pub mod rhai_fn_do_nothing {
|
||||
use super::*;
|
||||
struct Token();
|
||||
impl PluginFunction for Token {
|
||||
@ -625,10 +627,10 @@ mod generate_tests {
|
||||
vec![].into_boxed_slice()
|
||||
}
|
||||
}
|
||||
pub fn Token__callable() -> CallableFunction {
|
||||
pub fn token_callable() -> CallableFunction {
|
||||
CallableFunction::from_plugin(Token())
|
||||
}
|
||||
pub fn Token__input_types() -> Box<[std::any::TypeId]> {
|
||||
pub fn token_input_types() -> Box<[std::any::TypeId]> {
|
||||
Token().input_types()
|
||||
}
|
||||
}
|
||||
@ -646,7 +648,7 @@ mod generate_tests {
|
||||
|
||||
let expected_tokens = quote! {
|
||||
#[allow(unused)]
|
||||
pub mod rhai_fn__do_something {
|
||||
pub mod rhai_fn_do_something {
|
||||
use super::*;
|
||||
struct Token();
|
||||
impl PluginFunction for Token {
|
||||
@ -669,10 +671,10 @@ mod generate_tests {
|
||||
vec![std::any::TypeId::of::<usize>()].into_boxed_slice()
|
||||
}
|
||||
}
|
||||
pub fn Token__callable() -> CallableFunction {
|
||||
pub fn token_callable() -> CallableFunction {
|
||||
CallableFunction::from_plugin(Token())
|
||||
}
|
||||
pub fn Token__input_types() -> Box<[std::any::TypeId]> {
|
||||
pub fn token_input_types() -> Box<[std::any::TypeId]> {
|
||||
Token().input_types()
|
||||
}
|
||||
}
|
||||
@ -723,7 +725,7 @@ mod generate_tests {
|
||||
|
||||
let expected_tokens = quote! {
|
||||
#[allow(unused)]
|
||||
pub mod rhai_fn__add_together {
|
||||
pub mod rhai_fn_add_together {
|
||||
use super::*;
|
||||
struct Token();
|
||||
impl PluginFunction for Token {
|
||||
@ -748,10 +750,10 @@ mod generate_tests {
|
||||
std::any::TypeId::of::<usize>()].into_boxed_slice()
|
||||
}
|
||||
}
|
||||
pub fn Token__callable() -> CallableFunction {
|
||||
pub fn token_callable() -> CallableFunction {
|
||||
CallableFunction::from_plugin(Token())
|
||||
}
|
||||
pub fn Token__input_types() -> Box<[std::any::TypeId]> {
|
||||
pub fn token_input_types() -> Box<[std::any::TypeId]> {
|
||||
Token().input_types()
|
||||
}
|
||||
}
|
||||
@ -769,7 +771,7 @@ mod generate_tests {
|
||||
|
||||
let expected_tokens = quote! {
|
||||
#[allow(unused)]
|
||||
pub mod rhai_fn__increment {
|
||||
pub mod rhai_fn_increment {
|
||||
use super::*;
|
||||
struct Token();
|
||||
impl PluginFunction for Token {
|
||||
@ -782,7 +784,7 @@ mod generate_tests {
|
||||
args.len(), 2usize), Position::none())));
|
||||
}
|
||||
let arg1 = args[1usize].downcast_clone::<usize>().unwrap();
|
||||
let arg0: &mut _ = args[0usize].downcast_mut::<usize>().unwrap();
|
||||
let arg0: &mut _ = args[0usize].write_lock::<usize>().unwrap();
|
||||
Ok(Dynamic::from(increment(arg0, arg1)))
|
||||
}
|
||||
|
||||
@ -794,10 +796,10 @@ mod generate_tests {
|
||||
std::any::TypeId::of::<usize>()].into_boxed_slice()
|
||||
}
|
||||
}
|
||||
pub fn Token__callable() -> CallableFunction {
|
||||
pub fn token_callable() -> CallableFunction {
|
||||
CallableFunction::from_plugin(Token())
|
||||
}
|
||||
pub fn Token__input_types() -> Box<[std::any::TypeId]> {
|
||||
pub fn token_input_types() -> Box<[std::any::TypeId]> {
|
||||
Token().input_types()
|
||||
}
|
||||
}
|
||||
@ -816,7 +818,7 @@ mod generate_tests {
|
||||
|
||||
let expected_tokens = quote! {
|
||||
#[allow(unused)]
|
||||
pub mod rhai_fn__special_print {
|
||||
pub mod rhai_fn_special_print {
|
||||
use super::*;
|
||||
struct Token();
|
||||
impl PluginFunction for Token {
|
||||
@ -839,10 +841,10 @@ mod generate_tests {
|
||||
vec![std::any::TypeId::of::<ImmutableString>()].into_boxed_slice()
|
||||
}
|
||||
}
|
||||
pub fn Token__callable() -> CallableFunction {
|
||||
pub fn token_callable() -> CallableFunction {
|
||||
CallableFunction::from_plugin(Token())
|
||||
}
|
||||
pub fn Token__input_types() -> Box<[std::any::TypeId]> {
|
||||
pub fn token_input_types() -> Box<[std::any::TypeId]> {
|
||||
Token().input_types()
|
||||
}
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ pub fn export_module(
|
||||
pub fn exported_module(module_path: proc_macro::TokenStream) -> proc_macro::TokenStream {
|
||||
let module_path = parse_macro_input!(module_path as syn::Path);
|
||||
let tokens = quote::quote! {
|
||||
#module_path::rhai_module__generate()
|
||||
#module_path::rhai_module_generate()
|
||||
};
|
||||
proc_macro::TokenStream::from(tokens)
|
||||
}
|
||||
@ -133,7 +133,7 @@ pub fn register_exported_fn(args: proc_macro::TokenStream) -> proc_macro::TokenS
|
||||
let mut g = rust_modpath.clone().segments;
|
||||
g.pop();
|
||||
let ident = syn::Ident::new(
|
||||
&format!("rhai_fn__{}", rust_modpath.segments.last().unwrap().ident),
|
||||
&format!("rhai_fn_{}", rust_modpath.segments.last().unwrap().ident),
|
||||
items[2].span(),
|
||||
);
|
||||
g.push_value(syn::PathSegment {
|
||||
@ -144,8 +144,8 @@ pub fn register_exported_fn(args: proc_macro::TokenStream) -> proc_macro::TokenS
|
||||
};
|
||||
let tokens = quote! {
|
||||
#rhai_module.set_fn(#export_name, rhai::FnAccess::Public,
|
||||
#gen_mod_path::Token__input_types().as_ref(),
|
||||
#gen_mod_path::Token__callable());
|
||||
#gen_mod_path::token_input_types().as_ref(),
|
||||
#gen_mod_path::token_callable());
|
||||
|
||||
};
|
||||
proc_macro::TokenStream::from(tokens)
|
||||
|
@ -265,7 +265,7 @@ mod generate_tests {
|
||||
#[allow(unused_imports)]
|
||||
use super::*;
|
||||
#[allow(unused_mut)]
|
||||
pub fn rhai_module__generate() -> Module {
|
||||
pub fn rhai_module_generate() -> Module {
|
||||
let mut m = Module::new();
|
||||
m
|
||||
}
|
||||
@ -294,15 +294,15 @@ mod generate_tests {
|
||||
#[allow(unused_imports)]
|
||||
use super::*;
|
||||
#[allow(unused_mut)]
|
||||
pub fn rhai_module__generate() -> Module {
|
||||
pub fn rhai_module_generate() -> Module {
|
||||
let mut m = Module::new();
|
||||
m.set_fn("get_mystic_number", FnAccess::Public, &[],
|
||||
CallableFunction::from_plugin(get_mystic_number__Token()));
|
||||
CallableFunction::from_plugin(get_mystic_number_token()));
|
||||
m
|
||||
}
|
||||
#[allow(non_camel_case_types)]
|
||||
struct get_mystic_number__Token();
|
||||
impl PluginFunction for get_mystic_number__Token {
|
||||
struct get_mystic_number_token();
|
||||
impl PluginFunction for get_mystic_number_token {
|
||||
fn call(&self,
|
||||
args: &mut [&mut Dynamic], pos: Position
|
||||
) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||
@ -317,17 +317,17 @@ mod generate_tests {
|
||||
fn is_method_call(&self) -> bool { false }
|
||||
fn is_varadic(&self) -> bool { false }
|
||||
fn clone_boxed(&self) -> Box<dyn PluginFunction> {
|
||||
Box::new(get_mystic_number__Token())
|
||||
Box::new(get_mystic_number_token())
|
||||
}
|
||||
fn input_types(&self) -> Box<[std::any::TypeId]> {
|
||||
vec![].into_boxed_slice()
|
||||
}
|
||||
}
|
||||
pub fn get_mystic_number__Token__callable() -> CallableFunction {
|
||||
CallableFunction::from_plugin(get_mystic_number__Token())
|
||||
pub fn get_mystic_number_token_callable() -> CallableFunction {
|
||||
CallableFunction::from_plugin(get_mystic_number_token())
|
||||
}
|
||||
pub fn get_mystic_number__Token__input_types() -> Box<[std::any::TypeId]> {
|
||||
get_mystic_number__Token().input_types()
|
||||
pub fn get_mystic_number_token_input_types() -> Box<[std::any::TypeId]> {
|
||||
get_mystic_number_token().input_types()
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -354,15 +354,15 @@ mod generate_tests {
|
||||
#[allow(unused_imports)]
|
||||
use super::*;
|
||||
#[allow(unused_mut)]
|
||||
pub fn rhai_module__generate() -> Module {
|
||||
pub fn rhai_module_generate() -> Module {
|
||||
let mut m = Module::new();
|
||||
m.set_fn("add_one_to", FnAccess::Public, &[core::any::TypeId::of::<INT>()],
|
||||
CallableFunction::from_plugin(add_one_to__Token()));
|
||||
CallableFunction::from_plugin(add_one_to_token()));
|
||||
m
|
||||
}
|
||||
#[allow(non_camel_case_types)]
|
||||
struct add_one_to__Token();
|
||||
impl PluginFunction for add_one_to__Token {
|
||||
struct add_one_to_token();
|
||||
impl PluginFunction for add_one_to_token {
|
||||
fn call(&self,
|
||||
args: &mut [&mut Dynamic], pos: Position
|
||||
) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||
@ -378,17 +378,17 @@ mod generate_tests {
|
||||
fn is_method_call(&self) -> bool { false }
|
||||
fn is_varadic(&self) -> bool { false }
|
||||
fn clone_boxed(&self) -> Box<dyn PluginFunction> {
|
||||
Box::new(add_one_to__Token())
|
||||
Box::new(add_one_to_token())
|
||||
}
|
||||
fn input_types(&self) -> Box<[std::any::TypeId]> {
|
||||
vec![std::any::TypeId::of::<INT>()].into_boxed_slice()
|
||||
}
|
||||
}
|
||||
pub fn add_one_to__Token__callable() -> CallableFunction {
|
||||
CallableFunction::from_plugin(add_one_to__Token())
|
||||
pub fn add_one_to_token_callable() -> CallableFunction {
|
||||
CallableFunction::from_plugin(add_one_to_token())
|
||||
}
|
||||
pub fn add_one_to__Token__input_types() -> Box<[std::any::TypeId]> {
|
||||
add_one_to__Token().input_types()
|
||||
pub fn add_one_to_token_input_types() -> Box<[std::any::TypeId]> {
|
||||
add_one_to_token().input_types()
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -415,16 +415,16 @@ mod generate_tests {
|
||||
#[allow(unused_imports)]
|
||||
use super::*;
|
||||
#[allow(unused_mut)]
|
||||
pub fn rhai_module__generate() -> Module {
|
||||
pub fn rhai_module_generate() -> Module {
|
||||
let mut m = Module::new();
|
||||
m.set_fn("add_together", FnAccess::Public, &[core::any::TypeId::of::<INT>(),
|
||||
core::any::TypeId::of::<INT>()],
|
||||
CallableFunction::from_plugin(add_together__Token()));
|
||||
CallableFunction::from_plugin(add_together_token()));
|
||||
m
|
||||
}
|
||||
#[allow(non_camel_case_types)]
|
||||
struct add_together__Token();
|
||||
impl PluginFunction for add_together__Token {
|
||||
struct add_together_token();
|
||||
impl PluginFunction for add_together_token {
|
||||
fn call(&self,
|
||||
args: &mut [&mut Dynamic], pos: Position
|
||||
) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||
@ -441,18 +441,18 @@ mod generate_tests {
|
||||
fn is_method_call(&self) -> bool { false }
|
||||
fn is_varadic(&self) -> bool { false }
|
||||
fn clone_boxed(&self) -> Box<dyn PluginFunction> {
|
||||
Box::new(add_together__Token())
|
||||
Box::new(add_together_token())
|
||||
}
|
||||
fn input_types(&self) -> Box<[std::any::TypeId]> {
|
||||
vec![std::any::TypeId::of::<INT>(),
|
||||
std::any::TypeId::of::<INT>()].into_boxed_slice()
|
||||
}
|
||||
}
|
||||
pub fn add_together__Token__callable() -> CallableFunction {
|
||||
CallableFunction::from_plugin(add_together__Token())
|
||||
pub fn add_together_token_callable() -> CallableFunction {
|
||||
CallableFunction::from_plugin(add_together_token())
|
||||
}
|
||||
pub fn add_together__Token__input_types() -> Box<[std::any::TypeId]> {
|
||||
add_together__Token().input_types()
|
||||
pub fn add_together_token_input_types() -> Box<[std::any::TypeId]> {
|
||||
add_together_token().input_types()
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -475,7 +475,7 @@ mod generate_tests {
|
||||
#[allow(unused_imports)]
|
||||
use super::*;
|
||||
#[allow(unused_mut)]
|
||||
pub fn rhai_module__generate() -> Module {
|
||||
pub fn rhai_module_generate() -> Module {
|
||||
let mut m = Module::new();
|
||||
m.set_var("MYSTIC_NUMBER", 42);
|
||||
m
|
||||
@ -503,7 +503,7 @@ mod generate_tests {
|
||||
#[allow(unused_imports)]
|
||||
use super::*;
|
||||
#[allow(unused_mut)]
|
||||
pub fn rhai_module__generate() -> Module {
|
||||
pub fn rhai_module_generate() -> Module {
|
||||
let mut m = Module::new();
|
||||
m.set_var("MYSTIC_NUMBER", 42);
|
||||
m
|
||||
@ -533,7 +533,7 @@ mod generate_tests {
|
||||
#[allow(unused_imports)]
|
||||
use super::*;
|
||||
#[allow(unused_mut)]
|
||||
pub fn rhai_module__generate() -> Module {
|
||||
pub fn rhai_module_generate() -> Module {
|
||||
let mut m = Module::new();
|
||||
m
|
||||
}
|
||||
@ -558,7 +558,7 @@ mod generate_tests {
|
||||
#[allow(unused_imports)]
|
||||
use super::*;
|
||||
#[allow(unused_mut)]
|
||||
pub fn rhai_module__generate() -> Module {
|
||||
pub fn rhai_module_generate() -> Module {
|
||||
let mut m = Module::new();
|
||||
m
|
||||
}
|
||||
@ -587,16 +587,16 @@ mod generate_tests {
|
||||
#[allow(unused_imports)]
|
||||
use super::*;
|
||||
#[allow(unused_mut)]
|
||||
pub fn rhai_module__generate() -> Module {
|
||||
pub fn rhai_module_generate() -> Module {
|
||||
let mut m = Module::new();
|
||||
m.set_fn("print_out_to", FnAccess::Public,
|
||||
&[core::any::TypeId::of::<ImmutableString>()],
|
||||
CallableFunction::from_plugin(print_out_to__Token()));
|
||||
CallableFunction::from_plugin(print_out_to_token()));
|
||||
m
|
||||
}
|
||||
#[allow(non_camel_case_types)]
|
||||
struct print_out_to__Token();
|
||||
impl PluginFunction for print_out_to__Token {
|
||||
struct print_out_to_token();
|
||||
impl PluginFunction for print_out_to_token {
|
||||
fn call(&self,
|
||||
args: &mut [&mut Dynamic], pos: Position
|
||||
) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||
@ -612,17 +612,17 @@ mod generate_tests {
|
||||
fn is_method_call(&self) -> bool { false }
|
||||
fn is_varadic(&self) -> bool { false }
|
||||
fn clone_boxed(&self) -> Box<dyn PluginFunction> {
|
||||
Box::new(print_out_to__Token())
|
||||
Box::new(print_out_to_token())
|
||||
}
|
||||
fn input_types(&self) -> Box<[std::any::TypeId]> {
|
||||
vec![std::any::TypeId::of::<ImmutableString>()].into_boxed_slice()
|
||||
}
|
||||
}
|
||||
pub fn print_out_to__Token__callable() -> CallableFunction {
|
||||
CallableFunction::from_plugin(print_out_to__Token())
|
||||
pub fn print_out_to_token_callable() -> CallableFunction {
|
||||
CallableFunction::from_plugin(print_out_to_token())
|
||||
}
|
||||
pub fn print_out_to__Token__input_types() -> Box<[std::any::TypeId]> {
|
||||
print_out_to__Token().input_types()
|
||||
pub fn print_out_to_token_input_types() -> Box<[std::any::TypeId]> {
|
||||
print_out_to_token().input_types()
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -649,16 +649,16 @@ mod generate_tests {
|
||||
#[allow(unused_imports)]
|
||||
use super::*;
|
||||
#[allow(unused_mut)]
|
||||
pub fn rhai_module__generate() -> Module {
|
||||
pub fn rhai_module_generate() -> Module {
|
||||
let mut m = Module::new();
|
||||
m.set_fn("increment", FnAccess::Public,
|
||||
&[core::any::TypeId::of::<FLOAT>()],
|
||||
CallableFunction::from_plugin(increment__Token()));
|
||||
CallableFunction::from_plugin(increment_token()));
|
||||
m
|
||||
}
|
||||
#[allow(non_camel_case_types)]
|
||||
struct increment__Token();
|
||||
impl PluginFunction for increment__Token {
|
||||
struct increment_token();
|
||||
impl PluginFunction for increment_token {
|
||||
fn call(&self,
|
||||
args: &mut [&mut Dynamic], pos: Position
|
||||
) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||
@ -667,24 +667,24 @@ mod generate_tests {
|
||||
format!("wrong arg count: {} != {}",
|
||||
args.len(), 1usize), Position::none())));
|
||||
}
|
||||
let arg0: &mut _ = args[0usize].downcast_mut::<FLOAT>().unwrap();
|
||||
let arg0: &mut _ = args[0usize].write_lock::<FLOAT>().unwrap();
|
||||
Ok(Dynamic::from(increment(arg0)))
|
||||
}
|
||||
|
||||
fn is_method_call(&self) -> bool { true }
|
||||
fn is_varadic(&self) -> bool { false }
|
||||
fn clone_boxed(&self) -> Box<dyn PluginFunction> {
|
||||
Box::new(increment__Token())
|
||||
Box::new(increment_token())
|
||||
}
|
||||
fn input_types(&self) -> Box<[std::any::TypeId]> {
|
||||
vec![std::any::TypeId::of::<FLOAT>()].into_boxed_slice()
|
||||
}
|
||||
}
|
||||
pub fn increment__Token__callable() -> CallableFunction {
|
||||
CallableFunction::from_plugin(increment__Token())
|
||||
pub fn increment_token_callable() -> CallableFunction {
|
||||
CallableFunction::from_plugin(increment_token())
|
||||
}
|
||||
pub fn increment__Token__input_types() -> Box<[std::any::TypeId]> {
|
||||
increment__Token().input_types()
|
||||
pub fn increment_token_input_types() -> Box<[std::any::TypeId]> {
|
||||
increment_token().input_types()
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -26,7 +26,7 @@ pub(crate) fn generate_body(
|
||||
let mut gen_fn_tokens: Vec<proc_macro2::TokenStream> = Vec::new();
|
||||
for function in fns {
|
||||
let fn_token_name = syn::Ident::new(
|
||||
&format!("{}__Token", function.name().to_string()),
|
||||
&format!("{}_Token", function.name().to_string()),
|
||||
function.name().span(),
|
||||
);
|
||||
let fn_literal =
|
||||
@ -90,7 +90,7 @@ pub(crate) fn generate_body(
|
||||
#[allow(unused_imports)]
|
||||
use super::*;
|
||||
#[allow(unused_mut)]
|
||||
pub fn rhai_module__generate() -> Module {
|
||||
pub fn rhai_module_generate() -> Module {
|
||||
let mut m = Module::new();
|
||||
#(#set_fn_stmts)*
|
||||
#(#set_const_stmts)*
|
||||
|
@ -152,7 +152,7 @@ to partition the slice:
|
||||
let (first, rest) = args.split_at_mut(1);
|
||||
|
||||
// Mutable reference to the first parameter
|
||||
let this_ptr = first[0].downcast_mut::<A>().unwrap();
|
||||
let this_ptr = first[0].write_lock::<A>().unwrap();
|
||||
|
||||
// Immutable reference to the second value parameter
|
||||
// This can be mutable but there is no point because the parameter is passed by value
|
||||
|
Loading…
Reference in New Issue
Block a user