mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
heredoc etc.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@135 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
24a8209146
commit
b513f64769
8 changed files with 108 additions and 52 deletions
16
ChangeLog
16
ChangeLog
|
@ -1,3 +1,19 @@
|
|||
Wed Mar 25 08:12:07 1998 Yukihiro Matsumoto <matz@netlab.co.jp>
|
||||
|
||||
* numeric.c (flo_modulo): caused SEGV if left operand is not a
|
||||
float value.
|
||||
|
||||
* eval.c (f_eval): optional third and fourth argument to specify
|
||||
file name and line number.
|
||||
|
||||
* eval.c (eval): filename and linenumber set properly.
|
||||
|
||||
* parse.y (assign_in_cond): literal assignment is now warning, not
|
||||
compile error.
|
||||
|
||||
* error.c (Warn): Warn() always print message, OTOH Waring()
|
||||
prints when verbose flag is set.
|
||||
|
||||
Tue Mar 24 12:50:06 1998 Yukihiro Matsumoto <matz@netlab.co.jp>
|
||||
|
||||
* ruby.c (ruby_prog_init): `.' should come last in the load-path.
|
||||
|
|
16
error.c
16
error.c
|
@ -94,6 +94,22 @@ Error_Append(fmt, va_alist)
|
|||
err_append(buf);
|
||||
}
|
||||
|
||||
void
|
||||
Warn(fmt, va_alist)
|
||||
char *fmt;
|
||||
va_dcl
|
||||
{
|
||||
char buf[BUFSIZ];
|
||||
va_list args;
|
||||
|
||||
sprintf(buf, "warning: %s", fmt);
|
||||
|
||||
va_start(args);
|
||||
err_print(buf, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
/* Warning() reports only in verbose mode */
|
||||
void
|
||||
Warning(fmt, va_alist)
|
||||
char *fmt;
|
||||
|
|
72
eval.c
72
eval.c
|
@ -21,7 +21,7 @@
|
|||
#include "dln.h"
|
||||
|
||||
#ifndef HAVE_STRING_H
|
||||
char *strrchr();
|
||||
char *strrchr _((char*,char));
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_UNISTD_H
|
||||
|
@ -547,18 +547,15 @@ VALUE the_class;
|
|||
the_scope = _old;\
|
||||
}
|
||||
|
||||
static VALUE rb_eval();
|
||||
static VALUE eval();
|
||||
static NODE *compile();
|
||||
static VALUE rb_eval _((VALUE,NODE*));
|
||||
static VALUE eval _((VALUE,VALUE,VALUE,char*,int));
|
||||
static NODE *compile _((VALUE,char*));
|
||||
|
||||
static VALUE rb_call();
|
||||
VALUE rb_apply();
|
||||
VALUE rb_funcall2();
|
||||
static VALUE rb_call _((VALUE,VALUE,ID,int,VALUE*,int));
|
||||
static VALUE module_setup _((VALUE,NODE*));
|
||||
|
||||
static VALUE module_setup();
|
||||
|
||||
static VALUE massign();
|
||||
static void assign();
|
||||
static VALUE massign _((VALUE,NODE*,VALUE));
|
||||
static void assign _((VALUE,NODE*,VALUE));
|
||||
|
||||
static int safe_level = 0;
|
||||
/* safe-level:
|
||||
|
@ -943,7 +940,7 @@ rb_eval_string(str)
|
|||
char *oldsrc = sourcefile;
|
||||
|
||||
sourcefile = "(eval)";
|
||||
v = eval(TopSelf, str_new2(str), Qnil);
|
||||
v = eval(TopSelf, str_new2(str), Qnil, 0, 0);
|
||||
sourcefile = oldsrc;
|
||||
|
||||
return v;
|
||||
|
@ -975,7 +972,7 @@ rb_eval_cmd(cmd, arg)
|
|||
}
|
||||
|
||||
if ((state = EXEC_TAG()) == 0) {
|
||||
eval(TopSelf, cmd, Qnil);
|
||||
eval(TopSelf, cmd, Qnil, 0, 0);
|
||||
}
|
||||
|
||||
the_scope = saved_scope;
|
||||
|
@ -2139,7 +2136,7 @@ rb_eval(self, node)
|
|||
if (nd_type(list->nd_head) == NODE_EVSTR) {
|
||||
rb_in_eval++;
|
||||
eval_tree = 0;
|
||||
list->nd_head = compile(list->nd_head->nd_lit);
|
||||
list->nd_head = compile(list->nd_head->nd_lit,0);
|
||||
rb_in_eval--;
|
||||
if (nerrs > 0) {
|
||||
compile_error("string expand");
|
||||
|
@ -3627,22 +3624,25 @@ rb_frame_last_func()
|
|||
}
|
||||
|
||||
static NODE*
|
||||
compile(src)
|
||||
compile(src, place)
|
||||
VALUE src;
|
||||
char *place;
|
||||
{
|
||||
NODE *node;
|
||||
|
||||
Check_Type(src, T_STRING);
|
||||
|
||||
node = compile_string(sourcefile, RSTRING(src)->ptr, RSTRING(src)->len);
|
||||
if (place == 0) place = sourcefile;
|
||||
node = compile_string(place, RSTRING(src)->ptr, RSTRING(src)->len);
|
||||
|
||||
if (nerrs == 0) return node;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
eval(self, src, scope)
|
||||
eval(self, src, scope, file, line)
|
||||
VALUE self, src, scope;
|
||||
char *file;
|
||||
int line;
|
||||
{
|
||||
struct BLOCK *data;
|
||||
volatile VALUE result = Qnil;
|
||||
|
@ -3650,11 +3650,18 @@ eval(self, src, scope)
|
|||
struct BLOCK * volatile old_block;
|
||||
struct RVarmap * volatile old_d_vars;
|
||||
struct FRAME frame;
|
||||
char *file = sourcefile;
|
||||
int line = sourceline;
|
||||
char *filesave = sourcefile;
|
||||
int linesave = sourceline;
|
||||
volatile int iter = the_frame->iter;
|
||||
int state;
|
||||
|
||||
if (file == 0) {
|
||||
file = sourcefile;
|
||||
line = sourceline;
|
||||
}
|
||||
else if (line > 0) {
|
||||
sourceline = line;
|
||||
}
|
||||
if (!NIL_P(scope)) {
|
||||
if (TYPE(scope) != T_DATA || RDATA(scope)->dfree != blk_free) {
|
||||
TypeError("wrong argument type %s (expected Proc/Binding)",
|
||||
|
@ -3692,7 +3699,7 @@ eval(self, src, scope)
|
|||
PUSH_TAG(PROT_NONE);
|
||||
if ((state = EXEC_TAG()) == 0) {
|
||||
eval_tree = 0;
|
||||
compile(src);
|
||||
compile(src, file);
|
||||
if (nerrs > 0) {
|
||||
compile_error(0);
|
||||
}
|
||||
|
@ -3710,19 +3717,21 @@ eval(self, src, scope)
|
|||
else {
|
||||
the_frame->iter = iter;
|
||||
}
|
||||
sourcefile = filesave;
|
||||
sourceline = linesave;
|
||||
if (state) {
|
||||
VALUE err;
|
||||
|
||||
if (state == TAG_RAISE) {
|
||||
sourcefile = file;
|
||||
sourceline = line;
|
||||
if (strcmp(sourcefile, "(eval)") == 0) {
|
||||
err = str_dup(errinfo);
|
||||
if (strcmp(file, "(eval)") == 0) {
|
||||
if (sourceline > 1) {
|
||||
err = RARRAY(errat)->ptr[0];
|
||||
str_cat(err, ": ", 2);
|
||||
str_cat(err, RSTRING(errinfo)->ptr, RSTRING(errinfo)->len);
|
||||
}
|
||||
else {
|
||||
err = str_dup(errinfo);
|
||||
}
|
||||
errat = Qnil;
|
||||
rb_raise(exc_new3(CLASS_OF(errinfo), err));
|
||||
}
|
||||
|
@ -3740,12 +3749,17 @@ f_eval(argc, argv, self)
|
|||
VALUE *argv;
|
||||
VALUE self;
|
||||
{
|
||||
VALUE src, scope;
|
||||
VALUE src, scope, vfile, line;
|
||||
char *file = "(eval)";
|
||||
|
||||
rb_scan_args(argc, argv, "11", &src, &scope);
|
||||
rb_scan_args(argc, argv, "13", &src, &scope, &vfile, &line);
|
||||
if (!NIL_P(vfile)) {
|
||||
Check_Type(vfile, T_STRING);
|
||||
file = RSTRING(vfile)->ptr;
|
||||
}
|
||||
|
||||
Check_SafeStr(src);
|
||||
return eval(self, src, scope);
|
||||
return eval(self, src, scope, file, NUM2INT(line));
|
||||
}
|
||||
|
||||
static VALUE
|
||||
|
@ -3766,7 +3780,7 @@ eval_under(under, self, src)
|
|||
the_frame->cbase = (VALUE)node_newnode(NODE_CREF,under,0,cbase);
|
||||
PUSH_TAG(PROT_NONE);
|
||||
if ((state = EXEC_TAG()) == 0) {
|
||||
val = eval(self, src, Qnil);
|
||||
val = eval(self, src, Qnil, 0, 0);
|
||||
}
|
||||
POP_TAG();
|
||||
POP_FRAME();
|
||||
|
|
8
io.c
8
io.c
|
@ -1598,8 +1598,8 @@ next_argv()
|
|||
fr = rb_fopen(RSTRING(str)->ptr, "r");
|
||||
#else
|
||||
if (rename(fn, RSTRING(str)->ptr) < 0) {
|
||||
Warning("Can't rename %s to %s: %s, skipping file",
|
||||
fn, RSTRING(str)->ptr, strerror(errno));
|
||||
Warn("Can't rename %s to %s: %s, skipping file",
|
||||
fn, RSTRING(str)->ptr, strerror(errno));
|
||||
fclose(fr);
|
||||
goto retry;
|
||||
}
|
||||
|
@ -1608,8 +1608,8 @@ next_argv()
|
|||
else {
|
||||
#if !defined(MSDOS) && !defined(__BOW__) && !defined(__CYGWIN32__) && !defined(NT) && !defined(__human68k__)
|
||||
if (unlink(fn) < 0) {
|
||||
Warning("Can't remove %s: %s, skipping file",
|
||||
fn, strerror(errno));
|
||||
Warn("Can't remove %s: %s, skipping file",
|
||||
fn, strerror(errno));
|
||||
fclose(fr);
|
||||
goto retry;
|
||||
}
|
||||
|
|
|
@ -839,7 +839,7 @@ marshal_load(argc, argv)
|
|||
major = r_byte(&arg);
|
||||
if (major == MARSHAL_MAJOR) {
|
||||
if (r_byte(&arg) != MARSHAL_MINOR) {
|
||||
Warning("Old marshal file format (can be read)");
|
||||
Warn("Old marshal file format (can be read)");
|
||||
}
|
||||
arg.symbol = st_init_numtable();
|
||||
arg.data = st_init_numtable();
|
||||
|
|
13
numeric.c
13
numeric.c
|
@ -279,7 +279,7 @@ flo_modulo(x, y, modulo)
|
|||
VALUE x, y;
|
||||
int modulo;
|
||||
{
|
||||
double value;
|
||||
double value, result;
|
||||
|
||||
switch (TYPE(y)) {
|
||||
case T_FIXNUM:
|
||||
|
@ -296,22 +296,21 @@ flo_modulo(x, y, modulo)
|
|||
}
|
||||
|
||||
#ifdef HAVE_FMOD
|
||||
value = fmod(RFLOAT(x)->value, value);
|
||||
result = fmod(RFLOAT(x)->value, value);
|
||||
#else
|
||||
{
|
||||
double value1 = RFLOAT(x)->value;
|
||||
double value2;
|
||||
|
||||
modf(value1/value, &value2);
|
||||
value = value1 - value2 * value;
|
||||
result = value1 - value2 * value;
|
||||
}
|
||||
#endif
|
||||
if (modulo &&
|
||||
(RFLOAT(x)->value < 0.0) != (RFLOAT(y)->value < 0.0) &&
|
||||
value != 0.0) {
|
||||
value += RFLOAT(y)->value;
|
||||
(RFLOAT(x)->value < 0.0) != (result < 0.0) && result != 0.0) {
|
||||
result += value;
|
||||
}
|
||||
return float_new(value);
|
||||
return float_new(result);
|
||||
}
|
||||
|
||||
static VALUE
|
||||
|
|
28
parse.y
28
parse.y
|
@ -1577,6 +1577,7 @@ yyerror(msg)
|
|||
}
|
||||
|
||||
static int newline_seen;
|
||||
static int heredoc_end;
|
||||
|
||||
int rb_in_compile = 0;
|
||||
|
||||
|
@ -1633,6 +1634,10 @@ nextc()
|
|||
VALUE v = io_gets(lex_input);
|
||||
|
||||
if (NIL_P(v)) return -1;
|
||||
if (heredoc_end > 0) {
|
||||
sourceline = heredoc_end+1;
|
||||
heredoc_end = 0;
|
||||
}
|
||||
while (RSTRING(v)->ptr[RSTRING(v)->len-1] == '\n' &&
|
||||
RSTRING(v)->ptr[RSTRING(v)->len-2] == '\\') {
|
||||
VALUE v2 = io_gets(lex_input);
|
||||
|
@ -2098,6 +2103,7 @@ here_document(term)
|
|||
VALUE str, line;
|
||||
char *save_beg, *save_end, *save_lexp;
|
||||
NODE *list = 0;
|
||||
int linesave = sourceline;
|
||||
|
||||
newtok();
|
||||
switch (term) {
|
||||
|
@ -2178,6 +2184,8 @@ here_document(term)
|
|||
lex_pbeg = save_beg;
|
||||
lex_pend = save_end;
|
||||
lex_state = EXPR_END;
|
||||
heredoc_end = sourceline;
|
||||
sourceline = linesave;
|
||||
|
||||
if (list) {
|
||||
yylval.node = list;
|
||||
|
@ -3542,7 +3550,7 @@ assign_in_cond(node)
|
|||
switch (nd_type(node)) {
|
||||
case NODE_MASGN:
|
||||
Error("multiple assignment in conditional");
|
||||
return 0;
|
||||
return 1;
|
||||
|
||||
case NODE_LASGN:
|
||||
case NODE_DASGN:
|
||||
|
@ -3550,10 +3558,10 @@ assign_in_cond(node)
|
|||
case NODE_IASGN:
|
||||
case NODE_CASGN:
|
||||
break;
|
||||
case NODE_NEWLINE:
|
||||
|
||||
case NODE_NEWLINE:
|
||||
default:
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (nd_type(node->nd_value)) {
|
||||
|
@ -3567,14 +3575,16 @@ assign_in_cond(node)
|
|||
case NODE_NIL:
|
||||
case NODE_TRUE:
|
||||
case NODE_FALSE:
|
||||
Error("found = in conditional, should be ==");
|
||||
return 0;
|
||||
/* reports always */
|
||||
Warn("found = in conditional, should be ==");
|
||||
return 1;
|
||||
|
||||
default:
|
||||
Warning("assignment in condition");
|
||||
break;
|
||||
}
|
||||
if (assign_in_cond(node->nd_value)) return 1;
|
||||
if (assign_in_cond(node->nd_value) == 0) {
|
||||
Warning("assignment in condition");
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static NODE*
|
||||
|
@ -3583,7 +3593,7 @@ cond0(node)
|
|||
{
|
||||
enum node_type type = nd_type(node);
|
||||
|
||||
if (assign_in_cond(node) == 0) return 0;
|
||||
assign_in_cond(node);
|
||||
switch (type) {
|
||||
case NODE_DREGX:
|
||||
case NODE_DREGX_ONCE:
|
||||
|
|
3
ruby.h
3
ruby.h
|
@ -440,7 +440,8 @@ void rb_notimplement _((void));
|
|||
#endif
|
||||
|
||||
void Error();
|
||||
void Warning();
|
||||
void Warn();
|
||||
void Warning(); /* reports if `-w' specified */
|
||||
|
||||
VALUE rb_each _((VALUE));
|
||||
VALUE rb_yield _((VALUE));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue