Line | Count | Source |
1 | | // core.h: Replacement for core/*.py |
2 | | |
3 | | #ifndef CORE_H |
4 | | #define CORE_H |
5 | | |
6 | | #include <pwd.h> // passwd |
7 | | #include <termios.h> |
8 | | |
9 | | #include "_gen/frontend/syntax.asdl.h" |
10 | | #include "cpp/pgen2.h" |
11 | | #include "mycpp/runtime.h" |
12 | | |
13 | | // Hacky forward declaration |
14 | | namespace completion { |
15 | | class RootCompleter; |
16 | | }; |
17 | | |
18 | | namespace pyos { |
19 | | |
20 | | const int TERM_ICANON = ICANON; |
21 | | const int TERM_ECHO = ECHO; |
22 | | const int EOF_SENTINEL = 256; |
23 | | const int NEWLINE_CH = 10; |
24 | | |
25 | | Tuple2<int, int> WaitPid(int waitpid_options); |
26 | | Tuple2<int, int> Read(int fd, int n, List<BigStr*>* chunks); |
27 | | Tuple2<int, int> ReadByte(int fd); |
28 | | BigStr* ReadLineBuffered(); |
29 | | Dict<BigStr*, BigStr*>* Environ(); |
30 | | int Chdir(BigStr* dest_dir); |
31 | | BigStr* GetMyHomeDir(); |
32 | | BigStr* GetHomeDir(BigStr* user_name); |
33 | | |
34 | | class ReadError { |
35 | | public: |
36 | 1 | explicit ReadError(int err_num_) : err_num(err_num_) { |
37 | 1 | } |
38 | | |
39 | 1 | static constexpr ObjHeader obj_header() { |
40 | 1 | return ObjHeader::ClassFixed(kZeroMask, sizeof(ReadError)); |
41 | 1 | } |
42 | | |
43 | | int err_num; |
44 | | }; |
45 | | |
46 | | class PasswdEntry { |
47 | | public: |
48 | | explicit PasswdEntry(const passwd* entry) |
49 | | : pw_name(StrFromC(entry->pw_name)), |
50 | | pw_uid(entry->pw_uid), |
51 | 20 | pw_gid(entry->pw_gid) { |
52 | 20 | } |
53 | | |
54 | 20 | static constexpr ObjHeader obj_header() { |
55 | 20 | return ObjHeader::ClassFixed(field_mask(), sizeof(PasswdEntry)); |
56 | 20 | } |
57 | | |
58 | | BigStr* pw_name; |
59 | | int pw_uid; |
60 | | int pw_gid; |
61 | | |
62 | 20 | static constexpr uint32_t field_mask() { |
63 | 20 | return maskbit(offsetof(PasswdEntry, pw_name)); |
64 | 20 | } |
65 | | }; |
66 | | |
67 | | List<PasswdEntry*>* GetAllUsers(); |
68 | | |
69 | | BigStr* GetUserName(int uid); |
70 | | |
71 | | BigStr* OsType(); |
72 | | |
73 | | Tuple2<mops::BigInt, mops::BigInt> GetRLimit(int resource); |
74 | | |
75 | | void SetRLimit(int resource, mops::BigInt soft, mops::BigInt hard); |
76 | | |
77 | | Tuple3<double, double, double> Time(); |
78 | | |
79 | | void PrintTimes(); |
80 | | |
81 | | bool InputAvailable(int fd); |
82 | | |
83 | | List<int>* WaitForReading(List<int>* fd_list); |
84 | | |
85 | | IOError_OSError* FlushStdout(); |
86 | | |
87 | | Tuple2<int, void*> PushTermAttrs(int fd, int mask); |
88 | | void PopTermAttrs(int fd, int orig_local_modes, void* term_attrs); |
89 | | |
90 | | Tuple2<BigStr*, int>* MakeDirCacheKey(BigStr* path); |
91 | | |
92 | | } // namespace pyos |
93 | | |
94 | | namespace pyutil { |
95 | | |
96 | | double infinity(); |
97 | | double nan(); |
98 | | |
99 | | bool IsValidCharEscape(BigStr* c); |
100 | | BigStr* ChArrayToString(List<int>* ch_array); |
101 | | |
102 | | class _ResourceLoader { |
103 | | public: |
104 | 1 | _ResourceLoader() { |
105 | 1 | } |
106 | | |
107 | | virtual BigStr* Get(BigStr* path); |
108 | | |
109 | 1 | static constexpr ObjHeader obj_header() { |
110 | 1 | return ObjHeader::ClassFixed(kZeroMask, sizeof(_ResourceLoader)); |
111 | 1 | } |
112 | | }; |
113 | | |
114 | | _ResourceLoader* GetResourceLoader(); |
115 | | |
116 | | BigStr* GetVersion(_ResourceLoader* loader); |
117 | | |
118 | | void PrintVersionDetails(_ResourceLoader* loader); |
119 | | |
120 | | BigStr* strerror(IOError_OSError* e); |
121 | | |
122 | | BigStr* BackslashEscape(BigStr* s, BigStr* meta_chars); |
123 | | |
124 | | grammar::Grammar* LoadYshGrammar(_ResourceLoader*); |
125 | | |
126 | | } // namespace pyutil |
127 | | |
128 | | #endif // CORE_H |