Branch: Tag:

2001-03-19

2001-03-19 00:41:20 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Some support for the ring operator in types. Probably not completely correct yet.

Rev: src/pike_types.c:1.166
Rev: src/svalue.h:1.81

5:   \*/   /**/   #include "global.h" - RCSID("$Id: pike_types.c,v 1.165 2001/03/18 19:46:52 per Exp $"); + RCSID("$Id: pike_types.c,v 1.166 2001/03/19 00:41:20 grubba Exp $");   #include <ctype.h>   #include "svalue.h"   #include "pike_types.h"
176: Inside #if defined(USE_PIKE_TYPE)
   * ---------------------------------------------    * SCOPE num vars (int) type    * ASSIGN variable (int) type +  * NAME name (string) type    * FUNCTION type FUNCTION|MANY    * MANY many type return type -  +  * RING type type    * TUPLE type type    * MAPPING index type value type    * OR type type
240:    case T_MAPPING:    case T_OR:    case T_AND: +  case PIKE_T_RING:    /* Free car & cdr */    free_type(car);    t = cdr;
294:    case T_MAPPING:    case T_OR:    case T_AND: +  case PIKE_T_RING:    /* Free car & cdr */    free_type(car);    free_type(cdr);
459:    case T_MAPPING:    case T_OR:    case T_AND: +  case PIKE_T_RING:    /* Make a new type of the top two types. */    --Pike_compiler->type_stackp;    *Pike_compiler->type_stackp = mk_type(type,
531:    case T_MAPPING:    case T_OR:    case T_AND: +  case PIKE_T_RING:    /* Both car & cdr. */    push_finished_type(top->cdr);    push_finished_type(top->car);
592:    case T_MAPPING:    case T_OR:    case T_AND: +  case PIKE_T_RING:    {    /* Binary type-node. -- swap the types. */    struct pike_type *tmp = Pike_compiler->type_stackp[0];
1203: Inside #if defined(PIKE_DEBUG)
   break;       case PIKE_T_UNKNOWN: printf("unknown"); break; +  case PIKE_T_RING: +  printf("ring("; +  simple_describe_type(s->car); +  printf("°"); +  simple_describe_type(s->cdr); +  printf(")"); +  break;    case T_OR:    printf("or(");    simple_describe_type(s->car);
1393:    }    break;    +  case PIKE_T_RING: +  /* FIXME: Should be renumbered for correct parenthesing. */ +  my_strcat("("); +  my_describe_type(t->car); +  my_strcat(")°("); +  my_describe_type(t->cdr); +  my_strcat(")"); +  break; +     case T_OR:    if (t->car->type > T_OR) {    my_strcat("(");
1477:   {    switch(t->type)    { +  case PIKE_T_RING: +  return compile_type_to_runtime_type(t->car); +     case T_OR:    {    TYPE_T tmp = compile_type_to_runtime_type(t->car);
1953:    return low_match_types(a->cdr, b, flags);    }    +  case PIKE_T_RING: +  return low_match_types(a->car, b, flags); +     case PIKE_T_NAME:    return low_match_types(a->cdr, b, flags);   
2044:    return low_match_types(a, b->cdr, flags);    }    +  case PIKE_T_RING: +  return low_match_types(a, b->car, flags); +     case PIKE_T_NAME:    return low_match_types(a, b->cdr, flags);   
2471:    }    }    +  case PIKE_T_RING: +  a = a->car; +  goto recurse; +     case PIKE_T_NAME:    a = a->cdr;    goto recurse;
2558:    b = b->cdr;    goto recurse;    +  case PIKE_T_RING: +  b = b->car; +  goto recurse; +     case PIKE_T_NAME:    b = b->cdr;    goto recurse;
2967:    if(!tmp) return 0;    return low_get_return_type(a->cdr, b);    +  case PIKE_T_RING: +  return low_get_return_type(a->car, b); +     case PIKE_T_NAME:    return low_get_return_type(a->cdr, b);   
3147:   #endif    case T_ZERO:    case T_TYPE: +  case PIKE_T_RING:    case T_VOID:    case T_FLOAT:    return 0;
3306:    case T_VOID:    case T_ZERO:    case T_TYPE: +  case PIKE_T_RING:    case T_FLOAT:    case T_INT:    return 0;
3869:    case PIKE_T_NAME:    return type_may_overload(type->cdr, lfun);    +  case PIKE_T_RING: +  return type_may_overload(type->car, lfun); +     case T_OR:    return type_may_overload(type->car, lfun) ||    type_may_overload(type->cdr, lfun);
3963:    return low_make_function_type(type_string+1, cont);    case T_TUPLE:    case T_MAPPING: +  case PIKE_T_RING:    /* Order dependant */    return mk_type(type, low_make_pike_type(type_string+1, cont),    low_make_pike_type(*cont, cont), PT_COPY_BOTH);
4053:    type = type->cdr;    goto again;    +  case PIKE_T_RING: +  type = type->car; +  goto again; +     case T_OR:    case T_MAPPING:    if(!pike_type_allow_premature_toss(type->car)) return 0;
4097:    t = t->car;    goto recurse;    +  case PIKE_T_RING:    case T_TUPLE:    case T_MAPPING:    case T_OR:
4259:       case T_TUPLE:    case T_MAPPING: +  case PIKE_T_RING:    case T_OR:    case T_AND:    t+=type_length(t);
4911: Inside #if defined(PIKE_DEBUG)
      case PIKE_T_UNKNOWN: fputs("unknown", stderr); break;    case T_MANY: fputs("many", stderr); break; +  case PIKE_T_RING: fputs("ring", stderr); break;    case T_OR: fputs("or", stderr); break;    case T_AND: fputs("and", stderr); break;    case T_NOT: fputs("not", stderr); break;
5093:    }    break;    +  case PIKE_T_RING: +  my_strcat("("); +  t = low_describe_type(t); +  my_strcat(")°("); +  t = low_describe_type(t); +  my_strcat(")"); +  break; +     case T_OR:    if (EXTRACT_UCHAR(t) > T_OR) {    my_strcat("(");
5195:    case T_ZERO:    return T_INT;    +  case PIKE_T_RING: +  return low_compile_type_to_runtime_type(t+1); +     case T_SCOPE:    return low_compile_type_to_runtime_type(t+2);   
5678:    return low_match_types(a,b,flags);    }    +  case PIKE_T_RING: +  return low_match_types(a+1, b, flags); +     case T_NOT:    if(low_match_types(a+1,b,(flags ^ B_EXACT ) | NO_MAX_ARGS))    return 0;
5763:    return low_match_types(a,b,flags);    }    +  case PIKE_T_RING: +  return low_match_types(a, b+1, flags); +     case T_NOT:    if(low_match_types(a,b+1, (flags ^ A_EXACT ) | NO_MAX_ARGS))    return 0;
6177:    }    }    +  case PIKE_T_RING: +  return low_pike_types_le(a+1, b, array_cnt, flags); +     case T_NOT:    if (EXTRACT_UCHAR(b) == T_NOT) {    return low_pike_types_le(b+1, a+1, -array_cnt, flags);
6255:    b+=type_length(b);    return low_pike_types_le(a, b, array_cnt, flags);    +  case PIKE_T_RING: +  return low_pike_types_le(a, b+1, array_cnt, flags); +     case T_NOT:    if (EXTRACT_UCHAR(b+1) == T_NOT) {    return low_pike_types_le(a, b+2, array_cnt, flags);
6826:    case T_TYPE:    case T_VOID:    case T_FLOAT: +  case PIKE_T_RING:    return 0;       case T_OR:
6980:    case T_TYPE:    case T_FLOAT:    case T_INT: +  case PIKE_T_RING:    return 0;       case T_OR:
7596:    case T_FUNCTION:    return 0;    +  case PIKE_T_RING:    case T_SCOPE:    case T_ASSIGN:    type++;