glados-0.1.0.0
Stabilitystable
Safe HaskellSafe-Inferred
LanguageHaskell2010

Compiler.Bytecode.Encoder

Description

This module provides helper functions to encode primitive values into binary form using Builder. These functions are used by the assembler and encoder stages to produce the final bytecode stream.

Supported encodings: - 32-bit signed integers (big-endian) - Single bytes (Word8) - Booleans (encoded as 0 or 1) - UTF-8 strings with length prefix

Synopsis

Documentation

encodeInt32BE :: Int32 -> Builder Source #

Encode a signed 32-bit integer in big-endian format.

This function emits exactly 4 bytes corresponding to the given Int32 value, encoded in network byte order (big-endian).

It is primarily used for instruction operands such as relative offsets, indices, and immediate integer values.

encodeWord8 :: Word8 -> Builder Source #

Encode a single byte.

Writes the given Word8 value as-is into the output stream. This function is typically used to encode opcodes and small immediate values.

encodeBool :: Bool -> Builder Source #

Encode a boolean value as a single byte.

Encoding convention:

This representation is used consistently throughout the bytecode format.

encodeString :: String -> Builder Source #

Encode a UTF-8 string with a length prefix.

The string is first encoded as UTF-8, then preceded by a 32-bit big-endian integer representing the number of bytes in the encoded string.

Layout:

[length: Int32][utf8-bytes...]

This encoding is suitable for constant strings, symbol names, or metadata embedded in the bytecode.