Changeset 501


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

lisp: properly manage user functions and reactivate garbage collector.

Location:
abuse/trunk/src
Files:
4 edited

Legend:

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

    r497 r501  
    24872487
    24882488        game_net_init(argc, argv);
    2489 //        lisp_init(0x100000, 0x94000);
    24902489        lisp_init(0x80000, 0x94000);
    2491 //        lisp_init(0x20000, 0x94000);
    2492 //        lisp_init(0x100000, 0x10000);
    24932490
    24942491        dev_init(argc, argv);
  • 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
  • abuse/trunk/src/lisp/lisp.h

    r499 r501  
    154154struct LUserFunction : LObject
    155155{
    156 #ifndef NO_LIBS
    157     intptr_t alist, blist;      // id for cached blocks
    158 #else
    159     void *arg_list, *block_list;
    160 #endif
     156    LList *arg_list, *block_list;
    161157};
    162158
     
    238234LSysFunction *new_lisp_c_bool(int min_args, int max_args, int fun_number);
    239235
    240 #ifdef NO_LIBS
    241 LUserFunction *new_lisp_user_function(void *arg_list, void *block_list);
    242 #else
    243 LUserFunction *new_lisp_user_function(intptr_t arg_list, intptr_t block_list);
    244 #endif
     236LUserFunction *new_lisp_user_function(LList *arg_list, LList *block_list);
    245237
    246238LSysFunction *new_user_lisp_function(int min_args, int max_args, int fun_number);
  • abuse/trunk/src/lisp/lisp_gc.cpp

    r497 r501  
    148148        break;
    149149      case L_USER_FUNCTION:
    150 #ifndef NO_LIBS
    151         ret = new_lisp_user_function(((LUserFunction *)x)->alist,
    152                                      ((LUserFunction *)x)->blist);
    153 
    154 #else
    155         {
    156           LObject *arg = CollectObject(((LUserFunction *)x)->arg_list);
    157           LObject *block = CollectObject(((LUserFunction *)x)->block_list);
    158           ret = new_lisp_user_function(arg, block);
    159         }
    160 #endif
    161         break;
     150      {
     151        LUserFunction *fun = (LUserFunction *)x;
     152        LList *arg = (LList *)CollectObject(fun->arg_list);
     153        LList *block = (LList *)CollectObject(fun->block_list);
     154        ret = new_lisp_user_function(arg, block);
     155        break;
     156      }
    162157      case L_STRING:
    163158        ret = LString::Create(lstring_value(x));
     
    261256void collect_space(int which_space) // should be tmp or permanent
    262257{
    263   return; /* XXX: temporary hack */
    264 
    265258  int old_space = current_space;
    266259  cstart = space[which_space];
Note: See TracChangeset for help on using the changeset viewer.