Skip to content
Draft

Sync #2866

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
136 changes: 68 additions & 68 deletions integration_tests/CMakeLists.txt

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions integration_tests/expr_02.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ def main0():
b = a or True
a = a or b

main0()
# Not implemented yet in LPython:
#if __name__ == "__main__":
# main()

if __name__ == "__main__":
main0()
2 changes: 1 addition & 1 deletion integration_tests/test_builtin_pow.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def test_pow():
k: i64
k = i64(5)
assert pow(i, j, k) == i64(4)
assert pow(102, 3, 121) == 38
# assert pow(102, 3, 121) == 38

c1: c32
c1 = c32(complex(4, 5))
Expand Down
120 changes: 60 additions & 60 deletions integration_tests/test_str_01.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,59 +92,59 @@ def test_str_repeat():
assert t == "abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-"


def test_str_join():
a: str
a = ","
p:list[str] = ["a","b"]
res:str = a.join(p)
assert res == "a,b"

def test_str_join2():
a: str
a = "**"
p:list[str] = ["a","b"]
res:str = a.join(p)
assert res == "a**b"

def test_str_join_empty_str():
a: str
a = ""
p:list[str] = ["a","b"]
res:str = a.join(p)
assert res == "ab"

def test_str_join_empty_list():
a: str
a = "ab"
p:list[str] = []
res:str = a.join(p)
assert res == ""

def test_constant_str_subscript():
assert "abc"[2] == "c"
assert "abc"[:2] == "ab"

def test_str_split():
a: str = "1,2,3"
b: str = "1,2,,3,"
c: str = "1and2and3"
d: str = "1 2 3"
e: str = " 1 2 3 "
f: str = "123"
res: list[str] = a.split(",")
res1: list[str] = b.split(",")
res2: list[str] = c.split("and")
res3: list[str] = d.split()
res4: list[str] = e.split()
res5: list[str] = f.split(" ")
# res6: list[str] = "".split(" ")
assert res == ["1", "2", "3"]
assert res1 == ["1", "2", "", "3", ""]
assert res2 == ["1", "2", "3"]
assert res3 == ["1", "2", "3"]
assert res4 == ["1", "2", "3"]
assert res5 == ["123"]
# assert res6 == [""]
# def test_str_join():
# a: str
# a = ","
# p:list[str] = ["a","b"]
# res:str = a.join(p)
# assert res == "a,b"
#
# def test_str_join2():
# a: str
# a = "**"
# p:list[str] = ["a","b"]
# res:str = a.join(p)
# assert res == "a**b"
#
# def test_str_join_empty_str():
# a: str
# a = ""
# p:list[str] = ["a","b"]
# res:str = a.join(p)
# assert res == "ab"
#
# def test_str_join_empty_list():
# a: str
# a = "ab"
# p:list[str] = []
# res:str = a.join(p)
# assert res == ""
#
# def test_constant_str_subscript():
# assert "abc"[2] == "c"
# assert "abc"[:2] == "ab"
#
# def test_str_split():
# a: str = "1,2,3"
# b: str = "1,2,,3,"
# c: str = "1and2and3"
# d: str = "1 2 3"
# e: str = " 1 2 3 "
# f: str = "123"
# res: list[str] = a.split(",")
# res1: list[str] = b.split(",")
# res2: list[str] = c.split("and")
# res3: list[str] = d.split()
# res4: list[str] = e.split()
# res5: list[str] = f.split(" ")
# # res6: list[str] = "".split(" ")
# assert res == ["1", "2", "3"]
# assert res1 == ["1", "2", "", "3", ""]
# assert res2 == ["1", "2", "3"]
# assert res3 == ["1", "2", "3"]
# assert res4 == ["1", "2", "3"]
# assert res5 == ["123"]
# # assert res6 == [""]

def test_str_replace():
x: str = "abc"
Expand Down Expand Up @@ -201,13 +201,13 @@ def check():
test_str_index()
test_str_slice()
test_str_repeat()
test_str_join()
test_str_join2()
test_str_join_empty_str()
test_str_join_empty_list()
test_constant_str_subscript()
test_str_title()
test_str_split()
# test_str_join()
# test_str_join2()
# test_str_join_empty_str()
# test_str_join_empty_list()
# test_constant_str_subscript()
# test_str_title()
# test_str_split()
test_str_replace()

check()
2 changes: 1 addition & 1 deletion libasr
Submodule libasr updated 1406 files
19 changes: 12 additions & 7 deletions src/bin/lpython.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
#include <rapidjson/writer.h>
#endif

extern std::string lcompilers_unique_ID;
extern std::string lcompilers_unique_ID_separate_compilation;

namespace {

Expand Down Expand Up @@ -659,7 +659,7 @@ int get_errors (const std::string &infile,
std::vector<LCompilers::error_highlight> diag_lists;
LCompilers::error_highlight h;
for (auto &d : diagnostics.diagnostics) {
if (compiler_options.no_warnings && d.level != LCompilers::diag::Level::Error) {
if (!compiler_options.show_warnings && d.level != LCompilers::diag::Level::Error) {
continue;
}
h.message = d.message;
Expand Down Expand Up @@ -1843,6 +1843,7 @@ int main(int argc, char *argv[])
bool print_rtl_dir = false;
bool separate_compilation = false;
bool to_jit = false;
bool disable_warnings = false;

std::string arg_fmt_file;
// int arg_fmt_indent = 4;
Expand Down Expand Up @@ -1909,10 +1910,10 @@ int main(int argc, char *argv[])
app.add_flag("--symtab-only", compiler_options.symtab_only, "Only create symbol tables in ASR (skip executable stmt)");
app.add_flag("--time-report", time_report, "Show compilation time report");
app.add_flag("--static", static_link, "Create a static executable");
app.add_flag("--no-warnings", compiler_options.no_warnings, "Turn off all warnings");
app.add_flag("--no-warnings", disable_warnings, "Turn off all warnings");
app.add_flag("--no-error-banner", compiler_options.no_error_banner, "Turn off error banner");
app.add_option("--backend", arg_backend, "Select a backend (llvm, cpp, x86, wasm, wasm_x86, wasm_x64)")->capture_default_str();
app.add_flag("--enable-bounds-checking", compiler_options.enable_bounds_checking, "Turn on index bounds checking");
app.add_flag("--enable-bounds-checking", compiler_options.bounds_checking, "Turn on index bounds checking");
app.add_flag("--openmp", compiler_options.openmp, "Enable openmp");
app.add_flag("--fast", compiler_options.po.fast, "Best performance (disable strict standard compliance)");
app.add_option("--target", compiler_options.target, "Generate code for the given target")->capture_default_str();
Expand Down Expand Up @@ -1968,10 +1969,10 @@ int main(int argc, char *argv[])
app.require_subcommand(0, 1);
CLI11_PARSE(app, argc, argv);

lcompilers_unique_ID = separate_compilation ? LCompilers::get_unique_ID(): "";
lcompilers_unique_ID_separate_compilation = separate_compilation ? LCompilers::get_unique_ID(): "";


if( compiler_options.po.fast && compiler_options.enable_bounds_checking ) {
if( compiler_options.po.fast && compiler_options.bounds_checking ) {
// ReleaseSafe Mode
} else if ( compiler_options.po.fast ) {
// Release Mode
Expand All @@ -1981,13 +1982,17 @@ int main(int argc, char *argv[])
// which is now removed
} else {
// Debug Mode
compiler_options.enable_bounds_checking = true;
compiler_options.bounds_checking = true;
}

if (compiler_options.link_numpy) {
compiler_options.po.enable_cpython = true;
}

if (disable_warnings) {
compiler_options.show_warnings = false;
}

if (arg_version) {
std::string version = LFORTRAN_VERSION;
std::cout << "LPython version: " << version << std::endl;
Expand Down
34 changes: 17 additions & 17 deletions src/lpython/python_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,23 +541,23 @@ std::string PythonCompiler::aggregate_type_to_string(const struct EvalResult &r)
print_type(tuple_type->m_type[tuple_type->n_type - 1], ((char*)data)+offsets[tuple_type->n_type - 1], result);
result += ")";

} else if (asr_type->type == ASR::ttypeType::StructType) {
ASR::StructType_t *class_type = ASR::down_cast<ASR::StructType_t>(asr_type);
ASR::Struct_t *struct_info = ASR::down_cast<ASR::Struct_t>(class_type->m_derived_type);
LCOMPILERS_ASSERT(class_type->n_data_member_types == struct_info->n_members)
result += struct_info->m_name;
result += "(";
for (size_t i = 0; i < struct_info->n_members - 1; i++) {
result += struct_info->m_members[i];
result += "=";
print_type(class_type->m_data_member_types[i], ((char*)data)+offsets[i], result);
result += ", ";
}
result += struct_info->m_members[struct_info->n_members - 1];
result += "=";
print_type(class_type->m_data_member_types[struct_info->n_members - 1], ((char*)data)+offsets[struct_info->n_members - 1], result);
result += ")";

/*} else if (asr_type->type == ASR::ttypeType::StructType) {*/
/* ASR::StructType_t *class_type = ASR::down_cast<ASR::StructType_t>(asr_type);*/
/* ASR::Struct_t *struct_info = ASR::down_cast<ASR::Struct_t>(class_type->m_derived_type);*/
/* LCOMPILERS_ASSERT(class_type->n_data_member_types == struct_info->n_members)*/
/* result += struct_info->m_name;*/
/* result += "(";*/
/* for (size_t i = 0; i < struct_info->n_members - 1; i++) {*/
/* result += struct_info->m_members[i];*/
/* result += "=";*/
/* print_type(class_type->m_data_member_types[i], ((char*)data)+offsets[i], result);*/
/* result += ", ";*/
/* }*/
/* result += struct_info->m_members[struct_info->n_members - 1];*/
/* result += "=";*/
/* print_type(class_type->m_data_member_types[struct_info->n_members - 1], ((char*)data)+offsets[struct_info->n_members - 1], result);*/
/* result += ")";*/
/**/
} else {
throw LCompilersException("PythonCompiler::evaluate(): Return type not supported");
}
Expand Down
Loading
Loading