summary refs log tree commit diff
path: root/lisc/parse.c
diff options
context:
space:
mode:
authorQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2015-07-19 07:03:38 -0400
committerQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2015-09-15 23:01:28 -0400
commita280eb6597da33ea23f8349f74a20416e5519e7e (patch)
treee26aafc90d155950b339c48c298bfe8c2c60b77c /lisc/parse.c
parente5a7482b54f0840d4b9fe37488020410cd67a684 (diff)
downloadroux-a280eb6597da33ea23f8349f74a20416e5519e7e.tar.gz
export error functions
Diffstat (limited to 'lisc/parse.c')
-rw-r--r--lisc/parse.c31
1 files changed, 22 insertions, 9 deletions
diff --git a/lisc/parse.c b/lisc/parse.c
index 6f5a030..168da6d 100644
--- a/lisc/parse.c
+++ b/lisc/parse.c
@@ -9,6 +9,8 @@ enum {
 	NSym = 256,
 };
 
+Ins insb[NIns];
+
 OpDesc opdesc[OLast] = {
 	[OAdd] = { 2, 1, "add" },
 	[OSub] = { 2, 0, "sub" },
@@ -59,8 +61,8 @@ static int lnum;
 
 static Sym sym[NSym];
 static int ntmp;
-static Ins ins[NIns], *curi;
 static Phi **plink;
+static Ins *curi;
 static Blk *bmap[NBlk+1];
 static Blk *curb;
 static Blk **blink;
@@ -72,18 +74,29 @@ alloc(size_t n)
 {
 	void *p;
 
+	/* todo, export in util.c */
 	p = calloc(1, n);
 	if (!p)
 		abort();
 	return p;
 }
 
+void
+diag(char *s)
+{
+	/* todo, export in util.c */
+	fputs(s, stderr);
+	fputc('\n', stderr);
+	abort();
+}
+
 static void
 err(char *s)
 {
-	/* todo, export the error handling in util.c */
-	fprintf(stderr, "parse error: %s (line %d)\n", s, lnum);
-	exit(1);
+	char buf[100];
+
+	snprintf(buf, sizeof buf, "parse: %s (line %d)", s, lnum);
+	diag(buf);
 }
 
 static Token
@@ -287,11 +300,11 @@ expect(Token t)
 static void
 closeblk()
 {
-	curb->nins = curi - ins;
+	curb->nins = curi - insb;
 	curb->ins = alloc(curb->nins * sizeof(Ins));
-	memcpy(curb->ins, ins, curb->nins * sizeof(Ins));
+	memcpy(curb->ins, insb, curb->nins * sizeof(Ins));
 	blink = &curb->link;
-	curi = ins;
+	curi = insb;
 }
 
 static PState
@@ -407,7 +420,7 @@ parseline(PState ps)
 	if (op != -1 && i != opdesc[op].arity)
 		err("invalid arity");
 	if (op != -1) {
-		if (curi - ins >= NIns)
+		if (curi - insb >= NIns)
 			err("too many instructions in block");
 		curi->op = op;
 		curi->to = r;
@@ -440,7 +453,7 @@ parsefn(FILE *f)
 	for (i=Tmp0; i<NSym; i++)
 		sym[i] = (Sym){.type = SUndef};
 	ntmp = Tmp0;
-	curi = ins;
+	curi = insb;
 	curb = 0;
 	lnum = 1;
 	nblk = 0;