• R/O
  • SSH

Joypy: Commit

Main interpreter and library.


Commit MetaInfo

Revision4e07e6751eba59e0628de49f7ebf3cd15bfa6803 (tree)
Time2018-07-19 08:13:57
AuthorSimon Forman <sforman@hush...>
CommiterSimon Forman

Log Message

Cache the results of type checking.

Change Summary

Incremental Difference

diff -r 1ee655f86008 -r 4e07e6751eba joy/gui/world.py
--- a/joy/gui/world.py Wed Jul 18 14:55:39 2018 -0700
+++ b/joy/gui/world.py Wed Jul 18 16:13:57 2018 -0700
@@ -17,6 +17,10 @@
1717 # You should have received a copy of the GNU General Public License
1818 # along with joy.py. If not see <http://www.gnu.org/licenses/>.
1919 #
20+from logging import getLogger
21+
22+_log = getLogger(__name__)
23+
2024 import os, pickle, sys
2125 from inspect import getdoc
2226
@@ -40,14 +44,20 @@
4044 self.stack = stack
4145 self.dictionary = dictionary or {}
4246 self.text_widget = text_widget
47+ self.check_cache = {}
4348
4449 def check(self, name):
45- return type_check(name, self.stack)
50+ try:
51+ res = self.check_cache[name]
52+ except KeyError:
53+ res = self.check_cache[name] = type_check(name, self.stack)
54+ return res
4655
4756 def do_lookup(self, name):
4857 if name in self.dictionary:
4958 self.stack = (Symbol(name), ()), self.stack
5059 self.print_stack()
60+ self.check_cache.clear()
5161 else:
5262 assert is_numerical(name)
5363 self.interpret(name)
@@ -68,11 +78,13 @@
6878 if self.stack:
6979 self.stack = self.stack[1]
7080 self.print_stack()
81+ self.check_cache.clear()
7182
7283 def push(self, it):
7384 it = it.encode('utf8')
7485 self.stack = it, self.stack
7586 self.print_stack()
87+ self.check_cache.clear()
7688
7789 def peek(self):
7890 if self.stack:
@@ -83,6 +95,7 @@
8395 assert self.has(command), repr(command)
8496 if self.check(command) == False: # not in {True, None}:
8597 return
98+ old_stack = self.stack
8699 try:
87100 self.stack, _, self.dictionary = run(
88101 command,
@@ -91,6 +104,8 @@
91104 )
92105 finally:
93106 self.print_stack()
107+ if old_stack != self.stack:
108+ self.check_cache.clear()
94109
95110 def has(self, name):
96111 return self.dictionary.has_key(name)
@@ -140,7 +155,7 @@
140155 'message',
141156 committer='Simon Forman <forman.simon@gmail.com>',
142157 )
143- print >> sys.stderr, commit_id
158+ _log.info('commit %s', commit_id)
144159
145160 def load_stack(self):
146161 if os.path.exists(self.filename):
Show on old repository browser