Changeset 2949

Show
Ignore:
Timestamp:
12/09/07 21:23:52 (13 months ago)
Author:
mokehehe
Message:

ガベコレを作り始める。
うまく動いてない。

Location:
lang/c/misc/mlisp/src
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lang/c/misc/mlisp/src/ml_builtin.c

    r2378 r2949  
    264264                                r = ml_read(ml, fp); 
    265265                                if (r == cEOF)  break; 
    266                                 ml_print(ml, stdout, r, FALSE); 
     266//                              ml_print(ml, stdout, r, FALSE); 
    267267 
    268268                                e = ml_eval(ml, r); 
    269                                 ml_print(ml, stdout, e, FALSE); 
     269//                              ml_print(ml, stdout, e, FALSE); 
    270270                        } 
    271271 
  • lang/c/misc/mlisp/src/mlisp.cpp

    r2945 r2949  
    7575        SExp car; 
    7676        SExp cdr; 
     77        bool unreach;                   // �K�x�R���p�F�����B�t���O 
    7778} Cell; 
    7879 
     
    142143 
    143144private: 
    144         void collect_garbage(); 
     145        void clear_all_mark();                                                  ///< ���ׂẴZ���𖢓��B�ɐݒ� void mark_cell(SExp sexp);                                              ///< �Z���Ƀ}�[�N������ċA�j 
     146        void collect_garbage();                                                 ///< �K�x�[�W�R���N�V���� 
    145147 
    146148        SExp read_string(FILE* fp); 
     
    251253        g_builtin_p = 0; 
    252254 
     255        clear_all_mark(); 
    253256                // �Z������‚Ȃ��āA�t���[�Z���Ƃ���        for (int i=0; i<MAX_CELL-1; ++i) { 
    254257                Cell* p = &g_cell_buf[i]; 
     
    298301} 
    299302 
     303void MLContext::clear_all_mark() 
     304{ 
     305        for (int i=0; i<MAX_CELL; ++i) { 
     306                Cell* p = &g_cell_buf[i]; 
     307                p->unreach = true; 
     308        } 
     309} 
     310 
     311void MLContext::mark_cell(SExp sexp) 
     312{ 
     313        int type = SEXP_TYPE(sexp); 
     314        if (type == tCell || type == tFunc) { 
     315                Cell* p = get_cell_ptr(sexp); 
     316                if (p->unreach) { 
     317                        p->unreach = false; 
     318                        mark_cell(p->car); 
     319                        mark_cell(p->cdr); 
     320                } 
     321        } 
     322} 
     323 
    300324void MLContext::collect_garbage() 
    301325{ 
    302         assert(!"not implemented"); 
     326        assert(!"���r���I"); 
     327 
     328        clear_all_mark(); 
     329 
     330                // �‹����炽�ǂ��Z���Ƀ}�[�N�����           // �O���[�o�� 
     331        for (int i=0; i<g_symbol_free_p; ++i) { 
     332                Symbol* p = &g_symbol_buf[i]; 
     333                mark_cell(p->sexp); 
     334        } 
     335                // �X�^�b�N 
     336        for (int i=0; i<g_stack_p; ++i) { 
     337                SExp sexp = g_stack[i]; 
     338                mark_cell(sexp); 
     339        } 
     340 
     341                // �}�[�N�̂‚��ĂȂ��Z�����Exp free = cNil; 
     342        for (int i=0; i<MAX_CELL; ++i) { 
     343                Cell* p = &g_cell_buf[i]; 
     344                if (p->unreach) { 
     345                        SExp t = MAKE_SEXP(tCell, i); 
     346                        Cell* p = get_cell_ptr(t); 
     347                        p->cdr = free; 
     348                        free = t; 
     349                        ++free_cell_num; 
     350                } 
     351        } 
     352        g_free_cell = free; 
    303353} 
    304354 
     
    317367 
    318368        Cell* p = &g_cell_buf[idx]; 
     369        assert(p->unreach); 
    319370        p->car = a; 
    320371        p->cdr = d; 
     372        p->unreach = false; 
    321373 
    322374        return MAKE_SEXP(tCell, idx);