forked from lcompilers/lpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request lcompilers#1393 from Smit-create/test_import_c
C: Enable import tests
- Loading branch information
Showing
10 changed files
with
133 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,13 @@ | ||
from test_import.import_module_01 import multiply, e | ||
from test_import.import_module_02 import add, μ | ||
|
||
print(e) | ||
print(μ) | ||
print(add(10, 20)) | ||
print(multiply(10, 20)) | ||
|
||
def f(): | ||
print(e) | ||
print(μ) | ||
print(add(10, 20)) | ||
print(multiply(10, 20)) | ||
assert add(10, 20) == 30 | ||
assert multiply(10, 20) == 200 | ||
|
||
f() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import test_modules | ||
|
||
def main0(): | ||
print(test_modules.sin(0.5)) | ||
print(test_modules.cos(0.5)) | ||
assert abs(test_modules.sin(0.5) + test_modules.cos(0.5) - 1.0) <= 1e-12 | ||
print(test_modules.sinx(0.5)) | ||
print(test_modules.cosx(0.5)) | ||
assert abs(test_modules.sinx(0.5) + test_modules.cosx(0.5) - 1.0) <= 1e-12 | ||
|
||
main0() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
from .mathfn import sin, cos | ||
from .mathfn import sinx, cosx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
from .sin import sin, cos | ||
from .sin import sinx, cosx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
from ltypes import f64 | ||
|
||
def sin(x: f64) -> f64: | ||
def sinx(x: f64) -> f64: | ||
return x + 1.0 | ||
|
||
def cos(x: f64) -> f64: | ||
def cosx(x: f64) -> f64: | ||
return x - 1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"basename": "c-test_import_02-d2c54c4", | ||
"cmd": "lpython --no-color --show-c {infile}", | ||
"infile": "tests/../integration_tests/test_import_02.py", | ||
"infile_hash": "cf2059987c7470ee617df897ed0d19906a9a8a94f05a5612570fce91", | ||
"outfile": null, | ||
"outfile_hash": null, | ||
"stdout": "c-test_import_02-d2c54c4.stdout", | ||
"stdout_hash": "f9b88f238f975b6430540713f230a55f96c2a161a1e4cc086beefb4a", | ||
"stderr": null, | ||
"stderr_hash": null, | ||
"returncode": 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#include <inttypes.h> | ||
|
||
#include <stdlib.h> | ||
#include <stdbool.h> | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include <lfortran_intrinsics.h> | ||
|
||
#define ASSERT(cond) \ | ||
{ \ | ||
if (!(cond)) { \ | ||
printf("%s%s", "ASSERT failed: ", __FILE__); \ | ||
printf("%s%s", "\nfunction ", __func__); \ | ||
printf("%s%d%s", "(), line number ", __LINE__, " at \n"); \ | ||
printf("%s%s", #cond, "\n"); \ | ||
exit(1); \ | ||
} \ | ||
} | ||
#define ASSERT_MSG(cond, msg) \ | ||
{ \ | ||
if (!(cond)) { \ | ||
printf("%s%s", "ASSERT failed: ", __FILE__); \ | ||
printf("%s%s", "\nfunction ", __func__); \ | ||
printf("%s%d%s", "(), line number ", __LINE__, " at \n"); \ | ||
printf("%s%s", #cond, "\n"); \ | ||
printf("%s", "ERROR MESSAGE:\n"); \ | ||
printf("%s%s", msg, "\n"); \ | ||
exit(1); \ | ||
} \ | ||
} | ||
|
||
|
||
struct dimension_descriptor | ||
{ | ||
int32_t lower_bound, length; | ||
}; | ||
|
||
// Implementations | ||
#define e 2.71828182845904509e+00 | ||
|
||
int32_t multiply(int32_t x, int32_t y) | ||
{ | ||
int32_t _lpython_return_variable; | ||
_lpython_return_variable = x*y; | ||
return _lpython_return_variable; | ||
} | ||
|
||
#define μ 1.45136923488338110e+00 | ||
|
||
int32_t add(int32_t x, int32_t y) | ||
{ | ||
int32_t _lpython_return_variable; | ||
_lpython_return_variable = x + y; | ||
return _lpython_return_variable; | ||
} | ||
|
||
void f() | ||
{ | ||
printf("%lf\n", e); | ||
printf("%lf\n", μ); | ||
printf("%d\n", add(10, 20)); | ||
printf("%d\n", multiply(10, 20)); | ||
ASSERT(add(10, 20) == 30); | ||
ASSERT(multiply(10, 20) == 200); | ||
} | ||
|
||
void _lpython_main_program() | ||
{ | ||
f(); | ||
} | ||
|
||
int main(int argc, char* argv[]) | ||
{ | ||
_lpython_main_program(); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters