Skip to content

Commit

Permalink
Add base file-descriptors document.
Browse files Browse the repository at this point in the history
  • Loading branch information
SirJosh3917 authored and SirJosh3917 committed Sep 6, 2020
1 parent 19a57f7 commit 3ca198e
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions design/file-descriptors.md
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit 3ca198e

Please sign in to comment.