8000 "Compiling" version · python/cpython@3f5da24 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3f5da24

Browse files
committed
"Compiling" version
1 parent 226d79e commit 3f5da24

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+3302
-2000
lines changed

Include/allobjects.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* "allobjects.c" -- Source for precompiled header "allobjects.h" */
2+
3+
#include <stdio.h>
4+
#include "string.h"
5+
6+
#include "PROTO.h"
7+
8+
#include "object.h"
9+
#include "objimpl.h"
10+
11+
#include "intobject.h"
12+
#include "floatobject.h"
13+
#include "stringobject.h"
14+
#include "tupleobject.h"
15+
#include "listobject.h"
16+
#include "dictobject.h"
17+
#include "methodobject.h"
18+
#include "moduleobject.h"
19+
#include "funcobject.h"
20+
#include "classobject.h"
21+
#include "fileobject.h"
22+
23+
#include "errors.h"
24+
#include "malloc.h"
25+
26+
extern char *strdup PROTO((const char *));

Include/bltinmodule.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/* Built-in module interface */
2+
3+
extern object *getbuiltin PROTO((char *));

Include/ceval.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* Interface to execute compiled code */
2+
/* This header depends on "compile.h" */
3+
4+
object *eval_code PROTO((codeobject *, object *, object *, object *));
5+
6+
object *getglobals PROTO((void));
7+
object *getlocals PROTO((void));
8+
9+
void printtraceback PROTO((FILE *));

Include/classobject.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ extern typeobject Classtype, Classmembertype, Classmethodtype;
1212
#define is_classmemberobject(op) ((op)->ob_type == &Classmembertype)
1313
#define is_classmethodobject(op) ((op)->ob_type == &Classmethodtype)
1414

15-
extern object *newclassobject PROTO((node *, object *, object *));
15+
extern object *newclassobject PROTO((object *, object *));
1616
extern object *newclassmemberobject PROTO((object *));
1717
extern object *newclassmethodobject PROTO((object *, object *));
1818

Include/compile.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* Definitions for compiled intermediate code */
2+
3+
4+
/* An intermediate code fragment contains:
5+
- a string that encodes the instructions,
6+
- a list of the constants,
7+
- and a list of the names used. */
8+
9+
typedef struct {
10+
OB_HEAD
11+
stringobject *co_code; /* instruction opcodes */
12+
object *co_consts; /* list of immutable constant objects */
13+
object *co_names; /* list of stringobjects */
14+
object *co_filename; /* string */
15+
} codeobject;
16+
17+
extern typeobject Codetype;
18+
19+
#define is_codeobject(op) ((op)->ob_type == &Codetype)
20+
21+
22+
/* Public interface */
23+
codeobject *compile PROTO((struct _node *, char *));

Include/errors.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ int err_occurred PROTO((void));
77
void err_get PROTO((object **, object **));
88
void err_clear PROTO((void));
99

10-
/* Predefined exceptions (in run.c) */
10+
/* Predefined exceptions */
1111

1212
extern object *RuntimeError;
1313
extern object *EOFError;
@@ -29,5 +29,6 @@ extern object *KeyboardInterrupt;
2929
extern int err_badarg PROTO((void));
3030
extern object *err_nomem PROTO((void));
3131
extern object *err_errno PROTO((object *));
32+
extern void err_input PROTO((int));
3233

3334
extern void err_badcall PROTO((void));

Include/frameobject.h

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/* Frame object interface */
2+
3+
typedef struct {
4+
int b_type; /* what kind of block this is */
5+
int b_handler; /* where to jump to find handler */
6+
int b_level; /* value stack level to pop to */
7+
} block;
8+
9+
typedef struct _frame {
10+
OB_HEAD
11+
struct _frame *f_back; /* previous frame, or NULL */
12+
codeobject *f_code; /* code segment */
13+
object *f_globals; /* global symbol table (dictobject) */
14+
object *f_locals; /* local symbol table (dictobject) */
15+
object **f_valuestack; /* malloc'ed array */
16+
block *f_blockstack; /* malloc'ed array */
17+
int f_nvalues; /* size of f_valuestack */
18+
int f_nblocks; /* size of f_blockstack */
19+
int f_iblock; /* index in f_blockstack */
20+
} frameobject;
21+
22+
23+
/* Standard object interface */
24+
25+
extern typeobject Frametype;
26+
27+
#define is_frameobject(op) ((op)->ob_type == &Frametype)
28+
29+
frameobject * newframeobject PROTO(
30+
(frameobject *, codeobject *, object *, object *, int, int));
31+
32+
33+
/* The rest of the interface is specific for frame objects */
34+
35+
/* List access macros */
36+
37+
#ifdef NDEBUG
38+
#define GETITEM(v, i) GETLISTITEM((listobject *)(v), (i))
39+
#define GETITEMNAME(v, i) GETSTRINGVALUE((stringobject *)GETITEM((v), (i)))
40+
#else
41+
#define GETITEM(v, i) getlistitem((v), (i))
42+
#define GETITEMNAME(v, i) getstringvalue(getlistitem((v), (i)))
43+
#endif
44+
45+
#define GETUSTRINGVALUE(s) ((unsigned char *)GETSTRINGVALUE(s))
46+
47+
/* Code access macros */
48+
49+
#define Getconst(f, i) (GETITEM((f)->f_code->co_consts, (i)))
50+
#define Getname(f, i) (GETITEMNAME((f)->f_code->co_names, (i)))
51+
52+
53+
/* Block management functions */
54+
55+
void setup_block PROTO((frameobject *, int, int, int));
56+
block *pop_block PROTO((frameobject *));

Include/grammar.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,6 @@ void translatelabels PROTO((grammar *g));
7676
void addfirstsets PROTO((grammar *g));
7777

7878
void addaccellerators PROTO((grammar *g));
79+
80+
void printgrammar PROTO((grammar *g, FILE *fp));
81+
void printnonterminals PROTO((grammar *g, FILE *fp));

Include/import.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/* Module definition and import interface */
22

3-
object *new_module PROTO((char *name));
4-
object *import_module PROTO((struct _context *ctx, char *name));
5-
object *reload_module PROTO((struct _context *ctx, object *m));
3+
object *get_modules PROTO((void));
4+
object *add_module PROTO((char *name));
5+
object *import_module PROTO((char *name));
6+
object *reload_module PROTO((object *m));
7+
void doneimport PROTO((void));

Include/listobject.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ inserted in the list. Similarly, getlistitem does not increment the
1414
returned item's reference count.
1515
*/
1616

17+
typedef struct {
18+
OB_VARHEAD
19+
object **ob_item;
20+
} listobject;
21+
1722
extern typeobject Listtype;
1823

1924
#define is_listobject(op) ((op)->ob_type == &Listtype)
@@ -25,3 +30,6 @@ extern int setlistitem PROTO((object *, int, object *));
2530
extern int inslistitem PROTO((object *, int, object *));
2631
extern int addlistitem PROTO((object *, object *));
2732
extern int sortlist PROTO((object *));
33+
34+
/* Macro, trading safety for speed */
35+
#define GETLISTITEM(op, i) ((op)->ob_item[i])

Include/methodobject.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,10 @@ typedef object *(*method) FPROTO((object *, object *));
99
extern object *newmethodobject PROTO((char *, method, object *));
1010
extern method getmethod PROTO((object *));
1111
extern object *getself PROTO((object *));
12+
13+
struct methodlist {
14+
char *ml_name;
15+
method ml_meth;
16+
};
17+
18+
extern object *findmethod PROTO((struct methodlist *, object *, char *));

Include/modsupport.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
11
/* Module support interface */
22

3-
struct methodlist {
4-
char *ml_name;
5-
method ml_meth;
6-
};
7-
8-
extern object *findmethod PROTO((struct methodlist *, object *, char *));
93
extern object *initmodule PROTO((char *, struct methodlist *));

Include/moduleobject.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@ extern typeobject Moduletype;
66

77
extern object *newmoduleobject PROTO((char *));
88
extern object *getmoduledict PROTO((object *));
9-
extern int setmoduledict PROTO((object *, object *));
109
extern char *getmodulename PROTO((object *));

Include/node.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
typedef struct _node {
44
int n_type;
55
char *n_str;
6+
int n_lineno;
67
int n_nchildren;
78
struct _node *n_child;
89
} node;
910

10-
extern node *newnode PROTO((int type));
11-
extern node *addchild PROTO((node *n, int type, char *str));
12-
extern void freenode PROTO((node *n));
11+
extern node *newtree PROTO((int type));
12+
extern node *addchild PROTO((node *n, int type, char *str, int lineno));
13+
extern void freetree PROTO((node *n));
1314

1415
/* Node access functions */
1516
#define NCH(n) ((n)->n_nchildren)
@@ -28,3 +29,6 @@ extern void freenode PROTO((node *n));
2829
abort(); \
2930
} }
3031
#endif
32+
33+
extern void listtree PROTO((node *));
34+
extern void listnode PROTO((FILE *, node *));

Include/object.h

Lines changed: 23 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#define NDEBUG
12
/* Object and type object interface */
23

34
/*
@@ -47,11 +48,15 @@ whose size is determined when the object is allocated.
4748
123456789-123456789-123456789-123456789-123456789-123456789-123456789-12
4849
*/
4950

50-
#ifdef THINK_C
51-
/* Debugging options for THINK_C (which has no -D compiler option): */
52-
/*#define TRACE_REFS*/
53-
/*#define REF_DEBUG*/
54-
#endif
51+
#ifndef NDEBUG
52+
53+
/* Turn on heavy reference debugging */
54+
#define TRACE_REFS
55+
56+
/* Turn on reference counting */
57+
#define REF_DEBUG
58+
59+
#endif /* NDEBUG */
5560

5661
#ifdef TRACE_REFS
5762
#define OB_HEAD \
@@ -147,9 +152,12 @@ extern typeobject Typetype; /* The type of type objects */
147152

148153
#define is_typeobject(op) ((op)->ob_type == &Typetype)
149154

155+
/* Generic operations on objects */
150156
extern void printobject PROTO((object *, FILE *, int));
151157
extern object * reprobject PROTO((object *));
152158
extern int cmpobject PROTO((object *, object *));
159+
extern object *getattr PROTO((object *, char *));
160+
extern int setattr PROTO((object *, char *, object *));
153161

154162
/* Flag bits for printing: */
155163
#define PRINT_RAW 1 /* No string quotes etc. */
@@ -215,6 +223,10 @@ extern long ref_total;
215223
DELREF(op)
216224
#endif
217225

226+
/* Macros to use in case the object pointer may be NULL: */
227+
228+
#define XINCREF(op) if ((op) == NULL) ; else INCREF(op)
229+
#define XDECREF(op) if ((op) == NULL) ; else DECREF(op)
218230

219231
/* Definition of NULL, so you don't have to include <stdio.h> */
220232

@@ -252,22 +264,12 @@ Failure Modes
252264
-------------
253265
254266
Functions may fail for a variety of reasons, including running out of
255-
memory. This is communicated to the caller in two ways: 'errno' is set
256-
to indicate the error, and the function result differs: functions that
257-
normally return a pointer return nil for failure, functions returning
258-
an integer return -1 (which can be a legal return value too!), and
259-
other functions return 0 for success and the error number for failure.
260-
Callers should always check for errors before using the result. The
261-
following error codes are used:
262-
263-
EBADF bad object type (first argument only)
264-
EINVAL bad argument type (second and further arguments)
265-
ENOMEM no memory (malloc failed)
266-
ENOENT key not found in dictionary
267-
EDOM index out of range or division by zero
268-
ERANGE result not representable
269-
270-
XXX any others?
267+
memory. This is communicated to the caller in two ways: an error string
268+
is set (see errors.h), and the function result differs: functions that
269+
normally return a pointer return NULL for failure, functions returning
270+
an integer return -1 (which could be a legal return value too!), and
271+
other functions return 0 for success and -1 for failure.
272+
Callers should always check for errors before using the result.
271273
272274
Reference Counts
273275
----------------
@@ -296,16 +298,3 @@ times.
296298
297299
123456789-123456789-123456789-123456789-123456789-123456789-123456789-12
298300
*/
299-
300-
/* Error number interface */
301-
#include <errno.h>
302-
303-
#ifndef errno
304-
extern int errno;
305-
#endif
306-
307-
#ifdef THINK_C
308-
/* Lightspeed C doesn't define these in <errno.h> */
309-
#define EDOM 33
310-
#define ERANGE 34
311-
#endif

Include/objimpl.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,3 @@ extern varobject *newvarobject PROTO((typeobject *, unsigned int));
2424
#define NEWVAROBJ(type, typeobj, n) ((type *) newvarobject(typeobj, n))
2525

2626
extern int StopPrint; /* Set when printing is interrupted */
27-
28-
/* Malloc interface */
29-
#include "malloc.h"
30-
31-
extern char *strdup PROTO((const char *));

Include/opcode.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
/* Instruction opcodes for compiled code */
22

3-
#define DUP_TOP 0
3+
#define STOP_CODE 0
44
#define POP_TOP 1
55
#define ROT_TWO 2
66
#define ROT_THREE 3
7+
#define DUP_TOP 4
78

89
#define UNARY_POSITIVE 10
910
#define UNARY_NEGATIVE 11
@@ -76,5 +77,9 @@
7677
#define SETUP_EXCEPT 121 /* "" */
7778
#define SETUP_FINALLY 122 /* "" */
7879

80+
#define SET_LINENO 127 /* Current line number */
81+
7982
/* Comparison operator codes (argument to COMPARE_OP) */
8083
enum cmp_op {LT, LE, EQ, NE, GT, GE, IN, NOT_IN, IS, IS_NOT, EXC_MATCH, BAD};
84+
85+
#define HAS_ARG(op) ((op) >= HAVE_ARGUMENT)

Include/parsetok.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
/* Parser-tokenizer link interface */
22

3-
#if 0
4-
extern int parsetok PROTO((struct tok_state *, grammar *, int start,
5-
node **n_ret));
6-
#endif
73
extern int parsestring PROTO((char *, grammar *, int start, node **n_ret));
8-
extern int parsefile PROTO((FILE *, grammar *, int start,
4+
extern int parsefile PROTO((FILE *, char *, grammar *, int start,
95
char *ps1, char *ps2, node **n_ret));

Include/pgenheaders.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* Include files and extern declarations used by most of the parser.
2+
This is a precompiled header for THINK C. */
3+
4+
#include <stdio.h>
5+
6+
#ifdef THINK_C
7+
#define label label_
8+
#include <proto.h>
9+
#undef label
10+
#endif
11+
12+
#include "PROTO.h"
13+
#include "malloc.h"
14+
15+
extern void fatal PROTO((char *));

0 commit comments

Comments
 (0)
0