@@ -74,6 +74,11 @@ enum class IntrinsicFunctions : int64_t {
74
74
SymbolicInteger,
75
75
SymbolicDiff,
76
76
SymbolicExpand,
77
+ SymbolicSin,
78
+ SymbolicCos,
79
+ SymbolicLog,
80
+ SymbolicExp,
81
+ SymbolicAbs,
77
82
Sum,
78
83
// ...
79
84
};
@@ -2169,45 +2174,52 @@ namespace SymbolicInteger {
2169
2174
}
2170
2175
} // namespace SymbolicInteger
2171
2176
2172
- namespace SymbolicExpand {
2173
-
2174
- static inline void verify_args (const ASR::IntrinsicFunction_t& x, diag::Diagnostics& diagnostics) {
2175
- const Location& loc = x.base .base .loc ;
2176
- ASRUtils::require_impl (x.n_args == 1 ,
2177
- " SymbolicExpand must have exactly 1 input argument" ,
2178
- loc, diagnostics);
2179
-
2180
- ASR::ttype_t * input_type = ASRUtils::expr_type (x.m_args [0 ]);
2181
- ASRUtils::require_impl (ASR::is_a<ASR::SymbolicExpression_t>(*input_type),
2182
- " SymbolicExpand expects an argument of type SymbolicExpression" ,
2183
- x.base .base .loc , diagnostics);
2184
- }
2185
-
2186
- static inline ASR::expr_t *eval_SymbolicExpand (Allocator &/* al*/ ,
2187
- const Location &/* loc*/ , Vec<ASR::expr_t *>& /* args*/ ) {
2188
- // TODO
2189
- return nullptr ;
2190
- }
2191
-
2192
- static inline ASR::asr_t * create_SymbolicExpand (Allocator& al, const Location& loc,
2193
- Vec<ASR::expr_t *>& args,
2194
- const std::function<void (const std::string &, const Location &)> err) {
2195
- if (args.size () != 1 ) {
2196
- err (" Intrinsic expand function accepts exactly 1 argument" , loc);
2197
- }
2198
-
2199
- ASR::ttype_t * argtype = ASRUtils::expr_type (args[0 ]);
2200
- if (!ASR::is_a<ASR::SymbolicExpression_t>(*argtype)) {
2201
- err (" Argument of SymbolicExpand function must be of type SymbolicExpression" ,
2202
- args[0 ]->base .loc );
2203
- }
2204
-
2205
- ASR::ttype_t *to_type = ASRUtils::TYPE (ASR::make_SymbolicExpression_t (al, loc));
2206
- return UnaryIntrinsicFunction::create_UnaryFunction (al, loc, args, eval_SymbolicExpand,
2207
- static_cast <int64_t >(ASRUtils::IntrinsicFunctions::SymbolicExpand), 0 , to_type);
2208
- }
2177
+ #define create_symbolic_unary_macro (X ) \
2178
+ namespace X { \
2179
+ \
2180
+ static inline void verify_args (const ASR::IntrinsicFunction_t& x, \
2181
+ diag::Diagnostics& diagnostics) { \
2182
+ const Location& loc = x.base .base .loc ; \
2183
+ ASRUtils::require_impl (x.n_args == 1 , \
2184
+ #X " must have exactly 1 input argument" , loc, diagnostics); \
2185
+ \
2186
+ ASR::ttype_t * input_type = ASRUtils::expr_type (x.m_args [0 ]); \
2187
+ ASRUtils::require_impl (ASR::is_a<ASR::SymbolicExpression_t>(*input_type), \
2188
+ #X " expects an argument of type SymbolicExpression" , loc, diagnostics); \
2189
+ } \
2190
+ \
2191
+ static inline ASR::expr_t * eval_##X(Allocator &/* al*/ , const Location &/* loc*/ , \
2192
+ Vec<ASR::expr_t *> &/* args*/ ) { \
2193
+ /* TODO*/ \
2194
+ return nullptr ; \
2195
+ } \
2196
+ \
2197
+ static inline ASR::asr_t * create_##X(Allocator& al, const Location& loc, \
2198
+ Vec<ASR::expr_t *>& args, \
2199
+ const std::function<void (const std::string &, const Location &)> err) { \
2200
+ if (args.size () != 1 ) { \
2201
+ err (" Intrinsic " #X " function accepts exactly 1 argument" , loc); \
2202
+ } \
2203
+ \
2204
+ ASR::ttype_t * argtype = ASRUtils::expr_type (args[0 ]); \
2205
+ if (!ASR::is_a<ASR::SymbolicExpression_t>(*argtype)) { \
2206
+ err (" Argument of " #X " function must be of type SymbolicExpression" , \
2207
+ args[0 ]->base .loc ); \
2208
+ } \
2209
+ \
2210
+ ASR::ttype_t *to_type = ASRUtils::TYPE (ASR::make_SymbolicExpression_t (al, loc)); \
2211
+ return UnaryIntrinsicFunction::create_UnaryFunction (al, loc, args, eval_##X, \
2212
+ static_cast <int64_t >(ASRUtils::IntrinsicFunctions::X), 0 , to_type); \
2213
+ } \
2214
+ \
2215
+ } // namespace X
2209
2216
2210
- } // namespace SymbolicExpand
2217
+ create_symbolic_unary_macro (SymbolicSin)
2218
+ create_symbolic_unary_macro(SymbolicCos)
2219
+ create_symbolic_unary_macro(SymbolicLog)
2220
+ create_symbolic_unary_macro(SymbolicExp)
2221
+ create_symbolic_unary_macro(SymbolicAbs)
2222
+ create_symbolic_unary_macro(SymbolicExpand)
2211
2223
2212
2224
namespace IntrinsicFunctionRegistry {
2213
2225
@@ -2275,6 +2287,16 @@ namespace IntrinsicFunctionRegistry {
2275
2287
{nullptr , &SymbolicDiff::verify_args}},
2276
2288
{static_cast <int64_t >(ASRUtils::IntrinsicFunctions::SymbolicExpand),
2277
2289
{nullptr , &SymbolicExpand::verify_args}},
2290
+ {static_cast <int64_t >(ASRUtils::IntrinsicFunctions::SymbolicSin),
2291
+ {nullptr , &SymbolicSin::verify_args}},
2292
+ {static_cast <int64_t >(ASRUtils::IntrinsicFunctions::SymbolicCos),
2293
+ {nullptr , &SymbolicCos::verify_args}},
2294
+ {static_cast <int64_t >(ASRUtils::IntrinsicFunctions::SymbolicLog),
2295
+ {nullptr , &SymbolicLog::verify_args}},
2296
+ {static_cast <int64_t >(ASRUtils::IntrinsicFunctions::SymbolicExp),
2297
+ {nullptr , &SymbolicExp::verify_args}},
2298
+ {static_cast <int64_t >(ASRUtils::IntrinsicFunctions::SymbolicAbs),
2299
+ {nullptr , &SymbolicAbs::verify_args}},
2278
2300
};
2279
2301
2280
2302
static const std::map<int64_t , std::string>& intrinsic_function_id_to_name = {
@@ -2333,6 +2355,16 @@ namespace IntrinsicFunctionRegistry {
2333
2355
" SymbolicDiff" },
2334
2356
{static_cast <int64_t >(ASRUtils::IntrinsicFunctions::SymbolicExpand),
2335
2357
" SymbolicExpand" },
2358
+ {static_cast <int64_t >(ASRUtils::IntrinsicFunctions::SymbolicSin),
2359
+ " SymbolicSin" },
2360
+ {static_cast <int64_t >(ASRUtils::IntrinsicFunctions::SymbolicCos),
2361
+ " SymbolicCos" },
2362
+ {static_cast <int64_t >(ASRUtils::IntrinsicFunctions::SymbolicLog),
2363
+ " SymbolicLog" },
2364
+ {static_cast <int64_t >(ASRUtils::IntrinsicFunctions::SymbolicExp),
2365
+ " SymbolicExp" },
2366
+ {static_cast <int64_t >(ASRUtils::IntrinsicFunctions::SymbolicAbs),
2367
+ " SymbolicAbs" },
2336
2368
{static_cast <int64_t >(ASRUtils::IntrinsicFunctions::Any),
2337
2369
" any" },
2338
2370
{static_cast <int64_t >(ASRUtils::IntrinsicFunctions::Sum),
@@ -2372,6 +2404,11 @@ namespace IntrinsicFunctionRegistry {
2372
2404
{" SymbolicInteger" , {&SymbolicInteger::create_SymbolicInteger, &SymbolicInteger::eval_SymbolicInteger}},
2373
2405
{" diff" , {&SymbolicDiff::create_SymbolicDiff, &SymbolicDiff::eval_SymbolicDiff}},
2374
2406
{" expand" , {&SymbolicExpand::create_SymbolicExpand, &SymbolicExpand::eval_SymbolicExpand}},
2407
+ {" SymbolicSin" , {&SymbolicSin::create_SymbolicSin, &SymbolicSin::eval_SymbolicSin}},
2408
+ {" SymbolicCos" , {&SymbolicCos::create_SymbolicCos, &SymbolicCos::eval_SymbolicCos}},
2409
+ {" SymbolicLog" , {&SymbolicLog::create_SymbolicLog, &SymbolicLog::eval_SymbolicLog}},
2410
+ {" SymbolicExp" , {&SymbolicExp::create_SymbolicExp, &SymbolicExp::eval_SymbolicExp}},
2411
+ {" SymbolicAbs" , {&SymbolicAbs::create_SymbolicAbs, &SymbolicAbs::eval_SymbolicAbs}},
2375
2412
};
2376
2413
2377
2414
static inline bool is_intrinsic_function (const std::string& name) {
@@ -2488,6 +2525,11 @@ inline std::string get_intrinsic_name(int x) {
2488
2525
INTRINSIC_NAME_CASE (SymbolicInteger)
2489
2526
INTRINSIC_NAME_CASE (SymbolicDiff)
2490
2527
INTRINSIC_NAME_CASE (SymbolicExpand)
2528
+ INTRINSIC_NAME_CASE (SymbolicSin)
2529
+ INTRINSIC_NAME_CASE (SymbolicCos)
2530
+ INTRINSIC_NAME_CASE (SymbolicLog)
2531
+ INTRINSIC_NAME_CASE (SymbolicExp)
2532
+ INTRINSIC_NAME_CASE (SymbolicAbs)
2491
2533
INTRINSIC_NAME_CASE (Sum)
2492
2534
default : {
2493
2535
throw LCompilersException (" pickle: intrinsic_id not implemented" );
0 commit comments