Core development checkpoint
authorThomas Walker Lynch <eknp9n@reasoningtechnology.com>
Sat, 15 Mar 2025 08:06:29 +0000 (08:06 +0000)
committerThomas Walker Lynch <eknp9n@reasoningtechnology.com>
Sat, 15 Mar 2025 08:06:29 +0000 (08:06 +0000)
developer/cc馃枆/Core.lib.c
developer/cc馃枆/Core_scratch.c

index 11e5fe8..fbf690e 100644 (file)
     #define AU uint8_t
 
   //----------------------------------------
-  // model
+  // argument guard
+
+
+typedef void (*Flag路Function)(uint8_t *flag ,uint err);
+
+void Core路Flag路count(uint8_t *flag ,uint err){
+  if(err >= 0xFF){*flag = 0xFF; return;}
+  //*flag + err > 0xFF
+  if(*flag > 0xFF - err){flag = 0xFF;  return;}
+  (*flag) += err;
+}
+
+void Core路Flag路collect(uint8_t *flag ,uint err){
+  (*flag) |= err;
+}
+
+typedef struct {
+  Flag路Function flag_function;
+  uint8_t flag;
+} Core路Guard;
+
+typedef struct {
+  void (*init)(Core路Guard *chk ,Core路Flag路Function *af);
+  void (*reset)(Core路Guard *chk);
+  void (*check)(Core路Guard *chk ,unint err ,bool condition ,const char *message);
+} Core路Guard路FG;
+
+// a default guard
+Local Core路Guard路FG Core路Guard路fg = {
+  .init =
+  ,.reset =
+  ,.check = 
+}
+
+typedef void (*Flag路Function)(uint8_t *flag ,uint err);
+
+void Core路Flag路count(uint8_t *flag ,uint err){
+  if( err >= 0xFF ){ *flag = 0xFF; return;}
+
+  //*flag + err > 0xFF
+  if( *flag > 0xFF - err ){ *flag = 0xFF; return;}
+
+  (*flag) += err;
+}
+
+void Core路Flag路collect(uint8_t *flag ,uint err){
+  (*flag) |= err;
+}
+
+typedef struct {
+  Flag路Function flag_function;
+  uint8_t flag;
+} Core路Guard;
+
+typedef struct {
+  void (*init)(Core路Guard *chk ,Flag路Function af);
+  void (*reset)(Core路Guard *chk);
+  void (*check)(
+     Core路Guard *chk
+    ,uint err
+    ,bool condition
+    ,const char *message
+  );
+} Core路Guard路FG;
+
+// Default guard function table
+Local Core路Guard路FG Core路Guard路fg = {
+   .init = Core路Guard路init
+  ,.reset = Core路Guard路reset
+  ,.check = Core路Guard路check
+};
+
+// Implementation
+
+void Core路Guard路init(Core路Guard *chk ,Flag路Function af){
+  if( !chk ) return;
+  chk->flag_function = af;
+  chk->flag = 0;
+}
+
+void Core路Guard路reset(Core路Guard *chk){
+  if( !chk ) return;
+  chk->flag = 0;
+}
+
+void Core路Guard路check(
+   Core路Guard *chk
+  ,uint err
+  ,bool condition
+  ,const char *message
+){
+  if( !chk || !chk->flag_function ) return;
+  if( condition ) return;
+  fprintf(stderr ,"%s\n" ,message);
+  chk->flag_function(&chk->flag ,err);
+}
+
+
+
+  //----------------------------------------
+  // functions
 
     // no state, this is merely a namespace
 
       void *(*floor_within_aligned_8AU)(void *p);
       void *(*ceiling_within_aligned_8AU)(void *p);
 
-    } Core路U;
-
-    Local Core路U Core路u;
+    } Core路F;
 
+    Local Core路F Core路f;
 
   //----------------------------------------
   // Tape Machine
 
     typedef struct Core路TM_NX;
     typedef struct Core路TM_NX路Address;
+    typedef struct Core路TM_NX路Remote;
 
     typedef enum{
        Core路Tape路Topo路mu
 
     typedef struct{
 
-      Core路Status (*mount)(Core路TM_NX *tm);
-      Core路Status (*dismount)(Core路TM_NX *tm);
-      Core路Status (*rewind)(Core路TM_NX *tm);
+      // these are for types that need initialization and cleanup
+      Core路TM路Head路Status (*mount)(Core路TM_NX *tm);
+      Core路TM路Head路Status (*dismount)(Core路TM_NX *tm);
 
+      Core路TM路Head路Status (*status)(Core路TM_NX *tm);
       Core路Status (*can_step)(Core路TM_NX *tm ,bool *flag);
+      Core路Status (*can_read)(Core路TM_NX *tm ,bool *flag);
+
       Core路Status (*on_origin)(Core路TM_NX *tm ,bool *flag);
+      // only for bounded tapes
       Core路Status (*on_rightmost)(Core路TM_NX *tm ,bool *flag);
 
-      Core路Status (*extent)(Core路TM_NX *tm ,extent_t *extent_pt);
-      Core路Status (*can_read)(Core路TM_NX *tm ,bool *flag);
+      Core路Status (*read)(
+        Core路TM_NX *tm 
+        ,Core路TM_NX路Address *a 
+        ,Core路Tape路Remote *remote
+      );
+      Core路Status (*write)(
+        Core路TM_NX *tm 
+        ,Core路TM_NX路Address *a 
+        ,Core路Tape路Remote *remote
+      );
 
+      Core路Status (*rewind)(Core路TM_NX *tm);
       Core路Status (*step)(Core路TM_NX *tm);
       Core路Status (*step_left)(Core路TM_NX *tm);
       Core路Status (*step_right)(Core路TM_NX *tm); // Synonym for step
-      Core路TM路Head路Status (*status)(Core路TM_NX *tm);
 
       struct {
         Core路Tape路Topo (*topo)(Core路TM_NX *tm);
-        Core路Status (*extent)(Core路TM_NX *tm ,extent_t *write_pt);
-        Core路Status (*is_origin)(Core路TM_NX *tm ,Core路TM_NX路Address *a ,bool *result);
-        Core路Status (*is_rightmost)(Core路TM_NX *tm ,Core路TM_NX路Address *a ,bool *result);
-        Core路Status (*read)(Core路TM_NX *tm ,Core路TM_NX路Address *a ,Core路Tape路Remote *remote);
-        Core路Status (*write)(Core路TM_NX *tm ,Core路TM_NX路Address *a ,Core路Tape路Remote *remote);
+        Core路Status (*extent)(Core路TM_NX *tm ,extent_t *extent_pt);
 
         // Initialize TM area
-        Core路Status (*init_pe)(Core路TM_NX *tm ,void *position ,extent_t extent);
-        Core路Status (*init_pp)(Core路TM_NX *tm ,void *position_left ,void *position_right);
         Core路Status (*set_position)(Core路TM_NX *tm ,Core路TM_NX路Address *new_position);
         Core路Status (*set_position_left)(Core路TM_NX *tm ,Core路TM_NX路Address *new_position); // synonym
         Core路Status (*set_position_right)(Core路TM_NX *tm ,Core路TM_NX路Address *new_position_right);
         Core路Status (*set_extent)(Core路TM_NX *tm ,extent_t extent); 
 
+        Core路Status (*mount_pe)(Core路TM_NX *tm ,void *position ,extent_t extent);
+        Core路Status (*mount_pp)(Core路TM_NX *tm ,void *position_left ,void *position_right);
+        Core路Status (*dismount)(Core路TM_NX *tm);
+
         // Read TM properties
         Core路TM_NX路Address *(*position)(Core路TM_NX *tm);
         Core路TM_NX路Address *(*position_left)(Core路TM_NX *tm); // synonym
 
     } Core路TM_NX路FG;
 
-  //----------------------------------------
-  // Tape Machine
-
-    typedef struct Core路TM_NX;
-    typedef struct Core路TM_NX路Address;
-
-    typedef enum{
-       Core路Tape路Topo路mu
-      ,Core路Tape路Topo路nonexistent // pointer to tape is NULL
-      ,Core路Tape路Topo路empty      // tape has no cells
-      ,Core路Tape路Topo路singleton  // extent is zero
-      ,Core路Tape路Topo路segment    // finite non-singleton tape
-      ,Core路Tape路Topo路circle     // initial location recurs
-      ,Core路Tape路Topo路tail_cyclic  // other than initial location recurs
-      ,Core路Tape路Topo路infinite   // exists, not empty, no cycle, no rightmost
-    }Core路Tape路Topo;
-
-    // If tape machine does not support step left, then Status路leftmost 
-    // will be reported as Status路interim.
-    typedef enum{
-       Core路TM路Head路Status路mu = 0
-      ,Core路TM路Head路Status路not_on_tape = 1
-      ,Core路TM路Head路Status路origin
-      ,Core路TM路Head路Status路interim 
-      ,Core路TM路Head路Status路rightmost
-    } Core路TM路Head路Status;
-
-    typedef struct{
-
-      Core路Status mount(Core路TM_NX *tm);
-      Core路Status dismount(Core路TM_NX *tm);
-      Core路Status rewind(Core路TM_NX *tm);
-
-      Core路Tape路Extent路Status (*can_step)(Core路TM_NX *tm ,bool *flag);
-      Core路Tape路Extent路Status (*on_origin)(Core路TM_NX *tm ,bool *flag);
-      Core路Tape路Extent路Status (*on_rightmost)(Core路TM_NX *tm ,bool *flag);
-
-      Core路Tape路Extent路Status (*extent)(Core路TM_NX *tm ,extent_t *extent_pt);
-      Core路Status can_read(bool *flag);
-      Core路Status can_step(bool *flag);
-
-      Core路Status step(Core路TM_NX *tm);
-      Core路Status step_left(Core路TM_NX *tm);
-      Core路Status step_right(Core路TM_NX *tm); // Synonym for step
-      Core路TM路Head路Status status(Core路TM_NX *tm);
-
-      struct{
-        Core路Tape路Topo (*topo)(Core路TM_NX *tm);
-        Core路Tape路Extent路Status (*extent)(Core路TM_NX *tm ,extent_t *write_pt);
-        Core路Status (*is_leftmot)(Core路Tape *tape ,Core路Tape路Address *a ,bool *result);
-        Core路Status (*is_rightmost)(Core路Tape *tape ,Core路Tape路Address *a ,bool *result);
-        Core路Status (*read)(Core路TM_NX *tm ,Core路Tape路Address *a ,Core路Tape路Remote *remote);
-        Core路Status (*write)(Core路TM_NX *tm ,Core路Tape路Address *a ,Core路Tape路Remote *remote);
-
-        // initialize tm area
-        Core路Status (*init_pe)(Core路TM_NX *tm ,void *position ,extent_t extent);
-        Core路Status (*init_pp)(Core路TM_NX *tm ,void *position_left ,void *position_right);
-        Core路Status (*set_position)(Core路TM_NX *tm ,Core路TM_NX路Address *new_position);
-        Core路Status (*set_position_left)(Core路TM_NX *tm ,Core路TM_NX路Address *new_position); // synonym
-        Core路Status (*set_position_right)(Core路TM_NX *tm ,Core路TM_NX路Address *new_position_right);
-        Core路Status (*set_extent)(Core路TM_NX *tm ,extent_t extent); 
-
-        // read tm properties
-        Core路TM_NX路Address *(*position)(Core路TM_NX *tm);
-        Core路TM_NX路Address *(*position_left)(Core路TM_NX *tm); // synonym
-        Core路TM_NX路Address *(*position_right)(Core路TM_NX *tm);
-
-        Core路TM_NX路Address *(*complement)(Core路TM_NX *tm ,Core路TM_NX路Address *r);
-
-        // tm relationships
-        bool (*encloses_pt)(Core路TM_NX *tm ,Core路TM_NX路Address *pt);
-        bool (*encloses_pt_strictly)(Core路TM_NX *tm ,Core路TM_NX路Address *pt);
-        bool (*encloses_tm)(Core路TM_NX *outer ,Core路TM_NX *inner);
-        bool (*encloses_tm_strictly)(Core路TM_NX *outer ,Core路TM_NX *inner);
-        bool (*overlap)(Core路TM_NX *a ,Core路TM_NX *b);
-        void (*largest_aligned_64)(Core路TM_NX *outer ,Core路TM_NX *inner_64);
-
-      }area;
-
-    } Core路TM_NX路FG;
-
-    // Default functions given a Tape Machine
-    Local Core路TM_NX路FG Core路TM_NX路fg;
 
   //----------------------------------------
   // Map
     };
 
   //----------------------------------------
-  // Tape model, default implementation based on an array
+  // TM_NX 
 
-    typedef struct{
-      void *address;
-    }Core路Tape路Address;
-    Local Core路Tape路Address Core路Tape路address = {
-      .address = NULL
-    }
+    typedef union{
+      struct{
+        void *address;
+      }array;
+    }Core路TM_MX路Address;
 
-    typedef struct{
-      void *address;
-    }Core路Tape路Remote;
-    Local Core路Tape路Remote Core路Tape路remote = {
-      .address = NULL
-    }
+    typedef union{
+      struct{
+        AU *position;
+        extent_t extent;
+        AU *hd;
+      }array;
+      struct{
+        uint64_t *position;
+        extent_t extent;
+        uint64_t *hd;
+      }array8AU;
+    }Core路TM_MX;
 
-    typedef struct{
-      AU *position;
-      extent_t extent;
-    }Core路Tape;
-
-    Local Core路Tape路Topo Core路Tape路topo(Core路Tape *tape){
-      if(!tape) return Core路Area路Topo路nonexistent;
-      if(!tape->position) return Core路Area路Topo路empty;
-      if(!tape->extent) return Core路Area路Topo路singleton;
-      return Core路Area路Topo路segment;
+    //----------------------------------------
+    // TM_NX_Array: Array-Based Implementation
+
+    Core路TM路Head路Status *Core路TM_NX_Array路mount(Core路TM_NX *tm){
+    }
+    Core路TM路Head路Status *Core路TM_NX_Array路dismount(Core路TM_NX *tm){
     }
 
-    Local Core路Status Core路Tape路extent(Core路Tape *tape ,extent_t *write_pt){
-      #ifdef Core路Debug
-        uint error = 0;
-        if(!tape){
-          fprintf(stderr,"Core路Tape路extent:: given NULL tape");
-          error++;
-        }else if(!tape->position){
-          fprintf(stderr,"Core路Tape路extent:: extent requested for a marked as empty tape");
-          error++;
-        }
-        if(!write_pt){
-          fprintf(stderr,"Core路Tape路extent:: given NULL write_pt");
-          error++;
-        }
-        if(error) return Core路Status路derailed;
-      #endif
-      return tape->extent;
-    }    
+    Core路TM路Head路Status Core路TM_NX_Array路status(Core路TM_NX *tm){
+    }
+    Local Core路Status Core路TM_NX_Array路can_step(Core路TM_NX *tm ,bool *){
+    }
+    Local Core路Status Core路TM_NX_Array路can_read(Core路TM_NX *tm ,bool *){
+    }
 
-    Local bool Core路Area路action.encloses_pt(Core路Area *area ,AU *pt);
+    bool Core路TM_NX_Array路encloses_pt(Core路TM_NX *tm ,Core路TM_NX路Address *pt);
 
-    // a must be on tape
-    Local Core路Status Core路Tape路is_leftmost(
-      Core路Tape *tape ,Core路Tape路Address *a ,bool *result
+    Local Core路Status Core路TM_NX_Array路on_origin(
+      Core路TM_NX *tm ,Core路TM_NX路Address *a ,bool *flag
     ){
       #ifdef Core路Debug
         uint error = 0;
-        if(!tape){
-          fprintf(stderr,"Core路Tape路is_leftmost:: given NULL tape");
+        if( !tm ){
+          fprintf(stderr,"Core路TM_NX_Array路is_origin:: given NULL tm");
           error++;
-        }else if(!tape->position){
-          fprintf(stderr,"Core路Tape路is_leftmost:: leftmost requested of empty tape");
+        }else if( !tm->address ){
+          fprintf(stderr,"Core路TM_NX_Array路is_origin:: origin requested for empty tape");
           error++;
         }
-        if(!result){
-          fprintf(stderr,"Core路Tape路is_leftmost:: NULL result pointer");
+        if( !flag ){
+          fprintf(stderr,"Core路TM_NX_Array路is_origin:: NULL flag pointer");
           error++;
         }
-        // making this a warning, but by spec it must be true
-        if(!a){
-          fprintf(stderr,"Core路Tape路is_leftmost:: given NULL address");
-        }else if( !Core路Area路action.encloses_pt((Core路Area *)tape ,a->address) ){
-          fprintf(stderr,"Core路Tape路is_leftmost:: address is outside tape bounds");
+        if( !a ){
+          fprintf(stderr,"Core路TM_NX_Array路is_origin:: given NULL address");
+        }else if( !Core路TM_NX_Array路area.encloses_pt(tm ,a) ){
+          fprintf(stderr,"Core路TM_NX_Array路is_origin:: address is outside tape bounds");
         }
-        if(error) return Core路Status路derailed;
+        if( error ) return Core路Status路derailed;
       #endif
-        result = tape->position == a;
-        return Core路Status路on_track;
-    }    
+      *flag = ( tm->address == a );
+      return Core路Status路on_track;
+    }
 
-    Local Core路Status Core路Tape路is_rightmost(
-      Core路Tape *tape ,Core路Tape路Address *a ,bool *result
+    Local Core路Status Core路TM_NX_Array路on_rightmost(
+      Core路TM_NX *tm ,Core路TM_NX路Address *a ,bool *result
     ){
       #ifdef Core路Debug
         uint error = 0;
-        if(!tape){
-          fprintf(stderr,"Core路Tape路is_rightmost:: given NULL tape");
+        if( !tm ){
+          fprintf(stderr,"Core路TM_NX_Array路is_rightmost:: given NULL tm");
           error++;
-        }else if(!tape->position){
-          fprintf(stderr,"Core路Tape路is_rightmost:: rightmost requested of empty tape");
+        }else if( !tm->address ){
+          fprintf(stderr,"Core路TM_NX_Array路is_rightmost:: rightmost requested for empty tape");
           error++;
         }
-        if(!result){
-          fprintf(stderr,"Core路Tape路is_rightmost:: NULL result pointer");
+        if( !result ){
+          fprintf(stderr,"Core路TM_NX_Array路is_rightmost:: NULL result pointer");
           error++;
         }
-        // making this a warning, but by spec it must be true
-        if(!a){
-          fprintf(stderr,"Core路Tape路is_rightmost:: given NULL address");
-        }else if( !Core路Area路action.encloses_pt((Core路Area *)tape ,a->address) ){
-          fprintf(stderr,"Core路Tape路is_rightmost:: address is outside tape bounds");
+        if( !a ){
+          fprintf(stderr,"Core路TM_NX_Array路is_rightmost:: given NULL address");
+        }else if( !Core路TM_NX_Array路area.encloses_pt(tm ,a) ){
+          fprintf(stderr,"Core路TM_NX_Array路is_rightmost:: address is outside tape bounds");
         }
-        if(error) return Core路Status路derailed;
+        if( error ) return Core路Status路derailed;
       #endif
-        result = tape->position == tape->position + tape->extent;
-        return Core路Status路on_track;
-    }    
+      *result = ( tm->address == ( tm->address + tm->extent ) );
+      return Core路Status路on_track;
+    }
 
-    Local Core路Status Core路Tape路read(
-      Core路Tape *tape ,Core路Tape路Address *a ,Core路Tape路Remote *remote
+    Local Core路Status Core路TM_NX_Array路read(
+      Core路TM_NX *tm ,Core路TM_NX路Address *a ,Core路Tape路Remote *remote
     ){
       #ifdef Core路Debug
         uint error = 0;
-        if(!tape){
-          fprintf(stderr,"Core路Tape路read:: given NULL tape");
+        if( !tm ){
+          fprintf(stderr,"Core路TM_NX_Array路read:: given NULL tm");
           error++;
-        }else if(!tape->position){
-          fprintf(stderr,"Core路Tape路read:: read requested for a marked as empty tape");
+        }else if( !tm->address ){
+          fprintf(stderr,"Core路TM_NX_Array路read:: read requested for empty tape");
           error++;
         }
-        if(!a){
-          fprintf(stderr,"Core路Tape路read:: given NULL address");
+        if( !a ){
+          fprintf(stderr,"Core路TM_NX_Array路read:: given NULL address");
           error++;
-        }else if( !Core路Area路action.encloses_pt((Core路Area *)tape ,a->address) ){
-          fprintf(stderr,"Core路Tape路read:: address is outside tape bounds");
+        }else if( !Core路TM_NX_Array路area.encloses_pt(tm ,a) ){
+          fprintf(stderr,"Core路TM_NX_Array路read:: address is outside tape bounds");
           error++;
         }
-        if(!remote){
-          fprintf(stderr,"Core路Tape路read:: given NULL remote");
+        if( !remote ){
+          fprintf(stderr,"Core路TM_NX_Array路read:: given NULL remote");
           error++;
         }
-        if(error) return Core路Status路derailed;
+        if( error ) return Core路Status路derailed;
       #endif
       *(AU *)remote->address = *(AU *)a->address;
       return Core路Status路on_track;
     }
 
-    Local Core路Status Core路Tape路write(
-      Core路Tape *tape ,Core路Tape路Address *a ,Core路Tape路Remote *r
+    Local Core路Status Core路TM_NX_Array路write(
+      Core路TM_NX *tm ,Core路TM_NX路Address *a ,Core路Tape路Remote *r
     ){
       #ifdef Core路Debug
         uint error = 0;
-        if(!tape){
-          fprintf(stderr,"Core路Tape路write:: given NULL tape");
+        if( !tm ){
+          fprintf(stderr,"Core路TM_NX_Array路write:: given NULL tm");
           error++;
-        }else if(!tape->position){
-          fprintf(stderr,
-            "Core路Tape路write:: write requested for a marked as empty tape"
-          );
+        }else if( !tm->address ){
+          fprintf(stderr,"Core路TM_NX_Array路write:: write requested for empty tape");
           error++;
         }
-        if(!a){
-          fprintf(stderr,"Core路Tape路write:: given NULL address");
+        if( !a ){
+          fprintf(stderr,"Core路TM_NX_Array路write:: given NULL address");
           error++;
-        }else if( !Core路Area路action.encloses_pt((Core路Area *)tape ,a->address) ){
-          fprintf(stderr,"Core路Tape路write:: address is outside tape bounds");
+        }else if( !Core路TM_NX_Array路area.encloses_pt(tm ,a) ){
+          fprintf(stderr,"Core路TM_NX_Array路write:: address is outside tape bounds");
           error++;
         }
-        if(!r){
-          fprintf(stderr,"Core路Tape路write:: given NULL remote");
+        if( !r ){
+          fprintf(stderr,"Core路TM_NX_Array路write:: given NULL remote");
           error++;
         }
-        if(error) return Core路Status路derailed;
+        if( error ) return Core路Status路derailed;
       #endif
       *(AU *)a->address = *(AU *)r->address;
       return Core路Status路on_track;
     }
 
-    Local Core路Tape路FG Core路Tape路fg = {
-       .topo = Core路Tape路topo
-      ,.extent = Core路Tape路extent
-      ,.is_leftmost = is_leftmost
-      ,.is_rightmost = is_rightmost
-      ,.read = Core路Tape路read
-      ,.write = Core路Tape路write
-    };
-
-    //----------------------------------------
-    // Area Model Implementation
-
-    // Area to Tape Wrappers
-
-    Local Core路Tape路Topo Core路Area路topo(Core路Area *area){
-      return Core路Tape路fg.topo((Core路Tape *)area);
+    Local Core路Status Core路TM_NX_Array路rewind(Core路TM_NX *tm){
+      #ifdef Core路Debug
+        uint error = 0;
+        if( !tm ){
+          fprintf(stderr,"Core路TM_NX_Array路rewind:: given NULL tm");
+          error++;
+        }else if( !tm->array->position ){
+          fprintf(stderr,"Core路TM_NX_Array路rewind:: no tape");
+          error++;
+        }
+        if( error ) return Core路Status路derailed;
+      #endif
+      tm->array->hd = tm->array->position;
+      return Core路Status路on_track;
     }
 
-    Local Core路Status Core路Area路extent(Core路Area *area, extent_t *write_pt){
-      return Core路Tape路fg.extent((Core路Tape *)area, write_pt);
+    Core路Status Core路TM_NX_Array路step(Core路TM_NX *tm){
     }
-
-    Local void Core路Area路read(Core路Area *area, Core路Tape路Address *a, Core路Tape路Remote *r){
-      Core路Tape路fg.read((Core路Tape *)area, a, r);
+    Core路Status Core路TM_NX_Array路step_left(Core路TM_NX *tm){
     }
+    // step_right is a synonym for step
 
-    Local void Core路Area路write(Core路Area *area, Core路Tape路Address *a, Core路Tape路Remote *r){
-      Core路Tape路fg.write((Core路Tape *)area, a, r);
-    }
 
-    // initialization
+    // Area functions within Core路TM_NX_Array
+
+    Local Core路Tape路Topo Core路TM_NX_Array路topo(Core路TM_NX *tm){
+      if( !tm ) return Core路Tape路Topo路nonexistent;
+      if( !tm->address ) return Core路Tape路Topo路empty;
+      if( !tm->extent ) return Core路Tape路Topo路singleton;
+      return Core路Tape路Topo路segment;
+    }
 
-    Local Core路Status Core路Area路set_position(Core路Area *area ,AU *new_position){
+    Local Core路Status Core路TM_NX_Array路extent(Core路TM_NX *tm ,extent_t *extent_pt){
       #ifdef Core路Debug
-      if(!area){
-        fprintf(stderr, "Core路Area路set_position:: given NULL area");
-        return Core路Status路derailed;
-      }
+        uint error = 0;
+        if( !tm ){
+          fprintf(stderr,"Core路TM_NX_Array路extent:: given NULL tm");
+          error++;
+        }else if( !tm->address ){
+          fprintf(stderr,"Core路TM_NX_Array路extent:: extent requested for empty tape");
+          error++;
+        }
+        if( !write_pt ){
+          fprintf(stderr,"Core路TM_NX_Array路extent:: given NULL write_pt");
+          error++;
+        }
+        if( error ) return Core路Status路derailed;
       #endif
-      area->position = new_position;
+      *write_pt = tm->extent;
       return Core路Status路on_track;
     }
 
-    Local Core路Status Core路Area路set_extent(Core路Area *area ,extent_t extent){
+    Local Core路Status Core路TM_NX_Array路set_position(
+      Core路TM_NX *tm ,Core路TM_NX路Address *new_position
+    ){
       #ifdef Core路Debug
-      if(!area){
-        fprintf(stderr, "Core路Area路set_extent:: given NULL area");
-        return Core路Status路derailed;
-      }
+        if( !tm ){
+          fprintf(stderr, "Core路TM_NX_Array路set_position:: given NULL tape machine");
+          return Core路Status路derailed;
+        }
       #endif
-      area->extent = extent;
+      tm->array.hd = new_position->array.address;
       return Core路Status路on_track;
     }
 
-    Local Core路Status Core路Area路set_position_right(Core路Area *area ,AU *new_position_right){
+    // set_position_left is a synonym for set_position
+
+    Local Core路Status Core路TM_NX_Array路set_position_right(
+      Core路TM_NX *tm ,Core路TM_NX路Address *new_position_right
+    ){
       #ifdef Core路Debug
-      if(!area){
-        fprintf(stderr, "Core路Area路set_position_right:: given NULL area");
-        return Core路Status路derailed;
-      }
-      if(!area->position){
-        fprintf(stderr, "Core路Area路set_position_right:: NULL position_left");
-        return Core路Status路derailed;
-      }
+        if( !tm ){
+          fprintf(stderr, "Core路TM_NX_Array路set_position_right:: given NULL tape machine");
+          return Core路Status路derailed;
+        }
+        if( !tm->array.position ){
+          fprintf(stderr, "Core路TM_NX_Array路set_position_right:: NULL position_left");
+          return Core路Status路derailed;
+        }
       #endif
-      return Core路Area路set_extent(area, new_position_right - area->position);
+      return Core路TM_NX_Array路set_extent(
+        tm ,(extent_t)( (uintptr_t)new_position_right->array.address - (uintptr_t)tm->array.position )
+      );
     }
 
-    Local Core路Status Core路Area路init_pe(Core路Area *area ,AU *position ,extent_t extent){
+    Local Core路Status Core路Area路mount_pe(
+      Core路Area *area ,AU *position ,extent_t extent
+    ){
       Core路Status s1 = Core路Area路set_position(area, position);
       Core路Status s2 = Core路Area路set_extent(area, extent);
       return (s1 == Core路Status路derailed || s2 == Core路Status路derailed) ? Core路Status路derailed : Core路Status路on_track;
     }
-
-    Local Core路Status Core路Area路init_pp(Core路Area *area ,AU *position_left ,AU *position_right){
+    Local Core路Status Core路Area路mount_pp(
+      Core路Area *area ,AU *position_left ,AU *position_right
+    ){
       Core路Status s1 = Core路Area路set_position(area, position_left);
       Core路Status s2 = Core路Area路set_position_right(area, position_right);
       return (s1 == Core路Status路derailed || s2 == Core路Status路derailed) ? Core路Status路derailed : Core路Status路on_track;
     }
 
-    // Read Properties
 
-    Local bool Core路Area路empty(Core路Area *area){
-      #ifdef Core路Debug
-      if(!area){
-        fprintf(stderr,"Core路Area路empty:: given NULL area");
-        return true;
-      }
-      #endif
-      return area->position == NULL;
-    }
 
-    Local Core路Status Core路Area路position(Core路Area *area ,AU **out_position){
-      #ifdef Core路Debug
-      if(!area){
-        fprintf(stderr,"Core路Area路position:: given NULL area");
-        *out_position = NULL;
-        return Core路Status路derailed;
-      }
-      #endif
-      *out_position = area->position;
-      return Core路Status路on_track;
-    }
 
-    Local Core路Status Core路Area路position_right(Core路Area *area ,AU **out_position_right){
-      #ifdef Core路Debug
-      if(!area){
-        fprintf(stderr,"Core路Area路position_right:: given NULL area");
-        *out_position_right = NULL;
-        return Core路Status路derailed;
-      }
-      if(!area->position){
-        fprintf(stderr,"Core路Area路position_right:: request for right position when left is NULL");
-        *out_position_right = NULL;
-        return Core路Status路derailed;
-      }
-      #endif
-      *out_position_right = area->position + area->extent;
-      return Core路Status路on_track;
-    }
-
-    Local Core路Status Core路Area路extent(Core路Area *area ,extent_t *out_extent){
-      #ifdef Core路Debug
-      if(!area){
-        fprintf(stderr,"Core路Area路extent:: given NULL area");
-        *out_extent = 0;
-        return Core路Status路derailed;
-      }
-      #endif
-      *out_extent = area->extent;
-      return Core路Status路on_track;
-    }
-
-    Local Core路Status Core路Area路complement(Core路Area *area ,AU *r ,AU **out_complement){
+    Local Core路Status Core路TM_NX_Array路set_extent(
+      Core路TM_NX *tm ,extent_t extent
+    ){
       #ifdef Core路Debug
-      if(!area){
-        fprintf(stderr,"Core路Area路complement:: given NULL area");
-        *out_complement = NULL;
-        return Core路Status路derailed;
-      }
-      if(!r){
-        fprintf(stderr,"Core路Area路complement:: given NULL reference");
-        *out_complement = NULL;
-        return Core路Status路derailed;
-      }
+        if( !tm ){
+          fprintf(stderr, "Core路TM_NX_Array路set_extent:: given NULL tape machine");
+          return Core路Status路derailed;
+        }
       #endif
-      *out_complement = area->position + (area->position + area->extent - r);
+      tm->array.extent = extent;
       return Core路Status路on_track;
     }
 
-    // Relationships
-
-    Local bool Core路Area路encloses_pt(Core路Area *area ,AU *pt){
-      return 
-        (pt >= Core路Area路position(area)) 
-        && (pt <= Core路Area路position_right(area));
-    }
-
-    Local bool Core路Area路encloses_pt_strictly(Core路Area *area ,AU *pt){
-      return 
-        (pt > Core路Area路position(area)) 
-        && (pt < Core路Area路position_right(area));
-    }
-
-    Local bool Core路Area路encloses_area(Core路Area *outer ,Core路Area *inner){
-      return 
-        (Core路Area路position(inner) >= Core路Area路position(outer)) 
-        && (Core路Area路position_right(inner) <= Core路Area路position_right(outer));
-    }
-
-    Local bool Core路Area路encloses_area_strictly(Core路Area *outer ,Core路Area *inner){
-      return 
-        (Core路Area路position(inner) > Core路Area路position(outer)) 
-        && (Core路Area路position_right(inner) < Core路Area路position_right(outer));
-    }
-
-    Local bool Core路Area路overlap(Core路Area *area0 ,Core路Area *area1){
-      return 
-        Core路Area路position_right(area0) >= Core路Area路position(area1)
-        && Core路Area路position(area0) <= Core路Area路position_right(area1);
-    }
-
-    // Aligned Containment
-
-    Local Core路Status Core路Area路largest_aligned_64(Core路Area *outer ,Core路Area *inner_64){
-      #ifdef Core路Debug
-      if(!outer || !inner_64){
-        fprintf(stderr, "Core路Area路largest_aligned_64:: given NULL area(s)");
-        return Core路Status路derailed;
-      }
-      #endif
-
-      uintptr_t p0 = (uintptr_t)Core路Area路position(outer);
-      uintptr_t p1 = (uintptr_t)Core路Area路position_right(outer);
-
-      AU *p0_64 = (AU *)( (p0 + 0x7) & ~(uintptr_t)0x7 );
-      AU *p1_64 = (AU *)( (p1 - 0x7) & ~(uintptr_t)0x7 );
-
-      if(p1_64 < p0_64){
-        return Core路Area路set_position(inner_64 ,NULL);
-      }else{
-        return Core路Area路init_pp(inner_64 ,p0_64 ,p1_64);
-      }
-    }
-
-    // Functions given an Area Argument
-    Local Core路Area路FG Core路Area路fg = {
-      // Given Area functions in parallel to the given Tape functions.
-      ,.topo = Core路Area路topo
-      ,.extent = Core路Area路extent
-      ,.read = Core路Area路read
-      ,.write = Core路Area路write
-
-      // Given Area specific methods
-      ,.init_pe = Core路Area路init_pe
-      ,.init_pp = Core路Area路init_pp
-      ,.set_position = Core路Area路set_position
-      ,.set_position_left = Core路Area路set_position
-      ,.set_position_right = Core路Area路set_position_right
-      ,.set_extent = Core路Area路set_extent
-      ,.position = Core路Area路position
-      ,.position_left = Core路Area路position // Synonym
-      ,.position_right = Core路Area路position_right
-      ,.complement = Core路Area路complement
-      ,.encloses_pt = Core路Area路encloses_pt
-      ,.encloses_pt_strictly = Core路Area路encloses_pt_strictly
-      ,.encloses_area = Core路Area路encloses_area
-      ,.encloses_area_strictly = Core路Area路encloses_area_strictly
-      ,.overlap = Core路Area路overlap
-      ,.largest_aligned_64 = Core路Area路largest_aligned_64
-    };
-
-  //----------------------------------------
-  // Tape Machine Implementation
-
-  typedef struct {
-    Core路Tape *tape;
-    Core路Tape路Address *hd;
-  } Core路TM_NX;
-
-  // Returns the current head status.
-  Local Core路TM路Head路Status Core路TM_NX路status(Core路TM_NX *tm){
-    if(!tm || !tm->tape) return Core路TM路Head路Status路not_on_tape;
-
-    bool is_at_edge;
-
-    if(
-      Core路Tape路fg.is_leftmost(tm->tape ,tm->hd ,&is_at_edge) 
-      == 
-      Core路Status路derailed
-    )
-      return Core路TM路Head路Status路not_on_tape;
-    if(is_at_edge) return Core路TM路Head路Status路leftmost;
-
-    if(
-      Core路Tape路fg.is_rightmost(tm->tape ,tm->hd ,&is_at_edge) 
-      == 
-      Core路Status路derailed
-    )
-      return Core路TM路Head路Status路not_on_tape;
-    if(is_at_edge) return Core路TM路Head路Status路rightmost;
-
-    return Core路TM路Head路Status路interim;
-  }
-
-  // Mounts a tape onto the tape machine.
-  Local Core路Status Core路TM_NX路mount(Core路TM_NX *tm ,Core路Tape *tape){
-    #ifdef Core路DEBUG
-      if(!tm){
-        fprintf(stderr, "Core路TM_NX路mount:: given NULL tm\n");
-        return Core路Status路derailed;
-      }
-      if(!tape){
-        fprintf(stderr, "Core路TM_NX路mount:: given NULL tape\n");
-        return Core路Status路derailed;
-      }
-    #endif
-    tm->tape = tape;
-    tm->hd = (AU *)Core路Tape路fg.extent(tape ,NULL);
-    return Core路Status路on_track;
-  }
-
-  // Returns the associated tape.
-  Local Core路Status Core路TM_NX路tape(Core路TM_NX *tm ,Core路Tape **out_tape){
-    #ifdef Core路DEBUG
-      if(!tm){
-        fprintf(stderr, "Core路TM_NX路tape:: given NULL tm\n");
-        return Core路Status路derailed;
-      }
-    #endif
-    *out_tape = tm->tape;
-    return Core路Status路on_track;
-  }
-
-  // Resets the tape head to the starting position.
-  Local Core路Status Core路TM_NX路rewind(Core路TM_NX *tm){
-    #ifdef Core路DEBUG
-      if(!tm){
-        fprintf(stderr, "Core路TM_NX路rewind:: given NULL tm\n");
-        return Core路Status路derailed;
-      }
-      if(!tm->tape){
-        fprintf(stderr, "Core路TM_NX路rewind:: tape is not mounted\n");
-        return Core路Status路derailed;
-      }
-    #endif
-    tm->hd = Core路Tape路fg.position(tm->tape ,NULL);
-    return Core路Status路on_track;
-  }
-
-  // Checks if tape can be read.
-  Local Core路Status Core路TM_NX路can_read(bool *result){
-    *result = (Core路Tape路Topo路can_read & Core路Tape路fg.topo(tm->tape)) != 0;
-    return Core路Status路on_track;
-  }
-
-  // Moves the tape head one step to the right.
-  Local Core路Status Core路TM_NX路step(Core路TM_NX *tm){
-    #ifdef Core路DEBUG
-      if(!tm){
-        fprintf(stderr, "Core路TM_NX路step:: given NULL tm\n");
-        return Core路Status路derailed;
-      }
-      if(!tm->tape){
-        fprintf(stderr, "Core路TM_NX路step:: tape is not mounted\n");
-        return Core路Status路derailed;
-      }
-      if(!Core路TM_NX路can_step(tm)){
-        fprintf(stderr, "Core路TM_NX路step:: stepping not possible\n");
-        return Core路Status路derailed;
-      }
-    #endif
-
-    tm->hd++;
-    return Core路Status路on_track;
-  }
-
-  // Moves the tape head one step to the left.
-  Local Core路Status Core路TM_NX路step_left(Core路TM_NX *tm){
-    #ifdef Core路DEBUG
-      if(!tm){
-        fprintf(stderr, "Core路TM_NX路step_left:: given NULL tm\n");
-        return Core路Status路derailed;
-      }
-      if(!tm->tape){
-        fprintf(stderr, "Core路TM_NX路step_left:: tape is not mounted\n");
-        return Core路Status路derailed;
-      }
-      if(!Core路TM_NX路can_step_left(tm)){
-        fprintf(stderr, "Core路TM_NX路step_left:: stepping left not possible\n");
-        return Core路Status路derailed;
-      }
-    #endif
-
-    tm->hd--;
-    return Core路Status路on_track;
-  }
-
-  // Determines if stepping right is possible.
-  Local bool Core路TM_NX路can_step(Core路TM_NX *tm){
-    return tm->hd < (AU *)Core路Tape路fg.extent(tm->tape ,NULL);
-  }
-
-  // Determines if stepping left is possible.
-  Local bool Core路TM_NX路can_step_left(Core路TM_NX *tm){
-    return tm->hd > (AU *)Core路Tape路fg.extent(tm->tape ,NULL);
-  }
-
-  // Moves the head to the given position if within bounds.
-  Local Core路Status Core路TM_NX路cue(Core路TM_NX *tm ,AU *put){
-    #ifdef Core路DEBUG
-      if(!tm){
-        fprintf(stderr, "Core路TM_NX路cue:: given NULL tm\n");
-        return Core路Status路derailed;
-      }
-      if(!tm->tape){
-        fprintf(stderr, "Core路TM_NX路cue:: tape is not mounted\n");
-        return Core路Status路derailed;
-      }
-      if(put < (AU *)Core路Tape路fg.extent(tm->tape ,NULL) 
-      || put > (AU *)Core路Tape路fg.extent(tm->tape ,NULL)){
-        fprintf(stderr, "Core路TM_NX路cue:: given position is out of bounds\n");
-        return Core路Status路derailed;
-      }
-    #endif
-
-    tm->hd = put;
-    return Core路Status路on_track;
-  }
-
-Local Core路TapeMachine路FG Core路TapeMachine路fg = {
-    .mount = Core路TapeMachine路mount,
-    .dismount = Core路TapeMachine路dismount,
-    .rewind = Core路TapeMachine路rewind,
-    .step = Core路TapeMachine路step,
-    .step_left = Core路TapeMachine路step_left,
-    .step_right = Core路TapeMachine路step_right,
-    .can_step = Core路TapeMachine路can_step,
-    .can_step_left = Core路TapeMachine路can_step_left,
-    .fast_forward = Core路TapeMachine路fast_forward,
-    .cue = Core路TapeMachine路cue,
-    .status = Core路TapeMachine路status,
-
-    .area = {
-        .topo = Core路TapeMachine路topo,
-        .extent = Core路TapeMachine路extent,
-        .set_position = Core路TapeMachine路set_position,
-        .set_extent = Core路TapeMachine路set_extent,
-        .position = Core路TapeMachine路position,
-        .position_right = Core路TapeMachine路position_right,
-        .complement = Core路TapeMachine路complement,
-        .encloses_pt = Core路TapeMachine路encloses_pt,
-        .encloses_area = Core路TapeMachine路encloses_area,
-        .overlap = Core路TapeMachine路overlap,
-        .largest_aligned_64 = Core路TapeMachine路largest_aligned_64
+    Local Core路Status Core路TM_NX_Array路init_pp(
+      Core路TM_NX *tm ,void *position_left ,void *position_right
+    ){
+      Core路Status s1 = Core路TM_NX_Array路set_position(tm, (Core路TM_NX路Address *)&(Core路TM_NX路Address){ .array.address = position_left });
+      Core路Status s2 = Core路TM_NX_Array路set_position_right(tm, (Core路TM_NX路Address *)&(Core路TM_NX路Address){ .array.address = position_right });
+      return ( s1 == Core路Status路derailed || s2 == Core路Status路derailed ) ? Core路Status路derailed : Core路Status路on_track;
     }
-};
 
 
-  // Initialize the function table
-  Local Core路TM_NX路FG Core路TM_NX路fg = {
-     .mount = Core路TM_NX路mount
-    ,.tape = Core路TM_NX路tape
-    ,.rewind = Core路TM_NX路rewind
-    ,.can_read = Core路TM_NX路can_read
-    ,.step = Core路TM_NX路step
-    ,.step_left = Core路TM_NX路step_left
-    ,.step_right = Core路TM_NX路step
-    ,.status = Core路TM_NX路status
-  };
+    
 
     //----------------------------------------
-    // Tape Machine xx
-
-    typedef struct {
-      Core路Tape *tape;
-      AU *hd;
-    } Core路TM_NX;
-
-    // Returns the current head status.
-    Local Core路TM路Head路Status Core路TM_NX路status(Core路TM_NX *tm){
-      if(!tm) return Core路TM路Head路Status路mu;
-
-      bool q;
-
-      if(
-        Core路Tape路is_lefttmost(tm->hd ,&q) == Core路Status路derailed
-      )
-        return Core路TM路Head路Status路not_on_tape;
-      if(q) return Core路TM路Head路Status路leftmost;
-
-      if(
-        Core路Tape路is_lefttmost(tm->hd ,&q) == Core路Status路derailed
-      )
-        return Core路TM路Head路Status路not_on_tape;
-      if(q) return Core路TM路Head路Status路rightmost;
-
-      return Core路TM路Head路Status路interim;
-    }
-
-    // Mounts a tape onto the tape machine.
-    Local void Core路TM_NX路mount(Core路TM_NX *tm ,Core路Tape *tape){
-      #ifdef Core路DEBUG
-        if(!tm){
-          fprintf(stderr, "Core路TM_NX路mount:: given NULL tm\n");
-          return;
-        }
-        if(!tape){
-          fprintf(stderr, "Core路TM_NX路mount:: given NULL tape\n");
-          return;
-        }
-      #endif
-      tm->tape = tape;
-      tm->hd = tape->position; // Initialize head to leftmost position
-    }
-
-  // Returns the associated tape.
-  Local Core路Tape *Core路TM_NX路tape(Core路TM_NX *tm){
-    #ifdef Core路DEBUG
-      if(!tm){
-        fprintf(stderr, "Core路TM_NX路tape:: given NULL tm\n");
-        return NULL;
-      }
-    #endif
-    return tm->tape;
-  }
-
-  // Resets the tape head to the starting position.
-  Local void Core路TM_NX路rewind(Core路TM_NX *tm){
-    #ifdef Core路DEBUG
-      if(!tm){
-        fprintf(stderr, "Core路TM_NX路rewind:: given NULL tm\n");
-        return;
-      }
-      if(!tm->tape){
-        fprintf(stderr, "Core路TM_NX路rewind:: tape is not mounted\n");
-        return;
+    // FG Table Initialization for Array Implementation
+
+    Local Core路TM_NX路FG Core路TM_NX_Array路fg = {
+       .mount = Core路TM_NX_Array路mount
+      ,.dismount = Core路TM_NX_Array路dismount
+      ,.rewind = Core路TM_NX_Array路rewind
+
+      ,.can_step = Core路TM_NX_Array路can_step
+      ,.on_origin = Core路TM_NX_Array路on_origin
+      ,.on_rightmost = Core路TM_NX_Array路on_rightmost
+
+      ,.extent = Core路TM_NX_Array路extent
+      ,.can_read = Core路TM_NX_Array路can_read
+
+      ,.step = Core路TM_NX_Array路step
+      ,.step_left = Core路TM_NX_Array路step_left
+      ,.step_right = Core路TM_NX_Array路step_right
+      ,.status = Core路TM_NX_Array路status
+
+      ,.area {
+         .topo = Core路TM_NX_Array路topo
+        ,.extent = Core路TM_NX_Array路extent
+        ,.is_origin = Core路TM_NX_Array路is_origin
+        ,.is_rightmost = Core路TM_NX_Array路is_rightmost
+        ,.read = Core路TM_NX_Array路read
+        ,.write = Core路TM_NX_Array路write
+
+        ,.init_pe = Core路TM_NX_Array路init_pe
+        ,.init_pp = Core路TM_NX_Array路init_pp
+        ,.set_position = Core路TM_NX_Array路set_position
+        ,.set_position_left = Core路TM_NX_Array路set_position
+        ,.set_position_right = Core路TM_NX_Array路set_position_right
+        ,.set_extent = Core路TM_NX_Array路set_extent
+
+        ,.position = Core路TM_NX_Array路position
+        ,.position_left = Core路TM_NX_Array路position // synonym
+        ,.position_right = Core路TM_NX_Array路position_right
+
+        ,.complement = Core路TM_NX_Array路complement
+
+        ,.encloses_pt = Core路TM_NX_Array路encloses_pt
+        ,.encloses_tm = Core路TM_NX_Array路encloses_tm
+        ,.overlap = Core路TM_NX_Array路overlap
+        ,.largest_aligned_64 = Core路TM_NX_Array路largest_aligned_64
       }
-    #endif
-    tm->hd = tm->tape->position;
-  }
-
-  // Moves the tape head one step to the right.
-  Local void Core路TM_NX路step(Core路TM_NX *tm){
-    #ifdef Core路DEBUG
-      if(!tm){
-        fprintf(stderr, "Core路TM_NX路step:: given NULL tm\n");
-        return;
-      }
-      if(!tm->tape){
-        fprintf(stderr, "Core路TM_NX路step:: tape is not mounted\n");
-        return;
-      }
-      if(!Core路TM_NX路can_step(tm)){
-        fprintf(stderr, "Core路TM_NX路step:: stepping not possible\n");
-        return;
-      }
-    #endif
-
-    tm->hd++;
-
-  }
-
-  // Moves the tape head one step to the left.
-  Local void Core路TM_NX路step_left(Core路TM_NX *tm){
-    #ifdef Core路DEBUG
-      if(!tm){
-        fprintf(stderr, "Core路TM_NX路step_left:: given NULL tm\n");
-        return;
-      }
-      if(!tm->tape){
-        fprintf(stderr, "Core路TM_NX路step_left:: tape is not mounted\n");
-        return;
-      }
-      if(!Core路TM_NX路can_step_left(tm)){
-        fprintf(stderr, "Core路TM_NX路step_left:: stepping left not possible\n");
-        return;
-      }
-    #endif
-
-    tm->hd--;
-  }
-
-  // Determines if stepping right is possible.
-  Local bool Core路TM_NX路can_step(Core路TM_NX *tm){
-    #ifdef Core路DEBUG
-      if(!tm){
-        fprintf(stderr, "Core路TM_NX路路can_step:: given NULL tm\n");
-        return;
-      }
-    #endif
-    return tm->hd <= Core路Tape路position_right(tm->tape);
-  }
-
-  // Determines if stepping left is possible.
-  Local bool Core路TM_NX路can_step_left(Core路TM_NX *tm){
-    if(!tm || !tm->tape) return false;
-    return tm->hd > tm->tape->position;
-  }
-
-  // Fast forward to the rightmost position.
-  Local void Core路TM_NX路fast_forward(Core路TM_NX *tm){
-    #ifdef Core路DEBUG
-      if(!tm){
-        fprintf(stderr, "Core路TM_NX路fast_forward:: given NULL tm\n");
-        return;
-      }
-      if(!tm->tape){
-        fprintf(stderr, "Core路TM_NX路fast_forward:: tape is not mounted\n");
-        return;
-      }
-    #endif
-
-    tm->hd = tm->tape->position + tm->tape->extent - 1;
-  }
-
-  // Moves the head to the given position if within bounds.
-  Local void Core路TM_NX路cue(Core路TM_NX *tm ,AU *put){
-    #ifdef Core路DEBUG
-      if(!tm){
-        fprintf(stderr, "Core路TM_NX路cue:: given NULL tm\n");
-        return;
-      }
-      if(!tm->tape){
-        fprintf(stderr, "Core路TM_NX路cue:: tape is not mounted\n");
-        return;
-      }
-      if(put < tm->tape->position || put > (tm->tape->position + tm->tape->extent - 1)){
-        fprintf(stderr, "Core路TM_NX路cue:: given position is out of bounds\n");
-        return;
-      }
-    #endif
-
-    tm->hd = put;
-  }
-
-  // Initialize the function table
-  Local Core路TM_NX路FG Core路TM_NX路fg = {
-     .mount = Core路TM_NX路mount
-    ,.tape = Core路TM_NX路tape
-    ,.rewind = Core路TM_NX路rewind
-    ,.step = Core路TM_NX路step
-    ,.step_left = Core路TM_NX路step
-    ,.step_right = Core路TM_NX路step_right
-    ,.can_step = Core路TM_NX路can_step
-    ,.can_step_left = Core路TM_NX路can_step_left
-    ,.can_step_right = Core路TM_NX路can_step
-    ,.fast_forward = Core路TM_NX路fast_forward
-    ,.cue = Core路TM_NX路cue
-    ,.status = Core路TM_NX路status
-  };
-
+    };
 
     //----------------------------------------
     // Map
index 8177ee5..cfaa805 100644 (file)
@@ -1,3 +1,379 @@
+  //----------------------------------------
+  // TM_NX array
+
+    Local Core路TM_NX_Array路Topo Core路TM_NX路topo(Core路TM_NX *tape){
+      if(!tape) return Core路Area路Topo路nonexistent;
+      if(!tape->position) return Core路Area路Topo路empty;
+      if(!tape->extent) return Core路Area路Topo路singleton;
+      return Core路Area路Topo路segment;
+    }
+
+    Local Core路Status Core路TM_NX_Array路extent(Core路TM_NX *tape ,extent_t *write_pt){
+      #ifdef Core路Debug
+        uint error = 0;
+        if(!tape){
+          fprintf(stderr,"Core路TM_NX路extent:: given NULL tape");
+          error++;
+        }else if(!tape->position){
+          fprintf(stderr,"Core路TM_NX路extent:: extent requested for a marked as empty tape");
+          error++;
+        }
+        if(!write_pt){
+          fprintf(stderr,"Core路TM_NX路extent:: given NULL write_pt");
+          error++;
+        }
+        if(error) return Core路Status路derailed;
+      #endif
+      return tape->extent;    Local Core路TM_NX路FG Core路TM_NX路fg = {
+
+    }    
+
+    Local bool Core路TM_MX_Array路encloses_pt(Core路Area *area ,AU *pt);
+
+    // a must be on tape
+    Local Core路Status Core路TM_NX路is_leftmost(
+      Core路TM_NX *tape ,Core路TM_NX路Address *a ,bool *result
+    ){
+      #ifdef Core路Debug
+        uint error = 0;
+        if(!tape){
+          fprintf(stderr,"Core路TM_NX路is_leftmost:: given NULL tape");
+          error++;
+        }else if(!tape->position){
+          fprintf(stderr,"Core路TM_NX路is_leftmost:: leftmost requested of empty tape");
+          error++;
+        }
+        if(!result){
+          fprintf(stderr,"Core路TM_NX路is_leftmost:: NULL result pointer");
+          error++;
+        }
+        // making this a warning, but by spec it must be true
+        if(!a){
+          fprintf(stderr,"Core路TM_NX路is_leftmost:: given NULL address");
+        }else if( !Core路TM_MX_Array路encloses_pt((Core路Area *)tape ,a->address) ){
+          fprintf(stderr,"Core路TM_NX路is_leftmost:: address is outside tape bounds");
+        }
+        if(error) return Core路Status路derailed;
+      #endif
+        result = tape->position == a;
+        return Core路Status路on_track;
+    }    
+
+    Local Core路Status Core路TM_NX路is_rightmost(
+      Core路TM_NX *tape ,Core路TM_NX路Address *a ,bool *result
+    ){
+      #ifdef Core路Debug
+        uint error = 0;
+        if(!tape){
+          fprintf(stderr,"Core路TM_NX路is_rightmost:: given NULL tape");
+          error++;
+        }else if(!tape->position){
+          fprintf(stderr,"Core路TM_NX路is_rightmost:: rightmost requested of empty tape");
+          error++;
+        }
+        if(!result){
+          fprintf(stderr,"Core路TM_NX路is_rightmost:: NULL result pointer");
+          error++;
+        }
+        // making this a warning, but by spec it must be true
+        if(!a){
+          fprintf(stderr,"Core路TM_NX路is_rightmost:: given NULL address");
+        }else if( !Core路TM_MX_Array路encloses_pt((Core路Area *)tape ,a->address) ){
+          fprintf(stderr,"Core路TM_NX路is_rightmost:: address is outside tape bounds");
+        }
+        if(error) return Core路Status路derailed;
+      #endif
+        result = tape->position == tape->position + tape->extent;
+        return Core路Status路on_track;
+    }    
+
+    Local Core路Status Core路TM_NX路read(
+      Core路TM_NX *tape ,Core路TM_NX路Address *a ,Core路TM_NX路Remote *remote
+    ){
+      #ifdef Core路Debug
+        uint error = 0;
+        if(!tape){
+          fprintf(stderr,"Core路TM_NX路read:: given NULL tape");
+          error++;
+        }else if(!tape->position){
+          fprintf(stderr,"Core路TM_NX路read:: read requested for a marked as empty tape");
+          error++;
+        }
+        if(!a){
+          fprintf(stderr,"Core路TM_NX路read:: given NULL address");
+          error++;
+        }else if( !Core路TM_MX_Array路encloses_pt((Core路Area *)tape ,a->address) ){
+          fprintf(stderr,"Core路TM_NX路read:: address is outside tape bounds");
+          error++;
+        }
+        if(!remote){
+          fprintf(stderr,"Core路TM_NX路read:: given NULL remote");
+          error++;
+        }
+        if(error) return Core路Status路derailed;
+      #endif
+      *(AU *)remote->address = *(AU *)a->address;
+      return Core路Status路on_track;
+    }
+
+    Local Core路Status Core路TM_NX路write(
+      Core路TM_NX *tape ,Core路TM_NX路Address *a ,Core路TM_NX路Remote *r
+    ){
+      #ifdef Core路Debug
+        uint error = 0;
+        if(!tape){
+          fprintf(stderr,"Core路TM_NX路write:: given NULL tape");
+          error++;
+        }else if(!tape->position){
+          fprintf(stderr,
+            "Core路TM_NX路write:: write requested for a marked as empty tape"
+          );
+          error++;
+        }
+        if(!a){
+          fprintf(stderr,"Core路TM_NX路write:: given NULL address");
+          error++;
+        }else if( !Core路TM_MX_Array路encloses_pt((Core路Area *)tape ,a->address) ){
+          fprintf(stderr,"Core路TM_NX路write:: address is outside tape bounds");
+          error++;
+        }
+        if(!r){
+          fprintf(stderr,"Core路TM_NX路write:: given NULL remote");
+          error++;
+        }
+        if(error) return Core路Status路derailed;
+      #endif
+      *(AU *)a->address = *(AU *)r->address;
+      return Core路Status路on_track;
+    }
+
+    // area functions
+
+    Local Core路Status Core路Area路set_position(Core路Area *area ,AU *new_position){
+      #ifdef Core路Debug
+      if(!area){
+        fprintf(stderr, "Core路Area路set_position:: given NULL area");
+        return Core路Status路derailed;
+      }
+      #endif
+      area->position = new_position;
+      return Core路Status路on_track;
+    }
+
+    Local Core路Status Core路Area路set_extent(Core路Area *area ,extent_t extent){
+      #ifdef Core路Debug
+      if(!area){
+        fprintf(stderr, "Core路Area路set_extent:: given NULL area");
+        return Core路Status路derailed;
+      }
+      #endif
+      area->extent = extent;
+      return Core路Status路on_track;
+    }
+
+    Local Core路Status Core路Area路set_position_right(Core路Area *area ,AU *new_position_right){
+      #ifdef Core路Debug
+      if(!area){
+        fprintf(stderr, "Core路Area路set_position_right:: given NULL area");
+        return Core路Status路derailed;
+      }
+      if(!area->position){
+        fprintf(stderr, "Core路Area路set_position_right:: NULL position_left");
+        return Core路Status路derailed;
+      }
+      #endif
+      return Core路Area路set_extent(area, new_position_right - area->position);
+    }
+
+    Local Core路Status Core路Area路init_pe(Core路Area *area ,AU *position ,extent_t extent){
+      Core路Status s1 = Core路Area路set_position(area, position);
+      Core路Status s2 = Core路Area路set_extent(area, extent);
+      return (s1 == Core路Status路derailed || s2 == Core路Status路derailed) ? Core路Status路derailed : Core路Status路on_track;
+    }
+
+    Local Core路Status Core路Area路init_pp(Core路Area *area ,AU *position_left ,AU *position_right){
+      Core路Status s1 = Core路Area路set_position(area, position_left);
+      Core路Status s2 = Core路Area路set_position_right(area, position_right);
+      return (s1 == Core路Status路derailed || s2 == Core路Status路derailed) ? Core路Status路derailed : Core路Status路on_track;
+    }
+
+    // Read Properties
+
+    Local bool Core路Area路empty(Core路Area *area){
+      #ifdef Core路Debug
+      if(!area){
+        fprintf(stderr,"Core路Area路empty:: given NULL area");
+        return true;
+      }
+      #endif
+      return area->position == NULL;
+    }
+
+    Local Core路Status Core路Area路position(Core路Area *area ,AU **out_position){
+      #ifdef Core路Debug
+      if(!area){
+        fprintf(stderr,"Core路Area路position:: given NULL area");
+        *out_position = NULL;
+        return Core路Status路derailed;
+      }
+      #endif
+      *out_position = area->position;
+      return Core路Status路on_track;
+    }
+
+    Local Core路Status Core路Area路position_right(Core路Area *area ,AU **out_position_right){
+      #ifdef Core路Debug
+      if(!area){
+        fprintf(stderr,"Core路Area路position_right:: given NULL area");
+        *out_position_right = NULL;
+        return Core路Status路derailed;
+      }
+      if(!area->position){
+        fprintf(stderr,"Core路Area路position_right:: request for right position when left is NULL");
+        *out_position_right = NULL;
+        return Core路Status路derailed;
+      }
+      #endif
+      *out_position_right = area->position + area->extent;
+      return Core路Status路on_track;
+    }
+
+    Local Core路Status Core路Area路extent(Core路Area *area ,extent_t *out_extent){
+      #ifdef Core路Debug
+      if(!area){
+        fprintf(stderr,"Core路Area路extent:: given NULL area");
+        *out_extent = 0;
+        return Core路Status路derailed;
+      }
+      #endif
+      *out_extent = area->extent;
+      return Core路Status路on_track;
+    }
+
+    Local Core路Status Core路Area路complement(Core路Area *area ,AU *r ,AU **out_complement){
+      #ifdef Core路Debug
+      if(!area){
+        fprintf(stderr,"Core路Area路complement:: given NULL area");
+        *out_complement = NULL;
+        return Core路Status路derailed;
+      }
+      if(!r){
+        fprintf(stderr,"Core路Area路complement:: given NULL reference");
+        *out_complement = NULL;
+        return Core路Status路derailed;
+      }
+      #endif
+      *out_complement = area->position + (area->position + area->extent - r);
+      return Core路Status路on_track;
+    }
+
+    // Relationships
+
+    Local bool Core路Area路encloses_pt(Core路Area *area ,AU *pt){
+      return 
+        (pt >= Core路Area路position(area)) 
+        && (pt <= Core路Area路position_right(area));
+    }
+
+    Local bool Core路Area路encloses_pt_strictly(Core路Area *area ,AU *pt){
+      return 
+        (pt > Core路Area路position(area)) 
+        && (pt < Core路Area路position_right(area));
+    }
+
+    Local bool Core路Area路encloses_area(Core路Area *outer ,Core路Area *inner){
+      return 
+        (Core路Area路position(inner) >= Core路Area路position(outer)) 
+        && (Core路Area路position_right(inner) <= Core路Area路position_right(outer));
+    }
+
+    Local bool Core路Area路encloses_area_strictly(Core路Area *outer ,Core路Area *inner){
+      return 
+        (Core路Area路position(inner) > Core路Area路position(outer)) 
+        && (Core路Area路position_right(inner) < Core路Area路position_right(outer));
+    }
+
+    Local bool Core路Area路overlap(Core路Area *area0 ,Core路Area *area1){
+      return 
+        Core路Area路position_right(area0) >= Core路Area路position(area1)
+        && Core路Area路position(area0) <= Core路Area路position_right(area1);
+    }
+
+    // Aligned Containment
+
+    Local Core路Status Core路Area路largest_aligned_64(Core路Area *outer ,Core路Area *inner_64){
+      #ifdef Core路Debug
+      if(!outer || !inner_64){
+        fprintf(stderr, "Core路Area路largest_aligned_64:: given NULL area(s)");
+        return Core路Status路derailed;
+      }
+      #endif
+
+      uintptr_t p0 = (uintptr_t)Core路Area路position(outer);
+      uintptr_t p1 = (uintptr_t)Core路Area路position_right(outer);
+
+      AU *p0_64 = (AU *)( (p0 + 0x7) & ~(uintptr_t)0x7 );
+      AU *p1_64 = (AU *)( (p1 - 0x7) & ~(uintptr_t)0x7 );
+
+      if(p1_64 < p0_64){
+        return Core路Area路set_position(inner_64 ,NULL);
+      }else{
+        return Core路Area路init_pp(inner_64 ,p0_64 ,p1_64);
+      }
+    }
+
+    // functions given a TM_NX argument
+
+    Local Core路TM_NX路FG Core路TM_NX_Array路fg = {
+       .mount = Core路TM_NX路mount
+      ,.dismount = Core路TM_NX路dismount
+      ,.rewind = Core路TM_NX路rewind
+
+      ,.can_step = Core路TM_NX路can_step
+      ,.on_origin = Core路TM_NX路on_origin
+      ,.on_rightmost = Core路TM_NX路on_rightmost
+
+      ,.extent = Core路TM_NX路extent
+      ,.can_read = Core路TM_NX路can_read
+
+      ,.step = Core路TM_NX路step
+      ,.step_left = Core路TM_NX路step_left
+      ,.step_right = Core路TM_NX路step_right
+      ,.status = Core路TM_NX路status
+
+      ,.area {
+         .topo = Core路TM_NX路topo
+        ,.extent = Core路TM_NX路extent
+        ,.is_origin = Core路TM_NX路is_origin
+        ,.is_rightmost = Core路TM_NX路is_rightmost
+        ,.read = Core路TM_NX路read
+        ,.write = Core路TM_NX路write
+
+        ,.init_pe = Core路TM_NX路init_pe
+        ,.init_pp = Core路TM_NX路init_pp
+        ,.set_position = Core路TM_NX路set_position
+        ,.set_position_left = Core路TM_NX路set_position
+        ,.set_position_right = Core路TM_NX路set_position_right
+        ,.set_extent = Core路TM_NX路set_extent
+
+        ,.position = Core路TM_NX路position
+        ,.position_left = Core路TM_NX路position // synonym
+        ,.position_right = Core路TM_NX路position_right
+
+        ,.complement = Core路TM_NX路complement
+
+        ,.encloses_pt = Core路TM_NX路encloses_pt
+        ,.encloses_pt_strictly = Core路TM_NX路encloses_pt_strictly
+        ,.encloses_tm = Core路TM_NX路encloses_tm
+        ,.encloses_tm_strictly = Core路TM_NX路encloses_tm_strictly
+        ,.overlap = Core路TM_NX路overlap
+        ,.largest_aligned_64 = Core路TM_NX路largest_aligned_64
+       };
+
+    };
+
+
+================================================================================
   //----------------------------------------
   // Tape model