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
+16 -2
View File
@@ -23,6 +23,7 @@ from inspect import getdoc
from joy.joy import run
from joy.parser import Symbol
from joy.utils.stack import stack_to_string
from joy.utils.polytypes import type_check
def is_numerical(s):
@@ -40,6 +41,9 @@ class World(object):
self.dictionary = dictionary or {}
self.text_widget = text_widget
def check(self, name):
return type_check(name, self.stack)
def do_lookup(self, name):
if name in self.dictionary:
self.stack = (Symbol(name), ()), self.stack
@@ -75,6 +79,10 @@ class World(object):
return self.stack[0]
def interpret(self, command):
if len(command.split()) == 1 and not is_numerical(command):
assert self.has(command), repr(command)
if self.check(command) == False: # not in {True, None}:
return
try:
self.stack, _, self.dictionary = run(
command,
@@ -109,8 +117,14 @@ class StackDisplayWorld(World):
self.relative_STACK_FN = rel_filename
def interpret(self, command):
print '\njoy?', command
super(StackDisplayWorld, self).interpret(command)
if (
is_numerical(command)
or len(command.split()) > 1
or self.has(command)
and self.check(command) in {True, None}
):
print '\njoy?', command
super(StackDisplayWorld, self).interpret(command)
def print_stack(self):
print '\n%s <-' % stack_to_string(self.stack)