From 8e21c4727b48d79ccc6ca531c9204bb4ec880b28 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Tue, 26 Jul 2022 22:38:40 +0800 Subject: [PATCH 1/2] Fix definitions API code styles and formatting. --- CHANGELOG.md | 11 +- examples/README.md | 24 +-- .../definitions/__builtin-operators__.d.rhai | 8 + .../.rhai/definitions/__builtin__.d.rhai | 101 ++++++++++++- .../.rhai/definitions/general_kenobi.d.rhai | 3 +- examples/definitions/main.rs | 25 ++-- src/api/definitions/builtin-operators.d.rhai | 8 + src/api/definitions/builtin.d.rhai | 101 ++++++++++++- src/api/definitions/mod.rs | 139 +++++++++--------- src/tokenizer.rs | 2 +- 10 files changed, 314 insertions(+), 108 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ebb3d60..c81c5682 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,10 +15,19 @@ Bug fixes New features ------------ -* A new feature, `no_custom_syntax`, is added to remove custom syntax support from Rhai for applications that do not require it (which should be most). +### New feature flag + +* A new feature flag, `no_custom_syntax`, is added to remove custom syntax support from Rhai for applications that do not require it (which should be most). + +### Module documentation + * Comment lines beginning with `//!` (requires the `metadata` feature) are now collected as the script file's _module documentation_. * `AST` and `Module` have methods to access and manipulate documentation. +### Output definition files + +* An API is added to automatically generate definition files from a fully-configured `Engine`, for use with the Rhai Language Server. + Enhancements ------------ diff --git a/examples/README.md b/examples/README.md index 033be2af..17c379fe 100644 --- a/examples/README.md +++ b/examples/README.md @@ -4,18 +4,18 @@ Sample Applications Standard Examples ----------------- -| Example | Description | -| --------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | -| [`arrays_and_structs`](arrays_and_structs.rs) | shows how to register a Rust type and using it with arrays | -| [`callback`](callback.rs) | shows how to store a Rhai closure and call it later within Rust | -| [`custom_types_and_methods`](custom_types_and_methods.rs) | shows how to register a Rust type and methods/getters/setters for it | -| [`hello`](hello.rs) | simple example that evaluates an expression and prints the result | -| [`reuse_scope`](reuse_scope.rs) | evaluates two pieces of code in separate runs, but using a common `Scope` | -| [`serde`](serde.rs) | example to serialize and deserialize Rust types with [`serde`](https://crates.io/crates/serde) (requires the `serde` feature) | -| [`simple_fn`](simple_fn.rs) | shows how to register a simple Rust function | -| [`strings`](strings.rs) | shows different ways to register Rust functions taking string arguments | -| [`threading`](threading.rs) | shows how to communicate with an `Engine` running in a separate thread via an MPSC channel | -| [`definitions`](./definitions) | shows how to generate definition files for manual inspection or for use with [Rhai LSP](https://github.com/rhaiscript/lsp), requires the `metadata` feature | +| Example | Description | +| --------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- | +| [`arrays_and_structs`](arrays_and_structs.rs) | shows how to register a Rust type and using it with arrays | +| [`callback`](callback.rs) | shows how to store a Rhai closure and call it later within Rust | +| [`custom_types_and_methods`](custom_types_and_methods.rs) | shows how to register a Rust type and methods/getters/setters for it | +| [`definitions`](./definitions) | shows how to generate definition files for use with the [Rhai Language Server](https://github.com/rhaiscript/lsp) (requires the `metadata` feature) | +| [`hello`](hello.rs) | simple example that evaluates an expression and prints the result | +| [`reuse_scope`](reuse_scope.rs) | evaluates two pieces of code in separate runs, but using a common `Scope` | +| [`serde`](serde.rs) | example to serialize and deserialize Rust types with [`serde`](https://crates.io/crates/serde) (requires the `serde` feature) | +| [`simple_fn`](simple_fn.rs) | shows how to register a simple Rust function | +| [`strings`](strings.rs) | shows different ways to register Rust functions taking string arguments | +| [`threading`](threading.rs) | shows how to communicate with an `Engine` running in a separate thread via an MPSC channel | Scriptable Event Handler With State Examples diff --git a/examples/definitions/.rhai/definitions/__builtin-operators__.d.rhai b/examples/definitions/.rhai/definitions/__builtin-operators__.d.rhai index 4a5bdfd6..b5ba3344 100644 --- a/examples/definitions/.rhai/definitions/__builtin-operators__.d.rhai +++ b/examples/definitions/.rhai/definitions/__builtin-operators__.d.rhai @@ -249,3 +249,11 @@ op +=(Blob, Blob); op +=(Blob, i64); op +=(Blob, char); op +=(Blob, String); + +op in(?, Array) -> bool; +op in(String, String) -> bool; +op in(char, String) -> bool; +op in(int, Range) -> bool; +op in(int, RangeInclusive) -> bool; +op in(String, Map) -> bool; +op in(int, Blob) -> bool; diff --git a/examples/definitions/.rhai/definitions/__builtin__.d.rhai b/examples/definitions/.rhai/definitions/__builtin__.d.rhai index 2e08fa44..881c1582 100644 --- a/examples/definitions/.rhai/definitions/__builtin__.d.rhai +++ b/examples/definitions/.rhai/definitions/__builtin__.d.rhai @@ -112,7 +112,7 @@ fn curry(fn_ptr: FnPtr, ...args: ?) -> FnPtr; /// print(is_def_fn("foo", 0)); // prints false /// print(is_def_fn("bar", 1)); // prints false /// ``` -fn is_def_fn(fn_name: String, num_params: i64) -> bool; +fn is_def_fn(fn_name: String, num_params: int) -> bool; /// Return `true` if a variable matching a specified name is defined. /// @@ -162,9 +162,100 @@ fn is_shared(variable: ?) -> bool; /// ``` fn eval(script: String) -> ?; +/// Return `true` if the string contains another string. +/// +/// This function also drives the `in` operator. +/// +/// # Example +/// +/// ```rhai +/// let x = "hello world!"; +/// +/// // The 'in' operator calls 'contains' in the background +/// if "world" in x { +/// print("found!"); +/// } +/// ``` fn contains(string: String, find: String) -> bool; -fn contains(range: Range, value: i64) -> bool; -fn contains(range: RangeInclusive, value: i64) -> bool; -fn contains(map: Map, string: String) -> bool; -fn contains(blob: Blob, value: i64) -> bool; + +/// Return `true` if the string contains a character. +/// +/// This function also drives the `in` operator. +/// +/// # Example +/// +/// ```rhai +/// let x = "hello world!"; +/// +/// // The 'in' operator calls 'contains' in the background +/// if 'w' in x { +/// print("found!"); +/// } +/// ``` fn contains(string: String, ch: char) -> bool; + +/// Return `true` if a value falls within the exclusive range. +/// +/// This function also drives the `in` operator. +/// +/// # Example +/// +/// ```rhai +/// let r = 1..100; +/// +/// // The 'in' operator calls 'contains' in the background +/// if 42 in r { +/// print("found!"); +/// } +/// ``` +fn contains(range: Range, value: int) -> bool; + +/// Return `true` if a value falls within the inclusive range. +/// +/// This function also drives the `in` operator. +/// +/// # Example +/// +/// ```rhai +/// let r = 1..=100; +/// +/// // The 'in' operator calls 'contains' in the background +/// if 42 in r { +/// print("found!"); +/// } +/// ``` +fn contains(range: RangeInclusive, value: int) -> bool; + +/// Return `true` if a key exists within the object map. +/// +/// This function also drives the `in` operator. +/// +/// # Example +/// +/// ```rhai +/// let m = #{a:1, b:2, c:3}; +/// +/// // The 'in' operator calls 'contains' in the background +/// if "c" in m { +/// print("found!"); +/// } +/// ``` +fn contains(map: Map, string: String) -> bool; + +/// Return `true` if a value is found within the BLOB. +/// +/// This function also drives the `in` operator. +/// +/// # Example +/// +/// ```rhai +/// let b = blob(); +/// +/// b += 1; b += 2; b += 3; b += 4; b += 5; +/// +/// // The 'in' operator calls 'contains' in the background +/// if 3 in b { +/// print("found!"); +/// } +/// ``` +fn contains(blob: Blob, value: int) -> bool; diff --git a/examples/definitions/.rhai/definitions/general_kenobi.d.rhai b/examples/definitions/.rhai/definitions/general_kenobi.d.rhai index c6485585..dfa07701 100644 --- a/examples/definitions/.rhai/definitions/general_kenobi.d.rhai +++ b/examples/definitions/.rhai/definitions/general_kenobi.d.rhai @@ -1,5 +1,4 @@ module general_kenobi; -/// Returns a string where `hello there ` -/// is repeated `n` times. +/// Returns a string where "hello there" is repeated `n` times. fn hello_there(n: i64) -> String; \ No newline at end of file diff --git a/examples/definitions/main.rs b/examples/definitions/main.rs index f83ac4fd..96abc522 100644 --- a/examples/definitions/main.rs +++ b/examples/definitions/main.rs @@ -1,21 +1,20 @@ -use rhai::{plugin::*, Engine, Scope}; +use rhai::plugin::*; +use rhai::{Engine, EvalAltResult, Scope}; #[export_module] pub mod general_kenobi { - /// Returns a string where `hello there ` - /// is repeated `n` times. + /// Returns a string where "hello there" is repeated `n` times. pub fn hello_there(n: i64) -> String { use std::convert::TryInto; "hello there ".repeat(n.try_into().unwrap()) } } -fn main() { +fn main() -> Result<(), Box> { let mut engine = Engine::new(); let mut scope = Scope::new(); - // This variable will also show up in the definitions, - // since it will be part of the scope. + // This variable will also show up in the definitions, since it will be part of the scope. scope.push("hello_there", "hello there"); #[cfg(not(feature = "no_module"))] @@ -28,17 +27,15 @@ fn main() { engine.register_fn("minus", |a: i64, b: i64| a - b); } - engine - .eval_with_scope::<()>( - &mut scope, - r#" -hello_there = general_kenobi::hello_there(4 minus 2); -"#, - ) - .unwrap(); + engine.run_with_scope( + &mut scope, + "hello_there = general_kenobi::hello_there(4 minus 2);", + )?; engine .definitions_with_scope(&scope) .write_to_dir("examples/definitions/.rhai/definitions") .unwrap(); + + Ok(()) } diff --git a/src/api/definitions/builtin-operators.d.rhai b/src/api/definitions/builtin-operators.d.rhai index 4a5bdfd6..b5ba3344 100644 --- a/src/api/definitions/builtin-operators.d.rhai +++ b/src/api/definitions/builtin-operators.d.rhai @@ -249,3 +249,11 @@ op +=(Blob, Blob); op +=(Blob, i64); op +=(Blob, char); op +=(Blob, String); + +op in(?, Array) -> bool; +op in(String, String) -> bool; +op in(char, String) -> bool; +op in(int, Range) -> bool; +op in(int, RangeInclusive) -> bool; +op in(String, Map) -> bool; +op in(int, Blob) -> bool; diff --git a/src/api/definitions/builtin.d.rhai b/src/api/definitions/builtin.d.rhai index 2e08fa44..881c1582 100644 --- a/src/api/definitions/builtin.d.rhai +++ b/src/api/definitions/builtin.d.rhai @@ -112,7 +112,7 @@ fn curry(fn_ptr: FnPtr, ...args: ?) -> FnPtr; /// print(is_def_fn("foo", 0)); // prints false /// print(is_def_fn("bar", 1)); // prints false /// ``` -fn is_def_fn(fn_name: String, num_params: i64) -> bool; +fn is_def_fn(fn_name: String, num_params: int) -> bool; /// Return `true` if a variable matching a specified name is defined. /// @@ -162,9 +162,100 @@ fn is_shared(variable: ?) -> bool; /// ``` fn eval(script: String) -> ?; +/// Return `true` if the string contains another string. +/// +/// This function also drives the `in` operator. +/// +/// # Example +/// +/// ```rhai +/// let x = "hello world!"; +/// +/// // The 'in' operator calls 'contains' in the background +/// if "world" in x { +/// print("found!"); +/// } +/// ``` fn contains(string: String, find: String) -> bool; -fn contains(range: Range, value: i64) -> bool; -fn contains(range: RangeInclusive, value: i64) -> bool; -fn contains(map: Map, string: String) -> bool; -fn contains(blob: Blob, value: i64) -> bool; + +/// Return `true` if the string contains a character. +/// +/// This function also drives the `in` operator. +/// +/// # Example +/// +/// ```rhai +/// let x = "hello world!"; +/// +/// // The 'in' operator calls 'contains' in the background +/// if 'w' in x { +/// print("found!"); +/// } +/// ``` fn contains(string: String, ch: char) -> bool; + +/// Return `true` if a value falls within the exclusive range. +/// +/// This function also drives the `in` operator. +/// +/// # Example +/// +/// ```rhai +/// let r = 1..100; +/// +/// // The 'in' operator calls 'contains' in the background +/// if 42 in r { +/// print("found!"); +/// } +/// ``` +fn contains(range: Range, value: int) -> bool; + +/// Return `true` if a value falls within the inclusive range. +/// +/// This function also drives the `in` operator. +/// +/// # Example +/// +/// ```rhai +/// let r = 1..=100; +/// +/// // The 'in' operator calls 'contains' in the background +/// if 42 in r { +/// print("found!"); +/// } +/// ``` +fn contains(range: RangeInclusive, value: int) -> bool; + +/// Return `true` if a key exists within the object map. +/// +/// This function also drives the `in` operator. +/// +/// # Example +/// +/// ```rhai +/// let m = #{a:1, b:2, c:3}; +/// +/// // The 'in' operator calls 'contains' in the background +/// if "c" in m { +/// print("found!"); +/// } +/// ``` +fn contains(map: Map, string: String) -> bool; + +/// Return `true` if a value is found within the BLOB. +/// +/// This function also drives the `in` operator. +/// +/// # Example +/// +/// ```rhai +/// let b = blob(); +/// +/// b += 1; b += 2; b += 3; b += 4; b += 5; +/// +/// // The 'in' operator calls 'contains' in the background +/// if 3 in b { +/// print("found!"); +/// } +/// ``` +fn contains(blob: Blob, value: int) -> bool; diff --git a/src/api/definitions/mod.rs b/src/api/definitions/mod.rs index 53ffe6f3..7d195243 100644 --- a/src/api/definitions/mod.rs +++ b/src/api/definitions/mod.rs @@ -1,21 +1,18 @@ -use crate::{ - module::FuncInfo, plugin::*, tokenizer::is_valid_function_name, Engine, Module, Scope, -}; -use core::{cmp::Ordering, fmt, iter}; +//! Module that defines functions to output definition files for [`Engine`]. +#![cfg(feature = "metadata")] + +use crate::module::FuncInfo; +use crate::plugin::*; +use crate::tokenizer::is_valid_function_name; +use crate::{Engine, Module, Scope}; #[cfg(feature = "no_std")] use std::prelude::v1::*; - -#[cfg(feature = "no_std")] -use alloc::borrow::Cow; - -#[cfg(not(feature = "no_std"))] -use std::borrow::Cow; +use std::{borrow::Cow, cmp::Ordering, fmt}; impl Engine { - /// Return [`Definitions`] that can be used to - /// generate definition files that contain all - /// the visible items in the engine. + /// Return [`Definitions`] that can be used to generate definition files for the [`Engine`]. + /// Exported under the `metadata` feature only. /// /// # Example /// @@ -23,12 +20,15 @@ impl Engine { /// # use rhai::Engine; /// # fn main() -> std::io::Result<()> { /// let engine = Engine::new(); + /// /// engine /// .definitions() /// .write_to_dir(".rhai/definitions")?; /// # Ok(()) /// # } /// ``` + #[inline(always)] + #[must_use] pub fn definitions(&self) -> Definitions { Definitions { engine: self, @@ -36,10 +36,9 @@ impl Engine { } } - /// Return [`Definitions`] that can be used to - /// generate definition files that contain all - /// the visible items in the engine and the - /// given scope. + /// Return [`Definitions`] that can be used to generate definition files for the [`Engine`] and + /// the given [`Scope`]. + /// Exported under the `metadata` feature only. /// /// # Example /// @@ -54,6 +53,8 @@ impl Engine { /// # Ok(()) /// # } /// ``` + #[inline(always)] + #[must_use] pub fn definitions_with_scope<'e>(&'e self, scope: &'e Scope<'e>) -> Definitions<'e> { Definitions { engine: self, @@ -62,19 +63,20 @@ impl Engine { } } -/// Definitions helper that is used to generate -/// definition files based on the contents of an [`Engine`]. +/// Definitions helper type to generate definition files based on the contents of an [`Engine`]. #[must_use] pub struct Definitions<'e> { + /// The [`Engine`]. engine: &'e Engine, + /// Optional [`Scope`] to include. scope: Option<&'e Scope<'e>>, } impl<'e> Definitions<'e> { - /// Write all the definition files returned from [`iter_files`] to a directory. + /// Output all definition files returned from [`iter_files`][Definitions::iter_files] to a + /// specified directory. /// - /// This function will create the directory path if it does not yet exist, - /// it will also override any existing files as needed. + /// This function creates the directory if it does not exist, and overrides any existing files. #[cfg(all(not(feature = "no_std"), not(target_family = "wasm")))] pub fn write_to_dir(&self, path: impl AsRef) -> std::io::Result<()> { use std::fs; @@ -98,6 +100,7 @@ impl<'e> Definitions<'e> { fs::write(path.join("__scope__.d.rhai"), self.scope())?; } + #[cfg(not(feature = "no_module"))] for (name, decl) in self.modules() { fs::write(path.join(format!("{name}.d.rhai")), decl)?; } @@ -105,9 +108,11 @@ impl<'e> Definitions<'e> { Ok(()) } - /// Iterate over the generated definition files. + /// Iterate over generated definition files. /// - /// The returned iterator yields all the definition files as (filename, content) pairs. + /// The returned iterator yields all definition files as (filename, content) pairs. + #[inline] + #[must_use] pub fn iter_files(&self) -> impl Iterator + '_ { IntoIterator::into_iter([ ( @@ -120,23 +125,27 @@ impl<'e> Definitions<'e> { ), ("__static__.d.rhai".to_string(), self.static_module()), ]) - .chain(iter::from_fn(move || { - if self.scope.is_some() { - Some(("__scope__.d.rhai".to_string(), self.scope())) - } else { - None - } - })) .chain( - self.modules() - .map(|(name, def)| (format!("{name}.d.rhai"), def)), + self.scope + .iter() + .map(move |_| ("__scope__.d.rhai".to_string(), self.scope())), + ) + .chain( + #[cfg(not(feature = "no_module"))] + { + self.modules() + .map(|(name, def)| (format!("{name}.d.rhai"), def)) + }, + #[cfg(feature = "no_module")] + { + std::iter::empty() + }, ) } - /// Return the definitions for the globally available - /// items of the engine. + /// Return definitions for all globally available functions. /// - /// The definitions will always start with `module static;`. + /// Always starts with `module static;`. #[must_use] pub fn static_module(&self) -> String { let mut s = String::from("module static;\n\n"); @@ -153,11 +162,9 @@ impl<'e> Definitions<'e> { s } - /// Return the definitions for the available - /// items of the scope. + /// Return definitions for all items inside the [`Scope`], if any. /// - /// The definitions will always start with `module static;`, - /// even if the scope is empty or none was provided. + /// Always starts with `module static;` even if the [`Scope`] is empty or none was provided. #[must_use] pub fn scope(&self) -> String { let mut s = String::from("module static;\n\n"); @@ -169,44 +176,41 @@ impl<'e> Definitions<'e> { s } - /// Return module name and definition pairs for each registered module. + /// Return a (module name, definitions) pair for each registered static [module][Module]. /// - /// The definitions will always start with `module ;`. + /// Not available under `no_module`. /// - /// If the feature `no_module` is enabled, this will yield no elements. + /// Always starts with `module ;`. + #[cfg(not(feature = "no_module"))] + #[must_use] pub fn modules(&self) -> impl Iterator + '_ { - #[cfg(not(feature = "no_module"))] - let m = { - let mut m = self - .engine - .global_sub_modules - .iter() - .map(move |(name, module)| { - ( - name.to_string(), - format!("module {name};\n\n{}", module.definition(self)), - ) - }) - .collect::>(); + let mut m = self + .engine + .global_sub_modules + .iter() + .map(move |(name, module)| { + ( + name.to_string(), + format!("module {name};\n\n{}", module.definition(self)), + ) + }) + .collect::>(); - m.sort_by(|(name1, _), (name2, _)| name1.cmp(name2)); - m - }; - - #[cfg(feature = "no_module")] - let m = Vec::new(); + m.sort_by(|(name1, _), (name2, _)| name1.cmp(name2)); m.into_iter() } } impl Module { + /// Return definitions for all items inside the [`Module`]. fn definition(&self, def: &Definitions) -> String { let mut s = String::new(); self.write_definition(&mut s, def).unwrap(); s } + /// Output definitions for all items inside the [`Module`]. fn write_definition(&self, writer: &mut dyn fmt::Write, def: &Definitions) -> fmt::Result { let mut first = true; @@ -259,6 +263,7 @@ impl Module { } impl FuncInfo { + /// Output definitions for a function. fn write_definition( &self, writer: &mut dyn fmt::Write, @@ -324,14 +329,11 @@ impl FuncInfo { /// We have to transform some of the types. /// -/// This is highly inefficient and is currently based on -/// trial and error with the core packages. +/// This is highly inefficient and is currently based on trial and error with the core packages. /// -/// It tries to flatten types, removing `&` and `&mut`, -/// and paths, while keeping generics. +/// It tries to flatten types, removing `&` and `&mut`, and paths, while keeping generics. /// -/// Associated generic types are also rewritten into regular -/// generic type parameters. +/// Associated generic types are also rewritten into regular generic type parameters. fn def_type_name<'a>(ty: &'a str, engine: &'a Engine) -> Cow<'a, str> { let ty = engine.format_type_name(ty).replace("crate::", ""); let ty = ty.strip_prefix("&mut").unwrap_or(&*ty).trim(); @@ -353,6 +355,7 @@ fn def_type_name<'a>(ty: &'a str, engine: &'a Engine) -> Cow<'a, str> { } impl Scope<'_> { + /// Return definitions for all items inside the [`Scope`]. fn write_definition(&self, writer: &mut dyn fmt::Write) -> fmt::Result { let mut first = true; for (name, constant, _) in self.iter_raw() { diff --git a/src/tokenizer.rs b/src/tokenizer.rs index 5cccd741..682e4285 100644 --- a/src/tokenizer.rs +++ b/src/tokenizer.rs @@ -568,7 +568,7 @@ pub enum Token { Reserved(SmartString), /// A custom keyword. /// - /// Not available under the `no_custom_syntax` feature. + /// Not available under `no_custom_syntax`. #[cfg(not(feature = "no_custom_syntax"))] Custom(SmartString), /// End of the input stream. From d42c6b69a3b301d85bb30fb44c00beddc60a6913 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Tue, 26 Jul 2022 22:55:24 +0800 Subject: [PATCH 2/2] Map i64 and f64 to int and float in definitions file. --- .../definitions/__builtin-operators__.d.rhai | 234 ++++++------ .../.rhai/definitions/__static__.d.rhai | 338 +++++++++--------- .../.rhai/definitions/general_kenobi.d.rhai | 2 +- src/api/definitions/builtin-operators.d.rhai | 234 ++++++------ src/api/definitions/mod.rs | 16 +- 5 files changed, 415 insertions(+), 409 deletions(-) diff --git a/examples/definitions/.rhai/definitions/__builtin-operators__.d.rhai b/examples/definitions/.rhai/definitions/__builtin-operators__.d.rhai index b5ba3344..012a95a4 100644 --- a/examples/definitions/.rhai/definitions/__builtin-operators__.d.rhai +++ b/examples/definitions/.rhai/definitions/__builtin-operators__.d.rhai @@ -1,16 +1,16 @@ module static; -op ==(i64, i64) -> bool; -op !=(i64, i64) -> bool; -op >(i64, i64) -> bool; -op >=(i64, i64) -> bool; -op <(i64, i64) -> bool; -op <=(i64, i64) -> bool; -op &(i64, i64) -> i64; -op |(i64, i64) -> i64; -op ^(i64, i64) -> i64; -op ..(i64, i64) -> Range; -op ..=(i64, i64) -> RangeInclusive; +op ==(int, int) -> bool; +op !=(int, int) -> bool; +op >(int, int) -> bool; +op >=(int, int) -> bool; +op <(int, int) -> bool; +op <=(int, int) -> bool; +op &(int, int) -> int; +op |(int, int) -> int; +op ^(int, int) -> int; +op ..(int, int) -> Range; +op ..=(int, int) -> RangeInclusive; op ==(bool, bool) -> bool; op !=(bool, bool) -> bool; @@ -29,53 +29,53 @@ op >=((), ()) -> bool; op <((), ()) -> bool; op <=((), ()) -> bool; -op +(i64, i64) -> i64; -op -(i64, i64) -> i64; -op *(i64, i64) -> i64; -op /(i64, i64) -> i64; -op %(i64, i64) -> i64; -op **(i64, i64) -> i64; -op >>(i64, i64) -> i64; -op <<(i64, i64) -> i64; +op +(int, int) -> int; +op -(int, int) -> int; +op *(int, int) -> int; +op /(int, int) -> int; +op %(int, int) -> int; +op **(int, int) -> int; +op >>(int, int) -> int; +op <<(int, int) -> int; -op +(f64, f64) -> f64; -op -(f64, f64) -> f64; -op *(f64, f64) -> f64; -op /(f64, f64) -> f64; -op %(f64, f64) -> f64; -op **(f64, f64) -> f64; -op ==(f64, f64) -> bool; -op !=(f64, f64) -> bool; -op >(f64, f64) -> bool; -op >=(f64, f64) -> bool; -op <(f64, f64) -> bool; -op <=(f64, f64) -> bool; +op +(float, float) -> float; +op -(float, float) -> float; +op *(float, float) -> float; +op /(float, float) -> float; +op %(float, float) -> float; +op **(float, float) -> float; +op ==(float, float) -> bool; +op !=(float, float) -> bool; +op >(float, float) -> bool; +op >=(float, float) -> bool; +op <(float, float) -> bool; +op <=(float, float) -> bool; -op +(f64, i64) -> f64; -op -(f64, i64) -> f64; -op *(f64, i64) -> f64; -op /(f64, i64) -> f64; -op %(f64, i64) -> f64; -op **(f64, i64) -> f64; -op ==(f64, i64) -> bool; -op !=(f64, i64) -> bool; -op >(f64, i64) -> bool; -op >=(f64, i64) -> bool; -op <(f64, i64) -> bool; -op <=(f64, i64) -> bool; +op +(float, int) -> float; +op -(float, int) -> float; +op *(float, int) -> float; +op /(float, int) -> float; +op %(float, int) -> float; +op **(float, int) -> float; +op ==(float, int) -> bool; +op !=(float, int) -> bool; +op >(float, int) -> bool; +op >=(float, int) -> bool; +op <(float, int) -> bool; +op <=(float, int) -> bool; -op +(i64, f64) -> f64; -op -(i64, f64) -> f64; -op *(i64, f64) -> f64; -op /(i64, f64) -> f64; -op %(i64, f64) -> f64; -op **(i64, f64) -> f64; -op ==(i64, f64) -> bool; -op !=(i64, f64) -> bool; -op >(i64, f64) -> bool; -op >=(i64, f64) -> bool; -op <(i64, f64) -> bool; -op <=(i64, f64) -> bool; +op +(int, float) -> float; +op -(int, float) -> float; +op *(int, float) -> float; +op /(int, float) -> float; +op %(int, float) -> float; +op **(int, float) -> float; +op ==(int, float) -> bool; +op !=(int, float) -> bool; +op >(int, float) -> bool; +op >=(int, float) -> bool; +op <(int, float) -> bool; +op <=(int, float) -> bool; op +(Decimal, Decimal) -> Decimal; op -(Decimal, Decimal) -> Decimal; @@ -90,31 +90,31 @@ op >=(Decimal, Decimal) -> bool; op <(Decimal, Decimal) -> bool; op <=(Decimal, Decimal) -> bool; -op +(Decimal, i64) -> Decimal; -op -(Decimal, i64) -> Decimal; -op *(Decimal, i64) -> Decimal; -op /(Decimal, i64) -> Decimal; -op %(Decimal, i64) -> Decimal; -op **(Decimal, i64) -> Decimal; -op ==(Decimal, i64) -> bool; -op !=(Decimal, i64) -> bool; -op >(Decimal, i64) -> bool; -op >=(Decimal, i64) -> bool; -op <(Decimal, i64) -> bool; -op <=(Decimal, i64) -> bool; +op +(Decimal, int) -> Decimal; +op -(Decimal, int) -> Decimal; +op *(Decimal, int) -> Decimal; +op /(Decimal, int) -> Decimal; +op %(Decimal, int) -> Decimal; +op **(Decimal, int) -> Decimal; +op ==(Decimal, int) -> bool; +op !=(Decimal, int) -> bool; +op >(Decimal, int) -> bool; +op >=(Decimal, int) -> bool; +op <(Decimal, int) -> bool; +op <=(Decimal, int) -> bool; -op +(i64, Decimal) -> Decimal; -op -(i64, Decimal) -> Decimal; -op *(i64, Decimal) -> Decimal; -op /(i64, Decimal) -> Decimal; -op %(i64, Decimal) -> Decimal; -op **(i64, Decimal) -> Decimal; -op ==(i64, Decimal) -> bool; -op !=(i64, Decimal) -> bool; -op >(i64, Decimal) -> bool; -op >=(i64, Decimal) -> bool; -op <(i64, Decimal) -> bool; -op <=(i64, Decimal) -> bool; +op +(int, Decimal) -> Decimal; +op -(int, Decimal) -> Decimal; +op *(int, Decimal) -> Decimal; +op /(int, Decimal) -> Decimal; +op %(int, Decimal) -> Decimal; +op **(int, Decimal) -> Decimal; +op ==(int, Decimal) -> bool; +op !=(int, Decimal) -> bool; +op >(int, Decimal) -> bool; +op >=(int, Decimal) -> bool; +op <(int, Decimal) -> bool; +op <=(int, Decimal) -> bool; op +(String, String) -> String; op -(String, String) -> String; @@ -172,17 +172,17 @@ op ==(Blob, Blob) -> bool; op !=(Blob, Blob) -> bool; -op ==(Range, RangeInclusive) -> bool; -op !=(Range, RangeInclusive) -> bool; +op ==(Range, RangeInclusive) -> bool; +op !=(Range, RangeInclusive) -> bool; -op ==(RangeInclusive, Range) -> bool; -op !=(RangeInclusive, Range) -> bool; +op ==(RangeInclusive, Range) -> bool; +op !=(RangeInclusive, Range) -> bool; -op ==(Range, Range) -> bool; -op !=(Range, Range) -> bool; +op ==(Range, Range) -> bool; +op !=(Range, Range) -> bool; -op ==(RangeInclusive, RangeInclusive) -> bool; -op !=(RangeInclusive, RangeInclusive) -> bool; +op ==(RangeInclusive, RangeInclusive) -> bool; +op !=(RangeInclusive, RangeInclusive) -> bool; op ==(?, ?) -> bool; op !=(?, ?) -> bool; @@ -195,31 +195,31 @@ op <=(?, ?) -> bool; op &=(bool, bool); op |=(bool, bool); -op +=(i64, i64); -op -=(i64, i64); -op *=(i64, i64); -op /=(i64, i64); -op %=(i64, i64); -op **=(i64, i64); -op >>=(i64, i64); -op <<=(i64, i64); -op &=(i64, i64); -op |=(i64, i64); -op ^=(i64, i64); +op +=(int, int); +op -=(int, int); +op *=(int, int); +op /=(int, int); +op %=(int, int); +op **=(int, int); +op >>=(int, int); +op <<=(int, int); +op &=(int, int); +op |=(int, int); +op ^=(int, int); -op +=(f64, f64); -op -=(f64, f64); -op *=(f64, f64); -op /=(f64, f64); -op %=(f64, f64); -op **=(f64, f64); +op +=(float, float); +op -=(float, float); +op *=(float, float); +op /=(float, float); +op %=(float, float); +op **=(float, float); -op +=(f64, i64); -op -=(f64, i64); -op *=(f64, i64); -op /=(f64, i64); -op %=(f64, i64); -op **=(f64, i64); +op +=(float, int); +op -=(float, int); +op *=(float, int); +op /=(float, int); +op %=(float, int); +op **=(float, int); op +=(Decimal, Decimal); op -=(Decimal, Decimal); @@ -228,12 +228,12 @@ op /=(Decimal, Decimal); op %=(Decimal, Decimal); op **=(Decimal, Decimal); -op +=(Decimal, i64); -op -=(Decimal, i64); -op *=(Decimal, i64); -op /=(Decimal, i64); -op %=(Decimal, i64); -op **=(Decimal, i64); +op +=(Decimal, int); +op -=(Decimal, int); +op *=(Decimal, int); +op /=(Decimal, int); +op %=(Decimal, int); +op **=(Decimal, int); op +=(String, String); op -=(String, String); @@ -246,7 +246,7 @@ op +=(Array, Array); op +=(Array, ?); op +=(Blob, Blob); -op +=(Blob, i64); +op +=(Blob, int); op +=(Blob, char); op +=(Blob, String); diff --git a/examples/definitions/.rhai/definitions/__static__.d.rhai b/examples/definitions/.rhai/definitions/__static__.d.rhai index 80992faf..5e538b70 100644 --- a/examples/definitions/.rhai/definitions/__static__.d.rhai +++ b/examples/definitions/.rhai/definitions/__static__.d.rhai @@ -1,6 +1,6 @@ module static; -op minus(i64, i64) -> i64; +op minus(int, int) -> int; op !(bool) -> bool; @@ -45,13 +45,13 @@ op !=(Instant, Instant) -> bool; op !=(int, f32) -> bool; -op !=(int, f64) -> bool; +op !=(int, float) -> bool; op !=(f32, int) -> bool; op !=(f32, f32) -> bool; -op !=(f64, int) -> bool; +op !=(float, int) -> bool; op !=(i128, i128) -> bool; @@ -159,11 +159,11 @@ op **(u64, int) -> u64; op **(u8, int) -> u8; -op +(int) -> i64; +op +(int) -> int; op +(f32) -> f32; -op +(f64) -> f64; +op +(float) -> float; op +(i128) -> i128; @@ -279,7 +279,7 @@ op -(int) -> int; op -(f32) -> f32; -op -(f64) -> f64; +op -(float) -> float; op -(i128) -> i128; @@ -357,13 +357,13 @@ op <(Instant, Instant) -> bool; op <(int, f32) -> bool; -op <(int, f64) -> bool; +op <(int, float) -> bool; op <(f32, int) -> bool; op <(f32, f32) -> bool; -op <(f64, int) -> bool; +op <(float, int) -> bool; op <(i128, i128) -> bool; @@ -406,13 +406,13 @@ op <=(Instant, Instant) -> bool; op <=(int, f32) -> bool; -op <=(int, f64) -> bool; +op <=(int, float) -> bool; op <=(f32, int) -> bool; op <=(f32, f32) -> bool; -op <=(f64, int) -> bool; +op <=(float, int) -> bool; op <=(i128, i128) -> bool; @@ -473,13 +473,13 @@ op ==(Instant, Instant) -> bool; op ==(int, f32) -> bool; -op ==(int, f64) -> bool; +op ==(int, float) -> bool; op ==(f32, int) -> bool; op ==(f32, f32) -> bool; -op ==(f64, int) -> bool; +op ==(float, int) -> bool; op ==(i128, i128) -> bool; @@ -504,13 +504,13 @@ op >(Instant, Instant) -> bool; op >(int, f32) -> bool; -op >(int, f64) -> bool; +op >(int, float) -> bool; op >(f32, int) -> bool; op >(f32, f32) -> bool; -op >(f64, int) -> bool; +op >(float, int) -> bool; op >(i128, i128) -> bool; @@ -535,13 +535,13 @@ op >=(Instant, Instant) -> bool; op >=(int, f32) -> bool; -op >=(int, f64) -> bool; +op >=(int, float) -> bool; op >=(f32, int) -> bool; op >=(f32, f32) -> bool; -op >=(f64, int) -> bool; +op >=(float, int) -> bool; op >=(i128, i128) -> bool; @@ -580,10 +580,10 @@ op >>(u64, int) -> u64; op >>(u8, int) -> u8; /// Return the natural number _e_. -fn E() -> f64; +fn E() -> float; /// Return the number π. -fn PI() -> f64; +fn PI() -> float; op ^(i128, i128) -> i128; @@ -610,7 +610,7 @@ fn abs(x: int) -> int; fn abs(x: f32) -> f32; /// Return the absolute value of the floating-point number. -fn abs(x: f64) -> f64; +fn abs(x: float) -> float; /// Return the absolute value of the number. fn abs(x: i128) -> i128; @@ -625,10 +625,10 @@ fn abs(x: i32) -> i32; fn abs(x: i8) -> i8; /// Return the arc-cosine of the floating-point number, in radians. -fn acos(x: float) -> f64; +fn acos(x: float) -> float; /// Return the arc-hyperbolic-cosine of the floating-point number, in radians. -fn acosh(x: float) -> f64; +fn acosh(x: float) -> float; /// Return `true` if all elements in the array return `true` when applied a function named by `filter`. /// @@ -761,19 +761,19 @@ fn append(string: String, utf8: Blob) -> (); fn as_string(blob: Blob) -> String; /// Return the arc-sine of the floating-point number, in radians. -fn asin(x: float) -> f64; +fn asin(x: float) -> float; /// Return the arc-hyperbolic-sine of the floating-point number, in radians. -fn asinh(x: float) -> f64; +fn asinh(x: float) -> float; /// Return the arc-tangent of the floating-point number, in radians. -fn atan(x: float) -> f64; +fn atan(x: float) -> float; /// Return the arc-tangent of the floating-point numbers `x` and `y`, in radians. -fn atan(x: float, y: float) -> f64; +fn atan(x: float, y: float) -> float; /// Return the arc-hyperbolic-tangent of the floating-point number, in radians. -fn atanh(x: float) -> f64; +fn atanh(x: float) -> float; /// Return an iterator over all the bits in the number. /// @@ -814,7 +814,7 @@ fn bits(value: int, from: int) -> Iterator; /// print(bit); /// } /// ``` -fn bits(value: int, range: Range) -> Iterator; +fn bits(value: int, range: Range) -> Iterator; /// Return an iterator over an inclusive range of bits in the number. /// @@ -827,7 +827,7 @@ fn bits(value: int, range: Range) -> Iterator; /// print(bit); /// } /// ``` -fn bits(value: int, range: RangeInclusive) -> Iterator; +fn bits(value: int, range: RangeInclusive) -> Iterator; /// Return an iterator over a portion of bits in the number. /// @@ -886,10 +886,10 @@ fn blob(len: int, value: int) -> Blob; /// /// print(text.bytes); // prints 51 /// ``` -fn bytes(string: String) -> i64; +fn bytes(string: String) -> int; /// Return the smallest whole number larger than or equals to the floating-point number. -fn ceiling(x: float) -> f64; +fn ceiling(x: float) -> float; /// Return an iterator over the characters in the string. /// @@ -926,7 +926,7 @@ fn chars(string: String, from: int) -> Iterator; /// print(ch); /// } /// ``` -fn chars(string: String, range: Range) -> Iterator; +fn chars(string: String, range: Range) -> Iterator; /// Return an iterator over an inclusive range of characters in the string. /// @@ -937,7 +937,7 @@ fn chars(string: String, range: Range) -> Iterator; /// print(ch); /// } /// ``` -fn chars(string: String, range: RangeInclusive) -> Iterator; +fn chars(string: String, range: RangeInclusive) -> Iterator; /// Return an iterator over a portion of characters in the string. /// @@ -1030,10 +1030,10 @@ fn clear(string: String) -> (); fn contains(array: Array, value: ?) -> bool; /// Return the cosine of the floating-point number in radians. -fn cos(x: float) -> f64; +fn cos(x: float) -> float; /// Return the hyperbolic cosine of the floating-point number in radians. -fn cosh(x: float) -> f64; +fn cosh(x: float) -> float; /// Remove all characters from the string except those within an exclusive `range`. /// @@ -1046,7 +1046,7 @@ fn cosh(x: float) -> f64; /// /// print(text); // prints "llo, w" /// ``` -fn crop(string: String, range: Range) -> (); +fn crop(string: String, range: Range) -> (); /// Remove all characters from the string except those within an inclusive `range`. /// @@ -1059,7 +1059,7 @@ fn crop(string: String, range: Range) -> (); /// /// print(text); // prints "llo, wo" /// ``` -fn crop(string: String, range: RangeInclusive) -> (); +fn crop(string: String, range: RangeInclusive) -> (); /// Remove all characters from the string except until the `start` position. /// @@ -1127,7 +1127,7 @@ fn debug(map: Map) -> String; fn debug(number: f32) -> String; /// Convert the value of `number` into a string. -fn debug(number: f64) -> String; +fn debug(number: float) -> String; /// Convert the string into debug format. fn debug(string: String) -> String; @@ -1285,7 +1285,7 @@ fn drain(array: Array, filter: FnPtr) -> Array; /// /// print(z); // prints "[5]" /// ``` -fn drain(array: Array, range: Range) -> Array; +fn drain(array: Array, range: Range) -> Array; /// Remove all elements in the array within an inclusive `range` and return them as a new array. /// @@ -1306,7 +1306,7 @@ fn drain(array: Array, range: Range) -> Array; /// /// print(z); // prints "[5]" /// ``` -fn drain(array: Array, range: RangeInclusive) -> Array; +fn drain(array: Array, range: RangeInclusive) -> Array; /// Remove all bytes in the BLOB within an exclusive `range` and return them as a new BLOB. /// @@ -1329,7 +1329,7 @@ fn drain(array: Array, range: RangeInclusive) -> Array; /// /// print(b3); // prints "[05]" /// ``` -fn drain(blob: Blob, range: Range) -> Blob; +fn drain(blob: Blob, range: Range) -> Blob; /// Remove all bytes in the BLOB within an inclusive `range` and return them as a new BLOB. /// @@ -1352,7 +1352,7 @@ fn drain(blob: Blob, range: Range) -> Blob; /// /// print(b3); // prints "[05]" /// ``` -fn drain(blob: Blob, range: RangeInclusive) -> Blob; +fn drain(blob: Blob, range: RangeInclusive) -> Blob; /// Remove all elements within a portion of the array and return them as a new array. /// @@ -1424,10 +1424,10 @@ fn drain(blob: Blob, start: int, len: int) -> Blob; fn elapsed(timestamp: Instant) -> RhaiResult; /// Return the end of the exclusive range. -fn end(range: ExclusiveRange) -> i64; +fn end(range: ExclusiveRange) -> int; /// Return the end of the inclusive range. -fn end(range: InclusiveRange) -> i64; +fn end(range: InclusiveRange) -> int; /// Return `true` if the string ends with a specified string. /// @@ -1443,7 +1443,7 @@ fn end(range: InclusiveRange) -> i64; fn ends_with(string: String, match_string: String) -> bool; /// Return the exponential of the floating-point number. -fn exp(x: float) -> f64; +fn exp(x: float) -> float; /// Copy an exclusive range of the array and return it as a new array. /// @@ -1456,7 +1456,7 @@ fn exp(x: float) -> f64; /// /// print(x); // prints "[1, 2, 3, 4, 5]" /// ``` -fn extract(array: Array, range: Range) -> Array; +fn extract(array: Array, range: Range) -> Array; /// Copy an inclusive range of the array and return it as a new array. /// @@ -1469,7 +1469,7 @@ fn extract(array: Array, range: Range) -> Array; /// /// print(x); // prints "[1, 2, 3, 4, 5]" /// ``` -fn extract(array: Array, range: RangeInclusive) -> Array; +fn extract(array: Array, range: RangeInclusive) -> Array; /// Copy a portion of the array beginning at the `start` position till the end and return it as /// a new array. @@ -1504,7 +1504,7 @@ fn extract(array: Array, start: int) -> Array; /// /// print(b); // prints "[0102030405]" /// ``` -fn extract(blob: Blob, range: Range) -> Blob; +fn extract(blob: Blob, range: Range) -> Blob; /// Copy an inclusive `range` of the BLOB and return it as a new BLOB. /// @@ -1519,7 +1519,7 @@ fn extract(blob: Blob, range: Range) -> Blob; /// /// print(b); // prints "[0102030405]" /// ``` -fn extract(blob: Blob, range: RangeInclusive) -> Blob; +fn extract(blob: Blob, range: RangeInclusive) -> Blob; /// Copy a portion of the BLOB beginning at the `start` position till the end and return it as /// a new BLOB. @@ -1653,10 +1653,10 @@ fn filter(array: Array, filter: FnPtr) -> Array; fn filter(array: Array, filter_func: String) -> Array; /// Return the largest whole number less than or equals to the floating-point number. -fn floor(x: float) -> f64; +fn floor(x: float) -> float; /// Return the fractional part of the floating-point number. -fn fraction(x: float) -> f64; +fn fraction(x: float) -> float; /// Get a copy of the element at the `index` position in the array. /// @@ -1696,7 +1696,7 @@ fn get(array: Array, index: int) -> ?; /// /// print(b.get(99)); // prints 0 /// ``` -fn get(blob: Blob, index: int) -> i64; +fn get(blob: Blob, index: int) -> int; /// Get the value of the `property` in the object map and return a copy. /// @@ -1754,10 +1754,10 @@ fn get bits(value: int) -> Iterator; /// /// print(text.bytes); // prints 51 /// ``` -fn get bytes(string: String) -> i64; +fn get bytes(string: String) -> int; /// Return the smallest whole number larger than or equals to the floating-point number. -fn get ceiling(x: float) -> f64; +fn get ceiling(x: float) -> float; /// Return an iterator over all the characters in the string. /// @@ -1784,19 +1784,19 @@ fn get chars(string: String) -> Iterator; fn get elapsed(timestamp: Instant) -> RhaiResult; /// Return the end of the exclusive range. -fn get end(range: ExclusiveRange) -> i64; +fn get end(range: ExclusiveRange) -> int; /// Return the end of the inclusive range. -fn get end(range: InclusiveRange) -> i64; +fn get end(range: InclusiveRange) -> int; /// Return the largest whole number less than or equals to the floating-point number. -fn get floor(x: float) -> f64; +fn get floor(x: float) -> float; /// Return the fractional part of the floating-point number. -fn get fraction(x: float) -> f64; +fn get fraction(x: float) -> float; /// Return the integral part of the floating-point number. -fn get int(x: float) -> f64; +fn get int(x: float) -> float; /// Return `true` if the function is an anonymous function. /// @@ -1897,7 +1897,7 @@ fn get is_zero(x: int) -> bool; fn get is_zero(x: f32) -> bool; /// Return true if the floating-point number is zero. -fn get is_zero(x: f64) -> bool; +fn get is_zero(x: float) -> bool; /// Return true if the number is zero. fn get is_zero(x: i128) -> bool; @@ -1927,7 +1927,7 @@ fn get is_zero(x: u64) -> bool; fn get is_zero(x: u8) -> bool; /// Number of elements in the array. -fn get len(array: Array) -> i64; +fn get len(array: Array) -> int; /// Return the length of the BLOB. /// @@ -1940,7 +1940,7 @@ fn get len(array: Array) -> i64; /// /// print(b.len()); // prints 10 /// ``` -fn get len(blob: Blob) -> i64; +fn get len(blob: Blob) -> int; /// Return the length of the string, in number of characters. /// @@ -1951,7 +1951,7 @@ fn get len(blob: Blob) -> i64; /// /// print(text.len); // prints 17 /// ``` -fn get len(string: String) -> i64; +fn get len(string: String) -> int; /// Return the name of the function. /// @@ -1968,13 +1968,13 @@ fn get name(fn_ptr: FnPtr) -> String; /// Return the nearest whole number closest to the floating-point number. /// Rounds away from zero. -fn get round(x: float) -> f64; +fn get round(x: float) -> float; /// Return the start of the exclusive range. -fn get start(range: ExclusiveRange) -> i64; +fn get start(range: ExclusiveRange) -> int; /// Return the start of the inclusive range. -fn get start(range: InclusiveRange) -> i64; +fn get start(range: InclusiveRange) -> int; /// Return the _tag_ of a `Dynamic` value. /// @@ -1987,7 +1987,7 @@ fn get start(range: InclusiveRange) -> i64; /// /// print(x.tag); // prints 42 /// ``` -fn get tag(value: ?) -> i64; +fn get tag(value: ?) -> int; /// Return `true` if the specified `bit` in the number is set. /// @@ -2015,7 +2015,7 @@ fn get_bit(value: int, bit: int) -> bool; /// /// print(x.get_bits(5..10)); // print 18 /// ``` -fn get_bits(value: int, range: Range) -> int; +fn get_bits(value: int, range: Range) -> int; /// Return an inclusive range of bits in the number as a new number. /// @@ -2026,7 +2026,7 @@ fn get_bits(value: int, range: Range) -> int; /// /// print(x.get_bits(5..=9)); // print 18 /// ``` -fn get_bits(value: int, range: RangeInclusive) -> int; +fn get_bits(value: int, range: RangeInclusive) -> int; /// Return a portion of bits in the number as a new number. /// @@ -2050,7 +2050,7 @@ fn get_fn_metadata_list(name: String) -> Array; fn get_fn_metadata_list(name: String, params: int) -> Array; /// Return the hypotenuse of a triangle with sides `x` and `y`. -fn hypot(x: float, y: float) -> f64; +fn hypot(x: float, y: float) -> float; /// Iterate through all the elements in the array, applying a function named by `filter` to each /// element in turn, and return the index of the first element that returns `true`. @@ -2131,7 +2131,7 @@ fn index_of(array: Array, value: ?) -> int; /// /// print(text.index_of('x')); // prints -1 /// ``` -fn index_of(string: String, character: char) -> i64; +fn index_of(string: String, character: char) -> int; /// Find the specified `character` in the string and return the first index where it is found. /// If the `character` is not found, `-1` is returned. @@ -2145,7 +2145,7 @@ fn index_of(string: String, character: char) -> i64; /// /// print(text.index_of("xx:)); // prints -1 /// ``` -fn index_of(string: String, find_string: String) -> i64; +fn index_of(string: String, find_string: String) -> int; /// Iterate through all the elements in the array, starting from a particular `start` position, /// applying a function named by `filter` to each element in turn, and return the index of the @@ -2267,7 +2267,7 @@ fn index_of(array: Array, value: ?, start: int) -> int; /// /// print(text.index_of('x', 0)); // prints -1 /// ``` -fn index_of(string: String, character: char, start: int) -> i64; +fn index_of(string: String, character: char, start: int) -> int; /// Find the specified sub-string in the string, starting from the specified `start` position, /// and return the first index where it is found. @@ -2288,7 +2288,7 @@ fn index_of(string: String, character: char, start: int) -> i64; /// /// print(text.index_of("xx", 0)); // prints -1 /// ``` -fn index_of(string: String, find_string: String, start: int) -> i64; +fn index_of(string: String, find_string: String, start: int) -> int; /// Add a new element into the array at a particular `index` position. /// @@ -2331,7 +2331,7 @@ fn insert(array: Array, index: int, item: ?) -> (); fn insert(blob: Blob, index: int, value: int) -> (); /// Return the integral part of the floating-point number. -fn int(x: float) -> f64; +fn int(x: float) -> float; /// Return `true` if the function is an anonymous function. /// @@ -2432,7 +2432,7 @@ fn is_zero(x: int) -> bool; fn is_zero(x: f32) -> bool; /// Return true if the floating-point number is zero. -fn is_zero(x: f64) -> bool; +fn is_zero(x: float) -> bool; /// Return true if the number is zero. fn is_zero(x: i128) -> bool; @@ -2473,7 +2473,7 @@ fn is_zero(x: u8) -> bool; fn keys(map: Map) -> Array; /// Number of elements in the array. -fn len(array: Array) -> i64; +fn len(array: Array) -> int; /// Return the length of the BLOB. /// @@ -2486,10 +2486,10 @@ fn len(array: Array) -> i64; /// /// print(b.len()); // prints 10 /// ``` -fn len(blob: Blob) -> i64; +fn len(blob: Blob) -> int; /// Return the number of properties in the object map. -fn len(map: Map) -> i64; +fn len(map: Map) -> int; /// Return the length of the string, in number of characters. /// @@ -2500,16 +2500,16 @@ fn len(map: Map) -> i64; /// /// print(text.len); // prints 17 /// ``` -fn len(string: String) -> i64; +fn len(string: String) -> int; /// Return the natural log of the floating-point number. -fn ln(x: float) -> f64; +fn ln(x: float) -> float; /// Return the log of the floating-point number with base 10. -fn log(x: float) -> f64; +fn log(x: float) -> float; /// Return the log of the floating-point number with `base`. -fn log(x: float, base: float) -> f64; +fn log(x: float, base: float) -> float; /// Convert the character to lower-case. /// @@ -2726,14 +2726,14 @@ fn pad(string: String, len: int, padding: String) -> (); /// /// * If number of bytes in `range` < number of bytes for `FLOAT`, zeros are padded. /// * If number of bytes in `range` > number of bytes for `FLOAT`, extra bytes are ignored. -fn parse_be_float(blob: Blob, range: Range) -> f64; +fn parse_be_float(blob: Blob, range: Range) -> float; /// Parse the bytes within an inclusive `range` in the BLOB as a `FLOAT` /// in big-endian byte order. /// /// * If number of bytes in `range` < number of bytes for `FLOAT`, zeros are padded. /// * If number of bytes in `range` > number of bytes for `FLOAT`, extra bytes are ignored. -fn parse_be_float(blob: Blob, range: RangeInclusive) -> f64; +fn parse_be_float(blob: Blob, range: RangeInclusive) -> float; /// Parse the bytes beginning at the `start` position in the BLOB as a `FLOAT` /// in big-endian byte order. @@ -2746,7 +2746,7 @@ fn parse_be_float(blob: Blob, range: RangeInclusive) -> f64; /// /// * If number of bytes in range < number of bytes for `FLOAT`, zeros are padded. /// * If number of bytes in range > number of bytes for `FLOAT`, extra bytes are ignored. -fn parse_be_float(blob: Blob, start: int, len: int) -> f64; +fn parse_be_float(blob: Blob, start: int, len: int) -> float; /// Parse the bytes within an exclusive `range` in the BLOB as an `INT` /// in big-endian byte order. @@ -2763,7 +2763,7 @@ fn parse_be_float(blob: Blob, start: int, len: int) -> f64; /// /// print(x.to_hex()); // prints "02030000...00" /// ``` -fn parse_be_int(blob: Blob, range: Range) -> i64; +fn parse_be_int(blob: Blob, range: Range) -> int; /// Parse the bytes within an inclusive `range` in the BLOB as an `INT` /// in big-endian byte order. @@ -2780,7 +2780,7 @@ fn parse_be_int(blob: Blob, range: Range) -> i64; /// /// print(x.to_hex()); // prints "0203040000...00" /// ``` -fn parse_be_int(blob: Blob, range: RangeInclusive) -> i64; +fn parse_be_int(blob: Blob, range: RangeInclusive) -> int; /// Parse the bytes beginning at the `start` position in the BLOB as an `INT` /// in big-endian byte order. @@ -2803,7 +2803,7 @@ fn parse_be_int(blob: Blob, range: RangeInclusive) -> i64; /// /// print(x.to_hex()); // prints "02030000...00" /// ``` -fn parse_be_int(blob: Blob, start: int, len: int) -> i64; +fn parse_be_int(blob: Blob, start: int, len: int) -> int; /// Parse a string into a floating-point number. /// @@ -2849,14 +2849,14 @@ fn parse_int(string: String, radix: int) -> int; /// /// * If number of bytes in `range` < number of bytes for `FLOAT`, zeros are padded. /// * If number of bytes in `range` > number of bytes for `FLOAT`, extra bytes are ignored. -fn parse_le_float(blob: Blob, range: Range) -> f64; +fn parse_le_float(blob: Blob, range: Range) -> float; /// Parse the bytes within an inclusive `range` in the BLOB as a `FLOAT` /// in little-endian byte order. /// /// * If number of bytes in `range` < number of bytes for `FLOAT`, zeros are padded. /// * If number of bytes in `range` > number of bytes for `FLOAT`, extra bytes are ignored. -fn parse_le_float(blob: Blob, range: RangeInclusive) -> f64; +fn parse_le_float(blob: Blob, range: RangeInclusive) -> float; /// Parse the bytes beginning at the `start` position in the BLOB as a `FLOAT` /// in little-endian byte order. @@ -2869,7 +2869,7 @@ fn parse_le_float(blob: Blob, range: RangeInclusive) -> f64; /// /// * If number of bytes in range < number of bytes for `FLOAT`, zeros are padded. /// * If number of bytes in range > number of bytes for `FLOAT`, extra bytes are ignored. -fn parse_le_float(blob: Blob, start: int, len: int) -> f64; +fn parse_le_float(blob: Blob, start: int, len: int) -> float; /// Parse the bytes within an exclusive `range` in the BLOB as an `INT` /// in little-endian byte order. @@ -2886,7 +2886,7 @@ fn parse_le_float(blob: Blob, start: int, len: int) -> f64; /// /// print(x.to_hex()); // prints "0302" /// ``` -fn parse_le_int(blob: Blob, range: Range) -> i64; +fn parse_le_int(blob: Blob, range: Range) -> int; /// Parse the bytes within an inclusive `range` in the BLOB as an `INT` /// in little-endian byte order. @@ -2903,7 +2903,7 @@ fn parse_le_int(blob: Blob, range: Range) -> i64; /// /// print(x.to_hex()); // prints "040302" /// ``` -fn parse_le_int(blob: Blob, range: RangeInclusive) -> i64; +fn parse_le_int(blob: Blob, range: RangeInclusive) -> int; /// Parse the bytes beginning at the `start` position in the BLOB as an `INT` /// in little-endian byte order. @@ -2926,7 +2926,7 @@ fn parse_le_int(blob: Blob, range: RangeInclusive) -> i64; /// /// print(x.to_hex()); // prints "0302" /// ``` -fn parse_le_int(blob: Blob, start: int, len: int) -> i64; +fn parse_le_int(blob: Blob, start: int, len: int) -> int; /// Remove the last element from the array and return it. /// @@ -2958,7 +2958,7 @@ fn pop(array: Array) -> ?; /// /// print(b); // prints "[01020304]" /// ``` -fn pop(blob: Blob) -> i64; +fn pop(blob: Blob) -> int; /// Remove the last character from the string and return it. /// @@ -3011,7 +3011,7 @@ fn print(map: Map) -> String; fn print(number: f32) -> String; /// Convert the value of `number` into a string. -fn print(number: f64) -> String; +fn print(number: float) -> String; /// Return the `string`. fn print(string: String) -> String; @@ -3102,7 +3102,7 @@ fn range(from: i32, to: i32) -> Iterator; /// print(n); /// } /// ``` -fn range(from: i64, to: i64) -> Iterator; +fn range(from: int, to: int) -> Iterator; /// Return an iterator over the exclusive range of `from..to`. /// The value `to` is never included. @@ -3285,7 +3285,7 @@ fn range(range: Range, step: i32) -> Iterator; /// print(n); /// } /// ``` -fn range(range: Range, step: i64) -> Iterator; +fn range(range: Range, step: int) -> Iterator; /// Return an iterator over an exclusive range, each iteration increasing by `step`. /// @@ -3521,7 +3521,7 @@ fn range(from: i32, to: i32, step: i32) -> Iterator; /// print(n); /// } /// ``` -fn range(from: i64, to: i64, step: i64) -> Iterator; +fn range(from: int, to: int, step: int) -> Iterator; /// Return an iterator over the exclusive range of `from..to`, each iteration increasing by `step`. /// The value `to` is never included. @@ -3915,7 +3915,7 @@ fn remove(array: Array, index: int) -> ?; /// /// print(x); // prints "[010305]" /// ``` -fn remove(blob: Blob, index: int) -> i64; +fn remove(blob: Blob, index: int) -> int; /// Remove any property of the specified `name` from the object map, returning its value. /// @@ -4091,7 +4091,7 @@ fn retain(array: Array, filter: FnPtr) -> Array; /// /// print(z); // prints "[1]" /// ``` -fn retain(array: Array, range: Range) -> Array; +fn retain(array: Array, range: Range) -> Array; /// Remove all elements in the array not within an inclusive `range` and return them as a new array. /// @@ -4112,7 +4112,7 @@ fn retain(array: Array, range: Range) -> Array; /// /// print(z); // prints "[1]" /// ``` -fn retain(array: Array, range: RangeInclusive) -> Array; +fn retain(array: Array, range: RangeInclusive) -> Array; /// Remove all bytes in the BLOB not within an exclusive `range` and return them as a new BLOB. /// @@ -4135,7 +4135,7 @@ fn retain(array: Array, range: RangeInclusive) -> Array; /// /// print(b2); // prints "[01]" /// ``` -fn retain(blob: Blob, range: Range) -> Blob; +fn retain(blob: Blob, range: Range) -> Blob; /// Remove all bytes in the BLOB not within an inclusive `range` and return them as a new BLOB. /// @@ -4158,7 +4158,7 @@ fn retain(blob: Blob, range: Range) -> Blob; /// /// print(b2); // prints "[01]" /// ``` -fn retain(blob: Blob, range: RangeInclusive) -> Blob; +fn retain(blob: Blob, range: RangeInclusive) -> Blob; /// Remove all elements not within a portion of the array and return them as a new array. /// @@ -4248,7 +4248,7 @@ fn reverse(blob: Blob) -> (); /// Return the nearest whole number closest to the floating-point number. /// Rounds away from zero. -fn round(x: float) -> f64; +fn round(x: float) -> float; /// Set the element at the `index` position in the array to a new `value`. /// @@ -4394,7 +4394,7 @@ fn set_bit(value: int, bit: int, new_value: bool) -> (); /// /// print(x); // print 123200 /// ``` -fn set_bits(value: int, range: Range, new_value: int) -> (); +fn set_bits(value: int, range: Range, new_value: int) -> (); /// Replace an inclusive range of bits in the number with a new value. /// @@ -4407,7 +4407,7 @@ fn set_bits(value: int, range: Range, new_value: int) -> (); /// /// print(x); // print 123200 /// ``` -fn set_bits(value: int, range: RangeInclusive, new_value: int) -> (); +fn set_bits(value: int, range: RangeInclusive, new_value: int) -> (); /// Replace a portion of bits in the number with a new value. /// @@ -4473,14 +4473,14 @@ fn shift(array: Array) -> ?; /// /// print(b); // prints "[02030405]" /// ``` -fn shift(blob: Blob) -> i64; +fn shift(blob: Blob) -> int; /// Return the sign (as an integer) of the number according to the following: /// /// * `0` if the number is zero /// * `1` if the number is positive /// * `-1` if the number is negative -fn sign(x: int) -> i64; +fn sign(x: int) -> int; /// Return the sign (as an integer) of the floating-point number according to the following: /// @@ -4494,41 +4494,41 @@ fn sign(x: f32) -> int; /// * `0` if the number is zero /// * `1` if the number is positive /// * `-1` if the number is negative -fn sign(x: f64) -> int; +fn sign(x: float) -> int; /// Return the sign (as an integer) of the number according to the following: /// /// * `0` if the number is zero /// * `1` if the number is positive /// * `-1` if the number is negative -fn sign(x: i128) -> i64; +fn sign(x: i128) -> int; /// Return the sign (as an integer) of the number according to the following: /// /// * `0` if the number is zero /// * `1` if the number is positive /// * `-1` if the number is negative -fn sign(x: i16) -> i64; +fn sign(x: i16) -> int; /// Return the sign (as an integer) of the number according to the following: /// /// * `0` if the number is zero /// * `1` if the number is positive /// * `-1` if the number is negative -fn sign(x: i32) -> i64; +fn sign(x: i32) -> int; /// Return the sign (as an integer) of the number according to the following: /// /// * `0` if the number is zero /// * `1` if the number is positive /// * `-1` if the number is negative -fn sign(x: i8) -> i64; +fn sign(x: i8) -> int; /// Return the sine of the floating-point number in radians. -fn sin(x: float) -> f64; +fn sin(x: float) -> float; /// Return the hyperbolic sine of the floating-point number in radians. -fn sinh(x: float) -> f64; +fn sinh(x: float) -> float; /// Block the current thread for a particular number of `seconds`. fn sleep(seconds: int) -> (); @@ -4682,7 +4682,7 @@ fn sort(array: Array, comparer: FnPtr) -> (); /// /// print(x); // prints "[1, 7, 8, 9, 10, 4, 5]" /// ``` -fn splice(array: Array, range: Range, replace: Array) -> (); +fn splice(array: Array, range: Range, replace: Array) -> (); /// Replace an inclusive range of the array with another array. /// @@ -4696,7 +4696,7 @@ fn splice(array: Array, range: Range, replace: Array) -> (); /// /// print(x); // prints "[1, 7, 8, 9, 10, 5]" /// ``` -fn splice(array: Array, range: RangeInclusive, replace: Array) -> (); +fn splice(array: Array, range: RangeInclusive, replace: Array) -> (); /// Replace an exclusive `range` of the BLOB with another BLOB. /// @@ -4710,7 +4710,7 @@ fn splice(array: Array, range: RangeInclusive, replace: Array) -> (); /// /// print(b1); // prints "[4218181818184242 42424242]" /// ``` -fn splice(blob: Blob, range: Range, replace: Blob) -> (); +fn splice(blob: Blob, range: Range, replace: Blob) -> (); /// Replace an inclusive `range` of the BLOB with another BLOB. /// @@ -4724,7 +4724,7 @@ fn splice(blob: Blob, range: Range, replace: Blob) -> (); /// /// print(b1); // prints "[4218181818184242 424242]" /// ``` -fn splice(blob: Blob, range: RangeInclusive, replace: Blob) -> (); +fn splice(blob: Blob, range: RangeInclusive, replace: Blob) -> (); /// Replace a portion of the array with another array. /// @@ -4954,13 +4954,13 @@ fn split_rev(string: String, delimiter: String, segments: int) -> Array; fn split_rev(string: String, delimiter: char, segments: int) -> Array; /// Return the square root of the floating-point number. -fn sqrt(x: float) -> f64; +fn sqrt(x: float) -> float; /// Return the start of the exclusive range. -fn start(range: ExclusiveRange) -> i64; +fn start(range: ExclusiveRange) -> int; /// Return the start of the inclusive range. -fn start(range: InclusiveRange) -> i64; +fn start(range: InclusiveRange) -> int; /// Return `true` if the string starts with a specified string. /// @@ -4984,7 +4984,7 @@ fn starts_with(string: String, match_string: String) -> bool; /// /// print(text.sub_string(3..7)); // prints "lo, " /// ``` -fn sub_string(string: String, range: Range) -> String; +fn sub_string(string: String, range: Range) -> String; /// Copy an inclusive range of characters from the string and return it as a new string. /// @@ -4995,7 +4995,7 @@ fn sub_string(string: String, range: Range) -> String; /// /// print(text.sub_string(3..=7)); // prints "lo, w" /// ``` -fn sub_string(string: String, range: RangeInclusive) -> String; +fn sub_string(string: String, range: RangeInclusive) -> String; /// Copy a portion of the string beginning at the `start` position till the end and return it as /// a new string. @@ -5045,13 +5045,13 @@ fn sub_string(string: String, start: int, len: int) -> String; /// /// print(x.tag); // prints 42 /// ``` -fn tag(value: ?) -> i64; +fn tag(value: ?) -> int; /// Return the tangent of the floating-point number in radians. -fn tan(x: float) -> f64; +fn tan(x: float) -> float; /// Return the hyperbolic tangent of the floating-point number in radians. -fn tanh(x: float) -> f64; +fn tanh(x: float) -> float; /// Create a timestamp containing the current system time. fn timestamp() -> Instant; @@ -5079,7 +5079,7 @@ fn to_binary(value: i16) -> String; fn to_binary(value: i32) -> String; /// Convert the `value` into a string in binary format. -fn to_binary(value: i64) -> String; +fn to_binary(value: int) -> String; /// Convert the `value` into a string in binary format. fn to_binary(value: i8) -> String; @@ -5142,7 +5142,7 @@ fn to_debug(map: Map) -> String; fn to_debug(number: f32) -> String; /// Convert the value of `number` into a string. -fn to_debug(number: f64) -> String; +fn to_debug(number: float) -> String; /// Convert the string into debug format. fn to_debug(string: String) -> String; @@ -5154,28 +5154,28 @@ fn to_debug(unit: ()) -> String; fn to_debug(value: bool) -> String; /// Convert radians to degrees. -fn to_degrees(x: float) -> f64; +fn to_degrees(x: float) -> float; /// Convert the 32-bit floating-point number to 64-bit. -fn to_float(x: f32) -> f64; +fn to_float(x: f32) -> float; -fn to_float(x: i128) -> f64; +fn to_float(x: i128) -> float; -fn to_float(x: i16) -> f64; +fn to_float(x: i16) -> float; -fn to_float(x: i32) -> f64; +fn to_float(x: i32) -> float; -fn to_float(x: i64) -> f64; +fn to_float(x: int) -> float; -fn to_float(x: i8) -> f64; +fn to_float(x: i8) -> float; -fn to_float(x: u128) -> f64; +fn to_float(x: u128) -> float; -fn to_float(x: u16) -> f64; +fn to_float(x: u16) -> float; -fn to_float(x: u32) -> f64; +fn to_float(x: u32) -> float; -fn to_float(x: u8) -> f64; +fn to_float(x: u8) -> float; /// Convert the `value` into a string in hex format. fn to_hex(value: i128) -> String; @@ -5187,7 +5187,7 @@ fn to_hex(value: i16) -> String; fn to_hex(value: i32) -> String; /// Convert the `value` into a string in hex format. -fn to_hex(value: i64) -> String; +fn to_hex(value: int) -> String; /// Convert the `value` into a string in hex format. fn to_hex(value: i8) -> String; @@ -5207,33 +5207,33 @@ fn to_hex(value: u64) -> String; /// Convert the `value` into a string in hex format. fn to_hex(value: u8) -> String; -fn to_int(x: char) -> i64; +fn to_int(x: char) -> int; /// Convert the floating-point number into an integer. fn to_int(x: f32) -> int; /// Convert the floating-point number into an integer. -fn to_int(x: f64) -> int; +fn to_int(x: float) -> int; -fn to_int(x: i128) -> i64; +fn to_int(x: i128) -> int; -fn to_int(x: i16) -> i64; +fn to_int(x: i16) -> int; -fn to_int(x: i32) -> i64; +fn to_int(x: i32) -> int; -fn to_int(x: i64) -> i64; +fn to_int(x: int) -> int; -fn to_int(x: i8) -> i64; +fn to_int(x: i8) -> int; -fn to_int(x: u128) -> i64; +fn to_int(x: u128) -> int; -fn to_int(x: u16) -> i64; +fn to_int(x: u16) -> int; -fn to_int(x: u32) -> i64; +fn to_int(x: u32) -> int; -fn to_int(x: u64) -> i64; +fn to_int(x: u64) -> int; -fn to_int(x: u8) -> i64; +fn to_int(x: u8) -> int; /// Return the JSON representation of the object map. /// @@ -5292,7 +5292,7 @@ fn to_octal(value: i16) -> String; fn to_octal(value: i32) -> String; /// Convert the `value` into a string in octal format. -fn to_octal(value: i64) -> String; +fn to_octal(value: int) -> String; /// Convert the `value` into a string in octal format. fn to_octal(value: i8) -> String; @@ -5313,7 +5313,7 @@ fn to_octal(value: u64) -> String; fn to_octal(value: u8) -> String; /// Convert degrees to radians. -fn to_radians(x: float) -> f64; +fn to_radians(x: float) -> float; /// Convert the array into a string. fn to_string(array: Array) -> String; @@ -5331,7 +5331,7 @@ fn to_string(map: Map) -> String; fn to_string(number: f32) -> String; /// Convert the value of `number` into a string. -fn to_string(number: f64) -> String; +fn to_string(number: float) -> String; /// Return the `string`. fn to_string(string: String) -> String; @@ -5469,7 +5469,7 @@ fn values(map: Map) -> Array; /// /// print(b); // prints "[0068656c6c000000]" /// ``` -fn write_ascii(blob: Blob, range: Range, string: String) -> (); +fn write_ascii(blob: Blob, range: Range, string: String) -> (); /// Write an ASCII string to the bytes within an inclusive `range` in the BLOB. /// @@ -5486,7 +5486,7 @@ fn write_ascii(blob: Blob, range: Range, string: String) -> (); /// /// print(b); // prints "[0068656c6c6f0000]" /// ``` -fn write_ascii(blob: Blob, range: RangeInclusive, string: String) -> (); +fn write_ascii(blob: Blob, range: RangeInclusive, string: String) -> (); /// Write an ASCII string to the bytes within an exclusive `range` in the BLOB. /// @@ -5513,7 +5513,7 @@ fn write_ascii(blob: Blob, start: int, len: int, string: String) -> (); /// /// * If number of bytes in `range` < number of bytes for `FLOAT`, extra bytes in `FLOAT` are not written. /// * If number of bytes in `range` > number of bytes for `FLOAT`, extra bytes in `range` are not modified. -fn write_be(blob: Blob, range: Range, value: float) -> (); +fn write_be(blob: Blob, range: Range, value: float) -> (); /// Write an `INT` value to the bytes within an exclusive `range` in the BLOB /// in big-endian byte order. @@ -5528,14 +5528,14 @@ fn write_be(blob: Blob, range: Range, value: float) -> (); /// /// print(b); // prints "[4200004242424242]" /// ``` -fn write_be(blob: Blob, range: Range, value: int) -> (); +fn write_be(blob: Blob, range: Range, value: int) -> (); /// Write a `FLOAT` value to the bytes within an inclusive `range` in the BLOB /// in big-endian byte order. /// /// * If number of bytes in `range` < number of bytes for `FLOAT`, extra bytes in `FLOAT` are not written. /// * If number of bytes in `range` > number of bytes for `FLOAT`, extra bytes in `range` are not modified. -fn write_be(blob: Blob, range: RangeInclusive, value: float) -> (); +fn write_be(blob: Blob, range: RangeInclusive, value: float) -> (); /// Write an `INT` value to the bytes within an inclusive `range` in the BLOB /// in big-endian byte order. @@ -5550,7 +5550,7 @@ fn write_be(blob: Blob, range: RangeInclusive, value: float) -> (); /// /// print(b); // prints "[4200000042424242]" /// ``` -fn write_be(blob: Blob, range: RangeInclusive, value: int) -> (); +fn write_be(blob: Blob, range: RangeInclusive, value: int) -> (); /// Write a `FLOAT` value to the bytes beginning at the `start` position in the BLOB /// in big-endian byte order. @@ -5591,7 +5591,7 @@ fn write_be(blob: Blob, start: int, len: int, value: int) -> (); /// /// * If number of bytes in `range` < number of bytes for `FLOAT`, extra bytes in `FLOAT` are not written. /// * If number of bytes in `range` > number of bytes for `FLOAT`, extra bytes in `range` are not modified. -fn write_le(blob: Blob, range: Range, value: float) -> (); +fn write_le(blob: Blob, range: Range, value: float) -> (); /// Write an `INT` value to the bytes within an exclusive `range` in the BLOB /// in little-endian byte order. @@ -5606,14 +5606,14 @@ fn write_le(blob: Blob, range: Range, value: float) -> (); /// /// print(b); // prints "[0078560000000000]" /// ``` -fn write_le(blob: Blob, range: Range, value: int) -> (); +fn write_le(blob: Blob, range: Range, value: int) -> (); /// Write a `FLOAT` value to the bytes within an inclusive `range` in the BLOB /// in little-endian byte order. /// /// * If number of bytes in `range` < number of bytes for `FLOAT`, extra bytes in `FLOAT` are not written. /// * If number of bytes in `range` > number of bytes for `FLOAT`, extra bytes in `range` are not modified. -fn write_le(blob: Blob, range: RangeInclusive, value: float) -> (); +fn write_le(blob: Blob, range: RangeInclusive, value: float) -> (); /// Write an `INT` value to the bytes within an inclusive `range` in the BLOB /// in little-endian byte order. @@ -5628,7 +5628,7 @@ fn write_le(blob: Blob, range: RangeInclusive, value: float) -> (); /// /// print(b); // prints "[0078563400000000]" /// ``` -fn write_le(blob: Blob, range: RangeInclusive, value: int) -> (); +fn write_le(blob: Blob, range: RangeInclusive, value: int) -> (); /// Write a `FLOAT` value to the bytes beginning at the `start` position in the BLOB /// in little-endian byte order. @@ -5676,7 +5676,7 @@ fn write_le(blob: Blob, start: int, len: int, value: int) -> (); /// /// print(b); // prints "[00e69c9de3000000]" /// ``` -fn write_utf8(blob: Blob, range: Range, string: String) -> (); +fn write_utf8(blob: Blob, range: Range, string: String) -> (); /// Write a string to the bytes within an inclusive `range` in the BLOB in UTF-8 encoding. /// @@ -5690,7 +5690,7 @@ fn write_utf8(blob: Blob, range: Range, string: String) -> (); /// /// print(b); // prints "[00e69c9de3810000]" /// ``` -fn write_utf8(blob: Blob, range: RangeInclusive, string: String) -> (); +fn write_utf8(blob: Blob, range: RangeInclusive, string: String) -> (); /// Write a string to the bytes within an inclusive `range` in the BLOB in UTF-8 encoding. /// diff --git a/examples/definitions/.rhai/definitions/general_kenobi.d.rhai b/examples/definitions/.rhai/definitions/general_kenobi.d.rhai index dfa07701..9e077d8e 100644 --- a/examples/definitions/.rhai/definitions/general_kenobi.d.rhai +++ b/examples/definitions/.rhai/definitions/general_kenobi.d.rhai @@ -1,4 +1,4 @@ module general_kenobi; /// Returns a string where "hello there" is repeated `n` times. -fn hello_there(n: i64) -> String; \ No newline at end of file +fn hello_there(n: int) -> String; \ No newline at end of file diff --git a/src/api/definitions/builtin-operators.d.rhai b/src/api/definitions/builtin-operators.d.rhai index b5ba3344..012a95a4 100644 --- a/src/api/definitions/builtin-operators.d.rhai +++ b/src/api/definitions/builtin-operators.d.rhai @@ -1,16 +1,16 @@ module static; -op ==(i64, i64) -> bool; -op !=(i64, i64) -> bool; -op >(i64, i64) -> bool; -op >=(i64, i64) -> bool; -op <(i64, i64) -> bool; -op <=(i64, i64) -> bool; -op &(i64, i64) -> i64; -op |(i64, i64) -> i64; -op ^(i64, i64) -> i64; -op ..(i64, i64) -> Range; -op ..=(i64, i64) -> RangeInclusive; +op ==(int, int) -> bool; +op !=(int, int) -> bool; +op >(int, int) -> bool; +op >=(int, int) -> bool; +op <(int, int) -> bool; +op <=(int, int) -> bool; +op &(int, int) -> int; +op |(int, int) -> int; +op ^(int, int) -> int; +op ..(int, int) -> Range; +op ..=(int, int) -> RangeInclusive; op ==(bool, bool) -> bool; op !=(bool, bool) -> bool; @@ -29,53 +29,53 @@ op >=((), ()) -> bool; op <((), ()) -> bool; op <=((), ()) -> bool; -op +(i64, i64) -> i64; -op -(i64, i64) -> i64; -op *(i64, i64) -> i64; -op /(i64, i64) -> i64; -op %(i64, i64) -> i64; -op **(i64, i64) -> i64; -op >>(i64, i64) -> i64; -op <<(i64, i64) -> i64; +op +(int, int) -> int; +op -(int, int) -> int; +op *(int, int) -> int; +op /(int, int) -> int; +op %(int, int) -> int; +op **(int, int) -> int; +op >>(int, int) -> int; +op <<(int, int) -> int; -op +(f64, f64) -> f64; -op -(f64, f64) -> f64; -op *(f64, f64) -> f64; -op /(f64, f64) -> f64; -op %(f64, f64) -> f64; -op **(f64, f64) -> f64; -op ==(f64, f64) -> bool; -op !=(f64, f64) -> bool; -op >(f64, f64) -> bool; -op >=(f64, f64) -> bool; -op <(f64, f64) -> bool; -op <=(f64, f64) -> bool; +op +(float, float) -> float; +op -(float, float) -> float; +op *(float, float) -> float; +op /(float, float) -> float; +op %(float, float) -> float; +op **(float, float) -> float; +op ==(float, float) -> bool; +op !=(float, float) -> bool; +op >(float, float) -> bool; +op >=(float, float) -> bool; +op <(float, float) -> bool; +op <=(float, float) -> bool; -op +(f64, i64) -> f64; -op -(f64, i64) -> f64; -op *(f64, i64) -> f64; -op /(f64, i64) -> f64; -op %(f64, i64) -> f64; -op **(f64, i64) -> f64; -op ==(f64, i64) -> bool; -op !=(f64, i64) -> bool; -op >(f64, i64) -> bool; -op >=(f64, i64) -> bool; -op <(f64, i64) -> bool; -op <=(f64, i64) -> bool; +op +(float, int) -> float; +op -(float, int) -> float; +op *(float, int) -> float; +op /(float, int) -> float; +op %(float, int) -> float; +op **(float, int) -> float; +op ==(float, int) -> bool; +op !=(float, int) -> bool; +op >(float, int) -> bool; +op >=(float, int) -> bool; +op <(float, int) -> bool; +op <=(float, int) -> bool; -op +(i64, f64) -> f64; -op -(i64, f64) -> f64; -op *(i64, f64) -> f64; -op /(i64, f64) -> f64; -op %(i64, f64) -> f64; -op **(i64, f64) -> f64; -op ==(i64, f64) -> bool; -op !=(i64, f64) -> bool; -op >(i64, f64) -> bool; -op >=(i64, f64) -> bool; -op <(i64, f64) -> bool; -op <=(i64, f64) -> bool; +op +(int, float) -> float; +op -(int, float) -> float; +op *(int, float) -> float; +op /(int, float) -> float; +op %(int, float) -> float; +op **(int, float) -> float; +op ==(int, float) -> bool; +op !=(int, float) -> bool; +op >(int, float) -> bool; +op >=(int, float) -> bool; +op <(int, float) -> bool; +op <=(int, float) -> bool; op +(Decimal, Decimal) -> Decimal; op -(Decimal, Decimal) -> Decimal; @@ -90,31 +90,31 @@ op >=(Decimal, Decimal) -> bool; op <(Decimal, Decimal) -> bool; op <=(Decimal, Decimal) -> bool; -op +(Decimal, i64) -> Decimal; -op -(Decimal, i64) -> Decimal; -op *(Decimal, i64) -> Decimal; -op /(Decimal, i64) -> Decimal; -op %(Decimal, i64) -> Decimal; -op **(Decimal, i64) -> Decimal; -op ==(Decimal, i64) -> bool; -op !=(Decimal, i64) -> bool; -op >(Decimal, i64) -> bool; -op >=(Decimal, i64) -> bool; -op <(Decimal, i64) -> bool; -op <=(Decimal, i64) -> bool; +op +(Decimal, int) -> Decimal; +op -(Decimal, int) -> Decimal; +op *(Decimal, int) -> Decimal; +op /(Decimal, int) -> Decimal; +op %(Decimal, int) -> Decimal; +op **(Decimal, int) -> Decimal; +op ==(Decimal, int) -> bool; +op !=(Decimal, int) -> bool; +op >(Decimal, int) -> bool; +op >=(Decimal, int) -> bool; +op <(Decimal, int) -> bool; +op <=(Decimal, int) -> bool; -op +(i64, Decimal) -> Decimal; -op -(i64, Decimal) -> Decimal; -op *(i64, Decimal) -> Decimal; -op /(i64, Decimal) -> Decimal; -op %(i64, Decimal) -> Decimal; -op **(i64, Decimal) -> Decimal; -op ==(i64, Decimal) -> bool; -op !=(i64, Decimal) -> bool; -op >(i64, Decimal) -> bool; -op >=(i64, Decimal) -> bool; -op <(i64, Decimal) -> bool; -op <=(i64, Decimal) -> bool; +op +(int, Decimal) -> Decimal; +op -(int, Decimal) -> Decimal; +op *(int, Decimal) -> Decimal; +op /(int, Decimal) -> Decimal; +op %(int, Decimal) -> Decimal; +op **(int, Decimal) -> Decimal; +op ==(int, Decimal) -> bool; +op !=(int, Decimal) -> bool; +op >(int, Decimal) -> bool; +op >=(int, Decimal) -> bool; +op <(int, Decimal) -> bool; +op <=(int, Decimal) -> bool; op +(String, String) -> String; op -(String, String) -> String; @@ -172,17 +172,17 @@ op ==(Blob, Blob) -> bool; op !=(Blob, Blob) -> bool; -op ==(Range, RangeInclusive) -> bool; -op !=(Range, RangeInclusive) -> bool; +op ==(Range, RangeInclusive) -> bool; +op !=(Range, RangeInclusive) -> bool; -op ==(RangeInclusive, Range) -> bool; -op !=(RangeInclusive, Range) -> bool; +op ==(RangeInclusive, Range) -> bool; +op !=(RangeInclusive, Range) -> bool; -op ==(Range, Range) -> bool; -op !=(Range, Range) -> bool; +op ==(Range, Range) -> bool; +op !=(Range, Range) -> bool; -op ==(RangeInclusive, RangeInclusive) -> bool; -op !=(RangeInclusive, RangeInclusive) -> bool; +op ==(RangeInclusive, RangeInclusive) -> bool; +op !=(RangeInclusive, RangeInclusive) -> bool; op ==(?, ?) -> bool; op !=(?, ?) -> bool; @@ -195,31 +195,31 @@ op <=(?, ?) -> bool; op &=(bool, bool); op |=(bool, bool); -op +=(i64, i64); -op -=(i64, i64); -op *=(i64, i64); -op /=(i64, i64); -op %=(i64, i64); -op **=(i64, i64); -op >>=(i64, i64); -op <<=(i64, i64); -op &=(i64, i64); -op |=(i64, i64); -op ^=(i64, i64); +op +=(int, int); +op -=(int, int); +op *=(int, int); +op /=(int, int); +op %=(int, int); +op **=(int, int); +op >>=(int, int); +op <<=(int, int); +op &=(int, int); +op |=(int, int); +op ^=(int, int); -op +=(f64, f64); -op -=(f64, f64); -op *=(f64, f64); -op /=(f64, f64); -op %=(f64, f64); -op **=(f64, f64); +op +=(float, float); +op -=(float, float); +op *=(float, float); +op /=(float, float); +op %=(float, float); +op **=(float, float); -op +=(f64, i64); -op -=(f64, i64); -op *=(f64, i64); -op /=(f64, i64); -op %=(f64, i64); -op **=(f64, i64); +op +=(float, int); +op -=(float, int); +op *=(float, int); +op /=(float, int); +op %=(float, int); +op **=(float, int); op +=(Decimal, Decimal); op -=(Decimal, Decimal); @@ -228,12 +228,12 @@ op /=(Decimal, Decimal); op %=(Decimal, Decimal); op **=(Decimal, Decimal); -op +=(Decimal, i64); -op -=(Decimal, i64); -op *=(Decimal, i64); -op /=(Decimal, i64); -op %=(Decimal, i64); -op **=(Decimal, i64); +op +=(Decimal, int); +op -=(Decimal, int); +op *=(Decimal, int); +op /=(Decimal, int); +op %=(Decimal, int); +op **=(Decimal, int); op +=(String, String); op -=(String, String); @@ -246,7 +246,7 @@ op +=(Array, Array); op +=(Array, ?); op +=(Blob, Blob); -op +=(Blob, i64); +op +=(Blob, int); op +=(Blob, char); op +=(Blob, String); diff --git a/src/api/definitions/mod.rs b/src/api/definitions/mod.rs index 7d195243..5363f389 100644 --- a/src/api/definitions/mod.rs +++ b/src/api/definitions/mod.rs @@ -4,11 +4,11 @@ use crate::module::FuncInfo; use crate::plugin::*; use crate::tokenizer::is_valid_function_name; -use crate::{Engine, Module, Scope}; +use crate::{Engine, Module, Scope, INT}; #[cfg(feature = "no_std")] use std::prelude::v1::*; -use std::{borrow::Cow, cmp::Ordering, fmt}; +use std::{any::type_name, borrow::Cow, cmp::Ordering, fmt}; impl Engine { /// Return [`Definitions`] that can be used to generate definition files for the [`Engine`]. @@ -345,13 +345,19 @@ fn def_type_name<'a>(ty: &'a str, engine: &'a Engine) -> Cow<'a, str> { .map(str::trim) .unwrap_or(ty); - ty.replace("Iterator(), "int") .replace("FLOAT", "float") .replace("&str", "String") - .replace("ImmutableString", "String") - .into() + .replace("ImmutableString", "String"); + + #[cfg(not(feature = "no_float"))] + let ty = ty.replace(type_name::(), "float"); + + ty.into() } impl Scope<'_> {