3 * Copyright (c) 1987-1994, Larry Wall
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Artistic License, as specified in the README file.
19 # define BYTEORDER 0x1234
22 /* Overall memory policy? */
28 * The following contortions are brought to you on behalf of all the
29 * standards, semi-standards, de facto standards, not-so-de-facto standards
30 * of the world, as well as all the other botches anyone ever thought of.
31 * The basic theory is that if we work hard enough here, the rest of the
32 * code can be a lot prettier. Well, so much for theory. Sorry, Henry...
35 /* define this once if either system, instead of cluttering up the src */
36 #if defined(MSDOS) || defined(atarist)
40 #if defined(__STDC__) || defined(vax11c) || defined(_AIX) || defined(__stdc__) || defined(__cplusplus)
44 #if defined(HASVOLATILE) || defined(STANDARD_C)
46 # define VOL // to temporarily suppress warnings
54 #define TAINT_IF(c) (tainted |= (c))
55 #define TAINT_NOT (tainted = 0)
56 #define TAINT_PROPER(s) if (tainting) taint_proper(no_security, s)
57 #define TAINT_ENV() if (tainting) taint_env()
61 # define BSD_GETPGRP(pid) getpgrp((pid))
64 # define BSD_SETPGRP(pid, pgrp) setpgrp((pid), (pgrp))
68 # define BSD_GETPGRP(pid) getpgrp2((pid))
74 # define BSD_SETPGRP(pid, pgrp) setpgrp2((pid), (pgrp))
83 #include <appkit/NXCType.h>
92 #ifdef METHOD /* Defined by OSF/1 v3.0 by ctype.h */
99 # ifdef PARAM_NEEDS_TYPES
100 # include <sys/types.h>
102 # include <sys/param.h>
106 /* Use all the "standard" definitions? */
107 #if defined(STANDARD_C) && defined(I_STDLIB)
109 #endif /* STANDARD_C */
111 /* Maybe this comes after <stdlib.h> so we don't try to change
112 the standard library prototypes?. We'll use our own in
113 proto.h instead. I guess. The patch had no explanation.
117 # define malloc Mymalloc
118 # define realloc Myremalloc
121 # define safemalloc malloc
122 # define saferealloc realloc
123 # define safefree free
126 #define MEM_SIZE Size_t
128 #if defined(I_STRING) || defined(__cplusplus)
131 # include <strings.h>
134 #if !defined(HAS_STRCHR) && defined(HAS_INDEX) && !defined(strchr)
136 #define strrchr rindex
139 #if defined(mips) && defined(ultrix) && !defined(__STDC__)
148 # if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
150 extern char * memcpy _((char*, char*, int));
156 # define memcpy(d,s,l) bcopy(s,d,l)
158 # define memcpy(d,s,l) my_bcopy(s,d,l)
161 #endif /* HAS_MEMCPY */
164 # if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
166 extern char *memset _((char*, int, int));
169 # define memzero(d,l) memset(d,0,l)
173 # define memzero(d,l) bzero(d,l)
175 # define memzero(d,l) my_bzero(d,l)
178 #endif /* HAS_MEMSET */
181 # if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
183 extern int memcmp _((char*, char*, int));
188 # define memcmp my_memcmp
190 #endif /* HAS_MEMCMP */
192 /* XXX we prefer bcmp slightly for comparisons that don't care about ordering */
195 # define bcmp(s1,s2,l) memcmp(s1,s2,l)
197 #endif /* HAS_BCMP */
199 #if !defined(HAS_MEMMOVE) && !defined(memmove)
200 # if defined(HAS_BCOPY) && defined(HAS_SAFE_BCOPY)
201 # define memmove(d,s,l) bcopy(s,d,l)
203 # if defined(HAS_MEMCPY) && defined(HAS_SAFE_MEMCPY)
204 # define memmove(d,s,l) memcpy(d,s,l)
206 # define memmove(d,s,l) my_bcopy(s,d,l)
211 #ifndef _TYPES_ /* If types.h defines this it's easy. */
212 # ifndef major /* Does everyone's types.h define this? */
213 # include <sys/types.h>
218 # include <netinet/in.h>
222 #include <sys/stat.h>
225 /* The stat macros for Amdahl UTS, Unisoft System V/88 (and derivatives
226 like UTekV) are broken, sometimes giving false positives. Undefine
227 them here and let the code below set them to proper values.
229 The ghs macro stands for GreenHills Software C-1.8.5 which
230 is the C compiler for sysV88 and the various derivatives.
231 This header file bug is corrected in gcc-2.5.8 and later versions.
232 --Kaveh Ghazi (ghazi@noc.rutgers.edu) 10/3/94. */
234 #if defined(uts) || (defined(m88k) && defined(ghs))
248 # ifdef I_SYS_TIME_KERNEL
251 # include <sys/time.h>
252 # ifdef I_SYS_TIME_KERNEL
258 # if defined(HAS_TIMES) && defined(I_SYS_TIMES)
259 # include <sys/times.h>
263 #if defined(HAS_STRERROR) && (!defined(HAS_MKDIR) || !defined(HAS_RMDIR))
269 # define mkfifo(path, mode) (mknod((path), (mode) | S_IFIFO, 0))
271 #endif /* !HAS_MKFIFO */
276 # include <net/errno.h>
280 # define FIXSTATUS(sts) (U_L((sts) & 0xffff))
281 # define SHIFTSTATUS(sts) ((sts) >> 8)
282 # define SETERRNO(errcode,vmserrcode) errno = (errcode)
284 # define FIXSTATUS(sts) (U_L(sts))
285 # define SHIFTSTATUS(sts) (sts)
286 # define SETERRNO(errcode,vmserrcode) {set_errno(errcode); set_vaxc_errno(vmserrcode);}
291 extern int errno; /* ANSI allows errno to be an lvalue expr */
297 char *strerror _((int,...));
299 char *strerror _((int));
302 # define Strerror strerror
305 # ifdef HAS_SYS_ERRLIST
307 extern char *sys_errlist[];
309 # define Strerror(e) \
310 ((e) < 0 || (e) >= sys_nerr ? "(unknown)" : sys_errlist[e])
317 # include <sys/ioctl.h>
321 #if defined(mc300) || defined(mc500) || defined(mc700) || defined(mc6000)
322 # ifdef HAS_SOCKETPAIR
323 # undef HAS_SOCKETPAIR
338 /* Configure already sets Direntry_t */
339 #if defined(I_DIRENT)
341 # if defined(NeXT) && defined(I_SYS_DIR) /* NeXT needs dirent + sys/dir.h */
342 # include <sys/dir.h>
346 # include <sys/ndir.h>
350 # include <ndir.h> /* may be wrong in the future */
352 # include <sys/dir.h>
359 /* work around botch in SunOS 4.0.1 and 4.0.2 */
361 # define fputs(sv,fp) fprintf(fp,"%s",sv)
366 * The following gobbledygook brought to you on behalf of __STDC__.
367 * (I could just use #ifndef __STDC__, but this is more bulletproof
368 * in the face of half-implementations.)
373 # define S_IFMT _S_IFMT
375 # define S_IFMT 0170000
380 # define S_ISDIR(m) ((m & S_IFMT) == S_IFDIR)
384 # define S_ISCHR(m) ((m & S_IFMT) == S_IFCHR)
389 # define S_ISBLK(m) ((m & S_IFMT) == S_IFBLK)
391 # define S_ISBLK(m) (0)
396 # define S_ISREG(m) ((m & S_IFMT) == S_IFREG)
401 # define S_ISFIFO(m) ((m & S_IFMT) == S_IFIFO)
403 # define S_ISFIFO(m) (0)
409 # define S_ISLNK(m) _S_ISLNK(m)
412 # define S_ISLNK(m) ((m & S_IFMT) == _S_IFLNK)
415 # define S_ISLNK(m) ((m & S_IFMT) == S_IFLNK)
417 # define S_ISLNK(m) (0)
425 # define S_ISSOCK(m) _S_ISSOCK(m)
428 # define S_ISSOCK(m) ((m & S_IFMT) == _S_IFSOCK)
431 # define S_ISSOCK(m) ((m & S_IFMT) == S_IFSOCK)
433 # define S_ISSOCK(m) (0)
441 # define S_IRUSR S_IREAD
442 # define S_IWUSR S_IWRITE
443 # define S_IXUSR S_IEXEC
445 # define S_IRUSR 0400
446 # define S_IWUSR 0200
447 # define S_IXUSR 0100
449 # define S_IRGRP (S_IRUSR>>3)
450 # define S_IWGRP (S_IWUSR>>3)
451 # define S_IXGRP (S_IXUSR>>3)
452 # define S_IROTH (S_IRUSR>>6)
453 # define S_IWOTH (S_IWUSR>>6)
454 # define S_IXOTH (S_IXUSR>>6)
458 # define S_ISUID 04000
462 # define S_ISGID 02000
469 #if defined(cray) || defined(gould) || defined(i860) || defined(pyr)
470 # define SLOPPYDIVIDE
473 #if defined(cray) || defined(convex) || defined (uts) || BYTEORDER > 0xffff
485 # if defined(convex) || defined (uts)
486 # define Quad_t long long
492 typedef unsigned Quad_t UV;
495 typedef unsigned long UV;
498 typedef MEM_SIZE STRLEN;
500 typedef struct op OP;
501 typedef struct cop COP;
502 typedef struct unop UNOP;
503 typedef struct binop BINOP;
504 typedef struct listop LISTOP;
505 typedef struct logop LOGOP;
506 typedef struct condop CONDOP;
507 typedef struct pmop PMOP;
508 typedef struct svop SVOP;
509 typedef struct gvop GVOP;
510 typedef struct pvop PVOP;
511 typedef struct loop LOOP;
513 typedef struct Outrec Outrec;
514 typedef struct interpreter PerlInterpreter;
515 typedef struct ff FF;
516 typedef struct sv SV;
517 typedef struct av AV;
518 typedef struct hv HV;
519 typedef struct cv CV;
520 typedef struct regexp REGEXP;
521 typedef struct gp GP;
522 typedef struct sv GV;
523 typedef struct io IO;
524 typedef struct context CONTEXT;
525 typedef struct block BLOCK;
527 typedef struct magic MAGIC;
528 typedef struct xrv XRV;
529 typedef struct xpv XPV;
530 typedef struct xpviv XPVIV;
531 typedef struct xpvnv XPVNV;
532 typedef struct xpvmg XPVMG;
533 typedef struct xpvlv XPVLV;
534 typedef struct xpvav XPVAV;
535 typedef struct xpvhv XPVHV;
536 typedef struct xpvgv XPVGV;
537 typedef struct xpvcv XPVCV;
538 typedef struct xpvbm XPVBM;
539 typedef struct xpvfm XPVFM;
540 typedef struct xpvio XPVIO;
541 typedef struct mgvtbl MGVTBL;
542 typedef union any ANY;
546 typedef I32 (*filter_t) _((int, SV *, int));
547 #define FILTER_READ(idx, sv, len) filter_read(idx, sv, len)
548 #define FILTER_DATA(idx) (AvARRAY(rsfp_filters)[idx])
549 #define FILTER_ISREADER(idx) (idx >= AvFILL(rsfp_filters))
561 # include "unixish.h"
566 #define pause() sleep((32767<<16)+32767)
571 /* on BSDish systes we're safe */
572 # define IOCPARM_LEN(x) (((x) >> 16) & IOCPARM_MASK)
574 /* otherwise guess at what's safe */
575 # define IOCPARM_LEN(x) 256
584 void (*any_dptr) _((void*));
601 /* work around some libPW problems */
606 #if defined(iAPX286) || defined(M_I286) || defined(I80286)
610 #if defined(htonl) && !defined(HAS_HTONL)
613 #if defined(htons) && !defined(HAS_HTONS)
616 #if defined(ntohl) && !defined(HAS_NTOHL)
619 #if defined(ntohs) && !defined(HAS_NTOHS)
623 #if (BYTEORDER & 0xffff) != 0x4321
629 #define htons my_swap
630 #define htonl my_htonl
631 #define ntohs my_swap
632 #define ntohl my_ntohl
635 #if (BYTEORDER & 0xffff) == 0x4321
644 * Little-endian byte order functions - 'v' for 'VAX', or 'reVerse'.
647 #if BYTEORDER != 0x1234
652 # if BYTEORDER == 0x4321
653 # define vtohl(x) ((((x)&0xFF)<<24) \
655 +(((x)&0x0000FF00)<<8) \
656 +(((x)&0x00FF0000)>>8) )
657 # define vtohs(x) ((((x)&0xFF)<<8) + (((x)>>8)&0xFF))
658 # define htovl(x) vtohl(x)
659 # define htovs(x) vtohs(x)
661 /* otherwise default to functions in util.c */
665 #define U_S(what) ((U16)(what))
666 #define U_I(what) ((unsigned int)(what))
667 #define U_L(what) ((U32)(what))
669 U32 cast_ulong _((double));
670 #define U_S(what) ((U16)cast_ulong((double)(what)))
671 #define U_I(what) ((unsigned int)cast_ulong((double)(what)))
672 #define U_L(what) (cast_ulong((double)(what)))
676 #define I_32(what) ((I32)(what))
677 #define I_V(what) ((IV)(what))
678 #define U_V(what) ((UV)(what))
680 I32 cast_i32 _((double));
681 #define I_32(what) (cast_i32((double)(what)))
682 IV cast_iv _((double));
683 #define I_V(what) (cast_iv((double)(what)))
684 UV cast_uv _((double));
685 #define U_V(what) (cast_uv((double)(what)))
699 # define TMPPATH "/tmp/perl-eXXXXXX"
703 Uid_t getuid _((void));
704 Uid_t geteuid _((void));
705 Gid_t getgid _((void));
706 Gid_t getegid _((void));
712 #define DEBUG(a) if (debug) a
713 #define DEBUG_p(a) if (debug & 1) a
714 #define DEBUG_s(a) if (debug & 2) a
715 #define DEBUG_l(a) if (debug & 4) a
716 #define DEBUG_t(a) if (debug & 8) a
717 #define DEBUG_o(a) if (debug & 16) a
718 #define DEBUG_c(a) if (debug & 32) a
719 #define DEBUG_P(a) if (debug & 64) a
720 #define DEBUG_m(a) if (debug & 128) a
721 #define DEBUG_f(a) if (debug & 256) a
722 #define DEBUG_r(a) if (debug & 512) a
723 #define DEBUG_x(a) if (debug & 1024) a
724 #define DEBUG_u(a) if (debug & 2048) a
725 #define DEBUG_L(a) if (debug & 4096) a
726 #define DEBUG_H(a) if (debug & 8192) a
727 #define DEBUG_X(a) if (debug & 16384) a
728 #define DEBUG_D(a) if (debug & 32768) a
749 #define YYMAXDEPTH 300
751 #define assert(what) DEB( { \
753 croak("Assertion failed: file \"%s\", line %d", \
754 __FILE__, __LINE__); \
759 I32 (*uf_val)_((IV, SV*));
760 I32 (*uf_set)_((IV, SV*));
764 /* Fix these up for __STDC__ */
766 char *mktemp _((char*));
767 double atof _((const char*));
771 /* All of these are in stdlib.h or time.h for ANSI C */
773 struct tm *gmtime(), *localtime();
774 char *strchr(), *strrchr();
775 char *strcpy(), *strcat();
776 #endif /* ! STANDARD_C */
785 double exp _((double));
786 double log _((double));
787 double sqrt _((double));
788 double modf _((double,double*));
789 double sin _((double));
790 double cos _((double));
791 double atan2 _((double,double));
792 double pow _((double,double));
799 char *crypt _((const char*, const char*));
800 char *getenv _((const char*));
801 Off_t lseek _((int,Off_t,int));
802 char *getlogin _((void));
805 #ifdef UNLINK_ALL_VERSIONS /* Currently only makes sense for VMS */
807 I32 unlnk _((char*));
809 #define UNLINK unlink
813 # ifdef HAS_SETRESUID
814 # define setreuid(r,e) setresuid(r,e,(Uid_t)-1)
815 # define HAS_SETREUID
819 # ifdef HAS_SETRESGID
820 # define setregid(r,e) setresgid(r,e,(Gid_t)-1)
821 # define HAS_SETREGID
834 # define DEBUGGING_MSTATS
836 # define PAD_SV(po) pad_sv(po)
838 # define PAD_SV(po) curpad[po]
846 EXT PerlInterpreter * curinterp; /* currently running interpreter */
847 #ifndef VMS /* VMS doesn't use environ array */
848 extern char ** environ; /* environment variables supplied via exec */
850 EXT int uid; /* current real user id */
851 EXT int euid; /* current effective user id */
852 EXT int gid; /* current real group id */
853 EXT int egid; /* current effective group id */
854 EXT bool nomemok; /* let malloc context handle nomem */
855 EXT U32 an; /* malloc sequence number */
856 EXT U32 cop_seqmax; /* statement sequence number */
857 EXT U16 op_seqmax; /* op sequence number */
858 EXT U32 evalseq; /* eval sequence number */
859 EXT U32 sub_generation; /* inc to force methods to be looked up again */
860 EXT char ** origenviron;
862 EXT U32 * profiledata;
863 EXT int maxo INIT(MAXO);/* Number of ops */
865 EXT XPV* xiv_arenaroot; /* list of allocated xiv areas */
866 EXT IV ** xiv_root; /* free xiv list--shared by interpreters */
867 EXT double * xnv_root; /* free xnv list--shared by interpreters */
868 EXT XRV * xrv_root; /* free xrv list--shared by interpreters */
869 EXT XPV * xpv_root; /* free xpv list--shared by interpreters */
870 EXT HE * he_root; /* free he list--shared by interpreters */
871 EXT char * nice_chunk; /* a nice chunk of memory to reuse */
872 EXT U32 nice_chunk_size;/* how nice the chunk of memory is */
874 /* Stack for currently executing thread--context switch must handle this. */
875 EXT SV ** stack_base; /* stack->array_ary */
876 EXT SV ** stack_sp; /* stack pointer now */
877 EXT SV ** stack_max; /* stack->array_ary + stack->array_max */
879 /* likewise for these */
881 EXT OP * op; /* current op--oughta be in a global register */
883 EXT I32 * scopestack; /* blocks we've entered */
884 EXT I32 scopestack_ix;
885 EXT I32 scopestack_max;
887 EXT ANY* savestack; /* to save non-local values on */
888 EXT I32 savestack_ix;
889 EXT I32 savestack_max;
891 EXT OP ** retstack; /* returns we've pushed */
893 EXT I32 retstack_max;
895 EXT I32 * markstack; /* stackmarks we're remembering */
896 EXT I32 * markstack_ptr; /* stackmarks we're remembering */
897 EXT I32 * markstack_max; /* stackmarks we're remembering */
904 EXT char buf[2048]; /* should be longer than PATH_MAX */
905 EXT char tokenbuf[256];
906 EXT struct stat statbuf;
908 EXT struct tms timesbuf;
910 EXT STRLEN na; /* for use in SvPV when length is Not Applicable */
912 /* for tmp use in stupid debuggers */
917 /* handy constants */
918 EXT char * Yes INIT("1");
919 EXT char * No INIT("");
920 EXT char * hexdigit INIT("0123456789abcdef0123456789ABCDEFx");
921 EXT char * patleave INIT("\\.^$@dDwWsSbB+*?|()-nrtfeaxc0123456789[{]}");
922 EXT char * vert INIT("|");
924 EXT char warn_uninit[]
925 INIT("Use of uninitialized value");
926 EXT char warn_nosemi[]
927 INIT("Semicolon seems to be missing");
928 EXT char warn_reserved[]
929 INIT("Unquoted string \"%s\" may clash with future reserved word");
931 INIT("Unsuccessful %s on filename containing newline");
932 EXT char no_wrongref[]
933 INIT("Can't use %s ref as %s ref");
935 INIT("Can't use string (\"%.32s\") as %s ref while \"strict refs\" in use");
937 INIT("Can't use an undefined value as %s reference");
939 INIT("Modification of non-creatable array value attempted, subscript %d");
941 INIT("Modification of non-creatable hash value attempted, subscript \"%s\"");
943 INIT("Modification of a read-only value attempted");
945 INIT("Out of memory!\n");
946 EXT char no_security[]
947 INIT("Insecure dependency in %s%s");
948 EXT char no_sock_func[]
949 INIT("Unsupported socket function \"%s\" called");
950 EXT char no_dir_func[]
951 INIT("Unsupported directory function \"%s\" called");
953 INIT("The %s function is unimplemented");
955 INIT("\"my\" variable %s can't be in a package");
961 EXT char * cshname INIT(CSH);
966 EXT char *sig_name[] = { SIG_NAME };
967 EXT int sig_num[] = { SIG_NUM };
969 EXT char *sig_name[];
974 EXT unsigned char fold[] = { /* fast case folding table */
975 0, 1, 2, 3, 4, 5, 6, 7,
976 8, 9, 10, 11, 12, 13, 14, 15,
977 16, 17, 18, 19, 20, 21, 22, 23,
978 24, 25, 26, 27, 28, 29, 30, 31,
979 32, 33, 34, 35, 36, 37, 38, 39,
980 40, 41, 42, 43, 44, 45, 46, 47,
981 48, 49, 50, 51, 52, 53, 54, 55,
982 56, 57, 58, 59, 60, 61, 62, 63,
983 64, 'a', 'b', 'c', 'd', 'e', 'f', 'g',
984 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
985 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
986 'x', 'y', 'z', 91, 92, 93, 94, 95,
987 96, 'A', 'B', 'C', 'D', 'E', 'F', 'G',
988 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
989 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
990 'X', 'Y', 'Z', 123, 124, 125, 126, 127,
991 128, 129, 130, 131, 132, 133, 134, 135,
992 136, 137, 138, 139, 140, 141, 142, 143,
993 144, 145, 146, 147, 148, 149, 150, 151,
994 152, 153, 154, 155, 156, 157, 158, 159,
995 160, 161, 162, 163, 164, 165, 166, 167,
996 168, 169, 170, 171, 172, 173, 174, 175,
997 176, 177, 178, 179, 180, 181, 182, 183,
998 184, 185, 186, 187, 188, 189, 190, 191,
999 192, 193, 194, 195, 196, 197, 198, 199,
1000 200, 201, 202, 203, 204, 205, 206, 207,
1001 208, 209, 210, 211, 212, 213, 214, 215,
1002 216, 217, 218, 219, 220, 221, 222, 223,
1003 224, 225, 226, 227, 228, 229, 230, 231,
1004 232, 233, 234, 235, 236, 237, 238, 239,
1005 240, 241, 242, 243, 244, 245, 246, 247,
1006 248, 249, 250, 251, 252, 253, 254, 255
1009 EXT unsigned char fold[];
1013 EXT unsigned char freq[] = { /* letter frequencies for mixed English/C */
1014 1, 2, 84, 151, 154, 155, 156, 157,
1015 165, 246, 250, 3, 158, 7, 18, 29,
1016 40, 51, 62, 73, 85, 96, 107, 118,
1017 129, 140, 147, 148, 149, 150, 152, 153,
1018 255, 182, 224, 205, 174, 176, 180, 217,
1019 233, 232, 236, 187, 235, 228, 234, 226,
1020 222, 219, 211, 195, 188, 193, 185, 184,
1021 191, 183, 201, 229, 181, 220, 194, 162,
1022 163, 208, 186, 202, 200, 218, 198, 179,
1023 178, 214, 166, 170, 207, 199, 209, 206,
1024 204, 160, 212, 216, 215, 192, 175, 173,
1025 243, 172, 161, 190, 203, 189, 164, 230,
1026 167, 248, 227, 244, 242, 255, 241, 231,
1027 240, 253, 169, 210, 245, 237, 249, 247,
1028 239, 168, 252, 251, 254, 238, 223, 221,
1029 213, 225, 177, 197, 171, 196, 159, 4,
1030 5, 6, 8, 9, 10, 11, 12, 13,
1031 14, 15, 16, 17, 19, 20, 21, 22,
1032 23, 24, 25, 26, 27, 28, 30, 31,
1033 32, 33, 34, 35, 36, 37, 38, 39,
1034 41, 42, 43, 44, 45, 46, 47, 48,
1035 49, 50, 52, 53, 54, 55, 56, 57,
1036 58, 59, 60, 61, 63, 64, 65, 66,
1037 67, 68, 69, 70, 71, 72, 74, 75,
1038 76, 77, 78, 79, 80, 81, 82, 83,
1039 86, 87, 88, 89, 90, 91, 92, 93,
1040 94, 95, 97, 98, 99, 100, 101, 102,
1041 103, 104, 105, 106, 108, 109, 110, 111,
1042 112, 113, 114, 115, 116, 117, 119, 120,
1043 121, 122, 123, 124, 125, 126, 127, 128,
1044 130, 131, 132, 133, 134, 135, 136, 137,
1045 138, 139, 141, 142, 143, 144, 145, 146
1048 EXT unsigned char freq[];
1053 EXT char* block_type[] = {
1062 EXT char* block_type[];
1066 /*****************************************************************************/
1067 /* This lexer/parser stuff is currently global since yacc is hard to reenter */
1068 /*****************************************************************************/
1069 /* XXX This needs to be revisited, since BEGIN makes yacc re-enter... */
1082 EXT U32 lex_state; /* next token is determined */
1083 EXT U32 lex_defer; /* state after determined token */
1084 EXT expectation lex_expect; /* expect after determined token */
1085 EXT I32 lex_brackets; /* bracket count */
1086 EXT I32 lex_formbrack; /* bracket count at outer format level */
1087 EXT I32 lex_fakebrack; /* outer bracket is mere delimiter */
1088 EXT I32 lex_casemods; /* casemod count */
1089 EXT I32 lex_dojoin; /* doing an array interpolation */
1090 EXT I32 lex_starts; /* how many interps done on level */
1091 EXT SV * lex_stuff; /* runtime pattern from m// or s/// */
1092 EXT SV * lex_repl; /* runtime replacement from s/// */
1093 EXT OP * lex_op; /* extra info to pass back on op */
1094 EXT OP * lex_inpat; /* in pattern $) and $| are special */
1095 EXT I32 lex_inwhat; /* what kind of quoting are we in */
1096 EXT char * lex_brackstack; /* what kind of brackets to pop */
1097 EXT char * lex_casestack; /* what kind of case mods in effect */
1099 /* What we know when we're in LEX_KNOWNEXT state. */
1100 EXT YYSTYPE nextval[5]; /* value of next token, if any */
1101 EXT I32 nexttype[5]; /* type of next token */
1104 EXT FILE * VOL rsfp INIT(Nullfp);
1107 EXT char * oldbufptr;
1108 EXT char * oldoldbufptr;
1110 EXT expectation expect INIT(XSTATE); /* how to interpret ambiguous tokens */
1111 EXT AV * rsfp_filters;
1113 EXT I32 multi_start; /* 1st line of multi-line string */
1114 EXT I32 multi_end; /* last line of multi-line string */
1115 EXT I32 multi_open; /* delimiter of said string */
1116 EXT I32 multi_close; /* delimiter of said string */
1119 EXT I32 error_count; /* how many errors so far, max 10 */
1120 EXT I32 subline; /* line this subroutine began on */
1121 EXT SV * subname; /* name of current subroutine */
1123 EXT CV * compcv; /* currently compiling subroutine */
1124 EXT AV * comppad; /* storage for lexically scoped temporaries */
1125 EXT AV * comppad_name; /* variable names for "my" variables */
1126 EXT I32 comppad_name_fill;/* last "introduced" variable offset */
1127 EXT I32 min_intro_pending;/* start of vars to introduce */
1128 EXT I32 max_intro_pending;/* end of vars to introduce */
1129 EXT I32 padix; /* max used index in current "register" pad */
1130 EXT I32 padix_floor; /* how low may inner block reset padix */
1131 EXT I32 pad_reset_pending; /* reset pad on next attempted alloc */
1134 EXT I32 thisexpr; /* name id for nothing_in_common() */
1135 EXT char * last_uni; /* position of last named-unary operator */
1136 EXT char * last_lop; /* position of last list operator */
1137 EXT OPCODE last_lop_op; /* last list operator */
1138 EXT bool in_my; /* we're compiling a "my" declaration */
1140 EXT I32 cryptseen; /* has fast crypt() been initialized? */
1143 EXT U32 hints; /* various compilation flags */
1145 /* Note: the lowest 8 bits are reserved for
1146 stuffing into op->op_private */
1147 #define HINT_INTEGER 0x00000001
1148 #define HINT_STRICT_REFS 0x00000002
1150 #define HINT_BLOCK_SCOPE 0x00000100
1151 #define HINT_STRICT_SUBS 0x00000200
1152 #define HINT_STRICT_VARS 0x00000400
1154 /**************************************************************************/
1155 /* This regexp stuff is global since it always happens within 1 expr eval */
1156 /**************************************************************************/
1158 EXT char * regprecomp; /* uncompiled string. */
1159 EXT char * regparse; /* Input-scan pointer. */
1160 EXT char * regxend; /* End of input for compile */
1161 EXT I32 regnpar; /* () count. */
1162 EXT char * regcode; /* Code-emit pointer; ®dummy = don't. */
1163 EXT I32 regsize; /* Code size. */
1164 EXT I32 regnaughty; /* How bad is this pattern? */
1165 EXT I32 regsawback; /* Did we see \1, ...? */
1167 EXT char * reginput; /* String-input pointer. */
1168 EXT char * regbol; /* Beginning of input, for ^ check. */
1169 EXT char * regeol; /* End of input, for $ check. */
1170 EXT char ** regstartp; /* Pointer to startp array. */
1171 EXT char ** regendp; /* Ditto for endp. */
1172 EXT U32 * reglastparen; /* Similarly for lastparen. */
1173 EXT char * regtill; /* How far we are required to go. */
1174 EXT U16 regflags; /* are we folding, multilining? */
1175 EXT char regprev; /* char before regbol, \n if none */
1177 /***********************************************/
1178 /* Global only to current interpreter instance */
1179 /***********************************************/
1184 struct interpreter {
1187 #define IINIT(x) INIT(x)
1190 /* pseudo environmental stuff */
1192 IEXT char ** Iorigargv;
1196 IEXT char * Iorigfilename;
1198 IEXT SV * Iwarnhook;
1199 IEXT SV * Iparsehook;
1201 /* Various states of an input record separator SV (rs, nrs) */
1202 #define RsSNARF(sv) (! SvOK(sv))
1203 #define RsSIMPLE(sv) (SvOK(sv) && SvCUR(sv))
1204 #define RsPARA(sv) (SvOK(sv) && ! SvCUR(sv))
1209 IEXT char Ipatchlevel[10];
1211 IEXT char * Isplitstr IINIT(" ");
1212 IEXT bool Ipreprocess;
1218 IEXT bool Idoswitches;
1220 IEXT bool Idoextract;
1221 IEXT bool Isawampersand; /* must save all match strings */
1222 IEXT bool Isawstudy; /* do fbm_instr on all strings */
1223 IEXT bool Isawi; /* study must assume case insensitive */
1226 IEXT bool Ido_undump; /* -u or dump seen? */
1227 IEXT char * Iinplace;
1228 IEXT char * Ie_tmpname;
1230 IEXT VOL U32 Idebug;
1232 /* This value may be raised by extensions for testing purposes */
1233 IEXT int Iperl_destruct_level; /* 0=none, 1=full, 2=full with checks */
1235 /* magical thingies */
1236 IEXT Time_t Ibasetime; /* $^T */
1237 IEXT SV * Iformfeed; /* $^L */
1238 IEXT char * Ichopset IINIT(" \n-"); /* $: */
1239 IEXT SV * Irs; /* $/ */
1240 IEXT char * Iofs; /* $, */
1241 IEXT STRLEN Iofslen;
1242 IEXT char * Iors; /* $\ */
1243 IEXT STRLEN Iorslen;
1244 IEXT char * Iofmt; /* $# */
1245 IEXT I32 Imaxsysfd IINIT(MAXSYSFD); /* top fd to pass to subprocesses */
1246 IEXT int Imultiline; /* $*--do strings hold >1 line? */
1247 IEXT U32 Istatusvalue; /* $? */
1249 IEXT struct stat Istatcache; /* _ */
1251 IEXT SV * Istatname IINIT(Nullsv);
1253 /* shortcuts to various I/O objects */
1255 IEXT GV * Ilast_in_gv;
1258 IEXT GV * Idefoutgv;
1259 IEXT GV * Iargvoutgv;
1261 /* shortcuts to regexp stuff */
1265 IEXT PMOP * Icurpm; /* what to do \ interps from */
1266 IEXT I32 * Iscreamfirst;
1267 IEXT I32 * Iscreamnext;
1268 IEXT I32 Imaxscream IINIT(-1);
1269 IEXT SV * Ilastscream;
1271 /* shortcuts to misc objects */
1274 /* shortcuts to debugging objects */
1278 IEXT SV * IDBsingle;
1280 IEXT SV * IDBsignal;
1281 IEXT AV * Ilineary; /* lines of script for debugger */
1282 IEXT AV * Idbargs; /* args to call listed by caller function */
1285 IEXT HV * Idefstash; /* main symbol table */
1286 IEXT HV * Icurstash; /* symbol table for current package */
1287 IEXT HV * Idebstash; /* symbol table for perldb package */
1288 IEXT SV * Icurstname; /* name of current package */
1289 IEXT AV * Ibeginav; /* names of BEGIN subroutines */
1290 IEXT AV * Iendav; /* names of END subroutines */
1291 IEXT AV * Ipad; /* storage for lexically scoped temporaries */
1292 IEXT AV * Ipadname; /* variable names for "my" variables */
1294 /* memory management */
1295 IEXT SV ** Itmps_stack;
1296 IEXT I32 Itmps_ix IINIT(-1);
1297 IEXT I32 Itmps_floor IINIT(-1);
1299 IEXT I32 Isv_count; /* how many SV* are currently allocated */
1300 IEXT I32 Isv_objcount; /* how many objects are currently allocated */
1301 IEXT SV* Isv_root; /* storage for SVs belonging to interp */
1302 IEXT SV* Isv_arenaroot; /* list of areas for garbage collection */
1304 /* funky return mechanisms */
1305 IEXT I32 Ilastspbase;
1307 IEXT int Iforkprocess; /* so do_open |- can return proc# */
1309 /* subprocess state */
1310 IEXT AV * Ifdpid; /* keep fd-to-pid mappings for my_popen */
1311 IEXT HV * Ipidstatus; /* keep pid-to-status mappings for waitpid */
1313 /* internal state */
1314 IEXT VOL int Iin_eval; /* trap "fatal" errors? */
1315 IEXT OP * Irestartop; /* Are we propagating an error from croak? */
1316 IEXT int Idelaymagic; /* ($<,$>) = ... */
1317 IEXT bool Idirty; /* In the middle of tearing things down? */
1318 IEXT U8 Ilocalizing; /* are we processing a local() list? */
1319 IEXT bool Itainted; /* using variables controlled by $< */
1320 IEXT bool Itainting; /* doing taint checks */
1321 IEXT char * Iop_mask IINIT(NULL); /* masked operations for safe evals */
1325 IEXT I32 Idlmax IINIT(128);
1326 IEXT char * Idebname;
1327 IEXT char * Idebdelim;
1329 /* current interpreter roots */
1331 IEXT OP * Imain_root;
1332 IEXT OP * Imain_start;
1333 IEXT OP * Ieval_root;
1334 IEXT OP * Ieval_start;
1336 /* runtime control stuff */
1337 IEXT COP * VOL Icurcop IINIT(&compiling);
1338 IEXT line_t Icopline IINIT(NOLINE);
1339 IEXT CONTEXT * Icxstack;
1340 IEXT I32 Icxstack_ix IINIT(-1);
1341 IEXT I32 Icxstack_max IINIT(128);
1342 IEXT Sigjmp_buf Itop_env;
1346 IEXT AV * Istack; /* THE STACK */
1347 IEXT AV * Imainstack; /* the stack when nothing funny is happening */
1348 IEXT SV ** Imystack_base; /* stack->array_ary */
1349 IEXT SV ** Imystack_sp; /* stack pointer now */
1350 IEXT SV ** Imystack_max; /* stack->array_ary + stack->array_max */
1352 /* format accumulators */
1353 IEXT SV * Iformtarget;
1354 IEXT SV * Ibodytarget;
1355 IEXT SV * Itoptarget;
1357 /* statics moved here for shared library purposes */
1358 IEXT SV Istrchop; /* return value from chop */
1359 IEXT int Ifilemode; /* so nextargv() can preserve mode */
1360 IEXT int Ilastfd; /* what to preserve mode on */
1361 IEXT char * Ioldname; /* what to preserve mode on */
1362 IEXT char ** IArgv; /* stuff to free from do_aexec, vfork safe */
1363 IEXT char * ICmd; /* stuff to free from do_aexec, vfork safe */
1364 IEXT OP * Isortcop; /* user defined sort routine */
1365 IEXT HV * Isortstash; /* which is in some package or other */
1366 IEXT GV * Ifirstgv; /* $a */
1367 IEXT GV * Isecondgv; /* $b */
1368 IEXT AV * Isortstack; /* temp stack during pp_sort() */
1369 IEXT AV * Isignalstack; /* temp stack during sighandler() */
1370 IEXT SV * Imystrk; /* temp key string for do_each() */
1371 IEXT I32 Idumplvl; /* indentation level on syntax tree dump */
1372 IEXT PMOP * Ioldlastpm; /* for saving regexp context during debugger */
1373 IEXT I32 Igensym; /* next symbol for getsym() to define */
1374 IEXT bool Ipreambled;
1375 IEXT AV * Ipreambleav;
1376 IEXT int Ilaststatval IINIT(-1);
1377 IEXT I32 Ilaststype IINIT(OP_STAT);
1385 struct interpreter {
1403 # include <stdarg.h>
1406 # include <varargs.h>
1413 #define Perl_sv_setptrobj(rv,ptr,name) Perl_sv_setref_iv(rv,name,(IV)ptr)
1414 #define Perl_sv_setptrref(rv,ptr) Perl_sv_setref_iv(rv,Nullch,(IV)ptr)
1416 #define sv_setptrobj(rv,ptr,name) sv_setref_iv(rv,name,(IV)ptr)
1417 #define sv_setptrref(rv,ptr) sv_setref_iv(rv,Nullch,(IV)ptr)
1424 /* The following must follow proto.h */
1427 EXT MGVTBL vtbl_sv = {magic_get,
1431 EXT MGVTBL vtbl_env = {0, 0, 0, 0, 0};
1432 EXT MGVTBL vtbl_envelem = {0, magic_setenv,
1435 EXT MGVTBL vtbl_sig = {0, 0, 0, 0, 0};
1436 EXT MGVTBL vtbl_sigelem = {0, magic_setsig,
1438 EXT MGVTBL vtbl_pack = {0, 0, 0, magic_wipepack,
1440 EXT MGVTBL vtbl_packelem = {magic_getpack,
1444 EXT MGVTBL vtbl_dbline = {0, magic_setdbline,
1446 EXT MGVTBL vtbl_isa = {0, magic_setisa,
1448 EXT MGVTBL vtbl_isaelem = {0, magic_setisa,
1450 EXT MGVTBL vtbl_arylen = {magic_getarylen,
1453 EXT MGVTBL vtbl_glob = {magic_getglob,
1456 EXT MGVTBL vtbl_mglob = {0, magic_setmglob,
1458 EXT MGVTBL vtbl_taint = {magic_gettaint,magic_settaint,
1460 EXT MGVTBL vtbl_substr = {0, magic_setsubstr,
1462 EXT MGVTBL vtbl_vec = {0, magic_setvec,
1464 EXT MGVTBL vtbl_pos = {magic_getpos,
1467 EXT MGVTBL vtbl_bm = {0, magic_setbm,
1469 EXT MGVTBL vtbl_uvar = {magic_getuvar,
1474 EXT MGVTBL vtbl_amagic = {0, magic_setamagic,
1475 0, 0, magic_setamagic};
1476 EXT MGVTBL vtbl_amagicelem = {0, magic_setamagic,
1477 0, 0, magic_setamagic};
1478 #endif /* OVERLOAD */
1482 EXT MGVTBL vtbl_env;
1483 EXT MGVTBL vtbl_envelem;
1484 EXT MGVTBL vtbl_sig;
1485 EXT MGVTBL vtbl_sigelem;
1486 EXT MGVTBL vtbl_pack;
1487 EXT MGVTBL vtbl_packelem;
1488 EXT MGVTBL vtbl_dbline;
1489 EXT MGVTBL vtbl_isa;
1490 EXT MGVTBL vtbl_isaelem;
1491 EXT MGVTBL vtbl_arylen;
1492 EXT MGVTBL vtbl_glob;
1493 EXT MGVTBL vtbl_mglob;
1494 EXT MGVTBL vtbl_taint;
1495 EXT MGVTBL vtbl_substr;
1496 EXT MGVTBL vtbl_vec;
1497 EXT MGVTBL vtbl_pos;
1499 EXT MGVTBL vtbl_uvar;
1502 EXT MGVTBL vtbl_amagic;
1503 EXT MGVTBL vtbl_amagicelem;
1504 #endif /* OVERLOAD */
1509 EXT long amagic_generation;
1511 #define NofAMmeth 29
1513 EXT char * AMG_names[NofAMmeth][2] = {
1515 {"bool", "nomethod"},
1545 EXT char * AMG_names[NofAMmeth][2];
1546 #endif /* def INITAMAGIC */
1551 CV* table[NofAMmeth*2];
1554 typedef struct am_table AMT;
1556 #define AMGfallNEVER 1
1558 #define AMGfallYES 3
1561 fallback_amg, abs_amg,
1562 bool__amg, nomethod_amg,
1563 string_amg, numer_amg,
1564 add_amg, add_ass_amg,
1565 subtr_amg, subtr_ass_amg,
1566 mult_amg, mult_ass_amg,
1567 div_amg, div_ass_amg,
1568 mod_amg, mod_ass_amg,
1569 pow_amg, pow_ass_amg,
1570 lshift_amg, lshift_ass_amg,
1571 rshift_amg, rshift_ass_amg,
1572 band_amg, band_ass_amg,
1573 bor_amg, bor_ass_amg,
1574 bxor_amg, bxor_ass_amg,
1587 repeat_amg, repeat_ass_amg,
1588 concat_amg, concat_ass_amg,
1591 #endif /* OVERLOAD */
1593 #endif /* Include guard */