Difference between revisions of "NodeSpace.h"

From Organic Design wiki
(use more compact execution syntax tested in sandbox.c)
(Start filling in nodal functions)
Line 11: Line 11:
 
typedef void (*code)(); // code: a type for referring to functions
 
typedef void (*code)(); // code: a type for referring to functions
  
node nodeTraverse(node subject, node path) {
+
// - path is array-of-node
 +
node nodeTraverse(node subject,node *path) {
 
// select node wco selNode
 
// select node wco selNode
 
return subject;
 
return subject;
Line 17: Line 18:
  
 
// set nodal value of node/path
 
// set nodal value of node/path
// - path is array-of-node
+
node nodeGetValue(node subject,node key) {
node nodeGetValue(node subject, node path) {
+
return listGetValue((item)listTraverse((item)subject,(item)key));
node value;
 
return value;
 
 
}
 
}
  
void nodeSetValue(node subject, node path, node value) {
+
void nodeSetValue(node subject,node key,node value) {
 +
// todo: onChange
 +
return listSetValue((item)listTraverse((item)subject,(item)key),(item)value);
 
}
 
}
  
void* nodeGetState(node subject) {
+
// Not very efficient using text-trie, but good enough for now
void* state;
+
void *nodeGetState(node subject) {
return state;
+
return trieGetValue(itoa((int)subject));
 
}
 
}
  
void nodeSetState(node subject, void* state) {
+
void *nodeSetState(node subject, void *state) {
 +
return trieSetValue(itoa((int)subject),state);
 
}
 
}
  
 
node nodeInsertKey(node subject, node key) {
 
node nodeInsertKey(node subject, node key) {
 +
// todo: onInstall
 
node instance;
 
node instance;
 
return instance;
 
return instance;
Line 40: Line 43:
  
 
void nodeRemoveKey(node subject, node key) {
 
void nodeRemoveKey(node subject, node key) {
 +
// todo: onRemove
 
}
 
}
  

Revision as of 00:15, 14 July 2006

  1. define ROOT 0
  2. define NULL 0
  3. define CURRENT 1
  4. define AND 2
  5. define CODE 3
  6. define THEN 4
  7. define NETWORK 5
  8. define DESKTOP 6

typedef int node; // node: a type for referring to nodes typedef void (*code)(); // code: a type for referring to functions

// - path is array-of-node node nodeTraverse(node subject,node *path) { // select node wco selNode return subject; }

// set nodal value of node/path node nodeGetValue(node subject,node key) { return listGetValue((item)listTraverse((item)subject,(item)key)); }

void nodeSetValue(node subject,node key,node value) { // todo: onChange return listSetValue((item)listTraverse((item)subject,(item)key),(item)value); }

// Not very efficient using text-trie, but good enough for now void *nodeGetState(node subject) { return trieGetValue(itoa((int)subject)); }

void *nodeSetState(node subject, void *state) { return trieSetValue(itoa((int)subject),state); }

node nodeInsertKey(node subject, node key) { // todo: onInstall node instance; return instance; }

void nodeRemoveKey(node subject, node key) { // todo: onRemove }

// - 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 // - returns false if no more to reduce int nodeReduce(node subject) { node cur; if ((cur = nodeGetValue(subject, CURRENT)) == NULL) return; // return if no CURRENT node nodeSetValue(subject, CURRENT, nodeGetValue(cur, AND)); // test AND first? if (nodeGetValue(cur, CODE) != NULL) { ((code)nodeGetState(cur))(); // execute code-ref returned in state // Later this must declare and build if no function-reference // replace self in loop with n.THEN if non-zero } else nodeReduce(cur); return 1; }