📄 b.html
字号:
<?xml version="1.0" ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<!-- saved from url=(0017)http://localhost/ -->
<script language="JavaScript" src="../displayToc.js"></script>
<script language="JavaScript" src="../tocParas.js"></script>
<script language="JavaScript" src="../tocTab.js"></script>
<link rel="stylesheet" type="text/css" href="../scineplex.css">
<title>B - The Perl Compiler</title>
<link rel="stylesheet" href="../Active.css" type="text/css" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:" />
</head>
<body>
<script>writelinks('__top__',1);</script>
<h1><a>B - The Perl Compiler</a></h1>
<p><a name="__index__"></a></p>
<!-- INDEX BEGIN -->
<ul>
<li><a href="#name">NAME</a></li>
<li><a href="#synopsis">SYNOPSIS</a></li>
<li><a href="#description">DESCRIPTION</a></li>
<li><a href="#overview">OVERVIEW</a></li>
<li><a href="#utility_functions">Utility Functions</a></li>
<ul>
<li><a href="#functions_returning_b__sv__b__av__b__hv__and_b__cv_objects">Functions Returning <code>B::SV</code>, <code>B::AV</code>, <code>B::HV</code>, and <code>B::CV</code> objects</a></li>
<li><a href="#functions_for_examining_the_symbol_table">Functions for Examining the Symbol Table</a></li>
<li><a href="#functions_returning_b__op_objects_or_for_walking_op_trees">Functions Returning <code>B::OP</code> objects or for walking op trees</a></li>
<li><a href="#miscellaneous_utility_functions">Miscellaneous Utility Functions</a></li>
</ul>
<li><a href="#overview_of_classes">OVERVIEW OF CLASSES</a></li>
<ul>
<li><a href="#svrelated_classes">SV-RELATED CLASSES</a></li>
<li><a href="#b__sv_methods">B::SV Methods</a></li>
<li><a href="#b__iv_methods">B::IV Methods</a></li>
<li><a href="#b__nv_methods">B::NV Methods</a></li>
<li><a href="#b__rv_methods">B::RV Methods</a></li>
<li><a href="#b__pv_methods">B::PV Methods</a></li>
<li><a href="#b__pvmg_methods">B::PVMG Methods</a></li>
<li><a href="#b__magic_methods">B::MAGIC Methods</a></li>
<li><a href="#b__pvlv_methods">B::PVLV Methods</a></li>
<li><a href="#b__bm_methods">B::BM Methods</a></li>
<li><a href="#b__gv_methods">B::GV Methods</a></li>
<li><a href="#b__io_methods">B::IO Methods</a></li>
<li><a href="#b__av_methods">B::AV Methods</a></li>
<li><a href="#b__cv_methods">B::CV Methods</a></li>
<li><a href="#b__hv_methods">B::HV Methods</a></li>
<li><a href="#oprelated_classes">OP-RELATED CLASSES</a></li>
<li><a href="#b__op_methods">B::OP Methods</a></li>
<li><a href="#b__unop_method">B::UNOP METHOD</a></li>
<li><a href="#b__binop_method">B::BINOP METHOD</a></li>
<li><a href="#b__logop_method">B::LOGOP METHOD</a></li>
<li><a href="#b__listop_method">B::LISTOP METHOD</a></li>
<li><a href="#b__pmop_methods">B::PMOP Methods</a></li>
<li><a href="#b__svop_method">B::SVOP METHOD</a></li>
<li><a href="#b__padop_method">B::PADOP METHOD</a></li>
<li><a href="#b__pvop_method">B::PVOP METHOD</a></li>
<li><a href="#b__loop_methods">B::LOOP Methods</a></li>
<li><a href="#b__cop_methods">B::COP Methods</a></li>
</ul>
<li><a href="#author">AUTHOR</a></li>
</ul>
<!-- INDEX END -->
<hr />
<p>
</p>
<h1><a name="name">NAME</a></h1>
<p>B - The Perl Compiler</p>
<p>
</p>
<hr />
<h1><a name="synopsis">SYNOPSIS</a></h1>
<pre>
<span class="keyword">use</span> <span class="variable">B</span><span class="operator">;</span>
</pre>
<p>
</p>
<hr />
<h1><a name="description">DESCRIPTION</a></h1>
<p>The <code>B</code> module supplies classes which allow a Perl program to delve
into its own innards. It is the module used to implement the
"backends" of the Perl compiler. Usage of the compiler does not
require knowledge of this module: see the <em>O</em> module for the
user-visible part. The <code>B</code> module is of use to those who want to
write new compiler backends. This documentation assumes that the
reader knows a fair amount about perl's internals including such
things as SVs, OPs and the internal symbol table and syntax tree
of a program.</p>
<p>
</p>
<hr />
<h1><a name="overview">OVERVIEW</a></h1>
<p>The <code>B</code> module contains a set of utility functions for querying the
current state of the Perl interpreter; typically these functions
return objects from the B::SV and B::OP classes, or their derived
classes. These classes in turn define methods for querying the
resulting objects about their own internal state.</p>
<p>
</p>
<hr />
<h1><a name="utility_functions">Utility Functions</a></h1>
<p>The <code>B</code> module exports a variety of functions: some are simple
utility functions, others provide a Perl program with a way to
get an initial "handle" on an internal object.</p>
<p>
</p>
<h2><a name="functions_returning_b__sv__b__av__b__hv__and_b__cv_objects">Functions Returning <code>B::SV</code>, <code>B::AV</code>, <code>B::HV</code>, and <code>B::CV</code> objects</a></h2>
<p>For descriptions of the class hierarchy of these objects and the
methods that can be called on them, see below, <a href="#overview_of_classes">OVERVIEW OF CLASSES</a> and <a href="#svrelated_classes">SV-RELATED CLASSES</a>.</p>
<dl>
<dt><strong><a name="item_sv_undef">sv_undef</a></strong>
<dd>
<p>Returns the SV object corresponding to the C variable <a href="#item_sv_undef"><code>sv_undef</code></a>.</p>
</dd>
</li>
<dt><strong><a name="item_sv_yes">sv_yes</a></strong>
<dd>
<p>Returns the SV object corresponding to the C variable <a href="#item_sv_yes"><code>sv_yes</code></a>.</p>
</dd>
</li>
<dt><strong><a name="item_sv_no">sv_no</a></strong>
<dd>
<p>Returns the SV object corresponding to the C variable <a href="#item_sv_no"><code>sv_no</code></a>.</p>
</dd>
</li>
<dt><strong><a name="item_svref_2object"><code>svref_2object(SVREF)</code></a></strong>
<dd>
<p>Takes a reference to any Perl value, and turns the referred-to value
into an object in the appropriate B::OP-derived or B::SV-derived
class. Apart from functions such as <a href="#item_main_root"><code>main_root</code></a>, this is the primary
way to get an initial "handle" on an internal perl data structure
which can then be followed with the other access methods.</p>
</dd>
<dd>
<p>The returned object will only be valid as long as the underlying OPs
and SVs continue to exist. Do not attempt to use the object after the
underlying structures are freed.</p>
</dd>
</li>
<dt><strong><a name="item_amagic_generation">amagic_generation</a></strong>
<dd>
<p>Returns the SV object corresponding to the C variable <a href="#item_amagic_generation"><code>amagic_generation</code></a>.</p>
</dd>
</li>
<dt><strong><a name="item_init_av">init_av</a></strong>
<dd>
<p>Returns the AV object (i.e. in class B::AV) representing INIT blocks.</p>
</dd>
</li>
<dt><strong><a name="item_check_av">check_av</a></strong>
<dd>
<p>Returns the AV object (i.e. in class B::AV) representing CHECK blocks.</p>
</dd>
</li>
<dt><strong><a name="item_begin_av">begin_av</a></strong>
<dd>
<p>Returns the AV object (i.e. in class B::AV) representing BEGIN blocks.</p>
</dd>
</li>
<dt><strong><a name="item_end_av">end_av</a></strong>
<dd>
<p>Returns the AV object (i.e. in class B::AV) representing END blocks.</p>
</dd>
</li>
<dt><strong><a name="item_comppadlist">comppadlist</a></strong>
<dd>
<p>Returns the AV object (i.e. in class B::AV) of the global comppadlist.</p>
</dd>
</li>
<dt><strong><a name="item_regex_padav">regex_padav</a></strong>
<dd>
<p>Only when perl was compiled with ithreads.</p>
</dd>
</li>
<dt><strong><a name="item_main_cv">main_cv</a></strong>
<dd>
<p>Return the (faked) CV corresponding to the main part of the Perl
program.</p>
</dd>
</li>
</dl>
<p>
</p>
<h2><a name="functions_for_examining_the_symbol_table">Functions for Examining the Symbol Table</a></h2>
<dl>
<dt><strong><a name="item_walksymtable">walksymtable(SYMREF, METHOD, RECURSE, PREFIX)</a></strong>
<dd>
<p>Walk the symbol table starting at SYMREF and call METHOD on each
symbol (a B::GV object) visited. When the walk reaches package
symbols (such as "Foo::") it invokes RECURSE, passing in the symbol
name, and only recurses into the package if that sub returns true.</p>
</dd>
<dd>
<p>PREFIX is the name of the SYMREF you're walking.</p>
</dd>
<dd>
<p>For example:</p>
</dd>
<dd>
<pre>
<span class="comment"># Walk CGI's symbol table calling print_subs on each symbol.</span>
<span class="comment"># Recurse only into CGI::Util::</span>
<span class="variable">walksymtable</span><span class="operator">(\</span><span class="variable">%CGI::,</span> <span class="string">'print_subs'</span><span class="operator">,</span> <span class="keyword">sub</span><span class="variable"> </span><span class="operator">{</span> <span class="variable">$_</span><span class="operator">[</span><span class="number">0</span><span class="operator">]</span> <span class="keyword">eq</span> <span class="string">'CGI::Util::'</span> <span class="operator">},</span>
<span class="string">'CGI::'</span><span class="operator">);</span>
</pre>
</dd>
<dd>
<p><code>print_subs()</code> is a B::GV method you have declared. Also see <a href="#b__gv_methods">B::GV Methods</a>, below.</p>
</dd>
</li>
</dl>
<p>
</p>
<h2><a name="functions_returning_b__op_objects_or_for_walking_op_trees">Functions Returning <code>B::OP</code> objects or for walking op trees</a></h2>
<p>For descriptions of the class hierarchy of these objects and the
methods that can be called on them, see below, <a href="#overview_of_classes">OVERVIEW OF CLASSES</a> and <a href="#oprelated_classes">OP-RELATED CLASSES</a>.</p>
<dl>
<dt><strong><a name="item_main_root">main_root</a></strong>
<dd>
<p>Returns the root op (i.e. an object in the appropriate B::OP-derived
class) of the main part of the Perl program.</p>
</dd>
</li>
<dt><strong><a name="item_main_start">main_start</a></strong>
<dd>
<p>Returns the starting op of the main part of the Perl program.</p>
</dd>
</li>
<dt><strong><a name="item_walkoptree">walkoptree(OP, METHOD)</a></strong>
<dd>
<p>Does a tree-walk of the syntax tree based at OP and calls METHOD on
each op it visits. Each node is visited before its children. If
<a href="#item_walkoptree_debug"><code>walkoptree_debug</code></a> (see below) has been called to turn debugging on then
the method <a href="#item_walkoptree_debug"><code>walkoptree_debug</code></a> is called on each op before METHOD is
called.</p>
</dd>
</li>
<dt><strong><a name="item_walkoptree_debug"><code>walkoptree_debug(DEBUG)</code></a></strong>
<dd>
<p>Returns the current debugging flag for <a href="#item_walkoptree"><code>walkoptree</code></a>. If the optional
DEBUG argument is non-zero, it sets the debugging flag to that. See
the description of <a href="#item_walkoptree"><code>walkoptree</code></a> above for what the debugging flag
does.</p>
</dd>
</li>
</dl>
<p>
</p>
<h2><a name="miscellaneous_utility_functions">Miscellaneous Utility Functions</a></h2>
<dl>
<dt><strong><a name="item_ppname"><code>ppname(OPNUM)</code></a></strong>
<dd>
<p>Return the PP function name (e.g. "pp_add") of op number OPNUM.</p>
</dd>
</li>
<dt><strong><a name="item_hash"><code>hash(STR)</code></a></strong>
<dd>
<p>Returns a string in the form "0x..." representing the value of the
internal hash function used by perl on string STR.</p>
</dd>
</li>
<dt><strong><a name="item_cast_i32"><code>cast_I32(I)</code></a></strong>
<dd>
<p>Casts I to the internal I32 type used by that perl.</p>
</dd>
</li>
<dt><strong><a name="item_minus_c">minus_c</a></strong>
<dd>
<p>Does the equivalent of the <a href="../lib/Pod/perlrun.html#item__2dc"><code>-c</code></a> command-line option. Obviously, this
is only useful in a BEGIN block or else the flag is set too late.</p>
</dd>
</li>
<dt><strong><a name="item_cstring"><code>cstring(STR)</code></a></strong>
<dd>
<p>Returns a double-quote-surrounded escaped version of STR which can
be used as a string in C source code.</p>
</dd>
</li>
<dt><strong><a name="item_perlstring"><code>perlstring(STR)</code></a></strong>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -