yarv_generator 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/yarv_generator/yarv_generator.c +35 -19
- data/lib/yarv_generator/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b3d4a956c5122dad94eb6a5cd46bf134e2603217
|
4
|
+
data.tar.gz: 9ac66e7f566b0f619ab17ab03cae536ba0d5d331
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90d07824dba96aaa7e12a26e27a29fc656fdfe4de7644cd32d44cbf3cd12bce0ec0278115a36f5a96b854050d7992564b086064cbcaf23407cf79c43b3104746
|
7
|
+
data.tar.gz: 838eaf818a0b2cddaaad3844970c25d19665f0da9478b688c594f23f529082ed8765086d1b2cf923c4e57bd3e0151f9c234a5f17dbc6dd8731387dd3617e1cb1
|
@@ -39,16 +39,20 @@ yarv_builder_build_yarv_tree(rb_iseq_t *iseq)
|
|
39
39
|
VALUE type = yarv_builder_insn_type(iseq);
|
40
40
|
rb_funcall(iseq_object, rb_intern("type="), 1, type);
|
41
41
|
|
42
|
-
VALUE local_table
|
42
|
+
VALUE local_table;
|
43
|
+
local_table = yarv_builder_local_table(iseq);
|
43
44
|
rb_funcall(iseq_object, rb_intern("local_table="), 1, local_table);
|
44
45
|
|
45
|
-
VALUE params
|
46
|
+
VALUE params;
|
47
|
+
params = yarv_builder_params(iseq, labels_table);
|
46
48
|
rb_funcall(iseq_object, rb_intern("params="), 1, params);
|
47
49
|
|
48
|
-
VALUE catch_table
|
50
|
+
VALUE catch_table;
|
51
|
+
catch_table = yarv_builder_catch_table(iseq, labels_table);
|
49
52
|
rb_funcall(iseq_object, rb_intern("catch_table="), 1, catch_table);
|
50
53
|
|
51
|
-
VALUE instructions
|
54
|
+
VALUE instructions;
|
55
|
+
instructions = yarv_builder_instructions(iseq, labels_table);
|
52
56
|
rb_funcall(iseq_object, rb_intern("instructions="), 1, instructions);
|
53
57
|
|
54
58
|
rb_funcall(iseq_object, rb_intern("label="), 1, iseq->body->location.label);
|
@@ -103,8 +107,10 @@ yarv_builder_insn_type(rb_iseq_t *iseq)
|
|
103
107
|
VALUE
|
104
108
|
yarv_builder_local_table(rb_iseq_t *iseq)
|
105
109
|
{
|
106
|
-
VALUE local_table
|
107
|
-
|
110
|
+
VALUE local_table;
|
111
|
+
local_table = rb_ary_new();
|
112
|
+
unsigned int i;
|
113
|
+
for (i = 0; i < iseq->body->local_table_size; i++) {
|
108
114
|
ID var_id = iseq->body->local_table[i];
|
109
115
|
if (var_id) {
|
110
116
|
if (rb_id2str(var_id)) {
|
@@ -130,14 +136,19 @@ yarv_builder_instructions(rb_iseq_t *iseq, st_table *labels_table)
|
|
130
136
|
|
131
137
|
VALUE *iseq_original = rb_iseq_original_iseq((rb_iseq_t *)iseq);
|
132
138
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
139
|
+
VALUE *seq;
|
140
|
+
VALUE insn;
|
141
|
+
VALUE *nseq;
|
142
|
+
int len;
|
143
|
+
int j;
|
137
144
|
|
138
|
-
|
145
|
+
for (seq = iseq_original; seq < iseq_original + iseq->body->iseq_size; ) {
|
146
|
+
insn = *seq++;
|
147
|
+
len = insn_len_info[(int)insn];
|
148
|
+
VALUE operands = rb_ary_new2(len);
|
149
|
+
nseq = seq + len;
|
139
150
|
|
140
|
-
for (
|
151
|
+
for (j = 0; j < len - 1; j++, seq++) {
|
141
152
|
VALUE operand = Qnil;
|
142
153
|
switch (insn_op_type(insn, j)) {
|
143
154
|
case TS_LINDEX:
|
@@ -198,7 +209,8 @@ yarv_builder_instructions(rb_iseq_t *iseq, st_table *labels_table)
|
|
198
209
|
operand = rb_ary_new();
|
199
210
|
rb_hash_foreach(hash, cdhash_each, operand);
|
200
211
|
|
201
|
-
|
212
|
+
int i;
|
213
|
+
for (i=0; i<RARRAY_LEN(operand); i+=2) {
|
202
214
|
VALUE pos = FIX2INT(rb_ary_entry(operand, i+1));
|
203
215
|
unsigned long idx = nseq - iseq_original + pos;
|
204
216
|
|
@@ -217,8 +229,9 @@ yarv_builder_instructions(rb_iseq_t *iseq, st_table *labels_table)
|
|
217
229
|
rb_ary_push(instructions, insn_object);
|
218
230
|
}
|
219
231
|
|
220
|
-
|
221
|
-
|
232
|
+
unsigned int ip, pos, line_pos;
|
233
|
+
for (ip = 0, pos = 0, line_pos = 0; ip < RARRAY_LEN(instructions); ip++) {
|
234
|
+
VALUE instruction = RARRAY_AREF(instructions, ip);
|
222
235
|
|
223
236
|
st_data_t label;
|
224
237
|
if (st_lookup(labels_table, pos, &label)) {
|
@@ -242,9 +255,10 @@ VALUE yarv_builder_params(rb_iseq_t *iseq, st_table *labels_table) {
|
|
242
255
|
rb_hash_aset(params, ID2SYM(rb_intern("lead_num")), INT2FIX(iseq->body->param.lead_num));
|
243
256
|
}
|
244
257
|
|
258
|
+
int i;
|
245
259
|
if (iseq->body->param.flags.has_opt) {
|
246
260
|
VALUE opts = rb_ary_new2(iseq->body->param.opt_num);
|
247
|
-
for (
|
261
|
+
for (i = 0; i < iseq->body->param.opt_num; i++) {
|
248
262
|
VALUE value = iseq->body->param.opt_table[i];
|
249
263
|
register_label(labels_table, value);
|
250
264
|
rb_ary_push(opts, value);
|
@@ -264,7 +278,7 @@ VALUE yarv_builder_params(rb_iseq_t *iseq, st_table *labels_table) {
|
|
264
278
|
if (iseq->body->param.flags.has_kw) {
|
265
279
|
VALUE keywords = rb_ary_new();
|
266
280
|
int j = 0;
|
267
|
-
for (
|
281
|
+
for (i = 0; i < iseq->body->param.keyword->num; i++) {
|
268
282
|
if (i < iseq->body->param.keyword->required_num) {
|
269
283
|
// Require params
|
270
284
|
rb_ary_push(keywords, ID2SYM(iseq->body->param.keyword->table[i]));
|
@@ -295,8 +309,9 @@ VALUE yarv_builder_catch_table(rb_iseq_t *iseq, st_table *labels_table) {
|
|
295
309
|
VALUE catch_table = rb_ary_new();
|
296
310
|
VALUE rb_cYarvCatchEntry = rb_path2class("YarvGenerator::CatchEntry");
|
297
311
|
|
312
|
+
unsigned int i;
|
298
313
|
if (iseq->body->catch_table) {
|
299
|
-
for (
|
314
|
+
for (i = 0; i < iseq->body->catch_table->size; i++) {
|
300
315
|
VALUE catch_entry = rb_funcall(rb_cYarvCatchEntry, rb_intern("new"), 0);
|
301
316
|
|
302
317
|
const struct iseq_catch_table_entry *entry = &iseq->body->catch_table->entries[i];
|
@@ -350,7 +365,8 @@ yarv_builder_call_info(VALUE *seq)
|
|
350
365
|
struct rb_call_info_with_kwarg *ci_kw = (struct rb_call_info_with_kwarg *)ci;
|
351
366
|
VALUE kw = rb_ary_new2(ci_kw->kw_arg->keyword_len);
|
352
367
|
int len = ci->orig_argc - ci_kw->kw_arg->keyword_len;
|
353
|
-
|
368
|
+
int i;
|
369
|
+
for (i = 0; i < len; i++) {
|
354
370
|
rb_ary_push(kw, ci_kw->kw_arg->keywords[i]);
|
355
371
|
}
|
356
372
|
rb_funcall(ci_object, rb_intern("kw_arg="), 1, kw);
|