1 (define-module (language python spec
)
2 #:use-module
(parser stis-parser lang python3-parser
)
3 #:use-module
(language python compile
)
4 #:use-module
(rnrs io ports
)
5 #:use-module
(ice-9 pretty-print
)
6 #:use-module
(system base compile
)
7 #:use-module
(system base language
)
8 #:use-module
(language scheme compile-tree-il
)
9 #:use-module
(language scheme decompile-tree-il
)
10 #:use-module
(ice-9 rdelim
)
14 ;;; Language definition
18 (define port
(open-file "/home/stis/src/python-on-guile/log.txt" "a"))
19 (with-output-to-port port
21 (pretty-print x
) (car (reverse x
))))
25 (define (c x
) (pr (comp (pr (p (pr x
))))))
27 (if (equal? x
"") (read port
) (c x
)))
29 (define-language python
31 #:reader
(lambda (port env
)
32 (if (not (fluid-ref (@@ (system base compile
) %in-compile
)))
33 (cc port
(read-line port
))
34 (cc port
(read-string port
))))
36 #:compilers
`((tree-il .
,compile-tree-il
))
37 #:decompilers
`((tree-il .
,decompile-tree-il
))
38 #:evaluator
(lambda (x module
) (primitive-eval x
))
40 #:make-default-environment
42 ;; Ideally we'd duplicate the whole module hierarchy so that `set!',
43 ;; `fluid-set!', etc. don't have any effect in the current environment.
44 (let ((m (make-fresh-user-module)))
45 ;; Provide a separate `current-reader' fluid so that
46 ;; compile-time changes to `current-reader' are
47 ;; limited to the current compilation unit.
48 (module-define! m
'current-reader
(make-fluid))
50 ;; Default to `simple-format', as is the case until
51 ;; (ice-9 format) is loaded. This allows
52 ;; compile-time warnings to be emitted when using
53 ;; unsupported options.
54 (module-set! m
'format simple-format
)