feat: enhance os, random type decls

This commit is contained in:
Shunsuke Shibayama 2024-03-24 13:02:26 +09:00
parent 54bd111a5f
commit 35f55c62d3
4 changed files with 63 additions and 1 deletions

View file

@ -2096,7 +2096,10 @@ impl Context {
if let Some(Greater) = self.try_cmp(&l, &r) {
panic!("{l}..{r} is not a valid interval type (should be lhs <= rhs)")
}
Ok(int_interval(op, l, r))
let l_t = self.get_tp_t(&l).unwrap_or(Obj).derefine();
let r_t = self.get_tp_t(&r).unwrap_or(Obj).derefine();
let t = self.union(&l_t, &r_t);
Ok(interval(op, t, l, r))
}
TypeSpec::Subr(subr) => {
let mut errs = TyCheckErrors::empty();

View file

@ -81,6 +81,13 @@ The name of the operating system dependent module imported. The following names
.O_SHLOCK: Nat
.O_EXLOCK: Nat
.POSIX_FADV_NORMAL: Nat
.POSIX_FADV_SEQUENTIAL: Nat
.POSIX_FADV_RANDOM: Nat
.POSIX_FADV_NOREUSE: Nat
.POSIX_FADV_WILLNEED: Nat
.POSIX_FADV_DONTNEED: Nat
.PRIO_PGRP: Nat
.PRIO_PROCESS: Nat
.PRIO_USER: Nat
@ -89,12 +96,23 @@ The name of the operating system dependent module imported. The following names
.PRIO_DARWIN_BG: Nat
.PRIO_DARWIN_NONUI: Nat
.RWF_APPEND: Nat
.RWF_DSYNC: Nat
.RWF_HIPRI: Nat
.RWF_NOWAIT: Nat
.RWF_SYNC: Nat
.SEEK_SET: Nat
.SEEK_CUR: Nat
.SEEK_END: Nat
.SEEK_HOLE: Nat
.SEEK_DATA: Nat
.SF_MNOWAIT: Nat
.SF_NOCACHE: Nat
.SF_NODISKIO: Nat
.SF_SYNC: Nat
.close!: (fd: Nat or FileDescriptor) => NoneType
.closerange!: (fd_low: Nat, fd_high: Nat) => NoneType
.ctermid!: () => Str
@ -150,7 +168,16 @@ The name of the operating system dependent module imported. The following names
.openpty!: () => (Nat, Nat)
.pipe!: () => (Nat, Nat)
.pipe2!: (flags: Nat) => (Nat, Nat)
# 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
.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
.pwrite!: (fd: Nat or FileDescriptor, str: Bytes, offset: Nat) => Nat
.pwritev!: (fd: Nat or FileDescriptor, buffers: Ref(ByteArray!), offset: Nat, flags := Nat) => Nat
.read!: (fd: Nat or FileDescriptor, n: Nat) => Bytes
.readlink!: (path: PathLike, dir_fd := Nat or FileDescriptor) => Str
.remove!: (path: PathLike,) => NoneType
.removedirs!: (path: PathLike,) => NoneType
.rename!: (src: PathLike, dst: PathLike) => NoneType
@ -158,6 +185,8 @@ The name of the operating system dependent module imported. The following names
.replace!: (src: PathLike, dst: PathLike) => NoneType
.rmdir!: (path: PathLike,) => NoneType
.scandir!: (path := PathLike,) => Iterator DirEntry
.sendfile!: (out_fd: Nat or FileDescriptor, in_fd: Nat or FileDescriptor, offset := Nat, count := Nat) => Nat
.set_blocking!: (fd: Nat or FileDescriptor, blocking: Bool) => NoneType
.setegid!: (egid: Nat) => NoneType
.seteuid!: (euid: Nat) => NoneType
.setgid!: (gid: Nat) => NoneType

View file

@ -1,8 +1,22 @@
.Random!: ClassType
.Random! <: InheritableType
.Random!.
seed!: (self: RefMut(.Random!), a := Float, version := Nat) => NoneType
getstate!: (self: Ref(.Random!)) => (Nat, [Nat; _], Nat or NoneType)
setstate!: (self: RefMut(.Random!), state: (Nat, [Nat; _], Nat or NoneType)) => NoneType
random!: (self: RefMut(.Random!)) => Float
getrandbits!: (self: RefMut(.Random!), k: Nat) => Nat
.SystemRandom!: ClassType
.SystemRandom! <: InheritableType
.seed!: (a := Num, version := Int) => NoneType
.randbytes!: (n: Nat) => Bytes
.randrange!: (start: Int, stop := Int, step := Int) => Int
.randint!: (a: Int, b: Int) => Int
.getrandbits!: (k: Nat) => Nat
.getstate!: () => (Nat, [Nat; _], Nat or NoneType)
.setstate!: (state: (Nat, [Nat; _], Nat or NoneType)) => NoneType
.choice!: |T: Type|(seq: Sequence(T)) => T
# TODO: dependent length array type
.choices!: |T: Type|(population: Sequence(T), weights := [Nat; _] or NoneType, k := Nat) => [T; _]
@ -12,3 +26,13 @@
.random!: () => 0.0..1.0 # TODO: <1.0
.dep_uniform! = 'uniform': |A: Int, B: Int|(a: {A}, b: {B}) => A..B
.uniform!: (a: Int, b: Int) => Int
.triangular!: (low: Float, high: Float, mode: Float) => Float
.betavariate!: (alpha: Float, beta: Float) => 0.0..1.0
.expovariate!: (lambd := Float) => Float
.gammavariate!: (alpha: Float, beta: Float) => Float
.gauss!: (mu := Float, sigma := Float) => Float
.lognormvariate!: (mu: Float, sigma: Float) => Float
.normalvariate!: (mu := Float, sigma := Float) => Float
.vonmisesvariate!: (mu: Float, kappa: Float) => Float
.paretovariate!: (alpha: Float) => Float
.weibullvariate!: (alpha: Float, beta: Float) => Float

View file

@ -4,3 +4,9 @@ v.push! 1
w = v
print! w
print! v # this should cause a MoveError
push! |T| a: RefMut(Array!(T, _)), value: T =
a.push! value
push! w, 2
print! w # OK