Bringing it in line with Nim version.
This commit is contained in:
parent
65b2b4a7e3
commit
227e8b124b
|
|
@ -27,7 +27,11 @@ 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
|
from .utils.errors import (
|
||||||
|
NotAListError,
|
||||||
|
NotAnIntError,
|
||||||
|
StackUnderflowError,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class UnknownSymbolError(KeyError): pass
|
class UnknownSymbolError(KeyError): pass
|
||||||
|
|
@ -136,6 +140,8 @@ def interp(stack=(), dictionary=None):
|
||||||
print('Not enough values on stack.')
|
print('Not enough values on stack.')
|
||||||
except NotAnIntError:
|
except NotAnIntError:
|
||||||
print('Not an integer.')
|
print('Not an integer.')
|
||||||
|
except NotAListError:
|
||||||
|
print('Not a list.')
|
||||||
except:
|
except:
|
||||||
print_exc()
|
print_exc()
|
||||||
print(stack_to_string(stack))
|
print(stack_to_string(stack))
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ import operator, math
|
||||||
|
|
||||||
from .parser import text_to_expression, Symbol
|
from .parser import text_to_expression, Symbol
|
||||||
from .utils import generated_library as genlib
|
from .utils import generated_library as genlib
|
||||||
|
from .utils.errors import NotAnIntError, StackUnderflowError
|
||||||
from .utils.stack import (
|
from .utils.stack import (
|
||||||
concat,
|
concat,
|
||||||
expression_to_string,
|
expression_to_string,
|
||||||
|
|
@ -189,10 +190,6 @@ 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__:
|
||||||
|
|
@ -223,7 +220,11 @@ def BinaryBuiltinWrapper(f):
|
||||||
(a, (b, stack)) = stack
|
(a, (b, stack)) = stack
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise StackUnderflowError
|
raise StackUnderflowError
|
||||||
if not isinstance(a, int) or not isinstance(b, int):
|
if (not isinstance(a, int)
|
||||||
|
or not isinstance(b, int)
|
||||||
|
or isinstance(a, bool) # Because bools are ints in Python.
|
||||||
|
or isinstance(a, bool)
|
||||||
|
):
|
||||||
raise NotAnIntError
|
raise NotAnIntError
|
||||||
result = f(b, a)
|
result = f(b, a)
|
||||||
return (result, stack), expression, dictionary
|
return (result, stack), expression, dictionary
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
class NotAListError(Exception): pass
|
||||||
|
class NotAnIntError(Exception): pass
|
||||||
|
class StackUnderflowError(Exception): pass
|
||||||
|
|
||||||
|
|
||||||
Loading…
Reference in New Issue