Changeset 331 for EcnlProtoTool/trunk/mruby-1.3.0/src/variable.c
- Timestamp:
- Jan 21, 2018, 12:10:09 AM (6 years ago)
- Location:
- EcnlProtoTool/trunk/mruby-1.3.0
- Files:
-
- 1 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
EcnlProtoTool/trunk/mruby-1.3.0/src/variable.c
r321 r331 5 5 */ 6 6 7 #include "mruby.h"8 #include "mruby/array.h"9 #include "mruby/class.h"10 #include "mruby/proc.h"11 #include "mruby/string.h"7 #include <mruby.h> 8 #include <mruby/array.h> 9 #include <mruby/class.h> 10 #include <mruby/proc.h> 11 #include <mruby/string.h> 12 12 13 13 typedef int (iv_foreach_func)(mrb_state*,mrb_sym,mrb_value,void*); … … 45 45 iv_tbl *t; 46 46 47 t = mrb_malloc(mrb, sizeof(iv_tbl));47 t = (iv_tbl*)mrb_malloc(mrb, sizeof(iv_tbl)); 48 48 t->size = 0; 49 49 t->rootseg = NULL; … … 103 103 } 104 104 105 seg = mrb_malloc(mrb, sizeof(segment));105 seg = (segment*)mrb_malloc(mrb, sizeof(segment)); 106 106 if (!seg) return; 107 107 seg->next = NULL; … … 283 283 #else 284 284 285 #include "mruby/khash.h"285 #include <mruby/khash.h> 286 286 287 287 #ifndef MRB_IVHASH_INIT_SIZE … … 490 490 iv_tbl *t = obj->iv; 491 491 492 if (MRB_FROZEN_P(obj)) { 493 mrb_raisef(mrb, E_RUNTIME_ERROR, "can't modify frozen %S", mrb_obj_value(obj)); 494 } 492 495 if (!t) { 493 496 t = obj->iv = iv_new(mrb); … … 757 760 758 761 MRB_API mrb_value 759 mrb_mod_cv_get(mrb_state *mrb, struct RClass * 762 mrb_mod_cv_get(mrb_state *mrb, struct RClass *c, mrb_sym sym) 760 763 { 761 764 struct RClass * cls = c; 762 765 mrb_value v; 766 int given = FALSE; 763 767 764 768 while (c) { 765 769 if (c->iv && iv_get(mrb, c->iv, sym, &v)) { 766 return v;770 given = TRUE; 767 771 } 768 772 c = c->super; 769 773 } 774 if (given) return v; 770 775 if (cls && cls->tt == MRB_TT_SCLASS) { 771 776 mrb_value klass; … … 774 779 mrb_intern_lit(mrb, "__attached__")); 775 780 c = mrb_class_ptr(klass); 776 if (c->tt == MRB_TT_CLASS) { 781 if (c->tt == MRB_TT_CLASS || c->tt == MRB_TT_MODULE) { 782 given = FALSE; 777 783 while (c) { 778 784 if (c->iv && iv_get(mrb, c->iv, sym, &v)) { 779 return v;785 given = TRUE; 780 786 } 781 787 c = c->super; 782 788 } 789 if (given) return v; 783 790 } 784 791 } … … 813 820 } 814 821 815 if (!cls->iv) { 816 cls->iv = iv_new(mrb); 817 } 818 819 mrb_write_barrier(mrb, (struct RBasic*)cls); 820 iv_put(mrb, cls->iv, sym, v); 822 if (cls && cls->tt == MRB_TT_SCLASS) { 823 mrb_value klass; 824 825 klass = mrb_obj_iv_get(mrb, (struct RObject*)cls, 826 mrb_intern_lit(mrb, "__attached__")); 827 switch (mrb_type(klass)) { 828 case MRB_TT_CLASS: 829 case MRB_TT_MODULE: 830 case MRB_TT_SCLASS: 831 c = mrb_class_ptr(klass); 832 break; 833 default: 834 c = cls; 835 break; 836 } 837 } 838 else{ 839 c = cls; 840 } 841 842 if (!c->iv) { 843 c->iv = iv_new(mrb); 844 } 845 846 mrb_write_barrier(mrb, (struct RBasic*)c); 847 iv_put(mrb, c->iv, sym, v); 821 848 } 822 849 … … 927 954 return v; 928 955 } 929 if (c->tt == MRB_TT_SCLASS) { 956 c2 = c; 957 while (c2 && c2->tt == MRB_TT_SCLASS) { 930 958 mrb_value klass; 931 klass = mrb_obj_iv_get(mrb, (struct RObject *)c ,959 klass = mrb_obj_iv_get(mrb, (struct RObject *)c2, 932 960 mrb_intern_lit(mrb, "__attached__")); 933 961 c2 = mrb_class_ptr(klass); 934 if (c2->tt == MRB_TT_CLASS) 935 c = c2; 936 } 962 } 963 if (c2->tt == MRB_TT_CLASS || c2->tt == MRB_TT_MODULE) c = c2; 937 964 c2 = c; 938 965 for (;;) {
Note:
See TracChangeset
for help on using the changeset viewer.