forked from eholk/harlan
/
harlanc.scm
executable file
·45 lines (39 loc) · 1.35 KB
/
harlanc.scm
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
#! /usr/bin/env scheme-script
;; -*- scheme -*-
(import
(chezscheme)
(harlan compile-opts)
(harlan driver)
(harlan backend print-c)
(harlan compiler)
(util system) ;; HARLAND
)
(print-gensym 'pretty/suffix)
;; This could be set from the env var HARLAND, or based on the
;; directory in which this script resides. Using the latter:
(HARLAND (path-parent (car (command-line))))
;; Converts foo/bar.kfc to bar
(define (output-filename input)
(let ((base (path-last (path-root input))))
(if (make-shared-object)
(string-append base ".so")
base)))
(define print-compile-harlan
(lambda (filename)
(let-values (((input testspec) (read-source filename)))
(if (assq 'iterate testspec)
(error 'harlanc
"Test iteration is not supported. Use run-tests.scm instead.")
(let* ((c-expr (compile-harlan input))
(c-code (if (timing)
(time (harlan-format-c c-expr))
(harlan-format-c c-expr))))
(if (verbose) (printf c-code))
(g++-compile-stdin c-code (output-filename filename)))))))
(define (harlanc args)
(let ((args (parse-args (cdr args))))
(unless (null? args)
;; There should be a usage.
(let ((filename (car args)))
(print-compile-harlan filename)))))
(harlanc (command-line))