~vdupras/tumbleforth

be4aa202144fc50f5f450644ffa3c4de55d668cb — Virgil Dupras 1 year, 4 months ago f79d48b
fixes
3 files changed, 11 insertions(+), 11 deletions(-)

M 01-duskcc/04-wordsshell.md
M 01-duskcc/09-dusktillc.md
M 01-duskcc/10-beast.md
M 01-duskcc/04-wordsshell.md => 01-duskcc/04-wordsshell.md +1 -1
@@ 80,7 80,7 @@ process is:
3. Stop the loop when a whitespace is encountered.

You have a working loop! … for a certain definition of “working”. Being
directly wired to they keyboard, without any line editing mechanism, makes the
directly wired to the keyboard, without any line editing mechanism, makes the
system very difficult to use. But for now, this will have to do because it will
be a while before we add a line buffer.


M 01-duskcc/09-dusktillc.md => 01-duskcc/09-dusktillc.md +4 -4
@@ 1,4 1,4 @@
# [Tumble Forth](/): The Unbearable Immediateness of Compiling
# [Tumble Forth](/): From Dusk Till C

We now know the [secret ingredients that make Forths alive][prev], but we won’t
go all the way to a full Forth because it would be much less interesting than


@@ 66,7 66,7 @@ prompt.

For this story arc, we’ll make the filesystem root our workspace. We’ll write
our work in files at the root filesystem and then load them in Dusk. Let’s test
that this work by creating a file called `myasm.fs` in the `fs/` subfolder in
that this works by creating a file called `myasm.fs` in the `fs/` subfolder in
Dusk’s source code, with this content:

    ." Hello Dusk!\n"


@@ 240,7 240,7 @@ First of all, let’s have useful constants:

We’ll use these constants as arguments to our API. Now, the tricky part is to
elegantly express the “use `EAX` as a direct destination and use `ESI` as an
indirect source`”` command to the `add` instruction. Dusk’s i386 assembler has
indirect source” command to the `add` instruction. Dusk’s i386 assembler has
such an API, but the scope of this subject is too wide for this story arc.
We’ll defer this to another story arc and go with a brutally simple, albeit
ugly, API: specifying the form in the word name.


@@ 296,7 296,7 @@ compiler, when comes the time of generating the code.

We won't go further, assembler-wise, in this story arc. If you wish to explore
this subject further, I recommend you a [good tool to help you visualize x86
encoding][x86enc].
encoding][x86enc]. Then, you can of course take a look at Dusk's i386 assembler.

## Up next


M 01-duskcc/10-beast.md => 01-duskcc/10-beast.md +6 -6
@@ 63,7 63,7 @@ To avoid making words too heavy, we don't bother commenting the stack status at
each step. However, Dusk has the habit of documenting stack status at particular
points:

1. Right after the beginning of the loop
1. Right after the beginning of a loop.
2. Sometimes at the end of a loop. Especially in cases where there is more than
   one exit point for the loop, for example in `begin..while..repeat`, in which
   exit points can have different stack status!


@@ 105,7 105,7 @@ struct, is provided automatically by structbinds, so for us, the effective word
signature is `( -- c )`.

The `:getc` word yields the character at current stream position and then
advance this position by 1. If the end of the stream has been reached, -1 is
advances this position by 1. If the end of the stream has been reached, -1 is
returned. Therefore, we can reimplement (badly), the `:spit` method above thus:

    : myspit ( -- )


@@ 119,9 119,9 @@ you can do `0 file :seek`.

## Tokenizer API

What we'll want to build is a word that, when called, yields either the next
token, as a string, from `file`. If we've reached the end of the file, we yield
zero. Let's call this word `nextt ( -- str-or-0 )` (for "next token").
What we'll want to build is a word that, when called, yields the next token, as
a string, from `file`. If we've reached the end of the file, we yield zero.
Let's call this word `nextt ( -- str-or-0 )` (for "next token").

Let's start roughly and yield our stream line by line, leveraging
`IO :readline`:


@@ 147,7 147,7 @@ whitespace? Let's start a new `tok.fs` unit with this utility:

    : isWS? ( c -- f ) SPC <= ;

`SPC` is a system constant for $20. In signatures, `f` means "flag" (0 or 1).
`SPC` is a system constant for `$20`. In signatures, `f` means "flag" (0 or 1).

Then, all we need is a buffer and a loop: