### Install Zen C Source: https://z-libs.github.io/Zen-C-Docs/index Instructions for cloning the Zen C repository, building the compiler, and installing it on your system. This process involves using git to fetch the source code, make to compile it, and then installing it globally. ```bash git clone https://github.com/z-libs/Zen-C.git cd Zen-C make sudo make install ``` -------------------------------- ### Zen C Operator Overloading Example Source: https://z-libs.github.io/Zen-C-Docs/index Demonstrates how to overload arithmetic operators in Zen C using the `impl` keyword and specific method names like `add`. This allows for intuitive arithmetic operations on custom types. ```Zen C impl Point { fn add(self, other: Point) -> Point { return Point{x: self.x + other.x, y: self.y + other.y}; } } let p3 = p1 + p2; // Calls p1.add(p2) ``` -------------------------------- ### Configure Build Process with Zen C Directives Source: https://z-libs.github.io/Zen-C-Docs/index Zen C supports special comments at the top of source files to configure the build process. Directives like `link:`, `lib:`, `include:`, `framework:`, `cflags:`, `define:`, `pkg-config:`, `shell:`, and `get:` allow for library linking, path configuration, compiler flags, macro definitions, and external command execution. OS guarding and environment variable expansion are supported. ```Zen C //> link: -lfoo //> lib: path/to/libs //> include: path/to/headers //> framework: Cocoa //> cflags: -Wall -O3 //> define: MACRO //> pkg-config: gtk+-3.0 //> shell: command //> get: http://url/file // OS Guarding //> linux: link: -lm //> windows: link: -lws2_32 //> macos: framework: Cocoa // Environment Variable Expansion //> include: ${HOME}/mylib/include //> lib: ${ZC_ROOT}/std // Example Usage //> include: ./include //> lib: ./libs //> link: -lraylib -lm //> cflags: -Ofast //> pkg-config: gtk+-3.0 import "raylib.h" fn main() { ... } ``` -------------------------------- ### Implement REPL Functionality (C) Source: https://z-libs.github.io/Zen-C-Docs/repl_8h_source This C code snippet provides the implementation for the `run_repl` function, which initiates the Read-Eval-Print Loop (REPL). It takes the path of the self executable as an argument to start the interactive environment. ```c void run_repl(const char *self_path) { // Implementation to start the REPL } ``` -------------------------------- ### Objective-C Interoperability with Zen C Source: https://z-libs.github.io/Zen-C-Docs/index Shows how to compile Zen C code to Objective-C using the `--objc` flag, enabling the use of Objective-C frameworks like Foundation. It includes examples of including Objective-C headers and using raw blocks for Objective-C syntax. ```Zen C //> macos: framework: Foundation //> linux: cflags: -fconstant-string-class=NSConstantString -D_NATIVE_OBJC_EXCEPTIONS //> linux: link: -lgnustep-base -lobjc include fn main() { raw { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSLog(@"Hello from Objective-C!"); [pool drain]; } println "Zen C works too!"; } ``` -------------------------------- ### C++ Interoperability with Zen C Source: https://z-libs.github.io/Zen-C-Docs/index Examples of compiling Zen C code with C++ support using the `--cpp` flag, enabling seamless integration with C++ libraries and features. ```bash # Direct compilation with g++ zc app.zc --cpp # Or transpile for manual build zc transpile app.zc --cpp g++ out.c my_cpp_lib.o -o app ``` -------------------------------- ### Get Next Token Source: https://z-libs.github.io/Zen-C-Docs/zprep_8h_source Advances the lexer and returns the next token from the source code. ```APIDOC ## Get Next Token ### Description Advances the lexer and returns the next token from the source code. ### Method `lexer_next` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```c Token t = lexer_next(&l); // Process token t ``` ### Response #### Success Response (Token) - **type** (TokenType) - The type of the token. - **start** (const char *) - Pointer to the start of the token in the source string. - **len** (int) - The length of the token. - **line** (int) - The line number where the token is located. - **col** (int) - The column number where the token is located. #### Response Example ```json { "type": "TOK_IDENT", "start": "x", "len": 1, "line": 1, "col": 4 } ``` ``` -------------------------------- ### Import Compiler Plugins in Zen C Source: https://z-libs.github.io/Zen-C-Docs/index Imports external compiler plugins to extend Zen C's syntax and functionality. The 'regex' plugin is shown as an example, enabling the use of regular expressions. ```zen-c import plugin "regex" let re = regex! { ^[a-z]+$ }; ``` -------------------------------- ### Get LSP Signature Help (C) Source: https://z-libs.github.io/Zen-C-Docs/lsp__analysis_8c The lsp_signature_help function provides signature information for a function or method at a specified cursor position. It requires the document URI, line number, column number, and an identifier. This function enhances developer productivity by offering context-aware documentation and parameter hints. ```c void lsp_signature_help(const char *_uri_, int _line_, int _col_, int _id_) ``` -------------------------------- ### Zen-C Macros for Struct Type Manipulation Source: https://z-libs.github.io/Zen-C-Docs/constants_8h Defines macros to identify and manipulate type strings that represent C structs. IS_STRUCT_PREFIX checks if a type string starts with 'struct ', and STRIP_STRUCT_PREFIX removes this prefix to get the actual struct name. ```c #define IS_STRUCT_PREFIX(t) ((t) && strncmp((t), "struct ", 7) == 0) #define STRIP_STRUCT_PREFIX(t) (IS_STRUCT_PREFIX(t) ? ((t) + 7) : (t)) ``` -------------------------------- ### Zen C Build and Run Commands Source: https://z-libs.github.io/Zen-C-Docs/index Demonstrates common Zen C command-line usage for building, running, and interacting with the compiler. Includes commands for compiling source files, creating executables, and entering the interactive REPL. ```shell # Run on any supported OS ./out/bin/zc.com build hello.zc -o hello # Compile and run zc run hello.zc # Build executable zc build hello.zc -o hello # Interactive Shell zc repl ``` -------------------------------- ### LSP Project Initialization and File Management Functions (C) Source: https://z-libs.github.io/Zen-C-Docs/lsp__project_8h_source Provides C functions for initializing the LSP project, retrieving project files by URI, and updating file content. `lsp_project_init` sets up the project with a root path, `lsp_project_get_file` finds a specific file, and `lsp_project_update_file` re-parses and re-indexes a file's content. ```c #ifndef LSP_PROJECT_H #define LSP_PROJECT_H #include "parser.h" #include "lsp_index.h" typedef struct ProjectFile { char *path; char *uri; char *source; LSPIndex *index; struct ProjectFile *next; } ProjectFile; typedef struct { ParserContext *ctx; ProjectFile *files; char *root_path; } LSPProject; // Global project instance extern LSPProject *g_project; // Initialize the project with a root directory void lsp_project_init(const char *root_path); // Find a file in the project ProjectFile *lsp_project_get_file(const char *uri); // Update a file (re-parse and re-index) void lsp_project_update_file(const char *uri, const char *src); #endif ``` -------------------------------- ### Variable: loop_defer_boundary Source: https://z-libs.github.io/Zen-C-Docs/codegen_8h Defer stack index at the start of each loop. ```APIDOC ## Variable: loop_defer_boundary ### Description Defer stack index at the start of each loop. ### Type int[] ### Scope extern ``` -------------------------------- ### zptr_plugin_mgr_init Function Documentation (C) Source: https://z-libs.github.io/Zen-C-Docs/plugin__manager_8c Initializes the plugin system. This function must be called before any other plugin manager functions are used. ```c void zptr_plugin_mgr_init (void) { // Implementation details... } ``` -------------------------------- ### Get Next Token in C Source: https://z-libs.github.io/Zen-C-Docs/token_8c Retrieves the next token from the lexer's input stream. This is a fundamental operation for parsing. ```c Token lexer_next(Lexer *l) { // Implementation details for getting the next token return /* next token */; } ``` -------------------------------- ### Emit Preamble (C) Source: https://z-libs.github.io/Zen-C-Docs/codegen__decl_8c Emits the standard preamble, including necessary includes and macros, to the output file. Requires a ParserContext and an output file pointer. ```c void emit_preamble(ParserContext *_ctx_, FILE *_out_) ``` -------------------------------- ### cJSON Get Object Item Function Source: https://z-libs.github.io/Zen-C-Docs/cJSON_8c Function to retrieve a cJSON item from an object using its key. `cJSON_GetObjectItemCaseSensitive` performs a case-sensitive lookup. ```c cJSON_GetObjectItemCaseSensitive(const cJSON *const object, const char *const string); ``` -------------------------------- ### Building Zen C with Zig Source: https://z-libs.github.io/Zen-C-Docs/index Instructions for building the Zen C compiler itself using Zig's build system, leveraging Zig's cross-compilation capabilities. ```bash make zig ``` -------------------------------- ### lsp_main Function Signature and Documentation Source: https://z-libs.github.io/Zen-C-Docs/lsp__main_8c Documentation for the lsp_main function, which serves as the entry point for the Language Server Protocol (LSP) implementation in Zen-C. It outlines the function's return type, parameters, and provides a basic structure for its documentation. ```c /** * @brief Main function for the Language Server Protocol (LSP) implementation. * * @param argc The number of command-line arguments. * @param argv An array of command-line argument strings. * @return int Returns 0 on success, non-zero on failure. */ int lsp_main(int argc, char **argv); ``` -------------------------------- ### Check if Type is Struct Prefix (C) Source: https://z-libs.github.io/Zen-C-Docs/constants_8h Macro to check if a type string starts with the 'struct ' prefix. It uses `strncmp` for efficient prefix checking. ```c #define IS_STRUCT_PREFIX(t) ((t) && strncmp((t), "struct ", 7) == 0) ``` -------------------------------- ### Compiling Zen C with Different C Backends Source: https://z-libs.github.io/Zen-C-Docs/index Demonstrates how to specify the C compiler backend for Zen C using the `--cc` flag. Supports GCC, Clang, and Zig. ```bash zc run app.zc --cc clang zc run app.zc --cc zig ``` -------------------------------- ### Check if Type is Vec (C) Source: https://z-libs.github.io/Zen-C-Docs/constants_8h Macro to check if a type string represents a Vec generic type. It verifies if the string starts with 'Vec_' using `strncmp`. ```c #define IS_VEC_TYPE(t) ((t) && strncmp((t), "Vec_", 4) == 0) ``` -------------------------------- ### zptr_load_plugin Function Documentation (C) Source: https://z-libs.github.io/Zen-C-Docs/plugin__manager_8c Handles loading a plugin from a shared object file (.so). It takes the file path as input and returns a pointer to the loaded plugin on success, or NULL on failure. ```c ZPlugin * zptr_load_plugin (const char * _path_) { // Implementation details... return NULL; // Placeholder } ``` -------------------------------- ### Check if Type is Slice (C) Source: https://z-libs.github.io/Zen-C-Docs/constants_8h Macro to check if a type string represents a Slice generic type. It verifies if the string starts with 'Slice_' using `strncmp`. ```c #define IS_SLICE_TYPE(t) ((t) && strncmp((t), "Slice_", 6) == 0) ``` -------------------------------- ### Check if Type is Option (C) Source: https://z-libs.github.io/Zen-C-Docs/constants_8h Macro to check if a type string represents an Option generic type. It verifies if the string starts with 'Option_' using `strncmp`. ```c #define IS_OPTION_TYPE(t) ((t) && strncmp((t), "Option_", 7) == 0) ``` -------------------------------- ### Zen-C Main Entry Point Source: https://z-libs.github.io/Zen-C-Docs/main_8c The main function serves as the entry point for the Zen-C executable. It handles command-line arguments and orchestrates the program's execution. ```APIDOC ## GET /main ### Description Entry point for the Zen-C application. Handles command-line arguments and program execution. ### Method GET ### Endpoint /main ### Parameters #### Query Parameters - **argc** (int) - Required - Number of command-line arguments. - **argv** (char**) - Required - Array of command-line argument strings. ### Request Example ```json { "argc": 2, "argv": ["./zen-c", "--help"] } ``` ### Response #### Success Response (200) - **status** (string) - Indicates the success of the operation. - **message** (string) - A message detailing the outcome or output. #### Response Example ```json { "status": "success", "message": "Program executed successfully." } ``` ``` -------------------------------- ### Get Field Type String Source: https://z-libs.github.io/Zen-C-Docs/codegen__utils_8c Retrieves the string representation of a struct field's type. It needs the ParserContext, the struct name, and the field name. ```c char * get_field_type_str | ( | ParserContext * | _ctx_ , | | const char * | _struct_name_ , | | const char * | _field_name_ | ) ``` -------------------------------- ### Load Plugin Source: https://z-libs.github.io/Zen-C-Docs/plugin__manager_8h_source Loads a plugin from a shared object file (.so). ```APIDOC ## POST /plugin/load ### Description Load a plugin from a shared object file (.so). ### Method POST ### Endpoint /plugin/load ### Parameters #### Request Body - **path** (string) - Required - The file path to the plugin's shared object file. ### Request Example ```json { "path": "/path/to/your/plugin.so" } ``` ### Response #### Success Response (200) - **plugin_name** (string) - The name of the loaded plugin. - **status** (string) - Indicates successful loading. #### Response Example ```json { "plugin_name": "example_plugin", "status": "Plugin loaded successfully." } ``` ``` -------------------------------- ### Get Next Token from Lexer Source: https://z-libs.github.io/Zen-C-Docs/zprep_8h Retrieves the next token from the lexer's current position and advances the lexer's internal state. This is a fundamental operation for parsing. ```c Token lexer_next(Lexer *l) ``` -------------------------------- ### SQL Plugin Initialization and Transpilation (C) Source: https://z-libs.github.io/Zen-C-Docs/sql_8c This C code snippet defines the initialization function 'z_plugin_init' and the transpilation function 'sql_transpile' for the SQL plugin in Zen-C. It includes necessary headers and defines the plugin structure. ```c #include "zprep_plugin.h" #include #include #include #include typedef struct { const char *name; void (*fn)(const char *input_body, const ZApi *api); } ZPlugin; void sql_transpile(const char *input_body, const ZApi *api) { // Implementation for SQL transpilation } ZPlugin *z_plugin_init(void) { static ZPlugin sql_plugin = { .name = "sql", .fn = sql_transpile }; return &sql_plugin; } ``` -------------------------------- ### Emit Includes and Aliases Source: https://z-libs.github.io/Zen-C-Docs/codegen_8h_source Generates C code for including necessary headers and defining type aliases. This function consolidates the setup for includes and aliases. ```c void emit_includes_and_aliases(ASTNode *node, FILE *out) **Definition** codegen_decl.c:205 ``` -------------------------------- ### Plugin Manager Initialization Source: https://z-libs.github.io/Zen-C-Docs/plugin__manager_8h_source Initializes the Zen-C plugin system. This function should be called before any other plugin management functions. ```APIDOC ## POST /plugin/init ### Description Initializes the plugin system. ### Method POST ### Endpoint /plugin/init ### Parameters None ### Request Body None ### Request Example None ### Response #### Success Response (200) - **status** (string) - Indicates successful initialization. #### Response Example ```json { "status": "Plugin system initialized successfully." } ``` ``` -------------------------------- ### Strip Struct Prefix (C) Source: https://z-libs.github.io/Zen-C-Docs/constants_8h Macro to remove the 'struct ' prefix from a type string. If the string starts with 'struct ', it returns a pointer to the substring after the prefix; otherwise, it returns the original string. ```c #define STRIP_STRUCT_PREFIX(t) (IS_STRUCT_PREFIX(t) ? ((t) + 7) : (t)) ``` -------------------------------- ### cJSON Object Manipulation Functions (C) Source: https://z-libs.github.io/Zen-C-Docs/cJSON_8h_source A collection of functions for adding, getting, replacing, and detaching items from cJSON objects and arrays. These functions allow for detailed control over JSON structure. ```c cJSON_AddItemToObjectCS cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item) cJSON_GetObjectItemCaseSensitive cJSON_GetObjectItemCaseSensitive(const cJSON *const object, const char *const string) cJSON_DetachItemFromObjectCaseSensitive cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string) cJSON_InsertItemInArray cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem) cJSON_AddStringToObject cJSON_AddStringToObject(cJSON *const object, const char *const name, const char *const string) cJSON_AddRawToObject cJSON_AddRawToObject(cJSON *const object, const char *const name, const char *const raw) cJSON_AddNumberToObject cJSON_AddNumberToObject(cJSON *const object, const char *const name, const double number) cJSON_AddBoolToObject cJSON_AddBoolToObject(cJSON *const object, const char *const name, const cJSON_bool boolean) cJSON_ReplaceItemInObjectCaseSensitive cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object, const char *string, cJSON *newitem) cJSON_ReplaceItemInObject cJSON_ReplaceItemInObject(cJSON *object, const char *string, cJSON *newitem) cJSON_ReplaceItemViaPointer cJSON_ReplaceItemViaPointer(cJSON *const parent, cJSON *const item, cJSON *replacement) cJSON_AddItemReferenceToObject cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item) ``` -------------------------------- ### Lexer Initialization and Operations Source: https://z-libs.github.io/Zen-C-Docs/zprep_8h_source Functions for initializing the lexer and peeking at upcoming tokens. `lexer_init` sets up the lexer with the source code, while `lexer_peek` and `lexer_peek2` allow inspection of the next one or two tokens without consuming them. ```c void lexer_init(Lexer *l, const char *src); Token lexer_peek(Lexer *l); Token lexer_peek2(Lexer *l); ``` -------------------------------- ### Running Zen C Test Suite Source: https://z-libs.github.io/Zen-C-Docs/index Provides commands for executing the Zen C test suite. It covers running all tests with GCC, running a specific test file, and running tests with different backend compilers like clang, zig, and tcc. ```Shell # Run all tests (GCC) make test # Run specific test ./zc run tests/test_match.zc # Run with different compiler ./tests/run_tests.sh --cc clang ./tests/run_tests.sh --cc zig ./tests/run_tests.sh --cc tcc ``` -------------------------------- ### Emit Preamble Source: https://z-libs.github.io/Zen-C-Docs/codegen_8h_source Emits the standard preamble, including necessary includes and macros, to the output C file. This function ensures that the generated C code has the required setup. ```c void emit_preamble(ParserContext *ctx, FILE *out) Emits the standard preamble (includes, macros) to the output file. **Definition** codegen_decl.c:43 ``` -------------------------------- ### zen_init Function Source: https://z-libs.github.io/Zen-C-Docs/zen__facts_8c Initializes the Zen-C library. This function is a void function and takes no arguments. It is a fundamental part of setting up Zen-C's internal state. ```c void zen_init(void) ``` -------------------------------- ### Lexer Initialization Source: https://z-libs.github.io/Zen-C-Docs/zprep_8h_source Initializes the lexer with the source code string. ```APIDOC ## Lexer Initialization ### Description Initializes the lexer with the source code string. ### Method `lexer_init` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```c Lexer l; lexer_init(&l, "int x = 10;"); ``` ### Response #### Success Response (void) Initializes the lexer structure. #### Response Example N/A ``` -------------------------------- ### Zen C Slice Expression Structure Source: https://z-libs.github.io/Zen-C-Docs/structASTNode Represents slice expressions in Zen C, used for creating sub-arrays or sub-sequences. It includes the array expression and the start and end bounds of the slice. ```c struct { ASTNode *array; ASTNode *start; ASTNode *end; } slice; ``` -------------------------------- ### Plugin Initialization Function Signature (C) Source: https://z-libs.github.io/Zen-C-Docs/zprep__plugin_8h Defines the signature for the plugin entry point function, which dynamic libraries must export as 'z_init'. This function is responsible for initializing and returning a ZPlugin structure. ```c #include #include // Forward declarations for ZApi and ZPlugin struct ZApi; struct ZPlugin; typedef struct ZPlugin* (*ZPluginInitFn)(void); // Example of how it might be used (not part of the definition itself) // ZPlugin* z_init(void) { // // Plugin initialization logic here // return NULL; // Placeholder // } ``` -------------------------------- ### Zen C For Range Statement Structure Source: https://z-libs.github.io/Zen-C-Docs/structASTNode Details the structure for a for-range loop in Zen C, iterating over a range with a specified step. It includes the loop variable, start, end, step, and body. ```c struct { char *var_name; ASTNode *start; ASTNode *end; char *step; int is_inclusive; ASTNode *body; } for_range; ``` -------------------------------- ### Instantiation Function Source: https://z-libs.github.io/Zen-C-Docs/parser__utils_8c Function for instantiating methods. ```APIDOC ## Instantiation Function ### Description Function for instantiating methods within the parser context. ### Function - **instantiate_methods** (`ParserContext *ctx`, `GenericImplTemplate *it`, `const char *mangled_struct_name`, `const char *arg`, `const char *unmangled_arg`) ``` -------------------------------- ### Writing CUDA Kernels in Zen C Source: https://z-libs.github.io/Zen-C-Docs/index An example of a CUDA kernel (`add_kernel`) written in Zen C, utilizing `@global` for GPU execution and `thread_id()` for thread indexing, along with host code for kernel invocation. ```zen-c import "std/cuda.zc" @global fn add_kernel(a: float*, b: float*, c: float*, n: int) { let i = thread_id(); if i < n { c[i] = a[i] + b[i]; } } fn main() { def N = 1024; let d_a = cuda_alloc(N); let d_b = cuda_alloc(N); let d_c = cuda_alloc(N); defer cuda_free(d_a); defer cuda_free(d_b); defer cuda_free(d_c); // ... init data ... launch add_kernel(d_a, d_b, d_c, N) with { grid: (N + 255) / 256, block: 256 }; cuda_sync(); } ``` -------------------------------- ### Enter Scope Source: https://z-libs.github.io/Zen-C-Docs/parser__utils_8c Enters a new scope by pushing onto the scope stack. ```APIDOC ## enter_scope() ### Description Enters a new scope (pushes to scope stack). ### Method N/A (This appears to be a function signature, not an API endpoint) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) N/A (void return type) #### Response Example N/A ``` -------------------------------- ### Get Item Values (C) Source: https://z-libs.github.io/Zen-C-Docs/cJSON_8h_source Extracts the value of a cJSON item based on its type. `cJSON_GetStringValue` returns the string content, and `cJSON_GetNumberValue` returns the numeric value as a double. These functions assume the item is of the correct type; type checking should be performed beforehand. ```c char * cJSON_GetStringValue(const cJSON *const item); double cJSON_GetNumberValue(const cJSON *const item); ``` -------------------------------- ### Brainfuck Plugin Initialization and Transpilation (C) Source: https://z-libs.github.io/Zen-C-Docs/brainfuck_8c This C code snippet defines the brainfuck plugin for Zen-C, including its initialization function and the main transpilation function. It demonstrates how to integrate external functionalities into the Zen-C environment using the ZApi. ```c #include "zprep_plugin.h" // Function to initialize the brainfuck plugin ZPlugin * z_plugin_init (void) { // Placeholder for actual initialization logic return NULL; // Replace with actual plugin structure } // Function to transpile brainfuck code void bf_transpile (const char *input_body, const ZApi *api) { // Placeholder for actual transpilation logic } // Definition of the brainfuck plugin structure ZPlugin brainfuck_plugin = {.name = "brainfuck", .fn = bf_transpile}; ``` -------------------------------- ### Zen-C Lexer Initialization and Tokenization Functions Source: https://z-libs.github.io/Zen-C-Docs/zprep_8h_source This C code snippet provides the function prototypes for the Zen-C lexer. `lexer_init` initializes the lexer with a source string, `lexer_next` retrieves the next token from the source, `lexer_peek` returns the next token without consuming it, and `lexer_peek2` returns the token after the next one without consuming either. ```c void lexer_init(Lexer *l, const char *src); Token lexer_next(Lexer *l); Token lexer_peek(Lexer *l); Token lexer_peek2(Lexer *l); ``` -------------------------------- ### Get Parse Error Pointer (C) Source: https://z-libs.github.io/Zen-C-Docs/cJSON_8h_source Retrieves a pointer to the location of a parse error within the input string when `cJSON_Parse()` returns 0 (failure). This is useful for debugging and understanding why JSON parsing failed. A NULL pointer is returned if parsing was successful. ```c const char * cJSON_GetErrorPtr(void); ``` -------------------------------- ### Loop Depth and Boundary Source: https://z-libs.github.io/Zen-C-Docs/codegen_8h_source Global variables for tracking the current loop nesting depth and the defer stack index at the start of each loop. `loop_depth` indicates the current level of nested loops, while `loop_defer_boundary` stores the defer stack state for each loop level. ```c int loop_depth Current loop nesting depth. **Definition** codegen_utils.c:20 int loop_defer_boundary[] Defer stack index at start of each loop. **Definition** codegen_utils.c:19 ``` -------------------------------- ### ProjectFile Data Fields Documentation (C) Source: https://z-libs.github.io/Zen-C-Docs/structProjectFile Documents the individual data fields within the ProjectFile structure. Each field's purpose is explained, including 'path' for the absolute file path, 'uri' for the file's URI, 'source' for cached content, 'index' for the symbol index, and 'next' for linking to the next ProjectFile. ```c char * path; | Absolute file path. char * uri; | file:// URI. char * source; | Cached source content (in-memory). LSPIndex * index; | File-specific symbol index. struct ProjectFile * next; ``` -------------------------------- ### lsp_signature_help Function Implementation Source: https://z-libs.github.io/Zen-C-Docs/lsp__analysis_8c Implements the 'lsp_signature_help' function, which provides signature information for functions or methods at a given cursor position. It requires the file URI, line, column, and a request identifier. ```c void lsp_signature_help (const char *uri, int line, int col, int id) ``` -------------------------------- ### Access Array Elements (C) Source: https://z-libs.github.io/Zen-C-Docs/cJSON_8h_source Provides functions to get the size of a JSON array and retrieve a specific item by its index. `cJSON_GetArraySize` returns the number of elements, and `cJSON_GetArrayItem` returns a pointer to the item at the given index, returning NULL if the index is out of bounds or the item is not an array. ```c int cJSON_GetArraySize(const cJSON *array); cJSON * cJSON_GetArrayItem(const cJSON *array, int index); ``` -------------------------------- ### lsp_signature_help Source: https://z-libs.github.io/Zen-C-Docs/json__rpc_8c Provides signature help for a function or method at a given cursor position. ```APIDOC ## POST /lsp/signature_help ### Description Provides signature help for a function or method at a given cursor position. ### Method POST ### Endpoint /lsp/signature_help ### Parameters #### Request Body - **uri** (string) - Required - The URI of the file. - **line** (integer) - Required - The line number of the cursor position. - **col** (integer) - Required - The column number of the cursor position. - **id** (integer) - Required - The request ID. ### Request Example ```json { "uri": "file:///path/to/your/file.c", "line": 10, "col": 5, "id": 8 } ``` ### Response #### Success Response (200) - **result** (object) - An object containing signature help information. #### Response Example ```json { "result": { "signatures": [ { "label": "myFunction(int arg1, char *arg2)", "documentation": "This function does something.", "parameters": [ {"label": "arg1", "documentation": "The first argument."}, {"label": "arg2", "documentation": "The second argument."} ] } ], "activeSignature": 0, "activeParameter": 0 } } ``` ``` -------------------------------- ### Doxygen Class Inheritance Example (C++) Source: https://z-libs.github.io/Zen-C-Docs/graph_legend This C++ code snippet demonstrates how to document classes for Doxygen, illustrating different inheritance types (public, protected, private) and template usage. Doxygen comments are used to define class visibility and relationships in generated documentation graphs. ```cpp /*! Invisible class because of truncation */ class Invisible { }; /*! Truncated class, inheritance relation is hidden */ class Truncated : public Invisible { }; /* Class not documented with doxygen comments */ class Undocumented { }; /*! Class that is inherited using public inheritance */ class PublicBase : public Truncated { }; /*! A template class */ template class Templ { }; /*! Class that is inherited using protected inheritance */ class ProtectedBase { }; /*! Class that is inherited using private inheritance */ class PrivateBase { }; /*! Class that is used by the Inherited class */ class Used { }; /*! Super class that inherits a number of other classes */ class Inherited : public PublicBase, protected ProtectedBase, private PrivateBase, public Undocumented, public Templ { private: Used *m_usedClass; }; ``` -------------------------------- ### LSPProject Data Fields Documentation (C) Source: https://z-libs.github.io/Zen-C-Docs/structLSPProject Details the data fields within the LSPProject structure. Each field, such as 'ctx', 'files', and 'root_path', is explained along with its purpose and type. This documentation is crucial for understanding how the LSP manages project-specific data. ```c /* * Global shared parser context. Contains global registries (structs, functions) reused across files. */ ParserContext* ctx; /* * List of tracked open files. */ ProjectFile* files; /* * Project root directory. */ char* root_path; ``` -------------------------------- ### Zen-C Plugin API Source: https://z-libs.github.io/Zen-C-Docs/brainfuck_8c Documentation for the Zen-C plugin system, including initialization and transpile functions. ```APIDOC ## GET /plugins/brainfuck.c ### Description This endpoint provides information about the brainfuck plugin for Zen-C. ### Method GET ### Endpoint /plugins/brainfuck.c ### Parameters None ### Request Example None ### Response #### Success Response (200) - **functions** (array) - List of available functions in the plugin. - **variables** (array) - List of available variables in the plugin. #### Response Example ```json { "functions": [ { "name": "bf_transpile", "signature": "void bf_transpile(const char *input_body, const ZApi *api)" }, { "name": "z_plugin_init", "signature": "ZPlugin *z_plugin_init(void)" } ], "variables": [ { "name": "brainfuck_plugin", "type": "ZPlugin", "value": "{.name = \"brainfuck\", .fn = bf_transpile}" } ] } ``` ``` -------------------------------- ### cJSON Array and Object Manipulation (C) Source: https://z-libs.github.io/Zen-C-Docs/cJSON_8h Functions for interacting with JSON arrays and objects. This includes getting array size, retrieving items, adding items, detaching items, and replacing items. These operations modify the cJSON structure. Dependencies include the cJSON library and valid cJSON objects. ```C CJSON_PUBLIC (int) cJSON_GetArraySize(const cJSON *array); cJSON_GetObjectItemCaseSensitive (const cJSON *const object, const char *const string); cJSON_AddItemToObjectCS (cJSON *object, const char *string, cJSON *item); cJSON_AddItemReferenceToObject (cJSON *object, const char *string, cJSON *item); cJSON_DetachItemFromObjectCaseSensitive (cJSON *object, const char *string); cJSON_InsertItemInArray (cJSON *array, int which, cJSON *newitem); cJSON_ReplaceItemViaPointer (cJSON *const parent, cJSON *const item, cJSON *replacement); cJSON_ReplaceItemInObject (cJSON *object, const char *string, cJSON *newitem); cJSON_ReplaceItemInObjectCaseSensitive (cJSON *object, const char *string, cJSON *newitem); ``` -------------------------------- ### Get LSP References (C) Source: https://z-libs.github.io/Zen-C-Docs/lsp__analysis_8c The lsp_references function is used to retrieve references for a specific code element within a given URI, line, and column. It takes the document URI, line number, column number, and an identifier as input. This function is essential for code navigation and understanding symbol usage in an IDE. ```c void lsp_references(const char *_uri_, int _line_, int _col_, int _id_) ``` -------------------------------- ### lsp_signature_help() C Function for LSP Signature Help Source: https://z-libs.github.io/Zen-C-Docs/json__rpc_8c The lsp_signature_help function provides signature help for function calls at a specific cursor position. It takes the file URI, line, column, and an ID as parameters. This function is located in the lsp module and communicates via json_rpc.c. ```c void lsp_signature_help(const char * _uri_, int _line_, int _col_, int _id_) ``` -------------------------------- ### Lisp Plugin Initialization and Transpilation (C) Source: https://z-libs.github.io/Zen-C-Docs/lisp_8c This C code defines the Lisp plugin for Zen-C, including its initialization function and the transpilation function. It specifies the plugin's name and the function pointer for its core operation. Dependencies include standard C libraries and the Zen-C API header. ```c #include "zprep_plugin.h" #include #include #include #include void lisp_transpile (const char *input_body, const ZApi *api); ZPlugin * z_plugin_init (void); ZPlugin lisp_plugin = {.name = "lisp", .fn = lisp_transpile}; void lisp_transpile ( const char * _input_body_ , const ZApi * _api_ ) { // Function implementation would go here } ZPlugin * z_plugin_init (void) { return &lisp_plugin; } ``` -------------------------------- ### cJSON Value Access and Addition (C) Source: https://z-libs.github.io/Zen-C-Docs/cJSON_8h Functions to retrieve specific value types from cJSON items and to add new key-value pairs to JSON objects. This includes getting number values and adding boolean, number, string, and raw JSON values. Dependencies include the cJSON library and valid cJSON objects. ```C CJSON_PUBLIC (double) cJSON_GetNumberValue(const cJSON *const item); CJSON_AddBoolToObject (cJSON *const object, const char *const name, const cJSON_bool boolean); CJSON_AddNumberToObject (cJSON *const object, const char *const name, const double number); CJSON_AddStringToObject (cJSON *const object, const char *const name, const char *const string); CJSON_AddRawToObject (cJSON *const object, const char *const name, const char *const raw); ``` -------------------------------- ### LSP Project API Source: https://z-libs.github.io/Zen-C-Docs/lsp__project_8h Provides functions for initializing and managing the LSP project state, including file tracking, finding definitions, and locating references. ```APIDOC ## Data Structures ### `struct ProjectFile` **Description**: Represents a tracked file in the LSP project. ### `struct LSPProject` **Description**: Global state for the Language Server Project. ### `struct DefinitionResult` ### `struct ReferenceResult` ## Typedefs ### `typedef struct ProjectFile ProjectFile` **Description**: Represents a tracked file in the LSP project. ### `typedef struct ReferenceResult ReferenceResult` ## Functions ### `void lsp_project_init(const char *root_path)` **Description**: Initializes the LSP project with the given root path. **Method**: POST **Endpoint**: `/lsp/project/init` **Parameters**: #### Query Parameters - **root_path** (string) - Required - The root path of the project. ### `ProjectFile * lsp_project_get_file(const char *uri)` **Description**: Retrieves a tracked file by its URI. **Method**: GET **Endpoint**: `/lsp/project/file` **Parameters**: #### Query Parameters - **uri** (string) - Required - The URI of the file to retrieve. ### `void lsp_project_update_file(const char *uri, const char *src)` **Description**: Updates the content of a tracked file or adds it if it doesn't exist. **Method**: PUT **Endpoint**: `/lsp/project/file/update` **Parameters**: #### Request Body - **uri** (string) - Required - The URI of the file. - **src** (string) - Required - The source code content of the file. ### `DefinitionResult lsp_project_find_definition(const char *name)` **Description**: Finds the definition of a given symbol name. **Method**: GET **Endpoint**: `/lsp/project/definition` **Parameters**: #### Query Parameters - **name** (string) - Required - The name of the symbol to find. ### `ReferenceResult * lsp_project_find_references(const char *name)` **Description**: Finds all references to a given symbol name. **Method**: GET **Endpoint**: `/lsp/project/references` **Parameters**: #### Query Parameters - **name** (string) - Required - The name of the symbol to find references for. ## Variables ### `LSPProject * g_project` **Description**: Global instance of the LSP project state. ``` -------------------------------- ### Zen-C Token Types and Structures Source: https://z-libs.github.io/Zen-C-Docs/zprep_8h_source This C code snippet defines the enumeration for Zen-C token types, covering various language constructs like identifiers, literals, operators, keywords, and special symbols. It also defines the `Token` structure to hold token information (type, start position, length, line, and column) and the `Lexer` structure to manage the state of the lexical analysis process. ```c typedef enum { TOK_EOF = 0, TOK_IDENT, TOK_INT, TOK_FLOAT, TOK_STRING, TOK_FSTRING, TOK_CHAR, TOK_LPAREN, TOK_RPAREN, TOK_LBRACE, TOK_RBRACE, TOK_LBRACKET, TOK_RBRACKET, TOK_LANGLE, TOK_RANGLE, TOK_COMMA, TOK_COLON, TOK_SEMICOLON, TOK_OP, TOK_AT, TOK_DOTDOT, TOK_DOTDOT_EQ, TOK_DOTDOT_LT, TOK_ARROW, TOK_PIPE, TOK_TEST, TOK_ASSERT, TOK_SIZEOF, TOK_DEF, TOK_DEFER, TOK_AUTOFREE, TOK_QUESTION, TOK_USE, TOK_QQ, TOK_QQ_EQ, TOK_Q_DOT, TOK_DCOLON, TOK_TRAIT, TOK_IMPL, TOK_AND, TOK_OR, TOK_FOR, TOK_COMPTIME, TOK_ELLIPSIS, TOK_UNION, TOK_ASM, TOK_VOLATILE, TOK_ASYNC, TOK_AWAIT, TOK_PREPROC, TOK_ALIAS, TOK_COMMENT, TOK_OPAQUE, TOK_UNKNOWN } TokenType; typedef enum {…}; typedef struct { TokenType type; const char *start; int len; int line; int col; } Token; typedef struct {…}; typedef struct { const char *src; int pos; int line; int col; } Lexer; typedef struct {…}; ``` -------------------------------- ### Plugin Manager Initialization and Cleanup Source: https://z-libs.github.io/Zen-C-Docs/plugin__manager_8h Functions to initialize and clean up the plugin management system. ```APIDOC ## POST /plugin-manager/init ### Description Initializes the plugin system. ### Method POST ### Endpoint /plugin-manager/init ### Parameters None ### Request Example ```json {} ``` ### Response #### Success Response (200) - **status** (string) - Indicates success. #### Response Example ```json { "status": "initialized" } ``` ## DELETE /plugin-manager/cleanup ### Description Cleans up the plugin system and frees resources. ### Method DELETE ### Endpoint /plugin-manager/cleanup ### Parameters None ### Request Example ```json {} ``` ### Response #### Success Response (200) - **status** (string) - Indicates successful cleanup. #### Response Example ```json { "status": "cleaned_up" } ``` ``` -------------------------------- ### Regex Plugin Initialization and Transpilation (C) Source: https://z-libs.github.io/Zen-C-Docs/regex_8c This C code snippet defines the initialization function and the main transpilation function for the regex plugin in Zen-C. It includes necessary headers and declares the plugin structure with its name and callback function. ```c #include "zprep_plugin.h" #include #include #include #include ZPlugin regex_plugin = {.name = "regex", .fn = regex_transpile}; void regex_transpile (const char *input_body, const ZApi *api) { // Function implementation for regex transpilation } ZPlugin * z_plugin_init (void) { return ®ex_plugin; } ``` -------------------------------- ### lsp_build_index Function Documentation Source: https://z-libs.github.io/Zen-C-Docs/lsp__index_8h Documents the `lsp_build_index` function, which constructs an LSP index from a given Abstract Syntax Tree (AST) root. It details the function's parameters: an `LSPIndex` pointer and an `ASTNode` pointer. ```c void lsp_build_index | ( | LSPIndex * | _idx_ , | | ASTNode * | _root_ | ) ``` -------------------------------- ### Forth Plugin Entry Point Function (Zen-C) Source: https://z-libs.github.io/Zen-C-Docs/forth_8c The `zprep_forth_plugin_fn` function serves as the main entry point for the Forth plugin. It receives the input body and an API structure, allowing it to process Forth code or interact with the Zen-C environment. ```c void zprep_forth_plugin_fn (const char *input_body, const ZApi *api) { char *out = NULL; process_forth_source ((char *)input_body, &out); api->write (out); free (out); } ``` -------------------------------- ### lsp_goto_definition Function Implementation Source: https://z-libs.github.io/Zen-C-Docs/lsp__analysis_8c Implements the 'lsp_goto_definition' function, enabling navigation to the definition of a symbol at a specific cursor position. It requires the file URI, line, column, and a request identifier. ```c void lsp_goto_definition | ( | const char * | _uri_ , | | int | _line_ , | | int | _col_ , | | int | _id_ | ) | | ``` -------------------------------- ### Initialization Source: https://z-libs.github.io/Zen-C-Docs/parser_8h Function for initializing built-in types and symbols. ```APIDOC ## init_builtins() ### Description Initializes built-in types and symbols. ### Method N/A (Function Signature) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (N/A) N/A #### Response Example N/A ``` -------------------------------- ### Zen-C Header Inclusion and Dependencies Source: https://z-libs.github.io/Zen-C-Docs/ast_8h Demonstrates the standard header inclusions for Zen-C source files, including project-specific headers like 'zprep.h' and standard library headers such as 'stdlib.h'. It also shows the include dependency graph for 'ast.h', illustrating its relationships with other files in the project. ```c #include "zprep.h" #include Include dependency graph for ast.h: This graph shows which files directly or indirectly include this file: Go to the source code of this file. ``` -------------------------------- ### Zen-C Code Generation Main Entry Points Source: https://z-libs.github.io/Zen-C-Docs/codegen_8h_source These functions serve as the primary entry points for the code generation process. They take a ParserContext, an ASTNode, and a FILE pointer for output, initiating the traversal and emission of code based on the AST structure. ```c #ifndef CODEGEN_H #define CODEGEN_H #include "../ast/ast.h" #include "../parser/parser.h" #include "../zprep.h" #include // Main codegen entry points. void codegen_node(ParserContext *ctx, ASTNode *node, FILE *out); void codegen_node_single(ParserContext *ctx, ASTNode *node, FILE *out); void codegen_walker(ParserContext *ctx, ASTNode *node, FILE *out); void codegen_expression(ParserContext *ctx, ASTNode *node, FILE *out); void codegen_match_internal(ParserContext *ctx, ASTNode *node, FILE *out, int use_result); #endif ``` -------------------------------- ### emit_preamble Source: https://z-libs.github.io/Zen-C-Docs/codegen_8h Emits the standard preamble, including includes and macros, to the output file. ```APIDOC ## emit_preamble() ### Description Emits the standard preamble (includes, macros) to the output file. ### Method N/A (Function Signature) ### Parameters * `_ctx_` (ParserContext *) - The parser context. * `_out_` (FILE *) - The output file stream. ``` -------------------------------- ### CUDA Kernel Launch Syntax in Zen C Source: https://z-libs.github.io/Zen-C-Docs/index Demonstrates the Zen C `launch` statement for invoking CUDA kernels, specifying grid, block, shared memory, and stream configurations. ```zen-c launch kernel_name(args) with { grid: num_blocks, block: threads_per_block, shared_mem: 1024, // Optional stream: my_stream // Optional }; ``` -------------------------------- ### cJSON Version and Initialization Source: https://z-libs.github.io/Zen-C-Docs/cJSON_8h_source Retrieve the version of the cJSON library and initialize custom memory allocation hooks. ```APIDOC ## cJSON Version and Initialization ### Description Provides functions to get the cJSON library version and to set custom memory allocation functions. ### Functions #### `cJSON_Version()` * **Description**: Returns the version of cJSON as a string. * **Method**: GET * **Endpoint**: N/A (Library function) * **Return Type**: `const char*` #### `cJSON_InitHooks(cJSON_Hooks *hooks)` * **Description**: Initializes cJSON with custom memory allocation functions (malloc, free). * **Method**: POST * **Endpoint**: N/A (Library function) * **Parameters**: * **hooks** (`cJSON_Hooks*`) - Required - A pointer to a structure containing `malloc_fn` and `free_fn`. * **Request Body**: ```json { "malloc_fn": "function_pointer", "free_fn": "function_pointer" } ``` * **Response**: * **Success Response (void)**: No return value, but hooks are set. ```