transioned to glib
This commit is contained in:
parent
330ffc3b2f
commit
858a6a3c4e
|
@ -1,3 +0,0 @@
|
||||||
[submodule "dep/klib"]
|
|
||||||
path = dep/klib
|
|
||||||
url = https://github.com/attractivechaos/klib.git
|
|
|
@ -71,25 +71,18 @@ add_custom_command(OUTPUT ${YACC_GENERATED_SOURCE_FILE}
|
||||||
VERBATIM)
|
VERBATIM)
|
||||||
|
|
||||||
# ------------------------------------------------ #
|
# ------------------------------------------------ #
|
||||||
# Klib #
|
# Setup Glib 2.0 #
|
||||||
# ------------------------------------------------ #
|
# ------------------------------------------------ #
|
||||||
|
|
||||||
file(GLOB KLIB_SOURCE_FILES ${PROJECT_SOURCE_DIR}/dep/klib/*.c)
|
find_package(PkgConfig REQUIRED)
|
||||||
|
pkg_search_module(GLIB REQUIRED IMPORTED_TARGET glib-2.0)
|
||||||
add_library(klib
|
|
||||||
STATIC
|
|
||||||
${KLIB_SOURCE_FILES})
|
|
||||||
|
|
||||||
set_target_properties(klib
|
|
||||||
PROPERTIES
|
|
||||||
ARCHIVE_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/dep)
|
|
||||||
|
|
||||||
# ------------------------------------------------ #
|
# ------------------------------------------------ #
|
||||||
# Source #
|
# Source #
|
||||||
# ------------------------------------------------ #
|
# ------------------------------------------------ #
|
||||||
|
|
||||||
include_directories(${PROJECT_SOURCE_DIR}/src)
|
include_directories(${PROJECT_SOURCE_DIR}/src)
|
||||||
include_directories(SYSTEM ${PROJECT_SOURCE_DIR}/dep)
|
include_directories(PRIVATE ${GLIB_INCLUDE_DIRS})
|
||||||
|
|
||||||
file(GLOB_RECURSE SOURCE_FILES src/*.c)
|
file(GLOB_RECURSE SOURCE_FILES src/*.c)
|
||||||
|
|
||||||
|
@ -114,7 +107,7 @@ set_target_properties(release
|
||||||
OUTPUT_NAME "gsc"
|
OUTPUT_NAME "gsc"
|
||||||
RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/release)
|
RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/release)
|
||||||
|
|
||||||
target_link_libraries(release klib)
|
target_link_libraries(release PkgConfig::GLIB)
|
||||||
|
|
||||||
# FIXME: cannot compile with /O2 because of /RTC1 flag
|
# FIXME: cannot compile with /O2 because of /RTC1 flag
|
||||||
if (MSVC)
|
if (MSVC)
|
||||||
|
@ -148,7 +141,7 @@ set_target_properties(debug
|
||||||
OUTPUT_NAME "gsc"
|
OUTPUT_NAME "gsc"
|
||||||
RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/debug)
|
RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/debug)
|
||||||
|
|
||||||
target_link_libraries(debug klib)
|
target_link_libraries(debug PkgConfig::GLIB)
|
||||||
|
|
||||||
if (MSVC)
|
if (MSVC)
|
||||||
set(DEBUG_FLAGS /DEBUG)
|
set(DEBUG_FLAGS /DEBUG)
|
||||||
|
@ -179,7 +172,7 @@ set_target_properties(check
|
||||||
OUTPUT_NAME "gsc"
|
OUTPUT_NAME "gsc"
|
||||||
RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/check)
|
RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/check)
|
||||||
|
|
||||||
target_link_libraries(check klib)
|
target_link_libraries(check PkgConfig::GLIB)
|
||||||
|
|
||||||
if (MSVC)
|
if (MSVC)
|
||||||
set(CHECK_FLAGS /DEBUG /WX)
|
set(CHECK_FLAGS /DEBUG /WX)
|
||||||
|
|
|
@ -5,7 +5,6 @@ LABEL description="docker image for setting up the build pipeline on SDK"
|
||||||
LABEL website="https://github.com/Servostar/gemstone"
|
LABEL website="https://github.com/Servostar/gemstone"
|
||||||
|
|
||||||
COPY --chown=lorang src /home/lorang/src
|
COPY --chown=lorang src /home/lorang/src
|
||||||
COPY --chown=lorang dep /home/lorang/dep
|
|
||||||
COPY --chown=lorang tests /home/lorang/tests
|
COPY --chown=lorang tests /home/lorang/tests
|
||||||
COPY --chown=lorang CMakeLists.txt /home/lorang/
|
COPY --chown=lorang CMakeLists.txt /home/lorang/
|
||||||
COPY --chown=lorang run-check-test.sh /home/lorang/
|
COPY --chown=lorang run-check-test.sh /home/lorang/
|
||||||
|
|
1
dep/klib
1
dep/klib
|
@ -1 +0,0 @@
|
||||||
Subproject commit 4988b65b9c90473d155268c8ee15f3aad546406b
|
|
|
@ -9,6 +9,8 @@ echo "+--------------------------------------+"
|
||||||
echo "| BUILDING all TARGETS |"
|
echo "| BUILDING all TARGETS |"
|
||||||
echo "+--------------------------------------+"
|
echo "+--------------------------------------+"
|
||||||
|
|
||||||
|
cmake .
|
||||||
|
|
||||||
make -B
|
make -B
|
||||||
if [ ! $? -eq 0 ]; then
|
if [ ! $? -eq 0 ]; then
|
||||||
echo "===> failed to build targets"
|
echo "===> failed to build targets"
|
||||||
|
|
|
@ -5,7 +5,7 @@ LABEL description="base image for building the gemstone programming language com
|
||||||
LABEL website="https://github.com/Servostar/gemstone"
|
LABEL website="https://github.com/Servostar/gemstone"
|
||||||
|
|
||||||
# install dependencies
|
# install dependencies
|
||||||
RUN apk add build-base gcc make cmake bison flex git python3 graphviz zlib zlib-dev curl-dev
|
RUN apk add build-base gcc make cmake bison flex git python3 graphviz glib glib-dev
|
||||||
|
|
||||||
# create user for build
|
# create user for build
|
||||||
RUN adduser --disabled-password lorang
|
RUN adduser --disabled-password lorang
|
||||||
|
|
|
@ -9,4 +9,4 @@ set(CTEST_BINARY_DIRECTORY ${PROJECT_BINARY_DIR}/tests)
|
||||||
add_subdirectory(logging)
|
add_subdirectory(logging)
|
||||||
add_subdirectory(input_file)
|
add_subdirectory(input_file)
|
||||||
add_subdirectory(ast)
|
add_subdirectory(ast)
|
||||||
add_subdirectory(klib)
|
add_subdirectory(glib)
|
|
@ -0,0 +1,22 @@
|
||||||
|
include(CTest)
|
||||||
|
|
||||||
|
include_directories(${PROJECT_SOURCE_DIR}/src)
|
||||||
|
include_directories(PRIVATE ${GLIB_INCLUDE_DIRS})
|
||||||
|
|
||||||
|
find_package(PkgConfig REQUIRED)
|
||||||
|
pkg_search_module(GLIB REQUIRED IMPORTED_TARGET glib-2.0)
|
||||||
|
|
||||||
|
# ------------------------------------------------------- #
|
||||||
|
# CTEST 1
|
||||||
|
# test Glib's hashmap
|
||||||
|
|
||||||
|
add_executable(glib_hashmap
|
||||||
|
glib_hashmap.c)
|
||||||
|
set_target_properties(glib_hashmap
|
||||||
|
PROPERTIES
|
||||||
|
OUTPUT_NAME "glib_hashmap"
|
||||||
|
RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/tests/glib)
|
||||||
|
target_link_libraries(glib_hashmap PkgConfig::GLIB)
|
||||||
|
add_test(NAME glib_hashmap
|
||||||
|
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
||||||
|
COMMAND ${GEMSTONE_BINARY_DIR}/tests/glib/glib_hashmap)
|
|
@ -0,0 +1,27 @@
|
||||||
|
|
||||||
|
#include <glib.h>
|
||||||
|
|
||||||
|
int main(int argc, char* argv[]) {
|
||||||
|
|
||||||
|
GHashTable* map = g_hash_table_new(g_str_hash, g_str_equal);
|
||||||
|
|
||||||
|
for (int i = 0; i < argc; i++) {
|
||||||
|
int* index = malloc(sizeof(int));
|
||||||
|
|
||||||
|
*index = i;
|
||||||
|
|
||||||
|
g_hash_table_insert(map, argv[i], &index);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < argc; i++) {
|
||||||
|
int* index = (int*) g_hash_table_lookup(map, argv[i]);
|
||||||
|
|
||||||
|
g_hash_table_remove(map, argv[i]);
|
||||||
|
|
||||||
|
free(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_hash_table_destroy(map);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -1,20 +0,0 @@
|
||||||
include(CTest)
|
|
||||||
|
|
||||||
include_directories(SYSTEM ${PROJECT_SOURCE_DIR}/dep)
|
|
||||||
include_directories(${PROJECT_SOURCE_DIR}/src)
|
|
||||||
|
|
||||||
# ------------------------------------------------------- #
|
|
||||||
# CTEST 1
|
|
||||||
# test build configuration and dependency of Klib
|
|
||||||
|
|
||||||
add_executable(klib_hashmap
|
|
||||||
hashmap.c)
|
|
||||||
set_target_properties(klib_hashmap
|
|
||||||
PROPERTIES
|
|
||||||
OUTPUT_NAME "klib_hashmap"
|
|
||||||
RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/tests/klib)
|
|
||||||
target_link_libraries(klib_hashmap klib)
|
|
||||||
target_compile_options(klib_hashmap PUBLIC -Wall -Wextra -Wpedantic -Werror)
|
|
||||||
add_test(NAME klib_hashmap
|
|
||||||
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
|
||||||
COMMAND ${GEMSTONE_BINARY_DIR}/tests/klib/klib_hashmap)
|
|
|
@ -1,36 +0,0 @@
|
||||||
|
|
||||||
#include <klib/khash.h>
|
|
||||||
|
|
||||||
struct Book {
|
|
||||||
const char* author;
|
|
||||||
size_t pages;
|
|
||||||
};
|
|
||||||
|
|
||||||
KHASH_MAP_INIT_STR(books, struct Book)
|
|
||||||
|
|
||||||
void put(const char* key, const struct Book book, khash_t(books)* books) {
|
|
||||||
khint_t idx;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
idx = kh_put(books, books, key, &ret);
|
|
||||||
|
|
||||||
if (!ret)
|
|
||||||
kh_del(books, books, idx);
|
|
||||||
|
|
||||||
kh_value(books, idx) = book;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(void) {
|
|
||||||
|
|
||||||
khash_t(books) *map = kh_init(books);
|
|
||||||
|
|
||||||
struct Book book;
|
|
||||||
book.author = "Bob";
|
|
||||||
book.pages = 45;
|
|
||||||
|
|
||||||
put("Pharao of Egypt", book, map);
|
|
||||||
|
|
||||||
kh_destroy(books, map);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
Loading…
Reference in New Issue