Skip to content

Commit 80b5fe9

Browse files
committed
Implement quit(error_code)
1 parent c7bd162 commit 80b5fe9

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/lpython/semantics/python_ast_to_asr.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1763,8 +1763,16 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
17631763
args.p, args.size());
17641764
return;
17651765

1766-
} else if (call_name == "exit" || call_name == "quit") {
1767-
ASR::expr_t *code = nullptr;
1766+
} else if (call_name == "quit") {
1767+
ASR::expr_t *code;
1768+
if (args.size() == 0) {
1769+
code = nullptr;
1770+
} else if (args.size() == 1) {
1771+
code = args[0];
1772+
} else {
1773+
throw SemanticError("The function quit() requires 0 or 1 arguments",
1774+
x.base.base.loc);
1775+
}
17681776
tmp = ASR::make_Stop_t(al, x.base.base.loc, code);
17691777
return;
17701778
}

0 commit comments

Comments
 (0)