Complete ImmutableString.

This commit is contained in:
Stephen Chung
2020-05-26 14:14:03 +08:00
parent 95e67c48bd
commit b34d5fe3a1
15 changed files with 379 additions and 274 deletions

View File

@@ -1,6 +1,5 @@
use crate::def_package;
use crate::module::FuncReturn;
use crate::parser::{ImmutableString, INT};
// Comparison operators
pub fn lt<T: PartialOrd>(x: T, y: T) -> FuncReturn<bool> {
@@ -23,12 +22,6 @@ pub fn ne<T: PartialEq>(x: T, y: T) -> FuncReturn<bool> {
}
// Logic operators
fn and(x: bool, y: bool) -> FuncReturn<bool> {
Ok(x && y)
}
fn or(x: bool, y: bool) -> FuncReturn<bool> {
Ok(x || y)
}
fn not(x: bool) -> FuncReturn<bool> {
Ok(!x)
}
@@ -40,30 +33,9 @@ macro_rules! reg_op {
}
def_package!(crate:LogicPackage:"Logical operators.", lib, {
// reg_op!(lib, "<", lt, INT, char);
// reg_op!(lib, "<=", lte, INT, char);
// reg_op!(lib, ">", gt, INT, char);
// reg_op!(lib, ">=", gte, INT, char);
// reg_op!(lib, "==", eq, INT, char, bool, ());
// reg_op!(lib, "!=", ne, INT, char, bool, ());
// Special versions for strings - at least avoid copying the first string
// lib.set_fn_2("<", |x: ImmutableString, y: ImmutableString| Ok(*x < y));
// lib.set_fn_2("<=", |x: ImmutableString, y: ImmutableString| Ok(*x <= y));
// lib.set_fn_2(">", |x: ImmutableString, y: ImmutableString| Ok(*x > y));
// lib.set_fn_2(">=", |x: ImmutableString, y: ImmutableString| Ok(*x >= y));
// lib.set_fn_2("==", |x: ImmutableString, y: ImmutableString| Ok(*x == y));
// lib.set_fn_2("!=", |x: ImmutableString, y: ImmutableString| Ok(*x != y));
#[cfg(not(feature = "only_i32"))]
#[cfg(not(feature = "only_i64"))]
{
// reg_op!(lib, "<", lt, i8, u8, i16, u16, i32, i64, u32, u64, i128, u128);
// reg_op!(lib, "<=", lte, i8, u8, i16, u16, i32, i64, u32, u64, i128, u128);
// reg_op!(lib, ">", gt, i8, u8, i16, u16, i32, i64, u32, u64, i128, u128);
// reg_op!(lib, ">=", gte, i8, u8, i16, u16, i32, i64, u32, u64, i128, u128);
// reg_op!(lib, "==", eq, i8, u8, i16, u16, i32, i64, u32, u64, i128, u128);
// reg_op!(lib, "!=", ne, i8, u8, i16, u16, i32, i64, u32, u64, i128, u128);
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);
@@ -74,12 +46,6 @@ def_package!(crate:LogicPackage:"Logical operators.", lib, {
#[cfg(not(feature = "no_float"))]
{
// reg_op!(lib, "<", lt, f32, f64);
// reg_op!(lib, "<=", lte, f32, f64);
// reg_op!(lib, ">", gt, f32, f64);
// reg_op!(lib, ">=", gte, f32, f64);
// reg_op!(lib, "==", eq, f32, f64);
// reg_op!(lib, "!=", ne, f32, f64);
reg_op!(lib, "<", lt, f32);
reg_op!(lib, "<=", lte, f32);
reg_op!(lib, ">", gt, f32);
@@ -88,12 +54,5 @@ def_package!(crate:LogicPackage:"Logical operators.", lib, {
reg_op!(lib, "!=", ne, f32);
}
// `&&` and `||` are treated specially as they short-circuit.
// They are implemented as special `Expr` instances, not function calls.
//reg_op!(lib, "||", or, bool);
//reg_op!(lib, "&&", and, bool);
// lib.set_fn_2("|", or);
// lib.set_fn_2("&", and);
lib.set_fn_1("!", not);
});