From 724ad0591634cfae375ec0f7857d54668bdbfec5 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Fri, 19 Feb 2021 15:50:48 +0800 Subject: [PATCH] Add wasm64 as potential target. --- Cargo.toml | 5 ++++- src/dynamic.rs | 6 +++--- src/engine.rs | 6 +++--- src/engine_api.rs | 14 +++++++------- src/module/resolvers/mod.rs | 4 ++-- src/packages/arithmetic.rs | 6 +++--- src/packages/array_basic.rs | 4 ++-- src/packages/logic.rs | 4 ++-- src/packages/math_basic.rs | 8 ++++---- src/packages/string_basic.rs | 6 +++--- src/packages/string_more.rs | 4 ++-- src/packages/time_basic.rs | 26 +++++++++++--------------- src/stdlib.rs | 2 +- 13 files changed, 47 insertions(+), 48 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0911adfb..c1bff9aa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -44,7 +44,7 @@ no_function = [ "no_closure" ] # no script-defined functions (meaning no closur no_closure = [] # no automatic sharing and capture of anonymous functions to external variables no_module = [] # no modules internals = [] # expose internal data structures -unicode-xid-ident = ["unicode-xid"] # allow Unicode Standard Annex #31 for identifiers. +unicode-xid-ident = [ "unicode-xid" ] # allow Unicode Standard Annex #31 for identifiers. metadata = [ "serde", "serde_json" ] # enables exporting functions metadata to JSON # compiling for no-std @@ -107,5 +107,8 @@ optional = true [target.'cfg(target_arch = "wasm32")'.dependencies] instant= { version = "0.1" } # WASM implementation of std::time::Instant +[target.'cfg(target_arch = "wasm64")'.dependencies] +instant= { version = "0.1" } # WASM implementation of std::time::Instant + [package.metadata.docs.rs] features = [ "metadata", "internals" ] diff --git a/src/dynamic.rs b/src/dynamic.rs index afd1e099..a220f86f 100644 --- a/src/dynamic.rs +++ b/src/dynamic.rs @@ -25,12 +25,12 @@ use crate::Array; use crate::Map; #[cfg(not(feature = "no_std"))] -#[cfg(not(target_arch = "wasm32"))] +#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))] use crate::stdlib::time::Instant; use fmt::Debug; #[cfg(not(feature = "no_std"))] -#[cfg(target_arch = "wasm32")] +#[cfg(any(target_arch = "wasm32", target_arch = "wasm64"))] use instant::Instant; mod private { @@ -807,7 +807,7 @@ impl Dynamic { /// [`Arc`][std::sync::Arc]`<`[`RwLock`][std::sync::RwLock]`<`[`Dynamic`]`>>` /// depending on the `sync` feature. /// - /// Not available under [`no_closure`]. + /// Not available under `no_closure`. /// /// Shared [`Dynamic`] values are relatively cheap to clone as they simply increment the /// reference counts. diff --git a/src/engine.rs b/src/engine.rs index 0b164d91..b5586849 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -807,7 +807,7 @@ pub fn is_anonymous_fn(fn_name: &str) -> bool { #[inline(always)] fn default_print(_s: &str) { #[cfg(not(feature = "no_std"))] - #[cfg(not(target_arch = "wasm32"))] + #[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))] println!("{}", _s); } @@ -815,7 +815,7 @@ fn default_print(_s: &str) { #[inline(always)] fn default_debug(_s: &str, _source: Option<&str>, _pos: Position) { #[cfg(not(feature = "no_std"))] - #[cfg(not(target_arch = "wasm32"))] + #[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))] if let Some(source) = _source { println!("{} @ {:?} | {}", source, _pos, _s); } else { @@ -863,7 +863,7 @@ impl Engine { #[cfg(not(feature = "no_module"))] #[cfg(not(feature = "no_std"))] - #[cfg(not(target_arch = "wasm32"))] + #[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))] module_resolver: Box::new(crate::module::resolvers::FileModuleResolver::new()), #[cfg(not(feature = "no_module"))] #[cfg(any(feature = "no_std", target_arch = "wasm32",))] diff --git a/src/engine_api.rs b/src/engine_api.rs index f45403a3..808a2eff 100644 --- a/src/engine_api.rs +++ b/src/engine_api.rs @@ -1028,7 +1028,7 @@ impl Engine { } /// Read the contents of a file into a string. #[cfg(not(feature = "no_std"))] - #[cfg(not(target_arch = "wasm32"))] + #[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))] #[inline] fn read_file(path: crate::stdlib::path::PathBuf) -> Result> { use crate::stdlib::io::Read; @@ -1074,7 +1074,7 @@ impl Engine { /// # } /// ``` #[cfg(not(feature = "no_std"))] - #[cfg(not(target_arch = "wasm32"))] + #[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))] #[inline(always)] pub fn compile_file( &self, @@ -1116,7 +1116,7 @@ impl Engine { /// # } /// ``` #[cfg(not(feature = "no_std"))] - #[cfg(not(target_arch = "wasm32"))] + #[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))] #[inline(always)] pub fn compile_file_with_scope( &self, @@ -1301,7 +1301,7 @@ impl Engine { /// # } /// ``` #[cfg(not(feature = "no_std"))] - #[cfg(not(target_arch = "wasm32"))] + #[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))] #[inline(always)] pub fn eval_file( &self, @@ -1331,7 +1331,7 @@ impl Engine { /// # } /// ``` #[cfg(not(feature = "no_std"))] - #[cfg(not(target_arch = "wasm32"))] + #[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))] #[inline(always)] pub fn eval_file_with_scope( &self, @@ -1543,7 +1543,7 @@ impl Engine { /// /// Not available under `no_std` or `WASM`. #[cfg(not(feature = "no_std"))] - #[cfg(not(target_arch = "wasm32"))] + #[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))] #[inline(always)] pub fn consume_file( &self, @@ -1556,7 +1556,7 @@ impl Engine { /// /// Not available under `no_std` or `WASM`. #[cfg(not(feature = "no_std"))] - #[cfg(not(target_arch = "wasm32"))] + #[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))] #[inline(always)] pub fn consume_file_with_scope( &self, diff --git a/src/module/resolvers/mod.rs b/src/module/resolvers/mod.rs index bd94e19e..84b3448f 100644 --- a/src/module/resolvers/mod.rs +++ b/src/module/resolvers/mod.rs @@ -9,11 +9,11 @@ mod collection; pub use collection::ModuleResolversCollection; #[cfg(not(feature = "no_std"))] -#[cfg(not(target_arch = "wasm32"))] +#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))] mod file; #[cfg(not(feature = "no_std"))] -#[cfg(not(target_arch = "wasm32"))] +#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))] pub use file::FileModuleResolver; mod stat; diff --git a/src/packages/arithmetic.rs b/src/packages/arithmetic.rs index 4d81eda6..817be5b5 100644 --- a/src/packages/arithmetic.rs +++ b/src/packages/arithmetic.rs @@ -184,7 +184,7 @@ def_package!(crate:ArithmeticPackage:"Basic arithmetic", lib, { reg_functions!(lib += arith_numbers; i8, u8, i16, u16, i32, u32, u64); reg_functions!(lib += signed_numbers; i8, i16, i32); - #[cfg(not(target_arch = "wasm32"))] + #[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))] { reg_functions!(lib += arith_num_128; i128, u128); reg_functions!(lib += signed_num_128; i128); @@ -211,7 +211,7 @@ gen_arithmetic_functions!(arith_numbers => i8, u8, i16, u16, i32, u32, u64); #[cfg(not(feature = "only_i32"))] #[cfg(not(feature = "only_i64"))] -#[cfg(not(target_arch = "wasm32"))] +#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))] gen_arithmetic_functions!(arith_num_128 => i128, u128); gen_signed_functions!(signed_basic => INT); @@ -222,7 +222,7 @@ gen_signed_functions!(signed_numbers => i8, i16, i32); #[cfg(not(feature = "only_i32"))] #[cfg(not(feature = "only_i64"))] -#[cfg(not(target_arch = "wasm32"))] +#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))] gen_signed_functions!(signed_num_128 => i128); #[cfg(not(feature = "no_float"))] diff --git a/src/packages/array_basic.rs b/src/packages/array_basic.rs index 95b61dcc..7bd92fdd 100644 --- a/src/packages/array_basic.rs +++ b/src/packages/array_basic.rs @@ -71,7 +71,7 @@ def_package!(crate:BasicArrayPackage:"Basic array utilities.", lib, { { reg_functions!(lib += numbers; i8, u8, i16, u16, i32, i64, u32, u64); - #[cfg(not(target_arch = "wasm32"))] + #[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))] reg_functions!(lib += num_128; i128, u128); } @@ -706,7 +706,7 @@ gen_array_functions!(numbers => i8, u8, i16, u16, i32, i64, u32, u64); #[cfg(not(feature = "only_i32"))] #[cfg(not(feature = "only_i64"))] -#[cfg(not(target_arch = "wasm32"))] +#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))] gen_array_functions!(num_128 => i128, u128); #[cfg(not(feature = "no_float"))] diff --git a/src/packages/logic.rs b/src/packages/logic.rs index 578234c8..19e7dd2d 100644 --- a/src/packages/logic.rs +++ b/src/packages/logic.rs @@ -62,7 +62,7 @@ def_package!(crate:LogicPackage:"Logical operators.", lib, { { reg_functions!(lib += numbers; i8, u8, i16, u16, i32, u32, u64); - #[cfg(not(target_arch = "wasm32"))] + #[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))] reg_functions!(lib += num_128; i128, u128); } @@ -98,7 +98,7 @@ gen_cmp_functions!(numbers => i8, u8, i16, u16, i32, u32, u64); #[cfg(not(feature = "only_i32"))] #[cfg(not(feature = "only_i64"))] -#[cfg(not(target_arch = "wasm32"))] +#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))] gen_cmp_functions!(num_128 => i128, u128); #[cfg(not(feature = "no_float"))] diff --git a/src/packages/math_basic.rs b/src/packages/math_basic.rs index 5b8bc8dd..9adb5725 100644 --- a/src/packages/math_basic.rs +++ b/src/packages/math_basic.rs @@ -73,7 +73,7 @@ def_package!(crate:BasicMathPackage:"Basic mathematic functions.", lib, { { reg_functions!(lib += numbers_to_int::to_int(i8, u8, i16, u16, i32, u32, i64, u64)); - #[cfg(not(target_arch = "wasm32"))] + #[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))] reg_functions!(lib += num_128_to_int::to_int(i128, u128)); } @@ -92,7 +92,7 @@ def_package!(crate:BasicMathPackage:"Basic mathematic functions.", lib, { { reg_functions!(lib += numbers_to_float::to_float(i8, u8, i16, u16, i32, u32, i64, u32)); - #[cfg(not(target_arch = "wasm32"))] + #[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))] reg_functions!(lib += num_128_to_float::to_float(i128, u128)); } } @@ -452,7 +452,7 @@ gen_conversion_as_functions!(numbers_to_float => to_float (i8, u8, i16, u16, i32 #[cfg(not(feature = "no_float"))] #[cfg(not(feature = "only_i32"))] #[cfg(not(feature = "only_i64"))] -#[cfg(not(target_arch = "wasm32"))] +#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))] gen_conversion_as_functions!(num_128_to_float => to_float (i128, u128) -> FLOAT); gen_conversion_as_functions!(basic_to_int => to_int (char) -> INT); @@ -463,7 +463,7 @@ gen_conversion_as_functions!(numbers_to_int => to_int (i8, u8, i16, u16, i32, u3 #[cfg(not(feature = "only_i32"))] #[cfg(not(feature = "only_i64"))] -#[cfg(not(target_arch = "wasm32"))] +#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))] gen_conversion_as_functions!(num_128_to_int => to_int (i128, u128) -> INT); #[cfg(feature = "decimal")] diff --git a/src/packages/string_basic.rs b/src/packages/string_basic.rs index 2f15e7b2..bbf5e0a1 100644 --- a/src/packages/string_basic.rs +++ b/src/packages/string_basic.rs @@ -62,7 +62,7 @@ def_package!(crate:BasicStringPackage:"Basic string utilities, including printin reg_print_functions!(lib += print_numbers; i8, u8, i16, u16, i32, u32, i64, u64); reg_debug_functions!(lib += debug_numbers; i8, u8, i16, u16, i32, u32, i64, u64); - #[cfg(not(target_arch = "wasm32"))] + #[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))] { reg_print_functions!(lib += print_num_128; i128, u128); reg_debug_functions!(lib += debug_num_128; i128, u128); @@ -128,12 +128,12 @@ gen_functions!(debug_numbers => to_debug(i8, u8, i16, u16, i32, u32, i64, u64)); #[cfg(not(feature = "only_i32"))] #[cfg(not(feature = "only_i64"))] -#[cfg(not(target_arch = "wasm32"))] +#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))] gen_functions!(print_num_128 => to_string(i128, u128)); #[cfg(not(feature = "only_i32"))] #[cfg(not(feature = "only_i64"))] -#[cfg(not(target_arch = "wasm32"))] +#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))] gen_functions!(debug_num_128 => to_debug(i128, u128)); #[cfg(not(feature = "no_float"))] diff --git a/src/packages/string_more.rs b/src/packages/string_more.rs index 1a50b32d..05428dc3 100644 --- a/src/packages/string_more.rs +++ b/src/packages/string_more.rs @@ -41,7 +41,7 @@ def_package!(crate:MoreStringPackage:"Additional string utilities, including str { reg_functions!(lib += numbers; i8, u8, i16, u16, i32, i64, u32, u64); - #[cfg(not(target_arch = "wasm32"))] + #[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))] reg_functions!(lib += num_128; i128, u128); } @@ -65,7 +65,7 @@ gen_concat_functions!(numbers => i8, u8, i16, u16, i32, i64, u32, u64); #[cfg(not(feature = "only_i32"))] #[cfg(not(feature = "only_i64"))] -#[cfg(not(target_arch = "wasm32"))] +#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))] gen_concat_functions!(num_128 => i128, u128); #[cfg(not(feature = "no_float"))] diff --git a/src/packages/time_basic.rs b/src/packages/time_basic.rs index bcd50f55..cfd49fb9 100644 --- a/src/packages/time_basic.rs +++ b/src/packages/time_basic.rs @@ -8,10 +8,10 @@ use crate::{def_package, Dynamic, EvalAltResult, INT}; #[cfg(not(feature = "no_float"))] use crate::FLOAT; -#[cfg(not(target_arch = "wasm32"))] +#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))] use crate::stdlib::time::{Duration, Instant}; -#[cfg(target_arch = "wasm32")] +#[cfg(any(target_arch = "wasm32", target_arch = "wasm64"))] use instant::{Duration, Instant}; def_package!(crate:BasicTimePackage:"Basic timing utilities.", lib, { @@ -28,12 +28,10 @@ mod time_functions { #[rhai_fn(name = "elapsed", get = "elapsed", return_raw)] pub fn elapsed(timestamp: &mut Instant) -> Result> { #[cfg(not(feature = "no_float"))] - { - if *timestamp > Instant::now() { - Err(make_arithmetic_err("Time-stamp is later than now")) - } else { - Ok((timestamp.elapsed().as_secs_f64() as FLOAT).into()) - } + if *timestamp > Instant::now() { + Err(make_arithmetic_err("Time-stamp is later than now")) + } else { + Ok((timestamp.elapsed().as_secs_f64() as FLOAT).into()) } #[cfg(feature = "no_float")] @@ -56,14 +54,12 @@ mod time_functions { #[rhai_fn(return_raw, name = "-")] pub fn time_diff(ts1: Instant, ts2: Instant) -> Result> { #[cfg(not(feature = "no_float"))] - { - Ok(if ts2 > ts1 { - -(ts2 - ts1).as_secs_f64() as FLOAT - } else { - (ts1 - ts2).as_secs_f64() as FLOAT - } - .into()) + return Ok(if ts2 > ts1 { + -(ts2 - ts1).as_secs_f64() as FLOAT + } else { + (ts1 - ts2).as_secs_f64() as FLOAT } + .into()); #[cfg(feature = "no_float")] if ts2 > ts1 { diff --git a/src/stdlib.rs b/src/stdlib.rs index 0c0e0438..d1aa2f43 100644 --- a/src/stdlib.rs +++ b/src/stdlib.rs @@ -8,7 +8,7 @@ mod inner { pin, prelude, ptr, result, slice, str, task, time, u16, u32, u64, u8, usize, }; - #[cfg(not(target_arch = "wasm32"))] + #[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))] pub use core::{i128, u128}; #[cfg(feature = "sync")]