This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Include <unistd.h>
[perl5.git] / perl.h
CommitLineData
a0d0e21e 1/* perl.h
a687059c 2 *
a0d0e21e 3 * Copyright (c) 1987-1994, Larry Wall
a687059c 4 *
352d5a3a
LW
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.
8d063cd8 7 *
8d063cd8 8 */
85e6fe83
LW
9#ifndef H_PERL
10#define H_PERL 1
a0d0e21e 11#define OVERLOAD
8d063cd8 12
760ac839
LW
13#ifdef PERL_FOR_X2P
14/*
15 * This file is being used for x2p stuff.
16 * Above symbol is defined via -D in 'x2p/Makefile.SH'
17 * Decouple x2p stuff from some of perls more extreme eccentricities.
18 */
19#undef MULTIPLICITY
20#undef EMBED
21#undef USE_STDIO
22#define USE_STDIO
23#endif /* PERL_FOR_X2P */
24
728e2803
PP
25/*
26 * STMT_START { statements; } STMT_END;
27 * can be used as a single statement, as in
28 * if (x) STMT_START { ... } STMT_END; else ...
29 *
30 * Trying to select a version that gives no warnings...
31 */
32#if !(defined(STMT_START) && defined(STMT_END))
33# if defined(__GNUC__) && !defined(__STRICT_ANSI__)
34# define STMT_START (void)( /* gcc supports ``({ STATEMENTS; })'' */
35# define STMT_END )
36# else
37 /* Now which other defined()s do we need here ??? */
38# if (VOIDFLAGS) && (defined(sun) || defined(__sun__))
39# define STMT_START if (1)
40# define STMT_END else (void)0
41# else
42# define STMT_START do
43# define STMT_END while (0)
44# endif
45# endif
46#endif
47
79072805
LW
48#include "embed.h"
49
85e6fe83 50#define VOIDUSED 1
ac58e20f 51#include "config.h"
79072805
LW
52
53#ifndef BYTEORDER
54# define BYTEORDER 0x1234
55#endif
56
57/* Overall memory policy? */
58#ifndef CONSERVATIVE
59# define LIBERAL 1
60#endif
61
62/*
63 * The following contortions are brought to you on behalf of all the
64 * standards, semi-standards, de facto standards, not-so-de-facto standards
65 * of the world, as well as all the other botches anyone ever thought of.
66 * The basic theory is that if we work hard enough here, the rest of the
67 * code can be a lot prettier. Well, so much for theory. Sorry, Henry...
68 */
ac58e20f 69
ee0007ab
LW
70/* define this once if either system, instead of cluttering up the src */
71#if defined(MSDOS) || defined(atarist)
72#define DOSISH 1
73#endif
74
a0d0e21e 75#if defined(__STDC__) || defined(vax11c) || defined(_AIX) || defined(__stdc__) || defined(__cplusplus)
352d5a3a
LW
76# define STANDARD_C 1
77#endif
78
79#if defined(HASVOLATILE) || defined(STANDARD_C)
79072805
LW
80# ifdef __cplusplus
81# define VOL // to temporarily suppress warnings
82# else
83# define VOL volatile
84# endif
663a0e37 85#else
79072805 86# define VOL
663a0e37
LW
87#endif
88
463ee0b2
LW
89#define TAINT_IF(c) (tainted |= (c))
90#define TAINT_NOT (tainted = 0)
91#define TAINT_PROPER(s) if (tainting) taint_proper(no_security, s)
92#define TAINT_ENV() if (tainting) taint_env()
a687059c 93
f82b3d41
PP
94#ifdef USE_BSDPGRP
95# ifdef HAS_GETPGRP
96# define BSD_GETPGRP(pid) getpgrp((pid))
663a0e37 97# endif
f82b3d41
PP
98# ifdef HAS_SETPGRP
99# define BSD_SETPGRP(pid, pgrp) setpgrp((pid), (pgrp))
c07a80fd
PP
100# endif
101#else
f82b3d41
PP
102# ifdef HAS_GETPGRP2
103# define BSD_GETPGRP(pid) getpgrp2((pid))
104# ifndef HAS_GETPGRP
105# define HAS_GETPGRP
106# endif
107# endif
108# ifdef HAS_SETPGRP2
109# define BSD_SETPGRP(pid, pgrp) setpgrp2((pid), (pgrp))
110# ifndef HAS_SETPGRP
111# define HAS_SETPGRP
112# endif
c07a80fd 113# endif
663a0e37
LW
114#endif
115
760ac839
LW
116#ifndef _TYPES_ /* If types.h defines this it's easy. */
117# ifndef major /* Does everyone's types.h define this? */
118# include <sys/types.h>
119# endif
120#endif
121
122#ifdef __cplusplus
123# ifndef I_STDARG
124# define I_STDARG 1
125# endif
126#endif
127
128#ifdef I_STDARG
129# include <stdarg.h>
130#else
131# ifdef I_VARARGS
132# include <varargs.h>
133# endif
134#endif
135
136#include "perlio.h"
0c30d9ec 137
4633a7c4 138#ifdef USE_NEXT_CTYPE
0c30d9ec
PP
139
140#if NX_CURRENT_COMPILER_RELEASE >= 400
141#include <objc/NXCType.h>
142#else /* NX_CURRENT_COMPILER_RELEASE < 400 */
a0d0e21e 143#include <appkit/NXCType.h>
0c30d9ec
PP
144#endif /* NX_CURRENT_COMPILER_RELEASE >= 400 */
145
146#else /* !USE_NEXT_CTYPE */
fe14fcc3 147#include <ctype.h>
0c30d9ec 148#endif /* USE_NEXT_CTYPE */
a0d0e21e 149
4633a7c4
LW
150#ifdef I_LOCALE
151#include <locale.h>
152#endif
153
a0d0e21e
LW
154#ifdef METHOD /* Defined by OSF/1 v3.0 by ctype.h */
155#undef METHOD
156#endif
157
fe14fcc3 158#include <setjmp.h>
79072805 159
a0d0e21e 160#ifdef I_SYS_PARAM
79072805
LW
161# ifdef PARAM_NEEDS_TYPES
162# include <sys/types.h>
163# endif
164# include <sys/param.h>
352d5a3a 165#endif
79072805
LW
166
167
168/* Use all the "standard" definitions? */
a0d0e21e 169#if defined(STANDARD_C) && defined(I_STDLIB)
79072805 170# include <stdlib.h>
352d5a3a 171#endif /* STANDARD_C */
03a14243 172
4633a7c4
LW
173/* Maybe this comes after <stdlib.h> so we don't try to change
174 the standard library prototypes?. We'll use our own in
175 proto.h instead. I guess. The patch had no explanation.
176*/
177#ifdef MYMALLOC
760ac839
LW
178# ifdef HIDEMYMALLOC
179# define malloc Perl_malloc
180# define realloc Perl_realloc
181# define free Perl_free
182# define calloc Perl_calloc
4633a7c4
LW
183# endif
184# define safemalloc malloc
185# define saferealloc realloc
186# define safefree free
0c30d9ec 187# define safecalloc calloc
4633a7c4
LW
188#endif
189
a0d0e21e
LW
190#define MEM_SIZE Size_t
191
192#if defined(I_STRING) || defined(__cplusplus)
193# include <string.h>
194#else
195# include <strings.h>
196#endif
197
198#if !defined(HAS_STRCHR) && defined(HAS_INDEX) && !defined(strchr)
199#define strchr index
200#define strrchr rindex
201#endif
202
203#if defined(mips) && defined(ultrix) && !defined(__STDC__)
79072805 204# undef HAS_MEMCMP
663a0e37 205#endif
fe14fcc3 206
16d20bd9
AD
207#ifdef I_MEMORY
208# include <memory.h>
209#endif
210
fe14fcc3 211#ifdef HAS_MEMCPY
85e6fe83 212# if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
fe14fcc3 213# ifndef memcpy
a0d0e21e 214 extern char * memcpy _((char*, char*, int));
ee0007ab
LW
215# endif
216# endif
217#else
218# ifndef memcpy
219# ifdef HAS_BCOPY
220# define memcpy(d,s,l) bcopy(s,d,l)
221# else
222# define memcpy(d,s,l) my_bcopy(s,d,l)
223# endif
224# endif
225#endif /* HAS_MEMCPY */
fe14fcc3 226
ee0007ab 227#ifdef HAS_MEMSET
85e6fe83 228# if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
ee0007ab 229# ifndef memset
a0d0e21e 230 extern char *memset _((char*, int, int));
ee0007ab
LW
231# endif
232# endif
233# define memzero(d,l) memset(d,0,l)
234#else
235# ifndef memzero
236# ifdef HAS_BZERO
237# define memzero(d,l) bzero(d,l)
238# else
239# define memzero(d,l) my_bzero(d,l)
240# endif
352d5a3a 241# endif
ee0007ab
LW
242#endif /* HAS_MEMSET */
243
244#ifdef HAS_MEMCMP
85e6fe83 245# if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
ee0007ab 246# ifndef memcmp
a0d0e21e 247 extern int memcmp _((char*, char*, int));
ee0007ab
LW
248# endif
249# endif
250#else
251# ifndef memcmp
ecfc5424 252# define memcmp my_memcmp
352d5a3a 253# endif
ee0007ab 254#endif /* HAS_MEMCMP */
8d063cd8 255
f82b3d41 256/* XXX we prefer bcmp slightly for comparisons that don't care about ordering */
ee0007ab 257#ifndef HAS_BCMP
352d5a3a
LW
258# ifndef bcmp
259# define bcmp(s1,s2,l) memcmp(s1,s2,l)
260# endif
ee0007ab
LW
261#endif /* HAS_BCMP */
262
85e6fe83 263#if !defined(HAS_MEMMOVE) && !defined(memmove)
2304df62 264# if defined(HAS_BCOPY) && defined(HAS_SAFE_BCOPY)
79072805
LW
265# define memmove(d,s,l) bcopy(s,d,l)
266# else
2304df62 267# if defined(HAS_MEMCPY) && defined(HAS_SAFE_MEMCPY)
79072805
LW
268# define memmove(d,s,l) memcpy(d,s,l)
269# else
270# define memmove(d,s,l) my_bcopy(s,d,l)
271# endif
272# endif
d9d8d8de 273#endif
378cc40b 274
ae986130 275#ifdef I_NETINET_IN
79072805 276# include <netinet/in.h>
ae986130
LW
277#endif
278
1aef975c 279#ifdef I_SYS_STAT
8d063cd8 280#include <sys/stat.h>
1aef975c 281#endif
79072805 282
a0d0e21e
LW
283/* The stat macros for Amdahl UTS, Unisoft System V/88 (and derivatives
284 like UTekV) are broken, sometimes giving false positives. Undefine
285 them here and let the code below set them to proper values.
286
287 The ghs macro stands for GreenHills Software C-1.8.5 which
288 is the C compiler for sysV88 and the various derivatives.
289 This header file bug is corrected in gcc-2.5.8 and later versions.
290 --Kaveh Ghazi (ghazi@noc.rutgers.edu) 10/3/94. */
291
292#if defined(uts) || (defined(m88k) && defined(ghs))
79072805
LW
293# undef S_ISDIR
294# undef S_ISCHR
295# undef S_ISBLK
296# undef S_ISREG
297# undef S_ISFIFO
298# undef S_ISLNK
ee0007ab 299#endif
135863df 300
663a0e37
LW
301#ifdef I_TIME
302# include <time.h>
ffed7fef 303#endif
663a0e37 304
fe14fcc3 305#ifdef I_SYS_TIME
85e6fe83 306# ifdef I_SYS_TIME_KERNEL
663a0e37
LW
307# define KERNEL
308# endif
309# include <sys/time.h>
85e6fe83 310# ifdef I_SYS_TIME_KERNEL
663a0e37
LW
311# undef KERNEL
312# endif
a687059c 313#endif
135863df 314
d9d8d8de 315#ifndef MSDOS
a0d0e21e 316# if defined(HAS_TIMES) && defined(I_SYS_TIMES)
85e6fe83
LW
317# include <sys/times.h>
318# endif
d9d8d8de 319#endif
8d063cd8 320
fe14fcc3 321#if defined(HAS_STRERROR) && (!defined(HAS_MKDIR) || !defined(HAS_RMDIR))
79072805 322# undef HAS_STRERROR
663a0e37
LW
323#endif
324
a0d0e21e
LW
325#ifndef HAS_MKFIFO
326# ifndef mkfifo
327# define mkfifo(path, mode) (mknod((path), (mode) | S_IFIFO, 0))
328# endif
329#endif /* !HAS_MKFIFO */
330
663a0e37 331#include <errno.h>
ed6116ce 332#ifdef HAS_SOCKET
85e6fe83 333# ifdef I_NET_ERRNO
ed6116ce
LW
334# include <net/errno.h>
335# endif
336#endif
748a9306
LW
337#ifndef VMS
338# define FIXSTATUS(sts) (U_L((sts) & 0xffff))
339# define SHIFTSTATUS(sts) ((sts) >> 8)
340# define SETERRNO(errcode,vmserrcode) errno = (errcode)
341#else
342# define FIXSTATUS(sts) (U_L(sts))
343# define SHIFTSTATUS(sts) (sts)
728e2803 344# define SETERRNO(errcode,vmserrcode) STMT_START {set_errno(errcode); set_vaxc_errno(vmserrcode);} STMT_END
748a9306 345#endif
ed6116ce 346
d9d8d8de 347#ifndef MSDOS
79072805
LW
348# ifndef errno
349 extern int errno; /* ANSI allows errno to be an lvalue expr */
350# endif
d9d8d8de 351#endif
663a0e37 352
2304df62 353#ifdef HAS_STRERROR
a0d0e21e
LW
354# ifdef VMS
355 char *strerror _((int,...));
356# else
357 char *strerror _((int));
358# endif
2304df62
AD
359# ifndef Strerror
360# define Strerror strerror
361# endif
362#else
363# ifdef HAS_SYS_ERRLIST
79072805
LW
364 extern int sys_nerr;
365 extern char *sys_errlist[];
2304df62
AD
366# ifndef Strerror
367# define Strerror(e) \
79072805 368 ((e) < 0 || (e) >= sys_nerr ? "(unknown)" : sys_errlist[e])
2304df62 369# endif
79072805 370# endif
35c8bce7 371#endif
663a0e37 372
2304df62 373#ifdef I_SYS_IOCTL
79072805
LW
374# ifndef _IOCTL_
375# include <sys/ioctl.h>
376# endif
a687059c
LW
377#endif
378
ee0007ab 379#if defined(mc300) || defined(mc500) || defined(mc700) || defined(mc6000)
79072805
LW
380# ifdef HAS_SOCKETPAIR
381# undef HAS_SOCKETPAIR
382# endif
2304df62
AD
383# ifdef I_NDBM
384# undef I_NDBM
79072805 385# endif
a687059c
LW
386#endif
387
a687059c 388#if INTSIZE == 2
79072805
LW
389# define htoni htons
390# define ntohi ntohs
a687059c 391#else
79072805
LW
392# define htoni htonl
393# define ntohi ntohl
a687059c
LW
394#endif
395
a0d0e21e 396/* Configure already sets Direntry_t */
35c8bce7 397#if defined(I_DIRENT)
663a0e37 398# include <dirent.h>
a0d0e21e
LW
399# if defined(NeXT) && defined(I_SYS_DIR) /* NeXT needs dirent + sys/dir.h */
400# include <sys/dir.h>
401# endif
ae986130 402#else
fe14fcc3 403# ifdef I_SYS_NDIR
79a0689e 404# include <sys/ndir.h>
663a0e37 405# else
fe14fcc3 406# ifdef I_SYS_DIR
79a0689e
LW
407# ifdef hp9000s500
408# include <ndir.h> /* may be wrong in the future */
409# else
410# include <sys/dir.h>
411# endif
663a0e37
LW
412# endif
413# endif
4633a7c4 414#endif
a687059c 415
352d5a3a
LW
416#ifdef FPUTS_BOTCH
417/* work around botch in SunOS 4.0.1 and 4.0.2 */
418# ifndef fputs
79072805 419# define fputs(sv,fp) fprintf(fp,"%s",sv)
352d5a3a
LW
420# endif
421#endif
422
c623bd54
LW
423/*
424 * The following gobbledygook brought to you on behalf of __STDC__.
425 * (I could just use #ifndef __STDC__, but this is more bulletproof
426 * in the face of half-implementations.)
427 */
428
429#ifndef S_IFMT
430# ifdef _S_IFMT
431# define S_IFMT _S_IFMT
432# else
433# define S_IFMT 0170000
434# endif
435#endif
436
437#ifndef S_ISDIR
438# define S_ISDIR(m) ((m & S_IFMT) == S_IFDIR)
439#endif
440
441#ifndef S_ISCHR
442# define S_ISCHR(m) ((m & S_IFMT) == S_IFCHR)
443#endif
444
445#ifndef S_ISBLK
fe14fcc3
LW
446# ifdef S_IFBLK
447# define S_ISBLK(m) ((m & S_IFMT) == S_IFBLK)
448# else
449# define S_ISBLK(m) (0)
450# endif
c623bd54
LW
451#endif
452
453#ifndef S_ISREG
454# define S_ISREG(m) ((m & S_IFMT) == S_IFREG)
455#endif
456
457#ifndef S_ISFIFO
fe14fcc3
LW
458# ifdef S_IFIFO
459# define S_ISFIFO(m) ((m & S_IFMT) == S_IFIFO)
460# else
461# define S_ISFIFO(m) (0)
462# endif
c623bd54
LW
463#endif
464
465#ifndef S_ISLNK
466# ifdef _S_ISLNK
467# define S_ISLNK(m) _S_ISLNK(m)
468# else
469# ifdef _S_IFLNK
470# define S_ISLNK(m) ((m & S_IFMT) == _S_IFLNK)
471# else
472# ifdef S_IFLNK
473# define S_ISLNK(m) ((m & S_IFMT) == S_IFLNK)
474# else
475# define S_ISLNK(m) (0)
476# endif
477# endif
478# endif
479#endif
480
481#ifndef S_ISSOCK
482# ifdef _S_ISSOCK
483# define S_ISSOCK(m) _S_ISSOCK(m)
484# else
485# ifdef _S_IFSOCK
486# define S_ISSOCK(m) ((m & S_IFMT) == _S_IFSOCK)
487# else
488# ifdef S_IFSOCK
489# define S_ISSOCK(m) ((m & S_IFMT) == S_IFSOCK)
490# else
491# define S_ISSOCK(m) (0)
492# endif
493# endif
494# endif
495#endif
496
497#ifndef S_IRUSR
498# ifdef S_IREAD
499# define S_IRUSR S_IREAD
500# define S_IWUSR S_IWRITE
501# define S_IXUSR S_IEXEC
502# else
503# define S_IRUSR 0400
504# define S_IWUSR 0200
505# define S_IXUSR 0100
506# endif
507# define S_IRGRP (S_IRUSR>>3)
508# define S_IWGRP (S_IWUSR>>3)
509# define S_IXGRP (S_IXUSR>>3)
510# define S_IROTH (S_IRUSR>>6)
511# define S_IWOTH (S_IWUSR>>6)
512# define S_IXOTH (S_IXUSR>>6)
513#endif
514
515#ifndef S_ISUID
516# define S_ISUID 04000
517#endif
518
519#ifndef S_ISGID
520# define S_ISGID 02000
521#endif
522
79072805
LW
523#ifdef ff_next
524# undef ff_next
352d5a3a
LW
525#endif
526
a0d0e21e 527#if defined(cray) || defined(gould) || defined(i860) || defined(pyr)
45d8adaa
LW
528# define SLOPPYDIVIDE
529#endif
530
0c30d9ec 531#if defined(cray) || defined(convex) || BYTEORDER > 0xffff
ecfc5424 532# define HAS_QUAD
45d8adaa
LW
533#endif
534
748a9306
LW
535#ifdef UV
536#undef UV
537#endif
538
ecfc5424 539#ifdef HAS_QUAD
45d8adaa 540# ifdef cray
ecfc5424 541# define Quad_t int
45d8adaa 542# else
0c30d9ec 543# if defined(convex)
ecfc5424 544# define Quad_t long long
45d8adaa 545# else
ecfc5424 546# define Quad_t long
45d8adaa
LW
547# endif
548# endif
748a9306
LW
549 typedef Quad_t IV;
550 typedef unsigned Quad_t UV;
79072805 551#else
748a9306
LW
552 typedef long IV;
553 typedef unsigned long UV;
79072805
LW
554#endif
555
760ac839
LW
556/* Previously these definitions used hardcoded figures.
557 * It is hoped these formula are more portable, although
558 * no data one way or another is presently known to me.
559 * The "PERL_" names are used because these calculated constants
560 * do not meet the ANSI requirements for LONG_MAX, etc., which
561 * need to be constants acceptable to #if - kja
562 * define PERL_LONG_MAX 2147483647L
563 * define PERL_LONG_MIN (-LONG_MAX - 1)
564 * define PERL ULONG_MAX 4294967295L
565 */
566
567#ifdef I_LIMITS /* Needed for cast_xxx() functions below. */
568# include <limits.h>
569#else
570#ifdef I_VALUES
571# include <values.h>
572#endif
573#endif
574
575#ifdef LONG_MAX
576#define PERL_LONG_MAX LONG_MAX
577#else
578# ifdef MAXLONG /* Often used in <values.h> */
579# define PERL_LONG_MAX MAXLONG
580# else
581# define PERL_LONG_MAX ((long) ((~(unsigned long)0) >> 1))
582# endif
583#endif
584
585#ifdef LONG_MIN
586#define PERL_LONG_MIN LONG_MIN
587#else
588# ifdef MINLONG
589# define PERL_LONG_MIN MINLONG
590# else
591# define PERL_LONG_MIN (-LONG_MAX - ((3 & -1) == 3))
592# endif
593#endif
594
595#ifdef ULONG_MAX
596#define PERL_ULONG_MAX ULONG_MAX
597#else
598# ifdef MAXULONG
599# define PERL_ULONG_MAX MAXULONG
600# else
601# define PERL_ULONG_MAX (~(unsigned long)0)
602# endif
603#endif
604
605#ifdef ULONG_MIN
606#define PERL_ULONG_MIN ULONG_MIN
607#else
608# define ULONG_MIN 0L
609#endif
610
ee0007ab 611typedef MEM_SIZE STRLEN;
450a55e4 612
79072805
LW
613typedef struct op OP;
614typedef struct cop COP;
615typedef struct unop UNOP;
616typedef struct binop BINOP;
617typedef struct listop LISTOP;
618typedef struct logop LOGOP;
619typedef struct condop CONDOP;
620typedef struct pmop PMOP;
621typedef struct svop SVOP;
622typedef struct gvop GVOP;
623typedef struct pvop PVOP;
79072805
LW
624typedef struct loop LOOP;
625
626typedef struct Outrec Outrec;
93a17b20 627typedef struct interpreter PerlInterpreter;
79072805 628typedef struct ff FF;
79072805
LW
629typedef struct sv SV;
630typedef struct av AV;
631typedef struct hv HV;
632typedef struct cv CV;
378cc40b 633typedef struct regexp REGEXP;
79072805 634typedef struct gp GP;
0c30d9ec 635typedef struct gv GV;
8990e307 636typedef struct io IO;
79072805
LW
637typedef struct context CONTEXT;
638typedef struct block BLOCK;
639
640typedef struct magic MAGIC;
ed6116ce 641typedef struct xrv XRV;
79072805
LW
642typedef struct xpv XPV;
643typedef struct xpviv XPVIV;
644typedef struct xpvnv XPVNV;
645typedef struct xpvmg XPVMG;
646typedef struct xpvlv XPVLV;
647typedef struct xpvav XPVAV;
648typedef struct xpvhv XPVHV;
649typedef struct xpvgv XPVGV;
650typedef struct xpvcv XPVCV;
651typedef struct xpvbm XPVBM;
652typedef struct xpvfm XPVFM;
8990e307 653typedef struct xpvio XPVIO;
79072805
LW
654typedef struct mgvtbl MGVTBL;
655typedef union any ANY;
8d063cd8 656
378cc40b 657#include "handy.h"
a0d0e21e 658
16d20bd9
AD
659typedef I32 (*filter_t) _((int, SV *, int));
660#define FILTER_READ(idx, sv, len) filter_read(idx, sv, len)
661#define FILTER_DATA(idx) (AvARRAY(rsfp_filters)[idx])
662#define FILTER_ISREADER(idx) (idx >= AvFILL(rsfp_filters))
663
748a9306 664#ifdef DOSISH
4633a7c4
LW
665# if defined(OS2)
666# include "os2ish.h"
667# else
748a9306 668# include "dosish.h"
4633a7c4 669# endif
a0d0e21e 670#else
748a9306
LW
671# if defined(VMS)
672# include "vmsish.h"
673# else
0c30d9ec
PP
674# if defined(PLAN9)
675# include "./plan9/plan9ish.h"
676# else
677# include "unixish.h"
678# endif
748a9306
LW
679# endif
680#endif
681
0c30d9ec
PP
682#ifndef SH_PATH /* May be a variable. */
683# define SH_PATH BIN_SH
760ac839
LW
684#ifndef BIN_SH
685# define BIN_SH "/bin/sh"
686#endif
0c30d9ec
PP
687#endif
688
748a9306
LW
689#ifndef HAS_PAUSE
690#define pause() sleep((32767<<16)+32767)
691#endif
692
693#ifndef IOCPARM_LEN
694# ifdef IOCPARM_MASK
695 /* on BSDish systes we're safe */
696# define IOCPARM_LEN(x) (((x) >> 16) & IOCPARM_MASK)
697# else
698 /* otherwise guess at what's safe */
699# define IOCPARM_LEN(x) 256
700# endif
a0d0e21e
LW
701#endif
702
79072805
LW
703union any {
704 void* any_ptr;
705 I32 any_i32;
a0d0e21e 706 IV any_iv;
85e6fe83 707 long any_long;
a0d0e21e 708 void (*any_dptr) _((void*));
79072805
LW
709};
710
378cc40b 711#include "regexp.h"
79072805 712#include "sv.h"
378cc40b 713#include "util.h"
8d063cd8 714#include "form.h"
79072805
LW
715#include "gv.h"
716#include "cv.h"
717#include "opcode.h"
718#include "op.h"
719#include "cop.h"
720#include "av.h"
721#include "hv.h"
722#include "mg.h"
723#include "scope.h"
8d063cd8 724
4633a7c4
LW
725/* work around some libPW problems */
726#ifdef DOINIT
727EXT char Error[1];
728#endif
729
450a55e4 730#if defined(iAPX286) || defined(M_I286) || defined(I80286)
a687059c
LW
731# define I286
732#endif
733
fe14fcc3
LW
734#if defined(htonl) && !defined(HAS_HTONL)
735#define HAS_HTONL
ae986130 736#endif
fe14fcc3
LW
737#if defined(htons) && !defined(HAS_HTONS)
738#define HAS_HTONS
ae986130 739#endif
fe14fcc3
LW
740#if defined(ntohl) && !defined(HAS_NTOHL)
741#define HAS_NTOHL
ae986130 742#endif
fe14fcc3
LW
743#if defined(ntohs) && !defined(HAS_NTOHS)
744#define HAS_NTOHS
ae986130 745#endif
fe14fcc3 746#ifndef HAS_HTONL
d9d8d8de 747#if (BYTEORDER & 0xffff) != 0x4321
fe14fcc3
LW
748#define HAS_HTONS
749#define HAS_HTONL
750#define HAS_NTOHS
751#define HAS_NTOHL
a687059c
LW
752#define MYSWAP
753#define htons my_swap
754#define htonl my_htonl
755#define ntohs my_swap
756#define ntohl my_ntohl
757#endif
758#else
d9d8d8de 759#if (BYTEORDER & 0xffff) == 0x4321
fe14fcc3
LW
760#undef HAS_HTONS
761#undef HAS_HTONL
762#undef HAS_NTOHS
763#undef HAS_NTOHL
a687059c
LW
764#endif
765#endif
766
988174c1
LW
767/*
768 * Little-endian byte order functions - 'v' for 'VAX', or 'reVerse'.
769 * -DWS
770 */
771#if BYTEORDER != 0x1234
772# define HAS_VTOHL
773# define HAS_VTOHS
774# define HAS_HTOVL
775# define HAS_HTOVS
776# if BYTEORDER == 0x4321
777# define vtohl(x) ((((x)&0xFF)<<24) \
778 +(((x)>>24)&0xFF) \
779 +(((x)&0x0000FF00)<<8) \
780 +(((x)&0x00FF0000)>>8) )
781# define vtohs(x) ((((x)&0xFF)<<8) + (((x)>>8)&0xFF))
782# define htovl(x) vtohl(x)
783# define htovs(x) vtohs(x)
784# endif
785 /* otherwise default to functions in util.c */
786#endif
787
0f85fab0 788#ifdef CASTNEGFLOAT
79072805 789#define U_S(what) ((U16)(what))
0f85fab0 790#define U_I(what) ((unsigned int)(what))
79072805 791#define U_L(what) ((U32)(what))
0f85fab0 792#else
a0d0e21e 793U32 cast_ulong _((double));
232e078e
AD
794#define U_S(what) ((U16)cast_ulong((double)(what)))
795#define U_I(what) ((unsigned int)cast_ulong((double)(what)))
796#define U_L(what) (cast_ulong((double)(what)))
ee0007ab
LW
797#endif
798
ed6116ce
LW
799#ifdef CASTI32
800#define I_32(what) ((I32)(what))
a0d0e21e 801#define I_V(what) ((IV)(what))
5d94fbed 802#define U_V(what) ((UV)(what))
ed6116ce 803#else
a0d0e21e 804I32 cast_i32 _((double));
232e078e 805#define I_32(what) (cast_i32((double)(what)))
a0d0e21e 806IV cast_iv _((double));
232e078e 807#define I_V(what) (cast_iv((double)(what)))
5d94fbed
AD
808UV cast_uv _((double));
809#define U_V(what) (cast_uv((double)(what)))
ed6116ce
LW
810#endif
811
79072805
LW
812struct Outrec {
813 I32 o_lines;
d9d8d8de 814 char *o_str;
79072805 815 U32 o_len;
8d063cd8
LW
816};
817
352d5a3a
LW
818#ifndef MAXSYSFD
819# define MAXSYSFD 2
820#endif
ee0007ab 821
f82b3d41
PP
822#ifndef TMPPATH
823# define TMPPATH "/tmp/perl-eXXXXXX"
a0d0e21e 824#endif
79072805
LW
825
826#ifndef __cplusplus
a0d0e21e
LW
827Uid_t getuid _((void));
828Uid_t geteuid _((void));
829Gid_t getgid _((void));
830Gid_t getegid _((void));
79072805 831#endif
8d063cd8
LW
832
833#ifdef DEBUGGING
0c30d9ec 834#ifndef Perl_debug_log
760ac839 835#define Perl_debug_log PerlIO_stderr()
0c30d9ec 836#endif
d96024cf 837#define YYDEBUG 1
79072805
LW
838#define DEB(a) a
839#define DEBUG(a) if (debug) a
840#define DEBUG_p(a) if (debug & 1) a
841#define DEBUG_s(a) if (debug & 2) a
842#define DEBUG_l(a) if (debug & 4) a
843#define DEBUG_t(a) if (debug & 8) a
844#define DEBUG_o(a) if (debug & 16) a
845#define DEBUG_c(a) if (debug & 32) a
846#define DEBUG_P(a) if (debug & 64) a
0c30d9ec 847#define DEBUG_m(a) if (curinterp && debug & 128) a
79072805
LW
848#define DEBUG_f(a) if (debug & 256) a
849#define DEBUG_r(a) if (debug & 512) a
850#define DEBUG_x(a) if (debug & 1024) a
851#define DEBUG_u(a) if (debug & 2048) a
852#define DEBUG_L(a) if (debug & 4096) a
853#define DEBUG_H(a) if (debug & 8192) a
854#define DEBUG_X(a) if (debug & 16384) a
8990e307 855#define DEBUG_D(a) if (debug & 32768) a
79072805
LW
856#else
857#define DEB(a)
858#define DEBUG(a)
859#define DEBUG_p(a)
860#define DEBUG_s(a)
861#define DEBUG_l(a)
862#define DEBUG_t(a)
863#define DEBUG_o(a)
864#define DEBUG_c(a)
865#define DEBUG_P(a)
866#define DEBUG_m(a)
867#define DEBUG_f(a)
868#define DEBUG_r(a)
869#define DEBUG_x(a)
870#define DEBUG_u(a)
871#define DEBUG_L(a)
872#define DEBUG_H(a)
873#define DEBUG_X(a)
8990e307 874#define DEBUG_D(a)
8d063cd8 875#endif
fe14fcc3 876#define YYMAXDEPTH 300
8d063cd8 877
79072805
LW
878#define assert(what) DEB( { \
879 if (!(what)) { \
463ee0b2 880 croak("Assertion failed: file \"%s\", line %d", \
79072805
LW
881 __FILE__, __LINE__); \
882 exit(1); \
883 }})
8d063cd8 884
450a55e4 885struct ufuncs {
a0d0e21e
LW
886 I32 (*uf_val)_((IV, SV*));
887 I32 (*uf_set)_((IV, SV*));
888 IV uf_index;
450a55e4
LW
889};
890
fe14fcc3 891/* Fix these up for __STDC__ */
a0d0e21e
LW
892#ifndef __cplusplus
893char *mktemp _((char*));
894double atof _((const char*));
895#endif
79072805 896
352d5a3a 897#ifndef STANDARD_C
fe14fcc3 898/* All of these are in stdlib.h or time.h for ANSI C */
85e6fe83 899Time_t time();
8d063cd8 900struct tm *gmtime(), *localtime();
93a17b20 901char *strchr(), *strrchr();
378cc40b 902char *strcpy(), *strcat();
352d5a3a 903#endif /* ! STANDARD_C */
8d063cd8 904
79072805
LW
905
906#ifdef I_MATH
907# include <math.h>
908#else
909# ifdef __cplusplus
910 extern "C" {
911# endif
a0d0e21e 912 double exp _((double));
a0d0e21e
LW
913 double log _((double));
914 double sqrt _((double));
915 double modf _((double,double*));
916 double sin _((double));
917 double cos _((double));
918 double atan2 _((double,double));
919 double pow _((double,double));
79072805
LW
920# ifdef __cplusplus
921 };
922# endif
923#endif
924
a0d0e21e
LW
925#ifndef __cplusplus
926char *crypt _((const char*, const char*));
927char *getenv _((const char*));
928Off_t lseek _((int,Off_t,int));
929char *getlogin _((void));
930#endif
79072805 931
16d20bd9 932#ifdef UNLINK_ALL_VERSIONS /* Currently only makes sense for VMS */
378cc40b 933#define UNLINK unlnk
a0d0e21e 934I32 unlnk _((char*));
8d063cd8
LW
935#else
936#define UNLINK unlink
937#endif
a687059c 938
fe14fcc3 939#ifndef HAS_SETREUID
85e6fe83
LW
940# ifdef HAS_SETRESUID
941# define setreuid(r,e) setresuid(r,e,(Uid_t)-1)
942# define HAS_SETREUID
943# endif
a687059c 944#endif
fe14fcc3 945#ifndef HAS_SETREGID
85e6fe83
LW
946# ifdef HAS_SETRESGID
947# define setregid(r,e) setresgid(r,e,(Gid_t)-1)
948# define HAS_SETREGID
949# endif
a687059c 950#endif
ee0007ab
LW
951
952#define SCAN_DEF 0
953#define SCAN_TR 1
954#define SCAN_REPL 2
79072805 955
760ac839
LW
956#ifdef MYMALLOC
957# ifndef DEBUGGING_MSTATS
958# define DEBUGGING_MSTATS
959# endif
960#endif
961
79072805 962#ifdef DEBUGGING
4633a7c4 963# ifndef register
a0d0e21e
LW
964# define register
965# endif
966# define PAD_SV(po) pad_sv(po)
79072805 967#else
a0d0e21e 968# define PAD_SV(po) curpad[po]
79072805
LW
969#endif
970
971/****************/
972/* Truly global */
973/****************/
974
975/* global state */
a0d0e21e 976EXT PerlInterpreter * curinterp; /* currently running interpreter */
0c30d9ec
PP
977/* VMS doesn't use environ array and NeXT has problems with crt0.o globals */
978#if !defined(VMS) && !(defined(NeXT) && defined(__DYNAMIC__))
79072805 979extern char ** environ; /* environment variables supplied via exec */
0c30d9ec
PP
980#else
981# if defined(NeXT) && defined(__DYNAMIC__)
982
983# include <mach-o/dyld.h>
984EXT char *** environ_pointer;
985# define environ (*environ_pointer)
986# endif
987#endif /* environ processing */
988
79072805
LW
989EXT int uid; /* current real user id */
990EXT int euid; /* current effective user id */
991EXT int gid; /* current real group id */
992EXT int egid; /* current effective group id */
993EXT bool nomemok; /* let malloc context handle nomem */
994EXT U32 an; /* malloc sequence number */
463ee0b2 995EXT U32 cop_seqmax; /* statement sequence number */
c07a80fd 996EXT U16 op_seqmax; /* op sequence number */
8990e307 997EXT U32 evalseq; /* eval sequence number */
463ee0b2 998EXT U32 sub_generation; /* inc to force methods to be looked up again */
79072805
LW
999EXT char ** origenviron;
1000EXT U32 origalen;
a0d0e21e 1001EXT U32 * profiledata;
84ea024a 1002EXT int maxo INIT(MAXO);/* Number of ops */
728e2803 1003EXT char * osname; /* operating system */
79072805 1004
a0d0e21e
LW
1005EXT XPV* xiv_arenaroot; /* list of allocated xiv areas */
1006EXT IV ** xiv_root; /* free xiv list--shared by interpreters */
8990e307
LW
1007EXT double * xnv_root; /* free xnv list--shared by interpreters */
1008EXT XRV * xrv_root; /* free xrv list--shared by interpreters */
1009EXT XPV * xpv_root; /* free xpv list--shared by interpreters */
4633a7c4 1010EXT HE * he_root; /* free he list--shared by interpreters */
c07a80fd
PP
1011EXT char * nice_chunk; /* a nice chunk of memory to reuse */
1012EXT U32 nice_chunk_size;/* how nice the chunk of memory is */
8990e307 1013
79072805
LW
1014/* Stack for currently executing thread--context switch must handle this. */
1015EXT SV ** stack_base; /* stack->array_ary */
1016EXT SV ** stack_sp; /* stack pointer now */
1017EXT SV ** stack_max; /* stack->array_ary + stack->array_max */
1018
1019/* likewise for these */
1020
1021EXT OP * op; /* current op--oughta be in a global register */
1022
1023EXT I32 * scopestack; /* blocks we've entered */
1024EXT I32 scopestack_ix;
1025EXT I32 scopestack_max;
1026
1027EXT ANY* savestack; /* to save non-local values on */
1028EXT I32 savestack_ix;
1029EXT I32 savestack_max;
1030
1031EXT OP ** retstack; /* returns we've pushed */
1032EXT I32 retstack_ix;
1033EXT I32 retstack_max;
1034
1035EXT I32 * markstack; /* stackmarks we're remembering */
1036EXT I32 * markstack_ptr; /* stackmarks we're remembering */
1037EXT I32 * markstack_max; /* stackmarks we're remembering */
1038
1039EXT SV ** curpad;
1040
1041/* temp space */
1042EXT SV * Sv;
1043EXT XPV * Xpv;
f82b3d41 1044EXT char buf[2048]; /* should be longer than PATH_MAX */
79072805
LW
1045EXT char tokenbuf[256];
1046EXT struct stat statbuf;
ecfc5424 1047#ifdef HAS_TIMES
79072805
LW
1048EXT struct tms timesbuf;
1049#endif
463ee0b2 1050EXT STRLEN na; /* for use in SvPV when length is Not Applicable */
79072805
LW
1051
1052/* for tmp use in stupid debuggers */
1053EXT int * di;
1054EXT short * ds;
1055EXT char * dc;
1056
1057/* handy constants */
1058EXT char * Yes INIT("1");
1059EXT char * No INIT("");
1060EXT char * hexdigit INIT("0123456789abcdef0123456789ABCDEFx");
79072805
LW
1061EXT char * patleave INIT("\\.^$@dDwWsSbB+*?|()-nrtfeaxc0123456789[{]}");
1062EXT char * vert INIT("|");
1063
8990e307 1064EXT char warn_uninit[]
a0d0e21e 1065 INIT("Use of uninitialized value");
463ee0b2
LW
1066EXT char warn_nosemi[]
1067 INIT("Semicolon seems to be missing");
1068EXT char warn_reserved[]
1069 INIT("Unquoted string \"%s\" may clash with future reserved word");
1070EXT char warn_nl[]
93a17b20 1071 INIT("Unsuccessful %s on filename containing newline");
a0d0e21e
LW
1072EXT char no_wrongref[]
1073 INIT("Can't use %s ref as %s ref");
1074EXT char no_symref[]
748a9306 1075 INIT("Can't use string (\"%.32s\") as %s ref while \"strict refs\" in use");
93a17b20 1076EXT char no_usym[]
8990e307 1077 INIT("Can't use an undefined value as %s reference");
93a17b20
LW
1078EXT char no_aelem[]
1079 INIT("Modification of non-creatable array value attempted, subscript %d");
1080EXT char no_helem[]
1081 INIT("Modification of non-creatable hash value attempted, subscript \"%s\"");
1082EXT char no_modify[]
1083 INIT("Modification of a read-only value attempted");
1084EXT char no_mem[]
1085 INIT("Out of memory!\n");
1086EXT char no_security[]
463ee0b2 1087 INIT("Insecure dependency in %s%s");
93a17b20
LW
1088EXT char no_sock_func[]
1089 INIT("Unsupported socket function \"%s\" called");
1090EXT char no_dir_func[]
1091 INIT("Unsupported directory function \"%s\" called");
1092EXT char no_func[]
1093 INIT("The %s function is unimplemented");
748a9306
LW
1094EXT char no_myglob[]
1095 INIT("\"my\" variable %s can't be in a package");
93a17b20 1096
79072805
LW
1097EXT SV sv_undef;
1098EXT SV sv_no;
1099EXT SV sv_yes;
1100#ifdef CSH
1101 EXT char * cshname INIT(CSH);
1102 EXT I32 cshlen;
1103#endif
1104
1105#ifdef DOINIT
8e07c86e
AD
1106EXT char *sig_name[] = { SIG_NAME };
1107EXT int sig_num[] = { SIG_NUM };
0c30d9ec
PP
1108EXT SV * psig_ptr[sizeof(sig_num)/sizeof(*sig_num)];
1109EXT SV * psig_name[sizeof(sig_num)/sizeof(*sig_num)];
79072805
LW
1110#else
1111EXT char *sig_name[];
8e07c86e 1112EXT int sig_num[];
0c30d9ec
PP
1113EXT SV * psig_ptr[];
1114EXT SV * psig_name[];
79072805
LW
1115#endif
1116
1117#ifdef DOINIT
79072805
LW
1118EXT unsigned char fold[] = { /* fast case folding table */
1119 0, 1, 2, 3, 4, 5, 6, 7,
1120 8, 9, 10, 11, 12, 13, 14, 15,
1121 16, 17, 18, 19, 20, 21, 22, 23,
1122 24, 25, 26, 27, 28, 29, 30, 31,
1123 32, 33, 34, 35, 36, 37, 38, 39,
1124 40, 41, 42, 43, 44, 45, 46, 47,
1125 48, 49, 50, 51, 52, 53, 54, 55,
1126 56, 57, 58, 59, 60, 61, 62, 63,
1127 64, 'a', 'b', 'c', 'd', 'e', 'f', 'g',
1128 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
1129 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
1130 'x', 'y', 'z', 91, 92, 93, 94, 95,
1131 96, 'A', 'B', 'C', 'D', 'E', 'F', 'G',
1132 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
1133 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
1134 'X', 'Y', 'Z', 123, 124, 125, 126, 127,
1135 128, 129, 130, 131, 132, 133, 134, 135,
1136 136, 137, 138, 139, 140, 141, 142, 143,
1137 144, 145, 146, 147, 148, 149, 150, 151,
1138 152, 153, 154, 155, 156, 157, 158, 159,
1139 160, 161, 162, 163, 164, 165, 166, 167,
1140 168, 169, 170, 171, 172, 173, 174, 175,
1141 176, 177, 178, 179, 180, 181, 182, 183,
1142 184, 185, 186, 187, 188, 189, 190, 191,
1143 192, 193, 194, 195, 196, 197, 198, 199,
1144 200, 201, 202, 203, 204, 205, 206, 207,
1145 208, 209, 210, 211, 212, 213, 214, 215,
1146 216, 217, 218, 219, 220, 221, 222, 223,
1147 224, 225, 226, 227, 228, 229, 230, 231,
1148 232, 233, 234, 235, 236, 237, 238, 239,
1149 240, 241, 242, 243, 244, 245, 246, 247,
1150 248, 249, 250, 251, 252, 253, 254, 255
1151};
1152#else
1153EXT unsigned char fold[];
1154#endif
1155
1156#ifdef DOINIT
1157EXT unsigned char freq[] = { /* letter frequencies for mixed English/C */
1158 1, 2, 84, 151, 154, 155, 156, 157,
1159 165, 246, 250, 3, 158, 7, 18, 29,
1160 40, 51, 62, 73, 85, 96, 107, 118,
1161 129, 140, 147, 148, 149, 150, 152, 153,
1162 255, 182, 224, 205, 174, 176, 180, 217,
1163 233, 232, 236, 187, 235, 228, 234, 226,
1164 222, 219, 211, 195, 188, 193, 185, 184,
1165 191, 183, 201, 229, 181, 220, 194, 162,
1166 163, 208, 186, 202, 200, 218, 198, 179,
1167 178, 214, 166, 170, 207, 199, 209, 206,
1168 204, 160, 212, 216, 215, 192, 175, 173,
1169 243, 172, 161, 190, 203, 189, 164, 230,
1170 167, 248, 227, 244, 242, 255, 241, 231,
1171 240, 253, 169, 210, 245, 237, 249, 247,
1172 239, 168, 252, 251, 254, 238, 223, 221,
1173 213, 225, 177, 197, 171, 196, 159, 4,
1174 5, 6, 8, 9, 10, 11, 12, 13,
1175 14, 15, 16, 17, 19, 20, 21, 22,
1176 23, 24, 25, 26, 27, 28, 30, 31,
1177 32, 33, 34, 35, 36, 37, 38, 39,
1178 41, 42, 43, 44, 45, 46, 47, 48,
1179 49, 50, 52, 53, 54, 55, 56, 57,
1180 58, 59, 60, 61, 63, 64, 65, 66,
1181 67, 68, 69, 70, 71, 72, 74, 75,
1182 76, 77, 78, 79, 80, 81, 82, 83,
1183 86, 87, 88, 89, 90, 91, 92, 93,
1184 94, 95, 97, 98, 99, 100, 101, 102,
1185 103, 104, 105, 106, 108, 109, 110, 111,
1186 112, 113, 114, 115, 116, 117, 119, 120,
1187 121, 122, 123, 124, 125, 126, 127, 128,
1188 130, 131, 132, 133, 134, 135, 136, 137,
1189 138, 139, 141, 142, 143, 144, 145, 146
1190};
1191#else
1192EXT unsigned char freq[];
1193#endif
1194
8990e307
LW
1195#ifdef DEBUGGING
1196#ifdef DOINIT
1197EXT char* block_type[] = {
1198 "NULL",
1199 "SUB",
1200 "EVAL",
1201 "LOOP",
1202 "SUBST",
1203 "BLOCK",
1204};
1205#else
1206EXT char* block_type[];
1207#endif
1208#endif
1209
79072805
LW
1210/*****************************************************************************/
1211/* This lexer/parser stuff is currently global since yacc is hard to reenter */
1212/*****************************************************************************/
8990e307 1213/* XXX This needs to be revisited, since BEGIN makes yacc re-enter... */
79072805 1214
a0d0e21e
LW
1215#include "perly.h"
1216
79072805
LW
1217typedef enum {
1218 XOPERATOR,
1219 XTERM,
79072805 1220 XREF,
8990e307 1221 XSTATE,
a0d0e21e
LW
1222 XBLOCK,
1223 XTERMBLOCK
79072805
LW
1224} expectation;
1225
a0d0e21e
LW
1226EXT U32 lex_state; /* next token is determined */
1227EXT U32 lex_defer; /* state after determined token */
1228EXT expectation lex_expect; /* expect after determined token */
1229EXT I32 lex_brackets; /* bracket count */
1230EXT I32 lex_formbrack; /* bracket count at outer format level */
1231EXT I32 lex_fakebrack; /* outer bracket is mere delimiter */
1232EXT I32 lex_casemods; /* casemod count */
1233EXT I32 lex_dojoin; /* doing an array interpolation */
1234EXT I32 lex_starts; /* how many interps done on level */
1235EXT SV * lex_stuff; /* runtime pattern from m// or s/// */
1236EXT SV * lex_repl; /* runtime replacement from s/// */
1237EXT OP * lex_op; /* extra info to pass back on op */
1238EXT OP * lex_inpat; /* in pattern $) and $| are special */
1239EXT I32 lex_inwhat; /* what kind of quoting are we in */
1240EXT char * lex_brackstack; /* what kind of brackets to pop */
1241EXT char * lex_casestack; /* what kind of case mods in effect */
1242
1243/* What we know when we're in LEX_KNOWNEXT state. */
1244EXT YYSTYPE nextval[5]; /* value of next token, if any */
1245EXT I32 nexttype[5]; /* type of next token */
1246EXT I32 nexttoke;
1247
760ac839 1248EXT PerlIO * VOL rsfp INIT(Nullfp);
79072805
LW
1249EXT SV * linestr;
1250EXT char * bufptr;
1251EXT char * oldbufptr;
1252EXT char * oldoldbufptr;
1253EXT char * bufend;
8990e307 1254EXT expectation expect INIT(XSTATE); /* how to interpret ambiguous tokens */
16d20bd9 1255EXT AV * rsfp_filters;
79072805
LW
1256
1257EXT I32 multi_start; /* 1st line of multi-line string */
1258EXT I32 multi_end; /* last line of multi-line string */
1259EXT I32 multi_open; /* delimiter of said string */
1260EXT I32 multi_close; /* delimiter of said string */
1261
1262EXT GV * scrgv;
1263EXT I32 error_count; /* how many errors so far, max 10 */
1264EXT I32 subline; /* line this subroutine began on */
1265EXT SV * subname; /* name of current subroutine */
1266
748a9306 1267EXT CV * compcv; /* currently compiling subroutine */
93a17b20 1268EXT AV * comppad; /* storage for lexically scoped temporaries */
8990e307
LW
1269EXT AV * comppad_name; /* variable names for "my" variables */
1270EXT I32 comppad_name_fill;/* last "introduced" variable offset */
0c30d9ec 1271EXT I32 comppad_name_floor;/* start of vars in innermost block */
8990e307
LW
1272EXT I32 min_intro_pending;/* start of vars to introduce */
1273EXT I32 max_intro_pending;/* end of vars to introduce */
79072805 1274EXT I32 padix; /* max used index in current "register" pad */
a0d0e21e 1275EXT I32 padix_floor; /* how low may inner block reset padix */
748a9306 1276EXT I32 pad_reset_pending; /* reset pad on next attempted alloc */
79072805
LW
1277EXT COP compiling;
1278
79072805
LW
1279EXT I32 thisexpr; /* name id for nothing_in_common() */
1280EXT char * last_uni; /* position of last named-unary operator */
1281EXT char * last_lop; /* position of last list operator */
8990e307 1282EXT OPCODE last_lop_op; /* last list operator */
93a17b20 1283EXT bool in_my; /* we're compiling a "my" declaration */
79072805
LW
1284#ifdef FCRYPT
1285EXT I32 cryptseen; /* has fast crypt() been initialized? */
1286#endif
1287
85e6fe83
LW
1288EXT U32 hints; /* various compilation flags */
1289
1290 /* Note: the lowest 8 bits are reserved for
1291 stuffing into op->op_private */
1292#define HINT_INTEGER 0x00000001
1293#define HINT_STRICT_REFS 0x00000002
1294
1295#define HINT_BLOCK_SCOPE 0x00000100
1296#define HINT_STRICT_SUBS 0x00000200
1297#define HINT_STRICT_VARS 0x00000400
0c30d9ec 1298#define HINT_STRICT_UNTIE 0x00000800
85e6fe83 1299
79072805
LW
1300/**************************************************************************/
1301/* This regexp stuff is global since it always happens within 1 expr eval */
1302/**************************************************************************/
1303
1304EXT char * regprecomp; /* uncompiled string. */
1305EXT char * regparse; /* Input-scan pointer. */
1306EXT char * regxend; /* End of input for compile */
1307EXT I32 regnpar; /* () count. */
1308EXT char * regcode; /* Code-emit pointer; &regdummy = don't. */
1309EXT I32 regsize; /* Code size. */
a0d0e21e 1310EXT I32 regnaughty; /* How bad is this pattern? */
79072805
LW
1311EXT I32 regsawback; /* Did we see \1, ...? */
1312
1313EXT char * reginput; /* String-input pointer. */
79072805
LW
1314EXT char * regbol; /* Beginning of input, for ^ check. */
1315EXT char * regeol; /* End of input, for $ check. */
1316EXT char ** regstartp; /* Pointer to startp array. */
1317EXT char ** regendp; /* Ditto for endp. */
a0d0e21e 1318EXT U32 * reglastparen; /* Similarly for lastparen. */
79072805 1319EXT char * regtill; /* How far we are required to go. */
a0d0e21e
LW
1320EXT U16 regflags; /* are we folding, multilining? */
1321EXT char regprev; /* char before regbol, \n if none */
79072805 1322
760ac839
LW
1323EXT bool do_undump; /* -u or dump seen? */
1324EXT VOL U32 debug;
1325
79072805
LW
1326/***********************************************/
1327/* Global only to current interpreter instance */
1328/***********************************************/
1329
8990e307 1330#ifdef MULTIPLICITY
79072805
LW
1331#define IEXT
1332#define IINIT(x)
1333struct interpreter {
1334#else
1335#define IEXT EXT
1336#define IINIT(x) INIT(x)
1337#endif
1338
1339/* pseudo environmental stuff */
1340IEXT int Iorigargc;
1341IEXT char ** Iorigargv;
1342IEXT GV * Ienvgv;
1343IEXT GV * Isiggv;
1344IEXT GV * Iincgv;
1345IEXT char * Iorigfilename;
748a9306
LW
1346IEXT SV * Idiehook;
1347IEXT SV * Iwarnhook;
1348IEXT SV * Iparsehook;
79072805 1349
c07a80fd
PP
1350/* Various states of an input record separator SV (rs, nrs) */
1351#define RsSNARF(sv) (! SvOK(sv))
1352#define RsSIMPLE(sv) (SvOK(sv) && SvCUR(sv))
1353#define RsPARA(sv) (SvOK(sv) && ! SvCUR(sv))
1354
79072805
LW
1355/* switches */
1356IEXT char * Icddir;
1357IEXT bool Iminus_c;
a5f75d66 1358IEXT char Ipatchlevel[10];
728e2803 1359IEXT char ** Ilocalpatches;
c07a80fd 1360IEXT SV * Inrs;
2304df62 1361IEXT char * Isplitstr IINIT(" ");
79072805
LW
1362IEXT bool Ipreprocess;
1363IEXT bool Iminus_n;
1364IEXT bool Iminus_p;
1365IEXT bool Iminus_l;
1366IEXT bool Iminus_a;
2304df62 1367IEXT bool Iminus_F;
79072805
LW
1368IEXT bool Idoswitches;
1369IEXT bool Idowarn;
1370IEXT bool Idoextract;
79072805
LW
1371IEXT bool Isawampersand; /* must save all match strings */
1372IEXT bool Isawstudy; /* do fbm_instr on all strings */
1373IEXT bool Isawi; /* study must assume case insensitive */
1374IEXT bool Isawvec;
1375IEXT bool Iunsafe;
79072805
LW
1376IEXT char * Iinplace;
1377IEXT char * Ie_tmpname;
760ac839 1378IEXT PerlIO * Ie_fp;
79072805 1379IEXT U32 Iperldb;
748a9306
LW
1380 /* This value may be raised by extensions for testing purposes */
1381IEXT int Iperl_destruct_level; /* 0=none, 1=full, 2=full with checks */
79072805
LW
1382
1383/* magical thingies */
85e6fe83 1384IEXT Time_t Ibasetime; /* $^T */
79072805
LW
1385IEXT SV * Iformfeed; /* $^L */
1386IEXT char * Ichopset IINIT(" \n-"); /* $: */
c07a80fd 1387IEXT SV * Irs; /* $/ */
79072805 1388IEXT char * Iofs; /* $, */
8990e307 1389IEXT STRLEN Iofslen;
79072805 1390IEXT char * Iors; /* $\ */
8990e307 1391IEXT STRLEN Iorslen;
79072805
LW
1392IEXT char * Iofmt; /* $# */
1393IEXT I32 Imaxsysfd IINIT(MAXSYSFD); /* top fd to pass to subprocesses */
1394IEXT int Imultiline; /* $*--do strings hold >1 line? */
748a9306 1395IEXT U32 Istatusvalue; /* $? */
79072805
LW
1396
1397IEXT struct stat Istatcache; /* _ */
1398IEXT GV * Istatgv;
1399IEXT SV * Istatname IINIT(Nullsv);
1400
1401/* shortcuts to various I/O objects */
1402IEXT GV * Istdingv;
1403IEXT GV * Ilast_in_gv;
1404IEXT GV * Idefgv;
1405IEXT GV * Iargvgv;
1406IEXT GV * Idefoutgv;
79072805
LW
1407IEXT GV * Iargvoutgv;
1408
1409/* shortcuts to regexp stuff */
1410IEXT GV * Ileftgv;
1411IEXT GV * Iampergv;
1412IEXT GV * Irightgv;
1413IEXT PMOP * Icurpm; /* what to do \ interps from */
79072805
LW
1414IEXT I32 * Iscreamfirst;
1415IEXT I32 * Iscreamnext;
1416IEXT I32 Imaxscream IINIT(-1);
1417IEXT SV * Ilastscream;
1418
4633a7c4
LW
1419/* shortcuts to misc objects */
1420IEXT GV * Ierrgv;
1421
79072805
LW
1422/* shortcuts to debugging objects */
1423IEXT GV * IDBgv;
1424IEXT GV * IDBline;
1425IEXT GV * IDBsub;
1426IEXT SV * IDBsingle;
1427IEXT SV * IDBtrace;
1428IEXT SV * IDBsignal;
1429IEXT AV * Ilineary; /* lines of script for debugger */
1430IEXT AV * Idbargs; /* args to call listed by caller function */
1431
1432/* symbol tables */
1433IEXT HV * Idefstash; /* main symbol table */
1434IEXT HV * Icurstash; /* symbol table for current package */
1435IEXT HV * Idebstash; /* symbol table for perldb package */
1436IEXT SV * Icurstname; /* name of current package */
93a17b20
LW
1437IEXT AV * Ibeginav; /* names of BEGIN subroutines */
1438IEXT AV * Iendav; /* names of END subroutines */
0c30d9ec 1439IEXT HV * Istrtab; /* shared string table */
79072805
LW
1440
1441/* memory management */
79072805
LW
1442IEXT SV ** Itmps_stack;
1443IEXT I32 Itmps_ix IINIT(-1);
1444IEXT I32 Itmps_floor IINIT(-1);
8990e307
LW
1445IEXT I32 Itmps_max;
1446IEXT I32 Isv_count; /* how many SV* are currently allocated */
a0d0e21e 1447IEXT I32 Isv_objcount; /* how many objects are currently allocated */
8990e307
LW
1448IEXT SV* Isv_root; /* storage for SVs belonging to interp */
1449IEXT SV* Isv_arenaroot; /* list of areas for garbage collection */
79072805
LW
1450
1451/* funky return mechanisms */
1452IEXT I32 Ilastspbase;
1453IEXT I32 Ilastsize;
1454IEXT int Iforkprocess; /* so do_open |- can return proc# */
1455
1456/* subprocess state */
1457IEXT AV * Ifdpid; /* keep fd-to-pid mappings for my_popen */
1458IEXT HV * Ipidstatus; /* keep pid-to-status mappings for waitpid */
1459
1460/* internal state */
463ee0b2
LW
1461IEXT VOL int Iin_eval; /* trap "fatal" errors? */
1462IEXT OP * Irestartop; /* Are we propagating an error from croak? */
79072805 1463IEXT int Idelaymagic; /* ($<,$>) = ... */
2304df62 1464IEXT bool Idirty; /* In the middle of tearing things down? */
748a9306 1465IEXT U8 Ilocalizing; /* are we processing a local() list? */
79072805 1466IEXT bool Itainted; /* using variables controlled by $< */
463ee0b2 1467IEXT bool Itainting; /* doing taint checks */
e50aee73 1468IEXT char * Iop_mask IINIT(NULL); /* masked operations for safe evals */
79072805
LW
1469
1470/* trace state */
1471IEXT I32 Idlevel;
1472IEXT I32 Idlmax IINIT(128);
1473IEXT char * Idebname;
1474IEXT char * Idebdelim;
1475
1476/* current interpreter roots */
748a9306 1477IEXT CV * Imain_cv;
463ee0b2
LW
1478IEXT OP * Imain_root;
1479IEXT OP * Imain_start;
1480IEXT OP * Ieval_root;
1481IEXT OP * Ieval_start;
79072805
LW
1482
1483/* runtime control stuff */
1484IEXT COP * VOL Icurcop IINIT(&compiling);
0c30d9ec 1485IEXT COP * Icurcopdb IINIT(NULL);
79072805
LW
1486IEXT line_t Icopline IINIT(NOLINE);
1487IEXT CONTEXT * Icxstack;
1488IEXT I32 Icxstack_ix IINIT(-1);
1489IEXT I32 Icxstack_max IINIT(128);
a5f75d66 1490IEXT Sigjmp_buf Itop_env;
a0d0e21e 1491IEXT I32 Irunlevel;
79072805
LW
1492
1493/* stack stuff */
0c30d9ec 1494IEXT AV * Icurstack; /* THE STACK */
79072805
LW
1495IEXT AV * Imainstack; /* the stack when nothing funny is happening */
1496IEXT SV ** Imystack_base; /* stack->array_ary */
1497IEXT SV ** Imystack_sp; /* stack pointer now */
1498IEXT SV ** Imystack_max; /* stack->array_ary + stack->array_max */
1499
1500/* format accumulators */
463ee0b2
LW
1501IEXT SV * Iformtarget;
1502IEXT SV * Ibodytarget;
1503IEXT SV * Itoptarget;
79072805
LW
1504
1505/* statics moved here for shared library purposes */
93a17b20 1506IEXT SV Istrchop; /* return value from chop */
79072805
LW
1507IEXT int Ifilemode; /* so nextargv() can preserve mode */
1508IEXT int Ilastfd; /* what to preserve mode on */
1509IEXT char * Ioldname; /* what to preserve mode on */
1510IEXT char ** IArgv; /* stuff to free from do_aexec, vfork safe */
1511IEXT char * ICmd; /* stuff to free from do_aexec, vfork safe */
1512IEXT OP * Isortcop; /* user defined sort routine */
1513IEXT HV * Isortstash; /* which is in some package or other */
1514IEXT GV * Ifirstgv; /* $a */
1515IEXT GV * Isecondgv; /* $b */
1516IEXT AV * Isortstack; /* temp stack during pp_sort() */
1517IEXT AV * Isignalstack; /* temp stack during sighandler() */
1518IEXT SV * Imystrk; /* temp key string for do_each() */
1519IEXT I32 Idumplvl; /* indentation level on syntax tree dump */
79072805
LW
1520IEXT PMOP * Ioldlastpm; /* for saving regexp context during debugger */
1521IEXT I32 Igensym; /* next symbol for getsym() to define */
1522IEXT bool Ipreambled;
3c81428c 1523IEXT AV * Ipreambleav;
79072805
LW
1524IEXT int Ilaststatval IINIT(-1);
1525IEXT I32 Ilaststype IINIT(OP_STAT);
1526
1527#undef IEXT
1528#undef IINIT
1529
8990e307 1530#ifdef MULTIPLICITY
79072805
LW
1531};
1532#else
1533struct interpreter {
1534 char broiled;
1535};
1536#endif
1537
1538#include "pp.h"
1539
1540#ifdef __cplusplus
1541extern "C" {
1542#endif
1543
1544#include "proto.h"
1545
a0d0e21e
LW
1546#ifdef EMBED
1547#define Perl_sv_setptrobj(rv,ptr,name) Perl_sv_setref_iv(rv,name,(IV)ptr)
1548#define Perl_sv_setptrref(rv,ptr) Perl_sv_setref_iv(rv,Nullch,(IV)ptr)
1549#else
1550#define sv_setptrobj(rv,ptr,name) sv_setref_iv(rv,name,(IV)ptr)
1551#define sv_setptrref(rv,ptr) sv_setref_iv(rv,Nullch,(IV)ptr)
1552#endif
1553
79072805
LW
1554#ifdef __cplusplus
1555};
1556#endif
1557
93a17b20 1558/* The following must follow proto.h */
79072805
LW
1559
1560#ifdef DOINIT
4633a7c4 1561EXT MGVTBL vtbl_sv = {magic_get,
463ee0b2
LW
1562 magic_set,
1563 magic_len,
1564 0, 0};
4633a7c4
LW
1565EXT MGVTBL vtbl_env = {0, 0, 0, 0, 0};
1566EXT MGVTBL vtbl_envelem = {0, magic_setenv,
85e6fe83
LW
1567 0, magic_clearenv,
1568 0};
4633a7c4 1569EXT MGVTBL vtbl_sig = {0, 0, 0, 0, 0};
0c30d9ec
PP
1570EXT MGVTBL vtbl_sigelem = {magic_getsig,
1571 magic_setsig,
1572 0, magic_clearsig,
1573 0};
4633a7c4 1574EXT MGVTBL vtbl_pack = {0, 0, 0, magic_wipepack,
a0d0e21e 1575 0};
4633a7c4 1576EXT MGVTBL vtbl_packelem = {magic_getpack,
463ee0b2
LW
1577 magic_setpack,
1578 0, magic_clearpack,
1579 0};
4633a7c4 1580EXT MGVTBL vtbl_dbline = {0, magic_setdbline,
463ee0b2 1581 0, 0, 0};
4633a7c4 1582EXT MGVTBL vtbl_isa = {0, magic_setisa,
463ee0b2 1583 0, 0, 0};
4633a7c4 1584EXT MGVTBL vtbl_isaelem = {0, magic_setisa,
463ee0b2 1585 0, 0, 0};
4633a7c4 1586EXT MGVTBL vtbl_arylen = {magic_getarylen,
463ee0b2
LW
1587 magic_setarylen,
1588 0, 0, 0};
4633a7c4 1589EXT MGVTBL vtbl_glob = {magic_getglob,
463ee0b2
LW
1590 magic_setglob,
1591 0, 0, 0};
4633a7c4 1592EXT MGVTBL vtbl_mglob = {0, magic_setmglob,
463ee0b2 1593 0, 0, 0};
4633a7c4 1594EXT MGVTBL vtbl_taint = {magic_gettaint,magic_settaint,
463ee0b2 1595 0, 0, 0};
4633a7c4 1596EXT MGVTBL vtbl_substr = {0, magic_setsubstr,
463ee0b2 1597 0, 0, 0};
4633a7c4 1598EXT MGVTBL vtbl_vec = {0, magic_setvec,
463ee0b2 1599 0, 0, 0};
4633a7c4 1600EXT MGVTBL vtbl_pos = {magic_getpos,
a0d0e21e
LW
1601 magic_setpos,
1602 0, 0, 0};
4633a7c4 1603EXT MGVTBL vtbl_bm = {0, magic_setbm,
463ee0b2 1604 0, 0, 0};
4633a7c4 1605EXT MGVTBL vtbl_uvar = {magic_getuvar,
463ee0b2
LW
1606 magic_setuvar,
1607 0, 0, 0};
a0d0e21e
LW
1608
1609#ifdef OVERLOAD
4633a7c4 1610EXT MGVTBL vtbl_amagic = {0, magic_setamagic,
748a9306 1611 0, 0, magic_setamagic};
4633a7c4 1612EXT MGVTBL vtbl_amagicelem = {0, magic_setamagic,
748a9306 1613 0, 0, magic_setamagic};
a0d0e21e
LW
1614#endif /* OVERLOAD */
1615
79072805
LW
1616#else
1617EXT MGVTBL vtbl_sv;
1618EXT MGVTBL vtbl_env;
1619EXT MGVTBL vtbl_envelem;
1620EXT MGVTBL vtbl_sig;
1621EXT MGVTBL vtbl_sigelem;
463ee0b2
LW
1622EXT MGVTBL vtbl_pack;
1623EXT MGVTBL vtbl_packelem;
79072805 1624EXT MGVTBL vtbl_dbline;
463ee0b2
LW
1625EXT MGVTBL vtbl_isa;
1626EXT MGVTBL vtbl_isaelem;
79072805
LW
1627EXT MGVTBL vtbl_arylen;
1628EXT MGVTBL vtbl_glob;
93a17b20 1629EXT MGVTBL vtbl_mglob;
463ee0b2 1630EXT MGVTBL vtbl_taint;
79072805
LW
1631EXT MGVTBL vtbl_substr;
1632EXT MGVTBL vtbl_vec;
a0d0e21e 1633EXT MGVTBL vtbl_pos;
79072805
LW
1634EXT MGVTBL vtbl_bm;
1635EXT MGVTBL vtbl_uvar;
a0d0e21e
LW
1636
1637#ifdef OVERLOAD
1638EXT MGVTBL vtbl_amagic;
1639EXT MGVTBL vtbl_amagicelem;
1640#endif /* OVERLOAD */
1641
79072805 1642#endif
85e6fe83 1643
a0d0e21e
LW
1644#ifdef OVERLOAD
1645EXT long amagic_generation;
1646
748a9306 1647#define NofAMmeth 29
a0d0e21e
LW
1648#ifdef DOINIT
1649EXT char * AMG_names[NofAMmeth][2] = {
1650 {"fallback","abs"},
1651 {"bool", "nomethod"},
1652 {"\"\"", "0+"},
1653 {"+","+="},
1654 {"-","-="},
1655 {"*", "*="},
1656 {"/", "/="},
1657 {"%", "%="},
1658 {"**", "**="},
1659 {"<<", "<<="},
1660 {">>", ">>="},
748a9306
LW
1661 {"&", "&="},
1662 {"|", "|="},
1663 {"^", "^="},
a0d0e21e
LW
1664 {"<", "<="},
1665 {">", ">="},
1666 {"==", "!="},
1667 {"<=>", "cmp"},
1668 {"lt", "le"},
1669 {"gt", "ge"},
1670 {"eq", "ne"},
a0d0e21e
LW
1671 {"!", "~"},
1672 {"++", "--"},
1673 {"atan2", "cos"},
1674 {"sin", "exp"},
1675 {"log", "sqrt"},
1676 {"x","x="},
748a9306
LW
1677 {".",".="},
1678 {"=","neg"}
a0d0e21e
LW
1679};
1680#else
1681EXT char * AMG_names[NofAMmeth][2];
1682#endif /* def INITAMAGIC */
1683
1684struct am_table {
1685 long was_ok_sub;
1686 long was_ok_am;
1687 CV* table[NofAMmeth*2];
1688 long fallback;
1689};
1690typedef struct am_table AMT;
1691
1692#define AMGfallNEVER 1
1693#define AMGfallNO 2
1694#define AMGfallYES 3
1695
1696enum {
1697 fallback_amg, abs_amg,
1698 bool__amg, nomethod_amg,
1699 string_amg, numer_amg,
1700 add_amg, add_ass_amg,
1701 subtr_amg, subtr_ass_amg,
1702 mult_amg, mult_ass_amg,
1703 div_amg, div_ass_amg,
1704 mod_amg, mod_ass_amg,
1705 pow_amg, pow_ass_amg,
1706 lshift_amg, lshift_ass_amg,
1707 rshift_amg, rshift_ass_amg,
748a9306
LW
1708 band_amg, band_ass_amg,
1709 bor_amg, bor_ass_amg,
1710 bxor_amg, bxor_ass_amg,
a0d0e21e
LW
1711 lt_amg, le_amg,
1712 gt_amg, ge_amg,
1713 eq_amg, ne_amg,
1714 ncmp_amg, scmp_amg,
1715 slt_amg, sle_amg,
1716 sgt_amg, sge_amg,
1717 seq_amg, sne_amg,
a0d0e21e
LW
1718 not_amg, compl_amg,
1719 inc_amg, dec_amg,
1720 atan2_amg, cos_amg,
1721 sin_amg, exp_amg,
1722 log_amg, sqrt_amg,
1723 repeat_amg, repeat_ass_amg,
748a9306
LW
1724 concat_amg, concat_ass_amg,
1725 copy_amg, neg_amg
a0d0e21e
LW
1726};
1727#endif /* OVERLOAD */
1728
760ac839
LW
1729#if !defined(PERLIO_IS_STDIO) && defined(HAS_ATTRIBUTE)
1730/*
1731 * Now we have __attribute__ out of the way
1732 * Remap printf
1733 */
1734#define printf PerlIO_stdoutf
1735#endif
1736
85e6fe83 1737#endif /* Include guard */