IncludeCPP 4.5.2__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.
- includecpp/CHANGELOG.md +241 -0
- includecpp/__init__.py +89 -3
- includecpp/__init__.pyi +2 -1
- includecpp/cli/commands.py +1747 -266
- includecpp/cli/config_parser.py +1 -1
- includecpp/core/build_manager.py +64 -13
- includecpp/core/cpp_api_extensions.pyi +43 -270
- includecpp/core/cssl/CSSL_DOCUMENTATION.md +1799 -1445
- includecpp/core/cssl/cpp/build/api.pyd +0 -0
- includecpp/core/cssl/cpp/build/api.pyi +274 -0
- includecpp/core/cssl/cpp/build/cssl_core.pyi +0 -99
- includecpp/core/cssl/cpp/cssl_core.cp +2 -23
- includecpp/core/cssl/cssl_builtins.py +2116 -171
- includecpp/core/cssl/cssl_builtins.pyi +1324 -104
- includecpp/core/cssl/cssl_compiler.py +4 -1
- includecpp/core/cssl/cssl_modules.py +605 -6
- includecpp/core/cssl/cssl_optimizer.py +12 -1
- includecpp/core/cssl/cssl_parser.py +1048 -52
- includecpp/core/cssl/cssl_runtime.py +2041 -131
- includecpp/core/cssl/cssl_syntax.py +405 -277
- includecpp/core/cssl/cssl_types.py +5891 -1655
- includecpp/core/cssl_bridge.py +429 -3
- includecpp/core/error_catalog.py +54 -10
- includecpp/core/homeserver.py +1037 -0
- includecpp/generator/parser.cpp +203 -39
- includecpp/generator/parser.h +15 -1
- includecpp/templates/cpp.proj.template +1 -1
- includecpp/vscode/cssl/snippets/cssl.snippets.json +163 -0
- includecpp/vscode/cssl/syntaxes/cssl.tmLanguage.json +87 -12
- {includecpp-4.5.2.dist-info → includecpp-4.9.3.dist-info}/METADATA +81 -10
- {includecpp-4.5.2.dist-info → includecpp-4.9.3.dist-info}/RECORD +35 -33
- {includecpp-4.5.2.dist-info → includecpp-4.9.3.dist-info}/WHEEL +1 -1
- {includecpp-4.5.2.dist-info → includecpp-4.9.3.dist-info}/entry_points.txt +0 -0
- {includecpp-4.5.2.dist-info → includecpp-4.9.3.dist-info}/licenses/LICENSE +0 -0
- {includecpp-4.5.2.dist-info → includecpp-4.9.3.dist-info}/top_level.txt +0 -0
|
@@ -340,6 +340,144 @@ def typeof(value: Any) -> str:
|
|
|
340
340
|
"""
|
|
341
341
|
...
|
|
342
342
|
|
|
343
|
+
def memory(value: Any) -> dict:
|
|
344
|
+
"""Get memory/introspection info about a value (v4.8.9).
|
|
345
|
+
|
|
346
|
+
Args:
|
|
347
|
+
value: Any CSSL value (variable, function, class instance, etc.)
|
|
348
|
+
|
|
349
|
+
Returns:
|
|
350
|
+
Dictionary with keys:
|
|
351
|
+
- address: Memory address as hex string
|
|
352
|
+
- type: Type name string
|
|
353
|
+
- repr: Python repr() string
|
|
354
|
+
- value: Actual value for simple types
|
|
355
|
+
- methods: List of method names
|
|
356
|
+
- attributes: Dict of non-callable attributes
|
|
357
|
+
- class_name: For CSSL instances, the class name
|
|
358
|
+
- members: For CSSL instances, dict of member values
|
|
359
|
+
|
|
360
|
+
Example:
|
|
361
|
+
data = memory(myClass);
|
|
362
|
+
printl(data.get("address")); // "0x7f..."
|
|
363
|
+
printl(data.get("type")); // "MyClass"
|
|
364
|
+
printl(data.get("methods")); // ["method1", "method2"]
|
|
365
|
+
|
|
366
|
+
// Copy the info
|
|
367
|
+
info = memory(func).copy();
|
|
368
|
+
|
|
369
|
+
// Get specific field
|
|
370
|
+
addr = memory(obj).get("address");
|
|
371
|
+
"""
|
|
372
|
+
...
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
def address(value: Any) -> 'CSSLAddress':
|
|
376
|
+
"""Get memory address of an object as an Address type (v4.9.0).
|
|
377
|
+
|
|
378
|
+
Shortcut for memory(obj).get("address") that returns an Address object
|
|
379
|
+
which can be used with reflect() to get the object back.
|
|
380
|
+
|
|
381
|
+
Args:
|
|
382
|
+
value: Any CSSL value
|
|
383
|
+
|
|
384
|
+
Returns:
|
|
385
|
+
Address object pointing to the value
|
|
386
|
+
|
|
387
|
+
Example:
|
|
388
|
+
string text = "Hello";
|
|
389
|
+
address addr = address(text);
|
|
390
|
+
|
|
391
|
+
// Later, in another function:
|
|
392
|
+
obj = addr.reflect();
|
|
393
|
+
printl(obj); // "Hello"
|
|
394
|
+
|
|
395
|
+
// Or use the builtin
|
|
396
|
+
obj = reflect(addr);
|
|
397
|
+
"""
|
|
398
|
+
...
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
def reflect(addr: Any) -> Any:
|
|
402
|
+
"""Reflect an address to get the original object (v4.9.0).
|
|
403
|
+
|
|
404
|
+
Takes an Address object or address string and returns the object at that address.
|
|
405
|
+
|
|
406
|
+
Args:
|
|
407
|
+
addr: Address object or address string (hex)
|
|
408
|
+
|
|
409
|
+
Returns:
|
|
410
|
+
The object at that address, or None if not found
|
|
411
|
+
|
|
412
|
+
Example:
|
|
413
|
+
string text = "Hello";
|
|
414
|
+
address addr = address(text);
|
|
415
|
+
|
|
416
|
+
// Reflect to get object back
|
|
417
|
+
obj = reflect(addr);
|
|
418
|
+
printl(obj); // "Hello"
|
|
419
|
+
|
|
420
|
+
// Also works with address strings from memory()
|
|
421
|
+
data = memory(text);
|
|
422
|
+
obj = reflect(data.get("address"));
|
|
423
|
+
"""
|
|
424
|
+
...
|
|
425
|
+
|
|
426
|
+
|
|
427
|
+
def destroy(target: Any) -> bool:
|
|
428
|
+
"""Destroy an object and free its memory (v4.9.2).
|
|
429
|
+
|
|
430
|
+
Clears the contents of containers, removes objects from the address registry,
|
|
431
|
+
and helps garbage collection by nullifying references.
|
|
432
|
+
|
|
433
|
+
Args:
|
|
434
|
+
target: Object to destroy (can be Address, container, or any object)
|
|
435
|
+
|
|
436
|
+
Returns:
|
|
437
|
+
True if destruction was successful, False otherwise
|
|
438
|
+
|
|
439
|
+
Example:
|
|
440
|
+
list data = [1, 2, 3, 4, 5];
|
|
441
|
+
printl(len(data)); // 5
|
|
442
|
+
destroy(data);
|
|
443
|
+
printl(len(data)); // 0
|
|
444
|
+
|
|
445
|
+
// Works with addresses
|
|
446
|
+
ptr addr = address(someVar);
|
|
447
|
+
destroy(addr); // Removes from address registry
|
|
448
|
+
"""
|
|
449
|
+
...
|
|
450
|
+
|
|
451
|
+
|
|
452
|
+
def execute(code: str, context: dict = None) -> Any:
|
|
453
|
+
"""Execute CSSL code string inline (v4.9.2).
|
|
454
|
+
|
|
455
|
+
Parses and executes CSSL code from a string. Useful for dynamic code
|
|
456
|
+
execution, metaprogramming, and runtime code generation.
|
|
457
|
+
|
|
458
|
+
Args:
|
|
459
|
+
code: CSSL code string to execute
|
|
460
|
+
context: Optional dict of variables to inject into scope
|
|
461
|
+
|
|
462
|
+
Returns:
|
|
463
|
+
The result of the last expression or explicit return value.
|
|
464
|
+
Returns dict with 'error' key if execution fails.
|
|
465
|
+
|
|
466
|
+
Example:
|
|
467
|
+
// Simple execution
|
|
468
|
+
execute("x = 5; y = x * 2;");
|
|
469
|
+
printl(y); // 10
|
|
470
|
+
|
|
471
|
+
// Get return value
|
|
472
|
+
result = execute("return 5 + 3;");
|
|
473
|
+
printl(result); // 8
|
|
474
|
+
|
|
475
|
+
// With context
|
|
476
|
+
execute("printl(greeting + name);", {"greeting": "Hello, ", "name": "World"});
|
|
477
|
+
"""
|
|
478
|
+
...
|
|
479
|
+
|
|
480
|
+
|
|
343
481
|
def isinstance(value: Any, type_name: str) -> bool:
|
|
344
482
|
"""Check if value is instance of specified type.
|
|
345
483
|
|
|
@@ -2503,6 +2641,129 @@ def delete(name: str) -> bool:
|
|
|
2503
2641
|
"""
|
|
2504
2642
|
...
|
|
2505
2643
|
|
|
2644
|
+
def includecpp(cpp_proj: str, module: str) -> Any:
|
|
2645
|
+
"""Import a pre-built C++ module from IncludeCPP project (v4.8.8).
|
|
2646
|
+
|
|
2647
|
+
Loads compiled C++ modules directly into CSSL, enabling use of
|
|
2648
|
+
high-performance C++ functions from within CSSL scripts.
|
|
2649
|
+
|
|
2650
|
+
Args:
|
|
2651
|
+
cpp_proj: Path to cpp.proj file or project directory
|
|
2652
|
+
module: Name of the compiled module to import
|
|
2653
|
+
|
|
2654
|
+
Returns:
|
|
2655
|
+
Module proxy object with callable functions
|
|
2656
|
+
|
|
2657
|
+
Example:
|
|
2658
|
+
// Import a compiled math module
|
|
2659
|
+
@FastMath = includecpp(
|
|
2660
|
+
cpp_proj="C:/Projects/QbbLibrary/cpp.proj",
|
|
2661
|
+
module="fastmath"
|
|
2662
|
+
);
|
|
2663
|
+
|
|
2664
|
+
// Call C++ functions
|
|
2665
|
+
int result = @FastMath.fibonacci(40);
|
|
2666
|
+
printl("Fib(40) = " + result);
|
|
2667
|
+
|
|
2668
|
+
// Import different module
|
|
2669
|
+
@Crypto = includecpp(cpp_proj="/path/to/crypto/cpp.proj", module="hashing");
|
|
2670
|
+
string hash = @Crypto.sha256("hello world");
|
|
2671
|
+
"""
|
|
2672
|
+
...
|
|
2673
|
+
|
|
2674
|
+
def snapshot(variable: Any, name: str = None) -> bool:
|
|
2675
|
+
"""Capture variable state for later retrieval (v4.8.8).
|
|
2676
|
+
|
|
2677
|
+
Creates a snapshot of the variable's current value that can be
|
|
2678
|
+
accessed using %name syntax even after the variable changes.
|
|
2679
|
+
|
|
2680
|
+
Args:
|
|
2681
|
+
variable: Variable or function to snapshot
|
|
2682
|
+
name: Optional custom snapshot name (defaults to variable name)
|
|
2683
|
+
|
|
2684
|
+
Returns:
|
|
2685
|
+
True if snapshot was created
|
|
2686
|
+
|
|
2687
|
+
Example:
|
|
2688
|
+
string version = "1.0";
|
|
2689
|
+
snapshot(version); // Capture current value
|
|
2690
|
+
|
|
2691
|
+
version = "2.0"; // Modify
|
|
2692
|
+
printl(version); // "2.0"
|
|
2693
|
+
printl(%version); // "1.0" (snapshotted)
|
|
2694
|
+
|
|
2695
|
+
// Named snapshot
|
|
2696
|
+
int counter = 100;
|
|
2697
|
+
snapshot(counter, "backup");
|
|
2698
|
+
counter = 500;
|
|
2699
|
+
printl(get_snapshot("backup")); // 100
|
|
2700
|
+
|
|
2701
|
+
// Snapshot functions for CodeInfusion
|
|
2702
|
+
snapshot(printl);
|
|
2703
|
+
embedded define override &printl {
|
|
2704
|
+
%printl("PREFIX: " + args[0]); // Call original
|
|
2705
|
+
}
|
|
2706
|
+
"""
|
|
2707
|
+
...
|
|
2708
|
+
|
|
2709
|
+
def get_snapshot(name: str) -> Any:
|
|
2710
|
+
"""Retrieve a snapshotted value by name.
|
|
2711
|
+
|
|
2712
|
+
Example:
|
|
2713
|
+
snapshot(myVar, "saved");
|
|
2714
|
+
// ... later ...
|
|
2715
|
+
value = get_snapshot("saved");
|
|
2716
|
+
"""
|
|
2717
|
+
...
|
|
2718
|
+
|
|
2719
|
+
def has_snapshot(name: str) -> bool:
|
|
2720
|
+
"""Check if a snapshot exists.
|
|
2721
|
+
|
|
2722
|
+
Example:
|
|
2723
|
+
if (has_snapshot("backup")) {
|
|
2724
|
+
restore_snapshot("backup");
|
|
2725
|
+
}
|
|
2726
|
+
"""
|
|
2727
|
+
...
|
|
2728
|
+
|
|
2729
|
+
def clear_snapshot(name: str) -> bool:
|
|
2730
|
+
"""Delete a specific snapshot.
|
|
2731
|
+
|
|
2732
|
+
Example:
|
|
2733
|
+
clear_snapshot("temp");
|
|
2734
|
+
"""
|
|
2735
|
+
...
|
|
2736
|
+
|
|
2737
|
+
def clear_snapshots() -> int:
|
|
2738
|
+
"""Delete all snapshots. Returns count deleted.
|
|
2739
|
+
|
|
2740
|
+
Example:
|
|
2741
|
+
int removed = clear_snapshots();
|
|
2742
|
+
printl("Cleared " + removed + " snapshots");
|
|
2743
|
+
"""
|
|
2744
|
+
...
|
|
2745
|
+
|
|
2746
|
+
def list_snapshots() -> List[str]:
|
|
2747
|
+
"""Get names of all active snapshots.
|
|
2748
|
+
|
|
2749
|
+
Example:
|
|
2750
|
+
list names = list_snapshots();
|
|
2751
|
+
foreach (name in names) {
|
|
2752
|
+
printl("Snapshot: " + name);
|
|
2753
|
+
}
|
|
2754
|
+
"""
|
|
2755
|
+
...
|
|
2756
|
+
|
|
2757
|
+
def restore_snapshot(name: str) -> Any:
|
|
2758
|
+
"""Restore and remove a snapshot (pop operation).
|
|
2759
|
+
|
|
2760
|
+
Retrieves the snapshotted value and removes the snapshot.
|
|
2761
|
+
|
|
2762
|
+
Example:
|
|
2763
|
+
myVar = restore_snapshot("backup");
|
|
2764
|
+
"""
|
|
2765
|
+
...
|
|
2766
|
+
|
|
2506
2767
|
# =============================================================================
|
|
2507
2768
|
# PLATFORM DETECTION
|
|
2508
2769
|
# =============================================================================
|
|
@@ -3873,162 +4134,461 @@ Example:
|
|
|
3873
4134
|
|
|
3874
4135
|
|
|
3875
4136
|
# =============================================================================
|
|
3876
|
-
#
|
|
4137
|
+
# v4.8.4: C++ I/O STREAMS & TYPES
|
|
3877
4138
|
# =============================================================================
|
|
3878
4139
|
|
|
3879
|
-
class
|
|
3880
|
-
"""
|
|
3881
|
-
CSSL Function Keywords - Special modifiers for function definitions.
|
|
4140
|
+
class OutputStream:
|
|
4141
|
+
"""C++ style output stream (cout, cerr, clog equivalent).
|
|
3882
4142
|
|
|
3883
|
-
|
|
4143
|
+
Supports << operator for chained output.
|
|
4144
|
+
|
|
4145
|
+
Example:
|
|
4146
|
+
cout() << "Hello" << " World" << endl();
|
|
4147
|
+
cerr() << "Error: " << errMsg << endl();
|
|
4148
|
+
cout() << setprecision(4) << 3.14159; // "3.1416"
|
|
3884
4149
|
"""
|
|
3885
4150
|
|
|
3886
|
-
def
|
|
3887
|
-
"""
|
|
4151
|
+
def write(self, data: Any) -> 'OutputStream':
|
|
4152
|
+
"""Write data to stream (equivalent to << operator).
|
|
4153
|
+
|
|
4154
|
+
Args:
|
|
4155
|
+
data: Data to write (string, number, or 'endl'/'flush')
|
|
4156
|
+
|
|
4157
|
+
Returns:
|
|
4158
|
+
The stream for chaining
|
|
3888
4159
|
|
|
3889
4160
|
Example:
|
|
3890
|
-
|
|
3891
|
-
printl("Hello!");
|
|
3892
|
-
}
|
|
4161
|
+
cout().write("Hello").write(" World").write(endl());
|
|
3893
4162
|
"""
|
|
3894
4163
|
...
|
|
3895
4164
|
|
|
3896
|
-
def
|
|
3897
|
-
"""
|
|
4165
|
+
def flush(self) -> 'OutputStream':
|
|
4166
|
+
"""Flush the buffer to output."""
|
|
4167
|
+
...
|
|
3898
4168
|
|
|
3899
|
-
|
|
4169
|
+
def setprecision(self, n: int) -> 'OutputStream':
|
|
4170
|
+
"""Set floating point precision."""
|
|
4171
|
+
...
|
|
3900
4172
|
|
|
3901
|
-
|
|
3902
|
-
|
|
3903
|
-
|
|
3904
|
-
}
|
|
4173
|
+
def setw(self, n: int) -> 'OutputStream':
|
|
4174
|
+
"""Set field width for next output."""
|
|
4175
|
+
...
|
|
3905
4176
|
|
|
3906
|
-
|
|
3907
|
-
|
|
3908
|
-
}
|
|
3909
|
-
"""
|
|
4177
|
+
def setfill(self, c: str) -> 'OutputStream':
|
|
4178
|
+
"""Set fill character."""
|
|
3910
4179
|
...
|
|
3911
4180
|
|
|
3912
|
-
def
|
|
3913
|
-
"""
|
|
4181
|
+
def fixed(self) -> 'OutputStream':
|
|
4182
|
+
"""Use fixed-point notation for floats."""
|
|
4183
|
+
...
|
|
3914
4184
|
|
|
3915
|
-
|
|
3916
|
-
|
|
4185
|
+
def scientific(self) -> 'OutputStream':
|
|
4186
|
+
"""Use scientific notation for floats."""
|
|
4187
|
+
...
|
|
3917
4188
|
|
|
3918
|
-
|
|
3919
|
-
|
|
3920
|
-
riskyOperation(); // Errors ignored
|
|
3921
|
-
}
|
|
3922
|
-
mayFail(); // Won't crash even if error occurs
|
|
3923
|
-
"""
|
|
4189
|
+
def hex(self) -> 'OutputStream':
|
|
4190
|
+
"""Use hexadecimal for integers."""
|
|
3924
4191
|
...
|
|
3925
4192
|
|
|
3926
|
-
def
|
|
3927
|
-
"""
|
|
4193
|
+
def oct(self) -> 'OutputStream':
|
|
4194
|
+
"""Use octal for integers."""
|
|
4195
|
+
...
|
|
3928
4196
|
|
|
3929
|
-
|
|
3930
|
-
|
|
4197
|
+
def dec(self) -> 'OutputStream':
|
|
4198
|
+
"""Use decimal for integers (default)."""
|
|
4199
|
+
...
|
|
3931
4200
|
|
|
3932
|
-
Example:
|
|
3933
|
-
closed void protectedFunc() {
|
|
3934
|
-
printl("Protected from external injection");
|
|
3935
|
-
}
|
|
3936
4201
|
|
|
3937
|
-
|
|
3938
|
-
|
|
3939
|
-
"""
|
|
3940
|
-
...
|
|
4202
|
+
class InputStream:
|
|
4203
|
+
"""C++ style input stream (cin equivalent).
|
|
3941
4204
|
|
|
3942
|
-
|
|
3943
|
-
"""Function with ALL injections blocked.
|
|
4205
|
+
Supports >> operator for reading input.
|
|
3944
4206
|
|
|
3945
|
-
|
|
3946
|
-
|
|
4207
|
+
Example:
|
|
4208
|
+
@name = cin().read(str);
|
|
4209
|
+
@age = cin().read(int);
|
|
4210
|
+
@line = getline();
|
|
4211
|
+
"""
|
|
3947
4212
|
|
|
3948
|
-
|
|
3949
|
-
|
|
3950
|
-
printl("Cannot be modified");
|
|
3951
|
-
}
|
|
3952
|
-
"""
|
|
3953
|
-
...
|
|
4213
|
+
def read(self, target_type: type = str) -> Any:
|
|
4214
|
+
"""Read next token from stream.
|
|
3954
4215
|
|
|
3955
|
-
|
|
3956
|
-
|
|
4216
|
+
Args:
|
|
4217
|
+
target_type: Type to convert to (int, float, str, bool)
|
|
3957
4218
|
|
|
3958
|
-
|
|
4219
|
+
Returns:
|
|
4220
|
+
The read and converted value
|
|
3959
4221
|
|
|
3960
4222
|
Example:
|
|
3961
|
-
|
|
3962
|
-
|
|
3963
|
-
}
|
|
4223
|
+
@num = cin().read(int);
|
|
4224
|
+
@name = cin().read(str);
|
|
3964
4225
|
"""
|
|
3965
4226
|
...
|
|
3966
4227
|
|
|
3967
|
-
def
|
|
3968
|
-
"""
|
|
4228
|
+
def getline(self) -> str:
|
|
4229
|
+
"""Read entire line."""
|
|
4230
|
+
...
|
|
3969
4231
|
|
|
3970
|
-
|
|
4232
|
+
def get(self) -> str:
|
|
4233
|
+
"""Read single character."""
|
|
4234
|
+
...
|
|
3971
4235
|
|
|
3972
|
-
|
|
3973
|
-
|
|
3974
|
-
return "source code here";
|
|
3975
|
-
}
|
|
3976
|
-
"""
|
|
4236
|
+
def peek(self) -> str:
|
|
4237
|
+
"""Peek at next character without consuming."""
|
|
3977
4238
|
...
|
|
3978
4239
|
|
|
3979
|
-
def
|
|
3980
|
-
"""
|
|
4240
|
+
def eof(self) -> bool:
|
|
4241
|
+
"""Check if end of stream."""
|
|
4242
|
+
...
|
|
3981
4243
|
|
|
3982
|
-
|
|
4244
|
+
def fail(self) -> bool:
|
|
4245
|
+
"""Check if stream is in fail state."""
|
|
4246
|
+
...
|
|
3983
4247
|
|
|
3984
|
-
|
|
3985
|
-
|
|
3986
|
-
printl("Will ALWAYS complete");
|
|
3987
|
-
}
|
|
3988
|
-
"""
|
|
4248
|
+
def good(self) -> bool:
|
|
4249
|
+
"""Check if stream is good."""
|
|
3989
4250
|
...
|
|
3990
4251
|
|
|
3991
|
-
def
|
|
3992
|
-
"""
|
|
4252
|
+
def clear(self) -> 'InputStream':
|
|
4253
|
+
"""Clear error flags."""
|
|
4254
|
+
...
|
|
3993
4255
|
|
|
3994
|
-
Return statement can have comma-separated values.
|
|
3995
|
-
Caller can unpack using tuple assignment.
|
|
3996
4256
|
|
|
3997
|
-
|
|
3998
|
-
|
|
3999
|
-
return "Alice", "Bob", "Charlie";
|
|
4000
|
-
}
|
|
4257
|
+
class FileStream:
|
|
4258
|
+
"""C++ style file stream (fstream, ifstream, ofstream equivalent).
|
|
4001
4259
|
|
|
4002
|
-
|
|
4003
|
-
a, b, c = getNames();
|
|
4260
|
+
Fast file I/O with << and >> operator support.
|
|
4004
4261
|
|
|
4005
|
-
|
|
4006
|
-
|
|
4007
|
-
|
|
4008
|
-
|
|
4009
|
-
|
|
4262
|
+
Example:
|
|
4263
|
+
@file = fstream("data.txt", "r+");
|
|
4264
|
+
file << "Hello" << endl();
|
|
4265
|
+
@data = file.read(str);
|
|
4266
|
+
file.close();
|
|
4267
|
+
"""
|
|
4268
|
+
|
|
4269
|
+
def __init__(self, filename: str = None, mode: str = 'r'):
|
|
4270
|
+
"""Create a file stream.
|
|
4271
|
+
|
|
4272
|
+
Args:
|
|
4273
|
+
filename: Path to file
|
|
4274
|
+
mode: Open mode ('r', 'w', 'a', 'r+', etc.)
|
|
4010
4275
|
"""
|
|
4011
4276
|
...
|
|
4012
4277
|
|
|
4013
|
-
def open(self) ->
|
|
4014
|
-
"""
|
|
4278
|
+
def open(self, filename: str, mode: str = 'r') -> 'FileStream':
|
|
4279
|
+
"""Open a file."""
|
|
4280
|
+
...
|
|
4015
4281
|
|
|
4016
|
-
|
|
4017
|
-
|
|
4282
|
+
def close(self) -> 'FileStream':
|
|
4283
|
+
"""Close the file."""
|
|
4284
|
+
...
|
|
4018
4285
|
|
|
4019
|
-
|
|
4020
|
-
|
|
4021
|
-
|
|
4022
|
-
int count = OpenFind<int>(0);
|
|
4023
|
-
printl("Name: " + name + ", Count: " + count);
|
|
4024
|
-
}
|
|
4286
|
+
def is_open(self) -> bool:
|
|
4287
|
+
"""Check if file is open."""
|
|
4288
|
+
...
|
|
4025
4289
|
|
|
4026
|
-
|
|
4027
|
-
|
|
4028
|
-
"""
|
|
4290
|
+
def read(self, target_type: type = str) -> Any:
|
|
4291
|
+
"""Read next token from file."""
|
|
4029
4292
|
...
|
|
4030
4293
|
|
|
4031
|
-
|
|
4294
|
+
def write(self, data: Any) -> 'FileStream':
|
|
4295
|
+
"""Write data to file."""
|
|
4296
|
+
...
|
|
4297
|
+
|
|
4298
|
+
def getline(self) -> str:
|
|
4299
|
+
"""Read entire line."""
|
|
4300
|
+
...
|
|
4301
|
+
|
|
4302
|
+
def readlines(self) -> List[str]:
|
|
4303
|
+
"""Read all lines."""
|
|
4304
|
+
...
|
|
4305
|
+
|
|
4306
|
+
def readall(self) -> str:
|
|
4307
|
+
"""Read entire file."""
|
|
4308
|
+
...
|
|
4309
|
+
|
|
4310
|
+
def seekg(self, pos: int, whence: int = 0) -> 'FileStream':
|
|
4311
|
+
"""Seek to position."""
|
|
4312
|
+
...
|
|
4313
|
+
|
|
4314
|
+
def tellg(self) -> int:
|
|
4315
|
+
"""Get current position."""
|
|
4316
|
+
...
|
|
4317
|
+
|
|
4318
|
+
def eof(self) -> bool:
|
|
4319
|
+
"""Check end of file."""
|
|
4320
|
+
...
|
|
4321
|
+
|
|
4322
|
+
def good(self) -> bool:
|
|
4323
|
+
"""Check if stream is good."""
|
|
4324
|
+
...
|
|
4325
|
+
|
|
4326
|
+
|
|
4327
|
+
class Pipe:
|
|
4328
|
+
"""Unix-style pipe for data transformation.
|
|
4329
|
+
|
|
4330
|
+
Supports | operator for chaining transformations.
|
|
4331
|
+
|
|
4332
|
+
Example:
|
|
4333
|
+
@result = pipe([1,2,3,4,5])
|
|
4334
|
+
| Pipe.filter(x => x > 2)
|
|
4335
|
+
| Pipe.map(x => x * 2)
|
|
4336
|
+
| collect();
|
|
4337
|
+
"""
|
|
4338
|
+
|
|
4339
|
+
def __init__(self, data: Any = None):
|
|
4340
|
+
"""Create a pipe with initial data."""
|
|
4341
|
+
...
|
|
4342
|
+
|
|
4343
|
+
def collect(self) -> Any:
|
|
4344
|
+
"""Collect final result."""
|
|
4345
|
+
...
|
|
4346
|
+
|
|
4347
|
+
def to_list(self) -> list:
|
|
4348
|
+
"""Convert to list."""
|
|
4349
|
+
...
|
|
4350
|
+
|
|
4351
|
+
def to_string(self, sep: str = '') -> str:
|
|
4352
|
+
"""Convert to string."""
|
|
4353
|
+
...
|
|
4354
|
+
|
|
4355
|
+
@staticmethod
|
|
4356
|
+
def filter(predicate: Callable) -> Callable:
|
|
4357
|
+
"""Create filter transform."""
|
|
4358
|
+
...
|
|
4359
|
+
|
|
4360
|
+
@staticmethod
|
|
4361
|
+
def map(func: Callable) -> Callable:
|
|
4362
|
+
"""Create map transform."""
|
|
4363
|
+
...
|
|
4364
|
+
|
|
4365
|
+
@staticmethod
|
|
4366
|
+
def reduce(func: Callable, initial: Any = None) -> Callable:
|
|
4367
|
+
"""Create reduce transform."""
|
|
4368
|
+
...
|
|
4369
|
+
|
|
4370
|
+
@staticmethod
|
|
4371
|
+
def sort(key: Callable = None, reverse: bool = False) -> Callable:
|
|
4372
|
+
"""Create sort transform."""
|
|
4373
|
+
...
|
|
4374
|
+
|
|
4375
|
+
@staticmethod
|
|
4376
|
+
def take(n: int) -> Callable:
|
|
4377
|
+
"""Take first n elements."""
|
|
4378
|
+
...
|
|
4379
|
+
|
|
4380
|
+
@staticmethod
|
|
4381
|
+
def skip(n: int) -> Callable:
|
|
4382
|
+
"""Skip first n elements."""
|
|
4383
|
+
...
|
|
4384
|
+
|
|
4385
|
+
@staticmethod
|
|
4386
|
+
def unique() -> Callable:
|
|
4387
|
+
"""Remove duplicates."""
|
|
4388
|
+
...
|
|
4389
|
+
|
|
4390
|
+
@staticmethod
|
|
4391
|
+
def reverse() -> Callable:
|
|
4392
|
+
"""Reverse order."""
|
|
4393
|
+
...
|
|
4394
|
+
|
|
4395
|
+
@staticmethod
|
|
4396
|
+
def grep(pattern: str) -> Callable:
|
|
4397
|
+
"""Filter by regex pattern."""
|
|
4398
|
+
...
|
|
4399
|
+
|
|
4400
|
+
|
|
4401
|
+
class CStruct:
|
|
4402
|
+
"""C-style struct with named fields.
|
|
4403
|
+
|
|
4404
|
+
Fast, lightweight struct for performance-critical code.
|
|
4405
|
+
|
|
4406
|
+
Example:
|
|
4407
|
+
struct Point { int x; int y; };
|
|
4408
|
+
Point p = {10, 20};
|
|
4409
|
+
p.x = 30;
|
|
4410
|
+
printl(sizeof(p));
|
|
4411
|
+
"""
|
|
4412
|
+
|
|
4413
|
+
def __init__(self, name: str, fields: Dict[str, str] = None):
|
|
4414
|
+
"""Create a struct.
|
|
4415
|
+
|
|
4416
|
+
Args:
|
|
4417
|
+
name: Struct name
|
|
4418
|
+
fields: Dict of field_name -> type
|
|
4419
|
+
"""
|
|
4420
|
+
...
|
|
4421
|
+
|
|
4422
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
4423
|
+
"""Convert struct to dictionary."""
|
|
4424
|
+
...
|
|
4425
|
+
|
|
4426
|
+
def sizeof(self) -> int:
|
|
4427
|
+
"""Get estimated memory size."""
|
|
4428
|
+
...
|
|
4429
|
+
|
|
4430
|
+
def copy(self) -> 'CStruct':
|
|
4431
|
+
"""Return a copy of the struct."""
|
|
4432
|
+
...
|
|
4433
|
+
|
|
4434
|
+
|
|
4435
|
+
# =============================================================================
|
|
4436
|
+
# FUNCTION KEYWORDS (for defining functions)
|
|
4437
|
+
# =============================================================================
|
|
4438
|
+
|
|
4439
|
+
class FunctionKeywords:
|
|
4440
|
+
"""
|
|
4441
|
+
CSSL Function Keywords - Special modifiers for function definitions.
|
|
4442
|
+
|
|
4443
|
+
These are not callable functions but keywords used when defining functions.
|
|
4444
|
+
"""
|
|
4445
|
+
|
|
4446
|
+
def void(self) -> None:
|
|
4447
|
+
"""Function without return value.
|
|
4448
|
+
|
|
4449
|
+
Example:
|
|
4450
|
+
void sayHello() {
|
|
4451
|
+
printl("Hello!");
|
|
4452
|
+
}
|
|
4453
|
+
"""
|
|
4454
|
+
...
|
|
4455
|
+
|
|
4456
|
+
def define(self) -> None:
|
|
4457
|
+
"""Constant function without type declaration.
|
|
4458
|
+
|
|
4459
|
+
Does not require return type or 'void'. Used for simple procedures.
|
|
4460
|
+
|
|
4461
|
+
Example:
|
|
4462
|
+
define LOG_MESSAGE() {
|
|
4463
|
+
printl("Log entry");
|
|
4464
|
+
}
|
|
4465
|
+
|
|
4466
|
+
define processData() {
|
|
4467
|
+
// do something
|
|
4468
|
+
}
|
|
4469
|
+
"""
|
|
4470
|
+
...
|
|
4471
|
+
|
|
4472
|
+
def undefined(self) -> None:
|
|
4473
|
+
"""Function that silently ignores errors.
|
|
4474
|
+
|
|
4475
|
+
Any exceptions during execution are caught and ignored.
|
|
4476
|
+
Useful for optional operations that may fail.
|
|
4477
|
+
|
|
4478
|
+
Example:
|
|
4479
|
+
undefined void mayFail() {
|
|
4480
|
+
riskyOperation(); // Errors ignored
|
|
4481
|
+
}
|
|
4482
|
+
mayFail(); // Won't crash even if error occurs
|
|
4483
|
+
"""
|
|
4484
|
+
...
|
|
4485
|
+
|
|
4486
|
+
def closed(self) -> None:
|
|
4487
|
+
"""Function protected from EXTERNAL code injection.
|
|
4488
|
+
|
|
4489
|
+
Prevents external scripts from using <<== to modify this function.
|
|
4490
|
+
Internal injections (same file) still work.
|
|
4491
|
+
|
|
4492
|
+
Example:
|
|
4493
|
+
closed void protectedFunc() {
|
|
4494
|
+
printl("Protected from external injection");
|
|
4495
|
+
}
|
|
4496
|
+
|
|
4497
|
+
// This will be BLOCKED if from different file:
|
|
4498
|
+
protectedFunc() <<== { printl("Blocked!"); }
|
|
4499
|
+
"""
|
|
4500
|
+
...
|
|
4501
|
+
|
|
4502
|
+
def private(self) -> None:
|
|
4503
|
+
"""Function with ALL injections blocked.
|
|
4504
|
+
|
|
4505
|
+
Completely protects function from any CodeInfusion.
|
|
4506
|
+
No <<==, +<<==, or -<<== operations will work.
|
|
4507
|
+
|
|
4508
|
+
Example:
|
|
4509
|
+
private void superSecure() {
|
|
4510
|
+
printl("Cannot be modified");
|
|
4511
|
+
}
|
|
4512
|
+
"""
|
|
4513
|
+
...
|
|
4514
|
+
|
|
4515
|
+
def virtual(self) -> None:
|
|
4516
|
+
"""Function safe for import cycles.
|
|
4517
|
+
|
|
4518
|
+
Prevents infinite recursion when modules import each other.
|
|
4519
|
+
|
|
4520
|
+
Example:
|
|
4521
|
+
virtual void safeForImport() {
|
|
4522
|
+
// Safe to call from circular imports
|
|
4523
|
+
}
|
|
4524
|
+
"""
|
|
4525
|
+
...
|
|
4526
|
+
|
|
4527
|
+
def meta(self) -> None:
|
|
4528
|
+
"""Function declared as source provider (must return).
|
|
4529
|
+
|
|
4530
|
+
Indicates function provides metadata or source information.
|
|
4531
|
+
|
|
4532
|
+
Example:
|
|
4533
|
+
meta string getSource() {
|
|
4534
|
+
return "source code here";
|
|
4535
|
+
}
|
|
4536
|
+
"""
|
|
4537
|
+
...
|
|
4538
|
+
|
|
4539
|
+
def super_keyword(self) -> None:
|
|
4540
|
+
"""Function that forces execution without exceptions.
|
|
4541
|
+
|
|
4542
|
+
Function will complete even if errors occur internally.
|
|
4543
|
+
|
|
4544
|
+
Example:
|
|
4545
|
+
super void forceRun() {
|
|
4546
|
+
printl("Will ALWAYS complete");
|
|
4547
|
+
}
|
|
4548
|
+
"""
|
|
4549
|
+
...
|
|
4550
|
+
|
|
4551
|
+
def shuffled_keyword(self) -> None:
|
|
4552
|
+
"""Function that can return multiple values.
|
|
4553
|
+
|
|
4554
|
+
Return statement can have comma-separated values.
|
|
4555
|
+
Caller can unpack using tuple assignment.
|
|
4556
|
+
|
|
4557
|
+
Example:
|
|
4558
|
+
shuffled string getNames() {
|
|
4559
|
+
return "Alice", "Bob", "Charlie";
|
|
4560
|
+
}
|
|
4561
|
+
|
|
4562
|
+
// Unpack all values
|
|
4563
|
+
a, b, c = getNames();
|
|
4564
|
+
|
|
4565
|
+
// Or with mixed types
|
|
4566
|
+
shuffled getValues() {
|
|
4567
|
+
return "hello", 42, true;
|
|
4568
|
+
}
|
|
4569
|
+
text, num, flag = getValues();
|
|
4570
|
+
"""
|
|
4571
|
+
...
|
|
4572
|
+
|
|
4573
|
+
def open(self) -> None:
|
|
4574
|
+
"""Function that accepts any number/type of parameters.
|
|
4575
|
+
|
|
4576
|
+
Use with 'open Params' to accept variadic arguments.
|
|
4577
|
+
Use OpenFind<type>(index) to extract typed values.
|
|
4578
|
+
|
|
4579
|
+
Example:
|
|
4580
|
+
open define flexibleFunc(open Params) {
|
|
4581
|
+
string name = OpenFind<string>(0);
|
|
4582
|
+
int count = OpenFind<int>(0);
|
|
4583
|
+
printl("Name: " + name + ", Count: " + count);
|
|
4584
|
+
}
|
|
4585
|
+
|
|
4586
|
+
flexibleFunc("Alice", 42, true, "extra");
|
|
4587
|
+
// Extracts: name="Alice", count=42
|
|
4588
|
+
"""
|
|
4589
|
+
...
|
|
4590
|
+
|
|
4591
|
+
# =============================================================================
|
|
4032
4592
|
# CLASSES & OOP
|
|
4033
4593
|
# =============================================================================
|
|
4034
4594
|
|
|
@@ -4831,6 +5391,651 @@ class AppendMode:
|
|
|
4831
5391
|
...
|
|
4832
5392
|
|
|
4833
5393
|
|
|
5394
|
+
# =============================================================================
|
|
5395
|
+
# BINARY TYPES (v4.9.0)
|
|
5396
|
+
# =============================================================================
|
|
5397
|
+
|
|
5398
|
+
class CSSLBit:
|
|
5399
|
+
"""CSSL bit type - Single binary value (0 or 1).
|
|
5400
|
+
|
|
5401
|
+
A bit represents the smallest unit of data - a single binary digit that
|
|
5402
|
+
can only be 0 or 1. Useful for flags, toggles, and binary operations.
|
|
5403
|
+
|
|
5404
|
+
Declaration in CSSL:
|
|
5405
|
+
bit flag = 1;
|
|
5406
|
+
bit enabled = 0;
|
|
5407
|
+
|
|
5408
|
+
Example:
|
|
5409
|
+
bit active = 1;
|
|
5410
|
+
printl(active); // 1
|
|
5411
|
+
|
|
5412
|
+
active.switch(); // Toggle: 1 -> 0
|
|
5413
|
+
printl(active); // 0
|
|
5414
|
+
|
|
5415
|
+
active.set(1); // Set to 1
|
|
5416
|
+
printl(active); // 1
|
|
5417
|
+
"""
|
|
5418
|
+
|
|
5419
|
+
def switch(self) -> 'CSSLBit':
|
|
5420
|
+
"""Toggle the bit value (0 -> 1, 1 -> 0).
|
|
5421
|
+
|
|
5422
|
+
Returns:
|
|
5423
|
+
The bit (for chaining)
|
|
5424
|
+
|
|
5425
|
+
Example:
|
|
5426
|
+
bit flag = 1;
|
|
5427
|
+
flag.switch(); // Now 0
|
|
5428
|
+
flag.switch(); // Now 1 again
|
|
5429
|
+
"""
|
|
5430
|
+
...
|
|
5431
|
+
|
|
5432
|
+
def toggle(self) -> 'CSSLBit':
|
|
5433
|
+
"""Alias for switch(). Toggle the bit value."""
|
|
5434
|
+
...
|
|
5435
|
+
|
|
5436
|
+
def set(self, value: int = 1) -> 'CSSLBit':
|
|
5437
|
+
"""Set the bit to a specific value.
|
|
5438
|
+
|
|
5439
|
+
Args:
|
|
5440
|
+
value: 0 or 1 (default: 1)
|
|
5441
|
+
|
|
5442
|
+
Returns:
|
|
5443
|
+
The bit (for chaining)
|
|
5444
|
+
|
|
5445
|
+
Example:
|
|
5446
|
+
bit flag = 0;
|
|
5447
|
+
flag.set(1); // Now 1
|
|
5448
|
+
flag.set(0); // Now 0
|
|
5449
|
+
flag.set(); // Now 1 (default)
|
|
5450
|
+
"""
|
|
5451
|
+
...
|
|
5452
|
+
|
|
5453
|
+
def clear(self) -> 'CSSLBit':
|
|
5454
|
+
"""Clear the bit (set to 0).
|
|
5455
|
+
|
|
5456
|
+
Returns:
|
|
5457
|
+
The bit (for chaining)
|
|
5458
|
+
|
|
5459
|
+
Example:
|
|
5460
|
+
bit flag = 1;
|
|
5461
|
+
flag.clear(); // Now 0
|
|
5462
|
+
"""
|
|
5463
|
+
...
|
|
5464
|
+
|
|
5465
|
+
def is_set(self) -> bool:
|
|
5466
|
+
"""Check if the bit is set (equals 1).
|
|
5467
|
+
|
|
5468
|
+
Returns:
|
|
5469
|
+
True if bit is 1, False if 0
|
|
5470
|
+
|
|
5471
|
+
Example:
|
|
5472
|
+
bit flag = 1;
|
|
5473
|
+
if (flag.is_set()) {
|
|
5474
|
+
printl("Flag is active");
|
|
5475
|
+
}
|
|
5476
|
+
"""
|
|
5477
|
+
...
|
|
5478
|
+
|
|
5479
|
+
def is_clear(self) -> bool:
|
|
5480
|
+
"""Check if the bit is clear (equals 0).
|
|
5481
|
+
|
|
5482
|
+
Returns:
|
|
5483
|
+
True if bit is 0, False if 1
|
|
5484
|
+
"""
|
|
5485
|
+
...
|
|
5486
|
+
|
|
5487
|
+
def copy(self) -> 'CSSLBit':
|
|
5488
|
+
"""Create a copy of this bit.
|
|
5489
|
+
|
|
5490
|
+
Returns:
|
|
5491
|
+
A new bit with the same value
|
|
5492
|
+
|
|
5493
|
+
Example:
|
|
5494
|
+
bit a = 1;
|
|
5495
|
+
bit b = a.copy();
|
|
5496
|
+
a.switch();
|
|
5497
|
+
printl(a); // 0
|
|
5498
|
+
printl(b); // 1 (unchanged)
|
|
5499
|
+
"""
|
|
5500
|
+
...
|
|
5501
|
+
|
|
5502
|
+
|
|
5503
|
+
class CSSLByte:
|
|
5504
|
+
"""CSSL byte type - 8-bit value with x^y notation.
|
|
5505
|
+
|
|
5506
|
+
A byte represents 8 bits with a special notation: base^weight where
|
|
5507
|
+
base is 0 or 1 (determines signed/unsigned interpretation) and
|
|
5508
|
+
weight is the value (0-255).
|
|
5509
|
+
|
|
5510
|
+
Declaration in CSSL:
|
|
5511
|
+
byte b = 1^200; // Unsigned: value = 200
|
|
5512
|
+
byte s = 0^100; // Signed: value = 100
|
|
5513
|
+
|
|
5514
|
+
The x^y notation provides clear semantics:
|
|
5515
|
+
- 1^n: Unsigned byte, value = n (0-255)
|
|
5516
|
+
- 0^n: Signed interpretation context
|
|
5517
|
+
|
|
5518
|
+
Example:
|
|
5519
|
+
byte data = 1^255;
|
|
5520
|
+
printl(data.value()); // 255
|
|
5521
|
+
printl(data.to_str()); // "11111111" (binary)
|
|
5522
|
+
printl(data.info()); // Full byte info dict
|
|
5523
|
+
|
|
5524
|
+
byte flags = 1^0;
|
|
5525
|
+
flags.set(7, 1); // Set bit 7
|
|
5526
|
+
printl(flags.to_str()); // "10000000"
|
|
5527
|
+
"""
|
|
5528
|
+
|
|
5529
|
+
def value(self) -> int:
|
|
5530
|
+
"""Get the numeric value of the byte.
|
|
5531
|
+
|
|
5532
|
+
Returns:
|
|
5533
|
+
Integer value (0-255)
|
|
5534
|
+
|
|
5535
|
+
Example:
|
|
5536
|
+
byte b = 1^200;
|
|
5537
|
+
printl(b.value()); // 200
|
|
5538
|
+
"""
|
|
5539
|
+
...
|
|
5540
|
+
|
|
5541
|
+
def raw(self) -> int:
|
|
5542
|
+
"""Get raw weight value. Alias for value()."""
|
|
5543
|
+
...
|
|
5544
|
+
|
|
5545
|
+
def unsigned(self) -> int:
|
|
5546
|
+
"""Get unsigned interpretation of the byte.
|
|
5547
|
+
|
|
5548
|
+
Returns:
|
|
5549
|
+
Unsigned integer value (0-255)
|
|
5550
|
+
"""
|
|
5551
|
+
...
|
|
5552
|
+
|
|
5553
|
+
def to_bits(self) -> List[int]:
|
|
5554
|
+
"""Get list of individual bits (LSB first).
|
|
5555
|
+
|
|
5556
|
+
Returns:
|
|
5557
|
+
List of 8 integers, each 0 or 1
|
|
5558
|
+
|
|
5559
|
+
Example:
|
|
5560
|
+
byte b = 1^200;
|
|
5561
|
+
printl(b.to_bits()); // [0, 0, 0, 1, 0, 0, 1, 1] (200 = 11001000)
|
|
5562
|
+
"""
|
|
5563
|
+
...
|
|
5564
|
+
|
|
5565
|
+
def to_str(self) -> str:
|
|
5566
|
+
"""Get binary string representation.
|
|
5567
|
+
|
|
5568
|
+
Returns:
|
|
5569
|
+
8-character string of 0s and 1s
|
|
5570
|
+
|
|
5571
|
+
Example:
|
|
5572
|
+
byte b = 1^200;
|
|
5573
|
+
printl(b.to_str()); // "11001000"
|
|
5574
|
+
"""
|
|
5575
|
+
...
|
|
5576
|
+
|
|
5577
|
+
def reverse(self) -> 'CSSLByte':
|
|
5578
|
+
"""Reverse the bit order.
|
|
5579
|
+
|
|
5580
|
+
Returns:
|
|
5581
|
+
New byte with reversed bits
|
|
5582
|
+
|
|
5583
|
+
Example:
|
|
5584
|
+
byte b = 1^200; // 11001000
|
|
5585
|
+
byte r = b.reverse(); // 00010011 (19)
|
|
5586
|
+
"""
|
|
5587
|
+
...
|
|
5588
|
+
|
|
5589
|
+
def copy(self) -> 'CSSLByte':
|
|
5590
|
+
"""Create a copy of this byte.
|
|
5591
|
+
|
|
5592
|
+
Returns:
|
|
5593
|
+
A new byte with the same base and weight
|
|
5594
|
+
"""
|
|
5595
|
+
...
|
|
5596
|
+
|
|
5597
|
+
def get(self, index: int) -> 'CSSLBit':
|
|
5598
|
+
"""Get bit at specified index.
|
|
5599
|
+
|
|
5600
|
+
Args:
|
|
5601
|
+
index: Bit position (0-7, where 0 is LSB)
|
|
5602
|
+
|
|
5603
|
+
Returns:
|
|
5604
|
+
Bit object at that position
|
|
5605
|
+
|
|
5606
|
+
Example:
|
|
5607
|
+
byte b = 1^200; // 11001000
|
|
5608
|
+
printl(b.get(3)); // 1 (bit 3 is set)
|
|
5609
|
+
printl(b.get(0)); // 0 (bit 0 is clear)
|
|
5610
|
+
"""
|
|
5611
|
+
...
|
|
5612
|
+
|
|
5613
|
+
def at(self, index: int) -> int:
|
|
5614
|
+
"""Get bit value at index. Returns int directly.
|
|
5615
|
+
|
|
5616
|
+
Args:
|
|
5617
|
+
index: Bit position (0-7)
|
|
5618
|
+
|
|
5619
|
+
Returns:
|
|
5620
|
+
0 or 1
|
|
5621
|
+
"""
|
|
5622
|
+
...
|
|
5623
|
+
|
|
5624
|
+
def set(self, index: int, value: int) -> 'CSSLByte':
|
|
5625
|
+
"""Set bit at index to specific value.
|
|
5626
|
+
|
|
5627
|
+
Args:
|
|
5628
|
+
index: Bit position (0-7)
|
|
5629
|
+
value: 0 or 1
|
|
5630
|
+
|
|
5631
|
+
Returns:
|
|
5632
|
+
The byte (for chaining)
|
|
5633
|
+
|
|
5634
|
+
Example:
|
|
5635
|
+
byte b = 1^0;
|
|
5636
|
+
b.set(7, 1); // Set MSB
|
|
5637
|
+
b.set(0, 1); // Set LSB
|
|
5638
|
+
printl(b.value()); // 129
|
|
5639
|
+
"""
|
|
5640
|
+
...
|
|
5641
|
+
|
|
5642
|
+
def change(self, index: int, value: int) -> 'CSSLByte':
|
|
5643
|
+
"""Alias for set(). Set bit at index."""
|
|
5644
|
+
...
|
|
5645
|
+
|
|
5646
|
+
def switch(self, index: int) -> 'CSSLByte':
|
|
5647
|
+
"""Toggle bit at specified index.
|
|
5648
|
+
|
|
5649
|
+
Args:
|
|
5650
|
+
index: Bit position to toggle (0-7)
|
|
5651
|
+
|
|
5652
|
+
Returns:
|
|
5653
|
+
The byte (for chaining)
|
|
5654
|
+
|
|
5655
|
+
Example:
|
|
5656
|
+
byte b = 1^200; // 11001000
|
|
5657
|
+
b.switch(7); // 01001000 (toggle bit 7)
|
|
5658
|
+
"""
|
|
5659
|
+
...
|
|
5660
|
+
|
|
5661
|
+
def write(self, index: int, count: int) -> 'CSSLByte':
|
|
5662
|
+
"""Set 'count' consecutive bits starting at index to 1.
|
|
5663
|
+
|
|
5664
|
+
Args:
|
|
5665
|
+
index: Starting bit position
|
|
5666
|
+
count: Number of bits to set
|
|
5667
|
+
|
|
5668
|
+
Returns:
|
|
5669
|
+
The byte (for chaining)
|
|
5670
|
+
|
|
5671
|
+
Example:
|
|
5672
|
+
byte b = 1^0;
|
|
5673
|
+
b.write(0, 4); // Set bits 0-3
|
|
5674
|
+
printl(b.value()); // 15 (00001111)
|
|
5675
|
+
"""
|
|
5676
|
+
...
|
|
5677
|
+
|
|
5678
|
+
def info(self) -> Dict[str, Any]:
|
|
5679
|
+
"""Get detailed byte information.
|
|
5680
|
+
|
|
5681
|
+
Returns:
|
|
5682
|
+
Dictionary with: base, weight, value, unsigned, binary, hex, bits
|
|
5683
|
+
|
|
5684
|
+
Example:
|
|
5685
|
+
byte b = 1^200;
|
|
5686
|
+
printl(b.info());
|
|
5687
|
+
// {'base': 1, 'weight': 200, 'value': 200, 'unsigned': 200,
|
|
5688
|
+
// 'binary': '11001000', 'hex': '0xc8',
|
|
5689
|
+
// 'bits': [0, 0, 0, 1, 0, 0, 1, 1]}
|
|
5690
|
+
"""
|
|
5691
|
+
...
|
|
5692
|
+
|
|
5693
|
+
def len(self) -> int:
|
|
5694
|
+
"""Get number of bits (always 8).
|
|
5695
|
+
|
|
5696
|
+
Returns:
|
|
5697
|
+
8
|
|
5698
|
+
"""
|
|
5699
|
+
...
|
|
5700
|
+
|
|
5701
|
+
@staticmethod
|
|
5702
|
+
def from_bits(bits: List[int]) -> 'CSSLByte':
|
|
5703
|
+
"""Create byte from list of bits.
|
|
5704
|
+
|
|
5705
|
+
Args:
|
|
5706
|
+
bits: List of 8 integers (0 or 1)
|
|
5707
|
+
|
|
5708
|
+
Returns:
|
|
5709
|
+
New byte with those bit values
|
|
5710
|
+
|
|
5711
|
+
Example:
|
|
5712
|
+
byte b = Byte.from_bits([1, 0, 0, 0, 0, 0, 0, 0]); // 1
|
|
5713
|
+
"""
|
|
5714
|
+
...
|
|
5715
|
+
|
|
5716
|
+
|
|
5717
|
+
class CSSLAddress:
|
|
5718
|
+
"""CSSL address type - Memory reference (pointer-like).
|
|
5719
|
+
|
|
5720
|
+
An address stores a memory reference to an object and can be used to
|
|
5721
|
+
retrieve the object later using reflect(). Works like a pointer but
|
|
5722
|
+
with Python's reference semantics.
|
|
5723
|
+
|
|
5724
|
+
Declaration in CSSL:
|
|
5725
|
+
address addr = address(someObject);
|
|
5726
|
+
address ptr = memory(obj).get("address");
|
|
5727
|
+
|
|
5728
|
+
Example:
|
|
5729
|
+
string text = "Hello";
|
|
5730
|
+
address addr = address(text);
|
|
5731
|
+
|
|
5732
|
+
// Later, in another function:
|
|
5733
|
+
obj = addr.reflect(); // or reflect(addr)
|
|
5734
|
+
printl(obj); // "Hello"
|
|
5735
|
+
"""
|
|
5736
|
+
|
|
5737
|
+
@property
|
|
5738
|
+
def value(self) -> str:
|
|
5739
|
+
"""Get the address value as a hex string.
|
|
5740
|
+
|
|
5741
|
+
Returns:
|
|
5742
|
+
Address string (e.g., "0x7fff3adb4ed8")
|
|
5743
|
+
|
|
5744
|
+
Example:
|
|
5745
|
+
address addr = address(obj);
|
|
5746
|
+
printl(addr.value); // "0x7fff3adb4ed8"
|
|
5747
|
+
"""
|
|
5748
|
+
...
|
|
5749
|
+
|
|
5750
|
+
def reflect(self) -> Any:
|
|
5751
|
+
"""Reflect the address to get the original object.
|
|
5752
|
+
|
|
5753
|
+
Returns:
|
|
5754
|
+
The object at this address, or None if not found
|
|
5755
|
+
|
|
5756
|
+
Example:
|
|
5757
|
+
string text = "Hello";
|
|
5758
|
+
address addr = address(text);
|
|
5759
|
+
|
|
5760
|
+
// In another function:
|
|
5761
|
+
obj = addr.reflect();
|
|
5762
|
+
printl(obj); // "Hello"
|
|
5763
|
+
"""
|
|
5764
|
+
...
|
|
5765
|
+
|
|
5766
|
+
def is_null(self) -> bool:
|
|
5767
|
+
"""Check if this is a null address.
|
|
5768
|
+
|
|
5769
|
+
Returns:
|
|
5770
|
+
True if address is null (0x0)
|
|
5771
|
+
|
|
5772
|
+
Example:
|
|
5773
|
+
address addr; // Null address
|
|
5774
|
+
if (addr.is_null()) {
|
|
5775
|
+
printl("No address set");
|
|
5776
|
+
}
|
|
5777
|
+
"""
|
|
5778
|
+
...
|
|
5779
|
+
|
|
5780
|
+
def copy(self) -> 'CSSLAddress':
|
|
5781
|
+
"""Create a copy of this address.
|
|
5782
|
+
|
|
5783
|
+
Returns:
|
|
5784
|
+
A new address pointing to the same location
|
|
5785
|
+
"""
|
|
5786
|
+
...
|
|
5787
|
+
|
|
5788
|
+
@staticmethod
|
|
5789
|
+
def from_object(obj: Any) -> 'CSSLAddress':
|
|
5790
|
+
"""Create an Address from any object.
|
|
5791
|
+
|
|
5792
|
+
Args:
|
|
5793
|
+
obj: Object to get address of
|
|
5794
|
+
|
|
5795
|
+
Returns:
|
|
5796
|
+
Address pointing to the object
|
|
5797
|
+
"""
|
|
5798
|
+
...
|
|
5799
|
+
|
|
5800
|
+
|
|
5801
|
+
# Type aliases for quick access
|
|
5802
|
+
bit = CSSLBit
|
|
5803
|
+
byte = CSSLByte
|
|
5804
|
+
address = CSSLAddress
|
|
5805
|
+
|
|
5806
|
+
|
|
5807
|
+
# =============================================================================
|
|
5808
|
+
# ASYNC MODULE (v4.9.3)
|
|
5809
|
+
# =============================================================================
|
|
5810
|
+
|
|
5811
|
+
class CSSLFuture:
|
|
5812
|
+
"""Future - represents the result of an async operation.
|
|
5813
|
+
|
|
5814
|
+
A Future is returned when you call an async function or use async.run().
|
|
5815
|
+
Use await or async.wait() to get the result.
|
|
5816
|
+
|
|
5817
|
+
States:
|
|
5818
|
+
pending - Not started
|
|
5819
|
+
running - Currently executing
|
|
5820
|
+
completed - Finished successfully
|
|
5821
|
+
cancelled - Cancelled before completion
|
|
5822
|
+
failed - Finished with error
|
|
5823
|
+
|
|
5824
|
+
Example:
|
|
5825
|
+
async define fetchData(url) {
|
|
5826
|
+
return http.get(url);
|
|
5827
|
+
}
|
|
5828
|
+
|
|
5829
|
+
// Calling async function returns Future immediately
|
|
5830
|
+
future f = fetchData("http://example.com");
|
|
5831
|
+
|
|
5832
|
+
// Wait for result with await
|
|
5833
|
+
data = await f;
|
|
5834
|
+
|
|
5835
|
+
// Or check state
|
|
5836
|
+
if (f.is_done()) {
|
|
5837
|
+
result = f.result();
|
|
5838
|
+
}
|
|
5839
|
+
"""
|
|
5840
|
+
|
|
5841
|
+
PENDING: str
|
|
5842
|
+
RUNNING: str
|
|
5843
|
+
COMPLETED: str
|
|
5844
|
+
CANCELLED: str
|
|
5845
|
+
FAILED: str
|
|
5846
|
+
|
|
5847
|
+
def result(self, timeout: Optional[float] = None) -> Any:
|
|
5848
|
+
"""Get the result, blocking until complete.
|
|
5849
|
+
|
|
5850
|
+
Args:
|
|
5851
|
+
timeout: Optional timeout in seconds
|
|
5852
|
+
|
|
5853
|
+
Returns:
|
|
5854
|
+
The result of the async operation
|
|
5855
|
+
|
|
5856
|
+
Raises:
|
|
5857
|
+
Exception if operation failed or timed out
|
|
5858
|
+
"""
|
|
5859
|
+
...
|
|
5860
|
+
|
|
5861
|
+
def is_done(self) -> bool:
|
|
5862
|
+
"""Check if the operation has completed (success, fail, or cancel)."""
|
|
5863
|
+
...
|
|
5864
|
+
|
|
5865
|
+
def cancel(self) -> bool:
|
|
5866
|
+
"""Cancel the operation if not yet complete."""
|
|
5867
|
+
...
|
|
5868
|
+
|
|
5869
|
+
def then(self, callback: Callable[[Any], Any]) -> 'CSSLFuture':
|
|
5870
|
+
"""Chain a callback to run when complete.
|
|
5871
|
+
|
|
5872
|
+
Example:
|
|
5873
|
+
fetchData("url").then(lambda data: printl(data));
|
|
5874
|
+
"""
|
|
5875
|
+
...
|
|
5876
|
+
|
|
5877
|
+
|
|
5878
|
+
class CSSLGenerator:
|
|
5879
|
+
"""Generator - lazy iteration via yield.
|
|
5880
|
+
|
|
5881
|
+
Generators produce values on-demand using yield statements.
|
|
5882
|
+
Created by calling a generator function (one that uses yield).
|
|
5883
|
+
|
|
5884
|
+
Example:
|
|
5885
|
+
generator<int> define Range(int n) {
|
|
5886
|
+
int i = 0;
|
|
5887
|
+
while (i < n) {
|
|
5888
|
+
yield i;
|
|
5889
|
+
i = i + 1;
|
|
5890
|
+
}
|
|
5891
|
+
}
|
|
5892
|
+
|
|
5893
|
+
gen = Range(5);
|
|
5894
|
+
while (gen.has_next()) {
|
|
5895
|
+
printl(gen.next()); // 0, 1, 2, 3, 4
|
|
5896
|
+
}
|
|
5897
|
+
|
|
5898
|
+
// Or convert to list
|
|
5899
|
+
numbers = Range(10).to_list(); // [0,1,2,...,9]
|
|
5900
|
+
"""
|
|
5901
|
+
|
|
5902
|
+
def next(self) -> Any:
|
|
5903
|
+
"""Get the next yielded value.
|
|
5904
|
+
|
|
5905
|
+
Returns:
|
|
5906
|
+
The next value from the generator
|
|
5907
|
+
|
|
5908
|
+
Raises:
|
|
5909
|
+
StopIteration when exhausted
|
|
5910
|
+
"""
|
|
5911
|
+
...
|
|
5912
|
+
|
|
5913
|
+
def has_next(self) -> bool:
|
|
5914
|
+
"""Check if more values are available."""
|
|
5915
|
+
...
|
|
5916
|
+
|
|
5917
|
+
def send(self, value: Any) -> Any:
|
|
5918
|
+
"""Send a value into the generator (like Python's gen.send())."""
|
|
5919
|
+
...
|
|
5920
|
+
|
|
5921
|
+
def to_list(self) -> List[Any]:
|
|
5922
|
+
"""Consume all remaining values into a list."""
|
|
5923
|
+
...
|
|
5924
|
+
|
|
5925
|
+
def take(self, n: int) -> List[Any]:
|
|
5926
|
+
"""Take up to n values."""
|
|
5927
|
+
...
|
|
5928
|
+
|
|
5929
|
+
def skip(self, n: int) -> 'CSSLGenerator':
|
|
5930
|
+
"""Skip n values and return remaining as new generator."""
|
|
5931
|
+
...
|
|
5932
|
+
|
|
5933
|
+
|
|
5934
|
+
class AsyncModule:
|
|
5935
|
+
"""Async module - utilities for async/await operations.
|
|
5936
|
+
|
|
5937
|
+
Access via: async.run(), async.wait(), etc.
|
|
5938
|
+
Or: Async.run(), Async.wait(), etc.
|
|
5939
|
+
|
|
5940
|
+
Example:
|
|
5941
|
+
async define slowTask() {
|
|
5942
|
+
async.sleep(1000);
|
|
5943
|
+
return "Done!";
|
|
5944
|
+
}
|
|
5945
|
+
|
|
5946
|
+
future f = async.run(slowTask);
|
|
5947
|
+
result = await f;
|
|
5948
|
+
|
|
5949
|
+
// Or wait for multiple:
|
|
5950
|
+
results = async.all([f1, f2, f3]);
|
|
5951
|
+
|
|
5952
|
+
// First to complete:
|
|
5953
|
+
winner = async.race([f1, f2, f3]);
|
|
5954
|
+
"""
|
|
5955
|
+
|
|
5956
|
+
@staticmethod
|
|
5957
|
+
def run(func: Callable, *args, **kwargs) -> CSSLFuture:
|
|
5958
|
+
"""Run a function asynchronously.
|
|
5959
|
+
|
|
5960
|
+
Args:
|
|
5961
|
+
func: Function to run (async or regular)
|
|
5962
|
+
*args: Arguments to pass
|
|
5963
|
+
**kwargs: Keyword arguments
|
|
5964
|
+
|
|
5965
|
+
Returns:
|
|
5966
|
+
Future representing the operation
|
|
5967
|
+
"""
|
|
5968
|
+
...
|
|
5969
|
+
|
|
5970
|
+
@staticmethod
|
|
5971
|
+
def stop(future_or_name: Union[CSSLFuture, str]) -> bool:
|
|
5972
|
+
"""Cancel an async operation.
|
|
5973
|
+
|
|
5974
|
+
Args:
|
|
5975
|
+
future_or_name: Future to cancel or function name
|
|
5976
|
+
|
|
5977
|
+
Returns:
|
|
5978
|
+
True if cancelled successfully
|
|
5979
|
+
"""
|
|
5980
|
+
...
|
|
5981
|
+
|
|
5982
|
+
@staticmethod
|
|
5983
|
+
def wait(future: CSSLFuture, timeout: Optional[float] = None) -> Any:
|
|
5984
|
+
"""Wait for a future to complete.
|
|
5985
|
+
|
|
5986
|
+
Args:
|
|
5987
|
+
future: The future to wait for
|
|
5988
|
+
timeout: Optional timeout in seconds
|
|
5989
|
+
|
|
5990
|
+
Returns:
|
|
5991
|
+
The result of the future
|
|
5992
|
+
"""
|
|
5993
|
+
...
|
|
5994
|
+
|
|
5995
|
+
@staticmethod
|
|
5996
|
+
def all(futures: List[CSSLFuture], timeout: Optional[float] = None) -> List[Any]:
|
|
5997
|
+
"""Wait for all futures to complete.
|
|
5998
|
+
|
|
5999
|
+
Args:
|
|
6000
|
+
futures: List of futures to wait for
|
|
6001
|
+
timeout: Optional timeout in seconds
|
|
6002
|
+
|
|
6003
|
+
Returns:
|
|
6004
|
+
List of results in same order as input
|
|
6005
|
+
"""
|
|
6006
|
+
...
|
|
6007
|
+
|
|
6008
|
+
@staticmethod
|
|
6009
|
+
def race(futures: List[CSSLFuture], timeout: Optional[float] = None) -> Any:
|
|
6010
|
+
"""Return result of first completed future.
|
|
6011
|
+
|
|
6012
|
+
Args:
|
|
6013
|
+
futures: List of futures to race
|
|
6014
|
+
timeout: Optional timeout in seconds
|
|
6015
|
+
|
|
6016
|
+
Returns:
|
|
6017
|
+
Result of first completed future
|
|
6018
|
+
"""
|
|
6019
|
+
...
|
|
6020
|
+
|
|
6021
|
+
@staticmethod
|
|
6022
|
+
def sleep(ms: int) -> CSSLFuture:
|
|
6023
|
+
"""Async sleep for milliseconds.
|
|
6024
|
+
|
|
6025
|
+
Args:
|
|
6026
|
+
ms: Milliseconds to sleep
|
|
6027
|
+
|
|
6028
|
+
Returns:
|
|
6029
|
+
Future that completes after delay
|
|
6030
|
+
"""
|
|
6031
|
+
...
|
|
6032
|
+
|
|
6033
|
+
|
|
6034
|
+
# Type aliases for async
|
|
6035
|
+
future = CSSLFuture
|
|
6036
|
+
generator = CSSLGenerator
|
|
6037
|
+
|
|
6038
|
+
|
|
4834
6039
|
# =============================================================================
|
|
4835
6040
|
# EXPORTS
|
|
4836
6041
|
# =============================================================================
|
|
@@ -4902,4 +6107,19 @@ __all__ = [
|
|
|
4902
6107
|
"AppendMode", "NonNullAndTypeExclusion",
|
|
4903
6108
|
# Filter functions (filter:: namespace)
|
|
4904
6109
|
"filter_register", "filter_unregister", "filter_list", "filter_exists",
|
|
6110
|
+
# v4.8.4: C++ I/O Streams & Import
|
|
6111
|
+
"cppimport", "include", "cout", "cin", "cerr", "clog", "endl", "flush",
|
|
6112
|
+
"getline", "fstream", "ifstream", "ofstream",
|
|
6113
|
+
"setprecision", "setw", "setfill", "fixed", "scientific",
|
|
6114
|
+
# v4.8.4: Struct & Memory operations
|
|
6115
|
+
"sizeof", "memcpy", "memset", "struct",
|
|
6116
|
+
# v4.8.4: Pipe operations
|
|
6117
|
+
"pipe", "contains_fast",
|
|
6118
|
+
# v4.8.4: Stream types
|
|
6119
|
+
"OutputStream", "InputStream", "FileStream", "Pipe", "CStruct",
|
|
6120
|
+
# v4.9.0: Binary types and address pointer
|
|
6121
|
+
"CSSLBit", "CSSLByte", "CSSLAddress", "bit", "byte", "address", "reflect",
|
|
6122
|
+
# v4.9.3: Async types
|
|
6123
|
+
"CSSLFuture", "CSSLGenerator", "AsyncModule", "future", "generator",
|
|
6124
|
+
"async", "await", "yield",
|
|
4905
6125
|
]
|