Exemplo n.º 1
0
void symbolTableDispose(tSymbolTable* symbolTable){//je treba tyhle veci delat kdyz mame mmu?
    if (symbolTable==NULL) return;
    //projit stromem a zavolat functionDispose - zatim je tu memory leak
    btFree(&(symbolTable->functions));
    mmuFree(symbolTable);
    symbolTable=NULL;

}
Exemplo n.º 2
0
E_CODE listDeleteFirst(tList *L){
    if(L->first==NULL) return ERROR_OK;
    if(L->first==L->last)L->last=NULL;
    tListItem *tmp=L->first;
    L->first=L->first->next;
    mmuFree(tmp);
    return ERROR_OK;
}
Exemplo n.º 3
0
E_CODE functionInsertSymbol(tFunction* function,tString symbolname){
    tSymbol *symb=mmuMalloc(sizeof(tSymbol));
    strCopyString(&symbolname,&(symb->key));
    //symb->type=DT_UNKNOWN;
    symb->data=NULL;
    E_CODE err=BTInsert(&(function->symbols),&(symb->key),symb);
    if (err!=ERROR_OK){strFree(&(symb->key));mmuFree(symb);}
    return err;
}
Exemplo n.º 4
0
/**
 * @info      Uvolni string
 * @param   tString - struktura s polem a jeho rozmery
 * @return  E_CODE - chybovy kod
 */
E_CODE strFree (tString *str)
{
  if (str->data)
    mmuFree(str->data);
  str->data = NULL;
  str->alloc = 0;
  str->len = 0;

  return ERROR_OK;
}
Exemplo n.º 5
0
void gameboyFree(Gameboy *gameboy)
{
	cpuFree(gameboy->cpu);
	mmuFree(gameboy->mmu);
	free(gameboy->cpu);
	free(gameboy->mmu);
	free(gameboy->timer);
	free(gameboy->display);
	free(gameboy->joypad);
}
Exemplo n.º 6
0
E_CODE symbolTableInsertFunction(tSymbolTable* symbolTable, tString functionName){
    tFunction *func=mmuMalloc(sizeof(tFunction));
    strCopyString(&functionName,&(func->name)); // jmeno fce
    btInit(&(func->symbols)); // symboly
    initList(&(func->instructions)); // instrukce
    initList(&(func->constants));
    func->called=1;
    E_CODE err=BTInsert(&(symbolTable->functions),&(func->name),func);
    if (err!=ERROR_OK){strFree(&(func->name));mmuFree(func);}
    return err;
}
Exemplo n.º 7
0
tSymbol * functionInsertConstant(tFunction *function,tString data,tKeyword type){
    if(function==NULL)return NULL;
    tSymbol *symb=mmuMalloc(sizeof(tSymbol));
    if (symb == NULL) return NULL;

    symb->data=mmuMalloc(sizeof(tSymbolData));
    if (symb->data == NULL) return NULL;

    switch(type){
        case LEX_STRING:{
            symb->data->type = DT_STRING;
            if (strCopyString(&data,&(symb->data->data.sData)) != ERROR_OK)
              {return NULL;}
        }
        break;
        case LEX_NUMBER:{
            char *endptr = NULL;
            symb->data->type = DT_NUMBER;
            symb->data->data.dData=strtod(data.data, &endptr); // ATOF SE NEPOUZIVA, je to HNUSNA fce
            if (*endptr != '\0' || strcmp(endptr, data.data) == 0) {
              //*err = ERROR_SYNTAX; // toto je nejspis neco jinyho, ty tu kua nemas err...a ani ho nemas jak vratit
              mmuFree(symb);
              return NULL;
            }
        }
        break;
        case KW_NIL:{
            symb->data->type = DT_NIL;
        }
        break;
        case KW_TRUE:{
            symb->data->type = DT_BOOL;
            symb->data->data.bData = TRUE;
        }
        break;
        case KW_FALSE:{
            symb->data->type = DT_BOOL;
            symb->data->data.bData = FALSE;
        }
        break;
        case LEX_ID:{ //funkce pro TypeOf
            symb->data->type = DT_FUNCTION;
        }
        break;
        default: return NULL;
    }
    symb->key.data=NULL;
    listInsertLast(&(function->constants),symb);
    return symb;
}
Exemplo n.º 8
0
/**
 * @info      Hlavni fce, ktera uklidi, co se neuklidilo rucne
 * @return  void
 */
void mmuGlobalFree(){
    if(!mmuTable.table && !mmuTable.table->data)
        return;

    tMMUTableItemPtr head = NULL;
    tMMUTableItemPtr item = NULL;

    //Pro kazdy mozny radek pametove tabulky
    for(unsigned int i = 0; i < mmuTable.table->size; i++){
        if(mmuTable.table->data[i] != 0){
            head = mmuTable.table->data[i];

            while((item = head)){
                head = head->next;
                //printf("GLOBAL FREE: [%d] %lu -> %lu\n", i, (intptr_t)item, (intptr_t)item->next);

                if(item->allocated != 0){
                    if(item->type == MMU_FILE)
                        mmuFclose(item->ptr);
                    else
                        mmuFree(item->ptr);
                }

                mmuTableItemDestroy(item);

                mmuTable.table->data[i] = head;
            }

            mmuTable.table->data[i] = NULL;
        }
    }

    //Uvolnime vnitrni pole pametove tabulky
    mmuTableDispose(mmuTable.table);

    //Uvolnime pametovou tabulku
    mmuTableDestroy(mmuTable.table);

    mmuTable.table = NULL;

    /*
    printf("\n\n---------------------------- MMU report ---------------------------\n");
    printf("Memmory (malloc/calloc/realloc/free): %lu/%lu/%lu/%lu\n", mmuTable.mallocs, mmuTable.callocs, mmuTable.reallocs, mmuTable.frees);
    printf("Files (open/close): %lu/%lu\n", mmuTable.fopens, mmuTable.fcloses);
    printf("Total allocated memory: %lu bytes\n", mmuTable.allocated);
    printf("-------------------------------------------------------------------\n");
    */
}
Exemplo n.º 9
0
void deleteNodes(tBTNode N){
    if(N->left!=NULL)deleteNodes(N->left);
    if(N->right!=NULL)deleteNodes(N->right);
    mmuFree(N);
}