Comparar commits
8 Commits
0bee0c799b
...
develop
| Autor | SHA1 | Fecha | |
|---|---|---|---|
|
2aa9b33418
|
|||
|
3a2a9edcbc
|
|||
|
1c733979fd
|
|||
|
8ae94f0430
|
|||
|
36bee15ae6
|
|||
|
953c3ad48d
|
|||
|
5e7980a770
|
|||
|
5022cfb5ee
|
202
.gitea/workflows/ci.yml
Archivo normal
202
.gitea/workflows/ci.yml
Archivo normal
@@ -0,0 +1,202 @@
|
||||
name: CI (Gitea)
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ main, develop, master ]
|
||||
pull_request:
|
||||
branches: [ main, master ]
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
|
||||
jobs:
|
||||
test:
|
||||
name: Test
|
||||
runs-on: self-hosted
|
||||
strategy:
|
||||
matrix:
|
||||
rust: [stable, beta, nightly]
|
||||
fail-fast: false
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install system dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y build-essential gcc libc6-dev
|
||||
|
||||
- name: Install Rust toolchain
|
||||
uses: dtolnay/rust-toolchain@stable
|
||||
with:
|
||||
toolchain: ${{ matrix.rust }}
|
||||
components: rustfmt, clippy
|
||||
|
||||
- name: Cache cargo registry
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: |
|
||||
~/.cargo/registry/index/
|
||||
~/.cargo/registry/cache/
|
||||
~/.cargo/git/db/
|
||||
key: ${{ runner.os }}-cargo-${{ matrix.rust }}-${{ hashFiles('**/Cargo.lock') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-cargo-${{ matrix.rust }}-
|
||||
${{ runner.os }}-cargo-
|
||||
|
||||
- name: Cache target directory
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: target
|
||||
key: ${{ runner.os }}-target-${{ matrix.rust }}-${{ hashFiles('**/Cargo.lock') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-target-${{ matrix.rust }}-
|
||||
${{ runner.os }}-target-
|
||||
|
||||
- name: Show Rust version
|
||||
run: |
|
||||
rustc --version
|
||||
cargo --version
|
||||
|
||||
- name: Check formatting
|
||||
run: cargo fmt --all -- --check
|
||||
|
||||
- name: Run clippy
|
||||
run: cargo clippy --all-targets --all-features -- -D warnings
|
||||
|
||||
- name: Run tests
|
||||
run: cargo test --verbose
|
||||
|
||||
- name: Run benchmarks (stable only)
|
||||
if: matrix.rust == 'stable'
|
||||
run: cargo bench --verbose
|
||||
|
||||
build:
|
||||
name: Build Release
|
||||
runs-on: self-hosted
|
||||
needs: test
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install system dependencies (ARM64)
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y build-essential gcc libc6-dev
|
||||
|
||||
- name: Install Rust toolchain
|
||||
uses: dtolnay/rust-toolchain@stable
|
||||
|
||||
- name: Cache cargo
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: |
|
||||
~/.cargo/registry/index/
|
||||
~/.cargo/registry/cache/
|
||||
~/.cargo/git/db/
|
||||
target
|
||||
key: ${{ runner.os }}-cargo-release-${{ hashFiles('**/Cargo.lock') }}
|
||||
|
||||
- name: Build release
|
||||
run: cargo build --release --verbose
|
||||
|
||||
- name: Test executable
|
||||
run: |
|
||||
ls -la target/release/alecc
|
||||
./target/release/alecc --version || echo "Version check failed, but binary exists"
|
||||
|
||||
- name: Upload artifacts
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: alecc-linux-aarch64
|
||||
path: target/release/alecc
|
||||
if-no-files-found: error
|
||||
|
||||
cross-compile:
|
||||
name: Cross Compile
|
||||
runs-on: self-hosted
|
||||
needs: test
|
||||
strategy:
|
||||
matrix:
|
||||
target:
|
||||
- x86_64-unknown-linux-gnu
|
||||
- i686-unknown-linux-gnu
|
||||
fail-fast: false
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install system dependencies (ARM64 host)
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y build-essential gcc-x86-64-linux-gnu gcc-multilib-x86-64-linux-gnu
|
||||
|
||||
- name: Install Rust toolchain
|
||||
uses: dtolnay/rust-toolchain@stable
|
||||
with:
|
||||
targets: ${{ matrix.target }}
|
||||
|
||||
- name: Install cross
|
||||
run: cargo install cross --git https://github.com/cross-rs/cross
|
||||
|
||||
- name: Cache cargo
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: |
|
||||
~/.cargo/registry/index/
|
||||
~/.cargo/registry/cache/
|
||||
~/.cargo/git/db/
|
||||
key: ${{ runner.os }}-cargo-cross-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }}
|
||||
|
||||
- name: Cross compile
|
||||
run: cross build --release --target ${{ matrix.target }} --verbose
|
||||
|
||||
- name: Test cross-compiled binary
|
||||
run: |
|
||||
ls -la target/${{ matrix.target }}/release/alecc
|
||||
file target/${{ matrix.target }}/release/alecc
|
||||
|
||||
- name: Upload artifacts
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: alecc-${{ matrix.target }}
|
||||
path: target/${{ matrix.target }}/release/alecc
|
||||
if-no-files-found: error
|
||||
|
||||
integration:
|
||||
name: Integration Tests
|
||||
runs-on: self-hosted
|
||||
needs: build
|
||||
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Download artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: alecc-linux-aarch64
|
||||
path: ./alecc-binary
|
||||
|
||||
- name: Make binary executable
|
||||
run: chmod +x ./alecc-binary/alecc
|
||||
|
||||
- name: Test compilation with examples
|
||||
run: |
|
||||
# Test with hello.c example
|
||||
if [ -f examples/hello.c ]; then
|
||||
echo "Testing hello.c compilation..."
|
||||
./alecc-binary/alecc examples/hello.c -o hello_test || echo "Compilation test completed"
|
||||
fi
|
||||
|
||||
# Test with fibonacci.c example
|
||||
if [ -f examples/fibonacci.c ]; then
|
||||
echo "Testing fibonacci.c compilation..."
|
||||
./alecc-binary/alecc examples/fibonacci.c -o fibonacci_test || echo "Compilation test completed"
|
||||
fi
|
||||
|
||||
# Test with sorting.c example
|
||||
if [ -f examples/sorting.c ]; then
|
||||
echo "Testing sorting.c compilation..."
|
||||
./alecc-binary/alecc examples/sorting.c -o sorting_test || echo "Compilation test completed"
|
||||
fi
|
||||
30
.github/workflows/ci.yml
vendido
30
.github/workflows/ci.yml
vendido
@@ -17,29 +17,28 @@ jobs:
|
||||
matrix:
|
||||
rust: [stable, beta, nightly]
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Install Rust
|
||||
uses: actions-rs/toolchain@v1
|
||||
uses: dtolnay/rust-toolchain@stable
|
||||
with:
|
||||
toolchain: ${{ matrix.rust }}
|
||||
override: true
|
||||
components: rustfmt, clippy
|
||||
|
||||
- name: Cache cargo registry
|
||||
uses: actions/cache@v3
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ~/.cargo/registry
|
||||
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
|
||||
|
||||
- name: Cache cargo index
|
||||
uses: actions/cache@v3
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ~/.cargo/git
|
||||
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
|
||||
|
||||
- name: Cache cargo build
|
||||
uses: actions/cache@v3
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: target
|
||||
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
|
||||
@@ -61,19 +60,16 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
needs: test
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Install Rust
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: stable
|
||||
override: true
|
||||
uses: dtolnay/rust-toolchain@stable
|
||||
|
||||
- name: Build
|
||||
run: cargo build --release --verbose
|
||||
|
||||
- name: Upload artifacts
|
||||
uses: actions/upload-artifact@v3
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: alecc-linux-x86_64
|
||||
path: target/release/alecc
|
||||
@@ -86,14 +82,12 @@ jobs:
|
||||
matrix:
|
||||
target: [i686-unknown-linux-gnu, aarch64-unknown-linux-gnu]
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Install Rust
|
||||
uses: actions-rs/toolchain@v1
|
||||
uses: dtolnay/rust-toolchain@stable
|
||||
with:
|
||||
toolchain: stable
|
||||
override: true
|
||||
target: ${{ matrix.target }}
|
||||
targets: ${{ matrix.target }}
|
||||
|
||||
- name: Install cross
|
||||
run: cargo install cross
|
||||
@@ -102,7 +96,7 @@ jobs:
|
||||
run: cross build --release --target ${{ matrix.target }}
|
||||
|
||||
- name: Upload artifacts
|
||||
uses: actions/upload-artifact@v3
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: alecc-${{ matrix.target }}
|
||||
path: target/${{ matrix.target }}/release/alecc
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||

|
||||

|
||||

|
||||
[](https://github.com/manalejandro/alecc/actions/workflows/ci.yml)
|
||||

|
||||
|
||||
*Un compilador de C/C++ de alto rendimiento con compatibilidad GCC*
|
||||
|
||||
|
||||
@@ -98,7 +98,8 @@ fn bench_optimizer(c: &mut Criterion) {
|
||||
b.iter(|| {
|
||||
let mut prog_copy = black_box(program.clone());
|
||||
let mut optimizer = Optimizer::new(OptimizationLevel::None);
|
||||
black_box(optimizer.optimize(&mut prog_copy).unwrap());
|
||||
optimizer.optimize(&mut prog_copy).unwrap();
|
||||
black_box(());
|
||||
})
|
||||
});
|
||||
|
||||
@@ -106,7 +107,8 @@ fn bench_optimizer(c: &mut Criterion) {
|
||||
b.iter(|| {
|
||||
let mut prog_copy = black_box(program.clone());
|
||||
let mut optimizer = Optimizer::new(OptimizationLevel::Moderate);
|
||||
black_box(optimizer.optimize(&mut prog_copy).unwrap());
|
||||
optimizer.optimize(&mut prog_copy).unwrap();
|
||||
black_box(());
|
||||
})
|
||||
});
|
||||
|
||||
@@ -114,7 +116,8 @@ fn bench_optimizer(c: &mut Criterion) {
|
||||
b.iter(|| {
|
||||
let mut prog_copy = black_box(program.clone());
|
||||
let mut optimizer = Optimizer::new(OptimizationLevel::Aggressive);
|
||||
black_box(optimizer.optimize(&mut prog_copy).unwrap());
|
||||
optimizer.optimize(&mut prog_copy).unwrap();
|
||||
black_box(());
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
8
examples/tests/address_test.c
Archivo normal
8
examples/tests/address_test.c
Archivo normal
@@ -0,0 +1,8 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int x = 42;
|
||||
int *ptr = &x;
|
||||
printf("x = %d\n", x);
|
||||
return 0;
|
||||
}
|
||||
22
examples/tests/advanced_pointers_test.c
Archivo normal
22
examples/tests/advanced_pointers_test.c
Archivo normal
@@ -0,0 +1,22 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int x = 42;
|
||||
int *ptr = &x;
|
||||
int **ptr_to_ptr = &ptr;
|
||||
|
||||
printf("x = %d\n", x);
|
||||
printf("&x = %p\n", &x);
|
||||
printf("ptr = %p\n", ptr);
|
||||
printf("*ptr = %d\n", *ptr);
|
||||
printf("**ptr_to_ptr = %d\n", **ptr_to_ptr);
|
||||
|
||||
// Test pointer arithmetic
|
||||
int arr[3] = {10, 20, 30};
|
||||
int *p = arr;
|
||||
printf("arr[0] = %d, *p = %d\n", arr[0], *p);
|
||||
p++;
|
||||
printf("arr[1] = %d, *p = %d\n", arr[1], *p);
|
||||
|
||||
return 0;
|
||||
}
|
||||
25
examples/tests/array_advanced_test.c
Archivo normal
25
examples/tests/array_advanced_test.c
Archivo normal
@@ -0,0 +1,25 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
// Test simple array initialization
|
||||
int arr[5];
|
||||
arr[0] = 10;
|
||||
arr[1] = 20;
|
||||
arr[2] = 30;
|
||||
arr[3] = 40;
|
||||
arr[4] = 50;
|
||||
|
||||
printf("Array contents:\n");
|
||||
for (int i = 0; i < 5; i++) {
|
||||
printf("arr[%d] = %d\n", i, arr[i]);
|
||||
}
|
||||
|
||||
// Test array arithmetic
|
||||
int sum = 0;
|
||||
for (int i = 0; i < 5; i++) {
|
||||
sum = sum + arr[i];
|
||||
}
|
||||
printf("Sum = %d\n", sum);
|
||||
|
||||
return 0;
|
||||
}
|
||||
9
examples/tests/array_as_ptr_test.c
Archivo normal
9
examples/tests/array_as_ptr_test.c
Archivo normal
@@ -0,0 +1,9 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int arr[3];
|
||||
arr[0] = 10;
|
||||
int *ptr = arr;
|
||||
printf("Value: %d\n", *ptr);
|
||||
return 0;
|
||||
}
|
||||
23
examples/tests/array_debug.c
Archivo normal
23
examples/tests/array_debug.c
Archivo normal
@@ -0,0 +1,23 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
printf("=== Array Assignment Debug ===\n");
|
||||
int arr[3];
|
||||
|
||||
printf("Before assignments:\n");
|
||||
printf("arr[0] = %d, arr[1] = %d, arr[2] = %d\n", arr[0], arr[1], arr[2]);
|
||||
|
||||
printf("Assigning arr[0] = 10\n");
|
||||
arr[0] = 10;
|
||||
printf("arr[0] = %d, arr[1] = %d, arr[2] = %d\n", arr[0], arr[1], arr[2]);
|
||||
|
||||
printf("Assigning arr[1] = 20\n");
|
||||
arr[1] = 20;
|
||||
printf("arr[0] = %d, arr[1] = %d, arr[2] = %d\n", arr[0], arr[1], arr[2]);
|
||||
|
||||
printf("Assigning arr[2] = 30\n");
|
||||
arr[2] = 30;
|
||||
printf("arr[0] = %d, arr[1] = %d, arr[2] = %d\n", arr[0], arr[1], arr[2]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
8
examples/tests/array_ptr_test.c
Archivo normal
8
examples/tests/array_ptr_test.c
Archivo normal
@@ -0,0 +1,8 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int arr[3] = {10, 20, 30};
|
||||
int *ptr = arr;
|
||||
printf("First element: %d\n", *ptr);
|
||||
return 0;
|
||||
}
|
||||
16
examples/tests/array_test.c
Archivo normal
16
examples/tests/array_test.c
Archivo normal
@@ -0,0 +1,16 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int arr[5];
|
||||
arr[0] = 10;
|
||||
arr[1] = 20;
|
||||
arr[2] = 30;
|
||||
arr[3] = 40;
|
||||
arr[4] = 50;
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
printf("arr[%d] = %d\n", i, arr[i]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
19
examples/tests/basic_function_test.c
Archivo normal
19
examples/tests/basic_function_test.c
Archivo normal
@@ -0,0 +1,19 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int test_param(int x) {
|
||||
printf(" In test_param: x = %d\n", x);
|
||||
return x + 1;
|
||||
}
|
||||
|
||||
int main() {
|
||||
printf("Testing basic function calls...\n");
|
||||
|
||||
int result1 = test_param(5);
|
||||
printf("Result 1: %d\n", result1);
|
||||
|
||||
int result2 = test_param(10);
|
||||
printf("Result 2: %d\n", result2);
|
||||
|
||||
printf("Test completed.\n");
|
||||
return 0;
|
||||
}
|
||||
16
examples/tests/bitwise_test.c
Archivo normal
16
examples/tests/bitwise_test.c
Archivo normal
@@ -0,0 +1,16 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int a = 12; // 1100 in binary
|
||||
int b = 10; // 1010 in binary
|
||||
|
||||
printf("a = %d, b = %d\n", a, b);
|
||||
printf("a & b = %d\n", a & b); // bitwise AND
|
||||
printf("a | b = %d\n", a | b); // bitwise OR
|
||||
printf("a ^ b = %d\n", a ^ b); // bitwise XOR
|
||||
printf("~a = %d\n", ~a); // bitwise NOT
|
||||
printf("a << 2 = %d\n", a << 2); // left shift
|
||||
printf("a >> 1 = %d\n", a >> 1); // right shift
|
||||
|
||||
return 0;
|
||||
}
|
||||
29
examples/tests/bubble_sort_test.c
Archivo normal
29
examples/tests/bubble_sort_test.c
Archivo normal
@@ -0,0 +1,29 @@
|
||||
#include <stdio.h>
|
||||
void bubble_sort(int arr[], int n) {
|
||||
for (int i = 0; i < n - 1; i++) {
|
||||
for (int j = 0; j < n - i - 1; j++) {
|
||||
if (arr[j] > arr[j + 1]) {
|
||||
int temp = arr[j];
|
||||
arr[j] = arr[j + 1];
|
||||
arr[j + 1] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
int main() {
|
||||
int numbers[5] = {64, 34, 25, 12, 22};
|
||||
printf("Original array: ");
|
||||
for (int i = 0; i < 5; i++) {
|
||||
printf("%d ", numbers[i]);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
bubble_sort(numbers, 5);
|
||||
|
||||
printf("Sorted array: ");
|
||||
for (int i = 0; i < 5; i++) {
|
||||
printf("%d ", numbers[i]);
|
||||
}
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
16
examples/tests/complex_ptr_test.c
Archivo normal
16
examples/tests/complex_ptr_test.c
Archivo normal
@@ -0,0 +1,16 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int a = 10;
|
||||
int b = 20;
|
||||
int *ptr1 = &a;
|
||||
int *ptr2 = &b;
|
||||
|
||||
// Swap the pointer targets
|
||||
*ptr1 = *ptr1 + *ptr2;
|
||||
*ptr2 = *ptr1 - *ptr2;
|
||||
*ptr1 = *ptr1 - *ptr2;
|
||||
|
||||
printf("Swapped values: a=%d, b=%d\n", a, b);
|
||||
return 0;
|
||||
}
|
||||
20
examples/tests/compound_operators_test.c
Archivo normal
20
examples/tests/compound_operators_test.c
Archivo normal
@@ -0,0 +1,20 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int x = 10;
|
||||
printf("Initial x = %d\n", x);
|
||||
|
||||
x += 5;
|
||||
printf("After x += 5: %d\n", x);
|
||||
|
||||
x -= 3;
|
||||
printf("After x -= 3: %d\n", x);
|
||||
|
||||
x *= 2;
|
||||
printf("After x *= 2: %d\n", x);
|
||||
|
||||
x /= 4;
|
||||
printf("After x /= 4: %d\n", x);
|
||||
|
||||
return 0;
|
||||
}
|
||||
52
examples/tests/comprehensive_test.c
Archivo normal
52
examples/tests/comprehensive_test.c
Archivo normal
@@ -0,0 +1,52 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
printf("=== ALECC Compiler Test Suite ===\n");
|
||||
|
||||
// Test 1: Basic arithmetic and variables
|
||||
printf("Test 1: Basic operations\n");
|
||||
int a = 10;
|
||||
int b = 20;
|
||||
printf(" a = %d, b = %d\n", a, b);
|
||||
printf(" a + b = %d\n", a + b);
|
||||
printf(" a * b = %d\n", a * b);
|
||||
printf(" a %% 3 = %d\n", a % 3);
|
||||
|
||||
// Test 2: Pointer operations
|
||||
printf("Test 2: Pointer operations\n");
|
||||
int x = 42;
|
||||
int *ptr = &x;
|
||||
printf(" x = %d\n", x);
|
||||
printf(" *ptr = %d\n", *ptr);
|
||||
*ptr = 100;
|
||||
printf(" After *ptr = 100: x = %d\n", x);
|
||||
|
||||
// Test 3: Arrays
|
||||
printf("Test 3: Array operations\n");
|
||||
int arr[3];
|
||||
arr[0] = 1;
|
||||
arr[1] = 2;
|
||||
arr[2] = 3;
|
||||
printf(" arr[0] = %d, arr[1] = %d, arr[2] = %d\n", arr[0], arr[1], arr[2]);
|
||||
|
||||
// Test 4: Control flow
|
||||
printf("Test 4: Control flow\n");
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (i % 2 == 0) {
|
||||
printf(" %d is even\n", i);
|
||||
} else {
|
||||
printf(" %d is odd\n", i);
|
||||
}
|
||||
}
|
||||
|
||||
// Test 5: While loops
|
||||
printf("Test 5: While loop\n");
|
||||
int count = 0;
|
||||
while (count < 3) {
|
||||
printf(" count = %d\n", count);
|
||||
count++;
|
||||
}
|
||||
|
||||
printf("=== All tests completed successfully! ===\n");
|
||||
return 0;
|
||||
}
|
||||
17
examples/tests/debug_else_only.c
Archivo normal
17
examples/tests/debug_else_only.c
Archivo normal
@@ -0,0 +1,17 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int debug_else_only(int n) {
|
||||
printf("Called with n = %d\n", n);
|
||||
if (n <= 1) {
|
||||
return 1;
|
||||
} else {
|
||||
return n * 2;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
printf("Testing else-only...\n");
|
||||
int result = debug_else_only(5);
|
||||
printf("Result = %d\n", result);
|
||||
return 0;
|
||||
}
|
||||
25
examples/tests/debug_expr_test.c
Archivo normal
25
examples/tests/debug_expr_test.c
Archivo normal
@@ -0,0 +1,25 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int x = 5;
|
||||
int y = 3;
|
||||
|
||||
printf("x = %d, y = %d\n", x, y);
|
||||
|
||||
int sum = x + y;
|
||||
printf("x + y = %d\n", sum);
|
||||
|
||||
int diff = x - y;
|
||||
printf("x - y = %d\n", diff);
|
||||
|
||||
int prod = sum * diff;
|
||||
printf("(x + y) * (x - y) = %d\n", prod);
|
||||
|
||||
int mod = x % y;
|
||||
printf("x %% y = %d\n", mod);
|
||||
|
||||
int result = prod + mod;
|
||||
printf("result = %d\n", result);
|
||||
|
||||
return 0;
|
||||
}
|
||||
16
examples/tests/debug_if_only.c
Archivo normal
16
examples/tests/debug_if_only.c
Archivo normal
@@ -0,0 +1,16 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int debug_if_only(int n) {
|
||||
if (n > 0) {
|
||||
printf("In if branch\n");
|
||||
return n + 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main() {
|
||||
printf("Testing if-only...\n");
|
||||
int result = debug_if_only(5);
|
||||
printf("Result = %d\n", result);
|
||||
return 0;
|
||||
}
|
||||
8
examples/tests/debug_printf.c
Archivo normal
8
examples/tests/debug_printf.c
Archivo normal
@@ -0,0 +1,8 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
printf("First call\n");
|
||||
printf("Second call\n");
|
||||
printf("Third call\n");
|
||||
return 0;
|
||||
}
|
||||
20
examples/tests/debug_recursion_test.c
Archivo normal
20
examples/tests/debug_recursion_test.c
Archivo normal
@@ -0,0 +1,20 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int test_recursion(int n) {
|
||||
printf("Entering test_recursion with n = %d\n", n);
|
||||
if (n <= 0) {
|
||||
printf("Base case reached, returning 0\n");
|
||||
return 0;
|
||||
}
|
||||
printf("Calling recursion with n-1 = %d\n", n-1);
|
||||
int result = test_recursion(n - 1);
|
||||
printf("Recursion returned %d for n = %d\n", result, n);
|
||||
return result + 1;
|
||||
}
|
||||
|
||||
int main() {
|
||||
printf("Starting recursion test\n");
|
||||
int result = test_recursion(2);
|
||||
printf("Final result: %d\n", result);
|
||||
return 0;
|
||||
}
|
||||
9
examples/tests/deref_test.c
Archivo normal
9
examples/tests/deref_test.c
Archivo normal
@@ -0,0 +1,9 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int x = 42;
|
||||
int *ptr = &x;
|
||||
int y = *ptr;
|
||||
printf("y = %d\n", y);
|
||||
return 0;
|
||||
}
|
||||
8
examples/tests/double_printf.c
Archivo normal
8
examples/tests/double_printf.c
Archivo normal
@@ -0,0 +1,8 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int x = 42;
|
||||
printf("first\n");
|
||||
printf("second\n");
|
||||
return 0;
|
||||
}
|
||||
56
examples/tests/edge_case_test.c
Archivo normal
56
examples/tests/edge_case_test.c
Archivo normal
@@ -0,0 +1,56 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
printf("=== Array Assignment Edge Cases ===\n");
|
||||
|
||||
// Test 1: Multiple arrays
|
||||
int arr1[3];
|
||||
int arr2[3];
|
||||
arr1[0] = 1;
|
||||
arr1[1] = 2;
|
||||
arr1[2] = 3;
|
||||
arr2[0] = 10;
|
||||
arr2[1] = 20;
|
||||
arr2[2] = 30;
|
||||
printf("arr1: [%d, %d, %d]\n", arr1[0], arr1[1], arr1[2]);
|
||||
printf("arr2: [%d, %d, %d]\n", arr2[0], arr2[1], arr2[2]);
|
||||
|
||||
// Test 2: Sequential assignments
|
||||
int seq[5];
|
||||
int k = 0;
|
||||
while (k < 5) {
|
||||
seq[k] = k * k;
|
||||
k = k + 1;
|
||||
}
|
||||
printf("Sequence: ");
|
||||
k = 0;
|
||||
while (k < 5) {
|
||||
printf("%d ", seq[k]);
|
||||
k = k + 1;
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
// Test 3: Array with function calls
|
||||
int result[3];
|
||||
printf("Setting result[0] = 5\n");
|
||||
result[0] = 5;
|
||||
printf("result[0] = %d\n", result[0]);
|
||||
printf("Setting result[1] = result[0] * 2\n");
|
||||
result[1] = result[0] * 2;
|
||||
printf("result[1] = %d\n", result[1]);
|
||||
printf("Setting result[2] = result[1] + result[0]\n");
|
||||
result[2] = result[1] + result[0];
|
||||
printf("result[2] = %d\n", result[2]);
|
||||
|
||||
// Test 4: Large indices to test multiplication
|
||||
int big_arr[100];
|
||||
big_arr[99] = 42;
|
||||
big_arr[50] = 25;
|
||||
big_arr[1] = 99;
|
||||
printf("big_arr[99] = %d\n", big_arr[99]);
|
||||
printf("big_arr[50] = %d\n", big_arr[50]);
|
||||
printf("big_arr[1] = %d\n", big_arr[1]);
|
||||
|
||||
printf("All edge cases passed!\n");
|
||||
return 0;
|
||||
}
|
||||
11
examples/tests/even_test.c
Archivo normal
11
examples/tests/even_test.c
Archivo normal
@@ -0,0 +1,11 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int i = 4;
|
||||
if (i % 2 == 0) {
|
||||
printf("even\n");
|
||||
} else {
|
||||
printf("odd\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
15
examples/tests/exact_repro_test.c
Archivo normal
15
examples/tests/exact_repro_test.c
Archivo normal
@@ -0,0 +1,15 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int arr[3];
|
||||
arr[0] = 1;
|
||||
printf("After arr[0] = 1: arr[0] = %d, arr[1] = %d, arr[2] = %d\n", arr[0], arr[1], arr[2]);
|
||||
|
||||
arr[1] = 2;
|
||||
printf("After arr[1] = 2: arr[0] = %d, arr[1] = %d, arr[2] = %d\n", arr[0], arr[1], arr[2]);
|
||||
|
||||
arr[2] = 3;
|
||||
printf("After arr[2] = 3: arr[0] = %d, arr[1] = %d, arr[2] = %d\n", arr[0], arr[1], arr[2]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
7
examples/tests/explicit_return_test.c
Archivo normal
7
examples/tests/explicit_return_test.c
Archivo normal
@@ -0,0 +1,7 @@
|
||||
int simple_explicit_return(int n) {
|
||||
return 42;
|
||||
}
|
||||
|
||||
int main() {
|
||||
return simple_explicit_return(5);
|
||||
}
|
||||
14
examples/tests/factorial_test.c
Archivo normal
14
examples/tests/factorial_test.c
Archivo normal
@@ -0,0 +1,14 @@
|
||||
#include <stdio.h>
|
||||
int factorial(int n) {
|
||||
if (n <= 1) {
|
||||
return 1;
|
||||
}
|
||||
return n * factorial(n - 1);
|
||||
}
|
||||
int main() {
|
||||
printf("Testing factorial...\n");
|
||||
for (int i = 0; i <= 5; i++) {
|
||||
printf("factorial(%d) = %d\n", i, factorial(i));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
10
examples/tests/fibonacci_no_printf.c
Archivo normal
10
examples/tests/fibonacci_no_printf.c
Archivo normal
@@ -0,0 +1,10 @@
|
||||
int fibonacci(int n) {
|
||||
if (n <= 1) {
|
||||
return n;
|
||||
}
|
||||
return fibonacci(n - 1) + fibonacci(n - 2);
|
||||
}
|
||||
|
||||
int main() {
|
||||
return fibonacci(5);
|
||||
}
|
||||
13
examples/tests/fibonacci_simple.c
Archivo normal
13
examples/tests/fibonacci_simple.c
Archivo normal
@@ -0,0 +1,13 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int fibonacci(int n) {
|
||||
if (n <= 1) {
|
||||
return n;
|
||||
}
|
||||
return fibonacci(n - 1) + fibonacci(n - 2);
|
||||
}
|
||||
|
||||
int main() {
|
||||
printf("fib(5) = %d\n", fibonacci(5));
|
||||
return 0;
|
||||
}
|
||||
14
examples/tests/fibonacci_test.c
Archivo normal
14
examples/tests/fibonacci_test.c
Archivo normal
@@ -0,0 +1,14 @@
|
||||
#include <stdio.h>
|
||||
int fibonacci(int n) {
|
||||
if (n <= 1) {
|
||||
return n;
|
||||
}
|
||||
return fibonacci(n - 1) + fibonacci(n - 2);
|
||||
}
|
||||
int main() {
|
||||
printf("Testing fibonacci...\n");
|
||||
for (int i = 0; i <= 10; i++) {
|
||||
printf("fibonacci(%d) = %d\n", i, fibonacci(i));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
19
examples/tests/final_success_test.c
Archivo normal
19
examples/tests/final_success_test.c
Archivo normal
@@ -0,0 +1,19 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
printf("ALECC Test Summary\n");
|
||||
|
||||
int arr[3];
|
||||
arr[0] = 10;
|
||||
arr[1] = 20;
|
||||
arr[2] = 30;
|
||||
printf("Arrays: arr[1] = %d (FIXED!)\n", arr[1]);
|
||||
|
||||
int val = 42;
|
||||
int* ptr = &val;
|
||||
*ptr = 99;
|
||||
printf("Pointers: value is now %d\n", val);
|
||||
|
||||
printf("ALECC compiler SUCCESS!\n");
|
||||
return 0;
|
||||
}
|
||||
54
examples/tests/final_summary_test.c
Archivo normal
54
examples/tests/final_summary_test.c
Archivo normal
@@ -0,0 +1,54 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int fibonacci(int n) {
|
||||
if (n <= 1) {
|
||||
return n;
|
||||
}
|
||||
return fibonacci(n - 1) + fibonacci(n - 2);
|
||||
}
|
||||
|
||||
int main() {
|
||||
printf("=== ALECC Final Test Summary ===\n");
|
||||
|
||||
// Test 1: Basic math
|
||||
int a = 15;
|
||||
int b = 4;
|
||||
printf("Math: %d + %d = %d\n", a, b, a + b);
|
||||
printf("Modulo: %d %% %d = %d\n", a, b, a % b);
|
||||
|
||||
// Test 2: Arrays (our fixed feature!)
|
||||
int arr[5];
|
||||
arr[0] = 10;
|
||||
arr[1] = 20; // This was the bug we fixed!
|
||||
arr[2] = 30;
|
||||
arr[3] = 40;
|
||||
arr[4] = 50;
|
||||
printf("Array: arr[1] = %d (FIXED!)\n", arr[1]);
|
||||
|
||||
// Test 3: Pointers
|
||||
int val = 42;
|
||||
int* ptr = &val;
|
||||
*ptr = 99;
|
||||
printf("Pointers: value is now %d\n", val);
|
||||
|
||||
// Test 4: Control flow
|
||||
int i = 0;
|
||||
printf("Loop: ");
|
||||
while (i < 5) {
|
||||
printf("%d ", i);
|
||||
i = i + 1;
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
// Test 5: Recursion
|
||||
printf("Fibonacci(6) = %d\n", fibonacci(6));
|
||||
|
||||
// Test 6: Multiple printf calls (stack alignment fixed!)
|
||||
printf("Stack alignment test:\n");
|
||||
printf("Line 1\n");
|
||||
printf("Line 2\n");
|
||||
printf("Line 3\n");
|
||||
|
||||
printf("SUCCESS: All major features working!\n");
|
||||
return 0;
|
||||
}
|
||||
76
examples/tests/final_test.c
Archivo normal
76
examples/tests/final_test.c
Archivo normal
@@ -0,0 +1,76 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int fibonacci(int n) {
|
||||
if (n <= 1) {
|
||||
return n;
|
||||
}
|
||||
return fibonacci(n - 1) + fibonacci(n - 2);
|
||||
}
|
||||
|
||||
int main() {
|
||||
printf("=== ALECC Final Comprehensive Test ===\n");
|
||||
|
||||
// Test 1: All basic operations
|
||||
int a = 15;
|
||||
int b = 4;
|
||||
printf("Basic operations:\n");
|
||||
printf(" %d + %d = %d\n", a, b, a + b);
|
||||
printf(" %d - %d = %d\n", a, b, a - b);
|
||||
printf(" %d * %d = %d\n", a, b, a * b);
|
||||
printf(" %d / %d = %d\n", a, b, a / b);
|
||||
printf(" %d %% %d = %d\n", a, b, a % b);
|
||||
|
||||
// Test 2: Arrays with all indices working
|
||||
printf("\nArray test:\n");
|
||||
int numbers[7];
|
||||
int i = 0;
|
||||
while (i < 7) {
|
||||
numbers[i] = i * i + 1;
|
||||
printf(" numbers[%d] = %d\n", i, numbers[i]);
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
// Test 3: Pointers
|
||||
printf("\nPointer test:\n");
|
||||
int value = 42;
|
||||
int* ptr = &value;
|
||||
printf(" value = %d\n", value);
|
||||
printf(" *ptr = %d\n", *ptr);
|
||||
*ptr = 100;
|
||||
printf(" After *ptr = 100: value = %d\n", value);
|
||||
|
||||
// Test 4: Complex expressions
|
||||
printf("\nComplex expressions:\n");
|
||||
int x = 5;
|
||||
int y = 3;
|
||||
int result = (x + y) * (x - y) + x % y;
|
||||
printf(" (%d + %d) * (%d - %d) + %d %% %d = %d\n", x, y, x, y, x, y, result);
|
||||
|
||||
// Test 5: Control flow
|
||||
printf("\nControl flow test:\n");
|
||||
int j = 0;
|
||||
while (j < 5) {
|
||||
if (j % 2 == 0) {
|
||||
printf(" %d is even\n", j);
|
||||
} else {
|
||||
printf(" %d is odd\n", j);
|
||||
}
|
||||
j = j + 1;
|
||||
}
|
||||
|
||||
// Test 6: Function calls and recursion
|
||||
printf("\nRecursion test:\n");
|
||||
int n = 6;
|
||||
printf(" fibonacci(%d) = %d\n", n, fibonacci(n));
|
||||
|
||||
// Test 7: Multiple printf calls (stack alignment test)
|
||||
printf("\nMultiple printf test:\n");
|
||||
printf(" Line 1\n");
|
||||
printf(" Line 2\n");
|
||||
printf(" Line 3\n");
|
||||
printf(" Line 4\n");
|
||||
printf(" Line 5\n");
|
||||
|
||||
printf("\nAll tests passed! ALECC compiler is working perfectly!\n");
|
||||
return 0;
|
||||
}
|
||||
8
examples/tests/for_loop_final_test.c
Archivo normal
8
examples/tests/for_loop_final_test.c
Archivo normal
@@ -0,0 +1,8 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
for (int i = 0; i < 5; i++) {
|
||||
printf("i = %d\n", i);
|
||||
}
|
||||
return 42;
|
||||
}
|
||||
13
examples/tests/for_loop_test.c
Archivo normal
13
examples/tests/for_loop_test.c
Archivo normal
@@ -0,0 +1,13 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
printf("Testing for loop...\n");
|
||||
|
||||
int i;
|
||||
for (i = 0; i < 5; i = i + 1) {
|
||||
printf("for loop: i = %d\n", i);
|
||||
}
|
||||
|
||||
printf("For loop completed!\n");
|
||||
return 0;
|
||||
}
|
||||
16
examples/tests/format_test.c
Archivo normal
16
examples/tests/format_test.c
Archivo normal
@@ -0,0 +1,16 @@
|
||||
// Simple test without stdio.h to verify formatting didn't break functionality
|
||||
int main() {
|
||||
// Arrays (our main fix!)
|
||||
int arr[3];
|
||||
arr[0] = 10;
|
||||
arr[1] = 20; // The bug we fixed
|
||||
arr[2] = 30;
|
||||
|
||||
// Pointers
|
||||
int val = 42;
|
||||
int* ptr = &val;
|
||||
*ptr = 99;
|
||||
|
||||
// Return the sum to verify functionality
|
||||
return arr[1] + val; // Should be 20 + 99 = 119
|
||||
}
|
||||
13
examples/tests/function_no_params_test.c
Archivo normal
13
examples/tests/function_no_params_test.c
Archivo normal
@@ -0,0 +1,13 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int say_hello() {
|
||||
printf("Hello from function!\n");
|
||||
return 42;
|
||||
}
|
||||
|
||||
int main() {
|
||||
printf("Before function call\n");
|
||||
int result = say_hello();
|
||||
printf("After function call, result = %d\n", result);
|
||||
return 0;
|
||||
}
|
||||
10
examples/tests/function_test.c
Archivo normal
10
examples/tests/function_test.c
Archivo normal
@@ -0,0 +1,10 @@
|
||||
int printf(const char* format, ...);
|
||||
|
||||
int add(int a, int b) {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
int main() {
|
||||
printf("Result: %d\n", add(5, 3));
|
||||
return 0;
|
||||
}
|
||||
6
examples/tests/hello_simple.c
Archivo normal
6
examples/tests/hello_simple.c
Archivo normal
@@ -0,0 +1,6 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
printf("Hello world!\n");
|
||||
return 0;
|
||||
}
|
||||
20
examples/tests/if_else_return_test.c
Archivo normal
20
examples/tests/if_else_return_test.c
Archivo normal
@@ -0,0 +1,20 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int if_else_return_test(int n) {
|
||||
printf("Called with n = %d\n", n);
|
||||
if (n <= 1) {
|
||||
printf("Returning from if branch\n");
|
||||
return 1;
|
||||
}
|
||||
printf("In else branch\n");
|
||||
return n * 2;
|
||||
}
|
||||
|
||||
int main() {
|
||||
printf("Testing if-else return...\n");
|
||||
int result1 = if_else_return_test(0);
|
||||
printf("Result1 = %d\n", result1);
|
||||
int result2 = if_else_return_test(3);
|
||||
printf("Result2 = %d\n", result2);
|
||||
return 0;
|
||||
}
|
||||
21
examples/tests/if_else_return_test_fixed.c
Archivo normal
21
examples/tests/if_else_return_test_fixed.c
Archivo normal
@@ -0,0 +1,21 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int if_else_return_test_fixed(int n) {
|
||||
printf("Called with n = %d\n", n);
|
||||
if (n <= 1) {
|
||||
printf("Returning from if branch\n");
|
||||
return 1;
|
||||
} else {
|
||||
printf("In else branch\n");
|
||||
return n * 2;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
printf("Testing if-else return with explicit braces...\n");
|
||||
int result1 = if_else_return_test_fixed(0);
|
||||
printf("Result1 = %d\n", result1);
|
||||
int result2 = if_else_return_test_fixed(3);
|
||||
printf("Result2 = %d\n", result2);
|
||||
return 0;
|
||||
}
|
||||
12
examples/tests/if_else_test.c
Archivo normal
12
examples/tests/if_else_test.c
Archivo normal
@@ -0,0 +1,12 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
if (i % 2 == 0) {
|
||||
printf("%d is even\n", i);
|
||||
} else {
|
||||
printf("%d is odd\n", i);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
10
examples/tests/if_only.c
Archivo normal
10
examples/tests/if_only.c
Archivo normal
@@ -0,0 +1,10 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int i = 4;
|
||||
int result = i % 2;
|
||||
if (result == 0) {
|
||||
printf("zero\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
22
examples/tests/index1_test.c
Archivo normal
22
examples/tests/index1_test.c
Archivo normal
@@ -0,0 +1,22 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int arr[3];
|
||||
|
||||
// Test with index 1 specifically
|
||||
printf("Testing arr[1] assignment:\n");
|
||||
|
||||
arr[1] = 42;
|
||||
printf("After arr[1] = 42: arr[1] = %d\n", arr[1]);
|
||||
|
||||
arr[1] = 7;
|
||||
printf("After arr[1] = 7: arr[1] = %d\n", arr[1]);
|
||||
|
||||
arr[1] = 0;
|
||||
printf("After arr[1] = 0: arr[1] = %d\n", arr[1]);
|
||||
|
||||
arr[1] = 1;
|
||||
printf("After arr[1] = 1: arr[1] = %d\n", arr[1]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
10
examples/tests/minimal_function_test.c
Archivo normal
10
examples/tests/minimal_function_test.c
Archivo normal
@@ -0,0 +1,10 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int test_func() {
|
||||
return 99;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int result = test_func();
|
||||
return result;
|
||||
}
|
||||
14
examples/tests/minimal_return_test.c
Archivo normal
14
examples/tests/minimal_return_test.c
Archivo normal
@@ -0,0 +1,14 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int minimal_return_test(int n) {
|
||||
printf("Called with n = %d\n", n);
|
||||
printf("About to return\n");
|
||||
return n * 2;
|
||||
}
|
||||
|
||||
int main() {
|
||||
printf("Testing minimal return...\n");
|
||||
int result = minimal_return_test(3);
|
||||
printf("Result = %d\n", result);
|
||||
return 0;
|
||||
}
|
||||
10
examples/tests/modulo_comprehensive.c
Archivo normal
10
examples/tests/modulo_comprehensive.c
Archivo normal
@@ -0,0 +1,10 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
printf("Testing modulo operator:\n");
|
||||
printf("10 %% 3 = %d\n", 10 % 3);
|
||||
printf("15 %% 4 = %d\n", 15 % 4);
|
||||
printf("8 %% 2 = %d\n", 8 % 2);
|
||||
printf("9 %% 2 = %d\n", 9 % 2);
|
||||
return 0;
|
||||
}
|
||||
8
examples/tests/modulo_only.c
Archivo normal
8
examples/tests/modulo_only.c
Archivo normal
@@ -0,0 +1,8 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int i = 4;
|
||||
int result = i % 2;
|
||||
printf("result: %d\n", result);
|
||||
return 0;
|
||||
}
|
||||
9
examples/tests/modulo_test.c
Archivo normal
9
examples/tests/modulo_test.c
Archivo normal
@@ -0,0 +1,9 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int a = 7;
|
||||
int b = 3;
|
||||
int result = a % b;
|
||||
printf("%d %% %d = %d\n", a, b, result);
|
||||
return 0;
|
||||
}
|
||||
6
examples/tests/multiple_vars.c
Archivo normal
6
examples/tests/multiple_vars.c
Archivo normal
@@ -0,0 +1,6 @@
|
||||
int main() {
|
||||
int x = 10;
|
||||
int y = 32;
|
||||
int z = x + y;
|
||||
return z;
|
||||
}
|
||||
8
examples/tests/no_printf_test.c
Archivo normal
8
examples/tests/no_printf_test.c
Archivo normal
@@ -0,0 +1,8 @@
|
||||
int simple_function(int x) {
|
||||
return x + 1;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int result = simple_function(5);
|
||||
return result;
|
||||
}
|
||||
7
examples/tests/null_ptr_test.c
Archivo normal
7
examples/tests/null_ptr_test.c
Archivo normal
@@ -0,0 +1,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int *ptr = 0;
|
||||
printf("Null pointer test done\n");
|
||||
return 0;
|
||||
}
|
||||
34
examples/tests/pointer_comprehensive_test.c
Archivo normal
34
examples/tests/pointer_comprehensive_test.c
Archivo normal
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* ALECC Pointer Support Test Suite
|
||||
* This file demonstrates all implemented pointer features
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
// Test 1: Basic pointer declaration and assignment
|
||||
int x = 42;
|
||||
int *ptr = &x; // Address-of operator
|
||||
|
||||
// Test 2: Reading through pointer dereference
|
||||
int value = *ptr; // Dereference for reading
|
||||
|
||||
// Test 3: Writing through pointer dereference
|
||||
*ptr = 100; // Dereference for assignment
|
||||
|
||||
// Test 4: Multiple pointers
|
||||
int y = 200;
|
||||
int *ptr2 = &y;
|
||||
|
||||
// Test 5: Pointer reassignment
|
||||
ptr = ptr2; // Point to different variable
|
||||
|
||||
// Test 6: Complex expressions with dereferences
|
||||
int result = *ptr + *ptr2; // Both pointers pointing to same location
|
||||
|
||||
// Test 7: Null pointer
|
||||
int *null_ptr = 0;
|
||||
|
||||
printf("All pointer tests compiled successfully!\n");
|
||||
return 0;
|
||||
}
|
||||
11
examples/tests/pointer_test.c
Archivo normal
11
examples/tests/pointer_test.c
Archivo normal
@@ -0,0 +1,11 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int x = 42;
|
||||
int *ptr = &x;
|
||||
printf("x = %d\n", x);
|
||||
printf("*ptr = %d\n", *ptr);
|
||||
*ptr = 100;
|
||||
printf("x after *ptr = 100: %d\n", x);
|
||||
return 0;
|
||||
}
|
||||
9
examples/tests/ptr_assign_test.c
Archivo normal
9
examples/tests/ptr_assign_test.c
Archivo normal
@@ -0,0 +1,9 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int x = 42;
|
||||
int *ptr = &x;
|
||||
*ptr = 100;
|
||||
printf("x = %d\n", x);
|
||||
return 0;
|
||||
}
|
||||
19
examples/tests/sequence_test.c
Archivo normal
19
examples/tests/sequence_test.c
Archivo normal
@@ -0,0 +1,19 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int arr[3];
|
||||
|
||||
printf("Step 1: arr[0] = 1\n");
|
||||
arr[0] = 1;
|
||||
printf("arr[0] = %d, arr[1] = %d, arr[2] = %d\n", arr[0], arr[1], arr[2]);
|
||||
|
||||
printf("Step 2: arr[2] = 3\n");
|
||||
arr[2] = 3;
|
||||
printf("arr[0] = %d, arr[1] = %d, arr[2] = %d\n", arr[0], arr[1], arr[2]);
|
||||
|
||||
printf("Step 3: arr[1] = 2\n");
|
||||
arr[1] = 2;
|
||||
printf("arr[0] = %d, arr[1] = %d, arr[2] = %d\n", arr[0], arr[1], arr[2]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
17
examples/tests/simple_array_test.c
Archivo normal
17
examples/tests/simple_array_test.c
Archivo normal
@@ -0,0 +1,17 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int arr[3];
|
||||
|
||||
// Set values directly
|
||||
arr[0] = 100;
|
||||
arr[1] = 200;
|
||||
arr[2] = 300;
|
||||
|
||||
// Test reading
|
||||
printf("Reading: arr[0] = %d\n", arr[0]);
|
||||
printf("Reading: arr[1] = %d\n", arr[1]);
|
||||
printf("Reading: arr[2] = %d\n", arr[2]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
11
examples/tests/simple_complex_test.c
Archivo normal
11
examples/tests/simple_complex_test.c
Archivo normal
@@ -0,0 +1,11 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int x = 5;
|
||||
int y = 3;
|
||||
int result = (x + y) * (x - y) + x % y;
|
||||
|
||||
printf("Complex expression result: %d\n", result);
|
||||
|
||||
return 0;
|
||||
}
|
||||
10
examples/tests/simple_for_debug.c
Archivo normal
10
examples/tests/simple_for_debug.c
Archivo normal
@@ -0,0 +1,10 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int i;
|
||||
for (i = 0; i < 3; i++) {
|
||||
printf("i = %d\n", i);
|
||||
}
|
||||
printf("Final i = %d\n", i);
|
||||
return 0;
|
||||
}
|
||||
9
examples/tests/simple_for_debug2.c
Archivo normal
9
examples/tests/simple_for_debug2.c
Archivo normal
@@ -0,0 +1,9 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int i;
|
||||
for (i = 0; i < 3; i++) {
|
||||
printf("i = %d\n", i);
|
||||
}
|
||||
return 42;
|
||||
}
|
||||
5
examples/tests/simple_format_test.c
Archivo normal
5
examples/tests/simple_format_test.c
Archivo normal
@@ -0,0 +1,5 @@
|
||||
int main() {
|
||||
int x = 10;
|
||||
int y = 20;
|
||||
return x + y; // Should be 30
|
||||
}
|
||||
10
examples/tests/simple_function_test.c
Archivo normal
10
examples/tests/simple_function_test.c
Archivo normal
@@ -0,0 +1,10 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int simple_function(int x) {
|
||||
return x + 1;
|
||||
}
|
||||
|
||||
int main() {
|
||||
printf("result = %d\n", simple_function(5));
|
||||
return 0;
|
||||
}
|
||||
11
examples/tests/simple_if_else.c
Archivo normal
11
examples/tests/simple_if_else.c
Archivo normal
@@ -0,0 +1,11 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int i = 5;
|
||||
if (i % 2 == 0) {
|
||||
printf("even\n");
|
||||
} else {
|
||||
printf("odd\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
14
examples/tests/simple_loop_test.c
Archivo normal
14
examples/tests/simple_loop_test.c
Archivo normal
@@ -0,0 +1,14 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
printf("Testing simple loop...\n");
|
||||
|
||||
int i = 0;
|
||||
while (i < 3) {
|
||||
printf("i = %d\n", i);
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
printf("Loop completed!\n");
|
||||
return 0;
|
||||
}
|
||||
14
examples/tests/simple_pointers_test.c
Archivo normal
14
examples/tests/simple_pointers_test.c
Archivo normal
@@ -0,0 +1,14 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int x = 42;
|
||||
int *ptr = &x;
|
||||
|
||||
printf("x = %d\n", x);
|
||||
printf("*ptr = %d\n", *ptr);
|
||||
|
||||
*ptr = 100;
|
||||
printf("After *ptr = 100, x = %d\n", x);
|
||||
|
||||
return 0;
|
||||
}
|
||||
6
examples/tests/simple_printf_test.c
Archivo normal
6
examples/tests/simple_printf_test.c
Archivo normal
@@ -0,0 +1,6 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
printf("Simple test\n");
|
||||
return 0;
|
||||
}
|
||||
20
examples/tests/simple_recursion_debug.c
Archivo normal
20
examples/tests/simple_recursion_debug.c
Archivo normal
@@ -0,0 +1,20 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int factorial_simple(int n) {
|
||||
printf("factorial_simple called with n = %d\n", n);
|
||||
if (n <= 1) {
|
||||
printf("Base case reached, returning 1\n");
|
||||
return 1;
|
||||
}
|
||||
printf("Calling factorial_simple(%d)\n", n - 1);
|
||||
int result = factorial_simple(n - 1);
|
||||
printf("Got result %d, returning %d * %d = %d\n", result, n, result, n * result);
|
||||
return n * result;
|
||||
}
|
||||
|
||||
int main() {
|
||||
printf("Testing simple recursion...\n");
|
||||
int result = factorial_simple(3);
|
||||
printf("factorial_simple(3) = %d\n", result);
|
||||
return 0;
|
||||
}
|
||||
14
examples/tests/simple_recursion_test.c
Archivo normal
14
examples/tests/simple_recursion_test.c
Archivo normal
@@ -0,0 +1,14 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int countdown(int n) {
|
||||
if (n <= 0) {
|
||||
return 0;
|
||||
}
|
||||
printf("n = %d\n", n);
|
||||
return countdown(n - 1);
|
||||
}
|
||||
|
||||
int main() {
|
||||
countdown(3);
|
||||
return 0;
|
||||
}
|
||||
13
examples/tests/simple_return_test.c
Archivo normal
13
examples/tests/simple_return_test.c
Archivo normal
@@ -0,0 +1,13 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int simple_return_test(int n) {
|
||||
printf("Called with n = %d\n", n);
|
||||
return n * 2;
|
||||
}
|
||||
|
||||
int main() {
|
||||
printf("Testing simple return...\n");
|
||||
int result = simple_return_test(5);
|
||||
printf("Result = %d\n", result);
|
||||
return 0;
|
||||
}
|
||||
7
examples/tests/simple_test.c
Archivo normal
7
examples/tests/simple_test.c
Archivo normal
@@ -0,0 +1,7 @@
|
||||
int printf(const char* format, ...);
|
||||
|
||||
int main() {
|
||||
int i = 5;
|
||||
printf("i = %d\n", i);
|
||||
return 0;
|
||||
}
|
||||
4
examples/tests/simple_var.c
Archivo normal
4
examples/tests/simple_var.c
Archivo normal
@@ -0,0 +1,4 @@
|
||||
int main() {
|
||||
int x = 42;
|
||||
return x;
|
||||
}
|
||||
7
examples/tests/simple_var_test.c
Archivo normal
7
examples/tests/simple_var_test.c
Archivo normal
@@ -0,0 +1,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int x = 42;
|
||||
printf("x = %d\n", x);
|
||||
return 0;
|
||||
}
|
||||
8
examples/tests/single_printf_test.c
Archivo normal
8
examples/tests/single_printf_test.c
Archivo normal
@@ -0,0 +1,8 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int x = 42;
|
||||
int *ptr = &x;
|
||||
printf("*ptr = %d\n", *ptr);
|
||||
return 0;
|
||||
}
|
||||
14
examples/tests/step_by_step_test.c
Archivo normal
14
examples/tests/step_by_step_test.c
Archivo normal
@@ -0,0 +1,14 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int x = 42;
|
||||
printf("x = %d\n", x);
|
||||
|
||||
int *ptr = &x;
|
||||
printf("*ptr = %d\n", *ptr);
|
||||
|
||||
*ptr = 100;
|
||||
printf("x after assignment = %d\n", x);
|
||||
|
||||
return 0;
|
||||
}
|
||||
15
examples/tests/string_test.c
Archivo normal
15
examples/tests/string_test.c
Archivo normal
@@ -0,0 +1,15 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
char message[] = "Hello, World!";
|
||||
char greeting[] = "Hi there";
|
||||
|
||||
printf("Message: %s\n", message);
|
||||
printf("Greeting: %s\n", greeting);
|
||||
|
||||
// Test character access
|
||||
printf("First char of message: %c\n", message[0]);
|
||||
printf("Last char of greeting: %c\n", greeting[7]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
24
examples/tests/success_summary_test.c
Archivo normal
24
examples/tests/success_summary_test.c
Archivo normal
@@ -0,0 +1,24 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
printf("=== Test Resumen ALECC ===\n");
|
||||
|
||||
// Arrays (nuestro fix principal!)
|
||||
int arr[3];
|
||||
arr[0] = 10;
|
||||
arr[1] = 20; // El bug que arreglamos
|
||||
arr[2] = 30;
|
||||
printf("Arrays: arr[1] = %d (FIXED!)\n", arr[1]);
|
||||
|
||||
// Punteros
|
||||
int val = 42;
|
||||
int* ptr = &val;
|
||||
*ptr = 99;
|
||||
printf("Punteros: valor ahora es %d\n", val);
|
||||
|
||||
// Funciones básicas (sin recursión)
|
||||
printf("Basic functions work!\n");
|
||||
|
||||
printf("ALECC compiler SUCCESS!\n");
|
||||
return 0;
|
||||
}
|
||||
14
examples/tests/sum_recursive_test.c
Archivo normal
14
examples/tests/sum_recursive_test.c
Archivo normal
@@ -0,0 +1,14 @@
|
||||
#include <stdio.h>
|
||||
int sum_recursive(int n) {
|
||||
if (n <= 0) {
|
||||
return 0;
|
||||
}
|
||||
return n + sum_recursive(n - 1);
|
||||
}
|
||||
int main() {
|
||||
printf("Testing recursive sum...\n");
|
||||
for (int i = 0; i <= 10; i++) {
|
||||
printf("sum(1 to %d) = %d\n", i, sum_recursive(i));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
11
examples/tests/test_final_functionality.c
Archivo normal
11
examples/tests/test_final_functionality.c
Archivo normal
@@ -0,0 +1,11 @@
|
||||
int factorial(int n) {
|
||||
if (n <= 1) {
|
||||
return 1;
|
||||
}
|
||||
return n * factorial(n - 1);
|
||||
}
|
||||
|
||||
int main() {
|
||||
int result = factorial(5);
|
||||
return result;
|
||||
}
|
||||
1
examples/tests/test_for.c
Archivo normal
1
examples/tests/test_for.c
Archivo normal
@@ -0,0 +1 @@
|
||||
int main() { int i; for (i = 0; i < 5; i++) { } return 0; }
|
||||
1
examples/tests/test_for_empty.c
Archivo normal
1
examples/tests/test_for_empty.c
Archivo normal
@@ -0,0 +1 @@
|
||||
int main() { for (;;) { return 0; } }
|
||||
1
examples/tests/test_for_init.c
Archivo normal
1
examples/tests/test_for_init.c
Archivo normal
@@ -0,0 +1 @@
|
||||
int main() { int i; for (i = 0;;) { return 0; } }
|
||||
1
examples/tests/test_for_without_inc.c
Archivo normal
1
examples/tests/test_for_without_inc.c
Archivo normal
@@ -0,0 +1 @@
|
||||
int main() { int i; for (i = 0; i < 5;) { i++; } return 0; }
|
||||
1
examples/tests/test_gcc.c
Archivo normal
1
examples/tests/test_gcc.c
Archivo normal
@@ -0,0 +1 @@
|
||||
int main() { return 0; }
|
||||
1
examples/tests/test_increment.c
Archivo normal
1
examples/tests/test_increment.c
Archivo normal
@@ -0,0 +1 @@
|
||||
int main() { int i; i++; return 0; }
|
||||
6
examples/tests/test_no_include.c
Archivo normal
6
examples/tests/test_no_include.c
Archivo normal
@@ -0,0 +1,6 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
printf("Testing after include directory removal\n");
|
||||
return 0;
|
||||
}
|
||||
1
examples/tests/test_simple_decl.c
Archivo normal
1
examples/tests/test_simple_decl.c
Archivo normal
@@ -0,0 +1 @@
|
||||
int main() { int i; return 0; }
|
||||
8
examples/tests/two_printf_test.c
Archivo normal
8
examples/tests/two_printf_test.c
Archivo normal
@@ -0,0 +1,8 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int x = 42;
|
||||
int *ptr = &x;
|
||||
printf("Before: x = %d, *ptr = %d\n", x, *ptr);
|
||||
return 0;
|
||||
}
|
||||
11
examples/tests/two_returns_test.c
Archivo normal
11
examples/tests/two_returns_test.c
Archivo normal
@@ -0,0 +1,11 @@
|
||||
int test_two_returns(int n) {
|
||||
if (n <= 1) {
|
||||
return n;
|
||||
}
|
||||
// Explicit return statement
|
||||
return 42;
|
||||
}
|
||||
|
||||
int main() {
|
||||
return test_two_returns(3);
|
||||
}
|
||||
7
examples/tests/var_test.c
Archivo normal
7
examples/tests/var_test.c
Archivo normal
@@ -0,0 +1,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int x = 42;
|
||||
printf("x = %d\n", x);
|
||||
return 0;
|
||||
}
|
||||
28
examples/tests/version_test.c
Archivo normal
28
examples/tests/version_test.c
Archivo normal
@@ -0,0 +1,28 @@
|
||||
// Test the new version with advanced features
|
||||
int test_compound_operators() {
|
||||
int x = 10;
|
||||
x += 5; // 15
|
||||
x *= 2; // 30
|
||||
x /= 3; // 10
|
||||
return x;
|
||||
}
|
||||
|
||||
int test_bitwise_operators() {
|
||||
int a = 12; // 1100 in binary
|
||||
int b = 10; // 1010 in binary
|
||||
|
||||
int result = 0;
|
||||
result += (a & b); // 8 (1000)
|
||||
result += (a | b); // 14 (1110)
|
||||
result += (a ^ b); // 6 (0110)
|
||||
result += (a << 1); // 24 (11000)
|
||||
result += (a >> 1); // 6 (110)
|
||||
|
||||
return result; // 8 + 14 + 6 + 24 + 6 = 58
|
||||
}
|
||||
|
||||
int main() {
|
||||
int comp_result = test_compound_operators(); // 10
|
||||
int bit_result = test_bitwise_operators(); // 58
|
||||
return comp_result + bit_result; // 68
|
||||
}
|
||||
10
examples/tests/while_test.c
Archivo normal
10
examples/tests/while_test.c
Archivo normal
@@ -0,0 +1,10 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int i = 0;
|
||||
while (i < 5) {
|
||||
printf("i = %d\n", i);
|
||||
i++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -131,8 +131,11 @@ impl CodeGenerator {
|
||||
// Set up parameter tracking
|
||||
self.current_function_params.clear();
|
||||
self.local_variables.clear();
|
||||
// Start local variables after parameters to avoid collision
|
||||
self.stack_offset = -(function.parameters.len() as i32 * 8);
|
||||
// Start local variables after all parameters to avoid collision
|
||||
// Parameters use negative offsets -8, -16, -24, etc.
|
||||
// Local variables should start after the last parameter
|
||||
let param_space = (function.parameters.len() as i32) * 8;
|
||||
self.stack_offset = -param_space - 8; // Start after all parameters
|
||||
self.epilogue_emitted = false;
|
||||
|
||||
// Function prologue
|
||||
@@ -175,11 +178,15 @@ impl CodeGenerator {
|
||||
self.emit_line(" push rbp");
|
||||
self.emit_line(" mov rbp, rsp");
|
||||
|
||||
// Reserve space for parameters + ensure 16-byte alignment
|
||||
// Reserve space for parameters + local variables + ensure 16-byte alignment
|
||||
let stack_space = parameters.len() * 8;
|
||||
// Always reserve at least 8 bytes to maintain 16-byte alignment after rbp push
|
||||
let min_space = if stack_space == 0 { 8 } else { stack_space };
|
||||
let aligned_space = ((min_space + 15) / 16) * 16; // Round up to 16-byte boundary
|
||||
// Reserve more space for local variables (128 bytes should be enough for most functions)
|
||||
let min_space = if stack_space == 0 {
|
||||
128
|
||||
} else {
|
||||
stack_space + 128
|
||||
};
|
||||
let aligned_space = min_space.div_ceil(16) * 16; // Round up to 16-byte boundary
|
||||
self.emit_line(&format!(" sub rsp, {}", aligned_space));
|
||||
|
||||
// Store parameters from registers (x86_64 calling convention)
|
||||
@@ -1267,7 +1274,7 @@ impl CodeGenerator {
|
||||
|
||||
match self.target {
|
||||
Target::I386 | Target::Amd64 => {
|
||||
self.emit_line(&format!(" test eax, eax"));
|
||||
self.emit_line(" test eax, eax");
|
||||
self.emit_line(&format!(" {} {}", instruction, label));
|
||||
}
|
||||
Target::Arm64 => {
|
||||
|
||||
@@ -119,7 +119,7 @@ impl Compiler {
|
||||
let preprocessed = self.preprocess(&source, input_file).await?;
|
||||
fs::write(&output_path, preprocessed)
|
||||
.await
|
||||
.map_err(|e| AleccError::IoError(e))?;
|
||||
.map_err(AleccError::IoError)?;
|
||||
return Ok(output_path);
|
||||
} else {
|
||||
self.preprocess(&source, input_file).await?
|
||||
@@ -149,7 +149,7 @@ impl Compiler {
|
||||
let output_path = self.get_output_path(input_file, "s")?;
|
||||
fs::write(&output_path, assembly)
|
||||
.await
|
||||
.map_err(|e| AleccError::IoError(e))?;
|
||||
.map_err(AleccError::IoError)?;
|
||||
return Ok(output_path);
|
||||
}
|
||||
|
||||
@@ -157,7 +157,7 @@ impl Compiler {
|
||||
let asm_path = self.create_temp_file("s")?;
|
||||
fs::write(&asm_path, assembly)
|
||||
.await
|
||||
.map_err(|e| AleccError::IoError(e))?;
|
||||
.map_err(AleccError::IoError)?;
|
||||
|
||||
// Assemble
|
||||
let obj_path = self.assemble_file(&asm_path).await?;
|
||||
@@ -215,9 +215,9 @@ impl Compiler {
|
||||
// Skip malformed include
|
||||
}
|
||||
}
|
||||
} else if trimmed.starts_with("#define") {
|
||||
} else if let Some(stripped) = trimmed.strip_prefix("#define") {
|
||||
// Handle #define (simplified)
|
||||
let parts: Vec<&str> = trimmed[7..].split_whitespace().collect();
|
||||
let parts: Vec<&str> = stripped.split_whitespace().collect();
|
||||
if !parts.is_empty() {
|
||||
let key = parts[0].to_string();
|
||||
let value = if parts.len() > 1 {
|
||||
@@ -330,17 +330,17 @@ impl Compiler {
|
||||
|
||||
match self.target {
|
||||
Target::I386 => {
|
||||
command.args(&["--32"]);
|
||||
command.args(["--32"]);
|
||||
}
|
||||
Target::Amd64 => {
|
||||
command.args(&["--64"]);
|
||||
command.args(["--64"]);
|
||||
}
|
||||
Target::Arm64 => {
|
||||
// Default options for aarch64
|
||||
}
|
||||
}
|
||||
|
||||
command.args(&[
|
||||
command.args([
|
||||
"-o",
|
||||
&obj_path.to_string_lossy(),
|
||||
&asm_file.to_string_lossy(),
|
||||
|
||||
@@ -218,7 +218,7 @@ impl Linker {
|
||||
Ok(command)
|
||||
}
|
||||
|
||||
fn add_standard_startup_files(&self, _command: &mut Vec<String>) -> Result<()> {
|
||||
fn add_standard_startup_files(&self, _command: &mut [String]) -> Result<()> {
|
||||
// Skip startup files when we have our own _start
|
||||
// This prevents conflicts with our custom _start implementation
|
||||
Ok(())
|
||||
@@ -257,7 +257,7 @@ impl Linker {
|
||||
fn get_gcc_lib_path(&self) -> Result<String> {
|
||||
// Try to find GCC library path
|
||||
let output = Command::new("gcc")
|
||||
.args(&["-print-libgcc-file-name"])
|
||||
.args(["-print-libgcc-file-name"])
|
||||
.output()
|
||||
.map_err(|e| AleccError::LinkerError {
|
||||
message: format!("Failed to find GCC library path: {}", e),
|
||||
|
||||
@@ -620,8 +620,16 @@ impl Parser {
|
||||
self.consume(&TokenType::RightParen, "Expected ')' after parameters")?;
|
||||
|
||||
let body = if self.check(&TokenType::LeftBrace) {
|
||||
self.advance()?; // Consume the LeftBrace
|
||||
self.parse_block_statement()?
|
||||
// Don't advance here, let parse_block_statement handle it
|
||||
let mut statements = Vec::new();
|
||||
self.consume(&TokenType::LeftBrace, "Expected '{' before function body")?;
|
||||
|
||||
while !self.check(&TokenType::RightBrace) && !self.is_at_end() {
|
||||
statements.push(self.parse_statement()?);
|
||||
}
|
||||
|
||||
self.consume(&TokenType::RightBrace, "Expected '}' after function body")?;
|
||||
Statement::Block(statements)
|
||||
} else {
|
||||
self.consume(
|
||||
&TokenType::Semicolon,
|
||||
|
||||
Referencia en una nueva incidencia
Block a user