From c4d7f3178bbd2d16660ff1f94961c811c9d528c3 Mon Sep 17 00:00:00 2001 From: Stefan Israelsson Tampe Date: Tue, 11 Dec 2018 22:47:14 +0100 Subject: fix misscompilation of while loops --- modules/language/python/spec.scm | 46 ++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 9 deletions(-) (limited to 'modules/language/python/spec.scm') 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)) -- cgit v1.2.3