nac3_sca/nac3artiq/language.py

36 lines
882 B
Python
Raw Normal View History

2021-09-23 19:30:03 +08:00
from inspect import isclass
2020-12-18 23:44:45 +08:00
from functools import wraps
import nac3artiq
2020-12-18 23:44:45 +08:00
2021-09-27 10:13:03 +08:00
__all__ = ["extern", "kernel"]
2020-12-18 23:44:45 +08:00
nac3 = nac3artiq.NAC3()
2021-09-24 11:39:26 +08:00
allow_object_registration = True
2021-09-27 10:13:03 +08:00
def extern(function):
2021-09-24 11:39:26 +08:00
assert allow_object_registration
nac3.register_object(function)
return function
2020-12-18 23:44:45 +08:00
2021-09-23 19:30:03 +08:00
def kernel(function_or_class):
2021-09-24 11:39:26 +08:00
global allow_object_registration
2021-09-23 19:30:03 +08:00
if isclass(function_or_class):
2021-09-24 11:39:26 +08:00
assert allow_object_registration
nac3.register_object(function_or_class)
2021-09-23 19:30:03 +08:00
return function_or_class
else:
@wraps(function_or_class)
def run_on_core(self, *args, **kwargs):
2021-09-24 11:39:26 +08:00
global allow_object_registration
if allow_object_registration:
2021-09-23 19:30:03 +08:00
nac3.analyze()
2021-09-24 11:39:26 +08:00
allow_object_registration = False
2021-09-23 19:30:03 +08:00
nac3.compile_method(self.__class__.__name__, function_or_class.__name__)
return run_on_core