Nicer formatting/less indentation of module plugin blocks.
This commit is contained in:
parent
b4406f2302
commit
8736919cea
@ -17,8 +17,7 @@ use crate::stdlib::format;
|
|||||||
|
|
||||||
macro_rules! gen_arithmetic_functions {
|
macro_rules! gen_arithmetic_functions {
|
||||||
($root:ident => $($arg_type:ident),+) => {
|
($root:ident => $($arg_type:ident),+) => {
|
||||||
pub mod $root { $(
|
pub mod $root { $(pub mod $arg_type {
|
||||||
pub mod $arg_type {
|
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
#[export_module]
|
#[export_module]
|
||||||
@ -211,15 +210,13 @@ macro_rules! gen_arithmetic_functions {
|
|||||||
x ^ y
|
x ^ y
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
})* }
|
||||||
)* }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! gen_signed_functions {
|
macro_rules! gen_signed_functions {
|
||||||
($root:ident => $($arg_type:ident),+) => {
|
($root:ident => $($arg_type:ident),+) => {
|
||||||
pub mod $root { $(
|
pub mod $root { $(pub mod $arg_type {
|
||||||
pub mod $arg_type {
|
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
#[export_module]
|
#[export_module]
|
||||||
@ -259,8 +256,7 @@ macro_rules! gen_signed_functions {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
})* }
|
||||||
)* }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,30 +23,33 @@ pub type Unit = ();
|
|||||||
|
|
||||||
macro_rules! gen_array_functions {
|
macro_rules! gen_array_functions {
|
||||||
($root:ident => $($arg_type:ident),+ ) => {
|
($root:ident => $($arg_type:ident),+ ) => {
|
||||||
pub mod $root { $(
|
pub mod $root { $(pub mod $arg_type {
|
||||||
pub mod $arg_type {
|
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
#[export_fn]
|
#[export_fn]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn push_func(list: &mut Array, item: $arg_type) {
|
pub fn push(list: &mut Array, item: $arg_type) {
|
||||||
super::super::push(list, item);
|
list.push(Dynamic::from(item));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[export_fn]
|
#[export_fn]
|
||||||
#[inline(always)]
|
pub fn insert(list: &mut Array, position: INT, item: $arg_type) {
|
||||||
pub fn insert_func(list: &mut Array, len: INT, item: $arg_type) {
|
if position <= 0 {
|
||||||
super::super::insert(list, len, item);
|
list.insert(0, Dynamic::from(item));
|
||||||
|
} else if (position as usize) >= list.len() - 1 {
|
||||||
|
push(list, item);
|
||||||
|
} else {
|
||||||
|
list.insert(position as usize, Dynamic::from(item));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)* }
|
})* }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! reg_functions {
|
macro_rules! reg_functions {
|
||||||
($mod_name:ident += $root:ident ; $($arg_type:ident),+) => { $(
|
($mod_name:ident += $root:ident ; $($arg_type:ident),+) => { $(
|
||||||
set_exported_fn!($mod_name, "push", $root::$arg_type::push_func);
|
set_exported_fn!($mod_name, "push", $root::$arg_type::push);
|
||||||
set_exported_fn!($mod_name, "insert", $root::$arg_type::insert_func);
|
set_exported_fn!($mod_name, "insert", $root::$arg_type::insert);
|
||||||
|
|
||||||
$mod_name.set_raw_fn("pad",
|
$mod_name.set_raw_fn("pad",
|
||||||
&[TypeId::of::<Array>(), TypeId::of::<INT>(), TypeId::of::<$arg_type>()],
|
&[TypeId::of::<Array>(), TypeId::of::<INT>(), TypeId::of::<$arg_type>()],
|
||||||
@ -138,20 +141,6 @@ mod array_functions {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register array utility functions
|
|
||||||
#[inline(always)]
|
|
||||||
fn push<T: Variant + Clone>(list: &mut Array, item: T) {
|
|
||||||
list.push(Dynamic::from(item));
|
|
||||||
}
|
|
||||||
fn insert<T: Variant + Clone>(list: &mut Array, position: INT, item: T) {
|
|
||||||
if position <= 0 {
|
|
||||||
list.insert(0, Dynamic::from(item));
|
|
||||||
} else if (position as usize) >= list.len() - 1 {
|
|
||||||
push(list, item);
|
|
||||||
} else {
|
|
||||||
list.insert(position as usize, Dynamic::from(item));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fn pad<T: Variant + Clone>(
|
fn pad<T: Variant + Clone>(
|
||||||
_engine: &Engine,
|
_engine: &Engine,
|
||||||
_: &Module,
|
_: &Module,
|
||||||
|
@ -3,9 +3,8 @@ use crate::plugin::*;
|
|||||||
|
|
||||||
macro_rules! gen_cmp_functions {
|
macro_rules! gen_cmp_functions {
|
||||||
($root:ident => $($arg_type:ident),+) => {
|
($root:ident => $($arg_type:ident),+) => {
|
||||||
mod $root { $(
|
mod $root { $(pub mod $arg_type {
|
||||||
pub mod $arg_type {
|
use super::super::*;
|
||||||
use crate::plugin::*;
|
|
||||||
|
|
||||||
#[export_module]
|
#[export_module]
|
||||||
pub mod functions {
|
pub mod functions {
|
||||||
@ -40,8 +39,7 @@ macro_rules! gen_cmp_functions {
|
|||||||
x != y
|
x != y
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
})* }
|
||||||
)* }
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,8 +26,7 @@ pub const MAX_INT: INT = i64::MAX;
|
|||||||
|
|
||||||
macro_rules! gen_conversion_functions {
|
macro_rules! gen_conversion_functions {
|
||||||
($root:ident => $func_name:ident ( $($arg_type:ident),+ ) -> $result_type:ty) => {
|
($root:ident => $func_name:ident ( $($arg_type:ident),+ ) -> $result_type:ty) => {
|
||||||
pub mod $root { $(
|
pub mod $root { $(pub mod $arg_type {
|
||||||
pub mod $arg_type {
|
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
#[export_fn]
|
#[export_fn]
|
||||||
@ -35,8 +34,7 @@ macro_rules! gen_conversion_functions {
|
|||||||
pub fn $func_name(x: $arg_type) -> $result_type {
|
pub fn $func_name(x: $arg_type) -> $result_type {
|
||||||
x as $result_type
|
x as $result_type
|
||||||
}
|
}
|
||||||
}
|
})* }
|
||||||
)* }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,8 +22,7 @@ type Unit = ();
|
|||||||
|
|
||||||
macro_rules! gen_functions {
|
macro_rules! gen_functions {
|
||||||
($root:ident => $fn_name:ident ( $($arg_type:ident),+ )) => {
|
($root:ident => $fn_name:ident ( $($arg_type:ident),+ )) => {
|
||||||
pub mod $root { $(
|
pub mod $root { $(pub mod $arg_type {
|
||||||
pub mod $arg_type {
|
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
#[export_fn]
|
#[export_fn]
|
||||||
@ -31,8 +30,7 @@ macro_rules! gen_functions {
|
|||||||
pub fn to_string_func(x: &mut $arg_type) -> ImmutableString {
|
pub fn to_string_func(x: &mut $arg_type) -> ImmutableString {
|
||||||
super::super::$fn_name(x)
|
super::super::$fn_name(x)
|
||||||
}
|
}
|
||||||
}
|
})* }
|
||||||
)* }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,12 +126,12 @@ gen_functions!(print_array => to_debug(Array));
|
|||||||
#[export_fn]
|
#[export_fn]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn print_empty_string() -> ImmutableString {
|
fn print_empty_string() -> ImmutableString {
|
||||||
"".to_string().into()
|
String::new().into()
|
||||||
}
|
}
|
||||||
#[export_fn]
|
#[export_fn]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn print_unit(_x: ()) -> ImmutableString {
|
fn print_unit(_x: ()) -> ImmutableString {
|
||||||
"".to_string().into()
|
String::new().into()
|
||||||
}
|
}
|
||||||
#[export_fn]
|
#[export_fn]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
@ -143,7 +141,7 @@ fn print_string(s: ImmutableString) -> ImmutableString {
|
|||||||
#[export_fn]
|
#[export_fn]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn debug_fn_ptr(f: &mut FnPtr) -> ImmutableString {
|
fn debug_fn_ptr(f: &mut FnPtr) -> ImmutableString {
|
||||||
f.to_string().into()
|
to_string(f)
|
||||||
}
|
}
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn to_string<T: Display>(x: &mut T) -> ImmutableString {
|
fn to_string<T: Display>(x: &mut T) -> ImmutableString {
|
||||||
|
@ -12,28 +12,26 @@ use crate::utils::StaticVec;
|
|||||||
use crate::{result::EvalAltResult, token::Position};
|
use crate::{result::EvalAltResult, token::Position};
|
||||||
|
|
||||||
use crate::stdlib::{
|
use crate::stdlib::{
|
||||||
any::TypeId, boxed::Box, fmt::Display, format, mem, string::String, string::ToString, vec::Vec,
|
any::TypeId, boxed::Box, format, mem, string::String, string::ToString, vec::Vec,
|
||||||
};
|
};
|
||||||
|
|
||||||
macro_rules! gen_concat_functions {
|
macro_rules! gen_concat_functions {
|
||||||
($root:ident => $($arg_type:ident),+ ) => {
|
($root:ident => $($arg_type:ident),+ ) => {
|
||||||
pub mod $root { $(
|
pub mod $root { $(pub mod $arg_type {
|
||||||
pub mod $arg_type {
|
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
#[export_fn]
|
#[export_fn]
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
pub fn append_func(x: &mut ImmutableString, y: $arg_type) -> String {
|
pub fn append_func(x: &mut ImmutableString, y: $arg_type) -> String {
|
||||||
super::super::add_append(x, y)
|
format!("{}{}", x, y)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[export_fn]
|
#[export_fn]
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
pub fn prepend_func(x: &mut $arg_type, y: ImmutableString) -> String {
|
pub fn prepend_func(x: &mut $arg_type, y: ImmutableString) -> String {
|
||||||
super::super::add_prepend(x, y)
|
format!("{}{}", x, y)
|
||||||
}
|
}
|
||||||
}
|
})* }
|
||||||
)* }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,15 +114,6 @@ def_package!(crate:MoreStringPackage:"Additional string utilities, including str
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn add_prepend<T: Display>(x: &mut T, y: ImmutableString) -> String {
|
|
||||||
format!("{}{}", x, y)
|
|
||||||
}
|
|
||||||
#[inline]
|
|
||||||
fn add_append<T: Display>(x: &mut ImmutableString, y: T) -> String {
|
|
||||||
format!("{}{}", x, y)
|
|
||||||
}
|
|
||||||
|
|
||||||
gen_concat_functions!(basic => INT, bool, char, FnPtr);
|
gen_concat_functions!(basic => INT, bool, char, FnPtr);
|
||||||
|
|
||||||
#[cfg(not(feature = "only_i32"))]
|
#[cfg(not(feature = "only_i32"))]
|
||||||
|
Loading…
Reference in New Issue
Block a user