Difference between revisions of "NR.c"

From Organic Design wiki
(simplify for example)
(fix HL)
 
(11 intermediate revisions by the same user not shown)
Line 1: Line 1:
// Moves "this" to node's [[[[focus]]]] if exists then rotates [[[[loop]]]] and executes/reduces the focus item
+
<source lang="c">
 +
// Moves "this" to node's focus if exists then rotates loop and executes/reduces the focus item
 
void nodeReduce() {
 
void nodeReduce() {
this = listGetValue(loop = this);                    // Move "this" to the [[[[focus]]]] in the node's [[[[loop]]]]
+
    if(this = nodeLoopRotate(parent = this)) {        // Move "this" to the focus in the node's loop and rotate
if (this) {                                          // Returns immediately if no node in focus (next [[[[quantum]]]] would start at [[[[nodeROOT|root]]]] again)
+
        nodeSetValue(this, nodePARENT, parent);       // Update the parent association
listSetValue(loop,nodeGetValue(this,nodeNEXT));   // Rotate the loop
+
        if(code = *nodeState(this, nodeCODE)) code(); // nodeCODE value is a pointer-index, execute as function-reference if non-zero
code *ptr = *nodeState(this,nodeCODE);           // [[[[nodeCODE|nodeCODE's]]]] state is either NULL, or a pointer to a function
+
    }
if (ptr) ptr(); else nodeReduce();                // Execute ptr if non-NULL, else [[[[reduce]]]] item (give quantum to focus to reduce)
+
}</source>
}
 
}
 

Latest revision as of 00:32, 26 May 2016

// Moves "this" to node's focus if exists then rotates loop and executes/reduces the focus item
void nodeReduce() {
    if(this = nodeLoopRotate(parent = this)) {        // Move "this" to the focus in the node's loop and rotate
        nodeSetValue(this, nodePARENT, parent);       // Update the parent association
        if(code = *nodeState(this, nodeCODE)) code(); // nodeCODE value is a pointer-index, execute as function-reference if non-zero
    }
}