Browse Source

fixes for gcc

txlyre 1 day ago
parent
commit
b42a221401
2 changed files with 41 additions and 30 deletions
  1. 1 0
      .gitignore
  2. 40 30
      qic.c

+ 1 - 0
.gitignore

@@ -1,2 +1,3 @@
 qic
+qic.exe
 *.qi

+ 40 - 30
qic.c

@@ -6,13 +6,13 @@
 #include <time.h>
 
 #if defined(_WIN32) || defined(_WIN64)
-#  define ON_WINDOWS
-#  include <windows.h>
-#  undef TRUE
-#  undef FALSE
+#define ON_WINDOWS
+#include <windows.h>
+#undef TRUE
+#undef FALSE
 #else
-#  define ON_POSIX
-#  include <sys/stat.h>
+#define ON_POSIX
+#include <sys/stat.h>
 #endif
 
 int is_directory(char *path)
@@ -33,7 +33,7 @@ int is_directory(char *path)
 }
 
 #ifdef ON_WINDOWS
-#  define realpath(p, fp) (_fullpath((fp), (p), 0))
+#define realpath(p, fp) (_fullpath((fp), (p), 0))
 #endif
 
 #define __STR0(x) #x
@@ -1671,7 +1671,7 @@ list_t *MACROS;
 #define ATP(tk, p)                \
   ((*pos) + p < tokens->length && \
    ((token_t *)tokens->data[(*pos) + p])->tag == T_##tk)
-#define MATCH(tk) (AT(tk) && ++(*pos))
+#define MATCH(tk) ((*pos < tokens->length && ((token_t *)tokens->data[*pos])->tag == T_##tk) && ++(*pos))
 #define PARSE_ERROR(fmt, ...)                                                  \
   {                                                                            \
     format_error(                                                              \
@@ -1683,10 +1683,10 @@ list_t *MACROS;
         ##__VA_ARGS__);                                                        \
     exit(1);                                                                   \
   }
-#define EXPECT(tk, s)                  \
-  {                                    \
-    if (!MATCH(tk))                    \
-      PARSE_ERROR("expected %s", (s)); \
+#define EXPECT(tk, s)                                                                             \
+  {                                                                                               \
+    if (!((*pos < tokens->length && ((token_t *)tokens->data[*pos])->tag == T_##tk) && ++(*pos))) \
+      PARSE_ERROR("expected %s", (s));                                                            \
   }
 
 node_t *parse_expr(list_t *tokens, size_t *pos);
@@ -4242,7 +4242,9 @@ void compile_block(buffer_t *gbuf, buffer_t *buf, list_t *ctx, table_t *ltab,
           snprintf(buf, sizeof(buf), "%zu", k++);
 
           v = nodet(N_LITERAL, token(T_NUMBER, strdup(buf)));
-        } else k++;
+        }
+        else
+          k++;
 
         if (!const_set(name, v))
           COMPILE_ERROR("redeclaration of compile-time constant: '%s'", name);
@@ -4998,7 +5000,7 @@ int require_once(buffer_t *gbuf, buffer_t *buf, list_t *ctx, table_t *ltab,
                  list_t *lstk, list_t *sstk, list_t *lbl, char *path)
 {
   char tmp[512];
-          
+
   char *source = NULL;
 
   if (is_required(path))
@@ -5013,18 +5015,20 @@ int require_once(buffer_t *gbuf, buffer_t *buf, list_t *ctx, table_t *ltab,
       break;
     }
   }
-  
+
   if (!source)
   {
     FILE *fd;
-    
-    if (is_directory(path)) {
+
+    if (is_directory(path))
+    {
       snprintf(tmp, sizeof(tmp), "%s/main.qi", path);
 
       fd = fopen(tmp, "rb");
-      if (fd) {
+      if (fd)
+      {
         path = strdup(tmp);
-        
+
         goto pass;
       }
     }
@@ -5054,15 +5058,16 @@ int require_once(buffer_t *gbuf, buffer_t *buf, list_t *ctx, table_t *ltab,
         return -1;
     }
 
-pass:
+  pass:
     path = realpath(path, NULL);
 
-    if (is_required(path)) {
+    if (is_required(path))
+    {
       fclose(fd);
 
       return 1;
     }
-    
+
     buffer_t *fbuf = buffer_new();
 
     for (;;)
@@ -5991,9 +5996,10 @@ node_t *_expand_mvars(node_t *node, int expr, mvar_expand_err_t *err)
 
     return node;
   }
-  else if (node->tag == N_TRY) {
+  else if (node->tag == N_TRY)
+  {
     node = node_copy(node);
-    
+
     node->a = _expand_mvars(node->a, node->a->tag != N_PROGRAM, err);
     if (err->code != 0)
       return NULL;
@@ -7665,7 +7671,8 @@ void compile_node(buffer_t *gbuf, buffer_t *buf, list_t *ctx, table_t *ltab,
     {
       EMIT("%s", text);
     }
-    else if (text[0] && (text[strlen(text) - 1] == '{' || text[strlen(text) - 1] == '}')) {
+    else if (text[0] && (text[strlen(text) - 1] == '{' || text[strlen(text) - 1] == '}'))
+    {
       EMIT("%s", text);
     }
     else
@@ -7777,7 +7784,7 @@ char *compile(char *source, list_t *required)
   buffer_fmt(rbuf, "  fprintf(stderr, \"fatal: unsupported libqirt version\\n\");\n");
   buffer_fmt(rbuf, "  abort();\n");
   buffer_fmt(rbuf, "}\n\n");
-  
+
   buffer_appends(rbuf, "qi_state_t *state;\n");
 
   if (DEBUG)
@@ -7853,7 +7860,7 @@ int main(int argc, char **argv)
   genmathlib();
 
   char tmp[512];
-  
+
   char *out;
   char *main = NULL;
   char *outf = NULL;
@@ -7951,12 +7958,15 @@ int main(int argc, char **argv)
   else
   {
     FILE *fd;
-    if (is_directory(main)) {
+    if (is_directory(main))
+    {
       snprintf(tmp, sizeof(tmp), "%s/main.qi", main);
 
       fd = fopen(tmp, "rb");
-    } else fd = fopen(main, "rb");
-    
+    }
+    else
+      fd = fopen(main, "rb");
+
     if (!fd)
     {
       fprintf(stderr, "fatal: unable to open file: '%s'\n", main);