[hackers] [scc] [cc2] Fix definition of OOR and OSYM || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Wed, 27 Jan 2016 16:59:16 +0100 (CET)

commit e4d503205c322cbae995b0e195c3b17db25e686d
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Wed Jan 27 05:40:01 2016 +0100
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Wed Jan 27 07:17:43 2016 +0100

    [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.

diff --git a/cc2/cc2.h b/cc2/cc2.h
index 52dfd85..fe0cfce 100644
--- a/cc2/cc2.h
+++ b/cc2/cc2.h
_AT_@ -70,9 +70,9 @@ enum op {
         OCOLON = ' ',
         OADDR = '\'',
         OAND = 'a',
- OOR = 'b',
+ OOR = 'o',
         OPTR = '_AT_',
- OSYM = 'y',
+ OSYM = 'i',
         OCAST = 'g',
         OCONST = '#',
         OSTRING = '"',
diff --git a/cc2/parser.c b/cc2/parser.c
index 8f2ae2e..a2fc32c 100644
--- a/cc2/parser.c
+++ b/cc2/parser.c
_AT_@ -32,7 +32,8 @@ union tokenop {
 
 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,
_AT_@ -115,6 +116,9 @@ static struct decoc {
 
         [OCONST] = NULL, constant,
 
+ [OJMP] = NULL, NULL,
+ [ORET] = NULL, jump,
+
         [OCASE] = NULL,
         [ODEFAULT] = NULL,
         [OTABLE] = NULL,
_AT_@ -124,7 +128,7 @@ static struct decoc {
 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
_AT_@ -238,6 +242,17 @@ ternary(char *token, union tokenop u)
 }
 
 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();
_AT_@ -445,13 +460,20 @@ static void
 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;
         else
Received on Wed Jan 27 2016 - 16:59:16 CET

This archive was generated by hypermail 2.3.0 : Wed Jan 27 2016 - 17:00:50 CET