Ignore:
Timestamp:
Apr 18, 2011, 3:22:27 AM (11 years ago)
Author:
Sam Hocevar
Message:

lisp: properly manage user functions and reactivate garbage collector.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • abuse/trunk/src/lisp/lisp.cpp

    r499 r501  
    180180void *lmalloc(int size, int which_space)
    181181{
    182   return malloc(size); /* XXX: temporary hack */
    183 
    184182#ifdef WORD_ALIGN
    185183  size=(size+3)&(~3);
     
    355353}
    356354
    357 #ifdef NO_LIBS
    358 LUserFunction *new_lisp_user_function(void *arg_list, void *block_list)
     355LUserFunction *new_lisp_user_function(LList *arg_list, LList *block_list)
    359356{
    360357    PtrRef r1(arg_list), r2(block_list);
     
    370367    return lu;
    371368}
    372 #else
    373 LUserFunction *new_lisp_user_function(intptr_t arg_list, intptr_t block_list)
    374 {
    375     // Make sure all functions get defined in permanent space
    376     int sp = current_space;
    377     if (current_space != GC_SPACE)
    378         current_space = PERM_SPACE;
    379 
    380     size_t size = sizeof(LUserFunction);
    381     if (size < sizeof(LRedirect))
    382         size = sizeof(LRedirect);
    383 
    384     LUserFunction *lu = (LUserFunction *)lmalloc(size, current_space);
    385     lu->type = L_USER_FUNCTION;
    386     lu->alist = arg_list;
    387     lu->blist = block_list;
    388 
    389     current_space = sp;
    390 
    391     return lu;
    392 }
    393 #endif
    394369
    395370LSysFunction *new_lisp_sys_function(int min_args, int max_args, int fun_number)
     
    21482123    {
    21492124        LSymbol *symbol = (LSymbol *)CAR(arg_list);
     2125        PtrRef r1(symbol);
    21502126#ifdef TYPE_CHECKING
    21512127        if (item_type(symbol) != L_SYMBOL)
     
    21652141        LObject *block_list = CDR(CDR(arg_list));
    21662142
    2167 #ifndef NO_LIBS
    2168         intptr_t a = cache.reg_lisp_block(lcar(lcdr(arg_list)));
    2169         intptr_t b = cache.reg_lisp_block(block_list);
    2170         LUserFunction *ufun = new_lisp_user_function(a, b);
    2171 #else
    2172         LUserFunction *ufun = new_lisp_user_function(lcar(lcdr(arg_list)), block_list);
    2173 #endif
     2143        LUserFunction *ufun = new_lisp_user_function((LList *)lcar(lcdr(arg_list)), (LList *)block_list);
    21742144        symbol->SetFunction(ufun);
    21752145        ret = symbol;
     
    30022972void use_user_space(void *addr, long size)
    30032973{
    3004     current_space = 2;
     2974    current_space = USER_SPACE;
    30052975    free_space[USER_SPACE] = space[USER_SPACE] = (uint8_t *)addr;
    30062976    space_size[USER_SPACE] = size;
     
    30353005#endif
    30363006
    3037 #ifndef NO_LIBS
    3038     void *fun_arg_list = cache.lblock(fun->alist);
    3039     void *block_list = cache.lblock(fun->blist);
     3007    LList *fun_arg_list = fun->arg_list;
     3008    LList *block_list = fun->block_list;
    30403009    PtrRef r9(block_list), r10(fun_arg_list);
    3041 #else
    3042     void *fun_arg_list = fun->arg_list;
    3043     void *block_list = fun->block_list;
    3044     PtrRef r9(block_list), r10(fun_arg_list);
    3045 #endif
    30463010
    30473011    // mark the start start, so we can restore when done
     
    30533017    PtrRef r19(arg_list);
    30543018
    3055     for (f_arg = (LObject *)fun_arg_list; f_arg; f_arg = CDR(f_arg))
     3019    for (f_arg = fun_arg_list; f_arg; f_arg = CDR(f_arg))
    30563020    {
    30573021        LSymbol *s = (LSymbol *)CAR(f_arg);
     
    30643028        int i = new_start;
    30653029        // now push all the values we wish to gather
    3066         for (f_arg = (LObject *)fun_arg_list; f_arg; f_arg = CDR(f_arg))
     3030        for (f_arg = fun_arg_list; f_arg; f_arg = CDR(f_arg))
    30673031        {
    30683032            if (!arg_list)
     
    30773041
    30783042        // now store all the values and put them into the symbols
    3079         for (f_arg = (LObject *)fun_arg_list; f_arg; f_arg = CDR(f_arg))
     3043        for (f_arg = fun_arg_list; f_arg; f_arg = CDR(f_arg))
    30803044            ((LSymbol *)CAR(f_arg))->SetValue((LObject *)l_user_stack.sdata[i++]);
    30813045
     
    30943058    {
    30953059        ret = CAR(block_list)->Eval();
    3096         block_list = CDR(block_list);
     3060        block_list = (LList *)CDR(block_list);
    30973061    }
    30983062
    30993063    long cur_stack = stack_start;
    3100     for (f_arg = (LObject *)fun_arg_list; f_arg; f_arg = CDR(f_arg))
     3064    for (f_arg = fun_arg_list; f_arg; f_arg = CDR(f_arg))
    31013065        ((LSymbol *)CAR(f_arg))->SetValue((LObject *)l_user_stack.sdata[cur_stack++]);
    31023066
Note: See TracChangeset for help on using the changeset viewer.