## platform-properties.pkg
# Compiled by:
#
src/lib/std/src/standard-core.sublib# Get information about the underlying hardware and OS.
stipulate
package ci = mythryl_callable_c_library_interface; # mythryl_callable_c_library_interface is from
src/lib/std/src/unsafe/mythryl-callable-c-library-interface.pkgherein
package platform_properties
: (weak) Platform_Properties # Platform_Properties is from
src/lib/std/src/nj/platform-properties.api {
exception UNKNOWN;
fun get_info_string NULL => raise exception UNKNOWN;
get_info_string (THE s) => s;
end;
package os {
#
Kind
= POSIX # One of the many flavours of UNIX (incl Mach and NeXTStep)
| WIN32
# Wind32 API (incl. Windows95 and WindowsNT)
| MACOS
# Macintosh OS
| OS2
# IBM's OS/2
| BEOS
# BeOS from Be
;
};
# This function maps string properties to platform-specific string values:
#
# "OS_NAME" -> "Linux"/"BSD"/"Cygwin" /"SunOS"/"Solaris"/"Irix"/"OSF/1"/"AIX"/"Darwin"/"HPUX"
# "OS_VERSION" -> "<unknown>"
#
# "HOST_ARCH" -> "INTEL32"/"PWRPC32"/"SPARC32"/"<unknown>"
# "TARGET_ARCH" -> "INTEL32"/"PWRPC32"/"SPARC32"/"<unknown>"
#
# "HAS_SOFTWARE_GENERATED_PERIODIC_EVENTS" -> "TRUE" / "FALSE"
# "HAS_MP" -> "TRUE" / "FALSE"
#
# Returns: THE string for a valid query;
# NULL for an invalid one.
#
fun get_platform_property (s: String): Null_Or( String ) # Private to this file.
=
ci::find_c_function { lib_name => "heap", fun_name => "get_platform_property" } s; # "get_platform_property" def in src/c/lib/heap/get-platform-property.c
#
###############################################################
# This function is not a true syscall and is very fast, so the
# usual latency-minimization reasons for using find_c_function'
# in place of find_c_function do not apply. -- 2012-04-21 CrT
fun get_boolean flag
=
case (get_info_string (get_platform_property flag))
#
"NO" => FALSE;
_ => TRUE;
esac;
fun get_os_name ()
=
get_info_string (get_platform_property "OS_NAME");
fun get_os_kind ()
=
case (get_os_name ()) # OS name originates ultimately from src/c/h/architecture-and-os-names-system-dependent.h
#
("sunos"
| "solaris" | "irix" | "osf1" | "aix" | "nextstep" |
"ultrix"
| "hpux" | "linux" | "bsd" | "plan9" | "mach" | "darwin" | "cygwin"
) => os::POSIX;
"os2" => os::OS2;
"win32" => os::WIN32;
_ => raise exception DIE "unknown OS";
esac;
fun get_os_version () = get_info_string (get_platform_property "OS_VERSION");
fun get_host_architecture () = get_info_string (get_platform_property "HOST_ARCH");
fun get_target_architecture () = get_info_string (get_platform_property "TARGET_ARCH");
fun has_software_polling () = get_boolean "HAS_SOFTWARE_GENERATED_PERIODIC_EVENTS";
fun has_multiprocessing () = get_boolean "HAS_MP";
};
end;
## COPYRIGHT (c) 1995 AT&T Bell Laboratories.
## Subsequent changes by Jeff Prothero Copyright (c) 2010-2015,
## released per terms of SMLNJ-COPYRIGHT.