Skip to content

SohamTilekar/GigglyCode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

162 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸŽ‰ GigglyCode πŸŽ‰

[πŸ“– Getting Started] | [πŸ“š Learn] | [πŸ“ Documentation] | [🀝 Contributing]

This is the main source code repository for GigglyCode. It contains the πŸ› οΈ compiler, πŸ“¦ standard library, and πŸ“„ documentation.

❓ Why GigglyCode?

  • πŸŒ‰ Interoperability: Bridges the gap between different πŸ–₯️ programming languages by planning support for inline 🐍 Python and βš™οΈ C code.
  • πŸ“š Educational Tool: Perfect for learning C++ concepts while enabling a 🧡 multi-language approach in a single project.
  • πŸš€ Performance: Optimized for πŸƒβ€β™‚οΈ speed and πŸ’Ύ memory efficiency, suitable for embedded systems, critical services, and integration with other languages.
  • πŸ›‘οΈ Reliability: A robust type system and πŸ”— ownership model ensure 🐞 bug-free memory and thread safety.
  • πŸ’‘ Productivity: Extensive πŸ“– documentation, excellent compiler πŸ›ŽοΈ diagnostics, and modern πŸ”§ tooling like πŸ“¦ package management, auto-formatters, linters, and IDE support.

✨ Features

  • πŸ“¦ Variables: Easy declaration and use.
  • πŸ” Functions: Reusable and maintainable code.
  • πŸ—οΈ Structs: Custom data types for better πŸ—‚οΈ organization.
  • πŸ”€ Generic Structs & Functions: Write reusable code across data types.
  • ⚑ Function Overloading: Define multiple βš™οΈ functions with the same name but different parameters.
  • πŸ†• new Keyword: Dynamic memory allocation made simple.
  • πŸ€– Type Inference: Automatic πŸ•΅οΈβ€β™‚οΈ type detection for variables and expressions.
  • ⚠️ Error Handling: Graceful error management with πŸ§ͺ try-catch blocks.
  • πŸ“š Modules: Organize code into maintainable 🧩 modules.
  • πŸŒ‰ Interoperability: Planned support for inline 🐍 Python and βš™οΈ C code.
  • 🀝 Struct Methods: Define πŸ› οΈ methods that operate on struct instances.
  • πŸ” Control Flow: Flexible loops (for, while) with advanced controls (break, continue) targeting specific loop levels.
  • πŸ“₯ Imports: Effortless inclusion of πŸ›οΈ standard libraries and user-defined 🧩 modules.

πŸ› οΈ Syntax Examples

πŸ—οΈ Structs and Methods

# Define a struct to represent a rectangle
struct Rectangle {
    width: int;  # Width of the rectangle
    height: int;  # Height of the rectangle

    # Method to calculate the area of the rectangle
    def area(self: Rectangle) -> int {
        return self.width * self.height;
    };

    # Method to calculate the perimeter of the rectangle
    def perimeter(self: Rectangle) -> int {
        return 2 * (self.width + self.height);
    };
};

πŸ“¦ Generics

# Define a generic struct for a linked list node
@generic(T: Any)
struct ListNode {
    value: T;  # Generic value
    next: ListNode[T];  # Pointer to the next node

    # Constructor to initialize the node
    def __init__(self: ListNode[T], value: T, next: ListNode[T]) -> void {
        self.value = value;
        self.next = next;
    };
};

# Define a generic linked list
@generic(T: Any)
struct LinkedList {
    head: ListNode[T];  # Head node of the list

    # Constructor to initialize the linked list
    def __init__(self: LinkedList[T]) -> void {};

    # Method to add a new node to the list
    def add(self: LinkedList[T], value: T) -> void {
        newNode: ListNode[T] = new ListNode(value, nullptr);
        if (self.head == nullptr) {
            self.head = newNode;
        } else {
            current: ListNode[T] = self.head;
            while (current.next != nullptr) {
                current = current.next;
            }
            current.next = newNode;
        };
    };
};

⚑ Function Overloading

# Define multiple overloaded functions for subtraction
def subtract(a: int, b: int) -> int {
    return a - b;
};

def subtract(a: float, b: float) -> float {
    return a - b;
};

πŸ” Control Flow

# Switch-case example
val: int = 2;
switch (val) {
    case (1) {
        printf("Value is 1.");
    } case (2) {
        printf("Value is 2.");
    } case (3) {
        printf("Value is 3.");
    } default {
        printf("Value is unknown.");
    }
}

# While loop example
counter: int = 0;
while (counter < 5) {
    printf("Counter: %i", counter);
    counter = counter + 1;
};

πŸ†• Dynamic Memory Allocation

# Dynamic memory allocation for an raw_array
arr: int[] = array(int, 5);
for (i in range(0, 5)) {
    arr[i] = i * 10;
};
for (i in range(0, 5)) {
    printf("Array element %i : %i", i, arr[i]);
};

πŸ“₯ Imports

# Import example with usage
import "modules/math";

struct Calculator {
    def add(self: Calculator, a: int, b: int) -> int {
        return math.add(a, b);  # Use the imported math module
    };

    def subtract(self: Calculator, a: int, b: int) -> int {
        return math.subtract(a, b);  # Use the imported math module
    }
}

calc: Calculator = Calculator();
printf("Addition result: %i", calc.add(10, 5));
printf("Subtraction result: %i", calc.subtract(10, 5));

πŸ—οΈ Complete Program Example

# Main function to demonstrate all features
def main() {
    # Struct and method usage
    rect: Rectangle = Rectangle(10, 20);  # Initialize rectangle with width 10 and height 20
    printf("Rectangle area: %i", rect.area());  # Calculate and print area
    printf("Rectangle perimeter: %i", rect.perimeter());  # Calculate and print perimeter

    # Generic struct usage
    intList: LinkedList[int] = LinkedList(int);  # Linked list with integers
    intList.add(10);
    intList.add(20);
    intList.add(30);
    current: ListNode[int] = intList.head;
    while (current != nullptr) {
        printf("List node value: %i", current.value);
        current = current.next;
    }

    # Function overloading usage
    printf("Subtract integers: %i", subtract(10, 5));  # Calls the int version
    printf("Subtract floats: %f", subtract(10.5, 5.5));  # Calls the float version

    arr: raw_array[int] = [0, 10, 20, 30, 40]; # Allocate an raw_array with elements [[0, 10, 20, 30, 40]]

    # Dynamic memory allocation example
    arr: int = array(int, 5);
    for (i in range(0, 5)) {
        arr[i] = i * 10;
    };
    for (i in range(0, 5)) {
        printf("Array element %i : %i", i, arr[i]);
    }

    # Control flow demonstration
    val: int = 2;
    switch (val) {
        case (1) {
            printf("Value is 1.");
        } case (2) {
            printf("Value is 2.");
        } case (3) {
            printf("Value is 3.");
        } default {
            printf("Value is unknown.");
        }
    }

    # Import and usage of a module
    import "modules/math";
    calc: Calculator = Calculator();
    printf("Addition result: %i", calc.add(10, 5));
    printf("Subtraction result: %i", calc.subtract(10, 5));
}

πŸ›« Getting Started

  1. πŸ§‘β€πŸ’» Clone the Repository

    git clone https://github.com/SohamTilekar/GigglyCode.git
  2. πŸ› οΈ Build the Compiler Before this Make sure that You Have compiled & installed llvm & yaml

    cd GigglyCode
    mkdir build
    cd build
    cmake ../src
    cd ..
    cmake --build ./build --config Release --target all -j 4 -- <!--or--> cmake --build ./build --config Debug --target all -j 4 --
    # The  Cmake will Output the `./build/giggly` which is the main exec of the giggly code
  3. πŸ“œ Write Your First Program Create a .gc file and write your πŸ› οΈ GigglyCode program.

  4. πŸš€ Compile and Run Compile an entire project:

    ./build/giggly ./project_dir/ -O2 -o executable_path
    • πŸ—‚οΈ project_dir: The root πŸ“ containing the src folder where main.gc resides.
    • βš™οΈ -O2: Optimization level (e.g., O1, O2, O3, Ofast).
    • πŸ›€οΈ executable_path: Specifies the path for the compiled executable.

πŸ“ Example Project Structure

πŸ“ project/
    πŸ“‚ src/
        πŸ“„ main.gc
        πŸ“‚ modules/
            πŸ“„ io.gc

πŸ™Œ Contributing

We πŸ’– contributions! Here’s how you can get involved:

  • You know How to do this If you dont that means you are a beginner so do not try to contribute in OpenSource Project untill you have 1 year+ experience.

πŸ“œ License

GigglyCode is distributed under the πŸ“ MIT license. See the LICENSE file for details.

πŸ“§ Contact

Thank you for your πŸŽ‰ interest in GigglyCode! Stay tuned for updates as we continue to πŸš€ improve.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages