Skip to content

Commit f3f2427

Browse files
authored
Merge branch 'main' into builtin2
2 parents c1645fe + 27ee768 commit f3f2427

27 files changed

+609
-337
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# LFortran
22

33
src/bin/lpython
4-
src/bin/cpptranslate
54
src/bin/parse
65
src/bin/parse2
76
src/lpython/parser/parser.output

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ Run tests:
5757
ctest
5858
./run_tests.py
5959

60+
Also, run the integration tests:
61+
62+
./integration_tests/run_tests.py
63+
6064
## Examples
6165

6266
You can run the following examples by hand in a terminal:

ci/build.xsh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,8 @@ cd ../..
6363
jupyter kernelspec list --json
6464

6565
cp lpython-$lpython_version/test-bld/src/bin/lpython src/bin
66-
cp lpython-$lpython_version/test-bld/src/bin/cpptranslate src/bin
6766
if $WIN == "1":
68-
cp lpython-$lpython_version/test-bld/src/runtime/legacy/lfortran_runtime* src/runtime/
67+
cp lpython-$lpython_version/test-bld/src/runtime/lfortran_runtime* src/runtime/
6968
else:
7069
cp lpython-$lpython_version/test-bld/src/runtime/liblfortran_runtime* src/runtime/
7170
cp lpython-$lpython_version/test-bld/src/runtime/*.mod src/runtime/

integration_tests/run_tests.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"test_math.py",
1616
#"test_builtin.py",
1717
"test_builtin_abs.py",
18+
"test_math1.py"
1819
]
1920

2021
def main():

integration_tests/test_builtin_abs.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ def test_abs():
66
assert abs(x) == 5.5
77
x = -5.5
88
assert abs(x) == 5.5
9+
assert abs(5.5) == 5.5
10+
assert abs(-5.5) == 5.5
911

1012

1113
test_abs()

integration_tests/test_math1.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import math
2+
3+
def f():
4+
i: i32
5+
i = math.factorial(3)
6+
print(i)
7+
assert i == 6
8+
9+
f()

src/bin/CMakeLists.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ install(TARGETS lpython
131131
LIBRARY DESTINATION share/lpython/lib
132132
)
133133

134-
135-
add_executable(cpptranslate cpptranslate.cpp)
136-
target_link_libraries(cpptranslate lfortran_lib)
134+
set_target_properties(lpython PROPERTIES
135+
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/$<0:>
136+
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/$<0:>
137+
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/$<0:>)

src/bin/cpptranslate.cpp

Lines changed: 0 additions & 85 deletions
This file was deleted.

src/libasr/asr_utils.h

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,35 @@ static inline std::string unop_to_str(const ASR::unaryopType t) {
153153
}
154154
}
155155

156+
static inline std::string binop_to_str(const ASR::binopType t) {
157+
switch (t) {
158+
case (ASR::binopType::Add): { return " + "; }
159+
case (ASR::binopType::Sub): { return " - "; }
160+
case (ASR::binopType::Mul): { return "*"; }
161+
case (ASR::binopType::Div): { return "/"; }
162+
default : throw LFortranException("Cannot represent the binary operator as a string");
163+
}
164+
}
165+
156166
static inline std::string cmpop_to_str(const ASR::cmpopType t) {
157167
switch (t) {
158-
case (ASR::cmpopType::Eq): { return "=="; }
159-
case (ASR::cmpopType::NotEq): { return "!="; }
160-
case (ASR::cmpopType::Lt): { return "<"; }
161-
case (ASR::cmpopType::LtE): { return "<="; }
162-
case (ASR::cmpopType::Gt): { return ">"; }
163-
case (ASR::cmpopType::GtE): { return ">="; }
164-
default : throw LFortranException("Not implemented");
168+
case (ASR::cmpopType::Eq): { return " == "; }
169+
case (ASR::cmpopType::NotEq): { return " != "; }
170+
case (ASR::cmpopType::Lt): { return " < "; }
171+
case (ASR::cmpopType::LtE): { return " <= "; }
172+
case (ASR::cmpopType::Gt): { return " > "; }
173+
case (ASR::cmpopType::GtE): { return " >= "; }
174+
default : throw LFortranException("Cannot represent the comparison as a string");
175+
}
176+
}
177+
178+
static inline std::string boolop_to_str(const ASR::boolopType t) {
179+
switch (t) {
180+
case (ASR::boolopType::And): { return " && "; }
181+
case (ASR::boolopType::Or): { return " || "; }
182+
case (ASR::boolopType::Eqv): { return " == "; }
183+
case (ASR::boolopType::NEqv): { return " != "; }
184+
default : throw LFortranException("Cannot represent the boolean operator as a string");
165185
}
166186
}
167187

@@ -348,6 +368,18 @@ static inline bool is_intrinsic_function(const ASR::Function_t *fn) {
348368
return false;
349369
}
350370

371+
// Returns true if the Function is intrinsic, otherwise false
372+
// This version uses the `intrinsic` member of `Module`, so it
373+
// should be used instead of is_intrinsic_function
374+
static inline bool is_intrinsic_function2(const ASR::Function_t *fn) {
375+
ASR::symbol_t *sym = (ASR::symbol_t*)fn;
376+
ASR::Module_t *m = get_sym_module0(sym);
377+
if (m != nullptr) {
378+
if (m->m_intrinsic) return true;
379+
}
380+
return false;
381+
}
382+
351383
// Returns true if all arguments have a `value`
352384
static inline bool all_args_have_value(const Vec<ASR::expr_t*> &args) {
353385
for (auto &a : args) {

0 commit comments

Comments
 (0)