@@ -570,11 +570,13 @@ def get_data_type(t):
570
570
source_code = getsource (function )
571
571
source_code = source_code [source_code .find ('\n ' ):]
572
572
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
575
577
576
578
# Open the file for writing
577
- with open ("a .py" , "w" ) as file :
579
+ with open (filename + " .py" , "w" ) as file :
578
580
# Write the Python source code to the file
579
581
file .write ("@ccallable" )
580
582
file .write (source_code )
@@ -680,7 +682,7 @@ def get_data_type(t):
680
682
#include <numpy/ndarrayobject.h>
681
683
682
684
// LPython generated C code
683
- #include "a .h"
685
+ #include "{ self . fn_name } .h"
684
686
685
687
// Define the Python module and method mappings
686
688
static PyObject* define_module(PyObject* self, PyObject* args) {{
@@ -718,13 +720,14 @@ def get_data_type(t):
718
720
"""
719
721
# ----------------------------------------------------------------------
720
722
# Write the C source code to the file
721
- with open ("a .c" , "w" ) as file :
723
+ with open (filename + " .c" , "w" ) as file :
722
724
file .write (template )
723
725
724
726
# ----------------------------------------------------------------------
725
727
# Generate the Shared library
726
728
# 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" )
728
731
assert r == 0 , "Failed to create C file"
729
732
730
733
gcc_flags = ""
@@ -738,14 +741,15 @@ def get_data_type(t):
738
741
from numpy import get_include
739
742
from distutils .sysconfig import get_python_inc , get_python_lib
740
743
python_path = "-I" + get_python_inc () + " "
741
- numpy_path = "-I" + get_include ()
744
+ numpy_path = "-I" + get_include () + " "
742
745
rt_path_01 = "-I" + get_rtlib_dir () + "/../libasr/runtime "
743
746
rt_path_02 = "-L" + get_rtlib_dir () + " -Wl,-rpath " \
744
747
+ get_rtlib_dir () + " -llpython_runtime "
745
748
python_lib = "-L" + get_python_lib () + "/../.. -lpython3.10 -lm"
746
749
747
750
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 )
749
753
assert r == 0 , "Failed to create the shared library"
750
754
751
755
def __call__ (self , * args , ** kwargs ):
0 commit comments