Browse Source

Sol Part 45: I Just Don't Even!

Michael Hrcek 5 years ago
parent
commit
62b0048b40
12 changed files with 5398 additions and 4949 deletions
  1. 1
    1
      ast.h
  2. 5
    1
      astprint.c
  3. 10
    0
      builtins.c
  4. 113
    106
      lex.yy.c
  5. 4733
    4347
      parser.output
  6. 514
    492
      parser.tab.c
  7. 2
    1
      parser.tab.h
  8. 8
    1
      parser.y
  9. 4
    0
      runtime.c
  10. 3
    0
      sol.h
  11. 3
    0
      state.c
  12. 2
    0
      tokenizer.lex

+ 1
- 1
ast.h View File

@@ -26,7 +26,7 @@ typedef struct {
26 26
 	};
27 27
 } lit_node;
28 28
 
29
-typedef enum {OP_ADD, OP_SUB, OP_MUL, OP_DIV, OP_MOD, OP_POW, OP_BAND, OP_BOR, OP_BXOR, OP_LAND, OP_LOR, OP_EQUAL, OP_NEQUAL, OP_LESS, OP_GREATER, OP_LESSEQ, OP_GREATEREQ, OP_LSHIFT, OP_RSHIFT} binop_t;
29
+typedef enum {OP_ADD, OP_SUB, OP_MUL, OP_DIV, OP_MOD, OP_POW, OP_BAND, OP_BOR, OP_BXOR, OP_LAND, OP_LOR, OP_EQUAL, OP_NEQUAL, OP_LESS, OP_GREATER, OP_LESSEQ, OP_GREATEREQ, OP_LSHIFT, OP_RSHIFT, OP_TBANG} binop_t;
30 30
 typedef struct {
31 31
 	binop_t type;
32 32
 	expr_node *left;

+ 5
- 1
astprint.c View File

@@ -138,6 +138,10 @@ void prex(sol_state_t *state, expr_node *node, int lev) {
138 138
 					prlev(state, lev, "Op: **");
139 139
 					break;
140 140
 
141
+				case OP_TBANG:
142
+					prlev(state, lev, "Op: !!!");
143
+					break;
144
+
141 145
 				case OP_BAND:
142 146
 					prlev(state, lev, "Op: &");
143 147
 					break;
@@ -161,7 +165,7 @@ void prex(sol_state_t *state, expr_node *node, int lev) {
161 165
 				case OP_EQUAL:
162 166
 					prlev(state, lev, "Op: ==");
163 167
 					break;
164
-					
168
+
165 169
 				case OP_NEQUAL:
166 170
 					prlev(state, lev, "Op: !=");
167 171
 					break;

+ 10
- 0
builtins.c View File

@@ -55,6 +55,16 @@ sol_object_t *sol_f_default_repr(sol_state_t *state, sol_object_t *args) {
55 55
 	return res;
56 56
 }
57 57
 
58
+sol_object_t *sol_f_tbang(sol_state_t *state, sol_object_t *args) {
59
+	sol_object_t *a = sol_list_get_index(state, args, 0), *b = sol_list_get_index(state, args, 1);
60
+	sol_object_t c = *b;
61
+	*b = *a;
62
+	*a = c;
63
+	sol_obj_free(a);
64
+	sol_obj_free(b);
65
+	return sol_incref(state->None);
66
+}
67
+
58 68
 sol_object_t *sol_f_no_op(sol_state_t *state, sol_object_t *args) {
59 69
 	if(state) {
60 70
 		return sol_incref(state->None);

+ 113
- 106
lex.yy.c View File

@@ -369,8 +369,8 @@ static void yy_fatal_error (yyconst char msg[]  );
369 369
 	*yy_cp = '\0'; \
370 370
 	(yy_c_buf_p) = yy_cp;
371 371
 
372
-#define YY_NUM_RULES 71
373
-#define YY_END_OF_BUFFER 72
372
+#define YY_NUM_RULES 72
373
+#define YY_END_OF_BUFFER 73
374 374
 /* This struct is not used in this scanner,
375 375
    but its presence is necessary. */
376 376
 struct yy_trans_info
@@ -378,24 +378,24 @@ struct yy_trans_info
378 378
 	flex_int32_t yy_verify;
379 379
 	flex_int32_t yy_nxt;
380 380
 	};
381
-static yyconst flex_int16_t yy_accept[146] =
381
+static yyconst flex_int16_t yy_accept[148] =
382 382
     {   0,
383
-        0,    0,   72,   71,   70,   34,   71,   67,   23,   26,
384
-       71,   61,   62,   21,   19,   66,   20,   63,   22,    2,
385
-       64,   65,   51,   40,   52,   68,   68,   68,   68,   59,
386
-       60,   28,   68,   68,   68,   68,   68,   68,   68,   68,
387
-       68,   68,   68,   68,   68,   68,   57,   27,   58,   29,
388
-       70,   50,    0,    3,   30,   46,    0,    4,   25,   43,
389
-       41,    0,   42,   44,    1,    2,   56,   53,   49,   54,
390
-       55,   68,   68,   68,   68,   48,   68,   68,   68,   11,
391
-       68,   68,   68,   68,   68,    5,   10,   68,   68,   68,
392
-       33,   68,   68,   68,   68,   47,   32,   45,    0,   69,
393
-
394
-        1,   68,   68,   68,   31,   68,   68,   68,   17,   68,
395
-        9,   68,   68,   24,   35,   68,   68,   68,   68,   68,
396
-       18,   37,   68,   68,    7,   68,   12,   68,   68,    6,
397
-       36,   68,   39,   15,   68,   38,   68,   68,    8,   68,
398
-       13,   14,   68,   16,    0
383
+        0,    0,   73,   72,   71,   34,   72,   67,   23,   26,
384
+       72,   61,   62,   21,   19,   66,   20,   63,   22,    2,
385
+       64,   65,   51,   40,   52,   69,   69,   69,   69,   59,
386
+       60,   28,   69,   69,   69,   69,   69,   69,   69,   69,
387
+       69,   69,   69,   69,   69,   69,   57,   27,   58,   29,
388
+       71,    0,   50,    0,    3,   30,   46,    0,    4,   25,
389
+       43,   41,    0,   42,   44,    1,    2,   56,   53,   49,
390
+       54,   55,   69,   69,   69,   69,   48,   69,   69,   69,
391
+       11,   69,   69,   69,   69,   69,    5,   10,   69,   69,
392
+       69,   33,   69,   69,   69,   69,   47,   32,   68,   45,
393
+
394
+        0,   70,    1,   69,   69,   69,   31,   69,   69,   69,
395
+       17,   69,    9,   69,   69,   24,   35,   69,   69,   69,
396
+       69,   69,   18,   37,   69,   69,    7,   69,   12,   69,
397
+       69,    6,   36,   69,   39,   15,   69,   38,   69,   69,
398
+        8,   69,   13,   14,   69,   16,    0
399 399
     } ;
400 400
 
401 401
 static yyconst flex_int32_t yy_ec[256] =
@@ -440,100 +440,102 @@ static yyconst flex_int32_t yy_meta[53] =
440 440
         1,    1
441 441
     } ;
442 442
 
443
-static yyconst flex_int16_t yy_base[150] =
443
+static yyconst flex_int16_t yy_base[152] =
444 444
     {   0,
445
-        0,    0,  159,  160,   51,  136,  152,  160,  160,   47,
446
-      147,  160,  160,   44,  133,  160,   42,  160,  132,   42,
447
-      160,  160,   40,  131,   45,    0,  121,  108,  106,  160,
448
-      160,  127,  106,  103,  103,  102,   23,   28,   34,  113,
449
-      100,   99,   97,  105,   35,  102,  160,   51,  160,  160,
450
-       75,  160,  133,  160,  160,  160,  128,  160,  114,  160,
451
-      160,  132,  160,  160,  116,   64,  160,  160,  160,  160,
452
-      160,    0,   93,   90,   84,  160,   96,   94,   86,    0,
453
-       82,   92,   85,   80,   81,    0,    0,   81,   87,   74,
454
-        0,   73,   83,   70,   78,  160,  160,  160,  112,  160,
455
-
456
-       96,   68,   77,   76,    0,   79,   63,   73,    0,   55,
457
-        0,   66,   66,    0,    0,   50,   54,   60,   54,   58,
458
-        0,    0,   53,   53,    0,   55,    0,   55,   44,    0,
459
-        0,   52,    0,    0,   44,    0,   54,   42,    0,   36,
460
-        0,    0,   46,    0,  160,  101,  103,   72,  105
445
+        0,    0,  161,  162,   51,   51,  155,  162,  162,   48,
446
+      150,  162,  162,   45,  136,  162,   43,  162,  135,   43,
447
+      162,  162,   41,  134,   46,    0,  124,  111,  109,  162,
448
+      162,  130,  109,  106,  106,  105,   24,   29,   35,  116,
449
+      103,  102,  100,  108,   37,  105,  162,   53,  162,  162,
450
+       76,  137,  162,  135,  162,  162,  162,  130,  162,  116,
451
+      162,  162,  134,  162,  162,  118,   64,  162,  162,  162,
452
+      162,  162,    0,   95,   92,   86,  162,   98,   96,   88,
453
+        0,   84,   94,   87,   82,   83,    0,    0,   83,   89,
454
+       76,    0,   75,   85,   72,   80,  162,  162,  162,  162,
455
+
456
+      114,  162,   98,   70,   79,   78,    0,   81,   65,   75,
457
+        0,   57,    0,   68,   68,    0,    0,   52,   56,   62,
458
+       56,   60,    0,    0,   55,   55,    0,   57,    0,   57,
459
+       46,    0,    0,   54,    0,    0,   46,    0,   56,   44,
460
+        0,   38,    0,    0,   49,    0,  162,  103,  105,   81,
461
+      107
461 462
     } ;
462 463
 
463
-static yyconst flex_int16_t yy_def[150] =
464
+static yyconst flex_int16_t yy_def[152] =
464 465
     {   0,
465
-      145,    1,  145,  145,  145,  145,  146,  145,  145,  145,
466
-      147,  145,  145,  145,  145,  145,  145,  145,  145,  145,
467
-      145,  145,  145,  145,  145,  148,  148,  148,  148,  145,
468
-      145,  145,  148,  148,  148,  148,  148,  148,  148,  148,
469
-      148,  148,  148,  148,  148,  148,  145,  145,  145,  145,
470
-      145,  145,  146,  145,  145,  145,  147,  145,  145,  145,
471
-      145,  149,  145,  145,  145,  145,  145,  145,  145,  145,
472
-      145,  148,  148,  148,  148,  145,  148,  148,  148,  148,
473
-      148,  148,  148,  148,  148,  148,  148,  148,  148,  148,
474
-      148,  148,  148,  148,  148,  145,  145,  145,  149,  145,
475
-
476
-      145,  148,  148,  148,  148,  148,  148,  148,  148,  148,
477
-      148,  148,  148,  148,  148,  148,  148,  148,  148,  148,
478
-      148,  148,  148,  148,  148,  148,  148,  148,  148,  148,
479
-      148,  148,  148,  148,  148,  148,  148,  148,  148,  148,
480
-      148,  148,  148,  148,    0,  145,  145,  145,  145
466
+      147,    1,  147,  147,  147,  147,  148,  147,  147,  147,
467
+      149,  147,  147,  147,  147,  147,  147,  147,  147,  147,
468
+      147,  147,  147,  147,  147,  150,  150,  150,  150,  147,
469
+      147,  147,  150,  150,  150,  150,  150,  150,  150,  150,
470
+      150,  150,  150,  150,  150,  150,  147,  147,  147,  147,
471
+      147,  147,  147,  148,  147,  147,  147,  149,  147,  147,
472
+      147,  147,  151,  147,  147,  147,  147,  147,  147,  147,
473
+      147,  147,  150,  150,  150,  150,  147,  150,  150,  150,
474
+      150,  150,  150,  150,  150,  150,  150,  150,  150,  150,
475
+      150,  150,  150,  150,  150,  150,  147,  147,  147,  147,
476
+
477
+      151,  147,  147,  150,  150,  150,  150,  150,  150,  150,
478
+      150,  150,  150,  150,  150,  150,  150,  150,  150,  150,
479
+      150,  150,  150,  150,  150,  150,  150,  150,  150,  150,
480
+      150,  150,  150,  150,  150,  150,  150,  150,  150,  150,
481
+      150,  150,  150,  150,  150,  150,    0,  147,  147,  147,
482
+      147
481 483
     } ;
482 484
 
483
-static yyconst flex_int16_t yy_nxt[213] =
485
+static yyconst flex_int16_t yy_nxt[215] =
484 486
     {   0,
485 487
         4,    5,    5,    6,    7,    8,    9,   10,   11,   12,
486 488
        13,   14,   15,   16,   17,   18,   19,   20,   21,   22,
487 489
        23,   24,   25,   26,   27,   28,   29,   30,   31,   32,
488 490
        33,   34,   35,   36,   37,   38,   26,   39,   26,   40,
489 491
        41,   42,   43,   44,   26,   45,   26,   46,   47,   48,
490
-       49,   50,   51,   51,   55,   59,   62,   65,   83,   66,
491
-       67,   68,   81,   63,   82,   60,   70,   71,   56,   86,
492
-       84,   93,   96,   72,   85,   87,   51,   51,   94,   65,
493
-      144,   66,  143,  142,  141,  140,  139,  138,  137,  136,
494
-      135,  134,  133,  132,  131,  130,  129,  128,  127,  126,
495
-
496
-       97,   53,   53,   57,   57,   99,   99,  125,  124,  123,
497
-      122,  121,  120,  101,  100,  119,  118,  117,  116,  115,
498
-      114,  113,  112,  111,  110,  109,  108,  107,  106,  105,
499
-      104,  103,  102,  101,  100,   98,   58,   54,   95,   92,
500
-       91,   90,   89,   88,   80,   79,   78,   77,   76,   75,
501
-       74,   73,   69,   64,   61,   58,   54,   52,  145,    3,
502
-      145,  145,  145,  145,  145,  145,  145,  145,  145,  145,
503
-      145,  145,  145,  145,  145,  145,  145,  145,  145,  145,
504
-      145,  145,  145,  145,  145,  145,  145,  145,  145,  145,
505
-      145,  145,  145,  145,  145,  145,  145,  145,  145,  145,
506
-
507
-      145,  145,  145,  145,  145,  145,  145,  145,  145,  145,
508
-      145,  145
492
+       49,   50,   51,   51,   52,   56,   60,   63,   66,   84,
493
+       67,   68,   69,   82,   64,   83,   61,   71,   72,   57,
494
+       87,   85,   53,   94,   97,   86,   88,   51,   51,   66,
495
+       95,   67,   73,  146,  145,  144,  143,  142,  141,  140,
496
+      139,  138,  137,  136,  135,  134,  133,  132,  131,  130,
497
+
498
+      129,  128,   98,   54,   54,   58,   58,  101,  101,  127,
499
+      126,  125,  124,  123,  122,  103,  102,  121,  120,  119,
500
+      118,  117,  116,  115,  114,  113,  112,  111,  110,  109,
501
+      108,  107,  106,  105,  104,  103,  102,  100,   59,   55,
502
+       99,   96,   93,   92,   91,   90,   89,   81,   80,   79,
503
+       78,   77,   76,   75,   74,   70,   65,   62,   59,   55,
504
+      147,    3,  147,  147,  147,  147,  147,  147,  147,  147,
505
+      147,  147,  147,  147,  147,  147,  147,  147,  147,  147,
506
+      147,  147,  147,  147,  147,  147,  147,  147,  147,  147,
507
+      147,  147,  147,  147,  147,  147,  147,  147,  147,  147,
508
+
509
+      147,  147,  147,  147,  147,  147,  147,  147,  147,  147,
510
+      147,  147,  147,  147
509 511
     } ;
510 512
 
511
-static yyconst flex_int16_t yy_chk[213] =
513
+static yyconst flex_int16_t yy_chk[215] =
512 514
     {   0,
513 515
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
514 516
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
515 517
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
516 518
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
517 519
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
518
-        1,    1,    5,    5,   10,   14,   17,   20,   38,   20,
519
-       23,   23,   37,   17,   37,   14,   25,   25,   10,   39,
520
-       38,   45,   48,  148,   38,   39,   51,   51,   45,   66,
521
-      143,   66,  140,  138,  137,  135,  132,  129,  128,  126,
522
-      124,  123,  120,  119,  118,  117,  116,  113,  112,  110,
523
-
524
-       48,  146,  146,  147,  147,  149,  149,  108,  107,  106,
525
-      104,  103,  102,  101,   99,   95,   94,   93,   92,   90,
526
-       89,   88,   85,   84,   83,   82,   81,   79,   78,   77,
527
-       75,   74,   73,   65,   62,   59,   57,   53,   46,   44,
528
-       43,   42,   41,   40,   36,   35,   34,   33,   32,   29,
529
-       28,   27,   24,   19,   15,   11,    7,    6,    3,  145,
530
-      145,  145,  145,  145,  145,  145,  145,  145,  145,  145,
531
-      145,  145,  145,  145,  145,  145,  145,  145,  145,  145,
532
-      145,  145,  145,  145,  145,  145,  145,  145,  145,  145,
533
-      145,  145,  145,  145,  145,  145,  145,  145,  145,  145,
534
-
535
-      145,  145,  145,  145,  145,  145,  145,  145,  145,  145,
536
-      145,  145
520
+        1,    1,    5,    5,    6,   10,   14,   17,   20,   38,
521
+       20,   23,   23,   37,   17,   37,   14,   25,   25,   10,
522
+       39,   38,    6,   45,   48,   38,   39,   51,   51,   67,
523
+       45,   67,  150,  145,  142,  140,  139,  137,  134,  131,
524
+      130,  128,  126,  125,  122,  121,  120,  119,  118,  115,
525
+
526
+      114,  112,   48,  148,  148,  149,  149,  151,  151,  110,
527
+      109,  108,  106,  105,  104,  103,  101,   96,   95,   94,
528
+       93,   91,   90,   89,   86,   85,   84,   83,   82,   80,
529
+       79,   78,   76,   75,   74,   66,   63,   60,   58,   54,
530
+       52,   46,   44,   43,   42,   41,   40,   36,   35,   34,
531
+       33,   32,   29,   28,   27,   24,   19,   15,   11,    7,
532
+        3,  147,  147,  147,  147,  147,  147,  147,  147,  147,
533
+      147,  147,  147,  147,  147,  147,  147,  147,  147,  147,
534
+      147,  147,  147,  147,  147,  147,  147,  147,  147,  147,
535
+      147,  147,  147,  147,  147,  147,  147,  147,  147,  147,
536
+
537
+      147,  147,  147,  147,  147,  147,  147,  147,  147,  147,
538
+      147,  147,  147,  147
537 539
     } ;
538 540
 
539 541
 static yy_state_type yy_last_accepting_state;
@@ -625,7 +627,7 @@ static void update_loc(YYLTYPE *yylloc, char *yytext){
625 627
 <STRING>. { str_putc(*yytext); }
626 628
 
627 629
 */
628
-#line 629 "lex.yy.c"
630
+#line 631 "lex.yy.c"
629 631
 
630 632
 #define INITIAL 0
631 633
 
@@ -860,7 +862,7 @@ YY_DECL
860 862
 #line 85 "tokenizer.lex"
861 863
 
862 864
 
863
-#line 864 "lex.yy.c"
865
+#line 866 "lex.yy.c"
864 866
 
865 867
 	while ( 1 )		/* loops until end-of-file is reached */
866 868
 		{
@@ -887,13 +889,13 @@ yy_match:
887 889
 			while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
888 890
 				{
889 891
 				yy_current_state = (int) yy_def[yy_current_state];
890
-				if ( yy_current_state >= 146 )
892
+				if ( yy_current_state >= 148 )
891 893
 					yy_c = yy_meta[(unsigned int) yy_c];
892 894
 				}
893 895
 			yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
894 896
 			++yy_cp;
895 897
 			}
896
-		while ( yy_base[yy_current_state] != 160 );
898
+		while ( yy_base[yy_current_state] != 162 );
897 899
 
898 900
 yy_find_action:
899 901
 		yy_act = yy_accept[yy_current_state];
@@ -1257,26 +1259,31 @@ YY_RULE_SETUP
1257 1259
 case 68:
1258 1260
 YY_RULE_SETUP
1259 1261
 #line 221 "tokenizer.lex"
1260
-{ *yylval = (void *) strdup(yytext); return IDENT; }
1262
+{ return TBANG; }
1261 1263
 	YY_BREAK
1262 1264
 case 69:
1263
-/* rule 69 can match eol */
1264 1265
 YY_RULE_SETUP
1265 1266
 #line 223 "tokenizer.lex"
1266
-/* Skip comments */
1267
+{ *yylval = (void *) strdup(yytext); return IDENT; }
1267 1268
 	YY_BREAK
1268 1269
 case 70:
1269 1270
 /* rule 70 can match eol */
1270 1271
 YY_RULE_SETUP
1271 1272
 #line 225 "tokenizer.lex"
1272
-/* Skip whitespace */
1273
+/* Skip comments */
1273 1274
 	YY_BREAK
1274 1275
 case 71:
1276
+/* rule 71 can match eol */
1275 1277
 YY_RULE_SETUP
1276 1278
 #line 227 "tokenizer.lex"
1279
+/* Skip whitespace */
1280
+	YY_BREAK
1281
+case 72:
1282
+YY_RULE_SETUP
1283
+#line 229 "tokenizer.lex"
1277 1284
 ECHO;
1278 1285
 	YY_BREAK
1279
-#line 1280 "lex.yy.c"
1286
+#line 1287 "lex.yy.c"
1280 1287
 case YY_STATE_EOF(INITIAL):
1281 1288
 	yyterminate();
1282 1289
 
@@ -1569,7 +1576,7 @@ static int yy_get_next_buffer (void)
1569 1576
 		while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
1570 1577
 			{
1571 1578
 			yy_current_state = (int) yy_def[yy_current_state];
1572
-			if ( yy_current_state >= 146 )
1579
+			if ( yy_current_state >= 148 )
1573 1580
 				yy_c = yy_meta[(unsigned int) yy_c];
1574 1581
 			}
1575 1582
 		yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
@@ -1597,11 +1604,11 @@ static int yy_get_next_buffer (void)
1597 1604
 	while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
1598 1605
 		{
1599 1606
 		yy_current_state = (int) yy_def[yy_current_state];
1600
-		if ( yy_current_state >= 146 )
1607
+		if ( yy_current_state >= 148 )
1601 1608
 			yy_c = yy_meta[(unsigned int) yy_c];
1602 1609
 		}
1603 1610
 	yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
1604
-	yy_is_jam = (yy_current_state == 145);
1611
+	yy_is_jam = (yy_current_state == 147);
1605 1612
 
1606 1613
 		return yy_is_jam ? 0 : yy_current_state;
1607 1614
 }
@@ -2271,7 +2278,7 @@ void yyfree (void * ptr )
2271 2278
 
2272 2279
 #define YYTABLES_NAME "yytables"
2273 2280
 
2274
-#line 226 "tokenizer.lex"
2281
+#line 228 "tokenizer.lex"
2275 2282
 
2276 2283
 
2277 2284
 

+ 4733
- 4347
parser.output
File diff suppressed because it is too large
View File


+ 514
- 492
parser.tab.c
File diff suppressed because it is too large
View File


+ 2
- 1
parser.tab.h View File

@@ -103,7 +103,8 @@ extern int yydebug;
103 103
     COLON = 313,
104 104
     SEMICOLON = 314,
105 105
     COMMA = 315,
106
-    POUND = 316
106
+    POUND = 316,
107
+    TBANG = 317
107 108
   };
108 109
 #endif
109 110
 

+ 8
- 1
parser.y View File

@@ -21,6 +21,7 @@
21 21
 %token ASSIGN ASSIGNPLUS ASSIGNMINUS ASSIGNSTAR ASSIGNSLASH ASSIGNDSTAR ASSIGNBAND ASSIGNBOR ASSIGNBXOR
22 22
 %token EQUAL NEQUAL LESS GREATER LESSEQ GREATEREQ RSHIFT LSHIFT
23 23
 %token LBRACE RBRACE LPAREN RPAREN LBRACKET RBRACKET DOT COLON SEMICOLON COMMA POUND
24
+%token TBANG
24 25
 
25 26
 %parse-param {stmt_node **program}
26 27
 
@@ -317,10 +318,16 @@ factor_expr:
317 318
 ;
318 319
 
319 320
 power_expr:
320
-  power_expr DSTAR power_expr { $$ = NEW_EX(); AS_EX($$)->type = EX_BINOP; AS_EX($$)->binop = NEW(binop_node); AS_EX($$)->binop->type = OP_POW; AS_EX($$)->binop->left = $1; AS_EX($$)->binop->right = $3; }
321
+  tbang_expr DSTAR power_expr { $$ = NEW_EX(); AS_EX($$)->type = EX_BINOP; AS_EX($$)->binop = NEW(binop_node); AS_EX($$)->binop->type = OP_POW; AS_EX($$)->binop->left = $1; AS_EX($$)->binop->right = $3; }
322
+| tbang_expr { $$ = $1; }
323
+;
324
+
325
+tbang_expr:
326
+  binary_expr TBANG tbang_expr { $$ = NEW_EX(); AS_EX($$)->type = EX_BINOP; AS_EX($$)->binop = NEW(binop_node); AS_EX($$)->binop->type = OP_TBANG; AS_EX($$)->binop->left = $1; AS_EX($$)->binop->right = $3; }
321 327
 | binary_expr { $$ = $1; }
322 328
 ;
323 329
 
330
+
324 331
 binary_expr:
325 332
   binary_expr BAND binary_expr { $$ = NEW_EX(); AS_EX($$)->type = EX_BINOP; AS_EX($$)->binop = NEW(binop_node); AS_EX($$)->binop->type = OP_BAND; AS_EX($$)->binop->left = $1; AS_EX($$)->binop->right = $3; }
326 333
 | binary_expr BOR binary_expr { $$ = NEW_EX(); AS_EX($$)->type = EX_BINOP; AS_EX($$)->binop = NEW(binop_node); AS_EX($$)->binop->type = OP_BOR; AS_EX($$)->binop->left = $1; AS_EX($$)->binop->right = $3; }

+ 4
- 0
runtime.c View File

@@ -556,6 +556,10 @@ sol_object_t *sol_eval_inner(sol_state_t *state, expr_node *expr, jmp_buf jmp) {
556 556
 					res = CALL_METHOD(state, left, pow, list);
557 557
 					break;
558 558
 
559
+				case OP_TBANG:
560
+					res = CALL_METHOD(state, left, tbang, list);
561
+					break;
562
+
559 563
 				case OP_BAND:
560 564
 					res = CALL_METHOD(state, left, band, list);
561 565
 					break;

+ 3
- 0
sol.h View File

@@ -107,6 +107,8 @@ typedef struct {
107 107
 	sol_cfunc_t mod;
108 108
 	/** Called with [this, rhs] to perform binary exponentiation ("**"). */
109 109
 	sol_cfunc_t pow;
110
+	/** TODO: document me!*/
111
+	sol_cfunc_t tbang;
110 112
 	/** Called with [this, rhs] to perform binary bitwise AND ("&") */
111 113
 	sol_cfunc_t band;
112 114
 	/** Called with [this, rhs] to perform binary bitwise OR ("|") */
@@ -461,6 +463,7 @@ void sol_ops_init(sol_ops_t *);
461 463
 // builtins.c
462 464
 
463 465
 sol_object_t *sol_f_not_impl(sol_state_t *, sol_object_t *);
466
+sol_object_t *sol_f_tbang(sol_state_t *, sol_object_t *);
464 467
 sol_object_t *sol_f_no_op(sol_state_t *, sol_object_t *);
465 468
 sol_object_t *sol_f_default_cmp(sol_state_t *, sol_object_t *);
466 469
 sol_object_t *sol_f_default_tostring(sol_state_t *, sol_object_t *);

+ 3
- 0
state.c View File

@@ -68,6 +68,7 @@ int sol_state_init(sol_state_t *state) {
68 68
 	state->IntOps.mul = sol_f_int_mul;
69 69
 	state->IntOps.div = sol_f_int_div;
70 70
 	state->IntOps.mod = sol_f_int_mod;
71
+	state->IntOps.pow = sol_f_int_pow;
71 72
 	state->IntOps.band = sol_f_int_band;
72 73
 	state->IntOps.bor = sol_f_int_bor;
73 74
 	state->IntOps.bxor = sol_f_int_bxor;
@@ -745,6 +746,8 @@ void sol_ops_init(sol_ops_t *ops) {
745 746
 	ops->mul = sol_f_not_impl;
746 747
 	ops->div = sol_f_not_impl;
747 748
 	ops->mod = sol_f_not_impl;
749
+	ops->pow = sol_f_not_impl;
750
+	ops->tbang = sol_f_tbang;
748 751
 	ops->band = sol_f_not_impl;
749 752
 	ops->bor = sol_f_not_impl;
750 753
 	ops->bxor = sol_f_not_impl;

+ 2
- 0
tokenizer.lex View File

@@ -218,6 +218,8 @@ None { return NONE; }
218 218
 
219 219
 "#" { return POUND; }
220 220
 
221
+"!!!" { return TBANG; }
222
+
221 223
 {IDENT} { *yylval = (void *) strdup(yytext); return IDENT; }
222 224
 
223 225
 --[^\n]*\n /* Skip comments */

Loading…
Cancel
Save