[hackers] [scc] Update TODO || Roberto E. Vargas Caballero

2015-08-05 Thread git
commit 6b87a0492cf186510ad71c5b20fa4e90ec4ff050
Author: Roberto E. Vargas Caballero k...@shike2.com
AuthorDate: Wed Aug 5 08:09:03 2015 +0200
Commit: Roberto E. Vargas Caballero k...@shike2.com
CommitDate: Wed Aug 5 08:09:03 2015 +0200

Update TODO

diff --git a/cc1/TODO b/cc1/TODO
index 4f6bbd9..8bd6c22 100644
--- a/cc1/TODO
+++ b/cc1/TODO
@@ -1,8 +1,6 @@
-* Implement constant expressions
 * Verify correctness in initializators
 * emit initializators
 * emit structures definition
-* Define array types based in the value of constant expressions
 * Rewrite decl.c and use only one decl function with a function pointer
   parameter
 * Allow external declarations of incomplete array types



[hackers] [scc] Rewrite decl.c || Roberto E. Vargas Caballero

2015-08-05 Thread git
commit 3c619b9a7518c458fe6343faab8f566368557080
Author: Roberto E. Vargas Caballero k...@shike2.com
AuthorDate: Wed Aug 5 08:52:33 2015 +0200
Commit: Roberto E. Vargas Caballero k...@shike2.com
CommitDate: Wed Aug 5 08:55:39 2015 +0200

Rewrite decl.c

decl.c had several function that were very similar between them,
basically the different kind of declarations in a C program:

- externals
- internals
- parameters
- struct/union fields

This version puts all the logic in only one function, dodcl(),
which receives different parameters to adapt to the different
situations. The idea was taken from kencc and lcc.

diff --git a/cc1/TODO b/cc1/TODO
index 8bd6c22..96638cb 100644
--- a/cc1/TODO
+++ b/cc1/TODO
@@ -1,8 +1,6 @@
 * Verify correctness in initializators
 * emit initializators
 * emit structures definition
-* Rewrite decl.c and use only one decl function with a function pointer
-  parameter
 * Allow external declarations of incomplete array types
 * Implement bitfields
 * Define data structure shared between cc1 and cc2 with the type
diff --git a/cc1/cc1.h b/cc1/cc1.h
index 7399403..3d9630d 100644
--- a/cc1/cc1.h
+++ b/cc1/cc1.h
@@ -306,7 +306,7 @@ extern void compound(Symbol *lbreak, Symbol *lcont, 
Caselist *lswitch);
 
 /* decl.c */
 extern Type *typename(void);
-extern void extdecl(void), decl(void);
+extern void decl(void);
 
 /* lex.c */
 extern char ahead(void);
@@ -350,6 +350,8 @@ extern int cppoff, disexpand;
 extern unsigned cppctx;
 extern Input *input;
 extern int lexmode;
+extern unsigned curctx;
+extern Symbol *curfun;
 
 extern Type *voidtype, *pvoidtype, *booltype,
 *uchartype,   *chartype,
diff --git a/cc1/decl.c b/cc1/decl.c
index 04d40b1..d6aeaab 100644
--- a/cc1/decl.c
+++ b/cc1/decl.c
@@ -8,11 +8,8 @@
 #include ../inc/cc.h
 #include cc1.h
 
-#define ID_EXPECTED 1
-#define ID_ACCEPTED 2
-#define ID_FORBIDDEN3
-
-/* TODO: check identifiers in enum declaration */
+#define OUTCTX 0
+#define PARCTX 1
 
 struct dcldata {
unsigned char op;
@@ -55,54 +52,16 @@ arydcl(struct dcldata *dp)
return queue(dp, ARY, n, NULL);
 }
 
-static Symbol *parameter(void);
+static void parlist(Type *);
 
 static struct dcldata *
 fundcl(struct dcldata *dp)
 {
-   size_t siz;
-   unsigned n, i, noname;
-   Type *pars[NR_FUNPARAM], **tp = pars;
-   Symbol *syms[NR_FUNPARAM], **sp = syms, *sym;
+   Type dummy = {.n = {.elem = 0}, .pars = NULL};
 
pushctx();
-   expect('(');
-
-   n = noname = 0;
-   if (yytoken != ')') do {
-   if ((sym = parameter()) == NULL) {
-   if (n == 0)
-   break;
-   error(incorrect void parameter);
-   }
-   if (n++ == NR_FUNPARAM)
-   error(too much parameters in function definition);
-   *sp++ = sym;
-   *tp++ = sym-type;
-   noname |= sym-name[0] == '\0';
-   } while (accept(','));
-
-   expect(')');
-   if (n != 0) {
-   siz = sizeof(*tp) * n;
-   tp = memcpy(xmalloc(siz), pars, siz);
-   } else {
-   tp = NULL;
-   }
-
-   if (yytoken != '{') {
-   /* it is only a prototype */
-   popctx();
-   } else {
-   /* it is a function definition */
-   if (noname)
-   error(parameter name omitted);
-   sp = syms;
-   for (i = 0; i  n; ++i)
-   emit(ODECL, *sp++);
-   }
-
-   return queue(dp, FTN, n, tp);
+   parlist(dummy);
+   return queue(dp, FTN, dummy.n.elem, dummy.pars);
 }
 
 static struct dcldata *declarator0(struct dcldata *dp, unsigned ns);
@@ -154,7 +113,7 @@ declarator0(struct dcldata *dp, unsigned ns)
 }
 
 static Symbol *
-declarator(Type *tp, int flags, unsigned ns)
+declarator(Type *tp, unsigned ns)
 {
struct dcldata data[NR_DECLARATORS+1];
struct dcldata *bp;
@@ -167,16 +126,12 @@ declarator(Type *tp, int flags, unsigned ns)
tp = mktype(tp, bp-op, bp-nelem, bp-data);
} else {
sym = bp-data;
-   if (flags == ID_EXPECTED  *sym-name == '\0')
-   error(missed identifier in declaration);
-   if (flags == ID_FORBIDDEN  *sym-name != '\0')
-   error(unexpected identifier in type name);
break;
}
}
 
/* TODO: deal with external array declarations of []  */
-   if (!tp-defined  *sym-name)
+   if (!tp-defined  sym-name)
error(declared variable '%s' of incomplete type, sym-name);
sym-type = tp;
return sym;
@@ -326,63 +281,26 @@ newtag(void)
 
 /* TODO: bitfields */
 
+static void fieldlist(Type *tp);
+
 static Type *
 

[hackers] [scc] Fix error related to incorrect parameter declaration || Roberto E. Vargas Caballero

2015-08-05 Thread git
commit cde67f41cb37d1c695d7de0a5100458bcc5de9c1
Author: Roberto E. Vargas Caballero k...@shike2.com
AuthorDate: Wed Aug 5 09:07:45 2015 +0200
Commit: Roberto E. Vargas Caballero k...@shike2.com
CommitDate: Wed Aug 5 09:07:45 2015 +0200

Fix error related to incorrect parameter declaration

dodcl is called without knowing that the next token
is a valid specifier, so specifier() can return
NULL in the case of parameters. This patch detects
this situation and apply old rule of default int.
Maybe is better to put a flag for it.

diff --git a/cc1/decl.c b/cc1/decl.c
index d6aeaab..6957c38 100644
--- a/cc1/decl.c
+++ b/cc1/decl.c
@@ -364,7 +364,7 @@ typename(void)
 }
 
 static void
-field(Symbol *sym, unsigned sclass, Type *data)
+field(Symbol *sym, int sclass, Type *data)
 {
Type *tp = sym-type, *funtp = data;
size_t n = funtp-n.elem;
@@ -384,7 +384,7 @@ field(Symbol *sym, unsigned sclass, Type *data)
 }
 
 static void
-parameter(Symbol *sym, unsigned sclass, Type *data)
+parameter(Symbol *sym, int sclass, Type *data)
 {
Type *tp = sym-type, *funtp = data;
size_t n = funtp-n.elem;
@@ -415,7 +415,7 @@ parameter(Symbol *sym, unsigned sclass, Type *data)
 }
 
 static void
-internal(Symbol *sym, unsigned sclass, Type *data)
+internal(Symbol *sym, int sclass, Type *data)
 {
 
if (!sym-name) {
@@ -431,7 +431,7 @@ internal(Symbol *sym, unsigned sclass, Type *data)
 }
 
 static void
-external(Symbol *sym, unsigned sclass, Type *data)
+external(Symbol *sym, int sclass, Type *data)
 {
if (!sym-name) {
warn(empty declaration);
@@ -480,25 +480,24 @@ prototype(Symbol *sym)
 }
 
 static bool
-dodcl(int rep, void (*fun)(Symbol *, unsigned, Type *), uint8_t ns, Type *type)
+dodcl(int rep, void (*fun)(Symbol *, int, Type *), uint8_t ns, Type *type)
 {
-   Type *base, *tp = NULL;
-   unsigned sclass = 0;
-   Symbol *sym = NULL;
+   Type *base;
+   int sclass;
 
/* FIXME: curctx == PARCTX is incorrect. Structs also
 * create new contexts
 */
-   /* FIXME: in arguments base can be NULL */
-   base = specifier(sclass);
-   if (!base  curctx == OUTCTX) {
+   if ((base = specifier(sclass)) == NULL) {
+   if (curctx != OUTCTX)
+   unexpected();
warn(type defaults to 'int' in declaration);
-   tp = inttype;
+   base = inttype;
}
 
do {
-   sym = declarator(base, ns);
-   tp = sym-type;
+   Symbol *sym = declarator(base, ns);
+   Type *tp = sym-type;
 
switch (sclass) {
case REGISTER:



[hackers] [scc] Emit parameters in functions || Roberto E. Vargas Caballero

2015-08-05 Thread git
commit 7d056d042a60919bb854929e776e138e0ee2817d
Author: Roberto E. Vargas Caballero k...@shike2.com
AuthorDate: Wed Aug 5 20:01:45 2015 +0200
Commit: Roberto E. Vargas Caballero k...@shike2.com
CommitDate: Wed Aug 5 20:01:45 2015 +0200

Emit parameters in functions

Parameters are marked with a P, and in this case are
emited before of the body of the function, but this is
something we should change because we are loosing the
storage specifier.

diff --git a/cc1/decl.c b/cc1/decl.c
index 6957c38..3376a60 100644
--- a/cc1/decl.c
+++ b/cc1/decl.c
@@ -59,8 +59,8 @@ fundcl(struct dcldata *dp)
 {
Type dummy = {.n = {.elem = 0}, .pars = NULL};
 
-   pushctx();
parlist(dummy);
+
return queue(dp, FTN, dummy.n.elem, dummy.pars);
 }
 
@@ -409,6 +409,7 @@ parameter(Symbol *sym, int sclass, Type *data)
error(bad storage class in function parameter);
if (n++ == NR_FUNPARAM)
error(too much parameters in function definition);
+   sym-flags |= ISPARAM;
funtp-pars = xrealloc(funtp-pars, n);
funtp-pars[n-1] = tp;
funtp-n.elem = n;
@@ -462,27 +463,23 @@ prototype(Symbol *sym)
if (sym-token == TYPEIDEN)
error(function definition declared 'typedef');
 
-   /* TODO: emit parameters emit(ODECL, *sp++); */
sym-flags |= ISDEFINED;
curfun = sym;
emit(OFUN, sym);
compound(NULL, NULL, NULL);
emit(OEFUN, NULL);
+   popctx();
r = 0;
}
 
-   /*
-* fundcl() creates a new context for the parameters
-* and in this point we have to destroy the context
-*/
-   popctx();
return r;
 }
 
-static bool
+static Symbol *
 dodcl(int rep, void (*fun)(Symbol *, int, Type *), uint8_t ns, Type *type)
 {
-   Type *base;
+   Symbol *sym;
+   Type *base, *tp;
int sclass;
 
/* FIXME: curctx == PARCTX is incorrect. Structs also
@@ -496,8 +493,8 @@ dodcl(int rep, void (*fun)(Symbol *, int, Type *), uint8_t 
ns, Type *type)
}
 
do {
-   Symbol *sym = declarator(base, ns);
-   Type *tp = sym-type;
+   sym = declarator(base, ns);
+   tp = sym-type;
 
switch (sclass) {
case REGISTER:
@@ -516,13 +513,13 @@ dodcl(int rep, void (*fun)(Symbol *, int, Type *), 
uint8_t ns, Type *type)
sym-token = TYPEIDEN;
break;
}
-
if (tp-op == FTN  !prototype(sym))
-   return 0;
+   return NULL;
(*fun)(sym, sclass, type);
+
} while (rep  accept(','));
 
-   return 1;
+   return sym;
 }
 
 void
@@ -535,20 +532,46 @@ decl(void)
expect(';');
 }
 
+/*
+ * parlist() is called every time there is a argument list.
+ * It means that is called for prototypes and for functions.
+ * In both cases a new context is needed for the arguments,
+ * but in the case of prototypes we need pop the context
+ * before parsing anything else or we can have name conflicts.
+ * The heuristic used here to detect a function is check if
+ * next token will be '{', but it implies that KR alike
+ * functions are not allowed.
+ */
 static void
 parlist(Type *tp)
 {
+   Symbol *pars[NR_FUNPARAM], **sp = pars, *sym;
+   bool isfun;
+   int n;
+
+   pushctx();
expect('(');
 
if (accept(')')) {
-   /* TODO: implement kr functions */
+   tp-n.elem = -1;
return;
}
+
do
-   dodcl(0, parameter, NS_IDEN, tp);
+   *sp++ = dodcl(0, parameter, NS_IDEN, tp);
while (accept(','));
 
+   isfun = ahead() == '{';
+   if (!isfun)
+   popctx();
expect(')');
+
+   if (!isfun)
+   return;
+
+   n = tp-n.elem;
+   for (sp = pars; n--  0; ++sp)
+   emit(ODECL, *sp);
 }
 
 static void



[hackers] [scc] Change type of mktype parameter || Roberto E. Vargas Caballero

2015-08-05 Thread git
commit 64df849f2c1cd54a41c09c553f260ecb2c793595
Author: Roberto E. Vargas Caballero k...@shike2.com
AuthorDate: Wed Aug 5 21:18:50 2015 +0200
Commit: Roberto E. Vargas Caballero k...@shike2.com
CommitDate: Wed Aug 5 21:18:50 2015 +0200

Change type of mktype parameter

This parameter only receives Type ** data, so it is better
use Type ** instead of void *.

diff --git a/cc1/cc1.h b/cc1/cc1.h
index 3d9630d..5c0b281 100644
--- a/cc1/cc1.h
+++ b/cc1/cc1.h
@@ -289,7 +289,7 @@ extern void printerr(char *fmt, ...);
 /* types.c */
 extern bool eqtype(Type *tp1, Type *tp2);
 extern Type *ctype(unsigned type, unsigned sign, unsigned size);
-extern Type *mktype(Type *tp, unsigned op, short nelem, void *data);
+extern Type *mktype(Type *tp, unsigned op, short nelem, Type *data[]);
 extern Type *duptype(Type *base);
 
 /* symbol.c */
diff --git a/cc1/types.c b/cc1/types.c
index ddcbbc0..cceb98c 100644
--- a/cc1/types.c
+++ b/cc1/types.c
@@ -263,7 +263,7 @@ invalid_type:
 }
 
 Type *
-mktype(Type *tp, unsigned op, short nelem, void *data)
+mktype(Type *tp, unsigned op, short nelem, Type *pars[])
 {
static Type *typetab[NR_TYPE_HASH];
Type **tbl, type;
@@ -284,7 +284,7 @@ mktype(Type *tp, unsigned op, short nelem, void *data)
type.type = tp;
type.op = op;
type.letter = letters[op];
-   type.pars = data;
+   type.pars = pars;
type.n.elem = nelem;
type.ns = 0;
 



[hackers] [scc] Remove non used variables || Roberto E. Vargas Caballero

2015-08-05 Thread git
commit 53b8642aa9cedc398e937c31d7b5ca75c78b0ed9
Author: Roberto E. Vargas Caballero k...@shike2.com
AuthorDate: Wed Aug 5 22:14:00 2015 +0200
Commit: Roberto E. Vargas Caballero k...@shike2.com
CommitDate: Wed Aug 5 22:14:00 2015 +0200

Remove non used variables

diff --git a/cc1/code.c b/cc1/code.c
index d513286..e0488cb 100644
--- a/cc1/code.c
+++ b/cc1/code.c
@@ -365,7 +365,6 @@ constnode(Symbol *sym)
 Node *
 sizeofnode(Type *tp)
 {
-   Node *np;
Symbol *sym;
 
sym = newsym(NS_IDEN);
diff --git a/cc1/decl.c b/cc1/decl.c
index 3376a60..453a4b2 100644
--- a/cc1/decl.c
+++ b/cc1/decl.c
@@ -545,7 +545,7 @@ decl(void)
 static void
 parlist(Type *tp)
 {
-   Symbol *pars[NR_FUNPARAM], **sp = pars, *sym;
+   Symbol *pars[NR_FUNPARAM], **sp = pars;
bool isfun;
int n;
 



[hackers] [scc] Remove unneeded prototypes in code.c || Roberto E. Vargas Caballero

2015-08-05 Thread git
commit 8ef2996b6e515b7ab4aa177ba3511bf875a7eeff
Author: Roberto E. Vargas Caballero k...@shike2.com
AuthorDate: Wed Aug 5 22:00:44 2015 +0200
Commit: Roberto E. Vargas Caballero k...@shike2.com
CommitDate: Wed Aug 5 22:13:27 2015 +0200

Remove unneeded prototypes in code.c

diff --git a/cc1/code.c b/cc1/code.c
index f1994a4..d513286 100644
--- a/cc1/code.c
+++ b/cc1/code.c
@@ -12,7 +12,7 @@ static void emitbin(unsigned, void *),
 emitsym(unsigned, void *), emitfield(unsigned, void *),
 emitexp(unsigned, void *),
 emitsymid(unsigned, void *), emittext(unsigned, void *),
-emitprint(unsigned, void *), emitfun(unsigned, void *),
+emitfun(unsigned, void *),
 emitret(unsigned, void *), emitdcl(unsigned, void *);
 
 char *optxt[] = {
@@ -120,12 +120,6 @@ void (*opcode[])(unsigned, void *) = {
[OSWITCH] = emitswitch
 };
 
-static Node *simple_add(Type *, Node *, Node *),
-*simple_sub(Type *, Node *, Node *),
-*simple_mul(Type *, Node *, Node *),
-*simple_div(Type *, Node *, Node *),
-*simple_mod(Type *, Node *, Node *);
-
 void
 freetree(Node *np)
 {



[hackers] [scc] Fix type in several declarations || Roberto E. Vargas Caballero

2015-08-05 Thread git
commit 423f75f011f84fbc1ae9b439e34860f1d09d583f
Author: Roberto E. Vargas Caballero k...@shike2.com
AuthorDate: Wed Aug 5 22:15:27 2015 +0200
Commit: Roberto E. Vargas Caballero k...@shike2.com
CommitDate: Wed Aug 5 22:15:27 2015 +0200

Fix type in several declarations

diff --git a/cc1/code.c b/cc1/code.c
index e0488cb..573f03a 100644
--- a/cc1/code.c
+++ b/cc1/code.c
@@ -175,7 +175,7 @@ emitconst(Node *np)
 
switch (BTYPE(np)) {
case INT:
-   printf(#%c%x, np-type-letter, sym-u.i);
+   printf(#%c%X, np-type-letter, sym-u.i);
break;
case ARY:
/*
diff --git a/cc1/decl.c b/cc1/decl.c
index 453a4b2..3c782fa 100644
--- a/cc1/decl.c
+++ b/cc1/decl.c
@@ -14,7 +14,7 @@
 struct dcldata {
unsigned char op;
unsigned short nelem;
-   unsigned ndcl;
+   unsigned char ndcl;
void *data;
 };
 
@@ -140,7 +140,7 @@ declarator(Type *tp, unsigned ns)
 static Type *structdcl(void), *enumdcl(void);
 
 static Type *
-specifier(unsigned *sclass)
+specifier(int *sclass)
 {
Type *tp = NULL;
unsigned spec, qlf, sign, type, cls, size;
diff --git a/cc1/stmt.c b/cc1/stmt.c
index 4b34e3a..47db215 100644
--- a/cc1/stmt.c
+++ b/cc1/stmt.c
@@ -341,8 +341,7 @@ compound(Symbol *lbreak, Symbol *lcont, Caselist *lswitch)
 static void
 stmt(Symbol *lbreak, Symbol *lcont, Caselist *lswitch)
 {
-   void (*fun)(Symbol *lbreak, Symbol *lcont, Caselist *lswitch);
-   Node *np;
+   void (*fun)(Symbol *, Symbol *, Caselist *);
 
switch (yytoken) {
case '{':  fun = compound; break;
diff --git a/cc1/types.c b/cc1/types.c
index cceb98c..3436723 100644
--- a/cc1/types.c
+++ b/cc1/types.c
@@ -312,8 +312,12 @@ mktype(Type *tp, unsigned op, short nelem, Type *pars[])
tbl = typetab[t];
for (bp = *tbl; bp; bp = bp-next) {
if (eqtype(bp, type)) {
-   /* FIXME: data can be a pointer to static data */
-   free(data);
+   /*
+* pars was allocated by the caller
+* but the type already exists, so
+* we have to deallocted it
+*/
+   free(pars);
return bp;
}
}



[hackers] [dmenu] [PATCH] Typo Patch

2015-08-05 Thread Eric Pruitt
This patch fixes a typo in dmenu.

Eric
From 98573e0f8c4dda3ebe2a3639f24046c7d80cc3d8 Mon Sep 17 00:00:00 2001
From: Eric Pruitt eric.pru...@gmail.com
Date: Wed, 5 Aug 2015 19:19:14 -0700
Subject: [PATCH] Fixed typo introduced by shared code

---
 dmenu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/dmenu.c b/dmenu.c
index 3b465cf..12cf6c7 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -128,7 +128,7 @@ main(int argc, char *argv[]) {
 	if(!setlocale(LC_CTYPE, ) || !XSupportsLocale())
 		fputs(warning: no locale support\n, stderr);
 	if(!(dpy = XOpenDisplay(NULL)))
-		die(dwm: cannot open display\n);
+		die(dmenu: cannot open display\n);
 	screen = DefaultScreen(dpy);
 	root = RootWindow(dpy, screen);
 	sw = DisplayWidth(dpy, screen);
-- 
2.1.4



[hackers] [dvtm] [PATCH] Redraw border with URGENT_ATTR as soon as possible

2015-08-05 Thread Marcel Rodrigues
When a visible window other than the selected one receives a bell
('\a'), I expect its border to be redrawn immediately with the
corresponding attributes (URGENT_ATTR). Currently this does not
happen: the border will remain the same until draw_border() is
eventually called as a result of other events, such as layout
changing. The following patch is intended to fix this:

diff --git a/dvtm.c b/dvtm.c
index 7170f3b..373767f 100644
--- a/dvtm.c
+++ b/dvtm.c
@@ -626,6 +626,8 @@ term_urgent_handler(Vt *term) {
printf(\a);
fflush(stdout);
drawbar();
+   if (!isarrange(fullscreen)  sel != c  isvisible(c))
+   draw_border(c);
 }

 static void