Fix image scaling on 'internals' page.
@@ -8,7 +8,7 @@ permalink: /internals/
|
||||
{:toc}
|
||||
|
||||
# High-Level Design
|
||||

|
||||
{: class="thumbnail center-block img-responsive" }
|
||||
|
||||
On the diagram above is shown interaction of major components of software system: Parser and Runtime. Parser performs translation of input ECMAScript application into byte-code with specified format (refer to [Bytecode](/internals/#byte-code) and [Parser](/internals/#parser) page for details). Prepared bytecode is executed by Runtime engine that performs interpretation (refer to [Virtual Machine](/internals/#virtual-machine) and [ECMA](/internals/#ECMA) pages for details).
|
||||
|
||||
@@ -116,21 +116,21 @@ This component is just checks for syntax errors defined in the specification. It
|
||||
# Byte-code
|
||||
Every instruction of bytecode consists of opcode and up to three operands. Operand (idx) can be either a "register" or a string
|
||||
literal, specifying identifier to evaluate (i.e. `var //Storage idx`). General structure of instruction is shown on the picture.
|
||||

|
||||
{: class="thumbnail center-block img-responsive" }
|
||||
|
||||
Special kinds of instructions are described below.
|
||||
|
||||
## Arithmetic/bitwise-logic/logic/comparison/shift
|
||||
Arithmetic instruction can have the following structure:
|
||||
|
||||

|
||||
{: class="thumbnail center-block img-responsive" }
|
||||
|
||||
where dst/left/right/value identify an operand.
|
||||
|
||||
## Control (jumps)
|
||||
Control instructions utilize two bytes to encode jump location. Destination offset is contained inside `offset_high` and `offset_low` fields.
|
||||
|
||||

|
||||
{: class="thumbnail center-block img-responsive" }
|
||||
|
||||
Condition jump checks `cond value` field, which identifies an operand, and performs a jump if the operand has `true` value.
|
||||
|
||||
@@ -138,7 +138,7 @@ Condition jump checks `cond value` field, which identifies an operand, and perfo
|
||||
|
||||
Assignment instructions perform assignment of immediate value (contained inside instruction) to the operand, which is marked as `idx` on the picture.
|
||||
|
||||

|
||||
{: class="thumbnail center-block img-responsive" }
|
||||
|
||||
Type of the immediate value is encoded in the `type` field of instruction. The following values are supported:
|
||||
- "simple value" (see ECMA types encoding)
|
||||
@@ -151,7 +151,7 @@ Type of the immediate value is encoded in the `type` field of instruction. The f
|
||||
|
||||
Exit instruction serves to stop the execution and exit with a specified status.
|
||||
|
||||

|
||||
{: class="thumbnail center-block img-responsive" }
|
||||
|
||||
Exit instruction is employed in following cases:
|
||||
- at script end (exit with "succesful" stats);
|
||||
@@ -161,35 +161,35 @@ Exit instruction is employed in following cases:
|
||||
|
||||
Native call instruction is used to call intrinsics. Arguments are not encoded directly inside this instruction, instead they follow it as special "meta" instructions (see the according section). Id of desired intrinsic is encoded in the `intrinsic id` field.
|
||||
|
||||

|
||||
{: class="thumbnail center-block img-responsive" }
|
||||
|
||||
## Function call/Constructor call
|
||||
|
||||
Function/constructor call are utilized to perform calls to functions and constructors. Destination operand is encoded in `dst` field. Operand `name_idx` specifies the name of the function to call. Arguments are encoded the same way as in native call instruction.
|
||||
|
||||

|
||||
{: class="thumbnail center-block img-responsive" }
|
||||
|
||||
## Function declaration
|
||||
|
||||
Function declarations are represented by special kind of instructions. Function name and number of arguments are located in `name_idx` and `arg_list` fields respectively.
|
||||
|
||||

|
||||
{: class="thumbnail center-block img-responsive" }
|
||||
|
||||
## Function expression
|
||||
|
||||
Very similar to function declaration. But additionally contains destination (`dst`) field and `name` operand is optional, because anonymous functions are possible.
|
||||
|
||||

|
||||
{: class="thumbnail center-block img-responsive" }
|
||||
|
||||
## Return from function/eval
|
||||
|
||||
Return instructions perfrom unconditional return from function/eval code. Return value can be specified (`idx` field).
|
||||
|
||||

|
||||
{: class="thumbnail center-block img-responsive" }
|
||||
|
||||
## "Meta" (special marker opcode)
|
||||
|
||||

|
||||
{: class="thumbnail center-block img-responsive" }
|
||||
|
||||
Meta instructions are usually utilized as continuations of other instructions. Depending on `type` field, meta instruction can have the following meaning:
|
||||
|
||||
@@ -204,49 +204,49 @@ Meta instructions are usually utilized as continuations of other instructions. D
|
||||
|
||||
JavaScript delete operator is modeled with delete instruction in the bytecode. There are two types of delete instruction, applied either to element of lexical environment or to object's property.
|
||||
|
||||

|
||||
{: class="thumbnail center-block img-responsive" }
|
||||
|
||||
## This binding (evaluate "this")
|
||||
This binding instruction writes value of "this" to the `dst` operand.
|
||||
|
||||

|
||||
{: class="thumbnail center-block img-responsive" }
|
||||
|
||||
## typeof (typeof operation)
|
||||
|
||||
Typeof instruction executes JavaScript operator with the same name. Result is written to the `dst` operand.
|
||||
|
||||

|
||||
{: class="thumbnail center-block img-responsive" }
|
||||
|
||||
## with block
|
||||
|
||||
To specify bounds of "with" block, a pair of instructions is used. "With" instruction specifies its start. Followed by a number of arbitrary instructions, the block ends with `end_with` meta instruction.
|
||||
|
||||

|
||||
{: class="thumbnail center-block img-responsive"}
|
||||
|
||||
## try block
|
||||
|
||||
Try block consists of try instruction, followed by a number of arbitrary instructions, meta instruction `catch` or `finally` or both of them, separating catch and finally blocks respectively and meta instruction `end_try_catch_finally`, which finishes the whole construction.
|
||||
|
||||

|
||||
{: class="thumbnail center-block img-responsive" }
|
||||
|
||||
## Object declaration
|
||||
|
||||
Obect declaration instruction represents object literal in JavaScript specification. It consists of `op_obj_decl` instruction, followed by a list of `prop_data`, `prop_getter` and `prop_setter` meta instructions. A series of instructions which evaluate property values can precede meta instructions. Number of meta instructions, e.g. number of properties, is specified in the `prop_num` field.
|
||||
|
||||

|
||||
{: class="thumbnail center-block img-responsive" }
|
||||
|
||||
## Arguments and array declarartion
|
||||
|
||||
The strategy descibed in previous section is also used for encoding of arguments in function/constructor calls and elements in array declarations.
|
||||
See the according pictures.
|
||||
|
||||

|
||||
{: class="thumbnail center-block img-responsive" }
|
||||
|
||||
# Virtual machine
|
||||
|
||||
Virtual machine executes bytecode by interpreting instructions one by one. Bytecode is a continuous array of instructions, divided into blocks of fixed size. Main loop of interpreter calls `opfunc_*` for every instruction. This function returns completion value and position of the next instruction.
|
||||
|
||||

|
||||
{: class="thumbnail center-block img-responsive" }
|
||||
|
||||
Instruction can have up to three operands which are represented by `idx` values. Meaning of `idx` value depends on opcode and can be the following:
|
||||
|
||||
@@ -291,7 +291,7 @@ The major structure for data representation is `ECMA_value`. Lower two bits of t
|
||||
* string
|
||||
* object
|
||||
|
||||

|
||||
{: class="thumbnail center-block img-responsive" }
|
||||
|
||||
The immediate value is placed in higher bits. "Simple value" is an enumeration, which consists of the following elements:
|
||||
- undefined
|
||||
@@ -307,7 +307,7 @@ For other value types higher bits of `ECMA_value` structure contain compressed p
|
||||
|
||||
Compressed pointers were introduced to save heap space. They are possible because heap size is currently limited by 256 KB, which requires 18 bits to cover it. ECMA values in heap are aligned by 8 bytes and this allows to save three more bits, so that compressed pointer consumes 15 bits only.
|
||||
|
||||

|
||||
{: class="thumbnail center-block img-responsive" }
|
||||
|
||||
ECMA data elements are allocated in pools (pools are allocated on heap)
|
||||
Chunk size of the pool is 8 bytes (reduces fragmentation).
|
||||
@@ -345,7 +345,7 @@ Object and lexical environment structures, 8 bytes each, have common (GC) header
|
||||
|
||||
Remaining fields of these structures are different and are shown on the picture.
|
||||
|
||||

|
||||
{: class="thumbnail center-block img-responsive" }
|
||||
|
||||
### Property of an object / description of a lexical environment variable
|
||||
|
||||
@@ -359,7 +359,7 @@ All these units occupy 8 bytes and have common header:
|
||||
- next property/variable in the object/lexical environment (compressed pointer)
|
||||
|
||||
The remaining parts are differnt:
|
||||

|
||||
{: class="thumbnail center-block img-responsive" }
|
||||
|
||||
### Collections
|
||||
|
||||
@@ -400,7 +400,7 @@ Chunk's layout is following:
|
||||
|
||||
LCache is a cache for property variable search requests.
|
||||
|
||||

|
||||
{: class="thumbnail center-block img-responsive"}
|
||||
|
||||
Entry of LCache has the following layout:
|
||||
- object pointer
|
||||
@@ -426,7 +426,7 @@ However, there could be some combinations.
|
||||
|
||||
Many algorithms/routines described in ECMA return a value of "completion" type, that is triplet of the following form:
|
||||
|
||||

|
||||
{: class="thumbnail center-block img-responsive" }
|
||||
|
||||
Jerry introduces two additional completion types:
|
||||
- exit - produced by `exitval` opcode, indicates request to finish execution
|
||||
|
||||
|
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 29 KiB |
|
Before Width: | Height: | Size: 58 KiB After Width: | Height: | Size: 104 KiB |
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 43 KiB After Width: | Height: | Size: 29 KiB |
|
Before Width: | Height: | Size: 100 KiB After Width: | Height: | Size: 143 KiB |
|
Before Width: | Height: | Size: 75 KiB After Width: | Height: | Size: 114 KiB |
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 18 KiB |