Skip to content

Commit

Permalink
* random.c: replace with Mersenne Twister RNG.
Browse files Browse the repository at this point in the history
* eval.c (jump_tag_but_local_jump): preserve retval in
  LocalJumpError exceptions.

* parse.y (command): no more check for "super outside of method".

* eval.c (rb_mod_define_method): should set last_class and
  last_func in the block->frame.

* eval.c (error_handle): should handle TAG_THROW as well.

* parse.y (yylex): new decimal notation '0d4567'.

* parse.y (yylex): new octal notation '0o777'.

* parse.y (string_content): every string_content node should
  return string only.  use NODE_EVSTR to coercing.

* eval.c (rb_eval): NODE_EVSTR support.

* re.c (rb_reg_quote): avoid unnecessary string allocation.

* string.c (get_pat): quote metachracters before compiling a
  string into a regex.

* string.c (rb_str_split_m): special treatment of strings of size
  1, but AWK emulation.  now uses get_pat().

* string.c (rb_str_match_m): quote metacharacters.

* string.c (rb_str_match2): ditto.

* ext/socket/socket.c (sock_addrinfo): make all 3 versions of
  getaddrinfo happy.  [ruby-core:00184]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2654 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
matz committed Jul 26, 2002
1 parent 1d132e6 commit 7194b66
Show file tree
Hide file tree
Showing 14 changed files with 462 additions and 207 deletions.
52 changes: 52 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Fri Jul 26 14:31:06 2002 Yukihiro Matsumoto <[email protected]>

* random.c: replace with Mersenne Twister RNG.

Fri Jul 26 12:14:48 2002 Minero Aoki <[email protected]>

* parse.y (yylex): modify to accept a code like "m (a){...}".
Expand All @@ -22,6 +26,24 @@ Thu Jul 25 09:05:02 2002 Nobuyoshi Nakada <[email protected]>

* misc/ruby-mode.el (ruby-move-to-block): skips RD style comments.

Wed Jul 24 09:47:42 2002 Yukihiro Matsumoto <[email protected]>

* eval.c (jump_tag_but_local_jump): preserve retval in
LocalJumpError exceptions.

* parse.y (command): no more check for "super outside of method".

* eval.c (rb_mod_define_method): should set last_class and
last_func in the block->frame.

Mon Jul 22 17:23:00 2002 Yukihiro Matsumoto <[email protected]>

* eval.c (error_handle): should handle TAG_THROW as well.

Fri Jul 19 10:52:32 2002 Yukihiro Matsumoto <[email protected]>

* parse.y (yylex): new decimal notation '0d4567'.

Thu Jul 18 11:52:02 2002 Shugo Maeda <[email protected]>

* lib/net/ftp.rb (set_socket): new method.
Expand All @@ -30,6 +52,17 @@ Thu Jul 18 06:51:24 2002 Minero Aoki <[email protected]>

* parse.y (yylex): fix typo.

Wed Jul 17 18:41:28 2002 Yukihiro Matsumoto <[email protected]>

* parse.y (yylex): new octal notation '0o777'.

Mon Jul 15 18:36:42 2002 Yukihiro Matsumoto <[email protected]>

* parse.y (string_content): every string_content node should
return string only. use NODE_EVSTR to coercing.

* eval.c (rb_eval): NODE_EVSTR support.

Mon Jul 15 10:35:35 2002 Minero Aoki <[email protected]>

* parse.y (heredoc_identifier): fix typo.
Expand Down Expand Up @@ -61,6 +94,20 @@ Fri Jul 12 00:02:50 2002 Nobuyoshi Nakada <[email protected]>
* ext/stringio/stringio.c (strio_gets_internal): fixed for record
separator longer than 1.

Thu Jul 11 17:59:20 2002 Yukihiro Matsumoto <[email protected]>

* re.c (rb_reg_quote): avoid unnecessary string allocation.

* string.c (get_pat): quote metachracters before compiling a
string into a regex.

* string.c (rb_str_split_m): special treatment of strings of size
1, but AWK emulation. now uses get_pat().

* string.c (rb_str_match_m): quote metacharacters.

* string.c (rb_str_match2): ditto.

Thu Jul 11 12:59:23 2002 Shugo Maeda <[email protected]>

* lib/resolv.rb: untaint strings read from /etc/hosts and
Expand Down Expand Up @@ -256,6 +303,11 @@ Sun Jun 23 00:19:10 2002 Tadayoshi Funaba <[email protected]>
* lib/date.rb, lib/date/format.rb, sample/cal.rb, sample/goodfriday.rb:
updated to the new version (based on date2 3.3).

Sat Jun 22 14:41:33 2002 Guy Decoux <[email protected]>

* ext/socket/socket.c (sock_addrinfo): make all 3 versions of
getaddrinfo happy. [ruby-core:00184]

Fri Jun 21 18:49:58 2002 Yukihiro Matsumoto <[email protected]>

* parse.y (yylex): __END__ should not be effective within
Expand Down
47 changes: 47 additions & 0 deletions LEGAL
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,53 @@ win32/win32.[ch]:
You may distribute under the terms of either the GNU General Public
License or the Artistic License, as specified in the perl README file.

random.c

This file is under the new-style BSD license.

A C-program for MT19937, with initialization improved 2002/2/10.
Coded by Takuji Nishimura and Makoto Matsumoto.
This is a faster version by taking Shawn Cokus's optimization,
Matthe Bellew's simplification, Isaku Wada's real version.

Before using, initialize the state by using init_genrand(seed)
or init_by_array(init_key, key_length).

Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

3. The names of its contributors may not be used to endorse or promote
products derived from this software without specific prior written
permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


Any feedback is very welcome.
http://www.math.keio.ac.jp/matumoto/emt.html
email: [email protected]

st.[ch]:
x68/*:
missing/alloca.c:
Expand Down
1 change: 1 addition & 0 deletions ToDo
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ Standard Libraries
- Hash::new{default}
- hash etc. should handle self referenceing array/hash
- Array#select(n1,n2...) works like Array#indexes(n1,n2...)
- use Mersenne Twister RNG for random.
* String#scanf(?)
* Object#fmt(?)
* Time::strptime
Expand Down
10 changes: 3 additions & 7 deletions bignum.c
Original file line number Diff line number Diff line change
Expand Up @@ -1675,22 +1675,18 @@ rb_big_abs(x)
return x;
}

/* !!!warnig!!!!
this is not really a random number!!
*/

VALUE
rb_big_rand(max, rand)
rb_big_rand(max, rand_buf)
VALUE max;
double rand;
double *rand_buf;
{
VALUE v;
long len;

len = RBIGNUM(max)->len;
v = bignew(len,1);
while (len--) {
BDIGITS(v)[len] = ((BDIGIT)~0) * rand;
BDIGITS(v)[len] = ((BDIGIT)~0) * rand_buf[len];
}

return rb_big_modulo((VALUE)v, max);
Expand Down
32 changes: 28 additions & 4 deletions eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -1141,6 +1141,17 @@ error_handle(ex)
fprintf(stderr, ": retry outside of rescue clause\n");
ex = 1;
break;
case TAG_THROW:
if (prot_tag && prot_tag->frame && prot_tag->frame->file) {
fprintf(stderr, "%s:%d: uncaught throw\n",
prot_tag->frame->file, prot_tag->frame->line);
}
else {
error_pos();
fprintf(stderr, ": unexpected throw\n");
}
ex = 1;
break;
case TAG_RAISE:
case TAG_FATAL:
if (rb_obj_is_kind_of(ruby_errinfo, rb_eSystemExit)) {
Expand Down Expand Up @@ -1354,17 +1365,21 @@ static void
jump_tag_but_local_jump(state)
int state;
{
VALUE val;

if (prot_tag) val = prot_tag->retval;
else val = Qnil;
switch (state) {
case 0:
break;
case TAG_RETURN:
localjump_error("unexpected return", Qnil);
localjump_error("unexpected return", val);
break;
case TAG_NEXT:
localjump_error("unexpected next", Qnil);
localjump_error("unexpected next", val);
break;
case TAG_BREAK:
localjump_error("unexpected break", Qnil);
localjump_error("unexpected break", val);
break;
case TAG_REDO:
localjump_error("unexpected redo", Qnil);
Expand Down Expand Up @@ -1412,7 +1427,6 @@ rb_eval_cmd(cmd, arg, tcheck)
if ((state = EXEC_TAG()) == 0) {
val = eval(ruby_top_self, cmd, Qnil, 0, 0);
}

if (ruby_scope->flags & SCOPE_DONT_RECYCLE)
scope_dup(saved_scope);
ruby_scope = saved_scope;
Expand Down Expand Up @@ -3059,6 +3073,10 @@ rb_eval(self, n)
result = rb_str_new3(node->nd_lit);
break;

case NODE_EVSTR:
result = rb_obj_as_string(rb_eval(self, node->nd_body));
break;

case NODE_DSTR:
case NODE_DXSTR:
case NODE_DREGX:
Expand Down Expand Up @@ -7102,6 +7120,12 @@ rb_mod_define_method(argc, argv, mod)
node = NEW_DMETHOD(method_unbind(body));
}
else if (RDATA(body)->dmark == (RUBY_DATA_FUNC)blk_mark) {
struct BLOCK *block;

body = bind_clone(body);
Data_Get_Struct(body, struct BLOCK, block);
block->frame.last_func = id;
block->frame.last_class = mod;
node = NEW_BMETHOD(body);
}
else {
Expand Down
2 changes: 1 addition & 1 deletion gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,6 @@ rb_gc_mark_children(ptr)
case NODE_ARRAY:
case NODE_DSTR:
case NODE_DXSTR:
case NODE_EVSTR:
case NODE_DREGX:
case NODE_DREGX_ONCE:
case NODE_FBODY:
Expand Down Expand Up @@ -697,6 +696,7 @@ rb_gc_mark_children(ptr)
case NODE_MODULE:
case NODE_COLON3:
case NODE_OPT_N:
case NODE_EVSTR:
rb_gc_mark((VALUE)obj->as.node.u2.node);
break;

Expand Down
2 changes: 1 addition & 1 deletion intern.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ VALUE rb_big_and _((VALUE, VALUE));
VALUE rb_big_or _((VALUE, VALUE));
VALUE rb_big_xor _((VALUE, VALUE));
VALUE rb_big_lshift _((VALUE, VALUE));
VALUE rb_big_rand _((VALUE, double));
VALUE rb_big_rand _((VALUE, double*));
/* class.c */
VALUE rb_class_boot _((VALUE));
VALUE rb_class_new _((VALUE));
Expand Down
2 changes: 1 addition & 1 deletion node.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ typedef struct RNode {
#define NEW_DSTR(s) rb_node_newnode(NODE_DSTR,s,0,0)
#define NEW_XSTR(s) rb_node_newnode(NODE_XSTR,s,0,0)
#define NEW_DXSTR(s) rb_node_newnode(NODE_DXSTR,s,0,0)
#define NEW_EVSTR(s,l) rb_node_newnode(NODE_EVSTR,rb_str_new(s,l),0,0)
#define NEW_EVSTR(n) rb_node_newnode(NODE_EVSTR,0,(n),0)
#define NEW_CALL(r,m,a) rb_node_newnode(NODE_CALL,r,m,a)
#define NEW_FCALL(m,a) rb_node_newnode(NODE_FCALL,0,m,a)
#define NEW_VCALL(m) rb_node_newnode(NODE_VCALL,0,m,0)
Expand Down
3 changes: 2 additions & 1 deletion numeric.c
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,7 @@ rb_num2long(val)
case T_BIGNUM:
return rb_big2long(val);

#if 0
case T_STRING:
rb_raise(rb_eTypeError, "no implicit conversion to integer from string");
return Qnil; /* not reached */
Expand All @@ -869,7 +870,7 @@ rb_num2long(val)
case T_FALSE:
rb_raise(rb_eTypeError, "no implicit conversion to integer from boolean");
return Qnil; /* not reached */

#endif
default:
val = rb_to_int(val);
return NUM2LONG(val);
Expand Down
Loading

0 comments on commit 7194b66

Please sign in to comment.