Commit Graph

29 Commits

Author SHA1 Message Date
Andrew Kelley
d5bbd74871
allow C pointers to have alignment
clang/gcc support pointer alignment attribute:
https://clang.llvm.org/docs/AttributeReference.html#align-value
2019-02-14 20:04:13 -05:00
Andrew Kelley
cc7060d0d9
compile error for C pointer with align attribute
See #1059
2019-02-14 20:02:29 -05:00
Andrew Kelley
6769183a9d
fix implicit cast error unions with non-optional to optional pointer
and update self hosted compiler for C pointers

See #1059
2019-02-14 15:48:28 -05:00
Andrew Kelley
6f05e8d1be
implicit casting between C pointer and optional non-C pointer
See #1059
2019-02-12 01:38:11 -05:00
Andrew Kelley
069fc1a269
peer type resolution with C pointers
See #1059
2019-02-11 19:21:59 -05:00
Andrew Kelley
57a7ab0d33
comptime support for pointer arithmetic with hard coded addresses 2019-02-11 19:12:01 -05:00
Andrew Kelley
90b8cd4a45
add C pointer type to @typeInfo
See #1059
2019-02-11 16:07:40 -05:00
Andrew Kelley
342bca7f46
C pointer comparison and arithmetic
See #1059
2019-02-11 15:31:09 -05:00
Andrew Kelley
73e8e46257
casting between C pointers and normal pointers
See #1059
2019-02-10 01:11:40 -05:00
Andrew Kelley
b8cbe3872e
added C pointer type and implicit int-to-ptr for this type
See #1059
2019-02-10 00:14:30 -05:00
Andrew Kelley
caf672c495
@truncate: comptime 0 when target type is 0 bits
also if the dest type is a comptime_int, then treat it
as an implicit cast.

also compile error for attempting to truncate undefined

closes #1568
2019-02-09 21:38:34 -05:00
Andrew Kelley
34eb9f18ac
fix not updating debug info type of optional error sets
There's an unfortunate footgun in the current design of error sets.
The debug info type for every error set is the same as the debug info
type of the global error set, which is essentially an enum forward
declaration. The problem is that when we "replace" the forward
declaration with the final value, once we know all the possible errors,
we have to update the pointers of every error set.

So the footgun is that if you ever copy the debug info type of the
global error set, you have to add the address of the pointer to a list
of pointers that need to be updated once we "replace" the forward
declaration. I activated the footgun when I introduced the optimization
that `?anyerror` types are the same size as `anyerror` types (using 0 as
the null value), because I introduced a pointer copy of the global error
set debug info type, but forgot to add it to the list.

I'm sure that there is a better way to code this, which does not have
the footgun, but this commit contains only a fix, not a reworking of the
logic.

closes #1937
2019-02-09 20:41:26 -05:00
Andrew Kelley
373e21bb56
implement vector math safety with ext and trunc 2019-02-09 16:24:29 -05:00
Andrew Kelley
c2db077574
std.debug.assert: remove special case for test builds
Previously, std.debug.assert would `@panic` in test builds,
if the assertion failed. Now, it's always `unreachable`.

This makes release mode test builds more accurately test
the actual code that will be run.

However this requires tests to call `std.testing.expect`
rather than `std.debug.assert` to make sure output is correct.

Here is the explanation of when to use either one, copied from
the assert doc comments:

Inside a test block, it is best to use the `std.testing` module
rather than assert, because assert may not detect a test failure
in ReleaseFast and ReleaseSafe mode. Outside of a test block, assert
is the correct function to use.

closes #1304
2019-02-08 18:23:38 -05:00
Andrew Kelley
f330eebe4b fix using the result of @intCast to u0
closes #1817
2019-02-07 16:02:45 -05:00
Andrew Kelley
8a5d3e2eaf
Merge pull request #1924 from ziglang/tls
Implement Thread Local Variables
2019-02-06 20:21:13 -05:00
Andrew Kelley
b1775ca168
thread local storage working for linux x86_64 2019-02-06 13:48:04 -05:00
Jimmi Holst Christensen
4010f6a11d Added support for vector wrapping mult and sub
* I also merged the code that generates ir for add, sub, and mult
2019-02-05 09:57:11 -05:00
Andrew Kelley
8c6fa982cd
SIMD: array to vector, vector to array, wrapping int add
also vectors and arrays now use the same ConstExprVal representation

See #903
2019-02-04 20:30:00 -05:00
Matthew McAllister
c90c256868 Fix slice concatenation
This was causing an underflow error
2019-02-02 22:22:00 -05:00
Andrew Kelley
545064c1d9
introduce vector type for SIMD
See #903

 * create with `@Vector(len, ElemType)`
 * only wrapping addition is implemented

This feature is far from complete; this is only the beginning.
2019-01-30 23:39:25 -05:00
Andrew Kelley
581edd643f
backport copy elision changes
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.
2019-01-29 22:30:30 -05:00
Jimmi Holst Christensen
8139c5a516
New Zig formal grammar (#1685)
Reverted #1628 and changed the grammar+parser of the language to not allow certain expr where types are expected
2018-11-13 05:08:37 -08:00
Jimmi Holst Christensen
378d3e4403
Solve the return type ambiguity (#1628)
Changed container and initializer syntax
* <container> { ... } -> <container> . { ... }
* <exrp> { ... } -> <expr> . { ...}
2018-10-15 09:51:15 -04:00
Andrew Kelley
9c169f3cf7
C ABI: support returning large structs on x86_64
also panic instead of emitting bad code for returning small structs

See #1481
2018-09-07 20:09:33 -04:00
Andrew Kelley
9017efee22
C ABI: support medium size structs & unions for x86_64 params
See #1481
2018-09-07 18:51:34 -04:00
Andrew Kelley
743b2e4afc
add C ABI test for big unions 2018-09-07 13:51:11 -04:00
Andrew Kelley
be6cccb3a5
stage1: c abi for big struct works 2018-09-07 11:52:57 -04:00
Andrew Kelley
a9a925e500
add C ABI tests 2018-09-06 16:29:35 -04:00