| 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 | const int BACKSLASH_CH = 92;
|
| 25 |
|
| 26 | Tuple2<int, int> WaitPid(int waitpid_options);
|
| 27 | Tuple2<int, int> Read(int fd, int n, List<BigStr*>* chunks);
|
| 28 | Tuple2<int, int> ReadByte(int fd);
|
| 29 | BigStr* ReadLineBuffered();
|
| 30 | Dict<BigStr*, BigStr*>* Environ();
|
| 31 | int Chdir(BigStr* dest_dir);
|
| 32 | BigStr* GetMyHomeDir();
|
| 33 | BigStr* GetHomeDir(BigStr* user_name);
|
| 34 |
|
| 35 | class ReadError {
|
| 36 | public:
|
| 37 | explicit ReadError(int err_num_) : err_num(err_num_) {
|
| 38 | }
|
| 39 |
|
| 40 | static constexpr ObjHeader obj_header() {
|
| 41 | return ObjHeader::ClassFixed(kZeroMask, sizeof(ReadError));
|
| 42 | }
|
| 43 |
|
| 44 | int err_num;
|
| 45 | };
|
| 46 |
|
| 47 | class PasswdEntry {
|
| 48 | public:
|
| 49 | explicit PasswdEntry(const passwd* entry)
|
| 50 | : pw_name(StrFromC(entry->pw_name)),
|
| 51 | pw_uid(entry->pw_uid),
|
| 52 | pw_gid(entry->pw_gid) {
|
| 53 | }
|
| 54 |
|
| 55 | static constexpr ObjHeader obj_header() {
|
| 56 | return ObjHeader::ClassFixed(field_mask(), sizeof(PasswdEntry));
|
| 57 | }
|
| 58 |
|
| 59 | BigStr* pw_name;
|
| 60 | int pw_uid;
|
| 61 | int pw_gid;
|
| 62 |
|
| 63 | static constexpr uint32_t field_mask() {
|
| 64 | return maskbit(offsetof(PasswdEntry, pw_name));
|
| 65 | }
|
| 66 | };
|
| 67 |
|
| 68 | List<PasswdEntry*>* GetAllUsers();
|
| 69 |
|
| 70 | BigStr* GetUserName(int uid);
|
| 71 |
|
| 72 | BigStr* OsType();
|
| 73 |
|
| 74 | Tuple2<mops::BigInt, mops::BigInt> GetRLimit(int resource);
|
| 75 |
|
| 76 | void SetRLimit(int resource, mops::BigInt soft, mops::BigInt hard);
|
| 77 |
|
| 78 | Tuple3<double, double, double> Time();
|
| 79 |
|
| 80 | void PrintTimes();
|
| 81 |
|
| 82 | bool InputAvailable(int fd);
|
| 83 |
|
| 84 | List<int>* WaitForReading(List<int>* fd_list);
|
| 85 |
|
| 86 | IOError_OSError* FlushStdout();
|
| 87 |
|
| 88 | Tuple2<int, void*> PushTermAttrs(int fd, int mask);
|
| 89 | void PopTermAttrs(int fd, int orig_local_modes, void* term_attrs);
|
| 90 |
|
| 91 | Tuple2<BigStr*, int>* MakeDirCacheKey(BigStr* path);
|
| 92 |
|
| 93 | bool IsSameFile(BigStr* path1, BigStr* path2);
|
| 94 |
|
| 95 | int Unlink(BigStr* path);
|
| 96 |
|
| 97 | } // namespace pyos
|
| 98 |
|
| 99 | namespace pyutil {
|
| 100 |
|
| 101 | double infinity();
|
| 102 | double nan();
|
| 103 |
|
| 104 | bool IsValidCharEscape(BigStr* c);
|
| 105 | BigStr* ChArrayToString(List<int>* ch_array);
|
| 106 |
|
| 107 | class _ResourceLoader {
|
| 108 | public:
|
| 109 | _ResourceLoader() {
|
| 110 | }
|
| 111 |
|
| 112 | virtual BigStr* Get(BigStr* path);
|
| 113 |
|
| 114 | static constexpr ObjHeader obj_header() {
|
| 115 | return ObjHeader::ClassFixed(kZeroMask, sizeof(_ResourceLoader));
|
| 116 | }
|
| 117 | };
|
| 118 |
|
| 119 | _ResourceLoader* GetResourceLoader();
|
| 120 |
|
| 121 | BigStr* GetVersion(_ResourceLoader* loader);
|
| 122 |
|
| 123 | void PrintVersionDetails(_ResourceLoader* loader);
|
| 124 |
|
| 125 | BigStr* strerror(IOError_OSError* e);
|
| 126 |
|
| 127 | BigStr* BackslashEscape(BigStr* s, BigStr* meta_chars);
|
| 128 |
|
| 129 | grammar::Grammar* LoadYshGrammar(_ResourceLoader*);
|
| 130 |
|
| 131 | } // namespace pyutil
|
| 132 |
|
| 133 | #endif // CORE_H
|