Commits

Anonymous committed 0dac2d2

Make DEBUG compile-time conditional, compile under -ansi -pedantic.

Comments (0)

Files changed (3)

impl/mignon/Makefile

 CFLAGS+= ${WARNS} ${EXTRA_CFLAGS}
 
 ifdef DEBUG
-  CFLAGS+= -g
+  CFLAGS+= -g -DDEBUG
 endif
 
 OBJS=	sexp${O} parse${O} eval${O} main${O}

impl/mignon/eval.c

     printf("}\n");
 }
 
+#ifdef DEBUG
 static void debug(const char *msg)
 {
-    //printf("%s\n", msg);
+    printf("%s\n", msg);
     msg = msg;
 }
+#else
+#define debug(x)
+#endif
 
 struct value *eval(struct value *sexp, struct env *env)
 {
         switch (sexp->type) {
             case V_ATOM:
             {
-                debug("V_ATOM");
-                debug(((struct atom *)sexp)->string);
                 struct atom *name = (struct atom *)sexp;
                 struct value *value = lookup(env, name);
                 if (value == NULL) {
             }
             case V_CONS:
             {
-                debug("V_CONS");
                 struct value *h = head(sexp);
                 struct value *t = tail(sexp);
                 struct value *bound = lookup(env, (struct atom *)h);
+                debug("V_CONS");
                 if (bound != NULL) {
                     debug("*(bound)");
                     debug(((struct atom *)h)->string);
                     sexp = cons(bound, t); /* pair of a lambda and a list */
                     done = 0; /* "tail call" */
                 } else if (h == cadr) {
+                    struct value *k = eval(head(t), env);
                     debug("*cadr");
-                    struct value *k = eval(head(t), env);
                     return head(tail(k));
                 } else if (h == car) {
+                    struct value *k = eval(head(t), env);
                     debug("*car");
-                    struct value *k = eval(head(t), env);
                     return head(k);
                 } else if (h == cdr) {
+                    struct value *k = eval(head(t), env);
                     debug("*cdr");
-                    struct value *k = eval(head(t), env);
                     return tail(k);
                 } else if (h == cond) {
+                    struct value *branch = head(t);
                     debug("*cond");
-                    struct value *branch = head(t);
                     /* this will error out with car(nil) if no 'else' in cond */
                     while (done) {
                         struct value *test = head(branch);
                         }
                     }
                 } else if (h == cons_) {
-                    debug("*cons");
                     struct value *j = eval(head(t), env);
                     struct value *k = eval(head(tail(t)), env);
+                    debug("*cons");
                     return cons(j, k);
                 } else if (h == equalp) {
-                    debug("*equalp");
                     struct value *j = eval(head(t), env);
                     struct value *k = eval(head(tail(t)), env);
+                    debug("*equalp");
                     if (equal(j, k)) {
                         return truth;
                     } else {
                     debug("*lambda");
                     return lambda(env, head(t), head(tail(t)));
                 } else if (h == let) {
-                    debug("*let*");
                     struct value *pairs = head(t);
                     struct value *body = head(tail(t));
-
+                    debug("*let*");
                     while (pairs != nil) {
                         struct value *pair = head(pairs);
                         struct value *name = head(pair);
                     sexp = body;
                     done = 0; /* "tail call" */
                 } else if (h == listp) {
+                    struct value *k = eval(head(t), env);
                     debug("*list?");
-                    struct value *k = eval(head(t), env);
                     while (k->type == V_CONS) {
                         k = tail(k);
                     }
                         return falsehood;
                     }
                 } else if (h == nullp) {
+                    struct value *k = eval(head(t), env);
                     debug("*null?");
-                    struct value *k = eval(head(t), env);
                     if (k == nil) {
                         return truth;
                     } else {
                         return t;
                     return head(t);
                 } else if (h->type == V_LAMBDA) {
-                    debug("*(lambda)");
                     struct lambda *l = (struct lambda *)h;
                     struct value *formals = l->formals;
                     struct env *l_env = l->env;
+                    debug("*(lambda)");
                     while (t->type == V_CONS) {
                         struct value *formal = head(formals);
                         struct value *value = eval(head(t), env);
                     sexp = l->body;
                     done = 0; /* "tail call" */       
                 } else {
-                    debug("*(inner sexp)*");
                     struct value *k = eval(h, env);
                     struct value *m = cons(eval(k, env), t);
+                    debug("*(inner sexp)*");
                     return eval(m, env);
                 }
                 break;
 #!/bin/sh
 
-cd impl/mignon && make || exit 1
+cd impl/mignon && ANSI=yes make || exit 1
 cd ../..
 cd impl/haney && make || exit 1
 cd ../..
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.