Fixed a couple prelude bugs

This commit is contained in:
2023-01-02 14:27:00 -06:00
parent 2dea244673
commit 4de3bd5c0c
3 changed files with 12 additions and 3 deletions
+5 -3
View File
@@ -2,11 +2,11 @@
: then resolve ; immediate
: else r> $ jmpr >asm >r resolve ; immediate
: variable create 0 , does> ;
: arshift $ arshift asm ;
: arshift [ $ arshift asm ] ;
: lshift [ $ lshift asm ] ;
: rshift [ $ rshift asm ] ;
: u> [ $ gt ] asm ;
: u< [ $ lt ] asm ;
: u> [ $ gt asm ] ;
: u< [ $ lt asm ] ;
: rdrop r> pop ;
: over 1 pick ;
: nip swap pop ;
@@ -23,3 +23,5 @@
: ror dup 1 rshift swap 23 lshift | ;
: rol dup 23 rshift swap 1 lshift | ;
: abs dup 0 < if negate then ;
: begin here >r ; immediate
: until r> here - $ brz #asm ; immediate
+1
View File
@@ -31,4 +31,5 @@ td.word, td.signature {
font-family: monospace;
font-weight: bold;
padding-right: 1em;
white-space: nowrap;
}
+6
View File
@@ -55,6 +55,11 @@
that number plus one; if it's even, it returns half that number. The ".s" word prints the stack without modifying
it and is a useful debugging tool.
</p>
<p>
<pre>: countdown begin dup . ." ... " 1 - dup not until pop ;
10 countdown</pre>
Demonstrating a loop, this program counts from its argument down to 1.
</p>
<h3>NovaForth Dictionary</h3>
<h4>Arithmetic and stack juggling</h4>
<table>
@@ -128,6 +133,7 @@
<tr><td class="word">not</td><td class="signature">a -- b</td><td class="meaning">If the argument is a 0, returns 1. Otherwise returns 0</td></tr>
<tr><td class="word">compare</td><td class="signature">a b -- c</td><td class="meaning">Compares two strings for equality, returns 1 if they're equal and 0 otherwise</td></tr>
<tr><td class="word">if / else / then</td><td class="signature">cond --</td><td class="meaning">A conditional branch: "<em>condition</em> if <em>truepath</em> else <em>falsepath</em> then". The "else" branch is optional (prelude words)</td></tr>
<tr><td class="word">begin / until</td><td class="signature">cond --</td><td class="meaning">A post-test loop: "until" jumps back to the corresponding "begin" as long as top of stack is 0 (prelude words)</td></tr>
</table>
<h4>Memory management</h4>
<table>