diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2001-08-14 08:13:31 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2001-08-14 08:13:31 +0000 |
commit | 04a8e85bc5d305d1c227ca9d3ccc0794e07fafc1 (patch) | |
tree | 9a58b8ba5b6f90fc55acf9da7dbc478e0b495bda | |
parent | 0aa005f8e96ff032229d1e90a0ac209eb90e4168 (diff) |
* range.c (range_step): new method.
* string.c (rb_str_cmp): remove needless conditional.
* string.c (rb_str_lstrip_bang) `return Qnil' was missing.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1682 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 27 | ||||
-rw-r--r-- | array.c | 4 | ||||
-rw-r--r-- | class.c | 4 | ||||
-rw-r--r-- | doc/NEWS | 4 | ||||
-rw-r--r-- | eval.c | 3 | ||||
-rw-r--r-- | misc/ruby-mode.el | 66 | ||||
-rw-r--r-- | parse.y | 41 | ||||
-rw-r--r-- | range.c | 87 | ||||
-rw-r--r-- | string.c | 3 | ||||
-rw-r--r-- | variable.c | 3 | ||||
-rw-r--r-- | version.h | 4 |
11 files changed, 182 insertions, 64 deletions
@@ -1,3 +1,15 @@ +Tue Aug 14 17:09:12 2001 Yukihiro Matsumoto <matz@ruby-lang.org> + + * range.c (range_step): new method. + +Tue Aug 14 11:49:00 2001 TOYOFUKU Chikanobu <toyofuku@juice.or.jp> + + * string.c (rb_str_cmp): remove needless conditional. + +Tue Aug 14 03:23:25 2001 Koji Arai <JCA02266@nifty.ne.jp> + + * string.c (rb_str_lstrip_bang) `return Qnil' was missing. + Mon Aug 13 14:16:46 2001 Akinori MUSHA <knu@iDaemons.org> * bignum.c, marshal.c: Detypo: s/SIZEOF_ING/SIZEOF_INT/. @@ -9,6 +21,17 @@ Sun Aug 12 15:01:58 2001 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp> * string.c (rb_str_append): nothing to append actually when `str2' is empty. +Sat Aug 11 14:43:47 2001 Tanaka Akira <akr@m17n.org> + + * array.c (rb_inspecting_p): initialize inspect_key if it is + not initialized yet. + +Fri Aug 10 22:14:37 2001 Yukihiro Matsumoto <matz@ruby-lang.org> + + * parse.y (cond0): operands of logical operators are not treated + as conditional expresion anymore, but propagate conditional + status if used in conditionals. + Tue Aug 7 09:10:32 2001 Usaku Nakamura <usa@ruby-lang.org> * win32/win32.h: fix problems with BC++ (ruby-bugs#PR161). @@ -21,6 +44,10 @@ Mon Aug 6 23:47:46 2001 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp> * string.c (rb_str_associate): associates an Array at once, not but a String. realloc's when str_buf. +Mon Aug 6 17:01:33 2001 Yukihiro Matsumoto <matz@ruby-lang.org> + + * eval.c (rb_gc_mark_threads): should mark ruby_cref. + Mon Aug 6 14:31:37 2001 Usaku Nakamura <usa@ruby-lang.org> * numeric.c (num_divmod): fix typo. @@ -910,7 +910,9 @@ rb_inspecting_p(obj) { VALUE inspect_tbl; - if (!inspect_key) return Qfalse; + if (!inspect_key) { + inspect_key = rb_intern("__inspect_key__"); + } inspect_tbl = rb_thread_local_aref(rb_thread_current(), inspect_key); if (NIL_P(inspect_tbl)) return Qfalse; return rb_ary_includes(inspect_tbl, rb_obj_id(obj)); @@ -30,6 +30,7 @@ rb_class_boot(super) klass->m_tbl = 0; /* safe GC */ klass->m_tbl = st_init_numtable(); + OBJ_INFECT(klass, super); return (VALUE)klass; } @@ -280,6 +281,8 @@ include_class_new(module, super) else { RBASIC(klass)->klass = module; } + OBJ_INFECT(klass, module); + OBJ_INFECT(klass, super); return (VALUE)klass; } @@ -308,6 +311,7 @@ rb_include_module(klass, module) Check_Type(module, T_MODULE); } + OBJ_INFECT(klass, module); while (module) { /* ignore if the module included already in superclasses */ for (p = RCLASS(klass)->super; p; p = RCLASS(p)->super) { @@ -1,3 +1,7 @@ +: Range#step([step=1]) + + Added. + : Regexp It is being obsoleted to regard /re/ as /re/ =~ $_ in a conditional @@ -7195,6 +7195,9 @@ rb_gc_mark_threads() { rb_thread_t th; + /* static global mark */ + rb_gc_mark((VALUE)ruby_cref); + if (!curr_thread) return; FOREACH_THREAD(th) { rb_gc_mark(th->thread); diff --git a/misc/ruby-mode.el b/misc/ruby-mode.el index 40f1eaa045..365311e3ed 100644 --- a/misc/ruby-mode.el +++ b/misc/ruby-mode.el @@ -668,11 +668,31 @@ An end of a defun is found by moving forward from the beginning of one." '(lambda () (make-local-variable 'font-lock-syntactic-keywords) (setq font-lock-syntactic-keywords - '(("\\$\\([#\"'`$\\]\\)" 1 (1 . nil)) + '( + ;; #{ }, #$hoge, #@foo are not comments ("\\(#\\)[{$@]" 1 (1 . nil)) - ("\\(/\\)\\([^/\n]\\|\\/\\)*\\(/\\)" - (1 (7 . ?')) - (3 (7 . ?'))) + ;; the last $' in the string ,'...$' is not variable + ("\\(^\\|[[\\s <+(,]\\)\\('\\)[^'\n\\\\]*\\(\\\\.[^'\n\\\\]*\\)*\\$\\('\\)" + (2 (7 . nil)) + (4 (7 . nil))) + ;; the last $` in the string ,`...$` is not variable + ("\\(^\\|[[\\s <+(,]\\)\\(`\\)[^`\n\\\\]*\\(\\\\.[^`\n\\\\]*\\)*\\$\\(`\\)" + (2 (7 . nil)) + (4 (7 . nil))) + ;; the last $" in the string ,"...$" is not variable + ("\\(^\\|[[\\s <+(,]\\)\\(\"\\)[^\"\n\\\\]*\\(\\\\.[^\"\n\\\\]*\\)*\\$\\(\"\\)" + (2 (7 . nil)) + (4 (7 . nil))) + ;; $' $" $` .... are variables + ("\\$[#\"'`$\\]" 0 (1 . nil)) + ;; regexps + ("\\(^\\|[=(,~?:;]\\|\\(^\\|\\s \\)\\(if\\|elsif\\|unless\\|while\\|until\\|when\\|and\\|or\\|&&\\|||\\)\\|g?sub!?\\|scan\\|split!?\\)\\s *\\(/\\)[^/\n\\\\]*\\(\\\\.[^/\n\\\\]*\\)*\\(/\\)" + (4 (7 . ?/)) + (6 (7 . ?/))) + ;; %Q!...! + ("\\(^\\|[[\\s <+(,]\\)%[xrqQ]?\\([^a-zA-Z0-9 \n]\\)[^\n\\\\]*\\(\\\\.[^\n\\\\]*\\)*\\(\\2\\)" + (2 (7 . nil)) + (4 (7 . nil))) ("^\\(=\\)begin\\(\\s \\|$\\)" 1 (7 . nil)) ("^\\(=\\)end\\(\\s \\|$\\)" 1 (7 . nil)))) (make-local-variable 'font-lock-defaults) @@ -707,9 +727,6 @@ An end of a defun is found by moving forward from the beginning of one." (defvar ruby-font-lock-keywords (list - ;; trick - '("\\s-+" 0 nil t) - '("\\S-+" 0 nil t) (cons (concat "\\(^\\|[^_:.@$]\\|\\.\\.\\)\\b\\(" (mapconcat @@ -757,10 +774,10 @@ An end of a defun is found by moving forward from the beginning of one." '("\\(^\\|[^_:.@$]\\|\\.\\.\\)\\b\\(nil\\|self\\|true\\|false\\)\\b\\([^_]\\|$\\)" 2 font-lock-variable-name-face) ;; variables - '("\\(\\$\\(\\W\\|[0-9]\\)\\)\\W" - 1 font-lock-variable-name-face t) - '("\\($\\|@\\|@@\\)\\(\\w\\(\\w\\|_\\)*\\|#{\\)" - 0 font-lock-variable-name-face t) + '("\\(\\$\\([^a-zA-Z0-9 \n]\\|[0-9]\\)\\)\\W" + 1 font-lock-variable-name-face) + '("\\(\\$\\|@\\|@@\\)\\(\\w\\(\\w\\|_\\)*\\|#{\\)" + 0 font-lock-variable-name-face) ;; embedded document '(ruby-font-lock-docs 0 font-lock-comment-face t) @@ -775,34 +792,9 @@ An end of a defun is found by moving forward from the beginning of one." ;; symbols '("\\(^\\|[^:]\\)\\(:\\([-+/%&|^~`]\\|\\*\\*?\\|<\\(<\\|=>?\\)?\\|>[>=]?\\|===?\\|=~\\|\\[\\]\\|\\(\\w\\|_\\)+\\([!?=]\\|\\b\\)\\|#{[^}\n\\\\]*\\(\\\\.[^}\n\\\\]*\\)*}\\)\\)" 2 font-lock-reference-face) - ;; strings - ;; %Q! ! - '("[[\\s <+(,]%[rqQ]?\\(\\([^a-zA-Z0-9 \n]\\)[^\\2\n\\\\]*\\(\\\\.[^\\2\n\\\\]*\\)*\\2\\)" - 1 font-lock-string-face t) - ;; '...' - '("[[\\s <+(,]\\('[^'\n\\\\]*\\(\\\\.[^'\n\\\\]*\\)*'\\)" - 1 font-lock-string-face t) - ;; "..." - '("[[\\s <+(,]\\(\"[^\"\n\\\\]*\\(\\\\.[^\"\n\\\\]*\\)*\"\\)" - 1 font-lock-string-face t) - ;; `...` - '("[\\s <+(,]\\(`[^`\n\\\\]*\\(\\\\.[^`\n\\\\]*\\)*`\\)" - 1 font-lock-warning-face t) - ;; %x!...! - '("[\\s <+(,]%x\\(\\([^a-zA-Z0-9 \n]\\)[^\\2\n\\]*\\(\\\\.[^\\2\n\\]*\\)*\\2\\)" - 1 font-lock-warning-face t) - ;; regexps - '("\\(^\\|[=(,~?:]\\|\\(^\\|\\s \\)\\(if\\|elsif\\|unless\\|while\\|until\\|when\\|and\\|or\\|&&\\|||\\)\\|\\.g?sub!?\\)\\s *\\(/[^/\n\\\\]*\\(\\\\.[^/\n\\\\]*\\)*/\\([iop]*\\)\\)" - (4 font-lock-string-face t) - (6 font-lock-constant-face t)) - '("\\(/[^/\n\\\\]*\\(\\\\.[^/\n\\\\]*\\)*/\\)\\s *[=!][=~]" - 1 font-lock-string-face t) ;; expression expansion '("#{[^}\n\\\\]*\\(\\\\.[^}\n\\\\]*\\)*}" - 0 font-lock-variable-name-face t) - ;; comment - '("^\\s *\\([^#\n'\"%/]\\|'[^'\n\\]*\\(\\\\.[^'\n\\]*\\)*'\\|\"[^\"\n\\]*\\(\\\\.[^\"\n\\]*\\)*\"\\|%[rqQx]?\\([^a-zA-Z0-9 \n]\\)[^\\4\n\\]*\\(\\\\.[^\\4\n\\]*\\)*\\4\\|/[^/\n\\]*\\(\\\\.[^/\n\\]\\)*/\\|#{[^}\\\\]*\\(\\\\.[^}\\\\]*\\)*}\\)*\\(#\\([^{\n].*\\|$\\)\\)" - 8 font-lock-comment-face t)) + 0 font-lock-variable-name-face t)) "*Additional expressions to highlight in ruby mode.")) ((featurep 'hilit19) @@ -4570,34 +4570,30 @@ warning_unless_e_option(str) static NODE *cond0(); static NODE* -range_op(node, logop) +range_op(node) NODE *node; - int logop; { enum node_type type; - if (logop) return node; if (!e_option_supplied()) return node; - warn_unless_e_option("integer literal in condition"); node = cond0(node); type = nd_type(node); if (type == NODE_NEWLINE) node = node->nd_next; if (type == NODE_LIT && FIXNUM_P(node->nd_lit)) { + warn_unless_e_option("integer literal in conditional range"); return call_op(node,tEQ,1,NEW_GVAR(rb_intern("$."))); } return node; } static NODE* -cond0(node, logop) +cond0(node) NODE *node; - int logop; { enum node_type type = nd_type(node); assign_in_cond(node); - if (logop) return node; switch (type) { case NODE_DSTR: @@ -4612,10 +4608,16 @@ cond0(node, logop) local_cnt('~'); return NEW_MATCH2(node, NEW_GVAR(rb_intern("$_"))); + case NODE_AND: + case NODE_OR: + node->nd_1st = cond0(node->nd_1st); + node->nd_2nd = cond0(node->nd_2nd); + break; + case NODE_DOT2: case NODE_DOT3: - node->nd_beg = range_op(node->nd_beg, logop); - node->nd_end = range_op(node->nd_end, logop); + node->nd_beg = range_op(node->nd_beg); + node->nd_end = range_op(node->nd_end); if (type == NODE_DOT2) nd_set_type(node,NODE_FLIP2); else if (type == NODE_DOT3) nd_set_type(node, NODE_FLIP3); node->nd_cnt = local_append(0); @@ -4624,33 +4626,28 @@ cond0(node, logop) case NODE_LIT: if (TYPE(node->nd_lit) == T_REGEXP) { - warning_unless_e_option("regex literal in condition"); + warn_unless_e_option("regex literal in condition"); nd_set_type(node, NODE_MATCH); local_cnt('_'); local_cnt('~'); } + else { + rb_warning("literal in condition"); + } } return node; } static NODE* -cond1(node, logop) +cond(node) NODE *node; - int logop; { if (node == 0) return 0; if (nd_type(node) == NODE_NEWLINE){ - node->nd_next = cond0(node->nd_next, logop); + node->nd_next = cond0(node->nd_next); return node; } - return cond0(node, logop); -} - -static NODE* -cond(node) - NODE *node; -{ - return cond1(node, 0); + return cond0(node); } static NODE* @@ -4659,7 +4656,7 @@ logop(type, left, right) NODE *left, *right; { value_expr(left); - return rb_node_newnode(type, cond1(left, 1), cond1(right, 1), 0); + return rb_node_newnode(type, left, right, 0); } static NODE * @@ -233,6 +233,92 @@ range_each(range) } static VALUE +r_step_str(args) + VALUE *args; +{ + return rb_str_upto(args[0], args[1], EXCL(args[2])); +} + +static VALUE +r_step_str_i(i, iter) + VALUE i; + long *iter; +{ + iter[0]--; + if (iter[0] == 0) { + rb_yield(i); + iter[0] = iter[1]; + } + return Qnil; +} + +static VALUE +range_step(argc, argv, range) + int argc; + VALUE *argv; + VALUE range; +{ + VALUE b, e, step; + + b = rb_ivar_get(range, id_beg); + e = rb_ivar_get(range, id_end); + rb_scan_args(argc, argv, "01", &step); + + if (FIXNUM_P(b) && FIXNUM_P(e)) { /* fixnums are special */ + long end = FIX2LONG(e); + long i, s = (argc == 0) ? 1 : NUM2LONG(step); + + if (!EXCL(range)) end += 1; + for (i=FIX2LONG(b); i<end; i+=s) { + rb_yield(INT2NUM(i)); + } + } + else if (rb_obj_is_kind_of(b, rb_cNumeric)) { + b = rb_Integer(b); + e = rb_Integer(e); + step = rb_Integer(step); + + if (!EXCL(range)) e = rb_funcall(e, '+', 1, INT2FIX(1)); + while (RTEST(rb_funcall(b, '<', 1, e))) { + rb_yield(b); + b = rb_funcall(b, '+', 1, step); + } + } + else if (TYPE(b) == T_STRING) { + VALUE args[5]; + long *iter; + + args[0] = b; args[1] = e; args[2] = range; + iter[0] = 1; iter[1] = NUM2LONG(step); + rb_iterate(r_step_str, (VALUE)args, r_step_str_i, (VALUE)iter); + } + else { /* generic each */ + VALUE v = b; + long lim = NUM2INT(step); + long i; + + if (EXCL(range)) { + while (r_lt(v, e)) { + if (r_eq(v, e)) break; + rb_yield(v); + for (i=0; i<lim; i++) + v = rb_funcall(v, id_succ, 0, 0); + } + } + else { + while (r_le(v, e)) { + rb_yield(v); + if (r_eq(v, e)) break; + for (i=0; i<lim; i++) + v = rb_funcall(v, id_succ, 0, 0); + } + } + } + + return range; +} + +static VALUE range_first(obj) VALUE obj; { @@ -417,6 +503,7 @@ Init_Range() rb_define_method(rb_cRange, "==", range_eq, 1); rb_define_method(rb_cRange, "===", range_eqq, 1); rb_define_method(rb_cRange, "each", range_each, 0); + rb_define_method(rb_cRange, "step", range_step, -1); rb_define_method(rb_cRange, "first", range_first, 0); rb_define_method(rb_cRange, "last", range_last, 0); rb_define_method(rb_cRange, "begin", range_first, 0); @@ -686,7 +686,6 @@ rb_str_cmp(str1, str2) if (RSTRING(str1)->len > RSTRING(str2)->len) return 1; return -1; } - if (retval == 0) return 0; if (retval > 0) return 1; return -1; } @@ -2674,6 +2673,7 @@ rb_str_lstrip_bang(str) RSTRING(str)->ptr[RSTRING(str)->len] = '\0'; return str; } + return Qnil; } static VALUE @@ -3065,7 +3065,6 @@ Init_String() rb_define_method(rb_cString, "sub!", rb_str_sub_bang, -1); rb_define_method(rb_cString, "gsub!", rb_str_gsub_bang, -1); - rb_define_method(rb_cString, "strip!", rb_str_strip_bang, 0); rb_define_method(rb_cString, "chop!", rb_str_chop_bang, 0); rb_define_method(rb_cString, "chomp!", rb_str_chomp_bang, -1); rb_define_method(rb_cString, "strip!", rb_str_strip_bang, 0); diff --git a/variable.c b/variable.c index 79e02b910c..8090efd76c 100644 --- a/variable.c +++ b/variable.c @@ -1412,6 +1412,9 @@ rb_cvar_declare(klass, id, val) if (RCLASS(tmp)->iv_tbl && st_lookup(RCLASS(tmp)->iv_tbl,id,0)) { if (!OBJ_TAINTED(tmp) && rb_safe_level() >= 4) rb_raise(rb_eSecurityError, "Insecure: can't modify class variable"); + if (ruby_verbose && klass != tmp) { + rb_warning("already initialized class variable %s", rb_id2name(id)); + } st_insert(RCLASS(tmp)->iv_tbl,id,val); return; } @@ -1,4 +1,4 @@ #define RUBY_VERSION "1.7.1" -#define RUBY_RELEASE_DATE "2001-08-06" +#define RUBY_RELEASE_DATE "2001-08-14" #define RUBY_VERSION_CODE 171 -#define RUBY_RELEASE_CODE 20010806 +#define RUBY_RELEASE_CODE 20010814 |