Branch: Tag:

1999-12-10

1999-12-10 23:45:02 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Fixed typo.
Added some support for tuple, scope & type (DON'T USE!).
The type fix of aggregate_mapping() should make implied zero always work.
The EXACT flag is now cleared when changing scope in match_types(), otherwise
eg the following type won't work as intended:

!function(!object...:mixed)&function(mixed...:mixed),

since it would match

function(zero...:mixed)

due to the double negation the EXACT flag was cleared, which would make
zero match object, and thus not !object. The EXACT flag is now cleared
just before !object, and will thus be set when object is matched against
zero.

Rev: src/pike_types.c:1.86

5:   \*/   /**/   #include "global.h" - RCSID("$Id: pike_types.c,v 1.85 1999/12/07 09:40:59 hubbe Exp $"); + RCSID("$Id: pike_types.c,v 1.86 1999/12/10 23:45:02 grubba Exp $");   #include <ctype.h>   #include "svalue.h"   #include "pike_types.h"
137:       break;    +  case T_SCOPE:    case T_ASSIGN:    t++;    goto one_more_type;
145:    while(EXTRACT_UCHAR(t)!=T_MANY) t+=type_length(t); /* skip arguments */    t++;    +  case T_TUPLE:    case T_MAPPING:    case T_OR:    case T_AND:
167:    case '9':    case T_FLOAT:    case T_STRING: +  case T_TYPE:    case T_PROGRAM:    case T_MIXED:    case T_VOID:
373:    switch(buf[0])    {    case 'z': -  if(!strcmp(buf,"zero")) { push_type(T_MIXED); break; } +  if(!strcmp(buf,"zero")) { push_type(T_ZERO); break; }    goto bad_type;       case 'i':
496:    if(!strcmp(buf,"void")) { push_type(T_VOID); break; }    goto bad_type;    +  case 't': +  if (!strcmp(buf,"tuple")) +  { +  while(ISSPACE(**s)) ++*s; +  if(**s == '(') +  { +  type_stack_mark(); +  ++*s; +  type_stack_mark(); +  internal_parse_type(_s); +  type_stack_reverse(); +  if(**s != ',') error("Expecting ','.\n"); +  ++*s; +  type_stack_mark(); +  internal_parse_type(_s); +  type_stack_reverse(); +  if(**s != ')') error("Expecting ')'.\n"); +  ++*s; +  type_stack_reverse(); +  }else{ +  push_type(T_MIXED); +  push_type(T_MIXED); +  } +  push_type(T_TUPLE); +  break; +  } +  if(!strcmp(buf,"type")) { push_type(T_TYPE); break; } +  goto bad_type; +     case 'm':    if(!strcmp(buf,"mixed")) { push_type(T_MIXED); break; }    if(!strcmp(buf,"mapping"))
714: Inside #if defined(PIKE_DEBUG)
   printf("%c",EXTRACT_UCHAR(a+e));    break;    +  case T_SCOPE: printf("scope"); break; +  case T_TUPLE: printf("tuple"); break;    case T_ASSIGN: printf("="); break;    case T_INT:    {
727: Inside #if defined(PIKE_DEBUG)
   }    case T_FLOAT: printf("float"); break;    case T_STRING: printf("string"); break; +  case T_TYPE: printf("type"); break;    case T_PROGRAM: printf("program"); break;    case T_OBJECT:    printf("object(%s %ld)",
777:    my_putchar(')');    break;    +  case T_SCOPE: +  my_putchar('{'); +  my_putchar(EXTRACT_UCHAR(t++)); +  my_putchar(','); +  t = low_describe_type(t); +  my_putchar('}'); +  break; +  +  case T_TUPLE: +  my_putchar('['); +  t = low_describe_type(t); +  my_putchar(','); +  t = low_describe_type(t); +  my_putchar(']'); +  break; +     case T_VOID: my_strcat("void"); break;    case T_ZERO: my_strcat("zero"); break;    case T_MIXED: my_strcat("mixed"); break;
813:    /* Prog id */    break;    case T_STRING: my_strcat("string"); break; +  case T_TYPE: my_strcat("type"); break;       case T_FUNCTION:    {
944:    if(tmp == low_compile_type_to_runtime_type(t+type_length(t)))    return tmp;    +  case T_TUPLE: +  /* FIXME: Shouldn't occur/should be converted to array? */ +  /* FALL_THROUGH */    default:    return T_MIXED;       case T_ZERO:    return T_INT;    -  +  case T_SCOPE: +  return low_compile_type_to_runtime_type(t+2); +     case T_ARRAY:    case T_MAPPING:    case T_MULTISET:
959:    case T_FUNCTION:       case T_STRING: +  case T_TYPE:    case T_INT:    case T_FLOAT:    return EXTRACT_UCHAR(t);
1044:       push_type(T_INT);    } +  else if (EXTRACT_UCHAR(t1) == T_SCOPE) +  { +  if (EXTRACT_UCHAR(t2) == T_SCOPE) { +  low_or_pike_types(t1+2, t2+2, zero_implied); +  if (EXTRACT_UCHAR(t1+1) > EXTRACT_UCHAR(t2+1)) +  push_type(EXTRACT_UCHAR(t1+1));    else -  +  push_type(EXTRACT_UCHAR(t2+1)); +  } else { +  low_or_pike_types(t1+2, t2, zero_implied); +  push_type(EXTRACT_UCHAR(t1+1)); +  } +  push_type(T_SCOPE); +  } +  else if (EXTRACT_UCHAR(t2) == T_SCOPE)    { -  +  low_or_pike_types(t1, t2+2, zero_implied); +  push_type(EXTRACT_UCHAR(t2+1)); +  push_type(T_SCOPE); +  } +  else +  {    push_unfinished_type(t1);    very_low_or_pike_types(t2,t1);    }
1063:    int zero_implied)   {    type_stack_mark(); -  medium_or_pike_types(a,b,zero_implied); +  medium_or_pike_types(a,b,1 /*zero_implied*/);    return pop_unfinished_type();   }   
1130:    break;    case T_PROGRAM:    case T_STRING: +  case T_TYPE:    case T_FLOAT:    case T_INT:    even_lower_and_pike_types(t1, t2);
1162:    case T_ZERO:    case T_PROGRAM:    case T_STRING: +  case T_TYPE:    case T_FLOAT:    case T_INT:    /* Simple type. Already handled. */
1218:    push_type(T_VOID);    }    } +  else if (EXTRACT_UCHAR(t1) == T_SCOPE) +  { +  if (EXTRACT_UCHAR(t2) == T_SCOPE) { +  low_and_pike_types(t1+2, t2+2); +  if (EXTRACT_UCHAR(t1+1) > EXTRACT_UCHAR(t2+1)) +  push_type(EXTRACT_UCHAR(t1+1)); +  else +  push_type(EXTRACT_UCHAR(t2+1)); +  } else { +  low_and_pike_types(t1+2, t2); +  push_type(EXTRACT_UCHAR(t1+1)); +  } +  push_type(T_SCOPE); +  } +  else if (EXTRACT_UCHAR(t2) == T_SCOPE) +  { +  low_and_pike_types(t1, t2+2); +  push_type(EXTRACT_UCHAR(t2+1)); +  push_type(T_SCOPE); +  }    else if((EXTRACT_UCHAR(t1)==T_STRING && EXTRACT_UCHAR(t2)==T_STRING) || -  +  (EXTRACT_UCHAR(t1)==T_TYPE && EXTRACT_UCHAR(t2)==T_TYPE) ||    (EXTRACT_UCHAR(t1)==T_FLOAT && EXTRACT_UCHAR(t2)==T_FLOAT) ||    (EXTRACT_UCHAR(t1)==T_PROGRAM && EXTRACT_UCHAR(t2)==T_PROGRAM))    {
1558:    return a;    }    +  /* Convert zero to int(0..0). */ +  if (EXTRACT_UCHAR(a) == T_ZERO) +  a = tInt0; +  if (EXTRACT_UCHAR(b) == T_ZERO) +  b = tInt0;       /* Special cases (tm) */    switch(EXTRACT_TWOT(a,b))
1569:    {    struct pike_string *s;    if((s=low_object_lfun_type(a, LFUN_CALL))) -  return low_match_types(s->str,b,flags); +  return low_match_types(s->str,b,flags & ~(A_EXACT|B_EXACT));    return a;    }   
1577:    {    struct pike_string *s;    if((s=low_object_lfun_type(b, LFUN_CALL))) -  return low_match_types(a,s->str,flags); +  return low_match_types(a,s->str,flags & ~(A_EXACT|B_EXACT));    return a;    }    }
1610:    b+=type_length(b);    }    -  if(!low_match_types(a_tmp, b_tmp, flags | NO_MAX_ARGS)) return 0; +  if(!low_match_types(a_tmp, b_tmp, +  (flags | NO_MAX_ARGS) & ~(A_EXACT|B_EXACT))) +  return 0;    if(++correct_args > max_correct_args)    if(!(flags & NO_MAX_ARGS))    max_correct_args=correct_args;
1623:    a+=type_length(a);    b+=type_length(b);    }else{ -  if(!low_match_types(a,b,flags | NO_MAX_ARGS)) return 0; +  if(!low_match_types(a,b, (flags | NO_MAX_ARGS) & ~(A_EXACT|B_EXACT))) +  return 0;    }    if(!(flags & NO_MAX_ARGS))    max_correct_args=0x7fffffff;    /* check the returntype */    if ((EXTRACT_UCHAR(b) == T_VOID) && (EXTRACT_UCHAR(a) != T_VOID)) {    /* Promote b to a function returning zero. */ -  if (!low_match_types(a, tZero, flags)) return 0; +  if (!low_match_types(a, tZero, flags & ~(A_EXACT|B_EXACT))) return 0;    } else if ((EXTRACT_UCHAR(a) == T_VOID) && (EXTRACT_UCHAR(b) != T_VOID)) {    /* Promote a to a function returning zero. */ -  if(!low_match_types(tZero,b,flags)) return 0; -  } else if(!low_match_types(a,b,flags)) return 0; +  if(!low_match_types(tZero,b,flags & ~(A_EXACT|B_EXACT))) return 0; +  } else if(!low_match_types(a,b,flags & ~(A_EXACT|B_EXACT))) return 0;    break;       case T_MAPPING: -  if(!low_match_types(++a,++b,flags)) return 0; -  if(!low_match_types(a+type_length(a),b+type_length(b),flags)) return 0; +  if(!low_match_types(++a,++b,flags & ~(A_EXACT|B_EXACT))) return 0; +  if(!low_match_types(a+type_length(a),b+type_length(b), +  flags & ~(A_EXACT|B_EXACT))) return 0;    break;       case T_OBJECT:
1704:       case T_MULTISET:    case T_ARRAY: -  if(!low_match_types(++a,++b,flags)) return 0; +  if(!low_match_types(++a,++b,flags & ~(A_EXACT|B_EXACT))) return 0;       case T_FLOAT:    case T_STRING: -  +  case T_TYPE:    case T_PROGRAM:    case T_ZERO:    case T_VOID:
2108:       case T_FLOAT:    case T_STRING: +  case T_TYPE:    case T_PROGRAM:    case T_ZERO:    case T_VOID:
2175:    a=low_match_types(a,b,NO_SHORTCUTS);    if(a)    { + #if 0 +  if ((lex.pragmas & ID_STRICT_TYPES) && +  !low_pike_types_le(a, b)) { +  yywarning("Type mismatch"); +  } + #endif /* 0 */    switch(EXTRACT_UCHAR(a))    {    case T_FUNCTION:
2230:   {    struct pike_string *tmp;    struct program *p; +     switch(low_check_indexing(t, index_type, n))    {    case 0: return 0;
2305:    reference_shared_string(mixed_type_string);    return mixed_type_string;    +  case T_MIXED: +  if (lex.pragmas & ID_STRICT_TYPES) { +  yywarning("Indexing mixed."); +  } +  reference_shared_string(mixed_type_string); +  return mixed_type_string; +     case T_INT:   #ifdef AUTO_BIGNUM    /* Don't force Gmp.mpz to be loaded here since this function
2315:    goto comefrom_int_index;   #endif    case T_ZERO: +  case T_TYPE:    case T_VOID:    case T_FLOAT:    return 0;
2424:       case T_VOID:    case T_ZERO: +  case T_TYPE:    case T_FLOAT:    case T_INT:    return 0;
2835:    case T_OBJECT: return "object";    case T_PROGRAM: return "program";    case T_STRING: return "string"; +  case T_TYPE: return "type";    case T_ZERO: return "zero";    case T_VOID: return "void";    default: return "unknown";