applicable structs used
[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 (if (not (fluid-ref (@@ (system base compile) %in-compile)))
33 (cc port (read-line port))
34 (cc port (read-string port))))
35
36 #:compilers `((tree-il . ,compile-tree-il))
37 #:decompilers `((tree-il . ,decompile-tree-il))
38 #:evaluator (lambda (x module) (primitive-eval x))
39 #:printer write
40 #:make-default-environment
41 (lambda ()
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))
49
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)
55
56 m)))