IncludeCPP 3.4.2__py3-none-any.whl → 3.4.8__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.
@@ -346,6 +346,49 @@ class OpenQuote:
346
346
  return self._data
347
347
 
348
348
 
349
+ class Parameter:
350
+ """Parameter accessor for CSSL exec() arguments.
351
+
352
+ Provides access to arguments passed to CSSL.exec() via parameter.get(index).
353
+
354
+ Usage in CSSL:
355
+ parameter.get(0) # Get first argument
356
+ parameter.get(1) # Get second argument
357
+ parameter.count() # Get total argument count
358
+ parameter.all() # Get all arguments as list
359
+ """
360
+
361
+ def __init__(self, args: List[Any] = None):
362
+ self._args = args if args is not None else []
363
+
364
+ def get(self, index: int, default: Any = None) -> Any:
365
+ """Get argument at index, returns default if not found"""
366
+ if 0 <= index < len(self._args):
367
+ return self._args[index]
368
+ return default
369
+
370
+ def count(self) -> int:
371
+ """Return total number of arguments"""
372
+ return len(self._args)
373
+
374
+ def all(self) -> List[Any]:
375
+ """Return all arguments as a list"""
376
+ return list(self._args)
377
+
378
+ def has(self, index: int) -> bool:
379
+ """Check if argument exists at index"""
380
+ return 0 <= index < len(self._args)
381
+
382
+ def __iter__(self):
383
+ return iter(self._args)
384
+
385
+ def __len__(self):
386
+ return len(self._args)
387
+
388
+ def __getitem__(self, index: int) -> Any:
389
+ return self.get(index)
390
+
391
+
349
392
  def OpenFind(combo_or_type: Union[Combo, type], index: int = 0) -> Optional[Any]:
350
393
  """Find open parameter by type or combo space.
351
394
 
@@ -384,7 +427,12 @@ def create_openquote(db_ref: Any = None) -> OpenQuote:
384
427
 
385
428
  __all__ = [
386
429
  'DataStruct', 'Shuffled', 'Iterator', 'Combo', 'DataSpace', 'OpenQuote',
387
- 'OpenFind',
430
+ 'OpenFind', 'Parameter',
388
431
  'create_datastruct', 'create_shuffled', 'create_iterator',
389
- 'create_combo', 'create_dataspace', 'create_openquote'
432
+ 'create_combo', 'create_dataspace', 'create_openquote', 'create_parameter'
390
433
  ]
434
+
435
+
436
+ def create_parameter(args: List[Any] = None) -> Parameter:
437
+ """Create a Parameter object for accessing exec arguments"""
438
+ return Parameter(args)
@@ -5,7 +5,105 @@ Provides CsslLang class for executing CSSL code from Python.
5
5
 
6
6
  import threading
7
7
  from pathlib import Path
8
- from typing import Any, List, Optional, Callable
8
+ from typing import Any, List, Optional, Callable, Dict
9
+
10
+
11
+ class CSSLModule:
12
+ """
13
+ A callable CSSL module that executes code with arguments.
14
+
15
+ Created via CSSL.module() - the code is executed each time the module is called,
16
+ with arguments accessible via parameter.get(index).
17
+ """
18
+
19
+ def __init__(self, cssl_instance: 'CsslLang', code: str):
20
+ self._cssl = cssl_instance
21
+ self._code = code
22
+
23
+ def __call__(self, *args) -> Any:
24
+ """Execute the module code with the given arguments."""
25
+ return self._cssl.exec(self._code, *args)
26
+
27
+ def __repr__(self) -> str:
28
+ return f"<CSSLModule code_len={len(self._code)}>"
29
+
30
+
31
+ class CSSLFunctionModule:
32
+ """
33
+ A CSSL module with accessible functions as methods.
34
+
35
+ Created via CSSL.makemodule() - functions defined in the CSSL code
36
+ become callable attributes on this module.
37
+ """
38
+
39
+ def __init__(self, cssl_instance: 'CsslLang', code: str):
40
+ self._cssl = cssl_instance
41
+ self._code = code
42
+ self._runtime = None
43
+ self._functions: Dict[str, Any] = {}
44
+ self._initialized = False
45
+
46
+ def _ensure_initialized(self):
47
+ """Initialize the module by parsing and registering functions."""
48
+ if self._initialized:
49
+ return
50
+
51
+ from .cssl import CSSLRuntime, parse_cssl_program, ASTNode
52
+
53
+ # Create a dedicated runtime for this module
54
+ self._runtime = CSSLRuntime()
55
+
56
+ # Parse the code
57
+ ast = parse_cssl_program(self._code)
58
+
59
+ # Execute to register all function definitions
60
+ for child in ast.children:
61
+ if child.type == 'function':
62
+ func_info = child.value
63
+ func_name = func_info.get('name')
64
+ self._functions[func_name] = child
65
+ self._runtime.scope.set(func_name, child)
66
+ else:
67
+ # Execute other statements (like struct definitions)
68
+ try:
69
+ self._runtime._execute_node(child)
70
+ except Exception:
71
+ pass
72
+
73
+ self._initialized = True
74
+
75
+ def __getattr__(self, name: str) -> Callable:
76
+ """Get a function from the module."""
77
+ # Avoid recursion for internal attributes
78
+ if name.startswith('_'):
79
+ raise AttributeError(f"'{type(self).__name__}' has no attribute '{name}'")
80
+
81
+ self._ensure_initialized()
82
+
83
+ if name in self._functions:
84
+ func_node = self._functions[name]
85
+
86
+ def wrapper(*args):
87
+ from .cssl import Parameter
88
+ # Set up parameter object for this call
89
+ self._runtime.global_scope.set('parameter', Parameter(list(args)))
90
+ self._runtime.global_scope.set('args', list(args))
91
+ self._runtime.global_scope.set('argc', len(args))
92
+ return self._runtime._call_function(func_node, list(args))
93
+
94
+ return wrapper
95
+
96
+ raise AttributeError(f"CSSL module has no function '{name}'")
97
+
98
+ def __dir__(self) -> List[str]:
99
+ """List available functions."""
100
+ self._ensure_initialized()
101
+ return list(self._functions.keys())
102
+
103
+ def __repr__(self) -> str:
104
+ self._ensure_initialized()
105
+ funcs = ', '.join(self._functions.keys())
106
+ return f"<CSSLFunctionModule functions=[{funcs}]>"
9
107
 
10
108
 
11
109
  class CsslLang:
@@ -58,8 +156,10 @@ class CsslLang:
58
156
  source = path_or_code
59
157
 
60
158
  # Set arguments in runtime scope
159
+ from .cssl import Parameter
61
160
  runtime.global_scope.set('args', list(args))
62
161
  runtime.global_scope.set('argc', len(args))
162
+ runtime.global_scope.set('parameter', Parameter(list(args)))
63
163
 
64
164
  # Execute as standalone program
65
165
  try:
@@ -120,6 +220,53 @@ class CsslLang:
120
220
  runtime = self._get_runtime()
121
221
  return runtime.global_scope.get(name)
122
222
 
223
+ def module(self, code: str) -> 'CSSLModule':
224
+ """
225
+ Create a callable CSSL module from code.
226
+
227
+ The module can be called with arguments that are passed to the CSSL code.
228
+
229
+ Usage:
230
+ module = CSSL.module('''
231
+ printl(parameter.get(0));
232
+ ''')
233
+ module("Hello") # Prints "Hello"
234
+
235
+ Args:
236
+ code: CSSL code string
237
+
238
+ Returns:
239
+ CSSLModule - a callable module
240
+ """
241
+ return CSSLModule(self, code)
242
+
243
+ def makemodule(self, code: str) -> 'CSSLFunctionModule':
244
+ """
245
+ Create a CSSL module with accessible functions.
246
+
247
+ Functions defined in the code become methods on the returned module.
248
+
249
+ Usage:
250
+ module = CSSL.makemodule('''
251
+ string greet(string name) {
252
+ return "Hello, " + name + "!";
253
+ }
254
+
255
+ int add(int a, int b) {
256
+ return a + b;
257
+ }
258
+ ''')
259
+ module.greet("World") # Returns "Hello, World!"
260
+ module.add(2, 3) # Returns 5
261
+
262
+ Args:
263
+ code: CSSL code string with function definitions
264
+
265
+ Returns:
266
+ CSSLFunctionModule - module with callable function attributes
267
+ """
268
+ return CSSLFunctionModule(self, code)
269
+
123
270
 
124
271
  # Singleton for convenience
125
272
  _default_instance: Optional[CsslLang] = None
@@ -130,3 +277,133 @@ def get_cssl() -> CsslLang:
130
277
  if _default_instance is None:
131
278
  _default_instance = CsslLang()
132
279
  return _default_instance
280
+
281
+
282
+ # Module-level convenience functions
283
+ def exec(path_or_code: str, *args) -> Any:
284
+ """
285
+ Execute CSSL code or file.
286
+
287
+ Usage:
288
+ from includecpp import CSSL
289
+ CSSL.exec("script.cssl", arg1, arg2)
290
+ CSSL.exec("printl('Hello World');")
291
+
292
+ Args:
293
+ path_or_code: Path to .cssl file or CSSL code string
294
+ *args: Arguments to pass to the script
295
+
296
+ Returns:
297
+ Execution result
298
+ """
299
+ return get_cssl().exec(path_or_code, *args)
300
+
301
+
302
+ def T_exec(path_or_code: str, *args, callback: Optional[Callable[[Any], None]] = None) -> threading.Thread:
303
+ """
304
+ Execute CSSL code asynchronously in a thread.
305
+
306
+ Usage:
307
+ from includecpp import CSSL
308
+ CSSL.T_exec("async_script.cssl", arg1, callback=on_done)
309
+
310
+ Args:
311
+ path_or_code: Path to .cssl file or CSSL code string
312
+ *args: Arguments to pass to the script
313
+ callback: Optional callback when execution completes
314
+
315
+ Returns:
316
+ Thread object
317
+ """
318
+ return get_cssl().T_exec(path_or_code, *args, callback=callback)
319
+
320
+
321
+ def set_global(name: str, value: Any) -> None:
322
+ """Set a global variable in CSSL runtime."""
323
+ get_cssl().set_global(name, value)
324
+
325
+
326
+ def get_global(name: str) -> Any:
327
+ """Get a global variable from CSSL runtime."""
328
+ return get_cssl().get_global(name)
329
+
330
+
331
+ def get_output() -> List[str]:
332
+ """Get output buffer from last execution."""
333
+ return get_cssl().get_output()
334
+
335
+
336
+ def clear_output() -> None:
337
+ """Clear output buffer."""
338
+ get_cssl().clear_output()
339
+
340
+
341
+ # Aliases to avoid conflict with Python builtin exec
342
+ _exec = exec
343
+ _T_exec = T_exec
344
+
345
+
346
+ def module(code: str) -> CSSLModule:
347
+ """
348
+ Create a callable CSSL module from code.
349
+
350
+ Usage:
351
+ from includecpp import CSSL
352
+ greet = CSSL.module('''
353
+ printl("Hello, " + parameter.get(0) + "!");
354
+ ''')
355
+ greet("World") # Prints "Hello, World!"
356
+
357
+ Args:
358
+ code: CSSL code string
359
+
360
+ Returns:
361
+ CSSLModule - a callable module
362
+ """
363
+ return get_cssl().module(code)
364
+
365
+
366
+ def makemodule(code: str) -> CSSLFunctionModule:
367
+ """
368
+ Create a CSSL module with accessible functions.
369
+
370
+ Usage:
371
+ from includecpp import CSSL
372
+ math_mod = CSSL.makemodule('''
373
+ int add(int a, int b) {
374
+ return a + b;
375
+ }
376
+
377
+ int multiply(int a, int b) {
378
+ return a * b;
379
+ }
380
+ ''')
381
+ math_mod.add(2, 3) # Returns 5
382
+ math_mod.multiply(4, 5) # Returns 20
383
+
384
+ Args:
385
+ code: CSSL code string with function definitions
386
+
387
+ Returns:
388
+ CSSLFunctionModule - module with callable function attributes
389
+ """
390
+ return get_cssl().makemodule(code)
391
+
392
+
393
+ # Export all
394
+ __all__ = [
395
+ 'CsslLang',
396
+ 'CSSLModule',
397
+ 'CSSLFunctionModule',
398
+ 'get_cssl',
399
+ 'exec',
400
+ '_exec', # Alias for exec (avoids Python builtin conflict)
401
+ 'T_exec',
402
+ '_T_exec', # Alias for T_exec
403
+ 'set_global',
404
+ 'get_global',
405
+ 'get_output',
406
+ 'clear_output',
407
+ 'module',
408
+ 'makemodule',
409
+ ]
@@ -0,0 +1,311 @@
1
+ """
2
+ CSSL Bridge - Type Stubs for Python API
3
+ """
4
+
5
+ import threading
6
+ from typing import Any, List, Optional, Callable, Dict
7
+
8
+
9
+ class CSSLModule:
10
+ """
11
+ A callable CSSL module that executes code with arguments.
12
+
13
+ Created via CSSL.module() - the code is executed each time the module is called,
14
+ with arguments accessible via parameter.get(index).
15
+ """
16
+
17
+ def __init__(self, cssl_instance: 'CsslLang', code: str) -> None: ...
18
+ def __call__(self, *args: Any) -> Any:
19
+ """Execute the module code with the given arguments."""
20
+ ...
21
+ def __repr__(self) -> str: ...
22
+
23
+
24
+ class CSSLFunctionModule:
25
+ """
26
+ A CSSL module with accessible functions as methods.
27
+
28
+ Created via CSSL.makemodule() - functions defined in the CSSL code
29
+ become callable attributes on this module.
30
+ """
31
+
32
+ def __init__(self, cssl_instance: 'CsslLang', code: str) -> None: ...
33
+ def __getattr__(self, name: str) -> Callable[..., Any]:
34
+ """Get a function from the module."""
35
+ ...
36
+ def __dir__(self) -> List[str]:
37
+ """List available functions."""
38
+ ...
39
+ def __repr__(self) -> str: ...
40
+
41
+
42
+ class CsslLang:
43
+ """
44
+ CSSL Language interface for Python.
45
+
46
+ Usage:
47
+ from includecpp import CSSL
48
+ cssl = CSSL.CsslLang()
49
+ result = cssl.exec("script.cssl", arg1, arg2)
50
+ cssl.T_exec("async_script.cssl", arg1) # Threaded
51
+ """
52
+
53
+ def __init__(self, output_callback: Optional[Callable[[str, str], None]] = ...) -> None:
54
+ """
55
+ Initialize CSSL runtime.
56
+
57
+ Args:
58
+ output_callback: Optional callback for output (text, level)
59
+ """
60
+ ...
61
+
62
+ def exec(self, path_or_code: str, *args: Any) -> Any:
63
+ """
64
+ Execute CSSL code or file.
65
+
66
+ Args:
67
+ path_or_code: Path to .cssl file or CSSL code string
68
+ *args: Arguments to pass to the script
69
+
70
+ Returns:
71
+ Execution result
72
+ """
73
+ ...
74
+
75
+ def T_exec(
76
+ self,
77
+ path_or_code: str,
78
+ *args: Any,
79
+ callback: Optional[Callable[[Any], None]] = ...
80
+ ) -> threading.Thread:
81
+ """
82
+ Execute CSSL code asynchronously in a thread.
83
+
84
+ Args:
85
+ path_or_code: Path to .cssl file or CSSL code string
86
+ *args: Arguments to pass to the script
87
+ callback: Optional callback when execution completes
88
+
89
+ Returns:
90
+ Thread object
91
+ """
92
+ ...
93
+
94
+ def wait_all(self, timeout: Optional[float] = ...) -> None:
95
+ """Wait for all async executions to complete."""
96
+ ...
97
+
98
+ def get_output(self) -> List[str]:
99
+ """Get output buffer from last execution."""
100
+ ...
101
+
102
+ def clear_output(self) -> None:
103
+ """Clear output buffer."""
104
+ ...
105
+
106
+ def set_global(self, name: str, value: Any) -> None:
107
+ """Set a global variable in CSSL runtime."""
108
+ ...
109
+
110
+ def get_global(self, name: str) -> Any:
111
+ """Get a global variable from CSSL runtime."""
112
+ ...
113
+
114
+ def module(self, code: str) -> CSSLModule:
115
+ """
116
+ Create a callable CSSL module from code.
117
+
118
+ Usage:
119
+ module = cssl.module('''
120
+ printl(parameter.get(0));
121
+ ''')
122
+ module("Hello") # Prints "Hello"
123
+
124
+ Args:
125
+ code: CSSL code string
126
+
127
+ Returns:
128
+ CSSLModule - a callable module
129
+ """
130
+ ...
131
+
132
+ def makemodule(self, code: str) -> CSSLFunctionModule:
133
+ """
134
+ Create a CSSL module with accessible functions.
135
+
136
+ Usage:
137
+ module = cssl.makemodule('''
138
+ string greet(string name) {
139
+ return "Hello, " + name + "!";
140
+ }
141
+ ''')
142
+ module.greet("World") # Returns "Hello, World!"
143
+
144
+ Args:
145
+ code: CSSL code string with function definitions
146
+
147
+ Returns:
148
+ CSSLFunctionModule - module with callable function attributes
149
+ """
150
+ ...
151
+
152
+
153
+ def get_cssl() -> CsslLang:
154
+ """Get default CSSL instance."""
155
+ ...
156
+
157
+
158
+ def exec(path_or_code: str, *args: Any) -> Any:
159
+ """
160
+ Execute CSSL code or file.
161
+
162
+ Usage:
163
+ from includecpp import CSSL
164
+ CSSL.exec("script.cssl", arg1, arg2)
165
+ CSSL.exec("printl('Hello World');")
166
+
167
+ Args:
168
+ path_or_code: Path to .cssl file or CSSL code string
169
+ *args: Arguments to pass to the script
170
+
171
+ Returns:
172
+ Execution result
173
+ """
174
+ ...
175
+
176
+
177
+ def T_exec(
178
+ path_or_code: str,
179
+ *args: Any,
180
+ callback: Optional[Callable[[Any], None]] = ...
181
+ ) -> threading.Thread:
182
+ """
183
+ Execute CSSL code asynchronously in a thread.
184
+
185
+ Usage:
186
+ from includecpp import CSSL
187
+ CSSL.T_exec("async_script.cssl", arg1, callback=on_done)
188
+
189
+ Args:
190
+ path_or_code: Path to .cssl file or CSSL code string
191
+ *args: Arguments to pass to the script
192
+ callback: Optional callback when execution completes
193
+
194
+ Returns:
195
+ Thread object
196
+ """
197
+ ...
198
+
199
+
200
+ def set_global(name: str, value: Any) -> None:
201
+ """Set a global variable in CSSL runtime."""
202
+ ...
203
+
204
+
205
+ def get_global(name: str) -> Any:
206
+ """Get a global variable from CSSL runtime."""
207
+ ...
208
+
209
+
210
+ def get_output() -> List[str]:
211
+ """Get output buffer from last execution."""
212
+ ...
213
+
214
+
215
+ def clear_output() -> None:
216
+ """Clear output buffer."""
217
+ ...
218
+
219
+
220
+ # Aliases to avoid conflict with Python builtin exec
221
+ def _exec(code: str, *args: Any) -> Any:
222
+ """
223
+ Execute CSSL code directly (alias for exec).
224
+
225
+ Supports triple-quoted docstrings for inline CSSL code:
226
+
227
+ Usage:
228
+ from includecpp import CSSL
229
+ CSSL._exec('''
230
+ global base = include("abc.cssl-mod");
231
+
232
+ void TestFunc() {
233
+ printl("hey");
234
+ @base.RechneWas(4, 5);
235
+ }
236
+
237
+ TestFunc();
238
+ ''')
239
+
240
+ Args:
241
+ code: CSSL code string (supports triple-quoted docstrings)
242
+ *args: Arguments to pass to the script
243
+
244
+ Returns:
245
+ Execution result
246
+ """
247
+ ...
248
+
249
+
250
+ def _T_exec(
251
+ code: str,
252
+ *args: Any,
253
+ callback: Optional[Callable[[Any], None]] = ...
254
+ ) -> threading.Thread:
255
+ """
256
+ Execute CSSL code asynchronously in a thread (alias for T_exec).
257
+
258
+ Args:
259
+ code: CSSL code string
260
+ *args: Arguments to pass to the script
261
+ callback: Optional callback when execution completes
262
+
263
+ Returns:
264
+ Thread object
265
+ """
266
+ ...
267
+
268
+
269
+ def module(code: str) -> CSSLModule:
270
+ """
271
+ Create a callable CSSL module from code.
272
+
273
+ Usage:
274
+ from includecpp import CSSL
275
+ greet = CSSL.module('''
276
+ printl("Hello, " + parameter.get(0) + "!");
277
+ ''')
278
+ greet("World") # Prints "Hello, World!"
279
+
280
+ Args:
281
+ code: CSSL code string
282
+
283
+ Returns:
284
+ CSSLModule - a callable module
285
+ """
286
+ ...
287
+
288
+
289
+ def makemodule(code: str) -> CSSLFunctionModule:
290
+ """
291
+ Create a CSSL module with accessible functions.
292
+
293
+ Usage:
294
+ from includecpp import CSSL
295
+ math_mod = CSSL.makemodule('''
296
+ int add(int a, int b) {
297
+ return a + b;
298
+ }
299
+ ''')
300
+ math_mod.add(2, 3) # Returns 5
301
+
302
+ Args:
303
+ code: CSSL code string with function definitions
304
+
305
+ Returns:
306
+ CSSLFunctionModule - module with callable function attributes
307
+ """
308
+ ...
309
+
310
+
311
+ __all__: List[str]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: IncludeCPP
3
- Version: 3.4.2
3
+ Version: 3.4.8
4
4
  Summary: Professional C++ Python bindings with type-generic templates, pystubs and native threading
5
5
  Home-page: https://github.com/liliassg/IncludeCPP
6
6
  Author: Lilias Hatterscheidt