This brings Python Joy into congruence with Nim.

It's hacky.  I edited the generated file.  The more complicated
functions like popop will not generate the same errors as the Nim
versions.  This is only congruence in the sense that the current jtest
suite passes identically on both.

Ideally I should be generating both the Nim and Python code from the
Prolog compiler.
This commit is contained in:
Simon Forman 2021-04-09 18:01:07 -07:00
parent 8e0472a5ff
commit 7f193fbdbe
3 changed files with 9 additions and 9 deletions

View File

@ -222,7 +222,7 @@ def BinaryBuiltinWrapper(f):
try:
(a, (b, stack)) = stack
except ValueError:
raise StackUnderflowError
raise StackUnderflowError('Not enough values on stack.')
if (not isinstance(a, int)
or not isinstance(b, int)
or isinstance(a, bool) # Because bools are ints in Python.
@ -849,7 +849,7 @@ def i(stack, expression, dictionary):
try:
quote, stack = stack
except ValueError:
raise StackUnderflowError
raise StackUnderflowError('Not enough values on stack.')
return stack, concat(quote, expression), dictionary
@ -1174,7 +1174,7 @@ def dip(stack, expression, dictionary):
try:
(quote, (x, stack)) = stack
except ValueError:
raise StackUnderflowError
raise StackUnderflowError('Not enough values on stack.')
expression = (x, expression)
return stack, concat(quote, expression), dictionary
@ -1378,13 +1378,13 @@ def loop(stack, expression, dictionary):
try:
quote, stack = stack
except ValueError:
raise StackUnderflowError
raise StackUnderflowError('Not enough values on stack.')
if not isinstance(quote, tuple):
raise NotAListError('Loop body not a list.')
try:
(flag, stack) = stack
except ValueError:
raise StackUnderflowError
raise StackUnderflowError('Not enough values on stack.')
if flag:
expression = concat(quote, (quote, (S_loop, expression)))
return stack, expression, dictionary

View File

@ -67,10 +67,10 @@ def cons(stack):
"""
try: s0, stack = stack
except ValueError: raise StackUnderflowError
if not isinstance(s0, tuple): raise NotAListError
except ValueError: raise StackUnderflowError('Not enough values on stack.')
if not isinstance(s0, tuple): raise NotAListError('Not a list.')
try: a1, s23 = stack
except ValueError: raise StackUnderflowError
except ValueError: raise StackUnderflowError('Not enough values on stack.')
return ((a1, s0), s23)

View File

@ -177,7 +177,7 @@ def concat(quote, expression):
temp = []
while quote:
if not isinstance(quote, tuple):
raise NotAListError
raise NotAListError('Not a list.')
item, quote = quote
temp.append(item)
for item in reversed(temp):