Skip to content

Commit c2a3d42

Browse files
Merge branch 'main' into fix/import-alias
2 parents ee053ac + 0299465 commit c2a3d42

File tree

173 files changed

+1121
-288
lines changed

Some content is hidden

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

173 files changed

+1121
-288
lines changed

.github/workflows/CI.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on:
1010
branches:
1111
- main
1212
env:
13-
MACOSX_DEPLOYMENT_TARGET: 14.0
13+
MACOSX_DEPLOYMENT_TARGET: 15.0
1414

1515
jobs:
1616
Build:

integration_tests/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ RUN(NAME test_types_01 LABELS cpython llvm llvm_jit c)
529529
RUN(NAME test_types_02 LABELS cpython llvm llvm_jit c wasm)
530530
# RUN(NAME test_str_01 LABELS cpython llvm llvm_jit c)
531531
RUN(NAME test_str_02 LABELS cpython llvm llvm_jit) # renable c
532-
RUN(NAME test_str_03 LABELS cpython llvm llvm_jit) # renable c # post sync
532+
# RUN(NAME test_str_03 LABELS cpython llvm llvm_jit) # renable c # str negative indexing
533533
RUN(NAME test_str_04 LABELS cpython llvm llvm_jit) # renable c, wasm
534534
RUN(NAME test_str_05 LABELS cpython llvm llvm_jit) # renable c
535535
# RUN(NAME test_str_06 LABELS cpython llvm llvm_jit c)
@@ -542,7 +542,7 @@ RUN(NAME test_list_04 LABELS cpython llvm llvm_jit NOFAST) # renable c
542542
RUN(NAME test_list_06 LABELS cpython llvm llvm_jit c)
543543
RUN(NAME test_list_07 LABELS cpython llvm llvm_jit c NOFAST)
544544
RUN(NAME test_list_08 LABELS cpython llvm llvm_jit c NOFAST)
545-
# RUN(NAME test_list_09 LABELS cpython llvm llvm_jit c NOFAST)
545+
RUN(NAME test_list_09 LABELS cpython llvm llvm_jit NOFAST) # renable c
546546
# RUN(NAME test_list_10 LABELS cpython llvm llvm_jit c NOFAST)
547547
# RUN(NAME test_list_11 LABELS cpython llvm llvm_jit c)
548548
# RUN(NAME test_list_section LABELS cpython llvm llvm_jit c NOFAST)
@@ -761,8 +761,8 @@ RUN(NAME structs_35 LABELS cpython llvm llvm_jit)
761761
# RUN(NAME enum_02 LABELS cpython llvm llvm_jit NOFAST)
762762
RUN(NAME enum_03 LABELS cpython llvm llvm_jit c NOFAST)
763763
# RUN(NAME enum_04 LABELS cpython llvm llvm_jit c NOFAST)
764-
RUN(NAME enum_05 LABELS llvm c
765-
EXTRAFILES enum_05b.c NOFAST)
764+
# RUN(NAME enum_05 LABELS llvm c
765+
# EXTRAFILES enum_05b.c NOFAST)
766766
# RUN(NAME enum_06 LABELS cpython llvm llvm_jit c)
767767
RUN(NAME enum_07 IMPORT_PATH ..
768768
LABELS cpython llvm llvm_jit c NOFAST)

integration_tests/test_list_09.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from lpython import i32
22

3+
34
def test_list_concat():
45
x: list[i32] = []
56
y: list[i32] = []
@@ -10,39 +11,41 @@ def test_list_concat():
1011
x = [1, 2, 3]
1112
z = x + y
1213
for i in range(1, 4):
13-
assert z[i-1] == i
14+
assert z[i - 1] == i
1415

1516
x.clear()
1617
y = [6, 7, 8]
1718
z = x + y
1819
for i in range(1, 4):
19-
assert z[i-1] == i + 5
20+
assert z[i - 1] == i + 5
2021

2122
x = [1, 2, 3, 4, 5]
2223
z = x + y
2324
for i in range(1, 9):
24-
assert z[i-1] == i
25+
assert z[i - 1] == i
2526

26-
x.clear(); y.clear()
27+
x.clear()
28+
y.clear()
2729
for i in range(9, 51):
2830
x.append(i)
2931
for i in range(51, 101):
3032
y.append(i)
3133

3234
z = z + x + y
33-
x[0] = 0; x[1] = 0
35+
x[0] = 0
36+
x[1] = 0
3437
y.clear()
3538
for i in range(1, 100):
36-
assert z[i-1] == i
37-
39+
assert z[i - 1] == i
40+
3841
c: list[str]
3942
d: list[str]
40-
c = ['a', 'b']
41-
d = ['c', 'd', 'e']
43+
c = ["a", "b"]
44+
d = ["c", "d", "e"]
4245
c += d
4346
assert len(c) == 5
4447
for i in range(5):
45-
assert ord(c[i]) - ord('a') == i
48+
assert ord(c[i]) - ord("a") == i
4649

4750

4851
test_list_concat()

libasr

Submodule libasr updated 1735 files

src/bin/lpython.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ int emit_llvm(const std::string &infile,
791791
// ASR -> LLVM
792792
LCompilers::PythonCompiler fe(compiler_options);
793793
LCompilers::Result<std::unique_ptr<LCompilers::LLVMModule>>
794-
res = fe.get_llvm3(*asr, pass_manager, diagnostics, infile);
794+
res = fe.get_llvm3(*asr, pass_manager, diagnostics, lm, infile);
795795
std::cerr << diagnostics.render(lm, compiler_options);
796796
if (!res.ok) {
797797
LCOMPILERS_ASSERT(diagnostics.has_error())
@@ -1118,7 +1118,7 @@ int compile_python_using_llvm(
11181118
LCompilers::LLVMEvaluator e(compiler_options.target);
11191119
auto asr_to_llvm_start = std::chrono::high_resolution_clock::now();
11201120
LCompilers::Result<std::unique_ptr<LCompilers::LLVMModule>>
1121-
res = fe.get_llvm3(*asr, pass_manager, diagnostics, infile);
1121+
res = fe.get_llvm3(*asr, pass_manager, diagnostics, lm, infile);
11221122
auto asr_to_llvm_end = std::chrono::high_resolution_clock::now();
11231123
times.push_back(std::make_pair("ASR to LLVM", std::chrono::duration<double, std::milli>(asr_to_llvm_end - asr_to_llvm_start).count()));
11241124

@@ -1844,6 +1844,7 @@ int main(int argc, char *argv[])
18441844
bool separate_compilation = false;
18451845
bool to_jit = false;
18461846
bool disable_warnings = false;
1847+
bool hide_error_banner = false;
18471848

18481849
std::string arg_fmt_file;
18491850
// int arg_fmt_indent = 4;
@@ -1911,7 +1912,7 @@ int main(int argc, char *argv[])
19111912
app.add_flag("--time-report", time_report, "Show compilation time report");
19121913
app.add_flag("--static", static_link, "Create a static executable");
19131914
app.add_flag("--no-warnings", disable_warnings, "Turn off all warnings");
1914-
app.add_flag("--no-error-banner", compiler_options.no_error_banner, "Turn off error banner");
1915+
app.add_flag("--no-error-banner", hide_error_banner, "Turn off error banner");
19151916
app.add_option("--backend", arg_backend, "Select a backend (llvm, cpp, x86, wasm, wasm_x86, wasm_x64)")->capture_default_str();
19161917
app.add_flag("--enable-bounds-checking", compiler_options.bounds_checking, "Turn on index bounds checking");
19171918
app.add_flag("--openmp", compiler_options.openmp, "Enable openmp");
@@ -1993,6 +1994,10 @@ int main(int argc, char *argv[])
19931994
compiler_options.show_warnings = false;
19941995
}
19951996

1997+
if (hide_error_banner) {
1998+
compiler_options.show_error_banner = false;
1999+
}
2000+
19962001
if (arg_version) {
19972002
std::string version = LFORTRAN_VERSION;
19982003
std::cout << "LPython version: " << version << std::endl;

src/lpython/python_evaluator.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ Result<PythonCompiler::EvalResult> PythonCompiler::evaluate(
111111
run_fn = module_name + "global_stmts_" + std::to_string(eval_count) + "__";
112112

113113
Result<std::unique_ptr<LLVMModule>> res3 = get_llvm3(*asr,
114-
pass_manager, diagnostics, lm.files.back().in_filename);
114+
pass_manager, diagnostics, lm, lm.files.back().in_filename);
115115
std::unique_ptr<LCompilers::LLVMModule> m;
116116
if (res3.ok) {
117117
m = std::move(res3.result);
@@ -419,7 +419,7 @@ Result<std::unique_ptr<LLVMModule>> PythonCompiler::get_llvm2(
419419
return asr.error;
420420
}
421421
Result<std::unique_ptr<LLVMModule>> res = get_llvm3(*asr.result, pass_manager,
422-
diagnostics, lm.files.back().in_filename);
422+
diagnostics, lm, lm.files.back().in_filename);
423423
if (res.ok) {
424424
#ifdef HAVE_LFORTRAN_LLVM
425425
std::unique_ptr<LLVMModule> m = std::move(res.result);
@@ -437,10 +437,10 @@ Result<std::unique_ptr<LLVMModule>> PythonCompiler::get_llvm2(
437437
Result<std::unique_ptr<LLVMModule>> PythonCompiler::get_llvm3(
438438
#ifdef HAVE_LFORTRAN_LLVM
439439
ASR::TranslationUnit_t &asr, LCompilers::PassManager& lpm,
440-
diag::Diagnostics &diagnostics, const std::string &infile
440+
diag::Diagnostics &diagnostics, LCompilers::LocationManager &lm, const std::string &infile
441441
#else
442442
ASR::TranslationUnit_t &/*asr*/, LCompilers::PassManager&/*lpm*/,
443-
diag::Diagnostics &/*diagnostics*/,const std::string &/*infile*/
443+
diag::Diagnostics &/*diagnostics*/, LCompilers::LocationManager & /*lm*/, const std::string &/*infile*/
444444
#endif
445445
)
446446
{
@@ -463,7 +463,7 @@ Result<std::unique_ptr<LLVMModule>> PythonCompiler::get_llvm3(
463463
Result<std::unique_ptr<LCompilers::LLVMModule>> res
464464
= asr_to_llvm(asr, diagnostics,
465465
e->get_context(), al, lpm, compiler_options,
466-
run_fn, global_underscore_name, infile);
466+
run_fn, global_underscore_name, infile, lm);
467467
if (res.ok) {
468468
m = std::move(res.result);
469469
} else {

src/lpython/python_evaluator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class PythonCompiler
116116
diag::Diagnostics &diagnostics);
117117

118118
Result<std::unique_ptr<LLVMModule>> get_llvm3(ASR::TranslationUnit_t &asr,
119-
LCompilers::PassManager& lpm, diag::Diagnostics &diagnostics,
119+
LCompilers::PassManager& lpm, diag::Diagnostics &diagnostics, LCompilers::LocationManager& lm,
120120
const std::string &infile);
121121

122122
Result<std::string> get_asm(const std::string &code,

src/lpython/semantics/python_ast_to_asr.cpp

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,7 @@ class CommonVisitor : public AST::BaseVisitor<StructType> {
10841084
ASR::symbol_t* variable_sym = ASR::down_cast<ASR::symbol_t>(variable_asr);
10851085
current_scope->add_symbol(dummy_ret_name, variable_sym);
10861086
ASR::expr_t* variable_var = ASRUtils::EXPR(ASR::make_Var_t(al, expr->base.loc, variable_sym));
1087-
return ASR::make_Assignment_t(al, expr->base.loc, variable_var, expr, nullptr, false);
1087+
return ASRUtils::make_Assignment_t_util(al, expr->base.loc, variable_var, expr, nullptr, false, false);
10881088
}
10891089

10901090
// Function to create appropriate call based on symbol type. If it is external
@@ -2609,8 +2609,8 @@ class CommonVisitor : public AST::BaseVisitor<StructType> {
26092609
is_runtime_expression) && !is_variable_const) {
26102610
ASR::expr_t* v_expr = ASRUtils::EXPR(ASR::make_Var_t(al, loc, v_sym));
26112611
cast_helper(v_expr, init_expr, true);
2612-
ASR::asr_t* assign = ASR::make_Assignment_t(al, loc, v_expr,
2613-
init_expr, nullptr, false);
2612+
ASR::asr_t* assign = ASRUtils::make_Assignment_t_util(al, loc, v_expr,
2613+
init_expr, nullptr, false, false);
26142614
if (current_body) {
26152615
current_body->push_back(al, ASRUtils::STMT(assign));
26162616
} else if (ASR::is_a<ASR::List_t>(*type) || is_runtime_expression) {
@@ -2705,7 +2705,7 @@ class CommonVisitor : public AST::BaseVisitor<StructType> {
27052705
dims.push_back(al, dim);
27062706
ASR::ttype_t* type = ASRUtils::make_Array_t_util(al, loc,
27072707
ASRUtils::expr_type(lbs[0]), dims.p, dims.size(), ASR::abiType::Source,
2708-
false, ASR::array_physical_typeType::PointerToDataArray, true);
2708+
false, ASR::array_physical_typeType::PointerArray, true);
27092709
return ASRUtils::EXPR(ASRUtils::make_ArrayConstructor_t_util(al,
27102710
loc, lbs.p, lbs.size(), type,
27112711
ASR::arraystorageType::RowMajor));
@@ -5339,7 +5339,7 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
53395339
ASR::symbol_t* call_sym = get_struct_member(parent_sym,call_name,loc);
53405340
super_call_stmt = ASRUtils::STMT(
53415341
ASR::make_SubroutineCall_t(al, loc, call_sym, call_sym, args_w_first.p,
5342-
args_w_first.size(), nullptr));
5342+
args_w_first.size(), nullptr, true));
53435343
}
53445344
} else {
53455345
body.push_back(al, x.m_body[i]);
@@ -5721,8 +5721,8 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
57215721
x.base.base.loc);
57225722
}
57235723
tmp = nullptr;
5724-
tmp_vec.push_back(ASR::make_Assignment_t(al, x.base.base.loc, target,
5725-
tmp_value, nullptr, false));
5724+
tmp_vec.push_back(ASRUtils::make_Assignment_t_util(al, x.base.base.loc, target,
5725+
tmp_value, nullptr, false, false));
57265726
continue;
57275727
}
57285728
if( ASRUtils::is_const(target) ) {
@@ -5763,8 +5763,8 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
57635763
throw SemanticError("Only Class constructor is allowed in the object assignment for now", target->base.loc);
57645764
}
57655765
}
5766-
tmp_vec.push_back(ASR::make_Assignment_t(al, x.base.base.loc, target, tmp_value,
5767-
overloaded, false));
5766+
tmp_vec.push_back(ASRUtils::make_Assignment_t_util(al, x.base.base.loc, target, tmp_value,
5767+
overloaded, false, false));
57685768
if ( target->type == ASR::exprType::Var &&
57695769
tmp_value->type == ASR::exprType::StructConstructor ) {
57705770
AST::Call_t* call = AST::down_cast<AST::Call_t>(x.m_value);
@@ -6057,9 +6057,9 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
60576057
current_scope->add_symbol(tmp_assign_name, tmp_assign_variable_sym);
60586058

60596059
// Assign the Subscript expr to temporary variable
6060-
ASR::asr_t* assign = ASR::make_Assignment_t(al, x.base.base.loc,
6060+
ASR::asr_t* assign = ASRUtils::make_Assignment_t_util(al, x.base.base.loc,
60616061
ASRUtils::EXPR(ASR::make_Var_t(al, x.base.base.loc, tmp_assign_variable_sym)),
6062-
target, nullptr, false);
6062+
target, nullptr, false, false);
60636063
if (current_body != nullptr) {
60646064
current_body->push_back(al, ASRUtils::STMT(assign));
60656065
} else {
@@ -6095,9 +6095,9 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
60956095
current_scope->add_symbol(tmp_assign_name, tmp_assign_variable_sym);
60966096

60976097
// Assign the List expr to temporary variable
6098-
ASR::asr_t* assign = ASR::make_Assignment_t(al, x.base.base.loc,
6098+
ASR::asr_t* assign = ASRUtils::make_Assignment_t_util(al, x.base.base.loc,
60996099
ASRUtils::EXPR(ASR::make_Var_t(al, x.base.base.loc, tmp_assign_variable_sym)),
6100-
target, nullptr, false);
6100+
target, nullptr, false, false);
61016101
if (current_body != nullptr) {
61026102
current_body->push_back(al, ASRUtils::STMT(assign));
61036103
} else {
@@ -6150,7 +6150,8 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
61506150
al, x.base.base.loc, loop_src_var,
61516151
ASRUtils::EXPR(explicit_iter_var), ASRUtils::get_contained_type(loop_src_var_ttype), nullptr);
61526152
}
6153-
auto loop_target_assignment = ASR::make_Assignment_t(al, x.base.base.loc, target, ASRUtils::EXPR(loop_src_var_element), nullptr, false);
6153+
auto loop_target_assignment = ASRUtils::make_Assignment_t_util(al, x.base.base.loc, target,
6154+
ASRUtils::EXPR(loop_src_var_element), nullptr, false, false);
61546155
body.push_back(al, ASRUtils::STMT(loop_target_assignment));
61556156

61566157
head.m_v = ASRUtils::EXPR(explicit_iter_var);
@@ -6275,7 +6276,7 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
62756276

62766277
ASR::stmt_t* a_overloaded = nullptr;
62776278
ASR::expr_t *tmp2 = ASR::down_cast<ASR::expr_t>(tmp);
6278-
tmp = ASR::make_Assignment_t(al, x.base.base.loc, left, tmp2, a_overloaded, false);
6279+
tmp = ASRUtils::make_Assignment_t_util(al, x.base.base.loc, left, tmp2, a_overloaded, false, false);
62796280

62806281
}
62816282

@@ -7259,8 +7260,8 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
72597260
}
72607261
cast_helper(target, value, true);
72617262
ASR::stmt_t *overloaded=nullptr;
7262-
tmp = ASR::make_Assignment_t(al, x.base.base.loc, target, value,
7263-
overloaded, false);
7263+
tmp = ASRUtils::make_Assignment_t_util(al, x.base.base.loc, target, value,
7264+
overloaded, false, false);
72647265
// if( ASR::is_a<ASR::Const_t>(*ASRUtils::symbol_type(return_var)) ) {
72657266
// ASR::Variable_t* return_variable = ASR::down_cast<ASR::Variable_t>(return_var);
72667267
// return_variable->m_symbolic_value = value;
@@ -7361,8 +7362,8 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
73617362
ASR::expr_t* cptr = ASRUtils::EXPR(tmp);
73627363
ASR::asr_t* pp = ASR::make_PointerToCPtr_t(al, x.base.base.loc, pptr,
73637364
ASRUtils::expr_type(cptr), nullptr);
7364-
return ASR::make_Assignment_t(al, x.base.base.loc,
7365-
cptr, ASR::down_cast<ASR::expr_t>(pp), nullptr, false);
7365+
return ASRUtils::make_Assignment_t_util(al, x.base.base.loc,
7366+
cptr, ASR::down_cast<ASR::expr_t>(pp), nullptr, false, false);
73667367
}
73677368

73687369
void handle_string_attributes(ASR::expr_t *s_var,
@@ -8911,7 +8912,7 @@ we will have to use something else.
89118912
make_Integer_t, 0, 4, dim.loc);
89128913
dims.push_back(al, dim);
89138914
type = ASRUtils::make_Array_t_util(al, x.base.base.loc, type, dims.p, dims.size(),
8914-
ASR::abiType::Source, false, ASR::array_physical_typeType::PointerToDataArray, true);
8915+
ASR::abiType::Source, false, ASR::array_physical_typeType::PointerArray, true);
89158916
for( size_t i = 0; i < n_args; i++ ) {
89168917
m_args[i] = CastingUtil::perform_casting(m_args[i], ASRUtils::type_get_past_array(type),
89178918
al, x.base.base.loc);

tests/reference/asr-array_01_decl-39cf894.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"outfile": null,
77
"outfile_hash": null,
88
"stdout": "asr-array_01_decl-39cf894.stdout",
9-
"stdout_hash": "195a4d1ca41ba5c8ed64f7af675a59ef0100f236e0f63fcbb6c771aa",
9+
"stdout_hash": "5bc6bef74c19e3ab954672c7b77c461beab78c936732fed4116ab0f3",
1010
"stderr": null,
1111
"stderr_hash": null,
1212
"returncode": 0

0 commit comments

Comments
 (0)