@@ -74,6 +74,11 @@ enum class IntrinsicFunctions : int64_t {
7474 SymbolicInteger,
7575 SymbolicDiff,
7676 SymbolicExpand,
77+ SymbolicSin,
78+ SymbolicCos,
79+ SymbolicLog,
80+ SymbolicExp,
81+ SymbolicAbs,
7782 Sum,
7883 // ...
7984};
@@ -2169,45 +2174,52 @@ namespace SymbolicInteger {
21692174 }
21702175} // namespace SymbolicInteger
21712176
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
22092216
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)
22112223
22122224namespace IntrinsicFunctionRegistry {
22132225
@@ -2275,6 +2287,16 @@ namespace IntrinsicFunctionRegistry {
22752287 {nullptr , &SymbolicDiff::verify_args}},
22762288 {static_cast <int64_t >(ASRUtils::IntrinsicFunctions::SymbolicExpand),
22772289 {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}},
22782300 };
22792301
22802302 static const std::map<int64_t , std::string>& intrinsic_function_id_to_name = {
@@ -2333,6 +2355,16 @@ namespace IntrinsicFunctionRegistry {
23332355 " SymbolicDiff" },
23342356 {static_cast <int64_t >(ASRUtils::IntrinsicFunctions::SymbolicExpand),
23352357 " 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" },
23362368 {static_cast <int64_t >(ASRUtils::IntrinsicFunctions::Any),
23372369 " any" },
23382370 {static_cast <int64_t >(ASRUtils::IntrinsicFunctions::Sum),
@@ -2372,6 +2404,11 @@ namespace IntrinsicFunctionRegistry {
23722404 {" SymbolicInteger" , {&SymbolicInteger::create_SymbolicInteger, &SymbolicInteger::eval_SymbolicInteger}},
23732405 {" diff" , {&SymbolicDiff::create_SymbolicDiff, &SymbolicDiff::eval_SymbolicDiff}},
23742406 {" 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}},
23752412 };
23762413
23772414 static inline bool is_intrinsic_function (const std::string& name) {
@@ -2488,6 +2525,11 @@ inline std::string get_intrinsic_name(int x) {
24882525 INTRINSIC_NAME_CASE (SymbolicInteger)
24892526 INTRINSIC_NAME_CASE (SymbolicDiff)
24902527 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)
24912533 INTRINSIC_NAME_CASE (Sum)
24922534 default : {
24932535 throw LCompilersException (" pickle: intrinsic_id not implemented" );
0 commit comments