builtup4/bu4/tracing/trace.py

32 lines
912 B
Python

# Copyright (c) PARRRATE T&V 2021. All rights reserved.
from bu4.combinatory.lic import EIC
from bu4.combinatory.lkc import EKC
from bu4.combinatory.lsc import ESC, ESC1, ESC2
from bu4.evaluation.constructs.edelayed import EDelayed
from bu4.evaluation.constructs.evalue import EValue
from bu4.evaluation.sync import sync
from bu4.indexing.evaluation.eilambda import EILambda
from bu4.linking.evaluation.ellambda import ELLambda
from bu4.tracing.probe import Probe
__all__ = ('trace', 'probe_index_reset',)
_probe_index = 0
def trace(lambda_: EValue):
global _probe_index
size = 0
while True:
if not isinstance(lambda_, (ELLambda, EILambda, EIC, EKC, ESC, ESC1, ESC2, EDelayed)):
return size, lambda_
lambda_ = sync(lambda_.call(Probe(_probe_index)))
_probe_index += 1
size += 1
def probe_index_reset():
global _probe_index
_probe_index = 0