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])

0 commit comments

Comments
 (0)