λ61
Loading...
Searching...
No Matches
defs.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2025 Tetex7
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18//
19// Created by tete on 05/01/2025.
20//
21#pragma once
22
23//Documentation in this header is still work in progress
24//Professionalism is not guaranteed And will never be lol
25
26#ifndef L61_DEFS_HPP
27#define L61_DEFS_HPP
28
29#include <cstdlib>
30#include <cstdio>
31#include <cstdint>
32#include <string>
33#include <cstring>
34#include <vector>
35#include <csignal>
36#include <filesystem>
37#include <print>
38#include <queue>
39
40#include "sol/sol.hpp"
41#include "json.hpp"
43#include "l61/baseTypes.hpp"
45
46//Works on clang and GCC Though that's everybody important
47//But poor Microsoft the farthest from being standard
48//yet cannot even do simple gnu extensions
49//NOTE: Experimental use with caution
50/*#define l61_interface_cast(type, obj) \
51__extension__({ \
52static_assert(std::is_base_of_v<type, std::remove_pointer_t<decltype(obj)>>); \
53dynamic_cast<type*>(obj); \
54})*/
55
56#include <l61/meta.hpp>
57
58
59#define l61_interface_cast(type, obj) l61::dyn_cast<type, decltype(obj)>(obj)
60/*([]< \
61typename R = decltype(obj), \
62typename Rp = type, \
63typename T = std::conditional_t<std::is_pointer_v<R>, R, std::add_pointer_t<R>>, \
64typename Tx = std::conditional_t<std::is_pointer_v<Rp>, Rp, std::add_pointer_t<Rp>>>(T _obj) -> Tx { \
65 static_assert(std::is_base_of_v<std::remove_pointer_t<Tx>, std::remove_pointer_t<T>>, "l61_interface_cast type must be a base of the object's type"); \
66 return static_cast<Tx>(_obj); \
67})((obj))*/
68
69
70#define l61_no_copy(type) \
71type(const type&) = delete; \
72type(type&&) = delete/*; \
73type& operator=(const type&) = delete*/
74
75
76namespace l61
77{
78 template<class K, class V>
79 using HashMap = std::unordered_map<K, V>;
80
81 template<typename... T>
82 using AutoPointer = std::unique_ptr<T...>;
83}
84
85//End of abomination
86
87namespace fs = std::filesystem;
88
89using std::literals::operator ""s;
90
91namespace l61
92{
94 using flag_t = std::uint8_t;
96 enum class ScriptMode : std::uint8_t
97 {
101 };
103 __inline std::string scrModeToStr(ScriptMode script_mode)
104 {
105 switch (script_mode)
106 {
108 return "ScriptMode::ShellScriptMode"s;
110 return "ScriptMode::BuildScriptMode"s;
111 default:
112 return "ScriptMode::UndefMode"s;
113 }
114 }
115
117 __inline ScriptMode toScriptMode(const std::string& str)
118 {
119 if (str == "shell")
120 {
122 }
123 if (str == "build")
124 {
126 }
128 }
129
130
131 template<typename... vT>
132 [[__gnu__::__always_inline__]] __inline void cout_print(const vT&... vals)
133 {
134 (std::cout << ... << vals);
135 }
137 namespace ExtensionSystem
138 {
139 class ExtensionManager;
140 }
142 struct ConfigRecord final
144 std::vector<std::string> spaths; // Search path to be appended to built-in
145 std::vector<std::string> extension; // Native (*.lex61) Extensions to be autoloaded
147 };
157 };
159 struct l61_stat final
161 std::string work_path;
162 std::string make_file_path;
163 std::string bin_path;
164 std::string user_name;
165 std::string user_home;
166 std::vector<std::string> spaths;
167 const std::string version;
169 };
174 }
175}
176
177template <>
178struct std::formatter<l61::ScriptMode> : std::formatter<std::string> {
179 auto format(const l61::ScriptMode& mode, format_context& ctx) const
180 {
181 const std::string result = l61::scrModeToStr(mode);
182 return std::formatter<std::string>::format(result, ctx);
183 }
184};
185#endif //L61_DEFS_HPP
#define l61_abstract_class
Denotes that the class is abstract with most functions being implemented leaving a few functions to b...
Definition PseudoKeywords.hpp:63
This is an event bus leveraging l61::EventSystem::Event.
Definition EventBus.hpp:49
Definition ExtensionManager.hpp:31
Definition defs.hpp:137
Definition defs.hpp:171
l61_abstract_class AbstractScriptDebugger
Definition defs.hpp:172
Definition Object.hpp:34
__inline std::string scrModeToStr(ScriptMode script_mode)
Definition defs.hpp:102
__inline ScriptMode toScriptMode(const std::string &str)
Definition defs.hpp:116
ScriptMode
Definition defs.hpp:96
@ BuildScriptMode
Definition defs.hpp:99
@ UndefMode
Definition defs.hpp:97
@ ShellScriptMode
Definition defs.hpp:98
std::unique_ptr< T... > AutoPointer
Definition defs.hpp:81
__inline void cout_print(const vT &... vals)
Definition defs.hpp:131
std::unordered_map< K, V > HashMap
Definition defs.hpp:78
std::queue< c_signal_t > SignalQueue_t
Definition baseTypes.hpp:29
std::uint8_t flag_t
Definition defs.hpp:93
Definition defs.hpp:142
NLOHMANN_DEFINE_TYPE_INTRUSIVE(ConfigRecord, spaths, extension)
std::vector< std::string > spaths
Definition defs.hpp:143
std::vector< std::string > extension
Definition defs.hpp:144
Definition defs.hpp:149
flag_t verbose
Definition defs.hpp:153
ScriptMode runMode
Definition defs.hpp:150
EventSystem::EventBus eventBus
Definition defs.hpp:155
ConfigRecord config
Definition defs.hpp:152
SignalQueue_t signalQueue
Definition defs.hpp:154
std::unique_ptr< ExtensionSystem::ExtensionManager > extension_manager
Definition defs.hpp:151
Definition defs.hpp:159
ProgramStatus procStat
Definition defs.hpp:167
std::string user_home
Definition defs.hpp:164
std::string work_path
Definition defs.hpp:160
std::string make_file_path
Definition defs.hpp:161
const std::string version
Definition defs.hpp:166
std::string bin_path
Definition defs.hpp:162
std::vector< std::string > spaths
Definition defs.hpp:165
std::string user_name
Definition defs.hpp:163
auto format(const l61::ScriptMode &mode, format_context &ctx) const
Definition defs.hpp:178