From 6d22548c7cb45e0386e23a60dd92e6fe39c8723d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20H=C3=BCbinette=20=28Hubbe=29?= <hubbe@hubbe.net> Date: Wed, 28 Jan 1998 16:30:37 -0800 Subject: [PATCH] identifiers in parents should now work better Rev: lib/modules/Stdio.pmod:1.13 Rev: src/compilation.h:1.6 Rev: src/docode.c:1.26 Rev: src/fsort.c:1.4 Rev: src/global.h:1.14 Rev: src/las.c:1.47 Rev: src/object.c:1.35 Rev: src/object.h:1.15 Rev: src/pike_memory.c:1.7 Rev: src/program.c:1.59 Rev: src/program.h:1.29 --- lib/modules/Stdio.pmod | 7 ++---- src/compilation.h | 1 + src/docode.c | 25 +++++++++++++++--- src/fsort.c | 42 ++++++++++++++++++++----------- src/global.h | 34 +++++++++++++++++++++++++ src/las.c | 42 +++++++++++++++++++++++-------- src/object.c | 11 +------- src/object.h | 1 - src/pike_memory.c | 57 ++++++++++++++++++++++++++---------------- src/program.c | 50 ++++++++++++++++++++++++++++++------ src/program.h | 2 +- 11 files changed, 199 insertions(+), 73 deletions(-) diff --git a/lib/modules/Stdio.pmod b/lib/modules/Stdio.pmod index df2b35ad7b..7a04886f18 100644 --- a/lib/modules/Stdio.pmod +++ b/lib/modules/Stdio.pmod @@ -1,10 +1,7 @@ #include <string.h> -constant PROP_IPC=files.PROP_IPC; -constant PROP_NONBLOCk=files.PROP_NONBLOCK; -constant PROP_SHUTDOWN=files.PROP_SHUTDOWN; -constant PROP_BUFFERED=files.PROP_BUFFERED; -constant PROP_BIDIRECTIONAL=files.PROP_BIDIRECTIONAL; +inherit files; + constant File=files.file; constant Port=files.port; diff --git a/src/compilation.h b/src/compilation.h index e64f1c71fe..70ecf28bc3 100644 --- a/src/compilation.h +++ b/src/compilation.h @@ -77,6 +77,7 @@ SNAME(program_state,previous_program_state) ZMEMBER(INT32,last_line) STRMEMBER(last_file,"last_file") + ZMEMBER(struct object *,fake_object) ZMEMBER(struct program *,new_program) ZMEMBER(struct program *,malloc_size_program) ZMEMBER(node *,init_node) diff --git a/src/docode.c b/src/docode.c index c92c110c06..53f1650b34 100644 --- a/src/docode.c +++ b/src/docode.c @@ -4,7 +4,7 @@ ||| See the files COPYING and DISCLAIMER for more information. \*/ #include "global.h" -RCSID("$Id: docode.c,v 1.25 1998/01/25 08:25:05 hubbe Exp $"); +RCSID("$Id: docode.c,v 1.26 1998/01/29 00:30:33 hubbe Exp $"); #include "las.h" #include "program.h" #include "language.h" @@ -23,6 +23,7 @@ RCSID("$Id: docode.c,v 1.25 1998/01/25 08:25:05 hubbe Exp $"); #include "peep.h" #include "docode.h" #include "operators.h" +#include "object.h" INT32 current_break=-1; INT32 current_continue=-1; @@ -668,7 +669,7 @@ static int do_docode2(node *n,int flags) if(n->type == void_type_string) return 0; return 1; }else{ - if(CAR(n)->u.sval.u.object == &fake_object) + if(CAR(n)->u.sval.u.object->next == fake_object) { emit2(F_MARK); do_docode(CDR(n),0); @@ -1024,12 +1025,30 @@ static int do_docode2(node *n,int flags) case T_FUNCTION: if(n->u.sval.subtype!=FUNCTION_BUILTIN) { - if(n->u.sval.u.object == &fake_object) + if(n->u.sval.u.object == fake_object) { emit(F_LFUN,n->u.sval.subtype); return 1; } + + if(n->u.sval.u.object->next == n->u.sval.u.object) + { + int x=0; + struct object *o; + + for(o=fake_object->parent;o!=n->u.sval.u.object;o=o->parent) + x++; + emit(F_LDA, x); + emit(F_EXTERNAL, n->u.sval.subtype); + return 1; + } } + +#ifdef DEBUG + case T_OBJECT: + if(n->u.sval.u.object->next == n->u.sval.u.object) + fatal("Internal error: Pointer to parent cannot be a compile time constant!\n"); +#endif default: tmp1=store_constant(&(n->u.sval),!(n->tree_info & OPT_EXTERNAL_DEPEND)); diff --git a/src/fsort.c b/src/fsort.c index a463b22779..9c455d8394 100644 --- a/src/fsort.c +++ b/src/fsort.c @@ -17,40 +17,44 @@ static char *tmp_area; #define STEP(X,Y) (&((X)[(Y)])) #define ID fsort_1 -typedef struct a1 { char b[1]; } b1; -#define TYPE b1 +#define TYPE B1_T #include "fsort_template.h" #undef ID #undef TYPE +#ifdef B2_T #define ID fsort_2 -typedef struct a2 { char b[2]; } b2; -#define TYPE b2 +#define TYPE B2_T #include "fsort_template.h" #undef ID #undef TYPE +#endif +#ifdef B4_T #define ID fsort_4 -typedef struct a4 { char b[4]; } b4; -#define TYPE b4 +#define TYPE B4_T #include "fsort_template.h" #undef ID #undef TYPE +#endif +#ifdef B8_T #define ID fsort_8 -typedef struct a8 { char b[8]; } b8; -#define TYPE b8 +#define TYPE B8_T #include "fsort_template.h" #undef ID #undef TYPE +#endif + +#ifdef B16_T #define ID fsort_16 -typedef struct a16 { char b[16]; } b16; -#define TYPE b16 +#define TYPE B16_T #include "fsort_template.h" #undef ID #undef TYPE +#endif #undef SWAP #undef STEP @@ -83,11 +87,19 @@ void fsort(void *base, switch(elmSize) { - case 1: fsort_1(( b1 *)base,(elms-1)+( b1 *)base); break; - case 2: fsort_2(( b2 *)base,(elms-1)+( b2 *)base); break; - case 4: fsort_4(( b4 *)base,(elms-1)+( b4 *)base); break; - case 8: fsort_8(( b8 *)base,(elms-1)+( b8 *)base); break; - case 16: fsort_16((b16 *)base,(elms-1)+(b16 *)base); break; + case 1: fsort_1(( B1_T *)base,(elms-1)+( B1_T *)base); break; +#ifdef B2_T + case 2: fsort_2(( B2_T *)base,(elms-1)+( B2_T *)base); break; +#endif +#ifdef B4_T + case 4: fsort_4(( B4_T *)base,(elms-1)+( B4_T *)base); break; +#endif +#ifdef B8_T + case 8: fsort_8(( B8_T *)base,(elms-1)+( B8_T *)base); break; +#endif +#ifdef B16_T + case 16: fsort_16((B16_T *)base,(elms-1)+(B16_T *)base); break; +#endif default: tmp_area=(char *)alloca(elmSize); fsort_n((char *)base,((char *)base) + size * (elms - 1)); diff --git a/src/global.h b/src/global.h index d5abb067c1..31b28620a8 100644 --- a/src/global.h +++ b/src/global.h @@ -133,7 +133,41 @@ char *alloca (); #define FLOAT_TYPE float +#define B1_T char +#if SIZEOF_SHORT == 2 +#define B2_T short +#elif SIZEOF_INT == 2 +#define B2_T int +#endif + +#if SIZEOF_SHORT == 4 +#define B4_T short +#elif SIZEOF_INT == 4 +#define B4_T int +#elif SIZEOF_LONG == 4 +#define B4_T long +#endif + +#if SIZEOF_INT == 8 +#define B8_T int +#elif SIZEOF_LONG == 8 +#define B8_T long +#elif SIZEOF_CHAR_P == 8 +#define B8_T char * +#elif SIZEOF_DOUBLE == 8 +#define B8_T double +#elif defined(B4_T) +struct b8_t_s { B4_T x,y; }; +#define B8_T struct b8_t +#endif + +#if SIZEOF_DOUBLE == 16 +#define B16_T double +#elif defined(B8_T) +struct b16_t { B8_T x,y; }; +#define B16_T struct b16_t +#endif #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7) diff --git a/src/las.c b/src/las.c index 156c8d57ff..4b707e6b8d 100644 --- a/src/las.c +++ b/src/las.c @@ -4,7 +4,7 @@ ||| See the files COPYING and DISCLAIMER for more information. \*/ #include "global.h" -RCSID("$Id: las.c,v 1.46 1998/01/27 20:51:56 hubbe Exp $"); +RCSID("$Id: las.c,v 1.47 1998/01/29 00:30:34 hubbe Exp $"); #include "language.h" #include "interpret.h" @@ -524,7 +524,12 @@ node *mkexternalnode(int level, copy_shared_string(res->type, id->type); /* FIXME */ - res->node_info = OPT_NOT_CONST; + if(IDENTIFIER_IS_CONSTANT(ID_FROM_INT(parent_compilation(level), i)->identifier_flags)) + { + res->node_info = OPT_EXTERNAL_DEPEND; + }else{ + res->node_info = OPT_NOT_CONST; + } res->tree_info=res->node_info; #ifdef __CHECKER__ @@ -772,12 +777,21 @@ node *mksvaluenode(struct svalue *s) return make_node_from_mapping(s->u.mapping); case T_OBJECT: - if(s->u.object == &fake_object) + if(s->u.object == fake_object) { return mkefuncallnode("this_object", 0); -/* }else{ - yyerror("Non-constant object pointer! (should not happen!)"); - */ + } + if(s->u.object->next == s->u.object) + { + int x=0; + struct object *o; + node *n=mkefuncallnode("this_object", 0); + for(o=fake_object;o!=s->u.object;o=o->parent) + { + n=mkefuncallnode("function_object", + mkefuncallnode("object_program",n)); + } + return n; } break; @@ -785,9 +799,19 @@ node *mksvaluenode(struct svalue *s) { if(s->subtype != FUNCTION_BUILTIN) { - if(s->u.object == &fake_object) + if(s->u.object == fake_object) return mkidentifiernode(s->subtype); + if(s->u.object->next == s->u.object) + { + int x=0; + struct object *o; + for(o=fake_object->parent;o!=s->u.object;o=o->parent) x++; + return mkexternalnode(x, s->subtype, + ID_FROM_INT(o->prog, s->subtype)); + + } + /* yyerror("Non-constant function pointer! (should not happen!)"); */ } } @@ -2053,13 +2077,11 @@ int eval_low(node *n) foo.counter=10000; foo.yes=0; - setup_fake_object(); - tmp_callback=add_to_callback(&evaluator_callbacks, check_evaluation_time, (void *)&foo,0); - if(apply_low_safe_and_stupid(&fake_object, jump)) + if(apply_low_safe_and_stupid(fake_object, jump)) { /* Generate error message */ if(throw_value.type == T_ARRAY && throw_value.u.array->size) diff --git a/src/object.c b/src/object.c index 3360b32e3a..60d26241b3 100644 --- a/src/object.c +++ b/src/object.c @@ -4,7 +4,7 @@ ||| See the files COPYING and DISCLAIMER for more information. \*/ #include "global.h" -RCSID("$Id: object.c,v 1.34 1998/01/26 19:59:56 hubbe Exp $"); +RCSID("$Id: object.c,v 1.35 1998/01/29 00:30:35 hubbe Exp $"); #include "object.h" #include "dynamic_buffer.h" #include "interpret.h" @@ -26,15 +26,6 @@ struct object *master_object = 0; struct program *master_program =0; struct object *first_object; -struct object fake_object = { 1 }; /* start with one reference */ - -void setup_fake_object(void) -{ - fake_object.prog=new_program; - fake_object.next=0; - fake_object.refs=0xffffff; -} - struct object *low_clone(struct program *p) { int e; diff --git a/src/object.h b/src/object.h index ee127e8bc8..650b1cf851 100644 --- a/src/object.h +++ b/src/object.h @@ -25,7 +25,6 @@ struct object char storage[1]; }; -extern struct object fake_object; extern struct object *first_object; extern struct object *master_object; extern struct program *master_program; diff --git a/src/pike_memory.c b/src/pike_memory.c index 4954205893..6838257a33 100644 --- a/src/pike_memory.c +++ b/src/pike_memory.c @@ -44,23 +44,31 @@ void swap(char *a, char *b, INT32 size) 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; \ +#define DOSIZE(X,Y) \ + case X: \ + { \ + Y tmp; \ + Y *start=(Y *) memory; \ + 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) + DOSIZE(1,B1_T) +#ifdef B2_T + DOSIZE(2,B2_T) +#endif +#ifdef B4_T + DOSIZE(4,B4_T) +#endif +#ifdef B16_T + DOSIZE(8,B8_T) +#endif +#ifdef B16_T + DOSIZE(16,B8_T) +#endif default: { char *start = (char *) memory; @@ -89,9 +97,8 @@ void reorder(char *memory, INT32 nitems, INT32 size,INT32 *order) #define DOSIZE(X,Y) \ case X: \ { \ - struct Y { char tt[X]; }; \ - struct Y *from=(struct Y *) memory; \ - struct Y *to=(struct Y *) tmp; \ + Y *from=(Y *) memory; \ + Y *to=(Y *) tmp; \ for(e=0;e<nitems;e++) to[e]=from[order[e]]; \ break; \ } @@ -99,11 +106,19 @@ void reorder(char *memory, INT32 nitems, INT32 size,INT32 *order) switch(size) { - DOSIZE(1,TMP1) - DOSIZE(2,TMP2) - DOSIZE(4,TMP4) - DOSIZE(8,TMP8) - DOSIZE(16,TMP16) + DOSIZE(1,B1_T) +#ifdef B2_T + DOSIZE(2,B2_T) +#endif +#ifdef B4_T + DOSIZE(4,B4_T) +#endif +#ifdef B8_T + DOSIZE(8,B8_T) +#endif +#ifdef B16_T + DOSIZE(16,B16_T) +#endif default: for(e=0;e<nitems;e++) MEMCPY(tmp+e*size, memory+order[e]*size, size); diff --git a/src/program.c b/src/program.c index e1821cf52d..ee30198258 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.58 1998/01/28 00:31:17 hubbe Exp $"); +RCSID("$Id: program.c,v 1.59 1998/01/29 00:30:36 hubbe Exp $"); #include "program.h" #include "object.h" #include "dynamic_buffer.h" @@ -91,6 +91,7 @@ struct program *first_program = 0; static int current_program_id=0; struct program *new_program=0; +struct object *fake_object=0; struct program *malloc_size_program=0; int compiler_pass; @@ -214,12 +215,17 @@ struct node_s *find_module_identifier(struct pike_string *ident) #if 0 if(IDENTIFIER_IS_CONSTANT(id->identifier_flags)) { - ret=mksvaluenode(PROG_FROM_INT(p->new_program, i)->constants+ - id->func.offset); - return ret; + struct svalue *s=PROG_FROM_INT(p->new_program, i)->constants+ + id->func.offset; + if(s->type != T_PROGRAM) + { + ret=mksvaluenode(s); + return ret; + } } #endif - return mkexternalnode(n, i, id); + + return mkexternalnode(n, i, id); } } } @@ -367,7 +373,7 @@ void low_start_new_program(struct program *p, struct pike_string *name, int flags) { - int e; + int e,id=0; threads_disabled++; compilation_depth++; @@ -391,7 +397,7 @@ void low_start_new_program(struct program *p, struct svalue s; s.type=T_PROGRAM; s.u.program=p; - add_constant(name, &s, flags); + id=add_constant(name, &s, flags); } #define PUSH @@ -408,6 +414,29 @@ void low_start_new_program(struct program *p, } malloc_size_program = ALLOC_STRUCT(program); +#ifdef DEBUG + fake_object=(struct object *)xalloc(sizeof(struct object) + 256*sizeof(struct svalue)); + /* Stipple to find illegal accesses */ + MEMSET(fake_object,0x55,sizeof(struct object) + 256*sizeof(struct svalue)); +#else + fake_object=ALLOC_STRUCT(object); +#endif + + fake_object->next=fake_object; + fake_object->prev=fake_object; + fake_object->refs=1; + fake_object->parent=0; + fake_object->parent_identifier=0; + fake_object->prog=p; + p->refs++; + + if(name) + { + if((fake_object->parent=previous_program_state->fake_object)) + fake_object->parent->refs++; + fake_object->parent_identifier=id; + } + new_program=p; if(new_program->program) @@ -558,6 +587,13 @@ static void toss_compilation_resources(void) free((char *)malloc_size_program); malloc_size_program=0; } + + if(fake_object) + { + fake_object->prog=0; + free_object(fake_object); + fake_object=0; + } while(compiler_frame) pop_compiler_frame(); diff --git a/src/program.h b/src/program.h index e18f49936d..513c0b76ad 100644 --- a/src/program.h +++ b/src/program.h @@ -214,7 +214,7 @@ struct program #define free_program(p) do{ struct program *_=(p); if(!--_->refs) really_free_program(_); }while(0) -extern struct object fake_object; +extern struct object *fake_object; extern struct program *new_program; extern struct program *first_program; extern int compiler_pass; -- GitLab