mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
"Compiling" version
This commit is contained in:
parent
226d79eb4a
commit
3f5da24ea3
72 changed files with 3363 additions and 2061 deletions
26
Include/allobjects.h
Normal file
26
Include/allobjects.h
Normal file
|
@ -0,0 +1,26 @@
|
|||
/* "allobjects.c" -- Source for precompiled header "allobjects.h" */
|
||||
|
||||
#include <stdio.h>
|
||||
#include "string.h"
|
||||
|
||||
#include "PROTO.h"
|
||||
|
||||
#include "object.h"
|
||||
#include "objimpl.h"
|
||||
|
||||
#include "intobject.h"
|
||||
#include "floatobject.h"
|
||||
#include "stringobject.h"
|
||||
#include "tupleobject.h"
|
||||
#include "listobject.h"
|
||||
#include "dictobject.h"
|
||||
#include "methodobject.h"
|
||||
#include "moduleobject.h"
|
||||
#include "funcobject.h"
|
||||
#include "classobject.h"
|
||||
#include "fileobject.h"
|
||||
|
||||
#include "errors.h"
|
||||
#include "malloc.h"
|
||||
|
||||
extern char *strdup PROTO((const char *));
|
3
Include/bltinmodule.h
Normal file
3
Include/bltinmodule.h
Normal file
|
@ -0,0 +1,3 @@
|
|||
/* Built-in module interface */
|
||||
|
||||
extern object *getbuiltin PROTO((char *));
|
9
Include/ceval.h
Normal file
9
Include/ceval.h
Normal file
|
@ -0,0 +1,9 @@
|
|||
/* Interface to execute compiled code */
|
||||
/* This header depends on "compile.h" */
|
||||
|
||||
object *eval_code PROTO((codeobject *, object *, object *, object *));
|
||||
|
||||
object *getglobals PROTO((void));
|
||||
object *getlocals PROTO((void));
|
||||
|
||||
void printtraceback PROTO((FILE *));
|
|
@ -12,7 +12,7 @@ extern typeobject Classtype, Classmembertype, Classmethodtype;
|
|||
#define is_classmemberobject(op) ((op)->ob_type == &Classmembertype)
|
||||
#define is_classmethodobject(op) ((op)->ob_type == &Classmethodtype)
|
||||
|
||||
extern object *newclassobject PROTO((node *, object *, object *));
|
||||
extern object *newclassobject PROTO((object *, object *));
|
||||
extern object *newclassmemberobject PROTO((object *));
|
||||
extern object *newclassmethodobject PROTO((object *, object *));
|
||||
|
||||
|
|
23
Include/compile.h
Normal file
23
Include/compile.h
Normal file
|
@ -0,0 +1,23 @@
|
|||
/* Definitions for compiled intermediate code */
|
||||
|
||||
|
||||
/* An intermediate code fragment contains:
|
||||
- a string that encodes the instructions,
|
||||
- a list of the constants,
|
||||
- and a list of the names used. */
|
||||
|
||||
typedef struct {
|
||||
OB_HEAD
|
||||
stringobject *co_code; /* instruction opcodes */
|
||||
object *co_consts; /* list of immutable constant objects */
|
||||
object *co_names; /* list of stringobjects */
|
||||
object *co_filename; /* string */
|
||||
} codeobject;
|
||||
|
||||
extern typeobject Codetype;
|
||||
|
||||
#define is_codeobject(op) ((op)->ob_type == &Codetype)
|
||||
|
||||
|
||||
/* Public interface */
|
||||
codeobject *compile PROTO((struct _node *, char *));
|
|
@ -7,7 +7,7 @@ int err_occurred PROTO((void));
|
|||
void err_get PROTO((object **, object **));
|
||||
void err_clear PROTO((void));
|
||||
|
||||
/* Predefined exceptions (in run.c) */
|
||||
/* Predefined exceptions */
|
||||
|
||||
extern object *RuntimeError;
|
||||
extern object *EOFError;
|
||||
|
@ -29,5 +29,6 @@ extern object *KeyboardInterrupt;
|
|||
extern int err_badarg PROTO((void));
|
||||
extern object *err_nomem PROTO((void));
|
||||
extern object *err_errno PROTO((object *));
|
||||
extern void err_input PROTO((int));
|
||||
|
||||
extern void err_badcall PROTO((void));
|
||||
|
|
56
Include/frameobject.h
Normal file
56
Include/frameobject.h
Normal file
|
@ -0,0 +1,56 @@
|
|||
/* Frame object interface */
|
||||
|
||||
typedef struct {
|
||||
int b_type; /* what kind of block this is */
|
||||
int b_handler; /* where to jump to find handler */
|
||||
int b_level; /* value stack level to pop to */
|
||||
} block;
|
||||
|
||||
typedef struct _frame {
|
||||
OB_HEAD
|
||||
struct _frame *f_back; /* previous frame, or NULL */
|
||||
codeobject *f_code; /* code segment */
|
||||
object *f_globals; /* global symbol table (dictobject) */
|
||||
object *f_locals; /* local symbol table (dictobject) */
|
||||
object **f_valuestack; /* malloc'ed array */
|
||||
block *f_blockstack; /* malloc'ed array */
|
||||
int f_nvalues; /* size of f_valuestack */
|
||||
int f_nblocks; /* size of f_blockstack */
|
||||
int f_iblock; /* index in f_blockstack */
|
||||
} frameobject;
|
||||
|
||||
|
||||
/* Standard object interface */
|
||||
|
||||
extern typeobject Frametype;
|
||||
|
||||
#define is_frameobject(op) ((op)->ob_type == &Frametype)
|
||||
|
||||
frameobject * newframeobject PROTO(
|
||||
(frameobject *, codeobject *, object *, object *, int, int));
|
||||
|
||||
|
||||
/* The rest of the interface is specific for frame objects */
|
||||
|
||||
/* List access macros */
|
||||
|
||||
#ifdef NDEBUG
|
||||
#define GETITEM(v, i) GETLISTITEM((listobject *)(v), (i))
|
||||
#define GETITEMNAME(v, i) GETSTRINGVALUE((stringobject *)GETITEM((v), (i)))
|
||||
#else
|
||||
#define GETITEM(v, i) getlistitem((v), (i))
|
||||
#define GETITEMNAME(v, i) getstringvalue(getlistitem((v), (i)))
|
||||
#endif
|
||||
|
||||
#define GETUSTRINGVALUE(s) ((unsigned char *)GETSTRINGVALUE(s))
|
||||
|
||||
/* Code access macros */
|
||||
|
||||
#define Getconst(f, i) (GETITEM((f)->f_code->co_consts, (i)))
|
||||
#define Getname(f, i) (GETITEMNAME((f)->f_code->co_names, (i)))
|
||||
|
||||
|
||||
/* Block management functions */
|
||||
|
||||
void setup_block PROTO((frameobject *, int, int, int));
|
||||
block *pop_block PROTO((frameobject *));
|
|
@ -76,3 +76,6 @@ void translatelabels PROTO((grammar *g));
|
|||
void addfirstsets PROTO((grammar *g));
|
||||
|
||||
void addaccellerators PROTO((grammar *g));
|
||||
|
||||
void printgrammar PROTO((grammar *g, FILE *fp));
|
||||
void printnonterminals PROTO((grammar *g, FILE *fp));
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
/* Module definition and import interface */
|
||||
|
||||
object *new_module PROTO((char *name));
|
||||
object *import_module PROTO((struct _context *ctx, char *name));
|
||||
object *reload_module PROTO((struct _context *ctx, object *m));
|
||||
object *get_modules PROTO((void));
|
||||
object *add_module PROTO((char *name));
|
||||
object *import_module PROTO((char *name));
|
||||
object *reload_module PROTO((object *m));
|
||||
void doneimport PROTO((void));
|
||||
|
|
|
@ -14,6 +14,11 @@ inserted in the list. Similarly, getlistitem does not increment the
|
|||
returned item's reference count.
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
OB_VARHEAD
|
||||
object **ob_item;
|
||||
} listobject;
|
||||
|
||||
extern typeobject Listtype;
|
||||
|
||||
#define is_listobject(op) ((op)->ob_type == &Listtype)
|
||||
|
@ -25,3 +30,6 @@ extern int setlistitem PROTO((object *, int, object *));
|
|||
extern int inslistitem PROTO((object *, int, object *));
|
||||
extern int addlistitem PROTO((object *, object *));
|
||||
extern int sortlist PROTO((object *));
|
||||
|
||||
/* Macro, trading safety for speed */
|
||||
#define GETLISTITEM(op, i) ((op)->ob_item[i])
|
||||
|
|
|
@ -9,3 +9,10 @@ typedef object *(*method) FPROTO((object *, object *));
|
|||
extern object *newmethodobject PROTO((char *, method, object *));
|
||||
extern method getmethod PROTO((object *));
|
||||
extern object *getself PROTO((object *));
|
||||
|
||||
struct methodlist {
|
||||
char *ml_name;
|
||||
method ml_meth;
|
||||
};
|
||||
|
||||
extern object *findmethod PROTO((struct methodlist *, object *, char *));
|
||||
|
|
|
@ -1,9 +1,3 @@
|
|||
/* Module support interface */
|
||||
|
||||
struct methodlist {
|
||||
char *ml_name;
|
||||
method ml_meth;
|
||||
};
|
||||
|
||||
extern object *findmethod PROTO((struct methodlist *, object *, char *));
|
||||
extern object *initmodule PROTO((char *, struct methodlist *));
|
||||
|
|
|
@ -6,5 +6,4 @@ extern typeobject Moduletype;
|
|||
|
||||
extern object *newmoduleobject PROTO((char *));
|
||||
extern object *getmoduledict PROTO((object *));
|
||||
extern int setmoduledict PROTO((object *, object *));
|
||||
extern char *getmodulename PROTO((object *));
|
||||
|
|
|
@ -3,13 +3,14 @@
|
|||
typedef struct _node {
|
||||
int n_type;
|
||||
char *n_str;
|
||||
int n_lineno;
|
||||
int n_nchildren;
|
||||
struct _node *n_child;
|
||||
} node;
|
||||
|
||||
extern node *newnode PROTO((int type));
|
||||
extern node *addchild PROTO((node *n, int type, char *str));
|
||||
extern void freenode PROTO((node *n));
|
||||
extern node *newtree PROTO((int type));
|
||||
extern node *addchild PROTO((node *n, int type, char *str, int lineno));
|
||||
extern void freetree PROTO((node *n));
|
||||
|
||||
/* Node access functions */
|
||||
#define NCH(n) ((n)->n_nchildren)
|
||||
|
@ -28,3 +29,6 @@ extern void freenode PROTO((node *n));
|
|||
abort(); \
|
||||
} }
|
||||
#endif
|
||||
|
||||
extern void listtree PROTO((node *));
|
||||
extern void listnode PROTO((FILE *, node *));
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#define NDEBUG
|
||||
/* Object and type object interface */
|
||||
|
||||
/*
|
||||
|
@ -47,11 +48,15 @@ whose size is determined when the object is allocated.
|
|||
123456789-123456789-123456789-123456789-123456789-123456789-123456789-12
|
||||
*/
|
||||
|
||||
#ifdef THINK_C
|
||||
/* Debugging options for THINK_C (which has no -D compiler option): */
|
||||
/*#define TRACE_REFS*/
|
||||
/*#define REF_DEBUG*/
|
||||
#endif
|
||||
#ifndef NDEBUG
|
||||
|
||||
/* Turn on heavy reference debugging */
|
||||
#define TRACE_REFS
|
||||
|
||||
/* Turn on reference counting */
|
||||
#define REF_DEBUG
|
||||
|
||||
#endif /* NDEBUG */
|
||||
|
||||
#ifdef TRACE_REFS
|
||||
#define OB_HEAD \
|
||||
|
@ -147,9 +152,12 @@ extern typeobject Typetype; /* The type of type objects */
|
|||
|
||||
#define is_typeobject(op) ((op)->ob_type == &Typetype)
|
||||
|
||||
/* Generic operations on objects */
|
||||
extern void 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 *));
|
||||
|
||||
/* Flag bits for printing: */
|
||||
#define PRINT_RAW 1 /* No string quotes etc. */
|
||||
|
@ -215,6 +223,10 @@ extern long ref_total;
|
|||
DELREF(op)
|
||||
#endif
|
||||
|
||||
/* Macros to use in case the object pointer may be NULL: */
|
||||
|
||||
#define XINCREF(op) if ((op) == NULL) ; else INCREF(op)
|
||||
#define XDECREF(op) if ((op) == NULL) ; else DECREF(op)
|
||||
|
||||
/* Definition of NULL, so you don't have to include <stdio.h> */
|
||||
|
||||
|
@ -252,22 +264,12 @@ Failure Modes
|
|||
-------------
|
||||
|
||||
Functions may fail for a variety of reasons, including running out of
|
||||
memory. This is communicated to the caller in two ways: 'errno' is set
|
||||
to indicate the error, and the function result differs: functions that
|
||||
normally return a pointer return nil for failure, functions returning
|
||||
an integer return -1 (which can be a legal return value too!), and
|
||||
other functions return 0 for success and the error number for failure.
|
||||
Callers should always check for errors before using the result. The
|
||||
following error codes are used:
|
||||
|
||||
EBADF bad object type (first argument only)
|
||||
EINVAL bad argument type (second and further arguments)
|
||||
ENOMEM no memory (malloc failed)
|
||||
ENOENT key not found in dictionary
|
||||
EDOM index out of range or division by zero
|
||||
ERANGE result not representable
|
||||
|
||||
XXX any others?
|
||||
memory. This is communicated to the caller in two ways: an error string
|
||||
is set (see errors.h), and the function result differs: functions that
|
||||
normally return a pointer return NULL for failure, functions returning
|
||||
an integer return -1 (which could be a legal return value too!), and
|
||||
other functions return 0 for success and -1 for failure.
|
||||
Callers should always check for errors before using the result.
|
||||
|
||||
Reference Counts
|
||||
----------------
|
||||
|
@ -296,16 +298,3 @@ times.
|
|||
|
||||
123456789-123456789-123456789-123456789-123456789-123456789-123456789-12
|
||||
*/
|
||||
|
||||
/* Error number interface */
|
||||
#include <errno.h>
|
||||
|
||||
#ifndef errno
|
||||
extern int errno;
|
||||
#endif
|
||||
|
||||
#ifdef THINK_C
|
||||
/* Lightspeed C doesn't define these in <errno.h> */
|
||||
#define EDOM 33
|
||||
#define ERANGE 34
|
||||
#endif
|
||||
|
|
|
@ -24,8 +24,3 @@ extern varobject *newvarobject PROTO((typeobject *, unsigned int));
|
|||
#define NEWVAROBJ(type, typeobj, n) ((type *) newvarobject(typeobj, n))
|
||||
|
||||
extern int StopPrint; /* Set when printing is interrupted */
|
||||
|
||||
/* Malloc interface */
|
||||
#include "malloc.h"
|
||||
|
||||
extern char *strdup PROTO((const char *));
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
/* Instruction opcodes for compiled code */
|
||||
|
||||
#define DUP_TOP 0
|
||||
#define STOP_CODE 0
|
||||
#define POP_TOP 1
|
||||
#define ROT_TWO 2
|
||||
#define ROT_THREE 3
|
||||
#define DUP_TOP 4
|
||||
|
||||
#define UNARY_POSITIVE 10
|
||||
#define UNARY_NEGATIVE 11
|
||||
|
@ -76,5 +77,9 @@
|
|||
#define SETUP_EXCEPT 121 /* "" */
|
||||
#define SETUP_FINALLY 122 /* "" */
|
||||
|
||||
#define SET_LINENO 127 /* Current line number */
|
||||
|
||||
/* Comparison operator codes (argument to COMPARE_OP) */
|
||||
enum cmp_op {LT, LE, EQ, NE, GT, GE, IN, NOT_IN, IS, IS_NOT, EXC_MATCH, BAD};
|
||||
|
||||
#define HAS_ARG(op) ((op) >= HAVE_ARGUMENT)
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
/* Parser-tokenizer link interface */
|
||||
|
||||
#if 0
|
||||
extern int parsetok PROTO((struct tok_state *, grammar *, int start,
|
||||
node **n_ret));
|
||||
#endif
|
||||
extern int parsestring PROTO((char *, grammar *, int start, node **n_ret));
|
||||
extern int parsefile PROTO((FILE *, grammar *, int start,
|
||||
extern int parsefile PROTO((FILE *, char *, grammar *, int start,
|
||||
char *ps1, char *ps2, node **n_ret));
|
||||
|
|
15
Include/pgenheaders.h
Normal file
15
Include/pgenheaders.h
Normal file
|
@ -0,0 +1,15 @@
|
|||
/* Include files and extern declarations used by most of the parser.
|
||||
This is a precompiled header for THINK C. */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef THINK_C
|
||||
#define label label_
|
||||
#include <proto.h>
|
||||
#undef label
|
||||
#endif
|
||||
|
||||
#include "PROTO.h"
|
||||
#include "malloc.h"
|
||||
|
||||
extern void fatal PROTO((char *));
|
|
@ -7,7 +7,7 @@ int err_occurred PROTO((void));
|
|||
void err_get PROTO((object **, object **));
|
||||
void err_clear PROTO((void));
|
||||
|
||||
/* Predefined exceptions (in run.c) */
|
||||
/* Predefined exceptions */
|
||||
|
||||
extern object *RuntimeError;
|
||||
extern object *EOFError;
|
||||
|
@ -29,5 +29,6 @@ extern object *KeyboardInterrupt;
|
|||
extern int err_badarg PROTO((void));
|
||||
extern object *err_nomem PROTO((void));
|
||||
extern object *err_errno PROTO((object *));
|
||||
extern void err_input PROTO((int));
|
||||
|
||||
extern void err_badcall PROTO((void));
|
||||
|
|
23
Include/pythonrun.h
Normal file
23
Include/pythonrun.h
Normal file
|
@ -0,0 +1,23 @@
|
|||
/* Interfaces to parse and execute pieces of python code */
|
||||
|
||||
void initall PROTO((void));
|
||||
|
||||
int run PROTO((FILE *, char *));
|
||||
|
||||
int run_script PROTO((FILE *, char *));
|
||||
int run_tty_1 PROTO((FILE *, char *));
|
||||
int run_tty_loop PROTO((FILE *, char *));
|
||||
|
||||
int parse_string PROTO((char *, int, struct _node **));
|
||||
int parse_file PROTO((FILE *, char *, int, struct _node **));
|
||||
|
||||
object *eval_node PROTO((struct _node *, char *, object *, object *));
|
||||
|
||||
object *run_string PROTO((char *, int, object *, object *));
|
||||
object *run_file PROTO((FILE *, char *, int, object *, object *));
|
||||
object *run_err_node PROTO((int, struct _node *, char *, object *, object *));
|
||||
object *run_node PROTO((struct _node *, char *, object *, object *));
|
||||
|
||||
void print_error PROTO((void));
|
||||
|
||||
void goaway PROTO((int));
|
40
Include/structmember.h
Normal file
40
Include/structmember.h
Normal file
|
@ -0,0 +1,40 @@
|
|||
/* Interface to map C struct members to Python object attributes */
|
||||
|
||||
/* The offsetof() macro calculates the offset of a structure member
|
||||
in its structure. Unfortunately this cannot be written down
|
||||
portably, hence it is provided by a Standard C header file.
|
||||
For pre-Standard C compilers, here is a version that usually works
|
||||
(but watch out!): */
|
||||
|
||||
#ifndef offsetof
|
||||
#define offsetof(type, member) ( (int) & ((type*)0) -> member )
|
||||
#endif
|
||||
|
||||
/* An array of memberlist structures defines the name, type and offset
|
||||
of selected members of a C structure. These can be read by
|
||||
getmember() and set by setmember() (except if their READONLY flag
|
||||
is set). The array must be terminated with an entry whose name
|
||||
pointer is NULL. */
|
||||
|
||||
struct memberlist {
|
||||
char *name;
|
||||
int type;
|
||||
int offset;
|
||||
int readonly;
|
||||
};
|
||||
|
||||
/* Types */
|
||||
#define T_SHORT 0
|
||||
#define T_INT 1
|
||||
#define T_LONG 2
|
||||
#define T_FLOAT 3
|
||||
#define T_DOUBLE 4
|
||||
#define T_STRING 5
|
||||
#define T_OBJECT 6
|
||||
|
||||
/* Readonly flag */
|
||||
#define READONLY 1
|
||||
#define RO READONLY /* Shorthand */
|
||||
|
||||
object *getmember PROTO((char *, struct memberlist *, char *));
|
||||
int setmember PROTO((char *, struct memberlist *, char *, object *));
|
|
@ -3,4 +3,4 @@
|
|||
object *sysget PROTO((char *));
|
||||
int sysset PROTO((char *, object *));
|
||||
FILE *sysgetfile PROTO((char *, FILE *));
|
||||
void initsys PROTO((int, char **));
|
||||
void initsys PROTO((void));
|
||||
|
|
6
Include/traceback.h
Normal file
6
Include/traceback.h
Normal file
|
@ -0,0 +1,6 @@
|
|||
/* Traceback interface */
|
||||
|
||||
int tb_here PROTO((struct _frame *, int, int));
|
||||
object *tb_fetch PROTO((void));
|
||||
int tb_store PROTO((object *));
|
||||
int tb_print PROTO((object *, FILE *));
|
|
@ -14,6 +14,11 @@ inserted in the tuple. Similarly, gettupleitem does not increment the
|
|||
returned item's reference count.
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
OB_VARHEAD
|
||||
object *ob_item[1];
|
||||
} tupleobject;
|
||||
|
||||
extern typeobject Tupletype;
|
||||
|
||||
#define is_tupleobject(op) ((op)->ob_type == &Tupletype)
|
||||
|
@ -22,3 +27,6 @@ extern object *newtupleobject PROTO((int size));
|
|||
extern int gettuplesize PROTO((object *));
|
||||
extern object *gettupleitem PROTO((object *, int));
|
||||
extern int settupleitem PROTO((object *, int, object *));
|
||||
|
||||
/* Macro, trading safety for speed */
|
||||
#define GETTUPLEITEM(op, i) ((op)->ob_item[i])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue