compiler
[software/python-on-guile.git] / modules / language / python / spec.scm
1 (define-module (language python spec)
2 #:use-module (language python 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)
11 #:export (python))
12
13 ;;;
14 ;;; Language definition
15 ;;;
16
17 (define (pr . x) (pretty-print x) (car (reverse x)))
18
19 (define (c x) (pr (comp (pr (p (pr x))))))
20 (define (cc port x)
21 (if (equal? x "") (read port) (c x)))
22
23 (define-language python
24 #:title "python"
25 #:reader (lambda (port env)
26 (cc port (read-string port)))
27
28 #:compilers `((tree-il . ,compile-tree-il))
29 #:decompilers `((tree-il . ,decompile-tree-il))
30 #:evaluator (lambda (x module) (primitive-eval x))
31 #:printer write
32 #:make-default-environment
33 (lambda ()
34 ;; Ideally we'd duplicate the whole module hierarchy so that `set!',
35 ;; `fluid-set!', etc. don't have any effect in the current environment.
36 (let ((m (make-fresh-user-module)))
37 ;; Provide a separate `current-reader' fluid so that
38 ;; compile-time changes to `current-reader' are
39 ;; limited to the current compilation unit.
40 (module-define! m 'current-reader (make-fluid))
41
42 ;; Default to `simple-format', as is the case until
43 ;; (ice-9 format) is loaded. This allows
44 ;; compile-time warnings to be emitted when using
45 ;; unsupported options.
46 (module-set! m 'format simple-format)
47
48 m)))