diff --git a/.gitignore b/.gitignore index 62c77f9c..f595e66e 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,9 @@ docs/xml/ *.o *.s +# Ignore IDE directories +.vscode + # ignore the lsp-client server node modules node_modules package-lock.json diff --git a/.vscode/settings.json b/.vscode/settings.json index eb4d8854..551c6737 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,41 +1,44 @@ { "files.associations": { - "type.h": "c", - "array": "c", - "atomic": "c", - "bit": "c", - "charconv": "c", - "cmath": "c", - "compare": "c", - "concepts": "c", - "string": "c", - "unordered_map": "c", - "exception": "c", - "algorithm": "c", - "memory": "c", - "memory_resource": "c", - "optional": "c", - "random": "c", - "string_view": "c", - "type_traits": "c", - "utility": "c", - "functional": "c", - "format": "c", - "iosfwd": "c", - "istream": "c", - "limits": "c", - "new": "c", - "numeric": "c", - "queue": "c", - "ranges": "c", - "span": "c", - "sstream": "c", - "streambuf": "c", - "system_error": "c", - "tuple": "c", - "typeinfo": "c", - "variant": "c", - "vector": "c", - "help.h": "c" + "*.py": "python", + "*.rpy": "renpy", + "type.h": "c", + "array": "c", + "atomic": "c", + "bit": "c", + "charconv": "c", + "cmath": "c", + "compare": "c", + "concepts": "c", + "string": "c", + "unordered_map": "c", + "exception": "c", + "algorithm": "c", + "memory": "c", + "memory_resource": "c", + "optional": "c", + "random": "c", + "string_view": "c", + "type_traits": "c", + "utility": "c", + "functional": "c", + "format": "c", + "iosfwd": "c", + "istream": "c", + "limits": "c", + "new": "c", + "numeric": "c", + "queue": "c", + "ranges": "c", + "span": "c", + "sstream": "c", + "streambuf": "c", + "system_error": "c", + "tuple": "c", + "typeinfo": "c", + "variant": "c", + "vector": "c", + "help.h": "c", + "llvm.h": "c" } } \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 86615bea..a74e89a2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,8 +1,8 @@ -# Contributing to Lux +# Contributing to Luma -Thank you for your interest in contributing to Lux, a simple yet powerful systems programming language! +Thank you for your interest in contributing to Luma, a simple yet powerful systems programming language! -This document outlines the guidelines and best practices to help you contribute effectively. Whether you're reporting bugs, suggesting features, or submitting code, we appreciate your help making Lux better for everyone. +This document outlines the guidelines and best practices to help you contribute effectively. Whether you're reporting bugs, suggesting features, or submitting code, we appreciate your help making Luma better for everyone. ## Table of Contents @@ -24,7 +24,7 @@ By participating in this project, you agree to abide by the Contributor Covenant ### Reporting Issues -If you find a bug or unexpected behavior in Lux, please open an issue on the GitHub repository with: +If you find a bug or unexpected behavior in Luma, please open an issue on the GitHub repository with: - A clear and descriptive title - Steps to reproduce the problem @@ -58,18 +58,20 @@ To set up a local development environment: 1. Ensure you have the required dependencies installed (e.g., cmake, ninja, gcc or your preferred compiler). -2. Clone the Lux repository: - ```bash - git clone https://github.com/your-username/lux.git - cd lux - ``` +2. Clone the Luma repository: + +```bash +git clone https://github.com/your-username/luma.git +cd luma +``` 3. Build the project following instructions in the README (or specific build scripts). 4. Run to ensure everything is working: - ```bash - ./lux - ``` + +```bash +./luma +``` ## Style Guide @@ -93,4 +95,4 @@ By contributing, you agree that your contributions will be licensed under the MI --- -**Thank you for helping make Lux awesome!** \ No newline at end of file +**Thank you for helping make Luma awesome!** diff --git a/LPBS/parser.lx b/LPBS/parser.lx index 928713da..3b38d422 100644 --- a/LPBS/parser.lx +++ b/LPBS/parser.lx @@ -2,6 +2,7 @@ @use "lexer" as lexer @use "ast" as ast +@use "sys" as sys const BindingPower -> enum { BP_NONE, /**< No binding power */ @@ -46,7 +47,7 @@ pub const parse -> fn (tks: *Token, path: *char) *ASTNode { let psr: Parser; init_parser(&psr, tks, path); - output(peek(&psr, 10).value, "\n"); + sys::print(peek(&psr, 10).value); return cast<*ASTNode>(0); } diff --git a/README.md b/README.md index 40622839..1ff98d2d 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,12 @@ # Luma + *A low-level compiled alternative to C, C++, and more!*

- Luma Logo + Luma Logo

-

- Why? • - Goals • - Performance • - Static Analysis & Ownership • - Status • - Getting Started • - Join Us -

+[Why?](#why) • [Goals](#language-goals) • [Performance](#performance) • [Static Analysis & Ownership](#static-analysis-and-ownership) • [Status](#project-status) • [Getting Started](#getting-started) • [Join Us](#join-us) --- @@ -60,6 +53,7 @@ Build succeeded! Written to '3d_test' (51ms) ``` **Real-world metrics:** + - **51ms**: Complete 3D graphics app with math, memory management, strings, and terminal effects - **+1ms**: Memory safety analysis overhead (essentially free) - **Sub-100ms**: Typical compilation times for most projects @@ -72,6 +66,7 @@ $ ls -lh 3d_test_stripped ``` **Comparable to C** — Luma produces tiny, efficient binaries: + - **24KB**: Stripped 3D graphics application - **29KB**: With debug symbols - **Zero runtime**: No garbage collector, no hidden allocations @@ -79,12 +74,12 @@ $ ls -lh 3d_test_stripped ### Comparison Table | Language | Compile Time Range | Your Test | Binary Size | -|----------|-------------------|-----------|-------------| -| **Luma** | **50-52ms** | **51ms** | **24KB** | -| C/C++ | 100-800ms | ~300ms | 40-80KB | -| Rust | 2-15s | ~3-5s | 150-400KB | -| Go | 100-400ms | ~200ms | 1.5-2MB | -| Zig | 200-600ms | ~400ms | 30-50KB | +|----------|--------------------|-----------|-------------| +| C/C++ | 100-800ms | ~300ms | 40-80KB | +| Rust | 2-15s | ~3-5s | 150-400KB | +| Go | 100-400ms | ~200ms | 1.5-2MB | +| Zig | 200-600ms | ~400ms | 30-50KB | +| **Luma** | **50-52ms** | **51ms** | **24KB** | --- @@ -105,6 +100,7 @@ $ ls -lh 3d_test_stripped Luma performs **end-of-type-check static analysis** to ensure memory safety without runtime overhead. The analyzer checks for: + - Memory allocated but never freed - Double frees - Use-after-free errors @@ -141,6 +137,7 @@ pub const main = fn() int { ``` **Key Features:** + - `#returns_ownership` — Function returns newly allocated memory - `#takes_ownership` — Function takes responsibility for freeing memory - `defer` — Ensures cleanup happens at scope exit @@ -152,9 +149,10 @@ pub const main = fn() int { **Current Phase:** Early Development -Luma is currently in active development. Core language features are being implemented and the compiler architecture is being established. +Luma is currently in active development. Core language features are being implemented and the compiler architecture is being established. **What Works:** + - ✅ Complete lexer and parser - ✅ Full type system with structs, enums, functions - ✅ Static memory analysis with ownership tracking @@ -182,6 +180,7 @@ You'll need the following tools installed: **Important:** Luma requires LLVM 20.0 or higher due to critical bug fixes in the constant generation system. **Known Issues:** + - **LLVM 19.1.x**: Contains a regression that causes crashes during code generation (`illegal hardware instruction` errors) - **LLVM 18.x and older**: Not tested, may have compatibility issues @@ -196,6 +195,7 @@ llvm-config --version #### Linux Install **Arch Linux:** + ```bash sudo pacman -S llvm # For development headers: @@ -203,6 +203,7 @@ sudo pacman -S llvm-libs ``` **Fedora/RHEL:** + ```bash sudo dnf update llvm llvm-devel llvm-libs # Or install specific version: @@ -210,12 +211,14 @@ sudo dnf install llvm20-devel llvm20-libs ``` **Ubuntu/Debian:** + ```bash sudo apt update sudo apt install llvm-20-dev ``` **macOS (Homebrew):** + ```bash brew install llvm ``` @@ -223,20 +226,22 @@ brew install llvm ### Common Issues **"illegal hardware instruction" during compilation:** + - This indicates an LLVM version incompatibility - Upgrade to LLVM 20.0+ to resolve this issue - See [LLVM Version Requirements](#llvm-version-requirements) above **Missing LLVM development headers:** + ```bash # Install development packages sudo dnf install llvm-devel # Fedora/RHEL sudo apt install llvm-dev # Ubuntu/Debian ``` -# Building LLVM on Windows +## Building LLVM on Windows -## Prerequisites +### Windows Prerequisites Install the required tools using Scoop: @@ -245,56 +250,64 @@ Install the required tools using Scoop: scoop install python ninja cmake mingw ``` -## Build Steps +### Build Steps 1. Clone the LLVM repository: + ```bash git clone https://github.com/llvm/llvm-project.git cd llvm-project ``` 2. Configure the build: + ```bash cmake -S llvm -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS="clang;lld" -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_ASM_COMPILER=gcc ``` 3. Build LLVM (adjust `-j8` based on your CPU cores): + ```bash ninja -C build -j8 ``` -## Notes +### Notes - Build time: 30 minutes to several hours depending on hardware - Disk space required: ~15-20 GB for full build - RAM usage: Can use 8+ GB during compilation - If you encounter memory issues, reduce parallelism: `ninja -C build -j4` or `ninja -C build -j1` -## After Build +### After Build The compiled binaries will be located in `build/bin/` -### Add to PATH (Optional but Recommended) +#### Add to PATH (Optional but Recommended) To use `clang`, `lld`, and other LLVM tools from anywhere, add the build directory to your PATH: -**Option 1: Temporary (current session only)** +##### Option 1: Temporary (current session only) + ```cmd set PATH=%PATH%;C:\path\to\your\llvm-project\build\bin ``` -**Option 2: Permanent** +##### Option 2: Permanent + 1. Open System Properties → Advanced → Environment Variables 2. Edit the `PATH` variable for your user or system 3. Add the full path to your `build\bin` directory (e.g., `C:\Users\yourname\Desktop\llvm-project\build\bin`) -**Option 3: Using PowerShell (permanent)** +##### Option 3: Using PowerShell (permanent) + ```powershell [Environment]::SetEnvironmentVariable("PATH", $env:PATH + ";C:\path\to\your\llvm-project\build\bin", "User") ``` -### Verify Installation +#### Verify Installation + After adding to PATH, open a new command prompt and test: + ```bash clang --version lld --version @@ -303,9 +316,9 @@ llvm-config --version --- -## Examples +### Examples -### Hello World +#### Hello World ```luma @module "main" @@ -317,6 +330,7 @@ pub const main = fn () int { ``` Compile and run: + ```bash $ luma hello.lx [========================================] 100% - Completed (15ms) @@ -326,9 +340,10 @@ $ ./output Hello, World! ``` -### 3D Graphics (Real Example) +#### 3D Graphics (Real Example) See [tests/3d_spinning_cube.lx](tests/3d_spinning_cube.lx) for a complete 3D graphics application that: + - Renders rotating 3D cubes - Uses sine/cosine lookup tables for performance - Manages memory safely with `defer` @@ -336,12 +351,13 @@ See [tests/3d_spinning_cube.lx](tests/3d_spinning_cube.lx) for a complete 3D gra --- -## Join Us +### Join Us Interested in contributing to Luma? We'd love to have you! + - Check out our [GitHub repository](https://github.com/TheDevConnor/luma) - Join our [Discord community](https://bit.ly/lux-discord) -- Look at the doxygen-generated docs for architecture details [here](https://thedevconnor.github.io/Luma/) +- Look at the [doxygen-generated](https://thedevconnor.github.io/Luma/) docs for architecture details - If you would like to contribute, please read our [contribution guidelines](CONTRIBUTING.md). --- diff --git a/docs/mainpage.dox b/docs/mainpage.dox index fd0e129b..8bf75ba7 100644 --- a/docs/mainpage.dox +++ b/docs/mainpage.dox @@ -1,18 +1,18 @@ /** - * @mainpage Lux + * @mainpage Luma * - * @image html assets/lux.png width=120 + * @image html assets/luma.png width=120 * * @section tagline A low-level compiled alternative to C, C++, and more! * * @section intro Introduction - * Lux is a modern systems programming language designed to provide the performance + * Luma is a modern systems programming language designed to provide the performance * and control of low-level languages while maintaining developer productivity and * code clarity. Built from the ground up to address common pain points in systems programming. * * @section why Why? * Modern systems programming often involves a trade-off between performance, - * safety, and developer experience. Lux aims to bridge this gap by providing: + * safety, and developer experience. Luma aims to bridge this gap by providing: * - **Direct hardware access** without sacrificing code readability * - **Predictable performance** characteristics for systems-critical applications * - **Developer-friendly tooling** that doesn't compromise on compile speed @@ -27,7 +27,7 @@ * * @section status Project Status * **Current Phase:** Early Development - * Lux is currently in active development. Core language features are being implemented + * Luma is currently in active development. Core language features are being implemented * and the compiler architecture is being established. * * **What's Working:** @@ -49,7 +49,7 @@ * rankdir=LR; * node [shape=box, style=rounded, fontsize=12, fontname="Helvetica"]; * - * SourceCode [label="Lux Source Code (.lx)"]; + * SourceCode [label="Luma Source Code (.lx)"]; * Lexer [label="Lexer"]; * Parser [label="Pratt Parser"]; * TypeChecker [label="Type Checker"]; @@ -65,9 +65,9 @@ * *(usage instructions coming soon)* * * @section join_us Join Us - * Interested in contributing to Lux? We'd love to have you! + * Interested in contributing to Luma? We'd love to have you! * *(links coming soon)* * * --- - * **Built with ❤️ by the Lux community** + * **Built with ❤️ by the Luma community** */ diff --git a/ideas.md b/ideas.md index edda7499..40b2ca02 100644 --- a/ideas.md +++ b/ideas.md @@ -1,27 +1,29 @@ -## Fixing C: - - context free grammar - - no preprocessor - - strong typing - - no declaration order - - defined fixed sized primitives - - replace unsigned with natural that can overflow - - no integral promotion - - checked integer arithmetic - - bit array primitive, don't conflate bit operations with integers - - texts literals not null terminated - - remove varargs - - named function parameters - - defined expression evaluation order - - remove comma operator - - product type with undefined layout - - object sizes can be 0 - - remove pointer arithmetic - - arrays have value semantics, remove array implicit conversion to pointer - - modules, including modulemap - - (probably many more, maybe starting with C not a great idea) +# Fixing C + +- context free grammar +- no preprocessor +- strong typing +- no declaration order +- defined fixed sized primitives +- replace unsigned with natural that can overflow +- no integral promotion +- checked integer arithmetic +- bit array primitive, don't conflate bit operations with integers +- texts literals not null terminated +- remove varargs +- named function parameters +- defined expression evaluation order +- remove comma operator +- product type with undefined layout +- object sizes can be 0 +- remove pointer arithmetic +- arrays have value semantics, remove array implicit conversion to pointer +- modules, including modulemap +- (probably many more, maybe starting with C not a great idea) ## NOTE: for runtime constants on switch cases -``` + +```txt LLVM IRError: Case values must be compile-time constants Error: Case value must be a compile-time constant Basic Block in function 'main' does not have terminator! @@ -30,7 +32,8 @@ LLVM ERROR: Broken module found, compilation aborted! ``` ## Linked List Ideas -```lux + +```luma ;; Syntax will change on somethins const Link = struct { tag: int, @@ -65,7 +68,7 @@ const link_list_length = fn (list: *Link) int { }; ``` -# C Interoperability in Luma +## C Interoperability in Luma ## Overview @@ -109,7 +112,9 @@ pub const main = fn () int { ``` ## impl and its unique features -# simple example + +## simple example + impl [func list...] -> [struct list...] { if (1 > 0) { define a function one way @@ -117,39 +122,66 @@ impl [func list...] -> [struct list...] { define the same function another way } } -# The goals of the impl is to implement functions for structs. -# It should have the ability to conditionally make functions. -# The functions are `injected` into the struct and can reference -# `self` which is a pointer to the struct AstNode that should already be there. -# There should be two types of functions for this instance. Runtime ready, and compile time optional. -# with a tag of #runtime, the function will be compiled and optionally ran during runtime. -# two instances of the same function can only run one at a time, and must be derived from an expression. -# a #compile tag from a function within a conditional will be optionally compiled, and so only one available at runtime. -# Why the two? One use case for @run_time is to allow dynamic function assignment. Lets say you must work with an api. -# This api does not respond with the same data, same type of data and so on. This means you can write multiple capture() functions. -# Yes this is function overloading, but conditionally, and can be programmed for the potential context the appliction will be in. -# For @compile_time, it optionally compiles one of the implementations of the function. Say you need portability, you can use the same -# source code and target specific architectures. This can be thought of #IF_WINDOWS bullshit from C, you can conditionaly compile -# one function or another, but in a nice and effecient way. + +## The goals of the impl is to implement functions for structs + +## It should have the ability to conditionally make functions + +## The functions are `injected` into the struct and can reference + +## `self` which is a pointer to the struct AstNode that should already be there + +## There should be two types of functions for this instance. Runtime ready, and compile time optional + +## with a tag of #runtime, the function will be compiled and optionally ran during runtime + +## two instances of the same function can only run one at a time, and must be derived from an expression + +## a #compile tag from a function within a conditional will be optionally compiled, and so only one available at runtime + +## Why the two? One use case for @run_time is to allow dynamic function assignment. Lets say you must work with an api + +## This api does not respond with the same data, same type of data and so on. This means you can write multiple capture() functions + +## Yes this is function overloading, but conditionally, and can be programmed for the potential context the appliction will be in + +## For @compile_time, it optionally compiles one of the implementations of the function. Say you need portability, you can use the same + +## source code and target specific architectures. This can be thought of #IF_WINDOWS bullshit from C, you can conditionaly compile + +## one function or another, but in a nice and effecient way ## the ? and None type + someType: ?; # is a None, or a real type. -# Thats what it does. Gives a way to init without a type. Can also be used to identify things. if (someType? == None) {return "Nothing found";} -# It is our solution to NULL, but it provides a more meaning. Because it can also be a value if (someType?) {return "value found";} -# This is very straigh forward in its concept. someType? returns the value inside, or it returns the None type. + +## Thats what it does. Gives a way to init without a type. Can also be used to identify things. if (someType? == None) {return "Nothing found";} + +## It is our solution to NULL, but it provides a more meaning. Because it can also be a value if (someType?) {return "value found";} + +## This is very straigh forward in its concept. someType? returns the value inside, or it returns the None type ## the set type -# A set is a fixed sized array of types -# a, b, c : (int, float, char); -# const func1 = fn () (int, float, int) {} -# The same thing. -# a, b, c : () = func1; -# changes the the position for the returning set. -# a, b, c : (float, int, int) = func1; -# The () is here to be explicit that we are expecting a set from func1. - -## Luma Post-Processing and Build System (LPBS). -# LPBS is made in Luma and uses a subset (vars, funcs, if (expr)). + +## A set is a fixed sized array of types + +## a, b, c : (int, float, char) + +## const func1 = fn () (int, float, int) {} + +## The same thing + +## a, b, c : () = func1 + +## changes the the position for the returning set + +## a, b, c : (float, int, int) = func1 + +## The () is here to be explicit that we are expecting a set from func1 + +## Luma Post-Processing and Build System (LPBS) + +## LPBS is made in Luma and uses a subset (vars, funcs, if (expr)) // -V2 : verbose level 2 for strictness? // -OB : object files @@ -195,25 +227,32 @@ clean_all -> (where) { output("Removed all artefacts\n"); } -# compile: and clean: are labels, there are the external commands a user can run (lpbs compile, lpbs clean). -# Lets break it down. Post-Processing is about understanding end context from the src code and a solution. -# The LPB System should generate bindings for the end result. -# It should manage ffi for C and providing that compatability. -# It should provide a way to create, manage, and work with shared libraries or static libraries. -# Then it should build the program, it should read in a simp +## compile: and clean: are labels, there are the external commands a user can run (lpbs compile, lpbs clean) + +## Lets break it down. Post-Processing is about understanding end context from the src code and a solution + +## The LPB System should generate bindings for the end result + +## It should manage ffi for C and providing that compatability + +## It should provide a way to create, manage, and work with shared libraries or static libraries + +## Then it should build the program, it should read in a simp ### Manual Binding Generation + ```bash -# Generate bindings from C header +## Generate bindings from C header ./luma bindgen stdio.h -o std/stdio.lx -# Build with explicit linking +## Build with explicit linking ./luma build main.lx -l std/stdio.lx -name main ``` ### Automatic Header Detection + ```bash -# Build system detects and handles C dependencies +## Build system detects and handles C dependencies ./luma build main.lx -l std/stdio.lx -link-c stdio -name main ``` @@ -236,17 +275,17 @@ pub const main = fn () int { ## Comprehensive Standard Library Generation ```bash -# Generate all standard C library bindings at once +## Generate all standard C library bindings at once ./luma bindgen --std-headers -o std/ -# This creates: -# std/stdio.lx -# std/stdlib.lx -# std/math.lx -# std/string.lx -# etc. +## This creates: +## std/stdio.lx +## std/stdlib.lx +## std/math.lx +## std/string.lx +## etc. -# Build with multiple C libraries +## Build with multiple C libraries ./luma build main.lx -l std/stdio.lx -l std/math.lx -name main ``` @@ -267,26 +306,32 @@ extern "C" { ``` Build system automatically detects linking requirements: + ```bash -# Build system sees @link_lib "c" and automatically adds -lc +## Build system sees @link_lib "c" and automatically adds -lc ./luma build main.lx -l std/stdio.lx -name main ``` ## Key Benefits ### 1. **Module System Consistency** + C bindings are treated as regular Luma modules, maintaining language design coherence. ### 2. **Explicit Dependency Management** + Developers maintain full control over what gets linked and in what order, respecting the build system's link order requirements. ### 3. **Namespace Protection** + The `@use "stdio" as io` pattern prevents namespace pollution while clearly indicating C library usage. ### 4. **Tooling Integration** + Automatic binding generation creates proper Luma modules that integrate seamlessly with existing tools. ### 5. **Build System Compatibility** + Works within the existing build system architecture without requiring fundamental changes. ## Implementation Strategy @@ -298,5 +343,6 @@ Works within the existing build system architecture without requiring fundamenta This approach provides a foundation for C interoperability that feels natural to Luma developers while maintaining the language's design principles. -## Look into adding in Multithreading +## Look into adding in Multithreading + ## Add in multiple return types. ``const createStack = fn (stackCeiling: int) <*Stack, *void>`` diff --git a/releases/v0-1-0.md b/releases/v0-1-0.md index 5e425b1b..ce0021ce 100644 --- a/releases/v0-1-0.md +++ b/releases/v0-1-0.md @@ -18,7 +18,7 @@ Luma's static analyzer now validates heap operations at compile time: - Reports exact source locations for memory safety issues **Example:** -```lux +```luma let p = alloc(32); free(p); use(p); // ❌ use-after-free (caught at compile time) @@ -28,7 +28,7 @@ use(p); // ❌ use-after-free (caught at compile time) Ownership and lifetime tracking now correctly handle pointer aliasing: -```lux +```luma let c: *char = cast<*char>(alloc(6 * sizeof)); let b: *char = c; defer { free(b); } @@ -50,7 +50,7 @@ Added two new annotations to help the analyzer understand memory semantics: **Example:** -```lux +```luma #returns_ownership pub const make_buffer = fn(size: int) *char { return alloc(size); diff --git a/src/c_libs/error/error.c b/src/c_libs/error/error.c index 9b34b376..fefd6270 100644 --- a/src/c_libs/error/error.c +++ b/src/c_libs/error/error.c @@ -210,6 +210,7 @@ static void print_indicator(int col, int length, int line, const char *line_text, const char *token_text, int token_length, int max_width, const char *label) { + (void)line; print_gutter(max_width); // Calculate actual column position diff --git a/src/helper/help.c b/src/helper/help.c index 3a731c50..7e9836d6 100644 --- a/src/helper/help.c +++ b/src/helper/help.c @@ -33,7 +33,7 @@ */ bool check_argc(int argc, int expected) { if (argc < expected) { - fprintf(stderr, "Usage: %s \n", "lux"); + fprintf(stderr, "Usage: %s \n", "luma"); return false; } return true; @@ -118,7 +118,7 @@ int print_help() { * @return Always returns 0. */ int print_version() { - printf("Lux Compiler v1.0\n"); + printf("Luma Compiler v1.0\n"); return 0; } @@ -128,7 +128,7 @@ int print_version() { * @return Always returns 0. */ int print_license() { - printf("Lux Compiler is licensed under the MIT License.\n"); + printf("Luma Compiler is licensed under the MIT License.\n"); return 0; } diff --git a/src/helper/run.c b/src/helper/run.c index 686e899e..be314c90 100644 --- a/src/helper/run.c +++ b/src/helper/run.c @@ -12,17 +12,16 @@ #include // Helper function to create directory if it doesn't exist -bool create_directory(const char *path) { +// NOTE Replaced with macro #ifdef _WIN32 - return mkdir(path) == 0 || errno == EEXIST; + #define create_directory(path) (mkdir((path)) == 0 || errno == EEXIST) #else - return mkdir(path, 0755) == 0 || errno == EEXIST; + #define create_directory(path) (mkdir((path), 0755) == 0 || errno == EEXIST) #endif -} void handle_segfault(int sig) { (void)sig; - fprintf(stderr, "\nSegmentation fault caught during LLVM operations!\n"); + fprintf(stderr, "\nSegmentation fault!\n"); fprintf(stderr, "This likely indicates a problem in LLVM IR generation.\n"); exit(1); } @@ -95,6 +94,7 @@ bool generate_llvm_code_modules(AstNode *root, BuildConfig config, signal(SIGILL, handle_illegal_instruction); bool success = generate_program_modules(ctx, root, output_dir); + if (!success) { fprintf(stderr, "Failed to generate LLVM modules\n"); cleanup_codegen_context(ctx); @@ -347,7 +347,10 @@ bool run_build(BuildConfig config, ArenaAllocator *allocator) { if (tc) { // Stage 6: LLVM IR print_progress_with_time(++step, total_stages, "LLVM IR", &timer); - + if (!combined_program || combined_program->type != AST_PROGRAM) { + fprintf(stderr, "ERROR: Invalid program node before codegen\n"); + goto cleanup; + } success = generate_llvm_code_modules(combined_program, config, allocator, &step, &timer); } diff --git a/src/llvm/arrays.c b/src/llvm/arrays.c index 32353559..e15cd32c 100644 --- a/src/llvm/arrays.c +++ b/src/llvm/arrays.c @@ -51,6 +51,8 @@ LLVMValueRef convert_value_to_type(CodeGenContext *ctx, LLVMValueRef value, bool check_array_bounds_runtime(CodeGenContext *ctx, LLVMValueRef array_ptr, LLVMTypeRef array_type, LLVMValueRef index, const char *var_name) { + (void)ctx; + (void)array_ptr; if (LLVMGetTypeKind(array_type) != LLVMArrayTypeKind) { return true; // Can't check bounds for non-arrays } diff --git a/src/llvm/expr.c b/src/llvm/expr.c index ca189074..224f71fd 100644 --- a/src/llvm/expr.c +++ b/src/llvm/expr.c @@ -69,10 +69,26 @@ LLVMValueRef range_length(CodeGenContext *ctx, LLVMValueRef range_struct) { } LLVMValueRef codegen_expr_literal(CodeGenContext *ctx, AstNode *node) { + if (!ctx) { + fprintf(stderr, "FATAL: ctx is NULL in codegen_expr_literal!\n"); + abort(); + } + if (!ctx->context) { + fprintf(stderr, "FATAL: ctx->context is NULL in codegen_expr_literal!\n"); + fprintf(stderr, "LLVM context was not initialized properly!\n"); + abort(); + } + if (!ctx->builder) { + fprintf(stderr, "FATAL: ctx->builder is NULL in codegen_expr_literal!\n"); + fprintf(stderr, "LLVM builder was not initialized properly!\n"); + abort(); + } + switch (node->expr.literal.lit_type) { case LITERAL_INT: return LLVMConstInt(LLVMInt64TypeInContext(ctx->context), node->expr.literal.value.int_val, false); + case LITERAL_FLOAT: return LLVMConstReal(LLVMDoubleTypeInContext(ctx->context), node->expr.literal.value.float_val); @@ -80,18 +96,20 @@ LLVMValueRef codegen_expr_literal(CodeGenContext *ctx, AstNode *node) { case LITERAL_BOOL: return LLVMConstInt(LLVMInt1TypeInContext(ctx->context), node->expr.literal.value.bool_val ? 1 : 0, false); + case LITERAL_CHAR: return LLVMConstInt(LLVMInt8TypeInContext(ctx->context), (unsigned char)node->expr.literal.value.char_val, false); + case LITERAL_STRING: { char *processed_str = process_escape_sequences(node->expr.literal.value.string_val); - + // String literals must be created in the current module LLVMModuleRef current_llvm_module = ctx->current_module ? ctx->current_module->module : ctx->module; - + // Create the global string in the current module LLVMValueRef global_str = LLVMAddGlobal(current_llvm_module, @@ -127,7 +145,9 @@ LLVMValueRef codegen_expr_literal(CodeGenContext *ctx, AstNode *node) { case LITERAL_NULL: return LLVMConstNull( LLVMPointerType(LLVMInt8TypeInContext(ctx->context), 0)); + default: + fprintf(stderr, "ERROR: Unknown literal type: %d\n", node->expr.literal.lit_type); return NULL; } } diff --git a/src/llvm/llvm.c b/src/llvm/llvm.c index ded1f548..4ed486bc 100644 --- a/src/llvm/llvm.c +++ b/src/llvm/llvm.c @@ -232,6 +232,13 @@ CodeGenContext *init_codegen_context(ArenaAllocator *arena) { ctx->loop_break_block = NULL; ctx->struct_types = NULL; ctx->arena = arena; + + // ADD THIS LINE: + ctx->module = NULL; // Initialize legacy module field + + // OR initialize deferred statements if they exist: + ctx->deferred_statements = NULL; + ctx->deferred_count = 0; return ctx; } diff --git a/src/llvm/lookup.c b/src/llvm/lookup.c index f2b45cd6..09e3a9d1 100644 --- a/src/llvm/lookup.c +++ b/src/llvm/lookup.c @@ -2,6 +2,8 @@ LLVMValueRef codegen_expr(CodeGenContext *ctx, AstNode *node) { if (!node || node->category != Node_Category_EXPR) { + fprintf(stderr, "ERROR: codegen_expr - invalid node (node=%p, category=%d)\n", + (void*)node, node ? (signed int)node->category : -1); return NULL; } @@ -43,7 +45,6 @@ LLVMValueRef codegen_expr(CodeGenContext *ctx, AstNode *node) { case AST_EXPR_ADDR: return codegen_expr_addr(ctx, node); case AST_EXPR_MEMBER: - // Enhanced member access that handles both module.symbol and struct.field return codegen_expr_member_access_enhanced(ctx, node); case AST_EXPR_STRUCT: return codegen_expr_struct_literal(ctx, node); diff --git a/src/llvm/module_handles.c b/src/llvm/module_handles.c index a5687010..46a31830 100644 --- a/src/llvm/module_handles.c +++ b/src/llvm/module_handles.c @@ -664,7 +664,6 @@ void print_module_info(CodeGenContext *ctx) { // Also add this debug function to help diagnose linking issues: void debug_object_files(const char *output_dir) { printf("\n=== OBJECT FILE DEBUG INFO ===\n"); - char command[512]; snprintf(command, sizeof(command), "ls -la %s/*.o", output_dir); printf("Object files in %s:\n", output_dir); diff --git a/src/llvm/stmt.c b/src/llvm/stmt.c index 8048b388..607edbf5 100644 --- a/src/llvm/stmt.c +++ b/src/llvm/stmt.c @@ -391,33 +391,42 @@ LLVMValueRef codegen_stmt_return(CodeGenContext *ctx, AstNode *node) { } LLVMValueRef codegen_stmt_block(CodeGenContext *ctx, AstNode *node) { - // Save the current defer context - DeferredStatement *saved_defers = ctx->deferred_statements; - size_t saved_count = ctx->deferred_count; - - // Create new defer scope for this block - ctx->deferred_statements = NULL; - ctx->deferred_count = 0; - - // Process all statements in the block - for (size_t i = 0; i < node->stmt.block.stmt_count; i++) { - // Stop processing if we hit a terminator - if (LLVMGetBasicBlockTerminator(LLVMGetInsertBlock(ctx->builder))) { - break; + // Save the current defer context + DeferredStatement *saved_defers = ctx->deferred_statements; + size_t saved_count = ctx->deferred_count; + + // Create new defer scope for this block + ctx->deferred_statements = NULL; + ctx->deferred_count = 0; + + // Process all statements in the block + for (size_t i = 0; i < node->stmt.block.stmt_count; i++) { + AstNode *stmt = node->stmt.block.statements[i]; + + // ADD THESE CHECKS: + if (!stmt) { + fprintf(stderr, "ERROR: Statement %zu is NULL!\n", i); + continue; + } + + // Stop processing if we hit a terminator + if (LLVMGetBasicBlockTerminator(LLVMGetInsertBlock(ctx->builder))) { + break; + } + + codegen_stmt(ctx, stmt); } - codegen_stmt(ctx, node->stmt.block.statements[i]); - } - // Execute any deferred statements from this block scope (in reverse order) - if (ctx->deferred_statements) { - execute_deferred_statements_inline(ctx, ctx->deferred_statements); - } + // Execute any deferred statements from this block scope (in reverse order) + if (ctx->deferred_statements) { + execute_deferred_statements_inline(ctx, ctx->deferred_statements); + } - // Restore the previous defer context - ctx->deferred_statements = saved_defers; - ctx->deferred_count = saved_count; + // Restore the previous defer context + ctx->deferred_statements = saved_defers; + ctx->deferred_count = saved_count; - return NULL; + return NULL; } LLVMValueRef codegen_stmt_if(CodeGenContext *ctx, AstNode *node) { diff --git a/src/lsp/formatter/expr.c b/src/lsp/formatter/expr.c index e8a11993..2c2c8bbb 100644 --- a/src/lsp/formatter/expr.c +++ b/src/lsp/formatter/expr.c @@ -102,6 +102,11 @@ void format_unary_expression(FormatterContext *ctx, Expr *expr) { case UNOP_DEREF: write_string(ctx, "*"); break; + case UNOP_POST_INC: + case UNOP_POST_DEC: + // UNIMPLEMENTED!! + fprintf(stderr, "Postfix unary operators not implemented yet\n"); + break; case UNOP_ADDR: write_string(ctx, "&"); break; @@ -128,7 +133,7 @@ void format_function_call(FormatterContext *ctx, Expr *expr) { write_string(ctx, "("); // Format arguments - for (int i = 0; i < expr->expr.call.arg_count; i++) { + for (size_t i = 0; i < expr->expr.call.arg_count; i++) { if (i > 0) { write_string(ctx, ","); if (ctx->config.space_after_comma) { @@ -143,6 +148,11 @@ void format_function_call(FormatterContext *ctx, Expr *expr) { void format_literal_expression(FormatterContext *ctx, Expr *expr) { switch (expr->expr.literal.lit_type) { + case LITERAL_IDENT: + case LITERAL_DOUBLE: + case LITERAL_NULL: + fprintf(stderr, "Literal type not implemented in formatter yet check expr.c\n"); + break; case LITERAL_INT: { char buffer[64]; snprintf(buffer, sizeof(buffer), "%lld", expr->expr.literal.value.int_val); diff --git a/src/lsp/formatter/stmt.c b/src/lsp/formatter/stmt.c index b37ed504..924893d7 100644 --- a/src/lsp/formatter/stmt.c +++ b/src/lsp/formatter/stmt.c @@ -65,7 +65,7 @@ void format_function_definition(FormatterContext *ctx, Stmt *stmt) { // Format parameters write_string(ctx, "("); if (stmt->stmt.func_decl.param_count > 0) { - for (int i = 0; i < stmt->stmt.func_decl.param_count; i++) { + for (size_t i = 0; i < stmt->stmt.func_decl.param_count; i++) { if (i > 0) { write_string(ctx, ","); if (ctx->config.space_after_comma) { @@ -159,7 +159,7 @@ void format_struct_definition(FormatterContext *ctx, Stmt *stmt) { increase_indent(ctx); } - for (int i = 0; i < stmt->stmt.struct_decl.public_count; i++) { + for (size_t i = 0; i < stmt->stmt.struct_decl.public_count; i++) { format_stmt(ctx, stmt->stmt.struct_decl.public_members[i]); } @@ -169,7 +169,7 @@ void format_struct_definition(FormatterContext *ctx, Stmt *stmt) { increase_indent(ctx); } - for (int i = 0; i < stmt->stmt.struct_decl.private_count; i++) { + for (size_t i = 0; i < stmt->stmt.struct_decl.private_count; i++) { format_stmt(ctx, stmt->stmt.struct_decl.private_members[i]); } @@ -188,7 +188,7 @@ void format_enum_definition(FormatterContext *ctx, Stmt *stmt) { increase_indent(ctx); - for (int i = 0; i < stmt->stmt.enum_decl.member_count; i++) { + for (size_t i = 0; i < stmt->stmt.enum_decl.member_count; i++) { write_string(ctx, stmt->stmt.enum_decl.members[i]); if (i < stmt->stmt.enum_decl.member_count - 1) { write_string(ctx, ","); diff --git a/src/lsp/language-support/client/src/extension.ts b/src/lsp/language-support/client/src/extension.ts index d0964b6a..4d266e1f 100644 --- a/src/lsp/language-support/client/src/extension.ts +++ b/src/lsp/language-support/client/src/extension.ts @@ -14,7 +14,8 @@ export function activate(context: ExtensionContext) { // Otherwise the run options are used const serverOptions: ServerOptions = { //? the name of the project is "luma" in the Makefile so this will be the name of exe for users - command: "/home/thedevconnor/Projects/lux/luma", + // command: "luma", + command: "/home/sovietpancakes/Desktop/Code/luma/luma", transport: TransportKind.stdio, args: ["-lsp"] }; diff --git a/src/lsp/language-support/package.json b/src/lsp/language-support/package.json index 38c00940..517d3c1c 100644 --- a/src/lsp/language-support/package.json +++ b/src/lsp/language-support/package.json @@ -1,7 +1,7 @@ { - "name": "language-support", - "displayName": "Lux Language Support", - "description": "Syntax highlighting and language support for Lux programming language", + "name": "luma-language-support", + "displayName": "Luma Language Support", + "description": "Syntax highlighting and language support for Luma programming language", "version": "0.1.0", "publisher": "TheDevConnor", "engines": { @@ -13,9 +13,9 @@ "contributes": { "languages": [ { - "id": "lux", + "id": "luma", "aliases": [ - "Lux", + "luma", "lux" ], "extensions": [ @@ -26,21 +26,21 @@ ], "grammars": [ { - "language": "lux", - "scopeName": "source.lux", - "path": "./syntaxes/lux.tmLanguage.json" + "language": "luma", + "scopeName": "source.luma", + "path": "./syntaxes/luma.tmLanguage.json" } ], "themes": [ { - "label": "Lux Tokyo Night", + "label": "Luma Tokyo Night", "uiTheme": "vs-dark", - "path": "./themes/lux-tokyo-night.json" + "path": "./themes/luma-tokyo-night.json" }, { - "label": "Lux Horizon Reimagined", + "label": "Luma Horizon Reimagined", "uiTheme": "vs-dark", - "path": "./themes/lux-horizon-reimagined.json" + "path": "./themes/luma-horizon-reimagined.json" } ] }, diff --git a/src/lsp/language-support/syntaxes/lux.tmLanguage.json b/src/lsp/language-support/syntaxes/luma.tmLanguage.json similarity index 67% rename from src/lsp/language-support/syntaxes/lux.tmLanguage.json rename to src/lsp/language-support/syntaxes/luma.tmLanguage.json index c53b58e2..a4d3b7c1 100644 --- a/src/lsp/language-support/syntaxes/lux.tmLanguage.json +++ b/src/lsp/language-support/syntaxes/luma.tmLanguage.json @@ -1,7 +1,7 @@ { "$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json", "name": "Luma", - "scopeName": "source.lux", + "scopeName": "source.luma", "patterns": [ { "include": "#comments" @@ -38,12 +38,12 @@ "comments": { "patterns": [ { - "name": "comment.line.double-colon.lux", + "name": "comment.line.double-colon.luma", "begin": "//", "end": "$" }, { - "name": "comment.block.lux", + "name": "comment.block.luma", "begin": "/\\*", "end": "\\*/", "patterns": [ @@ -57,7 +57,7 @@ "attributes": { "patterns": [ { - "name": "storage.modifier.attribute.lux", + "name": "storage.modifier.attribute.luma", "match": "#(returns_ownership|takes_ownership)\\b" } ] @@ -65,23 +65,23 @@ "preprocessor": { "patterns": [ { - "name": "meta.preprocessor.lux", + "name": "meta.preprocessor.luma", "match": "(@)(module|use)\\s+(\"[^\"]*\")(\\s+as\\s+([a-zA-Z_][a-zA-Z0-9_]*))?", "captures": { "1": { - "name": "punctuation.definition.directive.lux" + "name": "punctuation.definition.directive.luma" }, "2": { - "name": "keyword.control.directive.lux" + "name": "keyword.control.directive.luma" }, "3": { - "name": "string.quoted.double.lux" + "name": "string.quoted.double.luma" }, "4": { - "name": "keyword.control.as.lux" + "name": "keyword.control.as.luma" }, "5": { - "name": "entity.name.namespace.lux" + "name": "entity.name.namespace.luma" } } } @@ -90,23 +90,23 @@ "strings": { "patterns": [ { - "name": "string.quoted.double.lux", + "name": "string.quoted.double.luma", "begin": "\"", "end": "\"", "patterns": [ { - "name": "constant.character.escape.lux", + "name": "constant.character.escape.luma", "match": "\\\\." } ] }, { - "name": "string.quoted.single.lux", + "name": "string.quoted.single.luma", "begin": "'", "end": "'", "patterns": [ { - "name": "constant.character.escape.lux", + "name": "constant.character.escape.luma", "match": "\\\\." } ] @@ -116,11 +116,11 @@ "numbers": { "patterns": [ { - "name": "constant.numeric.float.lux", + "name": "constant.numeric.float.luma", "match": "\\b\\d+\\.\\d+([eE][+-]?\\d+)?\\b" }, { - "name": "constant.numeric.integer.lux", + "name": "constant.numeric.integer.luma", "match": "\\b\\d+\\b" } ] @@ -128,19 +128,19 @@ "keywords": { "patterns": [ { - "name": "keyword.control.lux", + "name": "keyword.control.luma", "match": "\\b(if|elif|else|loop|break|continue|return|defer)\\b" }, { - "name": "storage.type.lux", + "name": "storage.type.luma", "match": "\\b(const|let)\\b" }, { - "name": "keyword.other.lux", + "name": "keyword.other.luma", "match": "\\b(fn|struct|enum)\\b" }, { - "name": "storage.modifier.lux", + "name": "storage.modifier.luma", "match": "\\b(pub|priv|public|private)\\b" } ] @@ -148,11 +148,11 @@ "types": { "patterns": [ { - "name": "support.type.primitive.lux", + "name": "support.type.primitive.luma", "match": "\\b(int|uint|float|double|bool|str|void|char|short|long|nil)\\b" }, { - "name": "entity.name.type.lux", + "name": "entity.name.type.luma", "match": "\\b[A-Z][a-zA-Z0-9_]*\\b" } ] @@ -160,29 +160,29 @@ "functions": { "patterns": [ { - "name": "meta.function.definition.lux", + "name": "meta.function.definition.luma", "begin": "\\b(const)\\s+([a-zA-Z_][a-zA-Z0-9_]*)\\s*(=)\\s*(fn)\\s*(\\()", "beginCaptures": { "1": { - "name": "storage.type.lux" + "name": "storage.type.luma" }, "2": { - "name": "entity.name.function.lux" + "name": "entity.name.function.luma" }, "3": { - "name": "keyword.operator.assignment.lux" + "name": "keyword.operator.assignment.luma" }, "4": { - "name": "keyword.other.lux" + "name": "keyword.other.luma" }, "5": { - "name": "punctuation.definition.parameters.begin.lux" + "name": "punctuation.definition.parameters.begin.luma" } }, "end": "\\)", "endCaptures": { "0": { - "name": "punctuation.definition.parameters.end.lux" + "name": "punctuation.definition.parameters.end.luma" } }, "patterns": [ @@ -192,11 +192,11 @@ ] }, { - "name": "meta.function.call.lux", + "name": "meta.function.call.luma", "match": "\\b([a-zA-Z_][a-zA-Z0-9_]*)\\s*(?=\\()", "captures": { "1": { - "name": "entity.name.function.lux" + "name": "entity.name.function.luma" } } } @@ -205,7 +205,7 @@ "function-parameters": { "patterns": [ { - "name": "variable.parameter.lux", + "name": "variable.parameter.luma", "match": "\\b[a-zA-Z_][a-zA-Z0-9_]*\\b(?=\\s*:)" }, { @@ -219,35 +219,35 @@ "operators": { "patterns": [ { - "name": "keyword.operator.arithmetic.lux", + "name": "keyword.operator.arithmetic.luma", "match": "\\+\\+|--|\\+|\\-|\\*|/|%" }, { - "name": "keyword.operator.comparison.lux", + "name": "keyword.operator.comparison.luma", "match": "==|!=|<|>|<=|>=" }, { - "name": "keyword.operator.logical.lux", + "name": "keyword.operator.logical.luma", "match": "&&|\\|\\||!" }, { - "name": "keyword.operator.assignment.lux", + "name": "keyword.operator.assignment.luma", "match": "=" }, { - "name": "keyword.operator.bitwise.lux", + "name": "keyword.operator.bitwise.luma", "match": "&|\\||\\^|~|<<|>>" }, { - "name": "keyword.operator.pointer.lux", + "name": "keyword.operator.pointer.luma", "match": "\\*|&" }, { - "name": "keyword.operator.runtime-member.lux", + "name": "keyword.operator.runtime-member.luma", "match": "\\." }, { - "name": "keyword.operator.compiletime-const.lux", + "name": "keyword.operator.compiletime-const.luma", "match": "::" } ] @@ -255,7 +255,7 @@ "identifiers": { "patterns": [ { - "name": "variable.other.lux", + "name": "variable.other.luma", "match": "\\b[a-zA-Z_][a-zA-Z0-9_]*\\b" } ] diff --git a/src/lsp/language-support/themes/lux-horizon-reimagined.json b/src/lsp/language-support/themes/luma-horizon-reimagined.json similarity index 60% rename from src/lsp/language-support/themes/lux-horizon-reimagined.json rename to src/lsp/language-support/themes/luma-horizon-reimagined.json index e0cee61c..913d6eef 100644 --- a/src/lsp/language-support/themes/lux-horizon-reimagined.json +++ b/src/lsp/language-support/themes/luma-horizon-reimagined.json @@ -1,6 +1,6 @@ { "$schema": "vscode://schemas/color-theme", - "name": "Lux Horizon Reimagined", + "name": "Luma Horizon Reimagined", "type": "dark", "colors": { "editor.background": "#1C1E26", @@ -20,85 +20,85 @@ "tokenColors": [ { "scope": [ - "comment.line.double-colon.lux", - "comment.block.lux", + "comment.line.double-colon.luma", + "comment.block.luma", "punctuation.definition.comment" ], "settings": { "foreground": "#6C6F93", "fontStyle": "italic" } }, { "scope": [ - "keyword.control.lux", - "keyword.other.lux", - "storage.type.lux", - "storage.modifier.lux" + "keyword.control.luma", + "keyword.other.luma", + "storage.type.luma", + "storage.modifier.luma" ], "settings": { "foreground": "#FAB795", "fontStyle": "bold" } }, { - "scope": "storage.modifier.attribute.lux", + "scope": "storage.modifier.attribute.luma", "settings": { "foreground": "#25B2BC", "fontStyle": "bold italic" } }, { "scope": [ - "variable.other.lux", - "variable.parameter.lux", + "variable.other.luma", + "variable.parameter.luma", "entity.name.variable" ], "settings": { "foreground": "#E0DEF4" } }, { "scope": [ - "entity.name.function.lux", + "entity.name.function.luma", "support.function" ], "settings": { "foreground": "#25B2BC" } }, { "scope": [ - "string.quoted.double.lux", - "string.quoted.single.lux", - "constant.character.escape.lux" + "string.quoted.double.luma", + "string.quoted.single.luma", + "constant.character.escape.luma" ], "settings": { "foreground": "#B877DB" } }, { "scope": [ - "constant.numeric.integer.lux", - "constant.numeric.float.lux", + "constant.numeric.integer.luma", + "constant.numeric.float.luma", "constant.language" ], "settings": { "foreground": "#F09383" } }, { "scope": [ - "entity.name.type.lux", - "support.type.primitive.lux" + "entity.name.type.luma", + "support.type.primitive.luma" ], "settings": { "foreground": "#F6C177" } }, { "scope": [ - "keyword.operator.arithmetic.lux", - "keyword.operator.comparison.lux", - "keyword.operator.logical.lux", - "keyword.operator.assignment.lux", - "keyword.operator.bitwise.lux", - "keyword.operator.pointer.lux", - "keyword.operator.member.lux" + "keyword.operator.arithmetic.luma", + "keyword.operator.comparison.luma", + "keyword.operator.logical.luma", + "keyword.operator.assignment.luma", + "keyword.operator.bitwise.luma", + "keyword.operator.pointer.luma", + "keyword.operator.member.luma" ], "settings": { "foreground": "#89ddff" } }, { "scope": [ - "meta.preprocessor.lux", - "punctuation.definition.directive.lux", - "keyword.control.directive.lux" + "meta.preprocessor.luma", + "punctuation.definition.directive.luma", + "keyword.control.directive.luma" ], "settings": { "foreground": "#bb9af7" } }, { - "scope": "entity.name.namespace.lux", + "scope": "entity.name.namespace.luma", "settings": { "foreground": "#73daca" } } ] diff --git a/src/lsp/language-support/themes/lux-tokyo-night.json b/src/lsp/language-support/themes/luma-tokyo-night.json similarity index 63% rename from src/lsp/language-support/themes/lux-tokyo-night.json rename to src/lsp/language-support/themes/luma-tokyo-night.json index 8dfd6760..506bd6f8 100644 --- a/src/lsp/language-support/themes/lux-tokyo-night.json +++ b/src/lsp/language-support/themes/luma-tokyo-night.json @@ -1,5 +1,5 @@ { - "name": "Lux Tokyo Night", + "name": "Luma Tokyo Night", "type": "dark", "colors": { "editor.background": "#1a1b26", @@ -12,8 +12,8 @@ { "name": "Comment", "scope": [ - "comment.line.double-slash.lux", - "comment.block.lux" + "comment.line.double-slash.luma", + "comment.block.luma" ], "settings": { "foreground": "#565f89", @@ -23,9 +23,9 @@ { "name": "Preprocessor Directives", "scope": [ - "meta.preprocessor.lux", - "punctuation.definition.directive.lux", - "keyword.control.directive.lux" + "meta.preprocessor.luma", + "punctuation.definition.directive.luma", + "keyword.control.directive.luma" ], "settings": { "foreground": "#bb9af7" @@ -33,7 +33,7 @@ }, { "name": "Function Attributes", - "scope": "storage.modifier.attribute.lux", + "scope": "storage.modifier.attribute.luma", "settings": { "foreground": "#7aa2f7", "fontStyle": "bold italic" @@ -42,9 +42,9 @@ { "name": "Keywords", "scope": [ - "keyword.control.lux", - "storage.type.lux", - "keyword.other.lux" + "keyword.control.luma", + "storage.type.luma", + "keyword.other.luma" ], "settings": { "foreground": "#bb9af7", @@ -53,35 +53,35 @@ }, { "name": "Storage Modifiers", - "scope": "storage.modifier.lux", + "scope": "storage.modifier.luma", "settings": { "foreground": "#f7768e" } }, { "name": "Primitive Types", - "scope": "support.type.primitive.lux", + "scope": "support.type.primitive.luma", "settings": { "foreground": "#2ac3de" } }, { "name": "User-defined Types", - "scope": "entity.name.type.lux", + "scope": "entity.name.type.luma", "settings": { "foreground": "#9ece6a" } }, { "name": "Function Names", - "scope": "entity.name.function.lux", + "scope": "entity.name.function.luma", "settings": { "foreground": "#7aa2f7" } }, { "name": "Function Parameters", - "scope": "variable.parameter.lux", + "scope": "variable.parameter.luma", "settings": { "foreground": "#e0af68" } @@ -89,8 +89,8 @@ { "name": "Strings", "scope": [ - "string.quoted.double.lux", - "string.quoted.single.lux" + "string.quoted.double.luma", + "string.quoted.single.luma" ], "settings": { "foreground": "#9ece6a" @@ -98,7 +98,7 @@ }, { "name": "String Escape Characters", - "scope": "constant.character.escape.lux", + "scope": "constant.character.escape.luma", "settings": { "foreground": "#ff9e64" } @@ -106,8 +106,8 @@ { "name": "Numbers", "scope": [ - "constant.numeric.integer.lux", - "constant.numeric.float.lux" + "constant.numeric.integer.luma", + "constant.numeric.float.luma" ], "settings": { "foreground": "#ff9e64" @@ -116,13 +116,13 @@ { "name": "Operators", "scope": [ - "keyword.operator.arithmetic.lux", - "keyword.operator.comparison.lux", - "keyword.operator.logical.lux", - "keyword.operator.assignment.lux", - "keyword.operator.bitwise.lux", - "keyword.operator.pointer.lux", - "keyword.operator.member.lux" + "keyword.operator.arithmetic.luma", + "keyword.operator.comparison.luma", + "keyword.operator.logical.luma", + "keyword.operator.assignment.luma", + "keyword.operator.bitwise.luma", + "keyword.operator.pointer.luma", + "keyword.operator.member.luma" ], "settings": { "foreground": "#89ddff" @@ -130,14 +130,14 @@ }, { "name": "Variables", - "scope": "variable.other.lux", + "scope": "variable.other.luma", "settings": { "foreground": "#a9b1d6" } }, { "name": "Namespaces", - "scope": "entity.name.namespace.lux", + "scope": "entity.name.namespace.luma", "settings": { "foreground": "#73daca" } @@ -145,8 +145,8 @@ { "name": "Punctuation", "scope": [ - "punctuation.definition.parameters.begin.lux", - "punctuation.definition.parameters.end.lux" + "punctuation.definition.parameters.begin.luma", + "punctuation.definition.parameters.end.luma" ], "settings": { "foreground": "#a9b1d6" diff --git a/src/lsp/lsp_features.c b/src/lsp/lsp_features.c index da4f5468..37439918 100644 --- a/src/lsp/lsp_features.c +++ b/src/lsp/lsp_features.c @@ -43,6 +43,7 @@ LSPLocation *lsp_definition(LSPDocument *doc, LSPPosition position, LSPCompletionItem *lsp_completion(LSPDocument *doc, LSPPosition position, size_t *completion_count, ArenaAllocator *arena) { + (void)position; if (!doc || !completion_count) { return NULL; } diff --git a/src/main.c b/src/main.c index 24467261..8a3cc924 100644 --- a/src/main.c +++ b/src/main.c @@ -1,6 +1,6 @@ /** * @file main.c - * @brief Entry point for the Lux compiler/interpreter build process. + * @brief Entry point for the Luma compiler/interpreter build process. * * This program parses command-line arguments, sets up a memory arena, * and runs the build process on a provided source file. @@ -13,12 +13,12 @@ * * ## Usage * ```bash - * lux build + * luma build * ``` * * Example: * ```bash - * lux build hello.lx + * luma build hello.lx * ``` */ diff --git a/src/typechecker/array.c b/src/typechecker/array.c index c0064932..4879a34c 100644 --- a/src/typechecker/array.c +++ b/src/typechecker/array.c @@ -66,6 +66,7 @@ bool validate_array_type(AstNode *array_type, Scope *scope, // Enhanced array bounds checking for constant indices bool check_array_bounds(AstNode *array_type, AstNode *index_expr, ArenaAllocator *arena) { + (void)arena; if (!array_type || array_type->type != AST_TYPE_ARRAY || !index_expr) { return true; // Can't check - assume valid } diff --git a/src/typechecker/static_mem_tracker.c b/src/typechecker/static_mem_tracker.c index e6418adf..bd6a0049 100644 --- a/src/typechecker/static_mem_tracker.c +++ b/src/typechecker/static_mem_tracker.c @@ -15,6 +15,8 @@ void static_memory_track_alloc(StaticMemoryAnalyzer *analyzer, size_t line, size_t column, const char *var_name, const char *function_name, Token *tokens, size_t token_count, const char *file_path) { + (void)tokens; + (void)token_count; if (!var_name || strcmp(var_name, "anonymous") == 0) { return; } @@ -113,6 +115,8 @@ bool static_memory_check_use_after_free(StaticMemoryAnalyzer *analyzer, Token *tokens, int token_count, const char *file_path, const char *function_name) { + (void)tokens; + (void)token_count; if (!var_name) return true; diff --git a/todo.md b/todo.md index fce485dd..81ff61e2 100644 --- a/todo.md +++ b/todo.md @@ -1,9 +1,11 @@ -# Lux Language Compiler TODO +# Luma Language Compiler TODO ## ✅ Implemented (Up to Codegen) + These AST node types are fully implemented in code generation: ### Expressions + - [x] `AST_EXPR_LITERAL` - [x] `AST_EXPR_IDENTIFIER` - [x] `AST_EXPR_BINARY` @@ -22,6 +24,7 @@ These AST node types are fully implemented in code generation: - [x] `AST_EXPR_DEC` ### Statements + - [x] `AST_PROGRAM` (multi-module support) - [x] `AST_PREPROCESSOR_MODULE` - [x] `AST_PREPROCESSOR_USE` @@ -37,6 +40,7 @@ These AST node types are fully implemented in code generation: - [x] `AST_STMT_IMPL` ### Types + - [x] `AST_TYPE_BASIC` - [x] `AST_TYPE_POINTER` - [x] `AST_TYPE_ARRAY` @@ -49,6 +53,7 @@ These AST node types are fully implemented in code generation: ## 🧠 Static Memory Analysis ### ✅ Currently Implemented + - [x] Basic allocation/free tracking by variable name - [x] Memory leak detection (allocated but never freed) - [x] Double-free detection with count tracking @@ -59,6 +64,7 @@ These AST node types are fully implemented in code generation: ### 🔧 Memory Analysis Improvements Needed #### High Priority + - [ ] **Pointer aliasing detection** - [ ] Track when `ptr2 = ptr1` creates aliases - [ ] Warn when analyzer can't track aliased pointers @@ -66,44 +72,50 @@ These AST node types are fully implemented in code generation: - [ ] Allowing structs to point to itself -- name struct {some: *name}; #### Control Flow Analysis + - [ ] **Conditional path tracking** - [ ] Detect leaks in conditional branches (`if/else` without free in all paths) - [ ] Handle early returns and breaks - [ ] Track memory across loop iterations #### Function Call Analysis + - [ ] **Cross-function tracking** - [ ] Track pointers passed to functions as parameters - [ ] Handle functions that free parameters - [ ] Return value allocation tracking - [ ] Support for ownership transfer through function calls - #### Advanced Pointer Operations + - [ ] **Complex pointer arithmetic** - [ ] Handle `ptr + offset` operations - [ ] Track array element allocations - [ ] Detect out-of-bounds access potential #### Memory Operation Extensions + - [ ] **Additional memory functions** - [ ] Track `realloc()` operations - [ ] Handle `calloc()` and `malloc()` variants - [ ] Monitor `memcpy()` for potential use-after-free #### Data Structure Tracking + - [ ] **Struct/array memory management** - [ ] Track allocations within struct members - [ ] Handle nested pointer structures - [ ] Monitor array of pointers #### Use-After-Free Detection + - [ ] **Access after free tracking** - [ ] Detect reads/writes to freed pointers - [ ] Track freed pointer usage across scopes - [ ] Integration with dereference operations #### Scope and Lifetime Analysis + - [ ] **Advanced scope tracking** - [ ] Detect pointers escaping local scope - [ ] Handle static/global pointer lifetimes @@ -114,6 +126,7 @@ These AST node types are fully implemented in code generation: ## 📝 Next Steps ### Parsing + - [ ] Add parsing for templates (`fn[T]`, `struct[T]`) - [ ] Add parsing for type aliases using `type` keyword - [ ] Add parsing for modules and imports refinements @@ -121,10 +134,12 @@ These AST node types are fully implemented in code generation: - [ ] Consider Go/Odin-style loop syntax improvements ### Semantic Analysis + - [ ] Type inference for generics - [ ] Detect unused imports and symbols ### Codegen + - [ ] Implement codegen for `switch` or `match` constructs - [ ] Support more LLVM optimizations - [ ] **Add structs and enums support** in codegen @@ -132,15 +147,18 @@ These AST node types are fully implemented in code generation: - [ ] **Add in memcpy and streq** streq === strcmp ### Lexer & Parser + - [ ] Add tokens and grammar for unions ### Type Checker + - [ ] Implement type checking for structs -- [ ] Implement type checking for unions +- [ ] Implement type checking for unions --- ## 🚀 Future Features Ideas (Maybe) + - [ ] Investigate pattern matching - [ ] Build minimal standard library - [ ] Consider ownership/borrowing system for advanced memory safety