Declaring data types like "integer" might help with run time checking or code optimization...

The check is currently just a simple bit check. To get any benefit, you would have to eliminate the check completely by moving it to compile-time.

Let's look at $x+$y. (Looking at ops with a variable number of arguments would just complicate things.) It compiles into three ops:

1 padsv[$x] -> 2 2 padsv[$y] -> 3 3 add -> 4

There's nothing to affect! Right now, it would be of no benefit.

Let's look at what it would take to benefit from it. Let's suppose some of the code in "add" was taken out and turned into ops. $x+$y would then compile into the following code:

1 padsv[$x] -> 2 2 padsv[$y] -> 3 3 add_if_overloaded -> 11 if overloaded, 4 otherwise 4 swap_stack[0,1] -> 5 5 get_magic -> 6 6 numify -> 7 7 swap_stack[0,1] -> 8 8 get_magic -> 9 9 numify -> 10 10 add_prenumified -> 11

If both $x and $y are known to be numbers, the optimiser could turn the above into the following:

1 padsv[$x] -> 2 2 padsv[$y] -> 10 10 add_prenumified -> 11

But changing Perl to produce the above would require changing just about every opcode. And then there's the optimiser additions on top of that. That's a crazy amount of work.

What would be the result of that work?


In reply to Re: my TYPE EXPR ? by ikegami
in thread my TYPE EXPR ? by LanX

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.