-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathstd_process.smash
More file actions
97 lines (81 loc) 路 2.32 KB
/
Copy pathstd_process.smash
File metadata and controls
97 lines (81 loc) 路 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// std_process.smash - Process-related functionality for SmashLang
// This extends the std module with process-like functionality
// System environment variables
export const env = {
// Core environment variables that should be available
HOME: __native_get_env("HOME"),
USER: __native_get_env("USER"),
PATH: __native_get_env("PATH"),
TEMP: __native_get_env("TEMP") || __native_get_env("TMP"),
SHELL: __native_get_env("SHELL"),
LANG: __native_get_env("LANG"),
// Helper method to get any environment variable
get: function(name) {
return __native_get_env(name);
},
// Helper method to set an environment variable
set: function(name, value) {
return __native_set_env(name, value);
}
};
// Command line arguments
// This will be populated by the runtime with the actual command line arguments
export const argv = __native_get_argv();
// Current working directory operations
export fn cwd() {
return __native_get_cwd();
}
export fn chdir(directory) {
return __native_set_cwd(directory);
}
// Platform information
export const platform = __native_get_platform(); // 'linux', 'darwin', 'win32', etc.
export const arch = __native_get_arch(); // 'x64', 'arm64', etc.
// Process control
export fn exit(code = 0) {
return __native_exit(code);
}
// Process information
export const pid = __native_get_pid();
export const ppid = __native_get_ppid();
// Memory usage
export fn memoryUsage() {
return __native_memory_usage();
}
// CPU usage
export fn cpuUsage() {
return __native_cpu_usage();
}
// High-resolution time measurement
export fn hrtime() {
return __native_hrtime();
}
// Event handling for process events
const eventHandlers = {
exit: [],
uncaughtException: [],
unhandledRejection: []
};
export fn on(event, handler) {
if (eventHandlers[event]) {
eventHandlers[event].push(handler);
}
return this; // For chaining
}
export fn removeListener(event, handler) {
if (eventHandlers[event]) {
const index = eventHandlers[event].indexOf(handler);
if (index !== -1) {
eventHandlers[event].splice(index, 1);
}
}
return this; // For chaining
}
// These functions would be called by the runtime when events occur
export fn __triggerEvent(event, ...args) {
if (eventHandlers[event]) {
for (const handler of eventHandlers[event]) {
handler(...args);
}
}
}