does perl_eval_pv function compile the source code passed to it?

does perl_eval_pv function compile the source code passed to it?

am 04.12.2007 11:36:08 von grbgooglefan

If I use perl_eval_pv function for parsing the Perl source code (in &
from C++ program), will that code be compiled also, in addition to
being parsed?
If code is compiled, will it be in the byte code format like that of
Java or pure executable as generated by C compiler?
Where do we get this internal information about Perl interpreter
embedded in C/ C++ application?

Re: does perl_eval_pv function compile the source code passed to it?

am 04.12.2007 13:08:34 von Ben Morrow

Quoth grbgooglefan :
> If I use perl_eval_pv function for parsing the Perl source code (in &
> from C++ program), will that code be compiled also, in addition to
> being parsed?

eval_pv (the perl_ names are deprecated) will compile and run the given
expression (in scalar context), returning the result. (It is not really
possible to separate the 'parse' and 'compile' stages when dealing with
Perl code.) It's exactly equivalent to eval STRING in Perl.

There isn't a function in the Perl api to compile a piece of code and
return the compiled form without running it, except for perl_parse at
the top level of your Perl program, mostly because it's not something
you can do in Perl and it would be rather hard to do anything useful
with the result. You can always wrap a piece of code in "sub {" ... "}"
and then call the returned subref with call_sv.

> If code is compiled, will it be in the byte code format like that of
> Java or pure executable as generated by C compiler?

More like Java bytecode than native object code, though not really
terribly similar. Perl stores a compiled program internally as a tree
of OPs, where each OP is one of the basic operations of the 'perl
virtual machine'. There is (was) a B::Bytecode that was supposed to
serialize that optree into something more like conventional bytecode,
but it never worked properly and has been removed from recent versions
of perl.

> Where do we get this internal information about Perl interpreter
> embedded in C/ C++ application?

perlapi / perlembed / perlcall / the perl source, in the end

Ben