Jump anywhere: Difference between revisions

Content added Content deleted
m (syntax highlighting fixup automation)
(fix <code> issue)
Line 2,428: Line 2,428:
Quackery is an assembler insomuch as there is a direct, one to one, left to right correspondence between Quackery source code and the contents of the resultant nest, which is convenient. (There are a few simple-to-understand exceptions, and of course because the assembler is extensible, you can add more of those if you like, but generally it's easy to figure out where a specific item is in the nest.
Quackery is an assembler insomuch as there is a direct, one to one, left to right correspondence between Quackery source code and the contents of the resultant nest, which is convenient. (There are a few simple-to-understand exceptions, and of course because the assembler is extensible, you can add more of those if you like, but generally it's easy to figure out where a specific item is in the nest.


As an example, this creates the control-flow word <code>jump-into</code>, which will start evaluation of a nest a specified distance in. <code>done</code> causes evaluation of the nest to terminate early (via <code>]done[</code>, which removes a pointer-offset pair from the call stack) and <code>again</code> causes a jump to the start of the nest. (<code>]again[ sets the number in the pair on the top of the call stack to 0.) So <code>5 jump-into</code> should start at item number 5 in the nest that follows it, echoing the numbers 2 and 3 to the screen, then branch back to the start end echo the numbers 0 and 1, then terminate.
As an example, this creates the control-flow word <code>jump-into</code>, which will start evaluation of a nest a specified distance in. <code>done</code> causes evaluation of the nest to terminate early (via <code>]done[</code>, which removes a pointer-offset pair from the call stack) and <code>again</code> causes a jump to the start of the nest. (<code>]again[</code> sets the number in the pair on the top of the call stack to 0.) So <code>5 jump-into</code> should start at item number 5 in the nest that follows it, echoing the numbers 2 and 3 to the screen, then branch back to the start end echo the numbers 0 and 1, then terminate.


To achieve this, <code>]'[</code> advances the offset on top of the return stack, like <code>]else[</code>, but also puts a copy of the item skipped over on the stack. (i.e. the nest following <code>jump-into</code> in the example) It puts this, with an offset of 0, onto the call stack (with <code>]do[</code>. Then it uses <code>' ]else[ swap of</code> to build a nest of the specified number of instances of <code>]else[</code>, and puts that on the call stack, so that it will be evaluated after exiting <code>jump-to</code>, and increment the offset of the top of the call stack (i.e. the nest following <code>jump-to</code>) that number of times.
To achieve this, <code>]'[</code> advances the offset on top of the return stack, like <code>]else[</code>, but also puts a copy of the item skipped over on the stack. (i.e. the nest following <code>jump-into</code> in the example) It puts this, with an offset of 0, onto the call stack (with <code>]do[</code>. Then it uses <code>' ]else[ swap of</code> to build a nest of the specified number of instances of <code>]else[</code>, and puts that on the call stack, so that it will be evaluated after exiting <code>jump-to</code>, and increment the offset of the top of the call stack (i.e. the nest following <code>jump-to</code>) that number of times.