aboutsummaryrefslogtreecommitdiff
path: root/test/cases/cast.zig
AgeCommit message (Collapse)Author
2019-01-29backport copy elision changesAndrew Kelley
This commit contains everything from the copy-elision-2 branch that does not have to do with copy elision directly, but is generally useful for master branch. * All const values know their parents, when applicable, not just structs and unions. * Null pointers in const values are represented explicitly, rather than as a HardCodedAddr value of 0. * Rename "maybe" to "optional" in various code locations. * Separate DeclVarSrc and DeclVarGen * Separate PtrCastSrc and PtrCastGen * Separate CmpxchgSrc and CmpxchgGen * Represent optional error set as an integer, using the 0 value. In a const value, it uses nullptr. * Introduce type_has_one_possible_value and use it where applicable. * Fix debug builds not setting memory to 0xaa when storing undefined. * Separate the type of a variable from the const value of a variable. * Use copy_const_val where appropriate. * Rearrange structs to pack data more efficiently. * Move test/cases/* to test/behavior/* * Use `std.debug.assertOrPanic` in behavior tests instead of `std.debug.assert`. * Fix outdated slice syntax in docs.
2018-11-18fix assertion failure related to @intToEnumAndrew Kelley
2018-11-18all numbers with comptime known values implicitly castAndrew Kelley
to all number types. If the value does not fit, a compile error is emitted. closes #422 closes #1712
2018-11-13New Zig formal grammar (#1685)Jimmi Holst Christensen
Reverted #1628 and changed the grammar+parser of the language to not allow certain expr where types are expected
2018-10-26remove @minValue,@maxValue; add std.math.minInt,maxIntAndrew Kelley
closes #1466 closes #1476
2018-10-15remove implicit cast from T to *const TAndrew Kelley
closes #1465
2018-10-15Solve the return type ambiguity (#1628)Jimmi Holst Christensen
Changed container and initializer syntax * <container> { ... } -> <container> . { ... } * <exrp> { ... } -> <expr> . { ...}
2018-09-26fix implicit casting to *c_voidAndrew Kelley
closes #1588 also some small std lib changes regarding posix sockets and one doc typo fix
2018-09-20better string literal caching implementationAndrew Kelley
We were caching the ConstExprValue of string literals, which works if you can never modify ConstExprValues. This premise is broken with `comptime var ...`. So I implemented an optimization in ConstExprValue arrays, where it stores a `Buf *` directly rather than an array of ConstExprValues for the elements, and then similar to array of undefined, it is expanded into the canonical form when necessary. However many operations can happen directly on the `Buf *`, which is faster. Furthermore, before a ConstExprValue array is expanded into canonical form, it removes itself from the string literal cache. This fixes the issue, because before an array element is modified it would have to be expanded. closes #1076
2018-09-13fix assertion failure on compile-time `@intToPtr` of functionAndrew Kelley
2018-09-13remove `this`. add `@This()`.Andrew Kelley
closes #1283
2018-09-05allow comptime_int to @floatToIntAndrew Kelley
2018-09-03ability to @ptrCast to *voidAndrew Kelley
fixes #960
2018-08-27minor fixupsAndrew Kelley
2018-08-27Allow implicit cast from *T and [*]T to ?*c_voidraulgrell
2018-08-22allow implicit cast from *[N]T to ?[*]T (#1398)Raul Leal
* allow implicit cast from *[N]T to ?[*]T
2018-07-16allow implicit cast of undefined to optionalAndrew Kelley
2018-06-27add f16 typeBen Noordhuis
Add support for half-precision floating point operations. Introduce `__extendhfsf2` and `__truncsfhf2` in std/special/compiler_rt. Add `__gnu_h2f_ieee` and `__gnu_f2h_ieee` as aliases that are used in Windows builds. The logic in std/special/compiler_rt/extendXfYf2.zig has been reworked and can now operate on 16 bits floating point types. `extendXfYf2()` and `truncXfYf2()` are marked `inline` to work around a not entirely understood stack alignment issue on Windows when calling the f16 versions of the builtins. closes #1122
2018-06-27scope variables in floating point cast testsBen Noordhuis
Fixes a bug where the result of a @floatCast wasn't actually checked; it was checking the result from the previous @floatCast.
2018-06-19`@floatToInt` now has safety-checked undefined behaviorAndrew Kelley
when the integer part does not fit in the destination integer type * Also fix incorrect safety triggered for integer casting an `i32` to a `u7`. closes #1138 * adds compiler-rt function: `__floatuntidf`
2018-06-18remove error to/from int casting syntax; add `@errorToInt`/`@intToError`Andrew Kelley
See #1061
2018-06-18remove []u8 casting syntax. add `@bytesToSlice` and `@sliceToBytes`Andrew Kelley
See #1061
2018-06-18fix compiler crash when using @intToFloat with float literalAndrew Kelley
closes #1132
2018-06-17remove integer and float casting syntaxAndrew Kelley
* add `@intCast` * add `@floatCast` * add `@floatToInt` * add `@intToFloat` See #1061
2018-06-16don't automatically take pointer when passing by non-copying valueAndrew Kelley
this commit does not have all tests passing
2018-06-10breaking syntax change: orelse keyword instead of ?? (#1096)Andrew Kelley
use the `zig-fmt-optional-default` branch to have zig fmt automatically do the changes. closes #1023
2018-06-09breaking syntax change: ??x to x.? (#1095)Andrew Kelley
See #1023 This also renames Nullable/Maybe to Optional
2018-06-09nullable pointers follow const-casting rulesAndrew Kelley
any *T -> ?*T cast is allowed implicitly, even when it occurs deep inside the type, and the cast is a no-op at runtime. in order to add this I had to make the comptime value representation of nullable pointers the same as the comptime value representation of normal pointers, so that we don't have to do any recursive transformation of values when doing this kind of cast.
2018-06-07add implicit casts from `*[N]T`Andrew Kelley
* to `[]T` * to `[*]T` See #770
2018-05-31use * for pointer type instead of &Andrew Kelley
See #770 To help automatically translate code, see the zig-fmt-pointer-reform-2 branch. This will convert all & into *. Due to the syntax ambiguity (which is why we are making this change), even address-of & will turn into *, so you'll have to manually fix thes instances. You will be guaranteed to get compile errors for them - expected 'type', found 'foo'
2018-05-29run zig fmt on the codebaseAndrew Kelley
See #1003
2018-05-01behavior tests passing with new pointer deref syntaxAndrew Kelley
2018-04-30[breaking] delete ptr deref prefix opAndrew Kelley
start using zig-fmt-pointer-reform branch build of zig fmt to fix code to use the new syntax all of test/cases/* are processed, but there are more left to be done - all the std lib used by the behavior tests
2018-03-06ptrCast builtin now gives an error for removing const qualifierAndrew Kelley
closes #384
2018-02-26allow implicit cast from &const to ?&const &constBen Noordhuis
Allow implicit casts from n-th degree const pointers to nullable const pointers of degree n+1. That is: fn f() void { const s = S {}; const p = &s; g(p); // Works. g(&p); // So does this. } fn g(_: ?&const &const S) void { // Nullable 2nd degree const ptr. } Fixes #731 some more.
2018-02-23allow implicit cast from `S` to `?&const S`Ben Noordhuis
Allow implicit casts from container types to nullable const pointers to said container type. That is: fn f() void { const s = S {}; g(s); // Works. g(&s); // So does this. } fn g(_: ?&const S) void { // Nullable const pointer. } Fixes #731.
2018-02-02*WI* error sets - basic support workingAndrew Kelley
2018-01-31*WIP* error sets converting std libAndrew Kelley
2018-01-25syntax: functions require return type. remove `->`Andrew Kelley
The purpose of this is: * Only one way to do things * Changing a function with void return type to return a possible error becomes a 1 character change, subtly encouraging people to use errors. See #632 Here are some imperfect sed commands for performing this update: remove arrow: ``` sed -i 's/\(\bfn\b.*\)-> /\1/g' $(find . -name "*.zig") ``` add void: ``` sed -i 's/\(\bfn\b.*\))\s*{/\1) void {/g' $(find ../ -name "*.zig") ``` Some cleanup may be necessary, but this should do the bulk of the work.
2018-01-09remove %% prefix operatorAndrew Kelley
See #632 closes #545 closes #510 this makes #651 higher priority
2018-01-02ir: new pass iteration strategyAndrew Kelley
Before: * IR basic blocks are in arbitrary order * when doing an IR pass, when a block is encountered, code must look at all the instructions in the old basic block, determine what blocks are referenced, and queue up those old basic blocks first. * This had a bug (See #667) Now: * IR basic blocks are required to be in an order that guarantees they will be referenced by a branch, before any instructions within are referenced. ir pass1 is updated to meet this constraint. * When doing an IR pass, we iterate over old basic blocks in the order they appear. Blocks which have not been referenced are discarded. * After the pass is complete, we must iterate again to look for old basic blocks which now point to incomplete new basic blocks, due to comptime code generation. * This last part can probably be optimized - most of the time we don't need to iterate over the basic block again. closes #667
2017-12-22explicitly return from blocksAndrew Kelley
instead of last statement being expression value closes #629
2017-08-30align syntax: align(4) instead of align 4Andrew Kelley
closes #37
2017-08-29more alignment improvementsAndrew Kelley
* add alignment capability for fn protos * add @alignCast * fix some ast rendering code * fix some ir rendering code * add error for pointer cast increasing alignment * update allocators in std to correctly align See #37
2017-08-25implement comptime bitcasting from arrayAndrew Kelley
2017-08-25fix some casts on const data causing segfaultAndrew Kelley
2017-08-17fix bitCast for big integersAndrew Kelley
and make bigfloat use __float128
2017-08-08add ptrToInt builtin, remove usize(ptr) castAndrew Kelley
closes #415
2017-08-07add ability to explicitly cast float to integerAndrew Kelley
closes #414
2017-06-17fix peer type resolution for array and errorAndrew Kelley
closes #388