[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/geiser-chicken e9bebe2 032/102: Adds memoization
From: |
Philip Kaludercic |
Subject: |
[nongnu] elpa/geiser-chicken e9bebe2 032/102: Adds memoization |
Date: |
Sun, 1 Aug 2021 18:26:50 -0400 (EDT) |
branch: elpa/geiser-chicken
commit e9bebe242b5fa3d0e6541aeecd5c5a213449046c
Author: Dan Leslie <dan@ironoxide.ca>
Commit: Dan Leslie <dan@ironoxide.ca>
Adds memoization
Clears memo when anything other than a safe geiser call is made.
Removes the last calls to regex within the thing
---
geiser/emacs.scm | 50 ++++++++++++++++++++++++++++++++++++--------------
1 file changed, 36 insertions(+), 14 deletions(-)
diff --git a/geiser/emacs.scm b/geiser/emacs.scm
index df804c3..09a3068 100644
--- a/geiser/emacs.scm
+++ b/geiser/emacs.scm
@@ -5,8 +5,7 @@
;; have received a copy of the license along with this program. If
;; not, see <http://www.xfree86.org/3.3.6/COPYRIGHT2.html#5>.
-(module geiser
- ;; A bunch of these needn't be toplevel functions
+(module geiser
(geiser-eval
geiser-no-values
geiser-newline
@@ -37,10 +36,11 @@
extras
ports
posix
- regex
srfi-1
srfi-13
+ srfi-14
srfi-18
+ srfi-69
tcp
utils)
@@ -219,8 +219,17 @@
(define module-name ##sys#module-name)
(define (list-modules) (map car ##sys#module-table))
- (define debug-log (make-parameter #f))
+ (define memo (make-parameter (make-hash-table)))
+ (define (clear-memo) (hash-table-clear! (memo)))
+ (define (memoize tag thunk)
+ (let ((table (memo)))
+ (if (hash-table-exists? table tag)
+ (hash-table-ref table tag)
+ (begin
+ (hash-table-set! table tag (thunk))
+ (memoize tag thunk)))))
+ (define debug-log (make-parameter #f))
(define (write-to-log form)
(when (geiser-use-debug-log)
(when (not (debug-log))
@@ -390,7 +399,8 @@
(args (if (or (list? rest) (pair? rest)) (cdr rest) '())))
(define (clean-arg arg)
- (string->symbol (string-substitute "(.*[^0-9]+)[0-9]+" "\\1"
(->string arg))))
+ (let ((s (->string arg)))
+ (substring/shared s 0 (string-skip-right s char-set:digit))))
(define (collect-args args #!key (reqs? #t) (opts? #f) (keys? #f))
(when (not (null? args))
@@ -452,7 +462,7 @@
(or (not filter-for-type)
(eq? (node-type n) filter-for-type)))
(match-nodes symbol))))))
-
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Geiser core functions
@@ -463,24 +473,36 @@
(define (geiser-eval module form . rest)
;; We can't allow nested module definitions in Chicken
(define (form-has-module? form)
- (let ((reg "\\( *module +|\\( *define-library +"))
- (string-search reg form)))
-
+ (or (eq? (car form) 'module) (eq? (car form) 'define-library)))
+
+ (define (form-has-safe-geiser? form)
+ (any (cut eq? (car form) <>)
+ '(geiser-no-values geiser-newline geiser-start-server
geiser-completions
+ geiser-autodoc geiser-object-signature geiser-symbol-location
+ geiser-symbol-documentation geiser-find-file
geiser-add-to-load-path
+ geiser-module-exports geiser-module-path geiser-module-location
+ geiser-module-completions geiser-macroexpand
geiser-use-debug-log)))
+
(when (and module
(not (symbol? module)))
(error "Module should be a symbol"))
;; All calls start at toplevel
- (let* ((str-form (format "~s" form))
- (is-module? (form-has-module? str-form))
+ (let* ((is-module? (form-has-module? form))
+ (is-safe-geiser? (form-has-safe-geiser? form))
(host-module (and (not is-module?)
(any (cut equal? module <>) (list-modules))
- module)))
+ module))
+ (thunk (lambda () (eval form))))
- (write-to-log '[[REQUEST]])
+ (write-to-log `[[REQUEST host-module ,host-module is-safe-geiser?
,is-safe-geiser?]])
(write-to-log form)
- (call-with-result host-module (lambda () (eval form)))))
+ (if is-safe-geiser?
+ (call-with-result host-module (lambda () (memoize form thunk)))
+ (begin
+ (clear-memo)
+ (call-with-result host-module thunk)))))
;; Load a file
- [nongnu] elpa/geiser-chicken 885fed9 095/102: Nit: first -> car, (continued)
- [nongnu] elpa/geiser-chicken 885fed9 095/102: Nit: first -> car, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-chicken 0016d96 096/102: Whitespace, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-chicken 555b25b 100/102: autoloads, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-chicken 1655717 080/102: Begin the summary lines of all elisp libraries with three semicolons, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-chicken 6370805 088/102: add geiser# prefix to geiser calls, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-chicken 2127c37 097/102: Fix error when compiling define-library form in Chicken, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-chicken b9b12e0 099/102: version update, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-chicken d7d4445 029/102: Refactored to reduce the reliance on regex., Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-chicken 0efe613 026/102: Limits search to the line beginning, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-chicken 6743d36 036/102: Stopped over-aggressive memoization, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-chicken e9bebe2 032/102: Adds memoization,
Philip Kaludercic <=
- [nongnu] elpa/geiser-chicken bfccf97 038/102: Fixes for Literals, Errors and Modules, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-chicken 2481dfc 041/102: Right-most character of arguments was being cut, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-chicken c3731bf 047/102: Oops: shell-quote-binary -> shell-quote-argument, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-chicken bc3f877 049/102: Fuzzy matching for Chicken AutoDoc and Completions, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-chicken d3743db 051/102: Fixes a potential endless loop., Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-chicken 1d3e6de 023/102: Add general font-lock keywords for all implementations, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-chicken c1f5959 053/102: Remove compilation of chicken module, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-chicken 975fca9 001/102: Initial Chicken support, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-chicken 0e84bba 013/102: The issue arose with numerics, as well., Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-chicken 6adf5fd 018/102: Adds recognition of the 'crunch' R5RS subset, Philip Kaludercic, 2021/08/01