xo-reader: integer arithmetic + parser + pretty-printing adds

This commit is contained in:
Roland Conybeare 2025-07-27 13:35:20 -04:00
commit 8d5a9c825f
25 changed files with 408 additions and 26 deletions

View file

@ -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>
{