1. Perl
  2. Language implementation
  3. here

embedvar.h

embedvar.h is a header for abstracting interpreter variable and global variable.

Interpreter variable abstraction

The logic of the interpretation variable abstraction is as follows.

# if defined(MULTIPLICITY)
/ * cases 2 and 3 above */
# if defined(PERL_IMPLICIT_CONTEXT)
# define vTHX aTHX
# else
# define vTHX PERL_GET_INTERP
# endif

# define PL_AboveLatin1 (vTHX->IAboveLatin1)
# define PL_Argv (vTHX->IArgv)
# define PL_Cmd (vTHX->ICmd)
# define PL_DBcontrol (vTHX->IDBcontrol)

# endif

First, when "MULTIPLICITY" is defined, it means that multiple interpreters can be used. In such cases, you need to access the variable for each interpreter.

Next, "PERL_IMPLICIT_CONTEXT" means that the interpreter is passed as the first argument of a function that starts with "Perl_", in the sense that an implicit context assumes it.

In general, if "MULTIPLICITY" is defined, consider that "PERL_IMPLICIT_CONTEXT" is defined.

"ATHX" is defined as follows:

/*perl.h */
# ifdef PERL_IMPLICIT_CONTEXT
# define aTHX my_perl
# end

my_perl is a global variable and represents an interpreter.

/* perlmain.c */static PerlInterpreter * my_perl;

Next, if "PERL_IMPLICIT_CONTEXT" is not defined, "PERL_GET_INTERP" is defined as follows and is the current interpreter. This is a global variable.

/*perl.h */
# define PERL_GET_INTERP (PL_curinterp)
/* perlvar.h */PERLVARI (G, curinterp, PerlInterpreter *, NULL)
/ * currently running interpreter
* (initial parent interpreter under under
* useithreads) */</pre>

If "PERL_IMPLICT_CONTEXT" is defined, "vTHX" will be expanded as "my_perl", otherwise it will be expanded as "Gcurinterp". ..

And the access to the interpreted variable is defined as follows.

<pre>
# define PL_AboveLatin1 (vTHX->IAboveLatin1)

Global variable abstraction

Next is the code for the abstraction of global variable. If "PERL_GLOBAL_STRUCT" is defined, the entire global variable exists as a single structure, otherwise it exists as a regular global variable. In both of these cases, you can access the variable with "PL_appctx".

# if defined(PERL_GLOBAL_STRUCT)

# define PL_appctx (my_vars->Gappctx)
# define PL_Gappctx (my_vars->Gappctx)
# endif
/* perlmain.c */struct perl_vars * my_vars = init_global_struct ();

Perl Language Research

Related Informatrion