From 6b0f49970ae59cf8cd42f56c1052f5bee6331b99 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Mon, 17 Jun 2024 12:25:46 -0400 Subject: [PATCH] xo-expression: ++ example to build primitive --- example/ex1/ex1.cpp | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/example/ex1/ex1.cpp b/example/ex1/ex1.cpp index 19dddc82..5c12a4b1 100644 --- a/example/ex1/ex1.cpp +++ b/example/ex1/ex1.cpp @@ -1,14 +1,34 @@ /** @file ex1.cpp **/ #include "xo/expression/Constant.hpp" +#include "xo/expression/Primitive.hpp" #include +#include int main() { using xo::ast::make_constant; + using xo::ast::make_primitive; + using std::cout; + using std::endl; - auto expr = make_constant(7); + { + auto expr = make_constant(7); + } + + { + auto expr = make_primitive("sqrt", &::sqrt); + + auto expr_td = expr->value_td(); + + cout << "expr_td: " << expr_td->short_name() << endl; + cout << "expr_td->is_function(): " << expr_td->is_function() << endl; + cout << "expr_td->fn_retval(): " << expr_td->fn_retval()->short_name() << endl; + cout << "expr_td->n_fn_arg(): " << expr_td->n_fn_arg() << endl; + for (uint32_t i = 0; i < expr_td->n_fn_arg(); ++i) + cout << "expr_td->fn_arg(" << i << "): " << expr_td->fn_arg(i)->short_name() << endl; + cout << "expr_td->fn_is_noexcept(): " << expr_td->fn_is_noexcept() << endl; + } } - /** end ex1.cpp **/