Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@jit interface for LPython #1708

Merged
merged 6 commits into from
May 10, 2023
Prev Previous commit
Next Next commit
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 <intelligent24harsh@gmail.com>
  • Loading branch information
Thirumalai-Shaktivel and harshsingh-24 committed May 10, 2023
commit cb7247189f929af9739cfb1cef10ef48731fbc92
21 changes: 21 additions & 0 deletions src/runtime/lpython/lpython.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,3 +514,24 @@ def ccallable(f):

def ccallback(f):
return f

class jit:
def __init__(self, function):
self.fn_name = function.__name__
# Get the source code of the function
source_code = getsource(function)
source_code = source_code[source_code.find('\n'):]

# TODO: Create a filename based on the function name
# filename = function.__name__ + ".py"

# Open the file for writing
with open("a.py", "w") as file:
# Write the Python source code to the file
file.write("@ccallable")
file.write(source_code)

# ----------------------------------------------------------------------
# TODO: Use LLVM instead of C backend
r = os.system("lpython --show-c --disable-main a.py > a.h")
assert r == 0, "Failed to create C file"