Skip to content

Commit

Permalink
feat: remove cpp-peglib, add python interfacing
Browse files Browse the repository at this point in the history
  • Loading branch information
jahan-addison committed Nov 22, 2024
1 parent db9bca6 commit f9ed983
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 19 deletions.
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ repos:
- id: clang-format
args: [--style=file]
- id: cppcheck
- id: cpplint
# - id: clang-tidy
# - id: include-what-you-use

19 changes: 5 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,14 @@ if(PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
)
endif()

if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zc:__cplusplus /utf-8 /D_CRT_SECURE_NO_DEPRECATE")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
endif()

# ---- Add dependencies via CPM ----
include(cmake/CPM.cmake)
include(cmake/tools.cmake)

CPMAddPackage(
NAME peglib
GIT_TAG v1.9.1
GITHUB_REPOSITORY yhirose/cpp-peglib
OPTIONS "PEGLIB_BUILD_LINT YES"
)
# Add python-dev library to interface with python

find_package(PythonLibs REQUIRED)
include_directories(${PYTHON_INCLUDE_DIRS})

# ---- Add source files ----

Expand All @@ -52,5 +44,4 @@ target_include_directories(
$<INSTALL_INTERFACE:${PROJECT_NAME}-${PROJECT_VERSION}>
)

target_include_directories(${PROJECT_NAME} PUBLIC peglib)
target_link_libraries(${PROJECT_NAME} PUBLIC peglib)
target_link_libraries(${PROJECT_NAME} PUBLIC ${PYTHON_LIBRARIES})
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

### B Compiler to z80 in C++

* The frontend is built with Parsing Expression Grammars (PEG) via [cpp-peglib](https://github.com/yhirose/cpp-peglib)
* The frontend is built with a [easy-to-read LALR(1) grammar and parser generator in python](https://github.com/jahan-addison/xion/tree/master), that interfaces with C++ via CPython
* The backend will focus on modern work in SSA, Sea of Nodes, and compiler optimizations through IR breakthroughs in LLVM, gcc, V8, and related toolchains.


Expand Down
2 changes: 1 addition & 1 deletion grammar/b-grammar.abnf
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,4 @@ COMMENT : "/*" /(\S|\s)*?/ "*/"
WHITESPACE : /[ \t\f\r\n]/+

%ignore WHITESPACE // Ignore whitespace
%ignore COMMENT // Ignore comments
%ignore COMMENT // Ignore comments
22 changes: 20 additions & 2 deletions roxas/main.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
/*
* Copyright (c) Jahan Addison
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <iostream>
#include <peglib.h>

// https://stackoverflow.com/questions/39813301/creating-a-python-object-in-c-and-calling-its-method
#include <Python.h>

int main(void)
{
std::cout << "Hello, World" << std::endl;
}
}

0 comments on commit f9ed983

Please sign in to comment.