/
vtable_extend.pl
167 lines (115 loc) · 3.65 KB
/
vtable_extend.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#! perl
use strict;
use warnings;
use lib 'lib';
use Parrot::Vtable;
my $tbl = 'src/vtable.tbl';
my $vtable = parse_vtable( $tbl );
my ( $funcs, $protos ) = vtbl_embed($vtable);
my $header = <<"EOH";
/* ex: set ro:
** !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
**
** This file is generated automatically from $tbl by
** tools/build/vtable_extend.pl
*/
EOH
open my $OUT, '>', 'include/parrot/extend_vtable.h' or die $!;
print $OUT $header, <<'EOF';
/*
Copyright (C) 2005-2011, Parrot Foundation.
*/
#ifndef PARROT_EXTEND_VTABLE_H_GUARD
#define PARROT_EXTEND_VTABLE_H_GUARD
/* Need size_t */
#include <stddef.h>
EOF
print $OUT $protos;
print $OUT <<'EOF';
#endif /* PARROT_EXTEND_VTABLE_H_GUARD */
EOF
# append the C code coda
print $OUT <<'EOF';
/*
* Local variables:
* c-file-style: "parrot"
* buffer-read-only: t
* End:
* vim: expandtab shiftwidth=4:
*/
EOF
close $OUT or die $!;
open $OUT, '>', 'src/extend_vtable.c' or die $!;
print $OUT $header, <<'EOF';
/*
Copyright (C) 2001-2011, Parrot Foundation.
=head1 NAME
src/extend_vtable.c - Parrot vtable extension interface
=head1 DESCRIPTION
These are the functions that Parrot extensions (that is, Parrot subroutines
written in C, or some other compiled language, rather than in Parrot
bytecode) may access.
There is a deliberate distancing from the internals here. Don't go
peeking inside -- you've as much access as bytecode does, but no more,
so we can provide backwards compatibility for as long as we possibly
can.
=head2 Functions
=over 4
=cut
*/
/* HEADERIZER HFILE: none */
/* HEADERIZER STOP */
/* Some internal notes. Parrot will die a horrible and bizarre death
if the stack start pointer's not set and a GC run is
triggered. The pointer *will* be set by the interpreter if the
interpreter calls code which calls these functions, so most
extension code is safe, no problem.
The problem comes in if these routines are called from *outside*
an interpreter. This happens when an embedding application calls
them to do stuff with PMCs, STRINGS, interpreter contents, and
suchlike things. This is perfectly legal -- in fact it's what
we've documented should be done -- but the problem is that the
stack base pointer will be NULL. This is Very Bad.
To deal with this there are two macros that are defined to handle
the problem.
PARROT_CALLIN_START(interpreter) will figure out if the stack
anchor needs setting and, if so, will set it. It must *always*
come immediately after the last variable declared in the block
making the calls into the interpreter, as it declares a variable
and has some code.
PARROT_CALLIN_END(interpreter) will put the stack anchor back to
the way it was, and should always be the last statement before a
return. (If you have multiple returns have it in multiple times)
Not doing this is a good way to introduce bizarre heisenbugs, so
just do it. This is the only place they ought to have to be put
in, and most of the functions are already written, so it's not
like it's an onerous requirement.
*/
#include "parrot/parrot.h"
#include "parrot/extend.h"
/* HEADERIZER HFILE: none */ /* XXX Ideally the headerizer can run on this file as well. */
EOF
print $OUT $funcs;
print $OUT <<'EOF';
/*
=back
=head1 SEE ALSO
See F<include/parrot/extend.h>, F<docs/extend.pod>, F<docs/embed.pod> and F<docs/pdds/pdd11_extending.pod>.
=head1 HISTORY
Initial version by Dan Sugalski.
=cut
*/
/*
* Local variables:
* c-file-style: "parrot"
* End:
* vim: expandtab shiftwidth=4:
*/
EOF
close $OUT or die $!;
# Local Variables:
# mode: cperl
# cperl-indent-level: 4
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4: