Some integration with Type Checking.

Now the UI highlights commands and numbers as you move the mouse, numbers
are blue, commands that type-check are green, commands that fail to
type-check are orange and will not be interpreted, and if there is no
stack effect information available for a command it is grey but you can
still attempt to execute it.

You can still evaluate whole expressions by selceting them and
right-inter-clicking before you release the left button, or by putting
the cursor on a line and typing ctrl-enter, which will run the whole
line.  These expressions are NOT (yet) type-checked.
This commit is contained in:
Simon Forman
2018-07-15 11:48:08 -07:00
parent 0292e8a297
commit e169c6aae2
5 changed files with 76 additions and 15 deletions
+26
View File
@@ -9,6 +9,7 @@ and we can introduce a kind of Kleene Star or sequence type that can stand for
an unbounded sequence of other types.
'''
import sys
from inspect import stack as inspect_stack
from itertools import chain, product
from logging import getLogger
@@ -343,6 +344,31 @@ def infer(*expression):
return sorted(set(_infer(list_to_stack(expression))))
def type_check(name, stack):
'''
Trinary predicate. True if named function type-checks, False if it
fails, None if it's indeterminate (because I haven't entered it into
the FUNCTIONS dict yet.)
'''
try:
func = FUNCTIONS[name]
except KeyError:
return # None, indicating unknown
for fi, fo in infer(func):
try:
U = unify(fi, stack)
except JoyTypeError, e:
#print e
continue
except ValueError, e:
#print >> sys.stderr, name, e, stack
continue
#print U
return True
return False
a0, a1, a2, a3, a4, a5, a6, a7, a8, a9 = A
b0, b1, b2, b3, b4, b5, b6, b7, b8, b9 = B
n0, n1, n2, n3, n4, n5, n6, n7, n8, n9 = N