Skip to content

Commit

Permalink
Module rework (#501)
Browse files Browse the repository at this point in the history
* Add API to associate documentation with inserted items
* Rework the module and function traits
  • Loading branch information
udoprog authored May 6, 2023
1 parent e7aa050 commit 2778a1e
Show file tree
Hide file tree
Showing 50 changed files with 2,177 additions and 2,120 deletions.
4 changes: 0 additions & 4 deletions crates/rune-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,5 @@ syn = { version = "2.0.15", features = ["full"] }
quote = "1.0.26"
proc-macro2 = { version = "1.0.56", features = ["span-locations"] }

[dev-dependencies]
rune = { version = "0.12.3", path = "../rune" }

[lib]
proc-macro = true
path = "src/lib.rs"
8 changes: 4 additions & 4 deletions crates/rune-macros/src/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ fn expand_enum_install_with(
generics: &syn::Generics,
) -> Option<()> {
let Tokens {
compile_variant,
module_variant,
protocol,
to_value,
type_of,
Expand Down Expand Up @@ -266,7 +266,7 @@ fn expand_enum_install_with(
}
}

variants.push(quote!((#variant_name, #compile_variant::st([#(#field_names),*]))));
variants.push(quote!((#variant_name, #module_variant::st([#(#field_names),*]))));
}
syn::Fields::Unnamed(fields) => {
let mut fields_len = 0usize;
Expand All @@ -290,7 +290,7 @@ fn expand_enum_install_with(
}
}

variants.push(quote!((#variant_name, #compile_variant::tuple(#fields_len))));
variants.push(quote!((#variant_name, #module_variant::tuple(#fields_len))));

if variant_attrs.constructor {
if fields_len != fields.unnamed.len() {
Expand All @@ -302,7 +302,7 @@ fn expand_enum_install_with(
}
}
syn::Fields::Unit => {
variants.push(quote!((#variant_name, #compile_variant::unit())));
variants.push(quote!((#variant_name, #module_variant::unit())));

if variant_attrs.constructor {
constructors
Expand Down
36 changes: 18 additions & 18 deletions crates/rune-macros/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,97 +617,97 @@ impl Context {
};

Tokens {
any_type_info: quote!(#module::runtime::AnyTypeInfo),
any: quote!(#module::Any),
compile_error: quote!(#module::compile::Error),
context_error: quote!(#module::compile::ContextError),
from_value: quote!(#module::runtime::FromValue),
full_type_of: quote!(#module::runtime::FullTypeOf),
hash: quote!(#module::Hash),
id: quote!(#module::parse::Id),
install_with: quote!(#module::compile::InstallWith),
install_with: quote!(#module::__private::InstallWith),
macro_context: quote!(#module::macros::MacroContext),
module: quote!(#module::compile::Module),
maybe_type_of: quote!(#module::runtime::MaybeTypeOf),
module_variant: quote!(#module::module::Variant),
module: quote!(#module::__private::Module),
named: quote!(#module::compile::Named),
object: quote!(#module::runtime::Object),
opaque: quote!(#module::parse::Opaque),
option_spanned: quote!(#module::ast::OptionSpanned),
compile_error: quote!(#module::compile::Error),
parse: quote!(#module::parse::Parse),
parser: quote!(#module::parse::Parser),
pointer_guard: quote!(#module::runtime::SharedPointerGuard),
protocol: quote!(#module::runtime::Protocol),
raw_into_mut: quote!(#module::runtime::RawMut),
raw_into_ref: quote!(#module::runtime::RawRef),
raw_str: quote!(#module::runtime::RawStr),
result: quote!(::core::result::Result),
shared: quote!(#module::runtime::Shared),
span: quote!(#module::ast::Span),
spanned: quote!(#module::ast::Spanned),
to_tokens: quote!(#module::macros::ToTokens),
to_value: quote!(#module::runtime::ToValue),
token_stream: quote!(#module::macros::TokenStream),
try_result: quote!(#module::runtime::try_result),
tuple: quote!(#module::runtime::Tuple),
type_info: quote!(#module::runtime::TypeInfo),
any_type_info: quote!(#module::runtime::AnyTypeInfo),
type_name: quote!(::core::any::type_name),
type_of: quote!(#module::runtime::TypeOf),
maybe_type_of: quote!(#module::runtime::MaybeTypeOf),
full_type_of: quote!(#module::runtime::FullTypeOf),
unit_struct: quote!(#module::runtime::UnitStruct),
unsafe_from_value: quote!(#module::runtime::UnsafeFromValue),
unsafe_to_value: quote!(#module::runtime::UnsafeToValue),
value: quote!(#module::runtime::Value),
variant_data: quote!(#module::runtime::VariantData),
compile_variant: quote!(#module::compile::Variant),
vm_error: quote!(#module::runtime::VmError),
vm_result: quote!(#module::runtime::VmResult),
try_result: quote!(#module::runtime::try_result),
type_name: quote!(::core::any::type_name),
result: quote!(::core::result::Result),
}
}
}

pub(crate) struct Tokens {
pub(crate) any_type_info: TokenStream,
pub(crate) any: TokenStream,
pub(crate) compile_error: TokenStream,
pub(crate) context_error: TokenStream,
pub(crate) from_value: TokenStream,
pub(crate) full_type_of: TokenStream,
pub(crate) hash: TokenStream,
pub(crate) id: TokenStream,
pub(crate) install_with: TokenStream,
pub(crate) macro_context: TokenStream,
pub(crate) maybe_type_of: TokenStream,
pub(crate) module_variant: TokenStream,
pub(crate) module: TokenStream,
pub(crate) named: TokenStream,
pub(crate) object: TokenStream,
pub(crate) opaque: TokenStream,
pub(crate) option_spanned: TokenStream,
pub(crate) compile_error: TokenStream,
pub(crate) parse: TokenStream,
pub(crate) parser: TokenStream,
pub(crate) pointer_guard: TokenStream,
pub(crate) protocol: TokenStream,
pub(crate) raw_into_mut: TokenStream,
pub(crate) raw_into_ref: TokenStream,
pub(crate) raw_str: TokenStream,
pub(crate) result: TokenStream,
pub(crate) shared: TokenStream,
pub(crate) span: TokenStream,
pub(crate) spanned: TokenStream,
pub(crate) to_tokens: TokenStream,
pub(crate) to_value: TokenStream,
pub(crate) token_stream: TokenStream,
pub(crate) try_result: TokenStream,
pub(crate) tuple: TokenStream,
pub(crate) type_info: TokenStream,
pub(crate) any_type_info: TokenStream,
pub(crate) type_name: TokenStream,
pub(crate) type_of: TokenStream,
pub(crate) maybe_type_of: TokenStream,
pub(crate) full_type_of: TokenStream,
pub(crate) unit_struct: TokenStream,
pub(crate) unsafe_from_value: TokenStream,
pub(crate) unsafe_to_value: TokenStream,
pub(crate) value: TokenStream,
pub(crate) variant_data: TokenStream,
pub(crate) compile_variant: TokenStream,
pub(crate) vm_error: TokenStream,
pub(crate) vm_result: TokenStream,
pub(crate) try_result: TokenStream,
pub(crate) type_name: TokenStream,
pub(crate) result: TokenStream,
}

impl Tokens {
Expand Down
Loading

0 comments on commit 2778a1e

Please sign in to comment.