* Changed all copyright messages to include 1993.

* Stubs for faster implementation of local variables (not yet finished)
* Added function name to code object.  Print it for code and function
  objects.  THIS MAKES THE .PYC FILE FORMAT INCOMPATIBLE (the version
  number has changed accordingly)
* Print address of self for built-in methods
* New internal functions getattro and setattro (getattr/setattr with
  string object arg)
* Replaced "dictobject" with more powerful "mappingobject"
* New per-type functio tp_hash to implement arbitrary object hashing,
  and hashobject() to interface to it
* Added built-in functions hash(v) and hasattr(v, 'name')
* classobject: made some functions static that accidentally weren't;
  added __hash__ special instance method to implement hash()
* Added proper comparison for built-in methods and functions
This commit is contained in:
Guido van Rossum 1993-03-29 10:43:31 +00:00
parent 4b1302bd1d
commit 9bfef44d97
97 changed files with 559 additions and 246 deletions

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@ -28,7 +28,9 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* An intermediate code fragment contains:
- a string that encodes the instructions,
- a list of the constants,
- and a list of the names used. */
- a list of the names used,
- the filename from which it was compiled,
- the name of the object for which it was compiled. */
typedef struct {
OB_HEAD
@ -36,6 +38,7 @@ typedef struct {
object *co_consts; /* list of immutable constant objects */
object *co_names; /* list of stringobjects */
object *co_filename; /* string */
object *co_name; /* string */
} codeobject;
extern typeobject Codetype;
@ -46,4 +49,5 @@ extern typeobject Codetype;
/* Public interface */
struct _node; /* Declare the existence of this type */
codeobject *compile PROTO((struct _node *, char *));
codeobject *newcodeobject PROTO((object *, object *, object *, object *));
codeobject *newcodeobject
PROTO((object *, object *, object *, object *, object *));

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@ -22,28 +22,23 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
******************************************************************/
/*
Dictionary object type -- mapping from char * to object.
NB: the key is given as a char *, not as a stringobject.
These functions set errno for errors. Functions dictremove() and
dictinsert() return nonzero for errors, getdictsize() returns -1,
the others NULL. A successful call to dictinsert() calls INCREF()
for the inserted item.
*/
/* All in the sake of backward compatibility... */
extern typeobject Dicttype;
#include "mappingobject.h"
#define is_dictobject(op) ((op)->ob_type == &Dicttype)
#define is_dictobject(op) is_mappingobject(op)
#define newdictobject newmappingobject
extern object *newdictobject PROTO((void));
extern object *dictlookup PROTO((object *dp, char *key));
extern int dictinsert PROTO((object *dp, char *key, object *item));
extern int dictremove PROTO((object *dp, char *key));
extern int getdictsize PROTO((object *dp));
extern char *getdictkey PROTO((object *dp, int i));
extern object *getdictkeys PROTO((object *dp));
extern object *getdict2key PROTO((object *dp, int i));
extern object *dict2lookup PROTO((object *dp, object *key));
extern int dict2insert PROTO((object *dp, object *key, object *item));
extern int dict2remove PROTO((object *dp, object *key));
#define getdictsize getmappingsize
#define getdictkeys getmappingkeys
#define getdict2key getmappingkey
#define dict2lookup mappinglookup
#define dict2insert mappinginsert
#define dict2remove mappingremove

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@ -188,6 +188,10 @@ typedef struct _typeobject {
number_methods *tp_as_number;
sequence_methods *tp_as_sequence;
mapping_methods *tp_as_mapping;
/* More standard operations (at end for binary compatibility) */
long (*tp_hash) FPROTO((object *));
} typeobject;
extern typeobject Typetype; /* The type of type objects */
@ -199,7 +203,9 @@ extern int printobject PROTO((object *, FILE *, int));
extern object * reprobject PROTO((object *));
extern int cmpobject PROTO((object *, object *));
extern object *getattr PROTO((object *, char *));
extern int setattr PROTO((object *, char *, object *));
extern object *getattro PROTO((object *, object *));
extern int setattro PROTO((object *, object *, object *));
extern long hashobject PROTO((object *));
/* Flag bits for printing: */
#define PRINT_RAW 1 /* No string quotes etc. */

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@ -113,6 +113,10 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#define LOAD_LOCAL 115 /* Index in name list */
#define LOAD_GLOBAL 116 /* Index in name list */
#define LOAD_FAST 117 /* Local variable number */
#define STORE_FAST 118 /* Local variable number */
#define RESERVE_FAST 119 /* Number of local variables */
#define SETUP_LOOP 120 /* Target address (absolute) */
#define SETUP_EXCEPT 121 /* "" */
#define SETUP_FINALLY 122 /* "" */

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/**********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -62,12 +62,12 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "patchlevel.h"
#define VERSION "0.9.%d (%s)"
#define VERSION "0.9.%d BETA (%s)"
#ifdef __DATE__
#define DATE __DATE__
#else
#define DATE ">= 11 Jan 1993"
#define DATE ">= 27 Mar 1993"
#endif
#ifdef USE_STDWIN

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -58,7 +58,7 @@ static imgfile_error(str)
{
err_setstr(ImgfileError, str);
error_called = 1;
return; /* To imglib, which will return a failure indictaor */
return; /* To imglib, which will return a failure indicator */
}

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -261,7 +261,7 @@ instance_setattr(inst, name, v)
return dictinsert(inst->in_attr, name, v);
}
object *
static object *
instance_repr(inst)
instanceobject *inst;
{
@ -280,7 +280,7 @@ instance_repr(inst)
return res;
}
int
static int
instance_compare(inst, other)
instanceobject *inst, *other;
{
@ -311,7 +311,43 @@ instance_compare(inst, other)
return outcome;
}
int
static long
instance_hash(inst)
instanceobject *inst;
{
object *func;
object *res;
int outcome;
func = instance_getattr(inst, "__hash__");
if (func == NULL) {
/* If there is no __cmp__ method, we hash on the address.
If a __cmp__ method exists, there must be a __hash__. */
err_clear();
func = instance_getattr(inst, "__cmp__");
if (func == NULL)
return (long)inst;
err_setstr(TypeError, "unhashable instance");
return -1;
}
res = call_object(func, (object *)NULL);
DECREF(func);
if (res == NULL)
return -1;
if (is_intobject(res)) {
outcome = getintvalue(res);
if (outcome == -1)
outcome = -2;
}
else {
err_setstr(TypeError, "__hash__() should return an int");
outcome = -1;
}
DECREF(res);
return outcome;
}
static int
instance_length(inst)
instanceobject *inst;
{
@ -339,7 +375,7 @@ instance_length(inst)
return outcome;
}
object *
static object *
instance_subscript(inst, key)
instanceobject *inst;
object *key;
@ -362,7 +398,7 @@ instance_subscript(inst, key)
return res;
}
int
static int
instance_ass_subscript(inst, key, value)
instanceobject*inst;
object *key;
@ -395,7 +431,7 @@ instance_ass_subscript(inst, key, value)
return 0;
}
mapping_methods instance_as_mapping = {
static mapping_methods instance_as_mapping = {
instance_length, /*mp_length*/
instance_subscript, /*mp_subscript*/
instance_ass_subscript, /*mp_ass_subscript*/
@ -612,7 +648,7 @@ UNARY(instance_neg, "__neg__")
UNARY(instance_pos, "__pos__")
UNARY(instance_abs, "__abs__")
int
static int
instance_nonzero(self)
instanceobject *self;
{
@ -739,9 +775,10 @@ typeobject Instancetype = {
&instance_as_number, /*tp_as_number*/
&instance_as_sequence, /*tp_as_sequence*/
&instance_as_mapping, /*tp_as_mapping*/
instance_hash, /*tp_hash*/
};
object *
static object *
instance_convert(inst, methodname)
object *inst;
char *methodname;
@ -837,6 +874,20 @@ instancemethod_compare(a, b)
return cmp;
}
static long
instancemethod_hash(a)
instancemethodobject *a;
{
long x, y;
x = hashobject(a->im_self);
if (x == -1)
return -1;
y = hashobject(a->im_func);
if (y == -1)
return -1;
return x ^ y;
}
typeobject Instancemethodtype = {
OB_HEAD_INIT(&Typetype)
0,
@ -852,4 +903,5 @@ typeobject Instancemethodtype = {
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
instancemethod_hash, /*tp_hash*/
};

View File

@ -24,8 +24,13 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* Mapping object implementation; using a hash table */
/* This file should really be called "dictobject.c", since "mapping"
is the generic name for objects with an unorderred arbitrary key
set (just like lists are sequences), but since it improves (and was
originally derived from) a file by that name I had to change its
name. For the user these objects are still called "dictionaries". */
#include "allobjects.h"
#include "mappingobject.h"
#include "modsupport.h"
@ -593,7 +598,7 @@ mapping_getattr(mp, name)
typeobject Mappingtype = {
OB_HEAD_INIT(&Typetype)
0,
"mapping",
"dictionary",
sizeof(mappingobject),
0,
mapping_dealloc, /*tp_dealloc*/

View File

@ -145,6 +145,38 @@ float_compare(v, w)
return (i < j) ? -1 : (i > j) ? 1 : 0;
}
static long
float_hash(v)
floatobject *v;
{
double intpart, fractpart;
int expo;
long x;
/* This is designed so that Python numbers with the same
value hash to the same value, otherwise comparisons
of mapping keys will turn out weird */
fractpart = modf(v->ob_fval, &intpart);
if (fractpart == 0.0) {
if (intpart > 0x7fffffffL || -intpart > 0x7fffffffL) {
/* Convert to long int and use its hash... */
object *w = dnewlongobject(v->ob_fval);
if (w == NULL)
return -1;
x = hashobject(w);
DECREF(w);
return x;
}
x = (long)intpart;
}
else {
fractpart = frexp(fractpart, &expo);
x = (long) (intpart + fractpart) ^ expo; /* Rather arbitrary */
}
if (x == -1)
x = -2;
return x;
}
static object *
float_add(v, w)
floatobject *v;
@ -378,4 +410,5 @@ typeobject Floattype = {
&float_as_number, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
float_hash, /*tp_hash */
};

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@ -25,7 +25,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* Function object implementation */
#include "allobjects.h"
#include "compile.h"
#include "structmember.h"
typedef struct {
@ -98,6 +98,17 @@ func_dealloc(op)
DEL(op);
}
static object*
func_repr(op)
funcobject *op;
{
char buf[140];
sprintf(buf, "<function %.100s at %lx>",
getstringvalue(((codeobject*)(op->func_code))->co_name),
(long)op);
return newstringobject(buf);
}
typeobject Functype = {
OB_HEAD_INIT(&Typetype)
0,
@ -109,5 +120,5 @@ typeobject Functype = {
func_getattr, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_compare*/
0, /*tp_repr*/
func_repr, /*tp_repr*/
};

View File

@ -144,6 +144,16 @@ int_compare(v, w)
return (i < j) ? -1 : (i > j) ? 1 : 0;
}
static long
int_hash(v)
intobject *v;
{
long x = v -> ob_ival;
if (x == -1)
x = -2;
return x;
}
static object *
int_add(v, w)
intobject *v;
@ -413,7 +423,7 @@ int_or(v, w)
static object *
int_int(v)
object *v;
intobject *v;
{
INCREF(v);
return v;
@ -421,26 +431,24 @@ int_int(v)
static object *
int_long(v)
object *v;
intobject *v;
{
long x = getintvalue(v);
return newlongobject(x);
return newlongobject((v -> ob_ival));
}
static object *
int_float(v)
object *v;
intobject *v;
{
long x = getintvalue(v);
return newfloatobject((double)x);
return newfloatobject((double)(v -> ob_ival));
}
static object *
int_oct(v)
object *v;
intobject *v;
{
char buf[20];
long x = getintvalue(v);
long x = v -> ob_ival;
if (x == 0)
strcpy(buf, "0");
else if (x > 0)
@ -452,10 +460,10 @@ int_oct(v)
static object *
int_hex(v)
object *v;
intobject *v;
{
char buf[20];
long x = getintvalue(v);
long x = v -> ob_ival;
if (x >= 0)
sprintf(buf, "0x%lx", x);
else
@ -463,7 +471,6 @@ int_hex(v)
return newstringobject(buf);
}
static number_methods int_as_number = {
int_add, /*nb_add*/
int_sub, /*nb_subtract*/
@ -505,4 +512,5 @@ typeobject Inttype = {
&int_as_number, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
&int_hash, /*tp_hash*/
};

View File

@ -555,6 +555,7 @@ static void long_dealloc PROTO((object *));
static int long_print PROTO((object *, FILE *, int));
static object *long_repr PROTO((object *));
static int long_compare PROTO((longobject *, longobject *));
static long long_hash PROTO((longobject *));
static object *long_add PROTO((longobject *, longobject *));
static object *long_sub PROTO((longobject *, longobject *));
@ -615,6 +616,35 @@ long_compare(a, b)
return sign < 0 ? -1 : sign > 0 ? 1 : 0;
}
static long
long_hash(v)
longobject *v;
{
long x;
int i, sign;
/* This is designed so that Python ints and longs with the
same value hash to the same value, otherwise comparisons
of mapping keys will turn out weird */
i = v->ob_size;
sign = 1;
x = 0;
if (i < 0) {
sign = -1;
i = -(i);
}
while (--i >= 0) {
/* Force a 32-bit circular shift */
x = ((x << SHIFT) & ~MASK) | ((x >> (32-SHIFT)) & MASK);
x += v->ob_digit[i];
}
x = x * sign;
if (x == -1)
x = -2;
return x;
}
/* Add the absolute values of two long integers. */
static longobject *x_add PROTO((longobject *, longobject *));
@ -1346,4 +1376,6 @@ typeobject Longtype = {
&long_as_number,/*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
(long (*) FPROTO((object *)))
long_hash, /*tp_hash*/
};

View File

@ -24,8 +24,13 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* Mapping object implementation; using a hash table */
/* This file should really be called "dictobject.c", since "mapping"
is the generic name for objects with an unorderred arbitrary key
set (just like lists are sequences), but since it improves (and was
originally derived from) a file by that name I had to change its
name. For the user these objects are still called "dictionaries". */
#include "allobjects.h"
#include "mappingobject.h"
#include "modsupport.h"
@ -593,7 +598,7 @@ mapping_getattr(mp, name)
typeobject Mappingtype = {
OB_HEAD_INIT(&Typetype)
0,
"mapping",
"dictionary",
sizeof(mappingobject),
0,
mapping_dealloc, /*tp_dealloc*/

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@ -108,11 +108,41 @@ meth_repr(m)
sprintf(buf, "<built-in function '%.80s'>", m->m_name);
else
sprintf(buf,
"<built-in method '%.80s' of some %.80s object>",
m->m_name, m->m_self->ob_type->tp_name);
"<built-in method '%.80s' of %.80s object at %lx>",
m->m_name, m->m_self->ob_type->tp_name,
(long)m->m_self);
return newstringobject(buf);
}
static int
meth_compare(a, b)
methodobject *a, *b;
{
if (a->m_self != b->m_self)
return cmpobject(a->m_self, b->m_self);
if (a->m_meth == b->m_meth)
return 0;
if (strcmp(a->m_name, b->m_name) < 0)
return -1;
else
return 1;
}
static long
meth_hash(a)
methodobject *a;
{
long x, y;
if (a->m_self == NULL)
x = 0;
else {
x = hashobject(a->m_self);
if (x == -1)
return -1;
}
return x ^ (long) a->m_meth;
}
typeobject Methodtype = {
OB_HEAD_INIT(&Typetype)
0,
@ -123,11 +153,12 @@ typeobject Methodtype = {
0, /*tp_print*/
0, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_compare*/
meth_compare, /*tp_compare*/
meth_repr, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
meth_hash, /*tp_hash*/
};
object *listmethods PROTO((struct methodlist *)); /* Forward */

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@ -165,6 +165,20 @@ cmpobject(v, w)
return (*tp->tp_compare)(v, w);
}
long
hashobject(v)
object *v;
{
typeobject *tp = v->ob_type;
if (tp->tp_hash != NULL)
return (*tp->tp_hash)(v);
if (tp->tp_compare == NULL)
return (long) v; /* Use address as hash value */
/* If there's a cmp but no hash defined, the object can't be hashed */
err_setstr(TypeError, "unhashable type");
return -1;
}
object *
getattr(v, name)
object *v;
@ -229,6 +243,7 @@ static typeobject Notype = {
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
0, /*tp_hash */
};
object NoObject = {

View File

@ -293,6 +293,21 @@ string_compare(a, b)
return (len_a < len_b) ? -1 : (len_a > len_b) ? 1 : 0;
}
static long
string_hash(a)
stringobject *a;
{
register int len = a->ob_size;
register unsigned char *p = (unsigned char *) a->ob_sval;
register long x = *p << 7;
while (--len >= 0)
x = (x + x + x) ^ *p++;
x ^= a->ob_size;
if (x == -1)
x = -2;
return x;
}
static sequence_methods string_as_sequence = {
string_length, /*sq_length*/
string_concat, /*sq_concat*/
@ -318,6 +333,7 @@ typeobject Stringtype = {
0, /*tp_as_number*/
&string_as_sequence, /*tp_as_sequence*/
0, /*tp_as_mapping*/
string_hash, /*tp_hash*/
};
void

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@ -179,6 +179,27 @@ tuplecompare(v, w)
return v->ob_size - w->ob_size;
}
static long
tuplehash(v)
tupleobject *v;
{
register long x, y;
register int len = v->ob_size;
register object **p;
x = 0x345678L;
p = v->ob_item;
while (--len >= 0) {
y = hashobject(*p++);
if (y == -1)
return -1;
x = (x + x + x) ^ y;
}
x ^= v->ob_size;
if (x == -1)
x = -2;
return x;
}
static int
tuplelength(a)
tupleobject *a;
@ -329,4 +350,5 @@ typeobject Tupletype = {
0, /*tp_as_number*/
&tuple_as_sequence, /*tp_as_sequence*/
0, /*tp_as_mapping*/
tuplehash, /*tp_hash*/
};

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -281,10 +281,28 @@ builtin_getattr(self, args)
object *args;
{
object *v;
char *name;
if (!getargs(args, "(Os)", &v, &name))
object *name;
if (!getargs(args, "(OS)", &v, &name))
return NULL;
return getattr(v, name);
return getattro(v, name);
}
static object *
builtin_hasattr(self, args)
object *self;
object *args;
{
object *v;
object *name;
if (!getargs(args, "(OS)", &v, &name))
return NULL;
v = getattro(v, name);
if (v == NULL) {
err_clear();
return newintobject(0L);
}
DECREF(v);
return newintobject(1L);
}
static object *
@ -293,16 +311,31 @@ builtin_setattr(self, args)
object *args;
{
object *v;
char *name;
object *name;
object *value;
if (!getargs(args, "(OsO)", &v, &name, &value))
if (!getargs(args, "(OSO)", &v, &name, &value))
return NULL;
if (setattr(v, name, value) != 0)
if (setattro(v, name, value) != 0)
return NULL;
INCREF(None);
return None;
}
static object *
builtin_hash(self, args)
object *self;
object *args;
{
object *v;
long x;
if (!getargs(args, "O", &v))
return NULL;
x = hashobject(v);
if (x == -1)
return NULL;
return newintobject(x);
}
static object *
builtin_hex(self, v)
object *self;
@ -687,6 +720,8 @@ static struct methodlist builtin_methods[] = {
{"execfile", builtin_execfile},
{"float", builtin_float},
{"getattr", builtin_getattr},
{"hasattr", builtin_hasattr},
{"hash", builtin_hash},
{"hex", builtin_hex},
{"input", builtin_input},
{"int", builtin_int},

View File

@ -173,6 +173,7 @@ eval_code(co, globals, locals, arg)
register object *u;
register object *t;
register frameobject *f; /* Current frame */
register listobject *fastlocals = NULL;
object *trace = NULL; /* Trace function or NULL */
object *retval; /* Return value iff why == WHY_RETURN */
char *name; /* Name used by some instructions */
@ -911,19 +912,18 @@ eval_code(co, globals, locals, arg)
break;
case STORE_ATTR:
name = GETNAME(oparg);
w = GETNAMEV(oparg);
v = POP();
u = POP();
err = setattr(v, name, u); /* v.name = u */
err = setattro(v, w, u); /* v.w = u */
DECREF(v);
DECREF(u);
break;
case DELETE_ATTR:
name = GETNAME(oparg);
w = GETNAMEV(oparg);
v = POP();
err = setattr(v, name, (object *)NULL);
/* del v.name */
err = setattro(v, w, (object *)NULL); /* del v.w */
DECREF(v);
break;
@ -992,6 +992,22 @@ eval_code(co, globals, locals, arg)
INCREF(x);
PUSH(x);
break;
case RESERVE_FAST:
if (oparg > 0) {
XDECREF(fastlocals);
x = newlistobject(oparg);
fastlocals = (listobject *) x;
}
break;
case LOAD_FAST:
/* NYI */
break;
case STORE_FAST:
/* NYI */
break;
case BUILD_TUPLE:
x = newtupleobject(oparg);
@ -1025,9 +1041,9 @@ eval_code(co, globals, locals, arg)
break;
case LOAD_ATTR:
name = GETNAME(oparg);
w = GETNAMEV(oparg);
v = POP();
x = getattr(v, name);
x = getattro(v, w);
DECREF(v);
PUSH(x);
break;
@ -1283,6 +1299,8 @@ eval_code(co, globals, locals, arg)
current_frame = f->f_back;
DECREF(f);
XDECREF(fastlocals);
return retval;
}

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@ -50,6 +50,7 @@ static struct memberlist code_memberlist[] = {
{"co_consts", T_OBJECT, OFF(co_consts), READONLY},
{"co_names", T_OBJECT, OFF(co_names), READONLY},
{"co_filename", T_OBJECT, OFF(co_filename), READONLY},
{"co_name", T_OBJECT, OFF(co_name), READONLY},
{NULL} /* Sentinel */
};
@ -69,6 +70,7 @@ code_dealloc(co)
XDECREF(co->co_consts);
XDECREF(co->co_names);
XDECREF(co->co_filename);
XDECREF(co->co_name);
DEL(co);
}
@ -80,12 +82,15 @@ code_repr(co)
int lineno = -1;
char *p = GETSTRINGVALUE(co->co_code);
char *filename = "???";
char *name = "???";
if (*p == SET_LINENO)
lineno = (p[1] & 0xff) | ((p[2] & 0xff) << 8);
if (co->co_filename && is_stringobject(co->co_filename))
filename = getstringvalue(co->co_filename);
sprintf(buf, "<code object at %lx, file \"%.400s\", line %d>",
(long)co, filename, lineno);
if (co->co_name && is_stringobject(co->co_name))
name = getstringvalue(co->co_name);
sprintf(buf, "<code object %.100s at %lx, file \"%.300s\", line %d>",
name, (long)co, filename, lineno);
return newstringobject(buf);
}
@ -107,18 +112,20 @@ typeobject Codetype = {
};
codeobject *
newcodeobject(code, consts, names, filename)
newcodeobject(code, consts, names, filename, name)
object *code;
object *consts;
object *names;
object *filename;
object *name;
{
codeobject *co;
int i;
/* Check argument types */
if (code == NULL || !is_stringobject(code) ||
consts == NULL || !is_listobject(consts) ||
names == NULL || !is_listobject(names)) {
names == NULL || !is_listobject(names) ||
name == NULL || !is_stringobject(name)) {
err_badcall();
return NULL;
}
@ -140,6 +147,8 @@ newcodeobject(code, consts, names, filename)
co->co_names = names;
INCREF(filename);
co->co_filename = filename;
INCREF(name);
co->co_name = name;
}
return co;
}
@ -162,6 +171,7 @@ struct compiling {
int c_block[MAXBLOCKS]; /* stack of block types */
int c_nblocks; /* current block stack level */
char *c_filename; /* filename of current node */
char *c_name; /* name of object (e.g. function) */
};
@ -232,6 +242,7 @@ com_init(c, filename)
c->c_begin = 0;
c->c_nblocks = 0;
c->c_filename = filename;
c->c_name = "?";
return 1;
fail_0:
@ -2020,6 +2031,8 @@ compile_funcdef(c, n)
{
node *ch;
REQ(n, funcdef); /* funcdef: 'def' NAME parameters ':' suite */
c->c_name = STR(CHILD(n, 1));
com_addoparg(c, RESERVE_FAST, 0); /* Patched up later */
ch = CHILD(n, 2); /* parameters: '(' [varargslist] ')' */
ch = CHILD(ch, 1); /* ')' | varargslist */
if (TYPE(ch) == RPAR)
@ -2089,6 +2102,8 @@ compile_node(c, n)
/* Optimization for local and global variables.
XXX Need to update this text for LOAD_FAST stuff...
Attempt to replace all LOAD_NAME instructions that refer to a local
variable with LOAD_LOCAL instructions, and all that refer to a global
variable with LOAD_GLOBAL instructions.
@ -2187,17 +2202,21 @@ compile(n, filename)
{
struct compiling sc;
codeobject *co;
object *v;
if (!com_init(&sc, filename))
return NULL;
compile_node(&sc, n);
com_done(&sc);
if (sc.c_errors == 0 && (v = newstringobject(filename)) != NULL) {
co = newcodeobject(sc.c_code, sc.c_consts, sc.c_names, v);
DECREF(v);
co = NULL;
if (sc.c_errors == 0) {
object *v, *w;
v = newstringobject(sc.c_filename);
w = newstringobject(sc.c_name);
if (v != NULL && w != NULL)
co = newcodeobject(sc.c_code, sc.c_consts,
sc.c_names, v, w);
XDECREF(v);
XDECREF(w);
}
else
co = NULL;
com_free(&sc);
if (co != NULL && filename[0] != '<')
optimizer(co);

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -52,9 +52,9 @@ extern int verbose; /* Defined in pythonmain.c */
extern char *argv0;
#endif
/* Magic word to reject pre-0.9.4 .pyc files */
/* Magic word to reject pre-0.9.9 .pyc files */
#define MAGIC 0x949494L
#define MAGIC 0x99BE2AL
static object *modules;

View File

@ -195,6 +195,7 @@ w_object(v, p)
w_object(co->co_consts, p);
w_object(co->co_names, p);
w_object(co->co_filename, p);
w_object(co->co_name, p);
}
else {
w_byte(TYPE_UNKNOWN, p);
@ -384,9 +385,10 @@ r_object(p)
object *consts = r_object(p);
object *names = r_object(p);
object *filename = r_object(p);
object *name = r_object(p);
if (!err_occurred()) {
v = (object *) newcodeobject(code,
consts, names, filename);
consts, names, filename, name);
}
else
v = NULL;

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved

View File

@ -1,6 +1,6 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved