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:
parent
6fc77a9a4a
commit
65b2b4a7e3
|
|
@ -27,6 +27,7 @@ from builtins import input
|
||||||
from traceback import print_exc
|
from traceback import print_exc
|
||||||
from .parser import text_to_expression, ParseError, Symbol
|
from .parser import text_to_expression, ParseError, Symbol
|
||||||
from .utils.stack import stack_to_string
|
from .utils.stack import stack_to_string
|
||||||
|
from .library import NotAnIntError, StackUnderflowError
|
||||||
|
|
||||||
|
|
||||||
class UnknownSymbolError(KeyError): pass
|
class UnknownSymbolError(KeyError): pass
|
||||||
|
|
@ -131,6 +132,10 @@ def interp(stack=(), dictionary=None):
|
||||||
stack, _, dictionary = run(text, stack, dictionary)
|
stack, _, dictionary = run(text, stack, dictionary)
|
||||||
except UnknownSymbolError as sym:
|
except UnknownSymbolError as sym:
|
||||||
print('Unknown:', sym)
|
print('Unknown:', sym)
|
||||||
|
except StackUnderflowError:
|
||||||
|
print('Not enough values on stack.')
|
||||||
|
except NotAnIntError:
|
||||||
|
print('Not an integer.')
|
||||||
except:
|
except:
|
||||||
print_exc()
|
print_exc()
|
||||||
print(stack_to_string(stack))
|
print(stack_to_string(stack))
|
||||||
|
|
|
||||||
|
|
@ -189,6 +189,10 @@ while == swap [nullary] cons dup dipd concat loop
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class NotAnIntError(Exception): pass
|
||||||
|
class StackUnderflowError(Exception): pass
|
||||||
|
|
||||||
|
|
||||||
def FunctionWrapper(f):
|
def FunctionWrapper(f):
|
||||||
'''Set name attribute.'''
|
'''Set name attribute.'''
|
||||||
if not f.__doc__:
|
if not f.__doc__:
|
||||||
|
|
@ -215,7 +219,12 @@ def BinaryBuiltinWrapper(f):
|
||||||
@FunctionWrapper
|
@FunctionWrapper
|
||||||
@wraps(f)
|
@wraps(f)
|
||||||
def inner(stack, expression, dictionary):
|
def inner(stack, expression, dictionary):
|
||||||
|
try:
|
||||||
(a, (b, stack)) = stack
|
(a, (b, stack)) = stack
|
||||||
|
except ValueError:
|
||||||
|
raise StackUnderflowError
|
||||||
|
if not isinstance(a, int) or not isinstance(b, int):
|
||||||
|
raise NotAnIntError
|
||||||
result = f(b, a)
|
result = f(b, a)
|
||||||
return (result, stack), expression, dictionary
|
return (result, stack), expression, dictionary
|
||||||
return inner
|
return inner
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue