mirror of
https://github.com/erg-lang/erg.git
synced 2025-08-04 10:49:54 +00:00
feat: add FileDescriptor
and enhance os
decls
This commit is contained in:
parent
d9e4dbe716
commit
d881a6ae3e
3 changed files with 138 additions and 10 deletions
|
@ -71,6 +71,7 @@ const PROC_READLINE: &str = "readline!";
|
|||
const FUNC_READLINE: &str = "readline";
|
||||
const FUNC_READLINES: &str = "readlines";
|
||||
const PROC_READLINES: &str = "readlines!";
|
||||
const FILE_DESCRIPTOR: &str = "FileDescriptor";
|
||||
const MUTABLE_IO: &str = "IO!";
|
||||
const FUNC_MODE: &str = "mode";
|
||||
const FUNC_NAME: &str = "name";
|
||||
|
|
|
@ -84,10 +84,16 @@ impl Context {
|
|||
Visibility::BUILTIN_PUBLIC,
|
||||
Some(FUNC_READLINES),
|
||||
);
|
||||
/* FileDescriptor */
|
||||
let mut file_descriptor = Self::builtin_mono_trait(FILE_DESCRIPTOR, 2);
|
||||
let Slf = mono_q(SELF, subtypeof(mono(FILE_DESCRIPTOR)));
|
||||
let t = fn0_met(Slf.clone(), Nat).quantify();
|
||||
file_descriptor.register_builtin_erg_decl(FUNC_FILENO, t, Visibility::BUILTIN_PUBLIC);
|
||||
/* IO! */
|
||||
let mut io = Self::builtin_mono_trait(MUTABLE_IO, 2);
|
||||
let Slf = mono(MUTABLE_IO);
|
||||
io.register_superclass(mono(MUTABLE_READABLE), &readable);
|
||||
io.register_superclass(mono(FILE_DESCRIPTOR), &file_descriptor);
|
||||
io.register_builtin_decl(
|
||||
FUNC_MODE,
|
||||
fn0_met(Slf.clone(), Str),
|
||||
|
@ -112,12 +118,6 @@ impl Context {
|
|||
Visibility::BUILTIN_PUBLIC,
|
||||
Some(FUNC_CLOSED),
|
||||
);
|
||||
io.register_builtin_decl(
|
||||
FUNC_FILENO,
|
||||
fn0_met(Slf.clone(), Nat),
|
||||
Visibility::BUILTIN_PUBLIC,
|
||||
Some(FUNC_FILENO),
|
||||
);
|
||||
io.register_builtin_decl(
|
||||
PROC_FLUSH,
|
||||
pr0_met(ref_mut(Slf.clone(), None), NoneType),
|
||||
|
@ -502,6 +502,13 @@ impl Context {
|
|||
Const,
|
||||
None,
|
||||
);
|
||||
self.register_builtin_type(
|
||||
mono(FILE_DESCRIPTOR),
|
||||
file_descriptor,
|
||||
Visibility::BUILTIN_PRIVATE,
|
||||
Const,
|
||||
None,
|
||||
);
|
||||
self.register_builtin_type(
|
||||
mono(MUTABLE_IO),
|
||||
io,
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
.path = pyimport "path"
|
||||
# .PathLike: ClassType
|
||||
|
||||
.OSError = OSError
|
||||
.PathLike = PathLike
|
||||
|
||||
.DirEntry: ClassType
|
||||
.DirEntry.
|
||||
name: Str
|
||||
|
@ -10,7 +13,24 @@
|
|||
is_file: (self: .DirEntry) -> Bool
|
||||
is_symlink: (self: .DirEntry) -> Bool
|
||||
|
||||
.ctermid!: () => Str
|
||||
.StatResult = 'stat_result': ClassType
|
||||
.StatResult.
|
||||
st_mode: Nat
|
||||
st_ino: Nat
|
||||
st_dev: Nat
|
||||
st_nlink: Nat
|
||||
st_uid: Nat
|
||||
st_gid: Nat
|
||||
st_size: Nat
|
||||
st_atime: Float
|
||||
st_mtime: Float
|
||||
st_ctime: Float
|
||||
st_atime_ns: Nat
|
||||
st_mtime_ns: Nat
|
||||
st_ctime_ns: Nat
|
||||
st_birthtime: Float
|
||||
st_birthtime_ns: Nat
|
||||
|
||||
# TODO: _Environ
|
||||
.environ: {Str: Str}
|
||||
.environb: {Bytes: Bytes}
|
||||
|
@ -19,9 +39,86 @@ The name of the operating system dependent module imported. The following names
|
|||
'posix', 'nt', 'java'.
|
||||
'''
|
||||
.name: Str
|
||||
.supports_bytes_environ: Bool
|
||||
|
||||
.F_LOCK: Nat
|
||||
.F_TLOCK: Nat
|
||||
.F_ULOCK: Nat
|
||||
.F_TEST: Nat
|
||||
|
||||
.O_RDONLY: Nat
|
||||
.O_WRONLY: Nat
|
||||
.O_RDWR: Nat
|
||||
.O_APPEND: Nat
|
||||
.O_CREAT: Nat
|
||||
.O_EXCL: Nat
|
||||
.O_TRUNC: Nat
|
||||
.O_DSYNC: Nat
|
||||
.O_RSYNC: Nat
|
||||
.O_SYNC: Nat
|
||||
.O_NDELAY: Nat
|
||||
.O_NONBLOCK: Nat
|
||||
.O_NOCTTY: Nat
|
||||
.O_CLOEXEC: Nat
|
||||
.O_BINARY: Nat
|
||||
.O_NOINHERIT: Nat
|
||||
.O_SHORT_LIVED: Nat
|
||||
.O_TEMPORARY: Nat
|
||||
.O_RANDOM: Nat
|
||||
.O_SEQUENTIAL: Nat
|
||||
.O_TEXT: Nat
|
||||
.O_EVTONLY: Nat
|
||||
.O_FSYNC: Nat
|
||||
.O_SYMLINK: Nat
|
||||
.O_NOFOLLOW_ANY: Nat
|
||||
.O_ASYNC: Nat
|
||||
.O_DIRECT: Nat
|
||||
.O_DIRECTORY: Nat
|
||||
.O_NOFOLLOW: Nat
|
||||
.O_NOATIME: Nat
|
||||
.O_PATH: Nat
|
||||
.O_TMPFILE: Nat
|
||||
.O_SHLOCK: Nat
|
||||
.O_EXLOCK: Nat
|
||||
|
||||
.PRIO_PGRP: Nat
|
||||
.PRIO_PROCESS: Nat
|
||||
.PRIO_USER: Nat
|
||||
.PRIO_DARWIN_THREAD: Nat
|
||||
.PRIO_DARWIN_PROCESS: Nat
|
||||
.PRIO_DARWIN_BG: Nat
|
||||
.PRIO_DARWIN_NONUI: Nat
|
||||
|
||||
.SEEK_SET: Nat
|
||||
.SEEK_CUR: Nat
|
||||
.SEEK_END: Nat
|
||||
.SEEK_HOLE: Nat
|
||||
.SEEK_DATA: Nat
|
||||
|
||||
.close!: (fd: Nat or FileDescriptor) => NoneType
|
||||
.closerange!: (fd_low: Nat, fd_high: Nat) => NoneType
|
||||
.ctermid!: () => Str
|
||||
.chdir!: (path: PathLike, ) => NoneType
|
||||
.chmod!: (path: PathLike, mode: Nat) => NoneType
|
||||
.copy_file_range!: (src: Nat or FileDescriptor, dst: Nat or FileDescriptor, count: Nat, offset_src := Nat, offset_dst := Nat) => Nat
|
||||
.device_encoding: (fd: Nat or FileDescriptor) -> Str or NoneType
|
||||
.dup!: (fd: Nat or FileDescriptor) => Nat
|
||||
.dup2!: (fd: Nat or FileDescriptor, fd2: Nat, inheritable := Bool) => Nat
|
||||
.fchdir!: (fd: Nat or FileDescriptor) => NoneType
|
||||
.fchmod!: (fd: Nat or FileDescriptor, mode: Nat) => NoneType
|
||||
.fchown!: (fd: Nat or FileDescriptor, uid: Nat, gid: Nat) => NoneType
|
||||
.fdatasync!: (fd: Nat or FileDescriptor) => NoneType
|
||||
.fdopen!: (fd: Nat or FileDescriptor, *args: Obj, **kwargs: Obj) => File!
|
||||
.fpathconf!: (fd: Nat or FileDescriptor, name: Nat) => Nat
|
||||
.fsdecode: (filename: Bytes) -> Str
|
||||
.fsencode: (filename: Str) -> Bytes
|
||||
.fspath: (path: PathLike) -> Str
|
||||
.fstat!: (fd: Nat or FileDescriptor) => .StatResult
|
||||
.fstatvfs!: (fd: Nat or FileDescriptor) => .StatResult
|
||||
.fsync!: (fd: Nat or FileDescriptor) => NoneType
|
||||
.ftruncate!: (fd: Nat or FileDescriptor, length: Nat) => NoneType
|
||||
.get_blocking!: (fd: Nat or FileDescriptor) => Bool
|
||||
.get_exec_path!: (env := {Str: Str}) => [Str; _]
|
||||
.getcwd!: () => Str
|
||||
.getcwdb!: () => Bytes
|
||||
.getegid!: () => Nat
|
||||
|
@ -29,19 +126,30 @@ The name of the operating system dependent module imported. The following names
|
|||
.getenvb!: |D <: Bytes or NoneType|(key: Bytes, default: D := NoneType) => Bytes or D
|
||||
.geteuid!: () => Nat
|
||||
.getgid!: () => Nat
|
||||
.getgrouplist!: (user: Str, group: Nat) => [Nat; _]
|
||||
.getgroups!: () => [Nat; _]
|
||||
.getlogin!: () => Str
|
||||
.getpgid!: (pid: Nat) => Nat
|
||||
.getpgrp!: () => Nat
|
||||
.getpid!: () => Nat
|
||||
.getppid!: () => Nat
|
||||
.getpriority!: (which: Nat, who: Nat) => Nat
|
||||
.getresgid!: () => (Nat, Nat, Nat)
|
||||
.getresuid!: () => (Nat, Nat, Nat)
|
||||
.getsid!: (pid: Nat) => Nat
|
||||
.getuid!: () => Nat
|
||||
# TODO:
|
||||
.isatty!: (fd: Obj) => Bool
|
||||
.initgroups!: (username: Str, gid: Nat) => NoneType
|
||||
.isatty!: (fd: Nat or FileDescriptor) => Bool
|
||||
.listdir!: (path := PathLike,) => [Str; _]
|
||||
.lockf!: (fd: Nat or FileDescriptor, cmd: Nat, len := Nat) => NoneType
|
||||
.login_tty!: (fd: Nat or FileDescriptor) => NoneType
|
||||
.lseek!: (fd: Nat or FileDescriptor, pos: Nat, whence: Nat) => Nat
|
||||
.mkdir!: (path: PathLike, mode := Nat) => NoneType
|
||||
.makedirs!: (path: PathLike, mode := Nat, exist_ok := Bool) => NoneType
|
||||
.open!: (path: PathLike, flags: Nat, mode := Nat, dir_fd := Nat or FileDescriptor) => Nat
|
||||
.openpty!: () => (Nat, Nat)
|
||||
.pipe!: () => (Nat, Nat)
|
||||
.pipe2!: (flags: Nat) => (Nat, Nat)
|
||||
.putenv!: (key: Str, value: Str) => NoneType
|
||||
.remove!: (path: PathLike,) => NoneType
|
||||
.removedirs!: (path: PathLike,) => NoneType
|
||||
|
@ -54,18 +162,30 @@ The name of the operating system dependent module imported. The following names
|
|||
.seteuid!: (euid: Nat) => NoneType
|
||||
.setgid!: (gid: Nat) => NoneType
|
||||
.setgroups!: (groups: Sequence(Nat)) => NoneType
|
||||
.setns!: (fd: Nat or FileDescriptor, nstype := Nat) => NoneType
|
||||
.setpgrp!: () => NoneType
|
||||
.setpgid!: (pid: Nat, pgid: Nat) => NoneType
|
||||
.setpriority!: (which: Nat, who: Nat, priority: Nat) => NoneType
|
||||
.setregid!: (rgid: Nat, egid: Nat) => NoneType
|
||||
.setresgid!: (rgid: Nat, egid: Nat, sgid: Nat) => NoneType
|
||||
.setresuid!: (ruid: Nat, euid: Nat, suid: Nat) => NoneType
|
||||
.setreuid!: (ruid: Nat, euid: Nat) => NoneType
|
||||
.setsid!: () => Nat
|
||||
.setuid!: (uid: Nat) => NoneType
|
||||
.strerror: (code: Nat) -> Str
|
||||
|
||||
.umask!: (mask: Nat) => Nat
|
||||
# posix = pyimport "posix"
|
||||
# .uname!: () => posix.UnameResult
|
||||
.uname!: () => {
|
||||
.uname!: () => NamedTuple {
|
||||
sysname = Str;
|
||||
nodename = Str;
|
||||
release = Str;
|
||||
version = Str;
|
||||
machine = Str;
|
||||
}
|
||||
.unsetenv!: (key: Str) => NoneType
|
||||
.unshare!: (flags: Nat) => NoneType
|
||||
|
||||
.getrandom!: (size: Nat) => Bytes
|
||||
.urandom!: (size: Nat) => Bytes
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue