Skip to content

Commit d9163ab

Browse files
authored
Remove goto (#1838)
* ASR: Remove goto support * TEST: Remove goto tests
1 parent cdbfddc commit d9163ab

File tree

9 files changed

+2
-355
lines changed

9 files changed

+2
-355
lines changed

integration_tests/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,6 @@ RUN(NAME generics_list_01 LABELS cpython llvm c)
540540
RUN(NAME test_statistics LABELS cpython llvm)
541541
RUN(NAME test_str_attributes LABELS cpython llvm c)
542542
RUN(NAME kwargs_01 LABELS cpython llvm c)
543-
RUN(NAME test_01_goto LABELS cpython llvm c)
544543

545544
RUN(NAME func_inline_01 LABELS llvm c wasm)
546545
RUN(NAME func_inline_02 LABELS cpython llvm c)

integration_tests/test_01_goto.py

Lines changed: 0 additions & 35 deletions
This file was deleted.

src/lpython/semantics/python_ast_to_asr.cpp

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3793,8 +3793,6 @@ class SymbolTableVisitor : public CommonVisitor<SymbolTableVisitor> {
37933793
vectorize = true;
37943794
} else if (name == "restriction") {
37953795
is_restriction = true;
3796-
} else if (name == "with_goto") {
3797-
// TODO: Use goto attribute in function?
37983796
} else if (name == "inline") {
37993797
is_inline = true;
38003798
} else if (name == "static") {
@@ -4337,8 +4335,6 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
43374335

43384336
public:
43394337
ASR::asr_t *asr;
4340-
std::map<std::string, std::tuple<int64_t, bool, Location>> goto_name2id;
4341-
int64_t gotoids;
43424338
std::vector<ASR::symbol_t*> do_loop_variables;
43434339
// Stores the name of imported functions and the modules they are imported from
43444340
std::map<std::string, std::string> imported_functions;
@@ -4348,13 +4344,12 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
43484344
bool main_module, std::map<int, ASR::symbol_t*> &ast_overload,
43494345
bool allow_implicit_casting_)
43504346
: CommonVisitor(al, lm, nullptr, diagnostics, main_module, ast_overload, "", {}, allow_implicit_casting_),
4351-
asr{unit}, gotoids{0}
4347+
asr{unit}
43524348
{}
43534349

43544350
// Transforms statements to a list of ASR statements
43554351
// In addition, it also inserts the following nodes if needed:
43564352
// * ImplicitDeallocate
4357-
// * GoToTarget
43584353
// The `body` Vec must already be reserved
43594354
void transform_stmts(Vec<ASR::stmt_t*> &body, size_t n_body, AST::stmt_t **m_body) {
43604355
tmp = nullptr;
@@ -4505,8 +4500,6 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
45054500
}
45064501

45074502
void visit_FunctionDef(const AST::FunctionDef_t &x) {
4508-
goto_name2id.clear();
4509-
gotoids = 0;
45104503
SymbolTable *old_scope = current_scope;
45114504
ASR::symbol_t *t = current_scope->get_symbol(x.m_name);
45124505
if (ASR::is_a<ASR::Function_t>(*t)) {
@@ -4527,13 +4520,6 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
45274520
}
45284521
current_scope = old_scope;
45294522
tmp = nullptr;
4530-
4531-
for( auto itr: goto_name2id ) {
4532-
if( !std::get<1>(itr.second) ) {
4533-
throw SemanticError("Label '" + itr.first + "' is not defined in '"
4534-
+ std::string(x.m_name) + "'", std::get<2>(itr.second));
4535-
}
4536-
}
45374523
}
45384524

45394525
void visit_Import(const AST::Import_t &x) {
@@ -5523,33 +5509,6 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
55235509
void visit_Attribute(const AST::Attribute_t &x) {
55245510
if (AST::is_a<AST::Name_t>(*x.m_value)) {
55255511
std::string value = AST::down_cast<AST::Name_t>(x.m_value)->m_id;
5526-
if( value == "label" ) {
5527-
std::string labelname = x.m_attr;
5528-
if( goto_name2id.find(labelname) == goto_name2id.end() ) {
5529-
goto_name2id[labelname] = std::make_tuple(gotoids, true, x.base.base.loc);
5530-
gotoids += 1;
5531-
} else if( !std::get<1>(goto_name2id[labelname]) ) {
5532-
goto_name2id[labelname] = std::make_tuple(
5533-
std::get<0>(goto_name2id[labelname]),
5534-
true,
5535-
std::get<2>(goto_name2id[labelname])
5536-
);
5537-
}
5538-
int id = std::get<0>(goto_name2id[labelname]);
5539-
tmp = ASR::make_GoToTarget_t(al, x.base.base.loc, id, x.m_attr);
5540-
return ;
5541-
}
5542-
5543-
if (value == "goto"){
5544-
std::string labelname = std::string(x.m_attr);
5545-
if( goto_name2id.find(labelname) == goto_name2id.end() ) {
5546-
goto_name2id[labelname] = std::make_tuple(gotoids, false, x.base.base.loc);
5547-
gotoids += 1;
5548-
}
5549-
int id = std::get<0>(goto_name2id[labelname]);
5550-
tmp = ASR::make_GoTo_t(al, x.base.base.loc, id, x.m_attr);
5551-
return ;
5552-
}
55535512

55545513
ASR::symbol_t *org_sym = current_scope->resolve_symbol(value);
55555514
if (!org_sym) {

src/runtime/lpython/goto.py

Lines changed: 0 additions & 241 deletions
This file was deleted.

src/runtime/lpython/lpython.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
import ctypes
44
import platform
55
from dataclasses import dataclass as py_dataclass, is_dataclass as py_is_dataclass
6-
from goto import with_goto
76

87
# TODO: this does not seem to restrict other imports
98
__slots__ = ["i8", "i16", "i32", "i64", "u8", "u16", "u32", "u64", "f32", "f64", "c32", "c64", "CPtr",
109
"overload", "ccall", "TypeVar", "pointer", "c_p_pointer", "Pointer",
11-
"p_c_pointer", "vectorize", "inline", "Union", "static", "with_goto",
10+
"p_c_pointer", "vectorize", "inline", "Union", "static",
1211
"packed", "Const", "sizeof", "ccallable", "ccallback", "Callable",
1312
"Allocatable"]
1413

0 commit comments

Comments
 (0)