Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: Perl 5 interpreter

by BrowserUk (Pope)
on Jan 12, 2011 at 08:23 UTC ( #881836=note: print w/ replies, xml ) Need Help??


in reply to Re: Perl 5 interpreter
in thread Perl 5 interpreter

but writing portable and efficient C code basically requires excessive macro usage.

Most, if not all of the macros in perl5 could be replaced by inline functions and be as if not more efficient.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.


Comment on Re^2: Perl 5 interpreter
Re^3: Perl 5 interpreter
by Corion (Pope) on Jan 12, 2011 at 08:25 UTC

    Except that Perl also is supposed to compile on C89 (or is that ANSI C, or even K&R?) compilers that don't support inline. And then you'd either get non-inlined functions (which would bring us back to inefficient) or no Perl at all...

      But there are so many macros that just replace one name with the same name with things like S_ or PL_ infront of it. I couldn't figure out why such a thing was needed.

      Also at times variable types like int, char and other terms like like volatile have been custom names through macros. Couldn't understand why that was done.

        The custom renaming to S_ or PL_ comes from C having no namespaces and Perl being embeddable into other applications. There you need to fake a namespace by prefixing all exported symbols with whatever you need.

        In theory, ideally, Perl C code wouldn't use int or char at all, but either Perl-internal data types like SV (which can hold an int) or whatever Perl defines to be the data type for holding integral numbers (UINT ?) or string length (SvLENGTH ?). Of course, at the boundary to the C library, you won't get around actually touching native data types.

      Ah yes. The spectre and drogue of backward compatibility.

      Does Perl really need to support a 21 year old standard that was superceded 11 years ago?

      How many people are still confined, other than by choice, to using a C89 only complier?


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

        Even if they are no longer using it, I don't think rewriting is an option which porters would consider.

        I mean fixing this would take too much effort but no visible benefit to the end user.

        If "by choice" you mean "the C compiler that my OS vendor uses", I guess too many, especially for OSes that you pay real money for :-)

        I think there are some macros that you can't conveniently elide, like dTHX, which expands to "the current thread context" if Perl is compiled with iThreads and "nothing" if threads are not compiled (but you know that). I'm not sure whether having inlined functions is much better, structurally, than having the macros.

        Does Perl really need to support a 21 year old standard that was superceded 11 years ago?

        How many people are still confined, other than by choice, to using a C89 only complier?

        FWIW the parrot developers had a similar discussion recently, and decided not to switch to full C99, because MSVC doesn't support that. But they switched to a C99 subset that most compilers understand. They might value developer sanity higher than support for legacy platforms, at least compared to p5p.

        I do, on a daily basis.

        First reason is that on those (proprietary) OS's there is no (more) update available for the ANSI C89 compiler.

        Second reason is that GNU folk do not consider OS's other than Linux worthwhile caring for. E.g. on HP-UX PA-RISC (10.20, 11.00, 11.11 and 11.23) it is impossible to create a GNU gcc-4.x.x that compiles reliable in 64bit mode, so I'm stuck to version 3.4.6.

        GNU gcc is a nightmare to compile on e.g. HP-UX 11.23 or 11.31 if all of your system is set up to be 64bitall only. GNU gcc folk claim the compiler just needs a 32bit environment to build a compiler that can generate 32bit and 64bit objects, but in order to get that compiler compiled, you need a 32bit environment and - at current - THREE extra packages installed (gmp, mpfr and mpc) that all need a gcc compiler to get compiled properly -> endless loop of FAIL. On these I stopped porting with gcc-4.2.4.

        Third reason is that (maybe because of reason 2), code generated with HP C-ANSI-C compiler runs up to 15% faster than when compiled with GNU gcc, so the option to use a gcc compiler just because it can do C99 is not a very obvious one. I bet inlining functions won't get a 15% speed gain ove macros, but I didn't check that.


        Enjoy, Have FUN! H.Merijn
Re^3: Perl 5 interpreter
by ikegami (Pope) on Jan 12, 2011 at 08:48 UTC

    Definitely not all. Some macros ("dXXX;") create and initialise variables used by one or more other macros. Those macros and the macros that use the variables declared by them couldn't be made into functions without a cost.

    In fact, these are the only macros that gave me any confusion. The documentation isn't clear as ti what declares what and what uses what. The only other time I've had to look into the macros was to see what exactly is an acceptable input. (e.g. Is NULL ok?)

    I'm not sure how much more readable inlinable functions would be. Looking down seven levels of functions is no easier than looking down seven level of macros. I imagine most debuggers are better at handling inline functions than macros, though.

      Are Macros only such ways of creating abstractions? Because they are more of a kind of reusable templating stuff. Here one has to do work on more text replacement and substitution and then work on its logic.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://881836]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (6)
As of 2014-12-27 22:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (177 votes), past polls