Email or username:

Password:

Forgot your password?
lawless polymorph

mini-announcement: I've decided to publish Yotta.

Yotta is a forth-like language with a very small core. In the beginning, all you can do is:

- emit machine code,
- emit machine code that emits machine code,
- define new words ... that emit machine code

With just those primitives we define an x86-64 assembler, and from there we use that assembler to define most of a forth.

Check it out: github.com/typeswitch-dev/yott

2 comments
lawless polymorph

In Yotta there are only three primitives:

$XX emits the byte XX (in hex)
^XX emits machine code that emits XX
: A defines the word A

From there, the first thing we need to do is define semicolon (;) which emits the RET instruction. Semicolon is used to end word definitions. We use semicolon to end its own definition.

This is the preamble, the first bit of Yotta code that the Yotta interpreter/compiler runs. Besides semicolon, we're also defining line and block comments with \ and ( ).

In Yotta there are only three primitives:

$XX emits the byte XX (in hex)
^XX emits machine code that emits XX
: A defines the word A

From there, the first thing we need to do is define semicolon (;) which emits the RET instruction. Semicolon is used to end word definitions. We use semicolon to end its own definition.

Excerpt of Yotta code, from the preamble. The full file is in the linked repository, at src/0-preamble.fs

This excerpt defines a few words, including semicolon (used to end a definition) and backslash (used to make a comment). Then it includes the following comment: 

Welcome to yotta! Yotta is a minimalistic forth-like language that has three primitives:

$XX  Compile the byte XX (in hex).
^XX  Compile code that compiles the byte XX (in hex).
: A   define the word A

Once a word is defined, it can be invoked by name. All definitions are executed immediately (i.e. all words are "immediate"). As a result, most words will compile something when executed. Words will either emit machine code directly (using ^XX), or they will use "CALL>" to emit a call instruction, or "INLINE>" to inline the rest of the word.
lawless polymorph

After the preamble, there is an x86-64 assembler, written in Yotta. The assembler makes it much easier to work with machine code, as you might expect.

However the assembler is a bit quirky, because it uses a syntax that reflects the structure of the machine code. It's neither intel syntax nor at&t syntax, but a secret third thing.

I won't get into the assembler details, but let me show you how it's used to build a forth:

Definition of DUP, NIP, DROP, OVER, 2DUP, and 2DROP words using Yotta assembler. The source code comes from the src/2-forth.fs in the linked repository.
Go Up