Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pair apply dump #175

Merged
merged 1 commit into from
Aug 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,14 @@ Apply the next two commands to `a` and push both results in a list.

***

# `Ç` (Pair apply and dump)

Tokens: `pair_apply_dump`

Apply the next two commands to `a` and push both results separately.

***

# `Ð` (Triplicate)

Tokens: `triplicate`
Expand Down Expand Up @@ -1403,14 +1411,6 @@ Push `\n` to the stack.

***

# `Ç` (Pipe character)

Tokens: `pipe`

Push `|` to the stack.

***

# `¬` (Non-vectorised logical NOT)

Tokens: `non_vectorised_not`,`non_vectorised_logical_not`
Expand Down
Binary file modified src/thunno2/__pycache__/commands.cpython-39.pyc
Binary file not shown.
Binary file modified src/thunno2/__pycache__/helpers.cpython-39.pyc
Binary file not shown.
Binary file modified src/thunno2/__pycache__/interpreter.cpython-39.pyc
Binary file not shown.
Binary file modified src/thunno2/__pycache__/lexer.cpython-39.pyc
Binary file not shown.
Binary file modified src/thunno2/__pycache__/tests.cpython-39.pyc
Binary file not shown.
Binary file modified src/thunno2/__pycache__/version.cpython-39.pyc
Binary file not shown.
1 change: 0 additions & 1 deletion src/thunno2/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -1226,7 +1226,6 @@ def __call__(self, pop=True):
("num_to_alphabet", "alphabet_to_num"),
),
"¶": Overload(0, {Any: (lambda: "\n")}, 0, ("newline",)),
"Ç": Overload(0, {Any: (lambda: "|")}, 0, ("pipe",)),
"¬": Overload(
1, {Any: logical_not}, 0, ("non_vectorised_not", "non_vectorised_logical_not")
),
Expand Down
16 changes: 16 additions & 0 deletions src/thunno2/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,22 @@ def run(code, *, context=None, iteration_index=None):
r.append(k[-1])
ctx.stack = Stack(copy.deepcopy(old_stack))
ctx.stack.push(r)
elif desc == "pair apply dump":
a = next(ctx.stack.rmv(1))
ctx.stack.push(a)
old_stack = Stack(copy.deepcopy(list(ctx.stack).copy()))
r = []
f1, f2 = info
k = f1()
if k:
r.append(k[-1])
ctx.stack = Stack(copy.deepcopy(old_stack))
k = f2()
if k:
r.append(k[-1])
ctx.stack = Stack(copy.deepcopy(old_stack))
for a in r:
ctx.stack.push(a)
elif desc == "recursive environment":
a = next(ctx.stack.rmv(1))
if isinstance(a, list):
Expand Down
20 changes: 20 additions & 0 deletions src/thunno2/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,26 @@ def tokenise(code, expected_end=""):
except:
func2, cmd2 = Void, ""
ret.append((char + cmd1 + cmd2, "pair apply", (func1, func2)))
elif char == "Ç":
try:
index += 1
cmd1 = code[index]
if cmd1 in DIGRAPHS:
index += 1
cmd1 += code[index]
func1 = get_a_function(cmd1)
except:
func1, cmd1 = Void, ""
try:
index += 1
cmd2 = code[index]
if cmd2 in DIGRAPHS:
index += 1
cmd2 += code[index]
func2 = get_a_function(cmd2)
except:
func2, cmd2 = Void, ""
ret.append((char + cmd1 + cmd2, "pair apply dump", (func1, func2)))
elif char in expected_end:
return index, ret
elif char == ":":
Expand Down
4 changes: 0 additions & 4 deletions src/thunno2/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2187,10 +2187,6 @@ def assert_eq(a, *b):

assert_eq(call("¶"), "\n")

# Ç

assert_eq(call("Ç"), "|")

# ¬

assert_eq(call("¬", 123), 0)
Expand Down
1 change: 1 addition & 0 deletions src/thunno2/tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def test():
":": ("else_statement", "else"),
";": ("close_statement",),
"ç": ("pair_apply",),
"Ç": ("pair_apply_dump",),
"n": ("context_variable",),
"ṅ": ("iteration_index",),
"x": ("get_x",),
Expand Down
Loading