diff options
author | Stefan Israelsson Tampe <stefan.itampe@gmail.com> | 2019-03-13 09:20:18 +0100 |
---|---|---|
committer | Stefan Israelsson Tampe <stefan.itampe@gmail.com> | 2019-03-13 09:20:18 +0100 |
commit | 6b0070bb5c37b118eb09c1ec023999bbdf1781e7 (patch) | |
tree | 7bbc9df1036b0a7733ea45f3dd74a199929176e1 /modules/language/python/spec.scm | |
parent | e1bf1a32c8453ea485365e9704e7cb983db3b4bb (diff) | |
parent | db36b6633b5ccd709eac44635ca88e8683ddb4e3 (diff) |
Merge branch 'master' of https://gitlab.com/python-on-guile/python-on-guile
Diffstat (limited to 'modules/language/python/spec.scm')
-rw-r--r-- | modules/language/python/spec.scm | 46 |
1 files changed, 37 insertions, 9 deletions
diff --git a/modules/language/python/spec.scm b/modules/language/python/spec.scm index 8291a14..46ac186 100644 --- a/modules/language/python/spec.scm +++ b/modules/language/python/spec.scm @@ -18,6 +18,7 @@ ;;; Language definition ;;; + (define (pr . x) (define port (open-file "/home/stis/src/python-on-guile/log.txt" "a")) (with-output-to-port port @@ -26,11 +27,42 @@ (close port) (car (reverse x))) -(define (c x) (pr (comp (pr (p (pr x)))))) -(define (cc port x) - (if (equal? x "") (read port) (c x))) +(define (c int x) (pr (comp int (pr (p (pr x)))))) +(define (cc int port x) + (if (equal? x "") (read port) (c int x))) + +(define (e x) (eval (c #t x) (current-module))) -(define (e x) (eval (c x) (current-module))) + +(define (int) + (catch #t + (lambda () + (if (fluid-ref (@@ (system base compile) %in-compile)) + #f + #t)) + (lambda x #f))) + +(define (in) + (catch #t + (lambda () + (fluid-set! (@@ (system base compile) %in-compile) #t)) + (lambda x #f))) + +(define mapper (make-weak-key-hash-table)) + +(define python-reader-wrap + (lambda (port env) + (if (int) + (cc #t port (read-line port)) + (let lp ((port2 (hash-ref mapper port))) + (if port2 + (read port2) + (let ((port2 + (open-input-string (cc #f port (read-string port))))) + (use-modules (language python guilemod)) + (in) + (hash-set! mapper port port2) + (lp port2))))))) (catch #t (lambda () @@ -40,11 +72,7 @@ (define-language python #:title "python" - #:reader (lambda (port env) - (if (not (fluid-ref (@@ (system base compile) %in-compile))) - (cc port (read-line port)) - (cc port (read-string port)))) - + #:reader python-reader-wrap #:compilers `((tree-il . ,compile-tree-il)) #:decompilers `((tree-il . ,decompile-tree-il)) #:evaluator (lambda (x module) (primitive-eval x)) |