Skip to content

Commit

Permalink
feat: enhance os, sys type decls
Browse files Browse the repository at this point in the history
  • Loading branch information
mtshiba committed Apr 14, 2024
1 parent d46f845 commit c7522b1
Show file tree
Hide file tree
Showing 2 changed files with 142 additions and 0 deletions.
110 changes: 110 additions & 0 deletions crates/erg_compiler/lib/pystd/os.d/__init__.d.er
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,51 @@ The name of the operating system dependent module imported. The following names
.supports_fd: Set Subroutine, _
.supports_follow_symlinks: Set Subroutine, _

.EFD_CLOEXEC: Nat
.EFD_NONBLOCK: Nat
.EFD_SEMAPHORE: Nat

.EX_OK: Nat
.EX_USAGE: Nat
.EX_DATAERR: Nat
.EX_NOINPUT: Nat
.EX_NOUSER: Nat
.EX_NOHOST: Nat
.EX_UNAVAILABLE: Nat
.EX_SOFTWARE: Nat
.EX_OSERR: Nat
.EX_OSFILE: Nat
.EX_CANTCREAT: Nat
.EX_IOERR: Nat
.EX_TEMPFAIL: Nat
.EX_PROTOCOL: Nat
.EX_NOPERM: Nat
.EX_CONFIG: Nat
.EX_NOTFOUND: Nat

.F_LOCK: Nat
.F_TLOCK: Nat
.F_ULOCK: Nat
.F_TEST: Nat

.MFD_CLOEXEC: Nat
.MFD_ALLOW_SEALING: Nat
.MFD_HUGETLB: Nat
.MFD_HUGE_SHIFT: Nat
.MFD_HUGE_MASK: Nat
.MFD_HUGE_64KB: Nat
.MFD_HUGE_512KB: Nat
.MFD_HUGE_1MB: Nat
.MFD_HUGE_2MB: Nat
.MFD_HUGE_8MB: Nat
.MFD_HUGE_16MB: Nat
.MFD_HUGE_32MB: Nat
.MFD_HUGE_256MB: Nat
.MFD_HUGE_512MB: Nat
.MFD_HUGE_1GB: Nat
.MFD_HUGE_2GB: Nat
.MFD_HUGE_16GB: Nat

.O_RDONLY: Nat
.O_WRONLY: Nat
.O_RDWR: Nat
Expand Down Expand Up @@ -130,13 +170,20 @@ The name of the operating system dependent module imported. The following names
.SF_NODISKIO: Nat
.SF_SYNC: Nat

.XATTR_CREATE: Nat
.XATTR_REPLACE: Nat
.XATTR_SIZE_MAX: Nat

._exit!: (n: Nat) => NoneType
.abort!: () => NoneType
.access!: (
path: PathLike,
mode: Nat,
dir_fd := Nat or FileDescriptor,
effective_ids := Bool,
follow_symlinks := Bool,
) => Bool
.add_dll_directory!: (path: PathLike) => NoneType
.close!: (fd: Nat or FileDescriptor) => NoneType
.closerange!: (fd_low: Nat, fd_high: Nat) => NoneType
.ctermid!: () => Str
Expand All @@ -155,11 +202,24 @@ The name of the operating system dependent module imported. The following names
.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
.eventfd!: (initval: Nat, flags := Nat) => Nat
.eventfd_read!: (fd: Nat or FileDescriptor) => Nat
.eventfd_write!: (fd: Nat or FileDescriptor, value: Nat) => NoneType
.execl!: (path: PathLike, *args: Obj) => NoneType
.execle!: (path: PathLike, *args: Obj, env := {Str: Str}) => NoneType
.execlp!: (file: Str, *args: Obj) => NoneType
.execlpe!: (file: Str, *args: Obj, env := {Str: Str}) => NoneType
.execv!: (path: PathLike, args: Sequence(Str)) => NoneType
.execve!: (path: PathLike, args: Sequence(Str), env: {Str: Str}) => NoneType
.execvp!: (file: Str, args: Sequence(Str)) => NoneType
.execvpe!: (file: Str, args: Sequence(Str), env: {Str: Str}) => NoneType
.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!
.fork!: () => Nat
.forkpty!: () => (Nat, Nat)
.fpathconf!: (fd: Nat or FileDescriptor, name: Nat) => Nat
.fsdecode: (filename: Bytes) -> Str
.fsencode: (filename: Str) -> Bytes
Expand Down Expand Up @@ -203,8 +263,11 @@ The name of the operating system dependent module imported. The following names
.getresuid!: () => (Nat, Nat, Nat)
.getsid!: (pid: Nat) => Nat
.getuid!: () => Nat
.getxattr!: (path: PathLike, attribute: Str, follow_symlinks := Bool) => Bytes
.initgroups!: (username: Str, gid: Nat) => NoneType
.isatty!: (fd: Nat or FileDescriptor) => Bool
.kill!: (pid: Nat, sig: Nat) => NoneType
.killpg!: (pgrp: Nat, sig: Nat) => NoneType
.lchmod!: (path: PathLike, mode: Nat) => NoneType
.lchown!: (path: PathLike, uid: Nat, gid: Nat) => NoneType
.link!: (
Expand All @@ -218,6 +281,7 @@ The name of the operating system dependent module imported. The following names
.listdrives!: () => [Str; _]
.listmounts!: (volume: PathLike) => [Str; _]
.listvolumes!: () => [Str; _]
.listxattr!: (path: PathLike, follow_symlinks := Bool) => [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
Expand All @@ -227,16 +291,31 @@ The name of the operating system dependent module imported. The following names
.makedirs!: (path: PathLike, mode := Nat, exist_ok := Bool) => NoneType
.makefifo!: (path: PathLike, mode := Nat, dir_fd := Nat or FileDescriptor) => NoneType
.major!: (device: Nat) => Nat
.memfd_create!: (name: Str, flags: Nat) => Nat
.minor!: (device: Nat) => Nat
.mknod!: (path: PathLike, mode: Nat, device := Nat, dir_fd := Nat or FileDescriptor) => NoneType
.nice!: (increment: Nat) => NoneType
.open!: (path: PathLike, flags: Nat, mode := Nat, dir_fd := Nat or FileDescriptor) => Nat
.openpty!: () => (Nat, Nat)
.pathconf!: (path: PathLike, name: Str or Nat) => Nat
.pidfd_open!: (pid: Nat, flags := Nat) => Nat
.pipe!: () => (Nat, Nat)
.pipe2!: (flags: Nat) => (Nat, Nat)
.plock!: (op: Nat) => NoneType
.popen!: (cmd: Str, mode := Str, buffering := Nat or {-1}) => File!
# TODO: only on linux
.posix_fallocate!: (fd: Nat or FileDescriptor, offset: Nat, len: Nat) => NoneType
.posix_fadvise!: (fd: Nat or FileDescriptor, offset: Nat, len: Nat, advice: Nat) => NoneType
.posix_spawn!: (
path: PathLike,
argv: Sequence(Str),
env := {Str: Str},
) => Nat
.posix_spawnp!: (
path: PathLike,
argv: Sequence(Str),
env := {Str: Str},
) => Nat
.pread!: (fd: Nat or FileDescriptor, n: Nat, offset: Nat) => Bytes
.preadv!: (fd: Nat or FileDescriptor, buffers: RefMut(ByteArray!), offset: Nat, flags := Nat) => Nat
.putenv!: (key: Str, value: Str) => NoneType
Expand All @@ -245,8 +324,10 @@ The name of the operating system dependent module imported. The following names
.read!: (fd: Nat or FileDescriptor, n: Nat) => Bytes
.readlink!: (path: PathLike, dir_fd := Nat or FileDescriptor) => Str
.readv!: (fd: Nat or FileDescriptor, buffers: RefMut(ByteArray!)) => Nat
.register_at_fork!: (before := Subroutine, after_in_parent := Subroutine, after_in_child := Subroutine) => NoneType
.remove!: (path: PathLike,) => NoneType
.removedirs!: (path: PathLike,) => NoneType
.removexattr!: (path: PathLike, attribute: Str, follow_symlinks := Bool) => NoneType
.rename!: (src: PathLike, dst: PathLike) => NoneType
.renames!: (old: PathLike, new: PathLike) => NoneType
.replace!: (src: PathLike, dst: PathLike) => NoneType
Expand All @@ -270,7 +351,18 @@ The name of the operating system dependent module imported. The following names
.setreuid!: (ruid: Nat, euid: Nat) => NoneType
.setsid!: () => Nat
.setuid!: (uid: Nat) => NoneType
.setxattr!: (path: PathLike, attribute: PathLike or Bytes, value: PathLike or Bytes, flags := Nat, follow_symlinks := Bool) => NoneType
.spawnl!: (mode: Str, path: PathLike, *args: Obj) => NoneType
.spawnle!: (mode: Str, path: PathLike, *args: Obj, env := {Str: Str}) => NoneType
.spawnlp!: (mode: Str, file: Str, *args: Obj) => NoneType
.spawnlpe!: (mode: Str, file: Str, *args: Obj, env := {Str: Str}) => NoneType
.spawnv!: (mode: Str, path: PathLike, args: Sequence(Str)) => NoneType
.spawnve!: (mode: Str, path: PathLike, args: Sequence(Str), env: {Str: Str}) => NoneType
.spawnvp!: (mode: Str, file: Str, args: Sequence(Str)) => NoneType
.spawnvpe!: (mode: Str, file: Str, args: Sequence(Str), env: {Str: Str}) => NoneType
.splice!: (src: Nat or FileDescriptor, dst: Nat or FileDescriptor, count: Nat, offset_src := Nat, offset_dst := Nat) => NoneType
.startfile!: ((path: PathLike) => NoneType) \
and ((path: Str, operation: Str, arguments: Str, cwd: PathLike, show_cmd: Int) => NoneType)
.statvfs!: (path: PathLike) => NamedTuple {
.f_bsize = Nat;
.f_frsize = Nat;
Expand All @@ -287,8 +379,15 @@ The name of the operating system dependent module imported. The following names
.strerror: (code: Nat) -> Str
.symlink!: (src: PathLike, dst: PathLike, target_is_directory := Bool, dir_fd := Nat or FileDescriptor) => NoneType
.sync!: () => NoneType
.system!: (command: Str) => Nat
.tcgetpgrp!: (fd: Nat or FileDescriptor) => Nat
.tcsetpgrp!: (fd: Nat or FileDescriptor, pgrp: Nat) => NoneType
.times!: () => NamedTuple {
.user = Float;
.system = Float;
.children_user = Float;
.children_system = Float;
}
.ttyname!: (fd: Nat or FileDescriptor) => Str

.umask!: (mask: Nat) => Nat
Expand All @@ -307,6 +406,17 @@ The name of the operating system dependent module imported. The following names
.urandom!: (size: Nat) => Bytes
.utime!: (path: PathLike, times := (Float, Float)) => NoneType

.wait!: () => NamedTuple {
.pid = Nat;
.status = Nat;
}
.waitid!: (idtype: Nat, id: Nat, options: Nat) => NamedTuple {
.si_pid = Nat;
.si_uid = Nat;
.si_signo = Nat;
.si_status = Nat;
.si_code = Nat;
}
.walk!: (
top: PathLike,
topdown := Bool,
Expand Down
32 changes: 32 additions & 0 deletions crates/erg_compiler/lib/pystd/sys.d.er
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
io = pyimport "io"

.__stdin__: io.TextIOWrapper!
.__stdout__: io.TextIOWrapper!
.__stderr__: io.TextIOWrapper!
.abiflags: Str
.api_version: Nat
.argv: [Str; _]
Expand All @@ -8,6 +11,7 @@ io = pyimport "io"
.builtin_module_names: [Str; _]
.byteorder: Str
.dont_write_bytecode: Bool
.dllhandle: Int
.copyright: Str
.exec_prefix: Str
.executable: Str
Expand Down Expand Up @@ -56,6 +60,25 @@ io = pyimport "io"
.seed_bits = Nat;
.cutoff = Int;
}
.hex_version: Nat
.int_info: NamedTuple {
.bits_per_digit = Nat;
.sizeof_digit = Nat;
.default_max_str_digits = Nat;
.str_dights_check_threshold = Nat;
}
.implementation: NamedTuple {
.name = Str;
.cache_tag = Str;
# TODO: version_info
.version = Obj;
.hexversion = Nat;
._multiarch = Str;
}
.maxsize: Nat
.maxunicode: Nat
.meta_path: List!(Str, _)
.modules: Dict!({Str: Module})
.path: List!(Str, _)
'''
* AIX -> 'aix'
Expand Down Expand Up @@ -86,11 +109,20 @@ io = pyimport "io"
.serial = Nat;
}

._clear_type_cache!: () => NoneType
._current_frames!: () => {Int: Frame}
.addaudithook!: (hook: (Str, *Obj) => NoneType) => NoneType
.audit!: (event: Str, *args: Obj) => NoneType
.breakpointhook!: () => NoneType
.displayhook!: (value: Obj) => NoneType
.exception!: () => Exception or NoneType
.exc_info!: () => (Type or NoneType, Exception or NoneType, Traceback or NoneType)
.exit: Obj -> Never
.getdefaultencoding!: () => Str
.getrecursionlimit!: () => Nat
.getrefcount!: (obj: Obj) => Nat
.getsizeof: (obj: Obj) -> Nat
.getswitchinterval!: () => Float
.intern: (string: Str) -> Str
.is_finalizing!: () => Bool
.setrecursionlimit!: Nat => NoneType

0 comments on commit c7522b1

Please sign in to comment.