xo-reader: integer arithmetic + parser + pretty-printing adds
This commit is contained in:
parent
10cb2462f3
commit
c06df5ccb5
6 changed files with 165 additions and 4 deletions
|
|
@ -30,6 +30,8 @@ namespace xo {
|
|||
return new Apply(fn_retval_type, fn, argv);
|
||||
}
|
||||
|
||||
// ----- integer comparison -----
|
||||
|
||||
rp<Apply>
|
||||
Apply::make_cmp_eq_i64(const rp<Expression> & lhs,
|
||||
const rp<Expression> & rhs)
|
||||
|
|
@ -46,6 +48,42 @@ namespace xo {
|
|||
{lhs, rhs});
|
||||
}
|
||||
|
||||
// ----- integer arithmetic -----
|
||||
|
||||
rp<Apply>
|
||||
Apply::make_add2_i64(const rp<Expression> & lhs,
|
||||
const rp<Expression> & rhs)
|
||||
{
|
||||
return Apply::make(Primitive_i64::make_add2_i64(),
|
||||
{lhs, rhs});
|
||||
}
|
||||
|
||||
rp<Apply>
|
||||
Apply::make_sub2_i64(const rp<Expression> & lhs,
|
||||
const rp<Expression> & rhs)
|
||||
{
|
||||
return Apply::make(Primitive_i64::make_sub2_i64(),
|
||||
{lhs, rhs});
|
||||
}
|
||||
|
||||
rp<Apply>
|
||||
Apply::make_mul2_i64(const rp<Expression> & lhs,
|
||||
const rp<Expression> & rhs)
|
||||
{
|
||||
return Apply::make(Primitive_i64::make_mul2_i64(),
|
||||
{lhs, rhs});
|
||||
}
|
||||
|
||||
rp<Apply>
|
||||
Apply::make_div2_i64(const rp<Expression> & lhs,
|
||||
const rp<Expression> & rhs)
|
||||
{
|
||||
return Apply::make(Primitive_i64::make_div2_i64(),
|
||||
{lhs, rhs});
|
||||
}
|
||||
|
||||
// ----- floating point arithmetic -----
|
||||
|
||||
rp<Apply>
|
||||
Apply::make_add2_f64(const rp<Expression> & lhs,
|
||||
const rp<Expression> & rhs)
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
* author: Roland Conybeare, Jul 2025
|
||||
*/
|
||||
|
||||
#include "xo/indentlog/print/ppdetail_atomic.hpp"
|
||||
#include "GlobalEnv.hpp"
|
||||
#include "Expression.hpp"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,17 @@
|
|||
/* @file Primitive.cpp */
|
||||
|
||||
#include "Primitive.hpp"
|
||||
#include <cstdint>
|
||||
|
||||
extern "C" {
|
||||
/** code here is used in two context:
|
||||
* 1. Fallback implementation under llvm.
|
||||
* In practice will use llvm intrinsic instead.
|
||||
* See xo-jit/src/jit/MachPipeline.cpp
|
||||
* 2. Schematika interpreter (aspirational asof jul 2025)
|
||||
*
|
||||
**/
|
||||
|
||||
bool
|
||||
cmp_eq2_i64(std::int64_t x, std::int64_t y) {
|
||||
return x == y;
|
||||
|
|
@ -13,6 +22,26 @@ extern "C" {
|
|||
return x != y;
|
||||
}
|
||||
|
||||
std::int64_t
|
||||
add2_i64(std::int64_t x, std::int64_t y) {
|
||||
return x + y;
|
||||
}
|
||||
|
||||
std::int64_t
|
||||
sub2_i64(std::int64_t x, std::int64_t y) {
|
||||
return x - y;
|
||||
}
|
||||
|
||||
std::int64_t
|
||||
mul2_i64(std::int64_t x, std::int64_t y) {
|
||||
return x * y;
|
||||
}
|
||||
|
||||
std::int64_t
|
||||
div2_i64(std::int64_t x, std::int64_t y) {
|
||||
return x / y;
|
||||
}
|
||||
|
||||
double
|
||||
add2_f64(double x, double y) {
|
||||
return x + y;
|
||||
|
|
@ -64,6 +93,65 @@ namespace xo {
|
|||
return s_retval;
|
||||
}
|
||||
|
||||
/* TODO: remaining integer arithmetic */
|
||||
|
||||
auto
|
||||
Primitive_i64::make_add2_i64() -> rp<PrimitiveType>
|
||||
{
|
||||
static rp<PrimitiveType> s_retval;
|
||||
|
||||
if (!s_retval)
|
||||
s_retval = Primitive::make("add2_i64",
|
||||
&add2_i64,
|
||||
true /*explicit_symbol_def*/,
|
||||
llvmintrinsic::i_add);
|
||||
|
||||
return s_retval;
|
||||
}
|
||||
|
||||
auto
|
||||
Primitive_i64::make_sub2_i64() -> rp<PrimitiveType>
|
||||
{
|
||||
static rp<PrimitiveType> s_retval;
|
||||
|
||||
if (!s_retval)
|
||||
s_retval = Primitive::make("sub2_i64",
|
||||
&sub2_i64,
|
||||
true /*explicit_symbol_def*/,
|
||||
llvmintrinsic::i_sub);
|
||||
|
||||
return s_retval;
|
||||
}
|
||||
|
||||
auto
|
||||
Primitive_i64::make_mul2_i64() -> rp<PrimitiveType>
|
||||
{
|
||||
static rp<PrimitiveType> s_retval;
|
||||
|
||||
if (!s_retval)
|
||||
s_retval = Primitive::make("mul2_i64",
|
||||
&mul2_i64,
|
||||
true /*explicit_symbol_def*/,
|
||||
llvmintrinsic::i_mul);
|
||||
|
||||
return s_retval;
|
||||
}
|
||||
|
||||
auto
|
||||
Primitive_i64::make_div2_i64() -> rp<PrimitiveType>
|
||||
{
|
||||
static rp<PrimitiveType> s_retval;
|
||||
|
||||
if (!s_retval)
|
||||
s_retval = Primitive::make("div2_i64",
|
||||
&div2_i64,
|
||||
true /*explicit_symbol+def*/,
|
||||
llvmintrinsic::i_sdiv);
|
||||
return s_retval;
|
||||
}
|
||||
|
||||
// ----- floating-point arithmetic -----
|
||||
|
||||
auto
|
||||
Primitive_f64::make_add2_f64() -> rp<PrimitiveType>
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue