Difference between revisions of "Peer-nodal.as"

From Organic Design wiki
(Send execution down if it has FOCUS)
(Handle the ref returned by executed [FUNC])
Line 15: Line 15:
 
// - ROOT.nodes is the current number of instantiated node objects
 
// - ROOT.nodes is the current number of instantiated node objects
 
ROOT = { idcount: 0, nodes: 0 };
 
ROOT = { idcount: 0, nodes: 0 };
NULL = ROOT;
+
VOID = ROOT;
 
INIT = new node( ROOT ); // Default method executed if quanta sent to empty/new association
 
INIT = new node( ROOT ); // Default method executed if quanta sent to empty/new association
 
NEXT = new node( ROOT );
 
NEXT = new node( ROOT );
Line 28: Line 28:
 
this.id = ROOT.idcount++;
 
this.id = ROOT.idcount++;
 
this.set( [FOCUS], key.get( [INIT] ) );
 
this.set( [FOCUS], key.get( [INIT] ) );
};
+
}
  
 
// NODAL METHODS
 
// NODAL METHODS
Line 39: Line 39:
  
 
node.prototype.set( path, value ) {
 
node.prototype.set( path, value ) {
ptr = this._resolve( path );
+
var ptr = this._resolve( path );
 
ptr.value = value;
 
ptr.value = value;
 
};
 
};
  
 
node.prototype.get( path ) {
 
node.prototype.get( path ) {
ptr = this._resolve( path );
+
var ptr = this._resolve( path );
 
// need to return class.value onNonExistent
 
// need to return class.value onNonExistent
 
return ptr.value;
 
return ptr.value;
Line 67: Line 67:
 
//  the structures necessary to build the fucntion are child assocs too
 
//  the structures necessary to build the fucntion are child assocs too
 
node.prototype.reduce = function() {
 
node.prototype.reduce = function() {
var ptr = this;
 
  
 
// Rotate this level's queue
 
// Rotate this level's queue
var focus = ptr.get( [FOCUS] );
+
var ptr = this.get( [FOCUS] );
ptr.set( [FOCUS], ptr.get( [FOCUS,NEXT] ) );
+
this.set( [FOCUS], this.get( [FOCUS,NEXT] ) );
  
 
// If there's a local function declaration, execute
 
// If there's a local function declaration, execute
if ( func = focus.get( [FUNC] ) ) {
+
if ( var ref = ptr.get( [FUNC] ) ) {
ref = func.call
+
ref = ref.call;
// also call class.reduce()
+
if ( ref == VOID ) {
 +
// Remove focus from loop
 +
ptr.set( [NEXT,PREV], ptr.get( [PREV] ) ); // ptr.next.prev = ptr.prev
 +
ptr.set( [PREV,NEXT], ptr.get( [NEXT] ) ); // ptr.prev.next = ptr.next
 +
}
 +
else if ( ref != ptr ) {
 +
// Replace current ptr with result-ref
 +
ref.set( [NEXT], ptr.get( [NEXT] ) ); // ref.next = ptr.next
 +
ref.set( [PREV], ptr.get( [PREV] ) ); // ref.prev = ptr.prev
 +
ptr.set( [NEXT,PREV], ref ); // ptr.next.prev = ref
 +
ptr.set( [PREV,NEXT], ref ); // ptr.prev.next = ref
 +
}
 +
}
 +
 
 +
// also call class.reduce
 +
 
 
};
 
};
  
 
// if not, send the quanta downstairs if there's anything in its loop
 
// if not, send the quanta downstairs if there's anything in its loop
else if ( focus = focus.get( [FOCUS] ) != NULL ) focus.reduce();
+
else if ( ptr = ptr.get( [FOCUS] ) != VOID ) ptr.reduce;
  
 
};
 
};

Revision as of 10:06, 10 April 2006

// Liscenced under LGPL: www.gnu.org/copyleft/lesser.html // // peer-nodal.as - ecma-script implimentation of the nodal core // Nad - 2006 //

// ISSUES // - associations (maintained class:instance relationships) // - get should use class content as default - resolve() doesn't // so either add get/set which use resolve, or remove object-freedom and have only .data

// NODAL PROPERTIES & CORE NODAL CONCEPTS // - all-capital-identifiers are node-references // - ROOT.idcount is a accumulating-only counter for locally-unique-id number // - ROOT.nodes is the current number of instantiated node objects ROOT = { idcount: 0, nodes: 0 }; VOID = ROOT; INIT = new node( ROOT ); // Default method executed if quanta sent to empty/new association NEXT = new node( ROOT ); PREV = new node( ROOT ); FUNC = new node( ROOT ); FOCUS = new node( ROOT );

// NODE OBJECT // - note: only a node's parent can adjust a nodes prev/next function node( key ) { ROOT.nodes++; this.id = ROOT.idcount++; this.set( [FOCUS], key.get( [INIT] ) ); }

// NODAL METHODS // - the delete-list is only needed for limited list-space env // - Actionscript failed ref-as-hashkey test, // so we use a id (locally unique identifier) as a lookup-key // - no delete currently // - just get/set properties with normal object-accessor way // - but keep all hierarchy nodal

node.prototype.set( path, value ) { var ptr = this._resolve( path ); ptr.value = value; };

node.prototype.get( path ) { var ptr = this._resolve( path ); // need to return class.value onNonExistent return ptr.value; };

// Resolve creates if non existent and returns reference to result // - this is private, used by get/set node.prototype._resolve = function( path ) { var context = this; while( path.length ) { var key = path.shift(); context = context[key.id] == null ? context[key.id] = new node( key ) : context[ key.id ]; } return context; };

// Consume one quanta // - each quantum is actually two, one for local instance, one for global class // - all instance-loops work by going cd this.current then assigning this.current.next to it // when a function executes, it can update the loop at that location (equiv to array.push) // - a functions parameters (and even further methods and tools) are child associations // the structures necessary to build the fucntion are child assocs too node.prototype.reduce = function() {

// Rotate this level's queue var ptr = this.get( [FOCUS] ); this.set( [FOCUS], this.get( [FOCUS,NEXT] ) );

// If there's a local function declaration, execute if ( var ref = ptr.get( [FUNC] ) ) { ref = ref.call; if ( ref == VOID ) { // Remove focus from loop ptr.set( [NEXT,PREV], ptr.get( [PREV] ) ); // ptr.next.prev = ptr.prev ptr.set( [PREV,NEXT], ptr.get( [NEXT] ) ); // ptr.prev.next = ptr.next } else if ( ref != ptr ) { // Replace current ptr with result-ref ref.set( [NEXT], ptr.get( [NEXT] ) ); // ref.next = ptr.next ref.set( [PREV], ptr.get( [PREV] ) ); // ref.prev = ptr.prev ptr.set( [NEXT,PREV], ref ); // ptr.next.prev = ref ptr.set( [PREV,NEXT], ref ); // ptr.prev.next = ref } }

// also call class.reduce

};

// if not, send the quanta downstairs if there's anything in its loop else if ( ptr = ptr.get( [FOCUS] ) != VOID ) ptr.reduce;

};