rubinius-melbourne 2.1.0.0 → 2.2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +1 -1
- data/ext/rubinius/melbourne/extconf.rb +4 -13
- data/ext/rubinius/melbourne/grammar.cpp +4788 -4044
- data/ext/rubinius/melbourne/grammar.y +919 -485
- data/ext/rubinius/melbourne/melbourne.cpp +3 -8
- data/ext/rubinius/melbourne/node.hpp +25 -1
- data/ext/rubinius/melbourne/node_types.cpp +74 -66
- data/ext/rubinius/melbourne/node_types.hpp +5 -1
- data/ext/rubinius/melbourne/node_types.rb +5 -0
- data/ext/rubinius/melbourne/parser_state.hpp +40 -15
- data/ext/rubinius/melbourne/symbols.cpp +6 -0
- data/ext/rubinius/melbourne/symbols.hpp +3 -0
- data/ext/rubinius/melbourne/visitor.cpp +75 -52
- data/lib/rubinius/melbourne/version.rb +2 -2
- data/lib/rubinius/melbourne.rb +2 -2
- data/rubinius-melbourne.gemspec +1 -4
- data/spec/array_spec.rb +20 -0
- data/spec/custom/matchers/parse_as.rb +2 -1
- data/spec/defn_spec.rb +556 -265
- data/spec/defs_spec.rb +63 -40
- data/spec/dstr_spec.rb +1 -2
- data/spec/ensure_spec.rb +12 -8
- data/spec/flip2_spec.rb +38 -2
- data/spec/hash_spec.rb +47 -0
- data/spec/iter_spec.rb +371 -244
- data/spec/lambda_spec.rb +107 -0
- data/spec/lit_spec.rb +16 -0
- data/spec/masgn_spec.rb +97 -301
- data/spec/rescue_spec.rb +12 -6
- data/spec/spec_helper.rb +6 -7
- data/spec/while_spec.rb +9 -6
- metadata +4 -16
@@ -32,17 +32,12 @@ VALUE MELBOURNE_FILE_TO_AST(VALUE self, VALUE fname, VALUE start) {
|
|
32
32
|
}
|
33
33
|
|
34
34
|
void Init_melbourne(void) {
|
35
|
-
VALUE
|
35
|
+
VALUE rb_mCodeTools, rb_cMelbourne;
|
36
36
|
|
37
37
|
MELBOURNE::init_symbols();
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
#endif
|
42
|
-
|
43
|
-
rb_mToolSets = rb_const_get(rb_mRubinius, rb_intern("ToolSets"));
|
44
|
-
rb_mToolSet = rb_funcall(rb_mToolSets, rb_intern("current"), 0);
|
45
|
-
rb_cMelbourne = rb_define_class_under(rb_mToolSet, "Melbourne", rb_cObject);
|
39
|
+
rb_mCodeTools = rb_const_get(rb_cObject, rb_intern("CodeTools"));
|
40
|
+
rb_cMelbourne = rb_define_class_under(rb_mCodeTools, "Melbourne", rb_cObject);
|
46
41
|
rb_define_method(rb_cMelbourne, "string_to_ast",
|
47
42
|
RUBY_METHOD_FUNC(MELBOURNE_STRING_TO_AST), 3);
|
48
43
|
rb_define_method(rb_cMelbourne, "file_to_ast",
|
@@ -37,11 +37,30 @@ namespace MELBOURNE {
|
|
37
37
|
struct RNode *node;
|
38
38
|
ID id;
|
39
39
|
long state;
|
40
|
+
struct rb_args_info *args;
|
40
41
|
long cnt;
|
41
42
|
VALUE value;
|
42
43
|
} u3;
|
43
44
|
} NODE;
|
44
45
|
|
46
|
+
struct rb_args_info {
|
47
|
+
NODE *pre_init;
|
48
|
+
NODE *post_init;
|
49
|
+
|
50
|
+
int pre_args_num; /* count of mandatory pre-arguments */
|
51
|
+
int post_args_num; /* count of mandatory post-arguments */
|
52
|
+
|
53
|
+
ID first_post_arg;
|
54
|
+
|
55
|
+
ID rest_arg;
|
56
|
+
ID block_arg;
|
57
|
+
|
58
|
+
NODE *kw_args;
|
59
|
+
NODE *kw_rest_arg;
|
60
|
+
|
61
|
+
NODE *opt_args;
|
62
|
+
};
|
63
|
+
|
45
64
|
#define RNODE(obj) ((NODE*)(obj))
|
46
65
|
|
47
66
|
/* 0..4:T_TYPES, 5:FL_MARK, 6:reserved, 7:NODE_FL_NEWLINE */
|
@@ -105,6 +124,7 @@ namespace MELBOURNE {
|
|
105
124
|
#define nd_recv u1.node
|
106
125
|
#define nd_mid u2.id
|
107
126
|
#define nd_args u3.node
|
127
|
+
#define nd_ainfo u3.args
|
108
128
|
|
109
129
|
#define nd_noex u3.id
|
110
130
|
#define nd_defn u3.node
|
@@ -162,7 +182,7 @@ namespace MELBOURNE {
|
|
162
182
|
#define NEW_UNTIL(c,b,n) NEW_NODE(NODE_UNTIL,c,b,n)
|
163
183
|
#define NEW_FOR(v,i,b) NEW_NODE(NODE_FOR,v,b,i)
|
164
184
|
#define NEW_ITER(a,b) NEW_NODE(NODE_ITER,0,NEW_SCOPE(a,b),0)
|
165
|
-
#define NEW_LAMBDA(a)
|
185
|
+
#define NEW_LAMBDA(a,b) NEW_NODE(NODE_LAMBDA,0,NEW_SCOPE(a,b),0)
|
166
186
|
#define NEW_BREAK(s) NEW_NODE(NODE_BREAK,s,0,0)
|
167
187
|
#define NEW_NEXT(s) NEW_NODE(NODE_NEXT,s,0,0)
|
168
188
|
#define NEW_REDO() NEW_NODE(NODE_REDO,0,0,0)
|
@@ -192,6 +212,7 @@ namespace MELBOURNE {
|
|
192
212
|
#define NEW_OP_ASGN22(i,o) NEW_NODE(NODE_OP_ASGN2,i,o,rb_id_attrset(i))
|
193
213
|
#define NEW_OP_ASGN_OR(i,val) NEW_NODE(NODE_OP_ASGN_OR,i,val,0)
|
194
214
|
#define NEW_OP_ASGN_AND(i,val) NEW_NODE(NODE_OP_ASGN_AND,i,val,0)
|
215
|
+
#define NEW_OP_CDECL(v,op,val) NEW_NODE(NODE_OP_CDECL,v,val,op)
|
195
216
|
#define NEW_GVAR(v) NEW_NODE(NODE_GVAR,v,0,0)
|
196
217
|
#define NEW_LVAR(v) NEW_NODE(NODE_LVAR,v,0,0)
|
197
218
|
#define NEW_DVAR(v) NEW_NODE(NODE_DVAR,v,0,0)
|
@@ -218,6 +239,7 @@ namespace MELBOURNE {
|
|
218
239
|
#define NEW_ARGS(m,o) NEW_NODE(NODE_ARGS,o,m,0)
|
219
240
|
#define NEW_ARGS_AUX(r,b) NEW_NODE(NODE_ARGS_AUX,r,b,0)
|
220
241
|
#define NEW_OPT_ARG(i,v) NEW_NODE(NODE_OPT_ARG,i,v,0)
|
242
|
+
#define NEW_KW_ARG(i,v) NEW_NODE(NODE_KW_ARG,i,v,0)
|
221
243
|
#define NEW_POSTARG(i,v) NEW_NODE(NODE_POSTARG,i,v,0)
|
222
244
|
#define NEW_ARGSCAT(a,b) NEW_NODE(NODE_ARGSCAT,a,b,0)
|
223
245
|
#define NEW_ARGSPUSH(a,b) NEW_NODE(NODE_ARGSPUSH,a,b,0)
|
@@ -251,6 +273,8 @@ namespace MELBOURNE {
|
|
251
273
|
#define NEW_FILE() NEW_NODE(NODE_FILE,0,0,0)
|
252
274
|
#define NEW_NUMBER(l) NEW_NODE(NODE_NUMBER,REF(l),0,0)
|
253
275
|
#define NEW_FLOAT(l) NEW_NODE(NODE_FLOAT,REF(l),0,0)
|
276
|
+
#define NEW_RATIONAL(l) NEW_NODE(NODE_RATIONAL,REF(l),0,0)
|
277
|
+
#define NEW_IMAGINARY(l) NEW_NODE(NODE_IMAGINARY,REF(l),0,0)
|
254
278
|
#define NEW_ENCODING(n) NEW_NODE(NODE_ENCODING,REF(n),0,0)
|
255
279
|
|
256
280
|
#define NOEX_PUBLIC 0x00,
|
@@ -41,6 +41,7 @@ namespace MELBOURNE {
|
|
41
41
|
"op_asgn2\0"
|
42
42
|
"op_asgn_and\0"
|
43
43
|
"op_asgn_or\0"
|
44
|
+
"op_cdecl\0"
|
44
45
|
"call\0"
|
45
46
|
"fcall\0"
|
46
47
|
"vcall\0"
|
@@ -74,6 +75,7 @@ namespace MELBOURNE {
|
|
74
75
|
"args\0"
|
75
76
|
"args_aux\0"
|
76
77
|
"opt_arg\0"
|
78
|
+
"kw_arg\0"
|
77
79
|
"postarg\0"
|
78
80
|
"argscat\0"
|
79
81
|
"argspush\0"
|
@@ -118,6 +120,8 @@ namespace MELBOURNE {
|
|
118
120
|
"float\0"
|
119
121
|
"encoding\0"
|
120
122
|
"preexe\0"
|
123
|
+
"rational\0"
|
124
|
+
"imaginary\0"
|
121
125
|
};
|
122
126
|
|
123
127
|
static const unsigned short node_types_offsets[] = {
|
@@ -156,87 +160,91 @@ namespace MELBOURNE {
|
|
156
160
|
195,
|
157
161
|
207,
|
158
162
|
218,
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
163
|
+
227,
|
164
|
+
232,
|
165
|
+
238,
|
166
|
+
244,
|
167
|
+
250,
|
168
|
+
257,
|
169
|
+
263,
|
170
|
+
270,
|
171
|
+
277,
|
172
|
+
282,
|
173
|
+
289,
|
174
|
+
295,
|
175
|
+
300,
|
176
|
+
305,
|
177
|
+
310,
|
178
|
+
315,
|
179
|
+
321,
|
180
|
+
326,
|
177
181
|
334,
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
362,
|
182
|
+
343,
|
183
|
+
349,
|
184
|
+
356,
|
185
|
+
363,
|
183
186
|
367,
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
187
|
+
371,
|
188
|
+
376,
|
189
|
+
381,
|
190
|
+
387,
|
191
|
+
393,
|
192
|
+
399,
|
193
|
+
410,
|
190
194
|
415,
|
191
|
-
|
192
|
-
|
195
|
+
424,
|
196
|
+
432,
|
193
197
|
439,
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
198
|
+
447,
|
199
|
+
455,
|
200
|
+
464,
|
201
|
+
470,
|
202
|
+
477,
|
199
203
|
487,
|
200
|
-
492,
|
201
204
|
498,
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
205
|
+
503,
|
206
|
+
508,
|
207
|
+
514,
|
208
|
+
521,
|
209
|
+
527,
|
210
|
+
533,
|
211
|
+
540,
|
212
|
+
547,
|
213
|
+
554,
|
211
214
|
561,
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
215
|
+
566,
|
216
|
+
571,
|
217
|
+
577,
|
218
|
+
583,
|
219
|
+
588,
|
220
|
+
592,
|
221
|
+
597,
|
218
222
|
603,
|
219
223
|
611,
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
637,
|
224
|
+
619,
|
225
|
+
627,
|
226
|
+
634,
|
224
227
|
642,
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
+
647,
|
229
|
+
653,
|
230
|
+
658,
|
231
|
+
667,
|
228
232
|
675,
|
229
|
-
|
230
|
-
685,
|
233
|
+
682,
|
231
234
|
691,
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
235
|
+
696,
|
236
|
+
701,
|
237
|
+
707,
|
238
|
+
714,
|
239
|
+
720,
|
240
|
+
729,
|
241
|
+
736,
|
242
|
+
745,
|
243
|
+
755
|
236
244
|
};
|
237
245
|
|
238
246
|
const char *get_node_type_string(enum node_type node) {
|
239
|
-
if(node <
|
247
|
+
if(node < 115) {
|
240
248
|
return node_types + node_types_offsets[node];
|
241
249
|
} else {
|
242
250
|
#define NODE_STRING_MESSAGE_LEN 20
|
@@ -38,6 +38,7 @@ namespace MELBOURNE {
|
|
38
38
|
NODE_OP_ASGN2,
|
39
39
|
NODE_OP_ASGN_AND,
|
40
40
|
NODE_OP_ASGN_OR,
|
41
|
+
NODE_OP_CDECL,
|
41
42
|
NODE_CALL,
|
42
43
|
NODE_FCALL,
|
43
44
|
NODE_VCALL,
|
@@ -71,6 +72,7 @@ namespace MELBOURNE {
|
|
71
72
|
NODE_ARGS,
|
72
73
|
NODE_ARGS_AUX,
|
73
74
|
NODE_OPT_ARG,
|
75
|
+
NODE_KW_ARG,
|
74
76
|
NODE_POSTARG,
|
75
77
|
NODE_ARGSCAT,
|
76
78
|
NODE_ARGSPUSH,
|
@@ -114,7 +116,9 @@ namespace MELBOURNE {
|
|
114
116
|
NODE_NUMBER,
|
115
117
|
NODE_FLOAT,
|
116
118
|
NODE_ENCODING,
|
117
|
-
NODE_PREEXE
|
119
|
+
NODE_PREEXE,
|
120
|
+
NODE_RATIONAL,
|
121
|
+
NODE_IMAGINARY
|
118
122
|
};
|
119
123
|
|
120
124
|
const char *get_node_type_string(enum node_type nt);
|
@@ -33,6 +33,7 @@ node_types = %w[
|
|
33
33
|
op_asgn2
|
34
34
|
op_asgn_and
|
35
35
|
op_asgn_or
|
36
|
+
op_cdecl
|
36
37
|
call
|
37
38
|
fcall
|
38
39
|
vcall
|
@@ -66,6 +67,7 @@ node_types = %w[
|
|
66
67
|
args
|
67
68
|
args_aux
|
68
69
|
opt_arg
|
70
|
+
kw_arg
|
69
71
|
postarg
|
70
72
|
argscat
|
71
73
|
argspush
|
@@ -110,6 +112,8 @@ node_types = %w[
|
|
110
112
|
float
|
111
113
|
encoding
|
112
114
|
preexe
|
115
|
+
rational
|
116
|
+
imaginary
|
113
117
|
]
|
114
118
|
|
115
119
|
def write_node_types(list)
|
@@ -117,6 +121,7 @@ def write_node_types(list)
|
|
117
121
|
f.puts <<EOF
|
118
122
|
/* This file is generated by node_types.rb. Do not edit. */
|
119
123
|
|
124
|
+
#include "namespace.h"
|
120
125
|
#include "node_types.hpp"
|
121
126
|
|
122
127
|
#include <stdio.h>
|
@@ -12,21 +12,42 @@
|
|
12
12
|
|
13
13
|
namespace MELBOURNE {
|
14
14
|
|
15
|
-
enum
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
15
|
+
enum lex_state_bits {
|
16
|
+
EXPR_BEG_BIT = 0, /* ignore newline, +/- is a sign. */
|
17
|
+
EXPR_END_BIT, /* newline significant, +/- is an operator. */
|
18
|
+
EXPR_ENDARG_BIT, /* ditto, and unbound braces. */
|
19
|
+
EXPR_ENDFN_BIT, /* ditto, and unbound braces. */
|
20
|
+
EXPR_ARG_BIT, /* newline significant, +/- is an operator. */
|
21
|
+
EXPR_CMDARG_BIT, /* newline significant, +/- is an operator. */
|
22
|
+
EXPR_MID_BIT, /* newline significant, +/- is an operator. */
|
23
|
+
EXPR_FNAME_BIT, /* ignore newline, no reserved words. */
|
24
|
+
EXPR_DOT_BIT, /* right after `.' or `::', no reserved words. */
|
25
|
+
EXPR_CLASS_BIT, /* immediate after `class', no here document. */
|
26
|
+
EXPR_VALUE_BIT, /* like EXPR_BEG but label is disallowed. */
|
27
27
|
EXPR_MAX_STATE
|
28
28
|
};
|
29
29
|
|
30
|
+
enum lex_state_e {
|
31
|
+
#define EXPR(e) EXPR_##e = (1 << EXPR_##e##_BIT)
|
32
|
+
EXPR(BEG),
|
33
|
+
EXPR(END),
|
34
|
+
EXPR(ENDARG),
|
35
|
+
EXPR(ENDFN),
|
36
|
+
EXPR(ARG),
|
37
|
+
EXPR(CMDARG),
|
38
|
+
EXPR(MID),
|
39
|
+
EXPR(FNAME),
|
40
|
+
EXPR(DOT),
|
41
|
+
EXPR(CLASS),
|
42
|
+
EXPR(VALUE),
|
43
|
+
EXPR_BEG_ANY = (EXPR_BEG | EXPR_VALUE | EXPR_MID | EXPR_CLASS),
|
44
|
+
EXPR_ARG_ANY = (EXPR_ARG | EXPR_CMDARG),
|
45
|
+
EXPR_END_ANY = (EXPR_END | EXPR_ENDARG | EXPR_ENDFN)
|
46
|
+
};
|
47
|
+
|
48
|
+
#define lex_state_of_p(x, s) ((x) & (s))
|
49
|
+
#define lex_state_p(s) lex_state_of_p(lex_state, s)
|
50
|
+
|
30
51
|
typedef VALUE stack_type;
|
31
52
|
|
32
53
|
struct StartPosition {
|
@@ -50,11 +71,13 @@ typedef VALUE stack_type;
|
|
50
71
|
int class_nest;
|
51
72
|
int in_single;
|
52
73
|
int in_def;
|
74
|
+
int brace_nest;
|
53
75
|
int compile_for_eval;
|
54
76
|
ID cur_mid;
|
55
77
|
char *token_buffer;
|
56
78
|
int tokidx;
|
57
79
|
int toksiz;
|
80
|
+
int tokline;
|
58
81
|
int emit_warnings;
|
59
82
|
/* Mirror'ing the 1.8 parser, There are 2 input methods,
|
60
83
|
from IO and directly from a string. */
|
@@ -77,9 +100,9 @@ typedef VALUE stack_type;
|
|
77
100
|
VALUE lex_lastline;
|
78
101
|
VALUE lex_nextline;
|
79
102
|
|
80
|
-
char *lex_pbeg;
|
81
|
-
char *lex_p;
|
82
|
-
char *lex_pend;
|
103
|
+
const char *lex_pbeg;
|
104
|
+
const char *lex_p;
|
105
|
+
const char *lex_pend;
|
83
106
|
int lex_str_used;
|
84
107
|
|
85
108
|
enum lex_state_e lex_state;
|
@@ -143,11 +166,13 @@ typedef VALUE stack_type;
|
|
143
166
|
#define class_nest PARSER_VAR(class_nest)
|
144
167
|
#define in_single PARSER_VAR(in_single)
|
145
168
|
#define in_def PARSER_VAR(in_def)
|
169
|
+
#define brace_nest PARSER_VAR(brace_nest)
|
146
170
|
#define compile_for_eval PARSER_VAR(compile_for_eval)
|
147
171
|
#define cur_mid PARSER_VAR(cur_mid)
|
148
172
|
#define tokenbuf PARSER_VAR(token_buffer)
|
149
173
|
#define tokidx PARSER_VAR(tokidx)
|
150
174
|
#define toksiz PARSER_VAR(toksiz)
|
175
|
+
#define tokline PARSER_VAR(tokline)
|
151
176
|
#define emit_warnings PARSER_VAR(emit_warnings)
|
152
177
|
#define lex_gets PARSER_VAR(lex_gets)
|
153
178
|
#define line_buffer PARSER_VAR(line_buffer)
|
@@ -57,8 +57,10 @@ namespace MELBOURNE {
|
|
57
57
|
ID rb_sHash;
|
58
58
|
ID rb_sIAsgn;
|
59
59
|
ID rb_sIf;
|
60
|
+
ID rb_sImaginary;
|
60
61
|
ID rb_sIter;
|
61
62
|
ID rb_sIVar;
|
63
|
+
ID rb_sKwArg;
|
62
64
|
ID rb_sLAsgn;
|
63
65
|
ID rb_sLambda;
|
64
66
|
ID rb_sLit;
|
@@ -83,6 +85,7 @@ namespace MELBOURNE {
|
|
83
85
|
ID rb_sPostExe;
|
84
86
|
ID rb_sPostArg;
|
85
87
|
ID rb_sPreExe;
|
88
|
+
ID rb_sRational;
|
86
89
|
ID rb_sRedo;
|
87
90
|
ID rb_sRegex;
|
88
91
|
ID rb_sResbody;
|
@@ -169,8 +172,10 @@ namespace MELBOURNE {
|
|
169
172
|
rb_sHash = rb_intern("process_hash");
|
170
173
|
rb_sIAsgn = rb_intern("process_iasgn");
|
171
174
|
rb_sIf = rb_intern("process_if");
|
175
|
+
rb_sImaginary = rb_intern("process_imaginary");
|
172
176
|
rb_sIter = rb_intern("process_iter");
|
173
177
|
rb_sIVar = rb_intern("process_ivar");
|
178
|
+
rb_sKwArg = rb_intern("process_kw_arg");
|
174
179
|
rb_sLAsgn = rb_intern("process_lasgn");
|
175
180
|
rb_sLambda = rb_intern("process_lambda");
|
176
181
|
rb_sLit = rb_intern("process_lit");
|
@@ -195,6 +200,7 @@ namespace MELBOURNE {
|
|
195
200
|
rb_sPostExe = rb_intern("process_postexe");
|
196
201
|
rb_sPostArg = rb_intern("process_postarg");
|
197
202
|
rb_sPreExe = rb_intern("process_preexe");
|
203
|
+
rb_sRational = rb_intern("process_rational");
|
198
204
|
rb_sRedo = rb_intern("process_redo");
|
199
205
|
rb_sRegex = rb_intern("process_regex");
|
200
206
|
rb_sResbody = rb_intern("process_resbody");
|