chiark / gitweb /
indirect movpos method table
authorian <ian>
Sun, 11 May 2008 09:16:31 +0000 (09:16 +0000)
committerian <ian>
Sun, 11 May 2008 09:16:31 +0000 (09:16 +0000)
hostside/movpos.c

index dc283038013d39ee3d59247e4a7447c52cb79a52..a81abd0b0869483bd90b4fd8ebb6480c24ad9d6f 100644 (file)
@@ -30,7 +30,7 @@ typedef struct KindInfo KindInfo;
  */
 
 typedef struct MovPosChange {      /* valid in:   filled in by and when:     */
-  const KindInfo *ki;              /*  ARCDE       indep after allocate()    */
+  const KindInfo **ki;             /*  ARCDE       indep after allocate()    */
   Segment *move;                   /*  ARCDE       indep after allocate()    */
   MovPosComb actual;               /*  CD          see below                 */
   MovPosComb intent;               /*  RCD         indep after allocate()    */
@@ -512,6 +512,10 @@ void on_pic_charged(const PicInsnInfo *pii, const PicInsn *pi, int objnum) {
   pt_check_action();
 }
 
+static const KindInfo point_method= {
+  "point",  point_allocate,  point_reserve,  point_confirm,  point_destroy
+};
+
 /*========== dummy `nomove' kind ==========*/
 
 static Change *nomove_allocate(int alloc_motions) {
@@ -533,19 +537,23 @@ static ErrorCode nomove_confirm(Change *chg, Segment *move, int n_motions,
   return 0;
 }
 
+static const KindInfo nomove_method= {
+  "nomove", nomove_allocate, nomove_reserve, nomove_confirm, nomove_destroy
+};
+
 /*========== method-independent machinery ==========*/
 
-static const KindInfo methodinfos[]= {
{ "nomove", nomove_allocate, nomove_reserve, nomove_confirm, nomove_destroy },
{ "point",  point_allocate,  point_reserve,  point_confirm,  point_destroy  },
{ 0 },
- { 0 }
+static const KindInfo *methodinfos[]= {
 &nomove_method,
 &point_method,
 0,
+  0
 };
 
-static Change *mp_allocate(const KindInfo *ki, Segment *move,
+static Change *mp_allocate(const KindInfo **ki, Segment *move,
                           int alloc_motions, MovPosComb target) {
   assert(sta_state >= Sta_Resolving);
-  Change *chg= ki->allocate(alloc_motions);
+  Change *chg= (*ki)->allocate(alloc_motions);
   chg->ki=        ki;
   chg->move=      move;
   chg->intent=    target;
@@ -558,7 +566,7 @@ static int change_needed(const MovFeatInfo *feati,
   r= startpoint<0 ||
     (target - startpoint) / feati->weight % feati->posns;
   oprintf(DUPO("movpos/change-needed") "%s:%s(%d*%d) %d..%d => %d\n",
-         methodinfos[feati->kind].pname, feati->pname,
+         methodinfos[feati->kind]->pname, feati->pname,
          feati->posns, feati->weight,
          startpoint, target, r);
   return r;
@@ -593,7 +601,7 @@ static int evaluate_target(Segment *move, MovPosComb target,
 
   if (kind_r) *kind_r= kind;
   oprintf(DUPO("movpos/eval") "changes=%d kind=%s\n",
-         tchanges, methodinfos[kind].pname);
+         tchanges, methodinfos[kind]->pname);
   return tchanges;
 }
 
@@ -653,7 +661,7 @@ ErrorCode movpos_change(Segment *move, MovPosComb target,
          move->i->pname, posnpname(move,target),
          maxdelay_ms, posnpname(move, actual));
   if (chg) oprintf(DUPO("movpos/change") " chg=%s:%s/%s\n",
-                  chg->ki->pname, chg->move->i->pname,
+                  (*chg->ki)->pname, chg->move->i->pname,
                   posnpname(chg->move, chg->intent));
 
   { /* provide horizon for visibility of motions[] */
@@ -676,7 +684,7 @@ ErrorCode movpos_change(Segment *move, MovPosComb target,
       n_motions++;
     }
 
-    const KindInfo *ki= &methodinfos[kind];
+    const KindInfo **ki= &methodinfos[kind];
 
     if (chg) {
       if (chg->ki != ki ||
@@ -688,8 +696,9 @@ ErrorCode movpos_change(Segment *move, MovPosComb target,
     }
     chg->actual= actual;
 
-    oprintf(DUPO("movpos/change") "confirm %s:%d...\n", ki->pname, n_motions);
-    ec= ki->confirm(chg, move, n_motions, motions, maxdelay_ms);
+    oprintf(DUPO("movpos/change") "confirm %s:%d...\n",
+           (*ki)->pname, n_motions);
+    ec= (*ki)->confirm(chg, move, n_motions, motions, maxdelay_ms);
     oprintf(DUPO("movpos/change") "confirm => %s\n",errorcodelist[ec]);
     if (ec) goto x;
   }
@@ -714,10 +723,11 @@ movpos_reserve(Segment *move, int maxdelay_ms, MovPosChange **res_r,
   nchanges= evaluate_target(move,target,startpoint,&kind);
   if (nchanges==-1) return EC_MovFeatKindsCombination;
 
-  const KindInfo *ki= &methodinfos[kind];
-  oprintf(DUPO("movpos/reserve") "allocate %s:%d...\n", ki->pname, nchanges);
+  const KindInfo **ki= &methodinfos[kind];
+  oprintf(DUPO("movpos/reserve") "allocate %s:%d...\n",
+         (*ki)->pname, nchanges);
   Change *chg= mp_allocate(ki, move, nchanges, target);
-  ec= ki->reserve(chg, move, maxdelay_ms);
+  ec= (*ki)->reserve(chg, move, maxdelay_ms);
   oprintf(DUPO("movpos/reserve") "reserve => %s\n",errorcodelist[ec]);
   if (ec) goto x;
 
@@ -732,9 +742,9 @@ movpos_reserve(Segment *move, int maxdelay_ms, MovPosChange **res_r,
 void movpos_unreserve(MovPosChange *res) {
   if (!res) return;
   oprintf(DUPO("movpos/unreserve") "%s:%s/%s\n",
-         res->ki->pname, res->move->i->pname,
+         (*res->ki)->pname, res->move->i->pname,
          posnpname(res->move, res->intent));
-  res->ki->destroy(res);
+  (*res->ki)->destroy(res);
 }
 
 MovPosComb movpos_poscomb_actual(Segment *seg) {