X-Git-Url: http://git.lukelau.me/?p=scheme.git;a=blobdiff_plain;f=main.scm;h=df8e656978b66349472e5a3599c12f5eb809f7f4;hp=53daa7c73b947bd85035303146778e8dfa3543b6;hb=5ea42a37be529974bff32b719bd91e004d1dfcd8;hpb=bcab2117e8a77309c3becdda8c32b102229a6349 diff --git a/main.scm b/main.scm index 53daa7c..df8e656 100644 --- a/main.scm +++ b/main.scm @@ -1,7 +1,40 @@ (load "codegen.scm") +(load "platform.scm") + +; returns (os filename) +(define (parse-args) + (define (parse-os x) + (if (null? x) host-os ; 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))) + +(define (read-prog port) + (if (port-input-empty? port) + '() + (cons (read) (read-prog port)))) (compile-to-binary - (if (> (length (command-line)) 1) - (call-with-input-file (cadr (command-line)) read) - (read)) - "a.out") + (if (eqv? file 'stdin) + (read-prog (current-input-port)) + (call-with-input-file file read-prog)) + "a.out" target)