pike.git / src / pike_types.c

version» Context lines:

pike.git/src/pike_types.c:1:   /*\   ||| This file a part of Pike, and is copyright by Fredrik Hubinette   ||| Pike is distributed as GPL (General Public License)   ||| See the files COPYING and DISCLAIMER for more information.   \*/   /**/   #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"   #include "stralloc.h"   #include "stuff.h"   #include "array.h"   #include "program.h"   #include "constants.h"   #include "object.h"   #include "multiset.h"
pike.git/src/pike_types.c:169: Inside #if defined(USE_PIKE_TYPE)
     /*    * New and improved type representation system.    *    * This representation is new in Pike 7.3.    *    * Node: Car: Cdr:    * ---------------------------------------------    * 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    * AND type type    * ARRAY type -    * MULTISET type -    * NOT type -    * '0'-'9' - -    * FLOAT - -    * STRING - -
pike.git/src/pike_types.c:233:    really_free_pike_type(t);       /* FIXME: Recursion: Should we use a stack? */    switch(type) {    case T_FUNCTION:    case T_MANY:    case T_TUPLE:    case T_MAPPING:    case T_OR:    case T_AND: +  case PIKE_T_RING:    /* Free car & cdr */    free_type(car);    t = cdr;    goto loop;       case T_ARRAY:    case T_MULTISET:    case T_NOT:    /* Free car */    t = car;
pike.git/src/pike_types.c:287:    for(t = pike_type_hash[index]; t; t = t->next) {    if ((t->hash == hash) && (t->type == type) &&    (t->car == car) && (t->cdr == cdr)) {    switch(type) {    case T_FUNCTION:    case T_MANY:    case T_TUPLE:    case T_MAPPING:    case T_OR:    case T_AND: +  case PIKE_T_RING:    /* Free car & cdr */    free_type(car);    free_type(cdr);    break;       case T_ARRAY:    case T_MULTISET:    case T_NOT:    /* Free car */    free_type(car);
pike.git/src/pike_types.c:452:   {    /* fprintf(stderr, "push_type(%d)\n", type); */       switch(type) {    case T_FUNCTION:    case T_MANY:    case T_TUPLE:    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,    *(Pike_compiler->type_stackp+1),    *Pike_compiler->type_stackp,    PT_COPY_BOTH);    break;       case T_ARRAY:    case T_MULTISET:
pike.git/src/pike_types.c:524:    fatal("Type stack underflow\n");       top = *(Pike_compiler->type_stackp--);    switch(top->type) {    case T_FUNCTION:    case T_MANY:    case T_TUPLE:    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);    break;    case T_ARRAY:    case T_MULTISET:    case T_NOT:    case T_TYPE:    /* car */    push_finished_type(top->car);
pike.git/src/pike_types.c:585:   {    /* fprintf(stderr, "push_reverse_type(%d)\n", type); */       switch(type) {    case T_FUNCTION:    case T_MANY:    case T_TUPLE:    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];    Pike_compiler->type_stackp[0] = Pike_compiler->type_stackp[-1];    Pike_compiler->type_stackp[-1] = tmp;    break;    }    }    push_type(type);   
pike.git/src/pike_types.c:1196: Inside #if defined(PIKE_DEBUG)
   simple_describe_type(s->cdr);    printf(")");    break;    case T_MULTISET:    printf("multiset(");    simple_describe_type(s->car);    printf(")");    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);    printf("|");    simple_describe_type(s->cdr);    printf(")");    break;    case T_AND:    printf("and(");    simple_describe_type(s->car);
pike.git/src/pike_types.c:1386:    my_strcat("!");    if (t->car->type > T_NOT) {    my_strcat("(");    my_describe_type(t->car);    my_strcat(")");    } else {    my_describe_type(t->car);    }    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("(");    my_describe_type(t->car);    my_strcat(")");    } else {    my_describe_type(t->car);    }    my_strcat(" | ");    if (t->cdr->type > T_OR) {
pike.git/src/pike_types.c:1470:      static int low_is_same_type(struct pike_type *a, struct pike_type *b)   {    return a == b;   }      TYPE_T compile_type_to_runtime_type(struct pike_type *t)   {    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);    if(tmp == compile_type_to_runtime_type(t->cdr))    return tmp;       /* FALL_THROUGH */    }    case T_TUPLE:    /* FIXME: Shouldn't occur/should be converted to array? */
pike.git/src/pike_types.c:1946:    ret = low_match_types(a->car, b, flags);    if(ret && !(flags & NO_SHORTCUTS)) return ret;    if(ret)    {    low_match_types(a->cdr, b, flags);    return ret;    }else{    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);       case T_NOT:    if(low_match_types(a->car, b, (flags ^ B_EXACT ) | NO_MAX_ARGS))    return 0;    return a;       case T_ASSIGN:    ret = low_match_types(a->cdr, b, flags);
pike.git/src/pike_types.c:2037:    ret = low_match_types(a, b->car, flags);    if(ret && !(flags & NO_SHORTCUTS)) return ret;    if(ret)    {    low_match_types(a, b->cdr, flags);    return ret;    }else{    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);       case T_NOT:    if(low_match_types(a, b->car, (flags ^ A_EXACT ) | NO_MAX_ARGS))    return 0;    return a;       case T_ASSIGN:    ret = low_match_types(a, b->cdr, flags);
pike.git/src/pike_types.c:2464:    if (a->cdr->type == T_VOID) {    /* Special case for T_VOID */    /* FIXME: Should probably be handled as T_ZERO. */    return 1;    } else {    a = a->cdr;    goto recurse;    }    }    +  case PIKE_T_RING: +  a = a->car; +  goto recurse; +     case PIKE_T_NAME:    a = a->cdr;    goto recurse;       case T_NOT:    if (b->type == T_NOT) {    struct pike_type *tmp = a->car;    a = b->car;    b = tmp;    array_cnt = -array_cnt;
pike.git/src/pike_types.c:2551:    b = b->cdr;    goto recurse;       case T_OR:    /* OK if a is a subset of either of the parts. */    ret=low_pike_types_le(a, b->car, array_cnt, flags);    if (ret) return ret;    b = b->cdr;    goto recurse;    +  case PIKE_T_RING: +  b = b->car; +  goto recurse; +     case PIKE_T_NAME:    b = b->cdr;    goto recurse;       case T_NOT:    if (b->car->type == T_NOT) {    b = b->car->car;    goto recurse;    }    if (low_pike_types_le(a, b->car, array_cnt, flags)) {
pike.git/src/pike_types.c:2960:    return 1;    }       case T_AND:    type_stack_mark();    tmp = low_get_return_type(a->car, b);    type_stack_pop_to_mark();    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);       case T_ARRAY:    tmp = low_get_return_type(a->car, b);    if(!tmp) return 0;    push_type(T_ARRAY);    return 1;    }   
pike.git/src/pike_types.c:3140: Inside #if defined(AUTO_BIGNUM)
  #ifdef AUTO_BIGNUM    /* Don't force Gmp.mpz to be loaded here since this function    * is called long before the master object is compiled...    * /Hubbe    */    p=get_auto_bignum_program_or_zero();    goto comefrom_int_index;   #endif    case T_ZERO:    case T_TYPE: +  case PIKE_T_RING:    case T_VOID:    case T_FLOAT:    return 0;       case T_OR:    {    struct pike_type *a,*b;    a = low_index_type(t->car, index_type, n);    b = low_index_type(t->cdr, index_type,n);    if(!b) return a;
pike.git/src/pike_types.c:3299:    add_ref(string_type_string);    return string_type_string;    }    default:    add_ref(mixed_type_string);    return mixed_type_string;       case T_VOID:    case T_ZERO:    case T_TYPE: +  case PIKE_T_RING:    case T_FLOAT:    case T_INT:    return 0;       case T_OR:    {    struct pike_type *a,*b;    a = low_key_type(t->car, n);    b = low_key_type(t->cdr, n);    if(!b) return a;
pike.git/src/pike_types.c:3862:    case T_MANY:    case T_ARRAY:    /* might want to check for `() */       default:    return 0;       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);       case T_AND:    return type_may_overload(type->car, lfun) &&    type_may_overload(type->cdr, lfun);       case T_NOT:    return !type_may_overload(type->car, lfun);
pike.git/src/pike_types.c:3956:    fatal("low_make_pike_type(): Bad marker: %d\n", type_string[1]);    }    return mk_type(type, (void *)(ptrdiff_t)(type_string[1] - '0'),    low_make_pike_type(type_string+2, cont), PT_COPY_CDR);    case T_FUNCTION:    /* Multiple ordered values. */    /* FIXME: */    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);    case T_OR:    case T_AND:    /* Order independant */    /* FIXME: */    return mk_type(type, low_make_pike_type(type_string+1, cont),    low_make_pike_type(*cont, cont), PT_COPY_BOTH);    case T_ARRAY:
pike.git/src/pike_types.c:4046:    case T_FUNCTION:    case T_MANY:    return 0;       case PIKE_T_NAME:    case T_SCOPE:    case T_ASSIGN:    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;    type = type->cdr;    goto again;       case T_AND:    /* FIXME: Should probably look at both branches. */    type = type->cdr;    goto again;
pike.git/src/pike_types.c:4090:    case T_ARRAY:    case T_MULTISET:    case T_TYPE:    case T_NOT:    my_putchar(t->type);    /* FALL_THROUGH */    case PIKE_T_NAME:    t = t->car;    goto recurse;    +  case PIKE_T_RING:    case T_TUPLE:    case T_MAPPING:    case T_OR:    case T_AND:    my_putchar(t->type);    low_type_to_string(t->car);    t = t->cdr;    goto recurse;       case '0':
pike.git/src/pike_types.c:4252:    case T_ASSIGN:    t++;    goto one_more_type;       case T_FUNCTION:    while(EXTRACT_UCHAR(t)!=T_MANY) t+=type_length(t); /* skip arguments */    t++;       case T_TUPLE:    case T_MAPPING: +  case PIKE_T_RING:    case T_OR:    case T_AND:    t+=type_length(t);       case T_ARRAY:    case T_MULTISET:    case T_TYPE:    case T_NOT:    goto one_more_type;   
pike.git/src/pike_types.c:4904: Inside #if defined(PIKE_DEBUG)
   (long)extract_type_int(a+e+2));    e+=sizeof(INT32)+1;    break;    case T_FUNCTION: fputs("function", stderr); break;    case T_ARRAY: fputs("array", stderr); break;    case T_MAPPING: fputs("mapping", stderr); break;    case T_MULTISET: fputs("multiset", stderr); break;       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;    case T_VOID: fputs("void", stderr); break;    case T_ZERO: fputs("zero", stderr); break;    case T_MIXED: fputs("mixed", stderr); break;       default: fprintf(stderr, "%d",EXTRACT_UCHAR(a+e)); break;    }    }
pike.git/src/pike_types.c:5086:    my_strcat("!");    if (EXTRACT_UCHAR(t) > T_NOT) {    my_strcat("(");    t=low_describe_type(t);    my_strcat(")");    } else {    t=low_describe_type(t);    }    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("(");    t=low_describe_type(t);    my_strcat(")");    } else {    t=low_describe_type(t);    }    my_strcat(" | ");    if (EXTRACT_UCHAR(t) > T_OR) {
pike.git/src/pike_types.c:5188:       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 PIKE_T_RING: +  return low_compile_type_to_runtime_type(t+1); +     case T_SCOPE:    return low_compile_type_to_runtime_type(t+2);       case T_ARRAY:    case T_MAPPING:    case T_MULTISET:       case T_OBJECT:    case T_PROGRAM:    case T_FUNCTION:
pike.git/src/pike_types.c:5671:    if(ret && !(flags & NO_SHORTCUTS)) return ret;    a+=type_length(a);    if(ret)    {    low_match_types(a,b,flags);    return ret;    }else{    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;    return a;       case T_ASSIGN:    ret=low_match_types(a+2,b,flags);    if(ret && EXTRACT_UCHAR(b)!=T_VOID)    {    int m=EXTRACT_UCHAR(a+1)-'0';
pike.git/src/pike_types.c:5756:    if(ret && !(flags & NO_SHORTCUTS)) return ret;    b+=type_length(b);    if(ret)    {    low_match_types(a,b,flags);    return ret;    }else{    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;    return a;       case T_ASSIGN:    ret=low_match_types(a,b+2,flags);    if(ret && EXTRACT_UCHAR(a)!=T_VOID)    {    int m=EXTRACT_UCHAR(b+1)-'0';
pike.git/src/pike_types.c:6170:    a+=type_length(a);    if (EXTRACT_UCHAR(a) == T_VOID) {    /* Special case for T_VOID */    /* FIXME: Should probably be handled as T_ZERO. */    return 1;    } else {    return low_pike_types_le(a, b, array_cnt, flags);    }    }    +  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);    }    if (EXTRACT_UCHAR(a+1) == T_NOT) {    return low_pike_types_le(a+2, b, array_cnt, flags);    }    if (low_pike_types_le(a+1, b, array_cnt, flags)) {    return 0;    }
pike.git/src/pike_types.c:6248:    return low_pike_types_le(a, b, array_cnt, flags);       case T_OR:    /* OK if a is a subset of either of the parts. */    b++;    ret=low_pike_types_le(a, b, array_cnt, flags);    if (ret) return ret;    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);    }    if (low_pike_types_le(a, b+1, array_cnt, flags)) {    return 0;    }    /* FIXME: This is wrong... */    return !low_pike_types_le(b+1, a, -array_cnt, flags);   
pike.git/src/pike_types.c:6819: Inside #if defined(AUTO_BIGNUM)
   * is called long before the master object is compiled...    * /Hubbe    */    p=get_auto_bignum_program_or_zero();    goto comefrom_int_index;   #endif    case T_ZERO:    case T_TYPE:    case T_VOID:    case T_FLOAT: +  case PIKE_T_RING:    return 0;       case T_OR:    {    struct pike_type *a, *b;    a=low_index_type(t,index_type,n);    t+=type_length(t);    b=low_index_type(t,index_type,n);    if(!b) return a;    if(!a) return b;
pike.git/src/pike_types.c:6973:    }    default:    reference_shared_string(mixed_type_string);    return mixed_type_string;       case T_VOID:    case T_ZERO:    case T_TYPE:    case T_FLOAT:    case T_INT: +  case PIKE_T_RING:    return 0;       case T_OR:    {    struct pike_type *a, *b;    a=low_key_type(t,n);    t+=type_length(t);    b=low_key_type(t,n);    if(!b) return a;    if(!a) return b;
pike.git/src/pike_types.c:7589:    switch(EXTRACT_UCHAR(type++))    {    case T_NOT:    return !low_pike_type_allow_premature_toss(type);       case T_OBJECT:    case T_MIXED:    case T_FUNCTION:    return 0;    +  case PIKE_T_RING:    case T_SCOPE:    case T_ASSIGN:    type++;    goto again;       case T_OR:    case T_MAPPING:    if(!low_pike_type_allow_premature_toss(type)) return 0;    case T_AND:    type+=type_length(type);