Merge pull request #34 from jhwgh1968/plugins

Improve CI and Fix Warnings and Errors
This commit is contained in:
Stephen Chung 2020-08-15 11:13:09 +08:00 committed by GitHub
commit 6b5741ecaa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 41 additions and 20 deletions

View File

@ -4,6 +4,7 @@ on:
push: push:
branches: branches:
- master - master
- plugins
pull_request: {} pull_request: {}
jobs: jobs:

View File

@ -3,6 +3,11 @@
#[cfg(no_std)] #[cfg(no_std)]
use core::mem; use core::mem;
#[cfg(no_std)]
use alloc::format;
#[cfg(not(no_std))]
use std::format;
use std::collections::HashMap; use std::collections::HashMap;
use quote::{quote, quote_spanned}; use quote::{quote, quote_spanned};

View File

@ -3,7 +3,9 @@
use crate::any::{Dynamic, Variant}; use crate::any::{Dynamic, Variant};
use crate::def_package; use crate::def_package;
use crate::engine::{make_getter, Array, Engine}; #[cfg(not(feature = "no_object"))]
use crate::engine::make_getter;
use crate::engine::{Array, Engine};
use crate::fn_native::FnPtr; use crate::fn_native::FnPtr;
use crate::parser::{ImmutableString, INT}; use crate::parser::{ImmutableString, INT};
use crate::plugin::*; use crate::plugin::*;

View File

@ -1,4 +1,5 @@
use crate::def_package; use crate::def_package;
#[cfg(not(feature = "no_object"))]
use crate::engine::make_getter; use crate::engine::make_getter;
use crate::fn_native::FnPtr; use crate::fn_native::FnPtr;
use crate::plugin::*; use crate::plugin::*;

View File

@ -1,4 +1,5 @@
use crate::def_package; use crate::def_package;
#[cfg(not(feature = "no_object"))]
use crate::engine::make_getter; use crate::engine::make_getter;
use crate::parser::INT; use crate::parser::INT;
use crate::plugin::*; use crate::plugin::*;
@ -211,6 +212,8 @@ mod float_functions {
mod float_funcs { mod float_funcs {
use crate::parser::FLOAT; use crate::parser::FLOAT;
use crate::plugin::*; use crate::plugin::*;
#[cfg(feature = "no_std")]
use num_traits::float::Float;
#[export_fn] #[export_fn]
pub fn floor(x: FLOAT) -> FLOAT { pub fn floor(x: FLOAT) -> FLOAT {

View File

@ -2,7 +2,9 @@
use crate::any::Dynamic; use crate::any::Dynamic;
use crate::def_package; use crate::def_package;
use crate::engine::{make_getter, Engine}; #[cfg(not(feature = "no_object"))]
use crate::engine::make_getter;
use crate::engine::Engine;
use crate::fn_native::FnPtr; use crate::fn_native::FnPtr;
use crate::parser::{ImmutableString, INT}; use crate::parser::{ImmutableString, INT};
use crate::plugin::*; use crate::plugin::*;
@ -11,11 +13,8 @@ use crate::utils::StaticVec;
#[cfg(not(feature = "unchecked"))] #[cfg(not(feature = "unchecked"))]
use crate::{result::EvalAltResult, token::Position}; use crate::{result::EvalAltResult, token::Position};
#[cfg(not(feature = "no_index"))]
use crate::engine::Array;
use crate::stdlib::{ use crate::stdlib::{
any::TypeId, boxed::Box, fmt::Display, format, mem, string::ToString, vec::Vec, any::TypeId, boxed::Box, fmt::Display, format, mem, string::String, string::ToString, vec::Vec,
}; };
macro_rules! gen_concat_functions { macro_rules! gen_concat_functions {
@ -47,8 +46,6 @@ macro_rules! reg_functions {
def_package!(crate:MoreStringPackage:"Additional string utilities, including string building.", lib, { def_package!(crate:MoreStringPackage:"Additional string utilities, including string building.", lib, {
reg_functions!(lib += basic; INT, bool, char, FnPtr); reg_functions!(lib += basic; INT, bool, char, FnPtr);
set_exported_fn!(lib, "+", string_funcs::append_unit);
set_exported_fn!(lib, "+", string_funcs::prepend_unit);
#[cfg(not(feature = "only_i32"))] #[cfg(not(feature = "only_i32"))]
#[cfg(not(feature = "only_i64"))] #[cfg(not(feature = "only_i64"))]
@ -64,8 +61,8 @@ def_package!(crate:MoreStringPackage:"Additional string utilities, including str
#[cfg(not(feature = "no_index"))] #[cfg(not(feature = "no_index"))]
{ {
set_exported_fn!(lib, "+", string_funcs::append_array); set_exported_fn!(lib, "+", string_funcs_array::append_array);
set_exported_fn!(lib, "+", string_funcs::prepend_array); set_exported_fn!(lib, "+", string_funcs_array::prepend_array);
} }
lib.combine(exported_module!(string_functions)); lib.combine(exported_module!(string_functions));
@ -192,11 +189,28 @@ mod string_functions {
} }
} }
mod string_funcs { #[cfg(not(feature = "no_index"))]
mod string_funcs_array {
use crate::engine::Array; use crate::engine::Array;
use crate::plugin::*;
use crate::utils::ImmutableString;
use crate::stdlib::string::String;
#[export_fn]
pub fn append_array(x: &mut ImmutableString, y: Array) -> String {
format!("{}{:?}", x, y)
}
#[export_fn]
pub fn prepend_array(x: &mut Array, y: ImmutableString) -> String {
format!("{:?}{}", x, y)
}
}
mod string_funcs {
use crate::parser::INT; use crate::parser::INT;
use crate::plugin::*; use crate::plugin::*;
use crate::utils::{ImmutableString, StaticVec}; use crate::utils::{ImmutableString, StaticVec};
use crate::stdlib::string::{String, ToString};
#[export_fn] #[export_fn]
pub fn append_unit(s: ImmutableString, _x: ()) -> ImmutableString { pub fn append_unit(s: ImmutableString, _x: ()) -> ImmutableString {
@ -207,14 +221,6 @@ mod string_funcs {
s s
} }
#[export_fn] #[export_fn]
pub fn append_array(x: &mut ImmutableString, y: Array) -> String {
format!("{}{:?}", x, y)
}
#[export_fn]
pub fn prepend_array(x: &mut Array, y: ImmutableString) -> String {
format!("{:?}{}", x, y)
}
#[export_fn]
pub fn len(s: &mut ImmutableString) -> INT { pub fn len(s: &mut ImmutableString) -> INT {
s.chars().count() as INT s.chars().count() as INT
} }

View File

@ -5,6 +5,7 @@
use super::math_basic::MAX_INT; use super::math_basic::MAX_INT;
use crate::def_package; use crate::def_package;
#[cfg(not(feature = "no_object"))]
use crate::engine::make_getter; use crate::engine::make_getter;
use crate::plugin::*; use crate::plugin::*;
use crate::result::EvalAltResult; use crate::result::EvalAltResult;
@ -98,7 +99,7 @@ fn time_diff(ts1: Instant, ts2: Instant) -> Result<Dynamic, Box<EvalAltResult>>
.into(); .into();
} }
Ok(-(seconds as INT).into()) Ok(Dynamic::from(-(seconds as INT)))
} else { } else {
let seconds = (ts1 - ts2).as_secs(); let seconds = (ts1 - ts2).as_secs();

View File

@ -3,6 +3,8 @@
pub use crate::{ pub use crate::{
stdlib::any::TypeId, stdlib::any::TypeId,
stdlib::boxed::Box, stdlib::boxed::Box,
stdlib::format,
stdlib::string::ToString,
stdlib::vec::Vec, stdlib::vec::Vec,
stdlib::vec as new_vec, stdlib::vec as new_vec,
stdlib::mem, stdlib::mem,