Ejemplo n.º 1
0
void test_priv_free(void) {
    Manual mem = (Manual) priv_imalloc(1 Mb, MANUAL + ASCENDING_SIZE);
    Priv_mem new_mem = style_to_priv((Memory) mem);
    mem->alloc((Memory) mem, 1 Kb);
    void *temp = mem->alloc((Memory) mem, 2 Kb);
    mem->alloc((Memory) mem, 1 Kb);
    CU_ASSERT(memory_start(search_memory(temp, new_mem->lists->alloclist, FALSE)) == temp);
    CU_ASSERT(priv_free((Memory) mem, temp) == 2 Kb);
    CU_ASSERT(memory_start(search_memory(temp, new_mem->lists->alloclist, FALSE)) == NULL);

    free_lists(new_mem->lists);
    free(new_mem->as->start);
    free(new_mem);
}
Ejemplo n.º 2
0
void test_avail(void) {
    Manual mem = (Manual) priv_imalloc(1 Mb, MANUAL + ASCENDING_SIZE);
    mem->alloc((Memory) mem, 1 Kb);
    void *temp = mem->alloc((Memory) mem, 1 Kb);
    mem->alloc((Memory) mem, 1 Kb);
    CU_ASSERT(priv_free((Memory) mem, temp) == 1 Kb);
    CU_ASSERT(avail((Memory) mem) == 1 Mb - 3 * 1 Kb);
    mem->alloc((Memory) mem, 1 Mb - 3 * 1 Kb);
    CU_ASSERT(avail((Memory) mem) == 1 Kb);

    Priv_mem new_mem = style_to_priv((Memory) mem);
    free_lists(new_mem->lists);
    free(new_mem->as->start);
    free(new_mem);
}
Ejemplo n.º 3
0
void test_manual_alloc(void) {
    Manual mem = (Manual) priv_imalloc(1 Mb, MANUAL + ASCENDING_SIZE);
    mem->alloc((Memory) mem, 1 Kb);
    Priv_mem new_mem = style_to_priv((Memory) mem);
    CU_ASSERT(new_mem->lists->freelist->size == 1 Mb - 1 Kb);
    CU_ASSERT(new_mem->lists->alloclist->size == 1 Kb);
    mem->alloc((Memory) mem, 1 Mb - 1 Kb);
    CU_ASSERT(new_mem->lists->freelist == NULL);
    CU_ASSERT(new_mem->lists->alloclist->size == 1 Mb - 1 Kb);
    CU_ASSERT(new_mem->lists->alloclist->next->size == 1 Kb);

    free_lists(new_mem->lists);
    free(new_mem->as->start);
    free(new_mem);
}
Ejemplo n.º 4
0
// 인자로 주어진 파일로부터 한문장씩 읽어 이를 번역
void doTranslate(char* pInFile, Manual& out, int wantedLang)
{
	ifstream ifs(pInFile);
	if (!ifs)
	{
		cout << "Can't open file : " << pInFile << endl;
		return;
	}
	string result;
	Sentence next;
	while (!(next = getSentence(ifs)).getString().empty())
	{
		switch (next.getType())
		{
		case NORMAL_SENTENCE: // 평서문
			result = TransNormalSentence(next.getString(), wantedLang);
			break;
		case INTERROGATIVE_SENTENCE: // 의문문
			result = TransInterrogativeSentence(next.getString(), wantedLang);
			break;
		case IMPERATIVE_SENTENCE: // 명령문
			result = TransImperativeSentence(next.getString(), wantedLang);
			break;
		default:
			cout << "Untranslatable sentence type" << endl;
			return;
		}
		out.addContents(result);

	}
}
Ejemplo n.º 5
0
int main() {
  SET_STACK_BOTTOM CURRENT_SP(__g_stack_bottom__);
  Manual manMem = (Manual) iMalloc(10 Kb, MANUAL + ADDRESS);
  printf("%d\n", manMem->avail((Memory) manMem));
  char *point = manMem->alloc((Memory) manMem, sizeof(char*)*4);
  strcpy(point, "hej\0");
  printf("%s\n", point);
  char *point2 = manMem->alloc((Memory) manMem, sizeof(void*));
  strcpy(point2, "hejsan\0");
  printf("%s\n", point2);
  printf("%d\n", manMem->avail((Memory) manMem));
  manMem->free((Memory) manMem, point);
  manMem->free((Memory) manMem, point2);
  printf("%d\n", manMem->avail((Memory) manMem));
  
  Managed mgrMem = (Managed) iMalloc(10 Kb, GCD + REFCOUNT + ADDRESS);
  Tree t = mgrMem->alloc((Memory) mgrMem, sizeof(tree));
  Tree t1 = mgrMem->alloc((Memory) mgrMem, sizeof(tree));
  Tree t2 = mgrMem->alloc((Memory) mgrMem, sizeof(tree));
  Tree t3 = mgrMem->alloc((Memory) mgrMem, sizeof(tree));
  Tree t4 = mgrMem->alloc((Memory) mgrMem, sizeof(tree));
 
  t->current = 5;
  t1->current = 3;
  t2->current = 6;
  t->l = t1;
  t->r = t2;
  t2->l = t4;
  t4 = NULL;
  t3 = NULL;
  mgrMem->gc.collect((Memory) mgrMem);
  void *p  = mgrMem->gc.alloc((Memory) mgrMem,"i\0");
  mgrMem->rc.retain(p);
  printf("%d\n", mgrMem->rc.count(p));
  mgrMem->rc.release((Memory) mgrMem, p);
  mgrMem->rc.release((Memory) mgrMem, p);
  
    return 0;
    }
Ejemplo n.º 6
0
int main()
{
	Manual out;
	doTranslate("input.txt", out, TO_ENGLISH);
	cout << out.getContents() << endl;
}