This commit is contained in:
2026-01-15 23:25:19 +08:00
parent 211a837468
commit 0248f47218
18 changed files with 79 additions and 42 deletions

1
.gitignore vendored
View File

@@ -23,6 +23,7 @@ Makefile
# Generated files # Generated files
*.log *.log
*.out *.out
.cache/
# macOS # macOS
.DS_Store .DS_Store

View File

@@ -1,56 +1,78 @@
cmake_minimum_required(VERSION 3.30) cmake_minimum_required(VERSION 3.30)
project(camellya) project(camellya)
set(CMAKE_CXX_STANDARD 23) set(CMAKE_CXX_STANDARD 20)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
option(CAMELLYA_BUILD_TESTS "Build tests" ON)
option(CAMELLYA_BUILD_STATIC "Build static library" ON)
option(CAMELLYA_BUILD_CLI "Build command line interface" ON)
# Library sources # Library sources
set(LIB_SOURCES set(LIB_SOURCES
library.cpp src/lexer.cpp
lexer.cpp src/parser.cpp
parser.cpp src/value.cpp
value.cpp src/interpreter.cpp
interpreter.cpp src/state.cpp
state.cpp
) )
# Library headers
set(LIB_HEADERS set(LIB_HEADERS
library.h src/camellya.h
lexer.h src/lexer.h
parser.h src/parser.h
ast.h src/ast.h
value.h src/value.h
interpreter.h src/interpreter.h
state.h src/state.h
) )
# Build static library if(CAMELLYA_BUILD_STATIC)
add_library(camellya STATIC ${LIB_SOURCES} ${LIB_HEADERS}) add_library(libcamellya STATIC ${LIB_SOURCES} ${LIB_HEADERS})
elseif()
add_library(libcamellya SHARED ${LIB_SOURCES} ${LIB_HEADERS})
endif()
include(FetchContent) target_include_directories(libcamellya PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src)
FetchContent_Declare( if(CAMELLYA_BUILD_CLI)
Catch2 add_executable(camellya
GIT_REPOSITORY https://github.com/catchorg/Catch2.git cli/main.cpp
GIT_TAG v3.6.0 )
) target_link_libraries(camellya
PRIVATE
libcamellya
)
endif()
FetchContent_MakeAvailable(Catch2) if(CAMELLYA_BUILD_TESTS)
include(FetchContent)
enable_testing() FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.12.0
)
add_executable(camellya_tests FetchContent_MakeAvailable(Catch2)
tests/test_basic.cpp
)
target_include_directories(camellya_tests enable_testing()
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
)
target_link_libraries(camellya_tests add_executable(camellya_tests
PRIVATE tests/test_basic.cpp
camellya )
Catch2::Catch2WithMain
)
add_test(NAME camellya_tests COMMAND camellya_tests) target_include_directories(camellya_tests
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
)
target_link_libraries(camellya_tests
PRIVATE
libcamellya
Catch2::Catch2WithMain
)
add_test(NAME camellya_tests COMMAND camellya_tests)
endif()

18
cli/main.cpp Normal file
View File

@@ -0,0 +1,18 @@
#include "camellya.h"
#include <iostream>
#include <format>
#include <chrono>
int main(int argc, char** argv) {
if(argc < 2){
std::cout << std::format("Usage: camellya <script> \n") << std::endl;
return 0;
}
std::chrono::high_resolution_clock::time_point start = std::chrono::high_resolution_clock::now();
camellya::State state;
state.do_file(argv[1]);
std::chrono::high_resolution_clock::time_point end = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> duration = end - start;
std::cout << std::format("Execution completed in {} seconds. \n", duration.count()) << std::endl;
return 0;
}

View File

@@ -1,4 +0,0 @@
#include "library.h"
// Implementation file for Camellya scripting language
// All implementation is in separate source files

View File

View File

@@ -1,6 +1,6 @@
#include <catch2/catch_test_macros.hpp> #include <catch2/catch_test_macros.hpp>
#include <catch2/benchmark/catch_benchmark.hpp> #include <catch2/benchmark/catch_benchmark.hpp>
#include "library.h" #include "camellya.h"
#include <memory> #include <memory>