Commit Graph

12762 Commits

Author SHA1 Message Date
Veikka Tuominen
d8b9fca0b1
translate-c: convert casts and string/array init 2021-02-16 16:40:05 +02:00
Veikka Tuominen
5dac3683c9
translate-c: convert record and enum decls 2021-02-16 16:40:05 +02:00
Veikka Tuominen
bb867b071a
translate-c: convert vardecl and typedef 2021-02-16 16:40:02 +02:00
Veikka Tuominen
f36849fed2
translate-c: convert function translation 2021-02-16 16:37:08 +02:00
Veikka Tuominen
7514c0ad0d
translate-c: unary operator, integers and misc 2021-02-16 16:37:08 +02:00
Veikka Tuominen
f5041caa2e
translate-c: more binaryoperator chagnes, blocks and unary type expressions 2021-02-16 16:37:07 +02:00
Veikka Tuominen
4c0c9b0755
translate-c: convert transBinaryOperator 2021-02-16 16:37:07 +02:00
Veikka Tuominen
d835f5cce5
translate-c: make Node more like Type 2021-02-16 16:37:07 +02:00
Veikka Tuominen
6ecec4c8b7
translate-c: translate C types to stage2 types 2021-02-16 16:37:07 +02:00
Veikka Tuominen
7051ef32bf
translate-c: start creating intermediate AST 2021-02-16 16:37:07 +02:00
Andrew Kelley
4006a3afb3 astgen: update more expression types to new mem layout
additionally introduce a new file to centralize all the data about
builtin functions that we have, including:
 * enum tag identifying the builtin function
 * number of parameters.
 * whether the expression may need a memory location.
 * whether the expression allows an lvalue (currently only true for
   `@field`).
Now there is only one ComptimeStringMap that has this data as the value,
and we dispatch on the enum tag in order to asgen the builtin function.
In particular this simplifies the logic for checking the number of
parameters.

This removes some untested code paths from if and while, which need to
be restored with #7929 in mind.

After this there are only a handful left of expression types to rework
to the new memory layout, and then it will be only compile errors left
to solve.
2021-02-15 22:36:46 -07:00
Isaac Freund
bbf5a4d7c5
zig fmt: fix inferred error union return types 2021-02-15 13:54:48 +01:00
Andrew Kelley
c2b4d51749 astgen: update a handful of expression types to new mem layout
break, continue, blocks, bit_not, negation, identifiers, string
literals, integer literals, inline assembly

also gave multiline string literals a different node tag from regular
string literals, for code clarity and to avoid an unnecessary load from
token_tags array.
2021-02-13 21:40:12 -07:00
Isaac Freund
24798b84ad zig fmt: implement multiline string literals 2021-02-13 16:57:34 -08:00
Isaac Freund
75ba8d8db6 zig fmt: remove empty lines at start/end of block 2021-02-13 16:57:34 -08:00
Andrew Kelley
7630a5c566 stage2: more progress towards Module/astgen building with new mem layout 2021-02-12 23:47:17 -07:00
Tadeo Kondrak
9270aae071
stage2: fix zero-sized function parameters (#7998) 2021-02-12 15:40:44 -05:00
Andrew Kelley
a9db40e870 zig fmt: add failing test case for inline/callconv conversion 2021-02-11 23:53:04 -07:00
Andrew Kelley
b4e344bcf8 Merge remote-tracking branch 'origin/master' into ast-memory-layout
Conflicts:
 * lib/std/zig/ast.zig
 * lib/std/zig/parse.zig
 * lib/std/zig/parser_test.zig
 * lib/std/zig/render.zig
 * src/Module.zig
 * src/zir.zig

I resolved some of the conflicts by reverting a small portion of
@tadeokondrak's stage2 logic here regarding `callconv(.Inline)`.
It will need to get reworked as part of this branch.
2021-02-11 23:45:40 -07:00
Andrew Kelley
3d0f4b9030 stage2: start reworking Module/astgen for memory layout changes
This commit does not reach any particular milestone, it is
work-in-progress towards getting things to build.

There's a `@panic("TODO")` in translate-c that should be removed when
working on translate-c stuff.
2021-02-11 23:29:55 -07:00
Veikka Tuominen
288e180598
snake_case render.Space 2021-02-12 02:14:07 +02:00
Veikka Tuominen
bb22490fcc
snake_case Node.Tag 2021-02-12 02:12:43 +02:00
Veikka Tuominen
e2289961c6
snake_case Token.Tag 2021-02-12 02:12:00 +02:00
Andrew Kelley
d3565ed6b4
Merge pull request #7749 from tadeokondrak/6429-callconv-inline
Replace inline fn with callconv(.Inline)
2021-02-11 16:01:58 -08:00
Isaac Freund
faa3fa65ac zig fmt: implement line comments 2021-02-11 15:49:49 -08:00
Isaac Freund
b6448a533d zig fmt: fix Tree.lastToken() for empty *Two nodes 2021-02-11 15:49:49 -08:00
Evan Haas
d98f09e4f6 translate-c: comma operator should introduce a new scope
This prevents inadvertent side-effects when an expression is not evaluated
due to boolean short-circuiting

Fixes #7989
2021-02-12 01:40:43 +02:00
Tadeo Kondrak
bb4f4c043e
test/cli.zig: Remove inline from panic function in testGodboltApi
Might add another line to stack traces there.
2021-02-10 20:22:20 -07:00
Tadeo Kondrak
bcc13597fc
translate_c: switch from inline fn to callconv(.Inline) 2021-02-10 20:22:19 -07:00
Tadeo Kondrak
7644e9a752
stage2: switch from inline fn to callconv(.Inline) 2021-02-10 20:22:18 -07:00
Tadeo Kondrak
1c15091bc8
stage1: switch from inline fn to callconv(.Inline) 2021-02-10 20:06:13 -07:00
Tadeo Kondrak
5dfe0e7e8f
Convert inline fn to callconv(.Inline) everywhere 2021-02-10 20:06:12 -07:00
Tadeo Kondrak
9c797fe3ac
std.zig: reformat inline fn to callconv(.Inline) 2021-02-10 20:06:11 -07:00
Jonathan Marler
61bcac108c Add more mingw def files
I've added more of the ".def" files from mingw. The list is based on all the libraries referenced by the win32metadata project. (see https://github.com/marlersoft/zigwin32).
2021-02-10 13:38:16 -08:00
Isaac Freund
4c8caf3343 zig fmt: implement Tree.lastToken() for all nodes 2021-02-10 11:53:53 -08:00
Isaac Freund
515d4920e7 zig fmt: fix 0 element struct and array init 2021-02-10 11:53:53 -08:00
Isaac Freund
5df7fc36c6 zig fmt: implement Tree.lastToken() for struct init 2021-02-10 11:53:53 -08:00
Isaac Freund
928f6f48a6 zig fmt: implement Tree.lastToken() for array init 2021-02-10 11:53:53 -08:00
Isaac Freund
3110a73486 zig fmt: implement Tree.lastToken() for array types 2021-02-10 11:53:53 -08:00
Isaac Freund
8c4f3e5a31 zig fmt: fix render of pointers with ** tokens 2021-02-10 11:53:53 -08:00
Isaac Freund
a524e57090 zig fmt: support bodyless function decls
extern function declarations do not have a body, so allow setting
the rhs for FnDecl to 0 to indicate this is the case.
2021-02-10 11:53:53 -08:00
Isaac Freund
80b719d967 zig fmt: fix typo in firstToken() for pointer types 2021-02-10 11:53:53 -08:00
Isaac Freund
6dc2236054 musl: update to 1.2.2 2021-02-10 11:50:55 -08:00
Evan Haas
a2ec77041b translate-c: call @boolToInt on return value when necessary
In C, if a function has return type `int` and the return expression
is a boolean expression, there is no implicit cast. Therefore the
translated Zig code needs to call @boolToInt() on the result.

Written with feedback from @Vexu

Fixes #6215
2021-02-10 20:23:27 +02:00
Jonathan Marler
1480c42806 require specifier for arrayish types 2021-02-09 22:25:52 -08:00
Andrew Kelley
58db3d2775 zig fmt: re-enable now-passing test cases 2021-02-09 23:07:29 -07:00
Andrew Kelley
fa5fcdd734 zig fmt: fix regression with many container members 2021-02-09 22:42:00 -07:00
Andrew Kelley
9d87e6aeb8 zig fmt: remove dead code
likely these will be resurrected to make array literal cases pass.
2021-02-09 22:29:01 -07:00
Andrew Kelley
36eee7bc6c zig fmt: anytype, fn calls with one param, trailing commas
and extra newlines between top level declarations
2021-02-09 22:26:21 -07:00
Andrew Kelley
25bcf4eb99 zig fmt: grouped expressions 2021-02-09 21:17:43 -07:00