shithub: mc

Download patch

ref: c98afde323137b801e18e42c3cb99fb51b1d6011
parent: 9220a5e91430f73453e50cc48ffee026587e0e53
author: Ori Bernstein <[email protected]>
date: Thu Jun 7 14:56:35 EDT 2012

Move debug pickling dump out of the compiler.

    We'll put it in the usefile generator.

--- a/8/main.c
+++ b/8/main.c
@@ -28,9 +28,7 @@
 {
     int opt;
     int i;
-    Node *rdback;
     Stab *globls;
-    FILE *tmp;
 
     while ((opt = getopt(argc, argv, "dho:")) != -1) {
         switch (opt) {
@@ -57,28 +55,13 @@
         file->file.globls = globls;
         yyparse();
 
-        if (debug) {
-            /* before we do anything to the parse */
+        /* before we do anything to the parse */
+        if (debug)
             dump(file, stdout);
-        }
-
         infer(file);
-
-        if (debug) {
-            /* test storing tree to file */
-            tmp = fopen("a.pkl", "w");
-            pickle(file, tmp);
-            fclose(tmp);
-
-            /* and reading it back */
-            tmp = fopen("a.pkl", "r");
-            rdback = unpickle(tmp);
-            dump(rdback, stdout);
-            fclose(tmp);
-
-            /* after all processing */
+        /* after all processing */
+        if (debug)
             dump(file, stdout);
-        }
         gen(file, "a.s");
     }
 
--- a/8/reduce.c
+++ b/8/reduce.c
@@ -183,7 +183,7 @@
 }
 
 void jmp(Simp *s, Node *lbl) { append(s, mkexpr(-1, Ojmp, lbl, NULL)); }
-Node *store(Node *t, Node *n) { return mkexpr(-1, Ostor, t, n, NULL); }
+Node *store(Node *dst, Node *src) { return mkexpr(-1, Ostor, dst, src, NULL); }
 
 void cjmp(Simp *s, Node *cond, Node *iftrue, Node *iffalse)
 {
@@ -350,6 +350,27 @@
     return r;
 }
 
+Node *simplazy(Simp *s, Node *n, Node *r)
+{
+    Node *a, *b;
+    Node *next;
+    Node *end;
+
+    next = genlbl();
+    end = genlbl();
+    a = rval(s, n->expr.args[0]);
+    append(s, store(r, a));
+    if (exprop(n) == Oland)
+        cjmp(s, a, next, end);
+    else if (exprop(n) == Olor)
+        cjmp(s, a, end, next);
+    append(s, next);
+    b = rval(s, n->expr.args[1]);
+    append(s, store(r, b));
+    append(s, end);
+    return r;
+}
+
 Node *rval(Simp *s, Node *n)
 {
     Node *r; /* expression result */
@@ -376,7 +397,8 @@
     switch (exprop(n)) {
         case Obad:
         case Olor: case Oland:
-            die("Have not implemented lowering op %s", opstr(exprop(n)));
+            r = temp(s, n);
+            simplazy(s, n, r);
             break;
         case Osize:
             r = mkexpr(-1, Olit, mkint(-1, size(args[0])), NULL);
--- a/muse/main.c
+++ b/muse/main.c
@@ -28,6 +28,8 @@
     int opt;
     int i;
     Stab *globls;
+    Node *rdback;
+    FILE *tmp;
 
     while ((opt = getopt(argc, argv, "dho:")) != -1) {
         switch (opt) {
@@ -55,6 +57,17 @@
         yyparse();
 
         if (debug) {
+            /* test storing tree to file */
+            tmp = fopen("a.pkl", "w");
+            pickle(file, tmp);
+            fclose(tmp);
+
+            /* and reading it back */
+            tmp = fopen("a.pkl", "r");
+            rdback = unpickle(tmp);
+            dump(rdback, stdout);
+            fclose(tmp);
+
             /* before we do anything to the parse */
             dump(file, stdout);
         }
--- a/test/tests
+++ b/test/tests
@@ -13,3 +13,5 @@
 slice	E	7
 float   E       1
 structasn       E       42
+log-and E       0
+log-or  E       1