diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index ef9b6d1..5621326 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,34 +1,42 @@ ## Summary + ## Introduced Changes + ## Is this PR related to an issue or problem + ## What was the root cause for the problem + ## Does your new code introduce new warnings or errors? (At current state) + ## Changelog + ### Added + ### Changed + ### Removed \ No newline at end of file diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index 3923183..6d600f6 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -1,29 +1,33 @@ name: Codecov -on: [push] +on: [ push ] + jobs: run: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-latest] + os: [ ubuntu-latest ] env: OS: ${{ matrix.os }} steps: - - uses: actions/checkout@master - - name: Build GTest Tests - run: | - cmake . - cmake --build . --target runParacModulesTests -- -j 9 - - name: Run C-Coverage - run: | - ./tests/tests/runParacModulesTests - gcov -abcfu ./include/CMakeFiles/parac-modules.dir/*.gc* - tree . - - name: Upload C coverage to Codecov - uses: codecov/codecov-action@v2 - with: - token: ${{ secrets.CODECOV_TOKEN }} - directory: . - env_vars: OS - files: pbl-int.c.gcov,pbl-string.c.gcov,pbl-types.c.gcov,pbl-io.c.gcov,pbl-mem.c.gcov,pbl-main.c.gcov,pbl-function.c.gcov,pbl.c.gcov - verbose: true + - uses: actions/checkout@master + - name: Build GTest Tests + run: | + cmake . + cmake --build . --target runPblTests + - name: Run C-Coverage + run: | + ./tests/runPblTests + - name: Generate coverage files + run: | + gcov -abcfu ./CMakeFiles/pbl.dir/**/*.gcda ./CMakeFiles/pbl.dir/**/*.gcno + - name: Run Tree to show directory structure + run: | + tree . + - name: Download Codecov Uploader + run: | + curl -Os https://uploader.codecov.io/latest/linux/codecov + chmod +x codecov + - name: Upload C coverage to Codecov + run: | + ./codecov -v -F unittests -t ${{ secrets.CODECOV_TOKEN }} -s ./src/ -f ./src/**/*.gcov -n Github-Actions-Upload \ No newline at end of file diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 379328a..7fa1dc5 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -1,5 +1,4 @@ name: "CodeQL" - on: push: branches: [ main ] @@ -24,19 +23,18 @@ jobs: language: [ 'cpp' ] steps: - - name: Checkout repository - uses: actions/checkout@v2 - - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v1 - with: - languages: ${{ matrix.language }} + - name: Checkout repository + uses: actions/checkout@v2 - - name: Build - run: | - cmake . - cmake --build . --target runParacModulesTests -- -j 9 + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v1 + with: + languages: ${{ matrix.language }} - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v1 + - name: Build + run: | + cmake . + cmake --build . --target runPblTests + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v1 diff --git a/.github/workflows/drmemory.yml b/.github/workflows/drmemory.yml index 2b63de3..c6ae262 100644 --- a/.github/workflows/drmemory.yml +++ b/.github/workflows/drmemory.yml @@ -31,10 +31,10 @@ jobs: - name: Build Tests run: | cmake . - cmake --build . --target runParacModulesTests -- -j 9 + cmake --build . --target runPblTests - name: Run Tests run: | - ./tests/tests/runParacModulesTests + ./tests/runPblTests - name: Run DrMemory for Tests run: | - ./DrMemory-Linux-2.4.0-2/bin/drmemory -- ./tests/tests/runParacModulesTests + ./DrMemory-Linux-2.4.0-2/bin/drmemory -- ./tests/runPblTests diff --git a/.github/workflows/gcc-compatibility-checks.yml b/.github/workflows/gcc-compatibility-checks.yml new file mode 100644 index 0000000..f68edc4 --- /dev/null +++ b/.github/workflows/gcc-compatibility-checks.yml @@ -0,0 +1,35 @@ +name: GCC Compatibility Checks +on: + push: + branches-ignore: + - '**-coverage-report' + pull_request: + +jobs: + run: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + # At the moment only >=8.0 are supported -> https://github.com/Para-C/Para-C/discussions/76 + gcc-version: [ 8, 9, 10, 11, latest ] + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + - name: Set up GCC + uses: egor-tensin/setup-gcc@v1 + with: + version: ${{ matrix.gcc-version }} + platform: x64 + - name: Set up cmake + uses: jwlawson/actions-setup-cmake@v1.9 + with: + cmake-version: '3.17.x' + - name: Build Tests + run: | + cmake . + cmake --build . --target runPblTests + - name: Run Tests + run: | + ./tests/runPblTests diff --git a/.github/workflows/mingw-compatibility-checks.yml b/.github/workflows/mingw-compatibility-checks.yml new file mode 100644 index 0000000..7cc0e35 --- /dev/null +++ b/.github/workflows/mingw-compatibility-checks.yml @@ -0,0 +1,34 @@ +name: MinGW Compatibility Checks +on: + push: + branches-ignore: + - '**-coverage-report' + pull_request: + +jobs: + run: + runs-on: windows-latest + strategy: + fail-fast: false + matrix: + # At the moment only >=7.0 are supported by setup-gcc + mingw-version: [ latest ] + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + - name: Set up MinGW-w64 + uses: egor-tensin/setup-mingw@v1 + with: + platform: x64 + - name: Set up cmake + uses: jwlawson/actions-setup-cmake@v1.9 + with: + cmake-version: '3.17.x' + - name: Build Tests + run: | + cmake . -G "MinGW Makefiles" -D CMAKE_C_COMPILER=gcc -D CMAKE_CXX_COMPILER=g++ + cmake --build . --target runPblTests + - name: Run Tests + run: | + .\tests\runPblTests.exe diff --git a/CHANGELOG.md b/CHANGELOG.md index 55b39f4..7d3d4ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,57 +1,116 @@ # Changelog -All notable changes to the Compiler will be documented in this file. -Note that these changes in this file are specifically for the Compiler. -The full summary will be in the CHANGELOG.md file the main folder +All notable changes to the Compiler will be documented in this file. Note that these changes in this file are +specifically for the Compiler. The full summary will be in the CHANGELOG.md file the main folder -The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), -and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres +to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). *Note that Documentation changes should not appear here!* ## [Unreleased] ### Added -- `pbl-apply-macro.h` for defining a macro function, which allows for iterating through macro args and apply - another macro to them + +- `pbl-apply-macro.h` for defining a macro function, which allows for iterating through macro args and apply another + macro to them. - Macros `PBL_GET_FUNC_ARGS_IDENTIFIER`, `PBL_GET_FUNC_BASE_IDENTIFIER` and `PBL_GET_FUNC_OVERHEAD_IDENTIFIER` for - getting standardised macros -- `PBL_COUNT_VA_ARGS` for counting the amount of arguments passed to this specific macro -- `PBL_FUNC_ARG` for creating the effect of arguments being `NULL` per default -- `PBL_CREATE_FUNC_OVERHEAD` for creating overhead of a Para-C function, which can support default arguments and - struct-like initialisation -- `PBL_CALL_FUNC` for calling a Para-C function and properly handling it + getting standardised macros. +- `PBL_COUNT_VA_ARGS` for counting the amount of arguments passed to this specific macro. +- `PBL_FUNC_ARG` for creating the effect of arguments being `NULL` per default. +- `PBL_CREATE_FUNC_OVERHEAD` for creating overhead of a Para-C function, which can support default arguments and + struct-like initialisation. +- `PBL_CALL_FUNC` for calling a Para-C function and properly handling it. +- Header `pbl-advanced-mem.h` for exception-supported and advanced memory handling with Para-C types. +- Function `PblMallocUncollectable()` in `pbl-mem.h` for allocating a variable that will not be automatically collected + aka. will exist until the user deallocates it or the program ends. This will be used for global variables that are + used throughout the entire program, and are essential to running properly, which means they should not be checked for + Garbage Collection. +- New Macro for simplified cleanup attribute assignment: `PBL_CLEANUP(func)` +- Better Docstrings to: + - `PBL_CREATE_ADDRESS_COPY` + - `PBL_WRITE_BACK_ADDRESS_COPY` +- New macro `PBL_SIZEOF_ON_RUNTIME(var)` for dynamically fetching the size using `PblType_T.size`. +- New macro `PBL_VAL_REQ_ARG` for validating a required argument aka. it may not be null. This is to make the code more + verbose when handling Para-C functions. +- New IO functions `PblInput()`and `PblInputChar()` +- New type `PblPointer_T` with conversion function `PblGetPointerT(void* val, PblType_T* type)` +- Inclusion check for C++ to use the `c` prefix in inclusion for C++ to avoid warnings (e.g `#include ` + in C++ and `#include ` in C) +- New type `PblTypeList_T` for local file type and meta-data tracking, with the additional handling functions and + macros: + - `PblAddTypeToTypeList()` - Adds a new type to the local type list + - `PblCreateNewType()` - Allocates a new type in memory that may be used for type lists + - `PblInitTypeList()` - Initialises a local type list and creates the on-runtime constructor for allocating its + content + - `LOCAL_TYPE_LIST_CONSTRUCTOR` - Is replaced with a default constructor function signature for registering new types + at runtime + - `PBL_REGISTER_LOCAL_TYPE` - Registers a local type and adds it to the local type list. Has to be used inside of + `LOCAL_TYPE_LIST_CONSTRUCTOR` constructor function definitions + - `PBL_INIT_LOCAL_TYPE_LIST` - Creates and initialises the variables `LOCAL_TYPE_LIST` and + `LOCAL_TYPE_TRACKING_INITIALISED`, which are required for utilising type tracking inside a file ### Changed -- Disabled `pthreads.h` usage on Windows for gtest and enabled usage of WIN32 threads -- Updated macro `PBL_CALL_FUNC`, which handles now also the amount of args properly + +- Entirely restructured the buildup, and now created separate folders for headers (`include`) and + source code (`src`), where also CMake has been restructured and simplified. +- Updated macro `PBL_CALL_FUNC`, which handles now also the amount of args properly. +- Renamed the following types: + - `PblTypeMeta_T` to `PblType_T` + - `PblMetaVarCtx_T` to `PblVarMetaData_T` +- Renamed the following macros: + - `PBL_GET_ACTUAL_TYPE_INSTANCE` to `PBL_ASSIGN_TO_VAR` + - `PBL_ALLOC_DECLARATION` to `PBL_DECLARE_VAR` + - `PBL_DEFINE_VAR` to `PBL_DEFINE_VAR` + - `PBL_ALLOC_ARRAY_DEFINITION` to `PBL_CREATE_NEW_ARRAY` + - `PBL_DECLARATION_CONSTRUCTOR` to `PBL_TYPE_DECLARATION_DEFAULT_CONSTRUCTOR` + - `PBL_DEFINITION_STRUCT_CONSTRUCTOR` to `PBL_TYPE_DEFINITION_DEFAULT_STRUCT_CONSTRUCTOR` + - `PBL_DEFINITION_SINGLE_CONSTRUCTOR` to `PBL_TYPE_DEFINITION_DEFAULT_SIMPLE_CONSTRUCTOR` + - `PBL_PASTE_ADDRESS_COPY` to `PBL_WRITE_BACK_ADDRESS_COPY` +- Replaced `size_t *size` property in `PblVarMetaData_T` and replaced it with `PblType_T *type` +- Renamed `PBL_SIZEOF` to `PBL_SIZEOF_USABLE` +- Renamed `PBL_C_BASE_EXCEPTION_CATCH_CONSTRUCTOR` to `PBL_BASE_CALL_AND_CATCH_EXCEPTION` (for native C functions) and + avoided code repetition by utilising the function in `PBL_CALL_FUNC_AND_CATCH` (for Para-C functions) as well. +- Changed handling of `PBL_SIZEOF_ON_RUNTIME` to utilise usable memory and renamed the macro to + `PBL_SIZEOF_USABLE_ON_RUNTIME` ### Removed -- Outdated macro `PBL_CALL_FUNC_WITH_META_CTX`, which is now replaced by `PBL_CALL_FUNC` as the general method to - call Para-C functions + +- Outdated macro `PBL_CALL_FUNC_WITH_META_CTX`, which is now replaced by `PBL_CALL_FUNC` as the general method to call + Para-C functions +- Unneeded `PBL_DEFINITION_IF_VA_ARGS_CONSTRUCTOR` macro +- Parameter `type` in `PBL_WRITE_BACK_ADDRESS_COPY`, which was unnecessary, due to both variables already having been + defined. +- Unneeded `PblCleanupLocal()`, which was briefly defined in `pbl-mem.c` +- Unneeded default cleanups, which were replaced by optional opt-in cleanups on declaration / definition. ## [v0.1.dev6] - 2021-11-10 ### Changed -- Made the PBL properly fetch-able for the build script `build.py` in [Para-C](https://github.com/Para-C/Para-C) +- Made the PBL properly fetch-able for the build script `build.py` in [Para-C](https://github.com/Para-C/Para-C) ## [v0.1.dev5] - 2021-11-09 ### Added -- Base types in `pbl-types.h` that wrap the low-level C types, including conversion functions which allow simply one-line - conversion + +- Base types in `pbl-types.h` that wrap the low-level C types, including conversion functions which allow simply + one-line conversion - Proper meta-tracking for all Para-C types using `PblVarMeta_T` - Default declaration and definition macros for all types in `libpbl`. These are defined using `_DeclDefault` and `_DefDefault` for all types -- `PblStream_T` and `PblFile_T` implementation for stream handling +- `PblIOStream_T` and `PblIOFile_T` implementation for stream handling - Specified Int Types in `pbl-int.h` that wrap the int types in `stdint.h` -- Meta handling for managing a function call context and Exception handling in `pbl-function.h` -- Fallback implementation for `__VA_EXT__`, which has been implemented since C++20 or C23, using `./modules/parac-modules/included/va-opt.h` -- Added `pbl-mem.h` for independent memory management and Garbage Collector implementation using [Boehm-Demers-Weiser Garbage Collector](https://github.com/ivmai/bdwgc) +- Meta handling for managing a function call context and Exception handling in `pbl-function.h` +- Fallback implementation for `__VA_EXT__`, which has been implemented since C++20 or C23, + using `./modules/parac-modules/included/va-opt.h` +- Added `pbl-mem.h` for independent memory management and Garbage Collector implementation + using [Boehm-Demers-Weiser Garbage Collector](https://github.com/ivmai/bdwgc) - Handler macros `PBL_GET_ACTUAL_TYPE_INSTANCE` (getting type instance), `PBL_ALLOC_DECLARATION` (Para-C Declarations) - and `PBL_ALLOC_DEFINITION` (Para-C Definitions) which standardise the initialisation of Para-C values + and `PBL_DEFINE_VAR` (Para-C Definitions) which standardise the initialisation of Para-C values [unreleased]: https://github.com/Para-C/Para-C-Base-Library/tree/dev + [v0.1.dev6]: https://github.com/Para-C/Para-C-Base-Library/compare/v0.1.dev5...v0.1.dev6 + [v0.1.dev5]: https://github.com/Para-C/Para-C-Base-Library/tag/v0.1.dev5 \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index bafce87..379725c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,24 +1,56 @@ +# Only tested with 3.17 cmake_minimum_required(VERSION 3.17) -project(pbl) -add_definitions(-fprofile-arcs -ftest-coverage) +# General Project Setup +project( + libpbl + VERSION 0.1 + DESCRIPTION "The Para-C Base Library implementing macros, functions and types for the Para-C programming language" + LANGUAGES C CXX +) -set(CMAKE_C_STANDARD 11) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage -O0") +# Adding FetchContent for simplified content installation +include(FetchContent) -if (WIN32) - option(CMAKE_USE_WIN32_THREADS_INIT "Using WIN32 threads" ON) - option(gtest_disable_pthreads "Disable uses of pthreads in gtest" ON) -endif (WIN32) +# Enabling the usage of folders and make predefined projects go into their own solution folders +set_property(GLOBAL PROPERTY USE_FOLDERS ON) -include_directories(include) -include_directories(tests) +# If this is the main project, define additional terms required for testing and such +if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) + # PBL only supports C11 and upwards + set(CMAKE_C_STANDARD 11) -add_subdirectory(include) -add_subdirectory(tests) + # Setting test flags + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage -O0") -target_link_libraries(pbl) + # Adding coverage definitions + add_definitions(-fprofile-arcs -ftest-coverage) -if (CMAKE_BUILD_TYPE MATCHES Debug) - add_definitions(-DDEBUG) -endif() \ No newline at end of file + # Adding the examples runtime + add_subdirectory(examples) +endif() + +# Adding the src and linking the library +add_subdirectory(src) + +# If this is the main project, enable testing +if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) + # Including the tests and the testing target + add_subdirectory(tests) +endif() + +# If Debug-Mode is enabled add debug definitions +if (CMAKE_BUILD_TYPE MATCHES Debug OR DEFINED PBL_DEBUG) + # Add default definition for debugging + add_definitions(-DDEBUG) + + # Sets the PBL_DEBUG to true per default + set(PBL_DEBUG true) + + # Add macro for the Garbage Collector to allow debugging + add_compile_definitions(GC_DEBUG) +endif() + +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) diff --git a/README.md b/README.md index 10c6344..b13c79d 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,18 @@ -# `libpbl` - Para-C Base Library +# `libpbl` - Para-C Base Library +[![Latest Release](https://img.shields.io/github/v/release/Para-C/Para-C-Base-Library?include_prereleases)](https://github.com/Para-C/Para-C-Base-Library/releases) [![Codecov](https://github.com/Para-C/Para-C-Base-Library/actions/workflows/codecov.yml/badge.svg)](https://github.com/Para-C/Para-C-Base-Library/actions/workflows/codecov.yml) [![Dr.Memory and GTest](https://github.com/Para-C/Para-C-Base-Library/actions/workflows/drmemory.yml/badge.svg)](https://github.com/Para-C/Para-C-Base-Library/actions/workflows/drmemory.yml) [![Open Para-C issues](https://img.shields.io/github/issues/Para-C/Para-C)](https://github.com/Para-C/Para-C/issues) +[![Required GCC version](https://img.shields.io/badge/GCC-%3E%3D8.0-blue)](https://github.com/Para-C/Para-C/discussions/76) +![Required CMake version](https://img.shields.io/badge/CMake-%3E%3D3.17-blue) -This is the repository containing the c-implementation library (Para-C Core Library, and partly Para-C Built-In Library), -which is used for the built-in functions, keywords and items, which are required for the base language. +This is the repository containing the c-implementation library (Para-C Core Library, and partly Para-C Built-In Library) +, which is used for the built-in functions, keywords and items, which are required for the base language. -*For proper documentation and info on Para-C visit the main repo [here](https://github.com/Para-C/Para-C). -This also includes issues or requesting changes. These should be done on the main branch, while the issues -here will be maintainers-only* +*For proper documentation and info on Para-C visit the main repo [here](https://github.com/Para-C/Para-C). This also +includes issues or requesting changes. These should be done on the main branch, while the issues here will be +maintainers-only* # Testing @@ -18,55 +21,84 @@ is used in an C++ environment, which will simply include the C-files and run the In actual code usage, the Para-C Compiler will use the code as regular C, and only for testing C++ will/must be used. -# Basic Overview +# Overview ## Styling and Formatting The styling guide for the PBL is as following: - - Structs/Enums: PascalCase with leading 'Pbl' - - Struct Properties: snake_case - - Constants and Enum Properties: PascalCase with leading 'k' (copied from the Google C++ Styling Guide) - - Typedef: PascalCase with leading 'Pbl' and trailing '_T' - - Local Variables: snake_case - - Parameters: snake_case - - Macros: SCREAMING_SNAKE_CASE (exceptions are function definition macros, where PascalCase is applied) - - Functions: PascalCase - - Indention is set to 2 spaces -## `_DefDefault` and `_DeclDefault` for PBL-Types - -When declaring a built-in type that should be used inside Para-C, the style of the general types should -be replicated, to allow for the proper usage of defaults aka. `_DefDefault` and `_DeclDefault` +- Structs/Enums: PascalCase with leading `Pbl` +- Struct Properties: snake_case +- Constants and Enum Properties: SCREAMING_SNAKE_CASE +- Typedef: PascalCase with leading `Pbl` and trailing `_T` +- Local Variables: snake_case +- Parameters: snake_case +- Macros: SCREAMING_SNAKE_CASE (exceptions are function definition macros, where PascalCase is applied) +- Functions: PascalCase with leading `Pbl` +- Indention: 2 spaces +- Startup Constructors: Name with leading `PBL_CONSTRUCTOR` +- Cleanup De-Constructors: Name with leading `PBL_DECONSTRUCTOR` ## Meta-Data Tracking - `pbl-types.h` -Para-C implements meta-data tracking using `PblMetaVarCtx_T` and pre-defined macros, tracking things like: +Para-C implements meta-data tracking using `PblVarMetaData_T` and pre-defined macros, tracking things like: + - If the variable has been defined yet -- Effective space the user has to utilise. Note that effective space does not include actual space that is allocated! -This is due to meta-data also taking up a bit of memory space. +- Effective space the user has to utilise. Note that effective space does not include actual space that is allocated! + This is due to meta-data also taking up a bit of memory space. + +### `_DefDefault` and `_DeclDefault` for PBL-Types + +When declaring a built-in type that should be used inside Para-C, the style of the general types should be replicated, +to allow for the proper usage of defaults aka. `_DefDefault` and `_DeclDefault` + +## Variables - `pbl-types.h` + +Variables in Para-C are specifically handled using a garbage collector, meaning that initialised variables are +going to be represented and accessed using pointers. + +States of a Variable: +- Only Declared (True C Declaration) +- Technically "Declared" (Technically defined in C, but handled as declared in Para-C). Two possible + scenarios: + - Allocated, but the meta-Property `.meta.defined` is set to false, since no value was assigned yet + - The value is NULL, as it's a pointer and there has not been any clear definition. +- Defined Variable that has been written to +- Freed Variable by the Garbage Collector -## Declared and Defined handling - `pbl-types.h` +### Type List -In Para-C, there are two different states a variable can exist in; It is either declared or defined. +Para-C keeps a type list of all registered types that were created or imported inside a source file. This list is +created at startup of the program, meaning all types may be dynamically accessed and used to create new types. -### Declared Variable +This means that each file has its own scope with meta-data tracking, which can be also imported into other files. + +Constructor Priority: +- `PBL_CONSTRUCTOR_TYPES_LIST_INIT` - Initialises the local `LOCAL_TYPE_LIST` and `LOCAL_TYPE_TRACKING_INITIALISED` + +### Declared and Defined handling + +In Para-C, there are two different states a variable can exist in; It is either declared or defined. + +#### Declared Variable A declared variable is, unlike in C, can be appearing in two forms: + - Allocated and with a value set, though their meta-property `.meta.defined` is set to `false`, which means the program - knows it is invalid to be accessed. + knows it is invalid to be accessed. - The value is `NULL` aka. this is usually what is passed to a function as args to indicate the value is not set. This is in this case a *True `NULL`*, as it is not a pointer set to NULL or a value with their memory set to `NULL` This must be watched out for when writing PBL code, as both NULL and .meta.defined == false mean a variable is declared. -As a note, a double-pointer (user-created pointer) to a variable is always going to be NULL, aka. there is no -way to properly determine whether the variable is declared or defined, meaning the compiler will work out whether the +As a note, a double-pointer (user-created pointer) to a variable is always going to be NULL, aka. there is no way to +properly determine whether the variable is declared or defined, meaning the compiler will work out whether the user-created variable is declared. This means user-pointers are by default defined in the generated source code. -(This will be changed later, by implementing `PblPointer_T` as a new type and as such pointers will be like variables, +(This will be changed later, by implementing `PblPointer_T` as a new type and as such pointers will be like variables, meaning a `PblPointer_T` can be undefined with NULL and declared, but with `.meta.defined == false`) - -### Defined Variable + +#### Defined Variable The defined variables on the other hand will always be initialised with a default value, usually `0`, except for struct types, which will have all their property-pointers set to NULL, aka. they are also only 'declared' but not initialised. @@ -74,42 +106,46 @@ types, which will have all their property-pointers set to NULL, aka. they are al ### Function Return Type Handling For functions, returns will always be pointers no matter what, since all variables are dynamically allocated and the -actual storage in the stack is the pointer itself. +actual storage in the stack is the pointer itself. -This means that returning NULL will always be valid in Para-C aka. it's the `None` (from Python) of Para-C, +This means that returning NULL will always be valid in Para-C aka. it's the `None` (from Python) of Para-C, ### Global Variable handling -Global Variables are in Para-C handled a bit differentially, due to the general allocations using `pbl-mem.h`. This means -that any Para-C file will contain a `static void __InitialiseLocalGlobals()` function, where all the local globals are -defined and the code is executed that was written before. +Global Variables are in Para-C handled a bit differentially, due to the general allocations using `pbl-mem.h`. This +means that any Para-C file will contain a `static void PBL_INIT_GLOBALS()` function, where all the local globals +are defined and the code is executed that was written before. -This means that in the compiled code the globals will simply be pointer declarations with no interference. To that, -all declarations will be on runtime set to NULL, unless they have been defined. +This means that in the compiled code the globals will simply be declarations, until they were defined +on runtime (before the execution of main). ## Memory accessing - `pbl-mem.h` -(Currently in work - to be decided) +As already stated previously in section [Variables](#variables---pbl-typesh), Para-C is using a garbage collector to +handle its leftover variables that are not collected at the end of a stack's lifetime. This means that almost all +variables will be allocated and cleaned up using the [Boehm garbage collector](https://hboehm.info/gc/). The only +exceptions are for small variables that will likely be allocated in the stack using `alloca()` to preserve speed in +crucial tasks and not add unnecessary memory to the garbage collector. ## Function Meta-Data Tracking - `pbl-function.h` -Inside Para-C, when calling a Para-C function, so-called `PblMetaFunctionCallCtx_T` types are passed -as the first argument to every function, which contain: +Inside Para-C, when calling a Para-C function, so-called `PblFunctionCallMetaData_T` types are passed as the first +argument to every function, which contain: -- The meta-data of the invocation aka. call context, +- The meta-data of the invocation aka. call context, - The data necessary to track [exception meta-data](#exceptions---pbl-functionh) -These meta-data variables will be dynamically created for every invocation and will be allocated in the heap. -Meaning they can be accessed outside of the context, and used to create crash-tracebacks to -get extensive execution info on the failure of the program. +These meta-data variables will be dynamically created for every invocation and will be allocated in the heap. Meaning +they can be accessed outside the context, and used to create crash-tracebacks to get extensive execution info on the +failure of the program. ## Exceptions - `pbl-function.h` -Exceptions in Para-C are very similarly implemented to the exceptions in C#. +Exceptions in Para-C are very similarly implemented to the exceptions in C#. -Exceptions can be raised, re-raised with a parent-exception and child-exception, caught using an `except` block -and also used to pre-maturely abort the program. +Exceptions can be raised, re-raised with a parent-exception and child-exception, caught using an `except` block and also +used to pre-maturely abort the program. -Inside Para-C these are though implemented using the `PblMetaFunctionCallCtx_T` types, which will -store the traceback and exception information. All macros for exceptions have been implemented in this header -and should be always used when implementing higher level functions. +Inside Para-C these are though implemented using the `PblFunctionCallMetaData_T` types, which will store the traceback +and exception information. All macros for exceptions have been implemented in this header and should be always used when +implementing higher level functions. diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt new file mode 100644 index 0000000..2dcc77e --- /dev/null +++ b/examples/CMakeLists.txt @@ -0,0 +1,8 @@ +# Setting all files to compile +set(SOURCE_FILES ./simple-io.c) + +# Adding the executable example +add_executable(pbl-examples ${SOURCE_FILES}) + +# Linking the library into the example +target_link_libraries(pbl-examples PUBLIC pbl) diff --git a/examples/simple-io.c b/examples/simple-io.c new file mode 100644 index 0000000..d5233cd --- /dev/null +++ b/examples/simple-io.c @@ -0,0 +1,11 @@ +#include + +int main() +{ + PblString_T *string = PblGetStringT("Hello! Tell me your name:"); + PblChar_T *end = PblGetCharT(' '); + + PblString_T *input = PblInput_Base(string, end); + PblPrint(PblGetStringT("Your name is:"), .end=PblGetCharT(' ')); + PblPrint(input); +} \ No newline at end of file diff --git a/extern/CMakeLists.txt b/extern/CMakeLists.txt new file mode 100644 index 0000000..e69de29 diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt deleted file mode 100644 index a924383..0000000 --- a/include/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -project(pbl) - -set(HEADER_FILES - pbl/pbl-io.h - pbl/pbl.h - pbl/pbl-types.h - pbl/pbl-string.h - pbl/pbl-int.h - pbl/pbl-function.h - pbl/pbl-main.h - pbl/pbl-mem.h - pbl/pbl-any.h - pbl/pbl-apply-macro.h) - -set(SOURCE_FILES - pbl/pbl-io.c - pbl/pbl-types.c - pbl/pbl-string.c - pbl/pbl-int.c - pbl/pbl.c - pbl/pbl-function.c - pbl/pbl-main.c - pbl/pbl-mem.c - pbl/pbl-any.c) - -set(INCLUDED_EXTENSIONS - pbl/additional/va-opt.h) - -add_library(pbl STATIC ${SOURCE_FILES} ${HEADER_FILES} ${INCLUDED_EXTENSIONS}) - -include_directories(pbl) -include_directories(pbl/additional) - -add_subdirectory(pbl) -add_subdirectory(pbl/additional) diff --git a/include/pbl/pbl-apply-macro.h b/include/libpbl/additional/pbl-apply-macro.h similarity index 99% rename from include/pbl/pbl-apply-macro.h rename to include/libpbl/additional/pbl-apply-macro.h index b444526..63c95d4 100644 --- a/include/pbl/pbl-apply-macro.h +++ b/include/libpbl/additional/pbl-apply-macro.h @@ -1,11 +1,14 @@ /// @file pbl-apply-macro.c /// @brief This file defines the macro 'PBL_APPLY_MACRO', which allows for up to 127 args to be processed using the passed -///// macro function 't' +/// macro function 't' /// @author Luna-Klatzer /// @date 2021-11-23 /// @copyright Copyright (c) 2021 -#include "./additional/va-opt.h" +#pragma once + +// General Required Header Inclusion +#include "va-opt.h" #ifndef PBL_INCLUDE_APPLY_MACRO_H #define PBL_INCLUDE_APPLY_MACRO_H @@ -14,6 +17,8 @@ extern "C" { #endif +// ---- Macros -------------------------------------------------------------------------------------------------------- + /// @brief Eats the entered args and doesn't apply the macro 't' on any of the passed args #define PBL_APPLY_MACRO_EAT(t, ...) @@ -658,6 +663,8 @@ extern "C" { /// @note This has a limit of 127 repetitions! This means afterwards the macros will be eaten #define PBL_APPLY_MACRO(t, ...) PBL_APPLY_MACRO_APPLY_127(t, __VA_ARGS__) +// ---- End of Macros ------------------------------------------------------------------------------------------------- + #ifdef __cplusplus }; #endif diff --git a/include/pbl/additional/va-opt.h b/include/libpbl/additional/va-opt.h similarity index 67% rename from include/pbl/additional/va-opt.h rename to include/libpbl/additional/va-opt.h index 4d9c206..b915b9a 100644 --- a/include/pbl/additional/va-opt.h +++ b/include/libpbl/additional/va-opt.h @@ -55,50 +55,50 @@ www.boost.org/doc/libs/1_71_0/libs/preprocessor */ -#define VA_ARG1(A0,A1,...) A1 +#define VA_ARG1(A0, A1, ...) A1 // VA_EMPTY works only if __VA_OPT__ is supported, else always -> 1 -#define VA_EMPTY(...) VA_ARG1(__VA_OPT__(,)0,1,) +#define VA_EMPTY(...) VA_ARG1(__VA_OPT__(, ) 0, 1, ) // VA_OPT_SUPPORT helper macro for __VA_OPT__ feature detection. // Adapted from https://stackoverflow.com/a/48045656/7443483 // Use as #if VA_OPT_SUPPORT(?) -#define VA_OPT_SUPPORT ! VA_EMPTY +#define VA_OPT_SUPPORT !VA_EMPTY #if VA_OPT_SUPPORT(?) -# define IS_EMPTY(...) VA_EMPTY(__VA_ARGS__) -# define IFN(...) VA_EAT __VA_OPT__(()VA_IDENT) -# define IFE(...) VA_IDENT __VA_OPT__(()VA_EAT) -# define IFNE(...) VA_ARGTAIL __VA_OPT__((,)VA_ARG0) +#define IS_EMPTY(...) VA_EMPTY(__VA_ARGS__) +#define IFN(...) VA_EAT __VA_OPT__(() VA_IDENT) +#define IFE(...) VA_IDENT __VA_OPT__(() VA_EAT) +#define IFNE(...) VA_ARGTAIL __VA_OPT__((, ) VA_ARG0) #else -# define IS_EMPTY(...) IFP(IBP(__VA_ARGS__))(IE_GEN_0,IE_IBP)(__VA_ARGS__) -# define IFN(...) IFP(IBP(__VA_ARGS__))(GEN_IDENT,EAT_OR_IDENT)(__VA_ARGS__) -# define IFE(...) IFP(IBP(__VA_ARGS__))(GEN_EAT,IDENT_OR_EAT)(__VA_ARGS__) -# define IFNE(...) IFP(IBP(__VA_ARGS__))(GEN_ARGTAIL,ARG0_OR_TAIL)(__VA_ARGS__) +#define IS_EMPTY(...) IFP(IBP(__VA_ARGS__))(IE_GEN_0, IE_IBP)(__VA_ARGS__) +#define IFN(...) IFP(IBP(__VA_ARGS__))(GEN_IDENT, EAT_OR_IDENT)(__VA_ARGS__) +#define IFE(...) IFP(IBP(__VA_ARGS__))(GEN_EAT, IDENT_OR_EAT)(__VA_ARGS__) +#define IFNE(...) IFP(IBP(__VA_ARGS__))(GEN_ARGTAIL, ARG0_OR_TAIL)(__VA_ARGS__) #endif #define VA_EAT(...) #define VA_IDENT(...) __VA_ARGS__ -#define VA_ARG0_(A0,...) A0 +#define VA_ARG0_(A0, ...) A0 #define VA_ARG0(...) VA_ARG0_(__VA_ARGS__) -#define VA_ARGTAIL_(A0,...) __VA_ARGS__ +#define VA_ARGTAIL_(A0, ...) __VA_ARGS__ #define VA_ARGTAIL(...) VA_ARGTAIL_(__VA_ARGS__) // IFP helper macros to test IBP for IFN and IS_EMPTY -#define IFP_0(T,...) __VA_ARGS__ -#define IFP_1(T,...) T +#define IFP_0(T, ...) __VA_ARGS__ +#define IFP_1(T, ...) T -#define IFP_CAT(A,...) A##__VA_ARGS__ -#define IFP(BP) IFP_CAT(IFP_,BP) +#define IFP_CAT(A, ...) A##__VA_ARGS__ +#define IFP(BP) IFP_CAT(IFP_, BP) // IS_BEGIN_PAREN helper macros adapted from BOOST VMD -#define IBP_CAT_(A,...) A##__VA_ARGS__ -#define IBP_CAT(A,...) IBP_CAT_(A,__VA_ARGS__) +#define IBP_CAT_(A, ...) A##__VA_ARGS__ +#define IBP_CAT(A, ...) IBP_CAT_(A, __VA_ARGS__) -#define IBP_ARG0_(A,...) A +#define IBP_ARG0_(A, ...) A #define IBP_ARG0(...) IBP_ARG0_(__VA_ARGS__) #define IBP_IS_ARGS(...) 1 @@ -110,31 +110,31 @@ #define IBP(...) IBP_ARG0(IBP_CAT(IBP_, IBP_IS_ARGS __VA_ARGS__)) // IFN, IFE, IFNE and IF_EMPTY helpers without __VA_OPT__ support -#if ! VA_OPT_SUPPORT(?) +#if !VA_OPT_SUPPORT(?) -# define IBP_(T,...) IBP_ARG0(IBP_CAT(IF##T##_, IBP_IS_ARGS __VA_ARGS__)) +#define IBP_(T, ...) IBP_ARG0(IBP_CAT(IF##T##_, IBP_IS_ARGS __VA_ARGS__)) // IS_EMPTY helper macros, depend on IBP -# define IE_REDUCE_IBP(...) () -# define IE_GEN_0(...) 0 -# define IE_IBP(...) IBP(IE_REDUCE_IBP __VA_ARGS__ ()) +#define IE_REDUCE_IBP(...) () +#define IE_GEN_0(...) 0 +#define IE_IBP(...) IBP(IE_REDUCE_IBP __VA_ARGS__()) -# define GEN_IDENT(...) VA_IDENT -# define GEN_EAT(...) VA_EAT -# define GEN_ARGTAIL(...) VA_ARGTAIL -# define GEN_ARG0(...) VA_ARG0 +#define GEN_IDENT(...) VA_IDENT +#define GEN_EAT(...) VA_EAT +#define GEN_ARGTAIL(...) VA_ARGTAIL +#define GEN_ARG0(...) VA_ARG0 // IFN, IFE, IFNE helper macros -# define EAT_OR_IDENT(...) IBP_(N,IE_REDUCE_IBP __VA_ARGS__ ()) -# define IFN_1 VA_EAT, -# define IFN_IBP_IS_ARGS VA_IDENT, +#define EAT_OR_IDENT(...) IBP_(N, IE_REDUCE_IBP __VA_ARGS__()) +#define IFN_1 VA_EAT, +#define IFN_IBP_IS_ARGS VA_IDENT, -# define IDENT_OR_EAT(...) IBP_(E,IE_REDUCE_IBP __VA_ARGS__ ()) -# define IFE_1 VA_IDENT, -# define IFE_IBP_IS_ARGS VA_EAT, +#define IDENT_OR_EAT(...) IBP_(E, IE_REDUCE_IBP __VA_ARGS__()) +#define IFE_1 VA_IDENT, +#define IFE_IBP_IS_ARGS VA_EAT, -# define ARG0_OR_TAIL(...) IBP_(NE,IE_REDUCE_IBP __VA_ARGS__ ()) -# define IFNE_1 VA_ARGTAIL, -# define IFNE_IBP_IS_ARGS VA_ARG0, +#define ARG0_OR_TAIL(...) IBP_(NE, IE_REDUCE_IBP __VA_ARGS__()) +#define IFNE_1 VA_ARGTAIL, +#define IFNE_IBP_IS_ARGS VA_ARG0, -#endif // IFN and IF_EMPTY defs \ No newline at end of file +#endif// IFN and IF_EMPTY defs \ No newline at end of file diff --git a/include/pbl/pbl-function.h b/include/libpbl/func/pbl-function.h similarity index 69% rename from include/pbl/pbl-function.h rename to include/libpbl/func/pbl-function.h index 84a60be..2d96901 100644 --- a/include/pbl/pbl-function.h +++ b/include/libpbl/func/pbl-function.h @@ -5,11 +5,14 @@ /// @date 2021-11-23 /// @copyright Copyright (c) 2021 -#include "./additional/va-opt.h" -#include "./pbl-mem.h" -#include "./pbl-string.h" -#include "./pbl-types.h" -#include "./pbl-apply-macro.h" +#pragma once + +// General Required Header Inclusion +#include "../additional/va-opt.h" +#include "../additional/pbl-apply-macro.h" +#include "../mem/pbl-mem.h" +#include "../types/pbl-string.h" +#include "../types/pbl-types.h" #ifndef PBL_MODULES_FUNCTION_H #define PBL_MODULES_FUNCTION_H @@ -20,7 +23,7 @@ extern "C" { // ---- Helper Macros ------------------------------------------------------------------------------------------------- -/// As reference, this implementation of counting arguments is inspired by https://stackoverflow.com/a/35693080/13076191 +// As reference, this implementation of counting arguments is inspired by https://stackoverflow.com/a/35693080/13076191 /// @brief This macro function get fed 128 named parameters, which are eaten and used to get the off-set aka. N as the /// true number of args passed. @@ -51,37 +54,51 @@ extern "C" { /// @note This function also officially restricts the usage of functions with more than 127 parameters #define PBL_COUNT_VA_ARGS(...) PBL_COUNT_VA_ARGS_WRAP_GET_128TH_LOCATION(__VA_ARGS__, PBL_COUNT_VA_ARGS_128_ARG_SEQ()) +// ---- End of Helper Macros ------------------------------------------------------------------------------------------ + // ---- Basic Function Macros ----------------------------------------------------------------------------------------- /// @brief Specifier for a Para-C function, which is then formatted aka. to per default set the value passed to NULL, as /// in Para-C all values are pointers inherently and only declarations are not valid. -#define PBL_FUNC_ARG(arg, val) IFNE(val)(arg=val, .arg=NULL) +#define PBL_FUNC_ARG(arg, val) IFNE(val)(arg = val, .arg = NULL) + +/// @brief Validates a required argument for a Para-C function +#define PBL_VAL_REQ_ARG(var) PblValPtr((void*) (var)); /// @brief Creates based on the passed declaration signature a viable struct child aka. add ';' #define PBL_CREATE_FUNC_OVERHEAD_CREATE_STRUCT_CHILD(arg) arg; /// @brief Macro Function to get the standardised identifier for the 'Args' struct of a PBL function /// @note For this identifier to be valid, the macro function 'PBL_CREATE_FUNC_OVERHEAD' has to be used before +/// @return The identifier in the '_Args' format #define PBL_GET_FUNC_ARGS_IDENTIFIER(func_identifier) func_identifier##_Args /// @brief Macro Function to get the standardised identifier for the 'Base' of a PBL function /// @note For this identifier to be valid, the macro function 'PBL_CREATE_FUNC_OVERHEAD' has to be used before +/// @return The identifier in the '_Base' format #define PBL_GET_FUNC_BASE_IDENTIFIER(func_identifier) func_identifier##_Base /// @brief Macro Function to get the standardised identifier for the 'Overhead' of a PBL function /// @note For this identifier to be valid, the macro function 'PBL_CREATE_FUNC_OVERHEAD' has to be used before +/// @return The identifier in the '_Overhead' format #define PBL_GET_FUNC_OVERHEAD_IDENTIFIER(func_identifier) func_identifier##_Overhead /// @brief This creates the overhead function for the passed new function, by declaring it and generating a struct type, /// which defines the arguments that may be passed +/// @param ret_signature The return signature the function should have (left side of the identifier) +/// @param identifier The identifier for the function +/// @param _attribute_ The attribute for the function (right side) +/// @param args The arguments for the function, which should also be contained in the type struct itself /// @note At max. 127 args are allowed /// @note Both the macro for accessing the base and overhead have to be defined yourself! -#define PBL_CREATE_FUNC_OVERHEAD(signature, identifier, _attribute_, args...) \ +/// (This macro is only for headers) +/// @return The struct definition, and the base and overhead declaration +#define PBL_CREATE_FUNC_OVERHEAD(ret_signature, identifier, _attribute_, args...) \ struct PBL_GET_FUNC_ARGS_IDENTIFIER(identifier) { \ PBL_APPLY_MACRO(PBL_CREATE_FUNC_OVERHEAD_CREATE_STRUCT_CHILD, args) \ }; \ - signature PBL_GET_FUNC_BASE_IDENTIFIER(identifier)(args) _attribute_; \ - signature PBL_GET_FUNC_OVERHEAD_IDENTIFIER(identifier)(struct identifier##_Args in) _attribute_; + ret_signature PBL_GET_FUNC_BASE_IDENTIFIER(identifier)(args) _attribute_; \ + ret_signature PBL_GET_FUNC_OVERHEAD_IDENTIFIER(identifier)(struct identifier##_Args in) _attribute_; /// @brief Calls a function, passes the args and creates the appropriate unique identifier for the function call. /// @param func The function that should be called with the passed variadic arguments. @@ -92,28 +109,27 @@ extern "C" { /// @param meta_ctx The meta_ctx that should be used as a parent ctx (invocation context) of the child function /// @param args The arguments to pass to the local function #define PBL_CALL_FUNC(func, var_to_pass, unique_id, is_threaded, meta_ctx, args) \ - PblMetaFunctionCallCtx_T *unique_id_##func##_CALLCTX = PblGetMetaFunctionCallCtxT( \ - PblGetStringT(#func), \ - PblGetBoolT(false), \ - PblGetUIntT(IFNE(args)(PBL_COUNT_VA_ARGS(args), 0)), \ - is_threaded, \ - NULL, \ - meta_ctx, \ - NULL); \ + PblFunctionCallMetaData_T *unique_id_##func##_CALLCTX = PblGetMetaFunctionCallCtxT( \ + PblGetStringT(#func), PblGetBoolT(false), PblGetUIntT(IFNE(args)(PBL_COUNT_VA_ARGS(args), 0)), is_threaded, NULL, \ + meta_ctx, NULL); \ (var_to_pass) = func(unique_id_##func##_CALLCTX IFN(args)(, args)); +// ---- End of Basic Function Macros ---------------------------------------------------------------------------------- + // ---- Exception Implementation -------------------------------------------------------------------------------------- /// @brief (Never use this for malloc - this only indicates the usable memory space) -/// @returns The size in bytes of the PBL Long Double type +/// @returns The usable size in bytes of the PBL Long Double type #define PblException_T_Size (4 * sizeof(PblString_T *) + sizeof(PblUInt_T *) + 2 * sizeof(void *)) /// @brief Returns the declaration default for the type 'PblException_T' -#define PblException_T_DeclDefault PBL_DECLARATION_CONSTRUCTOR(PblException_T) -/// @brief Returns the definition default for the type 'PblException_T', where the children have not been set yet and only the -/// value itself 'exists' already. +#define PblException_T_DeclDefault PBL_TYPE_DECLARATION_DEFAULT_CONSTRUCTOR(PblException_T) +/// @brief Returns the definition default for the type 'PblException_T', where the value/the children have not been set yet +/// and only the value itself 'exists' already. If the type is a struct-type, then the children will likely be NULL, +/// initialised to 0 or another Definition Default of another type #define PblException_T_DefDefault \ - PBL_DEFINITION_STRUCT_CONSTRUCTOR(PblException_T, .msg = NULL, .name = NULL, .filename = NULL, .line = NULL, \ - .line_content = NULL, .parent_exc = NULL, .child_exc = NULL) + PBL_TYPE_DEFINITION_DEFAULT_STRUCT_CONSTRUCTOR(PblException_T, .msg = NULL, .name = NULL, .filename = NULL, \ + .line = NULL, .line_content = NULL, .parent_exc = NULL, \ + .child_exc = NULL) struct PblException_Base { /// @brief The message of the exception @@ -135,11 +151,13 @@ struct PblException_Base { }; /// Exception implementation -struct PblException PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(struct PblException_Base) +struct PblException { PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(struct PblException_Base) }; /// Exception implementation typedef struct PblException PblException_T; -// ---- Raise Exception Macros ---------------------------------------------------------------------------------------- +// ---- End of Exception Implementation ------------------------------------------------------------------------------- + +// ---- Raise Exception Macro ---------------------------------------------------------------------------------------- /// @brief This a "one-liner" constructor, which will allocate a new exception and raise it (return to the caller of the /// stack). @@ -148,10 +166,12 @@ typedef struct PblException PblException_T; /// @note This requires the existence of 'this_call_meta' of type 'PblMetaFunctionCallCtx_T'. #define PBL_RAISE_EXCEPTION(exception, call_return_type) \ PblRaiseNewException(this_call_meta, exception); \ - PBL_ALLOC_DECLARATION(raise_exc_ret, call_return_type) \ + PBL_DECLARE_VAR(raise_exc_ret, call_return_type) \ return raise_exc_ret; -// ---- Invoke and Catch Exception handling --------------------------------------------------------------------------- +// ---- End of Raise Exception Macro ---------------------------------------------------------------------------------- + +// ---- Invoke and Catch Exception-Handling --------------------------------------------------------------------------- /// @brief This is a "one-liner" constructor for Para-C functions, which will call the passed function with the args /// (__VA_ARGS__) and if an exception is raised update the local ctx appropriately @@ -161,7 +181,7 @@ typedef struct PblException PblException_T; /// @param is_threaded Whether this macro is invoked in a threaded context. This variable is directly passed to the /// created context. /// @param args the arguments to pass to the function, leave empty if none shall be passed. -#define PBL_C_BASE_EXCEPTION_CATCH_CONSTRUCTOR(func, var_to_pass, unique_id, is_threaded, meta_ctx, args) \ +#define PBL_BASE_CALL_AND_CATCH_EXCEPTION(func, var_to_pass, unique_id, is_threaded, meta_ctx, args) \ PBL_CALL_FUNC(func, var_to_pass, unique_id, is_threaded, meta_ctx, IFN(args)(args)) \ if (unique_id_##func##_CALLCTX->actual.is_failure->actual) { \ (meta_ctx)->actual.is_failure = PblGetBoolT(true); \ @@ -171,22 +191,20 @@ typedef struct PblException PblException_T; : unique_id_##func##_CALLCTX; \ } -/// @brief This is a "one-liner" constructor for Para-C functions, which will call the passed function with the args -/// (__VA_ARGS__) and return to the caller of the stack, if the called function returns with a raised exception. +/// @brief This will call the passed function with the args (__VA_ARGS__) and return to the caller of the stack, if the +/// called function returns with a raised exception. /// @param func The function that should be called with the passed variadic arguments. /// @param var_to_pass The variable the return of the function should be passed to. /// @param ctx_rtype The return type of the context (function) where this macro is used. If an exception occurs the /// default value (_DeclDefault) will be returned. /// @param unique_id The unique id the call ctx should be declared as. It follows the following scheme: unique##_##func. /// @note This requires the existence of 'this_call_meta' of type 'PblMetaFunctionCallCtx_T' -#define PBL_EXCEPTION_CATCH_FUNC_CONSTRUCTOR(func, var_to_pass, ctx_rtype, unique_id, args...) \ - PBL_CALL_FUNC(func, var_to_pass, unique_id, this_call_meta->actual.is_threaded, this_call_meta, IFN(args)(args)) \ - if (unique_id_##func##_CALLCTX->actual.is_failure->actual) { \ - this_call_meta->actual.is_failure = PblGetBoolT(true); \ - this_call_meta->actual.exception = unique_id_##func##_CALLCTX->actual.exception; \ - this_call_meta->actual.failure_origin_ctx = unique_id_##func##_CALLCTX; \ - return NULL; \ - } +#define PBL_CALL_FUNC_AND_CATCH(func, var_to_pass, unique_id, args...) \ + PBL_BASE_CALL_AND_CATCH_EXCEPTION(func, var_to_pass, unique_id, this_call_meta->actual.is_threaded, this_call_meta, \ + IFN(args)(args)); \ + if (unique_id_##func##_CALLCTX->actual.is_failure->actual) { return NULL; } + +// ---- End of Invoke and Catch Exception-Handling -------------------------------------------------------------------- // ---- Exception Catching (try-except) ------------------------------------------------------------------------------- @@ -198,26 +216,24 @@ typedef struct PblException PblException_T; /// correctly update the information. /// @param meta_ctx The meta_ctx that should be used as a parent ctx (invocation context) of the child function /// @param call_return_type The return type of the function where this macro is invoked. -#define PBL_EXCEPTION_TRY_EXCEPT_BLOCK(block, except_block, block_identifier, meta_ctx, call_return_type) \ +#define PBL_TRY_EXCEPT_BLOCK(block, except_block, block_identifier, meta_ctx, call_return_type) \ PblException_T block_identifier##_local_catched_exc; \ PblBool_T *block_identifier##_invoke_except = PblGetBoolT(false); \ PblBool_T *block_identifier##_except_handled = PblGetBoolT(false); \ block; \ - block_identifier##_except_block : except_block; \ + block_identifier##_except_block : { except_block }; \ block_identifier##_finish_up : { \ if (block_identifier##_invoke_except->actual && !block_identifier##_except_handled->actual) { return NULL; } \ } -/// @brief This is a "one-liner" constructor for functions that accept arguments and have a return, which will call the -/// passed function with the args (__VA_ARGS__) and if an exception is raised jump to the except blocks. +/// @brief This macro calls a function and if an exception was raised, goes directly to the parent except_block /// @param func The function that should be called with the passed variadic arguments. /// @param var_to_pass The variable the return of the function should be passed to. /// @param ctx_rtype The return type of the context (function) where this macro is used. If an exception occurs the /// default value (_DeclDefault) will be returned. /// @param unique_id The unique id the call ctx should be declared as. It follows the following scheme: unique##_##func. /// @note This requires the existence of 'this_call_meta' of type 'PblMetaFunctionCallCtx_T' -#define PBL_EXCEPTION_TRY_BLOCK_CATCH_FUNC_CONSTRUCTOR(func, var_to_pass, ctx_rtype, unique_id, block_identifier, \ - args...) \ +#define PBL_CALL_FUNC_IN_TRY_EXCEPT_BLOCK(func, var_to_pass, ctx_rtype, unique_id, block_identifier, args...) \ PBL_CALL_FUNC(func, var_to_pass, unique_id, this_call_meta->actual.is_threaded, this_call_meta, IFN(args)(args)) \ if (unique_id_##func##_CALLCTX->actual.is_failure->actual) { \ block_identifier##_local_catched_exc = *((PblException_T *) unique_id_##func##_CALLCTX->actual.exception); \ @@ -227,30 +243,34 @@ typedef struct PblException PblException_T; /// @brief Adds an exception clause to the current block - this should be used to create a block statement which then is /// passed as an argument to EXCEPTION_TRY_EXCEPT_BLOCK() -#define PBL_EXCEPTION_CREATE_EXCEPT_BLOCK(exception_name, block_to_execute, block_identifier) \ +#define PBL_EXCEPT_BLOCK(exception_name, block_to_execute, block_identifier) \ if (block_identifier##_invoke_except->actual) { \ block_to_execute; \ block_identifier##_except_handled = PblGetBoolT(true); \ goto block_identifier##_finish_up; \ } +// ---- End of Exception Catching (try-except) ------------------------------------------------------------------------ + // ---- Function Meta Type -------------------------------------------------------------------------------------------- /// @brief (Never use this for malloc - this only indicates the usable memory space) -/// @returns The size in bytes of the PBL MetaFunctionCallCtx type -#define PblMetaFunctionCallCtx_T_Size \ - (sizeof(PblBool*) + sizeof(PblUInt_T*) + sizeof(PblBool_T*) + 2 * sizeof(PblMetaFunctionCallCtx_T *) + sizeof(NULL)) +/// @returns The usable size in bytes of the PBL MetaFunctionCallCtx type +#define PblFunctionCallMetaData_T_Size \ + (sizeof(PblBool_T *) + sizeof(PblUInt_T *) + sizeof(PblBool_T *) + 2 * sizeof(PblFunctionCallMetaData_T *) + \ + sizeof(NULL)) /// @brief Returns the declaration default for the type 'PblMetaFunctionCallCtx_T' -#define PblMetaFunctionCallCtx_T_DeclDefault PBL_DECLARATION_CONSTRUCTOR(PblMetaFunctionCallCtx_T) -/// @brief Returns the definition default for the type 'PblMetaFunctionCallCtx_T', where the children have not been set yet and only the -/// value itself 'exists' already. -#define PblMetaFunctionCallCtx_T_DefDefault \ - PBL_DEFINITION_STRUCT_CONSTRUCTOR(PblMetaFunctionCallCtx_T, .function_identifier = NULL, .is_failure = NULL, \ - .arg_amount = NULL, .is_threaded = NULL, .failure_origin_ctx = NULL, \ - .call_origin_ctx = NULL, .exception = NULL) +#define PblFunctionCallMetaData_T_DeclDefault PBL_TYPE_DECLARATION_DEFAULT_CONSTRUCTOR(PblFunctionCallMetaData_T) +/// @brief Returns the definition default for the type 'PblMetaFunctionCallCtx_T', where the value/the children have not been set yet +/// and only the value itself 'exists' already. If the type is a struct-type, then the children will likely be NULL, +/// initialised to 0 or another Definition Default of another type +#define PblFunctionCallMetaData_T_DefDefault \ + PBL_TYPE_DEFINITION_DEFAULT_STRUCT_CONSTRUCTOR( \ + PblFunctionCallMetaData_T, .function_identifier = NULL, .is_failure = NULL, .arg_amount = NULL, \ + .is_threaded = NULL, .failure_origin_ctx = NULL, .call_origin_ctx = NULL, .exception = NULL) /// @brief Base Meta Type passed to all functions -struct PblMetaFunctionCallCtx_Base { +struct PblFunctionCallMetaData_Base { /// @brief The function name - identifier PblString_T *function_identifier; /// Returns whether the function failed due to an exception occurring @@ -272,28 +292,30 @@ struct PblMetaFunctionCallCtx_Base { PblException_T *exception; }; -struct PblMetaFunctionCallCtx PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(struct PblMetaFunctionCallCtx_Base) - /// @brief Base Meta Type passed to all functions -typedef struct PblMetaFunctionCallCtx PblMetaFunctionCallCtx_T; +struct PblFunctionCallMetaData { PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(struct PblFunctionCallMetaData_Base); }; +/// @brief Base Meta Type passed to all functions +typedef struct PblFunctionCallMetaData PblFunctionCallMetaData_T; -// ---- Helper Functions ---------------------------------------------------------------------------------------------- +// ---- End of Function Meta Type ------------------------------------------------------------------------------------- + +// ---- Functions Definitions ----------------------------------------------------------------------------------------- /** * @brief Gets a new function call ctx, which will be located in the heap * @return The newly created function call ctx (pointer) */ -PblMetaFunctionCallCtx_T *PblGetMetaFunctionCallCtxT(PblString_T *function_identifier, PblBool_T *is_failure, - PblUInt_T *arg_amount, PblBool_T *is_threaded, - PblMetaFunctionCallCtx_T *failure_origin_ctx, - PblMetaFunctionCallCtx_T *call_origin_ctx, - PblException_T *exception); +PblFunctionCallMetaData_T *PblGetMetaFunctionCallCtxT(PblString_T *function_identifier, PblBool_T *is_failure, + PblUInt_T *arg_amount, PblBool_T *is_threaded, + PblFunctionCallMetaData_T *failure_origin_ctx, + PblFunctionCallMetaData_T *call_origin_ctx, + PblException_T *exception); /** * @brief Deallocates the passed function call ctx and safely resets all values * @param ctx The function call ctx to deallocate */ -PblVoid_T PblDeallocateMetaFunctionCallCtxT(PblMetaFunctionCallCtx_T *ctx); +PblVoid_T PblDeallocateMetaFunctionCallCtxT(PblFunctionCallMetaData_T *ctx); /** * @brief Gets a new Exception Type, which is located in the heap @@ -307,7 +329,7 @@ PblException_T *PblGetExceptionT(PblString_T *msg, PblString_T *name, PblString_ * @param this_call_meta The current context info that should be updated * @param exception The exception that was initialised */ -PblVoid_T PblRaiseNewException(PblMetaFunctionCallCtx_T *this_call_meta, PblException_T *exception); +PblVoid_T PblRaiseNewException(PblFunctionCallMetaData_T *this_call_meta, PblException_T *exception); /** * @brief Deallocates the passed exception type and safely resets all values @@ -316,15 +338,10 @@ PblVoid_T PblRaiseNewException(PblMetaFunctionCallCtx_T *this_call_meta, PblExce */ PblVoid_T PblDeallocateExceptionT(PblException_T *exc); -/** - * @brief Cleanups the current exception Context and deallocates the memory that isn't used anymore - * @param cleanup_ctx The function call ctx that should be cleaned up (including all of it's children) - */ -PblVoid_T PblCleanupExceptionContext(PblMetaFunctionCallCtx_T *cleanup_ctx); - +// ---- End of Functions Definitions ---------------------------------------------------------------------------------- #ifdef __cplusplus } #endif -#endif //PBL_MODULES_FUNCTION_H +#endif//PBL_MODULES_FUNCTION_H diff --git a/include/libpbl/io/pbl-io.h b/include/libpbl/io/pbl-io.h new file mode 100644 index 0000000..e253665 --- /dev/null +++ b/include/libpbl/io/pbl-io.h @@ -0,0 +1,157 @@ +/// @file pbl-io.h +/// @brief IO Implementation based on stdio.h +/// @author Luna-Klatzer +/// @date 2021-11-23 +/// @copyright Copyright (c) 2021 + +#pragma once + +// Including the Base which this header intends to implement +#ifdef __cplusplus +# include +#else +# include +#endif + + +// General Required Header Inclusion +#include "../types/pbl-string.h" +#include "../types/pbl-types.h" +#include "../func/pbl-function.h" + +#ifndef PBL_MODULES_IO_H +#define PBL_MODULES_IO_H + +#ifdef __cplusplus +extern "C" { +#endif + +// ---- File ---------------------------------------------------------------------------------------------------------- + +/// @brief (Never use this for malloc - this only indicates the usable memory space) +/// @returns The size of the type 'PblIOFile_T' in bytes +#define PblFile_T_Size sizeof(FILE *) +/// @brief Returns the declaration default for the type 'PblIOFile_T' +#define PblFile_T_DeclDefault PBL_TYPE_DECLARATION_DEFAULT_CONSTRUCTOR(PblIOFile_T) +/// @brief Returns the definition default for the type 'PblIOFile_T', where the value/the children have not been set yet +/// and only the value itself 'exists' already. If the type is a struct-type, then the children will likely be NULL, +/// initialised to 0 or another Definition Default of another type +#define PblFile_T_DefDefault PBL_TYPE_DEFINITION_DEFAULT_SIMPLE_CONSTRUCTOR(PblIOFile_T, NULL) + +/// @brief File Descriptor used to perform I/O actions on a file +struct PblIOFile { PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(FILE *); }; +/// @brief File Descriptor used to perform I/O actions on a file +typedef struct PblIOFile PblIOFile_T; + +// ---- End of File --------------------------------------------------------------------------------------------------- + +// ---- Stream Type --------------------------------------------------------------------------------------------------- + +/// @brief (Never use this for malloc - this only indicates the usable memory space) +/// @returns The size of the type 'PblIOStream_T' in bytes +#define PblStream_T_Size (sizeof(PblUInt_T *) + sizeof(PblIOFile_T *) + sizeof(PblBool_T *) + sizeof(PblString_T *)) +/// @brief Returns the declaration default for the type 'PblIOStream_T' +#define PblStream_T_DeclDefault PBL_TYPE_DECLARATION_DEFAULT_CONSTRUCTOR(PblIOStream_T) +/// @brief Returns the definition default for the type 'PblIOStream_T', where the value/the children have not been set yet +/// and only the value itself 'exists' already. If the type is a struct-type, then the children will likely be NULL, +/// initialised to 0 or another Definition Default of another type +#define PblStream_T_DefDefault \ + PBL_TYPE_DEFINITION_DEFAULT_STRUCT_CONSTRUCTOR(PblIOStream_T, .fd = NULL, .file = NULL, .open = NULL, .mode = NULL) + +/// @brief Base Struct of PblString - avoid using this type +struct PblStream_Base { + /// @brief The unique integer identifier associated with the file Descriptor + PblUInt_T *fd; + /// @brief The FILE pointer, which points to the stream/file - defined if the stream was opened + PblIOFile_T *file; + /// @brief Describes whether the file descriptor is currently in use + PblBool_T *open; + /// @brief The mode the FILE* was opened + PblString_T *mode; +}; + +/// @brief File Stream used to perform I/O actions on a file +struct PblIOStream { PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(struct PblStream_Base); }; +/// @brief File Stream used to perform I/O actions on a file +typedef struct PblIOStream PblIOStream_T; + +/// @brief Standard stream for getting input on the default program console +#define PBL_STREAM_STDIN \ + PBL_TYPE_DEFINITION_DEFAULT_STRUCT_CONSTRUCTOR(PblIOStream_T, .fd = PblGetUIntT(0), .file = PblGetIOFileT(stdin), \ + .open = PblGetBoolT(true), .mode = PblGetStringT("a")) + +/// @brief Standard stream for outputting to the default program console +#define PBL_STREAM_STDOUT \ + PBL_TYPE_DEFINITION_DEFAULT_STRUCT_CONSTRUCTOR(PblIOStream_T, .fd = PblGetUIntT(1), .file = PblGetIOFileT(stdout), \ + .open = PblGetBoolT(true), .mode = PblGetStringT("a")) + +/// @brief Standard stream for outputting error messages to the default program console +#define PBL_STREAM_STDERR \ + PBL_TYPE_DEFINITION_DEFAULT_STRUCT_CONSTRUCTOR(PblIOStream_T, .fd = PblGetUIntT(2), .file = PblGetIOFileT(stderr), \ + .open = PblGetBoolT(true), .mode = PblGetStringT("a")) + +// ---- End of Stream Type -------------------------------------------------------------------------------------------- + +// ---- Functions Definitions ----------------------------------------------------------------------------------------- + +/** + * @brief Converts the low level C-Type to a PBL File type + * @param val The FILE pointer C-type + * @return The newly created PBL File type + * @note This is a C to Para-C type conversion function - args are in C therefore + */ +PblIOFile_T *PblGetIOFileT(FILE *val); + +/** + * @brief Converts the low level C-Type to a PBL Stream type. Creates the FILE* pointer as well + * @param fd The file descriptor that will be converted + * @param mode The mode that should be used to open the FILE* + * @return The newly created PBL Stream type + * @note This is a C to Para-C type conversion function - args are therefore in C + */ +PblIOStream_T *PblGetIOStreamT(int fd, const char *mode); + +// Creating the overhead and struct type for the Pbl-Function 'PblPrint' +PBL_CREATE_FUNC_OVERHEAD(PblString_T *, PblInput,, PblString_T *display_msg, PblChar_T* end) + +/** + * @brief Takes input and displays the entered message before it + * @param display The display message + * @param end The end-character that should be displayed. If per default '\0'. This is the same logic as in Print! + * @return The input that was given + */ +#define PblInput(args...) \ + PBL_GET_FUNC_OVERHEAD_IDENTIFIER(PblInput)((struct PBL_GET_FUNC_ARGS_IDENTIFIER(PblInput)){args}) + +// Creating the overhead and struct type for the Pbl-Function 'PblPrint' +PBL_CREATE_FUNC_OVERHEAD(PblChar_T *, PblInputChar,, PblString_T *display_msg, PblChar_T* end) + +/** + * @brief Takes a single key input and displays the entered message before it + * @param display The display message + * @param end The end-character that should be displayed. If per default '\0'. This is the same logic as in Print! + * @return The character that was fetched + * @note If the entered char is \n or EOF, then \0 is returned. + */ +#define PblInputChar(args...) \ + PBL_GET_FUNC_OVERHEAD_IDENTIFIER(PblInputChar)((struct PBL_GET_FUNC_ARGS_IDENTIFIER(PblInputChar)){args}) + +// Creating the overhead and struct type for the Pbl-Function 'PblPrint' +PBL_CREATE_FUNC_OVERHEAD(__attribute__((unused)) PblVoid_T, PblPrint,, PblString_T *out, PblIOStream_T *stream, PblChar_T *end) + +/** + * @brief Prints the content of the passed string + * @param out The string that should be printed out (Pointer) + * @param stream The stream it should be printed onto + * @param end The end character that should be printed after 'out' + */ +#define PblPrint(args...) \ + PBL_GET_FUNC_OVERHEAD_IDENTIFIER(PblPrint)((struct PBL_GET_FUNC_ARGS_IDENTIFIER(PblPrint)){args}) + +// ---- Functions Definitions ----------------------------------------------------------------------------------------- + +#ifdef __cplusplus +} +#endif + +#endif//PBL_MODULES_IO_H diff --git a/include/libpbl/mem/pbl-mem-tools.h b/include/libpbl/mem/pbl-mem-tools.h new file mode 100644 index 0000000..ea09eb6 --- /dev/null +++ b/include/libpbl/mem/pbl-mem-tools.h @@ -0,0 +1,57 @@ +/// @file pbl-advanced-mem.c +/// @brief Advanced memory handling and management, which is separate from the base pbl-mem.h as that implements only +/// the most basic functions. +/// @author Luna-Klatzer +/// @date 2021-12-09 +/// @copyright Copyright (c) 2021 + +#pragma once + +// General Required Header Inclusion +#include "./pbl-mem.h" +#include "../types/pbl-any.h" +#include "../types/pbl-types.h" + +#ifndef PBL_INCLUDE_ADVANCED_MEM_H_ +#define PBL_INCLUDE_ADVANCED_MEM_H_ + +// ---- Functions Definitions ----------------------------------------------------------------------------------------- + +// TODO! Implement global PblTypeList_T for proper dynamic type checking and fetching + +/** + * @brief Uses 'PblMemCpy()' from 'pbl-mem.h' to copy memory from a type to a destination. This is intended to be used + * as a safety function, which will always get the size from the appropriate size. This though means this function is + * only able to be used with Pbl-Types, as it requires the meta-data of the types. + * + * This function automatically fetches the types from the any type. This function will though not check for proper value + * usage, but simply for size as that could cause a segmentation fault. Meaning it is valid to copy a integer onto + * a string is valid, as long as both have the same effective size. + * @param dest The destination where the memory should be copied to + * @param src The source/origin that should be copied + * @param type The type that should be used for the type checking + * @param amount The amount that should be copied + * @return The pointer of the passed dest variable + * @note This function will raise an exception if either types are of invalid size (both must be equal). For example + * copying 4 bytes to a 2 byte variable. + */ +__attribute__((unused)) void *PblSafeMemCpy(PblAny_T *dest, PblAny_T *src, PblUInt_T amount); + +/** + * @brief Uses 'PblMemCpy()' from 'pbl-mem.h' to copy memory from a type to a destination. This is intended to be used + * as a safety function, which will always get the size from the appropriate size. This though means this function is + * only able to be used with Pbl-Types, as it requires the meta-data of the types. + * @param dest The destination where the memory should be copied to + * @param src The source/origin that should be copied + * @param type The type that should be used for the type checking + * @param amount The amount that should be copied + * @return The pointer of the passed dest variable + * @note This function will raise an exception if either types are of invalid size (both must be equal). For example + * copying 4 bytes to a 2 byte variable. + */ +__attribute__((unused)) void *PblTypedMemCpy(void *dest, const void *src, PblType_T *dest_type, PblType_T *src_type, + PblUInt_T amount); + +// ---- End of Functions Definitions ---------------------------------------------------------------------------------- + +#endif//PBL_INCLUDE_ADVANCED_MEM_H_ diff --git a/include/pbl/pbl-mem.h b/include/libpbl/mem/pbl-mem.h similarity index 68% rename from include/pbl/pbl-mem.h rename to include/libpbl/mem/pbl-mem.h index cb962d4..500bcd2 100644 --- a/include/pbl/pbl-mem.h +++ b/include/libpbl/mem/pbl-mem.h @@ -5,8 +5,13 @@ /// @date 2021-11-23 /// @copyright Copyright (c) 2021 +#pragma once + +// Including the required Garbage Collector, which this header intends to implement and utilise #include "gc.h" -#include "./pbl-main.h" + +// General Required Header Inclusion +#include "../pbl-main.h" #ifndef PBL_MODULES_MEM_H #define PBL_MODULES_MEM_H @@ -15,58 +20,57 @@ extern "C" { #endif -// ---- Helper Macro -------------------------------------------------------------------------------------------------- +// ---- End of Memory Setup ------------------------------------------------------------------------------------------- + +// ---- Helper Macros ------------------------------------------------------------------------------------------------- /// @brief Logs the entered error / string and aborts the program with the exit status '1' #define PBL_LOG_MEM_ERR(...) PblAbortWithCriticalError(1, __VA_ARGS__) -// ---- Mem-Cpy ------------------------------------------------------------------------------------------------------- - /// @brief Logs an error for attempting to copy from an invalid memory address (NULL) and aborts with exit status '1' #define PBL_LOG_CPY_FROM_NULL_PTR PBL_LOG_MEM_ERR("PARA-C: Attempted to copy from an invalid memory address (NULL)"); + /// @brief Logs an error for attempting to copy to an invalid memory address (NULL) and aborts with exit status '1' #define PBL_LOG_CPY_TO_NULL_PTR PBL_LOG_MEM_ERR("PARA-C: Attempted to copy to an invalid memory address (NULL)"); + /// @brief Logs an error for receiving 'NULL' from the call of the C function 'memcpy' and aborts with exit status '1' #define PBL_LOG_CPY_RECEIVE_NULL_PTR PBL_LOG_MEM_ERR("PARA-C: Failed to cpy memory (Received NULL)"); -// ---- Ptr-Access ---------------------------------------------------------------------------------------------------- - /// @brief Logs an error for attempting to use an invalid pointer address (NULL) and aborts with exit status '1' #define PBL_LOG_ACCESS_ERR_NULL_PTR PBL_LOG_MEM_ERR("PARA-C: Attempted to access invalid memory address (NULL)"); -// ---- Free ---------------------------------------------------------------------------------------------------------- - /// @brief Logs an error for attempting to free an invalid pointer address (NULL) and aborts with exit status '1' #define PBL_LOG_FREE_ERR_NULL_PTR PBL_LOG_MEM_ERR("PARA-C: Attempted to free invalid memory address (NULL)"); -// ---- Alloc --------------------------------------------------------------------------------------------------------- - -/// @brief Logs an error for attempting to allocate 0 bytes and aborts with exit status '1' -#define PBL_LOG_ALLOC_ERR_NULL_SZ PBL_LOG_MEM_ERR("PARA-C: Attempted to allocate invalid amounts of memory (0)"); /// @brief Logs an error for receiving 'NULL' from the call of the GC function 'GC_MALLOC' or 'GC_MALLOC_ATOMIC' and /// aborts with exit status '1' #define PBL_LOG_ALLOC_ERR_RECEIVE_NULL_RET PBL_LOG_MEM_ERR("PARA-C: Failed to allocate memory (Received NULL)"); -// ---- Re-Alloc ------------------------------------------------------------------------------------------------------ - /// @brief Logs an error for attempting to realloc an invalid pointer address (NULL) and aborts with exit status '1' #define PBL_LOG_REALLOC_ERR_NULL_PTR PBL_LOG_MEM_ERR("PARA-C: Attempted to re-allocate invalid memory address (NULL)"); -/// @brief Logs an error for attempting to realloc 0 bytes and aborts with exit status '1' -#define PBL_LOG_REALLOC_ERR_NULL_SZ PBL_LOG_MEM_ERR("PARA-C: Attempted to re-allocate invalid amounts of memory (0)"); + /// @brief Logs an error for receiving 'NULL' from the call of the GC function 'GC_REALLOC' and aborts with exit status /// '1' #define PBL_LOG_REALLOC_ERR_RECEIVE_NULL_RET PBL_LOG_MEM_ERR("PARA-C: Failed to re-allocate memory (Received NULL)"); -// ---- Helper functions ---------------------------------------------------------------------------------------------- +// ---- End of Helper Macro ------------------------------------------------------------------------------------------- + +// ---- Functions Definitions ----------------------------------------------------------------------------------------- /** - * @brief This is the Pbl equivalent of memcpy(), but in this case additional checking is applied for safety measures + * @brief This is the Pbl equivalent of memcpy(), but in this case additional checking is applied for safety measures. + * This may be used to copy bytes from one destination to the other, though it should be watched out the byte sizes are + * properly fetched using sizeof(PBL_TYPE | C_TYPE), as it **only** copies 1 byte at a time, and as such does NOT check + * for proper sizing. + * + * For proper checking you may use 'PblTypedMemCpy' (from 'pbl-advanced-mem.h'), which will copy a type one at a time, + * and not allow incomplete ones! * @param dest The destination where the memory should be copied to * @param src The source/origin that should be copied * @param bytes The amount of bytes to be copied * @return The pointer of the passed dest variable */ -void* PblMemCpy(void* dest, const void * src, size_t bytes); +void *PblMemCpy(void *dest, const void *src, size_t bytes); /** * @brief Validates the pointer given as parameter and checks whether it's save to access, if it's not safe it will @@ -76,7 +80,13 @@ void* PblMemCpy(void* dest, const void * src, size_t bytes); * @note Only use this function to validate whether the pointer is valid for accessing! This function will count NULL * as invalid, meaning this should not be used for pointers that will be defined later! */ -void* PblValPtr(void* ptr); +void *PblValPtr(void *ptr); + +/** + * @brief Frees the passed pointer if it is not NULL. Used as the function for __attribute__ (__cleanup__) + * @param ptr The double-pointer pointing to the local pointer variable + */ +void PblCleanupLocal(void **ptr); /** * @brief Frees the passed value and applies checks to avoid faulty freeing of memory. @@ -85,16 +95,26 @@ void* PblValPtr(void* ptr); */ void PblFree(void *ptr); +/** + * @brief Allocates the passed value and applies checks to avoid faulty allocations of memory. The allocated variable + * will not be checked for garbage collection, meaning it has to be manually de-allocated. This is intended for + * variables that are used globally and will be needed until the end of the program. + * @param size The size of the memory to allocate + * @return he pointer returned by the 'GC_MALLOC_UNCOLLECTABLE' call + * @note This will crash the program if the size of the value is invalid! + */ +__attribute__((unused)) void *PblMallocUncollectable(size_t size); + /** * @brief Allocates the passed value and applies checks to avoid faulty allocations of memory. * @param size The size of the memory to allocate - * @return The pointer returned by the GC malloc call + * @return The pointer returned by the 'GC_MALLOC()' call * @note This will crash the program if the size of the value is invalid! * @warning It is discouraged to directly use this function to allocate memory, unless for explicit cases. For general - * usage of allocating a type please use 'PBL_ALLOC_DEFINITION(to_write, type)', which will safely allocate and + * usage of allocating a type please use 'PBL_DEFINE_VAR(to_write, type, cleanup...)', which will safely allocate and * initialise the value! */ -void* PblMalloc(size_t size); +void *PblMalloc(size_t size); /** * @brief Allocates an atomic variable - Objects of atomic types are the only objects that are free from data races; @@ -103,10 +123,10 @@ void* PblMalloc(size_t size); * @return The pointer returned by the GC atomic malloc call * @note This will crash the program if the size of the value is invalid! * @warning It is discouraged to directly use this function to allocate memory, unless for explicit cases. For general - * usage of allocating a type please use 'PBL_ALLOC_DEFINITION(to_write, type)', which will safely allocate and + * usage of allocating a type please use 'PBL_DEFINE_VAR(to_write, type)', which will safely allocate and * initialise the value! */ -void* PblMallocAtomic(size_t size); +__attribute__((unused)) void *PblMallocAtomic(size_t size); /** * @brief Re-allocates the memory to the size given. @@ -117,10 +137,12 @@ void* PblMallocAtomic(size_t size); * @note Unlike the low-level GC realloc(), this may not be used to malloc or free memory and it will raise a critical * exception if attempted to secure the memory management process */ -void* PblRealloc(void* ptr, size_t size); +void *PblRealloc(void *ptr, size_t size); + +// ---- End of Functions Definitions ---------------------------------------------------------------------------------- #ifdef __cplusplus } #endif -#endif //PBL_MODULES_MEM_H +#endif//PBL_MODULES_MEM_H diff --git a/include/pbl/pbl-main.h b/include/libpbl/pbl-main.h similarity index 55% rename from include/pbl/pbl-main.h rename to include/libpbl/pbl-main.h index af7f87a..eb1f573 100644 --- a/include/pbl/pbl-main.h +++ b/include/libpbl/pbl-main.h @@ -5,20 +5,30 @@ /// @date 2021-11-23 /// @copyright Copyright (c) 2021 -#include -#include -#include +#pragma once + +// Including Headers that are required throughout the entire PBL Library +#ifdef __cplusplus +# include +# include +# include +#else +# include +# include +# include +#endif #ifndef PBL_MODULES_MAIN_H #define PBL_MODULES_MAIN_H -// ---- Main Functions ------------------------------------------------------------------------------------------------ - +// ---- Functions Definitions ----------------------------------------------------------------------------------------- /** * @brief Aborts the current program with the specified 'exit_code' and logs the error message * @param exit_code The exit code that should be used when exiting the program * @param string The string that should be printed out */ -void PblAbortWithCriticalError(int exit_code, const char* string); +void PblAbortWithCriticalError(int exit_code, const char *string); + +// ---- End of Function Definitions ----------------------------------------------------------------------------------- -#endif //PBL_MODULES_MAIN_H +#endif//PBL_MODULES_MAIN_H diff --git a/include/pbl/pbl.h b/include/libpbl/pbl.h similarity index 55% rename from include/pbl/pbl.h rename to include/libpbl/pbl.h index 2c69435..9f2cefa 100644 --- a/include/pbl/pbl.h +++ b/include/libpbl/pbl.h @@ -6,12 +6,24 @@ /// @date 2021-11-23 /// @copyright Copyright (c) 2021 -// lib-headers includes -#include "./pbl-int.h" -#include "./pbl-io.h" -#include "./pbl-string.h" -#include "./pbl-types.h" -#include "./pbl-function.h" +#pragma once + +// Including Headers that are required throughout the entire PBL Library +#ifdef __cplusplus +# include +# include +# include +#else +# include +# include +# include +#endif + +// Main Header Inclusions +#include "./pbl-main.h" + +// Included the additional headers +#include "./additional/va-opt.h" #ifndef PBL_MODULES_LIBRARY_H #define PBL_MODULES_LIBRARY_H @@ -23,14 +35,16 @@ extern "C" { // ---- Macros -------------------------------------------------------------------------------------------------------- /// @brief The current release identifier -#define __parac "0.1.dev6" +#define PBL_VERSION "0.1.dev6" /// @brief Indicates the current library version being a development version -#define __parac_dev true +#define PBL_DEV true /// @brief Indicates the current library version being a stable version -#define __parac_stable false +#define PBL_STABLE false + +// ---- End of Macros ------------------------------------------------------------------------------------------------- #ifdef __cplusplus } #endif -#endif //PBL_MODULES_LIBRARY_H +#endif//PBL_MODULES_LIBRARY_H diff --git a/include/pbl/pbl-any.h b/include/libpbl/types/pbl-any.h similarity index 51% rename from include/pbl/pbl-any.h rename to include/libpbl/types/pbl-any.h index 5ce31a6..64c2250 100644 --- a/include/pbl/pbl-any.h +++ b/include/libpbl/types/pbl-any.h @@ -5,8 +5,11 @@ /// @date 2021-11-23 /// @copyright Copyright (c) 2021 +#pragma once + +// General Required Header Inclusion +#include "./pbl-string.h" #include "./pbl-types.h" -#include "pbl-string.h" #ifndef PBL_INCLUDE_ANY_H #define PBL_INCLUDE_ANY_H @@ -18,43 +21,41 @@ extern "C" { // ---- Exception Implementation -------------------------------------------------------------------------------------- /// @brief (Never use this for malloc - this only indicates the usable memory space) -/// Returns the size in bytes of the PBL Long Double type +/// Returns The usable size in bytes of the PBL Long Double type #define PblAny_T_Size (sizeof(void *) + sizeof(PblString_T *) + sizeof(PblSize_T *)) /// @brief Returns the declaration default for the type 'PblAny_T' -#define PblAny_T_DeclDefault PBL_DECLARATION_CONSTRUCTOR(PblAny_T) -/// @brief Returns the definition default, for the type 'PblAny_T', where the children have not been set yet and only +#define PblAny_T_DeclDefault PBL_TYPE_DECLARATION_DEFAULT_CONSTRUCTOR(PblAny_T) +/// @brief Returns the definition default for the type 'PblAny_T', where the children have not been set yet and only /// the value itself 'exists' already. #define PblAny_T_DefDefault \ - PBL_DEFINITION_STRUCT_CONSTRUCTOR(PblAny_T, .val = NULL, .type_name = NULL, .byte_size = NULL) + PBL_TYPE_DEFINITION_DEFAULT_STRUCT_CONSTRUCTOR(PblAny_T, .val = NULL, .type = NULL, .byte_size = NULL) struct PblAny_Base { - void* val; - PblString_T* type_name; - PblSize_T* byte_size; + void *val; + PblType_T *type; + PblSize_T *byte_size; }; /// @brief Any implementation -struct PblAny PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(struct PblAny_Base); +struct PblAny { PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(struct PblAny_Base); }; /// @brief Any implementation - This type allows for a dynamic allocation and every type to be passed onto the allocated /// memory typedef struct PblAny PblAny_T; -// ---- Helper Functions ---------------------------------------------------------------------------------------------- +// ---- Functions Definitions ----------------------------------------------------------------------------------------- -/** - * @brief Allocates and fetches a new PblAny_T and passes the value onto it - * @param val The void* value that shall be assigned to the PblAny_T type - * @param size The size of the value to properly determine the size and the owned memory - * @return The new PblAny_T - * @note This is a C to Para-C type conversion function - args are in C therefore - */ -PblAny_T* PblGetAnyT(void* val, size_t size); +/// @brief Allocates and fetches a new PblAny_T and passes the value onto it +/// @param val The void* value that shall be assigned to the PblAny_T type +/// @param size The size of the value to properly determine the size and the owned memory +/// @return The new PblAny_T +/// @note This is a C to Para-C type conversion function - args are in C therefore +PblAny_T *PblGetAnyT(void *val, PblType_T *type); -/** - * @brief Force-deallocates the entire any-type - */ +/// @brief Force-deallocates the entire any-type PblVoid_T PblDeallocateAnyType(PblAny_T *val); +// ---- End of Functions Definitions ---------------------------------------------------------------------------------- + #ifdef __cplusplus } #endif diff --git a/include/libpbl/types/pbl-int.h b/include/libpbl/types/pbl-int.h new file mode 100644 index 0000000..20e1190 --- /dev/null +++ b/include/libpbl/types/pbl-int.h @@ -0,0 +1,647 @@ +/// @file pbl-int.h +/// @brief Int Type Implementation based on stdint.h +/// @author Luna-Klatzer +/// @date 2021-11-23 +/// @copyright Copyright (c) 2021 + +#pragma once + +// Including the base which this header intends to implement +#ifdef __cplusplus +# include +#else +# include +#endif + + +// General Required Header Inclusion +#include "./pbl-types.h" + +#ifndef PBL_MODULES_INT_H +#define PBL_MODULES_INT_H + +#ifdef __cplusplus +extern "C" { +#endif + +// ---- Exact Int ----------------------------------------------------------------------------------------------------- + +// ---- Int8 ---------------------------------------------------------------------------------------------------------- + +/// @brief (Never use this for malloc - this only indicates the usable memory space) +/// @returns The usable size in bytes of the PBL Signed Int8 type +#define PblInt8_T_Size sizeof(int8_t) +/// @brief Returns the declaration default for the type 'PblInt8_T' +#define PblInt8_T_DeclDefault PBL_TYPE_DECLARATION_DEFAULT_CONSTRUCTOR(PblInt8_T) +/// @brief Returns the definition default for the type 'PblInt8_T', where the value/the children have not been set yet +/// and only the value itself 'exists' already. If the type is a struct-type, then the children will likely be NULL, +/// initialised to 0 or another Definition Default of another type +#define PblInt8_T_DefDefault PBL_TYPE_DEFINITION_DEFAULT_SIMPLE_CONSTRUCTOR(PblInt8_T, 0) + +/// @brief PBL Int8 implementation +struct PblInt8 { PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(int8_t); }; +/// @brief PBL Signed Int8 implementation +typedef struct PblInt8 PblInt8_T; + +// ---- End of Int8 --------------------------------------------------------------------------------------------------- + +// ---- UInt8 --------------------------------------------------------------------------------------------------------- + +/// @brief (Never use this for malloc - this only indicates the usable memory space) +/// @returns The usable size in bytes of the PBL Signed Long type +#define PblUInt8_T_Size sizeof(uint8_t) +/// @brief Returns the declaration default for the type 'PblUInt8_T' +#define PblUInt8_T_DeclDefault PBL_TYPE_DECLARATION_DEFAULT_CONSTRUCTOR(PblUInt8_T) +/// @brief Returns the definition default for the type 'PblUInt8_T', where the value/the children have not been set yet +/// and only the value itself 'exists' already. If the type is a struct-type, then the children will likely be NULL, +/// initialised to 0 or another Definition Default of another type +#define PblUInt8_T_DefDefault PBL_TYPE_DEFINITION_DEFAULT_SIMPLE_CONSTRUCTOR(PblUInt8_T, 0) + +/// @brief PBL Unsigned Int8 implementation +struct PblUInt8 { PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(uint8_t); }; +/// @brief PBL Unsigned Int8 implementation +typedef struct PblUInt8 PblUInt8_T; + +// ---- End of UInt8 -------------------------------------------------------------------------------------------------- + +// ---- Int16 --------------------------------------------------------------------------------------------------------- + +/// @brief (Never use this for malloc - this only indicates the usable memory space) +/// @returns The usable size in bytes of the PBL Signed Int16 type +#define PblInt16_T_Size sizeof(int16_t) +/// @brief Returns the declaration default for the type 'PblInt16_T' +#define PblInt16_T_DeclDefault PBL_TYPE_DECLARATION_DEFAULT_CONSTRUCTOR(PblInt16_T) +/// @brief Returns the definition default for the type 'PblInt16_T', where the value/the children have not been set yet +/// and only the value itself 'exists' already. If the type is a struct-type, then the children will likely be NULL, +/// initialised to 0 or another Definition Default of another type +#define PblInt16_T_DefDefault PBL_TYPE_DEFINITION_DEFAULT_SIMPLE_CONSTRUCTOR(PblInt16_T, 0) + +/// @brief PBL Int16 implementation +struct PblInt16 { PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(int16_t); }; +/// @brief PBL Signed Int16 implementation +typedef struct PblInt16 PblInt16_T; + +// ---- End of Int16 -------------------------------------------------------------------------------------------------- + +// ---- UInt16 -------------------------------------------------------------------------------------------------------- + +/// @brief (Never use this for malloc - this only indicates the usable memory space) +/// @returns The usable size in bytes of the PBL Signed Long type +#define PblUInt16_T_Size sizeof(uint16_t) +/// @brief Returns the declaration default for the type 'PblUInt16_T' +#define PblUInt16_T_DeclDefault PBL_TYPE_DECLARATION_DEFAULT_CONSTRUCTOR(PblUInt16_T) +/// @brief Returns the definition default for the type 'PblUInt16_T', where the value/the children have not been set yet +/// and only the value itself 'exists' already. If the type is a struct-type, then the children will likely be NULL, +/// initialised to 0 or another Definition Default of another type +#define PblUInt16_T_DefDefault PBL_TYPE_DEFINITION_DEFAULT_SIMPLE_CONSTRUCTOR(PblUInt16_T, 0) + +/// @brief PBL UInt16 implementation +struct PblUInt16 { PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(uint16_t); }; +/// @brief PBL UInt16 implementation +typedef struct PblUInt16 PblUInt16_T; + +// ---- End of UInt16 ------------------------------------------------------------------------------------------------- + +// ---- Int32 --------------------------------------------------------------------------------------------------------- + +/// @brief (Never use this for malloc - this only indicates the usable memory space) +/// @returns The usable size in bytes of the PBL Signed Int32 type +#define PblInt32_T_Size sizeof(int32_t) +/// @brief Returns the declaration default for the type 'PblInt32_T' +#define PblInt32_T_DeclDefault PBL_TYPE_DECLARATION_DEFAULT_CONSTRUCTOR(PblInt32_T) +/// @brief Returns the definition default for the type 'PblInt32_T', where the value/the children have not been set yet +/// and only the value itself 'exists' already. If the type is a struct-type, then the children will likely be NULL, +/// initialised to 0 or another Definition Default of another type +#define PblInt32_T_DefDefault PBL_TYPE_DEFINITION_DEFAULT_SIMPLE_CONSTRUCTOR(PblInt32_T, 0) + +/// @brief PBL Int32 implementation +struct PblInt32 { PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(int32_t); }; +/// @brief PBL Signed Int32 implementation +typedef struct PblInt32 PblInt32_T; + +// ---- End of Int32 -------------------------------------------------------------------------------------------------- + +// ---- UInt32 -------------------------------------------------------------------------------------------------------- + +/// @brief (Never use this for malloc - this only indicates the usable memory space) +/// @returns The usable size in bytes of the PBL Signed Long type +#define PblUInt32_T_Size sizeof(uint32_t) +/// @brief Returns the declaration default for the type 'PblUInt32_T' +#define PblUInt32_T_DeclDefault PBL_TYPE_DECLARATION_DEFAULT_CONSTRUCTOR(PblUInt32_T) +/// @brief Returns the definition default for the type 'PblUInt32_T', where the value/the children have not been set yet +/// and only the value itself 'exists' already. If the type is a struct-type, then the children will likely be NULL, +/// initialised to 0 or another Definition Default of another type +#define PblUInt32_T_DefDefault PBL_TYPE_DEFINITION_DEFAULT_SIMPLE_CONSTRUCTOR(PblUInt32_T, 0) + +/// @brief PBL UInt32 implementation +struct PblUInt32 { PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(uint32_t); }; +/// @brief PBL UInt32 implementation +typedef struct PblUInt32 PblUInt32_T; + +// ---- End of UInt32 ------------------------------------------------------------------------------------------------- + +// ---- Int64 --------------------------------------------------------------------------------------------------------- + +/// @brief (Never use this for malloc - this only indicates the usable memory space) +/// @returns The usable size in bytes of the PBL Signed Int64 type +#define PblInt64_T_Size sizeof(int64_t) +/// @brief Returns the declaration default for the type 'PblInt64_T' +#define PblInt64_T_DeclDefault PBL_TYPE_DECLARATION_DEFAULT_CONSTRUCTOR(PblInt64_T) +/// @brief Returns the definition default for the type 'PblInt64_T', where the value/the children have not been set yet +/// and only the value itself 'exists' already. If the type is a struct-type, then the children will likely be NULL, +/// initialised to 0 or another Definition Default of another type +#define PblInt64_T_DefDefault PBL_TYPE_DEFINITION_DEFAULT_SIMPLE_CONSTRUCTOR(PblInt64_T, 0) + +/// @brief PBL Int64 implementation +struct PblInt64 { PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(int64_t); }; +/// @brief PBL Signed Int64 implementation +typedef struct PblInt64 PblInt64_T; + +// ---- End of Int64 -------------------------------------------------------------------------------------------------- + +// ---- UInt64 -------------------------------------------------------------------------------------------------------- + +/// @brief (Never use this for malloc - this only indicates the usable memory space) +/// @returns The usable size in bytes of the PBL Signed Long type +#define PblUInt64_T_Size sizeof(uint64_t) +/// @brief Returns the declaration default for the type 'PblUInt64_T' +#define PblUInt64_T_DeclDefault PBL_TYPE_DECLARATION_DEFAULT_CONSTRUCTOR(PblUInt64_T) +/// @brief Returns the definition default for the type 'PblUInt64_T', where the value/the children have not been set yet +/// and only the value itself 'exists' already. If the type is a struct-type, then the children will likely be NULL, +/// initialised to 0 or another Definition Default of another type +#define PblUInt64_T_DefDefault PBL_TYPE_DEFINITION_DEFAULT_SIMPLE_CONSTRUCTOR(PblUInt64_T, 0) + +/// @brief PBL UInt64 implementation +struct PblUInt64 { PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(uint64_t); }; +/// @brief PBL UInt64 implementation +typedef struct PblUInt64 PblUInt64_T; + +// ---- End of UInt64 ------------------------------------------------------------------------------------------------- + +// ---- End of Exact Int ---------------------------------------------------------------------------------------------- + +// ---- Least Int ----------------------------------------------------------------------------------------------------- + +// ---- LeastInt8 ----------------------------------------------------------------------------------------------------- + +/// @brief (Never use this for malloc - this only indicates the usable memory space) +/// @returns The usable size in bytes of the PBL Signed LeastInt8 type +#define PblLeastInt8_T_Size sizeof(int_least8_t) +/// @brief Returns the declaration default for the type 'PblLeastInt8_T' +#define PblLeastInt8_T_DeclDefault PBL_TYPE_DECLARATION_DEFAULT_CONSTRUCTOR(PblLeastInt8_T) +/// @brief Returns the definition default for the type 'PblLeastInt8_T', where the value/the children have not been set yet +/// and only the value itself 'exists' already. If the type is a struct-type, then the children will likely be NULL, +/// initialised to 0 or another Definition Default of another type +#define PblLeastInt8_T_DefDefault PBL_TYPE_DEFINITION_DEFAULT_SIMPLE_CONSTRUCTOR(PblLeastInt8_T, 0) + +/// @brief PBL LeastInt8 implementation +struct PblLeastInt8 { PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(int_least8_t); }; +/// @brief PBL Signed LeastInt8 implementation +typedef struct PblLeastInt8 PblLeastInt8_T; + +// ---- End of LeastInt8 ---------------------------------------------------------------------------------------------- + +// ---- ULeastInt8 ---------------------------------------------------------------------------------------------------- + +/// @brief (Never use this for malloc - this only indicates the usable memory space) +/// @returns The usable size in bytes of the PBL Signed Long type +#define PblULeastInt8_T_Size sizeof(uint_least8_t) +/// @brief Returns the declaration default for the type 'PblULeastInt8_T' +#define PblULeastInt8_T_DeclDefault PBL_TYPE_DECLARATION_DEFAULT_CONSTRUCTOR(PblULeastInt8_T) +/// @brief Returns the definition default for the type 'PblULeastInt8_T', where the value/the children have not been set yet +/// and only the value itself 'exists' already. If the type is a struct-type, then the children will likely be NULL, +/// initialised to 0 or another Definition Default of another type +#define PblULeastInt8_T_DefDefault PBL_TYPE_DEFINITION_DEFAULT_SIMPLE_CONSTRUCTOR(PblULeastInt8_T, 0) + +/// @brief PBL ULeastInt8 implementation +struct PblULeastInt8 { PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(uint_least8_t); }; +/// @brief PBL ULeastInt8 implementation +typedef struct PblULeastInt8 PblULeastInt8_T; + +// ---- End of ULeastInt8 --------------------------------------------------------------------------------------------- + +// ---- LeastInt16 ---------------------------------------------------------------------------------------------------- + +/// @brief (Never use this for malloc - this only indicates the usable memory space) +/// @returns The usable size in bytes of the PBL Signed LeastInt16 type +#define PblLeastInt16_T_Size sizeof(int_least16_t) +/// @brief Returns the declaration default for the type 'PblLeastInt16_T' +#define PblLeastInt16_T_DeclDefault PBL_TYPE_DECLARATION_DEFAULT_CONSTRUCTOR(PblLeastInt16_T) +/// @brief Returns the definition default for the type 'PblLeastInt16_T', where the value/the children have not been set yet +/// and only the value itself 'exists' already. If the type is a struct-type, then the children will likely be NULL, +/// initialised to 0 or another Definition Default of another type +#define PblLeastInt16_T_DefDefault PBL_TYPE_DEFINITION_DEFAULT_SIMPLE_CONSTRUCTOR(PblLeastInt16_T, 0) + +/// @brief PBL LeastInt16 implementation +struct PblLeastInt16 { PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(int_least16_t); }; +/// @brief PBL Signed LeastInt16 implementation +typedef struct PblLeastInt16 PblLeastInt16_T; + +// ---- End of PblLeastInt16 ------------------------------------------------------------------------------------------ + +// ---- ULeastInt16 --------------------------------------------------------------------------------------------------- + +/// @brief (Never use this for malloc - this only indicates the usable memory space) +/// @returns The usable size in bytes of the PBL Signed Long type +#define PblULeastInt16_T_Size sizeof(uint_least16_t) +/// @brief Returns the declaration default for the type 'PblULeastInt16_T' +#define PblULeastInt16_T_DeclDefault PBL_TYPE_DECLARATION_DEFAULT_CONSTRUCTOR(PblULeastInt16_T) +/// @brief Returns the definition default for the type 'PblULeastInt16_T', where the value/the children have not been set yet +/// and only the value itself 'exists' already. If the type is a struct-type, then the children will likely be NULL, +/// initialised to 0 or another Definition Default of another type +#define PblULeastInt16_T_DefDefault PBL_TYPE_DEFINITION_DEFAULT_SIMPLE_CONSTRUCTOR(PblULeastInt16_T, 0) + +/// @brief PBL ULeastInt16 implementation +struct PblULeastInt16 { PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(uint_least16_t); }; +/// @brief PBL ULeastInt16 implementation +typedef struct PblULeastInt16 PblULeastInt16_T; + +// ---- End of PblULeastInt16 ----------------------------------------------------------------------------------------- + +// ---- LeastInt32 ---------------------------------------------------------------------------------------------------- + +/// @brief (Never use this for malloc - this only indicates the usable memory space) +/// @returns The usable size in bytes of the PBL Signed LeastInt32 type +#define PblLeastInt32_T_Size sizeof(int_least32_t) +/// @brief Returns the declaration default for the type 'PblLeastInt32_T' +#define PblLeastInt32_T_DeclDefault PBL_TYPE_DECLARATION_DEFAULT_CONSTRUCTOR(PblLeastInt32_T) +/// @brief Returns the definition default for the type 'PblLeastInt32_T', where the value/the children have not been set yet +/// and only the value itself 'exists' already. If the type is a struct-type, then the children will likely be NULL, +/// initialised to 0 or another Definition Default of another type +#define PblLeastInt32_T_DefDefault PBL_TYPE_DEFINITION_DEFAULT_SIMPLE_CONSTRUCTOR(PblLeastInt32_T, 0) + +/// @brief PBL LeastInt32 implementation +struct PblLeastInt32 { PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(int_least32_t); }; +/// @brief PBL LeastInt32 implementation +typedef struct PblLeastInt32 PblLeastInt32_T; + +// ---- End of LeastInt32 --------------------------------------------------------------------------------------------- + +// ---- ULeastInt32 --------------------------------------------------------------------------------------------------- + +/// @brief (Never use this for malloc - this only indicates the usable memory space) +/// @returns The usable size in bytes of the PBL Signed Long type +#define PblULeastInt32_T_Size sizeof(uint_least32_t) +/// @brief Returns the declaration default for the type 'PblULeastInt32_T' +#define PblULeastInt32_T_DeclDefault PBL_TYPE_DECLARATION_DEFAULT_CONSTRUCTOR(PblULeastInt32_T) +/// @brief Returns the definition default for the type 'PblULeastInt32_T', where the value/the children have not been set yet +/// and only the value itself 'exists' already. If the type is a struct-type, then the children will likely be NULL, +/// initialised to 0 or another Definition Default of another type +#define PblULeastInt32_T_DefDefault PBL_TYPE_DEFINITION_DEFAULT_SIMPLE_CONSTRUCTOR(PblULeastInt32_T, 0) + +/// @brief PBL ULeastInt32 implementation +struct PblULeastInt32 { PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(uint_least32_t); }; +/// @brief PBL ULeastInt32 implementation +typedef struct PblULeastInt32 PblULeastInt32_T; + +// ---- End of ULeastInt32 -------------------------------------------------------------------------------------------- + +// ---- LeastInt64 ---------------------------------------------------------------------------------------------------- + +/// @brief (Never use this for malloc - this only indicates the usable memory space) +/// @returns The usable size in bytes of the PBL Signed LeastInt64 type +#define PblLeastInt64_T_Size sizeof(int_least64_t) +/// @brief Returns the declaration default for the type 'PblLeastInt64_T' +#define PblLeastInt64_T_DeclDefault PBL_TYPE_DECLARATION_DEFAULT_CONSTRUCTOR(PblLeastInt64_T) +/// @brief Returns the definition default for the type 'PblLeastInt64_T', where the value/the children have not been set yet +/// and only the value itself 'exists' already. If the type is a struct-type, then the children will likely be NULL, +/// initialised to 0 or another Definition Default of another type +#define PblLeastInt64_T_DefDefault PBL_TYPE_DEFINITION_DEFAULT_SIMPLE_CONSTRUCTOR(PblLeastInt64_T, 0) + +/// @brief PBL LeastInt64 implementation +struct PblLeastInt64 { PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(int_least64_t); }; +/// @brief PBL Signed LeastInt64 implementation +typedef struct PblLeastInt64 PblLeastInt64_T; + +// ---- End of LeastInt64 --------------------------------------------------------------------------------------------- + +// ---- ULeastInt64 --------------------------------------------------------------------------------------------------- + +/// @brief (Never use this for malloc - this only indicates the usable memory space) +/// @returns The usable size in bytes of the PBL Signed Long type +#define PblULeastInt64_T_Size sizeof(uint_least64_t) +/// @brief Returns the declaration default for the type 'PblULeastInt64_T' +#define PblULeastInt64_T_DeclDefault PBL_TYPE_DECLARATION_DEFAULT_CONSTRUCTOR(PblULeastInt64_T) +/// @brief Returns the definition default for the type 'PblULeastInt64_T', where the value/the children have not been set yet +/// and only the value itself 'exists' already. If the type is a struct-type, then the children will likely be NULL, +/// initialised to 0 or another Definition Default of another type +#define PblULeastInt64_T_DefDefault PBL_TYPE_DEFINITION_DEFAULT_SIMPLE_CONSTRUCTOR(PblULeastInt64_T, 0) + +/// @brief PBL ULeastInt64 implementation +struct PblULeastInt64 { PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(uint_least64_t); }; +/// @brief PBL ULeastInt64 implementation +typedef struct PblULeastInt64 PblULeastInt64_T; + +// ---- End of ULeastInt64 -------------------------------------------------------------------------------------------- + +// ---- End of Least Int ---------------------------------------------------------------------------------------------- + +// ---- Fast Int ------------------------------------------------------------------------------------------------------ + +// ---- FastInt8 ------------------------------------------------------------------------------------------------------ + +/// @brief (Never use this for malloc - this only indicates the usable memory space) +/// @returns The usable size in bytes of the PBL Signed FastInt8 type +#define PblFastInt8_T_Size sizeof(int_fast8_t) +/// @brief Returns the declaration default for the type 'PblFastInt8_T' +#define PblFastInt8_T_DeclDefault PBL_TYPE_DECLARATION_DEFAULT_CONSTRUCTOR(PblFastInt8_T) +/// @brief Returns the definition default for the type 'PblFastInt8_T', where the value/the children have not been set yet +/// and only the value itself 'exists' already. If the type is a struct-type, then the children will likely be NULL, +/// initialised to 0 or another Definition Default of another type +#define PblFastInt8_T_DefDefault PBL_TYPE_DEFINITION_DEFAULT_SIMPLE_CONSTRUCTOR(PblFastInt8_T, 0) + +/// @brief PBL FastInt8 implementation +struct PblFastInt8 { PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(int_fast8_t); }; +/// @brief PBL FastInt8 implementation +typedef struct PblFastInt8 PblFastInt8_T; + +// ---- End of FastInt8 ----------------------------------------------------------------------------------------------- + +// ---- UFastInt8 ----------------------------------------------------------------------------------------------------- + +/// @brief (Never use this for malloc - this only indicates the usable memory space) +/// @returns The usable size in bytes of the PBL Signed Long type +#define PblUFastInt8_T_Size sizeof(uint_fast8_t) +/// @brief Returns the declaration default for the type 'PblUFastInt8_T' +#define PblUFastInt8_T_DeclDefault PBL_TYPE_DECLARATION_DEFAULT_CONSTRUCTOR(PblUFastInt8_T) +/// @brief Returns the definition default for the type 'PblUFastInt8_T', where the value/the children have not been set yet +/// and only the value itself 'exists' already. If the type is a struct-type, then the children will likely be NULL, +/// initialised to 0 or another Definition Default of another type +#define PblUFastInt8_T_DefDefault PBL_TYPE_DEFINITION_DEFAULT_SIMPLE_CONSTRUCTOR(PblUFastInt8_T, 0) + +/// @brief PBL UFastInt8 implementation +struct PblUFastInt8 { PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(uint_fast8_t); }; +/// @brief PBL UFastInt8 implementation +typedef struct PblUFastInt8 PblUFastInt8_T; + +// ---- End of UFastInt8 ---------------------------------------------------------------------------------------------- + +// ---- FastInt16 ----------------------------------------------------------------------------------------------------- + +/// @brief (Never use this for malloc - this only indicates the usable memory space) +/// @returns The usable size in bytes of the PBL Signed FastInt16 type +#define PblFastInt16_T_Size sizeof(int_fast16_t) +/// @brief Returns the declaration default for the type 'PblFastInt16_T' +#define PblFastInt16_T_DeclDefault PBL_TYPE_DECLARATION_DEFAULT_CONSTRUCTOR(PblFastInt16_T) +/// @brief Returns the definition default for the type 'PblFastInt16_T', where the value/the children have not been set yet +/// and only the value itself 'exists' already. If the type is a struct-type, then the children will likely be NULL, +/// initialised to 0 or another Definition Default of another type +#define PblFastInt16_T_DefDefault PBL_TYPE_DEFINITION_DEFAULT_SIMPLE_CONSTRUCTOR(PblFastInt16_T, 0) + +/// @brief PBL FastInt16 implementation +struct PblFastInt16 { PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(int_fast16_t); }; +/// @brief PBL Signed FastInt16 implementation +typedef struct PblFastInt16 PblFastInt16_T; + +// ---- End of FastInt16 ---------------------------------------------------------------------------------------------- + +// ---- UFastInt16 ---------------------------------------------------------------------------------------------------- + +/// @brief (Never use this for malloc - this only indicates the usable memory space) +/// @returns The usable size in bytes of the PBL Signed Long type +#define PblUFastInt16_T_Size sizeof(uint_fast16_t) +/// @brief Returns the declaration default for the type 'PblUFastInt16_T' +#define PblUFastInt16_T_DeclDefault PBL_TYPE_DECLARATION_DEFAULT_CONSTRUCTOR(PblUFastInt16_T) +/// @brief Returns the definition default for the type 'PblUFastInt16_T', where the value/the children have not been set yet +/// and only the value itself 'exists' already. If the type is a struct-type, then the children will likely be NULL, +/// initialised to 0 or another Definition Default of another type +#define PblUFastInt16_T_DefDefault PBL_TYPE_DEFINITION_DEFAULT_SIMPLE_CONSTRUCTOR(PblUFastInt16_T, 0) + +/// @brief PBL UFastInt16 implementation +struct PblUFastInt16 { PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(uint_fast16_t); }; +/// @brief PBL UFastInt16 implementation +typedef struct PblUFastInt16 PblUFastInt16_T; + +// ---- End of UFastInt16 --------------------------------------------------------------------------------------------- + +// ---- FastInt32 ----------------------------------------------------------------------------------------------------- + +/// @brief (Never use this for malloc - this only indicates the usable memory space) +/// @returns The usable size in bytes of the PBL Signed FastInt32 type +#define PblFastInt32_T_Size sizeof(int_fast32_t) +/// @brief Returns the declaration default for the type 'PblFastInt32_T' +#define PblFastInt32_T_DeclDefault PBL_TYPE_DECLARATION_DEFAULT_CONSTRUCTOR(PblFastInt32_T) +/// @brief Returns the definition default for the type 'PblFastInt32_T', where the value/the children have not been set yet +/// and only the value itself 'exists' already. If the type is a struct-type, then the children will likely be NULL, +/// initialised to 0 or another Definition Default of another type +#define PblFastInt32_T_DefDefault PBL_TYPE_DEFINITION_DEFAULT_SIMPLE_CONSTRUCTOR(PblFastInt32_T, 0) + +/// @brief PBL FastInt32 implementation +struct PblFastInt32 { PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(int_fast32_t); }; +/// @brief PBL Signed FastInt32 implementation +typedef struct PblFastInt32 PblFastInt32_T; + +// ---- End of FastInt32 ---------------------------------------------------------------------------------------------- + +// ---- UFastInt32 ---------------------------------------------------------------------------------------------------- + +/// @brief (Never use this for malloc - this only indicates the usable memory space) +/// @returns The usable size in bytes of the PBL Signed Long type +#define PblUFastInt32_T_Size sizeof(uint_fast32_t) +/// @brief Returns the declaration default for the type 'PblUFastInt32_T' +#define PblUFastInt32_T_DeclDefault PBL_TYPE_DECLARATION_DEFAULT_CONSTRUCTOR(PblUFastInt32_T) +/// @brief Returns the definition default for the type 'PblUFastInt32_T', where the value/the children have not been set yet +/// and only the value itself 'exists' already. If the type is a struct-type, then the children will likely be NULL, +/// initialised to 0 or another Definition Default of another type +#define PblUFastInt32_T_DefDefault PBL_TYPE_DEFINITION_DEFAULT_SIMPLE_CONSTRUCTOR(PblUFastInt32_T, 0) + +/// @brief PBL UFastInt32 implementation +struct PblUFastInt32 { PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(uint_fast32_t); }; +/// @brief PBL UFastInt32 implementation +typedef struct PblUFastInt32 PblUFastInt32_T; + +// ---- End of UFastInt32 --------------------------------------------------------------------------------------------- + +// ---- FastInt64 ----------------------------------------------------------------------------------------------------- + +/// @brief (Never use this for malloc - this only indicates the usable memory space) +/// @returns The usable size in bytes of the PBL Signed FastInt64 type +#define PblFastInt64_T_Size sizeof(int_fast64_t) +/// @brief Returns the declaration default for the type 'PblFastInt64_T' +#define PblFastInt64_T_DeclDefault PBL_TYPE_DECLARATION_DEFAULT_CONSTRUCTOR(PblFastInt64_T) +/// @brief Returns the definition default for the type 'PblFastInt64_T', where the value/the children have not been set yet +/// and only the value itself 'exists' already. If the type is a struct-type, then the children will likely be NULL, +/// initialised to 0 or another Definition Default of another type +#define PblFastInt64_T_DefDefault PBL_TYPE_DEFINITION_DEFAULT_SIMPLE_CONSTRUCTOR(PblFastInt64_T, 0) + +/// @brief PBL FastInt64 implementation +struct PblFastInt64 { PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(int_fast64_t); }; +/// @brief PBL Signed FastInt64 implementation +typedef struct PblFastInt64 PblFastInt64_T; + +// ---- End of FastInt64 ---------------------------------------------------------------------------------------------- + +// ---- UFastInt64 ---------------------------------------------------------------------------------------------------- + +/// @brief (Never use this for malloc - this only indicates the usable memory space) +/// @returns The usable size in bytes of the PBL Signed Long type +#define PblUFastInt64_T_Size sizeof(uint_fast64_t) +/// @brief Returns the declaration default for the type 'PblUFastInt64_T' +#define PblUFastInt64_T_DeclDefault PBL_TYPE_DECLARATION_DEFAULT_CONSTRUCTOR(PblUFastInt64_T) +/// @brief Returns the definition default for the type 'PblUFastInt64_T', where the value/the children have not been set yet +/// and only the value itself 'exists' already. If the type is a struct-type, then the children will likely be NULL, +/// initialised to 0 or another Definition Default of another type +#define PblUFastInt64_T_DefDefault PBL_TYPE_DEFINITION_DEFAULT_SIMPLE_CONSTRUCTOR(PblUFastInt64_T, 0) + +/// @brief PBL UFastInt64 implementation +struct PblUFastInt64 { PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(uint_fast64_t); }; +/// @brief PBL UFastInt64 implementation +typedef struct PblUFastInt64 PblUFastInt64_T; + +// ---- End of UFastInt64 --------------------------------------------------------------------------------------------- + +// ---- End of Fast Int ----------------------------------------------------------------------------------------------- + +// ---- Functions Definitions ----------------------------------------------------------------------------------------- + +/// @brief Converts the low level C-Type to a PBL Int8 type +/// @param val The C-type to be converted +/// @return The newly created PBL Int8 type +/// @note This is a C to Para-C type conversion function - args are in C therefore +__attribute__((unused)) PblInt8_T *PblGetInt8T(int8_t val); + +/// @brief Converts the low level C-Type to a PBL UInt8 type +/// @param val The C-type to be converted +/// @return The newly created PBL UInt8 type +/// @note This is a C to Para-C type conversion function - args are in C therefore +__attribute__((unused)) PblUInt8_T *PblGetUInt8T(uint8_t val); + +/// @brief Converts the low level C-Type to a PBL Int16 type +/// @param val The C-type to be converted +/// @return The newly created PBL Int16 type +/// @note This is a C to Para-C type conversion function - args are in C therefore +__attribute__((unused)) PblInt16_T *PblGetInt16T(int16_t val); + +/// @brief Converts the low level C-Type to a PBL UInt16 type +/// @param val The C-type to be converted +/// @return The newly created PBL UInt16 type +/// @note This is a C to Para-C type conversion function - args are in C therefore +__attribute__((unused)) PblUInt16_T *PblGetUInt16T(uint16_t val); + +/// @brief Converts the low level C-Type to a PBL Int32 type +/// @param val The C-type to be converted +/// @return The newly created PBL Int32 type +/// @note This is a C to Para-C type conversion function - args are in C therefore +__attribute__((unused)) PblInt32_T *PblGetInt32T(int32_t val); + +/// @brief Converts the low level C-Type to a PBL UInt32 type +/// @param val The C-type to be converted +/// @return The newly created PBL UInt32 type +/// @note This is a C to Para-C type conversion function - args are in C therefore +__attribute__((unused)) PblUInt32_T *PblGetUInt32T(uint32_t val); + +/// @brief Converts the low level C-Type to a PBL Int64 type +/// @param val The C-type to be converted +/// @return The newly created PBL Int64 type +/// @note This is a C to Para-C type conversion function - args are in C therefore +__attribute__((unused)) PblInt64_T *PblGetInt64T(int64_t val); + +/// @brief Converts the low level C-Type to a PBL UInt64 type +/// @param val The C-type to be converted +/// @return The newly created PBL UInt64 type +/// @note This is a C to Para-C type conversion function - args are in C therefore +__attribute__((unused)) PblUInt64_T *PblGetUInt64T(uint64_t val); + +/// @brief Converts the low level C-Type to a PBL LeastInt8 type +/// @param val The C-type to be converted +/// @return The newly created PBL LeastInt8 type +/// @note This is a C to Para-C type conversion function - args are in C therefore +__attribute__((unused)) PblLeastInt8_T *PblGetLeastInt8T(int_least8_t val); + +/// @brief Converts the low level C-Type to a PBL ULeastInt8 type +/// @param val The C-type to be converted +/// @return The newly created PBL ULeastInt8 type +/// @note This is a C to Para-C type conversion function - args are in C therefore +__attribute__((unused)) PblULeastInt8_T *PblGetULeastInt8T(uint_least8_t val); + +/// @brief Converts the low level C-Type to a PBL LeastInt16 type +/// @param val The C-type to be converted +/// @return The newly created PBL LeastInt16 type +/// @note This is a C to Para-C type conversion function - args are in C therefore +__attribute__((unused)) PblLeastInt16_T *PblGetLeastInt16T(int_least16_t val); + +/// @brief Converts the low level C-Type to a PBL ULeastInt16 type +/// @param val The C-type to be converted +/// @return The newly created PBL ULeastInt16 type +/// @note This is a C to Para-C type conversion function - args are in C therefore +__attribute__((unused)) PblULeastInt16_T *PblGetULeastInt16T(uint_least16_t val); + +/// @brief Converts the low level C-Type to a PBL LeastInt32 type +/// @param val The C-type to be converted +/// @return The newly created PBL LeastInt32 type +/// @note This is a C to Para-C type conversion function - args are in C therefore +__attribute__((unused)) PblLeastInt32_T *PblGetLeastInt32T(int_least32_t val); + +/// @brief Converts the low level C-Type to a PBL ULeastInt32 type +/// @param val The C-type to be converted +/// @return The newly created PBL ULeastInt32 type +/// @note This is a C to Para-C type conversion function - args are in C therefore +__attribute__((unused)) PblULeastInt32_T *PblGetULeastInt32T(uint_least32_t val); + +/// @brief Converts the low level C-Type to a PBL LeastInt64 type +/// @param val The C-type to be converted +/// @return The newly created PBL LeastInt64 type +/// @note This is a C to Para-C type conversion function - args are in C therefore +__attribute__((unused)) PblLeastInt64_T *PblGetLeastInt64T(int_least64_t val); + +/// @brief Converts the low level C-Type to a PBL ULeastInt64 type +/// @param val The C-type to be converted +/// @return The newly created PBL ULeastInt64 type +/// @note This is a C to Para-C type conversion function - args are in C therefore +__attribute__((unused)) PblULeastInt64_T *PblGetULeastInt64T(uint_least64_t val); + +/// @brief Converts the low level C-Type to a PBL FastInt8 type +/// @param val The C-type to be converted +/// @return The newly created PBL FastInt8 type +/// @note This is a C to Para-C type conversion function - args are in C therefore +__attribute__((unused)) PblFastInt8_T *PblGetFastInt8T(int_fast8_t val); + +/// @brief Converts the low level C-Type to a PBL UFastInt8 type +/// @param val The C-type to be converted +/// @return The newly created PBL UFastInt8 type +/// @note This is a C to Para-C type conversion function - args are in C therefore +__attribute__((unused)) PblUFastInt8_T *PblGetUFastInt8T(uint_fast8_t val); + +/// @brief Converts the low level C-Type to a PBL FastInt16 type +/// @param val The C-type to be converted +/// @return The newly created PBL FastInt16 type +/// @note This is a C to Para-C type conversion function - args are in C therefore +__attribute__((unused)) PblFastInt16_T *PblGetFastInt16T(int_fast16_t val); + +/// @brief Converts the low level C-Type to a PBL UFastInt16 type +/// @param val The C-type to be converted +/// @return The newly created PBL UFastInt16 type +/// @note This is a C to Para-C type conversion function - args are in C therefore +__attribute__((unused)) PblUFastInt16_T *PblGetUFastInt16T(uint_fast16_t val); + +/// @brief Converts the low level C-Type to a PBL FastInt32 type +/// @param val The C-type to be converted +/// @return The newly created PBL FastInt32 type +/// @note This is a C to Para-C type conversion function - args are in C therefore +__attribute__((unused)) PblFastInt32_T *PblGetFastInt32T(int_fast32_t val); + +/// @brief Converts the low level C-Type to a PBL UFastInt32 type +/// @param val The C-type to be converted +/// @return The newly created PBL UFastInt32 type +/// @note This is a C to Para-C type conversion function - args are in C therefore +__attribute__((unused)) PblUFastInt32_T *PblGetUFastInt32T(uint_fast32_t val); + +/// @brief Converts the low level C-Type to a PBL FastInt64 type +/// @param val The C-type to be converted +/// @return The newly created PBL FastInt64 type +/// @note This is a C to Para-C type conversion function - args are in C therefore +__attribute__((unused)) PblFastInt64_T *PblGetFastInt64T(int_fast64_t val); + +/// @brief Converts the low level C-Type to a PBL UFastInt64 type +/// @param val The C-type to be converted +/// @return The newly created PBL UFastInt64 type +/// @note This is a C to Para-C type conversion function - args are in C therefore +__attribute__((unused)) PblUFastInt64_T *PblGetUFastInt64T(uint_fast64_t val); + +// ---- End of Functions Definitions ---------------------------------------------------------------------------------- + +#ifdef __cplusplus +} +#endif + +#endif//PBL_MODULES_INT_H diff --git a/include/libpbl/types/pbl-string.h b/include/libpbl/types/pbl-string.h new file mode 100644 index 0000000..1b6f830 --- /dev/null +++ b/include/libpbl/types/pbl-string.h @@ -0,0 +1,148 @@ +/// @file pbl-string.h +/// @brief String Implementation based on dynamic memory allocation - This is an optimised form of char[], which is +/// though not equal to PblChar_T[], as it does not contain meta-data tracking for each char, but altogether as an +/// entire type to save memory. +/// @author Luna-Klatzer +/// @date 2021-11-23 +/// @copyright Copyright (c) 2021 + +#pragma once + +// Including the base which this header intends to implement +#ifdef __cplusplus +# include +#else +# include +#endif + +// General Required Header Inclusion +#include "./pbl-types.h" + +#ifndef PBL_MODULES_STRING_H +#define PBL_MODULES_STRING_H + +#ifdef __cplusplus +extern "C" { +#endif + +// ---- Declaration --------------------------------------------------------------------------------------------------- + +/// @brief Size of the type 'PblString_T' in bytes +#define PblString_T_Size (sizeof(PblSize_T *) + sizeof(PblUInt_T *) + sizeof(PblUInt_T *) + sizeof(char *)) +/// @brief Returns the declaration default for the type 'PblString_T' +#define PblString_T_DeclDefault PBL_TYPE_DECLARATION_DEFAULT_CONSTRUCTOR(PblString_T) +/// @brief Returns the definition default for the type 'PblString_T', where the children have not been set yet and +/// only the value itself 'exists' already. +#define PblString_T_DefDefault \ + PBL_TYPE_DEFINITION_DEFAULT_STRUCT_CONSTRUCTOR(PblString_T, .allocated_len = NULL, .len = NULL, .str = NULL) + +/// @brief Base Struct of PblString - avoid using this type +struct PblString_Base { + /// @brief Amount of the chars that can be written to - includes null char (\0). This does not include the meta info + PblUInt_T *allocated_len; + /// @brief The length of the string - this is the length that it will take to reach the null character '\0' + PblUInt_T *len; + /// @brief The char* pointer to the allocated memory - the entire memory represents the array, meaning it's not an + /// array of PblChar_T pointers, but an actual block of PblChar_T types being stuck together in memory, meaning array + /// arithmetics are valid! + PblChar_T *str; +}; + +/// @brief PBL String implementation - uses dynamic memory allocation -> located in heap +struct PblString { PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(struct PblString_Base) }; +typedef struct PblString PblString_T; + +// ---- End of Declaration -------------------------------------------------------------------------------------------- + +// ---- Functions Definitions ----------------------------------------------------------------------------------------- + +/// @brief Gets the Length of a C string (const char*) +/// @param content The char array (pointer) +/// @return The length as Para-C Int +PblUInt_T *PblGetLengthOfCString(const char *content); + +/// @brief Converts the passed char* array to a PblChar_T array +/// @param content The C char array +/// @param len The length that shall be used to initialise the array. This length must be exact! +/// @return The newly allocated string +/// @note This is a C to Para-C type conversion function - args are in C therefore +PblChar_T *PblGetCharTArray(const char *content); + +/// @brief This directly converts a char* to a Para-C string type +/// @param content The char array (pointer) +/// @return The new Para-C string type, which was created using 'PblAllocateStringContentT' +/// @note This is a C to Para-C type conversion function - args are in C therefore +PblString_T *PblGetStringT(const char *content); + +/// @brief Compares the two passed strings and returns whether they are equal +/// @param str_1 The first string +/// @param str_2 The second string +/// @return True if both strings are equal and the content does not differ, else false +PblBool_T *PblCompareStringT(PblString_T *str_1, PblString_T *str_2); + +/// @brief Gets the required minimum array size for the string +/// @param len The length of the string that should be allocated +/// @return The length as PblUInt_T +PblUInt_T *PblGetMinimumArrayLen(PblUInt_T *len); + +/// @brief Gets the required byte_size for an allocation based on the passed length of the string. +/// @note The algorithm will always be a multiple of 50 + 1 (for null char '\0'). +/// The calculated size is the next biggest multiple of 50 + 1, which is still bigger than the passed length. +/// @param len The length of the actual string content, which will be used to calculate the allocation length. +/// @returns The size as size_t (int) +PblSize_T *PblGetAllocSizeStringT(PblUInt_T *len); + +/// @brief Resizes the string by reallocating the memory. +/// @note Automatically calculates the size of the new allocated memory based on the length. The function used for the +/// length calculation is 'PblGetAllocSizeStringT' +/// @param str The string that should be reallocated +/// @param len The length of the string content that is used to calculate the required size +PblVoid_T PblResizeStringT(PblString_T *str, PblUInt_T *len); + +/// @brief Converts the passed PblChar_T array into a native C char array +/// @param str The string that should be used +/// @return The char* array +char *PblGetCCharArrayFromCharT(PblChar_T *char_arr, PblUInt_T *len); + +/// @brief Converts the passed string into a native C char array +/// @param str The string that should be used +/// @return The char* array +char *PblGetCCharArrayFromString(PblString_T *str); + +/// @brief Writes onto the allocated memory the passed string content (PblChar_T) +/// @param len Length of the string (should not include null char) +/// @param content The content of the string that should be written to the allocated memory - C type as this should be +/// used in the back of the program +PblVoid_T PblWriteCharArrayToStringT(PblString_T *str, PblChar_T *content, PblUInt_T *len_to_write); + +/// @brief Writes onto the allocated memory the passed string content +/// @param len Length of the string (should not include null char) +/// @param content The content of the string that should be written to the allocated memory - C type as this should be +/// used in the back of the program +PblVoid_T PblWriteStringToStringT(PblString_T *str, PblString_T *content, PblUInt_T *len_to_write); + +/// @brief Allocates new memory for a new string +/// @note Default size/len is 50 - will be resized with additional space required using 'PblGetAllocSizeStringT' +/// @param len Length of the string - will be used to calculate allocated memory space (should not include null char) +/// @param content The content of the string that should be written to the allocated memory - C type as this should be +/// used for converting char/// and char[] to PblString_T +/// @returns The new string type that was allocated +PblString_T *PblCreateStringT(PblChar_T *content, PblUInt_T *len); + +/// @brief Allocates new memory for a new string - this function automatically calculates the minimum allocation size +/// @param byte_size The byte_size that should be allocated +/// @returns The char* pointer to the memory +PblChar_T *PblAllocateStringContentT(PblUInt_T *len); + +/// @brief Deallocates the entire memory for the string and resets it's struct properties +/// @note Writes to the string with '\0' before freeing the memory +/// @param lvalue The value that should be de-allocated +PblVoid_T PblDeallocateStringT(PblString_T *lvalue); + +// ---- End of Functions Definitions ---------------------------------------------------------------------------------- + +#ifdef __cplusplus +} +#endif + +#endif//PBL_MODULES_STRING_H diff --git a/include/libpbl/types/pbl-types.h b/include/libpbl/types/pbl-types.h new file mode 100644 index 0000000..b0b69f3 --- /dev/null +++ b/include/libpbl/types/pbl-types.h @@ -0,0 +1,743 @@ +/// @file pbl-types.h +/// @brief Para-C Base Types Implementation, which contains handler macros, conversion functions, default declaration, +/// default definition types and default size macros. This also includes meta-data tracking based on the +/// 'PblMetaVarCtx_T' type. +/// @author Luna-Klatzer +/// @date 2021-11-23 +/// @copyright Copyright (c) 2021 + +#pragma once + +// Including the base , and which this header intends to utilise and paritally +// implement +#ifdef __cplusplus +# include +# include +#else +# include +# include +# include +#endif + + +// General Required Header Inclusion +#include "../additional/va-opt.h" +#include "../mem/pbl-mem.h" + +#ifndef PBL_MODULES_TYPES_H +#define PBL_MODULES_TYPES_H + +#ifdef __cplusplus +extern "C" { +#endif + +// ---- Meta Types ---------------------------------------------------------------------------------------------------- + +/// @brief The Type type, which is used as a meta-type for tracking of types in types like 'PblAny_T' and to allow for +/// dynamic casting, conversion and type checking. +struct PblType { + /// @brief The size of the variable, which is stored *once*. This allows for dynamic size checking on runtime + /// @note For optimisation always prefer to use the macro 'type##_Size' + size_t actual_size; + /// @brief The usable size that may be utilised + size_t usable_size; + /// @brief The default template that should be used to initialise a new type from. + const void *type_template; + /// @brief The unique identifier for the type, that will be used to compare against. This is null char (\0) + /// terminated. + /// @note This is not a mangled identifier + const char *name; + /// @brief If the type is user defined and not a built-in + bool user_defined; + /// @brief If this type may be defined / converted to + bool definable; +}; + +/// @brief The Type type, which is used as a meta-type for tracking of types in types like 'PblAny_T' and to allow for +/// dynamic casting, conversion and type checking. +typedef struct PblType PblType_T; + +/// @brief Base Meta Type contained in ALL variables - has no DeclDefault or DefDefault +struct PblVarMetaData { + /// @brief Is true when the variable is defined (not declared). This variable is used to also validate whether a + /// variable's memory can be accessed without raising an error! + bool defined; + /// @brief The size of the variable, which is defined by the 'PblTypeMeta_T' global type + PblType_T *type; +}; + +/// @brief Base Meta Type contained in ALL variables - has no DeclDefault or DefDefault +typedef struct PblVarMetaData PblVarMetaData_T; + +// ---- End of Meta Types --------------------------------------------------------------------------------------------- + +// ---- Type List ----------------------------------------------------------------------------------------------------- + +/// @brief (Never use this for malloc - this only indicates the usable memory space) +/// @returns The usable size in bytes of the PBL Type Dict +#define PblTypeList_T_Size sizeof(void*) +/// @returns The declaration default for the type 'PblTypeList_T' +#define PblTypeList_T_DeclDefault (PblTypeList_T) {} +/// @returns The definition default for the type 'PblTypeList_T', where the value/the children have not been set yet +/// and only the value itself 'exists' already. If the type is a struct-type, then the children will likely be NULL, +/// initialised to 0 or another Definition Default of another type +#define PblTypeList_T_DefDefault (PblTypeList_T) { .alloc_len=0, .t_amount = 0, .t_items = NULL } + +/// @brief A type list storing pointers to data-types +struct PblTypeList { + /// @brief The actual allocated length + int alloc_len; + /// @brief The amount of items stored + int t_amount; + /// @brief A list of pointers, which point to the types + const PblType_T** t_items; +}; + +/// @brief A type list storing pointers to data-types +/// @note This will be used in each Para-C file to keep track of all types, and allow for more advanced dynamic type +/// fetching and handling without having to deal with name mangling +typedef struct PblTypeList PblTypeList_T; + +/// @brief Allocates and creates a new type signature based on the passed arguments +/// @returns The newly allocated type +const PblType_T *PblCreateNewType(const size_t size, const void *type_template, const char *name, + const bool user_defined, const bool definable); + +/// @brief Adds a new type to the type list by adding a new pointer which points to the type +void PblAddTypeToTypeList(PblTypeList_T* list, const PblType_T* type); + +void PblInitTypeList(PblTypeList_T* list); + +/// @brief Initialises the local types by making the function 'PBL_CONSTRUCTOR_TYPES_INIT' callable on startup +/// @note The function 'PBL_CONSTRUCTOR_TYPES_INIT' must be defined in an object file (included .c source file) and is +/// only called on startup +#define LOCAL_TYPE_LIST_CONSTRUCTOR \ + __attribute__((unused)) __attribute__((constructor(102))) \ + __attribute__((deprecated("Compiler-Only Function - User Call Invalid!"))) \ + static void PBL_CONSTRUCTOR_TYPES_INIT(void) + +/// @brief Simple Wrapper for the functions 'PblCreateNewType' and 'PblAddTypeToTypeList', which pre-populates the +/// arguments size and type_template by using 'sizeof()' and '_DefDefault' +/// @note This macro function should only be used inside 'PBL_INIT_LOCAL_TYPES' blocks, as it intends to register types +/// before starting execution +#define PBL_REGISTER_LOCAL_TYPE(list, type, name, user_defined, definable) \ + type *type##_DefaultTemplate = PblMalloc(sizeof(type)); \ + *type##_DefaultTemplate = type##_DefDefault; \ + PblAddTypeToTypeList(list, PblCreateNewType(sizeof(type), type##_DefaultTemplate, name, user_defined, definable)); + +/// @brief Creates the local type list and initialises it for the local file. This also will create a local +/// constructor function for initialising the list on runtime. +#define PBL_INIT_LOCAL_TYPE_LIST \ + __attribute__((unused)) static bool LOCAL_TYPE_TRACKING_INITIALISED = false; \ + __attribute__((unused)) static PblTypeList_T LOCAL_TYPE_LIST = PblTypeList_T_DefDefault; \ + __attribute__((unused)) __attribute__((constructor(101))) \ + __attribute__((deprecated("Compiler-Only Function - User Call Invalid!"))) \ + static void PBL_CONSTRUCTOR_TYPES_LIST_INIT(void) { \ + PblInitTypeList(&LOCAL_TYPE_LIST); LOCAL_TYPE_TRACKING_INITIALISED = true; \ + } + +// ---- End of Type List ---------------------------------------------------------------------------------------------- + +// ---- General Type Handling Macros ---------------------------------------------------------------------------------- + +#define PBL_CLEANUP(func) __attribute__((__cleanup__(func))) + +/// @brief This macro initialises an actual instance of a type, instead of allocating it, like the GetTypeT functions, +/// and passes it onto the "to_write" variable. +/// @note This should only be used when wanting the actual type itself written onto a variable +#define PBL_ASSIGN_TO_VAR(to_write, type, write_val) \ + (to_write) = type##_DefDefault; \ + (to_write).actual = write_val; + +// Use auto with C++ +#ifdef __cplusplus +/// @brief This macro allocates an empty declaration instance of a type, which has no actual value set yet +/// @note This should only be used when creating a declaration of a Para-C type +#define PBL_DECLARE_VAR(var_identifier, type, cleanup...) \ + auto *var_identifier IFN(cleanup)(PBL_CLEANUP(cleanup)) = (type *) PblMalloc(sizeof(type)); \ + *(var_identifier) = type##_DeclDefault; + +/// @brief This macro allocates an instance of type, which has the default initialisation value set +/// @note This should only be used when creating a definition that shall be empty - if it's though a conversion from C +/// to Para-C the defined GetTypeT(...) function should be used, which will properly allocate and write to the variable +#define PBL_DEFINE_VAR(var_identifier, type, cleanup...) \ + auto *var_identifier IFN(cleanup)(PBL_CLEANUP(cleanup)) = (type *) PblMalloc(sizeof(type)); \ + *(var_identifier) = type##_DefDefault; + +/// @brief This macro should serve as a helper for writing static arrays that shall be used to store types +/// @note This should not be used as a replacement to PblIterable_T, but only as a memory-efficient helper for copying +/// or setting memory values +#define PBL_CREATE_NEW_ARRAY(to_write, type, length, cleanup...) \ + auto *to_write IFN(cleanup)(PBL_CLEANUP(cleanup)) = (type *) PblMalloc(sizeof(type) * (length)); \ + for (int i = 0; i < (length); i++) { \ + (to_write)[i] = type##_DefDefault; \ + } +#else +/// @brief This macro allocates an empty declaration instance of a type, which has no actual value set yet +/// @note This should only be used when creating a declaration of a Para-C type +#define PBL_DECLARE_VAR(var_identifier, type, cleanup...) \ + type *var_identifier IFN(cleanup)(PBL_CLEANUP(cleanup)) = (type *) PblMalloc(sizeof(type)); \ + *(var_identifier) = type##_DeclDefault; + +/// @brief This macro allocates an instance of type, which has the default initialisation value set +/// @note This should only be used when creating a definition that shall be empty - if it's though a conversion from C +/// to Para-C the defined GetTypeT(...) function should be used, which will properly allocate and write to the variable +#define PBL_DEFINE_VAR(var_identifier, type, cleanup...) \ + type *var_identifier IFN(cleanup)(PBL_CLEANUP(cleanup)) = (type *) PblMalloc(sizeof(type)); \ + *(var_identifier) = type##_DefDefault; + +/// @brief This macro should serve as a helper for writing static arrays that shall be used to store types +/// @note This should not be used as a replacement to PblIterable_T, but only as a memory-efficient helper for copying +/// or setting memory values +#define PBL_CREATE_NEW_ARRAY(to_write, type, length, cleanup...) \ + type *to_write IFN(cleanup)(PBL_CLEANUP(cleanup)) = (type *) PblMalloc(sizeof(type) * (length)); \ + for (int i = 0; i < (length); i++) { \ + (to_write)[i] = type##_DefDefault; \ + } +#endif + +// ---- End of General Type Handling Macros --------------------------------------------------------------------------- + +// ---- Constructor Macros -------------------------------------------------------------------------------------------- + +/// @brief Declaration constructor which initialised the meta data for the passed type +#define PBL_TYPE_DECLARATION_DEFAULT_CONSTRUCTOR(type) \ + (type) { .meta = {.defined = false } } + +/// @brief Definition constructor, which initialises the meta data for the passed type and passes to '.actual' the args +/// as struct +#define PBL_TYPE_DEFINITION_DEFAULT_STRUCT_CONSTRUCTOR(type, ...) \ + (type) { .meta = {.defined = true}, .actual = { __VA_ARGS__ } } + +/// @brief Definition constructor, which initialised the meta data for the passed type and passes to '.actual' the +/// single arg +#define PBL_TYPE_DEFINITION_DEFAULT_SIMPLE_CONSTRUCTOR(type, var_actual...) \ + (type) { .meta = {.defined = true}, .actual = var_actual } + +/// @brief Creates the body for a Para-C type definition wrapper - the base_type is the actual value/struct +#define PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(base_type) \ + PblVarMetaData_T meta; \ + base_type actual; \ + + +// ---- End of Constructor Macros ------------------------------------------------------------------------------------- + +// ---- Local Variable state Saving ----------------------------------------------------------------------------------- + +/// @brief Copies the passed value to a local state copy - This is designed for pointers losing their addresses +/// @note There may only be a single value copy with this unique_id! +/// @param var The variable to copy from +/// @param type The POINTER type to assign the address to +/// @param unique_id The unique_id to separate the local copies from each other +#define PBL_CREATE_ADDRESS_COPY(var, type, unique_id) type unique_id##_localcpy = var; + +/// @brief Writes back to the original variable the state copy - This is designed for pointers losing their addresses +/// @note If the var is NULL, then the address will be restored +/// @param var The pointer to the variable that should be written to +/// @param type +#define PBL_WRITE_BACK_ADDRESS_COPY(var_pointer, unique_id) \ + if ((var_pointer) == NULL) { \ + (var_pointer) = unique_id##_localcpy; \ + unique_id##_localcpy = NULL; \ + } + +// ---- End of Local Variable state Saving --------------------------------------------------------------------------- + +// ---- Sizeof -------------------------------------------------------------------------------------------------------- + +/// @brief Returns the usable size of a Para-C type that can be actually used +/// @param var The variable to get the size from +/// @note This type must be a Para-C type +#define PBL_SIZEOF_USABLE(type) (type##_Size) + +/// @brief Returns the full allocation size of a Para-C type. This also includes meta data +/// @param var The variable to get the size from +/// @note This type must be a Para-C type +#define PBL_SIZEOF_FULL(type) (sizeof(type)) + +/// @brief Returns the full allocation size of a Para-C type, which has been defined dynamically. +/// This also includes meta data +/// @param var The variable to get the size from +/// @note This type must be a Para-C type +#define PBL_SIZEOF_FULL_ON_RUNTIME(var) var->meta.type->actual_size + +/// @brief Returns the usable size of a Para-C type, which has been defined dynamically +/// @param var The variable to get the size from +/// @note This type must be a Para-C type +#define PBL_SIZEOF_USABLE_ON_RUNTIME(var) var->meta.type->usable_size + +// ---- End of Sizeof ------------------------------------------------------------------------------------------------- + +// ---- Pointer Type -------------------------------------------------------------------------------------------------- + +/// @brief (Never use this for malloc - this only indicates the usable memory space) +/// @returns The usable size in bytes of the PBL Bool type +#define PblPointer_T_Size sizeof(void*) +/// @returns The declaration default for the type 'PblPointer_T' +#define PblPointer_T_DeclDefault PBL_TYPE_DECLARATION_DEFAULT_CONSTRUCTOR(PblPointer_T) +/// @returns The definition default for the type 'PblPointer_T', where the value/the children have not been set yet +/// and only the value itself 'exists' already. If the type is a struct-type, then the children will likely be NULL, +/// initialised to 0 or another Definition Default of another type +#define PblPointer_T_DefDefault PBL_TYPE_DEFINITION_DEFAULT_SIMPLE_CONSTRUCTOR(PblPointer_T, {.p_type=NULL,.p_void=NULL}) + +/// @brief The base pointer type, implemented with 'PblPointer_T' +/// @note If the p_void is NULL, then the type is also NULL +struct PblPointer_Base { + /// @brief The type of the pointer + PblType_T* p_type; + /// @brief The actual pointer to the type + void* p_void; +}; + +/// @brief This the general purpose pointer struct, which utilises 'PblType_T' to be differentiated +struct PblPointer { PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(struct PblPointer_Base); }; + +/// @brief This the general purpose pointer type, which utilises 'PblType_T' to be differentiated +typedef struct PblPointer PblPointer_T; + +// ---- End of Pointer Type ------------------------------------------------------------------------------------------- + +// ---- Void Type ----------------------------------------------------------------------------------------------------- + +/// @brief (Never use this for malloc - this only indicates the usable memory space) +/// @returns The usable size in bytes of the PBL PblVoid_T type +#define PblVoid_T_Size 0 +/// @brief Returns the declaration default for the type 'PblVoid_T' +#define PblVoid_T_DeclDefault PBL_TYPE_DECLARATION_DEFAULT_CONSTRUCTOR(PblVoid_T) +/// @brief Returns the definition default for the type 'PblVoid_T' +/// @note This type actually does not allow any definition, so using it as such is invalid +#define PblVoid_T_DefDefault PblVoid_T_DeclDefault + +/// @brief PBL Void implementation +struct PblVoid { + /// @brief Meta-data tracking, as this value will never have anything accessible + PblVarMetaData_T meta; +}; +/// @brief PBL Void implementation +typedef struct PblVoid PblVoid_T; + +// ---- End of Void Type ---------------------------------------------------------------------------------------------- + +// ---- Numeric Types ------------------------------------------------------------------------------------------------- +// All types that are not unsigned are signed by default to ensure consistency +// Note that in those definitions the size is calculated using the C-type (as only one "real" property is there) + +// ---- Bool ---------------------------------------------------------------------------------------------------------- + +/// @brief (Never use this for malloc - this only indicates the usable memory space) +/// @returns The usable size in bytes of the PBL Bool type +#define PblBool_T_Size sizeof(bool) +/// @returns The declaration default for the type 'PblBool_T' +#define PblBool_T_DeclDefault PBL_TYPE_DECLARATION_DEFAULT_CONSTRUCTOR(PblBool_T) +/// @returns The definition default for the type 'PblBool_T', where the value/the children have not been set yet +/// and only the value itself 'exists' already. If the type is a struct-type, then the children will likely be NULL, +/// initialised to 0 or another Definition Default of another type +#define PblBool_T_DefDefault PBL_TYPE_DEFINITION_DEFAULT_SIMPLE_CONSTRUCTOR(PblBool_T, false) + +/// @brief PBL Bool implementation +struct PblBool { PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(bool); }; +/// @brief PBL Bool implementation +typedef struct PblBool PblBool_T; + +// ---- End of Bool --------------------------------------------------------------------------------------------------- + +// ---- Size ---------------------------------------------------------------------------------------------------------- + +/// @brief (Never use this for malloc - this only indicates the usable memory space) +/// @returns The usable size in bytes of the PBL Size type +#define PblSize_T_Size sizeof(size_t) +/// @returns The declaration default for the type 'PblSize_T' +#define PblSize_T_DeclDefault PBL_TYPE_DECLARATION_DEFAULT_CONSTRUCTOR(PblSize_T) +/// @returns The definition default for the type 'PblSize_T', where the value/the children have not been set yet +/// and only the value itself 'exists' already. If the type is a struct-type, then the children will likely be NULL, +/// initialised to 0 or another Definition Default of another type +#define PblSize_T_DefDefault PBL_TYPE_DEFINITION_DEFAULT_SIMPLE_CONSTRUCTOR(PblSize_T, 0) + +/// @brief PBL Byte Size implementation +struct PblSize { PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(size_t); }; +/// @brief PBL Byte Size implementation +typedef struct PblSize PblSize_T; + +// ---- End of Size --------------------------------------------------------------------------------------------------- + +// ---- Char ---------------------------------------------------------------------------------------------------------- + +/// @brief (Never use this for malloc - this only indicates the usable memory space) +/// @returns The usable size in bytes of the PBL Signed Char type +#define PblChar_T_Size sizeof(signed char) +/// @returns The declaration default for the type 'PblChar_T' +#define PblChar_T_DeclDefault PBL_TYPE_DECLARATION_DEFAULT_CONSTRUCTOR(PblChar_T) +/// @returns The definition default for the type 'PblChar_T', where the value/the children have not been set yet +/// and only the value itself 'exists' already. If the type is a struct-type, then the children will likely be NULL, +/// initialised to 0 or another Definition Default of another type +#define PblChar_T_DefDefault PBL_TYPE_DEFINITION_DEFAULT_SIMPLE_CONSTRUCTOR(PblChar_T, 0) + +/// @brief PBL Signed Char implementation +struct PblChar { PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(signed char); }; +/// @brief PBL Signed Char implementation +typedef struct PblChar PblChar_T; + +// ---- End of Char --------------------------------------------------------------------------------------------------- + +// ---- UChar --------------------------------------------------------------------------------------------------------- + +/// @brief (Never use this for malloc - this only indicates the usable memory space) +/// @returns The usable size in bytes of the PBL Unsigned Char type +#define PblUChar_T_Size sizeof(unsigned char) +/// @returns The declaration default for the type 'PblUChar_T_Size' +#define PblUChar_T_DeclDefault PBL_TYPE_DECLARATION_DEFAULT_CONSTRUCTOR(PblUChar_T) +/// @returns The definition default for the type 'PblUChar_T', where the value/the children have not been set yet +/// and only the value itself 'exists' already. If the type is a struct-type, then the children will likely be NULL, +/// initialised to 0 or another Definition Default of another type +#define PblUChar_T_DefDefault PBL_TYPE_DEFINITION_DEFAULT_SIMPLE_CONSTRUCTOR(PblUChar_T, 0) + +/// @brief PBL Unsigned Char implementation +struct PblUChar { PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(unsigned char); }; +/// @brief PBL Unsigned Char implementation +typedef struct PblUChar PblUChar_T; + +// ---- End of UChar -------------------------------------------------------------------------------------------------- + +// ---- Short --------------------------------------------------------------------------------------------------------- + +/// @brief (Never use this for malloc - this only indicates the usable memory space) +/// @returns The usable size in bytes of the PBL Signed Short type +#define PblShort_T_Size sizeof(signed short) +/// @returns The declaration default for the type 'PblShort_T' +#define PblShort_T_DeclDefault PBL_TYPE_DECLARATION_DEFAULT_CONSTRUCTOR(PblShort_T) +/// @returns The definition default for the type 'PblShort_T', where the value/the children have not been set yet +/// and only the value itself 'exists' already. If the type is a struct-type, then the children will likely be NULL, +/// initialised to 0 or another Definition Default of another type +#define PblShort_T_DefDefault PBL_TYPE_DEFINITION_DEFAULT_SIMPLE_CONSTRUCTOR(PblShort_T, 0) + +/// @brief PBL Signed Short implementation +struct PblShort { PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(signed short); }; +/// @brief PBL Signed Short implementation +typedef struct PblShort PblShort_T; + +// ---- End of Short -------------------------------------------------------------------------------------------------- + +// ---- UShort -------------------------------------------------------------------------------------------------------- + +/// @brief (Never use this for malloc - this only indicates the usable memory space) +/// @returns The usable size in bytes of the PBL Unsigned Short type +#define PblUShort_T_Size sizeof(unsigned short) +/// @returns The declaration default for the type 'PblUShort_T_Size' +#define PblUShort_T_DeclDefault PBL_TYPE_DECLARATION_DEFAULT_CONSTRUCTOR(PblUShort_T) +/// @returns The definition default for the type 'PblUShort_T', where the value/the children have not been set yet +/// and only the value itself 'exists' already. If the type is a struct-type, then the children will likely be NULL, +/// initialised to 0 or another Definition Default of another type +#define PblUShort_T_DefDefault PBL_TYPE_DEFINITION_DEFAULT_SIMPLE_CONSTRUCTOR(PblUShort_T, 0) + +/// @brief PBL Unsigned Short implementation +struct PblUShort { PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(unsigned short); }; +/// @brief PBL Unsigned Short implementation +typedef struct PblUShort PblUShort_T; + +// ---- End of UShort ------------------------------------------------------------------------------------------------- + +// ---- Int ----------------------------------------------------------------------------------------------------------- + +/// @brief (Never use this for malloc - this only indicates the usable memory space) +/// @returns The usable size in bytes of the PBL Signed Int type +#define PblInt_T_Size sizeof(signed int) +/// @returns The declaration default for the type 'PblInt_T' +#define PblInt_T_DeclDefault PBL_TYPE_DECLARATION_DEFAULT_CONSTRUCTOR(PblInt_T) +/// @returns The definition default for the type 'PblInt_T', where the value/the children have not been set yet +/// and only the value itself 'exists' already. If the type is a struct-type, then the children will likely be NULL, +/// initialised to 0 or another Definition Default of another type +#define PblInt_T_DefDefault PBL_TYPE_DEFINITION_DEFAULT_SIMPLE_CONSTRUCTOR(PblInt_T, 0) + +/// @brief PBL Signed Int implementation +struct PblInt { PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(signed int); }; +/// @brief PBL Signed Int implementation +typedef struct PblInt PblInt_T; + +// ---- End of Int ---------------------------------------------------------------------------------------------------- + +// ---- UInt ---------------------------------------------------------------------------------------------------------- + +/// @brief (Never use this for malloc - this only indicates the usable memory space) +/// @returns The usable size in bytes of the PBL Unsigned Int type +#define PblUInt_T_Size sizeof(unsigned int) +/// @returns The declaration default for the type 'PblUInt_T' +#define PblUInt_T_DeclDefault PBL_TYPE_DECLARATION_DEFAULT_CONSTRUCTOR(PblUInt_T) +/// @returns The definition default for the type 'PblUInt_T', where the value/the children have not been set yet +/// and only the value itself 'exists' already. If the type is a struct-type, then the children will likely be NULL, +/// initialised to 0 or another Definition Default of another type +#define PblUInt_T_DefDefault PBL_TYPE_DEFINITION_DEFAULT_SIMPLE_CONSTRUCTOR(PblUInt_T, 0) + +/// @brief PBL Unsigned Int implementation +struct PblUInt { PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(unsigned int); }; +/// @brief PBL Unsigned Int implementation +typedef struct PblUInt PblUInt_T; + +// ---- End of UInt --------------------------------------------------------------------------------------------------- + +// ---- Long ---------------------------------------------------------------------------------------------------------- + +/// @brief (Never use this for malloc - this only indicates the usable memory space) +/// @returns The usable size in bytes of the PBL Signed Long type +#define PblLong_T_Size sizeof(signed long) +/// @returns The declaration default for the type 'PblLong_T' +#define PblLong_T_DeclDefault PBL_TYPE_DECLARATION_DEFAULT_CONSTRUCTOR(PblLong_T) +/// @returns The definition default for the type 'PblLong_T', where the value/the children have not been set yet +/// and only the value itself 'exists' already. If the type is a struct-type, then the children will likely be NULL, +/// initialised to 0 or another Definition Default of another type +#define PblLong_T_DefDefault PBL_TYPE_DEFINITION_DEFAULT_SIMPLE_CONSTRUCTOR(PblLong_T, 0) + +/// @brief PBL Signed Long implementation +struct PblLong { PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(signed long); }; +/// @brief PBL Signed Long implementation +typedef struct PblLong PblLong_T; + +// ---- End of Long -------------------------------------------------------------------------------------------------- + +// ---- ULong --------------------------------------------------------------------------------------------------------- + +/// @brief (Never use this for malloc - this only indicates the usable memory space) +/// @returns The usable size in bytes of the PBL Unsigned Long type +#define PblULong_T_Size sizeof(unsigned long) +/// @returns The declaration default for the type 'PblULong_T' +#define PblULong_T_DeclDefault PBL_TYPE_DECLARATION_DEFAULT_CONSTRUCTOR(PblULong_T) +/// @returns The definition default for the type 'PblULong_T', where the value/the children have not been set yet +/// and only the value itself 'exists' already. If the type is a struct-type, then the children will likely be NULL, +/// initialised to 0 or another Definition Default of another type +#define PblULong_T_DefDefault PBL_TYPE_DEFINITION_DEFAULT_SIMPLE_CONSTRUCTOR(PblULong_T, 0) + +/// @brief PBL Unsigned Long implementation +struct PblULong { PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(unsigned long); }; +/// @brief PBL Unsigned Long implementation +typedef struct PblULong PblULong_T; + +// ---- End of ULong -------------------------------------------------------------------------------------------------- + +// ---- Long Long ----------------------------------------------------------------------------------------------------- + +/// @brief (Never use this for malloc - this only indicates the usable memory space) +/// @returns The usable size in bytes of the PBL Signed Long Long type +#define PblLongLong_T_Size sizeof(signed long long) +/// @returns The declaration default for the type 'PblLongLong_T' +#define PblLongLong_T_DeclDefault PBL_TYPE_DECLARATION_DEFAULT_CONSTRUCTOR(PblLongLong_T) +/// @returns The definition default for the type 'PblLongLong_T', where the value/the children have not been set yet +/// and only the value itself 'exists' already. If the type is a struct-type, then the children will likely be NULL, +/// initialised to 0 or another Definition Default of another type +#define PblLongLong_T_DefDefault PBL_TYPE_DEFINITION_DEFAULT_SIMPLE_CONSTRUCTOR(PblLongLong_T, 0) + +/// @brief PBL Signed Long Long implementation +struct PblLongLong { PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(signed long long); }; +/// @brief PBL Signed Long Long implementation +typedef struct PblLongLong PblLongLong_T; + +// ---- End of Long Long ---------------------------------------------------------------------------------------------- + +// ---- ULong Long ---------------------------------------------------------------------------------------------------- + +/// @brief (Never use this for malloc - this only indicates the usable memory space) +/// @returns The usable size in bytes of the PBL Unsigned Long Long type +#define PblULongLong_T_Size sizeof(unsigned long long) +/// @returns The declaration default for the type 'PblULongLong_T' +#define PblULongLong_T_DeclDefault PBL_TYPE_DECLARATION_DEFAULT_CONSTRUCTOR(PblULongLong_T) +/// @returns The definition default for the type 'PblULongLong_T', where the value/the children have not been set yet +/// and only the value itself 'exists' already. If the type is a struct-type, then the children will likely be NULL, +/// initialised to 0 or another Definition Default of another type +#define PblULongLong_T_DefDefault PBL_TYPE_DEFINITION_DEFAULT_SIMPLE_CONSTRUCTOR(PblULongLong_T, 0) + +/// @brief PBL Unsigned Long Long implementation +struct PblULongLong { PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(unsigned long long); }; +/// @brief PBL Unsigned Long Long implementation +typedef struct PblULongLong PblULongLong_T; + +// ---- End of ULong Long --------------------------------------------------------------------------------------------- + +// ---- Float --------------------------------------------------------------------------------------------------------- + +/// @brief (Never use this for malloc - this only indicates the usable memory space) +/// @returns The usable size in bytes of the PBL Float type +#define PblFloat_T_Size sizeof(float) +/// @returns The declaration default for the type 'PblFloat_T' +#define PblFloat_T_DeclDefault PBL_TYPE_DECLARATION_DEFAULT_CONSTRUCTOR(PblFloat_T) +/// @returns The definition default for the type 'PblFloat_T', where the value/the children have not been set yet +/// and only the value itself 'exists' already. If the type is a struct-type, then the children will likely be NULL, +/// initialised to 0 or another Definition Default of another type +#define PblFloat_T_DefDefault PBL_TYPE_DEFINITION_DEFAULT_SIMPLE_CONSTRUCTOR(PblFloat_T, 0) + +/// @brief PBL Float implementation +struct PblFloat { PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(float); }; +/// @brief PBL Float implementation +typedef struct PblFloat PblFloat_T; + +// ---- End of Float -------------------------------------------------------------------------------------------------- + +// ---- Double -------------------------------------------------------------------------------------------------------- + +/// @brief (Never use this for malloc - this only indicates the usable memory space) +/// @returns The usable size in bytes of the PBL Double type +#define PblDouble_T_Size sizeof(double) +/// @returns The declaration default for the type 'PblDouble_T' +#define PblDouble_T_DeclDefault PBL_TYPE_DECLARATION_DEFAULT_CONSTRUCTOR(PblDouble_T) +/// @returns The definition default for the type 'PblDouble_T', where the value/the children have not been set yet +/// and only the value itself 'exists' already. If the type is a struct-type, then the children will likely be NULL, +/// initialised to 0 or another Definition Default of another type +#define PblDouble_T_DefDefault PBL_TYPE_DEFINITION_DEFAULT_SIMPLE_CONSTRUCTOR(PblDouble_T, 0) + +/// @brief PBL Double implementation +struct PblDouble { PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(double); }; +/// @brief PBL Double implementation +typedef struct PblDouble PblDouble_T; + +// ---- End of Double ------------------------------------------------------------------------------------------------- + +// ---- Long Double --------------------------------------------------------------------------------------------------- + +/// @brief (Never use this for malloc - this only indicates the usable memory space) +/// @returns The usable size in bytes of the PBL Long Double type +#define PblLongDouble_T_Size sizeof(long double) +/// @returns The declaration default for the type 'PblLongDouble_T' +#define PblLongDouble_T_DeclDefault PBL_TYPE_DECLARATION_DEFAULT_CONSTRUCTOR(PblLongDouble_T) +/// @returns The definition default for the type 'PblLongDouble_T', where the value/the children have not been set yet +/// and only the value itself 'exists' already. If the type is a struct-type, then the children will likely be NULL, +/// initialised to 0 or another Definition Default of another type +#define PblLongDouble_T_DefDefault PBL_TYPE_DEFINITION_DEFAULT_SIMPLE_CONSTRUCTOR(PblLongDouble_T, 0) + +/// @brief PBL Long Double implementation +struct PblLongDouble { PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(long double); }; +/// @brief PBL Long Double implementation +typedef struct PblLongDouble PblLongDouble_T; + +// ---- End of Numeric Types ------------------------------------------------------------------------------------------ + +// ---- Helper Function Constructor Macros ---------------------------------------------------------------------------- + +// Use auto with C++ +#ifdef __cplusplus +/// @brief This a macro function definition body constructor, which should be used to directly convert C types into +/// their Para-C counterparts. This should be only used for Para-C types that have as actual a single property, as this +/// does not support complex initialisation. +#define PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(parac_type, val, c_type) \ + { \ + auto *conv = (parac_type*) PblMalloc(sizeof(parac_type)); \ + *conv = parac_type##_DefDefault; \ + conv->actual = (c_type) (val); \ + return conv; \ + } +#else +/// @brief This a macro function definition body constructor, which should be used to directly convert C types into +/// their Para-C counterparts. This should be only used for Para-C types that have as actual a single property, as this +/// does not support complex initialisation. +#define PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(parac_type, val, c_type) \ + { \ + parac_type *conv = (parac_type*) PblMalloc(sizeof(parac_type)); \ + *conv = parac_type##_DefDefault; \ + conv->actual = (c_type) (val); \ + return conv; \ + } +#endif + +// ---- End of Helper Function Constructor Macros --------------------------------------------------------------------- + +// ---- Functions Definitions ----------------------------------------------------------------------------------------- + +/// @brief Converts a void* pointer and type to a Pbl Pointer type +/// @param val The actual pointer value +/// @param type The type of the pointer +/// @return The created pointer +__attribute__((unused)) PblPointer_T *PblGetPointerT(void* val, PblType_T* type); + +/// @brief Converts the low level C-Type to a PBL Bool type +/// @param val The C-type to be converted +/// @return The newly created PBL Bool type +/// @note This is a C to Para-C type conversion function - args are in C therefore +__attribute__((unused)) PblBool_T *PblGetBoolT(bool val); + +/// @brief Converts the low level C-Type to a PBL Byte Size type +/// @param val The C-type to be converted +/// @return The newly created PBL Byte Size type +/// @note This is a C to Para-C type conversion function - args are in C therefore +__attribute__((unused)) PblSize_T *PblGetSizeT(size_t val); + +/// @brief Converts the low level C-Type to a PBL Char type +/// @param val The C-type to be converted +/// @return The newly created PBL Char type +/// @note This is a C to Para-C type conversion function - args are in C therefore +__attribute__((unused)) PblChar_T *PblGetCharT(signed char val); + +/// @brief Converts the low level C-Type to a PBL Unsigned Char type +/// @param val The C-type to be converted +/// @return The newly created PBL Char type +/// @note This is a C to Para-C type conversion function - args are in C therefore +__attribute__((unused)) PblUChar_T *PblGetUCharT(unsigned char val); + +/// @brief Converts the low level C-Type to a PBL Short type +/// @param val The C-type to be converted +/// @return The newly created PBL Char type +/// @note This is a C to Para-C type conversion function - args are in C therefore +__attribute__((unused)) PblShort_T *PblGetShortT(signed short val); + +/// @brief Converts the low level C-Type to a PBL Unsigned Short type +/// @param val The C-type to be converted +/// @return The newly created PBL Char type +/// @note This is a C to Para-C type conversion function - args are in C therefore +__attribute__((unused)) PblUShort_T *PblGetUShortT(unsigned short val); + +/// @brief Converts the low level C-Type to a PBL Int type +/// @param val The C-type to be converted +/// @return The newly created PBL Char type +/// @note This is a C to Para-C type conversion function - args are in C therefore +__attribute__((unused)) PblInt_T *PblGetIntT(signed int val); + +/// @brief Converts the low level C-Type to a PBL Unsigned Int type +/// @param val The C-type to be converted +/// @return The newly created PBL Char type +/// @note This is a C to Para-C type conversion function - args are in C therefore +__attribute__((unused)) PblUInt_T *PblGetUIntT(unsigned int val); + +/// @brief Converts the low level C-Type to a PBL Long type +/// @param val The C-type to be converted +/// @return The newly created PBL Char type +/// @note This is a C to Para-C type conversion function - args are in C therefore +__attribute__((unused)) PblLong_T *PblGetLongT(signed long val); + +/// @brief Converts the low level C-Type to a PBL Unsigned Long type +/// @param val The C-type to be converted +/// @return The newly created PBL Char type +/// @note This is a C to Para-C type conversion function - args are in C therefore +__attribute__((unused)) PblULong_T *PblGetULongT(unsigned long val); + +/// @brief Converts the low level C-Type to a PBL Long Long type +/// @param val The C-type to be converted +/// @return The newly created PBL Char type +/// @note This is a C to Para-C type conversion function - args are in C therefore +__attribute__((unused)) PblLongLong_T *PblGetLongLongT(signed long long val); + +/// @brief Converts the low level C-Type to a PBL Unsigned Long Long type +/// @param val The C-type to be converted +/// @return The newly created PBL Char type +/// @note This is a C to Para-C type conversion function - args are in C therefore +__attribute__((unused)) PblULongLong_T *PblGetULongLongT(unsigned long long val); + +/// @brief Converts the low level C-Type to a PBL Float type +/// @param val The C-type to be converted +/// @return The newly created PBL Char type +/// @note This is a C to Para-C type conversion function - args are in C therefore +__attribute__((unused)) PblFloat_T *PblGetFloatT(float val); + +/// @brief Converts the low level C-Type to a PBL Double type +/// @param val The C-type to be converted +/// @return The newly created PBL Double type +/// @note This is a C to Para-C type conversion function - args are in C therefore +__attribute__((unused)) PblDouble_T *PblGetDoubleT(double val); + +/// @brief Converts the low level C-Type to a PBL Long Double type +/// @param val The C-type to be converted +/// @return The newly created PBL Long Double type +/// @note This is a C to Para-C type conversion function - args are in C therefore +__attribute__((unused)) PblLongDouble_T *PblGetLongDoubleT(long double val); + +// ---- End of Functions Definitions ---------------------------------------------------------------------------------- + +#ifdef __cplusplus +} +#endif + +#endif//PBL_MODULES_TYPES_H diff --git a/include/pbl/CMakeLists.txt b/include/pbl/CMakeLists.txt deleted file mode 100644 index 2c89dd6..0000000 --- a/include/pbl/CMakeLists.txt +++ /dev/null @@ -1,16 +0,0 @@ -project(pbl) - -include(FetchContent) -FetchContent_Declare( - gc-8.0.6 - URL https://github.com/ivmai/bdwgc/releases/download/v8.0.6/gc-8.0.6.tar.gz -) - -FetchContent_Populate( - gc-8.0.6 -) -add_subdirectory(${gc-8.0.6_SOURCE_DIR} ${gc-8.0.6_BINARY_DIR}) -target_include_directories(pbl PUBLIC "${gc-8.0.6_SOURCE_DIR}") -target_include_directories(pbl PUBLIC "${gc-8.0.6_SOURCE_DIR}/include") - -target_link_libraries(pbl PUBLIC gc-lib) diff --git a/include/pbl/additional/CMakeLists.txt b/include/pbl/additional/CMakeLists.txt deleted file mode 100644 index b901d30..0000000 --- a/include/pbl/additional/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -project(pbl) diff --git a/include/pbl/pbl-any.c b/include/pbl/pbl-any.c deleted file mode 100644 index b14dbce..0000000 --- a/include/pbl/pbl-any.c +++ /dev/null @@ -1,47 +0,0 @@ -/// @file pbl-any.c -/// @brief Implementation for the any type, which allows values to be dynamically allocated and converted using -/// pre-defined conversion functions. -/// @author Luna-Klatzer -/// @date 2021-11-23 -/// @copyright Copyright (c) 2021 - -#include "pbl-any.h" - -PblAny_T* PblGetAnyT(void* val, size_t bytes) { - // Validate the pointer for safety measures - val = PblValPtr(val); - - PBL_ALLOC_DEFINITION(ptr, PblAny_T); - - // copying the memory to the destination address (the new type) - ptr->actual.val = PblMalloc(bytes); - PblMemCpy(ptr->actual.val, val, bytes); - - // initialising the remaining properties - ptr->actual.byte_size = PblGetSizeT(bytes); - // NI = not implemented! type-dict in work! - ptr->actual.type_name = PblGetStringT("NI"); - - return ptr; -} - -PblVoid_T PblDeallocateAnyType(PblAny_T *val) { - // Validate the pointer for safety measures - val = PblValPtr(val); - - if (val->actual.val != NULL) { - PblFree(val->actual.val); - val->actual.val = NULL; - } - if (val->actual.byte_size != NULL) { - PblFree(val->actual.byte_size); - } - if (val->actual.type_name != NULL) { - PblDeallocateStringT(val->actual.type_name); - val->actual.type_name = NULL; - } - - *val = PblAny_T_DeclDefault; - PblFree(val); - return PblVoid_T_DeclDefault; -} diff --git a/include/pbl/pbl-function.c b/include/pbl/pbl-function.c deleted file mode 100644 index 8f1d38f..0000000 --- a/include/pbl/pbl-function.c +++ /dev/null @@ -1,92 +0,0 @@ -/// @file pbl-function.c -/// @brief Function-related types and exception implementation. This includes meta data tracking for functions calls, -/// function states, exceptions and tracebacks. -/// @author Luna-Klatzer -/// @date 2021-11-23 -/// @copyright Copyright (c) 2021 - -#include "./pbl-function.h" - -PblMetaFunctionCallCtx_T *PblGetMetaFunctionCallCtxT(PblString_T *function_identifier, PblBool_T *is_failure, - PblUInt_T *arg_amount, PblBool_T *is_threaded, - PblMetaFunctionCallCtx_T *failure_origin_ctx, - PblMetaFunctionCallCtx_T *call_origin_ctx, - PblException_T *exception) { - PBL_ALLOC_DEFINITION(ptr, PblMetaFunctionCallCtx_T); - *ptr = PblMetaFunctionCallCtx_T_DefDefault; - - ptr->actual = (struct PblMetaFunctionCallCtx_Base) { - .function_identifier=function_identifier, .is_failure=is_failure, .arg_amount=arg_amount, - .is_threaded=is_threaded, .failure_origin_ctx=failure_origin_ctx, .call_origin_ctx=call_origin_ctx, - .exception=exception - }; - return ptr; -} - -PblVoid_T PblDeallocateMetaFunctionCallCtxT(PblMetaFunctionCallCtx_T *ctx) { - // Validate the pointer for safety measures - ctx = PblValPtr((void *) ctx); - - if (ctx->meta.defined) { - if (ctx->actual.exception != NULL) PblDeallocateExceptionT(ctx->actual.exception); - if (ctx->actual.function_identifier != NULL) PblDeallocateStringT(ctx->actual.function_identifier); - - // resetting the values - *ctx = PblMetaFunctionCallCtx_T_DeclDefault; - PblFree(ctx); - ctx = NULL; - } - return PblVoid_T_DeclDefault; -} - -PblException_T *PblGetExceptionT(PblString_T *msg, PblString_T *name, PblString_T *filename, PblUInt_T *line, - PblString_T *line_content, PblVoid_T *parent_exc, PblVoid_T *child_exc) { - PBL_ALLOC_DEFINITION(ptr, PblException_T); - - // Using the Definition Default - *ptr = PblException_T_DefDefault; - ptr->actual = (struct PblException_Base){ - .msg = msg, .name = name, .filename = filename, .line = line, - .line_content = line_content, .parent_exc = parent_exc, .child_exc = child_exc - }; - - return ptr; -} - -PblVoid_T PblRaiseNewException(PblMetaFunctionCallCtx_T* this_call_meta, PblException_T *exception) { - // Validate the pointer for safety measures - this_call_meta = PblValPtr((void *) this_call_meta); - exception = PblValPtr((void *) exception); - - this_call_meta->actual.is_failure = PblGetBoolT(true); - this_call_meta->actual.failure_origin_ctx = this_call_meta; - this_call_meta->actual.exception = exception; - return PblVoid_T_DeclDefault; -} - -// TODO! Add Deallocating function for deallocating exception parents and children - -PblVoid_T PblDeallocateExceptionT(PblException_T *exc) { - // Validate the pointer for safety measures - exc = PblValPtr((void *) exc); - - // only if the exception is still defined - if (exc->meta.defined) - { - // deallocate if the values are defined -> if not, skip de-allocation - - if (exc->actual.msg != NULL && exc->actual.msg->meta.defined) - PblDeallocateStringT(exc->actual.msg); - if (exc->actual.name != NULL && exc->actual.name->meta.defined) - PblDeallocateStringT(exc->actual.name); - if (exc->actual.filename != NULL && exc->actual.filename->meta.defined) - PblDeallocateStringT(exc->actual.filename); - if (exc->actual.line_content != NULL && exc->actual.line_content->meta.defined) - PblDeallocateStringT(exc->actual.line_content); - - *exc = PblException_T_DeclDefault; - PblFree(exc); - exc = NULL; - } - return PblVoid_T_DeclDefault; -} diff --git a/include/pbl/pbl-int.c b/include/pbl/pbl-int.c deleted file mode 100644 index d3f8d32..0000000 --- a/include/pbl/pbl-int.c +++ /dev/null @@ -1,103 +0,0 @@ -/// @file pbl-int.c -/// @brief Int Type Implementation based on stdint.h -/// @author Luna-Klatzer -/// @date 2021-11-23 -/// @copyright Copyright (c) 2021 - -#include "./pbl-int.h" - -PblInt8_T* PblGetInt8T(int8_t val) { - PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblInt8_T, int8_t) -} - -PblUInt8_T* PblGetUInt8T(uint8_t val) { - PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblUInt8_T, uint8_t) -} - -PblInt16_T* PblGetInt16T(int16_t val) { - PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblInt16_T, int16_t) -} - -PblUInt16_T* PblGetUInt16T(uint16_t val) { - PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblUInt16_T, uint16_t) -} - -PblInt32_T* PblGetInt32T(int32_t val) { - PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblInt32_T, int32_t) -} - -PblUInt32_T* PblGetUInt32T(uint32_t val) { - PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblUInt32_T, uint32_t) -} - -PblInt64_T* PblGetInt64T(int64_t val) { - PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblInt64_T, int64_t) -} - -PblUInt64_T* PblGetUInt64T(uint64_t val) { - PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblUInt64_T, uint64_t) -} - -PblLeastInt8_T* PblGetLeastInt8T(int_least8_t val) { - PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblLeastInt8_T, int_least8_t) -} - -PblULeastInt8_T* PblGetULeastInt8T(uint_least8_t val) { - PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblULeastInt8_T, uint_least8_t) -} - -PblLeastInt16_T* PblGetLeastInt16T(int_least16_t val) { - PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblLeastInt16_T, int_least16_t) -} - -PblULeastInt16_T* PblGetULeastInt16T(uint_least16_t val) { - PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblULeastInt16_T, uint_least16_t) -} - -PblLeastInt32_T* PblGetLeastInt32T(int_least32_t val) { - PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblLeastInt32_T, int_least32_t) -} - -PblULeastInt32_T* PblGetULeastInt32T(uint_least32_t val) { - PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblULeastInt32_T, uint_least32_t) -} - -PblLeastInt64_T* PblGetLeastInt64T(int_least64_t val) { - PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblLeastInt64_T, int_least64_t) -} - -PblULeastInt64_T* PblGetULeastInt64T(uint_least64_t val) { - PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblULeastInt64_T, uint_least64_t) -} - -PblFastInt8_T* PblGetFastInt8T(int_fast8_t val) { - PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblFastInt8_T, int_fast8_t) -} - -PblUFastInt8_T* PblGetUFastInt8T(uint_fast8_t val) { - PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblUFastInt8_T, uint_fast8_t) -} - -PblFastInt16_T* PblGetFastInt16T(int_fast16_t val) { - PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblFastInt16_T, int_fast16_t) -} - -PblUFastInt16_T* PblGetUFastInt16T(uint_fast16_t val) { - PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblUFastInt16_T, uint_fast16_t) -} - -PblFastInt32_T* PblGetFastInt32T(int_fast32_t val) { - PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblFastInt32_T, int_fast32_t) -} - -PblUFastInt32_T* PblGetUFastInt32T(uint_fast32_t val) { - PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblUFastInt32_T, uint_fast32_t) -} - -PblFastInt64_T* PblGetFastInt64T(int_fast64_t val) { - PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblFastInt64_T, int_fast64_t) -} - -PblUFastInt64_T* PblGetUFastInt64T(uint_fast64_t val) { - PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblUFastInt64_T, uint_fast64_t) -} diff --git a/include/pbl/pbl-int.h b/include/pbl/pbl-int.h deleted file mode 100644 index d487d83..0000000 --- a/include/pbl/pbl-int.h +++ /dev/null @@ -1,582 +0,0 @@ -/// @file pbl-int.h -/// @brief Int Type Implementation based on stdint.h -/// @author Luna-Klatzer -/// @date 2021-11-23 -/// @copyright Copyright (c) 2021 - -#include - -#include "./pbl-types.h" - -#ifndef PBL_MODULES_INT_H -#define PBL_MODULES_INT_H - -#ifdef __cplusplus -extern "C" { -#endif - -// ---- Exact Int ----------------------------------------------------------------------------------------------------- - -// ---- Int8 ---------------------------------------------------------------------------------------------------------- - -/// @brief (Never use this for malloc - this only indicates the usable memory space) -/// @returns The size in bytes of the PBL Signed Int8 type -#define PblInt8_T_Size sizeof(int8_t) -/// @brief Returns the declaration default for the type 'PblInt8_T' -#define PblInt8_T_DeclDefault PBL_DECLARATION_CONSTRUCTOR(PblInt8_T) -/// @brief Returns the definition default for the type 'PblInt8_T', where only value itself has been created -#define PblInt8_T_DefDefault PBL_DEFINITION_SINGLE_CONSTRUCTOR(PblInt8_T, 0) - -/// @brief PBL Int8 implementation -struct PblInt8 PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(int8_t) -/// @brief PBL Signed Int8 implementation -typedef struct PblInt8 PblInt8_T; - -// ---- UInt8 --------------------------------------------------------------------------------------------------------- - -/// @brief (Never use this for malloc - this only indicates the usable memory space) -/// @returns The size in bytes of the PBL Signed Long type -#define PblUInt8_T_Size sizeof(uint8_t) -/// @brief Returns the declaration default for the type 'PblUInt8_T' -#define PblUInt8_T_DeclDefault PBL_DECLARATION_CONSTRUCTOR(PblUInt8_T) -/// @brief Returns the definition default for the type 'PblUInt8_T', where only value itself has been created -#define PblUInt8_T_DefDefault PBL_DEFINITION_SINGLE_CONSTRUCTOR(PblUInt8_T, 0) - -/// @brief PBL Unsigned Int8 implementation -struct PblUInt8 PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(uint8_t) -/// @brief PBL Unsigned Int8 implementation -typedef struct PblUInt8 PblUInt8_T; - -// ---- Int16 --------------------------------------------------------------------------------------------------------- - -/// @brief (Never use this for malloc - this only indicates the usable memory space) -/// @returns The size in bytes of the PBL Signed Int16 type -#define PblInt16_T_Size sizeof(int16_t) -/// @brief Returns the declaration default for the type 'PblInt16_T' -#define PblInt16_T_DeclDefault PBL_DECLARATION_CONSTRUCTOR(PblInt16_T) -/// @brief Returns the definition default for the type 'PblInt16_T', where only value itself has been created -#define PblInt16_T_DefDefault PBL_DEFINITION_SINGLE_CONSTRUCTOR(PblInt16_T, 0) - -/// @brief PBL Int16 implementation -struct PblInt16 PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(int16_t) -/// @brief PBL Signed Int16 implementation -typedef struct PblInt16 PblInt16_T; - -// ---- UInt16 -------------------------------------------------------------------------------------------------------- - -/// @brief (Never use this for malloc - this only indicates the usable memory space) -/// @returns The size in bytes of the PBL Signed Long type -#define PblUInt16_T_Size sizeof(uint16_t) -/// @brief Returns the declaration default for the type 'PblUInt16_T' -#define PblUInt16_T_DeclDefault PBL_DECLARATION_CONSTRUCTOR(PblUInt16_T) -/// @brief Returns the definition default for the type 'PblUInt16_T', where only value itself has been created -#define PblUInt16_T_DefDefault PBL_DEFINITION_SINGLE_CONSTRUCTOR(PblUInt16_T, 0) - -/// @brief PBL UInt16 implementation -struct PblUInt16 PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(uint16_t) -/// @brief PBL UInt16 implementation -typedef struct PblUInt16 PblUInt16_T; - -// ---- Int32 --------------------------------------------------------------------------------------------------------- - -/// @brief (Never use this for malloc - this only indicates the usable memory space) -/// @returns The size in bytes of the PBL Signed Int32 type -#define PblInt32_T_Size sizeof(int32_t) -/// @brief Returns the declaration default for the type 'PblInt32_T' -#define PblInt32_T_DeclDefault PBL_DECLARATION_CONSTRUCTOR(PblInt32_T) -/// @brief Returns the definition default for the type 'PblInt32_T', where only value itself has been created -#define PblInt32_T_DefDefault PBL_DEFINITION_SINGLE_CONSTRUCTOR(PblInt32_T, 0) - -/// @brief PBL Int32 implementation -struct PblInt32 PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(int32_t) -/// @brief PBL Signed Int32 implementation -typedef struct PblInt32 PblInt32_T; - -// ---- UInt32 -------------------------------------------------------------------------------------------------------- - -/// @brief (Never use this for malloc - this only indicates the usable memory space) -/// @returns The size in bytes of the PBL Signed Long type -#define PblUInt32_T_Size sizeof(uint32_t) -/// @brief Returns the declaration default for the type 'PblUInt32_T' -#define PblUInt32_T_DeclDefault PBL_DECLARATION_CONSTRUCTOR(PblUInt32_T) -/// @brief Returns the definition default for the type 'PblUInt32_T', where only value itself has been created -#define PblUInt32_T_DefDefault PBL_DEFINITION_SINGLE_CONSTRUCTOR(PblUInt32_T, 0) - -/// @brief PBL UInt32 implementation -struct PblUInt32 PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(uint32_t) -/// @brief PBL UInt32 implementation -typedef struct PblUInt32 PblUInt32_T; - -// ---- Int64 --------------------------------------------------------------------------------------------------------- - -/// @brief (Never use this for malloc - this only indicates the usable memory space) -/// @returns The size in bytes of the PBL Signed Int64 type -#define PblInt64_T_Size sizeof(int64_t) -/// @brief Returns the declaration default for the type 'PblInt64_T' -#define PblInt64_T_DeclDefault PBL_DECLARATION_CONSTRUCTOR(PblInt64_T) -/// @brief Returns the definition default for the type 'PblInt64_T', where only value itself has been created -#define PblInt64_T_DefDefault PBL_DEFINITION_SINGLE_CONSTRUCTOR(PblInt64_T, 0) - -/// @brief PBL Int64 implementation -struct PblInt64 PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(int64_t) -/// @brief PBL Signed Int64 implementation -typedef struct PblInt64 PblInt64_T; - -// ---- UInt64 -------------------------------------------------------------------------------------------------------- - -/// @brief (Never use this for malloc - this only indicates the usable memory space) -/// @returns The size in bytes of the PBL Signed Long type -#define PblUInt64_T_Size sizeof(uint64_t) -/// @brief Returns the declaration default for the type 'PblUInt64_T' -#define PblUInt64_T_DeclDefault PBL_DECLARATION_CONSTRUCTOR(PblUInt64_T) -/// @brief Returns the definition default for the type 'PblUInt64_T', where only value itself has been created -#define PblUInt64_T_DefDefault PBL_DEFINITION_SINGLE_CONSTRUCTOR(PblUInt64_T, 0) - -/// @brief PBL UInt64 implementation -struct PblUInt64 PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(uint64_t) -/// @brief PBL UInt64 implementation -typedef struct PblUInt64 PblUInt64_T; - -// ---- Least Int ----------------------------------------------------------------------------------------------------- - -// ---- LeastInt8 ----------------------------------------------------------------------------------------------------- - -/// @brief (Never use this for malloc - this only indicates the usable memory space) -/// @returns The size in bytes of the PBL Signed LeastInt8 type -#define PblLeastInt8_T_Size sizeof(int_least8_t) -/// @brief Returns the declaration default for the type 'PblLeastInt8_T' -#define PblLeastInt8_T_DeclDefault PBL_DECLARATION_CONSTRUCTOR(PblLeastInt8_T) -/// @brief Returns the definition default for the type 'PblLeastInt8_T', where only value itself has been created -#define PblLeastInt8_T_DefDefault PBL_DEFINITION_SINGLE_CONSTRUCTOR(PblLeastInt8_T, 0) - -/// @brief PBL LeastInt8 implementation -struct PblLeastInt8 PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(int_least8_t) -/// @brief PBL Signed LeastInt8 implementation -typedef struct PblLeastInt8 PblLeastInt8_T; - -// ---- ULeastInt8 ---------------------------------------------------------------------------------------------------- - -/// @brief (Never use this for malloc - this only indicates the usable memory space) -/// @returns The size in bytes of the PBL Signed Long type -#define PblULeastInt8_T_Size sizeof(uint_least8_t) -/// @brief Returns the declaration default for the type 'PblULeastInt8_T' -#define PblULeastInt8_T_DeclDefault PBL_DECLARATION_CONSTRUCTOR(PblULeastInt8_T) -/// @brief Returns the definition default for the type 'PblULeastInt8_T', where only value itself has been created -#define PblULeastInt8_T_DefDefault PBL_DEFINITION_SINGLE_CONSTRUCTOR(PblULeastInt8_T, 0) - -/// @brief PBL ULeastInt8 implementation -struct PblULeastInt8 PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(uint_least8_t) -/// @brief PBL ULeastInt8 implementation -typedef struct PblULeastInt8 PblULeastInt8_T; - -// ---- LeastInt16 ---------------------------------------------------------------------------------------------------- - -/// @brief (Never use this for malloc - this only indicates the usable memory space) -/// @returns The size in bytes of the PBL Signed LeastInt16 type -#define PblLeastInt16_T_Size sizeof(int_least16_t) -/// @brief Returns the declaration default for the type 'PblLeastInt16_T' -#define PblLeastInt16_T_DeclDefault PBL_DECLARATION_CONSTRUCTOR(PblLeastInt16_T) -/// @brief Returns the definition default for the type 'PblLeastInt16_T', where only value itself has been created -#define PblLeastInt16_T_DefDefault PBL_DEFINITION_SINGLE_CONSTRUCTOR(PblLeastInt16_T, 0) - -/// @brief PBL LeastInt16 implementation -struct PblLeastInt16 PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(int_least16_t) -/// @brief PBL Signed LeastInt16 implementation -typedef struct PblLeastInt16 PblLeastInt16_T; - -// ---- ULeastInt16 --------------------------------------------------------------------------------------------------- - -/// @brief (Never use this for malloc - this only indicates the usable memory space) -/// @returns The size in bytes of the PBL Signed Long type -#define PblULeastInt16_T_Size sizeof(uint_least16_t) -/// @brief Returns the declaration default for the type 'PblULeastInt16_T' -#define PblULeastInt16_T_DeclDefault PBL_DECLARATION_CONSTRUCTOR(PblULeastInt16_T) -/// @brief Returns the definition default for the type 'PblULeastInt16_T', where only value itself has been created -#define PblULeastInt16_T_DefDefault PBL_DEFINITION_SINGLE_CONSTRUCTOR(PblULeastInt16_T, 0) - -/// @brief PBL ULeastInt16 implementation -struct PblULeastInt16 PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(uint_least16_t) -/// @brief PBL ULeastInt16 implementation -typedef struct PblULeastInt16 PblULeastInt16_T; - -// ---- LeastInt32 ---------------------------------------------------------------------------------------------------- - -/// @brief (Never use this for malloc - this only indicates the usable memory space) -/// @returns The size in bytes of the PBL Signed LeastInt32 type -#define PblLeastInt32_T_Size sizeof(int_least32_t) -/// @brief Returns the declaration default for the type 'PblLeastInt32_T' -#define PblLeastInt32_T_DeclDefault PBL_DECLARATION_CONSTRUCTOR(PblLeastInt32_T) -/// @brief Returns the definition default for the type 'PblLeastInt32_T', where only value itself has been created -#define PblLeastInt32_T_DefDefault PBL_DEFINITION_SINGLE_CONSTRUCTOR(PblLeastInt32_T, 0) - -/// @brief PBL LeastInt32 implementation -struct PblLeastInt32 PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(int_least32_t) -/// @brief PBL LeastInt32 implementation -typedef struct PblLeastInt32 PblLeastInt32_T; - -// ---- ULeastInt32 --------------------------------------------------------------------------------------------------- - -/// @brief (Never use this for malloc - this only indicates the usable memory space) -/// @returns The size in bytes of the PBL Signed Long type -#define PblULeastInt32_T_Size sizeof(uint_least32_t) -/// @brief Returns the declaration default for the type 'PblULeastInt32_T' -#define PblULeastInt32_T_DeclDefault PBL_DECLARATION_CONSTRUCTOR(PblULeastInt32_T) -/// @brief Returns the definition default for the type 'PblULeastInt32_T', where only value itself has been created -#define PblULeastInt32_T_DefDefault PBL_DEFINITION_SINGLE_CONSTRUCTOR(PblULeastInt32_T, 0) - -/// @brief PBL ULeastInt32 implementation -struct PblULeastInt32 PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(uint_least32_t) -/// @brief PBL ULeastInt32 implementation -typedef struct PblULeastInt32 PblULeastInt32_T; - -// ---- LeastInt64 ---------------------------------------------------------------------------------------------------- - -/// @brief (Never use this for malloc - this only indicates the usable memory space) -/// @returns The size in bytes of the PBL Signed LeastInt64 type -#define PblLeastInt64_T_Size sizeof(int_least64_t) -/// @brief Returns the declaration default for the type 'PblLeastInt64_T' -#define PblLeastInt64_T_DeclDefault PBL_DECLARATION_CONSTRUCTOR(PblLeastInt64_T) -/// @brief Returns the definition default for the type 'PblLeastInt64_T', where only value itself has been created -#define PblLeastInt64_T_DefDefault PBL_DEFINITION_SINGLE_CONSTRUCTOR(PblLeastInt64_T, 0) - -/// @brief PBL LeastInt64 implementation -struct PblLeastInt64 PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(int_least64_t) -/// @brief PBL Signed LeastInt64 implementation -typedef struct PblLeastInt64 PblLeastInt64_T; - -// ---- ULeastInt64 --------------------------------------------------------------------------------------------------- - -/// @brief (Never use this for malloc - this only indicates the usable memory space) -/// @returns The size in bytes of the PBL Signed Long type -#define PblULeastInt64_T_Size sizeof(uint_least64_t) -/// @brief Returns the declaration default for the type 'PblULeastInt64_T' -#define PblULeastInt64_T_DeclDefault PBL_DECLARATION_CONSTRUCTOR(PblULeastInt64_T) -/// @brief Returns the definition default for the type 'PblULeastInt64_T', where only value itself has been created -#define PblULeastInt64_T_DefDefault PBL_DEFINITION_SINGLE_CONSTRUCTOR(PblULeastInt64_T, 0) - -/// @brief PBL ULeastInt64 implementation -struct PblULeastInt64 PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(uint_least64_t) -/// @brief PBL ULeastInt64 implementation -typedef struct PblULeastInt64 PblULeastInt64_T; - -// ---- Fast Int ------------------------------------------------------------------------------------------------------ - -// ---- FastInt8 --------------------------------------------------------------------------------------------------- - -/// @brief (Never use this for malloc - this only indicates the usable memory space) -/// @returns The size in bytes of the PBL Signed FastInt8 type -#define PblFastInt8_T_Size sizeof(int_fast8_t) -/// @brief Returns the declaration default for the type 'PblFastInt8_T' -#define PblFastInt8_T_DeclDefault PBL_DECLARATION_CONSTRUCTOR(PblFastInt8_T) -/// @brief Returns the definition default for the type 'PblFastInt8_T', where only value itself has been created -#define PblFastInt8_T_DefDefault PBL_DEFINITION_SINGLE_CONSTRUCTOR(PblFastInt8_T, 0) - -/// @brief PBL FastInt8 implementation -struct PblFastInt8 PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(int_fast8_t) -/// @brief PBL FastInt8 implementation -typedef struct PblFastInt8 PblFastInt8_T; - -// ---- UFastInt8 -------------------------------------------------------------------------------------------------- - -/// @brief (Never use this for malloc - this only indicates the usable memory space) -/// @returns The size in bytes of the PBL Signed Long type -#define PblUFastInt8_T_Size sizeof(uint_fast8_t) -/// @brief Returns the declaration default for the type 'PblUFastInt8_T' -#define PblUFastInt8_T_DeclDefault PBL_DECLARATION_CONSTRUCTOR(PblUFastInt8_T) -/// @brief Returns the definition default for the type 'PblUFastInt8_T', where only value itself has been created -#define PblUFastInt8_T_DefDefault PBL_DEFINITION_SINGLE_CONSTRUCTOR(PblUFastInt8_T, 0) - -/// @brief PBL UFastInt8 implementation -struct PblUFastInt8 PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(uint_fast8_t) -/// @brief PBL UFastInt8 implementation -typedef struct PblUFastInt8 PblUFastInt8_T; - -// ---- FastInt16 -------------------------------------------------------------------------------------------------- - -/// @brief (Never use this for malloc - this only indicates the usable memory space) -/// @returns The size in bytes of the PBL Signed FastInt16 type -#define PblFastInt16_T_Size sizeof(int_fast16_t) -/// @brief Returns the declaration default for the type 'PblFastInt16_T' -#define PblFastInt16_T_DeclDefault PBL_DECLARATION_CONSTRUCTOR(PblFastInt16_T) -/// @brief Returns the definition default for the type 'PblFastInt16_T', where only value itself has been created -#define PblFastInt16_T_DefDefault PBL_DEFINITION_SINGLE_CONSTRUCTOR(PblFastInt16_T, 0) - -/// @brief PBL FastInt16 implementation -struct PblFastInt16 PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(int_fast16_t) -/// @brief PBL Signed FastInt16 implementation -typedef struct PblFastInt16 PblFastInt16_T; - -// ---- UFastInt16 ------------------------------------------------------------------------------------------------- - -/// @brief (Never use this for malloc - this only indicates the usable memory space) -/// @returns The size in bytes of the PBL Signed Long type -#define PblUFastInt16_T_Size sizeof(uint_fast16_t) -/// @brief Returns the declaration default for the type 'PblUFastInt16_T' -#define PblUFastInt16_T_DeclDefault PBL_DECLARATION_CONSTRUCTOR(PblUFastInt16_T) -/// @brief Returns the definition default for the type 'PblUFastInt16_T', where only value itself has been created -#define PblUFastInt16_T_DefDefault PBL_DEFINITION_SINGLE_CONSTRUCTOR(PblUFastInt16_T, 0) - -/// @brief PBL UFastInt16 implementation -struct PblUFastInt16 PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(uint_fast16_t) -/// @brief PBL UFastInt16 implementation -typedef struct PblUFastInt16 PblUFastInt16_T; - -// ---- FastInt32 -------------------------------------------------------------------------------------------------- - -/// @brief (Never use this for malloc - this only indicates the usable memory space) -/// @returns The size in bytes of the PBL Signed FastInt32 type -#define PblFastInt32_T_Size sizeof(int_fast32_t) -/// @brief Returns the declaration default for the type 'PblFastInt32_T' -#define PblFastInt32_T_DeclDefault PBL_DECLARATION_CONSTRUCTOR(PblFastInt32_T) -/// @brief Returns the definition default for the type 'PblFastInt32_T', where only value itself has been created -#define PblFastInt32_T_DefDefault PBL_DEFINITION_SINGLE_CONSTRUCTOR(PblFastInt32_T, 0) - -/// @brief PBL FastInt32 implementation -struct PblFastInt32 PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(int_fast32_t) -/// @brief PBL Signed FastInt32 implementation -typedef struct PblFastInt32 PblFastInt32_T; - -// ---- UFastInt32 ------------------------------------------------------------------------------------------------- - -/// @brief (Never use this for malloc - this only indicates the usable memory space) -/// @returns The size in bytes of the PBL Signed Long type -#define PblUFastInt32_T_Size sizeof(uint_fast32_t) -/// @brief Returns the declaration default for the type 'PblUFastInt32_T' -#define PblUFastInt32_T_DeclDefault PBL_DECLARATION_CONSTRUCTOR(PblUFastInt32_T) -/// @brief Returns the definition default for the type 'PblUFastInt32_T', where only value itself has been created -#define PblUFastInt32_T_DefDefault PBL_DEFINITION_SINGLE_CONSTRUCTOR(PblUFastInt32_T, 0) - -/// @brief PBL UFastInt32 implementation -struct PblUFastInt32 PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(uint_fast32_t) -/// @brief PBL UFastInt32 implementation -typedef struct PblUFastInt32 PblUFastInt32_T; - -// ---- FastInt64 -------------------------------------------------------------------------------------------------- - -/// @brief (Never use this for malloc - this only indicates the usable memory space) -/// @returns The size in bytes of the PBL Signed FastInt64 type -#define PblFastInt64_T_Size sizeof(int_fast64_t) -/// @brief Returns the declaration default for the type 'PblFastInt64_T' -#define PblFastInt64_T_DeclDefault PBL_DECLARATION_CONSTRUCTOR(PblFastInt64_T) -/// @brief Returns the definition default for the type 'PblFastInt64_T', where only value itself has been created -#define PblFastInt64_T_DefDefault PBL_DEFINITION_SINGLE_CONSTRUCTOR(PblFastInt64_T, 0) - -/// @brief PBL FastInt64 implementation -struct PblFastInt64 PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(int_fast64_t) -/// @brief PBL Signed FastInt64 implementation -typedef struct PblFastInt64 PblFastInt64_T; - -// ---- UFastInt64 ------------------------------------------------------------------------------------------------- - -/// @brief (Never use this for malloc - this only indicates the usable memory space) -/// @returns The size in bytes of the PBL Signed Long type -#define PblUFastInt64_T_Size sizeof(uint_fast64_t) -/// @brief Returns the declaration default for the type 'PblUFastInt64_T' -#define PblUFastInt64_T_DeclDefault PBL_DECLARATION_CONSTRUCTOR(PblUFastInt64_T) -/// @brief Returns the definition default for the type 'PblUFastInt64_T', where only value itself has been created -#define PblUFastInt64_T_DefDefault PBL_DEFINITION_SINGLE_CONSTRUCTOR(PblUFastInt64_T, 0) - -/// @brief PBL UFastInt64 implementation -struct PblUFastInt64 PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(uint_fast64_t) -/// @brief PBL UFastInt64 implementation -typedef struct PblUFastInt64 PblUFastInt64_T; - -// ---- Helper Functions ---------------------------------------------------------------------------------------------- - -/** - * @brief Converts the low level C-Type to a PBL Int8 type - * @param val The C-type to be converted - * @return The newly created PBL Int8 type - * @note This is a C to Para-C type conversion function - args are in C therefore - */ -PblInt8_T* PblGetInt8T(int8_t val); - -/** -* @brief Converts the low level C-Type to a PBL UInt8 type -* @param val The C-type to be converted -* @return The newly created PBL UInt8 type -* @note This is a C to Para-C type conversion function - args are in C therefore -*/ -PblUInt8_T* PblGetUInt8T(uint8_t val); - -/** -* @brief Converts the low level C-Type to a PBL Int16 type -* @param val The C-type to be converted -* @return The newly created PBL Int16 type -* @note This is a C to Para-C type conversion function - args are in C therefore -*/ -PblInt16_T* PblGetInt16T(int16_t val); - -/** -* @brief Converts the low level C-Type to a PBL UInt16 type -* @param val The C-type to be converted -* @return The newly created PBL UInt16 type -* @note This is a C to Para-C type conversion function - args are in C therefore -*/ -PblUInt16_T* PblGetUInt16T(uint16_t val); - -/** -* @brief Converts the low level C-Type to a PBL Int32 type -* @param val The C-type to be converted -* @return The newly created PBL Int32 type -* @note This is a C to Para-C type conversion function - args are in C therefore -*/ -PblInt32_T* PblGetInt32T(int32_t val); - -/** -* @brief Converts the low level C-Type to a PBL UInt32 type -* @param val The C-type to be converted -* @return The newly created PBL UInt32 type -* @note This is a C to Para-C type conversion function - args are in C therefore -*/ -PblUInt32_T* PblGetUInt32T(uint32_t val); - -/** -* @brief Converts the low level C-Type to a PBL Int64 type -* @param val The C-type to be converted -* @return The newly created PBL Int64 type -* @note This is a C to Para-C type conversion function - args are in C therefore -*/ -PblInt64_T* PblGetInt64T(int64_t val); - -/** -* @brief Converts the low level C-Type to a PBL UInt64 type -* @param val The C-type to be converted -* @return The newly created PBL UInt64 type -* @note This is a C to Para-C type conversion function - args are in C therefore -*/ -PblUInt64_T* PblGetUInt64T(uint64_t val); - -/** -* @brief Converts the low level C-Type to a PBL LeastInt8 type -* @param val The C-type to be converted -* @return The newly created PBL LeastInt8 type -* @note This is a C to Para-C type conversion function - args are in C therefore -*/ -PblLeastInt8_T* PblGetLeastInt8T(int_least8_t val); - -/** -* @brief Converts the low level C-Type to a PBL ULeastInt8 type -* @param val The C-type to be converted -* @return The newly created PBL ULeastInt8 type -* @note This is a C to Para-C type conversion function - args are in C therefore -*/ -PblULeastInt8_T* PblGetULeastInt8T(uint_least8_t val); - -/** -* @brief Converts the low level C-Type to a PBL LeastInt16 type -* @param val The C-type to be converted -* @return The newly created PBL LeastInt16 type -* @note This is a C to Para-C type conversion function - args are in C therefore -*/ -PblLeastInt16_T* PblGetLeastInt16T(int_least16_t val); - -/** -* @brief Converts the low level C-Type to a PBL ULeastInt16 type -* @param val The C-type to be converted -* @return The newly created PBL ULeastInt16 type -* @note This is a C to Para-C type conversion function - args are in C therefore -*/ -PblULeastInt16_T* PblGetULeastInt16T(uint_least16_t val); - -/** -* @brief Converts the low level C-Type to a PBL LeastInt32 type -* @param val The C-type to be converted -* @return The newly created PBL LeastInt32 type -* @note This is a C to Para-C type conversion function - args are in C therefore -*/ -PblLeastInt32_T* PblGetLeastInt32T(int_least32_t val); - -/** -* @brief Converts the low level C-Type to a PBL ULeastInt32 type -* @param val The C-type to be converted -* @return The newly created PBL ULeastInt32 type -* @note This is a C to Para-C type conversion function - args are in C therefore -*/ -PblULeastInt32_T* PblGetULeastInt32T(uint_least32_t val); - -/** -* @brief Converts the low level C-Type to a PBL LeastInt64 type -* @param val The C-type to be converted -* @return The newly created PBL LeastInt64 type -* @note This is a C to Para-C type conversion function - args are in C therefore -*/ -PblLeastInt64_T* PblGetLeastInt64T(int_least64_t val); - -/** -* @brief Converts the low level C-Type to a PBL ULeastInt64 type -* @param val The C-type to be converted -* @return The newly created PBL ULeastInt64 type -* @note This is a C to Para-C type conversion function - args are in C therefore -*/ -PblULeastInt64_T* PblGetULeastInt64T(uint_least64_t val); - -/** -* @brief Converts the low level C-Type to a PBL FastInt8 type -* @param val The C-type to be converted -* @return The newly created PBL FastInt8 type -* @note This is a C to Para-C type conversion function - args are in C therefore -*/ -PblFastInt8_T* PblGetFastInt8T(int_fast8_t val); - -/** -* @brief Converts the low level C-Type to a PBL UFastInt8 type -* @param val The C-type to be converted -* @return The newly created PBL UFastInt8 type -* @note This is a C to Para-C type conversion function - args are in C therefore -*/ -PblUFastInt8_T* PblGetUFastInt8T(uint_fast8_t val); - -/** -* @brief Converts the low level C-Type to a PBL FastInt16 type -* @param val The C-type to be converted -* @return The newly created PBL FastInt16 type -* @note This is a C to Para-C type conversion function - args are in C therefore -*/ -PblFastInt16_T* PblGetFastInt16T(int_fast16_t val); - -/** -* @brief Converts the low level C-Type to a PBL UFastInt16 type -* @param val The C-type to be converted -* @return The newly created PBL UFastInt16 type -* @note This is a C to Para-C type conversion function - args are in C therefore -*/ -PblUFastInt16_T* PblGetUFastInt16T(uint_fast16_t val); - -/** -* @brief Converts the low level C-Type to a PBL FastInt32 type -* @param val The C-type to be converted -* @return The newly created PBL FastInt32 type -* @note This is a C to Para-C type conversion function - args are in C therefore -*/ -PblFastInt32_T* PblGetFastInt32T(int_fast32_t val); - -/** -* @brief Converts the low level C-Type to a PBL UFastInt32 type -* @param val The C-type to be converted -* @return The newly created PBL UFastInt32 type -* @note This is a C to Para-C type conversion function - args are in C therefore -*/ -PblUFastInt32_T* PblGetUFastInt32T(uint_fast32_t val); - -/** -* @brief Converts the low level C-Type to a PBL FastInt64 type -* @param val The C-type to be converted -* @return The newly created PBL FastInt64 type -* @note This is a C to Para-C type conversion function - args are in C therefore -*/ -PblFastInt64_T* PblGetFastInt64T(int_fast64_t val); - -/** -* @brief Converts the low level C-Type to a PBL UFastInt64 type -* @param val The C-type to be converted -* @return The newly created PBL UFastInt64 type -* @note This is a C to Para-C type conversion function - args are in C therefore -*/ -PblUFastInt64_T* PblGetUFastInt64T(uint_fast64_t val); - -#ifdef __cplusplus -} -#endif - -#endif //PBL_MODULES_INT_H diff --git a/include/pbl/pbl-io.c b/include/pbl/pbl-io.c deleted file mode 100644 index be18dc7..0000000 --- a/include/pbl/pbl-io.c +++ /dev/null @@ -1,59 +0,0 @@ -/// @file pbl-io.c -/// @brief IO Implementation based on stdio.h -/// @author Luna-Klatzer -/// @date 2021-11-23 -/// @copyright Copyright (c) 2021 - -#include - -#include "./pbl-io.h" -#include "./pbl-string.h" -#include "./pbl-mem.h" - -PblFile_T* PblGetFileT(FILE *val) { - // Validate the pointer for safety measures - val = PblValPtr(val); - - PblFile_T* conv = PblMalloc(sizeof(PblFile_T)); - *conv = PblFile_T_DefDefault; - conv->actual = val; - return conv; -} - -PblStream_T* PblGetStreamT(int fd, const char *mode) { - // Validate the pointer for safety measures - mode = PblValPtr((void*) mode); - - PblStream_T* conv = PblMalloc(sizeof(PblStream_T)); - *conv = PblStream_T_DefDefault; - conv->actual.fd = PblGetUIntT((signed int) fd); - conv->actual.file = PblGetFileT(fdopen(fd, mode)); - conv->actual.mode = PblGetStringT(mode); - conv->actual.open = PblGetBoolT(true); - return conv; -} - -PblVoid_T PblPrint_Base(PblString_T *out, const PblStream_T *stream, const PblChar_T *end) { - // Validate the pointer for safety measures - out = PblValPtr((void*) out); - - for (int i = 0; i < out->actual.len->actual; i++) - fprintf(stream->actual.file->actual, "%c", (out->actual.str[i].actual)); - fprintf(stream->actual.file->actual, "%c", end->actual); - return PblVoid_T_DeclDefault; -} - -PblVoid_T PblPrint_Overhead(struct PblPrint_Args in) { - // Validate the pointer for safety measures - PblString_T *out = PblValPtr((void*) in.out); - - PblStream_T* stream; - if (in.stream != NULL) { - stream = in.stream; - } else { - stream = PblMalloc(sizeof(PblStream_T)); - *stream = PBL_STREAM_STDOUT; - } - PblChar_T* end = in.end != NULL ? in.end : PblGetCharT('\n'); - return PblPrint_Base(out, stream, end); -} diff --git a/include/pbl/pbl-io.h b/include/pbl/pbl-io.h deleted file mode 100644 index a6868af..0000000 --- a/include/pbl/pbl-io.h +++ /dev/null @@ -1,136 +0,0 @@ -/// @file pbl-io.h -/// @brief IO Implementation based on stdio.h -/// @author Luna-Klatzer -/// @date 2021-11-23 -/// @copyright Copyright (c) 2021 - -#include -#include - -#include "./pbl-string.h" -#include "./pbl-types.h" - -#ifndef PBL_MODULES_IO_H -#define PBL_MODULES_IO_H - -#ifdef __cplusplus -extern "C" { -#endif - -// ---- Declarations -------------------------------------------------------------------------------------------------- - -// ---- File ---------------------------------------------------------------------------------------------------------- - -/// @brief (Never use this for malloc - this only indicates the usable memory space) -/// @returns The size of the type 'PblFile_T' in bytes -#define PblFile_T_Size sizeof(FILE *) -/// @brief Returns the declaration default for the type 'PblFile_T' -#define PblFile_T_DeclDefault PBL_DECLARATION_CONSTRUCTOR(PblFile_T) -/// @brief Returns the definition default for the type 'PblFile_T', where only value itself has been created -#define PblFile_T_DefDefault PBL_DEFINITION_SINGLE_CONSTRUCTOR(PblFile_T, NULL) - -/// @brief File Descriptor used to perform I/O actions on a file -struct PblFile PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(FILE*) -/// @brief File Descriptor used to perform I/O actions on a file -typedef struct PblFile PblFile_T; - -// ---- Stream -------------------------------------------------------------------------------------------------------- - -/// @brief (Never use this for malloc - this only indicates the usable memory space) -/// @returns The size of the type 'PblStream_T' in bytes -#define PblStream_T_Size (sizeof(PblUInt_T*) + sizeof(PblFile_T*) + sizeof(PblBool_T*) + sizeof(PblString_T*)) -/// @brief Returns the declaration default for the type 'PblStream_T' -#define PblStream_T_DeclDefault PBL_DECLARATION_CONSTRUCTOR(PblStream_T) -/// @brief Returns the definition default for the type 'PblStream_T', where the children have not been set yet and only the -/// value itself 'exists' already. -#define PblStream_T_DefDefault \ - PBL_DEFINITION_STRUCT_CONSTRUCTOR(PblStream_T, .fd = NULL, .file = NULL, .open = NULL, .mode = NULL) - -/// @brief Base Struct of PblString - avoid using this type -struct PblStream_Base { - /// @brief The unique integer identifier associated with the file Descriptor - PblUInt_T *fd; - /// @brief The FILE pointer, which points to the stream/file - defined if the stream was opened - PblFile_T *file; - /// @brief Describes whether the file descriptor is currently in use - PblBool_T *open; - /// @brief The mode the FILE* was opened - PblString_T *mode; -}; - -/// @brief File Stream used to perform I/O actions on a file -struct PblStream PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(struct PblStream_Base) -/// @brief File Stream used to perform I/O actions on a file -typedef struct PblStream PblStream_T; - -// ---- Streams ------------------------------------------------------------------------------------------------------- - -/// @brief Standard stream for getting input on the default program console -#define PBL_STREAM_STDIN \ - PBL_DEFINITION_STRUCT_CONSTRUCTOR(PblStream_T, .fd = PblGetUIntT(0), .file = PblGetFileT(stdin), \ - .open = PblGetBoolT(true), .mode = PblGetStringT("a")) - -/// @brief Standard stream for outputting to the default program console -#define PBL_STREAM_STDOUT \ - PBL_DEFINITION_STRUCT_CONSTRUCTOR(PblStream_T, .fd = PblGetUIntT(1), .file = PblGetFileT(stdout), \ - .open = PblGetBoolT(true), .mode = PblGetStringT("a")) - -/// @brief Standard stream for outputting error messages to the default program console -#define PBL_STREAM_STDERR \ - PBL_DEFINITION_STRUCT_CONSTRUCTOR(PblStream_T, .fd = PblGetUIntT(2), .file = PblGetFileT(stderr), \ - .open = PblGetBoolT(true), .mode = PblGetStringT("a")) - -// ---- Handler functions --------------------------------------------------------------------------------------------- - -/** - * @brief Converts the low level C-Type to a PBL File type - * @param val The FILE pointer C-type - * @return The newly created PBL File type - * @note This is a C to Para-C type conversion function - args are in C therefore - */ -PblFile_T* PblGetFileT(FILE *val); - -/** - * @brief Converts the low level C-Type to a PBL Stream type. Creates the FILE* pointer as well - * @param fd The file descriptor that will be converted - * @param mode The mode that should be used to open the FILE* - * @return The newly created PBL Stream type - * @note This is a C to Para-C type conversion function - args are therefore in C - */ -PblStream_T* PblGetStreamT(int fd, const char *mode); - -/// Arguments struct for PblPrint (PblPrintOverhead) -struct PblPrint_Args { - PblString_T *out; - PblStream_T *stream; - PblChar_T *end; -}; - -/** - * @brief Prints the content of the passed string - * @param out The string that should be printed out - * @param stream The stream it should be printed onto - * @param end The end character that should be printed after 'out' - * @note This is the base function that is wrapped using 'PblPrintOverhead' - */ -PblVoid_T PblPrint_Base(PblString_T *out, const PblStream_T *stream, const PblChar_T *end); - -/** - * @brief Printing overhead for 'PblPrintBase' - this it the function called by the macro 'PblPrint' - * @param in The parameter struct - */ -PblVoid_T PblPrint_Overhead(struct PblPrint_Args in); - -/** - * @brief Prints the content of the passed string - * @param out The string that should be printed out (Pointer) - * @param stream The stream it should be printed onto - * @param end The end character that should be printed after 'out' - */ -#define PblPrint(...) PblPrint_Overhead((struct PblPrint_Args){__VA_ARGS__}); - -#ifdef __cplusplus -} -#endif - -#endif //PBL_MODULES_IO_H diff --git a/include/pbl/pbl-mem.c b/include/pbl/pbl-mem.c deleted file mode 100644 index 3f8a74d..0000000 --- a/include/pbl/pbl-mem.c +++ /dev/null @@ -1,72 +0,0 @@ -/// @file pbl-mem.c -/// @brief Para-C memory management and handling implementation based on `malloc.h` and `gc.h` (Hans-J. Boehm garbage -/// collector) -/// @author Luna-Klatzer -/// @date 2021-11-23 -/// @copyright Copyright (c) 2021 - -#include "./pbl-mem.h" -#include "./pbl-types.h" -#include "string.h" - -void* PblMemCpy(void* dest, const void * src, size_t bytes) { - if (dest == NULL) { PBL_LOG_CPY_FROM_NULL_PTR } - if (src == NULL) { PBL_LOG_CPY_TO_NULL_PTR } - - void* ret_ptr = memcpy(dest, src, bytes); - if (ret_ptr == NULL) { PBL_LOG_CPY_RECEIVE_NULL_PTR } - return ret_ptr; -} - -void *PblValPtr(void *ptr) { - // Crash on invalid input - Don't bother raising exceptions on this low-level area - if (ptr == NULL) { PBL_LOG_ACCESS_ERR_NULL_PTR } - return ptr; -} - -void PblFree(void *ptr) { - // Crash on invalid input - Don't bother raising exceptions on this low-level area - if (ptr == NULL) { PBL_LOG_FREE_ERR_NULL_PTR } - GC_FREE(ptr); - - // old pointer is invalid - ptr = NULL; -} - -void *PblMalloc(size_t size) { - // Crash on invalid input - Don't bother raising exceptions on this low-level area - if (size <= 0) { - PBL_LOG_ALLOC_ERR_NULL_SZ - } - - // allocating the memory - void *ptr = GC_MALLOC(size); - if (ptr == NULL) { PBL_LOG_ALLOC_ERR_RECEIVE_NULL_RET } - return ptr; -} - -void *PblMallocAtomic(size_t size) { - // Crash on invalid input - Don't bother raising exceptions on this low-level area - if (size <= 0) { - PBL_LOG_ALLOC_ERR_NULL_SZ - } - - // allocating the memory - void *ptr = GC_MALLOC_ATOMIC(size); - if (ptr == NULL) { PBL_LOG_ALLOC_ERR_RECEIVE_NULL_RET } - return ptr; -} - -void *PblRealloc(void *ptr, size_t size) { - // Crash on invalid input - Don't bother raising exceptions on this low-level area - if (ptr == NULL) { PBL_LOG_REALLOC_ERR_NULL_PTR } - if (size <= 0) { PBL_LOG_REALLOC_ERR_NULL_SZ } - - // re-allocating the memory - void *new_ptr = GC_REALLOC(ptr, size); - if (new_ptr == NULL) { PBL_LOG_REALLOC_ERR_RECEIVE_NULL_RET } - - // old pointer is invalid - if (new_ptr != ptr) ptr = NULL; - return new_ptr; -} diff --git a/include/pbl/pbl-string.h b/include/pbl/pbl-string.h deleted file mode 100644 index 91c87a3..0000000 --- a/include/pbl/pbl-string.h +++ /dev/null @@ -1,162 +0,0 @@ -/// @file pbl-string.h -/// @brief String Implementation based on dynamic memory allocation - This is an optimised form of char[], which is -/// though not equal to PblChar_T[], as it does not contain meta-data tracking for each char, but altogether as an -/// entire type to save memory. -/// @author Luna-Klatzer -/// @date 2021-11-23 -/// @copyright Copyright (c) 2021 - -#include "./pbl-types.h" - -#ifndef PBL_MODULES_STRING_H -#define PBL_MODULES_STRING_H - -#ifdef __cplusplus -extern "C" { -#endif - -// ---- Declaration --------------------------------------------------------------------------------------------------- - -/// @brief Size of the type 'PblString_T' in bytes -#define PblString_T_Size (sizeof(PblSize_T*) + sizeof(PblUInt_T*) + sizeof(PblUInt_T*) + sizeof(char *)) -/// @brief Returns the declaration default for the type 'PblString_T' -#define PblString_T_DeclDefault PBL_DECLARATION_CONSTRUCTOR(PblString_T) -/// @brief Returns the definition default, for the type 'PblString_T', where the children have not been set yet and -/// only the value itself 'exists' already. -#define PblString_T_DefDefault \ - PBL_DEFINITION_STRUCT_CONSTRUCTOR(PblString_T, .allocated_len = NULL, .len = NULL, .str = NULL) - -/// @brief Base Struct of PblString - avoid using this type -struct PblString_Base { - /// @brief Amount of the chars that can be written to - includes null char (\0). This does not include the meta info - PblUInt_T *allocated_len; - /// @brief The length of the string - this is the length that it will take to reach the null character '\0' - PblUInt_T *len; - /// @brief The char* pointer to the allocated memory - the entire memory represents the array, meaning it's not an - /// array of PblChar_T pointers, but an actual block of PblChar_T types being stuck together in memory, meaning array - /// arithmetics are valid! - PblChar_T *str; -}; - -/// @brief PBL String implementation - uses dynamic memory allocation -> located in heap -struct PblString PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(struct PblString_Base) -typedef struct PblString PblString_T; - -// ---- Handler functions --------------------------------------------------------------------------------------------- - -/** - * @brief Gets the Length of a C string (const char*) - * @param content The char array (pointer) - * @return The length as Para-C Int - */ -PblUInt_T *PblGetLengthOfCString(const char *content); - -/** - * @brief Converts the passed char* array to a PblChar_T array - * @param content The C char array - * @param len The length that shall be used to initialise the array. This length must be exact! - * @return The newly allocated string - * @note This is a C to Para-C type conversion function - args are in C therefore - */ -PblChar_T *PblGetCharTArray(const char *content); - -/** - * @brief This directly converts a char* to a Para-C string type - * @param content The char array (pointer) - * @return The new Para-C string type, which was created using 'PblAllocateStringContentT' - * @note This is a C to Para-C type conversion function - args are in C therefore - */ -PblString_T *PblGetStringT(const char *content); - -/** - * @brief Compares the two passed strings and returns whether they are equal - * @param str_1 The first string - * @param str_2 The second string - * @return True whether it's the same else false - */ -PblBool_T *PblCompareStringT(PblString_T *str_1, PblString_T *str_2); - -/** - * @brief Gets the required minimum array size for the string - * @param len The length of the string that should be allocated - * @return The length as PblUInt_T - */ -PblUInt_T* PblGetMinimumArrayLen(PblUInt_T* len); - -/** - * @brief Gets the required byte_size for an allocation based on the passed length of the string. - * @note The algorithm will always be a multiple of 50 + 1 (for null char '\0'). - * The calculated size is the next biggest multiple of 50 + 1, which is still bigger than the passed length. - * @param len The length of the actual string content, which will be used to calculate the allocation length. - * @returns The size as size_t (int) - */ -PblSize_T *PblGetAllocSizeStringT(PblUInt_T *len); - -/** - * @brief Resizes the string by reallocating the memory. - * @note Automatically calculates the size of the new allocated memory based on the length. The function used for the - * length calculation is 'PblGetAllocSizeStringT' - * @param str The string that should be reallocated - * @param len The length of the string content that is used to calculate the required size - */ -PblVoid_T PblResizeStringT(PblString_T *str, PblUInt_T *len); - -/** - * @brief Converts the passed PblChar_T array into a native C char array - * @param str The string that should be used - * @return The char* array - */ -char* PblGetCCharArrayFromCharT(PblChar_T* char_arr, PblUInt_T* len); - -/** - * @brief Converts the passed string into a native C char array - * @param str The string that should be used - * @return The char* array - */ -char* PblGetCCharArrayFromString(PblString_T* str); - -/** - * @brief Writes onto the allocated memory the passed string content (PblChar_T) - * @param len Length of the string (should not include null char) - * @param content The content of the string that should be written to the allocated memory - C type as this should be - * used in the back of the program - */ -PblVoid_T PblWriteCharArrayToStringT(PblString_T *str, PblChar_T *content, PblUInt_T *len_to_write); - -/** - * @brief Writes onto the allocated memory the passed string content - * @param len Length of the string (should not include null char) - * @param content The content of the string that should be written to the allocated memory - C type as this should be - * used in the back of the program - */ -PblVoid_T PblWriteStringToStringT(PblString_T *str, PblString_T *content, PblUInt_T *len_to_write); - -/** - * @brief Allocates new memory for a new string - * @note Default size/len is 50 - will be resized with additional space required using 'PblGetAllocSizeStringT' - * @param len Length of the string - will be used to calculate allocated memory space (should not include null char) - * @param content The content of the string that should be written to the allocated memory - C type as this should be - * used for converting char * and char[] to PblString_T - * @returns The new string type that was allocated - */ -PblString_T *PblCreateStringT(PblChar_T *content, PblUInt_T *len); - -/** - * @brief Allocates new memory for a new string - this function automatically calculates the minimum allocation size - * @param byte_size The byte_size that should be allocated - * @returns The char* pointer to the memory - */ -PblChar_T *PblAllocateStringContentT(PblUInt_T *len); - -/** - * @brief Deallocates the entire memory for the string and resets it's struct properties - * @note Writes to the string with '\0' before freeing the memory - * @param lvalue The value that should be de-allocated - */ -PblVoid_T PblDeallocateStringT(PblString_T *lvalue); - -#ifdef __cplusplus -} -#endif - -#endif //PBL_MODULES_STRING_H diff --git a/include/pbl/pbl-types.c b/include/pbl/pbl-types.c deleted file mode 100644 index 317ecab..0000000 --- a/include/pbl/pbl-types.c +++ /dev/null @@ -1,69 +0,0 @@ -/// @file pbl-types.c -/// @brief Para-C Base Types Implementation, which contains handler macros, conversion functions, default declaration, -/// default definition types and default size macros. This also includes meta-data tracking based on the -/// 'PblMetaVarCtx_T' type. -/// @author Luna-Klatzer -/// @date 2021-11-23 -/// @copyright Copyright (c) 2021 - -#include "./pbl-types.h" - -PblBool_T* PblGetBoolT(bool val) { - PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblBool_T, bool) -} - -PblSize_T* PblGetSizeT(size_t val) { - PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblSize_T, size_t) -} - -PblChar_T* PblGetCharT(signed char val) { - PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblChar_T, signed char) -} - -PblUChar_T* PblGetUCharT(unsigned char val) { - PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblUChar_T, unsigned char) -} - -PblShort_T* PblGetShortT(signed short val) { - PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblShort_T, signed short) -} - -PblUShort_T* PblGetUShortT(unsigned short val) { - PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblUShort_T, unsigned short) -} - -PblInt_T* PblGetIntT(signed int val) { - PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblInt_T, signed int) -} - -PblUInt_T* PblGetUIntT(unsigned int val) { - PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblUInt_T, unsigned int) -} - -PblLong_T* PblGetLongT(signed long val) { - PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblLong_T, signed long) -} - -PblULong_T* PblGetULongT(unsigned long val) { - PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblULong_T, unsigned long) -} - -PblLongLong_T* PblGetLongLongT(signed long long val) { - PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblLongLong_T, signed long long) - } - -PblULongLong_T* PblGetULongLongT(unsigned long long val) { - PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblULongLong_T, unsigned long long) -} - -PblFloat_T* PblGetFloatT(float val) { - PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblFloat_T, float) -} - -PblDouble_T* PblGetDoubleT(double val) { - PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblDouble_T, double) -} - -PblLongDouble_T* PblGetLongDoubleT(long double val) { - PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblLongDouble_T, long double) -} \ No newline at end of file diff --git a/include/pbl/pbl-types.h b/include/pbl/pbl-types.h deleted file mode 100644 index 4070ae1..0000000 --- a/include/pbl/pbl-types.h +++ /dev/null @@ -1,505 +0,0 @@ -/// @file pbl-types.h -/// @brief Para-C Base Types Implementation, which contains handler macros, conversion functions, default declaration, -/// default definition types and default size macros. This also includes meta-data tracking based on the -/// 'PblMetaVarCtx_T' type. -/// @author Luna-Klatzer -/// @date 2021-11-23 -/// @copyright Copyright (c) 2021 - -#include -#include - -#include "./pbl-mem.h" -#include "./additional/va-opt.h" - -#ifndef PBL_MODULES_TYPES_H -#define PBL_MODULES_TYPES_H - -#ifdef __cplusplus -extern "C" { -#endif -// ---- Macro Functions ----------------------------------------------------------------------------------------------- - -/// @brief Returns the effective size of a Para-C type that can be actually used. Must be a Para-C type -#define PBL_SIZEOF(type) (type##_Size) - -/// @brief Returns the effective C size of a type. This also includes meta data -#define PBL_C_SIZEOF(type) (sizeof(type)) - -// ---- All Base types implemented in the Para-C style ---------------------------------------------------------------- - -/// @brief Base Meta Type contained in ALL variables - has no DeclDefault or DefDefault -struct PblMetaVarCtx { - /// @brief Returns whether the variable is defined. This defaults to false (unless a declaration is use, where accessing the - /// variable is undefined behaviour. This means it should IN NO CASE BE accessed when it's only declared) - /// This variable is used to also validate whether a variable can be accessed without raising an error! - bool defined; -}; - -/// @brief Base Meta Type contained in ALL variables -typedef struct PblMetaVarCtx PblMetaVarCtx_T; - -// ---- Get type macro ------------------------------------------------------------------------------------------------ - -/// @brief This macro initialises an actual instance of a type, instead of allocating it, like the GetTypeT functions -/// This should be used to save memory in the background, but not actually for the user to preserve the functionality -/// @note This should only be used when wanting the actual type itself written onto a variable -#define PBL_GET_ACTUAL_TYPE_INSTANCE(to_write, type, write_val) \ - (to_write) = type##_DefDefault; \ - (to_write).actual = write_val; - -/// @brief This macro allocates an empty declaration instance of a type, which has no actual value set yet -/// @note This should only be used when creating a declaration of a Para-C type -#define PBL_ALLOC_DECLARATION(to_write, type) \ - type *to_write = (type *) PblMalloc(sizeof(type)); \ - *(to_write) = type##_DeclDefault; - -/// @brief This macro allocates an instance of type, which has the default initialisation value set -/// @note This should only be used when creating a definition that shall be empty - if it's though a conversion from C -/// to Para-C the defined GetTypeT(...) function should be used, which will properly allocate and write to the variable -#define PBL_ALLOC_DEFINITION(to_write, type) \ - type *to_write = (type *) PblMalloc(sizeof(type)); \ - *(to_write) = type##_DefDefault; - -/// @brief This macro should serve as a helper for writing static arrays that shall be used to store types -/// @note This should not be used as a replacement to PblIterable_T, but only as a memory-efficient helper for copying -/// or setting memory values -#define PBL_ALLOC_ARRAY_DEFINITION(to_write, type, amount) \ - type *to_write = (type *) PblMalloc(sizeof(type) * (amount)); \ - for (int i = 0; i < (amount); i++) { \ - (to_write)[i] = type##_DefDefault; \ - } - - -// ---- Constructor Macros -------------------------------------------------------------------------------------------- - -/// @brief Declaration constructor which initialised the meta data for the passed type -#define PBL_DECLARATION_CONSTRUCTOR(type) \ - (type) { \ - .meta = {.defined = false } \ - } - -/// @brief Definition constructor, which initialises the type with the passed __VA_ARGS__, if they are empty, the value -/// will be only set as defined (meta), but not contain any values -#define PBL_DEFINITION_IF_VA_ARGS_CONSTRUCTOR(type, ...) \ - (type) { .meta = {.defined = true}, IFN(__VA_ARGS__)(__VA_ARGS__) } - -/// @brief Definition constructor, which initialises the meta data for the passed type and passes to '.actual' the args -/// as struct -#define PBL_DEFINITION_STRUCT_CONSTRUCTOR(type, ...) \ - (type) { \ - .meta = {.defined = true}, .actual = { __VA_ARGS__ } \ - } - -/// @brief Definition constructor, which initialised the meta data for the passed type and passes to '.actual' the -/// single arg -#define PBL_DEFINITION_SINGLE_CONSTRUCTOR(type, var_actual) \ - (type) { .meta = {.defined = true}, .actual = (var_actual) } - -/// @brief Creates the body for a Para-C type definition wrapper - the base_type is the actual value/struct -#define PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(base_type) { \ - PblMetaVarCtx_T meta; \ - base_type actual; \ - }; - - -// ---- Local Variable state saving ----------------------------------------------------------------------------------- - -/// @brief Copies the passed value to a local state copy - This is designed for pointers losing their addresses -/// @note There may only be a single value copy with this unique_id! -#define PBL_CREATE_ADDRESS_COPY(var, type, unique_id) type unique_id##_localcpy = var; - -/// @brief Writes back to the original variable the state copy - This is designed for pointers losing their addresses -/// @note If the var is NULL, then the address will be restored -#define PBL_PASTE_ADDRESS_COPY(var, type, unique_id) \ - if (var == NULL) { \ - var = unique_id##_localcpy; \ - unique_id##_localcpy = NULL; \ - } - -// ---- Void Type ----------------------------------------------------------------------------------------------------- - -/// @brief (Never use this for malloc - this only indicates the usable memory space) -/// @returns The size in bytes of the PBL PblVoid_T type -#define PblVoid_T_Size 0 -/// @brief Returns the declaration default for the type 'PblVoid_T' -#define PblVoid_T_DeclDefault PBL_DECLARATION_CONSTRUCTOR(PblVoid_T) -/// @brief Returns the definition default, for the type 'PblVoid_T', where only value itself has been created -#define PblVoid_T_DefDefault PBL_DEFINITION_STRUCT_CONSTRUCTOR(PblVoid_T, ) - -/// @brief PBL Void implementation -struct PblVoid { - /// @brief Meta-data tracking, as this value will never have anything accessible - PblMetaVarCtx_T meta; -}; -/// @brief PBL Void implementation -typedef struct PblVoid PblVoid_T; - -// ---- Numeric Values ------------------------------------------------------------------------------------------------ -// All types that are not unsigned are signed by default to ensure consistency -// Note that in those definitions the size is calculated using the C-type (as only one "real" property is there) - -// ---- Bool ---------------------------------------------------------------------------------------------------------- - -/// @brief (Never use this for malloc - this only indicates the usable memory space) -/// @@returns The size in bytes of the PBL Bool type -#define PblBool_T_Size sizeof(bool) -/// @returns The declaration default for the type 'PblBool_T' -#define PblBool_T_DeclDefault PBL_DECLARATION_CONSTRUCTOR(PblBool_T) -/// @returns The definition default, for the type 'PblBool_T', where only value itself has been created -#define PblBool_T_DefDefault PBL_DEFINITION_SINGLE_CONSTRUCTOR(PblBool_T, false) - -/// @brief PBL Bool implementation -struct PblBool PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(bool) -/// @brief PBL Bool implementation -typedef struct PblBool PblBool_T; - -// ---- Byte Size ----------------------------------------------------------------------------------------------------- - -/// @brief (Never use this for malloc - this only indicates the usable memory space) -/// @returns The size in bytes of the PBL Size type -#define PblSize_T_Size sizeof(size_t) -/// @returns The declaration default for the type 'PblSize_T' -#define PblSize_T_DeclDefault PBL_DECLARATION_CONSTRUCTOR(PblSize_T) -/// @returns The definition default, for the type 'PblSize_T', where only value itself has been created -#define PblSize_T_DefDefault PBL_DEFINITION_SINGLE_CONSTRUCTOR(PblSize_T, 0) - -/// @brief PBL Byte Size implementation -struct PblSize PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(size_t) -/// @brief PBL Byte Size implementation -typedef struct PblSize PblSize_T; - -// ---- Char ---------------------------------------------------------------------------------------------------------- - -/// @brief (Never use this for malloc - this only indicates the usable memory space) -/// @returns The size in bytes of the PBL Signed Char type -#define PblChar_T_Size sizeof(signed char) -/// @returns The declaration default for the type 'PblChar_T' -#define PblChar_T_DeclDefault PBL_DECLARATION_CONSTRUCTOR(PblChar_T) -/// @returns The definition default, for the type 'PblChar_T', where only value itself has been created -#define PblChar_T_DefDefault PBL_DEFINITION_SINGLE_CONSTRUCTOR(PblChar_T, 0) - -/// @brief PBL Signed Char implementation -struct PblChar PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(signed char) -/// @brief PBL Signed Char implementation -typedef struct PblChar PblChar_T; - -// ---- UChar --------------------------------------------------------------------------------------------------------- - -/// @brief (Never use this for malloc - this only indicates the usable memory space) -/// @returns The size in bytes of the PBL Unsigned Char type -#define PblUChar_T_Size sizeof(unsigned char) -/// @returns The declaration default for the type 'PblUChar_T_Size' -#define PblUChar_T_DeclDefault PBL_DECLARATION_CONSTRUCTOR(PblUChar_T) -/// @returns The definition default, for the type 'PblUChar_T', where only value itself has been created -#define PblUChar_T_DefDefault PBL_DEFINITION_SINGLE_CONSTRUCTOR(PblUChar_T, 0) - -/// @brief PBL Unsigned Char implementation -struct PblUChar PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(unsigned char) -/// @brief PBL Unsigned Char implementation -typedef struct PblUChar PblUChar_T; - -// ---- Short --------------------------------------------------------------------------------------------------------- - -/// @brief (Never use this for malloc - this only indicates the usable memory space) -/// @returns The size in bytes of the PBL Signed Short type -#define PblShort_T_Size sizeof(signed short) -/// @returns The declaration default for the type 'PblShort_T' -#define PblShort_T_DeclDefault PBL_DECLARATION_CONSTRUCTOR(PblShort_T) -/// @returns The definition default, for the type 'PblShort_T', where only value itself has been created -#define PblShort_T_DefDefault PBL_DEFINITION_SINGLE_CONSTRUCTOR(PblShort_T, 0) - -/// @brief PBL Signed Short implementation -struct PblShort PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(signed short) -/// @brief PBL Signed Short implementation -typedef struct PblShort PblShort_T; - -// ---- UShort -------------------------------------------------------------------------------------------------------- - -/// @brief (Never use this for malloc - this only indicates the usable memory space) -/// @returns The size in bytes of the PBL Unsigned Short type -#define PblUShort_T_Size sizeof(unsigned short) -/// @returns The declaration default for the type 'PblUShort_T_Size' -#define PblUShort_T_DeclDefault PBL_DECLARATION_CONSTRUCTOR(PblUShort_T) -/// @returns The definition default, for the type 'PblUShort_T', where only value itself has been created -#define PblUShort_T_DefDefault PBL_DEFINITION_SINGLE_CONSTRUCTOR(PblUShort_T, 0) - -/// @brief PBL Unsigned Short implementation -struct PblUShort PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(unsigned short) -/// @brief PBL Unsigned Short implementation -typedef struct PblUShort PblUShort_T; - -// ---- Int ----------------------------------------------------------------------------------------------------------- - -/// @brief (Never use this for malloc - this only indicates the usable memory space) -/// @returns The size in bytes of the PBL Signed Int type -#define PblInt_T_Size sizeof(signed int) -/// @returns The declaration default for the type 'PblInt_T' -#define PblInt_T_DeclDefault PBL_DECLARATION_CONSTRUCTOR(PblInt_T) -/// @returns The definition default, for the type 'PblInt_T', where only value itself has been created -#define PblInt_T_DefDefault PBL_DEFINITION_SINGLE_CONSTRUCTOR(PblInt_T, 0) - -/// @brief PBL Signed Int implementation -struct PblInt PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(signed int) -/// @brief PBL Signed Int implementation -typedef struct PblInt PblInt_T; - -// ---- UInt ---------------------------------------------------------------------------------------------------------- - -/// @brief (Never use this for malloc - this only indicates the usable memory space) -/// @returns The size in bytes of the PBL Unsigned Int type -#define PblUInt_T_Size sizeof(unsigned int) -/// @returns The declaration default for the type 'PblUInt_T' -#define PblUInt_T_DeclDefault PBL_DECLARATION_CONSTRUCTOR(PblUInt_T) -/// @returns The definition default, for the type 'PblUInt_T', where only value itself has been created -#define PblUInt_T_DefDefault PBL_DEFINITION_SINGLE_CONSTRUCTOR(PblUInt_T, 0) - -/// @brief PBL Unsigned Int implementation -struct PblUInt PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(unsigned int) -/// @brief PBL Unsigned Int implementation -typedef struct PblUInt PblUInt_T; - -// ---- Long ---------------------------------------------------------------------------------------------------------- - -/// @brief (Never use this for malloc - this only indicates the usable memory space) -/// @returns The size in bytes of the PBL Signed Long type -#define PblLong_T_Size sizeof(signed long) -/// @returns The declaration default for the type 'PblLong_T' -#define PblLong_T_DeclDefault PBL_DECLARATION_CONSTRUCTOR(PblLong_T) -/// @returns The definition default, for the type 'PblLong_T', where only value itself has been created -#define PblLong_T_DefDefault PBL_DEFINITION_SINGLE_CONSTRUCTOR(PblLong_T, 0) - -/// @brief PBL Signed Long implementation -struct PblLong PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(signed long) -/// @brief PBL Signed Long implementation -typedef struct PblLong PblLong_T; - -// ---- ULong --------------------------------------------------------------------------------------------------------- - -/// @brief (Never use this for malloc - this only indicates the usable memory space) -/// @returns The size in bytes of the PBL Unsigned Long type -#define PblULong_T_Size sizeof(unsigned long) -/// @returns The declaration default for the type 'PblULong_T' -#define PblULong_T_DeclDefault PBL_DECLARATION_CONSTRUCTOR(PblULong_T) -/// @returns The definition default, for the type 'PblULong_T', where only value itself has been created -#define PblULong_T_DefDefault PBL_DEFINITION_SINGLE_CONSTRUCTOR(PblULong_T, 0) - -/// @brief PBL Unsigned Long implementation -struct PblULong PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(unsigned long) -/// @brief PBL Unsigned Long implementation -typedef struct PblULong PblULong_T; - -// ---- Long Long ----------------------------------------------------------------------------------------------------- - -/// @brief (Never use this for malloc - this only indicates the usable memory space) -/// @returns The size in bytes of the PBL Signed Long Long type -#define PblLongLong_T_Size sizeof(signed long long) -/// @returns The declaration default for the type 'PblLongLong_T' -#define PblLongLong_T_DeclDefault PBL_DECLARATION_CONSTRUCTOR(PblLongLong_T) -/// @returns The definition default, for the type 'PblLongLong_T', where only value itself has been created -#define PblLongLong_T_DefDefault PBL_DEFINITION_SINGLE_CONSTRUCTOR(PblLongLong_T, 0) - -/// @brief PBL Signed Long Long implementation -struct PblLongLong PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(signed long long) -/// @brief PBL Signed Long Long implementation -typedef struct PblLongLong PblLongLong_T; - -// ---- ULong Long ---------------------------------------------------------------------------------------------------- - -/// @brief (Never use this for malloc - this only indicates the usable memory space) -/// @returns The size in bytes of the PBL Unsigned Long Long type -#define PblULongLong_T_Size sizeof(unsigned long long) -/// @returns The declaration default for the type 'PblULongLong_T' -#define PblULongLong_T_DeclDefault PBL_DECLARATION_CONSTRUCTOR(PblULongLong_T) -/// @returns The definition default, for the type 'PblULongLong_T', where only value itself has been created -#define PblULongLong_T_DefDefault PBL_DEFINITION_SINGLE_CONSTRUCTOR(PblULongLong_T, 0) - -/// @brief PBL Unsigned Long Long implementation -struct PblULongLong PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(unsigned long long) -/// @brief PBL Unsigned Long Long implementation -typedef struct PblULongLong PblULongLong_T; - -// ---- Float --------------------------------------------------------------------------------------------------------- - -/// @brief (Never use this for malloc - this only indicates the usable memory space) -/// @returns The size in bytes of the PBL Float type -#define PblFloat_T_Size sizeof(float) -/// @returns The declaration default for the type 'PblFloat_T' -#define PblFloat_T_DeclDefault PBL_DECLARATION_CONSTRUCTOR(PblFloat_T) -/// @returns The definition default, for the type 'PblFloat_T', where only value itself has been created -#define PblFloat_T_DefDefault PBL_DEFINITION_SINGLE_CONSTRUCTOR(PblFloat_T, 0) - -/// @brief PBL Float implementation -struct PblFloat PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(float) -/// @brief PBL Float implementation -typedef struct PblFloat PblFloat_T; - -// ---- Double -------------------------------------------------------------------------------------------------------- - -/// @brief (Never use this for malloc - this only indicates the usable memory space) -/// @returns The size in bytes of the PBL Double type -#define PblDouble_T_Size sizeof(double) -/// @returns The declaration default for the type 'PblDouble_T' -#define PblDouble_T_DeclDefault PBL_DECLARATION_CONSTRUCTOR(PblDouble_T) -/// @returns The definition default, for the type 'PblDouble_T', where only value itself has been created -#define PblDouble_T_DefDefault PBL_DEFINITION_SINGLE_CONSTRUCTOR(PblDouble_T, 0) - -/// @brief PBL Double implementation -struct PblDouble PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(double) -/// @brief PBL Double implementation -typedef struct PblDouble PblDouble_T; - -// ---- Long Double --------------------------------------------------------------------------------------------------- - -/// @brief (Never use this for malloc - this only indicates the usable memory space) -/// @returns The size in bytes of the PBL Long Double type -#define PblLongDouble_T_Size sizeof(long double) -/// @returns The declaration default for the type 'PblLongDouble_T' -#define PblLongDouble_T_DeclDefault PBL_DECLARATION_CONSTRUCTOR(PblLongDouble_T) -/// @returns The definition default, for the type 'PblLongDouble_T', where only value itself has been created -#define PblLongDouble_T_DefDefault PBL_DEFINITION_SINGLE_CONSTRUCTOR(PblLongDouble_T, 0) - -/// @brief PBL Long Double implementation -struct PblLongDouble PBL_TYPE_DEFINITION_WRAPPER_CONSTRUCTOR(long double) -/// @brief PBL Long Double implementation -typedef struct PblLongDouble PblLongDouble_T; - -// ---- Helper Functions ---------------------------------------------------------------------------------------------- - -/// This a macro function definition body constructor, which should be used to directly convert C types into their -/// Para-C counterparts. This should be only used for Para-C types that have as actual a single property, as this does -/// not support complex initialisation. -#define PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(parac_type, c_type) \ - { \ - parac_type* conv = PblMalloc(sizeof(parac_type)); \ - *conv = parac_type##_DefDefault; \ - conv->actual = (c_type) val; \ - return conv; \ - } - -/** - * @brief Converts the low level C-Type to a PBL Bool type - * @param val The C-type to be converted - * @return The newly created PBL Bool type - * @note This is a C to Para-C type conversion function - args are in C therefore - * @ - */ -PblBool_T* PblGetBoolT(bool val); - -/** -* @brief Converts the low level C-Type to a PBL Byte Size type -* @param val The C-type to be converted -* @return The newly created PBL Byte Size type -* @note This is a C to Para-C type conversion function - args are in C therefore -*/ -PblSize_T* PblGetSizeT(size_t val); - -/** -* @brief Converts the low level C-Type to a PBL Char type -* @param val The C-type to be converted -* @return The newly created PBL Char type -* @note This is a C to Para-C type conversion function - args are in C therefore -*/ -PblChar_T* PblGetCharT(signed char val); - -/** -* @brief Converts the low level C-Type to a PBL Unsigned Char type -* @param val The C-type to be converted -* @return The newly created PBL Char type -* @note This is a C to Para-C type conversion function - args are in C therefore -*/ -PblUChar_T* PblGetUCharT(unsigned char val); - -/** -* @brief Converts the low level C-Type to a PBL Short type -* @param val The C-type to be converted -* @return The newly created PBL Char type -* @note This is a C to Para-C type conversion function - args are in C therefore -*/ -PblShort_T* PblGetShortT(signed short val); - -/** -* @brief Converts the low level C-Type to a PBL Unsigned Short type -* @param val The C-type to be converted -* @return The newly created PBL Char type -* @note This is a C to Para-C type conversion function - args are in C therefore -*/ -PblUShort_T* PblGetUShortT(unsigned short val); - -/** -* @brief Converts the low level C-Type to a PBL Int type -* @param val The C-type to be converted -* @return The newly created PBL Char type -* @note This is a C to Para-C type conversion function - args are in C therefore -*/ -PblInt_T* PblGetIntT(signed int val); - -/** -* @brief Converts the low level C-Type to a PBL Unsigned Int type -* @param val The C-type to be converted -* @return The newly created PBL Char type -* @note This is a C to Para-C type conversion function - args are in C therefore -*/ -PblUInt_T* PblGetUIntT(unsigned int val); - -/** -* @brief Converts the low level C-Type to a PBL Long type -* @param val The C-type to be converted -* @return The newly created PBL Char type -* @note This is a C to Para-C type conversion function - args are in C therefore -*/ -PblLong_T* PblGetLongT(signed long val); - -/** -* @brief Converts the low level C-Type to a PBL Unsigned Long type -* @param val The C-type to be converted -* @return The newly created PBL Char type -* @note This is a C to Para-C type conversion function - args are in C therefore -*/ -PblULong_T* PblGetULongT(unsigned long val); - -/** -* @brief Converts the low level C-Type to a PBL Long Long type -* @param val The C-type to be converted -* @return The newly created PBL Char type -* @note This is a C to Para-C type conversion function - args are in C therefore -*/ -PblLongLong_T* PblGetLongLongT(signed long long val); - -/** -* @brief Converts the low level C-Type to a PBL Unsigned Long Long type -* @param val The C-type to be converted -* @return The newly created PBL Char type -* @note This is a C to Para-C type conversion function - args are in C therefore -*/ -PblULongLong_T* PblGetULongLongT(unsigned long long val); - -/** -* @brief Converts the low level C-Type to a PBL Float type -* @param val The C-type to be converted -* @return The newly created PBL Char type -* @note This is a C to Para-C type conversion function - args are in C therefore -*/ -PblFloat_T* PblGetFloatT(float val); - -/** -* @brief Converts the low level C-Type to a PBL Double type -* @param val The C-type to be converted -* @return The newly created PBL Double type -* @note This is a C to Para-C type conversion function - args are in C therefore -*/ -PblDouble_T* PblGetDoubleT(double val); - -/** -* @brief Converts the low level C-Type to a PBL Long Double type -* @param val The C-type to be converted -* @return The newly created PBL Long Double type -* @note This is a C to Para-C type conversion function - args are in C therefore -*/ -PblLongDouble_T* PblGetLongDoubleT(long double val); - -#ifdef __cplusplus -} -#endif - -#endif //PBL_MODULES_TYPES_H diff --git a/include/pbl/pbl.c b/include/pbl/pbl.c deleted file mode 100644 index 0604e8e..0000000 --- a/include/pbl/pbl.c +++ /dev/null @@ -1,9 +0,0 @@ -/// @file pbl.c -/// @brief Main file for the Para-C Base Library (Static C library) -/// Styling and naming are similar to the Google C++ style guide -/// @see https://google.github.io/styleguide/cppguide.html -/// @author Luna-Klatzer -/// @date 2021-11-23 -/// @copyright Copyright (c) 2021 - -#include "./pbl.h" diff --git a/lib/README.md b/lib/README.md new file mode 100644 index 0000000..fbf9cb6 --- /dev/null +++ b/lib/README.md @@ -0,0 +1,3 @@ +# PBL `lib` folder + +This folder is simply intended to contain the compiled output of the C library. diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..2554993 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,74 @@ +# Defining the directories for source and header files +set(HEADER_INCLUDE_DIRECTORY "${libpbl_SOURCE_DIR}/include") +set(SOURCE_INCLUDE_DIRECTORY "${libpbl_SOURCE_DIR}/src") + +# Logging for debugging purposes the source and header directories +message("SOURCE_INCLUDE_DIRECTORY = ${SOURCE_INCLUDE_DIRECTORY}") +message("HEADER_INCLUDE_DIRECTORY = ${HEADER_INCLUDE_DIRECTORY}") + +# Using glob to get all files that should be included +set(SOURCE_FILES + "${SOURCE_INCLUDE_DIRECTORY}/pbl.c" + "${SOURCE_INCLUDE_DIRECTORY}/pbl-main.c" + "${SOURCE_INCLUDE_DIRECTORY}/types/pbl-any.c" + "${SOURCE_INCLUDE_DIRECTORY}/types/pbl-int.c" + "${SOURCE_INCLUDE_DIRECTORY}/types/pbl-string.c" + "${SOURCE_INCLUDE_DIRECTORY}/types/pbl-types.c" + "${SOURCE_INCLUDE_DIRECTORY}/mem/pbl-mem.c" + "${SOURCE_INCLUDE_DIRECTORY}/mem/pbl-mem-tools.c" + "${SOURCE_INCLUDE_DIRECTORY}/io/pbl-io.c" + "${SOURCE_INCLUDE_DIRECTORY}/func/pbl-function.c" + ) + +set(HEADER_FILES + "${HEADER_INCLUDE_DIRECTORY}/libpbl/pbl.h" + "${HEADER_INCLUDE_DIRECTORY}/libpbl/pbl-main.h" + "${HEADER_INCLUDE_DIRECTORY}/libpbl/types/pbl-any.h" + "${HEADER_INCLUDE_DIRECTORY}/libpbl/types/pbl-int.h" + "${HEADER_INCLUDE_DIRECTORY}/libpbl/types/pbl-string.h" + "${HEADER_INCLUDE_DIRECTORY}/libpbl/types/pbl-types.h" + "${HEADER_INCLUDE_DIRECTORY}/libpbl/mem/pbl-mem.h" + "${HEADER_INCLUDE_DIRECTORY}/libpbl/mem/pbl-mem-tools.h" + "${HEADER_INCLUDE_DIRECTORY}/libpbl/io/pbl-io.h" + "${HEADER_INCLUDE_DIRECTORY}/libpbl/func/pbl-function.h" + "${HEADER_INCLUDE_DIRECTORY}/libpbl/additional/pbl-apply-macro.h" + "${HEADER_INCLUDE_DIRECTORY}/libpbl/additional/va-opt.h") + +# Setting the output for the static library (.a) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${libpbl_SOURCE_DIR}/lib") + +# Adding the static Library +add_library(pbl STATIC ${SOURCE_FILES} ${HEADER_FILES}) + +# Making the /include/libpbl headers available +include_directories(${HEADER_INCLUDE_DIRECTORY} ${SOURCE_INCLUDE_DIRECTORY}) +target_include_directories(pbl PUBLIC ${HEADER_INCLUDE_DIRECTORY} ${SOURCE_INCLUDE_DIRECTORY}) + +# Linking the garbage collector +target_link_libraries(pbl PUBLIC gc-lib) + +# Including the Hans Boehm garbage collector +FetchContent_Declare( + gc-8.0.6 + URL https://github.com/ivmai/bdwgc/releases/download/v8.0.6/gc-8.0.6.tar.gz +) + +# Populating the Library +FetchContent_Populate( + gc-8.0.6 +) + +# Adding the directories into the local references +add_subdirectory(${gc-8.0.6_SOURCE_DIR} ${gc-8.0.6_BINARY_DIR}) +target_include_directories(pbl PUBLIC "${gc-8.0.6_SOURCE_DIR}") +target_include_directories(pbl PUBLIC "${gc-8.0.6_SOURCE_DIR}/include") + +# Hinting the usage of built-in atomic types (since we use C11 as an enforced base standard) +add_compile_definitions(GC_BUILTIN_ATOMIC) + +# IDEs should put the headers in a nice place +source_group( + TREE ${HEADER_INCLUDE_DIRECTORY} + PREFIX "Header Files" + FILES ${HEADER_FILES} +) diff --git a/src/func/pbl-function.c b/src/func/pbl-function.c new file mode 100644 index 0000000..9ac02fd --- /dev/null +++ b/src/func/pbl-function.c @@ -0,0 +1,97 @@ +/// @file pbl-function.c +/// @brief Function-related types and exception implementation. This includes meta data tracking for functions calls, +/// function states, exceptions and tracebacks. +/// @author Luna-Klatzer +/// @date 2021-11-23 +/// @copyright Copyright (c) 2021 + +#include + +// ---- Functions Definitions ----------------------------------------------------------------------------------------- + +PblFunctionCallMetaData_T *PblGetMetaFunctionCallCtxT(PblString_T *function_identifier, PblBool_T *is_failure, + PblUInt_T *arg_amount, PblBool_T *is_threaded, + PblFunctionCallMetaData_T *failure_origin_ctx, + PblFunctionCallMetaData_T *call_origin_ctx, + PblException_T *exception) { + PBL_DEFINE_VAR(ptr, PblFunctionCallMetaData_T); + *ptr = PblFunctionCallMetaData_T_DefDefault; + + ptr->actual = (struct PblFunctionCallMetaData_Base){.function_identifier = function_identifier, + .is_failure = is_failure, + .arg_amount = arg_amount, + .is_threaded = is_threaded, + .failure_origin_ctx = failure_origin_ctx, + .call_origin_ctx = call_origin_ctx, + .exception = exception}; + return ptr; +} + +__attribute__((unused)) PblVoid_T PblDeallocateMetaFunctionCallCtxT(PblFunctionCallMetaData_T *ctx) { + // Validate the pointer for safety measures + ctx = PblValPtr((void *) ctx); + + if (ctx->meta.defined) { + if (ctx->actual.exception != NULL) PblDeallocateExceptionT(ctx->actual.exception); + if (ctx->actual.function_identifier != NULL) PblDeallocateStringT(ctx->actual.function_identifier); + + // resetting the values + *ctx = PblFunctionCallMetaData_T_DeclDefault; + PblFree(ctx); + ctx = NULL; + } + return PblVoid_T_DeclDefault; +} + +PblException_T *PblGetExceptionT(PblString_T *msg, PblString_T *name, PblString_T *filename, PblUInt_T *line, + PblString_T *line_content, PblVoid_T *parent_exc, PblVoid_T *child_exc) { + PBL_DEFINE_VAR(ptr, PblException_T); + + // Using the Definition Default + *ptr = PblException_T_DefDefault; + ptr->actual = (struct PblException_Base){.msg = msg, + .name = name, + .filename = filename, + .line = line, + .line_content = line_content, + .parent_exc = parent_exc, + .child_exc = child_exc}; + + return ptr; +} + +PblVoid_T PblRaiseNewException(PblFunctionCallMetaData_T *this_call_meta, PblException_T *exception) { + // Validate the pointer for safety measures + this_call_meta = PblValPtr((void *) this_call_meta); + exception = PblValPtr((void *) exception); + + this_call_meta->actual.is_failure = PblGetBoolT(true); + this_call_meta->actual.failure_origin_ctx = this_call_meta; + this_call_meta->actual.exception = exception; + return PblVoid_T_DeclDefault; +} + +// TODO! Add Deallocating function for deallocating exception parents and children + +PblVoid_T PblDeallocateExceptionT(PblException_T *exc) { + // Validate the pointer for safety measures + exc = PblValPtr((void *) exc); + + // only if the exception is still defined + if (exc->meta.defined) { + // deallocate if the values are defined -> if not, skip de-allocation + + if (exc->actual.msg != NULL && exc->actual.msg->meta.defined) PblDeallocateStringT(exc->actual.msg); + if (exc->actual.name != NULL && exc->actual.name->meta.defined) PblDeallocateStringT(exc->actual.name); + if (exc->actual.filename != NULL && exc->actual.filename->meta.defined) PblDeallocateStringT(exc->actual.filename); + if (exc->actual.line_content != NULL && exc->actual.line_content->meta.defined) + PblDeallocateStringT(exc->actual.line_content); + + *exc = PblException_T_DeclDefault; + PblFree(exc); + exc = NULL; + } + return PblVoid_T_DeclDefault; +} + +// ---- End of Function Definitions ----------------------------------------------------------------------------------- diff --git a/src/io/pbl-io.c b/src/io/pbl-io.c new file mode 100644 index 0000000..f02cd38 --- /dev/null +++ b/src/io/pbl-io.c @@ -0,0 +1,116 @@ +/// @file pbl-io.c +/// @brief IO Implementation based on stdio.h +/// @author Luna-Klatzer +/// @date 2021-11-23 +/// @copyright Copyright (c) 2021 + +// Parent Header for this file +#include + +// General Required Header Inclusion +#include +#include + +// ---- Functions Definitions ----------------------------------------------------------------------------------------- + +PblIOFile_T *PblGetIOFileT(FILE *val) { + // Validate the pointer for safety measures + val = PblValPtr(val); + + PblIOFile_T *conv = PblMalloc(sizeof(PblIOFile_T)); + *conv = PblFile_T_DefDefault; + conv->actual = val; + return conv; +} + +PblIOStream_T *PblGetIOStreamT(int fd, const char *mode) { + // Validate the pointer for safety measures + mode = PblValPtr((void *) mode); + + PblIOStream_T *conv = PblMalloc(sizeof(PblIOStream_T)); + *conv = PblStream_T_DefDefault; + conv->actual.fd = PblGetUIntT((signed int) fd); + conv->actual.file = PblGetIOFileT(fdopen(fd, mode)); + conv->actual.mode = PblGetStringT(mode); + conv->actual.open = PblGetBoolT(true); + return conv; +} + +PblChar_T *PblInputChar_Base(PblString_T *display_msg, PblChar_T* end) { + PblPrint(display_msg, .end=end); + + char in_char = (char) getchar(); + // Avoid returning \n or EOF by replacing it with \0 + return in_char == '\n' || (int) in_char == EOF ? '\0' : PblGetCharT(in_char); +} + +__attribute__((unused)) PblChar_T * PblInputChar_Overhead(struct PblInputChar_Args in) { + // Validate the pointer for safety measures + PblString_T *display_msg = PBL_VAL_REQ_ARG(in.display_msg); + PblChar_T *end = in.end != NULL ? in.end : PblGetCharT('\0'); + return PblInputChar_Base(display_msg, end); +} + +PblString_T *PblInput_Base(PblString_T *display_msg, PblChar_T *end) { + // Printing the initial display message + PblPrint(display_msg, .end=end); + + // Initial size + unsigned int length = 100; + // Allocate mem for 100 chars + char *in_str = PblMalloc(length * sizeof(char)); + // Keep Track of how many chars where inputted now + int count = 0; + + char c; + // Run as long as it's not a newline + while((c = (char) getchar()) != '\n') { + // If the character is EOF, abort immediately + // (This should not happen though on a console stream, but covering for possible edge cases ) + if (c == EOF) + break; + + if(count >= length) { + // Resize the buffer. We increase each time with 50 + length += 50; + in_str = PblRealloc(in_str, length * sizeof(char)); + } + // Writing the char into the name + in_str[count++] = c; + } + return PblGetStringT(in_str); +} + +__attribute__((unused)) PblString_T * PblInput_Overhead(struct PblInput_Args in) { + // Validate the pointer for safety measures + PblString_T *display_msg = PBL_VAL_REQ_ARG(in.display_msg); + PblChar_T *end = in.end != NULL ? in.end : PblGetCharT('\0'); + return PblInput_Base(display_msg, end); +} + +PblVoid_T PblPrint_Base(PblString_T *out, PblIOStream_T *stream, PblChar_T *end) { + // Validate the pointer for safety measures + out = PblValPtr((void *) out); + + for (int i = 0; i < out->actual.len->actual; i++) + fprintf(stream->actual.file->actual, "%c", (out->actual.str[i].actual)); + fprintf(stream->actual.file->actual, "%c", end->actual); + return PblVoid_T_DeclDefault; +} + +__attribute__((unused)) PblVoid_T PblPrint_Overhead(struct PblPrint_Args in) { + // Validate the pointer for safety measures + PblString_T *out = PBL_VAL_REQ_ARG(in.out); + + PblIOStream_T *stream; + if (in.stream != NULL) { + stream = in.stream; + } else { + stream = PblMalloc(sizeof(PblIOStream_T)); + *stream = PBL_STREAM_STDOUT; + } + PblChar_T *end = in.end != NULL ? in.end : PblGetCharT('\n'); + return PblPrint_Base(out, stream, end); +} + +// ---- End of Function Definitions ----------------------------------------------------------------------------------- diff --git a/src/mem/pbl-mem-tools.c b/src/mem/pbl-mem-tools.c new file mode 100644 index 0000000..52147d7 --- /dev/null +++ b/src/mem/pbl-mem-tools.c @@ -0,0 +1,13 @@ +/// @file pbl-advanced-mem.c +/// @brief Advanced memory handling and management, which is separate from the base pbl-mem.h as that implements only +/// the most basic functions. +/// @author Luna-Klatzer +/// @date 2021-12-09 +/// @copyright Copyright (c) 2021 + +// General Required Header Inclusion +#include + +// ---- Functions Definitions ----------------------------------------------------------------------------------------- + +// ---- End of Function Definitions ----------------------------------------------------------------------------------- diff --git a/src/mem/pbl-mem.c b/src/mem/pbl-mem.c new file mode 100644 index 0000000..664c489 --- /dev/null +++ b/src/mem/pbl-mem.c @@ -0,0 +1,103 @@ +/// @file pbl-mem.c +/// @brief Para-C memory management and handling implementation based on `malloc.h` and `gc.h` (Hans-J. Boehm garbage +/// collector) +/// @author Luna-Klatzer +/// @date 2021-11-23 +/// @copyright Copyright (c) 2021 + +// Parent Header for this file +#include + +// General Required Header Inclusion +#include + +// ---- Memory Setup -------------------------------------------------------------------------------------------------- + +__attribute__((unused)) +__attribute__((constructor)) +__attribute__((deprecated("Compiler-Only Function - User Call Invalid!"))) +static void PBL_CONSTRUCTOR_MEM_INIT(void) { + GC_INIT(); +} + +// ---- End of Memory Setup ------------------------------------------------------------------------------------------- + +// ---- Functions Definitions ----------------------------------------------------------------------------------------- + +void *PblMemCpy(void *dest, const void *src, size_t bytes) { + if (dest == NULL) { + PBL_LOG_CPY_FROM_NULL_PTR + } + if (src == NULL) { + PBL_LOG_CPY_TO_NULL_PTR + } + + void *ret_ptr = memcpy(dest, src, bytes); + if (ret_ptr == NULL) { + PBL_LOG_CPY_RECEIVE_NULL_PTR + } + return ret_ptr; +} + +void *PblValPtr(void *ptr) { + // Crash on invalid input - Don't bother raising exceptions on this low-level area + if (ptr == NULL) { + PBL_LOG_ACCESS_ERR_NULL_PTR + } + return ptr; +} + +void PblFree(void *ptr) { + // Crash on invalid input - Don't bother raising exceptions on this low-level area + if (ptr == NULL) { + PBL_LOG_FREE_ERR_NULL_PTR + } + GC_FREE(ptr); + + // old pointer is invalid + ptr = NULL; +} + +__attribute__((unused)) void *PblMallocUncollectable(size_t size) { + // allocating the memory + void *ptr = GC_MALLOC_UNCOLLECTABLE(size); + if (ptr == NULL) { + PBL_LOG_ALLOC_ERR_RECEIVE_NULL_RET + } + return ptr; +} + +void *PblMalloc(size_t size) { + // allocating the memory + void *ptr = GC_MALLOC(size); + if (ptr == NULL) { + PBL_LOG_ALLOC_ERR_RECEIVE_NULL_RET + } + return ptr; +} + +__attribute__((unused)) void *PblMallocAtomic(size_t size) { + // allocating the memory + void *ptr = GC_MALLOC_ATOMIC(size); + if (ptr == NULL) { + PBL_LOG_ALLOC_ERR_RECEIVE_NULL_RET + } + return ptr; +} + +void *PblRealloc(void *ptr, size_t size) { + // Crash on invalid input - Don't bother raising exceptions on this low-level area + if (ptr == NULL) { + PBL_LOG_REALLOC_ERR_NULL_PTR + } + + // re-allocating the memory + void *new_ptr = GC_REALLOC(ptr, size); + if (new_ptr == NULL) { + PBL_LOG_REALLOC_ERR_RECEIVE_NULL_RET + } + + // old pointer is invalid + if (new_ptr != ptr) ptr = NULL; + return new_ptr; +} diff --git a/include/pbl/pbl-main.c b/src/pbl-main.c similarity index 57% rename from include/pbl/pbl-main.c rename to src/pbl-main.c index a1acfd9..91fd820 100644 --- a/include/pbl/pbl-main.c +++ b/src/pbl-main.c @@ -5,9 +5,14 @@ /// @date 2021-11-23 /// @copyright Copyright (c) 2021 -#include "pbl-main.h" +// Parent Header for this file +#include + +// ---- Functions Definitions ----------------------------------------------------------------------------------------- void PblAbortWithCriticalError(int exit_code, const char* string) { fprintf(stderr, "%s", string); exit(exit_code); } + +// ---- End of Function Definitions ----------------------------------------------------------------------------------- diff --git a/src/pbl.c b/src/pbl.c new file mode 100644 index 0000000..eddff62 --- /dev/null +++ b/src/pbl.c @@ -0,0 +1,19 @@ +/// @file pbl.c +/// @brief Main file for the Para-C Base Library (Static C library) +/// Styling and naming are similar to the Google C++ style guide +/// @see https://google.github.io/styleguide/cppguide.html +/// @author Luna-Klatzer +/// @date 2021-11-23 +/// @copyright Copyright (c) 2021 + +// Parent Header for this file +#include + +// ---- Functions Definitions ----------------------------------------------------------------------------------------- + +void PblAbortWithCriticalError(int exit_code, const char *string) { + fprintf(stderr, "%s", string); + exit(exit_code); +} + +// ---- End of Function Definitions ----------------------------------------------------------------------------------- diff --git a/src/types/pbl-any.c b/src/types/pbl-any.c new file mode 100644 index 0000000..c14e30d --- /dev/null +++ b/src/types/pbl-any.c @@ -0,0 +1,47 @@ +/// @file pbl-any.c +/// @brief Implementation for the any type, which allows values to be dynamically allocated and converted using +/// pre-defined conversion functions. +/// @author Luna-Klatzer +/// @date 2021-11-23 +/// @copyright Copyright (c) 2021 + +// Parent Header for this file +#include + +// ---- Functions Definitions ----------------------------------------------------------------------------------------- + +PblAny_T *PblGetAnyT(void *val, PblType_T *type) { + // Validate the pointer for safety measures + val = PblValPtr(val); + + PBL_DEFINE_VAR(ptr, PblAny_T); + + // Copying the memory to the destination address (the new type) + ptr->actual.val = PblMalloc(type->actual_size); + PblMemCpy(ptr->actual.val, val, type->actual_size); + + // Initialising the remaining properties + ptr->actual.byte_size = PblGetSizeT(type->actual_size); + ptr->actual.type = type; + + return ptr; +} + +PblVoid_T PblDeallocateAnyType(PblAny_T *val) { + // Validate the pointer for safety measures + val = PblValPtr(val); + + if (val->actual.val != NULL) { + PblFree(val->actual.val); + val->actual.val = NULL; + } + if (val->actual.byte_size != NULL) { PblFree(val->actual.byte_size); } + + // Note, we don't deallocate type, as it's a global pointer which **must** be kept alive + + *val = PblAny_T_DeclDefault; + PblFree(val); + return PblVoid_T_DeclDefault; +} + +// ---- End of Function Definitions ----------------------------------------------------------------------------------- diff --git a/src/types/pbl-int.c b/src/types/pbl-int.c new file mode 100644 index 0000000..d3d3b9b --- /dev/null +++ b/src/types/pbl-int.c @@ -0,0 +1,76 @@ +/// @file pbl-int.c +/// @brief Int Type Implementation based on stdint.h +/// @author Luna-Klatzer +/// @date 2021-11-23 +/// @copyright Copyright (c) 2021 + +// Parent Header for this file +#include + +// ---- Functions Definitions ----------------------------------------------------------------------------------------- + +__attribute__((unused)) PblInt8_T *PblGetInt8T(int8_t val){PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblInt8_T, val, int8_t)} + +__attribute__((unused)) PblUInt8_T *PblGetUInt8T(uint8_t val){PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblUInt8_T, val, uint8_t)} + +__attribute__((unused)) PblInt16_T *PblGetInt16T(int16_t val){PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblInt16_T, val, int16_t)} + +__attribute__((unused)) PblUInt16_T *PblGetUInt16T(uint16_t val){PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblUInt16_T, val, uint16_t)} + +__attribute__((unused)) PblInt32_T *PblGetInt32T(int32_t val){PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblInt32_T, val, int32_t)} + +__attribute__((unused)) PblUInt32_T *PblGetUInt32T(uint32_t val){PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblUInt32_T, val, uint32_t)} + +__attribute__((unused)) PblInt64_T *PblGetInt64T(int64_t val){PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblInt64_T, val, int64_t)} + +__attribute__((unused)) PblUInt64_T *PblGetUInt64T(uint64_t val){PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblUInt64_T, val, uint64_t)} + +__attribute__((unused)) PblLeastInt8_T *PblGetLeastInt8T(int_least8_t val){ + PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblLeastInt8_T, val, int_least8_t)} + +__attribute__((unused)) PblULeastInt8_T *PblGetULeastInt8T(uint_least8_t val){ + PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblULeastInt8_T, val, uint_least8_t)} + +__attribute__((unused)) PblLeastInt16_T *PblGetLeastInt16T(int_least16_t val){ + PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblLeastInt16_T, val, int_least16_t)} + +__attribute__((unused)) PblULeastInt16_T *PblGetULeastInt16T(uint_least16_t val){ + PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblULeastInt16_T, val, uint_least16_t)} + +__attribute__((unused)) PblLeastInt32_T *PblGetLeastInt32T(int_least32_t val){ + PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblLeastInt32_T, val, int_least32_t)} + +__attribute__((unused)) PblULeastInt32_T *PblGetULeastInt32T(uint_least32_t val){ + PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblULeastInt32_T, val, uint_least32_t)} + +__attribute__((unused)) PblLeastInt64_T *PblGetLeastInt64T(int_least64_t val){ + PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblLeastInt64_T, val, int_least64_t)} + +__attribute__((unused)) PblULeastInt64_T *PblGetULeastInt64T(uint_least64_t val){ + PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblULeastInt64_T, val, uint_least64_t)} + +__attribute__((unused)) PblFastInt8_T *PblGetFastInt8T(int_fast8_t val){PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblFastInt8_T, val, int_fast8_t)} + +__attribute__((unused)) PblUFastInt8_T *PblGetUFastInt8T(uint_fast8_t val){ + PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblUFastInt8_T, val, uint_fast8_t)} + +__attribute__((unused)) PblFastInt16_T *PblGetFastInt16T(int_fast16_t val){ + PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblFastInt16_T, val, int_fast16_t)} + +__attribute__((unused)) PblUFastInt16_T *PblGetUFastInt16T(uint_fast16_t val){ + PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblUFastInt16_T, val, uint_fast16_t)} + +__attribute__((unused)) PblFastInt32_T *PblGetFastInt32T(int_fast32_t val){ + PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblFastInt32_T, val, int_fast32_t)} + +__attribute__((unused)) PblUFastInt32_T *PblGetUFastInt32T(uint_fast32_t val){ + PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblUFastInt32_T, val, uint_fast32_t)} + +__attribute__((unused)) PblFastInt64_T *PblGetFastInt64T(int_fast64_t val){ + PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblFastInt64_T, val, int_fast64_t)} + +__attribute__((unused)) PblUFastInt64_T *PblGetUFastInt64T(uint_fast64_t val) { + PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblUFastInt64_T, val, uint_fast64_t) +} + +// ---- End of Function Definitions ----------------------------------------------------------------------------------- diff --git a/include/pbl/pbl-string.c b/src/types/pbl-string.c similarity index 60% rename from include/pbl/pbl-string.c rename to src/types/pbl-string.c index 27fd616..81ed743 100644 --- a/include/pbl/pbl-string.c +++ b/src/types/pbl-string.c @@ -6,48 +6,49 @@ /// @date 2021-11-23 /// @copyright Copyright (c) 2021 -#include -#include +// Parent Header for this file +#include -#include "./pbl-string.h" -#include "./pbl-types.h" -#include "./pbl-mem.h" +// General Required Header Inclusion +#include +#include -PblUInt_T* PblGetLengthOfCString(const char *content) { +// ---- Functions Definitions ----------------------------------------------------------------------------------------- + +PblUInt_T *PblGetLengthOfCString(const char *content) { // Validate the pointer for safety measures - content = PblValPtr((void*) content); + content = PblValPtr((void *) content); return PblGetUIntT(strlen(content)); } -PblSize_T* PblGetUsableStrSize(PblString_T* str) { +PblSize_T *PblGetUsableStrSize(PblString_T *str) { // Validate the pointer for safety measures - str = PblValPtr((void*) str); + str = PblValPtr((void *) str); return PblGetSizeT(str->actual.allocated_len->actual * PblChar_T_Size); } -char* PblGetCCharArrayFromCharT(PblChar_T* char_arr, PblUInt_T* len) { +char *PblGetCCharArrayFromCharT(PblChar_T *char_arr, PblUInt_T *len) { // Validate the pointer for safety measures - char_arr = PblValPtr((void*) char_arr); - len = PblValPtr((void*) len); + char_arr = PblValPtr((void *) char_arr); + len = PblValPtr((void *) len); - char* ret_arr = (char*) PblMalloc(sizeof(char) * len->actual); + char *ret_arr = (char *) PblMalloc(sizeof(char) * len->actual); - int i = 0; - for (; i < len->actual; i++) { + for (int i = 0; i < len->actual; i++) { PblMemCpy(&(ret_arr[i]), &(char_arr[i].actual), sizeof(char)); } - ret_arr[i] = '\0'; + ret_arr[len->actual] = '\0'; return ret_arr; } -char* PblGetCCharArrayFromString(PblString_T* str) { +char *PblGetCCharArrayFromString(PblString_T *str) { // Validate the pointer for safety measures - str = PblValPtr((void*) str); + str = PblValPtr((void *) str); - char* ret_arr = (char*) PblMalloc(sizeof(char) * str->actual.len->actual); + char *ret_arr = (char *) PblMalloc(sizeof(char) * str->actual.len->actual); for (int i = 0; i < str->actual.len->actual; i++) { PblMemCpy(&(ret_arr[i]), &(str->actual.str[i].actual), sizeof(char)); @@ -55,38 +56,38 @@ char* PblGetCCharArrayFromString(PblString_T* str) { return ret_arr; } -PblChar_T* PblGetCharTArray(const char* content) { +PblChar_T *PblGetCharTArray(const char *content) { // Validate the pointer for safety measures - content = PblValPtr((void*) content); + content = PblValPtr((void *) content); - PblUInt_T* len = PblGetLengthOfCString(content); - PblChar_T* pbl_chars = PblMalloc( -sizeof(PblChar_T) * (len->actual + 1) // Min. size is 1 -> plus end-char: \0 - ); + PblUInt_T *len = PblGetLengthOfCString(content); + PblChar_T *pbl_chars = PblMalloc(sizeof(PblChar_T) * (len->actual + 1)// Min. size is 1 -> plus end-char: \0 + ); for (int i = 0; i < len->actual; i++) { - PBL_GET_ACTUAL_TYPE_INSTANCE(pbl_chars[i], PblChar_T, content[i]); + PBL_ASSIGN_TO_VAR(pbl_chars[i], PblChar_T, content[i]); } - // adding null character - PBL_GET_ACTUAL_TYPE_INSTANCE(pbl_chars[len->actual], PblChar_T, '\0'); + + // Adding null character + PBL_ASSIGN_TO_VAR(pbl_chars[len->actual], PblChar_T, '\0'); return pbl_chars; } -PblString_T* PblGetStringT(const char *content) { +PblString_T *PblGetStringT(const char *content) { // Validate the pointer for safety measures - content = PblValPtr((void*) content); + content = PblValPtr((void *) content); - // converting the char array into the corresponding PblChar_T type - PblUInt_T* len = PblGetLengthOfCString(content); + // Converting the char array into the corresponding PblChar_T type + PblUInt_T *len = PblGetLengthOfCString(content); return PblCreateStringT(PblGetCharTArray(content), len); } -PblBool_T* PblCompareStringT(PblString_T* str_1, PblString_T* str_2) { +PblBool_T *PblCompareStringT(PblString_T *str_1, PblString_T *str_2) { // Validate the pointer for safety measures - str_1 = PblValPtr((void*) str_1); - str_2 = PblValPtr((void*) str_2); + str_1 = PblValPtr((void *) str_1); + str_2 = PblValPtr((void *) str_2); - // don't bother with comparison if the lengths are the same + // Don't bother with comparison if the lengths are the same if (str_1->actual.len->actual != str_2->actual.len->actual) return PblGetBoolT(false); for (int i = 0; i < str_1->actual.len->actual; i++) { @@ -96,9 +97,9 @@ PblBool_T* PblCompareStringT(PblString_T* str_1, PblString_T* str_2) { return PblGetBoolT(true); } -PblUInt_T* PblGetMinimumArrayLen(PblUInt_T* len) { +PblUInt_T *PblGetMinimumArrayLen(PblUInt_T *len) { // Validate the pointer for safety measures - len = PblValPtr((void*) len); + len = PblValPtr((void *) len); unsigned int alloc_len = 0; // The size of the allocated memory should always be bigger than the actual content @@ -111,12 +112,12 @@ PblUInt_T* PblGetMinimumArrayLen(PblUInt_T* len) { return PblGetUIntT((alloc_len + 1)); } -PblSize_T* PblGetAllocSizeStringT(PblUInt_T* len) { +PblSize_T *PblGetAllocSizeStringT(PblUInt_T *len) { // Validate the pointer for safety measures - len = PblValPtr((void*) len); + len = PblValPtr((void *) len); - PblUInt_T* min_arr_len = PblGetMinimumArrayLen(len); - PblSize_T* size = PblGetSizeT( min_arr_len->actual * sizeof(PblChar_T)); + PblUInt_T *min_arr_len = PblGetMinimumArrayLen(len); + PblSize_T *size = PblGetSizeT(min_arr_len->actual * sizeof(PblChar_T)); // Deallocating early even with a garbage collector to save a small amount of time PblFree(min_arr_len); return size; @@ -124,10 +125,10 @@ PblSize_T* PblGetAllocSizeStringT(PblUInt_T* len) { PblVoid_T PblResizeStringT(PblString_T *str, PblUInt_T *len) { // Validate the pointer for safety measures - str = PblValPtr((void*) str); - len = PblValPtr((void*) len); + str = PblValPtr((void *) str); + len = PblValPtr((void *) len); - PblSize_T* byte_size = PblGetAllocSizeStringT(len); + PblSize_T *byte_size = PblGetAllocSizeStringT(len); // Reallocating the memory with the new length - includes space for '\0' byte str->actual.str = PblRealloc(str->actual.str, byte_size->actual); @@ -139,14 +140,15 @@ PblVoid_T PblResizeStringT(PblString_T *str, PblUInt_T *len) { PblVoid_T PblWriteStringToStringT(PblString_T *str, PblString_T *content, PblUInt_T *len_to_write) { // Validate the pointer for safety measures - str = PblValPtr((void*) str); - content = PblValPtr((void*) content); - len_to_write = PblValPtr((void*) len_to_write); + str = PblValPtr((void *) str); + content = PblValPtr((void *) content); + len_to_write = PblValPtr((void *) len_to_write); - PBL_ALLOC_ARRAY_DEFINITION(char_arr, PblChar_T, len_to_write->actual); - for (int i = 0; i < len_to_write->actual; i++) + PBL_CREATE_NEW_ARRAY(char_arr, PblChar_T, len_to_write->actual); + for (int i = 0; i < len_to_write->actual; i++) { // Using MemCpy to properly copy the value, aka. to be certain it is copied properly PblMemCpy(&char_arr[i], &content->actual.str[i], sizeof(PblChar_T)); + } PblWriteCharArrayToStringT(str, char_arr, len_to_write); return PblVoid_T_DeclDefault; @@ -154,46 +156,46 @@ PblVoid_T PblWriteStringToStringT(PblString_T *str, PblString_T *content, PblUIn PblVoid_T PblWriteCharArrayToStringT(PblString_T *str, PblChar_T *content, PblUInt_T *len_to_write) { // Validate the pointer for safety measures - str = PblValPtr((void*) str); - content = PblValPtr((void*) content); - len_to_write = PblValPtr((void*) len_to_write); + str = PblValPtr((void *) str); + content = PblValPtr((void *) content); + len_to_write = PblValPtr((void *) len_to_write); // Don't bother writing when the length to write is 0 if (len_to_write->actual == 0) return PblVoid_T_DeclDefault; - PblUInt_T* required_size = PblGetMinimumArrayLen(len_to_write); + PblUInt_T *required_size = PblGetMinimumArrayLen(len_to_write); // If the required space is bigger that means that the available space is not sufficient - if (required_size->actual > str->actual.allocated_len->actual) { + if (required_size->actual > str->actual.allocated_len->actual) PblResizeStringT(str, len_to_write); - } int i = 0; for (; i < len_to_write->actual; i++) + // Copying from the source string to the destination block of memory PblMemCpy(&(str->actual.str[i]), &(content[i]), sizeof(PblChar_T)); - // adding null character + // Adding null character str->actual.str[i].actual = '\0'; - // resetting length + // Resetting length str->actual.len->actual = len_to_write->actual; - // updating meta data + // Updating meta data str->meta.defined = true; return PblVoid_T_DeclDefault; } -PblString_T* PblCreateStringT(PblChar_T *content, PblUInt_T *len) { +PblString_T *PblCreateStringT(PblChar_T *content, PblUInt_T *len) { // Validate the pointer for safety measures - content = PblValPtr((void*) content); - len = PblValPtr((void*) len); + content = PblValPtr((void *) content); + len = PblValPtr((void *) len); // Using the DeclDefault to avoid recursion when 'DefDefault' is 'PblGetStringT("")' aka. an empty string - PBL_ALLOC_DEFINITION(str, PblString_T); + PBL_DEFINE_VAR(str, PblString_T); str->actual.allocated_len = PblGetMinimumArrayLen(len); str->actual.len = len; str->actual.str = PblAllocateStringContentT(len); - // safe writing null char to the beginning + // Safe writing null char to the beginning str->actual.str[0].actual = '\0'; PblWriteCharArrayToStringT(str, content, len); @@ -203,11 +205,11 @@ PblString_T* PblCreateStringT(PblChar_T *content, PblUInt_T *len) { PblChar_T *PblAllocateStringContentT(PblUInt_T *len) { // Validate the pointer for safety measures - len = PblValPtr((void*) len); + len = PblValPtr((void *) len); // length = len * sizeof(PblChar_T) + 1 (null character (\0)) - PblSize_T* byte_size = PblGetAllocSizeStringT(len); - PblChar_T* ptr = PblMalloc(byte_size->actual); + PblSize_T *byte_size = PblGetAllocSizeStringT(len); + PblChar_T *ptr = PblMalloc(byte_size->actual); // Early de-allocating to save a little amount of time PblFree(byte_size); return ptr; @@ -215,11 +217,11 @@ PblChar_T *PblAllocateStringContentT(PblUInt_T *len) { PblVoid_T PblDeallocateStringT(PblString_T *lvalue) { // Validate the pointer for safety measures - lvalue = PblValPtr((void*) lvalue); + lvalue = PblValPtr((void *) lvalue); if (lvalue->meta.defined) { - // writing \0 onto the entire space of memory - PBL_ALLOC_ARRAY_DEFINITION(nullify, PblChar_T, lvalue->actual.len->actual); + // Writing \0 onto the entire space of memory + PBL_CREATE_NEW_ARRAY(nullify, PblChar_T, lvalue->actual.len->actual); for (int i = 0; i < lvalue->actual.len->actual; i++) nullify[i].actual = '\0'; PblWriteCharArrayToStringT(lvalue, nullify, lvalue->actual.len); @@ -229,7 +231,7 @@ PblVoid_T PblDeallocateStringT(PblString_T *lvalue) { lvalue->actual.allocated_len = NULL; } if (lvalue->actual.str != NULL) { - // deallocating the str, since it's a pointer to an array of PblChar_T type instances + // Deallocating the str, since it's a pointer to an array of PblChar_T type instances PblFree(lvalue->actual.str); lvalue->actual.str = NULL; } @@ -244,4 +246,6 @@ PblVoid_T PblDeallocateStringT(PblString_T *lvalue) { return PblVoid_T_DeclDefault; } -// TODO! Add copy string function \ No newline at end of file +// TODO! Add copy string function + +// ---- End of Function Definitions ----------------------------------------------------------------------------------- diff --git a/src/types/pbl-types.c b/src/types/pbl-types.c new file mode 100644 index 0000000..6160aba --- /dev/null +++ b/src/types/pbl-types.c @@ -0,0 +1,140 @@ +/// @file pbl-types.c +/// @brief Para-C Base Types Implementation, which contains handler macros, conversion functions, default declaration, +/// default definition types and default size macros. This also includes meta-data tracking based on the +/// 'PblMetaVarCtx_T' type. +/// @author Luna-Klatzer +/// @date 2021-11-23 +/// @copyright Copyright (c) 2021 + +// Parent Header for this file +#include + +// ---- Initialisation of the global type list ------------------------------------------------------------------------ + +const PblType_T *PblCreateNewType(const size_t size, const void *type_template, const char *name, + const bool user_defined, const bool definable) { + PblType_T *type = PblMalloc(sizeof(PblType_T)); + *type = (PblType_T) { + .actual_size =size, + .type_template=type_template, + .name=name, + .user_defined=user_defined, + .definable=definable + }; + return type; +} + +void PblInitTypeList(PblTypeList_T* list) { + // Default size on init is 50 + list->t_items = PblMalloc(sizeof(PblType_T) * 50); + list->alloc_len = 50; +} + +void PblAddTypeToTypeList(PblTypeList_T* list, const PblType_T* type) { + // If there is not enough space to add a new item, extend the list + if (list->alloc_len == list->t_amount) { + list->t_items = PblRealloc( + list->t_items, + sizeof(PblType_T *) * (list->alloc_len * 50) + ); + list->alloc_len += 50; + } + list->t_items[list->t_amount] = type; + list->t_amount++; +} + +// ---- End of Initialisation of the global type list ----------------------------------------------------------------- + +// ---- Initialisation of the Local types ----------------------------------------------------------------------------- + +PBL_INIT_LOCAL_TYPE_LIST; +LOCAL_TYPE_LIST_CONSTRUCTOR { + PBL_REGISTER_LOCAL_TYPE(&LOCAL_TYPE_LIST, PblVoid_T, "void", false, false); + PBL_REGISTER_LOCAL_TYPE(&LOCAL_TYPE_LIST, PblPointer_T, "ptr", false, true); + PBL_REGISTER_LOCAL_TYPE(&LOCAL_TYPE_LIST, PblSize_T, "size", false, true); + PBL_REGISTER_LOCAL_TYPE(&LOCAL_TYPE_LIST, PblBool_T, "bool", false, true); + PBL_REGISTER_LOCAL_TYPE(&LOCAL_TYPE_LIST, PblChar_T, "char", false, true); + PBL_REGISTER_LOCAL_TYPE(&LOCAL_TYPE_LIST, PblUChar_T, "uchar", false, true); + PBL_REGISTER_LOCAL_TYPE(&LOCAL_TYPE_LIST, PblShort_T, "int", false, true); + PBL_REGISTER_LOCAL_TYPE(&LOCAL_TYPE_LIST, PblUShort_T, "ushort", false, true); + PBL_REGISTER_LOCAL_TYPE(&LOCAL_TYPE_LIST, PblInt_T, "int", false, true); + PBL_REGISTER_LOCAL_TYPE(&LOCAL_TYPE_LIST, PblUInt_T, "uint", false, true); + PBL_REGISTER_LOCAL_TYPE(&LOCAL_TYPE_LIST, PblLong_T, "long", false, true); + PBL_REGISTER_LOCAL_TYPE(&LOCAL_TYPE_LIST, PblULong_T, "ulong", false, true); + PBL_REGISTER_LOCAL_TYPE(&LOCAL_TYPE_LIST, PblLongLong_T, "longlong", false, true); + PBL_REGISTER_LOCAL_TYPE(&LOCAL_TYPE_LIST, PblULongLong_T, "ulonglong", false, true); + PBL_REGISTER_LOCAL_TYPE(&LOCAL_TYPE_LIST, PblFloat_T, "float", false, true); + PBL_REGISTER_LOCAL_TYPE(&LOCAL_TYPE_LIST, PblDouble_T, "double", false, true); +}; + +// ---- Functions Definitions ----------------------------------------------------------------------------------------- + +__attribute__((unused)) PblPointer_T *PblGetPointerT(void* val, PblType_T* type) { + struct PblPointer_Base struct_type = { + .p_void = val, + .p_type = type + }; + PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblPointer_T, struct_type, struct PblPointer_Base); +} + +PblBool_T *PblGetBoolT(bool val) { + PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblBool_T, val, bool); +} + +__attribute__((unused)) PblSize_T *PblGetSizeT(size_t val) { + PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblSize_T, val, size_t); +} + +__attribute__((unused)) PblChar_T *PblGetCharT(signed char val) { + PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblChar_T, val, signed char); +} + +__attribute__((unused)) PblUChar_T *PblGetUCharT(unsigned char val) { + PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblUChar_T, val, unsigned char); +} + +__attribute__((unused)) PblShort_T *PblGetShortT(signed short val) { + PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblShort_T, val, signed short); +} + +__attribute__((unused)) PblUShort_T *PblGetUShortT(unsigned short val) { + PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblUShort_T, val, unsigned short); +} + +__attribute__((unused)) PblInt_T *PblGetIntT(signed int val) { + PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblInt_T, val, signed int); +} + +__attribute__((unused)) PblUInt_T *PblGetUIntT(unsigned int val) { + PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblUInt_T, val, unsigned int); +} + +__attribute__((unused)) PblLong_T *PblGetLongT(signed long val) { + PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblLong_T, val, signed long); +} + +__attribute__((unused)) PblULong_T *PblGetULongT(unsigned long val) { + PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblULong_T, val, unsigned long); +} + +__attribute__((unused)) PblLongLong_T *PblGetLongLongT(signed long long val) { + PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblLongLong_T, val, signed long long); +} + +__attribute__((unused)) PblULongLong_T *PblGetULongLongT(unsigned long long val) { + PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblULongLong_T, val, unsigned long long); +} + +__attribute__((unused)) PblFloat_T *PblGetFloatT(float val) { + PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblFloat_T, val, float); +} + +__attribute__((unused)) PblDouble_T *PblGetDoubleT(double val) { + PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblDouble_T, val, double); +} + +__attribute__((unused)) PblLongDouble_T *PblGetLongDoubleT(long double val) { + PBL_CONVERSION_FUNCTION_DEF_CONSTRUCTOR(PblLongDouble_T, val, long double); +} + +// ---- End of Function Definitions ----------------------------------------------------------------------------------- diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 13d9125..1ea26ec 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,12 +1,27 @@ -project(pbl-tests) - -include(FetchContent) +# Including GTest FetchContent_Declare( - gtest-1.11.0 - URL https://github.com/google/googletest/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip + gtest-1.11.0 + URL https://github.com/google/googletest/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip ) + # For Windows: Prevent overriding the parent project's compiler/linker settings set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) FetchContent_MakeAvailable(gtest-1.11.0) -add_subdirectory(tests) \ No newline at end of file +# Including the gtest headers +include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR}) + +# Defining the directories for source and header files +set(TEST_SOURCE_INCLUDE_DIRECTORY "${libpbl_SOURCE_DIR}/tests") + +# Using glob to get all files that should be included +file(GLOB TEST_SOURCE_FILES CONFIGURE_DEPENDS "${TEST_SOURCE_INCLUDE_DIRECTORY}/**/*.cpp") + +# Adding the test executable +add_executable(runPblTests ${TEST_SOURCE_FILES}) + +# Linking the required GTest library +target_link_libraries(runPblTests gtest gtest_main) + +# Linking the PBl itself +target_link_libraries(runPblTests pbl) diff --git a/tests/func/test_exception.cpp b/tests/func/test_exception.cpp new file mode 100644 index 0000000..f94c6d0 --- /dev/null +++ b/tests/func/test_exception.cpp @@ -0,0 +1,196 @@ +/// +/// Testing for the header pbl-exception.h +/// +/// @author Luna-Klatzer + +// Including the required GTest +#include "gtest/gtest.h" + +// Including the header to be tested +#include + +TEST(FunctionMetaTest, PblMetaFunctionCallCtxDefaults) { + PBL_DECLARE_VAR(v_1, PblFunctionCallMetaData_T); + + EXPECT_EQ(PblFunctionCallMetaData_T_Size, sizeof(PblBool_T *) + sizeof(PblUInt_T *) + sizeof(PblBool_T *) + + 2 * sizeof(PblFunctionCallMetaData_T *) + sizeof(nullptr)); + EXPECT_EQ(v_1->meta.defined, false); + + PBL_DEFINE_VAR(v_2, PblFunctionCallMetaData_T); + + EXPECT_TRUE(v_2->actual.call_origin_ctx == nullptr); + EXPECT_TRUE(v_2->actual.exception == nullptr); + EXPECT_TRUE(v_2->actual.failure_origin_ctx == nullptr); + EXPECT_TRUE(v_2->actual.is_failure == nullptr); + EXPECT_TRUE(v_2->actual.arg_amount == nullptr); + EXPECT_TRUE(v_2->actual.function_identifier == nullptr); + EXPECT_EQ(PblFunctionCallMetaData_T_Size, sizeof(PblBool_T *) + sizeof(PblUInt_T *) + sizeof(PblBool_T *) + + 2 * sizeof(PblFunctionCallMetaData_T *) + sizeof(nullptr)); + EXPECT_TRUE(v_2->meta.defined); +} + +TEST(ExceptionTest, PblExceptionDefaults) { + PBL_DECLARE_VAR(v_1, PblException_T); + + EXPECT_EQ(PblException_T_Size, 4 * sizeof(PblString_T *) + sizeof(PblUInt_T *) + 2 * sizeof(void *)); + EXPECT_EQ(v_1->meta.defined, false); + + PBL_DEFINE_VAR(v_2, PblException_T); + + EXPECT_TRUE(v_2->actual.child_exc == nullptr); + EXPECT_TRUE(v_2->actual.parent_exc == nullptr); + EXPECT_TRUE(v_2->actual.name == nullptr); + EXPECT_TRUE(v_2->actual.msg == nullptr); + EXPECT_TRUE(v_2->actual.filename == nullptr); + EXPECT_TRUE(v_2->actual.line_content == nullptr); + EXPECT_TRUE(v_2->actual.line == nullptr); + EXPECT_EQ(PblException_T_Size, 4 * sizeof(PblString_T *) + sizeof(PblUInt_T *) + 2 * sizeof(void *)); + EXPECT_EQ(v_2->meta.defined, true); +} + +PblInt_T *NestedTestFunction(PblFunctionCallMetaData_T *this_call_meta, PblUInt_T *i) { + PblUInt_T *line = PblGetUIntT(__LINE__); + PblException_T *exception = + PblGetExceptionT(PblGetStringT("test"), PblGetStringT("TestException"), PblGetStringT(__FILE__), line, + PblGetStringT("raise exception"), nullptr, nullptr); + PBL_RAISE_EXCEPTION(exception, PblInt_T); +} + +PblInt_T *TestFunction(PblFunctionCallMetaData_T *this_call_meta) { + PBL_DECLARE_VAR(r_1, PblInt_T); + + /// creating a copy of the addr, if the pointer is accidentally set to NULL by the function returning NULL (due to + /// the exception occurring) + PBL_CREATE_ADDRESS_COPY(r_1, PblInt_T *, H3); + PBL_CALL_FUNC_AND_CATCH(NestedTestFunction, r_1, X1, PblGetUIntT(1)); + + // if the function failed, treat the return as invalid -> restore previous value + // in this case the function raises an exception and as such it will never reach this code + if (this_call_meta->actual.is_failure->actual) { + // Restore if NULL -> here it should be restored as NULL is returned + PBL_WRITE_BACK_ADDRESS_COPY(r_1, H3); + } + return r_1; +} + +TEST(ExceptionTest, OneNestCall) { + PBL_DECLARE_VAR(r_1, PblInt_T); + PBL_DEFINE_VAR(this_call_meta, PblFunctionCallMetaData_T); + this_call_meta->actual.is_failure = PblGetBoolT(false); + + // creating a copy of the addr, if the pointer is accidentally set to NULL by the function returning NULL (due to + // the exception occurring) + PBL_CREATE_ADDRESS_COPY(r_1, PblInt_T *, H3); + /// Call the function and update the local ctx if an exception was raised + PBL_BASE_CALL_AND_CATCH_EXCEPTION(TestFunction, r_1, H3, PblGetBoolT(false), this_call_meta, ); + + // if the function failed, treat the return as invalid -> restore previous value + if (this_call_meta->actual.is_failure->actual) { + // Restore if NULL -> here it should be restored as NULL is returned + PBL_WRITE_BACK_ADDRESS_COPY(r_1, H3); + } + + // the return should have failed aka. the value should have been set to NULL and then restored by + // 'PBL_PASTE_ADDRESS_COPY' + EXPECT_EQ(r_1->meta.defined, false); + EXPECT_TRUE(this_call_meta->actual.is_failure->actual); + EXPECT_TRUE(this_call_meta->actual.failure_origin_ctx != nullptr); + EXPECT_TRUE(this_call_meta->actual.exception != nullptr); + EXPECT_TRUE(this_call_meta->actual.call_origin_ctx == nullptr); + PblString_T *default_name = PblGetStringT("test"); + EXPECT_TRUE( + PblCompareStringT(((PblException_T *) this_call_meta->actual.exception)->actual.msg, default_name)->actual); + PblString_T *default_msg = PblGetStringT("TestException"); + EXPECT_TRUE( + PblCompareStringT(((PblException_T *) this_call_meta->actual.exception)->actual.name, default_msg)->actual); + PblString_T *default_filename = PblGetStringT(__FILE__); + EXPECT_TRUE( + PblCompareStringT(((PblException_T *) this_call_meta->actual.exception)->actual.filename, default_filename) + ->actual); + PblString_T *default_line_content = PblGetStringT("raise exception"); + EXPECT_TRUE( + PblCompareStringT(((PblException_T *) this_call_meta->actual.exception)->actual.line_content, default_line_content) + ->actual); +} + +PblInt_T *TestFunction2(PblFunctionCallMetaData_T *this_call_meta) { + /// Call the block and execute the except block if the exc names match + PBL_TRY_EXCEPT_BLOCK( + { + PBL_DECLARE_VAR(r_1, PblInt_T); + PBL_CALL_FUNC_IN_TRY_EXCEPT_BLOCK(NestedTestFunction, r_1, PblInt_T *, X1, Y2, PblGetUIntT(1)) + return r_1; + }, + {PBL_EXCEPT_BLOCK( + "test", { return PblGetIntT(1); }, Y2)}, + Y2, this_call_meta, PblInt_T); + // default return is 0 - aka. the exception was raised + return PblGetIntT(0); +} + +TEST(ExceptionTest, TryExceptCall) { + PBL_DECLARE_VAR(r_1, PblInt_T); + PBL_DEFINE_VAR(this_call_meta, PblFunctionCallMetaData_T); + this_call_meta->actual.is_failure = PblGetBoolT(false); + + // creating a copy of the addr, if the pointer is accidentally set to NULL by the function returning NULL (due to + // the exception occurring) + PBL_CREATE_ADDRESS_COPY(r_1, PblInt_T *, H3); + /// Call the function and update the local ctx if an exception was raised + PBL_BASE_CALL_AND_CATCH_EXCEPTION(TestFunction2, r_1, H3, PblGetBoolT(false), this_call_meta, ); + + // if the function failed, treat the return as invalid -> restore previous value + if (this_call_meta->actual.is_failure->actual) { + // Restore if NULL -> here it should be restored as NULL is returned + PBL_WRITE_BACK_ADDRESS_COPY(r_1, H3); + } + + // Try-except should never if there is a except statement that was executed, log it's exception and throw the results + // away right after finishing up + EXPECT_FALSE(this_call_meta->actual.is_failure->actual); + EXPECT_TRUE(this_call_meta->actual.failure_origin_ctx == nullptr); + EXPECT_TRUE(this_call_meta->actual.exception == nullptr); + EXPECT_TRUE(this_call_meta->actual.call_origin_ctx == nullptr); + EXPECT_EQ(r_1->meta.defined, true); + EXPECT_EQ(r_1->actual, 1); +} + +PblInt_T *TestFunction3(PblFunctionCallMetaData_T *this_call_meta) { + /// Call the block and execute the except block if the exc names match + PBL_TRY_EXCEPT_BLOCK( + { + PBL_DECLARE_VAR(r_1, PblInt_T); + PBL_CALL_FUNC_IN_TRY_EXCEPT_BLOCK(NestedTestFunction, r_1, PblInt_T *, X1, Y2, PblGetUIntT(1)) + return r_1; + }, + {PBL_EXCEPT_BLOCK( + "test", { return PblGetIntT(1); }, Y2)}, + Y2, this_call_meta, PblInt_T); + // default return is 0 - aka. the exception was raised + return PblGetIntT(0); +} + +TEST(ExceptionTest, TryExceptCallWithContinuation) { + PBL_DECLARE_VAR(r_1, PblInt_T); + PBL_DEFINE_VAR(this_call_meta, PblFunctionCallMetaData_T); + this_call_meta->actual.is_failure = PblGetBoolT(false); + + // creating a copy of the addr, if the pointer is accidentally set to NULL by the function returning NULL (due to + // the exception occurring) + PBL_CREATE_ADDRESS_COPY(r_1, PblInt_T *, H3); + /// Call the function and update the local ctx if an exception was raised + PBL_BASE_CALL_AND_CATCH_EXCEPTION(TestFunction3, r_1, H3, PblGetBoolT(false), this_call_meta, ); + + // if the function failed, treat the return as invalid -> restore previous value + if (this_call_meta->actual.is_failure->actual) { + // Restore if NULL -> here it should be restored as NULL is returned + PBL_WRITE_BACK_ADDRESS_COPY(r_1, H3); + } + + EXPECT_FALSE(this_call_meta->actual.is_failure->actual); + EXPECT_TRUE(this_call_meta->actual.failure_origin_ctx == nullptr); + EXPECT_TRUE(this_call_meta->actual.exception == nullptr); + EXPECT_TRUE(this_call_meta->actual.call_origin_ctx == nullptr); + EXPECT_EQ(r_1->meta.defined, true); + EXPECT_EQ(r_1->actual, 1); +} \ No newline at end of file diff --git a/tests/general/test_main_header.cpp b/tests/general/test_main_header.cpp new file mode 100644 index 0000000..83f6d18 --- /dev/null +++ b/tests/general/test_main_header.cpp @@ -0,0 +1,15 @@ +/// +/// Testing for the macros in the header pbl.h +/// +/// @author Luna-Klatzer + +// Including the required GTest +#include "gtest/gtest.h" + +// Including the header to be tested +#include + +TEST(MacroTest, SimpleCheckForExistances) { + EXPECT_TRUE(PBL_VERSION); + EXPECT_STREQ(PBL_VERSION, "0.1.dev6"); +} \ No newline at end of file diff --git a/tests/general/test_simple_print_program.cpp b/tests/general/test_simple_print_program.cpp new file mode 100644 index 0000000..854e55a --- /dev/null +++ b/tests/general/test_simple_print_program.cpp @@ -0,0 +1,25 @@ +/// +/// Testing for the macros in the header pbl.h +/// +/// @author Luna-Klatzer + +// Including the required GTest +#include "gtest/gtest.h" + +// Including the header to be tested +#include +#include +#include + +TEST(BaseFunctionalityTest, SimpleStringPrintCheck) { + PblString_T *string_1 = PblGetStringT("'PblGetStringT' = This is a simple string inside a test program"); + PblPrint(string_1); + + PblString_T *string_2 = PblGetStringT("'PblGetStringT' = Thus this is a simple string inside a test program"); + PblPrint(string_2); + + if (PblCompareStringT(string_1, string_2)) + { + PblPrint(PblGetStringT("'PblCompareStringT' = The strings are not equal")); + } +} diff --git a/tests/tests/test_io.cpp b/tests/io/test_io.cpp similarity index 56% rename from tests/tests/test_io.cpp rename to tests/io/test_io.cpp index 4e06cd4..1d8672a 100644 --- a/tests/tests/test_io.cpp +++ b/tests/io/test_io.cpp @@ -3,42 +3,39 @@ /// /// @author Luna-Klatzer -#include +// Including the required GTest #include "gtest/gtest.h" +// Including the header to be tested +#include + TEST(IOFileTest, ConversionCheck) { - FILE* val = fdopen(1, "a"); - PblFile_T* stream = PblGetFileT(val); + FILE *val = fdopen(1, "a"); + PblIOFile_T *stream = PblGetIOFileT(val); EXPECT_EQ(stream->actual, val); EXPECT_EQ(stream->meta.defined, true); - EXPECT_EQ( - PblFile_T_Size, - sizeof(FILE*) - ); + EXPECT_EQ(PblFile_T_Size, sizeof(FILE *)); } TEST(IOStreamTest, ConversionCheck) { - PblStream_T* stream = PblGetStreamT(1, "a"); + PblIOStream_T *stream = PblGetIOStreamT(1, "a"); EXPECT_EQ(stream->actual.fd->actual, 1); - PblString_T* mode = PblGetStringT("a"); + PblString_T *mode = PblGetStringT("a"); EXPECT_TRUE(PblCompareStringT(stream->actual.mode, mode)->actual); EXPECT_EQ(stream->actual.open->actual, true); EXPECT_EQ(stream->meta.defined, true); - EXPECT_EQ( - PblStream_T_Size, - sizeof(PblString_T *) + sizeof(PblUInt_T *) + sizeof(PblFile_T *) + sizeof(PblBool_T *) - ); + EXPECT_EQ(PblStream_T_Size, sizeof(PblString_T *) + sizeof(PblUInt_T *) + sizeof(PblIOFile_T *) + sizeof(PblBool_T *)); } TEST(IOPrintTest, SimplePrint) { - PblString_T* str = PblCreateStringT(PblGetCharTArray("hello world"), PblGetUIntT(11)); + PblString_T *str = PblCreateStringT(PblGetCharTArray("hello world"), PblGetUIntT(11)); // size is per default 50 + 1 (for null char) EXPECT_EQ(str->actual.allocated_len->actual, 51); - PblPrint(.out=str, .end=PblGetCharT(' ')); + PblPrint(.out = str, .end = PblGetCharT(' ')); PblPrint(str); // deallocating the string @@ -46,16 +43,15 @@ TEST(IOPrintTest, SimplePrint) { } TEST(IOPrintTest, SimplePrintWithSetStream) { - PblString_T* str = PblCreateStringT(PblGetCharTArray("hello world"), PblGetUIntT(11)); + PblString_T *str = PblCreateStringT(PblGetCharTArray("hello world"), PblGetUIntT(11)); // size is per default 50 + 1 (for null char) EXPECT_EQ(str->actual.allocated_len->actual, 51); - PblStream_T* stream = (PblStream_T*) PblMalloc(sizeof(PblStream_T)); + PblIOStream_T *stream = (PblIOStream_T *) PblMalloc(sizeof(PblIOStream_T)); *stream = PBL_STREAM_STDOUT; - PblPrint(.out = str, .stream=stream); + PblPrint(.out = str, .stream = stream); // deallocating the string PblDeallocateStringT(str); } - diff --git a/tests/tests/CMakeLists.txt b/tests/tests/CMakeLists.txt deleted file mode 100644 index 8cd7a1e..0000000 --- a/tests/tests/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR}) - -add_executable(runParacModulesTests - test_io.cpp - test_types.cpp - test_parac_modules.cpp - test_string.cpp - test_int.cpp - test_exception.cpp - ) - -target_link_libraries(runParacModulesTests gtest gtest_main) -target_link_libraries(runParacModulesTests pbl) diff --git a/tests/tests/test_exception.cpp b/tests/tests/test_exception.cpp deleted file mode 100644 index 6934213..0000000 --- a/tests/tests/test_exception.cpp +++ /dev/null @@ -1,233 +0,0 @@ -/// -/// Testing for the header pbl-exception.h -/// -/// @author Luna-Klatzer - -#include -#include "gtest/gtest.h" - -TEST(FunctionMetaTest, PblMetaFunctionCallCtxDefaults) { - PBL_ALLOC_DECLARATION(v_1, PblMetaFunctionCallCtx_T); - - EXPECT_EQ( - PblMetaFunctionCallCtx_T_Size, - sizeof(PblBool_T *) + sizeof(PblUInt_T *) + sizeof(PblBool_T *) + 2 * sizeof(PblMetaFunctionCallCtx_T* ) + sizeof(NULL) - ); - EXPECT_EQ(v_1->meta.defined, false); - - PBL_ALLOC_DEFINITION(v_2, PblMetaFunctionCallCtx_T); - - EXPECT_TRUE(v_2->actual.call_origin_ctx == NULL); - EXPECT_TRUE(v_2->actual.exception == NULL); - EXPECT_TRUE(v_2->actual.failure_origin_ctx == NULL); - EXPECT_TRUE(v_2->actual.is_failure == NULL); - EXPECT_TRUE(v_2->actual.arg_amount == NULL); - EXPECT_TRUE(v_2->actual.function_identifier == NULL); - EXPECT_EQ( - PblMetaFunctionCallCtx_T_Size, - sizeof(PblBool_T *) + sizeof(PblUInt_T *) + sizeof(PblBool_T *) + 2 * sizeof(PblMetaFunctionCallCtx_T* ) + sizeof(NULL) - ); - EXPECT_TRUE(v_2->meta.defined); -} - -TEST(ExceptionTest, PblExceptionDefaults) { - PBL_ALLOC_DECLARATION(v_1, PblException_T); - - EXPECT_EQ(PblException_T_Size, 4 * sizeof(PblString_T *) + sizeof(PblUInt_T *) + 2 * sizeof(void*)); - EXPECT_EQ(v_1->meta.defined, false); - - PBL_ALLOC_DEFINITION(v_2, PblException_T); - - EXPECT_TRUE(v_2->actual.child_exc == NULL); - EXPECT_TRUE(v_2->actual.parent_exc == NULL); - EXPECT_TRUE(v_2->actual.name == NULL); - EXPECT_TRUE(v_2->actual.msg == NULL); - EXPECT_TRUE(v_2->actual.filename == NULL); - EXPECT_TRUE(v_2->actual.line_content == NULL); - EXPECT_TRUE(v_2->actual.line == NULL); - EXPECT_EQ(PblException_T_Size, 4 * sizeof(PblString_T *) + sizeof(PblUInt_T *) + 2 * sizeof(void*)); - EXPECT_EQ(v_2->meta.defined, true); -} - -PblInt_T* NestedTestFunction(PblMetaFunctionCallCtx_T* this_call_meta, PblUInt_T* i) -{ - PblUInt_T* line = PblGetUIntT(__LINE__); - PblException_T* exception = PblGetExceptionT( - PblGetStringT("test"), - PblGetStringT("TestException"), - PblGetStringT(__FILE__), - line, - PblGetStringT("raise exception"), - NULL, - NULL - ); - PBL_RAISE_EXCEPTION(exception, PblInt_T); -} - -PblInt_T* TestFunction(PblMetaFunctionCallCtx_T* this_call_meta) -{ - PBL_ALLOC_DECLARATION(r_1, PblInt_T); - - /// creating a copy of the addr, if the pointer is accidentally set to NULL by the function returning NULL (due to - /// the exception occurring) - PBL_CREATE_ADDRESS_COPY(r_1, PblInt_T*, H3); - PBL_EXCEPTION_CATCH_FUNC_CONSTRUCTOR(NestedTestFunction, r_1, PblInt_T*, X1, PblGetUIntT(1)); - - // if the function failed, treat the return as invalid -> restore previous value - // in this case the function raises an exception and as such it will never reach this code - if (this_call_meta->actual.is_failure->actual) - { - // Restore if NULL -> here it should be restored as NULL is returned - PBL_PASTE_ADDRESS_COPY(r_1, PblInt_T *, H3); - } - return r_1; -} - -TEST(ExceptionTest, OneNestCall) { - PBL_ALLOC_DECLARATION(r_1, PblInt_T); - PBL_ALLOC_DEFINITION(this_call_meta, PblMetaFunctionCallCtx_T); - this_call_meta->actual.is_failure = PblGetBoolT(false); - - // creating a copy of the addr, if the pointer is accidentally set to NULL by the function returning NULL (due to - // the exception occurring) - PBL_CREATE_ADDRESS_COPY(r_1, PblInt_T*, H3); - /// Call the function and update the local ctx if an exception was raised - PBL_C_BASE_EXCEPTION_CATCH_CONSTRUCTOR(TestFunction, r_1, H3, PblGetBoolT(false),this_call_meta,); - - // if the function failed, treat the return as invalid -> restore previous value - if (this_call_meta->actual.is_failure->actual) - { - // Restore if NULL -> here it should be restored as NULL is returned - PBL_PASTE_ADDRESS_COPY(r_1, PblInt_T *, H3); - } - - // the return should have failed aka. the value should have been set to NULL and then restored by - // 'PBL_PASTE_ADDRESS_COPY' - EXPECT_EQ(r_1->meta.defined, false); - EXPECT_TRUE(this_call_meta->actual.is_failure->actual); - EXPECT_TRUE(this_call_meta->actual.failure_origin_ctx != NULL); - EXPECT_TRUE(this_call_meta->actual.exception != NULL); - EXPECT_TRUE(this_call_meta->actual.call_origin_ctx == NULL); - PblString_T* default_name = PblGetStringT("test"); - EXPECT_TRUE( - PblCompareStringT( - ((PblException_T* ) this_call_meta->actual.exception)->actual.msg, default_name)->actual - ); - PblString_T* default_msg = PblGetStringT("TestException"); - EXPECT_TRUE( - PblCompareStringT( - ((PblException_T* ) this_call_meta->actual.exception)->actual.name, default_msg)->actual - ); - PblString_T* default_filename = PblGetStringT(__FILE__); - EXPECT_TRUE( - PblCompareStringT( - ((PblException_T* ) this_call_meta->actual.exception)->actual.filename, default_filename)->actual - ); - PblString_T* default_line_content = PblGetStringT("raise exception"); - EXPECT_TRUE( - PblCompareStringT( - ((PblException_T* ) this_call_meta->actual.exception)->actual.line_content, default_line_content)->actual - ); -} - -PblInt_T* TestFunction2(PblMetaFunctionCallCtx_T* this_call_meta) { - /// Call the block and execute the except block if the exc names match - PBL_EXCEPTION_TRY_EXCEPT_BLOCK( - { - PBL_ALLOC_DECLARATION(r_1, PblInt_T); - PBL_EXCEPTION_TRY_BLOCK_CATCH_FUNC_CONSTRUCTOR(NestedTestFunction, r_1, PblInt_T*, X1, Y2, PblGetUIntT(1)) - return r_1; - }, - {PBL_EXCEPTION_CREATE_EXCEPT_BLOCK( - "test", - { - return PblGetIntT(1); - }, - Y2 - ) - }, - Y2, - this_call_meta, - PblInt_T - ); - // default return is 0 - aka. the exception was raised - return PblGetIntT(0); -} - -TEST(ExceptionTest, TryExceptCall) { - PBL_ALLOC_DECLARATION(r_1, PblInt_T); - PBL_ALLOC_DEFINITION(this_call_meta, PblMetaFunctionCallCtx_T); - this_call_meta->actual.is_failure = PblGetBoolT(false); - - // creating a copy of the addr, if the pointer is accidentally set to NULL by the function returning NULL (due to - // the exception occurring) - PBL_CREATE_ADDRESS_COPY(r_1, PblInt_T*, H3); - /// Call the function and update the local ctx if an exception was raised - PBL_C_BASE_EXCEPTION_CATCH_CONSTRUCTOR(TestFunction2, r_1, H3, PblGetBoolT(false), this_call_meta,); - - // if the function failed, treat the return as invalid -> restore previous value - if (this_call_meta->actual.is_failure->actual) - { - // Restore if NULL -> here it should be restored as NULL is returned - PBL_PASTE_ADDRESS_COPY(r_1, PblInt_T *, H3); - } - - // Try-except should never if there is a except statement that was executed, log it's exception and throw the results - // away right after finishing up - EXPECT_FALSE(this_call_meta->actual.is_failure->actual); - EXPECT_TRUE(this_call_meta->actual.failure_origin_ctx == NULL); - EXPECT_TRUE(this_call_meta->actual.exception == NULL); - EXPECT_TRUE(this_call_meta->actual.call_origin_ctx == NULL); - EXPECT_EQ(r_1->meta.defined, true); - EXPECT_EQ(r_1->actual, 1); -} - -PblInt_T* TestFunction3(PblMetaFunctionCallCtx_T* this_call_meta) { - /// Call the block and execute the except block if the exc names match - PBL_EXCEPTION_TRY_EXCEPT_BLOCK( - { - PBL_ALLOC_DECLARATION(r_1, PblInt_T); - PBL_EXCEPTION_TRY_BLOCK_CATCH_FUNC_CONSTRUCTOR(NestedTestFunction, r_1, PblInt_T*, X1, Y2, PblGetUIntT(1)) - return r_1; - }, - {PBL_EXCEPTION_CREATE_EXCEPT_BLOCK( - "test", - { - return PblGetIntT(1); - }, - Y2 - ) - }, - Y2, - this_call_meta, - PblInt_T - ); - // default return is 0 - aka. the exception was raised - return PblGetIntT(0); -} - -TEST(ExceptionTest, TryExceptCallWithContinuation) { - PBL_ALLOC_DECLARATION(r_1, PblInt_T); - PBL_ALLOC_DEFINITION(this_call_meta, PblMetaFunctionCallCtx_T); - this_call_meta->actual.is_failure = PblGetBoolT(false); - - // creating a copy of the addr, if the pointer is accidentally set to NULL by the function returning NULL (due to - // the exception occurring) - PBL_CREATE_ADDRESS_COPY(r_1, PblInt_T*, H3); - /// Call the function and update the local ctx if an exception was raised - PBL_C_BASE_EXCEPTION_CATCH_CONSTRUCTOR(TestFunction3, r_1, H3, PblGetBoolT(false), this_call_meta,); - - // if the function failed, treat the return as invalid -> restore previous value - if (this_call_meta->actual.is_failure->actual) - { - // Restore if NULL -> here it should be restored as NULL is returned - PBL_PASTE_ADDRESS_COPY(r_1, PblInt_T *, H3); - } - - EXPECT_FALSE(this_call_meta->actual.is_failure->actual); - EXPECT_TRUE(this_call_meta->actual.failure_origin_ctx == NULL); - EXPECT_TRUE(this_call_meta->actual.exception == NULL); - EXPECT_TRUE(this_call_meta->actual.call_origin_ctx == NULL); - EXPECT_EQ(r_1->meta.defined, true); - EXPECT_EQ(r_1->actual, 1); -} \ No newline at end of file diff --git a/tests/tests/test_parac_modules.cpp b/tests/tests/test_parac_modules.cpp deleted file mode 100644 index 98dad2e..0000000 --- a/tests/tests/test_parac_modules.cpp +++ /dev/null @@ -1,12 +0,0 @@ -/// -/// Testing for the macros in the header pbl.h -/// -/// @author Luna-Klatzer - -#include -#include "gtest/gtest.h" - -TEST(MacroTest, SimpleCheckForExistances) { - EXPECT_TRUE(__parac); - EXPECT_STREQ(__parac, "0.1.dev6"); -} \ No newline at end of file diff --git a/tests/tests/test_int.cpp b/tests/types/test_int.cpp similarity index 91% rename from tests/tests/test_int.cpp rename to tests/types/test_int.cpp index 06fb819..8a8fa3b 100644 --- a/tests/tests/test_int.cpp +++ b/tests/types/test_int.cpp @@ -3,18 +3,21 @@ /// /// @author Luna-Klatzer -#include +// Including the required GTest #include "gtest/gtest.h" +// Including the header to be tested +#include + TEST(BaseTypesTest, PblInt8) { - PblInt8_T* v = PblGetInt8T(0); + PblInt8_T *v = PblGetInt8T(0); EXPECT_EQ(v->actual, 0); EXPECT_EQ(PblInt8_T_Size, sizeof(int8_t)); EXPECT_EQ(v->meta.defined, true); } TEST(BaseTypesTest, PblUInt8) { - PblUInt8_T* v = PblGetUInt8T(0); + PblUInt8_T *v = PblGetUInt8T(0); EXPECT_EQ(v->actual, 0); EXPECT_EQ(PblUInt8_T_Size, sizeof(int8_t)); EXPECT_EQ(v->meta.defined, true); @@ -47,14 +50,14 @@ TEST(BaseTypesTest, PblUInt8Defaults) { } TEST(BaseTypesTest, PblInt16) { - PblInt16_T* v = PblGetInt16T(0); + PblInt16_T *v = PblGetInt16T(0); EXPECT_EQ(v->actual, 0); EXPECT_EQ(PblInt16_T_Size, sizeof(int16_t)); EXPECT_EQ(v->meta.defined, true); } TEST(BaseTypesTest, PblUInt16) { - PblUInt16_T* v = PblGetUInt16T(0); + PblUInt16_T *v = PblGetUInt16T(0); EXPECT_EQ(v->actual, 0); EXPECT_EQ(PblUInt16_T_Size, sizeof(int16_t)); EXPECT_EQ(v->meta.defined, true); @@ -87,14 +90,14 @@ TEST(BaseTypesTest, PblUInt16Defaults) { } TEST(BaseTypesTest, PblInt32) { - PblInt32_T* v = PblGetInt32T(0); + PblInt32_T *v = PblGetInt32T(0); EXPECT_EQ(v->actual, 0); EXPECT_EQ(PblInt32_T_Size, sizeof(int32_t)); EXPECT_EQ(v->meta.defined, true); } TEST(BaseTypesTest, PblUInt32) { - PblUInt32_T* v = PblGetUInt32T(0); + PblUInt32_T *v = PblGetUInt32T(0); EXPECT_EQ(v->actual, 0); EXPECT_EQ(PblUInt32_T_Size, sizeof(int32_t)); EXPECT_EQ(v->meta.defined, true); @@ -127,14 +130,14 @@ TEST(BaseTypesTest, PblUInt32Defaults) { } TEST(BaseTypesTest, PblInt64) { - PblInt64_T* v = PblGetInt64T(0); + PblInt64_T *v = PblGetInt64T(0); EXPECT_EQ(v->actual, 0); EXPECT_EQ(PblInt64_T_Size, sizeof(int64_t)); EXPECT_EQ(v->meta.defined, true); } TEST(BaseTypesTest, PblUInt64) { - PblUInt64_T* v = PblGetUInt64T(0); + PblUInt64_T *v = PblGetUInt64T(0); EXPECT_EQ(v->actual, 0); EXPECT_EQ(PblUInt64_T_Size, sizeof(int64_t)); EXPECT_EQ(v->meta.defined, true); @@ -167,14 +170,14 @@ TEST(BaseTypesTest, PblUInt64Defaults) { } TEST(BaseTypesTest, PblLeastInt8) { - PblLeastInt8_T* v = PblGetLeastInt8T(0); + PblLeastInt8_T *v = PblGetLeastInt8T(0); EXPECT_EQ(v->actual, 0); EXPECT_EQ(PblLeastInt8_T_Size, sizeof(int_least8_t)); EXPECT_EQ(v->meta.defined, true); } TEST(BaseTypesTest, PblULeastInt8) { - PblULeastInt8_T* v = PblGetULeastInt8T(0); + PblULeastInt8_T *v = PblGetULeastInt8T(0); EXPECT_EQ(v->actual, 0); EXPECT_EQ(PblULeastInt8_T_Size, sizeof(int_least8_t)); EXPECT_EQ(v->meta.defined, true); @@ -207,14 +210,14 @@ TEST(BaseTypesTest, PblULeastInt8Defaults) { } TEST(BaseTypesTest, PblLeastInt16) { - PblLeastInt16_T* v = PblGetLeastInt16T(0); + PblLeastInt16_T *v = PblGetLeastInt16T(0); EXPECT_EQ(v->actual, 0); EXPECT_EQ(PblLeastInt16_T_Size, sizeof(int_least16_t)); EXPECT_EQ(v->meta.defined, true); } TEST(BaseTypesTest, PblULeastInt16) { - PblULeastInt16_T* v = PblGetULeastInt16T(0); + PblULeastInt16_T *v = PblGetULeastInt16T(0); EXPECT_EQ(v->actual, 0); EXPECT_EQ(PblULeastInt16_T_Size, sizeof(int_least16_t)); EXPECT_EQ(v->meta.defined, true); @@ -247,14 +250,14 @@ TEST(BaseTypesTest, PblULeastInt16Defaults) { } TEST(BaseTypesTest, PblLeastInt32) { - PblLeastInt32_T* v = PblGetLeastInt32T(0); + PblLeastInt32_T *v = PblGetLeastInt32T(0); EXPECT_EQ(v->actual, 0); EXPECT_EQ(PblLeastInt32_T_Size, sizeof(int_least32_t)); EXPECT_EQ(v->meta.defined, true); } TEST(BaseTypesTest, PblULeastInt32) { - PblULeastInt32_T* v = PblGetULeastInt32T(0); + PblULeastInt32_T *v = PblGetULeastInt32T(0); EXPECT_EQ(v->actual, 0); EXPECT_EQ(PblULeastInt32_T_Size, sizeof(int_least32_t)); EXPECT_EQ(v->meta.defined, true); @@ -287,14 +290,14 @@ TEST(BaseTypesTest, PblULeastInt32Defaults) { } TEST(BaseTypesTest, PblLeastInt64) { - PblLeastInt64_T* v = PblGetLeastInt64T(0); + PblLeastInt64_T *v = PblGetLeastInt64T(0); EXPECT_EQ(v->actual, 0); EXPECT_EQ(PblLeastInt64_T_Size, sizeof(int_least64_t)); EXPECT_EQ(v->meta.defined, true); } TEST(BaseTypesTest, PblULeastInt64) { - PblULeastInt64_T* v = PblGetULeastInt64T(0); + PblULeastInt64_T *v = PblGetULeastInt64T(0); EXPECT_EQ(v->actual, 0); EXPECT_EQ(PblULeastInt64_T_Size, sizeof(int_least64_t)); EXPECT_EQ(v->meta.defined, true); @@ -327,14 +330,14 @@ TEST(BaseTypesTest, PblULeastInt64Defaults) { } TEST(BaseTypesTest, PblFastInt8) { - PblFastInt8_T* v = PblGetFastInt8T(0); + PblFastInt8_T *v = PblGetFastInt8T(0); EXPECT_EQ(v->actual, 0); EXPECT_EQ(PblFastInt8_T_Size, sizeof(int_fast8_t)); EXPECT_EQ(v->meta.defined, true); } TEST(BaseTypesTest, PblUFastInt8) { - PblUFastInt8_T* v = PblGetUFastInt8T(0); + PblUFastInt8_T *v = PblGetUFastInt8T(0); EXPECT_EQ(v->actual, 0); EXPECT_EQ(PblUFastInt8_T_Size, sizeof(int_fast8_t)); EXPECT_EQ(v->meta.defined, true); @@ -367,14 +370,14 @@ TEST(BaseTypesTest, PblUFastInt8Defaults) { } TEST(BaseTypesTest, PblFastInt16) { - PblFastInt16_T* v = PblGetFastInt16T(0); + PblFastInt16_T *v = PblGetFastInt16T(0); EXPECT_EQ(v->actual, 0); EXPECT_EQ(PblFastInt16_T_Size, sizeof(int_fast16_t)); EXPECT_EQ(v->meta.defined, true); } TEST(BaseTypesTest, PblUFastInt16) { - PblUFastInt16_T* v = PblGetUFastInt16T(0); + PblUFastInt16_T *v = PblGetUFastInt16T(0); EXPECT_EQ(v->actual, 0); EXPECT_EQ(PblUFastInt16_T_Size, sizeof(int_fast16_t)); EXPECT_EQ(v->meta.defined, true); @@ -407,14 +410,14 @@ TEST(BaseTypesTest, PblUFastInt16Defaults) { } TEST(BaseTypesTest, PblFastInt32) { - PblFastInt32_T* v = PblGetFastInt32T(0); + PblFastInt32_T *v = PblGetFastInt32T(0); EXPECT_EQ(v->actual, 0); EXPECT_EQ(PblFastInt32_T_Size, sizeof(int_fast32_t)); EXPECT_EQ(v->meta.defined, true); } TEST(BaseTypesTest, PblUFastInt32) { - PblUFastInt32_T* v = PblGetUFastInt32T(0); + PblUFastInt32_T *v = PblGetUFastInt32T(0); EXPECT_EQ(v->actual, 0); EXPECT_EQ(PblUFastInt32_T_Size, sizeof(int_fast32_t)); EXPECT_EQ(v->meta.defined, true); @@ -447,14 +450,14 @@ TEST(BaseTypesTest, PblUFastInt32Defaults) { } TEST(BaseTypesTest, PblFastInt64) { - PblFastInt64_T* v = PblGetFastInt64T(0); + PblFastInt64_T *v = PblGetFastInt64T(0); EXPECT_EQ(v->actual, 0); EXPECT_EQ(PblFastInt64_T_Size, sizeof(int_fast64_t)); EXPECT_EQ(v->meta.defined, true); } TEST(BaseTypesTest, PblUFastInt64) { - PblUFastInt64_T* v = PblGetUFastInt64T(0); + PblUFastInt64_T *v = PblGetUFastInt64T(0); EXPECT_EQ(v->actual, 0); EXPECT_EQ(PblUFastInt64_T_Size, sizeof(int_fast64_t)); EXPECT_EQ(v->meta.defined, true); diff --git a/tests/tests/test_string.cpp b/tests/types/test_string.cpp similarity index 75% rename from tests/tests/test_string.cpp rename to tests/types/test_string.cpp index b535197..a11d284 100644 --- a/tests/tests/test_string.cpp +++ b/tests/types/test_string.cpp @@ -2,10 +2,11 @@ /// /// @author Luna-Klatzer -#include +// Including the required GTest #include "gtest/gtest.h" -// IMPORTANT! When actually using PblString_T, do NOT use a bigger length than of the actual string +// Including the header to be tested +#include TEST(StringTypesTest, GetLenghtOfCString) { EXPECT_EQ(PblGetLengthOfCString("")->actual, 0); @@ -14,21 +15,15 @@ TEST(StringTypesTest, GetLenghtOfCString) { } TEST(StringTypesTest, GetStringConversion) { - PblString_T* string_1 = PblGetStringT("hello"); + PblString_T *string_1 = PblGetStringT("hello"); - EXPECT_EQ( - PblString_T_Size, - sizeof(PblSize_T *) + sizeof(PblUInt_T *) + sizeof(PblUInt_T *) + sizeof(char *) - ); + EXPECT_EQ(PblString_T_Size, sizeof(PblSize_T *) + sizeof(PblUInt_T *) + sizeof(PblUInt_T *) + sizeof(char *)); EXPECT_EQ(string_1->actual.len->actual, 5); EXPECT_EQ(string_1->actual.allocated_len->actual, 51); - PblString_T* string_2 = PblGetStringT("world"); + PblString_T *string_2 = PblGetStringT("world"); - EXPECT_EQ( - PblString_T_Size, - sizeof(PblSize_T *) + sizeof(PblUInt_T *) + sizeof(PblUInt_T *) + sizeof(char *) - ); + EXPECT_EQ(PblString_T_Size, sizeof(PblSize_T *) + sizeof(PblUInt_T *) + sizeof(PblUInt_T *) + sizeof(char *)); EXPECT_EQ(string_2->actual.len->actual, 5); EXPECT_EQ(string_2->actual.allocated_len->actual, 51); @@ -38,7 +33,7 @@ TEST(StringTypesTest, GetStringConversion) { } TEST(StringTypesTest, SimpleAllocation1) { - PblString_T* str = PblCreateStringT(PblGetCharTArray("hello world"), PblGetUIntT(15)); + PblString_T *str = PblCreateStringT(PblGetCharTArray("hello world"), PblGetUIntT(15)); // size is per default 50 + 1 (for null char) EXPECT_EQ(str->actual.allocated_len->actual, 51); @@ -48,7 +43,7 @@ TEST(StringTypesTest, SimpleAllocation1) { } TEST(StringTypesTest, SimpleAllocation2) { - PblString_T* str = PblCreateStringT(PblGetCharTArray("hello world"), PblGetUIntT(60)); + PblString_T *str = PblCreateStringT(PblGetCharTArray("hello world"), PblGetUIntT(60)); // size is per default 50 + 1 (for null char) - will be resized to 100, since len is 60 EXPECT_EQ(str->actual.allocated_len->actual, 101); @@ -58,7 +53,7 @@ TEST(StringTypesTest, SimpleAllocation2) { } TEST(StringTypesTest, SimpleAllocation3) { - PblString_T* str = PblCreateStringT(PblGetCharTArray("hello world"), PblGetUIntT(600)); + PblString_T *str = PblCreateStringT(PblGetCharTArray("hello world"), PblGetUIntT(600)); // size is per default 50 + 1 (for null char) - will be resized to 100, since len is 60 EXPECT_EQ(str->actual.allocated_len->actual, 601); @@ -68,7 +63,7 @@ TEST(StringTypesTest, SimpleAllocation3) { } TEST(StringTypesTest, ValidateDeallocation) { - PblString_T* str = PblCreateStringT(PblGetCharTArray("hello world"), PblGetUIntT(49)); + PblString_T *str = PblCreateStringT(PblGetCharTArray("hello world"), PblGetUIntT(49)); // size is per default 50 + 1 (for null char) - will be resized to 100, since len is 60 EXPECT_EQ(str->actual.allocated_len->actual, 51); @@ -78,7 +73,7 @@ TEST(StringTypesTest, ValidateDeallocation) { } TEST(StringTypesTest, ValidateAllocation) { - PblString_T* str = PblCreateStringT(PblGetCharTArray("hello world"), PblGetUIntT(49)); + PblString_T *str = PblCreateStringT(PblGetCharTArray("hello world"), PblGetUIntT(49)); // size is per default 50 + 1 (for null char) EXPECT_EQ(str->actual.allocated_len->actual, 51); @@ -89,7 +84,7 @@ TEST(StringTypesTest, ValidateAllocation) { } TEST(StringTypesTest, ValidateOverwrite) { - PblString_T* str = PblCreateStringT(PblGetCharTArray("hello world"), PblGetUIntT(11)); + PblString_T *str = PblCreateStringT(PblGetCharTArray("hello world"), PblGetUIntT(11)); // size is per default 50 + 1 (for null char) EXPECT_EQ(str->actual.allocated_len->actual, 51); EXPECT_EQ(str->actual.len->actual, 11); @@ -103,12 +98,13 @@ TEST(StringTypesTest, ValidateOverwrite) { } TEST(StringTypesTest, ValidateReallocOverwrite) { - PblString_T* str = PblCreateStringT(PblGetCharTArray("hello world"), PblGetUIntT(11)); + PblString_T *str = PblCreateStringT(PblGetCharTArray("hello world"), PblGetUIntT(11)); // size is per default 50 + 1 (for null char) EXPECT_EQ(str->actual.allocated_len->actual, 51); EXPECT_EQ(str->actual.len->actual, 11); - PblWriteCharArrayToStringT(str, PblGetCharTArray("12345678901234567890123456789012345678901234567890"), PblGetUIntT(50)); + PblWriteCharArrayToStringT(str, PblGetCharTArray("12345678901234567890123456789012345678901234567890"), + PblGetUIntT(50)); EXPECT_EQ(str->actual.allocated_len->actual, 51); EXPECT_EQ(str->actual.len->actual, 50); @@ -129,9 +125,9 @@ TEST(StringTypesTest, GetAllocSizeStringT) { } TEST(StringTypesTest, PblGetCCharArrayFromCharT) { - PblChar_T* char_arr_1 = PblGetCharTArray("hello"); - PblChar_T* char_arr_2 = PblGetCharTArray("hello world"); - PblChar_T* char_arr_3 = PblGetCharTArray("hello new world"); + PblChar_T *char_arr_1 = PblGetCharTArray("hello"); + PblChar_T *char_arr_2 = PblGetCharTArray("hello world"); + PblChar_T *char_arr_3 = PblGetCharTArray("hello new world"); EXPECT_STREQ(PblGetCCharArrayFromCharT(char_arr_1, PblGetUIntT(5)), "hello"); EXPECT_STREQ(PblGetCCharArrayFromCharT(char_arr_2, PblGetUIntT(11)), "hello world"); @@ -139,9 +135,9 @@ TEST(StringTypesTest, PblGetCCharArrayFromCharT) { } TEST(StringTypesTest, PblGetCCharArrayFromString) { - PblString_T* str_1 = PblGetStringT("hello"); - PblString_T* str_2 = PblGetStringT("hello world"); - PblString_T* str_3 = PblGetStringT("hello new world"); + PblString_T *str_1 = PblGetStringT("hello"); + PblString_T *str_2 = PblGetStringT("hello world"); + PblString_T *str_3 = PblGetStringT("hello new world"); EXPECT_STREQ(PblGetCCharArrayFromString(str_1), "hello"); EXPECT_STREQ(PblGetCCharArrayFromString(str_2), "hello world"); @@ -149,10 +145,10 @@ TEST(StringTypesTest, PblGetCCharArrayFromString) { } TEST(StringTypesTest, PblWriteStringToStringT) { - PblString_T* str_1 = PblGetStringT("hello"); - PblString_T* str_2 = PblGetStringT("hello world"); - PblString_T* str_3 = PblGetStringT("hello new world"); - PblString_T* str_4 = PblGetStringT("hello new world world"); + PblString_T *str_1 = PblGetStringT("hello"); + PblString_T *str_2 = PblGetStringT("hello world"); + PblString_T *str_3 = PblGetStringT("hello new world"); + PblString_T *str_4 = PblGetStringT("hello new world world"); EXPECT_FALSE(PblCompareStringT(str_1, str_2)->actual); EXPECT_FALSE(PblCompareStringT(str_2, str_3)->actual); diff --git a/tests/tests/test_types.cpp b/tests/types/test_types.cpp similarity index 81% rename from tests/tests/test_types.cpp rename to tests/types/test_types.cpp index 37c4304..bcc8128 100644 --- a/tests/tests/test_types.cpp +++ b/tests/types/test_types.cpp @@ -2,21 +2,62 @@ /// /// @author Luna-Klatzer -#include +// Including the required GTest #include "gtest/gtest.h" -// TODO! Add tests for the type defaults and size +// Including the header to be tested +#include TEST(MacroTypesTest, PblSizeof) { - EXPECT_EQ(PblBool_T_Size, PBL_SIZEOF(PblBool_T)); + EXPECT_EQ(PblBool_T_Size, PBL_SIZEOF_USABLE(PblBool_T)); } TEST(MacroTypesTest, CSizeof) { - EXPECT_EQ(sizeof(char), PBL_C_SIZEOF(char)); + EXPECT_EQ(sizeof(char), PBL_SIZEOF_FULL(char)); +} + +TEST(PointerTest, PblPointerWithNULL) { + PBL_DEFINE_VAR(pointer, PblPointer_T); + EXPECT_EQ(pointer->actual.p_void, nullptr); + EXPECT_EQ(pointer->actual.p_type, nullptr); +} + +TEST(PointerTest, PblPointerUsageWithoutType) { + PBL_DEFINE_VAR(pointer, PblPointer_T); + PBL_DEFINE_VAR(integer, PblInt_T); + + integer = PblGetIntT(4); + pointer->actual.p_void = integer; + + EXPECT_EQ(((PblInt_T*) pointer->actual.p_void)->actual, integer->actual); +} + +TEST(PointerTest, VoidPblPointerWithoutType) { + PBL_DEFINE_VAR(pointer, PblPointer_T); + PBL_DEFINE_VAR(integer, PblInt_T); + + integer = PblGetIntT(4); + pointer->actual.p_void = integer; + + EXPECT_EQ(((PblInt_T*) pointer->actual.p_void)->actual, integer->actual); +} + +TEST(BaseTypesTest, PblPointerDefaults) { + PblPointer_T v_1 = PblPointer_T_DeclDefault; + + EXPECT_EQ(PblPointer_T_Size, sizeof(void*)); + EXPECT_EQ(v_1.meta.defined, false); + + PblPointer_T v_2 = PblPointer_T_DefDefault; + + EXPECT_EQ(v_2.actual.p_void, nullptr); + EXPECT_EQ(v_2.actual.p_type, nullptr); + EXPECT_EQ(PblPointer_T_Size, sizeof(void*)); + EXPECT_EQ(v_2.meta.defined, true); } TEST(BaseTypesTest, PblBool) { - PblBool_T* v = PblGetBoolT(true); + PblBool_T *v = PblGetBoolT(true); EXPECT_EQ(v->actual, true); EXPECT_EQ(PblBool_T_Size, sizeof(bool)); EXPECT_EQ(v->meta.defined, true); @@ -36,7 +77,7 @@ TEST(BaseTypesTest, PblBoolDefaults) { } TEST(BaseTypesTest, PblSize) { - PblSize_T* v = PblGetSizeT(sizeof(int)); + PblSize_T *v = PblGetSizeT(sizeof(int)); EXPECT_EQ(v->actual, sizeof(int)); EXPECT_EQ(PblSize_T_Size, sizeof(size_t)); EXPECT_EQ(v->meta.defined, true); @@ -56,7 +97,7 @@ TEST(BaseTypesTest, PblSizeDefaults) { } TEST(BaseTypesTest, PblChar) { - PblChar_T* v = PblGetCharT('x'); + PblChar_T *v = PblGetCharT('x'); EXPECT_EQ(v->actual, 'x'); EXPECT_EQ(PblChar_T_Size, sizeof(unsigned char)); EXPECT_EQ(PblChar_T_Size, sizeof(signed char)); @@ -65,7 +106,7 @@ TEST(BaseTypesTest, PblChar) { } TEST(BaseTypesTest, PblUChar) { - PblUChar_T* v = PblGetUCharT('x'); + PblUChar_T *v = PblGetUCharT('x'); EXPECT_EQ(v->actual, 'x'); EXPECT_EQ(PblUChar_T_Size, sizeof(unsigned char)); EXPECT_EQ(PblUChar_T_Size, sizeof(signed char)); @@ -100,7 +141,7 @@ TEST(BaseTypesTest, PblUCharDefaults) { } TEST(BaseTypesTest, PblShort) { - PblShort_T* v = PblGetShortT('x'); + PblShort_T *v = PblGetShortT('x'); EXPECT_EQ(v->actual, 'x'); EXPECT_EQ(PblShort_T_Size, sizeof(unsigned short)); EXPECT_EQ(PblShort_T_Size, sizeof(signed short)); @@ -109,7 +150,7 @@ TEST(BaseTypesTest, PblShort) { } TEST(BaseTypesTest, PblUShort) { - PblUShort_T* v = PblGetUShortT('x'); + PblUShort_T *v = PblGetUShortT('x'); EXPECT_EQ(v->actual, 'x'); EXPECT_EQ(PblShort_T_Size, sizeof(unsigned short)); EXPECT_EQ(PblShort_T_Size, sizeof(signed short)); @@ -144,7 +185,7 @@ TEST(BaseTypesTest, PblUShortDefaults) { } TEST(BaseTypesTest, PblInt) { - PblInt_T* v = PblGetIntT('x'); + PblInt_T *v = PblGetIntT('x'); EXPECT_EQ(v->actual, 'x'); EXPECT_EQ(PblInt_T_Size, sizeof(unsigned int)); EXPECT_EQ(PblInt_T_Size, sizeof(signed int)); @@ -153,7 +194,7 @@ TEST(BaseTypesTest, PblInt) { } TEST(BaseTypesTest, PblUInt) { - PblUInt_T* v = PblGetUIntT('x'); + PblUInt_T *v = PblGetUIntT('x'); EXPECT_EQ(v->actual, 'x'); EXPECT_EQ(PblUInt_T_Size, sizeof(unsigned int)); EXPECT_EQ(PblUInt_T_Size, sizeof(signed int)); @@ -188,7 +229,7 @@ TEST(BaseTypesTest, PblUIntDefaults) { } TEST(BaseTypesTest, PblLong) { - PblLong_T* v = PblGetLongT('x'); + PblLong_T *v = PblGetLongT('x'); EXPECT_EQ(v->actual, 'x'); EXPECT_EQ(PblLong_T_Size, sizeof(unsigned long)); EXPECT_EQ(PblLong_T_Size, sizeof(signed long)); @@ -197,7 +238,7 @@ TEST(BaseTypesTest, PblLong) { } TEST(BaseTypesTest, PblULong) { - PblULong_T* v = PblGetULongT('x'); + PblULong_T *v = PblGetULongT('x'); EXPECT_EQ(v->actual, 'x'); EXPECT_EQ(PblULong_T_Size, sizeof(unsigned long)); EXPECT_EQ(PblULong_T_Size, sizeof(signed long)); @@ -232,7 +273,7 @@ TEST(BaseTypesTest, PblULongDefaults) { } TEST(BaseTypesTest, PblLongLong) { - PblLongLong_T* v = PblGetLongLongT('x'); + PblLongLong_T *v = PblGetLongLongT('x'); EXPECT_EQ(v->actual, 'x'); EXPECT_EQ(PblLongLong_T_Size, sizeof(unsigned long long)); EXPECT_EQ(PblLongLong_T_Size, sizeof(signed long long)); @@ -241,7 +282,7 @@ TEST(BaseTypesTest, PblLongLong) { } TEST(BaseTypesTest, PblULongLong) { - PblULongLong_T* v = PblGetULongLongT('x'); + PblULongLong_T *v = PblGetULongLongT('x'); EXPECT_EQ(v->actual, 'x'); EXPECT_EQ(PblULongLong_T_Size, sizeof(unsigned long long)); EXPECT_EQ(PblULongLong_T_Size, sizeof(signed long long)); @@ -276,7 +317,7 @@ TEST(BaseTypesTest, PblULongLongDefaults) { } TEST(BaseTypesTest, PblFloat) { - PblFloat_T* v = PblGetFloatT('x'); + PblFloat_T *v = PblGetFloatT('x'); EXPECT_EQ(v->actual, 'x'); EXPECT_EQ(PblFloat_T_Size, sizeof(float)); EXPECT_EQ(v->meta.defined, true); @@ -296,7 +337,7 @@ TEST(BaseTypesTest, PblFloatDefaults) { } TEST(BaseTypesTest, PblDouble) { - PblDouble_T* v = PblGetDoubleT('x'); + PblDouble_T *v = PblGetDoubleT('x'); EXPECT_EQ(v->actual, 'x'); EXPECT_EQ(PblDouble_T_Size, sizeof(double)); EXPECT_EQ(v->meta.defined, true); @@ -316,7 +357,7 @@ TEST(BaseTypesTest, PblDoubleDefaults) { } TEST(BaseTypesTest, PblLongDouble) { - PblLongDouble_T* v = PblGetLongDoubleT('x'); + PblLongDouble_T *v = PblGetLongDoubleT('x'); EXPECT_EQ(v->actual, 'x'); EXPECT_EQ(PblLongDouble_T_Size, sizeof(long double)); EXPECT_EQ(v->meta.defined, true);