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.