(load "codegen.scm")
+; returns (os filename)
+(define (parse-args)
+ (define (parse-os x)
+ (if (null? x) 'darwin ; todo: replace this with the os
+ ; it was compiled with
+ (if
+ (or (equal? (car x) "-t")
+ (equal? (car x) "--target"))
+ (case (cadr x)
+ ("darwin" 'darwin)
+ ("linux" 'linux)
+ (else (error #f "unknown os")))
+ (parse-os (cdr x)))))
+ (define (parse-file x)
+ (if (null? x) 'stdin
+ (if
+ (or (equal? (car x) "-t")
+ (equal? (car x) "--target"))
+ (parse-file (cddr x))
+ (car x))))
+ (let ((args (cdr (command-line))))
+ (list (parse-os args) (parse-file args))))
+
+
+(define target (car (parse-args)))
+(define file (cadr (parse-args)))
+
(compile-to-binary
- (if (> (length (command-line)) 1)
- (call-with-input-file (cadr (command-line)) read)
- (read))
- "a.out")
+ (if (eqv? file 'stdin)
+ (read)
+ (call-with-input-file file read))
+ "a.out" target)