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