Gate i128/u128 for wasm32 target.

This commit is contained in:
Stephen Chung 2020-06-17 16:50:46 +08:00
parent e095a87ea2
commit ae6d5e13a9
8 changed files with 127 additions and 41 deletions

View File

@ -275,27 +275,51 @@ def_package!(crate:ArithmeticPackage:"Basic arithmetic", lib, {
#[cfg(not(feature = "unchecked"))]
{
// Checked basic arithmetic
reg_op!(lib, "+", add, i8, u8, i16, u16, i32, u32, u64, i128, u128);
reg_op!(lib, "-", sub, i8, u8, i16, u16, i32, u32, u64, i128, u128);
reg_op!(lib, "*", mul, i8, u8, i16, u16, i32, u32, u64, i128, u128);
reg_op!(lib, "/", div, i8, u8, i16, u16, i32, u32, u64, i128, u128);
reg_op!(lib, "+", add, i8, u8, i16, u16, i32, u32, u64);
reg_op!(lib, "-", sub, i8, u8, i16, u16, i32, u32, u64);
reg_op!(lib, "*", mul, i8, u8, i16, u16, i32, u32, u64);
reg_op!(lib, "/", div, i8, u8, i16, u16, i32, u32, u64);
// Checked bit shifts
reg_op!(lib, "<<", shl, i8, u8, i16, u16, i32, u32, u64, i128, u128);
reg_op!(lib, ">>", shr, i8, u8, i16, u16, i32, u32, u64, i128, u128);
reg_op!(lib, "%", modulo, i8, u8, i16, u16, i32, u32, u64, i128, u128);
reg_op!(lib, "<<", shl, i8, u8, i16, u16, i32, u32, u64);
reg_op!(lib, ">>", shr, i8, u8, i16, u16, i32, u32, u64);
reg_op!(lib, "%", modulo, i8, u8, i16, u16, i32, u32, u64);
#[cfg(not(target_arch = "wasm32"))]
{
reg_op!(lib, "+", add, i128, u128);
reg_op!(lib, "-", sub, i128, u128);
reg_op!(lib, "*", mul, i128, u128);
reg_op!(lib, "/", div, i128, u128);
// Checked bit shifts
reg_op!(lib, "<<", shl, i128, u128);
reg_op!(lib, ">>", shr, i128, u128);
reg_op!(lib, "%", modulo, i128, u128);
}
}
#[cfg(feature = "unchecked")]
{
// Unchecked basic arithmetic
reg_op!(lib, "+", add_u, i8, u8, i16, u16, i32, u32, u64, i128, u128);
reg_op!(lib, "-", sub_u, i8, u8, i16, u16, i32, u32, u64, i128, u128);
reg_op!(lib, "*", mul_u, i8, u8, i16, u16, i32, u32, u64, i128, u128);
reg_op!(lib, "/", div_u, i8, u8, i16, u16, i32, u32, u64, i128, u128);
reg_op!(lib, "+", add_u, i8, u8, i16, u16, i32, u32, u64);
reg_op!(lib, "-", sub_u, i8, u8, i16, u16, i32, u32, u64);
reg_op!(lib, "*", mul_u, i8, u8, i16, u16, i32, u32, u64);
reg_op!(lib, "/", div_u, i8, u8, i16, u16, i32, u32, u64);
// Unchecked bit shifts
reg_op!(lib, "<<", shl_u, i64, i8, u8, i16, u16, i32, u32, u64, i128, u128);
reg_op!(lib, ">>", shr_u, i64, i8, u8, i16, u16, i32, u32, u64, i128, u128);
reg_op!(lib, "%", modulo_u, i8, u8, i16, u16, i32, u32, u64, i128, u128);
reg_op!(lib, "<<", shl_u, i64, i8, u8, i16, u16, i32, u32, u64);
reg_op!(lib, ">>", shr_u, i64, i8, u8, i16, u16, i32, u32, u64);
reg_op!(lib, "%", modulo_u, i8, u8, i16, u16, i32, u32, u64);
#[cfg(not(target_arch = "wasm32"))]
{
reg_op!(lib, "+", add_u, i128, u128);
reg_op!(lib, "-", sub_u, i128, u128);
reg_op!(lib, "*", mul_u, i128, u128);
reg_op!(lib, "/", div_u, i128, u128);
// Unchecked bit shifts
reg_op!(lib, "<<", shl_u, i128, u128);
reg_op!(lib, ">>", shr_u, i128, u128);
reg_op!(lib, "%", modulo_u, i128, u128);
}
}
}
@ -311,9 +335,16 @@ def_package!(crate:ArithmeticPackage:"Basic arithmetic", lib, {
#[cfg(not(feature = "only_i32"))]
#[cfg(not(feature = "only_i64"))]
{
reg_op!(lib, "|", binary_or, i8, u8, i16, u16, i32, u32, u64, i128, u128);
reg_op!(lib, "&", binary_and, i8, u8, i16, u16, i32, u32, u64, i128, u128);
reg_op!(lib, "^", binary_xor, i8, u8, i16, u16, i32, u32, u64, i128, u128);
reg_op!(lib, "|", binary_or, i8, u8, i16, u16, i32, u32, u64);
reg_op!(lib, "&", binary_and, i8, u8, i16, u16, i32, u32, u64);
reg_op!(lib, "^", binary_xor, i8, u8, i16, u16, i32, u32, u64);
#[cfg(not(target_arch = "wasm32"))]
{
reg_op!(lib, "|", binary_or, i128, u128);
reg_op!(lib, "&", binary_and, i128, u128);
reg_op!(lib, "^", binary_xor, i128, u128);
}
}
#[cfg(not(feature = "no_float"))]
@ -343,8 +374,14 @@ def_package!(crate:ArithmeticPackage:"Basic arithmetic", lib, {
#[cfg(not(feature = "only_i32"))]
#[cfg(not(feature = "only_i64"))]
{
reg_unary!(lib, "-", neg, i8, i16, i32, i64, i128);
reg_unary!(lib, "abs", abs, i8, i16, i32, i64, i128);
reg_unary!(lib, "-", neg, i8, i16, i32, i64);
reg_unary!(lib, "abs", abs, i8, i16, i32, i64);
#[cfg(not(target_arch = "wasm32"))]
{
reg_unary!(lib, "-", neg, i128);
reg_unary!(lib, "abs", abs, i128);
}
}
}
@ -357,8 +394,14 @@ def_package!(crate:ArithmeticPackage:"Basic arithmetic", lib, {
#[cfg(not(feature = "only_i32"))]
#[cfg(not(feature = "only_i64"))]
{
reg_unary!(lib, "-", neg_u, i8, i16, i32, i64, i128);
reg_unary!(lib, "abs", abs_u, i8, i16, i32, i64, i128);
reg_unary!(lib, "-", neg_u, i8, i16, i32, i64);
reg_unary!(lib, "abs", abs_u, i8, i16, i32, i64);
#[cfg(not(target_arch = "wasm32"))]
{
reg_unary!(lib, "-", neg_u, i128);
reg_unary!(lib, "abs", abs_u, i128);
}
}
}
});

View File

@ -98,9 +98,16 @@ def_package!(crate:BasicArrayPackage:"Basic array utilities.", lib, {
#[cfg(not(feature = "only_i32"))]
#[cfg(not(feature = "only_i64"))]
{
reg_op!(lib, "push", push, i8, u8, i16, u16, i32, i64, u32, u64, i128, u128);
reg_pad!(lib, "pad", pad, i8, u8, i16, u16, i32, u32, i64, u64, i128, u128);
reg_tri!(lib, "insert", ins, i8, u8, i16, u16, i32, i64, u32, u64, i128, u128);
reg_op!(lib, "push", push, i8, u8, i16, u16, i32, i64, u32, u64);
reg_pad!(lib, "pad", pad, i8, u8, i16, u16, i32, u32, i64, u64);
reg_tri!(lib, "insert", ins, i8, u8, i16, u16, i32, i64, u32, u64);
#[cfg(not(target_arch = "wasm32"))]
{
reg_op!(lib, "push", push, i128, u128);
reg_pad!(lib, "pad", pad, i128, u128);
reg_tri!(lib, "insert", ins, i128, u128);
}
}
#[cfg(not(feature = "no_float"))]

View File

@ -85,7 +85,10 @@ def_package!(crate:BasicIteratorPackage:"Basic range iterators.", lib, {
)
}
reg_range!(lib, "range", i8, u8, i16, u16, i32, i64, u32, u64, i128, u128);
reg_range!(lib, "range", i8, u8, i16, u16, i32, i64, u32, u64);
#[cfg(not(target_arch = "wasm32"))]
reg_range!(lib, "range", i128, u128);
}
reg_step::<INT>(lib);
@ -103,6 +106,9 @@ def_package!(crate:BasicIteratorPackage:"Basic range iterators.", lib, {
)
}
reg_step!(lib, "range", i8, u8, i16, u16, i32, i64, u32, u64, i128, u128);
reg_step!(lib, "range", i8, u8, i16, u16, i32, i64, u32, u64);
#[cfg(not(target_arch = "wasm32"))]
reg_step!(lib, "range", i128, u128);
}
});

View File

@ -36,12 +36,22 @@ def_package!(crate:LogicPackage:"Logical operators.", lib, {
#[cfg(not(feature = "only_i32"))]
#[cfg(not(feature = "only_i64"))]
{
reg_op!(lib, "<", lt, i8, u8, i16, u16, i32, u32, u64, i128, u128);
reg_op!(lib, "<=", lte, i8, u8, i16, u16, i32, u32, u64, i128, u128);
reg_op!(lib, ">", gt, i8, u8, i16, u16, i32, u32, u64, i128, u128);
reg_op!(lib, ">=", gte, i8, u8, i16, u16, i32, u32, u64, i128, u128);
reg_op!(lib, "==", eq, i8, u8, i16, u16, i32, u32, u64, i128, u128);
reg_op!(lib, "!=", ne, i8, u8, i16, u16, i32, u32, u64, i128, u128);
reg_op!(lib, "<", lt, i8, u8, i16, u16, i32, u32, u64);
reg_op!(lib, "<=", lte, i8, u8, i16, u16, i32, u32, u64);
reg_op!(lib, ">", gt, i8, u8, i16, u16, i32, u32, u64);
reg_op!(lib, ">=", gte, i8, u8, i16, u16, i32, u32, u64);
reg_op!(lib, "==", eq, i8, u8, i16, u16, i32, u32, u64);
reg_op!(lib, "!=", ne, i8, u8, i16, u16, i32, u32, u64);
#[cfg(not(target_arch = "wasm32"))]
{
reg_op!(lib, "<", lt, i128, u128);
reg_op!(lib, "<=", lte, i128, u128);
reg_op!(lib, ">", gt, i128, u128);
reg_op!(lib, ">=", gte, i128, u128);
reg_op!(lib, "==", eq, i128, u128);
reg_op!(lib, "!=", ne, i128, u128);
}
}
#[cfg(not(feature = "no_float"))]

View File

@ -70,10 +70,14 @@ def_package!(crate:BasicMathPackage:"Basic mathematic functions.", lib, {
lib.set_fn_1("to_float", |x: u32| Ok(x as FLOAT));
lib.set_fn_1("to_float", |x: i64| Ok(x as FLOAT));
lib.set_fn_1("to_float", |x: u64| Ok(x as FLOAT));
#[cfg(not(target_arch = "wasm32"))]
{
lib.set_fn_1("to_float", |x: i128| Ok(x as FLOAT));
lib.set_fn_1("to_float", |x: u128| Ok(x as FLOAT));
}
}
}
lib.set_fn_1("to_int", |ch: char| Ok(ch as INT));

View File

@ -52,9 +52,16 @@ def_package!(crate:BasicStringPackage:"Basic string utilities, including printin
reg_op!(lib, KEYWORD_PRINT, to_string, i8, u8, i16, u16, i32, u32);
reg_op!(lib, FUNC_TO_STRING, to_string, i8, u8, i16, u16, i32, u32);
reg_op!(lib, KEYWORD_DEBUG, to_debug, i8, u8, i16, u16, i32, u32);
reg_op!(lib, KEYWORD_PRINT, to_string, i64, u64, i128, u128);
reg_op!(lib, FUNC_TO_STRING, to_string, i64, u64, i128, u128);
reg_op!(lib, KEYWORD_DEBUG, to_debug, i64, u64, i128, u128);
reg_op!(lib, KEYWORD_PRINT, to_string, i64, u64);
reg_op!(lib, FUNC_TO_STRING, to_string, i64, u64);
reg_op!(lib, KEYWORD_DEBUG, to_debug, i64, u64);
#[cfg(not(target_arch = "wasm32"))]
{
reg_op!(lib, KEYWORD_PRINT, to_string, i128, u128);
reg_op!(lib, FUNC_TO_STRING, to_string, i128, u128);
reg_op!(lib, KEYWORD_DEBUG, to_debug, i128, u128);
}
}
#[cfg(not(feature = "no_float"))]

View File

@ -95,8 +95,14 @@ def_package!(crate:MoreStringPackage:"Additional string utilities, including str
#[cfg(not(feature = "only_i32"))]
#[cfg(not(feature = "only_i64"))]
{
reg_op!(lib, "+", append, i8, u8, i16, u16, i32, i64, u32, u64, i128, u128);
reg_op!(lib, "+", prepend, i8, u8, i16, u16, i32, i64, u32, u64, i128, u128);
reg_op!(lib, "+", append, i8, u8, i16, u16, i32, i64, u32, u64);
reg_op!(lib, "+", prepend, i8, u8, i16, u16, i32, i64, u32, u64);
#[cfg(not(target_arch = "wasm32"))]
{
reg_op!(lib, "+", append, i128, u128);
reg_op!(lib, "+", prepend, i128, u128);
}
}
#[cfg(not(feature = "no_float"))]

View File

@ -4,10 +4,13 @@
mod inner {
pub use core::{
any, arch, array, ascii, cell, char, clone, cmp, convert, default, f32, f64, ffi, fmt,
future, hash, hint, i128, i16, i32, i64, i8, isize, iter, marker, mem, num, ops, option,
panic, pin, prelude, ptr, result, slice, str, task, time, u128, u16, u32, u64, u8, usize,
future, hash, hint, i16, i32, i64, i8, isize, iter, marker, mem, num, ops, option, panic,
pin, prelude, ptr, result, slice, str, task, time, u16, u32, u64, u8, usize,
};
#[cfg(not(target_arch = "wasm32"))]
pub use core::{i128, u128};
pub use alloc::{borrow, boxed, format, rc, string, sync, vec};
pub use core_error as error;