Skip to main content

Module serialize

Module serialize 

Source
Expand description

Serialisation of compiled bytecode.

The format is our own — it deliberately does not interoperate with the C implementation’s binary blobs — but it keeps the same semantics: a compiled function can be written out and read back without the source, which is what qjsc relies on for ahead-of-time compilation.

Layout, all integers big-endian:

magic    4 bytes  "QJSB"
version  u16      format version
function          one function record, recursively

function record:
  name        string (u32 length + UTF-8 bytes)
  kind        u8
  flags       u8    bit 0 = strict
  line, column u32 each
  args        u32 count, then name/flags records
  vars        u32 count, then name/flags/scope records
  closures    u32 count, then name/flags/type/index records
  cpool       u32 count, then constants
  code        u32 length + bytes
  stack_size  u32
  var_refs    u32
  positions   u32 count, then pc/line/column u32 each

A version bump is required for any change to this layout; MAGIC plus VERSION make a stale blob fail loudly instead of being misinterpreted.

Enums§

DecodeError
Why a blob could not be read.

Constants§

MAGIC
File magic.
VERSION
Format version. Bumped whenever the layout below changes.

Functions§

deserialize
Read a compiled function back.
serialize
Write a compiled function, including its nested functions.