| author | desharna | 
| Mon, 25 Mar 2024 19:27:53 +0100 | |
| changeset 79997 | d8320c3a43ec | 
| parent 77692 | 3e746e684f4b | 
| permissions | -rw-r--r-- | 
| 
62508
 
d0b68218ea55
discontinued RAW session: bootstrap directly from isabelle_process RAW_ML_SYSTEM;
 
wenzelm 
parents: 
62468 
diff
changeset
 | 
1  | 
(* Title: Pure/ML/ml_system.ML  | 
| 43948 | 2  | 
Author: Makarius  | 
3  | 
||
| 48416 | 4  | 
ML system and platform operations.  | 
| 43948 | 5  | 
*)  | 
6  | 
||
7  | 
signature ML_SYSTEM =  | 
|
8  | 
sig  | 
|
9  | 
val name: string  | 
|
10  | 
val platform: string  | 
|
| 73586 | 11  | 
val platform_is_linux: bool  | 
12  | 
val platform_is_macos: bool  | 
|
| 
60962
 
faa452d8e265
basic setup for native Windows (RAW session without image);
 
wenzelm 
parents: 
48416 
diff
changeset
 | 
13  | 
val platform_is_windows: bool  | 
| 73586 | 14  | 
val platform_is_unix: bool  | 
| 77692 | 15  | 
val platform_is_arm: bool  | 
| 69701 | 16  | 
val platform_is_64: bool  | 
| 77692 | 17  | 
val platform_obj_size: int  | 
| 62468 | 18  | 
val platform_path: string -> string  | 
19  | 
val standard_path: string -> string  | 
|
| 43948 | 20  | 
end;  | 
21  | 
||
22  | 
structure ML_System: ML_SYSTEM =  | 
|
23  | 
struct  | 
|
24  | 
||
25  | 
val SOME name = OS.Process.getEnv "ML_SYSTEM";  | 
|
26  | 
val SOME platform = OS.Process.getEnv "ML_PLATFORM";  | 
|
| 73586 | 27  | 
|
28  | 
val platform_is_linux = String.isSuffix "linux" platform;  | 
|
29  | 
val platform_is_macos = String.isSuffix "darwin" platform;  | 
|
| 
60962
 
faa452d8e265
basic setup for native Windows (RAW session without image);
 
wenzelm 
parents: 
48416 
diff
changeset
 | 
30  | 
val platform_is_windows = String.isSuffix "windows" platform;  | 
| 73586 | 31  | 
val platform_is_unix = platform_is_linux orelse platform_is_macos;  | 
| 77692 | 32  | 
val platform_is_arm = String.isPrefix "arm64_32-" platform orelse String.isPrefix "arm64-" platform;  | 
| 74776 | 33  | 
val platform_is_64 = String.isPrefix "x86_64-" platform orelse String.isPrefix "arm64-" platform;  | 
| 77692 | 34  | 
|
35  | 
val platform_obj_size = if platform_is_64 then 8 else 4;  | 
|
| 43948 | 36  | 
|
| 62468 | 37  | 
val platform_path =  | 
38  | 
if platform_is_windows then  | 
|
39  | 
fn path =>  | 
|
40  | 
if String.isPrefix "/" path andalso not (String.isPrefix "//" path) then  | 
|
41  | 
(case String.tokens (fn c => c = #"/") path of  | 
|
42  | 
"cygdrive" :: drive :: arcs =>  | 
|
43  | 
let  | 
|
44  | 
val vol =  | 
|
45  | 
(case Char.fromString drive of  | 
|
46  | 
NONE => drive ^ ":"  | 
|
47  | 
| SOME d => String.str (Char.toUpper d) ^ ":");  | 
|
48  | 
in String.concatWith "\\" (vol :: arcs) end  | 
|
49  | 
| arcs =>  | 
|
50  | 
(case OS.Process.getEnv "CYGWIN_ROOT" of  | 
|
51  | 
SOME root => OS.Path.concat (root, String.concatWith "\\" arcs)  | 
|
52  | 
| NONE => raise Fail "Unknown environment variable CYGWIN_ROOT"))  | 
|
53  | 
else String.translate (fn #"/" => "\\" | c => String.str c) path  | 
|
54  | 
else fn path => path;  | 
|
55  | 
||
56  | 
val standard_path =  | 
|
57  | 
if platform_is_windows then  | 
|
58  | 
fn path =>  | 
|
59  | 
let  | 
|
60  | 
        val {vol, arcs, isAbs} = OS.Path.fromString path;
 | 
|
61  | 
val path' = String.translate (fn #"\\" => "/" | c => String.str c) path;  | 
|
62  | 
in  | 
|
63  | 
if isAbs then  | 
|
64  | 
(case String.explode vol of  | 
|
65  | 
[d, #":"] =>  | 
|
66  | 
              String.concatWith "/" ("/cygdrive" :: String.str (Char.toLower d) :: arcs)
 | 
|
67  | 
| _ => path')  | 
|
68  | 
else path'  | 
|
69  | 
end  | 
|
70  | 
else fn path => path;  | 
|
71  | 
||
| 43948 | 72  | 
end;  |