Skip to content

Commit d48b523

Browse files
Use unique name for the lpython decorator generated files
1 parent a9e9a33 commit d48b523

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ inst/bin/*
9090
*_lines.dat.txt
9191
*__tmp__generated__.c
9292
visualize*.html
93+
lpython_decorator*/
9394
a.c
9495
a.h
9596
a.py

src/runtime/lpython/lpython.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -570,11 +570,13 @@ def get_data_type(t):
570570
source_code = getsource(function)
571571
source_code = source_code[source_code.find('\n'):]
572572

573-
# TODO: Create a filename based on the function name
574-
# filename = function.__name__ + ".py"
573+
dir_name = "./lpython_decorator_" + self.fn_name
574+
if not os.path.exists(dir_name):
575+
os.mkdir(dir_name)
576+
filename = dir_name + "/" + self.fn_name
575577

576578
# Open the file for writing
577-
with open("a.py", "w") as file:
579+
with open(filename + ".py", "w") as file:
578580
# Write the Python source code to the file
579581
file.write("@ccallable")
580582
file.write(source_code)
@@ -680,7 +682,7 @@ def get_data_type(t):
680682
#include <numpy/ndarrayobject.h>
681683
682684
// LPython generated C code
683-
#include "a.h"
685+
#include "{self.fn_name}.h"
684686
685687
// Define the Python module and method mappings
686688
static PyObject* define_module(PyObject* self, PyObject* args) {{
@@ -718,13 +720,14 @@ def get_data_type(t):
718720
"""
719721
# ----------------------------------------------------------------------
720722
# Write the C source code to the file
721-
with open("a.c", "w") as file:
723+
with open(filename + ".c", "w") as file:
722724
file.write(template)
723725

724726
# ----------------------------------------------------------------------
725727
# Generate the Shared library
726728
# TODO: Use LLVM instead of C backend
727-
r = os.system("lpython --show-c --disable-main a.py > a.h")
729+
r = os.system("lpython --show-c --disable-main "
730+
+ filename + ".py > " + filename + ".h")
728731
assert r == 0, "Failed to create C file"
729732

730733
gcc_flags = ""
@@ -738,14 +741,15 @@ def get_data_type(t):
738741
from numpy import get_include
739742
from distutils.sysconfig import get_python_inc, get_python_lib
740743
python_path = "-I" + get_python_inc() + " "
741-
numpy_path = "-I" + get_include()
744+
numpy_path = "-I" + get_include() + " "
742745
rt_path_01 = "-I" + get_rtlib_dir() + "/../libasr/runtime "
743746
rt_path_02 = "-L" + get_rtlib_dir() + " -Wl,-rpath " \
744747
+ get_rtlib_dir() + " -llpython_runtime "
745748
python_lib = "-L" + get_python_lib() + "/../.. -lpython3.10 -lm"
746749

747750
r = os.system("gcc -g" + gcc_flags + python_path + numpy_path +
748-
" a.c -o lpython_jit_module.so " + rt_path_01 + rt_path_02 + python_lib)
751+
filename + ".c -o lpython_jit_module.so " +
752+
rt_path_01 + rt_path_02 + python_lib)
749753
assert r == 0, "Failed to create the shared library"
750754

751755
def __call__(self, *args, **kwargs):

0 commit comments

Comments
 (0)