[π Getting Started] | [π Learn] | [π Documentation] | [π€ Contributing]
This is the main source code repository for GigglyCode. It contains the π οΈ compiler, π¦ standard library, and π documentation.
- π 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.
- π¦ 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.
- π
newKeyword: 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.
# 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);
};
};# 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;
};
};
};# 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;
};# 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 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]);
};# 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));# 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));
}-
π§βπ» Clone the Repository
git clone https://github.com/SohamTilekar/GigglyCode.git
-
π οΈ 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
-
π Write Your First Program Create a
.gcfile and write your π οΈ GigglyCode program. -
π Compile and Run Compile an entire project:
./build/giggly ./project_dir/ -O2 -o executable_path
- ποΈ
project_dir: The root π containing thesrcfolder wheremain.gcresides. - βοΈ
-O2: Optimization level (e.g.,O1,O2,O3,Ofast). - π€οΈ
executable_path: Specifies the path for the compiled executable.
- ποΈ
π project/
π src/
π main.gc
π modules/
π io.gcWe π 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.
GigglyCode is distributed under the π MIT license. See the LICENSE file for details.
Thank you for your π interest in GigglyCode! Stay tuned for updates as we continue to π improve.