### Install Rules for Executable, Libraries, and Data Files
Source: https://github.com/zenc-lang/zenc/blob/main/CMakeLists.txt
Defines installation rules for the 'zc' executable, standard library files, plugin directories, and documentation JSON files. Also handles man page installation on Unix-like systems.
```cmake
install(TARGETS zc DESTINATION bin)
install(FILES std.zc DESTINATION share/zenc)
install(DIRECTORY std DESTINATION share/zenc)
install(FILES src/zen/facts.json DESTINATION share/zenc)
install(FILES src/repl/docs.json DESTINATION share/zenc)
install(FILES plugins/zprep_plugin.h DESTINATION include/zenc)
install(DIRECTORY ${CMAKE_BINARY_DIR}/plugins/ DESTINATION lib/zenc/plugins
FILES_MATCHING PATTERN "*.${PLUGIN_EXT}")
if(UNIX AND NOT WIN32)
install(FILES man/zc.1 DESTINATION share/man/man1)
install(FILES man/zc.5 DESTINATION share/man/man5)
install(FILES man/zc.7 DESTINATION share/man/man7)
endif()
```
--------------------------------
### Install Zen C Compiler
Source: https://github.com/zenc-lang/zenc/blob/main/README.md
Follow these steps to clone the repository, build, and install the Zen C compiler on your system.
```bash
git clone https://github.com/zenc-lang/zenc.git
cd zenc
make clean # remove old build files
make
sudo make install
```
--------------------------------
### Negative Test Pattern Example
Source: https://github.com/zenc-lang/zenc/blob/main/tests/DOCS.md
Demonstrates the pattern for files testing compiler rejection. Must start with `// EXPECT: FAIL`.
```zc
// EXPECT: FAIL
// Using a moved value should be rejected
struct Mover { val: int }
impl Drop for Mover { fn drop(self) {} }
fn consume(m: Mover) {}
fn main() {
let m = Mover { val: 10 }
consume(m)
consume(m) // Error: use of moved value
}
```
--------------------------------
### Standard Library Import Examples
Source: https://github.com/zenc-lang/zenc/blob/main/tests/DOCS.md
Shows how to import standard library modules in Zenc. `std/test.zc` is auto-imported with the `test` keyword.
```zc
import "std/core.zc"
import "std/string.zc"
import "std/result.zc"
```
--------------------------------
### Start Zen C REPL
Source: https://github.com/zenc-lang/zenc/blob/main/README.md
Launch the Read-Eval-Print Loop (REPL) for interactive Zen C code experimentation with in-process JIT compilation.
```bash
zc repl
```
--------------------------------
### File Header Comment Example
Source: https://github.com/zenc-lang/zenc/blob/main/tests/DOCS.md
Example of a file header comment describing the test file's content.
```zc
// control-flow/match: match expression compilation and runtime behavior
```
--------------------------------
### Run Portable Executable
Source: https://github.com/zenc-lang/zenc/blob/main/README.md
Example of running the APE-compiled Zenc compiler on any supported OS to build a project.
```bash
./out/bin/zc.com build hello.zc -o hello
```
--------------------------------
### Standard Test File Structure
Source: https://github.com/zenc-lang/zenc/blob/main/tests/DOCS.md
Illustrates the required structure for a typical Zen C test file, including sections for setup, execution, and assertion.
```zc
//
/: one-line description of what this tests
// Arrange -- set up inputs and expected values
// Act -- execute the feature under test
let input = some_value;
let result = feature_under_test(input);
// Assert -- verify with descriptive message
expect_eq(result, expected, "feature(x) should return y [when condition]");
```
--------------------------------
### Negative Test File Header Example
Source: https://github.com/zenc-lang/zenc/blob/main/tests/DOCS.md
Example of a file header comment for a negative test file, placed after the `// EXPECT: FAIL` marker.
```zc
// EXPECT: FAIL
// keyword-ident/fn: 'fn' used as identifier should be rejected
```
--------------------------------
### Compile and Run Zen C with Zig
Source: https://github.com/zenc-lang/zenc/blob/main/README.md
Use this command to compile and run a Zen C program using Zig as the C compiler backend. Ensure Zig is installed and configured.
```bash
# Compile and run a Zen C program with Zig
zc run app.zc --cc zig
```
--------------------------------
### Start Zen C Language Server
Source: https://github.com/zenc-lang/zenc/blob/main/README.md
Initiate the Zen C Language Server (LSP) for editor integration using the 'zc lsp' command. It communicates via standard I/O (JSON-RPC 2.0).
```bash
zc lsp
```
--------------------------------
### Compiling Embedded Zen C Application After Install
Source: https://github.com/zenc-lang/zenc/blob/main/README.md
Compile your C application after installing Zen C. Use the system's include path for the public headers.
```bash
cc -I /usr/local/include/zenc my_tool.c -o my_tool
```
--------------------------------
### Positive Test Case Example
Source: https://github.com/zenc-lang/zenc/blob/main/tests/DOCS.md
Example of a positive test case demonstrating a feature working with typical valid input.
```zc
expect_eq(fn(42), 42, "fn(42) should return 42")
```
--------------------------------
### Embedding Zen C Compiler (C API)
Source: https://github.com/zenc-lang/zenc/blob/main/README.md
Use the public C API headers to embed the Zen C compiler in your tools. This example shows basic compiler initialization and execution.
```c
#include
#include
#include
int main(void) {
ZenCompiler compiler = {0};
compiler.config.input_file = "source.zc";
return driver_run(&compiler);
}
```
--------------------------------
### Assertion Message Examples
Source: https://github.com/zenc-lang/zenc/blob/main/tests/DOCS.md
Illustrates correct and incorrect ways to format assertion messages. Messages should describe the expectation clearly.
```zc
// BAD -- unacceptable, will fail review:
assert(ok, "ok");
assert(result == 42);
assert(cond, "x == 42"); // tautological
// GOOD -- required:
expect_eq(result, 42, "double(21) should return 42");
expect(result != null, "safe-nav should return null on missing field");
assert(x > 0, "Fibonacci(10) should be positive");
```
--------------------------------
### Filtering Tests by Name Pattern
Source: https://github.com/zenc-lang/zenc/blob/main/tests/DOCS.md
Example of filtering tests to run only those matching a specific name pattern using `ZC_TEST_FILTER`.
```sh
# Filter by name pattern:
ZC_TEST_FILTER="string" make test # Only tests with "string" in the path
```
--------------------------------
### Zenc Unit Test Syntax
Source: https://github.com/zenc-lang/zenc/blob/main/README.md
Example of defining a test case in Zenc using the built-in testing framework. Tests feature per-test isolation and non-fatal assertions.
```zc
test "descriptive name" {
let a = 3;
assert(a > 0, "a should be positive");
}
```
--------------------------------
### Test with Different Backends
Source: https://github.com/zenc-lang/zenc/blob/main/CONTRIBUTING.md
Run the test suite using different C compilers as backends.
```bash
./tests/scripts/run_tests.sh --cc clang # Clang
./tests/scripts/run_tests.sh --cc zig # Zig cc
./tests/scripts/run_tests.sh --cc tcc # Tiny C Compiler
```
--------------------------------
### Build with Warnings as Errors
Source: https://github.com/zenc-lang/zenc/blob/main/CONTRIBUTING.md
Clean the build, then compile with -Werror and parallel jobs for recommended pre-PR checks.
```bash
make clean && make WERROR=1 -j$(nproc)
```
--------------------------------
### Platform-Specific Library Logic
Source: https://github.com/zenc-lang/zenc/blob/main/CMakeLists.txt
Sets up platform-dependent libraries and file extensions. Includes logic for Windows (Winsock), macOS (CoreFoundation), and Linux/BSD (libdl, libm).
```cmake
set(PLATFORM_LIBS Threads::Threads)
if(ZC_USE_JIT)
list(APPEND PLATFORM_LIBS ${TCC_LIBRARY})
endif()
if(WIN32)
# Winsock 2 for Networking, ws2_32 is required for our socket abstraction
list(APPEND PLATFORM_LIBS ws2_32)
set(PLUGIN_EXT ".dll")
set(BINARY_EXT ".exe")
set(SHARED_FLAGS "")
elseif(APPLE)
# macOS requires CoreFoundation for _NSGetExecutablePath
find_library(COREFOUNDATION_FRAMEWORK CoreFoundation)
list(APPEND PLATFORM_LIBS ${CMAKE_DL_LIBS} ${COREFOUNDATION_FRAMEWORK})
set(SHARED_FLAGS "-fPIC")
set(BINARY_EXT "")
set(PLUGIN_EXT ".dylib")
else()
# Linux/BSD: Link with libdl for zc_dlopen and libm for math
if(NOT ZC_NO_PLUGINS)
list(APPEND PLATFORM_LIBS ${CMAKE_DL_LIBS})
endif()
list(APPEND PLATFORM_LIBS m)
set(SHARED_FLAGS "-fPIC")
set(BINARY_EXT "")
set(PLUGIN_EXT ".so")
endif()
```
--------------------------------
### Build Zenc on Windows
Source: https://github.com/zenc-lang/zenc/blob/main/README.md
Build the Zenc compiler executable on Windows using the provided batch script with GCC (MinGW).
```cmd
build.bat
```
--------------------------------
### Convenience Alias for Full Lisp Content
Source: https://github.com/zenc-lang/zenc/blob/main/README.md
Use the convenience alias `--backend-full-content` for transpiling to Lisp to display the full raw content without truncation.
```bash
zc transpile file.zc --backend lisp --backend-full-content
```
--------------------------------
### Running a Single Test File
Source: https://github.com/zenc-lang/zenc/blob/main/tests/DOCS.md
Command to run a specific Zenc test file directly.
```sh
./zc run tests/path/to/test.zc
```
--------------------------------
### LLDB Debugger Launch Configuration for VS Code
Source: https://github.com/zenc-lang/zenc/blob/main/README.md
Set up a launch configuration in VS Code's 'launch.json' to debug Zen C applications using LLDB, with the build task specified as a pre-launch task.
```json
{
"name": "Zen C: Debug (LLDB)",
"type": "lldb",
"request": "launch",
"program": "${fileDirname}/app",
"preLaunchTask": "Zen C: Build Debug"
}
```
--------------------------------
### Development Targets
Source: https://github.com/zenc-lang/zenc/blob/main/README.md
Common make targets for formatting, linting, benchmarking, and building with warnings.
```bash
make format # Auto-format all source files with clang-format
make format-check # Verify formatting without changing files
make lint # Run format-check + shellcheck on test scripts
make bench # Run performance benchmarks
make WERROR=1 # Build with -Werror (warnings as errors)
```
--------------------------------
### Show Full Raw Content for Lisp Backend
Source: https://github.com/zenc-lang/zenc/blob/main/README.md
Transpile a Zen C file to Lisp format and display the full raw content without truncation. This option is useful for debugging or when complete output is required.
```bash
# Show full raw content (no truncation)
zc transpile file.zc --backend lisp --backend-opt full-content
```
--------------------------------
### Build Native Plugins with Custom Command
Source: https://github.com/zenc-lang/zenc/blob/main/CMakeLists.txt
Uses a custom command to build native plugins for various languages (befunge, brainfuck, forth, lisp, sql). It ensures the plugin directory exists and uses the 'zc' compiler to build shared objects.
```cmake
set(PLUGIN_NAMES befunge brainfuck forth lisp sql)
foreach(plugin ${PLUGIN_NAMES})
set(PLUGIN_OUTPUT "${CMAKE_BINARY_DIR}/plugins/${plugin}${PLUGIN_EXT}")
add_custom_command(
OUTPUT "${PLUGIN_OUTPUT}"
COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/plugins"
COMMAND $ build "${PROJECT_SOURCE_DIR}/plugins/${plugin}.zc" -shared -o "${PLUGIN_OUTPUT}"
DEPENDS zc "${PROJECT_SOURCE_DIR}/plugins/${plugin}.zc"
COMMENT "Building native plugin ${plugin}"
VERBATIM
)
add_custom_target(${plugin}_plugin ALL DEPENDS "${PLUGIN_OUTPUT}")
endforeach()
```
--------------------------------
### Build Zen C Compiler with Zig
Source: https://github.com/zenc-lang/zenc/blob/main/README.md
This command builds the Zen C compiler itself using Zig. It's recommended to use GCC or Clang for building the compiler, but Zig can be used as a backend for operational code.
```bash
# Build the Zen C compiler itself with Zig
make zig
```
--------------------------------
### Run All Tests
Source: https://github.com/zenc-lang/zenc/blob/main/CONTRIBUTING.md
Execute the entire test suite to ensure all functionality remains intact.
```bash
make test
```
--------------------------------
### Running All Tests
Source: https://github.com/zenc-lang/zenc/blob/main/tests/DOCS.md
Command to run all language, compiler, and stdlib tests in C mode.
```sh
make test # Run all language/compiler/stdlib tests (C mode)
```
--------------------------------
### Build Portable Executable (APE)
Source: https://github.com/zenc-lang/zenc/blob/main/README.md
Build the Zenc compiler as an Actually Portable Executable (APE) using Cosmopolitan Libc. This produces a single binary that runs on multiple OS and architectures.
```bash
make ape
sudo env "PATH=$PATH" make install-ape
```
--------------------------------
### Test Target Configuration
Source: https://github.com/zenc-lang/zenc/blob/main/CMakeLists.txt
Sets up a 'test' target that runs various test scripts (run_tests.sh, run_codegen_tests.sh, run_example_transpile.sh). Allows specifying specific test files via the TEST_FILES cache variable.
```cmake
set(TEST_FILES "" CACHE STRING "Space-separated list of specific test files to run")
add_custom_target(test
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/scripts/run_tests.sh -- ${TEST_FILES}
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/scripts/run_codegen_tests.sh ${TEST_FILES}
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/scripts/run_example_transpile.sh ${TEST_FILES}
DEPENDS zc
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
```
--------------------------------
### Running LSP Protocol Tests
Source: https://github.com/zenc-lang/zenc/blob/main/tests/DOCS.md
Command to run the LSP protocol tests.
```sh
make test-lsp # Run LSP protocol tests
```
--------------------------------
### Add Executable and Link Libraries
Source: https://github.com/zenc-lang/zenc/blob/main/CMakeLists.txt
Defines the main executable target 'zc' and links it with the platform-specific libraries. Also applies custom compile flags if provided.
```cmake
add_executable(zc ${SRCS})
target_link_libraries(zc PRIVATE ${PLATFORM_LIBS})
if(NOT "${ZC_COMPILE_FLAGS}" STREQUAL "")
target_compile_options(zc PRIVATE ${ZC_COMPILE_FLAGS})
endif()
```
--------------------------------
### Run Specific Test
Source: https://github.com/zenc-lang/zenc/blob/main/CONTRIBUTING.md
Execute a single test file directly using the Zen C runner.
```bash
./zc run tests/language/control_flow/test_match.zc
```
--------------------------------
### Specify Compiler Backend
Source: https://github.com/zenc-lang/zenc/blob/main/README.md
Use the '--cc' flag with 'zc run' to select a different C compiler backend, such as Clang or Zig.
```bash
zc run app.zc --cc clang
```
```bash
zc run app.zc --cc zig
```
--------------------------------
### Zen C Code with C++ Interop
Source: https://github.com/zenc-lang/zenc/blob/main/README.md
Demonstrates how to include C++ headers and use raw blocks for C++ code within Zen C. This allows for seamless integration with C++ libraries and standard library features.
```zc
include
include
raw {
std::vector make_vec(int a, int b) {
return {a, b};
}
}
fn main() {
let v = make_vec(1, 2);
raw { std::cout << "Size: " << v.size() << std::endl; }
}
```
--------------------------------
### Run Zen C Tests
Source: https://github.com/zenc-lang/zenc/blob/main/README.md
Execute Zen C test files using the 'zc run' command. The output will indicate which tests passed or failed.
```bash
zc run my_file.zc
```
--------------------------------
### Transpile Zen C to C++ for Manual Build
Source: https://github.com/zenc-lang/zenc/blob/main/README.md
Transpile a Zen C file to C++ source code, allowing for a manual build process with g++. This is useful for integrating with existing C++ build systems.
```bash
# Or transpile for manual build
zc transpile app.zc --backend cpp
g++ out.cpp my_cpp_lib.o -o app
```
--------------------------------
### Zen C Kernel Launch Syntax
Source: https://github.com/zenc-lang/zenc/blob/main/README.md
Use the `launch` statement to invoke CUDA kernels with specified grid, block, shared memory, and stream configurations.
```zc
launch kernel_name(args) with {
grid: num_blocks,
block: threads_per_block,
shared_mem: 1024, // Optional
stream: my_stream // Optional
};
```
--------------------------------
### Direct Compilation with CUDA Backend
Source: https://github.com/zenc-lang/zenc/blob/main/README.md
Compile a Zen C application directly for CUDA using the `--backend cuda` flag. This command utilizes nvcc for compilation, enabling GPU programming.
```bash
# Direct compilation with nvcc
zc run app.zc --backend cuda
```
--------------------------------
### Convenience Alias for Pretty JSON Output
Source: https://github.com/zenc-lang/zenc/blob/main/README.md
Use the convenience alias `--json-pretty` to achieve the same result as `--backend json --backend-opt pretty` for transpiling to JSON.
```bash
# OR use convenience aliases:
zc transpile file.zc --backend json --json-pretty
```
--------------------------------
### Zenc Compiler Usage
Source: https://github.com/zenc-lang/zenc/blob/main/README.md
Common commands for compiling, running, and documenting Zenc code, including interactive shell and Zen facts.
```bash
# Compile and run
zc run hello.zc
# Build executable
zc build hello.zc -o hello
# Interactive Shell
zc repl
# Documentation (Recursive)
zc doc main.zc
# Documentation (Single file, no check)
zc doc --no-recursive-doc --no-check main.zc
# Show Zen Facts
zc build hello.zc --zen
```
--------------------------------
### Run Specific Test via Make
Source: https://github.com/zenc-lang/zenc/blob/main/CONTRIBUTING.md
Execute a single test file using the make test command with a specific filter.
```bash
make test only="tests/language/control_flow/test_match.zc"
```
--------------------------------
### Running MISRA Compliance Suite
Source: https://github.com/zenc-lang/zenc/blob/main/tests/DOCS.md
Command to run the MISRA compliance test suite.
```sh
make test-misra # Run MISRA compliance suite
```
--------------------------------
### Compiling Zen C to Objective-C
Source: https://github.com/zenc-lang/zenc/blob/main/README.md
Compile Zen C code to Objective-C using the `--backend objc` flag. This allows integration with Objective-C frameworks like Cocoa/Foundation.
```bash
zc app.zc --backend objc --cc clang
```
--------------------------------
### Using Objective-C Syntax in Zen C
Source: https://github.com/zenc-lang/zenc/blob/main/README.md
Include Objective-C headers using `include` and embed Objective-C syntax within `raw` blocks. Supports string interpolation with Objective-C objects.
```zc
//> 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!";
}
```
--------------------------------
### Transpile Zen C to CUDA for Manual Build
Source: https://github.com/zenc-lang/zenc/blob/main/README.md
Transpile a Zen C file to CUDA C++ source code for a manual build process with nvcc. This provides flexibility in managing the compilation of GPU kernels.
```bash
# Or transpile for manual build
zc transpile app.zc --backend cuda -o app.cu
nvcc app.cu -o app
```
--------------------------------
### Compile Zen C with C++ Backend
Source: https://github.com/zenc-lang/zenc/blob/main/README.md
Directly compile a Zen C application using the C++ backend, which is compatible with C++ libraries. This command uses g++ for compilation.
```bash
# Direct compilation with g++
zc app.zc --backend cpp
```
--------------------------------
### Pretty-print JSON Output
Source: https://github.com/zenc-lang/zenc/blob/main/README.md
Transpile a Zen C file to JSON format and pretty-print the output. This is useful for generating machine-readable Abstract Syntax Trees (AST) for tooling.
```bash
# Pretty-print JSON output
zc transpile file.zc --backend json --backend-opt pretty
```
--------------------------------
### Set Zenc Standard Library Path
Source: https://github.com/zenc-lang/zenc/blob/main/README.md
Configure the ZC_ROOT environment variable to specify the location of the Zenc Standard Library, allowing the compiler to be run from any directory.
```bash
export ZC_ROOT=/path/to/Zen-C
```
--------------------------------
### Compiling Embedded Zen C Application
Source: https://github.com/zenc-lang/zenc/blob/main/README.md
Compile your C application that embeds the Zen C compiler. Include necessary paths for the public headers.
```bash
cc -I src/public -I src -I src/utils my_tool.c -o my_tool
```
--------------------------------
### Run Specialized Test Suites
Source: https://github.com/zenc-lang/zenc/blob/main/CONTRIBUTING.md
Execute specialized test suites for specific purposes like LSP integration or MISRA compliance.
```bash
make test-lsp # LSP integration tests
make test-tcc # Full suite with TCC backend
make test-misra # MISRA C compliance checks
make test-asan # AddressSanitizer / UBSan tests
```
--------------------------------
### Writing CUDA Kernels in Zen C
Source: https://github.com/zenc-lang/zenc/blob/main/README.md
Define CUDA kernels using the `@global` decorator and Zen C's function syntax. Includes memory allocation, data initialization, kernel launch, and synchronization.
```zc
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();
}
```
--------------------------------
### Create Feature Branch
Source: https://github.com/zenc-lang/zenc/blob/main/CONTRIBUTING.md
Create a new branch for your feature or bugfix to keep changes organized.
```bash
git checkout -b feature/NewThing
```
--------------------------------
### Build Debug Task for VS Code
Source: https://github.com/zenc-lang/zenc/blob/main/README.md
Configure a build task in VS Code's 'tasks.json' to compile Zen C code with debugging flags enabled.
```json
{
"label": "Zen C: Build Debug",
"type": "shell",
"command": "zc",
"args": [ "${file}", "-g", "-o", "${fileDirname}/app", "-O0" ],
"group": { "kind": "build", "isDefault": true }
}
```
--------------------------------
### Per-test-block Structure
Source: https://github.com/zenc-lang/zenc/blob/main/tests/DOCS.md
Defines the standard structure for a Zenc test block, including Arrange, Act, and Assert phases.
```zc
test "" {
// Arrange
// Act
// Assert
expect_eq(actual, expected, "description");
}
```
--------------------------------
### Add Compile Definitions Based on Feature Flags
Source: https://github.com/zenc-lang/zenc/blob/main/CMakeLists.txt
Adds preprocessor definitions to the build based on the state of feature flag options. This allows the C/C++ code to conditionally compile features.
```cmake
add_compile_definitions(ZC_HAS_LSP=$>)
add_compile_definitions(ZC_HAS_REPL=$>)
add_compile_definitions(ZC_HAS_PLUGINS=$>)
add_compile_definitions(ZC_HAS_ZEN=$>)
add_compile_definitions(ZC_HAS_CPP_BACKEND=$>)
add_compile_definitions(ZC_HAS_CUDA_BACKEND=$>)
add_compile_definitions(ZC_HAS_OBJC_BACKEND=$>)
add_compile_definitions(ZC_HAS_JSON_BACKEND=$>)
add_compile_definitions(ZC_HAS_LISP_BACKEND=$>)
add_compile_definitions(ZC_HAS_DOT_BACKEND=$>)
add_compile_definitions(ZC_HAS_ASTDUMP_BACKEND=$>)
```
--------------------------------
### Zen C Assertions in Tests
Source: https://github.com/zenc-lang/zenc/blob/main/README.md
Use 'expect' for non-fatal assertions within a test to check multiple conditions. Both 'expect' assertions will run even if the first one fails.
```zc
test "example" {
expect(result != null, "result should not be null");
expect(result.code == 200, "status should be 200");
// both run even if the first fails
}
```
--------------------------------
### Distclean Target for Cleaning Build Artifacts
Source: https://github.com/zenc-lang/zenc/blob/main/CMakeLists.txt
Defines a 'distclean' target to clean the build directory. It removes compiled files, the 'out.c' file, and the generated plugin directory.
```cmake
add_custom_target(distclean
COMMAND ${CMAKE_COMMAND} --build . --target clean
COMMAND ${CMAKE_COMMAND} -E rm -f out.c
COMMAND ${CMAKE_COMMAND} -E rm -rf ${CMAKE_BINARY_DIR}/plugins
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
```
--------------------------------
### Define Feature Flags with Options
Source: https://github.com/zenc-lang/zenc/blob/main/CMakeLists.txt
Defines boolean options to control feature availability like plugins, LSP, REPL, Zen facts, and backends. These options can be set to ON or OFF during the CMake configuration.
```cmake
option(ZC_NO_PLUGINS "Disable the plugin system entirely" OFF)
option(ZC_NO_LSP "Disable LSP server" OFF)
option(ZC_NO_REPL "Disable interactive REPL" OFF)
option(ZC_NO_ZEN "Disable Zen facts/docs" OFF)
option(ZC_NO_BACKENDS "Disable non-C backends" OFF)
```
--------------------------------
### Conditional Compile Definition and Message
Source: https://github.com/zenc-lang/zenc/blob/main/CMakeLists.txt
Conditionally adds a compile definition and prints a status message if the plugin system is disabled.
```cmake
if(ZC_NO_PLUGINS)
add_compile_definitions(ZC_NO_PLUGINS)
message(STATUS "Plugin system disabled.")
endif()
```
--------------------------------
### Misra Test Target
Source: https://github.com/zenc-lang/zenc/blob/main/CMakeLists.txt
Defines a 'test-misra' custom target to run Misra-specific tests using a dedicated script.
```cmake
add_custom_target(test-misra
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/scripts/run_misra_tests.sh
DEPENDS zc
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
```
--------------------------------
### Zen C CUDA Standard Library Usage
Source: https://github.com/zenc-lang/zenc/blob/main/README.md
Utilize the `std/cuda.zc` library for common CUDA operations like memory management and synchronization. Thread indexing functions are for use inside kernels.
```zc
import "std/cuda.zc"
// Memory management
let d_ptr = cuda_alloc(1024);
cuda_copy_to_device(d_ptr, h_ptr, 1024 * sizeof(float));
defer cuda_free(d_ptr);
// Synchronization
cuda_sync();
// Thread Indexing (use inside kernels)
let i = thread_id(); // Global index
let bid = block_id();
let tid = local_id();
```
--------------------------------
### TCC Test Target
Source: https://github.com/zenc-lang/zenc/blob/main/CMakeLists.txt
Defines a 'test-tcc' custom target to run tests specifically using the TCC compiler, leveraging the run_tests.sh script with a '--cc tcc' argument.
```cmake
add_custom_target(test-tcc
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/scripts/run_tests.sh --cc tcc
DEPENDS zc
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.