parent
9ea0157969
commit
4fb9e1e003
|
|
@ -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,12 +74,14 @@ class World(object):
|
||||||
return self.stack[0]
|
return self.stack[0]
|
||||||
|
|
||||||
def interpret(self, command):
|
def interpret(self, command):
|
||||||
self.stack, _, self.dictionary = run(
|
try:
|
||||||
command,
|
self.stack, _, self.dictionary = run(
|
||||||
self.stack,
|
command,
|
||||||
self.dictionary,
|
self.stack,
|
||||||
)
|
self.dictionary,
|
||||||
self.print_stack()
|
)
|
||||||
|
finally:
|
||||||
|
self.print_stack()
|
||||||
|
|
||||||
def has(self, name):
|
def has(self, name):
|
||||||
return self.dictionary.has_key(name)
|
return self.dictionary.has_key(name)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue