Beispiel #1
0
void
Hash_serialize(Hash *self, OutStream *outstream) {
    Obj *key;
    Obj *val;
    uint32_t charbuf_count = 0;
    OutStream_Write_C32(outstream, self->size);

    // Write CharBuf keys first.  CharBuf keys are the common case; grouping
    // them together is a form of run-length-encoding and saves space, since
    // we omit the per-key class name.
    Hash_Iterate(self);
    while (Hash_Next(self, &key, &val)) {
        if (Obj_Is_A(key, CHARBUF)) {
            charbuf_count++;
        }
    }
    OutStream_Write_C32(outstream, charbuf_count);
    Hash_Iterate(self);
    while (Hash_Next(self, &key, &val)) {
        if (Obj_Is_A(key, CHARBUF)) {
            Obj_Serialize(key, outstream);
            FREEZE(val, outstream);
        }
    }

    // Punt on the classes of the remaining keys.
    Hash_Iterate(self);
    while (Hash_Next(self, &key, &val)) {
        if (!Obj_Is_A(key, CHARBUF)) {
            FREEZE(key, outstream);
            FREEZE(val, outstream);
        }
    }
}
Beispiel #2
0
void
Compiler_serialize(Compiler *self, OutStream *outstream) {
    ABSTRACT_CLASS_CHECK(self, COMPILER);
    OutStream_Write_F32(outstream, self->boost);
    FREEZE(self->parent, outstream);
    FREEZE(self->sim, outstream);
}
Beispiel #3
0
void
TermQuery_Serialize_IMP(TermQuery *self, OutStream *outstream) {
    TermQueryIVARS *const ivars = TermQuery_IVARS(self);
    Freezer_serialize_string(ivars->field, outstream);
    FREEZE(ivars->term, outstream);
    OutStream_Write_F32(outstream, ivars->boost);
}
Beispiel #4
0
void
PolyQuery_Serialize_IMP(PolyQuery *self, OutStream *outstream) {
    PolyQueryIVARS *const ivars = PolyQuery_IVARS(self);
    const uint32_t num_kids = (uint32_t)Vec_Get_Size(ivars->children);
    OutStream_Write_F32(outstream, ivars->boost);
    OutStream_Write_U32(outstream, num_kids);
    for (uint32_t i = 0; i < num_kids; i++) {
        Query *child = (Query*)Vec_Fetch(ivars->children, i);
        FREEZE(child, outstream);
    }
}
Beispiel #5
0
void
RangeQuery_serialize(RangeQuery *self, OutStream *outstream) {
    OutStream_Write_F32(outstream, self->boost);
    CB_Serialize(self->field, outstream);
    if (self->lower_term) {
        OutStream_Write_U8(outstream, true);
        FREEZE(self->lower_term, outstream);
    }
    else {
        OutStream_Write_U8(outstream, false);
    }
    if (self->upper_term) {
        OutStream_Write_U8(outstream, true);
        FREEZE(self->upper_term, outstream);
    }
    else {
        OutStream_Write_U8(outstream, false);
    }
    OutStream_Write_U8(outstream, self->include_lower);
    OutStream_Write_U8(outstream, self->include_upper);
}
Beispiel #6
0
void
RangeQuery_Serialize_IMP(RangeQuery *self, OutStream *outstream) {
    RangeQueryIVARS *const ivars = RangeQuery_IVARS(self);
    OutStream_Write_F32(outstream, ivars->boost);
    Freezer_serialize_string(ivars->field, outstream);
    if (ivars->lower_term) {
        OutStream_Write_U8(outstream, true);
        FREEZE(ivars->lower_term, outstream);
    }
    else {
        OutStream_Write_U8(outstream, false);
    }
    if (ivars->upper_term) {
        OutStream_Write_U8(outstream, true);
        FREEZE(ivars->upper_term, outstream);
    }
    else {
        OutStream_Write_U8(outstream, false);
    }
    OutStream_Write_U8(outstream, ivars->include_lower);
    OutStream_Write_U8(outstream, ivars->include_upper);
}
Beispiel #7
0
void
Freezer_serialize_hash(Hash *hash, OutStream *outstream) {
    uint32_t hash_size = Hash_Get_Size(hash);
    OutStream_Write_C32(outstream, hash_size);

    HashIterator *iter = HashIter_new(hash);
    while (HashIter_Next(iter)) {
        String *key = HashIter_Get_Key(iter);
        Obj    *val = HashIter_Get_Value(iter);
        Freezer_serialize_string(key, outstream);
        FREEZE(val, outstream);
    }
    DECREF(iter);
}
Beispiel #8
0
void
Freezer_serialize_varray(Vector *array, OutStream *outstream) {
    uint32_t last_valid_tick = 0;
    uint32_t size = (uint32_t)Vec_Get_Size(array);
    OutStream_Write_C32(outstream, size);
    for (uint32_t i = 0; i < size; i++) {
        Obj *elem = Vec_Fetch(array, i);
        if (elem) {
            OutStream_Write_C32(outstream, i - last_valid_tick);
            FREEZE(elem, outstream);
            last_valid_tick = i;
        }
    }
    // Terminate.
    OutStream_Write_C32(outstream, size - last_valid_tick);
}
Beispiel #9
0
void
VA_serialize(VArray *self, OutStream *outstream)
{
    u32_t i;
    u32_t last_valid_tick = 0;
    OutStream_Write_C32(outstream, self->size);
    for (i = 0; i < self->size; i++) {
        Obj *elem = self->elems[i];
        if (elem) {
            OutStream_Write_C32(outstream, i - last_valid_tick);
            FREEZE(elem, outstream);
            last_valid_tick = i;
        }
    }
    /* Terminate. */
    OutStream_Write_C32(outstream, self->size - last_valid_tick);
}
Beispiel #10
0
void FORTE_MotorPOS::executeEvent(int pa_nEIID){
  //TODO MotorPOS add error checks and  messages
  QO() = QI();
  switch (pa_nEIID){
    case scm_nEventINITID:
      if(true == QI()){
        if(PORT() <= 3){
          libcbc_init(); //TODO: only call once //initialises the CBC Library :)
          m_nPort = PORT();
          QO() = true; /* Turned on and No Error */
        }
        else{
          QO() = false;
        }
      }
      sendOutputEvent(scm_nEventINITOID);
      break;
    case scm_nEventREQID:
      if(true == QI()){
        if(true == RELPOS())
          mrp(m_nPort, 1000, POS());
        else
          mtp(m_nPort, 1000, POS());
      }
      sendOutputEvent(scm_nEventCNFID);
      break;
    case scm_nEventRSPID:
//TODO respond to IND
      break;
    case scm_nEventSTOPID:
      if(true == QI()){
        motor(m_nPort, 0);
        if(true == FREEZE()){
          freeze(m_nPort);
        }
        else{
          off(m_nPort);
        }
      }
      sendOutputEvent(scm_nEventSTOPOID);
      break;
  }
}
Beispiel #11
0
void W0939() // W0939
{
  _ro_SETUP_rc_(); // (SETUP)
  _ro_CS_ask__rc_(); // (CS?)
  Push(Read16(cc_DS)); // DS
  Store(); // !
  Push(0xf2d2);
  Push(Read16(cc_PSW)); // PSW
  Store(); // !
  Push(0x0701);
  Push(pp_OPERATOR); // OPERATOR
  Push(0x0074);
  CMOVE_2(); // CMOVE_2
  Push(Read16(user_DP)); // DP @
  Push(Read16(cc_INITIAL_dash_DPB)); // INITIAL-DPB
  Store(); // !
  _i_FORTH(); // 'FORTH
  Push(user_CONTEXT); // CONTEXT
  Store(); // !
  DEFINITIONS(); // DEFINITIONS
  FREEZE(); // FREEZE
  AUTO_dash_LIMIT(); // AUTO-LIMIT
  AUTO_dash_CACHE(); // AUTO-CACHE
  SP_ex_(); // SP!
  RP_ex_(); // RP!
  SET_dash_BUFFERS(); // SET-BUFFERS
  AUTO_dash_SCREEN(); // AUTO-SCREEN
  W0343(); // W0343
  Push(Read16(pp_BOOT_dash_HOOK)); // BOOT-HOOK @
  if (Read16(regsp) != 0) Push(Read16(regsp)); // ?DUP
  if (Pop() != 0)
  {
    EXECUTE(); // EXECUTE
  }
  Push(Read16(pp_BOOT_dash_LOAD)); // BOOT-LOAD @
  if (Read16(regsp) != 0) Push(Read16(regsp)); // ?DUP
  if (Pop() != 0)
  {
    Exec("LOAD_2"); // call of word 0x1e23 '(LOAD)'
  }
  W03C3(); // W03C3
  Exec("ABORT"); // call of word 0x1c45 '(ABORT)'
}
Beispiel #12
0
void SYSGEN() // SYSGEN
{
  Exec("CR"); // call of word 0x26ee '(CR)'
  FREEZE(); // FREEZE
  _ro_RESTORE_rc_(); // (RESTORE)
  SYSUTIL(); // SYSUTIL
  INIT(); // INIT
  MAKE_st_NAME_gt_(); // MAKE<NAME>
  _ro_CS_ask__rc_(); // (CS?)
  Push(0x0100);
  Push(pp_DTA); // DTA
  _2_ex__2(); // 2!_2
  DOS_dash_DTA(); // DOS-DTA
  HERE(); // HERE
  Push(Pop() - 0x0100); //  0x0100 -
  RECSIZE(); // RECSIZE
  Store(); // !
  WRITENEXT(); // WRITENEXT
  _ro_SETUP_rc_(); // (SETUP)
  IsUNRAVEL(); // ?UNRAVEL
  CLOSE(); // CLOSE
  IsUNRAVEL(); // ?UNRAVEL
}
Beispiel #13
0
    std::vector<Cell*>  MazeTile::validCells(unsigned int p,
                                             unsigned int q,
                        // p, q - position in the tilemap
                                             const TileMap& tm)
    {
        std::vector<Cell*> valid_cells(9);

        //   
        //   Locations of indices in the array:
        //         A                 B
        //          X TS [0] X TM [1] X TE [2]
        //          |               |
        //          X MS [3] X MM [4] X ME [5]
        //          |               |
        //          X BS [6] X BM [7] X BE [8]
        //         C                 D 
        //

        // constants as labels for indices in the array
        // KEY:
        //      T -> top
        //      M -> middle
        //      B -> bottom
        //      S -> start
        //      E -> end
        //          
        //          e.g.
        //              TS -> top row, start
        //              MM -> middle row, middle
        //
        const static unsigned int   TS = 0, TM = 1, TE = 2,
                                    MS = 3, MM = 4, ME = 5,
                                    BS = 6, BM = 7, BE = 8;

        std::vector<Cell*>::size_type vc_sz = valid_cells.size();
        for (std::size_t i = 0; i < vc_sz; ++i) {
            valid_cells[i] = new Cell;
        }

        const vector2& t_wp = worldPosition();

        //
        //  A(s[0], s[1]) ------ B(e[0], s[1])
        //       |                    |
        //       |                    |
        //       |                    |
        //  C(s[0], e[1]) ------ D(e[0], e[1])

        const vector2& S = t_wp;
        const vector2& E = t_wp + sz_;

        vector2     A = S,
                    B(E[0], S[1]),
                    C(S[0], E[1]),
                    D = E;

#define SET_CELL_POS(a, xy) (valid_cells[(a)])->screen_position = (xy)

#define MIDPOINT(a, b) (((a) + (b)) / 2)


        SET_CELL_POS(TS, A);
        SET_CELL_POS(TM, MIDPOINT(A, B));
        SET_CELL_POS(TE, B);

        SET_CELL_POS(MS, MIDPOINT(A, C));

        SET_CELL_POS(MM, MIDPOINT(A, D));

        SET_CELL_POS(ME, MIDPOINT(B, D));

        SET_CELL_POS(BS, C);
        SET_CELL_POS(BM, MIDPOINT(C, D));
        SET_CELL_POS(BE, D);

#define FREEZE(x)   (valid_cells[(x)])->solid = true
#define MELT(x)     (valid_cells[(x)])->solid = false

        if ((MAZECELL_HAS_NORTH(mc_)) ||
            (MAZECELL_HAS_SOUTH(mc_)) ||
            (MAZECELL_HAS_EAST(mc_))  ||
            (MAZECELL_HAS_WEST(mc_))) {
            MELT(MM);
        }

#define SET_CELL_ROW(a, b, c, wall_macro) do {\
                                                if (!wall_macro(mc_)) {\
                                                    FREEZE((a));\
                                                    FREEZE((b));\
                                                    FREEZE((c));\
                                                } else {\
                                                    MELT((a));\
                                                    MELT((b));\
                                                    MELT((c));\
                                               }\
                                            } while (0)

        SET_CELL_ROW(TS, TM, TE, MAZECELL_HAS_NORTH);
        SET_CELL_ROW(BS, BM, BE, MAZECELL_HAS_SOUTH);
        SET_CELL_ROW(TE, ME, BE, MAZECELL_HAS_EAST);
        SET_CELL_ROW(TS, MS, BS, MAZECELL_HAS_WEST);


        //
        // now the current cell (S) has been set, check the cells around it
        //
        //      (i - 1, j - 1)      (i, j - 1)      (i + 1, j - 1) 
        //      (i - 1, j)          S (i, j)        (i + 1, j)   
        //      (i - 1, j + 1)      (i, j + 1)      (i + 1, j + 1)
        //      
        MazeTile* adjt = 0;
        const MazeCell* xc = 0;

        adjt = static_cast<MazeTile*>(tm.tile(p - 1, q - 1));
        if (adjt != 0) {
            xc = &(adjt->mc());
            if ((!MAZECELL_HAS_EAST(*xc)) || (!MAZECELL_HAS_SOUTH(*xc))) {
                FREEZE(TS);
            }
        }

        adjt = static_cast<MazeTile*>(tm.tile(p, q - 1));
        if (adjt != 0) {
            xc = &(adjt->mc());
            if ((!MAZECELL_HAS_SOUTH(*xc))) {
                FREEZE(TS);
                FREEZE(TM);
                FREEZE(TE);
            }
        }

        adjt = static_cast<MazeTile*>(tm.tile(p + 1, q - 1));
        if (adjt != 0) {
            xc = &(adjt->mc());
            if ((!MAZECELL_HAS_WEST(*xc)) || (!MAZECELL_HAS_SOUTH(*xc))) {
                FREEZE(TE);
            }
        }

        adjt = static_cast<MazeTile*>(tm.tile(p - 1, q));
        if (adjt != 0) {
            xc = &(adjt->mc());
            if ((!MAZECELL_HAS_EAST(*xc))) {
                FREEZE(TS);
                FREEZE(MS);
                FREEZE(BS);
            }
        }

        adjt = static_cast<MazeTile*>(tm.tile(p + 1, q));
        if (adjt != 0) {
            xc = &(adjt->mc());
            if ((!MAZECELL_HAS_WEST(*xc))) {
                FREEZE(TE);
                FREEZE(ME);
                FREEZE(BE);
            }
        }

        adjt = static_cast<MazeTile*>(tm.tile(p - 1, q + 1));
        if (adjt != 0) {
            xc = &(adjt->mc());
            if ((!MAZECELL_HAS_NORTH(*xc)) ||(!MAZECELL_HAS_EAST(*xc))) {
                FREEZE(BS);
            }
        }

        adjt = static_cast<MazeTile*>(tm.tile(p, q + 1));
        if (adjt != 0) {
            xc = &(adjt->mc());
            if (!MAZECELL_HAS_NORTH(*xc)) {
                FREEZE(BS);
                FREEZE(BM);
                FREEZE(BE);
            }
        }
    
        adjt = static_cast<MazeTile*>(tm.tile(p + 1, q + 1));
        if (adjt != 0) {
            xc = &(adjt->mc());
            if ((!MAZECELL_HAS_NORTH(*xc)) ||(!MAZECELL_HAS_WEST(*xc))) {
                FREEZE(BE);
            }
        }

        return valid_cells;
    }