2

How can a Chez Scheme program or library find out which operating system and machine architecture it's running on (from within Scheme code)?

Lassi
  • 3,522
  • 3
  • 22
  • 34

1 Answers1

2

From the Chez Scheme Version 9 User's Guide:

Section 6.10. Bytevectors

(native-endianness)             import (rnrs) or (rnrs bytevectors)

Section 12.4. Compilation, Evaluation, and Loading

(machine-type)                  import (chezscheme)

Section 12.15. Environmental Queries and Settings

(scheme-version)                import (chezscheme)
(scheme-version-number)         import (chezscheme)
(petite?)                       import (chezscheme)
(threaded?)                     import (chezscheme)
(interactive?)                  import (chezscheme)

Unfortunately (machine-type) is a cryptic string idiomatic to Chez (instead of a standard symbol like x86-64) and may change from version to version. The other procedures work in the obvious manner.

I found these in the r7rs-benchmarks repo.

Parsing the machine type

The machine type string is constructed as follows:

  1. Start with an empty string.
  2. For a build that supports threads, append the letter t.
  3. Append the machine architecture.
  4. Append the operating system.

Current architectures and operating systems:

(define arch-pairs
  '(("a6"    . amd64)
    ("arm32" . arm32)
    ("i3"    . i386)
    ("ppc32" . ppc32)))

(define os-pairs
  '(("fb"  . freebsd)
    ("le"  . linux)
    ("nb"  . netbsd)
    ("nt"  . windows)
    ("ob"  . openbsd)
    ("osx" . macos)
    ("qnx" . qnx)
    ("s2"  . solaris)))

To find all the machine types, look for all the makefiles named Mf-* in the c directory of the Chez Scheme source repo.

Lassi
  • 3,522
  • 3
  • 22
  • 34