Compare commits

...

2437 Commits

Author SHA1 Message Date
gingerBill b2cf0755f2 Add vendor to nightly.yml 2021-09-01 13:08:26 +01:00
gingerBill d399d2256b Change to [^][N] to just [^] 2021-08-31 20:39:32 +01:00
Jeroen van Rijn 27fd702692 Merge pull request #1111 from Kelimion/libtommath
Slim down LibTomMath compile.
2021-08-29 16:01:42 +02:00
gingerBill 5f29288254 Remove Syscall type 2021-08-29 15:00:35 +01:00
gingerBill 7c108dbf48 Update usage of syscall to use the intrinsics 2021-08-29 14:56:47 +01:00
Jeroen van Rijn 5c7cb393dc Slim down LibTomMath compile. 2021-08-29 15:54:56 +02:00
gingerBill 54b37573c9 Add intrinsics.syscall (for Linux and Darwin only) 2021-08-29 13:17:06 +01:00
gingerBill c3a64c2a59 Merge branch 'master' of https://github.com/odin-lang/Odin 2021-08-29 11:45:16 +01:00
gingerBill a5c31bbee0 Add map_insert which returns the pointer to inserted value 2021-08-29 11:45:11 +01:00
Jeroen van Rijn d6bd56da2c Merge pull request #1109 from Kelimion/makefile
Fix `Makefile`.
2021-08-28 22:41:06 +02:00
Jeroen van Rijn 17d31bfad6 Fix Makefile. 2021-08-28 22:40:38 +02:00
Jeroen van Rijn 89ffd40d70 Merge pull request #1108 from Kelimion/bigint
big: Add two more asymptotically optimal multiplication methods.
2021-08-28 18:19:55 +02:00
Jeroen van Rijn 737b4fde1c big: Add _private_int_mul_balance. 2021-08-28 18:17:57 +02:00
Jeroen van Rijn 2cfd6b7024 big: Add _private_int_mul_high. 2021-08-28 14:59:13 +02:00
gingerBill 713cd728ba Merge pull request #1107 from odin-lang/mv/libc-errors
Fix libc errors in Windows and add some tests.
2021-08-28 12:51:22 +01:00
vassvik f9bea5b791 Updated comment for Windows version of setjmp. 2021-08-28 13:41:14 +02:00
Jeroen van Rijn 586641d77f Merge pull request #1106 from Kelimion/bigint
big: Add `int_is_square` and Montgomery Reduction.
2021-08-28 13:36:36 +02:00
vassvik 8ca4286624 Add core:c/libc tests 2021-08-28 13:32:32 +02:00
vassvik 165118c641 Fix runtime crash for setjmp in Windows related to an hidden second argument not normally accessible needing to be set to 0. 2021-08-28 13:32:13 +02:00
Jeroen van Rijn 852643e6ba Add tests for `internal_int_is_square'. 2021-08-28 13:27:46 +02:00
vassvik 102d080a31 Fix core:c/libc Windows compilation errors by linking to the right libraries.
Fix some name typos and missing types in Windows.
Add explicit cast on MB_CUR_MAX
2021-08-28 13:27:41 +02:00
Jeroen van Rijn ec4cae4f04 big: Add int_is_square. 2021-08-27 16:41:16 +02:00
Jeroen van Rijn 4153898c55 big: Add Montgomery Reduction. 2021-08-27 16:41:16 +02:00
Jeroen van Rijn 33df335ec9 big: Add internal_int_montgomery_calc_normalization. 2021-08-27 16:41:16 +02:00
Jeroen van Rijn 893cc013b5 big: Add Montgomery reduction. 2021-08-27 16:41:16 +02:00
gingerBill b88e945268 ERROR_BLOCK() any usages of "Did you mean?" like behaviour whilst iterating across a scope entry map 2021-08-27 12:14:51 +01:00
gingerBill bf56e3ea8d Improve strings.index_any and strings.last_index_any 2021-08-27 12:07:57 +01:00
gingerBill 284acc37f9 Update SDL scancodes to have the same C enums equivalent global values 2021-08-27 11:38:29 +01:00
gingerBill 582559f7ac Correct did you mean logic and make thread-safe-er 2021-08-27 11:18:38 +01:00
gingerBill 53556d9bd2 Disable local mutex for the time being. 2021-08-26 23:16:57 +01:00
gingerBill da79124e5d Use local mutex for each AstFile.arena 2021-08-26 23:10:15 +01:00
gingerBill 2f34f1283a Make thread_join be more correct 2021-08-26 22:42:56 +01:00
gingerBill f973d271cf Add mutex around condition_broadcast 2021-08-26 22:28:09 +01:00
gingerBill 4625b25287 Wrap linux specific code for internal_thread_proc 2021-08-26 22:26:51 +01:00
gingerBill 8d8b3fd071 Add missing header 2021-08-26 22:24:26 +01:00
gingerBill a852c17614 Don't permit any signal delivery to threads on Linux 2021-08-26 22:20:10 +01:00
gingerBill b33bf3f704 Correct race condition and incorrect usage of condition_signal outside of a mutex lock 2021-08-26 22:17:51 +01:00
gingerBill 726788a483 Treat Type_Tuple closer to a Type_Struct in lb_type 2021-08-26 22:01:02 +01:00
gingerBill cdd3560702 Merge pull request #1103 from odin-lang/new-thread-pool
Improved Thread Pool implementation for the Compiler
2021-08-26 21:44:02 +01:00
gingerBill 6d49df1d87 Don't use the thread pool if worker count is 0 2021-08-26 21:40:54 +01:00
gingerBill ac191bd31f Simplify logic for -thread-count:1 2021-08-26 21:30:23 +01:00
gingerBill ad3a3547d6 Unify thread pool logic across the rest of the compiler, using a global thread pool 2021-08-26 21:22:30 +01:00
gingerBill aba14c43ac Fix typo 2021-08-26 17:57:29 +01:00
gingerBill 25c3fd48f0 Improved ThreadPool implementation 2021-08-26 17:56:28 +01:00
gingerBill e45aa68c14 Remove unneeded +1 for outstanding_task_count 2021-08-26 16:10:32 +01:00
gingerBill 6dfab34aca Merge pull request #1101 from odin-lang/compiler-allocator-improvements
Compiler Allocator Improvements
2021-08-26 16:06:37 +01:00
gingerBill d3d805ffb3 Fix typo 2021-08-26 15:58:34 +01:00
gingerBill 05b9724c85 Correct platform_virtual_memory_init on Unix 2021-08-26 15:55:09 +01:00
gingerBill 5053f0179c Implement virtual memory code for *nix and make generic 2021-08-26 15:53:08 +01:00
gingerBill 3e4d615983 Minor fixes 2021-08-26 15:41:32 +01:00
gingerBill aa8777ee47 Change the implementation of Arena to use virtual memory, and remove the old gbArena code 2021-08-26 15:38:34 +01:00
gingerBill 98dd59e412 Fix return value 2021-08-25 22:28:15 +01:00
gingerBill 7b2f6aaa1c Add [^] to GameControllerGetSensorData 2021-08-25 16:10:39 +01:00
gingerBill ad943f0189 Use [^] on PeepEvents 2021-08-25 15:50:35 +01:00
gingerBill 224496dca7 Merge branch 'master' of https://github.com/odin-lang/Odin 2021-08-25 15:21:14 +01:00
gingerBill 1ef59417ef Add gl_set_proc_address to both sdl2 and glfw as utility loaders for OpenGL 2021-08-25 15:21:06 +01:00
Jeroen van Rijn 0d5a160409 Add PortMidi to vendor:README.txt. 2021-08-25 13:54:39 +02:00
gingerBill 82facb387c Add vendor:portmidi 2021-08-25 12:46:18 +01:00
gingerBill da7a0df7a1 Simplify logic for parse_binary_expr 2021-08-25 11:43:02 +01:00
gingerBill fcbd94b924 Update enums 2021-08-24 20:05:01 +01:00
gingerBill 5bb3912001 Update licences for GLFW 2021-08-24 20:04:35 +01:00
gingerBill f4248b159d Add vendor:glfw 2021-08-24 20:00:24 +01:00
gingerBill 2e4edcc7e9 Merge pull request #1099 from Kelimion/vendor
vendor: Add `README.md` and clarify licensing.
2021-08-24 18:34:47 +01:00
gingerBill 0d3272d914 Remove ICD from generation 2021-08-24 18:33:35 +01:00
Jeroen van Rijn 50f3e77b43 vendor: Add README.md and clarify licensing. 2021-08-24 19:33:10 +02:00
gingerBill 964d91b855 Add vendor:vulkan 2021-08-24 17:08:03 +01:00
gingerBill bdac3ee120 Add gamecontrollerdb.txt to vendor:sdl
https://github.com/gabomdq/SDL_GameControllerDB
2021-08-24 14:04:27 +01:00
gingerBill b81c670597 Remove debug message 2021-08-24 11:08:41 +01:00
gingerBill 4489df2871 Make sync_t distinct 2021-08-24 00:22:11 +01:00
gingerBill 766c17a6a3 Change [^][1]T usage to [^]T 2021-08-24 00:20:51 +01:00
gingerBill 018f8a82d6 Correct indentation 2021-08-24 00:19:47 +01:00
gingerBill d5a0c004b6 More [^][N]T usage for UniformNuiv 2021-08-24 00:16:39 +01:00
gingerBill 0b6e45c9a2 More [^][N]T usage 2021-08-24 00:15:34 +01:00
gingerBill 5c41f64829 Improve signatures for [^][N*M]T like matrix parameters 2021-08-24 00:14:09 +01:00
gingerBill ad56cf0038 Change some usages of [^]T to ^[N]T where appropriate 2021-08-24 00:06:49 +01:00
gingerBill 58b5e92c2f Update more uses of [^]T types 2021-08-23 23:57:16 +01:00
gingerBill 0a0752db7c Correct int to i32 usage 2021-08-23 23:46:36 +01:00
gingerBill 49fbdd6188 Add more indirect command structs to the procedure calls 2021-08-23 23:45:00 +01:00
gingerBill 1048553e78 More corrections; Add DrawArraysIndirectCommand and DrawElementsIndirectCommand data structures 2021-08-23 23:02:19 +01:00
gingerBill 63282290db Remove dead procedure 2021-08-23 21:42:11 +01:00
gingerBill 7a1498e7dc Remove space prefix 2021-08-23 21:40:17 +01:00
gingerBill 0d3cbb8883 Add vendor:OpenGL
Based off a heavily modified version of: https://github.com/vassvik/odin-gl
2021-08-23 21:33:39 +01:00
gingerBill ce7698c20e Correct core library usage of the new mem.new behaviour 2021-08-23 19:29:01 +01:00
gingerBill 382ca20916 Correct procedure checking flag handling, and correct the (bodge) handle of unchecked procedure bodies 2021-08-23 19:24:53 +01:00
gingerBill fe2ad54f60 Fix bug in check_is_terminating 2021-08-23 17:42:54 +01:00
gingerBill b014879159 Add extra message to assert 2021-08-23 16:45:52 +01:00
gingerBill 81623861c0 Correct mem.clone_slice 2021-08-23 14:33:54 +01:00
gingerBill bd86993035 Remove the old inline and no_inline tokens 2021-08-23 12:37:42 +01:00
gingerBill 4ccf135892 Unify new/make the internal logic between runtime and mem 2021-08-23 12:35:29 +01:00
gingerBill cba0bd30f5 Add suggestions when trying to take the address the a value from a for/switch statement 2021-08-23 11:50:02 +01:00
gingerBill 276d4b8f0d Merge branch 'master' of https://github.com/odin-lang/Odin 2021-08-23 11:31:09 +01:00
gingerBill 7bdbaca938 Make SDL_image.Init return InitFlags 2021-08-23 11:31:00 +01:00
Jeroen van Rijn 7f34080b69 Merge pull request #1097 from nakst/master
Thread pool: create threads in thread_pool_wait
2021-08-23 11:17:54 +02:00
nakst 9397555c91 Thread pool: create threads in thread_pool_wait 2021-08-23 10:11:24 +01:00
gingerBill 7a00ef1879 Merge pull request #1096 from nakst/master
thread_pool.cpp: fix with 1 thread; gb.h: remove buggy /proc/cpuinfo code
2021-08-23 09:32:41 +01:00
nakst 35204e3cc5 thread_pool.cpp: fix with 1 thread; gb.h: remove buggy /proc/cpuinfo code 2021-08-23 09:18:18 +01:00
gingerBill daced956e3 Make ThreadPool use std::atomic and heap_allocator() 2021-08-22 23:01:01 +01:00
gingerBill 5a2d582a09 Merge pull request #1095 from nakst/master
Rewrite thread_pool.cpp
2021-08-22 22:55:31 +01:00
nakst b878be6f79 Thread pool fix on Win32 2021-08-22 21:24:56 +01:00
nakst 1f25f60a68 Rewrite thread_pool.cpp 2021-08-22 21:13:41 +01:00
gingerBill 2e921c88fb Add debug information for [^]T 2021-08-22 19:02:52 +01:00
gingerBill abaf8c127d Correct build.bat 2021-08-22 17:12:19 +01:00
gingerBill 0c5fa2cdd5 Fix build.bat 2021-08-22 17:09:40 +01:00
gingerBill 36cb1f868b Embed the SDL2 libraries into vendor:sdl2 2021-08-22 17:05:06 +01:00
gingerBill 037cc679c4 Keep -vet happy 2021-08-22 16:58:12 +01:00
gingerBill db6fad7396 Fix indexing code gen for multi-pointers 2021-08-22 16:55:57 +01:00
gingerBill 07bfb55658 Fix code gen for compare against nil for multi pointers 2021-08-22 16:53:26 +01:00
gingerBill 56078ee099 Merge branch 'master' of https://github.com/odin-lang/Odin 2021-08-22 16:49:48 +01:00
gingerBill ae4a378294 Merge pull request #1094 from graphitemaster/master
Project all of libc
2021-08-22 16:06:15 +01:00
Dale Weiler 791d7f764b cleanup 2021-08-22 10:05:27 -04:00
Dale Weiler b39a4f3e3b Merge branch 'master' of https://github.com/odin-lang/Odin 2021-08-22 09:49:20 -04:00
Dale Weiler 389b50f735 libc projection 2021-08-22 09:48:34 -04:00
gingerBill 2f6e566a32 Remove the deprecated fmt.print*_err procedures 2021-08-22 12:57:08 +01:00
gingerBill d5bad374d9 Remove deprecated procedure slice_ptr_to_bytes 2021-08-22 12:55:57 +01:00
gingerBill 445ed9be2b Use multi-pointers when appropriate 2021-08-22 12:54:04 +01:00
gingerBill 8694a0f68a Update signature_parameter_similar_enough for multi pointers 2021-08-22 12:31:03 +01:00
gingerBill d3fee9d761 Merge pull request #1093 from odin-lang/multi-pointers
Multi Pointers `[^]T`
2021-08-22 11:50:47 +01:00
gingerBill 36a6805b7c Update doc format for multi-pointers 2021-08-22 11:46:26 +01:00
gingerBill 19bf12aa09 Update odin/ast for multi pointers 2021-08-22 11:46:12 +01:00
gingerBill 0decdaed1a Merge branch 'master' into multi-pointers 2021-08-22 11:28:44 +01:00
gingerBill 93b5befe45 Improve error handling for missing semicolon separators in a for loop 2021-08-22 11:27:24 +01:00
gingerBill d72f4a8a79 Correct Multi Pointer Type handling in expressions 2021-08-22 00:59:42 +01:00
gingerBill 91247a8fe1 Fix multi pointers for parapoly 2021-08-21 23:16:30 +01:00
gingerBill 18a0fa02c5 Add multi pointers to core 2021-08-21 23:16:14 +01:00
gingerBill 932f330a51 Add comparisons to LLVM backend for multi pointers 2021-08-21 23:12:15 +01:00
gingerBill 6a77fc4cdd Add multi-pointer types [^]T 2021-08-21 23:10:21 +01:00
gingerBill 01a888fced Update import path 2021-08-21 14:09:48 +01:00
gingerBill f0437a4242 Enforce core:builtin and core:intrinsics for imports 2021-08-21 13:44:16 +01:00
gingerBill 32bdad322a Improve parsing for or_return in core:odin/parser 2021-08-21 13:43:38 +01:00
gingerBill bf130087e7 Change to strings.clone_from_cstring_bounded 2021-08-21 13:43:03 +01:00
gingerBill 38e038a1ab Add strings.clone_from and strings.clone_from_nul_terminated 2021-08-21 13:42:06 +01:00
gingerBill 6504607adf Merge branch 'master' of https://github.com/odin-lang/Odin 2021-08-21 13:32:12 +01:00
gingerBill c8378fce95 Add library collection vendor 2021-08-21 13:32:07 +01:00
Jeroen van Rijn 1aeaec8d5c Merge pull request #1091 from Kelimion/win11
os: Add Windows 11 detection.
2021-08-21 14:12:26 +02:00
gingerBill 2aaf927beb Improve error message for Cannot assign value if they have the same name but are from different packages 2021-08-21 13:09:23 +01:00
Jeroen van Rijn bb86b0f526 os: Add Windows 11 detection. 2021-08-21 14:08:22 +02:00
gingerBill 2f5edebefa Rename mem.reinterpret to mem.reinterpret_copy 2021-08-20 10:19:30 +01:00
gingerBill b5cdb331b0 Add mem.reinterpret 2021-08-20 10:18:34 +01:00
gingerBill fa4f3aa7ad Correct atomic usage 2021-08-19 17:51:19 +01:00
gingerBill a90fe7211c Make global_entity_id atomic 2021-08-19 17:44:26 +01:00
gingerBill ac6cc5191a Make ThreadPool.is_running atomic 2021-08-19 17:43:15 +01:00
gingerBill 38841dd46e Fix race condition from add_entity_use due to Entity.identifier 2021-08-19 17:38:18 +01:00
gingerBill e722af7f61 Remove unneeded disabled warnings from build.bat 2021-08-19 15:43:51 +01:00
gingerBill df372dbd5b Migrate and remove more from gb.h 2021-08-19 15:38:21 +01:00
gingerBill 5c4d95d539 Move more of gb.h's Synchronization code into common.cpp 2021-08-19 15:19:36 +01:00
gingerBill 9ae4de2ab8 Remove unused code from gb.h (which means it is heavily modified now) 2021-08-19 15:09:39 +01:00
gingerBill 7845769d4b Remove unused code 2021-08-19 15:03:10 +01:00
gingerBill 33239324b8 Improve the C++ to be more correct for clang on Windows, still requiring the same disabled warnings as on *nix 2021-08-19 14:44:53 +01:00
gingerBill 82a74ebfa9 Merge branch 'master' of https://github.com/odin-lang/Odin 2021-08-19 11:40:32 +01:00
gingerBill 35026000bb Fix deadlock caused by typo 2021-08-19 11:40:26 +01:00
Jeroen van Rijn 55cf3d26bf Merge pull request #1090 from Kelimion/bigint
big: Update license to BSD-3.
2021-08-19 12:13:39 +02:00
Jeroen van Rijn 23d29be4d8 big: Update license to BSD-3. 2021-08-19 12:12:59 +02:00
Jeroen van Rijn 1ad0743a52 big: Nicely align test suite results. 2021-08-19 12:12:59 +02:00
gingerBill 54af47a138 Remove useless code 2021-08-18 23:38:06 +01:00
gingerBill b84ee3ab8f Fix odin test not executing any tests 2021-08-18 23:33:27 +01:00
gingerBill e023b96737 Remove json import from demo 2021-08-18 22:33:18 +01:00
gingerBill 3fde4616e0 Correct mutex usage for path_to_fullpath; make ThreadPool use BlockingMutex 2021-08-18 21:21:30 +01:00
Mikkel Hjortshøj 4812006eb8 Update ci.yml 2021-08-18 22:09:44 +02:00
gingerBill 740995df3d Remove attribute parameter for pthread_mutex_init 2021-08-18 21:07:06 +01:00
gingerBill aa5c3da414 Make BlockingMutex non-recursive on *nix systems 2021-08-18 20:57:03 +01:00
gingerBill d419d81841 Remove unused code 2021-08-18 20:48:26 +01:00
gingerBill 08942714a2 Make Arena allocate virtual memory directory; make it use a BlockingMutex 2021-08-18 20:46:10 +01:00
gingerBill 3c443babb2 Extra sanity check around static 2021-08-18 20:32:54 +01:00
gingerBill 326e5cd046 Merge branch 'master' of https://github.com/odin-lang/Odin 2021-08-18 20:31:39 +01:00
gingerBill 79e98b71d3 Remove dead code, and add an extra mutex 2021-08-18 20:31:34 +01:00
Jeroen van Rijn 96605f700b Merge pull request #1089 from Kelimion/bigint
big: Enable Toom again.
2021-08-18 15:36:45 +02:00
Jeroen van Rijn 38b5e01343 Merge branch 'master' into bigint 2021-08-18 15:35:49 +02:00
Jeroen van Rijn 06cde91ba3 big: Enable Toom again. 2021-08-18 15:35:01 +02:00
Jeroen van Rijn 3891d6a483 Merge pull request #1088 from Kelimion/bigint
big: Fix signed multiplication for some inputs.
2021-08-18 15:32:49 +02:00
Jeroen van Rijn 5fd7a5f32a big: Fix signed multiplication for some inputs. 2021-08-18 15:24:43 +02:00
gingerBill a01c946c20 Add mutex to Scope lookups and insertions 2021-08-18 11:17:14 +01:00
gingerBill 84b0da44db Merge branch 'master' of https://github.com/odin-lang/Odin 2021-08-17 19:54:17 +01:00
gingerBill cdb3a5205c Add mutex for add_type_and_value 2021-08-17 19:54:09 +01:00
Jeroen van Rijn eae98feb7a Merge pull request #1086 from Kelimion/bigint
big: Temporarily disable Toom.
2021-08-16 22:19:10 +02:00
Jeroen van Rijn 3af078e941 Merge branch 'master' into bigint 2021-08-16 22:16:03 +02:00
Jeroen van Rijn 48c1f0ab59 big: Disable Toom for a moment. 2021-08-16 22:13:54 +02:00
Jeroen van Rijn 19386814b3 Merge pull request #1085 from Kelimion/bigint
Add `_private_int_mul_toom` + `_private_int_mul_karatsuba`.
2021-08-16 21:29:40 +02:00
Jeroen van Rijn 706e58c1c7 big: Add _private_int_mul_toom`. 2021-08-16 21:17:21 +02:00
gingerBill 9ab94650c8 Allow + in import paths 2021-08-16 18:21:58 +01:00
gingerBill fce86ff3d5 Correct struct tag bug 2021-08-16 18:17:26 +01:00
gingerBill 0051cd12e2 Make flags atomic for Entity and Type 2021-08-16 16:30:49 +01:00
gingerBill df159dbae7 Add some missing files to sync2 for linux and darwin 2021-08-16 15:48:54 +01:00
gingerBill 94d298755a Fix race condition when adding a dependency 2021-08-16 15:33:26 +01:00
Jeroen van Rijn 8b49bbb0fc big: Add _private_mul_karatsuba. 2021-08-16 16:10:10 +02:00
gingerBill 5f072591ba Merge pull request #1082 from odin-lang/or_else-or_return-operator
`or_else` and `or_return` operators
2021-08-16 12:03:43 +01:00
gingerBill e3fef2dade Improve parsing for or_return; allow #force_inline foo() or_return; 2021-08-16 11:58:50 +01:00
gingerBill 4c306a6f99 Correct or_return logic for debug printing and expression is not used checking 2021-08-16 11:08:37 +01:00
gingerBill 0996cc82a7 Keep -vet happy 2021-08-15 23:17:12 +01:00
gingerBill f293d7c997 Update package encoding/json for or_return 2021-08-15 23:11:15 +01:00
gingerBill b2097604d5 Add clone_ast for or_else and or_return 2021-08-15 23:10:52 +01:00
gingerBill 4e1c9b71f4 Update core:odin/* for or_else and or_return 2021-08-15 19:05:55 +01:00
gingerBill 3e2788afdc Add extra example to or_return_operator 2021-08-15 18:51:20 +01:00
gingerBill 1a7f508dd9 Improve comment 2021-08-15 18:44:50 +01:00
gingerBill dc8cfcf92a Fix typos and improve clarity of or_return_operator 2021-08-15 18:36:34 +01:00
gingerBill ac08d37ca0 Add or_return_operator to examples/demo 2021-08-15 18:29:49 +01:00
gingerBill 4035fec784 Add more uses of or_return 2021-08-15 18:13:56 +01:00
gingerBill b071a07c86 Replace uses of err != nil with or_return where appropriate 2021-08-15 17:56:24 +01:00
gingerBill c27b8a71fd Replace err != nil with or_return where appropriate 2021-08-15 17:52:10 +01:00
gingerBill b8661e0ae0 Update semi-colon insertion rules for or_return 2021-08-15 17:16:37 +01:00
gingerBill 21cbac755e Make or_else and or_return operators (binary and suffix respectively) 2021-08-15 17:14:35 +01:00
gingerBill a3a20f09e2 or_return built-in procedure 2021-08-15 16:55:30 +01:00
gingerBill d62f189d72 Remove some dead code 2021-08-15 15:09:47 +01:00
gingerBill 84713b58e0 Improve error handling for field list prefixes 2021-08-15 13:29:44 +01:00
gingerBill 294c8426e6 Minor clean up of parse_field_prefixes 2021-08-15 13:18:06 +01:00
gingerBill 7bbc9a4634 Add #any_int directive to replace auto_cast uses on parameters. 2021-08-15 12:56:59 +01:00
gingerBill 1cd3b693ae Update LICENSE 2021-08-15 12:12:48 +01:00
gingerBill d1b9b06614 Add core:math/big to examples/all 2021-08-15 11:14:51 +01:00
gingerBill 19aefa6a40 Add assignment statement to #no_bounds_check etc rules. Correct os_linux.odin usage. 2021-08-15 11:14:34 +01:00
gingerBill effecf8595 Fix typo 2021-08-15 11:13:59 +01:00
gingerBill d5e3f72a0b Define where #bounds_check/#no_bounds_check can be applied 2021-08-15 11:09:41 +01:00
gingerBill 9fb486b2ad Merge branch 'master' of https://github.com/odin-lang/Odin 2021-08-15 11:08:35 +01:00
gingerBill d70fa4329c Move #no_bounds_check to before return 2021-08-15 11:08:28 +01:00
Jeroen van Rijn 3f29a0d6dd Merge pull request #1078 from Kelimion/bigint
Add recursive division.
2021-08-14 15:58:27 +02:00
Jeroen van Rijn 0db86a0638 big: Add workaround for DLL globals bug. 2021-08-14 13:51:17 +02:00
Jeroen van Rijn dc02566a84 big: Add _private_int_div_recursive. 2021-08-13 23:45:00 +02:00
gingerBill 0e84e06756 Fix lower and upper values for a bit_set[Enum] type. 2021-08-13 14:17:27 +01:00
gingerBill e6b2df4b2b Add extra error message check to lb_big_int_to_llvm 2021-08-13 14:16:53 +01:00
Jeroen van Rijn 37be8d4091 big: Add internal_invmod. 2021-08-13 14:55:53 +02:00
gingerBill a3930cb470 Improve fmt._user_formatters logic 2021-08-13 12:44:55 +01:00
gingerBill ad402726f1 Fix #1026 2021-08-13 12:21:14 +01:00
gingerBill 8ff9f2e44f Fix #1077 2021-08-13 11:49:52 +01:00
gingerBill 799a56bbcb Fix column in tokenizer (due to removed line) 2021-08-13 10:50:05 +01:00
gingerBill fbbd43a6d8 Merge branch 'master' of https://github.com/odin-lang/Odin 2021-08-13 10:45:35 +01:00
gingerBill 367bf0c7ae Fix #1076 2021-08-13 10:45:29 +01:00
Jeroen van Rijn f72a0de074 big: Add inverse mod. 2021-08-13 01:41:33 +02:00
Jeroen van Rijn 07baae04c9 Merge pull request #1075 from Kelimion/bigint
Add `core:math/big`, an arbitrary precision library.
2021-08-11 21:43:54 +02:00
Jeroen van Rijn eb22a49b02 big: Add int_from_bytes_*. 2021-08-11 20:59:54 +02:00
Jeroen van Rijn ee24f2dd37 big: Improve int_to_bytes_*. 2021-08-11 20:59:54 +02:00
Jeroen van Rijn 12f9b6db63 big: Add int_to_bytes_{big, little} + Python compatible variants. 2021-08-11 20:59:54 +02:00
Jeroen van Rijn 851780b8f4 big: Add arguments and usage to test.py. 2021-08-11 20:59:54 +02:00
Jeroen van Rijn 5f34ff9f9f big: Add _private_int_sqr_toom. 2021-08-11 20:59:54 +02:00
Jeroen van Rijn 2b274fefbb big: Add _private_int_sqr_karatsuba. 2021-08-11 20:59:54 +02:00
Jeroen van Rijn 6c681b258c big: Add _private_int_sqr_comba. 2021-08-11 20:59:54 +02:00
Jeroen van Rijn 1f91a2fe65 big: Finish refactor. 2021-08-11 20:59:54 +02:00
Jeroen van Rijn 19ff27788c big: Refactoring. 2021-08-11 20:59:54 +02:00
Jeroen van Rijn 1ebb0bd9d6 big: More refactoring. 2021-08-11 20:59:54 +02:00
Jeroen van Rijn d505a05d36 big: More refactoring. 2021-08-11 20:59:53 +02:00
Jeroen van Rijn 07dca737f0 big: More refactoring. 2021-08-11 20:59:53 +02:00
Jeroen van Rijn 6d34a8344a big: Refactor helpers. 2021-08-11 20:59:53 +02:00
Jeroen van Rijn 40b7b9ecdf big: Refactor exponents and such. 2021-08-11 20:59:53 +02:00
Jeroen van Rijn 53bf66ce1e big: Prettify internal_cmp_digit. 2021-08-11 20:59:53 +02:00
Jeroen van Rijn fd95f50c56 big: Split up int_is_* comparison tests. 2021-08-11 20:59:53 +02:00
Jeroen van Rijn 777e17d80f big: Improve tunables. 2021-08-11 20:59:53 +02:00
Jeroen van Rijn d4a03acbc3 big: Split up int_mod_bits (res = val % (1 << bits)) 2021-08-11 20:59:53 +02:00
Jeroen van Rijn c3db24f834 big: Split up gcd + lcm. 2021-08-11 20:59:53 +02:00
Jeroen van Rijn 62dcccd7ef big: Move division internals. 2021-08-11 20:59:53 +02:00
Jeroen van Rijn e288a563e1 big: Move _mul private functions. 2021-08-11 20:59:53 +02:00
Jeroen van Rijn 6298226238 big: Switch choose over to internal implementations. 2021-08-11 20:59:53 +02:00
Jeroen van Rijn 9321616c80 big: Split more into public and internal. 2021-08-11 20:59:53 +02:00
Jeroen van Rijn 9890e7cfeb big: Improved zero_unused helper. 2021-08-11 20:59:53 +02:00
Jeroen van Rijn 4be48973ad big: Squashed shl1 bug when a larger dest was reused for a smaller result. 2021-08-11 20:59:53 +02:00
Jeroen van Rijn f8442e0524 big: Split up mul into internal and public parts. 2021-08-11 20:59:53 +02:00
Jeroen van Rijn 9858989b1c big: Split up add and sub into public and internal parts. 2021-08-11 20:59:53 +02:00
Jeroen van Rijn 511057ca36 big: Improve timing code. 2021-08-11 20:59:53 +02:00
Jeroen van Rijn 35d8976de4 bit: Optimized int_bitfield_extract. 2021-08-11 20:59:53 +02:00
Jeroen van Rijn 463003e86a bit: Improved bitfield extraction. 2021-08-11 20:59:53 +02:00
Jeroen van Rijn 85a2a8815e big: Some more work on constants. 2021-08-11 20:59:53 +02:00
Jeroen van Rijn 47397a6a48 Add faster divison. 2021-08-11 20:59:53 +02:00
Jeroen van Rijn 2323ca1622 big: Add MATH_BIG_FORCE_64/32_BIT flags. 2021-08-11 20:59:52 +02:00
Jeroen van Rijn fc0a92f8ac big: Add constants. 2021-08-11 20:59:52 +02:00
Jeroen van Rijn 97d80d03f9 big: Error.None -> nil 2021-08-11 20:59:52 +02:00
Jeroen van Rijn 627872db97 big: Timed factorial. 2021-08-11 20:59:52 +02:00
Jeroen van Rijn a27612ec6a Add _mul_comba path. 2021-08-11 20:59:52 +02:00
Jeroen van Rijn 491e4ecc74 big: Add binary split factorial. 2021-08-11 20:59:52 +02:00
Jeroen van Rijn cd0ce7b76e big: Add choose. 2021-08-11 20:59:52 +02:00
Jeroen van Rijn 320387c4ee big: Add gcd_lcm fast path in wrapper. 2021-08-11 20:59:52 +02:00
Jeroen van Rijn 6424a5a8dd big: Refactored gcm and lcm to use a common function. 2021-08-11 20:59:52 +02:00
Jeroen van Rijn 06f5a6c785 big: Special case gcd(0,0) + lcm(0,0). 2021-08-11 20:59:52 +02:00
Jeroen van Rijn 8b1d8c8453 big: Add lcm and its test. 2021-08-11 20:59:52 +02:00
Jeroen van Rijn 0028cb0258 big: Test gcd. 2021-08-11 20:59:52 +02:00
Jeroen van Rijn b15ee059ad big: Add gcd. 2021-08-11 20:59:52 +02:00
Jeroen van Rijn 50feeaa285 big: Add test for factorial. 2021-08-11 20:59:52 +02:00
Jeroen van Rijn e80ac18324 big: Add factorial, have tests use hex strings. 2021-08-11 20:59:52 +02:00
Jeroen van Rijn db0196abc7 big: Test root_n. 2021-08-11 20:59:52 +02:00
Jeroen van Rijn 149c7b88df big: Fix sqrt, div, add with certain inputs. 2021-08-11 20:59:52 +02:00
Jeroen van Rijn 7afd1b15a8 big: test_pow for larger ints. 2021-08-11 20:59:52 +02:00
Jeroen van Rijn f12672727d big: Add test_pow and some more switches. 2021-08-11 20:59:52 +02:00
Jeroen van Rijn 2179cc2bc7 big: Improved test driver. 2021-08-11 20:59:52 +02:00
Jeroen van Rijn 961adfedd9 big: Test negative inputs as well. 2021-08-11 20:59:52 +02:00
Jeroen van Rijn 385b9c9922 big: Add tests for log. 2021-08-11 20:59:52 +02:00
Jeroen van Rijn 922df6a438 big: Add more exhaustive tests. 2021-08-11 20:59:52 +02:00
Jeroen van Rijn c1a001c331 big: Add randomized testing. 2021-08-11 20:59:52 +02:00
Jeroen van Rijn 13fab36639 big: Fix mul. 2021-08-11 20:59:52 +02:00
Jeroen van Rijn 708389a7ee big: Improve test driver. 2021-08-11 20:59:51 +02:00
Jeroen van Rijn fb6c9af1ae big: Improve tests. 2021-08-11 20:59:51 +02:00
Jeroen van Rijn 85aa4dd670 big: Start test suite. 2021-08-11 20:59:51 +02:00
Jeroen van Rijn 74258a170a big: fix itoa base PoT other than 16. 2021-08-11 20:59:51 +02:00
Jeroen van Rijn 2fbff25a18 big: Improve int_bitfield_extract. 2021-08-11 20:59:51 +02:00
Jeroen van Rijn 9c150381bf big: Add rand. 2021-08-11 20:59:51 +02:00
Jeroen van Rijn 531c4936dd big: Add root_n. 2021-08-11 20:59:51 +02:00
Jeroen van Rijn 2aae1016ab big: Add sqrt. 2021-08-11 20:59:51 +02:00
Jeroen van Rijn 9c2468ecf7 big: Add atoi. 2021-08-11 20:59:51 +02:00
Jeroen van Rijn 0a431eef19 big: Add another way to estimate radix size. 2021-08-11 20:59:51 +02:00
Jeroen van Rijn 9646d1f2b8 big: Add submod, mulmod, sqrmod. 2021-08-11 20:59:51 +02:00
Jeroen van Rijn 5f7aeb3045 big: Add mod and addmod. 2021-08-11 20:59:51 +02:00
Jeroen van Rijn 1ebaa9fb3b big: itoa now works for arbitrary radixes. 2021-08-11 20:59:51 +02:00
Jeroen van Rijn c2255c6c19 big: Add div. 2021-08-11 20:59:51 +02:00
Jeroen van Rijn 2884fa5506 big: add div by 3. 2021-08-11 20:59:51 +02:00
Jeroen van Rijn 31c94bd7f8 big: Finish log, fix sqr. 2021-08-11 20:59:51 +02:00
Jeroen van Rijn 5f63e3952e big: Correct pow bugs from the original. 2021-08-11 20:59:51 +02:00
Jeroen van Rijn d953e40fb3 big: Add pow. 2021-08-11 20:59:51 +02:00
Jeroen van Rijn c3a4d7dda2 big: Fast square method. 2021-08-11 20:59:51 +02:00
Jeroen van Rijn b4a29844e9 big: Add multiplication. 2021-08-11 20:59:51 +02:00
Jeroen van Rijn 0254057f1b big: Add swap. 2021-08-11 20:59:51 +02:00
Jeroen van Rijn f34ba44bf8 big: Add shl, shr and shrmod. 2021-08-11 20:59:51 +02:00
Jeroen van Rijn d4d863c4db big: Add mod_power_of_two. 2021-08-11 20:59:51 +02:00
Jeroen van Rijn 78c0877994 big: Add get(a, type) and get_float. 2021-08-11 20:59:51 +02:00
Jeroen van Rijn 1d0b37c1d8 big: add shl1, shr1. 2021-08-11 20:59:51 +02:00
Jeroen van Rijn 7648f2e655 big: Finish big ZII refactor. 2021-08-11 20:59:50 +02:00
Jeroen van Rijn d9efa6c8b5 big: More ZII refactoring. 2021-08-11 20:59:50 +02:00
Jeroen van Rijn 2e372b33a3 big: More ZII refactoring. 2021-08-11 20:59:50 +02:00
Jeroen van Rijn 687c211a58 big: ZII. 2021-08-11 20:59:50 +02:00
Jeroen van Rijn 4eadd0867d big: Continuing to refactor. 2021-08-11 20:59:50 +02:00
Jeroen van Rijn 9dba17cf87 bigint: refactor to big.Int instead of bigint.Int. 2021-08-11 20:59:50 +02:00
Jeroen van Rijn baef0c291d bigint: Added some more helpers. 2021-08-11 20:59:50 +02:00
Jeroen van Rijn cccd290834 bigint: Add is_power_of_two helper. 2021-08-11 20:59:50 +02:00
Jeroen van Rijn 5af85aed3d bigint: itoa support for arbitrary precision if is_power_of_two(radix) 2021-08-11 20:59:50 +02:00
Jeroen van Rijn e600e5947b bigint: remove unnecessary boundary checks. 2021-08-11 20:59:50 +02:00
Jeroen van Rijn d7ae611f76 bigint: itoa now writes backwards directly, no need to reverse after. 2021-08-11 20:59:50 +02:00
Jeroen van Rijn 04a83eb9f7 bigint: pass size to itoa_raw. 2021-08-11 20:59:50 +02:00
Jeroen van Rijn 341e8a3c99 bigint: itoa works for numbers <= 120 bits. 2021-08-11 20:59:50 +02:00
Jeroen van Rijn e3d8ac559d bigint: Fast paths for radix code. 2021-08-11 20:59:50 +02:00
Jeroen van Rijn 767948ab46 bigint: log_n for bases that fit within one DIGIT or are a power of two. 2021-08-11 20:59:50 +02:00
Jeroen van Rijn dbcd8da733 bigint: Working on itoa and logn. 2021-08-11 20:59:50 +02:00
Jeroen van Rijn 905d5459a9 bigint: Add count_bits and more prep. 2021-08-11 20:59:50 +02:00
Jeroen van Rijn dfd5a993a2 bigint: Prepare for multiplication. 2021-08-11 20:59:50 +02:00
Jeroen van Rijn daceaa65f5 bigint: Add substractin with immediate. 2021-08-11 20:59:50 +02:00
Jeroen van Rijn c2c07f07db Add single DIGIT addition. 2021-08-11 20:59:50 +02:00
Jeroen van Rijn c5cbd3260a bigint: Add prototypes for immediate add+sub. 2021-08-11 20:59:50 +02:00
Jeroen van Rijn d57e1be89f bigint: Improve add. 2021-08-11 20:59:50 +02:00
Jeroen van Rijn 18dda6ff9d Start of core:math/bigint
We have:
- `init` to create a new `Int`
- `init(from_integer)` to create a new `Int` and set it to `from_integer`.
- `set(Int, from_integer)` to set an `Int` to `from_integer`
- `add(dest, a, b)` to add `a` and `b` into `dest`.
- `sub(dest, a, b)` to subtract `b` from `a` and put the result in `dest`.

And a few helper functions, like:
- `is_zero`, `is_negative`, ...
- `grow`, `shrink`, `clear`, `zero`
2021-08-11 20:59:50 +02:00
gingerBill 7afc367275 Update examples/all/all_main.odin 2021-08-11 19:11:00 +01:00
gingerBill c465171b45 Fix #1061 2021-08-09 21:41:19 +01:00
gingerBill 02f22a0b3f Correct DllMain behaviour 2021-08-09 21:23:24 +01:00
gingerBill 193fd0eecb Correct and improve type inference for swizzling expressions 2021-08-09 20:13:58 +01:00
gingerBill 01f431b01f Unify semantics of the built-in swizzle procedure with the selector expression semantics e.g. .xyz 2021-08-09 19:37:58 +01:00
gingerBill aebfa4b28e Allow len and cap to return a uint if a type hint is uint to aid people wanting to use unsigned integers 2021-08-09 17:39:38 +01:00
gingerBill a3abe991a4 Add package core:encoding/hxa 2021-08-09 16:26:51 +01:00
gingerBill e793f92e67 Improve parsing handling for the { return } cases 2021-08-09 13:01:47 +01:00
gingerBill 042f376626 Minor code changes to Map/StringMap 2021-08-09 13:01:26 +01:00
gingerBill d99ed692ba Add utility procedures: io.read_ptr; io.write_ptr; io.read_ptr_at; io.write_ptr_at 2021-08-09 12:33:21 +01:00
gingerBill 4d00c2b800 Allocator_Error.Mode_Not_Implemented; Minor improvement to map runtime procedures 2021-08-08 14:29:45 +01:00
gingerBill a5605e94b1 Simplify Map and StringMap in the compiler to reuse the hashes' array data if possible. 2021-08-08 13:56:40 +01:00
gingerBill 9cfe20cfb4 Correct error message for add_import_dependency_node 2021-08-08 13:13:31 +01:00
gingerBill db3501f61b [Breaking] Change the layout json.Value to be a union rather than a struct of a json.Pos and the union 2021-08-08 12:59:35 +01:00
gingerBill 48538aa792 Remove package core:encoding/cel 2021-08-08 12:50:38 +01:00
gingerBill 5fd64f48ee Minor procedure rename 2021-08-08 12:48:44 +01:00
gingerBill a3b7126875 Simplify init_tokenizer_with_data 2021-08-08 12:47:45 +01:00
gingerBill 5756c8a7c6 Merge branch 'master' of https://github.com/odin-lang/Odin 2021-08-08 12:45:33 +01:00
gingerBill cdd0061869 Prefer ..= over .. 2021-08-08 12:45:27 +01:00
Mikkel Hjortshøj e6adfd8054 Update create_nightly_json.py 2021-08-08 11:29:56 +02:00
Jeroen van Rijn 6d59223efd Merge pull request #1072 from Kelimion/cel_fix_ise
CEL: Fix by changing `using enum` to ISE.
2021-08-08 02:21:04 +02:00
Jeroen van Rijn ebd034fff9 CEL: Fix ISE. 2021-08-08 02:19:32 +02:00
gingerBill 000bda8419 Reduce superfluous error messages for return statements expecting not-1 return values 2021-08-07 16:29:00 +01:00
gingerBill 423b842347 Fix typo 2021-08-07 15:07:29 +01:00
gingerBill 16eeae36d7 Inline heap_allocator resize logic on *nix platforms 2021-08-07 15:05:46 +01:00
gingerBill 5453e92bcb Minor test on array_set_capacity 2021-08-07 14:44:48 +01:00
gingerBill c16c9535d9 Reorder ci.yml from run check version to version check run 2021-08-07 14:40:54 +01:00
gingerBill 662c7b1e71 Minor clean-up 2021-08-07 14:39:26 +01:00
gingerBill 571170fd30 Improve and simplify the memory layout of MPMCQueue 2021-08-07 14:25:48 +01:00
gingerBill 911c428dac Remove dead code in queue.cpp; clean up initialization code 2021-08-07 13:54:08 +01:00
gingerBill 40822be595 Reorganize llvm_backend.cpp into separate files for easier maintenance 2021-08-07 12:01:48 +01:00
gingerBill f5e51a29b5 Fix #1070 2021-08-07 11:23:40 +01:00
gingerBill beaad719ad Reallow using on enum declarations temporarily but with a warning. 2021-08-05 17:51:45 +01:00
gingerBill 0d257c61cd Disallow using on an enum declaration. 2021-08-05 17:46:42 +01:00
gingerBill dd8fa1d690 Prefer ..= over .. 2021-08-04 00:36:10 +01:00
gingerBill af6df7d7c9 Improve error cases in core:odin/parser 2021-08-04 00:23:31 +01:00
gingerBill 57a17a708b Improve core:odin/parser 2021-08-04 00:10:41 +01:00
gingerBill 1f79082921 Remove dead comments 2021-08-04 00:10:05 +01:00
gingerBill afff9478c8 Make core:odin/tokenizer be consistent with the compiler's version 2021-08-03 23:27:26 +01:00
gingerBill b352b42afc Remove old comment 2021-08-03 16:31:50 +01:00
gingerBill c3e4509d17 Improve error message when using a comma rather than a semicolon in a bit_set 2021-08-03 15:46:14 +01:00
gingerBill 664be28941 Fix typo 2021-08-03 15:45:32 +01:00
gingerBill d7e970ac32 Add extra debugf message for generate missing procedure 2021-08-03 14:36:15 +01:00
gingerBill 810dcfc602 Remove debug gb_printf_err and replace with debugf 2021-08-03 14:30:32 +01:00
gingerBill 14645b147f Reorganize missing_procedures_to_check generation code 2021-08-03 14:17:39 +01:00
gingerBill b036cc9013 Add missing_procedures_to_check to lbModule 2021-08-03 14:13:38 +01:00
gingerBill 3a8ac92995 Add sanity check in lb_create_procedure 2021-08-03 13:49:01 +01:00
gingerBill 67bedcba4b Reorganize stages in checker 2021-08-03 13:41:28 +01:00
gingerBill 4987ef89f1 Reorganize some of the checker stages 2021-08-03 13:40:47 +01:00
gingerBill 545b345eea Remove optimizations in tokenizer and default to older code (same logic) (optimize later) 2021-08-03 13:33:01 +01:00
gingerBill 3e961af5f1 Sort files by name in packages 2021-08-02 22:55:22 +01:00
gingerBill 9e6e769141 Add sanity checks to checker 2021-08-02 18:32:17 +01:00
Jeroen van Rijn c0f746a251 Merge pull request #1065 from Kelimion/string_cut
Add `strings.cut`, which returns a substring.
2021-08-02 18:09:59 +02:00
gingerBill ccbdf086ff Add @(warning=<string>) 2021-08-02 16:58:50 +01:00
Jeroen van Rijn d260ca6738 string.cut uses context.allocator by default. 2021-08-02 17:58:42 +02:00
gingerBill b0e64ca7e8 Prepare tokenizer for optimizations 2021-08-02 16:47:32 +01:00
gingerBill 7f3d4cb504 Remove the literal conversion logic to the parser from the tokenizer 2021-08-02 00:53:45 +01:00
gingerBill 97be36d18a Replace line with column_minus_one in Tokenizer; Remove dead code 2021-08-02 00:26:54 +01:00
gingerBill be76da2c90 Begin optimizing tokenizer; Replace gb_utf8_decode with utf8_decode (CC but easier to change later) 2021-08-01 23:56:17 +01:00
gingerBill b1a8357f50 Clean up a bit of the tokenizer code so that the semicolon insertion rules are in one place 2021-08-01 22:41:00 +01:00
Jeroen van Rijn 0dc900ba34 Add strings.cut, which returns a substring. 2021-08-01 19:41:20 +02:00
gingerBill 700624119b Give begin_error_block its own recursive mutex 2021-07-29 12:35:11 +01:00
gingerBill af32aba7fc Modify MPMCQueue behaviour to use i32 over isize; Correct cache line padding within MPMCQueue 2021-07-28 00:59:30 +01:00
gingerBill 541c79c01a Add mutex for @(builtin) attributes 2021-07-28 00:27:16 +01:00
gingerBill 358226468d EXPERIMENT: Set DEFAULT_TO_THREADED_CHECKER on all platforms 2021-07-27 23:55:55 +01:00
gingerBill d1e5f34f76 Use DEFAULT_TO_THREADED_CHECKER 2021-07-27 23:55:19 +01:00
gingerBill 416dd93bf7 Add accidentally removed call 2021-07-27 23:39:35 +01:00
gingerBill 7c80577160 Correct race condition on untyped expr info map logic on global evaluations 2021-07-27 23:37:55 +01:00
gingerBill a5d6fda433 Define which mutexes are blocking and recursive explicitly 2021-07-27 23:14:01 +01:00
gingerBill 4bc3796f9b Short circuit check_with_workers logic on worker_count == 0 2021-07-27 23:00:51 +01:00
gingerBill 5e12f5a746 Unify threading logic 2021-07-27 22:55:32 +01:00
gingerBill 4080ba4026 Remove global semaphore and place in CheckerInfo 2021-07-27 21:42:43 +01:00
gingerBill e17593be94 Remove dead mutex 2021-07-27 21:14:06 +01:00
gingerBill 44aa69748c Correct logic for check_import_entities - collect file decls 2021-07-27 21:13:03 +01:00
gingerBill 9cd5ea59dd Big simplification and improvement of the entity collection system, reducing unneeded steps for packages 2021-07-27 20:45:50 +01:00
gingerBill 116e98b378 Improve default scope size 2021-07-27 10:59:39 +01:00
gingerBill ae25787f48 Fix syntax error for a missing package name 2021-07-26 11:43:17 +01:00
gingerBill 08dc829b70 Manually short circuit in lb_build_if_stmt for constant conditions 2021-07-26 10:59:07 +01:00
gingerBill 3ac674cf02 Fix typo 2021-07-25 13:12:09 +01:00
gingerBill 6cd06ab95f Minor fix 2021-07-25 13:07:31 +01:00
gingerBill 99080d41f3 INTERNAL USE ONLY: //+lazy build flag 2021-07-25 13:06:09 +01:00
gingerBill 92f3567ee6 Default to using a threaded checker on Windows; Add -no-threaded-checker for Windows 2021-07-24 18:00:19 +01:00
Jeroen van Rijn 481fc8a5b6 Merge pull request #1060 from Kelimion/win_sys
Allow `core:sys/windows` to build on Windows only
2021-07-15 12:15:10 +02:00
Jeroen van Rijn 5dfff51a40 Allow core:sys/windows to build on Windows only 2021-07-15 12:13:57 +02:00
gingerBill 2938ec028f Remove dead code 2021-07-15 00:37:59 +01:00
gingerBill 981b9fb7a8 Remove need for scope mutex, make Scope singly linked list tree with atomic pointers 2021-07-14 23:49:35 +01:00
gingerBill 10f4d8df32 Override libtommath allocation procedures 2021-07-14 23:36:23 +01:00
gingerBill e15858e2be Remove random load balancing in thread_proc_body 2021-07-14 22:53:02 +01:00
gingerBill 6d8302825c Add Greed Work Stealing and Random Load Balancing for check_procedure_bodies 2021-07-14 01:13:39 +01:00
gingerBill fae8bf96dd Muilthread check_collect_entities_all 2021-07-14 00:46:03 +01:00
gingerBill bc59dc6389 Remove duplicate code 2021-07-14 00:36:48 +01:00
gingerBill bd8e2f82be Replace non-recursive mutexes with BlockingMutex; Minor improves to initialization improves 2021-07-14 00:34:34 +01:00
gingerBill 69027b6840 Remove dead mutexes 2021-07-13 23:10:12 +01:00
gingerBill 7a9b7af078 Reduce mutex usage and convert things to queues from arrays 2021-07-13 23:09:24 +01:00
gingerBill 31c7afce1b Minor code clean up to reuse the ProcInfo consumption code 2021-07-13 21:19:13 +01:00
gingerBill bab1873416 Require throughput pass results with -show-more-timings -show-debug-messages rather than just the former flag 2021-07-13 18:39:11 +01:00
gingerBill 5e2950e9fb Move asserts around 2021-07-13 18:35:23 +01:00
gingerBill 74c019f271 Correct lb_big_int_to_llvm 2021-07-13 18:32:53 +01:00
gingerBill a745bb8f42 Add extra message to assert 2021-07-13 18:21:53 +01:00
gingerBill da9870c77d Do manual byte swapping for endianness in lb_big_int_to_llvm 2021-07-13 18:15:47 +01:00
gingerBill 698eeaf7c3 Add (internal flag) -show-debug-messages 2021-07-13 17:40:06 +01:00
gingerBill bd954d9990 Minor code reorganization 2021-07-13 17:28:39 +01:00
gingerBill 4ded42a33b Split up cycle check and adding type info timings 2021-07-13 17:24:20 +01:00
gingerBill 1877965ac3 Short on -threaded-checker 2021-07-13 17:04:08 +01:00
gingerBill cec2309504 Big improvement to the -threaded-checker code, unifying the logic and simplify behaviour 2021-07-13 16:58:40 +01:00
gingerBill ed5a4afc8c Temporarily disable -threaded-checker; Restructure the untyped-expr-info system to be much more thread-friendly 2021-07-13 15:54:56 +01:00
gingerBill f29b51efdd Fix gb_shuffle 2021-07-13 13:09:55 +01:00
gingerBill 3930a32b0c enum Addressing_Mode : u8; 2021-07-12 16:45:54 +01:00
gingerBill 76707e1d2f Add sanity casts for 32/64 bit correctness 2021-07-12 11:03:12 +01:00
gingerBill ff2e5c3efe Simplify big_int_not for negative inputs 2021-07-11 17:43:56 +01:00
gingerBill 3600b2e209 Merge pull request #1057 from odin-lang/new-big-int-library-integration
New Big Int Library Integration
2021-07-11 17:20:57 +01:00
gingerBill eb36a0f3b1 Remove dead file 2021-07-11 16:35:04 +01:00
gingerBill b397254696 Rename libtommath.c to libtommath.cpp 2021-07-11 16:33:58 +01:00
gingerBill 9a37d3b6e5 Add -Wno-unused-value 2021-07-11 16:29:51 +01:00
gingerBill 51c4a19234 Fix tab and space issue in Makefile
FUCK DO I HATE Makefile whitespace sensitivity between spaces and tabs
2021-07-11 16:26:21 +01:00
gingerBill a1a1668dcf Update build.bat and Makefile 2021-07-11 16:23:25 +01:00
gingerBill e308098f18 Add libtommath.c 2021-07-11 16:19:20 +01:00
gingerBill 63b572a0ab Clean up big int to LLVM integer code 2021-07-11 16:18:30 +01:00
gingerBill e90e7d4af9 Change mp_clear calls to big_int_dealloc 2021-07-11 16:10:04 +01:00
gingerBill 460e14e586 Change the compiler's big integer library to use libTomMath
This now replaces Bill's crappy big int implementation
2021-07-11 16:08:16 +01:00
gingerBill ebcabb8a27 Add sanity conversion check for integer to quaternion 2021-07-11 00:51:56 +01:00
gingerBill 257b749e9d Minimize mutex usage in update_expr_type 2021-07-11 00:21:31 +01:00
gingerBill d9e6ade030 Add experimental support for a threaded semantic checker to -threaded-checker 2021-07-10 23:51:37 +01:00
gingerBill 690374d4de Fix typo 2021-07-10 23:07:42 +01:00
gingerBill adb25d9d19 Convert constant tag to the correct type for LLVMAddCase 2021-07-10 22:29:52 +01:00
gingerBill 2949e4b0c7 Fix floattidf typo 2021-07-10 22:23:22 +01:00
gingerBill 6de0181c75 Minor improvements to Map and StringMap 2021-07-10 21:51:39 +01:00
gingerBill 8a6b743d2a Simplify thread_pool_wait_to_process 2021-07-10 21:50:19 +01:00
gingerBill ed8a6f872d Move things around for sanity checking for multithread preparation 2021-07-10 21:29:49 +01:00
gingerBill 0a61d4bf2b Use next_pow2_isize 2021-07-10 19:57:54 +01:00
gingerBill 332461c0d2 Add prototypes for next_pow2 2021-07-10 19:52:26 +01:00
gingerBill d8abe7fc4d Implement MPMCQueue for procedure body checking
This is preparation for basic multithreading in the semantic checker
2021-07-10 19:50:34 +01:00
gingerBill ec9667ef5a Remove debug code 2021-07-10 17:11:54 +01:00
gingerBill 9f7154a039 Prepare for multithreading the semantic checker by giving mutexes to variables of contention
NOTE(bill): I know this is dodgy, but I want to make sure it is correct logic before improve those data structures
2021-07-10 15:14:25 +01:00
gingerBill 4a932616fc Improve CheckerContext usage 2021-07-10 13:02:13 +01:00
gingerBill 73fe36f19c Remove dead variable 2021-07-10 11:59:41 +01:00
gingerBill 4167ae95ae Fix #1050 2021-07-10 11:48:28 +01:00
gingerBill 13c3c5be95 Fix #1028 2021-07-10 11:46:22 +01:00
gingerBill 3afec0bcbe Fix #1054 2021-07-10 11:42:21 +01:00
gingerBill 8b1bfc80fb Fix #1051 2021-07-10 11:27:38 +01:00
gingerBill 3662275119 Allow x in ptr_to_map_or_bit_set 2021-07-10 11:18:19 +01:00
gingerBill 141573c18c Enable Damerau-Levenshtein 2021-07-10 11:09:24 +01:00
gingerBill e692efbe09 Improve update expr type semantics for ternary expressions 2021-07-10 11:08:51 +01:00
gingerBill f6c1a5bf6e Merge branch 'master' of https://github.com/odin-lang/Odin 2021-07-09 15:33:30 +01:00
gingerBill 6afc28f827 Use builtin.min and builtin.max in package slice 2021-07-09 15:33:25 +01:00
gingerBill df6681ad4e Merge pull request #1055 from streof/fix-typos-container-package
Fix typos container package
2021-07-09 13:27:03 +01:00
streof 114efbc57c Fix error: Cannot assign to a procedure parameter 2021-07-09 14:03:49 +02:00
streof 2c71494ad1 Fix error: Undeclared name: p 2021-07-09 13:54:27 +02:00
gingerBill 35230b1a11 Add "Suggestion: Did you mean?" for selector expression typos 2021-07-08 23:15:07 +01:00
gingerBill 7acbf8b7b9 Add slice.min and add slice.max 2021-07-08 11:23:07 +01:00
gingerBill f7413ca974 Fix thread_unix.odin 2021-07-05 16:36:07 +01:00
gingerBill 9b3a0251ca Use or_else in the core library when it makes sense 2021-07-05 16:33:01 +01:00
gingerBill 3b9ca8535f Fix comments 2021-07-05 16:26:11 +01:00
gingerBill a98eee145d Remove try; Replace try x else y with or_else(x, y) 2021-07-05 16:23:13 +01:00
gingerBill c6b9b3b9a4 Fix try parsing for expression statements 2021-07-04 22:52:12 +01:00
gingerBill a4be1a5e4c delete_key now returns the deleted key and deleted value (if found) 2021-07-04 18:52:47 +01:00
gingerBill ee908c00de Add documentation for the overview of package fmt 2021-07-04 18:21:41 +01:00
gingerBill 46264032aa Improve error messages for try expressions 2021-07-04 12:50:44 +01:00
gingerBill 4b831dbddd Try try and or_else built-in procedures with operators try and try else 2021-07-04 12:37:21 +01:00
gingerBill a01d6dcea7 Refactor return logic to be more reusable with lb_emit_try 2021-07-04 01:57:38 +01:00
gingerBill 01a15f78e6 Simplify lb_emit_try return logic 2021-07-04 01:50:37 +01:00
gingerBill 5f71c41582 Fix lb_emit_try 2021-07-04 01:47:43 +01:00
gingerBill e8f2c5a48a [Experimental] Add 'try' and `or_else' built-in procedures 2021-07-04 01:38:43 +01:00
gingerBill 1c76577918 Add slice.sort_by_cmp Ordering based sorting algorithms 2021-07-03 15:16:44 +01:00
gingerBill 4285b58aaa Add #no_bounds_check to linalg procedures 2021-07-03 14:38:41 +01:00
gingerBill 9cc366de97 Be more consistent with runtime intrinsics usage 2021-07-03 14:38:15 +01:00
gingerBill 212d294b84 Deprecate sort.slice and sort.reverse_slice 2021-07-03 14:37:55 +01:00
gingerBill d6125f05d4 Correct does_field_type_allow_using 2021-06-29 12:35:15 +01:00
gingerBill ad22eda87c Improve linalg.transpose type determination for square matrices 2021-06-28 13:23:28 +01:00
gingerBill 8d31ba492d Fix #1042 2021-06-28 11:32:23 +01:00
gingerBill 8f611b3399 Fix #1043 2021-06-28 11:21:03 +01:00
gingerBill 618f858930 Merge branch 'master' of https://github.com/odin-lang/Odin 2021-06-28 11:06:00 +01:00
gingerBill 185277a2b6 Fix swizzling of pointers to arrays 2021-06-28 11:05:52 +01:00
Jeroen van Rijn 8e5c3141f6 Merge pull request #1047 from Kelimion/zlib_optimize
ZLIB: Fix edge case where initial buffer < 258 bytes.
2021-06-27 18:49:09 +02:00
Jeroen van Rijn 87aaa9c3f0 ZLIB: Fix edge case where initial buffer < 258 bytes. 2021-06-27 18:44:36 +02:00
Jeroen van Rijn 095605b7db Merge pull request #1046 from Kelimion/zlib_optimize
ZLIB: Optimize
2021-06-27 16:54:15 +02:00
Jeroen van Rijn 6836b501af Merge branch 'master' into zlib_optimize 2021-06-27 16:50:27 +02:00
Jeroen van Rijn d949d5a046 ZLIB: cleanup. 2021-06-27 16:48:12 +02:00
Jeroen van Rijn 064516bf0b PNG: Inform inflate about expected output size for extra speed. 2021-06-27 13:57:12 +02:00
Jeroen van Rijn eaf88bcc4d PNG: Let PNG use the new compress I/O routines. 2021-06-27 13:51:52 +02:00
gingerBill 76d3bab955 Modify scope finding rules for distinct types in lb_debug_type 2021-06-27 12:21:11 +01:00
Jeroen van Rijn 02f9668185 ZLIB: Split up input from stream and memory into own code paths. 2021-06-27 13:19:24 +02:00
gingerBill abda75feee Add bufio.Lookahead_Reader 2021-06-26 23:45:45 +01:00
gingerBill a779cb2798 Fix #1044 2021-06-26 23:31:04 +01:00
gingerBill 5e42675b42 Allow alternative syntax for offset_of: offset_of(Type, field), offset_of(value.field) 2021-06-26 23:19:46 +01:00
gingerBill 11c565e199 Fix semicolon insertion rule for --- 2021-06-26 22:47:12 +01:00
Jeroen van Rijn 4689a6b341 Refactor compress.Context struct. 2021-06-26 22:25:55 +02:00
Jeroen van Rijn 30a5808460 ZLIB: Moar faster. 2021-06-26 20:40:39 +02:00
Jeroen van Rijn 8ba1c9a6cd ZLIB: Remove superfluous code. 2021-06-26 17:44:12 +02:00
Jeroen van Rijn 65b78b1aa9 So far, so good. 2021-06-26 15:11:15 +02:00
Jeroen van Rijn c369719362 Merge branch 'master' into zlib_optimize 2021-06-26 13:40:22 +02:00
Jeroen van Rijn 40a12cca53 ZLIB: If output size is known, reserve that much. 2021-06-26 13:17:14 +02:00
gingerBill d8940f5fd7 Support compound literals for struct #raw_union types 2021-06-26 12:08:14 +01:00
gingerBill 74dee82dbf Fix compiler errors 2021-06-25 14:33:42 +01:00
gingerBill f1cf724bd4 Add bufio.Scanner 2021-06-25 14:31:35 +01:00
gingerBill fc809d3fad Merge branch 'master' of https://github.com/odin-lang/Odin 2021-06-24 19:41:36 +01:00
gingerBill 42d135aade Change logic for comparison against nil for array-like data types (compare the pointer rather than the length/capacity) 2021-06-24 19:39:51 +01:00
Jeroen van Rijn ab12ca69af Merge pull request #1040 from Kelimion/zlib_optimize
Adler32 speedup.
2021-06-24 19:15:22 +02:00
Jeroen van Rijn 17748f18b9 Adler32 speedup. 2021-06-24 19:06:39 +02:00
gingerBill 3803bdff5f Allow bufio.Reader and bufio.Writer to have a configurable max_consecutive_empty_(reads|writes) field 2021-06-24 15:56:58 +01:00
gingerBill 0a94a67190 Merge branch 'master' of https://github.com/odin-lang/Odin 2021-06-24 15:55:50 +01:00
gingerBill 8dcb14fbc2 Add helper procedures for strings.Reader creation 2021-06-24 15:55:42 +01:00
Jeroen van Rijn f62f40e508 Merge pull request #1039 from Kelimion/zlib_optimize
ZLIB: Another 10%+ faster.
2021-06-24 15:02:02 +02:00
Jeroen van Rijn 980aa37bee ZLIB: Another 10%+ faster. 2021-06-24 14:56:28 +02:00
gingerBill 1e9cc058a0 Update hash.crc32 to use slicing-by-8 algorithm to improve throughput by ~3.5x 2021-06-24 00:03:59 +01:00
Jeroen van Rijn 824efc82b9 Merge pull request #1036 from Kelimion/zlib_optimize
ZLIB: More faster.
2021-06-23 22:25:02 +02:00
Jeroen van Rijn 1cfe226686 ZLIB: More faster. 2021-06-23 22:18:17 +02:00
Jeroen van Rijn ea0ce7bd2c Merge pull request #1035 from Kelimion/zlib_optimize
Zlib optimize
2021-06-23 20:15:32 +02:00
Jeroen van Rijn 342adb627d All reads now skip stream if in memory. 2021-06-23 16:32:48 +02:00
Jeroen van Rijn a70635d2f6 Most reads now go through buffer for zlib. 2021-06-23 16:32:48 +02:00
Jeroen van Rijn 5cb16c4cd1 All reads now go through read_slice. 2021-06-23 16:32:48 +02:00
Jeroen van Rijn 538004ba5f Introduce read_slice, make read_u8 use it. 2021-06-23 16:32:48 +02:00
Jeroen van Rijn 8663c64e47 Refactor ZLIB structs. 2021-06-23 16:32:47 +02:00
gingerBill bb3ffdbdfb Merge branch 'master' of https://github.com/odin-lang/Odin 2021-06-23 14:55:53 +01:00
gingerBill fcf7cf973b Add documentation for -verbose-errors 2021-06-23 14:55:40 +01:00
Jeroen van Rijn fb2e1c32bd Merge pull request #1034 from Kelimion/bytes_util
Move `bytes` utils back to EXR code for the time being.
2021-06-22 16:48:07 +02:00
Jeroen van Rijn ae0b8fce44 Move bytes utils back to EXR code for the time being.
Also, allow PNG example to be run directly from `core:image/png` directory.
2021-06-22 16:39:00 +02:00
Jeroen van Rijn d2e55f9ffa Merge pull request #1032 from Kelimion/png_fix
PNG: Fix leak if you don't ask for metadata.
2021-06-21 22:56:39 +02:00
Jeroen van Rijn d5e2b387fa PNG: Fix leak if you don't ask for metadata. 2021-06-21 22:47:54 +02:00
Jeroen van Rijn 922b511a24 Merge pull request #1031 from Kelimion/zlib_fix
ZLIB: fix.
2021-06-21 22:16:56 +02:00
Jeroen van Rijn 9de9111082 ZLIB: fix. 2021-06-21 22:15:04 +02:00
Jeroen van Rijn 5a7fe2e3d9 Merge pull request #1030 from Kelimion/zlib_optimize
Comment out tracy imports.
2021-06-21 21:43:57 +02:00
Jeroen van Rijn 1e8c12c2a3 Comment out tracy imports. 2021-06-21 21:41:56 +02:00
Jeroen van Rijn b92c70e55c Merge pull request #1029 from Kelimion/zlib_optimize
ZLIB: Start optimization.
2021-06-21 21:26:52 +02:00
Jeroen van Rijn 352494cbb4 ZLIB: Start optimization. 2021-06-21 21:05:52 +02:00
Jeroen van Rijn 797c41950a Merge pull request #1027 from Kelimion/png
Replace `core:image`'s `sidecar` with explicit pointer and type
2021-06-21 16:41:38 +02:00
Jeroen van Rijn e036a321a0 Replace core:image's sidecar with explicit metadata_ptr and metadata_type.
To unpack, use:
```odin

v: ^png.Info;

if img.metadata_ptr != nil && img.metadata_type == png.Info {
	v = (^png.Info)(img.metadata_ptr);
	...
}
```
2021-06-21 16:32:42 +02:00
Jeroen van Rijn 18471f358e Merge pull request #1025 from Kelimion/png_info
Change PNG's img.sidecar to ^Info, make img.depth an int.
2021-06-20 18:40:46 +02:00
Jeroen van Rijn 55d09251d8 Change PNG's img.sidecar to ^Info, make img.depth an int.
For compatibility with the upcoming OpenEXR code, img.depth is now an int.
Like OpenEXR's code, it will now also return metadata as ^Info instead of Info.

The example was updated to retrieve the metadata this way.

It regrettably does not fix: #1018. That seems to be a codegen issue in the test runner or elsewhere.
2021-06-20 18:27:23 +02:00
Jeroen van Rijn d66fd71d21 Merge pull request #1024 from Kelimion/defer_fix
GZIP defer diverging fix in gzip example.
2021-06-20 17:40:15 +02:00
Jeroen van Rijn f10fc2a494 Merge pull request #1023 from Kelimion/test_runner_fix
Fix Windows test runner.
2021-06-20 17:37:04 +02:00
Jeroen van Rijn 055d8c5370 Fix Windows test runner. 2021-06-20 17:33:39 +02:00
Jeroen van Rijn 955472bd21 GZIP defer diverging fix in gzip example. 2021-06-20 17:21:18 +02:00
gingerBill a2d5f660ed Merge pull request #1022 from Kelimion/buffer_convert
Add `bytes.buffer_create_of_type` and `bytes.buffer_convert_to_type`.
2021-06-18 16:41:48 +01:00
Jeroen van Rijn 8a4b9ddaa3 Fix comment. 2021-06-18 15:42:04 +02:00
Jeroen van Rijn 54a2b6f00e Add bytes.buffer_create_of_type and bytes.buffer_convert_to_type.
Convenience functions to reinterpret or cast one buffer to another type, or create a buffer of a specific type.

	Example:
```odin
	fmt.println("Convert []f16le (x2) to []f32 (x2).");
	b := []u8{0, 60, 0, 60}; // == []f16{1.0, 1.0}

	res, backing, had_to_allocate, err := bytes.buffer_convert_to_type(2, f32, f16le, b);
	fmt.printf("res      : %v\n", res);              // [1.000, 1.000]
	fmt.printf("backing  : %v\n", backing);          // &Buffer{buf = [0, 0, 128, 63, 0, 0, 128, 63], off = 0, last_read = Invalid}
	fmt.printf("allocated: %v\n", had_to_allocate);  // true
	fmt.printf("err      : %v\n", err);              // false

	if had_to_allocate { defer bytes.buffer_destroy(backing); }

	fmt.println("\nConvert []f16le (x2) to []u16 (x2).");

	res2: []u16;
	res2, backing, had_to_allocate, err = bytes.buffer_convert_to_type(2, u16, f16le, b);
	fmt.printf("res      : %v\n", res2);             // [15360, 15360]
	fmt.printf("backing  : %v\n", backing);          // Buffer.buf points to `b` because it could be converted in-place.
	fmt.printf("allocated: %v\n", had_to_allocate);  // false
	fmt.printf("err      : %v\n", err);              // false

	if had_to_allocate { defer bytes.buffer_destroy(backing); }

	fmt.println("\nConvert []f16le (x2) to []u16 (x2), force_convert=true.");

	res2, backing, had_to_allocate, err = bytes.buffer_convert_to_type(2, u16, f16le, b, true);
	fmt.printf("res      : %v\n", res2);             // [1, 1]
	fmt.printf("backing  : %v\n", backing);          // Buffer.buf points to `b` because it could be converted in-place.
	fmt.printf("allocated: %v\n", had_to_allocate);  // false
	fmt.printf("err      : %v\n", err);              // false

	if had_to_allocate { defer bytes.buffer_destroy(backing); }
```
2021-06-18 15:25:36 +02:00
gingerBill abe728dbbb Add intrinsics.type_is_endian_platform 2021-06-17 20:39:00 +01:00
gingerBill 574ceb37a9 Correct selector call expression chaining behaviour (a bit of a hack) 2021-06-16 17:04:05 +01:00
gingerBill dbdc4471c2 Fix double evaluation bug with selector call expressions x->y(z) 2021-06-16 14:03:12 +01:00
gingerBill af95381bf8 Add missing -> ! annotation 2021-06-16 12:12:24 +01:00
gingerBill 41f2539484 Improve logic for diverging procedures by checking if it terminates 2021-06-16 12:07:24 +01:00
gingerBill 8f57bb0799 Add unreachable detection for deferred statements in a scope which contains a diverging procedure call
```odin
{
    defer foo(); // Unreachable defer statement due to diverging procedure call at the end of the current scope
    os.exit(0);
}
```
2021-06-16 11:41:29 +01:00
gingerBill 84a4188c72 Fix #1017 2021-06-15 01:16:19 +01:00
gingerBill 31f1e0aeae Fix #1019 2021-06-15 01:13:16 +01:00
gingerBill 4b8cbb5a3b Fix #1015 2021-06-14 13:26:28 +01:00
gingerBill 3e7aabe6d8 Change uses for parapoly records to use $ always 2021-06-14 11:43:35 +01:00
gingerBill d4df325e0a Just create context when required 2021-06-14 11:41:50 +01:00
gingerBill 9f8a63cb43 More minor stylization changes (remove unneeded parentheses) 2021-06-14 11:34:31 +01:00
gingerBill 6f745677b4 Minor formatting changes 2021-06-14 11:30:00 +01:00
gingerBill 86649e6b44 Core library clean up: Make range expressions more consistent and replace uses of .. with ..= 2021-06-14 11:15:25 +01:00
gingerBill 3ca887a60a Add struct_fields_zipped and enum_fields_zipped (allowing for iteration through an #soa slice) 2021-06-14 11:04:51 +01:00
gingerBill 312a1e8a94 Fix context logic 2021-06-13 16:00:20 +01:00
gingerBill 9a311ab9e7 Remove dead code 2021-06-12 16:47:20 +01:00
gingerBill 7d92eaaeb2 Correct context logic in lb_build_addr 2021-06-12 16:45:44 +01:00
gingerBill 582f423b67 Improve vector arithmetic generation for array programming operations 2021-06-12 16:37:20 +01:00
gingerBill c2524464f9 Fix remove_temp_files 2021-06-12 16:23:41 +01:00
gingerBill 55e472cdb6 Fix linkage problem for procedures required by LLVM 2021-06-10 12:23:08 +01:00
gingerBill e6ad773a88 Minor code clean up 2021-06-09 23:47:44 +01:00
gingerBill 82eae32bca Improve code generation for type switch statements to use a jump table by default 2021-06-09 23:46:00 +01:00
gingerBill b0e21bd616 Allow trivial optimizations for switch statements of typeid 2021-06-09 23:05:37 +01:00
gingerBill 7b88bed098 Do trivial SwitchInstr optimization for constant case switch statements 2021-06-09 22:55:08 +01:00
gingerBill 28abf5d33b Correct minimum dependency for complex32 2021-06-08 21:20:33 +01:00
gingerBill fb8ad338d0 Keep -vet happy 2021-06-08 18:26:38 +01:00
gingerBill ee60be0137 Improve code generation hints for return statements which return by pointer 2021-06-08 17:17:53 +01:00
gingerBill 9efd4c5097 Aid code generation on non-release builds 2021-06-08 17:17:24 +01:00
gingerBill f30e6f50bd Reorganize code to improve code generation 2021-06-08 16:21:19 +01:00
gingerBill 8ec2ca9dcd Remove context.thread_id 2021-06-08 15:57:00 +01:00
gingerBill f19bb0f4d4 Make default calling convention code more correct to read 2021-06-08 14:33:49 +01:00
gingerBill 76bb82a726 Minor alignment cleanup for swizzle load 2021-06-08 14:27:36 +01:00
gingerBill 8e62f9c83c Correct is_operand_value for Swizzle addressing modes 2021-06-08 14:23:44 +01:00
gingerBill 696f758435 Fix and improve swizzle loads for ordered indices 2021-06-08 14:19:27 +01:00
gingerBill 6421152104 Fix show-timings header for -lld on windows 2021-06-08 13:19:19 +01:00
gingerBill 1e989f5c10 Fix -lld on Windows 2021-06-08 13:10:22 +01:00
gingerBill 3eb42ecb55 Minor improvements to -use-separate-modules 2021-06-08 13:00:20 +01:00
gingerBill 286cb60c45 Minor changes to tools/odinfmt 2021-06-08 12:18:55 +01:00
gingerBill 28e9a4f79c Replace js_wasm32 with freestanding_wasm32 2021-06-08 12:18:26 +01:00
gingerBill e79fb68291 Correct #soa type creation 2021-06-08 11:23:23 +01:00
gingerBill 16eaa17ed9 Fix -target:js_wasm32 for core:runtime 2021-06-08 11:20:39 +01:00
gingerBill 9491c13a5c Fix #1011 by unifying the logic 2021-06-08 11:09:41 +01:00
gingerBill 8d8adac1b4 Fix lb_build_defer_stmt 2021-06-08 10:43:11 +01:00
gingerBill ba6c63e366 Fix full_path_from_name allocator behaviour 2021-06-08 10:14:35 +01:00
gingerBill 963b1a12d7 Correct code for #simd in unions 2021-06-06 16:56:03 +01:00
gingerBill 89890d7900 Correct union tag size for large alignments 2021-06-06 16:34:51 +01:00
gingerBill 661fcad895 Add examples/all which imports every package
This is useful for knowing what exists and producing documentation with `odin doc`
2021-06-06 13:05:54 +01:00
gingerBill cef16feb0b Fix #861 - Add extra check on missing main 2021-06-06 12:46:59 +01:00
gingerBill 84b851f578 Add warning to variables which may overflow the stack on declaration; #Fix 661 2021-06-06 12:42:39 +01:00
gingerBill 785c27daa7 Fix 128-bit integer to float cast by explicitly calling the procedure direct; Fix #781 2021-06-06 12:35:38 +01:00
gingerBill 795a5910cf Add support for Addressing_OptionalOkPtr
Allowing for `i, ok := &x.(T);` (type assertions) and `v, ok := &m[k];` (map indexing)
2021-06-06 12:18:45 +01:00
gingerBill 4c21f9495d Clean up lbAddr_Swizzle logic for load and store 2021-06-05 23:56:59 +01:00
gingerBill f119fd1ee1 Use shufflevector when possible for lbAddr_Swizzle load 2021-06-05 22:50:23 +01:00
gingerBill 46ab822316 Improved lb_build_assign_stmt_array logic 2021-06-05 22:07:39 +01:00
gingerBill 104aea9f42 Improve error message for addressing a swizzle intermediate array value 2021-06-05 18:25:51 +01:00
gingerBill a2f2041aa6 Fix lb_build_assign_stmt_array for lbAddr_Swizzle 2021-06-05 17:33:42 +01:00
gingerBill 599d18f26f Experimental support for inline swizzling for array types of len <= 4 e.g. v.xyz, v.argb, v.xxx 2021-06-05 17:22:39 +01:00
gingerBill 61084d832d Add missing doc_format flags for entities and improve docs for the odin package 2021-06-05 15:55:19 +01:00
gingerBill b957996577 Add extra documentation to doc_format.odin 2021-06-05 15:26:05 +01:00
gingerBill f41150f8e9 Fix transposing 2021-06-04 15:10:53 +01:00
gingerBill 21adad4e09 Fix typo 2021-06-04 15:09:55 +01:00
gingerBill 47f9e8f850 Fix ast_end_token for [?]T types 2021-06-03 11:35:27 +01:00
gingerBill ba3f2a6a0c All spaces in import-like paths 2021-06-03 10:28:45 +01:00
gingerBill b9888f8f68 Fix linalg.transpose 2021-06-03 10:05:05 +01:00
gingerBill 32cda5d56a Or did it?! 2021-06-02 22:12:38 +01:00
gingerBill a4d9847f45 FINALLY fix lazy_buffer_destroy 2021-06-02 22:12:20 +01:00
gingerBill 8aa6d70dec Fix filepath.lazy_buffer 2021-06-02 12:21:20 +01:00
gingerBill ea6b222430 Clean up filepath.lazy_buffer memory leak 2021-06-02 12:19:25 +01:00
gingerBill 91b4bf3daa Minor clean up 2021-06-02 10:39:47 +01:00
gingerBill 8c943eb054 Make inline array arithmetic use load+extractvalue rather than getelementptr+load to give the optimizer a better hint for vectorization 2021-06-01 10:51:54 +01:00
gingerBill 446703ba75 Improves to array arithmetic on += etc assignment statements 2021-06-01 10:37:31 +01:00
gingerBill 266b5d7d85 Fix container/map.odin 2021-06-01 09:26:01 +01:00
gingerBill d90adb7a8e Fix #998 2021-05-31 21:03:50 +01:00
gingerBill 2573da12fc Fix #992 2021-05-31 20:58:28 +01:00
gingerBill bbc9c6a93c Fix #999 2021-05-31 20:56:07 +01:00
gingerBill 673134185a Fix #996 2021-05-31 20:54:09 +01:00
gingerBill 3bf00e6125 Comment on the required generate_minimum_dependency_set entities 2021-05-31 20:50:21 +01:00
gingerBill 8fd4fe25d6 Remove unneeded minimum dependencies 2021-05-31 20:44:48 +01:00
gingerBill ea1dc5373d Remove unneeded dependencies 2021-05-31 20:39:48 +01:00
gingerBill b8d6dd4eb7 Fix #1004 2021-05-31 20:38:10 +01:00
gingerBill 4d80f8598d Fix polymorphic record "too few" lacking error message 2021-05-31 20:33:14 +01:00
Jeroen van Rijn bc4591fc1e Merge pull request #1006 from jockus/master
Fix for value rather than type used for intrinsics
2021-05-31 14:23:40 +02:00
Joakim Hentula 6465fb8ec7 Fix for value rather than type used for intrinsics 2021-05-31 13:21:13 +01:00
gingerBill 46204ed7f0 Update core:runtime to use the new intrinsics 2021-05-30 13:22:15 +01:00
gingerBill 0f91ffe28f Add intrinsics.{ptr_offset, ptr_sub} 2021-05-30 13:21:56 +01:00
gingerBill 4b46d691f8 Improve logic for intrinsics.{mem_copy, mem_copy_non_overlapping, mem_zero} to use the *.inline LLVM variants when possible 2021-05-30 12:52:44 +01:00
gingerBill 599d0cf6ac Merge pull request #1005 from Kelimion/maths
Add `abs_f16` support + endian versions of maths routines.
2021-05-30 11:48:17 +01:00
Jeroen van Rijn d7dba495fd Last of the Endian float in math.odin. 2021-05-29 18:27:43 +02:00
Jeroen van Rijn c05f6b4a31 Even more Endian maths. 2021-05-29 17:52:47 +02:00
Jeroen van Rijn a0a578c72a More Endian version of maths procs. 2021-05-29 17:21:54 +02:00
Jeroen van Rijn 55fc2c00c0 Add Endian versions of math routines. 2021-05-29 16:22:47 +02:00
Jeroen van Rijn 6944e2fc04 Add abs_f16 dependency when used. 2021-05-29 15:33:11 +02:00
gingerBill c8b353b6d8 Makefile fix 2021-05-27 14:59:45 +01:00
gingerBill 6a8a31824d Minor change to Makefile 2021-05-27 14:55:12 +01:00
gingerBill 275b8d2e8a Merge pull request #925 from Kelimion/testing
Fix `core:sys/win32` tests to use `core:testing`.
2021-05-27 14:51:09 +01:00
gingerBill 8cfdd9805d Merge branch 'master' of https://github.com/odin-lang/Odin 2021-05-27 14:46:10 +01:00
gingerBill 7d304f4e8b Convert tabs to spaces for Makefile (stupid make) 2021-05-27 14:45:57 +01:00
gingerBill b65e5d5e03 Merge pull request #1003 from jockus/master
Fix deleting substring in filepath.rel
2021-05-27 13:35:46 +01:00
jockus b110153b51 Fix accidental removal of newline 2021-05-27 12:04:24 +01:00
jockus b261937233 Remove accidental core:fmt include in path/filepath 2021-05-27 12:03:37 +01:00
jockus 4455ba5b65 Merge branch 'master' of https://github.com/odin-lang/Odin 2021-05-27 12:01:28 +01:00
jockus e8aa767c8d Fix deleting substring in filepath.release 2021-05-27 12:01:13 +01:00
gingerBill bb7bd94b0a Fix comparison bug of enumerated arrays 2021-05-27 09:52:50 +01:00
gingerBill 4a886a1bc5 Disable copy elision on assignments for the time being 2021-05-25 15:43:34 +01:00
gingerBill c21c754b6f Minimize copying on getting the address of a call if required 2021-05-24 23:51:01 +01:00
gingerBill e948fcd2f1 Use intrinsics.mem_zero in runtime.mem_zero 2021-05-24 22:41:18 +01:00
gingerBill 0c46d06e63 Add intrinsics.mem_zero 2021-05-24 22:39:27 +01:00
gingerBill 44b6e7c45d Move the mem zero into a separate procedure for reuse 2021-05-24 22:32:38 +01:00
gingerBill 284a2631fd Refactoring of lbFunctionType retrieval 2021-05-24 22:16:22 +01:00
gingerBill 3f156bcb4b Refactor backend code for assignments; Refactor some statements into separate procedures 2021-05-24 22:09:21 +01:00
gingerBill d35a9e65b6 Heavily improve the copy elision logic in the backend 2021-05-24 20:57:44 +01:00
gingerBill c440296ae8 Add @(link_section=<string>) for global variables 2021-05-24 15:41:22 +01:00
gingerBill 79f115d6a7 Handle #c_vararg correctly 2021-05-24 14:46:03 +01:00
gingerBill 39eccdf6b9 Make js default to nil allocator for the time being 2021-05-23 15:17:58 +01:00
gingerBill 71cfa0c9fe Clean up organization of package runtime 2021-05-23 12:13:13 +01:00
gingerBill e82f8214e8 Add bytes.remove, bytes.remove_all, strings.remove, strings.remove_all 2021-05-23 11:46:43 +01:00
gingerBill b8f8d4c3a1 Modify ABI for the Odin calling conventions on SysV slightly 2021-05-22 11:33:08 +01:00
gingerBill 9e2eb717fe Correct newline_limit logic 2021-05-21 15:22:35 +01:00
gingerBill f0c9f82e1b Minor changes to printer to use a bit set rather than booleans for list options 2021-05-21 13:42:29 +01:00
gingerBill cc1d3a7b19 parser.check_poly_params_for_type 2021-05-21 13:07:00 +01:00
gingerBill 159daba759 Fix ast_end_token 2021-05-21 12:44:45 +01:00
gingerBill d7e85725e1 General improves to formatting for the visitor 2021-05-21 11:16:07 +01:00
gingerBill 247f4f3293 Fix ..= logic in the backend 2021-05-21 10:51:19 +01:00
gingerBill 8758afdf4e General fixes for odinfmt 2021-05-21 10:21:23 +01:00
gingerBill 362f07d7c5 Merge pull request #997 from DanielGavin/prototype-fmt
Add odin/format and odin/printer packages
2021-05-20 21:02:26 +01:00
gingerBill fe74b479c6 Begin changes to sync2 2021-05-20 21:02:05 +01:00
Daniel Gavin 44ee0f2cdc Merge branch 'master' into prototype-fmt 2021-05-20 12:15:14 +02:00
Daniel Gavin 50035f257e don't factor in the rhs length for lines that don't have Equal tokens. 2021-05-20 12:13:23 +02:00
gingerBill 92abddddc5 Be a little more correct with the temporary Ast node 2021-05-19 15:02:36 +01:00
gingerBill 4d580ed693 Keep -vet happy 2021-05-19 14:26:20 +01:00
gingerBill 9c54ed5792 Add range-based error messages to -verbose-errors
Example:
Cannot convert '(1 + 2)' to 'untyped bool' from 'untyped integer'

	x := (1 + 2) * true;
	     ^~~~~~^
2021-05-19 14:15:57 +01:00
gingerBill 5108ebf015 Replace error calls with Token to use TokenPos 2021-05-19 13:02:44 +01:00
gingerBill 86dbcb1b20 Add -verbose-errors which shows the error in the line of code 2021-05-19 12:57:30 +01:00
gingerBill 3ac934dd15 Add suggestion for unused expression on x == y
Expression is not used: 'x == 123'
	Suggestion: Did you mean to do an assignment?
	            'x = 123;'
2021-05-19 11:58:02 +01:00
gingerBill 26ce40c188 Remove @(static) for global variables 2021-05-19 11:51:48 +01:00
gingerBill b34e4a9fd1 More minor linkage changes 2021-05-19 11:46:27 +01:00
gingerBill 28561ef5f5 Minor change to internal linkage stuff 2021-05-19 11:26:05 +01:00
gingerBill 10b798456c Add soa_zip and soa_unzip to demo.odin 2021-05-19 10:55:56 +01:00
gingerBill a580cdbe7b Delete core:sync/sync2/channel* stuff (for the time being) 2021-05-19 10:50:27 +01:00
gingerBill e82e4398b6 Add intrinsics.mem_copy and intrinsics.mem_copy_non_overlapping 2021-05-19 10:50:02 +01:00
gingerBill e0225c3579 Add intrinsics.sqrt for floating-point values 2021-05-19 10:32:41 +01:00
gingerBill 8d044fd442 Minor ABI change and cleanup 2021-05-17 17:08:25 +01:00
gingerBill 6ef96d3300 Improve untyped to typed logic for aiding the backend 2021-05-16 14:44:02 +01:00
gingerBill 2e633f57a0 Add concrete type information for untyped values as procedure arguments 2021-05-16 13:00:16 +01:00
gingerBill 50369cf19c Update LICENSE year 2021-05-16 12:48:36 +01:00
gingerBill 385385364b Fix #988 2021-05-16 12:46:25 +01:00
gingerBill 9ccdc40f65 Make .Optional_Semicolons a flag for the parser 2021-05-16 12:43:35 +01:00
gingerBill df3512b112 Make core:odin use a string for the source rather than []byte 2021-05-16 12:38:27 +01:00
gingerBill ce08e832f7 Allow ..= alongside .. as a "full range" operator; Update core:odin/parser etc 2021-05-16 12:34:35 +01:00
gingerBill 24c89b3eee Minor change 2021-05-16 00:29:22 +01:00
gingerBill 85e5be03d1 Redesign os2.Error to work with the new extended union behaviour 2021-05-16 00:25:47 +01:00
gingerBill b1cfeb6c95 Add missing instruction to pass 2021-05-15 22:14:20 +01:00
gingerBill fffb83282b Add missing instructions to pass 2021-05-15 21:24:17 +01:00
gingerBill 1cf6b6679d Add custom basic dead instruction elimination pass 2021-05-15 21:10:06 +01:00
gingerBill 7886798156 Add space 2021-05-15 19:49:48 +01:00
gingerBill 0ad599675e Improve semicolon insertion rule for dummy tokens ++ and -- 2021-05-15 19:47:00 +01:00
gingerBill 5d03bc61b8 Tokenize ++ and -- as tokens but disallow them in the parser, and give better error messages for they are used as operators/statements 2021-05-15 19:34:46 +01:00
gingerBill 5e31c04a01 Disallow duplicate unary operators for +, -, and ~ 2021-05-15 19:13:34 +01:00
gingerBill 7b7081d607 Remove old dead code 2021-05-15 18:59:54 +01:00
gingerBill 5ae564cc8c Add name to aggregate result pointer to procedures 2021-05-15 18:53:52 +01:00
gingerBill 0507b9ebb7 Fix #987 2021-05-15 18:40:06 +01:00
gingerBill f7b1290fe9 Change for i in x..y {} behaviour
Adds an extra check before incrementation to prevent the possibility of overflowing of `y` is at the limit maximum size of the integer
e.g. `for i in u8(0)..255 {}` (assuming `255` is not known at compile time)
2021-05-15 18:02:06 +01:00
gingerBill b01c2e1017 Disallow slicing of constant values 2021-05-15 16:40:40 +01:00
gingerBill 63b54ce7c6 Add minor ignoring hint on type assertions to get better code generation with no optimizations enabled 2021-05-13 12:48:12 +01:00
gingerBill b8a35c658c Remove incl/excl usage from demo 2021-05-13 12:06:35 +01:00
gingerBill 465b6139d5 Temporarily fix syscall in Linux and Freebsd (eventually to be replaced with a proper implementation) 2021-05-13 12:05:23 +01:00
gingerBill b37d344eb2 Add intrinsics.type_is_variant_of 2021-05-13 12:04:51 +01:00
gingerBill d4ee1a9e19 Correct default procedure parameter logic 2021-05-13 10:07:28 +01:00
gingerBill be12f12c3c Fix #814 2021-05-13 00:57:10 +01:00
gingerBill 2e5f57d8a1 Fix #741 2021-05-13 00:44:33 +01:00
Mikkel Hjortshøj d5c3f99655 Update feature_request.md 2021-05-13 01:26:15 +02:00
Mikkel Hjortshøj 083e9e2053 Update feature_request.md 2021-05-13 01:25:37 +02:00
gingerBill c6c5af527b Fix #746 2021-05-12 23:43:16 +01:00
gingerBill 5420cc083d Implement #807 2021-05-12 23:26:21 +01:00
gingerBill c81f7b31c6 Add explicit numbers to enum AddressingMode 2021-05-12 23:22:43 +01:00
gingerBill fdd0c726bc Improve error message to "fix" #640 2021-05-12 23:12:20 +01:00
gingerBill da9cabc334 Fix #682 2021-05-12 23:02:57 +01:00
gingerBill d962cfdc6b Fix #713 2021-05-12 22:38:37 +01:00
gingerBill dfb8143149 Fix #651 2021-05-12 22:23:43 +01:00
gingerBill d2fcbf0e1d Fix #948 2021-05-12 15:00:19 +01:00
gingerBill e08f39ec28 Remove unneeded assert 2021-05-11 16:20:50 +01:00
gingerBill d353f97f91 Add byval with align, sret attributes for SysV 2021-05-11 13:30:27 +01:00
gingerBill 8144e82c6c Fix docs for -lld 2021-05-11 13:13:34 +01:00
gingerBill d0f7cf74e9 Add llvm-config version 11 check for Darwin in Makefile 2021-05-11 12:31:56 +01:00
gingerBill e1c2528d87 Remove warning on \*nix 2021-05-11 12:29:27 +01:00
gingerBill eac61fb536 Remove LLVMAddLowerConstantIntrinsicsPass 2021-05-11 12:17:48 +01:00
gingerBill 20f7e61363 Revert LLVM-C.lib 2021-05-11 12:11:59 +01:00
gingerBill 8bb6651dda Remove test call for LLVM 2021-05-11 12:08:09 +01:00
gingerBill 8ff80dec58 Minor change (in preparation for something else) to opt passes 2021-05-11 12:00:55 +01:00
gingerBill f31b09212a Improve SysV ABI 2021-05-11 12:00:27 +01:00
gingerBill 073bd3f6c9 Update LLVM-C.lib (since it was missing many required definitions missing from the official one that LLVM supplied) 2021-05-11 10:55:55 +01:00
gingerBill 9a4d942b0b Fix debug information for array types by setting the DISubrange 2021-05-10 21:29:25 +01:00
gingerBill ff6fdc7812 Correct SysV ABI for -> (f32, bool) 2021-05-10 21:16:26 +01:00
gingerBill c85c5ec38c Merge branch 'master' of https://github.com/odin-lang/Odin 2021-05-07 13:18:07 +01:00
gingerBill d70b5475eb Minor code clean up 2021-05-07 13:18:01 +01:00
gingerBill 42138d1ad5 Merge pull request #947 from Kelimion/deprecated
Mark mem.slice_ptr_to_bytes as deprecated.
2021-05-07 10:59:08 +01:00
gingerBill 47f97b8f89 Remove unused hint 2021-05-06 14:09:50 +01:00
gingerBill 902be0d09c Improve type inference system to allow &{} alongside &T{} in some cases 2021-05-06 14:06:22 +01:00
gingerBill 502ad0c10b sync2.Auto_Reset_Event; Make atomic operations names clearer 2021-05-06 14:00:01 +01:00
gingerBill 27f5aadd5a Merge branch 'master' of https://github.com/odin-lang/Odin 2021-05-06 13:59:14 +01:00
gingerBill da7a9a3584 Improve type inference rules for implicit selector expressions
New improvements:
`(.A == x)`
`a_union_containing_many_enums = .A;`
2021-05-06 13:59:05 +01:00
Jeroen van Rijn 03862d1f48 Mark mem.slice_ptr_to_bytes as deprecated.
Use byte_slice instead.

We can't make it an alias *and* mark it as deprecated, regrettably:

```odin
byte_slice :: #force_inline proc "contextless" (data: rawptr, len: int) -> []byte {
    return transmute([]u8)Raw_Slice{data=data, len=max(len, 0)};
}
@(deprecated="use byte_slice")
slice_ptr_to_bytes :: byte_slice;

"mem.odin(145:1) Constant alias declarations cannot have attributes"
```
2021-05-06 13:23:17 +02:00
Jeroen van Rijn 15ce8b0454 Merge pull request #946 from Kelimion/virtual_allocator
Fix typo in core:mem alloc() comment.
2021-05-06 11:33:08 +02:00
Jeroen van Rijn 4f51d74fc2 Fix typo in core:mem alloc() comment. 2021-05-06 11:25:41 +02:00
gingerBill b6a1ec0229 Remove debug code 2021-05-05 23:34:53 +01:00
gingerBill 60685369b9 Fix typo 2021-05-05 23:34:39 +01:00
gingerBill 0f2a9e6143 Fix LLVM store point for nested types containing procedures (e.g. ^^proc()) 2021-05-05 23:00:12 +01:00
gingerBill 278de3a92f Unify AstTernaryExpr with AstTernaryIfExpr
Allow for both syntaxes `x if cond else y` and `cond ? x : y`
Removes the confusing semantics behind `?:` which could be `if` or `when` depending on the context.
2021-05-05 15:22:54 +01:00
gingerBill abdf54800e Improve ternary expression logic within parametric polymorphic parameter assignments 2021-05-05 15:14:39 +01:00
gingerBill 579b317be8 Mark external thread local globals 2021-05-05 11:47:47 +01:00
gingerBill 08360e2337 Minor cleanup 2021-05-05 10:56:19 +01:00
gingerBill f11f84964d Merge branch 'master' of https://github.com/odin-lang/Odin 2021-05-04 23:41:45 +01:00
gingerBill bb9c1d04db Fix missing newline check 2021-05-04 23:41:35 +01:00
Jeroen van Rijn f3c4d97250 Merge pull request #942 from Kelimion/grayscale-alpha-extract
Fix gray+alpha alpha extract.
2021-05-04 17:49:09 +02:00
Jeroen van Rijn afb6ebd21e Fix gray+alpha alpha extract. 2021-05-04 17:48:43 +02:00
gingerBill 6fa5eb9e1f Update README.md 2021-05-04 15:27:41 +01:00
gingerBill 94570a24c1 Move anonymous proc generation into lbGenerator 2021-05-04 00:56:29 +01:00
gingerBill 17001bf38c Nearly approach full functionality for -use-separate-modules coupled with multithreading 2021-05-04 00:45:09 +01:00
gingerBill b83e67f45f Get LLVM backend multithread for object generation with -use-separate-modules 2021-05-04 00:06:20 +01:00
gingerBill a5eea97edb Prepare to multithread object generation 2021-05-03 20:45:27 +01:00
gingerBill 866d5302fe Add [EXPERIMENTAL] warning to -user-separate-modules help message 2021-05-03 20:05:45 +01:00
gingerBill 5d70289b69 Remove test code 2021-05-03 20:03:37 +01:00
gingerBill d76ba7895b Minor fixes to -use-separate-modules 2021-05-03 19:59:17 +01:00
gingerBill dfe1dedeb1 Experimental support for -use-separate-modules 2021-05-03 19:39:36 +01:00
gingerBill d027a5f1a4 Add min_f16 and max_f16 dependencies 2021-05-03 18:48:48 +01:00
gingerBill 746e880eb5 Begin work on making LLVM backend work with multiple modules for possible faster compilation 2021-05-03 17:43:14 +01:00
gingerBill e4286d0ff9 Force zero_init in lb_add_local in certain cases 2021-05-03 15:57:35 +01:00
gingerBill 3a556eb304 Add -test-name:<string> flag to allow specific tests to be ran 2021-05-03 15:44:57 +01:00
gingerBill b44a56118e Begin cleanup for allowing for multiple LLVM modules 2021-05-03 15:26:40 +01:00
gingerBill 0d044eabac Remove non-InContext type creations 2021-05-03 15:00:50 +01:00
Jeroen van Rijn 3cf26af600 Merge pull request #941 from Kelimion/compress_error_handling
Change General_Error.OK to nil
2021-05-03 15:39:42 +02:00
Jeroen van Rijn 9a39ce6b75 Change General_Error.OK to nil 2021-05-03 15:38:43 +02:00
gingerBill 3a5245dcce Make sure builder uses the InContext version 2021-05-03 14:36:27 +01:00
Jeroen van Rijn ca0f36be42 Merge pull request #940 from Kelimion/convert_error_checks
Convert `core:compress` and `core:image` error checks to new union co…
2021-05-03 15:09:52 +02:00
Jeroen van Rijn 59b3c472ca Convert core:compress and core:image error checks to new union comparison.
No more need for `is_kind(err, Error_Value)`, just test err == Error_Value.
2021-05-03 15:08:34 +02:00
gingerBill 357f66fcee Fix typo 2021-05-03 13:45:17 +01:00
gingerBill 050f128554 Correct hashing for union #maybe 2021-05-03 13:40:36 +01:00
gingerBill 1a3784c4df Allow unions which are comparable to also be valid map keys (i.e. hashable) 2021-05-03 13:38:15 +01:00
gingerBill 518ecaf9c9 Allow unions to be comparable if all their variants are comparable 2021-05-03 13:17:16 +01:00
gingerBill 77e2e1e1d0 Add missing skip_possible_newline_for_literal calls 2021-05-03 12:02:08 +01:00
Jeroen van Rijn 448f834b28 Remove debug print in image helper. 2021-05-03 01:23:03 +02:00
Jeroen van Rijn 9212e3176a Merge pull request #939 from Kelimion/new_png_post_processing
Don't need other path for grayscale output.
2021-05-02 21:17:00 +02:00
Jeroen van Rijn 3160a6a12c Don't need other path for grayscale output. 2021-05-02 21:11:06 +02:00
Jeroen van Rijn ef7b72d14c Merge pull request #938 from Kelimion/new_png_post_processing
Add new PNG post processing options.
2021-05-02 20:39:33 +02:00
Jeroen van Rijn 7d534769d6 Add new PNG post processing options. 2021-05-02 20:38:30 +02:00
Jeroen van Rijn 0a81fcc2af Merge pull request #937 from Kelimion/core_time
datetime_to_time's ok should default to true.
2021-05-02 13:24:33 +02:00
Jeroen van Rijn 2451014b6e datetime_to_time's ok should default to true. 2021-05-02 13:23:57 +02:00
gingerBill 348d25c43a Fix parsing error for for 2021-05-02 00:11:36 +01:00
gingerBill 9854dbe889 Remove unused import 2021-05-01 23:14:14 +01:00
Jeroen van Rijn 038337fd07 Port core:sys/win32 tests to test runner. 2021-05-02 00:10:00 +02:00
gingerBill cf0bf1a7cb Add testing.fail_now 2021-05-01 23:06:14 +01:00
gingerBill 364e6c9573 Move comment 2021-05-01 22:58:13 +01:00
gingerBill 52d38ae42b Make the core:testing runner on windows run in a separate thread to handle crashes in more safe manner 2021-05-01 22:54:27 +01:00
Jeroen van Rijn 2dbdff07c5 Merge pull request #935 from Kelimion/zlib_level_0
ZLIB level 0: LEN/NLEN = i16.
2021-05-01 21:57:36 +02:00
Jeroen van Rijn 2ad8f99790 ZLIB level 0: LEN/NLEN = i16. 2021-05-01 21:56:45 +02:00
Daniel Gavin 87a1833862 fix weird behavior of nesting proc types in structs 2021-05-01 21:26:40 +02:00
Jeroen van Rijn 0a0ba95e85 Merge pull request #934 from Kelimion/paeth
Fix Paeth for bit depth < 8.
2021-05-01 20:39:40 +02:00
Jeroen van Rijn 433d742183 Fix Paeth for bit depth < 8. 2021-05-01 20:39:00 +02:00
gingerBill b845db1618 Add prototypes for intrinsics.fixed_point_* 2021-05-01 18:26:51 +01:00
gingerBill ced7700cdb Add extra check for #no_bounds_check etc being followed by a newline or empty statement 2021-05-01 17:59:30 +01:00
gingerBill 406d2ab6ba Simplify/Fix the state_flag behaviour for code generation 2021-05-01 17:42:59 +01:00
gingerBill 327116b84b Merge branch 'master' of https://github.com/odin-lang/Odin 2021-05-01 17:30:27 +01:00
gingerBill fd56b48825 Add ODIN_ROOT information 2021-05-01 17:30:22 +01:00
Jeroen van Rijn 1ef9b094b6 Merge pull request #932 from Kelimion/png_blend_test
PNG: Fix tRNS handling.
2021-05-01 18:28:23 +02:00
Jeroen van Rijn 0659a11a1a PNG: Fix tRNS handling. 2021-05-01 18:24:31 +02:00
gingerBill 956b59d48c Update old bin/README.md 2021-05-01 16:27:11 +01:00
gingerBill 97b537f800 Update intrinsics.odin for documentation 2021-05-01 16:23:50 +01:00
Jeroen van Rijn ae907bf724 Merge pull request #931 from Kelimion/png_blend_test
Fix a few more cases in which bKGD wasn't properly applied.
2021-05-01 16:05:48 +02:00
Jeroen van Rijn db1ef078ff Fix a few more cases in which bKGD wasn't properly applied. 2021-05-01 16:05:13 +02:00
Jeroen van Rijn c2603297ee Merge pull request #928 from Kelimion/png_blend_test
PNG: Fix test for when premultiplication is needed.
2021-05-01 13:25:49 +02:00
Jeroen van Rijn a02bcd3bfd PNG: Fix test for when premultiplication is needed. 2021-05-01 13:16:47 +02:00
Mikkel Hjortshøj 0e972296a4 Change non-target indentation in Makefile to spaces to fix make error 2021-04-30 22:50:14 +02:00
Mikkel Hjortshøj 5ec82623ab Remove downloading the LLVM binaries in nightly.yml 2021-04-30 22:27:09 +02:00
Mikkel Hjortshøj 47ff50a92d Remove downloading the LLVM binaries in ci.yml 2021-04-30 22:26:15 +02:00
Mikkel Hjortshøj a1558b3398 Update nightly.yml 2021-04-30 22:19:10 +02:00
gingerBill 5f617c56e1 Minor stylistic code changes to compress and image packages 2021-04-30 10:58:29 +01:00
Jeroen van Rijn 7ef30355cb Merge pull request #924 from Kelimion/core_compress
Add `compress` and `image` to core.
2021-04-30 11:33:41 +02:00
Jeroen van Rijn 06f1eaa153 Use regular allocator from png+gzip's load_from_file.
I would've used `os.stream_from_handle`, but:
- Parts of it seem to be implemented for Windows only at the moment.
- PNG's `peek_data` using that stream didn't manage to rewind and thus tried to parse the data after the header as the header.

Two things must happen:
- The `os.stream_from_handle` implementation needs to be fixed.
- PNG and GZIP's parsers need to be able to handle streams that can't rewind or seek (backward).

Those fixes are on my TODO list but are exceed the scope of this patch.
2021-04-30 09:35:43 +02:00
Jeroen van Rijn 58e023e0cf Add compress and image to core. 2021-04-30 00:21:52 +02:00
gingerBill 222bab501c Disallow unnamed polymorphic records 2021-04-29 11:00:14 +01:00
Daniel Gavin 9c6ab05981 fix tokenizer for ~= and better struct aligning 2021-04-29 00:51:24 +02:00
gingerBill bee637aef1 Update Makefile for Linux 2021-04-28 16:23:42 +01:00
gingerBill d5844dfd2a Update llvm-config checking on Linux 2021-04-28 16:07:46 +01:00
gingerBill 3751322521 Add -no-pie flag to linker on Linux 2021-04-28 15:36:29 +01:00
gingerBill 71ac145f49 Remove dead code related to old backend 2021-04-28 15:28:14 +01:00
gingerBill e50ef33c2a Fix #921 2021-04-28 12:34:16 +01:00
gingerBill 3061dd2497 Update build.bat to use wmic os get LocalDateTime /value instead of %DATE% which is not consistent across computers 2021-04-28 11:56:47 +01:00
Daniel Gavin 088f4b5039 fix out of bounds with empty struct 2021-04-28 12:53:04 +02:00
gingerBill 002184cd49 Merge pull request #920 from rasa-silva/patch-1
Fix Makefile for OSX
2021-04-28 11:20:47 +01:00
Ricardo Silva 02da4d61ae Fix Makefile for OSX 2021-04-28 11:15:05 +01:00
gingerBill 102c29575b Allow @(test) to be ran outside of *_test.odin files 2021-04-28 10:49:40 +01:00
gingerBill 24fce21d90 Add "naked" calling convention (removes prologue and epilogue) 2021-04-28 10:49:30 +01:00
gingerBill afe185ee22 Fix procedure entity finding 2021-04-27 21:08:18 +01:00
gingerBill ffffb04d85 Remove unused import 2021-04-27 17:21:52 +01:00
gingerBill 17390cd317 Implement sync2.Recursive_Mutex using WaitOnAddress and friends on Windows 2021-04-27 17:19:12 +01:00
gingerBill 7ac80544a1 Max sync2.Sema on windows be i32 for the counter internally. 2021-04-27 16:59:25 +01:00
gingerBill 96b60d8779 Reimplement sync2.Sema on windows with WaitOnAddress primitives 2021-04-27 16:56:11 +01:00
gingerBill 24f2d97c0e Make atomic compare related intrinsics optional ok 2021-04-27 16:55:39 +01:00
gingerBill f6d98d2a16 Fix Makefile for macOs 2021-04-27 13:29:14 +01:00
gingerBill ab5460e2e2 Update CI 2021-04-27 13:22:30 +01:00
gingerBill cd1658e56c Update Makefile 2021-04-27 13:14:54 +01:00
gingerBill e7e1866e50 Fix #893 2021-04-27 13:09:37 +01:00
Daniel Gavin 51b198aa56 Merge remote-tracking branch 'upstream/master' into prototype-fmt 2021-04-27 00:06:30 +02:00
gingerBill 94fd59e6f0 Make compound literals require trailing commas if followed by a newline 2021-04-26 23:05:00 +01:00
gingerBill c07ab5f9ad Change expr_level increment rules within a compound literal 2021-04-26 23:02:00 +01:00
gingerBill 06e0da97b7 Implement ODIN_ROOT #913 2021-04-26 22:56:32 +01:00
gingerBill 04535b2913 Fix constant aliasing for debug information 2021-04-26 22:36:20 +01:00
gingerBill 6667b78c12 Correct core:os/os2 mock-up 2021-04-26 22:08:15 +01:00
gingerBill 7e0c78eae7 Fix logic for \n ignoring 2021-04-26 21:39:49 +01:00
gingerBill 6d1eb473cf Correct \n ignore rules 2021-04-26 21:25:44 +01:00
gingerBill 898245431f Make -strict-style the default #871 2021-04-26 21:07:58 +01:00
gingerBill 43942a6199 Fix odin run on Windows 2021-04-26 20:54:18 +01:00
gingerBill 53c7e65c57 Merge pull request #914 from odin-lang/old-backend-removal
Removal of the Old Backend
2021-04-26 20:50:43 +01:00
gingerBill a38586420c Fix race condition with procedure aliases checking for declarations on constant aliases 2021-04-26 19:46:42 +01:00
gingerBill 1aa9c49172 Remove warning for "Redundant 'auto_cast' applied to expression" 2021-04-26 19:17:25 +01:00
gingerBill 5a88fef483 Make corrections 2021-04-26 18:07:34 +01:00
gingerBill 43b55223af Merge branch 'master' into old-backend-removal 2021-04-26 11:46:58 +01:00
gingerBill aa846d0ea5 Fix union #maybe comparison against nil -llvm-api 2021-04-26 11:46:26 +01:00
gingerBill 8d0428a8b3 Merge pull request #915 from wilsonk/issue-820
Fix for issue 720 (import name is not an identifier)
2021-04-26 10:50:06 +01:00
Kelly Wilson 86c1aed20d Fix for issue 820 (import name is not an identifier) 2021-04-25 23:26:12 -06:00
gingerBill 1d628a5e3d Change how GIT_SHA is rendered in odin version 2021-04-25 22:23:47 +01:00
gingerBill af3784ebb6 Add -DODIN_VERSION_RAW to Makefile 2021-04-25 22:19:34 +01:00
gingerBill ff933ca37f Remove old shell scripts in favour of Makefile 2021-04-25 22:13:01 +01:00
gingerBill bbf79fc1d4 Add ODIN_VERSION_RAW define to build.bat 2021-04-25 22:10:52 +01:00
gingerBill 2af8e956a6 Change versioning system from v0.13.1 to dev-2021-04 2021-04-25 22:09:22 +01:00
gingerBill 9ed826f6fb Remove import "core:runtime" from core:math/bits 2021-04-25 21:51:33 +01:00
gingerBill 07f9e551c1 Revert build.bat 2021-04-25 21:38:29 +01:00
gingerBill df4404e093 Fix typo in gb_get_env 2021-04-25 21:24:33 +01:00
gingerBill 583fd89fcf Add gb_get_env 2021-04-25 21:22:15 +01:00
gingerBill 2691c394e0 Add intrinsics.count_zeros 2021-04-25 20:50:25 +01:00
gingerBill 4662bad59c Remove unused file 2021-04-25 20:31:35 +01:00
gingerBill 7086b49ae6 Rename intrinsics to count_trailing_zeros and count_leading_zeros 2021-04-25 20:26:11 +01:00
gingerBill 72aa0e6e38 Replace many foreign llvm calls with intrinsics 2021-04-25 20:22:26 +01:00
gingerBill cb2e6ea31d Remove use_llvm_api related checks and other related things 2021-04-25 20:03:05 +01:00
gingerBill 74c683e908 Remove -llvm-api from CI 2021-04-25 19:59:35 +01:00
gingerBill 6383714bff Remove old procedure ABI code 2021-04-25 19:56:46 +01:00
gingerBill a25e796b00 Delete ir.cpp and related files 2021-04-25 19:52:37 +01:00
gingerBill 833784e196 Remove old backend specific code in main 2021-04-25 19:51:57 +01:00
gingerBill 66a70b9d27 Remove the need for LLVM_BACKEND_SUPPORT 2021-04-25 19:49:29 +01:00
gingerBill cd125c0f41 Override -llvm-api to always be true 2021-04-25 19:46:48 +01:00
gingerBill ff620422fa Fix #857 2021-04-25 19:40:02 +01:00
gingerBill 5685a8d885 Fix #911 for -llvm-api backend 2021-04-25 19:19:44 +01:00
gingerBill b8327ad00d Merge pull request #912 from odin-lang/llvm-api-ci-changes
Update Makefile to compile with LLVM C API
2021-04-25 19:02:24 +01:00
gingerBill 1bdce19c18 Update nightly.yml to support -llvm-api 2021-04-25 18:44:05 +01:00
gingerBill 041ff13672 Update CI for Linux 2021-04-25 18:06:29 +01:00
gingerBill 60a2eaf666 Revert changes to macOS Makefile 2021-04-25 18:04:07 +01:00
gingerBill ec2db568c1 Update Makefile for macOS to be more "correct" with Linux 2021-04-25 15:57:35 +01:00
gingerBill 1387fd9047 Make -llvm-api run first before old backend on Linux 2021-04-25 15:52:24 +01:00
gingerBill fb6288a54e Try specifying the specific libs on Linux 2021-04-25 15:48:54 +01:00
gingerBill 4d00058858 Try clang-11 2021-04-24 22:11:38 +01:00
gingerBill 5c26cf9d73 Try llvm-config-11 in the Makefil 2021-04-24 21:58:44 +01:00
gingerBill 6048d25d36 Try llvm-config-11 2021-04-24 21:26:14 +01:00
gingerBill 748f094e15 Add llvm-dev-11 to Linux CI (just testing) 2021-04-24 21:20:18 +01:00
gingerBill 184c686c7e Add clang-11 for Linux; blank out threading_example on darwin 2021-04-24 21:13:40 +01:00
gingerBill 240a568eb9 Update CI to run both old and new backends 2021-04-24 21:09:35 +01:00
gingerBill ad953c4670 Add cast on S_ISDIR 2021-04-24 21:08:15 +01:00
gingerBill 0f9b0c2052 Remove libllvm-11 2021-04-24 21:04:38 +01:00
gingerBill cde334ada3 Modify flags in Makefile 2021-04-24 21:03:22 +01:00
gingerBill 2b4010998d Up ci.yml 2021-04-24 20:55:50 +01:00
gingerBill 4272fe5e85 Update Makefile to compile with LLVM C API 2021-04-24 20:46:47 +01:00
gingerBill c29b643a58 Move out some intrinsics into separate procedures in llvm_backend.cpp; Rename InlineRangeStmt to UnrollRangeStmt (eventually merge the two AST nodes) 2021-04-24 15:00:01 +01:00
Daniel Gavin 87bfd31664 force all enums newlined if there is more than one line 2021-04-23 23:42:53 +02:00
Daniel Gavin 5fba548aa0 more fixes with wierd comment placements 2021-04-23 23:22:48 +02:00
Daniel Gavin aafbf5bac7 odinfmt 2021-04-23 22:55:59 +02:00
Daniel Gavin 951e940470 handle comments in stupid places 2021-04-23 21:52:27 +02:00
Daniel Gavin 3b5b845ea6 refractor 2021-04-23 16:45:55 +02:00
Daniel Gavin 3f9ad6ba09 fix proc group, struct align with internal structs 2021-04-23 16:33:11 +02:00
gingerBill c9b82a21e9 Move check_builtin_procedure to check_builtin.cpp 2021-04-23 10:01:52 +01:00
gingerBill bd31a99bf7 Remove redundant auto_cast 2021-04-23 09:50:26 +01:00
Daniel Gavin f10f7ebbf1 Merge remote-tracking branch 'upstream/master' into prototype-fmt 2021-04-23 10:24:05 +02:00
gingerBill 17bbb48d8a Warn on redundant auto_cast, and make an error on -vet 2021-04-22 17:36:28 +01:00
gingerBill ac53577e9b Improve auto_cast logic 2021-04-22 17:29:48 +01:00
gingerBill 896057b5a7 Reuse unused 'context' variables to minimize stack usage (-llvm-api) 2021-04-22 16:56:02 +01:00
gingerBill 01db195b47 Make main calling convention "odin" rather than "contextless" to simplify code generation 2021-04-22 16:26:28 +01:00
gingerBill d33350e3a5 Add truncate_to_byte and truncate_to_rune for packages strings and bytes 2021-04-22 15:49:10 +01:00
gingerBill 8a86c4c7cc Remove old code 2021-04-22 14:24:30 +01:00
gingerBill 1c9f48031d Change function pass manager passes 2021-04-22 13:54:26 +01:00
gingerBill 7fcd5ecbd5 Change how lb_populate_function_pass_manager works by using the default LLVM passes when not using minimal optimizations 2021-04-22 12:35:01 +01:00
gingerBill b68b090f13 Add intrinsics: overflow_add, overflow_sub, overflow_mul; Change byte swap behaviour in -llvm-api to be the same as the intrinsic 2021-04-22 11:33:46 +01:00
gingerBill 542098dc6f Add intrinsics: byte_swap (integers and floats); count_ones; trailing_zeros; reverse_bits 2021-04-22 11:06:16 +01:00
gingerBill 0a66f8c9a3 Remove intrinsics.x86_mmx type 2021-04-22 10:39:20 +01:00
gingerBill 158e4c0b6c Add @(cold) tag 2021-04-22 10:35:37 +01:00
gingerBill 47c7dc6a9b Add new intrinsics: debug_trap, trap, read_cycle_counter, expect 2021-04-22 10:35:17 +01:00
gingerBill 65551ba8fb Add optimization_mode attribute for procedures
Allowed modes: "none", "minimal", "size", "speed"
Currently: none == minimal and size == speed
2021-04-22 00:04:47 +01:00
Daniel Gavin 40ed7e48d0 remove prints 2021-04-22 00:56:31 +02:00
Daniel Gavin ab53900c95 check comma count in enum instead 2021-04-22 00:55:25 +02:00
gingerBill c7d92562c2 Fix typo 2021-04-21 23:40:19 +01:00
gingerBill 5b3802b8ca Add new -o:<string> flag as an alternative to -opt:<integer> 2021-04-21 23:39:48 +01:00
Daniel Gavin 43589a56b7 odinfmt on printer 2021-04-22 00:32:36 +02:00
gingerBill 2fb0383e82 Add -build-mode:llvm-ir for -llvm-api backend 2021-04-21 23:25:08 +01:00
Daniel Gavin de1838c0cb align not mutable correctly 2021-04-22 00:23:17 +02:00
Daniel Gavin 9b8563dfc0 style 2021-04-22 00:08:03 +02:00
Daniel Gavin b18e8898d8 ran odinfmt on source 2021-04-22 00:07:07 +02:00
Daniel Gavin ca112c0b6d better placing of the end brace 2021-04-22 00:04:01 +02:00
Daniel Gavin 6eb64f2bdc align enum 2021-04-21 23:40:08 +02:00
Daniel Gavin 25c3b6dc95 align value decls 2021-04-21 23:21:45 +02:00
gingerBill 8077d5f565 Merge branch 'master' of https://github.com/odin-lang/Odin 2021-04-21 10:52:34 +01:00
gingerBill 6b45856e81 Remove useless error message for constant binary expressions with non-constant operations 2021-04-21 10:52:26 +01:00
gingerBill 28e5df6e7f Merge pull request #907 from awwdev/fix-variable-name-in-path_unix
fix variable name in path_unix
2021-04-20 21:14:25 +01:00
André 22867ec6f0 fix variable name in path_unix
replace the immutable variable "path" (that is a parameter) with a new variable "path_str"
2021-04-20 22:09:10 +02:00
gingerBill d0a50ff0a3 Merge pull request #905 from jasmcaus/patch-1
Fix potential Typo
2021-04-20 10:44:54 +01:00
gingerBill e9b1d4f633 Fix #906 2021-04-20 10:34:41 +01:00
gingerBill ba9f0dd553 Hack ABI for windows passing pointers to structures 2021-04-19 23:03:22 +01:00
gingerBill c3b3194a00 Update builtin procedures to support the new allocator features (without breaking other code) 2021-04-19 22:44:20 +01:00
gingerBill 201cad51a9 Fix typo 2021-04-19 22:41:52 +01:00
gingerBill d21e522208 Add code that was accidentally removed 2021-04-19 22:35:59 +01:00
gingerBill f1bdd2e60f Improve #optional_ok logic for procedures; Add #optional_second for package runtime usage 2021-04-19 22:31:14 +01:00
Daniel Gavin 3464784e5e add proc to format multiline 2021-04-19 19:41:53 +02:00
Daniel Gavin f1dc7c0b27 more work 2021-04-19 19:38:08 +02:00
gingerBill 0eb75886d1 Allow assignment of procedure calls with #optional_ok to single values 2021-04-19 16:02:36 +01:00
gingerBill 3612569624 Allow casting of #optional_ok call expressions 2021-04-19 15:46:12 +01:00
gingerBill c83d13d0cb Fix update_expr_type behaviour, along with fixing procedure groups updating the proc expr type 2021-04-19 15:12:10 +01:00
gingerBill f98c4d6837 Improve the Allocator interface to support returning Allocator_Error to allow for safer calls
Virtually all code (except for user-written custom allocators) should work as normal. Extra features will need to be added to make the current procedures support the `Allocator_Error` return value (akin to #optional_ok)
2021-04-19 12:31:31 +01:00
gingerBill a4d0092b16 Remove temporary reference types 2021-04-19 11:02:09 +01:00
gingerBill eb49b5f84a Fix override_entity_in_scope behaviour to correctly to report the changes upstream better 2021-04-19 11:01:00 +01:00
Jason Dsouza 9d949ef82e Fix potential Typo : S32 ==> I32 2021-04-19 11:41:02 +05:30
Daniel Gavin c708f649ec Merge remote-tracking branch 'upstream/master' into prototype-fmt 2021-04-19 02:13:29 +02:00
Daniel Gavin f7b8b3a340 ensure that the comments gets pushed if it's in the beginning before package 2021-04-18 22:06:32 +02:00
Daniel Gavin 2cbb3443d3 ran odinfmt 2021-04-18 21:53:52 +02:00
Daniel Gavin 11bd518f36 fix bugs 2021-04-18 21:52:00 +02:00
gingerBill ae04af4e4e Add package flags 2021-04-18 20:19:03 +01:00
gingerBill 3baddd4116 Improve init_string determination for constants 2021-04-18 20:13:20 +01:00
Daniel Gavin a721802337 fixing calls in calls 2021-04-18 21:07:58 +02:00
gingerBill 6ae468828c Improve odin-doc type information for Named types by storing the base type 2021-04-18 19:59:24 +01:00
gingerBill b59e110fec Add calling_convention to Type 2021-04-18 19:26:36 +01:00
gingerBill 4282688e60 Add calling_convention to odin-doc Type format 2021-04-18 19:26:21 +01:00
gingerBill 9b3fb25a41 Fix enumerated arrays for .odin-doc 2021-04-18 19:15:14 +01:00
gingerBill 2ce9873464 Remove dead comment 2021-04-18 18:53:19 +01:00
gingerBill 986844a0f0 Change elem_counts to i64le from u64 2021-04-18 18:48:56 +01:00
gingerBill 7c1f538c02 Change u32 to u32le 2021-04-18 18:46:29 +01:00
gingerBill 2f1c896290 Add -doc-format command for the new .odin-doc file format (to be used to generate documentation tools) 2021-04-18 18:33:15 +01:00
Daniel Gavin 5a8c7b4f90 support multiline for and if 2021-04-16 02:15:29 +02:00
Daniel Gavin f17fc05ff2 format call and binary expression 2021-04-16 00:44:16 +02:00
Daniel Gavin a12db382e0 damn, ran the odinfmt with spaces instead of tabs... 2021-04-15 00:24:00 +02:00
Daniel Gavin 22daa50374 ran the odinfmt - looks good, except for multi line binary operations 2021-04-15 00:19:13 +02:00
Daniel Gavin a09300fb0e more fixes 2021-04-15 00:11:10 +02:00
gingerBill 8827818b1d Clean-up fallback io.read_at and io.write_at behaviour 2021-04-14 21:25:46 +01:00
Daniel Gavin bab4e5531a remove print 2021-04-14 21:53:11 +02:00
gingerBill e19958152a Fix floattidf 2021-04-14 20:45:05 +01:00
gingerBill 05a181d719 Fix style issues; Use new attribute @(cold) where appropriate in the new sync package 2021-04-14 20:19:02 +01:00
gingerBill d24784074c Add extra error to io.Error 2021-04-14 20:17:54 +01:00
gingerBill cd2476e084 Add buffer_read_at buffer_write_at 2021-04-14 20:13:26 +01:00
gingerBill ebbc33fdb5 Mockup of the new package os interface (incomplete and non-functioning) 2021-04-14 19:39:12 +01:00
Daniel Gavin 1de928df78 fixed bug in parser on when 2021-04-14 18:43:04 +02:00
gingerBill 3a4373641b Correct call site attributes 2021-04-14 17:16:10 +01:00
gingerBill 9adec628c1 Add @(cold) attribute to procedure declarations 2021-04-14 17:15:28 +01:00
Daniel Gavin aded272b33 split stmts 2021-04-14 18:04:48 +02:00
Daniel Gavin b0721f1e0c aligning structs now work 2021-04-14 16:31:31 +02:00
Daniel Gavin 7e90ece84a more switch alignment work 2021-04-14 16:03:36 +02:00
Daniel Gavin 1f563f2810 work on switch alignment 2021-04-14 15:34:50 +02:00
gingerBill 3e54cddf64 Merge pull request #902 from Kelimion/run_as_user
Add support to core:windows to add/delete users.
2021-04-14 12:15:30 +01:00
gingerBill d602709133 Fix typo 2021-04-14 12:14:44 +01:00
Daniel Gavin c46317c00b fix os error 2021-04-14 02:20:05 +02:00
Daniel Gavin cb4b7efd3e only align comments in same indentation blocks 2021-04-14 01:57:42 +02:00
Daniel Gavin 411beaa3bf work on comments 2021-04-14 01:15:46 +02:00
Daniel Gavin 1cb3a31f32 have to sort attributes because they are not ordered by position(maybe bug on parser) 2021-04-14 00:53:34 +02:00
Daniel Gavin c99afd04ad work 2021-04-14 00:08:09 +02:00
Daniel Gavin 3157467e4b bring over the odinfmt code 2021-04-13 23:59:40 +02:00
Daniel Gavin 2001384ae6 make sure to print comments at the end of the file 2021-04-13 23:52:23 +02:00
Daniel Gavin b09e53d7fe now aligning comments 2021-04-13 23:42:58 +02:00
gingerBill 8e1120bc09 Fix typo 2021-04-13 19:23:12 +01:00
Daniel Gavin d046c9c072 at the same point as the previous formatter now 2021-04-13 20:18:50 +02:00
gingerBill ebed29fc09 Revert *nix thread stuff to old sync
(I was just testing)
2021-04-13 19:09:04 +01:00
gingerBill bee8beb2c9 Default to pthreads in sync2 for *nix 2021-04-13 19:04:44 +01:00
gingerBill 12296a0dcc Allow intrinsics entities to be exported from other packages if wanted 2021-04-13 18:57:47 +01:00
Daniel Gavin 2e8da35851 multiline comments work 2021-04-13 15:27:04 +02:00
Jeroen van Rijn 2942e45ff5 Placate -vet for unrelated core:thread update. 2021-04-13 02:23:14 +02:00
Jeroen van Rijn aca5c7c1c6 Placate -vet. 2021-04-13 02:18:47 +02:00
Jeroen van Rijn a1d871360c Add support to core:windows to add/delete users.
main :: proc() {

	using fmt;
	using windows;

	username := "testuser";
	password := "testpass";

	ok := add_user("", username, password);
	fmt.printf("add_user: %v\n", ok);
	pi := windows.PROCESS_INFORMATION{};

	ok2, path := windows.add_user_profile(username);
	fmt.printf("add_user_profile: %v, %v\n", ok2, path);

	ok3 := windows.delete_user_profile(username);
	fmt.printf("delete_user_profile: %v\n", ok3);

	ok4 := windows.delete_user("", username);
	fmt.printf("delete_user: %v\n", ok4);

	// Has optional bool to not wait on the process before returning.
	b := run_as_user(username, password, "C:\\Repro\\repro.exe", "Hellope!", &pi);
	fmt.printf("run_as_user: %v %v\n", b, pi);
}
2021-04-13 02:09:44 +02:00
Daniel Gavin 1d3458cadb single line comments work 2021-04-12 22:35:26 +02:00
gingerBill 2b36069924 Fix typo 2021-04-12 17:13:05 +01:00
Daniel Gavin 9139ca4673 more work on fmt 2021-04-12 17:01:43 +02:00
gingerBill 4fb4ada2c7 Update sync2 to just use atomic intrinsics rather than the parapoly wrappers 2021-04-12 15:22:40 +01:00
gingerBill e3ee005404 Clean up path_unix.odin to make it not depend on package os 2021-04-11 19:05:01 +01:00
gingerBill e8bf1f2064 Minor fixes to platform checking code 2021-04-11 18:59:54 +01:00
Daniel Gavin e0e6bba865 start new prototype 2021-04-11 19:47:33 +02:00
gingerBill 1156bd9dd0 Remove thread stuff from sync2; Cleanup package thread 2021-04-11 18:25:56 +01:00
gingerBill 52c193316b Add Thread stuff to new sync package 2021-04-11 15:36:55 +01:00
gingerBill 2db1fe7429 New redesign of core:sync (stored under core:sync/sync2 for the time being) 2021-04-11 15:18:28 +01:00
gingerBill 5bc9e4e4f7 Merge pull request #901 from atkurtul/swarning
fix Syntax Warning
2021-04-09 11:28:06 +01:00
gingerBill 2d99a348b8 Fix proc literal bug not finding the associated DeclInfo 2021-04-09 11:27:44 +01:00
Gitea 011c8d5cda fix Syntax Warning 2021-04-09 13:03:01 +03:00
vassvik 8169cb4853 Fix missing newlines in core:math/linalg/specific.odin 2021-04-09 09:21:20 +02:00
gingerBill 18ab7fb68b Add break; for sanity 2021-04-08 15:32:59 +01:00
gingerBill 3eaf3327d4 Add "Dwarf Version" metadata for darwin on -llvm-api 2021-04-08 15:06:23 +01:00
gingerBill d721ffa6fa Add assertion check on parameter types for lb_emit_call_internal 2021-04-06 11:26:57 +01:00
gingerBill 535048e2b3 Fix LLVMConstIntOfArbitraryPrecision usage for a pointer 2021-04-06 11:07:05 +01:00
gingerBill 050d6f670e Merge pull request #896 from Platin21/Master-Origin
Add's Handling for Return Values for Linker-Stage
2021-04-05 19:06:04 +01:00
Platin21 ae7d7d33d4 Merge remote-tracking branch 'origin/master' into Master-Origin 2021-04-05 19:57:58 +02:00
gingerBill 19470683e7 Add runtime.extendhfsf2 to dependency list 2021-04-05 18:57:09 +01:00
gingerBill 394e4fcbad Add __extendhfsf2 for macOS 2021-04-05 18:44:08 +01:00
Platin21 f722cceef0 Removed debug code 2021-04-05 19:35:03 +02:00
Platin21 66fb2a94ee Adds return values to linker stages 2021-04-05 19:28:19 +02:00
gingerBill f78b2a6090 Undo fix 2021-04-03 18:04:39 +01:00
gingerBill 46bf39cae1 Fix lb_emit_array_ep 2021-04-03 18:03:36 +01:00
gingerBill 46c5c7d1ec Experiment with different opt passes 2021-04-01 23:41:01 +01:00
gingerBill bcda9ddee7 Add core:math/fixed 2021-04-01 17:09:34 +01:00
gingerBill 4a66cbb1f4 Fix signed fixed arithmetic intrinsics 2021-04-01 17:08:34 +01:00
gingerBill f0392d0c75 Cleanup again 2021-04-01 15:46:07 +01:00
gingerBill 3bd39886a0 Cleanup code for fixed-point intrinsics 2021-04-01 15:43:50 +01:00
gingerBill cef698afd6 Implement fixed-point arithmetic intrinsics for -llvm-api backend 2021-04-01 14:36:06 +01:00
gingerBill 0fc04a939e Add f16 support to core:math/linalg 2021-04-01 11:12:40 +01:00
gingerBill 3e1b4c17ac Fix alignment for complex32 and quaternion64 2021-04-01 11:10:17 +01:00
gingerBill b3e788b9d9 Fix missing complex32/quaternion64 checks 2021-04-01 10:56:57 +01:00
gingerBill 63bb26c0e0 Add f16 specific procedures to core:math 2021-04-01 10:52:46 +01:00
gingerBill b3dce34bc6 Add min(f16) and max(f16) support 2021-04-01 10:35:07 +01:00
gingerBill 491b282615 Add extra optimization level pass -opt:2 in lb_populate_module_pass_manager 2021-04-01 10:31:46 +01:00
gingerBill 54e6c50769 Implement f16 functionality 2021-04-01 10:06:00 +01:00
gingerBill a00d7cc705 Merge pull request #884 from corruptmemory/corruptmemory/better-define-errors
Helpful error message for invalid `-define:` cases
2021-03-30 21:59:03 +01:00
Jim Powers 9757af5e4a Helpful error message for invalid -define: cases 2021-03-30 16:49:18 -04:00
gingerBill 3359d0323a Change >> behaviour in LLVM to prevent stupid UB 2021-03-30 20:38:04 +01:00
gingerBill fbd01660ee Experiment with new grammatical parsing rule for expression level (-strict-style) idea 2021-03-30 11:48:32 +01:00
gingerBill bc5e80d7d6 Merge pull request #885 from DanielGavin/parser
Parser fixes
2021-03-30 11:47:45 +01:00
DanielGavin c429c85ade Merge remote-tracking branch 'upstream/master' into parser 2021-03-30 12:42:11 +02:00
DanielGavin 02bbac0903 changed error 2021-03-30 12:40:40 +02:00
DanielGavin b8658547e0 Give error if raw literal hits EOF, and stop removing .Using if it exists in flags and allowed_flags. 2021-03-30 12:38:58 +02:00
gingerBill 2c14accfd0 Merge pull request #879 from Kelimion/partial_hash_updates
Allow seeding CRC32, CRC64 & Adler32 with previous partial hash.
2021-03-30 11:20:19 +01:00
gingerBill 439e2c9242 Fix shifting limits and LLVM code gen bug relating to shifts 2021-03-29 23:15:31 +01:00
gingerBill 6fb0868517 Remove dead code and comments 2021-03-29 22:45:36 +01:00
gingerBill e1588c9322 Remove LLVMPassManagerBuilder usage in lb_populate_module_pass_manager; simplify lb_populate_function_pass_manager 2021-03-29 22:04:54 +01:00
gingerBill 8fcc6ca464 Add LLVM_USE_NO_EXTRA_PASSES build flag 2021-03-29 16:51:06 +01:00
gingerBill faa0240900 Change how lb_populate_module_pass_manager handles the LLVMPassManagerBuilder calls 2021-03-29 16:40:39 +01:00
gingerBill 66941aed0a Clamp maximum optimization level to 2 for -llvm-api 2021-03-29 15:51:15 +01:00
gingerBill fc8c94324e Fix typo 2021-03-29 15:43:33 +01:00
gingerBill 8c20ac1bf0 Add optional LLVM_USE_BASIC_PASSES build flag. If evaluates to a truthy value, it will be do only basic passes for -llvm-api 2021-03-29 14:55:37 +01:00
gingerBill 371094b067 Remove LLVMAddScalarReplAggregatesPass from passes 2021-03-29 14:50:09 +01:00
gingerBill c1e125a009 Change alignment of alloca to a larger one if OdinLLVMBuildTransmute requires it 2021-03-29 14:31:26 +01:00
gingerBill 48767301a4 Another minor change to OdinLLVMBuildTransmute regarding minimum source alignment 2021-03-29 14:11:02 +01:00
gingerBill 253a3edd30 Change OdinLLVMBuildTransmute when to deal with loads 2021-03-29 14:07:25 +01:00
gingerBill 8239cd34eb Issue #823 - Change semantics of disabled attribute to not evaluate any of the parameters at run time 2021-03-27 17:59:01 +00:00
gingerBill 818942b72e Minor code style change 2021-03-27 17:26:38 +00:00
gingerBill 9bac9af022 Clean up code for record type checking 2021-03-27 17:25:56 +00:00
gingerBill 342761e83a Refactor record polymorphic params code for unification 2021-03-27 17:21:12 +00:00
gingerBill 87bc9275fe Correct poly type determination of a where clause for an enumerated array 2021-03-27 16:49:56 +00:00
gingerBill 5ade037b7d Refactor polymorphic parameter for records; Improve error message for parametric polymorphic enumerated array index types 2021-03-27 16:42:42 +00:00
gingerBill 1e587d6635 Fix #883 - polymorphic specialization with target types of enumerated arrays 2021-03-27 15:22:05 +00:00
gingerBill e21d716720 Fix endian conversion to and from floats and ints 2021-03-27 14:33:33 +00:00
gingerBill d62ff39e60 Remove extra passes 2021-03-27 13:30:15 +00:00
gingerBill 0ccf103160 Fix byte swapping for endian specific types in -llvm-api 2021-03-27 12:48:29 +00:00
gingerBill 01c2662de4 Simplify ir_print.cpp escape byte code 2021-03-27 12:17:12 +00:00
gingerBill bd607b131e Fix #882 2021-03-27 12:13:17 +00:00
gingerBill 43ac6ca8f4 Add linalg.matrix_cast 2021-03-26 16:24:56 +00:00
gingerBill 62d2656f69 Add linalg.matrix_cast 2021-03-26 14:33:46 +00:00
gingerBill a611cf545d Add basic error correction in parser to check for unattached else 2021-03-26 11:39:46 +00:00
gingerBill 7463ad23d8 Move variable declarations to aid other compilers 2021-03-25 22:59:15 +00:00
gingerBill 6271d10af7 Fix to OdinLLVMBuildTransmute to goto general_end on different sized data 2021-03-25 22:54:49 +00:00
gingerBill c5c82e0551 Fix pseudo-constant local slice initialization 2021-03-25 22:47:23 +00:00
gingerBill 29ed1d5459 Minor zero enforcement 2021-03-25 22:34:35 +00:00
gingerBill 50b439daa8 Fix pseudo-constant local embedded slice generation 2021-03-25 22:27:52 +00:00
gingerBill 23c68b4f7a Change to assert to test both LLVMIsConstant and LLVMIsGlobalConstant 2021-03-25 22:14:38 +00:00
gingerBill 615104afd1 Revert change :D 2021-03-25 20:59:24 +00:00
gingerBill d3665331c7 Another minor fix to OdinLLVMBuildTransmute 2021-03-25 20:47:10 +00:00
gingerBill 04be6d190e Minor fix to OdinLLVMBuildTransmute 2021-03-25 20:45:22 +00:00
gingerBill 6668fd44cf Merge branch 'master' of https://github.com/odin-lang/Odin 2021-03-25 20:23:49 +00:00
gingerBill 0007ac63ed Correct #c_vararg behaviour on -llvm-api 2021-03-25 20:23:43 +00:00
gingerBill f656968aea Merge pull request #880 from breeo7/master
Add `container.Priority_Queue`
2021-03-25 16:02:22 +00:00
breeo 24e7b5ea78 Add container.Priority_Queue 2021-03-25 15:50:33 +01:00
Jeroen van Rijn f4d0f74dbb Allow seeding CRC32, CRC64 & Adler32 with previous partial hash.
Foo  := []u8{'F', 'o','o', '3', 'F', 'o', 'o', '4'};
crc     := hash.crc32(Foo[0:4]);
crc      = hash.crc32(Foo[4:], crc);
crc_all := hash.crc32(Foo);

fmt.printf("%8x %8x\n", crc, crc_all);
d6285ff7 d6285ff7

a32     := hash.adler32(Foo[0:4]);
a32      = hash.adler32(Foo[4:], a32);
a32_all := hash.adler32(Foo);

fmt.printf("%8x %8x\n", a32, a32_all);
0c5102b0 0c5102b0
2021-03-25 13:48:34 +01:00
gingerBill 7c951cbf0a Add SOA struct len/cap/allocator fields for the debug symbols 2021-03-24 23:12:54 +00:00
gingerBill 2d0e2625ac Ensure pointers are of the same type in LLVM ICmp 2021-03-24 23:01:48 +00:00
gingerBill 1aecd7f5ff Add support for soa slice reference iteration 2021-03-24 22:39:29 +00:00
gingerBill 5faf859a56 Support using on intermediate soa field value from a for-in statement 2021-03-24 22:34:55 +00:00
gingerBill 7028797d53 Implement soa_unzip 2021-03-24 19:29:25 +00:00
gingerBill 6c9d3715d8 Add type hinting to soa_zip 2021-03-24 18:08:34 +00:00
gingerBill 989a03dc77 soa_zip (-llvm-api only): creates an #soa[]struct from passed slices
x := []i32{1, 3, 9};
y := []f32{2, 4, 16};
z := []b32{true, false, true};

s_anonymous := soa_zip(x, y, z);
assert(s_anonymous[0]._1 == 2);

s_named := soa_zip(a=x, b=y, c=z);
assert(s_anonymous[0].b == 2);
2021-03-24 17:33:05 +00:00
gingerBill 7a045bd957 Merge pull request #877 from Kelimion/datetime
Add core:datetime_to_time
2021-03-24 16:59:19 +00:00
gingerBill a5329ae48c Add better package declaration specific error message (#878) 2021-03-24 14:34:30 +00:00
gingerBill 2ec3326653 Support #soa array iteration in a for in loop for -llvm-api backend only 2021-03-24 14:31:44 +00:00
gingerBill bec42e8dd3 Improve core:odin/ast ast.Range_Stmt to use generic number of vals rather than the fixed two to aid with parsing errors 2021-03-24 12:34:06 +00:00
gingerBill d969d0b264 Make for in logic a bit more generic 2021-03-24 12:31:05 +00:00
gingerBill 0e3ecc350a Make the parser support as many identifiers on the LHS in for in loops to improve error messages 2021-03-24 12:11:00 +00:00
gingerBill 295c1550a8 Support using variables in debug information 2021-03-24 10:57:00 +00:00
gingerBill fc1a352285 For bit_set, allow + and - to be aliases for | and &~, respectively 2021-03-23 23:34:01 +00:00
gingerBill 082381284c Remove dead code 2021-03-23 23:23:40 +00:00
gingerBill ccd078620b Improve error message in parser 2021-03-23 23:05:00 +00:00
gingerBill 08f7d3edbe Allow $ in polymorphic record parameter fields (but disallow mixing) 2021-03-23 22:59:10 +00:00
gingerBill c62980eaea Minor improvement to error message about assigning a type to a variable with no inference 2021-03-23 22:33:32 +00:00
gingerBill d88d6a1fdd bit_set support in debug symbols by treating them like a bit field of 1 bit booleans 2021-03-23 22:09:16 +00:00
gingerBill f1e13bdddb Prefix named types with package name in debug types 2021-03-23 20:45:39 +00:00
gingerBill 331167e91f Improve debug type names for composite types (arrays, map, struct, union) 2021-03-23 20:41:49 +00:00
gingerBill e229882fde Clean up some debug type code 2021-03-23 19:33:22 +00:00
gingerBill 300f988905 Add global variables to -llvm-api debug information 2021-03-23 18:34:20 +00:00
gingerBill 7f6a43f0af Move LLVM optimization procedures to a separate file to aid with organization 2021-03-23 18:24:49 +00:00
Jeroen van Rijn 06c5a7fb3e Correct overflowed months. 2021-03-23 18:49:50 +01:00
Jeroen van Rijn 781f784375 Add core:datetime_to_time
datetime_to_time takes separate parameters for date and time values and returns a time.Time and an `ok` bool.

If the values are out of range, they're considered modulo and ok will be set to false.
2021-03-23 18:41:40 +01:00
gingerBill ccd91aee5c Fix debug information for typeid on -llvm-api 2021-03-22 16:14:58 +00:00
gingerBill bf46a3f1d3 Correct debug info for basic composite types (e.g. string, any) 2021-03-22 15:36:18 +00:00
gingerBill 8ab1b32fe1 Add local debug variable support for -llvm-api 2021-03-22 14:51:19 +00:00
gingerBill 0355908af8 Start work on very basic LLVM debug type information 2021-03-22 13:09:23 +00:00
gingerBill fd7d70954e Begin integrating work from branch llvm-debug-symbols 2021-03-20 13:10:53 +00:00
gingerBill cb0bd80f50 Fix LLVMConstArray usage 2021-03-19 16:59:46 +00:00
gingerBill 5a67e6ecbd Fix LLVM asserts 2021-03-19 16:53:22 +00:00
gingerBill c8a823a387 Add ExternC.h 2021-03-19 15:49:07 +00:00
gingerBill 178e891c78 Fix some LLVM asserts by using LLVMConstNamedStruct everywhere 2021-03-19 15:47:10 +00:00
gingerBill bda9eb7348 Update llvm-c headers for Version 11.0.1 2021-03-19 15:46:33 +00:00
gingerBill 2b806f7463 Merge pull request #875 from atkurtul/master
Run an early memcpy pass regardless of the opt flag and return large structs by pointer on linux
2021-03-19 11:07:12 +00:00
atkurtul 6de0b68928 Merge pull request #2 from atkurtul/main
early memcpyopt
2021-03-19 10:26:10 +03:00
atkurtul bb6e6fb4ef Merge pull request #1 from atkurtul/llvm
return by pointer on linux
2021-03-19 07:30:18 +03:00
atil 5f5dfdc00e return by pointer on linux 2021-03-19 07:28:27 +03:00
Atil Kurtulmus 88b8052532 fix windows 2021-03-19 07:23:17 +03:00
atil 2c0ddfb5db fixtypo 2021-03-19 09:57:38 +03:00
atil 2f4902c9b9 fixtypo 2021-03-19 09:54:28 +03:00
atil d28f6144a4 early memcpyopt 2021-03-19 09:52:53 +03:00
gingerBill 3337412228 split*_iterator procedures for package bytes and strings 2021-03-18 13:26:33 +00:00
gingerBill e3f9d99a3b Merge branch 'master' of https://github.com/odin-lang/Odin 2021-03-18 13:25:47 +00:00
gingerBill 359ae29d98 Minor fixes 2021-03-18 13:25:41 +00:00
gingerBill 453b756edc Merge pull request #872 from Kelimion/fix-cubic
Fix typo in cubic().
2021-03-16 15:36:34 +00:00
Jeroen van Rijn d80670fe0c Fix typo in cubic(). 2021-03-16 16:34:59 +01:00
gingerBill 04e0cacd30 Update package core:math/linalg to support matrix3 euler angle operations 2021-03-16 12:14:54 +00:00
gingerBill b94ab4dc05 Make check_single_global_entity use create_checker_context 2021-03-15 14:05:38 +00:00
gingerBill 85fd8aaf37 Merge pull request #868 from nakst/patch-1
Make size of allocation multiple of the alignment
2021-03-15 11:47:48 +00:00
gingerBill 6412a18ae1 Merge pull request #869 from nakst/patch-2
Similar to the update to gb.h
2021-03-14 20:53:30 +00:00
Nakst acefb2edbc Similar to the update to gb.h 2021-03-14 20:37:32 +00:00
Nakst 0d1addf0d4 Make size of allocation multiple of the alignment
To silence an error from GCC's address sanitizer.
2021-03-14 20:36:35 +00:00
gingerBill f5142aaec4 Change from test_* prefix to @(test) attribute for odin test 2021-03-14 18:43:21 +00:00
gingerBill db0ac2ba98 Add "NO TESTS RAN" message to testing.runner if no tests were ran 2021-03-14 18:17:00 +00:00
gingerBill 468ad4837b Add pkg field to testing.Internal_Test 2021-03-14 18:15:08 +00:00
gingerBill 2aa588209e odin test to work with the new core:testing package 2021-03-14 18:01:31 +00:00
gingerBill 10f91a0d3f Make base32 and base64 adhere to -strict-style 2021-03-14 12:54:28 +00:00
gingerBill 8cc4cba06c Add support for backslash \ to consume a newline 2021-03-14 12:53:57 +00:00
gingerBill 8f6439fa6b Simplify expect_semicolon_newline_error rule 2021-03-13 23:17:56 +00:00
gingerBill 81efd2dc64 Remove && false from test code 2021-03-13 21:39:33 +00:00
gingerBill b5c0c68615 Add -strict-style flag: Enforces code style stricter whilst parsing, requiring such things as trailing commas 2021-03-13 21:20:46 +00:00
gingerBill a60d22fefd Make trailing comma usage consistent 2021-03-13 21:18:07 +00:00
gingerBill 8123ff83a3 Fix is_diverging_stmt for invalid statements 2021-03-13 15:01:23 +00:00
gingerBill 4e2a2ac80a Fix formatting of code 2021-03-10 10:53:30 +00:00
gingerBill d23c10d80e Merge pull request #865 from matias-eduardo/patch_llvm_bool_return_types
Add LLVM boolean compatibility to result types
2021-03-10 09:48:57 +00:00
Matias Fernandez ba62bcf116 Add LLVM boolean compatibility to result types 2021-03-09 23:17:34 -04:00
gingerBill 84bb349900 Merge branch 'master' of https://github.com/odin-lang/Odin 2021-03-09 11:40:42 +00:00
gingerBill 3ff7bded64 Add intrinsics.volatile_store and intrinsics.volatile_load 2021-03-09 11:40:36 +00:00
gingerBill 8784b79482 Merge pull request #862 from Kelimion/kelimion/master
Remove double removal of extension when using the -out option.
2021-03-06 23:15:09 +00:00
gingerBill d0f923ba74 Merge pull request #863 from jlreymendez/dll_build_fix
Fix nullref access violation when building with no entry point
2021-03-06 23:14:55 +00:00
Jose Luis Rey Mendez 4e8ec4ce38 Fix nullref access violation when building with no entry point 2021-03-06 20:02:16 -03:00
Jose Luis Rey Mendez 4f1fb73f32 Added vs code to git ignore 2021-03-06 20:01:11 -03:00
Jeroen van Rijn cefde23232 Remove double removal of extension when using the -out option.
When specifying the out parameter, the extension was stripped twice.
If your path contains a ".", this caused issues.

e.g.
cd "C:\Repro\Path With a . In The Name\"
odin run repro.odin -keep-temp-files -out repro.exe

This would cause the files to end up as:
"C:\Repro\Path With a.exe", "C:\Repro\Path With a.ll", "C:\Repro\Path With a.bc" and "C:\Repro\Path With a.obj"

With this patch it works as expected, with or without a . in the file path.
2021-03-06 23:09:15 +01:00
gingerBill 083cec6c88 Remove dead code 2021-03-06 16:11:54 +00:00
gingerBill 45cd5c0b1c Remove test code 2021-03-06 16:11:39 +00:00
gingerBill 572b9d1b3f Fix context bug with deferred_* attributes which caused a new context to be created every time 2021-03-06 16:11:01 +00:00
gingerBill 0ae1b96182 Fix ir_print.cpp i32 line/column values 2021-03-05 15:42:59 +00:00
gingerBill 1988856eed Minimize the size of runtime.Source_Code_Location to use i32 instead of int 2021-03-05 12:56:36 +00:00
gingerBill 15dbc99cb9 Minimize TokenPos size by using i32 for line/column/offset and file_id instead of String
To make `i32` safe, the parser limits the file size of odin files to a maximum of 2GiB (which will be good enough for the vast vast majority of cases)
2021-03-04 16:45:30 +00:00
gingerBill 17eb0ce525 Minor update to math/linalg 2021-03-03 22:18:18 +00:00
gingerBill 619a977856 Improve math/linalg to support both f32 and f64 basic procedures for the specific*.odin files 2021-03-03 16:44:41 +00:00
gingerBill b727b6438b Minimize unneeded casts 2021-03-03 14:31:17 +00:00
gingerBill 75f127af7c Add -vet-extra (checks for unneeded casts and transmutes) 2021-03-03 14:17:48 +00:00
gingerBill c2794b62a9 Clean up logic for << and >> behaviour 2021-03-02 16:48:39 +00:00
gingerBill 4e63ab5edc Re-enable "LLVM Function Pass" 2021-03-02 13:36:57 +00:00
gingerBill 2a1bec9fbb Clean up lb_end_procedure_body logic 2021-03-02 00:43:25 +00:00
gingerBill 6faf024ab4 Remove unneeded return value from incl and excl 2021-03-02 00:40:40 +00:00
gingerBill 35edf45514 Add make_soa and delete_soa; Reorganize soa procedures into a separate file 2021-03-01 18:07:09 +00:00
gingerBill 667aa3671e Fix Addressing for SOA on store; Add intrinsics.type_struct_field_count(T) 2021-03-01 17:54:49 +00:00
gingerBill b428e9ee14 Improve lb_end_procedure_body logic 2021-03-01 15:14:21 +00:00
gingerBill 868117cddd Remove hack in lb_addr_store 2021-03-01 12:59:17 +00:00
gingerBill 9e0210f7f6 Merge branch 'master' of https://github.com/odin-lang/Odin 2021-03-01 12:15:38 +00:00
gingerBill 302742689b Patch win64 ABI problem caused by a bug in LLVM for 128 bit integers 2021-03-01 12:15:28 +00:00
gingerBill 6ffb4d2683 Minor changes to function pass manager in llvm_backend.cpp 2021-02-27 17:47:57 +00:00
gingerBill 4f298a5314 Fix LLVM -opt:2 bug for initializing global variables 2021-02-27 15:54:22 +00:00
gingerBill f49278b5f4 Merge pull request #855 from nakst/master
Update Essence API header
2021-02-27 11:34:38 +00:00
gingerBill a2557142cc Update package os for package path/filepath support on macOS 2021-02-27 11:30:43 +00:00
gingerBill fa09640e7e Fix slice.concatenate 2021-02-27 10:58:10 +00:00
gingerBill 1f9a2df42b Fix crash when a forced dependency doesn't exist 2021-02-27 10:57:44 +00:00
gingerBill ee04dde7c2 HACK check_unchecked_bodies further! 2021-02-26 15:34:12 +00:00
gingerBill 88599eeac1 Update build-m1.sh to remove unneeded macro define 2021-02-26 15:29:41 +00:00
gingerBill 54194af71c Fix patch (yeah... I know) 2021-02-26 15:29:10 +00:00
gingerBill 575c7ff031 Patch issue with minimum dependency system and how it interacts with para poly procedures 2021-02-26 15:09:32 +00:00
nakst 7b4ddd9b18 update essence API header 2021-02-26 14:46:38 +00:00
gingerBill ac155d9036 Merge branch 'master' of https://github.com/odin-lang/Odin 2021-02-26 10:56:40 +00:00
gingerBill d772710ae7 Add message to assert in ir_build_expr_internal 2021-02-26 10:56:32 +00:00
gingerBill 172fc9a46c Merge pull request #853 from ttvd/master
Fixing a typo in llvm backend.
2021-02-25 19:13:49 +00:00
Mykola Konyk 8182d9e828 Fixing a typo in llvm backend. 2021-02-25 13:13:25 -05:00
gingerBill d0ac9f605d Merge branch 'master' of https://github.com/odin-lang/Odin 2021-02-25 13:17:07 +00:00
gingerBill 3eae69effc Make USE_NEW_LLVM_ABI_SYSTEM the actual behaviour and remove the previous approach 2021-02-25 13:17:00 +00:00
gingerBill 53e4c536a1 Merge pull request #852 from Tetralux/fix-dll-mac
Fix -build-mode:shared on Darwin
2021-02-25 12:17:29 +00:00
gingerBill 84deee75cc Make lb_create_enum_attribute ignore certain attributes (they are not properly supported by the actual LLVM C API) 2021-02-25 11:39:46 +00:00
gingerBill 82275082ff Add #force_inline parsing directly to expression statements 2021-02-25 10:01:12 +00:00
gingerBill fc48e9638a Merge branch 'master' of https://github.com/odin-lang/Odin 2021-02-25 09:55:56 +00:00
gingerBill 4a69bfada1 Remove #force_inline for and only have #unroll for 2021-02-25 09:55:48 +00:00
gingerBill 4d13a43590 Enforce -llvm-api on Mac M1 2021-02-25 00:39:44 +00:00
gingerBill b2fdb53e26 fix timings.cpp for M1 2021-02-25 00:39:26 +00:00
gingerBill 58422711d1 Remove sret attribute in llvm_abi.cpp 2021-02-25 00:22:47 +00:00
gingerBill ba817d153c Get compiling on Mac Mini M1 2021-02-24 23:21:34 +00:00
gingerBill 2d88c6c6a5 Begin work on aarch64 ABI for -llvm-api 2021-02-24 16:49:19 +00:00
gingerBill a6fdb5eb5e Add -DUSE_NEW_LLVM_ABI_SYSTEM by default to Windows build for -llvm-api 2021-02-24 16:00:05 +00:00
gingerBill 425bb0579e Default to -microarch:generic 2021-02-24 15:59:31 +00:00
Tetralux a9af8b093d Fix -build-mode:shared on Darwin
Apparently, the '__$startup_runtime' symbol to initialize RTTI stuff has
three underscores (not two) on Darwin!
2021-02-24 02:18:47 +00:00
gingerBill 8f9111e552 Build tag to make all declarations within a file private to the package //+private 2021-02-23 20:40:48 +00:00
gingerBill 731e6ca3a6 Merge branch 'master' of https://github.com/odin-lang/Odin 2021-02-23 20:40:09 +00:00
gingerBill 79eb46bce3 Replace inline uses in the rest of core with #force_inline 2021-02-23 20:39:59 +00:00
gingerBill d39d238754 Merge pull request #851 from WalterPlinge/master
Fixed linalg distance function return type
2021-02-23 20:17:47 +00:00
WalterPlinge 0e9dee62bf Update extended.odin 2021-02-23 20:10:43 +00:00
gingerBill 533dde4648 Add deprecation message for inline and no_inline to use #force_inline and #force_no_inline instead 2021-02-23 16:22:28 +00:00
gingerBill 6988b12012 Replace inline with #force_inline in sys/es/api.odin 2021-02-23 16:15:37 +00:00
gingerBill aa93305015 Replace usage of inline proc with #force_inline proc in the core library 2021-02-23 16:14:47 +00:00
gingerBill 41b854f192 Remove #opaque types 2021-02-23 15:45:06 +00:00
gingerBill 28f279329d Remove bit_field keyword and parsing logic 2021-02-23 15:29:54 +00:00
gingerBill fe33a64b2e Remove #opaque usage in core library 2021-02-23 15:21:05 +00:00
gingerBill f95185a16e Fix new flags 2021-02-23 15:05:03 +00:00
gingerBill 01313eec7f Add flags -ignore-warnings and -warnings-as-errors 2021-02-23 14:59:28 +00:00
gingerBill a1693c0184 Deprecate inline for in favour of #unroll for 2021-02-23 14:45:15 +00:00
gingerBill 657c0ac4f5 Update odin/parser 2021-02-23 14:38:46 +00:00
gingerBill 908a403d78 Add #force_inline, #force_no_inline and #unroll for the transition to deprecate and then remove the keywords inline and no_inline
`inline for` will be replaced with `#unroll for`
2021-02-23 14:37:05 +00:00
gingerBill 28ed310f31 Remove "pure" and "pure_none" calling conventions 2021-02-23 13:10:23 +00:00
gingerBill a652c24ac3 Remove opaque keyboard 2021-02-23 13:02:18 +00:00
gingerBill 595885d3db Remove bit_field in type info, runtime, and general core library 2021-02-19 11:36:23 +00:00
gingerBill efdee0dafb Remove bit_field type from Odin (keyword and dead runtime code still exists) 2021-02-19 11:31:14 +00:00
gingerBill f332cf498d Merge branch 'master' of https://github.com/odin-lang/Odin 2021-02-19 00:05:02 +00:00
gingerBill 6ae619c0a6 Add to package math/bits bitfield_extract and bitfield_insert 2021-02-19 00:04:48 +00:00
gingerBill 7ea86f9c91 Merge pull request #844 from DanielGavin/master
Incorrect setting of allocators in stat_linux and read_dir includes itself and parent
2021-02-12 22:44:22 +00:00
DanielGavin 0f11c47579 set the correct allocators and ignore the previous and parent directory in readdir. 2021-02-12 23:22:53 +01:00
gingerBill 5cced38a6e Add kernel32 memory api 2021-02-11 15:31:51 +00:00
gingerBill d5dfa14f18 Clear up fmt.wprint* length logic 2021-02-11 10:44:38 +00:00
gingerBill fa02dc9736 Fix #840 2021-02-11 10:15:58 +00:00
gingerBill 92431c83ec Change default_temp_allocator_proc behaviour to use the default_allocator when the backing data has not been set. 2021-02-09 14:00:59 +00:00
gingerBill f5418837f0 Minor style clean up 2021-02-04 15:02:07 +00:00
gingerBill 825c5a963f Improve fmt's %#v behaviour for nested records 2021-02-04 14:52:23 +00:00
gingerBill f50ea36c70 Fix miscorrect type usage 2021-02-04 14:24:42 +00:00
gingerBill de9b6e3f6e Correct sys/win32 to match sys/windows 2021-02-04 13:50:48 +00:00
gingerBill 415379e1cf Fix delete_map 2021-02-02 16:30:34 +00:00
gingerBill d168c7936e Fix slices of slices in procedures for -llvm-api 2021-01-27 15:56:32 +00:00
gingerBill aed63a6e8b Update package reflect 2021-01-27 15:27:59 +00:00
gingerBill 98521618e6 Merge branch 'master' of https://github.com/odin-lang/Odin 2021-01-27 15:27:45 +00:00
gingerBill e64eb74eef Fix #831 2021-01-27 15:27:38 +00:00
gingerBill 31528f5ea2 Merge pull request #836 from laleksic/master
Mirror Windows interface for Linux in os module
2021-01-26 12:29:33 +00:00
Luka Aleksić ac184957db Fix CI 2021-01-21 20:55:58 +01:00
Luka Aleksić 92e23ec397 * Add some procedures to path_unix to mirror the path_windows API
* Add files stat_linux and dir_linux to mirror the stat/dir_windows API
* Add helper functions to os_linux that are used by the above
2021-01-21 20:20:38 +01:00
gingerBill c71c86f563 Merge pull request #821 from corruptmemory/corruptmemory/fix-for-c_vararg
Fix for `c_vararg` issue
2021-01-21 16:09:50 +00:00
gingerBill 773be83cad Merge pull request #835 from laleksic/master
Tracking allocator now tracks bad free calls
2021-01-21 16:09:20 +00:00
gingerBill e789e1eac1 Merge pull request #834 from DanielGavin/master
Invalid expression causes segmentation fault in parse_binary_expr in core/odin package
2021-01-21 16:08:30 +00:00
Luka Aleksić 00ebc877a1 Tracking allocator now tracks bad free calls 2021-01-21 00:19:56 +01:00
DanielGavin 3224869c29 handle expr is null in parse_binary_expr 2021-01-20 16:10:16 +01:00
DanielGavin 38c6182280 Merge branch 'master' of https://github.com/DanielGavin/Odin 2021-01-20 16:05:15 +01:00
Jim Powers 24db60eb4b Fix for c_vararg issue
Fixes #817
2021-01-18 20:05:33 -05:00
gingerBill 53d8ec4d15 Add extra error checks 2021-01-18 11:34:09 +00:00
gingerBill 2990b3efd5 Fix #825 2021-01-17 11:59:51 +00:00
gingerBill c653e400db Add extra error checking in parser.cpp 2021-01-15 16:15:03 +00:00
gingerBill e884f8c165 Fix typo 2021-01-15 15:46:15 +00:00
gingerBill 3bcccf88d5 vet all core packages 2021-01-09 23:43:34 +00:00
gingerBill 9e8c46b8de Add time.Tick for performance related timings 2021-01-09 01:08:16 +00:00
gingerBill fba4bfb2d5 Minor cleanup of slice/slice.odin code 2021-01-09 00:40:30 +00:00
gingerBill 79432be784 Add the mini ginger* hashes to package hash 2021-01-09 00:33:34 +00:00
gingerBill 56980e51da Update package io 2021-01-09 00:30:10 +00:00
gingerBill 37253f2621 Add encoding/csv Writer 2021-01-09 00:21:47 +00:00
gingerBill da380d6fc4 Add encoding/csv Reader 2021-01-08 23:24:35 +00:00
gingerBill bf183b2c2c Update c/frontend/preprocessor 2021-01-06 11:22:15 +00:00
gingerBill a07d199a48 Add slice.map_keys, slice.map_values, slice.map_entries, slice.map_entry_infos 2021-01-06 11:21:22 +00:00
gingerBill fa0e4c1294 Add -no-entry-point to help 2021-01-04 08:56:42 +00:00
gingerBill 60fe3c9ec6 Remove unused import from doc.odin 2021-01-02 16:50:24 +00:00
gingerBill a6ce417a35 Clean up doc.odin 2021-01-02 16:44:32 +00:00
gingerBill 6523aefdcc Merge branch 'master' of https://github.com/odin-lang/Odin 2021-01-02 16:36:51 +00:00
gingerBill 31c4a9d770 Add packages "core:c/frontend/tokenizer" and "core:c/frontend/preprocessor" 2021-01-02 16:36:43 +00:00
gingerBill 9fa6427a18 Merge pull request #816 from kennethmaples/file-time-fix
Fix layout of Stat for linux and make usage consistent
2020-12-29 11:38:17 +00:00
kennethmaples 6d5bd8bead Fix layout of Stat for linux and make usage consistent across unix variants 2020-12-29 17:45:19 +08:00
gingerBill 98ad912509 Fix typo 2020-12-27 16:16:04 +00:00
DanielGavin bd6ead32f8 Merge pull request #1 from odin-lang/master
update from master
2020-12-18 14:19:03 +01:00
gingerBill 3558848da8 Fix ir_print.cpp for typeid constants 2020-12-17 17:36:59 +00:00
gingerBill 720f2c7c61 Allow check_expr_with_type_hint to allow assignment of types to typeid without requiring typeid_of 2020-12-17 14:23:45 +00:00
gingerBill e6dfc22b8a Add bytes.buffer_write_to and bytes.buffer_read_from 2020-12-17 00:47:05 +00:00
gingerBill 1470cab842 Make bytes.odin consistent with strings.odin in functionality 2020-12-17 00:36:25 +00:00
gingerBill a31b992d2b Rename bytes/strings.odin to bytes/bytes.odin 2020-12-17 00:25:05 +00:00
gingerBill 5faa560f82 Make container.Map have similar semantics to the built-in map type 2020-12-15 23:23:07 +00:00
gingerBill 6c2b93d519 Improve text/scanner whitespace parameter to use a bit_set instead; Improve error message for for x in y where y is not iterable but allows in as an operator 2020-12-15 22:28:40 +00:00
gingerBill 2957da538d Add strings.Intern 2020-12-15 22:07:53 +00:00
gingerBill 089eccb245 Fix minor constant value declaration bug 2020-12-14 22:47:21 +00:00
gingerBill cbd4aa5392 Remove unused constant 2020-12-14 17:40:57 +00:00
gingerBill 1d333fedaa Support %i as an alternative to %d 2020-12-14 17:00:29 +00:00
gingerBill 82d63306c4 Fix enumerated array index printing bug #808 2020-12-14 16:55:19 +00:00
gingerBill 416051f17b Fix #811 2020-12-14 16:39:31 +00:00
gingerBill f6e2d74d10 Keep -vet happy 2020-12-14 14:36:45 +00:00
gingerBill aa2562fe7c Replace procedure call 2020-12-14 14:33:32 +00:00
gingerBill c17d17a9b4 Remove unused procedure 2020-12-14 14:32:34 +00:00
gingerBill 404c9e40ee Update io/util.odin 2020-12-14 14:31:18 +00:00
gingerBill 34788bfced Merge branch 'master' of https://github.com/odin-lang/Odin 2020-12-13 17:09:47 +00:00
gingerBill cffbd2d276 Add odin/parser/parse_files.odin 2020-12-13 17:09:41 +00:00
gingerBill 9250e4d3df Merge pull request #810 from oskarnp/fix-math-factorial
Fix math.factorial()
2020-12-13 11:17:59 +00:00
Oskar Nordquist 60b9ef1f5d Fix math.factorial() 2020-12-13 02:36:29 +01:00
gingerBill f64584b92a Improve -insert-semicolon rules 2020-12-09 23:40:45 +00:00
gingerBill 9eb12889f4 Merge branch 'master' of https://github.com/odin-lang/Odin 2020-12-09 23:35:14 +00:00
gingerBill 6f6a3f2ccf Fix typos for -insert-semicolon 2020-12-09 23:35:08 +00:00
gingerBill a574ebe5ec Merge pull request #805 from DanielGavin/master
small fixes to the parser
2020-12-09 23:22:11 +00:00
gingerBill 9be0272c13 Merge pull request #806 from arqv/nix
Add Nix derivation
2020-12-09 23:21:21 +00:00
Lyla Bravo 5923470e35 Add Nix derivation 2020-12-09 18:51:37 -03:00
DanielGavin 934809397f small fixes to the parser 2020-12-09 21:33:10 +01:00
gingerBill b6aa549eb8 Fix typo 2020-12-08 17:01:28 +00:00
gingerBill 168532ae8d Add runtime.print_strings 2020-12-08 17:01:06 +00:00
gingerBill d7a5767aa3 If ir_type_requires_mem_zero is stored with zero, don't store again with the zeroinitializer 2020-12-08 15:43:57 +00:00
gingerBill 15bf57e4e1 Fix typo 2020-12-08 15:03:46 +00:00
gingerBill 83cd2473f2 Improve rules for zeroing types with the ir.cpp backend with ir_type_requires_mem_zero 2020-12-08 15:00:07 +00:00
gingerBill 510d1f2518 Add docs to text/scanner 2020-12-07 12:43:28 +00:00
gingerBill 7b55068b04 Unify peek_n with peek and renamescan_peek_n to peek_token 2020-12-07 12:13:41 +00:00
gingerBill b9aa94ee0d Add scan_peek_n to package text/scanner #800 2020-12-07 11:30:54 +00:00
gingerBill 96d8971d87 Add peek_n to package text/scanner 2020-12-07 10:55:27 +00:00
gingerBill 98c8fde098 Remove unused tokens 2020-12-06 13:17:48 +00:00
gingerBill 1ac84b09a1 Add comments to ast.walk related entities 2020-12-06 13:04:11 +00:00
gingerBill 21d8562923 Add ast.walk and ast.inspect 2020-12-06 12:59:26 +00:00
gingerBill c8360f4fff Update ast.clone 2020-12-06 12:08:44 +00:00
gingerBill fe7e4e88c6 Merge pull request #797 from Tetralux/improve-string-parsing
Improve number parsing procedures
2020-12-06 11:43:04 +00:00
Tetralux c06528d702 Improve number parsing procedures
- No longer returns true for partial string parsing.
  All characters in the string must be part of the number.
  i.e: parse_int("2.345") no longer returns (2, true) - it now returns (2, false)

- Return (0, false) on empty strings.
2020-12-06 11:39:03 +00:00
gingerBill ea60db9f53 Add inline asm expression to odin/parser 2020-12-06 01:14:55 +00:00
gingerBill dff4c6b666 Clean up logic 2020-12-06 00:59:23 +00:00
gingerBill 0e9b357a5d Fix typo 2020-12-06 00:55:31 +00:00
gingerBill 1eb1bffd89 Merge pull request #799 from odin-lang/parser-experiments
Add experimental `-insert-semicolon` functionality to tokenizer and parser
2020-12-06 00:53:52 +00:00
gingerBill e8653ac47e Update main.cpp 2020-12-06 00:51:32 +00:00
gingerBill f0683c9102 Merge branch 'master' into parser-experiments 2020-12-06 00:49:48 +00:00
gingerBill ca4657fd31 Add custom semicolon insertion to odin/tokenizer and odin/parser 2020-12-06 00:47:58 +00:00
gingerBill d94414b0f4 Correct ternary if/when parsing 2020-12-06 00:15:35 +00:00
gingerBill 80fead1de5 Add ast.Selector_Expr_Call 2020-12-06 00:03:45 +00:00
gingerBill 069c6cac3f Add package name and source code location to Type_Info_Named 2020-12-05 20:47:50 +00:00
gingerBill 1a8ea6113a Remove hash field in runtime.Source_Code_Location 2020-12-05 19:52:08 +00:00
gingerBill 76e6624dbb Remove type name generation for procedures in ir.cpp 2020-12-05 19:21:00 +00:00
gingerBill 09a52b7ee6 Fix typos 2020-12-05 16:56:09 +00:00
gingerBill 7b36174c17 Fix formatting 2020-12-05 16:38:26 +00:00
gingerBill a82c902f99 Minor correction to bytes.Buffer's vtable 2020-12-05 15:36:02 +00:00
gingerBill 14ae2e0a8d Add bufio.Writer and bufio.Read_Writer 2020-12-05 15:14:21 +00:00
gingerBill 2ab6cdb98e Add package bufio; add bufio.Reader 2020-12-05 12:03:57 +00:00
gingerBill 21c1abe15a Add fmt formatting for runtime.Source_Code_Location 2020-12-05 12:03:38 +00:00
gingerBill 4c41045133 Fix typo in package io 2020-12-05 12:03:07 +00:00
gingerBill 0ed1300bd6 Make bytes.Reader and strings.Reader have the same interface 2020-12-04 21:25:13 +00:00
gingerBill dd63665b58 Update bytes.Reader 2020-12-04 20:33:14 +00:00
gingerBill 9b22583397 Add bytes.Buffer 2020-12-04 20:18:41 +00:00
gingerBill 63f2480951 Begin work on package bytes ([]byte equivalent of package strings) 2020-12-04 19:16:40 +00:00
gingerBill edbb3e3b32 Fix typos 2020-12-04 18:53:17 +00:00
gingerBill ecf324e213 Remove buffered type 2020-12-04 18:50:30 +00:00
gingerBill 7268c80d64 Add strings.fields and strings.fields_proc 2020-12-04 18:50:05 +00:00
gingerBill fd453be831 Deprecate opaque in favour of #opaque in the core library 2020-12-04 18:49:39 +00:00
gingerBill 2a232f2397 Remove the (reserved) keyword macro 2020-12-04 16:14:11 +00:00
gingerBill c4cb7170ee Deprecate keyword opaque in favour of #opaque 2020-12-04 16:13:05 +00:00
gingerBill b6bbe29c8f Remove const as a (reserved) keyword 2020-12-04 16:04:58 +00:00
gingerBill 5d0db4c63a Clean up fmt usage with io.Writer and strings.Builder 2020-12-04 15:04:54 +00:00
gingerBill 05a3bdad58 Allow nested procedures to access @(static) and @(thread_local) variables 2020-12-04 11:28:14 +00:00
gingerBill 0ef02e6737 Improve packages io and strings; add io.Section_Reader 2020-12-03 15:57:46 +00:00
gingerBill 047586afc6 Change ExactValue layout for complex/quaternion types to minimize its size 2020-12-03 14:21:33 +00:00
gingerBill 5acdcfb57c Keep -vet happy 2020-12-03 13:26:33 +00:00
gingerBill 6e04b1c429 Remove using stream on custom stream types in package io 2020-12-03 13:23:36 +00:00
gingerBill 828fe2ce56 Fix #795 2020-12-03 12:25:45 +00:00
gingerBill 18da0b3418 Integrate package io into core library 2020-12-03 10:45:26 +00:00
gingerBill 334a8c46e8 Fix io typos 2020-12-03 00:27:21 +00:00
gingerBill e0fb081cbd Keep -vet happy 2020-12-02 23:46:41 +00:00
gingerBill bca28e94ec Keep fmt happy 2020-12-02 23:43:28 +00:00
gingerBill 875415daa9 Make os._file_stream_vtable private 2020-12-02 23:40:23 +00:00
gingerBill 0cf3ae93c0 Add os.stream_from_handle; fix io.close 2020-12-02 23:39:33 +00:00
gingerBill c4172e3914 Rename stream field names 2020-12-02 23:17:21 +00:00
gingerBill 8e08ae47fb Add strings.Reader 2020-12-02 23:12:43 +00:00
gingerBill d9343ae997 Add package io 2020-12-02 23:12:14 +00:00
gingerBill 4d30b88927 Fix typos 2020-12-02 23:11:46 +00:00
gingerBill 7389ffba6d Fix -llvm-api const initialization of &T{} 2020-12-02 21:07:15 +00:00
gingerBill a6301ab58a Add type_assertion_check2 2020-12-02 11:50:57 +00:00
gingerBill 996c854071 Disable lb_const_hash for the time being 2020-12-02 11:48:50 +00:00
gingerBill a9c1811027 Fix typo 2020-12-02 10:41:18 +00:00
gingerBill 32b1537aa3 Fix xor for constant booleans 2020-12-02 10:39:59 +00:00
gingerBill 2d0c0a7a83 Fix typo 2020-12-01 15:38:15 +00:00
gingerBill 400816ebf7 Fix Pointer store in LLVM backend 2020-12-01 00:40:54 +00:00
gingerBill ef417017f0 Fix typo 2020-11-30 19:46:41 +00:00
gingerBill 7c1c9d22b4 Fix thread.run_with_poly_data* 2020-11-30 19:44:43 +00:00
gingerBill 5803fcc158 Revert function passes 2020-11-29 20:41:01 +00:00
gingerBill f4f2b8f5ad Add _internal field to context 2020-11-29 18:42:13 +00:00
gingerBill dd4f8e9747 Improve default pass manager for -llvm-api 2020-11-29 18:32:49 +00:00
gingerBill f06f33872c Make 16 simple hasher cases for small types 2020-11-29 18:17:21 +00:00
gingerBill 9e13416312 Simplify simple compare hasher code 2020-11-29 17:58:54 +00:00
gingerBill 5ab7ec5b16 Support any comparable type for map keys 2020-11-29 16:37:19 +00:00
gingerBill b922398a96 Sanity check for map key 2020-11-29 16:13:16 +00:00
gingerBill 57f5976ac1 Support map keys for simple compare types 2020-11-29 16:12:21 +00:00
gingerBill 7fbc081119 Improve const hash 2020-11-29 16:03:21 +00:00
gingerBill 1dfe0cdd1d Simplify hashing approach map 2020-11-29 15:50:29 +00:00
gingerBill 97c66c9c73 Add intrinsics.type_hasher_proc; Make map work with generic hasher procedure 2020-11-29 15:27:53 +00:00
gingerBill 085972bb2c Minor clean up 2020-11-29 14:31:42 +00:00
gingerBill 39bed567b3 Add intrinsics.type_equal_proc; Make map use an internal equal procedure to compare keys 2020-11-29 14:22:42 +00:00
gingerBill 2e0fd34e59 Keep -vet happy 2020-11-29 12:52:30 +00:00
gingerBill 9959a069fc Simplify internals of map[K]V 2020-11-29 12:48:33 +00:00
gingerBill c77098a91c Fix for in enum type 2020-11-26 10:19:45 +00:00
gingerBill 89cceb910a Keep -vet happy 2020-11-26 00:09:38 +00:00
gingerBill f36c5de746 Fix typo 2020-11-26 00:05:15 +00:00
gingerBill ca10248740 Add __dynamic_map_fix_keys 2020-11-25 23:50:25 +00:00
gingerBill aa859c2187 Clean up and fix __dynamic_map_erase 2020-11-25 22:36:34 +00:00
gingerBill 8591655334 Clean up __dynamic_map_rehash behaviour 2020-11-25 21:03:20 +00:00
gingerBill 70f5d7a1c9 Enforce zeroing through memset to ensure padding is zeroed with llvm api 2020-11-25 19:50:48 +00:00
gingerBill 1acd5acd70 Remove unused variable 2020-11-25 16:28:13 +00:00
gingerBill dbaf4d24f6 Update package json for new map layout; Correct llvm-api includes for *nix 2020-11-25 16:19:56 +00:00
gingerBill 9c1c9693f2 Patch up gb.h 2020-11-24 15:18:20 +00:00
gingerBill 776c3f4e90 Prepare for M1 Mac 2020-11-24 12:20:48 +00:00
gingerBill a55568b0c4 Make hash internal key be uintptr rather than u64 to reduce entry size 2020-11-23 19:14:36 +00:00
gingerBill b08ec005b2 Keep -vet happy 2020-11-23 18:33:49 +00:00
gingerBill 91758656f6 Change internal layout of map[K]V 2020-11-23 18:25:01 +00:00
gingerBill 4762d2f2d1 map type internal reorganization 2020-11-23 16:56:31 +00:00
gingerBill 67bc35e882 Fix logic for comparisons of struct #raw_union types 2020-11-23 16:19:26 +00:00
gingerBill 4e370e6ed8 Add equal procedure field to runtime.Type_Info_Struct 2020-11-23 15:53:49 +00:00
gingerBill 0b30c3dc5a Add flags: Type_Info_Flags, to runtime.Type_Info 2020-11-23 14:35:31 +00:00
gingerBill 9e42cb1595 Add comparisons to structs where all fields are comparable == and != 2020-11-23 12:20:04 +00:00
gingerBill 4379917c7d Re-enable zeroext for i1 2020-11-22 21:52:39 +00:00
gingerBill dc8e895d72 Merge branch 'master' of https://github.com/odin-lang/Odin 2020-11-22 21:38:52 +00:00
gingerBill a2461bdf6b Modify llvm_abi.cpp to work correctly for win64 abi of i128 types. (it's a pain) 2020-11-22 21:38:45 +00:00
Mikkel Hjortshøj 5cc9ddd40b Update nightly.yml 2020-11-22 02:49:19 +01:00
gingerBill acef96bde7 Merge pull request #787 from dbechrd/dbechrd-mixed-value-error-typo-fix
Update check_expr.cpp
2020-11-22 01:22:48 +00:00
gingerBill e0c028329b Merge pull request #786 from dbechrd/dbechrd-kernel32-typo
Update kernel32.odin
2020-11-22 01:22:18 +00:00
gingerBill 740411f207 Minor change to unicode/letter.odin 2020-11-21 23:14:07 +00:00
gingerBill fa50c8d7d3 Add ODIN_TEST constant for checking if odin test is being run 2020-11-21 11:40:15 +00:00
Dan Bechard 2d878de84d Update check_expr.cpp
Fixed typo in error message `procedure all` -> `procedure call`
2020-11-20 15:43:51 -08:00
Dan Bechard 58f768cb4f Update kernel32.odin
Fix typo in CreateProcessA/W mappings (https://github.com/odin-lang/Odin/issues/785)
2020-11-20 15:39:08 -08:00
gingerBill 260e28c0af Fix casting of untyped strings 2020-11-20 16:30:34 +00:00
gingerBill a14ea5b2b5 Add support for %s and %q for [dynamic]byte 2020-11-20 16:25:11 +00:00
gingerBill 63e4a2341f Support string literals for fixed arrays of runes; Add %q support for arrays/slices of bytes 2020-11-20 16:24:23 +00:00
gingerBill 6416a6f39c Allow string literals for [N]byte 2020-11-20 16:01:59 +00:00
gingerBill 87956676f5 Add %s support for arrays and slices of bytes 2020-11-20 16:01:16 +00:00
gingerBill 913eac13b1 Reorganize runtime code into separate files 2020-11-19 00:08:23 +00:00
gingerBill 3b7fd4711f Fix text/scanner.scan_string 2020-11-18 23:48:01 +00:00
gingerBill fef5172278 Add %q for runes in fmt 2020-11-18 23:40:54 +00:00
gingerBill a39921aa6a Add package text/scanner 2020-11-18 23:33:16 +00:00
gingerBill 9408eb9580 Update odin doc to support multiple package outputs by passing multiple paths; Replace -all with -short
Example:
odin doc core/path core/path/filepath
2020-11-18 23:22:27 +00:00
gingerBill ef2f204c58 Improve system_exec_command_line_app functionality; Restrict test_* procedures to *_test.odin files 2020-11-17 20:33:15 +00:00
gingerBill 30765475c6 Fix up system_exec_command_line_app exit code code 2020-11-17 18:59:48 +00:00
gingerBill 2bd0fd932a Begin rudimentary work on implementing odin test tooling with *_test.odin files 2020-11-17 18:50:30 +00:00
gingerBill 11577db6a8 Minor fixes 2020-11-17 16:36:33 +00:00
gingerBill ede25a88f8 Ignore +build flags in packages comments with odin doc 2020-11-17 16:01:33 +00:00
gingerBill aa5cb7f6a9 Fix proc type printing 2020-11-17 15:54:22 +00:00
gingerBill d730c5b334 Improve file doc logic 2020-11-17 15:48:18 +00:00
gingerBill 34ca4e92eb Fix parser logic for first comment group line in a file 2020-11-17 15:45:55 +00:00
gingerBill 7442f4bab6 Fix typo 2020-11-17 15:17:36 +00:00
gingerBill 4f303603e7 Add more documentation for odin doc flags 2020-11-17 15:15:26 +00:00
gingerBill a0fbc56317 Improve flags for odin doc 2020-11-17 15:13:38 +00:00
gingerBill d90fc18bef Basic odin doc support 2020-11-17 15:05:16 +00:00
gingerBill 00192bb349 Improve flag handling to check for invalid uses 2020-11-17 13:55:08 +00:00
gingerBill edd9d5e50b Add -show-unused-with-location 2020-11-17 13:02:10 +00:00
gingerBill fea8c63ab3 Fix string_compare 2020-11-17 12:19:28 +00:00
gingerBill 6f71d1f2a9 Add -show-unused (Shows unused package declarations of all imported packages)
Crude output at the moment but better than nothing
2020-11-17 12:10:25 +00:00
gingerBill ca4b0527e8 Minimize memory usage for AST nodes by using Slice<T> rather than Array<T> when the parameter doesn't need to grow 2020-11-16 15:18:25 +00:00
gingerBill adf6c85fd3 Minimize Ast flags usage 2020-11-16 01:42:30 +00:00
gingerBill 939878df50 Improve logic for x->y() shorthand 2020-11-15 23:54:18 +00:00
gingerBill 5fafb17d81 Improve generate_entity_dependency_graph: Calculate edges for graph M - Part 2 2020-11-15 22:46:07 +00:00
gingerBill 3a229397e4 Add next_pow2_isize for PtrSet 2020-11-15 21:22:26 +00:00
gingerBill db0bcbc4f4 Fix calling convention for new LLVM ABI, and changePtrSet index to be u32 rather than isize 2020-11-15 21:19:08 +00:00
gingerBill 0d6f5cec37 Implement custom temporary allocator using ring buffer 2020-11-15 19:36:37 +00:00
gingerBill 17ec3e72a6 Add SCOPED_TEMPORARY_BLOCK for temporary allocations within a block 2020-11-15 18:45:40 +00:00
gingerBill 30d922b059 Make set_procedure_abi_types use the permanent_allocator 2020-11-15 18:11:49 +00:00
gingerBill 3c1c10a178 Begin clarifying allocation patterns by changing from heap_allocator to specific arenas 2020-11-15 18:08:52 +00:00
gingerBill 9f93042163 Improve lb_abi_to_odin_type 2020-11-14 17:09:42 +00:00
gingerBill a64ea342df Improve USE_NEW_LLVM_ABI_SYSTEM's System V ABI 2020-11-12 23:40:13 +00:00
gingerBill fa284f9a5a Fix import paths 2020-11-12 14:20:33 +00:00
gingerBill 78b6948ff2 Reorganize package strings 2020-11-12 14:17:41 +00:00
gingerBill a6c5c203ab Begin work on Sys V for new ABI system 2020-11-12 01:21:09 +00:00
gingerBill 70b8b3c7dd Update LLVM backend to begin work on a generic ABI system 2020-11-12 00:43:49 +00:00
gingerBill 6ee4f51670 Add new math procedure: inf_f32 inf_f64 nan_f32 nan_f64 2020-11-11 11:42:21 +00:00
gingerBill e8da2ef65e Update package unicode 2020-11-10 19:00:38 +00:00
gingerBill 6c0fa24e5d Force dependency for @(export) entities 2020-11-10 19:00:16 +00:00
gingerBill 27d0660546 Merge pull request #779 from F0x1fy/master
Add flag -no-entry-point
2020-11-10 17:47:02 +00:00
F0x1fy 0eba4b46b5 Made sure the entry point is not generated when -no-entry-point is specified. 2020-11-10 10:16:22 -07:00
F0x1fy 6b6f1a5283 For the sake of consistency, fixed the placement of the -no-entry-point flag check. 2020-11-10 09:56:16 -07:00
F0x1fy 3bed5fad77 Removed unnecessary newline from previous commit. 2020-11-10 09:55:00 -07:00
F0x1fy 301e1d2ff3 Added -no-entry-point flag and relevant check. 2020-11-10 09:50:53 -07:00
gingerBill 49e140f4db Add utf8.full_rune 2020-11-10 16:47:56 +00:00
gingerBill 95b94a0f56 Fix sync.Channel code; add thread.run_with_poly_data and run_with_poly_data(2|3|4) procedures 2020-11-10 15:00:40 +00:00
gingerBill ee3b3fe6a3 Fix typeid_of bug 2020-11-10 14:48:57 +00:00
gingerBill eea3a1ecd3 Improve sync.Channel to encode the direction into the type 2020-11-09 13:05:02 +00:00
gingerBill 31f4590f4b Fix default parameters on record types 2020-11-09 13:04:36 +00:00
gingerBill 7909a9f5a5 Remove debug code causing bug 2020-11-09 10:36:09 +00:00
gingerBill c26cb470a2 Fix LLVM-API type cycle for procedures of named procedures 2020-11-09 10:27:27 +00:00
gingerBill 3d5e180dec Merge branch 'master' of https://github.com/odin-lang/Odin 2020-11-08 23:55:53 +00:00
gingerBill 44baf56d62 Fix cyclic check in is_type_polymorphic 2020-11-08 23:54:09 +00:00
Mikkel Hjortshøj 11a4dc8ee3 [CI] Done testing webhook 2020-11-08 01:47:09 +01:00
Mikkel Hjortshøj 19e2f7b7bf [CI] testing webhook 2020-11-08 01:46:28 +01:00
Mikkel Hjortshøj 817db70bde [CI] Remove -march for makefile nightly 2020-11-08 01:23:19 +01:00
Mikkel Hjortshøj ef27528ace [CI] Non-sudo install of b2? 2020-11-08 00:31:25 +01:00
Mikkel Hjortshøj a239fcfa3a Update nightly.yml 2020-11-08 00:21:28 +01:00
Mikkel Hjortshøj a77976533c [CI] Add manual trigger to nightly 2020-11-08 00:08:11 +01:00
Mikkel Hjortshøj 06b2a9a3e7 [CI] Try setting python 3.x in nightly upload step 2020-11-08 00:01:31 +01:00
gingerBill 7a7fddd1df Merge pull request #775 from Tetralux/fix-type-table-unix
Fix -build-mode:shared type table on Unix
2020-11-06 20:51:06 +00:00
Tetralux 140bb3ebfc Fix -build-mode:shared type table on Unix
Fixes #527.

Previously on Linux, '__$startup_runtime', the procedure that
initializes the type table for runtime typeids, was NOT called when
a shared library was loaded by the dynamic loader.

This caused the library to not have its type table populated, which
caused an assert to fail if you tried to use runtime typeids - like
core:fmt, for example.

This commit fixes this by calling ld instead of clang, when building a
shared library, so that we can pass "-init '__$startup_runtime'" to it,
when building a shared library.

Try as I might, I could not get clang to correctly pass through
the linker flags that I wanted.
2020-11-06 20:44:11 +00:00
gingerBill 6fab181c0d Merge pull request #774 from F0x1fy/master
Moved internal_windows to internal_any
2020-11-06 19:21:54 +00:00
gingerBill 17271f74c7 Merge pull request #776 from hectormonacci/patch-3
Fix small typo
2020-11-06 19:21:08 +00:00
Héctor M. Monacci 39044b5bb5 Fix small typo
Fix small typo
2020-11-06 15:46:32 -03:00
F0x1fy 94277fe41c As per GingerBill's request, copied the files over to a linux-specific file instead of renaming to . 2020-11-06 11:11:26 -07:00
F0x1fy b5a619e975 Moved internal_windows to internal_any to allow for manual linking related to issue odin-lang/Odin#527. 2020-11-05 22:14:56 -07:00
gingerBill 7c5247f5fb Add package sys/cpu - implements processor feature detection 2020-11-06 00:39:09 +00:00
gingerBill 9ac6d45bd6 Add more procedures to package slice 2020-11-06 00:38:03 +00:00
gingerBill 4cc84002db Merge pull request #773 from Tetralux/fix-slice-last
Fix slice.last()
2020-11-05 15:18:52 +00:00
Tetralux c1d3c3f926 Fix slice.last()
There was a typo that prevented it from being used.
2020-11-05 00:52:32 +00:00
gingerBill 85b2da2e2a Merge pull request #770 from hectormonacci/patch-2
Fix some typos
2020-11-03 13:53:35 +00:00
Héctor M. Monacci 968aa2f688 Fix some typos
Fix some typos
2020-11-03 10:51:56 -03:00
gingerBill 0784b0ac7f Merge pull request #769 from hectormonacci/patch-1
Fix typo
2020-11-03 10:41:39 +00:00
Héctor M. Monacci 44cfa3484f Fix typo
Fix typo (proprosal -> proposal)
2020-11-03 07:40:17 -03:00
gingerBill 54fbdabc38 Add experimental -insert-semicolon functionality to tokenizer and parser 2020-11-01 15:10:06 +00:00
Mikkel Hjortshøj 81398d21ed Merge pull request #768 from Platin21/fix_macos_linking
Fix macOS linking for user/local/libs and object files
2020-10-31 23:18:35 +01:00
Platin21 8c46582667 Fixes text layout now via GitHub 2020-10-31 22:37:11 +01:00
Platin21 f29f7351e9 Revert "Changed tab width was on 2 now 4"
This reverts commit fc7c0ca3b0.
2020-10-31 22:30:03 +01:00
Platin21 fc7c0ca3b0 Changed tab width was on 2 now 4 2020-10-31 22:29:02 +01:00
Platin21 8158239d76 Sets llvm api back to use the generic sdk link 2020-10-31 22:15:16 +01:00
Platin21 f3108493fb Combines all link-able types to a single if and adds .o for linking 2020-10-31 22:12:50 +01:00
Platin21 7694a89d38 Fix for local/lib linking from brew for macOS 2020-10-31 22:05:40 +01:00
gingerBill 75e8e5e06f Merge pull request #767 from SrMordred/patch-1
Update thread_windows.odin
2020-10-31 10:07:33 +00:00
Patric Dexheimer 59b8748c2c Update thread_windows.odin 2020-10-31 02:40:52 -03:00
Patric Dexheimer 2231f02f61 Update thread_windows.odin
`n` was left over being always zero. But you want `win32.WaitForMultipleObjects` to be the number of threads to wait for which u already have with `j`.
2020-10-31 02:37:26 -03:00
Mikkel Hjortshøj f9eadc3e98 Merge pull request #766 from odin-lang/fix-macos-ci
[CI] Fix macOS CI builds
2020-10-29 20:16:19 +01:00
Mikkel Hjortshøj d6057a7ec6 [CI] Fix macOS CPATH for nightly builds 2020-10-29 20:10:26 +01:00
Mikkel Hjortshøj 532d307a75 [CI] Remove test stage for macOS and go back to macos-latest 2020-10-29 20:06:50 +01:00
Mikkel Hjortshøj 6ae8f5a62d [CI] Try and fix CPATH setting for macOS 2020-10-29 20:03:38 +01:00
Mikkel Hjortshøj a5c6487bc1 [CI] Try not installing our own llvm with brew 2020-10-29 19:28:50 +01:00
Mikkel Hjortshøj 6a808235fe [CI] Change deprecated workflow commands for macOS 2020-10-29 19:25:22 +01:00
Mikkel Hjortshøj 61d7cdfe92 [CI] Fix macOS tag 2020-10-29 13:35:53 +01:00
Mikkel Hjortshøj 45815fd26e [CI] Change macos version to 11 from 10.5 2020-10-29 13:33:12 +01:00
Mikkel Hjortshøj c7a2d6970b [CI] Switch xcode version back to 11.7 2020-10-29 13:23:45 +01:00
gingerBill 6912ef1bc1 Merge branch 'master' of https://github.com/odin-lang/Odin 2020-10-29 09:58:15 +00:00
gingerBill 08fae7360a Fix ir printing for nested procedure literals indirectly through identifiers 2020-10-29 09:58:08 +00:00
gingerBill 6772cb0f3b Merge pull request #758 from zhibog/master
Fixed getting windows version. The former function is no longer worki…
2020-10-26 11:36:09 +00:00
gingerBill ce35de47e4 Merge pull request #761 from Tetralux/patch-7
Reuse container.Queue capacity when calling pop_front()
2020-10-26 11:35:25 +00:00
Tetralux 213864a50c Reuse container.Queue capacity when calling pop_front()
Currently, the Queue will never reuse it's full capacity if you call `pop_front`, even if you empty it before pushing more items.

With this change, if you empty the Queue with `pop_front`, then the offset will be set back to the start of the underlying array when you pop the last item.
Future pushes will then reuse the already-allocated--but now empty--space.
2020-10-26 00:12:31 +00:00
gingerBill 4629754f7c Inline asm expression (-llvm-api)
See https://llvm.org/docs/LangRef.html#inline-assembler-expressions
Example:
```
x := asm(i32) -> i32 {
    "bswap $0",
    "=r,r",
}(123);
```
Allowed directives `#side_effect`, `#align_stack`, `#att`, `#intel` e.g. `asm() #side_effect #intel {...}`
2020-10-24 16:32:37 +01:00
gingerBill 0061e63db0 Merge branch 'master' of https://github.com/odin-lang/Odin 2020-10-24 15:08:46 +01:00
gingerBill 5fa488f163 Add intrinsics.cpu_relax for llvm-api 2020-10-24 15:08:35 +01:00
gingerBill 71ef27fef9 Merge pull request #753 from Tetralux/fix-dirnoexist-error
Fix error message when importing package that does not exist
2020-10-24 09:41:26 +01:00
gingerBill 6ea000b648 Merge pull request #752 from powerc9000/patch-4
Fix a few bugs in path based code.
2020-10-24 01:28:15 +01:00
zhibog 05b58bdbb1 Fixed package name 2020-10-24 00:17:36 +02:00
zhibog 4c4112fbc7 Fixed getting windows version. The former function is no longer working on Windows 10. Also fixed the struct to use correct win32 names 2020-10-24 00:14:01 +02:00
gingerBill feeb342c00 Improve multiple return value copy-elision 2020-10-20 17:08:55 +01:00
gingerBill c4dbc88a12 Improve array programming code generation 2020-10-20 15:38:41 +01:00
gingerBill f4b4cd0433 Specific set the code gen level for -llvm-api 2020-10-20 12:43:15 +01:00
gingerBill 4e5b8f2c61 Add -build-mode:assembly for -llvm-api 2020-10-20 12:35:12 +01:00
gingerBill 0be6ddc7e2 Add -microarch:<string> (e.g. -microarch:native) 2020-10-20 12:25:11 +01:00
gingerBill b1bdd95f19 Begin work on making packages import assembly sort files (.S) 2020-10-16 15:32:09 +01:00
gingerBill 063c0548b0 Add new package strings procedures: trim_prefix, trim_suffix, to_valid_utf8 2020-10-16 15:30:14 +01:00
gingerBill 41f6a684e1 Rename slice.sort_proc to slice.sort_by; add slice.sort_by_key 2020-10-16 14:55:36 +01:00
gingerBill 289908e0b8 Add +build ignore tag 2020-10-15 16:25:57 +01:00
gingerBill 5a28a7e0f5 Add intrinsics.type_field_index_of 2020-10-15 16:12:47 +01:00
gingerBill f8e697dbbb Fix indirect selector bug with using on offset_of 2020-10-15 14:58:57 +01:00
gingerBill 7fc3030c63 Update path/filepath to use new slice.sort; Add sort.reverse_interface 2020-10-14 20:47:13 +01:00
gingerBill edd802e1ff Add package slice; New sort.Interface with default sort.sort 2020-10-14 19:52:05 +01:00
gingerBill de13584be2 Add #no_bounds_check to crc procedures 2020-10-14 16:00:08 +01:00
gingerBill 8806283cf7 Improve location information for log.panic* 2020-10-14 15:59:45 +01:00
gingerBill ec5934705c Enforce do bodies to be on the same line as the control statement's condition or token 2020-10-14 15:59:19 +01:00
gingerBill fa33476438 Improve default temp allocator; Fix filepath.abs behaviour on Windows 2020-10-13 14:40:13 +01:00
Tetralux dfac45942c Fix error message when importing package that does not exist
Previously on Linux, if a file in your program tried to import a
package that did not actually exist, read_directory() assumed that
the errno after calling opendir() was ENOTDIR.

This was incorrect.

Instead, we now switch on errno and check for ENOENT, which it is
if the directory does not exist.
2020-10-09 05:56:12 +01:00
gingerBill 1b4bccbc94 Add append_nothing 2020-10-08 12:23:44 +01:00
Clay Murray 062ae56f25 Fix a few bugs in path based code.
Trying to use path.dir and path.rel I found these two issues with the implementation.
2020-10-07 16:32:00 -06:00
gingerBill 6eeb12a986 Improve default temp_allocator; make nil loggers do nothing; improve mem.Scratch_Allocator behaviour 2020-10-02 16:06:55 +01:00
gingerBill a65553293f Add mem.Small_Allocator 2020-10-02 11:09:36 +01:00
gingerBill 8f28312705 Fix pop behaviour, and improve assert messages by using #caller_location 2020-10-02 11:04:17 +01:00
gingerBill 3a4f0d85a6 Fix container.Array and container.Ring 2020-10-01 17:04:56 +01:00
gingerBill c604e359c7 Move flush to within the sbprint* procedures 2020-10-01 12:09:38 +01:00
gingerBill 66c648e5e0 Remove unused variable 2020-10-01 12:05:42 +01:00
gingerBill e83af93394 Allow flushing with strings.Builder; Make fmt.fprint* procedures use a custom flush procedure 2020-10-01 12:03:20 +01:00
gingerBill dd4c02a1b9 Fix multiple declared foreign procedures 2020-10-01 12:02:07 +01:00
gingerBill bc2151f529 Add new os_specific_*.odin files 2020-10-01 10:59:47 +01:00
gingerBill 252a864308 Reimplement the Windows OS dependencies in package runtime 2020-10-01 10:57:02 +01:00
gingerBill 9513cf1ac6 Fix os.stat code; make fmt.panicf diverging 2020-09-30 22:04:39 +01:00
gingerBill c35d533ce5 Replace the *_remove_range with procedures with remove_range 2020-09-30 12:38:40 +01:00
gingerBill 464e733b88 Merge branch 'master' of https://github.com/odin-lang/Odin 2020-09-29 11:11:42 +01:00
gingerBill 519dcc2b76 Add os.read_at and for Windows; fix mem.clone_slice; fix current directory locking code 2020-09-29 11:11:28 +01:00
gingerBill 1818ceb4f2 Merge pull request #747 from Platin21/master
Fixes for MacOS 11 / Big Sur
2020-09-28 12:48:50 +01:00
gingerBill e95addb1f4 Revert user_data addition 2020-09-28 12:40:48 +01:00
gingerBill d343e47a86 Add user_data parameter to filepath.walk and filepath.Walk_Proc 2020-09-28 12:39:34 +01:00
gingerBill 1d21740afb Add filepath.walk 2020-09-28 12:29:14 +01:00
gingerBill 9ae3879956 Add os.stat, os.lstat, os.fstat, filepath.walk 2020-09-28 12:28:02 +01:00
Platin21 6b83159b06 Switched to else instead of not equal 2020-09-27 22:17:35 +03:00
Platin21 d72a01a714 Merge branch 'master' of https://github.com/odin-lang/Odin 2020-09-27 22:13:12 +03:00
Platin21 2ed6785b4a Adds -syslibroot to linker command needed for System.framework 2020-09-27 22:11:23 +03:00
Platin21 f7e40b8572 Adds when statement for framework include 2020-09-27 22:08:33 +03:00
Platin21 a71cbd4087 Changed foreign imports to now use the System Framework 2020-09-27 21:57:27 +03:00
gingerBill 2ebb94fa72 Allow os.read_dir to use a different allocator 2020-09-27 00:31:29 +01:00
gingerBill 96a0125599 Fix typo in reflect.set_union_variant_type_info 2020-09-27 00:30:54 +01:00
gingerBill 626d0736f4 Add more to package reflect (as_string, as_pointer, as_raw_data, relative_pointer_to_absolute) 2020-09-27 00:15:16 +01:00
gingerBill e26f63b448 Update package reflect 2020-09-26 23:51:42 +01:00
gingerBill b9076b0d5b Add package unicode/utf8/utf8string for efficient utf8 codepoint indexing to strings 2020-09-26 23:16:18 +01:00
gingerBill c43b8ef387 Merge branch 'master' of https://github.com/odin-lang/Odin 2020-09-26 23:12:20 +01:00
gingerBill b9f511954a Make runtime.slice_handle_error explicitly diverging 2020-09-26 23:12:04 +01:00
gingerBill 4936713a5e Merge pull request #740 from bttelle/issue-697
Fix issue #697
2020-09-26 21:09:40 +01:00
gingerBill 0bd38ba1f6 Add some comments to explain what the differences between packages path and path/filepath 2020-09-26 20:17:54 +01:00
gingerBill 49eaeccd84 Remove OS specific stuff from package path 2020-09-26 20:02:24 +01:00
gingerBill 840af6825a Update packages os, path, and filepath 2020-09-26 16:02:03 +01:00
gingerBill 3ccaf47566 Remove unused imports 2020-09-25 20:23:29 +01:00
gingerBill 8cc5cd1494 Add package path/filepath; Add os.stat for windows (TODO: unix) 2020-09-25 20:20:53 +01:00
gingerBill 6b634d5e46 Fix fmt with -vet 2020-09-25 15:54:23 +01:00
gingerBill 903ba1c5d8 Add built-in custom formatters for time.Time and time.Duration 2020-09-25 15:47:39 +01:00
gingerBill b42c7f9161 Update package path and fix bugs; add path.match which uses shell pattern matching 2020-09-25 11:43:51 +01:00
gingerBill 654b24e514 Add -disallow-do 2020-09-23 17:17:32 +01:00
gingerBill fc4fdd588e Remove usage of do in core library 2020-09-23 17:17:14 +01:00
gingerBill 4844dd4d96 Add check to block statements to see if they only contain one statement, a value declaration, and err. 2020-09-23 11:16:33 +01:00
gingerBill 609af3a651 Fix and clean up default procedure parameter code for non-constant types 2020-09-22 12:06:05 +01:00
gingerBill 20e4548999 Make llvm-c header use local includes 2020-09-18 13:18:28 +01:00
Joseph Battelle 7490ac2cfd Fix issue #697
Add `is_type_typeid` check to `does_field_type_allow_using`
2020-09-16 21:18:25 -07:00
gingerBill 10afc58d7d Minor style change in parser.odin 2020-09-16 22:28:32 +01:00
gingerBill f5b18482f6 Merge pull request #739 from bttelle/issue-486
Fix issue #486
2020-09-16 22:23:41 +01:00
gingerBill 97d7d8301a Fix ast.Branch_Node parsing in package odin/parser 2020-09-16 22:19:57 +01:00
Joseph Battelle 3a3d415295 Fix issue #486
Use `check_is_assignable_to_using_subtype` in
`is_polymorphic_type_assignable`.

The polymorphic procedure in #486 can now also be written without the
cast:
```odin
print_entity :: proc(e : ^$E, p : proc(^$T) = print_base) { p(e); }
```
2020-09-16 12:32:57 -07:00
gingerBill 33003d1bc1 Update README.md 2020-09-16 20:15:28 +01:00
gingerBill 59d9821bd9 Add intrinsics.type_has_field 2020-09-16 20:08:45 +01:00
gingerBill f530c80216 Fix -debug bug with internal startup procedures 2020-09-16 15:16:29 +01:00
gingerBill 94b27aa64e Merge pull request #737 from nakst/master
update essence platform
2020-09-15 22:28:15 +01:00
nakst c92860e142 update essence platform 2020-09-15 23:22:19 +01:00
gingerBill 4cf240ca05 Fix odin/parser issues 2020-09-15 22:14:23 +01:00
gingerBill ebad8e8990 Change how ir.cpp calls the startup type info procedure 2020-09-15 19:40:37 +01:00
gingerBill 2475c69f00 Remove runtime.os_stdout, since it is not required by the runtime 2020-09-15 14:16:44 +01:00
gingerBill c9dcb7242f Merge branch 'master' of https://github.com/odin-lang/Odin 2020-09-15 12:46:12 +01:00
gingerBill 9d976b04bc Fix +build tag logic 2020-09-15 12:45:44 +01:00
gingerBill 6f1e774a42 Move runtime os specific freestanding stuff to a separate file 2020-09-15 12:36:37 +01:00
gingerBill b94dde2817 Force used of imports in reflect/map.odin 2020-09-15 12:31:21 +01:00
gingerBill 92cd50d3f0 Add TargetOS_freestanding for future use 2020-09-15 12:29:32 +01:00
gingerBill 1ef1407f02 Update ODIN_VERSION 2020-09-15 12:28:15 +01:00
gingerBill edbad0709e Add -default-to-nil-allocator flag (sets ODIN_DEFAULT_TO_NIL_ALLOCATOR) 2020-09-15 12:27:53 +01:00
gingerBill bfc7d74967 Add relfect.map_entry_info_slice 2020-09-15 12:23:49 +01:00
gingerBill 9d91c46cb4 Move all os specific stuff for the runtime to one file 2020-09-15 12:19:56 +01:00
gingerBill 17b3c2ed4c Merge pull request #736 from jockus/json-parse-number-option
Added option to parse number as integer, disabled by default
2020-09-15 12:15:57 +01:00
jockus 8d637f5139 Added parse_integers optional to validation 2020-09-15 12:03:40 +01:00
gingerBill f48a873954 Reorganize package runtime
Separates out the OS specific stuff into different files
2020-09-15 11:52:19 +01:00
gingerBill 4930a9c1a4 Add mem.clone_slice 2020-09-15 11:51:38 +01:00
jockus 195dbd658d Added option to parse number as integer, disabled by default 2020-09-15 11:39:34 +01:00
gingerBill 0cd681e6b7 Expose runtime._startup_runtime to allow for freestanding targets in the future 2020-09-15 10:51:51 +01:00
gingerBill 3211e60018 Merge pull request #734 from krixano/FreeBSD
FreeBSD Support
2020-09-15 10:12:42 +01:00
gingerBill 775bd66382 Merge pull request #735 from bttelle/issue-723
Fix issue #723
2020-09-15 10:05:05 +01:00
Christian Seibold a13eed9894 Cleanup, check sched_param and SCHED_* constants in pthread_freebsd.odin 2020-09-15 01:34:01 -05:00
Joseph Battelle e9c598a426 Fix issue #723
Typo in `check_stmt_internal` for case Ast_UsingStmt; first element
was used for all elements of the enumerated list.
2020-09-14 16:41:53 -07:00
Christian Seibold 65787381c1 Change sizes of pthread types for freebsd 2020-09-14 16:48:55 -05:00
Christian Seibold dd7b29e681 Finish add all errors 2020-09-14 16:18:36 -05:00
Christian Seibold 577be4a8ae Get Odin compiling and produced exe's running on FreeBSD 2020-09-14 15:22:35 -05:00
Christian Seibold ac126a8cd7 Add FreeBSD targets, get gb.h working with FreeBSD, fix odin_root_directory function for FreeBSD and a few other operating systems not yet added 2020-09-14 11:28:41 -05:00
gingerBill d53725fe14 Merge pull request #733 from bttelle/issue-515
Fix issue #515
2020-09-14 14:07:02 +01:00
gingerBill b8bebf4511 Fix typo in Small_Array procedure 2020-09-14 10:10:35 +01:00
Joseph Battelle 2f32b8fb3d Fix issue #515
Modify `check_type_specialization_to` to require exact values
to be equal when called with constant basic types. This also
now allows procedure group members to differ only by constant
value specializations.  See the further example in the issue.
2020-09-13 22:58:05 -07:00
gingerBill 1fd1203d8b Improve error message for multi-valued global declarations not be allowed 2020-09-12 16:04:02 +01:00
gingerBill ccb7c3513b Fix check_arity_match bug 2020-09-12 15:50:42 +01:00
gingerBill bf215377de Add edge case check for "" string 2020-09-11 16:20:46 +01:00
gingerBill d317d3d8b3 Simplify "" string code 2020-09-11 16:18:24 +01:00
gingerBill 77829af9de Fix delete("") on -llvm-api; Fix linalg stuff 2020-09-11 13:46:52 +01:00
gingerBill 97846d8390 Clean up quaternion_from_matrix(3|4) code 2020-09-10 21:19:59 +01:00
gingerBill 079b887313 Make procedure names consistent 2020-09-10 17:32:18 +01:00
gingerBill 6aa708a455 Fix Odin bug with "none" procedure calling conventions in the runtime 2020-09-10 16:36:33 +01:00
gingerBill 8f38b06c60 Add sanity conversion for rand.norm_float64 2020-09-10 15:42:07 +01:00
gingerBill 993fc577b2 Clarify euler angle procedures better 2020-09-10 15:33:50 +01:00
gingerBill 824491f410 Clean up Euler Angle code for math/linalg 2020-09-10 15:23:08 +01:00
gingerBill c1149dbdee Update math and math/linalg; add "pure_none" calling convention 2020-09-10 15:00:19 +01:00
gingerBill 7e625f6ee7 Add extra check for checking uniqueness of package names 2020-09-10 11:13:09 +01:00
gingerBill 2dfa3a5df7 Fix typo 2020-09-07 14:40:36 +01:00
gingerBill 1064622ff7 Improve math/rand functionality 2020-09-07 14:38:01 +01:00
gingerBill f5b8609160 Remove debug print 2020-09-07 12:15:54 +01:00
gingerBill 7f48cf8405 [REFLECTION BREAKING] Modify the internals of the map type to increase performance 2020-09-07 11:41:42 +01:00
gingerBill 7e08bccc9a Merge branch 'master' of https://github.com/odin-lang/Odin 2020-09-04 11:18:58 +01:00
gingerBill 9fd9130891 Add new core procedures: ordered_remove_range; unordered_remove_range; insert_at 2020-09-04 11:18:46 +01:00
gingerBill 9f1f194d18 Merge pull request #727 from JoshuaManton/master-fork
Add allocator parameter to os.read_entire_file()
2020-09-03 08:37:22 +01:00
Joshua Mark Manton 0fe47a2f1b Add allocator parameter to os.read_entire_file() 2020-09-02 18:42:12 -07:00
Mikkel Hjortshøj 31989c93ac Merge pull request #725 from Skytrias/master
fix t0 not being t
2020-08-29 22:48:49 +02:00
Michael Kutowski 7b0ba76915 Update specific.odin 2020-08-29 22:33:24 +02:00
Michael Kutowski bd8ca64a30 Merge pull request #1 from odin-lang/master
Merge pull request #724 from Skytrias/master
2020-08-29 22:32:26 +02:00
Mikkel Hjortshøj 32fda798f3 Merge pull request #724 from Skytrias/master
fix hsl math.mod to usual hsl conversion
2020-08-29 21:58:16 +02:00
Michael Kutowski 12895de9ac fix hsl math.mod to usual hsl conversion 2020-08-29 21:49:49 +02:00
gingerBill 0216ade2f9 Merge pull request #721 from Tetralux/fix-getcwd-allocator
Fix os.get_current_directory() allocator
2020-08-27 11:38:24 +01:00
gingerBill 14e6cdb1a0 Merge pull request #722 from jockus/fix-core-path-name-extension
Fix path.name failing to remove extension
2020-08-27 11:38:04 +01:00
gingerBill 4daf098a3a Fix defer on explicit return of a procedure with no return values for llvm-api 2020-08-27 11:06:44 +01:00
jockus 914c99a15e Merge branch 'master' into fix-core-path-name-extension 2020-08-27 08:24:59 +01:00
gingerBill d31c63c0ae Fix #714 2020-08-27 00:11:02 +01:00
gingerBill c783840eab Fix #642 2020-08-26 23:20:25 +01:00
gingerBill d3eca21e40 Fix style in parse.odin 2020-08-26 22:48:32 +01:00
gingerBill df3690c32a Revert accidental removal of #const for procedure variable parameters #718 2020-08-26 22:46:54 +01:00
gingerBill 999d1a022d Merge branch 'master' of https://github.com/odin-lang/Odin 2020-08-26 22:41:06 +01:00
gingerBill 1f2f3cb315 Fix #712 2020-08-26 22:40:03 +01:00
jockus 8de70ce73d Fix path.name failing to remove extension 2020-08-26 17:32:47 +01:00
Tetralux 3820f27c7c Fix os.get_current_directory() allocator
This procedure accidentally used the temporary allocator for the
returned string.
Use context.allocator, and the allocator parameter idiom instead.
2020-08-26 11:37:44 +00:00
gingerBill 7309cfdbb2 Merge pull request #715 from Platin21/patch-1
Update ring.odin
2020-08-23 17:13:29 +01:00
Mikkel Hjortshoej ea19f3e77f Merge branch 'master' of github.com:odin-lang/Odin 2020-08-23 15:25:45 +02:00
Mikkel Hjortshoej ae2fc5830e Add git sha to odin version command 2020-08-23 15:25:19 +02:00
Platin21 3946f357e8 Update ring.odin
Someone missed the T type here ;)
2020-08-22 13:12:18 +02:00
gingerBill b9b2b90f0c Merge branch 'master' of https://github.com/odin-lang/Odin 2020-08-18 21:12:02 +01:00
gingerBill a6a7395be7 Update unicode/letter.odin 2020-08-18 21:11:51 +01:00
Mikkel Hjortshoej 16b50a2f57 Fix #711 2020-08-18 21:57:47 +02:00
gingerBill e7f54d25d6 Add mem.Allocator_Query_Info and mem.query_info 2020-08-16 23:05:33 +01:00
gingerBill 033b46def8 Add mem.Allocator_Mode.Query_Features, mem.Allocator_Mode_Set, mem.query_features` 2020-08-16 22:07:40 +01:00
gingerBill 1f571f48e5 Add mem.Tracking_Allocator 2020-08-16 21:29:14 +01:00
gingerBill ec178825ec Add more sort.compare_* procedures 2020-08-16 12:40:28 +01:00
gingerBill 6158a49618 Make sync.atomic_* operations use when statements instead of switch; Make #panic diverging 2020-08-16 12:34:12 +01:00
gingerBill 674aeffee4 Fix typo 2020-08-12 19:15:47 +01:00
gingerBill 546759bdef Fix multi_logger_proc to check for lowest_level 2020-08-12 19:01:25 +01:00
gingerBill fa903fb4df Fix #674 2020-08-06 00:09:36 +01:00
gingerBill 5164d1d866 Fix named results but in ir.cpp 2020-08-05 23:43:23 +01:00
gingerBill b6e33a1e64 Ensure add_type_info_type and add_min_dep_type_info are consistent 2020-08-05 23:36:31 +01:00
gingerBill f5248a8d9d Fix #705 2020-08-05 23:33:35 +01:00
gingerBill 74ed779616 Fix #702 2020-08-05 23:14:11 +01:00
gingerBill 9f24188ec8 Fix #708 2020-08-05 22:51:24 +01:00
gingerBill 5551404be4 Fix gb_alloc_str_len 2020-08-05 22:32:27 +01:00
gingerBill 9fd35776fd Fix typos in math.odin 2020-08-04 14:40:11 +01:00
gingerBill 3385fcecb0 Fix typo 2020-08-04 14:31:14 +01:00
gingerBill 804b96a985 Remove unused entities 2020-08-02 15:11:21 +01:00
gingerBill 9cc20954a3 Add sys/windows/synchronization.odin 2020-08-02 15:07:52 +01:00
gingerBill 91ff3e5bca Add sync/channel_*.odin files 2020-08-02 15:05:04 +01:00
gingerBill 6d032e6f1a Update package sync 2020-08-02 15:01:17 +01:00
gingerBill 16abfd56e8 Merge branch 'master' of https://github.com/odin-lang/Odin 2020-08-02 14:59:51 +01:00
gingerBill d1d5f61230 Add intrinsics.alloca 2020-08-02 14:59:39 +01:00
gingerBill 5b7e1cd6f6 Update LICENSE 2020-08-01 11:35:56 +01:00
gingerBill cbfe3571ab Merge pull request #693 from powerc9000/patch-2
Fix pthread_t on Macos.
2020-07-22 22:28:38 +01:00
gingerBill b04bc21ec6 Merge pull request #704 from oskarnp/log_thread_id
Add .Thread_Id option to log package
2020-07-22 22:27:53 +01:00
gingerBill 2945feecde Merge pull request #703 from oskarnp/darwin_thread_id
Implement os.current_thread_id() for Darwin (assumes OSX 10.6 / iOS 3…
2020-07-22 22:27:02 +01:00
Oskar Nordquist 36cac87387 Add .Thread_Id option to log package 2020-07-22 17:42:01 +02:00
Oskar Nordquist a7e38dc063 Implement os.current_thread_id() for Darwin (assumes OSX 10.6 / iOS 3.2 and later) 2020-07-22 17:38:13 +02:00
gingerBill 0aaab84938 Allow multiple -define flags 2020-07-16 20:59:03 +01:00
gingerBill 3a1492fc99 Add sync.Wait_Group 2020-07-15 00:25:37 +01:00
gingerBill ca818fb857 Remove comments containing unicode characters from tokenizer 2020-07-14 23:51:46 +01:00
gingerBill 13e5cb8cc4 Fix #691 and Fix #692 2020-07-14 23:50:09 +01:00
gingerBill 7ae54ae3b4 Add -no-dynamic-literals to disallow dynamic array and map literals 2020-07-14 23:01:34 +01:00
gingerBill b2beb9512f Add thread.join_multiple 2020-07-14 21:08:04 +01:00
gingerBill 96ad6d2084 Improve sync.Channel behaviour 2020-07-14 18:43:50 +01:00
gingerBill 86f1574f78 Fix #696 2020-07-14 16:43:23 +01:00
gingerBill 6565a49e34 Remove fmt from sync/channel.odin 2020-07-14 16:39:47 +01:00
gingerBill ce85b73eca Add sync.Once 2020-07-14 16:38:54 +01:00
gingerBill fc65aee307 Update sync.Channel 2020-07-14 16:37:29 +01:00
gingerBill ede135a08f Merge branch 'master' of https://github.com/odin-lang/Odin 2020-07-14 16:36:47 +01:00
gingerBill c18fc2da9f Remove some dead code 2020-07-14 16:36:33 +01:00
gingerBill c8a3937ea0 Merge pull request #695 from jharler/master
Added "sep" parameter to logging procs
2020-07-13 13:28:30 +01:00
jharler f9a6777e3a Added "sep" parameter to logging procs 2020-07-13 08:22:41 -04:00
Clay Murray 83eabe2140 Fix pthread_t on Macos.
From some testing with directly using C code, pthread_t on macos is 8 bytes.
This is my test code:

```
#include <assert.h>
#include <stdio.h>

#include <pthread.h>



void* PosixThreadMainRoutine(void* data)

{

	// Do some work here.
	for (int i = 0; i < 2000000000; i++) {

	}



	return NULL;

}



pthread_t LaunchThread()

{

	// Create the thread using POSIX routines.

	pthread_attr_t  attr;

	pthread_t       posixThreadID;

	int             returnVal;



	returnVal = pthread_attr_init(&attr);

	assert(!returnVal);

	returnVal = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);

	assert(!returnVal);



	int     threadError = pthread_create(&posixThreadID, &attr, &PosixThreadMainRoutine, NULL);



	returnVal = pthread_attr_destroy(&attr);

	assert(!returnVal);

	if (threadError != 0)

	{

		// Report an error.

	}

	return posixThreadID;

}

int main() {
	pthread_t t = LaunchThread();

	void ** ret;


	printf("%d, %d\n", sizeof(t), sizeof(pthread_t));

	int val = pthread_join(t, ret);


	printf("%d", val);
	return 0;
}
```
running this on macos reports `8, 8`. 
Then I made the proposed changes and errors I was having with threads completely went away.
2020-07-11 18:22:56 -06:00
gingerBill c4067372dd Fix double declaration 2020-07-10 22:28:48 +01:00
gingerBill b4e976364a Add path_unix.odin 2020-07-10 08:42:59 +01:00
gingerBill 642afa4f88 Fix new package path 2020-07-10 08:42:22 +01:00
gingerBill f65fa0e4a6 Merge pull request #339 from dotbmp/master
"core:path" Path library and "core:strings" `split` Utilities
2020-07-10 08:25:24 +01:00
gingerBill 65b9dbe13f Clean-up OS constants; Clean-up procs_wasm32.odin 2020-07-09 17:21:40 +01:00
gingerBill cb52f6986a Fix Addressing_OptionalOk selector expression rules for struct field variables 2020-07-08 23:39:49 +01:00
gingerBill 94ba182691 Add sync.Benaphore 2020-07-08 23:16:54 +01:00
gingerBill 5b7c83d871 Add strings.pop_byte strings.pop_rune 2020-07-08 23:15:48 +01:00
gingerBill 4059542afb Merge pull request #673 from kevinw/patch-2
add `#config` to odin parser
2020-07-08 23:08:31 +01:00
gingerBill 9da1347c21 Fix Source_Code_Location error for *_insert_dynamic_map_key_and_value procedures 2020-07-08 22:57:39 +01:00
gingerBill a8c10c58b4 Fix negation of complex and quaternion numbers for ir.cpp backend 2020-07-08 22:35:47 +01:00
Mikkel Hjortshøj 6d9b2ec5b4 Merge pull request #685 from ThisDrunkDane/master
Fix misplaced line number in log (was wrongly formatted and before procedure)
2020-07-05 19:53:22 +02:00
Mikkel Hjortshoej d749f5c704 Fix typo 2020-07-02 16:13:49 +02:00
Mikkel Hjortshoej 83f553cd89 Revert to old format and fix : when no file opt specified 2020-07-02 16:11:41 +02:00
Mikkel Hjortshoej 730f9ee0b3 Fix misplaced line number (was wrongly formatted and before procedure) 2020-07-02 15:31:40 +02:00
gingerBill 51e50d3e31 Add intrinsics.type_proc_parameter_type; Add intrinsics.type_proc_return_type 2020-07-01 22:35:38 +01:00
gingerBill 1b2cc739a9 Handle llvm package name edge case for IR mangling 2020-06-30 19:12:53 +01:00
gingerBill 7bdd8094d6 Fix signature_parameter_similar_enough logic 2020-06-30 19:10:24 +01:00
gingerBill 323fc7a6a9 Fix system calls for compiler 2020-06-30 19:04:14 +01:00
gingerBill 92363da58e Add -show-system-calls; Update runtime for windows_386; Fix some minor bugs 2020-06-30 10:09:58 +01:00
gingerBill 0ea64182f1 Begin work on windows 386 2020-06-29 17:35:33 +01:00
gingerBill 8478b887a5 Add mem.check_zero and mem.check_zero_ptr 2020-06-29 16:17:40 +01:00
gingerBill 86448ee044 Add raw_data to replace cases in which &x[0] was used 2020-06-29 15:58:24 +01:00
gingerBill 56a52a1d06 Add sync.condition_wait_for_timeout for unix 2020-06-27 12:21:31 +01:00
gingerBill 858c5f8fd8 Update thread_unix logic 2020-06-27 11:36:48 +01:00
gingerBill f92b4c7849 Update sys/unix; Rename thread.create_and_start 2020-06-27 11:26:38 +01:00
gingerBill 9fdebebd28 Add sync.Barrier; Add sync.Blocking_Mutex for unix 2020-06-27 11:23:37 +01:00
gingerBill 2b18f43b65 Update sys/windows; Add sync.Blocking_Mutex (windows only at the moment) 2020-06-27 00:59:40 +01:00
gingerBill 53e1512978 Add more exception handling stuff to sys/windows 2020-06-26 20:42:17 +01:00
gingerBill b5f9c95ce7 Remove foreign import for -vet 2020-06-26 20:33:47 +01:00
gingerBill 231f91304a Keep previous behaviour for sync but move to sys/windows 2020-06-26 20:30:33 +01:00
gingerBill d7b3f3a0e7 Revert sync_windows.odin 2020-06-26 20:22:48 +01:00
gingerBill bb81d4869f Update sys/windows 2020-06-26 20:09:31 +01:00
gingerBill b633a42bc2 Revert channel.odin 2020-06-26 19:16:17 +01:00
gingerBill 6bd05ef5d7 Begin migration from sys/win32 to sys/windows 2020-06-26 19:11:34 +01:00
gingerBill 251a3a690e Add optional sep parameter to fmt.*print and fmt.*println procedures 2020-06-25 15:00:50 +01:00
gingerBill f22b014db0 Revert build.bat 2020-06-23 09:20:13 +01:00
gingerBill a6edcf4f18 Fix ABI typo bug; Add pop_safe and pop_front_safe 2020-06-22 21:03:57 +01:00
gingerBill 2a598aa061 Update sync.Channel 2020-06-22 17:45:01 +01:00
gingerBill 910ab7b3d4 Fix typo 2020-06-22 17:00:35 +01:00
gingerBill 2b27300387 Fix LLVM code gen bug 2020-06-22 16:57:21 +01:00
gingerBill 0db1ebb4e5 -vet sync/channel.odin 2020-06-22 16:01:26 +01:00
gingerBill 0013033f9a Revert build.bat 2020-06-22 15:58:48 +01:00
gingerBill f00123742c Add experimental sync.Channel 2020-06-22 15:54:35 +01:00
gingerBill 509e8b512f Add time.read_cycle_counter 2020-06-22 15:54:19 +01:00
gingerBill 2562df5387 Remove unused imports in thread.odin 2020-06-22 13:35:44 +01:00
gingerBill 0ab356aa4e Fix sync and thread on *nix 2020-06-22 13:32:58 +01:00
gingerBill b3c51a8b44 Add thread.run* shorthand procedures; Thread.init_context use new Maybe concept 2020-06-22 13:28:37 +01:00
gingerBill fb3aeccd36 Add built-in Maybe 2020-06-22 13:25:19 +01:00
gingerBill 9495e3d10c Update sync.Condition to require a ^sync.Mutex on init 2020-06-22 13:24:51 +01:00
gingerBill 0f711b8719 Remove old llvm-demo 2020-06-21 20:04:29 +01:00
gingerBill 2a6130b7e1 Reorder log.do_location_header order 2020-06-19 15:24:42 +01:00
gingerBill 34384cc2f1 Clean up some of the log code 2020-06-19 15:18:23 +01:00
gingerBill aeafed0218 Add fmt.DEFAULT_BUFFER_SIZE to be configurable with #config(FMT_DEFAULT_BUFFER_SIZE, 1<<12) 2020-06-19 15:08:54 +01:00
gingerBill 3a4bbfcfae Change fmt.*print behaviour to match fmt.*println behaviour 2020-06-19 15:01:39 +01:00
gingerBill 01c84b32a6 Add log.panic and log.panicf 2020-06-19 12:23:06 +01:00
gingerBill 240fc65d4d Add multi_logger.odin; Fix os_windows.odin 2020-06-19 11:49:08 +01:00
gingerBill c9d3b95b0d Fix time.now 2020-06-19 11:35:43 +01:00
gingerBill 9f596d6f34 Clean up package log code 2020-06-19 11:18:23 +01:00
gingerBill 2a684830f9 Fix using pointers bug with addressing struct fields 2020-06-18 17:50:54 +01:00
gingerBill c4ba3f1c83 Merge branch 'master' of https://github.com/odin-lang/Odin 2020-06-17 23:28:46 +01:00
gingerBill 724c776dbe Fix enumerated array type information creation bug 2020-06-17 23:28:39 +01:00
Mikkel Hjortshoej ad8048b615 [CI] Use powershell to download LLVM on windows, split macOS and linux. 2020-06-16 18:12:43 +02:00
gingerBill 781395ada1 Add deferred_in_out attribute 2020-06-16 16:21:44 +01:00
gingerBill 9635ea8706 Revert demo.odin 2020-06-16 16:08:51 +01:00
gingerBill 413188bab2 Merge branch 'master' of https://github.com/odin-lang/Odin 2020-06-16 16:07:53 +01:00
gingerBill 5fa54fd2cc Commit fix 2020-06-16 16:07:44 +01:00
gingerBill b79e1b6b5c Cleanup package encoding/json 2020-06-16 16:05:15 +01:00
gingerBill 8dff0f7ef5 -vet code 2020-06-16 12:57:06 +01:00
gingerBill f85f3dce12 Revert demo.odin 2020-06-16 12:55:09 +01:00
gingerBill 5edb1e8a28 Add hash.djb2 hash.jenkins; Add container.Bloom_Filter; Add container.Ring 2020-06-16 12:53:57 +01:00
gingerBill f70939ab4f Use windows specific exception traps 2020-06-15 12:39:29 +01:00
gingerBill 08e271720a Merge branch 'master' of https://github.com/odin-lang/Odin 2020-06-15 11:54:28 +01:00
gingerBill c3ebc49ad2 Fix @static slice for LLVM C API backend 2020-06-15 11:54:18 +01:00
vassvik 9cccb20f49 Add some tests to test utf16_to_utf8 and wstring_to_utf8 2020-06-13 18:04:19 +02:00
vassvik 6985d72fda Make os.get_current_directory no longer strip the zero at the end of the resulting string, as it no longer should occur. 2020-06-13 15:20:39 +02:00
vassvik 0056cdffa7 Reworked win32.utf16_to_utf8 and win32.wstring_to_utf8 to scan for zeros from the start of the string instead of from the end.
This is useful to correctly convert strings from a buffer possibly containing multiple multiple substrings.

The resulting utf8 string is not null terminated, even if the backing memory might be null terminated.
2020-06-13 15:19:41 +02:00
gingerBill a229f9825b Fix -vet warning for fmt.printf("%10s") 2020-06-12 23:13:26 +01:00
gingerBill a6ff48a5de Merge pull request #681 from ralph-the-mighty/stringwidth
Control %s width in fmt.print* functions
2020-06-12 23:10:28 +01:00
Josh 6648dc9ed1 use width in when printing formatted string to control padding added after the string 2020-06-12 18:05:40 -04:00
vassvik bbbf7168f1 Add wstring_to_utf8 to sys/win32 2020-06-12 21:06:21 +02:00
vassvik c15ed44f82 Fix off by one bug introduced in the previous commit. 2020-06-12 18:19:46 +02:00
gingerBill 58466a6f3b Add extra NUL termination check for string length in win32 general string convertors 2020-06-12 15:01:43 +01:00
gingerBill be76c860a5 mem.simple_equal 2020-06-12 14:52:31 +01:00
gingerBill 4533c02cc7 Improve intrinsics.type_is_simple_compare 2020-06-12 14:37:27 +01:00
gingerBill 01d12770fa Fix compound literals for constant procedure fields 2020-06-11 16:11:54 +01:00
gingerBill 82b559c32b Remove debug code 2020-06-10 19:29:24 +01:00
gingerBill 474d79dcf1 Add mem.simple_compare_values 2020-06-10 16:37:22 +01:00
gingerBill 61db6c1234 Add force usage when importing intrinsics or builtin 2020-06-10 16:36:59 +01:00
gingerBill e641d714a0 Fix #677 2020-06-10 16:32:53 +01:00
gingerBill f305726015 Fix #c_vararg for LLVM C API 2020-06-10 16:15:56 +01:00
gingerBill 57b09b2ffb Fix #439 2020-06-10 15:37:50 +01:00
gingerBill e86fde3cb1 Fix #648 2020-06-10 15:09:04 +01:00
gingerBill 99944f3b02 Improve behaviour of return with named results to aid with defer statements 2020-06-10 14:53:35 +01:00
gingerBill a9295d33ab Fix #674 2020-06-10 14:39:50 +01:00
gingerBill 4acae2af44 Add support for using on relative pointers #670 2020-06-10 14:25:11 +01:00
gingerBill 036429bf2f Fix reflect.as_i64 and reflect.as_u64 2020-06-10 14:13:50 +01:00
gingerBill d0920804c3 Stop statement generation after terminating instruction in current block (LLVM C API) 2020-06-10 13:57:25 +01:00
gingerBill 97d3d4ff6f Minor changes for \*nix backend 2020-06-10 13:38:17 +01:00
gingerBill 6ea0910213 Fix typo 2020-06-10 13:02:42 +01:00
gingerBill b8d33165c9 Add -target:<string> fuzzy checking with "Did you mean" message 2020-06-10 12:59:54 +01:00
gingerBill 6b3ee447f0 Basic cross compilation support 2020-06-10 12:26:31 +01:00
gingerBill 9b1cc6e94f Update logic for slice literals, backing array to be on the stack if possible (LLVM C API) 2020-06-08 12:41:42 +01:00
gingerBill 0ffb718a91 Add fmt.User_Formatter 2020-06-08 12:40:50 +01:00
gingerBill a7dd686859 Add #caller_location to strings.clone; remove deprecated procedures in package strings 2020-06-08 11:42:38 +01:00
gingerBill 87a6d695d6 Fix typo in error message 2020-06-06 22:39:36 +01:00
gingerBill a89633e3ed Remove return after unreachable 2020-06-06 15:22:22 +01:00
gingerBill 59a0bbb385 Improve termination rules checking for missing return; Make diverging procedure -> ! be terminators 2020-06-06 15:16:24 +01:00
gingerBill a3fa647bfd Add package sys/llvm to expose some of the LLVM intrinsics 2020-06-06 14:52:22 +01:00
gingerBill 1a4e2196bd Fix runtime.bswap_16 2020-06-05 14:12:30 +01:00
gingerBill d8f9daac95 Fix different endian integers for LLVM C API backend 2020-06-05 13:12:57 +01:00
gingerBill f992e36f9a Rename reflect.to_* to reflect.as_* 2020-06-05 10:38:38 +01:00
gingerBill 11dd971e13 Add reflect.{to_int, to_uint, to_i64, to_u64, to_f64} 2020-06-05 10:27:32 +01:00
gingerBill 5ed4bac16f Merge pull request #676 from Tetralux/fix-temp-alloc-resize
Fix temporary allocator resizing
2020-06-04 23:13:41 +01:00
Tetralux 04ceb5d20c Fix temporary allocator resizing 2020-06-04 21:49:07 +00:00
Kevin Watters 0b67de47d6 add #config to odin parser
Update the `core:odin` parser for the new `#config` idiom.
2020-06-04 10:48:13 -04:00
gingerBill 15c4077806 Fix WASM foreign import names 2020-06-04 00:30:44 +01:00
gingerBill 37a3abdaaa Fix calling convention stuff with LLVM C API 2020-06-03 21:23:30 +01:00
gingerBill ac709b8afb Merge branch 'master' of https://github.com/odin-lang/Odin 2020-06-03 21:10:18 +01:00
gingerBill d80049bfd2 Change runtime.Type_Info_Enum_Value to be i64 internally rather than a union 2020-06-03 21:10:07 +01:00
gingerBill 239f3c0418 Merge pull request #672 from foxnne/fixwrap
Fix wrap in core:math.
2020-06-03 14:57:43 +01:00
gingerBill 5b11a842a8 Merge pull request #668 from kevinw/patch-1
Remove `intrinsics` import
2020-06-03 14:56:36 +01:00
gingerBill 626b4740b1 Add wasm-ld support for wasm code generation 2020-06-03 13:12:38 +01:00
foxnne 437d5e28cd fix wrap in core:math 2020-06-02 00:37:06 -05:00
Kevin Watters 6c7fc4212a Remove intrinsics import
When using `linalg` with the `-vet` compiler switch, you get the warning/error:

`odin/core/math/linalg/specific.odin(4:8) 'intrinsics' declared but not used`
2020-06-01 18:44:47 -04:00
gingerBill 8589af1458 Improve bits.rotate_left* 2020-05-31 16:19:08 +01:00
gingerBill bf5ce04b24 Improve rules for shifting behaviour
Example:
x: u64 = 123;
assert(x >> 64 == 0); // In C this would be 123 because (64 & 0b111111) == 0

a: u64 123;
assert(a << 64 == 0); // In C this would be 123 because (64 & 0b111111) == 0
2020-05-31 13:50:17 +01:00
gingerBill 8057af9e09 Fix #659 Compiler error when indexing constant slices 2020-05-31 12:20:47 +01:00
gingerBill d8bc2030e6 Fix big_int_to_f64 2020-05-30 16:45:49 +01:00
gingerBill 5eaef091e2 Update math/bits 2020-05-30 12:24:00 +01:00
gingerBill 84fd40de77 Fix rules for recursive initialization with procedure entities; Fix executable name if not given 2020-05-30 12:23:41 +01:00
gingerBill 1d7f99cbdf Remove mem_zero from make; Implement custom memset for windows amd64 2020-05-27 20:17:58 +01:00
gingerBill 3d4a3730b0 Add notin deprecation 2020-05-27 18:47:45 +01:00
gingerBill 1f31d573e4 Fix tokenization 2020-05-27 18:43:02 +01:00
gingerBill 237962182b Fix tokenizing for %% 2020-05-27 18:41:10 +01:00
gingerBill e84406a895 Move zero_size 2020-05-27 18:26:20 +01:00
gingerBill 1a0614b0d7 Improve performance of tokenization and parsing 2020-05-27 18:23:37 +01:00
gingerBill 876820789e Add rune_is_letter_or_digit for tokenizer 2020-05-27 12:54:11 +01:00
gingerBill 4e21a4d46a Optimize rune_is_* procedures for tokenizer 2020-05-27 12:43:49 +01:00
gingerBill 6ac0fb80a6 Minor tokenizer performance improvements 2020-05-27 12:32:11 +01:00
gingerBill 098699103d Begin work on supporting wasm32 architecture 2020-05-25 12:46:23 +01:00
gingerBill d6bcc25b69 Fix tokenizer for 0i #658 2020-05-24 21:43:36 +01:00
gingerBill a2c50d3666 Fix -vet for strings 2020-05-24 17:57:55 +01:00
gingerBill f06efffe22 Update strings case convertors to be unicode compliant 2020-05-24 17:50:27 +01:00
gingerBill e42f7008fc Change spaces to tabs 2020-05-24 16:40:48 +01:00
gingerBill 26c9d17040 Merge branch 'master' of https://github.com/odin-lang/Odin 2020-05-24 12:52:19 +01:00
gingerBill 2be87169ef Fix #656 2020-05-24 12:52:08 +01:00
Mikkel Hjortshøj 732c745bb3 Merge pull request #655 from ThisDrunkDane/master
Add case conversions by @dotbmp
2020-05-24 12:52:38 +02:00
Mikkel Hjortshoej c035fc337f Add case conversions by @dotbmp 2020-05-24 12:47:43 +02:00
gingerBill cbfbff7240 Add intrinsics.type_is_comparable; Add sort.linear_search 2020-05-23 14:02:21 +01:00
gingerBill 99e6eba20f Revert demo.odin 2020-05-23 13:57:45 +01:00
gingerBill 7d11ee605c Add sort.binary_search (uses interpolation sort for ordered numeric types) 2020-05-23 13:57:24 +01:00
gingerBill 4671207c61 Make the using import deprecation warning an error 2020-05-23 13:39:18 +01:00
gingerBill aa029fe8d9 Add "pure" procedure types 2020-05-23 13:38:06 +01:00
gingerBill ef539696b9 Strip carriage return \r from raw string literals 2020-05-23 11:39:29 +01:00
gingerBill 26fe9b0212 Fix SelectorCallExpr with no return values 2020-05-22 23:41:17 +01:00
gingerBill fd6e2ed5de Revert demo.odin 2020-05-22 14:56:32 +01:00
gingerBill 7bd1039a49 Selector Call Expressions: x->y(123) == x.y(x, 123) 2020-05-22 14:54:30 +01:00
gingerBill 76a230372f Merge branch 'master' of https://github.com/odin-lang/Odin 2020-05-22 12:32:36 +01:00
gingerBill 86b613fb15 Remove the need for type_of, size_of, align_of, offset_of to be keywords 2020-05-22 12:32:29 +01:00
gingerBill aacf524a47 Merge pull request #653 from lkppo/master
Fix the shebang portability of the build.sh script
2020-05-22 10:35:49 +01:00
Stéphane Aulery 8ad3a1f41f Fix the shebang portability of the build.sh script 2020-05-22 11:28:17 +02:00
gingerBill d09ac8943a Minor fixes to improve hash map/set performance 2020-05-21 16:27:40 +01:00
gingerBill 8e63c94393 Add string.h 2020-05-21 11:10:03 +01:00
gingerBill 0b16ed7c85 Use memcmp for str_eq 2020-05-21 11:05:38 +01:00
gingerBill 89d824216a Add extra information to -show-more-timings 2020-05-21 09:30:15 +01:00
gingerBill 3f23a0b3b0 Fix edge cases of relative pointers 2020-05-17 15:23:27 +01:00
gingerBill 7819fec0a1 Merge pull request #645 from Tetralux/llvm-noabc-obey-directive
LLVM C backend: Obey directives on blocks, procedures, and expressions
2020-05-16 18:15:25 +01:00
Tetralux 96ed948590 LLVM C backend: Obey directives on blocks, procedures, and expressions
e.g: #no_bounds_check / #bounds_check
2020-05-16 17:04:16 +00:00
gingerBill 3bd01d3a02 Merge pull request #644 from Tetralux/llvm-bounds-checks
Add bounds checks to LLVM C backend
2020-05-16 15:32:15 +01:00
Tetralux c4b492fb64 Add bounds checks to LLVM C backend 2020-05-16 14:25:36 +00:00
gingerBill e1bdaa981a Relative pointer and relative slices 2020-05-15 18:45:24 +01:00
gingerBill 95e8668b77 Relative pointers in old backend 2020-05-15 17:52:09 +01:00
gingerBill 90adf214d7 Merge branch 'master' of https://github.com/odin-lang/Odin 2020-05-15 17:37:14 +01:00
gingerBill ff92eb9112 Relative pointers 2020-05-15 17:37:00 +01:00
gingerBill 5f08c77d8b Merge pull request #641 from Tetralux/fix-container-arraypushelems
Fix container.Array.array_push_back_elems
2020-05-15 08:49:26 +01:00
Tetralux dc236d6830 Fix container.Array.array_push_back_elems
We were previously using array_slice to get the storage
that we were copying the new elements into, using the current
length as the offset: `copy(data[len:], ..elems)`

However, array_slice returns a slice over `data[0:len]` -- we
were using it as if it was `data[0:cap]`.

Add array_cap_slice that does this instead. :^)
2020-05-15 03:54:32 +00:00
gingerBill 8b066b2456 Fix runtime.memset issue 2020-05-14 17:56:24 +01:00
gingerBill 218c1599b1 Add explicit context to thread_unix.odin 2020-05-14 13:48:03 +01:00
gingerBill 9b2eecb3df Merge branch 'master' of https://github.com/odin-lang/Odin 2020-05-14 13:44:34 +01:00
gingerBill e0a242e9a1 Enforce explicit context definition for procedure calls 2020-05-14 13:44:28 +01:00
Mikkel Hjortshoej 48946fe46f Alright, things work. Reverting broken stuff 2020-05-14 14:20:04 +02:00
Mikkel Hjortshoej 0b0e661b62 Another test sorry 2020-05-14 14:18:20 +02:00
Mikkel Hjortshoej 10c3acf37f Remove test for webhook 2020-05-14 14:09:22 +02:00
Mikkel Hjortshoej e377f5a329 Briefly break master to test webhook 2020-05-14 14:07:33 +02:00
gingerBill cd4403be0c Fix Assertion failure in ir_print_exact_value #620 2020-05-14 00:34:27 +01:00
gingerBill f661d34049 Implement Explicit context creation #639 2020-05-14 00:13:26 +01:00
gingerBill af1d4d6e72 Implement Allow .? operator to unwrap any union #549 2020-05-14 00:00:10 +01:00
gingerBill f6c7a0c9b8 Fix -llvm-api memset "bug" 2020-05-13 23:51:51 +01:00
gingerBill c2bfb221f5 Fix #561 where statements that eval to false do not show incorrect usage location 2020-05-13 23:45:55 +01:00
gingerBill d59fced21b #591 Improve type switch statement error for fallthrough 2020-05-13 23:33:03 +01:00
gingerBill 7c42d4ba75 (#594) Add #config to replace #defined; Restrict #defined within procedure bodies to remove race condition 2020-05-13 23:29:06 +01:00
gingerBill 14ce6d8ed8 Fix #632 behaviour 2020-05-13 23:09:38 +01:00
gingerBill 2630e9ced1 Fix #622 on both backends 2020-05-13 23:00:34 +01:00
gingerBill 482c687462 Fix procedure references in global compound literals in old backend 2020-05-13 22:42:15 +01:00
gingerBill de8c1165c2 Fix procedure literal declarations at file scope with -llvm-api 2020-05-13 22:30:38 +01:00
gingerBill d51b98a8d2 Add extra 128 bit integer procedures 2020-05-13 13:46:32 +01:00
gingerBill 6861ff47bc Replace entity_of_ident with entity_of_node 2020-05-12 16:28:22 +01:00
gingerBill 0ba3b5c0bd Fix bug for array-like compounds for LLVM-API 2020-05-12 14:57:37 +01:00
gingerBill fcdfcfce19 Let -vet ignore intentional declaration shadowing #637 2020-05-12 10:31:49 +01:00
gingerBill d49ecd9009 Merge pull request #638 from jharler/master
Fixed thread_pool not destroying threads
2020-05-11 17:38:05 +01:00
jharler 72a5030f3d Fixed thread_pool not destroying threads 2020-05-11 12:32:35 -04:00
gingerBill 197a72adde Merge pull request #616 from Tetralux/fix-sync-badopt
Fix potential bad optimization bug in sync.Ticket_Mutex
2020-05-10 10:37:11 +01:00
gingerBill f043e92650 Add strconv.unquote_string and strconv.unquote_char 2020-05-09 13:58:45 +01:00
gingerBill e3f3e715e2 Merge pull request #634 from Tetralux/enum_from_name
Add reflect.enum_from_name
2020-05-09 12:57:27 +01:00
gingerBill e8f2fb58d9 Fix strconv.parse_ usage across other packages 2020-05-09 11:54:36 +01:00
Tetralux 8d2430e54d Add reflect.enum_from_name
Provides a way to go from a enum value name string to an actual enum value.

```
E :: enum { A, B }

// ...

s := "B";
v, ok := enum_from_name(E, s);
assert(ok && v == E.B);
```
2020-05-09 07:30:07 +00:00
gingerBill dc1b3cc563 Merge branch 'master' of https://github.com/odin-lang/Odin 2020-05-08 16:09:45 +01:00
gingerBill d52695b077 Fix constant complex arithmetic bug 2020-05-08 16:09:35 +01:00
gingerBill 6adbdb1e0e Merge pull request #633 from Tetralux/fix-parseint-again
Fix parsing of single-digit numbers
2020-05-07 00:35:26 +01:00
Tetralux 7d4f9545a7 Fix parsing of single-digit numbers 2020-05-06 23:21:24 +00:00
gingerBill 4fc60601d3 Fix ABI typo 2020-05-06 20:18:43 +01:00
gingerBill 4f4c3bb03b Add -extra-linker-flags:<string> 2020-05-06 13:41:22 +01:00
gingerBill 8434cb8951 Merge pull request #630 from Tetralux/parseint
Refactor parsing procedures: Return (value, ok) instead
2020-05-05 21:05:13 +01:00
gingerBill 99ebb5af3b Support --flag as redundancy for -flag 2020-05-04 18:23:23 +01:00
gingerBill 45274868c3 Fix -subsystem:windows for normal backend 2020-05-04 18:07:49 +01:00
gingerBill 3ef9566817 Fix typo 2020-05-03 16:18:47 +01:00
gingerBill 3299d6a204 Add -ignore-vs-search 2020-05-02 18:50:38 +01:00
gingerBill e27f5796d6 Add experimental atom op tables for llvm-backend 2020-05-02 18:45:57 +01:00
gingerBill ba4363d678 Improve append_elem(s) logic 2020-05-02 12:09:25 +01:00
gingerBill eb2b3572bb Move TypeProc outside 2020-05-02 11:59:43 +01:00
gingerBill 1a9e75267b Fix rc.exe call 2020-05-02 10:00:34 +01:00
gingerBill dd0fb744fe Add missing ; 2020-04-30 19:26:31 +01:00
gingerBill 70a66cd559 Add -subsystem to odin build -help 2020-04-30 17:57:21 +01:00
gingerBill 832a586b8d Merge branch 'master' of https://github.com/odin-lang/Odin 2020-04-30 17:48:46 +01:00
gingerBill 117ade0700 Fix errors in package win32 2020-04-30 17:48:35 +01:00
Tetralux 25f77e32ee Fix doc comments 2020-04-29 23:35:26 +01:00
Tetralux 704ee9f851 Return (value: T, ok: bool) instead 2020-04-29 22:37:33 +01:00
Tetralux 190932935c Refactor parse_* procedures: arbitrary bases, and return (value, rest_of_string) 2020-04-29 21:33:33 +01:00
gingerBill a10d180d81 Merge pull request #627 from zhibog/master
Added #maybe to the builtin parser and ast for Unions
2020-04-25 17:49:06 +01:00
zhibog c704de8442 Added the #maybe directive to the union struct in the AST. Also added it to the parsing code for a union. 2020-04-25 18:21:32 +02:00
gingerBill f63b9806d2 LLVM API: Fix compound literals with constant parameters to union fields 2020-04-25 14:45:34 +01:00
gingerBill 9409f53a9b Merge branch 'master' of https://github.com/odin-lang/Odin 2020-04-24 20:42:57 +01:00
gingerBill 9faf292218 Fix @(export) for global variable declarations 2020-04-24 20:42:47 +01:00
Mikkel Hjortshøj 92f5f86193 Remove push: on nightly 2020-04-23 22:38:54 +02:00
Mikkel Hjortshøj 1e711fa5a5 Merge pull request #625 from ThisDrunkDane/nightly-build
Improve nightly builds
2020-04-23 22:38:22 +02:00
Mikkel Hjortshoej 51b346753a Github actions apparently doesn't support YAML comments 2020-04-23 22:30:44 +02:00
Mikkel Hjortshoej b63aa0520a Remove the LLVM-C.lib from nightlies and include LLVM-C.dll 2020-04-23 22:30:07 +02:00
Mikkel Hjortshoej 04e106e06a Test push 2020-04-23 22:17:49 +02:00
Mikkel Hjortshoej 5d42a6de6e Remove llvm-binaries.zip from artifacts 2020-04-23 22:17:27 +02:00
Mikkel Hjortshoej bb3e0fa03f Add sizeInBytes of zip files to nightly.json generation 2020-04-23 22:16:31 +02:00
Tetralux e7e936f480 Merge branch 'master' into fix-sync-badopt 2020-04-22 06:12:41 +01:00
gingerBill 026bb8ed6f Remove unused headers 2020-04-21 23:26:59 +01:00
gingerBill cbc3800797 Merge branch 'master' of https://github.com/odin-lang/Odin 2020-04-21 23:26:09 +01:00
gingerBill 4236e870d7 Fix type assertion bug #619 2020-04-21 23:26:02 +01:00
gingerBill b725ae5ae0 Merge pull request #617 from Tetralux/dep-yield-processor
Rename `yield_processor` to `cpu_relax`
2020-04-21 18:07:04 +01:00
Tetralux 3afa2736b7 Fix potential bad optimization bug in sync.Ticket_Mutex
When locking, we were not loading m.serving atomically and so the optimizer
could have hoisted the check out of the loop, thus resulting in an infinite loop.
2020-04-21 17:04:29 +00:00
Tetralux 8dd1b61aa2 sync.yield_processor -> sync.cpu_relax; have it call intrinsics.cpu_relax 2020-04-21 16:07:18 +00:00
gingerBill f5a1d8f2b5 Merge pull request #614 from Tetralux/patch-1
Remove outdated comment
2020-04-21 15:35:24 +01:00
Tetralux d3f2f94800 Remove outdated comment
This is what I get for removing the ability to provide a stack at the last minute.... 🤣
2020-04-21 15:22:42 +01:00
gingerBill f141e2868d container.Set 2020-04-20 00:12:01 +01:00
gingerBill 400d6014d0 container.Small_Array 2020-04-19 23:57:57 +01:00
gingerBill ab6947b2c7 container.Small_Array 2020-04-19 23:57:40 +01:00
gingerBill 52bbdefec4 container.Map 2020-04-19 23:43:02 +01:00
gingerBill 8ee67e41f4 Fix #optional_ok; Fix container.Array 2020-04-19 23:08:50 +01:00
gingerBill 0af2b38225 Merge branch 'master' of https://github.com/odin-lang/Odin 2020-04-19 21:45:14 +01:00
gingerBill 97f7a558fa #optional_ok tag for procedures 2020-04-19 21:45:04 +01:00
Mikkel Hjortshøj ab7c75860e Merge pull request #607 from ThisDrunkDane/nightly-build
Use b2 upload-file instead of b2 sync for nightly builds
2020-04-19 21:54:17 +02:00
Mikkel Hjortshoej 680d723c77 Remove push 2020-04-19 21:44:45 +02:00
Mikkel Hjortshoej 8eda24f2d1 Actually include script to delete binaries 2020-04-19 21:38:59 +02:00
Mikkel Hjortshoej 3dac1c34fa Script to delete files older than x days 2020-04-19 21:34:04 +02:00
Mikkel Hjortshoej 7fddac2c36 Fix typo in nightly.yml 2020-04-19 18:06:20 +02:00
Mikkel Hjortshoej a55975bd5a Testing 2020-04-19 18:00:54 +02:00
gingerBill 2c91c21021 Merge pull request #610 from zhibog/master
Add bool flag to AST data in the parser in the core library
2020-04-18 20:43:21 +01:00
zhibog 3a1bee19a9 Added a bool flag to the Block_Stmt struct to have information whether or not 'do' was used vs brackets in the AST 2020-04-18 21:34:14 +02:00
gingerBill 872e97dba6 Merge pull request #609 from hasenj/osx-consts
Fix darwin open flags and mode
2020-04-18 19:20:42 +01:00
Hasen Judy 705984f828 Fix darwin open flags and mode 2020-04-19 01:39:22 +09:00
gingerBill aa620e8ea1 Fix Procedure value printing in ir.cpp 2020-04-17 16:20:50 +01:00
gingerBill 1addee32b5 package container with Queue and Array 2020-04-17 15:26:50 +01:00
gingerBill 92402603b9 Change find_or_generator_context_ptr behaviours 2020-04-17 14:02:45 +01:00
gingerBill 4438b3e7af Fix LLVM API backend for procedure "constant" values 2020-04-17 13:50:28 +01:00
gingerBill 602a651613 Fix name mangling for @(private) entities 2020-04-15 21:58:16 +01:00
Mikkel Hjortshoej d0cee15317 Remove on:push in nightly.yml 2020-04-15 20:44:47 +02:00
Mikkel Hjortshoej df5626cc1f Pass the bucket to /ci/create_nightly_json.py 2020-04-15 20:13:44 +02:00
Mikkel Hjortshoej 2dcc986c4c Update /ci/build_ci.bat 2020-04-15 20:11:00 +02:00
Mikkel Hjortshoej 550df8711f Fix typo in upload-create-nightly.sh 2020-04-15 20:04:43 +02:00
gingerBill 1e321cd48c Fix reflect.capacity and reflect.index 2020-04-15 19:00:05 +01:00
Mikkel Hjortshoej 020856d91a Fix macos artifact typo 2020-04-15 19:59:00 +02:00
Mikkel Hjortshoej 1bd0e09ae1 Upload to nightly path and echo out some info 2020-04-15 19:58:11 +02:00
gingerBill dbaf8568d6 Fix reflect.length 2020-04-15 18:56:19 +01:00
Mikkel Hjortshoej 802a776330 Use the correct path during upload 2020-04-15 19:49:37 +02:00
Mikkel Hjortshoej 9170c875e1 chmod +x the script before execution 2020-04-15 19:44:26 +02:00
Mikkel Hjortshoej 5002b71670 use b2 upload-file instead of b2 sync 2020-04-15 19:38:50 +02:00
gingerBill f229084baa Basic polymorphic named procedure parameters for procedures and records 2020-04-13 15:48:56 +01:00
gingerBill f09b6a4c90 Simplify compiler's Map and create a StringMap specifically for strings 2020-04-13 13:02:30 +01:00
gingerBill 65a2125dba Add -build-mode=obj 2020-04-13 12:00:40 +01:00
gingerBill 9e698b720f Change behaviour for zero-sized value types of array-related types; Fix make behaviour to always zero memory 2020-04-12 10:41:44 +01:00
gingerBill 5157619eb7 Support endian specific float on -llvm-api; fix unary - for endian floats 2020-04-11 21:51:43 +01:00
gingerBill 90593fe6ae Endian specific floating point types (e.g. f32be) 2020-04-11 21:34:55 +01:00
Mikkel Hjortshøj 16b4178b8a Merge pull request #606 from ThisDrunkDane/nightly-build
CI for nightly builds
2020-04-11 21:52:45 +02:00
Mikkel Hjortshoej 8f2b848698 Make the json for nightly have friendly URLs 2020-04-11 21:48:44 +02:00
Mikkel Hjortshøj 9655b61c11 Setup nightly.yml to run everyday at 20:00 UTC 2020-04-11 21:47:35 +02:00
Mikkel Hjortshoej 9b9a4fcf22 Python script for creating json 2020-04-11 21:01:41 +02:00
gingerBill a736d0e83f Fix @force on non-windows platforms 2020-04-11 19:40:01 +01:00
gingerBill 7ba339e6bd Fix link_name for variables 2020-04-11 19:34:29 +01:00
gingerBill baf5b9edc3 Add runtime.bswap_* required for -llvm-api 2020-04-11 19:26:16 +01:00
Mikkel Hjortshoej a615402d7c Start on json script 2020-04-11 19:55:20 +02:00
Mikkel Hjortshøj c9bec10a8e Setup POC nightly.yml 2020-04-11 19:41:25 +02:00
Mikkel Hjortshøj df80e8752b Update nightly.yml 2020-04-11 17:36:30 +02:00
Mikkel Hjortshøj 2df0532b17 Create nightly.yml 2020-04-11 17:32:21 +02:00
gingerBill 62dc99dbef Begin to make the -llvm-api more general 2020-04-10 19:52:17 +01:00
gingerBill b925ad5927 Update README.md 2020-04-10 10:27:36 +01:00
gingerBill 090579d6b5 Update README.md 2020-04-10 10:27:15 +01:00
gingerBill 29a3cb25d3 Add extra guards for window-only performance checking 2020-04-07 11:47:28 +01:00
gingerBill 7ff690500a Fix psapi.h to be windows only 2020-04-07 11:41:55 +01:00
gingerBill d0b913dad1 Add extra internal memory analysis 2020-04-06 12:17:54 +01:00
gingerBill d659e679fd Fix defer after return for -llvm-api 2020-04-06 12:17:27 +01:00
gingerBill ae97c1111a Fix -llvm-api for typeid comparison with a Type itself 2020-04-06 11:38:53 +01:00
gingerBill f38d7b02f3 Fix phi node check with untyped types 2020-04-05 14:20:26 +01:00
gingerBill 5e706bab56 Fix typeid comparison bug in ir.cpp 2020-04-04 21:23:11 +01:00
gingerBill b362ce9a22 Fix selector expressions for map[unknown-key] expressions for -llvm-api 2020-04-04 20:56:56 +01:00
gingerBill 9961ad8e48 Merge branch 'master' of https://github.com/odin-lang/Odin 2020-04-04 19:46:00 +01:00
gingerBill b54b5aabac Fix crash on aliasing compiler-only packages (e.g. intrinsics) with _ at the global scope. 2020-04-04 19:45:54 +01:00
Mikkel Hjortshøj d214c45fe5 Merge pull request #603 from joesycalik/win32-updates
Added to core:sys win32 package
2020-04-04 15:51:34 +02:00
gingerBill 3f638f92e2 Fix -vet warning in core.odin for intrinsics not being used 2020-04-04 13:48:53 +01:00
gingerBill b0d668d254 Fix math.atan 2020-04-04 13:02:39 +01:00
gingerBill 488282409f Fix shadowing for -vet 2020-03-30 15:22:42 +01:00
gingerBill d3c2191cf7 Fix formatting 2020-03-30 12:38:09 +01:00
vassvik dd13cf637e Fix linalg.euler_angles_from_quaternion 2020-03-30 13:29:01 +02:00
gingerBill 0804be5d81 Merge branch 'master' of https://github.com/odin-lang/Odin 2020-03-30 12:21:51 +01:00
gingerBill 3c189d2cf6 Add basic support for Python-style {} printf formatting 2020-03-30 12:21:44 +01:00
Joe c83592629d Fixed duplicated WHITENESS value in BLACKNESS constant 2020-03-29 18:10:10 -04:00
Joe 2e3706e447 -Win32-
New
- Constants: WHITENESS & BLACKNESS, and WM_PAINT
- Methods: pat_blt, register_class_a, register_class_w, message_box_a, message_box_w, begin_paint, and end_paint
- Structs: Wnd_Class_A, Wnd_Class_W, Paint_Struct
Modified
- WM_INPUT : Capitalized alphabetical values for consistency with other values
2020-03-29 17:06:09 -04:00
gingerBill 1524852ffc Merge pull request #600 from kevinw/master
Add a missing space after /LIBPATH linker options.
2020-03-29 14:32:42 +01:00
Kevin Watters 957e6f7f08 Add a missing space after /LIBPATH linker options. 2020-03-28 21:05:32 -04:00
gingerBill 1b3ee7153c Fix #599 - llvm-api GEP for structs with custom alignment 2020-03-28 16:08:14 +00:00
gingerBill bda5e8cc66 Merge branch 'master' of https://github.com/odin-lang/Odin 2020-03-28 15:42:53 +00:00
gingerBill 6d6f8f8da9 LLVM API fixes: for in ^map; complex/quaternion negation 2020-03-28 15:42:46 +00:00
Mikkel Hjortshøj dca6c451da Merge pull request #598 from ThisDrunkDane/master
Switch from now removed context.stdout/stderr to os.stdout/stderr
2020-03-28 14:14:20 +01:00
Mikkel Hjortshoej a6c8dcdd21 Switch from now removed context.stdout/stderr to os.stdout/stderr 2020-03-28 14:13:47 +01:00
gingerBill b98a4c6d69 Fix #597 2020-03-27 13:33:31 +00:00
gingerBill 4be385d648 Add more helpers to package reflect 2020-03-27 13:30:22 +00:00
gingerBill 6bbecbe895 Merge pull request #595 from odin-lang/llvm-integration
LLVM C API Integration
2020-03-26 17:41:38 +00:00
gingerBill b21993a1c4 Allow ability to reference compound literals like C99 for -llvm-api 2020-03-26 17:33:54 +00:00
gingerBill dd69fcba07 Merge branch 'master' into llvm-integration 2020-03-26 15:56:55 +00:00
gingerBill 7909872877 Allow referencing a compound literal to act like C99 2020-03-26 15:56:08 +00:00
gingerBill 0a920b5439 Fix map references in selector expressions 2020-03-25 15:55:00 +00:00
gingerBill 921ee82c97 Fix range statements for enumerated arrays without an element value but with an index 2020-03-25 15:11:35 +00:00
gingerBill b7893082ce Allow map indices to be referenced &m[key] and return a valid pointer if it exists otherwise nil 2020-03-24 15:51:17 +00:00
gingerBill 6bfe9b6656 Merge branch 'master' into llvm-integration 2020-03-24 15:48:57 +00:00
gingerBill da703edbf4 Allow map indices to be referenced &m[key] and return a valid pointer if it exists otherwise nil 2020-03-24 15:48:31 +00:00
gingerBill 796331fea6 Support by-reference semantics in for value_ref, i in &some_array and for key, value_ref in &some_map 2020-03-24 15:33:34 +00:00
gingerBill 820095ddac Merge branch 'master' into llvm-integration 2020-03-24 15:29:44 +00:00
gingerBill d57fbf48f0 Support by-reference semantics in for value_ref, index in &some_array and for key, value_ref in &some_map 2020-03-24 15:28:58 +00:00
gingerBill 53c842e9ba Change to new by-reference semantics for switch v in &value 2020-03-24 14:43:28 +00:00
gingerBill 1e375ba8de Merge branch 'master' into llvm-integration 2020-03-24 14:31:09 +00:00
gingerBill 5cbb266ef5 Change behaviour of switch v in &value to make v have by-reference semantics 2020-03-24 14:29:54 +00:00
gingerBill 0730e01b24 Merge branch 'master' into llvm-integration 2020-03-22 20:57:04 +00:00
gingerBill dfc63dcb60 Fix for in for pointer to map expressions 2020-03-22 20:56:46 +00:00
gingerBill 8093062e3b Wrap all LLVM C includes 2020-03-19 15:36:13 +00:00
gingerBill 9524739dfc Revert demo.odin 2020-03-19 15:31:05 +00:00
gingerBill 054e018e23 Remove dead stuff from build.bat 2020-03-19 15:30:10 +00:00
gingerBill 3d81ad46d2 Change demo.odin to default 2020-03-19 15:29:32 +00:00
gingerBill ed4d21045b Add LLVM_BACKEND_SUPPORT macro to make the backend optional 2020-03-19 15:14:31 +00:00
gingerBill 93955a0fd8 Remove context.std* parameters; Fix unary boolean not 2020-03-19 15:03:02 +00:00
gingerBill fc0002ab67 Fix enum type info generation 2020-03-19 12:28:39 +00:00
gingerBill 04fe23a3c8 Have different categories for optimization passes 2020-03-19 10:57:14 +00:00
gingerBill 1707e004ec Merge branch 'llvm-integration' of https://github.com/odin-lang/Odin into llvm-integration 2020-03-15 14:37:46 +00:00
gingerBill 5169dc07c7 Fix lb_add_proc_attribute_at_index 2020-03-15 14:37:39 +00:00
gingerBill 18fb6a4be4 Merge branch 'master' into llvm-integration 2020-03-15 14:31:26 +00:00
gingerBill 8dba0e332c Fix #590 2020-03-15 14:29:45 +00:00
gingerBill 3951b93d0a Fix branch statements within inline for blocks (partial hack) 2020-03-15 14:27:54 +00:00
gingerBill 10bac2445b Fix ir_print for byval types 2020-03-13 16:48:10 +00:00
gingerBill 06e364b9bd Apply byval to sret for System V ABI 2020-03-13 08:52:23 +00:00
gingerBill ce90509a07 Add initial -mem2reg pass to opt 2020-03-13 00:04:03 +00:00
gingerBill a0d0e93475 Fix os.read_entire_file 2020-03-12 23:45:46 +00:00
gingerBill 2ce1f4ba9f Revert os_windows.odin behaviour 2020-03-12 23:37:24 +00:00
gingerBill a985449c31 Fix os_windows.h 2020-03-12 23:24:30 +00:00
gingerBill 6abc93ad84 Fix os.read for windows 2020-03-12 23:22:01 +00:00
gingerBill a9bc07dbff Merge pull request #586 from Tetralux/fix-reading
Fix os.read / os.read_entire_file on Windows
2020-03-12 22:35:12 +00:00
gingerBill da283d5a7f Add byval 2020-03-12 22:33:49 +00:00
Tetralux 1181d7cf90 Fix os.read / os.read_entire_file
- DWORDs are NOT i32
- os.read didn't correctly read as much as it could
2020-03-12 22:31:00 +00:00
gingerBill 2a2d3273ea Add @require for global variables 2020-03-12 14:40:13 +00:00
gingerBill 775e6caf31 Merge pull request #583 from machinamentum/llvm-integration
LLVM: speed improvement changes.
2020-03-09 08:46:27 +00:00
Joshua Huelsman 4468ddf8f8 LLVM: speed improvement changes. 2020-03-09 03:21:08 -04:00
gingerBill bf0c6f5a30 Fixes for constants and nil parameters 2020-03-08 19:38:50 +00:00
gingerBill d1e670335f Fix lb_find_or_add_entity_string_byte_slice 2020-03-08 18:50:10 +00:00
gingerBill c6c6c56ba9 Fix mem.set for LLVM C API 2020-03-08 18:44:45 +00:00
gingerBill d4e95282c2 Fix llvm.memset for both backends 2020-03-08 18:42:30 +00:00
gingerBill 5a02ebe2c8 Fix foreign import dependencies; Fix lbParamPass_Integer ABI 2020-03-08 17:57:46 +00:00
gingerBill dae817e5ab Integrate linker code with the new LLVM API backend 2020-03-08 17:44:08 +00:00
gingerBill 28502ba53b Fix context system; add more to -show-more-timings for LLVM API; Add ODIN_USE_LLVM_API global constant 2020-03-08 12:34:36 +00:00
gingerBill 8dc74a004c Fix nested type declarations name generation, to be internally consistent 2020-03-08 11:46:05 +00:00
gingerBill c584456a21 Fix logical binary expressions 2020-03-08 10:43:00 +00:00
gingerBill c74d8405ec Merge branch 'master' into llvm-integration 2020-03-08 10:13:19 +00:00
gingerBill e0a370f8f1 Remove adding to path in shell.bat 2020-03-08 10:12:56 +00:00
gingerBill 4cf70f360b Add clone for ast.Ternary_If_Expr and ast.Ternary_When_Expr 2020-03-07 21:41:27 +00:00
gingerBill a83d9f59f6 Fix typo in parser.odin 2020-03-07 21:12:52 +00:00
gingerBill 5d14189a18 Merge branch 'master' of https://github.com/odin-lang/Odin 2020-03-07 16:20:04 +00:00
gingerBill fb686bdebd Remove the need for parapoly to print an enum as a string 2020-03-07 16:19:55 +00:00
gingerBill 19b9cb7524 Merge pull request #575 from Tetralux/patch-2
Fix mem.align_backward when pointer is already aligned
2020-03-07 10:46:19 +00:00
gingerBill f92334a769 Basic functionality, except for map and correct nested typename mangling 2020-03-07 10:38:14 +00:00
gingerBill 4ee936ab8d Merge pull request #581 from terickson001/linux_stat_fix
Linux stat fix
2020-03-06 15:42:05 +00:00
gingerBill 0c21939600 Merge pull request #579 from powerc9000/patch-1
Fix issues with stat struct.
2020-03-06 15:41:54 +00:00
Tyler Erickson f6f2ab2f25 Fixed bad merge 2020-03-05 19:29:32 -08:00
Tyler Erickson 9d163fede8 Merge branch 'master' of https://github.com/odin-lang/Odin into linux_stat_fix 2020-03-05 16:52:34 -08:00
Tyler Erickson bb026c99a9 Merged with master 2020-03-05 16:49:53 -08:00
gingerBill 8d2ad0da0e Fill in more of the llvm_backend code generation 2020-03-05 22:01:07 +00:00
gingerBill db7a3ffd2a Merge branch 'master' into llvm-integration 2020-03-05 21:12:16 +00:00
gingerBill c213d72ec6 Fix #580 defer bug 2020-03-05 20:58:59 +00:00
gingerBill 01b1385672 Disable tmp_block behaviour for ir_find_or_generate_context_ptr 2020-03-05 20:36:53 +00:00
gingerBill e92fdb4a99 x if cond else y and x when cond else y expressions 2020-03-05 20:34:30 +00:00
Tyler Erickson 2817bab494 Fix os_linux stat 2020-03-05 12:13:22 -08:00
gingerBill 7d93dd6024 Move module pass to after all function passes 2020-03-05 19:00:23 +00:00
gingerBill e1da631d26 General functionality without context 2020-03-04 22:09:58 +00:00
gingerBill 6151fdb324 Merge branch 'master' into llvm-integration 2020-03-04 19:27:01 +00:00
gingerBill 2fe0eaf2ad Fix formatting 2020-03-04 13:10:39 +00:00
Clay Murray 85f2f4aa88 Fix issues with stat struct.
The stat struct was the format for the 64 bit version of stat. So we need to call stat64 to get the proper data.
Also we need to use _File_Time instead of File_Time because it is a compound value. 

These changes were tested and work on my computer, MacOS 64 bit.
2020-03-03 19:42:20 -07:00
gingerBill 3f63e12198 Add -subsystem:console and -subsystem:windows flags for windows 2020-03-02 18:54:56 +00:00
gingerBill 10cde925ca Add checks for pre-existing type declarations. 2020-03-02 18:48:52 +00:00
gingerBill 56240240f6 Range Statement support 2020-02-29 14:29:47 +00:00
gingerBill f83e1b8b0a Fix any type and casting to any; Fix switch statement 2020-02-29 12:24:52 +00:00
gingerBill a27c68f526 Type_Info initialization 2020-02-29 11:12:37 +00:00
gingerBill 8ec5987ae1 Merge branch 'master' into llvm-integration 2020-02-29 09:55:25 +00:00
gingerBill 408fa027af Merge pull request #576 from Tetralux/patch-5
Fix encoding/base64 encoding null bytes incorrectly
2020-02-29 09:53:55 +00:00
gingerBill 5e903ed2ff Merge pull request #537 from Tetralux/fix-heap-alloc
Fix heap allocator alignment on all platforms
2020-02-29 09:49:24 +00:00
gingerBill ce20604e3c Fix #578 2020-02-29 09:35:41 +00:00
Tetralux 92e1c71dd6 Fix encoding/base64 encoding null bytes incorrectly
Fixes #574.

Thanks @jroatch!
2020-02-28 14:52:16 +00:00
Tetralux 0190f90979 Fix mem.align_backward when pointer is already aligned 2020-02-28 12:22:30 +00:00
gingerBill 3d74c2f6c0 Add proc(#const x: Type) to enforce a constant parameter (but not polymorphic) to a procedure 2020-02-26 22:53:40 +00:00
gingerBill 1596bca92d Add intrinsics.cpu_relax 2020-02-26 22:29:12 +00:00
gingerBill 470508adbc Clean-up initialization code 2020-02-26 22:05:52 +00:00
gingerBill 8f42958ba3 Fix __dynamic_array_reserve 2020-02-26 12:58:22 +00:00
gingerBill 4d7270cec9 Fix __dynamic_array_reserve to allow for zero sized elements 2020-02-26 12:55:56 +00:00
gingerBill b13423d7f7 Global variable initialization support 2020-02-23 16:25:11 +00:00
gingerBill 703404a54d Merge branch 'master' into llvm-integration 2020-02-23 10:55:41 +00:00
gingerBill 15f5c85379 Fix comparison against nil for union #maybe pointers 2020-02-23 10:55:09 +00:00
gingerBill e197af766d Merge branch 'master' into llvm-integration 2020-02-23 10:39:57 +00:00
gingerBill 10fe5e97b3 Merge pull request #541 from Tetralux/getcwd
Add os.get_current_directory / os.set_current_directory
2020-02-23 10:39:21 +00:00
gingerBill 5073fcd39e Improve error message on using with procedure parameters #568 2020-02-23 10:37:27 +00:00
gingerBill a72ac6f841 Fix #572 2020-02-23 10:26:49 +00:00
gingerBill 8a67775149 Fix #571 2020-02-23 10:20:12 +00:00
gingerBill 85e331d5e2 Fix #566 2020-02-23 10:13:42 +00:00
gingerBill 81b00c7a3e Fix #563 2020-02-23 10:11:43 +00:00
gingerBill 49ecd73406 Merge pull request #562 from Tetralux/string-compare
Fix #552: Fix strings.compare for empty strings and different-length strings.
2020-02-23 10:08:50 +00:00
gingerBill 2180f4a475 Basic work on obj generation 2020-02-23 10:04:25 +00:00
Tetralux 1f0c1943da Fix #552.
- Fix comparisons involving one or more empty string.
- Fix comparisons against two strings of different lengths.
2020-02-12 11:25:12 +00:00
Mikkel Hjortshøj 0b7711684b Delete dockerimage.yml
My bad
2020-02-11 21:53:45 +01:00
Mikkel Hjortshøj 9821b2be25 Create dockerimage.yml 2020-02-11 21:52:10 +01:00
Mikkel Hjortshøj 49b42f585c Merge pull request #560 from ThisDrunkDane/master
Enhance logger interface with 'f' and not 'f' variants, also move level detection out
2020-02-10 11:55:49 +01:00
Mikkel Hjortshoej 9d5692ae68 Enhance logger interface with 'f' and not 'f' variants, also move level detection out 2020-02-10 01:26:04 +01:00
gingerBill bfda101686 Get basic IR code generation working properly 2020-02-10 00:14:43 +00:00
vassvik 6d67567453 Fix linalg.matrix_mul_vector.
Incorrect index.
2020-02-09 18:47:02 +01:00
gingerBill 35711a400c Anonymous procedure literal support 2020-02-08 12:49:38 +00:00
gingerBill 66da96284a Add defer statement for LB 2020-02-07 00:01:44 +00:00
gingerBill 7d9600b740 Ternary Expr; lbAddr extra; Phi node support 2020-02-06 23:33:41 +00:00
vassvik 0c09cb9c12 Fix math.acos and math.asin, add f64 overloads. 2020-02-06 13:35:55 +01:00
gingerBill 09e1cf0737 IfStmt 2020-02-05 23:41:10 +00:00
gingerBill 992858b687 Add ReturnStmt 2020-02-05 22:39:23 +00:00
gingerBill b555b0083a Slowly add more statements and expressions; Add header file 2020-02-05 20:18:19 +00:00
Mikkel Hjortshøj 25feb507a4 Merge pull request #556 from oskarnp/issue-555
Fix #555
2020-02-05 21:03:36 +01:00
Oskar Nordquist 0b299cb8b4 Fix https://github.com/odin-lang/Odin/issues/555 2020-02-05 20:48:18 +01:00
gingerBill fbe2366af3 Merge pull request #554 from terickson001/merge-sort-proc
Removed 'where' clause from merge_sort_proc
2020-02-04 18:46:28 +00:00
Tyler Erickson 391e2a5120 Removed 'where' clause from merge_sort_proc 2020-02-03 19:20:12 -08:00
gingerBill 0103cedad7 Port code for lb_build_call_expr 2020-02-02 23:36:15 +00:00
gingerBill d56807095a Implement constant value generation from ExactValue 2020-02-02 18:33:13 +00:00
gingerBill 5dc82c2720 Correctly generate LLVM types from Odin types. 2020-02-02 12:34:49 +00:00
gingerBill 5f1b397a05 Use lbValue to represent values everywhere 2020-02-01 23:52:22 +00:00
gingerBill 6ed6a91a64 Begin LLVM C API integration 2020-02-01 22:50:57 +00:00
gingerBill 0f399a7294 Add union #maybe 2020-02-01 11:10:28 +00:00
gingerBill 4bcb667e97 Merge branch 'master' of https://github.com/odin-lang/Odin 2020-01-31 23:34:08 +00:00
gingerBill 7e6454b2f7 Add odin [command] -help (not requiring a file to be passed) 2020-01-31 23:34:00 +00:00
gingerBill 357e72654d Merge pull request #546 from thebirk/patch-1
Update README.md to use Odin syntax highlighting instead of Go.
2020-01-31 09:46:47 +00:00
Aleksander Birkeland e9f3ebba13 Update README.md to use Odin syntax highlighting instead of Go. 2020-01-30 01:01:01 +01:00
gingerBill 3a30f9fd71 Create .gitattributes 2020-01-29 12:04:54 +00:00
gingerBill 7a4ec48389 Fix missing allocator 2020-01-26 21:10:56 +00:00
gingerBill a101e0d7ba Add utf8.string_to_runes utf8.runes_to_string 2020-01-26 20:55:46 +00:00
gingerBill 64f5c9ab58 Merge branch 'master' of https://github.com/odin-lang/Odin 2020-01-26 20:44:32 +00:00
gingerBill 0ee5a07d01 Add package unicode letter.odin 2020-01-26 20:44:27 +00:00
gingerBill d658a8fca5 Merge pull request #545 from Tetralux/patch-2
Fix `make(map[K]V, 0)` by ensuring `reserve` always sets an allocator
2020-01-26 16:19:50 +00:00
Tetralux abe8789890 Fix make(map[K]V, 0) by ensuring reserve always sets an allocator
Currently, `make(map[K]V, 0)` asserts, because trying `reserve` zero items does not set the allocator; it early-outs.

`__dynamic_map_reserve` assumed that `__dynamic_array_reserve` would always set the allocator - even if given a desired capacity of `0`.

Rather than making `__slice_resize` just _also_ set the default allocator if there isn't one, this makes `__dynamic_array_reserve` always set the allocator, even if it is about to early out.
This is because users are lead to understand that `append` will set the allocator if one is not already set - `reserve` should work the same way.
2020-01-26 01:03:14 +00:00
Tetralux a4b60b78c8 Fix heap allocator alignment on all platforms 2020-01-22 12:03:16 +00:00
Tetralux 66d1656367 Add os.get_current_directory / os.set_current_directory 2020-01-20 14:28:31 +00:00
gingerBill 14c4fed94c v0.12.0 2020-01-18 15:32:15 +00:00
gingerBill c3205316ed Remove debug printing 2020-01-18 14:53:53 +00:00
gingerBill b542ef273d Begin work on -target:windows_386 2020-01-18 14:44:53 +00:00
gingerBill 404132de17 Fix microsoft_craziness.h to work correctly 2020-01-18 12:36:18 +00:00
gingerBill cd43f4c94c Add suggestions for indexing constant values with a variable index 2020-01-18 12:09:26 +00:00
gingerBill 23ff98dea0 Fix microsoft_craziness.h 2020-01-18 12:08:45 +00:00
gingerBill c3a8e232a5 Add new intrinsics for polymorphic records:
type_is_specialized_polymorphic_record, type_is_unspecialized_polymorphic_record, type_polymorphic_record_parameter_count, type_polymorphic_record_parameter_value
2020-01-18 11:27:41 +00:00
gingerBill 7f89f6b582 Add intrinsics.type_is_specialization_of 2020-01-17 23:30:38 +00:00
gingerBill 159150c6d9 Allow not_in as keyword over notin, but still allow notin to work 2020-01-16 10:00:14 +00:00
gingerBill 527b39ce2b Merge remote-tracking branch 'origin/master' 2020-01-16 09:07:52 +00:00
gingerBill 5af3c7b0e8 Fix constant slice checking, again 2020-01-16 09:05:17 +00:00
gingerBill 5db4bd9944 Fix #536 2020-01-15 12:01:29 +00:00
gingerBill 20b410f149 Fix #540 2020-01-15 11:56:42 +00:00
gingerBill ae7cbd5171 Add debug info for enumerated arrays 2020-01-14 17:37:45 +00:00
gingerBill 04f7225ea5 Exact value zero value for T{} of basic types 2020-01-14 17:36:37 +00:00
gingerBill f0c6f29f82 Merge branch 'master' of https://github.com/odin-lang/Odin 2020-01-12 13:53:57 +00:00
gingerBill 7d9a9a2283 Add extra check for opaque types 2020-01-12 13:53:51 +00:00
gingerBill ba85e432e7 Fix Proc Type ABI printing on System V 2020-01-12 13:43:45 +00:00
gingerBill cfba29002a Add extra set_procedure_abi_types sanity checks in IR 2020-01-11 20:29:46 +00:00
gingerBill 11c7b6a2e4 Fix len of type bug 2020-01-11 20:26:36 +00:00
gingerBill 47f9876b36 Merge branch 'master' of https://github.com/odin-lang/Odin 2020-01-11 20:20:20 +00:00
gingerBill ff31f9a900 Fix @thread_local IR printing 2020-01-11 20:19:52 +00:00
gingerBill ebc4867514 Fix #521 Explicit union tag values 2020-01-11 20:16:42 +00:00
gingerBill e1ccba3de5 Improve runtime/default_allocators.odin 2020-01-11 20:12:50 +00:00
gingerBill 28570f8fa4 Merge branch 'master' of https://github.com/odin-lang/Odin 2020-01-11 20:11:47 +00:00
gingerBill 24bd370e1b Fix Panic with runtime.type_info_base #532 2020-01-11 20:11:39 +00:00
Mikkel Hjortshøj 3e67ae7339 Merge pull request #534 from ThisDrunkDane/fix-log-mistake
Fix mistake in .Short_File_Path option in file_console_logger.odin
2020-01-09 19:19:23 +01:00
Mikkel Hjortshoej 0e52c37865 Don't change delimiter as location has changed to be unified no matter the platform 2020-01-08 21:29:46 +01:00
gingerBill d520b9a1ba Fix typo 2020-01-05 12:49:32 +00:00
gingerBill 5c7d6fcfd0 Improve minimum dependency for complex numbers and quaternion numbers. 2020-01-04 18:04:12 +00:00
gingerBill 5ae924f988 Make "none" calling convention ignore return_by_pointer flag 2020-01-04 12:42:16 +00:00
gingerBill cae1e02593 Add extra in set_procedure_abi_types ir_print.cpp 2020-01-04 12:10:28 +00:00
gingerBill b09297da81 Remove -Wno-writable-strings 2020-01-04 10:59:12 +00:00
gingerBill 9abdfaaf6c Merge pull request #531 from Tetralux/fix-make-and-reserve
Fix make and reserve
2020-01-03 10:51:42 +00:00
Tetralux b32ef9e47b Fix make and reserve
- Set the allocator, even if memory allocation fails.
  Right now it doesn't, which means that if allocation fails, it'll use
  the context allocator instead. This memory will be leaked if the user
  doesn't understand that this happened.

- Only set len and cap of the array returned from make iif the memory allocation
  succeeded.
  This means that reserve will return false if you do this:
  ```
  a := make([dynamic]int, failing_allocator);
  if !reserve(&a, 5) do return; // or whatever indicates failure
  ```
2020-01-03 10:40:45 +00:00
gingerBill b8324b0776 Fix behaviour for make to return nil when alloc returns nil 2020-01-03 10:17:30 +00:00
gingerBill d0ca045586 Merge pull request #530 from KTRosenberg/unix_yield_sem_fix
Fixes for yielding and semaphore posting on unix
2020-01-03 09:50:12 +00:00
KTRosenberg 673879d1d2 added note about pthread_yield 2020-01-02 16:44:30 -05:00
KTRosenberg 5d1c9583cb added the demo to the gitignore 2020-01-02 16:42:34 -05:00
KTRosenberg d017b5de9d replaced pthread_yield with ssched_yield, fixed semaphore post:q 2020-01-02 16:25:48 -05:00
gingerBill 93ead4bcb3 Fix typo 2020-01-02 15:41:32 +00:00
gingerBill bbe9b4dee0 Merge branch 'master' of https://github.com/odin-lang/Odin 2020-01-02 15:07:58 +00:00
gingerBill 3bd00fd6b7 Add thread.Pool with example in demo.odin; Update linalg to support handness changes for projection matrices 2020-01-02 15:07:12 +00:00
gingerBill 83fec387d4 Merge pull request #529 from Tetralux/patch-1
Fix `append_string`
2020-01-02 11:39:20 +00:00
Tetralux f6f10d10e8 Fix append_string 2020-01-02 11:38:25 +00:00
gingerBill 16a7c55334 Add x y z w fields to quaternion types; Improve linalg quaternion mathematics 2020-01-01 16:14:00 +00:00
gingerBill e9e2ab240d Merge pull request #528 from oskarnp/foreign-dylib-fix
Fix dylib foreign import
2020-01-01 10:42:09 +00:00
oskarn 842281ddd3 Fix dylib foreign import 2020-01-01 11:36:42 +01:00
gingerBill 978d7fcb99 Fix typeid information for enumerated arrays 2019-12-31 16:54:50 +00:00
gingerBill b267a5964d Fix memset for unix 2019-12-31 14:28:01 +00:00
gingerBill b288613307 Add extra check for ZeroInit instruction 2019-12-31 14:21:16 +00:00
gingerBill 4591353724 Use naive definition of memset for !windows 2019-12-31 14:17:21 +00:00
gingerBill 13107628f8 Make mem.set use llvm.memset.p0i8.iXX 2019-12-31 14:09:51 +00:00
gingerBill c407687a4c Fix new changes to runtime for unix 2019-12-31 14:04:19 +00:00
gingerBill 5a50ab7a99 Add new runtime files. 2019-12-31 13:54:42 +00:00
gingerBill 4578544007 Merge pull request #526 from sci4me/unix-dynlib
Implement dynlib core library for unix/darwin
2019-12-31 13:22:48 +00:00
gingerBill bdfef08214 Fix typos in demo.odin 2019-12-31 12:54:19 +00:00
gingerBill 42678848b2 Rename math/bits package name to math_bits 2019-12-31 12:27:31 +00:00
gingerBill ab52f8d795 Move definition of mem.Allocator and log.Logger to package runtime, to reduce import cycle magic 2019-12-31 12:15:19 +00:00
Scitoshi Nakayobro d79ee7d530 Implement dynlib core library for unix/darwin; not 100% about the build tags 2019-12-30 19:09:59 -05:00
gingerBill 7e271310ff Fix constant out of bounds bug 2019-12-29 22:53:37 +00:00
gingerBill f24de51c65 Add _tls_index and _fltused for windows -no-crt 2019-12-29 21:28:50 +00:00
gingerBill 2252d992d7 Add -disable-assert to disable the code generation of the built-in run-time 'assert' procedure 2019-12-29 21:10:27 +00:00
gingerBill 2d70a784d1 Add quaternion_look_at orientation procedure to package math/linalg 2019-12-29 20:35:27 +00:00
gingerBill a8a4dc1eb1 Make default context.temp_allocator thread safe when using package thread 2019-12-29 18:08:48 +00:00
gingerBill 9e9e905431 Add @(private="file") and @(private="package") 2019-12-29 15:39:20 +00:00
gingerBill 8ee41c20af Add more to package math 2019-12-28 23:48:15 +00:00
gingerBill 11c705508d Split linalg into general and specific parts 2019-12-28 23:09:43 +00:00
gingerBill 267ae0b4a2 Disallow enumerated array literals without field = value 2019-12-28 23:07:54 +00:00
gingerBill 1bc6e6a7cc Add linalg.vector_lerp, linalg.vector_unlerp 2019-12-28 23:07:31 +00:00
gingerBill 33a458c520 Update package math/linalg 2019-12-28 23:00:13 +00:00
gingerBill 6a7ccd8c0a Add new procedures for package math: atan2, asin, acos, atan, sin_bit, ldexp 2019-12-28 18:12:27 +00:00
gingerBill 9ba2926e7e Fix enumerated array contiguous error 2019-12-28 16:31:15 +00:00
gingerBill a50b2d5d04 Fix enumerated array literal check 2019-12-28 14:05:55 +00:00
gingerBill 7f9626e5c7 Improve 'cannot slice' error message 2019-12-27 17:53:05 +00:00
gingerBill 7140c95c55 Fix slicing of pointer to array 2019-12-27 17:47:55 +00:00
gingerBill ceef5db547 Support for and inline for for enumerated arrays 2019-12-27 17:16:43 +00:00
gingerBill 5ec8dd166a Add #partial tag for enumerated arrays to prevent common errors using non-contiguous enumerations 2019-12-27 16:55:32 +00:00
gingerBill 80a32a8182 Fix missing case 2019-12-27 16:01:58 +00:00
gingerBill c2b3056094 Fix enumerated array compound literals IR 2019-12-27 15:53:35 +00:00
gingerBill f99f351e01 Add constant literal expressions 2019-12-27 15:49:52 +00:00
gingerBill 880c7f01a8 Fix array lengths with enum value counts. 2019-12-27 13:55:18 +00:00
gingerBill 10f0961184 Enumerated arrays [Enum_Type]Elem_Type 2019-12-27 12:51:02 +00:00
gingerBill eea403d0ab Fix #514 2019-12-27 10:18:32 +00:00
gingerBill 2cc5c4eed3 Fix https://github.com/odin-lang/Odin/issues/522 2019-12-27 10:11:13 +00:00
gingerBill f308d8d73e Merge pull request #520 from SrMordred/memcpy
minor details ;)
2019-12-26 12:09:44 +00:00
Patric Dexheimer ff0bc3ccad minor details ;) 2019-12-24 11:50:26 -03:00
gingerBill 072979c6d2 Merge pull request #519 from Tetralux/remove-prints
remove errorneous prints
2019-12-24 12:54:00 +00:00
Tetralux a3d2c40da0 whoops 2019-12-24 12:51:27 +00:00
gingerBill 5b1312342e Fix runtime.mem_copy_non_overlapping to be like C's memcpy 2019-12-24 08:07:43 +00:00
gingerBill 85e31e1b69 Fix os.open 2019-12-23 18:10:09 +00:00
gingerBill fb0fb4767b Merge pull request #517 from SSStormy/fix-os-linux-fs-stuffs
Unix: Fix improper _unix_open binding; make write_entire_file set sane file permissions.
2019-12-23 18:07:59 +00:00
Justas Dabrila 38a9a2b7fc Linux: write_entire_file sets 644 permissions on open. 2019-12-23 16:35:10 +02:00
Justas Dabrila 005c6af302 Fix improper _unix_open binding that was ignoring the mode arg 2019-12-23 16:34:20 +02:00
gingerBill 1d14b3059e Fix Internal Compiler Error: Type_Info for 'XXX' could not be found #507 2019-12-22 14:16:56 +00:00
gingerBill cc2fa8f756 Fix thread/thread_unix.odin to use the new switch conventions 2019-12-22 12:11:54 +00:00
gingerBill d1c9fd4e01 Implement #complete switch by default, replace with #partial switch #511 2019-12-22 12:03:48 +00:00
gingerBill 4593730632 Fix Trying to get a pointer to a struct field that does not have a size generates an LLVM error #509 2019-12-22 11:40:30 +00:00
gingerBill f62a0891bd Fix Crash when compiling for loop with parens around array expression #506 2019-12-22 11:33:33 +00:00
gingerBill 4f2d4716ad Fix Internal error when accessing polymorphic struct parameters (also provide suggestions?) #513 2019-12-22 10:40:34 +00:00
gingerBill 022b793a7d Merge branch 'master' of https://github.com/odin-lang/Odin 2019-12-22 10:28:55 +00:00
gingerBill 7267004a55 Remove import "core:runtime" in integers.odin to make -vet happy 2019-12-22 10:28:48 +00:00
vassvik 786c9dfe07 Add the ability to toggle release mode externally when calling build.bat
The following cases builds Odin with optimizations:

    build.bat 1
    build.bat release

Any other options, or the lack thereof, will build without optimizations.
2019-12-22 11:19:42 +01:00
gingerBill 81b24594ce Add udivmod128.odin 2019-12-21 19:49:09 +00:00
gingerBill 995ba0df9a Fix using on array in struct 2019-12-21 14:42:08 +00:00
gingerBill 08392d885e Add strconv/integers.odin 2019-12-21 14:01:29 +00:00
gingerBill d462dbb5be Deprecate using import 2019-12-21 12:11:16 +00:00
gingerBill 19c32ecb81 Add extra to -help output 2019-12-21 11:27:55 +00:00
gingerBill 494b1e7eaa Add -help which prints information about the compiler flags 2019-12-21 11:22:46 +00:00
gingerBill c43d17bfec Merge pull request #505 from Tetralux/patch-2
Fix mem.Arena
2019-12-16 08:05:39 +00:00
Tetralux c9723e2dc0 Fix mem.Arena 2019-12-15 21:36:40 +00:00
gingerBill 4ba579bc25 Also allow #no_bounds_check on an expression #499 2019-12-15 11:41:21 +00:00
gingerBill 58d4d424c6 Replace #vector[N]T with #simd[N]T to reduce confusion #498 2019-12-15 11:30:09 +00:00
gingerBill 89ccb5b99f Add assert into scratch_allocator_proc to prevent initialization cycles #504 2019-12-15 11:20:06 +00:00
gingerBill 7f5021c8e9 Disallow procedure calls with an associated deferred procedure to be used in logical binary expressions (short-circuiting) 2019-12-15 11:10:50 +00:00
gingerBill 8bec324779 Fix Duplicate integer switch case values incorrectly consider its absolute value #502
(Hashing proc was wrong for big ints)
2019-12-15 09:56:11 +00:00
gingerBill e6f26b9931 Fix Unable to initialize a typeid field in a struct literal #501 2019-12-15 09:48:05 +00:00
gingerBill b8c534eba9 Merge pull request #500 from SSStormy/fix-string_to_enum_value
Fix 'fmt.string_to_enum_value' not compiling
2019-12-15 09:38:37 +00:00
Justas Dabrila 95d3f43e15 Fix 'string_to_enum_value' not compiling 2019-12-14 01:08:47 +02:00
vassvik 2d97e1dee3 Fix NaN checks in core:math.classify
Currently the classify procedures checks for NaNs using the check `x != x`, which is always false for NaNs and therefore that case is never entered. Using `!(x == x)` will work on the other hand.
2019-12-12 19:12:12 +01:00
gingerBill be2dfd42fd Merge pull request #493 from ThisDrunkDane/master
Fix #399 by removing unused parameter
2019-12-08 14:35:18 +00:00
Mikkel Hjortshoej 851118faf4 Fix #399 by removing unused parameter 2019-12-08 02:09:03 +01:00
gingerBill 53cd7a3d0c Fix transmute from uintptr to/from proc 2019-12-07 15:44:28 +00:00
gingerBill f170648629 Fix issue with -thread-count flag with <= 0 count 2019-12-03 18:23:14 +00:00
gingerBill 42def957d5 Fix append_elem_string, again 2019-12-03 09:35:24 +00:00
gingerBill 6433a0d31e Fix append_elem_string 2019-12-03 09:16:11 +00:00
gingerBill 359e5d9e15 Fix append_elem_string 2019-12-03 09:07:15 +00:00
gingerBill e229885b2b Remove addressing mode Addressing_Immutable 2019-12-01 19:11:00 +00:00
gingerBill ee78374281 Fix typo 2019-12-01 18:57:43 +00:00
gingerBill ebe152a155 Disable aligned heap allocations hack in os.heap_allocator_proc 2019-12-01 18:53:27 +00:00
gingerBill 46582a45bd Fix IR string interning type 2019-12-01 18:18:03 +00:00
gingerBill 6b5ea011e7 Add strings.ptr_from_string 2019-12-01 18:06:49 +00:00
gingerBill 9503440eb0 Add strings.unsafe_string_to_cstring 2019-12-01 17:45:07 +00:00
gingerBill 3fa4c5043a Fix crash caused by not checking for correct SOA kind on polymorphic parameters 2019-12-01 16:05:48 +00:00
gingerBill 9db81498d8 Make the string type elements "immutable", akin to char const * in C
Allows for extra security and optimization benefits
2019-12-01 14:10:59 +00:00
gingerBill 7fbe0a6f23 Fix nil comparisons for soa slices and dynamic arrays 2019-12-01 11:56:08 +00:00
gingerBill 3fd5c3cd85 Merge pull request #458 from Tetralux/linux-threads
Implement core:thread and core:sync on Unix using pthreads
2019-12-01 11:33:23 +00:00
Tetralux 99121d6ff2 Implement core:thread and core:sync on Unix using pthreads
Also do some cleanup and refactoring of the thread, sync and time APIs.

- remove 'semaphore_release' because 'post' and 'wait' is easier to understand

- change 'semaphore_wait' to '*_wait_for' to match Condition

- pthreads can be given a stack, but doing so requires the user to set up the guard
  pages manually. BE WARNED. The alignment requirements of the stack are also
  platform-dependant; it may need to be page size aligned on some systems.
  Unclear which systems, however. See 'os.get_page_size', and 'mem.make_aligned'.
  HOWEVER: I was unable to get custom stacks with guard pages working reliably,
  so while you can do it, the API does not support it.

- add 'os.get_page_size', 'mem.make_aligned', and 'mem.new_aligned'.

- removed thread return values because windows and linux are not consistent; windows returns 'i32'
  and pthreads return 'void*'; besides which, if you really wanted to communicate how the
  thread exited, you probably wouldn't do it with the thread's exit code.

- fixed 'thread.is_done' on Windows; it didn't report true immediately after calling 'thread.join'.

- moved time related stuff out of 'core:os' to 'core:time'.

- add 'mem.align_backward'

- fixed default allocator alignment
  The heap on Windows, and calloc on Linux, both have no facility to request alignment.
  It's a bit of hack, but the heap_allocator now overallocates; `size + alignment` bytes,
  and aligns things to at least 2.
  It does both of these things to ensure that there is at least two bytes before the payload,
  which it uses to store how much padding it needed to insert in order to fulfil the alignment
  requested.

- make conditions more sane by matching the Windows behaviour.
  The fact that they were signalled now lingers until a thread tries to wait,
  causing them to just pass by uninterrupted, without sleeping or locking the
  underlying mutex, as it would otherwise need to do.
  This means that a thread no longer has to be waiting in order to be signalled, which
  avoids timing bugs that causes deadlocks that are hard to debug and fix.
  See the comment on the `sync.Condition.flag` field.

- add thread priority: `thread.create(worker_proc, .High)`
2019-12-01 00:46:23 +00:00
gingerBill 0c0c83ee29 Disable find_visual_studio_and_windows_sdk_utf8 temporarily 2019-11-28 21:07:06 +00:00
gingerBill b75d59d6e0 Make sort.merge_sort in place; Add sort.heap_sort 2019-11-27 16:06:07 +00:00
gingerBill 71c8a3456e Update package odin/parser for #soa and #vector 2019-11-27 15:23:54 +00:00
gingerBill 37e3e081c6 Update microsoft_craziness.h to work correctly with the rest of the codebase (and not use WIN32_LEAN_AND_MEAN) 2019-11-27 15:18:32 +00:00
gingerBill 5ea9fc3fb0 Merge pull request #478 from castano/auto-search-sdk
Allow running Odin compiler without using visual studio command prompt or setting up environgment variables.
2019-11-26 22:29:08 +00:00
Mikkel Hjortshøj 53f65224f6 Merge pull request #459 from zhibog/master
Base32 added for core:encoding
2019-11-26 19:45:52 +01:00
gingerBill 902d313c6a Fix issue with os.write on *nix with writing nothing 2019-11-24 10:08:08 +00:00
gingerBill 45d844f9d2 Disable #soa compound literals 2019-11-21 20:05:45 +00:00
gingerBill 9b58781122 #soa[dynamic]Type (Experimental) 2019-11-21 19:36:07 +00:00
gingerBill b74f8f2047 Fix SOA entity usage error on -vet 2019-11-21 18:21:27 +00:00
gingerBill 88c90cf99a Update demo.odin 2019-11-21 14:41:33 +00:00
gingerBill 321dcc60e3 Update fmt.odin 2019-11-21 14:41:12 +00:00
gingerBill 400f12f31f Update demo.odin 2019-11-21 14:23:59 +00:00
gingerBill 2c5a84bb78 #soa[]Type (Experimental) 2019-11-21 00:07:21 +00:00
gingerBill e01d8a04a9 Fix String causes a crash when used in a polymorphic type #483 2019-11-20 22:07:12 +00:00
gingerBill 69afa33fa5 Fix Implicit Selector Expressions do not work at the global/package scope #484 2019-11-20 21:56:37 +00:00
gingerBill 44e0e96612 Prepare SOA Struct code for slices and dynamic arrays *to be implemented* 2019-11-19 23:54:36 +00:00
gingerBill 0839dccfdc Fix Compiler panic with SIMD Vector debug information #481 2019-11-19 23:24:49 +00:00
zhibog 2484f4d04b Removed CSV stuff. 2019-11-17 20:09:00 +01:00
gingerBill d22e5b697d Add new #soa and #vector syntax 2019-11-17 10:30:37 -08:00
gingerBill 301ee664e9 Add Handmade Seattle 2019 Demos 2019-11-16 06:59:48 -08:00
gingerBill 9b4d4a2c61 Minor fix to os.write on darwin 2019-11-16 06:59:14 -08:00
gingerBill d9647174a3 Merge pull request #479 from ThisDrunkDane/master
Fix CI badge on README.md
2019-11-14 22:57:08 +00:00
gingerBill 4d29b64196 Merge pull request #475 from hasenj/reverse
fix string reversal
2019-11-14 22:52:01 +00:00
gingerBill 8be1b2e1b1 Merge pull request #476 from castano/symlink-fix
Add support for running odin through a symlink.
2019-11-14 22:50:17 +00:00
Mikkel Hjortshoej b85258a9fc Add event query param to CI badge 2019-11-14 14:47:01 -08:00
gingerBill 07897ed78e Fix System V bitcast/transmute bug 2019-11-14 14:45:23 -08:00
Mikkel Hjortshoej 8115386217 Add branch query to CI badge 2019-11-14 14:39:11 -08:00
castano f8dd4816ff Integrate microsoft_craziness better. 2019-11-14 09:30:05 -08:00
castano 928a445a14 Fix definition. GB_SYSTEM_WINDOWS is not defined yet. Ideally microsoft_crazines.h should be included after common, but conflicts with defer macro. 2019-11-14 09:29:59 -08:00
castano 42cd78497a Use Jon's single file lib to find the latest compiler and SDK paths instead of relying on environment variables.
This allows you to run the odin compiler without having to use the visual studio command prompt or setting up environment variables. It would be nice to not rely on the automatic search exclusively, but allow specifying the desired compiler or SDK version.

This change introduces various library dependencies in order to interact with COM objects. Not sure if there's a way around that.
2019-11-14 09:29:45 -08:00
castano 813f5d211f Fix linux build. 2019-11-14 09:22:37 -08:00
castano 71d129a709 Add support for running odin through a symlink. Use realpath when obtaining root dir. 2019-11-14 00:50:26 -08:00
Hasen Judy c35762528c fix string reversal 2019-11-13 23:36:52 +09:00
zhibog 694ee02247 Missed one 2019-11-09 18:06:33 +01:00
zhibog 0451c88ab6 Fixed indenting 2019-11-09 18:04:30 +01:00
zhibog 803f6a6651 Added procs to read and write just the data, without any file loading / writing 2019-11-08 22:17:24 +01:00
zhibog 672cfd51c3 Added names to return values 2019-11-08 20:21:18 +01:00
zhibog 80cdf8b6a8 Should be row_count obviously 2019-11-08 20:16:56 +01:00
zhibog dc2d5239c5 Removed comments regarding RFC test vectors 2019-11-08 20:06:58 +01:00
zhibog 4b718aae75 Added an implementation for reading and writing csv files 2019-11-01 22:35:46 +01:00
zhibog 20db0e7f09 Added Base32 + official test vectors from the RFC 2019-11-01 22:35:09 +01:00
zhibog 614ea5c168 Added official test vectors from the RFC 2019-11-01 22:34:19 +01:00
Brendan Punsky e3d1d1d85c Merge branch 'master' into master 2019-03-18 17:22:57 -04:00
Brendan Punsky b6ea7b7418 Fix temp allocation on linux 2019-03-18 17:19:21 -04:00
Brendan Punsky 7426f3b092 Fix null termination detection, win32 namespacing 2019-03-18 17:11:17 -04:00
Brendan Punsky 299c299dff Add linux support 2019-03-18 17:07:36 -04:00
Brendan Punsky e398c074db Fix typo 2019-03-13 18:37:01 -04:00
Brendan Punsky eadb66c9ef Merge branch 'master' into master 2019-03-13 16:45:46 -04:00
Brendan Punsky 9d7e1c17cc Update kernel32.odin
Add Win32 path functions
2019-03-13 16:44:11 -04:00
Brendan Punsky 775b544326 Update path_windows.odin
Updated `long`, `short`, `full`, `current` to be cleaner, use `win32` for platform procs, and `strings.trim_null` to clean resulting strings
2019-03-13 16:40:26 -04:00
Brendan Punsky da26e14959 Update path.odin
Fix allocator usage for `rel_current` and `rel_between`
2019-03-13 16:38:02 -04:00
Brendan Punsky 222e5c8ae9 Delete path_linux.odin
Delete useless path_linux.odin stub
2019-02-14 20:25:13 -05:00
Brendan Punsky 772dc47f55 Oops, I forgot to stage core/strings/strings.odin 2019-02-12 17:30:46 -05:00
Brendan Punsky 0777351482 Added path lib "core:path", as well as single- and multiple-splitset string split proc variants to "core:string" 2019-02-12 17:27:54 -05:00
694 changed files with 179921 additions and 39779 deletions
+1
View File
@@ -0,0 +1 @@
*.odin linguist-language=Odin
+1 -1
View File
@@ -12,7 +12,7 @@ assignees: ''
Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.
* Operating System:
* Odin version/Commit:
* Please paste `odin version` output:
## Expected Behavior
@@ -7,6 +7,8 @@ assignees: ''
---
# PLEASE POST THIS IN THE DISCUSSION TAB UNDER "PROPOSALS" OR "IDEAS/REQUESTS"
**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
+43 -32
View File
@@ -2,56 +2,67 @@ name: CI
on: [push, pull_request]
jobs:
build_unix:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macOS-latest]
build_linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: (macOS) Download LLVM and setup PATH
if: startsWith(matrix.os, 'macOS')
run: |
brew install llvm
echo ::add-path::/usr/local/opt/llvm/bin
echo ::set-env name=CPATH::`xcrun --show-sdk-path`/usr/include
- name: (Linux) Download LLVM
if: startsWith(matrix.os, 'ubuntu')
run: |
sudo apt-get install llvm
- name: Download LLVM
run: sudo apt-get install llvm-11 clang-11 llvm
- name: build odin
run: make release
- name: Odin run
run: ./odin run examples/demo/demo.odin
- name: Odin version
run: ./odin version
timeout-minutes: 1
- name: Odin check
run: ./odin check examples/demo/demo.odin -vet
timeout-minutes: 10
- name: Odin run
run: ./odin run examples/demo/demo.odin
timeout-minutes: 10
build_macOS:
runs-on: macos-latest
steps:
- uses: actions/checkout@v1
- name: Download LLVM and setup PATH
run: |
brew install llvm@11
echo "/usr/local/opt/llvm@11/bin" >> $GITHUB_PATH
TMP_PATH=$(xcrun --show-sdk-path)/user/include
echo "CPATH=$TMP_PATH" >> $GITHUB_ENV
- name: build odin
run: make release
- name: Odin version
run: ./odin version
timeout-minutes: 1
- name: Odin check
run: ./odin check examples/demo/demo.odin -vet
timeout-minutes: 10
- name: Odin run
run: ./odin run examples/demo/demo.odin
timeout-minutes: 10
build_windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v1
- name: Install cURL
run: choco install curl
- name: Download and unpack LLVM bins
shell: cmd
run: |
cd bin
curl -sL https://github.com/odin-lang/Odin/releases/download/llvm-windows/llvm-binaries.zip --output llvm-binaries.zip
7z x llvm-binaries.zip > nul
- name: build Odin
shell: cmd
run: |
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars64.bat
./build_ci.bat
- name: Odin run
shell: cmd
run: |
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars64.bat
odin run examples/demo/demo.odin
./build.bat 1
- name: Odin version
run: ./odin version
timeout-minutes: 1
- name: Odin check
shell: cmd
run: |
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars64.bat
odin check examples/demo/demo.odin -vet
timeout-minutes: 10
- name: Odin run
shell: cmd
run: |
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars64.bat
odin run examples/demo/demo.odin
timeout-minutes: 10
+142
View File
@@ -0,0 +1,142 @@
name: Nightly
on:
workflow_dispatch:
schedule:
- cron: 0 20 * * *
jobs:
build_windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v1
- name: build Odin
shell: cmd
run: |
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars64.bat
./build.bat 1 1
- name: Odin run
shell: cmd
run: |
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars64.bat
odin run examples/demo/demo.odin
- name: Copy artifacts
run: |
rm bin/llvm/windows/LLVM-C.lib
mkdir dist
cp odin.exe dist
cp LLVM-C.dll dist
cp -r shared dist
cp -r core dist
cp -r vendor dist
cp -r bin dist
cp -r examples dist
- name: Upload artifact
uses: actions/upload-artifact@v1
with:
name: windows_artifacts
path: dist
build_ubuntu:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: (Linux) Download LLVM
run: sudo apt-get install llvm-11 clang-11 llvm
- name: build odin
run: make nightly
- name: Odin run
run: ./odin run examples/demo/demo.odin
- name: Copy artifacts
run: |
mkdir dist
cp odin dist
cp -r shared dist
cp -r core dist
cp -r vendor dist
cp -r examples dist
- name: Upload artifact
uses: actions/upload-artifact@v1
with:
name: ubuntu_artifacts
path: dist
build_macos:
runs-on: macOS-latest
steps:
- uses: actions/checkout@v1
- name: Download LLVM and setup PATH
run: |
brew install llvm@11
echo "/usr/local/opt/llvm@11/bin" >> $GITHUB_PATH
TMP_PATH=$(xcrun --show-sdk-path)/user/include
echo "CPATH=$TMP_PATH" >> $GITHUB_ENV
- name: build odin
run: make nightly
- name: Odin run
run: ./odin run examples/demo/demo.odin
- name: Copy artifacts
run: |
mkdir dist
cp odin dist
cp -r shared dist
cp -r core dist
cp -r vendor dist
cp -r examples dist
- name: Upload artifact
uses: actions/upload-artifact@v1
with:
name: macos_artifacts
path: dist
upload_b2:
runs-on: [ubuntu-latest]
needs: [build_windows, build_macos, build_ubuntu]
steps:
- uses: actions/checkout@v1
- uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install B2 CLI
shell: bash
run: |
python -m pip install --upgrade pip
pip install --upgrade b2
- name: Display Python version
run: python -c "import sys; print(sys.version)"
- name: Download Windows artifacts
uses: actions/download-artifact@v1
with:
name: windows_artifacts
- name: Download Ubuntu artifacts
uses: actions/download-artifact@v1
with:
name: ubuntu_artifacts
- name: Download macOS artifacts
uses: actions/download-artifact@v1
with:
name: macos_artifacts
- name: Create archives and upload
shell: bash
env:
APPID: ${{ secrets.B2_APPID }}
APPKEY: ${{ secrets.B2_APPKEY }}
BUCKET: ${{ secrets.B2_BUCKET }}
DAYS_TO_KEEP: ${{ secrets.B2_DAYS_TO_KEEP }}
run: |
b2 authorize-account "$APPID" "$APPKEY"
chmod +x ./ci/upload_create_nightly.sh
./ci/upload_create_nightly.sh "$BUCKET" windows-amd64 windows_artifacts/
./ci/upload_create_nightly.sh "$BUCKET" ubuntu-amd64 ubuntu_artifacts/
./ci/upload_create_nightly.sh "$BUCKET" macos-amd64 macos_artifacts/
python3 ci/delete_old_binaries.py "$BUCKET" "$DAYS_TO_KEEP"
python3 ci/create_nightly_json.py "$BUCKET" > nightly.json
b2 upload-file "$BUCKET" nightly.json nightly.json
b2 clear-account
+5
View File
@@ -21,8 +21,11 @@ bld/
![Cc]ore/[Ll]og/
# Visual Studio 2015 cache/options directory
.vs/
# Visual Studio Code options directory
.vscode/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
demo
# MSTest test Results
[Tt]est[Rr]esult*/
@@ -271,3 +274,5 @@ shared/
* .ll
*.bc
*.ll
*.sublime-workspace
+10 -6
View File
@@ -1,14 +1,18 @@
Copyright (c) 2016-2017 Ginger Bill. All rights reserved.
Copyright (c) 2016-2021 Ginger Bill. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
BIN
View File
Binary file not shown.
+35 -6
View File
@@ -1,12 +1,38 @@
DISABLED_WARNINGS=-Wno-switch -Wno-pointer-sign -Wno-tautological-constant-out-of-range-compare -Wno-tautological-compare -Wno-macro-redefined -Wno-writable-strings
GIT_SHA=$(shell git rev-parse --short HEAD)
DISABLED_WARNINGS=-Wno-switch -Wno-macro-redefined -Wno-unused-value
LDFLAGS=-pthread -ldl -lm -lstdc++
CFLAGS=-std=c++11
CFLAGS=-std=c++14 -DGIT_SHA=\"$(GIT_SHA)\"
CFLAGS:=$(CFLAGS) -DODIN_VERSION_RAW=\"dev-$(shell date +"%Y-%m")\"
CC=clang
OS=$(shell uname)
ifeq ($(OS), Darwin)
LDFLAGS:=$(LDFLAGS) -liconv
LLVM_CONFIG=llvm-config
ifneq ($(shell llvm-config --version | grep '^11\.'),)
LLVM_CONFIG=llvm-config
else
$(error "Requirement: llvm-config must be version 11")
endif
LDFLAGS:=$(LDFLAGS) -liconv
CFLAGS:=$(CFLAGS) $(shell $(LLVM_CONFIG) --cxxflags --ldflags)
LDFLAGS:=$(LDFLAGS) -lLLVM-C
endif
ifeq ($(OS), Linux)
LLVM_CONFIG=llvm-config-11
ifneq ($(shell which llvm-config-11 2>/dev/null),)
LLVM_CONFIG=llvm-config-11
else
ifneq ($(shell llvm-config --version | grep '^11\.'),)
LLVM_CONFIG=llvm-config
else
$(error "Requirement: llvm-config must be version 11")
endif
endif
CFLAGS:=$(CFLAGS) $(shell $(LLVM_CONFIG) --cxxflags --ldflags)
LDFLAGS:=$(LDFLAGS) $(shell $(LLVM_CONFIG) --libs core native --system-libs)
endif
all: debug demo
@@ -15,10 +41,13 @@ demo:
./odin run examples/demo/demo.odin
debug:
$(CC) src/main.cpp $(DISABLED_WARNINGS) $(CFLAGS) -g $(LDFLAGS) -o odin
$(CC) src/main.cpp src/libtommath.cpp $(DISABLED_WARNINGS) $(CFLAGS) -g $(LDFLAGS) -o odin
release:
$(CC) src/main.cpp $(DISABLED_WARNINGS) $(CFLAGS) -O3 -march=native $(LDFLAGS) -o odin
$(CC) src/main.cpp src/libtommath.cpp $(DISABLED_WARNINGS) $(CFLAGS) -O3 $(LDFLAGS) -o odin
release_native:
$(CC) src/main.cpp src/libtommath.cpp $(DISABLED_WARNINGS) $(CFLAGS) -O3 -march=native $(LDFLAGS) -o odin
nightly:
$(CC) src/main.cpp src/libtommath.cpp $(DISABLED_WARNINGS) $(CFLAGS) -DNIGHTLY -O3 $(LDFLAGS) -o odin
+1 -1
View File
@@ -30,7 +30,7 @@ The proposal process is the process for reviewing a proposal and reaching a deci
* Accept proposal
* Decline proposal
After the proposal is accepted or declined, implementation of the proprosal proceeds in the same way as any other contribution to the project.
After the proposal is accepted or declined, implementation of the proposal proceeds in the same way as any other contribution to the project.
## Design Documents
+17 -12
View File
@@ -15,13 +15,13 @@
<img src="https://img.shields.io/discord/568138951836172421?logo=discord">
</a>
<a href="https://github.com/odin-lang/odin/actions">
<img src="https://github.com/odin-lang/odin/workflows/CI/badge.svg">
<img src="https://github.com/odin-lang/odin/workflows/CI/badge.svg?branch=master&event=push">
</a>
</p>
# The Odin Programming Language
The Odin programming language is fast, concise, readable, pragmatic and open sourced. It is designed with the intent of replacing C with the following goals:
The Odin programming language is fast, concise, readable, pragmatic and open sourced. It is designed with the intent of creating an alternative to C with the following goals:
* simplicity
* high performance
* built for modern systems
@@ -29,7 +29,7 @@ The Odin programming language is fast, concise, readable, pragmatic and open sou
Website: [https://odin-lang.org/](https://odin-lang.org/)
```go
```odin
package main
import "core:fmt"
@@ -60,7 +60,7 @@ main :: proc() {
#### [Getting Started](https://odin-lang.org/docs/install)
Instructions for downloading and install the Odin compiler and libraries.
Instructions for downloading and installing the Odin compiler and libraries.
### Learning Odin
@@ -94,13 +94,12 @@ The official blog of the Odin programming language, featuring announcements, new
## Setup
Odin only supports x86-64 at the moment (64-bit), relies on LLVM for code generation and an external linker.
Odin only supports x86-64/amd64 at the moment (64-bit), relies on LLVM for code generation and an external linker.
In addition, the following platform-specific steps are necessary:
- Windows
* Have Visual Studio installed (MSVC 2010 or later, for the linker)
* Have a copy of `opt.exe` and `llc.exe` in `Odin/bin`. Pre-built Windows binaries can be found [here](https://github.com/odin-lang/Odin/releases/tag/llvm-windows) and *must* be explicitly copied
* Open a valid command prompt:
* **Basic:** run the `x64 Native Tools Command Prompt for VS2017` shortcut bundled with VS 2017, or
* **Advanced:** run `vcvarsall.bat x64` from a blank `cmd` session
@@ -126,27 +125,33 @@ Please read the [Getting Started Guide](https://github.com/odin-lang/Odin/wiki#g
Please read the [Getting Started Guide](https://github.com/odin-lang/Odin/wiki#getting-started-with-odin).
- Windows
* x86-64
* x86-64/amd64
* MSVC 2010 installed (C++11 support)
* [LLVM binaries](https://github.com/odin-lang/Odin/releases/tag/llvm-windows) for `opt.exe`, `llc.exe`, and `lld-link.exe`
* Requires MSVC's link.exe as the linker
* run `vcvarsall.bat` to setup the path
- MacOS
* x86-64
* x86-64/amd64
* LLVM explicitly installed (`brew install llvm`)
* XCode installed (for the linker)
- GNU/Linux
* x86-64
* x86-64/amd64
* Build tools (ld)
* LLVM installed
* Clang installed (temporary - this is Calling the linker for now)
- FreeBSD
* x86-64/amd64
* Build tools (ld)
* LLVM installed
* Clang installed (temporary - this is Calling the linker for now)
Other platforms may be supported but are experimental for the time being.
## Warnings
* This is still highly in development and the language's design is quite volatile.
* Syntax is not fixed.
* The Odin compiler is still in development.
## Demonstrations:
* First Talk & Demo
+3 -4
View File
@@ -2,13 +2,12 @@
## Setup
Odin only supports x86-64 at the moment (64-bit), relies on LLVM for code generation and an external linker.
Odin currently supports x86-64 and ARM64 at the moment (64-bit), relies on LLVM for code generation and an external linker.
In addition, the following platform-specific steps are necessary:
- Windows
* Have Visual Studio installed (MSVC 2010 or later, for the linker)
* Have a copy of `opt.exe` and `llc.exe` in `Odin/bin`. Pre-built Windows binaries can be found [here](https://github.com/odin-lang/Odin/releases/tag/llvm-windows) and *must* be explicitly copied
* Open a valid command prompt:
* **Basic:** run the `x64 Native Tools Command Prompt for VS2017` shortcut bundled with VS 2017, or
* **Advanced:** run `vcvarsall.bat x64` from a blank `cmd` session
@@ -19,12 +18,12 @@ In addition, the following platform-specific steps are necessary:
* Make sure the LLVM binaries and the linker are added to your `$PATH` environmental variable
- GNU/Linux
* Have LLVM installed (opt/llc)
* Have Clang installed (version X.X or later, for linking)
* Make sure the LLVM binaries and the linker are added to your `$PATH` environmental variable
Then build the compiler by calling `build.bat` (Windows) or `make` (Linux/MacOS). This will automatically run the demo program if successful.
**Notes for Linux:**: The compiler currently relies on the `core` and `shared` library collection being relative to the compiler executable. Installing the compiler in the usual sense (to `/usr/local/bin` or similar) is therefore not as straight forward as you need to make sure the mentioned libraries are available. As a result, it is recommended to simply explicitly invoke the compiler with `/path/to/odin` in your preferred build system, or add `/path/to/odin` to `$PATH`.
**Notes for \*Nix Systems:**: The compiler currently relies on the `core` and `shared` library collection being relative to the compiler executable, by default. Installing the compiler in the usual sense (to `/usr/local/bin` or similar) is therefore not as straight forward as you need to make sure the mentioned libraries are available. As a result, it is recommended to either simply explicitly invoke the compiler with `/path/to/odin` in your preferred build system, or `set ODIN_ROOT=/path/to/odin_root`.
Please read the [Getting Started Guide](https://github.com/odin-lang/Odin/wiki#getting-started-with-odin) for more information.
Binary file not shown.
+43 -13
View File
@@ -1,29 +1,58 @@
@echo off
setlocal EnableDelayedExpansion
for /f "usebackq tokens=1,2 delims=,=- " %%i in (`wmic os get LocalDateTime /value`) do @if %%i==LocalDateTime (
set CURR_DATE_TIME=%%j
)
set curr_year=%CURR_DATE_TIME:~0,4%
set curr_month=%CURR_DATE_TIME:~4,2%
:: Make sure this is a decent name and not generic
set exe_name=odin.exe
:: Debug = 0, Release = 1
set release_mode=0
set compiler_flags= -nologo -Oi -TP -fp:precise -Gm- -MP -FC -GS- -EHsc- -GR-
if "%1" == "1" (
set release_mode=1
) else if "%1" == "release" (
set release_mode=1
) else (
set release_mode=0
)
:: Normal = 0, CI Nightly = 1
if "%2" == "1" (
set nightly=1
) else (
set nightly=0
)
set odin_version_raw="dev-%curr_year%-%curr_month%"
set compiler_flags= -nologo -Oi -TP -fp:precise -Gm- -MP -FC -EHsc- -GR- -GF
set compiler_defines= -DODIN_VERSION_RAW=\"%odin_version_raw%\"
for /f %%i in ('git rev-parse --short HEAD') do set GIT_SHA=%%i
if %ERRORLEVEL% equ 0 set compiler_defines=%compiler_defines% -DGIT_SHA=\"%GIT_SHA%\"
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
rem -DDISPLAY_TIMING
) else ( rem Release
set compiler_flags=%compiler_flags% -O2 -MT -Z7 -DNO_ARRAY_BOUNDS_CHECK
set compiler_flags=%compiler_flags% -O2 -MT -Z7
set compiler_defines=%compiler_defines% -DNO_ARRAY_BOUNDS_CHECK
)
set compiler_warnings= ^
-W4 -WX ^
-wd4100 -wd4101 -wd4127 -wd4189 ^
-wd4201 -wd4204 ^
-wd4456 -wd4457 -wd4480 ^
-wd4512
-wd4100 -wd4101 -wd4127 -wd4146 ^
-wd4456 -wd4457
set compiler_includes=
set libs= ^
kernel32.lib
kernel32.lib ^
bin\llvm\windows\LLVM-C.lib
set linker_flags= -incremental:no -opt:ref -subsystem:console
@@ -33,15 +62,16 @@ if %release_mode% EQU 0 ( rem Debug
set linker_flags=%linker_flags% -debug
)
set compiler_settings=%compiler_includes% %compiler_flags% %compiler_warnings%
set compiler_settings=%compiler_includes% %compiler_flags% %compiler_warnings% %compiler_defines%
set linker_settings=%libs% %linker_flags%
del *.pdb > NUL 2> NUL
del *.ilk > NUL 2> NUL
cl %compiler_settings% "src\main.cpp" ^
/link %linker_settings% -OUT:%exe_name% ^
&& odin run examples/demo/demo.odin
cl %compiler_settings% "src\main.cpp" "src\libtommath.cpp" /link %linker_settings% -OUT:%exe_name%
if %errorlevel% neq 0 goto end_of_build
if %release_mode% EQU 0 odin run examples/demo
del *.obj > NUL 2> NUL
-28
View File
@@ -1,28 +0,0 @@
#!/bin/bash
release_mode=$1
warnings_to_disable="-std=c++11 -Wno-switch -Wno-pointer-sign -Wno-tautological-constant-out-of-range-compare -Wno-tautological-compare -Wno-macro-redefined -Wno-writable-strings"
libraries="-pthread -ldl -lm -lstdc++"
other_args=""
compiler="clang"
if [ -z "$release_mode" ]; then release_mode="0"; fi
if [ "$release_mode" -eq "0" ]; then
other_args="${other_args} -g"
fi
if [ "$release_mode" -eq "1" ]; then
other_args="${other_args} -O3 -march=native"
fi
if [[ "$(uname)" == "Darwin" ]]; then
# Set compiler to clang on MacOS
# MacOS provides a symlink to clang called gcc, but it's nice to be explicit here.
compiler="clang"
other_args="${other_args} -liconv"
fi
${compiler} src/main.cpp ${warnings_to_disable} ${libraries} ${other_args} -o odin && ./odin run examples/demo/demo.odin
-24
View File
@@ -1,24 +0,0 @@
@echo off
set exe_name=odin.exe
set compiler_flags= -nologo -Oi -TP -fp:precise -Gm- -MP -FC -GS- -EHsc- -GR- -O2 -MT -Z7 -DNO_ARRAY_BOUNDS_CHECK
set compiler_warnings= ^
-W4 -WX ^
-wd4100 -wd4101 -wd4127 -wd4189 ^
-wd4201 -wd4204 ^
-wd4456 -wd4457 -wd4480 ^
-wd4512
set compiler_includes=
set libs= ^
kernel32.lib
set linker_flags= -incremental:no -opt:ref -subsystem:console -debug
set compiler_settings=%compiler_includes% %compiler_flags% %compiler_warnings%
set linker_settings=%libs% %linker_flags%
cl %compiler_settings% "src\main.cpp" ^
/link %linker_settings% -OUT:%exe_name% ^
+51
View File
@@ -0,0 +1,51 @@
import subprocess
import sys
import json
import datetime
import urllib.parse
import sys
def main():
files_by_date = {}
bucket = sys.argv[1]
files_lines = execute_cli(f"b2 ls --long {bucket} nightly").split("\n")
for x in files_lines:
parts = x.split(" ", 1)
if parts[0]:
json_str = execute_cli(f"b2 get-file-info {parts[0]}")
data = json.loads(json_str)
name = remove_prefix(data['fileName'], "nightly/")
url = f"https://f001.backblazeb2.com/file/{bucket}/nightly/{urllib.parse.quote_plus(name)}"
sha1 = data['contentSha1']
size = int(data['size'])
ts = int(data['fileInfo']['src_last_modified_millis'])
date = datetime.datetime.fromtimestamp(ts/1000).strftime('%Y-%m-%d')
if date not in files_by_date.keys():
files_by_date[date] = []
files_by_date[date].append({
'name': name,
'url': url,
'sha1': sha1,
'sizeInBytes': size,
})
now = datetime.datetime.utcnow().isoformat()
print(json.dumps({
'last_updated' : now,
'files': files_by_date
}, sort_keys=True, indent=4))
def remove_prefix(text, prefix):
return text[text.startswith(prefix) and len(prefix):]
def execute_cli(command):
sb = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
return sb.stdout.read().decode("utf-8");
if __name__ == '__main__':
sys.exit(main())
+34
View File
@@ -0,0 +1,34 @@
import subprocess
import sys
import json
import datetime
import urllib.parse
import sys
def main():
files_by_date = {}
bucket = sys.argv[1]
days_to_keep = int(sys.argv[2])
print(f"Looking for binaries to delete older than {days_to_keep} days")
files_lines = execute_cli(f"b2 ls --long --versions {bucket} nightly").split("\n")
for x in files_lines:
parts = [y for y in x.split(' ') if y]
if parts and parts[0]:
date = datetime.datetime.strptime(parts[2], '%Y-%m-%d').replace(hour=0, minute=0, second=0, microsecond=0)
now = datetime.datetime.utcnow().replace(hour=0, minute=0, second=0, microsecond=0)
delta = now - date
if delta.days > days_to_keep:
print(f'Deleting {parts[5]}')
execute_cli(f'b2 delete-file-version {parts[0]}')
def execute_cli(command):
sb = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
return sb.stdout.read().decode("utf-8");
if __name__ == '__main__':
sys.exit(main())
+13
View File
@@ -0,0 +1,13 @@
#!/bin/bash
bucket=$1
platform=$2
artifact=$3
now=$(date +'%Y-%m-%d')
filename="odin-$platform-nightly+$now.zip"
echo "Creating archive $filename from $artifact and uploading to $bucket"
7z a -bd "output/$filename" -r "$artifact"
b2 upload-file --noProgress "$bucket" "output/$filename" "nightly/$filename"
+83
View File
@@ -0,0 +1,83 @@
package bufio
import "core:io"
// Loadahead_Reader provides io lookahead.
// This is useful for tokenizers/parsers.
// Loadahead_Reader is similar to bufio.Reader, but unlike bufio.Reader, Loadahead_Reader's buffer size
// will EXACTLY match the specified size, whereas bufio.Reader's buffer size may differ from the specified size.
// This makes sure that the buffer will not be accidentally read beyond the expected size.
Loadahead_Reader :: struct {
r: io.Reader,
buf: []byte,
n: int,
}
lookahead_reader_init :: proc(lr: ^Loadahead_Reader, r: io.Reader, buf: []byte) -> ^Loadahead_Reader {
lr.r = r;
lr.buf = buf;
lr.n = 0;
return lr;
}
lookahead_reader_buffer :: proc(lr: ^Loadahead_Reader) -> []byte {
return lr.buf[:lr.n];
}
// lookahead_reader_peek returns a slice of the Lookahead_Reader which holds n bytes
// If the Lookahead_Reader cannot hold enough bytes, it will read from the underlying reader to populate the rest.
// NOTE: The returned buffer is not a copy of the underlying buffer
lookahead_reader_peek :: proc(lr: ^Loadahead_Reader, n: int) -> ([]byte, io.Error) {
switch {
case n < 0:
return nil, .Negative_Read;
case n > len(lr.buf):
return nil, .Buffer_Full;
}
n := n;
err: io.Error;
read_count: int;
if lr.n < n {
read_count, err = io.read_at_least(lr.r, lr.buf[lr.n:], n-lr.n);
if err == .Unexpected_EOF {
err = .EOF;
}
}
lr.n += read_count;
if n > lr.n {
n = lr.n;
}
return lr.buf[:n], err;
}
// lookahead_reader_peek_all returns a slice of the Lookahead_Reader populating the full buffer
// If the Lookahead_Reader cannot hold enough bytes, it will read from the underlying reader to populate the rest.
// NOTE: The returned buffer is not a copy of the underlying buffer
lookahead_reader_peek_all :: proc(lr: ^Loadahead_Reader) -> ([]byte, io.Error) {
return lookahead_reader_peek(lr, len(lr.buf));
}
// lookahead_reader_consume drops the first n populated bytes from the Lookahead_Reader.
lookahead_reader_consume :: proc(lr: ^Loadahead_Reader, n: int) -> io.Error {
switch {
case n == 0:
return nil;
case n < 0:
return .Negative_Read;
case lr.n < n:
return .Short_Buffer;
}
copy(lr.buf, lr.buf[n:lr.n]);
lr.n -= n;
return nil;
}
lookahead_reader_consume_all :: proc(lr: ^Loadahead_Reader) -> io.Error {
return lookahead_reader_consume(lr, lr.n);
}
+68
View File
@@ -0,0 +1,68 @@
package bufio
import "core:io"
// Read_Writer stores pointers to a Reader and a Writer
Read_Writer :: struct {
r: ^Reader,
w: ^Writer,
}
read_writer_init :: proc(rw: ^Read_Writer, r: ^Reader, w: ^Writer) {
rw.r, rw.w = r, w;
}
read_writer_to_stream :: proc(rw: ^Read_Writer) -> (s: io.Stream) {
s.stream_data = rw;
s.stream_vtable = _read_writer_vtable;
return;
}
@(private)
_read_writer_vtable := &io.Stream_VTable{
impl_read = proc(s: io.Stream, p: []byte) -> (n: int, err: io.Error) {
b := (^Read_Writer)(s.stream_data).r;
return reader_read(b, p);
},
impl_read_byte = proc(s: io.Stream) -> (c: byte, err: io.Error) {
b := (^Read_Writer)(s.stream_data).r;
return reader_read_byte(b);
},
impl_unread_byte = proc(s: io.Stream) -> io.Error {
b := (^Read_Writer)(s.stream_data).r;
return reader_unread_byte(b);
},
impl_read_rune = proc(s: io.Stream) -> (r: rune, size: int, err: io.Error) {
b := (^Read_Writer)(s.stream_data).r;
return reader_read_rune(b);
},
impl_unread_rune = proc(s: io.Stream) -> io.Error {
b := (^Read_Writer)(s.stream_data).r;
return reader_unread_rune(b);
},
impl_write_to = proc(s: io.Stream, w: io.Writer) -> (n: i64, err: io.Error) {
b := (^Read_Writer)(s.stream_data).r;
return reader_write_to(b, w);
},
impl_flush = proc(s: io.Stream) -> io.Error {
b := (^Read_Writer)(s.stream_data).w;
return writer_flush(b);
},
impl_write = proc(s: io.Stream, p: []byte) -> (n: int, err: io.Error) {
b := (^Read_Writer)(s.stream_data).w;
return writer_write(b, p);
},
impl_write_byte = proc(s: io.Stream, c: byte) -> io.Error {
b := (^Read_Writer)(s.stream_data).w;
return writer_write_byte(b, c);
},
impl_write_rune = proc(s: io.Stream, r: rune) -> (int, io.Error) {
b := (^Read_Writer)(s.stream_data).w;
return writer_write_rune(b, r);
},
impl_read_from = proc(s: io.Stream, r: io.Reader) -> (n: i64, err: io.Error) {
b := (^Read_Writer)(s.stream_data).w;
return writer_read_from(b, r);
},
};
+480
View File
@@ -0,0 +1,480 @@
package bufio
import "core:io"
import "core:mem"
import "core:unicode/utf8"
import "core:bytes"
// Reader is a buffered wrapper for an io.Reader
Reader :: struct {
buf: []byte,
buf_allocator: mem.Allocator,
rd: io.Reader, // reader
r, w: int, // read and write positions for buf
err: io.Error,
last_byte: int, // last byte read, invalid is -1
last_rune_size: int, // size of last rune read, invalid is -1
max_consecutive_empty_reads: int,
}
DEFAULT_BUF_SIZE :: 4096;
@(private)
MIN_READ_BUFFER_SIZE :: 16;
@(private)
DEFAULT_MAX_CONSECUTIVE_EMPTY_READS :: 128;
reader_init :: proc(b: ^Reader, rd: io.Reader, size: int = DEFAULT_BUF_SIZE, allocator := context.allocator) {
size := size;
size = max(size, MIN_READ_BUFFER_SIZE);
reader_reset(b, rd);
b.buf_allocator = allocator;
b.buf = make([]byte, size, allocator);
}
reader_init_with_buf :: proc(b: ^Reader, rd: io.Reader, buf: []byte) {
reader_reset(b, rd);
b.buf_allocator = {};
b.buf = buf;
}
// reader_destroy destroys the underlying buffer with its associated allocator IFF that allocator has been set
reader_destroy :: proc(b: ^Reader) {
delete(b.buf, b.buf_allocator);
b^ = {};
}
reader_size :: proc(b: ^Reader) -> int {
return len(b.buf);
}
reader_reset :: proc(b: ^Reader, r: io.Reader) {
b.rd = r;
b.r, b.w = 0, 0;
b.err = nil;
b.last_byte = -1;
b.last_rune_size = -1;
}
@(private)
_reader_read_new_chunk :: proc(b: ^Reader) -> io.Error {
if b.r > 0 {
copy(b.buf, b.buf[b.r:b.w]);
b.w -= b.r;
b.r = 0;
}
if b.w >= len(b.buf) {
return .Buffer_Full;
}
if b.max_consecutive_empty_reads <= 0 {
b.max_consecutive_empty_reads = DEFAULT_MAX_CONSECUTIVE_EMPTY_READS;
}
// read new data, and try a limited number of times
for i := b.max_consecutive_empty_reads; i > 0; i -= 1 {
n, err := io.read(b.rd, b.buf[b.w:]);
if n < 0 {
return .Negative_Read;
}
b.w += n;
if err != nil {
b.err = err;
return nil;
}
if n > 0 {
return nil;
}
}
b.err = .No_Progress;
return nil;
}
@(private)
_reader_consume_err :: proc(b: ^Reader) -> io.Error {
err := b.err;
b.err = nil;
return err;
}
// reader_peek returns the next n bytes without advancing the reader
// The bytes stop being valid on the next read call
// If reader_peek returns fewer than n bytes, it also return an error
// explaining why the read is short
// The error will be .Buffer_Full if n is larger than the internal buffer size
reader_peek :: proc(b: ^Reader, n: int) -> (data: []byte, err: io.Error) {
n := n;
if n < 0 {
return nil, .Negative_Count;
}
b.last_byte = -1;
b.last_rune_size = -1;
for b.w-b.r < n && b.w-b.r < len(b.buf) && b.err == nil {
if fill_err := _reader_read_new_chunk(b); fill_err != nil {
return nil, fill_err;
}
}
if n > len(b.buf) {
return b.buf[b.r : b.w], .Buffer_Full;
}
if available := b.w - b.r; available < n {
n = available;
err = _reader_consume_err(b);
if err == nil {
err = .Buffer_Full;
}
}
return b.buf[b.r : b.r+n], err;
}
// reader_buffered returns the number of bytes that can be read from the current buffer
reader_buffered :: proc(b: ^Reader) -> int {
return b.w - b.r;
}
// reader_discard skips the next n bytes, and returns the number of bytes that were discarded
reader_discard :: proc(b: ^Reader, n: int) -> (discarded: int, err: io.Error) {
if n < 0 {
return 0, .Negative_Count;
}
if n == 0 {
return;
}
remaining := n;
for {
skip := reader_buffered(b);
if skip == 0 {
if fill_err := _reader_read_new_chunk(b); fill_err != nil {
return 0, fill_err;
}
skip = reader_buffered(b);
}
skip = min(skip, remaining);
b.r += skip;
remaining -= skip;
if remaining == 0 {
return n, nil;
}
if b.err != nil {
return n - remaining, _reader_consume_err(b);
}
}
return;
}
// reader_read reads data into p
// The bytes are taken from at most one read on the underlying Reader, which means n may be less than len(p)
reader_read :: proc(b: ^Reader, p: []byte) -> (n: int, err: io.Error) {
n = len(p);
if n == 0 {
if reader_buffered(b) > 0 {
return 0, nil;
}
return 0, _reader_consume_err(b);
}
if b.r == b.w {
if b.err != nil {
return 0, _reader_consume_err(b);
}
if len(p) >= len(b.buf) {
n, b.err = io.read(b.rd, p);
if n < 0 {
return 0, .Negative_Read;
}
if n > 0 {
b.last_byte = int(p[n-1]);
b.last_rune_size = -1;
}
return n, _reader_consume_err(b);
}
b.r, b.w = 0, 0;
n, b.err = io.read(b.rd, b.buf);
if n < 0 {
return 0, .Negative_Read;
}
if n == 0 {
return 0, _reader_consume_err(b);
}
b.w += n;
}
n = copy(p, b.buf[b.r:b.w]);
b.r += n;
b.last_byte = int(b.buf[b.r-1]);
b.last_rune_size = -1;
return n, nil;
}
// reader_read_byte reads and returns a single byte
// If no byte is available, it return an error
reader_read_byte :: proc(b: ^Reader) -> (byte, io.Error) {
b.last_rune_size = -1;
for b.r == b.w {
if b.err != nil {
return 0, _reader_consume_err(b);
}
if err := _reader_read_new_chunk(b); err != nil {
return 0, err;
}
}
c := b.buf[b.r];
b.r += 1;
b.last_byte = int(c);
return c, nil;
}
// reader_unread_byte unreads the last byte. Only the most recently read byte can be unread
reader_unread_byte :: proc(b: ^Reader) -> io.Error {
if b.last_byte < 0 || b.r == 0 && b.w > 0 {
return .Invalid_Unread;
}
if b.r > 0 {
b.r -= 1;
} else {
// b.r == 0 && b.w == 0
b.w = 1;
}
b.buf[b.r] = byte(b.last_byte);
b.last_byte = -1;
b.last_rune_size = -1;
return nil;
}
// reader_read_rune reads a single UTF-8 encoded unicode character
// and returns the rune and its size in bytes
// If the encoded rune is invalid, it consumes one byte and returns utf8.RUNE_ERROR (U+FFFD) with a size of 1
reader_read_rune :: proc(b: ^Reader) -> (r: rune, size: int, err: io.Error) {
for b.r+utf8.UTF_MAX > b.w &&
!utf8.full_rune(b.buf[b.r:b.w]) &&
b.err == nil &&
b.w-b.w < len(b.buf) {
if err = _reader_read_new_chunk(b); err != nil {
return;
}
}
b.last_rune_size = -1;
if b.r == b.w {
err = _reader_consume_err(b);
return;
}
r, size = rune(b.buf[b.r]), 1;
if r >= utf8.RUNE_SELF {
r, size = utf8.decode_rune(b.buf[b.r : b.w]);
}
b.r += size;
b.last_byte = int(b.buf[b.r-1]);
b.last_rune_size = size;
return;
}
// reader_unread_rune unreads the last rune. Only the most recently read rune can be unread
reader_unread_rune :: proc(b: ^Reader) -> io.Error {
if b.last_rune_size < 0 || b.r < b.last_rune_size {
return .Invalid_Unread;
}
b.r -= b.last_rune_size;
b.last_byte = -1;
b.last_rune_size = -1;
return nil;
}
reader_write_to :: proc(b: ^Reader, w: io.Writer) -> (n: i64, err: io.Error) {
write_buf :: proc(b: ^Reader, w: io.Writer) -> (i64, io.Error) {
n, err := io.write(w, b.buf[b.r:b.w]);
if n < 0 {
return 0, .Negative_Write;
}
b.r += n;
return i64(n), err;
}
n, err = write_buf(b, w);
if err != nil {
return;
}
m: i64;
if nr, ok := io.to_writer_to(b.rd); ok {
m, err = io.write_to(nr, w);
n += m;
return n, err;
}
if nw, ok := io.to_reader_from(w); ok {
m, err = io.read_from(nw, b.rd);
n += m;
return n, err;
}
if b.w-b.r < len(b.buf) {
if err = _reader_read_new_chunk(b); err != nil {
return;
}
}
for b.r < b.w {
m, err = write_buf(b, w);
n += m;
if err != nil {
return;
}
if err = _reader_read_new_chunk(b); err != nil {
return;
}
}
if b.err == .EOF {
b.err = nil;
}
err = _reader_consume_err(b);
return;
}
// reader_to_stream converts a Reader into an io.Stream
reader_to_stream :: proc(b: ^Reader) -> (s: io.Stream) {
s.stream_data = b;
s.stream_vtable = _reader_vtable;
return;
}
@(private)
_reader_vtable := &io.Stream_VTable{
impl_destroy = proc(s: io.Stream) -> io.Error {
b := (^Reader)(s.stream_data);
reader_destroy(b);
return nil;
},
impl_read = proc(s: io.Stream, p: []byte) -> (n: int, err: io.Error) {
b := (^Reader)(s.stream_data);
return reader_read(b, p);
},
impl_read_byte = proc(s: io.Stream) -> (c: byte, err: io.Error) {
b := (^Reader)(s.stream_data);
return reader_read_byte(b);
},
impl_unread_byte = proc(s: io.Stream) -> io.Error {
b := (^Reader)(s.stream_data);
return reader_unread_byte(b);
},
impl_read_rune = proc(s: io.Stream) -> (r: rune, size: int, err: io.Error) {
b := (^Reader)(s.stream_data);
return reader_read_rune(b);
},
impl_unread_rune = proc(s: io.Stream) -> io.Error {
b := (^Reader)(s.stream_data);
return reader_unread_rune(b);
},
impl_write_to = proc(s: io.Stream, w: io.Writer) -> (n: i64, err: io.Error) {
b := (^Reader)(s.stream_data);
return reader_write_to(b, w);
},
};
//
// Utility procedures
//
// reader_read_slice reads until the first occurrence of delim from the reader
// It returns a slice pointing at the bytes in the buffer
// The bytes stop being valid at the next read
// If reader_read_slice encounters an error before finding a delimiter
// reader_read_slice fails with error .Buffer_Full if the buffer fills without a delim
// Because the data returned from reader_read_slice will be overwritten on the
// next IO operation, reader_read_bytes or reader_read_string is usually preferred
//
// reader_read_slice returns err != nil if and only if line does not end in delim
//
reader_read_slice :: proc(b: ^Reader, delim: byte) -> (line: []byte, err: io.Error) {
s := 0;
for {
if i := bytes.index_byte(b.buf[b.r+s : b.w], delim); i >= 0 {
i += s;
line = b.buf[b.r:][:i+1];
b.r += i + 1;
break;
}
if b.err != nil {
line = b.buf[b.r : b.w];
b.r = b.w;
err = _reader_consume_err(b);
break;
}
if reader_buffered(b) >= len(b.buf) {
b.r = b.w;
line = b.buf;
err = .Buffer_Full;
break;
}
s = b.w - b.r;
if err = _reader_read_new_chunk(b); err != nil {
break;
}
}
if i := len(line)-1; i >= 0 {
b.last_byte = int(line[i]);
b.last_rune_size = -1;
}
return;
}
// reader_read_bytes reads until the first occurrence of delim from the Reader
// It returns an allocated slice containing the data up to and including the delimiter
reader_read_bytes :: proc(b: ^Reader, delim: byte, allocator := context.allocator) -> (buf: []byte, err: io.Error) {
full: [dynamic]byte;
full.allocator = allocator;
frag: []byte;
for {
e: io.Error;
frag, e = reader_read_slice(b, delim);
if e == nil {
break;
}
if e != .Buffer_Full {
err = e;
break;
}
append(&full, ..frag);
}
append(&full, ..frag);
return full[:], err;
}
// reader_read_string reads until the first occurrence of delim from the Reader
// It returns an allocated string containing the data up to and including the delimiter
reader_read_string :: proc(b: ^Reader, delim: byte, allocator := context.allocator) -> (string, io.Error) {
buf, err := reader_read_bytes(b, delim, allocator);
return string(buf), err;
}
+340
View File
@@ -0,0 +1,340 @@
package bufio
import "core:bytes"
import "core:io"
import "core:mem"
import "core:unicode/utf8"
import "core:intrinsics"
// Extra errors returns by scanning procedures
Scanner_Extra_Error :: enum i32 {
Negative_Advance,
Advanced_Too_Far,
Bad_Read_Count,
Too_Long,
Too_Short,
}
Scanner_Error :: union {
io.Error,
Scanner_Extra_Error,
}
// Split_Proc is the signature of the split procedure used to tokenize the input.
Split_Proc :: proc(data: []byte, at_eof: bool) -> (advance: int, token: []byte, err: Scanner_Error, final_token: bool);
Scanner :: struct {
r: io.Reader,
split: Split_Proc,
buf: [dynamic]byte,
max_token_size: int,
start: int,
end: int,
token: []byte,
_err: Scanner_Error,
max_consecutive_empty_reads: int,
successive_empty_token_count: int,
scan_called: bool,
done: bool,
}
DEFAULT_MAX_SCAN_TOKEN_SIZE :: 1<<16;
@(private)
_INIT_BUF_SIZE :: 4096;
scanner_init :: proc(s: ^Scanner, r: io.Reader, buf_allocator := context.allocator) -> ^Scanner {
s.r = r;
s.split = scan_lines;
s.max_token_size = DEFAULT_MAX_SCAN_TOKEN_SIZE;
s.buf.allocator = buf_allocator;
return s;
}
scanner_init_with_buffer :: proc(s: ^Scanner, r: io.Reader, buf: []byte) -> ^Scanner {
s.r = r;
s.split = scan_lines;
s.max_token_size = DEFAULT_MAX_SCAN_TOKEN_SIZE;
s.buf = mem.buffer_from_slice(buf);
resize(&s.buf, cap(s.buf));
return s;
}
scanner_destroy :: proc(s: ^Scanner) {
delete(s.buf);
}
// Returns the first non-EOF error that was encounted by the scanner
scanner_error :: proc(s: ^Scanner) -> Scanner_Error {
switch s._err {
case .EOF, .None:
return nil;
}
return s._err;
}
// Returns the most recent token created by scanner_scan.
// The underlying array may point to data that may be overwritten
// by another call to scanner_scan.
// Treat the returned value as if it is immutable.
scanner_bytes :: proc(s: ^Scanner) -> []byte {
return s.token;
}
// Returns the most recent token created by scanner_scan.
// The underlying array may point to data that may be overwritten
// by another call to scanner_scan.
// Treat the returned value as if it is immutable.
scanner_text :: proc(s: ^Scanner) -> string {
return string(s.token);
}
// scanner_scan advances the scanner
scanner_scan :: proc(s: ^Scanner) -> bool {
set_err :: proc(s: ^Scanner, err: Scanner_Error) {
err := err;
if err == .None {
err = nil;
}
switch s._err {
case nil, .EOF:
s._err = err;
}
}
if s.done {
return false;
}
s.scan_called = true;
for {
// Check if a token is possible with what is available
// Allow the split procedure to recover if it fails
if s.start < s.end || s._err != nil {
advance, token, err, final_token := s.split(s.buf[s.start:s.end], s._err != nil);
if final_token {
s.token = token;
s.done = true;
return true;
}
if err != nil {
set_err(s, err);
return false;
}
// Do advance
if advance < 0 {
set_err(s, .Negative_Advance);
return false;
}
if advance > s.end-s.start {
set_err(s, .Advanced_Too_Far);
return false;
}
s.start += advance;
s.token = token;
if s.token != nil {
if s._err == nil || advance > 0 {
s.successive_empty_token_count = 0;
} else {
s.successive_empty_token_count += 1;
if s.max_consecutive_empty_reads <= 0 {
s.max_consecutive_empty_reads = DEFAULT_MAX_CONSECUTIVE_EMPTY_READS;
}
if s.successive_empty_token_count > s.max_consecutive_empty_reads {
set_err(s, .No_Progress);
return false;
}
}
return true;
}
}
// If an error is hit, no token can be created
if s._err != nil {
s.start = 0;
s.end = 0;
return false;
}
// More data must be required to be read
if s.start > 0 && (s.end == len(s.buf) || s.start > len(s.buf)/2) {
copy(s.buf[:], s.buf[s.start:s.end]);
s.end -= s.start;
s.start = 0;
}
could_be_too_short := false;
// Resize the buffer if full
if s.end == len(s.buf) {
if s.max_token_size <= 0 {
s.max_token_size = DEFAULT_MAX_SCAN_TOKEN_SIZE;
}
if len(s.buf) >= s.max_token_size {
set_err(s, .Too_Long);
return false;
}
// overflow check
new_size := _INIT_BUF_SIZE;
if len(s.buf) > 0 {
overflowed: bool;
if new_size, overflowed = intrinsics.overflow_mul(len(s.buf), 2); overflowed {
set_err(s, .Too_Long);
return false;
}
}
old_size := len(s.buf);
new_size = min(new_size, s.max_token_size);
resize(&s.buf, new_size);
s.end -= s.start;
s.start = 0;
could_be_too_short = old_size >= len(s.buf);
}
// Read data into the buffer
loop := 0;
for {
n, err := io.read(s.r, s.buf[s.end:len(s.buf)]);
if n < 0 || len(s.buf)-s.end < n {
set_err(s, .Bad_Read_Count);
break;
}
s.end += n;
if err != nil {
set_err(s, err);
break;
}
if n > 0 {
s.successive_empty_token_count = 0;
break;
}
loop += 1;
if s.max_consecutive_empty_reads <= 0 {
s.max_consecutive_empty_reads = DEFAULT_MAX_CONSECUTIVE_EMPTY_READS;
}
if loop > s.max_consecutive_empty_reads {
if could_be_too_short {
set_err(s, .Too_Short);
} else {
set_err(s, .No_Progress);
}
break;
}
}
}
}
scan_bytes :: proc(data: []byte, at_eof: bool) -> (advance: int, token: []byte, err: Scanner_Error, final_token: bool) {
if at_eof && len(data) == 0 {
return;
}
return 1, data[0:1], nil, false;
}
scan_runes :: proc(data: []byte, at_eof: bool) -> (advance: int, token: []byte, err: Scanner_Error, final_token: bool) {
if at_eof && len(data) == 0 {
return;
}
if data[0] < utf8.RUNE_SELF {
advance = 1;
token = data[0:1];
return;
}
_, width := utf8.decode_rune(data);
if width > 1 {
advance = width;
token = data[0:width];
return;
}
if !at_eof && !utf8.full_rune(data) {
return;
}
@thread_local ERROR_RUNE := []byte{0xef, 0xbf, 0xbd};
advance = 1;
token = ERROR_RUNE;
return;
}
scan_words :: proc(data: []byte, at_eof: bool) -> (advance: int, token: []byte, err: Scanner_Error, final_token: bool) {
is_space :: proc "contextless" (r: rune) -> bool {
switch r {
// lower ones
case ' ', '\t', '\n', '\v', '\f', '\r':
return true;
case '\u0085', '\u00a0':
return true;
// higher ones
case '\u2000' ..= '\u200a':
return true;
case '\u1680', '\u2028', '\u2029', '\u202f', '\u205f', '\u3000':
return true;
}
return false;
}
// skip spaces at the beginning
start := 0;
for width := 0; start < len(data); start += width {
r: rune;
r, width = utf8.decode_rune(data[start:]);
if !is_space(r) {
break;
}
}
for width, i := 0, start; i < len(data); i += width {
r: rune;
r, width = utf8.decode_rune(data[i:]);
if is_space(r) {
advance = i+width;
token = data[start:i];
return;
}
}
if at_eof && len(data) > start {
advance = len(data);
token = data[start:];
return;
}
advance = start;
return;
}
scan_lines :: proc(data: []byte, at_eof: bool) -> (advance: int, token: []byte, err: Scanner_Error, final_token: bool) {
trim_carriage_return :: proc "contextless" (data: []byte) -> []byte {
if len(data) > 0 && data[len(data)-1] == '\r' {
return data[0:len(data)-1];
}
return data;
}
if at_eof && len(data) == 0 {
return;
}
if i := bytes.index_byte(data, '\n'); i >= 0 {
advance = i+1;
token = trim_carriage_return(data[0:i]);
return;
}
if at_eof {
advance = len(data);
token = trim_carriage_return(data);
}
return;
}
+259
View File
@@ -0,0 +1,259 @@
package bufio
import "core:io"
import "core:mem"
import "core:unicode/utf8"
// import "core:bytes"
// Writer is a buffered wrapper for an io.Writer
Writer :: struct {
buf: []byte,
buf_allocator: mem.Allocator,
wr: io.Writer,
n: int,
err: io.Error,
max_consecutive_empty_writes: int,
}
writer_init :: proc(b: ^Writer, wr: io.Writer, size: int = DEFAULT_BUF_SIZE, allocator := context.allocator) {
size := size;
size = max(size, MIN_READ_BUFFER_SIZE);
writer_reset(b, wr);
b.buf_allocator = allocator;
b.buf = make([]byte, size, allocator);
}
writer_init_with_buf :: proc(b: ^Writer, wr: io.Writer, buf: []byte) {
writer_reset(b, wr);
b.buf_allocator = {};
b.buf = buf;
}
// writer_destroy destroys the underlying buffer with its associated allocator IFF that allocator has been set
writer_destroy :: proc(b: ^Writer) {
delete(b.buf, b.buf_allocator);
b^ = {};
}
// writer_size returns the size of underlying buffer in bytes
writer_size :: proc(b: ^Writer) -> int {
return len(b.buf);
}
writer_reset :: proc(b: ^Writer, w: io.Writer) {
b.wr = w;
b.n = 0;
b.err = nil;
}
// writer_flush writes any buffered data into the underlying io.Writer
writer_flush :: proc(b: ^Writer) -> io.Error {
if b.err != nil {
return b.err;
}
if b.n == 0 {
return nil;
}
n, err := io.write(b.wr, b.buf[0:b.n]);
if n < b.n && err == nil {
err = .Short_Write;
}
if err != nil {
if n > 0 && n < b.n {
copy(b.buf[:b.n-n], b.buf[n : b.n]);
}
b.n -= n;
b.err = err;
return err;
}
b.n = 0;
return nil;
}
// writer_available returns how many bytes are unused in the buffer
writer_available :: proc(b: ^Writer) -> int {
return len(b.buf) - b.n;
}
// writer_buffered returns the number of bytes that have been writted into the current buffer
writer_buffered :: proc(b: ^Writer) -> int {
return b.n;
}
// writer_write writes the contents of p into the buffer
// It returns the number of bytes written
// If n < len(p), it will return an error explaining why the write is short
writer_write :: proc(b: ^Writer, p: []byte) -> (n: int, err: io.Error) {
p := p;
for len(p) > writer_available(b) && b.err == nil {
m: int;
if writer_buffered(b) == 0 {
m, b.err = io.write(b.wr, p);
} else {
m = copy(b.buf[b.n:], p);
b.n += m;
writer_flush(b);
}
n += m;
p = p[m:];
}
if b.err != nil {
return n, b.err;
}
m := copy(b.buf[b.n:], p);
b.n += m;
m += n;
return m, nil;
}
// writer_write_byte writes a single byte
writer_write_byte :: proc(b: ^Writer, c: byte) -> io.Error {
if b.err != nil {
return b.err;
}
if writer_available(b) <= 0 && writer_flush(b) != nil {
return b.err;
}
b.buf[b.n] = c;
b.n += 1;
return nil;
}
// writer_write_rune writes a single unicode code point, and returns the number of bytes written with any error
writer_write_rune :: proc(b: ^Writer, r: rune) -> (size: int, err: io.Error) {
if r < utf8.RUNE_SELF {
err = writer_write_byte(b, byte(r));
size = 0 if err != nil else 1;
return;
}
if b.err != nil {
return 0, b.err;
}
buf: [4]u8;
n := writer_available(b);
if n < utf8.UTF_MAX {
writer_flush(b);
if b.err != nil {
return 0, b.err;
}
n = writer_available(b);
if n < utf8.UTF_MAX {
// this only happens if the buffer is very small
w: int;
buf, w = utf8.encode_rune(r);
return writer_write(b, buf[:w]);
}
}
buf, size = utf8.encode_rune(r);
copy(b.buf[b.n:], buf[:size]);
b.n += size;
return;
}
// writer_write writes a string into the buffer
// It returns the number of bytes written
// If n < len(p), it will return an error explaining why the write is short
writer_write_string :: proc(b: ^Writer, s: string) -> (int, io.Error) {
return writer_write(b, transmute([]byte)s);
}
// writer_read_from is to support io.Reader_From types
// If the underlying writer supports the io,read_from, and b has no buffered data yet,
// this procedure calls the underlying read_from implementation without buffering
writer_read_from :: proc(b: ^Writer, r: io.Reader) -> (n: i64, err: io.Error) {
if b.err != nil {
return 0, b.err;
}
if writer_buffered(b) == 0 {
if w, ok := io.to_reader_from(b.wr); !ok {
n, err = io.read_from(w, r);
b.err = err;
return;
}
}
for {
if writer_available(b) == 0 {
writer_flush(b) or_return;
}
if b.max_consecutive_empty_writes <= 0 {
b.max_consecutive_empty_writes = DEFAULT_MAX_CONSECUTIVE_EMPTY_READS;
}
m: int;
nr := 0;
for nr < b.max_consecutive_empty_writes {
m, err = io.read(r, b.buf[b.n:]);
if m != 0 || err != nil {
break;
}
nr += 1;
}
if nr == b.max_consecutive_empty_writes {
return n, .No_Progress;
}
b.n += m;
n += i64(m);
if err != nil {
break;
}
}
if err == .EOF {
if writer_available(b) == 0 {
err = writer_flush(b);
} else {
err = nil;
}
}
return;
}
// writer_to_stream converts a Writer into an io.Stream
writer_to_stream :: proc(b: ^Writer) -> (s: io.Stream) {
s.stream_data = b;
s.stream_vtable = _writer_vtable;
return;
}
@(private)
_writer_vtable := &io.Stream_VTable{
impl_destroy = proc(s: io.Stream) -> io.Error {
b := (^Writer)(s.stream_data);
writer_destroy(b);
return nil;
},
impl_flush = proc(s: io.Stream) -> io.Error {
b := (^Writer)(s.stream_data);
return writer_flush(b);
},
impl_write = proc(s: io.Stream, p: []byte) -> (n: int, err: io.Error) {
b := (^Writer)(s.stream_data);
return writer_write(b, p);
},
impl_write_byte = proc(s: io.Stream, c: byte) -> io.Error {
b := (^Writer)(s.stream_data);
return writer_write_byte(b, c);
},
impl_write_rune = proc(s: io.Stream, r: rune) -> (int, io.Error) {
b := (^Writer)(s.stream_data);
return writer_write_rune(b, r);
},
impl_read_from = proc(s: io.Stream, r: io.Reader) -> (n: i64, err: io.Error) {
b := (^Writer)(s.stream_data);
return writer_read_from(b, r);
},
};
+15
View File
@@ -43,6 +43,7 @@ complex32 :: complex32;
complex64 :: complex64;
complex128 :: complex128;
quaternion64 :: quaternion64;
quaternion128 :: quaternion128;
quaternion256 :: quaternion256;
@@ -76,6 +77,17 @@ u64be :: u64be;
i128be :: i128be;
u128be :: u128be;
f16le :: f16le;
f32le :: f32le;
f64le :: f64le;
f16be :: f16be;
f32be :: f32be;
f64be :: f64be;
// Procedures
len :: proc(array: Array_Type) -> int ---
cap :: proc(array: Array_Type) -> int ---
@@ -103,3 +115,6 @@ min :: proc(values: ..T) -> T ---
max :: proc(values: ..T) -> T ---
abs :: proc(value: T) -> T ---
clamp :: proc(value, minimum, maximum: T) -> T ---
soa_zip :: proc(slices: ...) -> #soa[]Struct ---
soa_unzip :: proc(value: $S/#soa[]$E) -> (slices: ...) ---
+433
View File
@@ -0,0 +1,433 @@
package bytes
import "core:io"
import "core:unicode/utf8"
MIN_READ :: 512;
@(private)
SMALL_BUFFER_SIZE :: 64;
// A Buffer is a variable-sized buffer of bytes with a io.Stream interface
// The zero value for Buffer is an empty buffer ready to use.
Buffer :: struct {
buf: [dynamic]byte,
off: int,
last_read: Read_Op,
}
@(private)
Read_Op :: enum i8 {
Read = -1,
Invalid = 0,
Read_Rune1 = 1,
Read_Rune2 = 2,
Read_Rune3 = 3,
Read_Rune4 = 4,
}
buffer_init :: proc(b: ^Buffer, buf: []byte) {
resize(&b.buf, len(buf));
copy(b.buf[:], buf);
}
buffer_init_string :: proc(b: ^Buffer, s: string) {
resize(&b.buf, len(s));
copy(b.buf[:], s);
}
buffer_init_allocator :: proc(b: ^Buffer, len, cap: int, allocator := context.allocator) {
b.buf.allocator = allocator;
reserve(&b.buf, cap);
resize(&b.buf, len);
}
buffer_destroy :: proc(b: ^Buffer) {
delete(b.buf);
buffer_reset(b);
}
buffer_to_bytes :: proc(b: ^Buffer) -> []byte {
return b.buf[b.off:];
}
buffer_to_string :: proc(b: ^Buffer) -> string {
if b == nil {
return "<nil>";
}
return string(b.buf[b.off:]);
}
buffer_is_empty :: proc(b: ^Buffer) -> bool {
return len(b.buf) <= b.off;
}
buffer_length :: proc(b: ^Buffer) -> int {
return len(b.buf) - b.off;
}
buffer_capacity :: proc(b: ^Buffer) -> int {
return cap(b.buf);
}
buffer_reset :: proc(b: ^Buffer) {
clear(&b.buf);
b.off = 0;
b.last_read = .Invalid;
}
buffer_truncate :: proc(b: ^Buffer, n: int) {
if n == 0 {
buffer_reset(b);
return;
}
b.last_read = .Invalid;
if n < 0 || n > buffer_length(b) {
panic("bytes.truncate: truncation out of range");
}
resize(&b.buf, b.off+n);
}
@(private)
_buffer_try_grow :: proc(b: ^Buffer, n: int) -> (int, bool) {
if l := len(b.buf); n <= cap(b.buf)-l {
resize(&b.buf, l+n);
return l, true;
}
return 0, false;
}
@(private)
_buffer_grow :: proc(b: ^Buffer, n: int) -> int {
m := buffer_length(b);
if m == 0 && b.off != 0 {
buffer_reset(b);
}
if i, ok := _buffer_try_grow(b, n); ok {
return i;
}
if b.buf == nil && n <= SMALL_BUFFER_SIZE {
b.buf = make([dynamic]byte, n, SMALL_BUFFER_SIZE);
return 0;
}
c := cap(b.buf);
if n <= c/2 - m {
copy(b.buf[:], b.buf[b.off:]);
} else if c > max(int) - c - n {
panic("bytes.Buffer: too large");
} else {
resize(&b.buf, 2*c + n);
copy(b.buf[:], b.buf[b.off:]);
}
b.off = 0;
resize(&b.buf, m+n);
return m;
}
buffer_grow :: proc(b: ^Buffer, n: int) {
if n < 0 {
panic("bytes.buffer_grow: negative count");
}
m := _buffer_grow(b, n);
resize(&b.buf, m);
}
buffer_write_at :: proc(b: ^Buffer, p: []byte, offset: int) -> (n: int, err: io.Error) {
b.last_read = .Invalid;
if offset < 0 {
err = .Invalid_Offset;
return;
}
_, ok := _buffer_try_grow(b, offset+len(p));
if !ok {
_ = _buffer_grow(b, offset+len(p));
}
if len(b.buf) <= offset {
return 0, .Short_Write;
}
return copy(b.buf[offset:], p), nil;
}
buffer_write :: proc(b: ^Buffer, p: []byte) -> (n: int, err: io.Error) {
b.last_read = .Invalid;
m, ok := _buffer_try_grow(b, len(p));
if !ok {
m = _buffer_grow(b, len(p));
}
return copy(b.buf[m:], p), nil;
}
buffer_write_string :: proc(b: ^Buffer, s: string) -> (n: int, err: io.Error) {
b.last_read = .Invalid;
m, ok := _buffer_try_grow(b, len(s));
if !ok {
m = _buffer_grow(b, len(s));
}
return copy(b.buf[m:], s), nil;
}
buffer_write_byte :: proc(b: ^Buffer, c: byte) -> io.Error {
b.last_read = .Invalid;
m, ok := _buffer_try_grow(b, 1);
if !ok {
m = _buffer_grow(b, 1);
}
b.buf[m] = c;
return nil;
}
buffer_write_rune :: proc(b: ^Buffer, r: rune) -> (n: int, err: io.Error) {
if r < utf8.RUNE_SELF {
buffer_write_byte(b, byte(r));
return 1, nil;
}
b.last_read = .Invalid;
m, ok := _buffer_try_grow(b, utf8.UTF_MAX);
if !ok {
m = _buffer_grow(b, utf8.UTF_MAX);
}
res: [4]byte;
res, n = utf8.encode_rune(r);
copy(b.buf[m:][:utf8.UTF_MAX], res[:n]);
resize(&b.buf, m+n);
return;
}
buffer_next :: proc(b: ^Buffer, n: int) -> []byte {
n := n;
b.last_read = .Invalid;
m := buffer_length(b);
if n > m {
n = m;
}
data := b.buf[b.off : b.off + n];
b.off += n;
if n > 0 {
b.last_read = .Read;
}
return data;
}
buffer_read :: proc(b: ^Buffer, p: []byte) -> (n: int, err: io.Error) {
b.last_read = .Invalid;
if buffer_is_empty(b) {
buffer_reset(b);
if len(p) == 0 {
return 0, nil;
}
return 0, .EOF;
}
n = copy(p, b.buf[b.off:]);
b.off += n;
if n > 0 {
b.last_read = .Read;
}
return;
}
buffer_read_at :: proc(b: ^Buffer, p: []byte, offset: int) -> (n: int, err: io.Error) {
b.last_read = .Invalid;
if offset < 0 || offset >= len(b.buf) {
err = .Invalid_Offset;
return;
}
if 0 <= offset && offset < len(b.buf) {
n = copy(p, b.buf[offset:]);
}
if n > 0 {
b.last_read = .Read;
}
return;
}
buffer_read_byte :: proc(b: ^Buffer) -> (byte, io.Error) {
if buffer_is_empty(b) {
buffer_reset(b);
return 0, .EOF;
}
c := b.buf[b.off];
b.off += 1;
b.last_read = .Read;
return c, nil;
}
buffer_read_rune :: proc(b: ^Buffer) -> (r: rune, size: int, err: io.Error) {
if buffer_is_empty(b) {
buffer_reset(b);
return 0, 0, .EOF;
}
c := b.buf[b.off];
if c < utf8.RUNE_SELF {
b.off += 1;
b.last_read = .Read_Rune1;
return rune(c), 1, nil;
}
r, size = utf8.decode_rune(b.buf[b.off:]);
b.off += size;
b.last_read = Read_Op(i8(size));
return;
}
buffer_unread_byte :: proc(b: ^Buffer) -> io.Error {
if b.last_read == .Invalid {
return .Invalid_Unread;
}
b.last_read = .Invalid;
if b.off > 0 {
b.off -= 1;
}
return nil;
}
buffer_unread_rune :: proc(b: ^Buffer) -> io.Error {
if b.last_read <= .Invalid {
return .Invalid_Unread;
}
if b.off >= int(b.last_read) {
b.off -= int(i8(b.last_read));
}
b.last_read = .Invalid;
return nil;
}
buffer_read_bytes :: proc(b: ^Buffer, delim: byte) -> (line: []byte, err: io.Error) {
i := index_byte(b.buf[b.off:], delim);
end := b.off + i + 1;
if i < 0 {
end = len(b.buf);
err = .EOF;
}
line = b.buf[b.off:end];
b.off = end;
b.last_read = .Read;
return;
}
buffer_read_string :: proc(b: ^Buffer, delim: byte) -> (line: string, err: io.Error) {
slice: []byte;
slice, err = buffer_read_bytes(b, delim);
return string(slice), err;
}
buffer_write_to :: proc(b: ^Buffer, w: io.Writer) -> (n: i64, err: io.Error) {
b.last_read = .Invalid;
if byte_count := buffer_length(b); byte_count > 0 {
m, e := io.write(w, b.buf[b.off:]);
if m > byte_count {
panic("bytes.buffer_write_to: invalid io.write count");
}
b.off += m;
n = i64(m);
if e != nil {
err = e;
return;
}
if m != byte_count {
err = .Short_Write;
return;
}
}
buffer_reset(b);
return;
}
buffer_read_from :: proc(b: ^Buffer, r: io.Reader) -> (n: i64, err: io.Error) #no_bounds_check {
b.last_read = .Invalid;
for {
i := _buffer_grow(b, MIN_READ);
resize(&b.buf, i);
m, e := io.read(r, b.buf[i:cap(b.buf)]);
if m < 0 {
err = .Negative_Read;
return;
}
resize(&b.buf, i+m);
n += i64(m);
if e == .EOF {
return;
}
if e != nil {
err = e;
return;
}
}
return;
}
buffer_to_stream :: proc(b: ^Buffer) -> (s: io.Stream) {
s.stream_data = b;
s.stream_vtable = _buffer_vtable;
return;
}
@(private)
_buffer_vtable := &io.Stream_VTable{
impl_size = proc(s: io.Stream) -> i64 {
b := (^Buffer)(s.stream_data);
return i64(buffer_capacity(b));
},
impl_read = proc(s: io.Stream, p: []byte) -> (n: int, err: io.Error) {
b := (^Buffer)(s.stream_data);
return buffer_read(b, p);
},
impl_read_at = proc(s: io.Stream, p: []byte, offset: i64) -> (n: int, err: io.Error) {
b := (^Buffer)(s.stream_data);
return buffer_read_at(b, p, int(offset));
},
impl_read_byte = proc(s: io.Stream) -> (byte, io.Error) {
b := (^Buffer)(s.stream_data);
return buffer_read_byte(b);
},
impl_read_rune = proc(s: io.Stream) -> (r: rune, size: int, err: io.Error) {
b := (^Buffer)(s.stream_data);
return buffer_read_rune(b);
},
impl_write = proc(s: io.Stream, p: []byte) -> (n: int, err: io.Error) {
b := (^Buffer)(s.stream_data);
return buffer_write(b, p);
},
impl_write_at = proc(s: io.Stream, p: []byte, offset: i64) -> (n: int, err: io.Error) {
b := (^Buffer)(s.stream_data);
return buffer_write_at(b, p, int(offset));
},
impl_write_byte = proc(s: io.Stream, c: byte) -> io.Error {
b := (^Buffer)(s.stream_data);
return buffer_write_byte(b, c);
},
impl_write_rune = proc(s: io.Stream, r: rune) -> (int, io.Error) {
b := (^Buffer)(s.stream_data);
return buffer_write_rune(b, r);
},
impl_unread_byte = proc(s: io.Stream) -> io.Error {
b := (^Buffer)(s.stream_data);
return buffer_unread_byte(b);
},
impl_unread_rune = proc(s: io.Stream) -> io.Error {
b := (^Buffer)(s.stream_data);
return buffer_unread_rune(b);
},
impl_destroy = proc(s: io.Stream) -> io.Error {
b := (^Buffer)(s.stream_data);
buffer_destroy(b);
return nil;
},
impl_write_to = proc(s: io.Stream, w: io.Writer) -> (n: i64, err: io.Error) {
b := (^Buffer)(s.stream_data);
return buffer_write_to(b, w);
},
impl_read_from = proc(s: io.Stream, r: io.Reader) -> (n: i64, err: io.Error) {
b := (^Buffer)(s.stream_data);
return buffer_read_from(b, r);
},
};
File diff suppressed because it is too large Load Diff
+177
View File
@@ -0,0 +1,177 @@
package bytes
import "core:io"
import "core:unicode/utf8"
Reader :: struct {
s: []byte, // read-only buffer
i: i64, // current reading index
prev_rune: int, // previous reading index of rune or < 0
}
reader_init :: proc(r: ^Reader, s: []byte) {
r.s = s;
r.i = 0;
r.prev_rune = -1;
}
reader_to_stream :: proc(r: ^Reader) -> (s: io.Stream) {
s.stream_data = r;
s.stream_vtable = _reader_vtable;
return;
}
reader_length :: proc(r: ^Reader) -> int {
if r.i >= i64(len(r.s)) {
return 0;
}
return int(i64(len(r.s)) - r.i);
}
reader_size :: proc(r: ^Reader) -> i64 {
return i64(len(r.s));
}
reader_read :: proc(r: ^Reader, p: []byte) -> (n: int, err: io.Error) {
if r.i >= i64(len(r.s)) {
return 0, .EOF;
}
r.prev_rune = -1;
n = copy(p, r.s[r.i:]);
r.i += i64(n);
return;
}
reader_read_at :: proc(r: ^Reader, p: []byte, off: i64) -> (n: int, err: io.Error) {
if off < 0 {
return 0, .Invalid_Offset;
}
if off >= i64(len(r.s)) {
return 0, .EOF;
}
n = copy(p, r.s[off:]);
if n < len(p) {
err = .EOF;
}
return;
}
reader_read_byte :: proc(r: ^Reader) -> (byte, io.Error) {
r.prev_rune = -1;
if r.i >= i64(len(r.s)) {
return 0, .EOF;
}
b := r.s[r.i];
r.i += 1;
return b, nil;
}
reader_unread_byte :: proc(r: ^Reader) -> io.Error {
if r.i <= 0 {
return .Invalid_Unread;
}
r.prev_rune = -1;
r.i -= 1;
return nil;
}
reader_read_rune :: proc(r: ^Reader) -> (ch: rune, size: int, err: io.Error) {
if r.i >= i64(len(r.s)) {
r.prev_rune = -1;
return 0, 0, .EOF;
}
r.prev_rune = int(r.i);
if c := r.s[r.i]; c < utf8.RUNE_SELF {
r.i += 1;
return rune(c), 1, nil;
}
ch, size = utf8.decode_rune(r.s[r.i:]);
r.i += i64(size);
return;
}
reader_unread_rune :: proc(r: ^Reader) -> io.Error {
if r.i <= 0 {
return .Invalid_Unread;
}
if r.prev_rune < 0 {
return .Invalid_Unread;
}
r.i = i64(r.prev_rune);
r.prev_rune = -1;
return nil;
}
reader_seek :: proc(r: ^Reader, offset: i64, whence: io.Seek_From) -> (i64, io.Error) {
r.prev_rune = -1;
abs: i64;
switch whence {
case .Start:
abs = offset;
case .Current:
abs = r.i + offset;
case .End:
abs = i64(len(r.s)) + offset;
case:
return 0, .Invalid_Whence;
}
if abs < 0 {
return 0, .Invalid_Offset;
}
r.i = abs;
return abs, nil;
}
reader_write_to :: proc(r: ^Reader, w: io.Writer) -> (n: i64, err: io.Error) {
r.prev_rune = -1;
if r.i >= i64(len(r.s)) {
return 0, nil;
}
s := r.s[r.i:];
m: int;
m, err = io.write(w, s);
if m > len(s) {
panic("bytes.Reader.write_to: invalid io.write_string count");
}
r.i += i64(m);
n = i64(m);
if m != len(s) && err == nil {
err = .Short_Write;
}
return;
}
@(private)
_reader_vtable := &io.Stream_VTable{
impl_size = proc(s: io.Stream) -> i64 {
r := (^Reader)(s.stream_data);
return reader_size(r);
},
impl_read = proc(s: io.Stream, p: []byte) -> (n: int, err: io.Error) {
r := (^Reader)(s.stream_data);
return reader_read(r, p);
},
impl_read_at = proc(s: io.Stream, p: []byte, off: i64) -> (n: int, err: io.Error) {
r := (^Reader)(s.stream_data);
return reader_read_at(r, p, off);
},
impl_read_byte = proc(s: io.Stream) -> (byte, io.Error) {
r := (^Reader)(s.stream_data);
return reader_read_byte(r);
},
impl_unread_byte = proc(s: io.Stream) -> io.Error {
r := (^Reader)(s.stream_data);
return reader_unread_byte(r);
},
impl_read_rune = proc(s: io.Stream) -> (ch: rune, size: int, err: io.Error) {
r := (^Reader)(s.stream_data);
return reader_read_rune(r);
},
impl_unread_rune = proc(s: io.Stream) -> io.Error {
r := (^Reader)(s.stream_data);
return reader_unread_rune(r);
},
impl_seek = proc(s: io.Stream, offset: i64, whence: io.Seek_From) -> (i64, io.Error) {
r := (^Reader)(s.stream_data);
return reader_seek(r, offset, whence);
},
impl_write_to = proc(s: io.Stream, w: io.Writer) -> (n: i64, err: io.Error) {
r := (^Reader)(s.stream_data);
return reader_write_to(r, w);
},
};
+3 -3
View File
@@ -14,8 +14,8 @@ ushort :: b.u16;
int :: b.i32;
uint :: b.u32;
long :: (ODIN_OS == "windows" || size_of(b.rawptr) == 4) ? b.i32 : b.i64;
ulong :: (ODIN_OS == "windows" || size_of(b.rawptr) == 4) ? b.u32 : b.u64;
long :: b.i32 when (ODIN_OS == "windows" || size_of(b.rawptr) == 4) else b.i64;
ulong :: b.u32 when (ODIN_OS == "windows" || size_of(b.rawptr) == 4) else b.u64;
longlong :: b.i64;
ulonglong :: b.u64;
@@ -32,4 +32,4 @@ ptrdiff_t :: b.int;
uintptr_t :: b.uintptr;
intptr_t :: b.int;
wchar_t :: (ODIN_OS == "windows") ? b.u16 : b.u32;
wchar_t :: b.u16 when (ODIN_OS == "windows") else b.u32;
@@ -0,0 +1,25 @@
package c_frontend_preprocess
import "core:c/frontend/tokenizer"
const_expr :: proc(rest: ^^Token, tok: ^Token) -> i64 {
// TODO(bill): Handle const_expr correctly
// This is effectively a mini-parser
assert(rest != nil);
assert(tok != nil);
rest^ = tokenizer.new_eof(tok);
switch v in tok.val {
case i64:
return v;
case f64:
return i64(v);
case string:
return 0;
case []u16:
// TODO
case []u32:
// TODO
}
return 0;
}
File diff suppressed because it is too large Load Diff
+154
View File
@@ -0,0 +1,154 @@
package c_frontend_preprocess
import "core:unicode/utf8"
unquote_char :: proc(str: string, quote: byte) -> (r: rune, multiple_bytes: bool, tail_string: string, success: bool) {
hex_to_int :: proc(c: byte) -> int {
switch c {
case '0'..='9': return int(c-'0');
case 'a'..='f': return int(c-'a')+10;
case 'A'..='F': return int(c-'A')+10;
}
return -1;
}
w: int;
if str[0] == quote && quote == '"' {
return;
} else if str[0] >= 0x80 {
r, w = utf8.decode_rune_in_string(str);
return r, true, str[w:], true;
} else if str[0] != '\\' {
return rune(str[0]), false, str[1:], true;
}
if len(str) <= 1 {
return;
}
s := str;
c := s[1];
s = s[2:];
switch c {
case: r = rune(c);
case 'a': r = '\a';
case 'b': r = '\b';
case 'e': r = '\e';
case 'f': r = '\f';
case 'n': r = '\n';
case 'r': r = '\r';
case 't': r = '\t';
case 'v': r = '\v';
case '\\': r = '\\';
case '"': r = '"';
case '\'': r = '\'';
case '0'..='7':
v := int(c-'0');
if len(s) < 2 {
return;
}
for i in 0..<len(s) {
d := int(s[i]-'0');
if d < 0 || d > 7 {
return;
}
v = (v<<3) | d;
}
s = s[2:];
if v > 0xff {
return;
}
r = rune(v);
case 'x', 'u', 'U':
count: int;
switch c {
case 'x': count = 2;
case 'u': count = 4;
case 'U': count = 8;
}
if len(s) < count {
return;
}
for i in 0..<count {
d := hex_to_int(s[i]);
if d < 0 {
return;
}
r = (r<<4) | rune(d);
}
s = s[count:];
if c == 'x' {
break;
}
if r > utf8.MAX_RUNE {
return;
}
multiple_bytes = true;
}
success = true;
tail_string = s;
return;
}
unquote_string :: proc(lit: string, allocator := context.allocator) -> (res: string, allocated, success: bool) {
contains_rune :: proc(s: string, r: rune) -> int {
for c, offset in s {
if c == r {
return offset;
}
}
return -1;
}
assert(len(lit) >= 2);
s := lit;
quote := '"';
if s == `""` {
return "", false, true;
}
if contains_rune(s, '\n') >= 0 {
return s, false, false;
}
if contains_rune(s, '\\') < 0 && contains_rune(s, quote) < 0 {
if quote == '"' {
return s, false, true;
}
}
s = s[1:len(s)-1];
buf_len := 3*len(s) / 2;
buf := make([]byte, buf_len, allocator);
offset := 0;
for len(s) > 0 {
r, multiple_bytes, tail_string, ok := unquote_char(s, byte(quote));
if !ok {
delete(buf);
return s, false, false;
}
s = tail_string;
if r < 0x80 || !multiple_bytes {
buf[offset] = byte(r);
offset += 1;
} else {
b, w := utf8.encode_rune(r);
copy(buf[offset:], b[:w]);
offset += w;
}
}
new_string := string(buf[:offset]);
return new_string, true, true;
}
+34
View File
@@ -0,0 +1,34 @@
/*
package demo
import tokenizer "core:c/frontend/tokenizer"
import preprocessor "core:c/frontend/preprocessor"
import "core:fmt"
main :: proc() {
t := &tokenizer.Tokenizer{};
tokenizer.init_defaults(t);
cpp := &preprocessor.Preprocessor{};
cpp.warn, cpp.err = t.warn, t.err;
preprocessor.init_lookup_tables(cpp);
preprocessor.init_default_macros(cpp);
cpp.include_paths = {"my/path/to/include"};
tok := tokenizer.tokenize_file(t, "the/source/file.c", 1);
tok = preprocessor.preprocess(cpp, tok);
if tok != nil {
for t := tok; t.kind != .EOF; t = t.next {
fmt.println(t.lit);
}
}
fmt.println("[Done]");
}
*/
package c_frontend_tokenizer
+68
View File
@@ -0,0 +1,68 @@
package c_frontend_tokenizer
// NOTE(bill): This is a really dumb approach for a hide set,
// but it's really simple and probably fast enough in practice
Hide_Set :: struct {
next: ^Hide_Set,
name: string,
}
new_hide_set :: proc(name: string) -> ^Hide_Set {
hs := new(Hide_Set);
hs.name = name;
return hs;
}
hide_set_contains :: proc(hs: ^Hide_Set, name: string) -> bool {
for h := hs; h != nil; h = h.next {
if h.name == name {
return true;
}
}
return false;
}
hide_set_union :: proc(a, b: ^Hide_Set) -> ^Hide_Set {
head: Hide_Set;
curr := &head;
for h := a; h != nil; h = h.next {
curr.next = new_hide_set(h.name);
curr = curr.next;
}
curr.next = b;
return head.next;
}
hide_set_intersection :: proc(a, b: ^Hide_Set) -> ^Hide_Set {
head: Hide_Set;
curr := &head;
for h := a; h != nil; h = h.next {
if hide_set_contains(b, h.name) {
curr.next = new_hide_set(h.name);
curr = curr.next;
}
}
return head.next;
}
add_hide_set :: proc(tok: ^Token, hs: ^Hide_Set) -> ^Token {
head: Token;
curr := &head;
tok := tok;
for ; tok != nil; tok = tok.next {
t := copy_token(tok);
t.hide_set = hide_set_union(t.hide_set, hs);
curr.next = t;
curr = curr.next;
}
return head.next;
}
+169
View File
@@ -0,0 +1,169 @@
package c_frontend_tokenizer
Pos :: struct {
file: string,
line: int,
column: int,
offset: int,
}
Token_Kind :: enum {
Invalid,
Ident,
Punct,
Keyword,
Char,
String,
Number,
PP_Number,
Comment,
EOF,
}
File :: struct {
name: string,
id: int,
src: []byte,
display_name: string,
line_delta: int,
}
Token_Type_Hint :: enum u8 {
None,
Int,
Long,
Long_Long,
Unsigned_Int,
Unsigned_Long,
Unsigned_Long_Long,
Float,
Double,
Long_Double,
UTF_8,
UTF_16,
UTF_32,
UTF_Wide,
}
Token_Value :: union {
i64,
f64,
string,
[]u16,
[]u32,
}
Token :: struct {
kind: Token_Kind,
next: ^Token,
lit: string,
pos: Pos,
file: ^File,
line_delta: int,
at_bol: bool,
has_space: bool,
type_hint: Token_Type_Hint,
val: Token_Value,
prefix: string,
// Preprocessor values
hide_set: ^Hide_Set,
origin: ^Token,
}
Is_Keyword_Proc :: #type proc(tok: ^Token) -> bool;
copy_token :: proc(tok: ^Token) -> ^Token {
t := new_clone(tok^);
t.next = nil;
return t;
}
new_eof :: proc(tok: ^Token) -> ^Token {
t := new_clone(tok^);
t.kind = .EOF;
t.lit = "";
return t;
}
default_is_keyword :: proc(tok: ^Token) -> bool {
if tok.kind == .Keyword {
return true;
}
if len(tok.lit) > 0 {
return default_keyword_set[tok.lit];
}
return false;
}
token_name := [Token_Kind]string {
.Invalid = "invalid",
.Ident = "ident",
.Punct = "punct",
.Keyword = "keyword",
.Char = "char",
.String = "string",
.Number = "number",
.PP_Number = "preprocessor number",
.Comment = "comment",
.EOF = "eof",
};
default_keyword_set := map[string]bool{
"auto" = true,
"break" = true,
"case" = true,
"char" = true,
"const" = true,
"continue" = true,
"default" = true,
"do" = true,
"double" = true,
"else" = true,
"enum" = true,
"extern" = true,
"float" = true,
"for" = true,
"goto" = true,
"if" = true,
"int" = true,
"long" = true,
"register" = true,
"restrict" = true,
"return" = true,
"short" = true,
"signed" = true,
"sizeof" = true,
"static" = true,
"struct" = true,
"switch" = true,
"typedef" = true,
"union" = true,
"unsigned" = true,
"void" = true,
"volatile" = true,
"while" = true,
"_Alignas" = true,
"_Alignof" = true,
"_Atomic" = true,
"_Bool" = true,
"_Generic" = true,
"_Noreturn" = true,
"_Thread_local" = true,
"__restrict" = true,
"typeof" = true,
"asm" = true,
"__restrict__" = true,
"__thread" = true,
"__attribute__" = true,
};
+667
View File
@@ -0,0 +1,667 @@
package c_frontend_tokenizer
import "core:fmt"
import "core:os"
import "core:strings"
import "core:unicode/utf8"
Error_Handler :: #type proc(pos: Pos, fmt: string, args: ..any);
Tokenizer :: struct {
// Immutable data
path: string,
src: []byte,
// Tokenizing state
ch: rune,
offset: int,
read_offset: int,
line_offset: int,
line_count: int,
// Extra information for tokens
at_bol: bool,
has_space: bool,
// Mutable data
err: Error_Handler,
warn: Error_Handler,
error_count: int,
warning_count: int,
}
init_defaults :: proc(t: ^Tokenizer, err: Error_Handler = default_error_handler, warn: Error_Handler = default_warn_handler) {
t.err = err;
t.warn = warn;
}
@(private)
offset_to_pos :: proc(t: ^Tokenizer, offset: int) -> (pos: Pos) {
pos.file = t.path;
pos.offset = offset;
pos.line = t.line_count;
pos.column = offset - t.line_offset + 1;
return;
}
default_error_handler :: proc(pos: Pos, msg: string, args: ..any) {
fmt.eprintf("%s(%d:%d) ", pos.file, pos.line, pos.column);
fmt.eprintf(msg, ..args);
fmt.eprintf("\n");
}
default_warn_handler :: proc(pos: Pos, msg: string, args: ..any) {
fmt.eprintf("%s(%d:%d) warning: ", pos.file, pos.line, pos.column);
fmt.eprintf(msg, ..args);
fmt.eprintf("\n");
}
error_offset :: proc(t: ^Tokenizer, offset: int, msg: string, args: ..any) {
pos := offset_to_pos(t, offset);
if t.err != nil {
t.err(pos, msg, ..args);
}
t.error_count += 1;
}
warn_offset :: proc(t: ^Tokenizer, offset: int, msg: string, args: ..any) {
pos := offset_to_pos(t, offset);
if t.warn != nil {
t.warn(pos, msg, ..args);
}
t.warning_count += 1;
}
error :: proc(t: ^Tokenizer, tok: ^Token, msg: string, args: ..any) {
pos := tok.pos;
if t.err != nil {
t.err(pos, msg, ..args);
}
t.error_count += 1;
}
warn :: proc(t: ^Tokenizer, tok: ^Token, msg: string, args: ..any) {
pos := tok.pos;
if t.warn != nil {
t.warn(pos, msg, ..args);
}
t.warning_count += 1;
}
advance_rune :: proc(t: ^Tokenizer) {
if t.read_offset < len(t.src) {
t.offset = t.read_offset;
if t.ch == '\n' {
t.at_bol = true;
t.line_offset = t.offset;
t.line_count += 1;
}
r, w := rune(t.src[t.read_offset]), 1;
switch {
case r == 0:
error_offset(t, t.offset, "illegal character NUL");
case r >= utf8.RUNE_SELF:
r, w = utf8.decode_rune(t.src[t.read_offset:]);
if r == utf8.RUNE_ERROR && w == 1 {
error_offset(t, t.offset, "illegal UTF-8 encoding");
} else if r == utf8.RUNE_BOM && t.offset > 0 {
error_offset(t, t.offset, "illegal byte order mark");
}
}
t.read_offset += w;
t.ch = r;
} else {
t.offset = len(t.src);
if t.ch == '\n' {
t.at_bol = true;
t.line_offset = t.offset;
t.line_count += 1;
}
t.ch = -1;
}
}
advance_rune_n :: proc(t: ^Tokenizer, n: int) {
for in 0..<n {
advance_rune(t);
}
}
is_digit :: proc(r: rune) -> bool {
return '0' <= r && r <= '9';
}
skip_whitespace :: proc(t: ^Tokenizer) {
for {
switch t.ch {
case ' ', '\t', '\r', '\v', '\f', '\n':
t.has_space = true;
advance_rune(t);
case:
return;
}
}
}
scan_comment :: proc(t: ^Tokenizer) -> string {
offset := t.offset-1;
next := -1;
general: {
if t.ch == '/'{ // line comments
advance_rune(t);
for t.ch != '\n' && t.ch >= 0 {
advance_rune(t);
}
next = t.offset;
if t.ch == '\n' {
next += 1;
}
break general;
}
/* style comment */
advance_rune(t);
for t.ch >= 0 {
ch := t.ch;
advance_rune(t);
if ch == '*' && t.ch == '/' {
advance_rune(t);
next = t.offset;
break general;
}
}
error_offset(t, offset, "comment not terminated");
}
lit := t.src[offset : t.offset];
// NOTE(bill): Strip CR for line comments
for len(lit) > 2 && lit[1] == '/' && lit[len(lit)-1] == '\r' {
lit = lit[:len(lit)-1];
}
return string(lit);
}
scan_identifier :: proc(t: ^Tokenizer) -> string {
offset := t.offset;
for is_ident1(t.ch) {
advance_rune(t);
}
return string(t.src[offset : t.offset]);
}
scan_string :: proc(t: ^Tokenizer) -> string {
offset := t.offset-1;
for {
ch := t.ch;
if ch == '\n' || ch < 0 {
error_offset(t, offset, "string literal was not terminated");
break;
}
advance_rune(t);
if ch == '"' {
break;
}
if ch == '\\' {
scan_escape(t);
}
}
return string(t.src[offset : t.offset]);
}
digit_val :: proc(r: rune) -> int {
switch r {
case '0'..='9':
return int(r-'0');
case 'A'..='F':
return int(r-'A' + 10);
case 'a'..='f':
return int(r-'a' + 10);
}
return 16;
}
scan_escape :: proc(t: ^Tokenizer) -> bool {
offset := t.offset;
esc := t.ch;
n: int;
base, max: u32;
switch esc {
case 'a', 'b', 'e', 'f', 'n', 't', 'v', 'r', '\\', '\'', '"':
advance_rune(t);
return true;
case '0'..='7':
for digit_val(t.ch) < 8 {
advance_rune(t);
}
return true;
case 'x':
advance_rune(t);
for digit_val(t.ch) < 16 {
advance_rune(t);
}
return true;
case 'u':
advance_rune(t);
n, base, max = 4, 16, utf8.MAX_RUNE;
case 'U':
advance_rune(t);
n, base, max = 8, 16, utf8.MAX_RUNE;
case:
if t.ch < 0 {
error_offset(t, offset, "escape sequence was not terminated");
} else {
break;
}
return false;
}
x: u32;
main_loop: for n > 0 {
d := u32(digit_val(t.ch));
if d >= base {
if t.ch == '"' || t.ch == '\'' {
break main_loop;
}
if t.ch < 0 {
error_offset(t, t.offset, "escape sequence was not terminated");
} else {
error_offset(t, t.offset, "illegal character '%r' : %d in escape sequence", t.ch, t.ch);
}
return false;
}
x = x*base + d;
advance_rune(t);
n -= 1;
}
if x > max || 0xd800 <= x && x <= 0xe000 {
error_offset(t, offset, "escape sequence is an invalid Unicode code point");
return false;
}
return true;
}
scan_rune :: proc(t: ^Tokenizer) -> string {
offset := t.offset-1;
valid := true;
n := 0;
for {
ch := t.ch;
if ch == '\n' || ch < 0 {
if valid {
error_offset(t, offset, "rune literal not terminated");
valid = false;
}
break;
}
advance_rune(t);
if ch == '\'' {
break;
}
n += 1;
if ch == '\\' {
if !scan_escape(t) {
valid = false;
}
}
}
if valid && n != 1 {
error_offset(t, offset, "illegal rune literal");
}
return string(t.src[offset : t.offset]);
}
scan_number :: proc(t: ^Tokenizer, seen_decimal_point: bool) -> (Token_Kind, string) {
scan_mantissa :: proc(t: ^Tokenizer, base: int) {
for digit_val(t.ch) < base {
advance_rune(t);
}
}
scan_exponent :: proc(t: ^Tokenizer) {
if t.ch == 'e' || t.ch == 'E' || t.ch == 'p' || t.ch == 'P' {
advance_rune(t);
if t.ch == '-' || t.ch == '+' {
advance_rune(t);
}
if digit_val(t.ch) < 10 {
scan_mantissa(t, 10);
} else {
error_offset(t, t.offset, "illegal floating-point exponent");
}
}
}
scan_fraction :: proc(t: ^Tokenizer) -> (early_exit: bool) {
if t.ch == '.' && peek(t) == '.' {
return true;
}
if t.ch == '.' {
advance_rune(t);
scan_mantissa(t, 10);
}
return false;
}
check_end := true;
offset := t.offset;
seen_point := seen_decimal_point;
if seen_point {
offset -= 1;
scan_mantissa(t, 10);
scan_exponent(t);
} else {
if t.ch == '0' {
int_base :: proc(t: ^Tokenizer, base: int, msg: string) {
prev := t.offset;
advance_rune(t);
scan_mantissa(t, base);
if t.offset - prev <= 1 {
error_offset(t, t.offset, msg);
}
}
advance_rune(t);
switch t.ch {
case 'b', 'B':
int_base(t, 2, "illegal binary integer");
case 'x', 'X':
int_base(t, 16, "illegal hexadecimal integer");
case:
seen_point = false;
scan_mantissa(t, 10);
if t.ch == '.' {
seen_point = true;
if scan_fraction(t) {
check_end = false;
}
}
if check_end {
scan_exponent(t);
check_end = false;
}
}
}
}
if check_end {
scan_mantissa(t, 10);
if !scan_fraction(t) {
scan_exponent(t);
}
}
return .Number, string(t.src[offset : t.offset]);
}
scan_punct :: proc(t: ^Tokenizer, ch: rune) -> (kind: Token_Kind) {
kind = .Punct;
switch ch {
case:
kind = .Invalid;
case '<', '>':
if t.ch == ch {
advance_rune(t);
}
if t.ch == '=' {
advance_rune(t);
}
case '!', '+', '-', '*', '/', '%', '^', '=':
if t.ch == '=' {
advance_rune(t);
}
case '#':
if t.ch == '#' {
advance_rune(t);
}
case '&':
if t.ch == '=' || t.ch == '&' {
advance_rune(t);
}
case '|':
if t.ch == '=' || t.ch == '|' {
advance_rune(t);
}
case '(', ')', '[', ']', '{', '}':
// okay
case '~', ',', ':', ';', '?':
// okay
case '`':
// okay
case '.':
if t.ch == '.' && peek(t) == '.' {
advance_rune(t);
advance_rune(t); // consume last '.'
}
}
return;
}
peek :: proc(t: ^Tokenizer) -> byte {
if t.read_offset < len(t.src) {
return t.src[t.read_offset];
}
return 0;
}
peek_str :: proc(t: ^Tokenizer, str: string) -> bool {
if t.read_offset < len(t.src) {
return strings.has_prefix(string(t.src[t.offset:]), str);
}
return false;
}
scan_literal_prefix :: proc(t: ^Tokenizer, str: string, prefix: ^string) -> bool {
if peek_str(t, str) {
offset := t.offset;
for _ in str {
advance_rune(t);
}
prefix^ = string(t.src[offset:][:len(str)-1]);
return true;
}
return false;
}
allow_next_to_be_newline :: proc(t: ^Tokenizer) -> bool {
if t.ch == '\n' {
advance_rune(t);
return true;
} else if t.ch == '\r' && peek(t) == '\n' { // allow for MS-DOS style line endings
advance_rune(t); // \r
advance_rune(t); // \n
return true;
}
return false;
}
scan :: proc(t: ^Tokenizer, f: ^File) -> ^Token {
skip_whitespace(t);
offset := t.offset;
kind: Token_Kind;
lit: string;
prefix: string;
switch ch := t.ch; {
case scan_literal_prefix(t, `u8"`, &prefix):
kind = .String;
lit = scan_string(t);
case scan_literal_prefix(t, `u"`, &prefix):
kind = .String;
lit = scan_string(t);
case scan_literal_prefix(t, `L"`, &prefix):
kind = .String;
lit = scan_string(t);
case scan_literal_prefix(t, `U"`, &prefix):
kind = .String;
lit = scan_string(t);
case scan_literal_prefix(t, `u'`, &prefix):
kind = .Char;
lit = scan_rune(t);
case scan_literal_prefix(t, `L'`, &prefix):
kind = .Char;
lit = scan_rune(t);
case scan_literal_prefix(t, `U'`, &prefix):
kind = .Char;
lit = scan_rune(t);
case is_ident0(ch):
lit = scan_identifier(t);
kind = .Ident;
case '0' <= ch && ch <= '9':
kind, lit = scan_number(t, false);
case:
advance_rune(t);
switch ch {
case -1:
kind = .EOF;
case '\\':
kind = .Punct;
if allow_next_to_be_newline(t) {
t.at_bol = true;
t.has_space = false;
return scan(t, f);
}
case '.':
if is_digit(t.ch) {
kind, lit = scan_number(t, true);
} else {
kind = scan_punct(t, ch);
}
case '"':
kind = .String;
lit = scan_string(t);
case '\'':
kind = .Char;
lit = scan_rune(t);
case '/':
if t.ch == '/' || t.ch == '*' {
kind = .Comment;
lit = scan_comment(t);
t.has_space = true;
break;
}
fallthrough;
case:
kind = scan_punct(t, ch);
if kind == .Invalid && ch != utf8.RUNE_BOM {
error_offset(t, t.offset, "illegal character '%r': %d", ch, ch);
}
}
}
if lit == "" {
lit = string(t.src[offset : t.offset]);
}
if kind == .Comment {
return scan(t, f);
}
tok := new(Token);
tok.kind = kind;
tok.lit = lit;
tok.pos = offset_to_pos(t, offset);
tok.file = f;
tok.prefix = prefix;
tok.at_bol = t.at_bol;
tok.has_space = t.has_space;
t.at_bol, t.has_space = false, false;
return tok;
}
tokenize :: proc(t: ^Tokenizer, f: ^File) -> ^Token {
setup_tokenizer: {
t.src = f.src;
t.ch = ' ';
t.offset = 0;
t.read_offset = 0;
t.line_offset = 0;
t.line_count = len(t.src) > 0 ? 1 : 0;
t.error_count = 0;
t.path = f.name;
advance_rune(t);
if t.ch == utf8.RUNE_BOM {
advance_rune(t);
}
}
t.at_bol = true;
t.has_space = false;
head: Token;
curr := &head;
for {
tok := scan(t, f);
if tok == nil {
break;
}
curr.next = tok;
curr = curr.next;
if tok.kind == .EOF {
break;
}
}
return head.next;
}
add_new_file :: proc(t: ^Tokenizer, name: string, src: []byte, id: int) -> ^File {
file := new(File);
file.id = id;
file.src = src;
file.name = name;
file.display_name = name;
return file;
}
tokenize_file :: proc(t: ^Tokenizer, path: string, id: int, loc := #caller_location) -> ^Token {
src, ok := os.read_entire_file(path);
if !ok {
return nil;
}
return tokenize(t, add_new_file(t, path, src, id));
}
inline_tokenize :: proc(t: ^Tokenizer, tok: ^Token, src: []byte) -> ^Token {
file := new(File);
file.src = src;
if tok.file != nil {
file.id = tok.file.id;
file.name = tok.file.name;
file.display_name = tok.file.name;
}
return tokenize(t, file);
}
+116
View File
@@ -0,0 +1,116 @@
package c_frontend_tokenizer
in_range :: proc(range: []rune, c: rune) -> bool #no_bounds_check {
for i := 0; range[i] != -1; i += 2 {
if range[i] <= c && c <= range[i+1] {
return true;
}
}
return false;
}
// [https://www.sigbus.info/n1570#D] C11 allows ASCII and some multibyte characters in certan Unicode ranges to be used in an identifier.
//
// is_ident0 returns true if a given character is acceptable as the first character of an identifier.
is_ident0 :: proc(c: rune) -> bool {
return in_range(_range_ident0, c);
}
// is_ident0 returns true if a given character is acceptable as a non-first character of an identifier.
is_ident1 :: proc(c: rune) -> bool {
return is_ident0(c) || in_range(_range_ident1, c);
}
// Returns the number of columns needed to display a given character in a fixed-width font.
// Based on https://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c
char_width :: proc(c: rune) -> int {
switch {
case in_range(_range_width0, c):
return 0;
case in_range(_range_width2, c):
return 2;
}
return 1;
}
display_width :: proc(str: string) -> (w: int) {
for c in str {
w += char_width(c);
}
return;
}
_range_ident0 := []rune{
'_', '_', 'a', 'z', 'A', 'Z', '$', '$',
0x00A8, 0x00A8, 0x00AA, 0x00AA, 0x00AD, 0x00AD, 0x00AF, 0x00AF,
0x00B2, 0x00B5, 0x00B7, 0x00BA, 0x00BC, 0x00BE, 0x00C0, 0x00D6,
0x00D8, 0x00F6, 0x00F8, 0x00FF, 0x0100, 0x02FF, 0x0370, 0x167F,
0x1681, 0x180D, 0x180F, 0x1DBF, 0x1E00, 0x1FFF, 0x200B, 0x200D,
0x202A, 0x202E, 0x203F, 0x2040, 0x2054, 0x2054, 0x2060, 0x206F,
0x2070, 0x20CF, 0x2100, 0x218F, 0x2460, 0x24FF, 0x2776, 0x2793,
0x2C00, 0x2DFF, 0x2E80, 0x2FFF, 0x3004, 0x3007, 0x3021, 0x302F,
0x3031, 0x303F, 0x3040, 0xD7FF, 0xF900, 0xFD3D, 0xFD40, 0xFDCF,
0xFDF0, 0xFE1F, 0xFE30, 0xFE44, 0xFE47, 0xFFFD,
0x10000, 0x1FFFD, 0x20000, 0x2FFFD, 0x30000, 0x3FFFD, 0x40000, 0x4FFFD,
0x50000, 0x5FFFD, 0x60000, 0x6FFFD, 0x70000, 0x7FFFD, 0x80000, 0x8FFFD,
0x90000, 0x9FFFD, 0xA0000, 0xAFFFD, 0xB0000, 0xBFFFD, 0xC0000, 0xCFFFD,
0xD0000, 0xDFFFD, 0xE0000, 0xEFFFD,
-1,
};
_range_ident1 := []rune{
'0', '9', '$', '$', 0x0300, 0x036F, 0x1DC0, 0x1DFF, 0x20D0, 0x20FF, 0xFE20, 0xFE2F,
-1,
};
_range_width0 := []rune{
0x0000, 0x001F, 0x007f, 0x00a0, 0x0300, 0x036F, 0x0483, 0x0486,
0x0488, 0x0489, 0x0591, 0x05BD, 0x05BF, 0x05BF, 0x05C1, 0x05C2,
0x05C4, 0x05C5, 0x05C7, 0x05C7, 0x0600, 0x0603, 0x0610, 0x0615,
0x064B, 0x065E, 0x0670, 0x0670, 0x06D6, 0x06E4, 0x06E7, 0x06E8,
0x06EA, 0x06ED, 0x070F, 0x070F, 0x0711, 0x0711, 0x0730, 0x074A,
0x07A6, 0x07B0, 0x07EB, 0x07F3, 0x0901, 0x0902, 0x093C, 0x093C,
0x0941, 0x0948, 0x094D, 0x094D, 0x0951, 0x0954, 0x0962, 0x0963,
0x0981, 0x0981, 0x09BC, 0x09BC, 0x09C1, 0x09C4, 0x09CD, 0x09CD,
0x09E2, 0x09E3, 0x0A01, 0x0A02, 0x0A3C, 0x0A3C, 0x0A41, 0x0A42,
0x0A47, 0x0A48, 0x0A4B, 0x0A4D, 0x0A70, 0x0A71, 0x0A81, 0x0A82,
0x0ABC, 0x0ABC, 0x0AC1, 0x0AC5, 0x0AC7, 0x0AC8, 0x0ACD, 0x0ACD,
0x0AE2, 0x0AE3, 0x0B01, 0x0B01, 0x0B3C, 0x0B3C, 0x0B3F, 0x0B3F,
0x0B41, 0x0B43, 0x0B4D, 0x0B4D, 0x0B56, 0x0B56, 0x0B82, 0x0B82,
0x0BC0, 0x0BC0, 0x0BCD, 0x0BCD, 0x0C3E, 0x0C40, 0x0C46, 0x0C48,
0x0C4A, 0x0C4D, 0x0C55, 0x0C56, 0x0CBC, 0x0CBC, 0x0CBF, 0x0CBF,
0x0CC6, 0x0CC6, 0x0CCC, 0x0CCD, 0x0CE2, 0x0CE3, 0x0D41, 0x0D43,
0x0D4D, 0x0D4D, 0x0DCA, 0x0DCA, 0x0DD2, 0x0DD4, 0x0DD6, 0x0DD6,
0x0E31, 0x0E31, 0x0E34, 0x0E3A, 0x0E47, 0x0E4E, 0x0EB1, 0x0EB1,
0x0EB4, 0x0EB9, 0x0EBB, 0x0EBC, 0x0EC8, 0x0ECD, 0x0F18, 0x0F19,
0x0F35, 0x0F35, 0x0F37, 0x0F37, 0x0F39, 0x0F39, 0x0F71, 0x0F7E,
0x0F80, 0x0F84, 0x0F86, 0x0F87, 0x0F90, 0x0F97, 0x0F99, 0x0FBC,
0x0FC6, 0x0FC6, 0x102D, 0x1030, 0x1032, 0x1032, 0x1036, 0x1037,
0x1039, 0x1039, 0x1058, 0x1059, 0x1160, 0x11FF, 0x135F, 0x135F,
0x1712, 0x1714, 0x1732, 0x1734, 0x1752, 0x1753, 0x1772, 0x1773,
0x17B4, 0x17B5, 0x17B7, 0x17BD, 0x17C6, 0x17C6, 0x17C9, 0x17D3,
0x17DD, 0x17DD, 0x180B, 0x180D, 0x18A9, 0x18A9, 0x1920, 0x1922,
0x1927, 0x1928, 0x1932, 0x1932, 0x1939, 0x193B, 0x1A17, 0x1A18,
0x1B00, 0x1B03, 0x1B34, 0x1B34, 0x1B36, 0x1B3A, 0x1B3C, 0x1B3C,
0x1B42, 0x1B42, 0x1B6B, 0x1B73, 0x1DC0, 0x1DCA, 0x1DFE, 0x1DFF,
0x200B, 0x200F, 0x202A, 0x202E, 0x2060, 0x2063, 0x206A, 0x206F,
0x20D0, 0x20EF, 0x302A, 0x302F, 0x3099, 0x309A, 0xA806, 0xA806,
0xA80B, 0xA80B, 0xA825, 0xA826, 0xFB1E, 0xFB1E, 0xFE00, 0xFE0F,
0xFE20, 0xFE23, 0xFEFF, 0xFEFF, 0xFFF9, 0xFFFB, 0x10A01, 0x10A03,
0x10A05, 0x10A06, 0x10A0C, 0x10A0F, 0x10A38, 0x10A3A, 0x10A3F, 0x10A3F,
0x1D167, 0x1D169, 0x1D173, 0x1D182, 0x1D185, 0x1D18B, 0x1D1AA, 0x1D1AD,
0x1D242, 0x1D244, 0xE0001, 0xE0001, 0xE0020, 0xE007F, 0xE0100, 0xE01EF,
-1,
};
_range_width2 := []rune{
0x1100, 0x115F, 0x2329, 0x2329, 0x232A, 0x232A, 0x2E80, 0x303E,
0x3040, 0xA4CF, 0xAC00, 0xD7A3, 0xF900, 0xFAFF, 0xFE10, 0xFE19,
0xFE30, 0xFE6F, 0xFF00, 0xFF60, 0xFFE0, 0xFFE6, 0x1F000, 0x1F644,
0x20000, 0x2FFFD, 0x30000, 0x3FFFD,
-1,
};
+73
View File
@@ -0,0 +1,73 @@
# C support
The following is a mostly-complete projection of the C11 standard library as defined by the C11 specification: N1570, or ISO/IEC 9899:2011. Only the macros, types, and functions as required by the standard are projected. Extensions to C, such as POSIX are not handled by these bindings, this is otherwise portable to any implementation which can support a hosted C runtime.
## Support matrix
| Header | Status |
|:------------------|:---------------------------------------------------|
| `<assert.h>` | Not applicable, use Odin's `#assert` |
| `<complex.h>` | Mostly projected, see [limitations](#Limitations) |
| `<ctype.h>` | Fully projected |
| `<errno.h>` | Fully projected |
| `<fenv.h>` | Not projected |
| `<float.h>` | Not projected |
| `<inttypes.h>` | Fully projected |
| `<iso646.h>` | Not applicable, use Odin's operators |
| `<limits.h>` | Not projected |
| `<locale.h>` | Not projected |
| `<math.h>` | Mostly projected, see [limitations](#Limitations) |
| `<setjmp.h>` | Fully projected |
| `<signal.h>` | Fully projected |
| `<stdalign.h>` | Not applicable, use Odin's `#align` |
| `<stdarg.h>` | Mostly projected, see [limitations](#Limitations) |
| `<stdatomic.h>` | Fully projected |
| `<stdbool.h>` | Not applicable, use Odin's `b32` |
| `<stddef.h>` | Mostly projected, see [limitations](#Limitations) |
| `<stdint.h>` | Fully projected |
| `<stdio.h>` | Fully projected |
| `<stdlib.h>` | Fully projected |
| `<stdnoreturn.h>` | Not applicable, use Odin's divergent return `!` |
| `<string.h>` | Fully projected |
| `<tgmath.h>` | Mostly projected, see [limitations](#Limitations) |
| `<threads.h>` | Fully projected |
| `<time.h>` | Fully projected |
| `<uchar.h>` | Fully projected |
| `<wchar.h>` | Fully projected |
| `<wctype.h>` | Fully projected |
## Limitations
Not all C standard library functionality can be fully projected due to language differences. These limitations are listed here.
### `long double`
As Odin lacks a means to interact with `long double` in it's foreign interface, this projection effort does not bind or define anything requiring `long double` which is permitted by the C standard.
### `<complex.h>`
The special values `_Complex_I`, `_Imaginary_I` and the appropriate definition of `I` cannot be realized with the same type in Odin as it would be in C. The literal `1i` is tempting to use for these definitions but the semantics differ from C and would be confusing to use.
### `<math.h>`
The classification functions, e.g: `fpclassify` are required by C to be implemented as macros, meaning no implementation would expose functions in their library we could bind. Instead, we provide native Odin implementations with functionally equivalent semantics and behavior as the C ones. Unfortunately, since classification returns unspecified constant values this may be an ABI break where the value of those constants enter and exit native C code.
### `<stdarg.h>`
While Odin can interact with variable argument C functions through the use of the `#c_vararg` attribute within a foreign block, it's not actually possible to create procedures in Odin with bodies that have the same ABI as that of variable argument C functions, as a result `va_arg` is not projected.
### `<stddef.h>`
`offsetof` is not realizable in Odin, however you can use `offset_of` instead.
### `<tgmath.h>`
C has some strange promotion and type-coercion behavior for `<tgmath.h>` which isn't correctly handled by this projection, specifically involving the use of complex arithmetic and kernels. We do mostly support type-generic math through the use of Odin's explicit procedure overloading, however the semantic behavior of that doesn't match C and so literal expressions of complex type in C may not call the same underlying math kernel functions as they do in Odin through this projection.
## Caveats
In addition to limitations, there are some minor caveats you should be aware when using this projection.
* `errno()` is a function which returns `^int` rather than a macro.
* `MB_CUR_MAX()` is a function which return `size_t` rather than a macro.
* Currently only works on Windows (MSVCRT) and Linux (GLIBC or MUSL)
## License
Every file within this directory is made available under Odin's BSD-2 license
with the following copyright.
```
Copyright 2021 Dale Weiler <weilercdale@gmail.com>.
```
+82
View File
@@ -0,0 +1,82 @@
package libc
// 7.3 Complex arithmetic
when ODIN_OS == "windows" {
foreign import libc "system:libucrt.lib"
} else {
foreign import libc "system:c"
}
@(default_calling_convention="c")
foreign libc {
// 7.3.5 Trigonometric functions
cacos :: proc(z: complex_double) -> complex_double ---;
cacosf :: proc(z: complex_float) -> complex_float ---;
casin :: proc(z: complex_double) -> complex_double ---;
casinf :: proc(z: complex_float) -> complex_float ---;
catan :: proc(z: complex_double) -> complex_double ---;
catanf :: proc(z: complex_float) -> complex_float ---;
ccos :: proc(z: complex_double) -> complex_double ---;
ccosf :: proc(z: complex_float) -> complex_float ---;
csin :: proc(z: complex_double) -> complex_double ---;
csinf :: proc(z: complex_float) -> complex_float ---;
ctan :: proc(z: complex_double) -> complex_double ---;
ctanf :: proc(z: complex_float) -> complex_float ---;
// 7.3.6 Hyperbolic functions
cacosh :: proc(z: complex_double) -> complex_double ---;
cacoshf :: proc(z: complex_float) -> complex_float ---;
casinh :: proc(z: complex_double) -> complex_double ---;
casinhf :: proc(z: complex_float) -> complex_float ---;
catanh :: proc(z: complex_double) -> complex_double ---;
catanhf :: proc(z: complex_float) -> complex_float ---;
ccosh :: proc(z: complex_double) -> complex_double ---;
ccoshf :: proc(z: complex_float) -> complex_float ---;
csinh :: proc(z: complex_double) -> complex_double ---;
csinhf :: proc(z: complex_float) -> complex_float ---;
ctanh :: proc(z: complex_double) -> complex_double ---;
ctanhf :: proc(z: complex_float) -> complex_float ---;
// 7.3.7 Exponential and logarithmic functions
cexp :: proc(z: complex_double) -> complex_double ---;
cexpf :: proc(z: complex_float) -> complex_float ---;
clog :: proc(z: complex_double) -> complex_double ---;
clogf :: proc(z: complex_float) -> complex_float ---;
// 7.3.8 Power and absolute-value functions
cabs :: proc(z: complex_double) -> complex_double ---;
cabsf :: proc(z: complex_float) -> complex_float ---;
cpow :: proc(z: complex_double) -> complex_double ---;
cpowf :: proc(z: complex_float) -> complex_float ---;
csqrt :: proc(z: complex_double) -> complex_double ---;
csqrtf :: proc(z: complex_float) -> complex_float ---;
// 7.3.9 Manipulation functions
carg :: proc(z: complex_double) -> double ---;
cargf :: proc(z: complex_float) -> float ---;
cimag :: proc(z: complex_double) -> double ---;
cimagf :: proc(z: complex_float) -> float ---;
conj :: proc(z: complex_double) -> complex_double ---;
conjf :: proc(z: complex_float) -> complex_float ---;
cproj :: proc(z: complex_double) -> complex_double ---;
cprojf :: proc(z: complex_float) -> complex_float ---;
creal :: proc(z: complex_double) -> double ---;
crealf :: proc(z: complex_float) -> float ---;
}
import builtin "core:builtin"
complex_float :: distinct builtin.complex64;
complex_double :: distinct builtin.complex128;
// Cannot implement _Complex_I or _Imaginary_I in Odin, thus
// complex and imaginary cannot be implement either.
CMPLX :: #force_inline proc(x, y: double) -> complex_double {
return builtin.complex(x, y);
}
CMPLXF :: #force_inline proc(x, y: float) -> complex_float {
return builtin.complex(x, y);
}
+30
View File
@@ -0,0 +1,30 @@
package libc
when ODIN_OS == "windows" {
foreign import libc "system:libucrt.lib"
} else {
foreign import libc "system:c"
}
// 7.4 Character handling
@(default_calling_convention="c")
foreign libc {
// 7.4.1 Character classification functions
isalnum :: proc(c: int) -> int ---;
isalpha :: proc(c: int) -> int ---;
isblank :: proc(c: int) -> int ---;
iscntrl :: proc(c: int) -> int ---;
isdigit :: proc(c: int) -> int ---;
isgraph :: proc(c: int) -> int ---;
islower :: proc(c: int) -> int ---;
isprint :: proc(c: int) -> int ---;
ispunct :: proc(c: int) -> int ---;
isspace :: proc(c: int) -> int ---;
isupper :: proc(c: int) -> int ---;
isxdigit :: proc(c: int) -> int ---;
// 7.4.2 Character case mapping functions
tolower :: proc(c: int) -> int ---;
toupper :: proc(c: int) -> int ---;
}
+47
View File
@@ -0,0 +1,47 @@
package libc
// 7.5 Errors
when ODIN_OS == "windows" {
foreign import libc "system:libucrt.lib"
} else {
foreign import libc "system:c"
}
// C11 standard only requires the definition of:
// EDOM,
// EILSEQ
// ERANGE
when ODIN_OS == "linux" || ODIN_OS == "freebsd" {
@(private="file")
@(default_calling_convention="c")
foreign libc {
@(link_name="__libc_errno_location")
_get_errno :: proc() -> ^int ---;
}
EDOM :: 33;
EILSEQ :: 84;
ERANGE :: 34;
}
when ODIN_OS == "windows" {
@(private="file")
@(default_calling_convention="c")
foreign libc {
@(link_name="_errno")
_get_errno :: proc() -> ^int ---;
}
EDOM :: 33;
EILSEQ :: 42;
ERANGE :: 34;
}
// Odin has no way to make an identifier "errno" behave as a function call to
// read the value, or to produce an lvalue such that you can assign a different
// error value to errno. To work around this, just expose it as a function like
// it actually is.
errno :: #force_inline proc() -> ^int {
return _get_errno();
}
+400
View File
@@ -0,0 +1,400 @@
package libc
// 7.12 Mathematics
import "core:intrinsics"
when ODIN_OS == "windows" {
foreign import libc "system:libucrt.lib"
} else {
foreign import libc "system:c"
}
// To support C's tgmath behavior we use Odin's explicit procedure overloading,
// but we cannot use the same names as exported by libc so use @(link_name)
// and keep them as private symbols of name "libc_"
@(private="file")
@(default_calling_convention="c")
foreign libc {
// 7.12.4 Trigonometric functions
@(link_name="acos") libc_acos :: proc(x: double) -> double ---;
@(link_name="acosf") libc_acosf :: proc(x: float) -> float ---;
@(link_name="asin") libc_asin :: proc(x: double) -> double ---;
@(link_name="asinf") libc_asinf :: proc(x: float) -> float ---;
@(link_name="atan") libc_atan :: proc(x: double) -> double ---;
@(link_name="atanf") libc_atanf :: proc(x: float) -> float ---;
@(link_name="atan2") libc_atan2 :: proc(y: double, x: double) -> double ---;
@(link_name="atan2f") libc_atan2f :: proc(y: float, x: float) -> float ---;
@(link_name="cos") libc_cos :: proc(x: double) -> double ---;
@(link_name="cosf") libc_cosf :: proc(x: float) -> float ---;
@(link_name="sin") libc_sin :: proc(x: double) -> double ---;
@(link_name="sinf") libc_sinf :: proc(x: float) -> float ---;
@(link_name="tan") libc_tan :: proc(x: double) -> double ---;
@(link_name="tanf") libc_tanf :: proc(x: float) -> float ---;
// 7.12.5 Hyperbolic functions
@(link_name="acosh") libc_acosh :: proc(x: double) -> double ---;
@(link_name="acoshf") libc_acoshf :: proc(x: float) -> float ---;
@(link_name="asinh") libc_asinh :: proc(x: double) -> double ---;
@(link_name="asinhf") libc_asinhf :: proc(x: float) -> float ---;
@(link_name="atanh") libc_atanh :: proc(x: double) -> double ---;
@(link_name="atanhf") libc_atanhf :: proc(x: float) -> float ---;
@(link_name="cosh") libc_cosh :: proc(x: double) -> double ---;
@(link_name="coshf") libc_coshf :: proc(x: float) -> float ---;
@(link_name="sinh") libc_sinh :: proc(x: double) -> double ---;
@(link_name="sinhf") libc_sinhf :: proc(x: float) -> float ---;
@(link_name="tanh") libc_tanh :: proc(x: double) -> double ---;
@(link_name="tanhf") libc_tanhf :: proc(x: float) -> float ---;
// 7.12.6 Exponential and logarithmic functions
@(link_name="exp") libc_exp :: proc(x: double) -> double ---;
@(link_name="expf") libc_expf :: proc(x: float) -> float ---;
@(link_name="exp2") libc_exp2 :: proc(x: double) -> double ---;
@(link_name="exp2f") libc_exp2f :: proc(x: float) -> float ---;
@(link_name="expm1") libc_expm1 :: proc(x: double) -> double ---;
@(link_name="expm1f") libc_expm1f :: proc(x: float) -> float ---;
@(link_name="frexp") libc_frexp :: proc(value: double, exp: ^int) -> double ---;
@(link_name="frexpf") libc_frexpf :: proc(value: float, exp: ^int) -> float ---;
@(link_name="ilogb") libc_ilogb :: proc(x: double) -> int ---;
@(link_name="ilogbf") libc_ilogbf :: proc(x: float) -> int ---;
@(link_name="ldexp") libc_ldexp :: proc(x: double, exp: int) -> double ---;
@(link_name="ldexpf") libc_ldexpf :: proc(x: float, exp: int) -> float ---;
@(link_name="log") libc_log :: proc(x: double) -> double ---;
@(link_name="logf") libc_logf :: proc(x: float) -> float ---;
@(link_name="log10") libc_log10 :: proc(x: double) -> double ---;
@(link_name="log10f") libc_log10f :: proc(x: float) -> float ---;
@(link_name="log1p") libc_log1p :: proc(x: double) -> double ---;
@(link_name="log1pf") libc_log1pf :: proc(x: float) -> float ---;
@(link_name="log2") libc_log2 :: proc(x: double) -> double ---;
@(link_name="log2f") libc_log2f :: proc(x: float) -> float ---;
@(link_name="logb") libc_logb :: proc(x: double) -> double ---;
@(link_name="logbf") libc_logbf :: proc(x: float) -> float ---;
@(link_name="modf") libc_modf :: proc(value: double, iptr: ^double) -> double ---;
@(link_name="modff") libc_modff :: proc(value: float, iptr: ^float) -> float ---;
@(link_name="scalbn") libc_scalbn :: proc(x: double, n: int) -> double ---;
@(link_name="scalbnf") libc_scalbnf :: proc(x: float, n: int) -> float ---;
@(link_name="scalbln") libc_scalbln :: proc(x: double, n: long) -> double ---;
@(link_name="scalblnf") libc_scalblnf :: proc(x: float, n: long) -> float ---;
// 7.12.7 Power and absolute-value functions
@(link_name="cbrt") libc_cbrt :: proc(x: double) -> double ---;
@(link_name="cbrtf") libc_cbrtf :: proc(x: float) -> float ---;
@(link_name="fabs") libc_fabs :: proc(x: double) -> double ---;
@(link_name="fabsf") libc_fabsf :: proc(x: float) -> float ---;
@(link_name="hypot") libc_hypot :: proc(x: double, y: double) -> double ---;
@(link_name="hypotf") libc_hypotf :: proc(x: float, y: float) -> float ---;
@(link_name="pow") libc_pow :: proc(x: double, y: double) -> double ---;
@(link_name="powf") libc_powf :: proc(x: float, y: float) -> float ---;
@(link_name="sqrt") libc_sqrt :: proc(x: double) -> double ---;
@(link_name="sqrtf") libc_sqrtf :: proc(x: float) -> float ---;
// 7.12.8 Error and gamma functions
@(link_name="erf") libc_erf :: proc(x: double) -> double ---;
@(link_name="erff") libc_erff :: proc(x: float) -> float ---;
@(link_name="erfc") libc_erfc :: proc(x: double) -> double ---;
@(link_name="erfcf") libc_erfcf :: proc(x: float) -> float ---;
@(link_name="lgamma") libc_lgamma :: proc(x: double) -> double ---;
@(link_name="lgammaf") libc_lgammaf :: proc(x: float) -> float ---;
@(link_name="tgamma") libc_tgamma :: proc(x: double) -> double ---;
@(link_name="tgammaf") libc_tgammaf :: proc(x: float) -> float ---;
// 7.12.9 Nearest integer functions
@(link_name="ceil") libc_ceil :: proc(x: double) -> double ---;
@(link_name="ceilf") libc_ceilf :: proc(x: float) -> float ---;
@(link_name="floor") libc_floor :: proc(x: double) -> double ---;
@(link_name="floorf") libc_floorf :: proc(x: float) -> float ---;
@(link_name="nearbyint") libc_nearbyint :: proc(x: double) -> double ---;
@(link_name="nearbyintf") libc_nearbyintf :: proc(x: float) -> float ---;
@(link_name="rint") libc_rint :: proc(x: double) -> double ---;
@(link_name="rintf") libc_rintf :: proc(x: float) -> float ---;
@(link_name="lrint") libc_lrint :: proc(x: double) -> long ---;
@(link_name="lrintf") libc_lrintf :: proc(x: float) -> long ---;
@(link_name="llrint") libc_llrint :: proc(x: double) -> longlong ---;
@(link_name="llrintf") libc_llrintf :: proc(x: float) -> longlong ---;
@(link_name="round") libc_round :: proc(x: double) -> double ---;
@(link_name="roundf") libc_roundf :: proc(x: float) -> float ---;
@(link_name="lround") libc_lround :: proc(x: double) -> long ---;
@(link_name="lroundf") libc_lroundf :: proc(x: float) -> long ---;
@(link_name="llround") libc_llround :: proc(x: double) -> longlong ---;
@(link_name="llroundf") libc_llroundf :: proc(x: float) -> longlong ---;
@(link_name="trunc") libc_trunc :: proc(x: double) -> double ---;
@(link_name="truncf") libc_truncf :: proc(x: float) -> float ---;
// 7.12.10 Remainder functions
@(link_name="fmod") libc_fmod :: proc(x: double, y: double) -> double ---;
@(link_name="fmodf") libc_fmodf :: proc(x: float, y: float) -> float ---;
@(link_name="remainder") libc_remainder :: proc(x: double, y: double) -> double ---;
@(link_name="remainderf") libc_remainderf :: proc(x: float, y: float) -> float ---;
@(link_name="remquo") libc_remquo :: proc(x: double, y: double, quo: ^int) -> double ---;
@(link_name="remquof") libc_remquof :: proc(x: float, y: float, quo: ^int) -> float ---;
// 7.12.11 Manipulation functions
@(link_name="copysign") libc_copysign :: proc(x: double, y: double) -> double ---;
@(link_name="copysignf") libc_copysignf :: proc(x: float, y: float) -> float ---;
@(link_name="nan") libc_nan :: proc(tagp: cstring) -> double ---;
@(link_name="nanf") libc_nanf :: proc(tagp: cstring) -> float ---;
@(link_name="nextafter") libc_nextafter :: proc(x: double, y: double) -> double ---;
@(link_name="nextafterf") libc_nextafterf :: proc(x: float, y: float) -> float ---;
// 7.12.12 Maximum, minimum, and positive difference functions
@(link_name="fdim") libc_fdim :: proc(x: double, y: double) -> double ---;
@(link_name="fdimf") libc_fdimf :: proc(x: float, y: float) -> float ---;
@(link_name="fmax") libc_fmax :: proc(x: double, y: double) -> double ---;
@(link_name="fmaxf") libc_fmaxf :: proc(x: float, y: float) -> float ---;
@(link_name="fmin") libc_fmin :: proc(x: double, y: double) -> double ---;
@(link_name="fminf") libc_fminf :: proc(x: float, y: float) -> float ---;
@(link_name="fma") libc_fma :: proc(x, y, z: double) -> double ---;
@(link_name="fmaf") libc_fmaf :: proc(x, y, z: float) -> float ---;
}
@(private="file")
_nan_bit_pattern := ~u64(0);
// On amd64 Windows and Linux, float_t and double_t are respectively both
// their usual types. On x86 it's not possible to define these types correctly
// since they would be long double which Odin does have support for.
float_t :: float;
double_t :: double;
NAN := transmute(double)(_nan_bit_pattern);
INFINITY :: 1e5000;
HUGE_VALF :: INFINITY;
HUGE_VAL :: double(INFINITY);
MATH_ERRNO :: 1;
MATH_ERREXCEPT :: 2;
math_errhandling :: 2; // Windows, Linux, macOS all use this mode.
FP_ILOGBNAN :: -1 - int((~uint(0)) >> 1);
FP_ILOGB0 :: FP_ILOGBNAN;
// Number classification constants. These do not have to match libc since we
// implement our own classification functions as libc requires they be macros,
// which means libc does not export standard functions for them.
FP_NAN :: 0;
FP_INFINITE :: 1;
FP_ZERO :: 2;
FP_NORMAL :: 3;
FP_SUBNORMAL :: 4;
@(private)
_fpclassify :: #force_inline proc(x: double) -> int {
u := transmute(uint64_t)x;
e := u >> 52 & 0x7ff;
if e == 0 do return FP_SUBNORMAL if (u << 1) != 0 else FP_ZERO;
if e == 0x7ff do return FP_NAN if (u << 12) != 0 else FP_INFINITE;
return FP_NORMAL;
}
@(private)
_fpclassifyf :: #force_inline proc(x: float) -> int {
u := transmute(uint32_t)x;
e := u >> 23 & 0xff;
if e == 0 do return FP_SUBNORMAL if (u << 1) != 0 else FP_ZERO;
if e == 0xff do return FP_NAN if (u << 9) != 0 else FP_INFINITE;
return FP_NORMAL;
}
@(private)
_signbit :: #force_inline proc(x: double) -> int {
return int(transmute(uint64_t)x >> 63);
}
@(private)
_signbitf :: #force_inline proc(x: float) -> int {
return int(transmute(uint32_t)x >> 31);
}
isfinite :: #force_inline proc(x: $T) where intrinsics.type_is_float(T) {
return fpclassify(x) == FP_INFINITE;
}
isinf :: #force_inline proc(x: $T) where intrinsics.type_is_float(T) {
return fpclassify(x) > FP_INFINITE;
}
isnan :: #force_inline proc(x: $T) where intrinsics.type_is_float(T) {
return fpclassify(x) == FP_NAN;
}
isnormal :: #force_inline proc(x: $T) where intrinsics.type_is_float(T) {
return fpclassify(x) == FP_NORMAL;
}
// These are special in that they avoid float exceptions. They cannot just be
// implemented as the relational comparisons, as that would produce an invalid
// "sticky" state that propagates and affects maths results. These need
// to be implemented natively in Odin assuming isunordered to prevent that.
isgreater :: #force_inline proc(x, y: $T) where intrinsics.type_is_float(T) {
return !isunordered(x, y) && x > y;
}
isgreaterequal :: #force_inline proc(x, y: $T) where intrinsics.type_is_float(T) {
return !isunordered(x, y) && x >= y;
}
isless :: #force_inline proc(x, y: $T) where intrinsics.type_is_float(T) {
return !isunordered(x, y) && x < y;
}
islessequal :: #force_inline proc(x, y: $T) where intrinsics.type_is_float(T) {
return !isunordered(x, y) && x <= y;
}
islessgreater :: #force_inline proc(x, y: $T) where intrinsics.type_is_float(T) {
return !isunordered(x, y) && x <= y;
}
isunordered :: #force_inline proc(x, y: $T) where intrinsics.type_is_float(T) {
if isnan(x) {
// Force evaluation of y to propagate exceptions for ordering semantics.
// To ensure correct semantics of IEEE 754 this cannot be compiled away.
sink: T;
intrinsics.volatile_store(&sink, intrinsics.volatile_load(&y));
return true;
}
return isnan(y);
}
fpclassify :: proc{_fpclassify, _fpclassifyf};
signbit :: proc{_signbit, _signbitf};
// Emulate tgmath.h behavior with explicit procedure overloading here.
acos :: proc{libc_acos, libc_acosf, cacos, cacosf};
asin :: proc{libc_asin, libc_asinf, casin, casinf};
atan :: proc{libc_atan, libc_atanf, catan, catanf};
atan2 :: proc{libc_atan2, libc_atan2f};
cos :: proc{libc_cos, libc_cosf, ccos, ccosf};
sin :: proc{libc_sin, libc_sinf, csin, csinf};
tan :: proc{libc_tan, libc_tanf, ctan, ctanf};
acosh :: proc{libc_acosh, libc_acoshf, cacosh, cacoshf};
asinh :: proc{libc_asinh, libc_asinhf, casinh, casinhf};
atanh :: proc{libc_atanh, libc_atanhf, catanh, catanhf};
cosh :: proc{libc_cosh, libc_coshf, ccosh, ccoshf};
sinh :: proc{libc_sinh, libc_sinhf, csinh, csinhf};
tanh :: proc{libc_tanh, libc_tanhf, ctanh, ctanhf};
exp :: proc{libc_exp, libc_expf, cexp, cexpf};
exp2 :: proc{libc_exp2, libc_exp2f};
expm1 :: proc{libc_expm1, libc_expm1f};
frexp :: proc{libc_frexp, libc_frexpf};
ilogb :: proc{libc_ilogb, libc_ilogbf};
ldexp :: proc{libc_ldexp, libc_ldexpf};
log :: proc{libc_log, libc_logf, clog, clogf};
log10 :: proc{libc_log10, libc_log10f};
log1p :: proc{libc_log1p, libc_log1pf};
log2 :: proc{libc_log2, libc_log2f};
logb :: proc{libc_logb, libc_logbf};
modf :: proc{libc_modf, libc_modff};
scalbn :: proc{libc_scalbn, libc_scalbnf};
scalbln :: proc{libc_scalbln, libc_scalblnf};
cbrt :: proc{libc_cbrt, libc_cbrtf};
fabs :: proc{libc_fabs, libc_fabsf, cabs, cabsf};
hypot :: proc{libc_hypot, libc_hypotf};
pow :: proc{libc_pow, libc_powf, cpow, cpowf};
sqrt :: proc{libc_sqrt, libc_sqrtf, csqrt, csqrtf};
erf :: proc{libc_erf, libc_erff};
erfc :: proc{libc_erfc, libc_erfcf};
lgamma :: proc{libc_lgamma, libc_lgammaf};
tgamma :: proc{libc_tgamma, libc_tgammaf};
ceil :: proc{libc_ceil, libc_ceilf};
floor :: proc{libc_floor, libc_floorf};
nearbyint :: proc{libc_nearbyint, libc_nearbyintf};
rint :: proc{libc_rint, libc_rintf};
lrint :: proc{libc_lrint, libc_lrintf};
llrint :: proc{libc_llrint, libc_llrintf};
round :: proc{libc_round, libc_roundf};
lround :: proc{libc_lround, libc_lroundf};
llround :: proc{libc_llround, libc_llroundf};
trunc :: proc{libc_trunc, libc_truncf};
fmod :: proc{libc_fmod, libc_fmodf};
remainder :: proc{libc_remainder, libc_remainderf};
remquo :: proc{libc_remquo, libc_remquof};
copysign :: proc{libc_copysign, libc_copysignf};
nextafter :: proc{libc_nextafter, libc_nextafterf};
fdim :: proc{libc_fdim, libc_fdimf};
fmax :: proc{libc_fmax, libc_fmaxf};
fmin :: proc{libc_fmin, libc_fminf};
fma :: proc{libc_fma, libc_fmaf};
// But retain the 'f' suffix-variant functions as well so they can be used,
// a trick is used here where we use explicit procedrual overloading of one
// procedure. This is done because the foreign block is marked @(private) and
// aliasing functions does not remove privateness from the entity.
acosf :: proc{libc_acosf};
asinf :: proc{libc_asinf};
atanf :: proc{libc_atanf};
atan2f :: proc{libc_atan2f};
cosf :: proc{libc_cosf};
sinf :: proc{libc_sinf};
tanf :: proc{libc_tanf};
acoshf :: proc{libc_acoshf};
asinhf :: proc{libc_asinhf};
atanhf :: proc{libc_atanhf};
coshf :: proc{libc_coshf};
sinhf :: proc{libc_sinhf};
tanhf :: proc{libc_tanhf};
expf :: proc{libc_expf};
exp2f :: proc{libc_exp2f};
expm1f :: proc{libc_expm1f};
frexpf :: proc{libc_frexpf};
ilogbf :: proc{libc_ilogbf};
ldexpf :: proc{libc_ldexpf};
logf :: proc{libc_logf};
log10f :: proc{libc_log10f};
log1pf :: proc{libc_log1pf};
log2f :: proc{libc_log2f};
logbf :: proc{libc_logbf};
modff :: proc{libc_modff};
scalbnf :: proc{libc_scalbnf};
scalblnf :: proc{libc_scalblnf};
cbrtf :: proc{libc_cbrtf};
fabsf :: proc{libc_fabsf};
hypotf :: proc{libc_hypotf};
powf :: proc{libc_powf};
sqrtf :: proc{libc_sqrtf};
erff :: proc{libc_erff};
erfcf :: proc{libc_erfcf};
lgammaf :: proc{libc_lgammaf};
tgammaf :: proc{libc_tgammaf};
ceilf :: proc{libc_ceilf};
floorf :: proc{libc_floorf};
nearbyintf :: proc{libc_nearbyintf};
rintf :: proc{libc_rintf};
lrintf :: proc{libc_lrintf};
llrintf :: proc{libc_llrintf};
roundf :: proc{libc_roundf};
lroundf :: proc{libc_lroundf};
llroundf :: proc{libc_llroundf};
truncf :: proc{libc_truncf};
fmodf :: proc{libc_fmodf};
remainderf :: proc{libc_remainderf};
remquof :: proc{libc_remquof};
copysignf :: proc{libc_copysignf};
nextafterf :: proc{libc_nextafterf};
fdimf :: proc{libc_fdimf};
fmaxf :: proc{libc_fmaxf};
fminf :: proc{libc_fminf};
fmaf :: proc{libc_fmaf};
// These two functions are special and not made type generic in tgmath.h since
// they only differ by their return type.
nan :: proc{libc_nan};
nanf :: proc{libc_nanf};
+65
View File
@@ -0,0 +1,65 @@
package libc
// 7.13 Nonlocal jumps
when ODIN_OS == "windows" {
foreign import libc "system:libucrt.lib"
} else {
foreign import libc "system:c"
}
when ODIN_OS == "windows" {
@(default_calling_convention="c")
foreign libc {
// 7.13.1 Save calling environment
//
// NOTE(dweiler): C11 requires setjmp be a macro, which means it won't
// necessarily export a symbol named setjmp but rather _setjmp in the case
// of musl, glibc, BSD libc, and msvcrt.
//
/// NOTE(dweiler): UCRT has two implementations of longjmp. One that performs
// stack unwinding and one that doesn't. The choice of which to use depends on a
// flag which is set inside the jmp_buf structure given to setjmp. The default
// behavior is to unwind the stack. Within Odin, we cannot use the stack
// unwinding version as the unwinding information isn't present. To opt-in to
// the regular non-unwinding version we need a way to set this flag. Since the
// location of the flag within the struct is not defined or part of the ABI and
// can change between versions of UCRT, we must rely on setjmp to set it. It
// turns out that setjmp receives this flag in the RDX register on Win64, this
// just so happens to coincide with the second argument of a function in the
// Win64 ABI. By giving our setjmp a second argument with the value of zero,
// the RDX register will contain zero and correctly set the flag to disable
// stack unwinding.
@(link_name="_setjmp")
setjmp :: proc(env: ^jmp_buf, hack: rawptr = nil) -> int ---;
}
} else {
@(default_calling_convention="c")
foreign libc {
// 7.13.1 Save calling environment
//
// NOTE(dweiler): C11 requires setjmp be a macro, which means it won't
// necessarily export a symbol named setjmp but rather _setjmp in the case
// of musl, glibc, BSD libc, and msvcrt.
@(link_name="_setjmp")
setjmp :: proc(env: ^jmp_buf) -> int ---;
}
}
@(default_calling_convention="c")
foreign libc {
// 7.13.2 Restore calling environment
longjmp :: proc(env: ^jmp_buf, val: int) -> ! ---;
}
// The C99 Rationale describes jmp_buf as being an array type for backward
// compatibility. Odin does not need to honor this and couldn't as arrays in
// Odin don't decay to pointers. It is somewhat easy for us to bind this, we
// just need to ensure the structure contains enough storage with appropriate
// alignment. Since there are no types in C with an alignment larger than
// that of max_align_t, which cannot be larger than sizeof(long double) as any
// other exposed type wouldn't be valid C, the maximum alignment possible in a
// strictly conformant C implementation is 16 on the platforms we care about.
// The choice of 4096 bytes for storage of this type is more than enough on all
// relevant platforms.
jmp_buf :: struct #align 16 { _: [4096]char, };
+43
View File
@@ -0,0 +1,43 @@
package libc
// 7.14 Signal handling
when ODIN_OS == "windows" {
foreign import libc "system:libucrt.lib"
} else {
foreign import libc "system:c"
}
sig_atomic_t :: distinct atomic_int;
@(default_calling_convention="c")
foreign libc {
signal :: proc(sig: int, func: proc "c" (int)) -> proc "c" (int) ---;
raise :: proc(sig: int) -> int ---;
}
when ODIN_OS == "windows" {
SIG_ERR :: rawptr(~uintptr(0));
SIG_DFL :: rawptr(uintptr(0));
SIG_IGN :: rawptr(uintptr(1));
SIGABRT :: 22;
SIGFPE :: 8;
SIGILL :: 4;
SIGINT :: 2;
SIGSEGV :: 11;
SIGTERM :: 15;
}
when ODIN_OS == "linux" || ODIN_OS == "freebsd" || ODIN_OS == "darwin" {
SIG_ERR :: rawptr(~uintptr(0));
SIG_DFL :: rawptr(uintptr(0));
SIG_IGN :: rawptr(uintptr(1));
SIGABRT :: 6;
SIGFPE :: 8;
SIGILL :: 4;
SIGINT :: 2;
SIGSEGV :: 11;
SIGTERM :: 15;
}
+43
View File
@@ -0,0 +1,43 @@
package libc
// 7.16 Variable arguments
import "core:intrinsics"
import "core:runtime"
import "core:mem"
@(private="file")
@(default_calling_convention="none")
foreign _ {
@(link_name="llvm.va_start") _va_start :: proc(arglist: ^i8) ---;
@(link_name="llvm.va_end") _va_end :: proc(arglist: ^i8) ---;
@(link_name="llvm.va_copy") _va_copy :: proc(dst, src: ^i8) ---;
}
// Since there are no types in C with an alignment larger than that of
// max_align_t, which cannot be larger than sizeof(long double) as any other
// exposed type wouldn't be valid C, the maximum alignment possible in a
// strictly conformant C implementation is 16 on the platforms we care about.
// The choice of 4096 bytes for storage of this type is more than enough on all
// relevant platforms.
va_list :: struct #align 16 {
_: [4096]u8,
};
va_start :: #force_inline proc(ap: ^va_list, _: any) {
_va_start(cast(^i8)ap);
}
va_end :: #force_inline proc(ap: ^va_list) {
_va_end(cast(^i8)ap);
}
va_copy :: #force_inline proc(dst, src: ^va_list) {
_va_copy(cast(^i8)dst, cast(^i8)src);
}
// We cannot provide va_arg as there is no way to create "C" style procedures
// in Odin which take variable arguments the C way. The #c_vararg attribute only
// exists for foreign imports. That being said, being able to copy a va_list,
// as well as start and end one is necessary in some functions, the va_list
// taking functions in libc as an example.
+416
View File
@@ -0,0 +1,416 @@
package libc
// 7.17 Atomics
import "core:intrinsics"
ATOMIC_BOOL_LOCK_FREE :: true;
ATOMIC_CHAR_LOCK_FREE :: true;
ATOMIC_CHAR16_T_LOCK_FREE :: true;
ATOMIC_CHAR32_T_LOCK_FREE :: true;
ATOMIC_WCHAR_T_LOCK_FREE :: true;
ATOMIC_SHORT_LOCK_FREE :: true;
ATOMIC_INT_LOCK_FREE :: true;
ATOMIC_LONG_LOCK_FREE :: true;
ATOMIC_LLONG_LOCK_FREE :: true;
ATOMIC_POINTER_LOCK_FREE :: true;
// 7.17.3 Order and consistency
memory_order :: enum int {
relaxed,
consume,
acquire,
release,
acq_rel,
seq_cst,
}
memory_order_relaxed :: memory_order.relaxed;
memory_order_consume :: memory_order.consume;
memory_order_acquire :: memory_order.acquire;
memory_order_release :: memory_order.release;
memory_order_acq_rel :: memory_order.acq_rel;
memory_order_seq_cst :: memory_order.seq_cst;
// 7.17.2 Initialization
ATOMIC_VAR_INIT :: #force_inline proc(value: $T) -> T {
return value;
}
atomic_init :: #force_inline proc(obj: ^$T, value: T) {
intrinsics.atomic_store(obj, value);
}
kill_dependency :: #force_inline proc(value: $T) -> T {
return value;
}
// 7.17.4 Fences
atomic_thread_fence :: #force_inline proc(order: memory_order) {
switch (order) {
case .relaxed:
return;
case .consume:
intrinsics.atomic_fence_acq();
case .acquire:
intrinsics.atomic_fence_acq();
case .release:
intrinsics.atomic_fence_rel();
case .acq_rel:
intrinsics.atomic_fence_acqrel();
case .seq_cst:
intrinsics.atomic_fence_acqrel();
}
}
atomic_signal_fence :: #force_inline proc(order: memory_order) {
atomic_thread_fence(order);
}
// 7.17.5 Lock-free property
atomic_is_lock_free :: #force_inline proc(obj: ^$T) -> bool {
return size_of(T) <= 8 && (intrinsics.type_is_integer(T) || intrinsics.type_is_pointer(T));
}
// 7.17.6 Atomic integer types
atomic_bool :: distinct bool;
atomic_char :: distinct char;
atomic_schar :: distinct char;
atomic_uchar :: distinct uchar;
atomic_short :: distinct short;
atomic_ushort :: distinct ushort;
atomic_int :: distinct int;
atomic_uint :: distinct uint;
atomic_long :: distinct long;
atomic_ulong :: distinct ulong;
atomic_llong :: distinct longlong;
atomic_ullong :: distinct ulonglong;
atomic_char16_t :: distinct char16_t;
atomic_char32_t :: distinct char32_t;
atomic_wchar_t :: distinct wchar_t;
atomic_int_least8_t :: distinct int_least8_t;
atomic_uint_least8_t :: distinct uint_least8_t;
atomic_int_least16_t :: distinct int_least16_t;
atomic_uint_least16_t :: distinct uint_least16_t;
atomic_int_least32_t :: distinct int_least32_t;
atomic_uint_least32_t :: distinct uint_least32_t;
atomic_int_least64_t :: distinct int_least64_t;
atomic_uint_least64_t :: distinct uint_least64_t;
atomic_int_fast8_t :: distinct int_fast8_t;
atomic_uint_fast8_t :: distinct uint_fast8_t;
atomic_int_fast16_t :: distinct int_fast16_t;
atomic_uint_fast16_t :: distinct uint_fast16_t;
atomic_int_fast32_t :: distinct int_fast32_t;
atomic_uint_fast32_t :: distinct uint_fast32_t;
atomic_int_fast64_t :: distinct int_fast64_t;
atomic_uint_fast64_t :: distinct uint_fast64_t;
atomic_intptr_t :: distinct intptr_t;
atomic_uintptr_t :: distinct uintptr_t;
atomic_size_t :: distinct size_t;
atomic_ptrdiff_t :: distinct ptrdiff_t;
atomic_intmax_t :: distinct intmax_t;
atomic_uintmax_t :: distinct uintmax_t;
// 7.17.7 Operations on atomic types
atomic_store :: #force_inline proc(object: ^$T, desired: T) {
intrinsics.atomic_store(object, desired);
}
atomic_store_explicit :: #force_inline proc(object: ^$T, desired: T, order: memory_order) {
assert(order != .consume);
assert(order != .acquire);
assert(order != .acq_rel);
#partial switch (order) {
case .relaxed:
intrinsics.atomic_store_relaxed(object, desired);
case .release:
intrinsics.atomic_store_rel(object, desired);
case .seq_cst:
intrinsics.atomic_store(object, desired);
}
}
atomic_load :: #force_inline proc(object: ^$T) -> T {
return intrinsics.atomic_load(object);
}
atomic_load_explicit :: #force_inline proc(object: ^$T, order: memory_order) {
assert(order != .release);
assert(order != .acq_rel);
#partial switch (order) {
case .relaxed:
return intrinsics.atomic_load_relaxed(object);
case .consume:
return intrinsics.atomic_load_acq(object);
case .acquire:
return intrinsics.atomic_load_acq(object);
case .seq_cst:
return intrinsics.atomic_load(object);
}
}
atomic_exchange :: #force_inline proc(object: ^$T, desired: T) -> T {
return intrinsics.atomic_xchg(object, desired);
}
atomic_exchange_explicit :: #force_inline proc(object: ^$T, desired: T, order: memory_order) -> T {
switch (order) {
case .relaxed:
return intrinsics.atomic_xchg_relaxed(object, desired);
case .consume:
return intrinsics.atomic_xchg_acq(object, desired);
case .acquire:
return intrinsics.atomic_xchg_acq(object, desired);
case .release:
return intrinsics.atomic_xchg_rel(object, desired);
case .acq_rel:
return intrinsics.atomic_xchg_acqrel(object, desired);
case .seq_cst:
return intrinsics.atomic_xchg(object, desired);
}
return false;
}
// C does not allow failure memory order to be order_release or acq_rel.
// Similarly, it does not allow the failure order to be stronger than success
// order. Since consume and acquire are both monotonic, we can count them as
// one, for a total of three memory orders that are relevant in compare exchange.
// relaxed, acquire (consume), seq_cst.
// The requirement that the failure order cannot be stronger than success limits
// the valid combinations for the failure order to this table:
// [success = seq_cst, failure = seq_cst] => _
// [success = acquire, failure = seq_cst] => acq
// [success = release, failure = seq_cst] => rel
// [success = acq_rel, failure = seq_cst] => acqrel
// [success = relaxed, failure = relaxed] => relaxed
// [success = seq_cst, failure = relaxed] => failrelaxed
// [success = seq_cst, failure = acquire] => failacq
// [success = acquire, failure = relaxed] => acq_failrelaxed
// [success = acq_rel, failure = relaxed] => acqrel_failrelaxed
atomic_compare_exchange_strong :: #force_inline proc(object, expected: ^$T, desired: T) {
value, ok := intrinsics.atomic_cxchg(object, expected^, desired);
if !ok do expected^ = value;
return ok;
}
atomic_compare_exchange_strong_explicit :: #force_inline proc(object, expected: ^$T, desired: T, success, failure: memory_order) {
assert(failure != .release);
assert(failure != .acq_rel);
value: T; ok: bool;
#partial switch (failure) {
case .seq_cst:
assert(success != .relaxed);
#partial switch (success) {
case .seq_cst:
value, ok := intrinsics.atomic_cxchg(object, expected^, desired);
case .acquire:
value, ok := intrinsics.atomic_cxchg_acq(object, expected^, desired);
case .consume:
value, ok := intrinsics.atomic_cxchg_acq(object, expected^, desired);
case .release:
value, ok := intrinsics.atomic_cxchg_rel(object, expected^, desired);
case .acq_rel:
value, ok := intrinsics.atomic_cxchg_acqrel(object, expected^, desired);
}
case .relaxed:
assert(success != .release);
#partial switch (success) {
case .relaxed:
value, ok := intrinsics.atomic_cxchg_relaxed(object, expected^, desired);
case .seq_cst:
value, ok := intrinsics.atomic_cxchg_failrelaxed(object, expected^, desired);
case .acquire:
value, ok := intrinsics.atomic_cxchg_acq_failrelaxed(object, expected^, desired);
case .consume:
value, ok := intrinsics.atomic_cxchg_acq_failrelaxed(object, expected^, desired);
case .acq_rel:
value, ok := intrinsics.atomic_cxchg_acqrel_failrelaxed(object, expected^, desired);
}
case .consume:
fallthrough;
case .acquire:
assert(success == .seq_cst);
value, ok := intrinsics.atomic_cxchg_failacq(object, expected^, desired);
}
if !ok do expected^ = value;
return ok;
}
atomic_compare_exchange_weak :: #force_inline proc(object, expected: ^$T, desired: T) {
value, ok := intrinsics.atomic_cxchgweak(object, expected^, desired);
if !ok do expected^ = value;
return ok;
}
atomic_compare_exchange_weak_explicit :: #force_inline proc(object, expected: ^$T, desited: T, success, failure: memory_order) {
assert(failure != .release);
assert(failure != .acq_rel);
value: T; ok: bool;
#partial switch (failure) {
case .seq_cst:
assert(success != .relaxed);
#partial switch (success) {
case .seq_cst:
value, ok := intrinsics.atomic_cxchgweak(object, expected^, desired);
case .acquire:
value, ok := intrinsics.atomic_cxchgweak_acq(object, expected^, desired);
case .consume:
value, ok := intrinsics.atomic_cxchgweak_acq(object, expected^, desired);
case .release:
value, ok := intrinsics.atomic_cxchgweak_rel(object, expected^, desired);
case .acq_rel:
value, ok := intrinsics.atomic_cxchgweak_acqrel(object, expected^, desired);
}
case .relaxed:
assert(success != .release);
#partial switch (success) {
case .relaxed:
value, ok := intrinsics.atomic_cxchgweak_relaxed(object, expected^, desired);
case .seq_cst:
value, ok := intrinsics.atomic_cxchgweak_failrelaxed(object, expected^, desired);
case .acquire:
value, ok := intrinsics.atomic_cxchgweak_acq_failrelaxed(object, expected^, desired);
case .consume:
value, ok := intrinsics.atomic_cxchgweak_acq_failrelaxed(object, expected^, desired);
case .acq_rel:
value, ok := intrinsics.atomic_cxchgweak_acqrel_failrelaxed(object, expected^, desired);
}
case .consume:
fallthrough;
case .acquire:
assert(success == .seq_cst);
value, ok := intrinsics.atomic_cxchgweak_failacq(object, expected^, desired);
}
if !ok do expected^ = value;
return ok;
}
// 7.17.7.5 The atomic_fetch and modify generic functions
atomic_fetch_add :: #force_inline proc(object: ^$T, operand: T) -> T {
return intrinsics.atomic_add(object, operand);
}
atomic_fetch_add_explicit :: #force_inline proc(object: ^$T, operand: T, order: memory_order) -> T {
switch (order) {
case .relaxed:
return intrinsics.atomic_add_relaxed(object, operand);
case .consume:
return intrinsics.atomic_add_acq(object, operand);
case .acquire:
return intrinsics.atomic_add_acq(object, operand);
case .release:
return intrinsics.atomic_add_rel(object, operand);
case .acq_rel:
return intrinsics.atomic_add_acqrel(object, operand);
case .seq_cst:
return intrinsics.atomic_add(object, operand);
}
}
atomic_fetch_sub :: #force_inline proc(object: ^$T, operand: T) -> T {
return intrinsics.atomic_sub(object, operand);
}
atomic_fetch_sub_explicit :: #force_inline proc(object: ^$T, operand: T, order: memory_order) -> T {
switch (order) {
case .relaxed:
return intrinsics.atomic_sub_relaxed(object, operand);
case .consume:
return intrinsics.atomic_sub_acq(object, operand);
case .acquire:
return intrinsics.atomic_sub_acq(object, operand);
case .release:
return intrinsics.atomic_sub_rel(object, operand);
case .acq_rel:
return intrinsics.atomic_sub_acqrel(object, operand);
case .seq_cst:
return intrinsics.atomic_sub(object, operand);
}
}
atomic_fetch_or :: #force_inline proc(object: ^$T, operand: T) -> T {
return intrinsics.atomic_or(object, operand);
}
atomic_fetch_or_explicit :: #force_inline proc(object: ^$T, operand: T, order: memory_order) -> T {
switch (order) {
case .relaxed:
return intrinsics.atomic_or_relaxed(object, operand);
case .consume:
return intrinsics.atomic_or_acq(object, operand);
case .acquire:
return intrinsics.atomic_or_acq(object, operand);
case .release:
return intrinsics.atomic_or_rel(object, operand);
case .acq_rel:
return intrinsics.atomic_or_acqrel(object, operand);
case .seq_cst:
return intrinsics.atomic_or(object, operand);
}
}
atomic_fetch_xor :: #force_inline proc(object: ^$T, operand: T) -> T {
return intrinsics.atomic_xor(object, operand);
}
atomic_fetch_xor_explicit :: #force_inline proc(object: ^$T, operand: T, order: memory_order) -> T {
switch (order) {
case .relaxed:
return intrinsics.atomic_xor_relaxed(object, operand);
case .consume:
return intrinsics.atomic_xor_acq(object, operand);
case .acquire:
return intrinsics.atomic_xor_acq(object, operand);
case .release:
return intrinsics.atomic_xor_rel(object, operand);
case .acq_rel:
return intrinsics.atomic_xor_acqrel(object, operand);
case .seq_cst:
return intrinsics.atomic_xor(object, operand);
}
}
atomic_fetch_and :: #force_inline proc(object: ^$T, operand: T) -> T {
return intrinsics.atomic_and(object, operand);
}
atomic_fetch_and_explicit :: #force_inline proc(object: ^$T, operand: T, order: memory_order) -> T {
switch (order) {
case .relaxed:
return intrinsics.atomic_and_relaxed(object, operand);
case .consume:
return intrinsics.atomic_and_acq(object, operand);
case .acquire:
return intrinsics.atomic_and_acq(object, operand);
case .release:
return intrinsics.atomic_and_rel(object, operand);
case .acq_rel:
return intrinsics.atomic_and_acqrel(object, operand);
case .seq_cst:
return intrinsics.atomic_and(object, operand);
}
}
// 7.17.8 Atomic flag type and operations
atomic_flag :: distinct atomic_bool;
atomic_flag_test_and_set :: #force_inline proc(flag: ^atomic_flag) -> bool {
return bool(atomic_exchange(flag, atomic_flag(true)));
}
atomic_flag_test_and_set_explicit :: #force_inline proc(flag: ^atomic_flag, order: memory_order) -> bool {
return bool(atomic_exchange_explicit(flag, atomic_flag(true), order));
}
atomic_flag_clear :: #force_inline proc(flag: ^atomic_flag) {
atomic_store(flag, atomic_flag(false));
}
atomic_flag_clear_explicit :: #force_inline proc(flag: ^atomic_flag, order: memory_order) {
atomic_store_explicit(flag, atomic_flag(false), order);
}
+135
View File
@@ -0,0 +1,135 @@
package libc
when ODIN_OS == "windows" {
foreign import libc "system:libucrt.lib"
} else {
foreign import libc "system:c"
}
// 7.21 Input/output
FILE :: struct {};
// MSVCRT compatible.
when ODIN_OS == "windows" {
_IOFBF :: 0x0000;
_IONBF :: 0x0004;
_IOLBF :: 0x0040;
BUFSIZ :: 512;
EOF :: int(-1);
FOPEN_MAX :: 20;
FILENAME_MAX :: 260;
L_tmpnam :: 15; // "\\" + 12 + NUL
SEEK_SET :: 0;
SEEK_CUR :: 1;
SEEK_END :: 2;
TMP_MAX :: 32767; // SHRT_MAX
fpos_t :: distinct i64;
@(private="file")
@(default_calling_convention="c")
foreign libc {
__acrt_iob_func :: proc (index: uint) -> ^FILE ---;
}
stdin := __acrt_iob_func(0);
stdout := __acrt_iob_func(1);
stderr := __acrt_iob_func(2);
}
// GLIBC and MUSL compatible.
when ODIN_OS == "linux" {
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 :: 10000;
foreign libc {
stderr: ^FILE;
stdin: ^FILE;
stdout: ^FILE;
}
}
@(default_calling_convention="c")
foreign libc {
// 7.21.4 Operations on files
remove :: proc(filename: cstring) -> int ---;
rename :: proc(old, new: cstring) -> int ---;
tmpfile :: proc() -> ^FILE ---;
tmpnam :: proc(s: ^char) -> ^char ---;
// 7.21.5 File access functions
fclose :: proc(stream: ^FILE) -> int ---;
fflush :: proc(stream: ^FILE) -> int ---;
fopen :: proc(filename, mode: cstring) -> ^FILE ---;
freopen :: proc(filename, mode: cstring, stream: ^FILE) -> ^FILE ---;
setbuf :: proc(stream: ^FILE, buf: ^char) ---;
setvbuf :: proc(stream: ^FILE, buf: ^char, mode: int, size: size_t) -> int ---;
// 7.21.6 Formatted input/output functions
fprintf :: proc(stream: ^FILE, format: cstring, #c_vararg args: ..any) -> int ---;
fscanf :: proc(stream: ^FILE, format: cstring, #c_vararg args: ..any) -> int ---;
printf :: proc(format: cstring, #c_vararg args: ..any) -> int ---;
scanf :: proc(format: cstring, #c_vararg args: ..any) -> int ---;
snprintf :: proc(s: ^char, format: cstring, #c_vararg args: ..any) -> int ---;
sscanf :: proc(s, format: cstring, #c_vararg args: ..any) -> int ---;
vfprintf :: proc(stream: ^FILE, format: cstring, arg: ^va_list) -> int ---;
vfscanf :: proc(stream: ^FILE, format: cstring, arg: ^va_list) -> int ---;
vprintf :: proc(format: cstring, arg: ^va_list) -> int ---;
vscanf :: proc(format: cstring, arg: ^va_list) -> int ---;
vsnprintf :: proc(s: ^char, n: size_t, format: cstring, arg: ^va_list) -> int ---;
vsprintf :: proc(s: ^char, format: cstring, arg: ^va_list) -> int ---;
vsscanf :: proc(s, format: cstring, arg: ^va_list) -> int ---;
// 7.21.7 Character input/output functions
fgetc :: proc(stream: ^FILE) -> int ---;
fgets :: proc(s: ^char, n: int, stream: ^FILE) -> ^char ---;
fputc :: proc(s: cstring, stream: ^FILE) -> int ---;
getc :: proc(stream: ^FILE) -> int ---;
getchar :: proc() -> int ---;
putc :: proc(c: int, stream: ^FILE) -> int ---;
putchar :: proc() -> int ---;
puts :: proc(s: cstring) -> int ---;
ungetc :: proc(c: int, stream: ^FILE) -> int ---;
fread :: proc(ptr: rawptr, size: size_t, stream: ^FILE) -> size_t ---;
fwrite :: proc(ptr: rawptr, size: size_t, nmemb: size_t, stream: ^FILE) -> size_t ---;
// 7.21.9 File positioning functions
fgetpos :: proc(stream: ^FILE, pos: ^fpos_t) -> int ---;
fseek :: proc(stream: ^FILE, offset: long, whence: int) -> int ---;
fsetpos :: proc(stream: ^FILE, pos: ^fpos_t) -> int ---;
ftell :: proc(stream: ^FILE) -> long ---;
rewind :: proc(stream: ^FILE) ---;
// 7.21.10 Error-handling functions
clearerr :: proc(stream: ^FILE) ---;
feof :: proc(stream: ^FILE) -> int ---;
ferror :: proc(stream: ^FILE) -> int ---;
perror :: proc(s: cstring) ---;
}
+109
View File
@@ -0,0 +1,109 @@
package libc
// 7.22 General utilities
when ODIN_OS == "windows" {
foreign import libc "system:libucrt.lib"
} else {
foreign import libc "system:c"
}
when ODIN_OS == "windows" {
RAND_MAX :: 0x7fff;
@(private="file")
@(default_calling_convention="c")
foreign libc {
___mb_cur_max_func :: proc() -> int ---;
}
MB_CUR_MAX :: #force_inline proc() -> size_t {
return size_t(___mb_cur_max_func());
}
}
when ODIN_OS == "linux" {
RAND_MAX :: 0x7fffffff;
// GLIBC and MUSL only
@(private="file")
@(default_calling_convention="c")
foreign libc {
__ctype_get_mb_cur_max :: proc() -> size_t ---;
}
MB_CUR_MAX :: #force_inline proc() -> size_t {
return __ctype_get_mb_cur_max();
}
}
// C does not declare what these values should be, as an implementation is free
// to use any two distinct values it wants to indicate success or failure.
// However, nobody actually does and everyone appears to have agreed upon these
// values.
EXIT_SUCCESS :: 0;
EXIT_FAILURE :: 1;
// C does not declare which order 'quot' and 'rem' should be for the divide
// structures. An implementation could put 'rem' first. However, nobody actually
// does and everyone appears to have agreed upon this layout.
div_t :: struct { quot, rem: int, }
ldiv_t :: struct { quot, rem: long, }
lldiv_t :: struct { quot, rem: longlong, }
@(default_calling_convention="c")
foreign libc {
// 7.22.1 Numeric conversion functions
atof :: proc(nptr: cstring) -> double ---;
atoi :: proc(nptr: cstring) -> int ---;
atol :: proc(nptr: cstring) -> long ---;
atoll :: proc(nptr: cstring) -> longlong ---;
strtod :: proc(nptr: cstring, endptr: ^^char) -> double ---;
strtof :: proc(nptr: cstring, endptr: ^^char) -> float ---;
strtol :: proc(nptr: cstring, endptr: ^^char, base: int) -> long ---;
strtoll :: proc(nptr: cstring, endptr: ^^char, base: int) -> longlong ---;
strtoul :: proc(nptr: cstring, endptr: ^^char, base: int) -> ulong ---;
strtoull :: proc(nptr: cstring, endptr: ^^char, base: int) -> ulonglong ---;
// 7.22.2 Pseudo-random sequence generation functions
rand :: proc() -> int ---;
srand :: proc(seed: uint) ---;
// 7.22.3 Memory management functions
aligned_alloc :: proc(aligment, size: size_t) -> rawptr ---;
calloc :: proc(nmemb, size: size_t) -> rawptr ---;
free :: proc(ptr: rawptr) ---;
malloc :: proc(size: size_t) -> rawptr ---;
realloc :: proc(ptr: rawptr, size: size_t) -> rawptr ---;
// 7.22.4 Communication with the environment
abort :: proc() -> ! ---;
atexit :: proc(func: proc "c" ()) -> int ---;
at_quick_exit :: proc(func: proc "c" ()) -> int ---;
exit :: proc(status: int) -> ! ---;
_Exit :: proc(status: int) -> ! ---;
getenv :: proc(name: cstring) -> ^char ---;
quick_exit :: proc(status: int) -> ! ---;
system :: proc(cmd: cstring) -> int ---;
// 7.22.5 Searching and sorting utilities
bsearch :: proc(key, base: rawptr, nmemb, size: size_t, compar: proc "c" (lhs, rhs: rawptr) -> int) -> rawptr ---;
qsort :: proc(base: rawptr, nmemb, size: size_t, compar: proc "c" (lhs, rhs: rawptr) -> int) ---;
// 7.22.6 Integer arithmetic functions
abs :: proc(j: int) -> int ---;
labs :: proc(j: long) -> long ---;
llabs :: proc(j: longlong) -> longlong ---;
div :: proc(numer, denom: int) -> div_t ---;
ldiv :: proc(numer, denom: long) -> ldiv_t ---;
lldiv :: proc(numer, denom: longlong) -> lldiv_t ---;
// 7.22.7 Multibyte/wide character conversion functions
mblen :: proc(s: cstring, n: size_t) -> int ---;
mbtowc :: proc(pwc: ^wchar_t, s: cstring, n: size_t) -> int ---;
wctomb :: proc(s: ^char, wc: wchar_t) -> int ---;
// 7.22.8 Multibyte/wide string conversion functions
mbstowcs :: proc(pwcs: ^wchar_t, s: cstring, n: size_t) -> size_t ---;
wcstombs :: proc(s: ^char, pwcs: ^wchar_t, n: size_t) -> size_t ---;
}
+43
View File
@@ -0,0 +1,43 @@
package libc
// 7.24 String handling
when ODIN_OS == "windows" {
foreign import libc "system:libucrt.lib"
} else {
foreign import libc "system:c"
}
foreign libc {
// 7.24.2 Copying functions
memcpy :: proc(s1, s2: rawptr, n: size_t) -> rawptr ---;
memmove :: proc(s1, s2: rawptr, n: size_t) -> rawptr ---;
strcpy :: proc(s1: ^char, s2: cstring) -> ^char ---;
strncpy :: proc(s1: ^char, s2: cstring, n: size_t) -> ^char ---;
// 7.24.3 Concatenation functions
strcat :: proc(s1: ^char, s2: cstring) -> ^char ---;
strncat :: proc(s1: ^char, s2: cstring, n: size_t) -> ^char ---;
// 7.24.4 Comparison functions
memcmp :: proc(s1, s2: rawptr, n: size_t) -> int ---;
strcmp :: proc(s1, s2: cstring) -> int ---;
strcoll :: proc(s1, s2: cstring) -> int ---;
strncmp :: proc(s1, s2: cstring, n: size_t) -> int ---;
strxfrm :: proc(s1: ^char, s2: cstring, n: size_t) -> size_t ---;
// 7.24.5 Search functions
memchr :: proc(s: rawptr, c: int, n: size_t) -> rawptr ---;
strchr :: proc(s: cstring, c: int) -> ^char ---;
strcspn :: proc(s1, s2: cstring) -> size_t ---;
strpbrk :: proc(s1, s2: cstring) -> ^char ---;
strrchr :: proc(s: ^char, c: int) -> ^char ---;
strcpn :: proc(s1, s2: cstring) -> ^char ---;
strtok :: proc(s1: ^char, s2: cstring) -> ^char ---;
// 7.24.6 Miscellaneous functions
memset :: proc(s: rawptr, c: int, n: size_t) -> rawptr ---;
strerror :: proc(errnum: int) -> ^char ---;
strlen :: proc(s: cstring) -> size_t ---;
}
+50
View File
@@ -0,0 +1,50 @@
package libc_tests
import "core:c/libc"
test_stdio :: proc() {
c: libc.char = 'C';
libc.puts("Hello from puts");
libc.printf("Hello from printf in %c\n", c);
}
test_thread :: proc() {
thread_proc :: proc "c" (rawptr) -> libc.int {
libc.printf("Hello from thread");
return 42;
}
thread: libc.thrd_t;
libc.thrd_create(&thread, thread_proc, nil);
result: libc.int;
libc.thrd_join(thread, &result);
libc.printf(" %d\n", result);
}
jmp: libc.jmp_buf;
test_sjlj :: proc() {
if libc.setjmp(&jmp) != 0 {
libc.printf("Hello from longjmp\n");
return;
}
libc.printf("Hello from setjmp\n");
libc.longjmp(&jmp, 1);
}
test_signal :: proc() {
handler :: proc "c" (sig: libc.int) {
libc.printf("Hello from signal handler\n");
}
libc.signal(libc.SIGABRT, handler);
libc.raise(libc.SIGABRT);
}
test_atexit :: proc() {
handler :: proc "c" () {
libc.printf("Hello from atexit\n");
}
libc.atexit(handler);
}
main :: proc() {
test_stdio();
test_thread();
test_sjlj();
test_signal();
test_atexit();
}
+138
View File
@@ -0,0 +1,138 @@
package libc
// 7.26 Threads
thrd_start_t :: proc "c" (rawptr) -> int;
tss_dtor_t :: proc "c" (rawptr);
when ODIN_OS == "windows" {
foreign import libc {
"system:libucrt.lib",
"system:msvcprt.lib"
}
thrd_success :: 0; // _Thrd_success
thrd_nomem :: 1; // _Thrd_nomem
thrd_timedout :: 2; // _Thrd_timedout
thrd_busy :: 3; // _Thrd_busy
thrd_error :: 4; // _Thrd_error
mtx_plain :: 1; // _Mtx_plain
mtx_recursive :: 0x100; // _Mtx_recursive
mtx_timed :: 4; // _Mtx_timed
TSS_DTOR_ITERATIONS :: 4; // _TSS_DTOR_ITERATIONS_IMP
once_flag :: distinct i8; // _Once_flag_imp_t
thrd_t :: struct { _: rawptr, _: uint, } // _Thrd_t
tss_t :: distinct int; // _Tss_imp_t
cnd_t :: distinct rawptr; // _Cnd_imp_t
mtx_t :: distinct rawptr; // _Mtx_imp_t
// MSVCRT does not expose the C11 symbol names as what they are in C11
// because they held off implementing <threads.h> and C11 support for so
// long that people started implementing their own. To prevent symbol
// conflict with existing customers code they had to namespace them
// differently. Thus we need to alias the correct symbol names with Odin's
// link_name attribute.
@(default_calling_convention="c")
foreign libc {
// 7.26.2 Initialization functions
@(link_name="_Call_once") call_once :: proc(flag: ^once_flag, func: proc "c" ()) ---;
// 7.26.3 Condition variable functions
@(link_name="_Cnd_broadcast") cnd_broadcast :: proc(cond: ^cnd_t) -> int ---;
@(link_name="_Cnd_destroy") cnd_destroy :: proc(cond: ^cnd_t) ---;
@(link_name="_Cnd_init") cnd_init :: proc(cond: ^cnd_t) -> int ---;
@(link_name="_Cnd_signal") cnd_signal :: proc(cond: ^cnd_t) -> int ---;
@(link_name="_Cnd_timedwait") cnd_timedwait :: proc(cond: ^cnd_t, ts: ^timespec) -> int ---;
@(link_name="_Cnd_wait") cnd_wait :: proc(cond: ^cnd_t, mtx: ^mtx_t) -> int ---;
// 7.26.4 Mutex functions
@(link_name="_Mtx_destroy") mtx_destroy :: proc(mtx: ^mtx_t) ---;
@(link_name="_Mtx_init") mtx_init :: proc(mtx: ^mtx_t, type: int) -> int ---;
@(link_name="_Mtx_lock") mtx_lock :: proc(mtx: ^mtx_t) -> int ---;
@(link_name="_Mtx_timedlock") mtx_timedlock :: proc(mtx: ^mtx_t, ts: ^timespec) -> int ---;
@(link_name="_Mtx_trylock") mtx_trylock :: proc(mtx: ^mtx_t) -> int ---;
@(link_name="_Mtx_unlock") mtx_unlock :: proc(mtx: ^mtx_t) -> int ---;
// 7.26.5 Thread functions
@(link_name="_Thrd_create") thrd_create :: proc(thr: ^thrd_t, func: thrd_start_t, arg: rawptr) -> int ---;
@(link_name="_Thrd_current") thrd_current :: proc() -> thrd_t ---;
@(link_name="_Thrd_detach") thrd_detach :: proc(thr: thrd_t) -> int ---;
@(link_name="_Thrd_equal") thrd_equal :: proc(lhs, rhs: thrd_t) -> int ---;
@(link_name="_Thrd_exit") thrd_exit :: proc(res: int) -> ! ---;
@(link_name="_Thrd_join") thrd_join :: proc(thr: thrd_t, res: ^int) -> int ---;
@(link_name="_Thrd_sleep") thrd_sleep :: proc(duration, remaining: ^timespec) -> int ---;
@(link_name="_Thrd_yield") thrd_yield :: proc() ---;
// 7.26.6 Thread-specific storage functions
@(link_name="_Tss_create") tss_create :: proc(key: ^tss_t, dtor: tss_dtor_t) -> int ---;
@(link_name="_Tss_delete") tss_delete :: proc(key: tss_t) ---;
@(link_name="_Tss_get") tss_get :: proc(key: tss_t) -> rawptr ---;
@(link_name="_Tss_set") tss_set :: proc(key: tss_t, val: rawptr) -> int ---;
}
}
// GLIBC and MUSL compatible constants and types.
when ODIN_OS == "linux" {
foreign import libc {
"system:c",
"system:pthread"
}
thrd_success :: 0;
thrd_busy :: 1;
thrd_error :: 2;
thrd_nomem :: 3;
thrd_timedout :: 4;
mtx_plain :: 0;
mtx_recursive :: 1;
mtx_timed :: 2;
TSS_DTOR_ITERATIONS :: 4;
once_flag :: distinct int;
thrd_t :: distinct ulong;
tss_t :: distinct uint;
cnd_t :: struct #raw_union { _: [12]int, _: [12 * size_of(int) / size_of(rawptr)]rawptr, };
mtx_t :: struct #raw_union { _: [10 when size_of(long) == 8 else 6]int, _: [5 when size_of(long) == 8 else 6]rawptr, };
@(default_calling_convention="c")
foreign libc {
// 7.26.2 Initialization functions
call_once :: proc(flag: ^once_flag, func: proc "c" ()) ---;
// 7.26.3 Condition variable functions
cnd_broadcast :: proc(cond: ^cnd_t) -> int ---;
cnd_destroy :: proc(cond: ^cnd_t) ---;
cnd_init :: proc(cond: ^cnd_t) -> int ---;
cnd_signal :: proc(cond: ^cnd_t) -> int ---;
cnd_timedwait :: proc(cond: ^cnd_t, ts: ^timespec) -> int ---;
cnd_wait :: proc(cond: ^cnd_t, mtx: ^mtx_t) -> int ---;
// 7.26.4 Mutex functions
mtx_destroy :: proc(mtx: ^mtx_t) ---;
mtx_init :: proc(mtx: ^mtx_t, type: int) -> int ---;
mtx_lock :: proc(mtx: ^mtx_t) -> int ---;
mtx_timedlock :: proc(mtx: ^mtx_t, ts: ^timespec) -> int ---;
mtx_trylock :: proc(mtx: ^mtx_t) -> int ---;
mtx_unlock :: proc(mtx: ^mtx_t) -> int ---;
// 7.26.5 Thread functions
thrd_create :: proc(thr: ^thrd_t, func: thrd_start_t, arg: rawptr) -> int ---;
thrd_current :: proc() -> thrd_t ---;
thrd_detach :: proc(thr: thrd_t) -> int ---;
thrd_equal :: proc(lhs, rhs: thrd_t) -> int ---;
thrd_exit :: proc(res: int) -> ! ---;
thrd_join :: proc(thr: thrd_t, res: ^int) -> int ---;
thrd_sleep :: proc(duration, remaining: ^timespec) -> int ---;
thrd_yield :: proc() ---;
// 7.26.6 Thread-specific storage functions
tss_create :: proc(key: ^tss_t, dtor: tss_dtor_t) -> int ---;
tss_delete :: proc(key: tss_t) ---;
tss_get :: proc(key: tss_t) -> rawptr ---;
tss_set :: proc(key: tss_t, val: rawptr) -> int ---;
}
}
+81
View File
@@ -0,0 +1,81 @@
package libc
// 7.27 Date and time
when ODIN_OS == "windows" {
foreign import libc "system:libucrt.lib"
} else {
foreign import libc "system:c"
}
// We enforce 64-bit time_t and timespec as there is no reason to use 32-bit as
// we approach the 2038 problem. Windows has defaulted to this since VC8 (2005).
when ODIN_OS == "windows" {
foreign libc {
// 7.27.2 Time manipulation functions
clock :: proc() -> clock_t ---;
@(link_name="_difftime64") difftime :: proc(time1, time2: time_t) -> double ---;
mktime :: proc(timeptr: ^tm) -> time_t ---;
@(link_name="_time64") time :: proc(timer: ^time_t) -> time_t ---;
@(link_name="_timespec64_get") timespec_get :: proc(ts: ^timespec, base: int) -> int ---;
// 7.27.3 Time conversion functions
asctime :: proc(timeptr: ^tm) -> ^char ---;
@(link_name="_ctime64") ctime :: proc(timer: ^time_t) -> ^char ---;
@(link_name="_gmtime64") gmtime :: proc(timer: ^time_t) -> ^tm ---;
@(link_name="_localtime64") localtime :: proc(timer: ^time_t) -> ^tm ---;
strftime :: proc(s: ^char, maxsize: size_t, format: cstring, timeptr: ^tm) -> size_t ---;
}
CLOCKS_PER_SEC :: 1000;
TIME_UTC :: 1;
clock_t :: distinct long;
time_t :: distinct i64;
timespec :: struct #align 8 {
tv_sec: time_t,
tv_nsec: long,
}
tm :: struct #align 8 {
tm_sec, tm_min, tm_hour, tm_mday, tm_mon, tm_year, tm_wday, tm_yday, tm_isdst: int,
}
}
when ODIN_OS == "linux" || ODIN_OS == "freebsd" {
@(default_calling_convention="c")
foreign libc {
// 7.27.2 Time manipulation functions
clock :: proc() -> clock_t ---;
difftime :: proc(time1, time2: time_t) -> double ---;
mktime :: proc(timeptr: ^tm) -> time_t ---;
time :: proc(timer: ^time_t) -> time_t ---;
timespec_get :: proc(ts: ^timespec, base: int) -> int ---;
// 7.27.3 Time conversion functions
asctime :: proc(timeptr: ^tm) -> ^char ---;
ctime :: proc(timer: ^time_t) -> ^char ---;
gmtime :: proc(timer: ^time_t) -> ^tm ---;
localtime :: proc(timer: ^time_t) -> ^tm ---;
strftime :: proc(s: ^char, maxsize: size_t, format: cstring, timeptr: ^tm) -> size_t ---;
}
CLOCKS_PER_SEC :: 1000000;
TIME_UTC :: 1;
time_t :: distinct i64;
clock_t :: long;
timespec :: struct {
tv_sec: time_t,
tv_nsec: long,
}
tm :: struct {
tm_sec, tm_min, tm_hour, tm_mday, tm_mon, tm_year, tm_wday, tm_yday, tm_isdst: int,
_: long,
_: rawptr,
}
}
+82
View File
@@ -0,0 +1,82 @@
package libc
import builtin "core:builtin"
char :: builtin.u8; // assuming -funsigned-char
short :: builtin.i16;
int :: builtin.i32;
long :: builtin.i32 when (ODIN_OS == "windows" || size_of(builtin.rawptr) == 4) else builtin.i64;
longlong :: builtin.i64;
uchar :: builtin.u8;
ushort :: builtin.u16;
uint :: builtin.u32;
ulong :: builtin.u32 when (ODIN_OS == "windows" || size_of(builtin.rawptr) == 4) else builtin.u64;
ulonglong :: builtin.u64;
bool :: distinct builtin.b8;
size_t :: builtin.uint;
wchar_t :: builtin.u16 when (ODIN_OS == "windows") else builtin.u32;
float :: builtin.f32;
double :: builtin.f64;
// 7.20.1 Integer types
int8_t :: builtin.i8;
uint8_t :: builtin.u8;
int16_t :: builtin.i16;
uint16_t :: builtin.u16;
int32_t :: builtin.i32;
uint32_t :: builtin.u32;
int64_t :: builtin.i64;
uint64_t :: builtin.u64;
// These are all the same in multiple libc's for multiple architectures.
int_least8_t :: builtin.i8;
uint_least8_t :: builtin.u8;
int_least16_t :: builtin.i16;
uint_least16_t :: builtin.u16;
int_least32_t :: builtin.i32;
uint_least32_t :: builtin.u32;
int_least64_t :: builtin.i64;
uint_least64_t :: builtin.u64;
// Same on Windows, Linux, and FreeBSD
when ODIN_ARCH == "386" || ODIN_ARCH == "amd64" {
int_fast8_t :: builtin.i8;
uint_fast8_t :: builtin.u8;
int_fast16_t :: builtin.i32;
uint_fast16_t :: builtin.u32;
int_fast32_t :: builtin.i32;
uint_fast32_t :: builtin.u32;
int_fast64_t :: builtin.i64;
uint_fast64_t :: builtin.u64;
}
intptr_t :: builtin.int;
uintptr_t :: builtin.uintptr;
ptrdiff_t :: distinct intptr_t;
intmax_t :: builtin.i64;
uintmax_t :: builtin.u64;
// Copy C's rules for type promotion here by forcing the type on the literals.
INT8_MAX :: int(0x7f);
INT16_MAX :: int(0x7fff);
INT32_MAX :: int(0x7fffffff);
INT64_MAX :: longlong(0x7fffffffffffffff);
UINT8_MAX :: int(0xff);
UINT16_MAX :: int(0xffff);
UINT32_MAX :: uint(0xffffffff);
UINT64_MAX :: ulonglong(0xffffffffffffffff);
INT8_MIN :: ~INT8_MAX;
INT16_MIN :: ~INT16_MAX;
INT32_MIN :: ~INT32_MAX;
INT64_MIN :: ~INT64_MAX;
NULL :: rawptr(uintptr(0));
NDEBUG :: !ODIN_DEBUG;
+21
View File
@@ -0,0 +1,21 @@
package libc
// 7.28 Unicode utilities
when ODIN_OS == "windows" {
foreign import libc "system:libucrt.lib"
} else {
foreign import libc "system:c"
}
@(default_calling_convention="c")
foreign libc {
// 7.28.1 Restartable multibyte/wide character conversion functions
mbrtoc16 :: proc(pc16: ^char16_t, s: cstring, n: size_t, ps: ^mbstate_t) -> size_t ---;
c16rtomb :: proc(s: ^char, c16: char16_t, ps: ^mbstate_t) -> size_t ---;
mbrtoc32 :: proc(pc32: ^char32_t, s: cstring, n: size_t, ps: ^mbstate_t) -> size_t ---;
c32rtomb :: proc(s: ^char, c32: char32_t, ps: ^mbstate_t) -> size_t ---;
}
char16_t :: uint_least16_t;
char32_t :: uint_least32_t;
+108
View File
@@ -0,0 +1,108 @@
package libc
// 7.29 Extended multibyte and wide character utilities
when ODIN_OS == "windows" {
foreign import libc "system:libucrt.lib"
} else {
foreign import libc "system:c"
}
@(default_calling_convention="c")
foreign libc {
// 7.29.2 Formatted wide character input/output functions
fwprintf :: proc(stream: ^FILE, format: ^wchar_t, #c_vararg arg: ..any) -> int ---;
fwscanf :: proc(stream: ^FILE, format: ^wchar_t, #c_vararg arg: ..any) -> int ---;
swprintf :: proc(stream: ^FILE, n: size_t, format: ^wchar_t, #c_vararg arg: ..any) -> int ---;
swscanf :: proc(s, format: ^wchar_t, #c_vararg arg: ..any) -> int ---;
vfwprintf :: proc(stream: ^FILE, format: ^wchar_t, arg: va_list) -> int ---;
vfwscanf :: proc(stream: ^FILE, format: ^wchar_t, arg: va_list) -> int ---;
vswprintf :: proc(s: ^wchar_t, n: size_t, format: ^wchar_t, arg: va_list) -> int ---;
vswscanf :: proc(s, format: ^wchar_t, arg: va_list) -> int ---;
vwprintf :: proc(format: ^wchar_t, arg: va_list) -> int ---;
vwscanf :: proc(format: ^wchar_t, arg: va_list) -> int ---;
wprintf :: proc(format: ^wchar_t, #c_vararg arg: ..any) -> int ---;
wscanf :: proc(format: ^wchar_t, #c_vararg arg: ..any) -> int ---;
// 7.29.3 Wide character input/output functions
fwgetc :: proc(stream: ^FILE) -> wint_t ---;
fgetws :: proc(s: ^wchar_t, n: int, stream: ^FILE) -> wchar_t ---;
fputwc :: proc(c: wchar_t, stream: ^FILE) -> wint_t ---;
fputws :: proc(s: ^wchar_t, stream: ^FILE) -> int ---;
fwide :: proc(stream: ^FILE, mode: int) -> int ---;
getwc :: proc(stream: ^FILE) -> wint_t ---;
getwchar :: proc() -> wint_t ---;
putwc :: proc(c: wchar_t, stream: ^FILE) -> wint_t ---;
putwchar :: proc(c: wchar_t) -> wint_t ---;
ungetwc :: proc(c: wchar_t, stream: ^FILE) -> wint_t ---;
// 7.29.4 General wide string utilities
wcstod :: proc(nptr: ^wchar_t, endptr: ^^wchar_t) -> double ---;
wcstof :: proc(nptr: ^wchar_t, endptr: ^^wchar_t) -> float ---;
wcstol :: proc(nptr: ^wchar_t, endptr: ^^wchar_t, base: int) -> long ---;
wcstoll :: proc(nptr: ^wchar_t, endptr: ^^wchar_t, base: int) -> longlong ---;
wcstoul :: proc(nptr: ^wchar_t, endptr: ^^wchar_t, base: int) -> ulong ---;
wcstoull :: proc(nptr: ^wchar_t, endptr: ^^wchar_t, base: int) -> ulonglong ---;
// 7.29.4.2 Wide string copying functions
wcscpy :: proc(s1, s2: ^wchar_t) -> ^wchar_t ---;
wcsncpy :: proc(s1, s2: ^wchar_t, n: size_t) -> ^wchar_t ---;
wmemcpy :: proc(s1, s2: ^wchar_t, n: size_t) -> ^wchar_t ---;
wmemmove :: proc(s1, s2: ^wchar_t, n: size_t) -> ^wchar_t ---;
// 7.29.4.3 Wide string concatenation functions
wcscat :: proc(s1, s2: ^wchar_t) -> ^wchar_t ---;
wcsncat :: proc(s1, s2: ^wchar_t, n: size_t) -> ^wchar_t ---;
// 7.29.4.4 Wide string comparison functions
wcscmp :: proc(s1, s2: ^wchar_t) -> int ---;
wcscoll :: proc(s1, s2: ^wchar_t) -> int ---;
wcsncmp :: proc(s1, s2: ^wchar_t, n: size_t) -> int ---;
wcsxfrm :: proc(s1, s2: ^wchar_t, n: size_t) -> size_t ---;
wmemcmp :: proc(s1, s2: ^wchar_t, n: size_t) -> int ---;
// 7.29.4.5 Wide string search functions
wcschr :: proc(s: ^wchar_t, c: wchar_t) -> ^wchar_t ---;
wcscspn :: proc(s1, s2: ^wchar_t) -> size_t ---;
wcspbrk :: proc(s1, s2: ^wchar_t) -> ^wchar_t ---;
wcsrchr :: proc(s: ^wchar_t, c: wchar_t) -> ^wchar_t ---;
wcsspn :: proc(s1, s2: ^wchar_t) -> size_t ---;
wcsstr :: proc(s1, s2: ^wchar_t) -> ^wchar_t ---;
wcstok :: proc(s1, s2: ^wchar_t, ptr: ^^wchar_t) -> ^wchar_t ---;
wmemchr :: proc(s: ^wchar_t, c: wchar_t, n: size_t) -> ^wchar_t ---;
// 7.29.4.6 Miscellaneous functions
wcslen :: proc(s: ^wchar_t) -> size_t ---;
wmemset :: proc(s: ^wchar_t, c: wchar_t, n: size_t) -> ^wchar_t ---;
// 7.29.5 Wide character time conversion functions
wcsftime :: proc(s: ^wchar_t, maxsize: size_t, format: ^wchar_t, timeptr: ^tm) -> size_t ---;
// 7.29.6.1 Single-byte/wide character conversion functions
btowc :: proc(c: int) -> wint_t ---;
wctob :: proc(c: wint_t) -> int ---;
// 7.29.6.2 Conversion state functions
mbsinit :: proc(ps: ^mbstate_t) -> int ---;
// 7.29.6.3 Restartable multibyte/wide character conversion functions
mbrlen :: proc(s: cstring, n: size_t, ps: ^mbstate_t) -> size_t ---;
mbrtowc :: proc(pwc: ^wchar_t, s: cstring, n: size_t, ps: ^mbstate_t) -> size_t ---;
wcrtomb :: proc(s: ^char, wc: wchar_t, ps: ^mbstate_t) -> size_t ---;
// 7.29.6.4 Restartable multibyte/wide string conversion functions
mbsrtowcs :: proc(dst: ^wchar_t, src: ^cstring, len: size_t, ps: ^mbstate_t) -> size_t ---;
wcsrtombs :: proc(dst: ^char, src: ^^wchar_t, len: size_t, ps: ^mbstate_t) -> size_t ---;
}
// Large enough and aligned enough for any wide-spread in-use libc.
mbstate_t :: struct #align 16 { _: [32]char, }
// Odin does not have default argument promotion so the need for a separate type
// here isn't necessary, though make it distinct just to be safe.
wint_t :: distinct wchar_t;
// Calculate these values correctly regardless of what type wchar_t actually is.
WINT_MIN :: 0;
WINT_MAX :: 1 << (size_of(wint_t) * 8);
WEOF :: ~wint_t(0);
+48
View File
@@ -0,0 +1,48 @@
package libc
// 7.30 Wide character classification and mapping utilities
when ODIN_OS == "windows" {
foreign import libc "system:libucrt.lib"
} else {
foreign import libc "system:c"
}
when ODIN_OS == "windows" {
wctrans_t :: distinct wchar_t;
wctype_t :: distinct ushort;
}
when ODIN_OS == "linux" {
wctrans_t :: distinct rawptr;
wctype_t :: distinct ulong;
}
@(default_calling_convention="c")
foreign libc {
// 7.30.2.1 Wide character classification functions
iswalnum :: proc(wc: wint_t) -> int ---;
iswalpha :: proc(wc: wint_t) -> int ---;
iswblank :: proc(wc: wint_t) -> int ---;
iswcntrl :: proc(wc: wint_t) -> int ---;
iswdigit :: proc(wc: wint_t) -> int ---;
iswgraph :: proc(wc: wint_t) -> int ---;
iswlower :: proc(wc: wint_t) -> int ---;
iswprint :: proc(wc: wint_t) -> int ---;
iswpunct :: proc(wc: wint_t) -> int ---;
iswspace :: proc(wc: wint_t) -> int ---;
iswupper :: proc(wc: wint_t) -> int ---;
iswxdigit :: proc(wc: wint_t) -> int ---;
// 7.30.2.2 Extensible wide character classification functions
iswctype :: proc(wc: wint_t, desc: wctype_t) -> int ---;
wctype :: proc(property: cstring) -> wctype_t ---;
// 7.30.3 Wide character case mapping utilities
towlower :: proc(wc: wint_t) -> wint_t ---;
towupper :: proc(wc: wint_t) -> wint_t ---;
// 7.30.3.2 Extensible wide character case mapping functions
towctrans :: proc(wc: wint_t, desc: wctrans_t) -> wint_t ---;
wctrans :: proc(property: cstring) -> wctrans_t ---;
}
+478
View File
@@ -0,0 +1,478 @@
package compress
/*
Copyright 2021 Jeroen van Rijn <nom@duclavier.com>.
Made available under Odin's BSD-2 license.
List of contributors:
Jeroen van Rijn: Initial implementation, optimization.
*/
import "core:io"
import "core:image"
import "core:bytes"
/*
These settings bound how much compression algorithms will allocate for their output buffer.
If streaming their output, these are unnecessary and will be ignored.
*/
/*
When a decompression routine doesn't stream its output, but writes to a buffer,
we pre-allocate an output buffer to speed up decompression. The default is 1 MiB.
*/
COMPRESS_OUTPUT_ALLOCATE_MIN :: int(#config(COMPRESS_OUTPUT_ALLOCATE_MIN, 1 << 20));
/*
This bounds the maximum a buffer will resize to as needed, or the maximum we'll
pre-allocate if you inform the decompression routine you know the payload size.
For reference, the largest payload size of a GZIP file is 4 GiB.
*/
when size_of(uintptr) == 8 {
/*
For 64-bit platforms, we set the default max buffer size to 4 GiB,
which is GZIP and PKZIP's max payload size.
*/
COMPRESS_OUTPUT_ALLOCATE_MAX :: int(#config(COMPRESS_OUTPUT_ALLOCATE_MAX, 1 << 32));
} else {
/*
For 32-bit platforms, we set the default max buffer size to 512 MiB.
*/
COMPRESS_OUTPUT_ALLOCATE_MAX :: int(#config(COMPRESS_OUTPUT_ALLOCATE_MAX, 1 << 29));
}
Error :: union {
General_Error,
Deflate_Error,
ZLIB_Error,
GZIP_Error,
ZIP_Error,
/*
This is here because png.load will return a this type of error union,
as it may involve an I/O error, a Deflate error, etc.
*/
image.Error,
}
General_Error :: enum {
File_Not_Found,
Cannot_Open_File,
File_Too_Short,
Stream_Too_Short,
Output_Too_Short,
Unknown_Compression_Method,
Checksum_Failed,
Incompatible_Options,
Unimplemented,
/*
Memory errors
*/
Allocation_Failed,
Resize_Failed,
}
GZIP_Error :: enum {
Invalid_GZIP_Signature,
Reserved_Flag_Set,
Invalid_Extra_Data,
Original_Name_Too_Long,
Comment_Too_Long,
Payload_Length_Invalid,
Payload_CRC_Invalid,
/*
GZIP's payload can be a maximum of max(u32le), or 4 GiB.
If you tell it you expect it to contain more, that's obviously an error.
*/
Payload_Size_Exceeds_Max_Payload,
/*
For buffered instead of streamed output, the payload size can't exceed
the max set by the `COMPRESS_OUTPUT_ALLOCATE_MAX` switch in compress/common.odin.
You can tweak this setting using `-define:COMPRESS_OUTPUT_ALLOCATE_MAX=size_in_bytes`
*/
Output_Exceeds_COMPRESS_OUTPUT_ALLOCATE_MAX,
}
ZIP_Error :: enum {
Invalid_ZIP_File_Signature,
Unexpected_Signature,
Insert_Next_Disk,
Expected_End_of_Central_Directory_Record,
}
ZLIB_Error :: enum {
Unsupported_Window_Size,
FDICT_Unsupported,
Unsupported_Compression_Level,
Code_Buffer_Malformed,
}
Deflate_Error :: enum {
Huffman_Bad_Sizes,
Huffman_Bad_Code_Lengths,
Inflate_Error,
Bad_Distance,
Bad_Huffman_Code,
Len_Nlen_Mismatch,
BType_3,
}
// General I/O context for ZLIB, LZW, etc.
Context_Memory_Input :: struct #packed {
input_data: []u8,
output: ^bytes.Buffer,
bytes_written: i64,
code_buffer: u64,
num_bits: u64,
/*
If we know the data size, we can optimize the reads and writes.
*/
size_packed: i64,
size_unpacked: i64,
}
#assert(size_of(Context_Memory_Input) == 64);
Context_Stream_Input :: struct #packed {
input_data: []u8,
input: io.Stream,
output: ^bytes.Buffer,
bytes_written: i64,
code_buffer: u64,
num_bits: u64,
/*
If we know the data size, we can optimize the reads and writes.
*/
size_packed: i64,
size_unpacked: i64,
/*
Flags:
`input_fully_in_memory`
true = This tells us we read input from `input_data` exclusively. [] = EOF.
false = Try to refill `input_data` from the `input` stream.
*/
input_fully_in_memory: b8,
padding: [1]u8,
}
/*
TODO: The stream versions should really only check if a certain method is available once, perhaps even during setup.
Bit and byte readers may be merged so that reading bytes will grab them from the bit buffer first.
This simplifies end-of-stream handling where bits may be left in the bit buffer.
*/
// TODO: Make these return compress.Error errors.
input_size_from_memory :: proc(z: ^Context_Memory_Input) -> (res: i64, err: Error) {
return i64(len(z.input_data)), nil;
}
input_size_from_stream :: proc(z: ^Context_Stream_Input) -> (res: i64, err: Error) {
return io.size(z.input), nil;
}
input_size :: proc{input_size_from_memory, input_size_from_stream};
@(optimization_mode="speed")
read_slice_from_memory :: #force_inline proc(z: ^Context_Memory_Input, size: int) -> (res: []u8, err: io.Error) {
#no_bounds_check {
if len(z.input_data) >= size {
res = z.input_data[:size];
z.input_data = z.input_data[size:];
return res, .None;
}
}
if len(z.input_data) == 0 {
return []u8{}, .EOF;
} else {
return []u8{}, .Short_Buffer;
}
}
@(optimization_mode="speed")
read_slice_from_stream :: #force_inline proc(z: ^Context_Stream_Input, size: int) -> (res: []u8, err: io.Error) {
b := make([]u8, size, context.temp_allocator);
_, e := z.input->impl_read(b[:]);
if e == .None {
return b, .None;
}
return []u8{}, e;
}
read_slice :: proc{read_slice_from_memory, read_slice_from_stream};
@(optimization_mode="speed")
read_data :: #force_inline proc(z: ^$C, $T: typeid) -> (res: T, err: io.Error) {
b, e := read_slice(z, size_of(T));
if e == .None {
return (^T)(&b[0])^, .None;
}
return T{}, e;
}
@(optimization_mode="speed")
read_u8_from_memory :: #force_inline proc(z: ^Context_Memory_Input) -> (res: u8, err: io.Error) {
#no_bounds_check {
if len(z.input_data) >= 1 {
res = z.input_data[0];
z.input_data = z.input_data[1:];
return res, .None;
}
}
return 0, .EOF;
}
@(optimization_mode="speed")
read_u8_from_stream :: #force_inline proc(z: ^Context_Stream_Input) -> (res: u8, err: io.Error) {
b, e := read_slice_from_stream(z, 1);
if e == .None {
return b[0], .None;
}
return 0, e;
}
read_u8 :: proc{read_u8_from_memory, read_u8_from_stream};
/*
You would typically only use this at the end of Inflate, to drain bits from the code buffer
preferentially.
*/
@(optimization_mode="speed")
read_u8_prefer_code_buffer_lsb :: #force_inline proc(z: ^$C) -> (res: u8, err: io.Error) {
if z.num_bits >= 8 {
res = u8(read_bits_no_refill_lsb(z, 8));
} else {
size, _ := input_size(z);
if size > 0 {
res, err = read_u8(z);
} else {
err = .EOF;
}
}
return;
}
@(optimization_mode="speed")
peek_data_from_memory :: #force_inline proc(z: ^Context_Memory_Input, $T: typeid) -> (res: T, err: io.Error) {
size :: size_of(T);
#no_bounds_check {
if len(z.input_data) >= size {
buf := z.input_data[:size];
return (^T)(&buf[0])^, .None;
}
}
if len(z.input_data) == 0 {
return T{}, .EOF;
} else {
return T{}, .Short_Buffer;
}
}
@(optimization_mode="speed")
peek_data_from_stream :: #force_inline proc(z: ^Context_Stream_Input, $T: typeid) -> (res: T, err: io.Error) {
size :: size_of(T);
// Get current position to read from.
curr, e1 := z.input->impl_seek(0, .Current);
if e1 != .None {
return T{}, e1;
}
r, e2 := io.to_reader_at(z.input);
if !e2 {
return T{}, .Empty;
}
when size <= 128 {
b: [size]u8;
} else {
b := make([]u8, size, context.temp_allocator);
}
_, e3 := io.read_at(r, b[:], curr);
if e3 != .None {
return T{}, .Empty;
}
res = (^T)(&b[0])^;
return res, .None;
}
peek_data :: proc{peek_data_from_memory, peek_data_from_stream};
// Sliding window read back
@(optimization_mode="speed")
peek_back_byte :: #force_inline proc(z: ^$C, offset: i64) -> (res: u8, err: io.Error) {
// Look back into the sliding window.
return z.output.buf[z.bytes_written - offset], .None;
}
// Generalized bit reader LSB
@(optimization_mode="speed")
refill_lsb_from_memory :: #force_inline proc(z: ^Context_Memory_Input, width := i8(48)) {
refill := u64(width);
b := u64(0);
if z.num_bits > refill {
return;
}
for {
if len(z.input_data) != 0 {
b = u64(z.input_data[0]);
z.input_data = z.input_data[1:];
} else {
b = 0;
}
z.code_buffer |= b << u8(z.num_bits);
z.num_bits += 8;
if z.num_bits > refill {
break;
}
}
}
// Generalized bit reader LSB
@(optimization_mode="speed")
refill_lsb_from_stream :: proc(z: ^Context_Stream_Input, width := i8(24)) {
refill := u64(width);
for {
if z.num_bits > refill {
break;
}
if z.code_buffer == 0 && z.num_bits > 63 {
z.num_bits = 0;
}
if z.code_buffer >= 1 << uint(z.num_bits) {
// Code buffer is malformed.
z.num_bits = max(u64);
return;
}
b, err := read_u8(z);
if err != .None {
// This is fine at the end of the file.
return;
}
z.code_buffer |= (u64(b) << u8(z.num_bits));
z.num_bits += 8;
}
}
refill_lsb :: proc{refill_lsb_from_memory, refill_lsb_from_stream};
@(optimization_mode="speed")
consume_bits_lsb_from_memory :: #force_inline proc(z: ^Context_Memory_Input, width: u8) {
z.code_buffer >>= width;
z.num_bits -= u64(width);
}
@(optimization_mode="speed")
consume_bits_lsb_from_stream :: #force_inline proc(z: ^Context_Stream_Input, width: u8) {
z.code_buffer >>= width;
z.num_bits -= u64(width);
}
consume_bits_lsb :: proc{consume_bits_lsb_from_memory, consume_bits_lsb_from_stream};
@(optimization_mode="speed")
peek_bits_lsb_from_memory :: #force_inline proc(z: ^Context_Memory_Input, width: u8) -> u32 {
if z.num_bits < u64(width) {
refill_lsb(z);
}
return u32(z.code_buffer & ~(~u64(0) << width));
}
@(optimization_mode="speed")
peek_bits_lsb_from_stream :: #force_inline proc(z: ^Context_Stream_Input, width: u8) -> u32 {
if z.num_bits < u64(width) {
refill_lsb(z);
}
return u32(z.code_buffer & ~(~u64(0) << width));
}
peek_bits_lsb :: proc{peek_bits_lsb_from_memory, peek_bits_lsb_from_stream};
@(optimization_mode="speed")
peek_bits_no_refill_lsb_from_memory :: #force_inline proc(z: ^Context_Memory_Input, width: u8) -> u32 {
assert(z.num_bits >= u64(width));
return u32(z.code_buffer & ~(~u64(0) << width));
}
@(optimization_mode="speed")
peek_bits_no_refill_lsb_from_stream :: #force_inline proc(z: ^Context_Stream_Input, width: u8) -> u32 {
assert(z.num_bits >= u64(width));
return u32(z.code_buffer & ~(~u64(0) << width));
}
peek_bits_no_refill_lsb :: proc{peek_bits_no_refill_lsb_from_memory, peek_bits_no_refill_lsb_from_stream};
@(optimization_mode="speed")
read_bits_lsb_from_memory :: #force_inline proc(z: ^Context_Memory_Input, width: u8) -> u32 {
k := #force_inline peek_bits_lsb(z, width);
#force_inline consume_bits_lsb(z, width);
return k;
}
@(optimization_mode="speed")
read_bits_lsb_from_stream :: #force_inline proc(z: ^Context_Stream_Input, width: u8) -> u32 {
k := peek_bits_lsb(z, width);
consume_bits_lsb(z, width);
return k;
}
read_bits_lsb :: proc{read_bits_lsb_from_memory, read_bits_lsb_from_stream};
@(optimization_mode="speed")
read_bits_no_refill_lsb_from_memory :: #force_inline proc(z: ^Context_Memory_Input, width: u8) -> u32 {
k := #force_inline peek_bits_no_refill_lsb(z, width);
#force_inline consume_bits_lsb(z, width);
return k;
}
@(optimization_mode="speed")
read_bits_no_refill_lsb_from_stream :: #force_inline proc(z: ^Context_Stream_Input, width: u8) -> u32 {
k := peek_bits_no_refill_lsb(z, width);
consume_bits_lsb(z, width);
return k;
}
read_bits_no_refill_lsb :: proc{read_bits_no_refill_lsb_from_memory, read_bits_no_refill_lsb_from_stream};
@(optimization_mode="speed")
discard_to_next_byte_lsb_from_memory :: proc(z: ^Context_Memory_Input) {
discard := u8(z.num_bits & 7);
#force_inline consume_bits_lsb(z, discard);
}
@(optimization_mode="speed")
discard_to_next_byte_lsb_from_stream :: proc(z: ^Context_Stream_Input) {
discard := u8(z.num_bits & 7);
consume_bits_lsb(z, discard);
}
discard_to_next_byte_lsb :: proc{discard_to_next_byte_lsb_from_memory, discard_to_next_byte_lsb_from_stream};
+89
View File
@@ -0,0 +1,89 @@
//+ignore
package gzip
/*
Copyright 2021 Jeroen van Rijn <nom@duclavier.com>.
Made available under Odin's BSD-2 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(slice=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);
}
+367
View File
@@ -0,0 +1,367 @@
package gzip
/*
Copyright 2021 Jeroen van Rijn <nom@duclavier.com>.
Made available under Odin's BSD-2 license.
List of contributors:
Jeroen van Rijn: Initial implementation.
This package implements support for the GZIP file format v4.3,
as specified in RFC 1952.
It is implemented in such a way that it lends itself naturally
to be the input to a complementary TAR implementation.
*/
import "core:compress/zlib"
import "core:compress"
import "core:os"
import "core:io"
import "core:bytes"
import "core:hash"
Magic :: enum u16le {
GZIP = 0x8b << 8 | 0x1f,
}
Header :: struct #packed {
magic: Magic,
compression_method: Compression,
flags: Header_Flags,
modification_time: u32le,
xfl: Compression_Flags,
os: OS,
}
#assert(size_of(Header) == 10);
Header_Flag :: enum u8 {
// Order is important
text = 0,
header_crc = 1,
extra = 2,
name = 3,
comment = 4,
reserved_1 = 5,
reserved_2 = 6,
reserved_3 = 7,
}
Header_Flags :: distinct bit_set[Header_Flag; u8];
OS :: enum u8 {
FAT = 0,
Amiga = 1,
VMS = 2,
Unix = 3,
VM_CMS = 4,
Atari_TOS = 5,
HPFS = 6,
Macintosh = 7,
Z_System = 8,
CP_M = 9,
TOPS_20 = 10,
NTFS = 11,
QDOS = 12,
Acorn_RISCOS = 13,
_Unknown = 14,
Unknown = 255,
}
OS_Name :: #partial [OS]string{
.FAT = "FAT",
.Amiga = "Amiga",
.VMS = "VMS/OpenVMS",
.Unix = "Unix",
.VM_CMS = "VM/CMS",
.Atari_TOS = "Atari TOS",
.HPFS = "HPFS",
.Macintosh = "Macintosh",
.Z_System = "Z-System",
.CP_M = "CP/M",
.TOPS_20 = "TOPS-20",
.NTFS = "NTFS",
.QDOS = "QDOS",
.Acorn_RISCOS = "Acorn RISCOS",
.Unknown = "Unknown",
};
Compression :: enum u8 {
DEFLATE = 8,
}
Compression_Flags :: enum u8 {
Maximum_Compression = 2,
Fastest_Compression = 4,
}
Error :: compress.Error;
E_General :: compress.General_Error;
E_GZIP :: compress.GZIP_Error;
E_ZLIB :: compress.ZLIB_Error;
E_Deflate :: compress.Deflate_Error;
GZIP_MAX_PAYLOAD_SIZE :: int(max(u32le));
load :: proc{load_from_slice, load_from_file, load_from_context};
load_from_file :: proc(filename: string, buf: ^bytes.Buffer, expected_output_size := -1, allocator := context.allocator) -> (err: Error) {
data, ok := os.read_entire_file(filename, allocator);
defer delete(data);
err = E_General.File_Not_Found;
if ok {
err = load_from_slice(data, buf, len(data), expected_output_size, allocator);
}
return;
}
load_from_slice :: proc(slice: []u8, buf: ^bytes.Buffer, known_gzip_size := -1, expected_output_size := -1, allocator := context.allocator) -> (err: Error) {
buf := buf;
z := &compress.Context_Memory_Input{
input_data = slice,
output = buf,
};
return load_from_context(z, buf, known_gzip_size, expected_output_size, allocator);
}
load_from_context :: proc(z: ^$C, buf: ^bytes.Buffer, known_gzip_size := -1, expected_output_size := -1, allocator := context.allocator) -> (err: Error) {
buf := buf;
expected_output_size := expected_output_size;
input_data_consumed := 0;
z.output = buf;
if expected_output_size > GZIP_MAX_PAYLOAD_SIZE {
return E_GZIP.Payload_Size_Exceeds_Max_Payload;
}
if expected_output_size > compress.COMPRESS_OUTPUT_ALLOCATE_MAX {
return E_GZIP.Output_Exceeds_COMPRESS_OUTPUT_ALLOCATE_MAX;
}
b: []u8;
header, e := compress.read_data(z, Header);
if e != .None {
return E_General.File_Too_Short;
}
input_data_consumed += size_of(Header);
if header.magic != .GZIP {
return E_GZIP.Invalid_GZIP_Signature;
}
if header.compression_method != .DEFLATE {
return E_General.Unknown_Compression_Method;
}
if header.os >= ._Unknown {
header.os = .Unknown;
}
if .reserved_1 in header.flags || .reserved_2 in header.flags || .reserved_3 in header.flags {
return E_GZIP.Reserved_Flag_Set;
}
// printf("signature: %v\n", header.magic);
// printf("compression: %v\n", header.compression_method);
// printf("flags: %v\n", header.flags);
// printf("modification time: %v\n", time.unix(i64(header.modification_time), 0));
// printf("xfl: %v (%v)\n", header.xfl, int(header.xfl));
// printf("os: %v\n", OS_Name[header.os]);
if .extra in header.flags {
xlen, e_extra := compress.read_data(z, u16le);
input_data_consumed += 2;
if e_extra != .None {
return E_General.Stream_Too_Short;
}
// printf("Extra data present (%v bytes)\n", xlen);
if xlen < 4 {
// Minimum length is 2 for ID + 2 for a field length, if set to zero.
return E_GZIP.Invalid_Extra_Data;
}
field_id: [2]u8;
field_length: u16le;
field_error: io.Error;
for xlen >= 4 {
// println("Parsing Extra field(s).");
field_id, field_error = compress.read_data(z, [2]u8);
if field_error != .None {
// printf("Parsing Extra returned: %v\n", field_error);
return E_General.Stream_Too_Short;
}
xlen -= 2;
input_data_consumed += 2;
field_length, field_error = compress.read_data(z, u16le);
if field_error != .None {
// printf("Parsing Extra returned: %v\n", field_error);
return E_General.Stream_Too_Short;
}
xlen -= 2;
input_data_consumed += 2;
if xlen <= 0 {
// We're not going to try and recover by scanning for a ZLIB header.
// Who knows what else is wrong with this file.
return E_GZIP.Invalid_Extra_Data;
}
// printf(" Field \"%v\" of length %v found: ", string(field_id[:]), field_length);
if field_length > 0 {
b, field_error = compress.read_slice(z, int(field_length));
if field_error != .None {
// printf("Parsing Extra returned: %v\n", field_error);
return E_General.Stream_Too_Short;
}
xlen -= field_length;
input_data_consumed += int(field_length);
// printf("%v\n", string(field_data));
}
if xlen != 0 {
return E_GZIP.Invalid_Extra_Data;
}
}
}
if .name in header.flags {
// Should be enough.
name: [1024]u8;
i := 0;
name_error: io.Error;
for i < len(name) {
b, name_error = compress.read_slice(z, 1);
if name_error != .None {
return E_General.Stream_Too_Short;
}
input_data_consumed += 1;
if b[0] == 0 {
break;
}
name[i] = b[0];
i += 1;
if i >= len(name) {
return E_GZIP.Original_Name_Too_Long;
}
}
// printf("Original filename: %v\n", string(name[:i]));
}
if .comment in header.flags {
// Should be enough.
comment: [1024]u8;
i := 0;
comment_error: io.Error;
for i < len(comment) {
b, comment_error = compress.read_slice(z, 1);
if comment_error != .None {
return E_General.Stream_Too_Short;
}
input_data_consumed += 1;
if b[0] == 0 {
break;
}
comment[i] = b[0];
i += 1;
if i >= len(comment) {
return E_GZIP.Comment_Too_Long;
}
}
// printf("Comment: %v\n", string(comment[:i]));
}
if .header_crc in header.flags {
crc_error: io.Error;
_, crc_error = compress.read_slice(z, 2);
input_data_consumed += 2;
if crc_error != .None {
return E_General.Stream_Too_Short;
}
/*
We don't actually check the CRC16 (lower 2 bytes of CRC32 of header data until the CRC field).
If we find a gzip file in the wild that sets this field, we can add proper support for it.
*/
}
/*
We should have arrived at the ZLIB payload.
*/
payload_u32le: u32le;
// fmt.printf("known_gzip_size: %v | expected_output_size: %v\n", known_gzip_size, expected_output_size);
if expected_output_size > -1 {
/*
We already checked that it's not larger than the output buffer max,
or GZIP length field's max.
We'll just pass it on to `zlib.inflate_raw`;
*/
} else {
/*
If we know the size of the GZIP file *and* it is fully in memory,
then we can peek at the unpacked size at the end.
We'll still want to ensure there's capacity left in the output buffer when we write, of course.
*/
if known_gzip_size > -1 {
offset := i64(known_gzip_size - input_data_consumed - 4);
size, _ := compress.input_size(z);
if size >= offset + 4 {
length_bytes := z.input_data[offset:][:4];
payload_u32le = (^u32le)(&length_bytes[0])^;
expected_output_size = int(payload_u32le);
}
} else {
/*
TODO(Jeroen): When reading a GZIP from a stream, check if impl_seek is present.
If so, we can seek to the end, grab the size from the footer, and seek back to payload start.
*/
}
}
// fmt.printf("GZIP: Expected Payload Size: %v\n", expected_output_size);
zlib_error := zlib.inflate_raw(z=z, expected_output_size=expected_output_size);
if zlib_error != nil {
return zlib_error;
}
/*
Read CRC32 using the ctx bit reader because zlib may leave bytes in there.
*/
compress.discard_to_next_byte_lsb(z);
footer_error: io.Error;
payload_crc_b: [4]u8;
for _, i in payload_crc_b {
payload_crc_b[i], footer_error = compress.read_u8_prefer_code_buffer_lsb(z);
}
payload_crc := transmute(u32le)payload_crc_b;
payload := bytes.buffer_to_bytes(buf);
crc32 := u32le(hash.crc32(payload));
if crc32 != payload_crc {
return E_GZIP.Payload_CRC_Invalid;
}
payload_len_b: [4]u8;
for _, i in payload_len_b {
payload_len_b[i], footer_error = compress.read_u8_prefer_code_buffer_lsb(z);
}
payload_len := transmute(u32le)payload_len_b;
if len(payload) != int(payload_len) {
return E_GZIP.Payload_Length_Invalid;
}
return nil;
}
+52
View File
@@ -0,0 +1,52 @@
//+ignore
package zlib
/*
Copyright 2021 Jeroen van Rijn <nom@duclavier.com>.
Made available under Odin's BSD-2 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, 156, 101, 144, 77, 110, 131, 48, 16, 133, 215, 204, 41, 158, 44,
69, 73, 32, 148, 182, 75, 35, 14, 208, 125, 47, 96, 185, 195, 143,
130, 13, 50, 38, 81, 84, 101, 213, 75, 116, 215, 43, 246, 8, 53,
82, 126, 8, 181, 188, 152, 153, 111, 222, 147, 159, 123, 165, 247, 170,
98, 24, 213, 88, 162, 198, 244, 157, 243, 16, 186, 115, 44, 75, 227,
5, 77, 115, 72, 137, 222, 117, 122, 179, 197, 39, 69, 161, 170, 156,
50, 144, 5, 68, 130, 4, 49, 126, 127, 190, 191, 144, 34, 19, 57,
69, 74, 235, 209, 140, 173, 242, 157, 155, 54, 158, 115, 162, 168, 12,
181, 239, 246, 108, 17, 188, 174, 242, 224, 20, 13, 199, 198, 235, 250,
194, 166, 129, 86, 3, 99, 157, 172, 37, 230, 62, 73, 129, 151, 252,
70, 211, 5, 77, 31, 104, 188, 160, 113, 129, 215, 59, 205, 22, 52,
123, 160, 83, 142, 255, 242, 89, 123, 93, 149, 200, 50, 188, 85, 54,
252, 18, 248, 192, 238, 228, 235, 198, 86, 224, 118, 224, 176, 113, 166,
112, 67, 106, 227, 159, 122, 215, 88, 95, 110, 196, 123, 205, 183, 224,
98, 53, 8, 104, 213, 234, 201, 147, 7, 248, 192, 14, 170, 29, 25,
171, 15, 18, 59, 138, 112, 63, 23, 205, 110, 254, 136, 109, 78, 231,
63, 234, 138, 133, 204,
};
OUTPUT_SIZE :: 438;
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);
}
+676
View File
@@ -0,0 +1,676 @@
package zlib
/*
Copyright 2021 Jeroen van Rijn <nom@duclavier.com>.
Made available under Odin's BSD-2 license.
List of contributors:
Jeroen van Rijn: Initial implementation, optimization.
Ginger Bill: Cosmetic changes.
*/
import "core:compress"
import "core:mem"
import "core:io"
import "core:hash"
import "core:bytes"
/*
zlib.inflate decompresses a ZLIB stream passed in as a []u8 or io.Stream.
Returns: Error.
*/
/*
Do we do Adler32 as we write bytes to output?
It used to be faster to do it inline, now it's faster to do it at the end of `inflate`.
We'll see what's faster after more optimization, and might end up removing
`Context.rolling_hash` if not inlining it is still faster.
*/
Compression_Method :: enum u8 {
DEFLATE = 8,
Reserved = 15,
}
Compression_Level :: enum u8 {
Fastest = 0,
Fast = 1,
Default = 2,
Maximum = 3,
}
Options :: struct {
window_size: u16,
level: u8,
}
Error :: compress.Error;
E_General :: compress.General_Error;
E_ZLIB :: compress.ZLIB_Error;
E_Deflate :: compress.Deflate_Error;
DEFLATE_MAX_CHUNK_SIZE :: 65535;
DEFLATE_MAX_LITERAL_SIZE :: 65535;
DEFLATE_MAX_DISTANCE :: 32768;
DEFLATE_MAX_LENGTH :: 258;
HUFFMAN_MAX_BITS :: 16;
HUFFMAN_FAST_BITS :: 9;
HUFFMAN_FAST_MASK :: ((1 << HUFFMAN_FAST_BITS) - 1);
Z_LENGTH_BASE := [31]u16{
3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,
67,83,99,115,131,163,195,227,258,0,0,
};
Z_LENGTH_EXTRA := [31]u8{
0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,
};
Z_DIST_BASE := [32]u16{
1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,
257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0,
};
Z_DIST_EXTRA := [32]u8{
0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0,
};
Z_LENGTH_DEZIGZAG := []u8{
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15,
};
Z_FIXED_LENGTH := [288]u8{
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,
9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9, 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,
9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9, 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,
9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9, 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,
};
Z_FIXED_DIST := [32]u8{
5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
};
/*
Accelerate all cases in default tables.
*/
ZFAST_BITS :: 9;
ZFAST_MASK :: ((1 << ZFAST_BITS) - 1);
/*
ZLIB-style Huffman encoding.
JPEG packs from left, ZLIB from right. We can't share code.
*/
Huffman_Table :: struct {
fast: [1 << ZFAST_BITS]u16,
firstcode: [16]u16,
maxcode: [17]int,
firstsymbol: [16]u16,
size: [288]u8,
value: [288]u16,
};
// Implementation starts here
@(optimization_mode="speed")
z_bit_reverse :: #force_inline proc(n: u16, bits: u8) -> (r: u16) {
assert(bits <= 16);
// NOTE: Can optimize with llvm.bitreverse.i64 or some bit twiddling
// by reversing all of the bits and masking out the unneeded ones.
r = n;
r = ((r & 0xAAAA) >> 1) | ((r & 0x5555) << 1);
r = ((r & 0xCCCC) >> 2) | ((r & 0x3333) << 2);
r = ((r & 0xF0F0) >> 4) | ((r & 0x0F0F) << 4);
r = ((r & 0xFF00) >> 8) | ((r & 0x00FF) << 8);
r >>= (16 - bits);
return;
}
@(optimization_mode="speed")
grow_buffer :: proc(buf: ^[dynamic]u8) -> (err: compress.Error) {
/*
That we get here at all means that we didn't pass an expected output size,
or that it was too little.
*/
/*
Double until we reach the maximum allowed.
*/
new_size := min(len(buf) << 1, compress.COMPRESS_OUTPUT_ALLOCATE_MAX);
resize(buf, new_size);
if len(buf) != new_size {
/*
Resize failed.
*/
return .Resize_Failed;
}
return nil;
}
/*
TODO: Make these return compress.Error.
*/
@(optimization_mode="speed")
write_byte :: #force_inline proc(z: ^$C, c: u8) -> (err: io.Error) #no_bounds_check {
/*
Resize if needed.
*/
if int(z.bytes_written) + 1 >= len(z.output.buf) {
e := grow_buffer(&z.output.buf);
if e != nil {
return .Short_Write;
}
}
#no_bounds_check {
z.output.buf[z.bytes_written] = c;
}
z.bytes_written += 1;
return .None;
}
@(optimization_mode="speed")
repl_byte :: proc(z: ^$C, count: u16, c: u8) -> (err: io.Error) #no_bounds_check {
/*
TODO(Jeroen): Once we have a magic ring buffer, we can just peek/write into it
without having to worry about wrapping, so no need for a temp allocation to give to
the output stream, just give it _that_ slice.
*/
/*
Resize if needed.
*/
if int(z.bytes_written) + int(count) >= len(z.output.buf) {
e := grow_buffer(&z.output.buf);
if e != nil {
return .Short_Write;
}
}
#no_bounds_check {
for _ in 0..<count {
z.output.buf[z.bytes_written] = c;
z.bytes_written += 1;
}
}
return .None;
}
@(optimization_mode="speed")
repl_bytes :: proc(z: ^$C, count: u16, distance: u16) -> (err: io.Error) {
/*
TODO(Jeroen): Once we have a magic ring buffer, we can just peek/write into it
without having to worry about wrapping, so no need for a temp allocation to give to
the output stream, just give it _that_ slice.
*/
offset := i64(distance);
if int(z.bytes_written) + int(count) >= len(z.output.buf) {
e := grow_buffer(&z.output.buf);
if e != nil {
return .Short_Write;
}
}
#no_bounds_check {
for _ in 0..<count {
c := z.output.buf[z.bytes_written - offset];
z.output.buf[z.bytes_written] = c;
z.bytes_written += 1;
}
}
return .None;
}
allocate_huffman_table :: proc(allocator := context.allocator) -> (z: ^Huffman_Table, err: Error) {
return new(Huffman_Table, allocator), nil;
}
@(optimization_mode="speed")
build_huffman :: proc(z: ^Huffman_Table, code_lengths: []u8) -> (err: Error) {
sizes: [HUFFMAN_MAX_BITS+1]int;
next_code: [HUFFMAN_MAX_BITS]int;
k := int(0);
mem.zero_slice(sizes[:]);
mem.zero_slice(z.fast[:]);
for v in code_lengths {
sizes[v] += 1;
}
sizes[0] = 0;
for i in 1..<(HUFFMAN_MAX_BITS+1) {
if sizes[i] > (1 << uint(i)) {
return E_Deflate.Huffman_Bad_Sizes;
}
}
code := int(0);
for i in 1..<HUFFMAN_MAX_BITS {
next_code[i] = code;
z.firstcode[i] = u16(code);
z.firstsymbol[i] = u16(k);
code = code + sizes[i];
if sizes[i] != 0 {
if code - 1 >= (1 << u16(i)) {
return E_Deflate.Huffman_Bad_Code_Lengths;
}
}
z.maxcode[i] = code << (HUFFMAN_MAX_BITS - uint(i));
code <<= 1;
k += int(sizes[i]);
}
z.maxcode[HUFFMAN_MAX_BITS] = 0x10000; // Sentinel
c: int;
for v, ci in code_lengths {
if v != 0 {
c = next_code[v] - int(z.firstcode[v]) + int(z.firstsymbol[v]);
fastv := u16((u16(v) << 9) | u16(ci));
z.size[c] = u8(v);
z.value[c] = u16(ci);
if v <= ZFAST_BITS {
j := z_bit_reverse(u16(next_code[v]), v);
for j < (1 << ZFAST_BITS) {
z.fast[j] = fastv;
j += (1 << v);
}
}
next_code[v] += 1;
}
}
return nil;
}
@(optimization_mode="speed")
decode_huffman_slowpath :: proc(z: ^$C, t: ^Huffman_Table) -> (r: u16, err: Error) #no_bounds_check {
code := u16(compress.peek_bits_lsb(z,16));
k := int(z_bit_reverse(code, 16));
s: u8;
#no_bounds_check for s = HUFFMAN_FAST_BITS+1; ; {
if k < t.maxcode[s] {
break;
}
s += 1;
}
if s >= 16 {
return 0, E_Deflate.Bad_Huffman_Code;
}
// code size is s, so:
b := (k >> (16-s)) - int(t.firstcode[s]) + int(t.firstsymbol[s]);
if b >= size_of(t.size) {
return 0, E_Deflate.Bad_Huffman_Code;
}
if t.size[b] != s {
return 0, E_Deflate.Bad_Huffman_Code;
}
compress.consume_bits_lsb(z, s);
r = t.value[b];
return r, nil;
}
@(optimization_mode="speed")
decode_huffman :: proc(z: ^$C, t: ^Huffman_Table) -> (r: u16, err: Error) #no_bounds_check {
if z.num_bits < 16 {
if z.num_bits > 63 {
return 0, E_ZLIB.Code_Buffer_Malformed;
}
compress.refill_lsb(z);
if z.num_bits > 63 {
return 0, E_General.Stream_Too_Short;
}
}
#no_bounds_check b := t.fast[z.code_buffer & ZFAST_MASK];
if b != 0 {
s := u8(b >> ZFAST_BITS);
compress.consume_bits_lsb(z, s);
return b & 511, nil;
}
return decode_huffman_slowpath(z, t);
}
@(optimization_mode="speed")
parse_huffman_block :: proc(z: ^$C, z_repeat, z_offset: ^Huffman_Table) -> (err: Error) #no_bounds_check {
#no_bounds_check for {
value, e := decode_huffman(z, z_repeat);
if e != nil {
return err;
}
if value < 256 {
e := write_byte(z, u8(value));
if e != .None {
return E_General.Output_Too_Short;
}
} else {
if value == 256 {
// End of block
return nil;
}
value -= 257;
length := Z_LENGTH_BASE[value];
if Z_LENGTH_EXTRA[value] > 0 {
length += u16(compress.read_bits_lsb(z, Z_LENGTH_EXTRA[value]));
}
value, e = decode_huffman(z, z_offset);
if e != nil {
return E_Deflate.Bad_Huffman_Code;
}
distance := Z_DIST_BASE[value];
if Z_DIST_EXTRA[value] > 0 {
distance += u16(compress.read_bits_lsb(z, Z_DIST_EXTRA[value]));
}
if z.bytes_written < i64(distance) {
// Distance is longer than we've decoded so far.
return E_Deflate.Bad_Distance;
}
/*
These might be sped up with a repl_byte call that copies
from the already written output more directly, and that
update the Adler checksum once after.
That way we'd suffer less Stream vtable overhead.
*/
if distance == 1 {
/*
Replicate the last outputted byte, length times.
*/
if length > 0 {
c := z.output.buf[z.bytes_written - i64(distance)];
e := repl_byte(z, length, c);
if e != .None {
return E_General.Output_Too_Short;
}
}
} else {
if length > 0 {
e := repl_bytes(z, length, distance);
if e != .None {
return E_General.Output_Too_Short;
}
}
}
}
}
}
@(optimization_mode="speed")
inflate_from_context :: proc(using ctx: ^compress.Context_Memory_Input, raw := false, expected_output_size := -1, allocator := context.allocator) -> (err: Error) #no_bounds_check {
/*
ctx.output must be a bytes.Buffer for now. We'll add a separate implementation that writes to a stream.
raw determines whether the ZLIB header is processed, or we're inflating a raw
DEFLATE stream.
*/
if !raw {
size, size_err := compress.input_size(ctx);
if size < 6 || size_err != nil {
return E_General.Stream_Too_Short;
}
cmf, _ := compress.read_u8(ctx);
method := Compression_Method(cmf & 0xf);
if method != .DEFLATE {
return E_General.Unknown_Compression_Method;
}
if cinfo := (cmf >> 4) & 0xf; cinfo > 7 {
return E_ZLIB.Unsupported_Window_Size;
}
flg, _ := compress.read_u8(ctx);
fcheck := flg & 0x1f;
fcheck_computed := (cmf << 8 | flg) & 0x1f;
if fcheck != fcheck_computed {
return E_General.Checksum_Failed;
}
/*
We don't handle built-in dictionaries for now.
They're application specific and PNG doesn't use them.
*/
if fdict := (flg >> 5) & 1; fdict != 0 {
return E_ZLIB.FDICT_Unsupported;
}
// flevel := Compression_Level((flg >> 6) & 3);
/*
Inflate can consume bits belonging to the Adler checksum.
We pass the entire stream to Inflate and will unget bytes if we need to
at the end to compare checksums.
*/
}
// Parse ZLIB stream without header.
inflate_raw(z=ctx, expected_output_size=expected_output_size) or_return;
if !raw {
compress.discard_to_next_byte_lsb(ctx);
adler_b: [4]u8;
for _, i in adler_b {
adler_b[i], _ = compress.read_u8_prefer_code_buffer_lsb(ctx);
}
adler := transmute(u32be)adler_b;
output_hash := hash.adler32(ctx.output.buf[:]);
if output_hash != u32(adler) {
return E_General.Checksum_Failed;
}
}
return nil;
}
// TODO: Check alignment of reserve/resize.
@(optimization_mode="speed")
inflate_raw :: proc(z: ^$C, expected_output_size := -1, allocator := context.allocator) -> (err: Error) #no_bounds_check {
expected_output_size := expected_output_size;
/*
Always set up a minimum allocation size.
*/
expected_output_size = max(max(expected_output_size, compress.COMPRESS_OUTPUT_ALLOCATE_MIN), 512);
// fmt.printf("\nZLIB: Expected Payload Size: %v\n\n", expected_output_size);
if expected_output_size > 0 && expected_output_size <= compress.COMPRESS_OUTPUT_ALLOCATE_MAX {
/*
Try to pre-allocate the output buffer.
*/
reserve(&z.output.buf, expected_output_size);
resize (&z.output.buf, expected_output_size);
};
if len(z.output.buf) != expected_output_size {
return .Resize_Failed;
}
z.num_bits = 0;
z.code_buffer = 0;
z_repeat: ^Huffman_Table;
z_offset: ^Huffman_Table;
codelength_ht: ^Huffman_Table;
defer free(z_repeat);
defer free(z_offset);
defer free(codelength_ht);
z_repeat = allocate_huffman_table(allocator=context.allocator) or_return;
z_offset = allocate_huffman_table(allocator=context.allocator) or_return;
codelength_ht = allocate_huffman_table(allocator=context.allocator) or_return;
final := u32(0);
type := u32(0);
for {
final = compress.read_bits_lsb(z, 1);
type = compress.read_bits_lsb(z, 2);
// fmt.printf("Final: %v | Type: %v\n", final, type);
switch type {
case 0:
// Uncompressed block
// Discard bits until next byte boundary
compress.discard_to_next_byte_lsb(z);
uncompressed_len := i16(compress.read_bits_lsb(z, 16));
length_check := i16(compress.read_bits_lsb(z, 16));
// fmt.printf("LEN: %v, ~LEN: %v, NLEN: %v, ~NLEN: %v\n", uncompressed_len, ~uncompressed_len, length_check, ~length_check);
if ~uncompressed_len != length_check {
return E_Deflate.Len_Nlen_Mismatch;
}
/*
TODO: Maybe speed this up with a stream-to-stream copy (read_from)
and a single Adler32 update after.
*/
#no_bounds_check for uncompressed_len > 0 {
compress.refill_lsb(z);
lit := compress.read_bits_lsb(z, 8);
write_byte(z, u8(lit));
uncompressed_len -= 1;
}
case 3:
return E_Deflate.BType_3;
case:
// log.debugf("Err: %v | Final: %v | Type: %v\n", err, final, type);
if type == 1 {
// Use fixed code lengths.
build_huffman(z_repeat, Z_FIXED_LENGTH[:]) or_return;
build_huffman(z_offset, Z_FIXED_DIST[:]) or_return;
} else {
lencodes: [286+32+137]u8;
codelength_sizes: [19]u8;
//i: u32;
n: u32;
compress.refill_lsb(z, 14);
hlit := compress.read_bits_no_refill_lsb(z, 5) + 257;
hdist := compress.read_bits_no_refill_lsb(z, 5) + 1;
hclen := compress.read_bits_no_refill_lsb(z, 4) + 4;
ntot := hlit + hdist;
#no_bounds_check for i in 0..<hclen {
s := compress.read_bits_lsb(z, 3);
codelength_sizes[Z_LENGTH_DEZIGZAG[i]] = u8(s);
}
build_huffman(codelength_ht, codelength_sizes[:]) or_return;
n = 0;
c: u16;
for n < ntot {
c = decode_huffman(z, codelength_ht) or_return;
if c < 0 || c >= 19 {
return E_Deflate.Huffman_Bad_Code_Lengths;
}
if c < 16 {
lencodes[n] = u8(c);
n += 1;
} else {
fill := u8(0);
compress.refill_lsb(z, 7);
switch c {
case 16:
c = u16(compress.read_bits_no_refill_lsb(z, 2) + 3);
if n == 0 {
return E_Deflate.Huffman_Bad_Code_Lengths;
}
fill = lencodes[n - 1];
case 17:
c = u16(compress.read_bits_no_refill_lsb(z, 3) + 3);
case 18:
c = u16(compress.read_bits_no_refill_lsb(z, 7) + 11);
case:
return E_Deflate.Huffman_Bad_Code_Lengths;
}
if ntot - n < u32(c) {
return E_Deflate.Huffman_Bad_Code_Lengths;
}
nc := n + u32(c);
#no_bounds_check for ; n < nc; n += 1 {
lencodes[n] = fill;
}
}
}
if n != ntot {
return E_Deflate.Huffman_Bad_Code_Lengths;
}
build_huffman(z_repeat, lencodes[:hlit]) or_return;
build_huffman(z_offset, lencodes[hlit:ntot]) or_return;
}
parse_huffman_block(z, z_repeat, z_offset) or_return;
}
if final == 1 {
break;
}
}
if int(z.bytes_written) != len(z.output.buf) {
resize(&z.output.buf, int(z.bytes_written));
}
return nil;
}
inflate_from_byte_array :: proc(input: []u8, buf: ^bytes.Buffer, raw := false, expected_output_size := -1) -> (err: Error) {
ctx := compress.Context_Memory_Input{};
ctx.input_data = input;
ctx.output = buf;
return inflate_from_context(ctx=&ctx, raw=raw, expected_output_size=expected_output_size);
}
inflate_from_byte_array_raw :: proc(input: []u8, buf: ^bytes.Buffer, raw := false, expected_output_size := -1) -> (err: Error) {
ctx := compress.Context_Memory_Input{};
ctx.input_data = input;
ctx.output = buf;
return inflate_raw(z=&ctx, expected_output_size=expected_output_size);
}
inflate :: proc{inflate_from_context, inflate_from_byte_array};
+216
View File
@@ -0,0 +1,216 @@
package container
import "core:mem"
import "core:runtime"
Array :: struct($T: typeid) {
data: ^T,
len: int,
cap: int,
allocator: mem.Allocator,
}
ARRAY_DEFAULT_CAPACITY :: 16;
/*
array_init :: proc {
array_init_none,
array_init_len,
array_init_len_cap,
}
array_init
array_delete
array_len
array_cap
array_space
array_slice
array_get
array_get_ptr
array_set
array_reserve
array_resize
array_push = array_append :: proc{
array_push_back,
array_push_back_elems,
}
array_push_front
array_pop_back
array_pop_front
array_consume
array_trim
array_clear
array_clone
array_set_capacity
array_grow
*/
array_init_none :: proc(a: ^$A/Array, allocator := context.allocator) {
array_init_len_cap(a, 0, ARRAY_DEFAULT_CAPACITY, allocator);
}
array_init_len :: proc(a: ^$A/Array, len: int, allocator := context.allocator) {
array_init_len_cap(a, len, len, allocator);
}
array_init_len_cap :: proc(a: ^$A/Array($T), len: int, cap: int, allocator := context.allocator) {
a.allocator = allocator;
a.data = (^T)(mem.alloc(size_of(T)*cap, align_of(T), a.allocator));
a.len = len;
a.cap = cap;
}
array_init :: proc{array_init_none, array_init_len, array_init_len_cap};
array_delete :: proc(a: $A/Array) {
mem.free(a.data, a.allocator);
}
array_len :: proc(a: $A/Array) -> int {
return a.len;
}
array_cap :: proc(a: $A/Array) -> int {
return a.cap;
}
array_space :: proc(a: $A/Array) -> int {
return a.cap - a.len;
}
array_slice :: proc(a: $A/Array($T)) -> []T {
s := mem.Raw_Slice{a.data, a.len};
return transmute([]T)s;
}
array_cap_slice :: proc(a: $A/Array($T)) -> []T {
s := mem.Raw_Slice{a.data, a.cap};
return transmute([]T)s;
}
array_get :: proc(a: $A/Array($T), index: int, loc := #caller_location) -> T {
runtime.bounds_check_error_loc(loc, index, array_len(a));
return (^T)(uintptr(a.data) + size_of(T)*uintptr(index))^;
}
array_get_ptr :: proc(a: $A/Array($T), index: int, loc := #caller_location) -> ^T {
runtime.bounds_check_error_loc(loc, index, array_len(a));
return (^T)(uintptr(a.data) + size_of(T)*uintptr(index));
}
array_set :: proc(a: ^$A/Array($T), index: int, item: T, loc := #caller_location) {
runtime.bounds_check_error_loc(loc, index, array_len(a^));
(^T)(uintptr(a.data) + size_of(T)*uintptr(index))^ = item;
}
array_reserve :: proc(a: ^$A/Array, capacity: int) {
if capacity > a.len {
array_set_capacity(a, capacity);
}
}
array_resize :: proc(a: ^$A/Array, length: int) {
if length > a.len {
array_set_capacity(a, length);
}
a.len = length;
}
array_push_back :: proc(a: ^$A/Array($T), item: T) {
if array_space(a^) == 0 {
array_grow(a);
}
a.len += 1;
array_set(a, a.len-1, item);
}
array_push_front :: proc(a: ^$A/Array($T), item: T) {
if array_space(a^) == 0 {
array_grow(a);
}
a.len += 1;
data := array_slice(a^);
copy(data[1:], data[:]);
data[0] = item;
}
array_pop_back :: proc(a: ^$A/Array($T), loc := #caller_location) -> T {
assert(condition=a.len > 0, loc=loc);
item := array_get(a^, a.len-1);
a.len -= 1;
return item;
}
array_pop_front :: proc(a: ^$A/Array($T), loc := #caller_location) -> T {
assert(condition=a.len > 0, loc=loc);
item := array_get(a^, 0);
s := array_slice(a^);
copy(s[:], s[1:]);
a.len -= 1;
return item;
}
array_consume :: proc(a: ^$A/Array($T), count: int, loc := #caller_location) {
assert(condition=a.len >= count, loc=loc);
a.len -= count;
}
array_trim :: proc(a: ^$A/Array($T)) {
array_set_capacity(a, a.len);
}
array_clear :: proc(a: ^$A/Array($T)) {
array_resize(a, 0);
}
array_clone :: proc(a: $A/Array($T), allocator := context.allocator) -> A {
res: A;
array_init(&res, array_len(a), array_len(a), allocator);
copy(array_slice(res), array_slice(a));
return res;
}
array_push_back_elems :: proc(a: ^$A/Array($T), items: ..T) {
if array_space(a^) < len(items) {
array_grow(a, a.len + len(items));
}
offset := a.len;
data := array_cap_slice(a^);
n := copy(data[a.len:], items);
a.len += n;
}
array_push :: proc{array_push_back, array_push_back_elems};
array_append :: proc{array_push_back, array_push_back_elems};
array_set_capacity :: proc(a: ^$A/Array($T), new_capacity: int) {
if new_capacity == a.cap {
return;
}
if new_capacity < a.len {
array_resize(a, new_capacity);
}
new_data: ^T;
if new_capacity > 0 {
if a.allocator.procedure == nil {
a.allocator = context.allocator;
}
new_data = (^T)(mem.alloc(size_of(T)*new_capacity, align_of(T), a.allocator));
if new_data != nil {
mem.copy(new_data, a.data, size_of(T)*a.len);
}
}
mem.free(a.data, a.allocator);
a.data = new_data;
a.cap = new_capacity;
}
array_grow :: proc(a: ^$A/Array, min_capacity: int = 0) {
new_capacity := max(array_len(a^)*2 + 8, min_capacity);
array_set_capacity(a, new_capacity);
}
+80
View File
@@ -0,0 +1,80 @@
package container
import "core:mem"
Bloom_Hash_Proc :: #type proc(data: []byte) -> u32;
Bloom_Hash :: struct {
hash_proc: Bloom_Hash_Proc,
next: ^Bloom_Hash,
}
Bloom_Filter :: struct {
allocator: mem.Allocator,
hash: ^Bloom_Hash,
bits: []byte,
}
bloom_filter_init :: proc(b: ^Bloom_Filter, size: int, allocator := context.allocator) {
b.allocator = allocator;
b.bits = make([]byte, size, allocator);
}
bloom_filter_destroy :: proc(b: ^Bloom_Filter) {
context.allocator = b.allocator;
delete(b.bits);
for b.hash != nil {
hash := b.hash;
b.hash = b.hash.next;
free(hash);
}
}
bloom_filter_add_hash_proc :: proc(b: ^Bloom_Filter, hash_proc: Bloom_Hash_Proc) {
context.allocator = b.allocator;
h := new(Bloom_Hash);
h.hash_proc = hash_proc;
head := &b.hash;
for head^ != nil {
head = &(head^.next);
}
head^ = h;
}
bloom_filter_add :: proc(b: ^Bloom_Filter, item: []byte) {
#no_bounds_check for h := b.hash; h != nil; h = h.next {
hash := h.hash_proc(item);
hash %= u32(len(b.bits) * 8);
b.bits[hash >> 3] |= 1 << (hash & 3);
}
}
bloom_filter_add_string :: proc(b: ^Bloom_Filter, item: string) {
bloom_filter_add(b, transmute([]byte)item);
}
bloom_filter_add_raw :: proc(b: ^Bloom_Filter, data: rawptr, size: int) {
item := mem.slice_ptr((^byte)(data), size);
bloom_filter_add(b, item);
}
bloom_filter_test :: proc(b: ^Bloom_Filter, item: []byte) -> bool {
#no_bounds_check for h := b.hash; h != nil; h = h.next {
hash := h.hash_proc(item);
hash %= u32(len(b.bits) * 8);
if (b.bits[hash >> 3] & (1 << (hash & 3)) == 0) {
return false;
}
}
return true;
}
bloom_filter_test_string :: proc(b: ^Bloom_Filter, item: string) -> bool {
return bloom_filter_test(b, transmute([]byte)item);
}
bloom_filter_test_raw :: proc(b: ^Bloom_Filter, data: rawptr, size: int) -> bool {
item := mem.slice_ptr((^byte)(data), size);
return bloom_filter_test(b, item);
}
+377
View File
@@ -0,0 +1,377 @@
package container
import "core:intrinsics"
_ :: intrinsics;
Map :: struct($Key, $Value: typeid) where intrinsics.type_is_valid_map_key(Key) {
hash: Array(int),
entries: Array(Map_Entry(Key, Value)),
}
Map_Entry :: struct($Key, $Value: typeid) where intrinsics.type_is_valid_map_key(Key) {
hash: uintptr,
next: int,
key: Key,
value: Value,
}
/*
map_init :: proc{
map_init_none,
map_init_cap,
}
map_delete
map_has
map_get
map_get_default
map_get_ptr
map_set
map_remove
map_reserve
map_clear
// Multi Map
multi_map_find_first
multi_map_find_next
multi_map_count
multi_map_get :: proc{
multi_map_get_array,
multi_map_get_slice,
};
multi_map_get_as_slice
multi_map_insert
multi_map_remove
multi_map_remove_all
*/
map_init :: proc{map_init_none, map_init_cap};
map_init_none :: proc(m: ^$M/Map($Key, $Value), allocator := context.allocator) {
m.hash.allocator = allocator;
m.entries.allocator = allocator;
}
map_init_cap :: proc(m: ^$M/Map($Key, $Value), cap: int, allocator := context.allocator) {
m.hash.allocator = allocator;
m.entries.allocator = allocator;
map_reserve(m, cap);
}
map_delete :: proc(m: $M/Map($Key, $Value)) {
array_delete(m.hash);
array_delete(m.entries);
}
map_has :: proc(m: $M/Map($Key, $Value), key: Key) -> bool {
return _map_find_or_fail(m, key) >= 0;
}
map_get :: proc(m: $M/Map($Key, $Value), key: Key) -> (res: Value, ok: bool) #optional_ok {
i := _map_find_or_fail(m, key);
if i < 0 {
return {}, false;
}
return array_get(m.entries, i).value, true;
}
map_get_default :: proc(m: $M/Map($Key, $Value), key: Key, default: Value) -> (res: Value, ok: bool) #optional_ok {
i := _map_find_or_fail(m, key);
if i < 0 {
return default, false;
}
return array_get(m.entries, i).value, true;
}
map_get_ptr :: proc(m: $M/Map($Key, $Value), key: Key) -> ^Value {
i := _map_find_or_fail(m, key);
if i < 0 {
return nil;
}
return array_get_ptr(m.entries, i).value;
}
map_set :: proc(m: ^$M/Map($Key, $Value), key: Key, value: Value) {
if array_len(m.hash) == 0 {
_map_grow(m);
}
i := _map_find_or_make(m, key);
array_get_ptr(m.entries, i).value = value;
if _map_full(m^) {
_map_grow(m);
}
}
map_remove :: proc(m: ^$M/Map($Key, $Value), key: Key) {
fr := _map_find_key(m^, key);
if fr.entry_index >= 0 {
_map_erase(m, fr);
}
}
map_reserve :: proc(m: ^$M/Map($Key, $Value), new_size: int) {
nm: M;
map_init(&nm, m.hash.allocator);
array_resize(&nm.hash, new_size);
array_reserve(&nm.entries, array_len(m.entries));
for i in 0..<new_size {
array_set(&nm.hash, i, -1);
}
for i in 0..<array_len(m.entries) {
e := array_get(m.entries, i);
multi_map_insert(&nm, e.key, e.value);
}
map_delete(m^);
m^ = nm;
}
map_clear :: proc(m: ^$M/Map($Key, $Value)) {
array_clear(&m.hash);
array_clear(&m.entries);
}
multi_map_find_first :: proc(m: $M/Map($Key, $Value), key: Key) -> ^Map_Entry(Key, Value) {
i := _map_find_or_fail(m, key);
if i < 0 {
return nil;
}
return array_get_ptr(m.entries, i);
}
multi_map_find_next :: proc(m: $M/Map($Key, $Value), e: ^Map_Entry(Key, Value)) -> ^Map_Entry(Key, Value) {
i := e.next;
for i >= 0 {
it := array_get_ptr(m.entries, i);
if it.hash == e.hash && it.key == e.key {
return it;
}
i = it.next;
}
return nil;
}
multi_map_count :: proc(m: $M/Map($Key, $Value), key: Key) -> int {
n := 0;
e := multi_map_find_first(m, key);
for e != nil {
n += 1;
e = multi_map_find_next(m, e);
}
return n;
}
multi_map_get :: proc{multi_map_get_array, multi_map_get_slice};
multi_map_get_array :: proc(m: $M/Map($Key, $Value), key: Key, items: ^Array(Value)) {
if items == nil {
return;
}
e := multi_map_find_first(m, key);
for e != nil {
array_append(items, e.value);
e = multi_map_find_next(m, e);
}
}
multi_map_get_slice :: proc(m: $M/Map($Key, $Value), key: Key, items: []Value) {
e := multi_map_find_first(m, key);
i := 0;
for e != nil && i < len(items) {
items[i] = e.value;
i += 1;
e = multi_map_find_next(m, e);
}
}
multi_map_get_as_slice :: proc(m: $M/Map($Key, $Value), key: Key) -> []Value {
items: Array(Value);
array_init(&items, 0);
e := multi_map_find_first(m, key);
for e != nil {
array_append(&items, e.value);
e = multi_map_find_next(m, e);
}
return array_slice(items);
}
multi_map_insert :: proc(m: ^$M/Map($Key, $Value), key: Key, value: Value) {
if array_len(m.hash) == 0 {
_map_grow(m);
}
i := _map_make(m, key);
array_get_ptr(m.entries, i).value = value;
if _map_full(m^) {
_map_grow(m);
}
}
multi_map_remove :: proc(m: ^$M/Map($Key, $Value), e: ^Map_Entry(Key, Value)) {
fr := _map_find_entry(m, e);
if fr.entry_index >= 0 {
_map_erase(m, fr);
}
}
multi_map_remove_all :: proc(m: ^$M/Map($Key, $Value), key: Key) {
for map_exist(m^, key) {
map_remove(m, key);
}
}
/// Internal
Map_Find_Result :: struct {
hash_index: int,
entry_prev: int,
entry_index: int,
}
_map_add_entry :: proc(m: ^$M/Map($Key, $Value), key: Key) -> int where intrinsics.type_is_valid_map_key(Key) {
hasher := intrinsics.type_hasher_proc(Key);
e: Map_Entry(Key, Value);
e.key = key;
e.hash = hasher(&e.key, 0);
e.next = -1;
idx := array_len(m.entries);
array_push(&m.entries, e);
return idx;
}
_map_erase :: proc(m: ^$M/Map, fr: Map_Find_Result) {
if fr.entry_prev < 0 {
array_set(&m.hash, fr.hash_index, array_get(m.entries, fr.entry_index).next);
} else {
array_get_ptr(m.entries, fr.entry_prev).next = array_get(m.entries, fr.entry_index).next;
}
if fr.entry_index == array_len(m.entries)-1 {
array_pop_back(&m.entries);
return;
}
array_set(&m.entries, fr.entry_index, array_get(m.entries, array_len(m.entries)-1));
last := _map_find_key(m^, array_get(m.entries, fr.entry_index).key);
if last.entry_prev < 0 {
array_get_ptr(m.entries, last.entry_prev).next = fr.entry_index;
} else {
array_set(&m.hash, last.hash_index, fr.entry_index);
}
}
_map_find_key :: proc(m: $M/Map($Key, $Value), key: Key) -> Map_Find_Result where intrinsics.type_is_valid_map_key(Key) {
fr: Map_Find_Result;
fr.hash_index = -1;
fr.entry_prev = -1;
fr.entry_index = -1;
if array_len(m.hash) == 0 {
return fr;
}
hasher := intrinsics.type_hasher_proc(Key);
key := key;
hash := hasher(&key, 0);
fr.hash_index = int(hash % uintptr(array_len(m.hash)));
fr.entry_index = array_get(m.hash, fr.hash_index);
for fr.entry_index >= 0 {
it := array_get_ptr(m.entries, fr.entry_index);
if it.hash == hash && it.key == key {
return fr;
}
fr.entry_prev = fr.entry_index;
fr.entry_index = it.next;
}
return fr;
}
_map_find_entry :: proc(m: ^$M/Map($Key, $Value), e: ^Map_Entry(Key, Value)) -> Map_Find_Result {
fr: Map_Find_Result;
fr.hash_index = -1;
fr.entry_prev = -1;
fr.entry_index = -1;
if array_len(m.hash) == 0 {
return fr;
}
fr.hash_index = int(e.hash % uintptr(array_len(m.hash)));
fr.entry_index = array_get(m.hash, fr.hash_index);
for fr.entry_index >= 0 {
it := array_get_ptr(m.entries, fr.entry_index);
if it == e {
return fr;
}
fr.entry_prev = fr.entry_index;
fr.entry_index = it.next;
}
return fr;
}
_map_find_or_fail :: proc(m: $M/Map($Key, $Value), key: Key) -> int {
return _map_find_key(m, key).entry_index;
}
_map_find_or_make :: proc(m: ^$M/Map($Key, $Value), key: Key) -> int {
fr := _map_find_key(m^, key);
if fr.entry_index >= 0 {
return fr.entry_index;
}
i := _map_add_entry(m, key);
if fr.entry_prev < 0 {
array_set(&m.hash, fr.hash_index, i);
} else {
array_get_ptr(m.entries, fr.entry_prev).next = i;
}
return i;
}
_map_make :: proc(m: ^$M/Map($Key, $Value), key: Key) -> int {
fr := _map_find_key(m^, key);
i := _map_add_entry(m, key);
if fr.entry_prev < 0 {
array_set(&m.hash, fr.hash_index, i);
} else {
array_get_ptr(m.entries, fr.entry_prev).next = i;
}
array_get_ptr(m.entries, i).next = fr.entry_index;
return i;
}
_map_full :: proc(m: $M/Map($Key, $Value)) -> bool {
// TODO(bill): Determine good max load factor
return array_len(m.entries) >= (array_len(m.hash) / 4)*3;
}
_map_grow :: proc(m: ^$M/Map($Key, $Value)) {
new_size := array_len(m.entries) * 4 + 7; // TODO(bill): Determine good grow rate
map_reserve(m, new_size);
}
+113
View File
@@ -0,0 +1,113 @@
package container
Priority_Queue :: struct($T: typeid) {
data: Array(T),
len: int,
priority: proc(item: T) -> int,
}
priority_queue_init_none :: proc(q: ^$Q/Priority_Queue($T), f: proc(item: T) -> int, allocator := context.allocator) {
queue_init_len(q, f, 0, allocator);
}
priority_queue_init_len :: proc(q: ^$Q/Priority_Queue($T), f: proc(item: T) -> int, len: int, allocator := context.allocator) {
queue_init_len_cap(q, f, 0, 16, allocator);
}
priority_queue_init_len_cap :: proc(q: ^$Q/Priority_Queue($T), f: proc(item: T) -> int, len: int, cap: int, allocator := context.allocator) {
array_init(&q.data, len, cap, allocator);
q.len = len;
q.priority = f;
}
priority_queue_init :: proc{priority_queue_init_none, priority_queue_init_len, priority_queue_init_len_cap};
priority_queue_delete :: proc(q: $Q/Priority_Queue($T)) {
array_delete(q.data);
}
priority_queue_clear :: proc(q: ^$Q/Priority_Queue($T)) {
q.len = 0;
}
priority_queue_len :: proc(q: $Q/Priority_Queue($T)) -> int {
return q.len;
}
priority_queue_cap :: proc(q: $Q/Priority_Queue($T)) -> int {
return array_cap(q.data);
}
priority_queue_space :: proc(q: $Q/Priority_Queue($T)) -> int {
return array_len(q.data) - q.len;
}
priority_queue_reserve :: proc(q: ^$Q/Priority_Queue($T), capacity: int) {
if capacity > q.len {
array_resize(&q.data, new_capacity);
}
}
priority_queue_resize :: proc(q: ^$Q/Priority_Queue($T), length: int) {
if length > q.len {
array_resize(&q.data, new_capacity);
}
q.len = length;
}
_priority_queue_grow :: proc(q: ^$Q/Priority_Queue($T), min_capacity: int = 0) {
new_capacity := max(array_len(q.data)*2 + 8, min_capacity);
array_resize(&q.data, new_capacity);
}
priority_queue_push :: proc(q: ^$Q/Priority_Queue($T), item: T) {
if array_len(q.data) - q.len == 0 {
_priority_queue_grow(q);
}
s := array_slice(q.data);
s[q.len] = item;
i := q.len;
for i > 0 {
p := (i - 1) / 2;
if q.priority(s[p]) <= q.priority(item) do break;
s[i] = s[p];
i = p;
}
q.len += 1;
if q.len > 0 do s[i] = item;
}
priority_queue_pop :: proc(q: ^$Q/Priority_Queue($T)) -> T {
assert(q.len > 0);
s := array_slice(q.data);
min := s[0];
root := s[q.len-1];
q.len -= 1;
i := 0;
for i * 2 + 1 < q.len {
a := i * 2 + 1;
b := i * 2 + 2;
c := b < q.len && q.priority(s[b]) < q.priority(s[a]) ? b : a;
if q.priority(s[c]) >= q.priority(root) do break;
s[i] = s[c];
i = c;
}
if q.len > 0 do s[i] = root;
return min;
}
priority_queue_peek :: proc(q: ^$Q/Priority_Queue($T)) -> T {
assert(q.len > 0);
s := array_slice(q.data);
return s[0];
}
+175
View File
@@ -0,0 +1,175 @@
package container
Queue :: struct($T: typeid) {
data: Array(T),
len: int,
offset: int,
}
/*
queue_init :: proc{
queue_init_none,
queue_init_len,
queue_init_len_cap,
}
queue_delete
queue_clear
queue_len
queue_cap
queue_space
queue_get
queue_set
queue_reserve
queue_resize
queue_push :: proc{
queue_push_back,
queue_push_elems,
};
queue_push_front
queue_pop_front
queue_pop_back
queue_consume
*/
queue_init_none :: proc(q: ^$Q/Queue($T), allocator := context.allocator) {
queue_init_len(q, 0, allocator);
}
queue_init_len :: proc(q: ^$Q/Queue($T), len: int, allocator := context.allocator) {
queue_init_len_cap(q, 0, 16, allocator);
}
queue_init_len_cap :: proc(q: ^$Q/Queue($T), len: int, cap: int, allocator := context.allocator) {
array_init(&q.data, len, cap, allocator);
q.len = len;
q.offset = 0;
}
queue_init :: proc{queue_init_none, queue_init_len, queue_init_len_cap};
queue_delete :: proc(q: $Q/Queue($T)) {
array_delete(q.data);
}
queue_clear :: proc(q: ^$Q/Queue($T)) {
q.len = 0;
}
queue_len :: proc(q: $Q/Queue($T)) -> int {
return q.len;
}
queue_cap :: proc(q: $Q/Queue($T)) -> int {
return array_cap(q.data);
}
queue_space :: proc(q: $Q/Queue($T)) -> int {
return array_len(q.data) - q.len;
}
queue_get :: proc(q: $Q/Queue($T), index: int) -> T {
i := (index + q.offset) % array_len(q.data);
data := array_slice(q.data);
return data[i];
}
queue_set :: proc(q: ^$Q/Queue($T), index: int, item: T) {
i := (index + q.offset) % array_len(q.data);
data := array_slice(q.data);
data[i] = item;
}
queue_reserve :: proc(q: ^$Q/Queue($T), capacity: int) {
if capacity > q.len {
_queue_increase_capacity(q, capacity);
}
}
queue_resize :: proc(q: ^$Q/Queue($T), length: int) {
if length > q.len {
_queue_increase_capacity(q, length);
}
q.len = length;
}
queue_push_back :: proc(q: ^$Q/Queue($T), item: T) {
if queue_space(q^) == 0 {
_queue_grow(q);
}
queue_set(q, q.len, item);
q.len += 1;
}
queue_push_front :: proc(q: ^$Q/Queue($T), item: T) {
if queue_space(q^) == 0 {
_queue_grow(q);
}
q.offset = (q.offset - 1 + array_len(q.data)) % array_len(q.data);
q.len += 1;
queue_set(q, 0, item);
}
queue_pop_front :: proc(q: ^$Q/Queue($T)) -> T {
assert(q.len > 0);
item := queue_get(q^, 0);
q.offset = (q.offset + 1) % array_len(q.data);
q.len -= 1;
if q.len == 0 {
q.offset = 0;
}
return item;
}
queue_pop_back :: proc(q: ^$Q/Queue($T)) -> T {
assert(q.len > 0);
item := queue_get(q^, q.len-1);
q.len -= 1;
return item;
}
queue_consume :: proc(q: ^$Q/Queue($T), count: int) {
q.offset = (q.offset + count) & array_len(q.data);
q.len -= count;
}
queue_push_elems :: proc(q: ^$Q/Queue($T), items: ..T) {
if queue_space(q^) < len(items) {
_queue_grow(q, q.len + len(items));
}
size := array_len(q.data);
insert := (q.offset + q.len) % size;
to_insert := len(items);
if insert + to_insert > size {
to_insert = size - insert;
}
the_items := items[:];
data := array_slice(q.data);
q.len += copy(data[insert:][:to_insert], the_items);
the_items = the_items[to_insert:];
q.len += copy(data[:], the_items);
}
queue_push :: proc{queue_push_back, queue_push_elems};
_queue_increase_capacity :: proc(q: ^$Q/Queue($T), new_capacity: int) {
end := array_len(q.data);
array_resize(&q.data, new_capacity);
if q.offset + q.len > end {
end_items := q.len + end;
data := array_slice(q.data);
copy(data[new_capacity-end_items:][:end_items], data[q.offset:][:end_items]);
q.offset += new_capacity - end;
}
}
_queue_grow :: proc(q: ^$Q/Queue($T), min_capacity: int = 0) {
new_capacity := max(array_len(q.data)*2 + 8, min_capacity);
_queue_increase_capacity(q, new_capacity);
}
+74
View File
@@ -0,0 +1,74 @@
package container
Ring :: struct($T: typeid) {
next, prev: ^Ring(T),
value: T,
}
ring_init :: proc(r: ^$R/Ring) -> ^R {
r.prev, r.next = r, r;
return r;
}
ring_next :: proc(r: ^$R/Ring) -> ^R {
if r.next == nil {
return ring_init(r);
}
return r.next;
}
ring_prev :: proc(r: ^$R/Ring) -> ^R {
if r.prev == nil {
return ring_init(r);
}
return r.prev;
}
ring_move :: proc(r: ^$R/Ring, n: int) -> ^R {
r := r;
if r.next == nil {
return ring_init(r);
}
switch {
case n < 0:
for _ in n..<0 {
r = r.prev;
}
case n > 0:
for _ in 0..<n {
r = r.next;
}
}
return r;
}
ring_link :: proc(r, s: ^$R/Ring) -> ^R {
n := ring_next(r);
if s != nil {
p := ring_prev(s);
r.next = s;
s.prev = r;
n.prev = p;
p.next = n;
}
return n;
}
ring_unlink :: proc(r: ^$R/Ring, n: int) -> ^R {
if n <= 0 {
return nil;
}
return ring_link(r, ring_move(r, n+1));
}
ring_len :: proc(r: ^$R/Ring) -> int {
n := 0;
if r != nil {
n = 1;
for p := ring_next(r); p != r; p = p.next {
n += 1;
}
}
return n;
}
+240
View File
@@ -0,0 +1,240 @@
package container
Set :: struct {
hash: Array(int),
entries: Array(Set_Entry),
}
Set_Entry :: struct {
key: u64,
next: int,
}
/*
set_init :: proc{
set_init_none,
set_init_cap,
}
set_delete
set_in
set_not_in
set_add
set_remove
set_reserve
set_clear
*/
set_init :: proc{set_init_none, set_init_cap};
set_init_none :: proc(m: ^Set, allocator := context.allocator) {
m.hash.allocator = allocator;
m.entries.allocator = allocator;
}
set_init_cap :: proc(m: ^Set, cap: int, allocator := context.allocator) {
m.hash.allocator = allocator;
m.entries.allocator = allocator;
set_reserve(m, cap);
}
set_delete :: proc(m: Set) {
array_delete(m.hash);
array_delete(m.entries);
}
set_in :: proc(m: Set, key: u64) -> bool {
return _set_find_or_fail(m, key) >= 0;
}
set_not_in :: proc(m: Set, key: u64) -> bool {
return _set_find_or_fail(m, key) < 0;
}
set_add :: proc(m: ^Set, key: u64) {
if array_len(m.hash) == 0 {
_set_grow(m);
}
_ = _set_find_or_make(m, key);
if _set_full(m^) {
_set_grow(m);
}
}
set_remove :: proc(m: ^Set, key: u64) {
fr := _set_find_key(m^, key);
if fr.entry_index >= 0 {
_set_erase(m, fr);
}
}
set_reserve :: proc(m: ^Set, new_size: int) {
nm: Set;
set_init(&nm, m.hash.allocator);
array_resize(&nm.hash, new_size);
array_reserve(&nm.entries, array_len(m.entries));
for i in 0..<new_size {
array_set(&nm.hash, i, -1);
}
for i in 0..<array_len(m.entries) {
e := array_get(m.entries, i);
set_add(&nm, e.key);
}
set_delete(m^);
m^ = nm;
}
set_clear :: proc(m: ^Set) {
array_clear(&m.hash);
array_clear(&m.entries);
}
set_equal :: proc(a, b: Set) -> bool {
a_entries := array_slice(a.entries);
b_entries := array_slice(b.entries);
if len(a_entries) != len(b_entries) {
return false;
}
for e in a_entries {
if set_not_in(b, e.key) {
return false;
}
}
return true;
}
/// Internal
_set_add_entry :: proc(m: ^Set, key: u64) -> int {
e: Set_Entry;
e.key = key;
e.next = -1;
idx := array_len(m.entries);
array_push(&m.entries, e);
return idx;
}
_set_erase :: proc(m: ^Set, fr: Map_Find_Result) {
if fr.entry_prev < 0 {
array_set(&m.hash, fr.hash_index, array_get(m.entries, fr.entry_index).next);
} else {
array_get_ptr(m.entries, fr.entry_prev).next = array_get(m.entries, fr.entry_index).next;
}
if fr.entry_index == array_len(m.entries)-1 {
array_pop_back(&m.entries);
return;
}
array_set(&m.entries, fr.entry_index, array_get(m.entries, array_len(m.entries)-1));
last := _set_find_key(m^, array_get(m.entries, fr.entry_index).key);
if last.entry_prev < 0 {
array_get_ptr(m.entries, last.entry_prev).next = fr.entry_index;
} else {
array_set(&m.hash, last.hash_index, fr.entry_index);
}
}
_set_find_key :: proc(m: Set, key: u64) -> Map_Find_Result {
fr: Map_Find_Result;
fr.hash_index = -1;
fr.entry_prev = -1;
fr.entry_index = -1;
if array_len(m.hash) == 0 {
return fr;
}
fr.hash_index = int(key % u64(array_len(m.hash)));
fr.entry_index = array_get(m.hash, fr.hash_index);
for fr.entry_index >= 0 {
it := array_get_ptr(m.entries, fr.entry_index);
if it.key == key {
return fr;
}
fr.entry_prev = fr.entry_index;
fr.entry_index = it.next;
}
return fr;
}
_set_find_entry :: proc(m: ^Set, e: ^Set_Entry) -> Map_Find_Result {
fr: Map_Find_Result;
fr.hash_index = -1;
fr.entry_prev = -1;
fr.entry_index = -1;
if array_len(m.hash) == 0 {
return fr;
}
fr.hash_index = int(e.key % u64(array_len(m.hash)));
fr.entry_index = array_get(m.hash, fr.hash_index);
for fr.entry_index >= 0 {
it := array_get_ptr(m.entries, fr.entry_index);
if it == e {
return fr;
}
fr.entry_prev = fr.entry_index;
fr.entry_index = it.next;
}
return fr;
}
_set_find_or_fail :: proc(m: Set, key: u64) -> int {
return _set_find_key(m, key).entry_index;
}
_set_find_or_make :: proc(m: ^Set, key: u64) -> int {
fr := _set_find_key(m^, key);
if fr.entry_index >= 0 {
return fr.entry_index;
}
i := _set_add_entry(m, key);
if fr.entry_prev < 0 {
array_set(&m.hash, fr.hash_index, i);
} else {
array_get_ptr(m.entries, fr.entry_prev).next = i;
}
return i;
}
_set_make :: proc(m: ^Set, key: u64) -> int {
fr := _set_find_key(m^, key);
i := _set_add_entry(m, key);
if fr.entry_prev < 0 {
array_set(&m.hash, fr.hash_index, i);
} else {
array_get_ptr(m.entries, fr.entry_prev).next = i;
}
array_get_ptr(m.entries, i).next = fr.entry_index;
return i;
}
_set_full :: proc(m: Set) -> bool {
// TODO(bill): Determine good max load factor
return array_len(m.entries) >= (array_len(m.hash) / 4)*3;
}
_set_grow :: proc(m: ^Set) {
new_size := array_len(m.entries) * 4 + 7; // TODO(bill): Determine good grow rate
set_reserve(m, new_size);
}
+95
View File
@@ -0,0 +1,95 @@
package container
Small_Array :: struct($N: int, $T: typeid) where N >= 0 {
data: [N]T,
len: int,
}
small_array_len :: proc(a: $A/Small_Array) -> int {
return a.len;
}
small_array_cap :: proc(a: $A/Small_Array) -> int {
return len(a.data);
}
small_array_space :: proc(a: $A/Small_Array) -> int {
return len(a.data) - a.len;
}
small_array_slice :: proc(a: ^$A/Small_Array($N, $T)) -> []T {
return a.data[:a.len];
}
small_array_get :: proc(a: $A/Small_Array($N, $T), index: int, loc := #caller_location) -> T {
return a.data[index];
}
small_array_get_ptr :: proc(a: $A/Small_Array($N, $T), index: int, loc := #caller_location) -> ^T {
return &a.data[index];
}
small_array_set :: proc(a: ^$A/Small_Array($N, $T), index: int, item: T, loc := #caller_location) {
a.data[index] = item;
}
small_array_resize :: proc(a: ^$A/Small_Array, length: int) {
a.len = min(length, len(a.data));
}
small_array_push_back :: proc(a: ^$A/Small_Array($N, $T), item: T) -> bool {
if a.len < len(a.data) {
a.len += 1;
a.data[a.len-1] = item;
return true;
}
return false;
}
small_array_push_front :: proc(a: ^$A/Small_Array($N, $T), item: T) -> bool {
if a.len < len(a.data) {
a.len += 1;
data := small_array_slice(a);
copy(data[1:], data[:]);
data[0] = item;
return true;
}
return false;
}
small_array_pop_back :: proc(a: ^$A/Small_Array($N, $T), loc := #caller_location) -> T {
assert(condition=a.len > 0, loc=loc);
item := a.data[a.len-1];
a.len -= 1;
return item;
}
small_array_pop_front :: proc(a: ^$A/Small_Array($N, $T), loc := #caller_location) -> T {
assert(condition=a.len > 0, loc=loc);
item := a.data[0];
s := small_array_slice(a);
copy(s[:], s[1:]);
a.len -= 1;
return item;
}
small_array_consume :: proc(a: ^$A/Small_Array($N, $T), count: int, loc := #caller_location) {
assert(condition=a.len >= count, loc=loc);
a.len -= count;
}
small_array_clear :: proc(a: ^$A/Small_Array($N, $T)) {
small_array_resize(a, 0);
}
small_array_push_back_elems :: proc(a: ^$A/Small_Array($N, $T), items: ..T) {
n := copy(a.data[a.len:], items[:]);
a.len += n;
}
small_array_push :: proc{small_array_push_back, small_array_push_back_elems};
small_array_append :: proc{small_array_push_back, small_array_push_back_elems};
+1 -1
View File
@@ -1,3 +1,3 @@
package dynlib
Library :: opaque rawptr;
Library :: distinct rawptr;
+23
View File
@@ -0,0 +1,23 @@
// +build linux, darwin, freebsd
package dynlib
import "core:os"
load_library :: proc(path: string, global_symbols := false) -> (Library, bool) {
flags := os.RTLD_NOW;
if global_symbols {
flags |= os.RTLD_GLOBAL;
}
lib := os.dlopen(path, flags);
return Library(lib), lib != nil;
}
unload_library :: proc(library: Library) {
os.dlclose(rawptr(library));
}
symbol_address :: proc(library: Library, symbol: string) -> (ptr: rawptr, found: bool) {
ptr = os.dlsym(rawptr(library), symbol);
found = ptr != nil;
return;
}
+5 -4
View File
@@ -1,24 +1,25 @@
// +build windows
package dynlib
import "core:sys/win32"
import win32 "core:sys/windows"
import "core:strings"
load_library :: proc(path: string, global_symbols := false) -> (Library, bool) {
// NOTE(bill): 'global_symbols' is here only for consistency with POSIX which has RTLD_GLOBAL
wide_path := win32.utf8_to_wstring(path, context.temp_allocator);
handle := cast(Library)win32.load_library_w(wide_path);
handle := cast(Library)win32.LoadLibraryW(wide_path);
return handle, handle != nil;
}
unload_library :: proc(library: Library) -> bool {
ok := win32.free_library(cast(win32.Hmodule)library);
ok := win32.FreeLibrary(cast(win32.HMODULE)library);
return bool(ok);
}
symbol_address :: proc(library: Library, symbol: string) -> (ptr: rawptr, found: bool) {
c_str := strings.clone_to_cstring(symbol, context.temp_allocator);
ptr = win32.get_proc_address(cast(win32.Hmodule)library, c_str);
ptr = win32.GetProcAddress(cast(win32.HMODULE)library, c_str);
found = ptr != nil;
return;
}
+148
View File
@@ -0,0 +1,148 @@
package base32
// @note(zh): Encoding utility for Base32
// A secondary param can be used to supply a custom alphabet to
// @link(encode) and a matching decoding table to @link(decode).
// If none is supplied it just uses the standard Base32 alphabet.
// Incase your specific version does not use padding, you may
// truncate it from the encoded output.
ENC_TABLE := [32]byte {
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
'Y', 'Z', '2', '3', '4', '5', '6', '7',
};
PADDING :: '=';
DEC_TABLE := [?]u8 {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 26, 27, 28, 29, 30, 31, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 0, 0, 0, 0, 0,
0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};
encode :: proc(data: []byte, ENC_TBL := ENC_TABLE, allocator := context.allocator) -> string {
out_length := (len(data) + 4) / 5 * 8;
out := make([]byte, out_length);
_encode(out, data);
return string(out);
}
@private
_encode :: proc(out, data: []byte, ENC_TBL := ENC_TABLE, allocator := context.allocator) {
out := out;
data := data;
for len(data) > 0 {
carry: byte;
switch len(data) {
case:
out[7] = ENC_TABLE[data[4] & 0x1f];
carry = data[4] >> 5;
fallthrough;
case 4:
out[6] = ENC_TABLE[carry | (data[3] << 3) & 0x1f];
out[5] = ENC_TABLE[(data[3] >> 2) & 0x1f];
carry = data[3] >> 7;
fallthrough;
case 3:
out[4] = ENC_TABLE[carry | (data[2] << 1) & 0x1f];
carry = (data[2] >> 4) & 0x1f;
fallthrough;
case 2:
out[3] = ENC_TABLE[carry | (data[1] << 4) & 0x1f];
out[2] = ENC_TABLE[(data[1] >> 1) & 0x1f];
carry = (data[1] >> 6) & 0x1f;
fallthrough;
case 1:
out[1] = ENC_TABLE[carry | (data[0] << 2) & 0x1f];
out[0] = ENC_TABLE[data[0] >> 3];
}
if len(data) < 5 {
out[7] = byte(PADDING);
if len(data) < 4 {
out[6] = byte(PADDING);
out[5] = byte(PADDING);
if len(data) < 3 {
out[4] = byte(PADDING);
if len(data) < 2 {
out[3] = byte(PADDING);
out[2] = byte(PADDING);
}
}
}
break;
}
data = data[5:];
out = out[8:];
}
}
decode :: proc(data: string, DEC_TBL := DEC_TABLE, allocator := context.allocator) -> []byte #no_bounds_check{
if len(data) == 0 {
return nil;
}
outi := 0;
data := data;
out := make([]byte, len(data) / 8 * 5, allocator);
end := false;
for len(data) > 0 && !end {
dbuf : [8]byte;
dlen := 8;
for j := 0; j < 8; {
if len(data) == 0 {
dlen, end = j, true;
break;
}
input := data[0];
data = data[1:];
if input == byte(PADDING) && j >= 2 && len(data) < 8 {
assert(!(len(data) + j < 8 - 1), "Corrupted input");
for k := 0; k < 8-1-j; k +=1 {
assert(len(data) < k || data[k] == byte(PADDING), "Corrupted input");
}
dlen, end = j, true;
assert(dlen != 1 && dlen != 3 && dlen != 6, "Corrupted input");
break;
}
dbuf[j] = DEC_TABLE[input];
assert(dbuf[j] != 0xff, "Corrupted input");
j += 1;
}
switch dlen {
case 8:
out[outi + 4] = dbuf[6] << 5 | dbuf[7];
fallthrough;
case 7:
out[outi + 3] = dbuf[4] << 7 | dbuf[5] << 2 | dbuf[6] >> 3;
fallthrough;
case 5:
out[outi + 2] = dbuf[3] << 4 | dbuf[4] >> 1;
fallthrough;
case 4:
out[outi + 1] = dbuf[1] << 6 | dbuf[2] << 1 | dbuf[3] >> 4;
fallthrough;
case 2:
out[outi + 0] = dbuf[0] << 3 | dbuf[1] >> 2;
}
outi += 5;
}
return out;
}
+37 -33
View File
@@ -2,46 +2,48 @@ package base64
// @note(zh): Encoding utility for Base64
// A secondary param can be used to supply a custom alphabet to
// @link(encode) and a matching decoding table to @link(decode).
// @link(encode) and a matching decoding table to @link(decode).
// If none is supplied it just uses the standard Base64 alphabet.
// Incase your specific version does not use padding, you may
// truncate it from the encoded output.
ENC_TABLE := [64]byte {
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
'w', 'x', 'y', 'z', '0', '1', '2', '3',
'4', '5', '6', '7', '8', '9', '+', '/'
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
'w', 'x', 'y', 'z', '0', '1', '2', '3',
'4', '5', '6', '7', '8', '9', '+', '/',
};
PADDING :: '=';
DEC_TABLE := [128]int {
-1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, 62, -1, -1, -1, 63,
52, 53, 54, 55, 56, 57, 58, 59,
60, 61, -1, -1, -1, -1, -1, -1,
-1, 0, 1, 2, 3, 4, 5, 6,
7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22,
23, 24, 25, -1, -1, -1, -1, -1,
-1, 26, 27, 28, 29, 30, 31, 32,
33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48,
49, 50, 51, -1, -1, -1, -1, -1
-1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, 62, -1, -1, -1, 63,
52, 53, 54, 55, 56, 57, 58, 59,
60, 61, -1, -1, -1, -1, -1, -1,
-1, 0, 1, 2, 3, 4, 5, 6,
7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22,
23, 24, 25, -1, -1, -1, -1, -1,
-1, 26, 27, 28, 29, 30, 31, 32,
33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48,
49, 50, 51, -1, -1, -1, -1, -1,
};
encode :: proc(data: []byte, ENC_TBL := ENC_TABLE, allocator := context.allocator) -> string #no_bounds_check {
length := len(data);
if length == 0 do return "";
if length == 0 {
return "";
}
out_length := ((4 * length / 3) + 3) &~ 3;
out := make([]byte, out_length, allocator);
@@ -49,24 +51,26 @@ encode :: proc(data: []byte, ENC_TBL := ENC_TABLE, allocator := context.allocato
c0, c1, c2, block: int;
for i, d := 0, 0; i < length; i, d = i + 3, d + 4 {
c0, c1, c2 = int(data[i]), 0, 0;
c0, c1, c2 = int(data[i]), -1, -1;
if i + 1 < length do c1 = int(data[i + 1]);
if i + 2 < length do c2 = int(data[i + 2]);
if i + 1 < length { c1 = int(data[i + 1]); }
if i + 2 < length { c2 = int(data[i + 2]); }
block = (c0 << 16) | (max(c1, 0) << 8) | max(c2, 0);
out[d] = ENC_TBL[block >> 18 & 63];
out[d + 1] = ENC_TBL[block >> 12 & 63];
out[d + 2] = c1 == 0 ? PADDING : ENC_TBL[block >> 6 & 63];
out[d + 3] = c2 == 0 ? PADDING : ENC_TBL[block & 63];
out[d + 2] = c1 == -1 ? PADDING : ENC_TBL[block >> 6 & 63];
out[d + 3] = c2 == -1 ? PADDING : ENC_TBL[block & 63];
}
return string(out);
}
decode :: proc(data: string, DEC_TBL := DEC_TABLE, allocator := context.allocator) -> []byte #no_bounds_check{
decode :: proc(data: string, DEC_TBL := DEC_TABLE, allocator := context.allocator) -> []byte #no_bounds_check {
length := len(data);
if length == 0 do return []byte{};
if length == 0 {
return nil;
}
pad_count := data[length - 1] == PADDING ? (data[length - 2] == PADDING ? 2 : 1) : 0;
out_length := ((length * 6) >> 3) - pad_count;
@@ -90,4 +94,4 @@ decode :: proc(data: string, DEC_TBL := DEC_TABLE, allocator := context.allocato
out[j + 2] = byte(b2);
}
return out;
}
}
-840
View File
@@ -1,840 +0,0 @@
package cel;
import "core:fmt"
import "core:strconv"
import "core:unicode/utf8"
import "core:strings"
Array :: []Value;
Dict :: map[string]Value;
Nil_Value :: struct{};
Value :: union {
Nil_Value,
bool, i64, f64, string,
Array, Dict,
}
Parser :: struct {
tokens: [dynamic]Token,
prev_token: Token,
curr_token: Token,
curr_token_index: int,
allocated_strings: [dynamic]string,
error_count: int,
root: Dict,
dict_stack: [dynamic]^Dict, // NOTE: Pointers may be stored on the stack
}
print_value :: proc(value: Value, pretty := true, indent := 0) {
print_indent :: proc(indent: int) {
for _ in 0..<indent do fmt.print("\t");
}
switch v in value {
case bool: fmt.print(v);
case i64: fmt.print(v);
case f64: fmt.print(v);
case string: fmt.print(v);
case Array:
fmt.print("[");
if pretty do fmt.println();
for e, i in v {
if pretty {
print_indent(indent+1);
print_value(e, pretty, indent+1);
fmt.println(",");
} else {
if i > 0 do fmt.print(", ");
print_value(e);
}
}
if pretty do print_indent(indent);
fmt.print("]");
case Dict:
fmt.print("{");
if pretty do fmt.println();
i := 0;
for name, val in v {
if pretty {
print_indent(indent+1);
fmt.printf("%s = ", name);
print_value(val, pretty, indent+1);
fmt.println(",");
} else {
if i > 0 do fmt.print(", ");
fmt.printf("%s = ", name);
print_value(val, pretty, indent+1);
i += 1;
}
}
if pretty do print_indent(indent);
fmt.print("}");
case:
fmt.print("nil");
case Nil_Value:
fmt.print("nil");
}
}
print :: proc(p: ^Parser, pretty := false) {
for name, val in p.root {
fmt.printf("%s = ", name);
print_value(val, pretty);
fmt.println(";");
}
}
create_from_string :: proc(src: string) -> (^Parser, bool) {
return init(cast([]byte)src);
}
init :: proc(src: []byte) -> (^Parser, bool) {
t: Tokenizer;
tokenizer_init(&t, src);
return create_from_tokenizer(&t);
}
create_from_tokenizer :: proc(t: ^Tokenizer) -> (^Parser, bool) {
p := new(Parser);
for {
tok := scan(t);
if tok.kind == Kind.Illegal {
return p, false;
}
append(&p.tokens, tok);
if tok.kind == Kind.EOF {
break;
}
}
if t.error_count > 0 {
return p, false;
}
if len(p.tokens) == 0 {
tok := Token{kind = Kind.EOF};
tok.line, tok.column = 1, 1;
append(&p.tokens, tok);
return p, true;
}
p.curr_token_index = 0;
p.prev_token = p.tokens[p.curr_token_index];
p.curr_token = p.tokens[p.curr_token_index];
p.root = Dict{};
p.dict_stack = make([dynamic]^Dict, 0, 4);
append(&p.dict_stack, &p.root);
for p.curr_token.kind != Kind.EOF &&
p.curr_token.kind != Kind.Illegal &&
p.curr_token_index < len(p.tokens) {
if !parse_assignment(p) {
break;
}
}
return p, true;
}
destroy :: proc(p: ^Parser) {
destroy_value :: proc(value: Value) {
switch v in value {
case Array:
for elem in v do destroy_value(elem);
delete(v);
case Dict:
for _, dv in v do destroy_value(dv);
delete(v);
}
}
delete(p.tokens);
for s in p.allocated_strings do delete(s);
delete(p.allocated_strings);
delete(p.dict_stack);
destroy_value(p.root);
free(p);
}
error :: proc(p: ^Parser, pos: Pos, msg: string, args: ..any) {
fmt.eprintf("%s(%d:%d) Error: ", pos.file, pos.line, pos.column);
fmt.eprintf(msg, ..args);
fmt.eprintln();
p.error_count += 1;
}
next_token :: proc(p: ^Parser) -> Token {
p.prev_token = p.curr_token;
prev := p.prev_token;
if p.curr_token_index+1 < len(p.tokens) {
p.curr_token_index += 1;
p.curr_token = p.tokens[p.curr_token_index];
return prev;
}
p.curr_token_index = len(p.tokens);
p.curr_token = p.tokens[p.curr_token_index-1];
error(p, prev.pos, "Token is EOF");
return prev;
}
unquote_char :: proc(str: string, quote: byte) -> (r: rune, multiple_bytes: bool, tail_string: string, success: bool) {
hex_to_int :: proc(c: byte) -> int {
switch c {
case '0'..'9': return int(c-'0');
case 'a'..'f': return int(c-'a')+10;
case 'A'..'F': return int(c-'A')+10;
}
return -1;
}
w: int;
if str[0] == quote && quote == '"' {
return;
} else if str[0] >= 0x80 {
r, w = utf8.decode_rune_in_string(str);
return r, true, str[w:], true;
} else if str[0] != '\\' {
return rune(str[0]), false, str[1:], true;
}
if len(str) <= 1 {
return;
}
s := str;
c := s[1];
s = s[2:];
switch c {
case:
return;
case 'a': r = '\a';
case 'b': r = '\b';
case 'f': r = '\f';
case 'n': r = '\n';
case 'r': r = '\r';
case 't': r = '\t';
case 'v': r = '\v';
case '\\': r = '\\';
case '"': r = '"';
case '\'': r = '\'';
case '0'..'7':
v := int(c-'0');
if len(s) < 2 {
return;
}
for i in 0..<len(s) {
d := int(s[i]-'0');
if d < 0 || d > 7 {
return;
}
v = (v<<3) | d;
}
s = s[2:];
if v > 0xff {
return;
}
r = rune(v);
case 'x', 'u', 'U':
count: int;
switch c {
case 'x': count = 2;
case 'u': count = 4;
case 'U': count = 8;
}
if len(s) < count {
return;
}
for i in 0..<count {
d := hex_to_int(s[i]);
if d < 0 {
return;
}
r = (r<<4) | rune(d);
}
s = s[count:];
if c == 'x' {
break;
}
if r > utf8.MAX_RUNE {
return;
}
multiple_bytes = true;
}
success = true;
tail_string = s;
return;
}
unquote_string :: proc(p: ^Parser, t: Token) -> (string, bool) {
if t.kind != Kind.String {
return t.lit, true;
}
s := t.lit;
quote := '"';
if s == `""` {
return "", true;
}
if strings.contains_rune(s, '\n') >= 0 {
return s, false;
}
if strings.contains_rune(s, '\\') < 0 && strings.contains_rune(s, quote) < 0 {
if quote == '"' {
return s, true;
}
}
buf_len := 3*len(s) / 2;
buf := make([]byte, buf_len);
offset := 0;
for len(s) > 0 {
r, multiple_bytes, tail_string, ok := unquote_char(s, byte(quote));
if !ok {
delete(buf);
return s, false;
}
s = tail_string;
if r < 0x80 || !multiple_bytes {
buf[offset] = byte(r);
offset += 1;
} else {
b, w := utf8.encode_rune(r);
copy(buf[offset:], b[:w]);
offset += w;
}
}
new_string := string(buf[:offset]);
append(&p.allocated_strings, new_string);
return new_string, true;
}
allow_token :: proc(p: ^Parser, kind: Kind) -> bool {
if p.curr_token.kind == kind {
next_token(p);
return true;
}
return false;
}
expect_token :: proc(p: ^Parser, kind: Kind) -> Token {
prev := p.curr_token;
if prev.kind != kind {
got := prev.lit;
if got == "\n" do got = ";";
error(p, prev.pos, "Expected %s, got %s", kind_to_string[kind], got);
}
next_token(p);
return prev;
}
expect_operator :: proc(p: ^Parser) -> Token {
prev := p.curr_token;
if !is_operator(prev.kind) {
error(p, prev.pos, "Expected an operator, got %s", prev.lit);
}
next_token(p);
return prev;
}
fix_advance :: proc(p: ^Parser) {
for {
switch t := p.curr_token; t.kind {
case Kind.EOF, Kind.Semicolon:
return;
}
next_token(p);
}
}
copy_value :: proc(value: Value) -> Value {
switch v in value {
case Array:
a := make(Array, len(v));
for elem, idx in v {
a[idx] = copy_value(elem);
}
return a;
case Dict:
d := make(Dict, cap(v));
for key, val in v {
d[key] = copy_value(val);
}
return d;
}
return value;
}
lookup_value :: proc(p: ^Parser, name: string) -> (Value, bool) {
for i := len(p.dict_stack)-1; i >= 0; i -= 1 {
d := p.dict_stack[i];
if val, ok := d[name]; ok {
return copy_value(val), true;
}
}
return nil, false;
}
parse_operand :: proc(p: ^Parser) -> (Value, Pos) {
tok := p.curr_token;
switch p.curr_token.kind {
case Kind.Ident:
next_token(p);
v, ok := lookup_value(p, tok.lit);
if !ok do error(p, tok.pos, "Undeclared identifier %s", tok.lit);
return v, tok.pos;
case Kind.True:
next_token(p);
return true, tok.pos;
case Kind.False:
next_token(p);
return false, tok.pos;
case Kind.Nil:
next_token(p);
return Nil_Value{}, tok.pos;
case Kind.Integer:
next_token(p);
return strconv.parse_i64(tok.lit), tok.pos;
case Kind.Float:
next_token(p);
return strconv.parse_f64(tok.lit), tok.pos;
case Kind.String:
next_token(p);
str, ok := unquote_string(p, tok);
if !ok do error(p, tok.pos, "Unable to unquote string");
return string(str), tok.pos;
case Kind.Open_Paren:
expect_token(p, Kind.Open_Paren);
expr, _ := parse_expr(p);
expect_token(p, Kind.Close_Paren);
return expr, tok.pos;
case Kind.Open_Bracket:
expect_token(p, Kind.Open_Bracket);
elems := make([dynamic]Value, 0, 4);
for p.curr_token.kind != Kind.Close_Bracket &&
p.curr_token.kind != Kind.EOF {
elem, _ := parse_expr(p);
append(&elems, elem);
if p.curr_token.kind == Kind.Semicolon && p.curr_token.lit == "\n" {
next_token(p);
} else if !allow_token(p, Kind.Comma) {
break;
}
}
expect_token(p, Kind.Close_Bracket);
return Array(elems[:]), tok.pos;
case Kind.Open_Brace:
expect_token(p, Kind.Open_Brace);
dict := Dict{};
append(&p.dict_stack, &dict);
defer pop(&p.dict_stack);
for p.curr_token.kind != Kind.Close_Brace &&
p.curr_token.kind != Kind.EOF {
name_tok := p.curr_token;
if !allow_token(p, Kind.Ident) && !allow_token(p, Kind.String) {
name_tok = expect_token(p, Kind.Ident);
}
name, ok := unquote_string(p, name_tok);
if !ok do error(p, tok.pos, "Unable to unquote string");
expect_token(p, Kind.Assign);
elem, _ := parse_expr(p);
if _, ok2 := dict[name]; ok2 {
error(p, name_tok.pos, "Previous declaration of %s in this scope", name);
} else {
dict[name] = elem;
}
if p.curr_token.kind == Kind.Semicolon && p.curr_token.lit == "\n" {
next_token(p);
} else if !allow_token(p, Kind.Comma) {
break;
}
}
expect_token(p, Kind.Close_Brace);
return dict, tok.pos;
}
return nil, tok.pos;
}
parse_atom_expr :: proc(p: ^Parser, operand: Value, pos: Pos) -> (Value, Pos) {
loop := true;
for operand := operand; loop; {
switch p.curr_token.kind {
case Kind.Period:
next_token(p);
tok := next_token(p);
switch tok.kind {
case Kind.Ident:
d, ok := operand.(Dict);
if !ok || d == nil {
error(p, tok.pos, "Expected a dictionary");
operand = nil;
continue;
}
name, usok := unquote_string(p, tok);
if !usok do error(p, tok.pos, "Unable to unquote string");
val, found := d[name];
if !found {
error(p, tok.pos, "Field %s not found in dictionary", name);
operand = nil;
continue;
}
operand = val;
case:
error(p, tok.pos, "Expected a selector, got %s", tok.kind);
operand = nil;
}
case Kind.Open_Bracket:
expect_token(p, Kind.Open_Bracket);
index, index_pos := parse_expr(p);
expect_token(p, Kind.Close_Bracket);
switch a in operand {
case Array:
i, ok := index.(i64);
if !ok {
error(p, index_pos, "Index must be an integer for an array");
operand = nil;
continue;
}
if 0 <= i && i < i64(len(a)) {
operand = a[i];
} else {
error(p, index_pos, "Index %d out of bounds range 0..%d", i, len(a));
operand = nil;
continue;
}
case Dict:
key, ok := index.(string);
if !ok {
error(p, index_pos, "Index must be a string for a dictionary");
operand = nil;
continue;
}
val, found := a[key];
if found {
operand = val;
} else {
error(p, index_pos, "`%s` was not found in the dictionary", key);
operand = nil;
continue;
}
case:
error(p, index_pos, "Indexing is only allowed on an array or dictionary");
}
case:
loop = false;
}
}
return operand, pos;
}
parse_unary_expr :: proc(p: ^Parser) -> (Value, Pos) {
op := p.curr_token;
switch p.curr_token.kind {
case Kind.At:
next_token(p);
tok := expect_token(p, Kind.String);
v, ok := lookup_value(p, tok.lit);
if !ok do error(p, tok.pos, "Undeclared identifier %s", tok.lit);
return parse_atom_expr(p, v, tok.pos);
case Kind.Add, Kind.Sub:
next_token(p);
// TODO(bill): Calcuate values as you go!
expr, pos := parse_unary_expr(p);
switch e in expr {
case i64: if op.kind == Kind.Sub do return -e, pos;
case f64: if op.kind == Kind.Sub do return -e, pos;
case:
error(p, op.pos, "Unary operator %s can only be used on integers or floats", op.lit);
return nil, op.pos;
}
return expr, op.pos;
case Kind.Not:
next_token(p);
expr, _ := parse_unary_expr(p);
if v, ok := expr.(bool); ok {
return !v, op.pos;
}
error(p, op.pos, "Unary operator %s can only be used on booleans", op.lit);
return nil, op.pos;
}
return parse_atom_expr(p, parse_operand(p));
}
value_order :: proc(v: Value) -> int {
switch _ in v {
case bool, string:
return 1;
case i64:
return 2;
case f64:
return 3;
}
return 0;
}
match_values :: proc(left, right: ^Value) -> bool {
if value_order(right^) < value_order(left^) {
return match_values(right, left);
}
switch x in left^ {
case:
right^ = left^;
case bool, string:
return true;
case i64:
switch y in right^ {
case i64:
return true;
case f64:
left^ = f64(x);
return true;
}
case f64:
switch y in right {
case f64:
return true;
}
}
return false;
}
calculate_binary_value :: proc(p: ^Parser, op: Kind, a, b: Value) -> (Value, bool) {
// TODO(bill): Calculate value as you go!
x, y := a, b;
match_values(&x, &y);
switch a in x {
case: return x, true;
case bool:
b, ok := y.(bool);
if !ok do return nil, false;
switch op {
case Kind.Eq: return a == b, true;
case Kind.NotEq: return a != b, true;
case Kind.And: return a && b, true;
case Kind.Or: return a || b, true;
}
case i64:
b, ok := y.(i64);
if !ok do return nil, false;
switch op {
case Kind.Add: return a + b, true;
case Kind.Sub: return a - b, true;
case Kind.Mul: return a * b, true;
case Kind.Quo: return a / b, true;
case Kind.Rem: return a % b, true;
case Kind.Eq: return a == b, true;
case Kind.NotEq: return a != b, true;
case Kind.Lt: return a < b, true;
case Kind.Gt: return a > b, true;
case Kind.LtEq: return a <= b, true;
case Kind.GtEq: return a >= b, true;
}
case f64:
b, ok := y.(f64);
if !ok do return nil, false;
switch op {
case Kind.Add: return a + b, true;
case Kind.Sub: return a - b, true;
case Kind.Mul: return a * b, true;
case Kind.Quo: return a / b, true;
case Kind.Eq: return a == b, true;
case Kind.NotEq: return a != b, true;
case Kind.Lt: return a < b, true;
case Kind.Gt: return a > b, true;
case Kind.LtEq: return a <= b, true;
case Kind.GtEq: return a >= b, true;
}
case string:
b, ok := y.(string);
if !ok do return nil, false;
switch op {
case Kind.Add:
n := len(a) + len(b);
data := make([]byte, n);
copy(data[:], cast([]byte)a);
copy(data[len(a):], cast([]byte)b);
s := string(data);
append(&p.allocated_strings, s);
return s, true;
case Kind.Eq: return a == b, true;
case Kind.NotEq: return a != b, true;
case Kind.Lt: return a < b, true;
case Kind.Gt: return a > b, true;
case Kind.LtEq: return a <= b, true;
case Kind.GtEq: return a >= b, true;
}
}
return nil, false;
}
parse_binary_expr :: proc(p: ^Parser, prec_in: int) -> (Value, Pos) {
expr, pos := parse_unary_expr(p);
for prec := precedence(p.curr_token.kind); prec >= prec_in; prec -= 1 {
for {
op := p.curr_token;
op_prec := precedence(op.kind);
if op_prec != prec {
break;
}
expect_operator(p);
if op.kind == Kind.Question {
cond := expr;
x, _ := parse_expr(p);
expect_token(p, Kind.Colon);
y, _ := parse_expr(p);
if t, ok := cond.(bool); ok {
expr = t ? x : y;
} else {
error(p, pos, "Condition must be a boolean");
}
} else {
right, right_pos := parse_binary_expr(p, prec+1);
if right == nil {
error(p, right_pos, "Expected expression on the right-hand side of the binary operator %s", op.lit);
}
left := expr;
ok: bool;
expr, ok = calculate_binary_value(p, op.kind, left, right);
if !ok {
error(p, pos, "Invalid binary operation");
}
}
}
}
return expr, pos;
}
parse_expr :: proc(p: ^Parser) -> (Value, Pos) {
return parse_binary_expr(p, 1);
}
expect_semicolon :: proc(p: ^Parser) {
kind := p.curr_token.kind;
switch kind {
case Kind.Comma:
error(p, p.curr_token.pos, "Expected ';', got ','");
next_token(p);
case Kind.Semicolon:
next_token(p);
case Kind.EOF:
// okay
case:
error(p, p.curr_token.pos, "Expected ';', got %s", p.curr_token.lit);
fix_advance(p);
}
}
parse_assignment :: proc(p: ^Parser) -> bool {
top_dict :: proc(p: ^Parser) -> ^Dict {
assert(len(p.dict_stack) > 0);
return p.dict_stack[len(p.dict_stack)-1];
}
if p.curr_token.kind == Kind.Semicolon {
next_token(p);
return true;
}
if p.curr_token.kind == Kind.EOF {
return false;
}
tok := p.curr_token;
if allow_token(p, Kind.Ident) || allow_token(p, Kind.String) {
expect_token(p, Kind.Assign);
name, ok := unquote_string(p, tok);
if !ok do error(p, tok.pos, "Unable to unquote string");
expr, _ := parse_expr(p);
d := top_dict(p);
if _, ok2 := d[name]; ok2 {
error(p, tok.pos, "Previous declaration of %s", name);
} else {
d[name] = expr;
}
expect_semicolon(p);
return true;
}
error(p, tok.pos, "Expected an assignment, got %s", kind_to_string[tok.kind]);
fix_advance(p);
return false;
}
-51
View File
@@ -1,51 +0,0 @@
/*
package cel
sample := `
x = 123;
y = 321.456;
z = x * (y - 1) / 2;
w = "foo" + "bar";
# This is a comment
asd = "Semicolons are optional"
a = {id = {b = 123}} # Dict
b = a.id.b
f = [1, 4, 9] # Array
g = f[2]
h = x < y and w == "foobar"
i = h ? 123 : "google"
j = nil
"127.0.0.1" = "value" # Keys can be strings
"foo" = {
"bar" = {
"baz" = 123, # optional commas if newline is present
"zab" = 456,
"abz" = 789,
},
};
bar = @"foo"["bar"].baz
`;
main :: proc() {
p, ok := create_from_string(sample);
if !ok {
return;
}
defer destroy(p);
if p.error_count == 0 {
print(p);
}
}
*/
package cel
-523
View File
@@ -1,523 +0,0 @@
package cel
import "core:fmt"
import "core:unicode/utf8"
using Kind :: enum {
Illegal,
EOF,
Comment,
_literal_start,
Ident,
Integer,
Float,
Char,
String,
_literal_end,
_keyword_start,
True, // true
False, // false
Nil, // nil
_keyword_end,
_operator_start,
Question, // ?
And, // and
Or, // or
Add, // +
Sub, // -
Mul, // *
Quo, // /
Rem, // %
Not, // !
Eq, // ==
NotEq, // !=
Lt, // <
Gt, // >
LtEq, // <=
GtEq, // >=
At, // @
_operator_end,
_punc_start,
Assign, // =
Open_Paren, // (
Close_Paren, // )
Open_Bracket, // [
Close_Bracket, // ]
Open_Brace, // {
Close_Brace, // }
Colon, // :
Semicolon, // ;
Comma, // ,
Period, // .
_punc_end,
}
Pos :: struct {
file: string,
line: int,
column: int,
}
Token :: struct {
kind: Kind,
using pos: Pos,
lit: string,
}
Tokenizer :: struct {
src: []byte,
file: string, // May not be used
curr_rune: rune,
offset: int,
read_offset: int,
line_offset: int,
line_count: int,
insert_semi: bool,
error_count: int,
}
keywords := map[string]Kind{
"true" = True,
"false" = False,
"nil" = Nil,
"and" = And,
"or" = Or,
};
kind_to_string := [len(Kind)]string{
"illegal",
"EOF",
"comment",
"",
"identifier",
"integer",
"float",
"character",
"string",
"",
"",
"true", "false", "nil",
"",
"",
"?", "and", "or",
"+", "-", "*", "/", "%",
"!",
"==", "!=", "<", ">", "<=", ">=",
"@",
"",
"",
"=",
"(", ")",
"[", "]",
"{", "}",
":", ";", ",", ".",
"",
};
precedence :: proc(op: Kind) -> int {
switch op {
case Question:
return 1;
case Or:
return 2;
case And:
return 3;
case Eq, NotEq, Lt, Gt, LtEq, GtEq:
return 4;
case Add, Sub:
return 5;
case Mul, Quo, Rem:
return 6;
}
return 0;
}
token_lookup :: proc(ident: string) -> Kind {
if tok, is_keyword := keywords[ident]; is_keyword {
return tok;
}
return Ident;
}
is_literal :: proc(tok: Kind) -> bool do return _literal_start < tok && tok < _literal_end;
is_operator :: proc(tok: Kind) -> bool do return _operator_start < tok && tok < _operator_end;
is_keyword :: proc(tok: Kind) -> bool do return _keyword_start < tok && tok < _keyword_end;
tokenizer_init :: proc(t: ^Tokenizer, src: []byte, file := "") {
t.src = src;
t.file = file;
t.curr_rune = ' ';
t.offset = 0;
t.read_offset = 0;
t.line_offset = 0;
t.line_count = 1;
advance_to_next_rune(t);
if t.curr_rune == utf8.RUNE_BOM {
advance_to_next_rune(t);
}
}
token_error :: proc(t: ^Tokenizer, msg: string, args: ..any) {
fmt.eprintf("%s(%d:%d) Error: ", t.file, t.line_count, t.read_offset-t.line_offset+1);
fmt.eprintf(msg, ..args);
fmt.eprintln();
t.error_count += 1;
}
advance_to_next_rune :: proc(t: ^Tokenizer) {
if t.read_offset < len(t.src) {
t.offset = t.read_offset;
if t.curr_rune == '\n' {
t.line_offset = t.offset;
t.line_count += 1;
}
r, w := rune(t.src[t.read_offset]), 1;
switch {
case r == 0:
token_error(t, "Illegal character NUL");
case r >= utf8.RUNE_SELF:
r, w = utf8.decode_rune(t.src[t.read_offset:]);
if r == utf8.RUNE_ERROR && w == 1 {
token_error(t, "Illegal utf-8 encoding");
} else if r == utf8.RUNE_BOM && t.offset > 0 {
token_error(t, "Illegal byte order mark");
}
}
t.read_offset += w;
t.curr_rune = r;
} else {
t.offset = len(t.src);
if t.curr_rune == '\n' {
t.line_offset = t.offset;
t.line_count += 1;
}
t.curr_rune = utf8.RUNE_EOF;
}
}
get_pos :: proc(t: ^Tokenizer) -> Pos {
return Pos {
file = t.file,
line = t.line_count,
column = t.offset - t.line_offset + 1,
};
}
is_letter :: proc(r: rune) -> bool {
switch r {
case 'a'..'z', 'A'..'Z', '_':
return true;
}
return false;
}
is_digit :: proc(r: rune) -> bool {
switch r {
case '0'..'9':
return true;
}
return false;
}
skip_whitespace :: proc(t: ^Tokenizer) {
loop: for {
switch t.curr_rune {
case '\n':
if t.insert_semi {
break loop;
}
fallthrough;
case ' ', '\t', '\r', '\v', '\f':
advance_to_next_rune(t);
case:
break loop;
}
}
}
scan_identifier :: proc(t: ^Tokenizer) -> string {
offset := t.offset;
for is_letter(t.curr_rune) || is_digit(t.curr_rune) {
advance_to_next_rune(t);
}
return string(t.src[offset : t.offset]);
}
digit_value :: proc(r: rune) -> int {
switch r {
case '0'..'9': return int(r - '0');
case 'a'..'f': return int(r - 'a' + 10);
case 'A'..'F': return int(r - 'A' + 10);
}
return 16;
}
scan_number :: proc(t: ^Tokenizer, seen_decimal_point: bool) -> (Kind, string) {
scan_mantissa :: proc(t: ^Tokenizer, base: int) {
for digit_value(t.curr_rune) < base || t.curr_rune == '_' {
advance_to_next_rune(t);
}
}
scan_exponent :: proc(t: ^Tokenizer, tok: Kind, offset: int) -> (kind: Kind, text: string) {
kind = tok;
if t.curr_rune == 'e' || t.curr_rune == 'E' {
kind = Float;
advance_to_next_rune(t);
if t.curr_rune == '-' || t.curr_rune == '+' {
advance_to_next_rune(t);
}
if digit_value(t.curr_rune) < 10 {
scan_mantissa(t, 10);
} else {
token_error(t, "Illegal floating point exponent");
}
}
text = string(t.src[offset : t.offset]);
return;
}
scan_fraction :: proc(t: ^Tokenizer, tok: Kind, offset: int) -> (kind: Kind, text: string) {
kind = tok;
if t.curr_rune == '.' {
kind = Float;
advance_to_next_rune(t);
scan_mantissa(t, 10);
}
return scan_exponent(t, kind, offset);
}
offset := t.offset;
tok := Integer;
if seen_decimal_point {
offset -= 1;
tok = Float;
scan_mantissa(t, 10);
return scan_exponent(t, tok, offset);
}
if t.curr_rune == '0' {
offset = t.offset;
advance_to_next_rune(t);
switch t.curr_rune {
case 'b', 'B':
advance_to_next_rune(t);
scan_mantissa(t, 2);
if t.offset - offset <= 2 {
token_error(t, "Illegal binary number");
}
case 'o', 'O':
advance_to_next_rune(t);
scan_mantissa(t, 8);
if t.offset - offset <= 2 {
token_error(t, "Illegal octal number");
}
case 'x', 'X':
advance_to_next_rune(t);
scan_mantissa(t, 16);
if t.offset - offset <= 2 {
token_error(t, "Illegal hexadecimal number");
}
case:
scan_mantissa(t, 10);
switch t.curr_rune {
case '.', 'e', 'E':
return scan_fraction(t, tok, offset);
}
}
return tok, string(t.src[offset:t.offset]);
}
scan_mantissa(t, 10);
return scan_fraction(t, tok, offset);
}
scan :: proc(t: ^Tokenizer) -> Token {
skip_whitespace(t);
offset := t.offset;
tok: Kind;
pos := get_pos(t);
lit: string;
insert_semi := false;
switch r := t.curr_rune; {
case is_letter(r):
insert_semi = true;
lit = scan_identifier(t);
tok = Ident;
if len(lit) > 1 {
tok = token_lookup(lit);
}
case '0' <= r && r <= '9':
insert_semi = true;
tok, lit = scan_number(t, false);
case:
advance_to_next_rune(t);
switch r {
case -1:
if t.insert_semi {
t.insert_semi = false;
return Token{Semicolon, pos, "\n"};
}
return Token{EOF, pos, "\n"};
case '\n':
t.insert_semi = false;
return Token{Semicolon, pos, "\n"};
case '"':
insert_semi = true;
quote := r;
tok = String;
for {
this_r := t.curr_rune;
if this_r == '\n' || r < 0 {
token_error(t, "String literal not terminated");
break;
}
advance_to_next_rune(t);
if this_r == quote {
break;
}
// TODO(bill); Handle properly
if this_r == '\\' && t.curr_rune == quote {
advance_to_next_rune(t);
}
}
lit = string(t.src[offset+1:t.offset-1]);
case '#':
for t.curr_rune != '\n' && t.curr_rune >= 0 {
advance_to_next_rune(t);
}
if t.insert_semi {
t.insert_semi = false;
return Token{Semicolon, pos, "\n"};
}
// Recursive!
return scan(t);
case '?': tok = Question;
case ':': tok = Colon;
case '@': tok = At;
case ';':
tok = Semicolon;
lit = ";";
case ',': tok = Comma;
case '(':
tok = Open_Paren;
case ')':
insert_semi = true;
tok = Close_Paren;
case '[':
tok = Open_Bracket;
case ']':
insert_semi = true;
tok = Close_Bracket;
case '{':
tok = Open_Brace;
case '}':
insert_semi = true;
tok = Close_Brace;
case '+': tok = Add;
case '-': tok = Sub;
case '*': tok = Mul;
case '/': tok = Quo;
case '%': tok = Rem;
case '!':
tok = Not;
if t.curr_rune == '=' {
advance_to_next_rune(t);
tok = NotEq;
}
case '=':
tok = Assign;
if t.curr_rune == '=' {
advance_to_next_rune(t);
tok = Eq;
}
case '<':
tok = Lt;
if t.curr_rune == '=' {
advance_to_next_rune(t);
tok = LtEq;
}
case '>':
tok = Gt;
if t.curr_rune == '=' {
advance_to_next_rune(t);
tok = GtEq;
}
case '.':
if '0' <= t.curr_rune && t.curr_rune <= '9' {
insert_semi = true;
tok, lit = scan_number(t, true);
} else {
tok = Period;
}
case:
if r != utf8.RUNE_BOM {
token_error(t, "Illegal character '%r'", r);
}
insert_semi = t.insert_semi;
tok = Illegal;
}
}
t.insert_semi = insert_semi;
if lit == "" {
lit = string(t.src[offset:t.offset]);
}
return Token{tok, pos, lit};
}
+406
View File
@@ -0,0 +1,406 @@
// package csv reads and writes comma-separated values (CSV) files.
// This package supports the format described in RFC 4180 <https://tools.ietf.org/html/rfc4180.html>
package csv
import "core:bufio"
import "core:bytes"
import "core:io"
import "core:strings"
import "core:unicode/utf8"
// Reader is a data structure used for reading records from a CSV-encoded file
//
// The associated procedures for Reader expects its input to conform to RFC 4180.
Reader :: struct {
// comma is the field delimiter
// reader_init will set it to be ','
// A "comma" must be a valid rune, nor can it be \r, \n, or the Unicode replacement character (0xfffd)
comma: rune,
// comment, if not 0, is the comment character
// Lines beginning with the comment character without a preceding whitespace are ignored
comment: rune,
// fields_per_record is the number of expected fields per record
// if fields_per_record is >0, 'read' requires each record to have that field count
// if fields_per_record is 0, 'read' sets it to the field count in the first record
// if fields_per_record is <0, no check is made and records may have a variable field count
fields_per_record: int,
// If trim_leading_space is true, leading whitespace in a field is ignored
// This is done even if the field delimiter (comma), is whitespace
trim_leading_space: bool,
// If lazy_quotes is true, a quote may appear in an unquoted field and a non-doubled quote may appear in a quoted field
lazy_quotes: bool,
// reuse_record controls whether calls to 'read' may return a slice using the backing buffer
// for performance
// By default, each call to 'read' returns a newly allocated slice
reuse_record: bool,
// reuse_record_buffer controls whether calls to 'read' clone the strings of each field or uses
// the data stored in record buffer for performance
// By default, each call to 'read' clones the strings of each field
reuse_record_buffer: bool,
// internal buffers
r: bufio.Reader,
line_count: int, // current line being read in the CSV file
raw_buffer: [dynamic]byte,
record_buffer: [dynamic]byte,
field_indices: [dynamic]int,
last_record: [dynamic]string,
sr: strings.Reader, // used by reader_init_with_string
}
Reader_Error_Kind :: enum {
Bare_Quote,
Quote,
Field_Count,
Invalid_Delim,
}
reader_error_kind_string := [Reader_Error_Kind]string{
.Bare_Quote = "bare \" in non-quoted field",
.Quote = "extra or missing \" in quoted field",
.Field_Count = "wrong field count",
.Invalid_Delim = "invalid delimiter",
};
Reader_Error :: struct {
kind: Reader_Error_Kind,
start_line: int,
line: int,
column: int,
expected, got: int, // used by .Field_Count
}
Error :: union {
Reader_Error,
io.Error,
}
DEFAULT_RECORD_BUFFER_CAPACITY :: 256;
// reader_init initializes a new Reader from r
reader_init :: proc(reader: ^Reader, r: io.Reader, buffer_allocator := context.allocator) {
reader.comma = ',';
context.allocator = buffer_allocator;
reserve(&reader.record_buffer, DEFAULT_RECORD_BUFFER_CAPACITY);
reserve(&reader.raw_buffer, 0);
reserve(&reader.field_indices, 0);
reserve(&reader.last_record, 0);
bufio.reader_init(&reader.r, r);
}
// reader_init_with_string initializes a new Reader from s
reader_init_with_string :: proc(reader: ^Reader, s: string, buffer_allocator := context.allocator) {
strings.reader_init(&reader.sr, s);
r, _ := io.to_reader(strings.reader_to_stream(&reader.sr));
reader_init(reader, r, buffer_allocator);
}
// reader_destroy destroys a Reader
reader_destroy :: proc(r: ^Reader) {
delete(r.raw_buffer);
delete(r.record_buffer);
delete(r.field_indices);
delete(r.last_record);
bufio.reader_destroy(&r.r);
}
// read reads a single record (a slice of fields) from r
//
// All \r\n sequences are normalized to \n, including multi-line field
read :: proc(r: ^Reader, allocator := context.allocator) -> (record: []string, err: Error) {
if r.reuse_record {
record, err = _read_record(r, &r.last_record, allocator);
resize(&r.last_record, len(record));
copy(r.last_record[:], record);
} else {
record, err = _read_record(r, nil, allocator);
}
return;
}
// is_io_error checks where an Error is a specific io.Error kind
is_io_error :: proc(err: Error, io_err: io.Error) -> bool {
if v, ok := err.(io.Error); ok {
return v == io_err;
}
return false;
}
// read_all reads all the remaining records from r.
// Each record is a slice of fields.
// read_all is defined to read until an EOF, and does not treat, and does not treat EOF as an error
read_all :: proc(r: ^Reader, allocator := context.allocator) -> ([][]string, Error) {
context.allocator = allocator;
records: [dynamic][]string;
for {
record, rerr := _read_record(r, nil, allocator);
if is_io_error(rerr, .EOF) {
return records[:], nil;
}
if rerr != nil {
return nil, rerr;
}
append(&records, record);
}
}
// read reads a single record (a slice of fields) from the provided input.
read_from_string :: proc(input: string, record_allocator := context.allocator, buffer_allocator := context.allocator) -> (record: []string, n: int, err: Error) {
ir: strings.Reader;
strings.reader_init(&ir, input);
input_reader, _ := io.to_reader(strings.reader_to_stream(&ir));
r: Reader;
reader_init(&r, input_reader, buffer_allocator);
defer reader_destroy(&r);
record, err = read(&r, record_allocator);
n = int(r.r.r);
return;
}
// read_all reads all the remaining records from the provided input.
read_all_from_string :: proc(input: string, records_allocator := context.allocator, buffer_allocator := context.allocator) -> ([][]string, Error) {
ir: strings.Reader;
strings.reader_init(&ir, input);
input_reader, _ := io.to_reader(strings.reader_to_stream(&ir));
r: Reader;
reader_init(&r, input_reader, buffer_allocator);
defer reader_destroy(&r);
return read_all(&r, records_allocator);
}
@private
is_valid_delim :: proc(r: rune) -> bool {
switch r {
case 0, '"', '\r', '\n', utf8.RUNE_ERROR:
return false;
}
return utf8.valid_rune(r);
}
@private
_read_record :: proc(r: ^Reader, dst: ^[dynamic]string, allocator := context.allocator) -> ([]string, Error) {
read_line :: proc(r: ^Reader) -> ([]byte, io.Error) {
line, err := bufio.reader_read_slice(&r.r, '\n');
if err == .Buffer_Full {
clear(&r.raw_buffer);
append(&r.raw_buffer, ..line);
for err == .Buffer_Full {
line, err = bufio.reader_read_slice(&r.r, '\n');
append(&r.raw_buffer, ..line);
}
line = r.raw_buffer[:];
}
if len(line) > 0 && err == .EOF {
err = nil;
if line[len(line)-1] == '\r' {
line = line[:len(line)-1];
}
}
r.line_count += 1;
// normalize \r\n to \n
n := len(line);
for n >= 2 && string(line[n-2:]) == "\r\n" {
line[n-2] = '\n';
line = line[:n-1];
}
return line, err;
}
length_newline :: proc(b: []byte) -> int {
if len(b) > 0 && b[len(b)-1] == '\n' {
return 1;
}
return 0;
}
next_rune :: proc(b: []byte) -> rune {
r, _ := utf8.decode_rune(b);
return r;
}
if r.comma == r.comment ||
!is_valid_delim(r.comma) ||
(r.comment != 0 && !is_valid_delim(r.comment)) {
err := Reader_Error{
kind = .Invalid_Delim,
line = r.line_count,
};
return nil, err;
}
line, full_line: []byte;
err_read: io.Error;
for err_read == nil {
line, err_read = read_line(r);
if r.comment != 0 && next_rune(line) == r.comment {
line = nil;
continue;
}
if err_read == nil && len(line) == length_newline(line) {
line = nil;
continue;
}
full_line = line;
break;
}
if is_io_error(err_read, .EOF) {
return nil, err_read;
}
err: Error;
quote_len :: len(`"`);
comma_len := utf8.rune_size(r.comma);
record_line := r.line_count;
clear(&r.record_buffer);
clear(&r.field_indices);
parse_field: for {
if r.trim_leading_space {
line = bytes.trim_left_space(line);
}
if len(line) == 0 || line[0] != '"' {
i := bytes.index_rune(line, r.comma);
field := line;
if i >= 0 {
field = field[:i];
} else {
field = field[:len(field) - length_newline(field)];
}
if !r.lazy_quotes {
if j := bytes.index_byte(field, '"'); j >= 0 {
column := utf8.rune_count(full_line[:len(full_line) - len(line[j:])]);
err = Reader_Error{
kind = .Bare_Quote,
start_line = record_line,
line = r.line_count,
column = column,
};
break parse_field;
}
}
append(&r.record_buffer, ..field);
append(&r.field_indices, len(r.record_buffer));
if i >= 0 {
line = line[i+comma_len:];
continue parse_field;
}
break parse_field;
} else {
line = line[quote_len:];
for {
i := bytes.index_byte(line, '"');
switch {
case i >= 0:
append(&r.record_buffer, ..line[:i]);
line = line[i+quote_len:];
switch ch := next_rune(line); {
case ch == '"': // append quote
append(&r.record_buffer, '"');
line = line[quote_len:];
case ch == r.comma: // end of field
line = line[comma_len:];
append(&r.field_indices, len(r.record_buffer));
continue parse_field;
case length_newline(line) == len(line): // end of line
append(&r.field_indices, len(r.record_buffer));
break parse_field;
case r.lazy_quotes: // bare quote
append(&r.record_buffer, '"');
case: // invalid non-escaped quote
column := utf8.rune_count(full_line[:len(full_line) - len(line) - quote_len]);
err = Reader_Error{
kind = .Quote,
start_line = record_line,
line = r.line_count,
column = column,
};
break parse_field;
}
case len(line) > 0:
append(&r.record_buffer, ..line);
if err_read != nil {
break parse_field;
}
line, err_read = read_line(r);
if is_io_error(err_read, .EOF) {
err_read = nil;
}
full_line = line;
case:
if !r.lazy_quotes && err_read == nil {
column := utf8.rune_count(full_line);
err = Reader_Error{
kind = .Quote,
start_line = record_line,
line = r.line_count,
column = column,
};
break parse_field;
}
append(&r.field_indices, len(r.record_buffer));
break parse_field;
}
}
}
}
if err == nil && err_read != nil {
err = err_read;
}
context.allocator = allocator;
dst := dst;
str := string(r.record_buffer[:]);
if dst == nil {
// use local variable
dst = &([dynamic]string){};
}
clear(dst);
resize(dst, len(r.field_indices));
pre_idx: int;
for idx, i in r.field_indices {
field := str[pre_idx:idx];
if !r.reuse_record_buffer {
field = strings.clone(field);
}
dst[i] = field;
pre_idx = idx;
}
if r.fields_per_record > 0 {
if len(dst) != r.fields_per_record && err == nil {
err = Reader_Error{
kind = .Field_Count,
start_line = record_line,
line = r.line_count,
expected = r.fields_per_record,
got = len(dst),
};
}
} else if r.fields_per_record == 0 {
r.fields_per_record = len(dst);
}
return dst[:], err;
}
+126
View File
@@ -0,0 +1,126 @@
package csv
import "core:io"
import "core:strings"
import "core:unicode/utf8"
// Writer is a data structure used for writing records using a CSV-encoding.
Writer :: struct {
// Field delimiter (set to ',' with writer_init)
comma: rune,
// if set to true, \r\n will be used as the line terminator
use_crlf: bool,
w: io.Writer,
}
// writer_init initializes a Writer that writes to w
writer_init :: proc(writer: ^Writer, w: io.Writer) {
writer.comma = ',';
writer.w = w;
}
// write writes a single CSV records to w with any of the necessarily quoting.
// A record is a slice of strings, where each string is a single field.
//
// If the underlying io.Writer requires flushing, make sure to call io.flush
write :: proc(w: ^Writer, record: []string) -> io.Error {
CHAR_SET :: "\n\r\"";
field_needs_quoting :: proc(w: ^Writer, field: string) -> bool {
switch {
case field == "": // No need to quote empty strings
return false;
case field == `\.`: // Postgres is weird
return true;
case w.comma < utf8.RUNE_SELF: // ASCII optimization
for i in 0..<len(field) {
switch field[i] {
case '\n', '\r', '"', byte(w.comma):
return true;
}
}
case:
if strings.contains_rune(field, w.comma) >= 0 {
return true;
}
if strings.contains_any(field, CHAR_SET) {
return true;
}
}
// Leading spaces need quoting
r, _ := utf8.decode_rune_in_string(field);
return strings.is_space(r);
}
if !is_valid_delim(w.comma) {
return .No_Progress; // TODO(bill): Is this a good error?
}
for _, field_idx in record {
// NOTE(bill): declared like this so that the field can be modified later if necessary
field := record[field_idx];
if field_idx > 0 {
io.write_rune(w.w, w.comma) or_return;
}
if !field_needs_quoting(w, field) {
io.write_string(w.w, field) or_return;
continue;
}
io.write_byte(w.w, '"') or_return;
for len(field) > 0 {
i := strings.index_any(field, CHAR_SET);
if i < 0 {
i = len(field);
}
io.write_string(w.w, field[:i]) or_return;
field = field[i:];
if len(field) > 0 {
switch field[0] {
case '\r':
if !w.use_crlf {
io.write_byte(w.w, '\r') or_return;
}
case '\n':
if w.use_crlf {
io.write_string(w.w, "\r\n") or_return;
} else {
io.write_byte(w.w, '\n') or_return;
}
case '"':
io.write_string(w.w, `""`) or_return;
}
field = field[1:];
}
}
io.write_byte(w.w, '"') or_return;
}
if w.use_crlf {
_, err := io.write_string(w.w, "\r\n");
return err;
}
return io.write_byte(w.w, '\n');
}
// write_all writes multiple CSV records to w using write, and then flushes (if necessary).
write_all :: proc(w: ^Writer, records: [][]string) -> io.Error {
for record in records {
write(w, record) or_return;
}
return writer_flush(w);
}
// writer_flush flushes the underlying io.Writer.
// If the underlying io.Writer does not support flush, nil is returned.
writer_flush :: proc(w: ^Writer) -> io.Error {
return io.flush(auto_cast w.w);
}
+83
View File
@@ -0,0 +1,83 @@
// Implementation of the HxA 3D asset format
// HxA is a interchangeable graphics asset format.
// Designed by Eskil Steenberg. @quelsolaar / eskil 'at' obsession 'dot' se / www.quelsolaar.com
//
// Author of this Odin package: Ginger Bill
//
// Following comment is copied from the original C-implementation
// ---------
// -Does the world need another Graphics file format?
// Unfortunately, Yes. All existing formats are either too large and complicated to be implemented from
// scratch, or don't have some basic features needed in modern computer graphics.
// -Who is this format for?
// For people who want a capable open Graphics format that can be implemented from scratch in
// a few hours. It is ideal for graphics researchers, game developers or other people who
// wants to build custom graphics pipelines. Given how easy it is to parse and write, it
// should be easy to write utilities that process assets to preform tasks like: generating
// normals, light-maps, tangent spaces, Error detection, GPU optimization, LOD generation,
// and UV mapping.
// -Why store images in the format when there are so many good image formats already?
// Yes there are, but only for 2D RGB/RGBA images. A lot of computer graphics rendering rely
// on 1D, 3D, cube, multilayer, multi channel, floating point bitmap buffers. There almost no
// formats for this kind of data. Also 3D files that reference separate image files rely on
// file paths, and this often creates issues when the assets are moved. By including the
// texture data in the files directly the assets become self contained.
// -Why doesn't the format support <insert whatever>?
// Because the entire point is to make a format that can be implemented. Features like NURBSs,
// Construction history, or BSP trees would make the format too large to serve its purpose.
// The facilities of the formats to store meta data should make the format flexible enough
// for most uses. Adding HxA support should be something anyone can do in a days work.
// Structure:
// ----------
// HxA is designed to be extremely simple to parse, and is therefore based around conventions. It has
// a few basic structures, and depending on how they are used they mean different things. This means
// that you can implement a tool that loads the entire file, modifies the parts it cares about and
// leaves the rest intact. It is also possible to write a tool that makes all data in the file
// editable without the need to understand its use. It is also possible for anyone to use the format
// to store data axillary data. Anyone who wants to store data not covered by a convention can submit
// a convention to extend the format. There should never be a convention for storing the same data in
// two differed ways.
// The data is story in a number of nodes that are stored in an array. Each node stores an array of
// meta data. Meta data can describe anything you want, and a lot of conventions will use meta data
// to store additional information, for things like transforms, lights, shaders and animation.
// Data for Vertices, Corners, Faces, and Pixels are stored in named layer stacks. Each stack consists
// of a number of named layers. All layers in the stack have the same number of elements. Each layer
// describes one property of the primitive. Each layer can have multiple channels and each layer can
// store data of a different type.
// HaX stores 3 kinds of nodes
// - Pixel data.
// - Polygon geometry data.
// - Meta data only.
// Pixel Nodes stores pixels in a layer stack. A layer may store things like Albedo, Roughness,
// Reflectance, Light maps, Masks, Normal maps, and Displacement. Layers use the channels of the
// layers to store things like color. The length of the layer stack is determined by the type and
// dimensions stored in the
// Geometry data is stored in 3 separate layer stacks for: vertex data, corner data and face data. The
// vertex data stores things like verities, blend shapes, weight maps, and vertex colors. The first
// layer in a vertex stack has to be a 3 channel layer named "position" describing the base position
// of the vertices. The corner stack describes data per corner or edge of the polygons. It can be used
// for things like UV, normals, and adjacency. The first layer in a corner stack has to be a 1 channel
// integer layer named "index" describing the vertices used to form polygons. The last value in each
// polygon has a negative - 1 index to indicate the end of the polygon.
// Example:
// A quad and a tri with the vertex index:
// [0, 1, 2, 3] [1, 4, 2]
// is stored:
// [0, 1, 2, -4, 1, 4, -3]
// The face stack stores values per face. the length of the face stack has to match the number of
// negative values in the index layer in the corner stack. The face stack can be used to store things
// like material index.
// Storage
// -------
// All data is stored in little endian byte order with no padding. The layout mirrors the structs
// defined below with a few exceptions. All names are stored as a 8-bit unsigned integer indicating
// the length of the name followed by that many characters. Termination is not stored in the file.
// Text strings stored in meta data are stored the same way as names, but instead of a 8-bit unsigned
// integer a 32-bit unsigned integer is used.
package encoding_hxa
+193
View File
@@ -0,0 +1,193 @@
package encoding_hxa
import "core:mem"
LATEST_VERSION :: 3;
VERSION_API :: "0.3";
MAGIC_NUMBER :: 'H'<<0 | 'x'<<8 | 'A'<<16 | '\x00'<<24;
Header :: struct #packed {
magic_number: u32le,
version: u32le,
internal_node_count: u32le,
}
File :: struct {
using header: Header,
backing: []byte,
allocator: mem.Allocator,
nodes: []Node,
}
Node_Type :: enum u8 {
Meta_Only = 0, // node only containing meta data.
Geometry = 1, // node containing a geometry mesh, and meta data.
Image = 2, // node containing a 1D, 2D, 3D, or Cube image, and meta data.
}
Layer_Data_Type :: enum u8 {
Uint8 = 0, // 8-bit unsigned integer,
Int32 = 1, // 32-bit little-endian signed integer
Float = 2, // 32-bit little-endian IEEE 754 floating point value
Double = 3, // 64-bit little-endian IEEE 754 floating point value
}
// Pixel data is arranged in the following configurations
Image_Type :: enum u8 {
Image_Cube = 0, // 6 sided qube, in the order of: +x, -x, +y, -y, +z, -z.
Image_1D = 1, // One dimensional pixel data.
Image_2D = 2, // Two dimensional pixel data.
Image_3D = 3, // Three dimensional pixel data.
}
Meta_Value_Type :: enum u8 {
Int64 = 0,
Double = 1,
Node = 2,
Text = 3,
Binary = 4,
Meta = 5,
};
Meta :: struct {
name: string, // name of the meta data value (maximum length is 255)
value: union {
[]i64le,
[]f64le,
[]Node_Index, // a reference to another node
string, // text
[]byte, // binary data
[]Meta,
},
}
Layer :: struct {
name: string, // name of the layer (maximum length is 255)
components: u8, // 2 for uv, 3 for xyz/rgb, 4 for rgba
data: union {
[]u8,
[]i32le,
[]f32le,
[]f64le,
},
}
// Layers stacks are arrays of layers where all the layers have the same number of entries (polygons, edges, vertices or pixels)
Layer_Stack :: distinct []Layer;
Node_Geometry :: struct {
vertex_count: u32le, // number of vertices
vertex_stack: Layer_Stack, // stack of vertex arrays. the first layer is always the vertex positions
edge_corner_count: u32le, // number of corners
corner_stack: Layer_Stack, // stack of corner arrays, the first layer is always a reference array (see below)
edge_stack: Layer_Stack, // stack of edge arrays
face_count: u32le, // number of polygons
face_stack: Layer_Stack, // stack of per polygon data.
}
Node_Image :: struct {
type: Image_Type,
resolution: [3]u32le,
image_stack: Layer_Stack,
}
Node_Index :: distinct u32le;
// A file consists of an array of nodes, All nodes have meta data. Geometry nodes have geometry, image nodes have pixels
Node :: struct {
meta_data: []Meta,
content: union {
Node_Geometry,
Node_Image,
},
}
/* Conventions */
/* ------------
Much of HxA's use is based on convention. HxA lets users store arbitrary data in its structure that can be parsed but whose semantic meaning does not need to be understood.
A few conventions are hard, and some are soft. Hard convention that a user HAS to follow in order to produce a valid file. Hard conventions simplify parsing becaus the parser can make some assumptions. Soft convenbtions are basicly recomendations of how to store common data.
If you use HxA for something not covered by the conventions but need a convention for your use case. Please let us know so that we can add it!
*/
/* Hard conventions */
/* ---------------- */
CONVENTION_HARD_BASE_VERTEX_LAYER_NAME :: "vertex";
CONVENTION_HARD_BASE_VERTEX_LAYER_ID :: 0;
CONVENTION_HARD_BASE_VERTEX_LAYER_COMPONENTS :: 3;
CONVENTION_HARD_BASE_CORNER_LAYER_NAME :: "reference";
CONVENTION_HARD_BASE_CORNER_LAYER_ID :: 0;
CONVENTION_HARD_BASE_CORNER_LAYER_COMPONENTS :: 1;
CONVENTION_HARD_BASE_CORNER_LAYER_TYPE :: Layer_Data_Type.Int32;
CONVENTION_HARD_EDGE_NEIGHBOUR_LAYER_NAME :: "neighbour";
CONVENTION_HARD_EDGE_NEIGHBOUR_LAYER_TYPE :: Layer_Data_Type.Int32;
/* Soft Conventions */
/* ---------------- */
/* geometry layers */
CONVENTION_SOFT_LAYER_SEQUENCE0 :: "sequence";
CONVENTION_SOFT_LAYER_NAME_UV0 :: "uv";
CONVENTION_SOFT_LAYER_NORMALS :: "normal";
CONVENTION_SOFT_LAYER_BINORMAL :: "binormal";
CONVENTION_SOFT_LAYER_TANGENT :: "tangent";
CONVENTION_SOFT_LAYER_COLOR :: "color";
CONVENTION_SOFT_LAYER_CREASES :: "creases";
CONVENTION_SOFT_LAYER_SELECTION :: "select";
CONVENTION_SOFT_LAYER_SKIN_WEIGHT :: "skining_weight";
CONVENTION_SOFT_LAYER_SKIN_REFERENCE :: "skining_reference";
CONVENTION_SOFT_LAYER_BLENDSHAPE :: "blendshape";
CONVENTION_SOFT_LAYER_ADD_BLENDSHAPE :: "addblendshape";
CONVENTION_SOFT_LAYER_MATERIAL_ID :: "material";
/* Image layers */
CONVENTION_SOFT_ALBEDO :: "albedo";
CONVENTION_SOFT_LIGHT :: "light";
CONVENTION_SOFT_DISPLACEMENT :: "displacement";
CONVENTION_SOFT_DISTORTION :: "distortion";
CONVENTION_SOFT_AMBIENT_OCCLUSION :: "ambient_occlusion";
/* tags layers */
CONVENTION_SOFT_NAME :: "name";
CONVENTION_SOFT_TRANSFORM :: "transform";
/* destroy procedures */
meta_destroy :: proc(meta: Meta, allocator := context.allocator) {
if nested, ok := meta.value.([]Meta); ok {
for m in nested {
meta_destroy(m);
}
delete(nested, allocator);
}
}
nodes_destroy :: proc(nodes: []Node, allocator := context.allocator) {
for node in nodes {
for meta in node.meta_data {
meta_destroy(meta);
}
delete(node.meta_data, allocator);
switch n in node.content {
case Node_Geometry:
delete(n.corner_stack, allocator);
delete(n.edge_stack, allocator);
delete(n.face_stack, allocator);
case Node_Image:
delete(n.image_stack, allocator);
}
}
delete(nodes, allocator);
}
file_destroy :: proc(file: File) {
nodes_destroy(file.nodes, file.allocator);
delete(file.backing, file.allocator);
}
+215
View File
@@ -0,0 +1,215 @@
package encoding_hxa
import "core:fmt"
import "core:os"
import "core:mem"
Read_Error :: enum {
None,
Short_Read,
Invalid_Data,
Unable_To_Read_File,
}
read_from_file :: proc(filename: string, print_error := false, allocator := context.allocator) -> (file: File, err: Read_Error) {
context.allocator = allocator;
data, ok := os.read_entire_file(filename);
if !ok {
err = .Unable_To_Read_File;
return;
}
defer if !ok {
delete(data);
} else {
file.backing = data;
}
file, err = read(data, filename, print_error, allocator);
return;
}
read :: proc(data: []byte, filename := "<input>", print_error := false, allocator := context.allocator) -> (file: File, err: Read_Error) {
Reader :: struct {
filename: string,
data: []byte,
offset: int,
print_error: bool,
};
read_value :: proc(r: ^Reader, $T: typeid) -> (value: T, err: Read_Error) {
remaining := len(r.data) - r.offset;
if remaining < size_of(T) {
err = .Short_Read;
return;
}
ptr := raw_data(r.data[r.offset:]);
value = (^T)(ptr)^;
r.offset += size_of(T);
return;
}
read_array :: proc(r: ^Reader, $T: typeid, count: int) -> (value: []T, err: Read_Error) {
remaining := len(r.data) - r.offset;
if remaining < size_of(T)*count {
err = .Short_Read;
return;
}
ptr := raw_data(r.data[r.offset:]);
value = mem.slice_ptr((^T)(ptr), count);
r.offset += size_of(T)*count;
return;
}
read_string :: proc(r: ^Reader, count: int) -> (string, Read_Error) {
buf, err := read_array(r, byte, count);
return string(buf), err;
}
read_name :: proc(r: ^Reader) -> (value: string, err: Read_Error) {
len := read_value(r, u8) or_return;
data := read_array(r, byte, int(len)) or_return;
return string(data[:len]), nil;
}
read_meta :: proc(r: ^Reader, capacity: u32le) -> (meta_data: []Meta, err: Read_Error) {
meta_data = make([]Meta, int(capacity));
count := 0;
defer meta_data = meta_data[:count];
for m in &meta_data {
m.name = read_name(r) or_return;
type := read_value(r, Meta_Value_Type) or_return;
if type > max(Meta_Value_Type) {
if r.print_error {
fmt.eprintf("HxA Error: file '%s' has meta value type %d. Maximum value is ", r.filename, u8(type), u8(max(Meta_Value_Type)));
}
err = .Invalid_Data;
return;
}
array_length := read_value(r, u32le) or_return;
switch type {
case .Int64: m.value = read_array(r, i64le, int(array_length)) or_return;
case .Double: m.value = read_array(r, f64le, int(array_length)) or_return;
case .Node: m.value = read_array(r, Node_Index, int(array_length)) or_return;
case .Text: m.value = read_string(r, int(array_length)) or_return;
case .Binary: m.value = read_array(r, byte, int(array_length)) or_return;
case .Meta: m.value = read_meta(r, array_length) or_return;
}
count += 1;
}
return;
}
read_layer_stack :: proc(r: ^Reader, capacity: u32le) -> (layers: Layer_Stack, err: Read_Error) {
stack_count := read_value(r, u32le) or_return;
layer_count := 0;
layers = make(Layer_Stack, stack_count);
defer layers = layers[:layer_count];
for layer in &layers {
layer.name = read_name(r) or_return;
layer.components = read_value(r, u8) or_return;
type := read_value(r, Layer_Data_Type) or_return;
if type > max(type) {
if r.print_error {
fmt.eprintf("HxA Error: file '%s' has layer data type %d. Maximum value is ", r.filename, u8(type), u8(max(Layer_Data_Type)));
}
err = .Invalid_Data;
return;
}
data_len := int(layer.components) * int(capacity);
switch type {
case .Uint8: layer.data = read_array(r, u8, data_len) or_return;
case .Int32: layer.data = read_array(r, i32le, data_len) or_return;
case .Float: layer.data = read_array(r, f32le, data_len) or_return;
case .Double: layer.data = read_array(r, f64le, data_len) or_return;
}
layer_count += 1;
}
return;
}
if len(data) < size_of(Header) {
return;
}
context.allocator = allocator;
header := cast(^Header)raw_data(data);
assert(header.magic_number == MAGIC_NUMBER);
r := &Reader{
filename = filename,
data = data[:],
offset = size_of(Header),
print_error = print_error,
};
node_count := 0;
file.nodes = make([]Node, header.internal_node_count);
defer if err != nil {
nodes_destroy(file.nodes);
file.nodes = nil;
}
defer file.nodes = file.nodes[:node_count];
for node_idx in 0..<header.internal_node_count {
node := &file.nodes[node_count];
type := read_value(r, Node_Type) or_return;
if type > max(Node_Type) {
if r.print_error {
fmt.eprintf("HxA Error: file '%s' has node type %d. Maximum value is ", r.filename, u8(type), u8(max(Node_Type)));
}
err = .Invalid_Data;
return;
}
node_count += 1;
node.meta_data = read_meta(r, read_value(r, u32le) or_return) or_return;
switch type {
case .Meta_Only:
// Okay
case .Geometry:
g: Node_Geometry;
g.vertex_count = read_value(r, u32le) or_return;
g.vertex_stack = read_layer_stack(r, g.vertex_count) or_return;
g.edge_corner_count = read_value(r, u32le) or_return;
g.corner_stack = read_layer_stack(r, g.edge_corner_count) or_return;
if header.version > 2 {
g.edge_stack = read_layer_stack(r, g.edge_corner_count) or_return;
}
g.face_count = read_value(r, u32le) or_return;
g.face_stack = read_layer_stack(r, g.face_count) or_return;
node.content = g;
case .Image:
img: Node_Image;
img.type = read_value(r, Image_Type) or_return;
dimensions := int(img.type);
if img.type == .Image_Cube {
dimensions = 2;
}
img.resolution = {1, 1, 1};
for d in 0..<dimensions {
img.resolution[d] = read_value(r, u32le) or_return;
}
size := img.resolution[0]*img.resolution[1]*img.resolution[2];
if img.type == .Image_Cube {
size *= 6;
}
img.image_stack = read_layer_stack(r, size) or_return;
node.content = img;
}
}
return;
}
+193
View File
@@ -0,0 +1,193 @@
package encoding_hxa
import "core:os"
import "core:mem"
Write_Error :: enum {
None,
Buffer_Too_Small,
Failed_File_Write,
}
write_to_file :: proc(filepath: string, file: File) -> (err: Write_Error) {
required := required_write_size(file);
buf, alloc_err := make([]byte, required);
if alloc_err == .Out_Of_Memory {
return .Failed_File_Write;
}
defer delete(buf);
write_internal(&Writer{data = buf}, file);
if !os.write_entire_file(filepath, buf) {
err =.Failed_File_Write;
}
return;
}
write :: proc(buf: []byte, file: File) -> (n: int, err: Write_Error) {
required := required_write_size(file);
if len(buf) < required {
err = .Buffer_Too_Small;
return;
}
n = required;
write_internal(&Writer{data = buf}, file);
return;
}
required_write_size :: proc(file: File) -> (n: int) {
writer := &Writer{dummy_pass = true};
write_internal(writer, file);
n = writer.offset;
return;
}
@(private)
Writer :: struct {
data: []byte,
offset: int,
dummy_pass: bool,
};
@(private)
write_internal :: proc(w: ^Writer, file: File) {
write_value :: proc(w: ^Writer, value: $T) {
if !w.dummy_pass {
remaining := len(w.data) - w.offset;
assert(size_of(T) <= remaining);
ptr := raw_data(w.data[w.offset:]);
(^T)(ptr)^ = value;
}
w.offset += size_of(T);
}
write_array :: proc(w: ^Writer, array: []$T) {
if !w.dummy_pass {
remaining := len(w.data) - w.offset;
assert(size_of(T)*len(array) <= remaining);
ptr := raw_data(w.data[w.offset:]);
dst := mem.slice_ptr((^T)(ptr), len(array));
copy(dst, array);
}
w.offset += size_of(T)*len(array);
}
write_string :: proc(w: ^Writer, str: string) {
if !w.dummy_pass {
remaining := len(w.data) - w.offset;
assert(size_of(byte)*len(str) <= remaining);
ptr := raw_data(w.data[w.offset:]);
dst := mem.slice_ptr((^byte)(ptr), len(str));
copy(dst, str);
}
w.offset += size_of(byte)*len(str);
}
write_metadata :: proc(w: ^Writer, meta_data: []Meta) {
for m in meta_data {
name_len := max(len(m.name), 255);
write_value(w, u8(name_len));
write_string(w, m.name[:name_len]);
meta_data_type: Meta_Value_Type;
length: u32le = 0;
switch v in m.value {
case []i64le:
meta_data_type = .Int64;
length = u32le(len(v));
case []f64le:
meta_data_type = .Double;
length = u32le(len(v));
case []Node_Index:
meta_data_type = .Node;
length = u32le(len(v));
case string:
meta_data_type = .Text;
length = u32le(len(v));
case []byte:
meta_data_type = .Binary;
length = u32le(len(v));
case []Meta:
meta_data_type = .Meta;
length = u32le(len(v));
}
write_value(w, meta_data_type);
write_value(w, length);
switch v in m.value {
case []i64le: write_array(w, v);
case []f64le: write_array(w, v);
case []Node_Index: write_array(w, v);
case string: write_string(w, v);
case []byte: write_array(w, v);
case []Meta: write_metadata(w, v);
}
}
return;
}
write_layer_stack :: proc(w: ^Writer, layers: Layer_Stack) {
write_value(w, u32(len(layers)));
for layer in layers {
name_len := max(len(layer.name), 255);
write_value(w, u8(name_len));
write_string(w, layer .name[:name_len]);
write_value(w, layer.components);
layer_data_type: Layer_Data_Type;
switch v in layer.data {
case []u8: layer_data_type = .Uint8;
case []i32le: layer_data_type = .Int32;
case []f32le: layer_data_type = .Float;
case []f64le: layer_data_type = .Double;
}
write_value(w, layer_data_type);
switch v in layer.data {
case []u8: write_array(w, v);
case []i32le: write_array(w, v);
case []f32le: write_array(w, v);
case []f64le: write_array(w, v);
}
}
return;
}
write_value(w, &Header{
magic_number = MAGIC_NUMBER,
version = LATEST_VERSION,
internal_node_count = u32le(len(file.nodes)),
});
for node in file.nodes {
node_type: Node_Type;
switch content in node.content {
case Node_Geometry: node_type = .Geometry;
case Node_Image: node_type = .Image;
}
write_value(w, node_type);
write_value(w, u32(len(node.meta_data)));
write_metadata(w, node.meta_data);
switch content in node.content {
case Node_Geometry:
write_value(w, content.vertex_count);
write_layer_stack(w, content.vertex_stack);
write_value(w, content.edge_corner_count);
write_layer_stack(w, content.corner_stack);
write_layer_stack(w, content.edge_stack);
write_value(w, content.face_count);
write_layer_stack(w, content.face_stack);
case Node_Image:
write_value(w, content.type);
dimensions := int(content.type);
if content.type == .Image_Cube {
dimensions = 2;
}
for d in 0..<dimensions {
write_value(w, content.resolution[d]);
}
write_layer_stack(w, content.image_stack);
}
}
}
+107 -120
View File
@@ -5,19 +5,20 @@ import "core:math/bits"
import "core:runtime"
import "core:strconv"
import "core:strings"
import "core:reflect"
Marshal_Error :: enum {
None,
Unsupported_Type,
Invalid_Data,
}
marshal :: proc(v: any, allocator := context.allocator) -> ([]byte, Marshal_Error) {
b := strings.make_builder(allocator);
b: strings.Builder;
strings.init_builder(&b, allocator);
err := marshal_arg(&b, v);
if err != Marshal_Error.None {
if err != .None {
strings.destroy_builder(&b);
return nil, err;
}
@@ -30,21 +31,19 @@ marshal :: proc(v: any, allocator := context.allocator) -> ([]byte, Marshal_Erro
marshal_arg :: proc(b: ^strings.Builder, v: any) -> Marshal_Error {
using strings;
using runtime;
if v == nil {
write_string(b, "null");
return Marshal_Error.None;
strings.write_string(b, "null");
return .None;
}
ti := type_info_base(type_info_of(v.id));
ti := runtime.type_info_base(type_info_of(v.id));
a := any{v.data, ti.id};
switch info in ti.variant {
case Type_Info_Named:
panic("Unreachable");
case runtime.Type_Info_Named:
unreachable();
case Type_Info_Integer:
case runtime.Type_Info_Integer:
buf: [21]byte;
u: u64;
switch i in a {
@@ -76,18 +75,19 @@ marshal_arg :: proc(b: ^strings.Builder, v: any) -> Marshal_Error {
}
s := strconv.append_bits(buf[:], u, 10, info.signed, 8*ti.size, "0123456789", nil);
write_string(b, s);
strings.write_string(b, s);
case Type_Info_Rune:
case runtime.Type_Info_Rune:
r := a.(rune);
write_byte(b, '"');
write_escaped_rune(b, r, '"', true);
write_byte(b, '"');
strings.write_byte(b, '"');
strings.write_escaped_rune(b, r, '"', true);
strings.write_byte(b, '"');
case Type_Info_Float:
case runtime.Type_Info_Float:
val: f64;
switch f in a {
case f16: val = f64(f);
case f32: val = f64(f);
case f64: val = f64(f);
}
@@ -95,28 +95,31 @@ marshal_arg :: proc(b: ^strings.Builder, v: any) -> Marshal_Error {
buf: [386]byte;
str := strconv.append_float(buf[1:], val, 'f', 2*ti.size, 8*ti.size);
str = string(buf[:len(str)+1]);
if str[1] == '+' || str[1] == '-' {
str = str[1:];
s := buf[:len(str)+1];
if s[1] == '+' || s[1] == '-' {
s = s[1:];
} else {
str[0] = '+';
s[0] = '+';
}
if str[0] == '+' {
str = str[1:];
if s[0] == '+' {
s = s[1:];
}
write_string(b, str);
strings.write_string(b, string(s));
case Type_Info_Complex:
return Marshal_Error.Unsupported_Type;
case runtime.Type_Info_Complex:
return .Unsupported_Type;
case Type_Info_String:
case runtime.Type_Info_Quaternion:
return .Unsupported_Type;
case runtime.Type_Info_String:
switch s in a {
case string: write_quoted_string(b, s);
case cstring: write_quoted_string(b, string(s));
case string: strings.write_quoted_string(b, s);
case cstring: strings.write_quoted_string(b, string(s));
}
case Type_Info_Boolean:
case runtime.Type_Info_Boolean:
val: bool;
switch b in a {
case bool: val = bool(b);
@@ -125,103 +128,112 @@ marshal_arg :: proc(b: ^strings.Builder, v: any) -> Marshal_Error {
case b32: val = bool(b);
case b64: val = bool(b);
}
write_string(b, val ? "true" : "false");
strings.write_string(b, val ? "true" : "false");
case Type_Info_Any:
return Marshal_Error.Unsupported_Type;
case runtime.Type_Info_Any:
return .Unsupported_Type;
case Type_Info_Type_Id:
return Marshal_Error.Unsupported_Type;
case runtime.Type_Info_Type_Id:
return .Unsupported_Type;
case Type_Info_Pointer:
return Marshal_Error.Unsupported_Type;
case runtime.Type_Info_Pointer:
return .Unsupported_Type;
case Type_Info_Procedure:
return Marshal_Error.Unsupported_Type;
case runtime.Type_Info_Multi_Pointer:
return .Unsupported_Type;
case Type_Info_Tuple:
return Marshal_Error.Unsupported_Type;
case runtime.Type_Info_Procedure:
return .Unsupported_Type;
case Type_Info_Array:
write_byte(b, '[');
case runtime.Type_Info_Tuple:
return .Unsupported_Type;
case runtime.Type_Info_Enumerated_Array:
return .Unsupported_Type;
case runtime.Type_Info_Simd_Vector:
return .Unsupported_Type;
case runtime.Type_Info_Relative_Pointer:
return .Unsupported_Type;
case runtime.Type_Info_Relative_Slice:
return .Unsupported_Type;
case runtime.Type_Info_Array:
strings.write_byte(b, '[');
for i in 0..<info.count {
if i > 0 do write_string(b, ", ");
if i > 0 { strings.write_string(b, ", "); }
data := uintptr(v.data) + uintptr(i*info.elem_size);
marshal_arg(b, any{rawptr(data), info.elem.id});
}
write_byte(b, ']');
strings.write_byte(b, ']');
case Type_Info_Dynamic_Array:
write_byte(b, '[');
case runtime.Type_Info_Dynamic_Array:
strings.write_byte(b, '[');
array := cast(^mem.Raw_Dynamic_Array)v.data;
for i in 0..<array.len {
if i > 0 do write_string(b, ", ");
if i > 0 { strings.write_string(b, ", "); }
data := uintptr(array.data) + uintptr(i*info.elem_size);
marshal_arg(b, any{rawptr(data), info.elem.id});
}
write_byte(b, ']');
strings.write_byte(b, ']');
case Type_Info_Slice:
write_byte(b, '[');
case runtime.Type_Info_Slice:
strings.write_byte(b, '[');
slice := cast(^mem.Raw_Slice)v.data;
for i in 0..<slice.len {
if i > 0 do write_string(b, ", ");
if i > 0 { strings.write_string(b, ", "); }
data := uintptr(slice.data) + uintptr(i*info.elem_size);
marshal_arg(b, any{rawptr(data), info.elem.id});
}
write_byte(b, ']');
strings.write_byte(b, ']');
case Type_Info_Map:
case runtime.Type_Info_Map:
m := (^mem.Raw_Map)(v.data);
write_byte(b, '{');
strings.write_byte(b, '{');
if m != nil {
if info.generated_struct == nil {
return Marshal_Error.Unsupported_Type;
return .Unsupported_Type;
}
entries := &m.entries;
gs := type_info_base(info.generated_struct).variant.(Type_Info_Struct);
ed := type_info_base(gs.types[1]).variant.(Type_Info_Dynamic_Array);
entry_type := ed.elem.variant.(Type_Info_Struct);
gs := runtime.type_info_base(info.generated_struct).variant.(runtime.Type_Info_Struct);
ed := runtime.type_info_base(gs.types[1]).variant.(runtime.Type_Info_Dynamic_Array);
entry_type := ed.elem.variant.(runtime.Type_Info_Struct);
entry_size := ed.elem_size;
for i in 0..<entries.len {
if i > 0 do write_string(b, ", ");
if i > 0 { strings.write_string(b, ", "); }
data := uintptr(entries.data) + uintptr(i*entry_size);
header := cast(^Map_Entry_Header)data;
key := rawptr(data + entry_type.offsets[2]);
value := rawptr(data + entry_type.offsets[3]);
if reflect.is_string(info.key) {
marshal_arg(b, header.key.str);
} else {
marshal_arg(b, any{rawptr(&header.key.hash), info.key.id});
}
write_string(b, ": ");
value := data + entry_type.offsets[2];
marshal_arg(b, any{rawptr(value), info.value.id});
marshal_arg(b, any{key, info.key.id});
strings.write_string(b, ": ");
marshal_arg(b, any{value, info.value.id});
}
}
write_byte(b, '}');
strings.write_byte(b, '}');
case Type_Info_Struct:
write_byte(b, '{');
case runtime.Type_Info_Struct:
strings.write_byte(b, '{');
for name, i in info.names {
if i > 0 do write_string(b, ", ");
write_quoted_string(b, name);
write_string(b, ": ");
if i > 0 { strings.write_string(b, ", "); }
strings.write_quoted_string(b, name);
strings.write_string(b, ": ");
id := info.types[i].id;
data := rawptr(uintptr(v.data) + info.offsets[i]);
marshal_arg(b, any{data, id});
}
write_byte(b, '}');
strings.write_byte(b, '}');
case Type_Info_Union:
case runtime.Type_Info_Union:
tag_ptr := uintptr(v.data) + info.tag_offset;
tag_any := any{rawptr(tag_ptr), info.tag_type.id};
@@ -239,50 +251,22 @@ marshal_arg :: proc(b: ^strings.Builder, v: any) -> Marshal_Error {
}
if v.data == nil || tag == 0 {
write_string(b, "null");
strings.write_string(b, "null");
} else {
id := info.variants[tag-1].id;
marshal_arg(b, any{v.data, id});
}
case Type_Info_Enum:
case runtime.Type_Info_Enum:
return marshal_arg(b, any{v.data, info.base.id});
case Type_Info_Bit_Field:
data: u64 = 0;
switch ti.size {
case 1: data = cast(u64) (^u8)(v.data)^;
case 2: data = cast(u64)(^u16)(v.data)^;
case 4: data = cast(u64)(^u32)(v.data)^;
case 8: data = cast(u64)(^u64)(v.data)^;
}
write_byte(b, '{');
for name, i in info.names {
if i > 0 do write_string(b, ", ");
bits := u64(info.bits[i]);
offset := u64(info.offsets[i]);
marshal_arg(b, name);
write_string(b, ": ");
n := 8*u64(size_of(u64));
sa := n - bits;
u := data>>offset;
u <<= sa;
u >>= sa;
write_u64(b, u, 10);
}
write_byte(b, '}');
case Type_Info_Bit_Set:
case runtime.Type_Info_Bit_Set:
is_bit_set_different_endian_to_platform :: proc(ti: ^runtime.Type_Info) -> bool {
if ti == nil {
return false;
}
t := runtime.type_info_base(ti);
switch info in t.variant {
#partial switch info in t.variant {
case runtime.Type_Info_Integer:
switch info.endianness {
case .Platform: return false;
@@ -305,26 +289,29 @@ marshal_arg :: proc(b: ^strings.Builder, v: any) -> Marshal_Error {
bit_data = u64(x);
case 16:
x := (^u16)(v.data)^;
if do_byte_swap do x = bits.byte_swap(x);
if do_byte_swap {
x = bits.byte_swap(x);
}
bit_data = u64(x);
case 32:
x := (^u32)(v.data)^;
if do_byte_swap do x = bits.byte_swap(x);
if do_byte_swap {
x = bits.byte_swap(x);
}
bit_data = u64(x);
case 64:
x := (^u64)(v.data)^;
if do_byte_swap do x = bits.byte_swap(x);
if do_byte_swap {
x = bits.byte_swap(x);
}
bit_data = u64(x);
case: panic("unknown bit_size size");
}
write_u64(b, bit_data);
strings.write_u64(b, bit_data);
return Marshal_Error.Unsupported_Type;
case Type_Info_Opaque:
return Marshal_Error.Unsupported_Type;
return .Unsupported_Type;
}
return Marshal_Error.None;
return .None;
}
+72 -100
View File
@@ -5,16 +5,18 @@ import "core:unicode/utf8"
import "core:strconv"
Parser :: struct {
tok: Tokenizer,
prev_token: Token,
curr_token: Token,
spec: Specification,
allocator: mem.Allocator,
tok: Tokenizer,
prev_token: Token,
curr_token: Token,
spec: Specification,
allocator: mem.Allocator,
unmarshal_data: any,
parse_integers: bool,
}
make_parser :: proc(data: []byte, spec := Specification.JSON, allocator := context.allocator) -> Parser {
make_parser :: proc(data: []byte, spec := Specification.JSON, parse_integers := false, allocator := context.allocator) -> Parser {
p: Parser;
p.tok = make_tokenizer(data, spec);
p.tok = make_tokenizer(data, spec, parse_integers);
p.spec = spec;
p.allocator = allocator;
assert(p.allocator.procedure != nil);
@@ -22,9 +24,9 @@ make_parser :: proc(data: []byte, spec := Specification.JSON, allocator := conte
return p;
}
parse :: proc(data: []byte, spec := Specification.JSON, allocator := context.allocator) -> (Value, Error) {
parse :: proc(data: []byte, spec := Specification.JSON, parse_integers := false, allocator := context.allocator) -> (Value, Error) {
context.allocator = allocator;
p := make_parser(data, spec, allocator);
p := make_parser(data, spec, parse_integers, allocator);
if p.spec == Specification.JSON5 {
return parse_value(&p);
@@ -46,7 +48,7 @@ advance_token :: proc(p: ^Parser) -> (Token, Error) {
}
allow_token :: proc(p: ^Parser, kind: Kind) -> bool {
allow_token :: proc(p: ^Parser, kind: Token_Kind) -> bool {
if p.curr_token.kind == kind {
advance_token(p);
return true;
@@ -54,127 +56,115 @@ allow_token :: proc(p: ^Parser, kind: Kind) -> bool {
return false;
}
expect_token :: proc(p: ^Parser, kind: Kind) -> Error {
expect_token :: proc(p: ^Parser, kind: Token_Kind) -> Error {
prev := p.curr_token;
advance_token(p);
if prev.kind == kind {
return Error.None;
return .None;
}
return Error.Unexpected_Token;
return .Unexpected_Token;
}
parse_value :: proc(p: ^Parser) -> (value: Value, err: Error) {
value.pos = p.curr_token.pos;
defer value.end = token_end_pos(p.prev_token);
token := p.curr_token;
switch token.kind {
case Kind.Null:
value.value = Null{};
#partial switch token.kind {
case .Null:
value = Null{};
advance_token(p);
return;
case Kind.False:
value.value = Boolean(false);
case .False:
value = Boolean(false);
advance_token(p);
return;
case Kind.True:
value.value = Boolean(true);
case .True:
value = Boolean(true);
advance_token(p);
return;
case Kind.Integer:
value.value = Integer(strconv.parse_i64(token.text));
case .Integer:
i, _ := strconv.parse_i64(token.text);
value = Integer(i);
advance_token(p);
return;
case Kind.Float:
value.value = Float(strconv.parse_f64(token.text));
case .Float:
f, _ := strconv.parse_f64(token.text);
value = Float(f);
advance_token(p);
return;
case Kind.String:
value.value = String(unquote_string(token, p.spec, p.allocator));
case .String:
value = String(unquote_string(token, p.spec, p.allocator));
advance_token(p);
return;
case Kind.Open_Brace:
case .Open_Brace:
return parse_object(p);
case Kind.Open_Bracket:
case .Open_Bracket:
return parse_array(p);
case:
if p.spec == Specification.JSON5 {
switch token.kind {
case Kind.Infinity:
#partial switch token.kind {
case .Infinity:
inf: u64 = 0x7ff0000000000000;
if token.text[0] == '-' {
inf = 0xfff0000000000000;
}
value.value = transmute(f64)inf;
value = transmute(f64)inf;
advance_token(p);
return;
case Kind.NaN:
case .NaN:
nan: u64 = 0x7ff7ffffffffffff;
if token.text[0] == '-' {
nan = 0xfff7ffffffffffff;
}
value.value = transmute(f64)nan;
value = transmute(f64)nan;
advance_token(p);
return;
}
}
}
err = Error.Unexpected_Token;
err = .Unexpected_Token;
advance_token(p);
return;
}
parse_array :: proc(p: ^Parser) -> (value: Value, err: Error) {
value.pos = p.curr_token.pos;
defer value.end = token_end_pos(p.prev_token);
if err = expect_token(p, Kind.Open_Bracket); err != Error.None {
return;
}
expect_token(p, .Open_Bracket) or_return;
array: Array;
array.allocator = p.allocator;
defer if err != Error.None {
defer if err != .None {
for elem in array {
destroy_value(elem);
}
delete(array);
}
for p.curr_token.kind != Kind.Close_Bracket {
elem, elem_err := parse_value(p);
if elem_err != Error.None {
err = elem_err;
return;
}
for p.curr_token.kind != .Close_Bracket {
elem := parse_value(p) or_return;
append(&array, elem);
// Disallow trailing commas for the time being
if allow_token(p, Kind.Comma) {
if allow_token(p, .Comma) {
continue;
} else {
break;
}
}
if err = expect_token(p, Kind.Close_Bracket); err != Error.None {
return;
}
value.value = array;
expect_token(p, .Close_Bracket) or_return;
value = array;
return;
}
clone_string :: proc(s: string, allocator: mem.Allocator) -> string {
n := len(s);
b := make([]byte, n+1, allocator);
copy(b, cast([]byte)s);
copy(b, s);
b[n] = 0;
return string(b[:n]);
}
@@ -182,18 +172,18 @@ clone_string :: proc(s: string, allocator: mem.Allocator) -> string {
parse_object_key :: proc(p: ^Parser) -> (key: string, err: Error) {
tok := p.curr_token;
if p.spec == Specification.JSON5 {
if tok.kind == Kind.String {
expect_token(p, Kind.String);
if tok.kind == .String {
expect_token(p, .String);
key = unquote_string(tok, p.spec, p.allocator);
return;
} else if tok.kind == Kind.Ident {
expect_token(p, Kind.Ident);
} else if tok.kind == .Ident {
expect_token(p, .Ident);
key = clone_string(tok.text, p.allocator);
return;
}
}
if tok_err := expect_token(p, Kind.String); tok_err != Error.None {
err = Error.Expected_String_For_Object_Key;
if tok_err := expect_token(p, .String); tok_err != .None {
err = .Expected_String_For_Object_Key;
return;
}
key = unquote_string(tok, p.spec, p.allocator);
@@ -201,17 +191,11 @@ parse_object_key :: proc(p: ^Parser) -> (key: string, err: Error) {
}
parse_object :: proc(p: ^Parser) -> (value: Value, err: Error) {
value.pos = p.curr_token.pos;
defer value.end = token_end_pos(p.prev_token);
if err = expect_token(p, Kind.Open_Brace); err != Error.None {
value.pos = p.curr_token.pos;
return;
}
expect_token(p, .Open_Brace) or_return;
obj: Object;
obj.allocator = p.allocator;
defer if err != Error.None {
defer if err != .None {
for key, elem in obj {
delete(key, p.allocator);
destroy_value(elem);
@@ -219,31 +203,23 @@ parse_object :: proc(p: ^Parser) -> (value: Value, err: Error) {
delete(obj);
}
for p.curr_token.kind != Kind.Close_Brace {
for p.curr_token.kind != .Close_Brace {
key: string;
key, err = parse_object_key(p);
if err != Error.None {
if err != .None {
delete(key, p.allocator);
value.pos = p.curr_token.pos;
return;
}
if colon_err := expect_token(p, Kind.Colon); colon_err != Error.None {
err = Error.Expected_Colon_After_Key;
value.pos = p.curr_token.pos;
if colon_err := expect_token(p, .Colon); colon_err != .None {
err = .Expected_Colon_After_Key;
return;
}
elem, elem_err := parse_value(p);
if elem_err != Error.None {
err = elem_err;
value.pos = p.curr_token.pos;
return;
}
elem := parse_value(p) or_return;
if key in obj {
err = Error.Duplicate_Object_Key;
value.pos = p.curr_token.pos;
err = .Duplicate_Object_Key;
delete(key, p.allocator);
return;
}
@@ -252,12 +228,12 @@ parse_object :: proc(p: ^Parser) -> (value: Value, err: Error) {
if p.spec == Specification.JSON5 {
// Allow trailing commas
if allow_token(p, Kind.Comma) {
if allow_token(p, .Comma) {
continue;
}
} else {
// Disallow trailing commas
if allow_token(p, Kind.Comma) {
if allow_token(p, .Comma) {
continue;
} else {
break;
@@ -265,12 +241,8 @@ parse_object :: proc(p: ^Parser) -> (value: Value, err: Error) {
}
}
if err = expect_token(p, Kind.Close_Brace); err != Error.None {
value.pos = p.curr_token.pos;
return;
}
value.value = obj;
expect_token(p, .Close_Brace) or_return;
value = obj;
return;
}
@@ -286,9 +258,9 @@ unquote_string :: proc(token: Token, spec: Specification, allocator := context.a
for c in s[2:4] {
x: rune;
switch c {
case '0'..'9': x = c - '0';
case 'a'..'f': x = c - 'a' + 10;
case 'A'..'F': x = c - 'A' + 10;
case '0'..='9': x = c - '0';
case 'a'..='f': x = c - 'a' + 10;
case 'A'..='F': x = c - 'A' + 10;
case: return -1;
}
r = r*16 + x;
@@ -304,9 +276,9 @@ unquote_string :: proc(token: Token, spec: Specification, allocator := context.a
for c in s[2:6] {
x: rune;
switch c {
case '0'..'9': x = c - '0';
case 'a'..'f': x = c - 'a' + 10;
case 'A'..'F': x = c - 'A' + 10;
case '0'..='9': x = c - '0';
case 'a'..='f': x = c - 'a' + 10;
case 'A'..='F': x = c - 'A' + 10;
case: return -1;
}
r = r*16 + x;
@@ -314,7 +286,7 @@ unquote_string :: proc(token: Token, spec: Specification, allocator := context.a
return r;
}
if token.kind != Kind.String {
if token.kind != .String {
return "";
}
s := token.text;
@@ -349,7 +321,7 @@ unquote_string :: proc(token: Token, spec: Specification, allocator := context.a
}
b := make([]byte, len(s) + 2*utf8.UTF_MAX, allocator);
w := copy(b, cast([]byte)s[0:i]);
w := copy(b, s[0:i]);
loop: for i < len(s) {
c := s[i];
switch {
+76 -58
View File
@@ -2,14 +2,21 @@ package json
import "core:unicode/utf8"
Pos :: struct {
offset: int,
line: int,
column: int,
}
Token :: struct {
using pos: Pos,
kind: Kind,
kind: Token_Kind,
text: string,
}
Kind :: enum {
Token_Kind :: enum {
Invalid,
EOF,
Null,
False,
@@ -41,12 +48,13 @@ Tokenizer :: struct {
w: int, // current rune width in bytes
curr_line_offset: int,
spec: Specification,
parse_integers: bool,
}
make_tokenizer :: proc(data: []byte, spec := Specification.JSON) -> Tokenizer {
t := Tokenizer{pos = {line=1}, data = data, spec = spec};
make_tokenizer :: proc(data: []byte, spec := Specification.JSON, parse_integers := false) -> Tokenizer {
t := Tokenizer{pos = {line=1}, data = data, spec = spec, parse_integers = parse_integers};
next_rune(&t);
if t.r == utf8.RUNE_BOM {
next_rune(&t);
@@ -80,7 +88,7 @@ get_token :: proc(t: ^Tokenizer) -> (token: Token, err: Error) {
for t.offset < len(t.data) {
next_rune(t);
switch t.r {
case '0'..'9', 'a'..'f', 'A'..'F':
case '0'..='9', 'a'..='f', 'A'..='F':
// Okay
case:
return;
@@ -98,12 +106,13 @@ get_token :: proc(t: ^Tokenizer) -> (token: Token, err: Error) {
for i := 0; i < 4; i += 1 {
r := next_rune(t);
switch r {
case '0'..'9', 'a'..'f', 'A'..'F':
case '0'..='9', 'a'..='f', 'A'..='F':
// Okay
case:
return false;
}
}
return true;
case:
// Ignore the next rune regardless
next_rune(t);
@@ -122,7 +131,7 @@ get_token :: proc(t: ^Tokenizer) -> (token: Token, err: Error) {
t.pos.column = 1;
next_rune(t);
case:
if t.spec == Specification.JSON5 {
if t.spec == .JSON5 {
switch t.r {
case 0x2028, 0x2029, 0xFEFF:
next_rune(t);
@@ -147,7 +156,7 @@ get_token :: proc(t: ^Tokenizer) -> (token: Token, err: Error) {
skip_alphanum :: proc(t: ^Tokenizer) {
for t.offset < len(t.data) {
switch next_rune(t) {
case 'A'..'Z', 'a'..'z', '0'..'9', '_':
case 'A'..='Z', 'a'..='z', '0'..='9', '_':
continue;
}
@@ -159,64 +168,67 @@ get_token :: proc(t: ^Tokenizer) -> (token: Token, err: Error) {
token.pos = t.pos;
token.kind = Kind.Invalid;
token.kind = .Invalid;
curr_rune := t.r;
next_rune(t);
block: switch curr_rune {
case utf8.RUNE_ERROR:
err = Error.Illegal_Character;
err = .Illegal_Character;
case utf8.RUNE_EOF, '\x00':
err = Error.EOF;
token.kind = .EOF;
err = .EOF;
case 'A'..'Z', 'a'..'z', '_':
token.kind = Kind.Ident;
case 'A'..='Z', 'a'..='z', '_':
token.kind = .Ident;
skip_alphanum(t);
switch str := string(t.data[token.offset:t.offset]); str {
case "null": token.kind = Kind.Null;
case "false": token.kind = Kind.False;
case "true": token.kind = Kind.True;
case "null": token.kind = .Null;
case "false": token.kind = .False;
case "true": token.kind = .True;
case:
if t.spec == Specification.JSON5 do switch str {
case "Infinity": token.kind = Kind.Infinity;
case "NaN": token.kind = Kind.NaN;
if t.spec == .JSON5 {
switch str {
case "Infinity": token.kind = .Infinity;
case "NaN": token.kind = .NaN;
}
}
}
case '+':
err = Error.Illegal_Character;
if t.spec != Specification.JSON5 {
err = .Illegal_Character;
if t.spec != .JSON5 {
break;
}
fallthrough;
case '-':
switch t.r {
case '0'..'9':
case '0'..='9':
// Okay
case:
// Illegal use of +/-
err = Error.Illegal_Character;
err = .Illegal_Character;
if t.spec == Specification.JSON5 {
if t.spec == .JSON5 {
if t.r == 'I' || t.r == 'N' {
skip_alphanum(t);
}
switch string(t.data[token.offset:t.offset]) {
case "-Infinity": token.kind = Kind.Infinity;
case "-NaN": token.kind = Kind.NaN;
case "-Infinity": token.kind = .Infinity;
case "-NaN": token.kind = .NaN;
}
}
break block;
}
fallthrough;
case '0'..'9':
token.kind = Kind.Integer;
if t.spec == Specification.JSON5 { // Hexadecimal Numbers
case '0'..='9':
token.kind = t.parse_integers ? .Integer : .Float;
if t.spec == .JSON5 { // Hexadecimal Numbers
if curr_rune == '0' && (t.r == 'x' || t.r == 'X') {
next_rune(t);
skip_hex_digits(t);
@@ -227,7 +239,7 @@ get_token :: proc(t: ^Tokenizer) -> (token: Token, err: Error) {
skip_digits(t);
if t.r == '.' {
token.kind = Kind.Float;
token.kind = .Float;
next_rune(t);
skip_digits(t);
}
@@ -241,12 +253,12 @@ get_token :: proc(t: ^Tokenizer) -> (token: Token, err: Error) {
str := string(t.data[token.offset:t.offset]);
if !is_valid_number(str, t.spec) {
err = Error.Invalid_Number;
err = .Invalid_Number;
}
case '.':
err = Error.Illegal_Character;
if t.spec == Specification.JSON5 { // Allow leading decimal point
err = .Illegal_Character;
if t.spec == .JSON5 { // Allow leading decimal point
skip_digits(t);
if t.r == 'e' || t.r == 'E' {
switch r := next_rune(t); r {
@@ -257,24 +269,24 @@ get_token :: proc(t: ^Tokenizer) -> (token: Token, err: Error) {
}
str := string(t.data[token.offset:t.offset]);
if !is_valid_number(str, t.spec) {
err = Error.Invalid_Number;
err = .Invalid_Number;
}
}
case '\'':
err = Error.Illegal_Character;
if t.spec != Specification.JSON5 {
err = .Illegal_Character;
if t.spec != .JSON5 {
break;
}
fallthrough;
case '"':
token.kind = Kind.String;
token.kind = .String;
quote := curr_rune;
for t.offset < len(t.data) {
r := t.r;
if r == '\n' || r < 0 {
err = Error.String_Not_Terminated;
err = .String_Not_Terminated;
break;
}
next_rune(t);
@@ -288,20 +300,20 @@ get_token :: proc(t: ^Tokenizer) -> (token: Token, err: Error) {
str := string(t.data[token.offset : t.offset]);
if !is_valid_string_literal(str, t.spec) {
err = Error.Invalid_String;
err = .Invalid_String;
}
case ',': token.kind = Kind.Comma;
case ':': token.kind = Kind.Colon;
case '{': token.kind = Kind.Open_Brace;
case '}': token.kind = Kind.Close_Brace;
case '[': token.kind = Kind.Open_Bracket;
case ']': token.kind = Kind.Close_Bracket;
case ',': token.kind = .Comma;
case ':': token.kind = .Colon;
case '{': token.kind = .Open_Brace;
case '}': token.kind = .Close_Brace;
case '[': token.kind = .Open_Bracket;
case ']': token.kind = .Close_Bracket;
case '/':
err = Error.Illegal_Character;
if t.spec == Specification.JSON5 {
err = .Illegal_Character;
if t.spec == .JSON5 {
switch t.r {
case '/':
// Single-line comments
@@ -319,11 +331,11 @@ get_token :: proc(t: ^Tokenizer) -> (token: Token, err: Error) {
}
}
}
err = Error.EOF;
err = .EOF;
}
}
case: err = Error.Illegal_Character;
case: err = .Illegal_Character;
}
token.text = string(t.data[token.offset : t.offset]);
@@ -344,7 +356,7 @@ is_valid_number :: proc(str: string, spec: Specification) -> bool {
if s == "" {
return false;
}
} else if spec == Specification.JSON5 {
} else if spec == .JSON5 {
if s[0] == '+' { // Allow positive sign
s = s[1:];
if s == "" {
@@ -356,11 +368,13 @@ is_valid_number :: proc(str: string, spec: Specification) -> bool {
switch s[0] {
case '0':
s = s[1:];
case '1'..'9':
case '1'..='9':
s = s[1:];
for len(s) > 0 && '0' <= s[0] && s[0] <= '9' do s = s[1:];
for len(s) > 0 && '0' <= s[0] && s[0] <= '9' {
s = s[1:];
}
case '.':
if spec == Specification.JSON5 { // Allow leading decimal point
if spec == .JSON5 { // Allow leading decimal point
s = s[1:];
} else {
return false;
@@ -369,7 +383,7 @@ is_valid_number :: proc(str: string, spec: Specification) -> bool {
return false;
}
if spec == Specification.JSON5 {
if spec == .JSON5 {
if len(s) == 1 && s[0] == '.' { // Allow trailing decimal point
return true;
}
@@ -377,7 +391,9 @@ is_valid_number :: proc(str: string, spec: Specification) -> bool {
if len(s) >= 2 && s[0] == '.' && '0' <= s[1] && s[1] <= '9' {
s = s[2:];
for len(s) > 0 && '0' <= s[0] && s[0] <= '9' do s = s[1:];
for len(s) > 0 && '0' <= s[0] && s[0] <= '9' {
s = s[1:];
}
}
if len(s) >= 2 && (s[0] == 'e' || s[0] == 'E') {
@@ -389,7 +405,9 @@ is_valid_number :: proc(str: string, spec: Specification) -> bool {
return false;
}
}
for len(s) > 0 && '0' <= s[0] && s[0] <= '9' do s = s[1:];
for len(s) > 0 && '0' <= s[0] && s[0] <= '9' {
s = s[1:];
}
}
// The string should be empty now to be valid
@@ -406,7 +424,7 @@ is_valid_string_literal :: proc(str: string, spec: Specification) -> bool {
return false;
}
if s[0] != '"' || s[len(s)-1] != '"' {
if spec == Specification.JSON5 {
if spec == .JSON5 {
if s[0] != '\'' || s[len(s)-1] != '\'' {
return false;
}
@@ -442,7 +460,7 @@ is_valid_string_literal :: proc(str: string, spec: Specification) -> bool {
for j := 0; j < 4; j += 1 {
c2 := hex[j];
switch c2 {
case '0'..'9', 'a'..'z', 'A'..'Z':
case '0'..='9', 'a'..='z', 'A'..='Z':
// Okay
case:
return false;
+14 -21
View File
@@ -2,7 +2,8 @@ package json
Specification :: enum {
JSON,
JSON5,
JSON5, // https://json5.org/
// MJSON, // http://bitsquid.blogspot.com/2009/09/json-configuration-data.html
}
Null :: distinct rawptr;
@@ -13,26 +14,16 @@ String :: string;
Array :: distinct [dynamic]Value;
Object :: distinct map[string]Value;
Value :: struct {
pos, end: Pos,
value: union {
Null,
Integer,
Float,
Boolean,
String,
Array,
Object,
}
Value :: union {
Null,
Integer,
Float,
Boolean,
String,
Array,
Object,
}
Pos :: struct {
offset: int,
line: int,
column: int,
}
Error :: enum {
None,
@@ -56,7 +47,7 @@ Error :: enum {
destroy_value :: proc(value: Value) {
switch v in value.value {
#partial switch v in value {
case Object:
for key, elem in v {
delete(key);
@@ -64,7 +55,9 @@ destroy_value :: proc(value: Value) {
}
delete(v);
case Array:
for elem in v do destroy_value(elem);
for elem in v {
destroy_value(elem);
}
delete(v);
case String:
delete(v);
+25 -26
View File
@@ -3,8 +3,8 @@ package json
import "core:mem"
// NOTE(bill): is_valid will not check for duplicate keys
is_valid :: proc(data: []byte, spec := Specification.JSON) -> bool {
p := make_parser(data, spec, mem.nil_allocator());
is_valid :: proc(data: []byte, spec := Specification.JSON, parse_integers := false) -> bool {
p := make_parser(data, spec, parse_integers, mem.nil_allocator());
if p.spec == Specification.JSON5 {
return validate_value(&p);
}
@@ -14,27 +14,27 @@ is_valid :: proc(data: []byte, spec := Specification.JSON) -> bool {
validate_object_key :: proc(p: ^Parser) -> bool {
tok := p.curr_token;
if p.spec == Specification.JSON5 {
if tok.kind == Kind.String {
expect_token(p, Kind.String);
if tok.kind == .String {
expect_token(p, .String);
return true;
} else if tok.kind == Kind.Ident {
expect_token(p, Kind.Ident);
} else if tok.kind == .Ident {
expect_token(p, .Ident);
return true;
}
}
err := expect_token(p, Kind.String);
err := expect_token(p, .String);
return err == Error.None;
}
validate_object :: proc(p: ^Parser) -> bool {
if err := expect_token(p, Kind.Open_Brace); err != Error.None {
if err := expect_token(p, .Open_Brace); err != Error.None {
return false;
}
for p.curr_token.kind != Kind.Close_Brace {
for p.curr_token.kind != .Close_Brace {
if !validate_object_key(p) {
return false;
}
if colon_err := expect_token(p, Kind.Colon); colon_err != Error.None {
if colon_err := expect_token(p, .Colon); colon_err != Error.None {
return false;
}
@@ -44,12 +44,12 @@ validate_object :: proc(p: ^Parser) -> bool {
if p.spec == Specification.JSON5 {
// Allow trailing commas
if allow_token(p, Kind.Comma) {
if allow_token(p, .Comma) {
continue;
}
} else {
// Disallow trailing commas
if allow_token(p, Kind.Comma) {
if allow_token(p, .Comma) {
continue;
} else {
break;
@@ -57,31 +57,31 @@ validate_object :: proc(p: ^Parser) -> bool {
}
}
if err := expect_token(p, Kind.Close_Brace); err != Error.None {
if err := expect_token(p, .Close_Brace); err != Error.None {
return false;
}
return true;
}
validate_array :: proc(p: ^Parser) -> bool {
if err := expect_token(p, Kind.Open_Bracket); err != Error.None {
if err := expect_token(p, .Open_Bracket); err != Error.None {
return false;
}
for p.curr_token.kind != Kind.Close_Bracket {
for p.curr_token.kind != .Close_Bracket {
if !validate_value(p) {
return false;
}
// Disallow trailing commas for the time being
if allow_token(p, Kind.Comma) {
if allow_token(p, .Comma) {
continue;
} else {
break;
}
}
if err := expect_token(p, Kind.Close_Bracket); err != Error.None {
if err := expect_token(p, .Close_Bracket); err != Error.None {
return false;
}
@@ -91,28 +91,27 @@ validate_array :: proc(p: ^Parser) -> bool {
validate_value :: proc(p: ^Parser) -> bool {
token := p.curr_token;
using Kind;
switch token.kind {
case Null, False, True:
#partial switch token.kind {
case .Null, .False, .True:
advance_token(p);
return true;
case Integer, Float:
case .Integer, .Float:
advance_token(p);
return true;
case String:
case .String:
advance_token(p);
return is_valid_string_literal(token.text, p.spec);
case Open_Brace:
case .Open_Brace:
return validate_object(p);
case Open_Bracket:
case .Open_Bracket:
return validate_array(p);
case:
if p.spec == Specification.JSON5 {
switch token.kind {
case Infinity, NaN:
#partial switch token.kind {
case .Infinity, .NaN:
advance_token(p);
return true;
}
+141
View File
@@ -0,0 +1,141 @@
/*
package fmt implemented formatted I/O with procedures similar to C's printf and Python's format.
The format 'verbs' are derived from C's but simpler.
Printing
The verbs:
General:
%v the value in a default format
%#v an expanded format of %v with newlines and indentation
%T an Odin-syntax representation of the type of the value
%% a literal percent sign; consumes no value
{{ a literal open brace; consumes no value
}} a literal close brace; consumes no value
{:v} equivalent to %v (Python-like formatting syntax)
Boolean:
%t the word "true" or "false"
Integer:
%b base 2
%c the character represented by the corresponding Unicode code point
%r synonym for %c
%o base 8
%d base 10
%i base 10
%z base 12
%x base 16, with lower-case letters for a-f
%X base 16, with upper-case letters for A-F
%U Unicode format: U+1234; same as "U+%04X"
Floating-point, complex numbers, and quaternions:
%e scientific notation, e.g. -1.23456e+78
%E scientific notation, e.g. -1.23456E+78
%f decimal point but no exponent, e.g. 123.456
%F synonym for %f
%h hexadecimal (lower-case) representation with 0h prefix (0h01234abcd)
%H hexadecimal (upper-case) representation with 0H prefix (0h01234ABCD)
String and slice of bytes
%s the uninterpreted bytes of the string or slice
%q a double-quoted string safely escaped with Odin syntax
%x base 16, lower-case, two characters per byte
%X base 16, upper-case, two characters per byte
Slice and dynamic array:
%p address of the 0th element in base 16 notation (upper-case), with leading 0x
Pointer:
%p base 16 notation (upper-case), with leading 0x
The %b, %d, %o, %z, %x, %X verbs also work with pointers,
treating it as if it was an integer
Enums:
%s prints the name of the enum field
The %i, %d, %f verbs also work with enums,
treating it as if it was a number
For compound values, the elements are printed using these rules recursively; laid out like the following:
struct: {name0 = field0, name1 = field1, ...}
array [elem0, elem1, elem2, ...]
enumerated array [key0 = elem0, key1 = elem1, key2 = elem2, ...]
maps: map[key0 = value0, key1 = value1, ...]
bit sets {key0 = elem0, key1 = elem1, ...}
pointer to above: &{}, &[], &map[]
Width is specified by an optional decimal number immediately preceding the verb.
If not present, the width is whatever is necessary to represent the value.
Precision is specified after the (optional) width followed by a period followed by a decimal number.
If no period is present, a default precision is used.
A period with no following number specifies a precision of 0.
Examples:
%f default width, default precision
%8f width 8, default precision
%.3f default width, precision 2
%8.3f width 8, precision 3
%8.f width 8, precision 0
Width and precision are measured in units of Unicode code points (runes).
n.b. C's printf uses units of bytes
Other flags:
+ always print a sign for numeric values
- pad with spaces on the right rather the left (left-justify the field)
# alternate format:
add leading 0b for binary (%#b)
add leading 0o for octal (%#o)
add leading 0z for dozenal (%#z)
add leading 0x or 0X for hexadecimal (%#x or %#X)
remove leading 0x for %p (%#p)
' ' (space) leave a space for elided sign in numbers (% d)
0 pad with leading zeros rather than spaces
Flags are ignored by verbs that don't expect them
For each printf-like procedure, there is a print function that takes no
format, and is equivalent to doing %v for every value and inserts a separator
between each value (default is a single space).
Another procedure println which has the same functionality as print but appends a newline.
Explicit argument indices:
In printf-like procedures, the default behaviour is for each formatting verb to format successive
arguments passed in the call. However, the notation [n] immediately before the verb indicates that
the nth zero-index argument is to be formatted instead.
The same notation before an '*' for a width or precision selecting the argument index holding the value.
Python-like syntax with argument indices differs for the selecting the argument index: {N:v}
Examples:
fmt.printf("%[1]d %[0]d\n", 13, 37); // C-like syntax
fmt.printf("{1:d} {0:d}\n", 13, 37); // Python-like syntax
prints "37 13", whilst:
fmt.printf("%[2]*.[1]*[0]f\n", 17.0, 2, 6); // C-like syntax
fmt.printf("%{0:[2]*.[1]*f}\n", 17.0, 2, 6); // Python-like syntax
equivalent to:
fmt.printf("%6.2f\n", 17.0, 2, 6); // C-like syntax
fmt.printf("{:6.2f}\n", 17.0, 2, 6); // Python-like syntax
prints "17.00"
Format errors:
If an invalid argument is given for a verb, such as providing a string to %d, the generated string
will contain a description of the problem. For example:
Bad enum value:
%!(BAD ENUM VALUE)
Too many arguments:
%!(EXTRA <value>, <value>, ...)
Too few arguments:
%!(MISSING ARGUMENT)
Invalid width or precision
%!(BAD WIDTH)
%!(BAD PRECISION)
Missing verb:
%!(NO VERB)
Invalid or invalid use of argument index:
%!(BAD ARGUMENT NUMBER)
Missing close brace when using Python-like formatting syntax:
%!(MISSING CLOSE BRACE)
*/
package fmt
+1066 -557
View File
File diff suppressed because it is too large Load Diff
+78
View File
@@ -0,0 +1,78 @@
package hash
@(optimization_mode="speed")
crc64 :: proc(data: []byte, seed := u32(0)) -> u64 #no_bounds_check {
result := ~u64(seed);
#no_bounds_check for b in data {
result = result>>8 ~ _crc64_table[(result ~ u64(b)) & 0xff];
}
return ~result;
}
@private _crc64_table := [256]u64{
0x0000000000000000, 0x42f0e1eba9ea3693, 0x85e1c3d753d46d26, 0xc711223cfa3e5bb5,
0x493366450e42ecdf, 0x0bc387aea7a8da4c, 0xccd2a5925d9681f9, 0x8e224479f47cb76a,
0x9266cc8a1c85d9be, 0xd0962d61b56fef2d, 0x17870f5d4f51b498, 0x5577eeb6e6bb820b,
0xdb55aacf12c73561, 0x99a54b24bb2d03f2, 0x5eb4691841135847, 0x1c4488f3e8f96ed4,
0x663d78ff90e185ef, 0x24cd9914390bb37c, 0xe3dcbb28c335e8c9, 0xa12c5ac36adfde5a,
0x2f0e1eba9ea36930, 0x6dfeff5137495fa3, 0xaaefdd6dcd770416, 0xe81f3c86649d3285,
0xf45bb4758c645c51, 0xb6ab559e258e6ac2, 0x71ba77a2dfb03177, 0x334a9649765a07e4,
0xbd68d2308226b08e, 0xff9833db2bcc861d, 0x388911e7d1f2dda8, 0x7a79f00c7818eb3b,
0xcc7af1ff21c30bde, 0x8e8a101488293d4d, 0x499b3228721766f8, 0x0b6bd3c3dbfd506b,
0x854997ba2f81e701, 0xc7b97651866bd192, 0x00a8546d7c558a27, 0x4258b586d5bfbcb4,
0x5e1c3d753d46d260, 0x1cecdc9e94ace4f3, 0xdbfdfea26e92bf46, 0x990d1f49c77889d5,
0x172f5b3033043ebf, 0x55dfbadb9aee082c, 0x92ce98e760d05399, 0xd03e790cc93a650a,
0xaa478900b1228e31, 0xe8b768eb18c8b8a2, 0x2fa64ad7e2f6e317, 0x6d56ab3c4b1cd584,
0xe374ef45bf6062ee, 0xa1840eae168a547d, 0x66952c92ecb40fc8, 0x2465cd79455e395b,
0x3821458aada7578f, 0x7ad1a461044d611c, 0xbdc0865dfe733aa9, 0xff3067b657990c3a,
0x711223cfa3e5bb50, 0x33e2c2240a0f8dc3, 0xf4f3e018f031d676, 0xb60301f359dbe0e5,
0xda050215ea6c212f, 0x98f5e3fe438617bc, 0x5fe4c1c2b9b84c09, 0x1d14202910527a9a,
0x93366450e42ecdf0, 0xd1c685bb4dc4fb63, 0x16d7a787b7faa0d6, 0x5427466c1e109645,
0x4863ce9ff6e9f891, 0x0a932f745f03ce02, 0xcd820d48a53d95b7, 0x8f72eca30cd7a324,
0x0150a8daf8ab144e, 0x43a04931514122dd, 0x84b16b0dab7f7968, 0xc6418ae602954ffb,
0xbc387aea7a8da4c0, 0xfec89b01d3679253, 0x39d9b93d2959c9e6, 0x7b2958d680b3ff75,
0xf50b1caf74cf481f, 0xb7fbfd44dd257e8c, 0x70eadf78271b2539, 0x321a3e938ef113aa,
0x2e5eb66066087d7e, 0x6cae578bcfe24bed, 0xabbf75b735dc1058, 0xe94f945c9c3626cb,
0x676dd025684a91a1, 0x259d31cec1a0a732, 0xe28c13f23b9efc87, 0xa07cf2199274ca14,
0x167ff3eacbaf2af1, 0x548f120162451c62, 0x939e303d987b47d7, 0xd16ed1d631917144,
0x5f4c95afc5edc62e, 0x1dbc74446c07f0bd, 0xdaad56789639ab08, 0x985db7933fd39d9b,
0x84193f60d72af34f, 0xc6e9de8b7ec0c5dc, 0x01f8fcb784fe9e69, 0x43081d5c2d14a8fa,
0xcd2a5925d9681f90, 0x8fdab8ce70822903, 0x48cb9af28abc72b6, 0x0a3b7b1923564425,
0x70428b155b4eaf1e, 0x32b26afef2a4998d, 0xf5a348c2089ac238, 0xb753a929a170f4ab,
0x3971ed50550c43c1, 0x7b810cbbfce67552, 0xbc902e8706d82ee7, 0xfe60cf6caf321874,
0xe224479f47cb76a0, 0xa0d4a674ee214033, 0x67c58448141f1b86, 0x253565a3bdf52d15,
0xab1721da49899a7f, 0xe9e7c031e063acec, 0x2ef6e20d1a5df759, 0x6c0603e6b3b7c1ca,
0xf6fae5c07d3274cd, 0xb40a042bd4d8425e, 0x731b26172ee619eb, 0x31ebc7fc870c2f78,
0xbfc9838573709812, 0xfd39626eda9aae81, 0x3a28405220a4f534, 0x78d8a1b9894ec3a7,
0x649c294a61b7ad73, 0x266cc8a1c85d9be0, 0xe17dea9d3263c055, 0xa38d0b769b89f6c6,
0x2daf4f0f6ff541ac, 0x6f5faee4c61f773f, 0xa84e8cd83c212c8a, 0xeabe6d3395cb1a19,
0x90c79d3fedd3f122, 0xd2377cd44439c7b1, 0x15265ee8be079c04, 0x57d6bf0317edaa97,
0xd9f4fb7ae3911dfd, 0x9b041a914a7b2b6e, 0x5c1538adb04570db, 0x1ee5d94619af4648,
0x02a151b5f156289c, 0x4051b05e58bc1e0f, 0x87409262a28245ba, 0xc5b073890b687329,
0x4b9237f0ff14c443, 0x0962d61b56fef2d0, 0xce73f427acc0a965, 0x8c8315cc052a9ff6,
0x3a80143f5cf17f13, 0x7870f5d4f51b4980, 0xbf61d7e80f251235, 0xfd913603a6cf24a6,
0x73b3727a52b393cc, 0x31439391fb59a55f, 0xf652b1ad0167feea, 0xb4a25046a88dc879,
0xa8e6d8b54074a6ad, 0xea16395ee99e903e, 0x2d071b6213a0cb8b, 0x6ff7fa89ba4afd18,
0xe1d5bef04e364a72, 0xa3255f1be7dc7ce1, 0x64347d271de22754, 0x26c49cccb40811c7,
0x5cbd6cc0cc10fafc, 0x1e4d8d2b65facc6f, 0xd95caf179fc497da, 0x9bac4efc362ea149,
0x158e0a85c2521623, 0x577eeb6e6bb820b0, 0x906fc95291867b05, 0xd29f28b9386c4d96,
0xcedba04ad0952342, 0x8c2b41a1797f15d1, 0x4b3a639d83414e64, 0x09ca82762aab78f7,
0x87e8c60fded7cf9d, 0xc51827e4773df90e, 0x020905d88d03a2bb, 0x40f9e43324e99428,
0x2cffe7d5975e55e2, 0x6e0f063e3eb46371, 0xa91e2402c48a38c4, 0xebeec5e96d600e57,
0x65cc8190991cb93d, 0x273c607b30f68fae, 0xe02d4247cac8d41b, 0xa2dda3ac6322e288,
0xbe992b5f8bdb8c5c, 0xfc69cab42231bacf, 0x3b78e888d80fe17a, 0x7988096371e5d7e9,
0xf7aa4d1a85996083, 0xb55aacf12c735610, 0x724b8ecdd64d0da5, 0x30bb6f267fa73b36,
0x4ac29f2a07bfd00d, 0x08327ec1ae55e69e, 0xcf235cfd546bbd2b, 0x8dd3bd16fd818bb8,
0x03f1f96f09fd3cd2, 0x41011884a0170a41, 0x86103ab85a2951f4, 0xc4e0db53f3c36767,
0xd8a453a01b3a09b3, 0x9a54b24bb2d03f20, 0x5d45907748ee6495, 0x1fb5719ce1045206,
0x919735e51578e56c, 0xd367d40ebc92d3ff, 0x1476f63246ac884a, 0x568617d9ef46bed9,
0xe085162ab69d5e3c, 0xa275f7c11f7768af, 0x6564d5fde549331a, 0x279434164ca30589,
0xa9b6706fb8dfb2e3, 0xeb46918411358470, 0x2c57b3b8eb0bdfc5, 0x6ea7525342e1e956,
0x72e3daa0aa188782, 0x30133b4b03f2b111, 0xf7021977f9cceaa4, 0xb5f2f89c5026dc37,
0x3bd0bce5a45a6b5d, 0x79205d0e0db05dce, 0xbe317f32f78e067b, 0xfcc19ed95e6430e8,
0x86b86ed5267cdbd3, 0xc4488f3e8f96ed40, 0x0359ad0275a8b6f5, 0x41a94ce9dc428066,
0xcf8b0890283e370c, 0x8d7be97b81d4019f, 0x4a6acb477bea5a2a, 0x089a2aacd2006cb9,
0x14dea25f3af9026d, 0x562e43b4931334fe, 0x913f6188692d6f4b, 0xd3cf8063c0c759d8,
0x5dedc41a34bbeeb2, 0x1f1d25f19d51d821, 0xd80c07cd676f8394, 0x9afce626ce85b507,
};
+401
View File
@@ -0,0 +1,401 @@
package hash
import "core:intrinsics"
@(optimization_mode="speed")
crc32 :: proc(data: []byte, seed := u32(0)) -> u32 #no_bounds_check {
crc := ~seed;
buffer := raw_data(data);
length := len(data);
for length != 0 && uintptr(buffer) & 7 != 0 {
crc = crc32_table[0][byte(crc) ~ buffer^] ~ (crc >> 8);
buffer = intrinsics.ptr_offset(buffer, 1);
length -= 1;
}
for length >= 8 {
buf := (^[8]byte)(buffer);
word := u32((^u32le)(buffer)^);
crc ~= word;
crc = crc32_table[7][crc & 0xff] ~
crc32_table[6][(crc >> 8) & 0xff] ~
crc32_table[5][(crc >> 16) & 0xff] ~
crc32_table[4][(crc >> 24) & 0xff] ~
crc32_table[3][buf[4]] ~
crc32_table[2][buf[5]] ~
crc32_table[1][buf[6]] ~
crc32_table[0][buf[7]];
buffer = intrinsics.ptr_offset(buffer, 8);
length -= 8;
}
for length != 0 {
crc = crc32_table[0][byte(crc) ~ buffer^] ~ (crc >> 8);
buffer = intrinsics.ptr_offset(buffer, 1);
length -= 1;
}
return ~crc;
}
@(private)
crc32_table := [8][256]u32{
{
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,
0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5,
0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f,
0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d,
0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457,
0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb,
0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9,
0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad,
0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683,
0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7,
0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79,
0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f,
0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21,
0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45,
0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db,
0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,
0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d,
},
{
0x00000000, 0x191b3141, 0x32366282, 0x2b2d53c3, 0x646cc504, 0x7d77f445, 0x565aa786, 0x4f4196c7,
0xc8d98a08, 0xd1c2bb49, 0xfaefe88a, 0xe3f4d9cb, 0xacb54f0c, 0xb5ae7e4d, 0x9e832d8e, 0x87981ccf,
0x4ac21251, 0x53d92310, 0x78f470d3, 0x61ef4192, 0x2eaed755, 0x37b5e614, 0x1c98b5d7, 0x05838496,
0x821b9859, 0x9b00a918, 0xb02dfadb, 0xa936cb9a, 0xe6775d5d, 0xff6c6c1c, 0xd4413fdf, 0xcd5a0e9e,
0x958424a2, 0x8c9f15e3, 0xa7b24620, 0xbea97761, 0xf1e8e1a6, 0xe8f3d0e7, 0xc3de8324, 0xdac5b265,
0x5d5daeaa, 0x44469feb, 0x6f6bcc28, 0x7670fd69, 0x39316bae, 0x202a5aef, 0x0b07092c, 0x121c386d,
0xdf4636f3, 0xc65d07b2, 0xed705471, 0xf46b6530, 0xbb2af3f7, 0xa231c2b6, 0x891c9175, 0x9007a034,
0x179fbcfb, 0x0e848dba, 0x25a9de79, 0x3cb2ef38, 0x73f379ff, 0x6ae848be, 0x41c51b7d, 0x58de2a3c,
0xf0794f05, 0xe9627e44, 0xc24f2d87, 0xdb541cc6, 0x94158a01, 0x8d0ebb40, 0xa623e883, 0xbf38d9c2,
0x38a0c50d, 0x21bbf44c, 0x0a96a78f, 0x138d96ce, 0x5ccc0009, 0x45d73148, 0x6efa628b, 0x77e153ca,
0xbabb5d54, 0xa3a06c15, 0x888d3fd6, 0x91960e97, 0xded79850, 0xc7cca911, 0xece1fad2, 0xf5facb93,
0x7262d75c, 0x6b79e61d, 0x4054b5de, 0x594f849f, 0x160e1258, 0x0f152319, 0x243870da, 0x3d23419b,
0x65fd6ba7, 0x7ce65ae6, 0x57cb0925, 0x4ed03864, 0x0191aea3, 0x188a9fe2, 0x33a7cc21, 0x2abcfd60,
0xad24e1af, 0xb43fd0ee, 0x9f12832d, 0x8609b26c, 0xc94824ab, 0xd05315ea, 0xfb7e4629, 0xe2657768,
0x2f3f79f6, 0x362448b7, 0x1d091b74, 0x04122a35, 0x4b53bcf2, 0x52488db3, 0x7965de70, 0x607eef31,
0xe7e6f3fe, 0xfefdc2bf, 0xd5d0917c, 0xcccba03d, 0x838a36fa, 0x9a9107bb, 0xb1bc5478, 0xa8a76539,
0x3b83984b, 0x2298a90a, 0x09b5fac9, 0x10aecb88, 0x5fef5d4f, 0x46f46c0e, 0x6dd93fcd, 0x74c20e8c,
0xf35a1243, 0xea412302, 0xc16c70c1, 0xd8774180, 0x9736d747, 0x8e2de606, 0xa500b5c5, 0xbc1b8484,
0x71418a1a, 0x685abb5b, 0x4377e898, 0x5a6cd9d9, 0x152d4f1e, 0x0c367e5f, 0x271b2d9c, 0x3e001cdd,
0xb9980012, 0xa0833153, 0x8bae6290, 0x92b553d1, 0xddf4c516, 0xc4eff457, 0xefc2a794, 0xf6d996d5,
0xae07bce9, 0xb71c8da8, 0x9c31de6b, 0x852aef2a, 0xca6b79ed, 0xd37048ac, 0xf85d1b6f, 0xe1462a2e,
0x66de36e1, 0x7fc507a0, 0x54e85463, 0x4df36522, 0x02b2f3e5, 0x1ba9c2a4, 0x30849167, 0x299fa026,
0xe4c5aeb8, 0xfdde9ff9, 0xd6f3cc3a, 0xcfe8fd7b, 0x80a96bbc, 0x99b25afd, 0xb29f093e, 0xab84387f,
0x2c1c24b0, 0x350715f1, 0x1e2a4632, 0x07317773, 0x4870e1b4, 0x516bd0f5, 0x7a468336, 0x635db277,
0xcbfad74e, 0xd2e1e60f, 0xf9ccb5cc, 0xe0d7848d, 0xaf96124a, 0xb68d230b, 0x9da070c8, 0x84bb4189,
0x03235d46, 0x1a386c07, 0x31153fc4, 0x280e0e85, 0x674f9842, 0x7e54a903, 0x5579fac0, 0x4c62cb81,
0x8138c51f, 0x9823f45e, 0xb30ea79d, 0xaa1596dc, 0xe554001b, 0xfc4f315a, 0xd7626299, 0xce7953d8,
0x49e14f17, 0x50fa7e56, 0x7bd72d95, 0x62cc1cd4, 0x2d8d8a13, 0x3496bb52, 0x1fbbe891, 0x06a0d9d0,
0x5e7ef3ec, 0x4765c2ad, 0x6c48916e, 0x7553a02f, 0x3a1236e8, 0x230907a9, 0x0824546a, 0x113f652b,
0x96a779e4, 0x8fbc48a5, 0xa4911b66, 0xbd8a2a27, 0xf2cbbce0, 0xebd08da1, 0xc0fdde62, 0xd9e6ef23,
0x14bce1bd, 0x0da7d0fc, 0x268a833f, 0x3f91b27e, 0x70d024b9, 0x69cb15f8, 0x42e6463b, 0x5bfd777a,
0xdc656bb5, 0xc57e5af4, 0xee530937, 0xf7483876, 0xb809aeb1, 0xa1129ff0, 0x8a3fcc33, 0x9324fd72,
},
{
0x00000000, 0x01c26a37, 0x0384d46e, 0x0246be59, 0x0709a8dc, 0x06cbc2eb, 0x048d7cb2, 0x054f1685,
0x0e1351b8, 0x0fd13b8f, 0x0d9785d6, 0x0c55efe1, 0x091af964, 0x08d89353, 0x0a9e2d0a, 0x0b5c473d,
0x1c26a370, 0x1de4c947, 0x1fa2771e, 0x1e601d29, 0x1b2f0bac, 0x1aed619b, 0x18abdfc2, 0x1969b5f5,
0x1235f2c8, 0x13f798ff, 0x11b126a6, 0x10734c91, 0x153c5a14, 0x14fe3023, 0x16b88e7a, 0x177ae44d,
0x384d46e0, 0x398f2cd7, 0x3bc9928e, 0x3a0bf8b9, 0x3f44ee3c, 0x3e86840b, 0x3cc03a52, 0x3d025065,
0x365e1758, 0x379c7d6f, 0x35dac336, 0x3418a901, 0x3157bf84, 0x3095d5b3, 0x32d36bea, 0x331101dd,
0x246be590, 0x25a98fa7, 0x27ef31fe, 0x262d5bc9, 0x23624d4c, 0x22a0277b, 0x20e69922, 0x2124f315,
0x2a78b428, 0x2bbade1f, 0x29fc6046, 0x283e0a71, 0x2d711cf4, 0x2cb376c3, 0x2ef5c89a, 0x2f37a2ad,
0x709a8dc0, 0x7158e7f7, 0x731e59ae, 0x72dc3399, 0x7793251c, 0x76514f2b, 0x7417f172, 0x75d59b45,
0x7e89dc78, 0x7f4bb64f, 0x7d0d0816, 0x7ccf6221, 0x798074a4, 0x78421e93, 0x7a04a0ca, 0x7bc6cafd,
0x6cbc2eb0, 0x6d7e4487, 0x6f38fade, 0x6efa90e9, 0x6bb5866c, 0x6a77ec5b, 0x68315202, 0x69f33835,
0x62af7f08, 0x636d153f, 0x612bab66, 0x60e9c151, 0x65a6d7d4, 0x6464bde3, 0x662203ba, 0x67e0698d,
0x48d7cb20, 0x4915a117, 0x4b531f4e, 0x4a917579, 0x4fde63fc, 0x4e1c09cb, 0x4c5ab792, 0x4d98dda5,
0x46c49a98, 0x4706f0af, 0x45404ef6, 0x448224c1, 0x41cd3244, 0x400f5873, 0x4249e62a, 0x438b8c1d,
0x54f16850, 0x55330267, 0x5775bc3e, 0x56b7d609, 0x53f8c08c, 0x523aaabb, 0x507c14e2, 0x51be7ed5,
0x5ae239e8, 0x5b2053df, 0x5966ed86, 0x58a487b1, 0x5deb9134, 0x5c29fb03, 0x5e6f455a, 0x5fad2f6d,
0xe1351b80, 0xe0f771b7, 0xe2b1cfee, 0xe373a5d9, 0xe63cb35c, 0xe7fed96b, 0xe5b86732, 0xe47a0d05,
0xef264a38, 0xeee4200f, 0xeca29e56, 0xed60f461, 0xe82fe2e4, 0xe9ed88d3, 0xebab368a, 0xea695cbd,
0xfd13b8f0, 0xfcd1d2c7, 0xfe976c9e, 0xff5506a9, 0xfa1a102c, 0xfbd87a1b, 0xf99ec442, 0xf85cae75,
0xf300e948, 0xf2c2837f, 0xf0843d26, 0xf1465711, 0xf4094194, 0xf5cb2ba3, 0xf78d95fa, 0xf64fffcd,
0xd9785d60, 0xd8ba3757, 0xdafc890e, 0xdb3ee339, 0xde71f5bc, 0xdfb39f8b, 0xddf521d2, 0xdc374be5,
0xd76b0cd8, 0xd6a966ef, 0xd4efd8b6, 0xd52db281, 0xd062a404, 0xd1a0ce33, 0xd3e6706a, 0xd2241a5d,
0xc55efe10, 0xc49c9427, 0xc6da2a7e, 0xc7184049, 0xc25756cc, 0xc3953cfb, 0xc1d382a2, 0xc011e895,
0xcb4dafa8, 0xca8fc59f, 0xc8c97bc6, 0xc90b11f1, 0xcc440774, 0xcd866d43, 0xcfc0d31a, 0xce02b92d,
0x91af9640, 0x906dfc77, 0x922b422e, 0x93e92819, 0x96a63e9c, 0x976454ab, 0x9522eaf2, 0x94e080c5,
0x9fbcc7f8, 0x9e7eadcf, 0x9c381396, 0x9dfa79a1, 0x98b56f24, 0x99770513, 0x9b31bb4a, 0x9af3d17d,
0x8d893530, 0x8c4b5f07, 0x8e0de15e, 0x8fcf8b69, 0x8a809dec, 0x8b42f7db, 0x89044982, 0x88c623b5,
0x839a6488, 0x82580ebf, 0x801eb0e6, 0x81dcdad1, 0x8493cc54, 0x8551a663, 0x8717183a, 0x86d5720d,
0xa9e2d0a0, 0xa820ba97, 0xaa6604ce, 0xaba46ef9, 0xaeeb787c, 0xaf29124b, 0xad6fac12, 0xacadc625,
0xa7f18118, 0xa633eb2f, 0xa4755576, 0xa5b73f41, 0xa0f829c4, 0xa13a43f3, 0xa37cfdaa, 0xa2be979d,
0xb5c473d0, 0xb40619e7, 0xb640a7be, 0xb782cd89, 0xb2cddb0c, 0xb30fb13b, 0xb1490f62, 0xb08b6555,
0xbbd72268, 0xba15485f, 0xb853f606, 0xb9919c31, 0xbcde8ab4, 0xbd1ce083, 0xbf5a5eda, 0xbe9834ed,
},
{
0x00000000, 0xb8bc6765, 0xaa09c88b, 0x12b5afee, 0x8f629757, 0x37def032, 0x256b5fdc, 0x9dd738b9,
0xc5b428ef, 0x7d084f8a, 0x6fbde064, 0xd7018701, 0x4ad6bfb8, 0xf26ad8dd, 0xe0df7733, 0x58631056,
0x5019579f, 0xe8a530fa, 0xfa109f14, 0x42acf871, 0xdf7bc0c8, 0x67c7a7ad, 0x75720843, 0xcdce6f26,
0x95ad7f70, 0x2d111815, 0x3fa4b7fb, 0x8718d09e, 0x1acfe827, 0xa2738f42, 0xb0c620ac, 0x087a47c9,
0xa032af3e, 0x188ec85b, 0x0a3b67b5, 0xb28700d0, 0x2f503869, 0x97ec5f0c, 0x8559f0e2, 0x3de59787,
0x658687d1, 0xdd3ae0b4, 0xcf8f4f5a, 0x7733283f, 0xeae41086, 0x525877e3, 0x40edd80d, 0xf851bf68,
0xf02bf8a1, 0x48979fc4, 0x5a22302a, 0xe29e574f, 0x7f496ff6, 0xc7f50893, 0xd540a77d, 0x6dfcc018,
0x359fd04e, 0x8d23b72b, 0x9f9618c5, 0x272a7fa0, 0xbafd4719, 0x0241207c, 0x10f48f92, 0xa848e8f7,
0x9b14583d, 0x23a83f58, 0x311d90b6, 0x89a1f7d3, 0x1476cf6a, 0xaccaa80f, 0xbe7f07e1, 0x06c36084,
0x5ea070d2, 0xe61c17b7, 0xf4a9b859, 0x4c15df3c, 0xd1c2e785, 0x697e80e0, 0x7bcb2f0e, 0xc377486b,
0xcb0d0fa2, 0x73b168c7, 0x6104c729, 0xd9b8a04c, 0x446f98f5, 0xfcd3ff90, 0xee66507e, 0x56da371b,
0x0eb9274d, 0xb6054028, 0xa4b0efc6, 0x1c0c88a3, 0x81dbb01a, 0x3967d77f, 0x2bd27891, 0x936e1ff4,
0x3b26f703, 0x839a9066, 0x912f3f88, 0x299358ed, 0xb4446054, 0x0cf80731, 0x1e4da8df, 0xa6f1cfba,
0xfe92dfec, 0x462eb889, 0x549b1767, 0xec277002, 0x71f048bb, 0xc94c2fde, 0xdbf98030, 0x6345e755,
0x6b3fa09c, 0xd383c7f9, 0xc1366817, 0x798a0f72, 0xe45d37cb, 0x5ce150ae, 0x4e54ff40, 0xf6e89825,
0xae8b8873, 0x1637ef16, 0x048240f8, 0xbc3e279d, 0x21e91f24, 0x99557841, 0x8be0d7af, 0x335cb0ca,
0xed59b63b, 0x55e5d15e, 0x47507eb0, 0xffec19d5, 0x623b216c, 0xda874609, 0xc832e9e7, 0x708e8e82,
0x28ed9ed4, 0x9051f9b1, 0x82e4565f, 0x3a58313a, 0xa78f0983, 0x1f336ee6, 0x0d86c108, 0xb53aa66d,
0xbd40e1a4, 0x05fc86c1, 0x1749292f, 0xaff54e4a, 0x322276f3, 0x8a9e1196, 0x982bbe78, 0x2097d91d,
0x78f4c94b, 0xc048ae2e, 0xd2fd01c0, 0x6a4166a5, 0xf7965e1c, 0x4f2a3979, 0x5d9f9697, 0xe523f1f2,
0x4d6b1905, 0xf5d77e60, 0xe762d18e, 0x5fdeb6eb, 0xc2098e52, 0x7ab5e937, 0x680046d9, 0xd0bc21bc,
0x88df31ea, 0x3063568f, 0x22d6f961, 0x9a6a9e04, 0x07bda6bd, 0xbf01c1d8, 0xadb46e36, 0x15080953,
0x1d724e9a, 0xa5ce29ff, 0xb77b8611, 0x0fc7e174, 0x9210d9cd, 0x2aacbea8, 0x38191146, 0x80a57623,
0xd8c66675, 0x607a0110, 0x72cfaefe, 0xca73c99b, 0x57a4f122, 0xef189647, 0xfdad39a9, 0x45115ecc,
0x764dee06, 0xcef18963, 0xdc44268d, 0x64f841e8, 0xf92f7951, 0x41931e34, 0x5326b1da, 0xeb9ad6bf,
0xb3f9c6e9, 0x0b45a18c, 0x19f00e62, 0xa14c6907, 0x3c9b51be, 0x842736db, 0x96929935, 0x2e2efe50,
0x2654b999, 0x9ee8defc, 0x8c5d7112, 0x34e11677, 0xa9362ece, 0x118a49ab, 0x033fe645, 0xbb838120,
0xe3e09176, 0x5b5cf613, 0x49e959fd, 0xf1553e98, 0x6c820621, 0xd43e6144, 0xc68bceaa, 0x7e37a9cf,
0xd67f4138, 0x6ec3265d, 0x7c7689b3, 0xc4caeed6, 0x591dd66f, 0xe1a1b10a, 0xf3141ee4, 0x4ba87981,
0x13cb69d7, 0xab770eb2, 0xb9c2a15c, 0x017ec639, 0x9ca9fe80, 0x241599e5, 0x36a0360b, 0x8e1c516e,
0x866616a7, 0x3eda71c2, 0x2c6fde2c, 0x94d3b949, 0x090481f0, 0xb1b8e695, 0xa30d497b, 0x1bb12e1e,
0x43d23e48, 0xfb6e592d, 0xe9dbf6c3, 0x516791a6, 0xccb0a91f, 0x740cce7a, 0x66b96194, 0xde0506f1,
},
{
0x00000000, 0x3d6029b0, 0x7ac05360, 0x47a07ad0, 0xf580a6c0, 0xc8e08f70, 0x8f40f5a0, 0xb220dc10,
0x30704bc1, 0x0d106271, 0x4ab018a1, 0x77d03111, 0xc5f0ed01, 0xf890c4b1, 0xbf30be61, 0x825097d1,
0x60e09782, 0x5d80be32, 0x1a20c4e2, 0x2740ed52, 0x95603142, 0xa80018f2, 0xefa06222, 0xd2c04b92,
0x5090dc43, 0x6df0f5f3, 0x2a508f23, 0x1730a693, 0xa5107a83, 0x98705333, 0xdfd029e3, 0xe2b00053,
0xc1c12f04, 0xfca106b4, 0xbb017c64, 0x866155d4, 0x344189c4, 0x0921a074, 0x4e81daa4, 0x73e1f314,
0xf1b164c5, 0xccd14d75, 0x8b7137a5, 0xb6111e15, 0x0431c205, 0x3951ebb5, 0x7ef19165, 0x4391b8d5,
0xa121b886, 0x9c419136, 0xdbe1ebe6, 0xe681c256, 0x54a11e46, 0x69c137f6, 0x2e614d26, 0x13016496,
0x9151f347, 0xac31daf7, 0xeb91a027, 0xd6f18997, 0x64d15587, 0x59b17c37, 0x1e1106e7, 0x23712f57,
0x58f35849, 0x659371f9, 0x22330b29, 0x1f532299, 0xad73fe89, 0x9013d739, 0xd7b3ade9, 0xead38459,
0x68831388, 0x55e33a38, 0x124340e8, 0x2f236958, 0x9d03b548, 0xa0639cf8, 0xe7c3e628, 0xdaa3cf98,
0x3813cfcb, 0x0573e67b, 0x42d39cab, 0x7fb3b51b, 0xcd93690b, 0xf0f340bb, 0xb7533a6b, 0x8a3313db,
0x0863840a, 0x3503adba, 0x72a3d76a, 0x4fc3feda, 0xfde322ca, 0xc0830b7a, 0x872371aa, 0xba43581a,
0x9932774d, 0xa4525efd, 0xe3f2242d, 0xde920d9d, 0x6cb2d18d, 0x51d2f83d, 0x167282ed, 0x2b12ab5d,
0xa9423c8c, 0x9422153c, 0xd3826fec, 0xeee2465c, 0x5cc29a4c, 0x61a2b3fc, 0x2602c92c, 0x1b62e09c,
0xf9d2e0cf, 0xc4b2c97f, 0x8312b3af, 0xbe729a1f, 0x0c52460f, 0x31326fbf, 0x7692156f, 0x4bf23cdf,
0xc9a2ab0e, 0xf4c282be, 0xb362f86e, 0x8e02d1de, 0x3c220dce, 0x0142247e, 0x46e25eae, 0x7b82771e,
0xb1e6b092, 0x8c869922, 0xcb26e3f2, 0xf646ca42, 0x44661652, 0x79063fe2, 0x3ea64532, 0x03c66c82,
0x8196fb53, 0xbcf6d2e3, 0xfb56a833, 0xc6368183, 0x74165d93, 0x49767423, 0x0ed60ef3, 0x33b62743,
0xd1062710, 0xec660ea0, 0xabc67470, 0x96a65dc0, 0x248681d0, 0x19e6a860, 0x5e46d2b0, 0x6326fb00,
0xe1766cd1, 0xdc164561, 0x9bb63fb1, 0xa6d61601, 0x14f6ca11, 0x2996e3a1, 0x6e369971, 0x5356b0c1,
0x70279f96, 0x4d47b626, 0x0ae7ccf6, 0x3787e546, 0x85a73956, 0xb8c710e6, 0xff676a36, 0xc2074386,
0x4057d457, 0x7d37fde7, 0x3a978737, 0x07f7ae87, 0xb5d77297, 0x88b75b27, 0xcf1721f7, 0xf2770847,
0x10c70814, 0x2da721a4, 0x6a075b74, 0x576772c4, 0xe547aed4, 0xd8278764, 0x9f87fdb4, 0xa2e7d404,
0x20b743d5, 0x1dd76a65, 0x5a7710b5, 0x67173905, 0xd537e515, 0xe857cca5, 0xaff7b675, 0x92979fc5,
0xe915e8db, 0xd475c16b, 0x93d5bbbb, 0xaeb5920b, 0x1c954e1b, 0x21f567ab, 0x66551d7b, 0x5b3534cb,
0xd965a31a, 0xe4058aaa, 0xa3a5f07a, 0x9ec5d9ca, 0x2ce505da, 0x11852c6a, 0x562556ba, 0x6b457f0a,
0x89f57f59, 0xb49556e9, 0xf3352c39, 0xce550589, 0x7c75d999, 0x4115f029, 0x06b58af9, 0x3bd5a349,
0xb9853498, 0x84e51d28, 0xc34567f8, 0xfe254e48, 0x4c059258, 0x7165bbe8, 0x36c5c138, 0x0ba5e888,
0x28d4c7df, 0x15b4ee6f, 0x521494bf, 0x6f74bd0f, 0xdd54611f, 0xe03448af, 0xa794327f, 0x9af41bcf,
0x18a48c1e, 0x25c4a5ae, 0x6264df7e, 0x5f04f6ce, 0xed242ade, 0xd044036e, 0x97e479be, 0xaa84500e,
0x4834505d, 0x755479ed, 0x32f4033d, 0x0f942a8d, 0xbdb4f69d, 0x80d4df2d, 0xc774a5fd, 0xfa148c4d,
0x78441b9c, 0x4524322c, 0x028448fc, 0x3fe4614c, 0x8dc4bd5c, 0xb0a494ec, 0xf704ee3c, 0xca64c78c,
},
{
0x00000000, 0xcb5cd3a5, 0x4dc8a10b, 0x869472ae, 0x9b914216, 0x50cd91b3, 0xd659e31d, 0x1d0530b8,
0xec53826d, 0x270f51c8, 0xa19b2366, 0x6ac7f0c3, 0x77c2c07b, 0xbc9e13de, 0x3a0a6170, 0xf156b2d5,
0x03d6029b, 0xc88ad13e, 0x4e1ea390, 0x85427035, 0x9847408d, 0x531b9328, 0xd58fe186, 0x1ed33223,
0xef8580f6, 0x24d95353, 0xa24d21fd, 0x6911f258, 0x7414c2e0, 0xbf481145, 0x39dc63eb, 0xf280b04e,
0x07ac0536, 0xccf0d693, 0x4a64a43d, 0x81387798, 0x9c3d4720, 0x57619485, 0xd1f5e62b, 0x1aa9358e,
0xebff875b, 0x20a354fe, 0xa6372650, 0x6d6bf5f5, 0x706ec54d, 0xbb3216e8, 0x3da66446, 0xf6fab7e3,
0x047a07ad, 0xcf26d408, 0x49b2a6a6, 0x82ee7503, 0x9feb45bb, 0x54b7961e, 0xd223e4b0, 0x197f3715,
0xe82985c0, 0x23755665, 0xa5e124cb, 0x6ebdf76e, 0x73b8c7d6, 0xb8e41473, 0x3e7066dd, 0xf52cb578,
0x0f580a6c, 0xc404d9c9, 0x4290ab67, 0x89cc78c2, 0x94c9487a, 0x5f959bdf, 0xd901e971, 0x125d3ad4,
0xe30b8801, 0x28575ba4, 0xaec3290a, 0x659ffaaf, 0x789aca17, 0xb3c619b2, 0x35526b1c, 0xfe0eb8b9,
0x0c8e08f7, 0xc7d2db52, 0x4146a9fc, 0x8a1a7a59, 0x971f4ae1, 0x5c439944, 0xdad7ebea, 0x118b384f,
0xe0dd8a9a, 0x2b81593f, 0xad152b91, 0x6649f834, 0x7b4cc88c, 0xb0101b29, 0x36846987, 0xfdd8ba22,
0x08f40f5a, 0xc3a8dcff, 0x453cae51, 0x8e607df4, 0x93654d4c, 0x58399ee9, 0xdeadec47, 0x15f13fe2,
0xe4a78d37, 0x2ffb5e92, 0xa96f2c3c, 0x6233ff99, 0x7f36cf21, 0xb46a1c84, 0x32fe6e2a, 0xf9a2bd8f,
0x0b220dc1, 0xc07ede64, 0x46eaacca, 0x8db67f6f, 0x90b34fd7, 0x5bef9c72, 0xdd7beedc, 0x16273d79,
0xe7718fac, 0x2c2d5c09, 0xaab92ea7, 0x61e5fd02, 0x7ce0cdba, 0xb7bc1e1f, 0x31286cb1, 0xfa74bf14,
0x1eb014d8, 0xd5ecc77d, 0x5378b5d3, 0x98246676, 0x852156ce, 0x4e7d856b, 0xc8e9f7c5, 0x03b52460,
0xf2e396b5, 0x39bf4510, 0xbf2b37be, 0x7477e41b, 0x6972d4a3, 0xa22e0706, 0x24ba75a8, 0xefe6a60d,
0x1d661643, 0xd63ac5e6, 0x50aeb748, 0x9bf264ed, 0x86f75455, 0x4dab87f0, 0xcb3ff55e, 0x006326fb,
0xf135942e, 0x3a69478b, 0xbcfd3525, 0x77a1e680, 0x6aa4d638, 0xa1f8059d, 0x276c7733, 0xec30a496,
0x191c11ee, 0xd240c24b, 0x54d4b0e5, 0x9f886340, 0x828d53f8, 0x49d1805d, 0xcf45f2f3, 0x04192156,
0xf54f9383, 0x3e134026, 0xb8873288, 0x73dbe12d, 0x6eded195, 0xa5820230, 0x2316709e, 0xe84aa33b,
0x1aca1375, 0xd196c0d0, 0x5702b27e, 0x9c5e61db, 0x815b5163, 0x4a0782c6, 0xcc93f068, 0x07cf23cd,
0xf6999118, 0x3dc542bd, 0xbb513013, 0x700de3b6, 0x6d08d30e, 0xa65400ab, 0x20c07205, 0xeb9ca1a0,
0x11e81eb4, 0xdab4cd11, 0x5c20bfbf, 0x977c6c1a, 0x8a795ca2, 0x41258f07, 0xc7b1fda9, 0x0ced2e0c,
0xfdbb9cd9, 0x36e74f7c, 0xb0733dd2, 0x7b2fee77, 0x662adecf, 0xad760d6a, 0x2be27fc4, 0xe0beac61,
0x123e1c2f, 0xd962cf8a, 0x5ff6bd24, 0x94aa6e81, 0x89af5e39, 0x42f38d9c, 0xc467ff32, 0x0f3b2c97,
0xfe6d9e42, 0x35314de7, 0xb3a53f49, 0x78f9ecec, 0x65fcdc54, 0xaea00ff1, 0x28347d5f, 0xe368aefa,
0x16441b82, 0xdd18c827, 0x5b8cba89, 0x90d0692c, 0x8dd55994, 0x46898a31, 0xc01df89f, 0x0b412b3a,
0xfa1799ef, 0x314b4a4a, 0xb7df38e4, 0x7c83eb41, 0x6186dbf9, 0xaada085c, 0x2c4e7af2, 0xe712a957,
0x15921919, 0xdececabc, 0x585ab812, 0x93066bb7, 0x8e035b0f, 0x455f88aa, 0xc3cbfa04, 0x089729a1,
0xf9c19b74, 0x329d48d1, 0xb4093a7f, 0x7f55e9da, 0x6250d962, 0xa90c0ac7, 0x2f987869, 0xe4c4abcc,
},
{
0x00000000, 0xa6770bb4, 0x979f1129, 0x31e81a9d, 0xf44f2413, 0x52382fa7, 0x63d0353a, 0xc5a73e8e,
0x33ef4e67, 0x959845d3, 0xa4705f4e, 0x020754fa, 0xc7a06a74, 0x61d761c0, 0x503f7b5d, 0xf64870e9,
0x67de9cce, 0xc1a9977a, 0xf0418de7, 0x56368653, 0x9391b8dd, 0x35e6b369, 0x040ea9f4, 0xa279a240,
0x5431d2a9, 0xf246d91d, 0xc3aec380, 0x65d9c834, 0xa07ef6ba, 0x0609fd0e, 0x37e1e793, 0x9196ec27,
0xcfbd399c, 0x69ca3228, 0x582228b5, 0xfe552301, 0x3bf21d8f, 0x9d85163b, 0xac6d0ca6, 0x0a1a0712,
0xfc5277fb, 0x5a257c4f, 0x6bcd66d2, 0xcdba6d66, 0x081d53e8, 0xae6a585c, 0x9f8242c1, 0x39f54975,
0xa863a552, 0x0e14aee6, 0x3ffcb47b, 0x998bbfcf, 0x5c2c8141, 0xfa5b8af5, 0xcbb39068, 0x6dc49bdc,
0x9b8ceb35, 0x3dfbe081, 0x0c13fa1c, 0xaa64f1a8, 0x6fc3cf26, 0xc9b4c492, 0xf85cde0f, 0x5e2bd5bb,
0x440b7579, 0xe27c7ecd, 0xd3946450, 0x75e36fe4, 0xb044516a, 0x16335ade, 0x27db4043, 0x81ac4bf7,
0x77e43b1e, 0xd19330aa, 0xe07b2a37, 0x460c2183, 0x83ab1f0d, 0x25dc14b9, 0x14340e24, 0xb2430590,
0x23d5e9b7, 0x85a2e203, 0xb44af89e, 0x123df32a, 0xd79acda4, 0x71edc610, 0x4005dc8d, 0xe672d739,
0x103aa7d0, 0xb64dac64, 0x87a5b6f9, 0x21d2bd4d, 0xe47583c3, 0x42028877, 0x73ea92ea, 0xd59d995e,
0x8bb64ce5, 0x2dc14751, 0x1c295dcc, 0xba5e5678, 0x7ff968f6, 0xd98e6342, 0xe86679df, 0x4e11726b,
0xb8590282, 0x1e2e0936, 0x2fc613ab, 0x89b1181f, 0x4c162691, 0xea612d25, 0xdb8937b8, 0x7dfe3c0c,
0xec68d02b, 0x4a1fdb9f, 0x7bf7c102, 0xdd80cab6, 0x1827f438, 0xbe50ff8c, 0x8fb8e511, 0x29cfeea5,
0xdf879e4c, 0x79f095f8, 0x48188f65, 0xee6f84d1, 0x2bc8ba5f, 0x8dbfb1eb, 0xbc57ab76, 0x1a20a0c2,
0x8816eaf2, 0x2e61e146, 0x1f89fbdb, 0xb9fef06f, 0x7c59cee1, 0xda2ec555, 0xebc6dfc8, 0x4db1d47c,
0xbbf9a495, 0x1d8eaf21, 0x2c66b5bc, 0x8a11be08, 0x4fb68086, 0xe9c18b32, 0xd82991af, 0x7e5e9a1b,
0xefc8763c, 0x49bf7d88, 0x78576715, 0xde206ca1, 0x1b87522f, 0xbdf0599b, 0x8c184306, 0x2a6f48b2,
0xdc27385b, 0x7a5033ef, 0x4bb82972, 0xedcf22c6, 0x28681c48, 0x8e1f17fc, 0xbff70d61, 0x198006d5,
0x47abd36e, 0xe1dcd8da, 0xd034c247, 0x7643c9f3, 0xb3e4f77d, 0x1593fcc9, 0x247be654, 0x820cede0,
0x74449d09, 0xd23396bd, 0xe3db8c20, 0x45ac8794, 0x800bb91a, 0x267cb2ae, 0x1794a833, 0xb1e3a387,
0x20754fa0, 0x86024414, 0xb7ea5e89, 0x119d553d, 0xd43a6bb3, 0x724d6007, 0x43a57a9a, 0xe5d2712e,
0x139a01c7, 0xb5ed0a73, 0x840510ee, 0x22721b5a, 0xe7d525d4, 0x41a22e60, 0x704a34fd, 0xd63d3f49,
0xcc1d9f8b, 0x6a6a943f, 0x5b828ea2, 0xfdf58516, 0x3852bb98, 0x9e25b02c, 0xafcdaab1, 0x09baa105,
0xfff2d1ec, 0x5985da58, 0x686dc0c5, 0xce1acb71, 0x0bbdf5ff, 0xadcafe4b, 0x9c22e4d6, 0x3a55ef62,
0xabc30345, 0x0db408f1, 0x3c5c126c, 0x9a2b19d8, 0x5f8c2756, 0xf9fb2ce2, 0xc813367f, 0x6e643dcb,
0x982c4d22, 0x3e5b4696, 0x0fb35c0b, 0xa9c457bf, 0x6c636931, 0xca146285, 0xfbfc7818, 0x5d8b73ac,
0x03a0a617, 0xa5d7ada3, 0x943fb73e, 0x3248bc8a, 0xf7ef8204, 0x519889b0, 0x6070932d, 0xc6079899,
0x304fe870, 0x9638e3c4, 0xa7d0f959, 0x01a7f2ed, 0xc400cc63, 0x6277c7d7, 0x539fdd4a, 0xf5e8d6fe,
0x647e3ad9, 0xc209316d, 0xf3e12bf0, 0x55962044, 0x90311eca, 0x3646157e, 0x07ae0fe3, 0xa1d90457,
0x579174be, 0xf1e67f0a, 0xc00e6597, 0x66796e23, 0xa3de50ad, 0x05a95b19, 0x34414184, 0x92364a30,
},
{
0x00000000, 0xccaa009e, 0x4225077d, 0x8e8f07e3, 0x844a0efa, 0x48e00e64, 0xc66f0987, 0x0ac50919,
0xd3e51bb5, 0x1f4f1b2b, 0x91c01cc8, 0x5d6a1c56, 0x57af154f, 0x9b0515d1, 0x158a1232, 0xd92012ac,
0x7cbb312b, 0xb01131b5, 0x3e9e3656, 0xf23436c8, 0xf8f13fd1, 0x345b3f4f, 0xbad438ac, 0x767e3832,
0xaf5e2a9e, 0x63f42a00, 0xed7b2de3, 0x21d12d7d, 0x2b142464, 0xe7be24fa, 0x69312319, 0xa59b2387,
0xf9766256, 0x35dc62c8, 0xbb53652b, 0x77f965b5, 0x7d3c6cac, 0xb1966c32, 0x3f196bd1, 0xf3b36b4f,
0x2a9379e3, 0xe639797d, 0x68b67e9e, 0xa41c7e00, 0xaed97719, 0x62737787, 0xecfc7064, 0x205670fa,
0x85cd537d, 0x496753e3, 0xc7e85400, 0x0b42549e, 0x01875d87, 0xcd2d5d19, 0x43a25afa, 0x8f085a64,
0x562848c8, 0x9a824856, 0x140d4fb5, 0xd8a74f2b, 0xd2624632, 0x1ec846ac, 0x9047414f, 0x5ced41d1,
0x299dc2ed, 0xe537c273, 0x6bb8c590, 0xa712c50e, 0xadd7cc17, 0x617dcc89, 0xeff2cb6a, 0x2358cbf4,
0xfa78d958, 0x36d2d9c6, 0xb85dde25, 0x74f7debb, 0x7e32d7a2, 0xb298d73c, 0x3c17d0df, 0xf0bdd041,
0x5526f3c6, 0x998cf358, 0x1703f4bb, 0xdba9f425, 0xd16cfd3c, 0x1dc6fda2, 0x9349fa41, 0x5fe3fadf,
0x86c3e873, 0x4a69e8ed, 0xc4e6ef0e, 0x084cef90, 0x0289e689, 0xce23e617, 0x40ace1f4, 0x8c06e16a,
0xd0eba0bb, 0x1c41a025, 0x92cea7c6, 0x5e64a758, 0x54a1ae41, 0x980baedf, 0x1684a93c, 0xda2ea9a2,
0x030ebb0e, 0xcfa4bb90, 0x412bbc73, 0x8d81bced, 0x8744b5f4, 0x4beeb56a, 0xc561b289, 0x09cbb217,
0xac509190, 0x60fa910e, 0xee7596ed, 0x22df9673, 0x281a9f6a, 0xe4b09ff4, 0x6a3f9817, 0xa6959889,
0x7fb58a25, 0xb31f8abb, 0x3d908d58, 0xf13a8dc6, 0xfbff84df, 0x37558441, 0xb9da83a2, 0x7570833c,
0x533b85da, 0x9f918544, 0x111e82a7, 0xddb48239, 0xd7718b20, 0x1bdb8bbe, 0x95548c5d, 0x59fe8cc3,
0x80de9e6f, 0x4c749ef1, 0xc2fb9912, 0x0e51998c, 0x04949095, 0xc83e900b, 0x46b197e8, 0x8a1b9776,
0x2f80b4f1, 0xe32ab46f, 0x6da5b38c, 0xa10fb312, 0xabcaba0b, 0x6760ba95, 0xe9efbd76, 0x2545bde8,
0xfc65af44, 0x30cfafda, 0xbe40a839, 0x72eaa8a7, 0x782fa1be, 0xb485a120, 0x3a0aa6c3, 0xf6a0a65d,
0xaa4de78c, 0x66e7e712, 0xe868e0f1, 0x24c2e06f, 0x2e07e976, 0xe2ade9e8, 0x6c22ee0b, 0xa088ee95,
0x79a8fc39, 0xb502fca7, 0x3b8dfb44, 0xf727fbda, 0xfde2f2c3, 0x3148f25d, 0xbfc7f5be, 0x736df520,
0xd6f6d6a7, 0x1a5cd639, 0x94d3d1da, 0x5879d144, 0x52bcd85d, 0x9e16d8c3, 0x1099df20, 0xdc33dfbe,
0x0513cd12, 0xc9b9cd8c, 0x4736ca6f, 0x8b9ccaf1, 0x8159c3e8, 0x4df3c376, 0xc37cc495, 0x0fd6c40b,
0x7aa64737, 0xb60c47a9, 0x3883404a, 0xf42940d4, 0xfeec49cd, 0x32464953, 0xbcc94eb0, 0x70634e2e,
0xa9435c82, 0x65e95c1c, 0xeb665bff, 0x27cc5b61, 0x2d095278, 0xe1a352e6, 0x6f2c5505, 0xa386559b,
0x061d761c, 0xcab77682, 0x44387161, 0x889271ff, 0x825778e6, 0x4efd7878, 0xc0727f9b, 0x0cd87f05,
0xd5f86da9, 0x19526d37, 0x97dd6ad4, 0x5b776a4a, 0x51b26353, 0x9d1863cd, 0x1397642e, 0xdf3d64b0,
0x83d02561, 0x4f7a25ff, 0xc1f5221c, 0x0d5f2282, 0x079a2b9b, 0xcb302b05, 0x45bf2ce6, 0x89152c78,
0x50353ed4, 0x9c9f3e4a, 0x121039a9, 0xdeba3937, 0xd47f302e, 0x18d530b0, 0x965a3753, 0x5af037cd,
0xff6b144a, 0x33c114d4, 0xbd4e1337, 0x71e413a9, 0x7b211ab0, 0xb78b1a2e, 0x39041dcd, 0xf5ae1d53,
0x2c8e0fff, 0xe0240f61, 0x6eab0882, 0xa201081c, 0xa8c40105, 0x646e019b, 0xeae10678, 0x264b06e6,
},
};
/*
@(optimization_mode="speed")
crc32 :: proc(data: []byte, seed := u32(0)) -> u32 {
result := ~u32(seed);
#no_bounds_check for b in data {
result = result>>8 ~ _crc32_table[(result ~ u32(b)) & 0xff];
}
return ~result;
}
@private _crc32_table := [256]u32{
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba,
0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,
0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec,
0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5,
0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940,
0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116,
0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f,
0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d,
0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a,
0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818,
0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457,
0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c,
0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb,
0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9,
0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086,
0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4,
0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad,
0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683,
0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe,
0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7,
0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252,
0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60,
0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79,
0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f,
0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04,
0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a,
0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21,
0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e,
0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45,
0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db,
0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0,
0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6,
0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,
0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d,
};
*/
+75 -152
View File
@@ -1,32 +1,61 @@
package hash
import "core:mem"
import "core:intrinsics"
@(optimization_mode="speed")
adler32 :: proc(data: []byte, seed := u32(1)) -> u32 #no_bounds_check {
adler32 :: proc(data: []byte) -> u32 {
ADLER_CONST :: 65521;
a, b: u32 = 1, 0;
for x in data {
a = (a + u32(x)) % ADLER_CONST;
buffer := raw_data(data);
a, b: u64 = u64(seed) & 0xFFFF, u64(seed) >> 16;
buf := data[:];
for len(buf) != 0 && uintptr(buffer) & 7 != 0 {
a = (a + u64(buf[0]));
b = (b + a);
buffer = intrinsics.ptr_offset(buffer, 1);
buf = buf[1:];
}
for len(buf) > 7 {
count := min(len(buf), 5552);
for count > 7 {
a += u64(buf[0]); b += a;
a += u64(buf[1]); b += a;
a += u64(buf[2]); b += a;
a += u64(buf[3]); b += a;
a += u64(buf[4]); b += a;
a += u64(buf[5]); b += a;
a += u64(buf[6]); b += a;
a += u64(buf[7]); b += a;
buf = buf[8:];
count -= 8;
}
a %= ADLER_CONST;
b %= ADLER_CONST;
}
for len(buf) != 0 {
a = (a + u64(buf[0])) % ADLER_CONST;
b = (b + a) % ADLER_CONST;
buf = buf[1:];
}
return (b << 16) | a;
return (u32(b) << 16) | u32(a);
}
crc32 :: proc(data: []byte) -> u32 {
result := ~u32(0);
@(optimization_mode="speed")
djb2 :: proc(data: []byte) -> u32 {
hash: u32 = 5381;
for b in data {
result = result>>8 ~ _crc32_table[(result ~ u32(b)) & 0xff];
hash = (hash << 5) + hash + u32(b); // hash * 33 + u32(b)
}
return ~result;
}
crc64 :: proc(data: []byte) -> u64 {
result := ~u64(0);
for b in data {
result = result>>8 ~ _crc64_table[(result ~ u64(b)) & 0xff];
}
return ~result;
return hash;
}
@(optimization_mode="speed")
fnv32 :: proc(data: []byte) -> u32 {
h: u32 = 0x811c9dc5;
for b in data {
@@ -35,6 +64,7 @@ fnv32 :: proc(data: []byte) -> u32 {
return h;
}
@(optimization_mode="speed")
fnv64 :: proc(data: []byte) -> u64 {
h: u64 = 0xcbf29ce484222325;
for b in data {
@@ -43,6 +73,7 @@ fnv64 :: proc(data: []byte) -> u64 {
return h;
}
@(optimization_mode="speed")
fnv32a :: proc(data: []byte) -> u32 {
h: u32 = 0x811c9dc5;
for b in data {
@@ -51,6 +82,7 @@ fnv32a :: proc(data: []byte) -> u32 {
return h;
}
@(optimization_mode="speed")
fnv64a :: proc(data: []byte) -> u64 {
h: u64 = 0xcbf29ce484222325;
for b in data {
@@ -59,13 +91,28 @@ fnv64a :: proc(data: []byte) -> u64 {
return h;
}
@(optimization_mode="speed")
jenkins :: proc(data: []byte) -> u32 {
hash: u32 = 0;
for b in data {
hash += u32(b);
hash += hash << 10;
hash ~= hash >> 6;
}
hash += hash << 3;
hash ~= hash >> 11;
hash += hash << 15;
return hash;
}
@(optimization_mode="speed")
murmur32 :: proc(data: []byte) -> u32 {
c1_32: u32 : 0xcc9e2d51;
c2_32: u32 : 0x1b873593;
h1: u32 = 0;
nblocks := len(data)/4;
p := &data[0];
p := raw_data(data);
p1 := mem.ptr_offset(p, 4*nblocks);
for ; p < p1; p = mem.ptr_offset(p, 4) {
@@ -108,6 +155,7 @@ murmur32 :: proc(data: []byte) -> u32 {
return h1;
}
@(optimization_mode="speed")
murmur64 :: proc(data: []byte) -> u64 {
SEED :: 0x9747b28c;
@@ -116,7 +164,7 @@ murmur64 :: proc(data: []byte) -> u64 {
r :: 47;
h: u64 = SEED ~ (u64(len(data)) * m);
data64 := mem.slice_ptr(cast(^u64)&data[0], len(data)/size_of(u64));
data64 := mem.slice_ptr(cast(^u64)raw_data(data), len(data)/size_of(u64));
for _, i in data64 {
k := data64[i];
@@ -152,7 +200,7 @@ murmur64 :: proc(data: []byte) -> u64 {
h1 := u32(SEED) ~ u32(len(data));
h2 := u32(SEED) >> 32;
data32 := mem.slice_ptr(cast(^u32)&data[0], len(data)/size_of(u32));
data32 := mem.slice_ptr(cast(^u32)raw_data(data), len(data)/size_of(u32));
len := len(data);
i := 0;
@@ -213,136 +261,11 @@ murmur64 :: proc(data: []byte) -> u64 {
}
}
_crc32_table := [256]u32{
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba,
0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,
0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec,
0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5,
0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940,
0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116,
0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f,
0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d,
0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a,
0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818,
0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457,
0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c,
0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb,
0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9,
0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086,
0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4,
0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad,
0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683,
0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe,
0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7,
0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252,
0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60,
0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79,
0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f,
0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04,
0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a,
0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21,
0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e,
0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45,
0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db,
0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0,
0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6,
0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,
0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d,
};
_crc64_table := [256]u64{
0x0000000000000000, 0x42f0e1eba9ea3693, 0x85e1c3d753d46d26, 0xc711223cfa3e5bb5,
0x493366450e42ecdf, 0x0bc387aea7a8da4c, 0xccd2a5925d9681f9, 0x8e224479f47cb76a,
0x9266cc8a1c85d9be, 0xd0962d61b56fef2d, 0x17870f5d4f51b498, 0x5577eeb6e6bb820b,
0xdb55aacf12c73561, 0x99a54b24bb2d03f2, 0x5eb4691841135847, 0x1c4488f3e8f96ed4,
0x663d78ff90e185ef, 0x24cd9914390bb37c, 0xe3dcbb28c335e8c9, 0xa12c5ac36adfde5a,
0x2f0e1eba9ea36930, 0x6dfeff5137495fa3, 0xaaefdd6dcd770416, 0xe81f3c86649d3285,
0xf45bb4758c645c51, 0xb6ab559e258e6ac2, 0x71ba77a2dfb03177, 0x334a9649765a07e4,
0xbd68d2308226b08e, 0xff9833db2bcc861d, 0x388911e7d1f2dda8, 0x7a79f00c7818eb3b,
0xcc7af1ff21c30bde, 0x8e8a101488293d4d, 0x499b3228721766f8, 0x0b6bd3c3dbfd506b,
0x854997ba2f81e701, 0xc7b97651866bd192, 0x00a8546d7c558a27, 0x4258b586d5bfbcb4,
0x5e1c3d753d46d260, 0x1cecdc9e94ace4f3, 0xdbfdfea26e92bf46, 0x990d1f49c77889d5,
0x172f5b3033043ebf, 0x55dfbadb9aee082c, 0x92ce98e760d05399, 0xd03e790cc93a650a,
0xaa478900b1228e31, 0xe8b768eb18c8b8a2, 0x2fa64ad7e2f6e317, 0x6d56ab3c4b1cd584,
0xe374ef45bf6062ee, 0xa1840eae168a547d, 0x66952c92ecb40fc8, 0x2465cd79455e395b,
0x3821458aada7578f, 0x7ad1a461044d611c, 0xbdc0865dfe733aa9, 0xff3067b657990c3a,
0x711223cfa3e5bb50, 0x33e2c2240a0f8dc3, 0xf4f3e018f031d676, 0xb60301f359dbe0e5,
0xda050215ea6c212f, 0x98f5e3fe438617bc, 0x5fe4c1c2b9b84c09, 0x1d14202910527a9a,
0x93366450e42ecdf0, 0xd1c685bb4dc4fb63, 0x16d7a787b7faa0d6, 0x5427466c1e109645,
0x4863ce9ff6e9f891, 0x0a932f745f03ce02, 0xcd820d48a53d95b7, 0x8f72eca30cd7a324,
0x0150a8daf8ab144e, 0x43a04931514122dd, 0x84b16b0dab7f7968, 0xc6418ae602954ffb,
0xbc387aea7a8da4c0, 0xfec89b01d3679253, 0x39d9b93d2959c9e6, 0x7b2958d680b3ff75,
0xf50b1caf74cf481f, 0xb7fbfd44dd257e8c, 0x70eadf78271b2539, 0x321a3e938ef113aa,
0x2e5eb66066087d7e, 0x6cae578bcfe24bed, 0xabbf75b735dc1058, 0xe94f945c9c3626cb,
0x676dd025684a91a1, 0x259d31cec1a0a732, 0xe28c13f23b9efc87, 0xa07cf2199274ca14,
0x167ff3eacbaf2af1, 0x548f120162451c62, 0x939e303d987b47d7, 0xd16ed1d631917144,
0x5f4c95afc5edc62e, 0x1dbc74446c07f0bd, 0xdaad56789639ab08, 0x985db7933fd39d9b,
0x84193f60d72af34f, 0xc6e9de8b7ec0c5dc, 0x01f8fcb784fe9e69, 0x43081d5c2d14a8fa,
0xcd2a5925d9681f90, 0x8fdab8ce70822903, 0x48cb9af28abc72b6, 0x0a3b7b1923564425,
0x70428b155b4eaf1e, 0x32b26afef2a4998d, 0xf5a348c2089ac238, 0xb753a929a170f4ab,
0x3971ed50550c43c1, 0x7b810cbbfce67552, 0xbc902e8706d82ee7, 0xfe60cf6caf321874,
0xe224479f47cb76a0, 0xa0d4a674ee214033, 0x67c58448141f1b86, 0x253565a3bdf52d15,
0xab1721da49899a7f, 0xe9e7c031e063acec, 0x2ef6e20d1a5df759, 0x6c0603e6b3b7c1ca,
0xf6fae5c07d3274cd, 0xb40a042bd4d8425e, 0x731b26172ee619eb, 0x31ebc7fc870c2f78,
0xbfc9838573709812, 0xfd39626eda9aae81, 0x3a28405220a4f534, 0x78d8a1b9894ec3a7,
0x649c294a61b7ad73, 0x266cc8a1c85d9be0, 0xe17dea9d3263c055, 0xa38d0b769b89f6c6,
0x2daf4f0f6ff541ac, 0x6f5faee4c61f773f, 0xa84e8cd83c212c8a, 0xeabe6d3395cb1a19,
0x90c79d3fedd3f122, 0xd2377cd44439c7b1, 0x15265ee8be079c04, 0x57d6bf0317edaa97,
0xd9f4fb7ae3911dfd, 0x9b041a914a7b2b6e, 0x5c1538adb04570db, 0x1ee5d94619af4648,
0x02a151b5f156289c, 0x4051b05e58bc1e0f, 0x87409262a28245ba, 0xc5b073890b687329,
0x4b9237f0ff14c443, 0x0962d61b56fef2d0, 0xce73f427acc0a965, 0x8c8315cc052a9ff6,
0x3a80143f5cf17f13, 0x7870f5d4f51b4980, 0xbf61d7e80f251235, 0xfd913603a6cf24a6,
0x73b3727a52b393cc, 0x31439391fb59a55f, 0xf652b1ad0167feea, 0xb4a25046a88dc879,
0xa8e6d8b54074a6ad, 0xea16395ee99e903e, 0x2d071b6213a0cb8b, 0x6ff7fa89ba4afd18,
0xe1d5bef04e364a72, 0xa3255f1be7dc7ce1, 0x64347d271de22754, 0x26c49cccb40811c7,
0x5cbd6cc0cc10fafc, 0x1e4d8d2b65facc6f, 0xd95caf179fc497da, 0x9bac4efc362ea149,
0x158e0a85c2521623, 0x577eeb6e6bb820b0, 0x906fc95291867b05, 0xd29f28b9386c4d96,
0xcedba04ad0952342, 0x8c2b41a1797f15d1, 0x4b3a639d83414e64, 0x09ca82762aab78f7,
0x87e8c60fded7cf9d, 0xc51827e4773df90e, 0x020905d88d03a2bb, 0x40f9e43324e99428,
0x2cffe7d5975e55e2, 0x6e0f063e3eb46371, 0xa91e2402c48a38c4, 0xebeec5e96d600e57,
0x65cc8190991cb93d, 0x273c607b30f68fae, 0xe02d4247cac8d41b, 0xa2dda3ac6322e288,
0xbe992b5f8bdb8c5c, 0xfc69cab42231bacf, 0x3b78e888d80fe17a, 0x7988096371e5d7e9,
0xf7aa4d1a85996083, 0xb55aacf12c735610, 0x724b8ecdd64d0da5, 0x30bb6f267fa73b36,
0x4ac29f2a07bfd00d, 0x08327ec1ae55e69e, 0xcf235cfd546bbd2b, 0x8dd3bd16fd818bb8,
0x03f1f96f09fd3cd2, 0x41011884a0170a41, 0x86103ab85a2951f4, 0xc4e0db53f3c36767,
0xd8a453a01b3a09b3, 0x9a54b24bb2d03f20, 0x5d45907748ee6495, 0x1fb5719ce1045206,
0x919735e51578e56c, 0xd367d40ebc92d3ff, 0x1476f63246ac884a, 0x568617d9ef46bed9,
0xe085162ab69d5e3c, 0xa275f7c11f7768af, 0x6564d5fde549331a, 0x279434164ca30589,
0xa9b6706fb8dfb2e3, 0xeb46918411358470, 0x2c57b3b8eb0bdfc5, 0x6ea7525342e1e956,
0x72e3daa0aa188782, 0x30133b4b03f2b111, 0xf7021977f9cceaa4, 0xb5f2f89c5026dc37,
0x3bd0bce5a45a6b5d, 0x79205d0e0db05dce, 0xbe317f32f78e067b, 0xfcc19ed95e6430e8,
0x86b86ed5267cdbd3, 0xc4488f3e8f96ed40, 0x0359ad0275a8b6f5, 0x41a94ce9dc428066,
0xcf8b0890283e370c, 0x8d7be97b81d4019f, 0x4a6acb477bea5a2a, 0x089a2aacd2006cb9,
0x14dea25f3af9026d, 0x562e43b4931334fe, 0x913f6188692d6f4b, 0xd3cf8063c0c759d8,
0x5dedc41a34bbeeb2, 0x1f1d25f19d51d821, 0xd80c07cd676f8394, 0x9afce626ce85b507,
};
@(optimization_mode="speed")
sdbm :: proc(data: []byte) -> u32 {
hash: u32 = 0;
for b in data {
hash = u32(b) + (hash<<6) + (hash<<16) - hash;
}
return hash;
}
+40
View File
@@ -0,0 +1,40 @@
package hash
ginger_hash8 :: proc(x: u8) -> u8 {
h := x * 251;
h += ~(x << 3);
h ~= (x >> 1);
h += ~(x << 7);
h ~= (x >> 6);
h += (x << 2);
return h;
}
ginger_hash16 :: proc(x: u16) -> u16 {
z := (x << 8) | (x >> 8);
h := z;
h += ~(z << 5);
h ~= (z >> 2);
h += ~(z << 13);
h ~= (z >> 10);
h += ~(z << 4);
h = (h << 10) | (h >> 10);
return h;
}
ginger8 :: proc(data: []byte) -> u8 {
h := ginger_hash8(0);
for b in data {
h ~= ginger_hash8(b);
}
return h;
}
ginger16 :: proc(data: []byte) -> u16 {
h := ginger_hash16(0);
for b in data {
h ~= ginger_hash16(u16(b));
}
return h;
}
+214
View File
@@ -0,0 +1,214 @@
package image
/*
Copyright 2021 Jeroen van Rijn <nom@duclavier.com>.
Made available under Odin's BSD-2 license.
List of contributors:
Jeroen van Rijn: Initial implementation, optimization.
Ginger Bill: Cosmetic changes.
*/
import "core:bytes"
import "core:mem"
Image :: struct {
width: int,
height: int,
channels: int,
depth: int,
pixels: bytes.Buffer,
/*
Some image loaders/writers can return/take an optional background color.
For convenience, we return them as u16 so we don't need to switch on the type
in our viewer, and can just test against nil.
*/
background: Maybe([3]u16),
metadata_ptr: rawptr,
metadata_type: typeid,
}
/*
IMPORTANT: `.do_not_expand_*` options currently skip handling of the `alpha_*` options,
therefore Gray+Alpha will be returned as such even if you add `.alpha_drop_if_present`,
and `.alpha_add_if_missing` and keyed transparency will likewise be ignored.
The same goes for indexed images. This will be remedied in a near future update.
*/
/*
Image_Option:
`.info`
This option behaves as `.return_ihdr` and `.do_not_decompress_image` and can be used
to gather an image's dimensions and color information.
`.return_header`
Fill out img.sidecar.header with the image's format-specific header struct.
If we only care about the image specs, we can set `.return_header` +
`.do_not_decompress_image`, or `.info`, which works as if both of these were set.
`.return_metadata`
Returns all chunks not needed to decode the data.
It also returns the header as if `.return_header` was set.
`.do_not_decompress_image`
Skip decompressing IDAT chunk, defiltering and the rest.
`.do_not_expand_grayscale`
Do not turn grayscale (+ Alpha) images into RGB(A).
Returns just the 1 or 2 channels present, although 1, 2 and 4 bit are still scaled to 8-bit.
`.do_not_expand_indexed`
Do not turn indexed (+ Alpha) images into RGB(A).
Returns just the 1 or 2 (with `tRNS`) channels present.
Make sure to use `return_metadata` to also return the palette chunk so you can recolor it yourself.
`.do_not_expand_channels`
Applies both `.do_not_expand_grayscale` and `.do_not_expand_indexed`.
`.alpha_add_if_missing`
If the image has no alpha channel, it'll add one set to max(type).
Turns RGB into RGBA and Gray into Gray+Alpha
`.alpha_drop_if_present`
If the image has an alpha channel, drop it.
You may want to use `.alpha_premultiply` in this case.
NOTE: For PNG, this also skips handling of the tRNS chunk, if present,
unless you select `alpha_premultiply`.
In this case it'll premultiply the specified pixels in question only,
as the others are implicitly fully opaque.
`.alpha_premultiply`
If the image has an alpha channel, returns image data as follows:
RGB *= A, Gray = Gray *= A
`.blend_background`
If a bKGD chunk is present in a PNG, we normally just set `img.background`
with its value and leave it up to the application to decide how to display the image,
as per the PNG specification.
With `.blend_background` selected, we blend the image against the background
color. As this negates the use for an alpha channel, we'll drop it _unless_
you also specify `.alpha_add_if_missing`.
Options that don't apply to an image format will be ignored by their loader.
*/
Option :: enum {
info = 0,
do_not_decompress_image,
return_header,
return_metadata,
alpha_add_if_missing,
alpha_drop_if_present,
alpha_premultiply,
blend_background,
// Unimplemented
do_not_expand_grayscale,
do_not_expand_indexed,
do_not_expand_channels,
}
Options :: distinct bit_set[Option];
Error :: enum {
Invalid_PNG_Signature,
IHDR_Not_First_Chunk,
IHDR_Corrupt,
IDAT_Missing,
IDAT_Must_Be_Contiguous,
IDAT_Corrupt,
PNG_Does_Not_Adhere_to_Spec,
PLTE_Encountered_Unexpectedly,
PLTE_Invalid_Length,
TRNS_Encountered_Unexpectedly,
BKGD_Invalid_Length,
Invalid_Image_Dimensions,
Unknown_Color_Type,
Invalid_Color_Bit_Depth_Combo,
Unknown_Filter_Method,
Unknown_Interlace_Method,
Requested_Channel_Not_Present,
Post_Processing_Error,
}
/*
Functions to help with image buffer calculations
*/
compute_buffer_size :: proc(width, height, channels, depth: int, extra_row_bytes := int(0)) -> (size: int) {
size = ((((channels * width * depth) + 7) >> 3) + extra_row_bytes) * height;
return;
}
/*
For when you have an RGB(A) image, but want a particular channel.
*/
Channel :: enum u8 {
R = 1,
G = 2,
B = 3,
A = 4,
}
return_single_channel :: proc(img: ^Image, channel: Channel) -> (res: ^Image, ok: bool) {
ok = false;
t: bytes.Buffer;
idx := int(channel);
if img.channels == 2 && idx == 4 {
// Alpha requested, which in a two channel image is index 2: G.
idx = 2;
}
if idx > img.channels {
return {}, false;
}
switch img.depth {
case 8:
buffer_size := compute_buffer_size(img.width, img.height, 1, 8);
t = bytes.Buffer{};
resize(&t.buf, buffer_size);
i := bytes.buffer_to_bytes(&img.pixels);
o := bytes.buffer_to_bytes(&t);
for len(i) > 0 {
o[0] = i[idx];
i = i[img.channels:];
o = o[1:];
}
case 16:
buffer_size := compute_buffer_size(img.width, img.height, 2, 8);
t = bytes.Buffer{};
resize(&t.buf, buffer_size);
i := mem.slice_data_cast([]u16, img.pixels.buf[:]);
o := mem.slice_data_cast([]u16, t.buf[:]);
for len(i) > 0 {
o[0] = i[idx];
i = i[img.channels:];
o = o[1:];
}
case 1, 2, 4:
// We shouldn't see this case, as the loader already turns these into 8-bit.
return {}, false;
}
res = new(Image);
res.width = img.width;
res.height = img.height;
res.channels = 1;
res.depth = img.depth;
res.pixels = t;
res.background = img.background;
res.metadata_ptr = img.metadata_ptr;
res.metadata_type = img.metadata_type;
return res, true;
}
+354
View File
@@ -0,0 +1,354 @@
//+ignore
package png
/*
Copyright 2021 Jeroen van Rijn <nom@duclavier.com>.
Made available under Odin's BSD-2 license.
List of contributors:
Jeroen van Rijn: Initial implementation.
Ginger Bill: Cosmetic changes.
An example of how to use `load`.
*/
import "core:compress"
import "core:image"
// import "core:image/png"
import "core:bytes"
import "core:fmt"
// For PPM writer
import "core:mem"
import "core:os"
main :: proc() {
track := mem.Tracking_Allocator{};
mem.tracking_allocator_init(&track, context.allocator);
context.allocator = mem.tracking_allocator(&track);
demo();
if len(track.allocation_map) > 0 {
fmt.println("Leaks:");
for _, v in track.allocation_map {
fmt.printf("\t%v\n\n", v);
}
}
}
demo :: proc() {
file: string;
options := image.Options{}; // {.return_metadata};
err: compress.Error;
img: ^image.Image;
file = "../../../misc/logo-slim.png";
img, err = load(file, options);
defer destroy(img);
if err != nil {
fmt.printf("Trying to read PNG file %v returned %v\n", file, err);
} else {
v: ^Info;
fmt.printf("Image: %vx%vx%v, %v-bit.\n", img.width, img.height, img.channels, img.depth);
if img.metadata_ptr != nil && img.metadata_type == Info {
v = (^Info)(img.metadata_ptr);
// Handle ancillary chunks as you wish.
// We provide helper functions for a few types.
for c in v.chunks {
#partial switch c.header.type {
case .tIME:
t, _ := core_time(c);
fmt.printf("[tIME]: %v\n", t);
case .gAMA:
fmt.printf("[gAMA]: %v\n", gamma(c));
case .pHYs:
phys := phys(c);
if phys.unit == .Meter {
xm := f32(img.width) / f32(phys.ppu_x);
ym := f32(img.height) / f32(phys.ppu_y);
dpi_x, dpi_y := phys_to_dpi(phys);
fmt.printf("[pHYs] Image resolution is %v x %v pixels per meter.\n", phys.ppu_x, phys.ppu_y);
fmt.printf("[pHYs] Image resolution is %v x %v DPI.\n", dpi_x, dpi_y);
fmt.printf("[pHYs] Image dimensions are %v x %v meters.\n", xm, ym);
} else {
fmt.printf("[pHYs] x: %v, y: %v pixels per unknown unit.\n", phys.ppu_x, phys.ppu_y);
}
case .iTXt, .zTXt, .tEXt:
res, ok_text := text(c);
if ok_text {
if c.header.type == .iTXt {
fmt.printf("[iTXt] %v (%v:%v): %v\n", res.keyword, res.language, res.keyword_localized, res.text);
} else {
fmt.printf("[tEXt/zTXt] %v: %v\n", res.keyword, res.text);
}
}
defer text_destroy(res);
case .bKGD:
fmt.printf("[bKGD] %v\n", img.background);
case .eXIf:
res, ok_exif := exif(c);
if ok_exif {
/*
Other than checking the signature and byte order, we don't handle Exif data.
If you wish to interpret it, pass it to an Exif parser.
*/
fmt.printf("[eXIf] %v\n", res);
}
case .PLTE:
plte, plte_ok := plte(c);
if plte_ok {
fmt.printf("[PLTE] %v\n", plte);
} else {
fmt.printf("[PLTE] Error\n");
}
case .hIST:
res, ok_hist := hist(c);
if ok_hist {
fmt.printf("[hIST] %v\n", res);
}
case .cHRM:
res, ok_chrm := chrm(c);
if ok_chrm {
fmt.printf("[cHRM] %v\n", res);
}
case .sPLT:
res, ok_splt := splt(c);
if ok_splt {
fmt.printf("[sPLT] %v\n", res);
}
splt_destroy(res);
case .sBIT:
if res, ok_sbit := sbit(c); ok_sbit {
fmt.printf("[sBIT] %v\n", res);
}
case .iCCP:
res, ok_iccp := iccp(c);
if ok_iccp {
fmt.printf("[iCCP] %v\n", res);
}
iccp_destroy(res);
case .sRGB:
if res, ok_srgb := srgb(c); ok_srgb {
fmt.printf("[sRGB] Rendering intent: %v\n", res);
}
case:
type := c.header.type;
name := chunk_type_to_name(&type);
fmt.printf("[%v]: %v\n", name, c.data);
}
}
}
}
if err == nil && .do_not_decompress_image not_in options && .info not_in options {
if ok := write_image_as_ppm("out.ppm", img); ok {
fmt.println("Saved decoded image.");
} else {
fmt.println("Error saving out.ppm.");
fmt.println(img);
}
}
}
// Crappy PPM writer used during testing. Don't use in production.
write_image_as_ppm :: proc(filename: string, image: ^image.Image) -> (success: bool) {
_bg :: proc(bg: Maybe([3]u16), x, y: int, high := true) -> (res: [3]u16) {
if v, ok := bg.?; ok {
res = v;
} else {
if high {
l := u16(30 * 256 + 30);
if (x & 4 == 0) ~ (y & 4 == 0) {
res = [3]u16{l, 0, l};
} else {
res = [3]u16{l >> 1, 0, l >> 1};
}
} else {
if (x & 4 == 0) ~ (y & 4 == 0) {
res = [3]u16{30, 30, 30};
} else {
res = [3]u16{15, 15, 15};
}
}
}
return;
}
// profiler.timed_proc();
using image;
using os;
flags: int = O_WRONLY|O_CREATE|O_TRUNC;
img := image;
// PBM 16-bit images are big endian
when ODIN_ENDIAN == "little" {
if img.depth == 16 {
// The pixel components are in Big Endian. Let's byteswap back.
input := mem.slice_data_cast([]u16, img.pixels.buf[:]);
output := mem.slice_data_cast([]u16be, img.pixels.buf[:]);
#no_bounds_check for v, i in input {
output[i] = u16be(v);
}
}
}
pix := bytes.buffer_to_bytes(&img.pixels);
if len(pix) == 0 || len(pix) < image.width * image.height * int(image.channels) {
return false;
}
mode: int = 0;
when ODIN_OS == "linux" || ODIN_OS == "darwin" {
// NOTE(justasd): 644 (owner read, write; group read; others read)
mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
}
fd, err := open(filename, flags, mode);
if err != 0 {
return false;
}
defer close(fd);
write_string(fd,
fmt.tprintf("P6\n%v %v\n%v\n", width, height, (1 << uint(depth) - 1)),
);
if channels == 3 {
// We don't handle transparency here...
write_ptr(fd, raw_data(pix), len(pix));
} else {
bpp := depth == 16 ? 2 : 1;
bytes_needed := width * height * 3 * bpp;
op := bytes.Buffer{};
bytes.buffer_init_allocator(&op, bytes_needed, bytes_needed);
defer bytes.buffer_destroy(&op);
if channels == 1 {
if depth == 16 {
assert(len(pix) == width * height * 2);
p16 := mem.slice_data_cast([]u16, pix);
o16 := mem.slice_data_cast([]u16, op.buf[:]);
#no_bounds_check for len(p16) != 0 {
r := u16(p16[0]);
o16[0] = r;
o16[1] = r;
o16[2] = r;
p16 = p16[1:];
o16 = o16[3:];
}
} else {
o := 0;
for i := 0; i < len(pix); i += 1 {
r := pix[i];
op.buf[o ] = r;
op.buf[o+1] = r;
op.buf[o+2] = r;
o += 3;
}
}
write_ptr(fd, raw_data(op.buf), len(op.buf));
} else if channels == 2 {
if depth == 16 {
p16 := mem.slice_data_cast([]u16, pix);
o16 := mem.slice_data_cast([]u16, op.buf[:]);
bgcol := img.background;
#no_bounds_check for len(p16) != 0 {
r := f64(u16(p16[0]));
bg: f64;
if bgcol != nil {
v := bgcol.([3]u16)[0];
bg = f64(v);
}
a := f64(u16(p16[1])) / 65535.0;
l := (a * r) + (1 - a) * bg;
o16[0] = u16(l);
o16[1] = u16(l);
o16[2] = u16(l);
p16 = p16[2:];
o16 = o16[3:];
}
} else {
o := 0;
for i := 0; i < len(pix); i += 2 {
r := pix[i]; a := pix[i+1]; a1 := f32(a) / 255.0;
c := u8(f32(r) * a1);
op.buf[o ] = c;
op.buf[o+1] = c;
op.buf[o+2] = c;
o += 3;
}
}
write_ptr(fd, raw_data(op.buf), len(op.buf));
} else if channels == 4 {
if depth == 16 {
p16 := mem.slice_data_cast([]u16be, pix);
o16 := mem.slice_data_cast([]u16be, op.buf[:]);
#no_bounds_check for len(p16) != 0 {
bg := _bg(img.background, 0, 0);
r := f32(p16[0]);
g := f32(p16[1]);
b := f32(p16[2]);
a := f32(p16[3]) / 65535.0;
lr := (a * r) + (1 - a) * f32(bg[0]);
lg := (a * g) + (1 - a) * f32(bg[1]);
lb := (a * b) + (1 - a) * f32(bg[2]);
o16[0] = u16be(lr);
o16[1] = u16be(lg);
o16[2] = u16be(lb);
p16 = p16[4:];
o16 = o16[3:];
}
} else {
o := 0;
for i := 0; i < len(pix); i += 4 {
x := (i / 4) % width;
y := i / width / 4;
_b := _bg(img.background, x, y, false);
bgcol := [3]u8{u8(_b[0]), u8(_b[1]), u8(_b[2])};
r := f32(pix[i]);
g := f32(pix[i+1]);
b := f32(pix[i+2]);
a := f32(pix[i+3]) / 255.0;
lr := u8(f32(r) * a + (1 - a) * f32(bgcol[0]));
lg := u8(f32(g) * a + (1 - a) * f32(bgcol[1]));
lb := u8(f32(b) * a + (1 - a) * f32(bgcol[2]));
op.buf[o ] = lr;
op.buf[o+1] = lg;
op.buf[o+2] = lb;
o += 3;
}
}
write_ptr(fd, raw_data(op.buf), len(op.buf));
} else {
return false;
}
}
return true;
}
+525
View File
@@ -0,0 +1,525 @@
package png
/*
Copyright 2021 Jeroen van Rijn <nom@duclavier.com>.
Made available under Odin's BSD-2 license.
List of contributors:
Jeroen van Rijn: Initial implementation.
Ginger Bill: Cosmetic changes.
These are a few useful utility functions to work with PNG images.
*/
import "core:image"
import "core:compress/zlib"
import coretime "core:time"
import "core:strings"
import "core:bytes"
import "core:mem"
/*
Cleanup of image-specific data.
There are other helpers for cleanup of PNG-specific data.
Those are named *_destroy, where * is the name of the helper.
*/
destroy :: proc(img: ^Image) {
if img == nil {
/*
Nothing to do.
Load must've returned with an error.
*/
return;
}
bytes.buffer_destroy(&img.pixels);
// Clean up Info.
free(img.metadata_ptr);
/*
We don't need to do anything for the individual chunks.
They're allocated on the temp allocator, as is info.chunks
See read_chunk.
*/
free(img);
}
/*
Chunk helpers
*/
gamma :: proc(c: Chunk) -> f32 {
assert(c.header.type == .gAMA);
res := (^gAMA)(raw_data(c.data))^;
when true {
// Returns the wrong result on old backend
// Fixed for -llvm-api
return f32(res.gamma_100k) / 100_000.0;
} else {
return f32(u32(res.gamma_100k)) / 100_000.0;
}
}
INCHES_PER_METER :: 1000.0 / 25.4;
phys :: proc(c: Chunk) -> pHYs {
assert(c.header.type == .pHYs);
res := (^pHYs)(raw_data(c.data))^;
return res;
}
phys_to_dpi :: proc(p: pHYs) -> (x_dpi, y_dpi: f32) {
return f32(p.ppu_x) / INCHES_PER_METER, f32(p.ppu_y) / INCHES_PER_METER;
}
time :: proc(c: Chunk) -> tIME {
assert(c.header.type == .tIME);
res := (^tIME)(raw_data(c.data))^;
return res;
}
core_time :: proc(c: Chunk) -> (t: coretime.Time, ok: bool) {
png_time := time(c);
using png_time;
return coretime.datetime_to_time(
int(year), int(month), int(day),
int(hour), int(minute), int(second),
);
}
text :: proc(c: Chunk) -> (res: Text, ok: bool) {
#partial switch c.header.type {
case .tEXt:
ok = true;
fields := bytes.split(s=c.data, sep=[]u8{0}, allocator=context.temp_allocator);
if len(fields) == 2 {
res.keyword = strings.clone(string(fields[0]));
res.text = strings.clone(string(fields[1]));
} else {
ok = false;
}
return;
case .zTXt:
ok = true;
fields := bytes.split_n(s=c.data, sep=[]u8{0}, n=3, allocator=context.temp_allocator);
if len(fields) != 3 || len(fields[1]) != 0 {
// Compression method must be 0=Deflate, which thanks to the split above turns
// into an empty slice
ok = false; return;
}
// Set up ZLIB context and decompress text payload.
buf: bytes.Buffer;
zlib_error := zlib.inflate_from_byte_array(fields[2], &buf);
defer bytes.buffer_destroy(&buf);
if zlib_error != nil {
ok = false; return;
}
res.keyword = strings.clone(string(fields[0]));
res.text = strings.clone(bytes.buffer_to_string(&buf));
return;
case .iTXt:
ok = true;
s := string(c.data);
null := strings.index_byte(s, 0);
if null == -1 {
ok = false; return;
}
if len(c.data) < null + 4 {
// At a minimum, including the \0 following the keyword, we require 5 more bytes.
ok = false; return;
}
res.keyword = strings.clone(string(c.data[:null]));
rest := c.data[null+1:];
compression_flag := rest[:1][0];
if compression_flag > 1 {
ok = false; return;
}
compression_method := rest[1:2][0];
if compression_flag == 1 && compression_method > 0 {
// Only Deflate is supported
ok = false; return;
}
rest = rest[2:];
// We now expect an optional language keyword and translated keyword, both followed by a \0
null = strings.index_byte(string(rest), 0);
if null == -1 {
ok = false; return;
}
res.language = strings.clone(string(rest[:null]));
rest = rest[null+1:];
null = strings.index_byte(string(rest), 0);
if null == -1 {
ok = false; return;
}
res.keyword_localized = strings.clone(string(rest[:null]));
rest = rest[null+1:];
if compression_flag == 0 {
res.text = strings.clone(string(rest));
} else {
// Set up ZLIB context and decompress text payload.
buf: bytes.Buffer;
zlib_error := zlib.inflate_from_byte_array(rest, &buf);
defer bytes.buffer_destroy(&buf);
if zlib_error != nil {
ok = false; return;
}
res.text = strings.clone(bytes.buffer_to_string(&buf));
}
return;
case:
// PNG text helper called with an unrecognized chunk type.
ok = false; return;
}
}
text_destroy :: proc(text: Text) {
delete(text.keyword);
delete(text.keyword_localized);
delete(text.language);
delete(text.text);
}
iccp :: proc(c: Chunk) -> (res: iCCP, ok: bool) {
ok = true;
fields := bytes.split_n(s=c.data, sep=[]u8{0}, n=3, allocator=context.temp_allocator);
if len(fields[0]) < 1 || len(fields[0]) > 79 {
// Invalid profile name
ok = false; return;
}
if len(fields[1]) != 0 {
// Compression method should be a zero, which the split turned into an empty slice.
ok = false; return;
}
// Set up ZLIB context and decompress iCCP payload
buf: bytes.Buffer;
zlib_error := zlib.inflate_from_byte_array(fields[2], &buf);
if zlib_error != nil {
bytes.buffer_destroy(&buf);
ok = false; return;
}
res.name = strings.clone(string(fields[0]));
res.profile = bytes.buffer_to_bytes(&buf);
return;
}
iccp_destroy :: proc(i: iCCP) {
delete(i.name);
delete(i.profile);
}
srgb :: proc(c: Chunk) -> (res: sRGB, ok: bool) {
ok = true;
if c.header.type != .sRGB || len(c.data) != 1 {
return {}, false;
}
res.intent = sRGB_Rendering_Intent(c.data[0]);
if res.intent > max(sRGB_Rendering_Intent) {
ok = false; return;
}
return;
}
plte :: proc(c: Chunk) -> (res: PLTE, ok: bool) {
if c.header.type != .PLTE {
return {}, false;
}
i := 0; j := 0; ok = true;
for j < int(c.header.length) {
res.entries[i] = {c.data[j], c.data[j+1], c.data[j+2]};
i += 1; j += 3;
}
res.used = u16(i);
return;
}
splt :: proc(c: Chunk) -> (res: sPLT, ok: bool) {
if c.header.type != .sPLT {
return {}, false;
}
ok = true;
fields := bytes.split_n(s=c.data, sep=[]u8{0}, n=2, allocator=context.temp_allocator);
if len(fields) != 2 {
return {}, false;
}
res.depth = fields[1][0];
if res.depth != 8 && res.depth != 16 {
return {}, false;
}
data := fields[1][1:];
count: int;
if res.depth == 8 {
if len(data) % 6 != 0 {
return {}, false;
}
count = len(data) / 6;
if count > 256 {
return {}, false;
}
res.entries = mem.slice_data_cast([][4]u8, data);
} else { // res.depth == 16
if len(data) % 10 != 0 {
return {}, false;
}
count = len(data) / 10;
if count > 256 {
return {}, false;
}
res.entries = mem.slice_data_cast([][4]u16, data);
}
res.name = strings.clone(string(fields[0]));
res.used = u16(count);
return;
}
splt_destroy :: proc(s: sPLT) {
delete(s.name);
}
sbit :: proc(c: Chunk) -> (res: [4]u8, ok: bool) {
/*
Returns [4]u8 with the significant bits in each channel.
A channel will contain zero if not applicable to the PNG color type.
*/
if len(c.data) < 1 || len(c.data) > 4 {
ok = false; return;
}
ok = true;
for i := 0; i < len(c.data); i += 1 {
res[i] = c.data[i];
}
return;
}
hist :: proc(c: Chunk) -> (res: hIST, ok: bool) {
if c.header.type != .hIST {
return {}, false;
}
if c.header.length & 1 == 1 || c.header.length > 512 {
// The entries are u16be, so the length must be even.
// At most 256 entries must be present
return {}, false;
}
ok = true;
data := mem.slice_data_cast([]u16be, c.data);
i := 0;
for len(data) > 0 {
// HIST entries are u16be, we unpack them to machine format
res.entries[i] = u16(data[0]);
i += 1; data = data[1:];
}
res.used = u16(i);
return;
}
chrm :: proc(c: Chunk) -> (res: cHRM, ok: bool) {
ok = true;
if c.header.length != size_of(cHRM_Raw) {
return {}, false;
}
chrm := (^cHRM_Raw)(raw_data(c.data))^;
res.w.x = f32(chrm.w.x) / 100_000.0;
res.w.y = f32(chrm.w.y) / 100_000.0;
res.r.x = f32(chrm.r.x) / 100_000.0;
res.r.y = f32(chrm.r.y) / 100_000.0;
res.g.x = f32(chrm.g.x) / 100_000.0;
res.g.y = f32(chrm.g.y) / 100_000.0;
res.b.x = f32(chrm.b.x) / 100_000.0;
res.b.y = f32(chrm.b.y) / 100_000.0;
return;
}
exif :: proc(c: Chunk) -> (res: Exif, ok: bool) {
ok = true;
if len(c.data) < 4 {
ok = false; return;
}
if c.data[0] == 'M' && c.data[1] == 'M' {
res.byte_order = .big_endian;
if c.data[2] != 0 || c.data[3] != 42 {
ok = false; return;
}
} else if c.data[0] == 'I' && c.data[1] == 'I' {
res.byte_order = .little_endian;
if c.data[2] != 42 || c.data[3] != 0 {
ok = false; return;
}
} else {
ok = false; return;
}
res.data = c.data;
return;
}
/*
General helper functions
*/
compute_buffer_size :: image.compute_buffer_size;
/*
PNG save helpers
*/
when false {
make_chunk :: proc(c: any, t: Chunk_Type) -> (res: Chunk) {
data: []u8;
if v, ok := c.([]u8); ok {
data = v;
} else {
data = mem.any_to_bytes(c);
}
res.header.length = u32be(len(data));
res.header.type = t;
res.data = data;
// CRC the type
crc := hash.crc32(mem.any_to_bytes(res.header.type));
// Extend the CRC with the data
res.crc = u32be(hash.crc32(data, crc));
return;
}
write_chunk :: proc(fd: os.Handle, chunk: Chunk) {
c := chunk;
// Write length + type
os.write_ptr(fd, &c.header, 8);
// Write data
os.write_ptr(fd, mem.raw_data(c.data), int(c.header.length));
// Write CRC32
os.write_ptr(fd, &c.crc, 4);
}
write_image_as_png :: proc(filename: string, image: Image) -> (err: Error) {
profiler.timed_proc();
using image;
using os;
flags: int = O_WRONLY|O_CREATE|O_TRUNC;
if len(image.pixels) == 0 || len(image.pixels) < image.width * image.height * int(image.channels) {
return E_PNG.Invalid_Image_Dimensions;
}
mode: int = 0;
when ODIN_OS == "linux" || ODIN_OS == "darwin" {
// NOTE(justasd): 644 (owner read, write; group read; others read)
mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
}
fd, fderr := open(filename, flags, mode);
if fderr != 0 {
return E_General.Cannot_Open_File;
}
defer close(fd);
magic := Signature;
write_ptr(fd, &magic, 8);
ihdr := IHDR{
width = u32be(width),
height = u32be(height),
bit_depth = depth,
compression_method = 0,
filter_method = 0,
interlace_method = .None,
};
switch channels {
case 1: ihdr.color_type = Color_Type{};
case 2: ihdr.color_type = Color_Type{.Alpha};
case 3: ihdr.color_type = Color_Type{.Color};
case 4: ihdr.color_type = Color_Type{.Color, .Alpha};
case:// Unhandled
return E_PNG.Unknown_Color_Type;
}
h := make_chunk(ihdr, .IHDR);
write_chunk(fd, h);
bytes_needed := width * height * int(channels) + height;
filter_bytes := mem.make_dynamic_array_len_cap([dynamic]u8, bytes_needed, bytes_needed, context.allocator);
defer delete(filter_bytes);
i := 0; j := 0;
// Add a filter byte 0 per pixel row
for y := 0; y < height; y += 1 {
filter_bytes[j] = 0; j += 1;
for x := 0; x < width; x += 1 {
for z := 0; z < channels; z += 1 {
filter_bytes[j+z] = image.pixels[i+z];
}
i += channels; j += channels;
}
}
assert(j == bytes_needed);
a: []u8 = filter_bytes[:];
out_buf: ^[dynamic]u8;
defer free(out_buf);
ctx := zlib.ZLIB_Context{
in_buf = &a,
out_buf = out_buf,
};
err = zlib.write_zlib_stream_from_memory(&ctx);
b: []u8;
if err == nil {
b = ctx.out_buf[:];
} else {
return err;
}
idat := make_chunk(b, .IDAT);
write_chunk(fd, idat);
iend := make_chunk([]u8{}, .IEND);
write_chunk(fd, iend);
return nil;
}
}
File diff suppressed because it is too large Load Diff
+136 -76
View File
@@ -1,81 +1,124 @@
// This is purely for documentation
//+ignore
package intrinsics
// Types
simd_vector :: proc($N: int, $T: typeid) -> type/#simd[N]T
soa_struct :: proc($N: int, $T: typeid) -> type/#soa[N]T
vector :: proc() ---
// Volatile
volatile_load :: proc(dst: ^$T) -> T ---
volatile_store :: proc(dst: ^$T, val: T) -> T ---
// Trapping
debug_trap :: proc() ---
trap :: proc() -> ! ---
// Instructions
alloca :: proc(size, align: int) -> ^u8 ---
cpu_relax :: proc() ---
read_cycle_counter :: proc() -> i64 ---
count_ones :: proc(x: $T) -> T where type_is_integer(T) ---
count_zeros :: proc(x: $T) -> T where type_is_integer(T) ---
count_trailing_zeros :: proc(x: $T) -> T where type_is_integer(T) ---
count_leading_zeros :: proc(x: $T) -> T where type_is_integer(T) ---
reverse_bits :: proc(x: $T) -> T where type_is_integer(T) ---
byte_swap :: proc(x: $T) -> T where type_is_integer(T) || type_is_float(T) ---
overflow_add :: proc(lhs, rhs: $T) -> (T, bool) #optional_ok ---
overflow_sub :: proc(lhs, rhs: $T) -> (T, bool) #optional_ok ---
overflow_mul :: proc(lhs, rhs: $T) -> (T, bool) #optional_ok ---
sqrt :: proc(x: $T) -> T where type_is_float(T) ---
mem_copy :: proc(dst, src: rawptr, len: int) ---
mem_copy_non_overlapping :: proc(dst, src: rawptr, len: int) ---
mem_zero :: proc(ptr: rawptr, len: int) ---
fixed_point_mul :: proc(lhs, rhs: $T, #const scale: uint) -> T where type_is_integer(T) ---
fixed_point_div :: proc(lhs, rhs: $T, #const scale: uint) -> T where type_is_integer(T) ---
fixed_point_mul_sat :: proc(lhs, rhs: $T, #const scale: uint) -> T where type_is_integer(T) ---
fixed_point_div_sat :: proc(lhs, rhs: $T, #const scale: uint) -> T where type_is_integer(T) ---
// Compiler Hints
expect :: proc(val, expected_val: T) -> T ---
// Atomics
atomic_fence :: proc() ---
atomic_fence_acq :: proc() ---
atomic_fence_rel :: proc() ---
atomic_fence_acqrel :: proc() ---
atomic_store :: proc(dst: ^$T, val: $T) ---
atomic_store_rel :: proc(dst: ^$T, val: $T) ---
atomic_store_relaxed :: proc(dst: ^$T, val: $T) ---
atomic_store_unordered :: proc(dst: ^$T, val: $T) ---
atomic_store :: proc(dst: ^$T, val: T) ---
atomic_store_rel :: proc(dst: ^$T, val: T) ---
atomic_store_relaxed :: proc(dst: ^$T, val: T) ---
atomic_store_unordered :: proc(dst: ^$T, val: T) ---
atomic_load :: proc(dst: ^$T) -> T ---
atomic_load_acq :: proc(dst: ^$T) -> T ---
atomic_load_relaxed :: proc(dst: ^$T) -> T ---
atomic_load_unordered :: proc(dst: ^$T) -> T ---
atomic_add :: proc(dst; ^$T, val: $T) -> T ---
atomic_add_acq :: proc(dst; ^$T, val: $T) -> T ---
atomic_add_rel :: proc(dst; ^$T, val: $T) -> T ---
atomic_add_acqrel :: proc(dst; ^$T, val: $T) -> T ---
atomic_add_relaxed :: proc(dst; ^$T, val: $T) -> T ---
atomic_sub :: proc(dst; ^$T, val: $T) -> T ---
atomic_sub_acq :: proc(dst; ^$T, val: $T) -> T ---
atomic_sub_rel :: proc(dst; ^$T, val: $T) -> T ---
atomic_sub_acqrel :: proc(dst; ^$T, val: $T) -> T ---
atomic_sub_relaxed :: proc(dst; ^$T, val: $T) -> T ---
atomic_and :: proc(dst; ^$T, val: $T) -> T ---
atomic_and_acq :: proc(dst; ^$T, val: $T) -> T ---
atomic_and_rel :: proc(dst; ^$T, val: $T) -> T ---
atomic_and_acqrel :: proc(dst; ^$T, val: $T) -> T ---
atomic_and_relaxed :: proc(dst; ^$T, val: $T) -> T ---
atomic_nand :: proc(dst; ^$T, val: $T) -> T ---
atomic_nand_acq :: proc(dst; ^$T, val: $T) -> T ---
atomic_nand_rel :: proc(dst; ^$T, val: $T) -> T ---
atomic_nand_acqrel :: proc(dst; ^$T, val: $T) -> T ---
atomic_nand_relaxed :: proc(dst; ^$T, val: $T) -> T ---
atomic_or :: proc(dst; ^$T, val: $T) -> T ---
atomic_or_acq :: proc(dst; ^$T, val: $T) -> T ---
atomic_or_rel :: proc(dst; ^$T, val: $T) -> T ---
atomic_or_acqrel :: proc(dst; ^$T, val: $T) -> T ---
atomic_or_relaxed :: proc(dst; ^$T, val: $T) -> T ---
atomic_xor :: proc(dst; ^$T, val: $T) -> T ---
atomic_xor_acq :: proc(dst; ^$T, val: $T) -> T ---
atomic_xor_rel :: proc(dst; ^$T, val: $T) -> T ---
atomic_xor_acqrel :: proc(dst; ^$T, val: $T) -> T ---
atomic_xor_relaxed :: proc(dst; ^$T, val: $T) -> T ---
atomic_add :: proc(dst; ^$T, val: T) -> T ---
atomic_add_acq :: proc(dst; ^$T, val: T) -> T ---
atomic_add_rel :: proc(dst; ^$T, val: T) -> T ---
atomic_add_acqrel :: proc(dst; ^$T, val: T) -> T ---
atomic_add_relaxed :: proc(dst; ^$T, val: T) -> T ---
atomic_sub :: proc(dst; ^$T, val: T) -> T ---
atomic_sub_acq :: proc(dst; ^$T, val: T) -> T ---
atomic_sub_rel :: proc(dst; ^$T, val: T) -> T ---
atomic_sub_acqrel :: proc(dst; ^$T, val: T) -> T ---
atomic_sub_relaxed :: proc(dst; ^$T, val: T) -> T ---
atomic_and :: proc(dst; ^$T, val: T) -> T ---
atomic_and_acq :: proc(dst; ^$T, val: T) -> T ---
atomic_and_rel :: proc(dst; ^$T, val: T) -> T ---
atomic_and_acqrel :: proc(dst; ^$T, val: T) -> T ---
atomic_and_relaxed :: proc(dst; ^$T, val: T) -> T ---
atomic_nand :: proc(dst; ^$T, val: T) -> T ---
atomic_nand_acq :: proc(dst; ^$T, val: T) -> T ---
atomic_nand_rel :: proc(dst; ^$T, val: T) -> T ---
atomic_nand_acqrel :: proc(dst; ^$T, val: T) -> T ---
atomic_nand_relaxed :: proc(dst; ^$T, val: T) -> T ---
atomic_or :: proc(dst; ^$T, val: T) -> T ---
atomic_or_acq :: proc(dst; ^$T, val: T) -> T ---
atomic_or_rel :: proc(dst; ^$T, val: T) -> T ---
atomic_or_acqrel :: proc(dst; ^$T, val: T) -> T ---
atomic_or_relaxed :: proc(dst; ^$T, val: T) -> T ---
atomic_xor :: proc(dst; ^$T, val: T) -> T ---
atomic_xor_acq :: proc(dst; ^$T, val: T) -> T ---
atomic_xor_rel :: proc(dst; ^$T, val: T) -> T ---
atomic_xor_acqrel :: proc(dst; ^$T, val: T) -> T ---
atomic_xor_relaxed :: proc(dst; ^$T, val: T) -> T ---
atomic_xchg :: proc(dst; ^$T, val: $T) -> T ---
atomic_xchg_acq :: proc(dst; ^$T, val: $T) -> T ---
atomic_xchg_rel :: proc(dst; ^$T, val: $T) -> T ---
atomic_xchg_acqrel :: proc(dst; ^$T, val: $T) -> T ---
atomic_xchg_relaxed :: proc(dst; ^$T, val: $T) -> T ---
atomic_xchg :: proc(dst; ^$T, val: T) -> T ---
atomic_xchg_acq :: proc(dst; ^$T, val: T) -> T ---
atomic_xchg_rel :: proc(dst; ^$T, val: T) -> T ---
atomic_xchg_acqrel :: proc(dst; ^$T, val: T) -> T ---
atomic_xchg_relaxed :: proc(dst; ^$T, val: T) -> T ---
atomic_cxchg :: proc(dst: ^$T, old, new: T) -> (T, /*option*/bool) ---
atomic_cxchg_acq :: proc(dst: ^$T, old, new: T) -> (T, /*option*/bool) ---
atomic_cxchg_rel :: proc(dst: ^$T, old, new: T) -> (T, /*option*/bool) ---
atomic_cxchg_acqrel :: proc(dst: ^$T, old, new: T) -> (T, /*option*/bool) ---
atomic_cxchg_relaxed :: proc(dst: ^$T, old, new: T) -> (T, /*option*/bool) ---
atomic_cxchg_failrelaxed :: proc(dst: ^$T, old, new: T) -> (T, /*option*/bool) ---
atomic_cxchg_failacq :: proc(dst: ^$T, old, new: T) -> (T, /*option*/bool) ---
atomic_cxchg_acq_failrelaxed :: proc(dst: ^$T, old, new: T) -> (T, /*option*/bool) ---
atomic_cxchg_acqrel_failrelaxed :: proc(dst: ^$T, old, new: T) -> (T, /*option*/bool) ---
atomic_cxchgweak :: proc(dst: ^$T, old, new: T) -> (T, /*option*/bool) ---
atomic_cxchgweak_acq :: proc(dst: ^$T, old, new: T) -> (T, /*option*/bool) ---
atomic_cxchgweak_rel :: proc(dst: ^$T, old, new: T) -> (T, /*option*/bool) ---
atomic_cxchgweak_acqrel :: proc(dst: ^$T, old, new: T) -> (T, /*option*/bool) ---
atomic_cxchgweak_relaxed :: proc(dst: ^$T, old, new: T) -> (T, /*option*/bool) ---
atomic_cxchgweak_failrelaxed :: proc(dst: ^$T, old, new: T) -> (T, /*option*/bool) ---
atomic_cxchgweak_failacq :: proc(dst: ^$T, old, new: T) -> (T, /*option*/bool) ---
atomic_cxchgweak_acq_failrelaxed :: proc(dst: ^$T, old, new: T) -> (T, /*option*/bool) ---
atomic_cxchgweak_acqrel_failrelaxed :: proc(dst: ^$T, old, new: T) -> (T, /*option*/bool) ---
atomic_cxchg :: proc(dst: ^$T, old, new: T) -> (T, bool) #optional_ok ---
atomic_cxchg_acq :: proc(dst: ^$T, old, new: T) -> (T, bool) #optional_ok ---
atomic_cxchg_rel :: proc(dst: ^$T, old, new: T) -> (T, bool) #optional_ok ---
atomic_cxchg_acqrel :: proc(dst: ^$T, old, new: T) -> (T, bool) #optional_ok ---
atomic_cxchg_relaxed :: proc(dst: ^$T, old, new: T) -> (T, bool) #optional_ok ---
atomic_cxchg_failrelaxed :: proc(dst: ^$T, old, new: T) -> (T, bool) #optional_ok ---
atomic_cxchg_failacq :: proc(dst: ^$T, old, new: T) -> (T, bool) #optional_ok ---
atomic_cxchg_acq_failrelaxed :: proc(dst: ^$T, old, new: T) -> (T, bool) #optional_ok ---
atomic_cxchg_acqrel_failrelaxed :: proc(dst: ^$T, old, new: T) -> (T, bool) #optional_ok ---
atomic_cxchgweak :: proc(dst: ^$T, old, new: T) -> (T, bool) #optional_ok ---
atomic_cxchgweak_acq :: proc(dst: ^$T, old, new: T) -> (T, bool) #optional_ok ---
atomic_cxchgweak_rel :: proc(dst: ^$T, old, new: T) -> (T, bool) #optional_ok ---
atomic_cxchgweak_acqrel :: proc(dst: ^$T, old, new: T) -> (T, bool) #optional_ok ---
atomic_cxchgweak_relaxed :: proc(dst: ^$T, old, new: T) -> (T, bool) #optional_ok ---
atomic_cxchgweak_failrelaxed :: proc(dst: ^$T, old, new: T) -> (T, bool) #optional_ok ---
atomic_cxchgweak_failacq :: proc(dst: ^$T, old, new: T) -> (T, bool) #optional_ok ---
atomic_cxchgweak_acq_failrelaxed :: proc(dst: ^$T, old, new: T) -> (T, bool) #optional_ok ---
atomic_cxchgweak_acqrel_failrelaxed :: proc(dst: ^$T, old, new: T) -> (T, bool) #optional_ok ---
// Constant type tests
@@ -93,6 +136,7 @@ type_is_string :: proc($T: typeid) -> bool ---
type_is_typeid :: proc($T: typeid) -> bool ---
type_is_any :: proc($T: typeid) -> bool ---
type_is_endian_platform :: proc($T: typeid) -> bool ---
type_is_endian_little :: proc($T: typeid) -> bool ---
type_is_endian_big :: proc($T: typeid) -> bool ---
type_is_unsigned :: proc($T: typeid) -> bool ---
@@ -101,27 +145,43 @@ type_is_ordered :: proc($T: typeid) -> bool ---
type_is_ordered_numeric :: proc($T: typeid) -> bool ---
type_is_indexable :: proc($T: typeid) -> bool ---
type_is_sliceable :: proc($T: typeid) -> bool ---
type_is_simple_compare :: proc($T: typeid) -> bool --- // easily compared using memcmp
type_is_comparable :: proc($T: typeid) -> bool ---
type_is_simple_compare :: proc($T: typeid) -> bool --- // easily compared using memcmp (== and !=)
type_is_dereferenceable :: proc($T: typeid) -> bool ---
type_is_valid_map_key :: proc($T: typeid) -> bool ---
type_is_named :: proc($T: typeid) -> bool ---
type_is_pointer :: proc($T: typeid) -> bool ---
type_is_opaque :: proc($T: typeid) -> bool ---
type_is_array :: proc($T: typeid) -> bool ---
type_is_slice :: proc($T: typeid) -> bool ---
type_is_dynamic_array :: proc($T: typeid) -> bool ---
type_is_map :: proc($T: typeid) -> bool ---
type_is_struct :: proc($T: typeid) -> bool ---
type_is_union :: proc($T: typeid) -> bool ---
type_is_enum :: proc($T: typeid) -> bool ---
type_is_proc :: proc($T: typeid) -> bool ---
type_is_bit_field :: proc($T: typeid) -> bool ---
type_is_bit_field_value :: proc($T: typeid) -> bool ---
type_is_bit_set :: proc($T: typeid) -> bool ---
type_is_simd_vector :: proc($T: typeid) -> bool ---
type_is_named :: proc($T: typeid) -> bool ---
type_is_pointer :: proc($T: typeid) -> bool ---
type_is_array :: proc($T: typeid) -> bool ---
type_is_enumerated_array :: proc($T: typeid) -> bool ---
type_is_slice :: proc($T: typeid) -> bool ---
type_is_dynamic_array :: proc($T: typeid) -> bool ---
type_is_map :: proc($T: typeid) -> bool ---
type_is_struct :: proc($T: typeid) -> bool ---
type_is_union :: proc($T: typeid) -> bool ---
type_is_enum :: proc($T: typeid) -> bool ---
type_is_proc :: proc($T: typeid) -> bool ---
type_is_bit_set :: proc($T: typeid) -> bool ---
type_is_simd_vector :: proc($T: typeid) -> bool ---
type_has_nil :: proc($T: typeid) -> bool ---
type_has_nil :: proc($T: typeid) -> bool ---
type_is_specialization_of :: proc($T, $S: typeid) -> bool ---
type_is_variant_of :: proc($U, $V: typeid) -> bool where type_is_union(U) ---
type_has_field :: proc($T: typeid, $name: string) -> bool ---
type_proc_parameter_count :: proc($T: typeid) -> int where type_is_proc(T) ---
type_proc_return_count :: proc($T: typeid) -> int where type_is_proc(T) ---
type_proc_parameter_type :: proc($T: typeid, index: int) -> typeid where type_is_proc(T) ---
type_proc_return_type :: proc($T: typeid, index: int) -> typeid where type_is_proc(T) ---
type_polymorphic_record_parameter_count :: proc($T: typeid) -> typeid ---
type_polymorphic_record_parameter_value :: proc($T: typeid, index: int) -> $V ---
type_field_index_of :: proc($T: typeid, $name: string) -> uintptr ---
type_equal_proc :: proc($T: typeid) -> (equal: proc "contextless" (rawptr, rawptr) -> bool) where type_is_comparable(T) ---
type_hasher_proc :: proc($T: typeid) -> (hasher: proc "contextless" (data: rawptr, seed: uintptr) -> uintptr) where type_is_comparable(T) ---
+194
View File
@@ -0,0 +1,194 @@
package io
to_reader :: proc(s: Stream) -> (r: Reader, ok: bool = true) {
r.stream = s;
if s.stream_vtable == nil || s.impl_read == nil {
ok = false;
}
return;
}
to_writer :: proc(s: Stream) -> (w: Writer, ok: bool = true) {
w.stream = s;
if s.stream_vtable == nil || s.impl_write == nil {
ok = false;
}
return;
}
to_closer :: proc(s: Stream) -> (c: Closer, ok: bool = true) {
c.stream = s;
if s.stream_vtable == nil || s.impl_close == nil {
ok = false;
}
return;
}
to_flusher :: proc(s: Stream) -> (f: Flusher, ok: bool = true) {
f.stream = s;
if s.stream_vtable == nil || s.impl_flush == nil {
ok = false;
}
return;
}
to_seeker :: proc(s: Stream) -> (seeker: Seeker, ok: bool = true) {
seeker.stream = s;
if s.stream_vtable == nil || s.impl_seek == nil {
ok = false;
}
return;
}
to_read_writer :: proc(s: Stream) -> (r: Read_Writer, ok: bool = true) {
r.stream = s;
if s.stream_vtable == nil || s.impl_read == nil || s.impl_write == nil {
ok = false;
}
return;
}
to_read_closer :: proc(s: Stream) -> (r: Read_Closer, ok: bool = true) {
r.stream = s;
if s.stream_vtable == nil || s.impl_read == nil || s.impl_close == nil {
ok = false;
}
return;
}
to_read_write_closer :: proc(s: Stream) -> (r: Read_Write_Closer, ok: bool = true) {
r.stream = s;
if s.stream_vtable == nil || s.impl_read == nil || s.impl_write == nil || s.impl_close == nil {
ok = false;
}
return;
}
to_read_write_seeker :: proc(s: Stream) -> (r: Read_Write_Seeker, ok: bool = true) {
r.stream = s;
if s.stream_vtable == nil || s.impl_read == nil || s.impl_write == nil || s.impl_seek == nil {
ok = false;
}
return;
}
to_write_flusher :: proc(s: Stream) -> (w: Write_Flusher, ok: bool = true) {
w.stream = s;
if s.stream_vtable == nil || s.impl_write == nil || s.impl_flush == nil {
ok = false;
}
return;
}
to_write_flush_closer :: proc(s: Stream) -> (w: Write_Flush_Closer, ok: bool = true) {
w.stream = s;
if s.stream_vtable == nil || s.impl_write == nil || s.impl_flush == nil || s.impl_close == nil {
ok = false;
}
return;
}
to_reader_at :: proc(s: Stream) -> (r: Reader_At, ok: bool = true) {
r.stream = s;
if s.stream_vtable == nil || s.impl_read_at == nil {
ok = false;
}
return;
}
to_writer_at :: proc(s: Stream) -> (w: Writer_At, ok: bool = true) {
w.stream = s;
if s.stream_vtable == nil || s.impl_write_at == nil {
ok = false;
}
return;
}
to_reader_from :: proc(s: Stream) -> (r: Reader_From, ok: bool = true) {
r.stream = s;
if s.stream_vtable == nil || s.impl_read_from == nil {
ok = false;
}
return;
}
to_writer_to :: proc(s: Stream) -> (w: Writer_To, ok: bool = true) {
w.stream = s;
if s.stream_vtable == nil || s.impl_write_to == nil {
ok = false;
}
return;
}
to_write_closer :: proc(s: Stream) -> (w: Write_Closer, ok: bool = true) {
w.stream = s;
if s.stream_vtable == nil || s.impl_write == nil || s.impl_close == nil {
ok = false;
}
return;
}
to_write_seeker :: proc(s: Stream) -> (w: Write_Seeker, ok: bool = true) {
w.stream = s;
if s.stream_vtable == nil || s.impl_write == nil || s.impl_seek == nil {
ok = false;
}
return;
}
to_byte_reader :: proc(s: Stream) -> (b: Byte_Reader, ok: bool = true) {
b.stream = s;
if s.stream_vtable == nil || s.impl_read_byte == nil {
ok = false;
if s.stream_vtable != nil && s.impl_read != nil {
ok = true;
}
}
return;
}
to_byte_scanner :: proc(s: Stream) -> (b: Byte_Scanner, ok: bool = true) {
b.stream = s;
if s.stream_vtable != nil {
if s.impl_unread_byte == nil {
ok = false;
return;
}
if s.impl_read_byte != nil {
ok = true;
} else if s.impl_read != nil {
ok = true;
} else {
ok = false;
}
}
return;
}
to_byte_writer :: proc(s: Stream) -> (b: Byte_Writer, ok: bool = true) {
b.stream = s;
if s.stream_vtable == nil || s.impl_write_byte == nil {
ok = false;
if s.stream_vtable != nil && s.impl_write != nil {
ok = true;
}
}
return;
}
to_rune_reader :: proc(s: Stream) -> (r: Rune_Reader, ok: bool = true) {
r.stream = s;
if s.stream_vtable == nil || s.impl_read_rune == nil {
ok = false;
if s.stream_vtable != nil && s.impl_read != nil {
ok = true;
}
}
return;
}
to_rune_scanner :: proc(s: Stream) -> (r: Rune_Scanner, ok: bool = true) {
r.stream = s;
if s.stream_vtable != nil {
if s.impl_unread_rune == nil {
ok = false;
return;
}
if s.impl_read_rune != nil {
ok = true;
} else if s.impl_read != nil {
ok = true;
} else {
ok = false;
}
} else {
ok = false;
}
return;
}

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