Minor cleanup.
Improve the behavior of the World.
This commit is contained in:
+9
-3
@@ -20,6 +20,7 @@
|
|||||||
from inspect import getdoc
|
from inspect import getdoc
|
||||||
|
|
||||||
from joy.joy import run
|
from joy.joy import run
|
||||||
|
from joy.parser import Symbol
|
||||||
from joy.utils.stack import stack_to_string
|
from joy.utils.stack import stack_to_string
|
||||||
|
|
||||||
|
|
||||||
@@ -39,9 +40,12 @@ class World(object):
|
|||||||
self.text_widget = text_widget
|
self.text_widget = text_widget
|
||||||
|
|
||||||
def do_lookup(self, name):
|
def do_lookup(self, name):
|
||||||
word = self.dictionary[name]
|
if name in self.dictionary:
|
||||||
self.stack = word, self.stack
|
self.stack = (Symbol(name), ()), self.stack
|
||||||
self.print_stack()
|
self.print_stack()
|
||||||
|
else:
|
||||||
|
assert is_numerical(name)
|
||||||
|
self.interpret(name)
|
||||||
|
|
||||||
def do_opendoc(self, name):
|
def do_opendoc(self, name):
|
||||||
if is_numerical(name):
|
if is_numerical(name):
|
||||||
@@ -53,7 +57,7 @@ class World(object):
|
|||||||
print repr(name), '???'
|
print repr(name), '???'
|
||||||
else:
|
else:
|
||||||
print getdoc(word)
|
print getdoc(word)
|
||||||
self.text_widget.see('end')
|
self.print_stack()
|
||||||
|
|
||||||
def pop(self):
|
def pop(self):
|
||||||
if self.stack:
|
if self.stack:
|
||||||
@@ -70,11 +74,13 @@ class World(object):
|
|||||||
return self.stack[0]
|
return self.stack[0]
|
||||||
|
|
||||||
def interpret(self, command):
|
def interpret(self, command):
|
||||||
|
try:
|
||||||
self.stack, _, self.dictionary = run(
|
self.stack, _, self.dictionary = run(
|
||||||
command,
|
command,
|
||||||
self.stack,
|
self.stack,
|
||||||
self.dictionary,
|
self.dictionary,
|
||||||
)
|
)
|
||||||
|
finally:
|
||||||
self.print_stack()
|
self.print_stack()
|
||||||
|
|
||||||
def has(self, name):
|
def has(self, name):
|
||||||
|
|||||||
Reference in New Issue
Block a user