import operator, math
from .parser import text_to_expression, Symbol
-from .utils.stack import list_to_stack, iter_stack, pick, pushback
+from .utils.stack import list_to_stack, iter_stack, pick, concat
from .utils.brutal_hackery import rename_code_object
@inscribe
@SimpleFunctionWrapper
-def concat(S):
+def concat_(S):
'''Concatinate the two lists on the top of the stack.
::
'''
(tos, (second, stack)) = S
- for term in reversed(list(iter_stack(second))):
- tos = term, tos
- return tos, stack
+ return concat(second, tos), stack
@inscribe
'''
quote, stack = stack
- return stack, pushback(quote, expression), dictionary
+ return stack, concat(quote, expression), dictionary
@inscribe
'''
quote, _ = stack
- return stack, pushback(quote, expression), dictionary
+ return stack, concat(quote, expression), dictionary
@inscribe
'''
q, (p, (stack)) = stack
- return stack, pushback(p, pushback(q, expression)), dictionary
+ return stack, concat(p, concat(q, expression)), dictionary
@inscribe
'''
F, stack = stack
a = stack[0]
- return stack, pushback(F, (a, expression)), dictionary
+ return stack, concat(F, (a, expression)), dictionary
@inscribe
'''
(quote, (aggregate, stack)) = stack
- return aggregate, pushback(quote, (stack, (S_swaack, expression))), dictionary
+ return aggregate, concat(quote, (stack, (S_swaack, expression))), dictionary
@inscribe
(rec2, (rec1, stack)) = stack
(then, (if_, _)) = stack
F = (if_, (then, (rec1, (rec2, (S_genrec, ())))))
- else_ = pushback(rec1, (F, rec2))
+ else_ = concat(rec1, (F, rec2))
return (else_, stack), (S_ifte, expression), dictionary
'''
(then, (else_, (flag, stack))) = stack
- return stack, pushback(then if flag else else_, expression), dictionary
+ return stack, concat(then if flag else else_, expression), dictionary
@inscribe
'''
(quote, (x, stack)) = stack
expression = (x, expression)
- return stack, pushback(quote, expression), dictionary
+ return stack, concat(quote, expression), dictionary
@inscribe
'''
(quote, (x, (y, stack))) = S
expression = (y, (x, expression))
- return stack, pushback(quote, expression), dictionary
+ return stack, concat(quote, expression), dictionary
@inscribe
'''
(quote, (x, (y, (z, stack)))) = S
expression = (z, (y, (x, expression)))
- return stack, pushback(quote, expression), dictionary
+ return stack, concat(quote, expression), dictionary
@inscribe
n -= 1
if n:
expression = n, (quote, (S_times, expression))
- expression = pushback(quote, expression)
+ expression = concat(quote, expression)
return stack, expression, dictionary
'''
quote, (flag, stack) = stack
if flag:
- expression = pushback(quote, (quote, (S_loop, expression)))
+ expression = concat(quote, (quote, (S_loop, expression)))
return stack, expression, dictionary
L
'''
L, (E, (G, (b, (a, stack)))) = stack
- expression = pushback(G if a > b else L if a < b else E, expression)
+ expression = concat(G if a > b else L if a < b else E, expression)
return stack, expression, dictionary