Skip to content

Commit

Permalink
Merge branch 'master' into kinds_full
Browse files Browse the repository at this point in the history
  • Loading branch information
czgdp1807 committed Mar 31, 2021
2 parents 3e801ea + dead2f7 commit 74033cd
Show file tree
Hide file tree
Showing 194 changed files with 1,219 additions and 260 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ src/lfortran/tests/test_pickle
src/lfortran/tests/test_stacktrace*
src/lfortran/tests/test_serialization*
src/lfortran/tests/test_cwrapper
src/lfortran/tests/test_serialization
src/lfortran/tests/write32
src/lfortran/tests/write32.asm
src/lfortran/tests/subroutines32
Expand Down
21 changes: 16 additions & 5 deletions grammar/ASR.asdl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ unit
-- abi=Source means the symbol's implementation is included (full ASR),
-- otherwise it is external (interface ASR, such as procedure interface).

-- SubroutineCall/FuncCall store the actual final resolved subroutine or
-- SubroutineCall/FunctionCall store the actual final resolved subroutine or
-- function (`name` member). They also store the original symbol
-- (`original_name`), which can be one of: null, GenericProcedure or
-- ExternalSymbol.
Expand All @@ -60,23 +60,34 @@ unit
-- used. After the ASR is loaded, the symbols that are used are represented as
-- ExternalSymbols in the current scope of the symbol table.

-- ExternalSymbol represents symbols that cannot be looked up in the current
-- scoped symbol table. As an example, if a variable is defined in a module,
-- but used in a nested subroutine, that is not an external symbol
-- because it can be resolved in the current symbol table (nested subroutine)
-- by following the parents. However if a symbol is used from a different
-- module, then it is an external symbol, because usual symbol resolution by
-- going to the parents will not find the definition.

-- REPL: each cell is parsed into full ASR, compiled + executed, the full ASR
-- is transformed into interface ASR (abi=LFortran) and kept in the symbol
-- table. A new cell starts with an empty symbol table, whose parent symbol
-- table is the previous cell. That allows function / declaration shadowing.


symbol
= Program(symbol_table symtab, identifier name, stmt* body)
| Module(symbol_table symtab, identifier name)
= Program(symbol_table symtab, identifier name, identifier* dependencies,
stmt* body)
| Module(symbol_table symtab, identifier name, identifier* dependencies,
bool loaded_from_mod)
| Subroutine(symbol_table symtab, identifier name, expr* args, stmt* body,
abi abi, access access)
| Function(symbol_table symtab, identifier name, expr* args, stmt* body,
expr return_var, abi abi, access access)
| GenericProcedure(symbol_table parent_symtab, identifier name,
symbol* procs, access access)
| ExternalSymbol(symbol_table parent_symtab, identifier name,
symbol external, access acess)
symbol external, identifier module_name, identifier original_name,
access access)
| DerivedType(symbol_table symtab, identifier name, abi abi, access access)
| Variable(symbol_table parent_symtab, identifier name, intent intent,
expr? value, storage_type storage, ttype type, abi abi, access access)
Expand Down Expand Up @@ -147,7 +158,7 @@ expr
| StrOp(expr left, strop op, expr right, ttype type)
| UnaryOp(unaryop op, expr operand, ttype type)
| Compare(expr left, cmpop op, expr right, ttype type)
| FuncCall(symbol name, symbol? original_name, expr* args,
| FunctionCall(symbol name, symbol? original_name, expr* args,
keyword* keywords, ttype type)
| ArrayInitializer(expr* args, ttype type)
| ConstantInteger(int n, ttype type)
Expand Down
22 changes: 15 additions & 7 deletions grammar/asdl_cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ def make_visitor(self, name, fields, cons):
self.emit( 'self().write_int8(x.base.type);', 2)
self.used = False
for n, field in enumerate(fields):
self.visitField(field, cons)
self.visitField(field, cons, name)
if not self.used:
# Note: a better solution would be to change `&x` to `& /* x */`
# above, but we would need to change emit to return a string.
Expand All @@ -706,7 +706,7 @@ def make_simple_sum_visitor(self, name, types):
self.emit( 'self().write_int8(x);', 2)
self.emit("}", 1)

def visitField(self, field, cons):
def visitField(self, field, cons, cons_name):
if (field.type not in asdl.builtin_types and
field.type not in self.data.simple_types):
self.used = True
Expand All @@ -718,8 +718,11 @@ def visitField(self, field, cons):
template = "self().visit_%s(x.m_%s);" % (field.type, field.name)
else:
if field.type == "symbol":
template = "self().write_symbol(*x.m_%s);" \
% field.name
if cons_name == "ExternalSymbol":
template = "// We skip the symbol for ExternalSymbol"
else:
template = "self().write_symbol(*x.m_%s);" \
% field.name
else:
template = "self().visit_%s(*x.m_%s);" % (field.type, field.name)
if field.seq:
Expand Down Expand Up @@ -832,8 +835,9 @@ def visitModule(self, mod):
self.emit( "Derived& self() { return static_cast<Derived&>(*this); }", 1)
self.emit("public:")
self.emit( "Allocator &al;", 1)
self.emit( "bool load_symtab_id;", 1)
self.emit( "std::map<uint64_t,SymbolTable*> id_symtab_map;", 1)
self.emit( r"DeserializationBaseVisitor(Allocator &al) : al{al} {}", 1)
self.emit( r"DeserializationBaseVisitor(Allocator &al, bool load_symtab_id) : al{al}, load_symtab_id{load_symtab_id} {}", 1)
self.emit_deserialize_node();
self.mod = mod
super(DeserializationVisitorVisitor, self).visitModule(mod)
Expand Down Expand Up @@ -1036,7 +1040,7 @@ def visitConstructor(self, cons, _):
# be present:
lines.append("LFORTRAN_ASSERT(id_symtab_map.find(m_%s_counter) == id_symtab_map.end());" % f.name)
lines.append("SymbolTable *m_%s = al.make_new<SymbolTable>(nullptr);" % (f.name))
lines.append("m_%s->counter = m_%s_counter;" % (f.name, f.name))
lines.append("if (load_symtab_id) m_%s->counter = m_%s_counter;" % (f.name, f.name))
lines.append("id_symtab_map[m_%s_counter] = m_%s;" % (f.name, f.name))
lines.append("{")
lines.append(" size_t n = self().read_int64();")
Expand Down Expand Up @@ -1064,7 +1068,11 @@ def visitConstructor(self, cons, _):
if f.opt:
lines.append("if (self().read_bool()) {")
if f.type == "symbol":
lines.append("m_%s = self().read_symbol();" % (f.name))
if name == "ExternalSymbol":
lines.append("// We skip the symbol for ExternalSymbol")
lines.append("m_%s = nullptr;" % (f.name))
else:
lines.append("m_%s = self().read_symbol();" % (f.name))
else:
lines.append("m_%s = %s::down_cast<%s::%s_t>(self().deserialize_%s());" % (
f.name, subs["mod"].upper(), subs["mod"].upper(), f.type, f.type))
Expand Down
10 changes: 8 additions & 2 deletions integration_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ message("LFORTRAN_BACKEND: ${LFORTRAN_BACKEND}")
macro(RUN)
set(options FAIL)
set(oneValueArgs NAME)
set(multiValueArgs LABELS)
set(multiValueArgs LABELS EXTRAFILES)
cmake_parse_arguments(RUN "${options}" "${oneValueArgs}"
"${multiValueArgs}" ${ARGN} )
set(name ${RUN_NAME})
Expand All @@ -58,7 +58,7 @@ macro(RUN)
endif()

if (ADD_TEST)
add_executable(${name} ${name}.f90)
add_executable(${name} ${name}.f90 ${RUN_EXTRAFILES})
if ((LFORTRAN_BACKEND STREQUAL "cpp") OR (LFORTRAN_BACKEND STREQUAL "x86"))
target_compile_options(${name} PUBLIC --backend=${LFORTRAN_BACKEND})
target_link_options(${name} PUBLIC --backend=${LFORTRAN_BACKEND})
Expand Down Expand Up @@ -155,6 +155,12 @@ RUN(NAME modules_03 LABELS gfortran)
RUN(NAME modules_04 LABELS gfortran)
RUN(NAME modules_05 LABELS gfortran)
RUN(NAME modules_06 LABELS gfortran llvm)
RUN(NAME modules_07 LABELS gfortran llvm EXTRAFILES modules_07_module.f90)
RUN(NAME modules_08 LABELS gfortran llvm EXTRAFILES
modules_08_a.f90 modules_08_b.f90)
RUN(NAME modules_09 LABELS gfortran llvm EXTRAFILES
modules_09_a.f90 modules_09_b.f90)
RUN(NAME modules_10 LABELS gfortran llvm)

RUN(NAME if_04 LABELS gfortran x86)
RUN(NAME case_01 LABELS gfortran llvm)
Expand Down
4 changes: 4 additions & 0 deletions integration_tests/interface_01.f90
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,8 @@ program interface_01
call a(r)
if (r /= 7) error stop

i = 7
call a(i)
if (i /= 8) error stop

end program
4 changes: 2 additions & 2 deletions integration_tests/modules_01.f90
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module a
module a_01
implicit none

contains
Expand All @@ -10,7 +10,7 @@ subroutine b()
end module

program modules_01
use a, only: b
use a_01, only: b
implicit none

call b()
Expand Down
14 changes: 10 additions & 4 deletions integration_tests/modules_02.f90
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module a
module a_02
implicit none

contains
Expand All @@ -9,7 +9,7 @@ subroutine b()

end module

module c
module c_02
implicit none

contains
Expand All @@ -18,14 +18,20 @@ subroutine d()
print *, "d()"
end subroutine

subroutine e()
print *, "e()"
end subroutine

end module

program modules_02
use a
use c, only: x=>d
use a_02
use c_02, only: x=>d
use c_02, only: e
implicit none

call b()
call x()
call e()

end
6 changes: 3 additions & 3 deletions integration_tests/modules_04.f90
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module a
module a_04
implicit none

contains
Expand All @@ -18,12 +18,12 @@ program modules_04
contains

subroutine f()
use a, only: b
use a_04, only: b
call b()
end subroutine

integer function g()
use :: a, only: b
use :: a_04, only: b
call b()
g = 5
end function
Expand Down
4 changes: 2 additions & 2 deletions integration_tests/modules_06.f90
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module a
module a_06
implicit none

contains
Expand All @@ -11,7 +11,7 @@ integer function b() result(r)
end module

program modules_06
use a, only: b
use a_06, only: b
implicit none

integer :: i
Expand Down
7 changes: 7 additions & 0 deletions integration_tests/modules_07.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
program modules_07
use modules_07_module, only: b
implicit none

call b()

end
10 changes: 10 additions & 0 deletions integration_tests/modules_07_module.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module modules_07_module
implicit none

contains

subroutine b()
print *, "b()"
end subroutine

end module
11 changes: 11 additions & 0 deletions integration_tests/modules_08.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
program modules_08
use modules_08_a, only: a
use modules_08_b, only: b
implicit none

if (a() /= 3) error stop
if (b() /= 5) error stop

print *, "OK"

end
12 changes: 12 additions & 0 deletions integration_tests/modules_08_a.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module modules_08_a
implicit none
private
public a

contains

integer function a()
a = 3
end function

end module
12 changes: 12 additions & 0 deletions integration_tests/modules_08_b.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module modules_08_b
implicit none
private
public b

contains

integer function b()
b = 5
end function

end module
9 changes: 9 additions & 0 deletions integration_tests/modules_09.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
program modules_09
use modules_09_a, only: a
implicit none

if (a() /= 8) error stop

print *, "OK"

end
13 changes: 13 additions & 0 deletions integration_tests/modules_09_a.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module modules_09_a
use modules_09_b, only: b
implicit none
private
public a

contains

integer function a()
a = 3 + b()
end function

end module
12 changes: 12 additions & 0 deletions integration_tests/modules_09_b.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module modules_09_b
implicit none
private
public b

contains

integer function b()
b = 5
end function

end module
27 changes: 27 additions & 0 deletions integration_tests/modules_10.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module modules_10_b
implicit none
private
public b
contains
integer function b()
b = 5
end function
end module

module modules_10_a
use modules_10_b, only: b
implicit none
private
public a
contains
integer function a()
a = 3 + b()
end function
end module

program modules_10
use modules_10_a, only: a
implicit none
if (a() /= 8) error stop
print *, "OK"
end
Loading

0 comments on commit 74033cd

Please sign in to comment.