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