combinatory
This commit is contained in:
parent
b45301194c
commit
0a5d2eb0c5
11
bu4/combinatory/lcombinatory.py
Normal file
11
bu4/combinatory/lcombinatory.py
Normal file
@ -0,0 +1,11 @@
|
||||
# Copyright (c) PARRRATE T&V 2021. All rights reserved.
|
||||
|
||||
from abc import ABC
|
||||
|
||||
from bu4.linking.constructs.linked import Linked
|
||||
|
||||
__all__ = ('LCombinatory',)
|
||||
|
||||
|
||||
class LCombinatory(Linked, ABC):
|
||||
pass
|
53
bu4/combinatory/lic.py
Normal file
53
bu4/combinatory/lic.py
Normal file
@ -0,0 +1,53 @@
|
||||
# Copyright (c) PARRRATE T&V 2021. All rights reserved.
|
||||
|
||||
from bu4.combinatory.lcombinatory import LCombinatory
|
||||
from bu4.evaluation.av.envtype import envtype
|
||||
from bu4.evaluation.av.evtype import evtype
|
||||
from bu4.evaluation.constructs.evaluable import Evaluable
|
||||
from bu4.evaluation.constructs.evalue import EValue
|
||||
from bu4.indexing.constructs.indexed import Indexed
|
||||
from bu4.parsing.codes import CODE_CMBI
|
||||
from bu4.parsing.extensions.CodeExtension import CodeExtension
|
||||
from bu4.transform.states.transformfinished import TransformFinished
|
||||
from bu4.transform.states.transformstate import TransformState
|
||||
|
||||
__all__ = ('EIC', 'IIC', 'XII', 'LIC',)
|
||||
|
||||
|
||||
class EIC(EValue):
|
||||
def call(self, argument: Evaluable) -> Evaluable:
|
||||
return argument
|
||||
|
||||
def __str__(self):
|
||||
return f'I'
|
||||
|
||||
|
||||
class IIC(Indexed):
|
||||
def attach(self, ev: evtype) -> Evaluable:
|
||||
return EIC()
|
||||
|
||||
def bytes(self) -> TransformState[bytes]:
|
||||
return TransformFinished(bytes([CODE_CMBI]))
|
||||
|
||||
def __str__(self):
|
||||
return f'I'
|
||||
|
||||
|
||||
class XII(CodeExtension[Indexed], code=CODE_CMBI):
|
||||
def apply(self) -> TransformState[Indexed]:
|
||||
return TransformFinished(IIC())
|
||||
|
||||
|
||||
class LIC(LCombinatory):
|
||||
def __init__(self):
|
||||
self.future = set()
|
||||
self.multifuture = set()
|
||||
|
||||
def attach(self, env: envtype) -> Evaluable:
|
||||
return EIC()
|
||||
|
||||
def index(self, promise: list[bytes]) -> TransformState[Indexed]:
|
||||
return TransformFinished(IIC())
|
||||
|
||||
def __str__(self):
|
||||
return f'I'
|
54
bu4/combinatory/lkc.py
Normal file
54
bu4/combinatory/lkc.py
Normal file
@ -0,0 +1,54 @@
|
||||
# Copyright (c) PARRRATE T&V 2021. All rights reserved.
|
||||
|
||||
from bu4.combinatory.lcombinatory import LCombinatory
|
||||
from bu4.evaluation.av.envtype import envtype
|
||||
from bu4.evaluation.av.evtype import evtype
|
||||
from bu4.evaluation.constructs.edelayed import EDelayed
|
||||
from bu4.evaluation.constructs.evaluable import Evaluable
|
||||
from bu4.evaluation.constructs.evalue import EValue
|
||||
from bu4.indexing.constructs.indexed import Indexed
|
||||
from bu4.parsing.codes import CODE_CMBK
|
||||
from bu4.parsing.extensions.CodeExtension import CodeExtension
|
||||
from bu4.transform.states.transformfinished import TransformFinished
|
||||
from bu4.transform.states.transformstate import TransformState
|
||||
|
||||
__all__ = ('EKC', 'IKC', 'XIK', 'LKC',)
|
||||
|
||||
|
||||
class EKC(EValue):
|
||||
def call(self, argument: Evaluable) -> Evaluable:
|
||||
return EDelayed(argument)
|
||||
|
||||
def __str__(self):
|
||||
return f'K'
|
||||
|
||||
|
||||
class IKC(Indexed):
|
||||
def attach(self, ev: evtype) -> Evaluable:
|
||||
return EKC()
|
||||
|
||||
def bytes(self) -> TransformState[bytes]:
|
||||
return TransformFinished(bytes([CODE_CMBK]))
|
||||
|
||||
def __str__(self):
|
||||
return f'K'
|
||||
|
||||
|
||||
class XIK(CodeExtension[Indexed], code=CODE_CMBK):
|
||||
def apply(self) -> TransformState[Indexed]:
|
||||
return TransformFinished(IKC())
|
||||
|
||||
|
||||
class LKC(LCombinatory):
|
||||
def __init__(self):
|
||||
self.future = set()
|
||||
self.multifuture = set()
|
||||
|
||||
def attach(self, env: envtype) -> Evaluable:
|
||||
return EKC()
|
||||
|
||||
def index(self, promise: list[bytes]) -> TransformState[Indexed]:
|
||||
return TransformFinished(IKC())
|
||||
|
||||
def __str__(self):
|
||||
return f'K'
|
88
bu4/combinatory/lsc.py
Normal file
88
bu4/combinatory/lsc.py
Normal file
@ -0,0 +1,88 @@
|
||||
# Copyright (c) PARRRATE T&V 2021. All rights reserved.
|
||||
|
||||
from bu4.combinatory.lcombinatory import LCombinatory
|
||||
from bu4.evaluation.av.aftervalue import AfterValue
|
||||
from bu4.evaluation.av.envtype import envtype
|
||||
from bu4.evaluation.av.evtype import evtype
|
||||
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.indexing.constructs.indexed import Indexed
|
||||
from bu4.parsing.codes import CODE_CMBS
|
||||
from bu4.parsing.extensions.CodeExtension import CodeExtension
|
||||
from bu4.transform.states.transformfinished import TransformFinished
|
||||
from bu4.transform.states.transformstate import TransformState
|
||||
|
||||
__all__ = ('ESC', 'ESC1', 'ESC2', 'ISC', 'XIS', 'LSC',)
|
||||
|
||||
|
||||
class ESC2(EValue):
|
||||
def __init__(self, argument: Evaluable, lambda_: Evaluable):
|
||||
self.argument = AVAnonymousContainer(argument).after_value
|
||||
self.lambda_ = lambda_
|
||||
|
||||
def call(self, argument: Evaluable) -> Evaluable:
|
||||
argument = AVAnonymousContainer(argument).after_value
|
||||
return AfterValue(
|
||||
AfterValue(
|
||||
self.lambda_,
|
||||
AVCall(argument)
|
||||
),
|
||||
AVCall(
|
||||
AfterValue(
|
||||
self.argument,
|
||||
AVCall(argument)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return f'/{self.argument}/{self.lambda_}S'
|
||||
|
||||
|
||||
class ESC1(EValue):
|
||||
def __init__(self, lambda_: Evaluable):
|
||||
self.lambda_ = AVAnonymousContainer(lambda_).after_value
|
||||
|
||||
def call(self, argument: Evaluable) -> Evaluable:
|
||||
return ESC2(argument, self.lambda_)
|
||||
|
||||
def __str__(self):
|
||||
return f'/{self.lambda_}S'
|
||||
|
||||
|
||||
class ESC(EValue):
|
||||
def call(self, argument: Evaluable) -> Evaluable:
|
||||
return ESC1(argument)
|
||||
|
||||
|
||||
class ISC(Indexed):
|
||||
def attach(self, ev: evtype) -> Evaluable:
|
||||
return ESC()
|
||||
|
||||
def bytes(self) -> TransformState[bytes]:
|
||||
return TransformFinished(bytes([CODE_CMBS]))
|
||||
|
||||
def __str__(self):
|
||||
return f'I'
|
||||
|
||||
|
||||
class XIS(CodeExtension[Indexed], code=CODE_CMBS):
|
||||
def apply(self) -> TransformState[Indexed]:
|
||||
return TransformFinished(ISC())
|
||||
|
||||
|
||||
class LSC(LCombinatory):
|
||||
def __init__(self):
|
||||
self.future = set()
|
||||
self.multifuture = set()
|
||||
|
||||
def attach(self, env: envtype) -> Evaluable:
|
||||
return ESC()
|
||||
|
||||
def index(self, promise: list[bytes]) -> TransformState[Indexed]:
|
||||
return TransformFinished(ISC())
|
||||
|
||||
def __str__(self):
|
||||
return f'S'
|
173
bu4/combinatory/tocombinatory.py
Normal file
173
bu4/combinatory/tocombinatory.py
Normal file
@ -0,0 +1,173 @@
|
||||
# Copyright (c) PARRRATE T&V 2021. All rights reserved.
|
||||
|
||||
from bu4.combinatory.lcombinatory import LCombinatory
|
||||
from bu4.combinatory.lic import LIC
|
||||
from bu4.combinatory.lkc import LKC
|
||||
from bu4.combinatory.lsc import LSC
|
||||
from bu4.linking.constructs.lcall import LCall
|
||||
from bu4.linking.constructs.ldelayed import LDelayed
|
||||
from bu4.linking.constructs.lexception import LException
|
||||
from bu4.linking.constructs.linked import Linked
|
||||
from bu4.linking.constructs.llambda import LLambda
|
||||
from bu4.linking.constructs.lname import LName
|
||||
from bu4.linking.constructs.lnull import LNull
|
||||
from bu4.transform.states.aftertransform import AfterTransform
|
||||
from bu4.transform.states.transformfinished import TransformFinished
|
||||
from bu4.transform.states.transformstart import TransformStart
|
||||
from bu4.transform.states.transformstate import TransformState
|
||||
from bu4.transform.targets.atlambda import ATLambda
|
||||
|
||||
|
||||
class LCCall(LCall, LCombinatory):
|
||||
def __init__(self, argument: LCombinatory, lambda_: LCombinatory):
|
||||
super().__init__(argument, lambda_)
|
||||
|
||||
|
||||
class LCNull(LNull, LCombinatory):
|
||||
pass
|
||||
|
||||
|
||||
class LCException(LException, LCombinatory):
|
||||
pass
|
||||
|
||||
|
||||
def is_kks(linked: Linked) -> bool:
|
||||
if not isinstance(linked, LCall):
|
||||
return False
|
||||
if not isinstance(linked.lambda_, LSC):
|
||||
return False
|
||||
linked = linked.argument
|
||||
if not isinstance(linked, LCall):
|
||||
return False
|
||||
if not isinstance(linked.argument, LKC):
|
||||
return False
|
||||
if not isinstance(linked.lambda_, LKC):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def is_ikks(linked: Linked) -> bool:
|
||||
if not isinstance(linked, LCall):
|
||||
return False
|
||||
if not isinstance(linked.argument, LIC):
|
||||
return False
|
||||
return is_kks(linked.lambda_)
|
||||
|
||||
|
||||
def is_eta(linked: Linked) -> bool:
|
||||
if not isinstance(linked, LCall):
|
||||
return False
|
||||
if not isinstance(linked.argument, LKC):
|
||||
return False
|
||||
linked = linked.lambda_
|
||||
if not isinstance(linked, LCall):
|
||||
return False
|
||||
if not isinstance(linked.lambda_, LSC):
|
||||
return False
|
||||
linked = linked.argument
|
||||
if not isinstance(linked, LCall):
|
||||
return False
|
||||
if not isinstance(linked.lambda_, LKC):
|
||||
return False
|
||||
linked = linked.argument
|
||||
if not isinstance(linked, LCall):
|
||||
return False
|
||||
if not isinstance(linked.argument, LIC):
|
||||
return False
|
||||
if not isinstance(linked.lambda_, LSC):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def lccall(argument: Linked, lambda_: Linked) -> TransformState[Linked]:
|
||||
if isinstance(lambda_, LIC):
|
||||
return TransformFinished(argument)
|
||||
elif isinstance(argument, LKC) and isinstance(lambda_, LSC):
|
||||
return TransformFinished(LCCall(LIC(), LKC()))
|
||||
elif isinstance(lambda_, LCall) and isinstance(lambda_.lambda_, LKC):
|
||||
return TransformFinished(lambda_.argument)
|
||||
elif isinstance(argument, LIC) and is_kks(lambda_):
|
||||
return TransformFinished(LKC())
|
||||
elif isinstance(lambda_, LCall) and is_eta(lambda_.lambda_):
|
||||
lcall = lambda_
|
||||
return TransformStart(lambda: lccall(lcall.argument, argument))
|
||||
elif isinstance(argument, LCombinatory) and isinstance(lambda_, LCombinatory):
|
||||
return TransformFinished(LCCall(argument, lambda_))
|
||||
else:
|
||||
return TransformFinished(LCall(argument, lambda_))
|
||||
|
||||
|
||||
def to_combinatory(linked: Linked) -> TransformState[Linked]:
|
||||
if isinstance(linked, LCombinatory):
|
||||
return TransformFinished(linked)
|
||||
elif is_ikks(linked):
|
||||
return TransformFinished(LKC())
|
||||
elif isinstance(linked, LCall):
|
||||
lcall = linked
|
||||
return AfterTransform(
|
||||
TransformStart(lambda: to_combinatory(lcall.argument)),
|
||||
ATLambda(
|
||||
lambda argument: AfterTransform(
|
||||
TransformStart(lambda: to_combinatory(lcall.lambda_)),
|
||||
ATLambda(
|
||||
lambda lambda_: lccall(argument, lambda_)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
elif isinstance(linked, LDelayed):
|
||||
ldelayed = linked
|
||||
return AfterTransform(
|
||||
TransformStart(lambda: to_combinatory(ldelayed.value)),
|
||||
ATLambda(
|
||||
lambda value: lccall(value, LKC())
|
||||
)
|
||||
)
|
||||
elif isinstance(linked, LLambda):
|
||||
llambda = linked
|
||||
if not llambda.used:
|
||||
return AfterTransform(
|
||||
TransformStart(lambda: to_combinatory(llambda.value)),
|
||||
ATLambda(
|
||||
lambda value: lccall(value, LKC())
|
||||
)
|
||||
)
|
||||
elif isinstance(llambda.value, LName) and llambda.value.name == llambda.name:
|
||||
return TransformFinished(LIC())
|
||||
elif isinstance(llambda.value, LCall):
|
||||
lcall = llambda.value
|
||||
return AfterTransform(
|
||||
TransformStart(lambda: to_combinatory(LLambda(llambda.name, lcall.argument))),
|
||||
ATLambda(
|
||||
lambda argument: AfterTransform(
|
||||
TransformStart(lambda: to_combinatory(LLambda(llambda.name, lcall.lambda_))),
|
||||
ATLambda(
|
||||
lambda lambda_: AfterTransform(
|
||||
lccall(
|
||||
lambda_,
|
||||
LSC()
|
||||
),
|
||||
ATLambda(
|
||||
lambda combined: lccall(
|
||||
argument,
|
||||
combined
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
else:
|
||||
return AfterTransform(
|
||||
TransformStart(lambda: to_combinatory(llambda.value)),
|
||||
ATLambda(
|
||||
lambda value: to_combinatory(LLambda(llambda.name, value))
|
||||
)
|
||||
)
|
||||
elif isinstance(linked, LNull):
|
||||
return TransformFinished(LCNull())
|
||||
elif isinstance(linked, LException):
|
||||
return TransformFinished(LCException(linked.name))
|
||||
else:
|
||||
return TransformFinished(linked)
|
@ -1,9 +1,7 @@
|
||||
# Copyright (c) PARRRATE T&V 2021. All rights reserved.
|
||||
|
||||
from typing import TypeVar, Generic
|
||||
from typing import TypeVar
|
||||
|
||||
from bu4.evaluation.constructs.attachable import Attachable
|
||||
from bu4.evaluation.constructs.eattachable import EAttachable
|
||||
from bu4.evaluation.constructs.evaluable import Evaluable
|
||||
from bu4.evaluation.constructs.evalue import EValue
|
||||
from bu4.evaluation.targets.avanonymouscontainer import AVAnonymousContainer
|
||||
@ -13,17 +11,12 @@ __all__ = ('EDelayed',)
|
||||
T = TypeVar('T')
|
||||
|
||||
|
||||
class EDelayed(EValue, Generic[T]):
|
||||
def __init__(self, env: T, value: Attachable[T]):
|
||||
self.env = env
|
||||
self.value = value
|
||||
self.evaluable = AVAnonymousContainer(EAttachable(
|
||||
self.env,
|
||||
self.value
|
||||
)).after_value
|
||||
class EDelayed(EValue):
|
||||
def __init__(self, evaluable: Evaluable):
|
||||
self.evaluable = AVAnonymousContainer(evaluable).after_value
|
||||
|
||||
def call(self, argument: Evaluable) -> Evaluable:
|
||||
return self.evaluable
|
||||
|
||||
def __str__(self):
|
||||
return f'&{self.value}'
|
||||
return f'&{self.evaluable}'
|
||||
|
@ -21,6 +21,9 @@ class AVProxyCall(AVTarget):
|
||||
else:
|
||||
return eproxy(self.value(antiproxy(value)))
|
||||
|
||||
def __str__(self):
|
||||
return f'<{self.value}>'
|
||||
|
||||
|
||||
class EProxy(EValue):
|
||||
def __init__(self, value: Any):
|
||||
|
@ -14,6 +14,7 @@ class AVAnonymousContainer(AVTarget):
|
||||
|
||||
def given(self, value: EValue) -> Evaluable:
|
||||
self.after_value.evaluable = value
|
||||
self.after_value.target = self
|
||||
return value
|
||||
|
||||
def __str__(self):
|
||||
|
@ -1,25 +1,18 @@
|
||||
# Copyright (c) PARRRATE T&V 2021. All rights reserved.
|
||||
|
||||
from typing import TypeVar, Generic
|
||||
|
||||
from bu4.evaluation.constructs.attachable import Attachable
|
||||
from bu4.evaluation.constructs.eattachable import EAttachable
|
||||
from bu4.evaluation.constructs.evaluable import Evaluable
|
||||
from bu4.evaluation.constructs.evalue import EValue
|
||||
from bu4.evaluation.targets.avtarget import AVTarget
|
||||
|
||||
__all__ = ('AVCall',)
|
||||
|
||||
T = TypeVar('T')
|
||||
|
||||
|
||||
class AVCall(AVTarget, Generic[T]):
|
||||
def __init__(self, t: T, argument: Attachable[T]):
|
||||
self.t = t
|
||||
class AVCall(AVTarget):
|
||||
def __init__(self, argument: Evaluable):
|
||||
self.argument = argument
|
||||
|
||||
def given(self, value: EValue) -> Evaluable:
|
||||
return value.call(EAttachable(self.t, self.argument))
|
||||
return value.call(self.argument)
|
||||
|
||||
def __str__(self):
|
||||
return f'({self.argument})'
|
||||
|
@ -15,6 +15,7 @@ class AVNamedContainer(AVTarget):
|
||||
|
||||
def given(self, value: EValue) -> Evaluable:
|
||||
self.after_value.evaluable = value
|
||||
self.after_value.target = self
|
||||
return value
|
||||
|
||||
def __str__(self):
|
||||
|
@ -7,6 +7,11 @@ from bu4.evaluation.constructs.evaluable import Evaluable
|
||||
from bu4.evaluation.targets.avcall import AVCall
|
||||
from bu4.indexing.constructs.indexed import Indexed
|
||||
from bu4.parsing.codes import CODE_CALL
|
||||
from bu4.transform.states.aftertransform import AfterTransform
|
||||
from bu4.transform.states.transformfinished import TransformFinished
|
||||
from bu4.transform.states.transformstart import TransformStart
|
||||
from bu4.transform.states.transformstate import TransformState
|
||||
from bu4.transform.targets.atlambda import ATLambda
|
||||
|
||||
__all__ = ('ICall',)
|
||||
|
||||
@ -17,10 +22,22 @@ class ICall(Indexed):
|
||||
self.lambda_ = lambda_
|
||||
|
||||
def attach(self, ev: evtype) -> Evaluable:
|
||||
return AfterValue(EAttachable(ev, self.lambda_), AVCall(ev, self.argument))
|
||||
return AfterValue(EAttachable(ev, self.lambda_), AVCall(EAttachable(ev, self.argument)))
|
||||
|
||||
def __str__(self):
|
||||
return f'/{self.argument}{self.lambda_}'
|
||||
|
||||
def __bytes__(self):
|
||||
return bytes([CODE_CALL, *bytes(self.argument), *bytes(self.lambda_)])
|
||||
def bytes(self) -> TransformState[bytes]:
|
||||
return AfterTransform(
|
||||
TransformStart(lambda: self.argument.bytes()),
|
||||
ATLambda(
|
||||
lambda argument: AfterTransform(
|
||||
TransformStart(lambda: self.lambda_.bytes()),
|
||||
ATLambda(
|
||||
lambda lambda_: TransformFinished(
|
||||
bytes([CODE_CALL, *argument, *lambda_])
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
@ -1,10 +1,16 @@
|
||||
# Copyright (c) PARRRATE T&V 2021. All rights reserved.
|
||||
|
||||
from bu4.evaluation.av.evtype import evtype
|
||||
from bu4.evaluation.constructs.eattachable import EAttachable
|
||||
from bu4.evaluation.constructs.edelayed import EDelayed
|
||||
from bu4.evaluation.constructs.evaluable import Evaluable
|
||||
from bu4.indexing.constructs.indexed import Indexed
|
||||
from bu4.parsing.codes import CODE_DLYD
|
||||
from bu4.transform.states.aftertransform import AfterTransform
|
||||
from bu4.transform.states.transformfinished import TransformFinished
|
||||
from bu4.transform.states.transformstart import TransformStart
|
||||
from bu4.transform.states.transformstate import TransformState
|
||||
from bu4.transform.targets.atlambda import ATLambda
|
||||
|
||||
__all__ = ('IDelayed',)
|
||||
|
||||
@ -14,13 +20,18 @@ class IDelayed(Indexed):
|
||||
self.value = value
|
||||
|
||||
def attach(self, ev: evtype) -> Evaluable:
|
||||
return EDelayed(
|
||||
return EDelayed(EAttachable(
|
||||
ev,
|
||||
self.value
|
||||
)
|
||||
))
|
||||
|
||||
def __str__(self):
|
||||
return f'&{self.value}'
|
||||
|
||||
def __bytes__(self):
|
||||
return bytes([CODE_DLYD, *bytes(self.value)])
|
||||
def bytes(self) -> TransformState[bytes]:
|
||||
return AfterTransform(
|
||||
TransformStart(lambda: self.value.bytes()),
|
||||
ATLambda(
|
||||
lambda value: TransformFinished(bytes([CODE_DLYD, *value]))
|
||||
)
|
||||
)
|
||||
|
@ -5,6 +5,8 @@ from bu4.evaluation.constructs.eexception import EException
|
||||
from bu4.evaluation.constructs.evaluable import Evaluable
|
||||
from bu4.indexing.constructs.indexed import Indexed
|
||||
from bu4.parsing.codes import CODE_XCPT
|
||||
from bu4.transform.states.transformfinished import TransformFinished
|
||||
from bu4.transform.states.transformstate import TransformState
|
||||
|
||||
__all__ = ('IException',)
|
||||
|
||||
@ -19,5 +21,5 @@ class IException(Indexed):
|
||||
def __str__(self):
|
||||
return f'«{self.name.decode()}»'
|
||||
|
||||
def __bytes__(self):
|
||||
return bytes([CODE_XCPT, *self.name, 0])
|
||||
def bytes(self) -> TransformState[bytes]:
|
||||
return TransformFinished(bytes([CODE_XCPT, *self.name, 0]))
|
||||
|
@ -5,6 +5,11 @@ from bu4.evaluation.constructs.eilambda import EILambda
|
||||
from bu4.evaluation.constructs.evaluable import Evaluable
|
||||
from bu4.indexing.constructs.indexed import Indexed
|
||||
from bu4.parsing.codes import CODE_MAKE
|
||||
from bu4.transform.states.aftertransform import AfterTransform
|
||||
from bu4.transform.states.transformfinished import TransformFinished
|
||||
from bu4.transform.states.transformstart import TransformStart
|
||||
from bu4.transform.states.transformstate import TransformState
|
||||
from bu4.transform.targets.atlambda import ATLambda
|
||||
|
||||
__all__ = ('ILambda',)
|
||||
|
||||
@ -25,5 +30,12 @@ class ILambda(Indexed):
|
||||
def __str__(self):
|
||||
return f'(0){self.value}'
|
||||
|
||||
def __bytes__(self):
|
||||
return bytes([CODE_MAKE, self.memoize, len(self.table), *self.table, *bytes(self.value)])
|
||||
def bytes(self) -> TransformState[bytes]:
|
||||
return AfterTransform(
|
||||
TransformStart(lambda: self.value.bytes()),
|
||||
ATLambda(
|
||||
lambda value: TransformFinished(
|
||||
bytes([CODE_MAKE, self.memoize, len(self.table), *self.table, *value])
|
||||
)
|
||||
)
|
||||
)
|
||||
|
@ -4,6 +4,8 @@ from bu4.evaluation.av.evtype import evtype
|
||||
from bu4.evaluation.constructs.evaluable import Evaluable
|
||||
from bu4.indexing.constructs.indexed import Indexed
|
||||
from bu4.parsing.codes import CODE_NAME
|
||||
from bu4.transform.states.transformfinished import TransformFinished
|
||||
from bu4.transform.states.transformstate import TransformState
|
||||
|
||||
__all__ = ('IName',)
|
||||
|
||||
@ -18,5 +20,5 @@ class IName(Indexed):
|
||||
def __str__(self):
|
||||
return f'[[{self.index}]]'
|
||||
|
||||
def __bytes__(self):
|
||||
return bytes([CODE_NAME, self.index])
|
||||
def bytes(self) -> TransformState[bytes]:
|
||||
return TransformFinished(bytes([CODE_NAME, self.index]))
|
||||
|
@ -3,6 +3,8 @@
|
||||
from bu4.evaluation.av.evtype import evtype
|
||||
from bu4.evaluation.constructs.attachable import Attachable
|
||||
from bu4.evaluation.constructs.evaluable import Evaluable
|
||||
from bu4.transform.states.transformstate import TransformState
|
||||
from bu4.transform.transform import transform
|
||||
|
||||
__all__ = ('Indexed',)
|
||||
|
||||
@ -11,5 +13,8 @@ class Indexed(Attachable[evtype]):
|
||||
def attach(self, ev: evtype) -> Evaluable:
|
||||
raise NotImplementedError
|
||||
|
||||
def __bytes__(self):
|
||||
def bytes(self) -> TransformState[bytes]:
|
||||
raise NotImplementedError
|
||||
|
||||
def __bytes__(self):
|
||||
return transform(self.bytes())
|
||||
|
@ -5,6 +5,8 @@ from bu4.evaluation.constructs.enull import ENull
|
||||
from bu4.evaluation.constructs.evaluable import Evaluable
|
||||
from bu4.indexing.constructs.indexed import Indexed
|
||||
from bu4.parsing.codes import CODE_NULL
|
||||
from bu4.transform.states.transformfinished import TransformFinished
|
||||
from bu4.transform.states.transformstate import TransformState
|
||||
|
||||
__all__ = ('INull',)
|
||||
|
||||
@ -16,5 +18,5 @@ class INull(Indexed):
|
||||
def __str__(self):
|
||||
return '?'
|
||||
|
||||
def __bytes__(self):
|
||||
return bytes([CODE_NULL])
|
||||
def bytes(self) -> TransformState[bytes]:
|
||||
return TransformFinished(bytes([CODE_NULL]))
|
||||
|
@ -32,7 +32,7 @@ class LCall(Linked):
|
||||
)
|
||||
|
||||
def attach(self, env: envtype) -> Evaluable:
|
||||
return AfterValue(EAttachable(env, self.lambda_), AVCall(env, self.argument))
|
||||
return AfterValue(EAttachable(env, self.lambda_), AVCall(EAttachable(env, self.argument)))
|
||||
|
||||
def index(self, promise: list[bytes]) -> TransformState[Indexed]:
|
||||
return AfterTransform(
|
||||
|
@ -1,6 +1,7 @@
|
||||
# Copyright (c) PARRRATE T&V 2021. All rights reserved.
|
||||
|
||||
from bu4.evaluation.av.envtype import envtype
|
||||
from bu4.evaluation.constructs.eattachable import EAttachable
|
||||
from bu4.evaluation.constructs.edelayed import EDelayed
|
||||
from bu4.evaluation.constructs.evaluable import Evaluable
|
||||
from bu4.indexing.constructs.idelayed import IDelayed
|
||||
@ -24,7 +25,10 @@ class LDelayed(Linked):
|
||||
self.multifuture = self.future
|
||||
|
||||
def attach(self, env: envtype) -> Evaluable:
|
||||
return EDelayed(env, self.value)
|
||||
return EDelayed(EAttachable(
|
||||
env,
|
||||
self.value
|
||||
))
|
||||
|
||||
def index(self, promise: list[bytes]) -> TransformState[Indexed]:
|
||||
return AfterTransform(
|
||||
|
@ -1,6 +1,7 @@
|
||||
# Copyright (c) PARRRATE T&V 2021. All rights reserved.
|
||||
|
||||
from bu4.evaluation.av.envtype import envtype
|
||||
from bu4.evaluation.constructs.eattachable import EAttachable
|
||||
from bu4.evaluation.constructs.edelayed import EDelayed
|
||||
from bu4.evaluation.constructs.elambda import ELambda
|
||||
from bu4.evaluation.constructs.evaluable import Evaluable
|
||||
@ -38,7 +39,10 @@ class LLambda(Linked):
|
||||
if
|
||||
self.used
|
||||
else
|
||||
EDelayed(env, self.value)
|
||||
EDelayed(EAttachable(
|
||||
env,
|
||||
self.value
|
||||
))
|
||||
)
|
||||
|
||||
def index(self, promise: list[bytes]) -> TransformState[Indexed]:
|
||||
|
@ -10,3 +10,6 @@ CODE_QOPN = 6
|
||||
CODE_QCLS = 7
|
||||
CODE_XCPT = 8
|
||||
CODE_DLYD = 9
|
||||
CODE_CMBI = 10
|
||||
CODE_CMBK = 11
|
||||
CODE_CMBS = 12
|
||||
|
@ -17,7 +17,7 @@ class Probe(EValue):
|
||||
list_.append(probe.argument)
|
||||
probe = probe.prev
|
||||
assert isinstance(probe, ProbeA)
|
||||
return probe.start, reversed(list_)
|
||||
return probe.start, list(reversed(list_))
|
||||
|
||||
def __str__(self):
|
||||
start, list_ = self.start_and_list()
|
||||
|
@ -1,10 +1,16 @@
|
||||
# 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.eilambda import EILambda
|
||||
from bu4.evaluation.constructs.elambda import ELambda
|
||||
from bu4.evaluation.constructs.evalue import EValue
|
||||
from bu4.evaluation.sync import sync
|
||||
from bu4.tracing.probe import ProbeA
|
||||
|
||||
__all__ = ('trace',)
|
||||
__all__ = ('trace', 'probe_index_reset',)
|
||||
|
||||
_probe_index = 0
|
||||
|
||||
@ -13,8 +19,13 @@ def trace(lambda_: EValue):
|
||||
global _probe_index
|
||||
size = 0
|
||||
while True:
|
||||
if not isinstance(lambda_, ELambda):
|
||||
if not isinstance(lambda_, (ELambda, EILambda, EIC, EKC, ESC, ESC1, ESC2, EDelayed)):
|
||||
return size, lambda_
|
||||
lambda_ = sync(lambda_.call(ProbeA(_probe_index)))
|
||||
_probe_index += 1
|
||||
size += 1
|
||||
|
||||
|
||||
def probe_index_reset():
|
||||
global _probe_index
|
||||
_probe_index = 0
|
||||
|
69
main.py
69
main.py
@ -7,11 +7,50 @@ from bu4.common_interface import with_common_interface
|
||||
from bu4.evaluation.constructs.proxy import antiproxy, eproxy
|
||||
from bu4.evaluation.sync import sync
|
||||
from bu4.isynced import isynced as synced
|
||||
from bu4.linkable.toolchain.parse import parse
|
||||
from bu4.linkable.toolchain.readfile import readfile
|
||||
from bu4.linkable.toolchain.stdext import standard_extensions
|
||||
from bu4.linkable.toolchain.transply import transply
|
||||
from bu4.combinatory.tocombinatory import to_combinatory
|
||||
from bu4.tracing.probe import Probe
|
||||
from bu4.tracing.trace import trace
|
||||
from bu4.transform.transform import transform
|
||||
from timesample import TimeSample
|
||||
|
||||
|
||||
def deep_trace(sysx):
|
||||
hist = []
|
||||
queue = deque([(0, 0, sysx)])
|
||||
for trace_index in range(1, 1000 + 1):
|
||||
hist.append(trace_index)
|
||||
if not queue:
|
||||
break
|
||||
tab, parent, evaluable = queue.popleft()
|
||||
hist.append(parent)
|
||||
for _ in range(10000):
|
||||
evaluable = evaluable.next()
|
||||
_probe_index, probe = trace(evaluable)
|
||||
hist.append(_probe_index)
|
||||
# prefix = ('.', ' ' * tab, parent, trace_index)
|
||||
if isinstance(probe, Probe):
|
||||
start, list_ = probe.start_and_list()
|
||||
hist.append(start)
|
||||
for i in range(len(list_)):
|
||||
for _ in range(10000):
|
||||
list_[i] = list_[i].next()
|
||||
# TimeSample.print(*prefix, _probe_index, 'probe', start, f'[ {" ; ".join(map(str, list_))} ]')
|
||||
queue.extend((tab + 1, trace_index, deeper_evaluable) for deeper_evaluable in list_)
|
||||
else:
|
||||
hist.append(None)
|
||||
# TimeSample.print(*prefix, '...')
|
||||
return hist
|
||||
|
||||
|
||||
print(transform(to_combinatory(transform(parse(transply(
|
||||
'/[b]/[a](x)(y)/[x][y]'
|
||||
), standard_extensions).link({b'a', b'b'})))))
|
||||
|
||||
|
||||
with TimeSample('all'):
|
||||
with TimeSample('sys0'):
|
||||
with TimeSample('compilation'):
|
||||
@ -69,25 +108,13 @@ with TimeSample('all'):
|
||||
TimeSample.print(with_common_interface(synced(readfile('src/sys4'))))
|
||||
with TimeSample('sys5'):
|
||||
sys5 = synced(readfile('src/sys5'))
|
||||
queue = deque([(0, 0, sys5)])
|
||||
for trace_index in range(1, 100 + 1):
|
||||
if not queue:
|
||||
break
|
||||
tab, parent, evaluable = queue.popleft()
|
||||
for _ in range(10000):
|
||||
evaluable = evaluable.next()
|
||||
_probe_index, probe = trace(evaluable)
|
||||
prefix = ('.', ' ' * tab, parent, trace_index)
|
||||
if isinstance(probe, Probe):
|
||||
start, list_ = probe.start_and_list()
|
||||
TimeSample.print(*prefix, _probe_index, probe)
|
||||
queue.extend((tab + 1, trace_index, deeper_evaluable) for deeper_evaluable in list_)
|
||||
else:
|
||||
TimeSample.print(*prefix, '...')
|
||||
print(deep_trace(sys5))
|
||||
with TimeSample('sys6'):
|
||||
sys6 = synced(readfile('src/sys6')).call(synced('?'))
|
||||
for _ in range(100):
|
||||
sys6 = sys6.next()
|
||||
print(sys6)
|
||||
for _ in range(10000000):
|
||||
sys6 = sys6.next()
|
||||
with TimeSample('compilation'):
|
||||
sys6 = synced(readfile('src/sys6')).call(synced('?'))
|
||||
with TimeSample('runtime'):
|
||||
for _ in range(100):
|
||||
sys6 = sys6.next()
|
||||
# print(sys6)
|
||||
for _ in range(10000000):
|
||||
sys6 = sys6.next()
|
||||
|
@ -1,2 +1,2 @@
|
||||
{ (x) /[x][x] | SC }
|
||||
{ (g) /<(x)//[x][SC][g]>[SC] | YC }
|
||||
{ (x) /[x][x] | RC }
|
||||
{ (g) /<(x)//[x][RC][g]>[RC] | YC }
|
||||
|
@ -14,5 +14,5 @@
|
||||
[YC]
|
||||
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
(_)
|
||||
/ < (x) /[x][SC] > [SC]
|
||||
/ < (x) /[x][RC] > [RC]
|
||||
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
|
Loading…
Reference in New Issue
Block a user