Ejemplo n.º 1
0
int secd_dump_state(secd_t *secd, cell_t *fname) {
    cell_t *p = secd_newport(secd, "w", "file", fname);
    secd_pprintf(secd, p,
                 ";; secd->fixedptr = %ld\n", cell_index(secd, secd->fixedptr));
    secd_pprintf(secd, p,
                 ";; secd->arrayptr = %ld\n", cell_index(secd, secd->arrayptr));
    secd_pprintf(secd, p,
                 ";; secd->end      = %ld\n", cell_index(secd, secd->end));
    secd_pprintf(secd, p, ";; secd->input_port = %ld, secd->output_port = %ld\n",
                 cell_index(secd, secd->input_port), cell_index(secd, secd->output_port));
    secd_pprintf(secd, p, ";; SECD = (%ld, %ld, %ld, %ld)\n",
                 cell_index(secd, secd->stack), cell_index(secd, secd->env),
                 cell_index(secd, secd->control), cell_index(secd, secd->dump));
    secd_pprintf(secd, p, ";; secd->free = %ld (%ld free)\n",
                 cell_index(secd, secd->free), secd->stat.free_cells);
    /* dump fixed heap */
    long i;
    long n_fixed = secd->fixedptr - secd->begin;
    secd_pprintf(secd, p, "\n;; SECD persistent heap:\n");
    for (i = 0; i < n_fixed; ++i) {
        cell_t *cell_info = serialize_cell(secd, secd->begin + i);
        sexp_pprint(secd, p, cell_info);
        secd_pprintf(secd, p, "\n");
        free_cell(secd, cell_info);
    }

    secd_pprintf(secd, p, "\n;; SECD array heap:\n");
    cell_t *mcons = secd->arrlist;
    while (mcons_next(mcons)) {
        cell_t *cell_info = serialize_cell(secd, mcons);
        sexp_pprint(secd, p, cell_info);
        if (!mcons->as.mcons.free)
            secd_pdump_array(secd, p, mcons);
        secd_pprintf(secd, p, "\n");
        free_cell(secd, cell_info);

        mcons = mcons_next(mcons);
    }

    secd_pclose(secd, p);
    free_cell(secd, p);
    return 0;
}
Ejemplo n.º 2
0
int secd_pdump_array(secd_t *secd, cell_t *p, cell_t *mcons) {
    if (mcons->as.mcons.cells) {
        secd_pprintf(secd, p, " #(");
        cell_t *mem = meta_mem(mcons);
        size_t len = arrmeta_size(secd, mcons);
        size_t i;
        for (i = 0; i < len; ++i) {
            cell_t *item_info = serialize_cell(secd, mem + i);
            sexp_pprint(secd, p, item_info);
            free_cell(secd, item_info);
        }
        secd_pprintf(secd, p, ")");
    } else {
        sexp_print_bytes(secd, p, (char *)(mcons + 1),
                                   sizeof(cell_t) * arrmeta_size(secd, mcons));
    }
    return 0;
}
Ejemplo n.º 3
0
BUFFER* serialize_labyrinthe_to_buffer(Labyrinthe* lab, size_t* sizeOfBuffer) {
    BUFFER *buffer = NULL, *pBuffer = NULL;
    Laby_Cell_str_t** cells;
    int i,j;

    if(lab == NULL)
        return NULL;
    if(lab->donnees == NULL)
        return NULL;


    /* MAGIC_BYTE + 2x4 octets + (4*2 + 2*1) octets par cellules */
    if(sizeOfBuffer != NULL)
        *sizeOfBuffer =  1*sizeof(uint8_t) +   2*sizeof(int) + lab->nbcolonnes*lab->nblignes*(4*sizeof(uint16_t) + 2*sizeof(uint8_t));
    buffer = (BUFFER*)malloc(1*sizeof(uint8_t) + 2*sizeof(int) + lab->nbcolonnes*lab->nblignes*(4*sizeof(uint16_t) + 2*sizeof(uint8_t)));
    if(buffer == NULL)
        return NULL;

    pBuffer = buffer;

    *((uint8_t*)pBuffer) = MAGIC_BYTE;
    pBuffer = ((char*)pBuffer) + sizeof(uint8_t);

    memcpy(pBuffer, &(lab->nblignes), sizeof(int));
    pBuffer = ((char*)pBuffer) + sizeof(int);
    memcpy(pBuffer, &(lab->nbcolonnes), sizeof(int));
    pBuffer = ((char*)pBuffer) + sizeof(int);

    cells = (Laby_Cell_str_t**)lab->donnees;

    for(i = 0; i < lab->nblignes; i++)
        for(j = 0; j < lab->nbcolonnes; j++)
            pBuffer = serialize_cell(pBuffer, &cells[i][j]);



    return buffer;
}