2021-01-21 13:40:28 +01:00
|
|
|
<?xml version="1.0" encoding="utf-8"?>
|
|
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
|
|
|
<html xmlns="http://www.w3.org/1999/xhtml"><head>
|
|
|
|
<title>.</title>
|
|
|
|
<style type="text/css">
|
|
|
|
|
|
|
|
* { color: #000; background: #fff; max-width: 700px; }
|
|
|
|
tt, pre { background: #dedede; color: #111; font-family: monospace;
|
|
|
|
white-space: pre; display: block; width: 100%; }
|
|
|
|
.indentedcode { margin-left: 2em; margin-right: 2em; }
|
|
|
|
.codeblock {
|
|
|
|
background: #dedede; color: #111; font-family: monospace;
|
|
|
|
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
|
|
|
|
padding: 7px;
|
|
|
|
display: block;
|
|
|
|
}
|
|
|
|
|
|
|
|
.indentedlist { margin-left: 2em; color: #000; }
|
|
|
|
|
|
|
|
span { white-space: pre; }
|
|
|
|
.text { color: #000; white-space: pre; background: #dedede; }
|
|
|
|
.colon { color: #000; background: #dedede; }
|
|
|
|
.note { color: #000; background: #dedede; }
|
|
|
|
.str { color: #000; text-decoration: underline; background: #dedede; }
|
|
|
|
.num { color: #000; background: #dedede; font-weight: bold; font-style: italic; }
|
|
|
|
.fnum { color: #000; font-weight: bold; background: #dedede; }
|
|
|
|
.ptr { color: #000; font-weight: bold; background: #dedede; }
|
|
|
|
.fetch { color: #000; font-style: italic; background: #dedede; }
|
|
|
|
.store { color: #000; font-style: italic; background: #dedede; }
|
|
|
|
.char { color: #000; background: #dedede; }
|
|
|
|
.inst { color: #000; background: #dedede; }
|
|
|
|
.defer { color: #000; background: #dedede; }
|
|
|
|
.imm { color: #000; font-weight: bold; background: #dedede; }
|
|
|
|
.prim { color: #000; font-weight: bolder; background: #dedede; }
|
|
|
|
|
|
|
|
.tt { white-space: pre; font-family: monospace; background: #dedede; }
|
|
|
|
|
|
|
|
.h1, .h2, .h3, .h4 { white-space: normal; }
|
|
|
|
.h1 { font-size: 125%; }
|
|
|
|
.h2 { font-size: 120%; }
|
|
|
|
.h3 { font-size: 115%; }
|
|
|
|
.h4 { font-size: 110%; }
|
|
|
|
.hr { display: block; height: 2px; background: #000000; }
|
|
|
|
</style>
|
|
|
|
</head><body>
|
|
|
|
<p><span class="h2">On The Kernel Wordset</span>
|
|
|
|
<br/><br/>
|
2021-05-17 19:04:42 +02:00
|
|
|
In implementing the Retro 12 kernel (called Retro Core, and
|
2021-01-21 13:40:28 +01:00
|
|
|
defined in <span class="tt">image/retro.muri</span>) I had to decide on what functionality
|
|
|
|
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-17 19:04:42 +02:00
|
|
|
higher level, where the Retro language is fully functional, as
|
2021-01-21 13:40:28 +01:00
|
|
|
opposed to writing more assembly code.
|
|
|
|
<br/><br/>
|
|
|
|
So what made it in?
|
|
|
|
<br/><br/>
|
|
|
|
Primitives
|
|
|
|
<br/><br/>
|
|
|
|
These are words that map directly to Nga instructions.
|
|
|
|
<br/><br/>
|
|
|
|
<tt class='indentedcode'>dup drop swap call eq? -eq? lt? gt?</tt>
|
|
|
|
<tt class='indentedcode'>fetch store + - * /mod and or</tt>
|
|
|
|
<tt class='indentedcode'>xor shift push pop 0;</tt>
|
|
|
|
<br/><br/>
|
|
|
|
Memory
|
|
|
|
<br/><br/>
|
|
|
|
<tt class='indentedcode'>fetch-next store-next , s,</tt>
|
|
|
|
<br/><br/>
|
|
|
|
Strings
|
|
|
|
<br/><br/>
|
|
|
|
<tt class='indentedcode'>s:to-number s:eq? s:length</tt>
|
|
|
|
<br/><br/>
|
|
|
|
Flow Control
|
|
|
|
<br/><br/>
|
|
|
|
<tt class='indentedcode'>choose if -if repeat again</tt>
|
|
|
|
<br/><br/>
|
|
|
|
Compiler & Interpreter
|
|
|
|
<br/><br/>
|
|
|
|
<tt class='indentedcode'>Compiler Heap ; [ ] Dictionary</tt>
|
|
|
|
<tt class='indentedcode'>d:link d:class d:xt d:name d:add-header</tt>
|
|
|
|
<tt class='indentedcode'>class:word class:primitive class:data class:macro</tt>
|
2021-03-30 13:58:25 +02:00
|
|
|
<tt class='indentedcode'>sigil:: sigil:# sigil:& sigil:$</tt>
|
2021-01-21 13:40:28 +01:00
|
|
|
<tt class='indentedcode'>interpret d:lookup err:notfound</tt>
|
|
|
|
<br/><br/>
|
|
|
|
Assembler
|
|
|
|
<br/><br/>
|
|
|
|
<tt class='indentedcode'>i d r</tt>
|
|
|
|
<br/><br/>
|
2021-03-30 13:58:25 +02:00
|
|
|
I <strong>could</strong> slightly reduce this. The $ sigil could be defined in
|
2021-01-21 13:40:28 +01:00
|
|
|
higher level code, and I don't strictly <strong>need</strong> to expose the
|
|
|
|
<span class="tt">fetch-next</span> and <span class="tt">store-next</span> 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.
|
|
|
|
<br/><br/>
|
|
|
|
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.
|
|
|
|
<br/><br/>
|
|
|
|
With these words the rest of the language can be built up. Note
|
2021-05-17 19:04:42 +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
|
2021-01-21 13:40:28 +01:00
|
|
|
systems they run on.
|
|
|
|
<br/><br/>
|
|
|
|
There is another small bit. All images start with a few key
|
|
|
|
pointers in fixed offsets of memory. These are:
|
|
|
|
<br/><br/>
|
|
|
|
<tt class='indentedcode'>| Offset | Contains |</tt>
|
|
|
|
<tt class='indentedcode'>| ------ | --------------------------- |</tt>
|
|
|
|
<tt class='indentedcode'>| 0 | lit call nop nop |</tt>
|
|
|
|
<tt class='indentedcode'>| 1 | Pointer to main entry point |</tt>
|
|
|
|
<tt class='indentedcode'>| 2 | Dictionary |</tt>
|
|
|
|
<tt class='indentedcode'>| 3 | Heap |</tt>
|
2021-05-17 19:04:42 +02:00
|
|
|
<tt class='indentedcode'>| 4 | Retro version identifier |</tt>
|
2021-01-21 13:40:28 +01:00
|
|
|
<br/><br/>
|
|
|
|
An interface can use the dictionary pointer and knowledge of the
|
2021-05-17 19:04:42 +02:00
|
|
|
dictionary format for a specific Retro version to identify the
|
2021-01-21 13:40:28 +01:00
|
|
|
location of essential words like <span class="tt">interpret</span> and <span class="tt">err:notfound</span>
|
|
|
|
when implementing the user facing interface.
|
|
|
|
</p>
|
|
|
|
</body></html>
|