ref: dc95ae0df8f8e050672c1d84a01e2e318000c7ee
parent: aa6064b00e6354252a719357723a6b7265373a66
author: Ori Bernstein <ori@eigenstate.org>
date: Sun Nov 13 16:28:11 EST 2011
Stubbing in more stuff.
--- a/parse/Makefile
+++ b/parse/Makefile
@@ -1,5 +1,6 @@
BIN=pt
OBJ=dump.o \
+ infer.o \
main.o \
names.o \
node.o \
@@ -6,6 +7,7 @@
gram.o \
tok.o \
type.o \
+ use.o \
util.o
CLEAN=gram.c
--- a/parse/dump.c
+++ b/parse/dump.c
@@ -47,6 +47,10 @@
switch(n->type) {
case Nfile:
fprintf(fd, "(name = %s)\n", n->file.name);
+ for (i = 0; i < n->file.nuses; i++)
+ dumpnode(n->file.uses[i], fd, depth + 1);
+ for (i = 0; i < n->file.nstmts; i++)
+ dumpnode(n->file.stmts[i], fd, depth + 1);
break;
case Ndecl:
fprintf(fd, "\n");
@@ -67,7 +71,7 @@
case Nloopstmt:
dumpnode(n->loopstmt.init, fd, depth+1);
dumpnode(n->loopstmt.cond, fd, depth+1);
- dumpnode(n->loopstmt.incr, fd, depth+1);
+ dumpnode(n->loopstmt.step, fd, depth+1);
dumpnode(n->loopstmt.body, fd, depth+1);
break;
case Nuse:
--- a/parse/node.c
+++ b/parse/node.c
@@ -88,7 +88,7 @@
n = mknode(line, Nloopstmt);
n->loopstmt.init = init;
n->loopstmt.cond = init;
- n->loopstmt.incr = incr;
+ n->loopstmt.step = incr;
n->loopstmt.body = body;
return n;
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -53,7 +53,7 @@
struct Type {
Ty type;
int tid;
- size_t nsub; /* type sub-parts. For fnsub, tusub, sdecls, udecls, edecls. */
+ size_t nsub; /* For fnsub, tusub, sdecls, udecls, edecls. */
union {
Node *name; /* Tyname: unresolved name */
Type **fnsub; /* Tyfunc: return, args */
@@ -76,10 +76,12 @@
int type;
union {
struct {
- char *name;
+ char *name;
+ size_t nuses;
+ Node **uses;
size_t nstmts;
Node **stmts;
- Stab **globals;
+ Stab *globls;
} file;
struct {
@@ -116,7 +118,7 @@
struct {
Node *init;
Node *cond;
- Node *incr;
+ Node *step;
Node *body;
} loopstmt;
@@ -216,10 +218,15 @@
Node *mkdecl(int line, Sym *sym);
Node *mklabel(int line, char *lbl);
-
void addstmt(Node *file, Node *stmt);
void setns(Node *n, char *name);
+/* usefiles */
+void readuse(Node *use, Stab *into);
+
+/* typechecking/inference */
+void infer(Node *file);
+
/* debug */
void dump(Node *t, FILE *fd);
char *opstr(Op o);
@@ -227,7 +234,7 @@
char *litstr(Littype lt);
char *tidstr(Ty tid);
-/* convenience macro */
+/* convenience func */
void nlappend(Node ***nl, size_t *len, Node *n);
/* backend functions */