Browse Source

Merge pull request #16 from sol-lang/logicalfun

Sol Part 45: I Just Don't Even!
master
Grissess 6 years ago
parent
commit
642bd380be
  1. 2
      ast.h
  2. 6
      astprint.c
  3. 13
      builtins.c
  4. 219
      lex.yy.c
  5. 9080
      parser.output
  6. 1006
      parser.tab.c
  7. 3
      parser.tab.h
  8. 9
      parser.y
  9. 4
      runtime.c
  10. 3
      sol.h
  11. 3
      state.c
  12. 2
      tokenizer.lex

2
ast.h

@ -26,7 +26,7 @@ typedef struct {
};
} lit_node;
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;
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;
typedef struct {
binop_t type;
expr_node *left;

6
astprint.c

@ -138,6 +138,10 @@ void prex(sol_state_t *state, expr_node *node, int lev) {
prlev(state, lev, "Op: **");
break;
case OP_TBANG:
prlev(state, lev, "Op: !!!");
break;
case OP_BAND:
prlev(state, lev, "Op: &");
break;
@ -161,7 +165,7 @@ void prex(sol_state_t *state, expr_node *node, int lev) {
case OP_EQUAL:
prlev(state, lev, "Op: ==");
break;
case OP_NEQUAL:
prlev(state, lev, "Op: !=");
break;

13
builtins.c

@ -55,6 +55,19 @@ sol_object_t *sol_f_default_repr(sol_state_t *state, sol_object_t *args) {
return res;
}
sol_object_t *sol_f_tbang(sol_state_t *state, sol_object_t *args) {
sol_object_t *a = sol_list_get_index(state, args, 0), *b = sol_list_get_index(state, args, 1);
int refa = a->refcnt, refb = b->refcnt;
sol_object_t c = *b;
*b = *a;
*a = c;
b->refcnt = refa;
a->refcnt = refb;
sol_obj_free(a);
sol_obj_free(b);
return sol_incref(state->None);
}
sol_object_t *sol_f_no_op(sol_state_t *state, sol_object_t *args) {
if(state) {
return sol_incref(state->None);

219
lex.yy.c

@ -369,8 +369,8 @@ static void yy_fatal_error (yyconst char msg[] );
*yy_cp = '\0'; \
(yy_c_buf_p) = yy_cp;
#define YY_NUM_RULES 71
#define YY_END_OF_BUFFER 72
#define YY_NUM_RULES 72
#define YY_END_OF_BUFFER 73
/* This struct is not used in this scanner,
but its presence is necessary. */
struct yy_trans_info
@ -378,24 +378,24 @@ struct yy_trans_info
flex_int32_t yy_verify;
flex_int32_t yy_nxt;
};
static yyconst flex_int16_t yy_accept[146] =
static yyconst flex_int16_t yy_accept[148] =
{ 0,
0, 0, 72, 71, 70, 34, 71, 67, 23, 26,
71, 61, 62, 21, 19, 66, 20, 63, 22, 2,
64, 65, 51, 40, 52, 68, 68, 68, 68, 59,
60, 28, 68, 68, 68, 68, 68, 68, 68, 68,
68, 68, 68, 68, 68, 68, 57, 27, 58, 29,
70, 50, 0, 3, 30, 46, 0, 4, 25, 43,
41, 0, 42, 44, 1, 2, 56, 53, 49, 54,
55, 68, 68, 68, 68, 48, 68, 68, 68, 11,
68, 68, 68, 68, 68, 5, 10, 68, 68, 68,
33, 68, 68, 68, 68, 47, 32, 45, 0, 69,
1, 68, 68, 68, 31, 68, 68, 68, 17, 68,
9, 68, 68, 24, 35, 68, 68, 68, 68, 68,
18, 37, 68, 68, 7, 68, 12, 68, 68, 6,
36, 68, 39, 15, 68, 38, 68, 68, 8, 68,
13, 14, 68, 16, 0
0, 0, 73, 72, 71, 34, 72, 67, 23, 26,
72, 61, 62, 21, 19, 66, 20, 63, 22, 2,
64, 65, 51, 40, 52, 69, 69, 69, 69, 59,
60, 28, 69, 69, 69, 69, 69, 69, 69, 69,
69, 69, 69, 69, 69, 69, 57, 27, 58, 29,
71, 0, 50, 0, 3, 30, 46, 0, 4, 25,
43, 41, 0, 42, 44, 1, 2, 56, 53, 49,
54, 55, 69, 69, 69, 69, 48, 69, 69, 69,
11, 69, 69, 69, 69, 69, 5, 10, 69, 69,
69, 33, 69, 69, 69, 69, 47, 32, 68, 45,
0, 70, 1, 69, 69, 69, 31, 69, 69, 69,
17, 69, 9, 69, 69, 24, 35, 69, 69, 69,
69, 69, 18, 37, 69, 69, 7, 69, 12, 69,
69, 6, 36, 69, 39, 15, 69, 38, 69, 69,
8, 69, 13, 14, 69, 16, 0
} ;
static yyconst flex_int32_t yy_ec[256] =
@ -440,100 +440,102 @@ static yyconst flex_int32_t yy_meta[53] =
1, 1
} ;
static yyconst flex_int16_t yy_base[150] =
static yyconst flex_int16_t yy_base[152] =
{ 0,
0, 0, 159, 160, 51, 136, 152, 160, 160, 47,
147, 160, 160, 44, 133, 160, 42, 160, 132, 42,
160, 160, 40, 131, 45, 0, 121, 108, 106, 160,
160, 127, 106, 103, 103, 102, 23, 28, 34, 113,
100, 99, 97, 105, 35, 102, 160, 51, 160, 160,
75, 160, 133, 160, 160, 160, 128, 160, 114, 160,
160, 132, 160, 160, 116, 64, 160, 160, 160, 160,
160, 0, 93, 90, 84, 160, 96, 94, 86, 0,
82, 92, 85, 80, 81, 0, 0, 81, 87, 74,
0, 73, 83, 70, 78, 160, 160, 160, 112, 160,
96, 68, 77, 76, 0, 79, 63, 73, 0, 55,
0, 66, 66, 0, 0, 50, 54, 60, 54, 58,
0, 0, 53, 53, 0, 55, 0, 55, 44, 0,
0, 52, 0, 0, 44, 0, 54, 42, 0, 36,
0, 0, 46, 0, 160, 101, 103, 72, 105
0, 0, 161, 162, 51, 51, 155, 162, 162, 48,
150, 162, 162, 45, 136, 162, 43, 162, 135, 43,
162, 162, 41, 134, 46, 0, 124, 111, 109, 162,
162, 130, 109, 106, 106, 105, 24, 29, 35, 116,
103, 102, 100, 108, 37, 105, 162, 53, 162, 162,
76, 137, 162, 135, 162, 162, 162, 130, 162, 116,
162, 162, 134, 162, 162, 118, 64, 162, 162, 162,
162, 162, 0, 95, 92, 86, 162, 98, 96, 88,
0, 84, 94, 87, 82, 83, 0, 0, 83, 89,
76, 0, 75, 85, 72, 80, 162, 162, 162, 162,
114, 162, 98, 70, 79, 78, 0, 81, 65, 75,
0, 57, 0, 68, 68, 0, 0, 52, 56, 62,
56, 60, 0, 0, 55, 55, 0, 57, 0, 57,
46, 0, 0, 54, 0, 0, 46, 0, 56, 44,
0, 38, 0, 0, 49, 0, 162, 103, 105, 81,
107
} ;
static yyconst flex_int16_t yy_def[150] =
static yyconst flex_int16_t yy_def[152] =
{ 0,
145, 1, 145, 145, 145, 145, 146, 145, 145, 145,
147, 145, 145, 145, 145, 145, 145, 145, 145, 145,
145, 145, 145, 145, 145, 148, 148, 148, 148, 145,
145, 145, 148, 148, 148, 148, 148, 148, 148, 148,
148, 148, 148, 148, 148, 148, 145, 145, 145, 145,
145, 145, 146, 145, 145, 145, 147, 145, 145, 145,
145, 149, 145, 145, 145, 145, 145, 145, 145, 145,
145, 148, 148, 148, 148, 145, 148, 148, 148, 148,
148, 148, 148, 148, 148, 148, 148, 148, 148, 148,
148, 148, 148, 148, 148, 145, 145, 145, 149, 145,
145, 148, 148, 148, 148, 148, 148, 148, 148, 148,
148, 148, 148, 148, 148, 148, 148, 148, 148, 148,
148, 148, 148, 148, 148, 148, 148, 148, 148, 148,
148, 148, 148, 148, 148, 148, 148, 148, 148, 148,
148, 148, 148, 148, 0, 145, 145, 145, 145
147, 1, 147, 147, 147, 147, 148, 147, 147, 147,
149, 147, 147, 147, 147, 147, 147, 147, 147, 147,
147, 147, 147, 147, 147, 150, 150, 150, 150, 147,
147, 147, 150, 150, 150, 150, 150, 150, 150, 150,
150, 150, 150, 150, 150, 150, 147, 147, 147, 147,
147, 147, 147, 148, 147, 147, 147, 149, 147, 147,
147, 147, 151, 147, 147, 147, 147, 147, 147, 147,
147, 147, 150, 150, 150, 150, 147, 150, 150, 150,
150, 150, 150, 150, 150, 150, 150, 150, 150, 150,
150, 150, 150, 150, 150, 150, 147, 147, 147, 147,
151, 147, 147, 150, 150, 150, 150, 150, 150, 150,
150, 150, 150, 150, 150, 150, 150, 150, 150, 150,
150, 150, 150, 150, 150, 150, 150, 150, 150, 150,
150, 150, 150, 150, 150, 150, 150, 150, 150, 150,
150, 150, 150, 150, 150, 150, 0, 147, 147, 147,
147
} ;
static yyconst flex_int16_t yy_nxt[213] =
static yyconst flex_int16_t yy_nxt[215] =
{ 0,
4, 5, 5, 6, 7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
33, 34, 35, 36, 37, 38, 26, 39, 26, 40,
41, 42, 43, 44, 26, 45, 26, 46, 47, 48,
49, 50, 51, 51, 55, 59, 62, 65, 83, 66,
67, 68, 81, 63, 82, 60, 70, 71, 56, 86,
84, 93, 96, 72, 85, 87, 51, 51, 94, 65,
144, 66, 143, 142, 141, 140, 139, 138, 137, 136,
135, 134, 133, 132, 131, 130, 129, 128, 127, 126,
97, 53, 53, 57, 57, 99, 99, 125, 124, 123,
122, 121, 120, 101, 100, 119, 118, 117, 116, 115,
114, 113, 112, 111, 110, 109, 108, 107, 106, 105,
104, 103, 102, 101, 100, 98, 58, 54, 95, 92,
91, 90, 89, 88, 80, 79, 78, 77, 76, 75,
74, 73, 69, 64, 61, 58, 54, 52, 145, 3,
145, 145, 145, 145, 145, 145, 145, 145, 145, 145,
145, 145, 145, 145, 145, 145, 145, 145, 145, 145,
145, 145, 145, 145, 145, 145, 145, 145, 145, 145,
145, 145, 145, 145, 145, 145, 145, 145, 145, 145,
145, 145, 145, 145, 145, 145, 145, 145, 145, 145,
145, 145
49, 50, 51, 51, 52, 56, 60, 63, 66, 84,
67, 68, 69, 82, 64, 83, 61, 71, 72, 57,
87, 85, 53, 94, 97, 86, 88, 51, 51, 66,
95, 67, 73, 146, 145, 144, 143, 142, 141, 140,
139, 138, 137, 136, 135, 134, 133, 132, 131, 130,
129, 128, 98, 54, 54, 58, 58, 101, 101, 127,
126, 125, 124, 123, 122, 103, 102, 121, 120, 119,
118, 117, 116, 115, 114, 113, 112, 111, 110, 109,
108, 107, 106, 105, 104, 103, 102, 100, 59, 55,
99, 96, 93, 92, 91, 90, 89, 81, 80, 79,
78, 77, 76, 75, 74, 70, 65, 62, 59, 55,
147, 3, 147, 147, 147, 147, 147, 147, 147, 147,
147, 147, 147, 147, 147, 147, 147, 147, 147, 147,
147, 147, 147, 147, 147, 147, 147, 147, 147, 147,
147, 147, 147, 147, 147, 147, 147, 147, 147, 147,
147, 147, 147, 147, 147, 147, 147, 147, 147, 147,
147, 147, 147, 147
} ;
static yyconst flex_int16_t yy_chk[213] =
static yyconst flex_int16_t yy_chk[215] =
{ 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 5, 5, 10, 14, 17, 20, 38, 20,
23, 23, 37, 17, 37, 14, 25, 25, 10, 39,
38, 45, 48, 148, 38, 39, 51, 51, 45, 66,
143, 66, 140, 138, 137, 135, 132, 129, 128, 126,
124, 123, 120, 119, 118, 117, 116, 113, 112, 110,
48, 146, 146, 147, 147, 149, 149, 108, 107, 106,
104, 103, 102, 101, 99, 95, 94, 93, 92, 90,
89, 88, 85, 84, 83, 82, 81, 79, 78, 77,
75, 74, 73, 65, 62, 59, 57, 53, 46, 44,
43, 42, 41, 40, 36, 35, 34, 33, 32, 29,
28, 27, 24, 19, 15, 11, 7, 6, 3, 145,
145, 145, 145, 145, 145, 145, 145, 145, 145, 145,
145, 145, 145, 145, 145, 145, 145, 145, 145, 145,
145, 145, 145, 145, 145, 145, 145, 145, 145, 145,
145, 145, 145, 145, 145, 145, 145, 145, 145, 145,
145, 145, 145, 145, 145, 145, 145, 145, 145, 145,
145, 145
1, 1, 5, 5, 6, 10, 14, 17, 20, 38,
20, 23, 23, 37, 17, 37, 14, 25, 25, 10,
39, 38, 6, 45, 48, 38, 39, 51, 51, 67,
45, 67, 150, 145, 142, 140, 139, 137, 134, 131,
130, 128, 126, 125, 122, 121, 120, 119, 118, 115,
114, 112, 48, 148, 148, 149, 149, 151, 151, 110,
109, 108, 106, 105, 104, 103, 101, 96, 95, 94,
93, 91, 90, 89, 86, 85, 84, 83, 82, 80,
79, 78, 76, 75, 74, 66, 63, 60, 58, 54,
52, 46, 44, 43, 42, 41, 40, 36, 35, 34,
33, 32, 29, 28, 27, 24, 19, 15, 11, 7,
3, 147, 147, 147, 147, 147, 147, 147, 147, 147,
147, 147, 147, 147, 147, 147, 147, 147, 147, 147,
147, 147, 147, 147, 147, 147, 147, 147, 147, 147,
147, 147, 147, 147, 147, 147, 147, 147, 147, 147,
147, 147, 147, 147, 147, 147, 147, 147, 147, 147,
147, 147, 147, 147
} ;
static yy_state_type yy_last_accepting_state;
@ -625,7 +627,7 @@ static void update_loc(YYLTYPE *yylloc, char *yytext){
<STRING>. { str_putc(*yytext); }
*/
#line 629 "lex.yy.c"
#line 631 "lex.yy.c"
#define INITIAL 0
@ -860,7 +862,7 @@ YY_DECL
#line 85 "tokenizer.lex"
#line 864 "lex.yy.c"
#line 866 "lex.yy.c"
while ( 1 ) /* loops until end-of-file is reached */
{
@ -887,13 +889,13 @@ yy_match:
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{
yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 146 )
if ( yy_current_state >= 148 )
yy_c = yy_meta[(unsigned int) yy_c];
}
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
++yy_cp;
}
while ( yy_base[yy_current_state] != 160 );
while ( yy_base[yy_current_state] != 162 );
yy_find_action:
yy_act = yy_accept[yy_current_state];
@ -1257,26 +1259,31 @@ YY_RULE_SETUP
case 68:
YY_RULE_SETUP
#line 221 "tokenizer.lex"
{ *yylval = (void *) strdup(yytext); return IDENT; }
{ return TBANG; }
YY_BREAK
case 69:
/* rule 69 can match eol */
YY_RULE_SETUP
#line 223 "tokenizer.lex"
/* Skip comments */
{ *yylval = (void *) strdup(yytext); return IDENT; }
YY_BREAK
case 70:
/* rule 70 can match eol */
YY_RULE_SETUP
#line 225 "tokenizer.lex"
/* Skip whitespace */
/* Skip comments */
YY_BREAK
case 71:
/* rule 71 can match eol */
YY_RULE_SETUP
#line 227 "tokenizer.lex"
/* Skip whitespace */
YY_BREAK
case 72:
YY_RULE_SETUP
#line 229 "tokenizer.lex"
ECHO;
YY_BREAK
#line 1280 "lex.yy.c"
#line 1287 "lex.yy.c"
case YY_STATE_EOF(INITIAL):
yyterminate();
@ -1569,7 +1576,7 @@ static int yy_get_next_buffer (void)
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{
yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 146 )
if ( yy_current_state >= 148 )
yy_c = yy_meta[(unsigned int) yy_c];
}
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)
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{
yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 146 )
if ( yy_current_state >= 148 )
yy_c = yy_meta[(unsigned int) yy_c];
}
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
yy_is_jam = (yy_current_state == 145);
yy_is_jam = (yy_current_state == 147);
return yy_is_jam ? 0 : yy_current_state;
}
@ -2271,7 +2278,7 @@ void yyfree (void * ptr )
#define YYTABLES_NAME "yytables"
#line 226 "tokenizer.lex"
#line 228 "tokenizer.lex"

9080
parser.output
File diff suppressed because it is too large
View File

1006
parser.tab.c
File diff suppressed because it is too large
View File

3
parser.tab.h

@ -103,7 +103,8 @@ extern int yydebug;
COLON = 313,
SEMICOLON = 314,
COMMA = 315,
POUND = 316
POUND = 316,
TBANG = 317
};
#endif

9
parser.y

@ -21,6 +21,7 @@
%token ASSIGN ASSIGNPLUS ASSIGNMINUS ASSIGNSTAR ASSIGNSLASH ASSIGNDSTAR ASSIGNBAND ASSIGNBOR ASSIGNBXOR
%token EQUAL NEQUAL LESS GREATER LESSEQ GREATEREQ RSHIFT LSHIFT
%token LBRACE RBRACE LPAREN RPAREN LBRACKET RBRACKET DOT COLON SEMICOLON COMMA POUND
%token TBANG
%parse-param {stmt_node **program}
@ -317,10 +318,16 @@ factor_expr:
;
power_expr:
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; }
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; }
| tbang_expr { $$ = $1; }
;
tbang_expr:
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; }
| binary_expr { $$ = $1; }
;
binary_expr:
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; }
| 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
runtime.c

@ -556,6 +556,10 @@ sol_object_t *sol_eval_inner(sol_state_t *state, expr_node *expr, jmp_buf jmp) {
res = CALL_METHOD(state, left, pow, list);
break;
case OP_TBANG:
res = CALL_METHOD(state, left, tbang, list);
break;
case OP_BAND:
res = CALL_METHOD(state, left, band, list);
break;

3
sol.h

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

3
state.c

@ -68,6 +68,7 @@ int sol_state_init(sol_state_t *state) {
state->IntOps.mul = sol_f_int_mul;
state->IntOps.div = sol_f_int_div;
state->IntOps.mod = sol_f_int_mod;
state->IntOps.pow = sol_f_int_pow;
state->IntOps.band = sol_f_int_band;
state->IntOps.bor = sol_f_int_bor;
state->IntOps.bxor = sol_f_int_bxor;
@ -745,6 +746,8 @@ void sol_ops_init(sol_ops_t *ops) {
ops->mul = sol_f_not_impl;
ops->div = sol_f_not_impl;
ops->mod = sol_f_not_impl;
ops->pow = sol_f_not_impl;
ops->tbang = sol_f_tbang;
ops->band = sol_f_not_impl;
ops->bor = sol_f_not_impl;
ops->bxor = sol_f_not_impl;

2
tokenizer.lex

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

Loading…
Cancel
Save