Commit Graph

5168 Commits

Author SHA1 Message Date
jacob gw 58b14d01ae stage2: remove value field from error
This saves memory and from what I have heard allows threading
to be easier.
2021-02-28 22:01:13 +02:00
Evan Haas 294ee1bbc9 translate-c: add limited OffsetOfExpr support
Add support for OffsetOfExpr that contain exactly 1 component, when that component
is a field.

For example, given:

```c
struct S {
  float f;
  double d;
};
struct T {
  long l;
  int i;
  struct S s[10];
};
```

Then:
```c
offsetof(struct T, i)       // supported
offsetof(struct T, s[2].d)  // not supported currently
```
2021-02-28 21:56:57 +02:00
daurnimator d4af35b3fe HashMap.put returns !void, not a !bool 2021-02-27 13:11:47 +02:00
Andrew Kelley 4a548002af translate-c: upgrade to new std.zig.fmtEscapes API
fixes regressions from previous commit
2021-02-27 01:20:19 -07:00
Evan Haas 0816981561 translate-c: add typeof support 2021-02-25 22:33:42 -08:00
Andrew Kelley fd208d9d59 stage2: implement the error_value AST tag 2021-02-25 18:21:22 -07:00
g-w1 153c97ac9e improve stage2 to allow catch at comptime:
* add error_union value tag.
* add analyzeIsErr
* add Value.isError
* add TZIR wrap_errunion_payload and wrap_errunion_err for
  wrapping from T -> E!T and E -> E!T
* add anlyzeInstUnwrapErrCode and analyzeInstUnwrapErr
* add analyzeInstEnsureErrPayloadVoid:
* add wrapErrorUnion
* add comptime error comparison for tests
* tests!
2021-02-25 16:41:16 -08:00
Al Hoang c17396691c initial support for haiku sync update
* add cpu count
* use haiku find_directory
* add definitions and exports for building in haiku
2021-02-25 16:41:42 -07:00
Al Hoang 025635c3f8 initial support for haiku past stage0 2021-02-25 16:41:42 -07:00
joachimschmidt557 297eabd4ac stage2 ARM: Save callee-saved registers
Add a new allocated_registers bitmap to keep track of all callee-saved
registers allocated during generation of this function.

Function(.arm).gen uses this data to generate instructions in the
function prologue and epilogue to push and pop these registers
respectively.
2021-02-25 22:27:19 +02:00
Evan Haas 4f11a88b9f translate-c: Add support for pointer subtraction
When two pointers are subtracted, both shall point to elements of the
same array object, or one past the last element of the array object;
the result is the difference of the subscripts of the two array elements.

The size of the result is implementation-defined, and its type
(a signed integer type) is ptrdiff_t defined in the <stddef.h> header.
If the result is not representable in an object of that type,
the behavior is undefined.

See C Standard, §6.5.6 [ISO/IEC 9899:2011]

Fixes #7216
2021-02-25 22:24:11 +02:00
Andrew Kelley 449f4de382 zig fmt src/ 2021-02-24 21:54:23 -07:00
Andrew Kelley 8e6c2b7a47 Merge remote-tracking branch 'origin/master' into ast-memory-layout 2021-02-24 15:08:23 -07:00
Josh Wolfe 8b9434871e Avoid concept of a "Unicode character" in documentation and error messages (#8059) 2021-02-24 08:26:13 -05:00
Andrew Kelley f041425e48 translate-c: fix using wrong slice and AST tag 2021-02-23 13:55:12 -07:00
Andrew Kelley 01e89c9171 translate-c: update to latest AST tag changes 2021-02-23 12:39:50 -07:00
Isaac Freund 5306b1a9ab zig fmt: container doc comments 2021-02-23 18:32:47 +01:00
Veikka Tuominen d83698ab54 translate-c: check for noreturn in switch in more cases 2021-02-22 21:52:22 +02:00
Veikka Tuominen 011bc1b84f translate-c: switch default should have an empty block not break 2021-02-22 19:26:19 +02:00
Veikka Tuominen 69d5a106da render: handle comments ending in EOF 2021-02-22 16:59:44 +02:00
Andrew Kelley a17a5ca3a8 translate-c: fix fn_decl vs fn_proto
Regressed in 15603f403c.
2021-02-21 18:31:32 -07:00
joachimschmidt557 9712e89265 stage2 codegen: Add Type argument to genSetReg 2021-02-21 12:23:36 +02:00
Veikka Tuominen ef6aa3d027 Merge pull request #7960 from Luukdegram/wasm-extern
stage2: Add support for extern functions for the wasm backend
2021-02-21 12:22:01 +02:00
LemonBoy 057bf1afc9 std: Add more error checking in hexToBytes
Prevent the function from turning into an endless loop that may or may
not perform OOB accesses.
2021-02-21 12:19:03 +02:00
jacob gw 1bd434fd18 std.Progress: improve support for "dumb" terminals 2021-02-21 12:12:17 +02:00
Veikka Tuominen 4074e79748 translate-c: use global scope for typedef/record/enum type translation if needed
If the type is a reference to a global declaration that has not yet
been translated we need to use the global scope for translation
so that other functions can also reference it.
2021-02-20 13:32:07 +02:00
Andrew Kelley 669c2054a8 stage2: debug line nops supports bigger padding 2021-02-19 22:55:42 -07:00
Andrew Kelley ed1e5cb3f6 stage2: fix a couple off by one errors
All stage2 tests are passing again in this branch.

Remaining checklist for this branch:
 * get the rest of the zig fmt test cases passing
   - re-enable the translate-c test case that is blocking on this
 * implement the 2 `@panic(TODO)`'s in parse.zig
 * use fn_proto not fn_decl for extern function declarations
2021-02-19 21:47:11 -07:00
Michael Dusan 153cd4da0c macos: fix cond to enable ZIG_SYSTEM_LINKER_HACK
closes #8037
2021-02-19 23:37:13 -05:00
Andrew Kelley 5b597a16c6 stage2: fix not setting up ZIR arg instruction correctly
This is a regression from when I briefly flirted with changing how arg
ZIR instructions work in this branch, and then failed to revert it
correctly.
2021-02-19 20:57:06 -07:00
Andrew Kelley 70761d7c52 stage2: remove incorrect newlines from log statements 2021-02-19 20:27:06 -07:00
Andrew Kelley 6959b177ef stage2: test harness: panic on OOM rather than assert
also add a prefix to test names for C backend
2021-02-19 20:26:48 -07:00
Andrew Kelley 8fee41b1d5 stage2: AST: clean up parse errors
* struct instead of tagged union
 * delete dead code
 * simplify parser code
 * remove unnecessary metaprogramming
2021-02-19 18:04:52 -07:00
Veikka Tuominen 6f6568b1fd translate-c: correctly add semicolon to if statements 2021-02-19 20:48:06 +02:00
Veikka Tuominen d672c20b8a Merge pull request #7479 from ziglang/translate-c-ast
Make translate-c use intermediate AST
2021-02-19 13:03:29 +02:00
Veikka Tuominen 974a1c5525 translate-c: small fixes to avoid generating invalid code for macros 2021-02-19 12:50:42 +02:00
Andrew Kelley 914540ddb5 astgen: fix remaining compile errors
Now it builds and what remains in this branch is:
 * fix the stage2 compiler regressions from this branch
 * finish the rest of zig fmt test cases, get them passing
 * Merge in Vexu's translate-c AST branch & fix translate-c regressions
2021-02-19 00:04:31 -07:00
Andrew Kelley 9010bd8aec stage2: astgen: fix most of the remaining compile errors
more progress on converting astgen to the new AST memory layout.
only a few code paths left to update.
2021-02-18 20:09:29 -07:00
Veikka Tuominen 3aba1fa04f translate-c: ensure failed macros don't get defined multiple times 2021-02-19 01:52:27 +02:00
Veikka Tuominen df5a8120df translate-c: small miscellaneous improvements 2021-02-18 21:34:31 +02:00
Andrew Kelley 29daf10639 stage2: fix a couple more compilation errors 2021-02-17 22:34:06 -07:00
Andrew Kelley 5a2620fcca stage2: fix some of the compilation errors in this branch 2021-02-17 22:22:10 -07:00
Andrew Kelley c66481f9bc astgen: finish updating expressions to new mem layout
Now all that is left is compile errors and whatever regressions this
branch introduced.
2021-02-17 20:59:21 -07:00
Veikka Tuominen 7ca53bdfaa translate-c: improve switch translation 2021-02-17 22:11:26 +02:00
Veikka Tuominen d5fecbd0ba translate-c: support scoped typedef, enum and record decls
Closes #5256
2021-02-17 16:26:11 +02:00
Veikka Tuominen e2974759dd translate-c: demote untranslatable declarations to externs 2021-02-17 14:11:49 +02:00
Isaac Freund 070e548acf std: remove io.AutoIndentingStream
This type is not widely applicable enough to be a public part of the
public interface of the std.

The current implementation in only fully utilized by the zig fmt
implementation, which could benefit by even tighter integration as
will be demonstrated in the next commit. Therefore, move the current
io.AutoIndentingStream to lib/std/zig/render.zig.

The C backend of the self hosted compiler also use this type currently,
but it does not require anywhere near its full complexity. Therefore,
implement a greatly simplified version of this interface in
src/codegen/c.zig.
2021-02-16 23:20:46 +01:00
Veikka Tuominen 9a826ccbe0 translate-c: elide some unecessary casts of literals 2021-02-16 16:40:43 +02:00
Veikka Tuominen 74e9d4ca82 translate-c: get all translate-c tests passing 2021-02-16 16:40:43 +02:00
Veikka Tuominen 78fba4e021 translate-c: get all run-translated-c tests passing 2021-02-16 16:40:43 +02:00