-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathskive.rkt
executable file
·42 lines (36 loc) · 1.16 KB
/
skive.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
#!/usr/bin/env racket
#lang racket
(require racket/cmdline
"src/compile.rkt")
(define output-file (make-parameter #f))
(define if1-mode (make-parameter #f))
(define input-file
(command-line
#:program "skive"
#:once-each
[("--IF1") "Do not compile, only produce IF1 code" (if1-mode #t)]
[("-o" "--out") file "Output file" (output-file file)]
#:args (filename)
filename))
(define (read-all input)
(let loop ((res '())
(cur (read input)))
(if (eof-object? cur)
res
(loop (append res `(,cur))
(read input)))))
;; TODO: use file->list instead of read-all
(define (compile input output-file)
(let* ((skive-code (last (read-all input)))
(if1-code (compile-sequence-to-if1 skive-code)))
(if (if1-mode)
(call-with-output-file (if output-file output-file "if1.out")
(lambda (out)
(display if1-code out)))
(compile-if1-to-native if1-code
#:path (if output-file output-file "s.out")
#:type 'exe))
(void)))
(call-with-input-file
input-file
(lambda (input) (compile input (output-file))))