nac3/nac3embedded/language.py

36 lines
888 B
Python

from inspect import isclass
from functools import wraps
import nac3embedded
__all__ = ["extern", "kernel"]
nac3 = nac3embedded.NAC3()
allow_object_registration = True
def extern(function):
assert allow_object_registration
nac3.register_object(function)
return function
def kernel(function_or_class):
global allow_object_registration
if isclass(function_or_class):
assert allow_object_registration
nac3.register_object(function_or_class)
return function_or_class
else:
@wraps(function_or_class)
def run_on_core(self, *args, **kwargs):
global allow_object_registration
if allow_object_registration:
nac3.analyze()
allow_object_registration = False
nac3.compile_method(self.__class__.__name__, function_or_class.__name__)
return run_on_core