Merge branch 'master' of lukelau.me:/srv/git/scheme
[scheme.git] / main.scm
1 (load "codegen.scm")
2 (load "platform.scm")
3
4 ; returns (os filename)
5 (define (parse-args)
6   (define (parse-os x)
7     (if (null? x) host-os ; todo: replace this with the os
8                                         ; it was compiled with
9         (if
10          (or (equal? (car x) "-t")
11              (equal? (car x) "--target"))
12          (case (cadr x)
13            ("darwin" 'darwin)
14            ("linux"  'linux)
15            (else (error #f "unknown os")))         
16          (parse-os (cdr x)))))
17   (define (parse-file x)
18     (if (null? x) 'stdin
19         (if
20          (or (equal? (car x) "-t")
21              (equal? (car x) "--target"))
22          (parse-file (cddr x))
23          (car x))))
24   (let ((args (cdr (command-line))))
25     (list (parse-os args) (parse-file args))))
26
27
28 (define target (car (parse-args)))
29 (define file (cadr (parse-args)))
30
31 (define (read-prog port)
32   (if (port-input-empty? port)
33       '()
34       (cons (read) (read-prog port))))
35
36 (compile-to-binary
37  (if (eqv? file 'stdin)
38      (read-prog (current-input-port))
39      (call-with-input-file file read-prog))
40  "a.out" target)