diff --git a/bu4/evaluation/constructs/eexception.py b/bu4/evaluation/constructs/eexception.py new file mode 100644 index 0000000..8096f55 --- /dev/null +++ b/bu4/evaluation/constructs/eexception.py @@ -0,0 +1,17 @@ +# Copyright (c) PARRRATE T&V 2021. All rights reserved. + +from bu4.evaluation.constructs.evaluable import Evaluable +from bu4.evaluation.constructs.evalue import EValue + +__all__ = ('EException',) + + +class EException(EValue): + def __init__(self, name: bytes): + self.name = name + + def call(self, argument: Evaluable) -> Evaluable: + return self + + def __str__(self): + return f'«{self.name.decode()}»' diff --git a/bu4/linking/constructs/lexception.py b/bu4/linking/constructs/lexception.py new file mode 100644 index 0000000..e21f30a --- /dev/null +++ b/bu4/linking/constructs/lexception.py @@ -0,0 +1,20 @@ +# Copyright (c) PARRRATE T&V 2021. All rights reserved. + +from bu4.evaluation.av.envtype import envtype +from bu4.evaluation.constructs.eexception import EException +from bu4.evaluation.constructs.evaluable import Evaluable +from bu4.linking.constructs.linked import Linked + +__all__ = ('LException',) + + +class LException(Linked): + def __init__(self, name: bytes): + self.name = name + self.future = set() + + def evaluable(self, env: envtype) -> Evaluable: + return EException(self.name) + + def __str__(self): + return f'«{self.name.decode()}»' diff --git a/bu4/parsing/codes.py b/bu4/parsing/codes.py index 39b015e..a0f5e94 100644 --- a/bu4/parsing/codes.py +++ b/bu4/parsing/codes.py @@ -8,3 +8,4 @@ CODE_SKIP = 4 CODE_QUOT = 5 CODE_QOPN = 6 CODE_QCLS = 7 +CODE_XCPT = 8 diff --git a/bu4/parsing/constructs/pexception.py b/bu4/parsing/constructs/pexception.py new file mode 100644 index 0000000..80ca923 --- /dev/null +++ b/bu4/parsing/constructs/pexception.py @@ -0,0 +1,16 @@ +# Copyright (c) PARRRATE T&V 2021. All rights reserved. + +__all__ = ('PException',) + +from bu4.linking.constructs.lexception import LException +from bu4.linking.states.linkingfinished import LinkingFinished +from bu4.linking.states.linkingstate import LinkingState +from bu4.parsing.constructs.parsed import Parsed + + +class PException(Parsed): + def __init__(self, name: bytes): + self.name = name + + def link(self, promise: set[bytes]) -> LinkingState: + return LinkingFinished(LException(self.name)) diff --git a/bu4/parsing/extensions/xxcpt.py b/bu4/parsing/extensions/xxcpt.py new file mode 100644 index 0000000..02e6b2c --- /dev/null +++ b/bu4/parsing/extensions/xxcpt.py @@ -0,0 +1,16 @@ +# Copyright (c) PARRRATE T&V 2021. All rights reserved. + +from bu4.parsing.codes import CODE_XCPT +from bu4.parsing.constructs.pexception import PException +from bu4.parsing.extensions.extension import Extension +from bu4.parsing.states.parsestate import ParseState +from bu4.parsing.states.psafter import PSAfter +from bu4.parsing.states.psfinal import PSFinal + +__all__ = ('XXcpt',) + + +class XXcpt(Extension, code=CODE_XCPT): + def apply(self, state: PSAfter) -> ParseState: + state.state = PSFinal(PException(self.parser.parse_name())) + return state diff --git a/bu4/parsing/toolchain/readfile.py b/bu4/parsing/toolchain/readfile.py index a44a794..39e552c 100644 --- a/bu4/parsing/toolchain/readfile.py +++ b/bu4/parsing/toolchain/readfile.py @@ -8,7 +8,7 @@ __all__ = ('readfile',) def readfile(path: str) -> str: srcio = StringIO() - with open(path + '.bu4') as file: + with open(path + '.bu4', encoding='utf-8') as file: for line in file: if line.startswith('@'): srcio.write(readfile(os.path.join(path, os.path.pardir, line.removeprefix('@').strip()))) diff --git a/bu4/parsing/toolchain/stdext.py b/bu4/parsing/toolchain/stdext.py index 6342008..64b3c3f 100644 --- a/bu4/parsing/toolchain/stdext.py +++ b/bu4/parsing/toolchain/stdext.py @@ -7,6 +7,7 @@ from bu4.parsing.extensions.xnull import XNull from bu4.parsing.extensions.xqopn import XQopn from bu4.parsing.extensions.xquot import XQuot from bu4.parsing.extensions.xskip import XSkip +from bu4.parsing.extensions.xxcpt import XXcpt __all__ = ('standard_extension',) @@ -18,4 +19,5 @@ standard_extension = ( XSkip, XQuot, XQopn, + XXcpt, ) diff --git a/bu4/parsing/toolchain/transply.py b/bu4/parsing/toolchain/transply.py index 15ffda5..d746d71 100644 --- a/bu4/parsing/toolchain/transply.py +++ b/bu4/parsing/toolchain/transply.py @@ -26,7 +26,7 @@ def transply(source: str) -> bytes: transplied.write(bytes([CODE_SKIP])) elif c in '?': transplied.write(bytes([CODE_QOPN, CODE_NULL, CODE_QCLS])) - elif c in ']': + elif c in ']»': transplied.write(bytes([CODE_NULL, CODE_QCLS])) elif c in '[': transplied.write(bytes([CODE_QOPN, CODE_NAME])) @@ -36,7 +36,8 @@ def transply(source: str) -> bytes: transplied.write(bytes([CODE_QOPN])) elif c in '>›': transplied.write(bytes([CODE_QCLS])) + elif c in '«': + transplied.write(bytes([CODE_QOPN, CODE_XCPT])) else: - value = c.encode() - transplied.write(value if len(value) == 1 else f'[{value.hex()}]'.encode()) + transplied.write(c.encode()) return transplied.getvalue() diff --git a/src/binary/comparison/eq.bu4 b/src/binary/comparison/eq.bu4 new file mode 100644 index 0000000..ae5a8f0 --- /dev/null +++ b/src/binary/comparison/eq.bu4 @@ -0,0 +1,20 @@ +{ + /(b_eq) + (bA)(bB) + /(zqA)(lbA)(hb!A) + /(zqB)(lbB)(hb!B) + / + / + /[hb!B]/[hb!A][b_eq] + / + /[lbB]/[lbA][xnor] + [and] + / + [zqB] + [zqA] + [bB] + [bA] + [YC] +| + b_eq +} diff --git a/src/collections/deque/empty.bu4 b/src/collections/deque/empty.bu4 index 938f0cb..b08fc36 100644 --- a/src/collections/deque/empty.bu4 +++ b/src/collections/deque/empty.bu4 @@ -1 +1 @@ -{ (g) /? /? /? /? /[1][g] | dequeEmpty } +{ (g) /«deque_empty» /«deque_empty» /«deque_empty» /«deque_empty» /[1][g] | dequeEmpty } diff --git a/src/core/bool/operations.bu4 b/src/core/bool/operations.bu4 index adc9a9b..7469da8 100644 --- a/src/core/bool/operations.bu4 +++ b/src/core/bool/operations.bu4 @@ -3,3 +3,4 @@ { (x)(y) /[0]/[y][x] | and } { (x)(y) /[y]/[1][x] | or } { (x)(y) /[y]/[x] | xor } +{ (x)(y) //[y][x] | xnor } diff --git a/src/io/system/constructs/insimple.bu4 b/src/io/system/constructs/insimple.bu4 index bcb2f7d..ec3bc9a 100644 --- a/src/io/system/constructs/insimple.bu4 +++ b/src/io/system/constructs/insimple.bu4 @@ -4,9 +4,9 @@ / [input] / - ? + «simple_input_has_no_outSys» / - ? + «simple_input_has_no_outBit» / [1] [system]