Changeset 499


Ignore:
Timestamp:
Apr 17, 2011, 11:57:07 PM (7 years ago)
Author:
Sam Hocevar
Message:

lisp: implement LSymbol::EvalUserFunction? and ensure all local pointers
are protected against collection.

Location:
abuse/trunk/src
Files:
5 edited

Legend:

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

    r494 r499  
    119119    push_onto_list(LNumber::Create(o->aitype()),call_list);
    120120    push_onto_list(LPointer::Create(o),call_list);
    121     eval_user_fun((LSymbol *)l_fire_object,call_list);
     121    ((LSymbol *)l_fire_object)->EvalUserFunction((LList *)call_list);
    122122    o->set_state((character_state)S_weapon_fire);
    123123  }
  • abuse/trunk/src/lisp/lisp.cpp

    r498 r499  
    14601460        break;
    14611461    case L_USER_FUNCTION:
    1462         return (LObject *)eval_user_fun(this, arg_list);
     1462        return EvalUserFunction((LList *)arg_list);
    14631463    default:
    14641464        Print();
     
    15061506        break;
    15071507    case L_USER_FUNCTION:
    1508         return (LObject *)eval_user_fun(this, arg_list);
     1508        return EvalUserFunction((LList *)arg_list);
    15091509    case L_C_FUNCTION:
    15101510    case L_C_BOOL:
     
    27732773        if (x < 0 || x >= (int32_t)strlen(st))
    27742774        {
    2775             lbreak("elt : out of range of string\n");
     2775            lbreak("elt: out of range of string\n");
    27762776            ret = NULL;
    27772777        }
     
    27822782    case SYS_FUNC_LISTP:
    27832783    {
    2784         ltype t = item_type(CAR(arg_list)->Eval());
     2784        LObject *tmp = CAR(arg_list)->Eval();
     2785        ltype t = item_type(tmp);
    27852786        ret = (t == L_CONS_CELL) ? true_symbol : NULL;
    27862787        break;
     
    27882789    case SYS_FUNC_NUMBERP:
    27892790    {
    2790         ltype t = item_type(CAR(arg_list)->Eval());
     2791        LObject *tmp = CAR(arg_list)->Eval();
     2792        ltype t = item_type(tmp);
    27912793        ret = (t == L_NUMBER || t == L_FIXED_POINT) ? true_symbol : NULL;
    27922794        break;
     
    27962798        LObject *init_var = CAR(arg_list);
    27972799        PtrRef r1(init_var);
    2798         int ustack_start = l_user_stack.son;      // restore stack at end
     2800        int ustack_start = l_user_stack.son; // restore stack at end
    27992801        LSymbol *sym = NULL;
    28002802        PtrRef r2(sym);
     
    28682870    }
    28692871    case SYS_FUNC_SYMBOLP:
    2870         if (item_type(CAR(arg_list)->Eval()) == L_SYMBOL)
    2871             ret = true_symbol;
    2872         break;
     2872    {
     2873        LObject *tmp = CAR(arg_list)->Eval();
     2874        ret = (item_type(tmp) == L_SYMBOL) ? true_symbol : NULL;
     2875        break;
     2876    }
    28732877    case SYS_FUNC_NUM2STR:
    28742878    {
     
    29882992void tmp_space()
    29892993{
    2990   current_space=TMP_SPACE;
     2994    current_space = TMP_SPACE;
    29912995}
    29922996
    29932997void perm_space()
    29942998{
    2995   current_space=PERM_SPACE;
     2999    current_space = PERM_SPACE;
    29963000}
    29973001
    29983002void use_user_space(void *addr, long size)
    29993003{
    3000   current_space = 2;
    3001   free_space[USER_SPACE] = space[USER_SPACE] = (uint8_t *)addr;
    3002   space_size[USER_SPACE] = size;
    3003 }
    3004 
    3005 
    3006 void *eval_user_fun(LSymbol *sym, void *arg_list)
    3007 {
    3008   void *ret=NULL;
    3009   PtrRef ref1(ret);
     3004    current_space = 2;
     3005    free_space[USER_SPACE] = space[USER_SPACE] = (uint8_t *)addr;
     3006    space_size[USER_SPACE] = size;
     3007}
     3008
     3009/* PtrRef check: OK */
     3010LObject *LSymbol::EvalUserFunction(LList *arg_list)
     3011{
     3012    LObject *ret = NULL;
     3013    PtrRef ref1(ret);
    30103014
    30113015#ifdef TYPE_CHECKING
    3012   if (item_type(sym)!=L_SYMBOL)
    3013   {
    3014     ((LObject *)sym)->Print();
    3015     lbreak("EVAL : is not a function name (not symbol either)");
    3016     exit(0);
    3017   }
     3016    if (item_type(this) != L_SYMBOL)
     3017    {
     3018        Print();
     3019        lbreak("EVAL : is not a function name (not symbol either)");
     3020        exit(0);
     3021    }
    30183022#endif
    30193023#ifdef L_PROFILE
    3020   time_marker start;
    3021 #endif
    3022 
    3023 
    3024   LUserFunction *fun=(LUserFunction *)(((LSymbol *)sym)->function);
     3024    time_marker start;
     3025#endif
     3026
     3027    LUserFunction *fun = (LUserFunction *)function;
    30253028
    30263029#ifdef TYPE_CHECKING
    3027   if (item_type(fun)!=L_USER_FUNCTION)
    3028   {
    3029     ((LObject *)sym)->Print();
    3030     lbreak("is not a user defined function\n");
    3031   }
     3030    if (item_type(fun) != L_USER_FUNCTION)
     3031    {
     3032        Print();
     3033        lbreak("is not a user defined function\n");
     3034    }
    30323035#endif
    30333036
    30343037#ifndef NO_LIBS
    3035   void *fun_arg_list=cache.lblock(fun->alist);
    3036   void *block_list=cache.lblock(fun->blist);
    3037   PtrRef r9(block_list), r10(fun_arg_list);
     3038    void *fun_arg_list = cache.lblock(fun->alist);
     3039    void *block_list = cache.lblock(fun->blist);
     3040    PtrRef r9(block_list), r10(fun_arg_list);
    30383041#else
    3039   void *fun_arg_list=fun->arg_list;
    3040   void *block_list=fun->block_list;
    3041   PtrRef r9(block_list), r10(fun_arg_list);
    3042 #endif
    3043 
    3044 
    3045 
    3046   // mark the start start, so we can restore when done
    3047   long stack_start=l_user_stack.son;
    3048 
    3049   // first push all of the old symbol values
    3050   void *f_arg=fun_arg_list;
    3051   PtrRef r18(f_arg);
    3052   PtrRef r19(arg_list);
    3053   for (; f_arg; f_arg=CDR(f_arg))
    3054   {
    3055     LSymbol *s = (LSymbol *)CAR(f_arg);
    3056     l_user_stack.push(s->value);
    3057   }
    3058 
    3059   // open block so that local vars aren't saved on the stack
    3060   {
    3061     int new_start=l_user_stack.son;
    3062     int i=new_start;
    3063     // now push all the values we wish to gather
    3064     for (f_arg=fun_arg_list; f_arg; )
    3065     {
    3066       if (!arg_list)
    3067       { sym->Print(); lbreak("too few parameter to function\n"); exit(0); }
    3068       l_user_stack.push(CAR(arg_list)->Eval());
    3069       f_arg=CDR(f_arg);
    3070       arg_list=CDR(arg_list);
    3071     }
    3072 
    3073 
    3074     // now store all the values and put them into the symbols
    3075     for (f_arg=fun_arg_list; f_arg; f_arg=CDR(f_arg))
    3076       ((LSymbol *)CAR(f_arg))->SetValue((LObject *)l_user_stack.sdata[i++]);
    3077 
    3078     l_user_stack.son=new_start;
    3079   }
    3080 
    3081 
    3082 
    3083   if (f_arg)
    3084   { sym->Print(); lbreak("too many parameter to function\n"); exit(0); }
    3085 
    3086 
    3087   // now evaluate the function block
    3088   while (block_list)
    3089   {
    3090     ret=CAR(block_list)->Eval();
    3091     block_list=CDR(block_list);
    3092   }
    3093 
    3094   long cur_stack=stack_start;
    3095   for (f_arg=fun_arg_list; f_arg; f_arg=CDR(f_arg))
    3096     ((LSymbol *)CAR(f_arg))->SetValue((LObject *)l_user_stack.sdata[cur_stack++]);
    3097 
    3098   l_user_stack.son=stack_start;
     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
     3046
     3047    // mark the start start, so we can restore when done
     3048    long stack_start = l_user_stack.son;
     3049
     3050    // first push all of the old symbol values
     3051    LObject *f_arg = NULL;
     3052    PtrRef r18(f_arg);
     3053    PtrRef r19(arg_list);
     3054
     3055    for (f_arg = (LObject *)fun_arg_list; f_arg; f_arg = CDR(f_arg))
     3056    {
     3057        LSymbol *s = (LSymbol *)CAR(f_arg);
     3058        l_user_stack.push(s->value);
     3059    }
     3060
     3061    // open block so that local vars aren't saved on the stack
     3062    {
     3063        int new_start = l_user_stack.son;
     3064        int i = new_start;
     3065        // now push all the values we wish to gather
     3066        for (f_arg = (LObject *)fun_arg_list; f_arg; f_arg = CDR(f_arg))
     3067        {
     3068            if (!arg_list)
     3069            {
     3070                Print();
     3071                lbreak("too few parameter to function\n");
     3072                exit(0);
     3073            }
     3074            l_user_stack.push(CAR(arg_list)->Eval());
     3075            arg_list = (LList *)CDR(arg_list);
     3076        }
     3077
     3078        // 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))
     3080            ((LSymbol *)CAR(f_arg))->SetValue((LObject *)l_user_stack.sdata[i++]);
     3081
     3082        l_user_stack.son = new_start;
     3083    }
     3084
     3085    if (f_arg)
     3086    {
     3087        Print();
     3088        lbreak("too many parameter to function\n");
     3089        exit(0);
     3090    }
     3091
     3092    // now evaluate the function block
     3093    while (block_list)
     3094    {
     3095        ret = CAR(block_list)->Eval();
     3096        block_list = CDR(block_list);
     3097    }
     3098
     3099    long cur_stack = stack_start;
     3100    for (f_arg = (LObject *)fun_arg_list; f_arg; f_arg = CDR(f_arg))
     3101        ((LSymbol *)CAR(f_arg))->SetValue((LObject *)l_user_stack.sdata[cur_stack++]);
     3102
     3103    l_user_stack.son = stack_start;
    30993104
    31003105#ifdef L_PROFILE
    3101   time_marker end;
    3102   sym->time_taken += end.diff_time(&start);
    3103 #endif
    3104 
    3105 
    3106   return ret;
     3106    time_marker end;
     3107    sym->time_taken += end.diff_time(&start);
     3108#endif
     3109
     3110    return ret;
    31073111}
    31083112
  • abuse/trunk/src/lisp/lisp.h

    r498 r499  
    118118    /* Methods */
    119119    LObject *EvalFunction(void *arg_list);
     120    LObject *EvalUserFunction(LList *arg_list);
    120121
    121122    LString *GetName();
     
    220221void *lisp_equal(void *n1, void *n2);
    221222void *eval_block(void *list);
    222 void *eval_user_fun(LSymbol *sym, void *arg_list);
    223223void *assoc(void *item, void *list);
    224224void resize_tmp(int new_size);
  • abuse/trunk/src/objects.cpp

    r497 r499  
    524524      prof1 = new time_marker;
    525525
    526     eval_user_fun((LSymbol *)d, am);
     526    ((LSymbol *)d)->EvalUserFunction(am);
    527527    if (profiling())
    528528    {
     
    15941594        prof1=new time_marker;
    15951595
    1596       eval_user_fun((LSymbol *)f,NULL);
     1596      ((LSymbol *)f)->EvalUserFunction(NULL);
    15971597
    15981598      if (profiling())
  • abuse/trunk/src/view.cpp

    r497 r499  
    884884      game_object *o=current_object;
    885885      current_object=focus;
    886       eval_user_fun((LSymbol *)figures[focus->otype]->get_fun(OFUN_CONSTRUCTOR),NULL);
     886      ((LSymbol *)figures[focus->otype]->get_fun(OFUN_CONSTRUCTOR))->EvalUserFunction(NULL);
    887887      current_object=o;
    888888    }
Note: See TracChangeset for help on using the changeset viewer.