Remove crate:: from types.
This commit is contained in:
parent
b1e8b48471
commit
6791ef64da
@ -230,6 +230,8 @@ pub mod array_functions {
|
||||
// Check if array will be over max size limit
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
{
|
||||
use crate::types::dynamic::Union;
|
||||
|
||||
if _ctx.engine().max_array_size() > 0 && len > _ctx.engine().max_array_size() {
|
||||
return Err(
|
||||
ERR::ErrorDataTooLarge("Size of array".to_string(), Position::NONE).into(),
|
||||
@ -237,10 +239,10 @@ pub mod array_functions {
|
||||
}
|
||||
|
||||
let check_sizes = match item.0 {
|
||||
crate::types::dynamic::Union::Str(..) => true,
|
||||
crate::types::dynamic::Union::Array(..) => true,
|
||||
Union::Str(..) => true,
|
||||
Union::Array(..) => true,
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
crate::types::dynamic::Union::Map(..) => true,
|
||||
Union::Map(..) => true,
|
||||
_ => false,
|
||||
};
|
||||
|
||||
|
@ -143,7 +143,7 @@ mod bit_field_functions {
|
||||
}
|
||||
|
||||
// 2^bits - 1
|
||||
let mask = ((2 as UNSIGNED_INT).pow(bits as u32) - 1) as crate::INT;
|
||||
let mask = ((2 as UNSIGNED_INT).pow(bits as u32) - 1) as INT;
|
||||
|
||||
Ok(((value & (mask << bit)) >> bit) & mask)
|
||||
}
|
||||
@ -230,7 +230,7 @@ mod bit_field_functions {
|
||||
}
|
||||
|
||||
// 2^bits - 1
|
||||
let mask = ((2 as UNSIGNED_INT).pow(bits as u32) - 1) as crate::INT;
|
||||
let mask = ((2 as UNSIGNED_INT).pow(bits as u32) - 1) as INT;
|
||||
|
||||
*value &= !(mask << bit);
|
||||
*value |= (new_value & mask) << bit;
|
||||
|
@ -5,7 +5,7 @@ use crate::module::ModuleFlags;
|
||||
use crate::plugin::*;
|
||||
use crate::{
|
||||
def_package, Array, Blob, Dynamic, ExclusiveRange, InclusiveRange, NativeCallContext, Position,
|
||||
RhaiResultOf, INT, INT_BYTES, MAX_USIZE_INT,
|
||||
RhaiResultOf, ERR, INT, INT_BYTES, MAX_USIZE_INT,
|
||||
};
|
||||
#[cfg(feature = "no_std")]
|
||||
use std::prelude::v1::*;
|
||||
@ -363,9 +363,7 @@ pub mod blob_functions {
|
||||
|
||||
// Check if blob will be over max size limit
|
||||
if _ctx.engine().max_array_size() > 0 && len > _ctx.engine().max_array_size() {
|
||||
return Err(
|
||||
crate::ERR::ErrorDataTooLarge("Size of BLOB".to_string(), Position::NONE).into(),
|
||||
);
|
||||
return Err(ERR::ErrorDataTooLarge("Size of BLOB".to_string(), Position::NONE).into());
|
||||
}
|
||||
|
||||
if len > blob.len() {
|
||||
|
@ -34,16 +34,18 @@ mod debugging_functions {
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
#[cfg(not(feature = "no_index"))]
|
||||
pub fn back_trace(ctx: NativeCallContext) -> Array {
|
||||
use crate::debugger::CallStackFrame;
|
||||
|
||||
ctx.global_runtime_state()
|
||||
.debugger
|
||||
.call_stack()
|
||||
.iter()
|
||||
.rev()
|
||||
.filter(|crate::debugger::CallStackFrame { fn_name, args, .. }| {
|
||||
.filter(|CallStackFrame { fn_name, args, .. }| {
|
||||
fn_name.as_str() != "back_trace" || !args.is_empty()
|
||||
})
|
||||
.map(
|
||||
|frame @ crate::debugger::CallStackFrame {
|
||||
|frame @ CallStackFrame {
|
||||
fn_name: _fn_name,
|
||||
args: _args,
|
||||
source: _source,
|
||||
@ -53,6 +55,8 @@ mod debugging_functions {
|
||||
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
{
|
||||
use crate::INT;
|
||||
|
||||
let mut map = Map::new();
|
||||
map.insert("display".into(), display.into());
|
||||
map.insert("fn_name".into(), _fn_name.into());
|
||||
@ -63,10 +67,10 @@ mod debugging_functions {
|
||||
map.insert("source".into(), source.into());
|
||||
}
|
||||
if !_pos.is_none() {
|
||||
map.insert("line".into(), (_pos.line().unwrap() as crate::INT).into());
|
||||
map.insert("line".into(), (_pos.line().unwrap() as INT).into());
|
||||
map.insert(
|
||||
"position".into(),
|
||||
(_pos.position().unwrap_or(0) as crate::INT).into(),
|
||||
(_pos.position().unwrap_or(0) as INT).into(),
|
||||
);
|
||||
}
|
||||
Dynamic::from_map(map)
|
||||
|
@ -2,7 +2,7 @@ use crate::eval::calc_index;
|
||||
use crate::module::ModuleFlags;
|
||||
use crate::plugin::*;
|
||||
use crate::{
|
||||
def_package, ExclusiveRange, InclusiveRange, RhaiResultOf, INT, INT_BITS, MAX_USIZE_INT,
|
||||
def_package, ExclusiveRange, InclusiveRange, RhaiResultOf, ERR, INT, INT_BITS, MAX_USIZE_INT,
|
||||
};
|
||||
#[cfg(feature = "no_std")]
|
||||
use std::prelude::v1::*;
|
||||
@ -66,14 +66,11 @@ impl<T: Copy + PartialOrd> StepRange<T> {
|
||||
if let Some(n) = add(from, step) {
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
if n == from {
|
||||
return Err(crate::ERR::ErrorInFunctionCall(
|
||||
return Err(ERR::ErrorInFunctionCall(
|
||||
"range".to_string(),
|
||||
String::new(),
|
||||
crate::ERR::ErrorArithmetic(
|
||||
"step value cannot be zero".to_string(),
|
||||
Position::NONE,
|
||||
)
|
||||
.into(),
|
||||
ERR::ErrorArithmetic("step value cannot be zero".to_string(), Position::NONE)
|
||||
.into(),
|
||||
Position::NONE,
|
||||
)
|
||||
.into());
|
||||
@ -128,7 +125,7 @@ pub struct BitRange(INT, usize);
|
||||
impl BitRange {
|
||||
pub fn new(value: INT, from: INT, len: INT) -> RhaiResultOf<Self> {
|
||||
let from = calc_index(INT_BITS, from, true, || {
|
||||
crate::ERR::ErrorBitFieldBounds(INT_BITS, from, Position::NONE).into()
|
||||
ERR::ErrorBitFieldBounds(INT_BITS, from, Position::NONE).into()
|
||||
})?;
|
||||
|
||||
let len = if len < 0 {
|
||||
|
@ -159,8 +159,6 @@ mod int_functions {
|
||||
#[cfg(not(feature = "no_float"))]
|
||||
#[export_module]
|
||||
mod trig_functions {
|
||||
use crate::FLOAT;
|
||||
|
||||
/// Return the sine of the floating-point number in radians.
|
||||
pub fn sin(x: FLOAT) -> FLOAT {
|
||||
x.sin()
|
||||
@ -223,8 +221,6 @@ mod trig_functions {
|
||||
#[cfg(not(feature = "no_float"))]
|
||||
#[export_module]
|
||||
mod float_functions {
|
||||
use crate::FLOAT;
|
||||
|
||||
/// Return the natural number _e_.
|
||||
#[rhai_fn(name = "E")]
|
||||
pub fn e() -> FLOAT {
|
||||
|
@ -1,6 +1,6 @@
|
||||
use crate::module::ModuleFlags;
|
||||
use crate::plugin::*;
|
||||
use crate::{def_package, FnPtr, SmartString, INT};
|
||||
use crate::{def_package, FnPtr, ImmutableString, SmartString, INT};
|
||||
use std::any::TypeId;
|
||||
use std::fmt::{Binary, LowerHex, Octal, Write};
|
||||
#[cfg(feature = "no_std")]
|
||||
@ -26,7 +26,7 @@ def_package! {
|
||||
// Register characters iterator
|
||||
#[cfg(not(feature = "no_index"))]
|
||||
lib.set_iter(TypeId::of::<ImmutableString>(), |value| Box::new(
|
||||
value.cast::<ImmutableString>().chars().map(Into::into).collect::<crate::Array>().into_iter()
|
||||
value.cast::<ImmutableString>().chars().map(Into::into).collect::<Array>().into_iter()
|
||||
));
|
||||
}
|
||||
}
|
||||
@ -38,7 +38,7 @@ pub fn print_with_func(
|
||||
fn_name: &str,
|
||||
ctx: &NativeCallContext,
|
||||
value: &mut Dynamic,
|
||||
) -> crate::ImmutableString {
|
||||
) -> ImmutableString {
|
||||
match ctx.call_native_fn_raw(fn_name, true, &mut [value]) {
|
||||
Ok(result) if result.is_string() => {
|
||||
result.into_immutable_string().expect("`ImmutableString`")
|
||||
@ -50,8 +50,6 @@ pub fn print_with_func(
|
||||
|
||||
#[export_module]
|
||||
mod print_debug_functions {
|
||||
use crate::ImmutableString;
|
||||
|
||||
/// Convert the value of the `item` into a string.
|
||||
#[rhai_fn(name = "print", pure)]
|
||||
pub fn print_generic(ctx: NativeCallContext, item: &mut Dynamic) -> ImmutableString {
|
||||
|
@ -1,8 +1,8 @@
|
||||
use crate::module::ModuleFlags;
|
||||
use crate::plugin::*;
|
||||
use crate::{
|
||||
def_package, Dynamic, ExclusiveRange, InclusiveRange, RhaiResultOf, StaticVec, INT,
|
||||
MAX_USIZE_INT,
|
||||
def_package, Dynamic, ExclusiveRange, ImmutableString, InclusiveRange, RhaiResultOf,
|
||||
SmartString, StaticVec, INT, MAX_USIZE_INT, ERR, Position
|
||||
};
|
||||
#[cfg(feature = "no_std")]
|
||||
use std::prelude::v1::*;
|
||||
@ -21,8 +21,6 @@ def_package! {
|
||||
|
||||
#[export_module]
|
||||
mod string_functions {
|
||||
use crate::{ImmutableString, SmartString};
|
||||
|
||||
#[rhai_fn(name = "+", pure)]
|
||||
pub fn add_append(
|
||||
ctx: NativeCallContext,
|
||||
@ -135,7 +133,7 @@ mod string_functions {
|
||||
}
|
||||
#[rhai_fn(name = "+=", name = "append")]
|
||||
pub fn add(string: &mut ImmutableString, utf8: Blob) {
|
||||
let mut s = crate::SmartString::from(string.as_str());
|
||||
let mut s = SmartString::from(string.as_str());
|
||||
if !utf8.is_empty() {
|
||||
s.push_str(&String::from_utf8_lossy(&utf8));
|
||||
*string = s.into();
|
||||
@ -155,6 +153,25 @@ mod string_functions {
|
||||
|
||||
s.into()
|
||||
}
|
||||
|
||||
/// Convert the string into an UTF-8 encoded byte-stream as a BLOB.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rhai
|
||||
/// let text = "朝には紅顔ありて夕べには白骨となる";
|
||||
///
|
||||
/// let bytes = text.to_blob();
|
||||
///
|
||||
/// print(bytes.len()); // prints 51
|
||||
/// ```
|
||||
pub fn to_blob(string: &str) -> Blob {
|
||||
if string.is_empty() {
|
||||
Blob::new()
|
||||
} else {
|
||||
string.as_bytes().into()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the length of the string, in number of characters.
|
||||
@ -196,25 +213,6 @@ mod string_functions {
|
||||
string.len() as INT
|
||||
}
|
||||
}
|
||||
/// Convert the string into an UTF-8 encoded byte-stream as a BLOB.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rhai
|
||||
/// let text = "朝には紅顔ありて夕べには白骨となる";
|
||||
///
|
||||
/// let bytes = text.to_blob();
|
||||
///
|
||||
/// print(bytes.len()); // prints 51
|
||||
/// ```
|
||||
#[cfg(not(feature = "no_index"))]
|
||||
pub fn to_blob(string: &str) -> crate::Blob {
|
||||
if string.is_empty() {
|
||||
crate::Blob::new()
|
||||
} else {
|
||||
string.as_bytes().into()
|
||||
}
|
||||
}
|
||||
/// Remove all occurrences of a sub-string from the string.
|
||||
///
|
||||
/// # Example
|
||||
@ -1226,9 +1224,9 @@ mod string_functions {
|
||||
|
||||
// Check if string will be over max size limit
|
||||
if _ctx.engine().max_string_size() > 0 && len > _ctx.engine().max_string_size() {
|
||||
return Err(crate::ERR::ErrorDataTooLarge(
|
||||
return Err(ERR::ErrorDataTooLarge(
|
||||
"Length of string".to_string(),
|
||||
crate::Position::NONE,
|
||||
Position::NONE,
|
||||
)
|
||||
.into());
|
||||
}
|
||||
@ -1244,9 +1242,9 @@ mod string_functions {
|
||||
|
||||
if _ctx.engine().max_string_size() > 0 && string.len() > _ctx.engine().max_string_size()
|
||||
{
|
||||
return Err(crate::ERR::ErrorDataTooLarge(
|
||||
return Err(ERR::ErrorDataTooLarge(
|
||||
"Length of string".to_string(),
|
||||
crate::Position::NONE,
|
||||
Position::NONE,
|
||||
)
|
||||
.into());
|
||||
}
|
||||
@ -1286,9 +1284,9 @@ mod string_functions {
|
||||
|
||||
// Check if string will be over max size limit
|
||||
if _ctx.engine().max_string_size() > 0 && len > _ctx.engine().max_string_size() {
|
||||
return Err(crate::ERR::ErrorDataTooLarge(
|
||||
return Err(ERR::ErrorDataTooLarge(
|
||||
"Length of string".to_string(),
|
||||
crate::Position::NONE,
|
||||
Position::NONE,
|
||||
)
|
||||
.into());
|
||||
}
|
||||
@ -1311,9 +1309,9 @@ mod string_functions {
|
||||
|
||||
if _ctx.engine().max_string_size() > 0 && string.len() > _ctx.engine().max_string_size()
|
||||
{
|
||||
return Err(crate::ERR::ErrorDataTooLarge(
|
||||
return Err(ERR::ErrorDataTooLarge(
|
||||
"Length of string".to_string(),
|
||||
crate::Position::NONE,
|
||||
Position::NONE,
|
||||
)
|
||||
.into());
|
||||
}
|
||||
@ -1324,7 +1322,7 @@ mod string_functions {
|
||||
|
||||
#[cfg(not(feature = "no_index"))]
|
||||
pub mod arrays {
|
||||
use crate::{Array, ImmutableString};
|
||||
use crate::Array;
|
||||
|
||||
/// Split the string into two at the specified `index` position and return it both strings
|
||||
/// as an array.
|
||||
|
@ -1454,15 +1454,13 @@ impl Engine {
|
||||
#[cfg(feature = "no_closure")]
|
||||
let options = self.options | (settings.options & LangOptions::STRICT_VAR);
|
||||
|
||||
let mut flags = (settings.flags
|
||||
let flags = (settings.flags
|
||||
& !ParseSettingFlags::GLOBAL_LEVEL
|
||||
& ParseSettingFlags::BREAKABLE)
|
||||
| ParseSettingFlags::FN_SCOPE;
|
||||
|
||||
#[cfg(not(feature = "no_closure"))]
|
||||
{
|
||||
flags |= ParseSettingFlags::CLOSURE_SCOPE;
|
||||
}
|
||||
let flags = flags | ParseSettingFlags::CLOSURE_SCOPE;
|
||||
|
||||
let new_settings = ParseSettings {
|
||||
level: 0,
|
||||
@ -3728,7 +3726,7 @@ impl Engine {
|
||||
&self,
|
||||
input: &mut TokenStream,
|
||||
state: &mut ParseState,
|
||||
parent: &mut ParseState,
|
||||
_parent: &mut ParseState,
|
||||
lib: &mut FnLib,
|
||||
settings: ParseSettings,
|
||||
) -> ParseResult<(Expr, ScriptFnDef)> {
|
||||
@ -3822,7 +3820,7 @@ impl Engine {
|
||||
|
||||
#[cfg(not(feature = "no_closure"))]
|
||||
let expr =
|
||||
Self::make_curry_from_externals(state, parent, lib, expr, externals, settings.pos);
|
||||
Self::make_curry_from_externals(state, _parent, lib, expr, externals, settings.pos);
|
||||
|
||||
Ok((expr, script))
|
||||
}
|
||||
@ -3837,11 +3835,9 @@ impl Engine {
|
||||
) -> ParseResult<AST> {
|
||||
let mut functions = StraightHashMap::default();
|
||||
|
||||
let mut options = self.options & !LangOptions::STMT_EXPR & !LangOptions::LOOP_EXPR;
|
||||
let options = self.options & !LangOptions::STMT_EXPR & !LangOptions::LOOP_EXPR;
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
{
|
||||
options &= !LangOptions::ANON_FN;
|
||||
}
|
||||
let options = options & !LangOptions::ANON_FN;
|
||||
|
||||
let mut settings = ParseSettings {
|
||||
level: 0,
|
||||
|
Loading…
Reference in New Issue
Block a user