-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelisp.rkt
54 lines (40 loc) · 1.31 KB
/
delisp.rkt
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
49
50
51
52
53
54
#lang racket/base
(require racket/file
racket/match
racket/cmdline
racket/system
racket/path)
(require "compat.rkt")
(require "compiler.rkt")
(define project-root
(simple-form-path (path-only (find-system-path 'run-file))))
(define output-directory
(build-path project-root ".delisp" "builds"))
(define (get-output-file input-file ext)
(let ([relative (find-relative-path project-root (simple-form-path input-file))])
(build-path output-directory (path-replace-extension relative ext))))
;; Compile a file.
;;
;; All IO is confined in this file.
(define (compile-file file)
(let* ([m (file->list file)]
[json-string (compile-module m)]
[output-file (get-output-file file ".js")])
(make-parent-directory* output-file)
(format-js-to-file json-string output-file)))
(define (format-js-to-file ast out)
(let ([json-file (make-temporary-file)])
(display-to-file ast json-file #:exists 'truncate)
(let ([node (find-executable-path "node")])
(system* node "format.js" json-file out))))
(define (format-js ast)
(format-js-to-file ast "-"))
(define (compile-module-to-string m)
(format-js (compile-module m)))
(define file-to-compile
(command-line
#:program "delisp"
#:args (filename)
filename))
(void
(compile-file file-to-compile))