Skip to content

fix: added initial implementation for supporting internal function definitions #2119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions integration_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,7 @@ RUN(NAME func_static_01 LABELS cpython llvm c wasm)
RUN(NAME func_static_02 LABELS cpython llvm c wasm)
RUN(NAME func_dep_03 LABELS cpython llvm c)
RUN(NAME func_dep_04 LABELS cpython llvm c)
RUN(NAME func_internal_def_01 LABELS cpython llvm NOFAST)

RUN(NAME float_01 LABELS cpython llvm c wasm wasm_x64)
RUN(NAME recursive_01 LABELS cpython llvm c wasm wasm_x64 wasm_x86)
Expand Down
11 changes: 11 additions & 0 deletions integration_tests/func_internal_def_01.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
def main():
x: i32
x = (2+3)*5
print(x)

def bar():
assert x == 25

bar()

main()
24 changes: 24 additions & 0 deletions src/lpython/semantics/python_ast_to_asr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4060,6 +4060,24 @@ class SymbolTableVisitor : public CommonVisitor<SymbolTableVisitor> {
return nullptr;
}

// Implement visit_While for Symbol Table visitor.
void visit_While(const AST::While_t &/*x*/) {}

// Implement visit_Delete for Symbol Table visitor.
void visit_Delete(const AST::Delete_t &/*x*/) {}

// Implement visit_Pass for Symbol Table visitor.
void visit_Pass(const AST::Pass_t &/*x*/) {}

// Implement visit_Return for Symbol Table visitor.
void visit_Return(const AST::Return_t &/*x*/) {}

// Implement visit_Raise for Symbol Table visitor.
void visit_Raise(const AST::Raise_t &/*x*/) {}

// Implement visit_Global for Symbol Table visitor.
void visit_Global(const AST::Global_t &/*x*/) {}

void visit_FunctionDef(const AST::FunctionDef_t &x) {
dependencies.clear(al);
SymbolTable *parent_scope = current_scope;
Expand Down Expand Up @@ -4304,6 +4322,12 @@ class SymbolTableVisitor : public CommonVisitor<SymbolTableVisitor> {
}
} else {
bool is_pure = false, is_module = false;

// This checks for internal function defintions as well.
for (size_t i = 0; i < x.n_body; i++) {
visit_stmt(*x.m_body[i]);
}

tmp = ASRUtils::make_Function_t_util(
al, x.base.base.loc,
/* a_symtab */ current_scope,
Expand Down