Skip to content

Commit

Permalink
Clean up code (should be squashed with previous) - broken C tests (#66)
Browse files Browse the repository at this point in the history
* Fix syntax in GitHub Actions
* Refactor project to include under src
* Add Python test file
  • Loading branch information
thedavidchu authored Jan 7, 2024
1 parent a1075e1 commit bbcec76
Show file tree
Hide file tree
Showing 63 changed files with 526 additions and 580 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/linux_compiler_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v4
with:
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Compile
run: |
cd compiler
# For some reason, if we change to the compiler directory, Python complains.
export PYTHONPATH="${PYTHONPATH}:/home/runner/work/lolc/lolc/src/"
for x in fibonacci helloworld math_ops nested_if sum_three
do
python lol.py -i examples/$x.lol -o results
python src/compiler/lol.py -i examples/$x.lol -o results
gcc results/$x-*.c
./a.out
done
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
venv/

# Ignore Python Caches
compiler/results
/results/
__pycache__/

# Ignore CMake's build directory
Expand Down
73 changes: 0 additions & 73 deletions compiler/error/lol_error.py

This file was deleted.

Empty file removed compiler/parser/__init__.py
Empty file.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion compiler/examples/math_ops.lol → examples/math_ops.lol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ function math_operation(a: i32, b: i32, c: i32, d: i32) -> i32 {

function main() -> i32 {
let sum: i32 = math_operation(1, 2, 3, 4);
io::printf("Sum should be 31: %d", sum);
io::printf("Sum should be 31: %d\n", sum);
return 0;
}
File renamed without changes.
2 changes: 1 addition & 1 deletion compiler/examples/sum_three.lol → examples/sum_three.lol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ function sum_three(a: i32, b: i32, c: i32) -> i32 {

function main() -> i32 {
let sum: i32 = sum_three(1, 2, 3);
io::printf("Sum should be 6: %d", sum);
io::printf("Sum should be 6: %d\n", sum);
return 0;
}
2 changes: 0 additions & 2 deletions lint.bat

This file was deleted.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ documentation = "https://github.com/thedavidchu/lolc/"
[dependencies]

[dev-dependencies]
black = { version = "^22.3.0", python = "^3.6" }
black = { version = "^22.3.0", python = "^3.10" }

[tool.black]
line-length = 80
target_version = ['py36']
target-version = ['py310']
exclude = '''
(
/(
Expand Down
6 changes: 0 additions & 6 deletions run.sh

This file was deleted.

32 changes: 16 additions & 16 deletions src/CMakeLists.txt → src/c_interpretter/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# Make src public to tests
include_directories("${CMAKE_SOURCE_DIR}")

# Add libraries
## Compiler Compatibility Files
add_subdirectory("${CMAKE_SOURCE_DIR}/src/bool")
add_subdirectory("${CMAKE_SOURCE_DIR}/src/common")

## Standard Library Wrappers
add_subdirectory("${CMAKE_SOURCE_DIR}/src/mem")

## Custom Library
add_subdirectory("${CMAKE_SOURCE_DIR}/src/arr")
add_subdirectory("${CMAKE_SOURCE_DIR}/src/tbl")
add_subdirectory("${CMAKE_SOURCE_DIR}/src/rstr")

# Make src public to tests
include_directories("${CMAKE_SOURCE_DIR}")

# Add libraries
## Compiler Compatibility Files
add_subdirectory("${CMAKE_SOURCE_DIR}/src/bool")
add_subdirectory("${CMAKE_SOURCE_DIR}/src/common")

## Standard Library Wrappers
add_subdirectory("${CMAKE_SOURCE_DIR}/src/mem")

## Custom Library
add_subdirectory("${CMAKE_SOURCE_DIR}/src/arr")
add_subdirectory("${CMAKE_SOURCE_DIR}/src/tbl")
add_subdirectory("${CMAKE_SOURCE_DIR}/src/rstr")

File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Create the 'arr' target
add_library("arr" "${CMAKE_SOURCE_DIR}/src/arr/arr.c")

# Link executable to libraries
# Create the 'arr' target
add_library("arr" "${CMAKE_SOURCE_DIR}/src/arr/arr.c")

# Link executable to libraries
target_link_libraries("arr" PRIVATE "mem" "common")
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 6 additions & 6 deletions src/bool/bool.h → src/c_interpretter/bool/bool.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#ifndef __STDC_VERSION__ /* C89 */
typedef enum { false = 0, true = 1 } bool;
#else
#include <stdbool.h>
#pragma once

#ifndef __STDC_VERSION__ /* C89 */
typedef enum { false = 0, true = 1 } bool;
#else
#include <stdbool.h>
#endif
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit bbcec76

Please sign in to comment.