(use-modules (ice-9 threads) (ice-9 match) (system base target) (system base message) (guix build utils)) (define warnings ;; FIXME: 'format' is missing because it reports "non-literal format ;; strings" due to the fact that we use 'G_' instead of '_'. We'll need ;; help from Guile to solve this. '(unsupported-warning unbound-variable arity-mismatch)) (define host %host-type) (define srcdir (getcwd)) (define (relative-file file) (if (string-prefix? (string-append srcdir "/") file) (string-drop file (+ 1 (string-length srcdir))) file)) (define (scm->go file) (let* ((relative (relative-file file)) (without-extension (string-drop-right relative 4))) (string-append without-extension ".go"))) (cond-expand (guile-2.2 (use-modules (language tree-il optimize) (language cps optimize))) (else #f)) (define %default-optimizations ;; Default optimization options (equivalent to -O2 on Guile 2.2). (cond-expand (guile-2.2 (append (tree-il-default-optimization-options) (cps-default-optimization-options))) (else '()))) (define %lightweight-optimizations ;; Lightweight optimizations (like -O0, but with partial evaluation). (let loop ((opts %default-optimizations) (result '())) (match opts (() (reverse result)) ((#:partial-eval? _ rest ...) (loop rest `(#t #:partial-eval? ,@result))) ((kw _ rest ...) (loop rest `(#f ,kw ,@result)))))) (define (optimization-options file) (if (string-contains file "gnu/packages/") %lightweight-optimizations ;build faster '())) (define (compile-file* file output-mutex) (let ((go (scm->go file))) (with-mutex output-mutex (format #t " GUILEC ~a~%" go) (force-output)) (mkdir-p (dirname go)) (with-fluids ((*current-warning-prefix* "")) (with-target host (lambda () (compile-file file #:output-file go #:to 'cps #:opts `(#:warnings ,warnings ,@(optimization-options file)))))))) (use-modules (statprof)) (gcprof (lambda () (compile-file* ;; "t.scm" "gnu/packages/python.scm" (make-mutex))))