Something went wrong. Try again.
An experiment in static, refcounted, procedural language with ownership
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061use std.( c, c.write, os.errors, str.(?))const STDOUT: i32 = 1fn print*(msg: &str) unit = unsafe write(STDOUT, as[_](msg.ptr), msg.len)fn print*(msg: str) unit = print(&msg)fn println*() unit = print("\n")fn println*(msg: &str) unit = print("{msg}\n")fn println*(msg: str) unit = println(&msg)type Result*[T] = std.result.Result[T, Error]type Error* { PermissionDenied NotFound Interrupted BadFileNumber AlreadyExists InvalidArgument InvalidData(cause: &str) Other(code: i32)}fn Error.from-os-error*(code: i32) Error = match code { errors.EPERM -> Error.PermissionDenied errors.ENOENT -> Error.NotFound errors.EINTR -> Error.Interrupted errors.EBADF -> Error.BadFileNumber errors.EEXIST -> Error.AlreadyExists errors.EINVAL -> Error.InvalidArgument code -> Error.Other(code) }// TODO: cross-platform errnofn Error.last-os-error*() Error = Error.from-os-error(unsafe (c.__errno_location().0))fn fmt*(err: &Error, buf: &mut StrBuf) unit = match err { Error.PermissionDenied -> buf.push("Permission denied") Error.NotFound -> buf.push("Not found") Error.Interrupted -> buf.push("Interrupted") Error.BadFileNumber -> buf.push("Bad file number") Error.AlreadyExists -> buf.push("Already exists") Error.InvalidArgument -> buf.push("Invalid argument") Error.InvalidData(cause) -> { buf.push("Invalid data: ") buf.push(cause) } Error.Other(code) -> buf.push("Other({code})") }