Go to the first, previous, next, last section, table of contents.


Virtual Machine

Byte-Code File Format

File Header

magic
An UInt32 number containing the JavaScript byte-code file magic. The value of the magic is 0xc0014a53.
nsects
An UInt32 number containing the number of sections in this byte-code file.

Code Section

Constants Section

The constants section contains the constant values of the byte-code. The different constant types are stored as follows:

integer
(UInt8)3, (Int32)value
string
(UInt8)4, (UInt32)length, length bytes of data
float
(UInt8)5, (double)value
symbol
(UInt8)10, symbol name, (UInt8)0
NaN
(UInt8)13
regular expression
(UInt8)100, (UInt8)flags, (UInt32)length, length bytes of regexp source The item flags holds the regular expression flags. It is a combination of the following flags:
0x01
global match
0x02
ignore case

Symtab Section

Debug Section

Byte-Code Operands

The virtual machine knows the following byte-code operands. Each operand is identified by a 8 bit long unsigned integer number. The first operand halt has code 0, the next operand done has code 1, and so on. Some operand take arguments that are shown after the operand name in the following listing. The meanings of the arguments are:

Int8
The code of the operand is followed by a 8 bit long integer number argument.
Int16
The code of the operand is followed by a 16 bit long integer number argument.
Int32
The code of the operand is followed by a 32 bit long integer number argument.
Symbol
The code of the operand is followed by a 32 bit long integer number argument. The number is an offset to the constant section and the specified constant is a symbol that is the argument of the operand.

The notation

before => after

desribes how the operand modifies the virtual machine stack. For example, the notation:

--- => undefined

means that the operand takes no items from the stack and it pushes value undefined to the stack. The notation:

any any => boolean

means that the operand takes two items from the stack and it pushes a boolean result to the stack.

The virtual machine knows the following byte-code operands.

Operand: halt -- => ---
Halt the virtual machine. The program execution stops immediately and the virtual machine starts execute the following C-code:

while (1)
  sleep (5);

This "sleep forever" loop is implemented for debugging purposes.

Operand: done -- => ---
The execution of the byte-code is finished and the control returns to the calling C-function.

Operand: nop -- => ---
Do nothing; no operation.

Operand: dup any => any any
Duplicate the item at the top of the stack.

Operand: pop any => ---
Remove one item from the top of the stack.

Operand: pop_n Int8 any ... any => ---
Remove Int8 items from the top of the stack.

Operand: apop Int8 any_n ... any_0 => any_0
Remove Int8 items from the top of the stack, leaving the topmost item on the top of the stack. This operand is used to remove arguments of a function call, leaving the function's return value to the top of the stack.

Operand: swap any_1 any_2 => any_2 any_1
Swap the two topmost items in the stack.

Operand: roll Int8 any_n ... any_1 any_0 => any_0 any_n ... any_1

Operand: const Int32 -- => const
Push a constant from the constant section to the stack. The constant is specified by the value Int32.

Operand: const_null -- => null
Push value null to the stack.

Operand: const_true -- => true
Push value true to the stack.

Operand: const_false -- => false
Push value false to the stack.

Operand: const_undefined -- => undefined
Push value undefined to the stack.

Operand: const_i0 -- => 0
Push integer number 0 to the stack.

Operand: const_i1 -- => 1
Push integer number 1 to the stack.

Operand: const_i2 -- => 2
Push integer number 2 to the stack.

Operand: const_i3 -- => 3
Push integer number 3 to the stack.

Operand: const_i Int32 -- => Int32
Push integer number Int32 to the stack.

Operand: load_global Symbol -- => value
Push the value of the global variable Symbol to the stack.

Operand: store_global Symbol value => ---
Store the topmost item of the stack to the global variable Symbol.

Operand: load_arg Int8 -- => value
Push the value of the argument Int8 to the stack.

Operand: store_arg Int8 value => ---
Store the topmost item of the stack to the argument Int8.

Operand: load_local Int16 -- => value
Push the value of the local variable Int16 to the stack.

Operand: store_local Int16 value => ---
Store the topmost item of the stack to the local variable Int16.

Operand: load_property Symbol object => value
Push the value of the property Symbol of object object to the stack.

Operand: store_property Symbol object value => ---
Save the value value to the property Symbol of object object.

Operand: load_array object index => value
Push the index:th item of object object to the stack.

Operand: store_array value object index => ---
Store the value value to the index:th position of object object.

Operand: nth any integer => item boolean
Push the integer:th item of object any to the stack. Push a boolean success status that tells whether the object any did contain integer:th item.

Operand: cmp_eq any1 any2 => boolean
Compare the two objects any1, any2 for equality and push a boolean result code to the stack.

Operand: cmp_ne any any => boolean
Compare the two objects any1, any2 for inequality and push a boolean result code to the stack.

Operand: cmp_lt any1 any2 => boolean
Compare whether object any1 is smaller than object any2. Push a boolean result code to the stack.

Operand: cmp_gt any1 any2 => boolean
Compare whether object any1 is greater than object any2. Push a boolean result code to the stack.

Operand: cmp_le any1 any2 => boolean
Compare whether object any1 is smaller than, or equal to object any2. Push a boolean result code to the stack.

Operand: cmp_ge any1 any2 => boolean
Compare whether object any1 is greater than, or equal to object any2. Push a boolean result code to the stack.

Operand: cmp_seq any1 any2 => boolean
Compare the two objects any1, any2 for strict equality and push a boolean result code to the stack.

Operand: cmp_sne any any => boolean
Compare the two objects any1, any2 for strict inequality and push a boolean result code to the stack.

Operand: sub any1 any2 => result
Substract object any2 from object any1 and push the result to the stack.

Operand: add any1 any2 => result
Add object any2 to object any1 and push the result to the stack.

Operand: mul any1 any2 => result
Multiply object any1 with object any2 and push the result to the stack.

Operand: div any1 any2 => result
Divide object any1 with object any2 and push the result to the stack.

Operand: mod integer1 integer2 => result
Count object integer1 modulo object integer2 and push the result to the stack.

Operand: neg any => result
Negate object any and push the result to the stack.

Operand: and any1 any2 => result
Perform a bitwise and operation between objects any1 and any2 and push the result to the stack.

Operand: not any1 any2 => result
Perform a bitwise not operation between objects any1 and any2 and push the result to the stack.

Operand: or any1 any2 => result
Perform a bitwise or operation between objects any1 and any2 and push the result to the stack.

Operand: xor any1 any2 => result
Perform a bitwise xor operation between objects any1 and any2 and push the result to the stack.

Operand: shift_left integer1 integer2 => integer
Shift integer number integer1 left integer2 bits. Push the result value to the stack.

Operand: shift_right integer1 integer2 => integer
Shift integer number integer1 right integer2 bits. Push the result value to the stack.

Operand: shift_rright integer1 integer2 => integer

Operand: iffalse Int32 any => ---
If the topmost item in the stack has boolean value `false', adjust the program counter with relative offset Int32.

Operand: iftrue Int32 any => ---
If the topmost item in the stack has boolean value `true', adjust the program counter with relative offset Int32.

Operand: call_method Symbol object => result
Call method Symbol in the object object. Push the result of the method call to the stack.

Operand: jmp Int32 -- => ---
Adjust program counter with relative offset Int32, e.g. jump to relative position pc + Int32.

Operand: jsr Symbol -- => result
Jump to subroutine Symbol. Push the result of the subroutine call to the stack.

Operand: return result => result
Return from a subroutine with value result.

Operand: typeof any => string
Push the type name of object any to the stack.

Operand: new object => result object
Create an instance of object object and call its constructor function. Push the result from the constructor and the new instance to the stack. The return value of the constructor is discarded.

Operand: delete_property Symbol object => undefined
Delete property Symbol from object object. Push value undefined to the stack.

Operand: delete_array object index => undefined
Delete the index:th property of object object. Push value undefined to the stack.

Operand: locals Int16 -- => undefined ... undefined
Allocate Int16 local variables from the stack frame. The operand locals must be called in the beginning of the function code. The operand will push Int16 `undefined' values to the stack. The values will be the place-holders for the local variables.

Operand: min_args Int8 integer => ---
If the number of the arguments for the function integer is smaller than Int8, expand the stack frame so that the function gets Int8 arguments. The created arguments will have value undefined.

Operand: load_nth_arg integer => argument
Push the integer'th argument of function to the top of the stack. The index integer must be an integer number.

Operand: with_push object => ---
Push object object to the function's with-lookup chain.

Operand: with_pop Int8 -- => ---
Pop Int8 objects from the function's with-lookup chain.

Operand: try_push Int32 -- => ---
Push a try-frame with a catch block offset Int32 to the virtual machine's try-chain.

Operand: try_pop Int8 -- => ---
Pop Int8 frames from the virtual machine's try-chain.

Operand: throw any => ---
Throw an exception with value any.

Operand: iffalse_b Int32 boolean => ---
If the topmost item in the stack is false, adjust the program counter with relative offset Int32. The operand assumes that the topmost item is a boolean value.

Operand: iftrue_b Int32 boolean => ---
If the topmost item in the stack is true, adjust the program counter with relative offset Int32. The operand assumes that the topmost item is a boolean value.

Operand: add_1_i integer => integer
Add integer number one to the top most item in the stack. The operand assumes that the topmost item is an integer number.

Operand: add_2_i integer => integer
Add integer number two to the top most item in the stack. The operand assumes that the topmost item is an integer number.

Stack Frame

JS_SP0  sp =>
JS_SP1          local_var_n
JS_SP2          ...
JS_SP(n)        local_var_1
JS_LOCAL(0)     local_var_0
                return_addr
JS_WITHPTR      with_ptr
JS_ARGS_FIXP    args_fix
        fp =>   old_fp
JS_ARG(0)       this
JS_ARG(1)       arg_count
JS_ARG(2)       argument_1
                argument_2
                ...
JS_ARG(n)       argument_n
                local_var_n
                ...
                local_var_0
                args_fix
                return_addr
                with_ptr
                old_fp
                this
                ...


Go to the first, previous, next, last section, table of contents.