@@ -46,6 +46,7 @@ enum class IntrinsicFunctions : int64_t {
4646 Partition,
4747 ListReverse,
4848 ListPop,
49+ Reserve,
4950 DictKeys,
5051 DictValues,
5152 SetAdd,
@@ -102,6 +103,7 @@ inline std::string get_intrinsic_name(int x) {
102103 INTRINSIC_NAME_CASE (Partition)
103104 INTRINSIC_NAME_CASE (ListReverse)
104105 INTRINSIC_NAME_CASE (ListPop)
106+ INTRINSIC_NAME_CASE (Reserve)
105107 INTRINSIC_NAME_CASE (DictKeys)
106108 INTRINSIC_NAME_CASE (DictValues)
107109 INTRINSIC_NAME_CASE (SetAdd)
@@ -1262,6 +1264,55 @@ static inline ASR::asr_t* create_ListPop(Allocator& al, const Location& loc,
12621264
12631265} // namespace ListPop
12641266
1267+ namespace Reserve {
1268+
1269+ static inline void verify_args (const ASR::IntrinsicFunction_t& x, diag::Diagnostics& diagnostics) {
1270+ ASRUtils::require_impl (x.n_args == 2 , " Call to reserve must have exactly one argument" ,
1271+ x.base .base .loc , diagnostics);
1272+ ASRUtils::require_impl (ASR::is_a<ASR::List_t>(*ASRUtils::expr_type (x.m_args [0 ])),
1273+ " First argument to reserve must be of list type" ,
1274+ x.base .base .loc , diagnostics);
1275+ ASRUtils::require_impl (ASR::is_a<ASR::Integer_t>(*ASRUtils::expr_type (x.m_args [1 ])),
1276+ " Second argument to reserve must be an integer" ,
1277+ x.base .base .loc , diagnostics);
1278+ ASRUtils::require_impl (x.m_type == nullptr ,
1279+ " Return type of reserve must be empty" ,
1280+ x.base .base .loc , diagnostics);
1281+ }
1282+
1283+ static inline ASR::expr_t *eval_reserve (Allocator &/* al*/ ,
1284+ const Location &/* loc*/ , Vec<ASR::expr_t *>& /* args*/ ) {
1285+ // TODO: To be implemented for ListConstant expression
1286+ return nullptr ;
1287+ }
1288+
1289+ static inline ASR::asr_t * create_Reserve (Allocator& al, const Location& loc,
1290+ Vec<ASR::expr_t *>& args,
1291+ const std::function<void (const std::string &, const Location &)> err) {
1292+ if (args.size () != 2 ) {
1293+ err (" Call to reserve must have exactly two argument" , loc);
1294+ }
1295+ if (!ASR::is_a<ASR::List_t>(*ASRUtils::expr_type (args[0 ]))) {
1296+ err (" First argument to reserve must be of list type" , loc);
1297+ }
1298+ if (!ASR::is_a<ASR::Integer_t>(*ASRUtils::expr_type (args[1 ]))) {
1299+ err (" Second argument to reserve must be an integer" , loc);
1300+ }
1301+
1302+ Vec<ASR::expr_t *> arg_values;
1303+ arg_values.reserve (al, args.size ());
1304+ for ( size_t i = 0 ; i < args.size (); i++ ) {
1305+ arg_values.push_back (al, ASRUtils::expr_value (args[i]));
1306+ }
1307+ ASR::expr_t * compile_time_value = eval_reserve (al, loc, arg_values);
1308+ return ASR::make_Expr_t (al, loc,
1309+ ASRUtils::EXPR (ASRUtils::make_IntrinsicFunction_t_util (al, loc,
1310+ static_cast <int64_t >(ASRUtils::IntrinsicFunctions::Reserve),
1311+ args.p , args.size (), 0 , nullptr , compile_time_value)));
1312+ }
1313+
1314+ } // namespace Reserve
1315+
12651316namespace DictKeys {
12661317
12671318static inline void verify_args (const ASR::IntrinsicFunction_t& x, diag::Diagnostics& diagnostics) {
@@ -3124,6 +3175,8 @@ namespace IntrinsicFunctionRegistry {
31243175 {nullptr , &DictValues::verify_args}},
31253176 {static_cast <int64_t >(ASRUtils::IntrinsicFunctions::ListPop),
31263177 {nullptr , &ListPop::verify_args}},
3178+ {static_cast <int64_t >(ASRUtils::IntrinsicFunctions::Reserve),
3179+ {nullptr , &Reserve::verify_args}},
31273180 {static_cast <int64_t >(ASRUtils::IntrinsicFunctions::SetAdd),
31283181 {nullptr , &SetAdd::verify_args}},
31293182 {static_cast <int64_t >(ASRUtils::IntrinsicFunctions::SetRemove),
@@ -3206,6 +3259,8 @@ namespace IntrinsicFunctionRegistry {
32063259 " list.reverse" },
32073260 {static_cast <int64_t >(ASRUtils::IntrinsicFunctions::ListPop),
32083261 " list.pop" },
3262+ {static_cast <int64_t >(ASRUtils::IntrinsicFunctions::Reserve),
3263+ " reserve" },
32093264 {static_cast <int64_t >(ASRUtils::IntrinsicFunctions::DictKeys),
32103265 " dict.keys" },
32113266 {static_cast <int64_t >(ASRUtils::IntrinsicFunctions::DictValues),
@@ -3290,6 +3345,7 @@ namespace IntrinsicFunctionRegistry {
32903345 {" list.index" , {&ListIndex::create_ListIndex, &ListIndex::eval_list_index}},
32913346 {" list.reverse" , {&ListReverse::create_ListReverse, &ListReverse::eval_list_reverse}},
32923347 {" list.pop" , {&ListPop::create_ListPop, &ListPop::eval_list_pop}},
3348+ {" reserve" , {&Reserve::create_Reserve, &Reserve::eval_reserve}},
32933349 {" dict.keys" , {&DictKeys::create_DictKeys, &DictKeys::eval_dict_keys}},
32943350 {" dict.values" , {&DictValues::create_DictValues, &DictValues::eval_dict_values}},
32953351 {" set.add" , {&SetAdd::create_SetAdd, &SetAdd::eval_set_add}},
0 commit comments