Compare commits

...

2465 Commits

Author SHA1 Message Date
Jeroen van Rijn e6475fec4d Merge pull request #4449 from 0dminnimda/add-pie
Link as PIE for PIC by default
2024-11-04 14:25:31 +01:00
gingerBill a0b35f67f8 Fix previous commit for arrays 2024-11-04 12:51:54 +00:00
0dminnimda 5e308cef5e Revert further simplifiction 2024-11-04 15:50:43 +03:00
gingerBill bbf76fa43e Fix bug for foo().bar where foo() is a 0-value expression 2024-11-04 12:49:43 +00:00
0dminnimda 8ad5e46ff8 Simplify further 2024-11-04 15:44:07 +03:00
0dminnimda c26e7e17a1 Simplify use of pie 2024-11-04 15:39:51 +03:00
gingerBill 31ea10490f Fix auto_cast matrix bug 2024-11-04 12:35:17 +00:00
gingerBill aa36ae01cf Fix #4406 os2 to not close the std file handles but rather just free the memory for the ^File data. 2024-11-04 11:55:29 +00:00
Jeroen van Rijn 7a98b58189 Merge pull request #4451 from NicknEma/contextless-marks
Mark procs as "contextless" in winerror.odin
2024-11-04 11:37:32 +01:00
NicknEma cc29b41ccc Mark procs as "contextless" in winerror.odin
So that they can be called from places like the windproc and stuff.
2024-11-04 10:24:27 +01:00
0dminnimda 35f1b0f11e Add support for linking as pie 2024-11-04 02:35:49 +03:00
Jeroen van Rijn 468bd3dfde Merge pull request #4447 from Kelimion/is_aligned
`mem.is_aligned` is in bytes, not log2 bytes
2024-11-03 14:16:23 +01:00
Jeroen van Rijn c33d2ff96b Missing paren. 2024-11-03 14:10:29 +01:00
Jeroen van Rijn 9199c6df34 mem.is_aligned is in bytes, not log2 bytes
Fix formula and clarify comment
2024-11-03 14:07:31 +01:00
Laytan 7cfaf0b181 Merge pull request #4415 from p2jason/master
Remove the event queue from odin.js and directly invoke callbacks so they are executed in context where prevent default is possible
2024-11-01 19:48:36 +01:00
Laytan Laats 8b5492dd4d fix tabs 2024-11-01 18:10:20 +01:00
Laytan Laats 92bc3a5b4d add time/timezone to docs 2024-11-01 18:01:49 +01:00
Laytan Laats 80393cb708 add CoreFoundation and Security to docs 2024-11-01 16:47:48 +01:00
Laytan Laats 7fd32a74c5 add kqueue to docs 2024-11-01 16:42:06 +01:00
Laytan Laats f798f0b446 testing: separate the posix import into target files
This is needed for the docs generator to generate all the docs for the
posix package, if it is imported like it was on Windows it would
generate docs for the Windows version of the package which has much less
symbols exposed.
2024-11-01 16:27:45 +01:00
gingerBill c3971fe5fa Merge pull request #4441 from Barinzaya/raymath-vectortransform-translation-fix
Fix raymath not applying matrix translations
2024-11-01 13:09:31 +00:00
Jeroen van Rijn 73193e99f7 Merge pull request #4442 from peachey2k2/master
Add "-build-mode:dynamic" to the "odin help build" output
2024-11-01 14:03:55 +01:00
peachey2k2 04b000370b Add "-build-mode:dynamic" to the "odin help build" output 2024-11-01 15:51:18 +03:00
Barinzaya 30cf3ed02f Fixed raymath not applying matrix translations.
Translation matrices use the w components of the matrix to apply the
transform, and thus only work when the w component is 1. In the
original raymath implementation, the multiplication is done manually
and adds the translation components directly to the result, as if w is
1, but in the Odin binding this is done with a matrix multiplication.
However, the w component is set to 0 instead of 1, resulting in the
translation not being applied.
2024-10-31 13:37:43 -04:00
p2jason 94acfaf21e Removed event hook callback from add_*_event_listener functions 2024-10-31 13:15:39 +00:00
p2jason e825326d73 Removed event queue from add_*_event_listener JS functions and added event hook callback 2024-10-31 13:02:46 +00:00
Laytan d4d546a63a Merge pull request #4438 from laytan/fixing-threads
fix thread_unix for Darwin after pthread corrections in posix package
2024-10-30 16:10:34 +01:00
Laytan Laats cc3c9bd871 fix thread_unix for Darwin after pthread corrections in posix package
afed3ce removed the sys/unix package and moved over to sys/posix, it has
new bindings for the pthread APIs but should have been equivalent (not).

8fb7182 used `CANCEL_ENABLE :: 0`, `CANCEL_DISABLE :: 1`, `CANCEL_DEFERRED :: 0`, `CANCEL_ASYNCHRONOUS :: 1` for Darwin, while the
correct values are `1`, `0`, `2` and `0` respectively (same mistake was made for
FreeBSD in that commit).

What this meant is that the
`pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS)` was not actually
successful, but because the error wasn't checked it was assumed it was.
It also meant `pthread_setcancelstate(PTHREAD_CANCEL_ENABLE)` would
actually be setting `PTHREAD_CANCEL_DISABLE`.

The code in this PR restores the behaviour by now actually deliberately
setting `PTHREAD_CANCEL_DISABLE` and not setting
`PTHREAD_CANCEL_ASYNCHRONOUS` which was the previous behaviour that does
actually seem to work for some reason.

(I also fixed an issue in fmt where `x` would use uppercase if it was a
pointer.)
2024-10-30 15:51:56 +01:00
gingerBill 8a00d85cea Merge branch 'master' of https://github.com/odin-lang/Odin 2024-10-30 14:12:57 +00:00
gingerBill 2392300ffb Add warning for unsigned >= 0 like conditions in a for loop 2024-10-30 14:12:49 +00:00
gingerBill f469bbb004 Merge pull request #4425 from bobsayshilol/misc-fixes
Misc fixes
2024-10-30 12:24:23 +00:00
gingerBill ee76acd665 Merge pull request #4427 from laytan/posix-additions
Finish sys/posix with Linux and partial Windows support & clean up other packages as a result
2024-10-30 11:43:47 +00:00
gingerBill 8312528a87 Merge pull request #4436 from karl-zylinski/utf8string-last-rune-bug
Fix for using `utf8string.at` with last rune index returning wrong rune
2024-10-30 11:42:47 +00:00
Karl Zylinski 36b958c120 Fix for using utf8string.at with last rune index returning wrong rune. 2024-10-30 11:10:36 +01:00
Jeroen van Rijn d8187d1cf2 Merge pull request #4432 from Kelimion/fix-4431
match_exact_value: return when type is compound
2024-10-29 14:05:07 +01:00
Jeroen van Rijn b46b34228e match_exact_value: return when type is compound
fixes #4431
2024-10-29 13:59:11 +01:00
Laytan 47be77ead5 Merge pull request #4430 from Wyr0X/patch-1
fix cbor.to_json always returning array of tuples for objects
2024-10-29 11:46:51 +01:00
Jeroen van Rijn 28a3a68dc9 Fix image.which_bytes
Invert test in `which_bytes` to fix Softimage PIC detection. Fixes #4429.
2024-10-29 09:55:27 +01:00
Alexis Caraballo 31d5bc48a7 fix cbor.to_json always returning array of tuples for objects
to_json uses a small proc to check if all keys of an object are strings.
It was always returning false for any input.
2024-10-29 01:50:38 -03:00
Laytan 5f99d6b427 Merge pull request #4423 from laytan/rand-choice-bit-set
math/rand: add `choice_bit_set`
2024-10-28 20:23:45 +01:00
Laytan cb2768625a math/rand: choice_bit_set return not_empty -> ok 2024-10-28 20:07:38 +01:00
Laytan 3e024347ee Merge pull request #4426 from SrMordred/patch-1
Update process_windows.odin
2024-10-28 20:06:24 +01:00
Laytan 7e12e37df9 fix test 2024-10-28 19:58:39 +01:00
Laytan b7140875cf port pthread_mutex_t and pthread_cond_t from sys/unix cause miniaudio wants it 2024-10-28 19:42:27 +01:00
Laytan 0b4a4212bb clean up dynlib and path/filepath with sys/posix 2024-10-28 19:21:16 +01:00
Laytan afed3ce6b5 remove pthread from sys/unix and use sys/posix where used 2024-10-28 19:20:43 +01:00
Laytan e064f8c6be fix #load_directory including nested directories 2024-10-28 18:59:39 +01:00
Laytan Laats 1cebc025b0 sys/posix: impl rest of linux, impl some of Windows 2024-10-28 18:59:06 +01:00
Jeroen van Rijn d4e87f7a62 Merge pull request #4421 from IllusionMan1212/fix-escaping-rune-greater-than-U-FFFF
core/io: correctly escape runes greater than 0xFFFF
2024-10-28 14:05:43 +01:00
Patric Dexheimer b6599a52b5 Update process_windows.odin
Mistype
2024-10-27 23:27:18 -03:00
bobsayshilol b59647084b Plug a memory leak
The call to |array_make()| always allocates and since this variable was
unused it lead to a leak. Simply plug it by removing it.
2024-10-27 22:02:34 +00:00
bobsayshilol bb308b3ff4 Add missing guards around push/pop pragmas
This matches all the other places where we silence Windows warnings.
2024-10-27 22:02:34 +00:00
bobsayshilol c1496ab6c0 Fix passing nullptr to args marked as non-null
libstdc++'s |memcpy| and |memset| both state that their inputs should
never be a nullptr since this matches the C spec. Some compilers act on
these hints, so we shouldn't unconditionally call these as it would
signal to the compiler that they can't be nullptrs.

As an example, the following code will always call |do_something()|
when compiled with optimisations since GCC version 4.9:
```
    void clear(void *ptr, int size) {
        memset(ptr, 0, size);
    }
    void example(void *ptr, int size) {
        clear(ptr, size);
        if (ptr != nullptr) do_something();
    }
```
2024-10-27 22:02:34 +00:00
bobsayshilol 4f800a7fda Avoid undefined arithmetic shifting
The result of a left shift on a positive signed integer (Rune) must fit
into an unsigned integer otherwise it's undefined behaviour, as is left
shifting a negative integer by any amount. This code can only be hit if
|x >= 0xf0| and hence a left shift of 31 will always be undefined
unless the input is 0 or 1.

To avoid hitting this we can instead extend the lowest bit to be the
mask if we assume that ints are 2's complement, which we already do
elsewhere. This generates identical code in testing on Compiler
Explorer and the Odin test suite passes locally with this change.

Note that the original code would change to be defined behaviour in
C++20, however we are currently build with |-std=c++14| in the build
scripts.
2024-10-27 22:02:34 +00:00
bobsayshilol e67692b066 Avoid member access through nullptr in debug
If |result_count| is 0 then |results| will be a nullptr and hence the
access |results->Tuple| is undefined behaviour. There's already an
early return in the 0 branch so move that to be the first thing so that
we can guarantee that it's not a nullptr.

Note that technically we take the address of the result so it's not
actually dereferencing it, however UBSan doesn't care about that.
2024-10-27 22:02:34 +00:00
bobsayshilol 771d308d64 Fix invalid union access
UBSan spotted that |src->Basic.kind| had a value outside the range of
|BasicKind| due to it actually being a |Type_Pointer|. Since these are
stored in a union there could be cases where the value of |kind| just
so happens to be |Basic_string|, in which case the branch would have
been taken when it shouldn't have been.

To fix this simply check that it's a |Type_Basic| before treating it as
a |Basic|.
2024-10-27 21:24:36 +00:00
gingerBill 1f187adff4 Merge pull request #4416 from Yawning/fix/4413
src/big_int.cpp: Use square-multiply for exponentiation
2024-10-27 12:13:40 +00:00
gingerBill 35d818bb4e Fix possible leak in recursive filepath.glob 2024-10-27 12:10:10 +00:00
gingerBill f32e27d2e4 Fix bug caused due to incorrect type checking looking for context not defined in a context 2024-10-27 11:10:55 +00:00
Laytan Laats 69d375705e fix the typeid type kind of a typeid being set to Typeid_Invalid 2024-10-27 01:11:44 +02:00
Laytan Laats 44eef21997 wgpu: add missing JS impl for RenderPassEncoderSetBlendConstant 2024-10-26 22:41:52 +02:00
Laytan Laats bd38b4839c sys/wasm/js: add set_element_style 2024-10-26 22:41:14 +02:00
Laytan Laats 4608d26e6e encoding/cbor: fix skipping of ignored/missing fields in struct unmarshal 2024-10-26 22:39:46 +02:00
Laytan 1e3a924e11 Merge pull request #4420 from laytan/cbor-better-handling-of-mismatch-in-struct-and-binary-fields
encoding/cbor: handle binary having more fields than the struct by discarding
2024-10-26 17:14:44 +02:00
Laytan Laats 10c2f8dbeb math/rand: add choice_bit_set 2024-10-26 13:50:28 +02:00
IllusionMan1212 8906ffb39c core/io: correctly escape runes greater than 0xFFFF 2024-10-26 01:25:12 +02:00
Jeroen van Rijn 831558a7c2 Merge pull request #4419 from laytan/rand-choice-enum-non-contiguous
math/rand: support non-contiguous enums in choice_enum
2024-10-25 23:46:05 +02:00
Laytan Laats bb4fc9979a math/rand: support non-contiguous enums in choice_enum 2024-10-25 20:41:57 +02:00
Laytan Laats 793ef6012b encoding/cbor: handle binary having more fields than the struct by discarding 2024-10-25 20:37:55 +02:00
Laytan 3b6ed2164b Merge pull request #4399 from laytan/wgpu-improvements
wgpu: take version check out of @init, use C cc when appropriate
2024-10-25 20:15:15 +02:00
Laytan 0b8e98febe Merge pull request #4398 from laytan/image-misuse-panic
image: add panic when load is called without any registered loaders
2024-10-25 20:05:32 +02:00
gingerBill 4bde87de8f Merge pull request #4418 from laytan/check-packed-on-all-loads
check packed load and set alignment on all loads, not just lb_emit_load
2024-10-25 14:35:32 +01:00
Laytan Laats bcf2b93c6e quote the dsymutil argument
Fixes #4417
2024-10-25 15:34:59 +02:00
Laytan Laats da1e09c95d check packed load and set alignment on all loads, not just lb_emit_load 2024-10-25 15:23:15 +02:00
p2jason cf89526a9f Changed boolean parameters to bit set in the add_*_event_listener functions 2024-10-25 12:45:24 +01:00
Yawning Angel 61795232f4 src/big_int.cpp: Use square-multiply for exponentiation
For utterly unrealistic constant sizes, this still crashes on my system,
but it crashes fast due to the OOM killer, and people using rediculously
large exponents get what they deserve.
2024-10-25 11:46:47 +09:00
p2jason 8371995bfc Added parameters to the add_*_event_listener JS functions for stopping event behavior 2024-10-24 23:27:40 +01:00
gingerBill f047f804f6 Merge pull request #4402 from Lperlind/utf16_rune_count
core/unicode/utf16: add rune_count proc
2024-10-23 15:25:21 +01:00
gingerBill 33cc671302 Merge pull request #4403 from tf2spi/issue-4390-fix
Fix #4390 by assigning invalid entity type
2024-10-23 15:25:06 +01:00
gingerBill c5ae7daecd Merge pull request #4404 from tf2spi/issue-4395-fix
Fixes #4395 by not assuming simd returns val
2024-10-23 15:24:59 +01:00
gingerBill 8cba4aa1c3 Merge pull request #4410 from tf2spi/issue-4397-fix
Fix magnitude check in parse_f64_prefix
2024-10-23 15:24:48 +01:00
gingerBill 70bff68f69 Merge pull request #4408 from Lperlind/cache
cached.cpp: Improve internal cached robustness
2024-10-23 15:15:58 +01:00
Misomosi a9f2271a90 Fix magnitude check in parse_f64_prefix 2024-10-22 21:27:39 -04:00
laytan 50597e8691 fix erronous updating alignment of external global 2024-10-22 17:34:49 +02:00
Jeroen van Rijn 00ec862b63 Merge pull request #4335 from colrdavidson/datetime_tz
Add Timezone Support to Odin
2024-10-22 10:18:38 +02:00
Lucas Perlind 28b26043fb cached.cpp: Improve internal cached robustness
Do not memory map files; Windows cannot write to a file that is memory
mapped.
Write cache after llvm building. This ensures the cache won't have a
false positive if llvm fails.
2024-10-22 18:05:01 +11:00
Colin Davidson d8696badb6 add better comment about freebsd hacks 2024-10-21 21:58:32 -07:00
Colin Davidson 9e00d610c8 Update core/time/timezone/tzdate.odin
Co-authored-by: Feoramund <161657516+Feoramund@users.noreply.github.com>
2024-10-21 21:49:19 -07:00
Colin Davidson d393d3292f Update core/time/timezone/tzdate.odin
Co-authored-by: Feoramund <161657516+Feoramund@users.noreply.github.com>
2024-10-21 21:48:58 -07:00
Misomosi 6ef915c312 Fixes #4395 by not assuming simd returns val 2024-10-20 22:51:39 -04:00
Misomosi 01c7380df8 Fix #4390 by assigning invalid entity type 2024-10-20 22:45:30 -04:00
Lucas Perlind 66c53a1174 core/unicode/utf16: add rune_count proc
This returns the number of runes in a u16 slice
2024-10-21 08:29:07 +11:00
Laytan 7c1922b0a7 Merge pull request #4401 from tgolsson/ts/cbor-unmarshal-dynarray
cbor: fix capacity and ptr calculation for dynarray unmarshal
2024-10-20 21:40:05 +02:00
Tom Solberg 90a0c834bb cbor: fix capacity and ptr calculation for dynarray unmarshal 2024-10-20 21:27:16 +02:00
Laytan Laats c8ed499293 image: add panic when load is called without any registered loaders 2024-10-20 18:41:10 +02:00
Laytan Laats 62922a421c wgpu: take version check out of @init, use C cc when appropriate 2024-10-20 18:40:17 +02:00
Laytan Laats 9f609dd740 odin/parser: fix offsets of value declarations
Fixes #4356
2024-10-19 20:02:39 +02:00
gingerBill b6cbdf7c54 Merge pull request #4370 from IllusionMan1212/allow-e000-codepoint
fix(core:{odin,c}/tokenizer): Don't error on valid \uE000 codepoint
2024-10-19 18:12:08 +01:00
Laytan Laats e79f94ca5e encoding/json: fix leak when string is unmarshalled into non-string field
Fixes #4391
2024-10-19 17:08:24 +02:00
Laytan Laats b82f8df5f5 possibly fix not having shared dir in recent windows releases
Probably caused by https://github.com/actions/upload-artifact/issues/602
Possibly fixes #4384
2024-10-17 18:05:37 +02:00
Laytan 2141299d2b Merge pull request #4376 from Barinzaya/sysinfo-avx512
core:sys/info AVX-512 CPU Features
2024-10-16 19:46:01 +02:00
Laytan 1cb93efe8a Merge pull request #4382 from Barinzaya/time_32b_linux_overflow
Fixed core:time overflows on 32-bit Linux
2024-10-16 18:27:28 +02:00
Barinzaya 142e7d6b52 Fixed time overflows that occur when running in a 32-bit Linux target. 2024-10-15 13:43:28 -04:00
Barinzaya 872a29752c Renamed and trimmed AVX-512 features in sys/info.
Removed underscores from the AVX-512 names in `CPU_Feature` to make them match their equivalent LLVM target features. Removed 4FMAPs and 4VNNIW as there aren't matching LLVM target features.
2024-10-15 05:21:35 -04:00
Laytan Laats 7989d512a0 add macos 15.0.1 to odin report and core/sys/info 2024-10-14 16:19:03 +02:00
Laytan Laats 1dd9b8560d build mutex allocator code on freestanding wasm 2024-10-14 16:11:25 +02:00
Laytan Laats b746e5287e build tracking allocator code on freestanding wasm 2024-10-14 16:06:16 +02:00
Barinzaya ff35a59548 Fixed a theoretical edge case in AVX512VL support detection. 2024-10-14 09:13:27 -04:00
Barinzaya c93923c9f7 Fixed formatting. 2024-10-14 08:53:16 -04:00
Barinzaya 0e4ed515b9 Added AVX-512 feature detection to core:sys/info. 2024-10-14 08:20:23 -04:00
gingerBill 417e9bb37f Fix #4373 2024-10-13 22:26:04 +01:00
Laytan 0157ff1541 Merge pull request #4118 from andradei/posix-linux
Linux POSIX support
2024-10-13 20:05:03 +02:00
Laytan 591f827e5f Merge pull request #4371 from beaumccartney/mach-enum-member-aliases
mach darwin: enum member aliases are other enum members, not constants
2024-10-13 20:00:06 +02:00
gingerBill 55ff1769d0 Merge pull request #4368 from bersK/rlgl-binding-enablecolorblending-fix
[vendor:raylib/rlgl] Add `EnableColorBlend()` binding
2024-10-13 13:21:27 +01:00
Beau McCartney e240c034de aliases to enum members are other enum members, not constants 2024-10-12 20:11:46 -06:00
IllusionMan1212 d52e0a892c fix(core:{odin,c}/tokenizer): Don't error on valid \uE000 codepoint 2024-10-13 00:01:41 +02:00
Stefan Stefanov f112c27f7d rlgl: Add EnableColorBlend() 2024-10-12 20:01:27 +03:00
gingerBill 8006ba919e Improve formatting 2024-10-11 14:48:55 +01:00
Laytan 16eac6c844 Merge pull request #4357 from beaumccartney/mach-vm-apis
bindings, types, and constants for some mach vm apis
2024-10-10 20:04:20 +02:00
Colin Davidson 5bf8852b2e add julian day rule resolvers 2024-10-10 10:31:46 -07:00
Beau McCartney 77cf4373a8 sync policy enum 2024-10-10 11:24:55 -06:00
Colin Davidson 19c2b4d54f swap datetime_to_str to aprintf 2024-10-10 10:17:02 -07:00
Beau McCartney 4fffd1b271 kern return: doc comments above enum members 2024-10-10 11:12:42 -06:00
Beau McCartney 66c902406d align by space instead of colon 2024-10-10 11:09:06 -06:00
Beau McCartney 3aae1740c7 proc ( -> proc( 2024-10-10 11:03:55 -06:00
Colin Davidson fcaa3abe47 delete local_str with the appropriate allocator 2024-10-10 09:24:50 -07:00
Colin Davidson ba6203f8d3 sort out windows enum names too 2024-10-10 09:19:04 -07:00
Colin Davidson 4c8e355444 tweaks per laytan suggestions 2024-10-10 09:14:29 -07:00
Colin Davidson a6502c3e8c Initial cut of timezones 2024-10-09 19:26:43 -07:00
Jeroen van Rijn 4e07d3f1d3 Merge pull request #4360 from frwdrik/patch-1
Fix typo in demo.odin
2024-10-09 19:00:23 +02:00
Fredrik Vaeng Røtnes 15a8970493 Fix typo in demo.odin 2024-10-09 16:44:17 +00:00
Jeroen van Rijn 6f23b5bb60 Fix #4359
Fixes #4359
2024-10-09 14:31:01 +02:00
Beau McCartney b0ff41e673 indent with tabs not spaces 2024-10-08 19:08:13 -06:00
Beau McCartney 41c717de3f vm_flags as a bitset 2024-10-08 19:08:13 -06:00
Beau McCartney fee99c0800 move doc comment to right spot 2024-10-08 13:41:13 -06:00
Beau McCartney 58745bc7ae use b32 for boolean_t 2024-10-08 13:39:53 -06:00
Laytan Laats 5c63617191 net: fix leaking sockets in listen_tcp if an error occurs 2024-10-08 21:08:14 +02:00
Laytan Laats d8af35f01e net: fix leaking sockets in dial_tcp if connect errors 2024-10-08 21:01:57 +02:00
Beau McCartney 27753ff7a8 VM_INHERIT_* as an enum 2024-10-08 12:51:18 -06:00
Beau McCartney 9004441e43 VM_PROT_* flags as a bitset 2024-10-08 12:51:12 -06:00
Beau McCartney 2695b269a4 kern return as an enum 2024-10-08 12:44:49 -06:00
Beau McCartney 67252ff415 make some types and procs match the c apis
procs:
| type          | old  | new (matching c api)|
| ---           | ---- | ------------------- |
| kern_return_t | u64  | c.int               |
| thread_t      | u64  | mach_port_t         |
| task_t        | u64  | mach_port_t         |
| semaphore_t   | u64  | mach_port_t         |

for mach_task_self(), return mach_port_t instead of task_t

for semaphore_signal_thread(), accept a thread_t instead of a thread_act_t
2024-10-08 12:12:21 -06:00
gingerBill b839d06ac8 Merge branch 'master' of https://github.com/odin-lang/Odin 2024-10-08 11:58:28 +01:00
gingerBill 131e8d4187 Disable exe path test 2024-10-08 11:57:54 +01:00
Beau McCartney db8950922c add mach_port_deallocate - frees the port from mach_make_memory_entry() 2024-10-07 15:48:24 -06:00
Laytan Laats 6bf70b60d6 os/os2: add default permissions to write_entire_file 2024-10-07 22:31:43 +02:00
Beau McCartney 7b1086b489 make aliases of vm types not distinct
I think they're meant to be used interchangeably, just typedefed to have more
clear names for certain contexts
2024-10-07 14:24:38 -06:00
Laytan Laats 4b8462aa70 os/os2: fix mkdir_all on posix with abs path 2024-10-07 22:11:16 +02:00
Beau McCartney f858374ef2 small cleanup 2024-10-07 11:45:45 -06:00
Beau McCartney eaafe92402 remove vm_flags_t - not in the original sdk 2024-10-07 11:45:24 -06:00
Beau McCartney 15d70390e5 add missing trailing comma 2024-10-06 23:29:34 -06:00
Beau McCartney 75c5cf3e80 indent with tabs, not spaces 2024-10-06 23:02:36 -06:00
Beau McCartney 609eb00335 remove note comments 2024-10-06 22:47:46 -06:00
Beau McCartney 2fc04f29c8 make extra types distinct to fit existing types 2024-10-06 22:47:20 -06:00
Beau McCartney 5c0c1287dc put function parameters on the same line where possible to fit style 2024-10-06 22:45:10 -06:00
Beau McCartney ac4f4e883a group type definitions 2024-10-06 22:41:42 -06:00
Beau McCartney 80c390e851 add mach procedures and vm_page_size
- vm_allocate()
- vm_deallocate()
- vm_map()
- mach_make_memory_entry()
2024-10-06 22:08:23 -06:00
Jeroen van Rijn c50eaa0b77 Merge pull request #4352 from avanspector/master
build.bat: remove wmic and mandatory git requirement
2024-10-06 21:27:13 +02:00
avanspector 46ca1c8b32 Merge branch 'odin-lang:master' into master 2024-10-06 20:47:18 +02:00
avanspector bb29304029 remove wmic and mandatory git requirement 2024-10-06 20:46:41 +02:00
gingerBill ed29c881a5 Merge pull request #4351 from jakubtomsu/sys-windows-file-flags
[core:sys/windows] Add more FILE_FLAGs
2024-10-06 19:31:27 +01:00
jakubtomsu 0b74a661e3 add file flags like in WinBase.h 2024-10-06 19:53:04 +02:00
Beau McCartney a205bcd0da add VM_INHERIT constants 2024-10-05 11:19:10 -06:00
Beau McCartney 27daebf46c add vm_prot_t constants 2024-10-05 11:18:32 -06:00
Beau McCartney 04ddcc5e64 add VM_FLAGS constants 2024-10-05 11:17:37 -06:00
Beau McCartney 7eabb1d744 add KERN_RETURN constants 2024-10-05 11:15:29 -06:00
Beau McCartney 3c2efb24b7 some mach types 2024-10-05 11:11:42 -06:00
Beau McCartney 2181a42bbf rename mach import cause its not just for threads now 2024-10-05 11:09:58 -06:00
Laytan cf8f138c61 Merge pull request #4349 from MoritzHamann/master
Fix build for linux aarch64 architectures
2024-10-05 13:50:12 +02:00
Moritz 249242687c Fix build for linux aarch64 architectures
Build failed to compile on Raspberry Pi 4, with

clang: error: the clang compiler does not support '-march=native'

The build script checks $OS_ARCH for `arm64` to distinghuish between ARM
and X64 architecture. However on Raspberry Pi, the `uname -m` command
reports `aarch64` rather than `arm64`.

This change updates the EXTRAFLAGS of the `release-native` target to
check for both - `arm64` and `aarch64`.
2024-10-05 12:09:39 +01:00
Laytan 60eac68be7 Merge pull request #4346 from flysand7/os2-fix-process-exec
Don't append to buffer if nothing was read
2024-10-05 11:32:14 +02:00
Laytan Laats c21e62ddb4 reset n before stderr path too 2024-10-05 11:26:23 +02:00
flysand7 f61996fd6f Don't append to buffer if nothing was read 2024-10-05 11:06:36 +11:00
Laytan b5f7332ffb Merge pull request #4272 from flysand7/os2-noquote
[os2/process]: Don't quote arguments unless needed
2024-10-04 23:12:07 +02:00
flysand7 dad418cf91 Remove unused things 2024-10-05 07:23:15 +11:00
Laytan d0eae4a9ad Merge pull request #4342 from laytan/process-exec-improv
fix os2.process_exec on non-windows and add a smoke test
2024-10-04 19:09:13 +02:00
Laytan 54ffd6df06 better error handling 2024-10-04 15:08:21 +02:00
Laytan a3c3e5c822 reset err 2024-10-04 14:53:16 +02:00
Laytan cf705d4b29 wait instead of kill 2024-10-04 14:50:26 +02:00
Laytan 861efa4e54 Revert "add some debug logs"
This reverts commit 31ee829b44.
2024-10-04 13:58:59 +02:00
Laytan 59086a24a1 add .ENOSYS == .Unsupported for posix too 2024-10-04 13:52:54 +02:00
Laytan 424dc590a3 fix bsds process_open 2024-10-04 13:52:44 +02:00
Laytan 31ee829b44 add some debug logs 2024-10-04 13:40:25 +02:00
gingerBill abbbfd2925 Merge pull request #4340 from karl-zylinski/make-map
Add make_map that just sets the allocator without allocating anything
2024-10-04 12:26:32 +01:00
gingerBill 9fe8095a84 Merge pull request #4338 from laytan/fix-ternary-swallow-error
fix not erroring on invalid ternary
2024-10-04 12:25:54 +01:00
Laytan d9cfe692a9 make sure stdout and stderr always point to allocation 2024-10-04 13:24:40 +02:00
Laytan 64508e477b add unsupported check in process test 2024-10-04 13:24:24 +02:00
Laytan 563ed69c28 fix deadlock when in write_errno_to_parent_and_abort state 2024-10-04 13:24:14 +02:00
gingerBill c305c9dd04 [ABI FIX] Fix 128-bit ABI issues 2024-10-04 11:16:33 +01:00
gingerBill dd7c88989a Merge pull request #4341 from laytan/fix-quaternion64-arith
fix quaternion64 arith
2024-10-04 10:25:00 +01:00
Laytan Laats 386f144cca satisfy -vet 2024-10-04 10:54:27 +02:00
Laytan Laats 1d29dfd037 kill process if waiting didn't make it exit to avoid a zombie 2024-10-04 10:51:40 +02:00
Laytan Laats ae69f4b749 general cleanup 2024-10-04 10:50:14 +02:00
Laytan Laats 0b5cd3400f use dynamic array instead of string builder 2024-10-04 10:43:38 +02:00
Laytan Laats 77b033cf96 kill process if there was an error during reading to not leave a zombie 2024-10-04 10:38:47 +02:00
Laytan Laats 5d556fe277 fix idtype definition 2024-10-03 15:25:51 +02:00
Laytan Laats af8b592bf6 enable test on bsds 2024-10-03 14:45:45 +02:00
Laytan Laats 7676480526 fix temp allocator guard bug 2024-10-03 14:39:54 +02:00
Laytan Laats 77780f9ce8 fix use-after-free - closing wrong pipe 2024-10-03 14:24:00 +02:00
Laytan Laats a78cd48aa3 remove posix signal test, it isn't thread safe 2024-10-03 13:51:31 +02:00
Laytan Laats 76806080ef fix os2.process_exec on non-windows and add a smoke test 2024-10-03 13:51:27 +02:00
Laytan Laats 5d4fd09ff0 fix quaternion64 arith
Fixes #4282
2024-10-02 23:28:09 +02:00
Laytan Laats 0d834a2c2e fix paths 2024-10-02 17:52:12 +02:00
Laytan Laats 55e9a1b971 fix benchmarks not compiling and make sure it doesn't happen again by checking 2024-10-02 17:48:05 +02:00
Karl Zylinski fd05d94789 Add make_map that just takes an allocator and no capacity, similar to make_dynamic_array. This renames the old make_map to make_map_cap. 2024-10-02 17:47:04 +02:00
gingerBill 53bb6c85f7 a ordered to an ordered 2024-10-02 15:48:58 +01:00
gingerBill 21d0b073b1 Sort flags on odin build -help - #4329 2024-10-02 15:43:13 +01:00
gingerBill 3498d4341d Fix #4330 2024-10-02 15:07:22 +01:00
gingerBill aeb568f79a Ignore package runtime with using -vet-unused-packages 2024-10-02 15:04:50 +01:00
Laytan Laats 3ff887c6b6 fix not erroring on invalid ternary
For example: `a: f32 = true ? 1 : len` would get to the back-end without
errors.

Fixes #1690
2024-10-02 15:55:46 +02:00
Jeroen van Rijn 613f231fed Merge pull request #4336 from Kelimion/slice_to_type
Add `slice.to_type`
2024-10-01 23:45:59 +02:00
Jeroen van Rijn eba7be34e7 Add slice.to_type 2024-10-01 23:27:15 +02:00
gingerBill af9ae4897a Merge pull request #4290 from flysand7/pipe-has-data
[os2/process]: Implement `process_exec`, and `pipe_has_data`
2024-10-01 11:30:28 +01:00
gingerBill 9f813a6263 Merge pull request #4331 from olimpiu/patch-1
Fixed confusing (and incorrect) warning
2024-10-01 11:29:45 +01:00
olimpiu 5d57fe77be Fixed confusing (and incorrect) warning
Verbose errors *is* the new default
2024-09-30 20:46:03 -04:00
Laytan Laats ab54ad3a75 sys/posix: use '#max_field_align' 2024-09-30 16:39:14 +02:00
gingerBill 9919a0cacd Merge branch 'master' of https://github.com/odin-lang/Odin 2024-09-30 15:35:52 +01:00
gingerBill 91dece1656 Change struct alignment rules for #max_field_align 2024-09-30 15:35:47 +01:00
Laytan 5cd1784d41 review/correct/cleanup posix linux PR 2024-09-30 16:00:46 +02:00
gingerBill 1e1904e9ab Merge pull request #4323 from laytan/bit-array-init
container/bit_array: add 'init' procedure
2024-09-30 15:00:45 +01:00
gingerBill d6f6099419 Merge pull request #4324 from laytan/va-list-stb-sprintf-raylib-fixe
va_list fixes for raylib & stb sprintf
2024-09-30 15:00:14 +01:00
gingerBill d712ea43eb Merge pull request #4325 from mtarik34b/document-container-of-proc
Add documentation to `runtime.container_of`
2024-09-30 15:00:03 +01:00
gingerBill 962af780ae Merge pull request #4328 from Yawning/fix/cshake-bytepad
core/crypto/_sha3: Fix edge case in cSHAKE bytepad
2024-09-30 13:56:31 +01:00
Yawning Angel cf7d705c1f core/crypto/_sha3: Fix edge case in cSHAKE bytepad
If the domain separator happens to be exactly the rate, we would
previously incorrectly add another rate-bytes of 0s.
2024-09-30 21:50:18 +09:00
gingerBill a7d7c92a53 #min_field_align & #max_field_align; deprecate #field_align in favour of #min_field_align 2024-09-30 13:05:28 +01:00
gingerBill 4b6410e225 ABI BREAKING for SysV: Change how multiple return values are handled to be separate like all other ABIs 2024-09-30 12:32:55 +01:00
gingerBill b173fa1b9a Fix LLVM 18 ABI for 128-bit integers (because LLVM broke things) 2024-09-30 11:45:24 +01:00
gingerBill 225ffdec36 Fix union comparison bug 2024-09-30 11:10:16 +01:00
Jeroen van Rijn 7f9cfd1579 Merge pull request #4327 from beaumccartney/fix-deferred-attrib-error-report
fix #4326
2024-09-30 08:01:36 +02:00
Beau McCartney e3eea1b9fa print proc types in same order as procs 2024-09-29 23:55:55 -06:00
Beau McCartney fe8325f0ad fix deferred procedure errors 2024-09-29 23:34:09 -06:00
Laytan 38fedf2631 Merge pull request #4304 from kawaii-Code/linear_search_reverse
Add linear_search_reverse and linear_search_reverse_proc
2024-09-29 21:18:49 +02:00
Nia 253edb51f7 Fix markup in linear_search and binary_search docs 2024-09-29 17:08:54 +03:00
mtarik34b 82aefd4203 Add documentation to runtime.container_of 2024-09-29 16:04:39 +02:00
Nia 3c80f15a7a Remove pointless #no_bounds_check 2024-09-29 15:51:30 +03:00
Laytan 085b725774 Merge pull request #4302 from Pariatech/enable_static_glfw_linux
Add static GLFW bindings for Linux
2024-09-29 13:55:36 +02:00
Gabriel Pariat 3039131a5f do recommendation 2024-09-29 07:46:01 -04:00
Laytan daa3bb9a3b Merge pull request #4322 from laytan/fix-errors-not-printed-after-parse-warnings
fix errors not being printed after parse warnings
2024-09-29 12:51:21 +02:00
Laytan Laats 152479052e va_list fixes for raylib & stb sprintf 2024-09-29 11:45:57 +02:00
gingerBill 90cb62c5ac Merge branch 'master' of https://github.com/odin-lang/Odin 2024-09-29 10:15:02 +01:00
gingerBill 4a616d97df Pass delta time instead of current time to odin.js step 2024-09-29 10:14:56 +01:00
Laytan Laats 642ecc363b fix errors not being printed after parse warnings
Fixes #4299
2024-09-29 11:04:37 +02:00
Laytan Laats bd45900257 container/bit_array: add 'init' procedure 2024-09-29 10:57:42 +02:00
Laytan Laats eccb548935 fix box2d World_Draw not taking a pointer 2024-09-29 10:50:31 +02:00
Laytan a82f26f4c0 Merge pull request #4320 from laytan/fix-wgpu-examples-after-js-move
fix wgpu examples after move of files in 95721fe
2024-09-29 10:46:13 +02:00
Laytan Laats eeaa9f048b fix wgpu examples after move of files in 95721fe 2024-09-29 10:39:28 +02:00
flysand7 ca9cfc7167 remove extra binary 2024-09-29 08:01:47 +11:00
flysand7 0e446e1d68 adjust docs 2024-09-29 07:54:29 +11:00
gingerBill 90d024fb70 Merge pull request #4310 from wrapperup/fix-vulkan-wrapper
`vendor:vulkan` Update header files (to 1.3.296) and fix code generation
2024-09-28 18:22:17 +01:00
flysand7 d830069e5c [os2/process]: Implement process_exec 2024-09-28 11:25:32 +11:00
flysand7 7deb28c810 [os2/process]: Unindent doc comments 2024-09-28 10:30:54 +11:00
wrapperup 2b5c2cab1f generate new vulkan files (1.3.296) 2024-09-26 18:20:00 -04:00
wrapperup 39c8749d8f fix mismatching type generation with newer vulkan headers 2024-09-26 18:16:38 -04:00
gingerBill 4f2915a9b5 Merge pull request #4307 from flysand7/ptrace-user-regs
Fix missing registers in User_Regs on AMD64
2024-09-26 16:41:28 +01:00
gingerBill d3bff23bce Merge pull request #4308 from karl-zylinski/fix-constant-array-conversion-crash
Fix for crash when emitting a comparison between a constant array and a non-constant value.
2024-09-26 16:40:43 +01:00
Karl Zylinski 007730bfbc Fix for crash when emitting a comparison between a constant array and a non-constant value. 2024-09-25 23:42:35 +02:00
flysand7 e54b1560ee Add missing registers in User_Regs on AMD64 2024-09-26 07:27:11 +11:00
flysand7 abd52529a6 Revert "Add missing registers in User_Regs on AMD64"
This reverts commit acfac3cf2d.
2024-09-26 07:26:01 +11:00
flysand7 acfac3cf2d Add missing registers in User_Regs on AMD64 2024-09-26 07:25:40 +11:00
flysand7 842f1ae304 Fix indentation issues 2024-09-26 07:13:00 +11:00
gingerBill 8371ef6681 Merge pull request #4279 from obiwan87/master
Fix compile errors
2024-09-25 17:32:30 +01:00
gingerBill 987faa3f18 Merge pull request #4280 from Feoramund/fix-4278
Forbid parsing more fields if no separator was found
2024-09-25 16:12:33 +01:00
gingerBill e397fb6a7f Merge pull request #4297 from flysand7/ini-section
[encoding/ini]: Add missing line terminator at the end of the section
2024-09-25 16:07:03 +01:00
Nia 3337d6b264 Add linear_search_reverse and linear_search_reverse_proc 2024-09-25 16:41:55 +03:00
Gabriel Pariat fdc56c4d9a adding binding for static for linux 2024-09-24 19:44:11 -04:00
Jeroen van Rijn 791b05b14f Merge pull request #2600 from Hyrtwol/icon-for-odin-exe
Icon for odin.exe
2024-09-24 17:03:38 +02:00
flysand7 45d26dc7f9 [encoding/ini]: Add missing line terminator at the end of the section 2024-09-24 18:57:42 +11:00
flysand7 dbad23385d [os2]: Implement pipe_has_data procedure 2024-09-24 08:12:21 +11:00
Antonino Simone Di Stefano e9e7863033 Merge branch 'odin-lang:master' into master 2024-09-22 23:32:22 +02:00
Antonino Simone Di Stefano 5bced00f5d Return Allocator_Error in map_entry_infos 2024-09-22 23:25:46 +02:00
Antonino Simone Di Stefano 357c8f6f34 Replace "." with "," in parameter list 2024-09-22 23:19:36 +02:00
Antonino Simone Di Stefano baf5a06fba Remove address operator, which lead to a type error 2024-09-22 23:16:59 +02:00
Antonino Simone Di Stefano 3d202da63f Add missing package qualifier to alloc 2024-09-22 23:15:48 +02:00
Antonino Simone Di Stefano 5a6f761535 Add missing package qualifier to Context 2024-09-22 23:15:36 +02:00
gingerBill f7d74ff3a8 Merge branch 'master' of https://github.com/odin-lang/Odin 2024-09-22 19:29:15 +01:00
gingerBill 95721fe296 Add gamepad support 2024-09-22 19:29:05 +01:00
Jeroen van Rijn ba3d545c96 Merge pull request #4281 from c-cube/add-time-to-rfc3339
add a time-to-RFC3339 conversion function
2024-09-22 17:46:26 +02:00
gingerBill 66e83ef30d Add gamepad events 2024-09-22 16:24:46 +01:00
gingerBill 94288161e9 Add new js events 2024-09-22 15:52:04 +01:00
gingerBill 130318d003 Fix assert caused by typo 2024-09-22 14:19:31 +01:00
gingerBill 1ae57d8d20 Fix more JS stuff 2024-09-22 13:32:28 +01:00
gingerBill 26d00925cc Clean-up libc usage 2024-09-22 13:20:45 +01:00
gingerBill 634fa7aa30 Move vendor:wasm/js to core:sys/wasm/js 2024-09-22 13:13:34 +01:00
gingerBill 096258b5d5 Rename runtime.js to odin.js 2024-09-22 13:08:42 +01:00
gingerBill 6bdd572a30 Merge branch 'master' of https://github.com/odin-lang/Odin 2024-09-22 13:04:29 +01:00
gingerBill c39b934e7f Remove unused imports 2024-09-22 13:04:23 +01:00
Simon Cruanes a1349d8776 fix vet warnings 2024-09-22 00:08:07 -04:00
Isaac Andrade c1a67f37e6 Fix O_Flag_Bits.EXEC for non Linux platforms on posix/fcntl. 2024-09-21 21:37:41 -06:00
Isaac Andrade cc60725eda Move bit set creation to compiler guard. Fix indentation on posix/sys_sem. 2024-09-21 21:28:18 -06:00
Isaac Andrade 04c08c2e2d Resolve bit set differences between linux and other platforms in posix/fcntl 2024-09-21 21:24:18 -06:00
Isaac Andrade c68d847fb3 Satisfy the compiler. 2024-09-21 20:59:54 -06:00
Isaac Andrade 5162c6c506 Rename sigaction duplicate type to sigaction_t on linux, following other platforms. 2024-09-21 20:56:52 -06:00
Isaac Andrade 10702f1134 Implement POSIX pthread, signal, sys/resource, unistd for Linux. 2024-09-21 20:44:33 -06:00
Simon Cruanes 32e13f17ae Apply suggestions from code review
Co-authored-by: flysand7 <yyakut.ac@gmail.com>
2024-09-21 21:08:35 -04:00
Simon Cruanes d08b3d3b82 add tests for time.time_to_rfc3339 2024-09-21 00:48:39 -04:00
Simon Cruanes a89d22b291 add time.time_to_rfc3339, a printer to RFC3339 dates
this is the counterpart to the existing parsing function
`rfc3339_to_time_utc` and others. It prints the timestamp as a string,
allocated dynamically.
2024-09-21 00:47:21 -04:00
Feoramund 84700e09c9 Forbid parsing more fields if no separator was found
Fixes #4278
2024-09-20 19:02:00 -04:00
Antonino Simone Di Stefano 355f84d0cd Use package qualifier for type_info_base and Type_Info_map 2024-09-21 00:30:50 +02:00
Antonino Simone Di Stefano b33f6ba1b0 Fix type in parameter of atomic_compare_exchange_weak_explicit
desited -> desired
2024-09-21 00:30:36 +02:00
gingerBill c1264c2a79 Merge pull request #4275 from karl-zylinski/fix-file-tags-infinite-loop
Fix for infinite loop in core:odin file tags parser when a file uses \r
2024-09-20 14:36:52 +01:00
Karl Zylinski 9a8fb2fb27 Fix for infinite loop in core:odin file tags parser when your local copy uses \r 2024-09-20 15:12:35 +02:00
gingerBill 2c5be4e054 Use .shift() instead 2024-09-20 11:18:11 +01:00
gingerBill 02884207d5 Update wasm's runtime.js 2024-09-20 11:15:47 +01:00
gingerBill b116e8ff55 Fix 128-bit integer support for wasm targets 2024-09-20 01:29:39 +01:00
gingerBill a4dd489284 Add fmt tags 2024-09-19 17:12:47 +01:00
gingerBill 290561a39b Merge pull request #4270 from flysand7/heap-alloc-resize-fix
Fix resize OOB when copying old data that's bigger than new data
2024-09-19 12:57:18 +01:00
gingerBill a7fe647c8c Merge pull request #4269 from Feoramund/fix-4256
Specify integer-like only for some `atomic_*` intrinsics
2024-09-19 12:54:11 +01:00
gingerBill 327ca2ab71 Merge pull request #4261 from laytan/net-bound-endpoint
net: add `bound_endpoint` procedure
2024-09-19 12:53:42 +01:00
gingerBill 68960e7d0a Use #+ tags 2024-09-19 12:39:56 +01:00
flysand7 ee02d04a9b [os2/process]: Don't quote arguments unless needed 2024-09-19 22:38:20 +11:00
gingerBill 6bbeb0a243 Merge pull request #4203 from karl-zylinski/file-tags-without-comments
Make tags use #+ syntax instead of //+
2024-09-19 12:36:43 +01:00
Laytan a52b1e0321 Merge pull request #4271 from Feoramund/forbid-defer-orbreak
Forbid labelled or-branch expressions within `defer`
2024-09-19 13:25:28 +02:00
gingerBill d560dad0d8 Add missing import that was accidentally deleted before commit 2024-09-19 12:09:30 +01:00
gingerBill 5441620b6c Merge branch 'master' of https://github.com/odin-lang/Odin 2024-09-19 12:06:36 +01:00
gingerBill 244907149a Move os stuff to OS specific files 2024-09-19 12:06:31 +01:00
flysand7 bec09d82df Fix vet errors 2024-09-19 21:07:08 +11:00
Feoramund acbf5c8d97 Forbid labelled or-branch expressions within defer 2024-09-19 05:59:37 -04:00
flysand7 e0bb07728d Fix resize OOB when copying old data that's bigger than new data 2024-09-19 20:55:52 +11:00
Laytan 0ca5e70c7d Merge pull request #4266 from greenya/os-get-current-directory-allocator-arg
[core/os] get_current_directory: Add allocator arg to targets where i…
2024-09-19 02:17:20 +02:00
Feoramund 9456c36684 Specify integer-like only for some atomic_* intrinsics
Fixes #4256
2024-09-18 17:18:48 -04:00
Yuriy Grynevych 80622bcb3a Merge branch 'odin-lang:master' into os-get-current-directory-allocator-arg 2024-09-19 00:13:19 +03:00
Yuriy Grynevych 18fd1fefc3 Update core/os/os_openbsd.odin
Co-authored-by: Laytan <laytanlaats@hotmail.com>
2024-09-19 00:11:17 +03:00
Yuriy Grynevych 568705069c Update core/os/os_netbsd.odin
Co-authored-by: Laytan <laytanlaats@hotmail.com>
2024-09-19 00:11:12 +03:00
Yuriy Grynevych cbf0471c72 Update core/os/os_linux.odin
Co-authored-by: Laytan <laytanlaats@hotmail.com>
2024-09-19 00:11:06 +03:00
Yuriy Grynevych 35f0dcbb92 Update core/os/os_freebsd.odin
Co-authored-by: Laytan <laytanlaats@hotmail.com>
2024-09-19 00:11:00 +03:00
Yuriy Grynevych 6e979a96a1 Update core/os/os_darwin.odin
Co-authored-by: Laytan <laytanlaats@hotmail.com>
2024-09-19 00:10:53 +03:00
Laytan Laats 7491b3c332 Fix #4265 2024-09-18 22:45:27 +02:00
Yuriy Grynevych 4ff836609c [core/os] get_current_directory: Add allocator arg to targets where its missing 2024-09-18 21:03:48 +03:00
gingerBill 8814170edf Merge branch 'master' of https://github.com/odin-lang/Odin 2024-09-18 00:13:44 +01:00
gingerBill e17dfcf7a2 Remove distinct from core:math/linalg/(glsl|hlsl) types 2024-09-18 00:13:34 +01:00
Laytan Laats 80cc2f5416 fix it more 2024-09-17 23:28:34 +02:00
Laytan Laats 9973e0255c fix error interrupt error check 2024-09-17 23:19:20 +02:00
Laytan 4dd3248507 Merge pull request #4262 from flysand7/ptrace-args
[sys/linux]: Fix the order of arguments for ptrace cont, singlestep and syscall
2024-09-17 23:15:52 +02:00
flysand7 833157ecc9 [sys/linux]: Fix the order of arguments for ptrace cont, singlestep and syscall 2024-09-18 07:52:22 +11:00
Laytan Laats 652557bfcd net: add bound_endpoint procedure 2024-09-17 22:22:19 +02:00
Karl Zylinski 29fedc1808 Changed some recently added //+ usages to #+ and also fixed some //+ usages in some code generators. 2024-09-17 19:39:48 +02:00
Karl Zylinski 093ade0504 Merge branch 'master' into file-tags-without-comments 2024-09-17 19:36:17 +02:00
Laytan Laats 6ef779cd5c add new macos releases to 'odin report' and sys/info 2024-09-17 17:47:26 +02:00
Jeroen van Rijn 9508a1f031 Merge pull request #4255 from avanspector/master
init ansi on a standalone testing exe
2024-09-17 17:15:41 +02:00
avanspector c794f853e9 init ansi on a standalone testing exe 2024-09-17 16:57:02 +02:00
Laytan Laats 0975820c48 fix wrong ulock timeout calculation, add version check for ios 2024-09-17 15:52:35 +02:00
gingerBill 0d33df15b4 Merge pull request #4208 from laytan/more-wasm-vendor-support
wasm: support more vendor libraries
2024-09-17 11:37:10 +01:00
gingerBill 4a3b4da73c Merge pull request #4253 from pkova/master
Fix core sync test deadlock on darwin
2024-09-17 11:35:18 +01:00
gingerBill 09588836e7 Add -vet-unused-procedures 2024-09-17 11:33:42 +01:00
gingerBill 19c1ed154c Add -vet-packages:<comma-separated-string-array> 2024-09-17 11:01:26 +01:00
gingerBill abf6ea7732 Fix minor bug with addressability 2024-09-17 10:24:19 +01:00
pkova 6e0f1cc866 Pass microseconds instead of nanoseconds to __ulock_wait 2024-09-17 02:35:00 +03:00
Pyry Kovanen 4d6f7dcac0 Fix code alignment in futex_darwin.odin
Co-authored-by: Feoramund <161657516+Feoramund@users.noreply.github.com>
2024-09-17 02:21:00 +03:00
pkova aa25714d43 Remove comment from core sync tests now that they're fixed 2024-09-17 02:11:41 +03:00
pkova fff99c726e Fix core sync test deadlock on darwin 2024-09-17 01:52:51 +03:00
gingerBill a16d3b6c9a Merge pull request #4242 from laytan/caller-expression
add '#caller_expression'
2024-09-16 17:36:46 +01:00
gingerBill 68619f299e Merge pull request #4209 from flysand7/core-mem
[core/mem]: Document, refactor, reformat!
2024-09-16 17:35:19 +01:00
gingerBill 017d6bdf73 Merge pull request #4232 from Feoramund/test-sync
Add test suites for `core:sync` and `core:sync/chan`
2024-09-16 17:27:20 +01:00
Feoramund 16ef59700b Check for EINTR in sys/posix test 2024-09-15 23:58:03 -04:00
Feoramund d38f5ffb49 Remove unneeded synchronizations in Chan
Everything was already guarded by `c.mutex`.
2024-09-15 22:59:30 -04:00
Isaac Andrade 97e06cb98e Fix bit flags on fcntl linux POSIX implemention. Add sys/sem linux implementation. 2024-09-15 18:43:51 -06:00
Isaac Andrade 8616842ec6 Implement Linux POSIX compliance for poll, sched, sys/select. Fix enum in fcntl. 2024-09-14 20:23:42 -06:00
Isaac Andrade aa91479870 Fix O_NOFOLLOW typo. Add Linux support for POSIX fcntl. 2024-09-14 17:01:15 -06:00
Laytan Laats d03d9e49a6 fix #4243 2024-09-15 00:03:20 +02:00
Laytan d2d2026736 Merge pull request #4241 from laytan/improve-bit-field-debug-info
improve bit field debug info
2024-09-14 22:15:47 +02:00
Laytan Laats 603efa860a add '#caller_expression' 2024-09-14 22:13:37 +02:00
Karl Zylinski 3d7b924260 Fix a few incorrectly placed build tags. 2024-09-14 18:41:05 +02:00
Karl Zylinski 19f0127e55 Moved all packages in core, base, vendor, tests and examples to use new #+ file tag syntax. 2024-09-14 18:27:49 +02:00
Isaac Andrade af94c4ab32 Add initial POSIX support for Linux for wordexp. 2024-09-14 10:06:25 -06:00
Karl Zylinski b12d312408 core/odin: Added new file tag syntax as token. parse_file stores a list of tags that the file tag parser can use later. 2024-09-14 17:59:50 +02:00
Laytan Laats 4f3f256375 improve bit field debug info 2024-09-14 15:52:37 +02:00
Karl Zylinski c24e18bf10 Fix incorrect syntax error in parse_file 2024-09-14 14:36:33 +02:00
Karl Zylinski 8b84b9a4a2 Docs are generated as expected again. 2024-09-14 14:32:46 +02:00
Karl Zylinski 86e291235d Merge remote-tracking branch 'origin/master' into file-tags-without-comments 2024-09-14 11:26:41 +02:00
flysand7 466e29bb38 [mem]: Rollback allocator API consistency 2024-09-14 13:15:02 +11:00
flysand7 016d1a84d4 [mem]: Document mutex, rollback stack and tracking allocators 2024-09-14 10:46:35 +11:00
flysand7 3ed2ab6e2c [mem]: Adjust the docs for calc_padding_with_header 2024-09-14 10:18:51 +11:00
flysand7 e90f5d2528 [mem]: Adjust the docs on the buddy allocator 2024-09-14 10:03:04 +11:00
Laytan 129d85fe7d Merge pull request #4236 from laytan/box2d-release-build
vendor/box2d: build in release mode
2024-09-13 21:09:57 +02:00
Laytan Laats 18a63037d1 vendor/box2d: build in release mode 2024-09-13 20:51:06 +02:00
gingerBill 3166c7bef9 Add Suggested Example for using an inline procedure which enables a target feature 2024-09-12 10:07:09 +01:00
Isaac Andrade 55a9ba1fc0 Finish sys/socket POSIX support for Linux. 2024-09-11 22:25:38 -06:00
Laytan 275f1cc0de Merge pull request #4233 from laytan/fix-poly-variadic-reuse-slice
fix reuse of slice for varargs with poly types
2024-09-12 02:34:01 +02:00
Laytan Laats 387f56634d fix reuse of slice for varargs with poly types 2024-09-12 02:25:44 +02:00
Jeroen van Rijn c94829f4d3 Merge pull request #4231 from InKryption/enable-doc-out-param
Enable -out:<filename> for doc subcommand
2024-09-12 01:43:22 +02:00
Laytan Laats 201a7b90bb fix EventMaskAny definition 2024-09-12 00:11:27 +02:00
gingerBill 27ed10746d Allow transmute(Bit_Set)~T(0) 2024-09-11 23:08:38 +01:00
Laytan Laats 3b22c0854c fix some LLVM assertions 2024-09-11 22:45:16 +02:00
InKryption 1025b9e6c0 Enable -out:<filename> for doc subcommand
The logic for writing the .odin-doc file to the value assigned
to out_filepath already exists, this just enables it on the CLI
frontend.
2024-09-11 21:11:32 +02:00
Laytan 244a4acfa1 Merge pull request #4230 from laytan/cbor-unmarshal-non-string-keys
core/encoding/cbor: allow unmarshalling non-string map keys
2024-09-11 16:08:53 +02:00
Laytan Laats 788e4b2b6a core/encoding/cbor: allow unmarshalling non-string map keys 2024-09-11 15:57:56 +02:00
Feoramund 7f7cfebc91 Add tests for core:sync and core:sync/chan 2024-09-11 08:39:38 -04:00
Feoramund 16cd16b91e Fix comments 2024-09-11 08:39:23 -04:00
Feoramund 2938655a3d Fix CPU count detection in FreeBSD & NetBSD 2024-09-11 08:39:23 -04:00
Feoramund b1db33b519 Add cpu_relax to sync.auto_reset_event_signal 2024-09-11 08:39:23 -04:00
Feoramund a1435a6a90 Fix deadlock in Auto_Reset_Event 2024-09-11 08:39:23 -04:00
Feoramund fec1ccd7a3 Fix data races in sync.Recursive_Benaphore 2024-09-11 08:39:23 -04:00
gingerBill 9b06ea5bfd Fix #4229 for edge case os.Error/os.Errno legacy bodge 2024-09-11 12:01:01 +01:00
Laytan Laats b379d25a12 ci: try updating deprecated setup-python 2024-09-11 03:05:56 +02:00
Laytan Laats a15afccd36 ci: aware 2024-09-11 02:56:24 +02:00
Laytan Laats 83b5f82a92 ci: ohhh, I am dumb 2024-09-11 02:45:58 +02:00
Isaac Andrade 1632f19826 In-progress support for POSIX on Linux for sys/socket. 2024-09-10 18:43:09 -06:00
Laytan Laats 496d732aaf ci: does backblaze not like tar archives? 2024-09-11 02:41:28 +02:00
Laytan Laats 26db1c8860 ci: show me files 2024-09-11 02:30:43 +02:00
Laytan Laats 7ff424d148 ci: specify path 2024-09-11 02:26:39 +02:00
Laytan Laats f4322886f3 ci: really, what's in there? 2024-09-11 02:19:39 +02:00
Laytan Laats 005cadb52c ci: what's in there? 2024-09-11 02:10:55 +02:00
Laytan Laats 90ba78cdfc ci: no UTC on this python 2024-09-11 02:01:14 +02:00
Laytan Laats a66524b0b2 ci: fix run step 2024-09-11 01:55:33 +02:00
flysand7 f16ed256ea [mem]: Fix handling of default resize to check alignment 2024-09-11 08:00:27 +11:00
gingerBill b442ea8601 Merge pull request #4206 from laytan/improve-linking-shared-libraries
Improve linking shared libraries
2024-09-10 21:59:21 +01:00
Jeroen van Rijn 309ea50a7c Merge pull request #4204 from A1029384756/static_builds
Changed Linux CI builds to static linking with Musl for better compatibility
2024-09-10 22:41:25 +02:00
Jeroen van Rijn 5c4f241f22 upload v4 2024-09-10 22:21:50 +02:00
Jeroen van Rijn fce7bcec49 Merge branch 'master' into static_builds 2024-09-10 22:15:06 +02:00
Jeroen van Rijn 459de29a87 Merge pull request #4193 from odin-lang/dependabot/github_actions/dot-github/workflows/actions/download-artifact-4.1.7
Bump actions/download-artifact from 1 to 4.1.7 in /.github/workflows
2024-09-10 22:13:01 +02:00
Feoramund b2c2235e58 Fix recursive_benaphore_try_lock
Previously, if the owner called this, it would fail.
2024-09-10 14:52:20 -04:00
Feoramund 3a60109180 Fix signalling test child threads crashing test 0
A thread made inside a test does not share the test index of its parent,
so any time one of those threads failed an assert, it would tell the
runner to shutdown test index zero.
2024-09-10 14:52:20 -04:00
Feoramund 074314b887 Fix data race in test_core_flags 2024-09-10 14:52:20 -04:00
Feoramund 8a14a656fb Fix chan.can_send for unbuffered channels
`w_waiting` is the signal that says a caller is waiting to be able to
send something. It is incremented upon send and - in the case of an
unbuffered channel - it can only hold one message.

Therefore, check that `w_waiting` is zero instead.
2024-09-10 14:52:20 -04:00
Feoramund e9a6a34480 Forbid chan.try_send on closed buffered channels 2024-09-10 14:52:20 -04:00
Feoramund 026aef69e3 Fix deadlock on sending to full, buffered, closed Chan
This will also keep messages from being sent to closed, buffered
channels in general.
2024-09-10 14:52:20 -04:00
Feoramund 73f5ab473c Keep chan.can_recv from deadlocking 2024-09-10 14:52:20 -04:00
Feoramund 0a594147af Use contextless procs in core:sync instead 2024-09-10 14:52:20 -04:00
Isaac Andrade ff82396e7c Add Linux support for POSIX sys ipc, mman, time, utsname. 2024-09-10 07:32:58 -06:00
Jeroen van Rijn beb10cce63 Fix #4227 2024-09-10 15:31:57 +02:00
Jeroen van Rijn 4df668fa22 Merge pull request #4226 from Kelimion/fix-4225
Fix #4225
2024-09-10 15:30:43 +02:00
Jeroen van Rijn 564c7821c5 Allow ExactValue_Invalid in assert.
Fixes #4225
2024-09-10 15:19:12 +02:00
flysand7 fdd4882568 [mem]: Adjust docs for alloc 2024-09-10 19:51:20 +11:00
Isaac Andrade 92ff04629e Fix some compilation errors on POSIX linux. 2024-09-09 22:17:42 -06:00
Feoramund c3f363cfbc Fix data race when pool_stop_task is called 2024-09-09 16:19:15 -04:00
Feoramund dbb783fbf2 Fix atomic memory order for sync.ticket_mutex_unlock 2024-09-09 16:19:15 -04:00
Feoramund 45da009377 Use more atomic handling of thread flags
This can prevent a data race on Linux with `Self_Cleanup`.
2024-09-09 16:19:15 -04:00
Feoramund 4d14b4257e Convert POSIX Thread to use semaphore instead
One less value to store, and it should be less of a hack too.

Semaphores will not wait around if they have the go-ahead; they depend
on an internal value being non-zero, instead of whatever was loaded when
they started waiting, which is the case with a `Cond`.
2024-09-09 16:19:14 -04:00
Feoramund cbd4d5e765 Fix data race in atomic_sema_wait_with_timeout 2024-09-09 16:19:14 -04:00
Feoramund 74b28f1ff9 Fix rare double-join possibility in POSIX thread._join
This was occuring about 1/100 times with the test runner's thread pool.
2024-09-09 16:19:14 -04:00
Feoramund 9d6f71fd2e Fix sync.Benaphore
The calls to `atomic_add*` return the value before adding, not after, so
the previous code was causing the occasional data race.
2024-09-09 16:19:14 -04:00
Karl Zylinski f9de8fdaba Documentation typo fix in tokenizer. 2024-09-09 21:51:34 +02:00
Karl Zylinski 580f0599cd parse_file: Removed some nesting and removed probable incorrect safety check. 2024-09-09 21:24:41 +02:00
Karl Zylinski cc724ff5d2 Made error handling code in parse_file clearer. 2024-09-09 21:13:39 +02:00
Karl Zylinski 957cd64699 Rename process_file_tag -> parse_file_tag 2024-09-09 21:06:43 +02:00
Karl Zylinski 3637dcbd04 Simplified error messages in parse_build_tag, removed the idea of making multiple notted operating systems since it was misinformed. 2024-09-09 21:03:28 +02:00
Thomas la Cour 954dd86f7a nightly define fix 2024-09-09 19:55:00 +02:00
Thomas la Cour 6298b23e07 tag nightly builds 2024-09-09 19:34:19 +02:00
Thomas la Cour 053425e8d7 trim version digits, release=YYYY.MM.0.0 else YYYY.MM.DD.0 2024-09-09 19:29:43 +02:00
Laytan Laats 5ae27c6ebc wasm: support more vendor libraries
Adds support for:
- box2d
- cgltf
- stb image
- stb rect pack
2024-09-09 18:49:13 +02:00
Laytan d783bca297 Merge pull request #4218 from pkova/master
Fix os2/heap_linux.odin deadlock
2024-09-09 17:25:00 +02:00
Laytan ce3f6b60d2 Merge pull request #4223 from hstormo/bugfix
Remove stb_rect_pack implementation from stb_truetype (fix #4215)
2024-09-09 17:21:41 +02:00
gingerBill a25a9e6ebe Check for LLVM_VERSION_MAJOR >= 18 2024-09-09 14:47:44 +01:00
gingerBill 0dddd2b97e Add internal flag
`-internal-fast-isel`
2024-09-09 14:39:53 +01:00
laytan aa75909418 recompile bundled stb truetype on windows 2024-09-09 15:14:26 +02:00
Laytan Laats 0f379d7378 recompile bundled stb truetype 2024-09-09 17:09:49 +02:00
Håkon Stormo ae020ffb2e Remove stb_rect_pack implementation from stb_truetype (fix #4215) 2024-09-09 15:50:00 +02:00
A1029384756 036d7edda9 Changed Linux CI builds to static linking with Musl for better
compatibility

Changed to tarball distribution for mac and linux

Updated upload-artifact to v4
2024-09-08 18:35:16 -04:00
Laytan Laats 75dd562a0a fix #4219 - recursive mutex lock 2024-09-08 22:23:03 +02:00
pkova 0a17525791 Remove unused base:runtime from os2/heap_linux.odin 2024-09-08 17:25:30 +00:00
pkova 499a5d1f9c Fix os2/heap_linux.odin deadlock 2024-09-08 16:47:16 +00:00
gingerBill e72d0ba804 Move around mutex guard 2024-09-08 14:11:05 +01:00
Karl Zylinski f3a2b625ae Merge remote-tracking branch 'origin/master' into file-tags-without-comments 2024-09-08 11:29:21 +02:00
flysand7 167ced8ad1 [mem]: Don't use named params for dynamic pool in tests 2024-09-08 18:52:55 +11:00
flysand7 05df34f99c [mem]: Start documenting allocators.odin 2024-09-08 18:44:33 +11:00
flysand7 299accb717 [mem]: Put panic allocator after nil allocator, adjust @require_results 2024-09-08 14:17:32 +11:00
flysand7 3b30bc305c [mem]: Document raw.odin 2024-09-08 14:13:03 +11:00
Karl Zylinski 73e4954346 Better #+build tag error messages: Error when using more than one !notted operating system per build line. Error when using more than one operating system within a 'kind', such as writing #+build windows linux. 2024-09-08 03:13:21 +02:00
flysand7 f1f5dc614e [mem]: Remove old comments 2024-09-08 11:17:27 +11:00
flysand7 6eb80831b5 [mem]: Panic when allocator is not initialized 2024-09-08 11:12:28 +11:00
flysand7 b78d546010 [mem]: Add non_zeroed versions of resize 2024-09-08 11:02:17 +11:00
flysand7 c719a86312 [mem]: Document alloc.odin 2024-09-08 10:58:40 +11:00
Karl Zylinski dc767da12b Make tags use #+ syntax instead of //+ syntax so it no longer looks like a comment. Old style still works but is deprecated with a warning. Using unknown tags is now an error instead of a warning. There is a new token for #+ which consumes the whole line (or until it hits a comment). The tags are parsed like before. There are errors to tell you if you use something invalid in the pre-package-line block. 2024-09-08 01:50:56 +02:00
Jeroen van Rijn 300b01d77d Return "" for rune < 0 in strconv. 2024-09-08 00:32:46 +02:00
Laytan 1ab0745ca8 Merge pull request #4212 from karl-zylinski/fix-build-tags
Fix build tags that use ! multiple times on one line.
2024-09-07 22:18:29 +02:00
Karl Zylinski 8c636ac37b Fix build tags that use ! multiple times on one line. Those don't actually do anything since build tags use OR within the line. So something like //+build !windows, !linux would actually build on both linux and windows. What was intended in all these cases was probably AND, which you get by splitting them into separate lines. 2024-09-07 22:02:17 +02:00
Jeroen van Rijn 466a90010f Fix #4211 2024-09-07 21:07:29 +02:00
gingerBill 5a4746c3a0 Improve debug information for procedure types 2024-09-07 17:41:16 +01:00
flysand7 1842cd6297 Fix typo
Co-authored-by: FourteenBrush <74827262+FourteenBrush@users.noreply.github.com>
2024-09-08 00:09:18 +11:00
Jeroen van Rijn c4c2282595 Update 4210 test to use unaligned_load. 2024-09-07 14:05:56 +02:00
Jeroen van Rijn d2202416d2 Add test for #4210 2024-09-07 13:43:19 +02:00
gingerBill 0a08a65202 Simplify #row_major matrix and matrix_flatten behaviour 2024-09-07 12:21:29 +01:00
flysand7 f8cd13767e [mem]: Fix the issue with unbranched version of ptr align 2024-09-07 18:08:11 +11:00
flysand7 3a351ec407 [mem]: Document mem.odin 2024-09-07 18:01:41 +11:00
flysand7 7c9d2f61f5 [mem]: Update package documentation 2024-09-07 15:16:20 +11:00
flysand7 6017a20e1c [mem]: Make resize_bytes take a slice for the old memory 2024-09-07 15:11:04 +11:00
flysand7 2d988bbc5f [mem]: Rename alloc to alloc_bytes and add alloc 2024-09-07 14:45:15 +11:00
flysand7 64814f4199 [mem]: Document the package 2024-09-07 14:19:50 +11:00
flysand7 c0112d1c70 [mem]: Add free_all for buddy allocator 2024-09-07 13:27:17 +11:00
flysand7 c0e17808d4 [mem]: Split alloc and alloc_non_zeroed for buddy allocator 2024-09-07 13:26:09 +11:00
flysand7 6d3cffa13c [mem]: Add @require_results to all functions returning values 2024-09-07 13:14:58 +11:00
flysand7 b350a35b77 [mem]: Add resize_non_zeroed variant to dynamic arena, and rename pool to arena 2024-09-07 13:10:29 +11:00
flysand7 03f6b9bbf6 [mem]: Add alloc_non_zeroed variant to dynamic pool 2024-09-07 12:59:19 +11:00
flysand7 f8641ddd1b [mem]: Rename dynamic pool to dynamic arena 2024-09-07 12:33:12 +11:00
flysand7 aea3e9a585 [mem]: Fix vet errors 2024-09-07 12:26:47 +11:00
flysand7 4843db0960 [mem]: API for using small stack allocator directly 2024-09-07 12:23:55 +11:00
flysand7 de220a9aa5 [mem]: Remove the extra word 'allocator' in procedures 2024-09-07 11:07:06 +11:00
flysand7 9750b64096 [mem]: API for using stack allocator directly 2024-09-07 10:55:54 +11:00
flysand7 834f082dba [mem]: Initialize scratch allocator during calls to free and resize 2024-09-07 10:24:00 +11:00
flysand7 e5106e48a8 [mem]: API for using scratch allocator directly 2024-09-07 10:09:05 +11:00
flysand7 da6213196d [mem]: API for using arena directly 2024-09-07 09:42:04 +11:00
flysand7 2b9096517c [mem]: Code formatting 2024-09-07 09:20:56 +11:00
gingerBill 90358f97d5 Merge pull request #4205 from Valakor/wgpu
Fix wgpu on Windows - missing links to ole32.lib and oleaut32.lib
2024-09-06 14:08:07 +01:00
Matthew Pohlmann c19da21d81 Fix wgpu on Windows - missing links to ole32.lib and oleaut32.lib 2024-09-05 21:40:15 -07:00
gingerBill 78506b97a3 Merge pull request #4202 from laytan/add-fixed-point-dependency
add fixed point sign extend to 128 int deps
2024-09-05 19:08:38 +01:00
Laytan Laats 490f8c1568 add fixed point sign extend to 128 int deps 2024-09-05 15:55:55 +02:00
laytan a99e57c62c bytes: fix last_index_byte off-by-one 2024-09-05 13:30:46 +02:00
Laytan Laats ddf5ca7adf remove deprecation, technically deprecated but widely used 2024-09-05 01:08:09 +02:00
Laytan Laats 6778598bc6 support the rpath changes on macos 2024-09-05 00:12:16 +02:00
Laytan 0aa971207b add -no-rpath 2024-09-04 22:38:19 +02:00
gingerBill a4fd0c133e Merge pull request #4191 from laytan/improve-package-doc-comments
core: improve package doc comments for the documentation generator
2024-09-04 21:37:48 +01:00
Laytan ce018b4e6f Merge pull request #4197 from dekdevy/master
fix wgpu vendor lib error message
2024-09-04 22:22:25 +02:00
Laytan 1a7c1d107a set -rpath to \$ORIGIN and expect libraries next to executable just like Windows 2024-09-04 22:19:46 +02:00
dek d2d5ac33f4 fix wgpu vendor lib error message 2024-09-04 22:04:06 +02:00
Laytan 578de09775 types with explicit custom alignment are identical to types with the same natural alignment 2024-09-04 18:48:11 +02:00
Laytan dcf339517e make c vararg with any vs concrete type similar enough 2024-09-04 18:47:08 +02:00
gingerBill b2c5998e78 Merge pull request #4196 from jakubtomsu/unmarshal-json-bit-sets
Support unmarshalling bit_sets in `core:encoding/json`
2024-09-04 13:27:25 +01:00
jakubtomsu 7487d507be unmarshal bitset ints like cbor does 2024-09-04 11:08:45 +02:00
Jeroen van Rijn c6b551d2c3 Merge pull request #4194 from Feoramund/update-bit-array
Update `bit_array`
2024-09-03 23:42:27 +02:00
Feoramund 2f1228baa0 Add tests for Bit_Array 2024-09-03 17:23:42 -04:00
dependabot[bot] 73eea33b56 Bump actions/download-artifact from 1 to 4.1.7 in /.github/workflows
Bumps [actions/download-artifact](https://github.com/actions/download-artifact) from 1 to 4.1.7.
- [Release notes](https://github.com/actions/download-artifact/releases)
- [Commits](https://github.com/actions/download-artifact/compare/v1...v4.1.7)

---
updated-dependencies:
- dependency-name: actions/download-artifact
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-09-03 21:01:48 +00:00
Feoramund c3bd94a27e Change Bit_Array.max_index to length
This will allow correct iteration of empty `bit_array`s.
2024-09-03 16:56:02 -04:00
Jeroen van Rijn 645207b8b0 Merge pull request #4192 from laytan/strings-substring-rune-wise
strings: add `substring`, `substring_to` and `substring_from`
2024-09-03 22:47:56 +02:00
Feoramund d86e56089a Fix iteration of biased Bit_Array 2024-09-03 15:34:38 -04:00
Laytan Laats 597ba796b7 strings: add substring, substring_to and substring_from 2024-09-03 21:13:35 +02:00
Laytan Laats 288312a812 core: improve package doc comments for the documentation generator 2024-09-03 19:59:04 +02:00
Laytan 6bbc165121 Merge pull request #4181 from laytan/more-riscv-sysinfo
sys/info: more CPU feature detection for RISC-V
2024-09-03 19:54:15 +02:00
Feoramund b8f8cb9582 Add bit_array.shrink 2024-09-03 13:33:15 -04:00
Feoramund 001b2b9d8f Let bit_array.create make zero-length arrays 2024-09-03 13:33:11 -04:00
Laytan 33735ba5cc Merge pull request #4180 from dvrd/alt
fix(os2): mkdir_all on path_posix
2024-09-03 19:31:04 +02:00
Jeroen van Rijn 3da77bcd67 Merge pull request #4190 from Kelimion/strings.cut
strings.cut without allocation.
2024-09-03 19:09:27 +02:00
Jeroen van Rijn 996175753c strings.cut without allocation. 2024-09-03 19:02:40 +02:00
gingerBill 0e6109e171 Merge pull request #4189 from pkova/master
Fix thread sanitizer errors surfaced by tests/core/io
2024-09-03 15:57:45 +01:00
pkova 5b9b21e756 Fix thread sanitizer errors surfaced by tests/core/io 2024-09-03 16:30:51 +03:00
gingerBill d93aca647b Merge pull request #4171 from yay/objc-runtime-bindings
More Objective-C Runtime bindings.
2024-09-03 14:28:02 +01:00
gingerBill 6ed4bfeba1 Merge pull request #4186 from Feoramund/fix-4177
Return false if `Small_Array` can't append multiple elements
2024-09-03 14:25:15 +01:00
gingerBill 99a3e9a510 Merge pull request #4187 from Feoramund/fix-slice-equal
Check for zero-length slices in `slice.equal`
2024-09-03 14:24:45 +01:00
gingerBill c0154bffad Merge pull request #4188 from FrancisTheCat/master
Added `#any_int` to some `soa` procs to mirror the behaviour of their non `soa` counterparts
2024-09-03 14:24:36 +01:00
Jeroen van Rijn 9276476760 Merge pull request #4185 from Feoramund/add-time-to-datetime
Add `time.time_to_datetime`
2024-09-03 15:05:42 +02:00
Vitalii Kravchenko c86bbc61bc More Objective-C Runtime bindings. 2024-09-03 11:41:23 +01:00
Franz Hoeltermann 02da1ac9af Added #any_int directive to some more builtin slice/dynamic array
procedures
2024-09-03 12:36:32 +02:00
Franz Hoeltermann b618b665c6 Added #any_int to some #soa procs to mirror the behaviour of their
non-soa counterparts
2024-09-03 11:46:09 +02:00
Feoramund 806c87d71d Check for zero-length slices in slice.equal 2024-09-03 02:48:26 -04:00
Feoramund 309953e0f2 Return false if Small_Array can't append multiple elements
Fixes #4177
2024-09-03 01:14:17 -04:00
Isaac Andrade 9e4b45f0f0 Add linux to OS check. 2024-09-02 22:58:54 -06:00
Feoramund f6f2c67f37 Add time.time_to_datetime 2024-09-03 00:55:09 -04:00
Isaac Andrade d93f55c5d4 Reuse POSIX netinet_in constants for linux. 2024-09-02 22:32:52 -06:00
Isaac Andrade f072136c04 Implement POSIX linux support for poll and netinet_tcp. Incomplete support for netinet/in. 2024-09-02 21:59:03 -06:00
Jeroen van Rijn 71b2527df0 Merge pull request #4184 from Dimension4/help-text-build-mode
Add missing help text for -build-mode:test
2024-09-03 00:17:17 +02:00
Dimension4 b24157738f Add missing help text for -build-mode:test 2024-09-02 23:40:13 +02:00
Isaac Andrade 35f961d80f Add POSIX Linux support for net_if and netdb. 2024-09-02 14:25:32 -06:00
Isaac Andrade a248d49f34 Add Linux support for POSIX limits. 2024-09-02 14:04:05 -06:00
Laytan Laats 60321d98d4 also fix the doc comment in the code generator 2024-09-02 20:22:02 +02:00
Laytan Laats 195259e88b fix some doc comments 2024-09-02 20:10:11 +02:00
laytan 35731e66cf sys/info: more CPU feature detection for RISC-V 2024-09-02 14:06:19 +00:00
Dan Castrillo 54b46247bd fix(os2): mkdir_all on path_posix 2024-09-02 08:47:26 -04:00
gingerBill 16c5c69a40 Merge pull request #4175 from laytan/riscv-compiler
Support RISC-V for the compiler itself
2024-09-02 00:20:04 +01:00
gingerBill 39b49cb6fb Merge pull request #4176 from Feoramund/fix-context-error-msg
Remove extra format item at end of `context` error message
2024-09-02 00:18:15 +01:00
Feoramund 9871ad5fc8 Remove extra format item at end of context error message 2024-09-01 17:50:50 -04:00
Laytan 28c643d23f riscv compiler support 2024-09-01 21:42:47 +02:00
Jeroen van Rijn dd1f151696 Add math.remap_clamped. 2024-09-01 17:22:58 +02:00
Jeroen van Rijn c1605b5b4f Merge pull request #4173 from karl-zylinski/clamp-remap
Make math.remap clamp the result in range [new_min, new_max]
2024-09-01 16:54:17 +02:00
Karl Zylinski 6e150d1d58 Make math.remap clamp the result in range [new_min, new_max]. 2024-09-01 16:30:48 +02:00
Laytan 722b638e2c "fix" #4169, looks like llvm 14 bug 2024-08-31 19:40:05 +02:00
Jeroen van Rijn c1cb1a3d7e Simplified #assert check 2024-08-31 19:13:37 +02:00
Jeroen van Rijn a4ac50a5b4 Check for #assert condition to be a constant bool
Fixes #4170
2024-08-31 19:06:17 +02:00
gingerBill 6ba1506aa9 Fix possible leaks in os2.user_* calls 2024-08-31 15:12:47 +01:00
gingerBill b4bdb73158 Fix new(sync.Mutex) 2024-08-31 15:06:20 +01:00
gingerBill 476030dd28 Fix #4156 2024-08-31 13:51:35 +01:00
Isaac Andrade 186565b0c1 Simplify the implementation of POSIX langinfo for Linux:
No need for the enum runtime checks. Constant values were set manually
and comments were added to help locate their origin.
2024-08-30 20:34:12 -06:00
Isaac Andrade 575aedc3bf Implement POSIX support for Linux for the following facilities:
- fnmatch
- grp
- langinfo
- locale
2024-08-30 19:45:56 -06:00
Laytan Laats e0a2e52601 c/libc: fix time link name 2024-08-31 02:49:53 +02:00
Laytan Laats 7f3d8e115f remove comma 2024-08-31 02:45:17 +02:00
Laytan 584e8859bf Merge pull request #4168 from laytan/fix-bad-import-name-errors
fix some issues with the "bad import name" errors
2024-08-31 02:44:16 +02:00
Laytan Laats 8e855155fd fix bad import 2024-08-31 02:38:07 +02:00
Laytan Laats 7624ecf4ba fix some issues with the "bad import name" errors
There was so much wrong here:
- The `if` statement was never entered because even on invalid import
  names `path_to_entity_name` returns "_"
- Two errors were shown where one doesn't make sense, need to choose one
  based on context
- Structure of the messages were different from other error messages
- Suggestion was using the wrong import path
2024-08-31 02:30:32 +02:00
Laytan Laats bfedcd7035 encoding/csv: fix examples 2024-08-30 23:31:31 +02:00
Laytan Laats 6ef49d4f24 core/odin: support #type_assert and #no_type_assert 2024-08-30 23:21:35 +02:00
Jeroen van Rijn 8ad4427a25 Add a few more reflect.bit_field_* helpers. 2024-08-30 22:40:14 +02:00
Jeroen van Rijn db3bcd2cea Add reflect.bit_fields_zipped 2024-08-30 22:04:10 +02:00
Jeroen van Rijn 3072a02d5d Attempt to account for BuildTools installer's lack of \ 2024-08-30 18:54:51 +02:00
gingerBill 773703bc83 Merge pull request #4009 from thetarnav/file-tag-parser
Add a file tag parser to core:odin/parser
2024-08-30 11:58:18 +01:00
gingerBill a4e865f90b Fix #4166 2024-08-30 11:01:06 +01:00
gingerBill 9197a126fc Use XOR directly rather than (~x) & mask 2024-08-30 10:52:11 +01:00
gingerBill 38ea276231 Make ~some_bit_set work on only the possible bits by doing a mask with the full set 2024-08-30 10:48:21 +01:00
gingerBill b020b91df2 Merge pull request #4112 from Feoramund/fix-test-io-issues
Add `core:io` test suite
2024-08-30 09:57:02 +01:00
gingerBill 291048cb3b Merge pull request #4165 from avanspector/master
Add missing lexer checking delay for foreign blocks
2024-08-30 09:56:36 +01:00
Isaac Andrade 3557955f53 Align the dirent struct for linux 2024-08-29 20:17:39 -06:00
avanspector 3135c89a0a Merge branch 'master' of https://github.com/avanspector/Odin 2024-08-30 01:32:21 +02:00
avanspector 47f423c123 Set a flag for delayed checking 2024-08-30 01:32:06 +02:00
avanspector a7a2611efc Merge branch 'odin-lang:master' into master 2024-08-29 23:44:14 +02:00
avanspector 9866c83d61 Add missing checker delaying 2024-08-29 23:43:01 +02:00
Damian Tarnawski 655610ec87 Satisfy vet 2024-08-29 23:06:50 +02:00
Damian Tarnawski a28d574272 Add and test match_build_tags 2024-08-29 23:02:49 +02:00
Damian Tarnawski f93779d425 Parse build_project_name as [][]string 2024-08-29 22:08:01 +02:00
Damian Tarnawski a10f988020 Move some types to runtime, use reflection instead of lut 2024-08-29 21:12:33 +02:00
Damian Tarnawski 39bdf4d710 Add missing require_results attr 2024-08-29 20:52:27 +02:00
Damian Tarnawski 7862460374 Remove useless code 2024-08-29 20:52:27 +02:00
Damian Tarnawski 92821300e4 Add a file tag parser to core:odin/parser 2024-08-29 20:52:27 +02:00
Laytan 94a1a7aed5 Merge pull request #4164 from laytan/virtual-growing-min-block-size-fix
mem/virtual: make sure the given size is used for subsequent blocks
2024-08-29 18:27:54 +02:00
Laytan Laats 5a22d49b72 mem/virtual: make sure the given size is used for subsequent blocks 2024-08-29 14:48:36 +02:00
Laytan 942017b958 Merge pull request #4163 from laytan/sysconf-pagesize
mem/virtual: use `sysconf` for retrieving page size and actually use these init procs
2024-08-29 14:44:54 +02:00
Laytan Laats fd2ad20cd4 mem/virtual: use sysconf for retrieving page size and actually use these init procs 2024-08-29 14:36:32 +02:00
Isaac Andrade 4577d541ec Add contants RTLD contants on os_linux and posix (dlfcn). 2024-08-28 22:15:11 -06:00
Isaac Andrade f0e631cfa3 Use native types on linux POSIX structs. 2024-08-28 19:08:48 -06:00
Laytan Laats cca385209b Remove double close 2024-08-28 19:53:20 +02:00
Laytan Laats fe2d256468 Properly close the temporary files in io tests 2024-08-28 19:53:20 +02:00
Laytan Laats 0f2ad95014 Fix EOF detection is os2 window read 2024-08-28 19:53:20 +02:00
Feoramund 7fa2e56cd9 Add io tests for bufio streams 2024-08-28 19:53:20 +02:00
Feoramund 24a53c246f Make sure seek succeeds in io.Limited_Reader test setup 2024-08-28 19:53:20 +02:00
Feoramund b11fa90ed2 Test empty slice usage in io procs 2024-08-28 19:53:20 +02:00
Feoramund f453054aff Return 0, nil in all io cases where an empty slice is provided 2024-08-28 19:53:20 +02:00
Feoramund ef99373c31 Fix pread and pwrite on os2 Windows
The previous code was jumping ahead by the specified offset, instead of
getting the current offset.
2024-08-28 19:53:20 +02:00
Feoramund 1cd5cbb0e4 Test io unexpected pointer movement 2024-08-28 19:53:20 +02:00
Feoramund 56f232e5fc Report invalid whence & offset on os2 Windows 2024-08-28 19:53:20 +02:00
Feoramund de1432b315 Fix Windows infinite recursion with os2._flush 2024-08-28 19:53:20 +02:00
Feoramund e7d6e2d163 Add documentation to os2.close
Make it explicit that using a stream after closing is like a
use-after-free bug.
2024-08-28 19:53:20 +02:00
Feoramund 8b40be50b9 Update core:io tests
- Relax return value requirements on errors. Only the error is checked,
  as there are multiple conflicting return styles throughout the `os`
  API.

  Some return the error along with `0`, `-1`, or another value. This can
  be smoothed out later.

- Test `os2` files now.
- No longer test streams after closing; this is considered similar to a
  use-after-free in `os2`.
2024-08-28 19:53:20 +02:00
Feoramund 6798d15ecb Check int(abs) instead to avoid overflows 2024-08-28 19:53:20 +02:00
Feoramund 6aedb2695a Report Invalid_Whence on some os platforms
- Move `Seek`-related checks into OS-specific files for granularity.

Platforms:
- Darwin
- FreeBSD
- Haiku
- Linux
- NetBSD
- OpenBSD
2024-08-28 19:53:20 +02:00
Feoramund 0243647e15 Add missing flush functionality to os platforms
Platforms:
- FreeBSD
- Haiku
- Linux
- NetBSD
- OpenBSD
2024-08-28 19:53:20 +02:00
Feoramund 3ec4db212b Report Invalid_Whence in os2 Linux seek 2024-08-28 19:53:20 +02:00
Feoramund 7683c1f4bb Report Invalid_Whence in os2 POSIX seek 2024-08-28 19:53:20 +02:00
Feoramund ef2cd9d97f Copy missing errors in os2._get_platform_error from posix to linux 2024-08-28 19:53:20 +02:00
Feoramund 5b9e9fb822 Add test suite for core:io 2024-08-28 19:53:20 +02:00
Feoramund 741ccd7ff5 Zero n on error in _file_stream_proc 2024-08-28 19:53:20 +02:00
Feoramund eb92a2df71 Fix indentation 2024-08-28 19:53:20 +02:00
Feoramund d60f404bb4 Fix OpenBSD implementations of read_at and write_at 2024-08-28 19:53:20 +02:00
Feoramund 6c4806835c Fix indentation 2024-08-28 19:53:20 +02:00
Feoramund e1555e04ad Fix Haiku implementations of read_at and write_at 2024-08-28 19:53:20 +02:00
Feoramund 7061032db6 Fix NetBSD implementations of read_at and write_at
These procedures must not modify the underlying file pointer.
2024-08-28 19:53:20 +02:00
Feoramund 861d892ffe Make Windows pread and pwrite conform to POSIX 2024-08-28 19:53:20 +02:00
Feoramund 5c8c63ae04 Fix FreeBSD implementations of read_at and write_at
These procedures must not modify the underlying file pointer.
2024-08-28 19:53:20 +02:00
Feoramund 1ced76cdd1 Fix broken cases of Seek usage in _file_stream_proc
Handles `EINVAL`, among other fixes.
2024-08-28 19:53:20 +02:00
Feoramund e83b982afe Measure bytes.Buffer size by length instead of capacity 2024-08-28 19:53:20 +02:00
Feoramund 7c6cc81041 Add Seek behavior to bytes.Buffer 2024-08-28 19:53:20 +02:00
Feoramund 521e47ffee Don't invalidate prev_rune if Reader seek failed 2024-08-28 19:53:20 +02:00
Feoramund 8251f4d7d0 Return .EOF in bytes.buffer_read_at instead
This is consistent with the other stream `read` procs
2024-08-28 19:53:20 +02:00
Feoramund da49f7eb4e Make bytes.reader_init return an io.Stream
Makes the API like the other stream `init` procs.
2024-08-28 19:53:20 +02:00
Feoramund d66486c17e Make io.Section_Reader set base too
This should fix seeking from `.Start`, getting the `size`, and
`read_at`.

Also make the API consistent with the other `*_init` procs in
`util.odin` by returning the `io.Reader`.
2024-08-28 19:53:20 +02:00
Feoramund 981a2e1a00 Add missing io.Stream_Mode responses 2024-08-28 19:53:19 +02:00
Laytan eb6e5ee3a1 Merge pull request #4162 from laytan/os2-disable-custom-heap-allocator
os2: disable custom heap allocator
2024-08-28 19:51:22 +02:00
Laytan 5e850e24d6 os2: disable custom heap allocator
See #4161
2024-08-28 19:45:34 +02:00
Jeroen van Rijn 17d10b72d5 Merge pull request #4158 from sqrt-negativeone/master
Win32 clipboard procedures
2024-08-28 19:02:18 +02:00
Fakhri Mouad b08c14b710 fix style, ensure we compile with flags -vet -strict-style -disallow-do 2024-08-28 17:52:58 +01:00
Jeroen van Rijn d3fca60e4d Merge pull request #4160 from Kelimion/vsdd
-vet -strict-style -disallow-do
2024-08-28 18:49:44 +02:00
Jeroen van Rijn d602e2cc74 Remove duplicate vet flag. 2024-08-28 18:43:54 +02:00
Jeroen van Rijn 831e26cb6f Remove unused import. 2024-08-28 18:42:54 +02:00
Jeroen van Rijn 7b276cbc7e -vet -strict-style -disallow-do 2024-08-28 18:36:49 +02:00
Fakhri Mouad 7e4750c303 fix indentation in test file 2024-08-28 17:30:30 +01:00
Fakhri Mouad 967b6d46b2 avoid using do statement in odin codebase 2024-08-28 17:27:27 +01:00
Jeroen van Rijn fcafd83506 Merge pull request #4159 from Kelimion/disallow-do
More -disallow-do in CI.
2024-08-28 18:20:39 +02:00
Jeroen van Rijn 21dab9673d More -disallow-do in CI. 2024-08-28 18:13:53 +02:00
Fakhri Mouad 16503c3b91 Add Win32 procs needed to handle clipboard 2024-08-28 16:36:06 +01:00
Laytan Laats 1e6419b5b7 fix zombie thread leak in thread self cleanup 2024-08-28 16:22:38 +02:00
Laytan Laats ef66f96cf2 fix windows bindings where BOOL is not actually a boolean
Fixes #4157
2024-08-28 15:45:41 +02:00
Isaac Andrade 45322023e3 Merge branch 'master' of github.com:odin-lang/Odin into posix-linux 2024-08-27 18:51:58 -06:00
Laytan Laats 9684ade23e fix -vet-tabs 2024-08-27 19:13:46 +02:00
gingerBill 8694fa5f78 Minor cleanup of CFString.odin 2024-08-27 11:22:28 +01:00
Isaac Andrade 7d94810d01 Fix ino_t and ino_t32 types for POSIX linux. 2024-08-26 22:12:05 -06:00
gingerBill fb248056c9 Merge pull request #4146 from Feoramund/fix-i128-transmute-align
Fix inline transmutation of `[16]i8` to `i128`
2024-08-26 22:38:24 +01:00
gingerBill ade4e312fe Merge pull request #4154 from avanspector/master
Delay lexical checking for foreign blocks that are in file scope
2024-08-26 22:38:13 +01:00
gingerBill 12bd07d2df Merge pull request #4150 from laytan/update-wgpu-to-22-1-0
wgpu: update to v22.1.0.1
2024-08-26 22:37:31 +01:00
gingerBill 91f8c626bb Merge pull request #4148 from Feoramund/tls-cleaner
Add API for freeing `thread_local` state
2024-08-26 22:37:08 +01:00
Laytan c1684d6335 Merge pull request #4136 from flysand7/process-info-fix
[os2/process]: Don't free process info fields in partial success scenarios
2024-08-26 23:25:21 +02:00
flysand7 1a4faff9c9 [os2/process]: Fix typo on doc comments 2024-08-27 08:06:11 +11:00
Laytan 6c17642b91 Merge pull request #4155 from Feoramund/fix-test-vet-style
Fix `-vet` and `-strict-style` failures in tests
2024-08-26 23:01:21 +02:00
Laytan ef254ec055 Merge pull request #4153 from Feoramund/fix-4151
Fix #4151
2024-08-26 22:59:48 +02:00
Feoramund 1f04f541cf Fix -vet and -strict-style failures in tests 2024-08-26 16:20:08 -04:00
avanspector dd86a8f013 Merge branch 'odin-lang:master' into master 2024-08-26 21:00:25 +02:00
avanspector 43ec2b9253 checker: delay foreign block checking
if file scope, otherwise as before
2024-08-26 20:59:16 +02:00
Laytan Laats 60cd0da2ed wgpu: cont. fix sdl2glue on Linux 2024-08-26 20:24:26 +02:00
avanspector c21bbae427 Merge branch 'master' of https://github.com/avanspector/Odin 2024-08-26 19:59:20 +02:00
avanspector d7e977069a Update checker.cpp 2024-08-26 19:59:15 +02:00
Jeroen van Rijn ef98aa1fe1 Merge pull request #4152 from edyu/master
Fix error for uuid to require 36 bytes instead 32 (4 bytes for dashes)
2024-08-26 19:35:04 +02:00
Ed Yu 4e2bce0c83 Fix error for uuid to require 36 bytes instead 32 (4 bytes for dashes) 2024-08-26 10:25:10 -07:00
Feoramund d43c6e39f6 Fix #4151
The `core:mem` procs were calling the wrong `runtime` procs for their
number of arguments.
2024-08-26 13:23:04 -04:00
Laytan f56b895c05 wgpu: fix sdl2glue not using GetWindowWMInfo properly
Fixes #4127
2024-08-26 16:08:14 +02:00
Laytan Laats 54a420f3eb wgpu: update to v22.1.0.1 2024-08-26 15:49:12 +02:00
Jeroen van Rijn 3e0f6bda91 Merge pull request #4149 from Feoramund/fix-thread-pool-use-after-free
Fix use-after-free in `thread.Pool`
2024-08-26 13:05:23 +02:00
Feoramund 9fac03b84c Fix use-after-free in thread.Pool 2024-08-26 06:39:05 -04:00
Laytan 0a8f85e879 Merge pull request #4147 from Feoramund/cleanup-test-runtime-arenas
Free the arenas allocated in `test_core_runtime`
2024-08-26 12:09:34 +02:00
Feoramund 49606ec3ea Use thread_local_cleaner API in os2 2024-08-26 06:01:59 -04:00
Feoramund d338642dc4 Add API for freeing thread_local state 2024-08-26 06:01:59 -04:00
Feoramund 95d1c29c2a Free the arenas allocated in test_core_runtime
Found by using `-sanitize:address`.
2024-08-26 05:45:24 -04:00
Feoramund c424c94030 Fix inline transmutation of [16]i8 to i128
Forbids LLVM from generating SSE aligned loads on unaligned data.
2024-08-26 04:48:31 -04:00
gingerBill 8de1e88c4f Merge pull request #4144 from laytan/riscv-error-on-atomics-without-extension
riscv: add an error when atomics are used without the atomics extension
2024-08-25 22:49:42 +01:00
flysand7 3119e0489f [os2/process]: Fix vet errors 2024-08-26 07:23:59 +11:00
flysand7 db94e646e0 [os2/process]: Adjust documentation for process info 2024-08-26 07:21:54 +11:00
flysand7 4737485f09 [os2/process]: Force return on allocation errors and process not existing 2024-08-26 07:19:39 +11:00
Laytan d299d4e1cd riscv: add an error when atomics are used without the atomics extension 2024-08-25 21:17:00 +02:00
Laytan 9aeb0d0fb6 Merge pull request #4142 from laytan/os2-propogate-errors-from-execv
os2: propagate errors from execv
2024-08-25 21:09:54 +02:00
Laytan 0ea6809b49 os2: remove return on file_size error from read_entire_file
file_size can't return .No_Size because it uses io.size and only returns
an io.Error, removing this so it works when file_size fails (linux pipes
for instance)
2024-08-25 18:43:23 +02:00
Laytan Laats a0fe6da10b os2: propogate errors from execv functions to parent 2024-08-25 18:01:33 +02:00
gingerBill 8c952878fb Allow empty strings in link_prefix and link_suffix 2024-08-25 14:03:14 +01:00
gingerBill eda58357b6 Merge pull request #4141 from VladPavliuk/fix-dwmapi-enum
Fix win32 dwmapi DWMWINDOWATTRIBUTE enum.
2024-08-25 12:46:51 +01:00
gingerBill 7b14c267fb Merge pull request #4138 from z64/z64/fix-cmark
Fix binding to cmark_node_get_fence_info
2024-08-25 12:43:07 +01:00
VladPavliuk cc2ed2b302 Fix win32 dwmapi enum. 2024-08-25 14:34:24 +03:00
Zac Nowicki 17cc423a17 Fix binding to cmark_node_get_fence_info
https://github.com/commonmark/cmark/blob/master/src/cmark.h#L334
2024-08-25 01:42:12 -04:00
flysand7 fa84e86766 [os2/process]: Allow for partial success scenarios 2024-08-25 14:22:27 +11:00
flysand7 0d7e6430eb [os2/process]: Don't free process info fields in partial success scenarios 2024-08-25 13:08:24 +11:00
Jeroen van Rijn 4cf1af3f7d Merge pull request #4135 from gelatinstudios/master
fix core:reflect/iterator.odin
2024-08-24 23:23:33 +02:00
Laytan eef4dffa12 Merge pull request #4134 from karl-zylinski/fix-raylib-LoadImageAnim-binding
Fix binding: Make rl.LoadImageAnim take a pointer instead of a multi-pointer.
2024-08-24 22:56:49 +02:00
Karl Zylinski 25e8a6353d Fix comment indentation. 2024-08-24 22:02:17 +02:00
unknown ae5ef0ce9c fix core:reflect/iterator.odin 2024-08-24 16:01:49 -04:00
Karl Zylinski 574a5015d6 Make rl.LoadImageAnim take a pointer instead of a multipointer. The param frames is just for returning an int, it's not for passing a multipointer into the proc. 2024-08-24 22:00:29 +02:00
Jeroen van Rijn 0a825fc44d Improve SRV handling in dns_windows.odin 2024-08-24 18:43:25 +02:00
gingerBill aa659a637a Fix #4132 2024-08-24 15:46:54 +01:00
gingerBill 0e71e93b22 Remove unused import 2024-08-24 14:51:28 +01:00
gingerBill 61b3af5b08 MemFree as a procedure group for both rawptr and cstring 2024-08-24 14:51:05 +01:00
gingerBill 19b95349a6 Use fmt.caprintf directly 2024-08-24 14:47:33 +01:00
gingerBill d0eaf7642d Add intrinsics.type_has_shared_fields 2024-08-24 14:36:18 +01:00
gingerBill eb799393d5 Fix -vet-tabs issues 2024-08-24 13:56:41 +01:00
gingerBill 8ba87e01bd Improve parse_enforce_tabs usage 2024-08-24 13:56:30 +01:00
gingerBill daccd72162 Merge branch 'master' of https://github.com/odin-lang/Odin 2024-08-24 13:36:51 +01:00
gingerBill 8b248673c1 Fix #4105 2024-08-24 13:36:43 +01:00
Jeroen van Rijn faec52623d Merge pull request #4128 from gordonshamway23/mini_fix_in_image
Added missing slice advancing.
2024-08-24 14:23:42 +02:00
gingerBill b6d9a0c32e Manually implement tail-recursion for parse_if_stmt 2024-08-24 13:16:55 +01:00
gingerBill a4cc207022 Add a recursion depth limit for #3987 with a consideration to use a switch statement or refactor the code to not use a large if-else chain 2024-08-24 12:59:17 +01:00
gingerBill 683dde1fa0 Disallow labelled branches in defer - fix #3960 2024-08-24 12:47:29 +01:00
gingerBill ca4d91a8a3 Fix #4079 2024-08-24 12:26:41 +01:00
gingerBill 65543b993f Merge pull request #4130 from fusion32/fix-ambiguous-generic-type-names
fix ambiguous generic type names
2024-08-24 11:50:02 +01:00
gingerBill 00fb60d3d9 #4115 Add Suggestion: 'typeid_of(T)' 2024-08-24 11:48:32 +01:00
gingerBill 68a83abcd6 #4119 Add error when doing {.A | .B} instead of {.A, .B} with a suggestion to do surround it in parentheses to make it clear it is intended 2024-08-24 11:44:59 +01:00
gingerBill 4458ca4585 Fix #4126 2024-08-24 11:40:02 +01:00
Isaac Andrade e0b78476c5 Fix else when clause. 2024-08-23 20:18:26 -06:00
Isaac Andrade 2794eb31d9 On Linux POSIX, ENOTSUP and EOPNOTSUPP have the same value. 2024-08-23 20:08:59 -06:00
Isaac Andrade d8e4a1b93f Fix comment typo on POSIX ENOTSUP constant.
Co-authored-by: Feoramund <161657516+Feoramund@users.noreply.github.com>
2024-08-23 20:02:44 -06:00
Isaac Andrade 9c06898303 Add comma to last dirent struct member. 2024-08-23 20:01:15 -06:00
Isaac Andrade 90aa7dff04 Add POSIX dirent struct for Linux. 2024-08-23 19:56:45 -06:00
Isaac Andrade 1adea2f4d6 Merge branch 'master' of github.com:odin-lang/Odin into posix-linux 2024-08-23 18:40:35 -06:00
fusion32 5ef8a092f6 fix wrong exact value kind comparison 2024-08-23 17:50:27 -03:00
fusion32 c969bee86d fix ambiguous generic type names 2024-08-23 17:18:10 -03:00
gordonshamway23 426367c522 Added missing slice advancing. 2024-08-23 21:28:59 +02:00
Laytan Laats d410281766 os2: do read_entire_file in parts if the file size is 0 2024-08-23 20:25:47 +02:00
Laytan Laats ce53805d94 os2: fix read_entire_file wrong slice end variable 2024-08-23 20:25:19 +02:00
Laytan Laats 963e8544f4 os2: CLOEXEC the fds from pipe for posix implementation 2024-08-23 20:25:05 +02:00
Laytan Laats c2a7c29ce8 os2: fix using uuid as process handle for darwin, once it goes zombie it changes 2024-08-23 20:24:06 +02:00
Laytan b3f22133f3 Merge pull request #4123 from laytan/more-core-orca-support
orca: implement core:time and core:log
2024-08-23 18:47:00 +02:00
Laytan Laats caef37bc18 orca: implement core:time and core:log 2024-08-23 18:25:10 +02:00
gingerBill 574dc5efe6 Merge pull request #4120 from laytan/posix-process
os2: process API for Darwin and most of it for BSDs
2024-08-22 22:51:48 +01:00
Laytan Laats a66520ba57 os2: process API for Darwin and most of it for BSDs 2024-08-22 23:07:24 +02:00
Laytan Laats b9043db434 os2: make platform error more ergonomic by making it an alias 2024-08-22 22:59:13 +02:00
Laytan Laats 58e5078b66 add riscv to simd.IS_EMULATED 2024-08-22 14:17:45 +02:00
gingerBill 70932dc478 Merge pull request #4089 from laytan/riscv64
add support for linux_riscv64 and freestanding_riscv64
2024-08-22 11:20:03 +01:00
Jeroen van Rijn a8bc6f08a9 Merge pull request #4116 from Kelimion/article
Add table-driven (in)definite article to some errors.
2024-08-21 18:51:43 +02:00
Jeroen van Rijn 07aedb0b89 , 2024-08-21 18:42:11 +02:00
Thomas la Cour 171d917b7e odin manifest file 2024-08-21 16:26:10 +02:00
Laytan 63cd9a031a fix variadic parameter with default value error check 2024-08-21 15:11:16 +02:00
gingerBill c77e8ca401 Fix tests 2024-08-21 14:06:04 +01:00
gingerBill 58e811eea5 Merge pull request #3962 from Feoramund/regex
Add `core:text/regex`
2024-08-21 13:55:11 +01:00
Laytan c0125f3192 correct the riscv64 stat structs 2024-08-21 14:41:23 +02:00
Jeroen van Rijn 1bcc074223 dash 2024-08-21 14:18:12 +02:00
gingerBill e7b8e61c68 Merge pull request #4106 from yeongjukang/master
core:sys/linux - implement clock_settime, clock_getres and clock_nanosleep
2024-08-21 09:41:14 +01:00
Isaac Andrade ef06cd93cc Initial implementation of linux-specifig dirent struct. 2024-08-20 20:35:56 -06:00
Isaac Andrade c0521c6d99 Add linux support for errno. 2024-08-20 20:35:28 -06:00
Yeongju Kang bbe4c32e32 changed signature of clock_getres 2024-08-21 08:25:14 +09:00
Laytan 0d39f52b4d Merge pull request #4117 from yay/vet-tabs
A couple of foundation binding. Vet tabs.
2024-08-21 01:16:30 +02:00
Vitalii Kravchenko 14169ae5b4 A couple of foundation binding. Vet tabs. 2024-08-21 00:09:09 +01:00
Jeroen van Rijn 6b4b0cea5d Add table-driven (in)definite article to some errors. 2024-08-20 22:13:31 +02:00
Laytan 85a33a1c9b add constant_log2 to intrinsics file 2024-08-20 19:14:50 +02:00
Laytan 8f2d3dc955 fix i128 division? 2024-08-20 19:01:09 +02:00
Jeroen van Rijn daa0779c01 Rewrite compound_to_time without using i128. 2024-08-20 18:50:05 +02:00
Laytan d7e81e86f5 Merge pull request #4110 from andradei/termios-linux
Add support for Linux on os/sys/posix termios.
2024-08-20 17:23:53 +02:00
Laytan 06fb500dfe make sure net.Network_Error is of size 8 2024-08-20 15:52:07 +02:00
Jeroen van Rijn 5ef58049dc Merge pull request #4114 from it-a-me/master
fix wiki link in the README.md
2024-08-20 14:27:47 +02:00
Laytan Laats 5b22bfa2b7 unify LB_ABI_INFO and LB_ABI_INFO_CTX 2024-08-20 14:07:47 +02:00
Laytan ca6ef95b03 add support for linux_riscv64 and freestanding_riscv64 2024-08-20 14:06:40 +02:00
it-a-me 53500699a9 README.md: Fix wiki link 2024-08-19 23:00:26 -07:00
Jeroen van Rijn 29838da782 Merge pull request #4111 from RoryO/simd-typo
fix simd var typo
2024-08-20 00:52:37 +02:00
Rory OConnell 97795ff3a2 fix simd var typo 2024-08-19 15:50:42 -07:00
Isaac Andrade 6df51b42a8 Fix termios NCCS size on linux. 2024-08-19 15:32:55 -06:00
Isaac Andrade 3228178d87 Add support for Linux on os/sys/posix termios. 2024-08-19 14:56:37 -06:00
Jeroen van Rijn 3fc1f6f1cd Merge pull request #4101 from Yawning/feature/index-byte-tweaks
core/bytes: Tweak `index_byte`/`last_index_byte`
2024-08-19 20:43:37 +02:00
gingerBill 2999c02f65 Fix random typo 2024-08-19 16:33:17 +01:00
gingerBill 9d7ab8d5ca Add strings.contains_space 2024-08-19 16:31:03 +01:00
gingerBill 2a0785037b Fix switch val in ptr 2024-08-19 12:19:45 +01:00
Yawning Angel 9e65e229d0 core/bytes: Tweak index_byte and last_index_byte
- Assume unaligned loads are cheap
- Explicilty use 256-bit or 128-bit SIMD to avoid AVX512
- Limit "vectorized" scanning to 128-bits if SIMD is emulated via SWAR
- Add a few more benchmark cases
2024-08-19 11:40:36 +09:00
Jeroen van Rijn 34a9e20531 Merge pull request #4108 from Feoramund/remove-deprecated-testing-log
Remove deprecated `log` procs from `core:testing`
2024-08-19 04:19:22 +02:00
Feoramund 0fa24ac3c4 Remove deprecated log procs from core:testing 2024-08-18 21:30:32 -04:00
Jeroen van Rijn 17eb0b5ee0 Merge pull request #4107 from Feoramund/add-digit-count
Add `core:math.count_digits_of_base`
2024-08-19 02:36:05 +02:00
Feoramund b49b80bdf9 Add test for count_digits_of_base 2024-08-18 20:14:14 -04:00
Feoramund 2906f2aa7e Add core:math.count_digits_of_base 2024-08-18 20:14:14 -04:00
Yeongju Kang f96991364a implement clock_settime, clock_getres and clock_nanosleep 2024-08-19 08:53:07 +09:00
Laytan 359a212a78 Merge pull request #4104 from laytan/find-llvm-config-through-brew
query brew for llvm-config location if possible
2024-08-19 00:41:06 +02:00
Laytan Laats ea7e8f075d query brew for llvm-config location if possible 2024-08-19 00:02:14 +02:00
gingerBill d99a6ad003 Add suggestion for ~uint(0) if cast(uint)-1 is done 2024-08-18 22:52:57 +01:00
gingerBill 95c3b8a8de Move assert to else branch 2024-08-18 22:45:26 +01:00
Laytan Laats ae41779366 remove redundant & 2024-08-18 21:10:21 +02:00
Laytan bb3f848b4a Merge pull request #4103 from laytan/wait-shared-on-macos-10-15
UL_COMPARE_AND_WAIT_SHARED is macOS 10.15+
2024-08-18 19:38:52 +02:00
gingerBill a51b9c6fb0 Merge branch 'master' of https://github.com/odin-lang/Odin 2024-08-18 18:37:45 +01:00
gingerBill 8e52a52580 Cache the paddding filler type 2024-08-18 18:37:40 +01:00
Laytan Laats b7b3ada3b1 UL_COMPARE_AND_WAIT_SHARED is macOS 10.15+ 2024-08-18 19:31:52 +02:00
Laytan 9a895a318c Merge pull request #4102 from laytan/wasm-lshrti3
Implement lshrti3 on wasm
2024-08-18 17:18:05 +02:00
Laytan Laats b2e64b7ce0 implement lshrti3 on wasm 2024-08-18 17:09:57 +02:00
Yawning Angel 7020e9b66a core/simd: Add IS_EMULTATED so there is one place to look for potatos 2024-08-18 22:52:39 +09:00
gingerBill f49ebae956 Correct lbAddr_SoaVariable logic 2024-08-18 12:37:15 +01:00
gingerBill 0e82a46047 Fix #3999 2024-08-18 12:35:25 +01:00
gingerBill c4e0cbcd87 Fix #4005 2024-08-18 12:21:35 +01:00
gingerBill f82bf6cd42 Fix #4022 2024-08-18 12:13:52 +01:00
gingerBill 60b2979cfd Fix #4024 2024-08-18 12:10:46 +01:00
gingerBill 17740966e5 Fix #4040 2024-08-18 12:06:58 +01:00
gingerBill 5c06fcd346 Fix #4064 2024-08-18 12:00:27 +01:00
gingerBill 22a82e73d6 Fix #3976 2024-08-18 11:45:27 +01:00
Jeroen van Rijn bbb5593f87 Merge pull request #4098 from jolson88/raygui/vertical-text-alignment
(raygui) Restores vertical text alignment broken after 4.0 migration
2024-08-17 22:29:38 +02:00
Jason Olson d00057c803 Add missing trailing comma 2024-08-17 13:23:42 -07:00
Jason Olson acfd9dcd1b Restores vertical text alignment broken after 4.0 migration
A series of changes between raygui 3.6 and 4.0 were that various text box
properties were moved from the text box specific properties up into the
extended default control properties. This change corrects the various
property enums to match the raygui 4.0 API.

One additional aspect of this change was rolling back a previous commit
made to this vendor file that changed the signature of GuiSetStyle and
GuiGetStyle from using a c.int as property value to a more strongly-defined
GuiControlProperty enum. Unfortunately, this breaks the raygui API by
disallowing the use of various control-specific extended properties due to
how the enums are built.
2024-08-17 12:35:50 -07:00
Jeroen van Rijn 9553bc3689 If missing type is newline, print "newline", not \n
Turns:

W:/Odin/bug/bug.odin(3:27) Syntax Error: Expected a type, got '
'
        Storage :: distinct map[]

Into:

W:/Odin/bug/bug.odin(3:27) Syntax Error: Expected a type, got newline
        Storage :: distinct map[]
2024-08-17 17:25:52 +02:00
Jeroen van Rijn ebbb70f11d Error if missing map key type
Fixes #4096
2024-08-17 17:12:27 +02:00
Laytan Laats 142bda2804 posix: start on process API 2024-08-17 15:48:01 +02:00
Jeroen van Rijn 478f529744 Merge pull request #4094 from amad00r/fix-nil-logger
Fix log unnecessary allocations
2024-08-17 01:50:13 +02:00
gingerBill 536a342873 Merge pull request #4092 from laytan/fix-open-bindings
fix `open` bindings
2024-08-17 00:22:46 +01:00
Amadeu Moya 43dc7704a5 Fix log unnecessary allocations 2024-08-17 00:37:01 +02:00
Laytan Laats e8933e43ec add haiku to unsupported time file 2024-08-16 23:18:59 +02:00
Laytan Laats f7d7d65bc0 fix open bindings
`open` specifies the `mode` argument as vararg (presumably to make it
optional). varargs actually have rules about casting, in this case the
rule that any integer arg of size <= 4 has to be casted to `i32` before
passing it.

Not doing that implicit cast makes the permissions wrong or not apply at
all.
2024-08-16 22:54:53 +02:00
Jeroen van Rijn 970dc7a1f2 Merge pull request #4091 from Feoramund/fix-darwin-os-open
Check if file open-mode is `O_CREATE` on Darwin before forcing chmod
2024-08-16 20:31:22 +02:00
Feoramund a07878be71 Check if file open-mode is O_CREATE on Darwin before forcing chmod
Fixes #4087
2024-08-16 14:08:55 -04:00
Jeroen van Rijn 14e207088a Merge pull request #4088 from Kelimion/benchmark
Improve benchmarks.
2024-08-16 17:16:59 +02:00
Jeroen van Rijn 6c46c9e04b Improve benchmarks. 2024-08-16 17:00:16 +02:00
gingerBill 40b8150a23 Minor clean ups 2024-08-16 12:47:23 +01:00
gingerBill 31bb3dc4f0 Merge pull request #3971 from jasonKercher/os2-process-linux
os2 process linux implementation
2024-08-16 12:38:27 +01:00
gingerBill 65ce7687d7 Merge pull request #4004 from Skytrias/orca-odin-bindings
Add autogenerated orca bindings and macros from laytan
2024-08-16 12:37:36 +01:00
Laytan 6fc39c1b5d Merge pull request #4075 from yay/more-foundation-bindings
More Foundation bindings.
2024-08-16 13:08:15 +02:00
jason 07a9c69714 update core:filepath's clean, join and split_list to return optional Allocator_Errors 2024-08-16 01:48:27 -04:00
Vitalii Kravchenko 004036dc59 More Foundation bindings. 2024-08-16 00:00:29 +01:00
Laytan d91fa162d8 Merge pull request #3280 from beaumccartney/shm_syscalls
add shm_open and shm_unlink syscalls for darwin
2024-08-15 17:08:41 +02:00
gingerBill 6e91f6ab31 Merge pull request #4081 from DerTee/master
fix error handling in os2.read_entire_file_from_file()
2024-08-14 22:12:06 +01:00
gingerBill b16d5198a3 Merge pull request #4082 from FourteenBrush/master
Fix 'odin [run|test] --' giving a compiler out of bounds
2024-08-14 22:11:55 +01:00
FourteenBrush 12813e5d48 Fix 'odin [run|test] --' giving a compiler out of bounds 2024-08-14 21:37:40 +02:00
DerTee 6422e49255 fix error handling in os2.read_entire_file_from_file()
even when an error in file_size() happened, os2.ERROR_NONE was returned
2024-08-14 17:30:02 +02:00
Jeroen van Rijn f7234e2ed3 Allow ODIN_TEST_LOG_LEVEL override when -debug. 2024-08-14 16:29:51 +02:00
gingerBill e810c3eace Merge pull request #4012 from laytan/posix
core:sys/posix and core:os/os2 based on it (for darwin, netbsd, freebsd and openbsd)
2024-08-14 15:10:31 +01:00
gingerBill 18b6af1858 Minor clean up of comments 2024-08-14 14:15:20 +01:00
gingerBill 03dd38f203 Minor changes to vendor:ENet 2024-08-14 14:09:36 +01:00
gingerBill eb6f2078cf Add fmt:"v,extensions_count" tags to many struct fields 2024-08-14 14:03:41 +01:00
gingerBill df61096317 Improve doc comments for vendor:ggpo 2024-08-14 13:55:25 +01:00
gingerBill 8abe054665 Merge branch 'master' of https://github.com/odin-lang/Odin 2024-08-14 13:02:28 +01:00
gingerBill 324d9c2284 Fix doc writer bug caused by using an iterator rather than a for loop 2024-08-14 13:02:23 +01:00
Laytan Laats f657b4cc0c time: use assert_contextless in wasi implementation 2024-08-14 13:27:58 +02:00
gingerBill c98c95fcf0 Add require_results and change some of the wrapper to return a slice 2024-08-14 11:29:23 +01:00
gingerBill fd5376ba88 Allow @(require_results) on foreign blocks 2024-08-14 11:28:49 +01:00
gingerBill 78fa675c1a Add assert_contextless, panic_contextless, unimplemented_contextless 2024-08-14 11:18:24 +01:00
gingerBill 4c19f507ff Merge pull request #4074 from odin-lang/vendor/box2d
`vendor:box2d`
2024-08-14 11:15:34 +01:00
gingerBill 651122e9db Fix foreign import paths 2024-08-14 11:01:54 +01:00
gingerBill d1e114742e Add deprecated and require_results attributes to math_functions.odin 2024-08-14 10:55:40 +01:00
Laytan 29a6959a56 Merge pull request #2977 from jakubtomsu/disallow-variadic-param-default
Report error when a variadic procedure parameter has a default value
2024-08-14 11:55:09 +02:00
gingerBill 491def9d5b Fix paths for amd64 targets 2024-08-14 10:50:53 +01:00
gingerBill 427c48221d Clean up foreign import code for library path determination 2024-08-14 10:28:07 +01:00
gingerBill 1c97739ca3 Merge branch 'vendor/box2d' of https://github.com/odin-lang/Odin into vendor/box2d 2024-08-14 10:18:41 +01:00
gingerBill 0b26115805 Improve presentation 2024-08-14 10:18:36 +01:00
gingerBill 1c8672ac6c Merge pull request #4078 from funkkiy/fix-rodata-index
Error if assigning to `rodata` variable with index
2024-08-14 09:41:35 +01:00
jason 0f052dbde7 os2/process_linux: improve error handling, use pidfd where possible, remove usage of fmt 2024-08-14 00:45:25 -04:00
Davi 4bb51249d1 Error if assigning to rodata variable with index 2024-08-13 23:28:34 -03:00
Laytan Laats e29f0a0f40 os2: dup the file descriptor before fdopendir 2024-08-14 01:45:24 +02:00
Laytan Laats f837e35f4b os2: fix bad free for posix file closure 2024-08-14 01:45:24 +02:00
Laytan Laats 61ee2efa35 os2: just use runtime._heap_allocator_proc instead of a copy for posix 2024-08-14 01:45:24 +02:00
Laytan Laats e94c4e1e18 posix: remove the is_temp things that prevented use-after-frees
https://github.com/odin-lang/Odin/commit/d0709a7de21efded4625167dbff4a7dd13d561b4
fixes those another way.
2024-08-14 01:45:24 +02:00
Laytan Laats b07d0b38b1 os2: improve absolute/full path handling for posix 2024-08-14 01:45:23 +02:00
Laytan Laats a73677d21a os2: nice != priority 2024-08-14 01:44:37 +02:00
Laytan Laats 67ea7bb65a posix: address some freebsd feedback 2024-08-14 01:44:37 +02:00
Laytan Laats 175f5b0bb1 os2: don't rely on PATH_MAX in posix read_directory implementation 2024-08-14 01:44:37 +02:00
Laytan Laats 939ba4cf08 os2: fix leak and always close directory 2024-08-14 01:44:37 +02:00
Laytan Laats f00f68ef6f posix/os2: fix test and add back in removed temp guard 2024-08-14 01:44:37 +02:00
Laytan Laats de9abe1f7b os2: skip . and .. in read dir 2024-08-14 01:44:37 +02:00
Laytan Laats bd808f9ec6 os2: fix wiping results with temp allocator guard 2024-08-14 01:44:37 +02:00
Laytan Laats 7474db6a34 os2: fix lstat logic 2024-08-14 01:44:37 +02:00
Laytan Laats 00eb702c4a os2: implement the iterator based read directory 2024-08-14 01:44:37 +02:00
Laytan Laats ea5783c2ac os2: fixes after rebasing 2024-08-14 01:44:37 +02:00
Laytan Laats e05fddc001 posix: fix file type checks in stat 2024-08-14 01:44:37 +02:00
Laytan Laats 406e60f5dd posix: revert change to os that was done for testing 2024-08-14 01:44:37 +02:00
Laytan Laats 5115aee23f posix: actually fix netbsd test 2024-08-14 01:44:37 +02:00
Laytan Laats 72220a855f posix: fix write error check 2024-08-14 01:44:37 +02:00
Laytan Laats 4a61bac100 posix: fix test on netbsd 2024-08-14 01:44:37 +02:00
Laytan Laats 726891588f posix: more tests 2024-08-14 01:44:37 +02:00
Laytan Laats 2a5ceff667 posix: move doc 2024-08-14 01:44:37 +02:00
Laytan Laats 9e2c5acb9d os2: fix bit checks 2024-08-14 01:44:37 +02:00
Laytan Laats 7c9ca60ff0 mem/virtual: support the BSDs 2024-08-14 01:44:37 +02:00
Laytan Laats 379cd6fe66 os2: cleanup 2024-08-14 01:44:37 +02:00
Laytan Laats ffff3c3c88 posix: fix foreign import of dl for free/netbsd 2024-08-14 01:44:37 +02:00
Laytan Laats a4d459f651 os2: initial implementation for Darwin&BSDs, process API is only thing incomplete 2024-08-14 01:44:37 +02:00
Laytan Laats ff0ca0bd53 os2: make config directory on darwin also ~/.config, it is the proper place 2024-08-14 01:44:37 +02:00
Laytan Laats 07b9f7d280 os2: fix read_entire_file bad logic 2024-08-14 01:44:37 +02:00
Laytan Laats 9f80191f60 os2: add default make_directory permissions 2024-08-14 01:44:37 +02:00
Laytan Laats efe68c2e24 posix: add package 2024-08-14 01:44:35 +02:00
Laytan 3847d03248 Merge pull request #3281 from erjohnson/patch-1
Update mem doc example formatting
2024-08-14 00:10:03 +02:00
Laytan Laats bb54a0a972 fix whitespace 2024-08-14 00:08:46 +02:00
Laytan Laats ac68a9d52c update MacOS releases 2024-08-14 00:00:50 +02:00
Laytan Laats d4d46df2fc box2d: add build script and MacOS libraries 2024-08-13 22:15:31 +02:00
gingerBill 660b6ff0f1 Add vendor:box2d to examples/all 2024-08-13 17:08:31 +01:00
gingerBill 9ccaca7f1a Minor style change 2024-08-13 17:01:55 +01:00
gingerBill 926c419ef8 Change .lib to be /MT compatible; Fix comments 2024-08-13 16:58:35 +01:00
gingerBill 22b32ab0fa Use intrinsics.has_target_feature 2024-08-13 16:35:28 +01:00
gingerBill 40361f877e Add libraries for windows 2024-08-13 16:34:31 +01:00
gingerBill f2ba3da895 Create bindings for box2d
Currently missing lib binaries
2024-08-13 16:18:24 +01:00
Laytan 55be3e60a0 Merge pull request #3125 from marcs-feh/master
sys/linux: Add binding to ioctl syscall + standard fd constants.
2024-08-13 15:30:50 +02:00
gingerBill 62911539cd Minor style change 2024-08-13 14:27:25 +01:00
Laytan c7af8af76a Update core/sys/linux/sys.odin 2024-08-13 15:22:35 +02:00
gingerBill e3d5bbe62c Merge pull request #4065 from laytan/fix-max-alignments
fix max alignments
2024-08-13 14:09:45 +01:00
gingerBill 2584c6bcd7 Merge pull request #4069 from zen3ger/1738-aliased-procedure-resolution
Fix alias handling of procedures
2024-08-13 14:07:51 +01:00
gingerBill 66d3082a9a Merge pull request #4056 from laytan/re-enable-runtime-wasm-stuff
re-enable some wasm things in runtime
2024-08-13 14:04:19 +01:00
gingerBill 09a07bd7e0 Merge pull request #4055 from laytan/time-wasi
time: wasi implementation
2024-08-13 14:03:02 +01:00
gingerBill 848f7e117f Merge pull request #4050 from IllusionMan1212/egl-procs
vendor/egl: added a few more egl procedures and constants
2024-08-13 14:01:20 +01:00
gingerBill d93364ce52 Merge pull request #4049 from IllusionMan1212/xrandr-xinput-xfixes
vendor/x11: added a few procedures for xrandr, xinput, and xfixes
2024-08-13 14:00:08 +01:00
gingerBill 4c4f24b5f4 Merge pull request #4041 from zen3ger/1079-parametric-struct-from-other-package
Check if procedure parameter type declares polymorphic args
2024-08-13 13:59:06 +01:00
Jeroen van Rijn 069ad446cd Merge pull request #4070 from Feoramund/test-runner-mem-fail-as-error
Let memory failures be errors in the test runner
2024-08-13 13:50:46 +02:00
Jeroen van Rijn 02b4bb8491 Merge pull request #4072 from laytan/fix-32-bit-math-round
fix type hint propagation for shift
2024-08-13 00:34:19 +02:00
Laytan Laats 2808ecc5b6 remove panic workaround 2024-08-12 23:48:36 +02:00
Laytan Laats a1d518442a fix type hint propogation for shift
Fixes #3856
2024-08-12 23:39:07 +02:00
Jeroen van Rijn 0d916a659e Merge pull request #4053 from Feoramund/fix-gitignore
Fix `.gitignore`
2024-08-12 21:34:26 +02:00
Feoramund 3a32250b80 Add .gitignore for tests directory 2024-08-12 15:16:52 -04:00
Jeroen van Rijn 053e65a1c8 Merge pull request #4071 from andreas-jonsson/andreas-jonsson-patch-2
Use another URL for pkgsrc on CI
2024-08-12 20:58:41 +02:00
Andreas T Jonsson 7af0291c7d Try use another arch URL for pkgsrc 2024-08-12 20:27:20 +02:00
Feoramund 0af025d056 Add explicit copyright info to core:testing 2024-08-12 14:16:22 -04:00
Roland Kovacs 9eb7186cda Fix alias handling of procedures
An incorrect memmove when overriding entities caused multiple ones to point to
the same procedure with incomplete variant data, resulting in later hiting a
compiler assertion.

Introduced delayed type checking for procedure aliases, as it was masked by
the previous error in the override logic.
2024-08-12 19:52:42 +02:00
Laytan d68cc41782 Merge pull request #4068 from laytan/fix-read-dir-closing-given-fd
fix `os.read_dir` closing the given file descriptor
2024-08-12 19:23:48 +02:00
Laytan fb09ec06d3 Merge pull request #4066 from Tetralux/fmt-bitfields-pointers
[fmt] Add bit fields to the pointer printing logic
2024-08-12 19:14:15 +02:00
Laytan Laats a4ac3cc6e8 fix os.read_dir closing the given file descriptor 2024-08-12 18:51:27 +02:00
Tetralux 4f56822204 [fmt] Add bit fields to the pointer printing logic
core:fmt prints pointers to structs as `&StructName{ ... }` but `bit_field`s are currently printed
the same as rawptrs (`0xAABBCCDDEEFF` only).

This commit changes that so they behave the same as structs and unions.
2024-08-12 16:25:22 +00:00
Laytan Laats f22ff21039 fix max alignments 2024-08-12 17:05:51 +02:00
Laytan b71e0c2e36 Merge pull request #4059 from laytan/loop-write-entire-file
loop write_entire_file to write more than MAX_RW
2024-08-12 13:54:46 +02:00
Laytan fd9a008e1e Merge pull request #4058 from laytan/fix-cvararg-bitset
fix c_vararg bit_set
2024-08-12 13:54:28 +02:00
Laytan 450fc3ec77 Merge pull request #4060 from laytan/support-field-tag-bitsets-in-core-odin
core/odin: support field tags on bit_field fields
2024-08-12 13:53:33 +02:00
Laytan 0a118a14ab Merge pull request #4061 from laytan/fix-fmt-maybe-pointer-detection
fix `type_info_union_is_pure_maybe` only working with regular pointers
2024-08-12 13:53:17 +02:00
Feoramund f42a22369e Fix wrong define name in test runner log messages 2024-08-11 23:01:28 -04:00
Feoramund 675add4d90 Optionally treat memory failures as errors in the test runner
Enable with `-define:ODIN_TEST_FAIL_ON_BAD_MEMORY=true`.
2024-08-11 22:59:20 -04:00
Jeroen van Rijn 1761802330 Merge pull request #4062 from laytan/fix-switch-over-internal-pointer-union
fix type switching over internal pointer union
2024-08-12 00:25:47 +02:00
Laytan Laats 99aa0d3a35 fix type switching over internal pointer union
Fixes #3947
2024-08-12 00:02:05 +02:00
Laytan Laats dec97cbddb fix type_info_union_is_pure_maybe only working with regular pointers
Fixes #3996
2024-08-11 21:07:21 +02:00
Laytan Laats f0840ed24e core/odin: support field tags on bit_field fields
Fixes #4044
2024-08-11 20:59:54 +02:00
Laytan b9e68ee3c1 Merge pull request #4054 from Feoramund/zlib-reverse-bits
Use `intrinsics.reverse_bits` in `core:compress/zlib`
2024-08-11 17:42:28 +02:00
Laytan Laats d6336e7252 add orca to examples/all for docs 2024-08-11 17:35:19 +02:00
Laytan Laats c6a0d302b3 loop write_entire_file to write more than MAX_RW
Fixes #4042
2024-08-11 17:27:54 +02:00
Laytan Laats 26fa3aca44 fix copy-paste error in make docs 2024-08-11 17:09:26 +02:00
Laytan Laats e3f375afd8 fix c_vararg bit_set
Fixes #4051
2024-08-11 17:00:49 +02:00
Jeroen van Rijn 8a67221bd4 Merge pull request #4057 from asibahi/patch-1
typo fix
2024-08-11 13:35:10 +02:00
Abdul Rahman Sibahi 67251ad5b8 typo fix 2024-08-11 14:30:48 +03:00
Laytan 938e81e341 sys/orca: add missing using 2024-08-10 23:59:51 +02:00
Laytan Laats f5fe0de0fd add clarity for diverging mismatch error 2024-08-10 23:34:35 +02:00
Laytan Laats 7fd8b9c55b re-enable some wasm things in runtime
No idea why the floattidf procs are bodged to return 0, does somebody
know? I have just enabled the original codepath, if nobody knows I
suggest just enabling it and see if we get complaints, it works on all
wasm stuff I tried.

The linkage being set to "internal" instead of "strong" is actually
causing problems in my projects which is what prompted looking at this
in the first place, some of these functions were actually needed but not
added/used because they had internal linkage. This only happens on
bigger projects (or just when using f16?).

Unfortunately `git blame` gave me this generic commit: https://github.com/odin-lang/Odin/commit/94bad4d7861c78b9e7191ec0c3114861a1536d5c#diff-fb9f42022cb95efa59d16813546b8cb310234428c85edfabf09b1425c9dc46af
2024-08-10 23:10:30 +02:00
Laytan Laats a2cd763dbb time: wasi implementation 2024-08-10 23:01:31 +02:00
Feoramund cf8f6afeff Use intrinsics.reverse_bits in core:compress/zlib 2024-08-10 15:29:44 -04:00
Feoramund afbdc78f85 Fix .gitignore
- Remove all-encompassing `benchmark`
- Add exception for `core:simd/x86`
2024-08-10 15:16:12 -04:00
Laytan Laats 6918d8aaa6 possibly fix init_core_type_info race condition 2024-08-10 21:03:40 +02:00
Jeroen van Rijn e226d37803 Merge pull request #4023 from Feoramund/simd-index
Vectorize `index_byte`
2024-08-10 21:01:41 +02:00
Feoramund 4f816aabb3 Use SIMD_SCAN_WIDTH constant in core:bytes test 2024-08-10 13:54:12 -04:00
Laytan Laats d98f848247 fix debug compiler build message not ending output with a newline 2024-08-10 19:07:30 +02:00
Jeroen van Rijn 1242b6e82f Improve slice.binary_search_by 2024-08-10 18:26:59 +02:00
Jeroen van Rijn 9759d56c81 Merge pull request #4003 from Yawning/feature/crypto-improvements
core:crypto: Various improvements
2024-08-10 17:17:00 +02:00
Laytan d73ad8eb1e Merge pull request #4046 from laytan/cbor-fixes
encoding/cbor: various fixes
2024-08-10 17:02:41 +02:00
jason a52f7c129f stop trying to handle child pipe read errors in process_start 2024-08-10 09:13:07 -04:00
jason e54d6e5a11 Ignore process_open errors in process_start. This enforces a contract
with the user that any process returned without error must eventually be
waited on.
2024-08-10 09:03:34 -04:00
jason f7a73b9555 fix error handling; close read end of the child pipe instead of the write end twice 2024-08-10 08:55:40 -04:00
Feoramund 9d2b4b2f03 Simplify core:bytes test 2024-08-10 08:13:22 -04:00
Feoramund 5d5addd48f Set SIMD_SCAN_WIDTH based on size_of(uintptr) 2024-08-10 07:43:14 -04:00
Feoramund c69fa87d53 Merge core:simd/util into core:bytes 2024-08-10 07:17:03 -04:00
Jeroen van Rijn bf53d2f6db Fix time.precise_clock on 32-bit platforms. 2024-08-10 12:44:40 +02:00
Jeroen van Rijn d267735d99 Fixed time.precise_clock 2024-08-10 12:35:58 +02:00
IllusionMan1212 554b0e5bf7 vendor/x11: added a few procedures for xrandr, xinput, and xfixes 2024-08-10 12:06:52 +02:00
Yawning Angel ba1ad82c2b core/crypto/aead: Initial import 2024-08-10 18:32:37 +09:00
Yawning Angel 38aea1f907 core/crypto/aes,chacha20poly1305: Add require_results to open 2024-08-10 18:32:37 +09:00
Yawning Angel b381791f42 core/crypto/chacha20: Change API terminology to be consistent with AES 2024-08-10 18:32:37 +09:00
Yawning Angel 14ceb0b19d core/crypto/chacha20poly1305: Support AEAD_XChaCha20_Poly1305
IETF-draft flavor (32-bit counter) though this makes no practical
difference.
2024-08-10 18:32:37 +09:00
Yawning Angel 8efc98ce90 core/crypto/chacha20poly1305: Change the interface to match GCM 2024-08-10 18:32:37 +09:00
Yawning Angel 1f3107e693 core/crypto/chacha20: Use 128-bit/256-bit SIMD 2024-08-10 18:32:37 +09:00
Yawning Angel 708f053fe6 core/crypto/aes: Use NIST terminology for the IV 2024-08-10 18:32:37 +09:00
Yawning Angel ac7f44b1b8 core/crypto/aes: Slightly tweak GHASH to look less spooky 2024-08-10 18:32:37 +09:00
Yawning Angel b1d6e4139e core/crypto/aes: Disable bounds checking for the CTR loops 2024-08-10 18:32:37 +09:00
Yawning Angel dfc4df9807 core/crypto/_aes/hw_intel: Use a constant for the PSHUFB indicies 2024-08-10 18:32:37 +09:00
Yawning Angel b9293334ca core/crypto/ed25519: Rename a member for clarity
This better matches the spec.
2024-08-10 18:32:37 +09:00
Yawning Angel b68311d777 core/crypto/hash: Make the _to_buffer routines return the hash slice
Quality of life improvement.
2024-08-10 18:32:37 +09:00
Yawning Angel c0f9655ec4 test/core/crypto: Minor changes to AES related tests
- Test against the non-standard GCM nonce length vectors
- Fix the CTR mode test to match the comment

Correctness was fine without this change.
2024-08-10 18:32:37 +09:00
IllusionMan1212 7875e4a1ab vendor/egl: added a few more egl procedures and constants 2024-08-10 10:21:03 +02:00
Jeroen van Rijn be7a1f671c Revert "Add time.precise_clock_from_time + time.precise_clock_from_duration"
This reverts commit c9ca192f33.
2024-08-10 03:26:09 +02:00
Jeroen van Rijn c9ca192f33 Add time.precise_clock_from_time + time.precise_clock_from_duration 2024-08-10 03:23:08 +02:00
Feoramund e7e7fe766a Add test for misaligned data to core:simd/util suite 2024-08-09 18:54:04 -04:00
Feoramund 0d29cc3375 Use for x in y construct for bytes iteration
This cannot be applied to the `strings` version, as that would cause a
rune-by-rune iteration, not a byte-by-byte one.
2024-08-09 18:54:04 -04:00
Feoramund c8a62ee4ec Make simd_util index procs contextless where applicable 2024-08-09 18:54:04 -04:00
Feoramund 12dd0cb72a Simplify and make simd_util cross-platform
This new algorithm uses a Scalar->Vector->Scalar iteration loop which
requires no masking off of any incomplete data chunks.

Also, the width was reduced to 32 bytes instead of 64, as I found this
to be about as fast as the previous 64-byte x86 version.
2024-08-09 18:54:04 -04:00
Laytan Laats 912f99abc8 encoding/cbor: various fixes
- "null" is the proper way to represent the nil value in the diagnostic
  format
- hex encoding in diagnostic format was wrong
- struct keys weren't sorted the right deterministic way
2024-08-09 21:56:54 +02:00
jason baacc512e3 fix child pipe in process_start 2024-08-09 15:21:11 -04:00
Jeroen van Rijn c5ed7083d2 Disable NetBSD CI 2024-08-09 19:44:51 +02:00
Jeroen van Rijn d69e0bfa00 NetBSD vm fix. 2024-08-09 19:37:26 +02:00
Jeroen van Rijn fa6f343261 Remove unused import. 2024-08-09 19:06:50 +02:00
jason c4d43bbab0 os2 linux process_wait rework; add Sig_Child_Code to sys/linux bits 2024-08-09 09:16:44 -04:00
Jeroen van Rijn cc24d2de3e Merge pull request #3810 from Feoramund/freebsd-core-net
Port `core:net` to FreeBSD
2024-08-09 09:50:05 +02:00
Jeroen van Rijn bc6deab175 echo -> printf for build_odin.sh message 2024-08-09 09:46:45 +02:00
Laytan b5a612202f Merge pull request #4036 from laytan/master
add debug build message and align more with build.bat
2024-08-08 22:21:17 +02:00
Jeroen van Rijn 1e09ff3b2e Merge pull request #4043 from Kelimion/expect_leak_or_bad_free
Allow testing for intentional leaks in test runner
2024-08-08 21:40:17 +02:00
Jeroen van Rijn 933f9f9bd1 Enable test leak = fatal on CI. 2024-08-08 21:31:30 +02:00
Jeroen van Rijn b82cfc5f15 Fix shoco heisenleak 2024-08-08 21:15:59 +02:00
Jeroen van Rijn a05b73c632 Keep -vet happy when mem tracking is disabled. 2024-08-08 21:02:35 +02:00
Jeroen van Rijn 4d27898418 Use test runner's own tracking allocator. 2024-08-08 20:58:25 +02:00
Jeroen van Rijn 80d1e1ba82 Allow testing for intentional leaks in test runner
Adds `expect_leak_or_bad_free :: proc(t: ^T, client_test: proc(t: ^T), verifier: Memory_Verifier_Proc)`.

It sets up its own `Tracking_Allocator`, runs the `client_test`, and then calls the `verifier` procedure.
The verifier can then inspect the contents of the tracking allocator and call `testing.expect*` as sensible for the test in question.

Any allocations are then cleared so that the test runner doesn't itself complain about leaks.

Additionally, `ODIN_TEST_LOG_LEVEL_MEMORY` has been added as a define to set the severity of the test runner's memory tracker. You can use `-define:ODIN_TEST_LOG_LEVEL_MEMORY=error` to make tests fail rather than warn if leaks or bad frees have been found.
2024-08-08 20:41:32 +02:00
Roland Kovacs dda89a69bf Check if procedure parameter type declares polymorphic args
When a procedure parameter's type was declared in an imported package the type
checker correctly resolved to the parametric type, but it did not check if the
expression that refers to that type conforms to a polymorphic type declaration.

This error was not detected if the procedure was unused, since it was marked as
polymorphic, where further type check is done on instantiation.
2024-08-08 19:50:05 +02:00
Jeroen van Rijn f328929939 Merge pull request #4038 from Hyrtwol/core-sys-windows-rawinput-code
Core sys windows rawinput code
2024-08-08 18:23:02 +02:00
Thomas la Cour 3d0519fe6c trim whitespace 2024-08-08 18:05:41 +02:00
Thomas la Cour a4eeb6ed02 rawinput code 2024-08-08 18:03:59 +02:00
Jeroen van Rijn 94c62fb630 Fix typo. 2024-08-08 18:01:09 +02:00
Jeroen van Rijn a7fe9eec73 Merge pull request #4037 from Kelimion/symlink_test
Allow symlink test to work irrespective of git settings.
2024-08-08 17:56:05 +02:00
Jeroen van Rijn d93f3c63d8 Rename package to test_core_os to fit with the rest of test_* 2024-08-08 17:49:08 +02:00
Jeroen van Rijn ada3df303e Allow symlink test to work irrespective of git settings. 2024-08-08 17:46:00 +02:00
Laytan Laats 8b98fff98e add debug build message and align more with build.bat
1. if ran without choosing a build type (just `make` or
   `build_odin.sh`), print out a message about it being a debug build
2. Add `make release-native` alongside `make release_native` to align
   with `build_odin.sh release-native`
3. Only run the demo if it is a debug build (just like `build.bat`)
2024-08-08 15:33:40 +02:00
jason c3ba8fbd09 add child pipe for reporting post-fork errors 2024-08-08 08:56:29 -04:00
Jeroen van Rijn 4b9ca39522 Merge pull request #4035 from karl-zylinski/build-release-hint
Added a hint at end of build.bat about release mode when building in debug mode
2024-08-08 14:48:48 +02:00
Karl Zylinski 26633bbce6 Added a hint at end of build.bat about release mode when building in debug mode. 2024-08-08 14:15:32 +02:00
jason 9625798513 merge commit 2024-08-07 23:27:45 -04:00
Jeroen van Rijn 796feeead9 Remove LLVM copy from nightly. 2024-08-07 22:12:23 +02:00
Jeroen van Rijn 2bf055ec6e Delete empty file after access check. 2024-08-07 19:38:36 +02:00
Laytan Laats c9b69d76b0 text/edit: fix undo_state_push wrong builder check 2024-08-07 17:21:56 +02:00
Jeroen van Rijn 69a15ca5b6 Don't copy LLVM shared object on Linux
We copy the LLVM shared object when building Odin on Linux. Contrary the comment in `build_odin.sh`,
this is unnecessary, and Odin can be compiled and itself compile things just fine without this step.

This is then packaged up at release and leads to #4019 and #4033. The Linux release builds are built
on Ubuntu and not strictly supported on other Linux distributions. Building from source is preferred.
2024-08-07 14:50:45 +02:00
Laytan Laats 6fe938b946 darwin: add setAllowedFileTypes binding for open panels 2024-08-06 21:42:33 +02:00
Laytan Laats e5a478d393 wgpu: fix examples after changing color to an array 2024-08-06 21:42:33 +02:00
Feoramund 793811b219 Add simd_util to examples/all 2024-08-06 15:19:05 -04:00
Feoramund 0418d27bdf Add benchmarks for vectorized index_* procs 2024-08-06 15:19:05 -04:00
Feoramund 28c98c2e7a Add tests for vectorized index_* procs 2024-08-06 15:19:05 -04:00
Feoramund f66fcd9acb Use vectorized index_* procs in core 2024-08-06 15:19:05 -04:00
Feoramund 8deeb40e5d Add vectorized index_byte and last_index_byte 2024-08-06 15:19:01 -04:00
gingerBill 39d557bcb4 Merge pull request #4032 from Feoramund/fix-intrinsic-wording
Fix SIMD intrinsics wording
2024-08-06 20:13:10 +01:00
Feoramund e27a424f4d Swap reduce_any and reduce_all
`llvm.vector.reduce.or` will return true if any lane is true.
`llvm.vector.reduce.and` will return true if all lanes are true.
2024-08-06 14:50:34 -04:00
Feoramund 7a367c9c08 Fix documented names of a few SIMD procedures 2024-08-06 14:49:56 -04:00
Laytan 4423aac3de Merge pull request #4031 from RilleP/bit-field-closing-brace-fix
Fix missing closing brace for Bit_Field in core:odin/parser
2024-08-06 20:49:49 +02:00
gingerBill 94ded29b5f Merge pull request #4030 from Kelimion/struct_field_count
Add `reflect.struct_field_count` that returns the number of fields in a struct type
2024-08-06 18:56:24 +01:00
Rikard Petré 6a6f078186 Fix missing closing brace for Bit_Field in core:odin/parser 2024-08-06 19:48:38 +02:00
gingerBill bed18a17e6 Bodge: Improve aligned_resize logic 2024-08-06 11:22:34 +01:00
Jeroen van Rijn 17ebaffce8 Update comment. 2024-08-05 22:12:22 +02:00
Jeroen van Rijn 4902288a5a Add reflect.struct_field_count that returns the number of fields in a struct type
Example:
```odin
package struct_count_example

import "core:fmt"
import "core:reflect"
import "core:dynlib"

Foo :: struct{
	one: int,
	two: f32,
}

Bar :: struct {
	three: int,
	four:  bool,
	five:  f64,
}

Game_Api :: struct {
	init:      proc(api: ^Game_Api),
	update:    proc(api: ^Game_Api),

	using foo: Foo,
	bar:       Bar,

	// Private stuff
	reload_count: int,
	__handle:     rawptr,
}
API_PRIVATE_COUNT :: 2

game_api: Game_Api

main :: proc() {
	fmt.printfln("Game_Api, .Top:       %v", reflect.struct_field_count(Game_Api))              // 6
	fmt.printfln("Game_Api, .Using:     %v", reflect.struct_field_count(Game_Api, .Using))      // 8
	fmt.printfln("Game_Api, .Recursive: %v", reflect.struct_field_count(Game_Api, .Recursive))  // 11

	symbols_loaded, _  := dynlib.initialize_symbols(&game_api, "game.dll")
	symbols_expected   := reflect.struct_field_count(Game_Api) - API_PRIVATE_COUNT

	if symbols_loaded == -1 {
		fmt.eprintln("Couldn't load game.dll")
		return
	} else if symbols_loaded != symbols_expected {
		fmt.eprintfln("Expected %v symbols, got %v", symbols_expected, symbols_loaded)
		return
	}
}
```
2024-08-05 22:04:16 +02:00
Laytan a1c3c38f04 Merge pull request #4029 from Feoramund/fix-darwin-sigpipe-send
Prevent `SIGPIPE` on Darwin when writing to a closed `core:net` socket
2024-08-05 19:26:16 +02:00
Feoramund 4c0ab09c9a Handle EPIPE in Darwin core:net 2024-08-05 13:15:08 -04:00
Feoramund 6cc7f3b451 Add FreeBSD Accept_Error.Would_Block alias 2024-08-05 13:00:44 -04:00
Feoramund 3512d7c672 Move Darwin MSG_NOSIGNAL to core:os 2024-08-05 12:49:12 -04:00
Feoramund eba0774bf3 Prevent SIGPIPE on Darwin when writing to a closed core:net socket
Mimics behavior found on Linux implementation.
2024-08-05 12:23:09 -04:00
gingerBill 7c3461b0df Merge pull request #4028 from Kelimion/fix-4026
Fix crash if referencing import "aliased" in other file.
2024-08-05 16:57:58 +01:00
Jeroen van Rijn 2cc3795686 Merge pull request #4027 from karl-zylinski/blend-pixel-compile-fix
Fix for blend_pixel.odin in core/image/common.odin not compiling
2024-08-05 17:38:30 +02:00
Karl Zylinski b63657d293 Fix for blend_pixel.odin in core/image/common.odin not compiling 2024-08-05 17:23:58 +02:00
Jeroen van Rijn 6175efde3d Fix crash if referencing import "aliased" in other file.
Fixes #4026
2024-08-05 17:23:50 +02:00
Jeroen van Rijn 030220eb22 Merge pull request #4025 from karl-zylinski/patch-2
core/image/common.odin compile fix
2024-08-05 16:42:09 +02:00
Karl Zylinski 2d32b819dc common.odin compile fix
Fix for "Error: Prefer to separate 'where' clauses with a comma rather than '&&'"
2024-08-05 16:32:34 +02:00
gingerBill f56abf3780 Add intrinsics.masked_expand_load and intrinsics.masked_compress_store 2024-08-05 14:54:09 +01:00
gingerBill 78919f8524 Fix typos 2024-08-05 14:48:55 +01:00
gingerBill 80ea4e0aeb Remove dead code 2024-08-05 14:25:33 +01:00
gingerBill 84ac56f778 Add intrinsics.simd_masked_load and intrinsics.simd_masked_store 2024-08-05 14:08:41 +01:00
gingerBill 7e701d1677 Add intrinsics.simd_gather and `intrinsics.simd_scatter 2024-08-05 13:46:24 +01:00
gingerBill b67ed78afd add_sat -> saturating_add 2024-08-05 13:21:27 +01:00
gingerBill 90fc52c2ee Rename add_sat -> saturating_add 2024-08-05 13:19:01 +01:00
gingerBill 9a01a13914 Add simd_reduce_any and simd_reduce_all 2024-08-05 13:13:19 +01:00
gingerBill eeb92e2644 Allow cast between #simd[N]rawptr <-> #simd[N]uintptr 2024-08-05 13:06:55 +01:00
gingerBill fd06be2243 Allow swizzle to take more arguments than the original array length 2024-08-05 12:33:02 +01:00
gingerBill a06cb8ba46 Add #simd[N]rawptr support 2024-08-05 12:04:36 +01:00
Feoramund d0d4f19097 Remove debug line from test 2024-08-05 03:50:41 -04:00
Feoramund 8f5b838a07 Review manual for loops in core:text/regex 2024-08-05 03:49:29 -04:00
Feoramund ba0581ae79 Give FreeBSD access to core:net in core:flags 2024-08-05 03:05:50 -04:00
Feoramund d9404d928c Add copyright info to core:sys/freebsd 2024-08-05 03:05:50 -04:00
Feoramund fe754af13d Add new contribution notes to core:net 2024-08-05 03:05:49 -04:00
Feoramund 61e770d943 Clean up some FreeBSD core:net code 2024-08-05 03:05:43 -04:00
Feoramund 2b63684ccf Fix integer socket option values for FreeBSD 2024-08-05 02:14:41 -04:00
Feoramund 5ece6980eb Make EINVAL generic in FreeBSD Socket_Option_Error
The documentation for `setsockopt(2)` mentioned accept filters for
`EINVAL`, but I've found that it can arise for any manner of invalid
values for setting socket options.

We'll just have to leave this as a generic error.
2024-08-05 02:14:27 -04:00
Feoramund 42a2297d31 Add core:net tests specifically for FreeBSD 2024-08-05 02:08:48 -04:00
Feoramund 8de48d81ea Use common name for ENOBUFS 2024-08-05 00:30:39 -04:00
Feoramund 32fb1fb61c Add missing ECONNRESET TCP_Send_Error
This was not specifically documented in `send(2)`.
2024-08-05 00:30:39 -04:00
Feoramund 05c50561ae Set NOSIGPIPE on all core:net FreeBSD sockets 2024-08-05 00:30:39 -04:00
Feoramund 46455dd0a6 Add more socket options for FreeBSD core:net 2024-08-05 00:30:24 -04:00
Feoramund 3f9ddfe029 Clarify what umtx is 2024-08-04 22:24:55 -04:00
Feoramund 14858309f0 Add explicit license info to core:text/regex 2024-08-04 19:18:16 -04:00
Feoramund e17fc8272b Document rationale behind RegEx shorthand classes 2024-08-04 19:12:46 -04:00
Feoramund dde42f0ebc Add more documentation for core:text/regex API 2024-08-04 18:56:29 -04:00
Feoramund ca7e46d56f Add explicit test case for Capture pos 2024-08-04 18:56:29 -04:00
Feoramund 743480b1a4 Use regex.destroy for test captures 2024-08-04 18:56:29 -04:00
Feoramund 1ccb0b2558 Remove unused code 2024-08-04 18:56:29 -04:00
Feoramund babdc432e9 Move Flag_To_Letter to core:text/regex/common 2024-08-04 18:56:25 -04:00
Feoramund d3a51e208d Hide Regular_Expression values
We don't directly support printing these.

To prevent future issues being raised about the pattern being missing if
someone tries to print one, hide everything.
2024-08-04 18:40:27 -04:00
Feoramund cd8272557f Test that a RegEx Capture pos corresponds to its groups 2024-08-04 18:33:36 -04:00
gingerBill 7e0fa795e4 Just compare against nil directly if the comparator is known to be nil too 2024-08-04 21:17:58 +01:00
Feoramund 6252712363 Add missing features to regex package documentation 2024-08-04 13:21:13 -04:00
gingerBill 60bc7f53d2 Comment out open_buffered 2024-08-04 17:41:48 +01:00
gingerBill cf3c1a85ec Remove temp parameter 2024-08-04 17:36:28 +01:00
gingerBill 046f72befd Mock out open_buffered 2024-08-04 17:31:39 +01:00
gingerBill f19436fb4d Only swap if there was an arena 2024-08-04 17:17:09 +01:00
gingerBill d0709a7de2 Allow for nested temp_allocator() calls to flip between arenas on TEMP_ALLOCATOR_GUARDs 2024-08-04 17:14:24 +01:00
gingerBill f427f040fd Merge pull request #4020 from odin-lang/bill/os-errno
`os.Error` to replace `os.Errno`
2024-08-04 15:53:18 +01:00
gingerBill c078b2dd1b Add @(require_results) 2024-08-04 15:24:26 +01:00
gingerBill bf948ab8ae Add stubs for flush on platforms that didn't have it 2024-08-04 15:07:24 +01:00
gingerBill acb1ebddf6 Fix err != 0 uses 2024-08-04 15:01:04 +01:00
gingerBill 0bedd3357a Disallow err != 0 with os.Error when -strict-style is enabled 2024-08-04 14:58:12 +01:00
gingerBill 93fabf8628 Replace err != 0 with err != nil where possible 2024-08-04 14:57:25 +01:00
gingerBill fc10b781af Update core/os/os2/process.odin
Co-authored-by: Laytan <laytanlaats@hotmail.com>
2024-08-04 14:47:44 +01:00
gingerBill 6a6b5061db Update core/os/os_darwin.odin
Co-authored-by: Laytan <laytanlaats@hotmail.com>
2024-08-04 14:47:35 +01:00
gingerBill b67817517e Fix replace typo 2024-08-04 14:46:32 +01:00
gingerBill fff1d509d5 Add read_entire_file_or_err and write_entire_file_or_err 2024-08-04 14:41:55 +01:00
gingerBill e8d26c5797 Move errors to where appropriate 2024-08-04 13:41:34 +01:00
gingerBill 3d992e2704 Improve _error_string for Linux 2024-08-04 13:25:35 +01:00
gingerBill 0c5b645dde Correct EOF value 2024-08-04 13:20:33 +01:00
gingerBill cf5ec25873 Add extra cases for flush 2024-08-04 13:18:51 +01:00
gingerBill 7663a2036a Add read_at/write_at to missing platforms 2024-08-04 13:16:37 +01:00
gingerBill c32f345c68 Move error stuff to errors.odin 2024-08-04 12:55:08 +01:00
gingerBill 649b25fba6 Update the demo.odin to use nil instead of os.ERROR_NONE 2024-08-04 12:47:49 +01:00
gingerBill bdbbbf5c95 Fix typo; remove unneeded casts 2024-08-04 12:39:21 +01:00
gingerBill e8b6d15db9 Fix replace typo 2024-08-04 12:31:22 +01:00
gingerBill 5f7fef92fa Update example to use err != nil instead 2024-08-04 12:25:50 +01:00
gingerBill 66b86bc7e0 Correct os errors for darwin 2024-08-04 12:23:18 +01:00
gingerBill 5187bb68bb Hack: Convert 0 to nil 2024-08-04 12:08:52 +01:00
gingerBill 97c499dbb4 Begin mapping os.Error in the rest of the codebase 2024-08-04 11:58:04 +01:00
gingerBill 1d75a612d5 os.Errno -> os.Error 2024-08-04 11:47:23 +01:00
gingerBill 160048eaee Errno -> Error 2024-08-04 11:46:42 +01:00
gingerBill def2e2e271 Try to map to General_Error where possible 2024-08-04 11:44:45 +01:00
gingerBill 28666414bc More clean ups of ERROR_NONE and != nil usage 2024-08-04 11:37:49 +01:00
gingerBill a241168142 Clean up err != nil usage 2024-08-04 11:26:35 +01:00
gingerBill 29b6eebcd5 Clean up error handling 2024-08-04 11:21:09 +01:00
gingerBill 7dae38ce89 Begin mocking out for other errors 2024-08-04 11:12:45 +01:00
gingerBill 1826b0c700 Fix copy-replace errors 2024-08-04 11:10:17 +01:00
gingerBill 9f9abb8fb3 Use union #shared_nil for os.Error 2024-08-04 11:05:30 +01:00
gingerBill e60951a902 Begin converting os.Errno to be a nil-able type as a transition period 2024-08-04 10:51:08 +01:00
gingerBill 71932628cc Add alias 2024-08-04 10:08:48 +01:00
jason c691c7dc68 point stdin, stdout, stderr to /dev/null if unused in os2.process_start 2024-08-04 01:47:10 -04:00
jason 2a7db08c20 Remove returned bool from access and faccessat in sys/linux.
Switch to using AT_EMPTY_PATH to execve with file descriptors.
2024-08-04 00:59:40 -04:00
jason 2b89829b52 minor edits in process_linux.odin 2024-08-03 18:08:00 -04:00
Laytan Laats e77977c8ef fix vet errors in stb truetype 2024-08-03 23:56:19 +02:00
jason 38b96a7981 change child error behavior to trap instead of exit 2024-08-03 17:50:47 -04:00
Laytan Laats 4dd846fa29 fix readir_r link name for netbsd 2024-08-03 15:54:29 +02:00
Laytan Laats 61008232e4 actually fail CI when NetBSD tests fail 2024-08-03 15:43:35 +02:00
Jeroen van Rijn 90e573c54a Add image.premultiply_alpha helper. 2024-08-03 12:58:43 +02:00
Laytan ac483f72eb Merge pull request #4013 from laytan/fix-os-read-dir-with-symlinks
fix os.read_dir with symlinks
2024-08-03 01:08:23 +02:00
Laytan Laats 99d9e8f8b1 fix os.read_dir with symlinks 2024-08-03 00:26:46 +02:00
skytrias 9f5854e24e Update orca bindings and macros to requested changes 2024-08-02 23:46:02 +02:00
Laytan 772dce7e42 Merge pull request #3969 from elvodqa/master
Add `sdl2glue` to `vendor:wgpu` package
2024-08-02 17:18:34 +02:00
Emir e55d09bdfa Update vendor/wgpu/examples/sdl2/main.odin
Co-authored-by: Laytan <laytanlaats@hotmail.com>
2024-08-02 18:04:36 +03:00
Jeroen van Rijn 1a16585b10 Add image.pixels_to_image helper. 2024-08-02 14:54:52 +02:00
Laytan 500c117312 Merge pull request #4008 from Daxode/wasm-quality-of-life
Quality of Life changes to wgpu/js
2024-08-02 13:51:47 +02:00
daniel-andersen 723e6d19be right number whoops! 2024-08-02 13:38:36 +02:00
Jeroen van Rijn 8e8660fdfc Merge pull request #4007 from marcosantos98/fix-wasm
Fix: compilation error when using BufferSubDataSlice in webgl package
2024-08-02 12:31:23 +02:00
marcosantos98 3bfccde6f9 Fix: remove extra usage in webgl.odin:250
Compilation error when using webgl.BufferSubDataSlice.
The `usage` parameter is nowhere to be found.
This is probably a copy-pasta leftover.
2024-08-02 10:50:16 +01:00
daniel-andersen e7041f785a Quality of life changes to wgpu/wasm stuff 2024-08-02 11:04:10 +02:00
gingerBill 83599957b1 Merge pull request #3998 from zen3ger/os2-temp_file_linux
[os2] Add missing temp_file implementation for Linux
2024-08-01 20:07:21 +01:00
skytrias f8e0cda113 Add autogenerated orca bindings and macros from laytan 2024-08-01 19:19:24 +02:00
Jeroen van Rijn 0fa62937d5 Fix NetBSD CI 2024-07-31 20:19:13 +02:00
Jeroen van Rijn f627a38b4f Update rand.reset() example. 2024-07-31 20:00:55 +02:00
Jeroen van Rijn cc8c2f236b Merge pull request #4002 from thetarnav/update-builtin-constants
Update comments for builtin constants
2024-07-31 19:47:01 +02:00
Damian Tarnawski 953ae32607 Update builtin constants 2024-07-31 18:55:04 +02:00
Jeroen van Rijn fdfe6b00e0 Improve output path checking
Fixes #4001
2024-07-31 15:16:09 +02:00
Laytan 8a9901aeab Merge pull request #4000 from lxmcf/master
[vendor:raylib] Remove GuiStyleProp
2024-07-31 12:34:00 +02:00
Alex Macafee 1f2ab84e82 Use GuiControlProperty instead of c.int 2024-07-31 19:08:08 +10:00
Alex Macafee 92831d7ca3 Remove GuiStyleProp 2024-07-31 18:58:43 +10:00
Alex Macafee f33b4ecd3e Update Raygui Style set/get functions 2024-07-31 18:48:16 +10:00
gingerBill 62191f54a0 Merge pull request #3997 from Hyrtwol/reource-fix-windows
fix for using .rc files
2024-07-30 21:26:07 +01:00
gingerBill 04c3723985 Merge pull request #3992 from thetarnav/parser-patch
Correct the Array_Type.len comment and assign tok when making Ellipsis node
2024-07-30 21:25:21 +01:00
gingerBill ac19bb3a8c Merge pull request #3985 from flysand7/docs-sync
[sync]: Document all procedures
2024-07-30 21:24:59 +01:00
Roland Kovacs 1913c08b7b [os2] Add missing temp_file implementation for Linux 2024-07-30 18:11:44 +02:00
Thomas la Cour 744d7f7ef4 fix for using .rc files 2024-07-30 16:53:14 +02:00
jason c7eb2ae6bb use sys/linux dirent instead of manual iteration 2024-07-30 10:19:09 -04:00
jason 792640df1f remove File_Impl_Kind from file_linux 2024-07-30 09:41:49 -04:00
jason 278a63caaa remove pidfd availability caching 2024-07-30 09:28:40 -04:00
jason a03dffcd1a improve error handling; do not report errors from failed execve 2024-07-30 08:45:53 -04:00
flysand7 3aac4b1a3e [sync]: Document all procedures 2024-07-30 19:13:35 +11:00
Damian Tarnawski 478b2d7444 Correct the Array_Type.len comment and assign tok when making Ellipsis node 2024-07-29 22:14:42 +02:00
Laytan 7f17d4eb7f Merge pull request #3991 from laytan/fix-in-map-with-union-variants
fix `specific_union_variant in map_keyed_by_union` not converting to union type
2024-07-29 02:39:47 +02:00
Laytan Laats 4d1d754cae fix specific_union_variant in map_keyed_by_union not converting to union type 2024-07-29 02:32:13 +02:00
Jeroen van Rijn 24e6f16f4a Clamp dot in angle_between to avoid precision errors.
Fixes #3978
2024-07-28 15:00:29 +02:00
Laytan f852aac0e7 Merge pull request #3989 from colrdavidson/spall_doc
Improve Spall Docs slightly to reduce onboarding friction
2024-07-28 12:46:04 +02:00
Colin Davidson 27f75c40ab make example compile 2024-07-28 01:29:33 -07:00
Colin Davidson 1d598f8287 tweak doc a little to reduce onboarding friction for thread-users 2024-07-28 01:23:47 -07:00
Jeroen van Rijn cb31df34c1 Merge pull request #3362 from Hyrtwol/sys-windows-2
core/sys/windows part 2
2024-07-26 14:29:56 +02:00
Thomas la Cour 271ec643ed removed some comments 2024-07-26 11:30:48 +02:00
Thomas la Cour fe587ee79a try to add sys/windows to the normal core tests 2024-07-26 11:04:13 +02:00
Thomas la Cour b149b3d6c6 Merge remote-tracking branch 'upstream/master' into sys-windows-2 2024-07-26 10:45:09 +02:00
Thomas la Cour 03f3ea5a9e removed old test stuff 2024-07-26 10:43:26 +02:00
Thomas la Cour 6e6f2a1f6b removed obsolete fiels on WIN32_FIND_DATAW to match the size from the winsdk headers 2024-07-26 10:14:13 +02:00
Thomas la Cour 58ab6e5f94 missign cursorinfo 2024-07-26 10:07:20 +02:00
Jeroen van Rijn 4e194d5dbd Merge pull request #3980 from Kelimion/format-time
Add `time.to_string*` formatters.
2024-07-25 21:09:51 +02:00
Jeroen van Rijn 00c6b83537 Use constants in example. 2024-07-25 21:02:38 +02:00
Jeroen van Rijn ca7d86084e Improve docs. 2024-07-25 20:58:47 +02:00
Jeroen van Rijn 9088a493d9 Add time.to_string* formatters. 2024-07-25 19:43:42 +02:00
Thomas la Cour fe4754a77c format 2024-07-25 10:27:49 +02:00
Thomas la Cour 9d67d12d22 Merge remote-tracking branch 'upstream/master' into sys-windows-2
# Conflicts:
#	core/sys/windows/shell32.odin
2024-07-25 10:05:41 +02:00
gingerBill 9e82ae10ac Merge branch 'master' of https://github.com/odin-lang/Odin 2024-07-24 21:55:55 +01:00
gingerBill 85880f9def Add more NtDll stuff 2024-07-24 21:55:51 +01:00
Jeroen van Rijn 4ff62994bf Add CLSCTX_ALL 2024-07-24 22:54:17 +02:00
Feoramund 90f1f7fbdf Use unaligned_store in regex too 2024-07-24 16:48:49 -04:00
gingerBill 9b624ef9e1 Merge branch 'master' of https://github.com/odin-lang/Odin 2024-07-24 21:45:40 +01:00
gingerBill f03c2b7783 General clean up of os2.read_directory for Windows 2024-07-24 21:45:35 +01:00
Feoramund ff492e615c Use unaligned_load for regex virtual machine
This should hopefully avoid any issues with loading operands greater
than 8 bits on alignment-sensitive platforms.
2024-07-24 16:27:20 -04:00
Feoramund 042f6de478 Remove printing facilities for Regular_Expression
The `original_pattern` introduced a tenuous dependency to the expression
value as a whole, and after some consideration, I decided that it would
be better for the developer to manage their own pattern strings.

In the event you need to print the text representation of a pattern,
it's usually better that you manage the memory of it as well.
2024-07-24 16:27:20 -04:00
Feoramund c52a8a5f86 Allow configuring of MAX_CAPTURE_GROUPS for n > 10 2024-07-24 16:27:08 -04:00
Feoramund 16b644ad79 Use slice.zero instead 2024-07-24 15:23:20 -04:00
Feoramund e8537a3134 Add test cases for unclosed classes and repetition
Simplified error checking while I was at it, too.
2024-07-24 15:21:41 -04:00
Feoramund e642be8550 Fix handling of unclosed regex classes and repetitions 2024-07-24 15:17:37 -04:00
Jeroen van Rijn 33d6677514 Merge pull request #3951 from Kelimion/lua_test
Add Lua example to `vendor:lua` as well as basic tests.
2024-07-24 17:50:49 +02:00
Jeroen van Rijn 8d6ff51922 Copy lua54.dll during CI test 2024-07-24 17:43:51 +02:00
jason a5fa93e06d remove ctprintf; use fmt.caprintf; fix pipe_linux that I broke. 2024-07-24 10:23:23 -04:00
jasonKercher 215b21811e Merge branch 'master' into os2-process-linux 2024-07-24 10:14:59 -04:00
jason 95a8a4e7f0 typo - inverted logic 2024-07-24 10:12:16 -04:00
jason ecdd3887b2 fix process_info assumptions 2024-07-24 10:09:50 -04:00
gingerBill 2dbccbde54 Improve win32 types 2024-07-24 14:53:48 +01:00
gingerBill 07b1819dc8 Improve os2.read_directory 2024-07-24 14:53:33 +01:00
gingerBill 9d8953538b Add missing attribute 2024-07-24 14:25:42 +01:00
gingerBill d4af7b86a7 Begin cleaning up os2.read_directory 2024-07-24 14:19:30 +01:00
gingerBill 38e983cac6 Remove dead code 2024-07-24 13:47:57 +01:00
gingerBill 2ddaae45f3 Better handling of allocators 2024-07-24 13:47:22 +01:00
jason 16bdc6d240 use more iterators; global "has pidfd open" state is now thread-safe 2024-07-24 08:43:22 -04:00
gingerBill 6d2487a692 Add some more Ntdll calls 2024-07-24 13:38:14 +01:00
gingerBill c407e423d9 Add inode to os2.Stat 2024-07-24 13:37:56 +01:00
gingerBill 0e91c8368c Add allocator parameters to fmt.caprint* 2024-07-24 09:01:41 +01:00
gingerBill f08a53015c Merge pull request #3972 from laytan/testing-json-report
testing: add json reporting
2024-07-24 08:35:37 +01:00
Emir c98bb7da39 Update README.md 2024-07-24 10:33:34 +03:00
Emir ba81a81ca8 Update os_sdl2.odin 2024-07-24 10:29:34 +03:00
Emir 57dc6c2e94 Update os_sdl2.odin 2024-07-24 10:27:22 +03:00
Emir 95412df129 Add newline to glue_darwin.odin 2024-07-24 10:27:00 +03:00
Emir 2a2bedc85c Fix indentation and add full example 2024-07-24 10:22:18 +03:00
Laytan Laats f6488383d7 fix instrumentation features on LLVM versions with typed pointers
Fixes #3970
2024-07-24 02:43:53 +02:00
jason 0455e4b60f remove unused constants; fix comment 2024-07-23 19:48:18 -04:00
Laytan Laats 545fbc54c7 testing: add json reporting 2024-07-24 01:33:22 +02:00
jason 82deaa59ad os2 linux: fix order of operations bug in _open; fix process_info routine 2024-07-23 17:50:30 -04:00
jason 3c7d1f35db os2 process implementation for linux 2024-07-23 16:50:00 -04:00
Emir f9ef951b22 Add sdl2glue/glue_linux.odin 2024-07-23 22:39:50 +03:00
Laytan Laats fc2e31fcd0 fix build comment in os_freestanding 2024-07-23 20:51:00 +02:00
Emir e8e51db9ff Update glue.odin 2024-07-23 20:42:26 +03:00
Emir a429603195 Remove unused variable from example 2024-07-23 20:39:09 +03:00
Emir 42833d0471 Merge branch 'odin-lang:master' into master 2024-07-23 20:38:04 +03:00
Emir f3f08a4b47 Add sdl2glue to vendor:wgpu package + triangle example 2024-07-23 20:37:26 +03:00
gingerBill efa8c92bab Implement init_long_path_support 2024-07-23 17:46:22 +01:00
gingerBill 65fec9134e Use SHFileOperationW for remove_all on Windows 2024-07-23 17:30:42 +01:00
gingerBill a28392852a Mock out os2.remove_all for Windows 2024-07-23 17:05:41 +01:00
gingerBill 8037ace873 Begin work on os2/dir.odin 2024-07-23 16:47:49 +01:00
gingerBill 182454a1c0 Minor clean ups 2024-07-23 16:09:15 +01:00
gingerBill 24f9e2bbeb Begin mocking out the linux stuff on os2 2024-07-23 16:06:14 +01:00
gingerBill 61b9a5dbb2 Merge branch 'master' of https://github.com/odin-lang/Odin 2024-07-23 15:57:23 +01:00
gingerBill 0403626acf Add utility calls to os2 2024-07-23 15:57:17 +01:00
Laytan 6fc3d32d4b Merge pull request #3967 from thetarnav/remove-space
Remove space in indentation
2024-07-23 13:58:50 +02:00
Damian Tarnawski eb4f850b7f Remove space in indentation 2024-07-23 13:48:03 +02:00
Jeroen van Rijn da80c51195 Merge pull request #3966 from KyleNBurke/sys-windows-add-type
Add `NCCALCSIZE_PARAMS` to `sys/windows`
2024-07-23 07:45:44 +02:00
Kyle Burke 9d99f98194 Remove semicolon 2024-07-23 00:22:19 -05:00
Kyle Burke c32e12c3f5 Add NCCALCSIZE_PARAMS to sys/windows 2024-07-23 00:09:50 -05:00
Laytan c5fb72340a Merge pull request #3963 from andreas-jonsson/andreas-jonsson-patch-1
Use pkgsrc llvm for NetBSD CI
2024-07-23 04:20:54 +02:00
gingerBill b0fe777ede Propagate rodata a bit more in lb_const_value 2024-07-23 03:01:09 +01:00
gingerBill bc5b41938e Fix #3964 2024-07-23 02:40:51 +01:00
gingerBill 527c0b3202 Change lib for lz4 2024-07-23 00:19:42 +01:00
gingerBill 6eb28aeafc Check to see if people are return a slice of a local fixed array from a procedure 2024-07-22 22:52:10 +01:00
gingerBill 12b971746c vendor:compress/lz4
Bindings to lz4 library
2024-07-22 22:42:29 +01:00
gingerBill ef84382f23 Add suggestion for #3961 2024-07-22 20:11:23 +01:00
Feoramund b8f3d0fb53 Add core:text/regex to examples/all 2024-07-22 15:07:13 -04:00
Feoramund be38ba6c5e Add benchmarks for core:text/regex 2024-07-22 15:07:13 -04:00
Feoramund 3e49ceb82a Add tests for core:text/regex 2024-07-22 15:07:13 -04:00
Feoramund 730e10bd6f Support printing Regular_Expression in fmt 2024-07-22 14:25:12 -04:00
Feoramund cb0704d51c Add core:text/regex 2024-07-22 14:25:12 -04:00
Jeroen van Rijn 9cad8179b7 Clarify core:time Unix timestamp 2024-07-22 20:00:25 +02:00
Jeroen van Rijn ccf8b2764d Create README.md 2024-07-22 18:00:57 +02:00
gingerBill 915c5c3a87 Merge branch 'master' of https://github.com/odin-lang/Odin 2024-07-22 16:29:35 +01:00
gingerBill fcaa47986a Improve error handling for invalid syntax doing [*]T 2024-07-22 16:29:29 +01:00
Jeroen van Rijn 07d2aba310 Simplify exe path check. 2024-07-22 16:36:21 +02:00
Jeroen van Rijn 4889641af4 Merge pull request #3959 from Kelimion/fix-output-is-directory-check
Fix .exe path is directory check.
2024-07-22 16:22:17 +02:00
Jeroen van Rijn 90a4d12b30 Fix .exe path is directory check. 2024-07-22 16:11:33 +02:00
Jeroen van Rijn a39b6de18c Merge pull request #3958 from Kelimion/fix-3473
Fix #3473
2024-07-22 15:41:39 +02:00
Jeroen van Rijn 39657e4d96 Fix #3473
Fix the problem where the initial package's directory name ended in .odin.
2024-07-22 15:15:51 +02:00
Laytan 73a9a97413 Merge pull request #3476 from PucklaJ/syscall-fix
[sys/linux] Fix fork and execve syscalls on arm64
2024-07-22 13:58:17 +02:00
PucklaJ 1873f7215d [sys/linux]: Change execveat flags type to Execveat_Flags 2024-07-22 11:03:25 +02:00
Laytan Laats 4d86012d96 install lua for new lua vendor tests 2024-07-22 01:13:50 +02:00
Laytan Laats a055c03de9 use #directory in lua test 2024-07-22 01:11:01 +02:00
Laytan 68550cf915 Merge pull request #3957 from laytan/fix-any_base-and-any_core
fix `reflect.any_base` and `reflect.any_core` with any's containing nil
2024-07-22 01:09:38 +02:00
Laytan Laats 3e618bed40 fix reflect.any_base and reflect.any_core with any's containing nil 2024-07-22 00:51:38 +02:00
Jeroen van Rijn 51733fce68 Merge pull request #3952 from Ronaldr1985/master
Ensure that values in ini map are unquoted
2024-07-21 14:58:15 +02:00
Jeroen van Rijn a056e9da81 Merge pull request #3954 from flysand7/docs-thread
[thread]: Document all functions in core:thread
2024-07-21 14:10:49 +02:00
flysand7 b84b4c47d7 [thread]: Document all functions in core:thread 2024-07-21 14:34:36 +11:00
Jeroen van Rijn 431227d4c5 Add NULL check in check_range_stmt
Fixes #3953
2024-07-21 02:52:53 +02:00
Ronald 1a6885c2a3 Tidy up code 2024-07-21 00:08:20 +01:00
Ronald c3a57853e2 Ensure that values in ini map are unquoted 2024-07-21 00:00:47 +01:00
Jeroen van Rijn fc5ce30f34 Allow json to unmarshal empty struct. 2024-07-21 00:37:11 +02:00
Jeroen van Rijn 572b400d8e Merge pull request #3950 from Ronaldr1985/master
Add tests for encoding/ini
2024-07-20 18:47:08 +02:00
Jeroen van Rijn f78a792d48 Add Lua example to vendor\lua as well as basic tests. 2024-07-20 18:30:41 +02:00
Ronald e0a8bd04d5 Ensure deletion of maybe is delayed until we're finished with it. 2024-07-20 17:10:34 +01:00
Ronald f560b14d10 Fix typo in name of test 2024-07-20 17:10:19 +01:00
Ronald b584eeaade Add encoding/ini tests 2024-07-20 16:53:54 +01:00
Jeroen van Rijn cdd2c98b8d Merge pull request #3948 from flysand7/docs-time
[time]: Document all functions
2024-07-20 16:06:07 +02:00
Jeroen van Rijn 9d6ed991cb Remove LUA panic for non-big-3 OS 2024-07-20 14:33:34 +02:00
Jeroen van Rijn 2385e1ddd9 Update LUA imports for Darwin. 2024-07-20 14:24:01 +02:00
flysand7 b3ca2d5e0a [time]: Document all functions 2024-07-20 18:48:50 +11:00
Jeroen van Rijn 64614889de Merge pull request #3946 from flysand7/x11-fixes
[vendor/x11]: Fix missing argument in XDefaultDepth, wrong types in CreateSimpleWindow
2024-07-20 04:00:00 +02:00
Jeroen van Rijn d9d044970e Merge pull request #3945 from flysand7/docs-datetime
[time/datetime]: Document package datetime
2024-07-20 03:56:21 +02:00
flysand7 0c78cab336 [time/datetime]: Document package datetime 2024-07-20 12:49:40 +11:00
flysand7 15997d2a90 [vendor/x11]: Fix missing argument in XDefaultDepth, wrong types in CreateSimpleWindow 2024-07-20 12:47:00 +11:00
Jeroen van Rijn 7237f9c9f8 Help text default -o:none -> -o:minimal. 2024-07-19 20:47:26 +02:00
gingerBill ba3d7ba5d3 Add core:encoding/ini to examples/all 2024-07-19 12:03:34 +01:00
gingerBill f226eba342 Merge branch 'master' of https://github.com/odin-lang/Odin 2024-07-19 12:00:54 +01:00
gingerBill 393ca40c23 Minor clean ups 2024-07-19 12:00:49 +01:00
gingerBill 62f455f47b Merge branch 'master' into syscall-fix 2024-07-19 11:43:56 +01:00
gingerBill 163287d9ce Merge pull request #3938 from Ronaldr1985/master
Fix memory leak in encoding/ini
2024-07-19 11:42:35 +01:00
gingerBill 2f8399fe20 Merge pull request #3940 from flysand7/os2-handle-inheritance
[os2] Make all handles non-inheritable by default
2024-07-19 11:38:03 +01:00
gingerBill 685dbddcb5 Merge pull request #3939 from flysand7/os2-file-type
[os2]: Split file type from mode bits et other small fixes
2024-07-19 11:37:54 +01:00
Laytan Laats 27f9f0ba17 fix OLS #431, #393 2024-07-18 21:06:37 +02:00
Laytan Laats 2b6a926bb6 fix OLS #52 2024-07-18 21:06:37 +02:00
Laytan b3d798cb76 Merge pull request #3941 from laytan/wgpu-wayland-improvements
improve WGPU / GLFW / Wayland story by weak linking and adjusting docs
2024-07-18 20:20:01 +02:00
Laytan 7134015f56 improve WGPU / GLFW / Wayland story by weak linking and adjusting docs 2024-07-18 19:28:15 +02:00
flysand7 7b501b22bb [os2]: Split file type from mode bits 2024-07-18 23:09:27 +11:00
flysand7 75605a47e7 [os2]: Make anonymous pipes always inheritable 2024-07-18 22:57:30 +11:00
flysand7 4dcb75af6d Make all handles non-inheritable by default
The sockets are left as non-inheritable because they
never should be inherited.
2024-07-18 22:50:47 +11:00
Ronald c768d0719a Remove unnecessary change
This was accidentally added, it was a change I made whilst testing.
2024-07-17 21:57:35 +01:00
Ronald f04db7145c Fix memory leak in encoding/ini
A simple change that fixes a memory leak caused by not deleting all the
values in the map
2024-07-17 21:19:14 +01:00
gingerBill 0bb4cc6ce5 Merge pull request #3935 from IllusionMan1212/win32-drag-n-drop
core/sys/windows: added drag and drop procedures
2024-07-16 23:41:52 +01:00
IllusionMan1212 07121f81ff core/sys/windows: added drag and drop procedures 2024-07-17 00:32:25 +02:00
Jeroen van Rijn 5520b45457 Add glfw LICENSE file 2024-07-16 22:59:32 +02:00
Laytan cb16d2ddaf Merge pull request #3934 from laytan/fix-saturating-intrinsics
fix `add_sat` and `sub_sat` intrinsics
2024-07-16 22:30:06 +02:00
Laytan Laats a6d1a2e46c add #optional_ok to docs file for intrinsics 2024-07-16 22:22:06 +02:00
Laytan Laats 47f14dd9ea type is never a tuple here 2024-07-16 22:11:54 +02:00
Laytan Laats 853487e86c fix add_sat and sub_sat intrinsics 2024-07-16 22:07:49 +02:00
gingerBill 0d881e1561 Improve rand.shuffle further by splitting into 64-bit and 32-bit parts 2024-07-16 18:36:31 +01:00
gingerBill ba49950454 Improve rand.shuffle 2024-07-16 18:33:01 +01:00
gingerBill f66133959f Merge pull request #3933 from laytan/fix-some-bugs-with-disable-assert
fix some bugs with -disable-assert
2024-07-16 17:54:21 +01:00
Laytan Laats 28fac62a02 fix some bugs with -disable-assert 2024-07-16 18:44:18 +02:00
gingerBill a3fe5754d9 Make complex32 use higher precision where possible for calculations 2024-07-16 15:31:00 +01:00
gingerBill df56655ab1 Fix formatting inconsistencies 2024-07-16 14:03:02 +01:00
gingerBill 6702f07762 rawptr -> cstring 2024-07-16 14:02:07 +01:00
gingerBill 03e90bf924 Use RTTI to get the error_string for Windows 2024-07-16 12:26:24 +01:00
gingerBill 8d70a264ab Check for specific error directly 2024-07-16 12:21:55 +01:00
gingerBill fe718460c6 Clean up bit_set usage 2024-07-16 12:17:48 +01:00
gingerBill 1afb10109e Remove the need for temporary variables where possible 2024-07-16 12:13:39 +01:00
gingerBill 3a162de18f More clean up for process_windows.odin 2024-07-16 12:08:59 +01:00
gingerBill 321ef82d76 Add @(require_results) where needed 2024-07-16 11:57:22 +01:00
gingerBill 169fc4d3be General clean up of the os2/process_windows.odin code 2024-07-16 11:56:31 +01:00
gingerBill affe8f7144 Merge pull request #3310 from flysand7/core-process
Addition of `core:os2/process` api.
2024-07-16 11:24:24 +01:00
gingerBill 23ca27f40b Add intrinsics add_sat and sub_sat 2024-07-16 00:48:17 +01:00
Laytan Laats 03426175ae add workaround for kernel panics on MacOS 2024-07-15 22:45:16 +02:00
Jeroen van Rijn 0a9c150748 Merge pull request #3929 from laytan/fix-fmt-len-transfer-to-children
fmt: fix optional_len or use_nul_termination being used by both array and elems
2024-07-15 19:36:20 +02:00
Laytan Laats f362e0fa20 add test for leaking struct tag into elems 2024-07-15 19:27:48 +02:00
Laytan Laats d4d910bcfc fmt: fix optional_len or use_nul_termination being used by both array and elems
```odin
My_Struct :: struct {
	names:      [^]string `fmt:"v,name_count"`,
	name_count: int,
}

main :: proc() {
	name := "hello?"
	foo := My_Struct {
		names = &name,
		name_count = 1,
	}
	fmt.println(foo)
}
```

Before: `My_Struct{names = ["h"], name_count = 1}`
After:  `My_Struct{names = ["hello?"], name_count = 1}`
2024-07-15 18:51:18 +02:00
Jeroen van Rijn 3a75a8dd1b Merge pull request #3928 from Yawning/feature/aes-ni
core/crypto: Support AES-NI + PCLMUL
2024-07-15 18:41:21 +02:00
Yawning Angel 33dae2e26c core/crypto/aes: Support the full range of GCM nonce sizes 2024-07-16 01:29:43 +09:00
Yawning Angel 69026852ce core/crypto/aes: Add Intel AES-NI support
This supports AES-NI + PCLMUL, and provides optimized key schedule, ECB,
CTR, and GCM.  Other modes are trivial to add later if required.
2024-07-16 01:29:43 +09:00
Yawning Angel f578994fa6 core/simd/x86: Make the AES-NI intrinsics consistent with Intel 2024-07-16 01:29:43 +09:00
Yawning Angel 1bc21c3481 core/crypto/_aes: Remove redundant sanity checks 2024-07-16 01:29:43 +09:00
Yawning Angel c9c0b9ea7b core/crypto: Fix/add some documentation (NFC) 2024-07-16 01:29:43 +09:00
Yawning Angel 390cd3c30d core/simd/x86: Fix some intrinsics
- _mm_slli_si128 produced totally incorrect output
- _mm_storeu_si128 refered to a LLVM intrinsic that is missing
2024-07-16 01:29:43 +09:00
Yawning Angel 401877184f tests/benchmark/crypto: Benchmark AES256-CTR 2024-07-16 01:29:43 +09:00
Yawning Angel 4815154c31 test/core/crypto: Fix a copy-paste issue in failure spew 2024-07-16 01:29:43 +09:00
Yawning Angel 0d8dadec8a tests/core/crypto: Fix new -vet issues 2024-07-16 01:29:43 +09:00
Yawning Angel ff13ee3281 core/crypto: Enforce aliasing restrictions 2024-07-16 01:29:43 +09:00
Yawning Angel dcaf085bfa core/bytes: Add alias and alias_inexactly 2024-07-16 01:29:43 +09:00
Laytan Laats 55e0f97cc4 help fmt with Type_Info_Struct and Type_Info_Bit_Field changes 2024-07-15 18:29:06 +02:00
gingerBill 65c91b7dde Fix code gen issue with bit_set 2024-07-15 15:16:23 +01:00
gingerBill bd562116b8 Minor change to an internal flag 2024-07-15 15:08:26 +01:00
gingerBill 1e37eaf54d Begin work for bit_set[...; [N]T] (not working) 2024-07-15 14:49:20 +01:00
flysand7 8df61b7209 [os2/process]: Make get_args() private and use heap_allocator 2024-07-15 23:28:03 +11:00
Yawning Angel 1a30d47ee8 repo: Cleanup the .gitignore to match the new test runner 2024-07-15 21:25:07 +09:00
gingerBill 5cefab8229 Fix case: in type switch issue 2024-07-15 13:22:50 +01:00
gingerBill 7d643bcae3 Make linkage weak in certain places 2024-07-15 12:30:32 +01:00
gingerBill 549311fac9 Fix global variables being "missing" with -use-separate-modules 2024-07-15 12:21:42 +01:00
gingerBill c5decd3eae Fix possible race and correct linkage _after_ generation 2024-07-15 11:49:07 +01:00
flysand7 255f00d971 [os2/process]: Implement missing functionality, update docs 2024-07-15 20:24:05 +11:00
gingerBill 664a71454b -use-separate-modules default on Windows only 2024-07-15 02:53:01 +01:00
gingerBill 432388ac7f Generate backing array in the case where there is no DeclInfo for the procedure body 2024-07-15 02:42:28 +01:00
gingerBill cc3cf12ae2 Disable -use-separate-modules by default on darwin until problem is determined 2024-07-15 02:28:27 +01:00
gingerBill d87583bead Minimize mutex lock for #load_directory 2024-07-15 02:22:23 +01:00
gingerBill 1b0e98116d Revert changes to in_single_threaded_checker_stage 2024-07-15 01:47:52 +01:00
gingerBill eb6805ef40 Disable the need for mutexes in single threaded checker stage 2024-07-15 01:44:23 +01:00
gingerBill a45e05bb18 Remove need for BlockingMutex in Arena 2024-07-15 01:36:54 +01:00
gingerBill e4ba786948 Remove use of mutex in single threaded code 2024-07-15 01:29:57 +01:00
gingerBill cae8c1e94f Minimize use of mutex in Arena 2024-07-15 01:15:00 +01:00
gingerBill a8f84c87ae Add the permanent and temporary arenas directly on the Thread 2024-07-15 01:05:29 +01:00
gingerBill c64702ae5a Make -use-separate-modules the default behaviour for -o:none and -o:minimal 2024-07-15 00:43:46 +01:00
gingerBill 3311ea1c76 Keep MSVC happy with secure versions of C calls 2024-07-15 00:38:10 +01:00
gingerBill 018026d844 Use gb_zero_* calls 2024-07-15 00:36:00 +01:00
gingerBill 139c1bcdda Comment out debug code 2024-07-15 00:25:41 +01:00
gingerBill 46817e8f68 Merge branch 'master' of https://github.com/odin-lang/Odin 2024-07-15 00:01:31 +01:00
gingerBill 196ac7e6d6 Type erase _make_dynamic_array_len_cap 2024-07-15 00:01:26 +01:00
Jeroen van Rijn e3e31b42d0 #force_no_inline build_huffman to avoid bloat 2024-07-15 00:54:08 +02:00
gingerBill f7cb711874 Add #force_no_inline 2024-07-14 23:48:33 +01:00
gingerBill f657055f12 Add slice variable if not exists 2024-07-14 23:36:54 +01:00
gingerBill 26a9416a41 Minor clean ups 2024-07-14 23:33:35 +01:00
gingerBill e768bddaeb Inline _append_elem_string further 2024-07-14 23:22:22 +01:00
gingerBill 83b7dd122a Type erase for append_elems 2024-07-14 23:20:50 +01:00
gingerBill b0fbaf24a0 Type erase append_elem 2024-07-14 23:16:11 +01:00
gingerBill 1c3240b6b5 Add #force_no_inline 2024-07-14 23:09:58 +01:00
gingerBill 7673d478b6 Merge branch 'master' of https://github.com/odin-lang/Odin 2024-07-14 23:09:17 +01:00
gingerBill 15fb4ded2a type erase resize and reserve internals 2024-07-14 23:09:10 +01:00
Jeroen van Rijn 03cb585845 Merge pull request #3908 from NicknEma/Intrusive-list-docs
Write docs for `core:container/intrusive/list` package
2024-07-14 23:28:53 +02:00
gingerBill 9d84e00502 Clean up unquote code 2024-07-14 22:25:26 +01:00
gingerBill 7703b37a1b Merge branch 'master' of https://github.com/odin-lang/Odin 2024-07-14 22:23:52 +01:00
gingerBill 95a695e4cd Fix #3926 2024-07-14 22:23:46 +01:00
gingerBill 02408b713a Merge pull request #3910 from VladPavliuk/json-add-int-key-map-support
Allow to `marshal` and `unmarshal` maps with int keys
2024-07-14 22:00:01 +01:00
gingerBill 251fa477af Fix type 2024-07-14 21:39:33 +01:00
gingerBill 15a0655988 Merge branch 'master' of https://github.com/odin-lang/Odin 2024-07-14 21:37:41 +01:00
gingerBill 399c3ab067 Reduce the size of runtime.Type_Info 2024-07-14 21:37:35 +01:00
flysand7 b7ccfed9af [os2/process]: Implement process_kill 2024-07-15 07:27:44 +11:00
flysand7 4eca60946c [os2/process]: Refactor process_info procs, add process_info_by_handle 2024-07-15 07:27:44 +11:00
flysand7 8f4755532e [os2/process]: Adjust docs on process_close function 2024-07-15 07:27:44 +11:00
flysand7 63d94301fc [os2/process]: Implement process creation procedures 2024-07-15 07:27:43 +11:00
flysand7 e1eed7610c [os2/process]: Fix leaking memory on errors 2024-07-15 07:27:43 +11:00
flysand7 5d6e0bc793 [os2/process]: Implement retrieving command args in process info 2024-07-15 07:27:43 +11:00
flysand7 c1f5d8f006 [os2/process]: Improve documentation for *process_info() family of function 2024-07-15 07:27:43 +11:00
flysand7 f3d4a734d8 [os2/process]: Fix environment block null-terminator counting 2024-07-15 07:27:43 +11:00
flysand7 6387cd2c24 [os2/process] Added process_info() procedure 2024-07-15 07:27:43 +11:00
flysand7 56d55e4a86 Rebase master 2024-07-15 07:27:43 +11:00
flysand7 6fab055f43 [os2/process]: Add process list function 2024-07-15 07:27:43 +11:00
flysand7 2495f1c39a [os2/process]: Fill in basic functions 2024-07-15 07:27:43 +11:00
Jeroen van Rijn 65dab3a3b1 Merge pull request #3925 from Feoramund/fix-no-return-switch
Fix compiler crash when switching on no value
2024-07-14 21:26:46 +02:00
Feoramund b38237e8f0 Fix compiler crash when switching on no value 2024-07-14 14:59:00 -04:00
NicknEma 63276a85ba Fixed grammar and expanded info
Fixed points made by Jeroen.
2024-07-14 18:18:12 +02:00
VladPavliuk 3f8712edb0 Merge branch 'master' into json-add-int-key-map-support 2024-07-14 18:22:20 +03:00
gingerBill e7d37607ef Fix parameter to none 2024-07-14 16:05:47 +01:00
gingerBill 6feace2351 Add pseudo flag -fast-build 2024-07-14 16:05:07 +01:00
gingerBill a867378418 Default to -o:minimal again 2024-07-14 15:55:26 +01:00
gingerBill 11e2aa2d51 Improve error message 2024-07-14 15:31:40 +01:00
gingerBill 556355ef05 Disallow global use of target specific procedure calls 2024-07-14 15:30:40 +01:00
gingerBill 5de6016e7f Clean up os2.File.impl usage 2024-07-14 15:26:59 +01:00
gingerBill 2d56e3805b Merge branch 'master' of https://github.com/odin-lang/Odin 2024-07-14 15:09:38 +01:00
gingerBill 4f73b35da5 Make os2.File a more generic interface 2024-07-14 15:09:33 +01:00
Jeroen van Rijn 76b0562acd Merge pull request #3923 from laytan/fix-off-by-one-in-queue-back
Fix off-by-one in queue `back` and `back_ptr` procs
2024-07-14 16:09:16 +02:00
Laytan Laats d90d7ed002 Fix off-by-one in queue back and back_ptr procs 2024-07-14 16:00:55 +02:00
gingerBill 3d38f14202 Use fstat on os2.File directly 2024-07-14 14:51:22 +01:00
gingerBill d1450e3d88 Fix styling issues 2024-07-14 14:44:22 +01:00
gingerBill eff46c2e5f Merge pull request #3919 from colrdavidson/growing_workpool
move to a growing workstealing queue
2024-07-14 14:39:49 +01:00
gingerBill 8319917898 Merge branch 'master' of https://github.com/odin-lang/Odin 2024-07-14 14:07:42 +01:00
gingerBill 2e0c5fefde Reuse the slice value too for variadic parameters (LLVM >= 13) 2024-07-14 14:07:36 +01:00
Jeroen van Rijn 88823c4024 Merge pull request #3921 from Ronaldr1985/master
Fix logic bug in core/encoding/ini/ini.odin
2024-07-14 14:48:47 +02:00
gingerBill 6959554040 Calculate size and alignment, and reuse memory for all variadic calls within a procedure body 2024-07-14 13:44:47 +01:00
gingerBill 0a530b5ce8 Add error for #no_capture being reserved for future use 2024-07-14 13:20:12 +01:00
gingerBill 8650180ccc Change Odin calling convention to not do a copy on byval for SysV 2024-07-14 12:59:55 +01:00
gingerBill 5027c7081e Reuse slice variable for variadic parameters 2024-07-14 12:50:33 +01:00
gingerBill 3533094cc2 Restrict #no_capture to pointer-like types only 2024-07-14 12:44:13 +01:00
gingerBill 5ce6676914 Make #no_capture map to nocapture 2024-07-14 12:41:16 +01:00
gingerBill 3dff83f3dc Mock out #no_capture for future use 2024-07-14 12:39:30 +01:00
gingerBill 8642d719f0 Imply #no_capture to all variadic parameters 2024-07-14 12:19:47 +01:00
gingerBill 891cf54b5c Add f16 to #c_vararg promotion rules 2024-07-14 12:03:34 +01:00
gingerBill 3ba19d94cf Add #no_capture to core:odin/ast 2024-07-14 11:58:26 +01:00
gingerBill c7bd954752 Add more uses of #no_capture 2024-07-14 11:56:04 +01:00
Ronald 7e4e3429d7 Fix logic bug in core/encoding/ini/ini.odin
The load_map_from_path had incorrect logic where it would return false
for ok when err was equal to nil and true when there was an error.
2024-07-14 11:48:34 +01:00
gingerBill edc793d7c1 Add #no_capture args: ..T to reuse the backing array stack memory 2024-07-14 11:39:05 +01:00
gingerBill f98a7b84df Merge pull request #3914 from VladPavliuk/json-add-ignore-tag-support
Add support of `ignore` tag for `json.marshal`
2024-07-14 10:38:15 +01:00
gingerBill 0050cb9471 Merge pull request #3918 from flysand7/file-handle-inheritance2
[os2/file]: Fixes related to handle inheritance
2024-07-14 10:36:10 +01:00
Colin Davidson 64feb7599e move to isize 2024-07-14 00:33:40 -07:00
Colin Davidson 4420128dc1 handle steal-fail vs steal-empty 2024-07-14 00:29:58 -07:00
Colin Davidson cdede4928c move to a growing queue 2024-07-13 23:16:22 -07:00
flysand7 b686b072d5 [os2/file]: Fixes related to handle inheritance
All file handles created on Windows used to be made
non-inheritable, by forcing the .Close_On_Exec flag
in _open() function. In addition, there was an
issue with security descriptor being freed before
use, which has been fixed.
2024-07-14 15:06:28 +11:00
VladPavliuk 76fe5d1346 Align ignore syntax of json tags with fmt, cbor 2024-07-14 00:21:05 +03:00
gingerBill 8cebc7cc0c Merge pull request #3915 from tadeohepperle/vendor-wgpu-RenderPassEncoderSetPushConstants-signature
vendor/wgpu: RenderPassEncoderSetPushConstants should take a rawptr instead of cstring
2024-07-13 15:16:21 +01:00
Tadeo hepperle 75076e2d64 RenderPassEncoderSetPushConstants should take a rawptr instead of cstring for the data 2024-07-13 16:01:33 +02:00
VladPavliuk 64ae99f016 Add support of ignore tag for json.marshal 2024-07-13 14:13:59 +03:00
Jeroen van Rijn d845a07519 Merge pull request #3912 from xzores/master
Update stb_truetype.odin
2024-07-13 00:16:34 +02:00
xzores b4683f4399 Update stb_truetype.odin 2024-07-12 23:57:45 +02:00
VladPavliuk 79e2f63182 Small code refactoring in test_core_json 2024-07-13 00:38:58 +03:00
VladPavliuk 39983eaaa4 Remove unused imports in test_core_json 2024-07-13 00:26:54 +03:00
VladPavliuk dbdad0476d Allow to marshal and unmarshal maps with int keys 2024-07-13 00:07:48 +03:00
Thomas la Cour 3627a51daf Merge remote-tracking branch 'upstream/master' into sys-windows-2 2024-07-12 16:06:48 +02:00
gingerBill e715674512 Merge pull request #3907 from flysand7/console-read-fix
[core/os]: Fix read_console edge case bug
2024-07-12 14:58:40 +01:00
gingerBill 9e0c4098be Merge pull request #3905 from flysand7/winapi-process-procs
[sys/windows]: Advapi bindings, process-related functions and thread context
2024-07-12 14:58:27 +01:00
NicknEma d10694901f Simplify and fix doc examples
Remove unnecessary examples;
fix compilation errors in the remaining ones
2024-07-12 15:48:47 +02:00
NicknEma c75a872909 Write doc comments in intrusive_list.odin
Write description, inputs/returns and some examples for each procedure
2024-07-12 15:37:34 +02:00
NicknEma a348a7e84e Create doc.odin
Create a doc file with a brief of the package and an example program (copied from a discord message by laytan)
2024-07-12 15:18:58 +02:00
flysand7 a7d95ab3e1 [core/os]: Fix read_console not stopping the read when newline can't fit in output slice 2024-07-12 20:28:38 +11:00
flysand7 6ae47c6f43 [sys/windows] Add advapi bindings, process-related functions and context-related stuff 2024-07-12 19:21:44 +11:00
Thomas la Cour 3291c59728 post rebase 2024-07-11 21:37:37 +02:00
Thomas la Cour dd75b7a4d9 Merge remote-tracking branch 'upstream/master' into sys-windows-2
# Conflicts:
#	core/sys/windows/kernel32.odin
#	core/sys/windows/types.odin
#	core/sys/windows/user32.odin
#	core/sys/windows/winerror.odin
2024-07-11 21:20:53 +02:00
gingerBill 1770e3a9a9 Fix typo 2024-07-11 17:19:12 +01:00
gingerBill 19753ed8a3 Add rand.Generator and other calls 2024-07-11 17:12:42 +01:00
gingerBill 59d87d1f05 Add gen := context.random_generator parameters to rand calls 2024-07-11 17:01:34 +01:00
gingerBill 6b3453cc64 Fix #3902 2024-07-11 13:08:38 +01:00
gingerBill 5e7634d90c Merge branch 'master' of https://github.com/odin-lang/Odin 2024-07-11 13:04:32 +01:00
gingerBill fc7c7cd8ab Merge pull request #3900 from Kelimion/winres
Allow precompiled resources with `-resource:foo.res`
2024-07-11 12:51:25 +01:00
gingerBill e05e99253b Merge pull request #3904 from laytan/make-instrumentation-work-on-wasm
make instrumentation "work" on wasm
2024-07-11 12:50:51 +01:00
Jeroen van Rijn a8ce5bd005 Merge pull request #3903 from laytan/allow-mem-virtual-import-on-more-targets
allow `core:mem/virtual` import on more targets by expanding the `other` implementation
2024-07-11 02:12:53 +02:00
Laytan Laats 65ca03a930 make instrumentation "work" on wasm
Using instrumentation on WASM causes it to complain about the
llvm.returnaddress instrinsic. This PR could be considered a "hack" but
makes this work by just passing `nil` instead of the return address.
2024-07-11 01:57:00 +02:00
Laytan Laats 0dfc660c71 allow core:mem/virtual import on more targets by expanding the other implementation 2024-07-11 01:55:59 +02:00
Jeroen van Rijn c49afb0039 Add hinstdll forward to runtime globals 2024-07-10 19:58:29 +02:00
Jeroen van Rijn b02291b20a Compile demo with -vet -strict-style. 2024-07-10 19:26:35 +02:00
gingerBill f75a45c3fa Add aliases starts_with and ends_with 2024-07-10 16:34:15 +01:00
gingerBill 7e41340510 Unify IUnknown COM interface 2024-07-10 15:20:07 +01:00
Jeroen van Rijn 4148c6d6c7 #if WINDOWS 2024-07-10 15:25:49 +02:00
Jeroen van Rijn cc73e06a46 Allow precompiled resources with -resource:foo.res
And add them to the magic new feature.
2024-07-10 15:09:13 +02:00
gingerBill 733b7c704c Merge branch 'master' of https://github.com/odin-lang/Odin 2024-07-10 13:45:27 +01:00
gingerBill c54e3d3c4f Improve warning handling for possible default: typo 2024-07-10 13:45:21 +01:00
Jeroen van Rijn 8dc4eca4d2 Allow using precompiled .res file. 2024-07-10 14:25:18 +02:00
gingerBill 34c6868e78 Merge pull request #3895 from laytan/fix-optimization-mode-attribute
remove misleading @(optimization_mode) values and make "none" inhibit optimizations
2024-07-10 13:22:57 +01:00
gingerBill 38315f83da Merge pull request #3898 from laytan/fix-enable-target-features-for-poly-procs
fix require/enable target feature attribute on poly procs
2024-07-10 13:22:06 +01:00
gingerBill 5aa1f3751b Merge pull request #3899 from laytan/fix-more-attributes-not-applied-to-poly-procs
fix optimization mode, cold, and disabled not being applied to poly procs
2024-07-10 13:21:57 +01:00
gingerBill 36301d0359 Give better syntax error messages for things like #define Example 123 2024-07-10 13:03:38 +01:00
gingerBill c83307f26f Give error message suggestion when doing ^x instead of x^ if x is an r-value 2024-07-10 12:39:42 +01:00
gingerBill 30204837ce Merge branch 'master' of https://github.com/odin-lang/Odin 2024-07-10 12:28:23 +01:00
gingerBill f85f6b338a Change .. variadic logic; comment out unneeded error message 2024-07-10 12:28:15 +01:00
Laytan Laats 40625b24e2 fix optimization mode, cold, and disabled not being applied to poly procs 2024-07-09 19:49:12 +02:00
Laytan Laats 1fce5791a1 fix require/enable target feature attribute on poly procs 2024-07-09 19:33:25 +02:00
Jeroen van Rijn d43a2daa17 Merge pull request #3897 from Kelimion/simd-vet
Let simd/x86 pass new transmute/cast vet.
2024-07-09 17:04:45 +02:00
Jeroen van Rijn 7b31acd2d7 Let simd/x86 pass new transmute/cast vet. 2024-07-09 16:50:55 +02:00
gingerBill b83822fd35 #3892 - Use temporary directory for asm file generation 2024-07-09 15:41:05 +01:00
gingerBill ae2f16edea Fix #3894 2024-07-09 15:29:36 +01:00
gingerBill 9782d7b928 Merge pull request #3896 from odin-lang/cached-builds
Internal Cached Builds
2024-07-09 15:27:45 +01:00
gingerBill 5627af582a Add RPROMPT to blacklist 2024-07-09 15:18:15 +01:00
gingerBill d701642293 Check for PROMPT 2024-07-09 15:15:23 +01:00
gingerBill 4c1754b1dc environ is only for Linux 2024-07-09 14:56:12 +01:00
gingerBill 666703f430 Mock out \*nix stuff for cached.cpp 2024-07-09 14:47:22 +01:00
gingerBill 14dc3598b4 Add gb_internal to procedures 2024-07-09 14:33:01 +01:00
gingerBill 330d0e7a2a Add debugf calls 2024-07-09 14:30:38 +01:00
gingerBill 952fb998e6 Check for CURR_DATE_TIME 2024-07-09 14:20:55 +01:00
gingerBill 886ee66e7f Cache files, env, and args 2024-07-09 14:16:56 +01:00
gingerBill 68b70a2183 Check for bounds check error 2024-07-09 13:35:52 +01:00
gingerBill ccdad8b8dd Add odin clear-cache 2024-07-09 13:31:54 +01:00
gingerBill 45bf180847 Add subtarget to cached executable 2024-07-08 23:55:01 +01:00
gingerBill 87ac68fcf2 Add -internal-cached 2024-07-08 23:39:14 +01:00
Jeroen van Rijn 9575d85f1a Merge pull request #3511 from IllusionMan1212/x11-xkb
vendor/x11: some XKB extension procedures and constants
2024-07-08 21:14:26 +02:00
Laytan Laats 2d8d0dd851 fix @(optimization_mode) usage in builtin collections 2024-07-08 21:07:53 +02:00
Laytan Laats 1a20b78633 remove misleading @(optimization_mode) values and make "none" inhibit optimizations 2024-07-08 21:06:57 +02:00
IllusionMan1212 0c27d95679 vendor/x11: some XKB extension procedures and constants 2024-07-08 21:00:19 +02:00
gingerBill a3af94eeae Merge pull request #3893 from laytan/temporary-directory-non-windows
implement `temporary_directory` on non-windows
2024-07-08 18:25:34 +01:00
Laytan Laats 9ff77397c6 implement temporary_directory on non-windows 2024-07-08 18:58:17 +02:00
gingerBill 48aef50164 Add #load cache files to -export-dependencies:json 2024-07-08 17:46:10 +01:00
gingerBill fc9c995dc4 Fix fmt for code compilation bug with any 2024-07-08 16:39:13 +01:00
gingerBill 564d5af8b2 Default to -o:none for all builds 2024-07-08 16:12:22 +01:00
gingerBill 2c9ef6907a Clean up timings messages showing used module count 2024-07-08 15:30:33 +01:00
gingerBill 505dec7b14 Merge branch 'master' of https://github.com/odin-lang/Odin 2024-07-08 15:13:45 +01:00
gingerBill 2a219fa830 Correct -use-separate-module behaviour 2024-07-08 15:13:40 +01:00
gingerBill 498fb00c25 Merge pull request #3890 from laytan/llvm-18-non-windows-releases
ci: make releases use LLVM 18
2024-07-08 14:57:21 +01:00
Jeroen van Rijn ec2234560a Merge pull request #3889 from laytan/darwin-remove-implicit-syscall-usage
darwin: remove syscall usage (without -no-crt) to comply to Apple guidelines
2024-07-08 15:54:24 +02:00
Laytan Laats 5dd89a29e6 ci: make releases use LLVM 18
Since we updated to LLVM 18 on Windows now, we should make the releases
for non-windows use LLVM 18 too, this way all releases use the same version.
2024-07-08 15:49:37 +02:00
gingerBill 8491e2491c Experiment with different uses of -use-separate-modules 2024-07-08 14:48:59 +01:00
Laytan Laats ddad2011e2 darwin: remove syscall usage (without -no-crt) to comply to Apple guidelines 2024-07-08 15:39:23 +02:00
gingerBill 7dd4cccce7 Use a temporary directory for -use-separate-modules
Windows only currently
2024-07-08 14:21:07 +01:00
gingerBill 0f664893dd Add sort for global types and procedures 2024-07-08 13:59:25 +01:00
gingerBill 04e0b3e270 Merge pull request #3887 from odin-lang/windows-llvm-18
Update to LLVM 18.1.8 for Windows
2024-07-08 13:25:22 +01:00
gingerBill 930a147f24 Update to LLVM 18.1.8 2024-07-08 13:08:18 +01:00
gingerBill 86c58167ed Add -print-linker-flags 2024-07-08 10:40:04 +01:00
Jeroen van Rijn 212906ecd2 Merge pull request #3886 from laytan/cbor-enhancements
CBOR enhancements
2024-07-08 02:01:39 +02:00
Laytan Laats 6ab559437a encoding/cbor: add a custom tag to the example 2024-07-08 01:01:11 +02:00
Laytan Laats db3b4ceb4a encoding/cbor: improve perf of marshalling array-like types 2024-07-08 00:37:40 +02:00
Laytan Laats 39e9b65c59 encoding/cbor: fix umarshal of big fixed arrays 2024-07-08 00:35:19 +02:00
Laytan Laats 56856b6307 io: remove dead code in io.write_at_least 2024-07-08 00:33:50 +02:00
Jeroen van Rijn 861ad2037f Merge pull request #3884 from Feoramund/fix-3883
Forbid `$T=` parameter from crashing compiler
2024-07-06 22:08:05 +02:00
Feoramund 77d64a5461 Forbid $T= parameter from crashing compiler
Fixes #3883
2024-07-06 15:32:17 -04:00
gingerBill 88c9512d5f Merge pull request #3828 from laytan/re-raise-signals-from-odin-run
re-raise signals from the `odin run` binary
2024-07-06 18:55:37 +01:00
Jeroen van Rijn b79a098c2e Merge pull request #3882 from Kelimion/clean_up_iterator
Remove nil checks.
2024-07-06 18:45:45 +02:00
Jeroen van Rijn 258f120d52 Remove nil checks.
The caller should really not pass `foo: ^string = nil`. A `for ch, in foo` would also crash,
so let's not introduce new semantics for iteration.

A caller shouldn't pass garbage if they can help it, and a `nil` ^string is not a useful ZII usage here.
2024-07-06 18:34:52 +02:00
gingerBill 80d122f531 Merge pull request #3879 from caquillo07/hm/adding-missing-env-calls-to-core-os-darwin
Add Darwin setenv and unsetenv syscalls
2024-07-06 12:55:29 +01:00
gingerBill efe5e9e349 Merge pull request #3858 from flysand7/wow64-apiset
Add bindings for WOW64 API set
2024-07-06 00:23:47 +01:00
Jeroen van Rijn 25904e8f89 Merge pull request #3878 from Poaetce/setsid-returns-pid
[sys/linux]: change setsid to return Pid
2024-07-06 01:21:22 +02:00
Hector Mejia 2b854c94da added the setenv and unsetenv bindings for darwin, inspired but os_linux.odin 2024-07-05 16:26:03 -04:00
poa 8c98ca3a10 updated return value of setsid to return Pid 2024-07-05 22:53:45 +09:00
Jeroen van Rijn ecffe5a082 Merge pull request #3877 from Kelimion/wstring_fix
Fix utf8_to_wstring given zero bytes.
2024-07-05 13:58:49 +02:00
Jeroen van Rijn 9ecc33570b Improve fix. 2024-07-05 13:51:38 +02:00
Jeroen van Rijn 164a5e587e Fix utf8_to_wstring given zero bytes. 2024-07-05 13:46:07 +02:00
Jeroen van Rijn c8432df248 Merge pull request #3874 from laytan/fix-not-detecting-duplicate-proc-case
Fix not detecting duplicate proc cases
2024-07-05 01:00:14 +02:00
Laytan Laats f66b7021a6 Fix not detecting duplicate proc cases
Fixes #3864
2024-07-05 00:50:52 +02:00
Jeroen van Rijn 22fabba2f6 Fix #3873 2024-07-05 00:48:08 +02:00
gingerBill c77f5b00bc Merge pull request #3872 from laytan/fix-assertion-failure-on-old-llvm
Fix assertion false negative
2024-07-04 23:27:11 +01:00
Laytan Laats 1bd9fe04c4 Fix assertion false positive
Assertion was added in #3855 - https://github.com/odin-lang/Odin/pull/3855/commits/723314909679b89e159cb4cb05d250d12ac64436
to mimic LLVM's own internal assertion for this, turns out their
assertion is more sophisticated than an `==` so lets just remove it.

To be clear their internal assertion is not hit while this one is, which
defeats the purpose of ours.
2024-07-04 23:55:21 +02:00
Jeroen van Rijn 3c2161b196 Merge pull request #3870 from laytan/fix-fontstash-proc-group
vendor/fontstash: fix 'AddFont' proc group for JS target
2024-07-04 17:05:49 +02:00
Jeroen van Rijn 5247d3749c Merge pull request #3871 from Kelimion/dynlib_temp
Remove implicit allocator usage in `core:dynlib`
2024-07-04 17:05:21 +02:00
Jeroen van Rijn 8bee73b08e Remove implicit allocator usage in core:dynlib 2024-07-04 16:53:00 +02:00
Laytan Laats bcdb202639 vendor/fontstash: fix 'AddFont' proc group for JS target 2024-07-04 16:50:58 +02:00
gingerBill 1eb0bc1408 Remove *_test.odin; always compile it for all targets 2024-07-04 14:43:57 +01:00
gingerBill e9a54666e2 Fix typo. 2024-07-04 14:41:10 +01:00
gingerBill 8b7c6a23ba Restrict a bit more 2024-07-04 14:06:02 +01:00
gingerBill bf711b282d Remove when check in check_entity_from_ident_or_selector 2024-07-04 13:58:36 +01:00
gingerBill 87bccc8f3f Remove import name cases 2024-07-04 13:53:52 +01:00
gingerBill 657bc88535 Allow x :: y when cond else proc(...){...} 2024-07-04 13:48:52 +01:00
gingerBill 45b2a6a19e Fix reflect.as_pointer 2024-07-04 13:37:47 +01:00
gingerBill d78ff0be52 Fix lb_store_type_case_implicit 2024-07-04 13:20:36 +01:00
gingerBill 52c219690a Ff @(disabled=true), do not add that entity's dependencies to the set 2024-07-04 13:09:31 +01:00
gingerBill 053f1759d7 Merge pull request #3866 from DerTee/test_mem_dynamic_pool
add test for mem.dynamic_pool and fix alignment bug
2024-07-03 22:17:57 +01:00
gingerBill b65aa9c439 Merge pull request #3867 from karl-zylinski/error-on-typeof-untyped-type
error on type_of(value of untyped type)
2024-07-03 22:09:59 +01:00
Karl Zylinski 782286357b error on type_of(value of untyped type) 2024-07-03 22:21:32 +02:00
DerTee 6b373cf49e fix #3692 memory alignment bug in core:mem.dynamic_pool_alloc_bytes 2024-07-03 22:14:28 +02:00
DerTee a76f9a70d5 add test for allocator mem.Dynamic_Pool
this test currently fails because of bug #3692
2024-07-03 22:13:20 +02:00
Jeroen van Rijn a276722da5 Merge pull request #3865 from Feoramund/fix-sdl-constants
Fix SDL constants
2024-07-03 21:31:53 +02:00
Feoramund bb6cbf6559 Fix SDL constants 2024-07-03 15:22:39 -04:00
Jeroen van Rijn f6892d2236 Fix help text. 2024-07-03 19:30:25 +02:00
gingerBill 075384b2bb Fix #soa assignment bug 2024-07-03 00:33:13 +01:00
gingerBill 7e6acdf800 Merge pull request #3855 from laytan/master
Fix two LLVM assertion failures
2024-07-02 22:16:49 +01:00
gingerBill 8b49549fd3 Merge pull request #3859 from laytan/wasm-stbtt-object-linking-preopens
wasm: support `vendor:stb/truetype` and `vendor:fontstash`
2024-07-02 22:14:54 +01:00
Jeroen van Rijn 0ceae51223 Merge pull request #3862 from laytan/fix-empty-webgpu-link-errors
vendor/wgpu: fix linker errors with empty project
2024-07-02 23:05:34 +02:00
Laytan Laats 761a50e145 vendor/wgpu: fix linker errors with empty project 2024-07-02 22:37:02 +02:00
Laytan Laats 5399093050 make preopens a slice and remove bad current_dir 2024-07-02 20:17:24 +02:00
Laytan Laats 0ef5191540 use slice.ptr_swap instead of alloca 2024-07-02 20:11:44 +02:00
Laytan Laats 10c68a8951 wasm: support vendor:stb/truetype and vendor:fontstash 2024-07-02 16:03:42 +02:00
Laytan Laats 4e18e1b191 wasi: make os.open work with absolute paths 2024-07-02 15:29:24 +02:00
Laytan Laats 6f1cc8071c wasm: add foreign import and linking of wasm object files 2024-07-02 15:28:08 +02:00
flysand7 41282b5211 Add bindings for WOW64 API set 2024-07-02 21:56:04 +11:00
Jeroen van Rijn 0697fd0101 Merge pull request #3857 from flysand7/tlhelp-modentry
[sys/windows]: Fix the type declaration for MODULEENTRY32W
2024-07-02 12:42:18 +02:00
flysand7 62d107bea5 [sys/windows]: Fix the type declaration for MODULEENTRY32W 2024-07-02 21:34:54 +11:00
Andreas T Jonsson b26f4e0766 Use pkgsrc llvm for NetBSD CI 2024-07-02 11:43:01 +02:00
Laytan Laats 7233149096 fix llvm assertion failure when const initializer is not the same type 2024-07-02 01:25:52 +02:00
Laytan Laats c822f0b8c8 fix llvm assertion about metadata on non-instruction 2024-07-02 01:14:50 +02:00
Jeroen van Rijn d912c6e320 Merge pull request #3849 from Feoramund/zero-mantissa
Don't factor trailing zeroes into mantissa division
2024-07-01 20:53:07 +02:00
Jeroen van Rijn f7243eac74 Force cl.exe to parse Odin source as utf-8. 2024-07-01 20:48:00 +02:00
Jeroen van Rijn c2ab2bf25a Add UTF-8 BOM for ucg.c, because reasons. 2024-07-01 20:23:48 +02:00
gingerBill b4ca044ae0 Merge pull request #3846 from Feoramund/add-more-net-tests
Add more `core:net` tests
2024-07-01 17:56:07 +01:00
gingerBill a2b23de0a7 Sanity check for a nullptr 2024-07-01 12:24:46 +01:00
gingerBill 42ff711114 Fix #3515 2024-07-01 12:22:18 +01:00
gingerBill 544959326b Add intrinsics.type_struct_has_implicit_padding #3844 2024-07-01 12:13:35 +01:00
gingerBill 942f3f5220 Add non_zero_* variants for #soa dynamic array 2024-07-01 12:04:29 +01:00
gingerBill 8ddfcf174d Add #soa support to append directly 2024-07-01 11:51:28 +01:00
gingerBill 4086a62167 Fix showing error when not meant to 2024-07-01 11:50:35 +01:00
gingerBill 3a43928184 Add #no_broadcast to append_soa 2024-07-01 11:47:33 +01:00
gingerBill 7f6fe91896 Add #soa forms to reserve, clear, and resize 2024-07-01 11:37:21 +01:00
gingerBill 11617af8f5 Add support for make(#soa[]T) etc 2024-07-01 11:34:50 +01:00
gingerBill 4a2b87672c Unify #soa code for structs and arrays 2024-07-01 11:11:06 +01:00
gingerBill fb0b95bcad Merge pull request #3760 from Feoramund/refactor-show-error-on-line
Refactor `show_error_on_line`
2024-07-01 11:03:29 +01:00
gingerBill 1a4edad63e Merge pull request #3848 from laytan/wasm-c-abi-indirect-multifield-struct
make structs with multiple fields always return indirect in wasm c abi
2024-07-01 11:02:49 +01:00
Feoramund 8cd7fd95a3 Don't factor trailing zeroes into mantissa division
This should fix issues where `N00 / (pow+2)` results in a different number
than `N / pow`.
2024-06-30 22:18:25 -04:00
Laytan Laats ef6a73c7ef fix not setting cc before using it in abi computations 2024-07-01 01:30:44 +02:00
Laytan Laats e3dde8caf8 make structs with multiple fields always return indirect in wasm c abi 2024-07-01 00:50:10 +02:00
Feoramund 8e64265aed Replace unneeded transmute 2024-06-30 16:39:22 -04:00
Feoramund 1e7dfd0e34 Add more core:net tests
- UDP send & read
- DNS resolution
- Nonblocking socket option
2024-06-30 16:39:22 -04:00
gingerBill 13ace1dac9 Merge pull request #3839 from flysand7/tlhelp-fix
[sys/windows]: Fix the value for TH32CS_SNAPPROCESS constant
2024-06-30 20:15:33 +01:00
Jeroen van Rijn efd933e221 Merge pull request #3842 from karl-zylinski/fix-poly-bitset-size
Fix for bit_set[$T] proc params always being generated as i8
2024-06-30 21:10:42 +02:00
Karl Zylinski e0face1ac8 Make types like bit_set[$T] have their upper and lower bits overwritten by upper/lower from the source types when checking if polymorphic type is assignable. This fixes an issue where an i8 was always generated for bit_sets with generic elements, because it couldn't figure out upper/lower when check_bit_set_type was run. Fixes #2860 2024-06-30 20:36:51 +02:00
Feoramund 8b915aae5e Update code for new -vet 2024-06-30 11:18:40 -04:00
Feoramund f0cf1052d0 Fix FreeBSD recvfrom
`fromlen` must be a pointer, not a value.
2024-06-30 10:17:32 -04:00
Jeroen van Rijn 4fbd22b668 Merge pull request #3840 from H0mTanks/master
Add missing enum member for WSAEWOULDBLOCK in TCP_Send_Error for windows.
2024-06-30 11:29:31 +02:00
h0mtanks 2b615b09f0 fixed whitespace 2024-06-30 13:47:11 +05:30
h0mtanks d1603ebac4 added missing would_block enum member 2024-06-30 13:42:55 +05:30
flysand7 561b96b20d [sys/windows]: Fix the value for TH32CS_SNAPPROCESS constant 2024-06-30 13:34:08 +11:00
gingerBill afe24a0d4d Merge pull request #3838 from flysand7/windows-tlhelp
[core/windows]: Bind tlhelp.h functions from kernel32.dll
2024-06-30 02:52:35 +01:00
flysand7 2737ccab3d [core/windows]: Bind tlhelp.h functions from kernel32.dll 2024-06-30 12:35:42 +11:00
Feoramund 8ed5cb283b Re-implement the error squiggles with visual width 2024-06-29 18:55:12 -04:00
Feoramund 8b305a4c67 Add UCG library to Odin compiler 2024-06-29 18:42:56 -04:00
gingerBill 80592f0f51 Add -disallow-do in CI 2024-06-29 22:50:23 +01:00
gingerBill af3401631a Remove the -disallow-do aspect from -strict-style 2024-06-29 22:48:43 +01:00
gingerBill 5637ed9ecd Merge pull request #3836 from laytan/run-wasi-demo-in-ci
wasi: make the demo run on wasi and run it in CI
2024-06-29 22:30:31 +01:00
Laytan Laats 604551eb2d wasi: make the demo run on wasi and run it in CI 2024-06-29 23:15:31 +02:00
Jeroen van Rijn 476d0087c8 Fix bug in div3 fast path. 2024-06-29 23:14:12 +02:00
gingerBill 34fce83d66 Improve -strict-style rules for if-else statements 2024-06-29 20:04:34 +01:00
gingerBill b1a1da6618 Add -vet-tabs 2024-06-29 19:54:31 +01:00
gingerBill e296d6fb90 Fix loads of indentation issues with mixing spaces and tabs 2024-06-29 19:50:51 +01:00
gingerBill 90244a0849 Fix accidental deletion in the -strict-style help comment 2024-06-29 19:41:45 +01:00
gingerBill f4abdf716e Move microarch stuff to a separate file 2024-06-29 19:29:20 +01:00
gingerBill f64d1df90b Add note regarding -strict-style 2024-06-29 19:27:26 +01:00
gingerBill 888bf28076 -strict-style implies -disallow-do 2024-06-29 19:26:11 +01:00
gingerBill 103eccf104 More style improvements 2024-06-29 19:23:58 +01:00
gingerBill 663661db53 Update core to -strict-style 2024-06-29 19:16:32 +01:00
gingerBill 835e8bf87a Update -strict-style 2024-06-29 19:15:33 +01:00
gingerBill 2187f3e7ff -strict-style enforce 1TBS (mostly) 2024-06-29 19:14:24 +01:00
gingerBill 5413a8b744 Even more style fixes 2024-06-29 19:11:36 +01:00
gingerBill 3f9a58808c More style improvements 2024-06-29 19:07:34 +01:00
gingerBill e8517e2694 -strict-style: enforce case to be in the same column as switch 2024-06-29 18:56:45 +01:00
gingerBill 96330996a6 Fix indentation 2024-06-29 18:51:39 +01:00
gingerBill b0cbda4ee0 Fix indentation of tests 2024-06-29 18:51:28 +01:00
gingerBill 930c929294 Indentation fixes 2024-06-29 18:49:57 +01:00
gingerBill 7f05b4caf2 Fix generation for unicode entities 2024-06-29 18:43:09 +01:00
gingerBill 6db748b4a4 Remove debug message 2024-06-29 16:18:43 +01:00
gingerBill a935ade0d2 Keep -sanitize:address happy with bit_field loads 2024-06-29 16:18:07 +01:00
gingerBill ff2d042313 Remove unneeded transmute 2024-06-29 13:54:15 +01:00
gingerBill 913c08a33e Add bit_field to demo.odin 2024-06-29 12:56:46 +01:00
gingerBill c88a1bef91 Add another -vet-cast check 2024-06-29 12:40:04 +01:00
gingerBill 706adb1232 Update for transmute -vet-cast 2024-06-29 12:16:43 +01:00
gingerBill b9861a0cf6 cast to transmute 2024-06-29 12:14:21 +01:00
gingerBill e46d772b6d Add check for integer casts 2024-06-29 12:13:41 +01:00
gingerBill c18c0a3364 Adhere to -vet-cast 2024-06-29 12:07:21 +01:00
gingerBill d6b8544f50 Add internal flag for testing stuff 2024-06-29 12:04:31 +01:00
gingerBill 4b71c47fd5 Check for unneeded transmute with -vet-cast 2024-06-29 12:02:31 +01:00
gingerBill 704530497b Rename -vet-identical-cast to -vet-cast; with minor code clean up 2024-06-29 11:44:45 +01:00
gingerBill 4be0fc05bb Merge pull request #3832 from Feoramund/vet-identical-cast
Add `-vet-identical-cast`
2024-06-29 11:37:35 +01:00
gingerBill 52aa7085e4 Use f32 as the immediate type for addition and subtraction for complex32/quaternion64 2024-06-29 11:09:54 +01:00
gingerBill 9113f389d8 Merge pull request #3831 from Feoramund/fix-darwin-test-runner-cancel
Let Darwin safely panic in a test
2024-06-29 11:01:01 +01:00
gingerBill 55e9b8d994 Use explicit calling conventions 2024-06-29 10:48:41 +01:00
gingerBill ee2a0c4010 Merge branch 'master' of https://github.com/odin-lang/Odin 2024-06-29 10:47:15 +01:00
gingerBill f974002839 Use f32 operations rather than f16 in complex32 and quaternion64 to improve accuracy and performance 2024-06-29 10:47:09 +01:00
gingerBill 83b575aec2 Merge pull request #3833 from karl-zylinski/consistent-default-dynamic-array-capacity
Consistent dynamic array default capacity and avoid unnecessary dynamic array allocations
2024-06-29 10:38:22 +01:00
gingerBill 906afa4154 Allow for when x in y { (minor oversight in syntax) 2024-06-29 10:13:15 +01:00
Karl Zylinski 679f9b4e41 Made default capacity of dynamic arrays more consistent.
Before this if you do `arr: [dynamic]int` and then append to arr, then it will have capacity 8.
But if you did `arr := make([dynamic]int, context.temp_allocator)` then arr would have capacity 16.

Now both `arr: [dynamic]int` and `arr := make([dynamic]int, context.temp_allocator)` will resut in arr having zero 0. The only reason to use `make` without an explicit len or cap now is because you want to set it up for a non-default allocator. After the first call to `append` it will now in both cases have capacity 8.

I also updated the documentation on the strings builder, both to reflect this, and also to fix it incorrectly saying that len would be 'max(16,len)', which wasn't true even before these changes.
2024-06-29 08:57:21 +02:00
Feoramund b3caae6db4 Keep -vet happy 2024-06-28 23:14:03 -04:00
Feoramund 6496432b80 Add -vet-identical-cast 2024-06-28 23:14:03 -04:00
Feoramund 0ea0fac2f9 Call pthread_cancel on Darwin, with advisory comment 2024-06-28 20:47:37 -04:00
Feoramund 13539d3be1 Catch SIGTRAP in the test runner
Fixes `panic` for Darwin.
2024-06-28 19:43:03 -04:00
Feoramund 929cc48703 Merge Darwin signals into other UNIX-likes
They're all the same.
2024-06-28 19:03:43 -04:00
Jeroen van Rijn 06652bebce Merge pull request #3829 from Feoramund/fix-vetted-test-name
Let `-vet` be used with `-define:ODIN_TEST_NAMES`
2024-06-28 23:06:25 +02:00
Feoramund 574342af6f Let -vet be used with -define:ODIN_TEST_NAMES 2024-06-28 15:58:22 -04:00
Laytan Laats fa5be93da2 re-raise signals from the odin run binary 2024-06-28 19:33:34 +02:00
Jeroen van Rijn 007832488d Merge pull request #3827 from Feoramund/require-runtime-linalg-import
Require `base:runtime` import in `core:math/linalg`
2024-06-28 17:44:10 +02:00
Feoramund 2af121752a Require base:runtime import in core:math/linalg 2024-06-28 11:34:35 -04:00
gingerBill 0c8924ea85 Merge pull request #3822 from jasonKercher/os2-rebase
os2 linux round 2
2024-06-28 15:43:18 +01:00
jason 6a894195cb revert os2/process 2024-06-28 09:45:22 -04:00
jason dc954307d7 fix assumption about std handles in os2/file.odin 2024-06-28 07:55:33 -04:00
jason a15cbc474d change error strings to an enumerated array in rodata; print_error takes a file argument 2024-06-28 07:45:24 -04:00
gingerBill 37afd469c6 Merge pull request #3339 from axxeny/patch-1
fix comments in core:container/queue.
2024-06-28 12:00:34 +01:00
gingerBill 853173a11b Merge pull request #3517 from timosperisen/patch-1
Update builder.odin
2024-06-28 12:00:23 +01:00
gingerBill a1ae6f161b Merge pull request #3502 from ARtemachka/master
Fix typo in core_builtin
2024-06-28 12:00:10 +01:00
gingerBill 883f6c129a Merge pull request #3643 from korvahkh/fix-omitempty-comma
encoding/json: Fix struct marshal() emitting comma after omitted field
2024-06-28 11:50:31 +01:00
gingerBill 861d51b760 Merge pull request #3825 from Valakor/wgpu
wgpu_native fixes
2024-06-28 11:49:35 +01:00
gingerBill 17efb87eef Add -custom-attribute 2024-06-28 11:44:39 +01:00
gingerBill 1747fdc3f0 Fix signature 2024-06-28 11:07:54 +01:00
gingerBill bef3ca98f0 Fix signature 2024-06-28 11:01:57 +01:00
gingerBill e15c5c4692 Fix missing import 2024-06-28 10:32:16 +01:00
gingerBill 9a4ffa79db Add missing libraries to examples/all 2024-06-28 10:17:00 +01:00
gingerBill ec38215842 Fix #3803 2024-06-28 10:09:46 +01:00
gingerBill 67e9a6fd9b Improve error reporting on "Failed to parse fail" and show the line error if possible 2024-06-28 10:04:08 +01:00
gingerBill 4824050c99 Merge pull request #3792 from Feoramund/core-uuid
Add `core:encoding/uuid`
2024-06-28 09:49:23 +01:00
gingerBill 35651cfc17 Improve tokenization for false integer literals but not effect possible float literals 2024-06-28 09:24:34 +01:00
gingerBill dde7cb6e7f Improve error message for #3754 2024-06-28 09:21:33 +01:00
gingerBill 862a04376f Improve tokenizing wrong number literals 2024-06-28 09:16:01 +01:00
gingerBill 5a9698e8cb Properly fix #3820 2024-06-28 09:08:57 +01:00
gingerBill 0c8a81d298 Fix #3819 2024-06-28 08:57:31 +01:00
gingerBill 06ff08b9cf Fix #3820 2024-06-28 08:53:05 +01:00
gingerBill 52ea63f89c Fix #3471 2024-06-28 08:43:25 +01:00
gingerBill f883cd5053 Initialize default context in heap_allocator_other.odin 2024-06-28 08:33:12 +01:00
Matthew Pohlmann 4bf9de7237 SupportedLimitsExtras.chain should be a ChainedStructOut to properly chain from SupportedLimits 2024-06-27 21:53:16 -07:00
Matthew Pohlmann 0a504c2647 Some fixes to wgpu_native.
1. LogCallback should have the "c" calling convention and takes a
   userdata pointer like other callbacks.
2. DevicePoll's wrappedSubmissionIndex argument is an optional in/out
   parameter. The previous wrapper method was broken since it passed a
   non-nil structure to the underlying API with invalid members.
2024-06-27 21:41:48 -07:00
Jeroen van Rijn d31f88bfaa Merge pull request #3823 from laytan/enforce-global-foreign-import-variables
disallow non-global foreign import of variables on wasm
2024-06-28 02:11:50 +02:00
Laytan Laats b79d7e6917 disallow non-global foreign import of variables on wasm 2024-06-28 01:34:09 +02:00
Jeroen van Rijn ed7d34beb0 Avoid sporadic wasm crash 2024-06-28 00:39:51 +02:00
Jeroen van Rijn aba274cf75 Merge pull request #3821 from Kelimion/clang_override
Allow `ODIN_CLANG_PATH=clang-path` overrides for link stage.
2024-06-27 23:36:39 +02:00
Jeroen van Rijn 140ee036ce wasm error is no longer relevant 2024-06-27 23:29:36 +02:00
Jeroen van Rijn 58cd75350b Allow ODIN_CLANG_PATH=clang-path overrides
Link using `clang`, unless overridden by `ODIN_CLANG_PATH` environment variable.

Fixes #3783
2024-06-27 23:21:58 +02:00
jason f24f72c280 convert all to use sys/linux over sys/unix; new implementations for pipe, process and env 2024-06-27 17:14:48 -04:00
jason f22754fc90 sys/linux: fix some syscalls and types; add more to Sig_Action and Sig_Info; Pid int->i32 2024-06-27 16:29:47 -04:00
Jeroen van Rijn a0a48bfe34 Fix alignment. 2024-06-27 21:56:26 +02:00
Jeroen van Rijn 9f8b84c212 Merge pull request #3815 from laytan/tlsf-fixes
tlsf: destroy first pool & properly zero memory
2024-06-27 19:50:24 +02:00
Laytan Laats 1c199f52d6 tlsf: destroy first pool & properly zero memory 2024-06-27 19:27:07 +02:00
gingerBill 521182a100 Merge pull request #3813 from tadeohepperle/fix-vulkan-codegen-arrays-as-proc-args
Fix `vender:vulkan` codegen for procedures with fixed size arrays are arguments
2024-06-27 16:34:17 +01:00
Jeroen van Rijn aa27cd4b0b Allow core:odin to parse @(require) import 2024-06-27 16:14:16 +02:00
gingerBill b1d06ea03f Merge pull request #3808 from karl-zylinski/fix-append-elem-max-confusion
Replace `max(8, 1)` in _append_elem with just `8` and a comment.
2024-06-26 21:14:08 +01:00
Jeroen van Rijn e37afa3ada Merge pull request #3814 from Kelimion/fix_fixed
Fix core:math/fixed.
2024-06-26 20:46:46 +02:00
Tadeo hepperle b834bd32f5 fix typo 2024-06-26 20:31:43 +02:00
Jeroen van Rijn 3726f0b73c Merge pull request #3812 from Feoramund/add-table-decorations
Add `write_decorated_table` to `text/table`
2024-06-26 20:15:11 +02:00
Jeroen van Rijn c33bf7673f Fix core:math/fixed. 2024-06-26 20:12:55 +02:00
Tadeo hepperle 67e69f7196 Merge branch 'master' into fix-vulkan-codegen-arrays-as-proc-args 2024-06-26 19:31:00 +02:00
Tadeo hepperle 18dadd94e3 fix proc parsing 2024-06-26 19:30:21 +02:00
Feoramund ba354e0524 Add documentation for write_decorated_table 2024-06-26 12:53:34 -04:00
Feoramund f13d30ad23 Add write_decorated_table API 2024-06-26 12:50:43 -04:00
Feoramund ba05c74936 Enable core:net tests for FreeBSD 2024-06-26 10:05:24 -04:00
Feoramund e61d893a74 Port core:net to FreeBSD 2024-06-26 10:05:24 -04:00
Feoramund 10ce76fcc2 Fix FreeBSD futex implementation
- Add missing size of timeout struct to `_umtx_op`.
- Use `WAIT_UINT` not `WAIT`, as the expected value is an unsigned integer.
- Use new native calls instead of libc.
2024-06-26 10:02:07 -04:00
Feoramund c61f5bbfe7 Add core:sys/freebsd 2024-06-26 10:02:06 -04:00
Jeroen van Rijn 8d1827838f Merge pull request #3807 from karl-zylinski/ctprint
Added fmt.ctprint
2024-06-25 22:52:48 +02:00
Karl Zylinski f227a40652 Replace max(8, 1) in _append_elem with just 8 and a comment. 2024-06-25 22:48:14 +02:00
Karl Zylinski 4e2d12c540 Added fmt.ctprint 2024-06-25 22:32:20 +02:00
Jeroen van Rijn 5d1d98cef3 Merge pull request #3806 from NicknEma/windows_fixes
Update CommandLineToArgvW return type
2024-06-25 12:22:27 +02:00
NicknEma 845613c404 Update CommandLineToArgvW return type
It now returns a multi-pointer so it can be iterated without any casting.
2024-06-25 12:10:17 +02:00
gingerBill 93441a043a Make runtime.heap_alloc contextless 2024-06-25 09:38:49 +01:00
gingerBill c098739484 Remove @(warning) and #warning(...) 2024-06-25 09:36:59 +01:00
Jeroen van Rijn e42029c5ed wgpu ld -> dl 2024-06-25 01:35:26 +02:00
Jeroen van Rijn d97fe41834 Mark deux 2024-06-24 22:45:12 +02:00
Jeroen van Rijn d3d73590d3 Fix CSV comments. 2024-06-24 22:43:14 +02:00
Jeroen van Rijn 185e39e53d Merge pull request #3791 from Feoramund/fix-text-table-alignment
Refactor `core:text/table`
2024-06-24 21:59:33 +02:00
Feoramund 8b05ec1765 Add string caching example documentation 2024-06-24 15:11:43 -04:00
Feoramund fbd609fa37 Add complete example showcasing Unicode support 2024-06-24 15:04:45 -04:00
Feoramund f325a08e57 Make core:text/table examples more complete
They should be completely copy-and-paste friendly now, without the
assumption of someone using `using table`.
2024-06-24 15:04:45 -04:00
Feoramund 7a43404ea1 Add Width_Proc documentation 2024-06-24 15:04:45 -04:00
Feoramund 7da96c484d Remove table.dirty 2024-06-24 14:28:05 -04:00
Feoramund e397bdf11d Let WIDTH_PROC be specified as proc argument to write_*_table 2024-06-24 13:38:59 -04:00
Feoramund 67b4cb0038 Crunch the ranges 2024-06-24 13:18:54 -04:00
Jeroen van Rijn 8eafd9eb82 wgpu import 2024-06-23 22:19:29 +02:00
Feoramund ca58d7771b Use new API from_nanoseconds in uuid 2024-06-22 18:36:42 -04:00
Feoramund 8a4a3ed66e Change how Time is constructed in uuid 2024-06-22 18:21:32 -04:00
Feoramund 4481f9c695 Clarify some uuid legacy documentation 2024-06-22 18:21:32 -04:00
Feoramund 5a75cac5b9 Add API for creating custom version 8 UUIDs 2024-06-22 18:21:32 -04:00
Feoramund e9b882be05 Add vendor-specific version 8 UUID generation (hashing) 2024-06-22 18:21:32 -04:00
Feoramund 859cbf7d72 Test if v1 and v6 UUID node is set correctly 2024-06-22 18:21:32 -04:00
Feoramund d559feb701 Add uuid test for timestamps 2024-06-22 18:21:32 -04:00
Feoramund f6344577d3 Add UUID sorting tests 2024-06-22 18:21:32 -04:00
Feoramund 339b2b23f6 Add unsafe_write to uuid package 2024-06-22 18:21:32 -04:00
Feoramund 8b8f8c7f7d Address minor organizational issues 2024-06-22 18:21:32 -04:00
Feoramund 95a9c9b016 Fix indentation 2024-06-22 18:21:32 -04:00
Feoramund 9b3a104640 Add buffer-based to_string to uuid package 2024-06-22 18:21:32 -04:00
Feoramund 9b265b2309 Improve time-related API in uuid package
- Let timestamps be specified by the user.
- Change `time_v*` to `raw_time_v*` and implement an API that returns
  timestamps from the `time` package.
2024-06-22 18:21:32 -04:00
Feoramund ea771d0cb7 Update uuid package documentation 2024-06-22 18:21:31 -04:00
Feoramund fcdba334ea Require CSPRNG in UUID generation where applicable 2024-06-22 18:21:31 -04:00
Feoramund 3aa232a894 Move v3 and v5 UUID procs to uuid/legacy 2024-06-22 18:21:31 -04:00
Feoramund 9866b54d59 Add version 6 UUID generation 2024-06-22 18:21:31 -04:00
Feoramund 525bfca4ef Add version 1 UUID generation 2024-06-22 18:21:31 -04:00
Feoramund 4cfbd83b10 Add version 7 UUID generation 2024-06-22 18:21:31 -04:00
Feoramund fee81985b4 Make UUID namespaces @(rodata) 2024-06-22 18:21:31 -04:00
Feoramund 6da99b888a Make UUID Identfier only a distinct byte array 2024-06-22 18:21:31 -04:00
Feoramund 31873ed466 Fix wrong comments 2024-06-22 18:21:31 -04:00
Feoramund 4dacddd85e Add core:encoding/uuid 2024-06-22 18:21:27 -04:00
Jeroen van Rijn 3af9d31bd5 Add time.from_nanoseconds 2024-06-23 00:19:24 +02:00
Jeroen van Rijn dae9a8dfff Merge pull request #3796 from Feoramund/fix-lack-of-str-arg-or-cont
Fix print segfault by missing argument in `or_*` shadowed error
2024-06-22 17:57:02 +02:00
Feoramund f58eded5d2 Fix print segfault by missing argument in or_* shadowed error 2024-06-22 11:45:43 -04:00
Jeroen van Rijn 13c58948f4 Merge pull request #3793 from Kelimion/build_test_only
Add `-build-mode:test`
2024-06-21 16:12:13 +02:00
Jeroen van Rijn 9f696a646f Add -build-mode:test. 2024-06-21 16:02:55 +02:00
gingerBill bad4a6237e Delete misc/roadmap.md 2024-06-21 00:02:12 +01:00
Feoramund bf44a94065 Update core:text/table documentation 2024-06-20 18:22:03 -04:00
Feoramund 82d92dc46c Use log.error instead of eprintf 2024-06-20 17:53:45 -04:00
Feoramund b81458073e Add new API to core:text/table
- `header/row_of_values`, same `header/row`, more verbose name
- `aligned_header/row_of_values`, set alignment for an entire row
- `header/row_of_aligned_values`, set alignment per value
2024-06-20 17:53:45 -04:00
Feoramund 585747bbbf Clarify error message 2024-06-20 17:53:34 -04:00
Feoramund 99c955d124 Remove unneeded loc argument 2024-06-20 15:26:00 -04:00
Feoramund fd28199178 Optimize printing of markdown tables
Check only once if the table has a header row, instead of every row.
2024-06-20 15:01:09 -04:00
Feoramund dd099d9dd6 Add Unicode support to core:text/table 2024-06-20 15:01:09 -04:00
Feoramund 2241ca8e72 Use tabs to indent HTML tables 2024-06-20 13:06:32 -04:00
Feoramund b66b960e7e Don't build HTML tables
`build` only recalculates length and width information, and this is not
needed for HTML tables.
2024-06-20 13:06:32 -04:00
Feoramund 4a3684c5e8 Rename write_ascii_table to write_plain_table 2024-06-20 13:06:28 -04:00
Jeroen van Rijn 91cc006e8f Fix unaligned store for rand 2024-06-20 17:54:37 +02:00
Jeroen van Rijn ac4577ca66 Merge pull request #3790 from Feoramund/optimize-common-rng-dest-size
Optimize default RNG for the common case
2024-06-20 17:41:13 +02:00
Feoramund 1dfc89567e Optimize default RNG for the common case 2024-06-20 11:27:51 -04:00
gingerBill 28e33d86de Merge pull request #3776 from IllusionMan1212/os2-read-fix
fix(os2): check for 0 bytes read and return EOF
2024-06-20 15:37:41 +01:00
gingerBill dab3c832e0 Add #warning(<string>) builtin compile time procedure 2024-06-20 15:32:30 +01:00
Jeroen van Rijn 94a8c38d86 Add GetNumberOfConsoleInputEvents 2024-06-20 15:19:25 +02:00
gingerBill 8c760e140f Move import to a windows specific file 2024-06-20 12:38:09 +01:00
gingerBill 3db7780a2c Add vendor:wgpu to examples/all 2024-06-20 12:20:06 +01:00
gingerBill 8b446fc88d Fix wgpu paths for Windows 2024-06-20 12:18:26 +01:00
gingerBill c9884906d9 Add #directory 2024-06-20 12:15:55 +01:00
gingerBill 5dc98336a8 Merge pull request #3524 from Feoramund/freebsd-amd64-syscall-errno
Add `intrinsics.syscall_bsd`
2024-06-20 11:47:01 +01:00
gingerBill 23351ca8be Merge pull request #3137 from laytan/show-defineable
Add flags to show/export defineable values and warn if a -define is unused in the project
2024-06-20 11:45:52 +01:00
gingerBill 56383e45a7 Fix #3768 2024-06-20 11:44:00 +01:00
gingerBill 7184792f7a Merge pull request #3740 from laytan/wgpu
Add `vendor:wgpu`
2024-06-20 11:39:58 +01:00
gingerBill d4aa6c3288 Merge pull request #3788 from Beefster09/builder-utils
Add to_cstring for Builders
2024-06-20 11:34:03 +01:00
gingerBill 7703bc595c Merge pull request #3789 from Feoramund/unicode-annex-11
Measure `East_Asian_Width` during grapheme decoding
2024-06-20 11:32:06 +01:00
Feoramund e620645a03 Measure East_Asian_Width during grapheme decoding 2024-06-19 22:35:36 -04:00
Justin Snyder 1a6bb59125 drop unnecessary defer 2024-06-19 18:25:42 -06:00
Justin Snyder 271782d2f4 fix typo
apparently i had a moment of dyslexia
2024-06-19 17:53:34 -06:00
Justin Snyder 1b7c4c2efe trim added null byte 2024-06-19 17:35:16 -06:00
Jeroen van Rijn 4380934283 Merge pull request #3787 from jasonKercher/more-windows-comm
Add more bindings for comm ports and console events
2024-06-19 23:32:12 +02:00
Jeroen van Rijn 21806e5fa5 Merge pull request #3786 from fabiansperber/fix-d3d11-infoqueue
Fix d3d11 IInfoQueue_VTable & Add LoadLibraryExW
2024-06-19 23:26:40 +02:00
jason 93e67f6bec make -strict-style happy 2024-06-19 17:15:09 -04:00
jason 6b1e76985c move DCB to types.odin; add more bindings for comm functions 2024-06-19 17:04:18 -04:00
Fabian Sperber 0e9bf86123 Fix d3d11 IInfoQueue_VTable & Add LoadLibraryExW
- wrong order & was missing PushStorageFilter & PushRetrievalFilter
2024-06-19 22:22:26 +02:00
Justin Snyder 8f2c4a7ecf Add builder to_cstring 2024-06-19 11:55:19 -06:00
jason e6d84d18d3 Merge remote-tracking branch 'origin/master' into more-windows-comm 2024-06-19 12:33:13 -04:00
jason a9b6d28291 save before merging from upstream 2024-06-19 12:33:05 -04:00
Jeroen van Rijn 2797dc6452 Merge pull request #3785 from mgavioli/new_i18n_API
Separate I18N calls for immutable and for pluraliseable strings. Fixes #3687
2024-06-19 11:50:24 +02:00
Jeroen van Rijn 322b7f1f2f Spell check i18n.odin. 2024-06-19 11:41:58 +02:00
Jeroen van Rijn e0de52efa1 Spell check doc.odin. 2024-06-19 11:15:17 +02:00
Maurizio M. Gavioli 53755824fb Separate the I18N calls for immutable strings and for pluraliseable strings.
Also update tests.
2024-06-19 10:10:26 +02:00
Jeroen van Rijn 7064166da2 Merge pull request #3767 from Feoramund/use-rng-context-in-test-runner
Setup `context.random_generator` in test runner
2024-06-19 09:51:13 +02:00
Feoramund d4803583ff Work around Windows test failure
I am uncertain why this works, but it does. Previously, `rtti_test` was
failing due to non-zero data appearing in the `l_buggy` `Buggy_Struct`.

The issue was caused by calling `runtime.default_random_generator` with
a pointer to the state, somehow. The pointer could be on the stack or in
the heap; it did not matter.

I found two workarounds.

- One is to move the RNG setup behind the call to `free_all`.
- The other is to construct the random generator manually.

Despite my digging and testing, I could find no reason as to why this
works or what the fundamental issue was to begin with. If anyone comes
upon this in the future with direct access to a Windows machine, I
recommend stepping through the program with a debugger to investigate
more deeply into why this happens.
2024-06-18 23:21:04 -04:00
Jeroen van Rijn dff8a9153e Merge pull request #3781 from Feoramund/add-missing-test-imports
Add missing imports to `core` test suite
2024-06-18 18:20:02 +02:00
Feoramund e3f4772d01 Fix removal of temporary file in core:flags test 2024-06-18 11:06:49 -04:00
IllusionMan1212 c987b964c8 fix(os2): check for 0 bytes read and return EOF 2024-06-18 17:03:54 +02:00
Feoramund 6b25d17ef9 Add missing imports to core test suite 2024-06-18 10:38:43 -04:00
gingerBill 3d9db56410 Minor formatting changes to unicode stuff 2024-06-18 12:53:56 +01:00
gingerBill 02cd53d42c Merge pull request #3700 from Feoramund/core-flags
Add package `core:flags`
2024-06-18 12:48:57 +01:00
gingerBill de23965ecb Merge pull request #3775 from Feoramund/unicode-graphemes
Add grapheme analysis facilities to `core:unicode`
2024-06-18 12:48:31 +01:00
gingerBill e8c17ac356 Merge pull request #3778 from Feoramund/fix-2824
Allow custom `main` when `-no-entry-point` is set
2024-06-18 12:46:33 +01:00
gingerBill dc03e8380d Merge pull request #3779 from karl-zylinski/clarify-usage-of-temp-allocator-arena
Clarify when the arena in base:runtime should be used
2024-06-18 12:45:43 +01:00
Jeroen van Rijn aad7ddf2d1 Merge pull request #3780 from destroycomputers/fix/rbtree/key-ordering-constraint
Loosen constraint on the Key type in rb & avl tree
2024-06-18 13:42:36 +02:00
destroycomputers de44dd5412 Loosen constraint on the Key type in rb & avl tree
The current constraint on the `init_ordered' function accepts only
numeric types. While one still can init a non-numerically-keyed tree by
passing a comparator explicitly, the reason to disallow non-numeric
ordered types is nowhere to be found.
2024-06-18 13:31:45 +02:00
Karl Zylinski 11e586494b Clarify that the arena in base:runtime shouldn't be used for anything but the default temp allocator. This is done by renaming the file in which it lives, and also by improving the comment above Arena :: struct {. This should avoid some confusion where people end up using the Arena in base:runtime because they thought it was the 'default arena'. 2024-06-18 12:48:16 +02:00
Jeroen van Rijn dd364c0c0f Merge pull request #3777 from Feoramund/fix-3047
Forbid private test cases
2024-06-18 12:09:58 +02:00
Feoramund 0196cc46e3 Allow custom main when -no-entry-point is set 2024-06-18 01:49:55 -04:00
Feoramund eb5a66c944 Forbid private test cases 2024-06-18 01:28:05 -04:00
Feoramund 9e4899d35c Add tests for decode_grapheme_clusters 2024-06-17 21:57:32 -04:00
Feoramund 63973f431e Make core:unicode letter procs @(require_results) 2024-06-17 21:57:32 -04:00
Feoramund 1620a69398 Add decode_grapheme_clusters to core:unicode/utf8 2024-06-17 21:57:32 -04:00
Feoramund 1a93dfd28f Fix indentation 2024-06-17 13:24:47 -04:00
gingerBill f280ba8511 Merge pull request #3756 from matias-eduardo/empty_structs_hash_fmt
Handle empty structs in hash (#v) fmt
2024-06-16 19:54:28 +01:00
Jeroen van Rijn a66ce4f871 Merge pull request #3773 from Kelimion/res_path_bug
Fix `rc.exe` bug with double-quoted `.res` path.
2024-06-16 19:27:13 +02:00
Jeroen van Rijn fe3baae7a6 Merge pull request #3772 from Feoramund/fix-constant-wrong-type-bitset
Fix `bit_set` construction crash on constant non-integer field
2024-06-16 19:15:50 +02:00
Jeroen van Rijn eebc0dd026 Fix rc.exe bug with double-quoted .res path. 2024-06-16 19:11:54 +02:00
Feoramund 78a5a27212 Fix bit_set construction crash on constant non-integer field 2024-06-16 12:27:42 -04:00
Jeroen van Rijn 339bafe6ff Merge pull request #3770 from skaman/fix-slice-unique
Fix `slice.unique` wrong result
2024-06-16 13:48:21 +02:00
Jeroen van Rijn 0268be1925 Add tests for slice.unique and slice.unique_proc 2024-06-16 13:41:25 +02:00
Sandro Cavazzoni e41878a64f Fix slice.unique wrong result
When you try to make this array unique `[]int{1, 2, 4, 4, 5}` you get
`[]int{1, 4, 5}` instead of `[]int{1, 2, 4, 5}`.
Our index `i` should be increased even with both indices `i` and `j`
have the same value
2024-06-16 11:36:20 +02:00
Feoramund 8b31cddaba Keep -vet happy 2024-06-15 15:49:05 -04:00
Feoramund aab5338134 Add tests for core:math/rand 2024-06-15 15:49:05 -04:00
Feoramund 1a52cf1f1c Use test's random generator
This removes the `create` calls when a test was only setting up a
generator, and it replaces them with `reset` when run in a loop.
2024-06-15 15:49:05 -04:00
Feoramund 5dfd303fd1 Setup default context.random_generator for tests 2024-06-15 15:44:56 -04:00
gingerBill a619ea3bcd Merge pull request #3766 from Feoramund/fix-rng-state
Fix `default_random_generator_proc` not using state
2024-06-15 20:36:10 +01:00
Feoramund 53140dca15 Fix default_random_generator_proc not using state 2024-06-15 12:54:30 -04:00
Jeroen van Rijn ed99e77433 Merge pull request #3765 from Feoramund/add-short-test-logs
Add `ODIN_TEST_SHORT_LOGS` define
2024-06-15 18:01:49 +02:00
gingerBill bacb915ff8 Merge branch 'master' of https://github.com/odin-lang/Odin 2024-06-15 16:24:07 +01:00
gingerBill e41ad2bf16 to_random_generator -> random_generator 2024-06-15 16:24:01 +01:00
gingerBill 4c7469a264 Merge pull request #3764 from Feoramund/test-runner-fixes
Fix half-implemented features in the test runner
2024-06-15 16:19:58 +01:00
Feoramund 753516c392 Add ODIN_TEST_SHORT_LOGS define
Strips out the procedure, date, and time information, for when you just
need to know the file, line, and message.
2024-06-15 11:18:40 -04:00
Feoramund f353adc7fb Prefer log.error over fail_now in this case 2024-06-15 10:53:21 -04:00
Feoramund bb823d5ba0 Make testing.fail_now divergent
This is in line with the old way it worked on Windows.
2024-06-15 10:53:21 -04:00
gingerBill 1c940e3968 Remove dead variable 2024-06-15 15:53:16 +01:00
gingerBill c97ffbecbc Fix rand in container tests 2024-06-15 15:50:35 +01:00
gingerBill 2380720fa2 Fix core:sync/chan for rand 2024-06-15 15:46:48 +01:00
Feoramund 784408358d Call cleanups after test signal 2024-06-15 10:46:47 -04:00
gingerBill 149ecafdef Remove the need for rand in core:math/big 2024-06-15 15:43:57 +01:00
gingerBill 7ec17ecf98 Update core:math/rand to use context.random_generator and remove rand.Rand 2024-06-15 15:33:24 +01:00
gingerBill 318d5e4a7e Add Reset mode 2024-06-15 15:17:23 +01:00
gingerBill eaec8a2bbf Add runtime.default_random_generator 2024-06-15 15:08:49 +01:00
gingerBill c2a01096c4 Remove unneeded reassignment of r 2024-06-15 14:49:09 +01:00
gingerBill 827cb24023 Add random_generator.odin 2024-06-15 14:47:37 +01:00
gingerBill dc4ec8638c Add runtime.Random_Generator interface 2024-06-15 14:45:57 +01:00
Jeroen van Rijn 94ec647923 Merge pull request #3750 from Kelimion/dcb_bitfield
Update kernel32 struct DCB.
2024-06-15 12:14:27 +02:00
Feoramund 51a013fcf1 Work around BSD lack of core:net support 2024-06-15 01:32:48 -04:00
Feoramund f28c6c3bba Keep -vet happy 2024-06-15 00:50:12 -04:00
Feoramund 53e2cdf7af Add core:flags to examples/all 2024-06-15 00:28:47 -04:00
Feoramund 76575e834b Raise error on spaced UNIX-style flag with no value 2024-06-15 00:24:59 -04:00
Feoramund 42a5a2cf17 Fix memory leak in core:flags validation 2024-06-15 00:01:33 -04:00
Feoramund c3acdeb310 Add -- parsing to UNIX-style core:flags
This will allow a user to indicate all arguments after `--` are parsed
into the variadic array.
2024-06-14 23:59:01 -04:00
Feoramund d4e2fa0377 Refactor show_error_on_line
This should adequately solve any issues with Unicode alignment by
sidestepping the issue entirely. With this change, we make use of the
built-in ANSI facilities of the terminal to underline the text.

If the terminal does not support underlining, there are still the
fallback bold markers at the start and end of error locations.
2024-06-14 18:28:47 -04:00
Feoramund 582154f20d Remove unused code from tokenizer 2024-06-14 15:44:50 -04:00
Jeroen van Rijn 908a6ff2d4 Elide unnecessary condition 2024-06-14 21:34:05 +02:00
Jeroen van Rijn 09b3f5a7a7 Merge pull request #3757 from thetarnav/patch-2
Add `#no_bounds_check` to `slice.equal`
2024-06-14 21:27:21 +02:00
Jeroen van Rijn fa4fbbe1ce Merge pull request #3758 from jones-josh/master
Fix big.shrink not actually shrinking
2024-06-14 20:27:03 +02:00
Josh Jones 759139089f Fix big.shrink not actually shrinking 2024-06-14 19:58:13 +02:00
Damian Tarnawski 8ba644dd79 Add #no_bounds_check to slice.equal 2024-06-14 19:45:54 +02:00
Feoramund 8626d38db1 Fix displaying emptiness when error is on first line 2024-06-14 13:02:54 -04:00
Jeroen van Rijn b19bf5bbda Merge pull request #3732 from FrancisTheCat/master
add missing functions to core:sys/windows
2024-06-14 17:57:23 +02:00
Feoramund ca481dc52d Fix displaying error on wrong line with token at EOL
Previously, this would get a token on text like "\n*\n" where `*`
is the token's position, and it would advance off that line.
2024-06-14 11:51:03 -04:00
Franz Höltermann c3302615a3 Merge branch 'master' of https://github.com/FrancisTheCat/Odin 2024-06-14 17:43:09 +02:00
Franz Höltermann 3c3f0f90c2 Fixed WinEventFlags 2024-06-14 17:41:21 +02:00
FrancisTheCat cd5fa8523f Merge branch 'odin-lang:master' into master 2024-06-14 16:34:21 +02:00
Franz Höltermann ec7b77fc0f Improved win32 bindings according to Kelimions suggestions with enums and bitsets 2024-06-14 16:32:41 +02:00
Matias Fernandez 4baf101f15 Handle empty structs in fmt with hash 2024-06-14 05:36:23 -04:00
Jeroen van Rijn ff4787070d Revert "Merge pull request #3744 from Mango0x45/master"
This reverts commit 45044de0b7, reversing
changes made to 20c17ba6f9.
2024-06-14 00:06:55 +02:00
Jeroen van Rijn 54a3cfb540 Merge pull request #3753 from Feoramund/fix-silent-token-fail
Fix compiler silently returning if `parse_packages` fails
2024-06-13 19:33:02 +02:00
Feoramund c560553c21 Fix compiler silently returning if parse_packages fails 2024-06-13 13:01:51 -04:00
Thomas la Cour acce9acb6d Merge remote-tracking branch 'upstream/master' into sys-windows-2 2024-06-13 18:31:53 +02:00
Jeroen van Rijn 45044de0b7 Merge pull request #3744 from Mango0x45/master
Pad ‘^~~~^’-style diagnostic ranges properly
2024-06-13 17:34:17 +02:00
Jeroen van Rijn c9c7d3270d Merge branch 'master' of https://github.com/Mango0x45/Odin into pr/3744 2024-06-13 17:27:00 +02:00
Thomas Voss 9f7ac1469f Generate ranges of the correct length 2024-06-13 17:24:56 +02:00
Jeroen van Rijn ca9d1f940d Just change squiggle_extra type to i32. 2024-06-13 17:23:30 +02:00
Thomas Voss 9f190f3937 Generate ranges of the correct length 2024-06-13 17:00:13 +02:00
Thomas Voss 657c516360 Pad ‘^~~~^’-style diagnostic ranges properly 2024-06-13 16:23:34 +02:00
Jeroen van Rijn 20c17ba6f9 Merge pull request #3751 from Kelimion/custom_formatter
Add example of a custom formatter.
2024-06-13 11:42:38 +02:00
Jeroen van Rijn 3d4e23d741 Add example of a custom formatter. 2024-06-13 11:33:37 +02:00
Jeroen van Rijn 50564a301e Update kernel32 struct DCB. 2024-06-13 10:22:44 +02:00
Jeroen van Rijn f8f6f2dada Merge pull request #3749 from Feoramund/fix-w
Improve support for `%w`
2024-06-13 10:07:48 +02:00
korvahkh 104ca2ce22 Merge branch 'odin-lang:master' into fix-omitempty-comma 2024-06-13 01:27:44 +00:00
Feoramund abe5c2ca83 Add test for %w 2024-06-12 21:07:15 -04:00
Feoramund 0c9f487783 Fix and document %w verb for core:fmt 2024-06-12 20:35:50 -04:00
gingerBill a67df07392 Merge pull request #3742 from karl-zylinski/fix-raymath-matrix-to-float
Make rl.MatrixToFloatV do same thing in Odin as in C
2024-06-12 23:15:48 +01:00
Jeroen van Rijn 05972eb26b Merge pull request #3746 from jasonKercher/add-commtimeouts
add COMMTIMEOUTS, get/setCommTimeouts
2024-06-12 21:50:10 +02:00
gingerBill 4ccc473e97 Merge pull request #3745 from karl-zylinski/rlgl-add-missing-types
rlgl: Pull in raylib and expose missing types
2024-06-12 20:48:22 +01:00
gingerBill 90815452ca Merge pull request #3747 from Feoramund/fix-3739
Fix #3739
2024-06-12 20:48:02 +01:00
jasonkercher a804463a57 add COMMTIMEOUTS, get/setCommTimeouts 2024-06-12 15:31:59 -04:00
Feoramund 33270f14a4 Fix #3739 2024-06-12 15:31:43 -04:00
Karl Zylinski c7ea4ec71c rlgl: Pull in raylib and expose missing types, so it is the same as rlgl.h. This makes rlgl less stand-alone, but I left some notes in rlgl.odin how to easily make it stand-alone if one really wants to. 2024-06-12 21:13:12 +02:00
Karl Zylinski d37b5a7b67 Make rl.MatrixToFloatV transpose the matrix before transmuting it to [16]f32, so it does the same thing as the raymath version implemented in C. 2024-06-12 19:54:14 +02:00
Feoramund 1128bd1d7f Use syscall_bsd on NetBSD 2024-06-12 13:34:36 -04:00
Feoramund 20c32c807d Fix info.init_os_version on FreeBSD
It's possible for the return string to be longer than 128 characters
these days, so I've increased it to 1024, same as the other BSDs.

SYSCTL was otherwise erring out due to lack of buffer space.
2024-06-12 13:10:19 -04:00
Feoramund 5b5402fb23 Add intrinsics.syscall_bsd
This is a BSD-style syscall that checks for a high Carry Flag as the
error state. If the CF is high, the boolean return value is false, and
if it is low (no errors) then the boolean return value is true.
2024-06-12 13:07:13 -04:00
Laytan Laats 108b8feb35 Add vendor:wgpu 2024-06-12 17:22:02 +02:00
Jeroen van Rijn 603581aa53 Merge pull request #3738 from Kelimion/xml_attr
Xml attr
2024-06-12 14:06:40 +02:00
gingerBill c5f7788652 Check to see if matrices are exactly the same type 2024-06-12 12:54:57 +01:00
gingerBill f57c03c170 Improve matrix type hinting rules a little 2024-06-12 12:40:29 +01:00
Jeroen van Rijn 2fe961cbcd Fold XML attribute whitespace. 2024-06-12 13:30:00 +02:00
Jeroen van Rijn ebadff555d Update XML reader to normalize whitespace, part 1. 2024-06-12 12:52:48 +02:00
gingerBill cb45aa58fd Merge pull request #3731 from karl-zylinski/rlgl-subpackage
Move rlgl to vendor:raylib/rlgl
2024-06-12 11:51:16 +01:00
gingerBill e87c5bca58 Merge pull request #3737 from karl-zylinski/raylib-shader-location-index-any-int
Made rl.SetShaderValue etc take a c.int like in original raylib
2024-06-11 21:45:40 +01:00
Jeroen van Rijn 0398388a59 Merge pull request #3729 from Feoramund/fix-3460
Fix #3460
2024-06-11 20:32:37 +02:00
Thomas la Cour 8403952fd2 win32gen 2024-06-11 18:30:41 +02:00
Thomas la Cour 32dcb3caef windows bindings test 2024-06-11 18:19:29 +02:00
Thomas la Cour 465ac74020 more windows stuff 2024-06-11 18:19:16 +02:00
Karl Zylinski 1a22f82f94 Changed rl.SetShaderValue etc to take a c.int like in original raylib.h. You should be able to use other values than the ShaderLocationIndex enum, that enum is only for build in things in raylib. Added #any_int on those procs so you can pass both int and also a ShaderLocationIndex. 2024-06-11 18:03:20 +02:00
gingerBill 35a845b93f Fix indentation 2024-06-11 13:12:41 +01:00
gingerBill 3ff8952813 Replace panic(fmt.tprintf( antipattern with fmt.panicf 2024-06-11 13:11:14 +01:00
gingerBill 56c5e93fd1 Merge pull request #3728 from Feoramund/mem-any-int
Use `#any_int` for `reserve_*` and `resize_*` procs
2024-06-11 12:52:50 +01:00
gingerBill 39b166edd3 Merge pull request #3733 from Feoramund/ci-freebsd
Add FreeBSD to the CI
2024-06-11 12:51:42 +01:00
gingerBill eaf1d88287 Merge pull request #3734 from Feoramund/fix-3730
Fix #3730
2024-06-11 12:50:41 +01:00
gingerBill 1dc90103bd Make verification ignorable with a define flag 2024-06-11 12:30:24 +01:00
gingerBill 0b02c67cdf Minor clean up for backend 2024-06-11 12:19:52 +01:00
gingerBill 9b0e87544a Unify LLVMVerifyFunction invocations into on place 2024-06-11 12:07:22 +01:00
Feoramund 61c630bbf8 Fix #3730 2024-06-11 05:23:43 -04:00
Feoramund 0e6bcd0dbb Add FreeBSD to CI 2024-06-11 04:16:42 -04:00
Feoramund fc88de12c2 Implement absolute_path_from_handle for FreeBSD 2024-06-11 04:16:42 -04:00
Feoramund a3da796d54 Fix file_size on FreeBSD
It was using the generic UNIX `fstat` implemented in Odin, which is more
than what is needed here.

This also avoids the issue of needing a proper
`absolute_path_from_handle` implementation for it to work without error.
2024-06-11 03:55:41 -04:00
Feoramund 40e99ebb10 Fix file open O_* flags on FreeBSD 2024-06-11 03:55:41 -04:00
Feoramund c68560c573 Use correct __error link name for FreeBSD 2024-06-11 03:55:41 -04:00
Feoramund 76292c8ed5 Forbid all BSDs from running core:net tests
`net` is not yet implemented on them.
2024-06-11 03:55:41 -04:00
Franz Höltermann c6c00c706a Merge branch 'master' of https://github.com/odin-lang/Odin 2024-06-11 09:37:20 +02:00
Franz Höltermann 6454c6f087 Added some missing functions to core/sys/windows 2024-06-11 09:35:59 +02:00
Karl Zylinski c9e732d141 rlgl.RLGL_VERSION -> rlgl.VERSION 2024-06-11 08:59:30 +02:00
Karl Zylinski d2cd96c3c8 Made rlgl.odin work as a subpackage of raylib. So now you import vendor:raylib/rlgl. Instead of rl.rlBegin(rl.RL_TRIANGLES) you now type rlgl.Begin(rlgl.TRIANGLES). 2024-06-11 08:46:44 +02:00
Karl Zylinski 34af2bb8ad Moved rlgl.odin to subpackage 'raylib/rlgl' 2024-06-11 08:34:45 +02:00
Feoramund bd198aeada Fix #3460 2024-06-10 23:37:54 -04:00
Feoramund 50464bdce3 Use #any_int for reserve_* and resize_* procs
Resolves #3088
2024-06-10 20:51:58 -04:00
gingerBill f1779c85de Fix #3727 2024-06-10 18:50:53 +01:00
gingerBill 903e254e36 Merge pull request #3725 from laytan/add-forced-shutdown-to-test-runner
add forced shutdown to new test runner
2024-06-10 15:08:09 +01:00
gingerBill eef2aef021 Fix #3724 2024-06-10 15:07:45 +01:00
gingerBill c1e81dc14d Fix #3726 2024-06-10 15:05:24 +01:00
gingerBill fa3cae2bb0 Add intrinsics.procedure_of
```odin
foo :: proc(x: $T) { fmt.println(x) }
bar :: intrinsics.procedure_of(foo(int(123))) // parameters are never ran at compile time, similar to `size_of`
bar(333) // prints 333
```
2024-06-10 15:02:34 +01:00
Laytan Laats 71929f737b add forced shutdown to new test runner
Currently, a Ctrl+c starts a graceful shutdown of the tests and runner.
Sometimes tests get stuck and this would never complete.

This simply adds an extra step, if Ctrl+c is given for the second time,
just `os.exit` right away.
2024-06-10 15:35:23 +02:00
gingerBill 1945218f6d Improve parsing for label: #reverse for and label: #partial switch 2024-06-10 14:18:33 +01:00
Jeroen van Rijn bedeaa34d9 Merge pull request #3723 from Feoramund/use-final-march
Use `get_final_microarchitecture()` for `ODIN_MICROARCH_STRING`
2024-06-10 11:40:01 +02:00
Feoramund 71a812e7fe Use get_final_microarchitecture() for ODIN_MICROARCH_STRING 2024-06-10 05:30:16 -04:00
Jeroen van Rijn 741ee00b64 Merge pull request #3721 from Feoramund/add-tuning-consts
Add compilation-related constants
2024-06-10 10:31:12 +02:00
Jeroen van Rijn d3ae70264e Merge pull request #3720 from Feoramund/fix-force-inline-err-typo
Fix typo in a `#force_inline` error message
2024-06-10 10:25:09 +02:00
Jeroen van Rijn c8b376f07f Merge pull request #3719 from Feoramund/fix-orbranch-error
Fix `or_or_<branch>` error message
2024-06-10 10:21:05 +02:00
Feoramund ff7fcb6d38 Add compilation-related constants
`ODIN_VERSION_HASH` is the `git` SHA hash of the commit the Odin
compiler was built with.

`ODIN_MICROARCH_STRING` is the string passed to `-microarch` when
the program was built.

`ODIN_OPTIMIZATION_MODE` is an enum value of which optimization mode was
used to build the program.
2024-06-10 03:47:20 -04:00
Feoramund 45d1328a85 Fix typo in a #force_inline error message 2024-06-10 00:50:16 -04:00
Feoramund 8702bf00d5 Remove _ in Syntax_Error verbose message 2024-06-09 22:47:43 -04:00
Feoramund 9d28f2e18c Fix or_or_<branch> error messages 2024-06-09 22:46:45 -04:00
Jeroen van Rijn 5985c6e3df Merge pull request #3718 from Feoramund/add-missing-big-atoi-alias
Add missing `string_to_int` alias in `core:math/big`
2024-06-10 03:58:56 +02:00
Jeroen van Rijn 82e2d1916f Merge pull request #3717 from Feoramund/big-combo
Add permutation & combination procs to `core:math/big`
2024-06-10 03:47:55 +02:00
Feoramund 70820c2c40 Add missing string_to_int alias in core:math/big 2024-06-09 21:42:31 -04:00
Feoramund fe5c278fca Add test for core:math/big permutation & combination procs 2024-06-09 20:42:09 -04:00
Feoramund f0d65112b8 Rename math/big test package
This is in line with the other tests, and it does not seem to affect
building the library.
2024-06-09 20:42:07 -04:00
Feoramund 5fbd876db1 Add permutation & combination procedures to core:math/big 2024-06-09 20:42:04 -04:00
Jeroen van Rijn 4ea593bde0 Merge pull request #3716 from Feoramund/slice-permute
Add in-place permutation iterator to `core:slice`
2024-06-09 22:42:43 +02:00
Feoramund 047b505836 Add test for slice.permute 2024-06-09 16:15:43 -04:00
Feoramund 1f64d8d5bd Add slice.permute 2024-06-09 16:15:41 -04:00
gingerBill 7c529e990d Add -target:freestanding_arm32 (experimental) 2024-06-09 17:48:46 +01:00
gingerBill 828870004b Change indentation 2024-06-09 17:15:08 +01:00
Jeroen van Rijn 7e60e21934 Merge pull request #3714 from Kelimion/png_cleanup
PNG cleanup
2024-06-09 18:09:17 +02:00
Jeroen van Rijn 5be7d8e32d Clean up PNG code. 2024-06-09 17:59:59 +02:00
Jeroen van Rijn fc2ba81be0 Merge branch 'master' into png_cleanup 2024-06-09 17:13:43 +02:00
gingerBill edcbca51c3 Merge pull request #3684 from odin-lang/tlsf-allocator
`core:mem/tlsf` - "Two-Level Segregated Fit" memory allocator
2024-06-09 15:54:46 +01:00
Jeroen van Rijn 3c7e2659ac Merge branch 'master' into tlsf-allocator 2024-06-09 16:42:23 +02:00
Jeroen van Rijn 6b88d0a820 Use new blend helper 2024-06-09 16:37:27 +02:00
Jeroen van Rijn d2a2c1e74e Image: Add improved blending method and test it. 2024-06-09 16:10:06 +02:00
gingerBill ef7c6b9895 Re Fix #3713 2024-06-09 14:07:07 +01:00
gingerBill c17981ac38 Add edge case to error_operand_no_value 2024-06-09 14:02:01 +01:00
gingerBill 4b52f7fe2b Fix #3713 2024-06-09 13:35:22 +01:00
gingerBill 8fcfd8c506 Fix sign flag 2024-06-09 13:21:22 +01:00
gingerBill e0d0dc704c Make f32(u8) etc do an immediate cast to f32(u32(u8)) in code generation 2024-06-09 13:20:48 +01:00
Jeroen van Rijn 14f08ff02b Merge pull request #3712 from laytan/fix-large-ints-amd64sysv-abi
fix large ints amd64 sysv abi
2024-06-09 11:01:31 +02:00
Jeroen van Rijn 5d5ef78de9 Merge pull request #3711 from laytan/fix-swizzle-crash
fix swizzle crash due to wrong alignment
2024-06-09 11:00:15 +02:00
Jeroen van Rijn e595bdc805 Merge pull request #3710 from laytan/fix-unreachable-with-complex-param-or-return-inits
fix unreachable hit when param and/or return have complex inits
2024-06-09 10:59:26 +02:00
Laytan Laats 6d862cc4e5 fix unreachable hit when param and/or return have complex inits
Fixes #3630
2024-06-09 04:43:19 +02:00
Laytan Laats 3628154849 fix swizzle crash due to wrong alignment
Fixes #3691
2024-06-09 03:33:23 +02:00
Laytan Laats 9ad9236c3b fix large ints amd64 sysv abi
Fixes #3707
2024-06-09 02:47:05 +02:00
Jeroen van Rijn 0d698c7b53 Merge pull request #3709 from Feoramund/stop-low-swizzle
Prevent panic when `swizzle` called with < 2 indices
2024-06-08 23:14:55 +02:00
Feoramund 49f147cc86 Prevent panic when swizzle called with < 2 indices
The requirement for at least 2 indices has been sourced from
`lb_addr_swizzle` in `llvm_backend_general.cpp`, where there is an
assert to ensure the swizzle_count is `1 < n <= 4`.
2024-06-08 17:05:00 -04:00
Jeroen van Rijn e5bf6fd3aa Merge pull request #3708 from Feoramund/ignore-bmp-assets
Add `*.bmp` to core tests `.gitignore`
2024-06-08 22:45:08 +02:00
Feoramund 5c8f78a25a Add *.bmp to core tests .gitignore 2024-06-08 16:43:45 -04:00
Jeroen van Rijn 1f4cfd52fd Merge pull request #3706 from leidegre/os_read_dir_windows
Fixed error handling in read_dir on Windows
2024-06-08 17:14:49 +02:00
gingerBill be0774acc8 Add error message on return a constant slice value from a procedure 2024-06-08 16:07:28 +01:00
Jeroen van Rijn de7d3e2487 Update dir_windows.odin 2024-06-08 17:00:38 +02:00
gingerBill 7e994b6d21 Remove empty line preventing a suggestion from happening 2024-06-08 15:42:19 +01:00
John Leidegren 35e57fdef8 Fixed error handling in read_dir on Windows 2024-06-08 15:58:34 +02:00
gingerBill 371749d474 Make certain procedures "contextless" for microui 2024-06-08 14:48:04 +01:00
Jeroen van Rijn 575e5a255b Merge pull request #3704 from Feoramund/fix-fmt-p-verb
Fix `%p` pointers not printing leading `0x`
2024-06-07 23:00:29 +02:00
Jeroen van Rijn 323a6e0728 Nuke ancient comment. 2024-06-07 22:19:01 +02:00
Feoramund affd48c791 Add #caller_location to check in fmt tests
This makes it much easier to track down which line failed.
2024-06-07 16:08:37 -04:00
Feoramund b65589d036 Add %p tests for fmt 2024-06-07 16:07:11 -04:00
Feoramund 61c481bd81 Fix %p pointers not printing leading 0x 2024-06-07 15:27:43 -04:00
Jeroen van Rijn 96c06185dd Merge pull request #3701 from laytan/fix-thread-deadlock
Fix thread deadlock
2024-06-07 20:39:40 +02:00
Laytan Laats 00dfff7ee0 core/thread: fix a deadlock situation on unix 2024-06-07 20:28:09 +02:00
Laytan Laats b35e72c82b core/sync: fix wrong timeout calculation, time.Duration is ns already 2024-06-07 20:27:33 +02:00
Feoramund edb685f04b Add package core:flags 2024-06-07 13:16:13 -04:00
Jeroen van Rijn 7c977bb859 Merge pull request #3699 from laytan/macos-14.5
add MacOS 14.5 to 'core:sys/info' and 'odin report'
2024-06-07 17:44:09 +02:00
Laytan Laats 072825ac5a add MacOS 14.5 to 'core:sys/info' and 'odin report' 2024-06-07 17:42:41 +02:00
Jeroen van Rijn 4c45f7d3ae Merge pull request #3698 from laytan/utilize-odin-test-instead-of-scrips-to-run-tests
Utilise `odin test` instead of scripts to run tests
2024-06-07 17:36:23 +02:00
Jeroen van Rijn 11137cfec5 Merge pull request #3697 from laytan/add-error-message-for-unknown-test-log-level
add error message for unknown test log level
2024-06-07 17:11:48 +02:00
Laytan Laats e627fcb0e6 fix not printing Error: when terminal has no color support 2024-06-07 16:58:23 +02:00
Laytan Laats 29250f2657 fix regression in test_issue_2395 2024-06-07 16:33:38 +02:00
Laytan Laats 9122c20d4b update actions/checkout 2024-06-07 15:57:09 +02:00
Laytan Laats 0a528777e8 utilize odin test -all-packages instead of (make/bat) scripts for running tests 2024-06-07 15:50:00 +02:00
Laytan Laats f2be35f1f0 remove caught unused define 2024-06-07 15:22:14 +02:00
Laytan Laats ee93d7c05e add error message for unknown test log level
It would previously just be a compilation error about a missing
return statement.
2024-06-07 15:13:09 +02:00
Laytan Laats 315695b4f8 collect and show docs of defineables 2024-06-07 15:08:41 +02:00
gingerBill 68781f8dd3 Remove unnecessary Wait_Signal checks 2024-06-07 00:11:00 +01:00
gingerBill 1d99bc0f87 Merge branch 'master' of https://github.com/odin-lang/Odin 2024-06-06 23:55:54 +01:00
gingerBill 7044a7d776 Try to fix a possible race condition with polymorphic record parameters 2024-06-06 23:55:48 +01:00
Jeroen van Rijn 4b6fe2baa7 Merge pull request #3696 from Kelimion/bmp_save
BMP save
2024-06-07 00:23:55 +02:00
Jeroen van Rijn ed060819f3 Test roundtripping BMP 2024-06-07 00:14:15 +02:00
Jeroen van Rijn 566119ff83 Add saving of 24 and 32-bit images to BMP format. 2024-06-06 23:53:15 +02:00
gingerBill 08612423b9 Merge branch 'master' of https://github.com/odin-lang/Odin 2024-06-06 21:03:44 +01:00
gingerBill ff37a7435c Add parentheses around the foreign import paths 2024-06-06 21:03:35 +01:00
Laytan Laats fa08690686 explicit integer conversions 2024-06-06 19:49:51 +02:00
Laytan Laats b818a77131 check if -define is actually used 2024-06-06 19:46:01 +02:00
Laytan Laats 9a95049393 -show-defineables and -export-defineables 2024-06-06 19:44:54 +02:00
Jeroen van Rijn b196b84ef2 Merge pull request #3695 from laytan/fix-linking-on-weird-linuxes
fix linking on weird linuxes
2024-06-06 19:37:31 +02:00
Laytan e2eb3cdd8a fix linking on weird linuxes 2024-06-06 19:23:36 +02:00
gingerBill d0dbe9a1bd Merge branch 'master' of https://github.com/odin-lang/Odin 2024-06-06 17:59:19 +01:00
gingerBill 039bb8794a Improve matrix_align_of logic when it has invalid inputs. 2024-06-06 17:59:12 +01:00
gingerBill f010544eff Merge pull request #3609 from Kelimion/bmp
Add core:image/bmp
2024-06-06 16:29:35 +01:00
Jeroen van Rijn 4a290f47ad Re-add BMP test suite download. 2024-06-06 16:55:03 +02:00
Jeroen van Rijn 678fdae966 Rebased. 2024-06-06 16:32:18 +02:00
gingerBill 3a9b86628a Add @(rodata) and @(static, rodata) where appropriate 2024-06-06 15:23:52 +01:00
gingerBill bea47db495 Allow @(rodata) on @(static) variables 2024-06-06 15:20:47 +01:00
gingerBill 9ef43fc782 Add @(rodata) 2024-06-06 15:16:34 +01:00
Jeroen van Rijn 28ea9425fd Add core:mem tests. 2024-06-06 14:59:19 +02:00
Jeroen van Rijn 72f6b5479d Fix fls_uint 2024-06-06 14:42:19 +02:00
Jeroen van Rijn 0b6d73c86e Add original LICENSE 2024-06-06 14:29:28 +02:00
gingerBill 971229fe66 Fix #3686 2024-06-06 13:27:55 +01:00
gingerBill c4ef8e7f6c Merge branch 'master' of https://github.com/odin-lang/Odin 2024-06-06 13:02:16 +01:00
gingerBill 155516b897 Fix -ignore-warnings 2024-06-06 13:02:08 +01:00
Jeroen van Rijn 9b66b0c8e6 Merge pull request #3694 from rope-hmg/master
Updated SDL_CreateTexture to take `PixelFormatEnum` instead of `u32`
2024-06-06 13:03:16 +02:00
Hector 483015fe57 Updated SDL_CreateTexture to take PixelFormatEnum instead of u32 2024-06-06 11:47:59 +01:00
gingerBill a73741d3b7 Merge pull request #3690 from laytan/orcas
Runtime support for orca
2024-06-06 11:03:51 +01:00
Jeroen van Rijn fb2849e02e Merge pull request #3693 from colrdavidson/x11-title-change-support
Add support functions for title changes, cursor config, and dnd
2024-06-06 11:48:16 +02:00
Colin Davidson 70592630a4 add support for title changes, cursor config, and dnd 2024-06-06 02:39:48 -07:00
Jeroen van Rijn fcfc1cb97f Nightly ZIP level 9 2024-06-05 22:26:03 +02:00
Jeroen van Rijn cdd90a9a0b Merge pull request #3688 from Kelimion/nightly
Rewrite upload_b2 nightly action against B2 SDK
2024-06-05 21:11:25 +02:00
Jeroen van Rijn 460ffe1aee Rewrite upload_b2 nightly action against B2 SDK 2024-06-05 21:04:35 +02:00
laytan 08382cb05d orca windows 2024-06-05 19:28:40 +02:00
Laytan Laats 8455e159f5 improve orca target 2024-06-05 20:57:39 +02:00
gingerBill 76d3be7912 Merge pull request #3683 from andreas-jonsson/test-make-cleanup
Minor cleanup of makefiles and scripts
2024-06-05 15:44:27 +01:00
gingerBill 97f0f72080 Merge pull request #3685 from markersniffen/sniffen
D3D11.odin - fix VIDEO_SUPPORT flag
2024-06-05 15:43:55 +01:00
gingerBill a667878d23 Merge branch 'master' of https://github.com/odin-lang/Odin 2024-06-05 15:43:21 +01:00
gingerBill cbabcb0907 Fix #3682 2024-06-05 15:43:15 +01:00
gingerBill fac9ce5d83 Change to init from create 2024-06-05 15:30:35 +01:00
gingerBill d3342c2381 core:mem/tlsf - "Two-Level Segregated Fit" memory allocator 2024-06-05 15:15:39 +01:00
Mark Sniffen cd4375061c D3D11 - fixed VIDEO_SUPPORT flag 2024-06-05 10:11:18 -04:00
Andreas T Jonsson f0e98372fb Minor cleanup of makefiles and scripts 2024-06-05 15:37:02 +02:00
gingerBill a747e47582 Merge pull request #3675 from Feoramund/fix-partial-infinity
Fix partial parsing of `infinity`
2024-06-05 12:48:44 +01:00
gingerBill adcda88501 Merge pull request #3680 from andreas-jonsson/netbsd-arm64
ARM64 support for NetBSD
2024-06-05 12:47:29 +01:00
gingerBill e7190aab41 Merge pull request #3681 from andreas-jonsson/netbsd-lwp-self
Proper thread identification on NetBSD
2024-06-05 12:47:23 +01:00
Andreas T Jonsson 929437c7bc Fixed broken import 2024-06-05 11:17:13 +02:00
Andreas T Jonsson ed6667ebf2 Propper thread identification on NetBSD 2024-06-05 11:06:14 +02:00
Andreas T Jonsson 58f07698e8 Added arm64 support for NetBSD 2024-06-05 10:18:47 +02:00
Jeroen van Rijn c406bbb6e3 Merge pull request #3679 from Feoramund/fix-typos
Fix some typos
2024-06-05 09:30:10 +02:00
Feoramund b2f9f0af68 Fix some typos 2024-06-04 19:01:30 -04:00
Feoramund 25feff3eb4 Permit parsing of incomplete infinity but do not return true
To clarify, `parse_f64` will indeed take `infi` to mean `+Inf` and
return that as the value, but it will not return `ok = true`. It treats
it as `inf` followed by any other trailing character.

`parse_f64_prefix` is the lenient one which will return true so long as
it finds some meaningful value.
2024-06-04 18:55:13 -04:00
Feoramund 1fc6ff91b2 Add test for infinity with trailing characters 2024-06-04 18:55:13 -04:00
gingerBill 2c580aa6fb Merge pull request #3676 from laytan/fix-passing-pointer-to-constant-to-non-odin-cc
fix passing pointer to constant in non-odin cc
2024-06-04 23:12:46 +01:00
Jeroen van Rijn f0a6fb4057 Merge pull request #3678 from Feoramund/fix-p-f64-p-doc
Strike incorrect note from `parse_f64_prefix` doc
2024-06-05 00:02:34 +02:00
Jeroen van Rijn 448c0d8dd3 Merge pull request #3677 from Feoramund/parse-compquat
Add `parse_complex/quaternion*` to `core:strconv`
2024-06-04 23:58:43 +02:00
Feoramund b4cfae222c Strike incorrect note from parse_f64_prefix doc 2024-06-04 17:50:19 -04:00
Feoramund 265e6aa781 Add parse_complex/quaternion* to core:strconv 2024-06-04 17:12:55 -04:00
Jeroen van Rijn 9d234998c0 Update create_nightly_json 2024-06-04 22:44:49 +02:00
Jeroen van Rijn c2ddf4266f Update delete_old_binaries.py 2024-06-04 22:26:51 +02:00
gingerBill a0b1b8d1c3 Merge pull request #3673 from laytan/implement-foreign-import-improvements-on-vendor
Implement `#exists(path)` and use it to provide good errors for common missing vendor libraries
2024-06-04 19:57:09 +01:00
Laytan Laats dbaf1a1ce0 compile stb_vorbis 2024-06-04 20:26:21 +02:00
Feoramund c656a9e4cd Fix and subsume test_issue_2087 into strconv test suite
The full "infinity" strings were expected to be partial consumes, but
this is not the case. That has been fixed and the relevant extra tests
from that file have been added to this test suite.

Fixes #2670
2024-06-04 14:23:48 -04:00
Laytan Laats cd99625dd3 ci: compile needed libraries 2024-06-04 20:21:52 +02:00
Feoramund 7d670f6562 Add initial test suite for core:strconv 2024-06-04 14:20:31 -04:00
laytan 2a526058b3 fix passing pointer to constant in non-odin cc 2024-06-04 20:15:47 +02:00
Laytan Laats 3e159736cd use #exists to provide good errors for common missing libraries 2024-06-04 20:13:51 +02:00
Feoramund d33668fa91 Fix partial parsing of "infinity" in parse_f64_prefix
It was previously reporting an invalid number of characters parsed for
any string other than "inf", "+inf", or "-inf".
2024-06-04 13:24:46 -04:00
Laytan Laats b47a15733d implement #exists(path) 2024-06-04 19:06:13 +02:00
Laytan Laats 4f5b2bd127 fix crash when you have 2 #load_directory calls with the same path 2024-06-04 19:01:50 +02:00
gingerBill 3b7100f8e5 raygui: change c.int to their correct enum types 2024-06-04 16:17:49 +01:00
gingerBill 6b386631dd Improve error message suggestion for passing enums to integers 2024-06-04 16:16:27 +01:00
gingerBill 11b1a48bf0 Fix extra_linker_flags for raylib on windows 2024-06-04 15:54:57 +01:00
gingerBill 72ce111a95 Keep -vet happy 2024-06-04 15:51:19 +01:00
gingerBill 606608c02b Utilize foreign import constant strings for foreign imports 2024-06-04 15:49:17 +01:00
gingerBill eacf2918ad Merge pull request #3469 from hodgka/raylib_resizable_doc_patch
Fixed typo in raylib documentation
2024-06-04 15:41:15 +01:00
gingerBill afcccfdec5 Merge pull request #3615 from puzzleddev/export-dependencies
Add build flag to export dependencies.
2024-06-04 15:40:54 +01:00
gingerBill 60a064984d Merge pull request #3670 from colrdavidson/x11-tweaks
Correct X11 prefix issues
2024-06-04 15:02:03 +01:00
gingerBill 0504c12f04 Merge pull request #3672 from laytan/fix-old-llvm-debug-info
fix debug info IR error on LLVM < 13
2024-06-04 15:01:30 +01:00
Laytan Laats 7d29389834 fix debug info IR error on LLVM < 13 2024-06-04 14:41:42 +02:00
Colin Davidson 52ba3357ee oops, missed shuffling a few x-funcs 2024-06-04 04:48:24 -07:00
Jeroen van Rijn 78a67ef31e Merge pull request #3667 from Feoramund/fix-fmt-compquat-sign
Fix printing of duplicate signs in complex and quaternion types
2024-06-04 13:32:13 +02:00
Jeroen van Rijn f9d59ef6d4 Merge branch 'master' into fix-fmt-compquat-sign 2024-06-04 13:25:57 +02:00
Jeroen van Rijn c3b94b9e1d Merge pull request #3646 from Feoramund/multi-test
Refactor the test runner
2024-06-04 13:23:52 +02:00
Jeroen van Rijn 02f11dfded Merge branch 'master' of github.com:odin-lang/Odin 2024-06-04 11:27:01 +02:00
Jeroen van Rijn 303d86ab7e Complete nightly scripts update to new b2 cli version 2024-06-04 11:26:57 +02:00
Jeroen van Rijn 50374d9396 Merge pull request #3640 from harold-b/fix-darwin-libc-open
Fix open() foreign libc signature on Darwin
2024-06-04 10:54:08 +02:00
Jeroen van Rijn dfffc57536 Merge pull request #3668 from colrdavidson/x11-tweaks
add a few more x11 funcs, fix egl bug
2024-06-04 10:53:57 +02:00
Colin Davidson e46e22e21b add a few more x11 funcs, fix egl bug 2024-06-04 01:12:10 -07:00
Feoramund eb93779f63 Fix duplicate sign printing of complex and quaternion types
Negative zero wasn't being detected (so it would appear as `+-0`), and
`+Inf` was appearing as `++Inf` when imaginary.
2024-06-03 19:51:17 -04:00
Feoramund d2a9122176 Add fmt tests for printing complex and quaternion types 2024-06-03 19:48:09 -04:00
Jeroen van Rijn 36627d7d29 Merge pull request #3666 from Feoramund/add-missing-compquat
Add missing `Raw_*` complex and quaternion types
2024-06-04 01:28:18 +02:00
Jeroen van Rijn f745a1c470 b2 uri 2024-06-04 00:22:49 +02:00
gingerBill 17225131f7 Try / rather than 2024-06-03 23:12:24 +01:00
gingerBill c8f9af64db Add print to delete_old_binaries.py 2024-06-03 23:01:39 +01:00
gingerBill 0ef0894213 Fix to bl.tok = path 2024-06-03 22:55:24 +01:00
gingerBill dc6a8e5ffb Fix typo 2024-06-03 22:44:12 +01:00
gingerBill 5b5106baee Try updating nightly stuff 2024-06-03 22:36:54 +01:00
gingerBill 4dac577caa Add attributes to Foreign_Import_Decl in clone 2024-06-03 22:21:54 +01:00
gingerBill 8e9716ea2f Add ast.Foreign_Import_Decl to ast.clone 2024-06-03 22:20:39 +01:00
Feoramund d7f6def8ad Add aliases for Raw_* complex/quaternion types into core:mem 2024-06-03 17:18:27 -04:00
gingerBill 50b4a63fe1 Add ast.Foreign_Impot_Decl.fullpaths to walk.odin 2024-06-03 22:02:35 +01:00
Jeroen van Rijn 2cb3028086 Merge pull request #3664 from reduf/fix-signatures-of-some-functions
Fix signatures of two Win32 functions
2024-06-03 22:06:07 +02:00
Feoramund 88598c2c64 Make use of runtime.Raw_* types in core:math/linalg 2024-06-03 15:58:33 -04:00
Feoramund 97f1d12e04 Add missing Raw_* types for complex and quaternion 2024-06-03 15:41:14 -04:00
Feoramund 4e1dd4ced2 Move Raw_Complex/Quaternion types to base:runtime 2024-06-03 15:40:28 -04:00
Laurent Dufresne 1617060f46 Fix type of two Win32 functions 2024-06-03 20:41:31 +02:00
Feoramund 0ff130d82b Fix ad hoc printf in test runner signal handler 2024-06-02 23:36:04 -04:00
Feoramund fa29974dab Use Warning log level for reporting memory leaks
Works well with `-define:ODIN_TEST_LOG_LEVEL=warning`.
2024-06-02 23:21:44 -04:00
Feoramund 7764ab2ab0 Prevent test runner deadlock on NetBSD
Add `pthread_testcancel` to `core:sys/unix`
2024-06-02 21:27:36 -04:00
Feoramund 6a5633df2d Fix wrong PTHREAD_CANCEL_ASYNCHRONOUS on FreeBSD and OpenBSD
The test runner was deadlocking when a test raised a signal on FreeBSD.

This is untested on OpenBSD, but I have referenced this file:
https://github.com/openbsd/src/blob/master/include/pthread.h
2024-06-02 20:41:25 -04:00
Feoramund c8539fe411 Revert "Disable NetBSD tests until 'undefined reference to stdout' is solved."
This reverts commit 21a1ddfbae.
2024-06-02 19:29:27 -04:00
Feoramund ac9484206b Fix STDIN, STDOUT, STDERR handles for BSDs
Tested on FreeBSD 14.0 and NetBSD 10.0

OpenBSD is untested, but link names were sourced from:
https://github.com/openbsd/src/blob/master/include/stdio.h

According to this, OpenBSD shares the same layout as NetBSD.

FreeBSD has the same as Darwin in this regard.
2024-06-02 19:29:27 -04:00
Jeroen van Rijn 10d354aea8 Merge pull request #3662 from Feoramund/fix-3660
Fix #3660 and #3661
2024-06-02 23:22:16 +02:00
Feoramund f030603f0d Fix #3660
This also prevents a segfault if you do `odin build .odin -file`
2024-06-02 16:47:46 -04:00
Feoramund f77ce359ce Be pedantic about not overwriting Odin errors
I was encountering bounds-check error messages being overwritten during
a test, if the test failed for another reason and sent a log message.

The original intent of having this check inside of the above `if` block
was that if a test sent an error message, then it was assumed an
overwrite would be safe, but it's completely possible for a test to fail
for a legitimate reason, then do an unrelated bounds check somewhere
else that would be buried under the animation.

This change will make sure that, no matter what, the progress display
will not trigger a clear if a signal was raised. There's still no
guarantee that bounds-check messages will be printed properly, and it's
best to redirect STDERR.

The only way that can be fixed is if they get a similar hook to
`context.assertion_failure_proc`.
2024-06-02 15:51:26 -04:00
Feoramund 3f1249c27e Tell user about ODIN_TEST_RANDOM_SEED option 2024-06-02 15:34:13 -04:00
Feoramund 8d8c42e962 Use T.seed in tests where applicable 2024-06-02 15:30:23 -04:00
Jeroen van Rijn 60d0c03134 Strip old test runner back out of internal, issues and vendor 2024-06-02 21:15:25 +02:00
Jeroen van Rijn 9d8d864400 Plug leak in AES tests. 2024-06-02 21:12:24 +02:00
Jeroen van Rijn 21a1ddfbae Disable NetBSD tests until 'undefined reference to stdout' is solved. 2024-06-02 21:03:22 +02:00
Feoramund 890fe07c6e Disable FANCY_OUTPUT in Odin test scripts
This should tidy up the CI output logs a bit.
2024-06-02 14:54:32 -04:00
Feoramund d581dbbec5 Keep test runner main thread from using 100% of a CPU core 2024-06-02 14:54:32 -04:00
Feoramund 5e3e958574 Add -define:ODIN_TEST_LOG_LEVEL to set lowest log level 2024-06-02 14:54:32 -04:00
Feoramund 6a9203328b Log thread count at test run start
Provides a helpful info message about the option to change how many
threads are used per run.
2024-06-02 14:54:32 -04:00
Feoramund 5db65aa796 Make it easier to learn about ODIN_TEST_CLIPBOARD 2024-06-02 14:54:32 -04:00
Feoramund cb00b8022b Add note about SIGSEGV edge case on UNIX-likes 2024-06-02 14:54:32 -04:00
Feoramund 4875f745c8 Remove Windows test runner in favor of libc implementation 2024-06-02 14:54:32 -04:00
Feoramund ccdbd4b6ce Simplify casts in mem.Rollback_Stack procs 2024-06-02 14:54:32 -04:00
Feoramund 9dcf345795 Set thread pool is_running to false on shutdown 2024-06-02 14:54:32 -04:00
Feoramund 21064fbb60 Clear thread pool task data on restart 2024-06-02 14:54:32 -04:00
Feoramund 45fa9d8148 Expand documentation comment for ODIN_TEST_NAMES 2024-06-02 14:54:32 -04:00
Feoramund cb8faf5b74 Remove -test-name in favor of test runner option
`-define:ODIN_TEST_NAMES=...` is capable of selecting test by package
and name or name only, with the ability to access packages included by
`-all-packages`.
2024-06-02 14:54:32 -04:00
Feoramund 6a5d51f0d6 Use more concise way of satisfying -vet 2024-06-02 14:54:31 -04:00
Feoramund 433ca538bf Be specific about platforms not implementing test runner signal handler 2024-06-02 14:54:31 -04:00
Feoramund d1723664a7 Catch SIGILL, SIGFPE, SIGSEGV in the test runner 2024-06-02 14:54:31 -04:00
Feoramund fb37572c4c Rename signal_handler.odin to signal_handler_libc.odin 2024-06-02 14:54:31 -04:00
Jeroen van Rijn 6050bc3bf6 Add missing benchmarks build.bat. 2024-06-02 14:54:31 -04:00
Jeroen van Rijn 306169699c Update ci.yml 2024-06-02 14:54:31 -04:00
Jeroen van Rijn 3354212f8e Update ci.yml
Disable benchmark on Windows for a moment.
2024-06-02 14:54:31 -04:00
Jeroen van Rijn 54dae06ad1 Update CI 2024-06-02 14:54:31 -04:00
Jeroen van Rijn 8d93379e29 Factor benchmarks out into tests\benchmark\<pkg> 2024-06-02 14:54:29 -04:00
Jeroen van Rijn 62b7d8de97 Port tests\core\net 2024-06-02 14:47:09 -04:00
Jeroen van Rijn dacb0f7786 Port tests\core\thread 2024-06-02 14:47:09 -04:00
Jeroen van Rijn 5b1ffba915 Port testing\core\time 2024-06-02 14:47:09 -04:00
Jeroen van Rijn a406ff7063 Port tests\core\strings 2024-06-02 14:47:09 -04:00
Jeroen van Rijn 9ba02e888d Port tests\core\slice 2024-06-02 14:47:09 -04:00
Jeroen van Rijn ed0384c102 Port tests\core\runtime 2024-06-02 14:47:09 -04:00
Jeroen van Rijn 80b115748f Port tests\core\reflect 2024-06-02 14:47:09 -04:00
Jeroen van Rijn 9829a02571 Port tests\core\odin 2024-06-02 14:47:09 -04:00
Jeroen van Rijn 8383a45b62 Port tests\core\text\match 2024-06-02 14:47:09 -04:00
Jeroen van Rijn b0faab29e0 Port tests\core\math, math\linalg\glsl and math\noise 2024-06-02 14:47:09 -04:00
Jeroen van Rijn d7bfbe0552 Port testing\core\text\i18n 2024-06-02 14:47:08 -04:00
Jeroen van Rijn 39fd73fe17 Port testing\core\hash 2024-06-02 14:47:08 -04:00
Jeroen van Rijn 6f7c5a7577 Port tests\core\fmt 2024-06-02 14:47:08 -04:00
Jeroen van Rijn d334b8c72a Port tests\core\path\filepath 2024-06-02 14:47:08 -04:00
Jeroen van Rijn 9d0f4833bf Port tests\core\encoding\xml
Made them run in parallel as well.
2024-06-02 14:47:08 -04:00
Jeroen van Rijn 6641a6f6c9 Port tests\core\encoding\varint 2024-06-02 14:47:08 -04:00
Jeroen van Rijn 601df0e8f7 Port tests\core\encoding\json 2024-06-02 14:47:08 -04:00
Jeroen van Rijn 1b32e27aa4 Port tests\core\encoding\hxa
And fix a few leaks in `core:encoding/hxa` while at it.
2024-06-02 14:47:08 -04:00
Jeroen van Rijn 3404dea8ac Port tests\encoding\hex 2024-06-02 14:47:08 -04:00
Jeroen van Rijn 40b20fb473 Port tests\core\c\libc 2024-06-02 14:47:08 -04:00
Feoramund b74b956fda Remove unneeded import 2024-06-02 14:47:08 -04:00
Feoramund 1f6a6f2cd3 Support deterministic random seeding of tests
Add a new option `ODIN_TEST_RANDOM_SEED` which is picked from the cycle
counter at startup, if it's not specified by the user.

This number is sent to every test in the `T` struct and reset every test
(just in case).
2024-06-02 14:47:07 -04:00
Jeroen van Rijn a27b167218 Update tests\core\encoding\cbor to use new test runner.
It was leaky and required a substantial number of `loc := #caller_location` additions to parts of the core library to make it easier to track down how and where it leaked.

The tests now run fine multi-threaded.
2024-06-02 14:47:07 -04:00
Jeroen van Rijn 6a1649d8aa Update using new defaults for memory + reporting width 2024-06-02 14:47:07 -04:00
Feoramund 84ad71fdb3 Support ODIN_TEST_PROGRESS_WIDTH=0
This will automatically calculate how wide the progress bars should be
based on the package with the greatest number of tests.

The progress width is now capped to 100.
2024-06-02 14:47:07 -04:00
Feoramund 49fa66370f Report test memory usage only if there's an issue
Adds new option `ODIN_TEST_ALWAYS_REPORT_MEMORY`, for when you always
want to see the memory usage report.
2024-06-02 14:47:07 -04:00
Feoramund e1a3c0e21d Track memory in the test runner by default 2024-06-02 14:47:07 -04:00
Feoramund bf42e39b1c Be specific about int size for Rollback_Stack asserts
This should fix tests failing on 32-bit platforms.
2024-06-02 14:47:07 -04:00
Jeroen van Rijn c531427ee5 Update -define for crypto 2024-06-02 14:47:07 -04:00
Feoramund b7e1ae7073 Change test runner options to SCREAMING_SNAKE_CASE
This commit also changes the name of `test_select` to `ODIN_TEST_NAMES`,
to better conform with the already-existing `-test-name:<name>` option.
2024-06-02 14:47:07 -04:00
Feoramund e11f3d2520 Fix missing - for define in tests/core/build.bat 2024-06-02 14:47:07 -04:00
Feoramund dcfda195d2 Send terminal control code to STDOUT instead
`STDERR` might be redirected, and this code signals to the terminal to
show the cursor again. Otherwise, the cursor will be invisible.
2024-06-02 14:47:07 -04:00
Feoramund a1c5bebac7 Fix ANSI redraw eating last log line 2024-06-02 14:47:07 -04:00
Feoramund 89d8df28be Combine multi-line attributes onto one line 2024-06-02 14:47:07 -04:00
Feoramund dffc3af86c Remove safe_heap_allocator from test runner
I was under the impression that the default `context.allocator` was not
thread-safe, but I've been told that this is not the case.
2024-06-02 14:47:06 -04:00
Feoramund eadfbb1318 Forbid singleton allocations from shrinking their block offset 2024-06-02 14:47:06 -04:00
Feoramund 1afc235359 Use plain sort for internal_tests 2024-06-02 14:47:06 -04:00
Feoramund 09ef08f035 Add more sanity checking to mem.Rollback_Stack 2024-06-02 14:47:06 -04:00
Feoramund 0f675fa436 Use uintptr where applicable in mem.Rollback_Stack 2024-06-02 14:47:06 -04:00
Feoramund 568b746c98 Fix indentation 2024-06-02 14:47:06 -04:00
Jeroen van Rijn a0b2ea6d6e Update tests\core\crypto 2024-06-02 14:46:59 -04:00
Jeroen van Rijn a463e282db Update core:container tests 2024-06-02 14:34:31 -04:00
Jeroen van Rijn e3181c13c6 Update core:compress tests 2024-06-02 14:34:31 -04:00
Jeroen van Rijn 22c092f846 Delete duplicated flag. 2024-06-02 14:34:31 -04:00
Jeroen van Rijn eb3d6d7d75 Update core:image tests to use new runner. 2024-06-02 14:34:31 -04:00
Feoramund 852f694bee Get tests passing again
`T` no longer has a writer assigned to it.

`test_core_cbor.odin` has global state and is run with `odin test`,
so I've set it to use only one thread.
2024-06-02 14:34:31 -04:00
Feoramund 87ea4a2652 Temporarily disable Windows-specific test runner
I do not have a Windows machine to test the refactored test runner, and
I am unsure if it would even run correctly on Windows without this
disabled.
2024-06-02 14:34:31 -04:00
Feoramund d03024088a Remove unneeded code 2024-06-02 14:34:31 -04:00
Feoramund b6c4dfb68d Refactor the test runner
Changes

- Support multi-threaded testing.
- Support `set_fail_timeout` on all platforms.
- Display an animated progress report.
- Setup all tests with a context logger.
- Give all tests their own separate custom allocators.
- Support tracking test memory usage.
- Display a summary of the failed tests at the end.
- Let users select only specific tests to run.
- Support copying failed tests to the clipboard to run again.
- Support catching SIGINT (CTRL-C) to cancel early.
- Record context in cleanup procs.
- Write all log messages to STDERR for easy redirection.
- Possibly more I've forgotten.

New Options

- `-define:test_threads=N`: Specify thread count.
- `-define:test_thread_memory=B`: Specify initial memory block size in bytes to each thread.
- `-define:test_track_memory=true`: Track the memory usage of individual tests.
- `-define:test_fancy=false`: Disable animated progress report.
- `-define:test_select=package.test_name,...`: Run only select tests.
- `-define:test_clipboard=true`: Copy names of failed tests to the clipboard.
- `-define:test_progress_width=24`: Change the width of the animated progress bars.
2024-06-02 14:34:31 -04:00
Feoramund 95c2e020ff Share libc signal definitions with more platforms
I confirmed that these 3 platforms share the same signal definitions
from these sources.

Haiku: https://github.com/haiku/haiku/blob/master/headers/posix/signal.h
OpenBSD: https://github.com/openbsd/src/blob/master/sys/sys/signal.h
NetBSD: http://fxr.watson.org/fxr/source/sys/signal.h?v=NETBSD
2024-06-02 14:34:30 -04:00
Feoramund 50dffaf131 Add mem.Rollback_Stack 2024-06-02 14:34:30 -04:00
Feoramund fc4f6b87bb Add core:encoding/ansi package 2024-06-02 14:34:30 -04:00
Feoramund 8137b9dd75 Add mem.tracking_allocator_reset 2024-06-02 14:34:30 -04:00
Feoramund 558c330028 Add task-stopping functionality to thread.Pool 2024-06-02 14:34:30 -04:00
Feoramund 1875e7c36a Make log.do_*_header argument orders consistent 2024-06-02 14:34:30 -04:00
Feoramund 7d4da6eaa7 Fix trailing space with only .Date log option 2024-06-02 14:34:30 -04:00
Feoramund 8ae375dbff Move log timestamping out to do_time_header proc 2024-06-02 14:34:30 -04:00
Jeroen van Rijn c07a46abc9 Merge pull request #3635 from Yawning/feature/aes
core/crypto: Add AES
2024-06-01 21:42:59 +02:00
Yawning Angel c751e4b2eb core/crypto/aes: Add AES implementation 2024-06-01 22:55:42 +09:00
Yawning Angel 1ade62b630 core/crypto/_aes/ct64: Add GHASH 2024-06-01 22:55:42 +09:00
Yawning Angel cba58924a8 core/crypto/_aes: 64-bit portable implementation 2024-06-01 22:55:42 +09:00
Yawning Angel f49575f1fb core/simd/x86: Add the AES-NI intrinsics 2024-06-01 22:55:42 +09:00
gingerBill 72a5e74ef3 Merge pull request #3658 from laytan/wasm64p32-runtime-fixes
wasm: fix runtime.js even more for wasm64p32
2024-05-31 23:17:52 +01:00
gingerBill 881340fd3b Merge pull request #3659 from thetarnav/unreachable
Add unreachable to base/builtin/builtin.odin
2024-05-31 23:17:08 +01:00
Damian Tarnawski 451dc645df Add unreachable to base/builtin/builtin.odin 2024-05-31 21:55:40 +02:00
Laytan Laats 8a521648b9 wasm: fix runtime.js even more for wasm64p32
- make the int size configurable in the `runWasm` call, no more
  constants to hunt down and change
- make storeU64 and storeI64 handle bigints, this is needed in the
  odin_dom library
- fix alignment issues within init_event_raw
2024-05-31 20:57:15 +02:00
gingerBill 5628cfabe5 Merge branch 'master' of https://github.com/odin-lang/Odin 2024-05-31 16:35:38 +01:00
gingerBill 31a9b3f428 core:encoding/ini 2024-05-31 16:35:30 +01:00
Jeroen van Rijn e12ff63b16 Merge pull request #3657 from laytan/fix-wasm64p32-procs
wasm: fix target wasm64p32 runtime procs
2024-05-31 17:03:52 +02:00
Laytan Laats 3a0ec3d6a8 wasm: fix target wasm64p32 runtime procs
LLVM generates calls with `i32` regardless of target, so if a call to
any of these procs was generated this failed to compile.

I opted to fix by changing from `int` to `i32` on wasm64p32 and adding
`#any_int` so existing code keeps working.
2024-05-31 16:32:27 +02:00
gingerBill ffded3d557 Merge pull request #3655 from iErik/master
core:sys/linux - Add support for Unix Domain Socket addresses
2024-05-31 10:32:19 +01:00
gingerBill ae63fd9230 Fix #3649 2024-05-30 23:08:42 +01:00
gingerBill 6d9957d7e4 Fix types again 2024-05-30 21:59:01 +01:00
gingerBill e737122ce8 Add experimental target orca_wasm32 2024-05-30 21:58:27 +01:00
gingerBill 8db87170a9 Clean up handle_link_name handling of link_suffix 2024-05-30 21:53:23 +01:00
gingerBill ba1e9c8abe Fix #3651 2024-05-30 21:50:30 +01:00
gingerBill 66acbb7fed Add @(link_suffix=<string>) 2024-05-30 21:48:23 +01:00
Erik Isidore 0514ee0410 PR#3655 - small linter issue correction 2024-05-30 16:12:20 -03:00
gingerBill 7bcf33c881 Merge pull request #3656 from laytan/microui-optional-clipboard
microui: make clipboard optional during init
2024-05-30 17:37:35 +01:00
Laytan Laats 6bbe7d88b8 microui: make clipboard optional during init
Clipboard is an optional addition to the microui functionality, but the
init function makes it look like it is required. Additionally, a bunch of
the examples both on the Odin-Lang/examples repo and others are now
"broken".
2024-05-30 16:19:33 +02:00
gingerBill 7058d6f320 Merge pull request #3652 from Dudejoe870/compile-time-hash
Add #hash built-in directive for compile-time string hashing
2024-05-30 11:30:26 +01:00
gingerBill f86bb11f84 Merge pull request #3653 from laytan/fix-wheel-event-js-wsam
wasm: fix the WheelEvent not storing data properly
2024-05-30 11:13:44 +01:00
gingerBill 5391605961 Merge pull request #3654 from laytan/darwin-fix-sdkpath
darwin: fix sysroot retrieval for some systems
2024-05-30 11:13:32 +01:00
Erik Isidore f6e699cd22 core:sys/linux - Add support for Unix Domain Socket addresses 2024-05-30 00:14:00 -03:00
Laytan Laats eeb057b76d darwin: fix sysroot retrieval for some systems
Got a report on Discord that the current way didn't work for a user,
this change did work and I confirmed with @harold-b (who initially added
this) that it also works for them and is actually a better way.
2024-05-30 01:53:38 +02:00
Laytan Laats 692ca13ffd wasm: fix the WheelEvent not storing data properly
A `WheelEvent` is also an instanceof `MouseEvent` so it was never
hitting the if statement for the `WheelEvent`.
2024-05-30 01:49:30 +02:00
Dudejoe870 9b78061c8f Initial hash directive implementation 2024-05-28 22:42:10 -05:00
gingerBill ba8672ad29 Merge pull request #3650 from yay/destroy-multi-logger-no-pointer
Take logger itself, not a pointer to logger in multi-logger destructor.
2024-05-29 00:49:02 +01:00
Vitalii Kravchenko 223c987db2 Take logger itself, not a pointer to logger in multi-logger destructor. 2024-05-28 21:13:25 +01:00
gingerBill 74524b6050 Merge pull request #3644 from odin-lang/foreign-import-improvements
Allow `foreign import` import paths to be evaluated in the semantic phase rather than parsing
2024-05-28 12:18:15 +01:00
Jeroen van Rijn 23852c16be Merge pull request #3647 from Feoramund/fix-core-data-comments
Make `ODIN_OS`, `ODIN_BUILD_MODE` comments congruent to underlying data
2024-05-28 09:14:44 +02:00
Jeroen van Rijn 4c6b824658 Merge pull request #3648 from Feoramund/rem-unused-prime-code
Remove unused code in `internal_random_prime`
2024-05-28 08:55:04 +02:00
Feoramund 01ad69413a Remove unused code in internal_random_prime 2024-05-28 01:36:44 -04:00
Feoramund fa6e07d976 Make ODIN_OS, ODIN_BUILD_MODE comments congruent to underlying data
Sourced from `src/checker.cpp`.
2024-05-28 01:32:20 -04:00
gingerBill d91054b615 Change parser to use ^Expr rather than string for the foreign import paths 2024-05-28 00:27:13 +01:00
gingerBill a1b8749e74 Delay checking foreign import paths until after global scope is checked 2024-05-28 00:23:23 +01:00
gingerBill 38fffff06a Begin moving foreign import import paths to be evaluated in the semantic phase rather than parsing. 2024-05-27 23:51:43 +01:00
korvahkh a7a6ff8c69 encoding/json: Fix struct marshal() emitting comma after omitted field
Previously:
```odin
package main

import "core:fmt"
import "core:encoding/json"

T :: struct {
	a: string `json:",omitempty"`,
	b: string,
}

main :: proc() {
	data, _ := json.marshal(T{b = "foo"})
	fmt.println(string(data))
}
```
would output:
```
{,"b":"foo"}
```

which is not correct.

Also cleaned up some whitespace while I'm at it.
2024-05-27 16:59:46 -05:00
gingerBill 74ac2667e7 Merge pull request #3642 from 2nafish117/fix-pitch-from-quat
Fix pitch_from_quaternion
2024-05-27 22:24:46 +01:00
shashank fb6248925a fix pitch_from_quaternion 2024-05-27 23:38:50 +05:30
Harold Brenes 2ecf909be0 Fix open() foreign libc signature on Darwin 2024-05-27 11:55:58 -04:00
Jeroen van Rijn 75f1215ed2 Merge pull request #3639 from yay/destroy-file-logger-no-pointer
Make destroy_file_logger take logger instead of logger pointer.
2024-05-27 17:25:59 +02:00
Vitalii Kravchenko bdc4daca54 Make destroy_file_logger take logger instead of logger pointer. 2024-05-27 16:19:44 +01:00
gingerBill 6d163cee8a Merge pull request #3638 from harold-b/fix-darwin-libc-proc-sigs
Fix a few darwin libc signatures with incorrect parameters.
2024-05-27 02:06:50 +01:00
Harold Brenes cfd4fc835b Fix a few darwin libc signatures with incorrect parameters. 2024-05-26 19:40:08 -04:00
gingerBill 8421950546 Merge pull request #3637 from laytan/revert-clang++-detection
revert `$(llvm-config --bindir)/clang++` to get the cpp compiler
2024-05-26 19:16:32 +01:00
Laytan Laats 5027cfb618 revert $(llvm-config --bindir)/clang++ to get the cpp compiler
A few reports of either people not having this clang++ or having it but
it not finding system headers. On top of that, the reason we added this
in the first place was a bug that surfaced on clang-18 which we've since
fixed.

Order will now be clang++ from path, then the llvm bindir clang++, then an
error.

This can all still be overwritten with `CXX=blah make` like before.
2024-05-26 20:11:07 +02:00
gingerBill 149ae70be1 Merge branch 'master' of https://github.com/odin-lang/Odin 2024-05-26 12:17:09 +01:00
gingerBill 64bdb3a097 Fix #3630 (first part) 2024-05-26 12:17:03 +01:00
gingerBill ef7a155f9a Merge pull request #3633 from korvahkh/fix-slice-has-affix
Fix slice.has_prefix & slice.has_suffix
2024-05-25 21:48:31 +01:00
korvahkh 58ae96c821 Fix slice.has_prefix & slice.has_suffix
The needle was the element type instead of the slice type.
2024-05-25 15:52:35 -05:00
Jeroen van Rijn cfadca04f9 Merge pull request #3628 from IllusionMan1212/bitset-json-marshalling-fix
fix(core/encoding/json): remove Unsupported_Type return when marshalling bit_set
2024-05-25 08:34:59 +02:00
IllusionMan1212 65a4a56a83 fix(core/encoding/json): remove Unsupported_Type return when marshalling bit_set 2024-05-25 00:45:30 +02:00
Jeroen van Rijn fb22c59d1b Merge pull request #3625 from Kelimion/iso8061
Add dedicated ISO 8601 parser.
2024-05-24 23:56:20 +02:00
Jeroen van Rijn b945e3e708 Limit to max of 9 fraction second digits, part deux. 2024-05-24 23:48:18 +02:00
Jeroen van Rijn 1473374bba Limit to max of 9 fraction second digits. 2024-05-24 23:45:46 +02:00
Jeroen van Rijn 3526042f1e Add dedicated ISO 8601 parser. 2024-05-24 23:40:14 +02:00
Jeroen van Rijn e1c4b9b06a Allow lowercase z TZ indicator. 2024-05-24 19:16:24 +02:00
Jeroen van Rijn ff34970d79 Merge pull request #3623 from yay/allow-space-in-rfc-3339
Allow space (in addition to T and t) as RFC 3339 date/time separator.
2024-05-24 19:10:04 +02:00
Vitalii Kravchenko ff94ca9e42 Allow space (in addition to T and t) as RFC 3339 date/time separator. 2024-05-24 18:03:52 +01:00
gingerBill 590db0838a Fix types 2024-05-24 17:21:00 +01:00
Jeroen van Rijn d698d4cdae Merge pull request #3621 from laytan/enable-default-temp-allocator-wasm
wasm: enable default temp allocator
2024-05-24 15:42:51 +02:00
Jeroen van Rijn d99e1616cf Merge pull request #3620 from Kelimion/deprecate_odin_printer
Deprecate `core:odin/printer` in favor of OLS.
2024-05-24 15:02:59 +02:00
Laytan Laats aa72050586 wasm: enable default temp allocator
After #3592 I think it makes sense to also enable the temp allocator by default
2024-05-24 15:01:02 +02:00
Jeroen van Rijn b7cecc5762 Keep -vet happy. 2024-05-24 14:57:48 +02:00
Jeroen van Rijn 5c06480ce0 Add core:container/rbtree to examples/all 2024-05-24 14:55:21 +02:00
Jeroen van Rijn dc744411c5 Deprecate core:odin/printer + format in favor of OLS. 2024-05-24 14:49:11 +02:00
Jeroen van Rijn e2af3652c5 Merge pull request #3619 from Kelimion/csv_iterator
Add iterator_next(&r) to CSV.
2024-05-24 14:06:42 +02:00
Jeroen van Rijn 479d301e92 Merge pull request #3614 from Kelimion/rbtree
Add `core:container/rbtree`
2024-05-24 14:04:56 +02:00
Jeroen van Rijn 11e57fd3fd Address concerns. 2024-05-24 13:58:30 +02:00
tim4242 0cba33075f Add the option to export dependencies as JSON. 2024-05-24 13:44:38 +02:00
Jeroen van Rijn 2a4ddbb7be Remove core:mem import in example. 2024-05-24 13:35:32 +02:00
Jeroen van Rijn 3b739dc5cc Add iterator_next(&r) to CSV. 2024-05-24 13:26:12 +02:00
gingerBill 0658778a30 Merge pull request #3611 from hstormo/textbox
vendor/microui: nicer textbox
2024-05-24 11:51:09 +01:00
gingerBill 1081e9ac09 Fix enum definition for bit_set use 2024-05-24 11:41:56 +01:00
Jeroen van Rijn c43d189a33 Fix package line. 2024-05-24 01:43:17 +02:00
tim4242 8664b88c8f Improved depdendency formatting to support paths containing spaces 2024-05-24 01:20:45 +02:00
tim4242 7934e92d14 Initial dependency file generation 2024-05-24 01:04:41 +02:00
Håkon Stormo 4328562e2c Satisfy -vet 2024-05-23 23:50:26 +02:00
Håkon Stormo ee79c409b4 microui: use the text_edit procs 2024-05-23 23:28:58 +02:00
Håkon Stormo d3bbe29faa text_edit: better handle failure to resize underlying buffer 2024-05-23 23:28:39 +02:00
Jeroen van Rijn 410876b36a Add core:container/rbtree
Add a red-black tree with configurable $Key and $Value.
Also includes tests that verify it maintains RB invariants, doesn't leak.

Originally based on the CC0 implementation from literateprograms.org.
But reworked to the same API used by @Yawning's excellent `core:container/avl` for ease of use.
2024-05-23 23:00:00 +02:00
Håkon Stormo f411fcedb0 microui: textbox cut/copy/paste 2024-05-23 21:38:37 +02:00
Håkon Stormo 043ddd83a9 microui: textbox selection 2024-05-23 21:36:31 +02:00
gingerBill 7dc1f114b9 Add shadow suggestion 2024-05-22 22:22:41 +01:00
gingerBill f3f08c264f Be very particular with the cases for the error notes 2024-05-22 21:55:48 +01:00
gingerBill 2f35ee9671 Improve errors a lot for assigning procedures of the wrong signature 2024-05-22 21:52:15 +01:00
gingerBill 856537f0ce Fix #3603 2024-05-20 15:54:53 +01:00
gingerBill bc706f8b0c Fix indexing type when using a #row_major matrix 2024-05-20 15:04:15 +01:00
gingerBill a68c635c00 Remove constant indexing for matrix value propagation 2024-05-20 15:00:43 +01:00
gingerBill f600562ca5 Improve fmt parsing of struct field tags 2024-05-20 14:45:49 +01:00
gingerBill 5ed93563a1 Merge pull request #3606 from Kelimion/fmtfix
Fix the way '%32b' and other prefixed numbers are written.
2024-05-20 14:29:50 +01:00
gingerBill c49a291347 Merge pull request #3607 from Szwagi/fix-atomic-memory-order
Fix Odin to LLVM memory order mapping for .Relaxed and .Consume
2024-05-20 14:29:06 +01:00
Kamil T f6ef395057 Fix Odin to LLVM memory order mapping for .Relaxed and .Consume 2024-05-20 13:57:08 +01:00
Jeroen van Rijn e0d3d68ce5 Fix the way '%32b' and other prefixed numbers are written. 2024-05-20 14:42:13 +02:00
gingerBill 46b3e7b6fa Fix for &v in &fixed_array 2024-05-20 13:36:32 +01:00
gingerBill a80011c830 Merge branch 'master' of https://github.com/odin-lang/Odin 2024-05-20 13:32:22 +01:00
gingerBill 542c3d7561 Improve "Expected a type" syntax error 2024-05-20 13:32:16 +01:00
gingerBill f641399870 Merge pull request #3604 from matias-eduardo/master
remove extra newline in enumerated array hash fmt
2024-05-20 10:52:41 +01:00
gingerBill 891fefe117 Merge pull request #3592 from laytan/wasm-gpa
add a default heap/general purpose allocator for wasm to `base:runtime`
2024-05-20 10:38:09 +01:00
gingerBill 5473758467 Add intrinsics type_is_matrix_row_major & type_is_matrix_column_major 2024-05-20 10:15:21 +01:00
gingerBill 8eb7fe1859 Merge pull request #3482 from andreas-jonsson/netbsd-ci
NetBSD CI setup
2024-05-20 10:03:32 +01:00
gingerBill 8dec4f6ed3 Merge pull request #3570 from jasonKercher/linux-arm32
Get the compiler to build and work on arm32 Linux
2024-05-20 00:05:57 +01:00
gingerBill b6d5be8593 Merge pull request #3593 from harold-b/fix-build-sysroot-macos
Attempt to automatically resolve the sysroot on build_odin.sh on macOS
2024-05-19 23:59:44 +01:00
gingerBill 1207d64c64 Fix intrinsics.ptr_sub 2024-05-19 23:55:45 +01:00
Matias Fernandez a9629679ed remove extra newline in enumerated array hash fmt 2024-05-18 23:24:05 -04:00
Jeroen van Rijn c091b0d060 Merge pull request #3602 from Kelimion/qoifix
Apply fix to QOI decoder as well.
2024-05-18 19:48:37 +02:00
Jeroen van Rijn 58a1bb32e5 Apply fix to QOI decoder as well. 2024-05-18 19:41:07 +02:00
Jeroen van Rijn 5b92425e93 Merge pull request #3601 from Kelimion/qoifix
Fix qoi encoding bug.
2024-05-18 14:06:25 +02:00
Jeroen van Rijn 7955f4ddf1 Fix qoi encode bug. 2024-05-18 13:59:50 +02:00
gingerBill 98f8624447 Merge pull request #3594 from laytan/runtime-wasm64p32-fixes
correctly load/store uint&int in the runtime.js for wasm64p32
2024-05-17 17:32:36 +01:00
Laytan Laats e08b51ed73 correctly load/store uint&int in the runtime.js for wasm64p32 2024-05-17 16:32:34 +02:00
Jeroen van Rijn cf10c6d993 Merge pull request #3598 from Kelimion/i18n-fix
i18n: Add section merge + duplicate key detection to gettext.
2024-05-17 15:57:17 +02:00
Jeroen van Rijn f8c4ee3d3c i18n: Add section merge + duplicate key detection to gettext. 2024-05-17 15:50:37 +02:00
Jeroen van Rijn 419641ad8f Merge pull request #3596 from Kelimion/i18n-fix
Fix .mo contexts
2024-05-17 14:26:57 +02:00
Jeroen van Rijn 6139da3d41 Fix .mo contexts
Fixes #3590

- `get("key")`
- `get("context", "key")`
2024-05-17 14:15:56 +02:00
Jeroen van Rijn b51eb53d04 Merge pull request #3595 from Kelimion/i18n-fix
Fix .mo parser: Number of plurals
2024-05-17 12:15:40 +02:00
Jeroen van Rijn 5a76b3c7c5 Fix .mo parser: Number of plurals
Fixes #3591

Added plur.mo to tests
2024-05-17 12:00:20 +02:00
Harold Brenes f1b291ed62 Attempt to automatically resolve the sysroot on build_odin.sh on macOS 2024-05-16 17:53:41 -04:00
Laytan Laats f42b1c4973 add a default heap/general purpose allocator for wasm to base:runtime 2024-05-16 23:08:40 +02:00
gingerBill ab8e3db7e9 Remove bad code 2024-05-16 17:18:37 +01:00
gingerBill 575b268e88 Fix more #soa changes 2024-05-16 17:15:38 +01:00
gingerBill 7cf62f00c3 Correct #soa RTTI usage 2024-05-16 16:30:45 +01:00
gingerBill c9b1c99a40 Fix soa_zip and soa_unzip 2024-05-16 16:27:09 +01:00
gingerBill 32245e93a1 Fix #3514 along with soa.a[i] bounds checking 2024-05-16 16:18:21 +01:00
gingerBill 330d6117e3 Fix #3589 2024-05-16 15:43:08 +01:00
gingerBill b2dc5cc812 Fix error reporting for enforce new switch/for syntax 2024-05-16 15:32:15 +01:00
gingerBill a344bc4c0e Remove the old switch/for semantics entirely and enforce switch &x in y 2024-05-16 14:39:16 +01:00
gingerBill e71cd871c4 Reimplement -build-mode:static/-build-mode:lib 2024-05-16 14:27:05 +01:00
Andreas T Jonsson a93bbf6f92 Merge branch 'master' into netbsd-ci 2024-05-16 13:48:44 +02:00
gingerBill f9fd8f0c25 Merge pull request #3439 from andreas-jonsson/netbsd
NetBSD support
2024-05-15 10:33:52 +01:00
gingerBill 59c33dd9fc Add Fstat_Callback for File.user_fstat 2024-05-14 18:57:03 +01:00
gingerBill 6f9dcb4e02 Add missing @(require_results) 2024-05-14 18:46:45 +01:00
gingerBill 2b43535961 Fix typo 2024-05-14 18:45:47 +01:00
gingerBill 61826594c9 Add comment state to prefer virtual.Arena over runtime.Arena 2024-05-14 18:37:23 +01:00
gingerBill 9a487ccb6f Delete dead code 2024-05-14 18:35:24 +01:00
gingerBill 453fc5182b Remove all uses of context stuff in os2 2024-05-14 18:34:05 +01:00
gingerBill 450b9ceaec Add @(require_results) everywhere in os2 2024-05-14 18:25:15 +01:00
gingerBill 48c1822709 Move utility stuff to internal_util.odin 2024-05-14 18:14:44 +01:00
gingerBill 91b7cdaad2 Mock out temp_file.odin stuff 2024-05-14 18:11:50 +01:00
gingerBill 361be301fa Use internal temp_allocator() 2024-05-14 17:24:37 +01:00
gingerBill ecd7846ec3 Clean up allocator stuff into allocators.odin 2024-05-14 17:10:53 +01:00
gingerBill e05315831f Fix #3586 2024-05-14 00:18:38 +01:00
gingerBill 7734b12f9a Fix #3587 2024-05-14 00:16:32 +01:00
gingerBill 20f8f9012d Attempt at fixing #3588 2024-05-14 00:11:57 +01:00
gingerBill 0cf9dcd314 Make .. ranges a complete error rather than a warning now.
This should have been an error years ago.
2024-05-13 18:15:29 +01:00
gingerBill 8fa20fb875 Extra check for field being nullptr 2024-05-13 14:44:53 +01:00
gingerBill 1b593fc1ca Correct core:intrinsics to base:intrinsics 2024-05-13 13:27:44 +01:00
gingerBill 215ef3d985 Make core:runtime etc a warning, and an error with -vet 2024-05-13 13:26:47 +01:00
gingerBill 8808e5584a If only warnings exist on print_all_errors, next time it is called, clear the error list.
This is mostly only syntax errors too
2024-05-13 13:26:22 +01:00
gingerBill 54ebfa6179 Fix hanging on thread.join for windows where the thread had not been started 2024-05-13 12:58:18 +01:00
gingerBill 4bdc8548bd Fix #3554 2024-05-13 12:55:49 +01:00
gingerBill 6dc0ee3877 Fix #3577 2024-05-13 12:54:01 +01:00
gingerBill 8d687a959d Fix #3516 2024-05-13 12:52:28 +01:00
gingerBill 8b4a8e4d80 Fix #3569 2024-05-13 12:49:12 +01:00
gingerBill 90f26368d9 Merge pull request #3572 from Feoramund/fix-unix-nonstart-thread-stall
Fix joining non-`Started` threads from blocking main thread
2024-05-13 12:45:02 +01:00
gingerBill e4ec7cc3f3 Merge pull request #3580 from Feoramund/suggest-test-all-packages
Suggest `-all-packages` flag when testing empty directory
2024-05-13 12:42:48 +01:00
gingerBill 34c8739b69 Fix #3578 2024-05-13 12:42:06 +01:00
gingerBill d1217340f5 Fix #3573 2024-05-13 12:26:01 +01:00
gingerBill 4eab735b13 Minor clean up of is_terminating code
This does not fix all known issues with it
2024-05-13 12:24:50 +01:00
gingerBill f8d235b6f5 Fix #3581 due to typo 2024-05-13 12:02:02 +01:00
gingerBill 7905f0533f Fix #3582 by disallowing it 2024-05-13 12:01:16 +01:00
gingerBill 3fb0d52a74 Fix #3585 2024-05-13 11:57:04 +01:00
gingerBill 07a538cd82 Merge branch 'master' of https://github.com/odin-lang/Odin 2024-05-13 11:54:05 +01:00
gingerBill facae34354 Fix #3584 2024-05-13 11:53:59 +01:00
Andreas T Jonsson 5541f60233 Check examples/all on NetBSD 2024-05-13 10:02:48 +02:00
Andreas T Jonsson bde8407ce8 Merge branch 'netbsd' into netbsd-ci 2024-05-13 10:01:12 +02:00
Andreas T Jonsson 6298d4a36c Fixed some build tags in vendor libs 2024-05-13 10:00:19 +02:00
Andreas T Jonsson 3e181af409 Merge branch 'netbsd' into netbsd-ci 2024-05-13 09:44:27 +02:00
Andreas T Jonsson 88528f7613 Updated makefiles to exclude some tests on BSDs 2024-05-13 09:41:54 +02:00
Andreas T Jonsson 5d82f0cad5 Merge branch 'master' into netbsd 2024-05-13 09:21:32 +02:00
Feoramund 971201182a Fix read_directory() skipping directories on UNIX-likes 2024-05-12 19:52:36 -04:00
Feoramund 1935811b2c Suggest -all-packages if testing empty directory 2024-05-12 19:51:19 -04:00
Jeroen van Rijn 1183f4794b Merge pull request #3579 from Kelimion/test_string_compare
Test string compare
2024-05-12 23:52:39 +02:00
Jeroen van Rijn 23545c3f37 Enable in Makefile 2024-05-12 23:47:42 +02:00
Jeroen van Rijn 41b8f06f51 Add 1 more each for < and > 2024-05-12 23:43:05 +02:00
Jeroen van Rijn 55d21f4c2f Test string compare
To avoid regression of the bug fixed in f8581537e4.
2024-05-12 23:38:17 +02:00
gingerBill f8581537e4 Fix >= for strings
How did this not get noticed?!?!
2024-05-12 20:25:13 +01:00
gingerBill 0f76c22c46 Check for illegal use of distinct 2024-05-12 17:48:06 +01:00
gingerBill 6bfaf4a093 Fix another oversight for bit_field endian with 1-byte types 2024-05-11 22:36:17 +01:00
gingerBill f650690f61 Merge pull request #3574 from jasonKercher/i386-syscall6
fix 6 argument syscall on i386
2024-05-11 21:50:49 +01:00
gingerBill 321e4c45b0 Merge pull request #3576 from korvahkh/json-marshal-no-nil
encoding/json: Properly marshal `#no_nil` unions
2024-05-11 21:50:26 +01:00
korvahkh 9b759f39fc encoding/json: Properly marshal #no_nil unions
Previously the first variant of a `#no_nil` would always be output as
`null`, and following variants would be treated as the wrong type.
2024-05-11 14:36:56 -05:00
Jeroen van Rijn 3a3ae6d0df Fix and re-enable .doc tests. 2024-05-11 19:25:35 +02:00
gingerBill ad0053b798 Make doc writer use the old "Ordered Insertion" based PtrMap 2024-05-11 16:24:37 +01:00
gingerBill 8e263de4aa Fix error message handling 2024-05-11 13:59:06 +01:00
gingerBill 811d53b305 Generalize to any 1-byte element in bit_field 2024-05-11 13:48:19 +01:00
gingerBill aea28d5189 Allow edge-case where backing type of a bit_field is (array of) u8, to allow any endian type 2024-05-11 13:47:33 +01:00
jason 20752d904b fix 6 argument syscall on i386 2024-05-10 23:06:49 -04:00
Feoramund 33c6f75a2e Fix joining non-Started threads from blocking main thread 2024-05-10 17:24:45 -04:00
jasonkercher 2183140e71 arm32 now compiles and runs demo 2024-05-10 13:24:43 -04:00
Andreas T Jonsson f428e30211 Minor code cleanup 2024-05-10 17:49:56 +02:00
Andreas T Jonsson a9b94f4019 Merge branch 'netbsd' into netbsd-ci 2024-05-10 13:34:02 +02:00
Andreas T Jonsson a45e69e656 Removed dead code 2024-05-10 09:12:56 +02:00
Andreas T Jonsson b72c2edabb Merge branch 'master' into netbsd 2024-05-10 09:04:52 +02:00
Andreas T Jonsson 273e4c6b4c Changed target data layout 2024-05-10 08:47:51 +02:00
Andreas T Jonsson f1491280ab Fixed invalid alignment 2024-05-10 08:16:10 +02:00
Andreas T Jonsson 1d3845abf5 Added prebuilt clang17 2024-05-02 16:52:46 +02:00
Andreas T Jonsson ecaa26710b Fixed invalid package name 2024-05-02 14:50:13 +02:00
Andreas T Jonsson 9de9223578 Use custom llvm binaries 2024-05-02 14:38:54 +02:00
Andreas T Jonsson 021271091a Merge branch 'netbsd' into netbsd-ci 2024-05-02 09:34:17 +02:00
Andreas T Jonsson 7feff1c113 Merged with master 2024-05-02 09:27:46 +02:00
Timo 2918baa3e8 Update builder.odin
Modify documentation-text for procedure write_f64 :

change type f32 to f64
2024-04-29 20:22:53 +02:00
Artsiom Babukh 805bb69c6c Fix typo in core_builtin 2024-04-28 15:27:34 +00:00
PucklaJ 37b026cb9b [sys/linux] Directly call syscall in execve on arm64 2024-04-28 12:00:40 +02:00
PucklaJ d1a205e2cf [sys/linux]: Remove clone syscall and call it directly in fork on arm64 2024-04-28 11:56:19 +02:00
PucklaJ 7f301790d0 [sys/linux] Change flags parameter of execveat to bit_set 2024-04-28 11:48:18 +02:00
PucklaJ b0fe6212bb [sys/linux]: Fix return statement 2024-04-27 13:21:04 +02:00
Andreas T Jonsson 6bbdbb4447 Added missing core:sys/info package for NetBSD 2024-04-26 11:04:27 +02:00
Andreas T Jonsson 22fa420c4f Should pass 0 as the rest of futex arguments 2024-04-25 22:22:59 +02:00
Andreas T Jonsson 9a008d10f3 Merge branch 'master' into netbsd 2024-04-25 22:04:40 +02:00
Andreas T Jonsson 3000508c02 Switched to native futex on NetBSD 2024-04-25 21:50:34 +02:00
Andreas T Jonsson c1ff7894df Should only run BSD tests 2024-04-25 13:47:55 +02:00
Andreas T Jonsson b6eaadb9a8 Fixed invalid git path 2024-04-25 13:31:33 +02:00
Andreas T Jonsson f53abf736b Print the path of the git safe directory 2024-04-25 13:25:46 +02:00
Andreas T Jonsson 4c9c0899a9 Added git safe directory config 2024-04-25 13:14:09 +02:00
Andreas T Jonsson 2b8836e29a Fixed broken export 2024-04-25 13:03:19 +02:00
Andreas T Jonsson 101abb3004 Simple CI setup for NetBSD 2024-04-25 12:46:55 +02:00
Andreas T Jonsson ce80c37c75 Fixed potential memory leak 2024-04-25 11:04:44 +02:00
Andreas T Jonsson 642391eb49 Implemented absolute_path_from_handle for NetBSD 2024-04-25 09:45:28 +02:00
Andreas T Jonsson 8ffe577a15 Added missing build tags in core 2024-04-25 09:43:54 +02:00
PucklaJ a2ad66cd9d [sys/linux]: Add clone syscall and use it in fork for arm64 2024-04-24 15:32:43 +02:00
PucklaJ 2bf00d9b3f [sys/linux]: Add flags parameter to execveat and fix execve on arm64 2024-04-24 15:15:38 +02:00
alec hodgkinson 3b632b4d90 Fixed typo in raylib documentation 2024-04-22 15:13:52 -07:00
Andreas T Jonsson 384137d4e9 Use PHYSMEM64 on NetBSD
I realize we should use PHYSMEM64 on NetBSD. So we can not share code with FreeBSD.
2024-04-22 10:15:52 +02:00
Andreas T Jonsson 1b15d8b453 Added build tag
Added build tag to rand_bsd.odin and fixed build warning.
2024-04-22 09:32:19 +02:00
Andreas T Jonsson 50cbb802b7 Fixed bug report information for NetBSD 2024-04-19 14:44:35 +02:00
Andreas T Jonsson a23c378513 Make the linter happy 2024-04-19 12:32:09 +02:00
Andreas T Jonsson dd95a8d11d More std lib fixes
Just selecting the same codepath as other BSD's for the most part.
2024-04-19 10:42:09 +02:00
Andreas T Jonsson 07fc07822d Added some libc bindings for NetBSD 2024-04-18 16:22:07 +02:00
Andreas T Jonsson 41d4dfbcd5 Fixed concurrency issue
Fixed broken thread policy causing deadlocks.
2024-04-18 16:20:49 +02:00
Andreas T Jonsson 38640d5d9e Updated core lib and did cleanup
Updated core with some path related functions and did some minor code cleanup.
Most of the standard library function is just a matter of copy what is there for the other BSDs.
2024-04-18 10:12:42 +02:00
Andreas T Jonsson 2055f2b933 Fixed link warnings
Hardlink libc functions to the correct version on NetBSD 10 since we do not use the micro-magic from C.
2024-04-17 09:46:57 +02:00
Andreas T Jonsson 80067a959b Added thread name
Call pthread_setname_np with the correct number of arguments on NetBSD.
2024-04-17 09:42:41 +02:00
Andreas T Jonsson 4558f3992a Initial commit of NetBSD port 2024-04-16 14:27:29 +02:00
Arseniy Poroshin 77a0e50298 fix comments in core:container/queue. 2024-03-26 22:39:43 +00:00
Beau McCartney 43e8da2e06 shm_open: comment with notes abt permissions 2024-03-19 09:36:49 -06:00
Beau McCartney 1758bd683e sys_shm_open: fchmod the returned descriptor to get correct perms
this doesn't happen by default
2024-03-16 12:13:00 -06:00
Eric Johnson 4b7f32c287 Update mem doc example formatting 2024-03-15 12:26:01 -07:00
Beau McCartney 24f9e16dfd sys_open() calls _sys_open_mode() to get a permission flags integer
_sys_open_mode() does exactly what sys_open() was originally doing
inline, I simply factored it into a separate function so that other
wrappers could call it (similar to _sys_permission_mode())
2024-03-15 08:32:25 -06:00
Beau McCartney 56a29685b4 darwin: sys_shm_open() helper
wraps syscall_shm_open() in the same way that sys_open() wraps
syscall_open()
2024-03-15 08:27:27 -06:00
Beau McCartney cf949e541f helper function to convert Open_Flags bitset to a u32
- analagous to _sys_permission_mode()
- uses the already-existing conversion logic in sys_open()
2024-03-15 08:26:25 -06:00
Beau McCartney 44167800ad darwin: syscall wrappers for shm_open() and shm_unlink() 2024-03-15 08:26:03 -06:00
marcs feh 9c6574e053 Merge branch 'odin-lang:master' into master 2024-02-11 23:55:39 +00:00
marcs feh fc113315f6 Merge branch 'odin-lang:master' into master 2024-02-02 21:56:40 -03:00
marcs-feh d931bfcf83 resolve conflict 2024-01-26 16:23:16 -03:00
marcs-feh b58627490b Adjust signture + Fix rebase conflict 2024-01-26 12:10:15 -03:00
marcs feh dbaa82b581 Merge branch 'odin-lang:master' into master 2024-01-24 20:10:44 -03:00
marcs-feh 84123cc879 sys/linux: Adjust ioctl signature to fit the actual Linux Kernel implementation 2024-01-24 13:40:50 -03:00
marcs-feh 7b1f58a06a sys/linux: Add binding to ioctl syscall + fd consts
Add binding to ioctl syscall, due to the vast nature of this syscall
adding more device specific request values is possible. Also added the
stdin, stdout and stderr, to constants.odin
2024-01-22 16:09:44 -03:00
jakubtomsu fe268a9dd2 Add nullptr check back 2023-11-25 13:29:28 +01:00
jakubtomsu 3c25d93eae Check for variadic param default val 2023-11-25 13:20:34 +01:00
1140 changed files with 140908 additions and 33121 deletions
+193 -132
View File
@@ -2,147 +2,162 @@ name: CI
on: [push, pull_request, workflow_dispatch]
jobs:
build_linux:
name: Ubuntu Build, Check, and Test
build_netbsd:
name: NetBSD Build, Check, and Test
runs-on: ubuntu-latest
env:
PKGSRC_BRANCH: 2024Q2
steps:
- uses: actions/checkout@v4
- name: Build, Check, and Test
timeout-minutes: 15
uses: vmactions/netbsd-vm@v1
with:
release: "10.0"
envs: PKGSRC_BRANCH
usesh: true
copyback: false
prepare: |
PKG_PATH="https://cdn.NetBSD.org/pub/pkgsrc/packages/NetBSD/amd64/$(uname -r | cut -d_ -f1)_${PKGSRC_BRANCH}/All" /usr/sbin/pkg_add pkgin
pkgin -y in gmake git bash python311 llvm clang
ln -s /usr/pkg/bin/python3.11 /usr/bin/python3
run: |
set -e -x
git config --global --add safe.directory $(pwd)
gmake release
./odin version
./odin report
gmake -C vendor/stb/src
gmake -C vendor/cgltf/src
gmake -C vendor/miniaudio/src
./odin check examples/all -vet -strict-style -disallow-do -target:netbsd_amd64
./odin check examples/all -vet -strict-style -disallow-do -target:netbsd_arm64
./odin test tests/core/normal.odin -file -all-packages -vet -strict-style -disallow-do -define:ODIN_TEST_FANCY=false -define:ODIN_TEST_FAIL_ON_BAD_MEMORY=true
./odin test tests/core/speed.odin -file -all-packages -vet -strict-style -disallow-do -o:speed -define:ODIN_TEST_FANCY=false -define:ODIN_TEST_FAIL_ON_BAD_MEMORY=true
./odin test tests/vendor -all-packages -vet -strict-style -disallow-do -define:ODIN_TEST_FANCY=false -define:ODIN_TEST_FAIL_ON_BAD_MEMORY=true
(cd tests/issues; ./run.sh)
./odin check tests/benchmark -vet -strict-style -no-entry-point
build_freebsd:
name: FreeBSD Build, Check, and Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Download LLVM
- uses: actions/checkout@v4
- name: Build, Check, and Test
timeout-minutes: 15
uses: vmactions/freebsd-vm@v1
with:
usesh: true
copyback: false
prepare: |
pkg install -y gmake git bash python3 libxml2 llvm17
run: |
# `set -e` is needed for test failures to register. https://github.com/vmactions/freebsd-vm/issues/72
set -e -x
git config --global --add safe.directory $(pwd)
gmake release
./odin version
./odin report
gmake -C vendor/stb/src
gmake -C vendor/cgltf/src
gmake -C vendor/miniaudio/src
./odin check examples/all -vet -strict-style -disallow-do -target:freebsd_amd64
./odin test tests/core/normal.odin -file -all-packages -vet -strict-style -disallow-do -define:ODIN_TEST_FANCY=false -define:ODIN_TEST_FAIL_ON_BAD_MEMORY=true
./odin test tests/core/speed.odin -file -all-packages -vet -strict-style -disallow-do -o:speed -define:ODIN_TEST_FANCY=false -define:ODIN_TEST_FAIL_ON_BAD_MEMORY=true
./odin test tests/vendor -all-packages -vet -strict-style -disallow-do -define:ODIN_TEST_FANCY=false -define:ODIN_TEST_FAIL_ON_BAD_MEMORY=true
(cd tests/issues; ./run.sh)
./odin check tests/benchmark -vet -strict-style -no-entry-point
ci:
strategy:
fail-fast: false
matrix:
# MacOS 13 runs on Intel, 14 runs on ARM
os: [ubuntu-latest, macos-13, macos-14]
runs-on: ${{ matrix.os }}
name: ${{ matrix.os == 'macos-14' && 'MacOS ARM' || (matrix.os == 'macos-13' && 'MacOS Intel' || 'Ubuntu') }} Build, Check, and Test
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- name: Download LLVM (Linux)
if: matrix.os == 'ubuntu-latest'
run: |
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 17
echo "/usr/lib/llvm-17/bin" >> $GITHUB_PATH
- name: build odin
run: ./build_odin.sh release
- name: Odin version
run: ./odin version
timeout-minutes: 1
- name: Odin report
run: ./odin report
timeout-minutes: 1
- name: Odin check
run: ./odin check examples/demo -vet
timeout-minutes: 10
- name: Odin run
run: ./odin run examples/demo
timeout-minutes: 10
- name: Odin run -debug
run: ./odin run examples/demo -debug
timeout-minutes: 10
- name: Odin check examples/all
run: ./odin check examples/all -strict-style
timeout-minutes: 10
- name: Core library tests
- name: Download LLVM (MacOS Intel)
if: matrix.os == 'macos-13'
run: |
cd tests/core
make
timeout-minutes: 10
- name: Vendor library tests
run: |
cd tests/vendor
make
timeout-minutes: 10
- name: Odin internals tests
run: |
cd tests/internal
make
timeout-minutes: 10
- name: Odin check examples/all for Linux i386
run: ./odin check examples/all -vet -strict-style -target:linux_i386
timeout-minutes: 10
- name: Odin check examples/all for Linux arm64
run: ./odin check examples/all -vet -strict-style -target:linux_arm64
timeout-minutes: 10
- name: Odin check examples/all for FreeBSD amd64
run: ./odin check examples/all -vet -strict-style -target:freebsd_amd64
timeout-minutes: 10
- name: Odin check examples/all for OpenBSD amd64
run: ./odin check examples/all -vet -strict-style -target:openbsd_amd64
timeout-minutes: 10
build_macOS:
name: MacOS Build, Check, and Test
runs-on: macos-13
steps:
- uses: actions/checkout@v1
- name: Download LLVM, and setup PATH
run: |
brew install llvm@17
brew install llvm@17 lua@5.4
echo "/usr/local/opt/llvm@17/bin" >> $GITHUB_PATH
- name: build odin
run: ./build_odin.sh release
- name: Odin version
run: ./odin version
timeout-minutes: 1
- name: Odin report
run: ./odin report
timeout-minutes: 1
- name: Odin check
run: ./odin check examples/demo -vet
timeout-minutes: 10
- name: Odin run
run: ./odin run examples/demo
timeout-minutes: 10
- name: Odin run -debug
run: ./odin run examples/demo -debug
timeout-minutes: 10
- name: Odin check examples/all
run: ./odin check examples/all -strict-style
timeout-minutes: 10
- name: Core library tests
- name: Download LLVM (MacOS ARM)
if: matrix.os == 'macos-14'
run: |
cd tests/core
make
timeout-minutes: 10
- name: Odin internals tests
run: |
cd tests/internal
make
timeout-minutes: 10
build_macOS_arm:
name: MacOS ARM Build, Check, and Test
runs-on: macos-14 # This is an arm/m1 runner.
steps:
- uses: actions/checkout@v1
- name: Download LLVM and setup PATH
run: |
brew install llvm@17
brew install llvm@17 wasmtime lua@5.4
echo "/opt/homebrew/opt/llvm@17/bin" >> $GITHUB_PATH
- name: build odin
- name: Build Odin
run: ./build_odin.sh release
- name: Odin version
run: ./odin version
timeout-minutes: 1
- name: Odin report
run: ./odin report
timeout-minutes: 1
- name: Compile needed Vendor
run: |
make -C vendor/stb/src
make -C vendor/cgltf/src
make -C vendor/miniaudio/src
- name: Odin check
run: ./odin check examples/demo -vet
timeout-minutes: 10
- name: Odin run
run: ./odin run examples/demo
timeout-minutes: 10
- name: Odin run -debug
run: ./odin run examples/demo -debug
timeout-minutes: 10
- name: Odin check examples/all
run: ./odin check examples/all -strict-style
timeout-minutes: 10
- name: Core library tests
- name: Normal Core library tests
run: ./odin test tests/core/normal.odin -file -all-packages -vet -strict-style -disallow-do -define:ODIN_TEST_FANCY=false -define:ODIN_TEST_FAIL_ON_BAD_MEMORY=true
- name: Optimized Core library tests
run: ./odin test tests/core/speed.odin -o:speed -file -all-packages -vet -strict-style -disallow-do -define:ODIN_TEST_FANCY=false -define:ODIN_TEST_FAIL_ON_BAD_MEMORY=true
- name: Vendor library tests
run: ./odin test tests/vendor -all-packages -vet -strict-style -disallow-do -define:ODIN_TEST_FANCY=false -define:ODIN_TEST_FAIL_ON_BAD_MEMORY=true
- name: Internals tests
run: ./odin test tests/internal -all-packages -vet -strict-style -disallow-do -define:ODIN_TEST_FANCY=false -define:ODIN_TEST_FAIL_ON_BAD_MEMORY=true
- name: GitHub Issue tests
run: |
cd tests/core
make
timeout-minutes: 10
- name: Odin internals tests
cd tests/issues
./run.sh
- name: Check benchmarks
run: ./odin check tests/benchmark -vet -strict-style -no-entry-point
- name: Odin check examples/all for Linux i386
run: ./odin check examples/all -vet -strict-style -disallow-do -target:linux_i386
if: matrix.os == 'ubuntu-latest'
- name: Odin check examples/all for Linux arm64
run: ./odin check examples/all -vet -strict-style -disallow-do -target:linux_arm64
if: matrix.os == 'ubuntu-latest'
- name: Odin check examples/all for FreeBSD amd64
run: ./odin check examples/all -vet -strict-style -disallow-do -target:freebsd_amd64
if: matrix.os == 'ubuntu-latest'
- name: Odin check examples/all for OpenBSD amd64
run: ./odin check examples/all -vet -strict-style -disallow-do -target:openbsd_amd64
if: matrix.os == 'ubuntu-latest'
- name: Run demo on WASI WASM32
run: |
cd tests/internal
make
timeout-minutes: 10
./odin build examples/demo -target:wasi_wasm32 -vet -strict-style -disallow-do -out:demo.wasm
wasmtime ./demo.wasm
if: matrix.os == 'macos-14'
build_windows:
name: Windows Build, Check, and Test
runs-on: windows-2022
timeout-minutes: 15
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
- name: build Odin
shell: cmd
run: |
@@ -150,72 +165,118 @@ jobs:
./build.bat 1
- name: Odin version
run: ./odin version
timeout-minutes: 1
- name: Odin report
run: ./odin report
timeout-minutes: 1
- name: Odin check
shell: cmd
run: |
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat
odin check examples/demo -vet
timeout-minutes: 10
- name: Odin run
shell: cmd
run: |
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat
odin run examples/demo
timeout-minutes: 10
- name: Odin run -debug
shell: cmd
run: |
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat
odin run examples/demo -debug
timeout-minutes: 10
odin run examples/demo -debug -vet -strict-style -disallow-do
- name: Odin check examples/all
shell: cmd
run: |
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat
odin check examples/all -strict-style
timeout-minutes: 10
odin check examples/all -vet -strict-style -disallow-do
- name: Core library tests
shell: cmd
run: |
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat
cd tests\core
call build.bat
timeout-minutes: 10
odin test tests/core/normal.odin -file -all-packages -vet -strict-style -disallow-do -define:ODIN_TEST_FANCY=false -define:ODIN_TEST_FAIL_ON_BAD_MEMORY=true
- name: Optimized core library tests
shell: cmd
run: |
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat
odin test tests/core/speed.odin -o:speed -file -all-packages -vet -strict-style -disallow-do -define:ODIN_TEST_FANCY=false -define:ODIN_TEST_FAIL_ON_BAD_MEMORY=true
- name: Vendor library tests
shell: cmd
run: |
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat
cd tests\vendor
call build.bat
timeout-minutes: 10
copy vendor\lua\5.4\windows\*.dll .
odin test tests/vendor -all-packages -vet -strict-style -disallow-do -define:ODIN_TEST_FANCY=false -define:ODIN_TEST_FAIL_ON_BAD_MEMORY=true
- name: Odin internals tests
shell: cmd
run: |
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat
cd tests\internal
call build.bat
timeout-minutes: 10
odin test tests/internal -all-packages -vet -strict-style -disallow-do -define:ODIN_TEST_FANCY=false -define:ODIN_TEST_FAIL_ON_BAD_MEMORY=true
- name: Check benchmarks
shell: cmd
run: |
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat
odin check tests/benchmark -vet -strict-style -no-entry-point
- name: Odin documentation tests
shell: cmd
run: |
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat
cd tests\documentation
rem call build.bat
timeout-minutes: 10
call build.bat
- name: core:math/big tests
shell: cmd
run: |
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat
cd tests\core\math\big
call build.bat
timeout-minutes: 10
- name: Odin check examples/all for Windows 32bits
shell: cmd
run: |
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat
odin check examples/all -strict-style -target:windows_i386
timeout-minutes: 10
build_linux_riscv64:
runs-on: ubuntu-latest
name: Linux riscv64 (emulated) Build, Check and Test
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- name: Download LLVM (Linux)
run: |
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 18
echo "/usr/lib/llvm-18/bin" >> $GITHUB_PATH
- name: Build Odin
run: ./build_odin.sh release
- name: Odin version
run: ./odin version
- name: Odin report
run: ./odin report
- name: Compile needed Vendor
run: |
make -C vendor/stb/src
make -C vendor/cgltf/src
make -C vendor/miniaudio/src
- name: Odin check
run: ./odin check examples/all -target:linux_riscv64 -vet -strict-style -disallow-do
- name: Install riscv64 toolchain and qemu
run: sudo apt-get install -y qemu-user qemu-user-static gcc-12-riscv64-linux-gnu libc6-riscv64-cross
- name: Odin run
run: ./odin run examples/demo -vet -strict-style -disallow-do -target:linux_riscv64 -extra-linker-flags:"-fuse-ld=/usr/bin/riscv64-linux-gnu-gcc-12 -static -Wl,-static" -no-rpath
- name: Odin run -debug
run: ./odin run examples/demo -debug -vet -strict-style -disallow-do -target:linux_riscv64 -extra-linker-flags:"-fuse-ld=/usr/bin/riscv64-linux-gnu-gcc-12 -static -Wl,-static" -no-rpath
- name: Normal Core library tests
run: ./odin test tests/core/normal.odin -file -all-packages -vet -strict-style -disallow-do -define:ODIN_TEST_FANCY=false -define:ODIN_TEST_FAIL_ON_BAD_MEMORY=true -target:linux_riscv64 -extra-linker-flags:"-fuse-ld=/usr/bin/riscv64-linux-gnu-gcc-12 -static -Wl,-static" -no-rpath
- name: Optimized Core library tests
run: ./odin test tests/core/speed.odin -o:speed -file -all-packages -vet -strict-style -disallow-do -define:ODIN_TEST_FANCY=false -define:ODIN_TEST_FAIL_ON_BAD_MEMORY=true -target:linux_riscv64 -extra-linker-flags:"-fuse-ld=/usr/bin/riscv64-linux-gnu-gcc-12 -static -Wl,-static" -no-rpath
- name: Internals tests
run: ./odin test tests/internal -all-packages -vet -strict-style -disallow-do -define:ODIN_TEST_FANCY=false -define:ODIN_TEST_FAIL_ON_BAD_MEMORY=true -target:linux_riscv64 -extra-linker-flags:"-fuse-ld=/usr/bin/riscv64-linux-gnu-gcc-12 -static -Wl,-static" -no-rpath
+101 -89
View File
@@ -11,7 +11,7 @@ jobs:
if: github.repository == 'odin-lang/Odin'
runs-on: windows-2022
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
- name: build Odin
shell: cmd
run: |
@@ -36,149 +36,175 @@ jobs:
cp -r bin dist
cp -r examples dist
- name: Upload artifact
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v4
with:
include-hidden-files: true
name: windows_artifacts
path: dist
build_ubuntu:
name: Ubuntu Build
build_linux:
name: Linux Build
if: github.repository == 'odin-lang/Odin'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
- uses: jirutka/setup-alpine@v1
with:
branch: v3.20
- name: (Linux) Download LLVM
run: |
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 17
echo "/usr/lib/llvm-17/bin" >> $GITHUB_PATH
apk add --no-cache \
musl-dev llvm18-dev clang18 git mold lz4 \
libxml2-static llvm18-static zlib-static zstd-static \
make
shell: alpine.sh --root {0}
- name: build odin
run: make nightly
# NOTE: this build does slow compile times because of musl
run: ci/build_linux_static.sh
shell: alpine.sh {0}
- name: Odin run
run: ./odin run examples/demo
- name: Copy artifacts
run: |
mkdir dist
cp odin dist
cp LICENSE dist
cp libLLVM* dist
cp -r shared dist
cp -r base dist
cp -r core dist
cp -r vendor dist
cp -r examples dist
# Zipping so executable permissions are retained, see https://github.com/actions/upload-artifact/issues/38
zip -r dist.zip dist
FILE="odin-linux-amd64-nightly+$(date -I)"
mkdir $FILE
cp odin $FILE
cp LICENSE $FILE
cp -r shared $FILE
cp -r base $FILE
cp -r core $FILE
cp -r vendor $FILE
cp -r examples $FILE
# Creating a tarball so executable permissions are retained, see https://github.com/actions/upload-artifact/issues/38
tar -czvf dist.tar.gz $FILE
- name: Odin run
run: |
FILE="odin-linux-amd64-nightly+$(date -I)"
$FILE/odin run examples/demo
- name: Upload artifact
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v4
with:
name: ubuntu_artifacts
path: dist.zip
name: linux_artifacts
path: dist.tar.gz
build_macos:
name: MacOS Build
if: github.repository == 'odin-lang/Odin'
runs-on: macos-13
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
- name: Download LLVM and setup PATH
run: |
brew install llvm@17 dylibbundler
echo "/usr/local/opt/llvm@17/bin" >> $GITHUB_PATH
brew install llvm@18 dylibbundler
echo "/usr/local/opt/llvm@18/bin" >> $GITHUB_PATH
- name: build odin
# These -L makes the linker prioritize system libraries over LLVM libraries, this is mainly to
# not link with libunwind bundled with LLVM but link with libunwind on the system.
run: CXXFLAGS="-L/usr/lib/system -L/usr/lib" make nightly
- name: Bundle
run: |
mkdir dist
cp odin dist
cp LICENSE dist
cp -r shared dist
cp -r base dist
cp -r core dist
cp -r vendor dist
cp -r examples dist
dylibbundler -b -x dist/odin -d dist/libs -od -p @executable_path/libs
# Zipping so executable permissions are retained, see https://github.com/actions/upload-artifact/issues/38
zip -r dist.zip dist
FILE="odin-macos-amd64-nightly+$(date -I)"
mkdir $FILE
cp odin $FILE
cp LICENSE $FILE
cp -r shared $FILE
cp -r base $FILE
cp -r core $FILE
cp -r vendor $FILE
cp -r examples $FILE
dylibbundler -b -x $FILE/odin -d $FILE/libs -od -p @executable_path/libs
# Creating a tarball so executable permissions are retained, see https://github.com/actions/upload-artifact/issues/38
tar -czvf dist.tar.gz $FILE
- name: Odin run
run: ./dist/odin run examples/demo
run: |
FILE="odin-macos-amd64-nightly+$(date -I)"
$FILE/odin run examples/demo
- name: Upload artifact
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v4
with:
name: macos_artifacts
path: dist.zip
path: dist.tar.gz
build_macos_arm:
name: MacOS ARM Build
if: github.repository == 'odin-lang/Odin'
runs-on: macos-14 # ARM machine
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
- name: Download LLVM and setup PATH
run: |
brew install llvm@17 dylibbundler
echo "/opt/homebrew/opt/llvm@17/bin" >> $GITHUB_PATH
brew install llvm@18 dylibbundler
echo "/opt/homebrew/opt/llvm@18/bin" >> $GITHUB_PATH
- name: build odin
# These -L makes the linker prioritize system libraries over LLVM libraries, this is mainly to
# not link with libunwind bundled with LLVM but link with libunwind on the system.
run: CXXFLAGS="-L/usr/lib/system -L/usr/lib" make nightly
- name: Bundle
run: |
mkdir dist
cp odin dist
cp LICENSE dist
cp -r shared dist
cp -r base dist
cp -r core dist
cp -r vendor dist
cp -r examples dist
dylibbundler -b -x dist/odin -d dist/libs -od -p @executable_path/libs
# Zipping so executable permissions are retained, see https://github.com/actions/upload-artifact/issues/38
zip -r dist.zip dist
FILE="odin-macos-arm64-nightly+$(date -I)"
mkdir $FILE
cp odin $FILE
cp LICENSE $FILE
cp -r shared $FILE
cp -r base $FILE
cp -r core $FILE
cp -r vendor $FILE
cp -r examples $FILE
dylibbundler -b -x $FILE/odin -d $FILE/libs -od -p @executable_path/libs
# Creating a tarball so executable permissions are retained, see https://github.com/actions/upload-artifact/issues/38
tar -czvf dist.tar.gz $FILE
- name: Odin run
run: ./dist/odin run examples/demo
run: |
FILE="odin-macos-arm64-nightly+$(date -I)"
$FILE/odin run examples/demo
- name: Upload artifact
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v4
with:
name: macos_arm_artifacts
path: dist.zip
path: dist.tar.gz
upload_b2:
runs-on: [ubuntu-latest]
needs: [build_windows, build_macos, build_macos_arm, build_ubuntu]
needs: [build_windows, build_macos, build_macos_arm, build_linux]
steps:
- uses: actions/checkout@v1
- uses: actions/setup-python@v2
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.8.x'
- name: Install B2 CLI
- name: Install B2 SDK
shell: bash
run: |
python -m pip install --upgrade pip
pip install --upgrade b2
pip install --upgrade b2sdk
- name: Display Python version
run: python -c "import sys; print(sys.version)"
- name: Download Windows artifacts
uses: actions/download-artifact@v1
uses: actions/download-artifact@v4.1.7
with:
name: windows_artifacts
path: windows_artifacts
- name: Download Ubuntu artifacts
uses: actions/download-artifact@v1
uses: actions/download-artifact@v4.1.7
with:
name: ubuntu_artifacts
name: linux_artifacts
path: linux_artifacts
- name: Download macOS artifacts
uses: actions/download-artifact@v1
uses: actions/download-artifact@v4.1.7
with:
name: macos_artifacts
path: macos_artifacts
- name: Download macOS arm artifacts
uses: actions/download-artifact@v1
uses: actions/download-artifact@v4.1.7
with:
name: macos_arm_artifacts
path: macos_arm_artifacts
- name: Debug
run: |
tree -L 2
- name: Create archives and upload
shell: bash
@@ -188,24 +214,10 @@ jobs:
BUCKET: ${{ secrets.B2_BUCKET }}
DAYS_TO_KEEP: ${{ secrets.B2_DAYS_TO_KEEP }}
run: |
echo Authorizing B2 account
b2 authorize-account "$APPID" "$APPKEY"
echo Uploading artifcates to B2
chmod +x ./ci/upload_create_nightly.sh
./ci/upload_create_nightly.sh "$BUCKET" windows-amd64 windows_artifacts/
./ci/upload_create_nightly.sh "$BUCKET" ubuntu-amd64 ubuntu_artifacts/dist.zip
./ci/upload_create_nightly.sh "$BUCKET" macos-amd64 macos_artifacts/dist.zip
./ci/upload_create_nightly.sh "$BUCKET" macos-arm64 macos_arm_artifacts/dist.zip
echo Deleting old artifacts in B2
python3 ci/delete_old_binaries.py "$BUCKET" "$DAYS_TO_KEEP"
echo Creating nightly.json
python3 ci/create_nightly_json.py "$BUCKET" > nightly.json
echo Uploading nightly.json
b2 upload-file "$BUCKET" nightly.json nightly.json
echo Clear B2 account info
b2 clear-account
file linux_artifacts/dist.tar.gz
python3 ci/nightly.py artifact windows-amd64 windows_artifacts/
python3 ci/nightly.py artifact linux-amd64 linux_artifacts/dist.tar.gz
python3 ci/nightly.py artifact macos-amd64 macos_artifacts/dist.tar.gz
python3 ci/nightly.py artifact macos-arm64 macos_arm_artifacts/dist.tar.gz
python3 ci/nightly.py prune
python3 ci/nightly.py json
+5 -35
View File
@@ -17,45 +17,12 @@
[Rr]eleases/
x64/
x86/
!/core/simd/x86
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
![Cc]ore/[Ll]og/
tests/documentation/verify/
tests/documentation/all.odin-doc
tests/internal/test_map
tests/internal/test_pow
tests/internal/test_rtti
tests/core/test_base64
tests/core/test_cbor
tests/core/test_core_compress
tests/core/test_core_container
tests/core/test_core_filepath
tests/core/test_core_fmt
tests/core/test_core_i18n
tests/core/test_core_image
tests/core/test_core_libc
tests/core/test_core_match
tests/core/test_core_math
tests/core/test_core_net
tests/core/test_core_os_exit
tests/core/test_core_reflect
tests/core/test_core_strings
tests/core/test_core_time
tests/core/test_crypto
tests/core/test_hash
tests/core/test_hex
tests/core/test_hxa
tests/core/test_json
tests/core/test_linalg_glsl_math
tests/core/test_noise
tests/core/test_varint
tests/core/test_xml
tests/core/test_core_slice
tests/core/test_core_thread
tests/core/test_core_runtime
tests/vendor/vendor_botan
# Visual Studio 2015 cache/options directory
.vs/
# Visual Studio Code options directory
@@ -299,11 +266,14 @@ bin/
*.exe
*.obj
*.pdb
*.res
desktop.ini
Thumbs.db
# - Linux/MacOS
odin
!odin/
odin.dSYM
**/*.dSYM
*.bin
demo.bin
libLLVM*.so*
BIN
View File
Binary file not shown.
+7 -1
View File
@@ -1,4 +1,4 @@
all: debug
all: default
demo:
./odin run examples/demo/demo.odin -file
@@ -6,12 +6,18 @@ demo:
report:
./odin report
default:
PROGRAM=make ./build_odin.sh # debug
debug:
./build_odin.sh debug
release:
./build_odin.sh release
release-native:
./build_odin.sh release-native
release_native:
./build_odin.sh release-native
+2 -2
View File
@@ -76,9 +76,9 @@ Answers to common questions about Odin.
Documentation for all the official packages part of the [core](https://pkg.odin-lang.org/core/) and [vendor](https://pkg.odin-lang.org/vendor/) library collections.
#### [The Odin Wiki](https://github.com/odin-lang/Odin/wiki)
#### [Odin Documentation](https://odin-lang.org/docs/)
A wiki maintained by the Odin community.
Documentation for the Odin language itself.
#### [Odin Discord](https://discord.gg/sVBPHEv)
+2
View File
@@ -126,3 +126,5 @@ clamp :: proc(value, minimum, maximum: T) -> T ---
soa_zip :: proc(slices: ...) -> #soa[]Struct ---
soa_unzip :: proc(value: $S/#soa[]$E) -> (slices: ...) ---
unreachable :: proc() -> ! ---
+51 -19
View File
@@ -1,5 +1,5 @@
// This is purely for documentation
//+build ignore
#+build ignore
package intrinsics
// Package-Related
@@ -38,9 +38,12 @@ count_leading_zeros :: proc(x: $T) -> T where type_is_integer(T) || type_is_sim
reverse_bits :: proc(x: $T) -> T where type_is_integer(T) || type_is_simd_vector(T) ---
byte_swap :: proc(x: $T) -> T where type_is_integer(T) || type_is_float(T) ---
overflow_add :: proc(lhs, rhs: $T) -> (T, bool) ---
overflow_sub :: proc(lhs, rhs: $T) -> (T, bool) ---
overflow_mul :: proc(lhs, rhs: $T) -> (T, bool) ---
overflow_add :: proc(lhs, rhs: $T) -> (T, bool) where type_is_integer(T) #optional_ok ---
overflow_sub :: proc(lhs, rhs: $T) -> (T, bool) where type_is_integer(T) #optional_ok ---
overflow_mul :: proc(lhs, rhs: $T) -> (T, bool) where type_is_integer(T) #optional_ok ---
saturating_add :: proc(lhs, rhs: $T) -> T where type_is_integer(T) ---
saturating_sub :: proc(lhs, rhs: $T) -> T where type_is_integer(T) ---
sqrt :: proc(x: $T) -> T where type_is_float(T) || (type_is_simd_vector(T) && type_is_float(type_elem_type(T))) ---
@@ -73,6 +76,8 @@ expect :: proc(val, expected_val: T) -> T ---
// Linux and Darwin Only
syscall :: proc(id: uintptr, args: ..uintptr) -> uintptr ---
// FreeBSD, NetBSD, et cetera
syscall_bsd :: proc(id: uintptr, args: ..uintptr) -> (uintptr, bool) ---
// Atomics
@@ -167,6 +172,9 @@ type_is_matrix :: proc($T: typeid) -> bool ---
type_has_nil :: proc($T: typeid) -> bool ---
type_is_matrix_row_major :: proc($T: typeid) -> bool where type_is_matrix(T) ---
type_is_matrix_column_major :: proc($T: typeid) -> bool where type_is_matrix(T) ---
type_is_specialization_of :: proc($T, $S: typeid) -> bool ---
type_is_variant_of :: proc($U, $V: typeid) -> bool where type_is_union(U) ---
@@ -189,7 +197,8 @@ type_proc_return_count :: proc($T: typeid) -> int where type_is_proc(T) ---
type_proc_parameter_type :: proc($T: typeid, index: int) -> typeid where type_is_proc(T) ---
type_proc_return_type :: proc($T: typeid, index: int) -> typeid where type_is_proc(T) ---
type_struct_field_count :: proc($T: typeid) -> int where type_is_struct(T) ---
type_struct_field_count :: proc($T: typeid) -> int where type_is_struct(T) ---
type_struct_has_implicit_padding :: proc($T: typeid) -> bool where type_is_struct(T) ---
type_polymorphic_record_parameter_count :: proc($T: typeid) -> typeid ---
type_polymorphic_record_parameter_value :: proc($T: typeid, index: int) -> $V ---
@@ -210,14 +219,21 @@ type_map_cell_info :: proc($T: typeid) -> ^runtime.Map_Cell_Info ---
type_convert_variants_to_pointers :: proc($T: typeid) -> typeid where type_is_union(T) ---
type_merge :: proc($U, $V: typeid) -> typeid where type_is_union(U), type_is_union(V) ---
type_has_shared_fields :: proc($U, $V: typeid) -> bool typeid where type_is_struct(U), type_is_struct(V) ---
constant_utf16_cstring :: proc($literal: string) -> [^]u16 ---
constant_log2 :: proc($v: $T) -> T where type_is_integer(T) ---
// SIMD related
simd_add :: proc(a, b: #simd[N]T) -> #simd[N]T ---
simd_sub :: proc(a, b: #simd[N]T) -> #simd[N]T ---
simd_mul :: proc(a, b: #simd[N]T) -> #simd[N]T ---
simd_div :: proc(a, b: #simd[N]T) -> #simd[N]T where type_is_float(T) ---
simd_saturating_add :: proc(a, b: #simd[N]T) -> #simd[N]T where type_is_integer(T) ---
simd_saturating_sub :: proc(a, b: #simd[N]T) -> #simd[N]T where type_is_integer(T) ---
// Keeps Odin's Behaviour
// (x << y) if y <= mask else 0
simd_shl :: proc(a: #simd[N]T, b: #simd[N]Unsigned_Integer) -> #simd[N]T ---
@@ -228,9 +244,6 @@ simd_shr :: proc(a: #simd[N]T, b: #simd[N]Unsigned_Integer) -> #simd[N]T ---
simd_shl_masked :: proc(a: #simd[N]T, b: #simd[N]Unsigned_Integer) -> #simd[N]T ---
simd_shr_masked :: proc(a: #simd[N]T, b: #simd[N]Unsigned_Integer) -> #simd[N]T ---
simd_add_sat :: proc(a, b: #simd[N]T) -> #simd[N]T ---
simd_sub_sat :: proc(a, b: #simd[N]T) -> #simd[N]T ---
simd_bit_and :: proc(a, b: #simd[N]T) -> #simd[N]T ---
simd_bit_or :: proc(a, b: #simd[N]T) -> #simd[N]T ---
simd_bit_xor :: proc(a, b: #simd[N]T) -> #simd[N]T ---
@@ -259,13 +272,28 @@ simd_lanes_ge :: proc(a, b: #simd[N]T) -> #simd[N]Integer ---
simd_extract :: proc(a: #simd[N]T, idx: uint) -> T ---
simd_replace :: proc(a: #simd[N]T, idx: uint, elem: T) -> #simd[N]T ---
simd_reduce_add_ordered :: proc(a: #simd[N]T) -> T ---
simd_reduce_mul_ordered :: proc(a: #simd[N]T) -> T ---
simd_reduce_min :: proc(a: #simd[N]T) -> T ---
simd_reduce_max :: proc(a: #simd[N]T) -> T ---
simd_reduce_and :: proc(a: #simd[N]T) -> T ---
simd_reduce_or :: proc(a: #simd[N]T) -> T ---
simd_reduce_xor :: proc(a: #simd[N]T) -> T ---
simd_reduce_add_ordered :: proc(a: #simd[N]T) -> T where type_is_integer(T) || type_is_float(T)---
simd_reduce_mul_ordered :: proc(a: #simd[N]T) -> T where type_is_integer(T) || type_is_float(T)---
simd_reduce_min :: proc(a: #simd[N]T) -> T where type_is_integer(T) || type_is_float(T)---
simd_reduce_max :: proc(a: #simd[N]T) -> T where type_is_integer(T) || type_is_float(T)---
simd_reduce_and :: proc(a: #simd[N]T) -> T where type_is_integer(T) || type_is_float(T)---
simd_reduce_or :: proc(a: #simd[N]T) -> T where type_is_integer(T) || type_is_float(T)---
simd_reduce_xor :: proc(a: #simd[N]T) -> T where type_is_integer(T) || type_is_float(T)---
simd_reduce_any :: proc(a: #simd[N]T) -> T where type_is_boolean(T) ---
simd_reduce_all :: proc(a: #simd[N]T) -> T where type_is_boolean(T) ---
simd_gather :: proc(ptr: #simd[N]rawptr, val: #simd[N]T, mask: #simd[N]U) -> #simd[N]T where type_is_integer(U) || type_is_boolean(U) ---
simd_scatter :: proc(ptr: #simd[N]rawptr, val: #simd[N]T, mask: #simd[N]U) where type_is_integer(U) || type_is_boolean(U) ---
simd_masked_load :: proc(ptr: rawptr, val: #simd[N]T, mask: #simd[N]U) -> #simd[N]T where type_is_integer(U) || type_is_boolean(U) ---
simd_masked_store :: proc(ptr: rawptr, val: #simd[N]T, mask: #simd[N]U) where type_is_integer(U) || type_is_boolean(U) ---
simd_masked_expand_load :: proc(ptr: rawptr, val: #simd[N]T, mask: #simd[N]U) -> #simd[N]T where type_is_integer(U) || type_is_boolean(U) ---
simd_masked_compress_store :: proc(ptr: rawptr, val: #simd[N]T, mask: #simd[N]U) where type_is_integer(U) || type_is_boolean(U) ---
simd_shuffle :: proc(a, b: #simd[N]T, indices: ..int) -> #simd[len(indices)]T ---
simd_select :: proc(cond: #simd[N]boolean_or_integer, true, false: #simd[N]T) -> #simd[N]T ---
@@ -279,11 +307,11 @@ simd_nearest :: proc(a: #simd[N]any_float) -> #simd[N]any_float ---
simd_to_bits :: proc(v: #simd[N]T) -> #simd[N]Integer where size_of(T) == size_of(Integer), type_is_unsigned(Integer) ---
// equivalent a swizzle with descending indices, e.g. reserve(a, 3, 2, 1, 0)
simd_reverse :: proc(a: #simd[N]T) -> #simd[N]T ---
// equivalent to a swizzle with descending indices, e.g. reserve(a, 3, 2, 1, 0)
simd_lanes_reverse :: proc(a: #simd[N]T) -> #simd[N]T ---
simd_rotate_left :: proc(a: #simd[N]T, $offset: int) -> #simd[N]T ---
simd_rotate_right :: proc(a: #simd[N]T, $offset: int) -> #simd[N]T ---
simd_lanes_rotate_left :: proc(a: #simd[N]T, $offset: int) -> #simd[N]T ---
simd_lanes_rotate_right :: proc(a: #simd[N]T, $offset: int) -> #simd[N]T ---
// Checks if the current target supports the given target features.
//
@@ -292,6 +320,10 @@ simd_rotate_right :: proc(a: #simd[N]T, $offset: int) -> #simd[N]T ---
// if all listed features are supported.
has_target_feature :: proc($test: $T) -> bool where type_is_string(T) || type_is_proc(T) ---
// Returns the value of the procedure where `x` must be a call expression
procedure_of :: proc(x: $T) -> T where type_is_proc(T) ---
// WASM targets only
wasm_memory_grow :: proc(index, delta: uintptr) -> int ---
wasm_memory_size :: proc(index: uintptr) -> int ---
+133 -25
View File
@@ -18,7 +18,7 @@
// This could change at a later date if the all these data structures are
// implemented within the compiler rather than in this "preload" file
//
//+no-instrumentation
#+no-instrumentation
package runtime
import "base:intrinsics"
@@ -66,7 +66,7 @@ Type_Info_Named :: struct {
name: string,
base: ^Type_Info,
pkg: string,
loc: Source_Code_Location,
loc: ^Source_Code_Location,
}
Type_Info_Integer :: struct {signed: bool, endianness: Platform_Endianness}
Type_Info_Rune :: struct {}
@@ -112,23 +112,32 @@ Type_Info_Parameters :: struct { // Only used for procedures parameters and resu
}
Type_Info_Tuple :: Type_Info_Parameters // Will be removed eventually
Type_Info_Struct :: struct {
types: []^Type_Info,
names: []string,
offsets: []uintptr,
usings: []bool,
tags: []string,
is_packed: bool,
is_raw_union: bool,
is_no_copy: bool,
custom_align: bool,
Type_Info_Struct_Flags :: distinct bit_set[Type_Info_Struct_Flag; u8]
Type_Info_Struct_Flag :: enum u8 {
packed = 0,
raw_union = 1,
no_copy = 2,
align = 3,
}
equal: Equal_Proc, // set only when the struct has .Comparable set but does not have .Simple_Compare set
Type_Info_Struct :: struct {
// Slice these with `field_count`
types: [^]^Type_Info `fmt:"v,field_count"`,
names: [^]string `fmt:"v,field_count"`,
offsets: [^]uintptr `fmt:"v,field_count"`,
usings: [^]bool `fmt:"v,field_count"`,
tags: [^]string `fmt:"v,field_count"`,
field_count: i32,
flags: Type_Info_Struct_Flags,
// These are only set iff this structure is an SOA structure
soa_kind: Type_Info_Struct_Soa_Kind,
soa_len: i32,
soa_base_type: ^Type_Info,
soa_len: int,
equal: Equal_Proc, // set only when the struct has .Comparable set but does not have .Simple_Compare set
}
Type_Info_Union :: struct {
variants: []^Type_Info,
@@ -142,9 +151,9 @@ Type_Info_Union :: struct {
shared_nil: bool,
}
Type_Info_Enum :: struct {
base: ^Type_Info,
names: []string,
values: []Type_Info_Enum_Value,
base: ^Type_Info,
names: []string,
values: []Type_Info_Enum_Value,
}
Type_Info_Map :: struct {
key: ^Type_Info,
@@ -187,11 +196,12 @@ Type_Info_Soa_Pointer :: struct {
}
Type_Info_Bit_Field :: struct {
backing_type: ^Type_Info,
names: []string,
types: []^Type_Info,
bit_sizes: []uintptr,
bit_offsets: []uintptr,
tags: []string,
names: [^]string `fmt:"v,field_count"`,
types: [^]^Type_Info `fmt:"v,field_count"`,
bit_sizes: [^]uintptr `fmt:"v,field_count"`,
bit_offsets: [^]uintptr `fmt:"v,field_count"`,
tags: [^]string `fmt:"v,field_count"`,
field_count: int,
}
Type_Info_Flag :: enum u8 {
@@ -299,6 +309,8 @@ when ODIN_OS == .Windows {
Thread_Detach = 3,
}
dll_forward_reason: DLL_Forward_Reason
dll_instance: rawptr
}
// IMPORTANT NOTE(bill): Must be in this order (as the compiler relies upon it)
@@ -397,11 +409,34 @@ Logger :: struct {
options: Logger_Options,
}
Random_Generator_Mode :: enum {
Read,
Reset,
Query_Info,
}
Random_Generator_Query_Info_Flag :: enum u32 {
Cryptographic,
Uniform,
External_Entropy,
Resettable,
}
Random_Generator_Query_Info :: distinct bit_set[Random_Generator_Query_Info_Flag; u32]
Random_Generator_Proc :: #type proc(data: rawptr, mode: Random_Generator_Mode, p: []byte)
Random_Generator :: struct {
procedure: Random_Generator_Proc,
data: rawptr,
}
Context :: struct {
allocator: Allocator,
temp_allocator: Allocator,
assertion_failure_proc: Assertion_Failure_Proc,
logger: Logger,
random_generator: Random_Generator,
user_ptr: rawptr,
user_index: int,
@@ -470,6 +505,15 @@ Raw_Soa_Pointer :: struct {
index: int,
}
Raw_Complex32 :: struct {real, imag: f16}
Raw_Complex64 :: struct {real, imag: f32}
Raw_Complex128 :: struct {real, imag: f64}
Raw_Quaternion64 :: struct {imag, jmag, kmag: f16, real: f16}
Raw_Quaternion128 :: struct {imag, jmag, kmag: f32, real: f32}
Raw_Quaternion256 :: struct {imag, jmag, kmag: f64, real: f64}
Raw_Quaternion64_Vector_Scalar :: struct {vector: [3]f16, scalar: f16}
Raw_Quaternion128_Vector_Scalar :: struct {vector: [3]f32, scalar: f32}
Raw_Quaternion256_Vector_Scalar :: struct {vector: [3]f64, scalar: f64}
/*
@@ -482,8 +526,11 @@ Raw_Soa_Pointer :: struct {
Essence,
FreeBSD,
OpenBSD,
NetBSD,
Haiku,
WASI,
JS,
Orca,
Freestanding,
}
*/
@@ -499,15 +546,29 @@ Odin_OS_Type :: type_of(ODIN_OS)
arm64,
wasm32,
wasm64p32,
riscv64,
}
*/
Odin_Arch_Type :: type_of(ODIN_ARCH)
Odin_Arch_Types :: bit_set[Odin_Arch_Type]
ALL_ODIN_ARCH_TYPES :: Odin_Arch_Types{
.amd64,
.i386,
.arm32,
.arm64,
.wasm32,
.wasm64p32,
.riscv64,
}
/*
// Defined internally by the compiler
Odin_Build_Mode_Type :: enum int {
Executable,
Dynamic,
Static,
Object,
Assembly,
LLVM_IR,
@@ -525,6 +586,22 @@ Odin_Build_Mode_Type :: type_of(ODIN_BUILD_MODE)
*/
Odin_Endian_Type :: type_of(ODIN_ENDIAN)
Odin_OS_Types :: bit_set[Odin_OS_Type]
ALL_ODIN_OS_TYPES :: Odin_OS_Types{
.Windows,
.Darwin,
.Linux,
.Essence,
.FreeBSD,
.OpenBSD,
.NetBSD,
.Haiku,
.WASI,
.JS,
.Orca,
.Freestanding,
}
/*
// Defined internally by the compiler
@@ -542,12 +619,25 @@ Odin_Platform_Subtarget_Type :: type_of(ODIN_PLATFORM_SUBTARGET)
Memory = 1,
Thread = 2,
}
Odin_Sanitizer_Flags :: distinct bitset[Odin_Sanitizer_Flag; u32]
Odin_Sanitizer_Flags :: distinct bit_set[Odin_Sanitizer_Flag; u32]
ODIN_SANITIZER_FLAGS // is a constant
*/
Odin_Sanitizer_Flags :: type_of(ODIN_SANITIZER_FLAGS)
/*
// Defined internally by the compiler
Odin_Optimization_Mode :: enum int {
None = -1,
Minimal = 0,
Size = 1,
Speed = 2,
Aggressive = 3,
}
ODIN_OPTIMIZATION_MODE // is a constant
*/
Odin_Optimization_Mode :: type_of(ODIN_OPTIMIZATION_MODE)
/////////////////////////////
// Init Startup Procedures //
@@ -683,13 +773,20 @@ __init_context :: proc "contextless" (c: ^Context) {
c.logger.procedure = default_logger_proc
c.logger.data = nil
c.random_generator.procedure = default_random_generator_proc
c.random_generator.data = nil
}
default_assertion_failure_proc :: proc(prefix, message: string, loc: Source_Code_Location) -> ! {
default_assertion_contextless_failure_proc(prefix, message, loc)
}
default_assertion_contextless_failure_proc :: proc "contextless" (prefix, message: string, loc: Source_Code_Location) -> ! {
when ODIN_OS == .Freestanding {
// Do nothing
} else {
when !ODIN_DISABLE_ASSERT {
when ODIN_OS != .Orca && !ODIN_DISABLE_ASSERT {
print_caller_location(loc)
print_string(" ")
}
@@ -698,7 +795,18 @@ default_assertion_failure_proc :: proc(prefix, message: string, loc: Source_Code
print_string(": ")
print_string(message)
}
print_byte('\n')
when ODIN_OS == .Orca {
assert_fail(
cstring(raw_data(loc.file_path)),
cstring(raw_data(loc.procedure)),
loc.line,
"",
cstring(raw_data(orca_stderr_buffer[:orca_stderr_buffer_idx])),
)
} else {
print_byte('\n')
}
}
trap()
}
+250 -142
View File
@@ -6,6 +6,39 @@ import "base:intrinsics"
Maybe :: union($T: typeid) {T}
/*
Recovers the containing/parent struct from a pointer to one of its fields.
Works by "walking back" to the struct's starting address using the offset between the field and the struct.
Inputs:
- ptr: Pointer to the field of a container struct
- T: The type of the container struct
- field_name: The name of the field in the `T` struct
Returns:
- A pointer to the container struct based on a pointer to a field in it
Example:
package container_of
import "base:runtime"
Node :: struct {
value: int,
prev: ^Node,
next: ^Node,
}
main :: proc() {
node: Node
field_ptr := &node.next
container_struct_ptr: ^Node = runtime.container_of(field_ptr, Node, "next")
assert(container_struct_ptr == &node)
assert(uintptr(field_ptr) - uintptr(container_struct_ptr) == size_of(node.value) + size_of(node.prev))
}
Output:
^Node
*/
@(builtin, require_results)
container_of :: #force_inline proc "contextless" (ptr: $P/^$Field_Type, $T: typeid, $field_name: string) -> ^T
where intrinsics.type_has_field(T, field_name),
@@ -65,10 +98,10 @@ copy :: proc{copy_slice, copy_from_string}
// with the old value, and reducing the length of the dynamic array by 1.
//
// Note: This is an O(1) operation.
// Note: If you the elements to remain in their order, use `ordered_remove`.
// Note: If you want the elements to remain in their order, use `ordered_remove`.
// Note: If the index is out of bounds, this procedure will panic.
@builtin
unordered_remove :: proc(array: ^$D/[dynamic]$T, index: int, loc := #caller_location) #no_bounds_check {
unordered_remove :: proc(array: ^$D/[dynamic]$T, #any_int index: int, loc := #caller_location) #no_bounds_check {
bounds_check_error_loc(loc, index, len(array))
n := len(array)-1
if index != n {
@@ -79,10 +112,10 @@ unordered_remove :: proc(array: ^$D/[dynamic]$T, index: int, loc := #caller_loca
// `ordered_remove` removed the element at the specified `index` whilst keeping the order of the other elements.
//
// Note: This is an O(N) operation.
// Note: If you the elements do not have to remain in their order, prefer `unordered_remove`.
// Note: If the elements do not have to remain in their order, prefer `unordered_remove`.
// Note: If the index is out of bounds, this procedure will panic.
@builtin
ordered_remove :: proc(array: ^$D/[dynamic]$T, index: int, loc := #caller_location) #no_bounds_check {
ordered_remove :: proc(array: ^$D/[dynamic]$T, #any_int index: int, loc := #caller_location) #no_bounds_check {
bounds_check_error_loc(loc, index, len(array))
if index+1 < len(array) {
copy(array[index:], array[index+1:])
@@ -95,7 +128,7 @@ ordered_remove :: proc(array: ^$D/[dynamic]$T, index: int, loc := #caller_locati
// Note: This is an O(N) operation.
// Note: If the range is out of bounds, this procedure will panic.
@builtin
remove_range :: proc(array: ^$D/[dynamic]$T, lo, hi: int, loc := #caller_location) #no_bounds_check {
remove_range :: proc(array: ^$D/[dynamic]$T, #any_int lo, hi: int, loc := #caller_location) #no_bounds_check {
slice_expr_error_lo_hi_loc(loc, lo, hi, len(array))
n := max(hi-lo, 0)
if n > 0 {
@@ -163,21 +196,43 @@ pop_front_safe :: proc "contextless" (array: ^$T/[dynamic]$E) -> (res: E, ok: bo
// `clear` will set the length of a passed dynamic array or map to `0`
@builtin
clear :: proc{clear_dynamic_array, clear_map}
clear :: proc{
clear_dynamic_array,
clear_map,
clear_soa_dynamic_array,
}
// `reserve` will try to reserve memory of a passed dynamic array or map to the requested element count (setting the `cap`).
@builtin
reserve :: proc{reserve_dynamic_array, reserve_map}
reserve :: proc{
reserve_dynamic_array,
reserve_map,
reserve_soa,
}
@builtin
non_zero_reserve :: proc{non_zero_reserve_dynamic_array}
non_zero_reserve :: proc{
non_zero_reserve_dynamic_array,
non_zero_reserve_soa,
}
// `resize` will try to resize memory of a passed dynamic array to the requested element count (setting the `len`, and possibly `cap`).
@builtin
resize :: proc{resize_dynamic_array}
resize :: proc{
resize_dynamic_array,
resize_soa,
}
@builtin
non_zero_resize :: proc{non_zero_resize_dynamic_array}
non_zero_resize :: proc{
non_zero_resize_dynamic_array,
non_zero_resize_soa,
}
// Shrinks the capacity of a dynamic array or map down to the current length, or the given capacity.
@builtin
@@ -268,7 +323,7 @@ new_clone :: proc(data: $T, allocator := context.allocator, loc := #caller_locat
return
}
DEFAULT_RESERVE_CAPACITY :: 16
DEFAULT_DYNAMIC_ARRAY_CAPACITY :: 8
@(require_results)
make_aligned :: proc($T: typeid/[]$E, #any_int len: int, alignment: int, allocator := context.allocator, loc := #caller_location) -> (T, Allocator_Error) #optional_allocator_error {
@@ -295,7 +350,7 @@ make_slice :: proc($T: typeid/[]$E, #any_int len: int, allocator := context.allo
// Note: Prefer using the procedure group `make`.
@(builtin, require_results)
make_dynamic_array :: proc($T: typeid/[dynamic]$E, allocator := context.allocator, loc := #caller_location) -> (T, Allocator_Error) #optional_allocator_error {
return make_dynamic_array_len_cap(T, 0, DEFAULT_RESERVE_CAPACITY, allocator, loc)
return make_dynamic_array_len_cap(T, 0, 0, allocator, loc)
}
// `make_dynamic_array_len` allocates and initializes a dynamic array. Like `new`, the first argument is a type, not a value.
// Unlike `new`, `make`'s return value is the same as the type of its argument, not a pointer to it.
@@ -311,29 +366,47 @@ make_dynamic_array_len :: proc($T: typeid/[dynamic]$E, #any_int len: int, alloca
// Note: Prefer using the procedure group `make`.
@(builtin, require_results)
make_dynamic_array_len_cap :: proc($T: typeid/[dynamic]$E, #any_int len: int, #any_int cap: int, allocator := context.allocator, loc := #caller_location) -> (array: T, err: Allocator_Error) #optional_allocator_error {
make_dynamic_array_error_loc(loc, len, cap)
array.allocator = allocator // initialize allocator before just in case it fails to allocate any memory
data := mem_alloc_bytes(size_of(E)*cap, align_of(E), allocator, loc) or_return
s := Raw_Dynamic_Array{raw_data(data), len, cap, allocator}
if data == nil && size_of(E) != 0 {
s.len, s.cap = 0, 0
}
array = transmute(T)s
err = _make_dynamic_array_len_cap((^Raw_Dynamic_Array)(&array), size_of(E), align_of(E), len, cap, allocator, loc)
return
}
// `make_map` allocates and initializes a dynamic array. Like `new`, the first argument is a type, not a value.
@(require_results)
_make_dynamic_array_len_cap :: proc(array: ^Raw_Dynamic_Array, size_of_elem, align_of_elem: int, #any_int len: int, #any_int cap: int, allocator := context.allocator, loc := #caller_location) -> (err: Allocator_Error) {
make_dynamic_array_error_loc(loc, len, cap)
array.allocator = allocator // initialize allocator before just in case it fails to allocate any memory
data := mem_alloc_bytes(size_of_elem*cap, align_of_elem, allocator, loc) or_return
use_zero := data == nil && size_of_elem != 0
array.data = raw_data(data)
array.len = 0 if use_zero else len
array.cap = 0 if use_zero else cap
array.allocator = allocator
return
}
// `make_map` initializes a map with an allocator. Like `new`, the first argument is a type, not a value.
// Unlike `new`, `make`'s return value is the same as the type of its argument, not a pointer to it.
//
// Note: Prefer using the procedure group `make`.
@(builtin, require_results)
make_map :: proc($T: typeid/map[$K]$E, #any_int capacity: int = 1<<MAP_MIN_LOG2_CAPACITY, allocator := context.allocator, loc := #caller_location) -> (m: T, err: Allocator_Error) #optional_allocator_error {
make_map :: proc($T: typeid/map[$K]$E, allocator := context.allocator) -> (m: T) {
m.allocator = allocator
return m
}
// `make_map_cap` initializes a map with an allocator and allocates space using `capacity`.
// Like `new`, the first argument is a type, not a value.
// Unlike `new`, `make`'s return value is the same as the type of its argument, not a pointer to it.
//
// Note: Prefer using the procedure group `make`.
@(builtin, require_results)
make_map_cap :: proc($T: typeid/map[$K]$E, #any_int capacity: int = 1<<MAP_MIN_LOG2_CAPACITY, allocator := context.allocator, loc := #caller_location) -> (m: T, err: Allocator_Error) #optional_allocator_error {
make_map_expr_error_loc(loc, capacity)
context.allocator = allocator
err = reserve_map(&m, capacity, loc)
return
}
// `make_multi_pointer` allocates and initializes a dynamic array. Like `new`, the first argument is a type, not a value.
// `make_multi_pointer` allocates and initializes a multi-pointer. Like `new`, the first argument is a type, not a value.
// Unlike `new`, `make`'s return value is the same as the type of its argument, not a pointer to it.
//
// This is "similar" to doing `raw_data(make([]E, len, allocator))`.
@@ -363,7 +436,13 @@ make :: proc{
make_dynamic_array_len,
make_dynamic_array_len_cap,
make_map,
make_map_cap,
make_multi_pointer,
make_soa_slice,
make_soa_dynamic_array,
make_soa_dynamic_array_len,
make_soa_dynamic_array_len_cap,
}
@@ -383,7 +462,7 @@ clear_map :: proc "contextless" (m: ^$T/map[$K]$V) {
//
// Note: Prefer the procedure group `reserve`
@builtin
reserve_map :: proc(m: ^$T/map[$K]$V, capacity: int, loc := #caller_location) -> Allocator_Error {
reserve_map :: proc(m: ^$T/map[$K]$V, #any_int capacity: int, loc := #caller_location) -> Allocator_Error {
return __dynamic_map_reserve((^Raw_Map)(m), map_info(T), uint(capacity), loc) if m != nil else nil
}
@@ -413,106 +492,103 @@ delete_key :: proc(m: ^$T/map[$K]$V, key: K) -> (deleted_key: K, deleted_value:
return
}
_append_elem :: #force_inline proc(array: ^$T/[dynamic]$E, arg: E, should_zero: bool, loc := #caller_location) -> (n: int, err: Allocator_Error) #optional_allocator_error {
_append_elem :: #force_inline proc(array: ^Raw_Dynamic_Array, size_of_elem, align_of_elem: int, arg_ptr: rawptr, should_zero: bool, loc := #caller_location) -> (n: int, err: Allocator_Error) #optional_allocator_error {
if array == nil {
return 0, nil
return
}
when size_of(E) == 0 {
array := (^Raw_Dynamic_Array)(array)
array.len += 1
return 1, nil
} else {
if cap(array) < len(array)+1 {
cap := 2 * cap(array) + max(8, 1)
// do not 'or_return' here as it could be a partial success
if should_zero {
err = reserve(array, cap, loc)
} else {
err = non_zero_reserve(array, cap, loc)
}
}
if cap(array)-len(array) > 0 {
a := (^Raw_Dynamic_Array)(array)
when size_of(E) != 0 {
data := ([^]E)(a.data)
assert(data != nil, loc=loc)
data[a.len] = arg
}
a.len += 1
return 1, err
}
return 0, err
if array.cap < array.len+1 {
// Same behavior as _append_elems but there's only one arg, so we always just add DEFAULT_DYNAMIC_ARRAY_CAPACITY.
cap := 2 * array.cap + DEFAULT_DYNAMIC_ARRAY_CAPACITY
// do not 'or_return' here as it could be a partial success
err = _reserve_dynamic_array(array, size_of_elem, align_of_elem, cap, should_zero, loc)
}
if array.cap-array.len > 0 {
data := ([^]byte)(array.data)
assert(data != nil, loc=loc)
data = data[array.len*size_of_elem:]
intrinsics.mem_copy_non_overlapping(data, arg_ptr, size_of_elem)
array.len += 1
n = 1
}
return
}
@builtin
append_elem :: proc(array: ^$T/[dynamic]$E, #no_broadcast arg: E, loc := #caller_location) -> (n: int, err: Allocator_Error) #optional_allocator_error {
return _append_elem(array, arg, true, loc=loc)
when size_of(E) == 0 {
(^Raw_Dynamic_Array)(array).len += 1
return 1, nil
} else {
arg := arg
return _append_elem((^Raw_Dynamic_Array)(array), size_of(E), align_of(E), &arg, true, loc=loc)
}
}
@builtin
non_zero_append_elem :: proc(array: ^$T/[dynamic]$E, #no_broadcast arg: E, loc := #caller_location) -> (n: int, err: Allocator_Error) #optional_allocator_error {
return _append_elem(array, arg, false, loc=loc)
when size_of(E) == 0 {
(^Raw_Dynamic_Array)(array).len += 1
return 1, nil
} else {
arg := arg
return _append_elem((^Raw_Dynamic_Array)(array), size_of(E), align_of(E), &arg, false, loc=loc)
}
}
_append_elems :: #force_inline proc(array: ^$T/[dynamic]$E, should_zero: bool, loc := #caller_location, args: ..E) -> (n: int, err: Allocator_Error) #optional_allocator_error {
_append_elems :: #force_inline proc(array: ^Raw_Dynamic_Array, size_of_elem, align_of_elem: int, should_zero: bool, loc := #caller_location, args: rawptr, arg_len: int) -> (n: int, err: Allocator_Error) #optional_allocator_error {
if array == nil {
return 0, nil
}
arg_len := len(args)
if arg_len <= 0 {
return 0, nil
}
when size_of(E) == 0 {
array := (^Raw_Dynamic_Array)(array)
array.len += arg_len
return arg_len, nil
} else {
if cap(array) < len(array)+arg_len {
cap := 2 * cap(array) + max(8, arg_len)
if array.cap < array.len+arg_len {
cap := 2 * array.cap + max(DEFAULT_DYNAMIC_ARRAY_CAPACITY, arg_len)
// do not 'or_return' here as it could be a partial success
if should_zero {
err = reserve(array, cap, loc)
} else {
err = non_zero_reserve(array, cap, loc)
}
}
arg_len = min(cap(array)-len(array), arg_len)
if arg_len > 0 {
a := (^Raw_Dynamic_Array)(array)
when size_of(E) != 0 {
data := ([^]E)(a.data)
assert(data != nil, loc=loc)
intrinsics.mem_copy(&data[a.len], raw_data(args), size_of(E) * arg_len)
}
a.len += arg_len
}
return arg_len, err
// do not 'or_return' here as it could be a partial success
err = _reserve_dynamic_array(array, size_of_elem, align_of_elem, cap, should_zero, loc)
}
arg_len := arg_len
arg_len = min(array.cap-array.len, arg_len)
if arg_len > 0 {
data := ([^]byte)(array.data)
assert(data != nil, loc=loc)
data = data[array.len*size_of_elem:]
intrinsics.mem_copy(data, args, size_of_elem * arg_len) // must be mem_copy (overlapping)
array.len += arg_len
}
return arg_len, err
}
@builtin
append_elems :: proc(array: ^$T/[dynamic]$E, #no_broadcast args: ..E, loc := #caller_location) -> (n: int, err: Allocator_Error) #optional_allocator_error {
return _append_elems(array, true, loc, ..args)
when size_of(E) == 0 {
a := (^Raw_Dynamic_Array)(array)
a.len += len(args)
return len(args), nil
} else {
return _append_elems((^Raw_Dynamic_Array)(array), size_of(E), align_of(E), true, loc, raw_data(args), len(args))
}
}
@builtin
non_zero_append_elems :: proc(array: ^$T/[dynamic]$E, #no_broadcast args: ..E, loc := #caller_location) -> (n: int, err: Allocator_Error) #optional_allocator_error {
return _append_elems(array, false, loc, ..args)
when size_of(E) == 0 {
a := (^Raw_Dynamic_Array)(array)
a.len += len(args)
return len(args), nil
} else {
return _append_elems((^Raw_Dynamic_Array)(array), size_of(E), align_of(E), false, loc, raw_data(args), len(args))
}
}
// The append_string built-in procedure appends a string to the end of a [dynamic]u8 like type
_append_elem_string :: proc(array: ^$T/[dynamic]$E/u8, arg: $A/string, should_zero: bool, loc := #caller_location) -> (n: int, err: Allocator_Error) #optional_allocator_error {
args := transmute([]E)arg
if should_zero {
return append_elems(array, ..args, loc=loc)
} else {
return non_zero_append_elems(array, ..args, loc=loc)
}
return _append_elems((^Raw_Dynamic_Array)(array), 1, 1, should_zero, loc, raw_data(arg), len(arg))
}
@builtin
@@ -540,8 +616,23 @@ append_string :: proc(array: ^$T/[dynamic]$E/u8, args: ..string, loc := #caller_
}
// The append built-in procedure appends elements to the end of a dynamic array
@builtin append :: proc{append_elem, append_elems, append_elem_string}
@builtin non_zero_append :: proc{non_zero_append_elem, non_zero_append_elems, non_zero_append_elem_string}
@builtin append :: proc{
append_elem,
append_elems,
append_elem_string,
append_soa_elem,
append_soa_elems,
}
@builtin non_zero_append :: proc{
non_zero_append_elem,
non_zero_append_elems,
non_zero_append_elem_string,
non_zero_append_soa_elem,
non_zero_append_soa_elems,
}
@builtin
@@ -556,7 +647,7 @@ append_nothing :: proc(array: ^$T/[dynamic]$E, loc := #caller_location) -> (n: i
@builtin
inject_at_elem :: proc(array: ^$T/[dynamic]$E, index: int, #no_broadcast arg: E, loc := #caller_location) -> (ok: bool, err: Allocator_Error) #no_bounds_check #optional_allocator_error {
inject_at_elem :: proc(array: ^$T/[dynamic]$E, #any_int index: int, #no_broadcast arg: E, loc := #caller_location) -> (ok: bool, err: Allocator_Error) #no_bounds_check #optional_allocator_error {
if array == nil {
return
}
@@ -574,7 +665,7 @@ inject_at_elem :: proc(array: ^$T/[dynamic]$E, index: int, #no_broadcast arg: E,
}
@builtin
inject_at_elems :: proc(array: ^$T/[dynamic]$E, index: int, #no_broadcast args: ..E, loc := #caller_location) -> (ok: bool, err: Allocator_Error) #no_bounds_check #optional_allocator_error {
inject_at_elems :: proc(array: ^$T/[dynamic]$E, #any_int index: int, #no_broadcast args: ..E, loc := #caller_location) -> (ok: bool, err: Allocator_Error) #no_bounds_check #optional_allocator_error {
if array == nil {
return
}
@@ -597,7 +688,7 @@ inject_at_elems :: proc(array: ^$T/[dynamic]$E, index: int, #no_broadcast args:
}
@builtin
inject_at_elem_string :: proc(array: ^$T/[dynamic]$E/u8, index: int, arg: string, loc := #caller_location) -> (ok: bool, err: Allocator_Error) #no_bounds_check #optional_allocator_error {
inject_at_elem_string :: proc(array: ^$T/[dynamic]$E/u8, #any_int index: int, arg: string, loc := #caller_location) -> (ok: bool, err: Allocator_Error) #no_bounds_check #optional_allocator_error {
if array == nil {
return
}
@@ -622,7 +713,7 @@ inject_at_elem_string :: proc(array: ^$T/[dynamic]$E/u8, index: int, arg: string
@builtin
assign_at_elem :: proc(array: ^$T/[dynamic]$E, index: int, arg: E, loc := #caller_location) -> (ok: bool, err: Allocator_Error) #no_bounds_check #optional_allocator_error {
assign_at_elem :: proc(array: ^$T/[dynamic]$E, #any_int index: int, arg: E, loc := #caller_location) -> (ok: bool, err: Allocator_Error) #no_bounds_check #optional_allocator_error {
if index < len(array) {
array[index] = arg
ok = true
@@ -636,7 +727,7 @@ assign_at_elem :: proc(array: ^$T/[dynamic]$E, index: int, arg: E, loc := #calle
@builtin
assign_at_elems :: proc(array: ^$T/[dynamic]$E, index: int, args: ..E, loc := #caller_location) -> (ok: bool, err: Allocator_Error) #no_bounds_check #optional_allocator_error {
assign_at_elems :: proc(array: ^$T/[dynamic]$E, #any_int index: int, #no_broadcast args: ..E, loc := #caller_location) -> (ok: bool, err: Allocator_Error) #no_bounds_check #optional_allocator_error {
new_size := index + len(args)
if len(args) == 0 {
ok = true
@@ -653,7 +744,7 @@ assign_at_elems :: proc(array: ^$T/[dynamic]$E, index: int, args: ..E, loc := #c
@builtin
assign_at_elem_string :: proc(array: ^$T/[dynamic]$E/u8, index: int, arg: string, loc := #caller_location) -> (ok: bool, err: Allocator_Error) #no_bounds_check #optional_allocator_error {
assign_at_elem_string :: proc(array: ^$T/[dynamic]$E/u8, #any_int index: int, arg: string, loc := #caller_location) -> (ok: bool, err: Allocator_Error) #no_bounds_check #optional_allocator_error {
new_size := index + len(arg)
if len(arg) == 0 {
ok = true
@@ -686,11 +777,10 @@ clear_dynamic_array :: proc "contextless" (array: ^$T/[dynamic]$E) {
// `reserve_dynamic_array` will try to reserve memory of a passed dynamic array or map to the requested element count (setting the `cap`).
//
// Note: Prefer the procedure group `reserve`.
_reserve_dynamic_array :: #force_inline proc(array: ^$T/[dynamic]$E, capacity: int, should_zero: bool, loc := #caller_location) -> Allocator_Error {
if array == nil {
_reserve_dynamic_array :: #force_inline proc(a: ^Raw_Dynamic_Array, size_of_elem, align_of_elem: int, capacity: int, should_zero: bool, loc := #caller_location) -> Allocator_Error {
if a == nil {
return nil
}
a := (^Raw_Dynamic_Array)(array)
if capacity <= a.cap {
return nil
@@ -701,15 +791,15 @@ _reserve_dynamic_array :: #force_inline proc(array: ^$T/[dynamic]$E, capacity: i
}
assert(a.allocator.procedure != nil)
old_size := a.cap * size_of(E)
new_size := capacity * size_of(E)
old_size := a.cap * size_of_elem
new_size := capacity * size_of_elem
allocator := a.allocator
new_data: []byte
if should_zero {
new_data = mem_resize(a.data, old_size, new_size, align_of(E), allocator, loc) or_return
new_data = mem_resize(a.data, old_size, new_size, align_of_elem, allocator, loc) or_return
} else {
new_data = non_zero_mem_resize(a.data, old_size, new_size, align_of(E), allocator, loc) or_return
new_data = non_zero_mem_resize(a.data, old_size, new_size, align_of_elem, allocator, loc) or_return
}
if new_data == nil && new_size > 0 {
return .Out_Of_Memory
@@ -721,27 +811,24 @@ _reserve_dynamic_array :: #force_inline proc(array: ^$T/[dynamic]$E, capacity: i
}
@builtin
reserve_dynamic_array :: proc(array: ^$T/[dynamic]$E, capacity: int, loc := #caller_location) -> Allocator_Error {
return _reserve_dynamic_array(array, capacity, true, loc)
reserve_dynamic_array :: proc(array: ^$T/[dynamic]$E, #any_int capacity: int, loc := #caller_location) -> Allocator_Error {
return _reserve_dynamic_array((^Raw_Dynamic_Array)(array), size_of(E), align_of(E), capacity, true, loc)
}
@builtin
non_zero_reserve_dynamic_array :: proc(array: ^$T/[dynamic]$E, capacity: int, loc := #caller_location) -> Allocator_Error {
return _reserve_dynamic_array(array, capacity, false, loc)
non_zero_reserve_dynamic_array :: proc(array: ^$T/[dynamic]$E, #any_int capacity: int, loc := #caller_location) -> Allocator_Error {
return _reserve_dynamic_array((^Raw_Dynamic_Array)(array), size_of(E), align_of(E), capacity, false, loc)
}
// `resize_dynamic_array` will try to resize memory of a passed dynamic array or map to the requested element count (setting the `len`, and possibly `cap`).
//
// Note: Prefer the procedure group `resize`
_resize_dynamic_array :: #force_inline proc(array: ^$T/[dynamic]$E, length: int, should_zero: bool, loc := #caller_location) -> Allocator_Error {
if array == nil {
_resize_dynamic_array :: #force_inline proc(a: ^Raw_Dynamic_Array, size_of_elem, align_of_elem: int, length: int, should_zero: bool, loc := #caller_location) -> Allocator_Error {
if a == nil {
return nil
}
a := (^Raw_Dynamic_Array)(array)
if length <= a.cap {
if should_zero && a.len < length {
intrinsics.mem_zero(([^]E)(a.data)[a.len:], (length-a.len)*size_of(E))
intrinsics.mem_zero(([^]byte)(a.data)[a.len*size_of_elem:], (length-a.len)*size_of_elem)
}
a.len = max(length, 0)
return nil
@@ -752,15 +839,15 @@ _resize_dynamic_array :: #force_inline proc(array: ^$T/[dynamic]$E, length: int,
}
assert(a.allocator.procedure != nil)
old_size := a.cap * size_of(E)
new_size := length * size_of(E)
old_size := a.cap * size_of_elem
new_size := length * size_of_elem
allocator := a.allocator
new_data : []byte
if should_zero {
new_data = mem_resize(a.data, old_size, new_size, align_of(E), allocator, loc) or_return
new_data = mem_resize(a.data, old_size, new_size, align_of_elem, allocator, loc) or_return
} else {
new_data = non_zero_mem_resize(a.data, old_size, new_size, align_of(E), allocator, loc) or_return
new_data = non_zero_mem_resize(a.data, old_size, new_size, align_of_elem, allocator, loc) or_return
}
if new_data == nil && new_size > 0 {
return .Out_Of_Memory
@@ -772,14 +859,17 @@ _resize_dynamic_array :: #force_inline proc(array: ^$T/[dynamic]$E, length: int,
return nil
}
// `resize_dynamic_array` will try to resize memory of a passed dynamic array or map to the requested element count (setting the `len`, and possibly `cap`).
//
// Note: Prefer the procedure group `resize`
@builtin
resize_dynamic_array :: proc(array: ^$T/[dynamic]$E, length: int, loc := #caller_location) -> Allocator_Error {
return _resize_dynamic_array(array, length, true, loc=loc)
resize_dynamic_array :: proc(array: ^$T/[dynamic]$E, #any_int length: int, loc := #caller_location) -> Allocator_Error {
return _resize_dynamic_array((^Raw_Dynamic_Array)(array), size_of(E), align_of(E), length, true, loc=loc)
}
@builtin
non_zero_resize_dynamic_array :: proc(array: ^$T/[dynamic]$E, length: int, loc := #caller_location) -> Allocator_Error {
return _resize_dynamic_array(array, length, false, loc=loc)
non_zero_resize_dynamic_array :: proc(array: ^$T/[dynamic]$E, #any_int length: int, loc := #caller_location) -> Allocator_Error {
return _resize_dynamic_array((^Raw_Dynamic_Array)(array), size_of(E), align_of(E), length, false, loc=loc)
}
/*
@@ -793,11 +883,14 @@ non_zero_resize_dynamic_array :: proc(array: ^$T/[dynamic]$E, length: int, loc :
Note: Prefer the procedure group `shrink`
*/
shrink_dynamic_array :: proc(array: ^$T/[dynamic]$E, new_cap := -1, loc := #caller_location) -> (did_shrink: bool, err: Allocator_Error) {
if array == nil {
shrink_dynamic_array :: proc(array: ^$T/[dynamic]$E, #any_int new_cap := -1, loc := #caller_location) -> (did_shrink: bool, err: Allocator_Error) {
return _shrink_dynamic_array((^Raw_Dynamic_Array)(array), size_of(E), align_of(E), new_cap, loc)
}
_shrink_dynamic_array :: proc(a: ^Raw_Dynamic_Array, size_of_elem, align_of_elem: int, new_cap := -1, loc := #caller_location) -> (did_shrink: bool, err: Allocator_Error) {
if a == nil {
return
}
a := (^Raw_Dynamic_Array)(array)
new_cap := new_cap if new_cap >= 0 else a.len
@@ -810,10 +903,10 @@ shrink_dynamic_array :: proc(array: ^$T/[dynamic]$E, new_cap := -1, loc := #call
}
assert(a.allocator.procedure != nil)
old_size := a.cap * size_of(E)
new_size := new_cap * size_of(E)
old_size := a.cap * size_of_elem
new_size := new_cap * size_of_elem
new_data := mem_resize(a.data, old_size, new_size, align_of(E), a.allocator, loc) or_return
new_data := mem_resize(a.data, old_size, new_size, align_of_elem, a.allocator, loc) or_return
a.data = raw_data(new_data)
a.len = min(new_cap, a.len)
@@ -846,26 +939,14 @@ map_upsert :: proc(m: ^$T/map[$K]$V, key: K, value: V, loc := #caller_location)
@builtin
card :: proc "contextless" (s: $S/bit_set[$E; $U]) -> int {
when size_of(S) == 1 {
return int(intrinsics.count_ones(transmute(u8)s))
} else when size_of(S) == 2 {
return int(intrinsics.count_ones(transmute(u16)s))
} else when size_of(S) == 4 {
return int(intrinsics.count_ones(transmute(u32)s))
} else when size_of(S) == 8 {
return int(intrinsics.count_ones(transmute(u64)s))
} else when size_of(S) == 16 {
return int(intrinsics.count_ones(transmute(u128)s))
} else {
#panic("Unhandled card bit_set size")
}
return int(intrinsics.count_ones(transmute(intrinsics.type_bit_set_underlying_type(S))s))
}
@builtin
@(disabled=ODIN_DISABLE_ASSERT)
assert :: proc(condition: bool, message := "", loc := #caller_location) {
assert :: proc(condition: bool, message := #caller_expression(condition), loc := #caller_location) {
if !condition {
// NOTE(bill): This is wrapped in a procedure call
// to improve performance to make the CPU not
@@ -900,3 +981,30 @@ unimplemented :: proc(message := "", loc := #caller_location) -> ! {
}
p("not yet implemented", message, loc)
}
@builtin
@(disabled=ODIN_DISABLE_ASSERT)
assert_contextless :: proc "contextless" (condition: bool, message := #caller_expression(condition), loc := #caller_location) {
if !condition {
// NOTE(bill): This is wrapped in a procedure call
// to improve performance to make the CPU not
// execute speculatively, making it about an order of
// magnitude faster
@(cold)
internal :: proc "contextless" (message: string, loc: Source_Code_Location) {
default_assertion_contextless_failure_proc("runtime assertion", message, loc)
}
internal(message, loc)
}
}
@builtin
panic_contextless :: proc "contextless" (message: string, loc := #caller_location) -> ! {
default_assertion_contextless_failure_proc("panic", message, loc)
}
@builtin
unimplemented_contextless :: proc "contextless" (message := "", loc := #caller_location) -> ! {
default_assertion_contextless_failure_proc("not yet implemented", message, loc)
}
+78 -64
View File
@@ -55,7 +55,7 @@ raw_soa_footer_slice :: proc(array: ^$T/#soa[]$E) -> (footer: ^Raw_SOA_Footer_Sl
if array == nil {
return nil
}
field_count := uintptr(intrinsics.type_struct_field_count(E))
field_count := uintptr(len(E) when intrinsics.type_is_array(E) else intrinsics.type_struct_field_count(E))
footer = (^Raw_SOA_Footer_Slice)(uintptr(array) + field_count*size_of(rawptr))
return
}
@@ -64,12 +64,7 @@ raw_soa_footer_dynamic_array :: proc(array: ^$T/#soa[dynamic]$E) -> (footer: ^Ra
if array == nil {
return nil
}
field_count: uintptr
when intrinsics.type_is_array(E) {
field_count = len(E)
} else {
field_count = uintptr(intrinsics.type_struct_field_count(E))
}
field_count := uintptr(len(E) when intrinsics.type_is_array(E) else intrinsics.type_struct_field_count(E))
footer = (^Raw_SOA_Footer_Dynamic_Array)(uintptr(array) + field_count*size_of(rawptr))
return
}
@@ -81,7 +76,7 @@ raw_soa_footer :: proc{
@(builtin, require_results)
make_soa_aligned :: proc($T: typeid/#soa[]$E, length: int, alignment: int, allocator := context.allocator, loc := #caller_location) -> (array: T, err: Allocator_Error) #optional_allocator_error {
make_soa_aligned :: proc($T: typeid/#soa[]$E, #any_int length, alignment: int, allocator := context.allocator, loc := #caller_location) -> (array: T, err: Allocator_Error) #optional_allocator_error {
if length <= 0 {
return
}
@@ -98,11 +93,11 @@ make_soa_aligned :: proc($T: typeid/#soa[]$E, length: int, alignment: int, alloc
ti = type_info_base(ti)
si := &ti.variant.(Type_Info_Struct)
field_count := uintptr(intrinsics.type_struct_field_count(E))
field_count := uintptr(len(E) when intrinsics.type_is_array(E) else intrinsics.type_struct_field_count(E))
total_size := 0
for i in 0..<field_count {
type := si.types[i].variant.(Type_Info_Pointer).elem
type := si.types[i].variant.(Type_Info_Multi_Pointer).elem
total_size += type.size * length
total_size = align_forward_int(total_size, max_align)
}
@@ -126,7 +121,7 @@ make_soa_aligned :: proc($T: typeid/#soa[]$E, length: int, alignment: int, alloc
data := uintptr(&array)
offset := 0
for i in 0..<field_count {
type := si.types[i].variant.(Type_Info_Pointer).elem
type := si.types[i].variant.(Type_Info_Multi_Pointer).elem
offset = align_forward_int(offset, max_align)
@@ -140,14 +135,14 @@ make_soa_aligned :: proc($T: typeid/#soa[]$E, length: int, alignment: int, alloc
}
@(builtin, require_results)
make_soa_slice :: proc($T: typeid/#soa[]$E, length: int, allocator := context.allocator, loc := #caller_location) -> (array: T, err: Allocator_Error) #optional_allocator_error {
make_soa_slice :: proc($T: typeid/#soa[]$E, #any_int length: int, allocator := context.allocator, loc := #caller_location) -> (array: T, err: Allocator_Error) #optional_allocator_error {
return make_soa_aligned(T, length, align_of(E), allocator, loc)
}
@(builtin, require_results)
make_soa_dynamic_array :: proc($T: typeid/#soa[dynamic]$E, allocator := context.allocator, loc := #caller_location) -> (array: T, err: Allocator_Error) #optional_allocator_error {
context.allocator = allocator
reserve_soa(&array, DEFAULT_RESERVE_CAPACITY, loc) or_return
reserve_soa(&array, 0, loc) or_return
return array, nil
}
@@ -177,7 +172,7 @@ make_soa :: proc{
@builtin
resize_soa :: proc(array: ^$T/#soa[dynamic]$E, length: int, loc := #caller_location) -> Allocator_Error {
resize_soa :: proc(array: ^$T/#soa[dynamic]$E, #any_int length: int, loc := #caller_location) -> Allocator_Error {
if array == nil {
return nil
}
@@ -188,7 +183,27 @@ resize_soa :: proc(array: ^$T/#soa[dynamic]$E, length: int, loc := #caller_locat
}
@builtin
reserve_soa :: proc(array: ^$T/#soa[dynamic]$E, capacity: int, loc := #caller_location) -> Allocator_Error {
non_zero_resize_soa :: proc(array: ^$T/#soa[dynamic]$E, #any_int length: int, loc := #caller_location) -> Allocator_Error {
if array == nil {
return nil
}
non_zero_reserve_soa(array, length, loc) or_return
footer := raw_soa_footer(array)
footer.len = length
return nil
}
@builtin
reserve_soa :: proc(array: ^$T/#soa[dynamic]$E, #any_int capacity: int, loc := #caller_location) -> Allocator_Error {
return _reserve_soa(array, capacity, true, loc)
}
@builtin
non_zero_reserve_soa :: proc(array: ^$T/#soa[dynamic]$E, #any_int capacity: int, loc := #caller_location) -> Allocator_Error {
return _reserve_soa(array, capacity, false, loc)
}
_reserve_soa :: proc(array: ^$T/#soa[dynamic]$E, capacity: int, zero_memory: bool, loc := #caller_location) -> Allocator_Error {
if array == nil {
return nil
}
@@ -213,12 +228,7 @@ reserve_soa :: proc(array: ^$T/#soa[dynamic]$E, capacity: int, loc := #caller_lo
ti = type_info_base(ti)
si := &ti.variant.(Type_Info_Struct)
field_count: uintptr
when intrinsics.type_is_array(E) {
field_count = len(E)
} else {
field_count = uintptr(intrinsics.type_struct_field_count(E))
}
field_count := uintptr(len(E) when intrinsics.type_is_array(E) else intrinsics.type_struct_field_count(E))
assert(footer.cap == old_cap)
old_size := 0
@@ -226,7 +236,7 @@ reserve_soa :: proc(array: ^$T/#soa[dynamic]$E, capacity: int, loc := #caller_lo
max_align :: align_of(E)
for i in 0..<field_count {
type := si.types[i].variant.(Type_Info_Pointer).elem
type := si.types[i].variant.(Type_Info_Multi_Pointer).elem
old_size += type.size * old_cap
new_size += type.size * capacity
@@ -238,7 +248,7 @@ reserve_soa :: proc(array: ^$T/#soa[dynamic]$E, capacity: int, loc := #caller_lo
old_data := (^rawptr)(array)^
new_bytes := array.allocator.procedure(
array.allocator.data, .Alloc, new_size, max_align,
array.allocator.data, .Alloc if zero_memory else .Alloc_Non_Zeroed, new_size, max_align,
nil, old_size, loc,
) or_return
new_data := raw_data(new_bytes)
@@ -249,7 +259,7 @@ reserve_soa :: proc(array: ^$T/#soa[dynamic]$E, capacity: int, loc := #caller_lo
old_offset := 0
new_offset := 0
for i in 0..<field_count {
type := si.types[i].variant.(Type_Info_Pointer).elem
type := si.types[i].variant.(Type_Info_Multi_Pointer).elem
old_offset = align_forward_int(old_offset, max_align)
new_offset = align_forward_int(new_offset, max_align)
@@ -273,15 +283,26 @@ reserve_soa :: proc(array: ^$T/#soa[dynamic]$E, capacity: int, loc := #caller_lo
return nil
}
@builtin
append_soa_elem :: proc(array: ^$T/#soa[dynamic]$E, arg: E, loc := #caller_location) -> (n: int, err: Allocator_Error) #optional_allocator_error {
append_soa_elem :: proc(array: ^$T/#soa[dynamic]$E, #no_broadcast arg: E, loc := #caller_location) -> (n: int, err: Allocator_Error) #optional_allocator_error {
return _append_soa_elem(array, true, arg, loc)
}
@builtin
non_zero_append_soa_elem :: proc(array: ^$T/#soa[dynamic]$E, #no_broadcast arg: E, loc := #caller_location) -> (n: int, err: Allocator_Error) #optional_allocator_error {
return _append_soa_elem(array, false, arg, loc)
}
_append_soa_elem :: proc(array: ^$T/#soa[dynamic]$E, zero_memory: bool, #no_broadcast arg: E, loc := #caller_location) -> (n: int, err: Allocator_Error) #optional_allocator_error {
if array == nil {
return 0, nil
}
if cap(array) <= len(array) + 1 {
cap := 2 * cap(array) + 8
err = reserve_soa(array, cap, loc) // do not 'or_return' here as it could be a partial success
// Same behavior as append_soa_elems but there's only one arg, so we always just add DEFAULT_DYNAMIC_ARRAY_CAPACITY.
cap := 2 * cap(array) + DEFAULT_DYNAMIC_ARRAY_CAPACITY
err = _reserve_soa(array, cap, zero_memory, loc) // do not 'or_return' here as it could be a partial success
}
footer := raw_soa_footer(array)
@@ -290,12 +311,7 @@ append_soa_elem :: proc(array: ^$T/#soa[dynamic]$E, arg: E, loc := #caller_locat
ti := type_info_of(T)
ti = type_info_base(ti)
si := &ti.variant.(Type_Info_Struct)
field_count: uintptr
when intrinsics.type_is_array(E) {
field_count = len(E)
} else {
field_count = uintptr(intrinsics.type_struct_field_count(E))
}
field_count := uintptr(len(E) when intrinsics.type_is_array(E) else intrinsics.type_struct_field_count(E))
data := (^rawptr)(array)^
@@ -307,7 +323,7 @@ append_soa_elem :: proc(array: ^$T/#soa[dynamic]$E, arg: E, loc := #caller_locat
max_align :: align_of(E)
for i in 0..<field_count {
type := si.types[i].variant.(Type_Info_Pointer).elem
type := si.types[i].variant.(Type_Info_Multi_Pointer).elem
soa_offset = align_forward_int(soa_offset, max_align)
item_offset = align_forward_int(item_offset, type.align)
@@ -326,7 +342,17 @@ append_soa_elem :: proc(array: ^$T/#soa[dynamic]$E, arg: E, loc := #caller_locat
}
@builtin
append_soa_elems :: proc(array: ^$T/#soa[dynamic]$E, args: ..E, loc := #caller_location) -> (n: int, err: Allocator_Error) #optional_allocator_error {
append_soa_elems :: proc(array: ^$T/#soa[dynamic]$E, #no_broadcast args: ..E, loc := #caller_location) -> (n: int, err: Allocator_Error) #optional_allocator_error {
return _append_soa_elems(array, true, args=args, loc=loc)
}
@builtin
non_zero_append_soa_elems :: proc(array: ^$T/#soa[dynamic]$E, #no_broadcast args: ..E, loc := #caller_location) -> (n: int, err: Allocator_Error) #optional_allocator_error {
return _append_soa_elems(array, false, args=args, loc=loc)
}
_append_soa_elems :: proc(array: ^$T/#soa[dynamic]$E, zero_memory: bool, #no_broadcast args: []E, loc := #caller_location) -> (n: int, err: Allocator_Error) #optional_allocator_error {
if array == nil {
return
}
@@ -337,8 +363,8 @@ append_soa_elems :: proc(array: ^$T/#soa[dynamic]$E, args: ..E, loc := #caller_l
}
if cap(array) <= len(array)+arg_len {
cap := 2 * cap(array) + max(8, arg_len)
err = reserve_soa(array, cap, loc) // do not 'or_return' here as it could be a partial success
cap := 2 * cap(array) + max(DEFAULT_DYNAMIC_ARRAY_CAPACITY, arg_len)
err = _reserve_soa(array, cap, zero_memory, loc) // do not 'or_return' here as it could be a partial success
}
arg_len = min(cap(array)-len(array), arg_len)
@@ -347,7 +373,7 @@ append_soa_elems :: proc(array: ^$T/#soa[dynamic]$E, args: ..E, loc := #caller_l
ti := type_info_of(typeid_of(T))
ti = type_info_base(ti)
si := &ti.variant.(Type_Info_Struct)
field_count := uintptr(intrinsics.type_struct_field_count(E))
field_count := uintptr(len(E) when intrinsics.type_is_array(E) else intrinsics.type_struct_field_count(E))
data := (^rawptr)(array)^
@@ -358,7 +384,7 @@ append_soa_elems :: proc(array: ^$T/#soa[dynamic]$E, args: ..E, loc := #caller_l
max_align :: align_of(E)
for i in 0..<field_count {
type := si.types[i].variant.(Type_Info_Pointer).elem
type := si.types[i].variant.(Type_Info_Multi_Pointer).elem
soa_offset = align_forward_int(soa_offset, max_align)
item_offset = align_forward_int(item_offset, type.align)
@@ -389,7 +415,8 @@ append_soa :: proc{
delete_soa_slice :: proc(array: $T/#soa[]$E, allocator := context.allocator, loc := #caller_location) -> Allocator_Error {
when intrinsics.type_struct_field_count(E) != 0 {
field_count :: len(E) when intrinsics.type_is_array(E) else intrinsics.type_struct_field_count(E)
when field_count != 0 {
array := array
ptr := (^rawptr)(&array)^
free(ptr, allocator, loc) or_return
@@ -398,7 +425,8 @@ delete_soa_slice :: proc(array: $T/#soa[]$E, allocator := context.allocator, loc
}
delete_soa_dynamic_array :: proc(array: $T/#soa[dynamic]$E, loc := #caller_location) -> Allocator_Error {
when intrinsics.type_struct_field_count(E) != 0 {
field_count :: len(E) when intrinsics.type_is_array(E) else intrinsics.type_struct_field_count(E)
when field_count != 0 {
array := array
ptr := (^rawptr)(&array)^
footer := raw_soa_footer(&array)
@@ -416,7 +444,8 @@ delete_soa :: proc{
clear_soa_dynamic_array :: proc(array: ^$T/#soa[dynamic]$E) {
when intrinsics.type_struct_field_count(E) != 0 {
field_count :: len(E) when intrinsics.type_is_array(E) else intrinsics.type_struct_field_count(E)
when field_count != 0 {
footer := raw_soa_footer(array)
footer.len = 0
}
@@ -438,12 +467,7 @@ into_dynamic_soa :: proc(array: $T/#soa[]$E) -> #soa[dynamic]E {
allocator = nil_allocator(),
}
field_count: uintptr
when intrinsics.type_is_array(E) {
field_count = len(E)
} else {
field_count = uintptr(intrinsics.type_struct_field_count(E))
}
field_count := uintptr(len(E) when intrinsics.type_is_array(E) else intrinsics.type_struct_field_count(E))
array := array
dynamic_data := ([^]rawptr)(&d)[:field_count]
@@ -460,23 +484,18 @@ into_dynamic_soa :: proc(array: $T/#soa[]$E) -> #soa[dynamic]E {
// Note: If you the elements to remain in their order, use `ordered_remove_soa`.
// Note: If the index is out of bounds, this procedure will panic.
@builtin
unordered_remove_soa :: proc(array: ^$T/#soa[dynamic]$E, index: int, loc := #caller_location) #no_bounds_check {
unordered_remove_soa :: proc(array: ^$T/#soa[dynamic]$E, #any_int index: int, loc := #caller_location) #no_bounds_check {
bounds_check_error_loc(loc, index, len(array))
if index+1 < len(array) {
ti := type_info_of(typeid_of(T))
ti = type_info_base(ti)
si := &ti.variant.(Type_Info_Struct)
field_count: uintptr
when intrinsics.type_is_array(E) {
field_count = len(E)
} else {
field_count = uintptr(intrinsics.type_struct_field_count(E))
}
field_count := uintptr(len(E) when intrinsics.type_is_array(E) else intrinsics.type_struct_field_count(E))
data := uintptr(array)
for i in 0..<field_count {
type := si.types[i].variant.(Type_Info_Pointer).elem
type := si.types[i].variant.(Type_Info_Multi_Pointer).elem
offset := rawptr((^uintptr)(data)^ + uintptr(index*type.size))
final := rawptr((^uintptr)(data)^ + uintptr((len(array)-1)*type.size))
@@ -493,23 +512,18 @@ unordered_remove_soa :: proc(array: ^$T/#soa[dynamic]$E, index: int, loc := #cal
// Note: If you the elements do not have to remain in their order, prefer `unordered_remove_soa`.
// Note: If the index is out of bounds, this procedure will panic.
@builtin
ordered_remove_soa :: proc(array: ^$T/#soa[dynamic]$E, index: int, loc := #caller_location) #no_bounds_check {
ordered_remove_soa :: proc(array: ^$T/#soa[dynamic]$E, #any_int index: int, loc := #caller_location) #no_bounds_check {
bounds_check_error_loc(loc, index, len(array))
if index+1 < len(array) {
ti := type_info_of(typeid_of(T))
ti = type_info_base(ti)
si := &ti.variant.(Type_Info_Struct)
field_count: uintptr
when intrinsics.type_is_array(E) {
field_count = len(E)
} else {
field_count = uintptr(intrinsics.type_struct_field_count(E))
}
field_count := uintptr(len(E) when intrinsics.type_is_array(E) else intrinsics.type_struct_field_count(E))
data := uintptr(array)
for i in 0..<field_count {
type := si.types[i].variant.(Type_Info_Pointer).elem
type := si.types[i].variant.(Type_Info_Multi_Pointer).elem
offset := (^uintptr)(data)^ + uintptr(index*type.size)
length := type.size*(len(array) - index - 1)
@@ -6,6 +6,9 @@ when ODIN_DEFAULT_TO_NIL_ALLOCATOR {
} else when ODIN_DEFAULT_TO_PANIC_ALLOCATOR {
default_allocator_proc :: panic_allocator_proc
default_allocator :: panic_allocator
} else when ODIN_OS != .Orca && (ODIN_ARCH == .wasm32 || ODIN_ARCH == .wasm64p32) {
default_allocator :: default_wasm_allocator
default_allocator_proc :: wasm_allocator_proc
} else {
default_allocator :: heap_allocator
default_allocator_proc :: heap_allocator_proc
+2 -2
View File
@@ -1,8 +1,8 @@
package runtime
nil_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode,
size, alignment: int,
old_memory: rawptr, old_size: int, loc := #caller_location) -> ([]byte, Allocator_Error) {
size, alignment: int,
old_memory: rawptr, old_size: int, loc := #caller_location) -> ([]byte, Allocator_Error) {
switch mode {
case .Alloc, .Alloc_Non_Zeroed:
return nil, .Out_Of_Memory
@@ -12,6 +12,8 @@ Memory_Block :: struct {
capacity: uint,
}
// NOTE: This is a growing arena that is only used for the default temp allocator.
// For your own growing arena needs, prefer `Arena` from `core:mem/virtual`.
Arena :: struct {
backing_allocator: Allocator,
curr_block: ^Memory_Block,
@@ -127,7 +129,7 @@ arena_alloc :: proc(arena: ^Arena, size, alignment: uint, loc := #caller_locatio
return
}
// `arena_init` will initialize the arena with a usuable block.
// `arena_init` will initialize the arena with a usable block.
// This procedure is not necessary to use the Arena as the default zero as `arena_alloc` will set things up if necessary
@(require_results)
arena_init :: proc(arena: ^Arena, size: uint, backing_allocator: Allocator, loc := #caller_location) -> Allocator_Error {
@@ -1,7 +1,7 @@
package runtime
DEFAULT_TEMP_ALLOCATOR_BACKING_SIZE: int : #config(DEFAULT_TEMP_ALLOCATOR_BACKING_SIZE, 4 * Megabyte)
NO_DEFAULT_TEMP_ALLOCATOR: bool : ODIN_OS == .Freestanding || ODIN_OS == .JS || ODIN_DEFAULT_TO_NIL_ALLOCATOR
NO_DEFAULT_TEMP_ALLOCATOR: bool : ODIN_OS == .Freestanding || ODIN_DEFAULT_TO_NIL_ALLOCATOR
when NO_DEFAULT_TEMP_ALLOCATOR {
Default_Temp_Allocator :: struct {}
+1 -1
View File
@@ -157,7 +157,7 @@ __dynamic_map_get // dynamic map calls
__dynamic_map_set // dynamic map calls
## Dynamic literals ([dymamic]T and map[K]V) (can be disabled with -no-dynamic-literals)
## Dynamic literals ([dynamic]T and map[K]V) (can be disabled with -no-dynamic-literals)
__dynamic_array_reserve
__dynamic_array_append
+6 -6
View File
@@ -577,7 +577,7 @@ map_grow_dynamic :: proc "odin" (#no_alias m: ^Raw_Map, #no_alias info: ^Map_Inf
@(require_results)
map_reserve_dynamic :: proc "odin" (#no_alias m: ^Raw_Map, #no_alias info: ^Map_Info, new_capacity: uintptr, loc := #caller_location) -> Allocator_Error {
map_reserve_dynamic :: #force_no_inline proc "odin" (#no_alias m: ^Raw_Map, #no_alias info: ^Map_Info, new_capacity: uintptr, loc := #caller_location) -> Allocator_Error {
@(require_results)
ceil_log2 :: #force_inline proc "contextless" (x: uintptr) -> uintptr {
z := intrinsics.count_leading_zeros(x)
@@ -641,7 +641,7 @@ map_reserve_dynamic :: proc "odin" (#no_alias m: ^Raw_Map, #no_alias info: ^Map_
@(require_results)
map_shrink_dynamic :: proc "odin" (#no_alias m: ^Raw_Map, #no_alias info: ^Map_Info, loc := #caller_location) -> (did_shrink: bool, err: Allocator_Error) {
map_shrink_dynamic :: #force_no_inline proc "odin" (#no_alias m: ^Raw_Map, #no_alias info: ^Map_Info, loc := #caller_location) -> (did_shrink: bool, err: Allocator_Error) {
if m.allocator.procedure == nil {
m.allocator = context.allocator
}
@@ -688,7 +688,7 @@ map_shrink_dynamic :: proc "odin" (#no_alias m: ^Raw_Map, #no_alias info: ^Map_I
}
@(require_results)
map_free_dynamic :: proc "odin" (m: Raw_Map, info: ^Map_Info, loc := #caller_location) -> Allocator_Error {
map_free_dynamic :: #force_no_inline proc "odin" (m: Raw_Map, info: ^Map_Info, loc := #caller_location) -> Allocator_Error {
ptr := rawptr(map_data(m))
size := int(map_total_allocation_size(uintptr(map_cap(m)), info))
err := mem_free_with_size(ptr, size, m.allocator, loc)
@@ -700,7 +700,7 @@ map_free_dynamic :: proc "odin" (m: Raw_Map, info: ^Map_Info, loc := #caller_loc
}
@(require_results)
map_lookup_dynamic :: proc "contextless" (m: Raw_Map, #no_alias info: ^Map_Info, k: uintptr) -> (index: uintptr, ok: bool) {
map_lookup_dynamic :: #force_no_inline proc "contextless" (m: Raw_Map, #no_alias info: ^Map_Info, k: uintptr) -> (index: uintptr, ok: bool) {
if map_len(m) == 0 {
return 0, false
}
@@ -723,7 +723,7 @@ map_lookup_dynamic :: proc "contextless" (m: Raw_Map, #no_alias info: ^Map_Info,
}
}
@(require_results)
map_exists_dynamic :: proc "contextless" (m: Raw_Map, #no_alias info: ^Map_Info, k: uintptr) -> (ok: bool) {
map_exists_dynamic :: #force_no_inline proc "contextless" (m: Raw_Map, #no_alias info: ^Map_Info, k: uintptr) -> (ok: bool) {
if map_len(m) == 0 {
return false
}
@@ -749,7 +749,7 @@ map_exists_dynamic :: proc "contextless" (m: Raw_Map, #no_alias info: ^Map_Info,
@(require_results)
map_erase_dynamic :: #force_inline proc "contextless" (#no_alias m: ^Raw_Map, #no_alias info: ^Map_Info, k: uintptr) -> (old_k, old_v: uintptr, ok: bool) {
map_erase_dynamic :: #force_no_inline proc "contextless" (#no_alias m: ^Raw_Map, #no_alias info: ^Map_Info, k: uintptr) -> (old_k, old_v: uintptr, ok: bool) {
index := map_lookup_dynamic(m^, info, k) or_return
ks, vs, hs, _, _ := map_kvh_data_dynamic(m^, info)
hs[index] |= TOMBSTONE_MASK
+6 -3
View File
@@ -1,6 +1,6 @@
//+private
//+build linux, darwin, freebsd, openbsd, haiku
//+no-instrumentation
#+private
#+build linux, darwin, freebsd, openbsd, netbsd, haiku
#+no-instrumentation
package runtime
import "base:intrinsics"
@@ -34,6 +34,9 @@ when ODIN_BUILD_MODE == .Dynamic {
} else when ODIN_OS == .Darwin && ODIN_ARCH == .arm64 {
@require foreign import entry "entry_unix_no_crt_darwin_arm64.asm"
SYS_exit :: 1
} else when ODIN_ARCH == .riscv64 {
@require foreign import entry "entry_unix_no_crt_riscv64.asm"
SYS_exit :: 93
}
@(link_name="_start_odin", linkage="strong", require)
_start_odin :: proc "c" (argc: i32, argv: [^]cstring) -> ! {
@@ -0,0 +1,10 @@
.text
.globl _start
_start:
ld a0, 0(sp)
addi a1, sp, 8
addi sp, sp, ~15
call _start_odin
ebreak
+33 -14
View File
@@ -1,20 +1,39 @@
//+private
//+build wasm32, wasm64p32
//+no-instrumentation
#+private
#+build wasm32, wasm64p32
#+no-instrumentation
package runtime
import "base:intrinsics"
when !ODIN_TEST && !ODIN_NO_ENTRY_POINT {
@(link_name="_start", linkage="strong", require, export)
_start :: proc "c" () {
context = default_context()
#force_no_inline _startup_runtime()
intrinsics.__entry_point()
when ODIN_OS == .Orca {
@(linkage="strong", require, export)
oc_on_init :: proc "c" () {
context = default_context()
#force_no_inline _startup_runtime()
intrinsics.__entry_point()
}
@(linkage="strong", require, export)
oc_on_terminate :: proc "c" () {
context = default_context()
#force_no_inline _cleanup_runtime()
}
} else {
@(link_name="_start", linkage="strong", require, export)
_start :: proc "c" () {
context = default_context()
when ODIN_OS == .WASI {
_wasi_setup_args()
}
#force_no_inline _startup_runtime()
intrinsics.__entry_point()
}
@(link_name="_end", linkage="strong", require, export)
_end :: proc "c" () {
context = default_context()
#force_no_inline _cleanup_runtime()
}
}
@(link_name="_end", linkage="strong", require, export)
_end :: proc "c" () {
context = default_context()
#force_no_inline _cleanup_runtime()
}
}
}
+5 -4
View File
@@ -1,6 +1,6 @@
//+private
//+build windows
//+no-instrumentation
#+private
#+build windows
#+no-instrumentation
package runtime
import "base:intrinsics"
@@ -10,8 +10,9 @@ when ODIN_BUILD_MODE == .Dynamic {
DllMain :: proc "system" (hinstDLL: rawptr, fdwReason: u32, lpReserved: rawptr) -> b32 {
context = default_context()
// Populate Windows DLL-specific global
// Populate Windows DLL-specific globals
dll_forward_reason = DLL_Forward_Reason(fdwReason)
dll_instance = hinstDLL
switch dll_forward_reason {
case .Process_Attach:
+4
View File
@@ -4,6 +4,8 @@ package runtime
bounds_trap :: proc "contextless" () -> ! {
when ODIN_OS == .Windows {
windows_trap_array_bounds()
} else when ODIN_OS == .Orca {
abort_ext("", "", 0, "bounds trap")
} else {
trap()
}
@@ -13,6 +15,8 @@ bounds_trap :: proc "contextless" () -> ! {
type_assertion_trap :: proc "contextless" () -> ! {
when ODIN_OS == .Windows {
windows_trap_type_assertion()
} else when ODIN_OS == .Orca {
abort_ext("", "", 0, "type assertion trap")
} else {
trap()
}
+27 -18
View File
@@ -19,29 +19,41 @@ heap_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode,
// the pointer we return to the user.
//
aligned_alloc :: proc(size, alignment: int, old_ptr: rawptr = nil, zero_memory := true) -> ([]byte, Allocator_Error) {
aligned_alloc :: proc(size, alignment: int, old_ptr: rawptr, old_size: int, zero_memory := true) -> ([]byte, Allocator_Error) {
// Not(flysand): We need to reserve enough space for alignment, which
// includes the user data itself, the space to store the pointer to
// allocation start, as well as the padding required to align both
// the user data and the pointer.
a := max(alignment, align_of(rawptr))
space := size + a - 1
space := a-1 + size_of(rawptr) + size
allocated_mem: rawptr
if old_ptr != nil {
force_copy := old_ptr != nil && alignment > align_of(rawptr)
if old_ptr != nil && !force_copy {
original_old_ptr := ([^]rawptr)(old_ptr)[-1]
allocated_mem = heap_resize(original_old_ptr, space+size_of(rawptr))
allocated_mem = heap_resize(original_old_ptr, space)
} else {
allocated_mem = heap_alloc(space+size_of(rawptr), zero_memory)
allocated_mem = heap_alloc(space, zero_memory)
}
aligned_mem := rawptr(([^]u8)(allocated_mem)[size_of(rawptr):])
ptr := uintptr(aligned_mem)
aligned_ptr := (ptr - 1 + uintptr(a)) & -uintptr(a)
diff := int(aligned_ptr - ptr)
if (size + diff) > space || allocated_mem == nil {
aligned_ptr := (ptr + uintptr(a)-1) & ~(uintptr(a)-1)
if allocated_mem == nil {
aligned_free(old_ptr)
aligned_free(allocated_mem)
return nil, .Out_Of_Memory
}
aligned_mem = rawptr(aligned_ptr)
([^]rawptr)(aligned_mem)[-1] = allocated_mem
if force_copy {
mem_copy_non_overlapping(aligned_mem, old_ptr, min(old_size, size))
aligned_free(old_ptr)
}
return byte_slice(aligned_mem, size), nil
}
@@ -53,10 +65,10 @@ heap_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode,
aligned_resize :: proc(p: rawptr, old_size: int, new_size: int, new_alignment: int, zero_memory := true) -> (new_memory: []byte, err: Allocator_Error) {
if p == nil {
return nil, nil
return aligned_alloc(new_size, new_alignment, nil, old_size, zero_memory)
}
new_memory = aligned_alloc(new_size, new_alignment, p, zero_memory) or_return
new_memory = aligned_alloc(new_size, new_alignment, p, old_size, zero_memory) or_return
// NOTE: heap_resize does not zero the new memory, so we do it
if zero_memory && new_size > old_size {
@@ -68,7 +80,7 @@ heap_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode,
switch mode {
case .Alloc, .Alloc_Non_Zeroed:
return aligned_alloc(size, alignment, nil, mode == .Alloc)
return aligned_alloc(size, alignment, nil, 0, mode == .Alloc)
case .Free:
aligned_free(old_memory)
@@ -77,9 +89,6 @@ heap_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode,
return nil, .Mode_Not_Implemented
case .Resize, .Resize_Non_Zeroed:
if old_memory == nil {
return aligned_alloc(size, alignment, nil, mode == .Resize)
}
return aligned_resize(old_memory, old_size, size, alignment, mode == .Resize)
case .Query_Features:
@@ -97,14 +106,14 @@ heap_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode,
}
heap_alloc :: proc(size: int, zero_memory := true) -> rawptr {
heap_alloc :: proc "contextless" (size: int, zero_memory := true) -> rawptr {
return _heap_alloc(size, zero_memory)
}
heap_resize :: proc(ptr: rawptr, new_size: int) -> rawptr {
heap_resize :: proc "contextless" (ptr: rawptr, new_size: int) -> rawptr {
return _heap_resize(ptr, new_size)
}
heap_free :: proc(ptr: rawptr) {
heap_free :: proc "contextless" (ptr: rawptr) {
_heap_free(ptr)
}
+29
View File
@@ -0,0 +1,29 @@
#+build orca
#+private
package runtime
foreign {
@(link_name="malloc") _orca_malloc :: proc "c" (size: int) -> rawptr ---
@(link_name="calloc") _orca_calloc :: proc "c" (num, size: int) -> rawptr ---
@(link_name="free") _orca_free :: proc "c" (ptr: rawptr) ---
@(link_name="realloc") _orca_realloc :: proc "c" (ptr: rawptr, size: int) -> rawptr ---
}
_heap_alloc :: proc "contextless" (size: int, zero_memory := true) -> rawptr {
if size <= 0 {
return nil
}
if zero_memory {
return _orca_calloc(1, size)
} else {
return _orca_malloc(size)
}
}
_heap_resize :: proc "contextless" (ptr: rawptr, new_size: int) -> rawptr {
return _orca_realloc(ptr, new_size)
}
_heap_free :: proc "contextless" (ptr: rawptr) {
_orca_free(ptr)
}
+9 -6
View File
@@ -1,15 +1,18 @@
//+build js, wasi, freestanding, essence
//+private
#+build js, wasi, freestanding, essence
#+private
package runtime
_heap_alloc :: proc(size: int, zero_memory := true) -> rawptr {
_heap_alloc :: proc "contextless" (size: int, zero_memory := true) -> rawptr {
context = default_context()
unimplemented("base:runtime 'heap_alloc' procedure is not supported on this platform")
}
_heap_resize :: proc(ptr: rawptr, new_size: int) -> rawptr {
_heap_resize :: proc "contextless" (ptr: rawptr, new_size: int) -> rawptr {
context = default_context()
unimplemented("base:runtime 'heap_resize' procedure is not supported on this platform")
}
_heap_free :: proc(ptr: rawptr) {
_heap_free :: proc "contextless" (ptr: rawptr) {
context = default_context()
unimplemented("base:runtime 'heap_free' procedure is not supported on this platform")
}
}
+5 -5
View File
@@ -1,5 +1,5 @@
//+build linux, darwin, freebsd, openbsd, haiku
//+private
#+build linux, darwin, freebsd, openbsd, netbsd, haiku
#+private
package runtime
when ODIN_OS == .Darwin {
@@ -16,7 +16,7 @@ foreign libc {
@(link_name="realloc") _unix_realloc :: proc(ptr: rawptr, size: int) -> rawptr ---
}
_heap_alloc :: proc(size: int, zero_memory := true) -> rawptr {
_heap_alloc :: proc "contextless" (size: int, zero_memory := true) -> rawptr {
if size <= 0 {
return nil
}
@@ -27,12 +27,12 @@ _heap_alloc :: proc(size: int, zero_memory := true) -> rawptr {
}
}
_heap_resize :: proc(ptr: rawptr, new_size: int) -> rawptr {
_heap_resize :: proc "contextless" (ptr: rawptr, new_size: int) -> rawptr {
// NOTE: _unix_realloc doesn't guarantee new memory will be zeroed on
// POSIX platforms. Ensure your caller takes this into account.
return _unix_realloc(ptr, new_size)
}
_heap_free :: proc(ptr: rawptr) {
_heap_free :: proc "contextless" (ptr: rawptr) {
_unix_free(ptr)
}
+3 -3
View File
@@ -14,11 +14,11 @@ foreign kernel32 {
HeapFree :: proc(hHeap: rawptr, dwFlags: u32, lpMem: rawptr) -> b32 ---
}
_heap_alloc :: proc(size: int, zero_memory := true) -> rawptr {
_heap_alloc :: proc "contextless" (size: int, zero_memory := true) -> rawptr {
HEAP_ZERO_MEMORY :: 0x00000008
return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY if zero_memory else 0, uint(size))
}
_heap_resize :: proc(ptr: rawptr, new_size: int) -> rawptr {
_heap_resize :: proc "contextless" (ptr: rawptr, new_size: int) -> rawptr {
if new_size == 0 {
_heap_free(ptr)
return nil
@@ -30,7 +30,7 @@ _heap_resize :: proc(ptr: rawptr, new_size: int) -> rawptr {
HEAP_ZERO_MEMORY :: 0x00000008
return HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, ptr, uint(new_size))
}
_heap_free :: proc(ptr: rawptr) {
_heap_free :: proc "contextless" (ptr: rawptr) {
if ptr == nil {
return
}
+94 -44
View File
@@ -1,3 +1,4 @@
#+vet !cast
package runtime
import "base:intrinsics"
@@ -7,10 +8,9 @@ IS_WASM :: ODIN_ARCH == .wasm32 || ODIN_ARCH == .wasm64p32
@(private)
RUNTIME_LINKAGE :: "strong" when (
(ODIN_USE_SEPARATE_MODULES ||
ODIN_USE_SEPARATE_MODULES ||
ODIN_BUILD_MODE == .Dynamic ||
!ODIN_NO_CRT) &&
!IS_WASM) else "internal"
!ODIN_NO_CRT) else "internal"
RUNTIME_REQUIRE :: false // !ODIN_TILDE
@(private)
@@ -29,7 +29,7 @@ is_power_of_two_int :: #force_inline proc "contextless" (x: int) -> bool {
return (x & (x-1)) == 0
}
align_forward_int :: #force_inline proc(ptr, align: int) -> int {
align_forward_int :: #force_inline proc "odin" (ptr, align: int) -> int {
assert(is_power_of_two_int(align))
p := ptr
@@ -40,6 +40,24 @@ align_forward_int :: #force_inline proc(ptr, align: int) -> int {
return p
}
is_power_of_two_uint :: #force_inline proc "contextless" (x: uint) -> bool {
if x <= 0 {
return false
}
return (x & (x-1)) == 0
}
align_forward_uint :: #force_inline proc "odin" (ptr, align: uint) -> uint {
assert(is_power_of_two_uint(align))
p := ptr
modulo := p & (align-1)
if modulo != 0 {
p += align - modulo
}
return p
}
is_power_of_two_uintptr :: #force_inline proc "contextless" (x: uintptr) -> bool {
if x <= 0 {
return false
@@ -47,7 +65,7 @@ is_power_of_two_uintptr :: #force_inline proc "contextless" (x: uintptr) -> bool
return (x & (x-1)) == 0
}
align_forward_uintptr :: #force_inline proc(ptr, align: uintptr) -> uintptr {
align_forward_uintptr :: #force_inline proc "odin" (ptr, align: uintptr) -> uintptr {
assert(is_power_of_two_uintptr(align))
p := ptr
@@ -58,6 +76,18 @@ align_forward_uintptr :: #force_inline proc(ptr, align: uintptr) -> uintptr {
return p
}
is_power_of_two :: proc {
is_power_of_two_int,
is_power_of_two_uint,
is_power_of_two_uintptr,
}
align_forward :: proc {
align_forward_int,
align_forward_uint,
align_forward_uintptr,
}
mem_zero :: proc "contextless" (data: rawptr, len: int) -> rawptr {
if data == nil {
return nil
@@ -88,16 +118,15 @@ mem_copy_non_overlapping :: proc "contextless" (dst, src: rawptr, len: int) -> r
DEFAULT_ALIGNMENT :: 2*align_of(rawptr)
mem_alloc_bytes :: #force_inline proc(size: int, alignment: int = DEFAULT_ALIGNMENT, allocator := context.allocator, loc := #caller_location) -> ([]byte, Allocator_Error) {
if size == 0 {
return nil, nil
}
if allocator.procedure == nil {
assert(is_power_of_two_int(alignment), "Alignment must be a power of two", loc)
if size == 0 || allocator.procedure == nil{
return nil, nil
}
return allocator.procedure(allocator.data, .Alloc, size, alignment, nil, 0, loc)
}
mem_alloc :: #force_inline proc(size: int, alignment: int = DEFAULT_ALIGNMENT, allocator := context.allocator, loc := #caller_location) -> ([]byte, Allocator_Error) {
assert(is_power_of_two_int(alignment), "Alignment must be a power of two", loc)
if size == 0 || allocator.procedure == nil {
return nil, nil
}
@@ -105,6 +134,7 @@ mem_alloc :: #force_inline proc(size: int, alignment: int = DEFAULT_ALIGNMENT, a
}
mem_alloc_non_zeroed :: #force_inline proc(size: int, alignment: int = DEFAULT_ALIGNMENT, allocator := context.allocator, loc := #caller_location) -> ([]byte, Allocator_Error) {
assert(is_power_of_two_int(alignment), "Alignment must be a power of two", loc)
if size == 0 || allocator.procedure == nil {
return nil, nil
}
@@ -144,6 +174,7 @@ mem_free_all :: #force_inline proc(allocator := context.allocator, loc := #calle
}
_mem_resize :: #force_inline proc(ptr: rawptr, old_size, new_size: int, alignment: int = DEFAULT_ALIGNMENT, allocator := context.allocator, should_zero: bool, loc := #caller_location) -> (data: []byte, err: Allocator_Error) {
assert(is_power_of_two_int(alignment), "Alignment must be a power of two", loc)
if allocator.procedure == nil {
return nil, nil
}
@@ -185,9 +216,11 @@ _mem_resize :: #force_inline proc(ptr: rawptr, old_size, new_size: int, alignmen
}
mem_resize :: proc(ptr: rawptr, old_size, new_size: int, alignment: int = DEFAULT_ALIGNMENT, allocator := context.allocator, loc := #caller_location) -> (data: []byte, err: Allocator_Error) {
assert(is_power_of_two_int(alignment), "Alignment must be a power of two", loc)
return _mem_resize(ptr, old_size, new_size, alignment, allocator, true, loc)
}
non_zero_mem_resize :: proc(ptr: rawptr, old_size, new_size: int, alignment: int = DEFAULT_ALIGNMENT, allocator := context.allocator, loc := #caller_location) -> (data: []byte, err: Allocator_Error) {
assert(is_power_of_two_int(alignment), "Alignment must be a power of two", loc)
return _mem_resize(ptr, old_size, new_size, alignment, allocator, false, loc)
}
@@ -453,7 +486,7 @@ quaternion256_ne :: #force_inline proc "contextless" (a, b: quaternion256) -> bo
string_decode_rune :: #force_inline proc "contextless" (s: string) -> (rune, int) {
// NOTE(bill): Duplicated here to remove dependency on package unicode/utf8
@static accept_sizes := [256]u8{
@(static, rodata) accept_sizes := [256]u8{
0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, // 0x00-0x0f
0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, // 0x10-0x1f
0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, // 0x20-0x2f
@@ -474,7 +507,7 @@ string_decode_rune :: #force_inline proc "contextless" (s: string) -> (rune, int
}
Accept_Range :: struct {lo, hi: u8}
@static accept_ranges := [5]Accept_Range{
@(static, rodata) accept_ranges := [5]Accept_Range{
{0x80, 0xbf},
{0xa0, 0xbf},
{0x80, 0x9f},
@@ -612,21 +645,24 @@ abs_quaternion256 :: #force_inline proc "contextless" (x: quaternion256) -> f64
quo_complex32 :: proc "contextless" (n, m: complex32) -> complex32 {
e, f: f16
nr, ni := f32(real(n)), f32(imag(n))
mr, mi := f32(real(m)), f32(imag(m))
if abs(real(m)) >= abs(imag(m)) {
ratio := imag(m) / real(m)
denom := real(m) + ratio*imag(m)
e = (real(n) + imag(n)*ratio) / denom
f = (imag(n) - real(n)*ratio) / denom
e, f: f32
if abs(mr) >= abs(mi) {
ratio := mi / mr
denom := mr + ratio*mi
e = (nr + ni*ratio) / denom
f = (ni - nr*ratio) / denom
} else {
ratio := real(m) / imag(m)
denom := imag(m) + ratio*real(m)
e = (real(n)*ratio + imag(n)) / denom
f = (imag(n)*ratio - real(n)) / denom
ratio := mr / mi
denom := mi + ratio*mr
e = (nr*ratio + ni) / denom
f = (ni*ratio - nr) / denom
}
return complex(e, f)
return complex(f16(e), f16(f))
}
@@ -667,15 +703,15 @@ quo_complex128 :: proc "contextless" (n, m: complex128) -> complex128 {
}
mul_quaternion64 :: proc "contextless" (q, r: quaternion64) -> quaternion64 {
q0, q1, q2, q3 := real(q), imag(q), jmag(q), kmag(q)
r0, r1, r2, r3 := real(r), imag(r), jmag(r), kmag(r)
q0, q1, q2, q3 := f32(real(q)), f32(imag(q)), f32(jmag(q)), f32(kmag(q))
r0, r1, r2, r3 := f32(real(r)), f32(imag(r)), f32(jmag(r)), f32(kmag(r))
t0 := r0*q0 - r1*q1 - r2*q2 - r3*q3
t1 := r0*q1 + r1*q0 - r2*q3 + r3*q2
t2 := r0*q2 + r1*q3 + r2*q0 - r3*q1
t3 := r0*q3 - r1*q2 + r2*q1 + r3*q0
return quaternion(w=t0, x=t1, y=t2, z=t3)
return quaternion(w=f16(t0), x=f16(t1), y=f16(t2), z=f16(t3))
}
mul_quaternion128 :: proc "contextless" (q, r: quaternion128) -> quaternion128 {
@@ -703,8 +739,8 @@ mul_quaternion256 :: proc "contextless" (q, r: quaternion256) -> quaternion256 {
}
quo_quaternion64 :: proc "contextless" (q, r: quaternion64) -> quaternion64 {
q0, q1, q2, q3 := real(q), imag(q), jmag(q), kmag(q)
r0, r1, r2, r3 := real(r), imag(r), jmag(r), kmag(r)
q0, q1, q2, q3 := f32(real(q)), f32(imag(q)), f32(jmag(q)), f32(kmag(q))
r0, r1, r2, r3 := f32(real(r)), f32(imag(r)), f32(jmag(r)), f32(kmag(r))
invmag2 := 1.0 / (r0*r0 + r1*r1 + r2*r2 + r3*r3)
@@ -713,7 +749,7 @@ quo_quaternion64 :: proc "contextless" (q, r: quaternion64) -> quaternion64 {
t2 := (r0*q2 - r1*q3 - r2*q0 + r3*q1) * invmag2
t3 := (r0*q3 + r1*q2 + r2*q1 - r3*q0) * invmag2
return quaternion(w=t0, x=t1, y=t2, z=t3)
return quaternion(w=f16(t0), x=f16(t1), y=f16(t2), z=f16(t3))
}
quo_quaternion128 :: proc "contextless" (q, r: quaternion128) -> quaternion128 {
@@ -801,6 +837,10 @@ truncsfhf2 :: proc "c" (value: f32) -> __float16 {
}
}
@(link_name="__aeabi_d2h", linkage=RUNTIME_LINKAGE, require=RUNTIME_REQUIRE)
aeabi_d2h :: proc "c" (value: f64) -> __float16 {
return truncsfhf2(f32(value))
}
@(link_name="__truncdfhf2", linkage=RUNTIME_LINKAGE, require=RUNTIME_REQUIRE)
truncdfhf2 :: proc "c" (value: f64) -> __float16 {
@@ -841,9 +881,6 @@ extendhfsf2 :: proc "c" (value: __float16) -> f32 {
@(link_name="__floattidf", linkage=RUNTIME_LINKAGE, require=RUNTIME_REQUIRE)
floattidf :: proc "c" (a: i128) -> f64 {
when IS_WASM {
return 0
} else {
DBL_MANT_DIG :: 53
if a == 0 {
return 0.0
@@ -883,14 +920,10 @@ when IS_WASM {
fb[0] = u32(a) // mantissa-low
return transmute(f64)fb
}
}
@(link_name="__floattidf_unsigned", linkage=RUNTIME_LINKAGE, require=RUNTIME_REQUIRE)
floattidf_unsigned :: proc "c" (a: u128) -> f64 {
when IS_WASM {
return 0
} else {
DBL_MANT_DIG :: 53
if a == 0 {
return 0.0
@@ -928,7 +961,6 @@ when IS_WASM {
fb[0] = u32(a) // mantissa-low
return transmute(f64)fb
}
}
@@ -978,26 +1010,44 @@ modti3 :: proc "c" (a, b: i128) -> i128 {
bn := (b ~ s_b) - s_b
r: u128 = ---
_ = udivmod128(transmute(u128)an, transmute(u128)bn, &r)
return (transmute(i128)r ~ s_a) - s_a
_ = udivmod128(u128(an), u128(bn), &r)
return (i128(r) ~ s_a) - s_a
}
@(link_name="__divmodti4", linkage=RUNTIME_LINKAGE, require=RUNTIME_REQUIRE)
divmodti4 :: proc "c" (a, b: i128, rem: ^i128) -> i128 {
u := udivmod128(transmute(u128)a, transmute(u128)b, cast(^u128)rem)
return transmute(i128)u
s_a := a >> (128 - 1) // -1 if negative or 0
s_b := b >> (128 - 1)
an := (a ~ s_a) - s_a // absolute
bn := (b ~ s_b) - s_b
s_b ~= s_a // quotient sign
u_s_b := u128(s_b)
u_s_a := u128(s_a)
r: u128 = ---
u := i128((udivmodti4(u128(an), u128(bn), &r) ~ u_s_b) - u_s_b) // negate if negative
rem^ = i128((r ~ u_s_a) - u_s_a)
return u
}
@(link_name="__divti3", linkage=RUNTIME_LINKAGE, require=RUNTIME_REQUIRE)
divti3 :: proc "c" (a, b: i128) -> i128 {
u := udivmodti4(transmute(u128)a, transmute(u128)b, nil)
return transmute(i128)u
s_a := a >> (128 - 1) // -1 if negative or 0
s_b := b >> (128 - 1)
an := (a ~ s_a) - s_a // absolute
bn := (b ~ s_b) - s_b
s_a ~= s_b // quotient sign
u_s_a := u128(s_a)
return i128((udivmodti4(u128(an), u128(bn), nil) ~ u_s_a) - u_s_a) // negate if negative
}
@(link_name="__fixdfti", linkage=RUNTIME_LINKAGE, require=RUNTIME_REQUIRE)
fixdfti :: proc(a: u64) -> i128 {
fixdfti :: proc "c" (a: u64) -> i128 {
significandBits :: 52
typeWidth :: (size_of(u64)*8)
exponentBits :: (typeWidth - significandBits - 1)
@@ -1055,4 +1105,4 @@ __read_bits :: proc "contextless" (dst, src: [^]byte, offset: uintptr, size: uin
dst[j>>3] &~= 1<<(j&7)
dst[j>>3] |= the_bit<<(j&7)
}
}
}
+7 -3
View File
@@ -1,5 +1,5 @@
//+build freebsd, openbsd
//+private
#+build freebsd, openbsd, netbsd
#+private
package runtime
foreign import libc "system:c"
@@ -9,7 +9,11 @@ foreign libc {
@(link_name="write")
_unix_write :: proc(fd: i32, buf: rawptr, size: int) -> int ---
__error :: proc() -> ^i32 ---
when ODIN_OS == .NetBSD {
@(link_name="__errno") __error :: proc() -> ^i32 ---
} else {
__error :: proc() -> ^i32 ---
}
}
_stderr_write :: proc "contextless" (data: []byte) -> (int, _OS_Errno) {
+20 -7
View File
@@ -1,15 +1,28 @@
//+build darwin
//+private
#+build darwin
#+private
package runtime
import "base:intrinsics"
_stderr_write :: proc "contextless" (data: []byte) -> (int, _OS_Errno) {
WRITE :: 0x2000004
STDERR :: 2
ret := intrinsics.syscall(WRITE, STDERR, uintptr(raw_data(data)), uintptr(len(data)))
if ret < 0 {
return 0, _OS_Errno(-ret)
when ODIN_NO_CRT {
WRITE :: 0x2000004
ret := intrinsics.syscall(WRITE, STDERR, uintptr(raw_data(data)), uintptr(len(data)))
if ret < 0 {
return 0, _OS_Errno(-ret)
}
return int(ret), 0
} else {
foreign {
write :: proc(handle: i32, buffer: [^]byte, count: uint) -> int ---
__error :: proc() -> ^i32 ---
}
if ret := write(STDERR, raw_data(data), len(data)); ret >= 0 {
return int(ret), 0
}
return 0, _OS_Errno(__error()^)
}
return int(ret), 0
}
+2 -2
View File
@@ -1,5 +1,5 @@
//+build freestanding
//+private
#+build freestanding
#+private
package runtime
// TODO(bill): reimplement `os.write`
+2 -2
View File
@@ -1,5 +1,5 @@
//+build haiku
//+private
#+build haiku
#+private
package runtime
foreign import libc "system:c"
+2 -2
View File
@@ -1,5 +1,5 @@
//+build js
//+private
#+build js
#+private
package runtime
foreign import "odin_env"
+3 -1
View File
@@ -1,4 +1,4 @@
//+private
#+private
package runtime
import "base:intrinsics"
@@ -12,6 +12,8 @@ _stderr_write :: proc "contextless" (data: []byte) -> (int, _OS_Errno) {
SYS_write :: uintptr(4)
} else when ODIN_ARCH == .arm32 {
SYS_write :: uintptr(4)
} else when ODIN_ARCH == .riscv64 {
SYS_write :: uintptr(64)
}
stderr :: 2
+43
View File
@@ -0,0 +1,43 @@
#+build orca
#+private
package runtime
import "base:intrinsics"
// Constants allowing to specify the level of logging verbosity.
log_level :: enum u32 {
// Only errors are logged.
ERROR = 0,
// Only warnings and errors are logged.
WARNING = 1,
// All messages are logged.
INFO = 2,
COUNT = 3,
}
@(default_calling_convention="c", link_prefix="oc_")
foreign {
abort_ext :: proc(file: cstring, function: cstring, line: i32, fmt: cstring, #c_vararg args: ..any) -> ! ---
assert_fail :: proc(file: cstring, function: cstring, line: i32, src: cstring, fmt: cstring, #c_vararg args: ..any) -> ! ---
log_ext :: proc(level: log_level, function: cstring, file: cstring, line: i32, fmt: cstring, #c_vararg args: ..any) ---
}
// NOTE: This is all pretty gross, don't look.
// WASM is single threaded so this should be fine.
orca_stderr_buffer: [4096]byte
orca_stderr_buffer_idx: int
_stderr_write :: proc "contextless" (data: []byte) -> (int, _OS_Errno) {
for b in data {
orca_stderr_buffer[orca_stderr_buffer_idx] = b
orca_stderr_buffer_idx += 1
if b == '\n' || orca_stderr_buffer_idx == len(orca_stderr_buffer)-1 {
log_ext(.ERROR, "", "", 0, cstring(raw_data(orca_stderr_buffer[:orca_stderr_buffer_idx])))
orca_stderr_buffer_idx = 0
}
}
return len(data), 0
}
+49 -5
View File
@@ -1,11 +1,55 @@
//+build wasi
//+private
#+build wasi
#+private
package runtime
import "core:sys/wasm/wasi"
foreign import wasi "wasi_snapshot_preview1"
@(default_calling_convention="contextless")
foreign wasi {
fd_write :: proc(
fd: i32,
iovs: [][]byte,
n: ^uint,
) -> u16 ---
@(private="file")
args_sizes_get :: proc(
num_of_args: ^uint,
size_of_args: ^uint,
) -> u16 ---
@(private="file")
args_get :: proc(
argv: [^]cstring,
argv_buf: [^]byte,
) -> u16 ---
}
_stderr_write :: proc "contextless" (data: []byte) -> (int, _OS_Errno) {
data := (wasi.ciovec_t)(data)
n, err := wasi.fd_write(1, {data})
n: uint
err := fd_write(1, {data}, &n)
return int(n), _OS_Errno(err)
}
_wasi_setup_args :: proc() {
num_of_args, size_of_args: uint
if errno := args_sizes_get(&num_of_args, &size_of_args); errno != 0 {
return
}
err: Allocator_Error
if args__, err = make([]cstring, num_of_args); err != nil {
return
}
args_buf: []byte
if args_buf, err = make([]byte, size_of_args); err != nil {
delete(args__)
return
}
if errno := args_get(raw_data(args__), raw_data(args_buf)); errno != 0 {
delete(args__)
delete(args_buf)
}
}
+2 -2
View File
@@ -1,5 +1,5 @@
//+build windows
//+private
#+build windows
#+private
package runtime
foreign import kernel32 "system:Kernel32.lib"
+7 -6
View File
@@ -262,7 +262,7 @@ print_typeid :: #force_no_inline proc "contextless" (id: typeid) {
}
}
@(optimization_mode="size")
@(optimization_mode="favor_size")
print_type :: #force_no_inline proc "contextless" (ti: ^Type_Info) {
if ti == nil {
print_string("nil")
@@ -401,15 +401,16 @@ print_type :: #force_no_inline proc "contextless" (ti: ^Type_Info) {
}
print_string("struct ")
if info.is_packed { print_string("#packed ") }
if info.is_raw_union { print_string("#raw_union ") }
if info.custom_align {
if .packed in info.flags { print_string("#packed ") }
if .raw_union in info.flags { print_string("#raw_union ") }
if .no_copy in info.flags { print_string("#no_copy ") }
if .align in info.flags {
print_string("#align(")
print_u64(u64(ti.align))
print_string(") ")
}
print_byte('{')
for name, i in info.names {
for name, i in info.names[:info.field_count] {
if i > 0 { print_string(", ") }
print_string(name)
print_string(": ")
@@ -469,7 +470,7 @@ print_type :: #force_no_inline proc "contextless" (ti: ^Type_Info) {
print_string("bit_field ")
print_type(info.backing_type)
print_string(" {")
for name, i in info.names {
for name, i in info.names[:info.field_count] {
if i > 0 { print_string(", ") }
print_string(name)
print_string(": ")
+16 -10
View File
@@ -25,13 +25,19 @@ when ODIN_NO_CRT && ODIN_OS == .Windows {
RtlMoveMemory(dst, src, len)
return dst
}
} else when ODIN_NO_CRT || (ODIN_ARCH == .wasm32 || ODIN_ARCH == .wasm64p32) {
} else when ODIN_NO_CRT || (ODIN_OS != .Orca && (ODIN_ARCH == .wasm32 || ODIN_ARCH == .wasm64p32)) {
// NOTE: on wasm, calls to these procs are generated (by LLVM) with type `i32` instead of `int`.
//
// NOTE: `#any_int` is also needed, because calls that we generate (and package code)
// will be using `int` and need to be converted.
int_t :: i32 when ODIN_ARCH == .wasm64p32 else int
@(link_name="memset", linkage="strong", require)
memset :: proc "c" (ptr: rawptr, val: i32, len: int) -> rawptr {
memset :: proc "c" (ptr: rawptr, val: i32, #any_int len: int_t) -> rawptr {
if ptr != nil && len != 0 {
b := byte(val)
p := ([^]byte)(ptr)
for i := 0; i < len; i += 1 {
for i := int_t(0); i < len; i += 1 {
p[i] = b
}
}
@@ -39,10 +45,10 @@ when ODIN_NO_CRT && ODIN_OS == .Windows {
}
@(link_name="bzero", linkage="strong", require)
bzero :: proc "c" (ptr: rawptr, len: int) -> rawptr {
bzero :: proc "c" (ptr: rawptr, #any_int len: int_t) -> rawptr {
if ptr != nil && len != 0 {
p := ([^]byte)(ptr)
for i := 0; i < len; i += 1 {
for i := int_t(0); i < len; i += 1 {
p[i] = 0
}
}
@@ -50,7 +56,7 @@ when ODIN_NO_CRT && ODIN_OS == .Windows {
}
@(link_name="memmove", linkage="strong", require)
memmove :: proc "c" (dst, src: rawptr, len: int) -> rawptr {
memmove :: proc "c" (dst, src: rawptr, #any_int len: int_t) -> rawptr {
d, s := ([^]byte)(dst), ([^]byte)(src)
if d == s || len == 0 {
return dst
@@ -63,7 +69,7 @@ when ODIN_NO_CRT && ODIN_OS == .Windows {
}
if s > d && uintptr(s)-uintptr(d) < uintptr(len) {
for i := 0; i < len; i += 1 {
for i := int_t(0); i < len; i += 1 {
d[i] = s[i]
}
return dst
@@ -71,10 +77,10 @@ when ODIN_NO_CRT && ODIN_OS == .Windows {
return memcpy(dst, src, len)
}
@(link_name="memcpy", linkage="strong", require)
memcpy :: proc "c" (dst, src: rawptr, len: int) -> rawptr {
memcpy :: proc "c" (dst, src: rawptr, #any_int len: int_t) -> rawptr {
d, s := ([^]byte)(dst), ([^]byte)(src)
if d != s {
for i := 0; i < len; i += 1 {
for i := int_t(0); i < len; i += 1 {
d[i] = s[i]
}
}
@@ -92,4 +98,4 @@ when ODIN_NO_CRT && ODIN_OS == .Windows {
}
return ptr
}
}
}
+1 -1
View File
@@ -1,4 +1,4 @@
//+private
#+private
package runtime
foreign import "system:Foundation.framework"
+1 -1
View File
@@ -1,4 +1,4 @@
//+build js
#+build js
package runtime
init_default_context_for_js: Context
+57 -14
View File
@@ -1,4 +1,4 @@
//+build wasm32, wasm64p32
#+build wasm32, wasm64p32
package runtime
@(private="file")
@@ -14,33 +14,57 @@ ti_uint :: struct #raw_union {
}
@(link_name="__ashlti3", linkage="strong")
__ashlti3 :: proc "contextless" (la, ha: u64, b_: u32) -> i128 {
bits_in_dword :: size_of(u32)*8
b := u32(b_)
__ashlti3 :: proc "contextless" (a: i128, b: u32) -> i128 {
bits :: 64
input, result: ti_int
input.lo, input.hi = la, ha
if b & bits_in_dword != 0 {
input: ti_int = ---
result: ti_int = ---
input.all = a
if b & bits != 0 {
result.lo = 0
result.hi = input.lo << (b-bits_in_dword)
result.hi = input.lo << (b-bits)
} else {
if b == 0 {
return input.all
return a
}
result.lo = input.lo<<b
result.hi = (input.hi<<b) | (input.lo>>(bits_in_dword-b))
result.hi = (input.hi<<b) | (input.lo>>(bits-b))
}
return result.all
}
__ashlti3_unsigned :: proc "contextless" (a: u128, b: u32) -> u128 {
return cast(u128)__ashlti3(cast(i128)a, b)
}
@(link_name="__mulddi3", linkage="strong")
__mulddi3 :: proc "contextless" (a, b: u64) -> i128 {
r: ti_int
bits :: 32
mask :: ~u64(0) >> bits
r.lo = (a & mask) * (b & mask)
t := r.lo >> bits
r.lo &= mask
t += (a >> bits) * (b & mask)
r.lo += (t & mask) << bits
r.hi = t >> bits
t = r.lo >> bits
r.lo &= mask
t += (b >> bits) * (a & mask)
r.lo += (t & mask) << bits
r.hi += t >> bits
r.hi += (a >> bits) * (b >> bits)
return r.all
}
@(link_name="__multi3", linkage="strong")
__multi3 :: proc "contextless" (la, ha, lb, hb: u64) -> i128 {
__multi3 :: proc "contextless" (a, b: i128) -> i128 {
x, y, r: ti_int
x.lo, x.hi = la, ha
y.lo, y.hi = lb, hb
r.all = i128(x.lo * y.lo) // TODO this is incorrect
x.all = a
y.all = b
r.all = __mulddi3(x.lo, y.lo)
r.hi += x.hi*y.lo + x.lo*y.hi
return r.all
}
@@ -52,3 +76,22 @@ udivti3 :: proc "c" (la, ha, lb, hb: u64) -> u128 {
b.lo, b.hi = lb, hb
return udivmodti4(a.all, b.all, nil)
}
@(link_name="__lshrti3", linkage="strong")
__lshrti3 :: proc "c" (a: i128, b: u32) -> i128 {
bits :: 64
input, result: ti_int
input.all = a
if b & bits != 0 {
result.hi = 0
result.lo = input.hi >> (b - bits)
} else if b == 0 {
return a
} else {
result.hi = input.hi >> b
result.lo = (input.hi << (bits - b)) | (input.lo >> b)
}
return result.all
}
+2 -2
View File
@@ -1,5 +1,5 @@
//+private
//+no-instrumentation
#+private
#+no-instrumentation
package runtime
foreign import kernel32 "system:Kernel32.lib"
+2 -2
View File
@@ -1,5 +1,5 @@
//+private
//+no-instrumentation
#+private
#+no-instrumentation
package runtime
@require foreign import "system:int64.lib"
+127
View File
@@ -0,0 +1,127 @@
package runtime
import "base:intrinsics"
@(require_results)
random_generator_read_bytes :: proc(rg: Random_Generator, p: []byte) -> bool {
if rg.procedure != nil {
rg.procedure(rg.data, .Read, p)
return true
}
return false
}
@(require_results)
random_generator_read_ptr :: proc(rg: Random_Generator, p: rawptr, len: uint) -> bool {
if rg.procedure != nil {
rg.procedure(rg.data, .Read, ([^]byte)(p)[:len])
return true
}
return false
}
@(require_results)
random_generator_query_info :: proc(rg: Random_Generator) -> (info: Random_Generator_Query_Info) {
if rg.procedure != nil {
rg.procedure(rg.data, .Query_Info, ([^]byte)(&info)[:size_of(info)])
}
return
}
random_generator_reset_bytes :: proc(rg: Random_Generator, p: []byte) {
if rg.procedure != nil {
rg.procedure(rg.data, .Reset, p)
}
}
random_generator_reset_u64 :: proc(rg: Random_Generator, p: u64) {
if rg.procedure != nil {
p := p
rg.procedure(rg.data, .Reset, ([^]byte)(&p)[:size_of(p)])
}
}
Default_Random_State :: struct {
state: u64,
inc: u64,
}
default_random_generator_proc :: proc(data: rawptr, mode: Random_Generator_Mode, p: []byte) {
@(require_results)
read_u64 :: proc "contextless" (r: ^Default_Random_State) -> u64 {
old_state := r.state
r.state = old_state * 6364136223846793005 + (r.inc|1)
xor_shifted := (((old_state >> 59) + 5) ~ old_state) * 12605985483714917081
rot := (old_state >> 59)
return (xor_shifted >> rot) | (xor_shifted << ((-rot) & 63))
}
@(thread_local)
global_rand_seed: Default_Random_State
init :: proc "contextless" (r: ^Default_Random_State, seed: u64) {
seed := seed
if seed == 0 {
seed = u64(intrinsics.read_cycle_counter())
}
r.state = 0
r.inc = (seed << 1) | 1
_ = read_u64(r)
r.state += seed
_ = read_u64(r)
}
r: ^Default_Random_State = ---
if data == nil {
r = &global_rand_seed
} else {
r = cast(^Default_Random_State)data
}
switch mode {
case .Read:
if r.state == 0 && r.inc == 0 {
init(r, 0)
}
switch len(p) {
case size_of(u64):
// Fast path for a 64-bit destination.
intrinsics.unaligned_store((^u64)(raw_data(p)), read_u64(r))
case:
// All other cases.
pos := i8(0)
val := u64(0)
for &v in p {
if pos == 0 {
val = read_u64(r)
pos = 7
}
v = byte(val)
val >>= 8
pos -= 1
}
}
case .Reset:
seed: u64
mem_copy_non_overlapping(&seed, raw_data(p), min(size_of(seed), len(p)))
init(r, seed)
case .Query_Info:
if len(p) != size_of(Random_Generator_Query_Info) {
return
}
info := (^Random_Generator_Query_Info)(raw_data(p))
info^ += {.Uniform, .Resettable}
}
}
default_random_generator :: proc "contextless" (state: ^Default_Random_State = nil) -> Random_Generator {
return {
procedure = default_random_generator_proc,
data = state,
}
}
+34
View File
@@ -0,0 +1,34 @@
package runtime
Thread_Local_Cleaner :: #type proc "odin" ()
@(private="file")
thread_local_cleaners: [8]Thread_Local_Cleaner
// Add a procedure that will be run at the end of a thread for the purpose of
// deallocating state marked as `thread_local`.
//
// Intended to be called in an `init` procedure of a package with
// dynamically-allocated memory that is stored in `thread_local` variables.
add_thread_local_cleaner :: proc "contextless" (p: Thread_Local_Cleaner) {
for &v in thread_local_cleaners {
if v == nil {
v = p
return
}
}
panic_contextless("There are no more thread-local cleaner slots available.")
}
// Run all of the thread-local cleaner procedures.
//
// Intended to be called by the internals of a threading API at the end of a
// thread's lifetime.
run_thread_local_cleaners :: proc "odin" () {
for p in thread_local_cleaners {
if p == nil {
break
}
p()
}
}
+3 -3
View File
@@ -58,7 +58,7 @@ udivmod128 :: proc "c" (a, b: u128, rem: ^u128) -> u128 {
return u128(n[high] >> _ctz(d[high]))
}
sr = transmute(u32)(i32(_clz(d[high])) - i32(_clz(n[high])))
sr = u32(i32(_clz(d[high])) - i32(_clz(n[high])))
if sr > U64_BITS - 2 {
if rem != nil {
rem^ = a
@@ -107,7 +107,7 @@ udivmod128 :: proc "c" (a, b: u128, rem: ^u128) -> u128 {
r[low] = n[high] >> (sr - U64_BITS)
}
} else {
sr = transmute(u32)(i32(_clz(d[high])) - i32(_clz(n[high])))
sr = u32(i32(_clz(d[high])) - i32(_clz(n[high])))
if sr > U64_BITS - 1 {
if rem != nil {
@@ -143,7 +143,7 @@ udivmod128 :: proc "c" (a, b: u128, rem: ^u128) -> u128 {
r_all = transmute(u128)r
s := i128(b - r_all - 1) >> (U128_BITS - 1)
carry = u32(s & 1)
r_all -= b & transmute(u128)s
r_all -= b & u128(s)
r = transmute([2]u64)r_all
}
+871
View File
@@ -0,0 +1,871 @@
#+build wasm32, wasm64p32
package runtime
import "base:intrinsics"
/*
Port of emmalloc, modified for use in Odin.
Invariants:
- Per-allocation header overhead is 8 bytes, smallest allocated payload
amount is 8 bytes, and a multiple of 4 bytes.
- Acquired memory blocks are subdivided into disjoint regions that lie
next to each other.
- A region is either in used or free.
Used regions may be adjacent, and a used and unused region
may be adjacent, but not two unused ones - they would be
merged.
- Memory allocation takes constant time, unless the alloc needs to wasm_memory_grow()
or memory is very close to being exhausted.
- Free and used regions are managed inside "root regions", which are slabs
of memory acquired via wasm_memory_grow().
- Memory retrieved using wasm_memory_grow() can not be given back to the OS.
Therefore, frees are internal to the allocator.
Copyright (c) 2010-2014 Emscripten authors, see AUTHORS file.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
WASM_Allocator :: struct #no_copy {
// The minimum alignment of allocations.
alignment: uint,
// A region that contains as payload a single forward linked list of pointers to
// root regions of each disjoint region blocks.
list_of_all_regions: ^Root_Region,
// For each of the buckets, maintain a linked list head node. The head node for each
// free region is a sentinel node that does not actually represent any free space, but
// the sentinel is used to avoid awkward testing against (if node == freeRegionHeadNode)
// when adding and removing elements from the linked list, i.e. we are guaranteed that
// the sentinel node is always fixed and there, and the actual free region list elements
// start at free_region_buckets[i].next each.
free_region_buckets: [NUM_FREE_BUCKETS]Region,
// A bitmask that tracks the population status for each of the 64 distinct memory regions:
// a zero at bit position i means that the free list bucket i is empty. This bitmask is
// used to avoid redundant scanning of the 64 different free region buckets: instead by
// looking at the bitmask we can find in constant time an index to a free region bucket
// that contains free memory of desired size.
free_region_buckets_used: BUCKET_BITMASK_T,
// Because wasm memory can only be allocated in pages of 64k at a time, we keep any
// spilled/unused bytes that are left from the allocated pages here, first using this
// when bytes are needed.
spill: []byte,
// Mutex for thread safety, only used if the target feature "atomics" is enabled.
mu: Mutex_State,
}
// Not required to be called, called on first allocation otherwise.
wasm_allocator_init :: proc(a: ^WASM_Allocator, alignment: uint = 8) {
assert(is_power_of_two(alignment), "alignment must be a power of two")
assert(alignment > 4, "alignment must be more than 4")
a.alignment = alignment
for i in 0..<NUM_FREE_BUCKETS {
a.free_region_buckets[i].next = &a.free_region_buckets[i]
a.free_region_buckets[i].prev = a.free_region_buckets[i].next
}
if !claim_more_memory(a, 3*size_of(Region)) {
panic("wasm_allocator: initial memory could not be allocated")
}
}
global_default_wasm_allocator_data: WASM_Allocator
default_wasm_allocator :: proc() -> Allocator {
return wasm_allocator(&global_default_wasm_allocator_data)
}
wasm_allocator :: proc(a: ^WASM_Allocator) -> Allocator {
return {
data = a,
procedure = wasm_allocator_proc,
}
}
wasm_allocator_proc :: proc(a: rawptr, mode: Allocator_Mode, size, alignment: int, old_memory: rawptr, old_size: int, loc := #caller_location) -> ([]byte, Allocator_Error) {
a := (^WASM_Allocator)(a)
if a == nil {
a = &global_default_wasm_allocator_data
}
if a.alignment == 0 {
wasm_allocator_init(a)
}
switch mode {
case .Alloc:
ptr := aligned_alloc(a, uint(alignment), uint(size), loc)
if ptr == nil {
return nil, .Out_Of_Memory
}
intrinsics.mem_zero(ptr, size)
return ([^]byte)(ptr)[:size], nil
case .Alloc_Non_Zeroed:
ptr := aligned_alloc(a, uint(alignment), uint(size), loc)
if ptr == nil {
return nil, .Out_Of_Memory
}
return ([^]byte)(ptr)[:size], nil
case .Resize:
ptr := aligned_realloc(a, old_memory, uint(alignment), uint(size), loc)
if ptr == nil {
return nil, .Out_Of_Memory
}
bytes := ([^]byte)(ptr)[:size]
if size > old_size {
new_region := raw_data(bytes[old_size:])
intrinsics.mem_zero(new_region, size - old_size)
}
return bytes, nil
case .Resize_Non_Zeroed:
ptr := aligned_realloc(a, old_memory, uint(alignment), uint(size), loc)
if ptr == nil {
return nil, .Out_Of_Memory
}
return ([^]byte)(ptr)[:size], nil
case .Free:
free(a, old_memory, loc)
return nil, nil
case .Free_All, .Query_Info:
return nil, .Mode_Not_Implemented
case .Query_Features:
set := (^Allocator_Mode_Set)(old_memory)
if set != nil {
set^ = {.Alloc, .Alloc_Non_Zeroed, .Free, .Resize, .Resize_Non_Zeroed, .Query_Features }
}
return nil, nil
}
unreachable()
}
// Returns the allocated size of the allocator (both free and used).
// If `nil` is given, the global allocator is used.
wasm_allocator_size :: proc(a: ^WASM_Allocator = nil) -> (size: uint) {
a := a
if a == nil {
a = &global_default_wasm_allocator_data
}
lock(a)
defer unlock(a)
root := a.list_of_all_regions
for root != nil {
size += uint(uintptr(root.end_ptr) - uintptr(root))
root = root.next
}
size += len(a.spill)
return
}
// Returns the amount of free memory on the allocator.
// If `nil` is given, the global allocator is used.
wasm_allocator_free_space :: proc(a: ^WASM_Allocator = nil) -> (free: uint) {
a := a
if a == nil {
a = &global_default_wasm_allocator_data
}
lock(a)
defer unlock(a)
bucket_index: u64 = 0
bucket_mask := a.free_region_buckets_used
for bucket_mask != 0 {
index_add := intrinsics.count_trailing_zeros(bucket_mask)
bucket_index += index_add
bucket_mask >>= index_add
for free_region := a.free_region_buckets[bucket_index].next; free_region != &a.free_region_buckets[bucket_index]; free_region = free_region.next {
free += free_region.size - REGION_HEADER_SIZE
}
bucket_index += 1
bucket_mask >>= 1
}
free += len(a.spill)
return
}
@(private="file")
NUM_FREE_BUCKETS :: 64
@(private="file")
BUCKET_BITMASK_T :: u64
// Dynamic memory is subdivided into regions, in the format
// <size:u32> ..... <size:u32> | <size:u32> ..... <size:u32> | <size:u32> ..... <size:u32> | .....
// That is, at the bottom and top end of each memory region, the size of that region is stored. That allows traversing the
// memory regions backwards and forwards. Because each allocation must be at least a multiple of 4 bytes, the lowest two bits of
// each size field is unused. Free regions are distinguished by used regions by having the FREE_REGION_FLAG bit present
// in the size field. I.e. for free regions, the size field is odd, and for used regions, the size field reads even.
@(private="file")
FREE_REGION_FLAG :: 0x1
// Attempts to alloc more than this many bytes would cause an overflow when calculating the size of a region,
// therefore allocations larger than this are short-circuited immediately on entry.
@(private="file")
MAX_ALLOC_SIZE :: 0xFFFFFFC7
// A free region has the following structure:
// <size:uint> <prevptr> <nextptr> ... <size:uint>
@(private="file")
Region :: struct {
size: uint,
prev, next: ^Region,
_at_the_end_of_this_struct_size: uint,
}
// Each memory block starts with a Root_Region at the beginning.
// The Root_Region specifies the size of the region block, and forms a linked
// list of all Root_Regions in the program, starting with `list_of_all_regions`
// below.
@(private="file")
Root_Region :: struct {
size: u32,
next: ^Root_Region,
end_ptr: ^byte,
}
@(private="file")
Mutex_State :: enum u32 {
Unlocked = 0,
Locked = 1,
Waiting = 2,
}
@(private="file")
lock :: proc(a: ^WASM_Allocator) {
when intrinsics.has_target_feature("atomics") {
@(cold)
lock_slow :: proc(a: ^WASM_Allocator, curr_state: Mutex_State) {
new_state := curr_state // Make a copy of it
spin_lock: for spin in 0..<i32(100) {
state, ok := intrinsics.atomic_compare_exchange_weak_explicit(&a.mu, .Unlocked, new_state, .Acquire, .Consume)
if ok {
return
}
if state == .Waiting {
break spin_lock
}
for i := min(spin+1, 32); i > 0; i -= 1 {
intrinsics.cpu_relax()
}
}
// Set just in case 100 iterations did not do it
new_state = .Waiting
for {
if intrinsics.atomic_exchange_explicit(&a.mu, .Waiting, .Acquire) == .Unlocked {
return
}
ret := intrinsics.wasm_memory_atomic_wait32((^u32)(&a.mu), u32(new_state), -1)
assert(ret != 0)
intrinsics.cpu_relax()
}
}
if v := intrinsics.atomic_exchange_explicit(&a.mu, .Locked, .Acquire); v != .Unlocked {
lock_slow(a, v)
}
}
}
@(private="file")
unlock :: proc(a: ^WASM_Allocator) {
when intrinsics.has_target_feature("atomics") {
@(cold)
unlock_slow :: proc(a: ^WASM_Allocator) {
for {
s := intrinsics.wasm_memory_atomic_notify32((^u32)(&a.mu), 1)
if s >= 1 {
return
}
}
}
switch intrinsics.atomic_exchange_explicit(&a.mu, .Unlocked, .Release) {
case .Unlocked:
unreachable()
case .Locked:
// Okay
case .Waiting:
unlock_slow(a)
}
}
}
@(private="file")
assert_locked :: proc(a: ^WASM_Allocator) {
when intrinsics.has_target_feature("atomics") {
assert(intrinsics.atomic_load(&a.mu) != .Unlocked)
}
}
@(private="file")
has_alignment_uintptr :: proc(ptr: uintptr, #any_int alignment: uintptr) -> bool {
return ptr & (alignment-1) == 0
}
@(private="file")
has_alignment_uint :: proc(ptr: uint, alignment: uint) -> bool {
return ptr & (alignment-1) == 0
}
@(private="file")
has_alignment :: proc {
has_alignment_uintptr,
has_alignment_uint,
}
@(private="file")
REGION_HEADER_SIZE :: 2*size_of(uint)
@(private="file")
SMALLEST_ALLOCATION_SIZE :: 2*size_of(rawptr)
// Subdivide regions of free space into distinct circular doubly linked lists, where each linked list
// represents a range of free space blocks. The following function compute_free_list_bucket() converts
// an allocation size to the bucket index that should be looked at.
#assert(NUM_FREE_BUCKETS == 64, "Following function is tailored specifically for the NUM_FREE_BUCKETS == 64 case")
@(private="file")
compute_free_list_bucket :: proc(size: uint) -> uint {
if size < 128 { return (size >> 3) - 1 }
clz := intrinsics.count_leading_zeros(i32(size))
bucket_index: i32 = ((clz > 19) \
? 110 - (clz<<2) + ((i32)(size >> (u32)(29-clz)) ~ 4) \
: min( 71 - (clz<<1) + ((i32)(size >> (u32)(30-clz)) ~ 2), NUM_FREE_BUCKETS-1))
assert(bucket_index >= 0)
assert(bucket_index < NUM_FREE_BUCKETS)
return uint(bucket_index)
}
@(private="file")
prev_region :: proc(region: ^Region) -> ^Region {
prev_region_size := ([^]uint)(region)[-1]
prev_region_size = prev_region_size & ~uint(FREE_REGION_FLAG)
return (^Region)(uintptr(region)-uintptr(prev_region_size))
}
@(private="file")
next_region :: proc(region: ^Region) -> ^Region {
return (^Region)(uintptr(region)+uintptr(region.size))
}
@(private="file")
region_ceiling_size :: proc(region: ^Region) -> uint {
return ([^]uint)(uintptr(region)+uintptr(region.size))[-1]
}
@(private="file")
region_is_free :: proc(r: ^Region) -> bool {
return region_ceiling_size(r) & FREE_REGION_FLAG >= 1
}
@(private="file")
region_is_in_use :: proc(r: ^Region) -> bool {
return r.size == region_ceiling_size(r)
}
@(private="file")
region_payload_start_ptr :: proc(r: ^Region) -> [^]byte {
return ([^]byte)(r)[size_of(uint):]
}
@(private="file")
region_payload_end_ptr :: proc(r: ^Region) -> [^]byte {
return ([^]byte)(r)[r.size-size_of(uint):]
}
@(private="file")
create_used_region :: proc(ptr: rawptr, size: uint) {
assert(has_alignment(uintptr(ptr), size_of(uint)))
assert(has_alignment(size, size_of(uint)))
assert(size >= size_of(Region))
uptr := ([^]uint)(ptr)
uptr[0] = size
uptr[size/size_of(uint)-1] = size
}
@(private="file")
create_free_region :: proc(ptr: rawptr, size: uint) {
assert(has_alignment(uintptr(ptr), size_of(uint)))
assert(has_alignment(size, size_of(uint)))
assert(size >= size_of(Region))
free_region := (^Region)(ptr)
free_region.size = size
([^]uint)(ptr)[size/size_of(uint)-1] = size | FREE_REGION_FLAG
}
@(private="file")
prepend_to_free_list :: proc(region: ^Region, prepend_to: ^Region) {
assert(region_is_free(region))
region.next = prepend_to
region.prev = prepend_to.prev
prepend_to.prev = region
region.prev.next = region
}
@(private="file")
unlink_from_free_list :: proc(region: ^Region) {
assert(region_is_free(region))
region.prev.next = region.next
region.next.prev = region.prev
}
@(private="file")
link_to_free_list :: proc(a: ^WASM_Allocator, free_region: ^Region) {
assert(free_region.size >= size_of(Region))
bucket_index := compute_free_list_bucket(free_region.size-REGION_HEADER_SIZE)
free_list_head := &a.free_region_buckets[bucket_index]
free_region.prev = free_list_head
free_region.next = free_list_head.next
free_list_head.next = free_region
free_region.next.prev = free_region
a.free_region_buckets_used |= BUCKET_BITMASK_T(1) << bucket_index
}
@(private="file")
claim_more_memory :: proc(a: ^WASM_Allocator, num_bytes: uint) -> bool {
PAGE_SIZE :: 64 * 1024
page_alloc :: proc(page_count: int) -> []byte {
prev_page_count := intrinsics.wasm_memory_grow(0, uintptr(page_count))
if prev_page_count < 0 { return nil }
ptr := ([^]byte)(uintptr(prev_page_count) * PAGE_SIZE)
return ptr[:page_count * PAGE_SIZE]
}
alloc :: proc(a: ^WASM_Allocator, num_bytes: uint) -> (bytes: [^]byte) #no_bounds_check {
if uint(len(a.spill)) >= num_bytes {
bytes = raw_data(a.spill[:num_bytes])
a.spill = a.spill[num_bytes:]
return
}
pages := int((num_bytes / PAGE_SIZE) + 1)
allocated := page_alloc(pages)
if allocated == nil { return nil }
// If the allocated memory is a direct continuation of the spill from before,
// we can just extend the spill.
spill_end := uintptr(raw_data(a.spill)) + uintptr(len(a.spill))
if spill_end == uintptr(raw_data(allocated)) {
raw_spill := (^Raw_Slice)(&a.spill)
raw_spill.len += len(allocated)
} else {
// Otherwise, we have to "waste" the previous spill.
// Now this is probably uncommon, and will only happen if another code path
// is also requesting pages.
a.spill = allocated
}
bytes = raw_data(a.spill)
a.spill = a.spill[num_bytes:]
return
}
num_bytes := num_bytes
num_bytes = align_forward(num_bytes, a.alignment)
start_ptr := alloc(a, uint(num_bytes))
if start_ptr == nil { return false }
assert(has_alignment(uintptr(start_ptr), align_of(uint)))
end_ptr := start_ptr[num_bytes:]
end_sentinel_region := (^Region)(end_ptr[-size_of(Region):])
create_used_region(end_sentinel_region, size_of(Region))
// If we are the sole user of wasm_memory_grow(), it will feed us continuous/consecutive memory addresses - take advantage
// of that if so: instead of creating two disjoint memory regions blocks, expand the previous one to a larger size.
prev_alloc_end_address := a.list_of_all_regions != nil ? a.list_of_all_regions.end_ptr : nil
if start_ptr == prev_alloc_end_address {
prev_end_sentinel := prev_region((^Region)(start_ptr))
assert(region_is_in_use(prev_end_sentinel))
prev_region := prev_region(prev_end_sentinel)
a.list_of_all_regions.end_ptr = end_ptr
// Two scenarios, either the last region of the previous block was in use, in which case we need to create
// a new free region in the newly allocated space; or it was free, in which case we can extend that region
// to cover a larger size.
if region_is_free(prev_region) {
new_free_region_size := uint(uintptr(end_sentinel_region) - uintptr(prev_region))
unlink_from_free_list(prev_region)
create_free_region(prev_region, new_free_region_size)
link_to_free_list(a, prev_region)
return true
}
start_ptr = start_ptr[-size_of(Region):]
} else {
create_used_region(start_ptr, size_of(Region))
new_region_block := (^Root_Region)(start_ptr)
new_region_block.next = a.list_of_all_regions
new_region_block.end_ptr = end_ptr
a.list_of_all_regions = new_region_block
start_ptr = start_ptr[size_of(Region):]
}
create_free_region(start_ptr, uint(uintptr(end_sentinel_region)-uintptr(start_ptr)))
link_to_free_list(a, (^Region)(start_ptr))
return true
}
@(private="file")
validate_alloc_size :: proc(size: uint) -> uint {
#assert(size_of(uint) >= size_of(uintptr))
#assert(size_of(uint) % size_of(uintptr) == 0)
// NOTE: emmalloc aligns this forward on pointer size, but I think that is a mistake and will
// do bad on wasm64p32.
validated_size := size > SMALLEST_ALLOCATION_SIZE ? align_forward(size, size_of(uint)) : SMALLEST_ALLOCATION_SIZE
assert(validated_size >= size) // Assert we haven't wrapped.
return validated_size
}
@(private="file")
allocate_memory :: proc(a: ^WASM_Allocator, alignment: uint, size: uint, loc := #caller_location) -> rawptr {
attempt_allocate :: proc(a: ^WASM_Allocator, free_region: ^Region, alignment, size: uint) -> rawptr {
assert_locked(a)
free_region := free_region
payload_start_ptr := uintptr(region_payload_start_ptr(free_region))
payload_start_ptr_aligned := align_forward(payload_start_ptr, uintptr(alignment))
payload_end_ptr := uintptr(region_payload_end_ptr(free_region))
if payload_start_ptr_aligned + uintptr(size) > payload_end_ptr {
return nil
}
// We have enough free space, so the memory allocation will be made into this region. Remove this free region
// from the list of free regions: whatever slop remains will be later added back to the free region pool.
unlink_from_free_list(free_region)
// Before we proceed further, fix up the boundary between this and the preceding region,
// so that the boundary between the two regions happens at a right spot for the payload to be aligned.
if payload_start_ptr != payload_start_ptr_aligned {
prev := prev_region(free_region)
assert(region_is_in_use(prev))
region_boundary_bump_amount := payload_start_ptr_aligned - payload_start_ptr
new_this_region_size := free_region.size - uint(region_boundary_bump_amount)
create_used_region(prev, prev.size + uint(region_boundary_bump_amount))
free_region = (^Region)(uintptr(free_region) + region_boundary_bump_amount)
free_region.size = new_this_region_size
}
// Next, we need to decide whether this region is so large that it should be split into two regions,
// one representing the newly used memory area, and at the high end a remaining leftover free area.
// This splitting to two is done always if there is enough space for the high end to fit a region.
// Carve 'size' bytes of payload off this region. So,
// [sz prev next sz]
// becomes
// [sz payload sz] [sz prev next sz]
if size_of(Region) + REGION_HEADER_SIZE + size <= free_region.size {
new_free_region := (^Region)(uintptr(free_region) + REGION_HEADER_SIZE + uintptr(size))
create_free_region(new_free_region, free_region.size - size - REGION_HEADER_SIZE)
link_to_free_list(a, new_free_region)
create_used_region(free_region, size + REGION_HEADER_SIZE)
} else {
// There is not enough space to split the free memory region into used+free parts, so consume the whole
// region as used memory, not leaving a free memory region behind.
// Initialize the free region as used by resetting the ceiling size to the same value as the size at bottom.
([^]uint)(uintptr(free_region) + uintptr(free_region.size))[-1] = free_region.size
}
return rawptr(uintptr(free_region) + size_of(uint))
}
assert_locked(a)
assert(is_power_of_two(alignment))
assert(size <= MAX_ALLOC_SIZE, "allocation too big", loc=loc)
alignment := alignment
alignment = max(alignment, a.alignment)
size := size
size = validate_alloc_size(size)
// Attempt to allocate memory starting from smallest bucket that can contain the required amount of memory.
// Under normal alignment conditions this should always be the first or second bucket we look at, but if
// performing an allocation with complex alignment, we may need to look at multiple buckets.
bucket_index := compute_free_list_bucket(size)
bucket_mask := a.free_region_buckets_used >> bucket_index
// Loop through each bucket that has free regions in it, based on bits set in free_region_buckets_used bitmap.
for bucket_mask != 0 {
index_add := intrinsics.count_trailing_zeros(bucket_mask)
bucket_index += uint(index_add)
bucket_mask >>= index_add
assert(bucket_index <= NUM_FREE_BUCKETS-1)
assert(a.free_region_buckets_used & (BUCKET_BITMASK_T(1) << bucket_index) > 0)
free_region := a.free_region_buckets[bucket_index].next
assert(free_region != nil)
if free_region != &a.free_region_buckets[bucket_index] {
ptr := attempt_allocate(a, free_region, alignment, size)
if ptr != nil {
return ptr
}
// We were not able to allocate from the first region found in this bucket, so penalize
// the region by cycling it to the end of the doubly circular linked list. (constant time)
// This provides a randomized guarantee that when performing allocations of size k to a
// bucket of [k-something, k+something] range, we will not always attempt to satisfy the
// allocation from the same available region at the front of the list, but we try each
// region in turn.
unlink_from_free_list(free_region)
prepend_to_free_list(free_region, &a.free_region_buckets[bucket_index])
// But do not stick around to attempt to look at other regions in this bucket - move
// to search the next populated bucket index if this did not fit. This gives a practical
// "allocation in constant time" guarantee, since the next higher bucket will only have
// regions that are all of strictly larger size than the requested allocation. Only if
// there is a difficult alignment requirement we may fail to perform the allocation from
// a region in the next bucket, and if so, we keep trying higher buckets until one of them
// works.
bucket_index += 1
bucket_mask >>= 1
} else {
// This bucket was not populated after all with any regions,
// but we just had a stale bit set to mark a populated bucket.
// Reset the bit to update latest status so that we do not
// redundantly look at this bucket again.
a.free_region_buckets_used &~= BUCKET_BITMASK_T(1) << bucket_index
bucket_mask ~= 1
}
assert((bucket_index == NUM_FREE_BUCKETS && bucket_mask == 0) || (bucket_mask == a.free_region_buckets_used >> bucket_index))
}
// None of the buckets were able to accommodate an allocation. If this happens we are almost out of memory.
// The largest bucket might contain some suitable regions, but we only looked at one region in that bucket, so
// as a last resort, loop through more free regions in the bucket that represents the largest allocations available.
// But only if the bucket representing largest allocations available is not any of the first thirty buckets,
// these represent allocatable areas less than <1024 bytes - which could be a lot of scrap.
// In such case, prefer to claim more memory right away.
largest_bucket_index := NUM_FREE_BUCKETS - 1 - intrinsics.count_leading_zeros(a.free_region_buckets_used)
// free_region will be null if there is absolutely no memory left. (all buckets are 100% used)
free_region := a.free_region_buckets_used > 0 ? a.free_region_buckets[largest_bucket_index].next : nil
// The 30 first free region buckets cover memory blocks < 2048 bytes, so skip looking at those here (too small)
if a.free_region_buckets_used >> 30 > 0 {
// Look only at a constant number of regions in this bucket max, to avoid bad worst case behavior.
// If this many regions cannot find free space, we give up and prefer to claim more memory instead.
max_regions_to_try_before_giving_up :: 99
num_tries_left := max_regions_to_try_before_giving_up
for ; free_region != &a.free_region_buckets[largest_bucket_index] && num_tries_left > 0; num_tries_left -= 1 {
ptr := attempt_allocate(a, free_region, alignment, size)
if ptr != nil {
return ptr
}
free_region = free_region.next
}
}
// We were unable to find a free memory region. Must claim more memory!
num_bytes_to_claim := size+size_of(Region)*3
if alignment > a.alignment {
num_bytes_to_claim += alignment
}
success := claim_more_memory(a, num_bytes_to_claim)
if (success) {
// Try allocate again with the newly available memory.
return allocate_memory(a, alignment, size)
}
// also claim_more_memory failed, we are really really constrained :( As a last resort, go back to looking at the
// bucket we already looked at above, continuing where the above search left off - perhaps there are
// regions we overlooked the first time that might be able to satisfy the allocation.
if free_region != nil {
for free_region != &a.free_region_buckets[largest_bucket_index] {
ptr := attempt_allocate(a, free_region, alignment, size)
if ptr != nil {
return ptr
}
free_region = free_region.next
}
}
// Fully out of memory.
return nil
}
@(private="file")
aligned_alloc :: proc(a: ^WASM_Allocator, alignment, size: uint, loc := #caller_location) -> rawptr {
lock(a)
defer unlock(a)
return allocate_memory(a, alignment, size, loc)
}
@(private="file")
free :: proc(a: ^WASM_Allocator, ptr: rawptr, loc := #caller_location) {
if ptr == nil {
return
}
region_start_ptr := uintptr(ptr) - size_of(uint)
region := (^Region)(region_start_ptr)
assert(has_alignment(region_start_ptr, size_of(uint)))
lock(a)
defer unlock(a)
size := region.size
assert(region_is_in_use(region), "double free or corrupt region", loc=loc)
prev_region_size_field := ([^]uint)(region)[-1]
prev_region_size := prev_region_size_field & ~uint(FREE_REGION_FLAG)
if prev_region_size_field != prev_region_size {
prev_region := (^Region)(uintptr(region) - uintptr(prev_region_size))
unlink_from_free_list(prev_region)
region_start_ptr = uintptr(prev_region)
size += prev_region_size
}
next_reg := next_region(region)
size_at_end := (^uint)(region_payload_end_ptr(next_reg))^
if next_reg.size != size_at_end {
unlink_from_free_list(next_reg)
size += next_reg.size
}
create_free_region(rawptr(region_start_ptr), size)
link_to_free_list(a, (^Region)(region_start_ptr))
}
@(private="file")
aligned_realloc :: proc(a: ^WASM_Allocator, ptr: rawptr, alignment, size: uint, loc := #caller_location) -> rawptr {
attempt_region_resize :: proc(a: ^WASM_Allocator, region: ^Region, size: uint) -> bool {
lock(a)
defer unlock(a)
// First attempt to resize this region, if the next region that follows this one
// is a free region.
next_reg := next_region(region)
next_region_end_ptr := uintptr(next_reg) + uintptr(next_reg.size)
size_at_ceiling := ([^]uint)(next_region_end_ptr)[-1]
if next_reg.size != size_at_ceiling { // Next region is free?
assert(region_is_free(next_reg))
new_next_region_start_ptr := uintptr(region) + uintptr(size)
assert(has_alignment(new_next_region_start_ptr, size_of(uint)))
// Next region does not shrink to too small size?
if new_next_region_start_ptr + size_of(Region) <= next_region_end_ptr {
unlink_from_free_list(next_reg)
create_free_region(rawptr(new_next_region_start_ptr), uint(next_region_end_ptr - new_next_region_start_ptr))
link_to_free_list(a, (^Region)(new_next_region_start_ptr))
create_used_region(region, uint(new_next_region_start_ptr - uintptr(region)))
return true
}
// If we remove the next region altogether, allocation is satisfied?
if new_next_region_start_ptr <= next_region_end_ptr {
unlink_from_free_list(next_reg)
create_used_region(region, region.size + next_reg.size)
return true
}
} else {
// Next region is an used region - we cannot change its starting address. However if we are shrinking the
// size of this region, we can create a new free region between this and the next used region.
if size + size_of(Region) <= region.size {
free_region_size := region.size - size
create_used_region(region, size)
free_region := (^Region)(uintptr(region) + uintptr(size))
create_free_region(free_region, free_region_size)
link_to_free_list(a, free_region)
return true
} else if size <= region.size {
// Caller was asking to shrink the size, but due to not being able to fit a full Region in the shrunk
// area, we cannot actually do anything. This occurs if the shrink amount is really small. In such case,
// just call it success without doing any work.
return true
}
}
return false
}
if ptr == nil {
return aligned_alloc(a, alignment, size, loc)
}
if size == 0 {
free(a, ptr, loc)
return nil
}
if size > MAX_ALLOC_SIZE {
return nil
}
assert(is_power_of_two(alignment))
assert(has_alignment(uintptr(ptr), alignment), "realloc on different alignment than original allocation", loc=loc)
size := size
size = validate_alloc_size(size)
region := (^Region)(uintptr(ptr) - size_of(uint))
// Attempt an in-place resize.
if attempt_region_resize(a, region, size + REGION_HEADER_SIZE) {
return ptr
}
// Can't do it in-place, allocate new region and copy over.
newptr := aligned_alloc(a, alignment, size, loc)
if newptr != nil {
intrinsics.mem_copy(newptr, ptr, min(size, region.size - REGION_HEADER_SIZE))
free(a, ptr, loc=loc)
}
return newptr
}
Binary file not shown.
Binary file not shown.
+42 -8
View File
@@ -19,12 +19,12 @@ if "%VSCMD_ARG_TGT_ARCH%" neq "x64" (
)
)
for /f "usebackq tokens=1,2 delims=,=- " %%i in (`wmic os get LocalDateTime /value`) do @if %%i==LocalDateTime (
set CURR_DATE_TIME=%%j
for /f %%i in ('powershell get-date -format "{yyyyMMdd}"') do (
set CURR_DATE_TIME=%%i
)
set curr_year=%CURR_DATE_TIME:~0,4%
set curr_month=%CURR_DATE_TIME:~4,2%
set curr_day=%CURR_DATE_TIME:~6,2%
:: Make sure this is a decent name and not generic
set exe_name=odin.exe
@@ -45,23 +45,50 @@ if "%2" == "1" (
set nightly=0
)
set odin_version_raw="dev-%curr_year%-%curr_month%"
if %release_mode% equ 0 (
set V1=%curr_year%
set V2=%curr_month%
set V3=%curr_day%
) else (
set V1=%curr_year%
set V2=%curr_month%
set V3=0
)
set V4=0
set odin_version_full="%V1%.%V2%.%V3%.%V4%"
set odin_version_raw="dev-%V1%-%V2%"
set compiler_flags= -nologo -Oi -TP -fp:precise -Gm- -MP -FC -EHsc- -GR- -GF
rem Parse source code as utf-8 even on shift-jis and other codepages
rem See https://learn.microsoft.com/en-us/cpp/build/reference/utf-8-set-source-and-executable-character-sets-to-utf-8?view=msvc-170
set compiler_flags= %compiler_flags% /utf-8
set compiler_defines= -DODIN_VERSION_RAW=\"%odin_version_raw%\"
rem fileversion is defined as {Major,Minor,Build,Private: u16} so a bit limited
set rc_flags=-nologo ^
-DV1=%V1% -DV2=%V2% -DV3=%V3% -DV4=%V4% ^
-DVF=%odin_version_full% -DNIGHTLY=%nightly%
where /Q git.exe || goto skip_git_hash
if not exist .git\ goto skip_git_hash
for /f "tokens=1,2" %%i IN ('git show "--pretty=%%cd %%h" "--date=format:%%Y-%%m" --no-patch --no-notes HEAD') do (
set odin_version_raw=dev-%%i
set GIT_SHA=%%j
)
if %ERRORLEVEL% equ 0 set compiler_defines=%compiler_defines% -DGIT_SHA=\"%GIT_SHA%\"
if %ERRORLEVEL% equ 0 (
set compiler_defines=%compiler_defines% -DGIT_SHA=\"%GIT_SHA%\"
set rc_flags=%rc_flags% -DGIT_SHA=%GIT_SHA% -DVP=%odin_version_raw%:%GIT_SHA%
) else (
set rc_flags=%rc_flags% -DVP=%odin_version_raw%
)
:skip_git_hash
if %nightly% equ 1 set compiler_defines=%compiler_defines% -DNIGHTLY
if %release_mode% EQU 0 ( rem Debug
set compiler_flags=%compiler_flags% -Od -MDd -Z7
set rc_flags=%rc_flags% -D_DEBUG
) else ( rem Release
set compiler_flags=%compiler_flags% -O2 -MT -Z7
set compiler_defines=%compiler_defines% -DNO_ARRAY_BOUNDS_CHECK
@@ -79,6 +106,8 @@ set libs= ^
kernel32.lib ^
Synchronization.lib ^
bin\llvm\windows\LLVM-C.lib
set odin_res=misc\odin.res
set odin_rc=misc\odin.rc
rem DO NOT TOUCH!
rem THIS TILDE STUFF IS FOR DEVELOPMENT ONLY!
@@ -90,7 +119,7 @@ if %tilde_backend% EQU 1 (
rem DO NOT TOUCH!
set linker_flags= -incremental:no -opt:ref -subsystem:console
set linker_flags= -incremental:no -opt:ref -subsystem:console -MANIFEST:EMBED
if %release_mode% EQU 0 ( rem Debug
set linker_flags=%linker_flags% -debug /NATVIS:src\odin_compiler.natvis
@@ -99,19 +128,24 @@ if %release_mode% EQU 0 ( rem Debug
)
set compiler_settings=%compiler_includes% %compiler_flags% %compiler_warnings% %compiler_defines%
set linker_settings=%libs% %linker_flags%
set linker_settings=%libs% %odin_res% %linker_flags%
del *.pdb > NUL 2> NUL
del *.ilk > NUL 2> NUL
rc %rc_flags% %odin_rc%
cl %compiler_settings% "src\main.cpp" "src\libtommath.cpp" /link %linker_settings% -OUT:%exe_name%
mt -nologo -inputresource:%exe_name%;#1 -manifest misc\odin.manifest -outputresource:%exe_name%;#1 -validate_manifest -identity:"odin, processorArchitecture=amd64, version=%odin_version_full%, type=win32"
if %errorlevel% neq 0 goto end_of_build
call build_vendor.bat
if %errorlevel% neq 0 goto end_of_build
rem If the demo doesn't run for you and your CPU is more than a decade old, try -microarch:native
if %release_mode% EQU 0 odin run examples/demo -- Hellope World
if %release_mode% EQU 0 odin run examples/demo -vet -strict-style -resource:examples/demo/demo.rc -- Hellope World
rem Many non-compiler devs seem to run debug build but don't realize.
if %release_mode% EQU 0 echo: & echo Debug compiler built. Note: run "build.bat release" if you want a faster, release mode compiler.
del *.obj > NUL 2> NUL
+37 -5
View File
@@ -23,6 +23,14 @@ error() {
exit 1
}
# Brew advises people not to add llvm to their $PATH, so try and use brew to find it.
if [ -z "$LLVM_CONFIG" ] && [ -n "$(command -v brew)" ]; then
if [ -n "$(command -v $(brew --prefix llvm@18)/bin/llvm-config)" ]; then LLVM_CONFIG="$(brew --prefix llvm@18)/bin/llvm-config"
elif [ -n "$(command -v $(brew --prefix llvm@17)/bin/llvm-config)" ]; then LLVM_CONFIG="$(brew --prefix llvm@17)/bin/llvm-config"
elif [ -n "$(command -v $(brew --prefix llvm@14)/bin/llvm-config)" ]; then LLVM_CONFIG="$(brew --prefix llvm@14)/bin/llvm-config"
fi
fi
if [ -z "$LLVM_CONFIG" ]; then
# darwin, linux, openbsd
if [ -n "$(command -v llvm-config-18)" ]; then LLVM_CONFIG="llvm-config-18"
@@ -45,7 +53,13 @@ if [ -z "$LLVM_CONFIG" ]; then
fi
fi
: ${CXX=$($LLVM_CONFIG --bindir)/clang++}
if [ -x "$(which clang++)" ]; then
: ${CXX="clang++"}
elif [ -x "$($LLVM_CONFIG --bindir)/clang++" ]; then
: ${CXX=$($LLVM_CONFIG --bindir)/clang++}
else
error "No clang++ command found. Set CXX to proceed."
fi
LLVM_VERSION="$($LLVM_CONFIG --version)"
LLVM_VERSION_MAJOR="$(echo $LLVM_VERSION | awk -F. '{print $1}')"
@@ -64,19 +78,32 @@ Darwin)
fi
fi
CXXFLAGS="$CXXFLAGS $($LLVM_CONFIG --cxxflags --ldflags)"
darwin_sysroot=
if [ $(which xcrun) ]; then
darwin_sysroot="--sysroot $(xcrun --sdk macosx --show-sdk-path)"
elif [[ -e "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk" ]]; then
darwin_sysroot="--sysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk"
else
echo "Warning: MacOSX.sdk not found."
fi
CXXFLAGS="$CXXFLAGS $($LLVM_CONFIG --cxxflags --ldflags) ${darwin_sysroot}"
LDFLAGS="$LDFLAGS -liconv -ldl -framework System -lLLVM"
;;
FreeBSD)
CXXFLAGS="$CXXFLAGS $($LLVM_CONFIG --cxxflags --ldflags)"
LDFLAGS="$LDFLAGS $($LLVM_CONFIG --libs core native --system-libs)"
;;
NetBSD)
CXXFLAGS="$CXXFLAGS $($LLVM_CONFIG --cxxflags --ldflags)"
LDFLAGS="$LDFLAGS $($LLVM_CONFIG --libs core native --system-libs)"
;;
Linux)
CXXFLAGS="$CXXFLAGS $($LLVM_CONFIG --cxxflags --ldflags)"
LDFLAGS="$LDFLAGS -ldl $($LLVM_CONFIG --libs core native --system-libs --libfiles)"
# Copy libLLVM*.so into current directory for linking
# NOTE: This is needed by the Linux release pipeline!
cp $(readlink -f $($LLVM_CONFIG --libfiles)) ./
# cp $(readlink -f $($LLVM_CONFIG --libfiles)) ./
LDFLAGS="$LDFLAGS -Wl,-rpath=\$ORIGIN"
;;
OpenBSD)
@@ -103,7 +130,7 @@ build_odin() {
EXTRAFLAGS="-O3"
;;
release-native)
if [ "$OS_ARCH" = "arm64" ]; then
if [ "$OS_ARCH" = "arm64" ] || [ "$OS_ARCH" = "aarch64" ]; then
# Use preferred flag for Arm (ie arm64 / aarch64 / etc)
EXTRAFLAGS="-O3 -mcpu=native"
else
@@ -125,12 +152,17 @@ build_odin() {
}
run_demo() {
./odin run examples/demo/demo.odin -file -- Hellope World
if [ $# -eq 0 ] || [ "$1" = "debug" ]; then
./odin run examples/demo -vet -strict-style -- Hellope World
fi
}
if [ $# -eq 0 ]; then
build_odin debug
run_demo
: ${PROGRAM:=$0}
printf "\nDebug compiler built. Note: run \"$PROGRAM release\" or \"$PROGRAM release-native\" if you want a faster, release mode compiler.\n"
elif [ $# -eq 1 ]; then
case $1 in
report)
+19
View File
@@ -0,0 +1,19 @@
#!/usr/bin/env sh
# Intended for use in Alpine containers, see the "nightly" Github action for a list of dependencies
CXX="clang++-18"
LLVM_CONFIG="llvm-config-18"
DISABLED_WARNINGS="-Wno-switch -Wno-macro-redefined -Wno-unused-value"
CPPFLAGS="-DODIN_VERSION_RAW=\"dev-$(date +"%Y-%m")\""
CXXFLAGS="-std=c++14 $($LLVM_CONFIG --cxxflags --ldflags)"
LDFLAGS="-static -lm -lzstd -lz -lffi -pthread -ldl -fuse-ld=mold"
LDFLAGS="$LDFLAGS $($LLVM_CONFIG --link-static --ldflags --libs --system-libs --libfiles)"
LDFLAGS="$LDFLAGS -Wl,-rpath=\$ORIGIN"
EXTRAFLAGS="-DNIGHTLY -O3"
set -x
$CXX src/main.cpp src/libtommath.cpp $DISABLED_WARNINGS $CPPFLAGS $CXXFLAGS $EXTRAFLAGS $LDFLAGS -o odin
-51
View File
@@ -1,51 +0,0 @@
import subprocess
import sys
import json
import datetime
import urllib.parse
import sys
def main():
files_by_date = {}
bucket = sys.argv[1]
files_lines = execute_cli(f"b2 ls --long {bucket} nightly").split("\n")
for x in files_lines:
parts = x.split(" ", 1)
if parts[0]:
json_str = execute_cli(f"b2 get-file-info {parts[0]}")
data = json.loads(json_str)
name = remove_prefix(data['fileName'], "nightly/")
url = f"https://f001.backblazeb2.com/file/{bucket}/nightly/{urllib.parse.quote_plus(name)}"
sha1 = data['contentSha1']
size = int(data['size'])
ts = int(data['fileInfo']['src_last_modified_millis'])
date = datetime.datetime.fromtimestamp(ts/1000).strftime('%Y-%m-%d')
if date not in files_by_date.keys():
files_by_date[date] = []
files_by_date[date].append({
'name': name,
'url': url,
'sha1': sha1,
'sizeInBytes': size,
})
now = datetime.datetime.utcnow().isoformat()
print(json.dumps({
'last_updated' : now,
'files': files_by_date
}, sort_keys=True, indent=4))
def remove_prefix(text, prefix):
return text[text.startswith(prefix) and len(prefix):]
def execute_cli(command):
sb = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
return sb.stdout.read().decode("utf-8");
if __name__ == '__main__':
sys.exit(main())
-34
View File
@@ -1,34 +0,0 @@
import subprocess
import sys
import json
import datetime
import urllib.parse
import sys
def main():
files_by_date = {}
bucket = sys.argv[1]
days_to_keep = int(sys.argv[2])
print(f"Looking for binaries to delete older than {days_to_keep} days")
files_lines = execute_cli(f"b2 ls --long --versions {bucket} nightly").split("\n")
for x in files_lines:
parts = [y for y in x.split(' ') if y]
if parts and parts[0]:
date = datetime.datetime.strptime(parts[2], '%Y-%m-%d').replace(hour=0, minute=0, second=0, microsecond=0)
now = datetime.datetime.utcnow().replace(hour=0, minute=0, second=0, microsecond=0)
delta = now - date
if delta.days > days_to_keep:
print(f'Deleting {parts[5]}')
execute_cli(f'b2 delete-file-version {parts[0]}')
def execute_cli(command):
sb = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
return sb.stdout.read().decode("utf-8");
if __name__ == '__main__':
sys.exit(main())
+145
View File
@@ -0,0 +1,145 @@
import os
import sys
from zipfile import ZipFile, ZIP_DEFLATED
from b2sdk.v2 import InMemoryAccountInfo, B2Api
from datetime import datetime, timezone
import json
UPLOAD_FOLDER = "nightly/"
info = InMemoryAccountInfo()
b2_api = B2Api(info)
application_key_id = os.environ['APPID']
application_key = os.environ['APPKEY']
bucket_name = os.environ['BUCKET']
days_to_keep = os.environ['DAYS_TO_KEEP']
def auth() -> bool:
try:
realm = b2_api.account_info.get_realm()
return True # Already authenticated
except:
pass # Not yet authenticated
err = b2_api.authorize_account("production", application_key_id, application_key)
return err is None
def get_bucket():
if not auth(): sys.exit(1)
return b2_api.get_bucket_by_name(bucket_name)
def remove_prefix(text: str, prefix: str) -> str:
return text[text.startswith(prefix) and len(prefix):]
def create_and_upload_artifact_zip(platform: str, artifact: str) -> int:
now = datetime.now(timezone.utc).replace(hour=0, minute=0, second=0, microsecond=0)
source_archive: str
destination_name = f'odin-{platform}-nightly+{now.strftime("%Y-%m-%d")}'
if platform.startswith("linux") or platform.startswith("macos"):
destination_name += ".tar.gz"
source_archive = artifact
else:
destination_name += ".zip"
source_archive = destination_name
print(f"Creating archive {destination_name} from {artifact} and uploading to {bucket_name}")
with ZipFile(source_archive, mode='w', compression=ZIP_DEFLATED, compresslevel=9) as z:
for root, directory, filenames in os.walk(artifact):
for file in filenames:
file_path = os.path.join(root, file)
zip_path = os.path.join("dist", os.path.relpath(file_path, artifact))
z.write(file_path, zip_path)
if not os.path.exists(source_archive):
print(f"Error: archive {source_archive} not found.")
return 1
print("Uploading {} to {}".format(source_archive, UPLOAD_FOLDER + destination_name))
bucket = get_bucket()
res = bucket.upload_local_file(
source_archive, # Local file to upload
"nightly/" + destination_name, # B2 destination path
)
return 0
def prune_artifacts():
print(f"Looking for binaries to delete older than {days_to_keep} days")
bucket = get_bucket()
for file, _ in bucket.ls(UPLOAD_FOLDER, latest_only=False):
# Timestamp is in milliseconds
date = datetime.fromtimestamp(file.upload_timestamp / 1_000.0, tz=timezone.utc).replace(hour=0, minute=0, second=0, microsecond=0)
now = datetime.now(timezone.utc).replace(hour=0, minute=0, second=0, microsecond=0)
delta = now - date
if delta.days > int(days_to_keep):
print("Deleting {}".format(file.file_name))
file.delete()
return 0
def update_nightly_json():
print(f"Updating nightly.json with files {days_to_keep} days or newer")
files_by_date = {}
bucket = get_bucket()
for file, _ in bucket.ls(UPLOAD_FOLDER, latest_only=True):
# Timestamp is in milliseconds
date = datetime.fromtimestamp(file.upload_timestamp / 1_000.0).replace(hour=0, minute=0, second=0, microsecond=0).strftime('%Y-%m-%d')
name = remove_prefix(file.file_name, UPLOAD_FOLDER)
sha1 = file.content_sha1
size = file.size
url = bucket.get_download_url(file.file_name)
if date not in files_by_date.keys():
files_by_date[date] = []
files_by_date[date].append({
'name': name,
'url': url,
'sha1': sha1,
'sizeInBytes': size,
})
now = datetime.now(timezone.utc).isoformat()
nightly = json.dumps({
'last_updated' : now,
'files': files_by_date
}, sort_keys=True, indent=4, ensure_ascii=False).encode('utf-8')
res = bucket.upload_bytes(
nightly, # JSON bytes
"nightly.json", # B2 destination path
)
return 0
if __name__ == "__main__":
if len(sys.argv) == 1:
print("Usage: {} <verb> [arguments]".format(sys.argv[0]))
print("\tartifact <platform prefix> <artifact path>\n\t\tCreates and uploads a platform artifact zip.")
print("\tprune\n\t\tDeletes old artifacts from bucket")
print("\tjson\n\t\tUpdate and upload nightly.json")
sys.exit(1)
else:
command = sys.argv[1].lower()
if command == "artifact":
if len(sys.argv) != 4:
print("Usage: {} artifact <platform prefix> <artifact path>".format(sys.argv[0]))
print("Error: Expected artifact command to be given platform prefix and artifact path.\n")
sys.exit(1)
res = create_and_upload_artifact_zip(sys.argv[2], sys.argv[3])
sys.exit(res)
elif command == "prune":
res = prune_artifacts()
sys.exit(res)
elif command == "json":
res = update_nightly_json()
sys.exit(res)
-25
View File
@@ -1,25 +0,0 @@
#!/bin/bash
set -e
bucket=$1
platform=$2
artifact=$3
now=$(date +'%Y-%m-%d')
filename="odin-$platform-nightly+$now.zip"
echo "Creating archive $filename from $artifact and uploading to $bucket"
# If this is already zipped up (done before artifact upload to keep permissions in tact), just move it.
if [ "${artifact: -4}" == ".zip" ]
then
echo "Artifact already a zip"
mkdir -p "output"
mv "$artifact" "output/$filename"
else
echo "Artifact needs to be zipped"
7z a -bd "output/$filename" -r "$artifact"
fi
b2 upload-file --noProgress "$bucket" "output/$filename" "nightly/$filename"
+2 -2
View File
@@ -29,12 +29,12 @@ MIN_READ_BUFFER_SIZE :: 16
@(private)
DEFAULT_MAX_CONSECUTIVE_EMPTY_READS :: 128
reader_init :: proc(b: ^Reader, rd: io.Reader, size: int = DEFAULT_BUF_SIZE, allocator := context.allocator) {
reader_init :: proc(b: ^Reader, rd: io.Reader, size: int = DEFAULT_BUF_SIZE, allocator := context.allocator, loc := #caller_location) {
size := size
size = max(size, MIN_READ_BUFFER_SIZE)
reader_reset(b, rd)
b.buf_allocator = allocator
b.buf = make([]byte, size, allocator)
b.buf = make([]byte, size, allocator, loc)
}
reader_init_with_buf :: proc(b: ^Reader, rd: io.Reader, buf: []byte) {
+68 -38
View File
@@ -27,19 +27,19 @@ Read_Op :: enum i8 {
}
buffer_init :: proc(b: ^Buffer, buf: []byte) {
resize(&b.buf, len(buf))
buffer_init :: proc(b: ^Buffer, buf: []byte, loc := #caller_location) {
resize(&b.buf, len(buf), loc=loc)
copy(b.buf[:], buf)
}
buffer_init_string :: proc(b: ^Buffer, s: string) {
resize(&b.buf, len(s))
buffer_init_string :: proc(b: ^Buffer, s: string, loc := #caller_location) {
resize(&b.buf, len(s), loc=loc)
copy(b.buf[:], s)
}
buffer_init_allocator :: proc(b: ^Buffer, len, cap: int, allocator := context.allocator) {
buffer_init_allocator :: proc(b: ^Buffer, len, cap: int, allocator := context.allocator, loc := #caller_location) {
if b.buf == nil {
b.buf = make([dynamic]byte, len, cap, allocator)
b.buf = make([dynamic]byte, len, cap, allocator, loc)
return
}
@@ -96,28 +96,28 @@ buffer_truncate :: proc(b: ^Buffer, n: int) {
}
@(private)
_buffer_try_grow :: proc(b: ^Buffer, n: int) -> (int, bool) {
_buffer_try_grow :: proc(b: ^Buffer, n: int, loc := #caller_location) -> (int, bool) {
if l := len(b.buf); n <= cap(b.buf)-l {
resize(&b.buf, l+n)
resize(&b.buf, l+n, loc=loc)
return l, true
}
return 0, false
}
@(private)
_buffer_grow :: proc(b: ^Buffer, n: int) -> int {
_buffer_grow :: proc(b: ^Buffer, n: int, loc := #caller_location) -> int {
m := buffer_length(b)
if m == 0 && b.off != 0 {
buffer_reset(b)
}
if i, ok := _buffer_try_grow(b, n); ok {
if i, ok := _buffer_try_grow(b, n, loc=loc); ok {
return i
}
if b.buf == nil && n <= SMALL_BUFFER_SIZE {
// Fixes #2756 by preserving allocator if already set on Buffer via init_buffer_allocator
reserve(&b.buf, SMALL_BUFFER_SIZE)
resize(&b.buf, n)
reserve(&b.buf, SMALL_BUFFER_SIZE, loc=loc)
resize(&b.buf, n, loc=loc)
return 0
}
@@ -127,31 +127,34 @@ _buffer_grow :: proc(b: ^Buffer, n: int) -> int {
} else if c > max(int) - c - n {
panic("bytes.Buffer: too large")
} else {
resize(&b.buf, 2*c + n)
resize(&b.buf, 2*c + n, loc=loc)
copy(b.buf[:], b.buf[b.off:])
}
b.off = 0
resize(&b.buf, m+n)
resize(&b.buf, m+n, loc=loc)
return m
}
buffer_grow :: proc(b: ^Buffer, n: int) {
buffer_grow :: proc(b: ^Buffer, n: int, loc := #caller_location) {
if n < 0 {
panic("bytes.buffer_grow: negative count")
}
m := _buffer_grow(b, n)
resize(&b.buf, m)
m := _buffer_grow(b, n, loc=loc)
resize(&b.buf, m, loc=loc)
}
buffer_write_at :: proc(b: ^Buffer, p: []byte, offset: int) -> (n: int, err: io.Error) {
buffer_write_at :: proc(b: ^Buffer, p: []byte, offset: int, loc := #caller_location) -> (n: int, err: io.Error) {
if len(p) == 0 {
return 0, nil
}
b.last_read = .Invalid
if offset < 0 {
err = .Invalid_Offset
return
}
_, ok := _buffer_try_grow(b, offset+len(p))
_, ok := _buffer_try_grow(b, offset+len(p), loc=loc)
if !ok {
_ = _buffer_grow(b, offset+len(p))
_ = _buffer_grow(b, offset+len(p), loc=loc)
}
if len(b.buf) <= offset {
return 0, .Short_Write
@@ -160,47 +163,47 @@ buffer_write_at :: proc(b: ^Buffer, p: []byte, offset: int) -> (n: int, err: io.
}
buffer_write :: proc(b: ^Buffer, p: []byte) -> (n: int, err: io.Error) {
buffer_write :: proc(b: ^Buffer, p: []byte, loc := #caller_location) -> (n: int, err: io.Error) {
b.last_read = .Invalid
m, ok := _buffer_try_grow(b, len(p))
m, ok := _buffer_try_grow(b, len(p), loc=loc)
if !ok {
m = _buffer_grow(b, len(p))
m = _buffer_grow(b, len(p), loc=loc)
}
return copy(b.buf[m:], p), nil
}
buffer_write_ptr :: proc(b: ^Buffer, ptr: rawptr, size: int) -> (n: int, err: io.Error) {
return buffer_write(b, ([^]byte)(ptr)[:size])
buffer_write_ptr :: proc(b: ^Buffer, ptr: rawptr, size: int, loc := #caller_location) -> (n: int, err: io.Error) {
return buffer_write(b, ([^]byte)(ptr)[:size], loc=loc)
}
buffer_write_string :: proc(b: ^Buffer, s: string) -> (n: int, err: io.Error) {
buffer_write_string :: proc(b: ^Buffer, s: string, loc := #caller_location) -> (n: int, err: io.Error) {
b.last_read = .Invalid
m, ok := _buffer_try_grow(b, len(s))
m, ok := _buffer_try_grow(b, len(s), loc=loc)
if !ok {
m = _buffer_grow(b, len(s))
m = _buffer_grow(b, len(s), loc=loc)
}
return copy(b.buf[m:], s), nil
}
buffer_write_byte :: proc(b: ^Buffer, c: byte) -> io.Error {
buffer_write_byte :: proc(b: ^Buffer, c: byte, loc := #caller_location) -> io.Error {
b.last_read = .Invalid
m, ok := _buffer_try_grow(b, 1)
m, ok := _buffer_try_grow(b, 1, loc=loc)
if !ok {
m = _buffer_grow(b, 1)
m = _buffer_grow(b, 1, loc=loc)
}
b.buf[m] = c
return nil
}
buffer_write_rune :: proc(b: ^Buffer, r: rune) -> (n: int, err: io.Error) {
buffer_write_rune :: proc(b: ^Buffer, r: rune, loc := #caller_location) -> (n: int, err: io.Error) {
if r < utf8.RUNE_SELF {
buffer_write_byte(b, byte(r))
buffer_write_byte(b, byte(r), loc=loc)
return 1, nil
}
b.last_read = .Invalid
m, ok := _buffer_try_grow(b, utf8.UTF_MAX)
m, ok := _buffer_try_grow(b, utf8.UTF_MAX, loc=loc)
if !ok {
m = _buffer_grow(b, utf8.UTF_MAX)
m = _buffer_grow(b, utf8.UTF_MAX, loc=loc)
}
res: [4]byte
res, n = utf8.encode_rune(r)
@@ -246,10 +249,13 @@ buffer_read_ptr :: proc(b: ^Buffer, ptr: rawptr, size: int) -> (n: int, err: io.
}
buffer_read_at :: proc(b: ^Buffer, p: []byte, offset: int) -> (n: int, err: io.Error) {
if len(p) == 0 {
return 0, nil
}
b.last_read = .Invalid
if uint(offset) >= len(b.buf) {
err = .Invalid_Offset
err = .EOF
return
}
n = copy(p, b.buf[offset:])
@@ -310,6 +316,27 @@ buffer_unread_rune :: proc(b: ^Buffer) -> io.Error {
return nil
}
buffer_seek :: proc(b: ^Buffer, offset: i64, whence: io.Seek_From) -> (i64, io.Error) {
abs: i64
switch whence {
case .Start:
abs = offset
case .Current:
abs = i64(b.off) + offset
case .End:
abs = i64(len(b.buf)) + offset
case:
return 0, .Invalid_Whence
}
abs_int := int(abs)
if abs_int < 0 {
return 0, .Invalid_Offset
}
b.last_read = .Invalid
b.off = abs_int
return abs, nil
}
buffer_read_bytes :: proc(b: ^Buffer, delim: byte) -> (line: []byte, err: io.Error) {
i := index_byte(b.buf[b.off:], delim)
@@ -395,14 +422,17 @@ _buffer_proc :: proc(stream_data: rawptr, mode: io.Stream_Mode, p: []byte, offse
return io._i64_err(buffer_write(b, p))
case .Write_At:
return io._i64_err(buffer_write_at(b, p, int(offset)))
case .Seek:
n, err = buffer_seek(b, offset, whence)
return
case .Size:
n = i64(buffer_capacity(b))
n = i64(buffer_length(b))
return
case .Destroy:
buffer_destroy(b)
return
case .Query:
return io.query_utility({.Read, .Read_At, .Write, .Write_At, .Size, .Destroy})
return io.query_utility({.Read, .Read_At, .Write, .Write_At, .Seek, .Size, .Destroy, .Query})
}
return 0, .Empty
}
+309 -6
View File
@@ -1,9 +1,38 @@
package bytes
import "base:intrinsics"
import "core:mem"
import "core:simd"
import "core:unicode"
import "core:unicode/utf8"
when ODIN_ARCH == .amd64 && intrinsics.has_target_feature("avx2") {
@(private)
SCANNER_INDICES_256 : simd.u8x32 : {
0, 1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31,
}
@(private)
SCANNER_SENTINEL_MAX_256: simd.u8x32 : u8(0x00)
@(private)
SCANNER_SENTINEL_MIN_256: simd.u8x32 : u8(0xff)
@(private)
SIMD_REG_SIZE_256 :: 32
}
@(private)
SCANNER_INDICES_128 : simd.u8x16 : {
0, 1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13, 14, 15,
}
@(private)
SCANNER_SENTINEL_MAX_128: simd.u8x16 : u8(0x00)
@(private)
SCANNER_SENTINEL_MIN_128: simd.u8x16 : u8(0xff)
@(private)
SIMD_REG_SIZE_128 :: 16
clone :: proc(s: []byte, allocator := context.allocator, loc := #caller_location) -> []byte {
c := make([]byte, len(s), allocator, loc)
copy(c, s)
@@ -293,28 +322,277 @@ split_after_iterator :: proc(s: ^[]byte, sep: []byte) -> ([]byte, bool) {
return _split_iterator(s, sep, len(sep))
}
/*
Scan a slice of bytes for a specific byte.
index_byte :: proc(s: []byte, c: byte) -> int {
for i := 0; i < len(s); i += 1 {
This procedure safely handles slices of any length, including empty slices.
Inputs:
- data: A slice of bytes.
- c: The byte to search for.
Returns:
- index: The index of the byte `c`, or -1 if it was not found.
*/
index_byte :: proc "contextless" (s: []byte, c: byte) -> (index: int) #no_bounds_check {
i, l := 0, len(s)
// Guard against small strings. On modern systems, it is ALWAYS
// worth vectorizing assuming there is a hardware vector unit, and
// the data size is large enough.
if l < SIMD_REG_SIZE_128 {
for /**/; i < l; i += 1 {
if s[i] == c {
return i
}
}
return -1
}
c_vec: simd.u8x16 = c
when !simd.IS_EMULATED {
// Note: While this is something that could also logically take
// advantage of AVX512, the various downclocking and power
// consumption related woes make premature to have a dedicated
// code path.
when ODIN_ARCH == .amd64 && intrinsics.has_target_feature("avx2") {
c_vec_256: simd.u8x32 = c
s_vecs: [4]simd.u8x32 = ---
c_vecs: [4]simd.u8x32 = ---
m_vec: [4]u8 = ---
// Scan 128-byte chunks, using 256-bit SIMD.
for nr_blocks := l / (4 * SIMD_REG_SIZE_256); nr_blocks > 0; nr_blocks -= 1 {
#unroll for j in 0..<4 {
s_vecs[j] = intrinsics.unaligned_load(cast(^simd.u8x32)raw_data(s[i+j*SIMD_REG_SIZE_256:]))
c_vecs[j] = simd.lanes_eq(s_vecs[j], c_vec_256)
m_vec[j] = simd.reduce_or(c_vecs[j])
}
if m_vec[0] | m_vec[1] | m_vec[2] | m_vec[3] > 0 {
#unroll for j in 0..<4 {
if m_vec[j] > 0 {
sel := simd.select(c_vecs[j], SCANNER_INDICES_256, SCANNER_SENTINEL_MIN_256)
off := simd.reduce_min(sel)
return i + j * SIMD_REG_SIZE_256 + int(off)
}
}
}
i += 4 * SIMD_REG_SIZE_256
}
// Scan 64-byte chunks, using 256-bit SIMD.
for nr_blocks := (l - i) / (2 * SIMD_REG_SIZE_256); nr_blocks > 0; nr_blocks -= 1 {
#unroll for j in 0..<2 {
s_vecs[j] = intrinsics.unaligned_load(cast(^simd.u8x32)raw_data(s[i+j*SIMD_REG_SIZE_256:]))
c_vecs[j] = simd.lanes_eq(s_vecs[j], c_vec_256)
m_vec[j] = simd.reduce_or(c_vecs[j])
}
if m_vec[0] | m_vec[1] > 0 {
#unroll for j in 0..<2 {
if m_vec[j] > 0 {
sel := simd.select(c_vecs[j], SCANNER_INDICES_256, SCANNER_SENTINEL_MIN_256)
off := simd.reduce_min(sel)
return i + j * SIMD_REG_SIZE_256 + int(off)
}
}
}
i += 2 * SIMD_REG_SIZE_256
}
} else {
s_vecs: [4]simd.u8x16 = ---
c_vecs: [4]simd.u8x16 = ---
m_vecs: [4]u8 = ---
// Scan 64-byte chunks, using 128-bit SIMD.
for nr_blocks := l / (4 * SIMD_REG_SIZE_128); nr_blocks > 0; nr_blocks -= 1 {
#unroll for j in 0..<4 {
s_vecs[j]= intrinsics.unaligned_load(cast(^simd.u8x16)raw_data(s[i+j*SIMD_REG_SIZE_128:]))
c_vecs[j] = simd.lanes_eq(s_vecs[j], c_vec)
m_vecs[j] = simd.reduce_or(c_vecs[j])
}
if m_vecs[0] | m_vecs[1] | m_vecs[2] | m_vecs[3] > 0 {
#unroll for j in 0..<4 {
if m_vecs[j] > 0 {
sel := simd.select(c_vecs[j], SCANNER_INDICES_128, SCANNER_SENTINEL_MIN_128)
off := simd.reduce_min(sel)
return i + j * SIMD_REG_SIZE_128 + int(off)
}
}
}
i += 4 * SIMD_REG_SIZE_128
}
}
}
// Scan the remaining SIMD register sized chunks.
//
// Apparently LLVM does ok with 128-bit SWAR, so this path is also taken
// on potato targets. Scanning more at a time when LLVM is emulating SIMD
// likely does not buy much, as all that does is increase GP register
// pressure.
for nr_blocks := (l - i) / SIMD_REG_SIZE_128; nr_blocks > 0; nr_blocks -= 1 {
s0 := intrinsics.unaligned_load(cast(^simd.u8x16)raw_data(s[i:]))
c0 := simd.lanes_eq(s0, c_vec)
if simd.reduce_or(c0) > 0 {
sel := simd.select(c0, SCANNER_INDICES_128, SCANNER_SENTINEL_MIN_128)
off := simd.reduce_min(sel)
return i + int(off)
}
i += SIMD_REG_SIZE_128
}
// Scan serially for the remainder.
for /**/; i < l; i += 1 {
if s[i] == c {
return i
}
}
return -1
}
// Returns -1 if c is not present
last_index_byte :: proc(s: []byte, c: byte) -> int {
for i := len(s)-1; i >= 0; i -= 1 {
/*
Scan a slice of bytes for a specific byte, starting from the end and working
backwards to the start.
This procedure safely handles slices of any length, including empty slices.
Inputs:
- data: A slice of bytes.
- c: The byte to search for.
Returns:
- index: The index of the byte `c`, or -1 if it was not found.
*/
last_index_byte :: proc "contextless" (s: []byte, c: byte) -> int #no_bounds_check {
i := len(s)
// Guard against small strings. On modern systems, it is ALWAYS
// worth vectorizing assuming there is a hardware vector unit, and
// the data size is large enough.
if i < SIMD_REG_SIZE_128 {
#reverse for ch, j in s {
if ch == c {
return j
}
}
return -1
}
c_vec: simd.u8x16 = c
when !simd.IS_EMULATED {
// Note: While this is something that could also logically take
// advantage of AVX512, the various downclocking and power
// consumption related woes make premature to have a dedicated
// code path.
when ODIN_ARCH == .amd64 && intrinsics.has_target_feature("avx2") {
c_vec_256: simd.u8x32 = c
s_vecs: [4]simd.u8x32 = ---
c_vecs: [4]simd.u8x32 = ---
m_vec: [4]u8 = ---
// Scan 128-byte chunks, using 256-bit SIMD.
for i >= 4 * SIMD_REG_SIZE_256 {
i -= 4 * SIMD_REG_SIZE_256
#unroll for j in 0..<4 {
s_vecs[j] = intrinsics.unaligned_load(cast(^simd.u8x32)raw_data(s[i+j*SIMD_REG_SIZE_256:]))
c_vecs[j] = simd.lanes_eq(s_vecs[j], c_vec_256)
m_vec[j] = simd.reduce_or(c_vecs[j])
}
if m_vec[0] | m_vec[1] | m_vec[2] | m_vec[3] > 0 {
#unroll for j in 0..<4 {
if m_vec[3-j] > 0 {
sel := simd.select(c_vecs[3-j], SCANNER_INDICES_256, SCANNER_SENTINEL_MAX_256)
off := simd.reduce_max(sel)
return i + (3-j) * SIMD_REG_SIZE_256 + int(off)
}
}
}
}
// Scan 64-byte chunks, using 256-bit SIMD.
for i >= 2 * SIMD_REG_SIZE_256 {
i -= 2 * SIMD_REG_SIZE_256
#unroll for j in 0..<2 {
s_vecs[j] = intrinsics.unaligned_load(cast(^simd.u8x32)raw_data(s[i+j*SIMD_REG_SIZE_256:]))
c_vecs[j] = simd.lanes_eq(s_vecs[j], c_vec_256)
m_vec[j] = simd.reduce_or(c_vecs[j])
}
if m_vec[0] | m_vec[1] > 0 {
#unroll for j in 0..<2 {
if m_vec[1-j] > 0 {
sel := simd.select(c_vecs[1-j], SCANNER_INDICES_256, SCANNER_SENTINEL_MAX_256)
off := simd.reduce_max(sel)
return i + (1-j) * SIMD_REG_SIZE_256 + int(off)
}
}
}
}
} else {
s_vecs: [4]simd.u8x16 = ---
c_vecs: [4]simd.u8x16 = ---
m_vecs: [4]u8 = ---
// Scan 64-byte chunks, using 128-bit SIMD.
for i >= 4 * SIMD_REG_SIZE_128 {
i -= 4 * SIMD_REG_SIZE_128
#unroll for j in 0..<4 {
s_vecs[j] = intrinsics.unaligned_load(cast(^simd.u8x16)raw_data(s[i+j*SIMD_REG_SIZE_128:]))
c_vecs[j] = simd.lanes_eq(s_vecs[j], c_vec)
m_vecs[j] = simd.reduce_or(c_vecs[j])
}
if m_vecs[0] | m_vecs[1] | m_vecs[2] | m_vecs[3] > 0 {
#unroll for j in 0..<4 {
if m_vecs[3-j] > 0 {
sel := simd.select(c_vecs[3-j], SCANNER_INDICES_128, SCANNER_SENTINEL_MAX_128)
off := simd.reduce_max(sel)
return i + (3-j) * SIMD_REG_SIZE_128 + int(off)
}
}
}
}
}
}
// Scan the remaining SIMD register sized chunks.
//
// Apparently LLVM does ok with 128-bit SWAR, so this path is also taken
// on potato targets. Scanning more at a time when LLVM is emulating SIMD
// likely does not buy much, as all that does is increase GP register
// pressure.
for i >= SIMD_REG_SIZE_128 {
i -= SIMD_REG_SIZE_128
s0 := intrinsics.unaligned_load(cast(^simd.u8x16)raw_data(s[i:]))
c0 := simd.lanes_eq(s0, c_vec)
if simd.reduce_or(c0) > 0 {
sel := simd.select(c0, SCANNER_INDICES_128, SCANNER_SENTINEL_MAX_128)
off := simd.reduce_max(sel)
return i + int(off)
}
}
// Scan serially for the remainder.
for i > 0 {
i -= 1
if s[i] == c {
return i
}
}
return -1
}
@private PRIME_RABIN_KARP :: 16777619
index :: proc(s, substr: []byte) -> int {
@@ -1167,3 +1445,28 @@ fields_proc :: proc(s: []byte, f: proc(rune) -> bool, allocator := context.alloc
return subslices[:]
}
// alias returns true iff a and b have a non-zero length, and any part of
// a overlaps with b.
alias :: proc "contextless" (a, b: []byte) -> bool {
a_len, b_len := len(a), len(b)
if a_len == 0 || b_len == 0 {
return false
}
a_start, b_start := uintptr(raw_data(a)), uintptr(raw_data(b))
a_end, b_end := a_start + uintptr(a_len-1), b_start + uintptr(b_len-1)
return a_start <= b_end && b_start <= a_end
}
// alias_inexactly returns true iff a and b have a non-zero length,
// the base pointer of a and b are NOT equal, and any part of a overlaps
// with b (ie: `alias(a, b)` with an exception that returns false for
// `a == b`, `b = a[:len(a)-69]` and similar conditions).
alias_inexactly :: proc "contextless" (a, b: []byte) -> bool {
if raw_data(a) == raw_data(b) {
return false
}
return alias(a, b)
}
+9 -2
View File
@@ -9,10 +9,11 @@ Reader :: struct {
prev_rune: int, // previous reading index of rune or < 0
}
reader_init :: proc(r: ^Reader, s: []byte) {
reader_init :: proc(r: ^Reader, s: []byte) -> io.Stream {
r.s = s
r.i = 0
r.prev_rune = -1
return reader_to_stream(r)
}
reader_to_stream :: proc(r: ^Reader) -> (s: io.Stream) {
@@ -33,6 +34,9 @@ reader_size :: proc(r: ^Reader) -> i64 {
}
reader_read :: proc(r: ^Reader, p: []byte) -> (n: int, err: io.Error) {
if len(p) == 0 {
return 0, nil
}
if r.i >= i64(len(r.s)) {
return 0, .EOF
}
@@ -42,6 +46,9 @@ reader_read :: proc(r: ^Reader, p: []byte) -> (n: int, err: io.Error) {
return
}
reader_read_at :: proc(r: ^Reader, p: []byte, off: i64) -> (n: int, err: io.Error) {
if len(p) == 0 {
return 0, nil
}
if off < 0 {
return 0, .Invalid_Offset
}
@@ -97,7 +104,6 @@ reader_unread_rune :: proc(r: ^Reader) -> io.Error {
return nil
}
reader_seek :: proc(r: ^Reader, offset: i64, whence: io.Seek_From) -> (i64, io.Error) {
r.prev_rune = -1
abs: i64
switch whence {
case .Start:
@@ -114,6 +120,7 @@ reader_seek :: proc(r: ^Reader, offset: i64, whence: io.Seek_From) -> (i64, io.E
return 0, .Invalid_Offset
}
r.i = abs
r.prev_rune = -1
return abs, nil
}
reader_write_to :: proc(r: ^Reader, w: io.Writer) -> (n: i64, err: io.Error) {
+1 -1
View File
@@ -291,7 +291,7 @@ scan_escape :: proc(t: ^Tokenizer) -> bool {
n -= 1
}
if x > max || 0xd800 <= x && x <= 0xe000 {
if x > max || 0xd800 <= x && x <= 0xdfff {
error_offset(t, offset, "escape sequence is an invalid Unicode code point")
return false
}
+2 -2
View File
@@ -14,7 +14,7 @@ The following is a mostly-complete projection of the C11 standard library as def
| `<inttypes.h>` | Fully projected |
| `<iso646.h>` | Not applicable, use Odin's operators |
| `<limits.h>` | Not projected |
| `<locale.h>` | Not projected |
| `<locale.h>` | Fully projected |
| `<math.h>` | Mostly projected, see [limitations](#Limitations) |
| `<setjmp.h>` | Fully projected |
| `<signal.h>` | Fully projected |
@@ -70,4 +70,4 @@ with the following copyright.
```
Copyright 2021 Dale Weiler <weilercdale@gmail.com>.
```
```
+2 -2
View File
@@ -47,8 +47,8 @@ foreign libc {
clogf :: proc(z: complex_float) -> complex_float ---
// 7.3.8 Power and absolute-value functions
cabs :: proc(z: complex_double) -> complex_double ---
cabsf :: proc(z: complex_float) -> complex_float ---
cabs :: proc(z: complex_double) -> double ---
cabsf :: proc(z: complex_float) -> float ---
cpow :: proc(x, y: complex_double) -> complex_double ---
cpowf :: proc(x, y: complex_float) -> complex_float ---
csqrt :: proc(z: complex_double) -> complex_double ---
+10 -2
View File
@@ -40,7 +40,7 @@ when ODIN_OS == .FreeBSD {
ERANGE :: 34
}
when ODIN_OS == .OpenBSD {
when ODIN_OS == .OpenBSD || ODIN_OS == .NetBSD {
@(private="file")
@(default_calling_convention="c")
foreign libc {
@@ -98,10 +98,18 @@ when ODIN_OS == .Haiku {
ERANGE :: B_POSIX_ERROR_BASE + 17
}
when ODIN_OS == .JS {
_ :: libc
_get_errno :: proc "c" () -> ^int {
@(static) errno: int
return &errno
}
}
// Odin has no way to make an identifier "errno" behave as a function call to
// read the value, or to produce an lvalue such that you can assign a different
// error value to errno. To work around this, just expose it as a function like
// it actually is.
errno :: #force_inline proc() -> ^int {
errno :: #force_inline proc "contextless" () -> ^int {
return _get_errno()
}
+133
View File
@@ -0,0 +1,133 @@
package libc
import "core:c"
when ODIN_OS == .Windows {
foreign import libc "system:libucrt.lib"
} else when ODIN_OS == .Darwin {
foreign import libc "system:System.framework"
} else {
foreign import libc "system:c"
}
// locale.h - category macros
foreign libc {
/*
Sets the components of an object with the type lconv with the values appropriate for the
formatting of numeric quantities (monetary and otherwise) according to the rules of the current
locale.
Returns: a pointer to the lconv structure, might be invalidated by subsequent calls to localeconv() and setlocale()
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/localeconv.html ]]
*/
localeconv :: proc() -> ^lconv ---
/*
Selects the appropriate piece of the global locale, as specified by the category and locale arguments,
and can be used to change or query the entire global locale or portions thereof.
Returns: the current locale if `locale` is `nil`, the set locale otherwise
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/setlocale.html ]]
*/
@(link_name=LSETLOCALE)
setlocale :: proc(category: Locale_Category, locale: cstring) -> cstring ---
}
Locale_Category :: enum c.int {
ALL = LC_ALL,
COLLATE = LC_COLLATE,
CTYPE = LC_CTYPE,
MESSAGES = LC_MESSAGES,
MONETARY = LC_MONETARY,
NUMERIC = LC_NUMERIC,
TIME = LC_TIME,
}
when ODIN_OS == .NetBSD {
@(private) LSETLOCALE :: "__setlocale50"
} else {
@(private) LSETLOCALE :: "setlocale"
}
when ODIN_OS == .Windows {
lconv :: struct {
decimal_point: cstring,
thousand_sep: cstring,
grouping: cstring,
int_curr_symbol: cstring,
currency_symbol: cstring,
mon_decimal_points: cstring,
mon_thousands_sep: cstring,
mon_grouping: cstring,
positive_sign: cstring,
negative_sign: cstring,
int_frac_digits: c.char,
frac_digits: c.char,
p_cs_precedes: c.char,
p_sep_by_space: c.char,
n_cs_precedes: c.char,
n_sep_by_space: c.char,
p_sign_posn: c.char,
n_sign_posn: c.char,
_W_decimal_point: [^]u16 `fmt:"s,0"`,
_W_thousands_sep: [^]u16 `fmt:"s,0"`,
_W_int_curr_symbol: [^]u16 `fmt:"s,0"`,
_W_currency_symbol: [^]u16 `fmt:"s,0"`,
_W_mon_decimal_point: [^]u16 `fmt:"s,0"`,
_W_mon_thousands_sep: [^]u16 `fmt:"s,0"`,
_W_positive_sign: [^]u16 `fmt:"s,0"`,
_W_negative_sign: [^]u16 `fmt:"s,0"`,
}
} else {
lconv :: struct {
decimal_point: cstring,
thousand_sep: cstring,
grouping: cstring,
int_curr_symbol: cstring,
currency_symbol: cstring,
mon_decimal_points: cstring,
mon_thousands_sep: cstring,
mon_grouping: cstring,
positive_sign: cstring,
negative_sign: cstring,
int_frac_digits: c.char,
frac_digits: c.char,
p_cs_precedes: c.char,
p_sep_by_space: c.char,
n_cs_precedes: c.char,
n_sep_by_space: c.char,
p_sign_posn: c.char,
n_sign_posn: c.char,
_int_p_cs_precedes: c.char,
_int_n_cs_precedes: c.char,
_int_p_sep_by_space: c.char,
_int_n_sep_by_space: c.char,
_int_p_sign_posn: c.char,
_int_n_sign_posn: c.char,
}
}
when ODIN_OS == .Darwin || ODIN_OS == .FreeBSD || ODIN_OS == .NetBSD || ODIN_OS == .OpenBSD || ODIN_OS == .Windows {
LC_ALL :: 0
LC_COLLATE :: 1
LC_CTYPE :: 2
LC_MESSAGES :: 6
LC_MONETARY :: 3
LC_NUMERIC :: 4
LC_TIME :: 5
} else when ODIN_OS == .Linux {
LC_CTYPE :: 0
LC_NUMERIC :: 1
LC_TIME :: 2
LC_COLLATE :: 3
LC_MONETARY :: 4
LC_MESSAGES :: 5
LC_ALL :: 6
}
+12 -7
View File
@@ -32,24 +32,21 @@ when ODIN_OS == .Windows {
// the RDX register will contain zero and correctly set the flag to disable
// stack unwinding.
@(link_name="_setjmp")
setjmp :: proc(env: ^jmp_buf, hack: rawptr = nil) -> int ---
setjmp :: proc(env: ^jmp_buf, hack: rawptr = nil) -> int ---
}
} else {
@(default_calling_convention="c")
foreign libc {
// 7.13.1 Save calling environment
//
// NOTE(dweiler): C11 requires setjmp be a macro, which means it won't
// necessarily export a symbol named setjmp but rather _setjmp in the case
// of musl, glibc, BSD libc, and msvcrt.
@(link_name="_setjmp")
setjmp :: proc(env: ^jmp_buf) -> int ---
@(link_name=LSETJMP)
setjmp :: proc(env: ^jmp_buf) -> int ---
}
}
@(default_calling_convention="c")
foreign libc {
// 7.13.2 Restore calling environment
@(link_name=LLONGJMP)
longjmp :: proc(env: ^jmp_buf, val: int) -> ! ---
}
@@ -64,3 +61,11 @@ foreign libc {
// The choice of 4096 bytes for storage of this type is more than enough on all
// relevant platforms.
jmp_buf :: struct #align(16) { _: [4096]char, }
when ODIN_OS == .NetBSD {
@(private) LSETJMP :: "__setjmp14"
@(private) LLONGJMP :: "__longjmp14"
} else {
@(private) LSETJMP :: "setjmp"
@(private) LLONGJMP :: "longjmp"
}
+1 -14
View File
@@ -34,20 +34,7 @@ when ODIN_OS == .Windows {
SIGTERM :: 15
}
when ODIN_OS == .Linux || ODIN_OS == .FreeBSD {
SIG_ERR :: rawptr(~uintptr(0))
SIG_DFL :: rawptr(uintptr(0))
SIG_IGN :: rawptr(uintptr(1))
SIGABRT :: 6
SIGFPE :: 8
SIGILL :: 4
SIGINT :: 2
SIGSEGV :: 11
SIGTERM :: 15
}
when ODIN_OS == .Darwin {
when ODIN_OS == .Linux || ODIN_OS == .FreeBSD || ODIN_OS == .Haiku || ODIN_OS == .OpenBSD || ODIN_OS == .NetBSD || ODIN_OS == .Darwin {
SIG_ERR :: rawptr(~uintptr(0))
SIG_DFL :: rawptr(uintptr(0))
SIG_IGN :: rawptr(uintptr(1))
+1 -1
View File
@@ -235,7 +235,7 @@ atomic_compare_exchange_weak :: #force_inline proc(object, expected: ^$T, desire
return ok
}
atomic_compare_exchange_weak_explicit :: #force_inline proc(object, expected: ^$T, desited: T, success, failure: memory_order) -> bool {
atomic_compare_exchange_weak_explicit :: #force_inline proc(object, expected: ^$T, desired: T, success, failure: memory_order) -> bool {
assert(failure != .release)
assert(failure != .acq_rel)
+69 -16
View File
@@ -17,6 +17,12 @@ when ODIN_OS == .Windows {
FILE :: struct {}
Whence :: enum int {
SET = SEEK_SET,
CUR = SEEK_CUR,
END = SEEK_END,
}
// MSVCRT compatible.
when ODIN_OS == .Windows {
_IOFBF :: 0x0000
@@ -83,7 +89,31 @@ when ODIN_OS == .Linux {
}
}
when ODIN_OS == .OpenBSD {
when ODIN_OS == .JS {
fpos_t :: struct #raw_union { _: [16]char, _: longlong, _: double, }
_IOFBF :: 0
_IOLBF :: 1
_IONBF :: 2
BUFSIZ :: 1024
EOF :: int(-1)
FOPEN_MAX :: 1000
FILENAME_MAX :: 4096
L_tmpnam :: 20
SEEK_SET :: 0
SEEK_CUR :: 1
SEEK_END :: 2
TMP_MAX :: 308915776
}
when ODIN_OS == .OpenBSD || ODIN_OS == .NetBSD {
fpos_t :: distinct i64
_IOFBF :: 0
@@ -101,11 +131,15 @@ when ODIN_OS == .OpenBSD {
SEEK_CUR :: 1
SEEK_END :: 2
TMP_MAX :: 308915776
foreign libc {
stderr: ^FILE
stdin: ^FILE
stdout: ^FILE
__sF: [3]FILE
}
stdin: ^FILE = &__sF[0]
stdout: ^FILE = &__sF[1]
stderr: ^FILE = &__sF[2]
}
when ODIN_OS == .FreeBSD {
@@ -126,10 +160,12 @@ when ODIN_OS == .FreeBSD {
SEEK_CUR :: 1
SEEK_END :: 2
TMP_MAX :: 308915776
foreign libc {
stderr: ^FILE
stdin: ^FILE
stdout: ^FILE
@(link_name="__stderrp") stderr: ^FILE
@(link_name="__stdinp") stdin: ^FILE
@(link_name="__stdoutp") stdout: ^FILE
}
}
@@ -193,10 +229,21 @@ when ODIN_OS == .Haiku {
}
}
when ODIN_OS == .NetBSD {
@(private) LRENAME :: "__posix_rename"
@(private) LFGETPOS :: "__fgetpos50"
@(private) LFSETPOS :: "__fsetpos50"
} else {
@(private) LRENAME :: "rename"
@(private) LFGETPOS :: "fgetpos"
@(private) LFSETPOS :: "fsetpos"
}
@(default_calling_convention="c")
foreign libc {
// 7.21.4 Operations on files
remove :: proc(filename: cstring) -> int ---
@(link_name=LRENAME)
rename :: proc(old, new: cstring) -> int ---
tmpfile :: proc() -> ^FILE ---
tmpnam :: proc(s: [^]char) -> [^]char ---
@@ -238,8 +285,10 @@ foreign libc {
fwrite :: proc(ptr: rawptr, size: size_t, nmemb: size_t, stream: ^FILE) -> size_t ---
// 7.21.9 File positioning functions
@(link_name=LFGETPOS)
fgetpos :: proc(stream: ^FILE, pos: ^fpos_t) -> int ---
fseek :: proc(stream: ^FILE, offset: long, whence: int) -> int ---
fseek :: proc(stream: ^FILE, offset: long, whence: Whence) -> int ---
@(link_name=LFSETPOS)
fsetpos :: proc(stream: ^FILE, pos: ^fpos_t) -> int ---
ftell :: proc(stream: ^FILE) -> long ---
rewind :: proc(stream: ^FILE) ---
@@ -286,11 +335,11 @@ to_stream :: proc(file: ^FILE) -> io.Stream {
return 0, unknown_or_eof(file)
}
if fseek(file, long(offset), SEEK_SET) != 0 {
if fseek(file, long(offset), .SET) != 0 {
return 0, unknown_or_eof(file)
}
defer fseek(file, long(curr), SEEK_SET)
defer fseek(file, long(curr), .SET)
n = i64(fread(raw_data(p), size_of(byte), len(p), file))
if n == 0 { err = unknown_or_eof(file) }
@@ -305,17 +354,21 @@ to_stream :: proc(file: ^FILE) -> io.Stream {
return 0, unknown_or_eof(file)
}
if fseek(file, long(offset), SEEK_SET) != 0 {
if fseek(file, long(offset), .SET) != 0 {
return 0, unknown_or_eof(file)
}
defer fseek(file, long(curr), SEEK_SET)
defer fseek(file, long(curr), .SET)
n = i64(fwrite(raw_data(p), size_of(byte), len(p), file))
if n == 0 { err = unknown_or_eof(file) }
case .Seek:
if fseek(file, long(offset), int(whence)) != 0 {
#assert(int(Whence.SET) == int(io.Seek_From.Start))
#assert(int(Whence.CUR) == int(io.Seek_From.Current))
#assert(int(Whence.END) == int(io.Seek_From.End))
if fseek(file, long(offset), Whence(whence)) != 0 {
return 0, unknown_or_eof(file)
}
@@ -324,9 +377,9 @@ to_stream :: proc(file: ^FILE) -> io.Stream {
if curr == -1 {
return 0, unknown_or_eof(file)
}
defer fseek(file, curr, SEEK_SET)
defer fseek(file, curr, .SET)
if fseek(file, 0, SEEK_END) != 0 {
if fseek(file, 0, .END) != 0 {
return 0, unknown_or_eof(file)
}
@@ -339,7 +392,7 @@ to_stream :: proc(file: ^FILE) -> io.Stream {
return 0, .Empty
case .Query:
return io.query_utility({ .Close, .Flush, .Read, .Read_At, .Write, .Write_At, .Seek, .Size })
return io.query_utility({ .Close, .Flush, .Read, .Read_At, .Write, .Write_At, .Seek, .Size, .Query })
}
return
}
+27 -4
View File
@@ -10,6 +10,9 @@ when ODIN_OS == .Windows {
foreign import libc "system:c"
}
@(require)
import "base:runtime"
when ODIN_OS == .Windows {
RAND_MAX :: 0x7fff
@@ -40,10 +43,9 @@ when ODIN_OS == .Linux {
}
when ODIN_OS == .Darwin {
when ODIN_OS == .Darwin || ODIN_OS == .FreeBSD || ODIN_OS == .OpenBSD {
RAND_MAX :: 0x7fffffff
// GLIBC and MUSL only
@(private="file")
@(default_calling_convention="c")
foreign libc {
@@ -55,6 +57,20 @@ when ODIN_OS == .Darwin {
}
}
when ODIN_OS == .NetBSD {
RAND_MAX :: 0x7fffffff
@(private="file")
@(default_calling_convention="c")
foreign libc {
__mb_cur_max: size_t
}
MB_CUR_MAX :: #force_inline proc() -> size_t {
return __mb_cur_max
}
}
// C does not declare what these values should be, as an implementation is free
// to use any two distinct values it wants to indicate success or failure.
// However, nobody actually does and everyone appears to have agreed upon these
@@ -99,7 +115,7 @@ foreign libc {
at_quick_exit :: proc(func: proc "c" ()) -> int ---
exit :: proc(status: int) -> ! ---
_Exit :: proc(status: int) -> ! ---
getenv :: proc(name: cstring) -> [^]char ---
getenv :: proc(name: cstring) -> cstring ---
quick_exit :: proc(status: int) -> ! ---
system :: proc(cmd: cstring) -> int ---
@@ -132,6 +148,10 @@ aligned_alloc :: #force_inline proc "c" (alignment, size: size_t) -> rawptr {
_aligned_malloc :: proc(size, alignment: size_t) -> rawptr ---
}
return _aligned_malloc(size=size, alignment=alignment)
} else when ODIN_ARCH == .wasm32 || ODIN_ARCH == .wasm64p32 {
context = runtime.default_context()
data, _ := runtime.mem_alloc_bytes(auto_cast size, auto_cast alignment)
return raw_data(data)
} else {
foreign libc {
aligned_alloc :: proc(alignment, size: size_t) -> rawptr ---
@@ -147,7 +167,10 @@ aligned_free :: #force_inline proc "c" (ptr: rawptr) {
_aligned_free :: proc(ptr: rawptr) ---
}
_aligned_free(ptr)
} else when ODIN_ARCH == .wasm32 || ODIN_ARCH == .wasm64p32 {
context = runtime.default_context()
runtime.mem_free(ptr)
} else {
free(ptr)
}
}
}
+2 -1
View File
@@ -12,6 +12,7 @@ when ODIN_OS == .Windows {
foreign import libc "system:c"
}
@(default_calling_convention="c")
foreign libc {
// 7.24.2 Copying functions
memcpy :: proc(s1, s2: rawptr, n: size_t) -> rawptr ---
@@ -40,7 +41,7 @@ foreign libc {
strtok :: proc(s1: [^]char, s2: cstring) -> [^]char ---
// 7.24.6 Miscellaneous functions
strerror :: proc(errnum: int) -> [^]char ---
strerror :: proc(errnum: int) -> cstring ---
strlen :: proc(s: cstring) -> size_t ---
}
memset :: proc "c" (s: rawptr, c: int, n: size_t) -> rawptr {
+30 -4
View File
@@ -45,35 +45,61 @@ when ODIN_OS == .Windows {
}
}
when ODIN_OS == .Linux || ODIN_OS == .FreeBSD || ODIN_OS == .Darwin || ODIN_OS == .OpenBSD || ODIN_OS == .Haiku {
when ODIN_OS == .Linux || ODIN_OS == .FreeBSD || ODIN_OS == .Darwin || ODIN_OS == .OpenBSD || ODIN_OS == .NetBSD || ODIN_OS == .Haiku || ODIN_OS == .JS {
@(default_calling_convention="c")
foreign libc {
// 7.27.2 Time manipulation functions
clock :: proc() -> clock_t ---
@(link_name=LDIFFTIME)
difftime :: proc(time1, time2: time_t) -> double ---
@(link_name=LMKTIME)
mktime :: proc(timeptr: ^tm) -> time_t ---
@(link_name=LTIME)
time :: proc(timer: ^time_t) -> time_t ---
timespec_get :: proc(ts: ^timespec, base: int) -> int ---
// 7.27.3 Time conversion functions
asctime :: proc(timeptr: ^tm) -> [^]char ---
@(link_name=LCTIME)
ctime :: proc(timer: ^time_t) -> [^]char ---
@(link_name=LGMTIME)
gmtime :: proc(timer: ^time_t) -> ^tm ---
@(link_name=LLOCALTIME)
localtime :: proc(timer: ^time_t) -> ^tm ---
strftime :: proc(s: [^]char, maxsize: size_t, format: cstring, timeptr: ^tm) -> size_t ---
}
when ODIN_OS == .NetBSD {
@(private) LDIFFTIME :: "__difftime50"
@(private) LMKTIME :: "__mktime50"
@(private) LTIME :: "__time50"
@(private) LCTIME :: "__ctime50"
@(private) LGMTIME :: "__gmtime50"
@(private) LLOCALTIME :: "__localtime50"
} else {
@(private) LDIFFTIME :: "difftime"
@(private) LMKTIME :: "mktime"
@(private) LTIME :: "time"
@(private) LCTIME :: "ctime"
@(private) LGMTIME :: "gmtime"
@(private) LLOCALTIME :: "localtime"
}
when ODIN_OS == .OpenBSD {
CLOCKS_PER_SEC :: 100
} else {
CLOCKS_PER_SEC :: 1000000
}
TIME_UTC :: 1
TIME_UTC :: 1
time_t :: distinct i64
time_t :: distinct i64
clock_t :: long
when ODIN_OS == .FreeBSD || ODIN_OS == .NetBSD {
clock_t :: distinct int32_t
} else {
clock_t :: distinct long
}
timespec :: struct {
tv_sec: time_t,
+2 -2
View File
@@ -14,7 +14,7 @@ when ODIN_OS == .Windows {
wctrans_t :: distinct wchar_t
wctype_t :: distinct ushort
} else when ODIN_OS == .Linux {
} else when ODIN_OS == .Linux || ODIN_OS == .JS {
wctrans_t :: distinct intptr_t
wctype_t :: distinct ulong
@@ -22,7 +22,7 @@ when ODIN_OS == .Windows {
wctrans_t :: distinct int
wctype_t :: distinct u32
} else when ODIN_OS == .OpenBSD {
} else when ODIN_OS == .OpenBSD || ODIN_OS == .NetBSD {
wctrans_t :: distinct rawptr
wctype_t :: distinct rawptr
+28 -28
View File
@@ -34,13 +34,13 @@ COMPRESS_OUTPUT_ALLOCATE_MIN :: int(#config(COMPRESS_OUTPUT_ALLOCATE_MIN, 1 << 2
*/
when size_of(uintptr) == 8 {
// For 64-bit platforms, we set the default max buffer size to 4 GiB,
// which is GZIP and PKZIP's max payload size.
// For 64-bit platforms, we set the default max buffer size to 4 GiB,
// which is GZIP and PKZIP's max payload size.
COMPRESS_OUTPUT_ALLOCATE_MAX :: int(#config(COMPRESS_OUTPUT_ALLOCATE_MAX, 1 << 32))
} else {
// For 32-bit platforms, we set the default max buffer size to 512 MiB.
COMPRESS_OUTPUT_ALLOCATE_MAX :: int(#config(COMPRESS_OUTPUT_ALLOCATE_MAX, 1 << 29))
COMPRESS_OUTPUT_ALLOCATE_MAX :: int(#config(COMPRESS_OUTPUT_ALLOCATE_MAX, 1 << 29))
}
@@ -186,7 +186,7 @@ input_size_from_stream :: proc(z: ^Context_Stream_Input) -> (res: i64, err: Erro
input_size :: proc{input_size_from_memory, input_size_from_stream}
@(optimization_mode="speed")
@(optimization_mode="favor_size")
read_slice_from_memory :: #force_inline proc(z: ^Context_Memory_Input, size: int) -> (res: []u8, err: io.Error) {
#no_bounds_check {
if len(z.input_data) >= size {
@@ -203,7 +203,7 @@ read_slice_from_memory :: #force_inline proc(z: ^Context_Memory_Input, size: int
}
}
@(optimization_mode="speed")
@(optimization_mode="favor_size")
read_slice_from_stream :: #force_inline proc(z: ^Context_Stream_Input, size: int) -> (res: []u8, err: io.Error) {
// TODO: REMOVE ALL USE OF context.temp_allocator here
// there is literally no need for it
@@ -214,13 +214,13 @@ read_slice_from_stream :: #force_inline proc(z: ^Context_Stream_Input, size: int
read_slice :: proc{read_slice_from_memory, read_slice_from_stream}
@(optimization_mode="speed")
@(optimization_mode="favor_size")
read_data :: #force_inline proc(z: ^$C, $T: typeid) -> (res: T, err: io.Error) {
b := read_slice(z, size_of(T)) or_return
return (^T)(&b[0])^, nil
}
@(optimization_mode="speed")
@(optimization_mode="favor_size")
read_u8_from_memory :: #force_inline proc(z: ^Context_Memory_Input) -> (res: u8, err: io.Error) {
#no_bounds_check {
if len(z.input_data) >= 1 {
@@ -232,7 +232,7 @@ read_u8_from_memory :: #force_inline proc(z: ^Context_Memory_Input) -> (res: u8,
return 0, .EOF
}
@(optimization_mode="speed")
@(optimization_mode="favor_size")
read_u8_from_stream :: #force_inline proc(z: ^Context_Stream_Input) -> (res: u8, err: io.Error) {
b := read_slice_from_stream(z, 1) or_return
return b[0], nil
@@ -242,7 +242,7 @@ read_u8 :: proc{read_u8_from_memory, read_u8_from_stream}
// You would typically only use this at the end of Inflate, to drain bits from the code buffer
// preferentially.
@(optimization_mode="speed")
@(optimization_mode="favor_size")
read_u8_prefer_code_buffer_lsb :: #force_inline proc(z: ^$C) -> (res: u8, err: io.Error) {
if z.num_bits >= 8 {
res = u8(read_bits_no_refill_lsb(z, 8))
@@ -257,7 +257,7 @@ read_u8_prefer_code_buffer_lsb :: #force_inline proc(z: ^$C) -> (res: u8, err: i
return
}
@(optimization_mode="speed")
@(optimization_mode="favor_size")
peek_data_from_memory :: #force_inline proc(z: ^Context_Memory_Input, $T: typeid) -> (res: T, err: io.Error) {
size :: size_of(T)
@@ -275,7 +275,7 @@ peek_data_from_memory :: #force_inline proc(z: ^Context_Memory_Input, $T: typeid
}
}
@(optimization_mode="speed")
@(optimization_mode="favor_size")
peek_data_at_offset_from_memory :: #force_inline proc(z: ^Context_Memory_Input, $T: typeid, #any_int offset: int) -> (res: T, err: io.Error) {
size :: size_of(T)
@@ -293,7 +293,7 @@ peek_data_at_offset_from_memory :: #force_inline proc(z: ^Context_Memory_Input,
}
}
@(optimization_mode="speed")
@(optimization_mode="favor_size")
peek_data_from_stream :: #force_inline proc(z: ^Context_Stream_Input, $T: typeid) -> (res: T, err: io.Error) {
size :: size_of(T)
@@ -317,7 +317,7 @@ peek_data_from_stream :: #force_inline proc(z: ^Context_Stream_Input, $T: typeid
return res, .None
}
@(optimization_mode="speed")
@(optimization_mode="favor_size")
peek_data_at_offset_from_stream :: #force_inline proc(z: ^Context_Stream_Input, $T: typeid, #any_int offset: int) -> (res: T, err: io.Error) {
size :: size_of(T)
@@ -352,14 +352,14 @@ peek_data :: proc{peek_data_from_memory, peek_data_from_stream, peek_data_at_off
// Sliding window read back
@(optimization_mode="speed")
@(optimization_mode="favor_size")
peek_back_byte :: #force_inline proc(z: ^$C, offset: i64) -> (res: u8, err: io.Error) {
// Look back into the sliding window.
return z.output.buf[z.bytes_written - offset], .None
}
// Generalized bit reader LSB
@(optimization_mode="speed")
@(optimization_mode="favor_size")
refill_lsb_from_memory :: #force_inline proc(z: ^Context_Memory_Input, width := i8(48)) {
refill := u64(width)
b := u64(0)
@@ -385,7 +385,7 @@ refill_lsb_from_memory :: #force_inline proc(z: ^Context_Memory_Input, width :=
}
// Generalized bit reader LSB
@(optimization_mode="speed")
@(optimization_mode="favor_size")
refill_lsb_from_stream :: proc(z: ^Context_Stream_Input, width := i8(24)) {
refill := u64(width)
@@ -414,13 +414,13 @@ refill_lsb_from_stream :: proc(z: ^Context_Stream_Input, width := i8(24)) {
refill_lsb :: proc{refill_lsb_from_memory, refill_lsb_from_stream}
@(optimization_mode="speed")
@(optimization_mode="favor_size")
consume_bits_lsb_from_memory :: #force_inline proc(z: ^Context_Memory_Input, width: u8) {
z.code_buffer >>= width
z.num_bits -= u64(width)
}
@(optimization_mode="speed")
@(optimization_mode="favor_size")
consume_bits_lsb_from_stream :: #force_inline proc(z: ^Context_Stream_Input, width: u8) {
z.code_buffer >>= width
z.num_bits -= u64(width)
@@ -428,7 +428,7 @@ consume_bits_lsb_from_stream :: #force_inline proc(z: ^Context_Stream_Input, wid
consume_bits_lsb :: proc{consume_bits_lsb_from_memory, consume_bits_lsb_from_stream}
@(optimization_mode="speed")
@(optimization_mode="favor_size")
peek_bits_lsb_from_memory :: #force_inline proc(z: ^Context_Memory_Input, width: u8) -> u32 {
if z.num_bits < u64(width) {
refill_lsb(z)
@@ -436,7 +436,7 @@ peek_bits_lsb_from_memory :: #force_inline proc(z: ^Context_Memory_Input, width:
return u32(z.code_buffer &~ (~u64(0) << width))
}
@(optimization_mode="speed")
@(optimization_mode="favor_size")
peek_bits_lsb_from_stream :: #force_inline proc(z: ^Context_Stream_Input, width: u8) -> u32 {
if z.num_bits < u64(width) {
refill_lsb(z)
@@ -446,13 +446,13 @@ peek_bits_lsb_from_stream :: #force_inline proc(z: ^Context_Stream_Input, width:
peek_bits_lsb :: proc{peek_bits_lsb_from_memory, peek_bits_lsb_from_stream}
@(optimization_mode="speed")
@(optimization_mode="favor_size")
peek_bits_no_refill_lsb_from_memory :: #force_inline proc(z: ^Context_Memory_Input, width: u8) -> u32 {
assert(z.num_bits >= u64(width))
return u32(z.code_buffer &~ (~u64(0) << width))
}
@(optimization_mode="speed")
@(optimization_mode="favor_size")
peek_bits_no_refill_lsb_from_stream :: #force_inline proc(z: ^Context_Stream_Input, width: u8) -> u32 {
assert(z.num_bits >= u64(width))
return u32(z.code_buffer &~ (~u64(0) << width))
@@ -460,14 +460,14 @@ peek_bits_no_refill_lsb_from_stream :: #force_inline proc(z: ^Context_Stream_Inp
peek_bits_no_refill_lsb :: proc{peek_bits_no_refill_lsb_from_memory, peek_bits_no_refill_lsb_from_stream}
@(optimization_mode="speed")
@(optimization_mode="favor_size")
read_bits_lsb_from_memory :: #force_inline proc(z: ^Context_Memory_Input, width: u8) -> u32 {
k := #force_inline peek_bits_lsb(z, width)
#force_inline consume_bits_lsb(z, width)
return k
}
@(optimization_mode="speed")
@(optimization_mode="favor_size")
read_bits_lsb_from_stream :: #force_inline proc(z: ^Context_Stream_Input, width: u8) -> u32 {
k := peek_bits_lsb(z, width)
consume_bits_lsb(z, width)
@@ -476,14 +476,14 @@ read_bits_lsb_from_stream :: #force_inline proc(z: ^Context_Stream_Input, width:
read_bits_lsb :: proc{read_bits_lsb_from_memory, read_bits_lsb_from_stream}
@(optimization_mode="speed")
@(optimization_mode="favor_size")
read_bits_no_refill_lsb_from_memory :: #force_inline proc(z: ^Context_Memory_Input, width: u8) -> u32 {
k := #force_inline peek_bits_no_refill_lsb(z, width)
#force_inline consume_bits_lsb(z, width)
return k
}
@(optimization_mode="speed")
@(optimization_mode="favor_size")
read_bits_no_refill_lsb_from_stream :: #force_inline proc(z: ^Context_Stream_Input, width: u8) -> u32 {
k := peek_bits_no_refill_lsb(z, width)
consume_bits_lsb(z, width)
@@ -493,14 +493,14 @@ read_bits_no_refill_lsb_from_stream :: #force_inline proc(z: ^Context_Stream_Inp
read_bits_no_refill_lsb :: proc{read_bits_no_refill_lsb_from_memory, read_bits_no_refill_lsb_from_stream}
@(optimization_mode="speed")
@(optimization_mode="favor_size")
discard_to_next_byte_lsb_from_memory :: proc(z: ^Context_Memory_Input) {
discard := u8(z.num_bits & 7)
#force_inline consume_bits_lsb(z, discard)
}
@(optimization_mode="speed")
@(optimization_mode="favor_size")
discard_to_next_byte_lsb_from_stream :: proc(z: ^Context_Stream_Input) {
discard := u8(z.num_bits & 7)
consume_bits_lsb(z, discard)
+90
View File
@@ -0,0 +1,90 @@
/*
Copyright 2021 Jeroen van Rijn <nom@duclavier.com>.
Made available under Odin's BSD-3 license.
List of contributors:
Jeroen van Rijn: Initial implementation.
Ginger Bill: Cosmetic changes.
A small GZIP implementation as an example.
*/
/*
Example:
import "core:bytes"
import "core:os"
import "core:compress"
import "core:fmt"
// Small GZIP file with fextra, fname and fcomment present.
@private
TEST: []u8 = {
0x1f, 0x8b, 0x08, 0x1c, 0xcb, 0x3b, 0x3a, 0x5a,
0x02, 0x03, 0x07, 0x00, 0x61, 0x62, 0x03, 0x00,
0x63, 0x64, 0x65, 0x66, 0x69, 0x6c, 0x65, 0x6e,
0x61, 0x6d, 0x65, 0x00, 0x54, 0x68, 0x69, 0x73,
0x20, 0x69, 0x73, 0x20, 0x61, 0x20, 0x63, 0x6f,
0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x00, 0x2b, 0x48,
0xac, 0xcc, 0xc9, 0x4f, 0x4c, 0x01, 0x00, 0x15,
0x6a, 0x2c, 0x42, 0x07, 0x00, 0x00, 0x00,
}
main :: proc() {
// Set up output buffer.
buf := bytes.Buffer{}
stdout :: proc(s: string) {
os.write_string(os.stdout, s)
}
stderr :: proc(s: string) {
os.write_string(os.stderr, s)
}
args := os.args
if len(args) < 2 {
stderr("No input file specified.\n")
err := load(data=TEST, buf=&buf, known_gzip_size=len(TEST))
if err == nil {
stdout("Displaying test vector: ")
stdout(bytes.buffer_to_string(&buf))
stdout("\n")
} else {
fmt.printf("gzip.load returned %v\n", err)
}
bytes.buffer_destroy(&buf)
os.exit(0)
}
// The rest are all files.
args = args[1:]
err: Error
for file in args {
if file == "-" {
// Read from stdin
s := os.stream_from_handle(os.stdin)
ctx := &compress.Context_Stream_Input{
input = s,
}
err = load(ctx, &buf)
} else {
err = load(file, &buf)
}
if err != nil {
if err != E_General.File_Not_Found {
stderr("File not found: ")
stderr(file)
stderr("\n")
os.exit(1)
}
stderr("GZIP returned an error.\n")
bytes.buffer_destroy(&buf)
os.exit(2)
}
stdout(bytes.buffer_to_string(&buf))
}
bytes.buffer_destroy(&buf)
}
*/
package compress_gzip
-89
View File
@@ -1,89 +0,0 @@
//+build ignore
package compress_gzip
/*
Copyright 2021 Jeroen van Rijn <nom@duclavier.com>.
Made available under Odin's BSD-3 license.
List of contributors:
Jeroen van Rijn: Initial implementation.
Ginger Bill: Cosmetic changes.
A small GZIP implementation as an example.
*/
import "core:bytes"
import "core:os"
import "core:compress"
import "core:fmt"
// Small GZIP file with fextra, fname and fcomment present.
@private
TEST: []u8 = {
0x1f, 0x8b, 0x08, 0x1c, 0xcb, 0x3b, 0x3a, 0x5a,
0x02, 0x03, 0x07, 0x00, 0x61, 0x62, 0x03, 0x00,
0x63, 0x64, 0x65, 0x66, 0x69, 0x6c, 0x65, 0x6e,
0x61, 0x6d, 0x65, 0x00, 0x54, 0x68, 0x69, 0x73,
0x20, 0x69, 0x73, 0x20, 0x61, 0x20, 0x63, 0x6f,
0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x00, 0x2b, 0x48,
0xac, 0xcc, 0xc9, 0x4f, 0x4c, 0x01, 0x00, 0x15,
0x6a, 0x2c, 0x42, 0x07, 0x00, 0x00, 0x00,
}
main :: proc() {
// Set up output buffer.
buf := bytes.Buffer{}
stdout :: proc(s: string) {
os.write_string(os.stdout, s)
}
stderr :: proc(s: string) {
os.write_string(os.stderr, s)
}
args := os.args
if len(args) < 2 {
stderr("No input file specified.\n")
err := load(data=TEST, buf=&buf, known_gzip_size=len(TEST))
if err == nil {
stdout("Displaying test vector: ")
stdout(bytes.buffer_to_string(&buf))
stdout("\n")
} else {
fmt.printf("gzip.load returned %v\n", err)
}
bytes.buffer_destroy(&buf)
os.exit(0)
}
// The rest are all files.
args = args[1:]
err: Error
for file in args {
if file == "-" {
// Read from stdin
s := os.stream_from_handle(os.stdin)
ctx := &compress.Context_Stream_Input{
input = s,
}
err = load(ctx, &buf)
} else {
err = load(file, &buf)
}
if err != nil {
if err != E_General.File_Not_Found {
stderr("File not found: ")
stderr(file)
stderr("\n")
os.exit(1)
}
stderr("GZIP returned an error.\n")
bytes.buffer_destroy(&buf)
os.exit(2)
}
stdout(bytes.buffer_to_string(&buf))
}
bytes.buffer_destroy(&buf)
}
+1 -2
View File
@@ -4,7 +4,6 @@
which is an English word model.
*/
// package shoco is an implementation of the shoco short string compressor
package compress_shoco
DEFAULT_MODEL :: Shoco_Model {
@@ -145,4 +144,4 @@ DEFAULT_MODEL :: Shoco_Model {
{ 0xc0000000, 2, 4, { 25, 22, 19, 16, 16, 16, 16, 16 }, { 15, 7, 7, 7, 0, 0, 0, 0 }, 0xe0, 0xc0 },
{ 0xe0000000, 4, 8, { 23, 19, 15, 11, 8, 5, 2, 0 }, { 31, 15, 15, 15, 7, 7, 7, 3 }, 0xf0, 0xe0 },
},
}
}
+6 -9
View File
@@ -8,7 +8,7 @@
An implementation of [shoco](https://github.com/Ed-von-Schleck/shoco) by Christian Schramm.
*/
// package shoco is an implementation of the shoco short string compressor
// package shoco is an implementation of the shoco short string compressor.
package compress_shoco
import "base:intrinsics"
@@ -98,7 +98,7 @@ decompress_slice_to_output_buffer :: proc(input: []u8, output: []u8, model := DE
validate_model(model) or_return
for inp < inp_end {
val := transmute(i8)input[inp]
val := i8(input[inp])
mark := int(-1)
for val < 0 {
@@ -274,12 +274,9 @@ compress_string_to_buffer :: proc(input: string, output: []u8, model := DEFAULT_
out_ptr := raw_data(output[out:])
switch pack.bytes_packed {
case 4:
intrinsics.unaligned_store(transmute(^u32)out_ptr, code)
case 2:
intrinsics.unaligned_store(transmute(^u16)out_ptr, u16(code))
case 1:
intrinsics.unaligned_store(transmute(^u8)out_ptr, u8(code))
case 4: intrinsics.unaligned_store((^u32)(out_ptr), code)
case 2: intrinsics.unaligned_store((^u16)(out_ptr), u16(code))
case 1: intrinsics.unaligned_store( (^u8)(out_ptr), u8(code))
case:
return out, .Unknown_Compression_Method
}
@@ -311,4 +308,4 @@ compress_string :: proc(input: string, model := DEFAULT_MODEL, allocator := cont
resize(&buf, length) or_return
return buf[:length], result
}
compress :: proc{compress_string_to_buffer, compress_string}
compress :: proc{compress_string_to_buffer, compress_string}
+50
View File
@@ -0,0 +1,50 @@
/*
Copyright 2021 Jeroen van Rijn <nom@duclavier.com>.
Made available under Odin's BSD-3 license.
List of contributors:
Jeroen van Rijn: Initial implementation.
An example of how to use `zlib.inflate`.
*/
/*
Example:
package main
import "core:bytes"
import "core:fmt"
main :: proc() {
ODIN_DEMO := []u8{
120, 218, 101, 144, 65, 110, 131, 48, 16, 69, 215, 246, 41, 190, 44, 69, 73, 32, 148, 182,
75, 75, 28, 32, 251, 46, 217, 88, 238, 0, 86, 192, 32, 219, 36, 170, 170, 172, 122, 137,
238, 122, 197, 30, 161, 70, 162, 20, 81, 203, 139, 25, 191, 255, 191, 60, 51, 40, 125, 81,
53, 33, 144, 15, 156, 155, 110, 232, 93, 128, 208, 189, 35, 89, 117, 65, 112, 222, 41, 99,
33, 37, 6, 215, 235, 195, 17, 239, 156, 197, 170, 118, 170, 131, 44, 32, 82, 164, 72, 240,
253, 245, 249, 129, 12, 185, 224, 76, 105, 61, 118, 99, 171, 66, 239, 38, 193, 35, 103, 85,
172, 66, 127, 33, 139, 24, 244, 235, 141, 49, 204, 223, 76, 208, 205, 204, 166, 7, 173, 60,
97, 159, 238, 37, 214, 41, 105, 129, 167, 5, 102, 27, 152, 173, 97, 178, 129, 73, 129, 231,
5, 230, 27, 152, 175, 225, 52, 192, 127, 243, 170, 157, 149, 18, 121, 142, 115, 109, 227, 122,
64, 87, 114, 111, 161, 49, 182, 6, 181, 158, 162, 226, 206, 167, 27, 215, 246, 48, 56, 99,
67, 117, 16, 47, 13, 45, 35, 151, 98, 231, 75, 1, 173, 90, 61, 101, 146, 71, 136, 244,
170, 218, 145, 176, 123, 45, 173, 56, 113, 134, 191, 51, 219, 78, 235, 95, 28, 249, 253, 7,
159, 150, 133, 125,
}
OUTPUT_SIZE :: 432
buf: bytes.Buffer
// We can pass ", true" to inflate a raw DEFLATE stream instead of a ZLIB wrapped one.
err := inflate(input=ODIN_DEMO, buf=&buf, expected_output_size=OUTPUT_SIZE)
defer bytes.buffer_destroy(&buf)
if err != nil {
fmt.printf("\nError: %v\n", err)
}
s := bytes.buffer_to_string(&buf)
fmt.printf("Input: %v bytes, output (%v bytes):\n%v\n", len(ODIN_DEMO), len(s), s)
assert(len(s) == OUTPUT_SIZE)
}
*/
package compress_zlib
-47
View File
@@ -1,47 +0,0 @@
//+build ignore
package compress_zlib
/*
Copyright 2021 Jeroen van Rijn <nom@duclavier.com>.
Made available under Odin's BSD-3 license.
List of contributors:
Jeroen van Rijn: Initial implementation.
An example of how to use `zlib.inflate`.
*/
import "core:bytes"
import "core:fmt"
main :: proc() {
ODIN_DEMO := []u8{
120, 218, 101, 144, 65, 110, 131, 48, 16, 69, 215, 246, 41, 190, 44, 69, 73, 32, 148, 182,
75, 75, 28, 32, 251, 46, 217, 88, 238, 0, 86, 192, 32, 219, 36, 170, 170, 172, 122, 137,
238, 122, 197, 30, 161, 70, 162, 20, 81, 203, 139, 25, 191, 255, 191, 60, 51, 40, 125, 81,
53, 33, 144, 15, 156, 155, 110, 232, 93, 128, 208, 189, 35, 89, 117, 65, 112, 222, 41, 99,
33, 37, 6, 215, 235, 195, 17, 239, 156, 197, 170, 118, 170, 131, 44, 32, 82, 164, 72, 240,
253, 245, 249, 129, 12, 185, 224, 76, 105, 61, 118, 99, 171, 66, 239, 38, 193, 35, 103, 85,
172, 66, 127, 33, 139, 24, 244, 235, 141, 49, 204, 223, 76, 208, 205, 204, 166, 7, 173, 60,
97, 159, 238, 37, 214, 41, 105, 129, 167, 5, 102, 27, 152, 173, 97, 178, 129, 73, 129, 231,
5, 230, 27, 152, 175, 225, 52, 192, 127, 243, 170, 157, 149, 18, 121, 142, 115, 109, 227, 122,
64, 87, 114, 111, 161, 49, 182, 6, 181, 158, 162, 226, 206, 167, 27, 215, 246, 48, 56, 99,
67, 117, 16, 47, 13, 45, 35, 151, 98, 231, 75, 1, 173, 90, 61, 101, 146, 71, 136, 244,
170, 218, 145, 176, 123, 45, 173, 56, 113, 134, 191, 51, 219, 78, 235, 95, 28, 249, 253, 7,
159, 150, 133, 125,
}
OUTPUT_SIZE :: 432
buf: bytes.Buffer
// We can pass ", true" to inflate a raw DEFLATE stream instead of a ZLIB wrapped one.
err := inflate(input=ODIN_DEMO, buf=&buf, expected_output_size=OUTPUT_SIZE)
defer bytes.buffer_destroy(&buf)
if err != nil {
fmt.printf("\nError: %v\n", err)
}
s := bytes.buffer_to_string(&buf)
fmt.printf("Input: %v bytes, output (%v bytes):\n%v\n", len(ODIN_DEMO), len(s), s)
assert(len(s) == OUTPUT_SIZE)
}
+16 -21
View File
@@ -1,4 +1,4 @@
//+vet !using-param
#+vet !using-param
package compress_zlib
/*
@@ -12,6 +12,7 @@ package compress_zlib
import "core:compress"
import "base:intrinsics"
import "core:mem"
import "core:io"
import "core:hash"
@@ -120,23 +121,17 @@ Huffman_Table :: struct {
}
// Implementation starts here
@(optimization_mode="speed")
@(optimization_mode="favor_size")
z_bit_reverse :: #force_inline proc(n: u16, bits: u8) -> (r: u16) {
assert(bits <= 16)
// NOTE: Can optimize with llvm.bitreverse.i64 or some bit twiddling
// by reversing all of the bits and masking out the unneeded ones.
r = n
r = ((r & 0xAAAA) >> 1) | ((r & 0x5555) << 1)
r = ((r & 0xCCCC) >> 2) | ((r & 0x3333) << 2)
r = ((r & 0xF0F0) >> 4) | ((r & 0x0F0F) << 4)
r = ((r & 0xFF00) >> 8) | ((r & 0x00FF) << 8)
r = intrinsics.reverse_bits(n)
r >>= (16 - bits)
return
}
@(optimization_mode="speed")
@(optimization_mode="favor_size")
grow_buffer :: proc(buf: ^[dynamic]u8) -> (err: compress.Error) {
/*
That we get here at all means that we didn't pass an expected output size,
@@ -154,7 +149,7 @@ grow_buffer :: proc(buf: ^[dynamic]u8) -> (err: compress.Error) {
TODO: Make these return compress.Error.
*/
@(optimization_mode="speed")
@(optimization_mode="favor_size")
write_byte :: #force_inline proc(z: ^$C, c: u8) -> (err: io.Error) #no_bounds_check {
/*
Resize if needed.
@@ -173,7 +168,7 @@ write_byte :: #force_inline proc(z: ^$C, c: u8) -> (err: io.Error) #no_bounds_ch
return .None
}
@(optimization_mode="speed")
@(optimization_mode="favor_size")
repl_byte :: proc(z: ^$C, count: u16, c: u8) -> (err: io.Error) #no_bounds_check {
/*
TODO(Jeroen): Once we have a magic ring buffer, we can just peek/write into it
@@ -201,7 +196,7 @@ repl_byte :: proc(z: ^$C, count: u16, c: u8) -> (err: io.Error) #no_bounds_check
return .None
}
@(optimization_mode="speed")
@(optimization_mode="favor_size")
repl_bytes :: proc(z: ^$C, count: u16, distance: u16) -> (err: io.Error) {
/*
TODO(Jeroen): Once we have a magic ring buffer, we can just peek/write into it
@@ -234,8 +229,8 @@ allocate_huffman_table :: proc(allocator := context.allocator) -> (z: ^Huffman_T
return new(Huffman_Table, allocator), nil
}
@(optimization_mode="speed")
build_huffman :: proc(z: ^Huffman_Table, code_lengths: []u8) -> (err: Error) {
@(optimization_mode="favor_size")
build_huffman :: #force_no_inline proc(z: ^Huffman_Table, code_lengths: []u8) -> (err: Error) {
sizes: [HUFFMAN_MAX_BITS+1]int
next_code: [HUFFMAN_MAX_BITS+1]int
@@ -293,7 +288,7 @@ build_huffman :: proc(z: ^Huffman_Table, code_lengths: []u8) -> (err: Error) {
return nil
}
@(optimization_mode="speed")
@(optimization_mode="favor_size")
decode_huffman_slowpath :: proc(z: ^$C, t: ^Huffman_Table) -> (r: u16, err: Error) #no_bounds_check {
code := u16(compress.peek_bits_lsb(z,16))
@@ -324,7 +319,7 @@ decode_huffman_slowpath :: proc(z: ^$C, t: ^Huffman_Table) -> (r: u16, err: Erro
return r, nil
}
@(optimization_mode="speed")
@(optimization_mode="favor_size")
decode_huffman :: proc(z: ^$C, t: ^Huffman_Table) -> (r: u16, err: Error) #no_bounds_check {
if z.num_bits < 16 {
if z.num_bits > 63 {
@@ -344,7 +339,7 @@ decode_huffman :: proc(z: ^$C, t: ^Huffman_Table) -> (r: u16, err: Error) #no_bo
return decode_huffman_slowpath(z, t)
}
@(optimization_mode="speed")
@(optimization_mode="favor_size")
parse_huffman_block :: proc(z: ^$C, z_repeat, z_offset: ^Huffman_Table) -> (err: Error) #no_bounds_check {
#no_bounds_check for {
value, e := decode_huffman(z, z_repeat)
@@ -413,7 +408,7 @@ parse_huffman_block :: proc(z: ^$C, z_repeat, z_offset: ^Huffman_Table) -> (err:
}
}
@(optimization_mode="speed")
@(optimization_mode="favor_size")
inflate_from_context :: proc(using ctx: ^compress.Context_Memory_Input, raw := false, expected_output_size := -1, allocator := context.allocator) -> (err: Error) #no_bounds_check {
/*
ctx.output must be a bytes.Buffer for now. We'll add a separate implementation that writes to a stream.
@@ -486,7 +481,7 @@ inflate_from_context :: proc(using ctx: ^compress.Context_Memory_Input, raw := f
// TODO: Check alignment of reserve/resize.
@(optimization_mode="speed")
@(optimization_mode="favor_size")
inflate_raw :: proc(z: ^$C, expected_output_size := -1, allocator := context.allocator) -> (err: Error) #no_bounds_check {
context.allocator = allocator
expected_output_size := expected_output_size
@@ -670,4 +665,4 @@ inflate_from_byte_array_raw :: proc(input: []u8, buf: ^bytes.Buffer, raw := fals
return inflate_raw(&ctx, expected_output_size=expected_output_size)
}
inflate :: proc{inflate_from_context, inflate_from_byte_array}
inflate :: proc{inflate_from_context, inflate_from_byte_array}
+4 -7
View File
@@ -5,13 +5,10 @@ The implementation is non-intrusive, and non-recursive.
*/
package container_avl
import "base:intrinsics"
import "base:runtime"
@(require) import "base:intrinsics"
@(require) import "base:runtime"
import "core:slice"
_ :: intrinsics
_ :: runtime
// Originally based on the CC0 implementation by Eric Biggers
// See: https://github.com/ebiggers/avl_tree/
@@ -90,7 +87,7 @@ init_cmp :: proc(
init_ordered :: proc(
t: ^$T/Tree($Value),
node_allocator := context.allocator,
) where intrinsics.type_is_ordered_numeric(Value) {
) where intrinsics.type_is_ordered(Value) {
init_cmp(t, slice.cmp_proc(Value), node_allocator)
}
@@ -675,4 +672,4 @@ iterator_first :: proc "contextless" (it: ^Iterator($Value)) {
if it._cur != nil {
it._next = node_next_or_prev_in_order(it._cur, it._direction)
}
}
}
+103 -25
View File
@@ -1,5 +1,6 @@
package container_dynamic_bit_array
import "base:builtin"
import "base:intrinsics"
import "core:mem"
@@ -18,7 +19,7 @@ NUM_BITS :: 64
Bit_Array :: struct {
bits: [dynamic]u64,
bias: int,
max_index: int,
length: int,
free_pointer: bool,
}
@@ -52,9 +53,9 @@ Returns:
*/
iterate_by_all :: proc (it: ^Bit_Array_Iterator) -> (set: bool, index: int, ok: bool) {
index = it.word_idx * NUM_BITS + int(it.bit_idx) + it.array.bias
if index > it.array.max_index { return false, 0, false }
if index >= it.array.length + it.array.bias { return false, 0, false }
word := it.array.bits[it.word_idx] if len(it.array.bits) > it.word_idx else 0
word := it.array.bits[it.word_idx] if builtin.len(it.array.bits) > it.word_idx else 0
set = (word >> it.bit_idx & 1) == 1
it.bit_idx += 1
@@ -106,22 +107,22 @@ Returns:
*/
@(private="file")
iterate_internal_ :: proc (it: ^Bit_Array_Iterator, $ITERATE_SET_BITS: bool) -> (index: int, ok: bool) {
word := it.array.bits[it.word_idx] if len(it.array.bits) > it.word_idx else 0
word := it.array.bits[it.word_idx] if builtin.len(it.array.bits) > it.word_idx else 0
when ! ITERATE_SET_BITS { word = ~word }
// If the word is empty or we have already gone over all the bits in it,
// b.bit_idx is greater than the index of any set bit in the word,
// meaning that word >> b.bit_idx == 0.
for it.word_idx < len(it.array.bits) && word >> it.bit_idx == 0 {
for it.word_idx < builtin.len(it.array.bits) && word >> it.bit_idx == 0 {
it.word_idx += 1
it.bit_idx = 0
word = it.array.bits[it.word_idx] if len(it.array.bits) > it.word_idx else 0
word = it.array.bits[it.word_idx] if builtin.len(it.array.bits) > it.word_idx else 0
when ! ITERATE_SET_BITS { word = ~word }
}
// If we are iterating the set bits, reaching the end of the array means we have no more bits to check
when ITERATE_SET_BITS {
if it.word_idx >= len(it.array.bits) {
if it.word_idx >= builtin.len(it.array.bits) {
return 0, false
}
}
@@ -135,7 +136,7 @@ iterate_internal_ :: proc (it: ^Bit_Array_Iterator, $ITERATE_SET_BITS: bool) ->
it.bit_idx = 0
it.word_idx += 1
}
return index, index <= it.array.max_index
return index, index < it.array.length + it.array.bias
}
/*
Gets the state of a bit in the bit-array
@@ -160,7 +161,7 @@ get :: proc(ba: ^Bit_Array, #any_int index: uint) -> (res: bool, ok: bool) #opti
If we `get` a bit that doesn't fit in the Bit Array, it's naturally `false`.
This early-out prevents unnecessary resizing.
*/
if leg_index + 1 > len(ba.bits) { return false, true }
if leg_index + 1 > builtin.len(ba.bits) { return false, true }
val := u64(1 << uint(bit_index))
res = ba.bits[leg_index] & val == val
@@ -208,10 +209,13 @@ set :: proc(ba: ^Bit_Array, #any_int index: uint, set_to: bool = true, allocator
resize_if_needed(ba, leg_index) or_return
ba.max_index = max(idx, ba.max_index)
ba.length = max(1 + idx, ba.length)
if set_to{ ba.bits[leg_index] |= 1 << uint(bit_index) }
else { ba.bits[leg_index] &= ~(1 << uint(bit_index)) }
if set_to {
ba.bits[leg_index] |= 1 << uint(bit_index)
} else {
ba.bits[leg_index] &~= 1 << uint(bit_index)
}
return true
}
@@ -253,11 +257,15 @@ Inputs:
- index: Which bit in the array
*/
unsafe_unset :: proc(b: ^Bit_Array, bit: int) #no_bounds_check {
b.bits[bit >> INDEX_SHIFT] &= ~(1 << uint(bit & INDEX_MASK))
b.bits[bit >> INDEX_SHIFT] &~= 1 << uint(bit & INDEX_MASK)
}
/*
A helper function to create a Bit Array with optional bias, in case your smallest index is non-zero (including negative).
The range of bits created by this procedure is `min_index..<max_index`, and the
array will be able to expand beyond `max_index` if needed.
*Allocates (`new(Bit_Array) & make(ba.bits)`)*
Inputs:
@@ -269,22 +277,50 @@ Returns:
- ba: Allocates a bit_Array, backing data is set to `max-min / 64` indices, rounded up (eg 65 - 0 allocates for [2]u64).
*/
create :: proc(max_index: int, min_index: int = 0, allocator := context.allocator) -> (res: ^Bit_Array, ok: bool) #optional_ok {
context.allocator = allocator
size_in_bits := max_index - min_index
if size_in_bits < 1 { return {}, false }
if size_in_bits < 0 { return {}, false }
legs := size_in_bits >> INDEX_SHIFT
if size_in_bits & INDEX_MASK > 0 {legs+=1}
bits, err := make([dynamic]u64, legs)
ok = err == mem.Allocator_Error.None
res = new(Bit_Array)
res.bits = bits
res.bias = min_index
res.max_index = max_index
res = new(Bit_Array, allocator)
ok = init(res, max_index, min_index, allocator)
res.free_pointer = true
if !ok { free(res, allocator) }
return
}
/*
A helper function to initialize a Bit Array with optional bias, in case your smallest index is non-zero (including negative).
The range of bits created by this procedure is `min_index..<max_index`, and the
array will be able to expand beyond `max_index` if needed.
*Allocates (`make(ba.bits)`)*
Inputs:
- max_index: maximum starting index
- min_index: minimum starting index (used as a bias)
- allocator: (default is context.allocator)
*/
init :: proc(res: ^Bit_Array, max_index: int, min_index: int = 0, allocator := context.allocator) -> (ok: bool) {
size_in_bits := max_index - min_index
if size_in_bits < 0 { return false }
legs := size_in_bits >> INDEX_SHIFT
if size_in_bits & INDEX_MASK > 0 { legs += 1 }
bits, err := make([dynamic]u64, legs, allocator)
ok = err == nil
res.bits = bits
res.bias = min_index
res.length = max_index - min_index
res.free_pointer = false
return
}
/*
Sets all values in the Bit_Array to zero.
@@ -296,6 +332,48 @@ clear :: proc(ba: ^Bit_Array) {
mem.zero_slice(ba.bits[:])
}
/*
Gets the length of set and unset valid bits in the Bit_Array.
Inputs:
- ba: The target Bit_Array
Returns:
- length: The length of valid bits.
*/
len :: proc(ba: ^Bit_Array) -> (length: int) {
if ba == nil { return }
return ba.length
}
/*
Shrinks the Bit_Array's backing storage to the smallest possible size.
Inputs:
- ba: The target Bit_Array
*/
shrink :: proc(ba: ^Bit_Array) #no_bounds_check {
if ba == nil { return }
legs_needed := builtin.len(ba.bits)
for i := legs_needed - 1; i >= 0; i -= 1 {
if ba.bits[i] == 0 {
legs_needed -= 1
} else {
break
}
}
if legs_needed == builtin.len(ba.bits) {
return
}
ba.length = 0
if legs_needed > 0 {
if legs_needed > 1 {
ba.length = (legs_needed - 1) * NUM_BITS
}
ba.length += NUM_BITS - int(intrinsics.count_leading_zeros(ba.bits[legs_needed - 1]))
}
resize(&ba.bits, legs_needed)
builtin.shrink(&ba.bits)
}
/*
Deallocates the Bit_Array and its backing storage
Inputs:
@@ -318,8 +396,8 @@ resize_if_needed :: proc(ba: ^Bit_Array, legs: int, allocator := context.allocat
context.allocator = allocator
if legs + 1 > len(ba.bits) {
if legs + 1 > builtin.len(ba.bits) {
resize(&ba.bits, legs + 1)
}
return len(ba.bits) > legs
return builtin.len(ba.bits) > legs
}
+4 -4
View File
@@ -1,8 +1,8 @@
/*
The Bit Array can be used in several ways:
- By default you don't need to instantiate a Bit Array:
By default you don't need to instantiate a Bit Array.
Example:
package test
import "core:fmt"
@@ -22,8 +22,8 @@ The Bit Array can be used in several ways:
destroy(&bits)
}
- A Bit Array can optionally allow for negative indices, if the minimum value was given during creation:
A Bit Array can optionally allow for negative indices, if the minimum value was given during creation.
Example:
package test
import "core:fmt"
+49
View File
@@ -0,0 +1,49 @@
/*
Package list implements an intrusive doubly-linked list.
An intrusive container requires a `Node` to be embedded in your own structure, like this.
Example:
My_String :: struct {
node: list.Node,
value: string,
}
Embedding the members of a `list.Node` in your structure with the `using` keyword is also allowed.
Example:
My_String :: struct {
using node: list.Node,
value: string,
}
Here is a full example.
Example:
package test
import "core:fmt"
import "core:container/intrusive/list"
main :: proc() {
l: list.List
one := My_String{value="Hello"}
two := My_String{value="World"}
list.push_back(&l, &one.node)
list.push_back(&l, &two.node)
iter := list.iterator_head(l, My_String, "node")
for s in list.iterate_next(&iter) {
fmt.println(s.value)
}
}
My_String :: struct {
node: list.Node,
value: string,
}
Output:
Hello
World
*/
package container_intrusive_list
@@ -18,11 +18,18 @@ List :: struct {
tail: ^Node,
}
// The list link you must include in your own structure.
Node :: struct {
prev, next: ^Node,
}
/*
Inserts a new element at the front of the list with O(1) time complexity.
**Inputs**
- list: The container list
- node: The node member of the user-defined element structure
*/
push_front :: proc "contextless" (list: ^List, node: ^Node) {
if list.head != nil {
list.head.prev = node
@@ -33,7 +40,13 @@ push_front :: proc "contextless" (list: ^List, node: ^Node) {
node.prev, node.next = nil, nil
}
}
/*
Inserts a new element at the back of the list with O(1) time complexity.
**Inputs**
- list: The container list
- node: The node member of the user-defined element structure
*/
push_back :: proc "contextless" (list: ^List, node: ^Node) {
if list.tail != nil {
list.tail.next = node
@@ -45,6 +58,13 @@ push_back :: proc "contextless" (list: ^List, node: ^Node) {
}
}
/*
Removes an element from a list with O(1) time complexity.
**Inputs**
- list: The container list
- node: The node member of the user-defined element structure to be removed
*/
remove :: proc "contextless" (list: ^List, node: ^Node) {
if node != nil {
if node.next != nil {
@@ -61,7 +81,13 @@ remove :: proc "contextless" (list: ^List, node: ^Node) {
}
}
}
/*
Removes from the given list all elements that satisfy a condition with O(N) time complexity.
**Inputs**
- list: The container list
- to_erase: The condition procedure. It should return `true` if a node should be removed, `false` otherwise
*/
remove_by_proc :: proc(list: ^List, to_erase: proc(^Node) -> bool) {
for node := list.head; node != nil; {
next := node.next
@@ -82,7 +108,13 @@ remove_by_proc :: proc(list: ^List, to_erase: proc(^Node) -> bool) {
node = next
}
}
/*
Removes from the given list all elements that satisfy a condition with O(N) time complexity.
**Inputs**
- list: The container list
- to_erase: The _contextless_ condition procedure. It should return `true` if a node should be removed, `false` otherwise
*/
remove_by_proc_contextless :: proc(list: ^List, to_erase: proc "contextless" (^Node) -> bool) {
for node := list.head; node != nil; {
next := node.next
@@ -104,12 +136,26 @@ remove_by_proc_contextless :: proc(list: ^List, to_erase: proc "contextless" (^N
}
}
/*
Checks whether the given list does not contain any element.
**Inputs**
- list: The container list
**Returns** `true` if `list` is empty, `false` otherwise
*/
is_empty :: proc "contextless" (list: ^List) -> bool {
return list.head == nil
}
/*
Removes and returns the element at the front of the list with O(1) time complexity.
**Inputs**
- list: The container list
**Returns** The node member of the user-defined element structure, or `nil` if the list is empty
*/
pop_front :: proc "contextless" (list: ^List) -> ^Node {
link := list.head
if link == nil {
@@ -130,6 +176,14 @@ pop_front :: proc "contextless" (list: ^List) -> ^Node {
return link
}
/*
Removes and returns the element at the back of the list with O(1) time complexity.
**Inputs**
- list: The container list
**Returns** The node member of the user-defined element structure, or `nil` if the list is empty
*/
pop_back :: proc "contextless" (list: ^List) -> ^Node {
link := list.tail
if link == nil {
@@ -151,29 +205,102 @@ pop_back :: proc "contextless" (list: ^List) -> ^Node {
}
Iterator :: struct($T: typeid) {
curr: ^Node,
offset: uintptr,
}
/*
Creates an iterator pointing at the head of the given list. For an example, see `iterate_next`.
**Inputs**
- list: The container list
- T: The type of the list's elements
- field_name: The name of the node field in the `T` structure
**Returns** An iterator pointing at the head of `list`
*/
iterator_head :: proc "contextless" (list: List, $T: typeid, $field_name: string) -> Iterator(T)
where intrinsics.type_has_field(T, field_name),
intrinsics.type_field_type(T, field_name) == Node {
return {list.head, offset_of_by_string(T, field_name)}
}
/*
Creates an iterator pointing at the tail of the given list. For an example, see `iterate_prev`.
**Inputs**
- list: The container list
- T: The type of the list's elements
- field_name: The name of the node field in the `T` structure
**Returns** An iterator pointing at the tail of `list`
*/
iterator_tail :: proc "contextless" (list: List, $T: typeid, $field_name: string) -> Iterator(T)
where intrinsics.type_has_field(T, field_name),
intrinsics.type_field_type(T, field_name) == Node {
return {list.tail, offset_of_by_string(T, field_name)}
}
/*
Creates an iterator pointing at the specified node of a list.
**Inputs**
- node: a list node
- T: The type of the list's elements
- field_name: The name of the node field in the `T` structure
**Returns** An iterator pointing at `node`
*/
iterator_from_node :: proc "contextless" (node: ^Node, $T: typeid, $field_name: string) -> Iterator(T)
where intrinsics.type_has_field(T, field_name),
intrinsics.type_field_type(T, field_name) == Node {
return {node, offset_of_by_string(T, field_name)}
}
/*
Retrieves the next element in a list and advances the iterator.
**Inputs**
- it: The iterator
**Returns**
- ptr: The next list element
- ok: `true` if the element is valid (the iterator could advance), `false` otherwise
Example:
import "core:fmt"
import "core:container/intrusive/list"
iterate_next_example :: proc() {
l: list.List
one := My_Struct{value=1}
two := My_Struct{value=2}
list.push_back(&l, &one.node)
list.push_back(&l, &two.node)
it := list.iterator_head(l, My_Struct, "node")
for num in list.iterate_next(&it) {
fmt.println(num.value)
}
}
My_Struct :: struct {
node : list.Node,
value: int,
}
Output:
1
2
*/
iterate_next :: proc "contextless" (it: ^Iterator($T)) -> (ptr: ^T, ok: bool) {
node := it.curr
if node == nil {
@@ -183,7 +310,47 @@ iterate_next :: proc "contextless" (it: ^Iterator($T)) -> (ptr: ^T, ok: bool) {
return (^T)(uintptr(node) - it.offset), true
}
/*
Retrieves the previous element in a list and recede the iterator.
**Inputs**
- it: The iterator
**Returns**
- ptr: The previous list element
- ok: `true` if the element is valid (the iterator could recede), `false` otherwise
Example:
import "core:fmt"
import "core:container/intrusive/list"
iterate_next_example :: proc() {
l: list.List
one := My_Struct{value=1}
two := My_Struct{value=2}
list.push_back(&l, &one.node)
list.push_back(&l, &two.node)
it := list.iterator_tail(l, My_Struct, "node")
for num in list.iterate_prev(&it) {
fmt.println(num.value)
}
}
My_Struct :: struct {
node : list.Node,
value: int,
}
Output:
2
1
*/
iterate_prev :: proc "contextless" (it: ^Iterator($T)) -> (ptr: ^T, ok: bool) {
node := it.curr
if node == nil {
@@ -192,4 +359,4 @@ iterate_prev :: proc "contextless" (it: ^Iterator($T)) -> (ptr: ^T, ok: bool) {
it.curr = node.prev
return (^T)(uintptr(node) - it.offset), true
}
}
+1 -2
View File
@@ -70,8 +70,7 @@ set :: proc(c: ^$C/Cache($Key, $Value), key: Key, value: Value) -> runtime.Alloc
if c.count == c.capacity {
e = c.tail
_remove_node(c, e)
}
else {
} else {
c.count += 1
e = new(Node(Key, Value), c.node_allocator) or_return
}
+4 -4
View File
@@ -95,11 +95,11 @@ front_ptr :: proc(q: ^$Q/Queue($T)) -> ^T {
}
back :: proc(q: ^$Q/Queue($T)) -> T {
idx := (q.offset+uint(q.len))%builtin.len(q.data)
idx := (q.offset+uint(q.len - 1))%builtin.len(q.data)
return q.data[idx]
}
back_ptr :: proc(q: ^$Q/Queue($T)) -> ^T {
idx := (q.offset+uint(q.len))%builtin.len(q.data)
idx := (q.offset+uint(q.len - 1))%builtin.len(q.data)
return &q.data[idx]
}
@@ -189,7 +189,7 @@ pop_front_safe :: proc(q: ^$Q/Queue($T)) -> (elem: T, ok: bool) {
return
}
// Push multiple elements to the front of the queue
// Push multiple elements to the back of the queue
push_back_elems :: proc(q: ^$Q/Queue($T), elems: ..T) -> (ok: bool, err: runtime.Allocator_Error) {
n := uint(builtin.len(elems))
if space(q^) < int(n) {
@@ -241,7 +241,7 @@ clear :: proc(q: ^$Q/Queue($T)) {
}
// Internal growinh procedure
// Internal growing procedure
_grow :: proc(q: ^$Q/Queue($T), min_capacity: uint = 0) -> runtime.Allocator_Error {
new_capacity := max(min_capacity, uint(8), uint(builtin.len(q.data))*2)
n := uint(builtin.len(q.data))
+568
View File
@@ -0,0 +1,568 @@
// This package implements a red-black tree
package container_rbtree
@(require) import "base:intrinsics"
@(require) import "base:runtime"
import "core:slice"
// Originally based on the CC0 implementation from literateprograms.org
// But with API design mimicking `core:container/avl` for ease of use.
// Direction specifies the traversal direction for a tree iterator.
Direction :: enum i8 {
// Backward is the in-order backwards direction.
Backward = -1,
// Forward is the in-order forwards direction.
Forward = 1,
}
Ordering :: slice.Ordering
// Tree is a red-black tree
Tree :: struct($Key: typeid, $Value: typeid) {
// user_data is a parameter that will be passed to the on_remove
// callback.
user_data: rawptr,
// on_remove is an optional callback that can be called immediately
// after a node is removed from the tree.
on_remove: proc(key: Key, value: Value, user_data: rawptr),
_root: ^Node(Key, Value),
_node_allocator: runtime.Allocator,
_cmp_fn: proc(Key, Key) -> Ordering,
_size: int,
}
// Node is a red-black tree node.
//
// WARNING: It is unsafe to mutate value if the node is part of a tree
// if doing so will alter the Node's sort position relative to other
// elements in the tree.
Node :: struct($Key: typeid, $Value: typeid) {
key: Key,
value: Value,
_parent: ^Node(Key, Value),
_left: ^Node(Key, Value),
_right: ^Node(Key, Value),
_color: Color,
}
// Might store this in the node pointer in the future, but that'll require a decent amount of rework to pass ^^N instead of ^N
Color :: enum uintptr {Black = 0, Red = 1}
// Iterator is a tree iterator.
//
// WARNING: It is unsafe to modify the tree while iterating, except via
// the iterator_remove method.
Iterator :: struct($Key: typeid, $Value: typeid) {
_tree: ^Tree(Key, Value),
_cur: ^Node(Key, Value),
_next: ^Node(Key, Value),
_direction: Direction,
_called_next: bool,
}
// init initializes a tree.
init :: proc {
init_ordered,
init_cmp,
}
// init_cmp initializes a tree.
init_cmp :: proc(t: ^$T/Tree($Key, $Value), cmp_fn: proc(a, b: Key) -> Ordering, node_allocator := context.allocator) {
t._root = nil
t._node_allocator = node_allocator
t._cmp_fn = cmp_fn
t._size = 0
}
// init_ordered initializes a tree containing ordered keys, with
// a comparison function that results in an ascending order sort.
init_ordered :: proc(t: ^$T/Tree($Key, $Value), node_allocator := context.allocator) where intrinsics.type_is_ordered(Key) {
init_cmp(t, slice.cmp_proc(Key), node_allocator)
}
// destroy de-initializes a tree.
destroy :: proc(t: ^$T/Tree($Key, $Value), call_on_remove: bool = true) {
iter := iterator(t, .Forward)
for _ in iterator_next(&iter) {
iterator_remove(&iter, call_on_remove)
}
}
len :: proc "contextless" (t: ^$T/Tree($Key, $Value)) -> (node_count: int) {
return t._size
}
// first returns the first node in the tree (in-order) or nil iff
// the tree is empty.
first :: proc "contextless" (t: ^$T/Tree($Key, $Value)) -> ^Node(Key, Value) {
return tree_first_or_last_in_order(t, Direction.Backward)
}
// last returns the last element in the tree (in-order) or nil iff
// the tree is empty.
last :: proc "contextless" (t: ^$T/Tree($Key, $Value)) -> ^Node(Key, Value) {
return tree_first_or_last_in_order(t, Direction.Forward)
}
// find finds the key in the tree, and returns the corresponding node, or nil iff the value is not present.
find :: proc(t: ^$T/Tree($Key, $Value), key: Key) -> (node: ^Node(Key, Value)) {
node = t._root
for node != nil {
switch t._cmp_fn(key, node.key) {
case .Equal: return node
case .Less: node = node._left
case .Greater: node = node._right
}
}
return node
}
// find_value finds the key in the tree, and returns the corresponding value, or nil iff the value is not present.
find_value :: proc(t: ^$T/Tree($Key, $Value), key: Key) -> (value: Value, ok: bool) #optional_ok {
if n := find(t, key); n != nil {
return n.value, true
}
return
}
// find_or_insert attempts to insert the value into the tree, and returns
// the node, a boolean indicating if the value was inserted, and the
// node allocator error if relevant. If the value is already present, the existing node is updated.
find_or_insert :: proc(t: ^$T/Tree($Key, $Value), key: Key, value: Value) -> (n: ^Node(Key, Value), inserted: bool, err: runtime.Allocator_Error) {
n_ptr := &t._root
for n_ptr^ != nil {
n = n_ptr^
switch t._cmp_fn(key, n.key) {
case .Less:
n_ptr = &n._left
case .Greater:
n_ptr = &n._right
case .Equal:
return
}
}
_parent := n
n = new_clone(Node(Key, Value){key=key, value=value, _parent=_parent, _color=.Red}, t._node_allocator) or_return
n_ptr^ = n
insert_case1(t, n)
t._size += 1
return n, true, nil
}
// remove removes a node or value from the tree, and returns true iff the
// removal was successful. While the node's value will be left intact,
// the node itself will be freed via the tree's node allocator.
remove :: proc {
remove_key,
remove_node,
}
// remove_value removes a value from the tree, and returns true iff the
// removal was successful. While the node's key + value will be left intact,
// the node itself will be freed via the tree's node allocator.
remove_key :: proc(t: ^$T/Tree($Key, $Value), key: Key, call_on_remove := true) -> bool {
n := find(t, key)
if n == nil {
return false // Key not found, nothing to do
}
return remove_node(t, n, call_on_remove)
}
// remove_node removes a node from the tree, and returns true iff the
// removal was successful. While the node's key + value will be left intact,
// the node itself will be freed via the tree's node allocator.
remove_node :: proc(t: ^$T/Tree($Key, $Value), node: ^$N/Node(Key, Value), call_on_remove := true) -> (found: bool) {
if node._parent == node || (node._parent == nil && t._root != node) {
return false // Don't touch self-parented or dangling nodes.
}
node := node
if node._left != nil && node._right != nil {
// Copy key + value from predecessor and delete it instead
predecessor := maximum_node(node._left)
node.key = predecessor.key
node.value = predecessor.value
node = predecessor
}
child := node._right == nil ? node._left : node._right
if node_color(node) == .Black {
node._color = node_color(child)
remove_case1(t, node)
}
replace_node(t, node, child)
if node._parent == nil && child != nil {
child._color = .Black // root should be black
}
if call_on_remove && t.on_remove != nil {
t.on_remove(node.key, node.value, t.user_data)
}
free(node, t._node_allocator)
t._size -= 1
return true
}
// iterator returns a tree iterator in the specified direction.
iterator :: proc "contextless" (t: ^$T/Tree($Key, $Value), direction: Direction) -> Iterator(Key, Value) {
it: Iterator(Key, Value)
it._tree = cast(^Tree(Key, Value))t
it._direction = direction
iterator_first(&it)
return it
}
// iterator_from_pos returns a tree iterator in the specified direction,
// spanning the range [pos, last] (inclusive).
iterator_from_pos :: proc "contextless" (t: ^$T/Tree($Key, $Value), pos: ^Node(Key, Value), direction: Direction) -> Iterator(Key, Value) {
it: Iterator(Key, Value)
it._tree = transmute(^Tree(Key, Value))t
it._direction = direction
it._next = nil
it._called_next = false
if it._cur = pos; pos != nil {
it._next = node_next_or_prev_in_order(it._cur, it._direction)
}
return it
}
// iterator_get returns the node currently pointed to by the iterator,
// or nil iff the node has been removed, the tree is empty, or the end
// of the tree has been reached.
iterator_get :: proc "contextless" (it: ^$I/Iterator($Key, $Value)) -> ^Node(Key, Value) {
return it._cur
}
// iterator_remove removes the node currently pointed to by the iterator,
// and returns true iff the removal was successful. Semantics are the
// same as the Tree remove.
iterator_remove :: proc(it: ^$I/Iterator($Key, $Value), call_on_remove: bool = true) -> bool {
if it._cur == nil {
return false
}
ok := remove_node(it._tree, it._cur , call_on_remove)
if ok {
it._cur = nil
}
return ok
}
// iterator_next advances the iterator and returns the (node, true) or
// or (nil, false) iff the end of the tree has been reached.
//
// Note: The first call to iterator_next will return the first node instead
// of advancing the iterator.
iterator_next :: proc "contextless" (it: ^$I/Iterator($Key, $Value)) -> (^Node(Key, Value), bool) {
// This check is needed so that the first element gets returned from
// a brand-new iterator, and so that the somewhat contrived case where
// iterator_remove is called before the first call to iterator_next
// returns the correct value.
if !it._called_next {
it._called_next = true
// There can be the contrived case where iterator_remove is
// called before ever calling iterator_next, which needs to be
// handled as an actual call to next.
//
// If this happens it._cur will be nil, so only return the
// first value, if it._cur is valid.
if it._cur != nil {
return it._cur, true
}
}
if it._next == nil {
return nil, false
}
it._cur = it._next
it._next = node_next_or_prev_in_order(it._cur, it._direction)
return it._cur, true
}
@(private)
tree_first_or_last_in_order :: proc "contextless" (t: ^$T/Tree($Key, $Value), direction: Direction) -> ^Node(Key, Value) {
first, sign := t._root, i8(direction)
if first != nil {
for {
tmp := node_get_child(first, sign)
if tmp == nil {
break
}
first = tmp
}
}
return first
}
@(private)
node_get_child :: #force_inline proc "contextless" (n: ^Node($Key, $Value), sign: i8) -> ^Node(Key, Value) {
if sign < 0 {
return n._left
}
return n._right
}
@(private)
node_next_or_prev_in_order :: proc "contextless" (n: ^Node($Key, $Value), direction: Direction) -> ^Node(Key, Value) {
next, tmp: ^Node(Key, Value)
sign := i8(direction)
if next = node_get_child(n, +sign); next != nil {
for {
tmp = node_get_child(next, -sign)
if tmp == nil {
break
}
next = tmp
}
} else {
tmp, next = n, n._parent
for next != nil && tmp == node_get_child(next, +sign) {
tmp, next = next, next._parent
}
}
return next
}
@(private)
iterator_first :: proc "contextless" (it: ^Iterator($Key, $Value)) {
// This is private because behavior when the user manually calls
// iterator_first followed by iterator_next is unintuitive, since
// the first call to iterator_next MUST return the first node
// instead of advancing so that `for node in iterator_next(&next)`
// works as expected.
switch it._direction {
case .Forward:
it._cur = tree_first_or_last_in_order(it._tree, .Backward)
case .Backward:
it._cur = tree_first_or_last_in_order(it._tree, .Forward)
}
it._next = nil
it._called_next = false
if it._cur != nil {
it._next = node_next_or_prev_in_order(it._cur, it._direction)
}
}
@(private)
grand_parent :: proc(n: ^$N/Node($Key, $Value)) -> (g: ^N) {
return n._parent._parent
}
@(private)
sibling :: proc(n: ^$N/Node($Key, $Value)) -> (s: ^N) {
if n == n._parent._left {
return n._parent._right
} else {
return n._parent._left
}
}
@(private)
uncle :: proc(n: ^$N/Node($Key, $Value)) -> (u: ^N) {
return sibling(n._parent)
}
@(private)
rotate__left :: proc(t: ^$T/Tree($Key, $Value), n: ^$N/Node(Key, Value)) {
r := n._right
replace_node(t, n, r)
n._right = r._left
if r._left != nil {
r._left._parent = n
}
r._left = n
n._parent = r
}
@(private)
rotate__right :: proc(t: ^$T/Tree($Key, $Value), n: ^$N/Node(Key, Value)) {
l := n._left
replace_node(t, n, l)
n._left = l._right
if l._right != nil {
l._right._parent = n
}
l._right = n
n._parent = l
}
@(private)
replace_node :: proc(t: ^$T/Tree($Key, $Value), old_n: ^$N/Node(Key, Value), new_n: ^N) {
if old_n._parent == nil {
t._root = new_n
} else {
if (old_n == old_n._parent._left) {
old_n._parent._left = new_n
} else {
old_n._parent._right = new_n
}
}
if new_n != nil {
new_n._parent = old_n._parent
}
}
@(private)
insert_case1 :: proc(t: ^$T/Tree($Key, $Value), n: ^$N/Node(Key, Value)) {
if n._parent == nil {
n._color = .Black
} else {
insert_case2(t, n)
}
}
@(private)
insert_case2 :: proc(t: ^$T/Tree($Key, $Value), n: ^$N/Node(Key, Value)) {
if node_color(n._parent) == .Black {
return // Tree is still valid
} else {
insert_case3(t, n)
}
}
@(private)
insert_case3 :: proc(t: ^$T/Tree($Key, $Value), n: ^$N/Node(Key, Value)) {
if node_color(uncle(n)) == .Red {
n._parent._color = .Black
uncle(n)._color = .Black
grand_parent(n)._color = .Red
insert_case1(t, grand_parent(n))
} else {
insert_case4(t, n)
}
}
@(private)
insert_case4 :: proc(t: ^$T/Tree($Key, $Value), n: ^$N/Node(Key, Value)) {
n := n
if n == n._parent._right && n._parent == grand_parent(n)._left {
rotate__left(t, n._parent)
n = n._left
} else if n == n._parent._left && n._parent == grand_parent(n)._right {
rotate__right(t, n._parent)
n = n._right
}
insert_case5(t, n)
}
@(private)
insert_case5 :: proc(t: ^$T/Tree($Key, $Value), n: ^$N/Node(Key, Value)) {
n._parent._color = .Black
grand_parent(n)._color = .Red
if n == n._parent._left && n._parent == grand_parent(n)._left {
rotate__right(t, grand_parent(n))
} else {
rotate__left(t, grand_parent(n))
}
}
// The maximum_node() helper function just walks _right until it reaches the last non-leaf:
@(private)
maximum_node :: proc(n: ^$N/Node($Key, $Value)) -> (max_node: ^N) {
n := n
for n._right != nil {
n = n._right
}
return n
}
@(private)
remove_case1 :: proc(t: ^$T/Tree($Key, $Value), n: ^$N/Node(Key, Value)) {
if n._parent == nil {
return
} else {
remove_case2(t, n)
}
}
@(private)
remove_case2 :: proc(t: ^$T/Tree($Key, $Value), n: ^$N/Node(Key, Value)) {
if node_color(sibling(n)) == .Red {
n._parent._color = .Red
sibling(n)._color = .Black
if n == n._parent._left {
rotate__left(t, n._parent)
} else {
rotate__right(t, n._parent)
}
}
remove_case3(t, n)
}
@(private)
remove_case3 :: proc(t: ^$T/Tree($Key, $Value), n: ^$N/Node(Key, Value)) {
if node_color(n._parent) == .Black &&
node_color(sibling(n)) == .Black &&
node_color(sibling(n)._left) == .Black &&
node_color(sibling(n)._right) == .Black {
sibling(n)._color = .Red
remove_case1(t, n._parent)
} else {
remove_case4(t, n)
}
}
@(private)
remove_case4 :: proc(t: ^$T/Tree($Key, $Value), n: ^$N/Node(Key, Value)) {
if node_color(n._parent) == .Red &&
node_color(sibling(n)) == .Black &&
node_color(sibling(n)._left) == .Black &&
node_color(sibling(n)._right) == .Black {
sibling(n)._color = .Red
n._parent._color = .Black
} else {
remove_case5(t, n)
}
}
@(private)
remove_case5 :: proc(t: ^$T/Tree($Key, $Value), n: ^$N/Node(Key, Value)) {
if n == n._parent._left &&
node_color(sibling(n)) == .Black &&
node_color(sibling(n)._left) == .Red &&
node_color(sibling(n)._right) == .Black {
sibling(n)._color = .Red
sibling(n)._left._color = .Black
rotate__right(t, sibling(n))
} else if n == n._parent._right &&
node_color(sibling(n)) == .Black &&
node_color(sibling(n)._right) == .Red &&
node_color(sibling(n)._left) == .Black {
sibling(n)._color = .Red
sibling(n)._right._color = .Black
rotate__left(t, sibling(n))
}
remove_case6(t, n)
}
@(private)
remove_case6 :: proc(t: ^$T/Tree($Key, $Value), n: ^$N/Node(Key, Value)) {
sibling(n)._color = node_color(n._parent)
n._parent._color = .Black
if n == n._parent._left {
sibling(n)._right._color = .Black
rotate__left(t, n._parent)
} else {
sibling(n)._left._color = .Black
rotate__right(t, n._parent)
}
}
node_color :: proc(n: ^$N/Node($Key, $Value)) -> (c: Color) {
return n == nil ? .Black : n._color
}
+11 -7
View File
@@ -119,29 +119,33 @@ consume :: proc "odin" (a: ^$A/Small_Array($N, $T), count: int, loc := #caller_l
}
ordered_remove :: proc "contextless" (a: ^$A/Small_Array($N, $T), index: int, loc := #caller_location) #no_bounds_check {
runtime.bounds_check_error_loc(loc, index, a.len)
if index+1 < a.len {
runtime.bounds_check_error_loc(loc, index, a.len)
if index+1 < a.len {
copy(a.data[index:], a.data[index+1:])
}
a.len -= 1
}
unordered_remove :: proc "contextless" (a: ^$A/Small_Array($N, $T), index: int, loc := #caller_location) #no_bounds_check {
runtime.bounds_check_error_loc(loc, index, a.len)
runtime.bounds_check_error_loc(loc, index, a.len)
n := a.len-1
if index != n {
a.data[index] = a.data[n]
}
a.len -= 1
a.len -= 1
}
clear :: proc "contextless" (a: ^$A/Small_Array($N, $T)) {
resize(a, 0)
}
push_back_elems :: proc "contextless" (a: ^$A/Small_Array($N, $T), items: ..T) {
n := copy(a.data[a.len:], items[:])
a.len += n
push_back_elems :: proc "contextless" (a: ^$A/Small_Array($N, $T), items: ..T) -> bool {
if a.len + builtin.len(items) <= cap(a^) {
n := copy(a.data[a.len:], items[:])
a.len += n
return true
}
return false
}
inject_at :: proc "contextless" (a: ^$A/Small_Array($N, $T), item: T, index: int) -> bool #no_bounds_check {
@@ -61,7 +61,7 @@ add_dependency :: proc(sorter: ^$S/Sorter($K), key, dependency: K) -> bool {
}
find.dependents[key] = true
find = &sorter.relations[key]
find = &sorter.relations[key]
if find == nil {
find = map_insert(&sorter.relations, key, make_relations(sorter))
}
+28
View File
@@ -0,0 +1,28 @@
package _aes
// KEY_SIZE_128 is the AES-128 key size in bytes.
KEY_SIZE_128 :: 16
// KEY_SIZE_192 is the AES-192 key size in bytes.
KEY_SIZE_192 :: 24
// KEY_SIZE_256 is the AES-256 key size in bytes.
KEY_SIZE_256 :: 32
// BLOCK_SIZE is the AES block size in bytes.
BLOCK_SIZE :: 16
// ROUNDS_128 is the number of rounds for AES-128.
ROUNDS_128 :: 10
// ROUNDS_192 is the number of rounds for AES-192.
ROUNDS_192 :: 12
// ROUNDS_256 is the number of rounds for AES-256.
ROUNDS_256 :: 14
// GHASH_KEY_SIZE is the GHASH key size in bytes.
GHASH_KEY_SIZE :: 16
// GHASH_BLOCK_SIZE is the GHASH block size in bytes.
GHASH_BLOCK_SIZE :: 16
// GHASH_TAG_SIZE is the GHASH tag size in bytes.
GHASH_TAG_SIZE :: 16
// RCON is the AES keyschedule round constants.
RCON := [10]byte{0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1B, 0x36}
+86
View File
@@ -0,0 +1,86 @@
package aes_ct64
import "base:intrinsics"
import "core:mem"
STRIDE :: 4
// Context is a keyed AES (ECB) instance.
Context :: struct {
_sk_exp: [120]u64,
_num_rounds: int,
}
// init initializes a context for AES with the provided key.
init :: proc(ctx: ^Context, key: []byte) {
skey: [30]u64 = ---
ctx._num_rounds = keysched(skey[:], key)
skey_expand(ctx._sk_exp[:], skey[:], ctx._num_rounds)
}
// encrypt_block sets `dst` to `AES-ECB-Encrypt(src)`.
encrypt_block :: proc(ctx: ^Context, dst, src: []byte) {
q: [8]u64
load_blockx1(&q, src)
_encrypt(&q, ctx._sk_exp[:], ctx._num_rounds)
store_blockx1(dst, &q)
}
// encrypt_block sets `dst` to `AES-ECB-Decrypt(src)`.
decrypt_block :: proc(ctx: ^Context, dst, src: []byte) {
q: [8]u64
load_blockx1(&q, src)
_decrypt(&q, ctx._sk_exp[:], ctx._num_rounds)
store_blockx1(dst, &q)
}
// encrypt_blocks sets `dst` to `AES-ECB-Encrypt(src[0], .. src[n])`.
encrypt_blocks :: proc(ctx: ^Context, dst, src: [][]byte) {
q: [8]u64 = ---
src, dst := src, dst
n := len(src)
for n > 4 {
load_blocks(&q, src[0:4])
_encrypt(&q, ctx._sk_exp[:], ctx._num_rounds)
store_blocks(dst[0:4], &q)
src = src[4:]
dst = dst[4:]
n -= 4
}
if n > 0 {
load_blocks(&q, src)
_encrypt(&q, ctx._sk_exp[:], ctx._num_rounds)
store_blocks(dst, &q)
}
}
// decrypt_blocks sets dst to `AES-ECB-Decrypt(src[0], .. src[n])`.
decrypt_blocks :: proc(ctx: ^Context, dst, src: [][]byte) {
q: [8]u64 = ---
src, dst := src, dst
n := len(src)
for n > 4 {
load_blocks(&q, src[0:4])
_decrypt(&q, ctx._sk_exp[:], ctx._num_rounds)
store_blocks(dst[0:4], &q)
src = src[4:]
dst = dst[4:]
n -= 4
}
if n > 0 {
load_blocks(&q, src)
_decrypt(&q, ctx._sk_exp[:], ctx._num_rounds)
store_blocks(dst, &q)
}
}
// reset sanitizes the Context. The Context must be re-initialized to
// be used again.
reset :: proc(ctx: ^Context) {
mem.zero_explicit(ctx, size_of(ctx))
}
+265
View File
@@ -0,0 +1,265 @@
// Copyright (c) 2016 Thomas Pornin <pornin@bolet.org>
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// THIS SOFTWARE IS PROVIDED BY THE AUTHORS AS IS AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package aes_ct64
import "base:intrinsics"
// Bitsliced AES for 64-bit general purpose (integer) registers. Each
// invocation will process up to 4 blocks at a time. This implementation
// is derived from the BearSSL ct64 code, and distributed under a 1-clause
// BSD license with permission from the original author.
//
// WARNING: "hic sunt dracones"
//
// This package also deliberately exposes enough internals to be able to
// function as a replacement for `AESENC` and `AESDEC` from AES-NI, to
// allow the implementation of non-AES primitives that use the AES round
// function such as AEGIS and Deoxys-II. This should ONLY be done when
// implementing something other than AES itself.
sub_bytes :: proc "contextless" (q: ^[8]u64) {
// This S-box implementation is a straightforward translation of
// the circuit described by Boyar and Peralta in "A new
// combinational logic minimization technique with applications
// to cryptology" (https://eprint.iacr.org/2009/191.pdf).
//
// Note that variables x* (input) and s* (output) are numbered
// in "reverse" order (x0 is the high bit, x7 is the low bit).
x0 := q[7]
x1 := q[6]
x2 := q[5]
x3 := q[4]
x4 := q[3]
x5 := q[2]
x6 := q[1]
x7 := q[0]
// Top linear transformation.
y14 := x3 ~ x5
y13 := x0 ~ x6
y9 := x0 ~ x3
y8 := x0 ~ x5
t0 := x1 ~ x2
y1 := t0 ~ x7
y4 := y1 ~ x3
y12 := y13 ~ y14
y2 := y1 ~ x0
y5 := y1 ~ x6
y3 := y5 ~ y8
t1 := x4 ~ y12
y15 := t1 ~ x5
y20 := t1 ~ x1
y6 := y15 ~ x7
y10 := y15 ~ t0
y11 := y20 ~ y9
y7 := x7 ~ y11
y17 := y10 ~ y11
y19 := y10 ~ y8
y16 := t0 ~ y11
y21 := y13 ~ y16
y18 := x0 ~ y16
// Non-linear section.
t2 := y12 & y15
t3 := y3 & y6
t4 := t3 ~ t2
t5 := y4 & x7
t6 := t5 ~ t2
t7 := y13 & y16
t8 := y5 & y1
t9 := t8 ~ t7
t10 := y2 & y7
t11 := t10 ~ t7
t12 := y9 & y11
t13 := y14 & y17
t14 := t13 ~ t12
t15 := y8 & y10
t16 := t15 ~ t12
t17 := t4 ~ t14
t18 := t6 ~ t16
t19 := t9 ~ t14
t20 := t11 ~ t16
t21 := t17 ~ y20
t22 := t18 ~ y19
t23 := t19 ~ y21
t24 := t20 ~ y18
t25 := t21 ~ t22
t26 := t21 & t23
t27 := t24 ~ t26
t28 := t25 & t27
t29 := t28 ~ t22
t30 := t23 ~ t24
t31 := t22 ~ t26
t32 := t31 & t30
t33 := t32 ~ t24
t34 := t23 ~ t33
t35 := t27 ~ t33
t36 := t24 & t35
t37 := t36 ~ t34
t38 := t27 ~ t36
t39 := t29 & t38
t40 := t25 ~ t39
t41 := t40 ~ t37
t42 := t29 ~ t33
t43 := t29 ~ t40
t44 := t33 ~ t37
t45 := t42 ~ t41
z0 := t44 & y15
z1 := t37 & y6
z2 := t33 & x7
z3 := t43 & y16
z4 := t40 & y1
z5 := t29 & y7
z6 := t42 & y11
z7 := t45 & y17
z8 := t41 & y10
z9 := t44 & y12
z10 := t37 & y3
z11 := t33 & y4
z12 := t43 & y13
z13 := t40 & y5
z14 := t29 & y2
z15 := t42 & y9
z16 := t45 & y14
z17 := t41 & y8
// Bottom linear transformation.
t46 := z15 ~ z16
t47 := z10 ~ z11
t48 := z5 ~ z13
t49 := z9 ~ z10
t50 := z2 ~ z12
t51 := z2 ~ z5
t52 := z7 ~ z8
t53 := z0 ~ z3
t54 := z6 ~ z7
t55 := z16 ~ z17
t56 := z12 ~ t48
t57 := t50 ~ t53
t58 := z4 ~ t46
t59 := z3 ~ t54
t60 := t46 ~ t57
t61 := z14 ~ t57
t62 := t52 ~ t58
t63 := t49 ~ t58
t64 := z4 ~ t59
t65 := t61 ~ t62
t66 := z1 ~ t63
s0 := t59 ~ t63
s6 := t56 ~ ~t62
s7 := t48 ~ ~t60
t67 := t64 ~ t65
s3 := t53 ~ t66
s4 := t51 ~ t66
s5 := t47 ~ t65
s1 := t64 ~ ~s3
s2 := t55 ~ ~t67
q[7] = s0
q[6] = s1
q[5] = s2
q[4] = s3
q[3] = s4
q[2] = s5
q[1] = s6
q[0] = s7
}
orthogonalize :: proc "contextless" (q: ^[8]u64) {
CL2 :: 0x5555555555555555
CH2 :: 0xAAAAAAAAAAAAAAAA
q[0], q[1] = (q[0] & CL2) | ((q[1] & CL2) << 1), ((q[0] & CH2) >> 1) | (q[1] & CH2)
q[2], q[3] = (q[2] & CL2) | ((q[3] & CL2) << 1), ((q[2] & CH2) >> 1) | (q[3] & CH2)
q[4], q[5] = (q[4] & CL2) | ((q[5] & CL2) << 1), ((q[4] & CH2) >> 1) | (q[5] & CH2)
q[6], q[7] = (q[6] & CL2) | ((q[7] & CL2) << 1), ((q[6] & CH2) >> 1) | (q[7] & CH2)
CL4 :: 0x3333333333333333
CH4 :: 0xCCCCCCCCCCCCCCCC
q[0], q[2] = (q[0] & CL4) | ((q[2] & CL4) << 2), ((q[0] & CH4) >> 2) | (q[2] & CH4)
q[1], q[3] = (q[1] & CL4) | ((q[3] & CL4) << 2), ((q[1] & CH4) >> 2) | (q[3] & CH4)
q[4], q[6] = (q[4] & CL4) | ((q[6] & CL4) << 2), ((q[4] & CH4) >> 2) | (q[6] & CH4)
q[5], q[7] = (q[5] & CL4) | ((q[7] & CL4) << 2), ((q[5] & CH4) >> 2) | (q[7] & CH4)
CL8 :: 0x0F0F0F0F0F0F0F0F
CH8 :: 0xF0F0F0F0F0F0F0F0
q[0], q[4] = (q[0] & CL8) | ((q[4] & CL8) << 4), ((q[0] & CH8) >> 4) | (q[4] & CH8)
q[1], q[5] = (q[1] & CL8) | ((q[5] & CL8) << 4), ((q[1] & CH8) >> 4) | (q[5] & CH8)
q[2], q[6] = (q[2] & CL8) | ((q[6] & CL8) << 4), ((q[2] & CH8) >> 4) | (q[6] & CH8)
q[3], q[7] = (q[3] & CL8) | ((q[7] & CL8) << 4), ((q[3] & CH8) >> 4) | (q[7] & CH8)
}
@(require_results)
interleave_in :: proc "contextless" (w: []u32) -> (q0, q1: u64) #no_bounds_check {
if len(w) < 4 {
intrinsics.trap()
}
x0, x1, x2, x3 := u64(w[0]), u64(w[1]), u64(w[2]), u64(w[3])
x0 |= (x0 << 16)
x1 |= (x1 << 16)
x2 |= (x2 << 16)
x3 |= (x3 << 16)
x0 &= 0x0000FFFF0000FFFF
x1 &= 0x0000FFFF0000FFFF
x2 &= 0x0000FFFF0000FFFF
x3 &= 0x0000FFFF0000FFFF
x0 |= (x0 << 8)
x1 |= (x1 << 8)
x2 |= (x2 << 8)
x3 |= (x3 << 8)
x0 &= 0x00FF00FF00FF00FF
x1 &= 0x00FF00FF00FF00FF
x2 &= 0x00FF00FF00FF00FF
x3 &= 0x00FF00FF00FF00FF
q0 = x0 | (x2 << 8)
q1 = x1 | (x3 << 8)
return
}
@(require_results)
interleave_out :: proc "contextless" (q0, q1: u64) -> (w0, w1, w2, w3: u32) {
x0 := q0 & 0x00FF00FF00FF00FF
x1 := q1 & 0x00FF00FF00FF00FF
x2 := (q0 >> 8) & 0x00FF00FF00FF00FF
x3 := (q1 >> 8) & 0x00FF00FF00FF00FF
x0 |= (x0 >> 8)
x1 |= (x1 >> 8)
x2 |= (x2 >> 8)
x3 |= (x3 >> 8)
x0 &= 0x0000FFFF0000FFFF
x1 &= 0x0000FFFF0000FFFF
x2 &= 0x0000FFFF0000FFFF
x3 &= 0x0000FFFF0000FFFF
w0 = u32(x0) | u32(x0 >> 16)
w1 = u32(x1) | u32(x1 >> 16)
w2 = u32(x2) | u32(x2 >> 16)
w3 = u32(x3) | u32(x3 >> 16)
return
}
@(private)
rotr32 :: #force_inline proc "contextless" (x: u64) -> u64 {
return (x << 32) | (x >> 32)
}
+135
View File
@@ -0,0 +1,135 @@
// Copyright (c) 2016 Thomas Pornin <pornin@bolet.org>
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// THIS SOFTWARE IS PROVIDED BY THE AUTHORS AS IS AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package aes_ct64
import "base:intrinsics"
inv_sub_bytes :: proc "contextless" (q: ^[8]u64) {
// AES S-box is:
// S(x) = A(I(x)) ^ 0x63
// where I() is inversion in GF(256), and A() is a linear
// transform (0 is formally defined to be its own inverse).
// Since inversion is an involution, the inverse S-box can be
// computed from the S-box as:
// iS(x) = B(S(B(x ^ 0x63)) ^ 0x63)
// where B() is the inverse of A(). Indeed, for any y in GF(256):
// iS(S(y)) = B(A(I(B(A(I(y)) ^ 0x63 ^ 0x63))) ^ 0x63 ^ 0x63) = y
//
// Note: we reuse the implementation of the forward S-box,
// instead of duplicating it here, so that total code size is
// lower. By merging the B() transforms into the S-box circuit
// we could make faster CBC decryption, but CBC decryption is
// already quite faster than CBC encryption because we can
// process four blocks in parallel.
q0 := ~q[0]
q1 := ~q[1]
q2 := q[2]
q3 := q[3]
q4 := q[4]
q5 := ~q[5]
q6 := ~q[6]
q7 := q[7]
q[7] = q1 ~ q4 ~ q6
q[6] = q0 ~ q3 ~ q5
q[5] = q7 ~ q2 ~ q4
q[4] = q6 ~ q1 ~ q3
q[3] = q5 ~ q0 ~ q2
q[2] = q4 ~ q7 ~ q1
q[1] = q3 ~ q6 ~ q0
q[0] = q2 ~ q5 ~ q7
sub_bytes(q)
q0 = ~q[0]
q1 = ~q[1]
q2 = q[2]
q3 = q[3]
q4 = q[4]
q5 = ~q[5]
q6 = ~q[6]
q7 = q[7]
q[7] = q1 ~ q4 ~ q6
q[6] = q0 ~ q3 ~ q5
q[5] = q7 ~ q2 ~ q4
q[4] = q6 ~ q1 ~ q3
q[3] = q5 ~ q0 ~ q2
q[2] = q4 ~ q7 ~ q1
q[1] = q3 ~ q6 ~ q0
q[0] = q2 ~ q5 ~ q7
}
inv_shift_rows :: proc "contextless" (q: ^[8]u64) {
for x, i in q {
q[i] =
(x & 0x000000000000FFFF) |
((x & 0x000000000FFF0000) << 4) |
((x & 0x00000000F0000000) >> 12) |
((x & 0x000000FF00000000) << 8) |
((x & 0x0000FF0000000000) >> 8) |
((x & 0x000F000000000000) << 12) |
((x & 0xFFF0000000000000) >> 4)
}
}
inv_mix_columns :: proc "contextless" (q: ^[8]u64) {
q0 := q[0]
q1 := q[1]
q2 := q[2]
q3 := q[3]
q4 := q[4]
q5 := q[5]
q6 := q[6]
q7 := q[7]
r0 := (q0 >> 16) | (q0 << 48)
r1 := (q1 >> 16) | (q1 << 48)
r2 := (q2 >> 16) | (q2 << 48)
r3 := (q3 >> 16) | (q3 << 48)
r4 := (q4 >> 16) | (q4 << 48)
r5 := (q5 >> 16) | (q5 << 48)
r6 := (q6 >> 16) | (q6 << 48)
r7 := (q7 >> 16) | (q7 << 48)
q[0] = q5 ~ q6 ~ q7 ~ r0 ~ r5 ~ r7 ~ rotr32(q0 ~ q5 ~ q6 ~ r0 ~ r5)
q[1] = q0 ~ q5 ~ r0 ~ r1 ~ r5 ~ r6 ~ r7 ~ rotr32(q1 ~ q5 ~ q7 ~ r1 ~ r5 ~ r6)
q[2] = q0 ~ q1 ~ q6 ~ r1 ~ r2 ~ r6 ~ r7 ~ rotr32(q0 ~ q2 ~ q6 ~ r2 ~ r6 ~ r7)
q[3] = q0 ~ q1 ~ q2 ~ q5 ~ q6 ~ r0 ~ r2 ~ r3 ~ r5 ~ rotr32(q0 ~ q1 ~ q3 ~ q5 ~ q6 ~ q7 ~ r0 ~ r3 ~ r5 ~ r7)
q[4] = q1 ~ q2 ~ q3 ~ q5 ~ r1 ~ r3 ~ r4 ~ r5 ~ r6 ~ r7 ~ rotr32(q1 ~ q2 ~ q4 ~ q5 ~ q7 ~ r1 ~ r4 ~ r5 ~ r6)
q[5] = q2 ~ q3 ~ q4 ~ q6 ~ r2 ~ r4 ~ r5 ~ r6 ~ r7 ~ rotr32(q2 ~ q3 ~ q5 ~ q6 ~ r2 ~ r5 ~ r6 ~ r7)
q[6] = q3 ~ q4 ~ q5 ~ q7 ~ r3 ~ r5 ~ r6 ~ r7 ~ rotr32(q3 ~ q4 ~ q6 ~ q7 ~ r3 ~ r6 ~ r7)
q[7] = q4 ~ q5 ~ q6 ~ r4 ~ r6 ~ r7 ~ rotr32(q4 ~ q5 ~ q7 ~ r4 ~ r7)
}
@(private)
_decrypt :: proc "contextless" (q: ^[8]u64, skey: []u64, num_rounds: int) {
add_round_key(q, skey[num_rounds << 3:])
for u := num_rounds - 1; u > 0; u -= 1 {
inv_shift_rows(q)
inv_sub_bytes(q)
add_round_key(q, skey[u << 3:])
inv_mix_columns(q)
}
inv_shift_rows(q)
inv_sub_bytes(q)
add_round_key(q, skey)
}
+95
View File
@@ -0,0 +1,95 @@
// Copyright (c) 2016 Thomas Pornin <pornin@bolet.org>
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// THIS SOFTWARE IS PROVIDED BY THE AUTHORS AS IS AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package aes_ct64
import "base:intrinsics"
add_round_key :: proc "contextless" (q: ^[8]u64, sk: []u64) #no_bounds_check {
if len(sk) < 8 {
intrinsics.trap()
}
q[0] ~= sk[0]
q[1] ~= sk[1]
q[2] ~= sk[2]
q[3] ~= sk[3]
q[4] ~= sk[4]
q[5] ~= sk[5]
q[6] ~= sk[6]
q[7] ~= sk[7]
}
shift_rows :: proc "contextless" (q: ^[8]u64) {
for x, i in q {
q[i] =
(x & 0x000000000000FFFF) |
((x & 0x00000000FFF00000) >> 4) |
((x & 0x00000000000F0000) << 12) |
((x & 0x0000FF0000000000) >> 8) |
((x & 0x000000FF00000000) << 8) |
((x & 0xF000000000000000) >> 12) |
((x & 0x0FFF000000000000) << 4)
}
}
mix_columns :: proc "contextless" (q: ^[8]u64) {
q0 := q[0]
q1 := q[1]
q2 := q[2]
q3 := q[3]
q4 := q[4]
q5 := q[5]
q6 := q[6]
q7 := q[7]
r0 := (q0 >> 16) | (q0 << 48)
r1 := (q1 >> 16) | (q1 << 48)
r2 := (q2 >> 16) | (q2 << 48)
r3 := (q3 >> 16) | (q3 << 48)
r4 := (q4 >> 16) | (q4 << 48)
r5 := (q5 >> 16) | (q5 << 48)
r6 := (q6 >> 16) | (q6 << 48)
r7 := (q7 >> 16) | (q7 << 48)
q[0] = q7 ~ r7 ~ r0 ~ rotr32(q0 ~ r0)
q[1] = q0 ~ r0 ~ q7 ~ r7 ~ r1 ~ rotr32(q1 ~ r1)
q[2] = q1 ~ r1 ~ r2 ~ rotr32(q2 ~ r2)
q[3] = q2 ~ r2 ~ q7 ~ r7 ~ r3 ~ rotr32(q3 ~ r3)
q[4] = q3 ~ r3 ~ q7 ~ r7 ~ r4 ~ rotr32(q4 ~ r4)
q[5] = q4 ~ r4 ~ r5 ~ rotr32(q5 ~ r5)
q[6] = q5 ~ r5 ~ r6 ~ rotr32(q6 ~ r6)
q[7] = q6 ~ r6 ~ r7 ~ rotr32(q7 ~ r7)
}
@(private)
_encrypt :: proc "contextless" (q: ^[8]u64, skey: []u64, num_rounds: int) {
add_round_key(q, skey)
for u in 1 ..< num_rounds {
sub_bytes(q)
shift_rows(q)
mix_columns(q)
add_round_key(q, skey[u << 3:])
}
sub_bytes(q)
shift_rows(q)
add_round_key(q, skey[num_rounds << 3:])
}
+179
View File
@@ -0,0 +1,179 @@
// Copyright (c) 2016 Thomas Pornin <pornin@bolet.org>
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// THIS SOFTWARE IS PROVIDED BY THE AUTHORS AS IS AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package aes_ct64
import "base:intrinsics"
import "core:crypto/_aes"
import "core:encoding/endian"
import "core:mem"
@(private, require_results)
sub_word :: proc "contextless" (x: u32) -> u32 {
q := [8]u64{u64(x), 0, 0, 0, 0, 0, 0, 0}
orthogonalize(&q)
sub_bytes(&q)
orthogonalize(&q)
ret := u32(q[0])
mem.zero_explicit(&q[0], size_of(u64))
return ret
}
@(private, require_results)
keysched :: proc(comp_skey: []u64, key: []byte) -> int {
num_rounds, key_len := 0, len(key)
switch key_len {
case _aes.KEY_SIZE_128:
num_rounds = _aes.ROUNDS_128
case _aes.KEY_SIZE_192:
num_rounds = _aes.ROUNDS_192
case _aes.KEY_SIZE_256:
num_rounds = _aes.ROUNDS_256
case:
panic("crypto/aes: invalid AES key size")
}
skey: [60]u32 = ---
nk, nkf := key_len >> 2, (num_rounds + 1) << 2
for i in 0 ..< nk {
skey[i] = endian.unchecked_get_u32le(key[i << 2:])
}
tmp := skey[(key_len >> 2) - 1]
for i, j, k := nk, 0, 0; i < nkf; i += 1 {
if j == 0 {
tmp = (tmp << 24) | (tmp >> 8)
tmp = sub_word(tmp) ~ u32(_aes.RCON[k])
} else if nk > 6 && j == 4 {
tmp = sub_word(tmp)
}
tmp ~= skey[i - nk]
skey[i] = tmp
if j += 1; j == nk {
j = 0
k += 1
}
}
q: [8]u64 = ---
for i, j := 0, 0; i < nkf; i, j = i + 4, j + 2 {
q[0], q[4] = interleave_in(skey[i:])
q[1] = q[0]
q[2] = q[0]
q[3] = q[0]
q[5] = q[4]
q[6] = q[4]
q[7] = q[4]
orthogonalize(&q)
comp_skey[j + 0] =
(q[0] & 0x1111111111111111) |
(q[1] & 0x2222222222222222) |
(q[2] & 0x4444444444444444) |
(q[3] & 0x8888888888888888)
comp_skey[j + 1] =
(q[4] & 0x1111111111111111) |
(q[5] & 0x2222222222222222) |
(q[6] & 0x4444444444444444) |
(q[7] & 0x8888888888888888)
}
mem.zero_explicit(&skey, size_of(skey))
mem.zero_explicit(&q, size_of(q))
return num_rounds
}
@(private)
skey_expand :: proc "contextless" (skey, comp_skey: []u64, num_rounds: int) {
n := (num_rounds + 1) << 1
for u, v := 0, 0; u < n; u, v = u + 1, v + 4 {
x0 := comp_skey[u]
x1, x2, x3 := x0, x0, x0
x0 &= 0x1111111111111111
x1 &= 0x2222222222222222
x2 &= 0x4444444444444444
x3 &= 0x8888888888888888
x1 >>= 1
x2 >>= 2
x3 >>= 3
skey[v + 0] = (x0 << 4) - x0
skey[v + 1] = (x1 << 4) - x1
skey[v + 2] = (x2 << 4) - x2
skey[v + 3] = (x3 << 4) - x3
}
}
orthogonalize_roundkey :: proc "contextless" (qq: []u64, key: []byte) {
if len(qq) < 8 || len(key) != 16 {
intrinsics.trap()
}
skey: [4]u32 = ---
skey[0] = endian.unchecked_get_u32le(key[0:])
skey[1] = endian.unchecked_get_u32le(key[4:])
skey[2] = endian.unchecked_get_u32le(key[8:])
skey[3] = endian.unchecked_get_u32le(key[12:])
q: [8]u64 = ---
q[0], q[4] = interleave_in(skey[:])
q[1] = q[0]
q[2] = q[0]
q[3] = q[0]
q[5] = q[4]
q[6] = q[4]
q[7] = q[4]
orthogonalize(&q)
comp_skey: [2]u64 = ---
comp_skey[0] =
(q[0] & 0x1111111111111111) |
(q[1] & 0x2222222222222222) |
(q[2] & 0x4444444444444444) |
(q[3] & 0x8888888888888888)
comp_skey[1] =
(q[4] & 0x1111111111111111) |
(q[5] & 0x2222222222222222) |
(q[6] & 0x4444444444444444) |
(q[7] & 0x8888888888888888)
for x, u in comp_skey {
x0 := x
x1, x2, x3 := x0, x0, x0
x0 &= 0x1111111111111111
x1 &= 0x2222222222222222
x2 &= 0x4444444444444444
x3 &= 0x8888888888888888
x1 >>= 1
x2 >>= 2
x3 >>= 3
qq[u * 4 + 0] = (x0 << 4) - x0
qq[u * 4 + 1] = (x1 << 4) - x1
qq[u * 4 + 2] = (x2 << 4) - x2
qq[u * 4 + 3] = (x3 << 4) - x3
}
mem.zero_explicit(&skey, size_of(skey))
mem.zero_explicit(&q, size_of(q))
mem.zero_explicit(&comp_skey, size_of(comp_skey))
}
+136
View File
@@ -0,0 +1,136 @@
// Copyright (c) 2016 Thomas Pornin <pornin@bolet.org>
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// THIS SOFTWARE IS PROVIDED BY THE AUTHORS AS IS AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package aes_ct64
import "base:intrinsics"
import "core:crypto/_aes"
import "core:encoding/endian"
@(private = "file")
bmul64 :: proc "contextless" (x, y: u64) -> u64 {
x0 := x & 0x1111111111111111
x1 := x & 0x2222222222222222
x2 := x & 0x4444444444444444
x3 := x & 0x8888888888888888
y0 := y & 0x1111111111111111
y1 := y & 0x2222222222222222
y2 := y & 0x4444444444444444
y3 := y & 0x8888888888888888
z0 := (x0 * y0) ~ (x1 * y3) ~ (x2 * y2) ~ (x3 * y1)
z1 := (x0 * y1) ~ (x1 * y0) ~ (x2 * y3) ~ (x3 * y2)
z2 := (x0 * y2) ~ (x1 * y1) ~ (x2 * y0) ~ (x3 * y3)
z3 := (x0 * y3) ~ (x1 * y2) ~ (x2 * y1) ~ (x3 * y0)
z0 &= 0x1111111111111111
z1 &= 0x2222222222222222
z2 &= 0x4444444444444444
z3 &= 0x8888888888888888
return z0 | z1 | z2 | z3
}
@(private = "file")
rev64 :: proc "contextless" (x: u64) -> u64 {
x := x
x = ((x & 0x5555555555555555) << 1) | ((x >> 1) & 0x5555555555555555)
x = ((x & 0x3333333333333333) << 2) | ((x >> 2) & 0x3333333333333333)
x = ((x & 0x0F0F0F0F0F0F0F0F) << 4) | ((x >> 4) & 0x0F0F0F0F0F0F0F0F)
x = ((x & 0x00FF00FF00FF00FF) << 8) | ((x >> 8) & 0x00FF00FF00FF00FF)
x = ((x & 0x0000FFFF0000FFFF) << 16) | ((x >> 16) & 0x0000FFFF0000FFFF)
return (x << 32) | (x >> 32)
}
// ghash calculates the GHASH of data, with the key `key`, and input `dst`
// and `data`, and stores the resulting digest in `dst`.
//
// Note: `dst` is both an input and an output, to support easy implementation
// of GCM.
ghash :: proc "contextless" (dst, key, data: []byte) {
if len(dst) != _aes.GHASH_BLOCK_SIZE || len(key) != _aes.GHASH_BLOCK_SIZE {
intrinsics.trap()
}
buf := data
l := len(buf)
y1 := endian.unchecked_get_u64be(dst[0:])
y0 := endian.unchecked_get_u64be(dst[8:])
h1 := endian.unchecked_get_u64be(key[0:])
h0 := endian.unchecked_get_u64be(key[8:])
h0r := rev64(h0)
h1r := rev64(h1)
h2 := h0 ~ h1
h2r := h0r ~ h1r
for l > 0 {
src: []byte = ---
if l >= _aes.GHASH_BLOCK_SIZE {
src = buf
buf = buf[_aes.GHASH_BLOCK_SIZE:]
l -= _aes.GHASH_BLOCK_SIZE
} else {
tmp: [_aes.GHASH_BLOCK_SIZE]byte
copy(tmp[:], buf)
src = tmp[:]
l = 0
}
y1 ~= endian.unchecked_get_u64be(src)
y0 ~= endian.unchecked_get_u64be(src[8:])
y0r := rev64(y0)
y1r := rev64(y1)
y2 := y0 ~ y1
y2r := y0r ~ y1r
z0 := bmul64(y0, h0)
z1 := bmul64(y1, h1)
z2 := bmul64(y2, h2)
z0h := bmul64(y0r, h0r)
z1h := bmul64(y1r, h1r)
z2h := bmul64(y2r, h2r)
z2 ~= z0 ~ z1
z2h ~= z0h ~ z1h
z0h = rev64(z0h) >> 1
z1h = rev64(z1h) >> 1
z2h = rev64(z2h) >> 1
v0 := z0
v1 := z0h ~ z2
v2 := z1 ~ z2h
v3 := z1h
v3 = (v3 << 1) | (v2 >> 63)
v2 = (v2 << 1) | (v1 >> 63)
v1 = (v1 << 1) | (v0 >> 63)
v0 = (v0 << 1)
v2 ~= v0 ~ (v0 >> 1) ~ (v0 >> 2) ~ (v0 >> 7)
v1 ~= (v0 << 63) ~ (v0 << 62) ~ (v0 << 57)
v3 ~= v1 ~ (v1 >> 1) ~ (v1 >> 2) ~ (v1 >> 7)
v2 ~= (v1 << 63) ~ (v1 << 62) ~ (v1 << 57)
y0 = v2
y1 = v3
}
endian.unchecked_put_u64be(dst[0:], y1)
endian.unchecked_put_u64be(dst[8:], y0)
}
+75
View File
@@ -0,0 +1,75 @@
package aes_ct64
import "base:intrinsics"
import "core:crypto/_aes"
import "core:encoding/endian"
load_blockx1 :: proc "contextless" (q: ^[8]u64, src: []byte) {
if len(src) != _aes.BLOCK_SIZE {
intrinsics.trap()
}
w: [4]u32 = ---
w[0] = endian.unchecked_get_u32le(src[0:])
w[1] = endian.unchecked_get_u32le(src[4:])
w[2] = endian.unchecked_get_u32le(src[8:])
w[3] = endian.unchecked_get_u32le(src[12:])
q[0], q[4] = interleave_in(w[:])
orthogonalize(q)
}
store_blockx1 :: proc "contextless" (dst: []byte, q: ^[8]u64) {
if len(dst) != _aes.BLOCK_SIZE {
intrinsics.trap()
}
orthogonalize(q)
w0, w1, w2, w3 := interleave_out(q[0], q[4])
endian.unchecked_put_u32le(dst[0:], w0)
endian.unchecked_put_u32le(dst[4:], w1)
endian.unchecked_put_u32le(dst[8:], w2)
endian.unchecked_put_u32le(dst[12:], w3)
}
load_blocks :: proc "contextless" (q: ^[8]u64, src: [][]byte) {
if n := len(src); n > STRIDE || n == 0 {
intrinsics.trap()
}
w: [4]u32 = ---
for s, i in src {
if len(s) != _aes.BLOCK_SIZE {
intrinsics.trap()
}
w[0] = endian.unchecked_get_u32le(s[0:])
w[1] = endian.unchecked_get_u32le(s[4:])
w[2] = endian.unchecked_get_u32le(s[8:])
w[3] = endian.unchecked_get_u32le(s[12:])
q[i], q[i + 4] = interleave_in(w[:])
}
orthogonalize(q)
}
store_blocks :: proc "contextless" (dst: [][]byte, q: ^[8]u64) {
if n := len(dst); n > STRIDE || n == 0 {
intrinsics.trap()
}
orthogonalize(q)
for d, i in dst {
// Allow storing [0,4] blocks.
if d == nil {
break
}
if len(d) != _aes.BLOCK_SIZE {
intrinsics.trap()
}
w0, w1, w2, w3 := interleave_out(q[i], q[i + 4])
endian.unchecked_put_u32le(d[0:], w0)
endian.unchecked_put_u32le(d[4:], w1)
endian.unchecked_put_u32le(d[8:], w2)
endian.unchecked_put_u32le(d[12:], w3)
}
}

Some files were not shown because too many files have changed in this diff Show More