Skip to content

Commit

Permalink
More detail in HTTP server README
Browse files Browse the repository at this point in the history
  • Loading branch information
ajyoon committed Dec 9, 2016
1 parent 5ddf9e0 commit 1231a65
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ This interpreter features a full implementation of the [brainfuck](https://esola

## Syscalls

Typical brainfuck programs are only able to interact with the real world via
STDIN and STDOUT. This implementation extends the language by allowing it to
make Linux syscalls, letting it do lots of cool things like
[write an HTTP server in brainfuck](examples/http).

To make a syscall in brainfuck programs, this implementation introduces an
additional language character: `%`. When this character is encountered in
a program, the interpreter does the following:
Expand All @@ -48,9 +53,6 @@ a program, the interpreter does the following:
in big-endian form.
5. The syscall is made, and its return value is dumped to the current cell.

Having the ability to interact with the outside world in ways other than STDIN/STDOUT
lets us do a lot of cool things, like [write HTTP servers in brainfuck](examples/http)

For example, to call sys-exit, we can give the following code:

```bf
Expand Down
18 changes: 14 additions & 4 deletions examples/http/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,26 @@ any way to properly create C `struct`s, we have to do things like manually
build up structs byte-by-byte, passing the series of brainfuck cells in
memory directly to the kernel.

Building the interpreter:

The interpreter is written in NASM x86-64 assembly. You'll need NASM to build, and if your architecture is not x86-64 you will need to use an emulator or similar solution. Otherwise, it's as easy as:

```sh
http$ cd ../../
systemf$ make [build || debug || clean]
```

To run:

```sh
# Build if you haven't already
systemf$ make debug
systemf$ cd examples/http
systemf/examples/http$ ../../bin/systemf server.bf
systemf$ cd examples/http/
http$ ../../bin/systemf server.bf
```

The server will listen on `localhost:4000`.
Go to `localhost:4000/index.html` to see the site in action!

It's, uh, pretty insecure. Don't try this in the wild.

For more details about the interpreter and its rules, check out
the [main project readme](https://github.com/ajyoon/systemf).

0 comments on commit 1231a65

Please sign in to comment.