~ubuntu-branches/ubuntu/intrepid/ruby1.9/intrepid-updates

« back to all changes in this revision

Viewing changes to insns.def

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2007-09-04 16:01:17 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20070904160117-i15zckg2nhxe9fyw
Tags: 1.9.0+20070830-2ubuntu1
* Sync from Debian; remaining changes:
  - Add -g to CFLAGS.
* Fixes build failure on ia64.
* Fixes build failure with gcc-4.2 on lpia.
* Robustify check for target_os, fixing build failure on lpia.
* Set Ubuntu maintainer address.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/** ##skip
2
 
  -*-c-*-
 
1
/** ##skip -*- mode:c; style:ruby -*-
3
2
  insns.def - YARV instruction definitions
4
3
 
5
4
  $Author: $
81
80
 */
82
81
DEFINE_INSN
83
82
getspecial
84
 
(rb_num_t idx, rb_num_t type)
 
83
(VALUE key, rb_num_t type)
85
84
()
86
85
(VALUE val)
87
86
{
88
 
    if (type == 0) {
89
 
        VALUE *pv = lfp_svar(GET_LFP(), idx);
90
 
        val = *pv;
91
 
    }
92
 
    else {
93
 
        VALUE backref = *lfp_svar(GET_LFP(), 1);
94
 
        if (type & 0x01) {
95
 
            switch (type >> 1) {
96
 
            case '&':
97
 
                val = rb_reg_last_match(backref);
98
 
                break;
99
 
            case '`':
100
 
                val = rb_reg_match_pre(backref);
101
 
                break;
102
 
            case '\'':
103
 
                val = rb_reg_match_post(backref);
104
 
                break;
105
 
            case '+':
106
 
                val = rb_reg_match_last(backref);
107
 
                break;
108
 
            default:
109
 
                rb_bug("unexpected back-ref");
110
 
            }
111
 
        }
112
 
        else {
113
 
            val = rb_reg_nth_match(type >> 1, backref);
114
 
        }
115
 
    }
 
87
    val = vm_getspecial(th, GET_LFP(), key, type);
116
88
}
117
89
 
118
90
/**
122
94
 */
123
95
DEFINE_INSN
124
96
setspecial
125
 
(rb_num_t idx)
 
97
(VALUE key)
126
98
(VALUE obj)
127
99
()
128
100
{
129
 
    VALUE *pv = lfp_svar(GET_LFP(), idx);
130
 
    *pv = obj;
 
101
    lfp_svar_set(th, GET_LFP(), key, obj);
131
102
}
132
103
 
133
104
/**
215
186
()
216
187
(VALUE val)
217
188
{
218
 
    VALUE klass = eval_get_cvar_base(th, GET_ISEQ());
 
189
    VALUE klass = vm_get_cvar_base(th, GET_ISEQ());
219
190
    val = rb_cvar_get(klass, id);
220
191
}
221
192
 
230
201
(VALUE val)
231
202
()
232
203
{
233
 
    rb_cvar_set(eval_get_cvar_base(th, GET_ISEQ()), id, val);
 
204
    rb_cvar_set(vm_get_cvar_base(th, GET_ISEQ()), id, val);
234
205
}
235
206
 
236
207
/**
251
222
(VALUE klass)
252
223
(VALUE val)
253
224
{
254
 
    val = eval_get_ev_const(th, GET_ISEQ(), klass, id, 0);
 
225
    val = vm_get_ev_const(th, GET_ISEQ(), klass, id, 0);
255
226
}
256
227
 
257
228
/**
275
246
()
276
247
{
277
248
    if (klass == Qnil) {
278
 
        klass = th_get_cbase(th);
 
249
        klass = vm_get_cbase(th);
279
250
    }
280
251
    if (NIL_P(klass)) {
281
252
        rb_raise(rb_eTypeError, "no class/module to define constant");
282
253
    }
283
254
 
284
255
    switch (TYPE(klass)) {
285
 
    case T_CLASS:
286
 
    case T_MODULE:
 
256
      case T_CLASS:
 
257
      case T_MODULE:
287
258
        break;
288
 
    default:
 
259
      default: {
 
260
        volatile VALUE tmp = rb_obj_as_string(klass);
289
261
        rb_raise(rb_eTypeError, "%s is not a class/module",
290
 
                 RSTRING_PTR(rb_obj_as_string(klass)));
 
262
                 RSTRING_PTR(tmp));
 
263
      }
291
264
    }
292
265
 
293
266
    rb_const_set(klass, id, val);
357
330
 
358
331
/**
359
332
  @c put
360
 
  @e put Qundef.  DO NOT USE in NORMAL RUBY PROGRAM
361
 
  @j put Qundef.
362
 
 */
363
 
DEFINE_INSN
364
 
putundef
365
 
()
366
 
()
367
 
(VALUE val)
368
 
{
369
 
    val = Qundef;
370
 
}
371
 
 
372
 
/**
373
 
  @c put
374
333
  @e put some object.
375
334
     i.e. Fixnum, true, false, nil, and so on.
376
335
  @j �I�u�W�F�N�g��u���Bi.e. Fixnum, true, false, nil, and so on.
392
351
 
393
352
DEFINE_INSN
394
353
putstring
395
 
(VALUE val)
 
354
(VALUE str)
396
355
()
397
356
(VALUE val)
398
357
{
399
 
    val = rb_str_new3(val);
 
358
    val = rb_str_new3(str);
400
359
}
401
360
 
402
361
/**
446
405
(VALUE str)
447
406
(VALUE val)
448
407
{
449
 
    val = rb_reg_new(RSTRING_PTR(str), RSTRING_LEN(str), flag);
 
408
    volatile VALUE tmp = str; /* for GC */
 
409
    val = rb_reg_new(str, flag);
450
410
}
451
411
 
452
412
/**
486
446
     num�ȏ�̗v�f�͐؂�̂Ă�B
487
447
     �z��I�u�W�F�N�g�łȂ���΁Anum - 1 �‚� nil ��ςށB
488
448
     ���� flag ���^�Ȃ�A�c��v�f�̔z���ς�
 
449
     flag: 0x01 - �Ō��z���
 
450
     flag: 0x02 - postarg �p
 
451
     flag: 0x04 - reverse?
489
452
 */
490
453
DEFINE_INSN
491
454
expandarray
492
455
(rb_num_t num, rb_num_t flag)
493
456
(..., VALUE ary)
494
 
(...) // inc += (num > 0) ? num - 1 + (flag ? 1 : 0) : num + 1 - (flag ? 1 : 0);
 
457
(...) // inc += flag == 0x02 ? num : ((num > 0) ? num - 1 + (flag ? 1 : 0) : num + 1 - (flag ? 1 : 0));
495
458
{
496
 
    int i;
497
 
    if ((long)num >= 0) {
498
 
        int len;
499
 
        if (TYPE(ary) != T_ARRAY) {
500
 
            ary = rb_ary_to_ary(ary);
501
 
        }
502
 
        len = RARRAY_LEN(ary);
503
 
        for (i = 0; i < len && i < num; i++) {
504
 
            PUSH(RARRAY_PTR(ary)[i]);
505
 
        }
506
 
        for (; i < num; i++) {
507
 
            PUSH(Qnil);
508
 
        }
509
 
        if (flag) {
510
 
            if (len > num) {
511
 
                PUSH(rb_ary_new4(len - num, &RARRAY_PTR(ary)[num]));
512
 
            }
513
 
            else {
514
 
                PUSH(rb_ary_new());
515
 
            }
516
 
        }
517
 
    }
518
 
    else {
519
 
        long holdnum = -num;
520
 
        VALUE val;
521
 
 
522
 
        val = rb_ary_new4(holdnum, STACK_ADDR_FROM_TOP(holdnum));
523
 
        if (CLASS_OF(ary) == rb_cArray) {
524
 
            val = rb_ary_concat(val, ary);
525
 
        }
526
 
        else {
527
 
            rb_ary_push(val, ary);
528
 
        }
529
 
        POPN(holdnum);
530
 
        PUSH(val);
531
 
    }
 
459
    vm_expandarray(GET_CFP(), ary, num, flag);
532
460
}
533
461
 
534
462
/**
543
471
(VALUE ary)
544
472
{
545
473
    VALUE ary2 = ary2st;
546
 
 
547
 
    if (ary2 == Qnil) {
548
 
        ary = ary1;
549
 
    }
550
 
    else {
551
 
        VALUE tmp1 = rb_check_convert_type(ary1, T_ARRAY, "Array", "to_splat");
552
 
        VALUE tmp2 = rb_check_convert_type(ary2, T_ARRAY, "Array", "to_splat");
553
 
 
554
 
        if (NIL_P(tmp1)) {
555
 
            tmp1 = rb_ary_new3(1, ary1);
556
 
        }
557
 
        
558
 
        if (NIL_P(tmp2)) {
559
 
            tmp2 = rb_ary_new3(1, ary2);
560
 
        }
561
 
 
562
 
        if (tmp1 == ary1) {
563
 
            tmp1 = rb_ary_dup(ary1);
564
 
        }
565
 
        ary = rb_ary_concat(tmp1, tmp2);
566
 
    }
 
474
    VALUE tmp1 = rb_check_convert_type(ary1, T_ARRAY, "Array", "to_splat");
 
475
    VALUE tmp2 = rb_check_convert_type(ary2, T_ARRAY, "Array", "to_splat");
 
476
 
 
477
    if (NIL_P(tmp1)) {
 
478
        tmp1 = rb_ary_new3(1, ary1);
 
479
    }
 
480
 
 
481
    if (NIL_P(tmp2)) {
 
482
        tmp2 = rb_ary_new3(1, ary2);
 
483
    }
 
484
 
 
485
    if (tmp1 == ary1) {
 
486
        tmp1 = rb_ary_dup(ary1);
 
487
    }
 
488
    ary = rb_ary_concat(tmp1, tmp2);
567
489
}
568
490
 
569
491
/**
582
504
        tmp = rb_ary_new3(1, ary);
583
505
    }
584
506
    obj = tmp;
585
 
    
586
 
    if (0) {
587
 
        if (flag == Qfalse) {
588
 
            /* NODE_SPLAT */
589
 
            obj = rb_Array(ary);
590
 
        }
591
 
        else {
592
 
            /* NODE_SVALUE */
593
 
            if (RARRAY_LEN(ary) == 0) {
594
 
                obj = Qnil;
595
 
            }
596
 
            else if (RARRAY_LEN(ary) == 1) {
597
 
                obj = RARRAY_PTR(ary)[0];
598
 
            }
599
 
            else {
600
 
                obj = ary;
601
 
            }
602
 
        }
603
 
    }
604
507
}
605
508
 
606
509
/**
839
742
(VALUE obj)
840
743
()
841
744
{
842
 
    eval_define_method(th, obj, id, body, is_singleton,
843
 
                       get_cref(GET_ISEQ(), GET_LFP()));
 
745
    vm_define_method(th, obj, id, body, is_singleton,
 
746
                     get_cref(GET_ISEQ(), GET_LFP()));
844
747
}
845
748
 
846
749
/**
920
823
        break;
921
824
      case DEFINED_CONST:
922
825
        klass = v;
923
 
        if (eval_get_ev_const(th, GET_ISEQ(), klass, SYM2ID(obj), 1)) {
 
826
        if (vm_get_ev_const(th, GET_ISEQ(), klass, SYM2ID(obj), 1)) {
924
827
            expr_type = "constant";
925
828
        }
926
829
        break;
959
862
              ip = ip->parent_iseq;
960
863
          }
961
864
          if (ip) {
962
 
              VALUE klass = search_super_klass(ip->klass, GET_SELF());
 
865
              VALUE klass = vm_search_normal_super_klass(ip->klass, GET_SELF());
963
866
              if (rb_method_boundp(klass, ip->defined_method_id, 0)) {
964
867
                  expr_type = "super";
965
868
              }
968
871
      }
969
872
      case DEFINED_REF:{
970
873
          int nth = FIX2INT(obj);
971
 
          VALUE backref = *lfp_svar(GET_LFP(), 1);
 
874
          VALUE backref = lfp_svar_get(th, GET_LFP(), 1);
972
875
          
973
876
          if (rb_reg_nth_match(nth, backref) != Qnil) {
974
877
              snprintf(buf, 0x10, "$%d", nth);
1008
911
    blockptr->iseq = blockiseq;
1009
912
    blockptr->proc = 0;
1010
913
 
1011
 
    proc = th_make_proc(th, GET_CFP(), blockptr);
1012
 
    rb_set_end_proc(call_yarv_end_proc, proc);
 
914
    proc = vm_make_proc(th, GET_CFP(), blockptr);
 
915
    rb_set_end_proc(call_end_proc, proc);
1013
916
}
1014
917
 
1015
918
/**
1048
951
{
1049
952
    VALUE klass;
1050
953
 
1051
 
    if (define_type == 0) {
 
954
    switch ((int)define_type) {
 
955
      case 0:
1052
956
        /* val is dummy.  classdef returns class scope value */
1053
957
 
1054
958
        if (super == Qnil) {
1056
960
        }
1057
961
 
1058
962
        if (cbase == Qnil) {
1059
 
            cbase = th_get_cbase(th);
 
963
            cbase = vm_get_cbase(th);
1060
964
        }
1061
965
 
1062
966
        /* find klass */
1084
988
            rb_const_set(cbase, id, klass);
1085
989
            rb_class_inherited(super, klass);
1086
990
        }
1087
 
    }
1088
 
    else if (define_type == 1) {
 
991
        break;
 
992
      case 1:
1089
993
        /* val is dummy.  classdef returns class scope value */
1090
994
        /* super is dummy */
1091
995
        klass = rb_singleton_class(cbase);
1092
 
    }
1093
 
    else if (define_type == 2) {
 
996
        break;
 
997
      case 2:
1094
998
        /* val is dummy.  classdef returns class scope value */
1095
999
        /* super is dummy */
1096
1000
        if (cbase == Qnil) {
1097
 
            cbase = th_get_cbase(th);
 
1001
            cbase = vm_get_cbase(th);
1098
1002
        }
1099
1003
 
1100
1004
        /* find klass */
1111
1015
            rb_set_class_path(klass, cbase, rb_id2name(id));
1112
1016
            rb_const_set(cbase, id, klass);
1113
1017
        }
1114
 
    }
1115
 
    else {
1116
 
        rb_bug("unknown defineclass type: %d", define_type);
1117
 
    }
1118
 
    
1119
 
    COPY_CREF(klass_iseq->cref_stack, th_cref_push(th, klass, NOEX_PUBLIC));
1120
 
    
 
1018
        break;
 
1019
      default:
 
1020
        rb_bug("unknown defineclass type: %d", (int)define_type);
 
1021
    }
 
1022
 
 
1023
    COPY_CREF(klass_iseq->cref_stack, vm_cref_push(th, klass, NOEX_PUBLIC));
 
1024
 
1121
1025
    /* enter scope */
1122
 
    push_frame(th, klass_iseq,
1123
 
               FRAME_MAGIC_CLASS, klass, (VALUE) GET_DFP() | 0x02,
1124
 
               klass_iseq->iseq_encoded, GET_SP(), 0,
1125
 
               klass_iseq->local_size);
 
1026
    vm_push_frame(th, klass_iseq,
 
1027
                  FRAME_MAGIC_CLASS, klass, (VALUE) GET_DFP() | 0x02,
 
1028
                  klass_iseq->iseq_encoded, GET_SP(), 0,
 
1029
                  klass_iseq->local_size);
1126
1030
    RESTORE_REGS();
1127
1031
 
1128
1032
    INC_VM_STATE_VERSION();
1150
1054
(VALUE val) // inc += - (op_argc + ((op_flag & VM_CALL_ARGS_BLOCKARG_BIT) ? 1 : 0));
1151
1055
{
1152
1056
    NODE *mn;
1153
 
    VALUE recv;
1154
 
    VALUE klass;
 
1057
    VALUE recv, klass;
1155
1058
    rb_block_t *blockptr = 0;
1156
 
    rb_num_t num = op_argc;
 
1059
    rb_num_t num = caller_setup_args(th, GET_CFP(), op_flag, op_argc, (rb_iseq_t *)blockiseq, &blockptr);
1157
1060
    rb_num_t flag = op_flag;
1158
1061
    ID id = op_id;
1159
1062
 
1160
 
    macro_eval_setup_send_arguments(num, blockptr, flag, blockiseq);
1161
 
 
1162
 
    if (flag & VM_CALL_FCALL_BIT) {
1163
 
        /* method(...) */
1164
 
        recv = GET_SELF();
1165
 
    }
1166
 
    else {
1167
 
        /* recv.method(...) */
1168
 
        recv = TOPN(num);
1169
 
    }
1170
 
 
 
1063
    /* get receiver */
 
1064
    recv = (flag & VM_CALL_FCALL_BIT) ? GET_SELF() : TOPN(num);
1171
1065
    klass = CLASS_OF(recv);
1172
 
 
1173
 
    mn = eval_method_search(id, klass, ic);
1174
 
 
1175
 
    if ((flag & VM_CALL_SEND_BIT) && mn && nd_type(mn->nd_body) == NODE_CFUNC) {
1176
 
        NODE *node = mn->nd_body;
1177
 
        extern VALUE rb_f_funcall(int argc, VALUE *argv, VALUE recv);
1178
 
        extern VALUE rb_f_send(int argc, VALUE *argv, VALUE recv);
1179
 
 
1180
 
        if (node->nd_cfnc == rb_f_funcall || node->nd_cfnc == rb_f_send) {
1181
 
            int i;
1182
 
            VALUE sym = TOPN(num - 1);
1183
 
            id = SYMBOL_P(sym) ? SYM2ID(sym) : rb_to_id(sym);
1184
 
 
1185
 
            /* shift arguments */
1186
 
            for (i=num-1; i>0; i--) {
1187
 
                TOPN(i) = TOPN(i-1);
1188
 
            }
1189
 
 
1190
 
            mn = rb_method_node(klass, id);
1191
 
 
1192
 
            num -= 1;
1193
 
            DEC_SP(1);
1194
 
        }
1195
 
 
1196
 
        if (node->nd_cfnc == rb_f_funcall) {
1197
 
            flag |= VM_CALL_FCALL_BIT;
1198
 
        }
1199
 
    }
1200
 
 
1201
 
#if CURRENT_INSN_send || CURRENT_INSN_send_SC_xx_ax
1202
 
#if !YARV_AOT_COMPILED
1203
 
    if (0) {
1204
 
        if (0) {
1205
 
            LABEL_IS_SC(start_init_in_send_for_opt_1):
1206
 
            num = 1;
1207
 
            recv = TOPN(1);
1208
 
        }
1209
 
        else if (0) {
1210
 
            LABEL_IS_SC(start_init_in_send_for_opt_2):
1211
 
            num = 2;
1212
 
            recv = TOPN(2);
1213
 
        }
1214
 
        flag = 0;
1215
 
        id = tmp_id;
1216
 
        klass = CLASS_OF(recv);
1217
 
        blockptr = 0;
1218
 
        mn = rb_method_node(klass, id);
1219
 
    }
1220
 
    if (0) {
1221
 
        LABEL_IS_SC(start_init_in_super):
1222
 
        {
1223
 
            rb_iseq_t *iseq = GET_ISEQ();
1224
 
            rb_iseq_t *ip = iseq;
1225
 
 
1226
 
            num = tmp_num;
1227
 
            flag = VM_CALL_FCALL_BIT;
1228
 
            recv = GET_SELF();
1229
 
 
1230
 
            while (ip && !ip->klass) {
1231
 
                ip = ip->parent_iseq;
1232
 
            }
1233
 
 
1234
 
            if (ip == 0) {
1235
 
                rb_raise(rb_eNoMethodError, "super called outside of method");
1236
 
            }
1237
 
 
1238
 
            id = ip->defined_method_id;
1239
 
            
1240
 
            if (ip != ip->local_iseq) {
1241
 
                /* defined by Module#define_method() */
1242
 
                rb_control_frame_t *lcfp = GET_CFP();
1243
 
 
1244
 
                while (lcfp->iseq != ip) {
1245
 
                    VALUE *tdfp = GET_PREV_DFP(lcfp->dfp);
1246
 
                    while (1) {
1247
 
                        lcfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(lcfp);
1248
 
                        if (lcfp->dfp == tdfp) {
1249
 
                            break;
1250
 
                        }
1251
 
                    }
1252
 
                }
1253
 
 
1254
 
                id = lcfp->method_id;
1255
 
                klass = search_super_klass(lcfp->method_klass, recv);
1256
 
 
1257
 
                if (TOPN(num) == Qfalse) {
1258
 
                    /* for ZSUPER */
1259
 
                    int i;
1260
 
                    POPN(num);
1261
 
                    num = ip->argc;
1262
 
                    for (i = 0; i < ip->argc; i++) {
1263
 
                        PUSH(lcfp->dfp[i - ip->local_size]);
1264
 
                    }
1265
 
                }
1266
 
            }
1267
 
            else {
1268
 
            klass = search_super_klass(ip->klass, recv);
1269
 
            }
1270
 
 
1271
 
            flag = VM_CALL_SUPER_BIT | VM_CALL_FCALL_BIT;
1272
 
            blockptr = tmp_blockptr;
1273
 
            mn = rb_method_node(klass, id);
1274
 
        }
1275
 
    }
1276
 
    LABEL_IS_SC(start_method_dispatch):
1277
 
#endif
1278
 
#endif
1279
 
    macro_eval_invoke_method(recv, klass, id, num, mn, blockptr);
1280
 
    RUBY_VM_CHECK_INTS();
 
1066
    mn = vm_method_search(id, klass, ic);
 
1067
 
 
1068
    /* send/funcall optimization */
 
1069
    if (flag & VM_CALL_SEND_BIT) {
 
1070
        vm_send_optimize(GET_CFP(), &mn, &flag, &num, &id, klass);
 
1071
    }
 
1072
 
 
1073
    CALL_METHOD(num, blockptr, flag, id, mn, recv, klass);
1281
1074
}
1282
1075
 
1283
1076
/**
1287
1080
 */
1288
1081
DEFINE_INSN
1289
1082
invokesuper
1290
 
(rb_num_t op_argc, ISEQ blockiseq, rb_num_t flag)
 
1083
(rb_num_t op_argc, ISEQ blockiseq, rb_num_t op_flag)
1291
1084
(...)
1292
1085
(VALUE val) // inc += - op_argc;
1293
1086
{
1294
 
#if YARV_AOT_COMPILED
1295
 
    /* TODO: */
1296
 
    rb_bug("...");
1297
 
#else
1298
 
    tmp_num = op_argc;
1299
 
    tmp_blockptr = 0;
1300
 
    macro_eval_setup_send_arguments(tmp_num, tmp_blockptr, flag, blockiseq);
1301
 
    if (!tmp_blockptr && !(flag & VM_CALL_ARGS_BLOCKARG_BIT)) {
1302
 
        tmp_blockptr = GET_BLOCK_PTR();
1303
 
    }
1304
 
    goto LABEL_IS_SC(start_init_in_super);
1305
 
#endif
 
1087
    rb_block_t *blockptr = !(op_flag & VM_CALL_ARGS_BLOCKARG_BIT) ? GET_BLOCK_PTR() : 0;
 
1088
    int num = caller_setup_args(th, GET_CFP(), op_flag, op_argc, blockiseq, &blockptr);
 
1089
    VALUE recv, klass;
 
1090
    NODE *mn;
 
1091
    ID id;
 
1092
    const VALUE flag = VM_CALL_SUPER_BIT | VM_CALL_FCALL_BIT;
 
1093
 
 
1094
    recv = GET_SELF();
 
1095
    vm_search_super_klass(GET_CFP(), GET_ISEQ(), recv, TOPN(num), &id, &klass);
 
1096
    mn = rb_method_node(klass, id);
 
1097
 
 
1098
    CALL_METHOD(num, blockptr, flag, id, mn, recv, klass);
1306
1099
}
1307
1100
 
1308
1101
/**
1316
1109
(...)
1317
1110
(VALUE val)  // inc += 1 - num;
1318
1111
{
1319
 
    rb_block_t *block = GET_BLOCK_PTR();
1320
 
    rb_iseq_t *iseq;
1321
 
    int argc = num;
1322
 
 
1323
 
    if (GET_ISEQ()->local_iseq->type != ISEQ_TYPE_METHOD || block == 0) {
1324
 
        th_localjump_error("no block given (yield)", Qnil, 0);
1325
 
    }
1326
 
    iseq = block->iseq;
1327
 
 
1328
 
    if (BUILTIN_TYPE(iseq) != T_NODE) {
1329
 
        if (flag & VM_CALL_ARGS_SPLAT_BIT) {
1330
 
            VALUE ary = TOPN(0);
1331
 
            if (CLASS_OF(ary) != rb_cArray) {
1332
 
                /* not a [BUG] */
1333
 
            }
1334
 
            else {
1335
 
                VALUE *ptr = RARRAY_PTR(ary);
1336
 
                VALUE *dst = GET_SP() - 1;
1337
 
                int i, len = RARRAY_LEN(ary);
1338
 
 
1339
 
                for (i = 0; i < len; i++) {
1340
 
                    dst[i] = ptr[i];
1341
 
                }
1342
 
                argc += i - 1;
1343
 
                INC_SP(i - 1);
1344
 
            }
1345
 
        }
1346
 
 
1347
 
        DEC_SP(argc);
1348
 
        argc = th_yield_setup_args(th, iseq, argc, GET_SP(),
1349
 
                                   block_proc_is_lambda(block->proc));
1350
 
        INC_SP(argc);
1351
 
 
1352
 
        push_frame(th, iseq,
1353
 
                   FRAME_MAGIC_BLOCK, block->self, (VALUE) block->dfp,
1354
 
                   iseq->iseq_encoded, GET_SP(), block->lfp,
1355
 
                   iseq->local_size - argc);
1356
 
 
1357
 
        reg_cfp->sp -= argc;
 
1112
    val = vm_invoke_block(th, GET_CFP(), num, flag);
 
1113
    if (val == Qundef) {
1358
1114
        RESTORE_REGS();
1359
1115
        NEXT_INSN();
1360
 
        /* unreachable */
1361
 
    }
1362
 
    else {
1363
 
        val = th_yield_with_cfunc(th, block, block->self,
1364
 
                                  num, STACK_ADDR_FROM_TOP(num));
1365
 
        POPN(num);
1366
1116
    }
1367
1117
}
1368
1118
 
1379
1129
{
1380
1130
    if (OPT_CHECKED_RUN) {
1381
1131
        if (reg_cfp->sp != reg_cfp->bp) {
1382
 
            rb_bug("Stack consistency error (sp: %p, bp: %p)",
1383
 
                   reg_cfp->sp, reg_cfp->bp);
 
1132
            rb_bug("Stack consistency error (sp: %d, bp: %d)",
 
1133
                   VM_SP_CNT(th, reg_cfp->sp), VM_SP_CNT(th, reg_cfp->bp));
1384
1134
        }
1385
1135
    }
1386
1136
 
1387
1137
    RUBY_VM_CHECK_INTS();
1388
 
    pop_frame(th);
 
1138
    vm_pop_frame(th);
1389
1139
    RESTORE_REGS();
1390
1140
}
1391
1141
 
1400
1150
(VALUE val)
1401
1151
(VALUE val)
1402
1152
{
 
1153
#if OPT_CALL_THREADED_CODE
 
1154
    rb_bug("unused instruction on OPT_CALL_THREADED_CODE");
 
1155
#else
1403
1156
    th->cfp++;
1404
1157
    return val;
 
1158
#endif
1405
1159
}
1406
1160
 
1407
1161
/**********************************************************/
1419
1173
(VALUE throwobj)
1420
1174
(VALUE val)
1421
1175
{
1422
 
    rb_num_t state = throw_state & 0xff;
1423
 
    rb_num_t flag = throw_state & 0x8000;
1424
 
    rb_num_t level = throw_state >> 16;
1425
 
    val = Qnil;                 /* dummy */
1426
 
 
1427
 
    if (state != 0) {
1428
 
        VALUE *pt;
1429
 
        int i;
1430
 
        if (flag != 0) {
1431
 
            if (throw_state & 0x4000) {
1432
 
                pt = (void *)1;
1433
 
            }
1434
 
            else {
1435
 
                pt = 0;
1436
 
            }
1437
 
        }
1438
 
        else {
1439
 
            if (state == TAG_BREAK || state == TAG_RETRY) {
1440
 
                pt = GC_GUARDED_PTR_REF((VALUE *) * GET_DFP());
1441
 
                for (i = 0; i < level; i++) {
1442
 
                    pt = GC_GUARDED_PTR_REF((VALUE *) * pt);
1443
 
                }
1444
 
            }
1445
 
            else if (state == TAG_RETURN) {
1446
 
                rb_control_frame_t *cfp = GET_CFP();
1447
 
                int is_orphan = 1;
1448
 
                VALUE *dfp = GET_DFP();
1449
 
                
1450
 
                /* check orphan */
1451
 
                while ((VALUE *) cfp < th->stack + th->stack_size) {
1452
 
                    if (GET_LFP() == cfp->lfp) {
1453
 
                        is_orphan = 0;
1454
 
                        break;
1455
 
                    }
1456
 
                    else if (dfp == cfp->dfp) {
1457
 
                        /* return from lambda{} */
1458
 
                        if (cfp->magic == FRAME_MAGIC_LAMBDA) {
1459
 
                            is_orphan = 0;
1460
 
                            break;
1461
 
                        }
1462
 
                        dfp = GC_GUARDED_PTR_REF(*cfp->dfp);
1463
 
                    }
1464
 
                    cfp++;
1465
 
                }
1466
 
                if (is_orphan) {
1467
 
                    th_localjump_error("unexpected return", throwobj,
1468
 
                                       TAG_RETURN);
1469
 
                }
1470
 
 
1471
 
                /* set current lfp */
1472
 
                pt = GET_LFP();
1473
 
            }
1474
 
            else {
1475
 
                rb_bug("isns(throw): unsupport throw type");
1476
 
            }
1477
 
        }
1478
 
        th->state = state;
1479
 
        return (VALUE) NEW_THROW_OBJECT(throwobj, (VALUE) pt, state);
1480
 
    }
1481
 
    else {
1482
 
        /* continue throw */
1483
 
        VALUE err = throwobj;
1484
 
 
1485
 
        if (FIXNUM_P(err)) {
1486
 
            th->state = FIX2INT(err);
1487
 
        }
1488
 
        else if (SYMBOL_P(err)) {
1489
 
            th->state = TAG_THROW;
1490
 
        }
1491
 
        else if (BUILTIN_TYPE(err) == T_NODE) {
1492
 
            th->state = GET_THROWOBJ_STATE(err);
1493
 
        }
1494
 
        else {
1495
 
            th->state = FIX2INT(rb_ivar_get(err, idThrowState));
1496
 
        }
1497
 
        return err;
1498
 
    }
 
1176
    RUBY_VM_CHECK_INTS();
 
1177
    val = vm_throw(th, GET_CFP(), throw_state, throwobj);
 
1178
    THROW_EXCEPTION(val);
1499
1179
    /* unreachable */
1500
1180
}
1501
1181
 
1610
1290
(VALUE val)
1611
1291
(VALUE val)
1612
1292
{
1613
 
    IC ic = (IC) * (GET_PC() + dst + 1);
 
1293
    IC ic = GET_CONST_INLINE_CACHE(dst);
1614
1294
 
1615
1295
    ic->ic_value = val;
1616
1296
    ic->ic_vmstat = GET_VM_STATE_VERSION();
1632
1312
    }
1633
1313
    else {
1634
1314
        VALUE val;
1635
 
        if (st_lookup(RHASH(hash)->tbl, key, &val)) {
 
1315
        if (st_lookup(RHASH_TBL(hash), key, &val)) {
1636
1316
            JUMP(FIX2INT(val));
1637
1317
        }
1638
1318
        else {
1682
1362
    else if (FIXNUM_2_P(recv, obj) &&
1683
1363
             BASIC_OP_UNREDEFINED_P(BOP_PLUS)) {
1684
1364
        /* fixnum + fixnum */
 
1365
#ifndef LONG_LONG_VALUE
1685
1366
        val = (recv + (obj & (~1)));
1686
1367
        if ((~(recv ^ obj) & (recv ^ val)) &
1687
1368
            ((VALUE)0x01 << ((sizeof(VALUE) * CHAR_BIT) - 1))) {
1688
 
            val = rb_big_plus(rb_int2big(FIX2INT(recv)),
1689
 
                              rb_int2big(FIX2INT(obj)));
1690
 
        }
 
1369
            val = rb_big_plus(rb_int2big(FIX2LONG(recv)),
 
1370
                              rb_int2big(FIX2LONG(obj)));
 
1371
        }
 
1372
#else
 
1373
        long a, b, c;
 
1374
        a = FIX2LONG(recv);
 
1375
        b = FIX2LONG(obj);
 
1376
        c = a + b;
 
1377
        if (FIXABLE(c)) {
 
1378
            val = LONG2FIX(c);
 
1379
        }
 
1380
        else {
 
1381
            val = rb_big_plus(rb_int2big(a), rb_int2big(b));
 
1382
        }
 
1383
#endif
1691
1384
    }
1692
1385
#endif
1693
1386
 
1721
1414
    }
1722
1415
    else {
1723
1416
      INSN_LABEL(normal_dispatch):
1724
 
 
1725
 
#ifdef YARV_AOT_COMPILED
1726
 
        val = rb_funcall(recv, idPLUS, 1, obj);
1727
 
#else
1728
1417
        PUSH(recv);
1729
1418
        PUSH(obj);
1730
 
        tmp_id = idPLUS;
1731
 
        goto LABEL_IS_SC(start_init_in_send_for_opt_1);
1732
 
#endif
 
1419
        CALL_SIMPLE_METHOD(1, idPLUS, recv);
1733
1420
    }
1734
1421
}
1735
1422
 
1751
1438
        a = FIX2LONG(recv);
1752
1439
        b = FIX2LONG(obj);
1753
1440
        c = a - b;
1754
 
        val = LONG2FIX(c);
1755
1441
 
1756
 
        if (FIX2LONG(val) != c) {
 
1442
        if (FIXABLE(c)) {
 
1443
            val = LONG2FIX(c);
 
1444
        }
 
1445
        else {
1757
1446
            val = rb_big_minus(rb_int2big(a), rb_int2big(b));
1758
1447
        }
1759
1448
    }
1760
1449
    else {
1761
1450
        /* other */
1762
 
#ifdef YARV_AOT_COMPILED
1763
 
        val = rb_funcall(recv, idMINUS, 1, obj);
1764
 
#else
1765
1451
        PUSH(recv);
1766
1452
        PUSH(obj);
1767
 
        tmp_id = idMINUS;
1768
 
        goto LABEL_IS_SC(start_init_in_send_for_opt_1);
1769
 
#endif
 
1453
        CALL_SIMPLE_METHOD(1, idMINUS, recv);
1770
1454
    }
1771
1455
}
1772
1456
 
1792
1476
        else {
1793
1477
            b = FIX2LONG(obj);
1794
1478
            c = a * b;
1795
 
            val = LONG2FIX(c);
1796
1479
 
1797
 
            if (FIX2LONG(val) != c || c / a != b) {
 
1480
            if (FIXABLE(c) && c / a == b) {
 
1481
                val = LONG2FIX(c);
 
1482
            }
 
1483
            else {
1798
1484
                val = rb_big_mul(rb_int2big(a), rb_int2big(b));
1799
1485
            }
1800
1486
        }
1815
1501
    }
1816
1502
    else {
1817
1503
      INSN_LABEL(normal_dispatch):
1818
 
 
1819
 
        /* other */
1820
 
#ifdef YARV_AOT_COMPILED
1821
 
        val = rb_funcall(recv, idMULT, 1, obj);
1822
 
#else
1823
1504
        PUSH(recv);
1824
1505
        PUSH(obj);
1825
 
        tmp_id = idMULT;
1826
 
        goto LABEL_IS_SC(start_init_in_send_for_opt_1);
1827
 
#endif
 
1506
        CALL_SIMPLE_METHOD(1, idMULT, recv);
1828
1507
    }
1829
1508
}
1830
1509
 
1868
1547
                div -= 1;
1869
1548
            }
1870
1549
        }
1871
 
        val = LONG2FIX(div);
 
1550
        val = LONG2NUM(div);
1872
1551
    }
1873
1552
    else if (!SPECIAL_CONST_P(recv) && !SPECIAL_CONST_P(obj)) {
1874
1553
        if (0) {
1886
1565
    }
1887
1566
    else {
1888
1567
      INSN_LABEL(normal_dispatch):
1889
 
 
1890
 
        /* other */
1891
 
#ifdef YARV_AOT_COMPILED
1892
 
        val = rb_funcall(recv, idDIV, 1, obj);
1893
 
#else
1894
1568
        PUSH(recv);
1895
1569
        PUSH(obj);
1896
 
        tmp_id = idDIV;
1897
 
        goto LABEL_IS_SC(start_init_in_send_for_opt_1);
1898
 
#endif
 
1570
        CALL_SIMPLE_METHOD(1, idDIV, recv);
1899
1571
    }
1900
1572
}
1901
1573
 
1952
1624
            double y = RFLOAT(obj)->value;
1953
1625
            double div, mod;
1954
1626
 
1955
 
            /* copied from numeric.c#flodivmod */
1956
 
#if 0 && defined(HAVE_FMOD) && !__x86_64__      /* temporary */
1957
 
            mod = fmod(x, y);
1958
 
            printf("-- %f %% %f = %f\n", x, y, mod);
1959
 
#else
1960
1627
            {
1961
1628
                double z;
1962
1629
 
1963
1630
                modf(x / y, &z);
1964
1631
                mod = x - z * y;
1965
1632
            }
1966
 
#endif
 
1633
 
1967
1634
            div = (x - mod) / y;
1968
1635
            if (y * mod < 0) {
1969
1636
                mod += y;
1977
1644
    }
1978
1645
    else {
1979
1646
      INSN_LABEL(normal_dispatch):
1980
 
 
1981
 
        /* other */
1982
 
#ifdef YARV_AOT_COMPILED
1983
 
        val = rb_funcall(recv, idMOD, 1, obj);
1984
 
#else
1985
1647
        PUSH(recv);
1986
1648
        PUSH(obj);
1987
 
        tmp_id = idMOD;
1988
 
        goto LABEL_IS_SC(start_init_in_send_for_opt_1);
1989
 
#endif
 
1649
        CALL_SIMPLE_METHOD(1, idMOD, recv);
1990
1650
    }
1991
1651
}
1992
1652
 
2056
1716
    else {
2057
1717
      INSN_LABEL(normal_dispatch):
2058
1718
        /* other */
2059
 
#ifdef YARV_AOT_COMPILED
2060
 
        val = rb_funcall(recv, idEq, 1, obj);
2061
 
#else
2062
1719
        PUSH(recv);
2063
1720
        PUSH(obj);
2064
 
        tmp_id = idEq;
2065
 
        goto LABEL_IS_SC(start_init_in_send_for_opt_1);
2066
 
#endif
 
1721
        CALL_SIMPLE_METHOD(1, idEq, recv);
2067
1722
    }
2068
1723
}
2069
1724
 
2091
1746
        }
2092
1747
    }
2093
1748
    else {
2094
 
        /* other */
2095
 
#ifdef YARV_AOT_COMPILED
2096
 
        val = rb_funcall(recv, idLT, 1, obj);
2097
 
#else
2098
1749
        PUSH(recv);
2099
1750
        PUSH(obj);
2100
 
        tmp_id = idLT;
2101
 
        goto LABEL_IS_SC(start_init_in_send_for_opt_1);
2102
 
#endif
 
1751
        CALL_SIMPLE_METHOD(1, idLT, recv);
2103
1752
    }
2104
1753
}
2105
1754
 
2127
1776
    }
2128
1777
    else {
2129
1778
        /* other */
2130
 
#ifdef YARV_AOT_COMPILED
2131
 
        val = rb_funcall(recv, idLE, 1, obj);
2132
 
#else
2133
1779
        PUSH(recv);
2134
1780
        PUSH(obj);
2135
 
        tmp_id = idLE;
2136
 
        goto LABEL_IS_SC(start_init_in_send_for_opt_1);
2137
 
#endif
 
1781
        CALL_SIMPLE_METHOD(1, idLE, recv);
2138
1782
    }
2139
1783
}
2140
1784
 
2161
1805
        }
2162
1806
    }
2163
1807
    else {
2164
 
        /* other */
2165
 
#ifdef YARV_AOT_COMPILED
2166
 
        val = rb_funcall(recv, idGT, 1, obj);
2167
 
#else
2168
1808
        PUSH(recv);
2169
1809
        PUSH(obj);
2170
 
        tmp_id = idGT;
2171
 
        goto LABEL_IS_SC(start_init_in_send_for_opt_1);
2172
 
#endif
 
1810
        CALL_SIMPLE_METHOD(1, idGT, recv);
2173
1811
    }
2174
1812
}
2175
1813
 
2196
1834
        }
2197
1835
    }
2198
1836
    else {
2199
 
        /* other */
2200
 
#ifdef YARV_AOT_COMPILED
2201
 
        val = rb_funcall(recv, idGE, 1, obj);
2202
 
#else
2203
1837
        PUSH(recv);
2204
1838
        PUSH(obj);
2205
 
        tmp_id = idGE;
2206
 
        goto LABEL_IS_SC(start_init_in_send_for_opt_1);
2207
 
#endif
 
1839
        CALL_SIMPLE_METHOD(1, idGE, recv);
2208
1840
    }
2209
1841
}
2210
1842
 
2236
1868
    }
2237
1869
    else {
2238
1870
      INSN_LABEL(normal_dispatch):
2239
 
        /* other */
2240
 
#ifdef YARV_AOT_COMPILED
2241
 
        val = rb_funcall(recv, idLTLT, 1, obj);
2242
 
#else
2243
1871
        PUSH(recv);
2244
1872
        PUSH(obj);
2245
 
        tmp_id = idLTLT;
2246
 
        goto LABEL_IS_SC(start_init_in_send_for_opt_1);
2247
 
#endif
 
1873
        CALL_SIMPLE_METHOD(1, idLTLT, recv);
2248
1874
    }
2249
1875
}
2250
1876
 
2272
1898
    }
2273
1899
    else {
2274
1900
      INSN_LABEL(normal_dispatch):
2275
 
        /* other */
2276
 
#ifdef YARV_AOT_COMPILED
2277
 
        val = rb_funcall(recv, idAREF, 1, obj);
2278
 
#else
2279
1901
        PUSH(recv);
2280
1902
        PUSH(obj);
2281
 
        tmp_id = idAREF;
2282
 
        goto LABEL_IS_SC(start_init_in_send_for_opt_1);
2283
 
#endif
 
1903
        CALL_SIMPLE_METHOD(1, idAREF, recv);
2284
1904
    }
2285
1905
}
2286
1906
 
2311
1931
    }
2312
1932
    else {
2313
1933
      INSN_LABEL(normal_dispatch):
2314
 
        /* other */
2315
 
#ifdef YARV_AOT_COMPILED
2316
 
        val = rb_funcall(recv, idASET, 2, obj, set);
2317
 
#else
2318
1934
        PUSH(recv);
2319
1935
        PUSH(obj);
2320
1936
        PUSH(set);
2321
 
        tmp_id = idASET;
2322
 
        goto LABEL_IS_SC(start_init_in_send_for_opt_2);
2323
 
#endif
 
1937
        CALL_SIMPLE_METHOD(2, idASET, recv);
2324
1938
    }
2325
1939
}
2326
1940
 
2337
1951
{
2338
1952
    if (!SPECIAL_CONST_P(recv) &&
2339
1953
        BASIC_OP_UNREDEFINED_P(BOP_LENGTH)) {
2340
 
        if (HEAP_CLASS_OF(recv) == rb_cArray) {
 
1954
        if (HEAP_CLASS_OF(recv) == rb_cString) {
 
1955
            val = rb_str_length(recv);
 
1956
        }
 
1957
        else if (HEAP_CLASS_OF(recv) == rb_cArray) {
2341
1958
            val = LONG2NUM(RARRAY_LEN(recv));
2342
1959
        }
2343
 
        else if (HEAP_CLASS_OF(recv) == rb_cString) {
2344
 
            val = LONG2NUM(RSTRING_LEN(recv));
2345
 
        }
2346
1960
        else if (HEAP_CLASS_OF(recv) == rb_cHash) {
2347
 
            val = INT2FIX(RHASH(recv)->tbl->num_entries);
 
1961
            val = INT2FIX(RHASH_SIZE(recv));
2348
1962
        }
2349
1963
        else {
2350
1964
            goto INSN_LABEL(normal_dispatch);
2352
1966
    }
2353
1967
    else {
2354
1968
      INSN_LABEL(normal_dispatch):
2355
 
        /* other */
2356
 
#ifdef YARV_AOT_COMPILED
2357
 
        val = rb_funcall(recv, idLength, 0);
2358
 
#else
2359
 
        val = rb_funcall(recv, idLength, 0);
2360
 
#endif
 
1969
        PUSH(recv);
 
1970
        CALL_SIMPLE_METHOD(0, idLength, recv);
2361
1971
    }
2362
1972
}
2363
1973
 
2378
1988
            const VALUE obj = INT2FIX(1);
2379
1989
            /* fixnum + INT2FIX(1) */
2380
1990
            val = (recv + (obj & (~1)));
2381
 
            if ((~(recv ^ obj) & (recv ^ val)) & 0x80000000) {
2382
 
                val = rb_big_plus(rb_int2big(INT2FIX(recv)),
2383
 
                                  rb_int2big(INT2FIX(obj)));
 
1991
            if ((~(recv ^ obj) & (recv ^ val)) & ((unsigned long)LONG_MAX + 1)) {
 
1992
                val = rb_big_plus(rb_int2big(FIX2LONG(recv)),
 
1993
                                  rb_int2big(FIX2LONG(obj)));
2384
1994
            }
2385
1995
        }
2386
1996
        else {
2402
2012
    }
2403
2013
    if (0) {
2404
2014
      INSN_LABEL(normal_dispatch):
2405
 
        /* other */
2406
 
#ifdef YARV_AOT_COMPILED
2407
 
        val = rb_funcall(recv, idSucc, 0);
2408
 
#else
2409
 
        val = rb_funcall(recv, idSucc, 0);
2410
 
#endif
 
2015
        PUSH(recv);
 
2016
        CALL_SIMPLE_METHOD(0, idSucc, recv);
2411
2017
    }
2412
2018
}
2413
2019
 
2450
2056
  @j �l�C�e�B�u�R���p�C���������\�b�h�� kick
2451
2057
 */
2452
2058
DEFINE_INSN
2453
 
opt_call_native_compiled
2454
 
()
 
2059
opt_call_c_function
 
2060
(rb_insn_func_t funcptr)
2455
2061
()
2456
2062
()
2457
2063
{
2458
 
#if __GNUC__ && OPT_USE_JIT_COMPILE
2459
 
    rb_iseq_t *iseq = GET_ISEQ();
2460
 
    void *label = (void *)iseq->jit_compiled;
2461
 
 
2462
 
    breakpoint();
2463
 
    SET_PC(iseq->iseq_orig);
2464
 
    goto *label;
2465
 
#else
2466
 
    rb_bug("opt_call_native_compiled is not supported");
2467
 
#endif
 
2064
    reg_cfp = (funcptr)(th, reg_cfp);
 
2065
 
 
2066
    if (reg_cfp == 0) {
 
2067
        VALUE err = th->errinfo;
 
2068
        th->errinfo = Qnil;
 
2069
        THROW_EXCEPTION(err);
 
2070
    }
 
2071
 
 
2072
    RESTORE_REGS();
 
2073
    NEXT_INSN();
2468
2074
}
2469
2075
 
2470
2076
/**