X-Git-Url: http://git.lukelau.me/?p=scheme.git;a=blobdiff_plain;f=main.scm;h=e6ac821f2e7407604a72c622dca82aeb79e56d5b;hp=289840b38db3ee0fb75d91bd42bab6297f40f977;hb=HEAD;hpb=da18430cebcb7b813c9b29841f78d65580c91684 diff --git a/main.scm b/main.scm old mode 100644 new mode 100755 index 289840b..e6ac821 --- a/main.scm +++ b/main.scm @@ -1,6 +1,44 @@ +#!/usr/bin/scheme --script + (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))) + + ; reads in all datums until eof +(define (read-prog port) + (let ([x (read port)]) + (if (eof-object? x) + '() + (cons x (read-prog port))))) (compile-to-binary - (if (> (length (command-line)) 1) - (call-with-input-file (cadr (command-line)) read) - (read))) + (if (eqv? file 'stdin) + (read-prog (current-input-port)) + (call-with-input-file file read-prog)) + "a.out" target)