Use no-std-compat to build no-std.

This commit is contained in:
Stephen Chung
2021-04-17 15:15:54 +08:00
parent 2f2b7403cb
commit 01f0cc028b
48 changed files with 293 additions and 293 deletions

View File

@@ -1,8 +1,9 @@
#![allow(non_snake_case)]
use crate::plugin::*;
use crate::stdlib::{format, string::String};
use crate::{def_package, EvalAltResult, Position, INT};
#[cfg(feature = "no_std")]
use std::prelude::v1::*;
#[cfg(not(feature = "no_float"))]
use crate::FLOAT;

View File

@@ -3,8 +3,10 @@
use crate::engine::OP_EQUALS;
use crate::plugin::*;
use crate::stdlib::{any::TypeId, boxed::Box, cmp::Ordering, mem, string::ToString};
use crate::{def_package, Array, Dynamic, EvalAltResult, FnPtr, NativeCallContext, Position, INT};
#[cfg(feature = "no_std")]
use std::prelude::v1::*;
use std::{any::TypeId, cmp::Ordering, mem};
def_package!(crate:BasicArrayPackage:"Basic array utilities.", lib, {
combine_with_exported_module!(lib, "array", array_functions);

View File

@@ -1,5 +1,7 @@
use crate::plugin::*;
use crate::{def_package, FnPtr, ImmutableString, NativeCallContext};
#[cfg(feature = "no_std")]
use std::prelude::v1::*;
def_package!(crate:BasicFnPackage:"Basic Fn functions.", lib, {
combine_with_exported_module!(lib, "FnPtr", fn_ptr_functions);
@@ -34,7 +36,8 @@ mod fn_ptr_functions {
#[cfg(not(feature = "no_index"))]
#[cfg(not(feature = "no_object"))]
fn collect_fn_metadata(ctx: NativeCallContext) -> crate::Array {
use crate::{ast::ScriptFnDef, stdlib::collections::BTreeSet, Array, Identifier, Map};
use crate::{ast::ScriptFnDef, Array, Identifier, Map};
use std::collections::BTreeSet;
// Create a metadata record for a function.
fn make_metadata(

View File

@@ -1,15 +1,17 @@
use crate::dynamic::Variant;
use crate::stdlib::{boxed::Box, ops::Range};
use crate::{def_package, EvalAltResult, INT};
use std::ops::Range;
#[cfg(feature = "no_std")]
use std::prelude::v1::*;
#[cfg(not(feature = "unchecked"))]
use crate::stdlib::string::ToString;
use std::string::ToString;
#[cfg(not(feature = "unchecked"))]
use num_traits::{CheckedAdd as Add, CheckedSub as Sub};
#[cfg(feature = "unchecked")]
use crate::stdlib::ops::{Add, Sub};
use std::ops::{Add, Sub};
fn get_range<T: Variant + Clone>(from: T, to: T) -> Result<Range<T>, Box<EvalAltResult>> {
Ok(from..to)
@@ -207,7 +209,7 @@ def_package!(crate:BasicIteratorPackage:"Basic range iterators.", lib, {
pub fn new(from: Decimal, to: Decimal, step: Decimal) -> Result<Self, Box<EvalAltResult>> {
#[cfg(not(feature = "unchecked"))]
if step.is_zero() {
use crate::stdlib::string::ToString;
use std::string::ToString;
return EvalAltResult::ErrorInFunctionCall("range".to_string(), "".to_string(),
Box::new(EvalAltResult::ErrorArithmetic("step value cannot be zero".to_string(), crate::Position::NONE)),
@@ -251,7 +253,7 @@ def_package!(crate:BasicIteratorPackage:"Basic range iterators.", lib, {
}
}
impl crate::stdlib::iter::FusedIterator for StepDecimalRange {}
impl std::iter::FusedIterator for StepDecimalRange {}
lib.set_iterator::<StepDecimalRange>();

View File

@@ -2,6 +2,8 @@
use crate::def_package;
use crate::plugin::*;
#[cfg(feature = "no_std")]
use std::prelude::v1::*;
#[cfg(any(
not(feature = "no_float"),

View File

@@ -3,6 +3,8 @@
use crate::engine::OP_EQUALS;
use crate::plugin::*;
use crate::{def_package, Dynamic, ImmutableString, Map, INT};
#[cfg(feature = "no_std")]
use std::prelude::v1::*;
#[cfg(not(feature = "no_index"))]
use crate::Array;

View File

@@ -2,6 +2,8 @@
use crate::plugin::*;
use crate::{def_package, Position, INT};
#[cfg(feature = "no_std")]
use std::prelude::v1::*;
#[cfg(not(feature = "no_float"))]
use crate::FLOAT;
@@ -9,9 +11,6 @@ use crate::FLOAT;
#[cfg(not(feature = "no_float"))]
use crate::result::EvalAltResult;
#[cfg(not(feature = "no_float"))]
use crate::stdlib::format;
#[cfg(feature = "no_std")]
#[cfg(not(feature = "no_float"))]
use num_traits::Float;
@@ -194,16 +193,16 @@ mod float_functions {
#[rhai_fn(name = "E")]
pub fn e() -> FLOAT {
#[cfg(not(feature = "f32_float"))]
return crate::stdlib::f64::consts::E;
return std::f64::consts::E;
#[cfg(feature = "f32_float")]
return crate::stdlib::f32::consts::E;
return std::f32::consts::E;
}
#[rhai_fn(name = "PI")]
pub fn pi() -> FLOAT {
#[cfg(not(feature = "f32_float"))]
return crate::stdlib::f64::consts::PI;
return std::f64::consts::PI;
#[cfg(feature = "f32_float")]
return crate::stdlib::f32::consts::PI;
return std::f32::consts::PI;
}
pub fn to_radians(x: FLOAT) -> FLOAT {
x.to_radians()
@@ -304,11 +303,11 @@ mod float_functions {
#[cfg(feature = "decimal")]
#[export_module]
mod decimal_functions {
use crate::stdlib::convert::TryFrom;
use rust_decimal::{
prelude::{FromStr, RoundingStrategy},
Decimal,
};
use std::convert::TryFrom;
#[rhai_fn(name = "floor", get = "floor")]
pub fn floor(x: Decimal) -> Decimal {

View File

@@ -3,6 +3,8 @@ use super::fn_basic::BasicFnPackage;
use super::iter_basic::BasicIteratorPackage;
use super::logic::LogicPackage;
use super::string_basic::BasicStringPackage;
#[cfg(feature = "no_std")]
use std::prelude::v1::*;
use crate::def_package;

View File

@@ -7,6 +7,8 @@ use super::pkg_core::CorePackage;
use super::string_more::MoreStringPackage;
#[cfg(not(feature = "no_std"))]
use super::time_basic::BasicTimePackage;
#[cfg(feature = "no_std")]
use std::prelude::v1::*;
use crate::def_package;

View File

@@ -1,8 +1,9 @@
#![allow(non_snake_case)]
use crate::plugin::*;
use crate::stdlib::{format, string::ToString};
use crate::{def_package, FnPtr};
#[cfg(feature = "no_std")]
use std::prelude::v1::*;
#[cfg(not(feature = "no_index"))]
use crate::Array;
@@ -69,10 +70,6 @@ mod print_debug_functions {
#[cfg(not(feature = "no_float"))]
pub mod float_functions {
#[cfg(feature = "no_std")]
#[cfg(not(feature = "no_float"))]
use num_traits::Float;
use crate::ast::FloatWrapper;
#[rhai_fn(name = "print", name = "to_string")]
@@ -106,7 +103,7 @@ mod print_debug_functions {
)]
pub fn format_array(ctx: NativeCallContext, array: &mut Array) -> ImmutableString {
let len = array.len();
let mut result = crate::stdlib::string::String::with_capacity(len * 5 + 2);
let mut result = std::string::String::with_capacity(len * 5 + 2);
result.push_str("[");
array.iter_mut().enumerate().for_each(|(i, x)| {
@@ -133,7 +130,7 @@ mod print_debug_functions {
)]
pub fn format_map(ctx: NativeCallContext, map: &mut Map) -> ImmutableString {
let len = map.len();
let mut result = crate::stdlib::string::String::with_capacity(len * 5 + 3);
let mut result = std::string::String::with_capacity(len * 5 + 3);
result.push_str("#{");
map.iter_mut().enumerate().for_each(|(i, (k, v))| {

View File

@@ -1,10 +1,10 @@
#![allow(non_snake_case)]
use crate::plugin::*;
use crate::stdlib::{
any::TypeId, boxed::Box, format, mem, string::String, string::ToString, vec::Vec,
};
use crate::{def_package, Dynamic, ImmutableString, StaticVec, INT};
#[cfg(feature = "no_std")]
use std::prelude::v1::*;
use std::{any::TypeId, mem};
use super::string_basic::{print_with_func, FUNC_TO_STRING};
@@ -422,7 +422,6 @@ mod string_functions {
#[cfg(not(feature = "no_index"))]
pub mod arrays {
use crate::stdlib::vec;
use crate::{Array, ImmutableString};
#[rhai_fn(name = "split")]

View File

@@ -2,14 +2,15 @@
use super::{arithmetic::make_err as make_arithmetic_err, math_basic::MAX_INT};
use crate::plugin::*;
use crate::stdlib::boxed::Box;
use crate::{def_package, Dynamic, EvalAltResult, INT};
#[cfg(feature = "no_std")]
use std::prelude::v1::*;
#[cfg(not(feature = "no_float"))]
use crate::FLOAT;
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
use crate::stdlib::time::{Duration, Instant};
use std::time::{Duration, Instant};
#[cfg(any(target_arch = "wasm32", target_arch = "wasm64"))]
use instant::{Duration, Instant};