jcc.h

Includes:
<stdint.h>
<stdbool.h>
<stddef.h>
<stdio.h>
<stdarg.h>
<setjmp.h>
<errno.h>
<sys/stat.h>
<time.h>
<string.h>
<stdlib.h>
<ctype.h>
<math.h>
<assert.h>
<libgen.h>
<windows.h>
<unistd.h>
<dlfcn.h>
<ffi.h>

Introduction

Use the links in the table of contents to the left to access the documentation.



Functions

cc_add_breakpoint

Add a breakpoint at a specific program counter address.

cc_add_watchpoint

Add a watchpoint at a specific memory address.

cc_compile

Compile the parsed program (Obj list) into VM bytecode.

cc_debug_repl

Enter interactive debugger REPL (Read-Eval-Print Loop).

cc_define

Define or override a preprocessor macro for the given VM.

cc_destroy

Free resources owned by an JCC instance.

cc_dlopen(JCC *, const char *)

Load a dynamic library and resolve all registered FFI functions.

cc_dlopen(JCC *, const char *)

Open a dynamic library.

cc_dlsym(JCC *, const char *, void *, int, int)

Update an existing registered FFI function's pointer by name.

cc_dlsym(JCC *, const char *, void *, int, int)

Resolve a symbol in a dynamic library.

cc_find_function_entry

Find program counter address for a function entry point by name.

cc_find_pc_for_source

Find program counter address for a given source location.

cc_get_source_location

Get source file location for a given program counter.

cc_include

Add a directory to the compiler's header search paths.

cc_init

Initialize an JCC instance.

cc_link_progs

Link multiple parsed programs (Obj lists) into a single program.

cc_load_bytecode

Load compiled bytecode from a file.

cc_load_libc

Load the platform's standard C library and resolve FFI functions.

cc_load_stdlib

Register all standard library functions available via FFI.

cc_lookup_symbol

Look up a debug symbol by name in current scope.

cc_output_json

Output C header declarations as JSON for FFI wrapper generation.

cc_parse

Parse a preprocessed token stream into an AST and produce a linked list of top-level Obj declarations.

cc_parse_assign

Parse an assignment expression from token stream (stops at commas).

cc_parse_compound_stmt

Parse a compound statement (block) from token stream.

cc_parse_expr

Parse a single C expression from token stream.

cc_parse_stmt

Parse a single C statement from token stream.

cc_preprocess

Run the preprocessor on a C source file and return a token stream.

cc_print_stack_report

Print stack instrumentation statistics and report.

cc_print_tokens

Print a token stream to stdout (useful for debugging the preprocessor and tokenizer).

cc_register_cfunc

Register a native C function to be callable from VM code via FFI.

cc_register_variadic_cfunc

Register a variadic native C function to be callable from VM code via FFI.

cc_remove_breakpoint

Remove a breakpoint by index.

cc_remove_watchpoint

Remove a watchpoint by index.

cc_run

Execute the compiled program within the VM.

cc_save_bytecode

Save compiled bytecode to a file for later execution.

cc_set_asm_callback

Register a callback invoked for `asm("...")` statements.

cc_system_include

Add a directory to the compiler's system header search paths.

cc_undef

Remove a preprocessor macro definition from the VM.


cc_add_breakpoint


Add a breakpoint at a specific program counter address.

int cc_add_breakpoint(
    JCC *vm,
    long long *pc);  
Parameters
vm

The JCC instance.

pc

Program counter address where breakpoint should be set.

Return Value

Breakpoint index, or -1 if failed (too many breakpoints).


cc_add_watchpoint


Add a watchpoint at a specific memory address.

int cc_add_watchpoint(
    JCC *vm,
    void *address,
    int size,
    int type,
    const char *expr);  
Parameters
vm

The JCC instance.

address

Memory address to watch.

size

Size of memory region to watch (in bytes).

type

Watchpoint type flags (WATCH_READ | WATCH_WRITE | WATCH_CHANGE).

expr

Original expression string (for display purposes).

Return Value

Watchpoint index, or -1 if failed (too many watchpoints).


cc_compile


Compile the parsed program (Obj list) into VM bytecode.

void cc_compile(
    JCC *vm,
    Obj *prog);  
Parameters
vm

The JCC instance.

prog

Linked list of top-level Obj returned by cc_parse.


cc_debug_repl


Enter interactive debugger REPL (Read-Eval-Print Loop).

void cc_debug_repl(
    JCC *vm);  
Parameters
vm

The JCC instance.

Discussion

Provides an interactive shell for debugging with commands like: - break/b: Set breakpoint - continue/c: Continue execution - step/s: Single step - next/n: Step over - finish/f: Step out - print/p: Print registers - stack/st: Print stack - help/h: Show help


cc_define


Define or override a preprocessor macro for the given VM.

void cc_define(
    JCC *vm,
    char *name,
    char *buf);  
Parameters
vm

The JCC instance.

name

Macro identifier (NUL-terminated).

buf

Macro replacement text (NUL-terminated).


cc_destroy


Free resources owned by an JCC instance.

void cc_destroy(
    JCC *vm);  
Parameters
vm

The JCC instance to destroy.

Discussion

Does not free the `JCC` struct itself; the caller is responsible for the memory of the struct if it was dynamically allocated.


cc_dlopen(JCC *, const char *)


Load a dynamic library and resolve all registered FFI functions.

int cc_dlopen(
    JCC *vm,
    const char *lib_path);  
Parameters
vm

The JCC instance.

lib_path

Path to the dynamic library (.so, .dylib, .dll) or NULL for default libraries.

Return Value

0 on success, -1 on error.

Discussion

This function opens a dynamic library and attempts to resolve all currently registered FFI functions. Functions that cannot be resolved will print warnings but won't fail the entire operation. If lib_path is NULL, the function searches in default system libraries.

Platform-specific behavior: - Unix: Uses dlopen/dlsym to load .so/.dylib files - Windows: Uses LoadLibrary/GetProcAddress to load .dll files

The library handle is not closed after loading to keep function pointers valid.


cc_dlopen(JCC *, const char *)


Open a dynamic library.

int cc_dlopen(
    JCC *vm,
    const char *lib_path);  
Parameters
vm

The JCC instance.

lib_path

Path to the dynamic library to open.

Return Value

0 on success, -1 on failure.


cc_dlsym(JCC *, const char *, void *, int, int)


Update an existing registered FFI function's pointer by name.

int cc_dlsym(
    JCC *vm,
    const char *name,
    void *func_ptr,
    int num_args,
    int returns_double);  
Parameters
vm

The JCC instance.

name

Function name to update.

func_ptr

New function pointer to assign.

num_args

Expected number of arguments (must match registered function).

returns_double

Expected return type (must match registered function).

Return Value

0 on success, -1 on error (function not found or signature mismatch).

Discussion

This function is useful for updating function pointers after loading a dynamic library, or for redirecting calls to different implementations. The function must already be registered via cc_register_cfunc or cc_register_variadic_cfunc.


cc_dlsym(JCC *, const char *, void *, int, int)


Resolve a symbol in a dynamic library.

int cc_dlsym(
    JCC *vm,
    const char *name,
    void *func_ptr,
    int num_args,
    int returns_double);  
Parameters
vm

The JCC instance.

name

Name of the symbol to resolve.

func_ptr

Pointer to the function to resolve.

num_args

Number of arguments the function expects.

returns_double

1 if function returns double, 0 if returns long long.

Return Value

0 on success, -1 on failure.


cc_find_function_entry


Find program counter address for a function entry point by name.

long long *cc_find_function_entry(
    JCC *vm,
    const char *name);  
Parameters
vm

The JCC instance.

name

Function name to find.

Return Value

Program counter address, or NULL if not found.


cc_find_pc_for_source


Find program counter address for a given source location.

long long *cc_find_pc_for_source(
    JCC *vm,
    File *file,
    int line);  
Parameters
vm

The JCC instance.

file

Source file (NULL to search in any file).

line

Line number to find.

Return Value

Program counter address, or NULL if not found.


cc_get_source_location


Get source file location for a given program counter.

int cc_get_source_location(
    JCC *vm,
    long long *pc,
    File **out_file,
    int *out_line);  
Parameters
vm

The JCC instance.

pc

Program counter address.

out_file

Pointer to receive the source File pointer (can be NULL).

out_line

Pointer to receive the line number (can be NULL).

Return Value

1 if location found, 0 if not found.


cc_include


Add a directory to the compiler's header search paths.

void cc_include(
    JCC *vm,
    const char *path);  
Parameters
vm

The JCC instance.

path

Filesystem path to add to include search.

Discussion

This adds the path to the list of directories searched for "..." includes (quote includes).


cc_init


Initialize an JCC instance.

void cc_init(
    JCC *vm,
    uint32_t flags);  
Parameters
vm

Pointer to an uninitialized JCC struct to initialize.

flags

Bitwise combination of JCCFlags to enable features (0 for none).

Discussion

The caller should allocate an `JCC` struct (usually on the stack) and pass its pointer to this function. This sets up memory segments, default include paths, and other runtime defaults.


cc_link_progs


Link multiple parsed programs (Obj lists) into a single program.

Obj *cc_link_progs(
    JCC *vm,
    Obj **progs,
    int count);  
Parameters
vm

The JCC instance.

progs

Array of Obj* programs (linked lists from cc_parse).

count

Number of programs in the array.

Return Value

A single merged Obj* linked list containing all objects.

Discussion

Takes an array of Obj* programs and combines them into one linked list. This allows multiple source files to be compiled together into a single program. The function handles duplicate definitions by preferring definitions over declarations.


cc_load_bytecode


Load compiled bytecode from a file.

int cc_load_bytecode(
    JCC *vm,
    const char *path);  
Parameters
vm

The JCC instance to load bytecode into.

path

Input file path.

Return Value

0 on success, -1 on error.

Discussion

Deserializes bytecode previously saved with cc_save_bytecode() and prepares the VM for execution with cc_run().


cc_load_libc


Load the platform's standard C library and resolve FFI functions.

int cc_load_libc(
    JCC *vm);  
Parameters
vm

The JCC instance.

Return Value

0 on success, -1 on error.

Discussion

This function automatically detects and loads the correct C library for the current platform: - macOS: /usr/lib/libSystem.dylib - Linux: /lib64/libc.so.6 (or /lib/libc.so.6 on 32-bit) - FreeBSD: /lib/libc.so.7 - Windows: msvcrt.dll This is useful when you want to load stdlib functions dynamically instead of registering them with explicit function pointers.


cc_load_stdlib


Register all standard library functions available via FFI.

void cc_load_stdlib(
    JCC *vm);  
Parameters
vm

The JCC instance.

Discussion

Automatically registers 50+ standard library functions including: - Memory: malloc, free, calloc, realloc, memcpy, memmove, memset, memcmp - String: strlen, strcpy, strncpy, strcat, strcmp, strncmp, strchr, strstr - I/O: puts, putchar, getchar, fopen, fclose, fread, fwrite, fgetc, fputc - Math: sin, cos, tan, sqrt, pow, exp, log, floor, ceil, fabs - Conversion: atoi, atol, atof, strtol, strtod - System: exit, abort, system, open, close, read, write

This function is automatically called by cc_init(), but can be called manually if you want to reset the FFI registry or initialize it separately.


cc_lookup_symbol


Look up a debug symbol by name in current scope.

DebugSymbol *cc_lookup_symbol(
    JCC *vm,
    const char *name);  
Parameters
vm

The JCC instance.

name

Symbol name to look up.

Return Value

Pointer to DebugSymbol if found, NULL otherwise.


cc_output_json


Output C header declarations as JSON for FFI wrapper generation.

void cc_output_json(
    FILE *f,
    Obj *prog);  
Parameters
f

Output file stream (e.g., stdout or file opened with fopen).

prog

Head of the parsed AST object list (from cc_parse).

Discussion

Serializes function signatures, struct/union definitions, enum declarations, and global variables from the parsed AST to JSON format. The output includes full type information with recursive expansion of pointers, arrays, and aggregate types. Storage class specifiers (static, extern) are included. Function bodies are not serialized - only signatures.

The JSON output format is: { "functions": [...], "structs": [...], "unions": [...], "enums": [...], "variables": [...] }


cc_parse


Parse a preprocessed token stream into an AST and produce a linked list of top-level Obj declarations.

Obj *cc_parse(
    JCC *vm,
    Token *tok);  
Parameters
vm

The JCC instance.

tok

Head of the preprocessed token stream.

Return Value

Linked list of top-level Obj representing globals and functions.


cc_parse_assign


Parse an assignment expression from token stream (stops at commas).

Node *cc_parse_assign(
    JCC *vm,
    Token **rest,
    Token *tok);  
Parameters
vm

The JCC instance.

rest

Pointer to receive the remaining tokens after parsing.

tok

Head of the token stream to parse.

Return Value

AST node representing the parsed assignment expression.

Discussion

Used for parsing function arguments and other contexts where commas are separators rather than operators.


cc_parse_compound_stmt


Parse a compound statement (block) from token stream.

Node *cc_parse_compound_stmt(
    JCC *vm,
    Token **rest,
    Token *tok);  
Parameters
vm

The JCC instance.

rest

Pointer to receive the remaining tokens after parsing.

tok

Head of the token stream to parse (should be opening brace).

Return Value

AST node representing the parsed compound statement.


cc_parse_expr


Parse a single C expression from token stream.

Node *cc_parse_expr(
    JCC *vm,
    Token **rest,
    Token *tok);  
Parameters
vm

The JCC instance.

rest

Pointer to receive the remaining tokens after parsing.

tok

Head of the token stream to parse.

Return Value

AST node representing the parsed expression.


cc_parse_stmt


Parse a single C statement from token stream.

Node *cc_parse_stmt(
    JCC *vm,
    Token **rest,
    Token *tok);  
Parameters
vm

The JCC instance.

rest

Pointer to receive the remaining tokens after parsing.

tok

Head of the token stream to parse.

Return Value

AST node representing the parsed statement.


cc_preprocess


Run the preprocessor on a C source file and return a token stream.

Token *cc_preprocess(
    JCC *vm,
    const char *path);  
Parameters
vm

The JCC instance.

path

Path to the source file to preprocess.

Return Value

Head of the token stream (linked Token list). Caller owns tokens.


cc_print_stack_report


Print stack instrumentation statistics and report.

Parameters
vm

The JCC instance.

Discussion

Outputs stack usage statistics including high water mark, variable access counts, and scope information. Only useful when stack instrumentation is enabled.


cc_print_tokens


Print a token stream to stdout (useful for debugging the preprocessor and tokenizer).

void cc_print_tokens(
    Token *tok);  
Parameters
tok

Head of the token stream to print.


cc_register_cfunc


Register a native C function to be callable from VM code via FFI.

void cc_register_cfunc(
    JCC *vm,
    const char *name,
    void *func_ptr,
    int num_args,
    int returns_double);  
Parameters
vm

The JCC instance.

name

Function name (must match declarations in C source).

func_ptr

Pointer to the native C function.

num_args

Number of arguments the function expects.

returns_double

1 if function returns double, 0 if returns long long.

Discussion

Registered functions can be called from C code compiled to VM bytecode. The CALLF instruction handles argument marshalling. All integer types are passed/returned as long long, floats as double.


cc_register_variadic_cfunc


Register a variadic native C function to be callable from VM code via FFI.

void cc_register_variadic_cfunc(
    JCC *vm,
    const char *name,
    void *func_ptr,
    int num_fixed_args,
    int returns_double);  
Parameters
vm

The JCC instance.

name

Function name (must match declarations in C source).

func_ptr

Pointer to the native C variadic function.

num_fixed_args

Number of fixed arguments before the ... (e.g., printf has 1: format string).

returns_double

1 if function returns double, 0 if returns long long.

Discussion

This function is only available when JCC_HAS_FFI is defined. When libffi is not available, use fixed-argument wrappers instead. Variadic functions accept a variable number of arguments after the fixed arguments. Example: printf has 1 fixed arg (format), fprintf has 2 (stream, format).


cc_remove_breakpoint


Remove a breakpoint by index.

void cc_remove_breakpoint(
    JCC *vm,
    int index);  
Parameters
vm

The JCC instance.

index

Breakpoint index to remove.


cc_remove_watchpoint


Remove a watchpoint by index.

void cc_remove_watchpoint(
    JCC *vm,
    int index);  
Parameters
vm

The JCC instance.

index

Watchpoint index to remove.


cc_run


Execute the compiled program within the VM.

int cc_run(
    JCC *vm,
    int argc,
    char **argv);  
Parameters
vm

The JCC instance containing compiled bytecode.

argc

Argument count to pass to the program's main().

argv

Argument vector (NUL-terminated array of strings).

Return Value

Program exit code returned by main().


cc_save_bytecode


Save compiled bytecode to a file for later execution.

int cc_save_bytecode(
    JCC *vm,
    const char *path);  
Parameters
vm

The JCC instance containing compiled bytecode.

path

Output file path.

Return Value

0 on success, -1 on error.

Discussion

Serializes the text segment, data segment, and necessary metadata to a binary file. The file can be loaded and executed by cc_load_bytecode().


cc_set_asm_callback


Register a callback invoked for `asm("...")` statements.

void cc_set_asm_callback(
    JCC *vm,
    JCCAsmCallback callback,
    void *user_data);  
Parameters
vm

The JCC instance.

callback

Callback function pointer, or NULL to unregister.

user_data

Optional user context pointer passed to the callback.


cc_system_include


Add a directory to the compiler's system header search paths.

void cc_system_include(
    JCC *vm,
    const char *path);  
Parameters
vm

The JCC instance.

path

Filesystem path to add to system include search.

Discussion

This adds the path to the list of directories searched for <...> includes (angle bracket includes). System include paths are searched after regular include paths for "..." includes.


cc_undef


Remove a preprocessor macro definition from the VM.

void cc_undef(
    JCC *vm,
    char *name);  
Parameters
vm

The JCC instance.

name

Macro identifier to remove.


Typedefs

AllocHeader

Metadata header stored before each heap allocation for tracking.

AllocRecord

Tracks an active heap allocation for leak detection.

CondIncl

Stack entry used to track nested #if/#elif/#else processing during preprocessing.

DebugSymbol

Represents a variable's debug information for expression evaluation.

EnumConstant

Represents an enumerator constant within an enum type.

File

Represents the contents and metadata of a source file.

ForeignFunc

Represents a registered foreign (native C) function callable from VM code.

FreeBlock

Free list node for tracking freed memory blocks.

GotoPatch

Records a forward jump (JMP) that must be patched once the destination label is defined.

HashEntry

Simple key/value bucket used by the project's HashMap.

HashMap

Lightweight open-addressing hashmap used for symbol tables, macros, and other small maps.

Hideset

Represents a set of macro names that have been hidden to prevent recursive macro expansion.

JCC_OP

VM instruction opcodes for the JCC bytecode.

JCCAsmCallback

Callback invoked when an `asm("...")` statement is encountered during code generation.

JCCFlags

Bitwise flags for JCC runtime features and safety checks.

LabelEntry

Tracks labels used for goto and labeled statements and their defined addresses in the generated text segment.

Member

Member (field) descriptor for struct and union types.

NodeKind

Kinds of AST nodes produced by the parser.

PragmaMacro

Represents a pragma macro function.

ProvenanceInfo

Tracks pointer provenance (origin) for validation.

Relocation

A relocation record for a global variable initializer that references another global symbol.

Scope

Represents a parser block scope. Two kinds of block scopes are used: one for variables/typedefs and another for tags.

SourceMap

Maps bytecode offsets to source file locations for debugger support.

StackPtrInfo

Tracks stack pointer information for dangling pointer detection.

StackVarMeta

Unified metadata for stack variable instrumentation.

StringArray

Dynamic array of strings used for include paths and similar small lists.

Token

Token produced by the lexer or by macro expansion.

TokenKind

Kinds of lexical tokens produced by the tokenizer and used by the preprocessor and parser.

TypeKind

Kind tag for the `Type` structure describing C types.


AllocHeader


Metadata header stored before each heap allocation for tracking.

typedef struct AllocHeader { 
    size_t size; // Allocated size (rounded, excluding header) 
    size_t requested_size; // Original requested size (for bounds checking) 
    int magic; // Magic number for debugging (0xDEADBEEF) 
    long long canary; // Front canary (if heap canaries enabled) 
    int freed; // 1 if freed (for UAF detection) 
    int generation; // Generation counter (incremented on free) 
    long long alloc_pc; // PC at allocation site (for leak detection) 
    int type_kind; // Type of allocation (TypeKind enum, for type checking) 
} AllocHeader;  
Fields
size

Size of allocation (excluding header), rounded up for alignment

requested_size

Original requested size (for bounds checking)

magic

Magic number (0xDEADBEEF) for detecting corruption.

canary

Front canary value for heap overflow detection (when enabled)

freed

Flag indicating if this block has been freed (for UAF detection)

generation

Generation counter incremented on each free (for UAF detection)

alloc_pc

Program counter at allocation site (for debugging)

type_kind

Type of allocation (for type checking on dereference)


AllocRecord


Tracks an active heap allocation for leak detection.

typedef struct AllocRecord { 
    struct AllocRecord *next; 
    void *address; 
    size_t size; 
    long long alloc_pc; 
} AllocRecord;  
Fields
next

Pointer to next record in the list.

address

Address of the allocated memory (user pointer).

size

Size of the allocation in bytes.

alloc_pc

Program counter at allocation site.


CondIncl


Stack entry used to track nested #if/#elif/#else processing during preprocessing.

typedef struct CondIncl { 
    struct CondIncl *next; 
    enum {
        IN_THEN,
        IN_ELIF,
        IN_ELSE 
        } ctx; Token *tok; bool included; 
} CondIncl;  

DebugSymbol


Represents a variable's debug information for expression evaluation.

typedef struct DebugSymbol { 
    char *name; // Variable name 
    long long offset; // BP offset (locals) or data segment address (globals) 
    Type *ty; // Variable type 
    int is_local; // 1=local (BP-relative), 0=global (data segment) 
    int scope_depth; // Scope depth for shadowing resolution 
} DebugSymbol;  
Fields
name

Variable name (for lookup).

offset

Offset from BP (negative for locals) or address in data segment (globals).

ty

Type of the variable.

is_local

True if local variable (BP-relative), false if global.

scope_depth

Scope depth (for handling shadowing).


EnumConstant


Represents an enumerator constant within an enum type.

typedef struct EnumConstant { 
    char *name; 
    int value; 
    struct EnumConstant *next; 
} EnumConstant;  
Fields
name

Name of the enumerator.

value

Integer value of the enumerator.

next

Pointer to the next enumerator in the linked list.


File


Represents the contents and metadata of a source file.

typedef struct File { 
    char *name; 
    int file_no; 
    char *contents;  
    // For #line directive 
    char *display_name; 
    int line_delta; 
} File;  
Fields
name

Original filename string.

file_no

Unique numeric id for the file.

contents

File contents as a NUL-terminated buffer.

display_name

Optional name emitted by a `#line` directive.

line_delta

Line number delta applied for `#line` handling.


ForeignFunc


Represents a registered foreign (native C) function callable from VM code.

typedef struct ForeignFunc { 
    char *name; 
    void *func_ptr; 
    int num_args; 
    int returns_double; 
    int is_variadic; // 1 if function is variadic (e.g., printf), 0 otherwise 
    int num_fixed_args; // For variadic functions, number of fixed args (rest are variable) 
    #ifdef JCC_HAS_FFI 
    ffi_cif cif; // libffi call interface 
    ffi_type **arg_types; // Array of argument types (NULL if not prepared) 
    #endif  
} ForeignFunc;  
Fields
name

Function name (for lookup during compilation).

func_ptr

Pointer to the native C function.

num_args

Number of arguments the function expects (total for non-variadic, fixed args for variadic).

returns_double

True if function returns double, false if returns long long.

is_variadic

True if function is variadic (accepts ... arguments).

num_fixed_args

For variadic functions: number of fixed args before ... (e.g., printf has 1: format string).

cif

libffi call interface (only when JCC_HAS_FFI is defined).

arg_types

Array of argument types for libffi (NULL if not prepared, only when JCC_HAS_FFI is defined).


FreeBlock


Free list node for tracking freed memory blocks.

typedef struct FreeBlock { 
    struct FreeBlock *next; 
    size_t size; 
} FreeBlock;  
Fields
next

Pointer to next free block in the list.

size

Size of this free block (excluding header).


GotoPatch


Records a forward jump (JMP) that must be patched once the destination label is defined.

typedef struct GotoPatch { 
    char *name; // Label name to jump to 
    char *unique_label; // Or unique label identifier 
    long long *location; // Location of JMP instruction's address operand 
} GotoPatch;  

HashEntry


Simple key/value bucket used by the project's HashMap.

typedef struct HashEntry { 
    char *key; 
    int keylen; 
    void *val; 
} HashEntry;  
Fields
key

Null-terminated string key.

keylen

Length of the key in bytes.

val

Pointer to the stored value.


HashMap


Lightweight open-addressing hashmap used for symbol tables, macros, and other small maps.

typedef struct HashMap { 
    HashEntry *buckets; 
    int capacity; 
    int used; 
} HashMap;  
Fields
buckets

Pointer to an array of HashEntry buckets.

capacity

Number of buckets allocated.

used

Number of buckets currently in use.


Hideset


Represents a set of macro names that have been hidden to prevent recursive macro expansion.

typedef struct Hideset { 
    struct Hideset *next; 
    char *name; 
} Hideset;  

JCC_OP


VM instruction opcodes for the JCC bytecode.

typedef enum { 
    #define X(NAME) NAME, 
    OPS_X  #undef X 
} JCC_OP;  
Discussion

The VM is stack-based with an accumulator `ax`. These opcodes are emitted by the code generator and interpreted by the VM executor.


JCCAsmCallback


Callback invoked when an `asm("...")` statement is encountered during code generation.

typedef void ( *JCCAsmCallback)(
    JCC *vm,
    const char *asm_str,
    void *user_data);  
Parameters
vm

The VM/compiler instance.

asm_str

The asm string literal content.

user_data

User-provided context pointer (set via cc_set_asm_callback).

Discussion

The callback may emit custom bytecode into the VM's text segment, perform logging, or otherwise handle the asm string.


JCCFlags


Bitwise flags for JCC runtime features and safety checks.

typedef enum { 
    // Memory safety flags (bits 0-19) 
    JCC_BOUNDS_CHECKS = (
        1 << 0), // 0x00000001 - Array bounds checking 
    JCC_UAF_DETECTION = (
        1 << 1), // 0x00000002 - Use-after-free detection 
    JCC_TYPE_CHECKS = (
        1 << 2), // 0x00000004 - Runtime type checking 
    JCC_UNINIT_DETECTION = (
        1 << 3), // 0x00000008 - Uninitialized variable detection 
    JCC_OVERFLOW_CHECKS = (
        1 << 4), // 0x00000010 - Integer overflow detection 
    JCC_STACK_CANARIES = (
        1 << 5), // 0x00000020 - Stack canary protection 
    JCC_HEAP_CANARIES = (
        1 << 6), // 0x00000040 - Heap canary protection 
    JCC_MEMORY_LEAK_DETECT = (
        1 << 7), // 0x00000080 - Memory leak detection 
    JCC_STACK_INSTR = (
        1 << 8), // 0x00000100 - Stack variable instrumentation 
    JCC_DANGLING_DETECT = (
        1 << 9), // 0x00000200 - Dangling pointer detection 
    JCC_ALIGNMENT_CHECKS = (
        1 << 10), // 0x00000400 - Pointer alignment checking 
    JCC_PROVENANCE_TRACK = (
        1 << 11), // 0x00000800 - Pointer provenance tracking 
    JCC_INVALID_ARITH = (
        1 << 12), // 0x00001000 - Invalid pointer arithmetic detection 
    JCC_FORMAT_STR_CHECKS = (
        1 << 13), // 0x00002000 - Format string validation 
    JCC_RANDOM_CANARIES = (
        1 << 14), // 0x00004000 - Random canary values 
    JCC_MEMORY_POISONING = (
        1 << 15), // 0x00008000 - Poison allocated/freed memory 
    JCC_MEMORY_TAGGING = (
        1 << 16), // 0x00010000 - Temporal memory tagging 
    JCC_VM_HEAP = (
        1 << 17), // 0x00020000 - Force VM-managed heap 
    JCC_CFI = (
        1 << 18), // 0x00040000 - Control flow integrity 
    JCC_STACK_INSTR_ERRORS = (
        1 << 19), // 0x00080000 - Stack instrumentation errors 
    JCC_ENABLE_DEBUGGER = (
        1 << 20), // 0x00100000 - Interactive debugger  
    // Convenience flag combinations 
    JCC_POINTER_SANITIZER = (
        JCC_BOUNDS_CHECKS | JCC_UAF_DETECTION | JCC_TYPE_CHECKS), 
    JCC_ALL_SAFETY = 0x000FFFFF, // All safety features (bits 0-19)  
    // VM heap is auto-enabled when any of these flags are set 
    JCC_VM_HEAP_TRIGGERS = (
        JCC_VM_HEAP | JCC_HEAP_CANARIES | JCC_MEMORY_LEAK_DETECT | JCC_UAF_DETECTION | JCC_POINTER_SANITIZER | JCC_BOUNDS_CHECKS | JCC_MEMORY_TAGGING),  
    // Pointer validity checks 
    JCC_POINTER_CHECKS = (
        JCC_UAF_DETECTION | JCC_BOUNDS_CHECKS | JCC_DANGLING_DETECT | JCC_MEMORY_TAGGING), 
} JCCFlags;  
Discussion

These flags control memory safety features, debugging, and runtime behavior. Flags can be combined with bitwise OR. Some flags are convenience constants that represent multiple underlying flags.


LabelEntry


Tracks labels used for goto and labeled statements and their defined addresses in the generated text segment.

typedef struct LabelEntry { 
    char *name; // Label name (for named labels) 
    char *unique_label; // Unique label identifier (for break/continue) 
    long long *address; // Address in text segment where label is defined 
} LabelEntry;  

Member


Member (field) descriptor for struct and union types.

typedef struct Member { 
    struct Member *next; 
    Type *ty; 
    Token *tok; // for error message 
    Token *name; 
    int idx; 
    int align; 
    int offset;  
    // Bitfield 
    bool is_bitfield; 
    int bit_offset; 
    int bit_width; 
} Member;  
Fields
ty

Type of the member.

name

Token pointing to the member identifier.

offset

Byte offset of the member within its aggregate.


NodeKind


Kinds of AST nodes produced by the parser.

typedef enum { 
    ND_NULL_EXPR = 0, // Do nothing 
    ND_ADD = 1, // + 
    ND_SUB = 2, // - 
    ND_MUL = 3, // * 
    ND_DIV = 4, // / 
    ND_NEG = 5, // unary - 
    ND_MOD = 6, // % 
    ND_BITAND = 7, // & 
    ND_BITOR = 8, // | 
    ND_BITXOR = 9, // ^ 
    ND_SHL = 10, // << 
    ND_SHR = 11, // >> 
    ND_EQ = 12, // == 
    ND_NE = 13, // != 
    ND_LT = 14, // < 
    ND_LE = 15, // <= 
    ND_ASSIGN = 16, // = 
    ND_COND = 17, // ?: 
    ND_COMMA = 18, // , 
    ND_MEMBER = 19, // . (struct member access) 
    ND_ADDR = 20, // unary & 
    ND_DEREF = 21, // unary * 
    ND_NOT = 22, // ! 
    ND_BITNOT = 23, // ~ 
    ND_LOGAND = 24, // && 
    ND_LOGOR = 25, // || 
    ND_RETURN = 26, // "return" 
    ND_IF = 27, // "if" 
    ND_FOR = 28, // "for" or "while" 
    ND_DO = 29, // "do" 
    ND_SWITCH = 30, // "switch" 
    ND_CASE = 31, // "case" 
    ND_BLOCK = 32, // { ... } 
    ND_GOTO = 33, // "goto" 
    ND_GOTO_EXPR = 34, // "goto" labels-as-values 
    ND_LABEL = 35, // Labeled statement 
    ND_LABEL_VAL = 36, // [GNU] Labels-as-values 
    ND_FUNCALL = 37, // Function call 
    ND_EXPR_STMT = 38, // Expression statement 
    ND_STMT_EXPR = 39, // Statement expression 
    ND_VAR = 40, // Variable 
    ND_VLA_PTR = 41, // VLA designator 
    ND_NUM = 42, // Integer 
    ND_CAST = 43, // Type cast 
    ND_MEMZERO = 44, // Zero-clear a stack variable 
    ND_ASM = 45, // "asm" 
    ND_CAS = 46, // Atomic compare-and-swap 
    ND_EXCH = 47, // Atomic exchange 
} NodeKind;  

PragmaMacro


Represents a pragma macro function.

typedef struct PragmaMacro { 
    char *name; // Function name 
    Token *body_tokens; // Original token stream for function body 
    void *compiled_fn; // Compiled function pointer (returns Node*) 
    JCC *macro_vm; // VM instance for this macro 
    struct PragmaMacro *next; // Next macro in list 
} PragmaMacro;  
Fields
name

Function name.

body_tokens

Original token stream for function body (from preprocessor).

compiled_fn

Compiled function pointer (returns Node*).

macro_vm

VM instance for this macro (used for recursive macro calls).

next

Pointer to next macro in list.


ProvenanceInfo


Tracks pointer provenance (origin) for validation.

typedef struct ProvenanceInfo { 
    int origin_type; // 0=HEAP, 1=STACK, 2=GLOBAL 
    long long base; 
    size_t size; 
} ProvenanceInfo;  
Fields
origin_type

Type of origin: 0=HEAP, 1=STACK, 2=GLOBAL.

base

Base address of the original object.

size

Size of the original object.


Relocation


A relocation record for a global variable initializer that references another global symbol.

typedef struct Relocation { 
    struct Relocation *next; 
    int offset; 
    char **label; 
    long addend; 
} Relocation;  
Discussion

Each relocation describes a pointer-sized slot within a global's initializer data that must be patched with the address of another global (or label) when codegen finalizes the data segment.


Scope


Represents a parser block scope. Two kinds of block scopes are used: one for variables/typedefs and another for tags.

typedef struct Scope { 
    struct Scope *next; 
    // C has two block scopes; one is for variables/typedefs and 
    // the other is for struct/union/enum tags. 
    HashMap vars; 
    HashMap tags; 
} Scope;  

SourceMap


Maps bytecode offsets to source file locations for debugger support.

typedef struct SourceMap { 
    long long pc_offset; // Offset in text segment 
    File *file; // Source file 
    int line_no; // Line number in source 
} SourceMap;  
Fields
pc_offset

Offset in text segment (bytecode) where this mapping applies.

file

Source file containing this code.

line_no

Line number in source file.


StackPtrInfo


Tracks stack pointer information for dangling pointer detection.

typedef struct StackPtrInfo { 
    long long bp; 
    long long offset; 
    size_t size; 
    int scope_id; 
} StackPtrInfo;  
Fields
bp

Base pointer value when pointer was created.

offset

Stack offset from BP.

size

Size of the pointed-to object.

scope_id

Unique identifier for the scope where variable was declared.


StackVarMeta


Unified metadata for stack variable instrumentation.

typedef struct StackVarMeta { 
    char *name; 
    long long bp; 
    long long offset; 
    Type *ty; 
    int scope_id; 
    int is_alive; 
    int initialized; 
    long long read_count; 
    long long write_count; 
} StackVarMeta;  
Fields
name

Variable name (for debugging/reporting).

bp

Base pointer value when variable is active.

offset

Offset from BP (negative for locals, positive for params).

ty

Type information for the variable.

scope_id

Unique identifier for the scope where variable was declared.

is_alive

1 if variable is in scope, 0 if out of scope.

initialized

1 if variable has been initialized, 0 if uninitialized.

read_count

Number of read accesses to this variable.

write_count

Number of write accesses to this variable.


StringArray


Dynamic array of strings used for include paths and similar small lists.

typedef struct StringArray { 
    char **data; 
    int capacity; 
    int len; 
} StringArray;  
Fields
data

Pointer to N entries of char* strings.

capacity

Allocated capacity of the array.

len

Current length (number of strings stored).


Token


Token produced by the lexer or by macro expansion.

typedef struct Token { 
    TokenKind kind; // Token kind 
    struct Token *next; // Next token 
    int64_t val; // If kind is TK_NUM, its value 
    long double fval; // If kind is TK_NUM, its value 
    char *loc; // Token location 
    int len; // Token length 
    Type *ty; // Used if TK_NUM or TK_STR 
    char *str; // String literal contents including terminating '\0'  
    File *file; // Source location 
    char *filename; // Filename 
    int line_no; // Line number 
    int line_delta; // Line number 
    bool at_bol; // True if this token is at beginning of line 
    bool has_space; // True if this token follows a space character 
    Hideset *hideset; // For macro expansion 
    struct Token *origin; // If this is expanded from a macro, the original token 
} Token;  
Fields
kind

Token kind (see TokenKind).

loc

Pointer into the source buffer where the token text begins.

len

Number of characters in the token text.

str

For string literals: pointer to the unescaped contents.


TokenKind


Kinds of lexical tokens produced by the tokenizer and used by the preprocessor and parser.

typedef enum { 
    TK_IDENT, // Identifiers 
    TK_PUNCT, // Punctuators 
    TK_KEYWORD, // Keywords 
    TK_STR, // String literals 
    TK_NUM, // Numeric literals 
    TK_PP_NUM, // Preprocessing numbers 
    TK_EOF, // End-of-file markers 
} TokenKind;  

TypeKind


Kind tag for the `Type` structure describing C types.

typedef enum { 
    TY_VOID = 0, 
    TY_BOOL = 1, 
    TY_CHAR = 2, 
    TY_SHORT = 3, 
    TY_INT = 4, 
    TY_LONG = 5, 
    TY_FLOAT = 6, 
    TY_DOUBLE = 7, 
    TY_LDOUBLE = 8, 
    TY_ENUM = 9, 
    TY_PTR = 10, 
    TY_FUNC = 11, 
    TY_ARRAY = 12, 
    TY_VLA = 13, // variable-length array 
    TY_STRUCT = 14, 
    TY_UNION = 15, 
} TypeKind;  

Structs and Unions

JCC

Encapsulates all state for the JCC compiler and virtual machine. Instances are independent and support embedding.

Node

Represents a node in the parser's abstract syntax tree.

Obj

Represents a C object: either a variable (global/local) or a function. The parser and code generator use Obj for symbol and storage tracking.

Type

Central representation of a C type in the compiler.


JCC


Encapsulates all state for the JCC compiler and virtual machine. Instances are independent and support embedding.

struct JCC { 
    // VM Registers 
    long long ax; // Accumulator register (integer) 
    double fax; // Floating-point accumulator register 
    long long *pc; // Program counter 
    long long *bp; // Base pointer (frame pointer) 
    long long *sp; // Stack pointer 
    long long cycle; // Instruction cycle counter  
    // Exit detection (for returning from main) 
    long long *initial_sp; // Initial stack pointer (for exit detection) 
    long long *initial_bp; // Initial base pointer (for exit detection)  
    // Memory Segments 
    long long *text_seg; // Text segment (bytecode instructions) 
    long long *text_ptr; // Current write position (for code generation) 
    long long *stack_seg; // Stack segment 
    long long *old_text_seg; // Backup of original text segment pointer 
    char *data_seg; // Data segment (global variables/constants) 
    char *data_ptr; // Current write position in data segment 
    char *heap_seg; // Heap segment (for VM malloc/free) 
    char *heap_ptr; // Current allocation pointer (bump allocator) 
    char *heap_end; // End of heap segment 
    FreeBlock *free_list; // Head of free blocks list (for memory reuse)  
    // Segregated free lists for optimized allocation 
    // Size classes: 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, LARGE (>8192) 
    FreeBlock *size_class_lists[12]; // One free list per size class (NUM_SIZE_CLASSES) 
    FreeBlock *large_list; // For allocations > MAX_SMALL_ALLOC (8192)  
    // Memory safety tracking 
    AllocRecord *alloc_list; // List of active allocations (for leak detection) 
    HashMap init_state; // Track initialization state of stack variables (for uninitialized detection) 
    HashMap stack_ptrs; // Track stack pointers for dangling detection (ptr -> {bp, offset, size}) 
    HashMap provenance; // Track pointer provenance (ptr -> {origin_type, base, size}) 
    HashMap stack_var_meta; // Unified stack variable metadata (bp+offset -> StackVarMeta) 
    HashMap alloc_map; // Maps base addresses to AllocHeaders (for fast pointer validation) 
    HashMap ptr_tags; // Maps pointers to their creation generation tags (for temporal safety)  
    // Sorted allocation array for O(log n) range queries (CHKP/CHKT performance) 
    struct { 
        void **addresses; // Sorted array of base addresses 
        AllocHeader **headers; // Parallel array of headers 
        int count; // Number of active allocations 
        int capacity; // Allocated array capacity 
        } sorted_allocs;  
    // Configuration 
    int poolsize; // Size of memory segments (bytes) 
    int debug_vm; // Enable debug output during execution  
    // Runtime flags (bitwise combination of JCCFlags) 
    uint32_t flags; // JCCFlags bitfield for all safety and runtime features 
    long long stack_canary; // Stack canary value (random if JCC_RANDOM_CANARIES set, else fixed) 
    int in_vm_alloc; // Reentrancy guard: prevents HashMap from triggering VM heap recursion  
    // Control Flow Integrity (shadow stack) 
    long long *shadow_stack; // Shadow stack for return addresses (CFI) 
    long long *shadow_sp; // Shadow stack pointer  
    // Stack instrumentation state 
    int current_scope_id; // Incremented for each scope entry 
    int current_function_scope_id; // Scope ID of current function being generated 
    long long stack_high_water; // Maximum stack usage tracking  
    // Debugger state (enable via JCC_ENABLE_DEBUGGER flag) 
    Breakpoint breakpoints[MAX_BREAKPOINTS]; // Breakpoint table 
    int num_breakpoints; // Number of active breakpoints 
    int single_step; // Single-step mode (stop after each instruction) 
    int step_over; // Step over mode (skip function calls) 
    int step_out; // Step out mode (run until function returns) 
    long long *step_over_return_addr; // Return address for step over 
    long long *step_out_bp; // Base pointer for step out 
    int debugger_attached; // Debugger REPL is active  
    // Source mapping for debugger (bytecode ↔ source lines) 
    SourceMap *source_map; // Array of PC to source location mappings 
    int source_map_count; // Number of source map entries 
    int source_map_capacity; // Allocated capacity 
    File *last_debug_file; // Last file during debug info emission 
    int last_debug_line; // Last line number during debug info emission  
    // Debug symbols for expression evaluation 
    #ifndef MAX_DEBUG_SYMBOLS 
    #define MAX_DEBUG_SYMBOLS 4096 
    #endif  
    DebugSymbol debug_symbols[MAX_DEBUG_SYMBOLS]; // Symbol table for debugger 
    int num_debug_symbols; // Number of symbols  
    // Watchpoints (data breakpoints) 
    Watchpoint watchpoints[MAX_WATCHPOINTS]; // Watchpoint table 
    int num_watchpoints; // Number of active watchpoints  
    // Preprocessor state 
    bool skip_preprocess; // Skip preprocessing step 
    HashMap macros; 
    CondIncl *cond_incl; 
    HashMap pragma_once; 
    int include_next_idx;  
    // Pragma macro system 
    struct PragmaMacro *pragma_macros; // Linked list of compile-time macros 
    bool compiling_pragma_macro; // True when compiling a pragma macro (skip main() requirement)  
    // Tokenization state 
    File *current_file; // Input file 
    File **input_files; // A list of all input files. 
    bool at_bol; // True if the current position is at the beginning of a line 
    bool has_space; // True if the current position follows a space character  
    // Parser state 
    // All local variable instances created during parsing are 
    Obj *locals; // accumulated to this list. 
    // Likewise, global variables are accumulated to this list. 
    Obj *globals; 
    Scope *scope; 
    // Track variable being initialized (for const initialization) 
    Obj *initializing_var; 
    // Points to the function object the parser is currently parsing. 
    Obj *current_fn; 
    // Lists of all goto statements and labels in the curent function. 
    Node *gotos; 
    Node *labels; 
    // Current "goto" and "continue" jump targets. 
    char *brk_label; 
    char *cont_label; 
    // Points to a node representing a switch if we are parsing 
    // a switch statement. Otherwise, NULL. 
    Node *current_switch; 
    Obj *builtin_alloca; 
    Obj *builtin_setjmp; 
    Obj *builtin_longjmp;  
    StringArray include_paths; 
    StringArray system_include_paths; // System header search paths for <...>  
    // Code generation state 
    int label_counter; // For generating unique labels 
    int local_offset; // Current local variable offset  
    #ifndef MAX_CALLS 
    #define MAX_CALLS 1024 
    #endif  
    struct { 
        long long *location; // Location in text segment to patch 
        Obj *function; // Function to call 
        } call_patches[MAX_CALLS]; 
    int num_call_patches;  
    // Function address patches for function pointers 
    struct { 
        long long *location; // Location of IMM operand to patch with function address 
        Obj *function; // Function whose address to use 
        } func_addr_patches[MAX_CALLS]; 
    int num_func_addr_patches;  
    #ifndef MAX_LABELS 
    #define MAX_LABELS 256 
    #endif  
    LabelEntry label_table[MAX_LABELS]; 
    int num_labels; 
    GotoPatch goto_patches[MAX_LABELS]; 
    int num_goto_patches;  
    // Inline assembly callback 
    JCCAsmCallback asm_callback; // User-provided callback for asm statements 
    void *asm_user_data; // User-provided context for callback  
    // Foreign Function Interface (FFI) 
    ForeignFunc *ffi_table; // Registry of foreign C functions 
    int ffi_count; // Number of registered functions 
    int ffi_capacity; // Capacity of ffi_table array  
    // Current function being compiled (for VLA cleanup) 
    Obj *current_codegen_fn;  
    // Struct/union return buffer (copy-before-return approach) 
    char *return_buffer; // Buffer for struct/union returns 
    int return_buffer_size; // Size of return buffer  
    // Linked programs for extern offset propagation 
    Obj **link_progs; // Array of original program lists 
    int link_prog_count; // Number of programs  
    // Error handling (setjmp/longjmp for exception-like behavior) 
    jmp_buf *error_jmp_buf; // Jump buffer for error handling (NULL = use exit()) 
    char *error_message; // Last error message (when using longjmp) 
};  
Discussion

The structure contains registers, memory segments, frontend state (preprocessor, tokenizer, parser) and codegen/VM bookkeeping. All public API functions accept an `JCC *` as the first parameter.


Node


Represents a node in the parser's abstract syntax tree.

struct Node { 
    NodeKind kind; // Node kind 
    struct Node *next; // Next node 
    Type *ty; // Type, e.g. int or pointer to int 
    Token *tok; // Representative token  
    struct Node *lhs; // Left-hand side 
    struct Node *rhs; // Right-hand side  
    // "if" or "for" statement 
    struct Node *cond; 
    struct Node *then; 
    struct Node *els; 
    struct Node *init; 
    struct Node *inc;  
    // "break" and "continue" labels 
    char *brk_label; 
    char *cont_label;  
    // Block or statement expression 
    struct Node *body;  
    // Struct member access 
    Member *member;  
    // Function call 
    Type *func_ty; 
    struct Node *args; 
    bool pass_by_stack; 
    Obj *ret_buffer;  
    // Goto or labeled statement, or labels-as-values 
    char *label; 
    char *unique_label; 
    struct Node *goto_next;  
    // Switch 
    struct Node *case_next; 
    struct Node *default_case;  
    // Case 
    long begin; 
    long end;  
    // "asm" string literal 
    char *asm_str;  
    // Atomic compare-and-swap 
    struct Node *cas_addr; 
    struct Node *cas_old; 
    struct Node *cas_new;  
    // Atomic op= operators 
    Obj *atomic_addr; 
    struct Node *atomic_expr;  
    // Variable 
    Obj *var;  
    // Numeric literal 
    int64_t val; 
    long double fval; 
};  
Fields
kind

Node kind (see NodeKind).

ty

Resolved type of this node (after semantic analysis).

lhs

Left-hand side child (when applicable).

rhs

Right-hand side child (when applicable).


Obj


Represents a C object: either a variable (global/local) or a function. The parser and code generator use Obj for symbol and storage tracking.

struct Obj { 
    struct Obj *next; 
    char *name; // Variable name 
    Type *ty; // Type 
    Token *tok; // representative token 
    bool is_local; // local or global/function 
    int align; // alignment  
    // Local variable 
    int offset;  
    // Global variable or function 
    bool is_function; 
    bool is_definition; 
    bool is_static; 
    bool is_constexpr;  
    // Global variable 
    bool is_tentative; 
    bool is_tls; 
    char *init_data; 
    Relocation *rel; 
    Node *init_expr; // For constexpr: AST of initializer expression  
    // Function 
    bool is_inline; 
    Obj *params; 
    Node *body; 
    Obj *locals; 
    Obj *va_area; 
    Obj *alloca_bottom; 
    int stack_size;  
    // Static inline function 
    bool is_live; 
    bool is_root; 
    StringArray refs;  
    // Code generation (for VM) 
    long long code_addr; // Address in text segment where function code starts 
};  
Fields
name

Identifier name of the object.

ty

Type of the object.

is_local

True for local (stack) variables; false for globals.

offset

For local variables: stack offset. For globals/functions some fields (like code_addr) are used instead.

is_function

True when this Obj represents a function.

code_addr

For functions compiled to VM bytecode: start address in the text segment.


Type


Central representation of a C type in the compiler.

struct Type { 
    TypeKind kind; 
    int size; // sizeof() value 
    int align; // alignment 
    bool is_unsigned; // unsigned or signed 
    bool is_atomic; // true if _Atomic 
    bool is_const; // true if const-qualified 
    struct Type *origin; // for type compatibility check  
    // Pointer-to or array-of type. We intentionally use the same member 
    // to represent pointer/array duality in C. 
    // 
    // In many contexts in which a pointer is expected, we examine this 
    // member instead of "kind" member to determine whether a type is a 
    // pointer or not. That means in many contexts "array of T" is 
    // naturally handled as if it were "pointer to T", as required by 
    // the C spec. 
    struct Type *base;  
    // Declaration 
    Token *name; 
    Token *name_pos;  
    // Array 
    int array_len;  
    // Variable-length array 
    Node *vla_len; // # of elements 
    Obj *vla_size; // sizeof() value  
    // Struct 
    struct Member *members; 
    bool is_flexible; 
    bool is_packed;  
    // Enum (tracks enum constants for code generation) 
    EnumConstant *enum_constants;  
    // Function type 
    struct Type *return_ty; 
    struct Type *params; 
    bool is_variadic; 
    struct Type *next; 
};  
Fields
kind

One of TypeKind indicating the category of this type.

size

sizeof() value in bytes.

align

Alignment requirement in bytes.

base

For pointer/array types: the referenced element/base type.


Macro Definitions

Breakpoint

Represents a debugger breakpoint at a specific program counter location.

MAX_BREAKPOINTS

Represents a debugger breakpoint at a specific program counter location.

MAX_WATCHPOINTS

Represents a data breakpoint that triggers on memory access.

Watchpoint

Represents a data breakpoint that triggers on memory access.


Breakpoint


Represents a debugger breakpoint at a specific program counter location.

#define MAX_BREAKPOINTS 256 
Parameters
pc

Program counter address where the breakpoint is set.

enabled

Whether this breakpoint is currently active.

hit_count

Number of times this breakpoint has been hit.

See Also


MAX_BREAKPOINTS


Represents a debugger breakpoint at a specific program counter location.

#define MAX_BREAKPOINTS 256 
Parameters
pc

Program counter address where the breakpoint is set.

enabled

Whether this breakpoint is currently active.

hit_count

Number of times this breakpoint has been hit.

See Also


MAX_WATCHPOINTS


Represents a data breakpoint that triggers on memory access.

#define MAX_WATCHPOINTS 64 
Parameters
address

Memory address being watched.

size

Size of watched region in bytes.

type

Type flags: WATCH_READ | WATCH_WRITE | WATCH_CHANGE.

old_value

Last known value (for change detection).

expr

Original expression string (for display).

enabled

Whether this watchpoint is currently active.

hit_count

Number of times this watchpoint has been triggered.

See Also


Watchpoint


Represents a data breakpoint that triggers on memory access.

#define MAX_WATCHPOINTS 64 
Parameters
address

Memory address being watched.

size

Size of watched region in bytes.

type

Type flags: WATCH_READ | WATCH_WRITE | WATCH_CHANGE.

old_value

Last known value (for change detection).

expr

Original expression string (for display).

enabled

Whether this watchpoint is currently active.

hit_count

Number of times this watchpoint has been triggered.

See Also