Commit Graph

1803 Commits

Author SHA1 Message Date
Christoffer Lerno
0ed917cdc2 Improve error when trying to use an extern const as a compile time constant. #2969 2026-02-23 19:15:30 +01:00
srkkov
8f7610345d More x86 instructions (#2964)
* Added most x86 cryptographic instructions

* Fixed popcnt test

* Fixed asm_ops_x64_2.c3t test

---------

Co-authored-by: Christoffer Lerno <christoffer@aegik.com>
2026-02-23 15:27:36 +01:00
Christoffer Lerno
dc52478c09 - Warn on use of visibility modifiers on methods. #2962 2026-02-21 21:10:08 +01:00
Manu Linares
eae7d0c4a1 stdlib: std::compression::zip and std::compression::deflate (#2930)
* stdlib: implement `std::compression::zip` and `std::compression::deflate`

- C3 implementation of DEFLATE (RFC 1951) and ZIP archive handling.
- Support for reading and writing archives using STORE and DEFLATE
methods.
- Decompression supports both fixed and dynamic Huffman blocks.
- Compression using greedy LZ77 matching.
- Zero dependencies on libc.
- Stream-based entry reading and writing.
- Full unit test coverage.

NOTE: This is an initial implementation. Future improvements could be:

- Optimization of the LZ77 matching (lazy matching).
- Support for dynamic Huffman blocks in compression.
- ZIP64 support for large files/archives.
- Support for encryption and additional compression methods.

* optimizations+refactoring

deflate:
- replace linear search with hash-based match finding.
- implement support for dynamic Huffman blocks using the Package-Merge
algorithm.
- add streaming decompression.
- add buffered StreamBitReader.

zip:
- add ZIP64 support.
- add CP437 and UTF-8 filename encoding detection.
- add DOS date/time conversion and timestamp preservation.
- add ZipEntryReader for streaming entry reads.
- implement ZipArchive.extract and ZipArchive.recover helpers.

other:
- Add `set_modified_time` to std::io;
- Add benchmarks and a few more unit tests.

* zip: add archive comment support

add tests

* forgot to rename the benchmark :(

* detect utf8 names on weird zips

fix method not passed to open_writer

* another edge case where directory doesn't end with /

* testing utilities

- detect encrypted zip
- `ZipArchive.open_writer` default to DEFLATE

* fix zip64 creation, add tests

* fix ZIP header endianness for big-endian compatibility

Update ZipLFH, ZipCDH, ZipEOCD, Zip64EOCD, and Zip64Locator structs to
use little-endian bitstruct types from std::core::bitorder

* fix ZipEntryReader position tracking and seek logic ZIP_METHOD_STORE

added a test to track this

* add package-merge algorithm attribution

Thanks @konimarti

* standalone deflate_benchmark.c3 against `miniz`

* fix integer overflows, leaks and improve safety

* a few safety for 32-bit systems and tests

* deflate compress optimization

* improve match finding, hash updates, and buffer usage

* use ulong for zip offsets

* style changes (#18)

* style changes

* update tests

* style changes in `deflate.c3`

* fix typo

* Allocator first. Some changes to deflate to use `copy_to`

* Fix missing conversion on 32 bits.

* Fix deflate stream. Formatting. Prefer switch over if-elseif

* - Stream functions now use long/ulong rather than isz/usz for seek/available.
- `instream.seek` is replaced by `set_cursor` and `cursor`.
- `instream.available`, `cursor` etc are long/ulong rather than isz/usz to be correct on 32-bit.

* Update to constdef

* Fix test

---------

Co-authored-by: Book-reader <thevoid@outlook.co.nz>
Co-authored-by: Christoffer Lerno <christoffer@aegik.com>
2026-02-20 20:41:34 +01:00
mmoustafa8108
5055e86518 test: added comprehensive tests for in-string & complex nested comments (#2956)
* test: added comprehensive tests for in-string & complex nested comments

* Properly handle error

---------

Co-authored-by: Christoffer Lerno <christoffer.lerno@gmail.com>
2026-02-20 13:24:08 +01:00
Manu Linares
4b13ad692a fixes for RISC-V ABI Implementation #1567 (#2937)
* fixes for RISC-V ABI Implementation #1567

Fixed RISC-V floating-point ABI by correcting the target triple to
`riscv64-unknown-linux-gnu`, adding the `target-abi` module flag, and
ensuring ABI-required CPU features are enabled.

I tested this with:
```bash
build/c3c compile-only --target linux-riscv64 rv_hello.c3
readelf -h obj/linux-riscv64/rv_hello.o | grep Flags
# Output: Flags: 0x5, RVC, double-float ABI
```

```bash
# and qemu because I don't have a riscv machine :/
qemu-riscv64-static -L /usr/riscv64-linux-gnu ./rv_hello
```

---

@lerno I purposedly left these two failing tests to clearly see the
difference.

`test/test_suite/abi/riscv64-lp64-lp64f-abi-1.c3t`
`test/test_suite/abi/riscv64-lp64-abi.c3t`

* improve Linux cross-compilation, specifically for RISC-V

- Implement automatic sysroot and CRT object discovery for RISC-V.
- Fix dynamic linker paths and emulation flags for LLD.
- Link against libgcc to resolve required arithmetic symbols.

* Update tests.

* fix linker CRT detection by centralizing host arch check

use target_host_arch() in linker.c
move target_host_arch() from hostinfo.c to target.c

* missing debug info

---------

Co-authored-by: Christoffer Lerno <christoffer@aegik.com>
2026-02-20 01:53:29 +01:00
Christoffer Lerno
7c81bb35ca Refactored contracts (#2960)
* - Properly support `@deprecated` as contract.
- Support deprecating enum values.
- Refactor contracts

* Always copy enum constants.

* Bugfix.
2026-02-20 01:51:28 +01:00
Christoffer Lerno
5a82f672b5 Update to constdef 2026-02-20 01:13:20 +01:00
Christoffer Lerno
0387d7666d - Trying to slice an indexable type leads to misleading error message #2958 2026-02-20 00:13:45 +01:00
Christoffer Lerno
392c78860d Add bitorder functions store_le, load_le, store_be, store_le. 2026-02-19 23:59:55 +01:00
Christoffer Lerno
585c66100d - Member access on a struct returned by the assignment expression, cause crash #2947 2026-02-19 20:43:45 +01:00
konimarti
8bb974829d math: implement discrete and continuous distributions (#2955)
* math: implement discrete and continuous distributions

Implement a comprehensive set of continuous and discrete probability
distributions with support for PDF, CDF, inverse CDF, random sampling,
mean, and variance calculations.

The following distributions are implemented:
* Normal
* Uniform
* Exponential
* Chi-Squared
* F-Distribution
* Student t
* Binomial
* Poisson

* update releasenotes.md

* Formatting

---------

Co-authored-by: Christoffer Lerno <christoffer@aegik.com>
2026-02-19 20:09:11 +01:00
Damien Wilson
9efb9b90d1 Minor attribute combination checking (#2918)
* Minor attribute combination checking

* Added tests to the test suite.
2026-02-19 17:58:39 +01:00
soerlemans
152558f5bc Optimized adler32 hashing algorithm. (#2948)
* Optimized adler32 implementations.

 - Adapted adler32 implementation from Crypto++ public domain library.
 - Added unit tests for adler32 hashing algorithm.

* tabified adler32 implementation to match stdlib.

* Formatting to be consistent. Make unrolling use macro.

---------

Co-authored-by: soerlemans <sebasoerlemans+git@gmail.com>
Co-authored-by: Christoffer Lerno <christoffer@aegik.com>
2026-02-19 17:51:33 +01:00
Fernando López Guevara
9fbf6bc213 enforce buff channel size > 0 (#2952)
* fix(stdlib): enforce BufferedChannel size > 0 and add regression test

* chore(repo): ignore cmake/test artifacts

* Formatting

---------

Co-authored-by: Christoffer Lerno <christoffer.lerno@gmail.com>
2026-02-18 14:34:41 +01:00
Christoffer Lerno
3ac701be0e Improve error message when providing alias with a typeid expression where a type was expected. #2944 2026-02-17 13:02:34 +01:00
Manu Linares
8cb23cff29 split test_hash_vector_macro into per-type functions (#2940)
* split `test_hash_vector_macro` into per-type functions

it went from a single 18367 instructions function, to eleven separate
functions with (1000 to 1600) instructions each
thats 15649 instructions total, 2718 less instructions overall.

```
$ build/c3c compile-test --suppress-run -O1 --print-large-functions -D
SLOW_TESTS test/unit/ 2>&1 | sort -n | grep "test_hash_vector"
    1041 instructions found in
std::core::builtins:test_hash_vector_int128
(/home/mb/scripts/c3c/test/unit/stdlib/core/builtintests.c3) - function
is very long.
    1041 instructions found in
std::core::builtins:test_hash_vector_uint128
(/home/mb/scripts/c3c/test/unit/stdlib/core/builtintests.c3) - function
is very long.
    1305 instructions found in std::core::builtins:test_hash_vector_long
(/home/mb/scripts/c3c/test/unit/stdlib/core/builtintests.c3) - function
is very long.
    1305 instructions found in
std::core::builtins:test_hash_vector_ulong
(/home/mb/scripts/c3c/test/unit/stdlib/core/builtintests.c3) - function
is very long.
    1453 instructions found in std::core::builtins:test_hash_vector_int
(/home/mb/scripts/c3c/test/unit/stdlib/core/builtintests.c3) - function
is very long.
    1453 instructions found in std::core::builtins:test_hash_vector_uint
(/home/mb/scripts/c3c/test/unit/stdlib/core/builtintests.c3) - function
is very long.
    1565 instructions found in
std::core::builtins:test_hash_vector_short
(/home/mb/scripts/c3c/test/unit/stdlib/core/builtintests.c3) - function
is very long.
    1565 instructions found in
std::core::builtins:test_hash_vector_ushort
(/home/mb/scripts/c3c/test/unit/stdlib/core/builtintests.c3) - function
is very long.
    1629 instructions found in std::core::builtins:test_hash_vector_char
(/home/mb/scripts/c3c/test/unit/stdlib/core/builtintests.c3) - function
is very long.
    1629 instructions found in
std::core::builtins:test_hash_vector_ichar
(/home/mb/scripts/c3c/test/unit/stdlib/core/builtintests.c3) - function
is very long.
    1663 instructions found in std::core::builtins:test_hash_vector_bool
(/home/mb/scripts/c3c/test/unit/stdlib/core/builtintests.c3) - function
is very long.
```

* made the `test_hash_vector_internal` generic
2026-02-17 02:30:30 +01:00
Manu Linares
4b03a84b00 optimize test_ct_intlog2 test and whirlpool hash (#2938)
* optimize `test_ct_intlog2` while still covering all 128 bit positions

* refactor whirlpool to reduce code bloat

replaced the fully unrolled round loop with a runtime loop, reducing
instruction count by 80k in `process_block` and yielding aprox 30%
performance boost due to improved cache locality.

* use compile-time arrays for `test_ct_intlog2`
2026-02-16 01:54:46 +01:00
Christoffer Lerno
990e9685d2 - Adding the incorrect sized vector to a pointer vector would cause a crash. 2026-02-16 00:39:14 +01:00
Christoffer Lerno
a7309b217e Add --print-large-functions for checking which functions likely dominate the compile time. 2026-02-16 00:13:19 +01:00
Christoffer Lerno
a78a169a17 Slim down the string_to_int tests by 800 MB. 2026-02-15 00:05:35 +01:00
Christoffer Lerno
eb80776988 More fixes for typedef @constinit change 2026-02-14 01:37:53 +01:00
Samuel
fac9054f1b Fix array initializer analysis (#2925)
* Fix array initializer analysis: improved semantic checking for arrays with inferred or fixed length,
* Update phrasing

---------

Co-authored-by: Christoffer Lerno <christoffer@aegik.com>
2026-02-13 23:38:07 +01:00
Zack Puhl
768d24d580 [stdlib] Add array even, odd, and unlace macros 2026-02-13 23:19:31 +01:00
Christoffer Lerno
e299a4b630 - Change typedef and const enums to not convert from literals by default. (#2934)
- Add `@constinit` to allow old typedef behaviour.
2026-02-13 20:39:47 +01:00
Christoffer Lerno
acc4a900f5 - New const enum declaration syntax.
- New enum associated value syntax.
2026-02-12 14:43:56 +01:00
Fernando López Guevara
f079fa82b2 fix(std-io): make uint128 decimal formatting safe (#2924)
* fix(std-io): make uint128 decimal formatting safe and add all-base
numeric coverage
---------

Co-authored-by: Christoffer Lerno <christoffer@aegik.com>
2026-02-11 23:50:16 +01:00
Christoffer Lerno
adea3dd83f Fix chacha20 2026-02-11 23:39:47 +01:00
Christoffer Lerno
9b52be9ba6 - unsigned % signed and unsigned / signed is no longer allowed without explicit casts, except for const denominators. #2928 2026-02-11 23:18:08 +01:00
Christoffer Lerno
e2f17a770b Using [] or .foo on $$ functions would not raise error but instead crash #2919. 2026-02-11 02:53:17 +01:00
konimarti
40e6a2c4a3 codepage: add single-byte code page support (#2891)
* codepage: add single-byte code page support

Add std::encoding::codepage with a shared engine for converting between
single-byte code pages and UTF-8 using table-driven mappings.

Introduce generated tables and wrappers for several code pages[1] each
exposing encode/decode helpers built on a common CodePageTable
structure.

The mapping data is generated by cpgen[2] from the Unicode Consortium’s
published code page mapping files and follows the Unicode standard’s
interpretation of control characters (abstract characters) rather than
historical VGA glyph shapes.

[1] Code page overview/groups:

    DOS/OEM code pages (legacy PC):
    cp437 cp737 cp775 cp850 cp852 cp855 cp857 cp860 cp861 cp862 cp863
    cp864 cp865 cp866 cp869 cp874

    Windows code pages (ANSI/Windows):
    cp1250 cp1251 cp1252 cp1253 cp1254 cp1255 cp1256 cp1257 cp1258

    ISO/IEC 8859 series (Latin/Regional):
    iso_8859_1 iso_8859_2 iso_8859_3 iso_8859_4 iso_8859_5 iso_8859_6
    iso_8859_7 iso_8859_8 iso_8859_9 iso_8859_10 iso_8859_11 iso_8859_13
    iso_8859_14 iso_8859_15 iso_8859_16

[2] github.com/konimarti/cpgen

Signed-off-by: Koni Marti <koni.marti@gmail.com>

* codepage: change encoding format, streamline api

* Use enum to collect the data.

---------

Signed-off-by: Koni Marti <koni.marti@gmail.com>
Co-authored-by: Christoffer Lerno <christoffer@aegik.com>
2026-02-11 01:10:12 +01:00
Christoffer Lerno
0542c05b88 Update tests. 2026-02-09 10:23:03 +01:00
Christoffer Lerno
565b08846f Remove use of tempnam. 2026-02-09 00:04:05 +01:00
Christoffer Lerno
80ad0e02ad Fix tests and error in returning error on function name. 2026-02-08 22:54:24 +01:00
Christoffer Lerno
89b9f52f1e Add libc mktemp and tempnam. Update test. 2026-02-07 20:25:28 +01:00
Laura Kirsch
5b93212f43 Added Xorshiro128++ random number generator. (#2846)
* Added Xorshiro128++ random number generator.

* Fixes to xorshiro implementation + tests.

---------

Co-authored-by: Christoffer Lerno <christoffer@aegik.com>
2026-02-06 20:14:56 +01:00
Christoffer Lerno
40aa4d4dcd Add Murmur3 hash 2026-02-06 17:53:19 +01:00
Christoffer Lerno
124efb2684 Improve error message on const int* 2026-02-06 02:00:26 +01:00
Christoffer Lerno
42b79d19c1 Update all stub methods. 2026-02-06 00:55:57 +01:00
Zack Puhl
4521a25284 [stdlib] Add PEM Encoding/Decoding Module (#2858)
* [stdlib] Add PEM Encoding/Decoding Module
* release notes
* Removed some unnecessary macro usages. Fixed memory handling with headers.
* Make end of line a parameter. Internal encode method -> function. Use more tmem. Remove t-functions.
* Update API

---------

Co-authored-by: Christoffer Lerno <christoffer@aegik.com>
Co-authored-by: Christoffer Lerno <christoffer.lerno@gmail.com>
2026-02-06 00:01:07 +01:00
Christoffer Lerno
d71aa10f62 - Const inline enums would not always implicitly get converted to the underlying type.
- Update to dstring.append_string to take any type converting to String.
2026-02-05 13:04:57 +01:00
Christoffer Lerno
dcf695c726 Fix list[0].i = 5 when list[0] returns a pointer. #2888 2026-02-05 00:34:17 +01:00
Christoffer Lerno
5f32c97094 - Compiler crash when using arrays of vectors in lists. #2889 2026-02-04 12:40:16 +01:00
Christoffer Lerno
1c8cb7fa11 Method resolution and $define now works together well unless definitions are out of order for real. 2026-02-04 12:23:37 +01:00
Christoffer Lerno
6bc606a9b1 Removed analyse top pass. Remove sub module tracking. Fix errors where ? should be ~ 2026-02-02 12:20:34 +01:00
Christoffer Lerno
4e129d4ae2 Fix test. 2026-01-30 13:18:56 +01:00
Christoffer Lerno
cb19c7d9e7 Test update 2026-01-29 20:08:58 +01:00
Christoffer Lerno
534dd42472 Update test. 2026-01-29 17:51:50 +01:00
Christoffer Lerno
084d5cbc94 Set target in test. 2026-01-29 02:30:06 +01:00
Christoffer Lerno
32b1df0f86 Set target in test. 2026-01-29 00:43:53 +01:00