Fix bug in built-in string operators.

This commit is contained in:
Stephen Chung 2021-03-05 20:06:49 +08:00
parent 8f0830af1c
commit 4e5039d4fe

View File

@ -118,6 +118,13 @@ pub fn get_builtin_binary_op_fn(
$func(x, y)
})
};
($base:ty => $op:tt) => {
return Some(|_, args| {
let x = &*args[0].read_lock::<$base>().unwrap();
let y = &*args[1].read_lock::<$base>().unwrap();
Ok((x $op y).into())
})
};
}
macro_rules! impl_float {
@ -327,26 +334,14 @@ pub fn get_builtin_binary_op_fn(
if type1 == TypeId::of::<ImmutableString>() {
match op {
"+" => {
return Some(|_, args| {
let x = &*args[0].read_lock::<ImmutableString>().unwrap();
let y = &*args[1].read_lock::<ImmutableString>().unwrap();
Ok((x + y).into())
})
}
"-" => {
return Some(|_, args| {
let x = &*args[0].read_lock::<ImmutableString>().unwrap();
let y = &*args[1].read_lock::<ImmutableString>().unwrap();
Ok((x - y).into())
})
}
"==" => impl_op!(&str => as_str == as_str),
"!=" => impl_op!(&str => as_str != as_str),
">" => impl_op!(&str => as_str > as_str),
">=" => impl_op!(&str => as_str >= as_str),
"<" => impl_op!(&str => as_str < as_str),
"<=" => impl_op!(&str => as_str <= as_str),
"+" => impl_op!(ImmutableString => +),
"-" => impl_op!(ImmutableString => -),
"==" => impl_op!(ImmutableString => ==),
"!=" => impl_op!(ImmutableString => !=),
">" => impl_op!(ImmutableString => >),
">=" => impl_op!(ImmutableString => >=),
"<" => impl_op!(ImmutableString => <),
"<=" => impl_op!(ImmutableString => <=),
_ => return None,
}
}