shithub: scc

Download patch

ref: e4d503205c322cbae995b0e195c3b17db25e686d
parent: 1aea31215a1c95497aaa919b1d88296f59fd8f2c
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Wed Jan 27 00:40:01 EST 2016

[cc2] Fix definition of OOR and OSYM

They were using letters that were already used in other
opcodes.
[cc2] Add return statement to the parser

Return is different to expressions, because it has a first element
that is prefix instead of postfix like all the elements of expressions.

--- a/cc2/cc2.h
+++ b/cc2/cc2.h
@@ -70,9 +70,9 @@
 	OCOLON   = ' ',
 	OADDR    = '\'',
 	OAND     = 'a',
-	OOR      = 'b',
+	OOR      = 'o',
 	OPTR     = '@',
-	OSYM     = 'y',
+	OSYM     = 'i',
 	OCAST    = 'g',
 	OCONST   = '#',
 	OSTRING  = '"',
--- a/cc2/parser.c
+++ b/cc2/parser.c
@@ -32,7 +32,8 @@
 
 typedef void parsefun(char *, union tokenop);
 static parsefun type, symbol, getname, unary, binary, ternary, call,
-                parameter, constant, composed, begininit, endinit;
+                parameter, constant, composed, begininit, endinit,
+                jump;
 
 typedef void evalfun(void);
 static evalfun vardecl, beginfun, endfun, endpars, stmt,
@@ -115,6 +116,9 @@
 
 	[OCONST]      = NULL, constant,
 
+	[OJMP]        = NULL, NULL,
+	[ORET]        = NULL, jump,
+
 	[OCASE]       = NULL,
 	[ODEFAULT]    = NULL,
 	[OTABLE]      = NULL,
@@ -124,7 +128,7 @@
 static void *stack[STACKSIZ], **sp = stack;
 static Symbol *lastsym, *curfun, *lastaggreg;
 static Symbol *params[NR_FUNPARAM];
-static int funpars = -1, sclass, callpars, ininit;
+static int funpars = -1, sclass, callpars, ininit, injump;
 static Node *stmtp, *callp;
 
 static void
@@ -238,6 +242,17 @@
 }
 
 static void
+jump(char *token, union tokenop u)
+{
+	Node *np;
+
+	np = newnode();
+	np->op = *token;
+	push(np);
+	injump = 1;
+}
+
+static void
 unary(char *token, union tokenop u)
 {
 	Node *np = newnode();
@@ -445,12 +460,19 @@
 stmt(void)
 {
 	static Node *lastp;
-	Node *np = pop();
+	Node *aux, *np;
 
+	np = pop();
 	if (ininit) {
 		data(np);
 		deltree(np);
 		return;
+	}
+	if (injump) {
+		aux = np;
+		np = pop();
+		np->left = aux;
+		injump = 0;
 	}
 	if (!stmtp)
 		stmtp = np;