<?xml version="1.0" encoding="utf-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: PHP Opcode Series</title>
	<atom:link href="http://jacobsantos.com/2007/writing-projects/php-opcode-series/feed/" rel="self" type="application/rss+xml" />
	<link>http://jacobsantos.com/2007/writing-projects/php-opcode-series/</link>
	<description>Rumblings, rants, essays, stories by Jacob Santos about Web Site Development, Persistent Browser-Based Games, personal journal, and Programming.</description>
	<lastBuildDate>Mon, 21 May 2012 13:04:07 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3-aortic-dissection</generator>
	<item>
		<title>By: Nexen.net : portail PHP et MySQL - Un coup d'oeil aux opcodes PHP</title>
		<link>http://jacobsantos.com/2007/writing-projects/php-opcode-series/comment-page-1/#comment-7882</link>
		<dc:creator>Nexen.net : portail PHP et MySQL - Un coup d'oeil aux opcodes PHP</dc:creator>
		<pubDate>Tue, 05 Jun 2007 15:26:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.santosj.name/php/php-opcode/php-opcode-series/#comment-7882</guid>
		<description>&lt;!--%kramer-ref-pre%--&gt;[...] en PHP, à quoi elle ressemble en opcode PHP, et comment elle est compilée à la volée.&#160;PHP Opcode Series (74 visites)&#160;Compiled Variables (19 visites)&#160;parsekit doc (7 visites)&#160;Liste des [...]&lt;!--%kramer-ref-post%--&gt;</description>
		<content:encoded><![CDATA[<p><!--%kramer-ref-pre%-->[...] en PHP, à quoi elle ressemble en opcode PHP, et comment elle est compilée à la volée.&nbsp;PHP Opcode Series (74 visites)&nbsp;Compiled Variables (19 visites)&nbsp;parsekit doc (7 visites)&nbsp;Liste des [...]<!--%kramer-ref-post%--></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: developercast.com &#187; Blog Archive &#187; Jacob Santos&#8217; Blog: PHP Opcode Series</title>
		<link>http://jacobsantos.com/2007/writing-projects/php-opcode-series/comment-page-1/#comment-3394</link>
		<dc:creator>developercast.com &#187; Blog Archive &#187; Jacob Santos&#8217; Blog: PHP Opcode Series</dc:creator>
		<pubDate>Thu, 15 Mar 2007 21:17:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.santosj.name/php/php-opcode/php-opcode-series/#comment-3394</guid>
		<description>[...] Santos has started a series of posts to his blog that focuses on the use of the opcode cache and language features in your applications. [...]</description>
		<content:encoded><![CDATA[<p>[...] Santos has started a series of posts to his blog that focuses on the use of the opcode cache and language features in your applications. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sara Golemon</title>
		<link>http://jacobsantos.com/2007/writing-projects/php-opcode-series/comment-page-1/#comment-3355</link>
		<dc:creator>Sara Golemon</dc:creator>
		<pubDate>Wed, 14 Mar 2007 21:34:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.santosj.name/php/php-opcode/php-opcode-series/#comment-3355</guid>
		<description>Thanks, I&#039;m glad you like it.  I do have several additions planned for the 2nd edition, but I&#039;m not sure compiler theory will make it in (assuming there is a 2nd ed, still too early to tell on that one).

I *have*, however, been meaning to get some more blog entries out which take a look under the hood (along the lines of &quot;How long is a piece of string?&quot;).  It&#039;s just a question of time and I&#039;m already quite late on getting part 4 of my devzone.zend.com series out the door.

As far as where you should start with your JIT compiler, just take a page out of the opcode cache book and hook zend_compile_file to get the opcodes, do some voodoo to turn that into C code, then run that into libgcc to make happy little binaries.  The principle is simple enough, it&#039;s just that voodoo step in the middle that&#039;ll drive you to seek truth at the bottom of a bottle some late frigid night...

In terms of understanding how the opcodes fit together, you ought to start by just pumping scripts into VLD and doing your best to make sense of the output.  The opcodes are (by and large) named pretty intuitively, QM being the major exception:  Hint, it&#039;s to do with ternary expressions.  Here&#039;s a few files of interrest in the Zend/ directory:

zend_language_scanner.l - Turns source into tokens (e.g. &quot;echo&quot; =&gt; T_ECHO )

zend_language_parser.y - Turns tokens into expressions (e.g. T_ECHO T_STRING &#039;;&#039; =&gt; zend_do_echo(&amp;$1) )

zend_compile.c - Turns expressions into opcodes (e.g.  zend_do_echo(znode *expr) =&gt; ZEND_ECHO  )

zend_vm_def.h - Executes opcodes (e.g. ZEND_ECHO  =&gt; zend_print_variable(op1) )

Note that all these files (with the exception of zend_compile.c) aren&#039;t &lt;i&gt;exactly&lt;/i&gt; C-source.  zend_language_scanner.l, zend_language_parser.y, and zend_vm_def.h are pre-processed by flex, bison, and zend_vm_gen.php, respectively.</description>
		<content:encoded><![CDATA[<p>Thanks, I&#8217;m glad you like it.  I do have several additions planned for the 2nd edition, but I&#8217;m not sure compiler theory will make it in (assuming there is a 2nd ed, still too early to tell on that one).</p>
<p>I *have*, however, been meaning to get some more blog entries out which take a look under the hood (along the lines of &#8220;How long is a piece of string?&#8221;).  It&#8217;s just a question of time and I&#8217;m already quite late on getting part 4 of my devzone.zend.com series out the door.</p>
<p>As far as where you should start with your JIT compiler, just take a page out of the opcode cache book and hook zend_compile_file to get the opcodes, do some voodoo to turn that into C code, then run that into libgcc to make happy little binaries.  The principle is simple enough, it&#8217;s just that voodoo step in the middle that&#8217;ll drive you to seek truth at the bottom of a bottle some late frigid night&#8230;</p>
<p>In terms of understanding how the opcodes fit together, you ought to start by just pumping scripts into VLD and doing your best to make sense of the output.  The opcodes are (by and large) named pretty intuitively, QM being the major exception:  Hint, it&#8217;s to do with ternary expressions.  Here&#8217;s a few files of interrest in the Zend/ directory:</p>
<p>zend_language_scanner.l &#8211; Turns source into tokens (e.g. &#8220;echo&#8221; =&gt; T_ECHO )</p>
<p>zend_language_parser.y &#8211; Turns tokens into expressions (e.g. T_ECHO T_STRING &#8216;;&#8217; =&gt; zend_do_echo(&amp;$1) )</p>
<p>zend_compile.c &#8211; Turns expressions into opcodes (e.g.  zend_do_echo(znode *expr) =&gt; ZEND_ECHO  )</p>
<p>zend_vm_def.h &#8211; Executes opcodes (e.g. ZEND_ECHO  =&gt; zend_print_variable(op1) )</p>
<p>Note that all these files (with the exception of zend_compile.c) aren&#8217;t <i>exactly</i> C-source.  zend_language_scanner.l, zend_language_parser.y, and zend_vm_def.h are pre-processed by flex, bison, and zend_vm_gen.php, respectively.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jacob Santos</title>
		<link>http://jacobsantos.com/2007/writing-projects/php-opcode-series/comment-page-1/#comment-3353</link>
		<dc:creator>Jacob Santos</dc:creator>
		<pubDate>Wed, 14 Mar 2007 20:22:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.santosj.name/php/php-opcode/php-opcode-series/#comment-3353</guid>
		<description>Dear Sara,

Your book on writing PHP Extensions is awesome! Any thoughts of extending it to include Zend Engine details?

Thanks.

Going-insane-wannabe-Zend-Engine-Hacker,

Jacob Santos

-------------

There would be a greater need for writing extensions than for hacking the Zend Engine, but it might be good for a double length book. It would help make this long journey shorter. Although I do realized that asking is probably a slap in a face, since you didn&#039;t have such material when you started hacking.

I&#039;ll take this as a rite as passage then, until which time such material does become widely available in printed form. I did find a lot of functions that might help in implementing the JIT compiler, but I really do need to hack and see what each does. That is quite a long process and it usually leads to other areas of the Zend Engine. For that is another reason for the creation of this series. Once I learn one part, I can accept it in ease, or at least as much ease as one can get with a month or two of hacking.</description>
		<content:encoded><![CDATA[<p>Dear Sara,</p>
<p>Your book on writing PHP Extensions is awesome! Any thoughts of extending it to include Zend Engine details?</p>
<p>Thanks.</p>
<p>Going-insane-wannabe-Zend-Engine-Hacker,</p>
<p>Jacob Santos</p>
<p>&#8212;&#8212;&#8212;&#8212;-</p>
<p>There would be a greater need for writing extensions than for hacking the Zend Engine, but it might be good for a double length book. It would help make this long journey shorter. Although I do realized that asking is probably a slap in a face, since you didn&#8217;t have such material when you started hacking.</p>
<p>I&#8217;ll take this as a rite as passage then, until which time such material does become widely available in printed form. I did find a lot of functions that might help in implementing the JIT compiler, but I really do need to hack and see what each does. That is quite a long process and it usually leads to other areas of the Zend Engine. For that is another reason for the creation of this series. Once I learn one part, I can accept it in ease, or at least as much ease as one can get with a month or two of hacking.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sara Golemon</title>
		<link>http://jacobsantos.com/2007/writing-projects/php-opcode-series/comment-page-1/#comment-3352</link>
		<dc:creator>Sara Golemon</dc:creator>
		<pubDate>Wed, 14 Mar 2007 20:01:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.santosj.name/php/php-opcode/php-opcode-series/#comment-3352</guid>
		<description>There&#039;s a lot about ZE that&#039;s beautiful, and lot that&#039;s just plain annoyingly wrongity-wrong (but has to be in order to appease the gods of BC).  Once you get your head about the organization of the linkages between the lexer, parser, compiler, and the awe-and-mystery that is the back-patching routines, it should start to hold together a little better.

To paraphrase someone I once knew(RIP), who was referring to the sendmail configuration file:

It&#039;s like the Necronomicon... You are warned away, but you go regardless, hoping to learn unearthly secrets. If your 
sanity survives, you spend the rest of your life conversing with znodes, running from refcounts, and striking fear into most heredocs. I don&#039;t know whether it has driven me insane or revealed to me deep secrets about the universe.</description>
		<content:encoded><![CDATA[<p>There&#8217;s a lot about ZE that&#8217;s beautiful, and lot that&#8217;s just plain annoyingly wrongity-wrong (but has to be in order to appease the gods of BC).  Once you get your head about the organization of the linkages between the lexer, parser, compiler, and the awe-and-mystery that is the back-patching routines, it should start to hold together a little better.</p>
<p>To paraphrase someone I once knew(RIP), who was referring to the sendmail configuration file:</p>
<p>It&#8217;s like the Necronomicon&#8230; You are warned away, but you go regardless, hoping to learn unearthly secrets. If your<br />
sanity survives, you spend the rest of your life conversing with znodes, running from refcounts, and striking fear into most heredocs. I don&#8217;t know whether it has driven me insane or revealed to me deep secrets about the universe.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jacob Santos</title>
		<link>http://jacobsantos.com/2007/writing-projects/php-opcode-series/comment-page-1/#comment-3349</link>
		<dc:creator>Jacob Santos</dc:creator>
		<pubDate>Wed, 14 Mar 2007 17:41:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.santosj.name/php/php-opcode/php-opcode-series/#comment-3349</guid>
		<description>@Padraic Brady

Thanks! Yeah, I figured it would be easier and quicker to learn and work with the Zend Engine than it would be to build my own compiler. I still want to build my own compiler, but &quot;getting my feet wet&quot; is something I should do to better learn how compilers work, or more specifically how the Zend Engine works. 

If I can&#039;t adapt to the Zend Engine, then there is no way in hell I can call myself a professional or say that I&#039;m ready for the professional world where I&#039;ll be working with another person&#039;s code all of the time. At the very least, I can say on my resume, that I can adapt well to alien code bases. Need to learn not to rewrite everything I don&#039;t understand (my New Year&#039;s resolution).

It also gets the little ideas that are floating around the inside of my head out in coherent form, so that I can follow and choose which idea is worth pursuing in the amount of time that I will have. Summer will be most interesting indeed, but I will also spend some time compiling theory and breaking the Zend Engine over the course of two months. Should be a fun side project.

My first step was going to be just jumping and using an library to allow JIT compilation for the Zend Engine. When I actually took a better look at the Zend Engine, the areas unrelated to PHP Extension writing, I got the idea to do this series. Comments are quite sparse and yeah, it might have went better for me if I had another two or three years of C/C++ experience.

Drowning is a better term I think to describe how over my head I am. I do have better respect for the people who understand and maintain the Zend Engine. Actually, some of the ideas I have are far too complicated for me to implement, even if I did understand the Zend Engine. Taking some posts that I had saved from last year and converting them to this format.</description>
		<content:encoded><![CDATA[<p>@Padraic Brady</p>
<p>Thanks! Yeah, I figured it would be easier and quicker to learn and work with the Zend Engine than it would be to build my own compiler. I still want to build my own compiler, but &#8220;getting my feet wet&#8221; is something I should do to better learn how compilers work, or more specifically how the Zend Engine works. </p>
<p>If I can&#8217;t adapt to the Zend Engine, then there is no way in hell I can call myself a professional or say that I&#8217;m ready for the professional world where I&#8217;ll be working with another person&#8217;s code all of the time. At the very least, I can say on my resume, that I can adapt well to alien code bases. Need to learn not to rewrite everything I don&#8217;t understand (my New Year&#8217;s resolution).</p>
<p>It also gets the little ideas that are floating around the inside of my head out in coherent form, so that I can follow and choose which idea is worth pursuing in the amount of time that I will have. Summer will be most interesting indeed, but I will also spend some time compiling theory and breaking the Zend Engine over the course of two months. Should be a fun side project.</p>
<p>My first step was going to be just jumping and using an library to allow JIT compilation for the Zend Engine. When I actually took a better look at the Zend Engine, the areas unrelated to PHP Extension writing, I got the idea to do this series. Comments are quite sparse and yeah, it might have went better for me if I had another two or three years of C/C++ experience.</p>
<p>Drowning is a better term I think to describe how over my head I am. I do have better respect for the people who understand and maintain the Zend Engine. Actually, some of the ideas I have are far too complicated for me to implement, even if I did understand the Zend Engine. Taking some posts that I had saved from last year and converting them to this format.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: PÃ¡draic Brady</title>
		<link>http://jacobsantos.com/2007/writing-projects/php-opcode-series/comment-page-1/#comment-3348</link>
		<dc:creator>PÃ¡draic Brady</dc:creator>
		<pubDate>Wed, 14 Mar 2007 17:02:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.santosj.name/php/php-opcode/php-opcode-series/#comment-3348</guid>
		<description>Look forward to the series. Getting your feet wet in a large codebase can be a pretty time consuming exercise so I dig your approach. It&#039;s imperfect, but builds early understanding. Definitely a topic worth blogging about.</description>
		<content:encoded><![CDATA[<p>Look forward to the series. Getting your feet wet in a large codebase can be a pretty time consuming exercise so I dig your approach. It&#8217;s imperfect, but builds early understanding. Definitely a topic worth blogging about.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Evert</title>
		<link>http://jacobsantos.com/2007/writing-projects/php-opcode-series/comment-page-1/#comment-3344</link>
		<dc:creator>Evert</dc:creator>
		<pubDate>Wed, 14 Mar 2007 14:54:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.santosj.name/php/php-opcode/php-opcode-series/#comment-3344</guid>
		<description>Excited to hear what your findings are! Would be great if you could blog along the way =)</description>
		<content:encoded><![CDATA[<p>Excited to hear what your findings are! Would be great if you could blog along the way =)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jacob Santos</title>
		<link>http://jacobsantos.com/2007/writing-projects/php-opcode-series/comment-page-1/#comment-3342</link>
		<dc:creator>Jacob Santos</dc:creator>
		<pubDate>Wed, 14 Mar 2007 12:37:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.santosj.name/php/php-opcode/php-opcode-series/#comment-3342</guid>
		<description>Oops, This wasn&#039;t supposed to be part of Planet PHP! I&#039;ll fix that.

@Greg Beaver

Yeah, I&#039;ve done that, except for IRC as I&#039;m not fond of chatting. Wastes way to much time. I also would not like to waste their time either with pointless question after pointless question. The quest is to find the answers myself and if I stumbled, &lt;b&gt;then&lt;/b&gt; ask. I may be a n00b, but I find it is better not to act like one.</description>
		<content:encoded><![CDATA[<p>Oops, This wasn&#8217;t supposed to be part of Planet PHP! I&#8217;ll fix that.</p>
<p>@Greg Beaver</p>
<p>Yeah, I&#8217;ve done that, except for IRC as I&#8217;m not fond of chatting. Wastes way to much time. I also would not like to waste their time either with pointless question after pointless question. The quest is to find the answers myself and if I stumbled, <b>then</b> ask. I may be a n00b, but I find it is better not to act like one.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Greg Beaver</title>
		<link>http://jacobsantos.com/2007/writing-projects/php-opcode-series/comment-page-1/#comment-3331</link>
		<dc:creator>Greg Beaver</dc:creator>
		<pubDate>Wed, 14 Mar 2007 05:30:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.santosj.name/php/php-opcode/php-opcode-series/#comment-3331</guid>
		<description>Why can&#039;t you ask the minds who created it?  They hang around on IRC, and all read internals@lists.php.net as well.</description>
		<content:encoded><![CDATA[<p>Why can&#8217;t you ask the minds who created it?  They hang around on IRC, and all read <a href="mailto:internals@lists.php.net">internals@lists.php.net</a> as well.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

