Debian Codegraph @

src/core/Sys.nml

raw
1 /*
2 * Copyright (C)2005-2022 Haxe Foundation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
21 */
22
23 neko("
24 @sys_exit = $loader.loadprim('std@sys_exit',1);
25 @get_env = $loader.loadprim('std@get_env',1);
26 @get_cwd = $loader.loadprim('std@get_cwd',0);
27 @exe_path = $loader.loadprim('std@sys_exe_path',0);
28 @sys_file_type = $loader.loadprim('std@sys_file_type',1);
29 @sys_read_dir = $loader.loadprim('std@sys_read_dir',1);
30 ");
31
32 type version {
33 maj : int;
34 min : int;
35 build : int;
36 }
37
38 function without_extension(s) {
39 match List.rev (String.split s ".") {
40 | [] -> ""
41 | [x] -> x
42 | ext :: l -> String.concat "." (List.rev l)
43 }
44 }
45
46 function extension(s) {
47 match List.rev (String.split s ".") {
48 | [] | [_] -> ""
49 | ext :: _ -> ext
50 }
51 }
52
53 function without_dir(s) {
54 var s = String.concat "/" (String.split s "\\");
55 match List.rev (String.split s "/") {
56 | [] -> assert()
57 | file :: _ -> file
58 }
59 }
60
61 var array_dependency = Array.make
62
63 function args() : string array {
64 neko("
65 @Array.@make($loader.args)
66 ");
67 }
68
69 function exit(code : int) : 'a {
70 neko("
71 @sys_exit(code);
72 ");
73 }
74
75 var exists : string -> bool = neko "$loader.loadprim('std@sys_exists',1)"
76
77 var version = {
78 var v : int = neko "$version()";
79 {
80 maj = v / 100;
81 min = (v / 10) % 10;
82 build = v % 10;
83 }
84 }
85
86 function get_env( s : string ) : string option {
87 var s = neko "@get_env(s)";
88 if s == neko "null" then None else Some s;
89 }
90
91 var put_env : string -> string -> void = neko "$loader.loadprim('std@put_env',2)"
92
93 function get_cwd() : string {
94 neko "@get_cwd()"
95 }
96
97 var set_cwd : string -> void = neko "$loader.loadprim('std@set_cwd',1)"
98
99 function executable_path() : string {
100 neko "@exe_path()"
101 }
102
103 function is_directory(str:string) : bool {
104 neko "@sys_file_type(str) == 'dir'";
105 }
106
107 function read_directory(str:string) : string list {
108 neko "@List.@make(@sys_read_dir(str))"
109 }