Equations
- instMonadEIO = inferInstanceAs (Monad (EStateM ε IO.RealWorld))
Equations
- instMonadFinallyEIO = inferInstanceAs (MonadFinally (EStateM ε IO.RealWorld))
Equations
- instMonadExceptOfEIO = inferInstanceAs (MonadExceptOf ε (EStateM ε IO.RealWorld))
Equations
- instOrElseEIO = { orElse := MonadExcept.orElse }
Equations
- instInhabitedEIO = inferInstanceAs (Inhabited (EStateM ε IO.RealWorld α))
Equations
Equations
@[inline]
Equations
- BaseIO.toEIO act s = match act s with | EStateM.Result.ok a s => EStateM.Result.ok a s
@[inline]
Equations
- EIO.toBaseIO act s = match act s with | EStateM.Result.ok a s => EStateM.Result.ok (Except.ok a) s | EStateM.Result.error ex s => EStateM.Result.ok (Except.error ex) s
@[inline]
Equations
- EIO.catchExceptions act h s = match act s with | EStateM.Result.ok a s => EStateM.Result.ok a s | EStateM.Result.error ex s => h ex s
@[inline]
Equations
- BaseIO.toIO act = liftM act
@[inline]
Equations
- unsafeBaseIO fn = match EStateM.run fn () with | EStateM.Result.ok a x => a
@[inline]
Equations
- unsafeEIO fn = unsafeBaseIO (EIO.toBaseIO fn)
@[extern lean_io_as_task]
constant
BaseIO.asTask
{α : Type}
(act : BaseIO α)
(prio : optParam Task.Priority Task.Priority.default)
:
@[extern lean_io_map_task]
constant
BaseIO.mapTask
{α : Type u_1}
{β : Type}
(f : α → BaseIO β)
(t : Task α)
(prio : optParam Task.Priority Task.Priority.default)
:
@[extern lean_io_bind_task]
constant
BaseIO.bindTask
{α : Type u_1}
{β : Type}
(t : Task α)
(f : α → BaseIO (Task β))
(prio : optParam Task.Priority Task.Priority.default)
:
def
BaseIO.mapTasks
{α : Type u_1}
{β : Type}
(f : List α → BaseIO β)
(tasks : List (Task α))
(prio : optParam Task.Priority Task.Priority.default)
:
Equations
- BaseIO.mapTasks f tasks prio = (fun go => go tasks []) (BaseIO.mapTasks.go f prio)
def
BaseIO.mapTasks.go
{α : Type u_1}
{β : Type}
(f : List α → BaseIO β)
(prio : optParam Task.Priority Task.Priority.default)
:
Equations
- BaseIO.mapTasks.go f prio (t :: ts) x = BaseIO.bindTask t (fun a => BaseIO.mapTasks.go f prio ts (a :: x)) prio
- BaseIO.mapTasks.go f prio [] x = BaseIO.asTask (f (List.reverse x)) prio
@[inline]
def
EIO.asTask
{ε : Type}
{α : Type}
(act : EIO ε α)
(prio : optParam Task.Priority Task.Priority.default)
:
Equations
- EIO.asTask act prio = BaseIO.asTask (EIO.toBaseIO act) prio
@[inline]
def
EIO.mapTask
{α : Type u_1}
{ε : Type}
{β : Type}
(f : α → EIO ε β)
(t : Task α)
(prio : optParam Task.Priority Task.Priority.default)
:
Equations
- EIO.mapTask f t prio = BaseIO.mapTask (fun a => EIO.toBaseIO (f a)) t prio
@[inline]
def
EIO.bindTask
{α : Type u_1}
{ε : Type}
{β : Type}
(t : Task α)
(f : α → EIO ε (Task (Except ε β)))
(prio : optParam Task.Priority Task.Priority.default)
:
Equations
- EIO.bindTask t f prio = BaseIO.bindTask t (fun a => EIO.catchExceptions (f a) fun e => pure { get := Except.error e }) prio
@[inline]
def
EIO.mapTasks
{α : Type u_1}
{ε : Type}
{β : Type}
(f : List α → EIO ε β)
(tasks : List (Task α))
(prio : optParam Task.Priority Task.Priority.default)
:
Equations
- EIO.mapTasks f tasks prio = BaseIO.mapTasks (fun as => EIO.toBaseIO (f as)) tasks prio
Equations
- IO.ofExcept e = match e with | Except.ok a => pure a | Except.error e => throw (IO.userError (toString e))
@[extern lean_io_get_random_bytes]
@[inline]
Equations
- IO.asTask act prio = EIO.asTask act prio
@[inline]
def
IO.mapTask
{α : Type u_1}
{β : Type}
(f : α → IO β)
(t : Task α)
(prio : optParam Task.Priority Task.Priority.default)
:
Equations
- IO.mapTask f t prio = EIO.mapTask f t prio
@[inline]
def
IO.bindTask
{α : Type u_1}
{β : Type}
(t : Task α)
(f : α → IO (Task (Except IO.Error β)))
(prio : optParam Task.Priority Task.Priority.default)
:
Equations
- IO.bindTask t f prio = EIO.bindTask t f prio
@[inline]
def
IO.mapTasks
{α : Type u_1}
{β : Type}
(f : List α → IO β)
(tasks : List (Task α))
(prio : optParam Task.Priority Task.Priority.default)
:
Equations
- IO.mapTasks f tasks prio = EIO.mapTasks f tasks prio
- read: IO.FS.Mode
- write: IO.FS.Mode
- readWrite: IO.FS.Mode
- append: IO.FS.Mode
Equations
- IO.FS.instInhabitedStream = { default := { isEof := default, flush := default, read := default, write := default, getLine := default, putStr := default } }
@[specialize]
@[extern lean_io_prim_handle_mk]
Equations
- IO.FS.Handle.mk fn Mode bin = IO.FS.Handle.mkPrim fn (IO.FS.Handle.fopenFlags Mode bin)
@[extern lean_io_prim_handle_is_eof]
@[extern lean_io_prim_handle_read]
@[extern lean_io_prim_handle_write]
@[extern lean_io_prim_handle_get_line]
@[extern lean_io_prim_handle_put_str]
@[extern lean_io_realpath]
@[inline]
def
IO.FS.withFile
{α : Type}
(fn : System.FilePath)
(mode : IO.FS.Mode)
(f : IO.FS.Handle → IO α)
:
IO α
Equations
- IO.FS.withFile fn mode f = IO.FS.Handle.mk fn mode true >>= f
Equations
- IO.FS.Handle.putStrLn h s = IO.FS.Handle.putStr h (String.push s (Char.ofNat 10))
Equations
- IO.FS.Handle.readBinToEnd h = (fun loop => loop ByteArray.empty) (IO.FS.Handle.readBinToEnd.loop h)
Equations
- IO.FS.Handle.readToEnd h = (fun loop => loop "") (IO.FS.Handle.readToEnd.loop h)
Equations
- IO.FS.readBinFile fname = do let h ← IO.FS.Handle.mk fname IO.FS.Mode.read true IO.FS.Handle.readBinToEnd h
Equations
- IO.FS.readFile fname = do let h ← IO.FS.Handle.mk fname IO.FS.Mode.read false IO.FS.Handle.readToEnd h
Equations
- IO.FS.lines fname = do let h ← IO.FS.Handle.mk fname IO.FS.Mode.read false (fun read => read #[]) (IO.FS.lines.read h)
Equations
- IO.FS.writeBinFile fname content = do let h ← IO.FS.Handle.mk fname IO.FS.Mode.write true IO.FS.Handle.write h content
Equations
- IO.FS.writeFile fname content = do let h ← IO.FS.Handle.mk fname IO.FS.Mode.write false IO.FS.Handle.putStr h content
Equations
- IO.FS.Stream.putStrLn strm s = IO.FS.Stream.putStr strm (String.push s (Char.ofNat 10))
Equations
- IO.FS.instReprDirEntry = { reprPrec := [anonymous] }
Equations
- IO.FS.DirEntry.path entry = entry.root / { toString := entry.fileName }
- dir: IO.FS.FileType
- file: IO.FS.FileType
- symlink: IO.FS.FileType
- other: IO.FS.FileType
Equations
- IO.FS.instReprFileType = { reprPrec := [anonymous] }
Equations
- IO.FS.instBEqFileType = { beq := [anonymous] }
Equations
- IO.FS.instBEqSystemTime = { beq := [anonymous] }
Equations
- IO.FS.instReprSystemTime = { reprPrec := [anonymous] }
Equations
- IO.FS.instInhabitedSystemTime = { default := { sec := default, nsec := default } }
Equations
- IO.FS.instOrdSystemTime = { compare := [anonymous] }
Equations
- IO.FS.instLTSystemTime = ltOfOrd
Equations
- IO.FS.instLESystemTime = leOfOrd
- accessed : IO.FS.SystemTime
- modified : IO.FS.SystemTime
- byteSize : UInt64
- type : IO.FS.FileType
Equations
- IO.FS.instReprMetadata = { reprPrec := [anonymous] }
@[extern lean_io_read_dir]
@[extern lean_io_metadata]
Equations
- System.FilePath.isDir p = do let a ← EIO.toBaseIO (System.FilePath.metadata p) match a with | Except.ok m => pure (m.type == IO.FS.FileType.dir) | Except.error x => pure false
Equations
- System.FilePath.pathExists p = do let a ← EIO.toBaseIO (System.FilePath.metadata p) pure (Except.toBool a)
def
System.FilePath.walkDir
(p : System.FilePath)
(enter : optParam (System.FilePath → IO Bool) fun x => pure true)
:
Equations
- System.FilePath.walkDir p enter = (fun go => Prod.snd <$> StateT.run (go p) #[]) (System.FilePath.walkDir.go enter)
partial def
System.FilePath.walkDir.go
(enter : optParam (System.FilePath → IO Bool) fun x => pure true)
(p : System.FilePath)
:
def
IO.withStdin
{m : Type → Type u_1}
{α : Type}
[inst : Monad m]
[inst : MonadFinally m]
[inst : MonadLiftT BaseIO m]
(h : IO.FS.Stream)
(x : m α)
:
m α
Equations
- IO.withStdin h x = do let prev ← liftM (IO.setStdin h) tryFinally x (discard (liftM (IO.setStdin prev)))
def
IO.withStdout
{m : Type → Type u_1}
{α : Type}
[inst : Monad m]
[inst : MonadFinally m]
[inst : MonadLiftT BaseIO m]
(h : IO.FS.Stream)
(x : m α)
:
m α
Equations
- IO.withStdout h x = do let prev ← liftM (IO.setStdout h) tryFinally x (discard (liftM (IO.setStdout prev)))
def
IO.withStderr
{m : Type → Type u_1}
{α : Type}
[inst : Monad m]
[inst : MonadFinally m]
[inst : MonadLiftT BaseIO m]
(h : IO.FS.Stream)
(x : m α)
:
m α
Equations
- IO.withStderr h x = do let prev ← liftM (IO.setStderr h) tryFinally x (discard (liftM (IO.setStderr prev)))
Equations
- IO.println s = IO.print (String.push (toString s) (Char.ofNat 10))
Equations
- IO.eprintln s = IO.eprint (String.push (toString s) (Char.ofNat 10))
Equations
- IO.appDir = do let p ← IO.appPath let discr ← pure (System.FilePath.parent p) match discr with | some p => IO.FS.realPath p | x => throw (IO.userError (toString "System.IO.appDir: unexpected filename '" ++ toString p ++ toString "'"))
- piped: IO.Process.Stdio
- inherit: IO.Process.Stdio
- null: IO.Process.Stdio
Equations
- IO.Process.Stdio.toHandleType x = match x with | IO.Process.Stdio.piped => IO.FS.Handle | IO.Process.Stdio.inherit => Unit | IO.Process.Stdio.null => Unit
- stdin : IO.Process.Stdio
- stdout : IO.Process.Stdio
- stderr : IO.Process.Stdio
- stdin : IO.Process.Stdio.toHandleType cfg.stdin
- stdout : IO.Process.Stdio.toHandleType cfg.stdout
- stderr : IO.Process.Stdio.toHandleType cfg.stderr
@[extern lean_io_process_spawn]
@[extern lean_io_process_child_wait]
@[extern lean_io_process_child_take_stdin]
constant
IO.Process.Child.takeStdin
{cfg : IO.Process.StdioConfig}
:
IO.Process.Child cfg →
IO
(IO.Process.Stdio.toHandleType cfg.stdin × IO.Process.Child { stdin := IO.Process.Stdio.null, stdout := cfg.stdout, stderr := cfg.stderr })
Equations
- IO.Process.output args = do let child ← IO.Process.spawn { toStdioConfig := { stdin := args.toStdioConfig.stdin, stdout := IO.Process.Stdio.piped, stderr := IO.Process.Stdio.piped }, cmd := args.cmd, args := args.args, cwd := args.cwd, env := args.env } let stdout ← liftM (IO.asTask (IO.FS.Handle.readToEnd child.stdout) Task.Priority.dedicated) let stderr ← IO.FS.Handle.readToEnd child.stderr let exitCode ← IO.Process.Child.wait child let stdout ← IO.ofExcept stdout.get pure { exitCode := exitCode, stdout := stdout, stderr := stderr }
Equations
- IO.Process.run args = do let out ← IO.Process.output args let _do_jp : PUnit → IO String := fun y => pure out.stdout if (out.exitCode != 0) = true then do let y ← throw (IO.userError ("process '" ++ args.cmd ++ "' exited with code " ++ toString out.exitCode)) _do_jp y else do let y ← pure PUnit.unit _do_jp y
Equations
- IO.AccessRight.flags acc = let r := if acc.read = true then 4 else 0; let w := if acc.write = true then 2 else 0; let x := if acc.execution = true then 1 else 0; UInt32.lor r (UInt32.lor w x)
- user : IO.AccessRight
- group : IO.AccessRight
- other : IO.AccessRight
Equations
- IO.FileRight.flags acc = let u := UInt32.shiftLeft (IO.AccessRight.flags acc.user) 6; let g := UInt32.shiftLeft (IO.AccessRight.flags acc.group) 3; let o := IO.AccessRight.flags acc.other; UInt32.lor u (UInt32.lor g o)
@[extern lean_chmod]
Equations
- IO.setAccessRights filename mode = IO.Prim.setAccessRights filename (IO.FileRight.flags mode)
Equations
- IO.instMonadLiftSTRealWorldBaseIO = { monadLift := fun {α} => id }
Equations
- IO.FS.Stream.ofHandle h = { isEof := liftM (IO.FS.Handle.isEof h), flush := IO.FS.Handle.flush h, read := IO.FS.Handle.read h, write := IO.FS.Handle.write h, getLine := IO.FS.Handle.getLine h, putStr := IO.FS.Handle.putStr h }
Equations
- IO.FS.Stream.ofBuffer r = { isEof := do let b ← ST.Ref.get r pure (decide (b.pos ≥ ByteArray.size b.data)), flush := pure (), read := fun n => ST.Ref.modifyGet r fun b => let data := ByteArray.extract b.data b.pos (b.pos + USize.toNat n); (data, { data := b.data, pos := b.pos + ByteArray.size data }), write := fun data => ST.Ref.modify r fun b => { data := ByteArray.copySlice data 0 b.data b.pos (ByteArray.size data) false, pos := b.pos + ByteArray.size data }, getLine := ST.Ref.modifyGet r fun b => let pos := match ByteArray.findIdx? b.data (fun u => u == 0 || decide (u = Nat.toUInt8 (Char.toNat (Char.ofNat 10)))) b.pos with | some pos => if (ByteArray.get! b.data pos == 0) = true then pos else pos + 1 | none => ByteArray.size b.data; (String.fromUTF8Unchecked (ByteArray.extract b.data b.pos pos), { data := b.data, pos := pos }), putStr := fun s => ST.Ref.modify r fun b => let data := String.toUTF8 s; { data := ByteArray.copySlice data 0 b.data b.pos (ByteArray.size data) false, pos := b.pos + ByteArray.size data } }
def
IO.FS.withIsolatedStreams
{m : Type → Type u_1}
{α : Type}
[inst : Monad m]
[inst : MonadFinally m]
[inst : MonadLiftT BaseIO m]
(x : m α)
:
Equations
- IO.FS.withIsolatedStreams x = do let bIn ← liftM (IO.mkRef { data := ByteArray.empty, pos := 0 }) let bOut ← liftM (IO.mkRef { data := ByteArray.empty, pos := 0 }) let r ← IO.withStdin (IO.FS.Stream.ofBuffer bIn) (IO.withStdout (IO.FS.Stream.ofBuffer bOut) (IO.withStderr (IO.FS.Stream.ofBuffer bOut) x)) let bOut ← liftM (ST.Ref.get bOut) let out : String := String.fromUTF8Unchecked bOut.data pure (out, r)
Equations
- Lean.instEval = { eval := fun a x => IO.println (toString (a ())) }
Equations
- Lean.instEval_1 = { eval := fun a x => IO.println (repr (a ())) }
Equations
- Lean.instEvalUnit = { eval := fun u hideUnit => if hideUnit = true then pure () else IO.println (repr (u ())) }
Equations
- Lean.instEvalIO = { eval := fun x x_1 => do let a ← x () Lean.Eval.eval (fun x => a) true }
@[noinline, nospecialize]
Equations
Equations
- termPrintln!__ = Lean.ParserDescr.node `termPrintln!__ 1022 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol "println! ") (Lean.ParserDescr.binary `orelse (Lean.ParserDescr.unary `interpolatedStr (Lean.ParserDescr.cat `term 0)) (Lean.ParserDescr.cat `term 0)))