IncludeCPP 4.0.2__py3-none-any.whl → 4.3.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.
- includecpp/CHANGELOG.md +142 -0
- includecpp/DOCUMENTATION.md +446 -0
- includecpp/__init__.py +1 -1
- includecpp/__init__.pyi +4 -1
- includecpp/cli/commands.py +700 -86
- includecpp/core/ai_integration.py +46 -13
- includecpp/core/cpp_api_extensions.pyi +350 -0
- includecpp/core/cssl/CSSL_DOCUMENTATION.md +1535 -1316
- includecpp/core/cssl/cssl_builtins.py +230 -23
- includecpp/core/cssl/cssl_languages.py +1757 -0
- includecpp/core/cssl/cssl_parser.py +967 -126
- includecpp/core/cssl/cssl_runtime.py +1133 -84
- includecpp/core/cssl/cssl_syntax.py +88 -4
- includecpp/core/cssl/cssl_types.py +361 -1
- includecpp/core/cssl_bridge.py +194 -8
- includecpp/core/cssl_bridge.pyi +148 -10
- includecpp/generator/parser.cpp +121 -4
- includecpp/generator/parser.h +6 -0
- includecpp/vscode/cssl/package.json +43 -1
- includecpp/vscode/cssl/syntaxes/cssl.tmLanguage.json +178 -19
- includecpp-4.3.0.dist-info/METADATA +277 -0
- {includecpp-4.0.2.dist-info → includecpp-4.3.0.dist-info}/RECORD +26 -22
- includecpp-4.0.2.dist-info/METADATA +0 -908
- {includecpp-4.0.2.dist-info → includecpp-4.3.0.dist-info}/WHEEL +0 -0
- {includecpp-4.0.2.dist-info → includecpp-4.3.0.dist-info}/entry_points.txt +0 -0
- {includecpp-4.0.2.dist-info → includecpp-4.3.0.dist-info}/licenses/LICENSE +0 -0
- {includecpp-4.0.2.dist-info → includecpp-4.3.0.dist-info}/top_level.txt +0 -0
includecpp/core/cssl_bridge.py
CHANGED
|
@@ -266,8 +266,8 @@ class CSSLFunctionModule:
|
|
|
266
266
|
|
|
267
267
|
from .cssl import CSSLRuntime, parse_cssl_program, ASTNode
|
|
268
268
|
|
|
269
|
-
# Create a dedicated runtime for this module
|
|
270
|
-
self._runtime = CSSLRuntime()
|
|
269
|
+
# Create a dedicated runtime for this module, preserving output_callback
|
|
270
|
+
self._runtime = CSSLRuntime(output_callback=self._cssl._output_callback)
|
|
271
271
|
|
|
272
272
|
# If we have a payload, load it first (defines functions/globals for main)
|
|
273
273
|
if self._payload_code:
|
|
@@ -330,7 +330,12 @@ class CSSLFunctionModule:
|
|
|
330
330
|
self._runtime.global_scope.set('parameter', Parameter(list(args)))
|
|
331
331
|
self._runtime.global_scope.set('args', list(args))
|
|
332
332
|
self._runtime.global_scope.set('argc', len(args))
|
|
333
|
-
|
|
333
|
+
# Enable running flag for function execution
|
|
334
|
+
self._runtime._running = True
|
|
335
|
+
try:
|
|
336
|
+
return self._runtime._call_function(func_node, list(args))
|
|
337
|
+
finally:
|
|
338
|
+
self._runtime._running = False
|
|
334
339
|
|
|
335
340
|
return wrapper
|
|
336
341
|
|
|
@@ -603,7 +608,8 @@ class CsslLang:
|
|
|
603
608
|
self,
|
|
604
609
|
main_script: Union[str, 'CSSLScript'],
|
|
605
610
|
payload_script: Union[str, 'CSSLScript', None] = None,
|
|
606
|
-
name: str = None
|
|
611
|
+
name: str = None,
|
|
612
|
+
bind: str = None
|
|
607
613
|
) -> 'CSSLFunctionModule':
|
|
608
614
|
"""
|
|
609
615
|
Create a CSSL module with accessible functions.
|
|
@@ -612,13 +618,22 @@ class CsslLang:
|
|
|
612
618
|
Optionally registers the module for payload() access in other scripts.
|
|
613
619
|
|
|
614
620
|
Args:
|
|
615
|
-
main_script: Main CSSL code
|
|
621
|
+
main_script: Main CSSL code, file path, or CSSLScript
|
|
616
622
|
payload_script: Optional payload code (string or CSSLScript)
|
|
617
623
|
name: Optional name to register for payload(name) access
|
|
624
|
+
bind: Optional payload name to auto-prepend (from makepayload)
|
|
618
625
|
|
|
619
626
|
Returns:
|
|
620
627
|
CSSLFunctionModule - module with callable function attributes
|
|
621
628
|
|
|
629
|
+
Usage (simplified - with file path and bind):
|
|
630
|
+
# First register the payload
|
|
631
|
+
cssl.makepayload("api", "lib/api/einkaufsmanager.cssl-pl")
|
|
632
|
+
|
|
633
|
+
# Then create module from file, binding to payload
|
|
634
|
+
mod = cssl.makemodule("writer", "lib/writer.cssl", bind="api")
|
|
635
|
+
mod.SaySomething("Hello!") # Functions are now accessible
|
|
636
|
+
|
|
622
637
|
Usage (v3.8.0 - with CSSLScript objects):
|
|
623
638
|
main = cssl.script("cssl", '''
|
|
624
639
|
printl("Main");
|
|
@@ -644,6 +659,28 @@ class CsslLang:
|
|
|
644
659
|
''')
|
|
645
660
|
module.greet("World") # Returns "Hello, World!"
|
|
646
661
|
"""
|
|
662
|
+
# Handle simplified API: makemodule(name, path, bind=...)
|
|
663
|
+
# Check if main_script looks like a short identifier and payload_script looks like a path
|
|
664
|
+
if (isinstance(main_script, str) and isinstance(payload_script, str) and
|
|
665
|
+
not '\n' in main_script and not ';' in main_script and not '{' in main_script):
|
|
666
|
+
# main_script is likely a name, payload_script is likely a path
|
|
667
|
+
module_name = main_script
|
|
668
|
+
path = payload_script
|
|
669
|
+
|
|
670
|
+
# Check if it's actually a file path
|
|
671
|
+
path_obj = Path(path)
|
|
672
|
+
if path_obj.exists():
|
|
673
|
+
main_code = path_obj.read_text(encoding='utf-8')
|
|
674
|
+
|
|
675
|
+
# If bind is specified, prepend that payload's code
|
|
676
|
+
payload_code = None
|
|
677
|
+
if bind:
|
|
678
|
+
runtime = self._get_runtime()
|
|
679
|
+
if hasattr(runtime, '_inline_payloads') and bind in runtime._inline_payloads:
|
|
680
|
+
payload_code = runtime._inline_payloads[bind]
|
|
681
|
+
|
|
682
|
+
return CSSLFunctionModule(self, main_code, payload_code, module_name)
|
|
683
|
+
|
|
647
684
|
# Extract code from CSSLScript objects if provided
|
|
648
685
|
if isinstance(main_script, CSSLScript):
|
|
649
686
|
main_code = main_script.code
|
|
@@ -657,6 +694,12 @@ class CsslLang:
|
|
|
657
694
|
else:
|
|
658
695
|
payload_code = payload_script
|
|
659
696
|
|
|
697
|
+
# If bind is specified and no payload_script, use the bound payload
|
|
698
|
+
if bind and payload_code is None:
|
|
699
|
+
runtime = self._get_runtime()
|
|
700
|
+
if hasattr(runtime, '_inline_payloads') and bind in runtime._inline_payloads:
|
|
701
|
+
payload_code = runtime._inline_payloads[bind]
|
|
702
|
+
|
|
660
703
|
return CSSLFunctionModule(self, main_code, payload_code, name)
|
|
661
704
|
|
|
662
705
|
def load(self, path: str, name: str) -> None:
|
|
@@ -781,6 +824,45 @@ class CsslLang:
|
|
|
781
824
|
runtime._inline_payloads = {}
|
|
782
825
|
runtime._inline_payloads[name] = code
|
|
783
826
|
|
|
827
|
+
def makepayload(self, name: str, path: str) -> str:
|
|
828
|
+
"""
|
|
829
|
+
Register a payload from a file path.
|
|
830
|
+
|
|
831
|
+
Reads the file and registers it as a payload accessible via payload(name) in CSSL.
|
|
832
|
+
This is a convenience method that combines reading a file and calling code().
|
|
833
|
+
|
|
834
|
+
Usage:
|
|
835
|
+
from includecpp import CSSL
|
|
836
|
+
cssl = CSSL.CsslLang()
|
|
837
|
+
|
|
838
|
+
# Register a payload from file
|
|
839
|
+
cssl.makepayload("api", "lib/api/myapi.cssl-pl")
|
|
840
|
+
|
|
841
|
+
# Now use in CSSL code
|
|
842
|
+
cssl.run('''
|
|
843
|
+
payload("api"); // Load the payload
|
|
844
|
+
myApiFunction(); // Call functions from it
|
|
845
|
+
''')
|
|
846
|
+
|
|
847
|
+
# Or use with makemodule for automatic binding
|
|
848
|
+
mod = cssl.makemodule("writer", "lib/writer.cssl", bind="api")
|
|
849
|
+
mod.SaySomething("Hello!")
|
|
850
|
+
|
|
851
|
+
Args:
|
|
852
|
+
name: Name to register the payload under (used in payload(name) and bind=name)
|
|
853
|
+
path: Path to the .cssl-pl or .cssl file
|
|
854
|
+
|
|
855
|
+
Returns:
|
|
856
|
+
The payload code that was registered
|
|
857
|
+
"""
|
|
858
|
+
path_obj = Path(path)
|
|
859
|
+
if not path_obj.exists():
|
|
860
|
+
raise FileNotFoundError(f"Payload file not found: {path}")
|
|
861
|
+
|
|
862
|
+
code = path_obj.read_text(encoding='utf-8')
|
|
863
|
+
self.code(name, code)
|
|
864
|
+
return code
|
|
865
|
+
|
|
784
866
|
def share(self, instance: Any, name: str = None) -> str:
|
|
785
867
|
"""
|
|
786
868
|
Share a Python object instance with CSSL scripts (LIVE sharing).
|
|
@@ -979,6 +1061,73 @@ class CsslLang:
|
|
|
979
1061
|
"""
|
|
980
1062
|
return self.get_shared(name)
|
|
981
1063
|
|
|
1064
|
+
def getInstance(self, name: str) -> Optional[Any]:
|
|
1065
|
+
"""
|
|
1066
|
+
Get a universal instance by name (for Python-side access).
|
|
1067
|
+
|
|
1068
|
+
Universal instances are shared containers accessible from CSSL, Python, and C++.
|
|
1069
|
+
They support dynamic member/method access and are mutable across all contexts.
|
|
1070
|
+
|
|
1071
|
+
Usage:
|
|
1072
|
+
from includecpp import CSSL
|
|
1073
|
+
cssl = CSSL.CsslLang()
|
|
1074
|
+
|
|
1075
|
+
# In CSSL: instance<"myContainer"> container;
|
|
1076
|
+
# Then in Python:
|
|
1077
|
+
container = cssl.getInstance("myContainer")
|
|
1078
|
+
container.member = "value"
|
|
1079
|
+
print(container.member) # value
|
|
1080
|
+
|
|
1081
|
+
Args:
|
|
1082
|
+
name: Name of the instance (without quotes)
|
|
1083
|
+
|
|
1084
|
+
Returns:
|
|
1085
|
+
The UniversalInstance or None if not found
|
|
1086
|
+
"""
|
|
1087
|
+
from .cssl.cssl_types import UniversalInstance
|
|
1088
|
+
return UniversalInstance.get(name)
|
|
1089
|
+
|
|
1090
|
+
def createInstance(self, name: str) -> Any:
|
|
1091
|
+
"""
|
|
1092
|
+
Create or get a universal instance by name (for Python-side creation).
|
|
1093
|
+
|
|
1094
|
+
Usage:
|
|
1095
|
+
container = cssl.createInstance("myContainer")
|
|
1096
|
+
container.data = {"key": "value"}
|
|
1097
|
+
# Now accessible in CSSL via instance<"myContainer">
|
|
1098
|
+
|
|
1099
|
+
Args:
|
|
1100
|
+
name: Name for the instance
|
|
1101
|
+
|
|
1102
|
+
Returns:
|
|
1103
|
+
The UniversalInstance (new or existing)
|
|
1104
|
+
"""
|
|
1105
|
+
from .cssl.cssl_types import UniversalInstance
|
|
1106
|
+
return UniversalInstance.get_or_create(name)
|
|
1107
|
+
|
|
1108
|
+
def deleteInstance(self, name: str) -> bool:
|
|
1109
|
+
"""
|
|
1110
|
+
Delete a universal instance by name.
|
|
1111
|
+
|
|
1112
|
+
Args:
|
|
1113
|
+
name: Name of the instance to delete
|
|
1114
|
+
|
|
1115
|
+
Returns:
|
|
1116
|
+
True if deleted, False if not found
|
|
1117
|
+
"""
|
|
1118
|
+
from .cssl.cssl_types import UniversalInstance
|
|
1119
|
+
return UniversalInstance.delete(name)
|
|
1120
|
+
|
|
1121
|
+
def listInstances(self) -> list:
|
|
1122
|
+
"""
|
|
1123
|
+
List all universal instance names.
|
|
1124
|
+
|
|
1125
|
+
Returns:
|
|
1126
|
+
List of instance names
|
|
1127
|
+
"""
|
|
1128
|
+
from .cssl.cssl_types import UniversalInstance
|
|
1129
|
+
return UniversalInstance.list_all()
|
|
1130
|
+
|
|
982
1131
|
|
|
983
1132
|
# Global shared objects registry (for cross-instance sharing)
|
|
984
1133
|
_global_shared_objects: Dict[str, str] = {}
|
|
@@ -1303,14 +1452,49 @@ def module(code: str) -> CSSLModule:
|
|
|
1303
1452
|
return get_cssl().module(code)
|
|
1304
1453
|
|
|
1305
1454
|
|
|
1455
|
+
def makepayload(name: str, path: str) -> str:
|
|
1456
|
+
"""
|
|
1457
|
+
Register a payload from a file path.
|
|
1458
|
+
|
|
1459
|
+
Reads the file and registers it as a payload accessible via payload(name) in CSSL.
|
|
1460
|
+
|
|
1461
|
+
Usage:
|
|
1462
|
+
from includecpp import CSSL
|
|
1463
|
+
|
|
1464
|
+
# Register a payload from file
|
|
1465
|
+
CSSL.makepayload("api", "lib/api/myapi.cssl-pl")
|
|
1466
|
+
|
|
1467
|
+
# Use with makemodule for automatic binding
|
|
1468
|
+
mod = CSSL.makemodule("writer", "lib/writer.cssl", bind="api")
|
|
1469
|
+
mod.SaySomething("Hello!")
|
|
1470
|
+
|
|
1471
|
+
Args:
|
|
1472
|
+
name: Name to register the payload under (used in payload(name) and bind=name)
|
|
1473
|
+
path: Path to the .cssl-pl or .cssl file
|
|
1474
|
+
|
|
1475
|
+
Returns:
|
|
1476
|
+
The payload code that was registered
|
|
1477
|
+
"""
|
|
1478
|
+
return get_cssl().makepayload(name, path)
|
|
1479
|
+
|
|
1480
|
+
|
|
1306
1481
|
def makemodule(
|
|
1307
1482
|
main_script: Union[str, CSSLScript],
|
|
1308
1483
|
payload_script: Union[str, CSSLScript, None] = None,
|
|
1309
|
-
name: str = None
|
|
1484
|
+
name: str = None,
|
|
1485
|
+
bind: str = None
|
|
1310
1486
|
) -> CSSLFunctionModule:
|
|
1311
1487
|
"""
|
|
1312
1488
|
Create a CSSL module with accessible functions.
|
|
1313
1489
|
|
|
1490
|
+
Usage (simplified - with file path and bind):
|
|
1491
|
+
# First register the payload
|
|
1492
|
+
CSSL.makepayload("api", "lib/api/einkaufsmanager.cssl-pl")
|
|
1493
|
+
|
|
1494
|
+
# Then create module from file, binding to payload
|
|
1495
|
+
mod = CSSL.makemodule("writer", "lib/writer.cssl", bind="api")
|
|
1496
|
+
mod.SaySomething("Hello!")
|
|
1497
|
+
|
|
1314
1498
|
Usage (v3.8.0 - with CSSLScript):
|
|
1315
1499
|
main = CSSL.script("cssl", '''printl("Main");''')
|
|
1316
1500
|
payload = CSSL.script("cssl-pl", '''void helper() {}''')
|
|
@@ -1323,14 +1507,15 @@ def makemodule(
|
|
|
1323
1507
|
math_mod.add(2, 3) # Returns 5
|
|
1324
1508
|
|
|
1325
1509
|
Args:
|
|
1326
|
-
main_script: Main CSSL code
|
|
1510
|
+
main_script: Main CSSL code, file path, or CSSLScript
|
|
1327
1511
|
payload_script: Optional payload code (string or CSSLScript)
|
|
1328
1512
|
name: Optional name to register for payload(name) access
|
|
1513
|
+
bind: Optional payload name to auto-prepend (from makepayload)
|
|
1329
1514
|
|
|
1330
1515
|
Returns:
|
|
1331
1516
|
CSSLFunctionModule - module with callable function attributes
|
|
1332
1517
|
"""
|
|
1333
|
-
return get_cssl().makemodule(main_script, payload_script, name)
|
|
1518
|
+
return get_cssl().makemodule(main_script, payload_script, name, bind)
|
|
1334
1519
|
|
|
1335
1520
|
|
|
1336
1521
|
# Export all
|
|
@@ -1360,6 +1545,7 @@ __all__ = [
|
|
|
1360
1545
|
'get_output',
|
|
1361
1546
|
'clear_output',
|
|
1362
1547
|
'module',
|
|
1548
|
+
'makepayload',
|
|
1363
1549
|
'makemodule',
|
|
1364
1550
|
'share',
|
|
1365
1551
|
'unshare',
|
includecpp/core/cssl_bridge.pyi
CHANGED
|
@@ -412,7 +412,37 @@ class CsslLang:
|
|
|
412
412
|
"""
|
|
413
413
|
...
|
|
414
414
|
|
|
415
|
-
def
|
|
415
|
+
def makepayload(self, name: str, path: str) -> str:
|
|
416
|
+
"""
|
|
417
|
+
Register a payload from a file path.
|
|
418
|
+
|
|
419
|
+
Reads the file and registers it as a payload accessible via payload(name) in CSSL.
|
|
420
|
+
This is a convenience method for loading payload files.
|
|
421
|
+
|
|
422
|
+
Args:
|
|
423
|
+
name: Name to register the payload under (used in payload(name) and bind=name)
|
|
424
|
+
path: Path to the .cssl-pl or .cssl file
|
|
425
|
+
|
|
426
|
+
Returns:
|
|
427
|
+
The payload code that was registered
|
|
428
|
+
|
|
429
|
+
Usage:
|
|
430
|
+
# Register a payload from file
|
|
431
|
+
cssl.makepayload("api", "lib/api/myapi.cssl-pl")
|
|
432
|
+
|
|
433
|
+
# Use with makemodule for automatic binding
|
|
434
|
+
mod = cssl.makemodule("writer", "lib/writer.cssl", bind="api")
|
|
435
|
+
mod.SaySomething("Hello!")
|
|
436
|
+
"""
|
|
437
|
+
...
|
|
438
|
+
|
|
439
|
+
def makemodule(
|
|
440
|
+
self,
|
|
441
|
+
main_script: Union[str, CSSLScript],
|
|
442
|
+
payload_script: Union[str, CSSLScript, None] = ...,
|
|
443
|
+
name: str = ...,
|
|
444
|
+
bind: str = ...
|
|
445
|
+
) -> CSSLFunctionModule:
|
|
416
446
|
"""
|
|
417
447
|
Create a CSSL module with accessible functions as methods.
|
|
418
448
|
|
|
@@ -420,14 +450,23 @@ class CsslLang:
|
|
|
420
450
|
Functions defined in the code become callable Python methods.
|
|
421
451
|
|
|
422
452
|
Args:
|
|
423
|
-
|
|
424
|
-
|
|
453
|
+
main_script: CSSL code string, file path, or CSSLScript object
|
|
454
|
+
payload_script: Optional payload code (string or CSSLScript)
|
|
455
|
+
name: Optional name to register for payload(name) access
|
|
456
|
+
bind: Optional payload name to auto-prepend (from makepayload)
|
|
425
457
|
|
|
426
458
|
Returns:
|
|
427
459
|
CSSLFunctionModule with callable function attributes
|
|
428
460
|
|
|
429
|
-
Usage:
|
|
430
|
-
#
|
|
461
|
+
Usage (simplified - with file path and bind):
|
|
462
|
+
# First register the payload
|
|
463
|
+
cssl.makepayload("api", "lib/api/einkaufsmanager.cssl-pl")
|
|
464
|
+
|
|
465
|
+
# Then create module from file, binding to payload
|
|
466
|
+
mod = cssl.makemodule("writer", "lib/writer.cssl", bind="api")
|
|
467
|
+
mod.SaySomething("Hello!") # Functions are now accessible
|
|
468
|
+
|
|
469
|
+
Usage (from code string):
|
|
431
470
|
math = cssl.makemodule('''
|
|
432
471
|
int add(int a, int b) { return a + b; }
|
|
433
472
|
int sub(int a, int b) { return a - b; }
|
|
@@ -435,7 +474,7 @@ class CsslLang:
|
|
|
435
474
|
print(math.add(10, 5)) # 15
|
|
436
475
|
print(math.sub(10, 5)) # 5
|
|
437
476
|
|
|
438
|
-
|
|
477
|
+
Usage (from script objects):
|
|
439
478
|
main = cssl.script("cssl", "...")
|
|
440
479
|
helpers = cssl.script("cssl-pl", "...")
|
|
441
480
|
mod = cssl.makemodule(main, helpers, "mymodule")
|
|
@@ -541,6 +580,66 @@ class CsslLang:
|
|
|
541
580
|
"""
|
|
542
581
|
...
|
|
543
582
|
|
|
583
|
+
def getInstance(self, name: str) -> Optional[Any]:
|
|
584
|
+
"""
|
|
585
|
+
Get a universal instance by name (for Python-side access).
|
|
586
|
+
|
|
587
|
+
Universal instances are shared containers accessible from CSSL, Python, and C++.
|
|
588
|
+
They support dynamic member/method access and are mutable across all contexts.
|
|
589
|
+
|
|
590
|
+
Args:
|
|
591
|
+
name: Name of the instance (without quotes)
|
|
592
|
+
|
|
593
|
+
Returns:
|
|
594
|
+
The UniversalInstance or None if not found
|
|
595
|
+
|
|
596
|
+
Usage:
|
|
597
|
+
# In CSSL: instance<"myContainer"> container;
|
|
598
|
+
# Then in Python:
|
|
599
|
+
container = cssl.getInstance("myContainer")
|
|
600
|
+
container.member = "value"
|
|
601
|
+
print(container.member) # value
|
|
602
|
+
"""
|
|
603
|
+
...
|
|
604
|
+
|
|
605
|
+
def createInstance(self, name: str) -> Any:
|
|
606
|
+
"""
|
|
607
|
+
Create or get a universal instance by name (for Python-side creation).
|
|
608
|
+
|
|
609
|
+
Args:
|
|
610
|
+
name: Name for the instance
|
|
611
|
+
|
|
612
|
+
Returns:
|
|
613
|
+
The UniversalInstance (new or existing)
|
|
614
|
+
|
|
615
|
+
Usage:
|
|
616
|
+
container = cssl.createInstance("myContainer")
|
|
617
|
+
container.data = {"key": "value"}
|
|
618
|
+
# Now accessible in CSSL via instance<"myContainer">
|
|
619
|
+
"""
|
|
620
|
+
...
|
|
621
|
+
|
|
622
|
+
def deleteInstance(self, name: str) -> bool:
|
|
623
|
+
"""
|
|
624
|
+
Delete a universal instance by name.
|
|
625
|
+
|
|
626
|
+
Args:
|
|
627
|
+
name: Name of the instance to delete
|
|
628
|
+
|
|
629
|
+
Returns:
|
|
630
|
+
True if deleted, False if not found
|
|
631
|
+
"""
|
|
632
|
+
...
|
|
633
|
+
|
|
634
|
+
def listInstances(self) -> List[str]:
|
|
635
|
+
"""
|
|
636
|
+
List all universal instance names.
|
|
637
|
+
|
|
638
|
+
Returns:
|
|
639
|
+
List of instance names
|
|
640
|
+
"""
|
|
641
|
+
...
|
|
642
|
+
|
|
544
643
|
def set_global(self, name: str, value: Any) -> None:
|
|
545
644
|
"""
|
|
546
645
|
Set a global variable in the CSSL runtime.
|
|
@@ -733,20 +832,59 @@ def module(code: str) -> CSSLModule:
|
|
|
733
832
|
...
|
|
734
833
|
|
|
735
834
|
|
|
736
|
-
def
|
|
835
|
+
def makepayload(name: str, path: str) -> str:
|
|
836
|
+
"""
|
|
837
|
+
Register a payload from a file path.
|
|
838
|
+
|
|
839
|
+
Reads the file and registers it as a payload accessible via payload(name) in CSSL.
|
|
840
|
+
|
|
841
|
+
Args:
|
|
842
|
+
name: Name to register the payload under (used in payload(name) and bind=name)
|
|
843
|
+
path: Path to the .cssl-pl or .cssl file
|
|
844
|
+
|
|
845
|
+
Returns:
|
|
846
|
+
The payload code that was registered
|
|
847
|
+
|
|
848
|
+
Usage:
|
|
849
|
+
from includecpp import CSSL
|
|
850
|
+
|
|
851
|
+
# Register a payload from file
|
|
852
|
+
CSSL.makepayload("api", "lib/api/myapi.cssl-pl")
|
|
853
|
+
|
|
854
|
+
# Use with makemodule for automatic binding
|
|
855
|
+
mod = CSSL.makemodule("writer", "lib/writer.cssl", bind="api")
|
|
856
|
+
mod.SaySomething("Hello!")
|
|
857
|
+
"""
|
|
858
|
+
...
|
|
859
|
+
|
|
860
|
+
|
|
861
|
+
def makemodule(
|
|
862
|
+
main_script: Union[str, CSSLScript],
|
|
863
|
+
payload_script: Union[str, CSSLScript, None] = ...,
|
|
864
|
+
name: str = ...,
|
|
865
|
+
bind: str = ...
|
|
866
|
+
) -> CSSLFunctionModule:
|
|
737
867
|
"""
|
|
738
868
|
Create a CSSL module with accessible functions.
|
|
739
869
|
|
|
740
870
|
Args:
|
|
741
|
-
|
|
742
|
-
|
|
871
|
+
main_script: CSSL code string, file path, or CSSLScript object
|
|
872
|
+
payload_script: Optional payload code (string or CSSLScript)
|
|
873
|
+
name: Optional name to register for payload(name) access
|
|
874
|
+
bind: Optional payload name to auto-prepend (from makepayload)
|
|
743
875
|
|
|
744
876
|
Returns:
|
|
745
877
|
CSSLFunctionModule with callable function attributes
|
|
746
878
|
|
|
747
|
-
Usage:
|
|
879
|
+
Usage (simplified):
|
|
748
880
|
from includecpp import CSSL
|
|
749
881
|
|
|
882
|
+
# Register payload and create module
|
|
883
|
+
CSSL.makepayload("api", "lib/api/myapi.cssl-pl")
|
|
884
|
+
mod = CSSL.makemodule("writer", "lib/writer.cssl", bind="api")
|
|
885
|
+
mod.SaySomething("Hello!")
|
|
886
|
+
|
|
887
|
+
Usage (code string):
|
|
750
888
|
math = CSSL.makemodule('''
|
|
751
889
|
int add(int a, int b) { return a + b; }
|
|
752
890
|
''')
|
includecpp/generator/parser.cpp
CHANGED
|
@@ -599,13 +599,81 @@ ModuleDescriptor API::parse_cp_file(const std::string& filepath) {
|
|
|
599
599
|
}
|
|
600
600
|
}
|
|
601
601
|
|
|
602
|
-
// Parse
|
|
602
|
+
// v4.1.1: Parse CONSTRUCTOR, METHOD, and FIELD entries for STRUCT
|
|
603
603
|
auto field_lines = split(field_block, '\n');
|
|
604
604
|
for (const auto& fline : field_lines) {
|
|
605
605
|
std::string ftrim = trim(fline);
|
|
606
606
|
if (ftrim.empty()) continue;
|
|
607
607
|
|
|
608
|
-
|
|
608
|
+
// v4.1.1: Parse CONSTRUCTOR(type1, type2, ...) for parametrized constructors
|
|
609
|
+
if (ftrim.find("CONSTRUCTOR") != std::string::npos) {
|
|
610
|
+
size_t c_start = ftrim.find('(');
|
|
611
|
+
size_t c_end = ftrim.rfind(')');
|
|
612
|
+
if (c_start != std::string::npos && c_end != std::string::npos) {
|
|
613
|
+
std::string params_str = ftrim.substr(c_start + 1, c_end - c_start - 1);
|
|
614
|
+
ConstructorInfo ctor;
|
|
615
|
+
if (!params_str.empty()) {
|
|
616
|
+
auto params = split(params_str, ',');
|
|
617
|
+
for (auto& p : params) {
|
|
618
|
+
std::string param_type = trim(p);
|
|
619
|
+
if (!param_type.empty()) {
|
|
620
|
+
ctor.param_types.push_back(param_type);
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
sb.constructors.push_back(ctor);
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
// v4.1.1: Parse METHOD and METHOD_CONST for STRUCT
|
|
628
|
+
else if (ftrim.find("METHOD") != std::string::npos) {
|
|
629
|
+
MethodSignature sig;
|
|
630
|
+
bool is_const_method = ftrim.find("METHOD_CONST") != std::string::npos;
|
|
631
|
+
|
|
632
|
+
size_t m_start = ftrim.find('(');
|
|
633
|
+
size_t m_end = ftrim.rfind(')');
|
|
634
|
+
|
|
635
|
+
if (m_start != std::string::npos && m_end != std::string::npos) {
|
|
636
|
+
std::string content = ftrim.substr(m_start + 1, m_end - m_start - 1);
|
|
637
|
+
|
|
638
|
+
// Parse method name and optional parameter types
|
|
639
|
+
std::vector<std::string> parts;
|
|
640
|
+
int template_depth = 0;
|
|
641
|
+
std::string current_part;
|
|
642
|
+
|
|
643
|
+
for (char c : content) {
|
|
644
|
+
if (c == '<') {
|
|
645
|
+
template_depth++;
|
|
646
|
+
current_part += c;
|
|
647
|
+
} else if (c == '>') {
|
|
648
|
+
template_depth--;
|
|
649
|
+
current_part += c;
|
|
650
|
+
} else if (c == ',' && template_depth == 0) {
|
|
651
|
+
parts.push_back(trim(current_part));
|
|
652
|
+
current_part.clear();
|
|
653
|
+
} else {
|
|
654
|
+
current_part += c;
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
if (!current_part.empty()) {
|
|
658
|
+
parts.push_back(trim(current_part));
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
if (!parts.empty()) {
|
|
662
|
+
sig.name = parts[0];
|
|
663
|
+
sig.is_const = is_const_method;
|
|
664
|
+
|
|
665
|
+
// Remaining parts are parameter types
|
|
666
|
+
for (size_t k = 1; k < parts.size(); ++k) {
|
|
667
|
+
sig.param_types.push_back(parts[k]);
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
sb.method_signatures.push_back(sig);
|
|
671
|
+
sb.methods.push_back(sig.name);
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
// Parse FIELD(name) or FIELD(type, name)
|
|
676
|
+
else if (ftrim.find("FIELD(") != std::string::npos) {
|
|
609
677
|
size_t f_start = ftrim.find('(');
|
|
610
678
|
size_t f_end = ftrim.find(')');
|
|
611
679
|
if (f_start != std::string::npos && f_end != std::string::npos) {
|
|
@@ -616,6 +684,10 @@ ModuleDescriptor API::parse_cp_file(const std::string& filepath) {
|
|
|
616
684
|
std::string field_type = trim(field_parts[0]);
|
|
617
685
|
std::string field_name = trim(field_parts[1]);
|
|
618
686
|
sb.fields.push_back({field_type, field_name});
|
|
687
|
+
} else if (field_parts.size() == 1) {
|
|
688
|
+
// Simple FIELD(name) - type will be inferred
|
|
689
|
+
std::string field_name = trim(field_parts[0]);
|
|
690
|
+
sb.fields.push_back({"auto", field_name});
|
|
619
691
|
}
|
|
620
692
|
}
|
|
621
693
|
}
|
|
@@ -870,7 +942,24 @@ std::string generate_struct_bindings(const StructBinding& sb, const ModuleDescri
|
|
|
870
942
|
|
|
871
943
|
code << " py::class_<" << cpp_type << ">(";
|
|
872
944
|
code << mod.module_name << "_module, \"" << struct_full_name << "\")\n";
|
|
873
|
-
|
|
945
|
+
|
|
946
|
+
// v4.1.1: Generate all constructor overloads from CONSTRUCTOR() entries
|
|
947
|
+
if (sb.constructors.empty()) {
|
|
948
|
+
// Backward compatibility: default constructor if none specified
|
|
949
|
+
code << " .def(py::init<>())\n";
|
|
950
|
+
} else {
|
|
951
|
+
for (const auto& ctor : sb.constructors) {
|
|
952
|
+
code << " .def(py::init<";
|
|
953
|
+
for (size_t i = 0; i < ctor.param_types.size(); ++i) {
|
|
954
|
+
if (i > 0) code << ", ";
|
|
955
|
+
// Replace T with actual template type
|
|
956
|
+
std::string ptype = ctor.param_types[i];
|
|
957
|
+
if (ptype == "T") ptype = ttype;
|
|
958
|
+
code << ptype;
|
|
959
|
+
}
|
|
960
|
+
code << ">())\n";
|
|
961
|
+
}
|
|
962
|
+
}
|
|
874
963
|
|
|
875
964
|
// Fields - readwrite access
|
|
876
965
|
for (const auto& [field_type, field_name] : sb.fields) {
|
|
@@ -884,6 +973,15 @@ std::string generate_struct_bindings(const StructBinding& sb, const ModuleDescri
|
|
|
884
973
|
<< cpp_type << "::" << field_name << ")\n";
|
|
885
974
|
}
|
|
886
975
|
|
|
976
|
+
// v4.1.1: Generate method bindings
|
|
977
|
+
for (const auto& sig : sb.method_signatures) {
|
|
978
|
+
if (sig.is_const) {
|
|
979
|
+
code << " .def(\"" << sig.name << "\", &" << cpp_type << "::" << sig.name << ")\n";
|
|
980
|
+
} else {
|
|
981
|
+
code << " .def(\"" << sig.name << "\", &" << cpp_type << "::" << sig.name << ")\n";
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
|
|
887
985
|
// Auto-generate to_dict() method
|
|
888
986
|
code << " .def(\"to_dict\", [](" << cpp_type << "& self) {\n";
|
|
889
987
|
code << " py::dict d;\n";
|
|
@@ -917,7 +1015,21 @@ std::string generate_struct_bindings(const StructBinding& sb, const ModuleDescri
|
|
|
917
1015
|
// Non-template struct
|
|
918
1016
|
code << " py::class_<" << sb.struct_name << ">(";
|
|
919
1017
|
code << mod.module_name << "_module, \"" << sb.struct_name << "\")\n";
|
|
920
|
-
|
|
1018
|
+
|
|
1019
|
+
// v4.1.1: Generate all constructor overloads from CONSTRUCTOR() entries
|
|
1020
|
+
if (sb.constructors.empty()) {
|
|
1021
|
+
// Backward compatibility: default constructor if none specified
|
|
1022
|
+
code << " .def(py::init<>())\n";
|
|
1023
|
+
} else {
|
|
1024
|
+
for (const auto& ctor : sb.constructors) {
|
|
1025
|
+
code << " .def(py::init<";
|
|
1026
|
+
for (size_t i = 0; i < ctor.param_types.size(); ++i) {
|
|
1027
|
+
if (i > 0) code << ", ";
|
|
1028
|
+
code << ctor.param_types[i];
|
|
1029
|
+
}
|
|
1030
|
+
code << ">())\n";
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
921
1033
|
|
|
922
1034
|
// Fields
|
|
923
1035
|
for (const auto& [field_type, field_name] : sb.fields) {
|
|
@@ -925,6 +1037,11 @@ std::string generate_struct_bindings(const StructBinding& sb, const ModuleDescri
|
|
|
925
1037
|
<< sb.struct_name << "::" << field_name << ")\n";
|
|
926
1038
|
}
|
|
927
1039
|
|
|
1040
|
+
// v4.1.1: Generate method bindings
|
|
1041
|
+
for (const auto& sig : sb.method_signatures) {
|
|
1042
|
+
code << " .def(\"" << sig.name << "\", &" << sb.struct_name << "::" << sig.name << ")\n";
|
|
1043
|
+
}
|
|
1044
|
+
|
|
928
1045
|
// Auto-generate to_dict() method
|
|
929
1046
|
code << " .def(\"to_dict\", [](" << sb.struct_name << "& self) {\n";
|
|
930
1047
|
code << " py::dict d;\n";
|