txlyre 2 天之前
父节点
当前提交
b2bc2a3062
共有 1 个文件被更改,包括 22 次插入4 次删除
  1. 22 4
      qic.c

+ 22 - 4
qic.c

@@ -4,6 +4,8 @@
 #include <stdlib.h>
 #include <string.h>
 
+#define QIC_VERSION "qic v01 " __DATE__
+
 size_t GID = 0;
 
 typedef struct {
@@ -1911,8 +1913,8 @@ node_t *parse_stmt(list_t *tokens, size_t *pos) {
 
       char *k = ((token_t *)tokens->data[(*pos)++])->text;
 
-      if (!(k[0] >= 'A' && k[0] <= 'Z'))
-        PARSE_ERROR("compile-time constant identifiers must begin with an uppercase letter, but '%s' does not", k);
+      if (k[0] != '_' && !(k[0] >= 'A' && k[0] <= 'Z'))
+        PARSE_ERROR("compile-time constant identifiers must begin with an uppercase letter or with an underscore, but '%s' does not", k);
 
       if (table_get(h, k))
         PARSE_ERROR("duplicated compile-time constant definition: '%s'", k);
@@ -4558,6 +4560,8 @@ char *escape(char *s) {
   return buffer_read(buf);
 }
 
+int NOSTD = 0;
+
 char *compile(char *source, list_t *required) {
   list_t *ctx = list_new();
   table_t *ltab = table_new();
@@ -4569,7 +4573,10 @@ char *compile(char *source, list_t *required) {
   buffer_t *gbuf = buffer_new();
   buffer_t *buf = buffer_new();
 
-  require_once(gbuf, buf, ctx, ltab, lstk, sstk, lbl, "std");
+  compile_into("const __QIC = \"" QIC_VERSION "\"", gbuf, buf, ctx, ltab, lstk, sstk, lbl);
+
+  if (!NOSTD)
+    require_once(gbuf, buf, ctx, ltab, lstk, sstk, lbl, "std");
 
   if (required && required->length)
     for (size_t i = 0; i < required->length; i++)
@@ -4671,7 +4678,18 @@ int main(int argc, char **argv) {
         DEBUG = 1;
       else if (strcmp(argv[i], "-s") == 0 || strcmp(argv[i], "--stdin") == 0)
         readstdin = 1;
-      else {
+      else if (strcmp(argv[i], "-N") == 0 || strcmp(argv[i], "--no-std") == 0)
+        NOSTD = 1;
+      else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "-?") == 0 || strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0) {
+        fprintf(stderr, "qilang compiler, " QIC_VERSION "\n");
+        fprintf(stderr, "usage: %s [-dsh] [input0.qi input1.qi ... inputN.qi]\n", argv[0]);
+        fprintf(stderr, "-h --help\tprint this message and exit\n");
+        fprintf(stderr, "-d --debug\tenable debug mode\n");
+        fprintf(stderr, "-s --stdin\tread stdin as input\n");
+        fprintf(stderr, "-N --no-std\tdont automatically require std\n");
+
+        return 0;
+      } else {
         fprintf(stderr, "fatal: unknown commandline argument: '%s'\n", argv[i]);
 
         return 1;