(load "codegen.scm")
+(load "platform.scm")
; returns (os filename)
(define (parse-args)
(define (parse-os x)
- (if (null? x) 'darwin ; todo: replace this with the os
+ (if (null? x) host-os ; todo: replace this with the os
; it was compiled with
(if
(or (equal? (car x) "-t")
--- /dev/null
+(define (slurp ip)
+ (with-output-to-string
+ (lambda ()
+ (let f ()
+ (let ([c (read-char ip)])
+ (unless (eof-object? c)
+ (write-char c)
+ (f)))))))
+
+(define (trim s)
+ (if (<= (string-length s) 0)
+ s
+ (if (char-whitespace?
+ (string-ref s (- (string-length s) 1)))
+ (trim (substring s 0 (- (string-length s) 1)))
+ s)))
+
+(define host-os
+ (string->symbol
+ (string-downcase
+ (trim (slurp (car (process "uname")))))))
+
(define (test-prog prog exit-code)
(display prog)
(newline)
- (compile-to-binary prog "/tmp/test-prog" 'darwin)
+ (compile-to-binary prog "/tmp/test-prog" host-os)
(test (system "/tmp/test-prog") exit-code))
(define (test-prog-stdout prog output)
(display prog)
(newline)
- (compile-to-binary prog "/tmp/test-prog" 'darwin)
+ (compile-to-binary prog "/tmp/test-prog" host-os)
(system "/tmp/test-prog > /tmp/test-output.txt")
(let ((str (read-file "/tmp/test-output.txt")))
(test str output)))