Skip to content

Commit

Permalink
Several changes in one:
Browse files Browse the repository at this point in the history
(1) dictionaries/mappings now have attributes values() and items() as
well as keys(); at the C level, use the new function mappinggetnext()
to iterate over a dictionary.

(2) "class C(): ..." is now illegal; you must write "class C: ...".

(3) Class objects now know their own name (finally!); and minor
improvements to the way how classes, functions and methods are
represented as strings.

(4) Added an "access" statement and semantics.  (This is still
experimental -- as long as you don't use the keyword 'access' nothing
should be changed.)
  • Loading branch information
gvanrossum committed May 19, 1993
1 parent 687dd13 commit 2583165
Show file tree
Hide file tree
Showing 21 changed files with 1,200 additions and 800 deletions.
20 changes: 13 additions & 7 deletions Grammar/Grammar
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

# Change log:

# 19-May-93:
# Add access statement

# 18-May-93:
# Abolish old class header syntax

# 06-Apr-92:
# Use only '*' for varargs list

Expand Down Expand Up @@ -81,7 +87,7 @@ fplist: fpdef (',' fpdef)* [',']

stmt: simple_stmt | compound_stmt
simple_stmt: small_stmt (';' small_stmt)* [';'] NEWLINE
small_stmt: expr_stmt | print_stmt | del_stmt | pass_stmt | flow_stmt | import_stmt | global_stmt
small_stmt: expr_stmt | print_stmt | del_stmt | pass_stmt | flow_stmt | import_stmt | global_stmt | access_stmt
expr_stmt: (exprlist '=')* exprlist
# For assignments, additional restrictions enforced by the interpreter
print_stmt: 'print' (test ',')* [test]
Expand All @@ -94,6 +100,11 @@ return_stmt: 'return' [testlist]
raise_stmt: 'raise' test [',' test]
import_stmt: 'import' NAME (',' NAME)* | 'from' NAME 'import' ('*' | NAME (',' NAME)*)
global_stmt: 'global' NAME (',' NAME)*
access_stmt: 'access' NAME (',' NAME)* ':' accesstype (',' accesstype)*
accesstype: NAME+
# accesstype should be ('public' | 'protected' | 'private') ['read'] ['write']
# but can't be because that would create undesirable reserved words!

compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | funcdef | classdef
if_stmt: 'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite]
while_stmt: 'while' test ':' suite ['else' ':' suite]
Expand Down Expand Up @@ -122,9 +133,4 @@ exprlist: expr (',' expr)* [',']
testlist: test (',' test)* [',']
dictmaker: test ':' test (',' test ':' test)* [',']

# New class syntax should be:
# classdef: class NAME ['(' testlist ')'] ':' suite
# but merged with old syntax for compatibility it becomes:
classdef: 'class' NAME ['(' testlist ')' |'(' ')' ['=' baselist]] ':' suite
baselist: atom arguments (',' atom arguments)*
arguments: '(' ')'
classdef: class NAME ['(' testlist ')'] ':' suite
1 change: 1 addition & 0 deletions Include/allobjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "object.h"
#include "objimpl.h"

#include "accessobject.h"
#include "intobject.h"
#include "longobject.h"
#include "floatobject.h"
Expand Down
2 changes: 1 addition & 1 deletion Include/classobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ extern typeobject Classtype, Instancetype, Instancemethodtype;
#define is_instancemethodobject(op) ((op)->ob_type == &Instancemethodtype)

extern object *newclassobject PROTO((object *, object *, object *));
extern object *newinstanceobject PROTO((object *));
extern object *newinstanceobject PROTO((object *, object *));
extern object *newinstancemethodobject PROTO((object *, object *));

extern object *instancemethodgetfunc PROTO((object *));
Expand Down
3 changes: 0 additions & 3 deletions Include/dictobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,9 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
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 char *getdictkey PROTO((object *dp, int i));

#define getdictsize getmappingsize
#define getdictkeys getmappingkeys

#define getdict2key getmappingkey
#define dict2lookup mappinglookup
#define dict2insert mappinginsert
#define dict2remove mappingremove
4 changes: 4 additions & 0 deletions Include/errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ void err_clear PROTO((void));

/* Predefined exceptions */

extern object *AccessError;
extern object *AttributeError;
extern object *ConflictError;
extern object *EOFError;
extern object *IOError;
extern object *ImportError;
Expand All @@ -59,3 +61,5 @@ extern object *err_errno PROTO((object *));
extern void err_input PROTO((int));

extern void err_badcall PROTO((void));

extern object *err_getexc PROTO((void));
7 changes: 7 additions & 0 deletions Include/funcobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

/* Function object interface */

typedef struct {
OB_HEAD
object *func_code;
object *func_globals;
object *func_name;
} funcobject;

extern typeobject Functype;

#define is_funcobject(op) ((op)->ob_type == &Functype)
Expand Down
56 changes: 28 additions & 28 deletions Include/graminit.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,31 @@
#define raise_stmt 276
#define import_stmt 277
#define global_stmt 278
#define compound_stmt 279
#define if_stmt 280
#define while_stmt 281
#define for_stmt 282
#define try_stmt 283
#define except_clause 284
#define suite 285
#define test 286
#define and_test 287
#define not_test 288
#define comparison 289
#define comp_op 290
#define expr 291
#define xor_expr 292
#define and_expr 293
#define shift_expr 294
#define arith_expr 295
#define term 296
#define factor 297
#define atom 298
#define trailer 299
#define subscript 300
#define exprlist 301
#define testlist 302
#define dictmaker 303
#define classdef 304
#define baselist 305
#define arguments 306
#define access_stmt 279
#define accesstype 280
#define compound_stmt 281
#define if_stmt 282
#define while_stmt 283
#define for_stmt 284
#define try_stmt 285
#define except_clause 286
#define suite 287
#define test 288
#define and_test 289
#define not_test 290
#define comparison 291
#define comp_op 292
#define expr 293
#define xor_expr 294
#define and_expr 295
#define shift_expr 296
#define arith_expr 297
#define term 298
#define factor 299
#define atom 300
#define trailer 301
#define subscript 302
#define exprlist 303
#define testlist 304
#define dictmaker 305
#define classdef 306
23 changes: 10 additions & 13 deletions Include/mappingobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,19 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
******************************************************************/

/*
Mapping object type -- mapping from object to object.
These functions set errno for errors. Functions mappingremove() and
mappinginsert() return nonzero for errors, getmappingsize() returns -1,
the others NULL. A successful call to mappinginsert() calls INCREF()
for the inserted item.
*/
/* Mapping object type -- mapping from hashable object to object */

extern typeobject Mappingtype;

#define is_mappingobject(op) ((op)->ob_type == &Mappingtype)

extern object *newmappingobject PROTO((void));
extern object *mappinglookup PROTO((object *dp, object *key));
extern int mappinginsert PROTO((object *dp, object *key, object *item));
extern int mappingremove PROTO((object *dp, object *key));
extern int getmappingsize PROTO((object *dp));
extern object *getmappingkey PROTO((object *dp, int i));
extern object *getmappingkeys PROTO((object *dp));
extern object *mappinglookup PROTO((object *mp, object *key));
extern int mappinginsert PROTO((object *mp, object *key, object *item));
extern int mappingremove PROTO((object *mp, object *key));
extern void mappingclear PROTO((object *mp));
extern int mappinggetnext
PROTO((object *mp, int *pos, object **key, object **value));
extern object *getmappingkeys PROTO((object *mp));
extern object *getmappingvalues PROTO((object *mp));
extern object *getmappingitems PROTO((object *mp));
1 change: 1 addition & 0 deletions Include/opcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#define COMPARE_OP 106 /* Comparison operator */
#define IMPORT_NAME 107 /* Index in name list */
#define IMPORT_FROM 108 /* Index in name list */
#define ACCESS_MODE 109 /* Name (mode is int on top of stack) */

#define JUMP_FORWARD 110 /* Number of bytes to skip */
#define JUMP_IF_FALSE 111 /* "" */
Expand Down
4 changes: 4 additions & 0 deletions Include/pyerrors.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ void err_clear PROTO((void));

/* Predefined exceptions */

extern object *AccessError;
extern object *AttributeError;
extern object *ConflictError;
extern object *EOFError;
extern object *IOError;
extern object *ImportError;
Expand All @@ -59,3 +61,5 @@ extern object *err_errno PROTO((object *));
extern void err_input PROTO((int));

extern void err_badcall PROTO((void));

extern object *err_getexc PROTO((void));
Loading

0 comments on commit 2583165

Please sign in to comment.