2020-01-07 15:09:08 +01:00
|
|
|
## On The Kernel Wordset
|
|
|
|
|
2021-05-12 15:57:22 +02:00
|
|
|
In implementing the Retro 12 kernel (called Retro Core, and
|
2020-12-21 22:05:30 +01:00
|
|
|
defined in `image/retro.muri`) I had to decide on what functionality
|
2020-12-17 13:53:47 +01:00
|
|
|
would be needed. It was important to me that this be kept clean
|
|
|
|
and minimalistic, as I didn't want to spend a lot of time
|
|
|
|
changing it as time progressed. It's far nicer to code at the
|
2021-05-12 15:57:22 +02:00
|
|
|
higher level, where the Retro language is fully functional, as
|
2020-12-17 13:53:47 +01:00
|
|
|
opposed to writing more assembly code.
|
2020-01-07 15:09:08 +01:00
|
|
|
|
|
|
|
So what made it in?
|
|
|
|
|
|
|
|
Primitives
|
|
|
|
|
|
|
|
These are words that map directly to Nga instructions.
|
|
|
|
|
|
|
|
dup drop swap call eq? -eq? lt? gt?
|
|
|
|
fetch store + - * /mod and or
|
|
|
|
xor shift push pop 0;
|
|
|
|
|
|
|
|
Memory
|
|
|
|
|
|
|
|
fetch-next store-next , s,
|
|
|
|
|
|
|
|
Strings
|
|
|
|
|
|
|
|
s:to-number s:eq? s:length
|
|
|
|
|
|
|
|
Flow Control
|
|
|
|
|
|
|
|
choose if -if repeat again
|
|
|
|
|
|
|
|
Compiler & Interpreter
|
|
|
|
|
|
|
|
Compiler Heap ; [ ] Dictionary
|
|
|
|
d:link d:class d:xt d:name d:add-header
|
|
|
|
class:word class:primitive class:data class:macro
|
2021-03-30 13:58:25 +02:00
|
|
|
sigil:: sigil:# sigil:& sigil:$
|
2020-01-07 15:09:08 +01:00
|
|
|
interpret d:lookup err:notfound
|
|
|
|
|
|
|
|
Assembler
|
|
|
|
|
|
|
|
i d r
|
|
|
|
|
2021-03-30 13:58:25 +02:00
|
|
|
I *could* slightly reduce this. The $ sigil could be defined in
|
2020-01-07 15:09:08 +01:00
|
|
|
higher level code, and I don't strictly *need* to expose the
|
|
|
|
`fetch-next` and `store-next` here. But since the are already
|
|
|
|
implemented as dependencies of the words in the kernel, it would
|
|
|
|
be a bit wasteful to redefine them later in higher level code.
|
|
|
|
|
|
|
|
A recent change was the addition of the assembler into the
|
|
|
|
kernel. This allows the higher levels to use assembly as needed,
|
|
|
|
which gives more flexibility and allows for more optimal code
|
|
|
|
in the standard library.
|
|
|
|
|
|
|
|
With these words the rest of the language can be built up. Note
|
2021-05-12 15:57:22 +02:00
|
|
|
that the Retro kernel does not provide any I/O words. It's assumed
|
|
|
|
that the Retro interfaces will add these as best suited for the
|
2020-01-07 15:09:08 +01:00
|
|
|
systems they run on.
|
|
|
|
|
|
|
|
There is another small bit. All images start with a few key
|
|
|
|
pointers in fixed offsets of memory. These are:
|
|
|
|
|
|
|
|
| Offset | Contains |
|
|
|
|
| ------ | --------------------------- |
|
|
|
|
| 0 | lit call nop nop |
|
|
|
|
| 1 | Pointer to main entry point |
|
|
|
|
| 2 | Dictionary |
|
|
|
|
| 3 | Heap |
|
2021-05-12 15:57:22 +02:00
|
|
|
| 4 | Retro version identifier |
|
2020-01-07 15:09:08 +01:00
|
|
|
|
|
|
|
An interface can use the dictionary pointer and knowledge of the
|
2021-05-12 15:57:22 +02:00
|
|
|
dictionary format for a specific Retro version to identify the
|
2020-01-07 15:09:08 +01:00
|
|
|
location of essential words like `interpret` and `err:notfound`
|
|
|
|
when implementing the user facing interface.
|