xo-expression xo-reader: integer comparisons !=, <, >

This commit is contained in:
Roland Conybeare 2025-07-27 14:32:31 -04:00
commit b811e34090
6 changed files with 101 additions and 1 deletions

View file

@ -34,6 +34,12 @@ namespace xo {
/** create apply-expression to compare two 64-bit integers **/
static rp<Apply> make_cmp_ne_i64(const rp<Expression> & lhs,
const rp<Expression> & rhs);
/** create apply-expression for less-than comparison of two 64-bit integers **/
static rp<Apply> make_cmp_lt_i64(const rp<Expression> & lhs,
const rp<Expression> & rhs);
/** create apply-expression for greater-than comparison of two 64-bit integers **/
static rp<Apply> make_cmp_gt_i64(const rp<Expression> & lhs,
const rp<Expression> & rhs);
/** create apply-expression to add two 64-bit integers **/
static rp<Apply> make_add2_i64(const rp<Expression> & lhs,

View file

@ -204,6 +204,10 @@ namespace xo {
static rp<PrimitiveType> make_cmp_eq2_i64();
/** ne2_i64: compare two 64-bit integers for inequality **/
static rp<PrimitiveType> make_cmp_ne2_i64();
/** lt2_i64: compare two 64-bit integers for lessthan **/
static rp<PrimitiveType> make_cmp_lt2_i64();
/** gt2_i64: compare two 64-bit integers for greaterthan **/
static rp<PrimitiveType> make_cmp_gt2_i64();
};
/** builtin primitives :: i64 x i64 -> i64 **/

View file

@ -48,6 +48,22 @@ namespace xo {
{lhs, rhs});
}
rp<Apply>
Apply::make_cmp_lt_i64(const rp<Expression> & lhs,
const rp<Expression> & rhs)
{
return Apply::make(Primitive_cmp_i64::make_cmp_lt2_i64(),
{lhs, rhs});
}
rp<Apply>
Apply::make_cmp_gt_i64(const rp<Expression> & lhs,
const rp<Expression> & rhs)
{
return Apply::make(Primitive_cmp_i64::make_cmp_gt2_i64(),
{lhs, rhs});
}
// ----- integer arithmetic -----
rp<Apply>

View file

@ -22,6 +22,16 @@ extern "C" {
return x != y;
}
bool
cmp_lt2_i64(std::int64_t x, std::int64_t y) {
return x < y;
}
bool
cmp_gt2_i64(std::int64_t x, std::int64_t y) {
return x > y;
}
std::int64_t
add2_i64(std::int64_t x, std::int64_t y) {
return x + y;
@ -93,6 +103,34 @@ namespace xo {
return s_retval;
}
auto
Primitive_cmp_i64::make_cmp_lt2_i64() -> rp<PrimitiveType>
{
static rp<PrimitiveType> s_retval;
if (!s_retval)
s_retval = Primitive::make("cmp_lt2_i64",
&cmp_lt2_i64,
true /*explicit_symbol_def*/,
llvmintrinsic::i_slt);
return s_retval;
}
auto
Primitive_cmp_i64::make_cmp_gt2_i64() -> rp<PrimitiveType>
{
static rp<PrimitiveType> s_retval;
if (!s_retval)
s_retval = Primitive::make("cmp_gt2_i64",
&cmp_gt2_i64,
true /*explicit_symbol_def*/,
llvmintrinsic::i_sgt);
return s_retval;
}
/* TODO: remaining integer arithmetic */
auto