Skip to content

Commit 47bd6d5

Browse files
authored
fix: added initial implementation for supporting internal function definitions (#2119)
1 parent 4a70207 commit 47bd6d5

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

integration_tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,7 @@ RUN(NAME func_static_01 LABELS cpython llvm c wasm)
671671
RUN(NAME func_static_02 LABELS cpython llvm c wasm)
672672
RUN(NAME func_dep_03 LABELS cpython llvm c)
673673
RUN(NAME func_dep_04 LABELS cpython llvm c)
674+
RUN(NAME func_internal_def_01 LABELS cpython llvm NOFAST)
674675

675676
RUN(NAME float_01 LABELS cpython llvm c wasm wasm_x64)
676677
RUN(NAME recursive_01 LABELS cpython llvm c wasm wasm_x64 wasm_x86)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
def main():
2+
x: i32
3+
x = (2+3)*5
4+
print(x)
5+
6+
def bar():
7+
assert x == 25
8+
9+
bar()
10+
11+
main()

src/lpython/semantics/python_ast_to_asr.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4060,6 +4060,24 @@ class SymbolTableVisitor : public CommonVisitor<SymbolTableVisitor> {
40604060
return nullptr;
40614061
}
40624062

4063+
// Implement visit_While for Symbol Table visitor.
4064+
void visit_While(const AST::While_t &/*x*/) {}
4065+
4066+
// Implement visit_Delete for Symbol Table visitor.
4067+
void visit_Delete(const AST::Delete_t &/*x*/) {}
4068+
4069+
// Implement visit_Pass for Symbol Table visitor.
4070+
void visit_Pass(const AST::Pass_t &/*x*/) {}
4071+
4072+
// Implement visit_Return for Symbol Table visitor.
4073+
void visit_Return(const AST::Return_t &/*x*/) {}
4074+
4075+
// Implement visit_Raise for Symbol Table visitor.
4076+
void visit_Raise(const AST::Raise_t &/*x*/) {}
4077+
4078+
// Implement visit_Global for Symbol Table visitor.
4079+
void visit_Global(const AST::Global_t &/*x*/) {}
4080+
40634081
void visit_FunctionDef(const AST::FunctionDef_t &x) {
40644082
dependencies.clear(al);
40654083
SymbolTable *parent_scope = current_scope;
@@ -4304,6 +4322,12 @@ class SymbolTableVisitor : public CommonVisitor<SymbolTableVisitor> {
43044322
}
43054323
} else {
43064324
bool is_pure = false, is_module = false;
4325+
4326+
// This checks for internal function defintions as well.
4327+
for (size_t i = 0; i < x.n_body; i++) {
4328+
visit_stmt(*x.m_body[i]);
4329+
}
4330+
43074331
tmp = ASRUtils::make_Function_t_util(
43084332
al, x.base.base.loc,
43094333
/* a_symtab */ current_scope,

0 commit comments

Comments
 (0)