forked from M-Labs/nac3
1
0
Fork 0
nac3/nac3embedded/language.py

30 lines
755 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 nac3embedded
2021-09-23 19:30:03 +08:00
__all__ = ["kernel"]
2020-12-18 23:44:45 +08:00
2021-09-23 19:30:03 +08:00
nac3 = nac3embedded.NAC3()
allow_class_registration = True
2020-12-18 23:44:45 +08:00
2021-09-23 19:30:03 +08:00
def kernel(function_or_class):
global allow_class_registration
if isclass(function_or_class):
assert allow_class_registration
nac3.register_class(function_or_class)
return function_or_class
else:
@wraps(function_or_class)
def run_on_core(self, *args, **kwargs):
global allow_class_registration
if allow_class_registration:
nac3.analyze()
allow_class_registration = False
nac3.compile_method(self.__class__.__name__, function_or_class.__name__)
return run_on_core