Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:45291 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 28293 invoked from network); 17 Aug 2009 04:36:24 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Aug 2009 04:36:24 -0000 Authentication-Results: pb1.pair.com header.from=stas@zend.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=stas@zend.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 63.205.162.117 as permitted sender) X-PHP-List-Original-Sender: stas@zend.com X-Host-Fingerprint: 63.205.162.117 us-mr1.zend.com Linux 2.4/2.6 Received: from [63.205.162.117] ([63.205.162.117:47218] helo=us-mr1.zend.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B2/F7-13350-74ED88A4 for ; Mon, 17 Aug 2009 00:36:24 -0400 Received: from us-gw1.zend.com (us-ex1.zend.net [192.168.16.5]) by us-mr1.zend.com (Postfix) with ESMTP id ADF0FE123E for ; Sun, 16 Aug 2009 21:23:50 -0700 (PDT) Received: from [192.168.27.6] ([192.168.27.6]) by us-gw1.zend.com with Microsoft SMTPSVC(6.0.3790.3959); Sun, 16 Aug 2009 21:37:27 -0700 Message-ID: <4A88DE3E.7020307@zend.com> Date: Sun, 16 Aug 2009 21:36:14 -0700 Organization: Zend Technologies User-Agent: Thunderbird 2.0.0.23 (Windows/20090812) MIME-Version: 1.0 To: Stefan Marr CC: internals@lists.php.net References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 17 Aug 2009 04:37:27.0535 (UTC) FILETIME=[6C8A7FF0:01CA1EF4] Subject: Re: [PHP-DEV] Design of the Zend Engine's Instruction Set From: stas@zend.com (Stanislav Malyshev) Hi! > So, the basic design of the Zend Engine is a > a stack-based interpreter for a fixed length > instruction set (76byte on a 32bit architecture), Not exactly stack-based, it's more register-based. Number of registers is not limited, even though most of them aren't used simultaneously. > Instructions encode: > - a line number > - a function pointer to the actual handler which is > used to execute it > - two operands, which encode constant values, > object references, jump addresses, > or pointer to other functions > - 64 bit for an extended operand value > - a field for results, which is use for some > operations return values. The basic model is that each operation works on 2 operands and (optionally) returns result. Operands can be either constants, temp variables or in-memory variables, or sometimes a number which is used as jump point, etc. This model can be extended for some opcodes by using either extended operand or additional opcode, if operation semantics does not fit in one opcode (e.g. opcode generated by $a->b["x"] would have 4 operands - $a, "b", "x" and how the expression is used - read/write/test, etc.) > However, its not a simple, single stack model, > but uses several purpose-specific stacks. Stacks indeed are used for function calls, but this is just an implementation detail. > What I am not so sure about is especially the > semantics of the result field and the pointer > to the other function (op_array). result field is a result of an operation, so if you have $a = $b + $c, then ADD opcode which would add content of $b and $c would use "result" field to store the value, which will then be used by ASSIGN opcode to assign the result to $a. As for op_array, I assume you are referring to op_array field in znode union. I don't think this one is used by the engine at runtime, it's a compiler utility field. > I am also not really sure with these complexity, > whether is not actually some kind of abstract syntax > tree instead of a instruction set like Java > bytecode. Thats not a technical problem, but merely > an academic question to categorize/characterize PHP. I think it's more like bytecode, indeed. Even though the instructions are pretty high-level so with some effort you probably could build a syntax tree out of it. -- Stanislav Malyshev, Zend Software Architect stas@zend.com http://www.zend.com/ (408)253-8829 MSN: stas@zend.com