summaryrefslogtreecommitdiff
path: root/modules/language/python/spec.scm
blob: 1389165094528cb733aeddeef03467251aba52ef (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
(define-module (language python spec)
  #:use-module (language python parser)
  #:use-module (language python compile)
  #:use-module (rnrs io ports)
  #:use-module (ice-9 pretty-print)
  #:use-module (system base compile)
  #:use-module (system base language)
  #:use-module (language scheme compile-tree-il)
  #:use-module (language scheme decompile-tree-il)
  #:use-module (ice-9 rdelim)
  #:export (python))

;;;
;;; Language definition
;;;

(define (pr . x) (pretty-print x) (car (reverse  x)))

(define (c x) (pr (comp (pr (p (pr x))))))
(define (cc port x)
  (if (equal? x "") (read port) (c x)))

(define-language python
  #:title	"python"
  #:reader      (lambda (port env)
                  (cc port (read-string port)))

  #:compilers   `((tree-il . ,compile-tree-il))
  #:decompilers `((tree-il . ,decompile-tree-il))
  #:evaluator	(lambda (x module) (primitive-eval x))
  #:printer	write
  #:make-default-environment
                (lambda ()
                  ;; Ideally we'd duplicate the whole module hierarchy so that `set!',
                  ;; `fluid-set!', etc. don't have any effect in the current environment.
                  (let ((m (make-fresh-user-module)))
                    ;; Provide a separate `current-reader' fluid so that
                    ;; compile-time changes to `current-reader' are
                    ;; limited to the current compilation unit.
                    (module-define! m 'current-reader (make-fluid))

                    ;; Default to `simple-format', as is the case until
                    ;; (ice-9 format) is loaded.  This allows
                    ;; compile-time warnings to be emitted when using
                    ;; unsupported options.
                    (module-set! m 'format simple-format)
                    
                    m)))