Skip to content

Commit ede6e7f

Browse files
committed
WIP
1 parent 7eb2bea commit ede6e7f

File tree

143 files changed

+79029
-11909
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

143 files changed

+79029
-11909
lines changed

integration_tests/array_expr_05.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from lpython import u8, u16, u32, u64
1+
from lpython import u8, u16, u32, u64, i8
22
from numpy import uint8, uint16, uint32, uint64, array
33

44
def g():
@@ -7,11 +7,6 @@ def g():
77
a32: u32[3] = array([127, 3, 111], dtype=uint32)
88
a64: u64[3] = array([127, 3, 111], dtype=uint64)
99

10-
print(a8)
11-
print(a16)
12-
print(a32)
13-
print(a64)
14-
1510
assert (a8[0] == u8(127))
1611
assert (a8[1] == u8(3))
1712
assert (a8[2] == u8(111))
@@ -28,4 +23,9 @@ def g():
2823
assert (a64[1] == u64(3))
2924
assert (a64[2] == u64(111))
3025

26+
print(a8)
27+
print(a16)
28+
print(a32)
29+
print(a64)
30+
3131
g()

integration_tests/bindc_02.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ def f():
1313
y[1] = i16(2)
1414
yptr1 = pointer(y)
1515
print(pointer(y), yptr1)
16-
print(yptr1[0], yptr1[1])
17-
assert yptr1[0] == i16(1)
18-
assert yptr1[1] == i16(2)
16+
# print(yptr1[0], yptr1[1])
17+
# assert yptr1[0] == i16(1)
18+
# assert yptr1[1] == i16(2)
1919

20-
yptr1 = c_p_pointer(yq, i16[:], array([2]))
20+
# yptr1 = c_p_pointer(yq, i16[:], array([2]))
2121

22-
print(yq, yptr1)
22+
# print(yq, yptr1)
2323

2424
f()

src/bin/lpython.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -856,9 +856,9 @@ int interactive_python_repl(
856856
std::cout << " - History (Keys: Up, Down)" << std::endl;
857857

858858
std::vector<std::string> history;
859-
859+
860860
std::function<bool(std::string)> iscomplete = determine_completeness;
861-
861+
862862
std::string code_string;
863863
size_t cell_count = 0;
864864
while (true) {
@@ -1013,8 +1013,8 @@ int interactive_python_repl(
10131013
}
10141014
case (LCompilers::PythonCompiler::EvalResult::struct_type) : {
10151015
if (verbose) {
1016-
std::cout << "Return type: "
1017-
<< LCompilers::ASRUtils::get_type_code(r.structure.ttype)
1016+
std::cout << "Return type: "
1017+
<< LCompilers::ASRUtils::get_type_code(r.structure.ttype)
10181018
<< std::endl;
10191019
}
10201020
if (verbose) section("Result:");
@@ -1094,7 +1094,7 @@ int compile_python_using_llvm(
10941094
}
10951095
LCompilers::ASR::TranslationUnit_t* asr = r1.result;
10961096
if( compiler_options.po.disable_main ) {
1097-
int err = LCompilers::LPython::save_pyc_files(*asr, infile);
1097+
int err = LCompilers::LPython::save_pyc_files(*asr, infile, lm);
10981098
if( err ) {
10991099
return err;
11001100
}
@@ -1237,7 +1237,7 @@ int compile_to_binary_wasm(
12371237
}
12381238
LCompilers::ASR::TranslationUnit_t* asr = r1.result;
12391239
if( compiler_options.po.disable_main ) {
1240-
int err = LCompilers::LPython::save_pyc_files(*asr, infile);
1240+
int err = LCompilers::LPython::save_pyc_files(*asr, infile, lm);
12411241
if( err ) {
12421242
return err;
12431243
}
@@ -1310,7 +1310,7 @@ int compile_to_binary_x86(
13101310
}
13111311
LCompilers::ASR::TranslationUnit_t* asr = r1.result;
13121312
if( compiler_options.po.disable_main ) {
1313-
int err = LCompilers::LPython::save_pyc_files(*asr, infile);
1313+
int err = LCompilers::LPython::save_pyc_files(*asr, infile, lm);
13141314
if( err ) {
13151315
return err;
13161316
}
@@ -1384,7 +1384,7 @@ int compile_to_binary_wasm_to_x86(
13841384
}
13851385
LCompilers::ASR::TranslationUnit_t* asr = r1.result;
13861386
if( compiler_options.po.disable_main ) {
1387-
int err = LCompilers::LPython::save_pyc_files(*asr, infile);
1387+
int err = LCompilers::LPython::save_pyc_files(*asr, infile, lm);
13881388
if( err ) {
13891389
return err;
13901390
}

src/libasr/ASR.asdl

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ unit
99
= TranslationUnit(symbol_table symtab, node* items)
1010

1111
symbol
12-
= Program(symbol_table symtab, identifier name, identifier* dependencies, stmt* body)
13-
| Module(symbol_table symtab, identifier name, identifier* dependencies, bool loaded_from_mod, bool intrinsic)
14-
| Function(symbol_table symtab, identifier name, ttype function_signature, identifier* dependencies, expr* args, stmt* body, expr? return_var, access access, bool deterministic, bool side_effect_free, string? module_file)
12+
= Program(symbol_table symtab, identifier name, identifier* dependencies, stmt* body, location start_name, location end_name)
13+
| Module(symbol_table symtab, identifier name, identifier* dependencies, bool loaded_from_mod, bool intrinsic, location start_name, location end_name)
14+
| Function(symbol_table symtab, identifier name, ttype function_signature, identifier* dependencies, expr* args, stmt* body, expr? return_var, access access, bool deterministic, bool side_effect_free, string? module_file, location start_name, location end_name)
1515
| GenericProcedure(symbol_table parent_symtab, identifier name, symbol* procs, access access)
1616
| CustomOperator(symbol_table parent_symtab, identifier name, symbol* procs, access access)
1717
| ExternalSymbol(symbol_table parent_symtab, identifier name, symbol external, identifier module_name, identifier* scope_names, identifier original_name, access access)
1818
| Struct(symbol_table symtab, identifier name, identifier* dependencies, identifier* members, identifier* member_functions, abi abi, access access, bool is_packed, bool is_abstract, call_arg* initializers, expr? alignment, symbol? parent)
19-
| EnumType(symbol_table symtab, identifier name, identifier* dependencies, identifier* members, abi abi, access access, enumtype enum_value_type, ttype type, symbol? parent)
20-
| UnionType(symbol_table symtab, identifier name, identifier* dependencies, identifier* members, abi abi, access access, call_arg* initializers, symbol? parent)
21-
| Variable(symbol_table parent_symtab, identifier name, identifier* dependencies, intent intent, expr? symbolic_value, expr? value, storage_type storage, ttype type, symbol? type_declaration, abi abi, access access, presence presence, bool value_attr)
22-
| ClassType(symbol_table symtab, identifier name, abi abi, access access)
19+
| Enum(symbol_table symtab, identifier name, identifier* dependencies, identifier* members, abi abi, access access, enumtype enum_value_type, ttype type, symbol? parent)
20+
| Union(symbol_table symtab, identifier name, identifier* dependencies, identifier* members, abi abi, access access, call_arg* initializers, symbol? parent)
21+
| Variable(symbol_table parent_symtab, identifier name, identifier* dependencies, intent intent, expr? symbolic_value, expr? value, storage_type storage, ttype type, symbol? type_declaration, abi abi, access access, presence presence, bool value_attr, bool target_attr)
22+
| Class(symbol_table symtab, identifier name, abi abi, access access)
2323
| ClassProcedure(symbol_table parent_symtab, identifier name, identifier? self_argument, identifier proc_name, symbol proc, abi abi, bool is_deferred, bool is_nopass)
2424
| AssociateBlock(symbol_table symtab, identifier name, stmt* body)
2525
| Block(symbol_table symtab, identifier name, stmt* body)
@@ -35,7 +35,7 @@ stmt
3535
| Cycle(identifier? stmt_name)
3636
| ExplicitDeallocate(expr* vars)
3737
| ImplicitDeallocate(expr* vars)
38-
| DoConcurrentLoop(do_loop_head head, stmt* body)
38+
| DoConcurrentLoop(do_loop_head* head, expr* shared, expr* local, reduction_expr* reduction, stmt* body)
3939
| DoLoop(identifier? name, do_loop_head head, stmt* body, stmt* orelse)
4040
| ErrorStop(expr? code)
4141
| Exit(identifier? stmt_name)
@@ -45,23 +45,23 @@ stmt
4545
| GoToTarget(int id, identifier name)
4646
| If(expr test, stmt* body, stmt* orelse)
4747
| IfArithmetic(expr test, int lt_label, int eq_label, int gt_label)
48-
| Print(expr* values, expr? separator, expr? end)
48+
| Print(expr text)
4949
| FileOpen(int label, expr? newunit, expr? filename, expr? status, expr? form)
5050
| FileClose(int label, expr? unit, expr? iostat, expr? iomsg, expr? err, expr? status)
5151
| FileRead(int label, expr? unit, expr? fmt, expr? iomsg, expr? iostat, expr? size, expr? id, expr* values, stmt? overloaded)
5252
| FileBackspace(int label, expr? unit, expr? iostat, expr? err)
5353
| FileRewind(int label, expr? unit, expr? iostat, expr? err)
54-
| FileInquire(int label, expr? unit, expr? file, expr? iostat, expr? err, expr? exist, expr? opened, expr? number, expr? named, expr? name, expr? access, expr? sequential, expr? direct, expr? form, expr? formatted, expr? unformatted, expr? recl, expr? nextrec, expr? blank, expr? position, expr? action, expr? read, expr? write, expr? readwrite, expr? delim, expr? pad, expr? flen, expr? blocksize, expr? convert, expr? carriagecontrol, expr? iolength)
54+
| FileInquire(int label, expr? unit, expr? file, expr? iostat, expr? err, expr? exist, expr? opened, expr? number, expr? named, expr? name, expr? access, expr? sequential, expr? direct, expr? form, expr? formatted, expr? unformatted, expr? recl, expr? nextrec, expr? blank, expr? position, expr? action, expr? read, expr? write, expr? readwrite, expr? delim, expr? pad, expr? flen, expr? blocksize, expr? convert, expr? carriagecontrol, expr? size, expr? iolength)
5555
| FileWrite(int label, expr? unit, expr? iomsg, expr? iostat, expr? id, expr* values, expr? separator, expr? end, stmt? overloaded)
5656
| Return()
5757
| Select(expr test, case_stmt* body, stmt* default, bool enable_fall_through)
5858
| Stop(expr? code)
5959
| Assert(expr test, expr? msg)
6060
| SubroutineCall(symbol name, symbol? original_name, call_arg* args, expr? dt)
61-
| IntrinsicImpureSubroutine(int intrinsic_id, expr* args, int overload_id)
61+
| IntrinsicImpureSubroutine(int sub_intrinsic_id, expr* args, int overload_id)
6262
| Where(expr test, stmt* body, stmt* orelse)
6363
| WhileLoop(identifier? name, expr test, stmt* body, stmt* orelse)
64-
| Nullify(symbol* vars)
64+
| Nullify(expr* vars)
6565
| Flush(int label, expr unit, expr? err, expr? iomsg, expr? iostat)
6666
| ListAppend(expr a, expr ele)
6767
| AssociateBlockCall(symbol m)
@@ -89,11 +89,11 @@ expr
8989
| IntrinsicImpureFunction(int impure_intrinsic_id, expr* args, int overload_id, ttype? type, expr? value)
9090
| TypeInquiry(int inquiry_id, ttype arg_type, expr? arg, ttype type, expr value)
9191
| StructConstructor(symbol dt_sym, call_arg* args, ttype type, expr? value)
92-
| EnumTypeConstructor(symbol dt_sym, expr* args, ttype type, expr? value)
93-
| UnionTypeConstructor(symbol dt_sym, expr* args, ttype type, expr? value)
92+
| StructConstant(symbol dt_sym, call_arg* args, ttype type)
93+
| EnumConstructor(symbol dt_sym, expr* args, ttype type, expr? value)
94+
| UnionConstructor(symbol dt_sym, expr* args, ttype type, expr? value)
9495
| ImpliedDoLoop(expr* values, expr var, expr start, expr end, expr? increment, ttype type, expr? value)
95-
| IntegerConstant(int n, ttype type)
96-
| IntegerBOZ(int v, integerboz intboz_type, ttype? type)
96+
| IntegerConstant(int n, ttype type, integerboz intboz_type)
9797
| IntegerBitNot(expr arg, ttype type, expr? value)
9898
| IntegerUnaryMinus(expr arg, ttype type, expr? value)
9999
| IntegerCompare(expr left, cmpop op, expr right, ttype type, expr? value)
@@ -139,15 +139,16 @@ expr
139139
| StringContains(expr substr, expr str, ttype type, expr? value)
140140
| StringOrd(expr arg, ttype type, expr? value)
141141
| StringChr(expr arg, ttype type, expr? value)
142-
| StringFormat(expr fmt, expr* args, string_format_kind kind, ttype type, expr? value)
142+
| StringFormat(expr? fmt, expr* args, string_format_kind kind, ttype type, expr? value)
143+
| StringPhysicalCast(expr arg, string_physical_type old, string_physical_type new, ttype type, expr? value)
143144
| CPtrCompare(expr left, cmpop op, expr right, ttype type, expr? value)
144145
| SymbolicCompare(expr left, cmpop op, expr right, ttype type, expr? value)
145146
| DictConstant(expr* keys, expr* values, ttype type)
146147
| DictLen(expr arg, ttype type, expr? value)
147148
| Var(symbol v)
148149
| FunctionParam(int param_number, ttype type, expr? value)
149150
| ArrayConstructor(expr* args, ttype type, expr? value, arraystorage storage_format)
150-
| ArrayConstant(expr* args, ttype type, arraystorage storage_format)
151+
| ArrayConstant(int n_data, void data, ttype type, arraystorage storage_format)
151152
| ArrayItem(expr v, array_index* args, ttype type, arraystorage storage_format, expr? value)
152153
| ArraySection(expr v, array_index* args, ttype type, expr? value)
153154
| ArraySize(expr v, expr? dim, ttype type, expr? value)
@@ -191,21 +192,22 @@ expr
191192
| PointerNullConstant(ttype type)
192193
| PointerAssociated(expr ptr, expr? tgt, ttype type, expr? value)
193194
| RealSqrt(expr arg, ttype type, expr? value)
195+
| ArrayIsContiguous(expr array, ttype type, expr? value)
194196

195197
ttype
196198
= Integer(int kind)
197199
| UnsignedInteger(int kind)
198200
| Real(int kind)
199201
| Complex(int kind)
200-
| Character(int kind, int len, expr? len_expr)
202+
| String(int kind, int len, expr? len_expr, string_physical_type physical_type)
201203
| Logical(int kind)
202204
| Set(ttype type)
203205
| List(ttype type)
204206
| Tuple(ttype* type)
205207
| StructType(ttype* data_member_types, ttype* member_function_types, bool is_cstruct, symbol derived_type)
206-
| Enum(symbol enum_type)
207-
| Union(symbol union_type)
208-
| Class(symbol class_type)
208+
| EnumType(symbol enum_type)
209+
| UnionType(symbol union_type)
210+
| ClassType(symbol class_type)
209211
| Dict(ttype key_type, ttype value_type)
210212
| Pointer(ttype type)
211213
| Allocatable(ttype type)
@@ -215,7 +217,7 @@ ttype
215217
| Array(ttype type, dimension* dims, array_physical_type physical_type)
216218
| FunctionType(ttype* arg_types, ttype? return_var_type, abi abi, deftype deftype, string? bindc_name, bool elemental, bool pure, bool module, bool inline, bool static, symbol* restrictions, bool is_restriction)
217219

218-
cast_kind = RealToInteger | IntegerToReal | LogicalToReal | RealToReal | IntegerToInteger | RealToComplex | IntegerToComplex | IntegerToLogical | RealToLogical | CharacterToLogical | CharacterToInteger | CharacterToList | ComplexToLogical | ComplexToComplex | ComplexToReal | ComplexToInteger | LogicalToInteger | RealToCharacter | IntegerToCharacter | LogicalToCharacter | UnsignedIntegerToInteger | UnsignedIntegerToUnsignedInteger | UnsignedIntegerToReal | UnsignedIntegerToLogical | IntegerToUnsignedInteger | RealToUnsignedInteger | CPtrToUnsignedInteger | UnsignedIntegerToCPtr | IntegerToSymbolicExpression | ListToArray | DerivedToBase
220+
cast_kind = RealToInteger | IntegerToReal | LogicalToReal | RealToReal | IntegerToInteger | RealToComplex | IntegerToComplex | IntegerToLogical | RealToLogical | StringToLogical | StringToInteger | StringToList | ComplexToLogical | ComplexToComplex | ComplexToReal | ComplexToInteger | LogicalToInteger | RealToString | IntegerToString | LogicalToString | UnsignedIntegerToInteger | UnsignedIntegerToUnsignedInteger | UnsignedIntegerToReal | UnsignedIntegerToLogical | IntegerToUnsignedInteger | RealToUnsignedInteger | CPtrToUnsignedInteger | UnsignedIntegerToCPtr | IntegerToSymbolicExpression | ListToArray
219221
storage_type = Default | Save | Parameter
220222
access = Public | Private
221223
intent = Local | In | Out | InOut | ReturnVar | Unspecified
@@ -227,18 +229,21 @@ alloc_arg = (expr a, dimension* dims, expr? len_expr, ttype? type)
227229
attribute = Attribute(identifier name, attribute_arg *args)
228230
attribute_arg = (identifier arg)
229231
call_arg = (expr? value)
232+
reduction_expr = (reduction_op op, expr arg)
230233
tbind = Bind(string lang, string name)
231234
array_index = (expr? left, expr? right, expr? step)
232235
do_loop_head = (expr? v, expr? start, expr? end, expr? increment)
233236
case_stmt = CaseStmt(expr* test, stmt* body, bool fall_through) | CaseStmt_Range(expr? start, expr? end, stmt* body)
234237
type_stmt = TypeStmtName(symbol sym, stmt* body) | ClassStmt(symbol sym, stmt* body) | TypeStmtType(ttype type, stmt* body)
235238
enumtype = IntegerConsecutiveFromZero | IntegerUnique | IntegerNotUnique | NonInteger
236239
require_instantiation = Require(identifier name, identifier* args)
237-
array_physical_type = DescriptorArray | PointerToDataArray | UnboundedPointerToDataArray | FixedSizeArray | CharacterArraySinglePointer | NumPyArray | ISODescriptorArray | SIMDArray
240+
array_physical_type = DescriptorArray | PointerToDataArray | UnboundedPointerToDataArray | FixedSizeArray | StringArraySinglePointer | NumPyArray | ISODescriptorArray | SIMDArray
241+
string_physical_type = PointerString | DescriptorString
238242
binop = Add | Sub | Mul | Div | Pow | BitAnd | BitOr | BitXor | BitLShift | BitRShift
243+
reduction_op = ReduceAdd | ReduceSub | ReduceMul | ReduceMIN | ReduceMAX
239244
logicalbinop = And | Or | Xor | NEqv | Eqv
240245
cmpop = Eq | NotEq | Lt | LtE | Gt | GtE
241-
integerboz = Binary | Hex | Octal
246+
integerboz = Binary | Hex | Octal | Decimal
242247
arraybound = LBound | UBound
243248
arraystorage = RowMajor | ColMajor
244249
string_format_kind = FormatFortran | FormatC | FormatPythonPercent | FormatPythonFString | FormatPythonFormat

src/libasr/CMakeLists.txt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ if (NOT LFORTRAN_VERSION)
1212
CACHE STRING "LFortran version" FORCE)
1313
endif ()
1414

15-
configure_file(config.h.in config.h)
15+
configure_file(config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/config.h)
1616

1717
set(SRC
1818
codegen/asr_to_cpp.cpp
@@ -30,8 +30,11 @@ set(SRC
3030
codegen/wasm_utils.cpp
3131

3232
pass/nested_vars.cpp
33+
pass/array_struct_temporary.cpp
3334
pass/where.cpp
3435
pass/function_call_in_declaration.cpp
36+
pass/array_passed_in_function_call.cpp
37+
pass/openmp.cpp
3538
pass/param_to_const.cpp
3639
pass/do_loops.cpp
3740
pass/for_all.cpp
@@ -70,6 +73,7 @@ set(SRC
7073
pass/unique_symbols.cpp
7174
pass/insert_deallocate.cpp
7275
pass/promote_allocatable_to_nonallocatable.cpp
76+
pass/replace_with_compile_time_values.cpp
7377

7478
asr_verify.cpp
7579
asr_utils.cpp
@@ -81,6 +85,7 @@ set(SRC
8185
modfile.cpp
8286
pickle.cpp
8387
serialization.cpp
88+
stacktrace.cpp
8489
utils2.cpp
8590
)
8691
if (WITH_LLVM)
@@ -90,6 +95,9 @@ if (WITH_LLVM)
9095
codegen/llvm_array_utils.cpp
9196
codegen/llvm_utils.cpp
9297
)
98+
if (WITH_MLIR)
99+
set(SRC ${SRC} codegen/asr_to_mlir.cpp)
100+
endif()
93101
# We use deprecated API in LLVM, so we disable the warning until we upgrade
94102
if (NOT MSVC)
95103
set_source_files_properties(codegen/evaluator.cpp PROPERTIES
@@ -100,11 +108,16 @@ if (WITH_LLVM)
100108
COMPILE_FLAGS -Wno-deprecated-declarations)
101109
set_source_files_properties(codegen/llvm_utils.cpp PROPERTIES
102110
COMPILE_FLAGS -Wno-deprecated-declarations)
111+
set_source_files_properties(stacktrace.cpp PROPERTIES
112+
COMPILE_FLAGS -Wno-deprecated-declarations)
103113
endif()
104114
endif()
105115
add_library(asr STATIC ${SRC})
106116
target_include_directories(asr BEFORE PUBLIC ${libasr_SOURCE_DIR}/..)
107117
target_include_directories(asr BEFORE PUBLIC ${libasr_BINARY_DIR}/..)
118+
if (WITH_LIBUNWIND)
119+
target_link_libraries(asr p::libunwind)
120+
endif()
108121
if (WITH_BFD)
109122
target_link_libraries(asr p::bfd)
110123
endif()

src/libasr/asdl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
# See the EBNF at the top of the file to understand the logical connection
3434
# between the various node types.
3535

36-
builtin_types = {'identifier', 'string', 'int', 'bool', 'float', 'node', 'symbol_table'}
36+
builtin_types = {'identifier', 'string', 'int', 'bool', 'float', 'node', 'symbol_table', 'void', 'location'}
3737

3838
class AST:
3939
def __repr__(self):

0 commit comments

Comments
 (0)