IncludeCPP 4.3.0__py3-none-any.whl → 4.6.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. includecpp/CHANGELOG.md +22 -0
  2. includecpp/__init__.py +1 -1
  3. includecpp/__init__.pyi +1 -4
  4. includecpp/cli/commands.py +1218 -25
  5. includecpp/core/cpp_api_extensions.pyi +204 -200
  6. includecpp/core/cssl/__init__.py +317 -0
  7. includecpp/core/cssl/cpp/build/api.pyd +0 -0
  8. includecpp/core/cssl/cpp/build/cssl_core.pyi +323 -0
  9. includecpp/core/cssl/cpp/build/libgcc_s_seh-1.dll +0 -0
  10. includecpp/core/cssl/cpp/build/libstdc++-6.dll +0 -0
  11. includecpp/core/cssl/cpp/build/libwinpthread-1.dll +0 -0
  12. includecpp/core/cssl/cpp/cssl_core.cp +108 -0
  13. includecpp/core/cssl/cpp/cssl_lexer.hpp +280 -0
  14. includecpp/core/cssl/cssl_builtins.py +142 -27
  15. includecpp/core/cssl/cssl_compiler.py +448 -0
  16. includecpp/core/cssl/cssl_optimizer.py +833 -0
  17. includecpp/core/cssl/cssl_parser.py +433 -38
  18. includecpp/core/cssl/cssl_runtime.py +294 -15
  19. includecpp/core/cssl/cssl_syntax.py +17 -0
  20. includecpp/core/cssl/cssl_types.py +143 -11
  21. includecpp/core/cssl_bridge.py +39 -2
  22. includecpp/generator/parser.cpp +38 -14
  23. includecpp/vscode/cssl/package.json +15 -0
  24. includecpp/vscode/cssl/syntaxes/cssl.tmLanguage.json +96 -0
  25. {includecpp-4.3.0.dist-info → includecpp-4.6.0.dist-info}/METADATA +1 -1
  26. {includecpp-4.3.0.dist-info → includecpp-4.6.0.dist-info}/RECORD +30 -21
  27. {includecpp-4.3.0.dist-info → includecpp-4.6.0.dist-info}/WHEEL +0 -0
  28. {includecpp-4.3.0.dist-info → includecpp-4.6.0.dist-info}/entry_points.txt +0 -0
  29. {includecpp-4.3.0.dist-info → includecpp-4.6.0.dist-info}/licenses/LICENSE +0 -0
  30. {includecpp-4.3.0.dist-info → includecpp-4.6.0.dist-info}/top_level.txt +0 -0
@@ -9,8 +9,275 @@ Features:
9
9
  - Advanced data types: datastruct, shuffled, iterator, combo, dataspace
10
10
  - Injection helpers: string::where, json::key, array::index, etc.
11
11
  - Global references: @Name, r@Name, s@Name
12
+
13
+ Performance:
14
+ - C++ acceleration via bundled cssl_core module (375x+ speedup)
15
+ - Pre-built binaries bundled in PyPI package for instant use
16
+ - Auto-rebuilds if bundled module doesn't match platform (once)
17
+ - Use is_cpp_available() to check if C++ module is loaded
12
18
  """
13
19
 
20
+ import os
21
+ import sys
22
+ import importlib.util
23
+ from pathlib import Path
24
+ from typing import Optional
25
+
26
+ # C++ acceleration state
27
+ _CPP_AVAILABLE = False
28
+ _cpp_module = None
29
+ _CPP_LOAD_SOURCE = None # 'bundled', 'rebuilt', None
30
+ _CPP_MODULE_PATH = None
31
+
32
+
33
+ def _load_module_from_path(path: Path) -> Optional[object]:
34
+ """
35
+ Load a Python extension module from file path.
36
+
37
+ IncludeCPP builds modules with 'api' as the export name, containing
38
+ submodules for each plugin. We load the 'api' module and return the
39
+ 'cssl_core' submodule.
40
+
41
+ Args:
42
+ path: Path to .pyd/.so module file
43
+
44
+ Returns:
45
+ Loaded cssl_core submodule, or None if loading failed
46
+ """
47
+ dll_handle = None
48
+ try:
49
+ # On Windows, add DLL directory to search path (for MinGW runtime DLLs)
50
+ if sys.platform == 'win32' and hasattr(os, 'add_dll_directory'):
51
+ dll_dir = path.parent
52
+ if dll_dir.exists():
53
+ dll_handle = os.add_dll_directory(str(dll_dir))
54
+
55
+ # IncludeCPP exports as 'api', with plugins as submodules
56
+ spec = importlib.util.spec_from_file_location('api', str(path))
57
+ if spec and spec.loader:
58
+ module = importlib.util.module_from_spec(spec)
59
+ spec.loader.exec_module(module)
60
+ # Return the cssl_core submodule
61
+ if hasattr(module, 'cssl_core'):
62
+ return module.cssl_core
63
+ return module
64
+ except Exception:
65
+ pass
66
+ finally:
67
+ # Clean up DLL directory handle
68
+ if dll_handle is not None:
69
+ try:
70
+ dll_handle.close()
71
+ except Exception:
72
+ pass
73
+ return None
74
+
75
+
76
+ def _try_load_bundled() -> bool:
77
+ """
78
+ Try to load bundled module from PyPI package directory.
79
+
80
+ CSSL bundles pre-built modules in includecpp/core/cssl/cpp/build/
81
+ so users get instant C++ acceleration without compiling.
82
+
83
+ Returns:
84
+ True if module loaded successfully
85
+ """
86
+ global _CPP_AVAILABLE, _cpp_module, _CPP_LOAD_SOURCE, _CPP_MODULE_PATH
87
+
88
+ try:
89
+ from .cssl_compiler import CSSLCompilerConfig, get_cssl_bundled_dir
90
+
91
+ config = CSSLCompilerConfig()
92
+ config.setup_first_run()
93
+
94
+ suffixes = config.get_all_possible_suffixes()
95
+ build_dir = get_cssl_bundled_dir()
96
+
97
+ if not build_dir.exists():
98
+ return False
99
+
100
+ # Check for cssl_core.{suffix}
101
+ for suffix in suffixes:
102
+ module_path = build_dir / f'cssl_core{suffix}'
103
+ if module_path.exists():
104
+ module = _load_module_from_path(module_path)
105
+ if module:
106
+ _cpp_module = module
107
+ _CPP_AVAILABLE = True
108
+ _CPP_LOAD_SOURCE = 'bundled'
109
+ _CPP_MODULE_PATH = str(module_path)
110
+ return True
111
+
112
+ # Check for api.pyd (IncludeCPP format)
113
+ api_path = build_dir / 'api.pyd'
114
+ if not api_path.exists():
115
+ api_path = build_dir / 'api.so'
116
+ if api_path.exists():
117
+ module = _load_module_from_path(api_path)
118
+ if module:
119
+ _cpp_module = module
120
+ _CPP_AVAILABLE = True
121
+ _CPP_LOAD_SOURCE = 'bundled'
122
+ _CPP_MODULE_PATH = str(api_path)
123
+ return True
124
+
125
+ except ImportError:
126
+ pass
127
+
128
+ return False
129
+
130
+
131
+ def _try_auto_rebuild() -> bool:
132
+ """
133
+ Auto-rebuild module if bundled version not available.
134
+
135
+ CSSL is special: if no bundled module matches the user's platform,
136
+ it automatically rebuilds ONCE to the bundled folder.
137
+
138
+ Returns:
139
+ True if rebuild succeeded and module loaded
140
+ """
141
+ global _CPP_AVAILABLE, _cpp_module, _CPP_LOAD_SOURCE, _CPP_MODULE_PATH
142
+
143
+ try:
144
+ from .cssl_compiler import compile_cssl_core, CSSLCompilerConfig
145
+
146
+ config = CSSLCompilerConfig()
147
+ if not config.can_compile():
148
+ return False
149
+
150
+ # Rebuild to bundled folder
151
+ module_path = compile_cssl_core(force=True)
152
+ if module_path and module_path.exists():
153
+ module = _load_module_from_path(module_path)
154
+ if module:
155
+ _cpp_module = module
156
+ _CPP_AVAILABLE = True
157
+ _CPP_LOAD_SOURCE = 'rebuilt'
158
+ _CPP_MODULE_PATH = str(module_path)
159
+ return True
160
+
161
+ except ImportError:
162
+ pass
163
+
164
+ return False
165
+
166
+
167
+ def _initialize_cpp_module():
168
+ """
169
+ Initialize C++ module for CSSL.
170
+
171
+ CSSL special handling:
172
+ 1. Try bundled module from PyPI package (instant use)
173
+ 2. If not found, auto-rebuild to bundled folder (once)
174
+ """
175
+ # Try bundled first (most users)
176
+ if _try_load_bundled():
177
+ return
178
+
179
+ # No bundled module - try auto-rebuild
180
+ _try_auto_rebuild()
181
+
182
+
183
+ # Initialize on import
184
+ _initialize_cpp_module()
185
+
186
+
187
+ # =============================================================================
188
+ # Public API
189
+ # =============================================================================
190
+
191
+ def is_cpp_available() -> bool:
192
+ """Check if C++ acceleration is available."""
193
+ return _CPP_AVAILABLE
194
+
195
+
196
+ def get_cpp_version() -> Optional[str]:
197
+ """Get C++ module version, or None if not available."""
198
+ if _CPP_AVAILABLE and _cpp_module and hasattr(_cpp_module, 'version'):
199
+ try:
200
+ return _cpp_module.version()
201
+ except Exception:
202
+ pass
203
+ return None
204
+
205
+
206
+ def get_cpp_platform() -> Optional[str]:
207
+ """Get the platform the C++ module was loaded for."""
208
+ return sys.platform if _CPP_AVAILABLE else None
209
+
210
+
211
+ def get_cpp_info() -> dict:
212
+ """
213
+ Get detailed C++ acceleration info.
214
+
215
+ Returns:
216
+ dict with keys:
217
+ - available: bool - whether C++ is available
218
+ - source: str - where module was loaded from ('bundled', 'rebuilt')
219
+ - version: str - module version
220
+ - module_path: str - path to loaded module
221
+ - platform: dict - platform info
222
+ - can_compile: bool - whether compilation is possible
223
+ """
224
+ result = {
225
+ 'available': _CPP_AVAILABLE,
226
+ 'source': _CPP_LOAD_SOURCE,
227
+ 'version': get_cpp_version(),
228
+ 'module_path': _CPP_MODULE_PATH,
229
+ }
230
+
231
+ try:
232
+ from .cssl_compiler import CSSLCompilerConfig
233
+ config = CSSLCompilerConfig()
234
+ result['platform'] = config.get_platform_info()
235
+ result['compiler'] = config.get_compiler()
236
+ result['can_compile'] = config.can_compile()
237
+ except ImportError:
238
+ result['platform'] = {'platform': sys.platform}
239
+ result['compiler'] = None
240
+ result['can_compile'] = False
241
+
242
+ return result
243
+
244
+
245
+ def compile_cpp_module(force: bool = False) -> bool:
246
+ """
247
+ Manually trigger C++ module compilation.
248
+
249
+ Compiles to the bundled folder so it's available for future imports.
250
+
251
+ Args:
252
+ force: If True, recompile even if module exists
253
+
254
+ Returns:
255
+ True if compilation succeeded
256
+ """
257
+ global _CPP_AVAILABLE, _cpp_module, _CPP_LOAD_SOURCE, _CPP_MODULE_PATH
258
+
259
+ try:
260
+ from .cssl_compiler import compile_cssl_core
261
+
262
+ module_path = compile_cssl_core(force=force)
263
+ if module_path and module_path.exists():
264
+ module = _load_module_from_path(module_path)
265
+ if module:
266
+ _cpp_module = module
267
+ _CPP_AVAILABLE = True
268
+ _CPP_LOAD_SOURCE = 'rebuilt'
269
+ _CPP_MODULE_PATH = str(module_path)
270
+ return True
271
+ except ImportError:
272
+ pass
273
+
274
+ return False
275
+
276
+
277
+ # =============================================================================
278
+ # Import CSSL modules
279
+ # =============================================================================
280
+
14
281
  from .cssl_parser import (
15
282
  parse_cssl, parse_cssl_program, tokenize_cssl,
16
283
  CSSLSyntaxError, CSSLLexer, CSSLParser, ASTNode,
@@ -28,7 +295,57 @@ from .cssl_types import (
28
295
  create_stack, create_vector, create_array
29
296
  )
30
297
 
298
+
299
+ # =============================================================================
300
+ # Fast tokenize with C++ acceleration
301
+ # =============================================================================
302
+
303
+ def fast_tokenize(source: str):
304
+ """
305
+ Tokenize CSSL source code.
306
+
307
+ Uses C++ Lexer if available (10-20x faster), otherwise Python.
308
+
309
+ Args:
310
+ source: CSSL source code string
311
+
312
+ Returns:
313
+ List of tokens
314
+ """
315
+ if _CPP_AVAILABLE and _cpp_module and hasattr(_cpp_module, 'Lexer'):
316
+ try:
317
+ lexer = _cpp_module.Lexer(source)
318
+ return lexer.tokenize()
319
+ except Exception:
320
+ pass
321
+ return tokenize_cssl(source)
322
+
323
+
324
+ # =============================================================================
325
+ # Optimizer - Smart Performance System
326
+ # =============================================================================
327
+
328
+ from .cssl_optimizer import (
329
+ run_optimized, get_optimizer_stats, configure_optimizer, clear_cache,
330
+ get_optimized_ops, precompile, PrecompiledPattern,
331
+ OptimizedOperations, OptimizedRuntime, ASTCache,
332
+ ExecutionContext, PerformanceThresholds, THRESHOLDS, OPS
333
+ )
334
+
335
+
336
+ # =============================================================================
337
+ # Exports
338
+ # =============================================================================
339
+
31
340
  __all__ = [
341
+ # C++ Acceleration
342
+ 'is_cpp_available', 'get_cpp_version', 'get_cpp_platform', 'get_cpp_info',
343
+ 'fast_tokenize', 'compile_cpp_module',
344
+ # Optimizer (NEW)
345
+ 'run_optimized', 'get_optimizer_stats', 'configure_optimizer', 'clear_cache',
346
+ 'get_optimized_ops', 'precompile', 'PrecompiledPattern',
347
+ 'OptimizedOperations', 'OptimizedRuntime', 'ASTCache',
348
+ 'ExecutionContext', 'PerformanceThresholds', 'THRESHOLDS', 'OPS',
32
349
  # Parser
33
350
  'parse_cssl', 'parse_cssl_program', 'tokenize_cssl',
34
351
  'CSSLSyntaxError', 'CSSLLexer', 'CSSLParser', 'ASTNode',
Binary file
@@ -0,0 +1,323 @@
1
+ """Type stubs for cssl_core C++ module.
2
+
3
+ Auto-generated by IncludeCPP - DO NOT EDIT.
4
+ Provides VSCode/PyCharm autocomplete for C++ bindings.
5
+ """
6
+
7
+ from typing import Any, List, Dict, Optional, Union, overload
8
+
9
+ class Lexer:
10
+ """C++ class: Lexer"""
11
+
12
+ def __init__(self, arg0: str) -> None:
13
+ """Initialize Lexer instance."""
14
+ ...
15
+
16
+ def tokenize(self) -> Any:
17
+ """C++ method: tokenize"""
18
+ ...
19
+
20
+
21
+ class Token:
22
+ """C++ class: Token"""
23
+
24
+ @overload
25
+ def __init__(self) -> None: ...
26
+ @overload
27
+ def __init__(self, arg0: int, arg1: int, arg2: int) -> None: ...
28
+ @overload
29
+ def __init__(self, arg0: int, arg1: str, arg2: int, arg3: int) -> None: ...
30
+ @overload
31
+ def __init__(self, arg0: int, arg1: float, arg2: int, arg3: int) -> None: ...
32
+ @overload
33
+ def __init__(self, arg0: int, arg1: bool, arg2: int, arg3: int) -> None: ...
34
+
35
+ def __init__(self, *args: Any, **kwargs: Any) -> None:
36
+ """Initialize Token instance."""
37
+ ...
38
+
39
+ pass
40
+
41
+ class Interpreter:
42
+ """C++ class: Interpreter"""
43
+
44
+ def __init__(self) -> None:
45
+ """Initialize Interpreter instance."""
46
+ ...
47
+
48
+ def run(self) -> Any:
49
+ """C++ method: run"""
50
+ ...
51
+
52
+ def run_string(self) -> Any:
53
+ """C++ method: run_string"""
54
+ ...
55
+
56
+
57
+ class Value:
58
+ """C++ class: Value"""
59
+
60
+ @overload
61
+ def __init__(self) -> None: ...
62
+ @overload
63
+ def __init__(self, arg0: bool) -> None: ...
64
+ @overload
65
+ def __init__(self, arg0: Any) -> None: ...
66
+ @overload
67
+ def __init__(self, arg0: float) -> None: ...
68
+ @overload
69
+ def __init__(self, arg0: str) -> None: ...
70
+
71
+ def __init__(self, *args: Any, **kwargs: Any) -> None:
72
+ """Initialize Value instance."""
73
+ ...
74
+
75
+ def as_bool(self) -> Any:
76
+ """C++ method: as_bool"""
77
+ ...
78
+
79
+ def as_float(self) -> Any:
80
+ """C++ method: as_float"""
81
+ ...
82
+
83
+ def as_int(self) -> Any:
84
+ """C++ method: as_int"""
85
+ ...
86
+
87
+ def as_string(self) -> Any:
88
+ """C++ method: as_string"""
89
+ ...
90
+
91
+ def get_type(self) -> Any:
92
+ """C++ method: get_type"""
93
+ ...
94
+
95
+ def is_bool(self) -> Any:
96
+ """C++ method: is_bool"""
97
+ ...
98
+
99
+ def is_dict(self) -> Any:
100
+ """C++ method: is_dict"""
101
+ ...
102
+
103
+ def is_float(self) -> Any:
104
+ """C++ method: is_float"""
105
+ ...
106
+
107
+ def is_int(self) -> Any:
108
+ """C++ method: is_int"""
109
+ ...
110
+
111
+ def is_list(self) -> Any:
112
+ """C++ method: is_list"""
113
+ ...
114
+
115
+ def is_null(self) -> Any:
116
+ """C++ method: is_null"""
117
+ ...
118
+
119
+ def is_number(self) -> Any:
120
+ """C++ method: is_number"""
121
+ ...
122
+
123
+ def is_string(self) -> Any:
124
+ """C++ method: is_string"""
125
+ ...
126
+
127
+ def is_set(self) -> Any:
128
+ """C++ method: is_set"""
129
+ ...
130
+
131
+ def is_stack(self) -> Any:
132
+ """C++ method: is_stack"""
133
+ ...
134
+
135
+ def is_container(self) -> Any:
136
+ """C++ method: is_container"""
137
+ ...
138
+
139
+ def to_bool(self) -> Any:
140
+ """C++ method: to_bool"""
141
+ ...
142
+
143
+ def to_string(self) -> Any:
144
+ """C++ method: to_string"""
145
+ ...
146
+
147
+ def size(self) -> Any:
148
+ """C++ method: size"""
149
+ ...
150
+
151
+ def contains(self) -> Any:
152
+ """C++ method: contains"""
153
+ ...
154
+
155
+
156
+ def run_cssl(source: str) -> str:
157
+ """C++ function: run_cssl"""
158
+ ...
159
+
160
+ def version(*args: Any, **kwargs: Any) -> str:
161
+ """C++ function: version"""
162
+ ...
163
+
164
+ def is_keyword(word: str) -> bool:
165
+ """C++ function: is_keyword"""
166
+ ...
167
+
168
+ def str_concat(a: str, b: str) -> str:
169
+ """C++ function: str_concat"""
170
+ ...
171
+
172
+ def str_contains(s: str, sub: str) -> bool:
173
+ """C++ function: str_contains"""
174
+ ...
175
+
176
+ def str_join(parts: List[str], delim: str) -> str:
177
+ """C++ function: str_join"""
178
+ ...
179
+
180
+ def str_lower(s: str) -> str:
181
+ """C++ function: str_lower"""
182
+ ...
183
+
184
+ def str_replace(s: str, from: str, to: str) -> str:
185
+ """C++ function: str_replace"""
186
+ ...
187
+
188
+ def str_split(s: str, delim: str) -> List[str]:
189
+ """C++ function: str_split"""
190
+ ...
191
+
192
+ def str_trim(s: str) -> str:
193
+ """C++ function: str_trim"""
194
+ ...
195
+
196
+ def str_upper(s: str) -> str:
197
+ """C++ function: str_upper"""
198
+ ...
199
+
200
+ def str_reverse(s: str) -> str:
201
+ """C++ function: str_reverse"""
202
+ ...
203
+
204
+ def str_len(s: str) -> Any:
205
+ """C++ function: str_len"""
206
+ ...
207
+
208
+ def str_repeat(s: str, count: Any) -> str:
209
+ """C++ function: str_repeat"""
210
+ ...
211
+
212
+ def str_startswith(s: str, prefix: str) -> bool:
213
+ """C++ function: str_startswith"""
214
+ ...
215
+
216
+ def str_endswith(s: str, suffix: str) -> bool:
217
+ """C++ function: str_endswith"""
218
+ ...
219
+
220
+ def str_indexof(s: str, sub: str) -> Any:
221
+ """C++ function: str_indexof"""
222
+ ...
223
+
224
+ def str_substr(s: str, start: Any, length: Any = -1) -> str:
225
+ """C++ function: str_substr"""
226
+ ...
227
+
228
+ def str_cmp(a: str, b: str) -> int:
229
+ """C++ function: str_cmp"""
230
+ ...
231
+
232
+ def math_clamp(value: float, min_val: float, max_val: float) -> float:
233
+ """C++ function: math_clamp"""
234
+ ...
235
+
236
+ def math_ipow(base: Any, exp: Any) -> Any:
237
+ """C++ function: math_ipow"""
238
+ ...
239
+
240
+ def math_pow(base: float, exp: float) -> float:
241
+ """C++ function: math_pow"""
242
+ ...
243
+
244
+ def math_mod(a: Any, b: Any) -> Any:
245
+ """C++ function: math_mod"""
246
+ ...
247
+
248
+ def math_abs(x: float) -> float:
249
+ """C++ function: math_abs"""
250
+ ...
251
+
252
+ def math_min(a: float, b: float) -> float:
253
+ """C++ function: math_min"""
254
+ ...
255
+
256
+ def math_max(a: float, b: float) -> float:
257
+ """C++ function: math_max"""
258
+ ...
259
+
260
+ def math_floor(x: float) -> Any:
261
+ """C++ function: math_floor"""
262
+ ...
263
+
264
+ def math_ceil(x: float) -> Any:
265
+ """C++ function: math_ceil"""
266
+ ...
267
+
268
+ def array_sum(arr: List[float]) -> float:
269
+ """C++ function: array_sum"""
270
+ ...
271
+
272
+ def array_isum(arr: List[Any]) -> Any:
273
+ """C++ function: array_isum"""
274
+ ...
275
+
276
+ def array_avg(arr: List[float]) -> float:
277
+ """C++ function: array_avg"""
278
+ ...
279
+
280
+ def array_min(arr: List[float]) -> float:
281
+ """C++ function: array_min"""
282
+ ...
283
+
284
+ def array_max(arr: List[float]) -> float:
285
+ """C++ function: array_max"""
286
+ ...
287
+
288
+ def range(start: Any, end: Any, step: Any = 1) -> List[Any]:
289
+ """C++ function: range"""
290
+ ...
291
+
292
+ def loop_check_lt(i: Any, end: Any) -> bool:
293
+ """C++ function: loop_check_lt"""
294
+ ...
295
+
296
+ def loop_check_le(i: Any, end: Any) -> bool:
297
+ """C++ function: loop_check_le"""
298
+ ...
299
+
300
+ def loop_check_gt(i: Any, end: Any) -> bool:
301
+ """C++ function: loop_check_gt"""
302
+ ...
303
+
304
+ def loop_check_ge(i: Any, end: Any) -> bool:
305
+ """C++ function: loop_check_ge"""
306
+ ...
307
+
308
+ def num_cmp(a: float, b: float) -> int:
309
+ """C++ function: num_cmp"""
310
+ ...
311
+
312
+ def eq_int(a: Any, b: Any) -> bool:
313
+ """C++ function: eq_int"""
314
+ ...
315
+
316
+ def eq_float(a: float, b: float) -> bool:
317
+ """C++ function: eq_float"""
318
+ ...
319
+
320
+ def eq_str(a: str, b: str) -> bool:
321
+ """C++ function: eq_str"""
322
+ ...
323
+