From bc94e648a9068411a2e49974c00f79f769e0ac1b Mon Sep 17 00:00:00 2001 From: crc Date: Tue, 10 Dec 2019 19:14:57 +0000 Subject: [PATCH] start expanding high level equals to the assembly in rx.muri FossilOrigin-Name: a00ce099dcc63593f3fd4368576f5af96d45d6a208a84b5f14c06864ab4cf353 --- image/rx.muri | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/image/rx.muri b/image/rx.muri index 38b6b84..e443140 100644 --- a/image/rx.muri +++ b/image/rx.muri @@ -312,6 +312,8 @@ address. `fetch-next` takes an address and fetches the stored value. It returns the next address and the stored value. + :fetch-next dup #1 + swap fetch ; + ~~~ : fetch-next i duliadsw @@ -322,6 +324,8 @@ i fere.... `store-next` takes a value and an address. It stores the value to the address and returns the next address. + :store-next dup #1 + push store pop ; + ~~~ : store-next i duliadpu @@ -348,6 +352,10 @@ Note that this requires that the flags be -1 (for TRUE) and 0 (for FALSE). It's possible to make this more flexible, but at a significant performance hit, so I'm leaving it this way. + :choose + &choice:false store &choice:true store + &choice:false + fetch call ; + ~~~ : choice:true d 0 @@ -367,6 +375,9 @@ i re...... Next the two *if* forms. Note that `-if` falls into `if`. This saves two cells of memory. + :-if push #0 eq? pop \cc...... ; + :if \cc...... ; + ~~~ : -if i pulieqpo @@ -395,6 +406,9 @@ First up, string length. The process here is trivial: * When done subtract the original address from the current one * Then subtract one (to account for the zero terminator) + :count repeat fetch-next 0; drop again ; + :s:length dup count #1 - swap - ; + ~~~ : count i lica.... @@ -459,6 +473,8 @@ The heart of the compiler is `comma` which stores a value into memory and increments a variable (`Heap`) pointing to the next free address. + :, &Heap fetch store-next &Heap store ; + ~~~ : comma i lifelica @@ -478,6 +494,8 @@ This performs a jump to the `comma` word instead of using a `call/ret` to save a cell and slightly improve performance. I will use this technique frequently. + :comma:opcode fetch , ; + ~~~ : comma:opcode i feliju.. @@ -527,6 +545,9 @@ Next is *semicolon*; which compiles the code to terminate a function and sets the `Compiler` to an off state (0). This just needs to compile in a RET. + :compiler:off #0 &Compiler store ; + :; &_ret comma:opcode compiler:off ; immediate + ~~~ : ; i lilica.. @@ -553,6 +574,8 @@ Rx provides several classes with differing behaviors: | -------------------- | ----------------------------- | | leave value on stack | compile value into definition | + :class:data &Compiler fetch 0; drop &_lit comma:opcode comma ; + ~~~ : class:data i lifezr..