IncludeCPP 4.6.0__py3-none-any.whl → 4.9.3__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 (35) hide show
  1. includecpp/CHANGELOG.md +241 -0
  2. includecpp/__init__.py +89 -3
  3. includecpp/__init__.pyi +2 -1
  4. includecpp/cli/commands.py +1747 -266
  5. includecpp/cli/config_parser.py +1 -1
  6. includecpp/core/build_manager.py +64 -13
  7. includecpp/core/cpp_api_extensions.pyi +43 -270
  8. includecpp/core/cssl/CSSL_DOCUMENTATION.md +1799 -1445
  9. includecpp/core/cssl/cpp/build/api.pyd +0 -0
  10. includecpp/core/cssl/cpp/build/api.pyi +274 -0
  11. includecpp/core/cssl/cpp/build/cssl_core.pyi +0 -99
  12. includecpp/core/cssl/cpp/cssl_core.cp +2 -23
  13. includecpp/core/cssl/cssl_builtins.py +2116 -171
  14. includecpp/core/cssl/cssl_builtins.pyi +1324 -104
  15. includecpp/core/cssl/cssl_compiler.py +4 -1
  16. includecpp/core/cssl/cssl_modules.py +605 -6
  17. includecpp/core/cssl/cssl_optimizer.py +12 -1
  18. includecpp/core/cssl/cssl_parser.py +1048 -52
  19. includecpp/core/cssl/cssl_runtime.py +2041 -131
  20. includecpp/core/cssl/cssl_syntax.py +405 -277
  21. includecpp/core/cssl/cssl_types.py +5891 -1655
  22. includecpp/core/cssl_bridge.py +427 -4
  23. includecpp/core/error_catalog.py +54 -10
  24. includecpp/core/homeserver.py +1037 -0
  25. includecpp/generator/parser.cpp +203 -39
  26. includecpp/generator/parser.h +15 -1
  27. includecpp/templates/cpp.proj.template +1 -1
  28. includecpp/vscode/cssl/snippets/cssl.snippets.json +163 -0
  29. includecpp/vscode/cssl/syntaxes/cssl.tmLanguage.json +87 -12
  30. {includecpp-4.6.0.dist-info → includecpp-4.9.3.dist-info}/METADATA +81 -10
  31. {includecpp-4.6.0.dist-info → includecpp-4.9.3.dist-info}/RECORD +35 -33
  32. {includecpp-4.6.0.dist-info → includecpp-4.9.3.dist-info}/WHEEL +1 -1
  33. {includecpp-4.6.0.dist-info → includecpp-4.9.3.dist-info}/entry_points.txt +0 -0
  34. {includecpp-4.6.0.dist-info → includecpp-4.9.3.dist-info}/licenses/LICENSE +0 -0
  35. {includecpp-4.6.0.dist-info → includecpp-4.9.3.dist-info}/top_level.txt +0 -0
@@ -1,1720 +1,2074 @@
1
- # CSSL - C-Style Scripting Language
1
+ # CSSL - C-Style Scripting Language
2
2
 
3
- > Version 4.1.0 | A modern scripting language with C++-style syntax and unique features like CodeInfusion, BruteInjection, Python Interop, and Multi-Language Support.
3
+ > Version 4.9.3 | A modern scripting language with C++-style syntax featuring async/await, generators, CodeInfusion, BruteInjection, Snapshots, Python/C++ Interop, Multi-Language Support, and 330+ built-in functions.
4
4
 
5
- ---
5
+ ---
6
6
 
7
- ## Table of Contents
7
+ ## Table of Contents
8
8
 
9
- 1. [Quick Start](#quick-start)
10
- 2. [Syntax Basics](#syntax-basics)
11
- 3. [Data Types](#data-types)
12
- 4. [Variables & Globals](#variables--globals)
13
- 5. [Operators](#operators)
14
- 6. [Control Flow](#control-flow)
15
- 7. [Functions](#functions)
16
- 8. [Classes & OOP](#classes--oop)
17
- 9. [Container Types](#container-types)
18
- 10. [Built-in Functions](#built-in-functions)
19
- 11. [CodeInfusion](#codeinfusion)
20
- 12. [BruteInjection](#bruteinjection)
21
- 13. [Value Capture](#value-capture)
22
- 14. [Module System](#module-system)
23
- 15. [Multi-Language Support](#multi-language-support)
24
- 16. [Error Handling](#error-handling)
25
- 17. [Quick Reference](#quick-reference)
9
+ 1. [Quick Start](#quick-start)
10
+ 2. [Syntax Basics](#syntax-basics)
11
+ 3. [Data Types](#data-types)
12
+ 4. [Variables & Scope](#variables--scope)
13
+ 5. [Operators](#operators)
14
+ 6. [Control Flow](#control-flow)
15
+ 7. [Functions](#functions)
16
+ 8. [Classes & OOP](#classes--oop)
17
+ 9. [Namespaces](#namespaces)
18
+ 10. [Enums & Structs](#enums--structs)
19
+ 11. [Container Types](#container-types)
20
+ 12. [Built-in Functions](#built-in-functions)
21
+ 13. [CodeInfusion](#codeinfusion)
22
+ 14. [BruteInjection](#bruteinjection)
23
+ 15. [Snapshot System](#snapshot-system)
24
+ 16. [C++ I/O Streams](#c-io-streams)
25
+ 17. [Module System](#module-system)
26
+ 18. [C++ Integration](#c-integration)
27
+ 19. [Python Interop](#python-interop)
28
+ 20. [Multi-Language Support](#multi-language-support)
29
+ 21. [Async/Await System](#asyncawait-system-v493)
30
+ 22. [Error Handling](#error-handling)
31
+ 23. [CLI Reference](#cli-reference)
32
+ 24. [Quick Reference](#quick-reference)
26
33
 
27
- ---
34
+ ---
28
35
 
29
- ## Quick Start
36
+ ## Quick Start
30
37
 
31
- ### Installation
38
+ ### Installation
32
39
 
33
- ```bash
34
- pip install includecpp
35
- ```
40
+ ```bash
41
+ pip install includecpp
42
+ ```
36
43
 
37
- ### Python Usage
44
+ ### Python Usage
38
45
 
39
- ```python
40
- from includecpp import CSSL
46
+ ```python
47
+ from includecpp import CSSL
41
48
 
42
- # Execute CSSL code
43
- CSSL.run('''
44
- printl("Hello CSSL!");
45
- ''')
49
+ # Execute CSSL code
50
+ CSSL.run('''
51
+ printl("Hello CSSL!");
52
+ ''')
46
53
 
47
- # With parameters and return value
48
- result = CSSL.run('''
49
- string name = parameter.get(0);
50
- printl("Hello " + name);
51
- parameter.return(true);
52
- ''', "World")
54
+ # With parameters and return value
55
+ result = CSSL.run('''
56
+ string name = parameter.get(0);
57
+ printl("Hello " + name);
58
+ parameter.return(true);
59
+ ''', "World")
53
60
 
54
- print(result) # True
55
- ```
61
+ print(result) # True
62
+ ```
56
63
 
57
- ### CLI Execution
64
+ ### CLI Execution
58
65
 
59
- ```bash
60
- # Execute CSSL file
61
- python -m includecpp cssl exec myfile.cssl
66
+ ```bash
67
+ # Execute CSSL file
68
+ includecpp cssl run myfile.cssl
62
69
 
63
- # Create module from Python file
64
- python -m includecpp cssl makemodule mylib.py -o mylib.cssl-mod
65
- ```
70
+ # Run inline code
71
+ includecpp cssl run -c 'printl("Hello!");'
66
72
 
67
- ### First Script
73
+ # Create module from Python file
74
+ includecpp cssl makemodule mylib.py -o mylib.cssl-mod
68
75
 
69
- ```cssl
70
- // Variables
71
- string name = "CSSL";
72
- int version = 3;
76
+ # Format CSSL file
77
+ includecpp cssl format myfile.cssl
78
+ ```
73
79
 
74
- // Output
75
- printl("Welcome to " + name);
80
+ ### First Script
76
81
 
77
- // Function
78
- void greet(string msg) {
79
- printl(msg);
80
- }
82
+ ```cssl
83
+ // Variables
84
+ string name = "CSSL";
85
+ int version = 4;
81
86
 
82
- greet("Hello World!");
83
- ```
87
+ // Output
88
+ printl("Welcome to " + name + " v" + version);
84
89
 
85
- ---
90
+ // Function
91
+ void greet(string msg) {
92
+ printl(msg);
93
+ }
86
94
 
87
- ## Syntax Basics
95
+ greet("Hello World!");
96
+
97
+ // Class
98
+ class Greeter {
99
+ string prefix = "Hello";
88
100
 
89
- ### Comments
101
+ constr(string p) {
102
+ this->prefix = p;
103
+ }
104
+
105
+ void say(string name) {
106
+ printl(this->prefix + ", " + name + "!");
107
+ }
108
+ }
109
+
110
+ @g = new Greeter("Hi");
111
+ g.say("CSSL");
112
+ ```
113
+
114
+ ---
115
+
116
+ ## Syntax Basics
117
+
118
+ ### Comments
119
+
120
+ ```cssl
121
+ // Single-line comment (C-style)
122
+ # Single-line comment (Python-style)
123
+ /* Multi-line
124
+ comment */
125
+ ```
90
126
 
91
- ```cssl
92
- // Single-line comment (C-style)
93
- # Single-line comment (Python-style)
94
- ```
127
+ ### Semicolons
95
128
 
96
- ### Semicolons
129
+ Semicolons are optional but recommended for clarity.
97
130
 
98
- Semicolons are optional but recommended for clarity.
131
+ ```cssl
132
+ printl("Hello") // Works
133
+ printl("Hello"); // Also works (recommended)
134
+ ```
99
135
 
100
- ```cssl
101
- printl("Hello") // Works
102
- printl("Hello"); // Also works (recommended)
103
- ```
136
+ ### I/O Functions
137
+
138
+ ```cssl
139
+ // Output
140
+ printl("Text"); // Print with newline
141
+ println("Text"); // Alias for printl
142
+ print("No newline"); // Print without newline
143
+ debug("Debug info"); // Print with [DEBUG] prefix
144
+ error("Error message"); // Print with [ERROR] prefix
145
+ warn("Warning"); // Print with [WARN] prefix
146
+ log("INFO", "Message"); // Print with custom prefix
147
+
148
+ // Input
149
+ string name = input("Enter your name: ");
150
+ int age = int(input("Enter your age: "));
151
+ string raw = input(); // Without prompt
152
+ ```
153
+
154
+ ### String Syntax
155
+
156
+ ```cssl
157
+ // Basic strings
158
+ string s1 = "Double quoted";
159
+ string s2 = 'Single quoted';
160
+ string s3 = `Raw string (no escape processing)`;
161
+
162
+ // String interpolation
163
+ string name = "CSSL";
164
+ printl("Welcome to <name>"); // "Welcome to CSSL"
165
+
166
+ // F-strings (v4.6.3)
167
+ printl(f"Hello {name}!");
168
+ printl(f"{red('Error:')} Something went wrong");
169
+ printl(f"Result: {bold(str(42))}");
170
+
171
+ // Escape sequences
172
+ "\n" // Newline
173
+ "\t" // Tab
174
+ "\\" // Backslash
175
+ "\"" // Double quote
176
+ ```
177
+
178
+ ---
179
+
180
+ ## Data Types
181
+
182
+ ### Primitive Types
183
+
184
+ | Type | Description | Example |
185
+ |------|-------------|---------|
186
+ | `int` | Integer | `int x = 42;` |
187
+ | `float` | Floating point | `float f = 3.14;` |
188
+ | `string` | Text string | `string s = "Hello";` |
189
+ | `bool` | Boolean | `bool b = true;` |
190
+ | `bit` | Binary 0 or 1 (v4.9.0) | `bit flag = 1;` |
191
+ | `byte` | 8-bit value (v4.9.0) | `byte b = 1^200;` |
192
+ | `address` | Memory reference (v4.9.0) | `address addr = memory(x).get("address");` |
193
+ | `dynamic` | Any type (flexible) | `dynamic x = "text";` |
194
+ | `void` | No return value | `void func() { }` |
195
+ | `undefined` | Function errors ignored | `undefined func() { }` |
196
+ | `null` / `None` | Absence of value | `dynamic x = null;` |
197
+ | `json` | JSON type | `json data = {"key": "value"};` |
198
+
199
+ ### Boolean Values
200
+
201
+ ```cssl
202
+ // Python-style
203
+ bool a = True;
204
+ bool b = False;
205
+
206
+ // C-style
207
+ bool c = true;
208
+ bool d = false;
209
+ ```
210
+
211
+ ### Type Conversion
212
+
213
+ ```cssl
214
+ int("42"); // String to int: 42
215
+ float("3.14"); // String to float: 3.14
216
+ str(42); // Int to string: "42"
217
+ bool(1); // Int to bool: true
218
+ int("ff", 16); // Hex to int: 255
219
+ list("abc"); // String to list: ['a', 'b', 'c']
220
+ dict([["a", 1]]); // List to dict
221
+ ```
222
+
223
+ ### Type Checking
224
+
225
+ ```cssl
226
+ typeof(42); // "int"
227
+ typeof("hello"); // "str"
228
+ typeof([1, 2]); // "list"
229
+ isinstance(42, "int"); // true
230
+ isint(42); // true
231
+ isfloat(3.14); // true
232
+ isstr("hello"); // true
233
+ isbool(true); // true
234
+ islist([1, 2]); // true
235
+ isdict({"a": 1}); // true
236
+ isnull(null); // true
237
+ ```
238
+
239
+ ### Binary Types (v4.9.0)
240
+
241
+ **bit** - Single binary value (0 or 1):
242
+ ```cssl
243
+ bit flag = 1;
244
+ printl(flag); // 1
245
+
246
+ flag.switch(); // Toggle: 1 -> 0
247
+ printl(flag); // 0
248
+
249
+ flag.set(1); // Set to 1
250
+ flag.clear(); // Set to 0
251
+
252
+ bit copy = flag.copy(); // Create copy
253
+ ```
254
+
255
+ **byte** - 8-bit value with x^y notation:
256
+ ```cssl
257
+ // x^y notation: x = base (0/1), y = weight (0-255)
258
+ byte b = 1^200; // Value = 200
259
+
260
+ printl(b.value()); // 200
261
+ printl(b.to_str()); // "11001000" (binary)
262
+ printl(b.info()); // Full info dict
263
+
264
+ // Bit operations
265
+ printl(b.at(7)); // Get bit 7
266
+ b.switch(7); // Toggle bit 7
267
+ b.set(0, 1); // Set bit 0 to 1
268
+ b.write(0, 4); // Set bits 0-3 to 1
269
+
270
+ // Copy and reverse
271
+ byte r = b.reverse(); // Reverse bit order
272
+ byte c = b.copy(); // Copy byte
273
+ ```
274
+
275
+ **address** - Memory reference (pointer-like):
276
+ ```cssl
277
+ string text = "Hello";
278
+
279
+ // Get memory address
280
+ address addr = memory(text).get("address");
281
+
282
+ // Reflect to get object back
283
+ obj = addr.reflect(); // Returns the original object
284
+ // Or use builtin
285
+ obj = reflect(addr); // Same result
286
+
287
+ printl(obj); // "Hello"
288
+ ```
289
+
290
+ ---
291
+
292
+ ## Variables & Scope
293
+
294
+ ### Basic Variable Declaration
295
+
296
+ ```cssl
297
+ // Typed variables (recommended)
298
+ int count = 0;
299
+ string name = "CSSL";
300
+ float pi = 3.14159;
301
+ bool active = true;
302
+
303
+ // Dynamic variables (flexible but slower)
304
+ dynamic value = "text";
305
+ value = 42; // Can change type
306
+ ```
307
+
308
+ ### Scope Behavior
309
+
310
+ Variables are **local by default**. Each function/class has its own scope.
311
+
312
+ ```cssl
313
+ define myFunction() {
314
+ string name = "Alice"; // Local to myFunction
315
+ printl(name); // Works
316
+ }
317
+
318
+ myFunction();
319
+ // printl(name); // Error! 'name' doesn't exist here
320
+ ```
321
+
322
+ ### Global Variables
323
+
324
+ ```cssl
325
+ // Method 1: global keyword
326
+ global counter = 0;
327
+
328
+ define increment() {
329
+ global(counter); // Access global
330
+ counter = counter + 1;
331
+ }
332
+
333
+ // Method 2: r@ prefix
334
+ r@globalVar = 100;
335
+
336
+ define readGlobal() {
337
+ printl(r@globalVar); // Access global
338
+ }
339
+
340
+ // Method 3: global modifier on function
341
+ global define myFunc() {
342
+ // This function is globally accessible
343
+ }
104
344
 
105
- ### I/O Functions
345
+ // Method 4: global variable declaration
346
+ global int sharedCounter = 0;
347
+ ```
106
348
 
107
- ```cssl
108
- // Output
109
- printl("Text"); // Print with newline
110
- print("No newline"); // Print without newline
111
- debug("Debug info"); // Print with [DEBUG] prefix
112
- error("Error message"); // Print with [ERROR] prefix
113
- warn("Warning"); // Print with [WARN] prefix
114
- log("INFO", "Message"); // Print with custom prefix
349
+ ### Variable References
350
+
351
+ ```cssl
352
+ // Module reference (@)
353
+ @Module = include("mymodule.cssl");
354
+ @ModuleName.function();
355
+
356
+ // Global reference (r@)
357
+ r@globalVar = "shared";
358
+
359
+ // Struct self-reference (s@)
360
+ s@Backend.Loop.timer; // Access global struct member
361
+
362
+ // Shared object reference ($)
363
+ $SharedData = {"key": "value"};
364
+ $SharedData.key; // Access shared
365
+
366
+ // Captured reference (% for snapshots)
367
+ snapshot(myVar);
368
+ printl(%myVar); // Access snapshotted value
369
+ ```
370
+
371
+ ---
372
+
373
+ ## Operators
374
+
375
+ ### Arithmetic Operators
376
+
377
+ | Operator | Description | Example |
378
+ |----------|-------------|---------|
379
+ | `+` | Addition | `5 + 3` → `8` |
380
+ | `-` | Subtraction | `5 - 3` → `2` |
381
+ | `*` | Multiplication | `5 * 3` → `15` |
382
+ | `/` | Division | `6 / 2` → `3` |
383
+ | `%` | Modulo | `7 % 3` → `1` |
384
+
385
+ ### Comparison Operators
386
+
387
+ | Operator | Description | Example |
388
+ |----------|-------------|---------|
389
+ | `==` | Equal to | `5 == 5` → `true` |
390
+ | `!=` | Not equal to | `5 != 3` → `true` |
391
+ | `<` | Less than | `3 < 5` → `true` |
392
+ | `>` | Greater than | `5 > 3` → `true` |
393
+ | `<=` | Less or equal | `3 <= 3` → `true` |
394
+ | `>=` | Greater or equal | `5 >= 3` → `true` |
395
+
396
+ ### Logical Operators
397
+
398
+ | Operator | Description | Example |
399
+ |----------|-------------|---------|
400
+ | `&&` / `and` | Logical AND | `true && false` → `false` |
401
+ | `\|\|` / `or` | Logical OR | `true \|\| false` → `true` |
402
+ | `!` / `not` | Logical NOT | `!true` → `false` |
403
+
404
+ ### Special Operators
405
+
406
+ | Operator | Description | Example |
407
+ |----------|-------------|---------|
408
+ | `in` | Containment | `"a" in "abc"` → `true` |
409
+ | `::` | Namespace access | `json::parse(s)` |
410
+ | `.` | Member access | `obj.method()` |
411
+ | `->` | C++ style access | `this->member` |
412
+ | `\|` | Pipe operator | `data \| filter \| process` |
413
+ | `<<` | Stream output | `cout << "text"` |
414
+ | `>>` | Stream input | `cin >> variable` |
415
+ | `~` | Destructor | `~object` |
416
+ | `&` | Reference | `&variable` |
417
+ | `++` | Append | `constr++ { }` |
418
+
419
+ ### Injection Operators
420
+
421
+ | Operator | Name | Description |
422
+ |----------|------|-------------|
423
+ | `<==` | Inject Left | Replace target with source |
424
+ | `==>` | Inject Right | Right-side injection |
425
+ | `+<==` | Brute+ Left | Keep old + add new |
426
+ | `==>+` | Brute+ Right | Keep old + add new (right) |
427
+ | `-<==` | Brute- Left | Move and remove old |
428
+ | `===>-` | Brute- Right | Move and remove (right) |
429
+ | `<<==` | Infuse Left | Code infusion |
430
+ | `==>>` | Infuse Right | Code infusion (right) |
431
+ | `+<<==` | Infuse+ Left | Code copy & add |
432
+ | `==>>+` | Infuse+ Right | Code copy & add (right) |
433
+
434
+ ### Flow Operators
435
+
436
+ | Operator | Description | Example |
437
+ |----------|-------------|---------|
438
+ | `->` | Flow right | `data -> process` |
439
+ | `<-` | Flow left | `result <- compute` |
440
+
441
+ ---
442
+
443
+ ## Control Flow
444
+
445
+ ### If/Else
446
+
447
+ ```cssl
448
+ if (condition) {
449
+ // code
450
+ } elif (other_condition) {
451
+ // code
452
+ } else {
453
+ // code
454
+ }
455
+
456
+ // Without parentheses
457
+ if condition {
458
+ // code
459
+ }
460
+ ```
461
+
462
+ ### While Loop
463
+
464
+ ```cssl
465
+ int i = 0;
466
+ while (i < 10) {
467
+ printl(i);
468
+ i = i + 1;
469
+ }
470
+ ```
471
+
472
+ ### For Loop
473
+
474
+ ```cssl
475
+ // C-style for loop
476
+ for (int i = 0; i < 10; i = i + 1) {
477
+ printl(i);
478
+ }
479
+
480
+ // Foreach with range
481
+ foreach (i in range(10)) {
482
+ printl(i);
483
+ }
484
+
485
+ // Foreach with collection
486
+ list items = [1, 2, 3];
487
+ foreach (item in items) {
488
+ printl(item);
489
+ }
490
+
491
+ // For-in loop
492
+ for item in items {
493
+ printl(item);
494
+ }
495
+ ```
496
+
497
+ ### Switch/Case
498
+
499
+ ```cssl
500
+ switch (value) {
501
+ case 1:
502
+ printl("One");
503
+ break;
504
+ case 2:
505
+ case 3:
506
+ printl("Two or Three");
507
+ break;
508
+ default:
509
+ printl("Other");
510
+ }
511
+ ```
512
+
513
+ ### Break/Continue
514
+
515
+ ```cssl
516
+ foreach (i in range(10)) {
517
+ if (i == 5) {
518
+ break; // Exit loop
519
+ }
520
+ if (i % 2 == 0) {
521
+ continue; // Skip to next iteration
522
+ }
523
+ printl(i);
524
+ }
525
+ ```
526
+
527
+ ---
528
+
529
+ ## Functions
530
+
531
+ ### Basic Functions
532
+
533
+ ```cssl
534
+ // Simple function
535
+ define greet() {
536
+ printl("Hello!");
537
+ }
538
+
539
+ // Typed function with return
540
+ int add(int a, int b) {
541
+ return a + b;
542
+ }
543
+
544
+ // Dynamic parameters
545
+ void process(dynamic data) {
546
+ printl(typeof(data) + ": " + str(data));
547
+ }
548
+
549
+ // C++ style void function
550
+ void myFunction() {
551
+ printl("C++ style");
552
+ }
553
+ ```
554
+
555
+ ### Function Modifiers
556
+
557
+ ```cssl
558
+ // const - Immutable function (no side effects)
559
+ const define pureFunc() {
560
+ return 42;
561
+ }
562
+
563
+ // private - No external injections
564
+ private define secureFunc() {
565
+ // Protected from injection
566
+ }
567
+
568
+ // static - No instance overhead
569
+ static define staticFunc() {
570
+ // Optimized static function
571
+ }
572
+
573
+ // global - Globally accessible
574
+ global define globalFunc() {
575
+ // Accessible from anywhere
576
+ }
577
+
578
+ // embedded - Immediate &target replacement (v4.2.5)
579
+ embedded define override &println {
580
+ print("[LOG] ");
581
+ %println(args); // Call original
582
+ }
115
583
 
116
- // Input
117
- string name = input("Enter your name: ");
118
- int age = int(input("Enter your age: "));
119
- string raw = input(); // Without prompt
120
- ```
584
+ // native - Force C++ execution (v4.6.0)
585
+ native define fastFunc() {
586
+ // Runs in C++ interpreter
587
+ }
121
588
 
122
- ---
589
+ // unative - Force Python execution (v4.6.5)
590
+ unative define pythonFunc() {
591
+ // Runs in Python interpreter
592
+ }
123
593
 
124
- ## Data Types
594
+ // meta - Source function (must return)
595
+ meta define mustReturn() {
596
+ return true;
597
+ }
125
598
 
126
- ### Primitive Types
599
+ // closed - Protect from external injection
600
+ closed define protectedFunc() {
601
+ // Cannot be injected from outside
602
+ }
127
603
 
128
- | Type | Description | Example |
129
- |------|-------------|---------|
130
- | `int` | Integer | `int x = 42;` |
131
- | `float` | Floating point | `float f = 3.14;` |
132
- | `string` | Text string | `string s = "Hello";` |
133
- | `bool` | Boolean | `bool b = true;` |
134
- | `dynamic` | Any type (flexible) | `dynamic x = "text";` |
135
- | `void` | No return value | `void func() { }` |
136
- | `null` | Absence of value | `dynamic x = null;` |
604
+ // open - Accept any parameter type
605
+ open define flexibleFunc(open param) {
606
+ printl(typeof(param));
607
+ }
608
+ ```
137
609
 
138
- ### Generic Container Types
610
+ ### Function Appending
139
611
 
140
- | Type | Description | Example |
141
- |------|-------------|---------|
142
- | `stack<T>` | LIFO stack | `stack<string> names;` |
143
- | `vector<T>` | Dynamic array | `vector<int> nums;` |
144
- | `array<T>` | Standard array | `array<float> values;` |
145
- | `map<K,V>` | Ordered key-value | `map<string, int> ages;` |
146
- | `list` | Python-like list | `list items = [1, 2, 3];` |
147
- | `dict` | Dictionary | `dict data = {"a": 1};` |
148
- | `datastruct<T>` | Universal container | `datastruct<string> data;` |
149
- | `iterator<T>` | Programmable iterator | `iterator<int> it;` |
150
- | `shuffled<T>` | Multi-value returns | `shuffled<string> results;` |
151
- | `combo<T>` | Filter/search space | `combo<string> search;` |
612
+ ```cssl
613
+ // Original function
614
+ define myFunc() {
615
+ printl("Original");
616
+ }
152
617
 
153
- ### Type Conversion
618
+ // Append to existing function (keeps old + adds new)
619
+ myFunc++ {
620
+ printl("Added behavior");
621
+ }
154
622
 
155
- ```cssl
156
- int("42"); // String to int: 42
157
- float("3.14"); // String to float: 3.14
158
- str(42); // Int to string: "42"
159
- bool(1); // Int to bool: true
160
- int("ff", 16); // Hex to int: 255
161
- ```
623
+ // Calling myFunc now outputs:
624
+ // "Original"
625
+ // "Added behavior"
626
+ ```
162
627
 
163
- ### Type Checking
628
+ ### Parameter Switch (v4.2.5)
164
629
 
165
- ```cssl
166
- typeof(42); // "int"
167
- typeof("hello"); // "str"
168
- isinstance(42, "int"); // true
169
- isint(42); // true
170
- isstr("hello"); // true
171
- isnull(null); // true
172
- ```
630
+ ```cssl
631
+ define processData(...params)
632
+ except {
633
+ // Handle invalid parameters
634
+ printl("Invalid parameters!");
635
+ }
636
+ always {
637
+ // Always execute (like finally)
638
+ printl("Cleanup");
639
+ }
640
+ ```
173
641
 
174
- ---
642
+ ---
175
643
 
176
- ## Variables & Globals
644
+ ## Classes & OOP
177
645
 
178
- ### Scope Behavior
646
+ ### Basic Class
179
647
 
180
- Variables are **local by default**. Each function/class has its own scope - variables defined inside a function only exist within that function.
648
+ ```cssl
649
+ class Person {
650
+ string name = "";
651
+ int age = 0;
181
652
 
182
- ```cssl
183
- define myFunction() {
184
- string name = "Alice"; // Local to myFunction
185
- printl(name); // Works
653
+ // Constructor
654
+ constr(string n, int a) {
655
+ this->name = n;
656
+ this->age = a;
186
657
  }
187
658
 
188
- myFunction();
189
- // printl(name); // Error! 'name' doesn't exist here
190
-
191
- // Same variable name in different scopes = different variables
192
- string name = "Bob";
193
-
194
- define otherFunction() {
195
- string name = "Charlie"; // Different variable, local to otherFunction
196
- printl(name); // "Charlie"
659
+ // Method
660
+ void introduce() {
661
+ printl("I'm " + this->name + ", " + this->age + " years old");
197
662
  }
663
+ }
198
664
 
199
- otherFunction();
200
- printl(name); // "Bob" - outer scope unchanged
201
- ```
202
-
203
- ### Everything is Local by Default
204
-
205
- All elements (variables, functions, classes) are **local by default** and must be explicitly marked global.
206
-
207
- | Element | Local (default) | Global |
208
- |---------|-----------------|--------|
209
- | **Variables** | `string x = "text";` | `global x = "text";` or `@x = "text";` |
210
- | **Functions** | `define myFunc() { }` | `global define myFunc() { }` or `define @myFunc() { }` |
211
- | **Typed functions** | `void myFunc() { }` | `global void myFunc() { }` or `void @myFunc() { }` |
212
- | **Classes** | `class MyClass { }` | `global class MyClass { }` or `class @MyClass { }` |
213
-
214
- ### Local Variables
215
-
216
- ```cssl
217
- string name = "Alice";
218
- int count = 10;
219
- float price = 19.99;
220
- bool active = true;
221
- ```
222
-
223
- ### Global Variables
224
-
225
- Use `global` keyword or `@`/`r@` prefix to create/access global variables:
226
-
227
- ```cssl
228
- // Declaration with 'global' keyword
229
- global myGlobal = "visible everywhere";
230
-
231
- // Access with '@' prefix
232
- printl(@myGlobal);
233
-
234
- // Direct global assignment with @ or r@
235
- @anotherGlobal = "also global";
236
- r@yetAnother = "and this too";
665
+ // Create instance
666
+ @p = new Person("Alice", 25);
667
+ p.introduce();
668
+ ```
237
669
 
238
- // Always read globals with @
239
- printl(@x);
240
- ```
670
+ ### Inheritance
241
671
 
242
- ### Global Functions
672
+ ```cssl
673
+ class Animal {
674
+ string name = "";
243
675
 
244
- ```cssl
245
- // Global function with 'global' keyword
246
- global define helper() {
247
- printl("I'm global!");
676
+ constr(string n) {
677
+ this->name = n;
248
678
  }
249
679
 
250
- // Alternative: @ prefix syntax
251
- define @anotherHelper() {
252
- printl("Also global!");
680
+ void speak() {
681
+ printl("...");
253
682
  }
683
+ }
254
684
 
255
- // Global typed function
256
- global void @utilityFunc(string msg) {
257
- printl(msg);
685
+ // C++ style inheritance (with 'extends')
686
+ class Dog extends Animal {
687
+ constr(string n) {
688
+ super(n); // Call parent constructor
258
689
  }
259
- ```
260
690
 
261
- ### Global Classes
262
-
263
- ```cssl
264
- // Global class with 'global' keyword
265
- global class SharedClass {
266
- string value;
691
+ void speak() {
692
+ printl(this->name + " says: Woof!");
267
693
  }
268
694
 
269
- // Alternative: @ prefix syntax
270
- class @AnotherShared {
271
- int count;
695
+ void fetch() {
696
+ printl(this->name + " fetches the ball!");
272
697
  }
698
+ }
273
699
 
274
- // Instantiate global class with @ prefix
275
- instance = new @SharedClass();
276
- ```
700
+ @dog = new Dog("Buddy");
701
+ dog.speak(); // "Buddy says: Woof!"
702
+ dog.fetch(); // "Buddy fetches the ball!"
703
+ ```
277
704
 
278
- ### Prefix Reference
705
+ ### Super Proxy (v4.8.8)
279
706
 
280
- | Prefix | Name | Usage |
281
- |--------|------|-------|
282
- | `@` | Global/Module | Read global vars, access modules: `@myVar`, `@os.getcwd()` |
283
- | `r@` | Global Ref | Assign to global scope: `r@name = value` |
284
- | `$` | Shared | Access Python objects: `$counter.value` |
285
- | `%` | Captured | Capture value at registration: `%version` |
286
- | `s@` | Self-Ref | Access global structs: `s@Backend.config` |
707
+ ```cssl
708
+ class Parent {
709
+ void greet() {
710
+ printl("Hello from Parent");
711
+ }
712
+ }
287
713
 
288
- ### Shared Objects ($)
714
+ class Child extends Parent {
715
+ void greet() {
716
+ super->greet(); // Call parent method
717
+ printl("Hello from Child");
718
+ }
719
+ }
289
720
 
290
- Access Python objects shared via `CSSL.share()`:
721
+ @c = new Child();
722
+ c.greet();
723
+ // Output:
724
+ // "Hello from Parent"
725
+ // "Hello from Child"
726
+ ```
291
727
 
292
- ```cssl
293
- // Access shared Python object
294
- $counter.value = 100;
295
- $counter.increment();
728
+ ### Destructor (v4.8.8)
296
729
 
297
- // Delete shared object
298
- delete("counter");
299
- ```
730
+ ```cssl
731
+ class Resource {
732
+ constr() {
733
+ printl("Resource acquired");
734
+ }
300
735
 
301
- ### Captured References (%)
736
+ // Destructor
737
+ ~constr() {
738
+ printl("Resource released");
739
+ }
740
+ }
302
741
 
303
- Capture value at registration time:
742
+ @r = new Resource(); // "Resource acquired"
743
+ ~r; // "Resource released"
744
+ // Or: instance::delete(r);
745
+ ```
304
746
 
305
- ```cssl
306
- string version = "1.0";
307
- savedVersion <<== { %version; }
308
- version = "2.0";
309
- printl(savedVersion); // Still "1.0"
310
- ```
747
+ ### Constructor Modifiers (v4.8.8)
311
748
 
312
- ### Class Member Access (this->)
749
+ ```cssl
750
+ class SafeResource {
751
+ // secure - Constructor runs only on exception
752
+ secure constr() {
753
+ printl("Handling error...");
754
+ }
755
+ }
313
756
 
314
- Inside classes, use `this->` to access instance members:
757
+ class ManualInit {
758
+ // callable - Constructor must be manually called
759
+ callable constr() {
760
+ printl("Initialized!");
761
+ }
762
+ }
315
763
 
316
- ```cssl
317
- class Person {
318
- string name;
764
+ @m = new ManualInit(); // NOT initialized
765
+ instance::call_constructor(m); // "Initialized!"
766
+ ```
319
767
 
320
- void setName(string n) {
321
- this->name = n; // Instance member
322
- }
323
- }
324
- ```
325
-
326
- ---
327
-
328
- ## Operators
329
-
330
- ### Arithmetic
331
-
332
- | Operator | Description | Example |
333
- |----------|-------------|---------|
334
- | `+` | Addition / Concatenation | `a + b` |
335
- | `-` | Subtraction | `a - b` |
336
- | `*` | Multiplication | `a * b` |
337
- | `/` | Division | `a / b` |
338
- | `%` | Modulo | `a % b` |
339
-
340
- ### Comparison
341
-
342
- | Operator | Description | Example |
343
- |----------|-------------|---------|
344
- | `==` | Equal | `a == b` |
345
- | `!=` | Not equal | `a != b` |
346
- | `<` | Less than | `a < b` |
347
- | `>` | Greater than | `a > b` |
348
- | `<=` | Less or equal | `a <= b` |
349
- | `>=` | Greater or equal | `a >= b` |
350
-
351
- ### Logical
352
-
353
- | Operator | Description | Example |
354
- |----------|-------------|---------|
355
- | `&&` | AND | `a && b` |
356
- | `\|\|` | OR | `a \|\| b` |
357
- | `!` | NOT | `!a` |
358
- | `and` | AND (keyword) | `a and b` |
359
- | `or` | OR (keyword) | `a or b` |
360
- | `not` | NOT (keyword) | `not a` |
361
-
362
- ### Increment/Decrement (in for-loops)
363
-
364
- | Operator | Description | Example |
365
- |----------|-------------|---------|
366
- | `++` | Increment | `i++` |
367
- | `--` | Decrement | `i--` |
368
- | `+=` | Add assign | `i += 1` |
369
- | `-=` | Subtract assign | `i -= 1` |
370
-
371
- ---
372
-
373
- ## Control Flow
374
-
375
- ### If / Else If / Else
376
-
377
- ```cssl
378
- if (x < 5) {
379
- printl("Small");
380
- } else if (x < 15) {
381
- printl("Medium");
382
- } else {
383
- printl("Large");
384
- }
768
+ ### Global/Embedded Classes
385
769
 
386
- // elif also works
387
- if (x < 5) {
388
- printl("Small");
389
- } elif (x < 15) {
390
- printl("Medium");
391
- }
392
- ```
393
-
394
- ### Switch / Case
395
-
396
- ```cssl
397
- switch (day) {
398
- case 1:
399
- printl("Monday");
400
- break;
401
- case 2:
402
- printl("Tuesday");
403
- break;
404
- default:
405
- printl("Other");
406
- }
407
- ```
408
-
409
- ### Parameter Switch (Open Params)
410
-
411
- Pattern matching on which named parameters were provided to a function.
412
-
413
- ```cssl
414
- define greet(...) {
415
- switch (open) {
416
- case name & age:
417
- printl("Hello " + OpenFind<string, "name"> + ", age " + OpenFind<int, "age">);
418
- case name:
419
- printl("Hello " + OpenFind<string, "name">);
420
- except name:
421
- printl("No name provided!");
422
- default:
423
- printl("Unknown parameters");
424
- always:
425
- printl("-- greeting complete --");
426
- finally:
427
- printl("== cleanup ==");
428
- }
770
+ ```cssl
771
+ // Global class - accessible everywhere
772
+ global class GlobalHelper {
773
+ static void help() {
774
+ printl("Help!");
429
775
  }
776
+ }
430
777
 
431
- greet(name="Alice"); // case name matches
432
- greet(name="Bob", age=25); // case name & age matches
433
- greet(foo="bar"); // except name matches (no name)
434
- ```
778
+ // Embedded class - auto-replaces target
779
+ embedded class @TargetClass {
780
+ // Replaces TargetClass
781
+ }
782
+ ```
435
783
 
436
- **Syntax:**
437
- - `case param:` - executes if parameter exists
438
- - `case param1 & param2:` - executes if ALL parameters exist
439
- - `case param1 & not param2:` - AND with negation
440
- - `except param:` - executes if parameter does NOT exist
441
- - `default:` - executes if no case matched
442
- - `always:` - executes after any matching case (not after except/default)
443
- - `finally:` - always executes (cleanup, like try/finally)
784
+ ---
444
785
 
445
- > **Note:** Cases are checked in order. Place more specific cases first (`case name & age` before `case name`).
786
+ ## Namespaces
446
787
 
447
- ### While Loop
788
+ ### Basic Namespace
448
789
 
449
- ```cssl
450
- int i = 0;
451
- while (i < 5) {
452
- printl(i);
453
- i = i + 1;
790
+ ```cssl
791
+ namespace utils {
792
+ void log(string msg) {
793
+ printl("[LOG] " + msg);
454
794
  }
455
- ```
456
795
 
457
- ### For Loop (Python-Style)
458
-
459
- ```cssl
460
- // Range-based
461
- for (i in range(5)) {
462
- printl(i); // 0, 1, 2, 3, 4
796
+ int add(int a, int b) {
797
+ return a + b;
463
798
  }
464
799
 
465
- // With start and end
466
- for (i in range(10, 15)) {
467
- printl(i); // 10, 11, 12, 13, 14
800
+ class Helper {
801
+ void assist() {
802
+ printl("Helping!");
803
+ }
468
804
  }
805
+ }
469
806
 
470
- // With step
471
- for (i in range(0, 10, 2)) {
472
- printl(i); // 0, 2, 4, 6, 8
473
- }
474
- ```
807
+ // Usage
808
+ utils::log("Hello"); // "[LOG] Hello"
809
+ int sum = utils::add(1, 2); // 3
810
+ @h = new utils::Helper();
811
+ h.assist(); // "Helping!"
812
+ ```
475
813
 
476
- ### For Loop (C-Style)
814
+ ### Nested Namespaces
477
815
 
478
- ```cssl
479
- for (int i = 0; i < 10; i++) {
480
- printl(i);
816
+ ```cssl
817
+ namespace app {
818
+ namespace core {
819
+ namespace utils {
820
+ void helper() {
821
+ printl("Deep helper");
822
+ }
823
+ }
481
824
  }
825
+ }
482
826
 
483
- for (int i = 10; i > 0; i--) {
484
- printl(i);
485
- }
486
- ```
827
+ app::core::utils::helper(); // "Deep helper"
828
+ ```
487
829
 
488
- ### Foreach
830
+ ---
489
831
 
490
- ```cssl
491
- stack<string> names;
492
- names.push("Alice");
493
- names.push("Bob");
832
+ ## Enums & Structs
494
833
 
495
- // Syntax 1
496
- foreach (name in names) {
497
- printl(name);
498
- }
834
+ ### Enums
499
835
 
500
- // Syntax 2
501
- foreach names as name {
502
- printl(name);
503
- }
504
- ```
836
+ ```cssl
837
+ enum Color {
838
+ RED = 0,
839
+ GREEN = 1,
840
+ BLUE = 2
841
+ }
505
842
 
506
- ### Break & Continue
843
+ enum Status {
844
+ PENDING, // 0
845
+ ACTIVE, // 1
846
+ COMPLETED // 2
847
+ }
507
848
 
508
- ```cssl
509
- for (i in range(10)) {
510
- if (i == 5) break; // Exit loop
511
- if (i == 3) continue; // Skip iteration
512
- printl(i);
513
- }
514
- ```
849
+ int c = Color.RED; // 0
850
+ int s = Status.ACTIVE; // 1
515
851
 
516
- ---
852
+ // Embedded enum (replaces target)
853
+ embedded enum @TargetEnum {
854
+ NEW_VALUE = 100
855
+ }
856
+ ```
517
857
 
518
- ## Functions
858
+ ### Structs
519
859
 
520
- ### Basic Syntax
860
+ ```cssl
861
+ struct Point {
862
+ x: 0,
863
+ y: 0,
864
+ name: "origin"
865
+ }
521
866
 
522
- ```cssl
523
- // Without return
524
- void sayHello() {
525
- printl("Hello!");
526
- }
867
+ struct Config {
868
+ host: "localhost",
869
+ port: 8080,
870
+ ssl: false
871
+ }
527
872
 
528
- // With return
529
- string getName() {
530
- return "CSSL";
531
- }
873
+ // Access struct
874
+ printl(Point.x); // 0
875
+ printl(Config.host); // "localhost"
532
876
 
533
- // With parameters
534
- int add(int a, int b) {
535
- return a + b;
536
- }
537
- ```
877
+ // Global struct reference
878
+ s@Config.port = 9000; // Modify global struct
879
+ ```
538
880
 
539
- ### Define Functions
881
+ ---
540
882
 
541
- ```cssl
542
- // Simple function without type
543
- define greet() {
544
- printl("Hello!");
545
- }
883
+ ## Container Types
546
884
 
547
- // With parameters
548
- define greet(string name) {
549
- printl("Hello " + name);
550
- }
551
- ```
552
-
553
- ### Function Modifiers
554
-
555
- | Modifier | Description |
556
- |----------|-------------|
557
- | `undefined` | Silently ignore errors |
558
- | `closed` | Block external CodeInfusion |
559
- | `private` | Block all CodeInfusion |
560
- | `virtual` | Import-cycle safe |
561
- | `meta` | Source function (any return type allowed) |
562
- | `super` | Force execution (no exceptions) |
563
- | `open` | Accept any parameters |
564
- | `shuffled` | Return multiple values |
565
- | `const` | Immutable function (like C++) |
566
- | `static` | Static method/function |
567
- | `public` | Explicitly public (default) |
568
- | `global` | Makes function globally accessible |
569
-
570
- **Flexible Modifier Order**: Modifiers can appear in any order before the function declaration.
571
-
572
- ```cssl
573
- // Ignore errors
574
- undefined void mayFail() {
575
- riskyOperation();
576
- }
885
+ ### Stack
577
886
 
578
- // Protected from injection
579
- closed void protected() {
580
- printl("Protected");
581
- }
887
+ ```cssl
888
+ stack<string> names;
889
+ names.push("Alice");
890
+ names.push("Bob");
891
+
892
+ string top = names.pop(); // "Bob"
893
+ string peek = names.peek(); // "Alice"
894
+ int size = names.size(); // 1
895
+ bool empty = names.empty(); // false
896
+ ```
897
+
898
+ ### Vector
899
+
900
+ ```cssl
901
+ vector<int> nums;
902
+ nums.push_back(1);
903
+ nums.push_back(2);
904
+ nums.push_back(3);
905
+
906
+ int first = nums[0]; // 1
907
+ int size = nums.size(); // 3
908
+ nums.insert(1, 10); // [1, 10, 2, 3]
909
+ nums.erase(2); // [1, 10, 3]
910
+ nums.clear(); // []
911
+ ```
912
+
913
+ ### Array
914
+
915
+ ```cssl
916
+ array<float> values;
917
+ values.push(1.0);
918
+ values.push(2.0);
919
+
920
+ float v = values.get(0); // 1.0
921
+ values.set(0, 5.0); // [5.0, 2.0]
922
+ ```
923
+
924
+ ### Map
925
+
926
+ ```cssl
927
+ map<string, int> ages;
928
+ ages.set("Alice", 25);
929
+ ages.set("Bob", 30);
930
+
931
+ int age = ages.get("Alice"); // 25
932
+ bool has = ages.has("Charlie"); // false
933
+ list keys = ages.keys(); // ["Alice", "Bob"]
934
+ list vals = ages.values(); // [25, 30]
935
+ ```
936
+
937
+ ### Queue (v4.7)
938
+
939
+ ```cssl
940
+ queue<int> tasks;
941
+ tasks.enqueue(1);
942
+ tasks.enqueue(2);
943
+ tasks.enqueue(3);
944
+
945
+ int first = tasks.dequeue(); // 1
946
+ int peek = tasks.peek(); // 2
947
+ int size = tasks.size(); // 2
948
+ bool empty = tasks.empty(); // false
949
+ tasks.clear(); // []
950
+ ```
951
+
952
+ ### DataStruct (Universal Container)
953
+
954
+ ```cssl
955
+ datastruct<dynamic> data;
956
+ data.add("text");
957
+ data.add(42);
958
+ data.add(true);
959
+
960
+ // Access by index
961
+ printl(data[0]); // "text"
962
+
963
+ // As lazy declarator
964
+ datastruct<string> lazy;
965
+ lazy.declare("key", "value");
966
+ printl(lazy.get("key")); // "value"
967
+ ```
968
+
969
+ ### Iterator
970
+
971
+ ```cssl
972
+ iterator<int> it = range(5);
973
+
974
+ while (it.has_next()) {
975
+ printl(it.next());
976
+ }
977
+
978
+ // With task
979
+ iterator<int> taskIt;
980
+ taskIt.add_task(lambda x: x * 2);
981
+ taskIt.set_data([1, 2, 3]);
982
+ // Results: [2, 4, 6]
983
+ ```
984
+
985
+ ### List & Dict
986
+
987
+ ```cssl
988
+ // Python-style list
989
+ list items = [1, 2, 3, 4, 5];
990
+ items.append(6);
991
+ items.remove(3);
992
+ int first = items[0];
993
+
994
+ // Python-style dict
995
+ dict config = {
996
+ "host": "localhost",
997
+ "port": 8080
998
+ };
999
+ config["ssl"] = true;
1000
+ printl(config["host"]);
1001
+ ```
1002
+
1003
+ ---
1004
+
1005
+ ## Built-in Functions
1006
+
1007
+ ### Output Functions
1008
+
1009
+ ```cssl
1010
+ print("no newline");
1011
+ printl("with newline");
1012
+ println("alias for printl");
1013
+ debug("debug message"); // [DEBUG] prefix
1014
+ error("error message"); // [ERROR] prefix
1015
+ warn("warning"); // [WARN] prefix
1016
+ log("CUSTOM", "message"); // [CUSTOM] prefix
1017
+ ```
1018
+
1019
+ ### String Functions
1020
+
1021
+ ```cssl
1022
+ len("hello"); // 5
1023
+ upper("hello"); // "HELLO"
1024
+ lower("HELLO"); // "hello"
1025
+ trim(" text "); // "text"
1026
+ split("a,b,c", ","); // ["a", "b", "c"]
1027
+ join(["a", "b"], "-"); // "a-b"
1028
+ replace("hello", "l", "x"); // "hexxo"
1029
+ substr("hello", 1, 3); // "ell"
1030
+ contains("hello", "ell"); // true
1031
+ startswith("hello", "he"); // true
1032
+ endswith("hello", "lo"); // true
1033
+ indexof("hello", "l"); // 2
1034
+ format("Hello {}!", "World"); // "Hello World!"
1035
+ repeat("ab", 3); // "ababab"
1036
+ reverse("hello"); // "olleh"
1037
+ capitalize("hello"); // "Hello"
1038
+ title("hello world"); // "Hello World"
1039
+ padleft("42", 5, "0"); // "00042"
1040
+ padright("42", 5, "0"); // "42000"
1041
+ ord("A"); // 65
1042
+ chr(65); // "A"
1043
+ isalpha("abc"); // true
1044
+ isdigit("123"); // true
1045
+ ```
1046
+
1047
+ ### List Functions
1048
+
1049
+ ```cssl
1050
+ push(list, item); // Add to end
1051
+ pop(list); // Remove from end
1052
+ shift(list); // Remove from start
1053
+ unshift(list, item); // Add to start
1054
+ slice(list, 1, 3); // Sublist
1055
+ sort(list); // Sort ascending
1056
+ rsort(list); // Sort descending
1057
+ unique(list); // Remove duplicates
1058
+ flatten([[1], [2, 3]]); // [1, 2, 3]
1059
+ filter(list, func); // Filter elements
1060
+ map(list, func); // Transform elements
1061
+ reduce(list, func, init); // Reduce to single value
1062
+ find(list, value); // Find first match
1063
+ findindex(list, value); // Find index
1064
+ every(list, func); // All match?
1065
+ some(list, func); // Any match?
1066
+ range(5); // [0, 1, 2, 3, 4]
1067
+ range(1, 5); // [1, 2, 3, 4]
1068
+ range(0, 10, 2); // [0, 2, 4, 6, 8]
1069
+ enumerate(list); // [[0, a], [1, b], ...]
1070
+ zip(list1, list2); // Pair elements
1071
+ reversed(list); // Reverse copy
1072
+ sorted(list); // Sorted copy
1073
+ count(list, value); // Count occurrences
1074
+ first(list); // First element
1075
+ last(list); // Last element
1076
+ take(list, n); // First n elements
1077
+ drop(list, n); // All except first n
1078
+ chunk(list, size); // Split into chunks
1079
+ shuffle(list); // Randomize order
1080
+ sample(list, n); // Random n elements
1081
+ ```
1082
+
1083
+ ### Dictionary Functions
1084
+
1085
+ ```cssl
1086
+ keys(dict); // Get keys
1087
+ values(dict); // Get values
1088
+ items(dict); // Get key-value pairs
1089
+ haskey(dict, "key"); // Check key exists
1090
+ getkey(dict, "key", default); // Get with default
1091
+ setkey(dict, "key", value); // Set key
1092
+ delkey(dict, "key"); // Delete key
1093
+ merge(dict1, dict2); // Merge dictionaries
1094
+ update(dict1, dict2); // Update in place
1095
+ fromkeys(["a", "b"], 0); // {"a": 0, "b": 0}
1096
+ invert(dict); // Swap keys/values
1097
+ pick(dict, ["key1", "key2"]); // Select keys
1098
+ omit(dict, ["key1"]); // Exclude keys
1099
+ ```
1100
+
1101
+ ### Math Functions
1102
+
1103
+ ```cssl
1104
+ abs(-5); // 5
1105
+ min(1, 2, 3); // 1
1106
+ max(1, 2, 3); // 3
1107
+ sum([1, 2, 3]); // 6
1108
+ avg([1, 2, 3]); // 2.0
1109
+ round(3.7); // 4
1110
+ floor(3.7); // 3
1111
+ ceil(3.2); // 4
1112
+ pow(2, 3); // 8
1113
+ sqrt(16); // 4.0
1114
+ mod(7, 3); // 1
1115
+ random(); // 0.0-1.0
1116
+ randint(1, 10); // 1-10
1117
+ sin(0); // 0.0
1118
+ cos(0); // 1.0
1119
+ tan(0); // 0.0
1120
+ asin(0); // 0.0
1121
+ acos(1); // 0.0
1122
+ atan(0); // 0.0
1123
+ atan2(1, 1); // 0.785...
1124
+ exp(1); // 2.718...
1125
+ log(10); // 2.302...
1126
+ log10(100); // 2.0
1127
+ radians(180); // 3.14159...
1128
+ degrees(3.14159); // ~180
1129
+
1130
+ // Constants
1131
+ pi; // 3.14159...
1132
+ e; // 2.71828...
1133
+ ```
1134
+
1135
+ ### Time/Date Functions
1136
+
1137
+ ```cssl
1138
+ now(); // Current timestamp
1139
+ timestamp(); // Unix timestamp
1140
+ sleep(1000); // Sleep 1 second (ms)
1141
+ delay(500); // Delay 500ms
1142
+ date(); // Current date string
1143
+ time(); // Current time string
1144
+ datetime(); // Full datetime
1145
+ strftime("%Y-%m-%d"); // Format time
1146
+ CurrentTime; // Alternative current time
1147
+ ```
1148
+
1149
+ ### File Functions
1150
+
1151
+ ```cssl
1152
+ pathexists("file.txt"); // Check exists
1153
+ exists("file.txt"); // Alias
1154
+ isfile("file.txt"); // Is file?
1155
+ isdir("folder"); // Is directory?
1156
+ basename("/path/file.txt"); // "file.txt"
1157
+ dirname("/path/file.txt"); // "/path"
1158
+ joinpath("dir", "file.txt"); // "dir/file.txt"
1159
+ abspath("relative"); // Full path
1160
+ normpath("a//b/../c"); // "a/c"
1161
+
1162
+ readfile("file.txt"); // Read entire file
1163
+ writefile("file.txt", "data"); // Write file
1164
+ appendfile("file.txt", "more"); // Append to file
1165
+ readlines("file.txt"); // Read as lines
1166
+
1167
+ listdir("folder"); // List directory
1168
+ makedirs("a/b/c"); // Create nested dirs
1169
+ removefile("file.txt"); // Delete file
1170
+ removedir("folder"); // Delete empty dir
1171
+ copyfile("src", "dst"); // Copy file
1172
+ movefile("src", "dst"); // Move file
1173
+ rename("old", "new"); // Rename
1174
+ filesize("file.txt"); // Get size in bytes
1175
+ ```
1176
+
1177
+ ### JSON Functions
1178
+
1179
+ ```cssl
1180
+ tojson({"a": 1}); // '{"a": 1}'
1181
+ fromjson('{"a": 1}'); // {"a": 1}
1182
+ json::read("file.json"); // Read JSON file
1183
+ json::write("file.json", data); // Write JSON file
1184
+ json::parse(str); // Parse JSON string
1185
+ json::stringify(obj); // Stringify object
1186
+ json::pretty(obj); // Pretty print
1187
+ json::keys(obj); // Get keys
1188
+ json::values(obj); // Get values
1189
+ json::get(obj, "key"); // Get nested value
1190
+ json::set(obj, "key", value); // Set nested value
1191
+ json::has(obj, "key"); // Check key exists
1192
+ json::merge(obj1, obj2); // Merge objects
1193
+ ```
1194
+
1195
+ ### Hash Functions
1196
+
1197
+ ```cssl
1198
+ md5("text"); // MD5 hash
1199
+ sha1("text"); // SHA-1 hash
1200
+ sha256("text"); // SHA-256 hash
1201
+ ```
1202
+
1203
+ ### Regex Functions
1204
+
1205
+ ```cssl
1206
+ match("hello123", "\\d+"); // "123"
1207
+ search("hello123world", "\\d+"); // Match object
1208
+ findall("a1b2c3", "\\d"); // ["1", "2", "3"]
1209
+ sub("hello123", "\\d+", "XXX"); // "helloXXX"
1210
+ ```
1211
+
1212
+ ### System Functions
1213
+
1214
+ ```cssl
1215
+ getcwd(); // Current working directory
1216
+ chdir("path"); // Change directory
1217
+ mkdir("folder"); // Create directory
1218
+ rmdir("folder"); // Remove directory
1219
+ clear(); // Clear screen
1220
+ cls(); // Alias for clear
1221
+ env("HOME"); // Get env variable
1222
+ setenv("VAR", "value"); // Set env variable
1223
+ exit(0); // Exit with code
1224
+ platform(); // "Windows", "Linux", etc.
1225
+ version(); // Python version
1226
+ argv(); // Command line args
1227
+ argc(); // Argument count
1228
+ isLinux(); // true if Linux
1229
+ isWindows(); // true if Windows
1230
+ isMac(); // true if macOS
1231
+ ```
1232
+
1233
+ ### Color Functions (v4.6.5)
1234
+
1235
+ ```cssl
1236
+ // Named colors
1237
+ red("error text");
1238
+ green("success text");
1239
+ blue("info text");
1240
+ yellow("warning text");
1241
+ cyan("note text");
1242
+ magenta("special text");
1243
+ white("white text");
1244
+ black("black text");
1245
+
1246
+ // Bright variants
1247
+ bright_red("bright error");
1248
+ bright_green("bright success");
1249
+ // ... and more
1250
+
1251
+ // Background colors
1252
+ bg_red("red background");
1253
+ bg_blue("blue background");
1254
+ bg_rgb(255, 200, 0, "custom bg");
1255
+
1256
+ // RGB color
1257
+ rgb(255, 128, 0, "orange text");
1258
+
1259
+ // Styles
1260
+ bold("bold text");
1261
+ italic("italic text");
1262
+ underline("underlined");
1263
+ dim("dimmed text");
1264
+ blink("blinking");
1265
+ strikethrough("crossed out");
1266
+ reset(); // Reset all styles
1267
+
1268
+ // In f-strings
1269
+ printl(f"{red('Error:')} {bold('Something failed')}");
1270
+ ```
1271
+
1272
+ ### Instance Functions
1273
+
1274
+ ```cssl
1275
+ instance::getMethods(obj); // Get all methods
1276
+ instance::getClasses(obj); // Get all classes
1277
+ instance::getVars(obj); // Get all variables
1278
+ instance::getAll(obj); // Get all members
1279
+ instance::call(obj, "method"); // Call method
1280
+ instance::has(obj, "member"); // Check member exists
1281
+ instance::type(obj); // Get type name
1282
+ instance::exists(obj); // Check if valid
1283
+ instance::isavailable(obj); // Alias
1284
+ instance::delete(obj); // Call destructor (v4.8.8)
1285
+ instance::call_constructor(obj);// Manual init (v4.8.8)
1286
+ ```
1287
+
1288
+ ### Watcher Functions (v4.6.5)
1289
+
1290
+ ```cssl
1291
+ watcher::get(name); // Get live Python instance value
1292
+ watcher::set(name, val); // Set live Python instance value
1293
+ watcher::list(); // List all watched instances
1294
+ watcher::exists(name); // Check if watcher exists
1295
+ watcher::refresh(name); // Refresh watched instance
1296
+ ```
1297
+
1298
+ ---
1299
+
1300
+ ## CodeInfusion
1301
+
1302
+ CodeInfusion allows injecting code into existing functions.
1303
+
1304
+ ### Basic Code Infusion
1305
+
1306
+ ```cssl
1307
+ define original() {
1308
+ printl("Original behavior");
1309
+ }
1310
+
1311
+ // Replace with new code (<<==)
1312
+ original <<== {
1313
+ printl("New behavior");
1314
+ }
1315
+
1316
+ original(); // "New behavior"
1317
+ ```
1318
+
1319
+ ### Add to Existing (Keep Original)
1320
+
1321
+ ```cssl
1322
+ define myFunc() {
1323
+ printl("Original");
1324
+ }
582
1325
 
583
- // Multiple returns
584
- shuffled string getNames() {
585
- return "Alice", "Bob", "Charlie";
586
- }
1326
+ // Add code before original (+<<==)
1327
+ myFunc +<<== {
1328
+ printl("Before");
1329
+ }
587
1330
 
588
- a, b, c = getNames();
1331
+ myFunc();
1332
+ // Output:
1333
+ // "Before"
1334
+ // "Original"
1335
+ ```
589
1336
 
590
- // Any order of modifiers works
591
- private string *@Myfunc() {
592
- println("Hello from global private non-null function!");
593
- return "Hey";
594
- }
1337
+ ### Using Captured Values
595
1338
 
596
- // Const function
597
- const void immutableFunc() {
598
- printl("I'm constant");
599
- }
1339
+ ```cssl
1340
+ define logger(string msg) {
1341
+ printl(msg);
1342
+ }
600
1343
 
601
- // Global private const
602
- global private const void @MyGlobalFunc() {
603
- printl("Complex modifiers in any order");
604
- }
605
- ```
1344
+ // Override with access to original via %
1345
+ logger <<== {
1346
+ printl("[LOG] " + args[0]);
1347
+ %logger(args[0]); // Call original
1348
+ }
1349
+ ```
606
1350
 
607
- ### Typed Functions (Enforced Returns)
1351
+ ---
608
1352
 
609
- Functions with a return type (like `int`, `string`, `vector<T>`) MUST return that type:
1353
+ ## BruteInjection
610
1354
 
611
- ```cssl
612
- // MUST return string
613
- string getName() {
614
- return "Alice"; // OK
615
- // return 42; // Error! Expected string
616
- }
1355
+ BruteInjection allows value/function injection with powerful filtering.
617
1356
 
618
- // MUST return int
619
- int getAge() {
620
- return 30; // OK
621
- }
1357
+ ### Basic Injection
622
1358
 
623
- // meta modifier bypasses type checking
624
- meta datastruct<string> getData() {
625
- return "just a string"; // OK despite declared type
626
- return 42; // Also OK - meta allows any type
627
- }
628
- ```
1359
+ ```cssl
1360
+ // Replace value
1361
+ target <== source;
629
1362
 
630
- ### Non-Null Functions (*)
1363
+ // Right injection
1364
+ source ==> target;
1365
+ ```
631
1366
 
632
- Functions that must never return null:
1367
+ ### Copy & Add
633
1368
 
634
- ```cssl
635
- // Non-null function
636
- define *alwaysReturns() {
637
- return "Always a value";
638
- }
1369
+ ```cssl
1370
+ // Keep old + add new
1371
+ target +<== newValue;
1372
+ ```
639
1373
 
640
- // Non-null assertion on value
641
- this->name = *$System.os; // Error if null
642
- ```
1374
+ ### Move & Remove
643
1375
 
644
- ### Type Exclusion Filter (*[type])
1376
+ ```cssl
1377
+ // Move and remove original
1378
+ target -<== source;
1379
+ ```
645
1380
 
646
- Functions that must NOT return a specific type:
1381
+ ### Injection Filters
647
1382
 
648
- ```cssl
649
- // Must NOT return string
650
- shuffled *[string] getNumbers() {
651
- return 1, 2, 3; // OK
652
- // return "text"; // Error!
653
- }
1383
+ ```cssl
1384
+ // Integer filter
1385
+ result [integer::gt=5] <== numbers; // Greater than 5
1386
+ result [integer::lt=10] <== numbers; // Less than 10
1387
+ result [integer::range=1,100] <== nums; // Range 1-100
654
1388
 
655
- // Must NOT return null
656
- define *[null] getValue() {
657
- return 42; // OK
658
- }
659
- ```
1389
+ // String filter
1390
+ result [string::startswith="test"] <== strings;
1391
+ result [string::contains="key"] <== strings;
1392
+ result [string::where="abc"] <== strings;
660
1393
 
661
- ### Open Parameters
1394
+ // JSON filter
1395
+ result [json::has="key"] <== objects;
1396
+ result [json::where="key=value"] <== objects;
662
1397
 
663
- ```cssl
664
- open define flexibleFunc(open Params) {
665
- string name = OpenFind<string>(0);
666
- int num = OpenFind<int>(0);
667
- printl(name + " " + num);
668
- }
1398
+ // Type filter
1399
+ result [type::filter=string] <== mixed; // Only strings
669
1400
 
670
- flexibleFunc("Hello", 123, true);
671
- ```
1401
+ // Custom filter
1402
+ register_filter("mytype", "myhelper", func);
1403
+ result [mytype::myhelper=value] <== data;
1404
+ ```
672
1405
 
673
- ---
1406
+ ---
674
1407
 
675
- ## Classes & OOP
1408
+ ## Snapshot System
676
1409
 
677
- ### Class Definition
1410
+ The Snapshot system (v4.8.8) allows capturing and restoring variable states.
678
1411
 
679
- ```cssl
680
- class Person {
681
- string name;
682
- int age;
1412
+ ### Basic Snapshots
683
1413
 
684
- // Constructor
685
- void Person(string n, int a) {
686
- this->name = n;
687
- this->age = a;
688
- }
1414
+ ```cssl
1415
+ string version = "1.0";
1416
+ snapshot(version); // Capture current value
689
1417
 
690
- void greet() {
691
- printl("Hello, I'm " + this->name);
692
- }
1418
+ version = "2.0"; // Modify
693
1419
 
694
- string getName() {
695
- return this->name;
696
- }
697
- }
698
- ```
1420
+ printl(version); // "2.0"
1421
+ printl(%version); // "1.0" (snapshotted value)
1422
+ ```
699
1423
 
700
- ### Creating Instances
1424
+ ### Named Snapshots
701
1425
 
702
- ```cssl
703
- Person p = new Person("Alice", 30);
704
- p.greet();
705
- printl(p.name);
706
- ```
1426
+ ```cssl
1427
+ int counter = 100;
1428
+ snapshot(counter, "backup"); // Custom name
707
1429
 
708
- ### Constructor with `constr` Keyword
1430
+ counter = 500;
709
1431
 
710
- ```cssl
711
- class Vehicle {
712
- string brand;
1432
+ printl(get_snapshot("backup")); // 100
1433
+ ```
713
1434
 
714
- constr Initialize(string b) {
715
- this->brand = b;
716
- }
1435
+ ### Snapshot Functions
717
1436
 
718
- constr SetupDefaults() {
719
- printl("Vehicle ready");
720
- }
721
- }
1437
+ ```cssl
1438
+ // Capture
1439
+ snapshot(variable); // Auto-name
1440
+ snapshot(variable, "name"); // Custom name
722
1441
 
723
- Vehicle v = new Vehicle("Toyota");
724
- ```
1442
+ // Retrieve
1443
+ get_snapshot("name"); // Get value
1444
+ %name; // Shorthand access
725
1445
 
726
- ### Class Inheritance
1446
+ // Check
1447
+ has_snapshot("name"); // true/false
1448
+ list_snapshots(); // ["name1", "name2", ...]
727
1449
 
728
- ```cssl
729
- class Animal {
730
- string name;
1450
+ // Manage
1451
+ clear_snapshot("name"); // Delete one
1452
+ clear_snapshots(); // Delete all
1453
+ restore_snapshot("name"); // Restore to current
731
1454
 
732
- void Animal(string n) {
733
- this->name = n;
734
- }
1455
+ // Function snapshots
1456
+ snapshot(printl); // Capture function
1457
+ embedded define override &printl {
1458
+ %printl("Prefix: " + args[0]); // Call original
1459
+ }
1460
+ ```
735
1461
 
736
- void speak() {
737
- printl("Sound");
738
- }
739
- }
1462
+ ### Direct Snapshot Assignment (v4.8.9)
740
1463
 
741
- class Dog : extends Animal {
742
- void Dog(string n) {
743
- this->name = n;
744
- }
1464
+ Assign values directly to snapshots using the `%name = value` syntax:
745
1465
 
746
- void speak() {
747
- printl("Woof! I'm " + this->name);
748
- }
749
- }
1466
+ ```cssl
1467
+ // Assign variable value to snapshot
1468
+ string greeting = "Hello";
1469
+ %savedGreeting = greeting; // Snapshot now holds "Hello"
750
1470
 
751
- Dog d = new Dog("Buddy");
752
- d.speak(); // "Woof! I'm Buddy"
753
- ```
1471
+ // Assign literal directly
1472
+ %message = "World"; // Create snapshot with literal
754
1473
 
755
- ### super() and super::method()
1474
+ // Typed expression assignment
1475
+ %config = (int maxRetries = 3); // Creates variable AND snapshot
1476
+ // Now 'maxRetries' = 3 and '%config' = 3
756
1477
 
757
- ```cssl
758
- class Child : extends Parent {
759
- constr ChildInit(string name) {
760
- super(name); // Call parent constructor
761
- }
1478
+ // Call snapshotted function
1479
+ %savedGreeting = somefunc;
1480
+ %savedGreeting(); // Call the snapshotted function
1481
+ ```
762
1482
 
763
- void speak() {
764
- super::speak(); // Call parent method
765
- printl("Child speaking");
766
- }
767
- }
768
- ```
1483
+ ---
769
1484
 
770
- ### Append Mode (++)
1485
+ ## C++ I/O Streams
771
1486
 
772
- Extend constructors/functions while keeping original code:
1487
+ CSSL supports C++ style I/O streams (v4.8.4).
773
1488
 
774
- ```cssl
775
- // Original function
776
- define BaseFunc() {
777
- printl("Base functionality");
778
- }
1489
+ ### Standard Streams
779
1490
 
780
- // Append to BaseFunc
781
- define ExtendedFunc() &BaseFunc ++ {
782
- printl("Extended functionality");
783
- }
1491
+ ```cssl
1492
+ // Output
1493
+ cout << "Hello";
1494
+ cout << " World" << endl;
784
1495
 
785
- ExtendedFunc();
786
- // Output:
787
- // Base functionality
788
- // Extended functionality
789
- ```
790
-
791
- ```cssl
792
- class MyClass {
793
- constr MyClassConstructor() {
794
- printl("MyClass constructor");
795
- this->value = 10;
796
- }
797
- }
1496
+ // Error output
1497
+ cerr << "Error message" << endl;
798
1498
 
799
- class BetterClass :: extends MyClass {
800
- constr BetterConstructor() &MyClass::MyClassConstructor ++ {
801
- printl("BetterClass - added code");
802
- this->extra = 20;
803
- }
804
- }
805
- ```
1499
+ // Log output
1500
+ clog << "Log message" << endl;
806
1501
 
807
- ### Non-Null Class
1502
+ // Input
1503
+ string name;
1504
+ cout << "Enter name: ";
1505
+ cin >> name;
808
1506
 
809
- ```cssl
810
- class *MyClass {
811
- // All methods must return non-null
812
- string getValue() {
813
- return "Value";
814
- }
815
- }
816
- ```
817
-
818
- ---
819
-
820
- ## Container Types
821
-
822
- ### stack\<T\> - LIFO Stack
823
-
824
- ```cssl
825
- stack<string> names;
826
- names.push("Alice");
827
- names.push("Bob");
828
-
829
- printl(names.pop()); // "Bob"
830
- printl(names.peek()); // "Alice" (doesn't remove)
831
- printl(names.size()); // 1
832
- printl(names.isEmpty()); // false
833
- ```
834
-
835
- **Methods:**
836
-
837
- | Method | Description |
838
- |--------|-------------|
839
- | `push(value)` | Add to top |
840
- | `pop()` | Remove and return top |
841
- | `peek()` | View top without removing |
842
- | `size()` / `length()` | Element count |
843
- | `isEmpty()` / `is_empty()` | Check if empty |
844
- | `contains(value)` | Check if contains |
845
- | `indexOf(value)` | Find index (-1 if not found) |
846
- | `toArray()` | Convert to list |
847
- | `swap()` | Swap top two elements |
848
- | `dup()` | Duplicate top element |
849
-
850
- ### vector\<T\> - Dynamic Array
851
-
852
- ```cssl
853
- vector<int> nums;
854
- nums.push(10);
855
- nums.push(20);
856
-
857
- printl(nums.at(0)); // 10
858
- printl(nums.front()); // 10
859
- printl(nums.back()); // 20
860
- ```
861
-
862
- **Methods:**
863
-
864
- | Method | Description |
865
- |--------|-------------|
866
- | `push(value)` / `push_back(value)` | Add to end |
867
- | `push_front(value)` | Add to front |
868
- | `pop_back()` | Remove from end |
869
- | `pop_front()` | Remove from front |
870
- | `at(index)` | Get element |
871
- | `set(index, value)` | Set element |
872
- | `front()` | Get first |
873
- | `back()` | Get last |
874
- | `size()` / `length()` | Element count |
875
- | `empty()` / `isEmpty()` | Check if empty |
876
- | `contains(value)` | Check if contains |
877
- | `indexOf(value)` | Find first index |
878
- | `lastIndexOf(value)` | Find last index |
879
- | `slice(start, end)` | Get sub-vector |
880
- | `join(separator)` | Join to string |
881
- | `map(func)` | Apply function |
882
- | `filter(predicate)` | Filter elements |
883
- | `forEach(func)` | Execute for each |
884
- | `every(predicate)` | Check all match |
885
- | `some(predicate)` | Check any match |
886
- | `reduce(func, initial)` | Reduce to value |
887
- | `toArray()` | Convert to list |
888
-
889
- ### map\<K,V\> - Ordered Key-Value
890
-
891
- ```cssl
892
- map<string, int> ages;
893
- ages.insert("Alice", 30);
894
- ages.insert("Bob", 25);
895
-
896
- printl(ages.find("Alice")); // 30
897
- printl(ages.contains("Bob")); // true
898
- ages.erase("Bob");
899
- ```
900
-
901
- **Methods:**
902
-
903
- | Method | Description |
904
- |--------|-------------|
905
- | `insert(key, value)` | Insert/update pair |
906
- | `find(key)` | Get value (null if not found) |
907
- | `at(key)` | Get value (throws if not found) |
908
- | `erase(key)` | Remove key |
909
- | `contains(key)` | Check if key exists |
910
- | `count(key)` | Count (0 or 1) |
911
- | `size()` | Pair count |
912
- | `empty()` | Check if empty |
913
- | `begin()` | First key-value tuple |
914
- | `end()` | Last key-value tuple |
915
- | `lower_bound(key)` | First key >= given |
916
- | `upper_bound(key)` | First key > given |
917
-
918
- ### datastruct\<T\> - Universal Container
919
-
920
- Primary target for BruteInjection operations.
921
-
922
- ```cssl
923
- datastruct<string> data;
924
- data.add("item1");
925
- data.add("item2");
926
-
927
- printl(data.content()); // All elements
928
- ```
929
-
930
- **Methods:**
931
-
932
- | Method | Description |
933
- |--------|-------------|
934
- | `content()` | Get all elements |
935
- | `add(value)` | Add element |
936
- | `remove_where(predicate)` | Remove matching |
937
- | `find_where(predicate)` | Find first matching |
938
- | `convert(type)` | Convert first element |
939
-
940
- ### shuffled\<T\> - Multiple Returns
941
-
942
- ```cssl
943
- shuffled string getInfo() {
944
- return "Alice", "Bob", "Charlie";
945
- }
1507
+ // Getline
1508
+ string line = getline(cin);
1509
+ ```
946
1510
 
947
- a, b, c = getInfo();
948
- printl(a); // "Alice"
949
- ```
950
-
951
- ---
952
-
953
- ## Built-in Functions
954
-
955
- ### String Operations
956
-
957
- ```cssl
958
- string s = "Hello World";
959
-
960
- // Case
961
- upper(s); // "HELLO WORLD"
962
- lower(s); // "hello world"
963
- capitalize(s); // "Hello world"
964
- title(s); // "Hello World"
965
-
966
- // Trim
967
- trim(" text "); // "text"
968
- ltrim(" text"); // "text"
969
- rtrim("text "); // "text"
970
-
971
- // Search
972
- contains(s, "World"); // true
973
- startswith(s, "Hello"); // true
974
- endswith(s, "World"); // true
975
- indexof(s, "o"); // 4
976
- lastindexof(s, "o"); // 7
977
-
978
- // Manipulation
979
- replace(s, "World", "CSSL"); // "Hello CSSL"
980
- substr(s, 0, 5); // "Hello"
981
- split(s, " "); // ["Hello", "World"]
982
- join("-", ["a", "b"]); // "a-b"
983
- repeat("ab", 3); // "ababab"
984
- reverse(s); // "dlroW olleH"
985
-
986
- // Padding
987
- padleft("42", 5, "0"); // "00042"
988
- padright("42", 5, "."); // "42..."
989
- center("hi", 6, "-"); // "--hi--"
990
- zfill("42", 5); // "00042"
991
-
992
- // Character
993
- len(s); // 11
994
- chars("abc"); // ["a", "b", "c"]
995
- ord("A"); // 65
996
- chr(65); // "A"
997
-
998
- // Checks
999
- isalpha("abc"); // true
1000
- isdigit("123"); // true
1001
- isalnum("abc123"); // true
1002
- isspace(" "); // true
1003
- ```
1004
-
1005
- ### Array/List Operations
1006
-
1007
- ```cssl
1008
- stack<int> arr = [1, 2, 3, 4, 5];
1009
-
1010
- // Add/Remove
1011
- push(arr, 6); // Add to end
1012
- pop(arr); // Remove last
1013
- shift(arr); // Remove first
1014
- unshift(arr, 0); // Add to front
1015
-
1016
- // Access
1017
- first(arr); // First element
1018
- last(arr); // Last element
1019
- slice(arr, 1, 3); // [2, 3]
1020
-
1021
- // Transform
1022
- sort(arr); // Sort ascending
1023
- rsort(arr); // Sort descending
1024
- reversed(arr); // Reverse copy
1025
- shuffle(arr); // Random order
1026
- unique(arr); // Remove duplicates
1027
- flatten([[1,2],[3,4]]); // [1, 2, 3, 4]
1028
-
1029
- // Search
1030
- find(arr, x => x > 3); // First matching
1031
- findindex(arr, x => x > 3);
1032
- every(arr, x => x > 0); // All match?
1033
- some(arr, x => x > 3); // Any match?
1034
- count(arr, 2); // Count of 2
1035
-
1036
- // Functional
1037
- map(arr, x => x * 2); // [2, 4, 6, 8, 10]
1038
- filter(arr, x => x > 2); // [3, 4, 5]
1039
- reduce(arr, (a,b) => a+b, 0); // 15
1040
-
1041
- // Utilities
1042
- range(5); // [0, 1, 2, 3, 4]
1043
- range(1, 5); // [1, 2, 3, 4]
1044
- range(0, 10, 2); // [0, 2, 4, 6, 8]
1045
- enumerate(arr); // [(0,1), (1,2), ...]
1046
- zip([1,2], ["a","b"]); // [(1,"a"), (2,"b")]
1047
- take(arr, 3); // First 3 elements
1048
- drop(arr, 2); // Skip first 2
1049
- chunk(arr, 2); // [[1,2], [3,4], [5]]
1050
- sample(arr, 2); // 2 random elements
1051
- ```
1052
-
1053
- ### Dictionary Operations
1054
-
1055
- ```cssl
1056
- dict d = {"name": "Alice", "age": 30};
1057
-
1058
- keys(d); // ["name", "age"]
1059
- values(d); // ["Alice", 30]
1060
- items(d); // [("name","Alice"), ...]
1061
- haskey(d, "name"); // true
1062
- getkey(d, "name"); // "Alice"
1063
- getkey(d, "x", "default"); // "default"
1064
- setkey(d, "city", "NYC"); // Add key
1065
- delkey(d, "age"); // Remove key
1066
- merge(d1, d2); // Merge dicts
1067
- update(d, {"new": 1}); // Update in place
1068
- fromkeys(["a","b"], 0); // {"a": 0, "b": 0}
1069
- invert({"a": 1}); // {1: "a"}
1070
- pick(d, "name"); // {"name": "Alice"}
1071
- omit(d, "age"); // {"name": "Alice"}
1072
- ```
1073
-
1074
- ### Math Functions
1075
-
1076
- ```cssl
1077
- abs(-5); // 5
1078
- min(3, 1, 2); // 1
1079
- max(3, 1, 2); // 3
1080
- sum([1, 2, 3]); // 6
1081
- avg([1, 2, 3, 4, 5]); // 3.0
1082
-
1083
- round(3.14159, 2); // 3.14
1084
- floor(3.9); // 3
1085
- ceil(3.1); // 4
1086
-
1087
- pow(2, 3); // 8
1088
- sqrt(16); // 4
1089
- mod(7, 3); // 1
1090
-
1091
- sin(0); // 0.0
1092
- cos(0); // 1.0
1093
- tan(0); // 0.0
1094
- asin(1); // 1.5708
1095
- acos(0); // 1.5708
1096
- atan(1); // 0.7854
1097
- atan2(1, 1); // 0.7854
1098
-
1099
- log(e()); // 1.0
1100
- log10(100); // 2.0
1101
- exp(1); // 2.71828
1102
-
1103
- pi(); // 3.14159...
1104
- e(); // 2.71828...
1105
- radians(180); // 3.14159
1106
- degrees(3.14159); // 180
1107
-
1108
- random(); // 0.0 to 1.0
1109
- randint(1, 6); // 1 to 6
1110
- ```
1111
-
1112
- ### Date/Time Functions
1113
-
1114
- ```cssl
1115
- now(); // Unix timestamp (float)
1116
- timestamp(); // Unix timestamp (int)
1117
- date(); // "2025-12-30"
1118
- date("%d/%m/%Y"); // "30/12/2025"
1119
- time(); // "14:30:45"
1120
- datetime(); // "2025-12-30 14:30:45"
1121
- strftime("%Y-%m-%d", ts);
1122
-
1123
- sleep(1.5); // Wait 1.5 seconds
1124
- delay(500); // Wait 500 milliseconds
1125
- ```
1126
-
1127
- ### File I/O Functions
1128
-
1129
- ```cssl
1130
- // Read
1131
- string content = read("file.txt");
1132
- string line5 = readline(5, "file.txt");
1133
- stack<string> lines = readlines("file.txt");
1134
-
1135
- // Write
1136
- write("file.txt", "Hello");
1137
- writeline(3, "New line", "file.txt");
1138
- appendfile("file.txt", "\nMore");
1139
-
1140
- // Path operations
1141
- basename("/path/to/file.txt"); // "file.txt"
1142
- dirname("/path/to/file.txt"); // "/path/to"
1143
- joinpath("/path", "file.txt"); // "/path/file.txt"
1144
- abspath("./file.txt");
1145
- normpath("/path/../other");
1146
-
1147
- // Checks
1148
- pathexists("file.txt"); // true/false
1149
- isfile("file.txt"); // true/false
1150
- isdir("folder"); // true/false
1151
- filesize("file.txt"); // bytes
1152
-
1153
- // Directory
1154
- listdir("./"); // ["file1", "file2"]
1155
- makedirs("new/folder");
1156
- removefile("file.txt");
1157
- removedir("folder");
1158
- copyfile("src", "dst");
1159
- movefile("old", "new");
1160
- ```
1161
-
1162
- ### JSON Functions (json:: namespace)
1163
-
1164
- ```cssl
1165
- // File operations
1166
- json data = json::read("config.json");
1167
- json::write("output.json", data);
1168
-
1169
- // Parse/Stringify
1170
- json obj = json::parse('{"name": "Alice"}');
1171
- string str = json::stringify(obj);
1172
- string pretty = json::pretty(obj);
1173
-
1174
- // Path operations
1175
- json::get(data, "user.name");
1176
- json::get(data, "user.age", 0); // with default
1177
- json::set(data, "user.name", "Bob");
1178
- json::has(data, "user.email");
1179
-
1180
- // Object operations
1181
- json::keys(obj); // ["name"]
1182
- json::values(obj); // ["Alice"]
1183
- json::merge(obj1, obj2); // Deep merge
1184
- ```
1185
-
1186
- ### Instance Functions (instance:: namespace)
1187
-
1188
- ```cssl
1189
- @module = include("lib.cssl-mod");
1190
-
1191
- instance::getMethods(@module); // Method names
1192
- instance::getClasses(@module); // Class names
1193
- instance::getVars(@module); // Variable names
1194
- instance::getAll(@module); // Categorized dict
1195
-
1196
- instance::call(@module, "methodName", arg1);
1197
- instance::has(@module, "attribute");
1198
- instance::type(@module); // Type name
1199
-
1200
- isavailable("sharedName"); // Check if exists
1201
- ```
1202
-
1203
- ### Regex Functions
1204
-
1205
- ```cssl
1206
- match("\\d+", "abc123"); // Match at start
1207
- search("\\d+", "abc123"); // Search anywhere
1208
- findall("\\d+", "a1b2c3"); // ["1", "2", "3"]
1209
- sub("\\d", "X", "a1b2"); // "aXbX"
1210
- sub("\\d", "X", "a1b2", 1); // "aXb2" (count=1)
1211
- ```
1212
-
1213
- ### Hash Functions
1214
-
1215
- ```cssl
1216
- md5("hello"); // 32 hex chars
1217
- sha1("hello"); // 40 hex chars
1218
- sha256("hello"); // 64 hex chars
1219
- ```
1220
-
1221
- ### System Functions
1511
+ ### File Streams
1222
1512
 
1223
- ```cssl
1224
- exit(0); // Exit with code
1225
- input("Enter name: "); // Read user input
1513
+ ```cssl
1514
+ // Write to file
1515
+ @file = ofstream("output.txt");
1516
+ file << "Hello" << endl;
1517
+ file << "World" << endl;
1518
+ file.close();
1226
1519
 
1227
- env("PATH"); // Get env variable
1228
- setenv("MY_VAR", "val"); // Set env variable
1229
-
1230
- copy(obj); // Shallow copy
1231
- deepcopy(obj); // Deep copy
1232
-
1233
- clear(); // Clear console
1520
+ // Read from file
1521
+ @input = ifstream("input.txt");
1522
+ string line;
1523
+ while (getline(input, line)) {
1524
+ printl(line);
1525
+ }
1526
+ input.close();
1234
1527
 
1235
- pyimport("os"); // Import Python module
1236
- include("lib.cssl-mod"); // Import CSSL module
1237
- payload("helper.cssl-pl"); // Load payload
1528
+ // Read/write
1529
+ @rw = fstream("data.txt", "r+");
1530
+ ```
1238
1531
 
1239
- isLinux(); // Platform checks
1240
- isWindows();
1241
- isMac();
1242
- ```
1532
+ ### Stream Manipulators
1243
1533
 
1244
- ### Filter Functions (filter:: namespace)
1534
+ ```cssl
1535
+ // Precision
1536
+ cout << setprecision(2) << 3.14159 << endl; // "3.14"
1245
1537
 
1246
- ```cssl
1247
- // Register custom filter
1248
- filter::register("custom", "handler", callback);
1249
- filter::unregister("custom", "handler");
1250
- filter::list(); // All registered filters
1251
- filter::exists("custom", "handler");
1252
- ```
1538
+ // Width and fill
1539
+ cout << setw(10) << setfill('0') << 42 << endl; // "0000000042"
1253
1540
 
1254
- ---
1541
+ // Number format
1542
+ cout << fixed << 3.14159 << endl; // Fixed point
1543
+ cout << scientific << 3.14159 << endl; // Scientific
1544
+ ```
1255
1545
 
1256
- ## CodeInfusion
1546
+ ---
1257
1547
 
1258
- Modify functions at runtime.
1548
+ ## Module System
1259
1549
 
1260
- ### <<== (Replace)
1550
+ ### Include Files
1261
1551
 
1262
- ```cssl
1263
- void original() {
1264
- printl("Original");
1265
- }
1552
+ ```cssl
1553
+ // Include CSSL file
1554
+ include "utils.cssl";
1266
1555
 
1267
- original() <<== {
1268
- printl("Replaced");
1269
- }
1556
+ // Include as module
1557
+ @utils = include("utils.cssl");
1558
+ utils.helper();
1270
1559
 
1271
- original(); // "Replaced"
1272
- ```
1560
+ // Include with alias
1561
+ @lib = include("library.cssl");
1562
+ lib::function();
1563
+ ```
1273
1564
 
1274
- ### +<<== (Add Before)
1565
+ ### CSSL Modules (.cssl-mod)
1275
1566
 
1276
- ```cssl
1277
- void base() {
1278
- printl("Base");
1279
- }
1567
+ Create modules from Python files:
1280
1568
 
1281
- base() +<<== {
1282
- printl("Added");
1283
- }
1569
+ ```bash
1570
+ includecpp cssl makemodule mylib.py -o mylib.cssl-mod
1571
+ ```
1284
1572
 
1285
- base();
1286
- // Output:
1287
- // Added
1288
- // Base
1289
- ```
1573
+ Use in CSSL:
1290
1574
 
1291
- ### -<<== (Remove)
1575
+ ```cssl
1576
+ include "mylib.cssl-mod";
1577
+ mylib.function();
1578
+ ```
1292
1579
 
1293
- ```cssl
1294
- void withExtra() {
1295
- printl("Important");
1296
- printl("Unimportant");
1297
- }
1580
+ ### Package System
1298
1581
 
1299
- withExtra() -<<== {
1300
- printl("Unimportant");
1582
+ ```cssl
1583
+ package "myapp" {
1584
+ package-includes {
1585
+ include "lib1.cssl"
1586
+ include "lib2.cssl"
1301
1587
  }
1302
1588
 
1303
- withExtra(); // Only "Important"
1304
- ```
1589
+ exec package {
1590
+ // Main package code
1591
+ printl("Package loaded");
1592
+ }
1593
+ }
1594
+ ```
1305
1595
 
1306
- ### Exit Injection
1596
+ ### Service Definition
1307
1597
 
1308
- ```cssl
1309
- exit() <<== {
1310
- printl("Cleanup...");
1311
- }
1598
+ ```cssl
1599
+ service:
1600
+ name: "MyService"
1601
+ version: "1.0.0"
1602
+ author: "Developer"
1312
1603
 
1313
- exit(); // Executes injection
1314
- ```
1604
+ service-init {
1605
+ // Initialization
1606
+ printl("Service initializing...");
1607
+ }
1315
1608
 
1316
- ---
1609
+ service-include {
1610
+ include "dependencies.cssl"
1611
+ }
1317
1612
 
1318
- ## BruteInjection
1613
+ service-run {
1614
+ // Main service code
1615
+ printl("Service running");
1616
+ }
1617
+ ```
1319
1618
 
1320
- Transfer data between containers.
1619
+ ---
1321
1620
 
1322
- ### +<== (Copy)
1621
+ ## C++ Integration
1323
1622
 
1324
- ```cssl
1325
- stack<string> source;
1326
- source.push("A");
1327
- source.push("B");
1623
+ ### Import C++ Modules (v4.8.8)
1328
1624
 
1329
- datastruct<string> target;
1330
- target +<== source; // Copy A, B (source unchanged)
1331
- ```
1625
+ ```cssl
1626
+ // Import pre-built C++ module
1627
+ @math = includecpp("C:/projects/mylib/cpp.proj", "fastmath");
1332
1628
 
1333
- ### -<== (Move)
1629
+ // Use module
1630
+ result = math.fibonacci(10); // 55
1631
+ heavy = math.heavy_compute(100); // Fast C++ execution
1632
+ ```
1334
1633
 
1335
- ```cssl
1336
- stack<string> src;
1337
- src.push("Data");
1634
+ ### C++ Operations
1338
1635
 
1339
- datastruct<string> dst;
1340
- dst -<== src; // src is empty after
1341
- ```
1636
+ ```cssl
1637
+ sizeof(int); // Get type size
1638
+ memcpy(dest, src, size); // Memory copy
1639
+ memset(buffer, value, size); // Memory set
1640
+ ```
1342
1641
 
1343
- ### ==> (Replace)
1642
+ ### Native/Unative Functions
1344
1643
 
1345
- ```cssl
1346
- stack<string> data;
1347
- data.push("New");
1644
+ ```cssl
1645
+ // Force C++ execution (v4.6.0)
1646
+ native define fastFunction() {
1647
+ // Runs in C++ interpreter for speed
1648
+ foreach (i in range(1000000)) {
1649
+ // Fast loop
1650
+ }
1651
+ }
1348
1652
 
1349
- datastruct<string> container;
1350
- container ==> data; // Replace container content
1351
- ```
1653
+ // Force Python execution (v4.6.5)
1654
+ unative define pythonFunction() {
1655
+ // Runs in Python for compatibility
1656
+ // Use for advanced CSSL features
1657
+ }
1658
+ ```
1352
1659
 
1353
- ### ==>- (Remove Matching)
1660
+ ### Memory Binding (v4.9.0)
1354
1661
 
1355
- ```cssl
1356
- stack<string> names;
1357
- names.push("Alice");
1358
- names.push("Bob");
1359
- names.push("Alice");
1662
+ Bind functions or classes to a memory address for deferred execution:
1360
1663
 
1361
- stack<string> toRemove;
1362
- toRemove.push("Alice");
1664
+ ```cssl
1665
+ // Get memory info about an object
1666
+ data = memory(myObject);
1667
+ addr = data.get("address"); // Memory address as hex string
1668
+ type = data.get("type"); // Type name
1669
+ methods = data.get("methods"); // List of methods
1363
1670
 
1364
- names ==>- toRemove;
1365
- printl(names); // ["Bob"]
1366
- ```
1671
+ // Bind function to execute when host is called
1672
+ define myFunc() : uses memory(hostFunction) {
1673
+ printl("Runs before hostFunction executes");
1674
+ }
1367
1675
 
1368
- ### Filter Syntax
1676
+ // When hostFunction is called, myFunc runs first, then hostFunction
1369
1677
 
1370
- ```cssl
1371
- target +<== [type::filter=value] source;
1678
+ // Bind class to execute constructor when host class is instantiated
1679
+ class MyClass : uses memory(HostClass) {
1680
+ constr MyClass() {
1681
+ printl("Runs when HostClass constructor is called");
1682
+ }
1683
+ }
1372
1684
 
1373
- // String filters
1374
- result +<== [string::where="Apple"] fruits;
1375
- result +<== [string::not="Banana"] fruits;
1376
- result +<== [string::contains="App"] fruits;
1377
- result +<== [string::length=5] fruits;
1378
- result +<== [string::cut=3] version;
1379
- result +<== [string::cutAfter="."] version;
1685
+ // Practical example: Hook into existing function
1686
+ define logCalls() : uses memory(printl) {
1687
+ // This runs every time printl is called
1688
+ }
1689
+ ```
1380
1690
 
1381
- // Other filters
1382
- result +<== [integer::where=42] numbers;
1383
- result +<== [json::key="name"] objects;
1384
- ```
1691
+ ---
1385
1692
 
1386
- ---
1693
+ ## Python Interop
1387
1694
 
1388
- ## Value Capture
1695
+ ### Import Python Modules
1389
1696
 
1390
- Capture values at registration time with `%`:
1697
+ ```cssl
1698
+ @math = pyimport("math");
1699
+ printl(math.sqrt(16)); // 4.0
1391
1700
 
1392
- ```cssl
1393
- string version = "1.0.0";
1394
- savedVersion <<== { %version; }
1701
+ @json = pyimport("json");
1702
+ data = json.loads('{"key": "value"}');
1703
+ ```
1395
1704
 
1396
- version = "2.0.0";
1397
- printl(savedVersion); // "1.0.0" (captured value)
1398
- ```
1705
+ ### Python Type Conversion
1399
1706
 
1400
- ### Capturing Functions
1707
+ ```cssl
1708
+ // Convert CSSL to Python
1709
+ python::pythonize(csslObject);
1710
+ python::wrap(csslObject);
1711
+ python::export(csslObject);
1401
1712
 
1402
- ```cssl
1403
- originalExit <<== { %exit(); }
1713
+ // Convert Python to CSSL
1714
+ python::csslize(pythonObject);
1715
+ python::import(pythonObject);
1716
+ ```
1404
1717
 
1405
- exit() <<== {
1406
- printl("Custom cleanup");
1407
- originalExit();
1408
- }
1409
- ```
1718
+ ### Parameter Exchange
1410
1719
 
1411
- ---
1720
+ ```cssl
1721
+ // In Python:
1722
+ // CSSL.run(code, param1, param2)
1412
1723
 
1413
- ## Module System
1724
+ // In CSSL:
1725
+ val = parameter.get(0); // Get first parameter
1726
+ parameter.return(result); // Return to Python
1414
1727
 
1415
- ### Import CSSL Module
1728
+ // Or via python namespace
1729
+ val = python::param_get(0);
1730
+ python::param_return(result);
1416
1731
 
1417
- ```cssl
1418
- @Math = include("mathlib.cssl-mod");
1419
- int result = @Math.add(5, 3);
1420
- ```
1732
+ // Count and check
1733
+ n = python::param_count();
1734
+ has = python::param_has(0);
1735
+ all = python::param_all();
1736
+ ```
1421
1737
 
1422
- ### Import Python Module
1738
+ ---
1423
1739
 
1424
- ```cssl
1425
- @os = pyimport("os");
1426
- string cwd = @os.getcwd();
1740
+ ## Multi-Language Support
1427
1741
 
1428
- @datetime = pyimport("datetime");
1429
- @datetime.datetime.now();
1430
- ```
1742
+ CSSL supports multi-language code blocks (v4.1.0).
1431
1743
 
1432
- ### Load Payload
1744
+ ### Language Blocks
1433
1745
 
1434
- ```cssl
1435
- payload("helpers.cssl-pl");
1436
- ```
1746
+ ```cssl
1747
+ supports python {
1748
+ # Python code here
1749
+ def helper():
1750
+ return 42
1751
+ }
1437
1752
 
1438
- ### Create Module (CLI)
1753
+ supports javascript {
1754
+ // JS-like code
1755
+ function jsHelper() {
1756
+ return "hello";
1757
+ }
1758
+ }
1759
+ ```
1439
1760
 
1440
- ```bash
1441
- python -m includecpp cssl makemodule mylib.py -o mylib.cssl-mod
1442
- ```
1761
+ ### Cross-Language Instance Access
1443
1762
 
1444
- ---
1763
+ ```cssl
1764
+ // Access C++ class
1765
+ cpp$MyClass.method();
1766
+ cpp$MyClass.property = value;
1445
1767
 
1446
- ## Multi-Language Support
1768
+ // Access Python object
1769
+ py$PyObject.method();
1770
+ py$PyObject.attribute;
1447
1771
 
1448
- CSSL v4.1.0 introduces multi-language support for interoperability with other programming languages.
1772
+ // Access JavaScript object (if JS support enabled)
1773
+ js$JsObject.function();
1774
+ ```
1449
1775
 
1450
- ### libinclude - Load Language Support
1776
+ ### Library Include
1451
1777
 
1452
- Use `libinclude()` to load a language support module:
1778
+ ```cssl
1779
+ // Include language-specific library
1780
+ libinclude("numpy", "python");
1781
+ libinclude("lodash", "javascript");
1782
+ ```
1453
1783
 
1454
- ```cssl
1455
- // Load language support
1456
- @py = libinclude("python");
1457
- cpp = libinclude("c++");
1458
- java = libinclude("java");
1459
- csharp = libinclude("c#");
1460
- js = libinclude("javascript");
1461
- ```
1784
+ ---
1462
1785
 
1463
- **Supported Languages:**
1786
+ ## Async/Await System (v4.9.3)
1464
1787
 
1465
- | Language | Identifiers |
1466
- |----------|-------------|
1467
- | Python | `python`, `py` |
1468
- | C++ | `c++`, `cpp` |
1469
- | Java | `java` |
1470
- | C# | `c#`, `csharp` |
1471
- | JavaScript | `javascript`, `js` |
1788
+ CSSL provides full async/await support for concurrent operations with generators for lazy iteration.
1472
1789
 
1473
- ### supports - Multi-Language Syntax
1790
+ ### Async Functions
1474
1791
 
1475
- Use the `supports` keyword to write functions or classes using another language's syntax:
1792
+ ```cssl
1793
+ // Define async function with 'async' modifier
1794
+ async define fetchData(string url) {
1795
+ result = http.get(url);
1796
+ return result;
1797
+ }
1476
1798
 
1477
- ```cssl
1478
- // Python-style function
1479
- define calculate(numbers) : supports python {
1480
- total = 0
1481
- for n in numbers:
1482
- total = total + n
1483
- return total
1484
- }
1799
+ // Calling async function returns a Future immediately
1800
+ future f = fetchData("http://example.com");
1485
1801
 
1486
- // C++ style class
1487
- class Engine : supports cpp {
1488
- int power;
1489
- bool running;
1802
+ // Wait for result with await
1803
+ data = await f;
1804
+ printl(data);
1805
+ ```
1490
1806
 
1491
- void start() {
1492
- this->running = true;
1493
- }
1494
- }
1807
+ ### Using the Async Module
1495
1808
 
1496
- // JavaScript style function
1497
- define fetchData(url) : supports javascript {
1498
- let response = fetch(url);
1499
- console.log("Fetched: " + url);
1500
- return response;
1501
- }
1502
- ```
1809
+ ```cssl
1810
+ // Run any function asynchronously
1811
+ future f = async.run(slowFunction, arg1, arg2);
1503
1812
 
1504
- ### Cross-Language Instance Access
1813
+ // Wait for result
1814
+ result = async.wait(f);
1505
1815
 
1506
- Access instances shared from other languages using `lang$InstanceName` syntax:
1816
+ // Or use await keyword
1817
+ result = await f;
1507
1818
 
1508
- ```cssl
1509
- cpp = libinclude("c++");
1819
+ // Cancel operation
1820
+ async.stop(f);
1510
1821
 
1511
- // Access C++ shared instance
1512
- engine = cpp$MyEngine;
1513
- printl(engine.power);
1822
+ // Async sleep (milliseconds)
1823
+ async.sleep(1000);
1824
+ ```
1514
1825
 
1515
- // Cross-language inheritance
1516
- class TurboEngine : extends cpp$Engine {
1517
- int turboBoost;
1826
+ ### Multiple Async Operations
1518
1827
 
1519
- constr TurboEngine(int boost) {
1520
- this->turboBoost = boost;
1521
- }
1522
- }
1523
- ```
1828
+ ```cssl
1829
+ // Wait for all to complete
1830
+ future f1 = async.run(task1);
1831
+ future f2 = async.run(task2);
1832
+ future f3 = async.run(task3);
1524
1833
 
1525
- ### Instance Sharing API
1834
+ results = async.all([f1, f2, f3]);
1835
+ // results = [result1, result2, result3]
1526
1836
 
1527
- Share instances between languages using the `share()` and `get_instance()` methods:
1837
+ // Race - first to complete wins
1838
+ winner = async.race([f1, f2, f3]);
1839
+ ```
1528
1840
 
1529
- ```cssl
1530
- // Get language support
1531
- cpp = libinclude("c++");
1841
+ ### Generators with Yield
1532
1842
 
1533
- // Share a CSSL instance with C++
1534
- class MyClass {
1535
- string value;
1843
+ ```cssl
1844
+ // Generator function using yield
1845
+ generator<int> define Range(int n) {
1846
+ int i = 0;
1847
+ while (i < n) {
1848
+ yield i;
1849
+ i = i + 1;
1536
1850
  }
1537
- instance = new MyClass();
1538
- cpp.share("MyClass", instance);
1851
+ }
1539
1852
 
1540
- // Access from C++:
1541
- // auto* obj = CSSL_GET(MyClass, "MyClass");
1542
- ```
1853
+ // Use generator
1854
+ gen = Range(5);
1855
+ while (gen.has_next()) {
1856
+ printl(gen.next()); // 0, 1, 2, 3, 4
1857
+ }
1543
1858
 
1544
- ### Language SDKs
1859
+ // Convert to list
1860
+ numbers = Range(10).to_list();
1861
+ ```
1545
1862
 
1546
- SDKs are available for sharing instances from other languages into CSSL:
1863
+ ### Generator Methods
1547
1864
 
1548
- **C++ SDK:**
1549
- ```cpp
1550
- #include "includecpp.h"
1865
+ ```cssl
1866
+ gen = myGenerator();
1551
1867
 
1552
- class Engine { public: int power = 100; };
1868
+ gen.next() // Get next value
1869
+ gen.has_next() // Check if more values
1870
+ gen.send(val) // Send value into generator
1871
+ gen.to_list() // Consume all into list
1872
+ gen.take(n) // Take up to n values
1873
+ gen.skip(n) // Skip n values
1874
+ ```
1553
1875
 
1554
- Engine engine;
1555
- CSSL_SHARE(Engine, &engine);
1556
- // Now accessible as cpp$Engine in CSSL
1557
- ```
1876
+ ### Future States
1558
1877
 
1559
- **Java SDK:**
1560
- ```java
1561
- import com.includecpp.CSSL;
1878
+ ```cssl
1879
+ future f = async.run(myFunc);
1562
1880
 
1563
- MyService svc = new MyService();
1564
- CSSL.share("MyService", svc);
1565
- // Now accessible as java$MyService in CSSL
1566
- ```
1881
+ // Check state
1882
+ if (f.is_done()) {
1883
+ result = f.result();
1884
+ }
1567
1885
 
1568
- **C# SDK:**
1569
- ```csharp
1570
- using IncludeCPP;
1886
+ // Chain callbacks
1887
+ f.then(lambda result: printl("Got: " + result));
1571
1888
 
1572
- var service = new MyService();
1573
- CSSL.Share("MyService", service);
1574
- // Now accessible as csharp$MyService in CSSL
1575
- ```
1889
+ // Cancel if needed
1890
+ f.cancel();
1891
+ ```
1576
1892
 
1577
- **JavaScript SDK:**
1578
- ```javascript
1579
- import { CSSL } from 'includecpp-cssl';
1893
+ ### Practical Example
1580
1894
 
1581
- class DataProcessor { process(data) { } }
1582
- CSSL.share('DataProcessor', new DataProcessor());
1583
- // Now accessible as js$DataProcessor in CSSL
1584
- ```
1895
+ ```cssl
1896
+ // Async HTTP requests in parallel
1897
+ async define fetchAll(array urls) {
1898
+ futures = [];
1899
+ foreach (url in urls) {
1900
+ futures.push(async.run(http.get, url));
1901
+ }
1902
+ return async.all(futures);
1903
+ }
1585
1904
 
1586
- ### SDK API Reference
1905
+ // Use it
1906
+ data = await fetchAll(["http://api1.com", "http://api2.com"]);
1907
+ ```
1587
1908
 
1588
- All language SDKs provide these methods:
1909
+ ---
1589
1910
 
1590
- | Method | Description |
1591
- |--------|-------------|
1592
- | `share(name, instance)` | Share an instance by name |
1593
- | `get(name)` | Get a shared instance |
1594
- | `has(name)` | Check if instance exists |
1595
- | `remove(name)` | Remove a shared instance |
1596
- | `list()` | Get all instance names |
1597
- | `clear()` | Clear all instances |
1911
+ ## Error Handling
1598
1912
 
1599
- ---
1913
+ ### Try/Catch/Finally
1600
1914
 
1601
- ## Error Handling
1915
+ ```cssl
1916
+ try {
1917
+ // Code that might fail
1918
+ result = riskyOperation();
1919
+ }
1920
+ catch (e) {
1921
+ // Handle error
1922
+ printl("Error: " + e);
1923
+ }
1924
+ finally {
1925
+ // Always executes
1926
+ cleanup();
1927
+ }
1928
+ ```
1602
1929
 
1603
- ### Try / Catch
1930
+ ### Throw Exceptions
1604
1931
 
1605
- ```cssl
1606
- try {
1607
- riskyOperation();
1608
- } catch (error) {
1609
- printl("Error: " + error);
1932
+ ```cssl
1933
+ define validate(int x) {
1934
+ if (x < 0) {
1935
+ throw "Value must be positive";
1610
1936
  }
1937
+ return x;
1938
+ }
1611
1939
 
1612
- try {
1613
- operation();
1614
- } catch (error) {
1615
- printl("Error");
1616
- } finally {
1617
- printl("Always runs");
1618
- }
1619
- ```
1940
+ try {
1941
+ validate(-5);
1942
+ }
1943
+ catch (e) {
1944
+ printl("Caught: " + e);
1945
+ }
1946
+ ```
1620
1947
 
1621
- ### Undefined Functions
1948
+ ### Assertions
1622
1949
 
1623
- ```cssl
1624
- undefined void safeOperation() {
1625
- dangerousCode(); // Errors ignored
1626
- }
1627
- ```
1628
-
1629
- ### Assert
1630
-
1631
- ```cssl
1632
- assert(x > 0, "x must be positive");
1633
- ```
1634
-
1635
- ---
1636
-
1637
- ## Quick Reference
1638
-
1639
- ### Keywords
1640
-
1641
- | Keyword | Description |
1642
- |---------|-------------|
1643
- | `void` | No return value |
1644
- | `return` | Return value |
1645
- | `global` | Declare global |
1646
- | `if` / `else` / `elif` | Conditionals |
1647
- | `switch` / `case` / `default` | Switch statement |
1648
- | `for` / `foreach` / `while` | Loops |
1649
- | `break` / `continue` | Loop control |
1650
- | `try` / `catch` / `finally` | Error handling |
1651
- | `class` / `new` / `this` | OOP |
1652
- | `extends` / `overwrites` | Inheritance |
1653
- | `constr` | Constructor |
1654
- | `define` | Function definition |
1655
- | `undefined` | Ignore errors |
1656
- | `closed` / `private` | Injection protection |
1657
- | `virtual` | Import-safe |
1658
- | `meta` / `super` | Special function types |
1659
- | `shuffled` | Multiple returns |
1660
- | `open` | Any parameters |
1661
- | `include` / `get` | Import modules |
1662
-
1663
- ### Injection Operators
1664
-
1665
- | Operator | Type | Description |
1666
- |----------|------|-------------|
1667
- | `<<==` | CodeInfusion | Replace function |
1668
- | `+<<==` | CodeInfusion | Add code before |
1669
- | `-<<==` | CodeInfusion | Remove code |
1670
- | `<==` | ValueCapture | Capture/assign |
1671
- | `+<==` | BruteInjection | Copy data |
1672
- | `-<==` | BruteInjection | Move data |
1673
- | `==>` | BruteInjection | Replace data |
1674
- | `==>-` | BruteInjection | Remove matching |
1675
- | `++` | AppendMode | Append to parent |
1676
-
1677
- ### Special Syntax
1678
-
1679
- | Syntax | Description |
1680
- |--------|-------------|
1681
- | `@name` | Global variable access |
1682
- | `@name = value` | Global variable assignment |
1683
- | `r@name = value` | Global reference assignment |
1684
- | `$name` | Shared Python object |
1685
- | `%name` | Captured value |
1686
- | `this->` | Class member access |
1687
- | `super::method()` | Parent method call |
1688
- | `json::func()` | Namespace function |
1689
- | `&ClassName::member` | Class member reference |
1690
- | `&FunctionName ++` | Append to function |
1691
- | `*func()` | Non-null function |
1692
- | `*[type]func()` | Type exclusion filter |
1693
- | `global class Name` | Global class declaration |
1694
- | `class @Name` | Global class (alt syntax) |
1695
- | `global define func()` | Global function declaration |
1696
- | `define @func()` | Global function (alt syntax) |
1697
- | `new @ClassName()` | Instantiate global class |
1698
- | `libinclude("lang")` | Load language support module |
1699
- | `supports lang` | Use other language syntax |
1700
- | `lang$InstanceName` | Cross-language instance access |
1701
-
1702
- ### Multi-Language Keywords
1703
-
1704
- | Keyword | Description |
1705
- |---------|-------------|
1706
- | `libinclude` | Load language support module |
1707
- | `supports` | Use another language's syntax in function/class |
1708
-
1709
- ### Cross-Language Syntax
1710
-
1711
- | Syntax | Description | Example |
1712
- |--------|-------------|---------|
1713
- | `libinclude("lang")` | Load language support | `cpp = libinclude("c++")` |
1714
- | `: supports lang` | Use language syntax | `define func() : supports python { }` |
1715
- | `lang$Name` | Access shared instance | `cpp$Engine`, `java$Service` |
1716
- | `extends lang$Name` | Inherit from shared class | `class Child : extends cpp$Parent { }` |
1717
-
1718
- ---
1719
-
1720
- *CSSL v4.1.0 - Developed as part of IncludeCPP*
1950
+ ```cssl
1951
+ assert(x > 0, "x must be positive");
1952
+ assert(list.length > 0); // Default message
1953
+ ```
1954
+
1955
+ ---
1956
+
1957
+ ## CLI Reference
1958
+
1959
+ ### CSSL Commands
1960
+
1961
+ ```bash
1962
+ # Run CSSL file
1963
+ includecpp cssl run myfile.cssl
1964
+
1965
+ # Run inline code
1966
+ includecpp cssl run -c 'printl("Hello!");'
1967
+
1968
+ # Run with parameters
1969
+ includecpp cssl run script.cssl --args "param1" "param2"
1970
+
1971
+ # Format CSSL file
1972
+ includecpp cssl format myfile.cssl
1973
+ includecpp cssl format myfile.cssl --inplace
1974
+
1975
+ # Create module from Python
1976
+ includecpp cssl makemodule mylib.py -o mylib.cssl-mod
1977
+
1978
+ # Show CSSL version
1979
+ includecpp cssl version
1980
+
1981
+ # Validate CSSL syntax
1982
+ includecpp cssl check myfile.cssl
1983
+ ```
1984
+
1985
+ ### C++ Build Commands
1986
+
1987
+ ```bash
1988
+ # Build all modules
1989
+ includecpp rebuild
1990
+
1991
+ # Build specific module
1992
+ includecpp rebuild --modules mymodule
1993
+
1994
+ # Clean build
1995
+ includecpp rebuild --clean
1996
+
1997
+ # Verbose output
1998
+ includecpp rebuild --verbose
1999
+ ```
2000
+
2001
+ ---
2002
+
2003
+ ## Quick Reference
2004
+
2005
+ ### Variable Prefixes
2006
+
2007
+ | Prefix | Meaning | Example |
2008
+ |--------|---------|---------|
2009
+ | `@` | Module/local | `@Module = include("m.cssl")` |
2010
+ | `r@` | Global | `r@globalVar = 1` |
2011
+ | `s@` | Struct self | `s@Config.port` |
2012
+ | `$` | Shared | `$SharedData = {}` |
2013
+ | `%` | Snapshot | `%capturedVar` |
2014
+
2015
+ ### Function Modifiers
2016
+
2017
+ | Modifier | Effect |
2018
+ |----------|--------|
2019
+ | `const` | Immutable, no side effects |
2020
+ | `private` | No external injections |
2021
+ | `static` | No instance overhead |
2022
+ | `global` | Globally accessible |
2023
+ | `native` | Force C++ execution |
2024
+ | `unative` | Force Python execution |
2025
+ | `embedded` | Immediate &target replacement |
2026
+ | `meta` | Must return value |
2027
+ | `closed` | Protected from injection |
2028
+ | `open` | Accept any parameter type |
2029
+ | `secure` | Constructor on exception only |
2030
+ | `callable` | Manual constructor call |
2031
+
2032
+ ### Container Quick Reference
2033
+
2034
+ | Type | Creation | Add | Remove | Access |
2035
+ |------|----------|-----|--------|--------|
2036
+ | `stack<T>` | `stack<T> s;` | `s.push(x)` | `s.pop()` | `s.peek()` |
2037
+ | `vector<T>` | `vector<T> v;` | `v.push_back(x)` | `v.erase(i)` | `v[i]` |
2038
+ | `array<T>` | `array<T> a;` | `a.push(x)` | `a.remove(i)` | `a.get(i)` |
2039
+ | `map<K,V>` | `map<K,V> m;` | `m.set(k,v)` | `m.remove(k)` | `m.get(k)` |
2040
+ | `queue<T>` | `queue<T> q;` | `q.enqueue(x)` | `q.dequeue()` | `q.peek()` |
2041
+ | `list` | `list l = [];` | `l.append(x)` | `l.remove(x)` | `l[i]` |
2042
+ | `dict` | `dict d = {};` | `d["k"] = v` | `del d["k"]` | `d["k"]` |
2043
+
2044
+ ### Operator Priority (High to Low)
2045
+
2046
+ 1. `()` `[]` `.` `->` `::`
2047
+ 2. `~` `!` `not`
2048
+ 3. `*` `/` `%`
2049
+ 4. `+` `-`
2050
+ 5. `<<` `>>`
2051
+ 6. `<` `<=` `>` `>=`
2052
+ 7. `==` `!=`
2053
+ 8. `&&` `and`
2054
+ 9. `||` `or`
2055
+ 10. `<==` `==>` `<<==` `==>>`
2056
+ 11. `=`
2057
+
2058
+ ---
2059
+
2060
+ ## Version History
2061
+
2062
+ - **v4.9.0** - Complete documentation update, includecpp() builtin, snapshot system enhancements
2063
+ - **v4.8.8** - Snapshot system, super->method(), destructor support, callable/secure constructors
2064
+ - **v4.8.4** - C++ I/O streams (cout, cin, fstream)
2065
+ - **v4.7.0** - Thread-safe Queue type
2066
+ - **v4.6.5** - Color functions, watcher namespace, unative modifier
2067
+ - **v4.6.3** - F-strings support
2068
+ - **v4.6.0** - Native modifier for C++ execution
2069
+ - **v4.2.5** - Embedded functions, parameter switch, bytearrayed
2070
+ - **v4.1.0** - Multi-language support, libinclude
2071
+
2072
+ ---
2073
+
2074
+ *CSSL is part of IncludeCPP - Professional C++/Python Integration*