From 858d81b49beb4a668fc9a8d392459776ed2b56d2 Mon Sep 17 00:00:00 2001 From: crc Date: Wed, 16 Dec 2020 14:54:46 +0000 Subject: [PATCH] nga-python: begin work to cache dictionary, provide faster versions of some words (working on #20) FossilOrigin-Name: cdfb621e669956d3ea1ca2c0a5ae74a78f7d90d0c728b2bd4768f53ec904f007 --- vm/nga-python/retro.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/vm/nga-python/retro.py b/vm/nga-python/retro.py index c64d4fa..bbb0657 100644 --- a/vm/nga-python/retro.py +++ b/vm/nga-python/retro.py @@ -42,8 +42,12 @@ class Retro: self.files = FileSystem() self.floats = FloatStack() self.afloats = FloatStack() - self.interpreter = self.memory.fetch(self.find_entry("interpret") + 1) - self.not_found = self.memory.fetch(self.find_entry("err:notfound") + 1) + self.Dictionary = dict() + self.Cached = dict() + self.Cached['interpreter'] = self.memory.fetch(self.find_entry("interpret") + 1) + self.Cached['not_found'] = self.memory.fetch(self.find_entry("err:notfound") + 1) + self.Cached['s:eq?'] = self.memory.fetch(self.find_entry("s:eq?") + 1) + self.instructions = [ self.i_nop, self.i_lit, @@ -440,7 +444,7 @@ class Retro: for token in line.split(): self.inject_string(token, 1024) self.stack.push(1024) - self.execute(self.interpreter, self.not_found) + self.execute(self.Cached['interpreter'], self.Cached['not_found']) def run_file(self, file): if not os.path.exists(file): @@ -456,7 +460,7 @@ class Retro: for token in line.strip().split(): self.inject_string(token, 1024) self.stack.push(1024) - self.execute(self.interpreter, self.not_found) + self.execute(self.Cached['interpreter'], self.Cached['not_found']) def update_image(self): import requests