//----------------------------------------
// memory
- #define extentof(x)(sizeof(x) - 1)
- #define extent_t size_t
-
// AU == Addressable Unit
// given an AU is an 8 bit byte, 4AU is 32 bits, and 8 AU is 64 bits.
+ // uint8_t is the current industry de-facto standard
#define AU uint8_t
+ // sizeof, and thus extent_t are measures of AU
+ #define extentof(x)(sizeof(x) - 1)
+ #define extent_t size_t
+
+ typedef enum{
+ Core路Status路mu = 0
+ ,Core路Status路on_track
+ ,Core路Status路derailed
+ }Core路Status;
+
//----------------------------------------
// argument guard
+ typedef void (*Flag路Function)(uint8_t *flag ,uint err);
-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
-};
+ void Core路Flag路count(uint8_t *flag ,uint err){
+ if(err >= 0xFF){ *flag = 0xFF; return;}
-// Implementation
+ //*flag + err > 0xFF
+ if(*flag > 0xFF - err){ *flag = 0xFF; return;}
-void Core路Guard路init(Core路Guard *chk ,Flag路Function af){
- if( !chk ) return;
- chk->flag_function = af;
- chk->flag = 0;
-}
+ (*flag) += err;
+ }
-void Core路Guard路reset(Core路Guard *chk){
- if( !chk ) return;
- chk->flag = 0;
-}
+ void Core路Flag路collect(uint8_t *flag ,uint err){
+ (*flag) |= err;
+ }
-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);
-}
+ typedef struct {
+ char *name;
+ Flag路Function flag_function;
+ uint8_t flag;
+ } Core路Guard;
+
+ typedef struct {
+ void (*init)(Core路Guard *chk ,const char *name ,Flag路Function af);
+ void (*reset)(Core路Guard *chk);
+ void (*check)(
+ Core路Guard *chk
+ ,uint err
+ ,bool condition
+ ,char *message
+ );
+ } Core路Guard路FG;
+ // Default guard function table
+ // initialized in the implementation section below
+ Local Core路Guard路FG Core路Guard路fg;
+ #define Core路Guard路if_return(chk) if( chk.flag ) return Core路Status路derailed;
+ #define Core路Guard路return(chk)\
+ if( chk.flag ) return Core路Status路derailed;\
+ else return Core路Status路on_track;
//----------------------------------------
// functions
// no state, this is merely a namespace
- typedef enum{
- Core路Status路mu = 0
- ,Core路Status路on_track
- ,Core路Status路derailed
- }Core路Status;
-
typedef struct{
Core路Status (*on_track)();
Core路Status (*derailed)();
typedef struct Core路TM_NX路Remote;
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路mu = 0
+ ,Core路Tape路Topo路nonexistent = 1
+ ,Core路Tape路Topo路empty = 1 << 1
+ ,Core路Tape路Topo路singleton = 1 << 2
+ ,Core路Tape路Topo路segment = 1 << 3
+ ,Core路Tape路Topo路circle = 1 << 4
+ ,Core路Tape路Topo路tail_cyclic = 1 << 5
+ ,Core路Tape路Topo路infinite = 1 << 6
}Core路Tape路Topo;
+ const Core路Tape路Topo Core路Tape路Topo路finite_nz =
+ Core路Tape路Topo路singleton | Core路Tape路Topo路segment
+ ;
+
// 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路origin = 1 << 1
+ ,Core路TM路Head路Status路interim = 1 << 2
+ ,Core路TM路Head路Status路rightmost = 1 << 3
} Core路TM路Head路Status;
+ const Core路TM路Head路Status Core路TM路Head路Status路on_tape =
+ Core路TM路Head路Status路origin
+ | Core路TM路Head路Status路interim
+ | Core路TM路Head路Status路rightmost
+ ;
+
typedef struct{
// these are for types that need initialization and cleanup
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);
Core路Status (*on_rightmost)(Core路TM_NX *tm ,bool *flag);
Core路Status (*read)(
- Core路TM_NX *tm
+ Core路TM_NX *tm
,Core路TM_NX路Address *a
,Core路Tape路Remote *remote
);
Core路Status (*write)(
- Core路TM_NX *tm
+ 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 (*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);
#ifdef LOCAL
+
+ //----------------------------------------
+ // argument guard
//----------------------------------------
- // Utilities
+
+
+ Local void Core路Guard路init(Core路Guard *chk ,Flag路Function af){
+ if( !chk ) return;
+ chk->flag_function = af;
+ chk->flag = 0;
+ }
+
+ Local void Core路Guard路reset(Core路Guard *chk){
+ if( !chk ) return;
+ chk->flag = 0;
+ }
+
+ Local 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);
+ }
+
+ Local Core路Guard路FG Core路Guard路fg = {
+ .init = Core路Guard路init
+ ,.reset = Core路Guard路reset
+ ,.check = Core路Guard路check
+ };
+
+
+ //----------------------------------------
+ // Functions
+ //----------------------------------------
+
Core路Status Core路on_track(){ return Core路Status路on_track; }
Core路Status Core路derailed(){ return Core路Status路derailed; }
Local void *Core路offset(void *p ,size_t 螖){
#ifdef Core路Debug
- if( !p ){
+ if(!p){
fprintf(stderr ,"Core路offset:: given NULL `p'");
return NULL;
}
Local void *Core路offset_8AU(void *p ,size_t 螖){
#ifdef Core路Debug
- if( !p ){
+ if(!p){
fprintf(stderr ,"Core路offset_8AU:: given NULL `p'");
return NULL;
}
Local bool Core路is_aligned_on_8AU(void *p){
#ifdef Core路Debug
- if( !p ){
+ if(!p){
fprintf(stderr ,"Core路is_aligned_on_8AU:: given NULL `p'");
return false;
}
// returns the byte pointer to the least address byte in the window
Local void *Core路floor_within_aligned_8AU(void *p){
#ifdef Core路Debug
- if( !p ){
+ if(!p){
fprintf(stderr ,"Core路floor_8AU:: given NULL `p'" );
return NULL;
}
// returns the byte pointer to the greatest address byte in the window
Local void *Core路ceiling_within_aligned_8AU(void *p){
#ifdef Core路Debug
- if( !p ){
+ if(!p){
fprintf(stderr ,"Core路ceiling_64:: given NULL `p'" );
return NULL;
}
//----------------------------------------
// TM_NX
+ //----------------------------------------
+
+ // The TM_NX has no destructive operations, so the tape will never get longer or shorter. Calls to 'mount_pe' or 'mount_pp' are initialization operations.
+ // hd == 0 is used to signal that the tape is unmounted or empty.
typedef union{
struct{
- void *address;
+ AU *address;
}array;
}Core路TM_MX路Address;
extent_t extent;
uint64_t *hd;
}array8AU;
- }Core路TM_MX;
+ }Core路TM_NX;
+
+ //----------------------------------------
+ // TM_NX_Array: Array-Based Implementation
+ //----------------------------------------
+
+ // common error messages
+ const char *Core路TM_NX_Array路Msg路tm = "given NULL tm";
+ const char *Core路TM_NX_Array路Msg路flag = "given NULL flag pointer";
+ const char *Core路TM_NX_Array路Msg路address = "given NULL address";
+ const char *Core路TM_NX_Array路Msg路address_on_tape =
+ "given address is not on the tape"
+ ;
+ const char *Core路TM_NX_Array路Msg路extent = "given NULL extent pointer";
+
+ // 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->position) return Core路Tape路Topo路empty;
+ if(!tm->extent ) return Core路Tape路Topo路singleton;
+ return Core路Tape路Topo路segment;
+ }
+
+ Local Core路Status Core路TM_NX_Array路extent(Core路TM_NX *tm ,extent_t *extent){
+ Core路Tape路Topo t = Core路TM_NX_Array路topo(tm) & Core路Tape路Topo路finite_nz;
+ #ifdef Core路Debug
+ Core路Guard chk;
+ Core路Guard路fg.init(&chk ,"Core路TM_NX_Array路extent" ,Core路Flag路count);
+ Core路Guard路fg.check(
+ &chk ,0 ,t
+ ,"Tape does not exist or topology does not have an extent."
+ );
+ #endif
+ if(!t) return Core路Status路derailed;
+ *extent = tm->extent;
+ return Core路Status路on_track;
+ }
+
+ Local Core路Status Core路Area路mount_pe(
+ Core路TM_NX *tm ,Core路TM_NX路Address *position ,extent_t extent
+ ){
+ #ifdef Core路Debug
+ Core路Guard chk;
+ Core路Guard路fg.init(&chk ,"Core路TM_NX_Array路mount_pp" ,Core路Flag路count);
+ Core路Guard路fg.check(&chk ,1 ,tm ,Core路TM_NX_Array路Msg路tm);
+ Core路Guard路fg.check(&chk ,1 ,position ,"given NULL position");
+ Core路Guard路if_return(chk);
+ #endif
+ area->array.position = position->array.address;
+ area->array.extent = extent;
+ return Core路Status路on_track;
+ }
+
+ Local Core路Status Core路Area路mount_pp(
+ Core路TM_NX *tm ,Core路TM_NX路Address *position_left ,Core路TM_NX路Address *position_right
+ ){
+ #ifdef Core路Debug
+ Core路Guard chk;
+ Core路Guard路fg.init(&chk ,"Core路TM_NX_Array路mount_pp" ,Core路Flag路count);
+ Core路Guard路fg.check(&chk ,1 ,tm ,Core路TM_NX_Array路Msg路tm);
+ Core路Guard路fg.check(&chk ,1 ,position_left ,"given NULL position_left");
+ Core路Guard路fg.check(&chk ,1 ,position_right ,"given NULL position_right");
+ Core路Guard路if_return(chk);
+ #endif
+ tm->array.position = position_left->array.address;
+ tm->array.extent =
+ (extent_t)((uintptr_t)position_right->array.address
+ - (uintptr_t)position_left->array.address)
+ ;
+
+ return Core路Status路on_track;
+ }
+
+ bool Core路TM_NX_Array路encloses_pt(Core路TM_NX *tm ,Core路TM_NX路Address *a){
+ #ifdef Core路Debug
+ Core路Guard chk;
+ Core路Guard路fg.init(&chk ,"Core路TM_NX_Array路encloses_pt" ,Core路Flag路count);
+ Core路Guard路fg.check(&chk ,1 ,tm ,Core路TM_NX_Array路Msg路tm);
+ Core路Guard路fg.check(&chk ,1 ,pt ,"given NULL pt");
+ Core路Guard路if_return(chk);
+ #endif
+
+ return
+ (a->array.address >= tm->position)
+ && (a->array.address <= tm->position + tm->extent)
+ ;
+ }
+
+ Local bool Core路TM_NX_Array路encloses_pt_strictly(Core路TM_NX *tm ,Core路TM_NX路Address *a){
+ #ifdef Core路Debug
+ Core路Guard chk;
+ Core路Guard路fg.init(&chk ,"Core路TM_NX_Array路encloses_pt_strictly" ,Core路Flag路count);
+ Core路Guard路fg.check(&chk ,1 ,tm ,Core路TM_NX_Array路Msg路tm);
+ Core路Guard路fg.check(&chk ,1 ,a ,Core路TM_NX_Array路Msg路address);
+ Core路Guard路if_return(chk);
+ #endif
+
+ return (a->array.address > tm->array.position)
+ && (a->array.address < tm->array.position + tm->array.extent);
+ }
+
+ Local bool Core路TM_NX_Array路encloses_tm(Core路TM_NX *outer ,Core路TM_NX *inner){
+ #ifdef Core路Debug
+ Core路Guard chk;
+ Core路Guard路fg.init(&chk ,"Core路TM_NX_Array路encloses_tm" ,Core路Flag路count);
+ Core路Guard路fg.check(&chk ,1 ,outer ,"given NULL outer TM");
+ Core路Guard路fg.check(&chk ,1 ,inner ,"given NULL inner TM");
+ Core路Guard路if_return(chk);
+ #endif
+
+ return (inner->array.position >= outer->array.position)
+ && (inner->array.position + inner->array.extent <= outer->array.position + outer->array.extent);
+ }
+
+ Local bool Core路TM_NX_Array路encloses_tm_strictly(Core路TM_NX *outer ,Core路TM_NX *inner){
+ #ifdef Core路Debug
+ Core路Guard chk;
+ Core路Guard路fg.init(&chk ,"Core路TM_NX_Array路encloses_tm_strictly" ,Core路Flag路count);
+ Core路Guard路fg.check(&chk ,1 ,outer ,"given NULL outer TM");
+ Core路Guard路fg.check(&chk ,1 ,inner ,"given NULL inner TM");
+ Core路Guard路if_return(chk);
+ #endif
+
+ return (inner->array.position > outer->array.position)
+ && (inner->array.position + inner->array.extent < outer->array.position + outer->array.extent);
+ }
+
+ Local bool Core路TM_NX_Array路overlap(Core路TM_NX *a ,Core路TM_NX *b){
+ #ifdef Core路Debug
+ Core路Guard chk;
+ Core路Guard路fg.init(&chk ,"Core路TM_NX_Array路overlap" ,Core路Flag路count);
+ Core路Guard路fg.check(&chk ,1 ,a ,"given NULL TM A");
+ Core路Guard路fg.check(&chk ,1 ,b ,"given NULL TM B");
+ Core路Guard路if_return(chk);
+ #endif
+
+ return (a->array.position < b->array.position + b->array.extent)
+ && (b->array.position < a->array.position + a->array.extent);
+ }
+
+ Local Core路Status Core路TM_NX_Array路largest_aligned_64(
+ Core路TM_NX *outer ,Core路TM_NX *inner_64
+ ){
+ #ifdef Core路Debug
+ Core路Guard chk;
+ Core路Guard路fg.init(&chk ,"Core路TM_NX_Array路largest_aligned_64" ,Core路Flag路count);
+ Core路Guard路fg.check(&chk ,1 ,outer ,"given NULL outer TM");
+ Core路Guard路fg.check(&chk ,1 ,inner_64 ,"given NULL inner TM");
+ Core路Guard路if_return(chk);
+ #endif
+
+ uintptr_t p0 = (uintptr_t)outer->array.position;
+ uintptr_t p1 = (uintptr_t)outer->array.position + outer->array.extent;
+
+ AU *p0_64 = (AU *)( (p0 + 0x7) & ~(uintptr_t)0x7 );
+ AU *p1_64 = (AU *)( (p1 - 0x7) & ~(uintptr_t)0x7 );
+
+ if(p1_64 < p0_64){
+ inner_64->array.position = NULL;
+ inner_64->array.extent = 0;
+ return Core路Status路on_track;
+ }else{
+ inner_64->array.position = p0_64;
+ inner_64->array.extent = (extent_t)(p1_64 - p0_64);
+ return Core路Status路on_track;
+ }
+ }
- //----------------------------------------
- // TM_NX_Array: Array-Based Implementation
+
+
+ //-----------------------------------
+ // base Tape Machine operations
Core路TM路Head路Status *Core路TM_NX_Array路mount(Core路TM_NX *tm){
+ #ifdef Core路Debug
+ Core路Guard chk;
+ Core路Guard路fg.init(&chk ,"Core路TM_NX_Array路mount" ,Core路Flag路count);
+ Core路Guard路fg.check(&chk ,1 ,tm ,Core路TM_NX_Array路Msg路tm);
+ Core路Guard路if_return(chk);
+ #endif
+
+ // Implementation-specific mounting logic
+ tm->hd = tm->position;
+ return &tm->status;
}
+
Core路TM路Head路Status *Core路TM_NX_Array路dismount(Core路TM_NX *tm){
+ #ifdef Core路Debug
+ Core路Guard chk;
+ Core路Guard路fg.init(&chk ,"Core路TM_NX_Array路dismount" ,Core路Flag路count);
+ Core路Guard路fg.check(&chk ,1 ,tm ,Core路TM_NX_Array路Msg路tm);
+ Core路Guard路if_return(chk);
+ #endif
+
+ // Reset head position upon dismount
+ tm->hd = NULL;
+ return &tm->status;
}
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 *){
+ if(!tm) return Core路TM路Head路Status路mu;
+ if(tm->hd == NULL) return Core路TM路Head路Status路not_on_tape;
+ if(tm->hd == tm->position) return Core路TM路Head路Status路origin;
+ if( tm->hd == (tm->position + tm->extent - 1) )
+ return Core路TM路Head路Status路rightmost;
+ return Core路TM路Head路Status路interim;
}
- bool Core路TM_NX_Array路encloses_pt(Core路TM_NX *tm ,Core路TM_NX路Address *pt);
+ Local Core路Status Core路TM_NX_Array路can_read(Core路TM_NX *tm ,bool *flag){
+ *flag = tm && tm->hd != NULL;
+ return Core路Status路on_track;
+ }
Local Core路Status Core路TM_NX_Array路on_origin(
- Core路TM_NX *tm ,Core路TM_NX路Address *a ,bool *flag
+ Core路TM_NX *tm ,bool *flag
){
#ifdef Core路Debug
- uint error = 0;
- if( !tm ){
- fprintf(stderr,"Core路TM_NX_Array路is_origin:: given NULL tm");
- error++;
- }else if( !tm->address ){
- fprintf(stderr,"Core路TM_NX_Array路is_origin:: origin requested for empty tape");
- error++;
- }
- if( !flag ){
- fprintf(stderr,"Core路TM_NX_Array路is_origin:: NULL flag pointer");
- error++;
- }
- 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;
+ Core路Guard chk;
+ Core路Guard路fg.init(&chk ,"Core路TM_NX_Array路on_origin" ,Core路Flag路count);
+ Core路Guard路fg.check(&chk ,1 ,tm ,Core路TM_NX_Array路Msg路tm);
+ Core路Guard路fg.check(&chk ,1 ,flag ,Core路TM_NX_Array路Msg路flag);
+ Core路Guard路if_return(chk);
#endif
- *flag = ( tm->address == a );
+
+ *flag = (tm->hd == tm->position);
return Core路Status路on_track;
}
Local Core路Status Core路TM_NX_Array路on_rightmost(
- Core路TM_NX *tm ,Core路TM_NX路Address *a ,bool *result
+ Core路TM_NX *tm ,bool *flag
){
#ifdef Core路Debug
- uint error = 0;
- if( !tm ){
- fprintf(stderr,"Core路TM_NX_Array路is_rightmost:: given NULL tm");
- error++;
- }else if( !tm->address ){
- fprintf(stderr,"Core路TM_NX_Array路is_rightmost:: rightmost requested for empty tape");
- error++;
- }
- if( !result ){
- fprintf(stderr,"Core路TM_NX_Array路is_rightmost:: NULL result pointer");
- error++;
- }
- 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;
+ Core路Guard chk;
+ Core路Guard路fg.init(&chk ,"Core路TM_NX_Array路on_rightmost" ,Core路Flag路count);
+ Core路Guard路fg.check(&chk ,1 ,tm ,Core路TM_NX_Array路Msg路tm);
+ Core路Guard路fg.check(&chk ,1 ,flag ,Core路TM_NX_Array路Msg路flag);
+ Core路Guard路if_return(chk);
#endif
- *result = ( tm->address == ( tm->address + tm->extent ) );
+
+ *flag = tm->hd == (tm->address + tm->extent)
return Core路Status路on_track;
}
Local Core路Status Core路TM_NX_Array路read(
Core路TM_NX *tm ,Core路TM_NX路Address *a ,Core路Tape路Remote *remote
){
+ #ifdef Core路Debug
+ Core路Guard chk;
+ Core路Guard路fg.init(&chk ,"Core路TM_NX_Array路on_rightmost" ,Core路Flag路count);
+ Core路Guard路fg.check(&chk ,1 ,tm ,Core路TM_NX_Array路Msg路tm);
+ Core路Guard路fg.check(&chk ,1 ,flag ,Core路TM_NX_Array路Msg路flag);
+ Core路Guard路if_return(chk);
+ #endif
+
#ifdef Core路Debug
uint error = 0;
if( !tm ){
// step_right is a synonym for step
- // 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路TM_NX_Array路extent(Core路TM_NX *tm ,extent_t *extent_pt){
- #ifdef Core路Debug
- 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
- *write_pt = tm->extent;
- return Core路Status路on_track;
- }
-
- Local Core路Status Core路TM_NX_Array路set_position(
- Core路TM_NX *tm ,Core路TM_NX路Address *new_position
- ){
- #ifdef Core路Debug
- if( !tm ){
- fprintf(stderr, "Core路TM_NX_Array路set_position:: given NULL tape machine");
- return Core路Status路derailed;
- }
- #endif
- tm->array.hd = new_position->array.address;
- return Core路Status路on_track;
- }
-
- // 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( !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路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路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路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;
- }
-
-
-
-
- Local Core路Status Core路TM_NX_Array路set_extent(
- Core路TM_NX *tm ,extent_t extent
- ){
- #ifdef Core路Debug
- if( !tm ){
- fprintf(stderr, "Core路TM_NX_Array路set_extent:: given NULL tape machine");
- return Core路Status路derailed;
- }
- #endif
- tm->array.extent = extent;
- return Core路Status路on_track;
- }
-
- 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;
- }