FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Make support for Set pop in python_attribute_eval.h · certik/lpython@8a2cf67 · GitHub

/ lpython Public
forked from lcompilers/lpython

Commit 8a2cf67

Browse files
committed
Make support for Set pop in python_attribute_eval.h
1 parent aa4204b commit 8a2cf67

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

‎src/libasr/asr_utils.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ static inline ASR::ttype_t* expr_type(const ASR::expr_t *f)
137137
case ASR::exprType::ListSection: { return ((ASR::ListSection_t*)f)->m_type; }
138138
case ASR::exprType::ListPop: { return ((ASR::ListPop_t*)f)->m_type; }
139139
case ASR::exprType::DictPop: { return ((ASR::DictPop_t*)f)->m_type; }
140+
case ASR::exprType::SetPop: { return ((ASR::SetPop_t*)f)->m_type; }
140141
default : throw LFortranException("Not implemented");
141142
}
142143
}
@@ -311,6 +312,7 @@ static inline ASR::expr_t* expr_value(ASR::expr_t *f)
311312
case ASR::exprType::ListSection: { return ASR::down_cast<ASR::ListSection_t>(f)->m_value; }
312313
case ASR::exprType::ListPop: { return ASR::down_cast<ASR::ListPop_t>(f)->m_value; }
313314
case ASR::exprType::DictPop: { return ASR::down_cast<ASR::DictPop_t>(f)->m_value; }
315+
case ASR::exprType::SetPop: { return ASR::down_cast<ASR::SetPop_t>(f)->m_value; }
314316
case ASR::exprType::DictItem: // Drop through
315317
case ASR::exprType::ArrayConstant: // Drop through
316318
case ASR::exprType::IntegerConstant: // Drop through

‎src/lpython/semantics/python_attribute_eval.h‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ struct AttributeHandler {
2222
{"list@remove", &eval_list_remove},
2323
{"list@insert", &eval_list_insert},
2424
{"list@pop", &eval_list_pop},
25+
{"set@pop", &eval_set_pop},
2526
{"set@add", &eval_set_add},
2627
{"set@remove", &eval_set_remove},
2728
{"dict@get", &eval_dict_get},
@@ -177,6 +178,17 @@ struct AttributeHandler {
177178
return make_ListPop_t(al, loc, s, idx, list_type, nullptr);
178179
}
179180

181+
static ASR::asr_t* eval_set_pop(ASR::symbol_t *s, Allocator &al, const Location &loc,
182+
Vec<ASR::expr_t*> &args, diag::Diagnostics &/*diag*/) {
183+
if (args.size() != 0) {
184+
throw SemanticError("pop() takes no arguments (" + std::to_string(args.size()) + " given)", loc);
185+
}
186+
ASR::Variable_t *v = ASR::down_cast<ASR::Variable_t>(s);
187+
ASR::ttype_t *type = v->m_type;
188+
ASR::ttype_t *set_type = ASR::down_cast<ASR::Set_t>(type)->m_type;
189+
return make_SetPop_t(al, loc, s, set_type, nullptr);
190+
}
191+
180192
static ASR::asr_t* eval_set_add(ASR::symbol_t *s, Allocator &al, const Location &loc,
181193
Vec<ASR::expr_t*> &args, diag::Diagnostics &diag) {
182194
if (args.size() != 1) {

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL