txlyre 2 weeks ago
parent
commit
3bd29fdd30
1 changed files with 48 additions and 27 deletions
  1. 48 27
      qic.c

+ 48 - 27
qic.c

@@ -623,8 +623,10 @@ token_t *tokenize_string(char *source, size_t *pos, size_t *size) {
 
 
         hx = 1;
         hx = 1;
 
 
-        if (size) (*size)++;
-      } continue;
+        if (size)
+          (*size)++;
+      }
+        continue;
 
 
       case 'n':
       case 'n':
         buffer_appends(text, "\\n");
         buffer_appends(text, "\\n");
@@ -679,7 +681,8 @@ token_t *tokenize_string(char *source, size_t *pos, size_t *size) {
 
 
             hx = 1;
             hx = 1;
 
 
-            if (size) (*size)++;
+            if (size)
+              (*size)++;
 
 
             continue;
             continue;
           }
           }
@@ -689,8 +692,10 @@ token_t *tokenize_string(char *source, size_t *pos, size_t *size) {
         break;
         break;
       }
       }
 
 
-      if (hx) hx = 0;
-      if (size) (*size)++;
+      if (hx)
+        hx = 0;
+      if (size)
+        (*size)++;
 
 
       continue;
       continue;
     }
     }
@@ -700,12 +705,14 @@ token_t *tokenize_string(char *source, size_t *pos, size_t *size) {
     else if (c == '\n') {
     else if (c == '\n') {
       buffer_appends(text, "\\n");
       buffer_appends(text, "\\n");
 
 
-      if (size) (*size)++;
+      if (size)
+        (*size)++;
 
 
       continue;
       continue;
     }
     }
 
 
-    if (size) (*size)++;
+    if (size)
+      (*size)++;
 
 
     if (hx) {
     if (hx) {
       hx = 0;
       hx = 0;
@@ -1607,9 +1614,11 @@ node_t *parse_primary(list_t *tokens, size_t *pos) {
         EXPECT(OF, "of");
         EXPECT(OF, "of");
 
 
         if (is_var)
         if (is_var)
-          loop = NODE2l(FOROFVARUNPACK, parse_expr(tokens, pos), NODEL(LIST, a), l);
+          loop = NODE2l(FOROFVARUNPACK, parse_expr(tokens, pos), NODEL(LIST, a),
+                        l);
         else
         else
-          loop = NODE2l(FOROFUNPACK, parse_expr(tokens, pos), NODEL(LIST, a), l);
+          loop =
+              NODE2l(FOROFUNPACK, parse_expr(tokens, pos), NODEL(LIST, a), l);
       } else {
       } else {
         if (!AT(NAME))
         if (!AT(NAME))
           PARSE_ERROR("expected identifier");
           PARSE_ERROR("expected identifier");
@@ -1674,9 +1683,11 @@ node_t *parse_primary(list_t *tokens, size_t *pos) {
         EXPECT(OF, "of");
         EXPECT(OF, "of");
 
 
         if (is_var)
         if (is_var)
-          loop = NODE2l(FOROFVARUNPACK, parse_expr(tokens, pos), NODEL(LIST, pairs), l);
+          loop = NODE2l(FOROFVARUNPACK, parse_expr(tokens, pos),
+                        NODEL(LIST, pairs), l);
         else
         else
-          loop = NODE2l(FOROFUNPACK, parse_expr(tokens, pos), NODEL(LIST, pairs), l);
+          loop = NODE2l(FOROFUNPACK, parse_expr(tokens, pos),
+                        NODEL(LIST, pairs), l);
       } else {
       } else {
         if (!AT(NAME))
         if (!AT(NAME))
           PARSE_ERROR("expected identifier");
           PARSE_ERROR("expected identifier");
@@ -1686,7 +1697,8 @@ node_t *parse_primary(list_t *tokens, size_t *pos) {
         EXPECT(OF, "of");
         EXPECT(OF, "of");
 
 
         if (is_var)
         if (is_var)
-          loop = NODE2t(FOROFVAR, parse_expr(tokens, pos), NODEL(LIST, pairs), t);
+          loop =
+              NODE2t(FOROFVAR, parse_expr(tokens, pos), NODEL(LIST, pairs), t);
         else
         else
           loop = NODE2t(FOROF, parse_expr(tokens, pos), NODEL(LIST, pairs), t);
           loop = NODE2t(FOROF, parse_expr(tokens, pos), NODEL(LIST, pairs), t);
       }
       }
@@ -1702,8 +1714,8 @@ node_t *parse_primary(list_t *tokens, size_t *pos) {
 
 
     return NODEL(TABLE, pairs);
     return NODEL(TABLE, pairs);
   } else if (MATCH(NUMBER) || MATCH(STRING) || MATCH(FSTRING) ||
   } else if (MATCH(NUMBER) || MATCH(STRING) || MATCH(FSTRING) ||
-             MATCH(USTRING) || MATCH(BSTRING) || MATCH(NAME) || MATCH(TRUE) || MATCH(FALSE) ||
-             MATCH(NIL))
+             MATCH(USTRING) || MATCH(BSTRING) || MATCH(NAME) || MATCH(TRUE) ||
+             MATCH(FALSE) || MATCH(NIL))
     return NODET(LITERAL, tokens->data[(*pos) - 1]);
     return NODET(LITERAL, tokens->data[(*pos) - 1]);
 
 
   if (MATCH(RPAR)) {
   if (MATCH(RPAR)) {
@@ -3401,7 +3413,7 @@ void compile_pairs(buffer_t *gbuf, buffer_t *buf, list_t *ctx, table_t *ltab,
   for (size_t i = 0; i < pairs->length; i++) {
   for (size_t i = 0; i < pairs->length; i++) {
     list_t *pair = pairs->data[i];
     list_t *pair = pairs->data[i];
 
 
-    buffer_fmt(tbuf, "qi_table_set(table, qi_to_string(state, ");   
+    buffer_fmt(tbuf, "qi_table_set(table, qi_to_string(state, ");
     compile_node(gbuf, tbuf, ctx, ltab, lstk, sstk, lbl, pair->data[0]);
     compile_node(gbuf, tbuf, ctx, ltab, lstk, sstk, lbl, pair->data[0]);
     buffer_fmt(tbuf, ")->value.string, ");
     buffer_fmt(tbuf, ")->value.string, ");
     compile_node(gbuf, tbuf, ctx, ltab, lstk, sstk, lbl, pair->data[1]);
     compile_node(gbuf, tbuf, ctx, ltab, lstk, sstk, lbl, pair->data[1]);
@@ -4146,8 +4158,10 @@ const char *STD[][2] = {
      "header `#endif`\n"
      "header `#endif`\n"
      "func system(s) {\n"
      "func system(s) {\n"
      "  if type(s) != \"string\"\n"
      "  if type(s) != \"string\"\n"
-     "    throw \"expected first argument to be: string, but got: \" + type(s)\n"
-     "  inline `return qi_make_number(state, system(qi_get(state, \"s\")->value.string))`"
+     "    throw \"expected first argument to be: string, but got: \" + "
+     "type(s)\n"
+     "  inline `return qi_make_number(state, system(qi_get(state, "
+     "\"s\")->value.string))`"
      "}\n"
      "}\n"
      "func getenv(n) {\n"
      "func getenv(n) {\n"
      "  if type(n) != \"string\"\n"
      "  if type(n) != \"string\"\n"
@@ -4348,7 +4362,7 @@ char *unescape(char *s) {
 
 
       case 'r':
       case 'r':
         buffer_append(buf, '\r');
         buffer_append(buf, '\r');
-        break;    
+        break;
 
 
       default:
       default:
         buffer_append(buf, nc);
         buffer_append(buf, nc);
@@ -4395,7 +4409,10 @@ int require_once(buffer_t *gbuf, buffer_t *buf, list_t *ctx, table_t *ltab,
         snprintf(tmp, sizeof(tmp), "%s/%s", n, path);
         snprintf(tmp, sizeof(tmp), "%s/%s", n, path);
 
 
         fd = fopen(tmp, "rb");
         fd = fopen(tmp, "rb");
-        if (fd) { path = strdup(tmp); break; } 
+        if (fd) {
+          path = strdup(tmp);
+          break;
+        }
       }
       }
 
 
       if (!fd)
       if (!fd)
@@ -5118,7 +5135,8 @@ node_t *_expand_mvars(node_t *node, int expr, mvar_expand_err_t *err) {
 
 
     return node;
     return node;
   } else if ((node->tag >= N_ADD && node->tag <= N_BAND) ||
   } else if ((node->tag >= N_ADD && node->tag <= N_BAND) ||
-             (node->tag >= N_ASSIGN && node->tag <= N_ASSIGN_SHR) || node->tag == N_DECL) {
+             (node->tag >= N_ASSIGN && node->tag <= N_ASSIGN_SHR) ||
+             node->tag == N_DECL) {
     node = node_copy(node);
     node = node_copy(node);
 
 
     node->a = _expand_mvars(node->a, 1, err);
     node->a = _expand_mvars(node->a, 1, err);
@@ -5481,7 +5499,8 @@ void compile_node(buffer_t *gbuf, buffer_t *buf, list_t *ctx, table_t *ltab,
       break;
       break;
 
 
     case T_BSTRING:
     case T_BSTRING:
-      EMIT("qi_make_bytes(state, (unsigned char *)\"%s\", %d)", node->t->text, node->t->z);
+      EMIT("qi_make_bytes(state, (unsigned char *)\"%s\", %d)", node->t->text,
+           node->t->z);
       break;
       break;
 
 
     case T_NAME: {
     case T_NAME: {
@@ -5596,7 +5615,7 @@ void compile_node(buffer_t *gbuf, buffer_t *buf, list_t *ctx, table_t *ltab,
     for (size_t i = 0; i < node->a->b->l->length; i++) {
     for (size_t i = 0; i < node->a->b->l->length; i++) {
       list_t *pair = node->a->b->l->data[i];
       list_t *pair = node->a->b->l->data[i];
 
 
-      buffer_fmt(bbuf, "qi_table_set(table, qi_to_string(state, ");   
+      buffer_fmt(bbuf, "qi_table_set(table, qi_to_string(state, ");
       compile_node(gbuf, bbuf, ctx, ltab, lstk, sstk, lbl, pair->data[0]);
       compile_node(gbuf, bbuf, ctx, ltab, lstk, sstk, lbl, pair->data[0]);
       buffer_fmt(bbuf, ")->value.string, ");
       buffer_fmt(bbuf, ")->value.string, ");
       compile_node(gbuf, bbuf, ctx, ltab, lstk, sstk, lbl, pair->data[1]);
       compile_node(gbuf, bbuf, ctx, ltab, lstk, sstk, lbl, pair->data[1]);
@@ -5815,9 +5834,11 @@ void compile_node(buffer_t *gbuf, buffer_t *buf, list_t *ctx, table_t *ltab,
     }
     }
 
 
     if (node->tag == N_DECL) {
     if (node->tag == N_DECL) {
-      DECL(node->a, compile_node(gbuf, buf, ctx, ltab, lstk, sstk, lbl, node->b));
+      DECL(node->a,
+           compile_node(gbuf, buf, ctx, ltab, lstk, sstk, lbl, node->b));
     } else {
     } else {
-      ASSIGN(node->a, compile_node(gbuf, buf, ctx, ltab, lstk, sstk, lbl, node->b));
+      ASSIGN(node->a,
+             compile_node(gbuf, buf, ctx, ltab, lstk, sstk, lbl, node->b));
     }
     }
     break;
     break;
 
 
@@ -6459,7 +6480,7 @@ void compile_node(buffer_t *gbuf, buffer_t *buf, list_t *ctx, table_t *ltab,
     buffer_fmt(tbuf, ";\n}, {\n");
     buffer_fmt(tbuf, ";\n}, {\n");
     buffer_fmt(tbuf, "%s = trap->value;\n", varname2);
     buffer_fmt(tbuf, "%s = trap->value;\n", varname2);
     buffer_fmt(tbuf, "}, NULL);\n");
     buffer_fmt(tbuf, "}, NULL);\n");
-   
+
     char *varname3 = tempvar();
     char *varname3 = tempvar();
     buffer_fmt(tbuf, "qi_list_t *%s = qi_list_make_n(2);\n", varname3);
     buffer_fmt(tbuf, "qi_list_t *%s = qi_list_make_n(2);\n", varname3);
     buffer_fmt(tbuf, "qi_list_data(%s, 0) = %s;\n", varname3, varname1);
     buffer_fmt(tbuf, "qi_list_data(%s, 0) = %s;\n", varname3, varname1);
@@ -6470,7 +6491,7 @@ void compile_node(buffer_t *gbuf, buffer_t *buf, list_t *ctx, table_t *ltab,
     buffer_appendb(gbuf, tbuf);
     buffer_appendb(gbuf, tbuf);
 
 
     EMIT("__%s%d(state)", PREFIX, gid);
     EMIT("__%s%d(state)", PREFIX, gid);
-    } break;
+  } break;
 
 
   case N_LABEL: {
   case N_LABEL: {
     int_stack_t *pair = table_get(list_index(lbl, -1), node->t->text);
     int_stack_t *pair = table_get(list_index(lbl, -1), node->t->text);
@@ -6557,7 +6578,7 @@ void compile_node(buffer_t *gbuf, buffer_t *buf, list_t *ctx, table_t *ltab,
     buffer_appendb(gbuf, tbuf);
     buffer_appendb(gbuf, tbuf);
 
 
     EMIT("__%s%d(state)", PREFIX, gid);
     EMIT("__%s%d(state)", PREFIX, gid);
-    } break;
+  } break;
 
 
   case N_FUNCEXPR:
   case N_FUNCEXPR:
     compile_func(gbuf, buf, ctx, ltab, lstk, sstk, lbl, node, NULL);
     compile_func(gbuf, buf, ctx, ltab, lstk, sstk, lbl, node, NULL);