diff --git a/a86/check-nasm.rkt b/a86/check-nasm.rkt index aec72cc..40e0271 100644 --- a/a86/check-nasm.rkt +++ b/a86/check-nasm.rkt @@ -1,5 +1,5 @@ #lang racket -(provide check-nasm-available) +(provide check-nasm-available nasm-version nasm-version-2.15+?) (require racket/gui/dynamic) (define nasm-msg @@ -30,10 +30,33 @@ HERE (define (drracket?) (gui-available?)) +;; -> [Maybe String] +(define (nasm-version-string) + (parameterize ([current-output-port (open-output-string)] + [current-error-port (open-output-string)]) + (and (system "nasm -v") + (get-output-string (current-output-port))))) + +(define (nasm-version-2.15+?) + (match (nasm-version) + [(list maj min) (and (>= maj 2) (>= min 15))] + [_ #f])) + +;; -> [Maybe (list Natural Natural)] +(define (nasm-version) + (match (nasm-version-string) + [#f #f] + [(regexp #rx"([0-9]+)\\.([0-9]+)" + (list _ (app string->number maj) (app string->number min))) + (list maj min)])) + +;; -> Void +;; Errors if nasm is not available, warns if available but below 2.15 (define (check-nasm-available) - (unless (parameterize ([current-output-port (open-output-string)] - [current-error-port (open-output-string)]) - (system "nasm -v")) + (define v (nasm-version)) + (unless v (error (format nasm-msg (getenv "PATH") - (if (and (drracket?) (macos?) (launched-with-finder?)) macosx-msg ""))))) \ No newline at end of file + (if (and (drracket?) (macos?) (launched-with-finder?)) macosx-msg "")))) + (unless (nasm-version-2.15+?) + (eprintf "nasm 2.15 or later is recommended; some faatures may not work as expected."))) diff --git a/a86/test/expressions.rkt b/a86/test/expressions.rkt index c443f3e..d988543 100644 --- a/a86/test/expressions.rkt +++ b/a86/test/expressions.rkt @@ -6,14 +6,12 @@ (check-equal? (ev '(<< 1 4)) (arithmetic-shift 1 4)) (check-equal? (ev '(<< 1 (+ 2 2))) (arithmetic-shift 1 (+ 2 2))) -(check-equal? (ev '(< 1 2)) 1) -(check-equal? (ev '(< 2 1)) 0) (check-equal? (ev '(! 0)) 1) (check-equal? (ev '(~ 0)) -1) -(check-equal? (ev '(? 1 2 3)) 2) -(check-equal? (ev '(? 0 2 3)) 3) -(check-equal? (ev '(? 8 2 3)) 2) -(check-equal? (ev (exp (? 8 2 3))) 2) -(check-equal? (let ((x 8)) (ev (exp (? x 2 3)))) 2) -(check-equal? (let ((x 0)) (ev (exp (? x 2 3)))) 3) +(when (nasm-version-2.15+?) + (check-equal? (ev '(< 1 2)) 1) + (check-equal? (ev '(< 2 1)) 0) + (check-equal? (ev '(? 1 2 3)) 2) + (check-equal? (ev '(? 0 2 3)) 3) + (check-equal? (ev '(? 8 2 3)) 2))