From: Simon Forman Date: Sat, 10 Apr 2021 01:01:07 +0000 (-0700) Subject: This brings Python Joy into congruence with Nim. X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=7f193fbdbe8c30ff1e30acabbe0ec8f547bc69ff;p=joypy%2FThun.git 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. --- diff --git a/joy/library.py b/joy/library.py index 6e7f817..8bd38f1 100644 --- a/joy/library.py +++ b/joy/library.py @@ -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 diff --git a/joy/utils/generated_library.py b/joy/utils/generated_library.py index 071cce4..2e51422 100644 --- a/joy/utils/generated_library.py +++ b/joy/utils/generated_library.py @@ -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) diff --git a/joy/utils/stack.py b/joy/utils/stack.py index c460384..366d8a4 100644 --- a/joy/utils/stack.py +++ b/joy/utils/stack.py @@ -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):