From 3ca198e4cc0872c0a23948a9ed15d9e98f565881 Mon Sep 17 00:00:00 2001 From: SirJosh3917 Date: Sat, 5 Sep 2020 22:34:17 -0400 Subject: [PATCH] Add base file-descriptors document. --- design/file-descriptors.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 design/file-descriptors.md diff --git a/design/file-descriptors.md b/design/file-descriptors.md new file mode 100644 index 00000000..76bdd715 --- /dev/null +++ b/design/file-descriptors.md @@ -0,0 +1,17 @@ +# File Descriptors +File Descriptors (witx type `fd`) are an abstract way of representing access to a resource. More often than not, they are processes (WIP), sockets (WIP), files, or even the console. + +# Null File Descriptor +A File Descriptor of 0 is a null file descriptor. It's used whenever there is *no* file descriptor. Passing this to a method is a no-no, and receiving one from a method must be handled. + +# The Console +When a program is initiated, `stdout`, `stdin`, and `stderr` (respectively `fd` ids `1`, `2`, and `3`) are opened. To print to these, simply call `fd_write` with the corresponding arguments. An simple "Hello World!" program written in `wat` is shown below: + +```wat +(module + ;; TODO: small hello world? +) +``` + +# Files +Files can be opened and closed with the commands `fd_open` and `fd_close` respectively. These commands will fail if the WASM environment did not give the program permission to execute these.