2022-09-16 21:04:20 +00:00
|
|
|
set(CMAKE_C_STANDARD 11)
|
|
|
|
|
set(CMAKE_C_EXTENSIONS OFF)
|
|
|
|
|
|
2023-02-10 20:39:51 +00:00
|
|
|
option(BUILD_SHARED_LIBS "Build dynamic / shared libraries" ON)
|
2022-11-29 22:13:10 +00:00
|
|
|
option(TEST_WITH_VALGRIND_MEMCHECK "Also run tests with valgrind / memcheck" ON)
|
|
|
|
|
|
2022-09-16 21:04:20 +00:00
|
|
|
add_library(apfl
|
|
|
|
|
alloc.c
|
|
|
|
|
bytecode.c
|
|
|
|
|
compile.c
|
|
|
|
|
context.c
|
|
|
|
|
error.c
|
|
|
|
|
eval.c
|
|
|
|
|
expr.c
|
|
|
|
|
format.c
|
|
|
|
|
gc.c
|
|
|
|
|
hashmap.c
|
|
|
|
|
globals.c
|
|
|
|
|
messages.c
|
|
|
|
|
parser.c
|
|
|
|
|
position.c
|
|
|
|
|
resizable.c
|
|
|
|
|
source_readers.c
|
|
|
|
|
scope.c
|
|
|
|
|
strings.c
|
|
|
|
|
token.c
|
|
|
|
|
tokenizer.c
|
|
|
|
|
value.c
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
add_executable(apfl-bin main.c)
|
|
|
|
|
target_link_libraries(apfl-bin PUBLIC apfl)
|
|
|
|
|
|
2022-10-30 21:00:11 +00:00
|
|
|
add_executable(functional-test-runner functional-test-runner.c)
|
|
|
|
|
target_link_libraries(functional-test-runner PUBLIC apfl)
|
|
|
|
|
|
2022-09-16 21:04:20 +00:00
|
|
|
set_target_properties(apfl-bin
|
|
|
|
|
PROPERTIES RUNTIME_OUTPUT_NAME apfl
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
function(unittest name moresources)
|
|
|
|
|
add_executable(${name} test.h ${name}.c ${moresources})
|
|
|
|
|
target_link_libraries(${name} PUBLIC apfl)
|
|
|
|
|
add_test(NAME ${name} COMMAND ${name})
|
2022-11-29 22:13:10 +00:00
|
|
|
if(${TEST_WITH_VALGRIND_MEMCHECK})
|
|
|
|
|
add_test(NAME "valgrind_memcheck__${name}" COMMAND valgrind --tool=memcheck --leak-check=full -q --error-exitcode=99 $<TARGET_FILE:${name}>)
|
|
|
|
|
endif()
|
|
|
|
|
|
2022-09-16 21:04:20 +00:00
|
|
|
endfunction()
|
|
|
|
|
|
|
|
|
|
unittest(tokenizer_test "")
|
|
|
|
|
unittest(parser_test "")
|
|
|
|
|
unittest(resizable_test "resizable.h")
|
|
|
|
|
unittest(hashmap_test "hashmap.h")
|
2022-10-30 21:00:11 +00:00
|
|
|
unittest(strings_test "")
|
2023-02-14 20:41:55 +00:00
|
|
|
unittest(alloc_test "")
|
2022-10-30 21:00:11 +00:00
|
|
|
|
|
|
|
|
function(functionaltest name)
|
|
|
|
|
add_test(NAME "functionaltest_${name}" COMMAND functional-test-runner ${CMAKE_SOURCE_DIR}/src/functional-tests/${name}.at)
|
2022-11-29 22:13:10 +00:00
|
|
|
if(${TEST_WITH_VALGRIND_MEMCHECK})
|
|
|
|
|
add_test(NAME "valgrind_memcheck__functionaltest_${name}" COMMAND valgrind --tool=memcheck --leak-check=full -q --error-exitcode=99 $<TARGET_FILE:functional-test-runner> ${CMAKE_SOURCE_DIR}/src/functional-tests/${name}.at)
|
|
|
|
|
endif()
|
2022-10-30 21:00:11 +00:00
|
|
|
endfunction()
|
|
|
|
|
|
|
|
|
|
functionaltest("hello-world")
|
2022-10-30 22:07:53 +00:00
|
|
|
functionaltest("factorial")
|
|
|
|
|
functionaltest("function-const-capture")
|
|
|
|
|
functionaltest("function-mutable-capture")
|
|
|
|
|
functionaltest("map")
|
|
|
|
|
functionaltest("deconstruct")
|
|
|
|
|
functionaltest("shadowing")
|
2022-10-30 22:08:41 +00:00
|
|
|
functionaltest("mathops")
|
2022-10-31 14:28:49 +00:00
|
|
|
functionaltest("len")
|
|
|
|
|
functionaltest("not")
|
|
|
|
|
functionaltest("type")
|
2022-10-31 14:50:51 +00:00
|
|
|
functionaltest("if")
|
2022-10-31 14:51:56 +00:00
|
|
|
functionaltest("while")
|
2022-11-04 20:51:31 +00:00
|
|
|
functionaltest("eq")
|
2022-11-19 20:27:08 +00:00
|
|
|
functionaltest("chained-assignments")
|
2022-11-19 21:06:23 +00:00
|
|
|
functionaltest("dictionary-assignments")
|
2022-11-19 22:14:09 +00:00
|
|
|
functionaltest("variadic-functions")
|
2022-11-19 22:20:22 +00:00
|
|
|
functionaltest("predicate")
|
2022-11-20 12:47:38 +00:00
|
|
|
functionaltest("compare")
|
2022-11-20 15:26:38 +00:00
|
|
|
functionaltest("concat")
|
|
|
|
|
functionaltest("join")
|
2023-03-03 21:25:25 +00:00
|
|
|
functionaltest("quine")
|
2022-09-16 21:04:20 +00:00
|
|
|
|
|
|
|
|
install(TARGETS apfl DESTINATION lib)
|
|
|
|
|
install(TARGETS apfl-bin DESTINATION bin)
|
|
|
|
|
install(FILES apfl.h DESTINATION include)
|