Ignore:
Timestamp:
Jan 21, 2018, 12:10:09 AM (6 years ago)
Author:
coas-nagasima
Message:

prototoolに関連するプロジェクトをnewlibからmuslを使うよう変更・更新
ntshellをnewlibの下位の実装から、muslのsyscallの実装に変更・更新
以下のOSSをアップデート
・mruby-1.3.0
・musl-1.1.18
・onigmo-6.1.3
・tcc-0.9.27
以下のOSSを追加
・openssl-1.1.0e
・curl-7.57.0
・zlib-1.2.11
以下のmrbgemsを追加
・iij/mruby-digest
・iij/mruby-env
・iij/mruby-errno
・iij/mruby-iijson
・iij/mruby-ipaddr
・iij/mruby-mock
・iij/mruby-require
・iij/mruby-tls-openssl

Location:
EcnlProtoTool/trunk/mruby-1.3.0
Files:
1 edited
1 moved

Legend:

Unmodified
Added
Removed
  • EcnlProtoTool/trunk/mruby-1.3.0/src/class.c

    r321 r331  
    66
    77#include <stdarg.h>
    8 #include "mruby.h"
    9 #include "mruby/array.h"
    10 #include "mruby/class.h"
    11 #include "mruby/numeric.h"
    12 #include "mruby/proc.h"
    13 #include "mruby/string.h"
    14 #include "mruby/variable.h"
    15 #include "mruby/error.h"
    16 #include "mruby/data.h"
     8#include <mruby.h>
     9#include <mruby/array.h>
     10#include <mruby/class.h>
     11#include <mruby/numeric.h>
     12#include <mruby/proc.h>
     13#include <mruby/string.h>
     14#include <mruby/variable.h>
     15#include <mruby/error.h>
     16#include <mruby/data.h>
     17#include <mruby/istruct.h>
    1718
    1819KHASH_DEFINE(mt, mrb_sym, struct RProc*, TRUE, kh_int_hash_func, kh_int_hash_equal)
     
    9798  else {
    9899    sc->super = o->c;
     100    prepare_singleton_class(mrb, (struct RBasic*)sc);
    99101  }
    100102  o->c = sc;
     
    122124}
    123125
    124 MRB_API struct RClass*
    125 mrb_class_outer_module(mrb_state *mrb, struct RClass *c)
    126 {
    127   mrb_value outer;
    128 
    129   outer = mrb_obj_iv_get(mrb, (struct RObject*)c, mrb_intern_lit(mrb, "__outer__"));
    130   if (mrb_nil_p(outer)) return NULL;
    131   return mrb_class_ptr(outer);
    132 }
    133 
    134 static void
    135 check_if_class_or_module(mrb_state *mrb, mrb_value obj)
     126static mrb_bool
     127class_ptr_p(mrb_value obj)
    136128{
    137129  switch (mrb_type(obj)) {
     
    139131  case MRB_TT_SCLASS:
    140132  case MRB_TT_MODULE:
    141     return;
     133    return TRUE;
    142134  default:
     135    return FALSE;
     136  }
     137}
     138
     139MRB_API struct RClass*
     140mrb_class_outer_module(mrb_state *mrb, struct RClass *c)
     141{
     142  mrb_value outer;
     143  struct RClass *cls;
     144
     145  outer = mrb_obj_iv_get(mrb, (struct RObject*)c, mrb_intern_lit(mrb, "__outer__"));
     146  if (mrb_nil_p(outer)) return NULL;
     147  cls = mrb_class_ptr(outer);
     148  if (cls->tt == MRB_TT_SCLASS)
     149  {
     150    mrb_value klass;
     151    klass = mrb_obj_iv_get(mrb, (struct RObject *)cls,
     152                           mrb_intern_lit(mrb, "__attached__"));
     153    if (class_ptr_p(klass)) {
     154      cls = mrb_class_ptr(klass);
     155    }
     156  }
     157  return cls;
     158}
     159
     160static void
     161check_if_class_or_module(mrb_state *mrb, mrb_value obj)
     162{
     163  if (!class_ptr_p(obj)) {
    143164    mrb_raisef(mrb, E_TYPE_ERROR, "%S is not a class/module", mrb_inspect(mrb, obj));
    144165  }
     
    175196{
    176197  check_if_class_or_module(mrb, outer);
     198  if (mrb_const_defined_at(mrb, outer, id)) {
     199    mrb_value old = mrb_const_get(mrb, outer, id);
     200
     201    if (mrb_type(old) != MRB_TT_MODULE) {
     202      mrb_raisef(mrb, E_TYPE_ERROR, "%S is not a module", mrb_inspect(mrb, old));
     203    }
     204    return mrb_class_ptr(old);
     205  }
    177206  return define_module(mrb, id, mrb_class_ptr(outer));
    178207}
     
    232261}
    233262
     263static mrb_value mrb_bob_init(mrb_state *mrb, mrb_value cv);
     264
    234265static void
    235266mrb_class_inherited(mrb_state *mrb, struct RClass *super, struct RClass *klass)
    236267{
     268  mrb_value s;
     269  mrb_sym mid;
     270
    237271  if (!super)
    238272    super = mrb->object_class;
    239   mrb_funcall(mrb, mrb_obj_value(super), "inherited", 1, mrb_obj_value(klass));
     273  s = mrb_obj_value(super);
     274  mid = mrb_intern_lit(mrb, "inherited");
     275  if (!mrb_func_basic_p(mrb, s, mid, mrb_bob_init)) {
     276    mrb_value c = mrb_obj_value(klass);
     277    mrb_funcall_argv(mrb, mrb_obj_value(super), mid, 1, &c);
     278  }
    240279}
    241280
     
    248287  if (!mrb_nil_p(super)) {
    249288    if (mrb_type(super) != MRB_TT_CLASS) {
    250       mrb_raisef(mrb, E_TYPE_ERROR, "superclass must be a Class (%S given)", super);
     289      mrb_raisef(mrb, E_TYPE_ERROR, "superclass must be a Class (%S given)",
     290                 mrb_inspect(mrb, super));
    251291    }
    252292    s = mrb_class_ptr(super);
     
    256296  }
    257297  check_if_class_or_module(mrb, outer);
     298  if (mrb_const_defined_at(mrb, outer, id)) {
     299    mrb_value old = mrb_const_get(mrb, outer, id);
     300
     301    if (mrb_type(old) != MRB_TT_CLASS) {
     302      mrb_raisef(mrb, E_TYPE_ERROR, "%S is not a class", mrb_inspect(mrb, old));
     303    }
     304    c = mrb_class_ptr(old);
     305    if (s) {
     306      /* check super class */
     307      if (mrb_class_real(c->super) != s) {
     308        mrb_raisef(mrb, E_TYPE_ERROR, "superclass mismatch for class %S", old);
     309      }
     310    }
     311    return c;
     312  }
    258313  c = define_class(mrb, id, s, mrb_class_ptr(outer));
    259314  mrb_class_inherited(mrb, mrb_class_real(c->super), c);
     
    272327}
    273328
     329MRB_API mrb_bool
     330mrb_class_defined_under(mrb_state *mrb, struct RClass *outer, const char *name)
     331{
     332  mrb_value sym = mrb_check_intern_cstr(mrb, name);
     333  if (mrb_nil_p(sym)) {
     334    return FALSE;
     335  }
     336  return mrb_const_defined_at(mrb, mrb_obj_value(outer), mrb_symbol(sym));
     337}
     338
    274339MRB_API struct RClass *
    275340mrb_class_get_under(mrb_state *mrb, struct RClass *outer, const char *name)
     
    282347{
    283348  return mrb_class_get_under(mrb, mrb->object_class, name);
     349}
     350
     351MRB_API struct RClass *
     352mrb_exc_get(mrb_state *mrb, const char *name)
     353{
     354  struct RClass *exc, *e;
     355  mrb_value c = mrb_const_get(mrb, mrb_obj_value(mrb->object_class),
     356                              mrb_intern_cstr(mrb, name));
     357
     358  if (mrb_type(c) != MRB_TT_CLASS) {
     359    mrb_raise(mrb, mrb->eException_class, "exception corrupted");
     360  }
     361  exc = e = mrb_class_ptr(c);
     362
     363  while (e) {
     364    if (e == mrb->eException_class)
     365      return exc;
     366    e = e->super;
     367  }
     368  return mrb->eException_class;
    284369}
    285370
     
    337422  h = c->mt;
    338423
     424  if (MRB_FROZEN_P(c)) {
     425    if (c->tt == MRB_TT_MODULE)
     426      mrb_raise(mrb, E_RUNTIME_ERROR, "can't modify frozen module");
     427    else
     428      mrb_raise(mrb, E_RUNTIME_ERROR, "can't modify frozen class");
     429  }
    339430  if (!h) h = c->mt = kh_init(mt, mrb);
    340431  k = kh_put(mt, mrb, h, mid);
    341432  kh_value(h, k) = p;
    342433  if (p) {
     434    p->c = NULL;
    343435    mrb_field_write_barrier(mrb, (struct RBasic *)c, (struct RBasic *)p);
    344436  }
     
    430522    mrb_value obj = mrb_funcall(mrb, ss, "inspect", 0);
    431523    mrb_raisef(mrb, E_TYPE_ERROR, "%S is not a symbol", obj);
     524    /* not reached */
     525    return 0;
    432526  }
    433527}
     
    457551    n:      Symbol         [mrb_sym]
    458552    d:      Data           [void*,mrb_data_type const] 2nd argument will be used to check data type so it won't be modified
     553    I:      Inline struct  [void*]
    459554    &:      Block          [mrb_value]
    460555    *:      rest argument  [mrb_value*,mrb_int]   Receive the rest of the arguments as an array.
     
    467562  char c;
    468563  int i = 0;
    469   mrb_value *sp = mrb->c->stack + 1;
    470564  va_list ap;
    471565  int argc = mrb->c->ci->argc;
     566  int arg_i = 0;
     567  mrb_bool array_argv;
    472568  mrb_bool opt = FALSE;
    473569  mrb_bool given = TRUE;
     
    478574
    479575    argc = a->len;
    480     sp = a->ptr;
    481   }
     576    array_argv = TRUE;
     577  }
     578  else {
     579    array_argv = FALSE;
     580  }
     581
     582#define ARGV \
     583  (array_argv ? mrb_ary_ptr(mrb->c->stack[1])->ptr : (mrb->c->stack + 1))
     584
    482585  while ((c = *format++)) {
    483586    switch (c) {
     
    503606        p = va_arg(ap, mrb_value*);
    504607        if (i < argc) {
    505           *p = *sp++;
     608          *p = ARGV[arg_i++];
    506609          i++;
    507610        }
     
    516619          mrb_value ss;
    517620
    518           ss = *sp++;
    519           switch (mrb_type(ss)) {
    520           case MRB_TT_CLASS:
    521           case MRB_TT_MODULE:
    522           case MRB_TT_SCLASS:
    523             break;
    524           default:
     621          ss = ARGV[arg_i++];
     622          if (!class_ptr_p(ss)) {
    525623            mrb_raisef(mrb, E_TYPE_ERROR, "%S is not class/module", ss);
    526             break;
    527624          }
    528625          *p = ss;
     
    538635        if (*format == '!') {
    539636          format++;
    540           if (i < argc && mrb_nil_p(*sp)) {
    541             *p = *sp++;
     637          if (i < argc && mrb_nil_p(ARGV[arg_i])) {
     638            *p = ARGV[arg_i++];
    542639            i++;
    543640            break;
     
    545642        }
    546643        if (i < argc) {
    547           *p = to_str(mrb, *sp++);
     644          *p = to_str(mrb, ARGV[arg_i++]);
    548645          i++;
    549646        }
     
    557654        if (*format == '!') {
    558655          format++;
    559           if (i < argc && mrb_nil_p(*sp)) {
    560             *p = *sp++;
     656          if (i < argc && mrb_nil_p(ARGV[arg_i])) {
     657            *p = ARGV[arg_i++];
    561658            i++;
    562659            break;
     
    564661        }
    565662        if (i < argc) {
    566           *p = to_ary(mrb, *sp++);
     663          *p = to_ary(mrb, ARGV[arg_i++]);
    567664          i++;
    568665        }
     
    576673        if (*format == '!') {
    577674          format++;
    578           if (i < argc && mrb_nil_p(*sp)) {
    579             *p = *sp++;
     675          if (i < argc && mrb_nil_p(ARGV[arg_i])) {
     676            *p = ARGV[arg_i++];
    580677            i++;
    581678            break;
     
    583680        }
    584681        if (i < argc) {
    585           *p = to_hash(mrb, *sp++);
     682          *p = to_hash(mrb, ARGV[arg_i++]);
    586683          i++;
    587684        }
     
    598695        if (*format == '!') {
    599696          format++;
    600           if (i < argc && mrb_nil_p(*sp)) {
     697          if (i < argc && mrb_nil_p(ARGV[arg_i])) {
    601698            *ps = NULL;
    602699            *pl = 0;
    603             i++;
     700            i++; arg_i++;
    604701            break;
    605702          }
    606703        }
    607704        if (i < argc) {
    608           ss = to_str(mrb, *sp++);
     705          ss = to_str(mrb, ARGV[arg_i++]);
    609706          *ps = RSTRING_PTR(ss);
    610707          *pl = RSTRING_LEN(ss);
     
    621718        if (*format == '!') {
    622719          format++;
    623           if (i < argc && mrb_nil_p(*sp)) {
     720          if (i < argc && mrb_nil_p(ARGV[arg_i])) {
    624721            *ps = NULL;
    625             i++; sp++;
     722            i++; arg_i++;
    626723            break;
    627724          }
    628725        }
    629726        if (i < argc) {
    630           ss = to_str(mrb, *sp++);
     727          ss = to_str(mrb, ARGV[arg_i++]);
    631728          *ps = mrb_string_value_cstr(mrb, &ss);
    632729          i++;
     
    645742        if (*format == '!') {
    646743          format++;
    647           if (i < argc && mrb_nil_p(*sp)) {
     744          if (i < argc && mrb_nil_p(ARGV[arg_i])) {
    648745            *pb = 0;
    649746            *pl = 0;
    650             i++; sp++;
     747            i++; arg_i++;
    651748            break;
    652749          }
    653750        }
    654751        if (i < argc) {
    655           aa = to_ary(mrb, *sp++);
     752          aa = to_ary(mrb, ARGV[arg_i++]);
    656753          a = mrb_ary_ptr(aa);
    657754          *pb = a->ptr;
     
    661758      }
    662759      break;
     760    case 'I':
     761      {
     762        void* *p;
     763        mrb_value ss;
     764
     765        p = va_arg(ap, void**);
     766        if (i < argc) {
     767          ss = ARGV[arg_i];
     768          if (mrb_type(ss) != MRB_TT_ISTRUCT)
     769          {
     770            mrb_raisef(mrb, E_TYPE_ERROR, "%S is not inline struct", ss);
     771          }
     772          *p = mrb_istruct_ptr(ss);
     773          arg_i++;
     774          i++;
     775        }
     776      }
     777      break;
    663778    case 'f':
    664779      {
     
    667782        p = va_arg(ap, mrb_float*);
    668783        if (i < argc) {
    669           *p = mrb_to_flo(mrb, *sp);
    670           sp++;
     784          *p = mrb_to_flo(mrb, ARGV[arg_i]);
     785          arg_i++;
    671786          i++;
    672787        }
     
    679794        p = va_arg(ap, mrb_int*);
    680795        if (i < argc) {
    681           switch (mrb_type(*sp)) {
     796          switch (mrb_type(ARGV[arg_i])) {
    682797            case MRB_TT_FIXNUM:
    683               *p = mrb_fixnum(*sp);
     798              *p = mrb_fixnum(ARGV[arg_i]);
    684799              break;
    685800            case MRB_TT_FLOAT:
    686801              {
    687                 mrb_float f = mrb_float(*sp);
    688 
    689                 if (!FIXABLE(f)) {
     802                mrb_float f = mrb_float(ARGV[arg_i]);
     803
     804                if (!FIXABLE_FLOAT(f)) {
    690805                  mrb_raise(mrb, E_RANGE_ERROR, "float too big for int");
    691806                }
     
    697812              break;
    698813            default:
    699               *p = mrb_fixnum(mrb_Integer(mrb, *sp));
     814              *p = mrb_fixnum(mrb_Integer(mrb, ARGV[arg_i]));
    700815              break;
    701816          }
    702           sp++;
     817          arg_i++;
    703818          i++;
    704819        }
     
    710825
    711826        if (i < argc) {
    712           mrb_value b = *sp++;
     827          mrb_value b = ARGV[arg_i++];
    713828          *boolp = mrb_test(b);
    714829          i++;
     
    724839          mrb_value ss;
    725840
    726           ss = *sp++;
     841          ss = ARGV[arg_i++];
    727842          *symp = to_sym(mrb, ss);
    728843          i++;
     
    739854        if (*format == '!') {
    740855          format++;
    741           if (i < argc && mrb_nil_p(*sp)) {
     856          if (i < argc && mrb_nil_p(ARGV[arg_i])) {
    742857            *datap = 0;
    743             i++; sp++;
     858            i++; arg_i++;
    744859            break;
    745860          }
    746861        }
    747862        if (i < argc) {
    748           *datap = mrb_data_get_ptr(mrb, *sp++, type);
     863          *datap = mrb_data_get_ptr(mrb, ARGV[arg_i++], type);
    749864          ++i;
    750865        }
     
    788903          *pl = argc-i;
    789904          if (*pl > 0) {
    790             *var = sp;
     905            *var = ARGV + arg_i;
    791906          }
    792907          i = argc;
    793           sp += *pl;
     908          arg_i += *pl;
    794909        }
    795910        else {
     
    804919    }
    805920  }
     921
     922#undef ARGV
     923
    806924  if (!c && argc > i) {
    807925    mrb_raise(mrb, E_ARGUMENT_ERROR, "wrong number of arguments");
     
    831949boot_initmod(mrb_state *mrb, struct RClass *mod)
    832950{
    833   mod->mt = kh_init(mt, mrb);
     951  if (!mod->mt) {
     952    mod->mt = kh_init(mt, mrb);
     953  }
    834954}
    835955
     
    847967  if (m->tt == MRB_TT_ICLASS) {
    848968    ic->c = m->c;
    849   } else {
     969  }
     970  else {
    850971    ic->c = m;
    851972  }
     
    873994        if (p->mt == m->mt) {
    874995          if (!superclass_seen) {
    875             ins_pos = p; // move insert point
     996            ins_pos = p; /* move insert point */
    876997          }
    877998          goto skip;
     
    9371058
    9381059static mrb_value
    939 mrb_mod_prepend(mrb_state *mrb, mrb_value klass)
    940 {
    941   mrb_value *argv;
    942   mrb_int argc, i;
    943 
    944   mrb_get_args(mrb, "*", &argv, &argc);
    945   for (i=0; i<argc; i++) {
    946     mrb_check_type(mrb, argv[i], MRB_TT_MODULE);
    947   }
    948   while (argc--) {
    949     mrb_funcall(mrb, argv[argc], "prepend_features", 1, klass);
    950     mrb_funcall(mrb, argv[argc], "prepended", 1, klass);
    951   }
    952 
    953   return klass;
    954 }
    955 
    956 static mrb_value
    9571060mrb_mod_append_features(mrb_state *mrb, mrb_value mod)
    9581061{
     
    9631066  mrb_include_module(mrb, mrb_class_ptr(klass), mrb_class_ptr(mod));
    9641067  return mod;
    965 }
    966 
    967 static mrb_value
    968 mrb_mod_include(mrb_state *mrb, mrb_value klass)
    969 {
    970   mrb_value *argv;
    971   mrb_int argc, i;
    972 
    973   mrb_get_args(mrb, "*", &argv, &argc);
    974   for (i=0; i<argc; i++) {
    975     mrb_check_type(mrb, argv[i], MRB_TT_MODULE);
    976   }
    977   while (argc--) {
    978     mrb_funcall(mrb, argv[argc], "append_features", 1, klass);
    979     mrb_funcall(mrb, argv[argc], "included", 1, klass);
    980   }
    981 
    982   return klass;
    9831068}
    9841069
     
    10761161  mrb_value b;
    10771162  struct RClass *m = mrb_class_ptr(mod);
    1078   boot_initmod(mrb, m); // bootstrap a newly initialized module
     1163  boot_initmod(mrb, m); /* bootstrap a newly initialized module */
    10791164  mrb_get_args(mrb, "|&", &b);
    10801165  if (!mrb_nil_p(b)) {
     
    11561241  obj = mrb_basic_ptr(v);
    11571242  prepare_singleton_class(mrb, obj);
    1158   if (mrb->c && mrb->c->ci && mrb->c->ci->target_class) {
    1159     mrb_obj_iv_set(mrb, (struct RObject*)obj->c, mrb_intern_lit(mrb, "__outer__"),
    1160                    mrb_obj_value(mrb->c->ci->target_class));
    1161   }
    11621243  return mrb_obj_value(obj->c);
    11631244}
     
    13201401
    13211402  if (ttype == 0) ttype = MRB_TT_OBJECT;
     1403  if (ttype <= MRB_TT_CPTR) {
     1404    mrb_raisef(mrb, E_TYPE_ERROR, "can't create instance of %S", cv);
     1405  }
    13221406  o = (struct RObject*)mrb_obj_alloc(mrb, ttype, c);
    13231407  return mrb_obj_value(o);
     
    13541438{
    13551439  mrb_value obj;
     1440  mrb_sym mid;
    13561441
    13571442  obj = mrb_instance_alloc(mrb, mrb_obj_value(c));
    1358   mrb_funcall_argv(mrb, obj, mrb_intern_lit(mrb, "initialize"), argc, argv);
    1359 
     1443  mid = mrb_intern_lit(mrb, "initialize");
     1444  if (!mrb_func_basic_p(mrb, obj, mid, mrb_bob_init)) {
     1445    mrb_funcall_argv(mrb, obj, mid, argc, argv);
     1446  }
    13601447  return obj;
    13611448}
     
    13791466  mrb_value super, blk;
    13801467  mrb_value new_class;
     1468  mrb_sym mid;
    13811469
    13821470  n = mrb_get_args(mrb, "|C&", &super, &blk);
     
    13851473  }
    13861474  new_class = mrb_obj_value(mrb_class_new(mrb, mrb_class_ptr(super)));
    1387   mrb_funcall_with_block(mrb, new_class, mrb_intern_lit(mrb, "initialize"), n, &super, blk);
     1475  mid = mrb_intern_lit(mrb, "initialize");
     1476  if (!mrb_func_basic_p(mrb, new_class, mid, mrb_bob_init)) {
     1477    mrb_funcall_with_block(mrb, new_class, mid, n, &super, blk);
     1478  }
    13881479  mrb_class_inherited(mrb, mrb_class_ptr(super), mrb_class_ptr(new_class));
    13891480  return new_class;
     
    14161507}
    14171508
    1418 void
    1419 mrb_method_missing(mrb_state *mrb, mrb_sym name, mrb_value self, mrb_value args)
    1420 {
    1421   mrb_sym inspect;
    1422   mrb_value repr;
    1423 
    1424   inspect = mrb_intern_lit(mrb, "inspect");
    1425   if (mrb->c->ci > mrb->c->cibase && mrb->c->ci[-1].mid == inspect) {
    1426     /* method missing in inspect; avoid recursion */
    1427     repr = mrb_any_to_s(mrb, self);
    1428   }
    1429   else if (mrb_respond_to(mrb, self, inspect) && mrb->c->ci - mrb->c->cibase < 64) {
    1430     repr = mrb_funcall_argv(mrb, self, inspect, 0, 0);
    1431     if (mrb_string_p(repr) && RSTRING_LEN(repr) > 64) {
    1432       repr = mrb_any_to_s(mrb, self);
    1433     }
    1434   }
    1435   else {
    1436     repr = mrb_any_to_s(mrb, self);
    1437   }
    1438 
    1439   mrb_no_method_error(mrb, name, args, "undefined method '%S' for %S",
    1440                       mrb_sym2str(mrb, name), repr);
    1441 }
    1442 
    1443 /* 15.3.1.3.30 */
     1509/* 15.3.1.3.1  */
     1510/* 15.3.1.3.10 */
     1511/* 15.3.1.3.11 */
    14441512/*
    14451513 *  call-seq:
    1446  *     obj.method_missing(symbol [, *args] )   -> result
    1447  *
    1448  *  Invoked by Ruby when <i>obj</i> is sent a message it cannot handle.
    1449  *  <i>symbol</i> is the symbol for the method called, and <i>args</i>
    1450  *  are any arguments that were passed to it. By default, the interpreter
    1451  *  raises an error when this method is called. However, it is possible
    1452  *  to override the method to provide more dynamic behavior.
    1453  *  If it is decided that a particular method should not be handled, then
    1454  *  <i>super</i> should be called, so that ancestors can pick up the
    1455  *  missing method.
    1456  *  The example below creates
    1457  *  a class <code>Roman</code>, which responds to methods with names
    1458  *  consisting of roman numerals, returning the corresponding integer
    1459  *  values.
    1460  *
    1461  *     class Roman
    1462  *       def romanToInt(str)
    1463  *         # ...
    1464  *       end
    1465  *       def method_missing(methId)
    1466  *         str = methId.id2name
    1467  *         romanToInt(str)
    1468  *       end
    1469  *     end
    1470  *
    1471  *     r = Roman.new
    1472  *     r.iv      #=> 4
    1473  *     r.xxiii   #=> 23
    1474  *     r.mm      #=> 2000
     1514 *     obj == other        -> true or false
     1515 *     obj.equal?(other)   -> true or false
     1516 *     obj.eql?(other)     -> true or false
     1517 *
     1518 *  Equality---At the <code>Object</code> level, <code>==</code> returns
     1519 *  <code>true</code> only if <i>obj</i> and <i>other</i> are the
     1520 *  same object. Typically, this method is overridden in descendant
     1521 *  classes to provide class-specific meaning.
     1522 *
     1523 *  Unlike <code>==</code>, the <code>equal?</code> method should never be
     1524 *  overridden by subclasses: it is used to determine object identity
     1525 *  (that is, <code>a.equal?(b)</code> iff <code>a</code> is the same
     1526 *  object as <code>b</code>).
     1527 *
     1528 *  The <code>eql?</code> method returns <code>true</code> if
     1529 *  <i>obj</i> and <i>anObject</i> have the same value. Used by
     1530 *  <code>Hash</code> to test members for equality.  For objects of
     1531 *  class <code>Object</code>, <code>eql?</code> is synonymous with
     1532 *  <code>==</code>. Subclasses normally continue this tradition, but
     1533 *  there are exceptions. <code>Numeric</code> types, for example,
     1534 *  perform type conversion across <code>==</code>, but not across
     1535 *  <code>eql?</code>, so:
     1536 *
     1537 *     1 == 1.0     #=> true
     1538 *     1.eql? 1.0   #=> false
    14751539 */
    1476 static mrb_value
    1477 mrb_bob_missing(mrb_state *mrb, mrb_value mod)
    1478 {
    1479   mrb_sym name;
    1480   mrb_value *a;
    1481   mrb_int alen;
    1482 
    1483   mrb_get_args(mrb, "n*", &name, &a, &alen);
    1484   mrb_method_missing(mrb, name, mod, mrb_ary_new_from_values(mrb, alen, a));
    1485   /* not reached */
    1486   return mrb_nil_value();
     1540mrb_value
     1541mrb_obj_equal_m(mrb_state *mrb, mrb_value self)
     1542{
     1543  mrb_value arg;
     1544
     1545  mrb_get_args(mrb, "o", &arg);
     1546  return mrb_bool_value(mrb_obj_equal(mrb, self, arg));
     1547}
     1548
     1549static mrb_value
     1550mrb_obj_not_equal_m(mrb_state *mrb, mrb_value self)
     1551{
     1552  mrb_value arg;
     1553
     1554  mrb_get_args(mrb, "o", &arg);
     1555  return mrb_bool_value(!mrb_equal(mrb, self, arg));
    14871556}
    14881557
     
    15331602      return mrb_nil_value();
    15341603    }
    1535     else if (outer && outer != mrb->object_class) {
     1604    else if (outer && outer != c && outer != mrb->object_class) {
    15361605      mrb_value base = mrb_class_path(mrb, outer);
    15371606      path = mrb_str_buf_new(mrb, 0);
     
    15521621      path = mrb_str_new(mrb, name, len);
    15531622    }
    1554     mrb_obj_iv_set(mrb, (struct RObject*)c, classpath, path);
    1555   }
    1556   return path;
     1623    if (!MRB_FROZEN_P(c)) {
     1624      mrb_obj_iv_set(mrb, (struct RObject*)c, classpath, path);
     1625    }
     1626  }
     1627  return mrb_str_dup(mrb, path);
    15571628}
    15581629
     
    16991770    str = mrb_str_new_lit(mrb, "#<Class:");
    17001771
    1701     switch (mrb_type(v)) {
    1702       case MRB_TT_CLASS:
    1703       case MRB_TT_MODULE:
    1704       case MRB_TT_SCLASS:
    1705         mrb_str_cat_str(mrb, str, mrb_inspect(mrb, v));
    1706         break;
    1707       default:
    1708         mrb_str_cat_str(mrb, str, mrb_any_to_s(mrb, v));
    1709         break;
     1772    if (class_ptr_p(v)) {
     1773      mrb_str_cat_str(mrb, str, mrb_inspect(mrb, v));
     1774    }
     1775    else {
     1776      mrb_str_cat_str(mrb, str, mrb_any_to_s(mrb, v));
    17101777    }
    17111778    return mrb_str_cat_lit(mrb, str, ">");
     
    17861853  mrb_get_args(mrb, "*", &argv, &argc);
    17871854  while (argc--) {
    1788     undef_method(mrb, c, mrb_symbol(*argv));
     1855    undef_method(mrb, c, to_sym(mrb, *argv));
    17891856    argv++;
    17901857  }
     
    17981865  struct RProc *p;
    17991866  mrb_sym mid;
     1867  mrb_value proc = mrb_undef_value();
    18001868  mrb_value blk;
    18011869
    1802   mrb_get_args(mrb, "n&", &mid, &blk);
     1870  mrb_get_args(mrb, "n|o&", &mid, &proc, &blk);
     1871  switch (mrb_type(proc)) {
     1872    case MRB_TT_PROC:
     1873      blk = proc;
     1874      break;
     1875    case MRB_TT_UNDEF:
     1876      /* ignored */
     1877      break;
     1878    default:
     1879      mrb_raisef(mrb, E_TYPE_ERROR, "wrong argument type %S (expected Proc)", mrb_obj_value(mrb_obj_class(mrb, proc)));
     1880      break;
     1881  }
    18031882  if (mrb_nil_p(blk)) {
    18041883    mrb_raise(mrb, E_ARGUMENT_ERROR, "no block given");
     
    20282107  mrb_get_args(mrb, "*", &argv, &argc);
    20292108  while (argc--) {
    2030     remove_method(mrb, mod, mrb_symbol(*argv));
     2109    remove_method(mrb, mod, to_sym(mrb, *argv));
    20312110    argv++;
    20322111  }
     
    21592238
    21602239  mrb_get_args(mrb, "*", &argv, &argc);
    2161   if(argc == 0) {
     2240  if (argc == 0) {
    21622241    /* set MODFUNC SCOPE if implemented */
    21632242    return mod;
     
    21822261  return mod;
    21832262}
     2263
     2264/* implementation of __id__ */
     2265mrb_value mrb_obj_id_m(mrb_state *mrb, mrb_value self);
     2266/* implementation of instance_eval */
     2267mrb_value mrb_obj_instance_eval(mrb_state*, mrb_value);
    21842268
    21852269void
     
    22222306  mrb_define_method(mrb, bob, "initialize",              mrb_bob_init,             MRB_ARGS_NONE());
    22232307  mrb_define_method(mrb, bob, "!",                       mrb_bob_not,              MRB_ARGS_NONE());
    2224   mrb_define_method(mrb, bob, "method_missing",          mrb_bob_missing,          MRB_ARGS_ANY());  /* 15.3.1.3.30 */
     2308  mrb_define_method(mrb, bob, "==",                      mrb_obj_equal_m,          MRB_ARGS_REQ(1)); /* 15.3.1.3.1  */
     2309  mrb_define_method(mrb, bob, "!=",                      mrb_obj_not_equal_m,      MRB_ARGS_REQ(1));
     2310  mrb_define_method(mrb, bob, "__id__",                  mrb_obj_id_m,             MRB_ARGS_NONE()); /* 15.3.1.3.3  */
     2311  mrb_define_method(mrb, bob, "__send__",                mrb_f_send,               MRB_ARGS_ANY());  /* 15.3.1.3.4  */
     2312  mrb_define_method(mrb, bob, "instance_eval",           mrb_obj_instance_eval,    MRB_ARGS_ANY());  /* 15.3.1.3.18 */
    22252313
    22262314  mrb_define_class_method(mrb, cls, "new",               mrb_class_new_class,      MRB_ARGS_OPT(1));
     
    22362324  mrb_define_method(mrb, mod, "extend_object",           mrb_mod_extend_object,    MRB_ARGS_REQ(1)); /* 15.2.2.4.25 */
    22372325  mrb_define_method(mrb, mod, "extended",                mrb_bob_init,             MRB_ARGS_REQ(1)); /* 15.2.2.4.26 */
    2238   mrb_define_method(mrb, mod, "prepend",                 mrb_mod_prepend,          MRB_ARGS_ANY());
    22392326  mrb_define_method(mrb, mod, "prepended",               mrb_bob_init,             MRB_ARGS_REQ(1));
    22402327  mrb_define_method(mrb, mod, "prepend_features",        mrb_mod_prepend_features, MRB_ARGS_REQ(1));
    2241   mrb_define_method(mrb, mod, "include",                 mrb_mod_include,          MRB_ARGS_ANY());  /* 15.2.2.4.27 */
    22422328  mrb_define_method(mrb, mod, "include?",                mrb_mod_include_p,        MRB_ARGS_REQ(1)); /* 15.2.2.4.28 */
    22432329  mrb_define_method(mrb, mod, "append_features",         mrb_mod_append_features,  MRB_ARGS_REQ(1)); /* 15.2.2.4.10 */
     
    22692355  mrb_define_method(mrb, mod, "remove_const",            mrb_mod_remove_const,     MRB_ARGS_REQ(1)); /* 15.2.2.4.40 */
    22702356  mrb_define_method(mrb, mod, "const_missing",           mrb_mod_const_missing,    MRB_ARGS_REQ(1));
    2271   mrb_define_method(mrb, mod, "define_method",           mod_define_method,        MRB_ARGS_REQ(1));
     2357  mrb_define_method(mrb, mod, "define_method",           mod_define_method,        MRB_ARGS_ARG(1,1));
    22722358  mrb_define_method(mrb, mod, "class_variables",         mrb_mod_class_variables,  MRB_ARGS_NONE()); /* 15.2.2.4.19 */
    22732359  mrb_define_method(mrb, mod, "===",                     mrb_mod_eqq,              MRB_ARGS_REQ(1));
Note: See TracChangeset for help on using the changeset viewer.