txlyre 1 giorno fa
parent
commit
93baa57982
1 ha cambiato i file con 17 aggiunte e 0 eliminazioni
  1. 17 0
      qic.c

+ 17 - 0
qic.c

@@ -325,6 +325,7 @@ typedef struct {
     T_STARSTARASSIGN,
     T_BARASSIGN,
     T_ANDASSIGN,
+    T_RAISEASSIGN,
     T_BARBAR,
     T_ANDAND,
     T_STARSTAR,
@@ -679,6 +680,8 @@ token_t *next_token(char *source, size_t *pos) {
     return TK(BARASSIGN);
   else if (strncmp(&source[*pos], "&=", 2) == 0 && ++(*pos) && ++(*pos))
     return TK(ANDASSIGN);
+  else if (strncmp(&source[*pos], "^=", 2) == 0 && ++(*pos) && ++(*pos))
+    return TK(RAISEASSIGN);
   else if (strncmp(&source[*pos], "||", 2) == 0 && ++(*pos) && ++(*pos))
     return TK(BARBAR);
   else if (strncmp(&source[*pos], "&&", 2) == 0 && ++(*pos) && ++(*pos))
@@ -823,6 +826,7 @@ struct _node_t {
     N_ASSIGN_POW,
     N_ASSIGN_BOR,
     N_ASSIGN_BAND,
+    N_ASSIGN_XOR,
 
     N_EQUALS,
     N_NOTEQUALS,
@@ -1633,6 +1637,14 @@ node_t *parse_assignment(list_t *tokens, size_t *pos) {
     node_t *b = parse_assignment(tokens, pos);
 
     return NODE2(ASSIGN_BOR, a, b);
+  } else if (MATCH(ANDASSIGN)) {
+    node_t *b = parse_assignment(tokens, pos);
+
+    return NODE2(ASSIGN_BAND, a, b);
+  } else if (MATCH(RAISEASSIGN)) {
+    node_t *b = parse_assignment(tokens, pos);
+
+    return NODE2(ASSIGN_XOR, a, b);
   }
 
   return a;
@@ -3796,6 +3808,7 @@ void compile_node(buffer_t *gbuf, buffer_t *buf, list_t *ctx, table_t *ltab, sta
     case N_ASSIGN_POW: COMPASSIGN(node->a, "pow", compile_node(gbuf, buf, ctx, ltab, lstk, sstk, lbl, node->b)); break;
     case N_ASSIGN_BOR: COMPASSIGN(node->a, "bor", compile_node(gbuf, buf, ctx, ltab, lstk, sstk, lbl, node->b)); break;
     case N_ASSIGN_BAND: COMPASSIGN(node->a, "band", compile_node(gbuf, buf, ctx, ltab, lstk, sstk, lbl, node->b)); break;
+    case N_ASSIGN_XOR: COMPASSIGN(node->a, "xor", compile_node(gbuf, buf, ctx, ltab, lstk, sstk, lbl, node->b)); break;
 
     case N_INC: 
       COMPASSIGN(node->a, "add", EMIT("state->one"));
@@ -4342,6 +4355,10 @@ char *compile(char *source) {
   buffer_appends(rbuf, "int main(int argc, char **argv) {\n");
   buffer_appends(rbuf, "qi_state_t *state;\n");
   buffer_appends(rbuf, "qi_state_init(&state);\n");
+  buffer_appends(rbuf, "qi_list_t *args = qi_list_make();\n");
+  buffer_appends(rbuf, "for (int i = 0; i < argc; i++)\n");
+  buffer_appends(rbuf, "  qi_list_push(args, qi_make_string(state, argv[i]));\n");
+  buffer_appends(rbuf, "qi_decl_const(state, \"ARGS\", qi_make_list(state, args));\n");
   buffer_appendb(rbuf, buf);
   buffer_appends(rbuf, "qi_old_scope(state);\n");
   buffer_appends(rbuf, "qi_finalize();\n");