Skip to content

TIL Compiler API

Andrea Fioraldi edited this page Mar 8, 2017 · 2 revisions

Data types

til_bytes_t

A stack data type that works with bytes. It is used inside the compiler to store bytecode.

struct _til_bytes;
typedef struct _til_bytes* til_bytes_t;

Functions

til_bytes_create

Alloc and initialize a til_bytes_t instance.

til_bytes_t til_bytes_create();

til_bytes_add

Append a byte to a til_bytes_t instance.

void til_bytes_add
	(til_bytes_t bytes, unsigned char b);

til_bytes_add_str

Append a bytes array to a til_bytes_t instance.

void til_bytes_add_str
	(til_bytes_t bytes, unsigned char* a, size_t l);

til_bytes_add_short

Serialize and append a signed 16 bit integer to a til_bytes_t instance. Little-endian format is used for serialization.

void til_bytes_add_short
	(til_bytes_t bytes, int16_t n);

til_bytes_add_ushort

Serialize and append an unsigned 16 bit integer to a til_bytes_t instance. Little-endian format is used for serialization.

void til_bytes_add_ushort
	(til_bytes_t bytes, uint16_t n);

til_bytes_add_int

Serialize and append a signed 32 bit integer to a til_bytes_t instance. Little-endian format is used for serialization.

void til_bytes_add_int
	(til_bytes_t bytes, int32_t n);

til_bytes_add_uint

Serialize and append an unsigned 32 bit integer to a til_bytes_t instance. Little-endian format is used for serialization.

void til_bytes_add_uint
	(til_bytes_t bytes, uint32_t n);

til_bytes_add_long

Serialize and append a signed 64 bit integer to a til_bytes_t instance. Little-endian format is used for serialization.

void til_bytes_add_long
	(til_bytes_t bytes, int64_t n);

til_bytes_add_ulong

Serialize and append an unsigned 64 bit integer to a til_bytes_t instance. Little-endian format is used for serialization.

void til_bytes_add_ulong
	(til_bytes_t bytes, uint64_t n);

til_bytes_add_float32

Serialize and append a 32 bit floating point number to a til_bytes_t instance. Little-endian format is used for serialization.

void til_bytes_add_float32
	(til_bytes_t bytes, float n);

til_bytes_add_float64

Serialize and append a 64 bit floating point number to a til_bytes_t instance. Little-endian format is used for serialization.

void til_bytes_add_float64
	(til_bytes_t bytes, double n);

til_bytes_cat

Concatenate a til_bytes_t instance to another.

void til_bytes_cat
	(til_bytes_t bytes, til_bytes_t b);

til_bytes_print

Write a til_bytes_t instance to a file

void til_bytes_print
	(til_bytes_t bytes, FILE* file);

til_bytes_get_buffer

Copy the internal buffer of a til_bytes_t instance and return it.

unsigned char* til_bytes_get_buffer
	(til_bytes_t bytes);

til_bytes_get_buffer_size

Return the number of bytes stored in a til_bytes_t instance.

size_t til_bytes_get_buffer_size
	(til_bytes_t bytes);

til_serialize_type

Compile a type id string to bytecode, return 0 on success.

int til_serialize_type
	(char *type, til_bytes_t bytes);

til_compile

The core function of the library. Compile a TIL source string to bytecode.

On failure return NULL and set the content of err_ptr to the generated error. In this case *err_ptr must be freed.

til_bytes_t til_compile
	(char *source, char** err_ptr);

til_assembler

Compile only the assembly code inside functions.

On failure return NULL and write the error in the err stack.

til_bytes_t til_assembler
	(char* assembly, int initial_line, til_bytes_t err);