char/avril

(wip) why'd you have to go and make things so complicaaaaated?

git clone https://git.t4t.associates/char/avril

Charlotte Somgenerate std typedefs from typescript impl38d7f6c

main
1.4 KiB64 linesraw
1import { ObjectFreeze } from "ext:core/primordials";
2import { onRuntimeStart } from "ext:core/bootstrap";
3import {
4  op_process_cwd,
5  op_runtime_info,
6  op_sys_hostname,
7  op_sys_loadavg,
8  op_sys_os_release,
9  op_sys_uptime,
10} from "ext:core/ops";
11import { result } from "ext:file/errors.js";
12
13// Live initialization runs before guest modules, including after snapshot restore.
14export const process: {
15  pid: number;
16  args: readonly string[];
17  cwd(): string;
18  hostname(): string;
19  osRelease(): string;
20  uptime(): number;
21  loadavg(): [number, number, number];
22} = {
23  pid: undefined!,
24  args: undefined!,
25  cwd() {
26    return result(op_process_cwd());
27  },
28  hostname() {
29    return result(op_sys_hostname());
30  },
31  osRelease() {
32    return result(op_sys_os_release());
33  },
34  uptime() {
35    return result(op_sys_uptime());
36  },
37  loadavg() {
38    return result(op_sys_loadavg());
39  },
40};
41
42export const runtime: {
43  os: "linux" | "macos" | "windows";
44  arch: "x86_64" | "aarch64";
45  version: string;
46  v8: string;
47} = {
48  os: undefined!,
49  arch: undefined!,
50  version: undefined!,
51  v8: undefined!,
52};
53
54onRuntimeStart(() => {
55  const info = op_runtime_info();
56  process.pid = info[0];
57  process.args = ObjectFreeze(info[5]);
58  runtime.os = info[1];
59  runtime.arch = info[2];
60  runtime.version = info[3];
61  runtime.v8 = info[4];
62  ObjectFreeze(process);
63  ObjectFreeze(runtime);
64});