├── .gitignore ├── .travis.yml ├── CMakeLists.txt ├── Dockerfile ├── LICENSE ├── README.md ├── cmake └── modules │ ├── FindLibClang.cmake │ ├── FindNUMA.cmake │ └── templates.cmake ├── figures ├── furious.png ├── furious.svg ├── tables.png ├── tables.svg ├── traditional.png └── traditional.svg ├── fixup.sh └── src ├── CMakeLists.txt ├── common ├── bitmap.c ├── bitmap.h ├── btree.c ├── btree.h ├── common.h ├── deprecated │ ├── btree.h │ ├── btree.inl │ ├── refcount_ptr.h │ └── refcount_ptr.inl ├── hashtable.c ├── hashtable.h ├── memory │ ├── memory.c │ ├── memory.h │ ├── numa_alloc.c │ ├── numa_alloc.h │ ├── page_allocator.c │ ├── page_allocator.h │ ├── pool_allocator.c │ ├── pool_allocator.h │ ├── stack_allocator.c │ └── stack_allocator.h ├── mutex.c ├── mutex.h ├── platform.c ├── platform.h ├── str_builder.c ├── str_builder.h ├── templates │ ├── array.cpp.in │ └── array.h.in ├── thread.c ├── thread.h ├── types.h ├── utils.c └── utils.h ├── compiler ├── CMakeLists.txt ├── backend │ ├── codegen.cpp │ ├── codegen.h │ ├── codegen_tools.cpp │ ├── codegen_tools.h │ ├── consumer.cpp │ ├── consumer.h │ ├── producer.cpp │ ├── producer.h │ ├── reflection.cpp │ └── reflection.h ├── driver.h ├── drivers │ └── clang │ │ ├── ast_visitor.cpp │ │ ├── ast_visitor.h │ │ ├── clang.cpp │ │ ├── clang.h │ │ ├── clang_parsing.cpp │ │ ├── clang_parsing.h │ │ ├── clang_reflection.cpp │ │ ├── clang_tools.cpp │ │ └── clang_tools.h ├── dyn_array.h ├── dyn_array.inl ├── fcc.cpp ├── fcc_context.cpp ├── fcc_context.h └── frontend │ ├── exec_plan.cpp │ ├── exec_plan.h │ ├── exec_plan_printer.cpp │ ├── exec_plan_printer.h │ ├── operator.cpp │ ├── operator.h │ ├── transforms.cpp │ └── transforms.h ├── components.h ├── furious.c ├── furious.h ├── furious_macros.h ├── lang ├── lang.h └── macros.h ├── lang_test.cpp ├── lang_test.h ├── runtime ├── data │ ├── bittable.c │ ├── bittable.h │ ├── block_cluster.c │ ├── block_cluster.h │ ├── context.c │ ├── context.h │ ├── context.inl │ ├── data.h │ ├── data_utils.c │ ├── data_utils.h │ ├── database.c │ ├── database.h │ ├── deprecated │ │ ├── entity.cpp │ │ ├── entity.h │ │ ├── entity.inl │ │ ├── table_view.h │ │ └── table_view.inl │ ├── ht_registry.c │ ├── ht_registry.h │ ├── macros.h │ ├── reflection.c │ ├── reflection.h │ ├── reftable.c │ ├── reftable.h │ ├── table.c │ ├── table.h │ ├── tx │ │ ├── tx.c │ │ ├── tx.h │ │ ├── txbtree.c │ │ ├── txbtree.h │ │ ├── txpool_allocator.c │ │ └── txpool_allocator.h │ └── webserver │ │ ├── webserver.c │ │ └── webserver.h ├── deprecated │ ├── system_wrapper.h │ └── system_wrapper.inl ├── log │ ├── log.c │ └── log.h ├── runtime.h └── task │ ├── task.c │ └── task.h └── test ├── compiler ├── CMakeLists.txt ├── basic_test.cpp ├── basic_test_header.h ├── basic_test_script.cpp ├── dependency_test.cpp ├── dependency_test_header.h ├── dependency_test_script.cpp ├── expand_test.cpp ├── expand_test_header.h ├── expand_test_script.cpp ├── filter_func_test.cpp ├── filter_func_test_header.h ├── filter_func_test_script.cpp ├── filter_lambda_test.cpp ├── filter_lambda_test_header.h ├── filter_lambda_test_script.cpp ├── filter_tag_test.cpp ├── filter_tag_test_header.h ├── filter_tag_test_script.cpp ├── global_test.cpp ├── global_test_header.h ├── global_test_script.cpp ├── reflection_test.cpp ├── reflection_test_header.h └── reflection_test_script.cpp └── runtime ├── CMakeLists.txt ├── bitmap_test.cpp ├── bittable_test.cpp ├── blockcluster_test.cpp ├── btree_test.cpp ├── database_test.cpp ├── dyn_array_test.cpp ├── hashtable_test.cpp ├── memory_test.cpp ├── page_alloc_test.cpp ├── pool_alloc_test.cpp ├── refs_test.cpp ├── stack_alloc_test.cpp ├── table_test.cpp ├── tags_test.cpp └── txpool_alloc_test.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | 34 | # Autogenerated 35 | src/compiler/autogen* 36 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: required 2 | language: cpp 3 | addons: 4 | apt: 5 | sources: 6 | - llvm-toolchain-trusty-4.0 7 | packages: 8 | - clang-tidy-4.0 9 | services: 10 | - docker 11 | before_install: 12 | - docker build -t furious . 13 | - docker run -itd --name build furious 14 | script: 15 | - docker exec build cmake . 16 | - docker exec build make 17 | - docker exec build make runtime_tests 18 | - docker exec build make compiler_tests 19 | #env: 20 | # global: 21 | # - secure: l2EkyEM2GdDVsndhyRkzj8vrt3wzVJQHZEK2YzqOROdo3hRa4JoMZOl01FDmjOHfb6MEIEe1mpRy6JBIAKAm5hcXT9hli2DlF9YHcg6SGFdPpkpFLMa7A3uuAwErR+1xy2WGWotq1QthtIekzayAySMmil9RC3zsw6u6K8zGuAdT6elrBiLodbdt2051aszCfBMrQF00lxYUaj9ePx/20QLeh+n2t2vyaKJ3Igau/UwvQS1stlV8jPc2+MwB3vhzhHMzmomlfNIhUtsLaHkkiLeaDUL+MRDRP5lORnP20qD5jxT6SjhMN/rROnMiWUtwuXYZbPzfsMPaLTXIesmicfB3nrjYaXKjhQakljz/P2cC3HTt+gFdHupUcyr7HrNU834yQ/5pN4b9ZtihApItfUZEcR39z/KedKsnDF8mYfdcegQhcUQSGzWwmTlqVTWlPhX4/sPJ8lNgZwa902FkyMmK3D5GxupM7MRyc4qBkYhWpgYiP/WDQVZeZ/kwXg9t/SWHj7Qa7IXc2yvwhWaHHmRDNGX2saQPnhijs0GkOvBpKcUpKBFiNuGy+bfDyaR6F0Hrb9LwEGRDP8VXxHtHQ47elZzGJI1COgpFszVThV2nPkBOpeLEf3R2GpsMbt7EknrZBMeK+yjprXMazoHK7MWXaUpY0aPWYYH+KYsvDOU= 22 | # 23 | #after_script: 24 | # - docker exec build . 25 | # - docker exec build make tidy-runtime 26 | # - docker exec build git diff > tidy.patch 27 | # - ./fixup.sh 28 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | CMAKE_MINIMUM_REQUIRED (VERSION 2.8) 2 | PROJECT( furious ) 3 | 4 | set( CMAKE_EXPORT_COMPILE_COMMANDS 1 ) 5 | 6 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) 7 | message(STATUS "Setting build type to 'RELEASE' as none was specified.") 8 | set(CMAKE_BUILD_TYPE RELEASE) 9 | endif() 10 | 11 | set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules/;${CMAKE_MODULE_PATH}") 12 | 13 | ## Checking for required packages 14 | 15 | find_package(LLVM REQUIRED CONFIG) 16 | set(LIBCLANG_INCLUDES_DIR "${LLVM_INCLUDE_DIR}") 17 | set(LLVM_INCLUDES_DIR "${LLVM_INCLUDE_DIR}") 18 | set(LIBCLANG_LIBS_DIR "${LLVM_LIBRARY_DIRS}") 19 | set(LIBCLANG_LIBS 20 | "${LIBCLANG_LIBS_DIR}/libclang.so" 21 | "${LIBCLANG_LIBS_DIR}/libclang-cpp.so.10") 22 | 23 | # Find the libraries that correspond to the LLVM components 24 | # that we wish to use 25 | llvm_map_components_to_libnames(LLVM_LIBS ) 26 | 27 | #find_package(LibClang REQUIRED) 28 | #if(NOT LIBCLANG_FOUND) 29 | # message(FATAL_ERROR "LibClang could not be found") 30 | #endif() 31 | # 32 | # 33 | #set(LIBCLANG_INCLUDES_DIR "${LIBCLANG_LIBDIR}/clang/${LIBCLANG_VERSION_STRING}/include") 34 | # 35 | #if(NOT LIBCLANG_INCLUDES_DIR) 36 | # message(FATAL_ERROR "Need to define folder with clang includes") 37 | #endif() 38 | # 39 | #set(LIBCLANG_LIBS ${LIBCLANG_LIBRARIES}) 40 | 41 | #set(CMAKE_INSTALL_PREFIX ${FURIOUS_INSTALL_PREFIX}) 42 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) 43 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) 44 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) 45 | 46 | 47 | 48 | set(CMAKE_CXX_FLAGS 49 | "${CMAKE_CXX_FLAGS} \ 50 | -std=c++11 \ 51 | -Wall \ 52 | -fno-rtti \ 53 | -fno-exceptions \ 54 | -fstrict-aliasing \ 55 | -Wstrict-aliasing") 56 | 57 | set(CMAKE_C_FLAGS 58 | "${CMAKE_C_FLAGS} \ 59 | -std=c99 \ 60 | -Wall \ 61 | -fstrict-aliasing") 62 | 63 | set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 -pg -ggdb") 64 | set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -pg -ggdb -std=c++17") 65 | #set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -g -pg -DNDEBUG -ftree-vectorize -ftree-vectorizer-verbose=7 -fopt-info-vec-all -fno-devirtualize ") 66 | set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3 -ggdb") 67 | set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -ggdb -std=c++17") 68 | 69 | IF(FDB_ENABLE_ASSERTS) 70 | set(FURIOUS_DEFAULT_DEFINES ${FURIOUS_DEFAULT_DEFINES} -DFDB_ENABLE_ASSERTS) 71 | ENDIF(FDB_ENABLE_ASSERTS) 72 | 73 | IF(FDB_DEBUG) 74 | set(FURIOUS_DEFAULT_DEFINES ${FURIOUS_DEFAULT_DEFINES} -DFDB_DEBUG) 75 | ENDIF(FDB_DEBUG) 76 | 77 | IF(UNIX) 78 | set(FURIOUS_DEFAULT_DEFINES 79 | ${FURIOUS_DEFAULT_DEFINES} 80 | "-DFDB_OS_LINUX" 81 | "-DFDB_COMPILER_GCC") 82 | ENDIF(UNIX) 83 | 84 | IF( WIN32 ) 85 | ENDIF(WIN32) 86 | 87 | add_definitions(${FURIOUS_DEFAULT_DEFINES}) 88 | set(FURIOUS_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) 89 | set(FURIOUS_OUTPUT_DIR "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/furious") 90 | 91 | enable_testing() 92 | 93 | if(NOT CXX_HEADERS_DIRS) 94 | message(FATAL_ERROR "CXX_HEADERS_DIRS is empty. Please set it to the list of 95 | paths where c++ headers are found") 96 | endif() 97 | 98 | message(STATUS "BUILD_TYPE: ${CMAKE_BUILD_TYPE}") 99 | message(STATUS "LLVM VERSION: ${LLVM_VERSION_MAJOR}") 100 | message(STATUS "LLVM INCLUDE DIRS: ${LLVM_INCLUDES_DIR}") 101 | message(STATUS "LLVM LIBS DIR: ${LLVM_LIBRARY_DIRS}") 102 | message(STATUS "LLVM LIBS: ${LLVM_LIBS}") 103 | message(STATUS "LLVM DEFINITIONS: ${LLVM_DEFINITIONS}") 104 | message(STATUS "LIBCLANG INCLUDE DIR: ${LIBCLANG_INCLUDES_DIR}") 105 | message(STATUS "LIBCLANG LIBS: ${LIBCLANG_LIBS}") 106 | message(STATUS "LIBCLANG LIBS DIR: ${LIBCLANG_LIBS_DIR}") 107 | message(STATUS "DEFINES: ${FURIOUS_DEFAULT_DEFINES}") 108 | message(STATUS "CXX_HEADERS_DIRS: ${CXX_HEADERS_DIRS}") 109 | 110 | add_subdirectory(src) 111 | 112 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM archlinux/base:latest 2 | MAINTAINER Arnau Prat 3 | CMD bash 4 | 5 | RUN mkdir -p /home/user 6 | WORKDIR /home/user 7 | 8 | ADD src ./src 9 | ADD CMakeLists.txt ./ 10 | ADD cmake ./cmake 11 | 12 | RUN mkdir build 13 | 14 | RUN pacman -Syy --noconfirm 15 | RUN pacman -S --noconfirm gcc cmake gtest numactl make clang llvm-libs llvm git 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /cmake/modules/FindNUMA.cmake: -------------------------------------------------------------------------------- 1 | # Module for locating libnuma 2 | # 3 | # Read-only variables: 4 | # NUMA_FOUND 5 | # Indicates that the library has been found. 6 | # 7 | # NUMA_INCLUDE_DIR 8 | # Points to the libnuma include directory. 9 | # 10 | # NUMA_LIBRARY_DIR 11 | # Points to the directory that contains the libraries. 12 | # The content of this variable can be passed to link_directories. 13 | # 14 | # NUMA_LIBRARY 15 | # Points to the libnuma that can be passed to target_link_libararies. 16 | # 17 | # Copyright (c) 2013-2017 MulticoreWare, Inc 18 | 19 | include(FindPackageHandleStandardArgs) 20 | 21 | find_path(NUMA_ROOT_DIR 22 | NAMES include/numa.h 23 | PATHS ENV NUMA_ROOT 24 | DOC "NUMA root directory") 25 | 26 | find_path(NUMA_INCLUDE_DIR 27 | NAMES numa.h 28 | HINTS ${NUMA_ROOT_DIR} 29 | PATH_SUFFIXES include 30 | DOC "NUMA include directory") 31 | 32 | find_library(NUMA_LIBRARY 33 | NAMES numa 34 | HINTS ${NUMA_ROOT_DIR} 35 | DOC "NUMA library") 36 | 37 | if (NUMA_LIBRARY) 38 | get_filename_component(NUMA_LIBRARY_DIR ${NUMA_LIBRARY} PATH) 39 | endif() 40 | 41 | mark_as_advanced(NUMA_INCLUDE_DIR NUMA_LIBRARY_DIR NUMA_LIBRARY) 42 | 43 | find_package_handle_standard_args(NUMA REQUIRED_VARS NUMA_ROOT_DIR 44 | NUMA_INCLUDE_DIR NUMA_LIBRARY) 45 | -------------------------------------------------------------------------------- /cmake/modules/templates.cmake: -------------------------------------------------------------------------------- 1 | 2 | 3 | function(GENERATE_ARRAY 4 | FDB_PREFIX 5 | FDB_TYPE 6 | FDB_FORWARD 7 | FDB_INCLUDE 8 | DST) 9 | string(TOUPPER ${FDB_PREFIX} FDB_GUARD) 10 | configure_file(${CMAKE_SOURCE_DIR}/src/common/templates/array.h.in 11 | ${DST}/${FDB_PREFIX}_array.h @ONLY) 12 | 13 | configure_file(${CMAKE_SOURCE_DIR}/src/common/templates/array.cpp.in 14 | ${DST}/${FDB_PREFIX}_array.cpp @ONLY) 15 | endfunction(GENERATE_ARRAY) 16 | -------------------------------------------------------------------------------- /figures/furious.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArnauPrat/furious/0275d82e8f7ee957dfd216920ce72bbdb8917bb7/figures/furious.png -------------------------------------------------------------------------------- /figures/tables.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArnauPrat/furious/0275d82e8f7ee957dfd216920ce72bbdb8917bb7/figures/tables.png -------------------------------------------------------------------------------- /figures/traditional.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArnauPrat/furious/0275d82e8f7ee957dfd216920ce72bbdb8917bb7/figures/traditional.png -------------------------------------------------------------------------------- /fixup.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [ "$TRAVIS_PULL_REQUEST" = false ] ; then 4 | echo 'Skipped build. This is not a pull request' 5 | exit 0 6 | fi 7 | 8 | if [ -z "$TRAVIS_REPO_SLUG" ] 9 | then 10 | echo "There is not TRAVIS_REPO_SLUG defined" 11 | exit 1 12 | fi 13 | 14 | if [ -z "$TRAVIS_PULL_REQUEST_SHA" ] 15 | then 16 | echo "There is not TRAVIS_PULL_REQUEST_SHA defined" 17 | exit 1 18 | fi 19 | 20 | if [ -z "$OCTOPATCH_API_TOKEN" ] ; then 21 | echo "There is not OCTOPATCH_API_TOKEN defined" 22 | exit 1 23 | fi 24 | 25 | REQUEST="curl -X POST -H \"Content-Type: multipart/form-data\"" 26 | FILES=$(find . -type f -name "*.patch") 27 | if [ -z "$FILES" ] 28 | then 29 | echo "Perfect! There are not patch files" 30 | exit 0 31 | fi 32 | 33 | for FILE in $FILES 34 | do 35 | REQUEST+=" -F \"data=@$FILE\"" 36 | done 37 | 38 | REQUEST+=" -H \"Authorization: $OCTOPATCH_API_TOKEN\" api.octopatch.io/api/pulls/$TRAVIS_REPO_SLUG/$TRAVIS_PULL_REQUEST/$TRAVIS_PULL_REQUEST_SHA" 39 | eval $REQUEST -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | include_directories(./) 3 | 4 | set (COMMON_SRC 5 | ${CMAKE_SOURCE_DIR}/src/common/memory/memory.h 6 | ${CMAKE_SOURCE_DIR}/src/common/memory/memory.c 7 | ${CMAKE_SOURCE_DIR}/src/common/memory/numa_alloc.c 8 | ${CMAKE_SOURCE_DIR}/src/common/memory/numa_alloc.h 9 | ${CMAKE_SOURCE_DIR}/src/common/memory/pool_allocator.c 10 | ${CMAKE_SOURCE_DIR}/src/common/memory/pool_allocator.h 11 | ${CMAKE_SOURCE_DIR}/src/common/memory/page_allocator.c 12 | ${CMAKE_SOURCE_DIR}/src/common/memory/page_allocator.h 13 | ${CMAKE_SOURCE_DIR}/src/common/memory/stack_allocator.c 14 | ${CMAKE_SOURCE_DIR}/src/common/memory/stack_allocator.h 15 | ${CMAKE_SOURCE_DIR}/src/common/mutex.h 16 | ${CMAKE_SOURCE_DIR}/src/common/mutex.c 17 | #${CMAKE_SOURCE_DIR}/src/common/refcount_ptr.h 18 | #${CMAKE_SOURCE_DIR}/src/common/refcount_ptr.inl 19 | #${CMAKE_SOURCE_DIR}/src/common/dyn_array.h 20 | #${CMAKE_SOURCE_DIR}/src/common/dyn_array.inl 21 | ${CMAKE_SOURCE_DIR}/src/common/bitmap.c 22 | ${CMAKE_SOURCE_DIR}/src/common/bitmap.h 23 | ${CMAKE_SOURCE_DIR}/src/common/btree.h 24 | ${CMAKE_SOURCE_DIR}/src/common/btree.c 25 | ${CMAKE_SOURCE_DIR}/src/common/common.h 26 | ${CMAKE_SOURCE_DIR}/src/common/platform.h 27 | ${CMAKE_SOURCE_DIR}/src/common/platform.c 28 | #${CMAKE_SOURCE_DIR}/src/common/reference.h 29 | ${CMAKE_SOURCE_DIR}/src/common/hashtable.c 30 | ${CMAKE_SOURCE_DIR}/src/common/hashtable.h 31 | ${CMAKE_SOURCE_DIR}/src/common/str_builder.c 32 | ${CMAKE_SOURCE_DIR}/src/common/str_builder.h 33 | ${CMAKE_SOURCE_DIR}/src/common/types.h 34 | ${CMAKE_SOURCE_DIR}/src/common/utils.c 35 | ${CMAKE_SOURCE_DIR}/src/common/utils.h 36 | ${CMAKE_SOURCE_DIR}/src/common/thread.h 37 | ${CMAKE_SOURCE_DIR}/src/common/thread.c 38 | ) 39 | 40 | set (RUNTIME_SRC 41 | ${CMAKE_SOURCE_DIR}/src/runtime/data/tx/txpool_allocator.h 42 | ${CMAKE_SOURCE_DIR}/src/runtime/data/tx/txpool_allocator.c 43 | ${CMAKE_SOURCE_DIR}/src/runtime/data/tx/tx.h 44 | ${CMAKE_SOURCE_DIR}/src/runtime/data/tx/tx.c 45 | ${CMAKE_SOURCE_DIR}/src/runtime/data/bittable.c 46 | ${CMAKE_SOURCE_DIR}/src/runtime/data/bittable.h 47 | ${CMAKE_SOURCE_DIR}/src/runtime/data/block_cluster.c 48 | ${CMAKE_SOURCE_DIR}/src/runtime/data/block_cluster.h 49 | ${CMAKE_SOURCE_DIR}/src/runtime/data/context.c 50 | ${CMAKE_SOURCE_DIR}/src/runtime/data/context.h 51 | ${CMAKE_SOURCE_DIR}/src/runtime/data/data.h 52 | ${CMAKE_SOURCE_DIR}/src/runtime/data/data_utils.c 53 | ${CMAKE_SOURCE_DIR}/src/runtime/data/data_utils.h 54 | ${CMAKE_SOURCE_DIR}/src/runtime/data/reflection.c 55 | ${CMAKE_SOURCE_DIR}/src/runtime/data/reflection.h 56 | ${CMAKE_SOURCE_DIR}/src/runtime/data/database.c 57 | ${CMAKE_SOURCE_DIR}/src/runtime/data/database.h 58 | #${CMAKE_SOURCE_DIR}/src/runtime/data/entity.c 59 | #${CMAKE_SOURCE_DIR}/src/runtime/data/entity.h 60 | #${CMAKE_SOURCE_DIR}/src/runtime/data/entity.inl 61 | ${CMAKE_SOURCE_DIR}/src/runtime/data/ht_registry.c 62 | ${CMAKE_SOURCE_DIR}/src/runtime/data/ht_registry.h 63 | ${CMAKE_SOURCE_DIR}/src/runtime/data/macros.h 64 | ${CMAKE_SOURCE_DIR}/src/runtime/data/table.c 65 | ${CMAKE_SOURCE_DIR}/src/runtime/data/table.h 66 | ${CMAKE_SOURCE_DIR}/src/runtime/data/reftable.c 67 | ${CMAKE_SOURCE_DIR}/src/runtime/data/reftable.h 68 | #${CMAKE_SOURCE_DIR}/src/runtime/data/table_view.h 69 | #${CMAKE_SOURCE_DIR}/src/runtime/data/table_view.inl 70 | ${CMAKE_SOURCE_DIR}/src/runtime/data/webserver/webserver.h 71 | ${CMAKE_SOURCE_DIR}/src/runtime/data/webserver/webserver.c 72 | ${CMAKE_SOURCE_DIR}/src/runtime/runtime.h 73 | #${CMAKE_SOURCE_DIR}/src/runtime/system_wrapper.h 74 | #${CMAKE_SOURCE_DIR}/src/runtime/system_wrapper.inl 75 | ${CMAKE_SOURCE_DIR}/src/runtime/task/task.h 76 | ${CMAKE_SOURCE_DIR}/src/runtime/task/task.c 77 | ${CMAKE_SOURCE_DIR}/src/runtime/log/log.c 78 | ) 79 | 80 | 81 | add_library(furious SHARED 82 | furious.h 83 | furious.c 84 | ${COMMON_SRC} 85 | ${RUNTIME_SRC} 86 | ) 87 | 88 | target_link_libraries(furious 89 | pthread) 90 | 91 | #set_property(TARGET furious PROPERTY POSITION_INDEPENDENT_CODE ON) 92 | 93 | set_target_properties(furious 94 | PROPERTIES 95 | RUNTIME_OUTPUT_DIRECTORY ${FURIOUS_OUTPUT_DIR} 96 | LIBRARY_OUTPUT_DIRECTORY ${FURIOUS_OUTPUT_DIR} 97 | ARCHIVE_OUTPUT_DIRECTORY ${FURIOUS_OUTPUT_DIR} 98 | ) 99 | 100 | ###################### 101 | #### FCC COMPILER #### 102 | ###################### 103 | 104 | add_subdirectory(./compiler) 105 | 106 | ####################### 107 | ####### TESTS ####### 108 | ####################### 109 | 110 | add_subdirectory(./test/runtime) 111 | add_subdirectory(./test/compiler) 112 | 113 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17") 114 | add_executable(lang_test 115 | lang_test.cpp 116 | ) 117 | 118 | SET(FURIOUS_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR} PARENT_SCOPE) 119 | 120 | install (TARGETS furious 121 | RUNTIME DESTINATION bin 122 | LIBRARY DESTINATION lib) 123 | 124 | install(DIRECTORY ${CMAKE_SOURCE_DIR}/src/common ${CMAKE_SOURCE_DIR}/src/runtime 125 | DESTINATION include/furious 126 | FILES_MATCHING PATTERN "*.h" 127 | ) 128 | -------------------------------------------------------------------------------- /src/common/bitmap.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _FDB_BITMAP_H_ 3 | #define _FDB_BITMAP_H_ 4 | 5 | #include "types.h" 6 | #include "platform.h" 7 | #include "memory/memory.h" 8 | 9 | #include 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | #define FDB_BITMAP_ALIGNMENT 64 16 | #define FDB_BITMAP_NUM_CHUNKS(bits) (bits + 7) / 8 17 | 18 | typedef struct fdb_bitmap_t 19 | { 20 | uint32_t m_max_bits; //< The maximum number of bits 21 | uint32_t m_num_set; //< The number of bits set to one 22 | FDB_ALIGNED(uint8_t*,p_data,FDB_BITMAP_ALIGNMENT); //< The buffer with the bitmap 23 | } fdb_bitmap_t; 24 | 25 | /** 26 | * \brief Initializes a bitmap 27 | * 28 | * \return The initd bitmap 29 | */ 30 | 31 | void 32 | fdb_bitmap_init(fdb_bitmap_t* bitmap, 33 | uint32_t max_bits, 34 | fdb_mem_allocator_t* allocator); 35 | 36 | /** 37 | * \brief Releases a bitmap 38 | * 39 | * \param bitmap 40 | */ 41 | 42 | void 43 | fdb_bitmap_release(fdb_bitmap_t* bitmap, fdb_mem_allocator_t* allocator); 44 | 45 | /** 46 | * \brief Sets to one the ith element of the bitmap 47 | * 48 | * \param bitmap The bitmap to perform the operation 49 | * \param element The element to set 50 | */ 51 | 52 | void 53 | fdb_bitmap_set(fdb_bitmap_t* bitmap, 54 | uint32_t element); 55 | 56 | /** 57 | * \brief Sets to 0 the ith element of the bitmap 58 | * 59 | * \param bitmap The bitmap to perform the operation 60 | * \param element The ith element to set 61 | */ 62 | 63 | void 64 | fdb_bitmap_unset(fdb_bitmap_t* bitmap, 65 | uint32_t element); 66 | 67 | /** 68 | * \brief Sets the bit of the given element to the specified value 69 | * 70 | * \param bitmap The bitmap to perform the operation 71 | * \param element The element to set the bit for 72 | * \param value The value to set the bit to 73 | */ 74 | 75 | void 76 | fdb_bitmap_set_bit(fdb_bitmap_t* bitmap, 77 | uint32_t element, 78 | bool value); 79 | 80 | /** 81 | * \brief Checks if a given element is set to 1 82 | * 83 | * \param bitmap The bitmap to perform the operation 84 | * \param element The element to check 85 | * 86 | * \return True if the element is set to 1 87 | */ 88 | 89 | bool 90 | fdb_bitmap_is_set(const fdb_bitmap_t* bitmap, 91 | uint32_t element); 92 | 93 | /** 94 | * \brief Sets the bits based on the given bitmap 95 | * 96 | * \param dst_bitmap The bitmap to set the bits to 97 | * \param src_bitmap The bitmap to set the bits from 98 | */ 99 | 100 | void 101 | fdb_bitmap_set_bitmap(FDB_RESTRICT(fdb_bitmap_t*) dst_bitmap, 102 | FDB_RESTRICT(const fdb_bitmap_t*) src_bitmap); 103 | 104 | /** 105 | * \brief Ands this bitmap with the given bitmap 106 | * 107 | * \param dst_bitmap The bitmap to set the bits to 108 | * \param src_bitmap The bitmap to set the bits from 109 | */ 110 | 111 | void 112 | fdb_bitmap_set_and(fdb_bitmap_t* dst_bitmap, 113 | const fdb_bitmap_t* src_bitmap); 114 | 115 | /** 116 | * \brief Ors this bitmap with the given bitmap 117 | * 118 | * \param dst_bitmap The bitmap to set the bits to 119 | * \param src_bitmap The bitmap to set the bits from 120 | */ 121 | 122 | void 123 | fdb_bitmap_set_or(fdb_bitmap_t* dst_bitmap, 124 | const fdb_bitmap_t* src_bitmap); 125 | 126 | /** 127 | * \brief Diffs this bitmap with the given bitmap 128 | * 129 | * \param dst_bitmap The bitmap to set the bits to 130 | * \param src_bitmap The bitmap to set the bits from 131 | */ 132 | 133 | void 134 | fdb_bitmap_set_diff(fdb_bitmap_t* dst_bitmap, 135 | const fdb_bitmap_t* src_bitmap); 136 | 137 | /** 138 | * \brief Negates the contents of this bitmap 139 | * 140 | * \param bitmap The bitmap to set the bits to 141 | */ 142 | 143 | void 144 | fdb_bitmap_negate(fdb_bitmap_t* bitmap); 145 | 146 | /** 147 | * \brief Sets the bitmap to all zeros 148 | * 149 | * \param bitmap The bitmap to nullify 150 | */ 151 | void 152 | fdb_bitmap_nullify(fdb_bitmap_t* bitmap); 153 | 154 | #ifdef __cplusplus 155 | } 156 | #endif 157 | 158 | #endif /* ifndef _FDB_BITMAP_H_ */ 159 | -------------------------------------------------------------------------------- /src/common/common.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _FURIOUS_COMMON_H_ 3 | #define _FURIOUS_COMMON_H_ 4 | 5 | #include "types.h" 6 | #include "platform.h" 7 | #include "utils.h" 8 | #include "memory/memory.h" 9 | #include "memory/pool_allocator.h" 10 | #include "memory/stack_allocator.h" 11 | #include "hashtable.h" 12 | #include "thread.h" 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /src/common/deprecated/btree.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef _FURIOUS_BTREE_H_ 4 | #define _FURIOUS_BTREE_H_ value 5 | 6 | #include "types.h" 7 | #include "impl/btree_impl.h" 8 | 9 | #include 10 | 11 | namespace furious 12 | { 13 | 14 | template 15 | struct BTree 16 | { 17 | struct Entry 18 | { 19 | uint32_t m_key; 20 | T* p_value; 21 | }; 22 | 23 | struct Iterator 24 | { 25 | public: 26 | Iterator(btree_t* root); 27 | ~Iterator(); 28 | 29 | bool 30 | has_next() const; 31 | 32 | Entry 33 | next(); 34 | 35 | private: 36 | mutable btree_iter_t m_iterator; 37 | }; 38 | 39 | BTree(mem_allocator_t* allocator = nullptr); 40 | BTree(const BTree&) = delete; 41 | BTree(BTree&&) = delete; 42 | ~BTree(); 43 | 44 | void operator=(const BTree&) = delete; 45 | void operator=(BTree&&) = delete; 46 | 47 | //////////////////////////////////////////////// 48 | //////////////////////////////////////////////// 49 | //////////////////////////////////////////////// 50 | 51 | 52 | /** 53 | * \brief Inserts an element to the btree. Replaces the element if this 54 | * already existed 55 | * 56 | * \param key The key of the element to add 57 | * \param element A pointer to the element to insert 58 | * 59 | * \return Returns a pointer to the inserted element or nullptr otherwise. 60 | */ 61 | T* 62 | insert_copy(uint32_t key, const T* element); 63 | 64 | 65 | template 66 | T* 67 | insert_new(uint32_t key, Args &&... args); 68 | 69 | 70 | /** 71 | * \brief Removes an element from the tree 72 | * 73 | * \param key The key of the element to remove 74 | * 75 | */ 76 | void 77 | remove(uint32_t key); 78 | 79 | /** 80 | * \brief Gets the element with the given key 81 | * 82 | * \param key The key of the element to search for 83 | * 84 | * \return Returns a pointer to the element with the given key. nullptr if it 85 | * does not exist 86 | */ 87 | T* 88 | get(uint32_t key) const; 89 | 90 | /** 91 | * \brief Checks if an element exists 92 | * 93 | * \param key The key to of the element to look for 94 | * 95 | * \return Retursn true if the element exists. false otherwise 96 | */ 97 | bool 98 | exists(uint32_t key); 99 | 100 | /** 101 | * \brief Gets the size of the btree (i.e. the number of elements) 102 | * 103 | * \return Returns the size of the btree 104 | */ 105 | size_t 106 | size() const; 107 | 108 | /** 109 | * \brief Gets an iterator to the btree 110 | * 111 | * \return Returns an iterator to the btree 112 | */ 113 | Iterator 114 | iterator() const; 115 | 116 | /** 117 | * brief Clears the btree 118 | */ 119 | void clear(); 120 | 121 | private: 122 | btree_t* p_root; 123 | size_t m_size; 124 | mem_allocator_t m_allocator; 125 | }; 126 | 127 | } /* furious */ 128 | 129 | #include "btree.inl" 130 | #endif /* ifndef _FURIOUS_BTREE_H_ */ 131 | -------------------------------------------------------------------------------- /src/common/deprecated/btree.inl: -------------------------------------------------------------------------------- 1 | 2 | #include "impl/btree_impl.h" 3 | #include 4 | #include 5 | #include 6 | #include "memory/memory.h" 7 | #include "platform.h" 8 | 9 | namespace furious { 10 | 11 | 12 | template 13 | BTree::BTree(mem_allocator_t* allocator) : 14 | p_root(nullptr), 15 | m_size(0) 16 | { 17 | FURIOUS_ASSERT(((allocator == nullptr) || 18 | (allocator->p_mem_alloc != nullptr && allocator->p_mem_free != nullptr)) && 19 | "Provided allocator is ill-formed.") 20 | 21 | if(allocator != nullptr) 22 | { 23 | m_allocator = *allocator; 24 | } 25 | else 26 | { 27 | m_allocator = global_mem_allocator; 28 | } 29 | 30 | p_root = (btree_t*) mem_alloc(&m_allocator, 31 | 1, 32 | sizeof(btree_t), 33 | -1); 34 | *p_root = btree_create(); 35 | 36 | } 37 | 38 | template 39 | BTree::~BTree() 40 | { 41 | if(p_root != nullptr) 42 | { 43 | BTree::Iterator it = iterator(); 44 | while(it.has_next()) 45 | { 46 | T* value = it.next().p_value; 47 | value->~T(); 48 | mem_free(&m_allocator, 49 | value); 50 | m_size--; 51 | } 52 | btree_destroy(p_root); 53 | mem_free(&m_allocator, 54 | p_root); 55 | p_root = nullptr; 56 | } 57 | } 58 | 59 | template 60 | void 61 | BTree::clear() 62 | { 63 | BTree::Iterator it = iterator(); 64 | while(it.has_next()) 65 | { 66 | T* value = it.next().p_value; 67 | value->~T(); 68 | mem_free(&m_allocator, 69 | value); 70 | } 71 | btree_destroy(p_root); 72 | mem_free(&m_allocator, 73 | p_root); 74 | p_root = (btree_t*)mem_alloc(&m_allocator, 75 | 1, 76 | sizeof(btree_t), 77 | -1); 78 | *p_root = btree_create(); 79 | m_size = 0; 80 | 81 | } 82 | 83 | template 84 | T* 85 | BTree::insert_copy(uint32_t key, const T* element) 86 | { 87 | btree_insert_t insert = btree_insert(p_root, key, nullptr); 88 | if(insert.m_inserted) 89 | { 90 | *insert.p_place = mem_alloc(&m_allocator, 91 | 1, 92 | sizeof(T), 93 | -1); 94 | new (*insert.p_place) T(*element); 95 | m_size++; 96 | return (T*)*insert.p_place; 97 | } 98 | return nullptr; 99 | } 100 | 101 | template 102 | template 103 | T* 104 | BTree::insert_new(uint32_t key, Args &&... args) 105 | { 106 | btree_insert_t insert = btree_insert(p_root, key, nullptr); 107 | if(insert.m_inserted) 108 | { 109 | *insert.p_place = mem_alloc(&m_allocator, 110 | 1, 111 | sizeof(T), 112 | -1); 113 | new (*insert.p_place) T(std::forward(args)...); 114 | m_size++; 115 | return (T*)*insert.p_place; 116 | } 117 | return nullptr; 118 | } 119 | 120 | template 121 | void 122 | BTree::remove(uint32_t key) 123 | { 124 | T* value = static_cast(btree_remove(p_root, key)); 125 | if (value != nullptr) 126 | { 127 | value->~T(); 128 | mem_free(&m_allocator, 129 | value); 130 | m_size--; 131 | } 132 | } 133 | 134 | template 135 | T* 136 | BTree::get(uint32_t key) const 137 | { 138 | T* ret = static_cast(btree_get(p_root, key)); 139 | return ret; 140 | } 141 | 142 | template 143 | bool 144 | BTree::exists(uint32_t key){ 145 | bool res = get(key) != nullptr; 146 | return res; 147 | } 148 | 149 | template 150 | size_t 151 | BTree::size() const 152 | { 153 | size_t ret = m_size; 154 | return ret; 155 | } 156 | 157 | template 158 | typename BTree::Iterator 159 | BTree::iterator() const 160 | { 161 | return Iterator(p_root); 162 | } 163 | 164 | template 165 | BTree::Iterator::Iterator(btree_t* root) 166 | { 167 | m_iterator = btree_iter_create(root); 168 | } 169 | 170 | template 171 | BTree::Iterator::~Iterator() 172 | { 173 | btree_iter_destroy(&m_iterator); 174 | } 175 | 176 | template 177 | bool 178 | BTree::Iterator::has_next() const 179 | { 180 | return btree_iter_has_next(&m_iterator); 181 | } 182 | 183 | template 184 | typename BTree::Entry 185 | BTree::Iterator::next() 186 | { 187 | btree_entry_t entry = btree_iter_next(&m_iterator); 188 | return BTree::Entry{entry.m_key, static_cast(entry.p_value)}; 189 | } 190 | 191 | } /* furious */ 192 | -------------------------------------------------------------------------------- /src/common/deprecated/refcount_ptr.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef _FURIOUS_REFCOUNT_PTR_H_ 4 | #define _FURIOUS_REFCOUNT_PTR_H_ 5 | 6 | #include "types.h" 7 | 8 | 9 | namespace furious 10 | { 11 | 12 | struct RefData 13 | { 14 | RefData(); 15 | uint32_t m_num_refs; 16 | }; 17 | 18 | template 19 | struct RefCountPtr 20 | { 21 | RefCountPtr(); 22 | RefCountPtr(T* ptr); 23 | RefCountPtr(const RefCountPtr& other); 24 | ~RefCountPtr(); 25 | 26 | T* 27 | get() const; 28 | 29 | void 30 | lock(); 31 | 32 | void 33 | release(); 34 | 35 | RefCountPtr& 36 | operator=(const RefCountPtr& other); 37 | 38 | //////////////////////////////////////////////// 39 | //////////////////////////////////////////////// 40 | //////////////////////////////////////////////// 41 | 42 | T* p_ptr; 43 | RefData* p_ref_data; 44 | 45 | }; 46 | 47 | } /* furious */ 48 | 49 | #include "refcount_ptr.inl" 50 | #endif 51 | -------------------------------------------------------------------------------- /src/common/deprecated/refcount_ptr.inl: -------------------------------------------------------------------------------- 1 | 2 | 3 | namespace furious 4 | { 5 | 6 | inline RefData::RefData() : 7 | m_num_refs(0) 8 | { 9 | } 10 | 11 | template 12 | RefCountPtr::RefCountPtr() : 13 | p_ptr(nullptr) 14 | { 15 | p_ref_data = new RefData(); 16 | lock(); 17 | } 18 | 19 | template 20 | RefCountPtr::RefCountPtr(T* ptr) : 21 | p_ptr(ptr) 22 | { 23 | p_ref_data = new RefData(); 24 | lock(); 25 | } 26 | 27 | template 28 | RefCountPtr::RefCountPtr(const RefCountPtr& other) : 29 | p_ptr(other.p_ptr), 30 | p_ref_data(other.p_ref_data) 31 | { 32 | lock(); 33 | } 34 | 35 | template 36 | RefCountPtr::~RefCountPtr() 37 | { 38 | release(); 39 | } 40 | 41 | template 42 | T* 43 | RefCountPtr::get() const 44 | { 45 | return p_ptr; 46 | } 47 | 48 | template 49 | void 50 | RefCountPtr::lock() 51 | { 52 | ++p_ref_data->m_num_refs; 53 | } 54 | 55 | template 56 | void 57 | RefCountPtr::release() 58 | { 59 | --p_ref_data->m_num_refs; 60 | if(p_ref_data != nullptr && 61 | p_ref_data->m_num_refs == 0) 62 | { 63 | delete p_ref_data; 64 | p_ref_data = nullptr; 65 | if(p_ptr != nullptr) 66 | { 67 | delete p_ptr; 68 | p_ptr = nullptr; 69 | } 70 | } 71 | } 72 | 73 | template 74 | RefCountPtr& 75 | RefCountPtr::operator=(const RefCountPtr& other) 76 | { 77 | release(); 78 | p_ptr = other.p_ptr; 79 | p_ref_data = other.p_ref_data; 80 | lock(); 81 | return *this; 82 | } 83 | 84 | } /* furious */ 85 | -------------------------------------------------------------------------------- /src/common/hashtable.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _FDB_HASHTABLE_H_ 3 | #define _FDB_HASHTABLE_H_ 4 | 5 | #include "types.h" 6 | #include "memory/memory.h" 7 | 8 | #include 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | 15 | #define _FDB_HASHTABLE_NODE_CAPACITY 8 16 | 17 | typedef struct fdb_hashtable_node_t 18 | { 19 | void* m_elements[_FDB_HASHTABLE_NODE_CAPACITY]; 20 | uint32_t m_keys[_FDB_HASHTABLE_NODE_CAPACITY]; 21 | uint32_t m_num_elements; 22 | struct fdb_hashtable_node_t* p_next; 23 | } fdb_hashtable_node_t; 24 | 25 | typedef struct fdb_hashtable_t 26 | { 27 | uint32_t m_capacity; 28 | uint32_t m_num_elements; 29 | fdb_hashtable_node_t* m_entries; 30 | fdb_mem_allocator_t* p_allocator; 31 | } fdb_hashtable_t; 32 | 33 | typedef struct fdb_hashtable_iter_t 34 | { 35 | fdb_hashtable_t* p_table; 36 | fdb_hashtable_node_t* p_next_node; 37 | uint32_t m_next_entry; 38 | uint32_t m_next_element; 39 | } fdb_hashtable_iter_t; 40 | 41 | typedef struct fdb_hashtable_entry_t 42 | { 43 | uint32_t m_key; 44 | void* p_value; 45 | } fdb_hashtable_entry_t; 46 | 47 | /** 48 | * \brief Initializes a hash table 49 | * 50 | * \param table The hash table to initialize 51 | */ 52 | void 53 | fdb_hashtable_init(fdb_hashtable_t* ht, 54 | uint32_t capacity, 55 | fdb_mem_allocator_t* allocator); 56 | 57 | /** 58 | * \brief Releases a hash table 59 | * 60 | * \param table The hash table to release 61 | */ 62 | void 63 | fdb_hashtable_release(fdb_hashtable_t* table); 64 | 65 | 66 | /** 67 | * \brief Adds an element to the hash table 68 | * 69 | * \param table The hash table to add the element to 70 | * \param key The key of the element to add 71 | * \param value The value of the element to add 72 | * 73 | * \return Returns the former element with the given added key if it existed 74 | */ 75 | void* 76 | fdb_hashtable_add(fdb_hashtable_t* table, 77 | uint32_t key, 78 | void* value); 79 | 80 | /** 81 | * \brief Adds an element to the hash table 82 | * 83 | * \param table The hash table to add the element to 84 | * \param key The key of the element to add 85 | * \param value The value of the element to add 86 | */ 87 | void* 88 | fdb_hashtable_get(fdb_hashtable_t* table, 89 | uint32_t key); 90 | 91 | /** 92 | * \brief Initialize a hashtable iterator 93 | * 94 | * \param iter The iterator to initialize 95 | * \param hashtable The hashtable this iterator iterates over 96 | */ 97 | fdb_hashtable_iter_t 98 | fdb_hashtable_iter_init(fdb_hashtable_t* hashtable); 99 | 100 | /** 101 | * \brief Releases the given iterator 102 | * 103 | * \param iter The iterator to release 104 | */ 105 | void 106 | fdb_hashtable_iter_release(fdb_hashtable_iter_t* iter); 107 | 108 | /** 109 | * \brief Checks if the iterator has next elements 110 | * 111 | * \param iter The iterator to check for has next 112 | */ 113 | bool 114 | fdb_hashtable_iter_has_next(fdb_hashtable_iter_t* iter); 115 | 116 | /** 117 | * \brief Checks if the iterator has next elements 118 | * 119 | * \param iter The iterator to check for has next 120 | * 121 | * \return Returns a hashtable entry typedef structure 122 | */ 123 | fdb_hashtable_entry_t 124 | fdb_hashtable_iter_next(fdb_hashtable_iter_t* iter); 125 | 126 | #ifdef __cplusplus 127 | } 128 | #endif 129 | 130 | #endif /* ifndef _FDB_fdb_hashtable_ */ 131 | -------------------------------------------------------------------------------- /src/common/memory/memory.c: -------------------------------------------------------------------------------- 1 | 2 | #include "memory.h" 3 | #include "../platform.h" 4 | 5 | #include "numa_alloc.h" 6 | 7 | fdb_mem_allocator_t global_mem_allocator; 8 | 9 | void* 10 | mem_alloc(fdb_mem_allocator_t* mem_allocator, 11 | uint32_t alignment, 12 | uint32_t size, 13 | uint32_t hint) 14 | { 15 | return mem_allocator->p_mem_alloc(mem_allocator->p_mem_state, 16 | alignment, 17 | size, 18 | hint); 19 | } 20 | 21 | void 22 | mem_free(fdb_mem_allocator_t* mem_allocator, 23 | void* ptr) 24 | { 25 | return mem_allocator->p_mem_free(mem_allocator->p_mem_state, 26 | ptr); 27 | } 28 | 29 | fdb_mem_stats_t 30 | mem_stats(fdb_mem_allocator_t* mem_allocator) 31 | { 32 | return mem_allocator->p_mem_stats(mem_allocator->p_mem_state); 33 | } 34 | 35 | fdb_mem_allocator_t* 36 | fdb_get_global_mem_allocator() 37 | { 38 | if(global_mem_allocator.p_mem_alloc == NULL || 39 | global_mem_allocator.p_mem_free == NULL) 40 | { 41 | global_mem_allocator.p_mem_alloc = fdb_numa_alloc; 42 | global_mem_allocator.p_mem_free = fdb_numa_free; 43 | } 44 | return &global_mem_allocator; 45 | } 46 | 47 | uint32_t 48 | alignment(uint32_t struct_size) 49 | { 50 | struct_size--; 51 | struct_size|=struct_size>>1; 52 | struct_size|=struct_size>>2; 53 | struct_size|=struct_size>>4; 54 | struct_size|=struct_size>>8; 55 | struct_size|=struct_size>>16; 56 | struct_size++; 57 | return struct_size; 58 | } 59 | -------------------------------------------------------------------------------- /src/common/memory/memory.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _FDB_MEMORY_H_ 3 | #define _FDB_MEMORY_H_ 4 | 5 | #include "../../common/types.h" 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | #define FDB_NO_HINT 0xffffffff 12 | #define BYTES(value) (value) 13 | #define KILOBYTES(value) (BYTES(value)*(uint64_t)1024) 14 | #define MEGABYTES(value) (KILOBYTES(value)*(uint64_t)1024) 15 | #define GIGABYTES(value) (MEGABYTES(value)*(uint64_t)1024) 16 | 17 | //constexpr int32_t ALIGNMENT = 64; 18 | 19 | typedef void* (*fdb_alloc_t) (void*, // ptr to state 20 | uint32_t, // alignment 21 | uint32_t, // size in bytes 22 | uint32_t); // hint with the block id of this allocation. -1 indicates no hint 23 | 24 | typedef void (*fdb_free_t) (void*, // ptr to state 25 | void*); // ptr to free 26 | 27 | typedef struct fdb_mem_stats_t 28 | { 29 | uint64_t m_allocated; 30 | uint64_t m_lost; 31 | uint64_t m_used; 32 | } fdb_mem_stats_t; 33 | 34 | typedef fdb_mem_stats_t (*fdb_stats_t) (void*); // ptr to state 35 | 36 | typedef struct fdb_mem_allocator_t 37 | { 38 | void* p_mem_state; 39 | fdb_alloc_t p_mem_alloc; 40 | fdb_free_t p_mem_free; 41 | fdb_stats_t p_mem_stats; 42 | } fdb_mem_allocator_t; 43 | 44 | void* 45 | mem_alloc(fdb_mem_allocator_t* mem_allocator, 46 | uint32_t alignment, 47 | uint32_t size, 48 | uint32_t hint); 49 | 50 | void 51 | mem_free(fdb_mem_allocator_t* mem_allocator, 52 | void* ptr); 53 | 54 | fdb_mem_stats_t 55 | mem_stats(fdb_mem_allocator_t* mem_allocator); 56 | 57 | /** 58 | * \brief gets the global mem allocator 59 | * 60 | * \return A pointer to the global mem allocator 61 | */ 62 | fdb_mem_allocator_t* 63 | fdb_get_global_mem_allocator(); 64 | 65 | /** 66 | * \brief Gets the alignment for a structure of the given size 67 | * 68 | * \param struct_size The size in bytes of the structure to get the alignment 69 | * for 70 | * 71 | * \return Returns the alignment 72 | */ 73 | uint32_t 74 | alignment(uint32_t struct_size); 75 | 76 | #ifdef __cplusplus 77 | } 78 | #endif 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /src/common/memory/numa_alloc.c: -------------------------------------------------------------------------------- 1 | 2 | // Required to have posix_memalign enabled 3 | #define _POSIX_C_SOURCE 200809L 4 | 5 | #include "../platform.h" 6 | #include "memory.h" 7 | #include "numa_alloc.h" 8 | 9 | #include 10 | #include 11 | 12 | 13 | int32_t numa_nodes() { 14 | return 0; 15 | } 16 | 17 | void* fdb_numa_alloc(void* state, 18 | uint32_t alignment, 19 | uint32_t size, 20 | uint32_t hint) 21 | { 22 | 23 | uint32_t min_alignment = alignment < FDB_MIN_ALIGNMENT ? FDB_MIN_ALIGNMENT : alignment; 24 | //uint32_t residual = size % min_alignment; 25 | //uint32_t real_size = size; 26 | //if(residual != 0) 27 | //{ 28 | // real_size += (min_alignment-residual); 29 | //} 30 | void* ptr = NULL; 31 | posix_memalign(&ptr, min_alignment, size); 32 | return ptr; 33 | } 34 | 35 | void fdb_numa_free( void* state, 36 | void* ptr ) { 37 | free(ptr); 38 | } 39 | -------------------------------------------------------------------------------- /src/common/memory/numa_alloc.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef _FDB_NUMA_ALLOC_H_ 4 | #define _FDB_NUMA_ALLOC_H_ value 5 | 6 | #include "../../common/types.h" 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | 13 | /** 14 | * @brief Gets the number of numa nodes available in the system 15 | * 16 | * @return Returns the number of numa nodes in the system 17 | */ 18 | int32_t fdb_numa_nodes(); 19 | 20 | 21 | /** 22 | * @brief Allocates a memory block in a numa node 23 | * 24 | * @param ptr The state 25 | * @param alignment The alignment of the memory allocator 26 | * @param size The size in bytes of the memory block to allocate 27 | * @param hint The hint to the allocator. It corresponds to id of the allocated 28 | * block 29 | * 30 | * @return 31 | */ 32 | void* fdb_numa_alloc(void* state, 33 | uint32_t alignment, 34 | uint32_t size, 35 | uint32_t hint); 36 | 37 | 38 | /** 39 | * @brief Frees an allocated memory block 40 | * 41 | * #param ptr The state 42 | * @param ptr The pointer to the memory block to free 43 | */ 44 | void fdb_numa_free( void* state, 45 | void* ptr ); 46 | 47 | #ifdef __cplusplus 48 | } 49 | #endif 50 | 51 | 52 | #endif /* ifndef _FDB_NUMA_ALLOC_H_ */ 53 | -------------------------------------------------------------------------------- /src/common/memory/page_allocator.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef _FDB_PAGE_ALLOC_H_ 4 | #define _FDB_PAGE_ALLOC_H_ 5 | 6 | #include "memory.h" 7 | #include "../mutex.h" 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | typedef struct fdb_page_alloc_t 14 | { 15 | void* p_data; 16 | void* p_stop; 17 | void* p_ltop; 18 | void* p_snextfree; 19 | void* p_lnextfree; 20 | uint64_t m_sregion; 21 | uint32_t m_ssize; 22 | uint32_t m_lsize; 23 | fdb_mem_allocator_t m_super; 24 | fdb_mem_stats_t m_stats; 25 | fdb_mutex_t m_mutex; 26 | } fdb_page_alloc_t; 27 | 28 | /** 29 | * \brief Initializes a page allocator 30 | * 31 | * \param palloc The page allocator to initialize 32 | * \param sregion The size of the memory region (in bytes) to allocate 33 | * \param ssmall The size of the small pages to allocate 34 | * \param slarge The size of the large pages to allocate 35 | */ 36 | void 37 | fdb_page_alloc_init(fdb_page_alloc_t* palloc, 38 | uint64_t sregion, 39 | uint32_t ssmall, 40 | uint32_t slarge); 41 | 42 | /** 43 | * \brief Releases a page allocator 44 | * 45 | * \param palloc The page allocator to release 46 | */ 47 | void 48 | fdb_page_alloc_release(fdb_page_alloc_t* palloc); 49 | 50 | /** 51 | * \brief Allocates a block of memory using the page allocator. This block 52 | * of memory must be either of size ssmall or slarge. Otherwise the program will 53 | * abort 54 | * 55 | * \param palloc The page allocator 56 | * \param alignment The alignment of the allocation (ignored) 57 | * \param size The size of the allocation (either ssmall or slarge) 58 | * \param hint The hint passed to the allocator (ignored) 59 | */ 60 | void* 61 | fdb_page_alloc_alloc(fdb_page_alloc_t* palloc, 62 | uint32_t alignment, 63 | uint32_t size, 64 | uint32_t hint); 65 | 66 | /** 67 | * \brief Frees a memory block from a page allocator 68 | * 69 | * \param palloc The page allocator to free the memory block from 70 | * \param ptr The pointer to the memory block to free 71 | */ 72 | void 73 | fdb_page_alloc_free(fdb_page_alloc_t* palloc, 74 | void* ptr); 75 | 76 | fdb_mem_stats_t 77 | fdb_page_alloc_stats(fdb_page_alloc_t* palloc); 78 | 79 | #ifdef __cplusplus 80 | } 81 | #endif 82 | 83 | #endif 84 | -------------------------------------------------------------------------------- /src/common/memory/pool_allocator.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | #ifndef _FURIOUS_POOL_ALLOCATOR_H_ 5 | #define _FURIOUS_POOL_ALLOCATOR_H_ value 6 | 7 | #include "memory.h" 8 | #include "../types.h" 9 | #include "../mutex.h" 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | typedef struct fdb_pool_alloc_header_t 16 | { 17 | void* p_next; 18 | } fdb_pool_alloc_header_t; 19 | 20 | typedef struct fdb_pool_alloc_t 21 | { 22 | void* p_first_chunk; //< Pointer to the first memory chunk/page 23 | void* p_last_chunk; //< Pointer to the last memory chunk/page 24 | void* p_first_free; //< Pointer to the first block freed 25 | uint64_t m_alignment; //< The alignment of the blocks 26 | uint64_t m_block_size; //< The size of the allocated blocks 27 | uint64_t m_page_size; //< The size of the preallocation chunks 28 | uint64_t m_next_free; //< The next free offset of the last chunk 29 | uint64_t m_grow_offset; //< The amount of offset to grow next_free after each allocation 30 | uint64_t m_lost_bytes; //< The amount of lost bytes per page due to growoffset unalignment plus header 31 | fdb_mem_allocator_t* p_allocator; //< The parent memory allocator 32 | fdb_mem_allocator_t m_super; 33 | fdb_mem_stats_t m_stats; 34 | fdb_mutex_t m_mutex; 35 | } fdb_pool_alloc_t; 36 | 37 | /** 38 | * \brief inits a pool allocator 39 | * 40 | * \param alignment The alignment of the allocations 41 | * \param block_size The size of the allocations 42 | * \param page_size The size of the batches to preallocate 43 | * \param allocator The parent allocator to use by this allocator 44 | * 45 | * \return Returns the memory allocator 46 | */ 47 | void 48 | fdb_pool_alloc_init(fdb_pool_alloc_t* palloc, 49 | uint32_t alignment, 50 | uint32_t block_size, 51 | uint32_t page_size, 52 | fdb_mem_allocator_t* allocator); 53 | 54 | 55 | /** 56 | * \brief releases a pool allocator 57 | * 58 | * \param fdb_pool_alloc The pool allocator to release 59 | */ 60 | void 61 | fdb_pool_alloc_release(fdb_pool_alloc_t* allocator); 62 | 63 | void* 64 | fdb_pool_alloc_alloc(fdb_pool_alloc_t* palloc, 65 | uint32_t alignment, 66 | uint32_t size, 67 | uint32_t hint); 68 | void 69 | fdb_pool_alloc_free(fdb_pool_alloc_t* palloc, 70 | void* ptr); 71 | 72 | void 73 | fdb_pool_alloc_flush(fdb_pool_alloc_t* palloc); 74 | 75 | fdb_mem_stats_t 76 | fdb_pool_alloc_stats(fdb_pool_alloc_t* palloc); 77 | 78 | #ifdef __cplusplus 79 | } 80 | #endif 81 | 82 | 83 | #endif /* ifndef _FURIOUS_fdb_pool_ALLOCATOR_H_ */ 84 | -------------------------------------------------------------------------------- /src/common/memory/stack_allocator.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | #ifndef _FURIOUS_STACK_ALLOCATOR_H_ 5 | #define _FURIOUS_STACK_ALLOCATOR_H_ value 6 | 7 | #include "../../common/types.h" 8 | #include "memory.h" 9 | #include "../mutex.h" 10 | #include "pool_allocator.h" 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | typedef struct fdb_stack_alloc_fheader_t 17 | { 18 | void* p_next_page; 19 | void* p_previous_page; 20 | uint32_t m_next_free; 21 | } fdb_stack_alloc_fheader_t; 22 | 23 | typedef struct fdb_stack_alloc_t 24 | { 25 | uint32_t m_page_size; 26 | uint64_t m_page_mask; 27 | fdb_mem_allocator_t* p_allocator; 28 | void* p_next_page; 29 | uint32_t m_next_offset; 30 | void* p_last_frame; 31 | uint32_t m_max_frame_offset; 32 | fdb_mem_allocator_t m_super; 33 | fdb_mem_stats_t m_stats; 34 | fdb_mutex_t m_mutex; 35 | } fdb_stack_alloc_t; 36 | 37 | /** 38 | * \brief inits a stack allocator 39 | * 40 | * \param allocator The allocator to use 41 | * 42 | * \return Returns a new stack allocator 43 | */ 44 | void 45 | fdb_stack_alloc_init(fdb_stack_alloc_t* salloc, 46 | uint32_t page_size, 47 | fdb_mem_allocator_t* allocator); 48 | 49 | /** 50 | * \brief releases a stack allocator 51 | * 52 | * \param fdb_stack_alloc The stack allocator to release 53 | */ 54 | void 55 | fdb_stack_alloc_release(fdb_stack_alloc_t* allocator); 56 | 57 | void* 58 | fdb_stack_alloc_alloc(fdb_stack_alloc_t* state, 59 | uint32_t alignment, 60 | uint32_t size, 61 | uint32_t hint); 62 | void 63 | fdb_stack_alloc_free(fdb_stack_alloc_t* state, 64 | void* ptr); 65 | 66 | /** 67 | * \brief Frees the last allocation performed by the stack allocator 68 | * 69 | * \param state The stack allocator 70 | * \param ptr The ptr to the data to be freed. This is used for error checking 71 | * purposes 72 | */ 73 | void 74 | fdb_stack_alloc_pop(fdb_stack_alloc_t* state, 75 | void* ptr); 76 | 77 | fdb_mem_stats_t 78 | fdb_stack_alloc_stats(fdb_stack_alloc_t* palloc); 79 | 80 | #ifdef __cplusplus 81 | } 82 | #endif 83 | 84 | #endif /* ifndef _FURIOUS_STACK_ALLOCATOR_H_ */ 85 | -------------------------------------------------------------------------------- /src/common/mutex.c: -------------------------------------------------------------------------------- 1 | 2 | #include "mutex.h" 3 | 4 | void 5 | fdb_mutex_init(fdb_mutex_t* mutex) 6 | { 7 | pthread_mutex_init(&mutex->m_mutex, NULL); 8 | } 9 | 10 | void 11 | fdb_mutex_release(fdb_mutex_t* mutex) 12 | { 13 | pthread_mutex_destroy(&mutex->m_mutex); 14 | } 15 | 16 | void 17 | fdb_mutex_lock(fdb_mutex_t* mutex) 18 | { 19 | pthread_mutex_lock(&mutex->m_mutex); 20 | } 21 | 22 | void 23 | fdb_mutex_unlock(fdb_mutex_t* mutex) 24 | { 25 | pthread_mutex_unlock(&mutex->m_mutex); 26 | } 27 | -------------------------------------------------------------------------------- /src/common/mutex.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef _FDB_MUTEX_H_ 4 | #define _FDB_MUTEX_H_ value 5 | 6 | #include 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | 13 | typedef struct fdb_mutex_t 14 | { 15 | pthread_mutex_t m_mutex; 16 | } fdb_mutex_t; 17 | 18 | 19 | /** 20 | * \brief inits a new mutex 21 | * 22 | * \return The newly initd mutex 23 | */ 24 | void 25 | fdb_mutex_init(fdb_mutex_t* mutex); 26 | 27 | /** 28 | * \brief Destroys a mutex 29 | * 30 | * \param mutex The mutex to destroy 31 | */ 32 | void 33 | fdb_mutex_release(fdb_mutex_t* mutex); 34 | 35 | /** 36 | * \brief Locks a mutex 37 | * 38 | * \param mutex The mutex to lock 39 | */ 40 | void 41 | fdb_mutex_lock(fdb_mutex_t* mutex); 42 | 43 | /** 44 | * \brief Unlocks a mutex 45 | * 46 | * \param mutex The mutex to unlock 47 | */ 48 | void 49 | fdb_mutex_unlock(fdb_mutex_t* mutex); 50 | 51 | #ifdef __cplusplus 52 | } 53 | #endif 54 | 55 | #endif /* ifndef _FURIOUS_MUTEX_H_ */ 56 | -------------------------------------------------------------------------------- /src/common/platform.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include "platform.h" 4 | 5 | uint32_t 6 | fdb_os_pow2_bit(uint64_t x) 7 | { 8 | #ifdef FDB_COMPILER_GCC 9 | return __builtin_ffs(x); 10 | #endif 11 | } 12 | 13 | void 14 | fdb_mem_barrier() 15 | { 16 | #ifdef FDB_COMPILER_GCC 17 | __sync_synchronize(); 18 | #endif 19 | } 20 | -------------------------------------------------------------------------------- /src/common/platform.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef _FDB_PLATFORM_H_ 4 | #define _FDB_PLATFORM_H_ 5 | 6 | #include "types.h" 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #ifdef FDB_COMPILER_GCC 13 | #define FDB_COMPILER_DEFINED 14 | #endif 15 | 16 | #ifdef FDB_OS_LINUX 17 | #define FDB_OS_DEFINED 18 | #ifndef _GNU_SOURCE 19 | #define _GNU_SOURCE 20 | #endif 21 | #endif 22 | 23 | #ifndef FDB_COMPILER_DEFINED 24 | #error compiler not defined 25 | #endif 26 | 27 | #ifndef FDB_OS_DEFINED 28 | #error os not defined 29 | #endif 30 | 31 | #ifdef FDB_ENABLE_ASSERTS 32 | #define FDB_ASSERT(_cond) if(!(_cond)) abort(); 33 | #else 34 | #define FDB_ASSERT(_cond) 35 | #endif 36 | 37 | #define FDB_PERMA_ASSERT(_cond) if(!(_cond)) { \ 38 | printf(#_cond);\ 39 | abort();\ 40 | } 41 | 42 | #define FDB_COPY_AND_CHECK_STR(dest, origin, capacity) \ 43 | strncpy(dest, origin, capacity);\ 44 | FDB_PERMA_ASSERT(strlen(origin) < capacity && "String exceeds maximum capacity"); 45 | 46 | #define FDB_RESTRICT(type) type __restrict__ 47 | #define FDB_ALIGNED(type, name, alignment) type __attribute__((aligned(alignment))) name 48 | 49 | /// RUNTIME 50 | 51 | #define FDB_MIN_ALIGNMENT 16 52 | 53 | #define FDB_BTREE_ALIGNMENT 64 54 | #define FDB_BTREE_PAGE_SIZE KILOBYTES(4) 55 | 56 | #define FDB_BITMAP_ALIGNMENT 64 57 | #define FDB_BITMAP_PAGE_SIZE KILOBYTES(4) 58 | #define FDB_BITMAP_DATA_ALIGNMENT 64 59 | #define FDB_BITMAP_DATA_PAGE_SIZE KILOBYTES(4) 60 | 61 | #define FDB_TABLE_BLOCK_ALIGNMENT 64 62 | #define FDB_TABLE_BLOCK_DATA_ALIGNMENT 64 63 | 64 | #define FDB_TABLE_BLOCK_PAGE_SIZE KILOBYTES(4) 65 | #define FDB_TABLE_BLOCK_DATA_PAGE_SIZE KILOBYTES(64) 66 | 67 | #define FDB_DATABASE_TABLE_ALIGNMENT 64 68 | #define FDB_DATABASE_BITTABLE_ALIGNMENT 64 69 | #define FDB_DATABASE_GLOBAL_ALIGNMENT 64 70 | #define FDB_DATABASE_TABLE_PAGE_SIZE KILOBYTES(4) 71 | #define FDB_DATABASE_BITTABLE_PAGE_SIZE KILOBYTES(4) 72 | #define FDB_DATABASE_GLOBAL_PAGE_SIZE KILOBYTES(4) 73 | 74 | #define FDB_INVALID_ID 0xffffffff 75 | #define FDB_INVALID_TABLE_ID FDB_INVALID_ID 76 | #define FDB_TABLE_BLOCK_SIZE 256 77 | #define FDB_MAX_TABLE_NAME 256 78 | 79 | #define FDB_MAX_COMPONENT_FIELDS 32 80 | 81 | #define FDB_REFLECTION_STRUCT_PAGE_SIZE KILOBYTES(4) 82 | #define FDB_REFLECTION_FIELD_PAGE_SIZE KILOBYTES(4) 83 | 84 | #define FDB_MAX_WEBSERVER_PORT_SIZE 64 85 | #define FDB_MAX_WEBSERVER_ADDRESS_SIZE 64 86 | 87 | #define FDB_TX_GC_PAGE_SIZE KILOBYTES(4) 88 | /// FCC_COMPILER 89 | 90 | #define FCC_INVALID_ID FDB_INVALID_ID 91 | #define FCC_MAX_TYPE_NAME FDB_MAX_TABLE_NAME 92 | #define FCC_MAX_QUALIFIED_TYPE_NAME FCC_MAX_TYPE_NAME+32 93 | #define FCC_MAX_FIELD_NAME 256 94 | #define FCC_MAX_REF_NAME 256 95 | #define FCC_MAX_TAG_NAME 256 96 | #define FCC_MAX_TABLE_VARNAME FCC_MAX_TYPE_NAME+32 97 | #define FCC_MAX_REF_TABLE_VARNAME FCC_MAX_TYPE_NAME+32 98 | #define FCC_MAX_TAG_TABLE_VARNAME FCC_MAX_TYPE_NAME+32 99 | #define FCC_MAX_SYSTEM_WRAPPER_VARNAME FCC_MAX_TYPE_NAME+32 100 | #define FCC_MAX_HASHTABLE_VARNAME 256 101 | #define FCC_MAX_CLUSTER_VARNAME 256 102 | #define FCC_MAX_ITER_VARNAME 256 103 | #define FCC_MAX_BLOCK_VARNAME 256 104 | #define FCC_MAX_INCLUDE_PATH_LENGTH 2048 105 | #define FCC_MAX_OPERATOR_NAME 32 106 | #define FCC_MAX_OPERATOR_NUM_COLUMNS 16 107 | #define FCC_MAX_SUBPLAN_NODES 32 108 | #define FCC_MAX_TASK_PARENTS FCC_MAX_OPERATOR_NUM_COLUMNS 109 | #define FCC_MAX_TASK_CHILDREN FCC_MAX_OPERATOR_NUM_COLUMNS 110 | 111 | #define FCC_MAX_CTOR_PARAMS 16 112 | #define FCC_MAX_SYSTEM_COMPONENTS FCC_MAX_OPERATOR_NUM_COLUMNS 113 | #define FCC_MAX_HAS_COMPONENTS FCC_MAX_OPERATOR_NUM_COLUMNS 114 | #define FCC_MAX_HAS_NOT_COMPONENTS FCC_MAX_HAS_COMPONENTS 115 | #define FCC_MAX_HAS_TAGS 16 116 | #define FCC_MAX_HAS_NOT_TAGS FCC_MAX_HAS_TAGS 117 | #define FCC_MAX_FILTER_FUNC 8 118 | 119 | /** 120 | * \brief Returns the index (starting from 1) of the least significant bit of the given 121 | * number 122 | * 123 | * \param x The number to get the index for 124 | * 125 | * \return The index of the least significant bit 126 | */ 127 | uint32_t 128 | fdb_os_pow2_bit(uint64_t x); 129 | 130 | /** 131 | * \brief Memory barrier. Prevents loads/stores to cross this instruction 132 | */ 133 | void 134 | fdb_mem_barrier(); 135 | 136 | #endif 137 | -------------------------------------------------------------------------------- /src/common/str_builder.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | #include "str_builder.h" 5 | #include "memory/memory.h" 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | 13 | void 14 | fdb_str_builder_init(fdb_str_builder_t* str_builder) 15 | { 16 | str_builder->m_capacity = 2048; 17 | str_builder->p_buffer = (char*) mem_alloc(fdb_get_global_mem_allocator(), 18 | 1, 19 | sizeof(char)*str_builder->m_capacity, 20 | FDB_NO_HINT); 21 | str_builder->p_buffer[0] = '\0'; 22 | str_builder->m_pos = 0; 23 | str_builder->p_buffer[str_builder->m_pos] = 0; 24 | } 25 | 26 | void fdb_str_builder_release(fdb_str_builder_t* str_builder) 27 | { 28 | if(str_builder->p_buffer != NULL) 29 | { 30 | mem_free(fdb_get_global_mem_allocator(), 31 | str_builder->p_buffer); 32 | str_builder->m_capacity = 0; 33 | } 34 | } 35 | 36 | void 37 | fdb_str_builder_append(fdb_str_builder_t* str_builder, 38 | const char* str, 39 | ...) 40 | { 41 | va_list myargs; 42 | va_start(myargs, str); 43 | 44 | uint32_t nwritten = 0; 45 | while( (nwritten = vsnprintf(&str_builder->p_buffer[str_builder->m_pos], 46 | str_builder->m_capacity - str_builder->m_pos, 47 | str, 48 | myargs)) > (str_builder->m_capacity - str_builder->m_pos - 1)) 49 | { 50 | uint32_t new_capacity = str_builder->m_capacity + 2048; 51 | char* new_buffer = (char*) mem_alloc(fdb_get_global_mem_allocator(), 52 | 1, 53 | sizeof(char)*new_capacity, 54 | -1); 55 | memcpy(new_buffer, 56 | str_builder->p_buffer, 57 | sizeof(char)*str_builder->m_capacity); 58 | mem_free(fdb_get_global_mem_allocator(), 59 | str_builder->p_buffer); 60 | str_builder->p_buffer = new_buffer; 61 | str_builder->m_capacity = new_capacity; 62 | } 63 | str_builder->m_pos += nwritten; 64 | str_builder->p_buffer[str_builder->m_pos] = '\0'; 65 | 66 | /* Clean up the va_list */ 67 | va_end(myargs); 68 | } 69 | 70 | void 71 | fdb_str_builder_clear(fdb_str_builder_t* str_builder) 72 | { 73 | str_builder->m_pos = 0; 74 | } 75 | 76 | -------------------------------------------------------------------------------- /src/common/str_builder.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef _FDB_STR_BUILDER_H_ 4 | #define _FDB_STR_BUILDER_H_ 5 | 6 | #include "types.h" 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | 13 | typedef struct fdb_str_builder_t 14 | { 15 | char* p_buffer; //string builder buffer 16 | uint32_t m_capacity; //capacity 17 | uint32_t m_pos; //next position 18 | } fdb_str_builder_t; 19 | 20 | /** 21 | * \brief Initializes a string builder 22 | * 23 | * \param The str_builder 24 | */ 25 | void 26 | fdb_str_builder_init(fdb_str_builder_t* str_builder); 27 | 28 | /** 29 | * \brief Releases a string builder 30 | * 31 | * \param The str_builder 32 | */ 33 | void 34 | fdb_str_builder_release(fdb_str_builder_t* str_builder); 35 | 36 | /** 37 | * \brief Appens the string to the string builder 38 | * 39 | * \param The str_builder 40 | * \param str The formatted string to append 41 | * \param ... The formatted variables 42 | */ 43 | void 44 | fdb_str_builder_append(fdb_str_builder_t* str_builder, 45 | const char* str, 46 | ...); 47 | 48 | /** 49 | * \brief Clears the contents of a string builder 50 | * 51 | * \param The str_builder 52 | */ 53 | void 54 | fdb_str_builder_clear(fdb_str_builder_t* str_builder); 55 | 56 | 57 | #ifdef __cplusplus 58 | } 59 | #endif 60 | 61 | #endif /* ifndef _FURIOUS_STRING_BUILDER_H_ */ 62 | -------------------------------------------------------------------------------- /src/common/templates/array.cpp.in: -------------------------------------------------------------------------------- 1 | 2 | 3 | /** THIS FILE IS AUTOGENERATED DO NOT EDIT THIS FILE. **/ 4 | 5 | #include "@FDB_PREFIX@_array.h" 6 | #include 7 | 8 | #include 9 | 10 | @FDB_INCLUDE@ 11 | 12 | 13 | @FDB_PREFIX@_array_t 14 | @FDB_PREFIX@_array_init() 15 | { 16 | @FDB_PREFIX@_array_t array; 17 | array.m_count = 0; 18 | array.m_capacity = 16; 19 | array.m_data = (@FDB_TYPE@*)mem_alloc(fdb_get_global_mem_allocator(), 20 | 64, 21 | sizeof(@FDB_TYPE@)*array.m_capacity, 22 | FDB_NO_HINT); 23 | return array; 24 | } 25 | 26 | void 27 | @FDB_PREFIX@_array_release(@FDB_PREFIX@_array_t* array) 28 | { 29 | mem_free(fdb_get_global_mem_allocator(), array->m_data); 30 | } 31 | 32 | void 33 | @FDB_PREFIX@_array_append(@FDB_PREFIX@_array_t* array, @FDB_TYPE@* e) 34 | { 35 | if(array->m_count == array->m_capacity) 36 | { 37 | uint32_t tmp = array->m_capacity*2; 38 | @FDB_TYPE@* buffer = (@FDB_TYPE@*)mem_alloc(fdb_get_global_mem_allocator(), 39 | 64, 40 | sizeof(@FDB_TYPE@)*tmp, 41 | FDB_NO_HINT); 42 | memcpy(buffer, array->m_data, sizeof(@FDB_TYPE@)*array->m_capacity); 43 | array->m_capacity = tmp; 44 | mem_free(fdb_get_global_mem_allocator(), array->m_data); 45 | array->m_data = buffer; 46 | } 47 | 48 | array->m_data[array->m_count++] = *e; 49 | } 50 | 51 | void 52 | @FDB_PREFIX@_array_copy(@FDB_PREFIX@_array_t* dst, 53 | @FDB_PREFIX@_array_t* src) 54 | { 55 | if(dst->m_capacity < src->m_capacity) 56 | { 57 | mem_free(fdb_get_global_mem_allocator(), dst->m_data); 58 | dst->m_capacity = src->m_capacity; 59 | dst->m_data = (@FDB_TYPE@*)mem_alloc(fdb_get_global_mem_allocator(), 60 | 64, 61 | sizeof(@FDB_TYPE@)*dst->m_capacity, 62 | FDB_NO_HINT); 63 | } 64 | dst->m_count = src->m_count; 65 | memcpy(dst->m_data, src->m_data, sizeof(@FDB_TYPE@)*dst->m_count); 66 | } 67 | 68 | -------------------------------------------------------------------------------- /src/common/templates/array.h.in: -------------------------------------------------------------------------------- 1 | 2 | 3 | /** THIS FILE IS AUTOGENERATED DO NOT EDIT THIS FILE. 4 | ** 5 | ** @FDB_GUARD@ specifies the header guard name 6 | ** @FDB_PREFIX@ specifies the prefix of the array name and methods 7 | ** @FDB_FORWARD@ specifies the forward declaration statement for the 8 | ** array type 9 | ** @FDB_INCLUDE@ specifies the include statement in the .cpp file 10 | ** to include the header with the array type 11 | */ 12 | 13 | #ifndef _FDB_@FDB_GUARD@_H_ 14 | #define _FDB_@FDB_GUARD@_H_ 15 | 16 | #include 17 | 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | @FDB_FORWARD@ 23 | 24 | struct @FDB_PREFIX@_array_t 25 | { 26 | uint32_t m_count; 27 | uint32_t m_capacity; 28 | @FDB_TYPE@* m_data; 29 | }; 30 | 31 | @FDB_PREFIX@_array_t 32 | @FDB_PREFIX@_array_init(); 33 | 34 | void 35 | @FDB_PREFIX@_array_release(@FDB_PREFIX@_array_t* array); 36 | 37 | void 38 | @FDB_PREFIX@_array_append(@FDB_PREFIX@_array_t* array, 39 | @FDB_TYPE@* e); 40 | 41 | void 42 | @FDB_PREFIX@_array_copy(@FDB_PREFIX@_array_t* dst, 43 | @FDB_PREFIX@_array_t* src); 44 | 45 | #ifdef __cplusplus 46 | } 47 | #endif 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /src/common/thread.c: -------------------------------------------------------------------------------- 1 | 2 | #include "thread.h" 3 | 4 | #ifdef FDB_OS_LINUX 5 | #include 6 | void* pthread_handler(void* arg) 7 | { 8 | fdb_thread_task_t* task = (fdb_thread_task_t*) arg; 9 | task->p_fp(task->p_args); 10 | return NULL; 11 | } 12 | #endif 13 | 14 | 15 | 16 | /** 17 | * \brief Starts a thread with the given task 18 | * 19 | * \param thread The thread to start 20 | * \param task The task to run with the thread 21 | */ 22 | void 23 | fdb_thread_start(fdb_thread_t* thread, 24 | fdb_thread_task_t* task) 25 | { 26 | #ifdef FDB_OS_LINUX 27 | pthread_create(&thread->m_pthread, 28 | NULL, 29 | pthread_handler, 30 | task); 31 | #endif 32 | } 33 | 34 | /** 35 | * \brief Joins a thread 36 | * 37 | * \param thread The thread to join 38 | */ 39 | void 40 | fdb_thread_join(fdb_thread_t* thread) 41 | { 42 | #ifdef FDB_OS_LINUX 43 | void* ptr; 44 | pthread_join(thread->m_pthread, &ptr); 45 | #endif 46 | } 47 | 48 | /** 49 | * \brief Kills a thread 50 | * 51 | * \param thread The thread to kill 52 | */ 53 | void 54 | fdb_thread_kill(fdb_thread_t* thread) 55 | { 56 | #ifdef FDB_OS_LINUX 57 | pthread_cancel(thread->m_pthread); 58 | #endif 59 | } 60 | 61 | bool 62 | fdb_thread_set_affinity(fdb_thread_t* thread, 63 | uint32_t cpuid) 64 | { 65 | #ifdef FDB_OS_LINUX 66 | cpu_set_t cpuset; 67 | CPU_ZERO(&cpuset); 68 | CPU_SET(cpuid, &cpuset); 69 | uint32_t res = pthread_setaffinity_np(thread->m_pthread, 70 | sizeof(cpu_set_t), 71 | &cpuset); 72 | return res == 0; 73 | #endif 74 | } 75 | 76 | bool 77 | fdb_thread_set_main_affinity(uint32_t cpuid) 78 | { 79 | #ifdef FDB_OS_LINUX 80 | cpu_set_t cpuset; 81 | CPU_ZERO(&cpuset); 82 | CPU_SET(cpuid, &cpuset); 83 | uint32_t res = sched_setaffinity(0, sizeof(cpuset), &cpuset); 84 | return res == 0; 85 | #endif 86 | } 87 | -------------------------------------------------------------------------------- /src/common/thread.h: -------------------------------------------------------------------------------- 1 | #ifdef FDB_OS_LINUX 2 | #ifndef _GNU_SOURCE 3 | #define _GNU_SOURCE 4 | #endif 5 | #endif 6 | 7 | #ifndef _FDB_THREAD_H_ 8 | #define _FDB_THREAD_H_ 9 | 10 | #include "platform.h" 11 | 12 | #ifdef FDB_OS_LINUX 13 | #include 14 | #endif 15 | 16 | #ifdef __cplusplus 17 | extern "C" 18 | { 19 | #endif 20 | 21 | typedef void (*fdb_thread_task_function_t)(void* arg); 22 | 23 | typedef struct fdb_thread_task_t 24 | { 25 | 26 | fdb_thread_task_function_t p_fp; 27 | 28 | void* p_args; 29 | 30 | } fdb_thread_task_t; 31 | 32 | 33 | typedef struct fdb_thread_t 34 | { 35 | #ifdef FDB_OS_LINUX 36 | pthread_t m_pthread; 37 | #endif 38 | } fdb_thread_t; 39 | 40 | 41 | /** 42 | * \brief Starts a thread with the given task 43 | * 44 | * \param thread The thread to start 45 | * \param task The task to run with the thread 46 | */ 47 | void 48 | fdb_thread_start(fdb_thread_t* thread, 49 | fdb_thread_task_t* task); 50 | 51 | /** 52 | * \brief Joins a thread 53 | * 54 | * \param thread The thread to join 55 | */ 56 | void 57 | fdb_thread_join(fdb_thread_t* thread); 58 | 59 | /** 60 | * \brief Kills a thread 61 | * 62 | * \param thread The thread to kill 63 | */ 64 | void 65 | fdb_thread_kill(fdb_thread_t* thread); 66 | 67 | /** 68 | * \brief Sets the affinity for the given thread 69 | * 70 | * \param thread The thread to set the affinity for 71 | * \param cpuid The id of the cpu to set the affinity to 72 | */ 73 | bool 74 | fdb_thread_set_affinity(fdb_thread_t* thread, 75 | uint32_t cpuid); 76 | 77 | /** 78 | * \brief Sets the affinity of the main thread 79 | * 80 | * \param cpuid The id of the cpu to set the affinity to 81 | */ 82 | bool 83 | fdb_thread_set_main_affinity(uint32_t cpuid); 84 | 85 | #ifdef __cplusplus 86 | } 87 | #endif 88 | 89 | 90 | #endif /* ifndef _GS_THREAD_H_ */ 91 | -------------------------------------------------------------------------------- /src/common/types.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _FDB_TYPES_H_ 3 | #define _FDB_TYPES_H_ 4 | 5 | #include 6 | #include 7 | 8 | #ifdef __cplusplus 9 | extern "C" 10 | { 11 | #endif 12 | 13 | typedef uint32_t entity_id_t; 14 | typedef uint32_t table_id_t; 15 | 16 | #ifdef __cplusplus 17 | } 18 | #endif 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /src/common/utils.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef _FDB_UTILS_H_ 4 | #define _FDB_UTILS_H_ 5 | 6 | #include "types.h" 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | /** 13 | * @brief Computes a hash on the given string 14 | * 15 | * @param str The string to compute the hash for 16 | * 17 | * @return Returns the hash of the given string 18 | */ 19 | uint32_t 20 | hash(const char* str); 21 | 22 | #ifdef __cplusplus 23 | } 24 | #endif 25 | 26 | #endif /* ifndef _FURIOUS_UTILS_H_ */ 27 | -------------------------------------------------------------------------------- /src/compiler/backend/codegen.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef _FDB_COMPILER_CODEGEN_H_ 4 | #define _FDB_COMPILER_CODEGEN_H_ value 5 | 6 | #include "common/platform.h" 7 | 8 | 9 | struct fcc_exec_plan_t; 10 | 11 | /** 12 | * \brief This function generates the code for a given execution plan and prints 13 | * it to the provided filename. The technique used to generate the code is that 14 | * published in the paper: 15 | * @article{neumann2011efficiently, 16 | * title={Efficiently compiling efficient query plans for modern hardware}, 17 | * author={Neumann, Thomas}, 18 | * journal={Proceedings of the VLDB Endowment}, 19 | * volume={4}, 20 | * number={9}, 21 | * pages={539--550}, 22 | * year={2011}, 23 | * publisher={VLDB Endowment} 24 | * } 25 | * 26 | * \param exec_plan The execution plan to generate the code for 27 | * \param filename The file where the code is going to be written. 28 | */ 29 | int32_t 30 | fcc_generate_code(const fcc_exec_plan_t* exec_plan, 31 | const fcc_exec_plan_t* post_exec_plan, 32 | const char* filename, 33 | const char* include_file); 34 | 35 | 36 | 37 | 38 | 39 | #endif /* ifndef _FDB_COMPILER_CODEGEN_H_ */ 40 | -------------------------------------------------------------------------------- /src/compiler/backend/codegen_tools.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _FURIOUS_CODEGEN_TOOLS_H_ 3 | #define _FURIOUS_CODEGEN_TOOLS_H_ 4 | 5 | #include "../../common/platform.h" 6 | #include "../driver.h" 7 | #include "../fcc_context.h" 8 | 9 | /* AUTOGENERATED INCLUDES */ 10 | #include "autogen/cchar_ptr_array.h" 11 | #include "autogen/fcc_decl_array.h" 12 | 13 | #include 14 | #include 15 | 16 | struct fcc_subplan_t; 17 | struct fcc_operator_t; 18 | 19 | /** 20 | * @brief Tool used to extract the dependencies of an execution plan, which 21 | * include structures and headers including dependent structures 22 | */ 23 | struct fcc_deps_extr_t 24 | { 25 | cchar_ptr_array_t m_incs; 26 | fcc_decl_array_t m_decls; 27 | }; 28 | 29 | void 30 | fcc_deps_extr_init(fcc_deps_extr_t* deps_extr); 31 | 32 | void 33 | fcc_deps_extr_release(fcc_deps_extr_t* deps_extr); 34 | 35 | void 36 | fcc_deps_extr_extract(fcc_deps_extr_t* deps_extr, 37 | const fcc_subplan_t* subplan); 38 | 39 | //////////////////////////////////////////////// 40 | //////////////////////////////////////////////// 41 | //////////////////////////////////////////////// 42 | 43 | 44 | /** 45 | * \brief Tool to extract the components and tags used in an execution plan, which will 46 | * be used to declare the required variables in the generated code. 47 | */ 48 | struct fcc_vars_extr_t 49 | { 50 | fcc_decl_array_t m_comp_decls; 51 | cchar_ptr_array_t m_tags; 52 | cchar_ptr_array_t m_refs; 53 | cchar_ptr_array_t m_comps; 54 | }; 55 | 56 | void 57 | fcc_vars_extr_init(fcc_vars_extr_t* vars_extr); 58 | 59 | void 60 | fcc_vars_extr_release(fcc_vars_extr_t* vars_extr); 61 | 62 | void 63 | fcc_vars_extr_extract(fcc_vars_extr_t* vars_extr, 64 | const fcc_subplan_t* subplan); 65 | 66 | //////////////////////////////////////////////// 67 | //////////////////////////////////////////////// 68 | //////////////////////////////////////////////// 69 | 70 | void 71 | sanitize_name(char* str); 72 | 73 | uint32_t 74 | generate_table_name(const char* type_name, 75 | char* buffer, 76 | uint32_t buffer_length, 77 | const fcc_operator_t* op = nullptr); 78 | 79 | uint32_t 80 | generate_temp_table_name(const char* type_name, 81 | char* buffer, 82 | uint32_t buffer_length, 83 | const fcc_operator_t* op = nullptr); 84 | 85 | uint32_t 86 | generate_ref_table_name(const char* ref_name, 87 | char* buffer, 88 | uint32_t buffer_length, 89 | const fcc_operator_t* op = nullptr); 90 | 91 | uint32_t 92 | generate_bittable_name(const char* tag_name, 93 | char* buffer, 94 | uint32_t buffer_length, 95 | const fcc_operator_t* op = nullptr); 96 | 97 | uint32_t 98 | generate_table_iter_name(const char* table_name, 99 | char* buffer, 100 | uint32_t buffer_length, 101 | const fcc_operator_t* op = nullptr); 102 | 103 | uint32_t 104 | generate_block_name(const char* type_name, 105 | char* buffer, 106 | uint32_t buffer_length, 107 | const fcc_operator_t* op = nullptr); 108 | 109 | uint32_t 110 | generate_cluster_name(const fcc_operator_t* op, 111 | char* buffer, 112 | uint32_t buffer_length); 113 | 114 | uint32_t 115 | generate_ref_groups_name(const char* ref_name, 116 | char* buffer, 117 | uint32_t buffer_length, 118 | const fcc_operator_t* op); 119 | 120 | uint32_t 121 | generate_hashtable_name(const fcc_operator_t* op, 122 | char* buffer, 123 | uint32_t buffer_length); 124 | 125 | uint32_t 126 | generate_system_wrapper_name(const char* system_name, 127 | uint32_t system_id, 128 | char* buffer, 129 | uint32_t buffer_length, 130 | const fcc_operator_t* op = nullptr); 131 | 132 | uint32_t 133 | generate_global_name(const char* type_name, 134 | char* buffer, 135 | uint32_t buffer_length, 136 | const fcc_operator_t* op = nullptr); 137 | 138 | 139 | #endif 140 | -------------------------------------------------------------------------------- /src/compiler/backend/consumer.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _FURIOUS_COMPILER_CONSUMER_H_ 3 | #define _FURIOUS_COMPILER_CONSUMER_H_ value 4 | 5 | #include 6 | 7 | struct fcc_operator_t; 8 | 9 | /** 10 | * \brief Visitor that implements the consume operation for generating code 11 | */ 12 | void 13 | consume(FILE* fd, 14 | const fcc_operator_t* op, 15 | const char* source, 16 | const fcc_operator_t* caller); 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /src/compiler/backend/producer.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _FURIOUS_COMPILER_PRODUCER_H_ 3 | #define _FURIOUS_COMPILER_PRODUCER_H_ value 4 | 5 | #include 6 | 7 | 8 | struct fcc_operator_t; 9 | 10 | /** 11 | * \brief Implements the produce operation for generating code 12 | */ 13 | void 14 | produce(FILE* fd, 15 | const fcc_operator_t* fcc_operator, 16 | bool parallel_stream); 17 | 18 | #endif /* ifndef _FURIOUS_COMPILER_PRODUCE_VISITOR */ 19 | -------------------------------------------------------------------------------- /src/compiler/backend/reflection.cpp: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include "../common/common.h" 4 | #include "../../common/str_builder.h" 5 | #include "reflection.h" 6 | #include "codegen_tools.h" 7 | #include "../../runtime/data/reflection.h" 8 | 9 | #include 10 | 11 | 12 | 13 | const char* fdb_mtype_str[(uint32_t)fdb_mtype_t::E_NUM_TYPES] = { 14 | "fdb_mtype_t::E_BOOL", 15 | "fdb_mtype_t::E_CHAR", 16 | "fdb_mtype_t::E_UINT8", 17 | "fdb_mtype_t::E_UINT16", 18 | "fdb_mtype_t::E_UINT32", 19 | "fdb_mtype_t::E_UINT64", 20 | "fdb_mtype_t::E_INT8", 21 | "fdb_mtype_t::E_INT16", 22 | "fdb_mtype_t::E_INT32", 23 | "fdb_mtype_t::E_INT64", 24 | "fdb_mtype_t::E_FLOAT", 25 | "fdb_mtype_t::E_DOUBLE", 26 | "fdb_mtype_t::E_CHAR_POINTER", 27 | "fdb_mtype_t::E_STD_STRING", 28 | "fdb_mtype_t::E_POINTER", 29 | "fdb_mtype_t::E_STRUCT", 30 | "fdb_mtype_t::E_UNION", 31 | "fdb_mtype_t::E_UNKNOWN", 32 | }; 33 | 34 | 35 | void 36 | generate_reflection_code(FILE* fd, 37 | fdb_mstruct_t* refl_data, 38 | const char* root, 39 | const char* path, 40 | char* var_name) 41 | { 42 | for(uint32_t i = 0; i < refl_data->m_nfields; ++i) 43 | { 44 | fdb_mfield_t* field = refl_data->p_fields[i]; 45 | fprintf(fd,"{\n"); 46 | fprintf(fd, "char field_name[FCC_MAX_FIELD_NAME];\n"); 47 | fprintf(fd, "strcpy(field_name,\"%s\");\n", field->m_name); 48 | fprintf(fd, "fdb_mtype_t type = %s;\n", fdb_mtype_str[(uint32_t)field->m_type]); 49 | fprintf(fd, "bool is_anon = %s;\n", field->m_anonymous ? "true" : "false"); 50 | fdb_str_builder_t str_builder; 51 | fdb_str_builder_init(&str_builder); 52 | if(field->m_anonymous) 53 | { 54 | fprintf(fd, "uint32_t offset = 0;\n"); 55 | if(strcmp(path,"")==0) // is first level 56 | { 57 | fdb_str_builder_append(&str_builder, "%s", ""); 58 | } 59 | else 60 | { 61 | fdb_str_builder_append(&str_builder, "%s", path); 62 | } 63 | } 64 | else 65 | { 66 | if(strcmp(path,"")==0) // is first level 67 | { 68 | fdb_str_builder_append(&str_builder, "%s", field->m_name); 69 | fprintf(fd, "uint32_t offset = offsetof(%s, %s);\n", root, str_builder.p_buffer); 70 | } 71 | else 72 | { 73 | fdb_str_builder_append(&str_builder, "%s.%s", path, field->m_name); 74 | 75 | fprintf(fd, "uint32_t offset = offsetof(%s, %s) - offsetof(%s, %s);\n", 76 | root, 77 | str_builder.p_buffer, 78 | root, 79 | path); 80 | } 81 | } 82 | 83 | if(field->m_type == fdb_mtype_t::E_STRUCT || field->m_type == fdb_mtype_t::E_UNION) 84 | { 85 | char tmp[FCC_MAX_TYPE_NAME]; 86 | FDB_COPY_AND_CHECK_STR(tmp, field->m_name, FCC_MAX_TYPE_NAME); 87 | sanitize_name(tmp); 88 | fdb_str_builder_t field_builder; 89 | fdb_str_builder_init(&field_builder); 90 | fdb_str_builder_append(&field_builder, "ref_data_"); 91 | fdb_str_builder_append(&field_builder, tmp); 92 | fprintf(fd, "fdb_mstruct_t* %s = fdb_mregistry_init_mfield(reg, %s, field_name, type, offset, is_anon);\n", field_builder.p_buffer, var_name); 93 | fprintf(fd,"{\n"); 94 | generate_reflection_code(fd, 95 | field->p_strct_type, 96 | root, 97 | str_builder.p_buffer, 98 | field_builder.p_buffer); 99 | fdb_str_builder_release(&field_builder); 100 | fprintf(fd,"}\n"); 101 | } 102 | else 103 | { 104 | fprintf(fd, "fdb_mregistry_init_mfield(reg, %s, field_name, type, offset, is_anon);\n", var_name); 105 | } 106 | fprintf(fd,"}\n"); 107 | fdb_str_builder_release(&str_builder); 108 | } 109 | } 110 | 111 | void 112 | generate_reflection_code(FILE* fd, fcc_decl_t decl) 113 | { 114 | fprintf(fd,"{\n"); 115 | fprintf(fd, "fdb_mregistry_t* reg = fdb_database_get_mregistry(database);\n"); 116 | fdb_mregistry_t reg; 117 | fdb_mregistry_init(®, NULL); 118 | fdb_mstruct_t* mstruct = get_reflection_data(decl, ®); 119 | 120 | char tmp[FCC_MAX_TYPE_NAME]; 121 | FDB_COPY_AND_CHECK_STR(tmp, mstruct->m_type_name, FCC_MAX_TYPE_NAME); 122 | sanitize_name(tmp); 123 | fdb_str_builder_t str_builder; 124 | fdb_str_builder_init(&str_builder); 125 | fdb_str_builder_append(&str_builder, "ref_data_"); 126 | fdb_str_builder_append(&str_builder, tmp); 127 | fprintf(fd, "fdb_mstruct_t* %s = fdb_mregistry_init_mstruct(reg, \"%s\", %d );\n", 128 | str_builder.p_buffer, 129 | mstruct->m_type_name, 130 | mstruct->m_is_union); 131 | generate_reflection_code(fd, 132 | mstruct, 133 | mstruct->m_type_name, 134 | "", 135 | str_builder.p_buffer); 136 | fdb_str_builder_release(&str_builder); 137 | fprintf(fd,"}\n"); 138 | fdb_mregistry_release(®); 139 | } 140 | 141 | -------------------------------------------------------------------------------- /src/compiler/backend/reflection.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef _FURIOUS_FCC_REFLECTION_H_ 4 | #define _FURIOUS_FCC_REFLECTION_H_ value 5 | 6 | #include 7 | #include "../fcc_context.h" 8 | 9 | void 10 | generate_reflection_code(FILE* fp, fcc_decl_t decl); 11 | 12 | #endif /* ifndef _FURIOUS_FCC_REFLECTION_H_ */ 13 | -------------------------------------------------------------------------------- /src/compiler/drivers/clang/ast_visitor.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _FURIOUS_FCCASTVISITOR_H_ 3 | #define _FURIOUS_FCCASTVISITOR_H_ 4 | 5 | #include 6 | #include 7 | 8 | #include "fcc_context.h" 9 | 10 | using namespace clang; 11 | 12 | 13 | struct FccContext; 14 | 15 | /** 16 | * @brief Visitor that extracts the execution information of a an expression with 17 | * cleanups. 18 | */ 19 | class FuriousExprVisitor : public RecursiveASTVisitor 20 | { 21 | private: 22 | ASTContext *p_ast_context; // used for getting additional AST info 23 | 24 | public: 25 | fcc_stmt_t* p_fcc_stmt; 26 | 27 | FuriousExprVisitor(ASTContext *ast_context); 28 | 29 | fcc_stmt_t* 30 | parse_expression(Expr* expr); 31 | 32 | virtual 33 | bool TraverseLambdaBody(LambdaExpr* expr); 34 | 35 | virtual 36 | bool VisitCallExpr(CallExpr* call); 37 | 38 | }; 39 | 40 | //////////////////////////////////////////////// 41 | //////////////////////////////////////////////// 42 | //////////////////////////////////////////////// 43 | 44 | /** 45 | * @brief Visitor that triggers a FuriousScriptVisitor on the body of the 46 | * furious_script function. 47 | */ 48 | class FccASTVisitor : public RecursiveASTVisitor 49 | { 50 | private: 51 | ASTContext* p_ast_context; // used for getting additional AST info 52 | 53 | public: 54 | explicit FccASTVisitor(ASTContext* ast_context); 55 | 56 | virtual 57 | bool VisitFunctionDecl(FunctionDecl* func); 58 | }; 59 | 60 | #endif /* ifndef _FURIOUS_CLANGASTVISITOR_H_ */ 61 | -------------------------------------------------------------------------------- /src/compiler/drivers/clang/clang.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef _FURIOUS_CLANG_H_H 4 | #define _FURIOUS_CLANG_H_H 5 | 6 | #include "../../../common/types.h" 7 | 8 | 9 | namespace clang 10 | { 11 | class Expr; 12 | class ASTContext; 13 | class QualType; 14 | class SourceManager; 15 | class SourceLocation; 16 | } 17 | 18 | using namespace clang; 19 | 20 | 21 | struct clang_expr_handler_t 22 | { 23 | const Expr* p_expr; 24 | ASTContext* p_context; 25 | }; 26 | 27 | QualType* 28 | push_type(QualType qtype); 29 | 30 | clang_expr_handler_t* 31 | push_expr(ASTContext* ctx, 32 | const Expr* expr); 33 | 34 | #endif /* ifndef _FURIOUS_CLANG_H_H */ 35 | -------------------------------------------------------------------------------- /src/compiler/dyn_array.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef _FURIOUS_DYNAMIC_ARRAY_H_ 4 | #define _FURIOUS_DYNAMIC_ARRAY_H_ 5 | 6 | #include "../common/platform.h" 7 | #include "../common/memory/memory.h" 8 | 9 | #include 10 | #include 11 | 12 | template 13 | struct DynArray 14 | { 15 | DynArray(fdb_mem_allocator_t* allocator = nullptr); 16 | DynArray(const DynArray&); 17 | DynArray(DynArray&&); 18 | DynArray(std::initializer_list); 19 | 20 | ~DynArray(); 21 | 22 | //////////////////////////////////////////////// 23 | //////////////////////////////////////////////// 24 | //////////////////////////////////////////////// 25 | 26 | uint32_t 27 | size() const; 28 | 29 | void 30 | clear(); 31 | 32 | //void 33 | //reset(); 34 | 35 | void 36 | append(const T&); 37 | 38 | void 39 | append(const DynArray&); 40 | 41 | void 42 | append(T&&); 43 | 44 | void 45 | pop(); 46 | 47 | T& 48 | get(uint32_t index); 49 | 50 | T& 51 | operator[](std::size_t index); 52 | 53 | const T& 54 | operator[](std::size_t index) const; 55 | 56 | DynArray& 57 | operator=(const DynArray&); 58 | 59 | DynArray& 60 | operator=(DynArray&&); 61 | 62 | T* 63 | buffer() const; 64 | 65 | private: 66 | 67 | 68 | char* p_data; 69 | uint32_t m_capacity; 70 | uint32_t m_num_elements; 71 | fdb_mem_allocator_t m_allocator; 72 | }; 73 | 74 | #endif 75 | 76 | #include "dyn_array.inl" 77 | -------------------------------------------------------------------------------- /src/compiler/fcc.cpp: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include "fcc_context.h" 4 | 5 | int main(int argc, const char **argv) 6 | { 7 | int result = fcc_run(argc, argv); 8 | return result; 9 | } 10 | -------------------------------------------------------------------------------- /src/compiler/frontend/exec_plan.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _FURIOUS_EXECUTION_PLAN_H_ 3 | #define _FURIOUS_EXECUTION_PLAN_H_ 4 | 5 | #include "../common/types.h" 6 | #include "fcc_context.h" 7 | 8 | // autogen includes 9 | #include "autogen/uint32_array.h" 10 | 11 | 12 | struct fcc_subplan_t; 13 | 14 | //////////////////////////////////////////////// 15 | //////////////////////////////////////////////// 16 | //////////////////////////////////////////////// 17 | 18 | struct fcc_exec_plan_node_t 19 | { 20 | uint32_array_t m_parents; 21 | uint32_array_t m_children; 22 | }; 23 | 24 | struct fcc_exec_plan_t 25 | { 26 | // Graph members 27 | fcc_exec_plan_node_t* m_nodes; 28 | uint32_t* m_roots; 29 | 30 | // Node attributes 31 | const fcc_stmt_t** p_stmts; 32 | fcc_subplan_t** m_subplans; 33 | 34 | uint32_t m_maxnodes; 35 | uint32_t m_nnodes; 36 | uint32_t m_nroots; 37 | }; 38 | 39 | /** 40 | * \brief Inserts a fcc_stmt_t to the dependency graph 41 | * 42 | * \param exec_plan The exec_plan to insert the stmts to 43 | * \param stmt The fcc_stmt_t to add 44 | * 45 | */ 46 | void 47 | fcc_exec_plan_insert(fcc_exec_plan_t* exec_plan, 48 | const fcc_stmt_t* stmt); 49 | 50 | 51 | /** 52 | * \brief Checks if the graph is acyclic 53 | * 54 | * \return Returns true if the graph is acyclyc 55 | */ 56 | bool 57 | fcc_exec_plan_is_acyclic(const fcc_exec_plan_t* exec_plan); 58 | 59 | /** 60 | * \brief Gets a valid execution sequence from a given root node 61 | * 62 | * \param exec_plan The exec plan to get the valid sequence from 63 | * \param root The id of the root node to start the sequence from 64 | * 65 | * \return An array with the sequence of node ids. 66 | */ 67 | void 68 | fcc_exec_plan_get_valid_exec_sequence(const fcc_exec_plan_t* exec_plan, 69 | uint32_t* seq, 70 | uint32_t nseq); 71 | 72 | /** 73 | * \brief inits an excution plan out of a sequence of fcc_stmt_t statements 74 | * 75 | * \param stmts[] The array of fcc_stmt_t 76 | * \param num_stmts The number of matches in the array 77 | * \param exec_plan The output execution plan 78 | * 79 | * \return Returns NO_ERROR if succeeds. The corresponding error code otherwise 80 | */ 81 | fcc_compilation_error_type_t 82 | fcc_exec_plan_init(fcc_exec_plan_t* exec_plan, 83 | const fcc_stmt_t* stmts[], 84 | uint32_t num_stmts); 85 | 86 | /** 87 | * \brief releases the execution plan 88 | * 89 | * \param exec_plan The execution plan to release 90 | */ 91 | void 92 | fcc_exec_plan_release(fcc_exec_plan_t* exec_plan); 93 | 94 | 95 | #endif /* ifndef SYMBOL */ 96 | -------------------------------------------------------------------------------- /src/compiler/frontend/exec_plan_printer.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _FURIOUS_COMPILER_PRITER_H_ 3 | #define _FURIOUS_COMPILER_PRITER_H_ 4 | 5 | #include "exec_plan.h" 6 | #include "../common/str_builder.h" 7 | 8 | // Autogen includes 9 | #include "autogen/char_array.h" 10 | 11 | #define _FCC_SUBPLAN_PRINTER_MAX_OFFSETS 256 // This value must be even 12 | 13 | struct fcc_subplan_printer_t 14 | { 15 | int32_t m_indents; 16 | fdb_str_builder_t m_str_builder; 17 | char_array_t m_offsets; 18 | bool m_c_src_string; 19 | }; 20 | 21 | void 22 | fcc_subplan_printer_init(fcc_subplan_printer_t* printer, 23 | bool c_src_string = false, 24 | bool add_comments = false); 25 | 26 | void 27 | fcc_subplan_printer_release(fcc_subplan_printer_t* printer); 28 | 29 | void 30 | fcc_subplan_printer_print(fcc_subplan_printer_t* printer, 31 | const fcc_subplan_t* plan); 32 | 33 | #endif /* ifndef _FURIOUS_COMPILER_PRITER_H_ */ 34 | -------------------------------------------------------------------------------- /src/compiler/frontend/transforms.cpp: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include "transforms.h" 4 | #include "exec_plan.h" 5 | #include "fcc_context.h" 6 | 7 | Foreach* 8 | merge_foreach(const Foreach* foreach1, 9 | const Foreach* foreach2) { 10 | return nullptr; 11 | } 12 | -------------------------------------------------------------------------------- /src/compiler/frontend/transforms.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef _FURIOUS_COMPILER_TRANSFORMS_H_ 4 | #define _FURIOUS_COMPILER_TRANSFORMS_H_ 5 | 6 | 7 | struct Foreach; 8 | struct FccContext; 9 | struct FccMatch; 10 | struct FccOperator; 11 | 12 | /** 13 | * @brief Merges two Foreach operators into a new one. The new Foreach operator 14 | * executes the functions of the two original foreach over the children table. 15 | * 16 | * @param context The Fcc compilation context 17 | * @param foreach1 The first Foreach to merge 18 | * @param foreach2 The secont Foreach to merge 19 | * 20 | * @return A newly created Foreach resulting of merging the two input Foreach. 21 | */ 22 | Foreach* 23 | merge_foreach(FccContext* context, 24 | const Foreach* foreach1, 25 | const Foreach* foreach2); 26 | 27 | 28 | 29 | 30 | 31 | #endif /* ifndef _FURIOUS_COMPILER_TRANSFORMS_H_ */ 32 | -------------------------------------------------------------------------------- /src/components.h: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/furious.c: -------------------------------------------------------------------------------- 1 | 2 | #include "furious.h" 3 | -------------------------------------------------------------------------------- /src/furious.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef _FDB_H_ 4 | #define _FDB_H_ 5 | 6 | #include "common/common.h" 7 | #include "runtime/runtime.h" 8 | #include "lang/macros.h" 9 | #include 10 | #include 11 | 12 | extern void 13 | furious_init(fdb_database_t* database); 14 | 15 | extern void 16 | furious_frame(float delta, 17 | fdb_database_t* database, 18 | void* user_data); 19 | 20 | extern void 21 | furious_post_frame(float delta, 22 | fdb_database_t* database, 23 | void* user_data); 24 | 25 | extern fdb_task_graph_t* 26 | furious_task_graph(); 27 | 28 | extern fdb_task_graph_t* 29 | furious_post_task_graph(); 30 | 31 | extern void 32 | furious_release(); 33 | 34 | void 35 | furious_set_log_func(fdb_log_func_t log_function); 36 | #endif /* ifndef _FURIOUS_H_ */ 37 | -------------------------------------------------------------------------------- /src/furious_macros.h: -------------------------------------------------------------------------------- 1 | 2 | #include "runtime/data/macros.h" 3 | #include "lang/macros.h" 4 | -------------------------------------------------------------------------------- /src/lang/macros.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _FURIOUS_LANG_MACROS_H_ 3 | #define _FURIOUS_LANG_MACROS_H_ 4 | 5 | #define FURIOUS_ENABLE_COMPONENT(context, Component, id)\ 6 | context->enable_component(#Component, id) 7 | 8 | #define FURIOUS_DISABLE_COMPONENT(context, Component, id)\ 9 | context->disable_component(#Component, id) 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /src/lang_test.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "lang_test.h" 3 | #include "lang/lang.h" 4 | 5 | struct ComponentC { 6 | int32_t m_field; 7 | }; 8 | 9 | bool test1(const ComponentA* ca, 10 | const ComponentC* cc, 11 | const ComponentB* cb) 12 | { 13 | return true; 14 | } 15 | 16 | BEGIN_FDB_SCRIPT 17 | 18 | struct TestSystem1 19 | { 20 | TestSystem1(int32_t val, float val2) : m_val{val} {} 21 | 22 | void run(fdb_context_t* context, 23 | uint32_t id, 24 | ComponentA *componentA, 25 | const ComponentC* componentC, 26 | const ComponentB *componentB) 27 | { 28 | componentA->m_field = componentB->m_field * m_val + componentC->m_field; 29 | }; 30 | 31 | int32_t m_val; 32 | }; 33 | 34 | match() 35 | .has_component() 36 | .has_not_component() 37 | .has_tag("Affected") 38 | .has_not_tag("NotAffected") 39 | .filter([](const ComponentA* ca, const ComponentC* cc, const ComponentB* cb) 40 | { 41 | return test1(ca,cc,cb); 42 | } 43 | ) 44 | .filter(test1).foreach(10,0.2); 45 | 46 | 47 | //select().foreach(10,0.2); 48 | 49 | //////////////////////////////////////////////// 50 | //////////////////////////////////////////////// 51 | //////////////////////////////////////////////// 52 | 53 | struct TestSystem2 54 | { 55 | TestSystem2(float val) : m_val{val} {} 56 | 57 | void run(fdb_context_t* context, 58 | uint32_t id, 59 | ComponentA* componentA, 60 | const ComponentB *componentB) 61 | { 62 | componentA->m_field = componentB->m_field * m_val; 63 | }; 64 | 65 | float m_val; 66 | }; 67 | 68 | match().expand("edge name").foreach(1.0); 69 | 70 | 71 | END_FDB_SCRIPT 72 | 73 | // This is just to not let the compiler and linker complain with warnings or 74 | // errors 75 | int main(int argc, 76 | char **argv) 77 | { 78 | furious_script(); 79 | return 0; 80 | } 81 | -------------------------------------------------------------------------------- /src/lang_test.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef _LANG_TEST_H_ 4 | #define _LANG_TEST_H_ 5 | 6 | #include "common/common.h" 7 | 8 | struct ComponentA 9 | { 10 | int32_t m_field; 11 | }; 12 | 13 | struct ComponentB 14 | { 15 | int32_t m_field; 16 | }; 17 | 18 | 19 | 20 | #endif /* ifndef _FURIOUS_LANG_TEST_H_ */ 21 | -------------------------------------------------------------------------------- /src/runtime/data/bittable.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef _FDB_BITTABLE_H_ 4 | #define _FDB_BITTABLE_H_ 5 | 6 | #include "../../common/platform.h" 7 | #include "../../common/bitmap.h" 8 | #include "../../common/btree.h" 9 | 10 | #include 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | typedef enum fdb_bittable_op_t 17 | { 18 | E_AND, 19 | E_OR, 20 | E_DIFF 21 | } fdb_bittable_op_t; 22 | 23 | typedef struct fdb_bittable_t 24 | { 25 | fdb_btree_t m_bitmaps; 26 | uint32_t m_size; 27 | fdb_pool_alloc_t m_bitmap_allocator; 28 | fdb_pool_alloc_t m_bitmap_data_allocator; 29 | } fdb_bittable_t; 30 | 31 | /** 32 | * \brief inits a bittable 33 | * 34 | * \param allocator The memory allocator to use in the bittable 35 | * 36 | * \return Returns a newly initd bittable 37 | */ 38 | 39 | void 40 | fdb_bittable_init(fdb_bittable_t* bt, 41 | fdb_mem_allocator_t* allocator); 42 | 43 | 44 | /** 45 | * \brief releases a bittable 46 | * 47 | * \param bittable 48 | */ 49 | void 50 | fdb_bittable_release(fdb_bittable_t* bittable); 51 | 52 | /** 53 | * \brief Tests if an element exists in the bit table 54 | * 55 | * \param bittable The bittable to check the existence of the entity 56 | * \param id The id of the element to test 57 | * 58 | * \return Returns true if the element exists. false otherwise. 59 | */ 60 | bool 61 | fdb_bittable_exists(const fdb_bittable_t* bittable, 62 | entity_id_t id); 63 | 64 | /** 65 | * \brief Adds an element to the bit table 66 | * 67 | * \param bittable The bittable to add the entity to 68 | * \param id The id of the entity to add 69 | */ 70 | void 71 | fdb_bittable_add(fdb_bittable_t* bittable, 72 | entity_id_t id); 73 | 74 | /** 75 | * \brief Removes an element from the bit table 76 | * 77 | * \param bittable The bittable to remove the entity from 78 | * \param id The id of the entity to remove 79 | */ 80 | void 81 | fdb_bittable_remove(fdb_bittable_t* bittable, entity_id_t id); 82 | 83 | /** 84 | * \brief Gets the bitmap of the bit table for a specific entity id. 85 | * 86 | * \param bittable The bittable to get the bitmap from 87 | * \param id The id of the entity to get the bitmap of 88 | * 89 | * \return Returns a pointer to the bitmap. Returns nullptr if the bitmap does 90 | * not exist. 91 | */ 92 | const fdb_bitmap_t* 93 | fdb_bittable_get_bitmap(const fdb_bittable_t* bittable, 94 | entity_id_t id) ; 95 | 96 | /** 97 | * \brief Gets the size of the bittable (number of bits set to 1) 98 | * 99 | * \param bittable The bittable to get the size of 100 | * 101 | * \return The size of the bit table 102 | */ 103 | uint32_t 104 | fdb_bittable_size(const fdb_bittable_t* bittable); 105 | 106 | /** 107 | * \brief Clears the bittable 108 | */ 109 | void 110 | fdb_bittable_clear(fdb_bittable_t* bittable); 111 | 112 | void 113 | fdb_bittable_union(FDB_RESTRICT(fdb_bittable_t*) first, FDB_RESTRICT(const fdb_bittable_t*) second); 114 | 115 | void 116 | fdb_bittable_difference(FDB_RESTRICT(fdb_bittable_t*) first, FDB_RESTRICT(const fdb_bittable_t*) second); 117 | 118 | #ifdef __cplusplus 119 | } 120 | #endif 121 | 122 | #endif /* ifndef _FDB_BIT_TABLE_H_ */ 123 | -------------------------------------------------------------------------------- /src/runtime/data/block_cluster.c: -------------------------------------------------------------------------------- 1 | 2 | #include "block_cluster.h" 3 | #include "../../common/platform.h" 4 | #include "table.h" 5 | #include "../../common/bitmap.h" 6 | #include "string.h" 7 | 8 | 9 | #define FDB_INVALID_BLOCK_START 0xffffffff 10 | 11 | void 12 | fdb_bcluster_init(fdb_bcluster_t* bc, fdb_mem_allocator_t* allocator) 13 | { 14 | FDB_ASSERT(((allocator == NULL) || 15 | (allocator->p_mem_alloc != NULL && allocator->p_mem_free != NULL)) && 16 | "Provided allocator is ill-formed.") 17 | bc->m_num_columns = 0; 18 | bc->m_start = FDB_INVALID_BLOCK_START; 19 | fdb_bitmap_init(&bc->m_enabled, 20 | FDB_TABLE_BLOCK_SIZE, 21 | allocator != NULL ? allocator : fdb_get_global_mem_allocator()); 22 | fdb_bitmap_init(&bc->m_global, 23 | FDB_MAX_CLUSTER_SIZE, 24 | allocator != NULL ? allocator : fdb_get_global_mem_allocator()); 25 | memset(&bc->p_blocks,0, sizeof(void*)*FDB_MAX_CLUSTER_SIZE); 26 | } 27 | 28 | void 29 | fdb_bcluster_release(fdb_bcluster_t* bc, 30 | fdb_mem_allocator_t* allocator) 31 | { 32 | FDB_ASSERT(((allocator == NULL) || 33 | (allocator->p_mem_alloc != NULL && allocator->p_mem_free != NULL)) && 34 | "Provided allocator is ill-formed.") 35 | 36 | fdb_bitmap_release(&bc->m_enabled, allocator != NULL ? allocator : fdb_get_global_mem_allocator()); 37 | fdb_bitmap_release(&bc->m_global, allocator != NULL ? allocator : fdb_get_global_mem_allocator()); 38 | } 39 | 40 | void 41 | fdb_bcluster_append_block(fdb_bcluster_t* bc, 42 | fdb_table_block_t* block) 43 | { 44 | FDB_ASSERT(bc->m_num_columns < FDB_MAX_CLUSTER_SIZE && "Cannot append block to full cluster"); 45 | FDB_ASSERT((bc->m_start == FDB_INVALID_BLOCK_START || bc->m_start == block->m_start ) && "Unaligned block cluster"); 46 | 47 | if(bc->m_start == FDB_INVALID_BLOCK_START) 48 | { 49 | bc->m_start = block->m_start; 50 | fdb_bitmap_set_bitmap(&bc->m_enabled, &block->m_enabled); 51 | } 52 | 53 | bc->p_blocks[bc->m_num_columns] = block; 54 | bc->m_num_columns++; 55 | fdb_bitmap_set_and(&bc->m_enabled, &block->m_enabled); 56 | } 57 | 58 | void 59 | fdb_bcluster_append_global(fdb_bcluster_t* bc, 60 | void* global) 61 | { 62 | fdb_bitmap_set(&bc->m_global, bc->m_num_columns); 63 | bc->p_blocks[bc->m_num_columns] = global; 64 | bc->m_num_columns++; 65 | } 66 | 67 | void 68 | fdb_bcluster_append_cluster(FDB_RESTRICT(fdb_bcluster_t*) bc, 69 | FDB_RESTRICT(const fdb_bcluster_t*) other) 70 | { 71 | FDB_ASSERT(((bc->m_start == other->m_start) || 72 | (bc->m_start == FDB_INVALID_BLOCK_START || other->m_start == FDB_INVALID_BLOCK_START) )&& 73 | "Trying to append unaligned blockclusters with different start values"); 74 | 75 | if(other->m_start != FDB_INVALID_BLOCK_START) 76 | { 77 | if(bc->m_start == FDB_INVALID_BLOCK_START) 78 | { 79 | fdb_bitmap_set_bitmap(&bc->m_enabled, &other->m_enabled); 80 | } 81 | else 82 | { 83 | fdb_bitmap_set_and(&bc->m_enabled, &other->m_enabled); 84 | } 85 | bc->m_start = other->m_start; 86 | } 87 | 88 | for(size_t i = 0; i < other->m_num_columns; ++i) 89 | { 90 | FDB_ASSERT(bc->m_num_columns < FDB_MAX_CLUSTER_SIZE && "Cannot append cluster. Not enough room"); 91 | bc->p_blocks[bc->m_num_columns] = other->p_blocks[i]; 92 | if(fdb_bitmap_is_set(&other->m_global, i)) 93 | { 94 | fdb_bitmap_set(&bc->m_global, bc->m_num_columns); 95 | } 96 | bc->m_num_columns++; 97 | } 98 | } 99 | 100 | void 101 | fdb_bcluster_filter(FDB_RESTRICT(fdb_bcluster_t*) bc, 102 | FDB_RESTRICT(const fdb_bcluster_t*) other) 103 | { 104 | fdb_bitmap_set_and(&bc->m_enabled, &other->m_enabled); 105 | } 106 | 107 | fdb_table_block_t* 108 | fdb_bcluster_get_tblock(fdb_bcluster_t* bc, 109 | uint32_t index) 110 | { 111 | FDB_ASSERT(!fdb_bitmap_is_set(&bc->m_global, index) && "Trying to get fdb_table_block_t which is a global from a BlockCluster"); 112 | return (fdb_table_block_t*)bc->p_blocks[index]; 113 | } 114 | 115 | void* 116 | fdb_bcluster_get_global(fdb_bcluster_t* bc, 117 | uint32_t index) 118 | { 119 | FDB_ASSERT(fdb_bitmap_is_set(&bc->m_global, index) && "Trying to get global which is a fdb_table_block_t from a BlockCluster"); 120 | return bc->p_blocks[index]; 121 | } 122 | 123 | bool 124 | fdb_bcluster_has_elements(fdb_bcluster_t* bc) 125 | { 126 | return (bc->m_enabled.m_num_set > 0) || 127 | fdb_bitmap_is_set(&bc->m_global, 0); 128 | } 129 | -------------------------------------------------------------------------------- /src/runtime/data/block_cluster.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _FDB_fdb_bcluster_H_H 3 | #define _FDB_fdb_bcluster_H_H value 4 | 5 | #include "../../common/bitmap.h" 6 | #include "../../common/platform.h" 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | #define FDB_MAX_CLUSTER_SIZE 16 13 | 14 | 15 | typedef struct fdb_table_block_t fdb_table_block_t; 16 | 17 | /** 18 | * \brief This is used to represent a joined block of data, mostly table blocks. 19 | * However, it can also contain pointers to global data. 20 | */ 21 | typedef struct fdb_bcluster_t 22 | { 23 | uint32_t m_num_columns; 24 | fdb_bitmap_t m_enabled; 25 | fdb_bitmap_t m_global; 26 | uint32_t m_start; 27 | void* p_blocks[FDB_MAX_CLUSTER_SIZE]; 28 | } fdb_bcluster_t; 29 | 30 | /** 31 | * \brief inits a block cluster 32 | * 33 | * \param allocator The allocator to use 34 | * 35 | * \return Returns a block cluster 36 | */ 37 | void 38 | fdb_bcluster_init(fdb_bcluster_t* bc, 39 | fdb_mem_allocator_t* allocator); 40 | 41 | /** 42 | * \brief releases a block cluster 43 | * 44 | * \param bc The block cluster to release 45 | */ 46 | void 47 | fdb_bcluster_release(fdb_bcluster_t* bc, 48 | fdb_mem_allocator_t* allocator); 49 | 50 | 51 | /** 52 | * \brief Appends a table block to the block cluster 53 | * 54 | * \param bc The block cluster 55 | * \param block The block to append 56 | */ 57 | void 58 | fdb_bcluster_append_block(fdb_bcluster_t* bc, 59 | fdb_table_block_t* block); 60 | 61 | /** 62 | * \brief Appends a global to the block cluster 63 | * 64 | * \param bc The block cluster 65 | * \param block The global to append 66 | */ 67 | void 68 | fdb_bcluster_append_global(fdb_bcluster_t* bc, 69 | void* global); 70 | 71 | void 72 | fdb_bcluster_append_cluster(FDB_RESTRICT(fdb_bcluster_t*) bc, 73 | FDB_RESTRICT(const fdb_bcluster_t*) other); 74 | 75 | void 76 | fdb_bcluster_filter(FDB_RESTRICT(fdb_bcluster_t*) bc, 77 | FDB_RESTRICT(const fdb_bcluster_t*) other); 78 | 79 | fdb_table_block_t* 80 | fdb_bcluster_get_tblock(fdb_bcluster_t* bc, 81 | uint32_t index); 82 | 83 | void* 84 | fdb_bcluster_get_global(fdb_bcluster_t* bc, 85 | uint32_t index); 86 | 87 | bool 88 | fdb_bcluster_has_elements(fdb_bcluster_t* bc); 89 | 90 | #ifdef __cplusplus 91 | } 92 | #endif 93 | 94 | #endif /* ifndef _FDB_fdb_bcluster_H_H */ 95 | -------------------------------------------------------------------------------- /src/runtime/data/context.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | #include "context.h" 5 | 6 | void 7 | fdb_context_init(fdb_context_t* ctx, 8 | float dt, 9 | struct fdb_database_t* database, 10 | void* user_data, 11 | uint32_t chunk_size, 12 | uint32_t thread_id, 13 | uint32_t num_threads) 14 | { 15 | ctx->m_dt = dt; 16 | ctx->p_user_data = user_data; 17 | ctx->m_chunk_size = chunk_size; 18 | ctx->m_thread_id = thread_id; 19 | ctx->m_num_threads = num_threads; 20 | ctx->p_database = database; 21 | } 22 | -------------------------------------------------------------------------------- /src/runtime/data/context.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef _FURIOUS_CONTEXT_H_ 4 | #define _FURIOUS_CONTEXT_H_ value 5 | 6 | #include "../../common/platform.h" 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | typedef struct fdb_context_t 13 | { 14 | float m_dt; 15 | void* p_user_data; 16 | uint32_t m_chunk_size; 17 | uint32_t m_thread_id; 18 | uint32_t m_num_threads; 19 | struct fdb_database_t* p_database; 20 | } fdb_context_t; 21 | 22 | 23 | void 24 | fdb_context_init(fdb_context_t* ctx, 25 | float dt, 26 | struct fdb_database_t* database, 27 | void* user_data, 28 | uint32_t chunk_size, 29 | uint32_t thread_id, 30 | uint32_t num_threads); 31 | 32 | void 33 | fdb_context_release(fdb_context_t* ctx); 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif 38 | 39 | #endif /* ifndef _FURIOUS_CONTEXT_H_ */ 40 | -------------------------------------------------------------------------------- /src/runtime/data/context.inl: -------------------------------------------------------------------------------- 1 | 2 | #include "database.h" 3 | 4 | 5 | //template 6 | //void Context::enable_component(const std::string& component_name, 7 | // int32_t id) 8 | //{ 9 | // m_to_enable.emplace_back(id, p_database->get_table_id(component_name)); 10 | //} 11 | // 12 | //template 13 | //void Context::disable_component(const std::string& component_name, 14 | // int32_t id) 15 | //{ 16 | // m_to_disable.emplace_back(id, p_database->get_table_id(component_name)); 17 | //} 18 | -------------------------------------------------------------------------------- /src/runtime/data/data.h: -------------------------------------------------------------------------------- 1 | 2 | #include "block_cluster.h" 3 | #include "database.h" 4 | #include "bittable.h" 5 | #include "table.h" 6 | #include "reftable.h" 7 | #include "context.h" 8 | #include "data_utils.h" 9 | #include "reflection.h" 10 | #include "ht_registry.h" 11 | #include "tx/tx.h" 12 | #include "tx/txpool_allocator.h" 13 | -------------------------------------------------------------------------------- /src/runtime/data/deprecated/entity.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "macros.h" 3 | #include "entity.h" 4 | #include "bit_table.h" 5 | 6 | namespace furious 7 | { 8 | 9 | Entity::Entity() : 10 | m_id(FURIOUS_INVALID_ID), 11 | p_database(nullptr) 12 | { 13 | } 14 | 15 | Entity::Entity(database_t* database, 16 | entity_id_t id) : 17 | m_id(id), 18 | p_database(database) 19 | { 20 | } 21 | 22 | Entity::Entity(database_t* database) : 23 | m_id(database_get_next_entity_id(database)), 24 | p_database(database) 25 | { 26 | } 27 | 28 | 29 | Entity 30 | Entity::create_entity(database_t* database) 31 | { 32 | Entity entity(database); 33 | return entity; 34 | } 35 | 36 | void 37 | Entity::remove_entity(Entity entity) 38 | { 39 | database_clear_entity(entity.p_database, 40 | entity.m_id); 41 | entity.m_id = FURIOUS_INVALID_ID; 42 | } 43 | 44 | void 45 | Entity::add_tag(const char* tag) 46 | { 47 | database_tag_entity(p_database, m_id, tag); 48 | } 49 | 50 | void 51 | Entity::remove_tag(const char* tag) 52 | { 53 | database_untag_entity(p_database, m_id, tag); 54 | } 55 | 56 | bool 57 | Entity::has_tag(const char* tag) 58 | { 59 | const BitTable* bit_table = database_get_tagged_entities(p_database, tag); 60 | return bit_table->exists(m_id); 61 | } 62 | 63 | void 64 | Entity::add_reference(const char* ref_name, 65 | Entity other) 66 | { 67 | database_add_reference(p_database, 68 | ref_name, 69 | m_id, 70 | other.m_id); 71 | } 72 | 73 | void 74 | Entity::remove_reference(const char* ref_name) 75 | { 76 | database_remove_reference(p_database, 77 | ref_name, 78 | m_id); 79 | } 80 | 81 | Entity 82 | Entity::get_reference(const char* ref_name) 83 | { 84 | TableView ref_table = FURIOUS_FIND_OR_CREATE_REF_TABLE(p_database, ref_name); 85 | uint32_t* other = ref_table.get_component(m_id); 86 | if(other != nullptr) 87 | { 88 | return Entity(p_database,*other); 89 | } 90 | return Entity(p_database,FURIOUS_INVALID_ID); 91 | } 92 | 93 | database_t* 94 | Entity::get_database() 95 | { 96 | return p_database; 97 | } 98 | 99 | bool 100 | Entity::is_valid() 101 | { 102 | return m_id != FURIOUS_INVALID_ID; 103 | } 104 | 105 | Entity 106 | create_entity(database_t* database) 107 | { 108 | return Entity::create_entity(database); 109 | } 110 | 111 | void 112 | destroy_entity(Entity entity) 113 | { 114 | Entity::remove_entity(entity); 115 | } 116 | 117 | } /* furious */ 118 | -------------------------------------------------------------------------------- /src/runtime/data/deprecated/entity.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _FURIOUS_ENTITY_H_ 3 | #define _FURIOUS_ENTITY_H_ 4 | 5 | #include "../../common/platform.h" 6 | 7 | namespace furious 8 | { 9 | 10 | struct database_t; 11 | 12 | class Entity 13 | { 14 | public: 15 | Entity(); 16 | Entity(database_t* database, 17 | entity_id_t id); 18 | Entity( database_t* database ); 19 | ~Entity() = default; 20 | 21 | Entity( const Entity& entity) = default; 22 | 23 | //////////////////////////////////////////////// 24 | //////////////////////////////////////////////// 25 | //////////////////////////////////////////////// 26 | 27 | public: 28 | 29 | template 30 | TComponent* 31 | add_component(Args&&...args); 32 | 33 | template 34 | void 35 | remove_component(); 36 | 37 | template 38 | TComponent* 39 | get_component(); 40 | 41 | void 42 | add_tag(const char* tag); 43 | 44 | void 45 | remove_tag(const char* tag); 46 | 47 | bool 48 | has_tag(const char* tag); 49 | 50 | void 51 | add_reference(const char* ref_name, 52 | Entity other); 53 | 54 | void 55 | remove_reference(const char* ref_name); 56 | 57 | Entity 58 | get_reference(const char* ref_name); 59 | 60 | bool 61 | is_valid(); 62 | 63 | /** 64 | * @brief Creates an entity 65 | * 66 | * @return 67 | */ 68 | static Entity 69 | create_entity(database_t* database); 70 | 71 | /** 72 | * @brief Removes the given entity 73 | * 74 | * @param The entity to remove 75 | */ 76 | static void 77 | remove_entity(Entity entity); 78 | 79 | database_t* get_database(); 80 | 81 | uint32_t m_id; 82 | 83 | private: 84 | database_t* p_database; 85 | }; 86 | 87 | /** 88 | * @brief Creates an entity 89 | * 90 | * @return A newly created entity 91 | */ 92 | Entity 93 | create_entity(database_t* database); 94 | 95 | /** 96 | * @brief Removes the given entity 97 | * 98 | * @param entiy The entity to remove. 99 | */ 100 | void 101 | destroy_entity(Entity entity); 102 | 103 | /** 104 | * \brief Gets the handler to an existing entity 105 | * 106 | * \param database 107 | * \param id 108 | * 109 | * \return 110 | */ 111 | Entity 112 | get_entity(database_t* database, 113 | entity_id_t id); 114 | 115 | } /* furious */ 116 | 117 | 118 | #endif /* ifndef _FURIOUS_ENTITY_H_H */ 119 | 120 | #include "entity.inl" 121 | -------------------------------------------------------------------------------- /src/runtime/data/deprecated/entity.inl: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _FURIOUS_ENTITY_INL_ 3 | #define _FURIOUS_ENTITY_INL_ 4 | 5 | #include "database.h" 6 | #include 7 | 8 | namespace furious 9 | { 10 | 11 | template 12 | TComponent* 13 | Entity::add_component(Args&&...args) 14 | { 15 | TableView table = database_find_or_create_table(p_database); 16 | return table.insert_component(m_id, std::forward(args)...); 17 | } 18 | 19 | template 20 | void Entity::remove_component() 21 | { 22 | TableView table = database_find_table(p_database); 23 | table.remove_component(m_id); 24 | } 25 | 26 | template 27 | TComponent* Entity::get_component() 28 | { 29 | TableView table = database_find_table(p_database); 30 | return static_cast(table.get_component(m_id)); 31 | } 32 | 33 | } /* furious */ 34 | 35 | #endif 36 | 37 | -------------------------------------------------------------------------------- /src/runtime/data/deprecated/table_view.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef _FURIOUS_TABLE_VIEW_H_ 4 | #define _FURIOUS_TABLE_VIEW_H_ value 5 | 6 | #include "table.h" 7 | 8 | namespace furious 9 | { 10 | 11 | template 12 | struct TableView 13 | { 14 | struct Block 15 | { 16 | typedef TComponent type; 17 | Block(table_block_t* block); 18 | ~Block() = default; 19 | 20 | TComponent* 21 | get_data() const; 22 | 23 | size_t 24 | get_num_components() const; 25 | 26 | size_t 27 | get_size() const; 28 | 29 | entity_id_t 30 | get_start() const; 31 | 32 | const bitmap_t* 33 | get_enabled() const; 34 | 35 | table_block_t* 36 | get_raw() const; 37 | 38 | private: 39 | table_block_t* p_table_block_t; 40 | }; 41 | 42 | struct BlockIterator 43 | { 44 | BlockIterator(table_iter_t iter); 45 | ~BlockIterator(); 46 | 47 | Block next(); 48 | 49 | bool has_next(); 50 | 51 | private: 52 | table_iter_t m_iterator; 53 | 54 | }; 55 | 56 | TableView(); 57 | TableView( table_t* table ); 58 | TableView(const TableView& other) = default; 59 | ~TableView() = default; 60 | 61 | TableView& operator=(const TableView& other) = default; 62 | 63 | /** 64 | * @brief Clears the table 65 | */ 66 | void 67 | clear(); 68 | 69 | /** 70 | * @brief Gets the component with the given id 71 | * 72 | * @param id The id of the component to get 73 | * 74 | * @return Returns a pointer to the component. Returns nullptr if the component 75 | * does not exist in the table 76 | */ 77 | TComponent* 78 | get_component(entity_id_t id) const ; 79 | 80 | /** 81 | * @brief Cre 82 | * 83 | * @tparam TComponent 84 | * @tparam typename...Args 85 | * @param id 86 | * @param ...args 87 | */ 88 | template 89 | TComponent* 90 | insert_component(entity_id_t id, 91 | Args&&...args); 92 | 93 | /** 94 | * @brief Drops the component with the given id 95 | * 96 | * @param id 97 | */ 98 | void 99 | remove_component(entity_id_t id); 100 | 101 | /** 102 | * @brief Enables an component of the table, only it it exists 103 | * 104 | * @param id The id of the component to enable 105 | */ 106 | void 107 | enable_component(entity_id_t id); 108 | 109 | /** 110 | * @brief Disables an component of the table 111 | * 112 | * @param id The if of the component to disable 113 | */ 114 | void 115 | disable_component(entity_id_t id); 116 | 117 | /** 118 | * @brief Tells if an component is enabled or not 119 | * 120 | * @param id The component to test if it is enabled or not 121 | * 122 | * @return True if the component is enabled. False if it is not 123 | */ 124 | bool 125 | is_enabled(entity_id_t id); 126 | 127 | 128 | /** 129 | * @brief Gets the size of the table 130 | * 131 | * @return Returns the size of the table 132 | */ 133 | size_t 134 | size() const; 135 | 136 | /** 137 | * @brief Gets an iterator of the table 138 | * 139 | * @return A new iterator of the table. 140 | */ 141 | BlockIterator 142 | iterator(); 143 | 144 | /** 145 | * @brief Gets an iterator of the table with an specific chunk_size, offset 146 | * and stride 147 | * 148 | * @return A new iterator of the table. 149 | */ 150 | BlockIterator 151 | iterator(uint32_t chunk_size, 152 | uint32_t offset, 153 | uint32_t stride); 154 | 155 | 156 | /** 157 | * \brief Gets the pointer to the raw table of this table view 158 | * 159 | * \return The pointer to the raw table. 160 | */ 161 | table_t* 162 | get_raw(); 163 | 164 | private: 165 | table_t* p_table; 166 | }; 167 | 168 | } /* furious */ 169 | 170 | #include "table_view.inl" 171 | 172 | #endif /* ifndef _FURIOUS_TABLE_VIEW_H_ */ 173 | 174 | -------------------------------------------------------------------------------- /src/runtime/data/deprecated/table_view.inl: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | namespace furious 6 | { 7 | 8 | template 9 | TableView::Block::Block(table_block_t* block) : p_table_block_t{block} 10 | { 11 | 12 | } 13 | 14 | template 15 | TComponent* 16 | TableView::Block::get_data() const 17 | { 18 | return reinterpret_cast(p_table_block_t->p_data); 19 | } 20 | 21 | template 22 | size_t 23 | TableView::Block::get_num_components() const 24 | { 25 | return p_table_block_t->m_num_components; 26 | } 27 | 28 | template 29 | entity_id_t TableView::Block::get_start() const 30 | { 31 | return p_table_block_t->m_start; 32 | } 33 | 34 | template 35 | size_t TableView::Block::get_size() const 36 | { 37 | return FURIOUS_TABLE_BLOCK_SIZE; 38 | } 39 | 40 | template 41 | const bitmap_t* 42 | TableView::Block::get_enabled() const 43 | { 44 | return &p_table_block_t->m_enabled; 45 | } 46 | 47 | template 48 | table_block_t* 49 | TableView::Block::get_raw() const 50 | { 51 | return p_table_block_t; 52 | } 53 | 54 | //////////////////////////////////////////////// 55 | //////////////////////////////////////////////// 56 | //////////////////////////////////////////////// 57 | 58 | 59 | template 60 | TableView::BlockIterator::BlockIterator(table_iter_t iter ) : 61 | m_iterator(iter) 62 | { 63 | } 64 | 65 | template 66 | bool 67 | TableView::BlockIterator::has_next() 68 | { 69 | return table_iter_has_next(&m_iterator); 70 | } 71 | 72 | template 73 | typename TableView::Block 74 | TableView::BlockIterator::next() 75 | { 76 | return Block{table_iter_next(&m_iterator)}; 77 | } 78 | 79 | //////////////////////////////////////////////// 80 | //////////////////////////////////////////////// 81 | //////////////////////////////////////////////// 82 | 83 | template 84 | TableView::TableView() : 85 | p_table(nullptr) 86 | { 87 | } 88 | 89 | template 90 | TableView::TableView( table_t* table ) : 91 | p_table(table) 92 | { 93 | assert(p_table != nullptr); 94 | } 95 | 96 | template 97 | void 98 | TableView::clear() 99 | { 100 | table_clear(p_table); 101 | } 102 | 103 | template 104 | TComponent* 105 | TableView::get_component(entity_id_t id) const 106 | { 107 | return static_cast(table_get_component(p_table, id)); 108 | } 109 | 110 | template 111 | template 112 | TComponent* 113 | TableView::insert_component(entity_id_t id, Args&&...args) 114 | { 115 | return new (table_alloc_component(p_table, id)) TComponent{std::forward(args)...}; 116 | } 117 | 118 | template 119 | void TableView::remove_component(entity_id_t id) 120 | { 121 | table_dealloc_component(p_table, id); 122 | } 123 | 124 | template 125 | void TableView::enable_component(entity_id_t id) 126 | { 127 | table_enable_component(p_table, id); 128 | } 129 | 130 | template 131 | void TableView::disable_component(entity_id_t id) 132 | { 133 | table_disable_component(p_table, id); 134 | } 135 | 136 | template 137 | bool TableView::is_enabled(entity_id_t id) 138 | { 139 | return table_is_enabled(p_table, id); 140 | } 141 | 142 | 143 | template 144 | size_t TableView::size() const 145 | { 146 | return table_size(p_table); 147 | } 148 | 149 | template 150 | typename TableView::BlockIterator TableView::iterator() 151 | { 152 | return BlockIterator{table_iter_create(p_table)}; 153 | } 154 | 155 | template 156 | typename TableView::BlockIterator TableView::iterator(uint32_t chunk_size, uint32_t offset, uint32_t stride) 157 | { 158 | return BlockIterator{table_iter_create(p_table, chunk_size, offset, stride)}; 159 | } 160 | 161 | template 162 | table_t* 163 | TableView::get_raw() 164 | { 165 | return p_table; 166 | } 167 | 168 | template 169 | TableView::BlockIterator::~BlockIterator() 170 | { 171 | table_iter_destroy(&m_iterator); 172 | } 173 | 174 | } /* furious */ 175 | 176 | 177 | -------------------------------------------------------------------------------- /src/runtime/data/ht_registry.c: -------------------------------------------------------------------------------- 1 | 2 | #include "ht_registry.h" 3 | #include "../../common/btree.h" 4 | #include "../../common/memory/memory.h" 5 | #include "../../common/utils.h" 6 | 7 | void 8 | fdb_htregistry_init(fdb_htregistry_t* registry, fdb_mem_allocator_t* allocator) 9 | { 10 | fdb_btree_init(®istry->m_registry, allocator); 11 | fdb_mutex_init(®istry->m_mutex); 12 | } 13 | 14 | void 15 | fdb_htregistry_release(fdb_htregistry_t* registry) 16 | { 17 | fdb_mutex_release(®istry->m_mutex); 18 | fdb_btree_release(®istry->m_registry); 19 | } 20 | 21 | void 22 | fdb_htregistry_insert(fdb_htregistry_t* registry, 23 | const char* key, 24 | void* value) 25 | { 26 | fdb_mutex_lock(®istry->m_mutex); 27 | uint32_t hash_key = hash(key); 28 | fdb_btree_insert_t insert = fdb_btree_insert(®istry->m_registry, hash_key, value); 29 | if(insert.m_inserted == false) 30 | { 31 | *insert.p_place = value; 32 | } 33 | fdb_mutex_unlock(®istry->m_mutex); 34 | } 35 | 36 | void* 37 | fdb_htregistry_get(fdb_htregistry_t* registry, 38 | const char* key) 39 | { 40 | fdb_mutex_lock(®istry->m_mutex); 41 | uint32_t hash_key = hash(key); 42 | void* ptr = fdb_btree_get(®istry->m_registry, 43 | hash_key); 44 | fdb_mutex_unlock(®istry->m_mutex); 45 | return ptr; 46 | } 47 | 48 | void 49 | fdb_htregistry_remove(fdb_htregistry_t* registry, 50 | const char* key) 51 | { 52 | fdb_mutex_lock(®istry->m_mutex); 53 | uint32_t hash_key = hash(key); 54 | fdb_btree_remove(®istry->m_registry, 55 | hash_key); 56 | fdb_mutex_unlock(®istry->m_mutex); 57 | } 58 | -------------------------------------------------------------------------------- /src/runtime/data/ht_registry.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _FDB_HASHTABLE_REGISTRY_H_ 3 | #define _FDB_HASHTABLE_REGISTRY_H_ value 4 | 5 | #include "../../common/mutex.h" 6 | #include "../../common/btree.h" 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | 13 | typedef struct fdb_htregistry_t 14 | { 15 | fdb_btree_t m_registry; 16 | fdb_mutex_t m_mutex; 17 | } fdb_htregistry_t; 18 | 19 | void 20 | fdb_htregistry_init(fdb_htregistry_t* registry, fdb_mem_allocator_t* allocator); 21 | 22 | void 23 | fdb_htregistry_release(fdb_htregistry_t* registry); 24 | 25 | void 26 | fdb_htregistry_insert(fdb_htregistry_t* registry, 27 | const char* key, 28 | void* value); 29 | 30 | void* 31 | fdb_htregistry_get(fdb_htregistry_t* registry, 32 | const char* key); 33 | 34 | void 35 | fdb_htregistry_remove(fdb_htregistry_t* registyr, 36 | const char* key); 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | 42 | #endif /* ifndef _FDB_HASHTABLE_REGISTRY_H_ */ 43 | -------------------------------------------------------------------------------- /src/runtime/data/macros.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef _FDB_DATA_MACROS_H_ 4 | #define _FDB_DATA_MACROS_H_ 5 | 6 | #include "../../common/platform.h" 7 | #include 8 | 9 | #define FDB_BEGIN_COMPONENT(Component, page_size) \ 10 | struct Component \ 11 | { 12 | /*static const char* __component_name() {return #Component;} \ 13 | static const uint64_t __component_page_size() {return page_size;} \ 14 | static const uint64_t __component_is_global() {return false;}*/ 15 | 16 | #define FDB_BEGIN_GLOBAL_COMPONENT(Component) \ 17 | struct Component \ 18 | { 19 | /*static const char* __component_name() {return #Component;} \ 20 | //static const uint64_t __component_page_size() {return KILOBYTES(4);} \ 21 | //static const uint64_t __component_is_global() {return true;}*/ 22 | 23 | #define FDB_END_COMPONENT }; 24 | 25 | //////////////////////////////////////////////// 26 | //////////////////////////////////////////////// 27 | //////////////////////////////////////////////// 28 | 29 | #define FDB_CREATE_TABLE(database, component, dstr) \ 30 | fdb_database_create_table(database,\ 31 | #component,\ 32 | sizeof(component),\ 33 | dstr) 34 | 35 | #define FDB_REMOVE_TABLE(database, component)\ 36 | fdb_database_remove_table(database,\ 37 | #component) 38 | 39 | #define FDB_FIND_TABLE(database, component)\ 40 | fdb_database_find_table(database,\ 41 | #component) 42 | 43 | #define FDB_FIND_OR_CREATE_TABLE(database, component, dstr)\ 44 | fdb_database_find_or_create_table(database,\ 45 | #component,\ 46 | sizeof(component),\ 47 | dstr) 48 | 49 | #define FDB_CREATE_GLOBAL(database, component, dstr) \ 50 | (component*)fdb_database_create_global(database,\ 51 | #component,\ 52 | sizeof(component),\ 53 | dstr) 54 | 55 | #define FDB_REMOVE_GLOBAL(database, component)\ 56 | fdb_database_remove_global(database,\ 57 | #component) 58 | 59 | #define FDB_FIND_GLOBAL(database, component)\ 60 | (component*)fdb_database_find_global(database\ 61 | #component) 62 | 63 | #define FDB_FIND_GLOBAL_NO_LOCK(database, component)\ 64 | (component*)fdb_database_find_global_no_lock(database,\ 65 | #component) 66 | 67 | #define FDB_FIND_OR_CREATE_GLOBAL(database, component, dstr)\ 68 | (component*)fdb_database_find_or_create_global(database,\ 69 | #component\ 70 | sizeof(component)\ 71 | destr) 72 | 73 | #define FDB_FIND_REF_TABLE(database, ref_name)\ 74 | fdb_database_find_reftable(database, ref_name) 75 | 76 | #define FDB_FIND_OR_CREATE_REF_TABLE(database, ref_name)\ 77 | fdb_database_find_or_create_reftable(database, ref_name) 78 | 79 | #define FDB_CREATE_REF_TABLE(database, ref_name)\ 80 | fdb_database_find_or_create_reftable(database, ref_name) 81 | 82 | #define FDB_FIND_TAG_TABLE(database, tagname)\ 83 | fdb_database_get_tagged_entities(database, tagname) 84 | 85 | #define FDB_GET_REFL_DATA(database, component) \ 86 | fdb_mregistry_get_mstruct(fdb_database_get_mregistry(database), #component); 87 | 88 | #define FDB_CREATE_TEMP_TABLE(database, component, name, dstr) \ 89 | fdb_database_create_table(database,\ 90 | name,\ 91 | sizeof(component),\ 92 | dstr) 93 | 94 | #define FDB_REMOVE_TEMP_TABLE(database, component, name)\ 95 | fdb_database_remove_table(database,\ 96 | name) 97 | 98 | #define FDB_FIND_TEMP_TABLE(database, component, name)\ 99 | fdb_database_find_table(database,\ 100 | name) 101 | 102 | //////////////////////////////////////////////// 103 | //////////////////////////////////////////////// 104 | //////////////////////////////////////////////// 105 | 106 | #define FDB_ADD_COMPONENT(table, component, entity) \ 107 | ((component*)fdb_table_create_component(table, entity));\ 108 | FDB_ASSERT(strcmp(#component, table->m_name)==0 && "Trying to create a component from the wrong table"); 109 | 110 | #define FDB_REMOVE_COMPONENT(table, entity) \ 111 | fdb_table_destroy_component(table, entity) 112 | 113 | #define FDB_GET_COMPONENT(table, component, entity) \ 114 | ((component*)fdb_table_get_component(table, entity)) 115 | 116 | #define FDB_ADD_TAG(bittable, entity) \ 117 | fdb_bittable_add(bittable, entity) 118 | 119 | #define FDB_REMOVE_TAG(entity, tag) \ 120 | (entity).remove_tag(tag) 121 | 122 | #define FDB_HAS_TAG(entity, tag) \ 123 | (entity).has_tag(tag) 124 | 125 | #define FDB_ADD_REFERENCE(reftable, tail, head) \ 126 | fdb_reftable_add(reftable, tail, head) 127 | 128 | #define FDB_REMOVE_REFERENCE(entity, reference, other) \ 129 | (entity).remove_reference(reference, other) 130 | 131 | #define FDB_GET_REFERENCE(entity, reference) \ 132 | (entity).get_reference(reference) 133 | 134 | #endif 135 | -------------------------------------------------------------------------------- /src/runtime/data/reflection.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include "reflection.h" 4 | #include "string.h" 5 | #include "../../common/utils.h" 6 | 7 | 8 | void 9 | fdb_mregistry_init(fdb_mregistry_t* reg, 10 | fdb_mem_allocator_t* allocator) 11 | { 12 | fdb_mem_allocator_t* mallocator = fdb_get_global_mem_allocator(); 13 | if(allocator != NULL) 14 | { 15 | mallocator = allocator; 16 | } 17 | 18 | fdb_pool_alloc_init(®->m_mstruct_allocator, 19 | 64, 20 | sizeof(fdb_mstruct_t), 21 | FDB_REFLECTION_STRUCT_PAGE_SIZE, 22 | mallocator); 23 | 24 | fdb_pool_alloc_init(®->m_mfield_allocator, 25 | 64, 26 | sizeof(fdb_mfield_t), 27 | FDB_REFLECTION_FIELD_PAGE_SIZE, 28 | mallocator); 29 | 30 | fdb_btree_init(®->m_metadata, 31 | mallocator); 32 | } 33 | 34 | void 35 | fdb_mregistry_release(fdb_mregistry_t* reg) 36 | { 37 | fdb_btree_iter_t iter; 38 | fdb_btree_iter_init(&iter, ®->m_metadata); 39 | while(fdb_btree_iter_has_next(&iter)) 40 | { 41 | fdb_mstruct_t* mstruct = (fdb_mstruct_t*)(fdb_btree_iter_next(&iter).p_value); 42 | //fdb_mstruct_release(mstruct); 43 | fdb_pool_alloc_free(®->m_mstruct_allocator, mstruct); 44 | } 45 | fdb_btree_iter_release(&iter); 46 | fdb_btree_release(®->m_metadata); 47 | fdb_pool_alloc_release(®->m_mfield_allocator); 48 | fdb_pool_alloc_release(®->m_mstruct_allocator); 49 | } 50 | 51 | 52 | fdb_mstruct_t* 53 | fdb_mregistry_init_mstruct(fdb_mregistry_t* reg, 54 | const char* name, 55 | bool is_union) 56 | { 57 | fdb_mstruct_t* mstruct = (fdb_mstruct_t*)fdb_pool_alloc_alloc(®->m_mstruct_allocator, 58 | 64, 59 | sizeof(fdb_mstruct_t), 60 | FDB_NO_HINT); 61 | memset(mstruct, 0, sizeof(fdb_mstruct_t)); 62 | FDB_COPY_AND_CHECK_STR(mstruct->m_type_name, name, FDB_MAX_TABLE_NAME); 63 | mstruct->m_is_union = is_union; 64 | mstruct->m_nfields = 0; 65 | uint32_t hashvalue = hash(name); 66 | fdb_btree_insert_t insert = fdb_btree_insert(®->m_metadata, hashvalue, mstruct); 67 | if(!insert.m_inserted) 68 | { 69 | fdb_mstruct_t* old = (fdb_mstruct_t*)(*insert.p_place); 70 | *insert.p_place = mstruct; 71 | fdb_pool_alloc_free(®->m_mstruct_allocator, old); 72 | } 73 | return mstruct; 74 | } 75 | 76 | fdb_mstruct_t* 77 | fdb_mregistry_init_mfield(fdb_mregistry_t* reg, 78 | fdb_mstruct_t* mstruct, 79 | const char* name, 80 | fdb_mtype_t type, 81 | size_t offset, 82 | bool is_anon) 83 | { 84 | fdb_mfield_t* mfield = (fdb_mfield_t*)fdb_pool_alloc_alloc(®->m_mfield_allocator, 85 | 64, 86 | sizeof(fdb_mfield_t), 87 | FDB_NO_HINT); 88 | memset(mfield, 0, sizeof(fdb_mfield_t)); 89 | FDB_COPY_AND_CHECK_STR(mfield->m_name, name, FCC_MAX_FIELD_NAME); 90 | mfield->m_type = type; 91 | mfield->m_offset = offset; 92 | mfield->m_anonymous = is_anon; 93 | if(mfield->m_type == E_UNION || mfield->m_type == E_STRUCT) 94 | { 95 | mfield->p_strct_type = (fdb_mstruct_t*)fdb_pool_alloc_alloc(®->m_mstruct_allocator, 96 | 64, 97 | sizeof(fdb_mstruct_t), 98 | FDB_NO_HINT); 99 | memset(mfield->p_strct_type, 0, sizeof(fdb_mstruct_t)); 100 | } 101 | FDB_PERMA_ASSERT(mstruct->m_nfields < FDB_MAX_COMPONENT_FIELDS && "Maximum number of fields per component reached"); 102 | mstruct->p_fields[mstruct->m_nfields++] = mfield; 103 | return mfield->p_strct_type; 104 | } 105 | 106 | 107 | fdb_mstruct_t* 108 | fdb_mregistry_get_mstruct(fdb_mregistry_t* reg, 109 | const char* name) 110 | { 111 | uint32_t hashvalue = hash(name); 112 | fdb_mstruct_t* mstruct = (fdb_mstruct_t*)fdb_btree_get(®->m_metadata, hashvalue); 113 | return mstruct; 114 | } 115 | 116 | -------------------------------------------------------------------------------- /src/runtime/data/reflection.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | #ifndef _FDB_REFLECTION_H_ 5 | #define _FDB_REFLECTION_H_ 6 | 7 | #include "../../common/platform.h" 8 | #include "../../common/memory/pool_allocator.h" 9 | #include "../../common/btree.h" 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | typedef enum fdb_mtype_t 16 | { 17 | E_BOOL, 18 | E_CHAR, 19 | E_UINT8, 20 | E_UINT16, 21 | E_UINT32, 22 | E_UINT64, 23 | E_INT8, 24 | E_INT16, 25 | E_INT32, 26 | E_INT64, 27 | E_FLOAT, 28 | E_DOUBLE, 29 | E_CHAR_POINTER, 30 | E_STD_STRING, 31 | E_POINTER, 32 | E_STRUCT, 33 | E_UNION, 34 | E_UNKNOWN, 35 | E_NUM_TYPES, 36 | } fdb_mtype_t; 37 | 38 | //////////////////////////////////////////////// 39 | //////////////////////////////////////////////// 40 | //////////////////////////////////////////////// 41 | 42 | typedef struct fdb_mstruct_t 43 | { 44 | char m_type_name[FDB_MAX_TABLE_NAME]; 45 | struct fdb_mfield_t* p_fields[FDB_MAX_COMPONENT_FIELDS]; 46 | uint32_t m_nfields; 47 | bool m_is_union; 48 | } fdb_mstruct_t; 49 | 50 | 51 | //////////////////////////////////////////////// 52 | //////////////////////////////////////////////// 53 | //////////////////////////////////////////////// 54 | 55 | typedef struct fdb_mfield_t 56 | { 57 | char m_name[FCC_MAX_FIELD_NAME]; 58 | fdb_mtype_t m_type; 59 | size_t m_offset; 60 | bool m_anonymous; 61 | fdb_mstruct_t* p_strct_type; 62 | } fdb_mfield_t; 63 | 64 | 65 | //////////////////////////////////////////////// 66 | //////////////////////////////////////////////// 67 | //////////////////////////////////////////////// 68 | 69 | 70 | typedef struct fdb_mregistry_t 71 | { 72 | fdb_btree_t m_metadata; //< btree with the mstruct mapping 73 | fdb_pool_alloc_t m_mstruct_allocator; 74 | fdb_pool_alloc_t m_mfield_allocator; 75 | } fdb_mregistry_t; 76 | 77 | /** 78 | * \brief inits a reflection data mregistry 79 | * 80 | * \param allocator The allocator to use for the mregistry 81 | * 82 | * \return Returns the newly allocated mregistry 83 | */ 84 | void 85 | fdb_mregistry_init(fdb_mregistry_t* reg, 86 | fdb_mem_allocator_t* allocator); 87 | 88 | /** 89 | * \brief Releases the reflection data mregistry 90 | * 91 | * \param reg The mregistry to destroy 92 | */ 93 | void 94 | fdb_mregistry_release(fdb_mregistry_t* reg); 95 | 96 | 97 | /** 98 | * \brief inits an mstruct mregistry for a given name 99 | * 100 | * \param reg The registy to use 101 | * \param name The name to associate the mstruct with 102 | * \param is_union Whether is a union or not 103 | * 104 | * \return The newly initd mstruct 105 | */ 106 | fdb_mstruct_t* 107 | fdb_mregistry_init_mstruct(fdb_mregistry_t* reg, 108 | const char* name, 109 | bool is_union); 110 | 111 | /** 112 | * \brief inits a mfield in a given mstruct 113 | * 114 | * \param reg The mregistry to use 115 | * \param mstruct The mstruct to init the field to 116 | * \param name The name of the field 117 | * \param type The type of the field 118 | * \param offset The offset in bytes of the field in the mstruct 119 | * \param is_anon Whether this is an anonymous field or not (e.g. anonymous 120 | * struct/union) 121 | * 122 | * \return If rtype == E_STRUCT or E_UNION-> then a pointer to the mstruct for that struct. 123 | * Otherwise, nullptr 124 | */ 125 | fdb_mstruct_t* 126 | fdb_mregistry_init_mfield(fdb_mregistry_t* reg, 127 | fdb_mstruct_t* mstruct, 128 | const char* name, 129 | fdb_mtype_t type, 130 | size_t offset, 131 | bool is_anon); 132 | 133 | /** 134 | * \brief Gets the mstruct associated with a given name 135 | * 136 | * \param reg The registry to use 137 | * \param name The name of the mstruct 138 | * 139 | * \return The mstruct or nullptr if it does not exist 140 | */ 141 | fdb_mstruct_t* 142 | fdb_mregistry_get_mstruct(fdb_mregistry_t* reg, 143 | const char* name); 144 | 145 | #ifdef __cplusplus 146 | } 147 | #endif 148 | 149 | #endif /* ifndef _FDB_REFLECTION_H_ */ 150 | -------------------------------------------------------------------------------- /src/runtime/data/reftable.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include "reftable.h" 4 | 5 | 6 | 7 | void 8 | fdb_reftable_init(fdb_reftable_t* rt, 9 | const char* rname, 10 | uint32_t id, 11 | fdb_mem_allocator_t* allocator) 12 | { 13 | fdb_table_init(&rt->m_table, 14 | rname, 15 | id, 16 | sizeof(entity_id_t), NULL, allocator); 17 | } 18 | 19 | /** 20 | * \brief Destroys a reference table 21 | * 22 | * \param rt The reference table to destroy 23 | */ 24 | void 25 | fdb_reftable_release(fdb_reftable_t* rt) 26 | { 27 | fdb_table_release(&rt->m_table); 28 | } 29 | 30 | void 31 | fdb_reftable_add(fdb_reftable_t* rt, 32 | entity_id_t tail, 33 | entity_id_t head) 34 | { 35 | entity_id_t* phead = (entity_id_t*)fdb_table_create_component(&rt->m_table, 36 | tail); 37 | *phead = head; 38 | } 39 | 40 | entity_id_t* 41 | fdb_reftable_get(fdb_reftable_t* rt, 42 | entity_id_t tail) 43 | { 44 | return (entity_id_t*) (entity_id_t*)fdb_table_get_component(&rt->m_table, 45 | tail); 46 | } 47 | 48 | void 49 | fdb_reftable_remove(fdb_reftable_t* rt, 50 | entity_id_t tail, 51 | entity_id_t head) 52 | { 53 | fdb_table_destroy_component(&rt->m_table, 54 | tail); 55 | } 56 | 57 | bool 58 | fdb_reftable_exists(fdb_reftable_t* rt, 59 | entity_id_t tail, 60 | entity_id_t head) 61 | { 62 | entity_id_t* phead = (entity_id_t*)fdb_table_get_component(&rt->m_table, 63 | tail); 64 | return phead != NULL && *phead == head; 65 | } 66 | 67 | -------------------------------------------------------------------------------- /src/runtime/data/reftable.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef _FURIOUS_REF_TABLE_H_ 4 | #define _FURIOUS_REF_TABLE_H_ 5 | 6 | #include "../../common/types.h" 7 | #include "table.h" 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | typedef struct fdb_reftable_t 14 | { 15 | fdb_table_t m_table; 16 | } fdb_reftable_t; 17 | 18 | 19 | /** 20 | * \brief inits a reference table 21 | * 22 | * \param The name of the reference 23 | * \param allocator The allocator to use 24 | * 25 | * \return The newly initd reference table 26 | */ 27 | void 28 | fdb_reftable_init(fdb_reftable_t* rt, 29 | const char* rname, 30 | uint32_t id, 31 | fdb_mem_allocator_t* allocator); 32 | 33 | /** 34 | * \brief releases a reference table 35 | * 36 | * \param rt The reference table to release 37 | */ 38 | void 39 | fdb_reftable_release(fdb_reftable_t* rt); 40 | 41 | /** 42 | * \brief Adds a reference to reftable 43 | * 44 | * \param rt The reference table 45 | * \param tail The tail of the reference 46 | * \param head The head of the reference 47 | */ 48 | void 49 | fdb_reftable_add(fdb_reftable_t* rt, 50 | entity_id_t tail, 51 | entity_id_t head); 52 | 53 | /** 54 | * \brief Gets the reference for the given tail 55 | * 56 | * \param rt The reference table 57 | * \param tail The tail 58 | * 59 | * \return Returns a pointer to the reference or false if it does not exist 60 | */ 61 | entity_id_t* 62 | fdb_reftable_get(fdb_reftable_t* rt, 63 | entity_id_t tail); 64 | 65 | /** 66 | * \brief Removes a reference from the ref table 67 | * 68 | * \param rt The reference table 69 | * \param tail The tail of the reference 70 | * \param head The head of the reference 71 | */ 72 | void 73 | fdb_reftable_remove(fdb_reftable_t* rt, 74 | entity_id_t tail, 75 | entity_id_t head); 76 | 77 | /** 78 | * \brief Checks if a reference exists 79 | * 80 | * \param rt The reference table 81 | * \param tail The tail of the reference 82 | * \param head The head of the reference 83 | */ 84 | bool 85 | fdb_reftable_exists(fdb_reftable_t* rt, 86 | entity_id_t tail, 87 | entity_id_t head); 88 | #ifdef __cplusplus 89 | } 90 | #endif 91 | 92 | #endif 93 | -------------------------------------------------------------------------------- /src/runtime/data/tx/tx.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _FDB_TX_H_ 3 | #define _FDB_TX_H_ 4 | 5 | #include "../../../common/platform.h" 6 | #include "../../../common/memory/pool_allocator.h" 7 | #include 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | struct fdb_txpool_alloc_t; 14 | struct fdb_txpool_alloc_block_t; 15 | 16 | #define FDB_TX_INVALID_ID (uint64_t)0LL 17 | 18 | typedef enum fdb_txtype_t 19 | { 20 | E_READ_ONLY, ///< A read-only transaction 21 | E_READ_WRITE ///< A read-write transaction 22 | } fdb_txtype_t; 23 | 24 | typedef struct fdb_tx_t 25 | { 26 | uint64_t m_id; ///< The id of the transaction 27 | uint64_t m_txversion; ///< The maximum version timestamp 28 | uint64_t m_ortxversion; ///< The ts of the oldest running ts. Used for GC during executiong of READ_WRITE tx's. 29 | fdb_txtype_t m_tx_type; ///< The transaction type 30 | struct fdb_tx_t* p_next; 31 | struct fdb_tx_t* p_prev; 32 | } fdb_tx_t; 33 | 34 | typedef struct fdb_txgarbage_t 35 | { 36 | struct fdb_txpool_alloc_t* p_palloc; ///< The txpool where this garbage item belongs to 37 | struct fdb_txpool_alloc_block_t* p_block; ///< The block to the garbage 38 | struct fdb_txgarbage_t* p_next; ///< The next garbage entry in the linkect list 39 | struct fdb_txgarbage_t* p_prev; ///< The previous garbage entry in th elinked list 40 | bool m_release; ///< Whether to fully release the reference or just GC it 41 | } fdb_txgarbage_t; 42 | 43 | 44 | typedef struct fdb_txthread_ctx_t 45 | { 46 | fdb_pool_alloc_t m_palloc; ///< the pool allocator used to allocate garbage objects 47 | fdb_txgarbage_t* p_first; ///< the first garbage object in the linked list 48 | } fdb_txthread_ctx_t; 49 | 50 | /** 51 | * \brief Initializes the transactional subsytem 52 | */ 53 | void 54 | fdb_tx_init(); 55 | 56 | /** 57 | * \brief Releases the transactional subsystem 58 | */ 59 | void 60 | fdb_tx_release(); 61 | 62 | /** 63 | * \brief Initializes a transaction. From this point, the transaction has 64 | * started. This operation blocks the execution if a read-write transaction is 65 | * already running. 66 | * 67 | * \param tx The transaction object to initialize 68 | * \param fdb_txtype_t The type of transaction 69 | */ 70 | void 71 | fdb_tx_begin(fdb_tx_t* tx, fdb_txtype_t txtype); 72 | 73 | /** 74 | * \brief Commits a transaction 75 | * 76 | * \param tx The transaction to commit 77 | */ 78 | void 79 | fdb_tx_commit(fdb_tx_t* tx); 80 | 81 | /** 82 | * \brief Locks the tx manager so no transactions can beging 83 | */ 84 | void 85 | fdb_tx_lock(); 86 | 87 | /** 88 | * \brief UnLocks the tx manager 89 | */ 90 | void 91 | fdb_tx_unlock(); 92 | 93 | 94 | /** 95 | * \brief Initializes the txthread context 96 | * 97 | * \param txtctx The txthread context to initialize 98 | * \param allocator Pointer to the memory allocator to use within the context 99 | */ 100 | void 101 | fdb_txthread_ctx_init(fdb_txthread_ctx_t* txtctx, 102 | fdb_mem_allocator_t* allocator); 103 | 104 | /** 105 | * \brief Releases the txthread context 106 | * 107 | * \param txctx The txthread context to release 108 | */ 109 | void 110 | fdb_txthread_ctx_release(fdb_txthread_ctx_t* txctx); 111 | 112 | /** 113 | * \brief Adds a txpool reference to the given txthread context 114 | * 115 | * \param txctx The txthread context to add the reference to 116 | * \param palloc The txpool alloc the reference belongs to 117 | * \param ref The reference to add 118 | * \param ts The timestamp of the transaction that marked this block as 119 | * deleted 120 | * \param release True if we want to fully release the reference. 121 | */ 122 | void 123 | fdb_txthread_ctx_add_entry(fdb_txthread_ctx_t* txtctx, 124 | struct fdb_txpool_alloc_t* palloc, 125 | struct fdb_txpool_alloc_block_t* ref); 126 | 127 | /** 128 | * \brief Executes the garbage collection process on this txthread ctx. 129 | * 130 | * \param txtctx The txthread context to run the garbage collection process 131 | * for 132 | * \param force Locks the tx manager and forces the garbage collection process. 133 | * 134 | * \return True if all items were garbage collected. False otherwise 135 | */ 136 | bool 137 | fdb_txthread_ctx_gc(fdb_txthread_ctx_t* txtctx, 138 | bool force); 139 | 140 | 141 | #ifdef __cplusplus 142 | } 143 | #endif 144 | 145 | #endif 146 | -------------------------------------------------------------------------------- /src/runtime/data/webserver/webserver.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | #ifndef _FURIOUS_WEBSERVER_H_ 5 | #define _FURIOUS_WEBSERVER_H_ value 6 | 7 | #include "../../../common/types.h" 8 | #include "../../../common/platform.h" 9 | #include "../../../common/str_builder.h" 10 | 11 | #include 12 | #include 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | 19 | typedef struct fdb_webserver_t 20 | { 21 | struct fdb_database_t* p_database; 22 | pthread_t m_thread; 23 | uint32_t m_table_infos_capacity; 24 | struct fdb_table_info_t* m_table_infos; 25 | fdb_str_builder_t m_builder; 26 | bool m_running; 27 | char m_port[FDB_MAX_WEBSERVER_PORT_SIZE]; 28 | char m_address[FDB_MAX_WEBSERVER_ADDRESS_SIZE]; 29 | } fdb_webserver_t; 30 | 31 | 32 | void 33 | fdb_webserver_init(fdb_webserver_t* ws); 34 | 35 | void 36 | fdb_webserver_release(fdb_webserver_t* ws); 37 | 38 | void 39 | fdb_webserver_start(fdb_webserver_t* ws, 40 | struct fdb_database_t* db, 41 | const char* address, 42 | const char* port); 43 | 44 | void 45 | fdb_webserver_stop(fdb_webserver_t* ws); 46 | 47 | #ifdef __cplusplus 48 | } 49 | #endif 50 | 51 | #endif /* ifndef _FURIOUS_WEBSERVER_H_ */ 52 | 53 | -------------------------------------------------------------------------------- /src/runtime/deprecated/system_wrapper.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _FURIOUS_STATIC_SYSTEM_H_ 3 | #define _FURIOUS_STATIC_SYSTEM_H_ 4 | 5 | #include "data/table.h" 6 | #include "data/context.h" 7 | 8 | namespace furious 9 | { 10 | 11 | template 12 | class SystemWrapper final 13 | { 14 | public: 15 | 16 | SystemWrapper(T* system_object); 17 | ~SystemWrapper(); 18 | 19 | //////////////////////////////////////////////// 20 | //////////////////////////////////////////////// 21 | //////////////////////////////////////////////// 22 | 23 | /** 24 | * @brief Applies the system to a set of components of an entity 25 | * 26 | * @param context The execution context 27 | * @param id The id of the entity 28 | * @param mask The bitset indicating the elements of the block to apply the 29 | * system to 30 | * @param components Pointers to the components of the entity 31 | */ 32 | 33 | void apply_block(Context* __restrict__ context, 34 | uint32_t block_start, 35 | const bitmap_t* mask, 36 | Components* __restrict__ ...components); 37 | 38 | T* p_system_object; 39 | }; 40 | 41 | } /* furious */ 42 | 43 | #include "system_wrapper.inl" 44 | #endif 45 | -------------------------------------------------------------------------------- /src/runtime/deprecated/system_wrapper.inl: -------------------------------------------------------------------------------- 1 | 2 | 3 | namespace furious 4 | { 5 | 6 | template 7 | SystemWrapper::SystemWrapper(T* system_object) : 8 | p_system_object(system_object) 9 | { 10 | 11 | } 12 | 13 | template 14 | SystemWrapper::~SystemWrapper() 15 | { 16 | delete p_system_object; 17 | } 18 | 19 | template 20 | inline 21 | void SystemWrapper::apply_block(Context* context, 22 | uint32_t block_start, 23 | const bitmap_t* mask, 24 | Components* __restrict__ ...components) 25 | { 26 | if(mask->m_num_set == FURIOUS_TABLE_BLOCK_SIZE) 27 | { 28 | for (size_t i = 0; i < FURIOUS_TABLE_BLOCK_SIZE; ++i) 29 | { 30 | p_system_object->run(context, block_start+i, &components[i]...); 31 | } 32 | } 33 | else 34 | { 35 | for (size_t i = 0; i < FURIOUS_TABLE_BLOCK_SIZE; ++i) 36 | { 37 | if(bitmap_is_set(mask,i)) 38 | { 39 | p_system_object->run(context, block_start+i, &components[i]...); 40 | } 41 | } 42 | } 43 | } 44 | 45 | 46 | template 47 | SystemWrapper* 48 | create_system(T* system, 49 | void (T::*)(Context*, uint32_t id, Components*...) ) 50 | { 51 | return new SystemWrapper(system); 52 | } 53 | 54 | template 55 | auto 56 | create_system(TArgs&&...args) -> decltype(create_system(new TSystem(std::forward(args)...), &TSystem::run)) 57 | { 58 | TSystem* system_object = new TSystem(std::forward(args)...); 59 | return create_system(system_object, &TSystem::run); 60 | } 61 | 62 | template 63 | void 64 | destroy_system(SystemWrapper* system) 65 | { 66 | delete system; 67 | } 68 | 69 | } /* furious */ 70 | -------------------------------------------------------------------------------- /src/runtime/log/log.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include "log.h" 4 | #include 5 | 6 | 7 | fdb_log_func_t m_log_function = NULL; 8 | 9 | void 10 | set_log_function(fdb_log_func_t log_function) 11 | { 12 | m_log_function = log_function; 13 | } 14 | -------------------------------------------------------------------------------- /src/runtime/log/log.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _FDB_LOG_H_ 3 | #define _FDB_LOG_H_ value 4 | 5 | #include "../../common/str_builder.h" 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | typedef enum fdb_log_level_t 12 | { 13 | E_INFO, 14 | E_WARNING, 15 | E_ERROR 16 | } fdb_log_level_t; 17 | 18 | typedef void (*fdb_log_func_t) (fdb_log_level_t, const char*); // hint with the block id of this allocation. -1 indicates no hint 19 | 20 | extern fdb_log_func_t m_log_function; 21 | 22 | #define FURIOUS_LOG(level, msg, ...) \ 23 | if(m_log_function) \ 24 | { \ 25 | str_builder_t str_builder = str_builder_create();\ 26 | str_builder_append(&str_builder, msg, __VA_ARGS__)\ 27 | m_log_function(level, str_builder.p_buffer);\ 28 | str_builder_destroy(&str_builder);\ 29 | } 30 | 31 | void 32 | set_log_function(fdb_log_func_t log_function); 33 | 34 | #ifdef __cplusplus 35 | } 36 | #endif 37 | 38 | #endif /* ifndef _FURIOUS_LOG_H_ */ 39 | -------------------------------------------------------------------------------- /src/runtime/runtime.h: -------------------------------------------------------------------------------- 1 | 2 | #include "data/data.h" 3 | #include "task/task.h" 4 | #include "log/log.h" 5 | -------------------------------------------------------------------------------- /src/runtime/task/task.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | #ifndef _FDB_TASK_H_ 5 | #define _FDB_TASK_H_ 6 | 7 | #include "../../common/platform.h" 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | typedef struct fdb_database_t fdb_database_t; 14 | typedef struct fdb_barrier_t 15 | { 16 | void* p_state; 17 | void (*p_wait) (void* state, int32_t num_processes); 18 | void (*p_reset) (); 19 | } fdb_barrier_t; 20 | 21 | typedef void (*fdb_task_func_t) (float, // delta 22 | fdb_database_t*, // database 23 | void*, // userdata 24 | uint32_t, // chunksize 25 | uint32_t, // offset 26 | uint32_t, // stride 27 | fdb_barrier_t* barrier); 28 | 29 | typedef struct fdb_task_t 30 | { 31 | uint32_t m_id; 32 | const char* p_info; 33 | fdb_task_func_t p_func; 34 | bool m_requires_sync; 35 | uint32_t m_parents[FCC_MAX_TASK_PARENTS]; 36 | uint32_t m_children[FCC_MAX_TASK_CHILDREN]; 37 | uint32_t m_num_parents; 38 | uint32_t m_num_children; 39 | } fdb_task_t; 40 | 41 | typedef struct fdb_task_graph_t 42 | { 43 | fdb_task_t* m_tasks; 44 | uint32_t* m_roots; 45 | uint32_t m_num_tasks; 46 | uint32_t m_num_roots; 47 | } fdb_task_graph_t; 48 | 49 | void 50 | fdb_task_graph_init(fdb_task_graph_t* task_graph, 51 | uint32_t num_tasks, 52 | uint32_t num_roots); 53 | 54 | void 55 | fdb_task_graph_release(fdb_task_graph_t* task_graph); 56 | 57 | 58 | void 59 | fdb_task_graph_insert_task(fdb_task_graph_t* task_graph, 60 | uint32_t task_id, 61 | fdb_task_func_t func, 62 | bool requires_sync, 63 | const char* info); 64 | 65 | void 66 | fdb_task_graph_set_parent(fdb_task_graph_t* task_graph, 67 | uint32_t task_id, 68 | uint32_t parent_id); 69 | 70 | void 71 | fdb_task_graph_set_root(fdb_task_graph_t* task_graph, 72 | uint32_t root_idx, 73 | uint32_t task_id); 74 | 75 | void 76 | fdb_task_graph_run(fdb_task_graph_t* task_graph, 77 | float delta, 78 | fdb_database_t* database, 79 | void* user_data); 80 | 81 | #ifdef __cplusplus 82 | } 83 | #endif 84 | 85 | #endif /* ifndef _FURIOUS_TASK_H_ */ 86 | -------------------------------------------------------------------------------- /src/test/compiler/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | CMAKE_MINIMUM_REQUIRED (VERSION 2.8) 2 | 3 | 4 | add_definitions(${FURIOUS_DEFAULT_DEFINES}) 5 | 6 | find_package(GTest REQUIRED) 7 | include_directories(${GTEST_INCLUDE_DIRS}) 8 | include_directories(${FURIOUS_INCLUDE_DIR}) 9 | 10 | function(create_test NAME) 11 | 12 | SET(CXX_INCLUDES_DIRS "") 13 | foreach(INC ${CXX_HEADERS_DIRS}) 14 | SET(CXX_INCLUDES_DIRS "-I${INC}" " " ${CXX_INCLUDES_DIRS}) 15 | endforeach() 16 | #string(REGEX REPLACE "\\" "" CXX_INCLUDES_DIRS "${CXX_INCLUDES_DIRS}") 17 | 18 | MESSAGE(STATUS ${CXX_INCLUDES_DIRS}) 19 | add_custom_command( 20 | OUTPUT ${NAME}_furious.cpp 21 | COMMAND fcc -o 22 | ${CMAKE_CURRENT_BINARY_DIR}/${NAME}_furious.cpp -i 23 | "furious.h" 24 | ${CMAKE_CURRENT_SOURCE_DIR}/${NAME}_script.cpp -- 25 | -fstrict-aliasing -std=c++17 ${CXX_INCLUDES_DIRS} -I${CMAKE_SOURCE_DIR}/src ${FURIOUS_DEFAULT_DEFINES} 26 | COMMAND clang-format --style='{BasedOnStyle: LLVM, ColumnLimit: 120}' -i 27 | ${CMAKE_CURRENT_BINARY_DIR}/${NAME}_furious.cpp 28 | DEPENDS fcc furious ${NAME}_script.cpp ${NAME}_header.h 29 | ) 30 | 31 | add_executable(${NAME} 32 | ${NAME}.cpp 33 | ${NAME}_header.h 34 | ${CMAKE_CURRENT_BINARY_DIR}/${NAME}_furious.cpp 35 | ) 36 | 37 | target_link_libraries(${NAME} ${GTEST_LIBRARIES} furious) 38 | add_test(${NAME} ${FURIOUS_OUTPUT_DIR}/test/compiler/${NAME}) 39 | 40 | set_target_properties( ${NAME} 41 | PROPERTIES 42 | RUNTIME_OUTPUT_DIRECTORY ${FURIOUS_OUTPUT_DIR}/test/compiler 43 | ) 44 | endfunction(create_test) 45 | 46 | SET(TESTS 47 | basic_test 48 | filter_tag_test 49 | filter_func_test 50 | filter_lambda_test 51 | dependency_test 52 | expand_test 53 | global_test 54 | reflection_test 55 | ) 56 | 57 | foreach( TEST ${TESTS} ) 58 | create_test(${TEST}) 59 | endforeach( TEST ) 60 | 61 | add_custom_target(compiler_tests COMMAND ${CMAKE_CTEST_COMMAND} 62 | DEPENDS ${TESTS}) 63 | -------------------------------------------------------------------------------- /src/test/compiler/basic_test.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "furious.h" 3 | #include "basic_test_header.h" 4 | 5 | #include 6 | 7 | 8 | 9 | TEST(BasicTest, BasicTest ) 10 | { 11 | fdb_database_t database; 12 | fdb_database_init(&database, nullptr); 13 | fdb_database_start_webserver(&database, 14 | "localhost", 15 | "8080"); 16 | furious_init(&database); 17 | 18 | fdb_table_t* pos_table = FDB_FIND_TABLE(&database, Position); 19 | fdb_table_t* vel_table = FDB_FIND_TABLE(&database, Velocity); 20 | 21 | entity_id_t NUM_ENTITIES = 1000; 22 | for(entity_id_t i = 0; i < NUM_ENTITIES; ++i) 23 | { 24 | Position* pos = FDB_ADD_COMPONENT(pos_table, Position, i); 25 | pos->m_x = 0.0; 26 | pos->m_y = 0.0; 27 | pos->m_z = 0.0; 28 | 29 | Velocity* vel = FDB_ADD_COMPONENT(vel_table, Velocity, i); 30 | vel->m_x = 1.0f; 31 | vel->m_y = 1.0f; 32 | vel->m_z = 1.0f; 33 | } 34 | 35 | furious_frame(0.1, &database, nullptr); 36 | 37 | for(entity_id_t i = 0; i < NUM_ENTITIES; ++i) 38 | { 39 | Position* pos = FDB_GET_COMPONENT(pos_table, Position, i); 40 | ASSERT_EQ(pos->m_x,0.1f); 41 | ASSERT_EQ(pos->m_y,0.1f); 42 | ASSERT_EQ(pos->m_z,0.1f); 43 | } 44 | furious_release(); 45 | fdb_database_release(&database); 46 | } 47 | 48 | int main(int argc, char *argv[]) 49 | { 50 | ::testing::InitGoogleTest(&argc, argv); 51 | int ret = RUN_ALL_TESTS(); 52 | return ret; 53 | } 54 | 55 | -------------------------------------------------------------------------------- /src/test/compiler/basic_test_header.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _BASIC_TEST_HEADER_H_ 3 | #define _BASIC_TEST_HEADER_H_ value 4 | 5 | #include "furious_macros.h" 6 | 7 | FDB_BEGIN_COMPONENT(Position, KILOBYTES(4)) 8 | float m_x; 9 | float m_y; 10 | float m_z; 11 | FDB_END_COMPONENT 12 | 13 | FDB_BEGIN_COMPONENT(Velocity, KILOBYTES(4)) 14 | float m_x; 15 | float m_y; 16 | float m_z; 17 | FDB_END_COMPONENT 18 | 19 | #endif /* ifndef _BASIC_TEST_HEADER_H_ */ 20 | -------------------------------------------------------------------------------- /src/test/compiler/basic_test_script.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "lang/lang.h" 3 | #include "basic_test_header.h" 4 | 5 | bool test(const Position* pos, const Velocity* vel) 6 | { 7 | return true; 8 | } 9 | 10 | BEGIN_FDB_SCRIPT 11 | 12 | struct UpdatePosition 13 | { 14 | UpdatePosition(float speed) : m_speed{speed} {} 15 | 16 | void run(fdb_context_t* context, 17 | uint32_t id, 18 | Position* position, 19 | const Velocity* velocity) 20 | { 21 | position->m_x = position->m_x + velocity->m_x*context->m_dt*m_speed; 22 | position->m_y = position->m_y + velocity->m_y*context->m_dt*m_speed; 23 | position->m_z = position->m_z + velocity->m_z*context->m_dt*m_speed; 24 | } 25 | 26 | float m_speed = 1.0; 27 | }; 28 | 29 | match().filter(test).foreach(1.0); 30 | 31 | END_FDB_SCRIPT 32 | -------------------------------------------------------------------------------- /src/test/compiler/dependency_test.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "furious.h" 3 | #include "basic_test_header.h" 4 | 5 | #include 6 | 7 | 8 | 9 | TEST(BasicTest, BasicTest ) 10 | { 11 | fdb_database_t database; 12 | fdb_database_init(&database, NULL); 13 | fdb_database_start_webserver(&database, 14 | "localhost", 15 | "8080"); 16 | furious_init(&database); 17 | 18 | fdb_table_t* pos_table = FDB_FIND_TABLE(&database, Position); 19 | fdb_table_t* vel_table = FDB_FIND_TABLE(&database, Velocity); 20 | 21 | entity_id_t NUM_ENTITIES = 1000; 22 | for(entity_id_t i = 0; i < NUM_ENTITIES; ++i) 23 | { 24 | Position* pos = FDB_ADD_COMPONENT(pos_table, Position, i); 25 | pos->m_x = 0.0f; 26 | pos->m_y = 0.0f; 27 | pos->m_z = 0.0f; 28 | Velocity* vel = FDB_ADD_COMPONENT(vel_table, Velocity, i); 29 | vel->m_x = 1.0f; 30 | vel->m_y = 1.0f; 31 | vel->m_z = 1.0f; 32 | } 33 | 34 | furious_frame(0.1,&database, nullptr); 35 | 36 | for (entity_id_t i = 0; i < NUM_ENTITIES; ++i) 37 | { 38 | Position* position = FDB_GET_COMPONENT(pos_table, Position, i); 39 | ASSERT_EQ(position->m_x,-0.1f); 40 | ASSERT_EQ(position->m_y,-0.1f); 41 | ASSERT_EQ(position->m_z,-0.1f); 42 | } 43 | furious_release(); 44 | fdb_database_release(&database); 45 | } 46 | 47 | int main(int argc, char *argv[]) 48 | { 49 | ::testing::InitGoogleTest(&argc, argv); 50 | int ret = RUN_ALL_TESTS(); 51 | return ret; 52 | } 53 | 54 | -------------------------------------------------------------------------------- /src/test/compiler/dependency_test_header.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _DEPENDENCY_TEST_HEADER_H_ 3 | #define _DEPENDENCY_TEST_HEADER_H_ value 4 | 5 | #include "furious_macros.h" 6 | 7 | FDB_BEGIN_COMPONENT(Position, KILOBYTES(4)) 8 | float m_x; 9 | float m_y; 10 | float m_z; 11 | FDB_END_COMPONENT 12 | 13 | FDB_BEGIN_COMPONENT(Velocity, KILOBYTES(4)) 14 | float m_x; 15 | float m_y; 16 | float m_z; 17 | FDB_END_COMPONENT 18 | 19 | #endif /* ifndef _BASIC_TEST_HEADER_H_ */ 20 | -------------------------------------------------------------------------------- /src/test/compiler/dependency_test_script.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "lang/lang.h" 3 | #include "dependency_test_header.h" 4 | 5 | BEGIN_FDB_SCRIPT 6 | 7 | struct UpdateVelocity 8 | { 9 | void run(fdb_context_t* context, 10 | uint32_t id, 11 | Velocity* velocity) 12 | { 13 | velocity->m_x *=-1.0; 14 | velocity->m_y *=-1.0; 15 | velocity->m_z *=-1.0; 16 | } 17 | 18 | }; 19 | 20 | struct UpdatePosition 21 | { 22 | UpdatePosition(float speed) : m_speed{speed} {} 23 | 24 | void run(fdb_context_t* context, 25 | uint32_t id, 26 | Position* position, 27 | const Velocity* velocity) 28 | { 29 | position->m_x = position->m_x + velocity->m_x*context->m_dt*m_speed; 30 | position->m_y = position->m_y + velocity->m_y*context->m_dt*m_speed; 31 | position->m_z = position->m_z + velocity->m_z*context->m_dt*m_speed; 32 | } 33 | 34 | float m_speed = 1.0; 35 | }; 36 | 37 | match().foreach(1.0); 38 | match().foreach(); 39 | 40 | END_FDB_SCRIPT 41 | -------------------------------------------------------------------------------- /src/test/compiler/expand_test_header.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _EXPAND_TEST_HEADER_H_ 3 | #define _EXPAND_TEST_HEADER_H_ value 4 | 5 | #include "furious_macros.h" 6 | 7 | FDB_BEGIN_COMPONENT(SimpleComponent1, KILOBYTES(4)) 8 | float m_x; 9 | float m_y; 10 | float m_z; 11 | FDB_END_COMPONENT 12 | 13 | FDB_BEGIN_COMPONENT(SimpleComponent2, KILOBYTES(4)) 14 | float m_x; 15 | float m_y; 16 | float m_z; 17 | FDB_END_COMPONENT 18 | 19 | FDB_BEGIN_COMPONENT(Position, KILOBYTES(4)) 20 | float m_x; 21 | float m_y; 22 | float m_z; 23 | FDB_END_COMPONENT 24 | 25 | FDB_BEGIN_COMPONENT(Velocity, KILOBYTES(4)) 26 | float m_x; 27 | float m_y; 28 | float m_z; 29 | FDB_END_COMPONENT 30 | 31 | FDB_BEGIN_COMPONENT(Intensity, KILOBYTES(4)) 32 | float m_intensity; 33 | FDB_END_COMPONENT 34 | 35 | FDB_BEGIN_COMPONENT(FieldMesh, KILOBYTES(4)) 36 | float m_x; 37 | float m_y; 38 | float m_z; 39 | FDB_END_COMPONENT 40 | 41 | //////////////////////////////////////////////// 42 | //////////////////////////////////////////////// 43 | //////////////////////////////////////////////// 44 | 45 | FDB_BEGIN_COMPONENT(TestComponent1, KILOBYTES(4)) 46 | float m_a; 47 | float m_b; 48 | float m_c; 49 | FDB_END_COMPONENT 50 | 51 | FDB_BEGIN_COMPONENT(TestComponent2, KILOBYTES(4)) 52 | float m_a; 53 | float m_b; 54 | float m_c; 55 | FDB_END_COMPONENT 56 | 57 | #endif /* ifndef _BASIC_TEST_HEADER_H_ */ 58 | -------------------------------------------------------------------------------- /src/test/compiler/expand_test_script.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "lang/lang.h" 3 | #include "expand_test_header.h" 4 | 5 | BEGIN_FDB_SCRIPT 6 | 7 | //////////////////////////////////////////////// 8 | //////////////////////////////////////////////// 9 | //////////////////////////////////////////////// 10 | 11 | 12 | struct SimpleSystem 13 | { 14 | void run(fdb_context_t* context, 15 | uint32_t id, 16 | SimpleComponent1* simple_component1, 17 | const SimpleComponent2* simple_component2) 18 | { 19 | simple_component1->m_x = simple_component2->m_x; 20 | simple_component1->m_y = simple_component2->m_y; 21 | simple_component1->m_z = simple_component2->m_z; 22 | } 23 | }; 24 | 25 | match().expand("parent").foreach(); 26 | 27 | //////////////////////////////////////////////// 28 | //////////////////////////////////////////////// 29 | //////////////////////////////////////////////// 30 | 31 | struct UpdatePosition 32 | { 33 | UpdatePosition(float speed) : m_speed{speed} {} 34 | 35 | void run(fdb_context_t* context, 36 | uint32_t id, 37 | Position* position, 38 | const Velocity* velocity, 39 | const Position* parent_position) 40 | { 41 | position->m_x = (position->m_x + parent_position->m_x) * velocity->m_x*context->m_dt*m_speed; 42 | position->m_y = (position->m_y + parent_position->m_y) * velocity->m_y*context->m_dt*m_speed; 43 | position->m_z = (position->m_z + parent_position->m_z) * velocity->m_z*context->m_dt*m_speed; 44 | } 45 | 46 | float m_speed = 1.0f; 47 | }; 48 | 49 | struct ResetPosition 50 | { 51 | void run(fdb_context_t* context, 52 | uint32_t id, 53 | Position* position) 54 | { 55 | position->m_x = 1.0f; 56 | position->m_y = 1.0f; 57 | position->m_z = 1.0f; 58 | } 59 | }; 60 | 61 | struct PropagateIntensity 62 | { 63 | void run(fdb_context_t* context, 64 | uint32_t id, 65 | FieldMesh* field, 66 | const Position* parent_position, 67 | const Intensity* parent_intensity) 68 | { 69 | // DRAW FIELD MESH 70 | field->m_x = parent_position->m_x*parent_intensity->m_intensity; 71 | field->m_y = parent_position->m_y*parent_intensity->m_intensity; 72 | field->m_z = parent_position->m_z*parent_intensity->m_intensity; 73 | } 74 | 75 | }; 76 | 77 | struct DrawFieldMesh 78 | { 79 | void run(fdb_context_t* context, 80 | uint32_t id, 81 | const FieldMesh* field) 82 | { 83 | // DRAW FIELD MESH 84 | } 85 | 86 | }; 87 | 88 | struct IncrementFieldMesh 89 | { 90 | void run(fdb_context_t* context, 91 | uint32_t id, 92 | FieldMesh* field) 93 | { 94 | 95 | // DRAW FIELD MESH 96 | field->m_x += 1.0; 97 | field->m_y += 1.0; 98 | field->m_z += 1.0; 99 | } 100 | }; 101 | 102 | match().foreach(); 103 | match().expand("parent").foreach(1.0f).set_priority(2); 104 | match().foreach(); 105 | match().expand("parent").foreach(); 106 | match().expand<>("parent").has_tag("test").foreach().set_priority(2); 107 | 108 | //////////////////////////////////////////////// 109 | //////////////////////////////////////////////// 110 | //////////////////////////////////////////////// 111 | 112 | 113 | struct TestSystemCascading 114 | { 115 | void run(fdb_context_t* context, 116 | uint32_t id, 117 | TestComponent1* comp_1, 118 | const TestComponent1* parent_comp_1, 119 | const TestComponent2* parent_comp_2) 120 | { 121 | } 122 | }; 123 | 124 | match().expand("parent").foreach(); 125 | 126 | END_FDB_SCRIPT 127 | -------------------------------------------------------------------------------- /src/test/compiler/filter_func_test.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "furious.h" 3 | #include "filter_func_test_header.h" 4 | 5 | #include 6 | 7 | 8 | TEST(FilterFuncTest, FilterFuncTest ) 9 | { 10 | fdb_database_t database; 11 | fdb_database_init(&database, nullptr); 12 | furious_init(&database); 13 | 14 | fdb_table_t* pos_table = FDB_FIND_TABLE(&database, Position); 15 | fdb_table_t* vel_table = FDB_FIND_TABLE(&database, Velocity); 16 | 17 | entity_id_t NUM_ENTITIES = 1000; 18 | for(entity_id_t i = 0; i < NUM_ENTITIES; ++i) 19 | { 20 | Position* pos = FDB_ADD_COMPONENT(pos_table, Position, i); 21 | pos->m_x = 0.0; 22 | pos->m_y = 0.0; 23 | pos->m_z = 0.0; 24 | 25 | Velocity* vel = FDB_ADD_COMPONENT(vel_table, Velocity, i); 26 | float tmp = 1.0f; 27 | if(i % 2 != 0) 28 | { 29 | tmp = 2.0f; 30 | } 31 | 32 | vel->m_x = tmp; 33 | vel->m_y = tmp; 34 | vel->m_z = tmp; 35 | } 36 | 37 | furious_frame(0.1f, &database, nullptr); 38 | 39 | for(entity_id_t i = 0; i < NUM_ENTITIES; ++i) 40 | { 41 | Position* pos = FDB_GET_COMPONENT(pos_table, Position, i); 42 | 43 | float tmp = 0.1; 44 | if(i % 2 != 0) 45 | { 46 | tmp = 0.0; 47 | } 48 | 49 | ASSERT_EQ(pos->m_x, tmp); 50 | ASSERT_EQ(pos->m_y, tmp); 51 | ASSERT_EQ(pos->m_z, tmp); 52 | 53 | } 54 | furious_release(); 55 | fdb_database_release(&database); 56 | } 57 | 58 | int main(int argc, char *argv[]) 59 | { 60 | ::testing::InitGoogleTest(&argc, argv); 61 | int ret = RUN_ALL_TESTS(); 62 | return ret; 63 | } 64 | 65 | -------------------------------------------------------------------------------- /src/test/compiler/filter_func_test_header.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _FILTER_FUNC_TEST_HEADER_H_ 3 | #define _FILTER_FUNC_TEST_HEADER_H_ value 4 | 5 | #include "furious_macros.h" 6 | 7 | FDB_BEGIN_COMPONENT(Position, KILOBYTES(4)) 8 | float m_x; 9 | float m_y; 10 | float m_z; 11 | FDB_END_COMPONENT 12 | 13 | FDB_BEGIN_COMPONENT(Velocity, KILOBYTES(4)) 14 | float m_x; 15 | float m_y; 16 | float m_z; 17 | FDB_END_COMPONENT 18 | 19 | #endif /* ifndef _BASIC_TEST_HEADER_H_ */ 20 | -------------------------------------------------------------------------------- /src/test/compiler/filter_func_test_script.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "lang/lang.h" 3 | #include "filter_func_test_header.h" 4 | 5 | static bool filter(const Position* pos, const Velocity* vel) 6 | { 7 | return vel->m_x < 2.0f && vel->m_y < 2.0f && vel->m_z < 2.0f; 8 | } 9 | 10 | BEGIN_FDB_SCRIPT 11 | 12 | struct UpdatePosition 13 | { 14 | UpdatePosition(float speed) : m_speed{speed} {} 15 | 16 | void run(fdb_context_t* context, 17 | uint32_t id, 18 | Position* position, 19 | const Velocity* velocity) 20 | { 21 | position->m_x = position->m_x + velocity->m_x*context->m_dt*m_speed; 22 | position->m_y = position->m_y + velocity->m_y*context->m_dt*m_speed; 23 | position->m_z = position->m_z + velocity->m_z*context->m_dt*m_speed; 24 | } 25 | 26 | float m_speed = 1.0f; 27 | }; 28 | 29 | match().filter(filter) 30 | .foreach(1.0f); 31 | 32 | END_FDB_SCRIPT 33 | -------------------------------------------------------------------------------- /src/test/compiler/filter_lambda_test.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "furious.h" 3 | #include "filter_func_test_header.h" 4 | 5 | #include 6 | 7 | 8 | TEST(FilterLambdaTest, FilterLambdaTest ) 9 | { 10 | fdb_database_t database; 11 | fdb_database_init(&database, nullptr); 12 | fdb_database_start_webserver(&database, 13 | "localhost", 14 | "8080"); 15 | furious_init(&database); 16 | 17 | fdb_table_t* pos_table = FDB_FIND_TABLE(&database, Position); 18 | fdb_table_t* vel_table = FDB_FIND_TABLE(&database, Velocity); 19 | 20 | entity_id_t NUM_ENTITIES = 1000; 21 | for(entity_id_t i = 0; i < NUM_ENTITIES; ++i) 22 | { 23 | Position* pos = FDB_ADD_COMPONENT(pos_table, Position, i); 24 | pos->m_x = 0.0; 25 | pos->m_y = 0.0; 26 | pos->m_z = 0.0; 27 | 28 | Velocity* vel = FDB_ADD_COMPONENT(vel_table, Velocity, i); 29 | float tmp = 1.0f; 30 | if(i % 2 != 0) 31 | { 32 | tmp = 2.0; 33 | } 34 | vel->m_x = tmp; 35 | vel->m_y = tmp; 36 | vel->m_z = tmp; 37 | } 38 | 39 | furious_frame(0.1f, &database, nullptr); 40 | 41 | for(entity_id_t i = 0; i < NUM_ENTITIES; ++i) 42 | { 43 | Position* pos = FDB_GET_COMPONENT(pos_table, Position, i); 44 | 45 | float tmp = 0.1f; 46 | if(i % 2 != 0) 47 | { 48 | tmp = 0.0; 49 | } 50 | ASSERT_EQ(pos->m_x, tmp); 51 | ASSERT_EQ(pos->m_y, tmp); 52 | ASSERT_EQ(pos->m_z, tmp); 53 | } 54 | furious_release(); 55 | fdb_database_release(&database); 56 | } 57 | 58 | int main(int argc, char *argv[]) 59 | { 60 | ::testing::InitGoogleTest(&argc, argv); 61 | int ret = RUN_ALL_TESTS(); 62 | return ret; 63 | } 64 | 65 | -------------------------------------------------------------------------------- /src/test/compiler/filter_lambda_test_header.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _FILTER_LAMBDA_TEST_HEADER_H_ 3 | #define _FILTER_LAMBDA_TEST_HEADER_H_ value 4 | 5 | #include "furious_macros.h" 6 | 7 | FURIOUS_BEGIN_COMPONENT(Position, KILOBYTES(4)) 8 | float m_x; 9 | float m_y; 10 | float m_z; 11 | FURIOUS_END_COMPONENT 12 | 13 | FURIOUS_BEGIN_COMPONENT(Velocity, KILOBYTES(4)) 14 | float m_x; 15 | float m_y; 16 | float m_z; 17 | FURIOUS_END_COMPONENT 18 | 19 | #endif /* ifndef _BASIC_TEST_HEADER_H_ */ 20 | -------------------------------------------------------------------------------- /src/test/compiler/filter_lambda_test_script.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "filter_func_test_header.h" 3 | #include "lang/lang.h" 4 | 5 | BEGIN_FDB_SCRIPT 6 | 7 | struct UpdatePosition 8 | { 9 | UpdatePosition(float speed) : m_speed{speed} {} 10 | 11 | void run(fdb_context_t* context, 12 | uint32_t id, 13 | Position* position, 14 | const Velocity* velocity) 15 | { 16 | position->m_x = position->m_x + velocity->m_x*context->m_dt*m_speed; 17 | position->m_y = position->m_y + velocity->m_y*context->m_dt*m_speed; 18 | position->m_z = position->m_z + velocity->m_z*context->m_dt*m_speed; 19 | } 20 | 21 | float m_speed = 1.0f; 22 | }; 23 | 24 | match().filter([](const Position* pos, const Velocity* vel) { 25 | return vel->m_x < 2.0f && vel->m_y < 2.0f && vel->m_z < 2.0f; 26 | }) 27 | .foreach(1.0f); 28 | 29 | END_FDB_SCRIPT 30 | -------------------------------------------------------------------------------- /src/test/compiler/filter_tag_test.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "filter_tag_test_header.h" 3 | #include "furious.h" 4 | 5 | #include 6 | 7 | 8 | 9 | TEST(FilterTagTest, FilterTagTest ) 10 | { 11 | fdb_database_t database; 12 | fdb_database_init(&database, nullptr); 13 | fdb_database_start_webserver(&database, 14 | "localhost", 15 | "8080"); 16 | furious_init(&database); 17 | 18 | fdb_table_t* pos_table = FDB_FIND_TABLE(&database, Position); 19 | fdb_table_t* vel_table = FDB_FIND_TABLE(&database, Velocity); 20 | fdb_bittable_t* aff_table = FDB_FIND_TAG_TABLE(&database, "affected"); 21 | fdb_bittable_t* naff_table = FDB_FIND_TAG_TABLE(&database, "not_affected"); 22 | 23 | entity_id_t NUM_ENTITIES = 1000; 24 | for(entity_id_t i = 0; i < NUM_ENTITIES; ++i) 25 | { 26 | Position* pos = FDB_ADD_COMPONENT(pos_table, Position, i); 27 | pos->m_x = 0.0f; 28 | pos->m_y = 0.0f; 29 | pos->m_z = 0.0f; 30 | 31 | Velocity* vel = FDB_ADD_COMPONENT(vel_table, Velocity, i); 32 | vel->m_x = 1.0f; 33 | vel->m_y = 1.0f; 34 | vel->m_z = 1.0f; 35 | 36 | if(i % 2 == 0) 37 | { 38 | FDB_ADD_TAG(aff_table, i); 39 | } 40 | 41 | if(i % 6 == 0) 42 | { 43 | FDB_ADD_TAG(naff_table, i); 44 | } 45 | 46 | } 47 | 48 | furious_frame(0.1f, &database, nullptr); 49 | 50 | for(entity_id_t i = 0; i < NUM_ENTITIES; ++i) 51 | { 52 | Position* pos = FDB_GET_COMPONENT(pos_table,Position,i); 53 | 54 | if(i % 2 == 0 && i % 6 != 0) 55 | { 56 | ASSERT_EQ(pos->m_x, 0.1f); 57 | ASSERT_EQ(pos->m_y, 0.1f); 58 | ASSERT_EQ(pos->m_z, 0.1f); 59 | } 60 | 61 | if(i % 6 == 0 || i % 2 != 0) 62 | { 63 | ASSERT_EQ(pos->m_x , 0.0f); 64 | ASSERT_EQ(pos->m_y , 0.0f); 65 | ASSERT_EQ(pos->m_z , 0.0f); 66 | } 67 | 68 | } 69 | furious_release(); 70 | fdb_database_release(&database); 71 | } 72 | 73 | int main(int argc, char *argv[]) 74 | { 75 | ::testing::InitGoogleTest(&argc, argv); 76 | int ret = RUN_ALL_TESTS(); 77 | return ret; 78 | } 79 | 80 | -------------------------------------------------------------------------------- /src/test/compiler/filter_tag_test_header.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _FILTER_TAG_TEST_HEADER_H_ 3 | #define _FILTER_TAG_TEST_HEADER_H_ value 4 | 5 | #include "furious_macros.h" 6 | 7 | FDB_BEGIN_COMPONENT(Position, KILOBYTES(4)) 8 | float m_x; 9 | float m_y; 10 | float m_z; 11 | FDB_END_COMPONENT 12 | 13 | FDB_BEGIN_COMPONENT(Velocity, KILOBYTES(4)) 14 | float m_x; 15 | float m_y; 16 | float m_z; 17 | FDB_END_COMPONENT 18 | 19 | #endif /* ifndef _BASIC_TEST_HEADER_H_ */ 20 | -------------------------------------------------------------------------------- /src/test/compiler/filter_tag_test_script.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "filter_tag_test_header.h" 3 | #include "lang/lang.h" 4 | 5 | BEGIN_FDB_SCRIPT 6 | 7 | struct UpdatePosition 8 | { 9 | 10 | UpdatePosition(float speed) : m_speed{speed} {} 11 | 12 | void run(fdb_context_t* context, 13 | uint32_t id, 14 | Position* position, 15 | const Velocity* velocity) 16 | { 17 | position->m_x = position->m_x + velocity->m_x*context->m_dt*m_speed; 18 | position->m_y = position->m_y + velocity->m_y*context->m_dt*m_speed; 19 | position->m_z = position->m_z + velocity->m_z*context->m_dt*m_speed; 20 | } 21 | 22 | float m_speed = 1.0f; 23 | }; 24 | 25 | match().has_tag("affected") 26 | .has_not_tag("not_affected") 27 | .foreach(1.0f); 28 | 29 | END_FDB_SCRIPT 30 | -------------------------------------------------------------------------------- /src/test/compiler/global_test.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "furious.h" 3 | #include "global_test_header.h" 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | 11 | TEST(GlobalTest, GlobalTest ) 12 | { 13 | fdb_database_t database; 14 | fdb_database_init(&database, nullptr); 15 | fdb_database_start_webserver(&database, 16 | "localhost", 17 | "8080"); 18 | 19 | fdb_table_t* pos_table = FDB_FIND_OR_CREATE_TABLE(&database, Position, nullptr); 20 | GlobalComponent* g = FDB_CREATE_GLOBAL(&database, GlobalComponent, nullptr); 21 | g->m_x = 1.0; 22 | g->m_y = 1.0; 23 | g->m_z = 1.0; 24 | 25 | entity_id_t NUM_ENTITIES = 8; 26 | for(uint32_t i = 0; i < NUM_ENTITIES; ++i) 27 | { 28 | Position* pos = FDB_ADD_COMPONENT(pos_table, Position, i); 29 | pos->m_x = 0.0f; 30 | pos->m_y = 0.0f; 31 | pos->m_z = 0.0f; 32 | } 33 | 34 | furious_init(&database); 35 | furious_frame(0.1, &database, nullptr); 36 | 37 | // FIRST LEVEL 38 | for(uint32_t i = 0; i < 8; ++i) 39 | { 40 | Position* pos = FDB_GET_COMPONENT(pos_table,Position,i); 41 | ASSERT_EQ(pos->m_x, 1.0f); 42 | ASSERT_EQ(pos->m_y, 1.0f); 43 | ASSERT_EQ(pos->m_z, 1.0f); 44 | } 45 | 46 | furious_release(); 47 | fdb_database_release(&database); 48 | } 49 | 50 | int main(int argc, char *argv[]) 51 | { 52 | ::testing::InitGoogleTest(&argc, argv); 53 | int ret = RUN_ALL_TESTS(); 54 | return ret; 55 | } 56 | 57 | -------------------------------------------------------------------------------- /src/test/compiler/global_test_header.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _GLOBAL_TEST_HEADER_H_ 3 | #define _GLOBAL_TEST_HEADER_H_ value 4 | 5 | #include "furious_macros.h" 6 | 7 | FDB_BEGIN_COMPONENT(Position, KILOBYTES(4)) 8 | float m_x; 9 | float m_y; 10 | float m_z; 11 | FDB_END_COMPONENT 12 | 13 | FDB_BEGIN_GLOBAL_COMPONENT(GlobalComponent) 14 | float m_x; 15 | float m_y; 16 | float m_z; 17 | FDB_END_COMPONENT 18 | 19 | #endif /* ifndef _BASIC_TEST_HEADER_H_ */ 20 | -------------------------------------------------------------------------------- /src/test/compiler/global_test_script.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "lang/lang.h" 3 | #include "global_test_header.h" 4 | 5 | BEGIN_FDB_SCRIPT 6 | 7 | struct UpdatePosition 8 | { 9 | UpdatePosition() {} 10 | 11 | void run(fdb_context_t* context, 12 | uint32_t id, 13 | const GlobalComponent* global, 14 | Position* position 15 | ) 16 | { 17 | position->m_x = (position->m_x + global->m_x); 18 | position->m_y = (position->m_y + global->m_y); 19 | position->m_z = (position->m_z + global->m_z); 20 | } 21 | 22 | }; 23 | 24 | match, Position>().foreach(); 25 | 26 | 27 | END_FDB_SCRIPT 28 | -------------------------------------------------------------------------------- /src/test/compiler/reflection_test.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "furious.h" 3 | #include "reflection_test_header.h" 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | 11 | 12 | TEST(ReflectionTest, ReflectionTest ) 13 | { 14 | fdb_database_t database; 15 | fdb_database_init(&database, NULL); 16 | fdb_database_start_webserver(&database, 17 | "localhost", 18 | "8080"); 19 | furious_init(&database); 20 | 21 | fdb_table_t* tc_table = FDB_FIND_TABLE(&database, TestComponent); 22 | entity_id_t ent = 0; 23 | TestComponent* tc = FDB_ADD_COMPONENT(tc_table, TestComponent, ent); 24 | tc->m_x = 1.0f; 25 | tc->m_y = 2.0f; 26 | tc->m_z = 3.0f; 27 | tc->m_q = 4.0f; 28 | tc->m_t = 5.0f; 29 | tc->X.m_a = 6.0f; 30 | tc->X.m_b = 6.0f; 31 | 32 | furious_frame(0.1, &database, nullptr); 33 | 34 | void* raw_pointer = tc; 35 | const fdb_mstruct_t* mstruct = FDB_GET_REFL_DATA(&database, TestComponent); 36 | ASSERT_TRUE(mstruct != nullptr); 37 | for(uint32_t i = 0; i < mstruct->m_nfields; ++i) 38 | { 39 | const fdb_mfield_t* field = mstruct->p_fields[i]; 40 | if(strcmp(field->m_name,"m_x")==0) 41 | { 42 | float* field_ptr = (float*)((char*)raw_pointer + field->m_offset); 43 | ASSERT_EQ(*field_ptr,1.0f); 44 | continue; 45 | } 46 | 47 | if(strcmp(field->m_name, "m_y")==0) 48 | { 49 | printf("%ld\n", field->m_offset); 50 | float* field_ptr = (float*)((char*)raw_pointer + field->m_offset); 51 | ASSERT_EQ(*field_ptr,2.0f); 52 | continue; 53 | } 54 | 55 | if(strcmp(field->m_name, "m_z")==0) 56 | { 57 | float* field_ptr = (float*)((char*)raw_pointer + field->m_offset); 58 | ASSERT_EQ(*field_ptr , 3.0f); 59 | continue; 60 | } 61 | 62 | if(strcmp(field->m_name,"") == 0 && field->m_anonymous) 63 | { 64 | const fdb_mstruct_t* child = field->p_strct_type; 65 | for(uint32_t j = 0; j < child->m_nfields; ++j) 66 | { 67 | const fdb_mfield_t* child_field = child->p_fields[j]; 68 | 69 | if(strcmp(child_field->m_name,"m_q")==0) 70 | { 71 | float* field_ptr = (float*)((char*)raw_pointer + child_field->m_offset); 72 | ASSERT_EQ(*field_ptr , 4.0f); 73 | continue; 74 | } 75 | 76 | if(strcmp(child_field->m_name, "m_t") == 0) 77 | { 78 | float* field_ptr = (float*)((char*)raw_pointer + child_field->m_offset); 79 | ASSERT_EQ(*field_ptr , 5.0f); 80 | continue; 81 | } 82 | } 83 | 84 | continue; 85 | } 86 | 87 | if(strcmp(field->m_name,"X") == 0) 88 | { 89 | const fdb_mstruct_t* child = field->p_strct_type; 90 | for(uint32_t j = 0; j < child->m_nfields; ++j) 91 | { 92 | const fdb_mfield_t* child_field = child->p_fields[j]; 93 | 94 | if(strcmp(child_field->m_name,"m_a") == 0) 95 | { 96 | float* field_ptr = (float*)((char*)raw_pointer + field->m_offset + child_field->m_offset); 97 | ASSERT_EQ(*field_ptr , 6.0f); 98 | continue; 99 | } 100 | 101 | if(strcmp(child_field->m_name, "m_b") == 0) 102 | { 103 | float* field_ptr = (float*)((char*)raw_pointer + field->m_offset + child_field->m_offset); 104 | ASSERT_EQ(*field_ptr , 6.0f); 105 | continue; 106 | } 107 | } 108 | continue; 109 | } 110 | } 111 | 112 | furious_release(); 113 | fdb_database_release(&database); 114 | } 115 | 116 | int main(int argc, char *argv[]) 117 | { 118 | ::testing::InitGoogleTest(&argc, argv); 119 | int ret = RUN_ALL_TESTS(); 120 | return ret; 121 | } 122 | 123 | -------------------------------------------------------------------------------- /src/test/compiler/reflection_test_header.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _REFLECTION_TEST_HEADER_H_ 3 | #define _REFLECTION_TEST_HEADER_H_ value 4 | 5 | #include "furious_macros.h" 6 | 7 | FDB_BEGIN_COMPONENT(TestComponent, KILOBYTES(4)) 8 | float m_x; 9 | float m_y; 10 | float m_z; 11 | 12 | struct { 13 | float m_q; 14 | float m_t; 15 | }; 16 | 17 | union { 18 | float m_a; 19 | float m_b; 20 | } X; 21 | FDB_END_COMPONENT 22 | 23 | 24 | #endif /* ifndef _BASIC_TEST_HEADER_H_ */ 25 | 26 | -------------------------------------------------------------------------------- /src/test/compiler/reflection_test_script.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "lang/lang.h" 3 | #include "reflection_test_header.h" 4 | 5 | BEGIN_FDB_SCRIPT 6 | 7 | struct TestSystem 8 | { 9 | void run(fdb_context_t* context, 10 | uint32_t id, 11 | TestComponent* position) 12 | { 13 | 14 | 15 | } 16 | }; 17 | 18 | match().foreach(); 19 | 20 | END_FDB_SCRIPT 21 | -------------------------------------------------------------------------------- /src/test/runtime/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | CMAKE_MINIMUM_REQUIRED (VERSION 2.8) 2 | 3 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions") 4 | #set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -g -pg -DNDEBUG -ftree-vectorize -ftree-vectorizer-verbose=7 -fopt-info-vec-all -fno-devirtualize ") 5 | 6 | add_definitions(${FURIOUS_DEFAULT_DEFINES}) 7 | 8 | find_package(GTest REQUIRED) 9 | include_directories(${GTEST_INCLUDE_DIRS}) 10 | include_directories(${FURIOUS_INCLUDE_DIR}) 11 | 12 | function(create_test NAME) 13 | add_executable(${NAME} 14 | ${NAME}.cpp 15 | ) 16 | 17 | target_link_libraries(${NAME} ${GTEST_LIBRARIES} furious) 18 | add_test(${NAME} ${FURIOUS_OUTPUT_DIR}/test/runtime/${NAME}) 19 | 20 | set_target_properties( ${NAME} 21 | PROPERTIES 22 | RUNTIME_OUTPUT_DIRECTORY ${FURIOUS_OUTPUT_DIR}/test/runtime 23 | ) 24 | endfunction(create_test) 25 | 26 | SET(TESTS 27 | pool_alloc_test 28 | page_alloc_test 29 | stack_alloc_test 30 | blockcluster_test 31 | hashtable_test 32 | bitmap_test 33 | btree_test 34 | memory_test 35 | table_test 36 | bittable_test 37 | database_test 38 | tags_test 39 | refs_test 40 | dyn_array_test 41 | txpool_alloc_test 42 | ) 43 | 44 | foreach( TEST ${TESTS} ) 45 | create_test(${TEST}) 46 | endforeach( TEST ) 47 | 48 | add_custom_target(runtime_tests COMMAND ${CMAKE_CTEST_COMMAND} 49 | DEPENDS ${TESTS}) 50 | -------------------------------------------------------------------------------- /src/test/runtime/bitmap_test.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "../../common/bitmap.h" 3 | #include "../../common/memory/stack_allocator.h" 4 | 5 | #include 6 | #include 7 | 8 | TEST(BitmapTest, BitmapTest ) 9 | { 10 | constexpr uint32_t BITMAP_SIZE = 304; 11 | fdb_stack_alloc_t lallocator; 12 | fdb_stack_alloc_init(&lallocator, KILOBYTES(4), NULL); 13 | fdb_bitmap_t bitmap; 14 | fdb_bitmap_init(&bitmap, BITMAP_SIZE, &lallocator.m_super); 15 | ASSERT_EQ(bitmap.m_num_set, 0); 16 | 17 | for(uint32_t i = 0; i < BITMAP_SIZE; ++i) 18 | { 19 | ASSERT_EQ(fdb_bitmap_is_set(&bitmap, i), false); 20 | fdb_bitmap_set(&bitmap, i); 21 | } 22 | 23 | ASSERT_EQ(bitmap.m_num_set, BITMAP_SIZE); 24 | 25 | for(uint32_t i = 0; i < BITMAP_SIZE; ++i) 26 | { 27 | ASSERT_EQ(fdb_bitmap_is_set(&bitmap, i), true); 28 | fdb_bitmap_unset(&bitmap, i); 29 | ASSERT_EQ(fdb_bitmap_is_set(&bitmap, i), false); 30 | } 31 | 32 | ASSERT_EQ(bitmap.m_num_set, 0); 33 | 34 | for(uint32_t i = 0; i < BITMAP_SIZE; i+=2) 35 | { 36 | ASSERT_EQ(fdb_bitmap_is_set(&bitmap, i), false); 37 | fdb_bitmap_set(&bitmap, i); 38 | ASSERT_EQ(fdb_bitmap_is_set(&bitmap, i), true); 39 | } 40 | 41 | ASSERT_EQ(bitmap.m_num_set, BITMAP_SIZE/2); 42 | 43 | for(uint32_t i = 0; i < BITMAP_SIZE; ++i) 44 | { 45 | if(i % 2 == 0) 46 | { 47 | ASSERT_EQ(fdb_bitmap_is_set(&bitmap, i), true); 48 | fdb_bitmap_unset(&bitmap, i); 49 | ASSERT_EQ(fdb_bitmap_is_set(&bitmap, i), false); 50 | } 51 | else 52 | { 53 | ASSERT_EQ(fdb_bitmap_is_set(&bitmap, i), false); 54 | fdb_bitmap_set(&bitmap, i); 55 | ASSERT_EQ(fdb_bitmap_is_set(&bitmap, i), true); 56 | } 57 | } 58 | 59 | ASSERT_EQ(bitmap.m_num_set, BITMAP_SIZE/2); 60 | 61 | fdb_bitmap_negate(&bitmap); 62 | 63 | ASSERT_EQ(bitmap.m_num_set, BITMAP_SIZE/2); 64 | 65 | for(uint32_t i = 0; i < BITMAP_SIZE; ++i) 66 | { 67 | if(i % 2 == 0) 68 | { 69 | ASSERT_EQ(fdb_bitmap_is_set(&bitmap, i), true); 70 | fdb_bitmap_unset(&bitmap, i); 71 | ASSERT_EQ(fdb_bitmap_is_set(&bitmap,i), false); 72 | } 73 | else 74 | { 75 | ASSERT_EQ(fdb_bitmap_is_set(&bitmap, i), false); 76 | fdb_bitmap_set(&bitmap, i); 77 | ASSERT_EQ(fdb_bitmap_is_set(&bitmap, i), true); 78 | } 79 | } 80 | ASSERT_EQ(bitmap.m_num_set, BITMAP_SIZE/2); 81 | 82 | fdb_bitmap_t bitmap2; 83 | fdb_bitmap_init(&bitmap2, 84 | BITMAP_SIZE, &lallocator.m_super); 85 | fdb_bitmap_set_bitmap(&bitmap2, &bitmap); 86 | 87 | fdb_bitmap_negate(&bitmap2); 88 | fdb_bitmap_set_or(&bitmap, &bitmap2); 89 | ASSERT_EQ(bitmap.m_num_set, BITMAP_SIZE); 90 | for(uint32_t i = 0; i < BITMAP_SIZE; ++i) 91 | { 92 | ASSERT_EQ(fdb_bitmap_is_set(&bitmap, i), true); 93 | } 94 | 95 | fdb_bitmap_set_and(&bitmap, &bitmap2); 96 | ASSERT_EQ(bitmap.m_num_set, BITMAP_SIZE/2); 97 | 98 | for(uint32_t i = 0; i < BITMAP_SIZE; ++i) 99 | { 100 | if(i % 2 == 0) 101 | { 102 | ASSERT_EQ(fdb_bitmap_is_set(&bitmap, i), true); 103 | } 104 | else 105 | { 106 | ASSERT_EQ(fdb_bitmap_is_set(&bitmap, i), false); 107 | } 108 | } 109 | fdb_bitmap_release(&bitmap, &lallocator.m_super); 110 | fdb_bitmap_release(&bitmap2, &lallocator.m_super); 111 | fdb_stack_alloc_release(&lallocator); 112 | } 113 | 114 | int main(int argc, char *argv[]) 115 | { 116 | ::testing::InitGoogleTest(&argc, argv); 117 | int ret = RUN_ALL_TESTS(); 118 | return ret; 119 | } 120 | 121 | -------------------------------------------------------------------------------- /src/test/runtime/bittable_test.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "furious.h" 3 | 4 | #include 5 | 6 | TEST(BitTableTest, BitTableWorks) 7 | { 8 | 9 | fdb_stack_alloc_t lallocator; 10 | fdb_stack_alloc_init(&lallocator, 11 | KILOBYTES(64), nullptr); 12 | fdb_bittable_t bt; 13 | fdb_bittable_init(&bt, &lallocator.m_super); 14 | constexpr uint32_t num_elements = 32000; 15 | for(uint32_t i = 0; 16 | i < num_elements; 17 | ++i) 18 | { 19 | fdb_bittable_add(&bt,i); 20 | } 21 | 22 | for(uint32_t i = 0; 23 | i < num_elements; 24 | ++i) 25 | { 26 | fdb_bittable_get_bitmap(&bt, i); 27 | ASSERT_TRUE(fdb_bittable_exists(&bt, i)); 28 | } 29 | 30 | fdb_bittable_clear(&bt); 31 | 32 | for(uint32_t i = 0; 33 | i < num_elements; 34 | ++i) 35 | { 36 | ASSERT_FALSE(fdb_bittable_exists(&bt, i)); 37 | } 38 | 39 | for(uint32_t i = 0; 40 | i < num_elements; 41 | ++i) 42 | { 43 | fdb_bittable_add(&bt, i); 44 | } 45 | 46 | for(uint32_t i = 0; 47 | i < num_elements; 48 | ++i) 49 | { 50 | ASSERT_TRUE(fdb_bittable_exists(&bt, i)); 51 | } 52 | 53 | for(uint32_t i = 0; 54 | i < num_elements; 55 | ++i) 56 | { 57 | fdb_bittable_remove(&bt, i); 58 | } 59 | 60 | for(uint32_t i = 0; 61 | i < num_elements; 62 | ++i) 63 | { 64 | ASSERT_FALSE(fdb_bittable_exists(&bt, i)); 65 | } 66 | 67 | fdb_bittable_clear(&bt); 68 | fdb_bittable_release(&bt); 69 | fdb_stack_alloc_release(&lallocator); 70 | } 71 | 72 | /*TEST(BitTableTest, BitTableClear) 73 | { 74 | fdb_bittable_t bt = fdb_bittable_init(); 75 | constexpr uint32_t num_elements = 100000; 76 | for (uint32_t i = 0; 77 | i < num_elements; 78 | ++i) 79 | { 80 | if(i % 10000 == 0) 81 | { 82 | fdb_bittable_clear(&bt); 83 | } 84 | fdb_bittable_add(&bt, i); 85 | } 86 | fdb_bittable_clear(&bt); 87 | } 88 | */ 89 | 90 | 91 | TEST(BitTableTest, BitTableUnion) 92 | { 93 | fdb_bittable_t bt1; 94 | fdb_bittable_init(&bt1, nullptr); 95 | fdb_bittable_t bt2; 96 | fdb_bittable_init(&bt2, nullptr); 97 | constexpr uint32_t num_elements = 1000000; 98 | 99 | for(uint32_t i = 0; 100 | i < num_elements; 101 | ++i) 102 | { 103 | fdb_bittable_add(&bt2, i); 104 | } 105 | 106 | fdb_bittable_union(&bt1, &bt2); 107 | 108 | for(uint32_t i = 0; 109 | i < num_elements; 110 | ++i) 111 | { 112 | ASSERT_TRUE(fdb_bittable_exists(&bt1, i)); 113 | } 114 | 115 | fdb_bittable_union(&bt1, &bt2); 116 | 117 | for(uint32_t i = 0; 118 | i < num_elements; 119 | ++i) 120 | { 121 | ASSERT_TRUE(fdb_bittable_exists(&bt1, i)); 122 | } 123 | 124 | fdb_bittable_clear(&bt1); 125 | fdb_bittable_clear(&bt2); 126 | 127 | fdb_bittable_release(&bt1); 128 | fdb_bittable_release(&bt2); 129 | } 130 | 131 | TEST(BitTableTest, BitTableDifference) 132 | { 133 | fdb_bittable_t bt1; 134 | fdb_bittable_init(&bt1, nullptr); 135 | fdb_bittable_t bt2; 136 | fdb_bittable_init(&bt2, nullptr); 137 | constexpr uint32_t num_elements = 1000000; 138 | 139 | for(uint32_t i = 0; 140 | i < num_elements; 141 | ++i) 142 | { 143 | if(i%2 == 0) 144 | { 145 | fdb_bittable_add(&bt2, i); 146 | } 147 | fdb_bittable_add(&bt1, i); 148 | } 149 | 150 | fdb_bittable_difference(&bt1, &bt2); 151 | 152 | for(uint32_t i = 0; 153 | i < num_elements; 154 | ++i) 155 | { 156 | if(i%2 == 0) 157 | { 158 | ASSERT_FALSE(fdb_bittable_exists(&bt1, i)); 159 | ASSERT_TRUE(fdb_bittable_exists(&bt2, i)); 160 | } 161 | else 162 | { 163 | ASSERT_TRUE(fdb_bittable_exists(&bt1,i)); 164 | } 165 | } 166 | 167 | fdb_bittable_clear(&bt1); 168 | fdb_bittable_clear(&bt2); 169 | fdb_bittable_release(&bt1); 170 | fdb_bittable_release(&bt2); 171 | } 172 | 173 | TEST(BitTableTest, BitTableSteps) 174 | { 175 | fdb_bittable_t bt; 176 | fdb_bittable_init(&bt,nullptr); 177 | constexpr uint32_t MAX_ELEMENTS = 1600; 178 | uint32_t stride = 21; 179 | uint32_t offset = 21604; 180 | for (uint32_t i = 0; i < MAX_ELEMENTS; ++i) 181 | { 182 | fdb_bittable_add(&bt,i*stride + offset); 183 | } 184 | 185 | for (uint32_t i = 0; i < MAX_ELEMENTS; ++i) 186 | { 187 | const fdb_bitmap_t* bt_block = fdb_bittable_get_bitmap(&bt, i*stride+offset); 188 | ASSERT_NE(bt_block, nullptr); 189 | } 190 | 191 | //ASSERT_EQ(btree_num_allocations, 0); 192 | fdb_bittable_release(&bt); 193 | } 194 | 195 | int main(int argc, char *argv[]) 196 | { 197 | ::testing::InitGoogleTest(&argc, argv); 198 | int ret = RUN_ALL_TESTS(); 199 | return ret; 200 | } 201 | 202 | -------------------------------------------------------------------------------- /src/test/runtime/blockcluster_test.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "furious.h" 3 | 4 | #include 5 | 6 | 7 | TEST(fdb_bcluster_Test, fdb_bcluster_Test) 8 | { 9 | fdb_table_block_t tblock; 10 | fdb_table_block_init(&tblock, 11 | 64, 12 | sizeof(long), 13 | fdb_get_global_mem_allocator(), 14 | fdb_get_global_mem_allocator()); 15 | 16 | fdb_bcluster_t cluster; 17 | fdb_bcluster_init(&cluster, nullptr); 18 | fdb_bcluster_append_block(&cluster, &tblock); 19 | ASSERT_EQ(fdb_bcluster_get_tblock(&cluster, 0), &tblock); 20 | fdb_bcluster_append_global(&cluster, (void*)(0xff)); 21 | ASSERT_EQ(fdb_bcluster_get_global(&cluster, 1), (void*)0xff); 22 | 23 | fdb_table_block_t tblock2; 24 | fdb_table_block_init(&tblock2, 25 | 64, 26 | sizeof(int), 27 | fdb_get_global_mem_allocator(), 28 | fdb_get_global_mem_allocator()); 29 | 30 | fdb_bcluster_t cluster2; 31 | fdb_bcluster_init(&cluster2, nullptr); 32 | fdb_bcluster_append_block(&cluster2, &tblock2); 33 | 34 | fdb_bcluster_append_cluster(&cluster2, &cluster); 35 | ASSERT_EQ(fdb_bcluster_get_tblock(&cluster2, 0), &tblock2); 36 | ASSERT_EQ(fdb_bcluster_get_tblock(&cluster2,1), &tblock); 37 | ASSERT_EQ(fdb_bcluster_get_global(&cluster2,2), (void*)0xff); 38 | fdb_bcluster_release(&cluster, fdb_get_global_mem_allocator()); 39 | fdb_bcluster_release(&cluster2, fdb_get_global_mem_allocator()); 40 | } 41 | 42 | int main(int argc, char *argv[]) 43 | { 44 | ::testing::InitGoogleTest(&argc, argv); 45 | int ret = RUN_ALL_TESTS(); 46 | return ret; 47 | } 48 | 49 | -------------------------------------------------------------------------------- /src/test/runtime/database_test.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "furious.h" 3 | #include 4 | 5 | 6 | FDB_BEGIN_COMPONENT(Component, KILOBYTES(4)) 7 | 8 | uint32_t field1_; 9 | double field2_; 10 | 11 | Component(uint32_t field1, double field2) : 12 | field1_(field1), 13 | field2_(field2) 14 | {} 15 | FDB_END_COMPONENT 16 | 17 | TEST(DatabaseTest, CreateAndRemoveTable) { 18 | fdb_database_t database; 19 | fdb_database_init(&database, nullptr); 20 | fdb_database_clear(&database); 21 | FDB_CREATE_TABLE(&database, Component, NULL); 22 | FDB_REMOVE_TABLE(&database, Component); 23 | fdb_database_release(&database); 24 | } 25 | 26 | 27 | TEST(DatabaseTest, FindTable) { 28 | fdb_database_t database; 29 | fdb_database_init(&database, nullptr); 30 | fdb_database_clear(&database); 31 | FDB_CREATE_TABLE(&database, Component, nullptr); 32 | FDB_FIND_TABLE(&database, Component); 33 | FDB_REMOVE_TABLE(&database, Component); 34 | fdb_database_release(&database); 35 | } 36 | 37 | int main(int argc, char *argv[]) 38 | { 39 | ::testing::InitGoogleTest(&argc, argv); 40 | int ret = RUN_ALL_TESTS(); 41 | return ret; 42 | } 43 | -------------------------------------------------------------------------------- /src/test/runtime/dyn_array_test.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "../../compiler/dyn_array.h" 3 | 4 | #include 5 | 6 | 7 | struct test_t 8 | { 9 | std::string m_str = ""; 10 | }; 11 | 12 | DynArray 13 | create_array() 14 | { 15 | DynArray array; 16 | for(uint32_t i = 0; i < 100; ++i) 17 | { 18 | test_t t; 19 | t.m_str = "TEST"; 20 | array.append(t); 21 | } 22 | return array; 23 | } 24 | 25 | TEST(DynArray, DynArrayTest ) 26 | { 27 | DynArray array = create_array(); 28 | } 29 | 30 | int main(int argc, char *argv[]) 31 | { 32 | ::testing::InitGoogleTest(&argc, argv); 33 | int ret = RUN_ALL_TESTS(); 34 | return ret; 35 | } 36 | 37 | -------------------------------------------------------------------------------- /src/test/runtime/hashtable_test.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "../../common/hashtable.h" 3 | 4 | #include 5 | #include 6 | 7 | 8 | TEST(HashtableTest, HashtableTest ) 9 | { 10 | fdb_hashtable_t hashtable; 11 | fdb_hashtable_init(&hashtable, 12 | 512, 13 | nullptr); 14 | constexpr uint32_t num_elements = 100000; 15 | for(uint32_t i = 0; 16 | i < num_elements; 17 | ++i) 18 | { 19 | fdb_hashtable_add(&hashtable, 20 | i, 21 | (void*)(uint64_t)i); 22 | } 23 | 24 | for(uint32_t i = 0; 25 | i < num_elements; 26 | ++i) 27 | { 28 | void* ptr = fdb_hashtable_get(&hashtable, 29 | i); 30 | ASSERT_EQ(ptr, (void*)(uint64_t)i); 31 | } 32 | 33 | 34 | fdb_hashtable_release(&hashtable); 35 | } 36 | 37 | TEST(HashtableTest, HashtableIteratorTest ) 38 | { 39 | fdb_hashtable_t hashtable; 40 | fdb_hashtable_init(&hashtable, 512, nullptr); 41 | constexpr uint32_t num_elements = 100000; 42 | for(uint32_t i = 0; 43 | i < num_elements; 44 | ++i) 45 | { 46 | fdb_hashtable_add(&hashtable, 47 | i, 48 | (void*)(uint64_t)i); 49 | } 50 | 51 | bool found[num_elements]; 52 | memset(found, 0, sizeof(bool)*num_elements); 53 | 54 | fdb_hashtable_iter_t iter = fdb_hashtable_iter_init(&hashtable); 55 | while(fdb_hashtable_iter_has_next(&iter)) 56 | { 57 | fdb_hashtable_entry_t entry = fdb_hashtable_iter_next(&iter); 58 | found[entry.m_key] = true; 59 | } 60 | fdb_hashtable_iter_release(&iter); 61 | 62 | bool all_true = true; 63 | for(uint32_t i = 0; 64 | i < num_elements; 65 | ++i) 66 | { 67 | all_true &= found[i]; 68 | } 69 | 70 | ASSERT_TRUE(all_true); 71 | 72 | fdb_hashtable_release(&hashtable); 73 | } 74 | 75 | int main(int argc, char *argv[]) 76 | { 77 | ::testing::InitGoogleTest(&argc, argv); 78 | int ret = RUN_ALL_TESTS(); 79 | return ret; 80 | } 81 | 82 | -------------------------------------------------------------------------------- /src/test/runtime/memory_test.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "furious.h" 3 | 4 | #include 5 | #include 6 | 7 | TEST(MemoryTest, NUMA ) { 8 | void* ptr = mem_alloc(fdb_get_global_mem_allocator(), 9 | 64, 10 | sizeof(int32_t)*1024, 11 | 0); 12 | ASSERT_NE(ptr, nullptr); 13 | mem_free(fdb_get_global_mem_allocator(), 14 | ptr); 15 | } 16 | 17 | int main(int argc, char *argv[]) 18 | { 19 | ::testing::InitGoogleTest(&argc, argv); 20 | int ret = RUN_ALL_TESTS(); 21 | return ret; 22 | } 23 | 24 | -------------------------------------------------------------------------------- /src/test/runtime/page_alloc_test.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "furious.h" 3 | #include "common/platform.h" 4 | #include "common/memory/page_allocator.h" 5 | 6 | #include 7 | 8 | TEST(fdb_pool_alloc_test, test) 9 | { 10 | fdb_page_alloc_t palloc; 11 | fdb_page_alloc_init(&palloc, GIGABYTES(1), KILOBYTES(4), KILOBYTES(512)); 12 | 13 | uint32_t numAllocs = 1000; 14 | void* sallocs[numAllocs]; 15 | void* lallocs[numAllocs]; 16 | for(uint32_t i = 0; i < numAllocs; ++i) 17 | { 18 | sallocs[i] = fdb_page_alloc_alloc(&palloc, 19 | 64, 20 | KILOBYTES(4), 21 | FDB_NO_HINT); 22 | 23 | ASSERT_EQ((uint64_t)sallocs[i] % KILOBYTES(4), 0); 24 | 25 | lallocs[i] = fdb_page_alloc_alloc(&palloc, 26 | 64, 27 | KILOBYTES(512), 28 | FDB_NO_HINT); 29 | 30 | ASSERT_EQ((uint64_t)lallocs[i] % KILOBYTES(512), 0); 31 | } 32 | 33 | for(uint32_t i = 0; i < numAllocs/2; ++i) 34 | { 35 | fdb_page_alloc_free(&palloc,sallocs[i]); 36 | fdb_page_alloc_free(&palloc,lallocs[i]); 37 | } 38 | 39 | for(uint32_t i = 0; i < numAllocs/2; ++i) 40 | { 41 | sallocs[i] = fdb_page_alloc_alloc(&palloc, 42 | 64, 43 | KILOBYTES(4), 44 | FDB_NO_HINT); 45 | 46 | ASSERT_EQ((uint64_t)sallocs[i] % KILOBYTES(4), 0); 47 | 48 | lallocs[i] = fdb_page_alloc_alloc(&palloc, 49 | 64, 50 | KILOBYTES(512), 51 | FDB_NO_HINT); 52 | 53 | ASSERT_EQ((uint64_t)lallocs[i] % KILOBYTES(512), 0); 54 | } 55 | 56 | for(uint32_t i = 0; i < numAllocs; ++i) 57 | { 58 | fdb_page_alloc_free(&palloc,sallocs[i]); 59 | fdb_page_alloc_free(&palloc,lallocs[i]); 60 | } 61 | 62 | fdb_page_alloc_release(&palloc); 63 | } 64 | 65 | int main(int argc, char *argv[]) 66 | { 67 | ::testing::InitGoogleTest(&argc, argv); 68 | int ret = RUN_ALL_TESTS(); 69 | return ret; 70 | } 71 | 72 | -------------------------------------------------------------------------------- /src/test/runtime/pool_alloc_test.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "furious.h" 3 | #include "../../compiler/dyn_array.h" 4 | 5 | #include 6 | 7 | TEST(fdb_pool_alloc_test, only_allocs) 8 | { 9 | 10 | constexpr uint32_t num_alignments = 10; 11 | uint32_t alignments[num_alignments] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512}; 12 | constexpr uint32_t num_chunks = 5; 13 | uint32_t chunk_sizes[num_chunks] = {KILOBYTES(4), 14 | KILOBYTES(8), 15 | KILOBYTES(16), 16 | KILOBYTES(32), 17 | KILOBYTES(64)}; 18 | constexpr uint32_t num_blocks = 4; 19 | uint32_t block_sizes[num_blocks] = {BYTES(32), 20 | BYTES(64), 21 | BYTES(128), 22 | BYTES(256)}; 23 | 24 | 25 | for (uint32_t i = 0; i < num_alignments; ++i) 26 | { 27 | for (uint32_t j = 0; j < num_chunks; ++j) 28 | { 29 | for (uint32_t k = 0; k < num_blocks; ++k) 30 | { 31 | fdb_pool_alloc_t alloc; 32 | fdb_pool_alloc_init(&alloc, 33 | alignments[i], 34 | block_sizes[k], 35 | chunk_sizes[j], 36 | nullptr); 37 | // NOTE(Arnau) This number cannot exceed 256 38 | constexpr uint32_t num_allocations = 256; 39 | DynArray allocations; 40 | for(uint32_t q = 0; q < num_allocations; ++q) 41 | { 42 | void* ptr = fdb_pool_alloc_alloc(&alloc, 43 | alignments[i], 44 | block_sizes[k], 45 | FDB_NO_HINT); 46 | memset(ptr, q, block_sizes[k]); 47 | ASSERT_EQ((uint64_t)ptr % alignments[i], 0); 48 | allocations.append((char*)ptr); 49 | } 50 | 51 | for(uint32_t q = 1; q < num_allocations; ++q) 52 | { 53 | char* ptr1 = allocations[q-1]; 54 | char* ptr2 = allocations[q]; 55 | ASSERT_TRUE(((uint64_t)ptr2 - (uint64_t)ptr1) >= block_sizes[k]); 56 | } 57 | 58 | for(uint32_t q = 0; q < num_allocations; ++q) 59 | { 60 | char* ptr =allocations[q]; 61 | //printf("BLOCK: %u size:%u ptr:%lu\n", q, block_sizes[k], (uint64_t)ptr); 62 | for(uint32_t t = 0; t < block_sizes[k]; ++t) 63 | { 64 | //printf("%u %u %u\n", t, (uint8_t)ptr[t], (uint8_t)q); 65 | ASSERT_EQ((uint8_t)ptr[t], (uint8_t)q); 66 | } 67 | } 68 | 69 | fdb_pool_alloc_release(&alloc); 70 | } 71 | } 72 | } 73 | 74 | } 75 | 76 | TEST(fdb_pool_alloc_test, allocs_and_frees_test) 77 | { 78 | 79 | constexpr uint32_t num_alignments = 10; 80 | uint32_t alignments[num_alignments] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512}; 81 | constexpr uint32_t num_chunks = 5; 82 | uint32_t chunk_sizes[num_chunks] = {KILOBYTES(4), 83 | KILOBYTES(8), 84 | KILOBYTES(16), 85 | KILOBYTES(32), 86 | KILOBYTES(64)}; 87 | constexpr uint32_t num_blocks = 4; 88 | uint32_t block_sizes[num_blocks] = {BYTES(32), 89 | BYTES(64), 90 | BYTES(128), 91 | BYTES(256)}; 92 | 93 | 94 | for (uint32_t i = 0; i < num_alignments; ++i) 95 | { 96 | for (uint32_t j = 0; j < num_chunks; ++j) 97 | { 98 | for (uint32_t k = 0; k < num_blocks; ++k) 99 | { 100 | fdb_pool_alloc_t alloc; 101 | fdb_pool_alloc_init(&alloc, 102 | alignments[i], 103 | block_sizes[k], 104 | chunk_sizes[j], 105 | nullptr); 106 | constexpr uint32_t num_allocations = 1024; 107 | for(uint32_t q = 0; q < num_allocations; ++q) 108 | { 109 | void* ptr = fdb_pool_alloc_alloc(&alloc, 110 | alignments[i], 111 | block_sizes[k], 112 | FDB_NO_HINT); 113 | memset(ptr, 0, block_sizes[k]); 114 | ASSERT_EQ((uint64_t)ptr % alignments[i], 0); 115 | if(q % 3 == 0) 116 | { 117 | fdb_pool_alloc_free(&alloc, ptr); 118 | } 119 | } 120 | 121 | fdb_pool_alloc_release(&alloc); 122 | } 123 | } 124 | } 125 | 126 | } 127 | 128 | int main(int argc, char *argv[]) 129 | { 130 | ::testing::InitGoogleTest(&argc, argv); 131 | int ret = RUN_ALL_TESTS(); 132 | return ret; 133 | } 134 | 135 | -------------------------------------------------------------------------------- /src/test/runtime/refs_test.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "furious.h" 3 | #include 4 | 5 | FDB_BEGIN_COMPONENT(ComponentA, KILOBYTES(4)) 6 | uint32_t m_field; 7 | FDB_END_COMPONENT 8 | 9 | FDB_BEGIN_COMPONENT(ComponentB, KILOBYTES(4)) 10 | uint32_t m_field; 11 | FDB_END_COMPONENT 12 | 13 | TEST(RefsTest,TagWorks) 14 | { 15 | fdb_database_t database; 16 | fdb_database_init(&database, 17 | nullptr); 18 | 19 | entity_id_t entX=0; 20 | entity_id_t entY=1; 21 | entity_id_t entZ=2; 22 | 23 | fdb_reftable_t* rt = fdb_database_find_or_create_reftable(&database, "test_ref"); 24 | fdb_reftable_add(rt, entX, entY); 25 | fdb_reftable_add(rt, entY, entZ); 26 | 27 | 28 | ASSERT_TRUE(fdb_reftable_exists(rt, entX, entY)); 29 | ASSERT_TRUE(fdb_reftable_exists(rt, entY, entZ)); 30 | ASSERT_FALSE(fdb_reftable_exists(rt, entX, entZ)); 31 | 32 | fdb_reftable_add(rt, entX, entZ); 33 | 34 | ASSERT_TRUE(fdb_reftable_exists(rt, entX, entZ)); 35 | ASSERT_FALSE(fdb_reftable_exists(rt, entX, entY)); 36 | 37 | fdb_database_release(&database); 38 | } 39 | 40 | int main(int argc, char *argv[]) 41 | { 42 | ::testing::InitGoogleTest(&argc, argv); 43 | int ret = RUN_ALL_TESTS(); 44 | return ret; 45 | } 46 | 47 | -------------------------------------------------------------------------------- /src/test/runtime/stack_alloc_test.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "furious.h" 3 | 4 | #include 5 | 6 | 7 | TEST(fdb_stack_alloc_test, fdb_stack_alloc_test) 8 | { 9 | fdb_stack_alloc_t alloc; 10 | fdb_stack_alloc_init(&alloc, KILOBYTES(4), nullptr); 11 | 12 | constexpr uint32_t num_alignments = 10; 13 | uint32_t alignments[num_alignments] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512}; 14 | constexpr uint32_t num_allocations = 250; 15 | uint32_t allocation_sizes[num_allocations]; 16 | void* allocation_addrs[num_allocations]; 17 | uint32_t allocation_alignments[num_allocations]; 18 | srand(time(NULL)); 19 | for (uint32_t i = 0; i < num_allocations; ++i) 20 | { 21 | allocation_alignments[i] = (uint32_t)alignments[(uint32_t)rand() % num_alignments]; 22 | allocation_sizes[i] = (uint32_t)(rand() % (KILOBYTES(4) - sizeof(void*) - (allocation_alignments[i] < FDB_MIN_ALIGNMENT ? FDB_MIN_ALIGNMENT : allocation_alignments[i]))) + 1; 23 | allocation_addrs[i] = nullptr; 24 | } 25 | 26 | for(uint32_t i = 0; i < num_allocations; ++i) 27 | { 28 | allocation_addrs[i] = fdb_stack_alloc_alloc(&alloc, 29 | allocation_alignments[i], 30 | allocation_sizes[i], 31 | -1); 32 | memset(allocation_addrs[i], i % 256, allocation_sizes[i]); 33 | } 34 | 35 | for(uint32_t i = 0; i < num_allocations; ++i) 36 | { 37 | char signature = i % 256; 38 | char* data = (char*)allocation_addrs[i]; 39 | for(uint32_t j = 0; j < allocation_sizes[i]; ++j) 40 | { 41 | ASSERT_EQ(data[j], signature); 42 | } 43 | uint32_t modulo = ((uint64_t)allocation_addrs[i]) % allocation_alignments[i]; 44 | ASSERT_EQ(modulo, 0); 45 | fdb_stack_alloc_free(&alloc, allocation_addrs[i]); 46 | } 47 | 48 | fdb_stack_alloc_release(&alloc); 49 | } 50 | 51 | TEST(fdb_stack_alloc_test, fdb_stack_alloc_test_pop) 52 | { 53 | fdb_stack_alloc_t alloc; 54 | fdb_stack_alloc_init(&alloc, KILOBYTES(4), nullptr); 55 | 56 | uint32_t alignment = 32; 57 | uint32_t alloc_size = 48; 58 | uint32_t num_allocs = 1024; 59 | void** allocations = new void*[num_allocs]; 60 | for(uint32_t i = 0; i < num_allocs; ++i) 61 | { 62 | allocations[i] = fdb_stack_alloc_alloc(&alloc, 63 | alignment, 64 | alloc_size, 65 | FDB_NO_HINT); 66 | } 67 | 68 | for(uint32_t i = 0; i < num_allocs; ++i) 69 | { 70 | fdb_stack_alloc_pop(&alloc, 71 | allocations[num_allocs-1-i]); 72 | } 73 | delete [] allocations; 74 | fdb_stack_alloc_release(&alloc); 75 | } 76 | 77 | 78 | int main(int argc, char *argv[]) 79 | { 80 | ::testing::InitGoogleTest(&argc, argv); 81 | int ret = RUN_ALL_TESTS(); 82 | return ret; 83 | } 84 | 85 | -------------------------------------------------------------------------------- /src/test/runtime/table_test.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "furious.h" 3 | 4 | #include 5 | #include 6 | 7 | FDB_BEGIN_COMPONENT(Component, KILOBYTES(4)) 8 | 9 | int32_t field1_; 10 | float field2_; 11 | 12 | Component(int32_t field1, double field2) : field1_(field1), field2_(field2) {} 13 | 14 | FDB_END_COMPONENT 15 | 16 | TEST(TableTest,TableWorks) 17 | { 18 | 19 | fdb_database_t database; 20 | fdb_database_init(&database, 21 | nullptr); 22 | fdb_table_t* t = FDB_CREATE_TABLE(&database, Component, nullptr); 23 | entity_id_t num_entities = FDB_TABLE_BLOCK_SIZE*2048; 24 | 25 | for(entity_id_t i = 0; i < num_entities; ++i) 26 | { 27 | Component* c = FDB_ADD_COMPONENT(t, Component, i); 28 | c->field1_ = i; 29 | c->field2_ = i; 30 | } 31 | 32 | ASSERT_EQ(fdb_table_size(t), num_entities); 33 | 34 | fdb_table_iter_t iter; 35 | fdb_table_iter_init(&iter, t, 1, 0, 1); 36 | int32_t counter = 0; 37 | while (fdb_table_iter_has_next(&iter)) 38 | { 39 | fdb_table_block_t* block = fdb_table_iter_next(&iter); 40 | Component* data = (Component*)block->p_data; 41 | const fdb_bitmap_t* mask = &block->m_enabled; 42 | for (size_t i = 0; i < FDB_TABLE_BLOCK_SIZE; ++i) 43 | { 44 | ASSERT_TRUE(fdb_bitmap_is_set(mask, i)); 45 | ASSERT_EQ(data[i].field1_, counter); 46 | ASSERT_EQ(data[i].field2_, static_cast(counter)); 47 | counter++; 48 | } 49 | } 50 | fdb_table_iter_release(&iter); 51 | ASSERT_EQ(counter, num_entities); 52 | ASSERT_EQ(fdb_table_size(t), num_entities); 53 | 54 | fdb_table_disable_component(t, num_entities-1); 55 | ASSERT_FALSE(fdb_table_is_enabled(t, num_entities-1)); 56 | fdb_table_enable_component(t, num_entities-1); 57 | ASSERT_TRUE(fdb_table_is_enabled(t, num_entities-1)); 58 | 59 | for(entity_id_t i = 0; i < num_entities; i+=2) { 60 | FDB_REMOVE_COMPONENT(t, i); 61 | } 62 | ASSERT_EQ(fdb_table_size(t), num_entities/2); 63 | 64 | fdb_table_iter_t iter2; 65 | fdb_table_iter_init(&iter2, t, 1, 0, 1); 66 | int32_t num_real = 0; 67 | counter = 0; 68 | while (fdb_table_iter_has_next(&iter2)) 69 | { 70 | fdb_table_block_t* block = fdb_table_iter_next(&iter2); 71 | const fdb_bitmap_t* mask = &block->m_enabled; 72 | Component* data = (Component*)block->p_data; 73 | for (size_t i = 0; i < FDB_TABLE_BLOCK_SIZE; ++i) 74 | { 75 | if(i % 2 == 0) 76 | { 77 | ASSERT_FALSE(fdb_bitmap_is_set(mask, i)); 78 | } 79 | else 80 | { 81 | ASSERT_TRUE(fdb_bitmap_is_set(mask, i)); 82 | ASSERT_EQ(data[i].field1_, counter); 83 | ASSERT_EQ(data[i].field2_, static_cast(counter)); 84 | num_real++; 85 | } 86 | counter++; 87 | } 88 | } 89 | fdb_table_iter_release(&iter2); 90 | ASSERT_EQ(num_real, num_entities/2); 91 | 92 | fdb_table_clear(t); 93 | ASSERT_EQ(fdb_table_size(t),0); 94 | 95 | FDB_REMOVE_TABLE(&database, Component); 96 | fdb_database_release(&database); 97 | } 98 | 99 | 100 | TEST(IteratorTest,TableWorks) 101 | { 102 | 103 | fdb_database_t database; 104 | fdb_database_init(&database, nullptr); 105 | fdb_table_t* t = FDB_CREATE_TABLE(&database, Component, nullptr); 106 | int32_t num_entities = FDB_TABLE_BLOCK_SIZE*2048; 107 | 108 | for(int32_t i = 0; i < num_entities; ++i) 109 | { 110 | Component* c = FDB_ADD_COMPONENT(t, Component, i); 111 | c->field1_ = i; 112 | c->field2_ = i; 113 | } 114 | 115 | fdb_table_iter_t it; 116 | fdb_table_iter_init(&it, 117 | t, 1, 0, 2); 118 | while(fdb_table_iter_has_next(&it)) 119 | { 120 | fdb_table_block_t* block = fdb_table_iter_next(&it); 121 | uint32_t block_start = block->m_start / FDB_TABLE_BLOCK_SIZE; 122 | ASSERT_TRUE(block_start % 2 == 0); 123 | } 124 | fdb_table_iter_release(&it); 125 | 126 | fdb_table_iter_t it2; 127 | fdb_table_iter_init(&it2, t, 1, 1, 2); 128 | while(fdb_table_iter_has_next(&it2)) 129 | { 130 | fdb_table_block_t* block = fdb_table_iter_next(&it2); 131 | uint32_t block_start = block->m_start / FDB_TABLE_BLOCK_SIZE; 132 | ASSERT_TRUE(block_start % 2 == 1); 133 | } 134 | 135 | fdb_database_release(&database); 136 | } 137 | 138 | int main(int argc, char *argv[]) 139 | { 140 | ::testing::InitGoogleTest(&argc, argv); 141 | int ret = RUN_ALL_TESTS(); 142 | return ret; 143 | } 144 | 145 | -------------------------------------------------------------------------------- /src/test/runtime/tags_test.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "furious.h" 3 | #include 4 | 5 | TEST(TagTests,TagWorks) 6 | { 7 | fdb_database_t database; 8 | fdb_database_init(&database, 9 | nullptr); 10 | 11 | entity_id_t entX = 0; 12 | entity_id_t entY = 1; 13 | entity_id_t entZ = 2; 14 | 15 | fdb_bittable_t* selected = fdb_database_get_tagged_entities(&database, "selected"); 16 | fdb_bittable_add(selected, entX); 17 | fdb_bittable_add(selected, entZ); 18 | 19 | ASSERT_TRUE(fdb_bittable_exists(selected, entX)); 20 | ASSERT_FALSE(fdb_bittable_exists(selected, entY)); 21 | ASSERT_TRUE(fdb_bittable_exists(selected, entZ)); 22 | 23 | fdb_database_release(&database); 24 | } 25 | 26 | int main(int argc, char *argv[]) 27 | { 28 | ::testing::InitGoogleTest(&argc, argv); 29 | int ret = RUN_ALL_TESTS(); 30 | return ret; 31 | } 32 | 33 | --------------------------------------------------------------------------------