Vexu
6b61fcddfa
fix translate-c arrow deref
2019-11-06 13:58:55 -05:00
Vexu
57aa8997bd
fix escape sequence rendering
2019-07-23 14:49:19 -04:00
Andrew Kelley
6fe3b20962
Merge branch 'translate-c-userland' of https://github.com/hryx/zig into hryx-translate-c-userland
2019-07-15 22:19:54 -04:00
Andrew Kelley
c0489abcdb
translate-c: fix incorrectly translated double function pointer
...
closes #2887
2019-07-13 12:38:10 -04:00
Andrew Kelley
4e58855a4a
translate-c: better detection of pointer to struct demoted to opaque
2019-07-12 12:11:26 -04:00
hryx
cc74bf5136
Translate IntegralCast; add stage2 test coverage
2019-06-27 23:12:33 -07:00
hryx
b2e06c3bf4
Observe translate mode in stage2
2019-06-23 14:32:45 -07:00
hryx
226a23d977
stage1: always render space after `fn` like stage2
2019-06-23 12:46:17 -07:00
Andrew Kelley
10e9d47b49
stage2 translate-c: implement functions with no prototype
...
stage1 translate-c actually has this wrong. When exporting a function,
it's ok to use empty parameters. But for prototypes, "no prototype"
means that it has to be emitted as a function that accepts anything,
e.g. extern fn foo(...) void;
See #1964
2019-05-11 12:09:11 -04:00
Andrew Kelley
5f4c3e6557
stage2 translate-c: simple function definitions
...
See #1964
2019-05-10 23:35:46 -04:00
Andrew Kelley
dbb5da14f4
stage2 translate-c: builtin types and pub
...
See #1964
2019-05-10 17:56:00 -04:00
Andrew Kelley
82219b1fd5
translate-c: better handling of restore points
2019-05-10 17:44:47 -04:00
Andrew Kelley
a6f7a9ce2b
translate-c: we have our first test of self-hosted
...
See #1964
2019-05-10 16:03:54 -04:00
Andrew Kelley
eb65410b62
translate-c: enough C tokenization/parsing to handle shifting in macros
...
See #2451
2019-05-09 12:48:38 -04:00
Andrew Kelley
62065a9aea
translate-c: handle int to ptr and ptr to int casting
...
See #2451
2019-05-09 12:17:23 -04:00
Andrew Kelley
e3542196c0
translate-c: NULL pointers translate to `null`
...
See #1967
2019-05-08 19:21:54 -04:00
LemonBoy
77383f968d
translate-c: Emit @ptrCast + @alignPtr sequence
...
Avoid producing Zig code that doesn't compile due to mismatched
alignments between pointers.
Always emit a @alignOf instead of hardcoding the alignment value
returned by LLVM for portability sake of the generated code.
2019-04-29 21:30:19 -04:00
LemonBoy
ab424bbb35
translate-c: Add test for implicit casts
2019-04-22 22:23:41 +02:00
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
Andrew Kelley
7066283004
translate-c: support const ptr initializer
2017-11-28 23:44:45 -05:00
Andrew Kelley
26096e79d1
translate-c: fix clobbering primitive types
2017-11-28 03:17:28 -05:00
Andrew Kelley
e745544dac
translate-c: detect macros referencing field lookup
...
as fn calls which assert the fn ptr is non-null
2017-11-28 02:58:51 -05:00
Andrew Kelley
f537c51f25
Merge branch 'c-field-expr' of https://github.com/dimenus/zig into dimenus-c-field-expr
2017-11-28 00:44:16 -05:00
Mason Remaley
3e8fd24547
Implements translation for the prefix not operator ( #628 )
2017-11-27 21:00:05 -05:00
Ryan Saunderson
57049b95b3
Resolving merge w/ upstream master
2017-11-27 11:42:48 -06:00
dimenus
04472f57be
Added support for exporting of C field expressions
2017-11-27 11:23:14 -06:00
Andrew Kelley
671183fa9a
translate-c: support pointer casting
...
also avoid some unnecessary casts
2017-11-26 20:05:55 -05:00
Andrew Kelley
93fac5f257
translate-c: support variable name shadowing
2017-11-26 17:30:43 -05:00
Andrew Kelley
9a8545d590
translate-c: fix translation when no default switch case
2017-11-26 16:03:56 -05:00
Andrew Kelley
aa2ca3f02c
translate-c: better way to translate switch
...
previously `continue` would be handled incorrectly
2017-11-26 15:58:49 -05:00
Andrew Kelley
1b0e90f70b
translate-c supports switch statements
2017-11-26 00:58:11 -05:00
Andrew Kelley
df0e875856
translate-c: introduce the concept of scopes
...
in preparation to implement switch and solve variable name collisions
2017-11-25 20:34:05 -05:00
Andrew Kelley
b390929826
translate-c supports break and continue
2017-11-25 11:56:17 -05:00
Andrew Kelley
bf20b260ce
translate-c supports for loops
2017-11-25 00:57:48 -05:00
Andrew Kelley
18eb3c5f90
translate-c supports returning void
2017-11-25 00:25:47 -05:00
Andrew Kelley
40480c7cdc
translate-c supports string literals
2017-11-24 19:26:05 -05:00
Andrew Kelley
68312afcdf
translate-c: support pre increment and decrement operators
2017-11-24 16:36:39 -05:00
Andrew Kelley
5a25505668
rename "parsec" to "translate-c"
2017-11-24 14:56:05 -05:00