Skip to content

Commit cb72471

Browse files
Jit Baseline implementation,
- Get the source code from Jit decorator and store it in a file - Create a C file using the --show-c option Co-authored-by: Harsh Singh Jadon <[email protected]>
1 parent 73bd468 commit cb72471

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/runtime/lpython/lpython.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,3 +514,24 @@ def ccallable(f):
514514

515515
def ccallback(f):
516516
return f
517+
518+
class jit:
519+
def __init__(self, function):
520+
self.fn_name = function.__name__
521+
# Get the source code of the function
522+
source_code = getsource(function)
523+
source_code = source_code[source_code.find('\n'):]
524+
525+
# TODO: Create a filename based on the function name
526+
# filename = function.__name__ + ".py"
527+
528+
# Open the file for writing
529+
with open("a.py", "w") as file:
530+
# Write the Python source code to the file
531+
file.write("@ccallable")
532+
file.write(source_code)
533+
534+
# ----------------------------------------------------------------------
535+
# TODO: Use LLVM instead of C backend
536+
r = os.system("lpython --show-c --disable-main a.py > a.h")
537+
assert r == 0, "Failed to create C file"

0 commit comments

Comments
 (0)