ETraceable + better call optimizations
This commit is contained in:
parent
5965373353
commit
9ef7bc0543
2
.gitignore
vendored
2
.gitignore
vendored
@ -218,4 +218,4 @@ dmypy.json
|
|||||||
cython_debug/
|
cython_debug/
|
||||||
|
|
||||||
|
|
||||||
|
/compiled/
|
||||||
|
54
bu4/asynchronous/easync.py
Normal file
54
bu4/asynchronous/easync.py
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
# Copyright (c) PARRRATE T&V 2021. All rights reserved.
|
||||||
|
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
from bu4.evaluation.av.aftervalue import AfterValue
|
||||||
|
from bu4.evaluation.constructs.evaluable import Evaluable
|
||||||
|
from bu4.evaluation.constructs.evalue import EValue
|
||||||
|
from bu4.evaluation.targets.avanonymouscontainer import AVAnonymousContainer
|
||||||
|
from bu4.evaluation.targets.avcall import AVCall
|
||||||
|
from bu4.evaluation.targets.avtarget import AVTarget
|
||||||
|
|
||||||
|
__all__ = ('EAsync',)
|
||||||
|
|
||||||
|
|
||||||
|
class EAsync(EValue):
|
||||||
|
def __init__(self):
|
||||||
|
self.__anext: Optional[Evaluable] = None
|
||||||
|
|
||||||
|
def call(self, argument: Evaluable) -> Evaluable:
|
||||||
|
return AfterAsync(self, AVCall(argument))
|
||||||
|
|
||||||
|
async def _anext(self) -> Evaluable:
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
async def anext(self) -> Evaluable:
|
||||||
|
if self.__anext is None:
|
||||||
|
self.__anext = AVAnonymousContainer(await self._anext())
|
||||||
|
return self.__anext
|
||||||
|
|
||||||
|
|
||||||
|
class AfterAsync(EAsync):
|
||||||
|
easync: EAsync
|
||||||
|
target: AVTarget
|
||||||
|
|
||||||
|
def __init__(self, easync: EAsync, target: AVTarget):
|
||||||
|
self.easync = easync
|
||||||
|
self.target = target
|
||||||
|
super().__init__()
|
||||||
|
|
||||||
|
async def _anext(self) -> Evaluable:
|
||||||
|
if isinstance(self.easync, AfterAsync):
|
||||||
|
return AfterAsync(self.easync.easync, AAChain(self.easync, self.easync.target))
|
||||||
|
return AfterValue(await self.easync.anext(), self.target)
|
||||||
|
|
||||||
|
|
||||||
|
class AAChain(AVTarget):
|
||||||
|
def __init__(self, evaluable: AfterAsync, target: AVTarget):
|
||||||
|
if isinstance(evaluable.target, AAChain):
|
||||||
|
raise TypeError
|
||||||
|
self.evaluable = evaluable
|
||||||
|
self.target = target
|
||||||
|
|
||||||
|
def given(self, value: EValue) -> Evaluable:
|
||||||
|
return AfterValue(self.evaluable.target.given(value), self.target)
|
17
bu4/asynchronous/efuture.py
Normal file
17
bu4/asynchronous/efuture.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
# Copyright (c) PARRRATE T&V 2021. All rights reserved.
|
||||||
|
|
||||||
|
from typing import Awaitable
|
||||||
|
|
||||||
|
from bu4.asynchronous.easync import EAsync
|
||||||
|
from bu4.evaluation.constructs.evaluable import Evaluable
|
||||||
|
|
||||||
|
__all__ = ('EFuture',)
|
||||||
|
|
||||||
|
|
||||||
|
class EFuture(EAsync):
|
||||||
|
def __init__(self, future: Awaitable):
|
||||||
|
self.future = future
|
||||||
|
super().__init__()
|
||||||
|
|
||||||
|
async def _anext(self) -> Evaluable:
|
||||||
|
return await self.future
|
@ -3,11 +3,11 @@
|
|||||||
from bu4.combinatory.lcombinatory import LCombinatory
|
from bu4.combinatory.lcombinatory import LCombinatory
|
||||||
from bu4.encoding.codes import CODE_CMBI
|
from bu4.encoding.codes import CODE_CMBI
|
||||||
from bu4.evaluation.constructs.evaluable import Evaluable
|
from bu4.evaluation.constructs.evaluable import Evaluable
|
||||||
from bu4.evaluation.constructs.evalue import EValue
|
from bu4.evaluation.constructs.etraceable import ETraceable
|
||||||
from bu4.indexing.constructs.indexed import Indexed
|
from bu4.indexing.constructs.indexed import Indexed
|
||||||
from bu4.indexing.evaluation.eivtype import eivtype
|
from bu4.indexing.evaluation.eivtype import eivtype
|
||||||
from bu4.linking.evaluation.elvtype import elvtype
|
|
||||||
from bu4.linking.constructs.linked import Linked
|
from bu4.linking.constructs.linked import Linked
|
||||||
|
from bu4.linking.evaluation.elvtype import elvtype
|
||||||
from bu4.parsing.extensions.CodeExtension import CodeExtension
|
from bu4.parsing.extensions.CodeExtension import CodeExtension
|
||||||
from bu4.transform.states.transformfinished import TransformFinished
|
from bu4.transform.states.transformfinished import TransformFinished
|
||||||
from bu4.transform.states.transformstate import TransformState
|
from bu4.transform.states.transformstate import TransformState
|
||||||
@ -15,7 +15,7 @@ from bu4.transform.states.transformstate import TransformState
|
|||||||
__all__ = ('EIC', 'IIC', 'XII', 'LIC', 'XLI',)
|
__all__ = ('EIC', 'IIC', 'XII', 'LIC', 'XLI',)
|
||||||
|
|
||||||
|
|
||||||
class EIC(EValue):
|
class EIC(ETraceable):
|
||||||
def call(self, argument: Evaluable) -> Evaluable:
|
def call(self, argument: Evaluable) -> Evaluable:
|
||||||
return argument
|
return argument
|
||||||
|
|
||||||
|
@ -4,11 +4,11 @@ from bu4.combinatory.lcombinatory import LCombinatory
|
|||||||
from bu4.encoding.codes import CODE_CMBK
|
from bu4.encoding.codes import CODE_CMBK
|
||||||
from bu4.evaluation.constructs.edelayed import EDelayed
|
from bu4.evaluation.constructs.edelayed import EDelayed
|
||||||
from bu4.evaluation.constructs.evaluable import Evaluable
|
from bu4.evaluation.constructs.evaluable import Evaluable
|
||||||
from bu4.evaluation.constructs.evalue import EValue
|
from bu4.evaluation.constructs.etraceable import ETraceable
|
||||||
from bu4.indexing.constructs.indexed import Indexed
|
from bu4.indexing.constructs.indexed import Indexed
|
||||||
from bu4.indexing.evaluation.eivtype import eivtype
|
from bu4.indexing.evaluation.eivtype import eivtype
|
||||||
from bu4.linking.evaluation.elvtype import elvtype
|
|
||||||
from bu4.linking.constructs.linked import Linked
|
from bu4.linking.constructs.linked import Linked
|
||||||
|
from bu4.linking.evaluation.elvtype import elvtype
|
||||||
from bu4.parsing.extensions.CodeExtension import CodeExtension
|
from bu4.parsing.extensions.CodeExtension import CodeExtension
|
||||||
from bu4.transform.states.transformfinished import TransformFinished
|
from bu4.transform.states.transformfinished import TransformFinished
|
||||||
from bu4.transform.states.transformstate import TransformState
|
from bu4.transform.states.transformstate import TransformState
|
||||||
@ -16,7 +16,7 @@ from bu4.transform.states.transformstate import TransformState
|
|||||||
__all__ = ('EKC', 'IKC', 'XIK', 'LKC', 'XLK',)
|
__all__ = ('EKC', 'IKC', 'XIK', 'LKC', 'XLK',)
|
||||||
|
|
||||||
|
|
||||||
class EKC(EValue):
|
class EKC(ETraceable):
|
||||||
def call(self, argument: Evaluable) -> Evaluable:
|
def call(self, argument: Evaluable) -> Evaluable:
|
||||||
return EDelayed(argument)
|
return EDelayed(argument)
|
||||||
|
|
||||||
|
@ -4,13 +4,13 @@ from bu4.combinatory.lcombinatory import LCombinatory
|
|||||||
from bu4.encoding.codes import CODE_CMBS
|
from bu4.encoding.codes import CODE_CMBS
|
||||||
from bu4.evaluation.av.aftervalue import AfterValue
|
from bu4.evaluation.av.aftervalue import AfterValue
|
||||||
from bu4.evaluation.constructs.evaluable import Evaluable
|
from bu4.evaluation.constructs.evaluable import Evaluable
|
||||||
from bu4.evaluation.constructs.evalue import EValue
|
from bu4.evaluation.constructs.etraceable import ETraceable
|
||||||
from bu4.evaluation.targets.avanonymouscontainer import AVAnonymousContainer
|
from bu4.evaluation.targets.avanonymouscontainer import AVAnonymousContainer
|
||||||
from bu4.evaluation.targets.avcall import AVCall
|
from bu4.evaluation.targets.avcall import AVCall
|
||||||
from bu4.indexing.constructs.indexed import Indexed
|
from bu4.indexing.constructs.indexed import Indexed
|
||||||
from bu4.indexing.evaluation.eivtype import eivtype
|
from bu4.indexing.evaluation.eivtype import eivtype
|
||||||
from bu4.linking.evaluation.elvtype import elvtype
|
|
||||||
from bu4.linking.constructs.linked import Linked
|
from bu4.linking.constructs.linked import Linked
|
||||||
|
from bu4.linking.evaluation.elvtype import elvtype
|
||||||
from bu4.parsing.extensions.CodeExtension import CodeExtension
|
from bu4.parsing.extensions.CodeExtension import CodeExtension
|
||||||
from bu4.transform.states.transformfinished import TransformFinished
|
from bu4.transform.states.transformfinished import TransformFinished
|
||||||
from bu4.transform.states.transformstate import TransformState
|
from bu4.transform.states.transformstate import TransformState
|
||||||
@ -18,7 +18,7 @@ from bu4.transform.states.transformstate import TransformState
|
|||||||
__all__ = ('ESC', 'ESC1', 'ESC2', 'ISC', 'XIS', 'LSC', 'XLS',)
|
__all__ = ('ESC', 'ESC1', 'ESC2', 'ISC', 'XIS', 'LSC', 'XLS',)
|
||||||
|
|
||||||
|
|
||||||
class ESC2(EValue):
|
class ESC2(ETraceable):
|
||||||
def __init__(self, argument: Evaluable, lambda_: Evaluable):
|
def __init__(self, argument: Evaluable, lambda_: Evaluable):
|
||||||
self.argument = AVAnonymousContainer(argument).after_value
|
self.argument = AVAnonymousContainer(argument).after_value
|
||||||
self.lambda_ = lambda_
|
self.lambda_ = lambda_
|
||||||
@ -42,7 +42,7 @@ class ESC2(EValue):
|
|||||||
return f'/{self.argument}/{self.lambda_}S'
|
return f'/{self.argument}/{self.lambda_}S'
|
||||||
|
|
||||||
|
|
||||||
class ESC1(EValue):
|
class ESC1(ETraceable):
|
||||||
def __init__(self, lambda_: Evaluable):
|
def __init__(self, lambda_: Evaluable):
|
||||||
self.lambda_ = AVAnonymousContainer(lambda_).after_value
|
self.lambda_ = AVAnonymousContainer(lambda_).after_value
|
||||||
|
|
||||||
@ -53,7 +53,7 @@ class ESC1(EValue):
|
|||||||
return f'/{self.lambda_}S'
|
return f'/{self.lambda_}S'
|
||||||
|
|
||||||
|
|
||||||
class ESC(EValue):
|
class ESC(ETraceable):
|
||||||
def call(self, argument: Evaluable) -> Evaluable:
|
def call(self, argument: Evaluable) -> Evaluable:
|
||||||
return ESC1(argument)
|
return ESC1(argument)
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ def lccall(argument: Linked, lambda_: Linked) -> TransformState[Linked]:
|
|||||||
elif isinstance(argument, LCombinatory) and isinstance(lambda_, LCombinatory):
|
elif isinstance(argument, LCombinatory) and isinstance(lambda_, LCombinatory):
|
||||||
return TransformFinished(LCCall(argument, lambda_))
|
return TransformFinished(LCCall(argument, lambda_))
|
||||||
else:
|
else:
|
||||||
return TransformFinished(LCall(argument, lambda_))
|
return TransformFinished(LCall.new(argument, lambda_))
|
||||||
|
|
||||||
|
|
||||||
def to_combinatory(linked: Linked) -> TransformState[Linked]:
|
def to_combinatory(linked: Linked) -> TransformState[Linked]:
|
||||||
|
@ -15,11 +15,14 @@ class AfterValue(Evaluable):
|
|||||||
def next(self) -> Evaluable:
|
def next(self) -> Evaluable:
|
||||||
if isinstance(self.evaluable, EValue):
|
if isinstance(self.evaluable, EValue):
|
||||||
if isinstance(self.target, AVChain):
|
if isinstance(self.target, AVChain):
|
||||||
self.evaluable, self.target = self.target.target.given(self.evaluable), self.target.aftertarget
|
self.target.evaluable.evaluable = self.evaluable
|
||||||
|
self.evaluable, self.target = self.target.evaluable.target.given(
|
||||||
|
self.evaluable), self.target.target
|
||||||
return self
|
return self
|
||||||
return self.target.given(self.evaluable)
|
return self.target.given(self.evaluable)
|
||||||
if isinstance(self.evaluable, AfterValue):
|
if isinstance(self.evaluable, AfterValue):
|
||||||
self.evaluable, self.target = self.evaluable.evaluable, AVChain(self.evaluable.target, self.target)
|
self.evaluable, self.target = self.evaluable.evaluable, AVChain(self.evaluable, self.target)
|
||||||
|
del self.target.evaluable.evaluable
|
||||||
self.evaluable = self.evaluable.next()
|
self.evaluable = self.evaluable.next()
|
||||||
return self
|
return self
|
||||||
|
|
||||||
@ -28,12 +31,15 @@ class AfterValue(Evaluable):
|
|||||||
|
|
||||||
|
|
||||||
class AVChain(AVTarget):
|
class AVChain(AVTarget):
|
||||||
def __init__(self, target: AVTarget, aftertarget: AVTarget):
|
def __init__(self, evaluable: AfterValue, target: AVTarget):
|
||||||
|
if isinstance(evaluable.target, AVChain):
|
||||||
|
raise TypeError
|
||||||
|
self.evaluable = evaluable
|
||||||
self.target = target
|
self.target = target
|
||||||
self.aftertarget = aftertarget
|
|
||||||
|
|
||||||
def given(self, value: EValue) -> Evaluable:
|
def given(self, value: EValue) -> Evaluable:
|
||||||
return AfterValue(self.target.given(value), self.aftertarget)
|
self.evaluable.evaluable = value
|
||||||
|
return AfterValue(self.evaluable.target.given(value), self.target)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f'{self.target}->{self.aftertarget}'
|
return f'{self.evaluable.target}->{self.target}'
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
from typing import TypeVar
|
from typing import TypeVar
|
||||||
|
|
||||||
from bu4.evaluation.constructs.evaluable import Evaluable
|
from bu4.evaluation.constructs.evaluable import Evaluable
|
||||||
from bu4.evaluation.constructs.evalue import EValue
|
from bu4.evaluation.constructs.etraceable import ETraceable
|
||||||
from bu4.evaluation.targets.avanonymouscontainer import AVAnonymousContainer
|
from bu4.evaluation.targets.avanonymouscontainer import AVAnonymousContainer
|
||||||
|
|
||||||
__all__ = ('EDelayed',)
|
__all__ = ('EDelayed',)
|
||||||
@ -11,7 +11,7 @@ __all__ = ('EDelayed',)
|
|||||||
T = TypeVar('T')
|
T = TypeVar('T')
|
||||||
|
|
||||||
|
|
||||||
class EDelayed(EValue):
|
class EDelayed(ETraceable):
|
||||||
def __init__(self, evaluable: Evaluable):
|
def __init__(self, evaluable: Evaluable):
|
||||||
self.evaluable = AVAnonymousContainer(evaluable).after_value
|
self.evaluable = AVAnonymousContainer(evaluable).after_value
|
||||||
|
|
||||||
|
@ -1,17 +1,13 @@
|
|||||||
# Copyright (c) PARRRATE T&V 2021. All rights reserved.
|
# Copyright (c) PARRRATE T&V 2021. All rights reserved.
|
||||||
|
|
||||||
from bu4.evaluation.constructs.evaluable import Evaluable
|
from bu4.evaluation.constructs.evoid import EVoid
|
||||||
from bu4.evaluation.constructs.evalue import EValue
|
|
||||||
|
|
||||||
__all__ = ('EException',)
|
__all__ = ('EException',)
|
||||||
|
|
||||||
|
|
||||||
class EException(EValue):
|
class EException(EVoid):
|
||||||
def __init__(self, name: bytes):
|
def __init__(self, name: bytes):
|
||||||
self.name = name
|
self.name = name
|
||||||
|
|
||||||
def call(self, argument: Evaluable) -> Evaluable:
|
|
||||||
return self
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f'«{self.name.decode()}»'
|
return f'«{self.name.decode()}»'
|
||||||
|
@ -1,14 +1,10 @@
|
|||||||
# Copyright (c) PARRRATE T&V 2021. All rights reserved.
|
# Copyright (c) PARRRATE T&V 2021. All rights reserved.
|
||||||
|
|
||||||
from bu4.evaluation.constructs.evaluable import Evaluable
|
from bu4.evaluation.constructs.evoid import EVoid
|
||||||
from bu4.evaluation.constructs.evalue import EValue
|
|
||||||
|
|
||||||
__all__ = ('ENull',)
|
__all__ = ('ENull',)
|
||||||
|
|
||||||
|
|
||||||
class ENull(EValue):
|
class ENull(EVoid):
|
||||||
def call(self, argument: Evaluable) -> Evaluable:
|
|
||||||
return self
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f'?'
|
return f'?'
|
||||||
|
11
bu4/evaluation/constructs/etraceable.py
Normal file
11
bu4/evaluation/constructs/etraceable.py
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
# Copyright (c) PARRRATE T&V 2021. All rights reserved.
|
||||||
|
|
||||||
|
import abc
|
||||||
|
|
||||||
|
from bu4.evaluation.constructs.evalue import EValue
|
||||||
|
|
||||||
|
__all__ = ('ETraceable',)
|
||||||
|
|
||||||
|
|
||||||
|
class ETraceable(EValue, abc.ABC):
|
||||||
|
pass
|
30
bu4/evaluation/constructs/evoid.py
Normal file
30
bu4/evaluation/constructs/evoid.py
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
# Copyright (c) PARRRATE T&V 2021. All rights reserved.
|
||||||
|
|
||||||
|
import abc
|
||||||
|
|
||||||
|
from bu4.evaluation.constructs.evaluable import Evaluable
|
||||||
|
from bu4.evaluation.constructs.evalue import EValue
|
||||||
|
|
||||||
|
__all__ = ('EVoid', 'ECoVoid',)
|
||||||
|
|
||||||
|
|
||||||
|
class EVoid(EValue, abc.ABC):
|
||||||
|
def call(self, argument: Evaluable) -> Evaluable:
|
||||||
|
if isinstance(argument, ECoVoid):
|
||||||
|
return argument.call(self)
|
||||||
|
else:
|
||||||
|
return self
|
||||||
|
|
||||||
|
|
||||||
|
class ECoVoid(EValue):
|
||||||
|
def void(self) -> EVoid:
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def covoid(self, void: EVoid) -> Evaluable:
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def call(self, argument: Evaluable) -> Evaluable:
|
||||||
|
if isinstance(argument, EVoid):
|
||||||
|
return self.covoid(argument)
|
||||||
|
else:
|
||||||
|
return self.void()
|
32
bu4/evaluation/targets/avconvert.py
Normal file
32
bu4/evaluation/targets/avconvert.py
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
# Copyright (c) PARRRATE T&V 2021. All rights reserved.
|
||||||
|
|
||||||
|
from typing import Type, Generic, TypeVar
|
||||||
|
|
||||||
|
from bu4.evaluation.av.aftervalue import AfterValue
|
||||||
|
from bu4.evaluation.constructs.evaluable import Evaluable
|
||||||
|
from bu4.evaluation.constructs.evalue import EValue
|
||||||
|
from bu4.evaluation.targets.avtarget import AVTarget
|
||||||
|
|
||||||
|
__all__ = ('AVConvert',)
|
||||||
|
|
||||||
|
T = TypeVar('T')
|
||||||
|
|
||||||
|
|
||||||
|
class AVConvert(AVTarget, Generic[T]):
|
||||||
|
def __init__(self, target_type: Type[T]):
|
||||||
|
self.target_type = target_type
|
||||||
|
|
||||||
|
def iterate(self, value: EValue) -> Evaluable:
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def given_typed(self, value: T) -> Evaluable:
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def given(self, value: EValue) -> Evaluable:
|
||||||
|
if isinstance(value, self.target_type):
|
||||||
|
return self.given_typed(value)
|
||||||
|
else:
|
||||||
|
return AfterValue(self.iterate(value), self)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f'<{self.target_type}>'
|
@ -3,14 +3,14 @@
|
|||||||
from bu4.evaluation.constructs.attachable import Attachable
|
from bu4.evaluation.constructs.attachable import Attachable
|
||||||
from bu4.evaluation.constructs.eattachable import EAttachable
|
from bu4.evaluation.constructs.eattachable import EAttachable
|
||||||
from bu4.evaluation.constructs.evaluable import Evaluable
|
from bu4.evaluation.constructs.evaluable import Evaluable
|
||||||
from bu4.evaluation.constructs.evalue import EValue
|
from bu4.evaluation.constructs.etraceable import ETraceable
|
||||||
from bu4.indexing.evaluation.eivtype import eivtype
|
from bu4.indexing.evaluation.eivtype import eivtype
|
||||||
from bu4.indexing.evaluation.lambdaeiv import LambdaEiv
|
from bu4.indexing.evaluation.lambdaeiv import LambdaEiv
|
||||||
|
|
||||||
__all__ = ('EILambda',)
|
__all__ = ('EILambda',)
|
||||||
|
|
||||||
|
|
||||||
class EILambda(EValue):
|
class EILambda(ETraceable):
|
||||||
def __init__(self, ev: eivtype, value: Attachable[eivtype], *, memoize: bool):
|
def __init__(self, ev: eivtype, value: Attachable[eivtype], *, memoize: bool):
|
||||||
self.ev = ev
|
self.ev = ev
|
||||||
self.value = value
|
self.value = value
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
# Copyright (c) PARRRATE T&V 2021. All rights reserved.
|
# Copyright (c) PARRRATE T&V 2021. All rights reserved.
|
||||||
|
|
||||||
|
from pathlib import Path
|
||||||
|
from textwrap import fill
|
||||||
|
from time import time_ns
|
||||||
|
|
||||||
from bu4.combinatory.tocombinatory import to_combinatory
|
from bu4.combinatory.tocombinatory import to_combinatory
|
||||||
from bu4.evaluation.constructs.evalue import EValue
|
from bu4.evaluation.constructs.evalue import EValue
|
||||||
from bu4.evaluation.sync import sync
|
from bu4.evaluation.sync import sync
|
||||||
@ -17,6 +21,11 @@ def isynced(source: str, *, combinatory=False) -> EValue:
|
|||||||
linked = transform(parsed.link(set()))
|
linked = transform(parsed.link(set()))
|
||||||
if combinatory:
|
if combinatory:
|
||||||
linked = transform(to_combinatory(linked))
|
linked = transform(to_combinatory(linked))
|
||||||
|
root = Path('compiled') / f'{round(time_ns())}'
|
||||||
|
root.mkdir(parents=True)
|
||||||
|
(root / 'source.bu4').write_text(source, encoding='utf-8')
|
||||||
indexed = transform(linked.index([]))
|
indexed = transform(linked.index([]))
|
||||||
evaluable = indexed.attach([])
|
evaluable = indexed.attach([])
|
||||||
|
bytesrc = ' '.join(f'{chr(c)} ' if c in range(0x20, 0xff) else f'{c:02x}' for c in bytes(indexed))
|
||||||
|
(root / 'compiled.txt').write_text(fill(bytesrc, width=120), encoding='utf-8')
|
||||||
return sync(evaluable)
|
return sync(evaluable)
|
||||||
|
@ -24,7 +24,7 @@ class PCall(Parsed):
|
|||||||
lambda argument: AfterTransform(
|
lambda argument: AfterTransform(
|
||||||
TransformStart(lambda: self.lambda_.link(promise)),
|
TransformStart(lambda: self.lambda_.link(promise)),
|
||||||
ATLambda(
|
ATLambda(
|
||||||
lambda lambda_: TransformFinished(LCall(argument, lambda_))
|
lambda lambda_: TransformFinished(LCall.new(argument, lambda_))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -6,6 +6,7 @@ from bu4.evaluation.constructs.evaluable import Evaluable
|
|||||||
from bu4.evaluation.targets.avcall import AVCall
|
from bu4.evaluation.targets.avcall import AVCall
|
||||||
from bu4.indexing.constructs.icall import ICall
|
from bu4.indexing.constructs.icall import ICall
|
||||||
from bu4.indexing.constructs.indexed import Indexed
|
from bu4.indexing.constructs.indexed import Indexed
|
||||||
|
from bu4.linking.constructs.ldelayed import LDelayed
|
||||||
from bu4.linking.constructs.linked import Linked
|
from bu4.linking.constructs.linked import Linked
|
||||||
from bu4.linking.evaluation.elvtype import elvtype
|
from bu4.linking.evaluation.elvtype import elvtype
|
||||||
from bu4.transform.states.aftertransform import AfterTransform
|
from bu4.transform.states.aftertransform import AfterTransform
|
||||||
@ -21,6 +22,10 @@ class LCall(Linked):
|
|||||||
argument: Linked
|
argument: Linked
|
||||||
lambda_: Linked
|
lambda_: Linked
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def new(cls, argument: Linked, lambda_: Linked) -> Linked:
|
||||||
|
return lambda_.value if isinstance(lambda_, LDelayed) else LCall(argument, lambda_)
|
||||||
|
|
||||||
def __init__(self, argument: Linked, lambda_: Linked):
|
def __init__(self, argument: Linked, lambda_: Linked):
|
||||||
self.argument = argument
|
self.argument = argument
|
||||||
self.lambda_ = lambda_
|
self.lambda_ = lambda_
|
||||||
|
@ -23,7 +23,7 @@ class LLambda(Linked):
|
|||||||
value: Linked
|
value: Linked
|
||||||
|
|
||||||
def __new__(cls, name: bytes, value: Linked):
|
def __new__(cls, name: bytes, value: Linked):
|
||||||
return Linked.__new__(LLambda) if name in value.future else LDelayed(value)
|
return Linked.__new__(cls) if name in value.future else LDelayed(value)
|
||||||
|
|
||||||
def __init__(self, name: bytes, value: Linked):
|
def __init__(self, name: bytes, value: Linked):
|
||||||
self.name = name
|
self.name = name
|
||||||
@ -31,7 +31,7 @@ class LLambda(Linked):
|
|||||||
self.used = name in value.future
|
self.used = name in value.future
|
||||||
self.memoize = name in value.multifuture
|
self.memoize = name in value.multifuture
|
||||||
self.future = self.value.future - {name}
|
self.future = self.value.future - {name}
|
||||||
self.multifuture = self.future if self.used else self.value.multifuture
|
self.multifuture = self.future if self.used else self.value.future
|
||||||
|
|
||||||
def attach(self, env: elvtype) -> Evaluable:
|
def attach(self, env: elvtype) -> Evaluable:
|
||||||
return (
|
return (
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
from bu4.evaluation.constructs.eattachable import EAttachable
|
from bu4.evaluation.constructs.eattachable import EAttachable
|
||||||
from bu4.evaluation.constructs.evaluable import Evaluable
|
from bu4.evaluation.constructs.evaluable import Evaluable
|
||||||
from bu4.evaluation.constructs.evalue import EValue
|
from bu4.evaluation.constructs.etraceable import ETraceable
|
||||||
from bu4.linking.constructs.linked import Linked
|
from bu4.linking.constructs.linked import Linked
|
||||||
from bu4.linking.evaluation.elvtype import elvtype
|
from bu4.linking.evaluation.elvtype import elvtype
|
||||||
from bu4.linking.evaluation.lambdaelv import LambdaElv
|
from bu4.linking.evaluation.lambdaelv import LambdaElv
|
||||||
@ -10,7 +10,7 @@ from bu4.linking.evaluation.lambdaelv import LambdaElv
|
|||||||
__all__ = ('ELLambda',)
|
__all__ = ('ELLambda',)
|
||||||
|
|
||||||
|
|
||||||
class ELLambda(EValue):
|
class ELLambda(ETraceable):
|
||||||
def __init__(self, env: elvtype, name: bytes, value: Linked):
|
def __init__(self, env: elvtype, name: bytes, value: Linked):
|
||||||
self.env = env
|
self.env = env
|
||||||
self.name = name
|
self.name = name
|
||||||
|
@ -1,13 +1,8 @@
|
|||||||
# Copyright (c) PARRRATE T&V 2021. All rights reserved.
|
# 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.constructs.evalue import EValue
|
||||||
|
from bu4.evaluation.constructs.etraceable import ETraceable
|
||||||
from bu4.evaluation.sync import sync
|
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
|
from bu4.tracing.probe import Probe
|
||||||
|
|
||||||
__all__ = ('trace', 'probe_index_reset',)
|
__all__ = ('trace', 'probe_index_reset',)
|
||||||
@ -19,7 +14,7 @@ def trace(lambda_: EValue):
|
|||||||
global _probe_index
|
global _probe_index
|
||||||
size = 0
|
size = 0
|
||||||
while True:
|
while True:
|
||||||
if not isinstance(lambda_, (ELLambda, EILambda, EIC, EKC, ESC, ESC1, ESC2, EDelayed)):
|
if not isinstance(lambda_, ETraceable):
|
||||||
return size, lambda_
|
return size, lambda_
|
||||||
lambda_ = sync(lambda_.call(Probe(_probe_index)))
|
lambda_ = sync(lambda_.call(Probe(_probe_index)))
|
||||||
_probe_index += 1
|
_probe_index += 1
|
||||||
|
3
main.py
3
main.py
@ -1,6 +1,8 @@
|
|||||||
# Copyright (c) PARRRATE T&V 2021. All rights reserved.
|
# Copyright (c) PARRRATE T&V 2021. All rights reserved.
|
||||||
|
|
||||||
import random
|
import random
|
||||||
|
import shutil
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
from bu4.common_interface import with_common_interface
|
from bu4.common_interface import with_common_interface
|
||||||
from bu4.evaluation.constructs.proxy import antiproxy, eproxy
|
from bu4.evaluation.constructs.proxy import antiproxy, eproxy
|
||||||
@ -10,6 +12,7 @@ from bu4.linkable.toolchain.readfile import readfile
|
|||||||
from bu4.tracing.deep_trace import deep_trace
|
from bu4.tracing.deep_trace import deep_trace
|
||||||
from timesample import TimeSample
|
from timesample import TimeSample
|
||||||
|
|
||||||
|
shutil.rmtree(Path('compiled'), ignore_errors=True)
|
||||||
with TimeSample('all'):
|
with TimeSample('all'):
|
||||||
with TimeSample('sys0'):
|
with TimeSample('sys0'):
|
||||||
with TimeSample('compilation'):
|
with TimeSample('compilation'):
|
||||||
|
Loading…
Reference in New Issue
Block a user