Skip to content

Commit

Permalink
Add warning for nasm version; avoid some tests if too old.
Browse files Browse the repository at this point in the history
  • Loading branch information
dvanhorn committed Dec 12, 2024
1 parent e54fb32 commit 8cf6809
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 deletions.
33 changes: 28 additions & 5 deletions a86/check-nasm.rkt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 "")))))
(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.")))
14 changes: 6 additions & 8 deletions a86/test/expressions.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -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))

0 comments on commit 8cf6809

Please sign in to comment.