⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 concise.html

📁 perl教程
💻 HTML
📖 第 1 页 / 共 3 页
字号:
<dt><strong><a name="item__23flagval"><strong>#flagval</strong></a></strong>

<dd>
<p>The numeric value of the OP's flags.</p>
</dd>
</li>
<dt><strong><a name="item__23hyphseq"><strong>#hyphseq</strong></a></strong>

<dd>
<p>The sequence number of the OP, or a hyphen if it doesn't have one.</p>
</dd>
</li>
<dt><strong><a name="item__23label"><strong>#label</strong></a></strong>

<dd>
<p>'NEXT', 'LAST', or 'REDO' if the OP is a target of one of those in exec
mode, or empty otherwise.</p>
</dd>
</li>
<dt><strong><a name="item__23lastaddr"><strong>#lastaddr</strong></a></strong>

<dd>
<p>The address of the OP's last child, in hexadecimal.</p>
</dd>
</li>
<dt><strong><a name="item__23name"><strong>#name</strong></a></strong>

<dd>
<p>The OP's name.</p>
</dd>
</li>
<dt><strong><a name="item__23name"><strong>#NAME</strong></a></strong>

<dd>
<p>The OP's name, in all caps.</p>
</dd>
</li>
<dt><strong><a name="item__23next"><strong>#next</strong></a></strong>

<dd>
<p>The sequence number of the OP's next OP.</p>
</dd>
</li>
<dt><strong><a name="item__23nextaddr"><strong>#nextaddr</strong></a></strong>

<dd>
<p>The address of the OP's next OP, in hexadecimal.</p>
</dd>
</li>
<dt><strong><a name="item__23noise"><strong>#noise</strong></a></strong>

<dd>
<p>A one- or two-character abbreviation for the OP's name.</p>
</dd>
</li>
<dt><strong><a name="item__23private"><strong>#private</strong></a></strong>

<dd>
<p>The OP's private flags, rendered with abbreviated names if possible.</p>
</dd>
</li>
<dt><strong><a name="item__23privval"><strong>#privval</strong></a></strong>

<dd>
<p>The numeric value of the OP's private flags.</p>
</dd>
</li>
<dt><strong><a name="item__23seq"><strong>#seq</strong></a></strong>

<dd>
<p>The sequence number of the OP. Note that this is a sequence number
generated by B::Concise.</p>
</dd>
</li>
<dt><strong><a name="item__23seqnum"><strong>#seqnum</strong></a></strong>

<dd>
<p>5.8.x and earlier only. 5.9 and later do not provide this.</p>
</dd>
<dd>
<p>The real sequence number of the OP, as a regular number and not adjusted
to be relative to the start of the real program. (This will generally be
a fairly large number because all of <strong>B::Concise</strong> is compiled before
your program is).</p>
</dd>
</li>
<dt><strong><a name="item__23opt"><strong>#opt</strong></a></strong>

<dd>
<p>Whether or not the op has been optimised by the peephole optimiser.</p>
</dd>
<dd>
<p>Only available in 5.9 and later.</p>
</dd>
</li>
<dt><strong><a name="item__23static"><strong>#static</strong></a></strong>

<dd>
<p>Whether or not the op is statically defined.  This flag is used by the
B::C compiler backend and indicates that the op should not be freed.</p>
</dd>
<dd>
<p>Only available in 5.9 and later.</p>
</dd>
</li>
<dt><strong><a name="item__23sibaddr"><strong>#sibaddr</strong></a></strong>

<dd>
<p>The address of the OP's next youngest sibling, in hexadecimal.</p>
</dd>
</li>
<dt><strong><a name="item__23svaddr"><strong>#svaddr</strong></a></strong>

<dd>
<p>The address of the OP's SV, if it has an SV, in hexadecimal.</p>
</dd>
</li>
<dt><strong><a name="item__23svclass"><strong>#svclass</strong></a></strong>

<dd>
<p>The class of the OP's SV, if it has one, in all caps (e.g., 'IV').</p>
</dd>
</li>
<dt><strong><a name="item__23svval"><strong>#svval</strong></a></strong>

<dd>
<p>The value of the OP's SV, if it has one, in a short human-readable format.</p>
</dd>
</li>
<dt><strong><a name="item__23targ"><strong>#targ</strong></a></strong>

<dd>
<p>The numeric value of the OP's targ.</p>
</dd>
</li>
<dt><strong><a name="item__23targarg"><strong>#targarg</strong></a></strong>

<dd>
<p>The name of the variable the OP's targ refers to, if any, otherwise the
letter t followed by the OP's targ in decimal.</p>
</dd>
</li>
<dt><strong><a name="item__23targarglife"><strong>#targarglife</strong></a></strong>

<dd>
<p>Same as <strong>#targarg</strong>, but followed by the COP sequence numbers that delimit
the variable's lifetime (or 'end' for a variable in an open scope) for a
variable.</p>
</dd>
</li>
<dt><strong><a name="item__23typenum"><strong>#typenum</strong></a></strong>

<dd>
<p>The numeric value of the OP's type, in decimal.</p>
</dd>
</li>
</dl>
<p>
</p>
<hr />
<h1><a name="using_b__concise_outside_of_the_o_framework">Using B::Concise outside of the O framework</a></h1>
<p>The common (and original) usage of B::Concise was for command-line
renderings of simple code, as given in EXAMPLE.  But you can also use
<strong>B::Concise</strong> from your code, and call <code>compile()</code> directly, and
repeatedly.  By doing so, you can avoid the compile-time only
operation of O.pm, and even use the debugger to step through
B::Concise::compile() itself.</p>
<p>Once you're doing this, you may alter Concise output by adding new
rendering styles, and by optionally adding callback routines which
populate new variables, if such were referenced from those (just
added) styles.</p>
<p>
</p>
<h2><a name="example__altering_concise_renderings">Example: Altering Concise Renderings</a></h2>
<pre>
    <span class="keyword">use</span> <span class="variable">B::Concise</span> <span class="string">qw(set_style add_callback)</span><span class="operator">;</span>
    <span class="variable">add_style</span><span class="operator">(</span><span class="variable">$yourStyleName</span> <span class="operator">=&gt;</span> <span class="variable">$defaultfmt</span><span class="operator">,</span> <span class="variable">$gotofmt</span><span class="operator">,</span> <span class="variable">$treefmt</span><span class="operator">);</span>
    <span class="variable">add_callback</span>
      <span class="operator">(</span> <span class="keyword">sub</span><span class="variable"> </span><span class="operator">{</span>
            <span class="keyword">my</span> <span class="operator">(</span><span class="variable">$h</span><span class="operator">,</span> <span class="variable">$op</span><span class="operator">,</span> <span class="variable">$format</span><span class="operator">,</span> <span class="variable">$level</span><span class="operator">,</span> <span class="variable">$stylename</span><span class="operator">)</span> <span class="operator">=</span> <span class="variable">@_</span><span class="operator">;</span>
            <span class="variable">$h</span><span class="operator">-&gt;</span><span class="operator">{</span><span class="string">variable</span><span class="operator">}</span> <span class="operator">=</span> <span class="variable">some_func</span><span class="operator">(</span><span class="variable">$op</span><span class="operator">);</span>
        <span class="operator">});</span>
    <span class="variable">$walker</span> <span class="operator">=</span> <span class="variable">B::Concise::compile</span><span class="operator">(</span><span class="variable">@options</span><span class="operator">,</span><span class="variable">@subnames</span><span class="operator">,</span><span class="variable">@subrefs</span><span class="operator">);</span>
    <span class="variable">$walker</span><span class="operator">-&gt;();</span>
</pre>
<p>
</p>
<h2><a name="set_style__"><code>set_style()</code></a></h2>
<p><strong>set_style</strong> accepts 3 arguments, and updates the three format-specs
comprising a line-style (basic-exec, goto, tree).  It has one minor
drawback though; it doesn't register the style under a new name.  This
can become an issue if you render more than once and switch styles.
Thus you may prefer to use <code>add_style()</code> and/or <code>set_style_standard()</code>
instead.</p>
<p>
</p>
<h2><a name="set_style_standard__name_"><code>set_style_standard($name)</code></a></h2>
<p>This restores one of the standard line-styles: <code>terse</code>, <code>concise</code>,
<code>linenoise</code>, <code>debug</code>, <code>env</code>, into effect.  It also accepts style
names previously defined with add_style().</p>
<p>
</p>
<h2><a name="add_style__"><code>add_style()</code></a></h2>
<p>This subroutine accepts a new style name and three style arguments as
above, and creates, registers, and selects the newly named style.  It is
an error to re-add a style; call <code>set_style_standard()</code> to switch between
several styles.</p>
<p>
</p>
<h2><a name="add_callback__"><code>add_callback()</code></a></h2>
<p>If your newly minted styles refer to any new #variables, you'll need
to define a callback subroutine that will populate (or modify) those
variables.  They are then available for use in the style you've
chosen.</p>
<p>The callbacks are called for each opcode visited by Concise, in the
same order as they are added.  Each subroutine is passed five
parameters.</p>
<pre>
  1. A hashref, containing the variable names and values which are
     populated into the report-line for the op
  2. the op, as a B&lt;B::OP&gt; object
  3. a reference to the format string
  4. the formatting (indent) level
  5. the selected stylename</pre>
<p>To define your own variables, simply add them to the hash, or change
existing values if you need to.  The level and format are passed in as
references to scalars, but it is unlikely that they will need to be
changed or even used.</p>
<p>
</p>
<h2><a name="running_b__concise__compile__">Running B::Concise::compile()</a></h2>
<p><strong>compile</strong> accepts options as described above in <a href="#options">OPTIONS</a>, and
arguments, which are either coderefs, or subroutine names.</p>
<p>It constructs and returns a $treewalker coderef, which when invoked,
traverses, or walks, and renders the optrees of the given arguments to
STDOUT.  You can reuse this, and can change the rendering style used
each time; thereafter the coderef renders in the new style.</p>
<p><strong>walk_output</strong> lets you change the print destination from STDOUT to
another open filehandle, or into a string passed as a ref (unless
you've built perl with -Uuseperlio).</p>
<pre>
    <span class="keyword">my</span> <span class="variable">$walker</span> <span class="operator">=</span> <span class="variable">B::Concise::compile</span><span class="operator">(</span><span class="string">'-terse'</span><span class="operator">,</span><span class="string">'aFuncName'</span><span class="operator">,</span> <span class="operator">\&amp;</span><span class="variable">aSubRef</span><span class="operator">);</span>  <span class="comment"># 1</span>
    <span class="variable">walk_output</span><span class="operator">(\</span><span class="keyword">my</span> <span class="variable">$buf</span><span class="operator">);</span>
    <span class="variable">$walker</span><span class="operator">-&gt;();</span>                        <span class="comment"># 1 renders -terse</span>
    <span class="variable">set_style_standard</span><span class="operator">(</span><span class="string">'concise'</span><span class="operator">);</span>      <span class="comment"># 2</span>
    <span class="variable">$walker</span><span class="operator">-&gt;();</span>                        <span class="comment"># 2 renders -concise</span>
    <span class="variable">$walker</span><span class="operator">-&gt;(</span><span class="variable">@new</span><span class="operator">);</span>                    <span class="comment"># 3 renders whatever</span>
    <span class="keyword">print</span> <span class="string">"3 different renderings: terse, concise, and @new: $buf\n"</span><span class="operator">;</span>
</pre>
<p>When $walker is called, it traverses the subroutines supplied when it
was created, and renders them using the current style.  You can change
the style afterwards in several different ways:</p>
<pre>
  1. call C&lt;compile&gt;, altering style or mode/order
  2. call C&lt;set_style_standard&gt;
  3. call $walker, passing @new options</pre>
<p>Passing new options to the $walker is the easiest way to change
amongst any pre-defined styles (the ones you add are automatically
recognized as options), and is the only way to alter rendering order
without calling compile again.  Note however that rendering state is
still shared amongst multiple $walker objects, so they must still be
used in a coordinated manner.</p>
<p>
</p>
<h2><a name="b__concise__reset_sequence__">B::Concise::reset_sequence()</a></h2>
<p>This function (not exported) lets you reset the sequence numbers (note
that they're numbered arbitrarily, their goal being to be human
readable).  Its purpose is mostly to support testing, i.e. to compare
the concise output from two identical anonymous subroutines (but
different instances).  Without the reset, B::Concise, seeing that
they're separate optrees, generates different sequence numbers in
the output.</p>
<p>
</p>
<h2><a name="errors">Errors</a></h2>
<p>Errors in rendering (non-existent function-name, non-existent coderef)
are written to the STDOUT, or wherever you've set it via
walk_output().</p>
<p>Errors using the various *style* calls, and bad args to walk_output(),
result in die().  Use an eval if you wish to catch these errors and
continue processing.</p>
<p>
</p>
<hr />
<h1><a name="author">AUTHOR</a></h1>
<p>Stephen McCamant, &lt;<a href="mailto:smcc@CSUA.Berkeley.EDU">smcc@CSUA.Berkeley.EDU</a>&gt;.</p>

</body>

</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -