EarendilEarendildjsHow djs works
Source

Opcodes

Every instruction of the bytecode, generated from the ops! table in crates/djs-core/src/bytecode/ops.rs: the encoded byte, the immediates, the encoded size, the stack effect and the fuel cost class. The emitter, decoder, disassembler and the stack-depth checker are generated from the same table, so this page cannot disagree with them.

opcodebyteimmediatessizepop → pushcostdescription
undefined0–10 → 1Basic-> undefined
null1–10 → 1Basic-> null
push_true2–10 → 1Basic-> true
push_false3–10 → 1Basic-> false
push_i84I820 → 1Basic-> n: a small integer constant.
push_i325I3250 → 1Basic-> n: an integer constant.
push_const6Const50 → 1Basic-> v: a constant pool entry (non-int32 numbers, strings).
push_atom7Atom50 → 1Basic-> s: the string of an atom.
object8–10 → 1Alloc-> {}
array_from9Count3imm0 → 1Allocv1 .. vn -> array: an array literal without holes or spread.
array_push10–12 → 1Basicarray v -> array
array_hole11–11 → 1Basicarray -> array: append a hole.
array_spread12–12 → 1Accessarray iterable -> array: append the elements of an iterable (spread).
fclosure13Child50 → 1Alloc-> function: create a closure of child template child.
regexp14–12 → 1Allocpattern flags -> regexp
get_template_object15Const50 → 1Alloc-> template object: tagged templates. CONSTS[idx] is the site’s object once created; before that, the index of n, n cooked strings (or undefined) and n raw strings, from which the first run creates and caches it.
special_object16U820 → 1Alloc-> v: arguments, new.target, home object, … (function entry only).
rest17Arg30 → 1Alloc-> array: the actual arguments from index on (a rest parameter).
drop18–11 → 0Basica ->
dup19–11 → 2Basica -> a a
dup220–12 → 4Basica b -> a b a b
swap21–12 → 2Basica b -> b a
nip22–12 → 1Basica b -> b
insert223–12 → 3Basica b -> b a b
insert324–13 → 4Basica b c -> c a b c
insert425–14 → 5Basica b c d -> d a b c d
rot3l26–13 → 3Basicx a b -> a b x
rot3r27–13 → 3Basica b x -> x a b
pick28U821+imm0 → 2+imm0Basicx a1 .. an -> x a1 .. an x: copy the value under the top n (pick 0 is dup). Destructuring reaches its iterator under assignment-target references.
poke29U822+imm0 → 1+imm0Basicx a1 .. an v -> v a1 .. an: overwrite the value under the top n + 1.
name_get30NameRef50 → 1Free-> v: read a name.
name_put31NameRef51 → 0Freev ->: assign a name.
name_set32NameRef51 → 1Freev -> v: assign a name, keep the value.
name_init33NameRef51 → 0Freev ->: initialize a declaration (no TDZ check, const allowed).
name_typeof34NameRef50 → 1Free-> v: read a name for typeof (undeclared globals give undefined).
enter_scope35Scope30 → 0FreeScope entry: TDZ setup, Boxes, hoisted block functions.
leave_scope36Scope30 → 0FreeScope exit.
iter_scope37Scope30 → 0FreeStart of a for (let ...) iteration: fresh copies of the scope’s captured bindings (rebox, CreatePerIterationEnvironment).
label38LabelId50 → 0FreeA label position (symbolic labels).
get_loc39Loc30 → 1Basic-> v
put_loc40Loc31 → 0Basicv ->
set_loc41Loc31 → 1Basicv -> v
get_loc_chk42Loc30 → 1Basic-> v, ReferenceError if uninitialized (TDZ).
put_loc_chk43Loc31 → 0Basicv ->, ReferenceError if uninitialized.
set_loc_chk44Loc31 → 1Basicv -> v, ReferenceError if uninitialized.
set_loc_uninit45Loc30 → 0BasicStore the uninitialized marker.
inc_loc46Loc30 → 0Basicloc = loc + 1 (i++;, ++i; on an unchecked local): inc in place. An object takes %ToNumeric into the local first, then the instruction runs again.
dec_loc47Loc30 → 0Basicloc = loc - 1, as inc_loc.
get_arg48Arg30 → 1Basic-> v
put_arg49Arg31 → 0Basicv ->
set_arg50Arg31 → 1Basicv -> v
get_box51Loc30 → 1Basic-> v: the value of the Box in local loc.
put_box52Loc31 → 0Basicv ->
set_box53Loc31 → 1Basicv -> v
get_box_chk54Loc30 → 1Basic-> v with a TDZ check.
put_box_chk55Loc31 → 0Basicv -> with a TDZ check.
set_box_chk56Loc31 → 1Basicv -> v with a TDZ check.
new_box57Loc30 → 0Allocloc = new Box(uninitialized)
new_box_init58Loc31 → 0Allocv ->: loc = new Box(v).
rebox59Loc30 → 0Allocloc = new Box(current value): per-iteration bindings.
get_cap60Cap30 → 1Basic-> v: the value of the closure’s capture cap.
put_cap61Cap31 → 0Basicv ->
set_cap62Cap31 → 1Basicv -> v
get_cap_chk63Cap30 → 1Basic-> v with a TDZ check.
put_cap_chk64Cap31 → 0Basicv -> with a TDZ check.
set_cap_chk65Cap31 → 1Basicv -> v with a TDZ check.
get_global66Atom, Cache70 → 1Access-> v: global lexical record, then the global object; ReferenceError if missing.
get_global_typeof67Atom, Cache70 → 1Access-> v: like get_global, but undefined if missing (typeof).
put_global68Atom, Cache71 → 0Accessv ->: ReferenceError if missing, TypeError for a global const.
init_global_lex69Atom51 → 0Accessv ->: initialize a Script top-level let/const/class.
global_decls70Const50 → 0AccessScript GlobalDeclarationInstantiation from the declaration list in constant idx.
throw_const_assign71Atom50 → 0BasicTypeError 'x' is read-only.
get_field72Atom, Cache71 → 1Accessobj -> v
get_method73Atom, Cache71 → 2Accessobj -> f obj: callee and this for a method call.
put_field74Atom, Cache72 → 0Accessobj v ->
get_elem75–12 → 1Accessobj key -> v
get_elem276–12 → 3Accessobj key -> obj key' v: get_elem keeping the reference for a compound assignment or update, with key' = ToPrimitive(key) (one conversion for the get and the put, after the RequireObjectCoercible of obj).
to_propkey77–11 → 1Basickey -> key': ToPrimitive(key, string) now, for a computed key whose definition comes after other code ({ [k]: v }: ToPropertyKey before v). Primitives stay.
get_elem_method78–12 → 2Accessobj key -> f obj
put_elem79–13 → 0Accessobj key v ->
define_field80Atom, Cache72 → 1Accessobj v -> obj: CreateDataProperty (literals).
define_elem81–13 → 1Accessobj key v -> obj: computed keys.
define_getter82Atom52 → 1Accessobj f -> obj
define_setter83Atom52 → 1Accessobj f -> obj
define_getter_elem84–13 → 1Accessobj key f -> obj
define_setter_elem85–13 → 1Accessobj key f -> obj
define_method86Atom52 → 1Accessobj f -> obj: also sets the home object.
define_method_elem87–13 → 1Accessobj key f -> obj
set_proto88–12 → 1Basicobj v -> obj: a literal __proto__: v sets the prototype when v is an object or null (other values are ignored).
set_function_name89U822 → 2Basickey f -> key f: SetFunctionName(f, ToPropertyKey(key), prefix) for an anonymous function under a computed key (prefix: 0 none, 1 “get”, 2 “set”).
copy_data_props90U822 → 1Accessobj src -> obj: object spread / rest (flags select the variant).
delete91–12 → 1Accessobj key -> bool
in92–12 → 1Accesskey obj -> bool
private_symbol93Atom, U860 → 1Alloc-> sym: a new private name (a private symbol described #x). flags: heap::cells::flags::SYM_PRIVATE_METHOD (a method or accessor) and SYM_PRIVATE_READONLY (no setter).
get_private_field94–12 → 1Accessobj sym -> v: obj.#x (own properties only, never a proxy trap; a getter is called).
put_private_field95–13 → 0Accessobj sym v ->: obj.#x = v (a setter is called).
define_private_field96U823 → 1Accessobj sym v -> obj: adds a private field (kind 0) or method (1), ignoring extensibility; TypeError if obj has it already.
define_private_accessor97–14 → 1Accessobj sym getter setter -> obj: adds a private accessor (undefined for a missing half).
private_in98–12 → 1Accesssym obj -> bool: #x in obj.
get_super99–11 → 1Accesso -> o.[[GetPrototypeOf]](): the base of a super property (from the home object), or the super constructor (from the active function).
get_super_field100Atom52 → 1Accessthis base -> v: super.x, base.[[Get]](x, this).
put_super_field101Atom53 → 0Accessthis base v ->: super.x = v, base.[[Set]](x, v, this).
get_super_elem102–13 → 1Accessthis base key -> v
put_super_elem103–14 → 0Accessthis base key v ->
set_home_object104–12 → 2Basichome f -> home f: sets the home object of f (class field initializers).
define_class105U823 → 2Allocparent protoParent ctor -> ctor proto: ClassDefinitionEvaluation’s prototype and constructor setup. flags bit 0: there is a heritage (parent and protoParent, checked by %ClassHeritage, are used; otherwise ignored).
define_class_method106Atom, U862 → 1Accessobj f -> obj: a class method (kind 0), getter (1) or setter (2): non-enumerable, and sets the home object.
define_class_method_elem107U823 → 1Accessobj key f -> obj
define_class_field108–13 → 1Accessobj key v -> obj: a public class field (CreateDataPropertyOrThrow).
require_object_coercible109–11 → 1Basicv -> v: TypeError for null/undefined (destructuring).
neg110–11 → 1Basica -> -a
plus111–11 → 1Basica -> +a (ToNumber)
bnot112–11 → 1Basica -> ~a
not113–11 → 1Basica -> !a
typeof114–11 → 1Basica -> typeof a
inc115–11 → 1Basica -> a + 1 (numeric)
dec116–11 → 1Basica -> a - 1 (numeric)
to_numeric117–11 → 1Basica -> ToNumeric(a) (postfix ++/--)
to_string118–11 → 1Basica -> ToString(a) (template substitutions)
add119–12 → 1Basica b -> a + b
sub120–12 → 1Basica b -> a - b
mul121–12 → 1Basica b -> a * b
div122–12 → 1Basica b -> a / b
mod123–12 → 1Basica b -> a % b
pow124–12 → 1Basica b -> a ** b
shl125–12 → 1Basica b -> a << b
sar126–12 → 1Basica b -> a >> b
shr127–12 → 1Basica b -> a >>> b
band128–12 → 1Basica b -> a & b
bor129–12 → 1Basica b -> a | b
bxor130–12 → 1Basica b -> a ^ b
lt131–12 → 1Basica b -> a < b
le132–12 → 1Basica b -> a <= b
gt133–12 → 1Basica b -> a > b
ge134–12 → 1Basica b -> a >= b
eq135–12 → 1Basica b -> a == b
ne136–12 → 1Basica b -> a != b
strict_eq137–12 → 1Basica b -> a === b
strict_ne138–12 → 1Basica b -> a !== b
instanceof139–12 → 1Accessa b -> a instanceof b
is_nullish140–11 → 1Basicv -> v is null or undefined
is_undefined141–11 → 1Basicv -> v === undefined
concat142Count3imm0 → 1Allocs1 .. sn -> s: join template literal parts in one allocation.
jump143Target50 → 0BasicUnconditional jump.
jump_if_false144Target51 → 0Basicv ->: jump if ToBoolean(v) is false.
jump_if_true145Target51 → 0Basicv ->: jump if ToBoolean(v) is true.
gosub146Target50 → 1Basic-> ret: push the return address (an int32) and jump (enter a finally).
ret147–11 → 0Basicret ->: jump to the popped return address.
throw148–11 → 0Basicv ->: throw v.
return149–11 → 0Basicv ->: return v.
return_undef150–10 → 0BasicReturn undefined.
call151Argc32+imm0 → 1Callf this a1 .. an -> r
construct152Argc31+imm0 → 1Callf a1 .. an -> r: new f(...), new.target = f.
call_spread153–13 → 1Callf this args -> r: call with an argument array (spread).
construct_spread154–12 → 1Callf args -> r
super_call155Argc32+imm0 → 1Callf a1 .. an newTarget -> r: super(...) in a derived constructor: constructs f (the super constructor) with that new.target.
super_call_spread156–13 → 1Callf args newTarget -> r: super(...args) with an argument array (spread).
call_intrinsic157Intrinsic, Argc5imm1 → 1Calla1 .. an -> r: privileged code only.
generator_start158Loc30 → 0AllocGenerator function entry: creates the generator object, stores it in local generator, suspends the frame (to resume at the next instruction) and returns the object to the caller.
yield159Loc31 → 2Allocv -> received isReturn: suspends the generator in local generator, handing v to the resumer. Resumed by next(x): x false; by return(x): x true (the code returns x, running finally blocks); throw(e) throws e here.
yield_star160Loc31 → 2AllocinnerResult -> received isReturn: yield for yield* in a sync generator: the resumer hands innerResult (the inner iterator’s result object) on as it is, without reading value or wrapping it (GeneratorYield ( innerResult )).
async_start161Loc30 → 0AllocAsync function entry: creates the async state (with the result promise) in local state. The function runs on synchronously.
await162Loc31 → 1Allocv -> result: suspends the async function of local state until v settles, then pushes its value or throws its reason here. The first await returns the result promise to the caller.
async_return163Loc31 → 0Callv ->: return from an async function: resolves the result promise with v and returns the promise.
async_reject164Loc31 → 0Calle ->: an exception leaves an async function: rejects the result promise with e and returns the promise (the target of the body’s catch-all handler).
get_iterator165–11 → 1Accessobj -> iterator
iter_next166Target52 → 1Callit next -> r: r = next.call(it), an iterator result. When next is the original next of an Array or String Iterator and that step runs no user code, r is the next value itself and the instruction jumps (no result object, D1800).
iter_check_object167–11 → 1Basicv -> v: TypeError if v is not an object (iterator results).
iterator_close168–11 → 0Accessiterator ->: call iterator.return() if present.
for_in_start169–11 → 1Allocobj -> for-in iterator (a snapshot of the enumerable keys)
for_in_next170–11 → 3Accessit -> it key done
check_ctor171–10 → 0BasicTypeError if a class constructor is called without new.
check_this172–11 → 1Basicv -> v: a derived constructor’s this: ReferenceError while uninitialized (undefined, before super()).
check_this_uninit173–11 → 0Basicv ->: before super() binds this: ReferenceError if it is bound already.
check_ctor_return174–11 → 1Basicv -> v: a derived constructor’s return value: TypeError unless an object or undefined.
throw_error175Atom, U860 → 0BasicThrows a new error with message atom; kind 0: TypeError, 1: ReferenceError.
debugger176–10 → 0Freedebugger (no effect).
nop177–10 → 0FreeNo operation.