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.16 1997/03/05 05:29:42 hubbe Exp $"); + RCSID("$Id: pike_types.c,v 1.17 1997/03/07 05:21:46 hubbe 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:126:    return t-q;   }         #define STACK_SIZE 100000   static unsigned char type_stack[STACK_SIZE];   static unsigned char *type_stackp=type_stack;   static unsigned char *mark_stack[STACK_SIZE/4];   static unsigned char **mark_stackp=mark_stack;    - void reset_type_stack() + void push_type(unsigned char tmp)   { -  type_stackp=type_stack; -  mark_stackp=mark_stack; +  *type_stackp=tmp; +  type_stackp++; +  if(type_stackp > type_stack + sizeof(type_stack)) +  yyerror("Type stack overflow.");   }      void type_stack_mark()   {    *mark_stackp=type_stackp;    mark_stackp++;    if(mark_stackp > mark_stack + NELEM(mark_stack))    yyerror("Type mark stack overflow.");   }    - unsigned char *pop_stack_mark() + INT32 pop_stack_mark()   {    mark_stackp--;    if(mark_stackp<mark_stack)    fatal("Type mark stack underflow\n");    -  return *mark_stackp; +  return type_stackp - *mark_stackp;   }      void pop_type_stack()   {    type_stackp--;    if(type_stackp<type_stack)    fatal("Type stack underflow\n");   }      void type_stack_pop_to_mark()   { -  type_stackp=pop_stack_mark(); +  type_stackp-=pop_stack_mark(); + #ifdef DEBUG +  if(type_stackp<type_stack) +  fatal("Type stack underflow\n"); + #endif   }    - void type_stack_reverse() + void reset_type_stack()   { -  unsigned char *a,*b,tmp; -  a=pop_stack_mark(); -  b=type_stackp-1; -  while(b>a) { tmp=*a; *a=*b; *b=tmp; b--; a++; } +  type_stack_pop_to_mark(); +  type_stack_mark();   }    - void push_type(unsigned char tmp) + void type_stack_reverse()   { -  *type_stackp=tmp; -  type_stackp++; -  if(type_stackp > type_stack + sizeof(type_stack)) -  yyerror("Type stack overflow."); +  INT32 a; +  a=pop_stack_mark(); +  reverse(type_stackp-a,a,1);   }      void push_type_int(unsigned INT32 i)   { -  if(type_stackp + sizeof(i)> type_stack + sizeof(type_stack)) -  yyerror("Type stack overflow."); -  -  type_stack_mark(); -  MEMCPY(type_stackp, &i, sizeof(i)); -  type_stackp+=sizeof(i); -  type_stack_reverse(); +  int e; +  for(e=sizeof(i)-1;e>=0;e--) +  push_type(((unsigned char *)&i)[e]);   }      void push_unfinished_type(char *s)   {    int e;    e=type_length(s);    for(e--;e>=0;e--) push_type(s[e]);   }      void push_finished_type(struct pike_string *type)   {    int e;    CHECK_TYPE(type);    for(e=type->len-1;e>=0;e--) push_type(type->str[e]);   }      struct pike_string *pop_unfinished_type()   {    int len,e;    struct pike_string *s; -  len=type_stackp - pop_stack_mark(); +  len=pop_stack_mark();    s=begin_shared_string(len); -  for(e=0;e<len;e++) s->str[e] = *--type_stackp; +  type_stackp-=len; +  MEMCPY(s->str, type_stackp, len); +  reverse(s->str, len, 1);    s=end_shared_string(s);    CHECK_TYPE(s);    return s;   }      struct pike_string *pop_type()   { -  int len,e; +     struct pike_string *s; -  len=type_stackp - type_stack; -  s=begin_shared_string(len); -  for(e=0;e<len;e++) s->str[e] = *--type_stackp; -  s=end_shared_string(s); -  reset_type_stack(); -  CHECK_TYPE(s); +  s=pop_unfinished_type(); +  type_stack_mark();    return s;   }    -  -  +    static void internal_parse_typeA(char **_s)   {    char buf[80];    unsigned int len;    unsigned char **s = (unsigned char **)_s;       while(ISSPACE(**s)) ++*s;       len=0;    for(len=0;isidchar(EXTRACT_UCHAR(s[0]+len));len++)
pike.git/src/pike_types.c:453:    }   }      /* This function is used when adding simul efuns so that    * the types for the functions can be easily stored in strings.    * It takes a string on the exact same format as Pike and returns a type    * struct.    */   struct pike_string *parse_type(char *s)   { +  type_stack_mark();    internal_parse_type(&s);       if( *s )    fatal("Extra junk at end of type definition.\n");    -  return pop_type(); +  return pop_unfinished_type();   }      #ifdef DEBUG   void stupid_describe_type(char *a,INT32 len)   {    INT32 e;    for(e=0;e<len;e++)    {    if(e) printf(" ");    switch(EXTRACT_UCHAR(a+e))
pike.git/src/pike_types.c:946:    }    }    }    default:    reference_shared_string(mixed_type_string);    return mixed_type_string;       case T_OR:    {    struct pike_string *a,*b; +  type_stack_mark();    a=low_index_type(t,n);    t+=type_length(t);    b=low_index_type(t,n);    if(!b) return a;    if(!a) return b;    push_finished_type(b);    push_finished_type(a);    push_type(T_OR); -  return pop_type(); +  return pop_unfinished_type();    }       case T_AND:    return low_index_type(t+type_length(t),n);       case T_STRING: /* always int */    case T_MULTISET: /* always int */    reference_shared_string(int_type_string);    return int_type_string;   
pike.git/src/pike_types.c:1071:    q++;    if(EXTRACT_UCHAR(q)!=T_VOID) return ~num;    return num;   }      struct pike_string *check_call(struct pike_string *args,    struct pike_string *type)   {    CHECK_TYPE(args);    CHECK_TYPE(type); -  reset_type_stack(); +  type_stack_mark();    max_correct_args=0; -  +     if(low_get_return_type(type->str,args->str))    { -  return pop_type(); +  return pop_unfinished_type();    }else{ -  +  pop_stack_mark();    return 0;    }   }      struct pike_string *get_type_of_svalue(struct svalue *s)   {    struct pike_string *ret;    switch(s->type)    {    case T_FUNCTION: