From 36feac31f057bfa9887842c206f0f8c21e8e3527 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20H=C3=BCbinette=20=28Hubbe=29?= <hubbe@hubbe.net> Date: Thu, 6 Mar 1997 21:21:47 -0800 Subject: [PATCH] recursive compiling bug fixed Rev: src/ChangeLog:1.83 Rev: src/interpret.c:1.28 Rev: src/interpret.h:1.10 Rev: src/memory.c:1.4 Rev: src/pike_types.c:1.17 Rev: src/pike_types.h:1.4 Rev: src/program.c:1.25 Rev: src/version.c:1.12 --- src/ChangeLog | 10 +++++++ src/interpret.c | 17 ++++++++++- src/interpret.h | 2 ++ src/memory.c | 50 ++++++++++++++++++++++++++++++- src/pike_types.c | 76 +++++++++++++++++++++++------------------------- src/pike_types.h | 10 ++++--- src/program.c | 6 +++- src/version.c | 2 +- 8 files changed, 126 insertions(+), 47 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 91a5a9dd41..2f9260b147 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,13 @@ +Thu Mar 6 21:19:28 1997 Fredrik Hubinette <hubbe@cytocin.hubbe.net> + + * pike_types.c: recurseive compiling bugs fixed + +Tue Mar 4 21:09:25 1997 Fredrik Hubinette <hubbe@cytocin.hubbe.net> + + * peephole optimizer improved + * fatal bug in get_type_of_svalue fixed + * fatal bug in constant (when using non-constant values) fixed + Tue Mar 4 23:07:31 1997 Henrik Grubbstr�m <grubba@infovav.se> * dynamic_load.c (f_load_module): Now works on FreeBSD. diff --git a/src/interpret.c b/src/interpret.c index 8c845ca850..aa29707fae 100644 --- a/src/interpret.c +++ b/src/interpret.c @@ -4,7 +4,7 @@ ||| See the files COPYING and DISCLAIMER for more information. \*/ #include "global.h" -RCSID("$Id: interpret.c,v 1.27 1997/03/05 05:32:14 hubbe Exp $"); +RCSID("$Id: interpret.c,v 1.28 1997/03/07 05:21:45 hubbe Exp $"); #include "interpret.h" #include "object.h" #include "program.h" @@ -66,6 +66,21 @@ struct svalue **mark_sp; /* Current position */ struct svalue **mark_stack; /* Start of stack */ int mark_stack_malloced = 0; +void push_sp_mark() +{ + if(mark_sp == mark_stack + stack_size) + error("No more mark stack!\n"); + *mark_sp++=sp; +} +int pop_sp_mark() +{ +#ifdef DEBUG + if(mark_sp < mark_stack) + fatal("Mark stack underflow!\n"); +#endif + return sp - *--mark_sp; +} + struct frame *fp; /* frame pointer */ void init_interpreter() diff --git a/src/interpret.h b/src/interpret.h index 9760b27888..d57a09be95 100644 --- a/src/interpret.h +++ b/src/interpret.h @@ -69,6 +69,8 @@ do{ \ }while(0) /* Prototypes begin here */ +void push_sp_mark(); +int pop_sp_mark(); void init_interpreter(); void check_stack(INT32 size); void check_mark_stack(INT32 size); diff --git a/src/memory.c b/src/memory.c index 84a31ae092..a99396b29c 100644 --- a/src/memory.c +++ b/src/memory.c @@ -20,6 +20,54 @@ char *xalloc(SIZE_T size) return 0; } +void swap(char *a, char *b, INT32 size) +{ + int tmp; + char tmpbuf[1024]; + while(size) + { + tmp=MINIMUM((long)sizeof(tmpbuf), size); + MEMCPY(tmpbuf,a,tmp); + MEMCPY(b,a,tmp); + MEMCPY(b,tmpbuf,tmp); + size-=tmp; + a+=tmp; + b+=tmp; + } +} + +void reverse(char *memory, INT32 nitems, INT32 size) +{ +#define DOSIZE(X,Y) \ + case X: \ + { \ + struct Y { char tt[X]; }; \ + struct Y tmp; \ + struct Y *start=(struct Y *) memory; \ + struct Y *end=start+nitems-1; \ + while(start<end){tmp=*start;*(start++)=*end;*(end--)=tmp;} \ + break; \ + } + + switch(size) + { + DOSIZE(1,TMP1) + DOSIZE(2,TMP2) + DOSIZE(4,TMP4) + DOSIZE(8,TMP8) + default: + { + char *start = (char *) memory; + char *end=start+(nitems-1)*size; + while(start<end) + { + swap(start,end,size); + start+=size; + end-=size; + } + } + } +} /* * This function may NOT change 'order' @@ -30,7 +78,7 @@ void reorder(char *memory, INT32 nitems, INT32 size,INT32 *order) INT32 e; char *tmp; tmp=xalloc(size * nitems); - +#undef DOSIZE #define DOSIZE(X,Y) \ case X: \ { \ diff --git a/src/pike_types.c b/src/pike_types.c index 43715dca8c..e1cb7f6516 100644 --- a/src/pike_types.c +++ b/src/pike_types.c @@ -4,7 +4,7 @@ ||| 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" @@ -133,10 +133,12 @@ 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() @@ -147,13 +149,13 @@ void type_stack_mark() 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() @@ -165,34 +167,31 @@ void pop_type_stack() 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) @@ -213,9 +212,11 @@ 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; @@ -223,19 +224,12 @@ struct pike_string *pop_unfinished_type() 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]; @@ -460,12 +454,13 @@ static void internal_parse_type(char **s) */ 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 @@ -953,6 +948,7 @@ static struct pike_string *low_index_type(char *t, node *n) 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); @@ -961,7 +957,7 @@ static struct pike_string *low_index_type(char *t, node *n) push_finished_type(b); push_finished_type(a); push_type(T_OR); - return pop_type(); + return pop_unfinished_type(); } case T_AND: @@ -1078,12 +1074,14 @@ struct pike_string *check_call(struct pike_string *args, { 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; } } diff --git a/src/pike_types.h b/src/pike_types.h index 50a0af8c67..427d6cac1f 100644 --- a/src/pike_types.h +++ b/src/pike_types.h @@ -22,15 +22,18 @@ extern struct pike_string *mixed_type_string; extern struct pike_string *void_type_string; extern struct pike_string *any_type_string; +#define init_type_stack type_stack_mark +#define exit_type_stack pop_stack_mark + /* Prototypes begin here */ void init_types(); -void reset_type_stack(); +void push_type(unsigned char tmp); void type_stack_mark(); -unsigned char *pop_stack_mark(); +INT32 pop_stack_mark(); void pop_type_stack(); void type_stack_pop_to_mark(); +void reset_type_stack(); void type_stack_reverse(); -void push_type(unsigned char tmp); void push_type_int(unsigned INT32 i); void push_unfinished_type(char *s); void push_finished_type(struct pike_string *type); @@ -50,7 +53,6 @@ int check_indexing(struct pike_string *type, int count_arguments(struct pike_string *s); struct pike_string *check_call(struct pike_string *args, struct pike_string *type); -void check_array_type(struct array *a); struct pike_string *get_type_of_svalue(struct svalue *s); char *get_name_of_type(int t); void cleanup_pike_types(); diff --git a/src/program.c b/src/program.c index 6175114e60..fb7b81f151 100644 --- a/src/program.c +++ b/src/program.c @@ -4,7 +4,7 @@ ||| See the files COPYING and DISCLAIMER for more information. \*/ #include "global.h" -RCSID("$Id: program.c,v 1.24 1997/03/01 17:56:29 grubba Exp $"); +RCSID("$Id: program.c,v 1.25 1997/03/07 05:21:47 hubbe Exp $"); #include "program.h" #include "object.h" #include "dynamic_buffer.h" @@ -236,6 +236,8 @@ void start_new_program() previous_program_state->fake_program.inherits[0].prog= &previous_program_state->fake_program; + init_type_stack(); + for(e=0; e<NUM_AREAS; e++) low_reinit_buf(areas + e); low_reinit_buf(& inherit_names); low_reinit_buf(& used_modules); @@ -564,6 +566,8 @@ struct program *end_program() init_node=0; } + exit_type_stack(); + if (num_parse_error > 0) { toss_current_program(); diff --git a/src/version.c b/src/version.c index 67afda03c9..3bad9a51b0 100644 --- a/src/version.c +++ b/src/version.c @@ -12,5 +12,5 @@ void f_version(INT32 args) { pop_n_elems(args); - push_text("Pike v0.5b2"); + push_text("Pike v0.5b3"); } -- GitLab