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