我怎样才能在Perl源代码中找到某些功能的实现?
发布时间:2020-12-15 23:24:15 所属栏目:大数据 来源:网络整理
导读:例如,我想找到’print’或’foreach’运算符的源代码. 我已经下载了Perl源代码,希望看到这个运算符的“真实”代码. 解决方法 Perl将源代码编译为名为Opcode Tree的图形.同时,此数据结构表示程序的语法和控制流程.要理解操作码,您可能需要从 Illustrated Perl
例如,我想找到’print’或’foreach’运算符的源代码.
我已经下载了Perl源代码,希望看到这个运算符的“真实”代码. 解决方法
Perl将源代码编译为名为Opcode Tree的图形.同时,此数据结构表示程序的语法和控制流程.要理解操作码,您可能需要从
Illustrated Perl Guts (illguts)开始.
要了解您的程序编译的Ops,您可以这样称呼它: > perl -MO = Concise script.pl – 在语法树中获取操作码 典型的操作码看起来像: 4 <$> const[PV "007B"] s/FOLD ->5 ^ ^ ^ ^ ^ | | | | The next op in execution order | | | Flags for this op,documented e.g. in illguts. "s" is | | | scalar context. After the slash,op-specific stuff | | The actual name of the op,may list further arguments | The optype ($: unop,2: binop,@:listop) – not really useful The op number Ops声明为PP(pp_const).要搜索该声明,请使用 $ack 'pp_const' *.c *.h 输出(这里没有颜色): op.c 29: * points to the pp_const() function and to an SV containing the constant 30: * value. When pp_const() is executed,its job is to push that SV onto the pp_hot.c 40:PP(pp_const) opcode.h 944: Perl_pp_const,pp_proto.h 43:PERL_CALLCONV OP *Perl_pp_const(pTHX); 所以它在pp_hot.c,第40行声明.我倾向于使用vim pp_hot.c 40去那里.然后我们看到定义: PP(pp_const) { dVAR; dSP; XPUSHs(cSVOP_sv); RETURN; } 要理解这一点,你应该对Perl API有一点了解,也许可以写一点XS. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |