OSDN Git Service

This brings Python Joy into congruence with Nim.
authorSimon Forman <sforman@hushmail.com>
Sat, 10 Apr 2021 01:01:07 +0000 (18:01 -0700)
committerSimon Forman <sforman@hushmail.com>
Sat, 10 Apr 2021 01:01:07 +0000 (18:01 -0700)
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.

joy/library.py
joy/utils/generated_library.py
joy/utils/stack.py

index 6e7f817..8bd38f1 100644 (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
index 071cce4..2e51422 100644 (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)
 
 
index c460384..366d8a4 100644 (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):