Idris2/libs/base/System/Info.idr

36 lines
924 B
Idris
Raw Normal View History

||| Miscellaneous functions for getting information about the system.
2020-05-18 15:59:07 +03:00
module System.Info
%default total
2020-05-18 15:59:07 +03:00
%extern prim__os : String
%extern prim__codegen : String
||| The current operating system.
2020-05-18 15:59:07 +03:00
export
os : String
os = prim__os
||| The codegen/backend used.
2020-05-18 15:59:07 +03:00
export
codegen : String
codegen = prim__codegen
2020-05-26 12:59:14 +03:00
||| Whether we are running on MS Windows, either directly or with a compability
||| layer (e.g. cygwin).
2020-05-26 12:59:14 +03:00
export
isWindows : Bool
2020-05-26 21:56:16 +03:00
isWindows = os `elem` ["windows", "mingw32", "cygwin32"]
2021-04-23 13:09:31 +03:00
%foreign "C:idris2_getNProcessors, libidris2_support, idris_support.h"
2022-04-07 12:09:30 +03:00
"node:lambda:() => require('os').cpus().length"
prim__getNProcessors : PrimIO Int
||| Get the number of processors on the system. Returns `Nothing` if we somehow
||| got 0 processors.
export
getNProcessors : IO (Maybe Nat)
getNProcessors = do
i <- fromPrim prim__getNProcessors
pure (if i < 0 then Nothing else Just (integerToNat (cast i)))