Compare commits

...

562 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
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
Isaac Andrade 3557955f53 Align the dirent struct for linux 2024-08-29 20:17:39 -06: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
Isaac Andrade 45322023e3 Merge branch 'master' of github.com:odin-lang/Odin into posix-linux 2024-08-27 18:51:58 -06:00
Isaac Andrade 7d94810d01 Fix ino_t and ino_t32 types for POSIX linux. 2024-08-26 22:12:05 -06: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
Thomas la Cour 171d917b7e odin manifest file 2024-08-21 16:26:10 +02: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
693 changed files with 27118 additions and 7266 deletions
+15 -5
View File
@@ -36,6 +36,8 @@ jobs:
./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
@@ -64,6 +66,7 @@ jobs:
./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
@@ -128,6 +131,8 @@ jobs:
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'
@@ -203,6 +208,11 @@ jobs:
run: |
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat
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: |
@@ -257,16 +267,16 @@ jobs:
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"
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"
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"
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"
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"
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
+87 -59
View File
@@ -36,43 +36,55 @@ 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@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 18
echo "/usr/lib/llvm-18/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 -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'
@@ -89,24 +101,27 @@ jobs:
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'
@@ -123,30 +138,33 @@ jobs:
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@v4
- uses: actions/setup-python@v2
- uses: actions/setup-python@v5
with:
python-version: '3.8.x'
@@ -160,24 +178,33 @@ jobs:
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
@@ -187,9 +214,10 @@ jobs:
BUCKET: ${{ secrets.B2_BUCKET }}
DAYS_TO_KEEP: ${{ secrets.B2_DAYS_TO_KEEP }}
run: |
file linux_artifacts/dist.tar.gz
python3 ci/nightly.py artifact windows-amd64 windows_artifacts/
python3 ci/nightly.py artifact ubuntu-amd64 ubuntu_artifacts/dist.zip
python3 ci/nightly.py artifact macos-amd64 macos_artifacts/dist.zip
python3 ci/nightly.py artifact macos-arm64 macos_arm_artifacts/dist.zip
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
+3
View File
@@ -266,6 +266,9 @@ bin/
*.exe
*.obj
*.pdb
*.res
desktop.ini
Thumbs.db
# - Linux/MacOS
odin
+1 -1
View File
@@ -1,5 +1,5 @@
// This is purely for documentation
//+build ignore
#+build ignore
package intrinsics
// Package-Related
+1 -1
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"
+60 -27
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),
@@ -68,7 +101,7 @@ copy :: proc{copy_slice, copy_from_string}
// 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 {
@@ -82,7 +115,7 @@ unordered_remove :: proc(array: ^$D/[dynamic]$T, index: int, loc := #caller_loca
// 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 {
@@ -350,12 +383,23 @@ _make_dynamic_array_len_cap :: proc(array: ^Raw_Dynamic_Array, size_of_elem, ali
return
}
// `make_map` allocates and initializes a map. Like `new`, the first argument is a type, not a value.
// `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
@@ -392,6 +436,7 @@ make :: proc{
make_dynamic_array_len,
make_dynamic_array_len_cap,
make_map,
make_map_cap,
make_multi_pointer,
make_soa_slice,
@@ -602,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
}
@@ -620,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
}
@@ -643,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
}
@@ -668,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
@@ -682,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, #no_broadcast 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
@@ -699,7 +744,7 @@ assign_at_elems :: proc(array: ^$T/[dynamic]$E, index: int, #no_broadcast args:
@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
@@ -838,7 +883,7 @@ non_zero_resize_dynamic_array :: proc(array: ^$T/[dynamic]$E, #any_int length: i
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) {
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)
}
@@ -894,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
@@ -952,7 +985,7 @@ unimplemented :: proc(message := "", loc := #caller_location) -> ! {
@builtin
@(disabled=ODIN_DISABLE_ASSERT)
assert_contextless :: proc "contextless" (condition: bool, message := "", loc := #caller_location) {
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
+8 -8
View File
@@ -76,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
}
@@ -135,7 +135,7 @@ 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)
}
@@ -172,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
}
@@ -183,7 +183,7 @@ resize_soa :: proc(array: ^$T/#soa[dynamic]$E, length: int, loc := #caller_locat
}
@builtin
non_zero_resize_soa :: proc(array: ^$T/#soa[dynamic]$E, length: 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
}
@@ -194,12 +194,12 @@ non_zero_resize_soa :: proc(array: ^$T/#soa[dynamic]$E, length: int, loc := #cal
}
@builtin
reserve_soa :: proc(array: ^$T/#soa[dynamic]$E, capacity: int, loc := #caller_location) -> Allocator_Error {
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, capacity: int, loc := #caller_location) -> Allocator_Error {
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)
}
@@ -484,7 +484,7 @@ 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))
@@ -512,7 +512,7 @@ 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))
+3 -3
View File
@@ -1,6 +1,6 @@
//+private
//+build linux, darwin, freebsd, openbsd, netbsd, haiku
//+no-instrumentation
#+private
#+build linux, darwin, freebsd, openbsd, netbsd, haiku
#+no-instrumentation
package runtime
import "base:intrinsics"
+3 -3
View File
@@ -1,6 +1,6 @@
//+private
//+build wasm32, wasm64p32
//+no-instrumentation
#+private
#+build wasm32, wasm64p32
#+no-instrumentation
package runtime
import "base:intrinsics"
+3 -3
View File
@@ -1,6 +1,6 @@
//+private
//+build windows
//+no-instrumentation
#+private
#+build windows
#+no-instrumentation
package runtime
import "base:intrinsics"
+12 -10
View File
@@ -20,25 +20,27 @@ heap_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode,
//
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
force_copy := old_ptr != nil && a > align_of(rawptr)
force_copy := old_ptr != nil && alignment > align_of(rawptr)
if !force_copy && old_ptr != nil {
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
@@ -48,7 +50,7 @@ heap_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode,
([^]rawptr)(aligned_mem)[-1] = allocated_mem
if force_copy {
mem_copy_non_overlapping(aligned_mem, old_ptr, old_size)
mem_copy_non_overlapping(aligned_mem, old_ptr, min(old_size, size))
aligned_free(old_ptr)
}
+2 -2
View File
@@ -1,5 +1,5 @@
//+build orca
//+private
#+build orca
#+private
package runtime
foreign {
+2 -2
View File
@@ -1,5 +1,5 @@
//+build js, wasi, freestanding, essence
//+private
#+build js, wasi, freestanding, essence
#+private
package runtime
_heap_alloc :: proc "contextless" (size: int, zero_memory := true) -> rawptr {
+2 -2
View File
@@ -1,5 +1,5 @@
//+build linux, darwin, freebsd, openbsd, netbsd, haiku
//+private
#+build linux, darwin, freebsd, openbsd, netbsd, haiku
#+private
package runtime
when ODIN_OS == .Darwin {
+8 -5
View File
@@ -1,4 +1,4 @@
//+vet !cast
#+vet !cast
package runtime
import "base:intrinsics"
@@ -118,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
}
@@ -135,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
}
@@ -174,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
}
@@ -215,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)
}
+2 -2
View File
@@ -1,5 +1,5 @@
//+build freebsd, openbsd, netbsd
//+private
#+build freebsd, openbsd, netbsd
#+private
package runtime
foreign import libc "system:c"
+2 -2
View File
@@ -1,5 +1,5 @@
//+build darwin
//+private
#+build darwin
#+private
package runtime
import "base:intrinsics"
+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"
+1 -1
View File
@@ -1,4 +1,4 @@
//+private
#+private
package runtime
import "base:intrinsics"
+2 -2
View File
@@ -1,5 +1,5 @@
//+build orca
//+private
#+build orca
#+private
package runtime
import "base:intrinsics"
+2 -2
View File
@@ -1,5 +1,5 @@
//+build wasi
//+private
#+build wasi
#+private
package runtime
foreign import wasi "wasi_snapshot_preview1"
+2 -2
View File
@@ -1,5 +1,5 @@
//+build windows
//+private
#+build windows
#+private
package runtime
foreign import kernel32 "system:Kernel32.lib"
+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
+42 -20
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
}
@@ -54,18 +78,16 @@ udivti3 :: proc "c" (la, ha, lb, hb: u64) -> u128 {
}
@(link_name="__lshrti3", linkage="strong")
__lshrti3 :: proc "c" (la, ha: u64, b: u32) -> i128 {
bits :: size_of(u32)*8
__lshrti3 :: proc "c" (a: i128, b: u32) -> i128 {
bits :: 64
input, result: ti_int
input.lo = la
input.hi = ha
input.all = a
if b & bits != 0 {
result.hi = 0
result.lo = input.hi >> (b - bits)
} else if b == 0 {
return input.all
return a
} else {
result.hi = input.hi >> b
result.lo = (input.hi << (bits - b)) | (input.lo >> b)
+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"
+1 -1
View File
@@ -1,4 +1,4 @@
//+build wasm32, wasm64p32
#+build wasm32, wasm64p32
package runtime
import "base:intrinsics"
+36 -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,7 +45,19 @@ 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
@@ -53,18 +65,30 @@ rem See https://learn.microsoft.com/en-us/cpp/build/reference/utf-8-set-source-a
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
@@ -82,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!
@@ -93,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
@@ -102,19 +128,21 @@ 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 -vet -strict-style -- 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.
+1 -1
View File
@@ -130,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
+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
+24 -19
View File
@@ -2,7 +2,7 @@ import os
import sys
from zipfile import ZipFile, ZIP_DEFLATED
from b2sdk.v2 import InMemoryAccountInfo, B2Api
from datetime import datetime
from datetime import datetime, timezone
import json
UPLOAD_FOLDER = "nightly/"
@@ -22,7 +22,7 @@ def auth() -> bool:
pass # Not yet authenticated
err = b2_api.authorize_account("production", application_key_id, application_key)
return err == None
return err is None
def get_bucket():
if not auth(): sys.exit(1)
@@ -32,30 +32,35 @@ 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.utcnow().replace(hour=0, minute=0, second=0, microsecond=0)
destination_zip_name = "odin-{}-nightly+{}.zip".format(platform, now.strftime("%Y-%m-%d"))
now = datetime.now(timezone.utc).replace(hour=0, minute=0, second=0, microsecond=0)
source_zip_name = artifact
if not artifact.endswith(".zip"):
print(f"Creating archive {destination_zip_name} from {artifact} and uploading to {bucket_name}")
source_archive: str
destination_name = f'odin-{platform}-nightly+{now.strftime("%Y-%m-%d")}'
source_zip_name = destination_zip_name
with ZipFile(source_zip_name, mode='w', compression=ZIP_DEFLATED, compresslevel=9) as z:
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_zip_name):
print(f"Error: Newly created ZIP archive {source_zip_name} not found.")
return 1
if not os.path.exists(source_archive):
print(f"Error: archive {source_archive} not found.")
return 1
print("Uploading {} to {}".format(source_zip_name, UPLOAD_FOLDER + destination_zip_name))
print("Uploading {} to {}".format(source_archive, UPLOAD_FOLDER + destination_name))
bucket = get_bucket()
res = bucket.upload_local_file(
source_zip_name, # Local file to upload
"nightly/" + destination_zip_name, # B2 destination path
source_archive, # Local file to upload
"nightly/" + destination_name, # B2 destination path
)
return 0
@@ -65,8 +70,8 @@ def prune_artifacts():
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).replace(hour=0, minute=0, second=0, microsecond=0)
now = datetime.utcnow().replace(hour=0, minute=0, second=0, microsecond=0)
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):
@@ -100,7 +105,7 @@ def update_nightly_json():
'sizeInBytes': size,
})
now = datetime.utcnow().isoformat()
now = datetime.now(timezone.utc).isoformat()
nightly = json.dumps({
'last_updated' : now,
@@ -137,4 +142,4 @@ if __name__ == "__main__":
elif command == "json":
res = update_nightly_json()
sys.exit(res)
sys.exit(res)
+5 -7
View File
@@ -334,7 +334,7 @@ Inputs:
Returns:
- index: The index of the byte `c`, or -1 if it was not found.
*/
index_byte :: proc(s: []byte, c: byte) -> (index: int) #no_bounds_check {
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
@@ -469,18 +469,16 @@ Inputs:
Returns:
- index: The index of the byte `c`, or -1 if it was not found.
*/
last_index_byte :: proc(s: []byte, c: byte) -> int #no_bounds_check {
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 {
if i > 0 { // Handle s == nil.
for /**/; i >= 0; i -= 1 {
if s[i] == c {
return i
}
#reverse for ch, j in s {
if ch == c {
return j
}
}
return -1
+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>.
```
```
+8
View File
@@ -98,6 +98,14 @@ 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
+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
}
+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)
+24
View File
@@ -89,6 +89,30 @@ when ODIN_OS == .Linux {
}
}
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
+10
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
@@ -145,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 ---
@@ -160,6 +167,9 @@ 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)
}
+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 ---
+1 -1
View File
@@ -45,7 +45,7 @@ when ODIN_OS == .Windows {
}
}
when ODIN_OS == .Linux || ODIN_OS == .FreeBSD || ODIN_OS == .Darwin || ODIN_OS == .OpenBSD || ODIN_OS == .NetBSD || 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
+1 -1
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
+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 },
},
}
}
+2 -2
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"
@@ -308,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)
}
+1 -1
View File
@@ -1,4 +1,4 @@
//+vet !using-param
#+vet !using-param
package compress_zlib
/*
+97 -22
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,7 +209,7 @@ 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)
@@ -258,9 +259,13 @@ Inputs:
unsafe_unset :: proc(b: ^Bit_Array, bit: int) #no_bounds_check {
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:
@@ -272,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.
@@ -299,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:
@@ -321,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"
+9 -6
View File
@@ -1,22 +1,22 @@
/*
Package list implements an intrusive doubly-linked list.
An intrusive container requires a `Node` to be embedded in your own structure, like this:
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:
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:
Here is a full example.
Example:
package test
import "core:fmt"
@@ -42,5 +42,8 @@ Here is a full example:
value: string,
}
Output:
Hello
World
*/
package container_intrusive_list
+7 -3
View File
@@ -139,9 +139,13 @@ 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 {
+1 -1
View File
@@ -1,4 +1,4 @@
//+build amd64
#+build amd64
package aes_hw_intel
import "core:sys/info"
+1 -1
View File
@@ -20,7 +20,7 @@
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//+build amd64
#+build amd64
package aes_hw_intel
import "base:intrinsics"
@@ -20,7 +20,7 @@
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//+build amd64
#+build amd64
package aes_hw_intel
import "base:intrinsics"
@@ -51,7 +51,7 @@ _ROT_16: simd.u32x4 : {16, 16, 16, 16}
when ODIN_ENDIAN == .Big {
@(private = "file")
_increment_counter :: #force_inline proc "contextless" (ctx: ^Context) -> simd.u32x4 {
_increment_counter :: #force_inline proc "contextless" (ctx: ^_chacha20.Context) -> simd.u32x4 {
// In the Big Endian case, the low and high portions in the vector
// are flipped, so the 64-bit addition can't be done with a simple
// vector add.
@@ -1,4 +1,4 @@
//+build amd64
#+build amd64
package chacha20_simd256
import "base:intrinsics"
@@ -1,4 +1,4 @@
//+build !amd64
#+build !amd64
package chacha20_simd256
import "base:intrinsics"
+8 -6
View File
@@ -81,16 +81,18 @@ bytepad :: proc(ctx: ^Context, x_strings: [][]byte, w: int) {
// 2. while len(z) mod 8 ≠ 0:
// z = z || 0
// 3. while (len(z)/8) mod w 0:
// 3. while (len(z)/8) mod w != 0:
// z = z || 00000000
z_len := u128(z_hi) << 64 | u128(z_lo)
z_rem := int(z_len % u128(w))
pad := _PAD[:w - z_rem]
if z_rem != 0 {
pad := _PAD[:w - z_rem]
// We just add the padding to the state, instead of returning z.
//
// 4. return z.
update(ctx, pad)
// We just add the padding to the state, instead of returning z.
//
// 4. return z.
update(ctx, pad)
}
}
encode_string :: #force_inline proc(ctx: ^Context, s: []byte) -> (u64, u64) {
+35 -36
View File
@@ -10,49 +10,48 @@ algorithm.
WARNING: Reusing the same key + iv to seal (encrypt) multiple messages
results in catastrophic loss of security for most algorithms.
```odin
package aead_example
Example:
package aead_example
import "core:bytes"
import "core:crypto"
import "core:crypto/aead"
import "core:bytes"
import "core:crypto"
import "core:crypto/aead"
main :: proc() {
algo := aead.Algorithm.XCHACHA20POLY1305
main :: proc() {
algo := aead.Algorithm.XCHACHA20POLY1305
// The example added associated data, and plaintext.
aad_str := "Get your ass in gear boys."
pt_str := "They're immanetizing the Eschaton."
// The example added associated data, and plaintext.
aad_str := "Get your ass in gear boys."
pt_str := "They're immanetizing the Eschaton."
aad := transmute([]byte)aad_str
plaintext := transmute([]byte)pt_str
pt_len := len(plaintext)
aad := transmute([]byte)aad_str
plaintext := transmute([]byte)pt_str
pt_len := len(plaintext)
// Generate a random key for the purposes of illustration.
key := make([]byte, aead.KEY_SIZES[algo])
defer delete(key)
crypto.rand_bytes(key)
// Generate a random key for the purposes of illustration.
key := make([]byte, aead.KEY_SIZES[algo])
defer delete(key)
crypto.rand_bytes(key)
// `ciphertext || tag`, is a common way data is transmitted, so
// demonstrate that.
buf := make([]byte, pt_len + aead.TAG_SIZES[algo])
defer delete(buf)
ciphertext, tag := buf[:pt_len], buf[pt_len:]
// `ciphertext || tag`, is a common way data is transmitted, so
// demonstrate that.
buf := make([]byte, pt_len + aead.TAG_SIZES[algo])
defer delete(buf)
ciphertext, tag := buf[:pt_len], buf[pt_len:]
// Seal the AAD + Plaintext.
iv := make([]byte, aead.IV_SIZES[algo])
defer delete(iv)
crypto.rand_bytes(iv) // Random IVs are safe with XChaCha20-Poly1305.
aead.seal(algo, ciphertext, tag, key, iv, aad, plaintext)
// Seal the AAD + Plaintext.
iv := make([]byte, aead.IV_SIZES[algo])
defer delete(iv)
crypto.rand_bytes(iv) // Random IVs are safe with XChaCha20-Poly1305.
aead.seal(algo, ciphertext, tag, key, iv, aad, plaintext)
// Open the AAD + Ciphertext.
opened_pt := buf[:pt_len]
if ok := aead.open(algo, opened_pt, key, iv, aad, ciphertext, tag); !ok {
panic("aead example: failed to open")
// Open the AAD + Ciphertext.
opened_pt := buf[:pt_len]
if ok := aead.open(algo, opened_pt, key, iv, aad, ciphertext, tag); !ok {
panic("aead example: failed to open")
}
assert(bytes.equal(opened_pt, plaintext))
}
assert(bytes.equal(opened_pt, plaintext))
}
```
*/
package aead
package aead
+3 -3
View File
@@ -2,9 +2,9 @@
package aes implements the AES block cipher and some common modes.
See:
- https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.197-upd1.pdf
- https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38a.pdf
- https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf
- [[ https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.197-upd1.pdf ]]
- [[ https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38a.pdf ]]
- [[ https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf ]]
*/
package aes
+1 -1
View File
@@ -1,4 +1,4 @@
//+build amd64
#+build amd64
package aes
import "base:intrinsics"
+1 -1
View File
@@ -1,4 +1,4 @@
//+build amd64
#+build amd64
package aes
import "base:intrinsics"
+1 -1
View File
@@ -1,4 +1,4 @@
//+build amd64
#+build amd64
package aes
import "base:intrinsics"
+1 -1
View File
@@ -1,4 +1,4 @@
//+build !amd64
#+build !amd64
package aes
@(private = "file")
+1 -1
View File
@@ -1,4 +1,4 @@
//+build amd64
#+build amd64
package aes
import "core:crypto/_aes/hw_intel"
+2 -2
View File
@@ -2,8 +2,8 @@
package blake2b implements the BLAKE2b hash algorithm.
See:
- https://datatracker.ietf.org/doc/html/rfc7693
- https://www.blake2.net
- [[ https://datatracker.ietf.org/doc/html/rfc7693 ]]
- [[ https://www.blake2.net ]]
*/
package blake2b
+2 -2
View File
@@ -2,8 +2,8 @@
package blake2s implements the BLAKE2s hash algorithm.
See:
- https://datatracker.ietf.org/doc/html/rfc7693
- https://www.blake2.net/
- [[ https://datatracker.ietf.org/doc/html/rfc7693 ]]
- [[ https://www.blake2.net/ ]]
*/
package blake2s
+2 -2
View File
@@ -2,8 +2,8 @@
package chacha20 implements the ChaCha20 and XChaCha20 stream ciphers.
See:
- https://datatracker.ietf.org/doc/html/rfc8439
- https://datatracker.ietf.org/doc/draft-irtf-cfrg-xchacha/03/
- [[ https://datatracker.ietf.org/doc/html/rfc8439 ]]
- [[ https://datatracker.ietf.org/doc/draft-irtf-cfrg-xchacha/03/ ]]
*/
package chacha20
@@ -4,8 +4,8 @@ AEAD_XChaCha20_Poly1305 Authenticated Encryption with Additional Data
algorithms.
See:
- https://www.rfc-editor.org/rfc/rfc8439
- https://datatracker.ietf.org/doc/html/draft-arciszewski-xchacha-03
- [[ https://www.rfc-editor.org/rfc/rfc8439 ]]
- [[ https://datatracker.ietf.org/doc/html/draft-arciszewski-xchacha-03 ]]
*/
package chacha20poly1305
+3 -3
View File
@@ -2,9 +2,9 @@
package ed25519 implements the Ed25519 EdDSA signature algorithm.
See:
- https://datatracker.ietf.org/doc/html/rfc8032
- https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.186-5.pdf
- https://eprint.iacr.org/2020/1244.pdf
- [[ https://datatracker.ietf.org/doc/html/rfc8032 ]]
- [[ https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.186-5.pdf ]]
- [[ https://eprint.iacr.org/2020/1244.pdf ]]
*/
package ed25519
+28 -30
View File
@@ -17,46 +17,44 @@ accomplish common tasks.
A third optional boolean parameter controls if the file is streamed
(default), or or read at once.
```odin
package hash_example
Example:
package hash_example
import "core:crypto/hash"
import "core:crypto/hash"
main :: proc() {
input := "Feed the fire."
main :: proc() {
input := "Feed the fire."
// Compute the digest, using the high level API.
returned_digest := hash.hash(hash.Algorithm.SHA512_256, input)
defer delete(returned_digest)
// Compute the digest, using the high level API.
returned_digest := hash.hash(hash.Algorithm.SHA512_256, input)
defer delete(returned_digest)
// Variant that takes a destination buffer, instead of returning
// the digest.
digest := make([]byte, hash.DIGEST_SIZES[hash.Algorithm.BLAKE2B]) // @note: Destination buffer has to be at least as big as the digest size of the hash.
defer delete(digest)
hash.hash(hash.Algorithm.BLAKE2B, input, digest)
}
```
// Variant that takes a destination buffer, instead of returning
// the digest.
digest := make([]byte, hash.DIGEST_SIZES[hash.Algorithm.BLAKE2B]) // @note: Destination buffer has to be at least as big as the digest size of the hash.
defer delete(digest)
hash.hash(hash.Algorithm.BLAKE2B, input, digest)
}
A generic low level API is provided supporting the init/update/final interface
that is typical with cryptographic hash function implementations.
```odin
package hash_example
Example:
package hash_example
import "core:crypto/hash"
import "core:crypto/hash"
main :: proc() {
input := "Let the cinders burn."
main :: proc() {
input := "Let the cinders burn."
// Compute the digest, using the low level API.
ctx: hash.Context
digest := make([]byte, hash.DIGEST_SIZES[hash.Algorithm.SHA3_512])
defer delete(digest)
// Compute the digest, using the low level API.
ctx: hash.Context
digest := make([]byte, hash.DIGEST_SIZES[hash.Algorithm.SHA3_512])
defer delete(digest)
hash.init(&ctx, hash.Algorithm.SHA3_512)
hash.update(&ctx, transmute([]byte)input)
hash.final(&ctx, digest)
}
```
hash.init(&ctx, hash.Algorithm.SHA3_512)
hash.update(&ctx, transmute([]byte)input)
hash.final(&ctx, digest)
}
*/
package crypto_hash
package crypto_hash
+4 -38
View File
@@ -1,16 +1,15 @@
package crypto_hash
/*
Copyright 2021 zhibog
Made available under the BSD-3 license.
Copyright 2021 zhibog
Made available under the BSD-3 license.
List of contributors:
zhibog, dotbmp: Initial implementation.
List of contributors:
zhibog, dotbmp: Initial implementation.
*/
import "core:io"
import "core:mem"
import "core:os"
// hash_bytes will hash the given input and return the computed digest
// in a newly allocated slice.
@@ -87,36 +86,3 @@ hash_stream :: proc(
return dst, io.Error.None
}
// hash_file will read the file provided by the given handle and return the
// computed digest in a newly allocated slice.
hash_file :: proc(
algorithm: Algorithm,
hd: os.Handle,
load_at_once := false,
allocator := context.allocator,
) -> (
[]byte,
io.Error,
) {
if !load_at_once {
return hash_stream(algorithm, os.stream_from_handle(hd), allocator)
}
buf, ok := os.read_entire_file(hd, allocator)
if !ok {
return nil, io.Error.Unknown
}
defer delete(buf, allocator)
return hash_bytes(algorithm, buf, allocator), io.Error.None
}
hash :: proc {
hash_stream,
hash_file,
hash_bytes,
hash_string,
hash_bytes_to_buffer,
hash_string_to_buffer,
}
+10
View File
@@ -0,0 +1,10 @@
#+build freestanding
package crypto_hash
hash :: proc {
hash_stream,
hash_bytes,
hash_string,
hash_bytes_to_buffer,
hash_string_to_buffer,
}
+38
View File
@@ -0,0 +1,38 @@
#+build !freestanding
package crypto_hash
import "core:io"
import "core:os"
// hash_file will read the file provided by the given handle and return the
// computed digest in a newly allocated slice.
hash_file :: proc(
algorithm: Algorithm,
hd: os.Handle,
load_at_once := false,
allocator := context.allocator,
) -> (
[]byte,
io.Error,
) {
if !load_at_once {
return hash_stream(algorithm, os.stream_from_handle(hd), allocator)
}
buf, ok := os.read_entire_file(hd, allocator)
if !ok {
return nil, io.Error.Unknown
}
defer delete(buf, allocator)
return hash_bytes(algorithm, buf, allocator), io.Error.None
}
hash :: proc {
hash_stream,
hash_file,
hash_bytes,
hash_string,
hash_bytes_to_buffer,
hash_string_to_buffer,
}
+1 -1
View File
@@ -2,7 +2,7 @@
package hkdf implements the HKDF HMAC-based Extract-and-Expand Key
Derivation Function.
See: https://www.rfc-editor.org/rfc/rfc5869
See: [[ https://www.rfc-editor.org/rfc/rfc5869 ]]
*/
package hkdf
+1 -1
View File
@@ -2,7 +2,7 @@
package hmac implements the HMAC MAC algorithm.
See:
- https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.198-1.pdf
- [[ https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.198-1.pdf ]]
*/
package hmac
+1 -1
View File
@@ -2,7 +2,7 @@
package kmac implements the KMAC MAC algorithm.
See:
- https://nvlpubs.nist.gov/nistpubs/specialpublications/nist.sp.800-185.pdf
- [[ https://nvlpubs.nist.gov/nistpubs/specialpublications/nist.sp.800-185.pdf ]]
*/
package kmac
+2 -2
View File
@@ -5,8 +5,8 @@ WARNING: The MD5 algorithm is known to be insecure and should only be
used for interoperating with legacy applications.
See:
- https://eprint.iacr.org/2005/075
- https://datatracker.ietf.org/doc/html/rfc1321
- [[ https://eprint.iacr.org/2005/075 ]]
- [[ https://datatracker.ietf.org/doc/html/rfc1321 ]]
*/
package md5
+3 -3
View File
@@ -5,9 +5,9 @@ WARNING: The SHA1 algorithm is known to be insecure and should only be
used for interoperating with legacy applications.
See:
- https://eprint.iacr.org/2017/190
- https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf
- https://datatracker.ietf.org/doc/html/rfc3174
- [[ https://eprint.iacr.org/2017/190 ]]
- [[ https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf ]]
- [[ https://datatracker.ietf.org/doc/html/rfc3174 ]]
*/
package sha1
+1 -1
View File
@@ -1,7 +1,7 @@
/*
package pbkdf2 implements the PBKDF2 password-based key derivation function.
See: https://www.rfc-editor.org/rfc/rfc2898
See: [[ https://www.rfc-editor.org/rfc/rfc2898 ]]
*/
package pbkdf2
+1 -1
View File
@@ -2,7 +2,7 @@
package poly1305 implements the Poly1305 one-time MAC algorithm.
See:
- https://datatracker.ietf.org/doc/html/rfc8439
- [[ https://datatracker.ietf.org/doc/html/rfc8439 ]]
*/
package poly1305
+1 -1
View File
@@ -1,4 +1,4 @@
//+build freebsd, openbsd, netbsd
#+build freebsd, openbsd, netbsd
package crypto
foreign import libc "system:c"
+7 -7
View File
@@ -1,10 +1,10 @@
//+build !linux
//+build !windows
//+build !openbsd
//+build !freebsd
//+build !netbsd
//+build !darwin
//+build !js
#+build !linux
#+build !windows
#+build !openbsd
#+build !freebsd
#+build !netbsd
#+build !darwin
#+build !js
package crypto
HAS_RAND_BYTES :: false
+1 -1
View File
@@ -2,7 +2,7 @@
package ristretto255 implement the ristretto255 prime-order group.
See:
- https://www.rfc-editor.org/rfc/rfc9496
- [[ https://www.rfc-editor.org/rfc/rfc9496 ]]
*/
package ristretto255
+2 -2
View File
@@ -2,8 +2,8 @@
package sha2 implements the SHA2 hash algorithm family.
See:
- https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf
- https://datatracker.ietf.org/doc/html/rfc3874
- [[ https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf ]]
- [[ https://datatracker.ietf.org/doc/html/rfc3874 ]]
*/
package sha2
+1 -1
View File
@@ -6,7 +6,7 @@ pre-standardization Keccak algorithm is required, it can be found in
crypto/legacy/keccak.
See:
- https://nvlpubs.nist.gov/nistpubs/fips/nist.fips.202.pdf
- [[ https://nvlpubs.nist.gov/nistpubs/fips/nist.fips.202.pdf ]]
*/
package sha3
+2 -2
View File
@@ -4,8 +4,8 @@ package shake implements the SHAKE and cSHAKE XOF algorithm families.
The SHA3 hash algorithm can be found in the crypto/sha3.
See:
- https://nvlpubs.nist.gov/nistpubs/fips/nist.fips.202.pdf
- https://nvlpubs.nist.gov/nistpubs/specialpublications/nist.sp.800-185.pdf
- [[ https://nvlpubs.nist.gov/nistpubs/fips/nist.fips.202.pdf ]]
- [[ https://nvlpubs.nist.gov/nistpubs/specialpublications/nist.sp.800-185.pdf ]]
*/
package shake
+9 -4
View File
@@ -1,3 +1,12 @@
/*
package siphash Implements the SipHash hashing algorithm.
Use the specific procedures for a certain setup. The generic procedures will default to Siphash 2-4.
See:
- [[ https://github.com/veorq/SipHash ]]
- [[ https://www.aumasson.jp/siphash/siphash.pdf ]]
*/
package siphash
/*
@@ -6,10 +15,6 @@ package siphash
List of contributors:
zhibog: Initial implementation.
Implementation of the SipHash hashing algorithm, as defined at <https://github.com/veorq/SipHash> and <https://www.aumasson.jp/siphash/siphash.pdf>
Use the specific procedures for a certain setup. The generic procdedures will default to Siphash 2-4
*/
import "core:crypto"
+1 -1
View File
@@ -2,7 +2,7 @@
package sm3 implements the SM3 hash algorithm.
See:
- https://datatracker.ietf.org/doc/html/draft-sca-cfrg-sm3-02
- [[ https://datatracker.ietf.org/doc/html/draft-sca-cfrg-sm3-02 ]]
*/
package sm3
+1 -1
View File
@@ -2,7 +2,7 @@
package tuplehash implements the TupleHash and TupleHashXOF algorithms.
See:
- https://nvlpubs.nist.gov/nistpubs/specialpublications/nist.sp.800-185.pdf
- [[ https://nvlpubs.nist.gov/nistpubs/specialpublications/nist.sp.800-185.pdf ]]
*/
package tuplehash
+1 -1
View File
@@ -3,7 +3,7 @@ package x25519 implements the X25519 (aka curve25519) Elliptic-Curve
Diffie-Hellman key exchange protocol.
See:
- https://www.rfc-editor.org/rfc/rfc7748
- [[ https://www.rfc-editor.org/rfc/rfc7748 ]]
*/
package x25519
+2 -2
View File
@@ -1,5 +1,5 @@
//+private file
//+build linux, darwin
#+private file
#+build linux, darwin
package debug_trace
import "base:intrinsics"
+3 -1
View File
@@ -1,4 +1,6 @@
//+build !windows !linux !darwin
#+build !windows
#+build !linux
#+build !darwin
package debug_trace
import "base:runtime"
+2 -2
View File
@@ -1,5 +1,5 @@
//+private
//+build windows
#+private
#+build windows
package debug_trace
import "base:intrinsics"
+1 -2
View File
@@ -4,7 +4,6 @@ Package `core:dynlib` implements loading of shared libraries/DLLs and their symb
The behaviour of dynamically loaded libraries is specific to the target platform of the program.
For in depth detail on the underlying behaviour please refer to your target platform's documentation.
See `example` directory for an example library exporting 3 symbols and a host program loading them automatically
by defining a symbol table struct.
For a full example, see: [[ core/dynlib/example; https://github.com/odin-lang/Odin/tree/master/core/dynlib/example ]]
*/
package dynlib

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