diff --git a/src/builtin.cmod b/src/builtin.cmod index a72568726b520facf2d545014b951ca2645a81cc..a74fa925e5ce29925e8570c3875b55aec4b0c687 100644 --- a/src/builtin.cmod +++ b/src/builtin.cmod @@ -2,7 +2,7 @@ || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information. -|| $Id: builtin.cmod,v 1.119 2003/02/11 09:28:19 grubba Exp $ +|| $Id: builtin.cmod,v 1.120 2003/02/16 03:59:57 mast Exp $ */ #include "global.h" @@ -113,7 +113,6 @@ PIKEFUN string basetype(mixed x) case T_FLOAT: push_constant_text("float"); break; case T_FUNCTION: push_constant_text("function"); break; case T_INT: push_constant_text("int"); break; - case T_LVALUE: push_constant_text("lvalue"); break; case T_MAPPING: push_constant_text("mapping"); break; case T_MULTISET: push_constant_text("multiset"); break; case T_OBJECT: push_constant_text("object"); break; @@ -122,7 +121,12 @@ PIKEFUN string basetype(mixed x) case T_TYPE: push_constant_text("type"); break; case T_ZERO: push_constant_text("zero"); break; case T_VOID: push_constant_text("void"); break; + /* The following are internal and shouldn't be applicable in normal use. */ + case T_SVALUE_PTR: push_constant_text("svalue_ptr"); break; + case T_OBJ_INDEX: push_constant_text("obj_index"); break; case T_MAPPING_DATA: push_constant_text("mapping_data"); break; + case T_PIKE_FRAME: push_constant_text("pike_frame"); break; + case T_MULTISET_DATA: push_constant_text("multiset_data"); break; default: push_constant_text("unknown"); break; } } diff --git a/src/code/ia32.c b/src/code/ia32.c index 5585fb6b6d3092da0b7d9ff0adc7dd92fb604877..f32dc4956fc6e9e3b337e48d7965f7269f1fdbc2 100644 --- a/src/code/ia32.c +++ b/src/code/ia32.c @@ -2,7 +2,7 @@ || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information. -|| $Id: ia32.c,v 1.23 2002/10/11 01:39:39 nilsson Exp $ +|| $Id: ia32.c,v 1.24 2003/02/16 03:59:58 mast Exp $ */ /* @@ -272,7 +272,7 @@ static void ia32_local_lvalue(INT32 arg) ia32_get_local_addr(arg); MEMSET(tmp, 0, sizeof(tmp)); - tmp[0].type=T_LVALUE; + tmp[0].type=T_SVALUE_PTR; tmp[0].u.lval=(struct svalue *)4711; tmp[1].type=T_VOID; diff --git a/src/interpret.c b/src/interpret.c index 843de0ab492234bf2d86fcee857bf359328a6a25..d50c6c681387d36deadd40f2e61b64fec077732b 100644 --- a/src/interpret.c +++ b/src/interpret.c @@ -2,11 +2,11 @@ || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information. -|| $Id: interpret.c,v 1.290 2003/02/15 17:33:33 grubba Exp $ +|| $Id: interpret.c,v 1.291 2003/02/16 03:59:57 mast Exp $ */ #include "global.h" -RCSID("$Id: interpret.c,v 1.290 2003/02/15 17:33:33 grubba Exp $"); +RCSID("$Id: interpret.c,v 1.291 2003/02/16 03:59:57 mast Exp $"); #include "interpret.h" #include "object.h" #include "program.h" @@ -286,9 +286,9 @@ use_malloc: * array[index] : { array, index } * mapping[index] : { mapping, index } * multiset[index] : { multiset, index } - * object[index] : { object, index } - * local variable : { svalue_pointer, nothing } - * global variable : { svalue_pointer/short_svalue_pointer, nothing } + * object[index] : { object, index } (external object indexing) + * local variable : { svalue pointer (T_SVALUE_PTR), nothing (T_VOID) } + * global variable : { object, identifier index (T_OBJ_INDEX) } (internal object indexing) */ void lvalue_to_svalue_no_free(struct svalue *to,struct svalue *lval) @@ -315,17 +315,15 @@ void lvalue_to_svalue_no_free(struct svalue *to,struct svalue *lval) break; } - case T_LVALUE: + case T_SVALUE_PTR: assign_svalue_no_free(to, lval->u.lval); break; - - case T_SHORT_LVALUE: - assign_from_short_svalue_no_free(to, lval->u.short_lval, - (TYPE_T)lval->subtype); - break; - + case T_OBJECT: - object_index_no_free(to, lval->u.object, lval+1); + if (lval[1].type == T_OBJ_INDEX) + low_object_index_no_free (to, lval->u.object, lval[1].u.identifier); + else + object_index_no_free(to, lval->u.object, lval+1); break; case T_ARRAY: @@ -383,16 +381,15 @@ PMOD_EXPORT void assign_lvalue(struct svalue *lval,struct svalue *from) } break; - case T_LVALUE: + case T_SVALUE_PTR: assign_svalue(lval->u.lval,from); break; - case T_SHORT_LVALUE: - assign_to_short_svalue(lval->u.short_lval, (TYPE_T)lval->subtype, from); - break; - case T_OBJECT: - object_set_index(lval->u.object, lval+1, from); + if (lval[1].type == T_OBJ_INDEX) + object_low_set_index (lval->u.object, lval[1].u.identifier, from); + else + object_set_index(lval->u.object, lval+1, from); break; case T_ARRAY: @@ -431,14 +428,10 @@ union anything *get_pointer_if_this_type(struct svalue *lval, TYPE_T t) case T_ARRAY_LVALUE: return 0; - case T_LVALUE: + case T_SVALUE_PTR: if(lval->u.lval->type == t) return & ( lval->u.lval->u ); return 0; - - case T_SHORT_LVALUE: - if(lval->subtype == t) return lval->u.short_lval; - return 0; - + case T_OBJECT: return object_get_item_ptr(lval->u.object,lval+1,t); @@ -2045,10 +2038,6 @@ void gdb_backtrace ( struct svalue *arg = f->locals + i; switch (arg->type) { - case T_LVALUE: - fputs ("lvalue", stderr); - break; - case T_INT: fprintf (stderr, "%ld", (long) arg->u.integer); break; diff --git a/src/interpret_functions.h b/src/interpret_functions.h index d726f247fae8b6e85f251098bd7b93929dd3415e..041aa7e8221ecd77ec55dff96da44da02b53c506 100644 --- a/src/interpret_functions.h +++ b/src/interpret_functions.h @@ -2,7 +2,7 @@ || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information. -|| $Id: interpret_functions.h,v 1.137 2003/02/15 14:59:35 grubba Exp $ +|| $Id: interpret_functions.h,v 1.138 2003/02/16 03:59:57 mast Exp $ */ /* @@ -408,7 +408,7 @@ OPCODE2(F_EXTERNAL_LVALUE, "& external", 0, { ref_push_object(loc.o); - Pike_sp->type=T_LVALUE; + Pike_sp->type=T_OBJ_INDEX; Pike_sp->u.integer=arg1 + loc.inherit->identifier_level; Pike_sp++; }); @@ -450,7 +450,7 @@ OPCODE2(F_GLOBAL_2_LOCAL, "local = global", 0, { }); OPCODE1(F_LOCAL_LVALUE, "& local", 0, { - Pike_sp[0].type = T_LVALUE; + Pike_sp[0].type = T_SVALUE_PTR; Pike_sp[0].u.lval = Pike_fp->locals + arg1; Pike_sp[1].type = T_VOID; Pike_sp += 2; @@ -474,7 +474,7 @@ OPCODE2(F_LEXICAL_LOCAL_LVALUE, "&lexical local", 0, { f=f->scope; if(!f) Pike_error("Lexical scope error.\n"); } - Pike_sp[0].type=T_LVALUE; + Pike_sp[0].type=T_SVALUE_PTR; Pike_sp[0].u.lval=f->locals+arg1; Pike_sp[1].type=T_VOID; Pike_sp+=2; @@ -724,7 +724,7 @@ OPCODE0(F_ADD_TO_AND_POP, "+= and pop", 0, { OPCODE1(F_GLOBAL_LVALUE, "& global", 0, { ref_push_object(Pike_fp->current_object); push_int(arg1 + Pike_fp->context.identifier_level); - Pike_sp[-1].type = T_LVALUE; + Pike_sp[-1].type = T_OBJ_INDEX; }); OPCODE0(F_INC, "++x", 0, { diff --git a/src/object.c b/src/object.c index 5b04f23437c5c53d5ff84249783d636949b7e84a..03a9b0c8819fb72349a9d0209ad7707e968b387d 100644 --- a/src/object.c +++ b/src/object.c @@ -2,11 +2,11 @@ || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information. -|| $Id: object.c,v 1.224 2003/02/15 16:02:05 grubba Exp $ +|| $Id: object.c,v 1.225 2003/02/16 04:05:16 mast Exp $ */ #include "global.h" -RCSID("$Id: object.c,v 1.224 2003/02/15 16:02:05 grubba Exp $"); +RCSID("$Id: object.c,v 1.225 2003/02/16 04:05:16 mast Exp $"); #include "object.h" #include "dynamic_buffer.h" #include "interpret.h" @@ -963,6 +963,8 @@ PMOD_EXPORT void schedule_really_free_object(struct object *o) } +/* Get a variable through internal indexing, i.e. directly by + * identifier index without going through `->= or `[]= lfuns. */ PMOD_EXPORT void low_object_index_no_free(struct svalue *to, struct object *o, ptrdiff_t f) @@ -1060,9 +1062,13 @@ PMOD_EXPORT void low_object_index_no_free(struct svalue *to, } } +/* Get a variable without going through `->= or `[]= lfuns. If index + * is a string then the externally visible identifiers are indexed. If + * index is T_OBJ_INDEX then any identifier is accessed through + * identifier index. */ PMOD_EXPORT void object_index_no_free2(struct svalue *to, - struct object *o, - struct svalue *index) + struct object *o, + struct svalue *index) { struct program *p; int f = -1; @@ -1079,11 +1085,15 @@ PMOD_EXPORT void object_index_no_free2(struct svalue *to, f=find_shared_string_identifier(index->u.string, p); break; - case T_LVALUE: - f=index->u.integer; + case T_OBJ_INDEX: + f=index->u.identifier; break; default: +#ifdef PIKE_DEBUG + if (index->type > MAX_TYPE) + Pike_fatal ("Invalid type %d in index.\n", index->type); +#endif Pike_error("Lookup in object with non-string index.\n"); } @@ -1099,6 +1109,8 @@ PMOD_EXPORT void object_index_no_free2(struct svalue *to, #define ARROW_INDEX_P(X) ((X)->type==T_STRING && (X)->subtype) +/* Get a variable through external indexing, i.e. by going through + * `-> or `[] lfuns, not seeing private and static etc. */ PMOD_EXPORT void object_index_no_free(struct svalue *to, struct object *o, struct svalue *index) @@ -1111,43 +1123,47 @@ PMOD_EXPORT void object_index_no_free(struct svalue *to, Pike_error("Lookup in destructed object.\n"); return; /* make gcc happy */ } - if (index->type != T_LVALUE) { - lfun=ARROW_INDEX_P(index) ? LFUN_ARROW : LFUN_INDEX; - if(p->flags & PROGRAM_FIXED) +#ifdef PIKE_DEBUG + if (index->type > MAX_TYPE) + Pike_fatal ("Invalid index type %d.\n", index->type); +#endif + + lfun=ARROW_INDEX_P(index) ? LFUN_ARROW : LFUN_INDEX; + + if(p->flags & PROGRAM_FIXED) + { + l=p->lfuns[lfun]; + }else{ + if(!(p->flags & PROGRAM_PASS_1_DONE)) { - l=p->lfuns[lfun]; - }else{ - if(!(p->flags & PROGRAM_PASS_1_DONE)) + if(report_compiler_dependency(p)) { - if(report_compiler_dependency(p)) - { #if 0 - fprintf(stderr,"Placeholder deployed for %p\n", p); + fprintf(stderr,"Placeholder deployed for %p\n", p); #endif - add_ref(to->u.object=placeholder_object); - to->type=T_OBJECT; - return; - } + add_ref(to->u.object=placeholder_object); + to->type=T_OBJECT; + return; } - l=low_find_lfun(p, lfun); - } - if(l != -1) - { - push_svalue(index); - apply_lfun(o, lfun, 1); - *to=sp[-1]; - sp--; - dmalloc_touch_svalue(sp); - } else { - object_index_no_free2(to, o, index); } + l=low_find_lfun(p, lfun); + } + if(l != -1) + { + push_svalue(index); + apply_lfun(o, lfun, 1); + *to=sp[-1]; + sp--; + dmalloc_touch_svalue(sp); } else { - low_object_index_no_free(to, o, index->u.integer); + object_index_no_free2(to, o, index); } } +/* Assign a variable through internal indexing, i.e. directly by + * identifier index without going through `->= or `[]= lfuns. */ PMOD_EXPORT void object_low_set_index(struct object *o, int f, struct svalue *from) @@ -1229,6 +1245,10 @@ PMOD_EXPORT void object_low_set_index(struct object *o, } } +/* Assign a variable without going through `->= or `[]= lfuns. If + * index is a string then the externally visible identifiers are + * indexed. If index is T_OBJ_INDEX then any identifier is accessed + * through identifier index. */ PMOD_EXPORT void object_set_index2(struct object *o, struct svalue *index, struct svalue *from) @@ -1246,39 +1266,39 @@ PMOD_EXPORT void object_set_index2(struct object *o, { case T_STRING: f=find_shared_string_identifier(index->u.string, p); - if(f<0) { - if (index->u.string->len < 1024) { - Pike_error("No such variable (%s) in object.\n", index->u.string->str); - } else { - Pike_error("No such variable in object.\n"); - } - } break; - case T_LVALUE: - f=index->u.integer; + case T_OBJ_INDEX: + f=index->u.identifier; break; default: +#ifdef PIKE_DEBUG + if (index->type > MAX_TYPE) + Pike_fatal ("Invalid type %d in index.\n", index->type); +#endif Pike_error("Lookup on non-string value.\n"); } if(f < 0) { - if (index->u.string->len < 1024) { + if (index->type == T_STRING && !index->u.string->size_shift && + index->u.string->len < 1024) Pike_error("No such variable (%s) in object.\n", index->u.string->str); - } else { + else Pike_error("No such variable in object.\n"); - } }else{ object_low_set_index(o, f, from); } } +/* Assign a variable through external indexing, i.e. by going through + * `->= or `[]= lfuns, not seeing private and static etc. */ PMOD_EXPORT void object_set_index(struct object *o, struct svalue *index, struct svalue *from) { + int lfun; struct program *p = NULL; if(!o || !(p=o->prog)) @@ -1287,20 +1307,21 @@ PMOD_EXPORT void object_set_index(struct object *o, return; /* make gcc happy */ } - if (index->type != T_LVALUE) { - int lfun=ARROW_INDEX_P(index) ? LFUN_ASSIGN_ARROW : LFUN_ASSIGN_INDEX; +#ifdef PIKE_DEBUG + if (index->type > MAX_TYPE) + Pike_fatal ("Invalid index type %d.\n", index->type); +#endif - if(FIND_LFUN(p, lfun) != -1) - { - push_svalue(index); - push_svalue(from); - apply_lfun(o, lfun, 2); - pop_stack(); - } else { - object_set_index2(o, index, from); - } + lfun=ARROW_INDEX_P(index) ? LFUN_ASSIGN_ARROW : LFUN_ASSIGN_INDEX; + + if(FIND_LFUN(p, lfun) != -1) + { + push_svalue(index); + push_svalue(from); + apply_lfun(o, lfun, 2); + pop_stack(); } else { - object_low_set_index(o, index->u.integer, from); + object_set_index2(o, index, from); } } @@ -1320,7 +1341,9 @@ static union anything *object_low_get_item_ptr(struct object *o, i=ID_FROM_INT(p, f); #ifdef PIKE_DEBUG - if (type == T_OBJECT || type == T_FUNCTION || type == T_LVALUE) + if (type > MAX_TYPE) + Pike_fatal ("Invalid type %d.\n", type); + if (type == T_OBJECT || type == T_FUNCTION) Pike_fatal ("Dangerous with the refcount-less this-pointers.\n"); #endif @@ -1373,18 +1396,26 @@ union anything *object_get_item_ptr(struct object *o, f=find_shared_string_identifier(index->u.string, p); break; - case T_LVALUE: - f=index->u.integer; + case T_OBJ_INDEX: + f=index->u.identifier; break; default: +#ifdef PIKE_DEBUG + if (index->type > MAX_TYPE) + Pike_fatal ("Invalid type %d in index.\n", index->type); +#endif /* Pike_error("Lookup on non-string value.\n"); */ return 0; } if(f < 0) { - Pike_error("No such variable in object.\n"); + if (index->type == T_STRING && !index->u.string->size_shift && + index->u.string->len < 1024) + Pike_error("No such variable (%s) in object.\n", index->u.string->str); + else + Pike_error("No such variable in object.\n"); }else{ return object_low_get_item_ptr(o, f, type); } @@ -2022,7 +2053,10 @@ static void f_magic_set_index(INT32 args) if(f<0) { - Pike_error("No such variable in object.\n"); + if (!s->size_shift && s->len < 1024) + Pike_error("No such variable (%s) in object.\n", s->str); + else + Pike_error("No such variable in object.\n"); }else{ object_low_set_index(o, f+inherit->identifier_level, val); diff --git a/src/pike_types.c b/src/pike_types.c index eb151b3d78964f5527cb26a22993fb5a886dddd9..13cc879939c1b3f36e80279cfc5613bd53461b45 100644 --- a/src/pike_types.c +++ b/src/pike_types.c @@ -2,11 +2,11 @@ || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information. -|| $Id: pike_types.c,v 1.206 2003/01/26 12:47:42 mirar Exp $ +|| $Id: pike_types.c,v 1.207 2003/02/16 03:59:57 mast Exp $ */ #include "global.h" -RCSID("$Id: pike_types.c,v 1.206 2003/01/26 12:47:42 mirar Exp $"); +RCSID("$Id: pike_types.c,v 1.207 2003/02/16 03:59:57 mast Exp $"); #include <ctype.h> #include "svalue.h" #include "pike_types.h" @@ -144,7 +144,8 @@ char *get_name_of_type(int t) case T_FLOAT: return "float"; case T_FUNCTION: return "function"; case T_INT: return "int"; - case T_LVALUE: return "lvalue"; + case T_SVALUE_PTR: return "svalue_ptr"; + case T_OBJ_INDEX: return "obj_index"; case T_MAPPING: return "mapping"; case T_MULTISET: return "multiset"; case T_OBJECT: return "object"; diff --git a/src/svalue.c b/src/svalue.c index 3079823c1451c1603db3321e3ebcf69aebc78fe8..1a90a953dfaaa544f534d1584258a590b654e933 100644 --- a/src/svalue.c +++ b/src/svalue.c @@ -2,7 +2,7 @@ || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information. -|| $Id: svalue.c,v 1.158 2003/02/10 20:33:39 mast Exp $ +|| $Id: svalue.c,v 1.159 2003/02/16 03:59:58 mast Exp $ */ #include "global.h" @@ -66,7 +66,7 @@ static int pike_isnan(double x) #endif /* HAVE__ISNAN */ #endif /* HAVE_ISNAN */ -RCSID("$Id: svalue.c,v 1.158 2003/02/10 20:33:39 mast Exp $"); +RCSID("$Id: svalue.c,v 1.159 2003/02/16 03:59:58 mast Exp $"); struct svalue dest_ob_zero = { T_INT, 0, @@ -1151,10 +1151,6 @@ PMOD_EXPORT void describe_svalue(const struct svalue *s,int indent,struct proces indent+=2; switch(s->type) { - case T_LVALUE: - my_strcat("lvalue"); - break; - case T_INT: sprintf(buf,"%"PRINTPIKEINT"d",s->u.integer); my_strcat(buf); diff --git a/src/svalue.h b/src/svalue.h index d5637d35e268032fe4df34bade3bb938d10c746a..d3db8d6d574576ae5f37b903422e69c66aee3159 100644 --- a/src/svalue.h +++ b/src/svalue.h @@ -2,7 +2,7 @@ || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information. -|| $Id: svalue.h,v 1.115 2003/02/15 02:51:06 mast Exp $ +|| $Id: svalue.h,v 1.116 2003/02/16 03:59:58 mast Exp $ */ #ifndef SVALUE_H @@ -67,8 +67,8 @@ union anything INT32 *refs; struct ref_dummy *dummy; FLOAT_TYPE float_number; - struct svalue *lval; /* only used on stack */ - union anything *short_lval; /* only used on stack */ + int identifier; /* Used with T_OBJ_INDEX. */ + struct svalue *lval; /* Used with T_SVALUE_PTR. */ void *ptr; }; @@ -99,7 +99,11 @@ struct svalue #define PIKE_T_ZERO 14 /* Can return 0, but nothing else */ #define T_UNFINISHED 15 /* Reserved for the garbage-collector */ -#define T_VOID 16 /* Can't return any value */ + +#define T_VOID 16 +/* Can't return any value. Also used on stack to fill out the second + * svalue on an lvalue when it isn't used. */ + #define T_MANY 17 #define PIKE_T_RING 240 @@ -109,8 +113,15 @@ struct svalue #define T_ASSIGN 245 #define T_DELETED 246 #define PIKE_T_UNKNOWN 247 -#define T_SHORT_LVALUE 248 -#define T_LVALUE 249 + +#define T_OBJ_INDEX 248 +/* svalue.u.identifer is an identifier index in an object. Primarily + * used in lvalues on stack. */ + +#define T_SVALUE_PTR 249 +/* svalue.u.lval points to an svalue. Primarily used in lvalues on + * stack. */ + #define T_ARRAY_LVALUE 250 #define PIKE_T_MIXED 251 #define T_NOT 253 @@ -317,7 +328,7 @@ do{ \ #ifdef PIKE_DEBUG PMOD_EXPORT extern void describe(void *); /* defined in gc.c */ PMOD_EXPORT extern const char msg_type_error[]; -#define check_type(T) if(T > MAX_TYPE && T!=T_LVALUE && T!=T_SHORT_LVALUE && T!=T_VOID && T!=T_DELETED && T!=T_ARRAY_LVALUE) Pike_fatal(msg_type_error,T) +#define check_type(T) if(T > MAX_TYPE && T!=T_SVALUE_PTR && T!=T_OBJ_INDEX && T!=T_VOID && T!=T_DELETED && T!=T_ARRAY_LVALUE) Pike_fatal(msg_type_error,T) #define check_svalue(S) debug_check_svalue(dmalloc_check_svalue(S,DMALLOC_LOCATION()))