Commit Graph

2157 Commits

Author SHA1 Message Date
LemonBoy
50754ba336 Fix ICE when BoundFn are passed as parameters
Closes #4022
Closes #3699
2020-01-14 13:09:23 -05:00
LemonBoy
cae93c860b Allow switching on pointer types
Closes #4074
2020-01-13 22:18:49 +01:00
LemonBoy
84930fec27 Validate switch range endpoints 2020-01-13 21:45:16 +01:00
LemonBoy
54b11f66a9 Fix compiler-error regression 2020-01-13 08:49:32 +01:00
LemonBoy
34cdcb13c0 Fix @call being too eager to resolve the fn argument
Closes #4020
2020-01-12 23:51:18 +01:00
LemonBoy
c96131f30c Propagate errors in for loop bodies
Closes #3819
2020-01-12 12:49:12 -05:00
LemonBoy
34ae1d9aa8 Fix unsafe cast in translate_c
* Handle EmptyDecls to clean up the generated code

Closes #4143
2020-01-11 15:51:10 -05:00
LemonBoy
570ffc470e Handle forward-declared functions
Closes #4130
2020-01-10 16:34:40 -05:00
travisstaloch
3f98756f85 Fix translation of signed array indices (#4113)
* cast only if the index is long long or signed
* cast long long to usize rather than c_uint

closes #4075
2020-01-10 00:08:24 -05:00
Andrew Kelley
5e345ff0ee
Merge pull request #3955 from LemonBoy/fix-1528
Pointer arithmetic affects the alignment factor
2020-01-09 13:53:56 -05:00
LemonBoy
5ab5de89c0 New @export() handling
Use a struct as second parameter to be future proof (and also allows to
specify default values for the parameters)

Closes #2679 as it was just a matter of a few lines of code.
2020-01-09 13:43:06 -05:00
Rocknest
4613e4d15f Fix C struct with function pointer member and typedefs mistranslated (#4122)
fixes #4118
2020-01-09 13:38:31 -05:00
LemonBoy
c51b79c56e Correct alignment calculation for runtime addends 2020-01-09 11:56:45 +01:00
LemonBoy
7ea7842ed0 Fix calculation of new alignment factor 2020-01-08 21:02:05 +01:00
LemonBoy
e134e6c994 Pointer arithmetic affects the alignment factor
Closes #1528
2020-01-08 20:03:03 +01:00
LemonBoy
6a72eb1541 Use abort() instead of assert()
Let's see if the Windows/MacOS CI like this more...
2020-01-08 10:31:11 +01:00
LemonBoy
5b34697b21 Cast integer literals to their specified type 2020-01-08 10:19:04 +01:00
LemonBoy
fd7e69a2c0 More translate-c fixes
* Translate OpaqueValueExpr
* Translate BinaryConditionalOperator
* Fix translation of boolean->int casts
* Reoder some tokens to avoid rendering errors
2020-01-08 08:43:37 +01:00
LemonBoy
2a5c622e65 Fix crash with unresolved loc
Fixes #4099
2020-01-07 18:16:17 -05:00
LemonBoy
3607d9ee68 Fix crash in struct initializer evaluation
Closes #4100
2020-01-07 15:06:22 -05:00
Andrew Kelley
4e4ba6c3e1
test harness: show annotated case name when translate-c test fails 2020-01-07 13:40:17 -05:00
via
9390e8b848 Preserve packed attribute in C translated struct (#4085)
* Preserve packed attribute in C translated struct

* Add tests for packed C struct
2020-01-07 02:36:07 -05:00
Andrew Kelley
8492c46ade
add test case for already fixed bug
closes #2655
2020-01-06 23:03:07 -05:00
LemonBoy
8c640b3e60 Prevent bitCast to enum types
Stop the user from creating invalid enum values.
2020-01-06 19:36:17 -05:00
LemonBoy
7e7d0e1ffa
Better handling of decayed arrays to pointers 2020-01-06 19:32:53 -05:00
Andrew Kelley
baaef7ed97
Merge pull request #4083 from LemonBoy/better-stdbool
Better _Bool translation
2020-01-06 19:21:55 -05:00
LemonBoy
62413da9d3
Add run-translated-c test & fix one more edge case 2020-01-06 19:17:47 -05:00
LemonBoy
2da9e0060b
Add explanation about weird clang behavior on windows 2020-01-06 19:17:47 -05:00
LemonBoy
1dc25d7550
Translate anonymous union/struct 2020-01-06 19:17:47 -05:00
Tadeo Kondrak
f83b02a581 translate-c: use @intToPtr to cast away qualifiers 2020-01-06 19:09:49 -05:00
Andrew Kelley
be2483c576
fix test suite regressions 2020-01-06 18:20:31 -05:00
Andrew Kelley
5ada610e09
update translate-c and tests for new extern/callconv syntax 2020-01-06 17:54:16 -05:00
Andrew Kelley
3b5c71d2a5
fix regression with @TypeInfo 2020-01-06 17:13:45 -05:00
Andrew Kelley
53913acaf7
zig fmt and update extern fn to callconv(.C) 2020-01-06 15:34:50 -05:00
Andrew Kelley
0a9daeb37e
Merge branch 'cc-work' of https://github.com/LemonBoy/zig into LemonBoy-cc-work 2020-01-06 14:07:56 -05:00
LemonBoy
eca294cd23 Add run-translated-c test 2020-01-06 00:18:26 +01:00
LemonBoy
cd39f6df95 Better _Bool translation 2020-01-06 00:12:18 +01:00
Andrew Kelley
c30106c906
add test case to cover already-solved bug
closes #2401
2020-01-05 17:42:03 -05:00
LemonBoy
6ff70d3c31 Better InitListExpr translation 2020-01-05 17:39:29 -05:00
Andrew Kelley
d7bff05098
Merge pull request #4064 from ziglang/fix-4054
use @intCast instead of @as for shift rhs
2020-01-05 15:01:21 -05:00
Andrew Kelley
a0ca34979e
Merge pull request #4053 from ziglang/test-run-translated-c
add test harness for "run translated C" tests
2020-01-05 14:50:02 -05:00
Andrew Kelley
242f5d10d5
fix test-gen-h and test-compile-errors regression 2020-01-05 13:08:18 -05:00
Andrew Kelley
157b8e6889
fix test-stack-traces regression 2020-01-05 02:35:52 -05:00
Andrew Kelley
a690a5085d
rework and improve some of the zig build steps
* `RunStep` moved to lib/std/build/run.zig and gains ability to compare
   output and exit code against expected values. Multiple redundant
   locations in the test harness code are replaced to use `RunStep`.
 * `WriteFileStep` moved to lib/std/build/write_file.zig and gains
   ability to write more than one file into the cache directory, for
   when the files need to be relative to each other. This makes
   usage of `WriteFileStep` no longer problematic when parallelizing
   zig build.
 * Added `CheckFileStep`, which can be used to validate that the output
   of another step produced a valid file. Multiple redundant locations
   in the test harness code are replaced to use `CheckFileStep`.
 * Added `TranslateCStep`. This exposes `zig translate-c` to the build
   system, which is likely to be rarely useful by most Zig users;
   however Zig's own test suite uses it both for translate-c tests and
   for run-translated-c tests.
 * Refactored ad-hoc code to handle source files coming from multiple
   kinds of sources, into `std.build.FileSource`.
 * Added `std.build.Builder.addExecutableFromWriteFileStep`.
 * Added `std.build.Builder.addExecutableSource`.
 * Added `std.build.Builder.addWriteFiles`.
 * Added `std.build.Builder.addTranslateC`.
 * Added `std.build.LibExeObjStep.addCSourceFileSource`.
 * Added `std.build.LibExeObjStep.addAssemblyFileFromWriteFileStep`.
 * Added `std.build.LibExeObjStep.addAssemblyFileSource`.
 * Exposed `std.fs.base64_encoder`.
2020-01-05 02:19:22 -05:00
LemonBoy
a712ea333b Fix translation of for loop init
Closes #4067
2020-01-04 11:49:43 +01:00
LemonBoy
51e430fac0 Fix edge case in hex-literal translation 2020-01-04 11:06:28 +01:00
Josh Wolfe
ac867cc45f fix tests 2020-01-03 20:55:47 -07:00
Andrew Kelley
14fcfe2981
translate-c supports --cache on
this will be used to provide a zig build step
2020-01-03 22:11:19 -05:00
LemonBoy
b91eaba38c Correct evaluation of optional type alignment
The lazy logic was too oversimplified and produced a different result
than the one computed later causing all kinds of problems.

Closes #4013
2020-01-03 17:41:55 -05:00
Andrew Kelley
695c8f756b
add test harness for "run translated C" tests 2020-01-03 00:26:12 -05:00
Andrew Kelley
a90fa45ae1
Merge pull request #4027 from ziglang/fix-float-ops
fix float ops with respect to vectors
2020-01-02 16:10:41 -05:00
Andrew Kelley
fe21d84c94
Merge pull request #4040 from Vexu/translate-c-cast-fixes
Translate c cast fixes
2020-01-02 14:57:48 -05:00
LemonBoy
b0fa2ff853
Translate struct/union initializer expressions 2020-01-02 14:16:39 -05:00
Andrew Kelley
213ff939f1
fix comptime vector float ops and add test coverage
also rename `@ln` to `@log` to match libc convention.
2020-01-02 14:01:48 -05:00
LemonBoy
d09bd3d86c Fix more tests 2020-01-02 19:01:38 +01:00
LemonBoy
0ccac79c8e Implement Thiscall CC 2020-01-02 18:57:08 +01:00
LemonBoy
08a26fea09 translate-c tests 2020-01-02 18:57:07 +01:00
LemonBoy
563d9ebfe5 Implement the callconv() annotation 2020-01-02 18:53:16 +01:00
LemonBoy
d908ca4823
Translate align attribute 2020-01-02 12:33:19 -05:00
LemonBoy
8e89bdfe99
Translate linksection attribute 2020-01-02 12:32:51 -05:00
Vexu
0f1595e72c
translate-c use @enumToInt for global enum values 2020-01-02 18:38:20 +02:00
Andrew Kelley
7bd80f2071
translate-c tests: print clang compile errors on nonzero exit code 2020-01-02 11:12:21 -05:00
Vexu
3dd067fa2b translate-c fix increment rendering issues 2020-01-02 10:47:14 -05:00
LemonBoy
de894f2bde Prefer simple ptrCast between opaque types
Closes #4031
2020-01-02 10:42:26 -05:00
LemonBoy
1e61e5f404 Don't ptrCast a result-location assignment to _
After #4010 doing `_ = @bitCast(...)` triggered a nonsensical compiler
error.
2020-01-02 10:41:11 -05:00
Vexu
f35a963ac5 translate-c properly handle unused var-args 2020-01-02 10:39:52 -05:00
Andrew Kelley
cb56b26900
fix float ops with respect to vectors
also remove the redundant type parameter
2020-01-01 23:27:43 -05:00
Andrew Kelley
576320e6d5
Merge pull request #4025 from ziglang/Vexu-stage-2-cimport
Use self hosted translate-c for cImport
2020-01-01 22:46:46 -05:00
Andrew Kelley
88c5e2a96e
translate-c: don't export inline functions 2020-01-01 20:54:17 -05:00
Andrew Kelley
5ba143e7e3
avoid trying to translate microsoft's stdio.h inline functions
...for now. See #515
2020-01-01 20:33:07 -05:00
Andrew Kelley
ec09b9e5f0
translate-c: prevent name clashing of macros declared after locals 2020-01-01 19:23:46 -05:00
Andrew Kelley
9298b9a4aa
translate-c: prevent name clashing of globals declared after locals 2020-01-01 18:53:08 -05:00
Andrew Kelley
dc28526c6c
translate-c: improve support of integer casting
Widening and truncating integer casting to different signedness
works better now. For example `(unsigned long)-1` is now translated
to zig code that compiles correctly.
2020-01-01 18:10:43 -05:00
Vexu
1b64a5f5f0 fix segfault in bit shift safety check 2020-01-01 13:11:42 -05:00
Andrew Kelley
7b62d5dfd8
translate-c: propagate scope properly in nested assignment 2019-12-31 21:01:49 -05:00
Andrew Kelley
42945a269a
translate-c: better mangling strategy
Block-local identifiers have block-local mangling numbers, and more
consistent mangling is applied within blocks. Parameters, for example,
are treated the same as other block-local variables, and are not mangled
unless they conflict with another name in scope.
2019-12-31 20:39:33 -05:00
Andrew Kelley
5749f706ef
translate-c: non-wrapping operator for pointer arithmetic
According to C11 6.5.6.8, pointer arithmetic may not overflow. In fact,
it may not even go more than 1 past the end of an object, or UB occurs.

This is the same as Zig pointer arithmetic semantics, and so the
`+` and `+=` operators rather than `+%` and `+%=` are appropriate for
C-translated pointer arithmetic.
2019-12-31 17:33:55 -05:00
Andrew Kelley
39ee3bc0ec
Merge branch 'stage-2-cimport' of https://github.com/Vexu/zig into Vexu-stage-2-cimport 2019-12-31 16:55:41 -05:00
Andrew Kelley
73e535e112
Merge pull request #3683 from Vexu/atomic-float
Support floats with some atomic operations
2019-12-30 19:19:05 -05:00
Andrew Kelley
a05150e92d
fix comparing comptime_int against undefined literal
closes #4004
2019-12-30 19:08:57 -05:00
LemonBoy
28a8ded95a Resolve more types as needed
Closes #3994
2019-12-30 17:45:09 -05:00
LemonBoy
c1ee846c22 Fix ptrCast of zero-sized type
Closes #2431
2019-12-30 17:43:58 -05:00
Vexu
950eb81304
translate-c-2 macro comparision ops 2019-12-29 20:19:30 +02:00
frmdstryr
fcc82a219a
Add macro ops 2019-12-29 19:50:45 +02:00
Vexu
621629e20d
translate-c-2 fix assertion failure rendering do while 2019-12-29 17:09:31 +02:00
Vexu
f5e7d2d00c
translate-c fix bugs
Thanks @daurnimator
2019-12-29 14:01:59 +02:00
Vexu
59cc7072e2
translate-c-2 use intCast in most places 2019-12-29 11:04:59 +02:00
Vexu
fceda07f94
use self hosted translate-c for cimports 2019-12-29 11:04:45 +02:00
Vexu
aea46dcd7e
translate-c-2 macro conditional operator 2019-12-28 22:32:18 +02:00
LemonBoy
6070ffc28e Fix crash with forward-declared enums
Closes #3754
2019-12-28 00:57:37 +01:00
LemonBoy
a38704d012 Fix crash in translate-c w/ parameterless fn 2019-12-28 00:50:17 +01:00
Vexu
2252951066
disable test on arm 2019-12-23 11:55:00 +02:00
Vexu
ab7fc33c83
add zig llvm wrapper for atomicrmw 2019-12-23 11:55:00 +02:00
Vexu
8bb1e04449
support some atomic operations with floats 2019-12-23 11:54:47 +02:00
Andrew Kelley
28dbdba37e
Merge pull request #3935 from Vexu/translate-c-2
Translate-c-2 the rest
2019-12-22 16:12:56 -05:00
Vexu
9d31b65b34
translate-c-2 various fixes
- make non-namespaced enums ints
- fix .used compound assignments not being grouped
- fix macro calls with casts producing invalid Zig
2019-12-22 14:38:06 +02:00
Andrew Kelley
290dc5d95b
zig fmt support for slice sentinel syntax 2019-12-21 14:03:36 -05:00
Andrew Kelley
8d73703d52
fix safety for sentinel-slicing floats 2019-12-20 18:28:59 -05:00
Andrew Kelley
8918cb06fc
sentinel slicing improvements
* add runtime safety for slicing pointers, arrays, and slices.
 * slicing without a sentinel value results in non-sentineled slice
 * improved `std.debug.panic` handling of panic-during-panic
2019-12-20 18:28:59 -05:00
Andrew Kelley
26f3c2d061
fix std.mem.addNullByte and implement sentinel slicing
see #3770
2019-12-20 18:28:56 -05:00
LemonBoy
51cbd96820 Fix sentinel value of opaque pointers in typeInfo
Fixes #3888
2019-12-20 15:48:34 -05:00
LemonBoy
f077c3c4cc Fix comptime evaluation of runtime array access
Fix #3951
2019-12-20 15:47:43 -05:00
Vexu
9437d99ae2
translate-c-2 final small fixes 2019-12-20 18:51:44 +02:00
Vexu
e0046b737e
translate-c-2 improve macro escape sequences 2019-12-20 13:50:34 +02:00
Vexu
daeb939210
translate-c-2 fix switch range 2019-12-20 11:35:21 +02:00
Vexu
d172a7335c
translate-c-2 copy parametrs to stack 2019-12-20 00:12:08 +02:00
Vexu
b7f18164f9
translate-c-2 add missing casts 2019-12-19 21:30:51 +02:00
Vexu
61482be153
translate-c-2 improve macro fn ptr caller 2019-12-19 20:58:48 +02:00
Vexu
f837c7c9cd
translate-c-2 compound assign 2019-12-19 16:13:28 +02:00
Vexu
6cd402f1b4
translate-c-2 increments worst-case 2019-12-19 10:48:32 +02:00
Vexu
809deb6ec0
translate-c-2 unary operators common case 2019-12-19 09:56:00 +02:00
Vexu
e4c47e80b4
translate-c-2 unaryexprortypetrait + fixes 2019-12-19 08:28:36 +02:00
Vexu
122a9bad39
translate-c-2 fix some casts 2019-12-19 01:38:42 +02:00
Vexu
d54c288bd3
translate-c-2 function calls 2019-12-18 23:56:39 +02:00
Vexu
c2666c48a4
translate-c-2 array access 2019-12-18 22:57:53 +02:00
Vexu
cf7a5b7a4a
translate-c-2 member access 2019-12-18 22:29:42 +02:00
Vexu
e65b9e8f7b
translate-c-2 stmt expr 2019-12-18 21:20:38 +02:00
Vexu
62bfff5e87
translate-c-2 fix expression grouping bugs 2019-12-18 13:32:19 +02:00
Vexu
f54e7d6c99
translate-c-2 update @kavika13's work to removal of TransResult 2019-12-18 12:47:35 +02:00
Vexu
90eed4172d
Merge remote-tracking branch 'kavika13/master' into translate-c-2 2019-12-18 09:51:40 +02:00
Vexu
21bc3353b8
translate-c-2 character literals and more test fixes 2019-12-18 01:04:01 +02:00
Vexu
6d7025d0c5
translate-c-2 various fixes to get more tests passing 2019-12-17 23:28:13 +02:00
LemonBoy
d8499f7abe Make sure the fields array is always non-null
Fixes #3497
2019-12-17 15:45:22 -05:00
Vexu
a6960b89ed
translate-c-2 fix container type resolution 2019-12-17 22:05:07 +02:00
Vexu
65531c73a9
translate-c-2 switch 2019-12-17 17:19:28 +02:00
Vexu
0283ab8a1a
translate-c-2 conditional operator 2019-12-17 12:06:28 +02:00
Vexu
daa22d42b0
translate-c-2 floats 2019-12-17 11:28:56 +02:00
Vexu
9cda93a24e
translate-c-2 don't shadow primitive types 2019-12-17 10:20:02 +02:00
Vexu
ab6fe57462
translate-c-2 for loops 2019-12-17 01:40:06 +02:00
Vexu
6a3d48353b
translate-c-2 while loops 2019-12-16 22:10:17 +02:00
Andrew Kelley
496f271d17
Merge branch 'shawnl-lessThan'
* always allow integer comparison operations no matter the
   bit width, signedness, or comptime-ness of operands.
   closes #2133
 * implement comparisons for vectors, which returns vector of
   bools.

closes #3001
2019-12-16 11:39:13 -05:00
Andrew Kelley
1cad0acc7e
add behavior test for vector comparison 2019-12-16 11:22:28 -05:00
Vexu
e3f1bfe483
translate-c-2 if statements 2019-12-16 18:19:37 +02:00
Vexu
626562555e
translate-c-2 wors-case assign 2019-12-16 18:19:37 +02:00
Vexu
d9527edfe0
translate-c-2 comma operator 2019-12-16 18:19:24 +02:00
Andrew Kelley
9468d63819
allow comparison of any numeric types 2019-12-16 11:09:10 -05:00
Andrew Kelley
0f09ff4923
Merge pull request #3916 from Vexu/translate-c-2
Translate-c-2 macros
2019-12-16 10:55:32 -05:00
Vexu
04dc0bd0e4
translate-c-2 variable aliasing 2019-12-16 12:45:00 +02:00
Merlyn Morgan-Graham
89ef635b35 Add boolean and, boolean or binary ops in translate-c-2 2019-12-16 01:34:05 -08:00
Merlyn Morgan-Graham
acff2d407b Add bit shift binary ops in translate-c-2 2019-12-16 01:34:04 -08:00
Merlyn Morgan-Graham
c8c89648b0 Add comparison and bitwise binary ops in translate-c-2 2019-12-16 01:34:04 -08:00
Vexu
a37caaa528
translate-c-2 parameter name aliasing 2019-12-16 10:39:31 +02:00
Vexu
620bf695e8
organize tests 2019-12-16 07:43:18 +02:00
Vexu
0f38410ea6
improve extern enum 2019-12-15 19:28:53 -05:00
Vexu
ab60c8e28f
c tokenizer escape sequences 2019-12-16 00:55:50 +02:00
Vexu
9f0e83a571
translate-c-2 macro functions 2019-12-15 23:46:35 +02:00
LemonBoy
59de23dfa0 Don't assume TLS storage has a fixed address
Fixes #3433
2019-12-15 16:23:42 -05:00
LemonBoy
19ddbd9e9e Make sure the address is aligned for intToPtr ops
Closes #773
2019-12-15 14:41:05 -05:00
Vexu
ed2a19dcec
translate-c-2 macro cast 2019-12-15 21:32:30 +02:00
Vexu
57170f9eb6
translate-c-2 macro inline fn 2019-12-15 19:28:34 +02:00