Commit Graph

69 Commits

Author SHA1 Message Date
Andrew Kelley
a17bf219c6
Merge pull request #2069 from ziglang/glibc-assert-translation
Implemented enough of translate-c to translate assert
2019-03-18 14:43:17 -04:00
Jimmi Holst Christensen
9171e7a7c1 More work on ignoring values correctly 2019-03-18 14:55:57 +01:00
Jimmi HC
5ae400fb39 fixed void cast and added the last tests 2019-03-15 19:11:46 +01:00
Jimmi Holst Christensen
a77b2a0810 Implemented enough of translate-c to translate assert
This required the following
* __extention__
* ({})
* Fixing if (0) ; else ;
2019-03-15 16:12:41 +01:00
Jimmi Holst Christensen
3ef9b899e4 workaround for #2043 2019-03-15 11:17:21 +01:00
Sahnvour
9b99356551 translate-c: additional test case for integer suffixes on 0 2019-03-11 16:36:27 -04:00
Sahnvour
fa9fcab620 translate-c: add support for integer suffixes on 0 (zero) litteral inside macro definitions 2019-03-10 14:56:35 -04:00
LemonBoy
e280dce30f Translate parameterless C functions (#1978)
Both FunctionNoProto and FunctionProto are subclasses of FunctionType,
the only difference is that the former is parameterless.
2019-02-18 10:26:45 -05:00
Andrew Kelley
f57182456d
Merge pull request #1898 from Sahnvour/translate-c-arrays
Translate c arrays
2019-02-16 14:07:41 -05:00
Andrew Kelley
d6e0d82c32
translate-c: back to *c_void for opaque types
See #1059
2019-02-14 23:09:31 -05:00
Andrew Kelley
342bca7f46
C pointer comparison and arithmetic
See #1059
2019-02-11 15:31:09 -05:00
Andrew Kelley
d9e01be973
translate-c: use C pointer type everywhere
See #1059
2019-02-11 14:56:59 -05:00
Sahnvour
075fda3c73 translate-c: add tests. Commented for now as the output is currently empty until #646 is fixed. 2019-02-05 20:36:57 +01: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
877036e7ef fix translate-c test expecting incorrect C ABI on windows 2018-09-24 15:14:20 -04:00
Andrew Kelley
004c383292
fix translate-c incorrectly translating negative enum init values
closes #1360
2018-09-24 12:19:16 -04:00
Andrew Kelley
b2917e6be0 Revert "Merge branch 'mtn-translate-c-enum-vals'"
This reverts commit 937b822fa9, reversing
changes made to dd4b13ac03.

Tests failing on Windows.

Re-opens #1360
2018-08-21 20:50:03 -04:00
kristopher tate
b023db2e82 src/translate_c.cpp: correctly bridge llvm::APSInt with Zig BigInt;
ACHTUNG: llvm::APSInt stores an int's sign inside of its getRawData; Internally to Zig we store an integer's sign outside of getRawData! (~aps_int) calls .flip() internally on the raw data to match Zig.

test/translate_c.zig: enum: add wider range of values (u64) to try;
2018-08-20 22:46:11 -04:00
Michael Noronha
7e7e59d881 translate-c: Correctly translate enum init values, addressing #1360 2018-08-20 22:45:19 -04:00
Andrew Kelley
dd4b13ac03 Revert "translate-c: Correctly translate enum init values, addressing #1360 (#1377)"
This reverts commit b8ce8f219c.

Squashing the commits from the pull request resulted in kristopher tate
from being omitted from the authors. A future commit will merge
the code correctly.
2018-08-20 22:39:39 -04:00
Michael Noronha
b8ce8f219c translate-c: Correctly translate enum init values, addressing #1360 (#1377)
* translate-c: Correctly translate enum init values

* translate-c: Test enum initialization

* translate-c: Flip to positive using APSInt builtins

* src/translate_c.cpp: correctly bridge llvm::APSInt with Zig BigInt;

ACHTUNG: llvm::APSInt stores an int's sign inside of its getRawData; Internally to Zig we store an integer's sign outside of getRawData! (~aps_int) calls .flip() internally on the raw data to match Zig.

* test/translate_c.zig: enum: add wider range of values (u64) to try;

closes #1360
2018-08-20 14:29:26 -04:00
Andrew Kelley
63a23e848a translate-c: fix for loops with var init and empty body 2018-08-05 18:40:14 -04:00
Andrew Kelley
387fab60a6 translate-c: fix do while with empty body 2018-08-05 18:32:38 -04:00
Andrew Kelley
c420b234cc translate-c: handle for loop with empty body 2018-08-05 18:18:24 -04:00
Andrew Kelley
aa232089f2 translate-c: fix while loop with no body 2018-08-05 18:06:39 -04:00
Andrew Kelley
77678b2cbc
breaking syntax change: orelse keyword instead of ?? (#1096)
use the `zig-fmt-optional-default` branch to have zig fmt
automatically do the changes.

closes #1023
2018-06-10 01:13:51 -04:00
Andrew Kelley
652f4bdf62 disallow unknown-length pointer to opaque
This also means that translate-c has to detect when a pointer to
opaque is happening, and use `*` instead of `[*]`.

See #1059
2018-06-05 18:03:21 -04:00
Andrew Kelley
96164ce613 disallow single-item pointer indexing
add pointer arithmetic for unknown length pointer
2018-06-04 01:39:57 -04:00
Andrew Kelley
fcbb7426fa use * for pointer type instead of &
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-31 17:28:07 -04:00
Andrew Kelley
0c16cd2d0e run zig fmt on the codebase
See #1003
2018-05-29 04:23:38 -04:00
Andrew Kelley
c38b165db4 all tests passing with postfix deref syntax 2018-05-17 23:21:44 -04:00
Andrew Kelley
bf21747a42 translate-c: fix typedef duplicate definition of variable
closes #998
2018-05-09 20:23:36 -04:00
Jimmi Holst Christensen
1a9403f38a Added better support for none pure enums in tranlate C 2018-05-02 21:50:41 +02:00
Jimmi Holst Christensen
2e010c60ae Translate C now correctly converts ints, floats, ptrs and enums to bools
* Boolean "and" and "or" should also work with these types.
* This new method also simplifies to output code.
2018-03-08 15:34:00 +01:00
Jimmi Holst Christensen
b2887620f3 Translate C will now handle ignored return values 2018-03-08 13:15:30 +01:00
Jimmi Holst Christensen
51b2f1b80b Translate C can now translate switch statements again 2018-03-08 10:29:29 +01:00
Jimmi Holst Christensen
bb80daf509 Ast Render no longer outputs erroneous semicolon
closes #813
2018-03-07 10:39:32 +01:00
Jimmi Holst Christensen
5ab25798e3 We now also use trans_to_bool_expr on bool not 2018-03-06 12:04:14 +01:00
Jimmi Holst Christensen
bf47cf418a expr to bool is now it's own function.
* Now while and for loops work on ints and floats, like if statements
* This fixes the loop problem in #813
2018-03-06 11:57:51 +01:00
Andrew Kelley
3671582c15 syntax: functions require return type. remove ->
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-25 04:10:11 -05:00
Jimmi Holst Christensen
3974b7d31d translate_c can now translate if statements on integers and floats 2018-01-16 15:48:28 +01:00
Jimmi Holst Christensen
f59dcc5546 Fixed tests for undefined variables 2018-01-16 15:21:48 +01:00
Andrew Kelley
d917815d81 explicitly return from blocks
instead of last statement being expression value

closes #629
2017-12-22 00:50:30 -05:00
Andrew Kelley
8bc523219c add labeled loops, labeled break, labeled continue. remove goto
closes #346
closes #630

regression: translate-c can no longer translate switch statements.
after #629 we can ressurect and modify the code to utilize arbitrarily
returning from blocks.
2017-12-20 23:00:19 -05:00
Andrew Kelley
9d9201c3b4 bring back code that uses export and fix tests
partial revert of 1fdebc1dc4
2017-12-19 02:39:43 -05:00
Andrew Kelley
1fdebc1dc4 wip export rewrite 2017-12-18 09:59:57 -05:00
Andrew Kelley
3577a80bb6 translate-c: more complex logic for translating a C cast in a macro 2017-12-08 12:28:21 -05:00
Andrew Kelley
182cf5b8de translate-c: support macros with pointer casting 2017-12-07 12:27:29 -05:00
Andrew Kelley
7729f6cf4e translate-c: support static incomplete array inside function 2017-11-29 21:50:38 -05:00