Difference between revisions of "NodeSpace.h"

From Organic Design wiki
(change variant to void*)
m
Line 3: Line 3:
 
#define THEN 4
 
#define THEN 4
 
#define CODE 5
 
#define CODE 5
 +
typedef int node;
  
int nodeTraverse(int subject, int path) {
+
node nodeTraverse(node subject, node path) {
 
// select node wco selNode
 
// select node wco selNode
 
return subject;
 
return subject;
Line 11: Line 12:
 
// set nodal value of node/path
 
// set nodal value of node/path
 
// - path is array-of-node
 
// - path is array-of-node
int nodeGetValue(int subject, int path) {
+
node nodeGetValue(node subject, node path) {
int value;
+
node value;
 
return value;
 
return value;
 
}
 
}
  
void nodeSetValue(int subject, int path, int value) {
+
void nodeSetValue(node subject, node path, node value) {
 
}
 
}
  
// PROBLEM:
+
void* nodeGetState(node subject) {
// - currently this code assumes all states are text,
 
//  but we need to be able to return function references too.
 
// - not sure how to handle this in C++ properly,
 
//  we could get state to return a struct with STRING, INT, CODE
 
//  the caller knows which field is populated
 
void* nodeGetState(int subject) {
 
 
void* state;
 
void* state;
 
return state;
 
return state;
 
}
 
}
  
void nodeSetState(int subject, void* state) {
+
void nodeSetState(node subject, void* state) {
 
}
 
}
  
int nodeInsertKey(int subject, int key) {
+
node nodeInsertKey(node subject, node key) {
int instance;
+
node instance;
 
return instance;
 
return instance;
 
}
 
}
  
void nodeRemoveKey(int subject, int key) {
+
void nodeRemoveKey(node subject, node key) {
 
}
 
}
  
Line 45: Line 40:
 
// - Builds, declares and executes functionality
 
// - Builds, declares and executes functionality
 
// - Should reduction handle cyles (current-cycle etc), or a separate root-thread
 
// - Should reduction handle cyles (current-cycle etc), or a separate root-thread
void nodeReduce(int subject) {
+
void nodeReduce(node subject) {
 
// return if no CURRENT node (either nonexistent, or ref to node 0)
 
// return if no CURRENT node (either nonexistent, or ref to node 0)
int node;
+
node n;
if ((node = nodeGetValue(subject, CURRENT)) == 0) return;
+
if ((n = nodeGetValue(subject, CURRENT)) == 0) return;
nodeSetValue(subject, CURRENT, nodeGetValue(node, AND));
+
nodeSetValue(subject, CURRENT, nodeGetValue(n, AND));
if (nodeGetValue(node, CODE)) {
+
if (nodeGetValue(n, CODE)) {
void (*code)() = nodeGetState(node);
+
void (*code)() = nodeGetState(n);
 
code();
 
code();
 
// Later this must declare and build if no function-reference
 
// Later this must declare and build if no function-reference
// replace self in loop with node.THEN if non-zero
+
// replace self in loop with n.THEN if non-zero
} else nodeReduce(node);
+
} else nodeReduce(n);
 
}
 
}

Revision as of 12:40, 5 July 2006

  1. define CURRENT 2
  2. define AND 3
  3. define THEN 4
  4. define CODE 5

typedef int node;

node nodeTraverse(node subject, node path) { // select node wco selNode return subject; }

// set nodal value of node/path // - path is array-of-node node nodeGetValue(node subject, node path) { node value; return value; }

void nodeSetValue(node subject, node path, node value) { }

void* nodeGetState(node subject) { void* state; return state; }

void nodeSetState(node subject, void* state) { }

node nodeInsertKey(node subject, node key) { node instance; return instance; }

void nodeRemoveKey(node subject, node key) { }

// - Consumes quanta of execution // - Creates History from change events // - Builds, declares and executes functionality // - Should reduction handle cyles (current-cycle etc), or a separate root-thread void nodeReduce(node subject) { // return if no CURRENT node (either nonexistent, or ref to node 0) node n; if ((n = nodeGetValue(subject, CURRENT)) == 0) return; nodeSetValue(subject, CURRENT, nodeGetValue(n, AND)); if (nodeGetValue(n, CODE)) { void (*code)() = nodeGetState(n); code(); // Later this must declare and build if no function-reference // replace self in loop with n.THEN if non-zero } else nodeReduce(n); }