Skip to content

Commit

Permalink
Merge branch 'assert' into 'py'
Browse files Browse the repository at this point in the history
Make `assert` working

See merge request certik/lfortran!25
  • Loading branch information
certik committed Jan 12, 2022
2 parents 5ec9f1c + 7497093 commit 747e2f3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions grammar/ASR.asdl
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ stmt
| Return()
| Select(expr test, case_stmt* body, stmt* default)
| Stop(expr? code)
| Assert(expr test, expr? msg)
| SubroutineCall(symbol name, symbol? original_name, expr* args, expr? dt)
| Where(expr test, stmt* body, stmt* orelse)
| WhileLoop(expr test, stmt* body)
Expand Down
11 changes: 11 additions & 0 deletions src/lfortran/semantics/python_ast_to_asr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,17 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
overloaded);
}

void visit_Assert(const AST::Assert_t &x) {
this->visit_expr(*x.m_test);
ASR::expr_t *test = LFortran::ASRUtils::EXPR(tmp);
ASR::expr_t *msg = nullptr;
if (x.m_msg != nullptr) {
this->visit_expr(*x.m_msg);
msg = LFortran::ASRUtils::EXPR(tmp);
}
tmp = ASR::make_Assert_t(al, x.base.base.loc, test, msg);
}

void visit_Subscript(const AST::Subscript_t &x) {
this->visit_expr(*x.m_value);
ASR::expr_t *value = LFortran::ASRUtils::EXPR(tmp);
Expand Down

0 comments on commit 747e2f3

Please sign in to comment.