This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
initial stub implementation of implicit thread/this
[perl5.git] / embed.pl
CommitLineData
5f05dabc 1#!/usr/bin/perl -w
e50aee73 2
5f05dabc 3require 5.003;
4
709f4e38
GS
5# XXX others that may need adding
6# warnhook
7# hints
8# copline
84fee439
NIS
9my @extvars = qw(sv_undef sv_yes sv_no na dowarn
10 curcop compiling
11 tainting tainted stack_base stack_sp sv_arenaroot
256a4781 12 no_modify
84fee439
NIS
13 curstash DBsub DBsingle debstash
14 rsfp
15 stdingv
6b88bc9c
GS
16 defgv
17 errgv
3070f6ec
GS
18 rsfp_filters
19 perldb
709f4e38
GS
20 diehook
21 dirty
22 perl_destruct_level
84fee439
NIS
23 );
24
5f05dabc 25sub readsyms (\%$) {
26 my ($syms, $file) = @_;
5f05dabc 27 local (*FILE, $_);
28 open(FILE, "< $file")
29 or die "embed.pl: Can't open $file: $!\n";
30 while (<FILE>) {
31 s/[ \t]*#.*//; # Delete comments.
32 if (/^\s*(\S+)\s*$/) {
22c35a8c
GS
33 my $sym = $1;
34 warn "duplicate symbol $sym while processing $file\n"
35 if exists $$syms{$sym};
36 $$syms{$sym} = 1;
5f05dabc 37 }
38 }
39 close(FILE);
40}
41
42readsyms %global, 'global.sym';
22c35a8c 43readsyms %global, 'pp.sym';
5f05dabc 44
c6af7a1a
GS
45sub readvars(\%$$@) {
46 my ($syms, $file,$pre,$keep_pre) = @_;
d4cce5f1
NIS
47 local (*FILE, $_);
48 open(FILE, "< $file")
49 or die "embed.pl: Can't open $file: $!\n";
50 while (<FILE>) {
51 s/[ \t]*#.*//; # Delete comments.
3fe35a81 52 if (/PERLVARI?C?\($pre(\w+)/) {
22c35a8c 53 my $sym = $1;
c6af7a1a 54 $sym = $pre . $sym if $keep_pre;
22c35a8c
GS
55 warn "duplicate symbol $sym while processing $file\n"
56 if exists $$syms{$sym};
57 $$syms{$sym} = 1;
d4cce5f1
NIS
58 }
59 }
60 close(FILE);
61}
62
63my %intrp;
64my %thread;
65
66readvars %intrp, 'intrpvar.h','I';
67readvars %thread, 'thrdvar.h','T';
22239a37 68readvars %globvar, 'perlvars.h','G';
c6af7a1a 69readvars %objvar, 'intrpvar.h','pi', 1;
d4cce5f1
NIS
70
71foreach my $sym (sort keys %intrp)
72 {
d4cce5f1
NIS
73 if (exists $global{$sym})
74 {
75 delete $global{$sym};
22c35a8c 76 warn "$sym in {global,pp}.sym as well as intrpvar.h\n";
d4cce5f1
NIS
77 }
78 }
79
22239a37
NIS
80foreach my $sym (sort keys %globvar)
81 {
82 if (exists $global{$sym})
83 {
84 delete $global{$sym};
22c35a8c 85 warn "$sym in {global,pp}.sym as well as perlvars.h\n";
22239a37
NIS
86 }
87 }
88
d4cce5f1
NIS
89foreach my $sym (sort keys %thread)
90 {
34b58025 91 warn "$sym in intrpvar.h as well as thrdvar.h\n" if exists $intrp{$sym};
d4cce5f1
NIS
92 if (exists $global{$sym})
93 {
94 delete $global{$sym};
22c35a8c 95 warn "$sym in {global,pp}.sym as well as thrdvar.h\n";
d4cce5f1
NIS
96 }
97 }
98
c6af7a1a
GS
99sub undefine ($) {
100 my ($sym) = @_;
101 "#undef $sym\n";
102}
103
5f05dabc 104sub hide ($$) {
105 my ($from, $to) = @_;
106 my $t = int(length($from) / 8);
107 "#define $from" . "\t" x ($t < 3 ? 3 - $t : 1) . "$to\n";
108}
c6af7a1a 109
5f05dabc 110sub embed ($) {
111 my ($sym) = @_;
864dbfa3
GS
112 my $def = $sym;
113 hide($def, $sym) if $def =~ s/^Perl_//;
5f05dabc 114}
c6af7a1a 115
22c35a8c
GS
116sub embedobj ($) {
117 my ($sym) = @_;
118 hide($sym, $sym =~ /^perl_/i ? "CPerlObj::$sym" : "CPerlObj::Perl_$sym");
119}
c6af7a1a
GS
120
121sub objxsub_func ($) {
122 my ($sym) = @_;
123 undefine($sym) . hide($sym, $sym =~ /^perl_/i
124 ? "pPerl->$sym"
125 : "pPerl->Perl_$sym");
126}
127
128sub objxsub_var ($) {
129 my ($sym) = @_;
130 undefine("PL_$sym") . hide("PL_$sym", "pPerl->PL_$sym");
131}
132
3280af22
NIS
133sub embedvar ($) {
134 my ($sym) = @_;
135# hide($sym, "Perl_$sym");
136 return '';
137}
138
d4cce5f1
NIS
139sub multon ($$$) {
140 my ($sym,$pre,$ptr) = @_;
3280af22 141 hide("PL_$sym", "($ptr$pre$sym)");
5f05dabc 142}
d4cce5f1
NIS
143sub multoff ($$) {
144 my ($sym,$pre) = @_;
533c011a 145 return hide("PL_$pre$sym", "PL_$sym");
5f05dabc 146}
147
148unlink 'embed.h';
149open(EM, '> embed.h')
150 or die "Can't create embed.h: $!\n";
e50aee73
AD
151
152print EM <<'END';
76b72cf1 153/* !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
22c35a8c 154 This file is built by embed.pl from global.sym, pp.sym, intrpvar.h,
c6af7a1a 155 perlvars.h and thrdvar.h. Any changes made here will be lost!
76b72cf1 156*/
e50aee73
AD
157
158/* (Doing namespace management portably in C is really gross.) */
159
22c35a8c 160/* NO_EMBED is no longer supported. i.e. EMBED is always active. */
820c3be9 161
22c35a8c 162/* Hide global symbols */
5f05dabc 163
22c35a8c 164#if !defined(PERL_OBJECT)
e50aee73 165
e50aee73
AD
166END
167
5f05dabc 168for $sym (sort keys %global) {
864dbfa3 169 next if $sym =~ /^Perl_(malloc|calloc|realloc|mfree)$/;
dc86dda3 170 print EM embed($sym);
e50aee73
AD
171}
172
e50aee73
AD
173print EM <<'END';
174
22c35a8c
GS
175#else /* PERL_OBJECT */
176
177END
178
179# XXX these should be in a *.sym file
c6af7a1a 180my @staticfuncs = qw(
22c35a8c
GS
181 perl_init_i18nl10n
182 perl_init_i18nl14n
183 perl_new_collate
184 perl_new_ctype
185 perl_new_numeric
186 perl_set_numeric_local
187 perl_set_numeric_standard
188 perl_construct
189 perl_destruct
190 perl_atexit
191 perl_free
192 perl_parse
193 perl_run
194 perl_get_sv
195 perl_get_av
196 perl_get_hv
197 perl_get_cv
198 perl_call_argv
199 perl_call_pv
200 perl_call_method
201 perl_call_sv
202 perl_eval_pv
203 perl_eval_sv
204 perl_require_pv
205
206 hsplit
207 hfreeentries
208 more_he
209 new_he
210 del_he
211 save_hek
212 mess_alloc
213 gv_init_sv
214 save_scalar_at
215 asIV
216 asUV
217 more_sv
218 more_xiv
219 more_xnv
220 more_xpv
221 more_xrv
222 new_xiv
223 new_xnv
224 new_xpv
225 new_xrv
226 del_xiv
227 del_xnv
228 del_xpv
229 del_xrv
22c35a8c 230 sv_unglob
22c35a8c
GS
231 avhv_index_sv
232 do_report_used
233 do_clean_objs
234 do_clean_named_objs
235 do_clean_all
236 not_a_number
237 my_safemalloc
238 visit
239 qsortsv
240 sortcv
241 save_magic
242 magic_methpack
243 magic_methcall
244 magic_methcall
245 doform
246 doencodes
247 refto
248 seed
249 docatch
a6c40364
GS
250 docatch_body
251 perl_parse_body
252 perl_run_body
253 perl_call_body
254 perl_call_xbody
255 call_list_body
22c35a8c
GS
256 dofindlabel
257 doparseform
258 dopoptoeval
259 dopoptolabel
260 dopoptoloop
261 dopoptosub
262 dopoptosub_at
067f92a0 263 free_closures
22c35a8c
GS
264 save_lines
265 doeval
a6c40364 266 doopen_pmc
bda4119b
GS
267 sv_ncmp
268 sv_i_ncmp
269 amagic_ncmp
270 amagic_i_ncmp
22c35a8c
GS
271 amagic_cmp
272 amagic_cmp_locale
273 mul128
274 is_an_int
275 div128
22c35a8c
GS
276 check_uni
277 force_next
278 force_version
279 force_word
280 tokeq
281 scan_const
282 scan_formline
283 scan_heredoc
284 scan_ident
285 scan_inputsymbol
286 scan_pat
287 scan_str
288 scan_subst
289 scan_trans
290 scan_word
291 skipspace
292 checkcomma
293 force_ident
294 incline
295 intuit_method
296 intuit_more
297 lop
298 missingterm
299 no_op
300 set_csh
301 sublex_done
302 sublex_push
303 sublex_start
304 uni
305 filter_gets
306 new_constant
307 ao
308 depcom
309 win32_textfilter
310 incl_perldb
311 isa_lookup
312 get_db_sub
313 list_assignment
314 bad_type
315 modkids
316 no_fh_allowed
7a52d87a 317 no_bareword_allowed
22c35a8c
GS
318 scalarboolean
319 too_few_arguments
320 too_many_arguments
321 null
322 pad_findlex
323 newDEFSVOP
324 gv_ename
325 cv_clone2
326 find_beginning
327 forbid_setid
328 incpush
329 init_interp
330 init_ids
331 init_debugger
332 init_lexer
333 init_main_stash
334 init_perllib
335 init_postdump_symbols
336 init_predump_symbols
337 my_exit_jump
338 nuke_stacks
339 open_script
340 usage
341 validate_suid
342 emulate_eaccess
343 reg
344 reganode
345 regatom
346 regbranch
347 regc
348 reguni
349 regclass
350 regclassutf8
351 regcurly
352 reg_node
353 regpiece
354 reginsert
355 regoptail
356 regset
357 regtail
358 regwhite
359 nextchar
360 dumpuntil
361 scan_commit
362 study_chunk
363 add_data
364 re_croak2
eb1ab10a 365 regpposixcc
4327152a 366 clear_re
22c35a8c
GS
367 regmatch
368 regrepeat
369 regrepeat_hard
370 regtry
371 reginclass
372 reginclassutf8
373 regcppush
374 regcppop
375 regcp_set_to
376 cache_re
9661b544 377 restore_pos
22c35a8c
GS
378 reghop
379 reghopmaybe
380 dump
381 do_aspawn
382 debprof
22c35a8c 383 new_logop
bda4119b 384 simplify_sort
35cd451c 385 is_handle_constructor
810b8aa5
GS
386 sv_add_backref
387 sv_del_backref
22c35a8c
GS
388 do_trans_CC_simple
389 do_trans_CC_count
390 do_trans_CC_complex
391 do_trans_UU_simple
392 do_trans_UU_count
393 do_trans_UU_complex
394 do_trans_UC_simple
395 do_trans_CU_simple
396 do_trans_UC_trivial
397 do_trans_CU_trivial
398 unwind_handler_stack
399 restore_magic
400 restore_rsfp
401 restore_expect
402 restore_lex_expect
22c35a8c 403 del_sv
22c35a8c
GS
404);
405
c6af7a1a 406for $sym (sort(keys(%global),@staticfuncs)) {
864dbfa3 407 next if $sym =~ /^Perl_(malloc|calloc|realloc|mfree)$/;
22c35a8c
GS
408 print EM embedobj($sym);
409}
410
411print EM <<'END';
412
413#endif /* PERL_OBJECT */
e50aee73 414
db5cf5a9
GS
415/* compatibility stubs */
416
417#define sv_setptrobj(rv,ptr,name) sv_setref_iv(rv,name,(IV)ptr)
418#define sv_setptrref(rv,ptr) sv_setref_iv(rv,Nullch,(IV)ptr)
864dbfa3
GS
419#define perl_atexit call_atexit
420#define perl_call_argv call_argv
421#define perl_call_pv call_pv
422#define perl_call_method call_method
423#define perl_call_sv call_sv
424#define perl_eval_sv eval_sv
425#define perl_eval_pv eval_pv
426#define perl_require_pv require_pv
427#define perl_get_sv get_sv
428#define perl_get_av get_av
429#define perl_get_hv get_hv
430#define perl_get_cv get_cv
431#define perl_init_i18nl10n init_i18nl10n
432#define perl_init_i18nl14n init_i18nl14n
433#define perl_new_ctype new_ctype
434#define perl_new_collate new_collate
435#define perl_new_numeric new_numeric
db5cf5a9 436
d4cce5f1
NIS
437END
438
439close(EM);
440
441unlink 'embedvar.h';
442open(EM, '> embedvar.h')
443 or die "Can't create embedvar.h: $!\n";
444
445print EM <<'END';
446/* !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
22c35a8c 447 This file is built by embed.pl from global.sym, pp.sym, intrpvar.h,
c6af7a1a 448 perlvars.h and thrdvar.h. Any changes made here will be lost!
d4cce5f1
NIS
449*/
450
451/* (Doing namespace management portably in C is really gross.) */
452
5f05dabc 453/* Put interpreter-specific symbols into a struct? */
e50aee73
AD
454
455#ifdef MULTIPLICITY
456
d4cce5f1
NIS
457#ifndef USE_THREADS
458/* If we do not have threads then per-thread vars are per-interpreter */
459
e50aee73
AD
460END
461
d4cce5f1 462for $sym (sort keys %thread) {
8f872242 463 print EM multon($sym,'T','PL_curinterp->');
d4cce5f1
NIS
464}
465
466print EM <<'END';
467
468#endif /* !USE_THREADS */
469
470/* These are always per-interpreter if there is more than one */
471
472END
473
474for $sym (sort keys %intrp) {
8f872242 475 print EM multon($sym,'I','PL_curinterp->');
760ac839 476}
760ac839 477
55497cff 478print EM <<'END';
479
5f05dabc 480#else /* !MULTIPLICITY */
55497cff 481
482END
760ac839 483
d4cce5f1
NIS
484for $sym (sort keys %intrp) {
485 print EM multoff($sym,'I');
e50aee73 486}
e50aee73 487
56d28764
CS
488print EM <<'END';
489
d4cce5f1
NIS
490#ifndef USE_THREADS
491
492END
493
494for $sym (sort keys %thread) {
495 print EM multoff($sym,'T');
496}
497
498print EM <<'END';
499
500#endif /* USE_THREADS */
501
502/* Hide what would have been interpreter-specific symbols? */
5f05dabc 503
56d28764 504END
e50aee73 505
d4cce5f1 506for $sym (sort keys %intrp) {
3280af22 507 print EM embedvar($sym);
d4cce5f1
NIS
508}
509
510print EM <<'END';
511
512#ifndef USE_THREADS
513
514END
515
516for $sym (sort keys %thread) {
3280af22 517 print EM embedvar($sym);
5f05dabc 518}
519
520print EM <<'END';
521
d4cce5f1 522#endif /* USE_THREADS */
e50aee73 523#endif /* MULTIPLICITY */
d4cce5f1
NIS
524
525/* Now same trickey for per-thread variables */
526
527#ifdef USE_THREADS
528
529END
530
531for $sym (sort keys %thread) {
22239a37 532 print EM multon($sym,'T','thr->');
d4cce5f1
NIS
533}
534
535print EM <<'END';
536
537#endif /* USE_THREADS */
538
22239a37
NIS
539#ifdef PERL_GLOBAL_STRUCT
540
541END
542
543for $sym (sort keys %globvar) {
533c011a 544 print EM multon($sym,'G','PL_Vars.');
22239a37
NIS
545}
546
547print EM <<'END';
548
549#else /* !PERL_GLOBAL_STRUCT */
550
551END
552
553for $sym (sort keys %globvar) {
554 print EM multoff($sym,'G');
555}
556
557print EM <<'END';
558
22239a37
NIS
559END
560
561for $sym (sort keys %globvar) {
3280af22 562 print EM embedvar($sym);
22239a37
NIS
563}
564
565print EM <<'END';
566
22239a37
NIS
567#endif /* PERL_GLOBAL_STRUCT */
568
e50aee73
AD
569END
570
84fee439
NIS
571print EM <<'END';
572
db5cf5a9 573#ifdef PERL_POLLUTE /* disabled by default in 5.006 */
84fee439
NIS
574
575END
576
577for $sym (sort @extvars) {
578 print EM hide($sym,"PL_$sym");
579}
580
581print EM <<'END';
582
db5cf5a9 583#endif /* PERL_POLLUTE */
84fee439
NIS
584END
585
586
3fe35a81 587close(EM);
c6af7a1a
GS
588
589unlink 'objXSUB.h';
590open(OBX, '> objXSUB.h')
591 or die "Can't create objXSUB.h: $!\n";
592
593print OBX <<'EOT';
594/* !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
595 This file is built by embed.pl from global.sym, pp.sym, intrpvar.h,
596 perlvars.h and thrdvar.h. Any changes made here will be lost!
597*/
598
599#ifndef __objXSUB_h__
600#define __objXSUB_h__
601
602/* Variables */
603
604EOT
605
606foreach my $sym (sort(keys(%intrp),
607 keys(%thread),
608 keys(%globvar),
609 keys(%objvar)))
610{
611 print OBX objxsub_var($sym);
612}
613
614print OBX <<'EOT';
615
616/* Functions */
617
618EOT
619
620
621for $sym (sort(keys(%global),@staticfuncs)) {
622 print OBX objxsub_func($sym);
623}
624
625
626print OBX <<'EOT';
627
628#endif /* __objXSUB_h__ */
629EOT
630
631close(OBX);