summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog18
-rw-r--r--error.c5
-rw-r--r--parse.y73
-rw-r--r--regex.c10
-rw-r--r--time.c51
5 files changed, 102 insertions, 55 deletions
diff --git a/ChangeLog b/ChangeLog
index 4fd252c7ed..899b9f6edf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -6,7 +6,23 @@ Wed Jan 22 23:19:57 2003 NAKAMURA Usaku <usa@ruby-lang.org>
* win32/win32.c (pipe_exec): remove unnecessary SetStdHandle().
-Tue Jan 21 20:29:31 2003 Michal Rokos <michal@rokos.homeip.net>
+Wed Jan 22 20:20:59 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * parse.y (arg): syntaxify tPOW negative number hack.
+
+ * parse.y (negate_lit): new function to negate literal numeric
+ values in compile time.
+
+Wed Jan 22 15:36:54 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * regex.c (re_match_exec): charset info may be stored in MBC
+ region when $KCODE != NONE.
+
+Wed Jan 22 14:22:53 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * error.c (set_syserr): should preserve duplicated error names.
+
+=Tue Jan 21 20:29:31 2003 Michal Rokos <michal@rokos.homeip.net>
* mkmf.rb: make possible to add files to clean and distclean targets
diff --git a/error.c b/error.c
index e364084bc0..6f958aa2d0 100644
--- a/error.c
+++ b/error.c
@@ -479,10 +479,13 @@ set_syserr(n, name)
VALUE error;
if (!st_lookup(syserr_tbl, n, &error)) {
- error = rb_define_class_under(rb_mErrno, name, rb_eSystemCallError);;
+ error = rb_define_class_under(rb_mErrno, name, rb_eSystemCallError);
rb_define_const(error, "Errno", INT2NUM(n));
st_add_direct(syserr_tbl, n, error);
}
+ else {
+ rb_define_const(rb_mErrno, name, error);
+ }
return error;
}
diff --git a/parse.y b/parse.y
index 5bbcf06d64..8d34c153d2 100644
--- a/parse.y
+++ b/parse.y
@@ -137,6 +137,7 @@ static NODE *new_evstr();
static NODE *call_op();
static int in_defined = 0;
+static NODE *negate_lit();
static NODE *ret_args();
static NODE *arg_blk_pass();
static NODE *new_call();
@@ -306,8 +307,9 @@ static void top_local_setup();
%left tLSHFT tRSHFT
%left '+' '-'
%left '*' '/' '%'
-%right '!' '~' tUPLUS tUMINUS
+%right tUMINUS_NUM
%right tPOW
+%right '!' '~' tUPLUS tUMINUS
%token tLAST_TOKEN
@@ -1022,26 +1024,15 @@ arg : lhs '=' arg
}
| arg tPOW arg
{
- int need_negate = Qfalse;
-
- if ($1 && nd_type($1) == NODE_LIT) {
-
- switch (TYPE($1->nd_lit)) {
- case T_FIXNUM:
- case T_FLOAT:
- case T_BIGNUM:
- if (RTEST(rb_funcall($1->nd_lit,'<',1,INT2FIX(0)))) {
- $1->nd_lit = rb_funcall($1->nd_lit,rb_intern("-@"),0,0);
- need_negate = Qtrue;
- }
- default:
- break;
- }
- }
$$ = call_op($1, tPOW, 1, $3);
- if (need_negate) {
- $$ = call_op($$, tUMINUS, 0, 0);
- }
+ }
+ | tUMINUS_NUM tINTEGER tPOW arg
+ {
+ $$ = call_op(call_op($2, tPOW, 1, $4), tUMINUS);
+ }
+ | tUMINUS_NUM tFLOAT tPOW arg
+ {
+ $$ = call_op(call_op($2, tPOW, 1, $4), tUMINUS);
}
| tUPLUS arg
{
@@ -1054,15 +1045,7 @@ arg : lhs '=' arg
}
| tUMINUS arg
{
- if ($2 && nd_type($2) == NODE_LIT && FIXNUM_P($2->nd_lit)) {
- long i = FIX2LONG($2->nd_lit);
-
- $2->nd_lit = LONG2NUM(-i);
- $$ = $2;
- }
- else {
- $$ = call_op($2, tUMINUS, 0, 0);
- }
+ $$ = call_op($2, tUMINUS, 0, 0);
}
| arg '|' arg
{
@@ -2096,6 +2079,14 @@ dsym : tSYMBEG xstring_contents tSTRING_END
numeric : tINTEGER
| tFLOAT
+ | tUMINUS_NUM tINTEGER %prec tLOWEST
+ {
+ $$ = negate_lit($2);
+ }
+ | tUMINUS_NUM tFLOAT %prec tLOWEST
+ {
+ $$ = negate_lit($2);
+ }
;
variable : tIDENTIFIER
@@ -3654,8 +3645,12 @@ yylex()
lex_state = EXPR_BEG;
pushback(c);
if (ISDIGIT(c)) {
+#if 0
c = '-';
goto start_num;
+#else
+ return tUMINUS_NUM;
+#endif
}
return tUMINUS;
}
@@ -5268,6 +5263,26 @@ ret_args(node)
return node;
}
+static NODE*
+negate_lit(node)
+ NODE *node;
+{
+ switch (TYPE(node->nd_lit)) {
+ case T_FIXNUM:
+ node->nd_lit = LONG2FIX(-FIX2LONG(node->nd_lit));
+ break;
+ case T_BIGNUM:
+ node->nd_lit = rb_funcall(node->nd_lit,tUMINUS,0,0);
+ break;
+ case T_FLOAT:
+ RFLOAT(node->nd_lit)->value = -RFLOAT(node->nd_lit)->value;
+ break;
+ default:
+ break;
+ }
+ return node;
+}
+
static NODE *
arg_blk_pass(node1, node2)
NODE *node1;
diff --git a/regex.c b/regex.c
index 360b7a8efc..53eb9b469b 100644
--- a/regex.c
+++ b/regex.c
@@ -740,7 +740,7 @@ is_in_list(c, b)
unsigned long c;
const unsigned char *b;
{
- return is_in_list_sbc(c, b) || is_in_list_mbc(c, b);
+ return is_in_list_sbc(c, b) || (current_mbctype ? is_in_list_mbc(c, b) : 0);
}
static void
@@ -1689,7 +1689,7 @@ re_compile_pattern(pattern, size, bufp)
SET_LIST_BIT(c);
had_num_literal = 0;
}
- else
+ else
set_list_bits(c, c, b);
had_mbchar = 0;
}
@@ -3838,16 +3838,16 @@ re_match_exec(bufp, string_arg, size, pos, beg, regs)
MBC2WC(c, d);
not = is_in_list_mbc(c, p);
if (!not) {
- part = not = is_in_list_sbc(cc, p);
+ part = not = is_in_list(cc, p);
}
} else {
- not = is_in_list_sbc(c, p);
+ not = is_in_list(c, p);
}
}
else {
if (TRANSLATE_P())
c = (unsigned char)translate[c];
- not = is_in_list_sbc(c, p);
+ not = is_in_list(c, p);
}
if (*(p - 1) == (unsigned char)charset_not) {
diff --git a/time.c b/time.c
index b2aee1041d..310530f2c0 100644
--- a/time.c
+++ b/time.c
@@ -236,11 +236,12 @@ time_arg(argc, argv, tm, usec)
struct tm *tm;
time_t *usec;
{
- VALUE v[7];
+ VALUE v[8];
int i;
long year;
MEMZERO(tm, struct tm, 1);
+ *usec = 0;
if (argc == 10) {
v[0] = argv[5];
v[1] = argv[4];
@@ -248,12 +249,13 @@ time_arg(argc, argv, tm, usec)
v[3] = argv[2];
v[4] = argv[1];
v[5] = argv[0];
- *usec = 0;
tm->tm_isdst = RTEST(argv[8]) ? 1 : 0;
}
else {
- rb_scan_args(argc, argv, "16", &v[0],&v[1],&v[2],&v[3],&v[4],&v[5],&v[6]);
- *usec = NIL_P(v[6]) ? 0 : obj2long(v[6]);
+ rb_scan_args(argc, argv, "17", &v[0],&v[1],&v[2],&v[3],&v[4],&v[5],&v[6],&v[7]);
+ /* v[6] may be usec or zone (parsedate) */
+ /* v[7] is wday (parsedate; ignored) */
+ tm->tm_wday = -1;
tm->tm_isdst = -1;
}
@@ -275,25 +277,28 @@ time_arg(argc, argv, tm, usec)
if (NIL_P(v[1])) {
tm->tm_mon = 0;
}
- else if (TYPE(v[1]) == T_STRING) {
- tm->tm_mon = -1;
- for (i=0; i<12; i++) {
- if (RSTRING(v[1])->len == 3 &&
- strcasecmp(months[i], RSTRING(v[1])->ptr) == 0) {
- tm->tm_mon = i;
- break;
+ else {
+ VALUE s = rb_check_string_type(v[1]);
+ if (!NIL_P(s)) {
+ tm->tm_mon = -1;
+ for (i=0; i<12; i++) {
+ if (RSTRING(s)->len == 3 &&
+ strcasecmp(months[i], RSTRING(v[1])->ptr) == 0) {
+ tm->tm_mon = i;
+ break;
+ }
}
- }
- if (tm->tm_mon == -1) {
- char c = RSTRING(v[1])->ptr[0];
+ if (tm->tm_mon == -1) {
+ char c = RSTRING(s)->ptr[0];
- if ('0' <= c && c <= '9') {
- tm->tm_mon = obj2long(v[1])-1;
+ if ('0' <= c && c <= '9') {
+ tm->tm_mon = obj2long(s)-1;
+ }
}
}
- }
- else {
- tm->tm_mon = obj2long(v[1]) - 1;
+ else {
+ tm->tm_mon = obj2long(v[1])-1;
+ }
}
if (NIL_P(v[2])) {
tm->tm_mday = 1;
@@ -304,6 +309,14 @@ time_arg(argc, argv, tm, usec)
tm->tm_hour = NIL_P(v[3])?0:obj2long(v[3]);
tm->tm_min = NIL_P(v[4])?0:obj2long(v[4]);
tm->tm_sec = NIL_P(v[5])?0:obj2long(v[5]);
+ if (!NIL_P(v[6])) {
+ if (argc == 8) {
+ /* v[6] is timezone, but ignored */
+ }
+ else {
+ *usec = obj2long(v[6]);
+ }
+ }
/* value validation */
if (