Hmm.
I think update() should be done better...
This commit is contained in:
+3
-219
@@ -221,8 +221,11 @@ class DefinitionWrapper(object):
|
||||
self.body = text_to_expression(body_text)
|
||||
self._body = tuple(iter_stack(self.body))
|
||||
self.__doc__ = doc or body_text
|
||||
self._compiled = None
|
||||
|
||||
def __call__(self, stack, expression, dictionary):
|
||||
if self._compiled:
|
||||
return self._compiled(stack, expression, dictionary)
|
||||
expression = list_to_stack(self._body, expression)
|
||||
return stack, expression, dictionary
|
||||
|
||||
@@ -278,32 +281,6 @@ def parse(stack):
|
||||
return expression, stack
|
||||
|
||||
|
||||
##@inscribe
|
||||
##@SimpleFunctionWrapper
|
||||
##def first(stack):
|
||||
## '''
|
||||
## ::
|
||||
##
|
||||
## first == uncons pop
|
||||
##
|
||||
## '''
|
||||
## ((head, tail), stack) = stack
|
||||
## return head, stack
|
||||
|
||||
|
||||
##@inscribe
|
||||
##@SimpleFunctionWrapper
|
||||
##def rest(stack):
|
||||
## '''
|
||||
## ::
|
||||
##
|
||||
## rest == uncons popd
|
||||
##
|
||||
## '''
|
||||
## ((head, tail), stack) = stack
|
||||
## return tail, stack
|
||||
|
||||
|
||||
@inscribe
|
||||
@SimpleFunctionWrapper
|
||||
def getitem(stack):
|
||||
@@ -490,30 +467,6 @@ def sort_(S):
|
||||
return list_to_stack(sorted(iter_stack(tos))), stack
|
||||
|
||||
|
||||
##@inscribe
|
||||
##@SimpleFunctionWrapper
|
||||
##def cons(S):
|
||||
## '''
|
||||
## The cons operator expects a list on top of the stack and the potential
|
||||
## member below. The effect is to add the potential member into the
|
||||
## aggregate.
|
||||
## '''
|
||||
## (tos, (second, stack)) = S
|
||||
## return (second, tos), stack
|
||||
|
||||
|
||||
##@inscribe
|
||||
##@SimpleFunctionWrapper
|
||||
##def uncons(S):
|
||||
## '''
|
||||
## Inverse of cons, removes an item from the top of the list on the stack
|
||||
## and places it under the remaining list.
|
||||
## '''
|
||||
## (tos, stack) = S
|
||||
## item, tos = tos
|
||||
## return tos, (item, stack)
|
||||
|
||||
|
||||
@inscribe
|
||||
@SimpleFunctionWrapper
|
||||
def clear(stack):
|
||||
@@ -527,72 +480,6 @@ def clear(stack):
|
||||
return ()
|
||||
|
||||
|
||||
##@inscribe
|
||||
##@SimpleFunctionWrapper
|
||||
##def dup(S):
|
||||
## '''Duplicate the top item on the stack.'''
|
||||
## (tos, stack) = S
|
||||
## return tos, (tos, stack)
|
||||
|
||||
|
||||
##@inscribe
|
||||
##@SimpleFunctionWrapper
|
||||
##def over(S):
|
||||
## '''
|
||||
## Copy the second item down on the stack to the top of the stack.
|
||||
## ::
|
||||
##
|
||||
## a b over
|
||||
## --------------
|
||||
## a b a
|
||||
##
|
||||
## '''
|
||||
## second = S[1][0]
|
||||
## return second, S
|
||||
|
||||
|
||||
##@inscribe
|
||||
##@SimpleFunctionWrapper
|
||||
##def tuck(S):
|
||||
## '''
|
||||
## Copy the item at TOS under the second item of the stack.
|
||||
## ::
|
||||
##
|
||||
## a b tuck
|
||||
## --------------
|
||||
## b a b
|
||||
##
|
||||
## '''
|
||||
## (tos, (second, stack)) = S
|
||||
## return tos, (second, (tos, stack))
|
||||
|
||||
|
||||
##@inscribe
|
||||
##@SimpleFunctionWrapper
|
||||
##def swap(S):
|
||||
## '''Swap the top two items on stack.'''
|
||||
## (tos, (second, stack)) = S
|
||||
## return second, (tos, stack)
|
||||
|
||||
|
||||
##@inscribe
|
||||
##@SimpleFunctionWrapper
|
||||
##def swaack(stack):
|
||||
## '''swap stack'''
|
||||
## old_stack, stack = stack
|
||||
## return stack, old_stack
|
||||
|
||||
|
||||
##@inscribe
|
||||
##@SimpleFunctionWrapper
|
||||
##def stack_(stack):
|
||||
## '''
|
||||
## The stack operator pushes onto the stack a list containing all the
|
||||
## elements of the stack.
|
||||
## '''
|
||||
## return stack, stack
|
||||
|
||||
|
||||
@inscribe
|
||||
@SimpleFunctionWrapper
|
||||
def unstack(stack):
|
||||
@@ -603,44 +490,6 @@ def unstack(stack):
|
||||
return stack[0]
|
||||
|
||||
|
||||
##@inscribe
|
||||
##@SimpleFunctionWrapper
|
||||
##def pop(stack):
|
||||
## '''Pop and discard the top item from the stack.'''
|
||||
## return stack[1]
|
||||
|
||||
|
||||
##@inscribe
|
||||
##@SimpleFunctionWrapper
|
||||
##def popd(stack):
|
||||
## '''Pop and discard the second item from the stack.'''
|
||||
## (tos, (_, stack)) = stack
|
||||
## return tos, stack
|
||||
|
||||
|
||||
##@inscribe
|
||||
##@SimpleFunctionWrapper
|
||||
##def popdd(stack):
|
||||
## '''Pop and discard the third item from the stack.'''
|
||||
## (tos, (second, (_, stack))) = stack
|
||||
## return tos, (second, stack)
|
||||
|
||||
|
||||
##@inscribe
|
||||
##@SimpleFunctionWrapper
|
||||
##def popop(stack):
|
||||
## '''Pop and discard the first and second items from the stack.'''
|
||||
## return stack[1][1]
|
||||
|
||||
|
||||
##@inscribe
|
||||
##@SimpleFunctionWrapper
|
||||
##def dupd(S):
|
||||
## '''Duplicate the second item on the stack.'''
|
||||
## (tos, (second, stack)) = S
|
||||
## return tos, (second, (second, stack))
|
||||
|
||||
|
||||
@inscribe
|
||||
@SimpleFunctionWrapper
|
||||
def reverse(S):
|
||||
@@ -771,36 +620,6 @@ def sqrt(a):
|
||||
return r
|
||||
|
||||
|
||||
##@inscribe
|
||||
##@SimpleFunctionWrapper
|
||||
##def rollup(S):
|
||||
## '''
|
||||
## ::
|
||||
##
|
||||
## a b c
|
||||
## -----------
|
||||
## b c a
|
||||
##
|
||||
## '''
|
||||
## (a, (b, (c, stack))) = S
|
||||
## return b, (c, (a, stack))
|
||||
|
||||
|
||||
##@inscribe
|
||||
##@SimpleFunctionWrapper
|
||||
##def rolldown(S):
|
||||
## '''
|
||||
## ::
|
||||
##
|
||||
## a b c
|
||||
## -----------
|
||||
## c a b
|
||||
##
|
||||
## '''
|
||||
## (a, (b, (c, stack))) = S
|
||||
## return c, (a, (b, stack))
|
||||
|
||||
|
||||
#def execute(S):
|
||||
# (text, stack) = S
|
||||
# if isinstance(text, str):
|
||||
@@ -1448,42 +1267,7 @@ def cmp_(stack, expression, dictionary):
|
||||
return stack, expression, dictionary
|
||||
|
||||
|
||||
#def nullary(S, expression, dictionary):
|
||||
# '''
|
||||
# Run the program on TOS and return its first result without consuming
|
||||
# any of the stack (except the program on TOS.)
|
||||
# '''
|
||||
# (quote, stack) = S
|
||||
# result = joy(stack, quote, dictionary)
|
||||
# return (result[0][0], stack), expression, dictionary
|
||||
#
|
||||
#
|
||||
#def unary(S, expression, dictionary):
|
||||
# (quote, stack) = S
|
||||
# _, return_stack = stack
|
||||
# result = joy(stack, quote, dictionary)[0]
|
||||
# return (result[0], return_stack), expression, dictionary
|
||||
#
|
||||
#
|
||||
#def binary(S, expression, dictionary):
|
||||
# (quote, stack) = S
|
||||
# _, (_, return_stack) = stack
|
||||
# result = joy(stack, quote, dictionary)[0]
|
||||
# return (result[0], return_stack), expression, dictionary
|
||||
#
|
||||
#
|
||||
#def ternary(S, expression, dictionary):
|
||||
# (quote, stack) = S
|
||||
# _, (_, (_, return_stack)) = stack
|
||||
# result = joy(stack, quote, dictionary)[0]
|
||||
# return (result[0], return_stack), expression, dictionary
|
||||
|
||||
|
||||
# FunctionWrapper(binary),
|
||||
# FunctionWrapper(cleave),
|
||||
# FunctionWrapper(nullary),
|
||||
# FunctionWrapper(ternary),
|
||||
# FunctionWrapper(unary),
|
||||
# FunctionWrapper(while_),
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user