Path: utzoo!mnetor!uunet!husc6!rutgers!sri-spam!ames!elroy!devvax!lroot From: lroot@devvax.JPL.NASA.GOV (The Superuser) Newsgroups: comp.sources.bugs Subject: perl 1.0 patch #8 Message-ID: <1174@devvax.JPL.NASA.GOV> Date: 28 Jan 88 19:44:05 GMT Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 1437 Summary: This is an official patch for perl 1.0. Please apply it. System: perl version 1.0 Patch #: 8 Priority: ENHANCEMENT Subject: perl needed an eval operator and a symbolic debugger From: lwall@jpl-devvax.jpl.nasa.gov (Larry Wall) Description: I didn't add an eval operator to the original perl because I hadn't thought of any good uses for it. Recently I thought of some. Along with creating the eval operator, this patch introduces a symbolic debugger for perl scripts, which makes use of eval to interpret some debugging commands. Having eval also lets me emulate awk's FOO=bar command line behavior with a line such as the one a2p now inserts at the beginning of translated scripts. Fix: From rn, say "| patch -p0 -d DIR", where DIR is your perl source ^^^ directory. Outside of rn, say "cd DIR; patch -p0 >>> YOU MUST USE THE -p0 SWITCH ABOVE OR PATCH WON'T WORK RIGHT. <<<< If patch indicates that patchlevel is the wrong version, you may need to apply one or more previous patches, or the patch may already have been applied. See the patchlevel.h file to find out what has or has not been applied. In any event, don't continue with the patch. If you are missing previous patches they can be obtained from me: Larry Wall lwall@jpl-devvax.jpl.nasa.gov If you send a mail message of the following form it will greatly speed processing: Subject: Command @SH mailpatch PATH perl 1.0 LIST ^ note the c where PATH is a return path FROM ME TO YOU in Internet notation, and LIST is the number of one or more patches you need, separated by spaces, commas, and/or hyphens. Saying 35- says everything from 35 to the end. You can also get the patches via anonymous FTP from jpl-devvax.jpl.nasa.gov (128.149.8.43). Index: patchlevel.h Prereq: 7 1c1 < #define PATCHLEVEL 7 --- > #define PATCHLEVEL 8 Index: Makefile.SH Prereq: 1.0.1.3 *** Makefile.SH.old Thu Jan 28 11:08:32 1988 --- Makefile.SH Thu Jan 28 11:08:33 1988 *************** *** 14,22 **** esac echo "Extracting Makefile (with variable substitutions)" cat >Makefile <Makefile <>Makefile <<'!NO!SUBS!' ! public = perl private = ! manpages = perl.man util = --- 50,60 ---- cat >>Makefile <<'!NO!SUBS!' ! public = perl perldb private = ! manpages = perl.man perldb.man util = If you are sitting there wondering why patch didn't find x2p/a2py.c, perhaps it is because you didn't say -p0 to patch. If so, abort patch now and run it again as you did, but add the following switches: -p0 -N Index: x2p/a2py.c Prereq: 1.0 *** x2p/a2py.c.old Thu Jan 28 11:18:17 1988 --- x2p/a2py.c Thu Jan 28 11:18:18 1988 *************** *** 1,6 **** ! /* $Header: a2py.c,v 1.0 87/12/18 17:50:33 root Exp $ * * $Log: a2py.c,v $ * Revision 1.0 87/12/18 17:50:33 root * Initial revision * --- 1,9 ---- ! /* $Header: a2py.c,v 1.0.1.1 88/01/28 11:07:08 root Exp $ * * $Log: a2py.c,v $ + * Revision 1.0.1.1 88/01/28 11:07:08 root + * patch8: added support for FOO=bar switches using eval. + * * Revision 1.0 87/12/18 17:50:33 root * Initial revision * *************** *** 114,119 **** --- 117,126 ---- tmpstr = walk(0,0,root,&i); str = str_make("#!/bin/perl\n\n"); + str_cat(str, + "eval '$'.$1.'$2;' while $ARGV[0] =~ /^([A-Za-z_]+=)(.*)/ && shift;\n"); + str_cat(str, + " # process any FOO=bar switches\n\n"); if (do_opens && opens) { str_scat(str,opens); str_free(opens); Index: arg.c Prereq: 1.0.1.3 *** arg.c.old Thu Jan 28 11:08:43 1988 --- arg.c Thu Jan 28 11:08:46 1988 *************** *** 1,8 **** ! /* $Header: arg.c,v 1.0.1.3 88/01/26 12:30:33 root Exp $ * * $Log: arg.c,v $ ! * Revision 1.0.1.3 88/01/26 12:30:33 root ! * patch 6: sprintf didn't finish processing format string when out of args. * * Revision 1.0.1.2 88/01/24 03:52:34 root * patch 2: added STATBLKS dependencies. --- 1,8 ---- ! /* $Header: arg.c,v 1.0.1.4 88/01/28 10:22:06 root Exp $ * * $Log: arg.c,v $ ! * Revision 1.0.1.4 88/01/28 10:22:06 root ! * patch8: added eval operator. * * Revision 1.0.1.2 88/01/24 03:52:34 root * patch 2: added STATBLKS dependencies. *************** *** 1190,1195 **** --- 1190,1196 ---- opargs[O_UNSHIFT] = A(1,0,0); opargs[O_LINK] = A(1,1,0); opargs[O_REPEAT] = A(1,1,0); + opargs[O_EVAL] = A(1,0,0); } #ifdef VOIDSIG *************** *** 2091,2096 **** --- 2092,2102 ---- astore(ary,0,str); } value = (double)(ary->ary_fill + 1); + break; + case O_EVAL: + str_sset(str, + do_eval(arg[1].arg_type != A_NULL ? sarg[1] : defstab->stab_val) ); + STABSET(str); break; } #ifdef DEBUGGING Index: arg.h Prereq: 1.0 *** arg.h.old Thu Jan 28 11:08:59 1988 --- arg.h Thu Jan 28 11:09:00 1988 *************** *** 1,6 **** ! /* $Header: arg.h,v 1.0 87/12/18 13:04:39 root Exp $ * * $Log: arg.h,v $ * Revision 1.0 87/12/18 13:04:39 root * Initial revision * --- 1,9 ---- ! /* $Header: arg.h,v 1.0.1.1 88/01/28 10:22:40 root Exp $ * * $Log: arg.h,v $ + * Revision 1.0.1.1 88/01/28 10:22:40 root + * patch8: added eval operator. + * * Revision 1.0 87/12/18 13:04:39 root * Initial revision * *************** *** 111,117 **** #define O_UNSHIFT 102 #define O_LINK 103 #define O_REPEAT 104 ! #define MAXO 105 #ifndef DOINIT extern char *opname[]; --- 114,121 ---- #define O_UNSHIFT 102 #define O_LINK 103 #define O_REPEAT 104 ! #define O_EVAL 105 ! #define MAXO 106 #ifndef DOINIT extern char *opname[]; *************** *** 222,228 **** "UNSHIFT", "LINK", "REPEAT", ! "105" }; #endif --- 226,233 ---- "UNSHIFT", "LINK", "REPEAT", ! "EVAL", ! "106" }; #endif Index: t/base.lex Prereq: 1.0 *** t/base.lex.old Thu Jan 28 11:17:55 1988 --- t/base.lex Thu Jan 28 11:17:56 1988 *************** *** 1,8 **** #!./perl ! # $Header: base.lex,v 1.0 87/12/18 13:11:51 root Exp $ ! print "1..4\n"; $ # this is the register = 'x'; --- 1,8 ---- #!./perl ! # $Header: base.lex,v 1.0.1.1 88/01/28 10:37:00 root Exp $ ! print "1..6\n"; $ # this is the register = 'x'; *************** *** 21,23 **** --- 21,32 ---- $x = '\\'; # '; if (length($x) == 1) {print "ok 4\n";} else {print "not ok 4\n";} + + eval 'while (0) { + print "foo\n"; + } + /^/ && (print "ok 5\n"); + '; + + eval '$foo{1} / 1;'; + if (!$@) {print "ok 6\n";} else {print "not ok 6\n";} Index: cmd.h Prereq: 1.0 *** cmd.h.old Thu Jan 28 11:09:05 1988 --- cmd.h Thu Jan 28 11:09:06 1988 *************** *** 1,6 **** ! /* $Header: cmd.h,v 1.0 87/12/18 13:04:59 root Exp $ * * $Log: cmd.h,v $ * Revision 1.0 87/12/18 13:04:59 root * Initial revision * --- 1,9 ---- ! /* $Header: cmd.h,v 1.0.1.1 88/01/28 10:23:07 root Exp $ * * $Log: cmd.h,v $ + * Revision 1.0.1.1 88/01/28 10:23:07 root + * patch8: added eval_root for eval operator. + * * Revision 1.0 87/12/18 13:04:59 root * Initial revision * *************** *** 106,111 **** --- 109,115 ---- #define Nullcmd Null(CMD*) EXT CMD *main_root INIT(Nullcmd); + EXT CMD *eval_root INIT(Nullcmd); EXT struct compcmd { CMD *comp_true; Index: t/op.eval *** t/op.eval.old Thu Jan 28 11:18:04 1988 --- t/op.eval Thu Jan 28 11:18:04 1988 *************** *** 0 **** --- 1,20 ---- + #!./perl + + print "1..6\n"; + + eval 'print "ok 1\n";'; + + if ($@ eq '') {print "ok 2\n";} else {print "not ok 2\n";} + + eval "\$foo\n = # this is a comment\n'ok 3';"; + print $foo,"\n"; + + eval "\$foo\n = # this is a comment\n'ok 4\n';"; + print $foo; + + eval ' + $foo ='; # this tests for a call through yyerror() + if ($@ =~ /line 2/) {print "ok 5\n";} else {print "not ok 5\n";} + + eval '$foo = /'; # this tests for a call through fatal() + if ($@ =~ /Search/) {print "ok 6\n";} else {print "not ok 6\n";} Index: perl.h Prereq: 1.0.1.2 *** perl.h.old Thu Jan 28 11:09:13 1988 --- perl.h Thu Jan 28 11:09:14 1988 *************** *** 1,6 **** ! /* $Header: perl.h,v 1.0.1.2 88/01/24 03:53:47 root Exp $ * * $Log: perl.h,v $ * Revision 1.0.1.2 88/01/24 03:53:47 root * patch 2: hid str_peek() in #ifdef DEBUGGING. * --- 1,9 ---- ! /* $Header: perl.h,v 1.0.1.3 88/01/28 10:24:17 root Exp $ * * $Log: perl.h,v $ + * Revision 1.0.1.3 88/01/28 10:24:17 root + * patch8: added eval operator. + * * Revision 1.0.1.2 88/01/24 03:53:47 root * patch 2: hid str_peek() in #ifdef DEBUGGING. * *************** *** 103,109 **** STR *arg_to_str(); STR *str_new(); STR *stab_str(); ! STR *eval(); FCMD *load_format(); --- 106,113 ---- STR *arg_to_str(); STR *str_new(); STR *stab_str(); ! STR *eval(); /* this evaluates expressions */ ! STR *do_eval(); /* this evaluates eval operator */ FCMD *load_format(); *************** *** 164,169 **** --- 168,174 ---- EXT char tokenbuf[256]; EXT int expectterm INIT(TRUE); EXT int lex_newlines INIT(FALSE); + EXT int in_eval INIT(FALSE); FILE *popen(); /* char *str_get(); */ *************** *** 196,201 **** --- 201,207 ---- EXT int loop_ptr INIT(-1); EXT jmp_buf top_env; + EXT jmp_buf eval_env; EXT char *goto_targ INIT(Nullch); /* cmd_exec gets strange when set */ Index: perl.y Prereq: 1.0 *** perl.y.old Thu Jan 28 11:09:22 1988 --- perl.y Thu Jan 28 11:09:24 1988 *************** *** 1,6 **** ! /* $Header: perl.y,v 1.0 87/12/18 15:48:59 root Exp $ * * $Log: perl.y,v $ * Revision 1.0 87/12/18 15:48:59 root * Initial revision * --- 1,9 ---- ! /* $Header: perl.y,v 1.0.1.1 88/01/28 10:25:31 root Exp $ * * $Log: perl.y,v $ + * Revision 1.0.1.1 88/01/28 10:25:31 root + * patch8: added eval operator. + * * Revision 1.0 87/12/18 15:48:59 root * Initial revision * *************** *** 97,103 **** %% /* RULES */ prog : lineseq ! { main_root = block_head($1); } ; compblock: block CONTINUE block --- 100,109 ---- %% /* RULES */ prog : lineseq ! { if (in_eval) ! eval_root = block_head($1); ! else ! main_root = block_head($1); } ; compblock: block CONTINUE block Index: perldb *** perldb.old Thu Jan 28 11:17:03 1988 --- perldb Thu Jan 28 11:17:04 1988 *************** *** 0 **** --- 1,296 ---- + #!/bin/perl + + # $Header: perldb,v 1.0.1.1 88/01/28 10:27:16 root Exp $ + # + # $Log: perldb,v $ + # Revision 1.0.1.1 88/01/28 10:27:16 root + # patch8: created this file. + # + # + + $tmp = "/tmp/pdb$$"; # default temporary file, -o overrides. + + # parse any switches + + while ($ARGV[0] =~ /^-/) { + $_ = shift; + /^-o$/ && ($tmp = shift,next); + die "Unrecognized switch: $_"; + } + + $filename = shift; + die "Usage: perldb [-o output] scriptname arguments" unless $filename; + + open(script,$filename) || die "Can't find $filename"; + + open(tmp, ">$tmp") || die "Can't make temp script"; + + $perl = '/bin/perl'; + $init = 1; + $state = 'statement'; + + # now translate script to contain DB calls at the appropriate places + + while (