Switch back to spaces for indentation.

For better or worse, Python 3 won.  No need to be shitty about it, eh?
This commit is contained in:
Simon Forman 2021-04-09 16:16:34 -07:00
parent 6fc77a9a4a
commit 65b2b4a7e3
6 changed files with 1088 additions and 1074 deletions

View File

@ -27,6 +27,7 @@ from builtins import input
from traceback import print_exc
from .parser import text_to_expression, ParseError, Symbol
from .utils.stack import stack_to_string
from .library import NotAnIntError, StackUnderflowError
class UnknownSymbolError(KeyError): pass
@ -131,6 +132,10 @@ def interp(stack=(), dictionary=None):
stack, _, dictionary = run(text, stack, dictionary)
except UnknownSymbolError as sym:
print('Unknown:', sym)
except StackUnderflowError:
print('Not enough values on stack.')
except NotAnIntError:
print('Not an integer.')
except:
print_exc()
print(stack_to_string(stack))

View File

@ -189,6 +189,10 @@ while == swap [nullary] cons dup dipd concat loop
)
class NotAnIntError(Exception): pass
class StackUnderflowError(Exception): pass
def FunctionWrapper(f):
'''Set name attribute.'''
if not f.__doc__:
@ -215,7 +219,12 @@ def BinaryBuiltinWrapper(f):
@FunctionWrapper
@wraps(f)
def inner(stack, expression, dictionary):
try:
(a, (b, stack)) = stack
except ValueError:
raise StackUnderflowError
if not isinstance(a, int) or not isinstance(b, int):
raise NotAnIntError
result = f(b, a)
return (result, stack), expression, dictionary
return inner