Branch: Tag:

1998-02-23

1998-02-23 23:24:35 by Fredrik Hübinette (Hubbe) <hubbe@hubbe.net>

min, max, `<, `<=, `>=, `>, `==, `!=, `- and `/ now takes any amount
of arguments.

Rev: src/las.c:1.51
Rev: src/modules/math/math.c:1.9
Rev: src/operators.c:1.25
Rev: src/pike_types.c:1.32
Rev: src/pike_types.h:1.9

4:   ||| See the files COPYING and DISCLAIMER for more information.   \*/   #include "global.h" - RCSID("$Id: pike_types.c,v 1.31 1998/02/20 00:55:23 hubbe Exp $"); + RCSID("$Id: pike_types.c,v 1.32 1998/02/23 23:24:04 hubbe Exp $");   #include <ctype.h>   #include "svalue.h"   #include "pike_types.h"
645:      #define A_EXACT 1   #define B_EXACT 2 + #define NO_MAX_ARGS 4      /*    * match two type strings, return zero if they don't match, and return
673:    return low_match_types(a,b,flags);       case T_NOT: -  if(low_match_types(a+1,b,flags | B_EXACT)) +  if(low_match_types(a+1,b,flags | B_EXACT | NO_MAX_ARGS))    return 0;    return a;    }
695:    return low_match_types(a,b,flags);       case T_NOT: -  if(low_match_types(a,b+1, flags | A_EXACT)) +  if(low_match_types(a,b+1, flags | A_EXACT | NO_MAX_ARGS))    return 0;    return a;    }
763:    b+=type_length(b);    }    -  if(!low_match_types(a_tmp, b_tmp, flags)) return 0; +  if(!low_match_types(a_tmp, b_tmp, flags | NO_MAX_ARGS)) return 0;    if(++correct_args > max_correct_args) -  +  if(!(flags & NO_MAX_ARGS))    max_correct_args=correct_args;    }    /* check the 'many' type */
775:    a+=type_length(a);    b+=type_length(b);    }else{ -  if(!low_match_types(a,b,flags)) return 0; +  if(!low_match_types(a,b,flags | NO_MAX_ARGS)) return 0;    } -  +  if(!(flags & NO_MAX_ARGS)) +  max_correct_args=0x7fffffff;    /* check the returntype */    if(!low_match_types(a,b,flags)) return 0;    break;
1087:    return low_check_indexing(type->str, index_type->str, n);   }    - /* Count the number of arguments for a funciton type. -  * return -1-n if the function can take number of arguments -  * >= n (varargs) -  */ - int count_arguments(struct pike_string *s) + static int low_count_arguments(char *q)   { -  int num; -  char *q; +  int num,num2;    -  CHECK_TYPE(s); +  switch(EXTRACT_UCHAR(q++)) +  { +  case T_OR: +  num=low_count_arguments(q); +  num2=low_count_arguments(q+type_length(q)); +  if(num<0 && num2>0) return num; +  if(num2<0 && num>0) return num2; +  if(num2<0 && num<0) return ~num>~num2?num:num2; +  return num>num2?num:num2;    -  q=s->str; -  if(EXTRACT_UCHAR(q) != T_FUNCTION) return MAX_LOCAL; -  q++; +  case T_AND: +  num=low_count_arguments(q); +  num2=low_count_arguments(q+type_length(q)); +  if(num<0 && num2>0) return num2; +  if(num2<0 && num>0) return num; +  if(num2<0 && num<0) return ~num<~num2?num:num2; +  return num<num2?num:num2; +  +  default: return MAX_LOCAL; +  +  case T_FUNCTION:    num=0;    while(EXTRACT_UCHAR(q)!=T_MANY)    {
1111:    if(EXTRACT_UCHAR(q)!=T_VOID) return ~num;    return num;   } + }    -  + /* Count the number of arguments for a funciton type. +  * return -1-n if the function can take number of arguments +  * >= n (varargs) +  */ + int count_arguments(struct pike_string *s) + { +  CHECK_TYPE(s); +  +  return low_count_arguments(s->str); + } +    struct pike_string *check_call(struct pike_string *args,    struct pike_string *type)   {
1129:    }   }    + INT32 get_max_args(struct pike_string *type) + { +  INT32 ret,tmp=max_correct_args; +  CHECK_TYPE(type); +  type=check_call(function_type_string, type); +  if(type) free_string(type); +  ret=max_correct_args; +  max_correct_args=tmp; +  return tmp; + } +    struct pike_string *get_type_of_svalue(struct svalue *s)   {    struct pike_string *ret;