Bring it inline with Nim version.

See https://git.sr.ht/~sforman/joytest
This commit is contained in:
Simon Forman 2021-04-09 17:32:51 -07:00
parent 49bcab2e91
commit 810a6afdbb
2 changed files with 17 additions and 4 deletions

View File

@ -140,8 +140,8 @@ def interp(stack=(), dictionary=None):
print('Not enough values on stack.')
except NotAnIntError:
print('Not an integer.')
except NotAListError:
print('Not a list.')
except NotAListError as e:
print(e) # 'Not a list.'
except:
print_exc()
print(stack_to_string(stack))

View File

@ -30,7 +30,11 @@ import operator, math
from .parser import text_to_expression, Symbol
from .utils import generated_library as genlib
from .utils.errors import NotAnIntError, StackUnderflowError
from .utils.errors import (
NotAListError,
NotAnIntError,
StackUnderflowError,
)
from .utils.stack import (
concat,
expression_to_string,
@ -1371,7 +1375,16 @@ def loop(stack, expression, dictionary):
...
'''
quote, (flag, stack) = stack
try:
quote, stack = stack
except ValueError:
raise StackUnderflowError
if not isinstance(quote, tuple):
raise NotAListError('Loop body not a list.')
try:
(flag, stack) = stack
except ValueError:
raise StackUnderflowError
if flag:
expression = concat(quote, (quote, (S_loop, expression)))
return stack, expression, dictionary