]> git.mdlowis.com Git - proto/obnc.git/commitdiff
cleaned up loops
authormike lowis <mike@mdlowis.com>
Fri, 30 Apr 2021 03:08:22 +0000 (23:08 -0400)
committermike lowis <mike@mdlowis.com>
Fri, 30 Apr 2021 03:08:22 +0000 (23:08 -0400)
cerise/src/grammar.c

index d0f81871b74528176821be3c26a86794f108d560..51b154784492ca83644f09d070070071cde78146 100644 (file)
@@ -282,7 +282,7 @@ RULE(type)
 RULE(var_decl)
 {
     (void)item;
-    while (1)
+    do
     {
         int nsyms = 0;
         Symbol* sym = NULL;
@@ -290,19 +290,15 @@ RULE(var_decl)
         char* name = NULL;
         bool export = false;
 
-        while (1)
+        do
         {
             name = expect_text(p, IDENT);
             export = accept(p, '*');
             sym = symbol_new(p, name, SYM_VAR, export);
             sym->global = 1;
             nsyms++;
-
-            if (!accept(p, ','))
-            {
-                break;
-            }
         }
+        while (accept(p, ','));
 
         expect(p, ':');
         name = expect_text(p, IDENT);
@@ -315,12 +311,8 @@ RULE(var_decl)
             codegen_global(p, sym->name, sym->type);
             sym = sym->next;
         }
-
-        if (!matches(p, IDENT))
-        {
-            break;
-        }
     }
+    while (matches(p, IDENT));
 }
 
 RULE(type_decl)
@@ -329,22 +321,16 @@ RULE(type_decl)
     bool export = false;
     Symbol* sym = NULL;
 
-    while (1)
+    do
     {
         name = expect_text(p, IDENT);
         export = accept(p, '*');
         sym = symbol_new(p, name, SYM_TYPE, export);
         expect(p, '=');
         type(p, item);
-//        expression(p, item);
-//        sym->imm = item->imm;
-//        sym->type = item->type;
-
-        if (!matches(p, IDENT))
-        {
-            break;
-        }
+        sym->type = item->type;
     }
+    while (matches(p, IDENT));
 }
 
 RULE(const_decl)
@@ -353,7 +339,7 @@ RULE(const_decl)
     bool export = false;
     Symbol* sym = NULL;
 
-    while (1)
+    do
     {
         name = expect_text(p, IDENT);
         export = accept(p, '*');
@@ -363,17 +349,13 @@ RULE(const_decl)
         expression(p, item);
         sym->imm = item->imm;
         sym->type = item->type;
-
-        if (!matches(p, IDENT))
-        {
-            break;
-        }
     }
+    while (matches(p, IDENT));
 }
 
 RULE(statement_seq)
 {
-    while (1)
+    do
     {
         if (matches(p, IDENT))
         {
@@ -401,38 +383,45 @@ RULE(statement_seq)
             expect(p, IF);
             expression(p, item);
             check_bool(p, item);
+            // CFJump(item)
             expect(p, THEN);
             statement_seq(p, &(Item){0});
+            // L = 0
             while (accept(p, ELSIF))
             {
+                // FJump(L)
+                // FixLink(item->imm.i)
                 expression(p, item);
                 check_bool(p, item);
+                // CFJump(item)
                 expect(p, THEN);
                 statement_seq(p, &(Item){0});
             }
             if (accept(p, ELSE))
             {
+                // FJump(L)
+                // FixLink(item->imm.i)
                 statement_seq(p, &(Item){0});
             }
+            else
+            {
+                // FixLink(item->imm.i)
+            }
             expect(p, END);
         }
         else
         {
             error(p, "expected a statement");
         }
-
-        if (matches(p, END) || matches(p, ELSE) || matches(p, ELSIF))
-        {
-            break;
-        }
     }
+    while (!matches(p, END) && !matches(p, ELSE) && !matches(p, ELSIF));
 }
 
 RULE(import_list)
 {
     (void)item;
     expect(p, IMPORT);
-    while (1)
+    do
     {
         Module* m = calloc(1, sizeof(Module));
         m->name = expect_text(p, IDENT);
@@ -443,12 +432,8 @@ RULE(import_list)
             m->next    = p->imports;
             p->imports = m;
         }
-
-        if (!matches(p, IDENT))
-        {
-            break;
-        }
     }
+    while (matches(p, IDENT));
 
     /* reverse the list so when we init it happens in the right order */
     Module* imports = p->imports;