Commit Graph

2643 Commits

Author SHA1 Message Date
Andrew Kelley
df7aa9a4f0
allow implicit optional pointer to optional c_void pointer 2019-05-26 17:55:20 -04:00
Andrew Kelley
269a53b6af
introduce @hasDecl builtin function
closes #1439
2019-05-26 16:21:03 -04:00
Andrew Kelley
21ed939117
support enum literals implicit casting to tagged unions 2019-05-26 12:59:30 -04:00
LemonBoy
6672ee9eb3 Fix too eager comptime evaluation of error ptr 2019-05-19 15:53:32 -04:00
LemonBoy
b660134a18 Use the correct scope for use
use expressions outside the top-level scope now work as intended.
2019-05-19 00:32:49 -04:00
LemonBoy
0a3aec020a Fix load/store of non-integer fields in packed struct 2019-05-18 19:59:47 -04:00
Andrew Kelley
2eba779af5
stage1 tokenizer: add more missing break statements 2019-05-16 16:50:24 -04:00
SamTebbs33
87901baa28 Add break after digit_value check in TokenizeStateCharCode 2019-05-16 16:49:26 -04:00
Andrew Kelley
80983ca1ca
fixups to the previous commit 2019-05-16 16:37:58 -04:00
Shawn Landden
1fdb24827f
breaking changes to all bit manipulation intrinsics
* `@clz`, `@ctz`, `@popCount`, `@bswap`, `@bitreverse` now
   have a type parameter
 * rename @bitreverse to @bitReverse
 * rename @bswap to @byteSwap

Closes #2119
Closes #2120
2019-05-16 16:37:58 -04:00
Andrew Kelley
81e960eb74
improvements to build-lib use case of WebAssembly
* build-exe does include the startup code that supplies _start for the
   wasm32-freestanding target. Previously this did not occur because
   of logic excluding "freestanding".
 * build-lib for wasm32-freestanding target gets linked by LLD. To avoid
   infinite recursion, compiler_rt and zig libc are built as objects
   rather than libraries.
   - no "lib" prefix and ".wasm" extension instead of ".a". Rather than
   build-lib foo.zig producing "libfoo.a", now it produces "foo.wasm".
 * go back to using `.o` extension for webassembly objects
 * zig libc only provides _start symbol for wasm when linking libc.
2019-05-16 13:56:56 -04:00
Andrew Kelley
07d0aee11a
clang C API wrapper: small progress 2019-05-16 12:55:45 -04:00
Andrew Kelley
6b36b756eb
fix static builds of zig from requiring c compiler
to be installed when linking libc.

When zig links against libc, it requires a dynamic linker path.
Usually this can be determined based on the architecture and operating
system components of the target. However on some systems this is not
correct; because of this zig checks its own dynamic linker.

When zig is statically linked, this information is not available, and so
it resorts to using cc -print-filename=foo to find the dynamic linker
path.

Before this commit, Zig incorrectly exited with an error if there was
no c compiler installed. Now, Zig falls back to the dynamic linker
determined based on the arch and os when no C compiler can be found.
2019-05-15 21:50:56 -04:00
Shritesh Bhattarai
b64e6cb813 change wasm obj ext to .wasm 2019-05-15 20:41:22 -04:00
Andrew Kelley
14cdb01f35 improvements to zig's implementation of libc and WebAssembly
* rename std/special/builtin.zig to std/special/c.zig
   not to be confused with @import("builtin") which is entirely
   different, this is zig's multi-target libc implementation.
 * WebAssembly: build-exe is for executables which have a main().
   build-lib is for building libraries of functions to use from,
   for example, a web browser environment.
   - for now pass --export-all for libraries when there are any
     C objects because we have no way to detect the list of exports
     when compiling C code.
   - stop passing --no-entry for executables. if you want --no-entry
     then use build-lib.
 * make the "musl" ABI the default ABI for wasm32-freestanding.
 * zig provides libc for wasm32-freestanding-musl.
2019-05-15 20:14:58 -04:00
Andrew Kelley
3aa43dc31c
update libclang C API wrapper 2019-05-15 11:57:55 -04:00
Andrew Kelley
057a5d4898
slice types no longer have field access
* fix crash when doing field access of slice types. closes #2486
 * remove the deprecated Child property from slice types
 * add -Dskip-non-native build option to build script
2019-05-14 21:21:59 -04:00
Andrew Kelley
e93a05b6e4
switching on error sets makes new error set for capture values
closes #769
2019-05-14 19:11:37 -04:00
Andrew Kelley
c08c222d5e
fix regression on switch capture value for multiple cases 2019-05-14 18:25:14 -04:00
Andrew Kelley
df4f77024e
else value when switching on error set has
optional capture value which is subset.

see #769
2019-05-14 18:06:57 -04:00
LemonBoy
6536b409df Don't emit DW_TAG_lexical_block for VarDecls 2019-05-14 14:34:49 -04:00
Andrew Kelley
7330a6102f
cache_add_dep_file: handle ErrorFileNotFound specially 2019-05-13 12:15:55 -04:00
Andrew Kelley
f3db3b3c13
Merge branch 'asm-cc' of https://github.com/LemonBoy/zig into LemonBoy-asm-cc 2019-05-13 12:10:21 -04:00
LemonBoy
a038ef3570 Assemble asm files using CC
Stuffing all the files together and compiling the resulting blob with
the main program is a terrible idea.

Some files, namely the .S ones, must be run trough the C preprocessor
before assembling them (#2437).

Beside that the aggregate may be mis-compiled due to the presence of
some flags that affect the following code.

For example let's consider two files, a.s and b.s

a.s
```
fn1:
    ret
.data
data1:
    .word 0
```

b.s
```
fn2:
    ret
```

Now, fn1 and fn2 will be both placed in the .text section as intended if
the two files are compiled separately. But if we merge them the `.data`
flag ends up placing fn2 in the wrong section!

This fixes a nasty crash where musl's memset ended up in the
non-executable data segment, leading to too many hours of
head-scratching.
2019-05-13 16:41:07 +02:00
LemonBoy
d210628c91 Amend the error messages 2019-05-11 21:29:55 +02:00
LemonBoy
b05e8d46ec Change the enum value allocation strategy 2019-05-11 21:29:53 +02:00
LemonBoy
655794f44f amend type_is_valid_extern_enum_tag 2019-05-11 21:29:00 +02:00
LemonBoy
c766f3f9ca Support signed types as enum tags 2019-05-11 21:28:58 +02:00
LemonBoy
917bd4192d Validate enum tag for extern enum
The C specification mandates the enum to be compatible with signed char,
signed int or unsigned int.
2019-05-11 21:27:58 +02:00
Jimmi Holst Christensen
6cf7fb1177 fixes #2235 2019-05-11 20:51:59 +02:00
Jimmi Holst Christensen
c051904903 Fixed parser for extern threadlocal variables 2019-05-11 18:48:52 +02:00
Andrew Kelley
5f4c3e6557
stage2 translate-c: simple function definitions
See #1964
2019-05-10 23:35:46 -04:00
Andrew Kelley
fee0e6c8b9
fix hang for some compile errors
see #2467
2019-05-10 16:39:50 -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
Michael Dusan
d065f297ab stage1: compile error for loop expr val ignored
closes #2460
2019-05-10 10:05:40 -04:00
Jimmi HC
6b10f03b4a Fixes and simplifications for stage 1 parser 2019-05-10 16:09:58 +02:00
Andrew Kelley
1c0223899c
translate-c: progress on self-hosted function prototypes
See #1964
2019-05-10 01:24:00 -04:00
Andrew Kelley
09cff0d2bd
fix translate-c regression
introduced in eb65410b62
2019-05-09 20:11:56 -04:00
Andrew Kelley
eea2de108d
translate-c: progress on self-hosted function prototypes
See #1964
2019-05-09 16:52:30 -04:00
Andrew Kelley
214625587c
translate-c: use C API for builtin types
See #1964
2019-05-09 15:46:48 -04:00
Andrew Kelley
010963ce43
stage1: make some asserts print source location 2019-05-09 14:52:06 -04:00
Andrew Kelley
c459edac18
compile error for attempt to cast enum literal to error
closes #2203
2019-05-09 13:18:13 -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
a7346ea49f fix build on macOS
Sadly due to a workaround for LLD linker limitations on macOS
we cannot put libuserland into an .a file; instead we have to use object
files. Again due to linker limitations, bundling compiler_rt.o into
another relocatable object also doesn't work. So we're left with
disabling stack probing on macOS for the stage1 self-hosted code.

These workarounds could all be removed if the macos support in the LLD
linker improved, or if Zig project had its own linker that did not have
these issues.
2019-05-08 22:45:49 -04:00
Andrew Kelley
46e1c34fcf
self-hosted translate-c progress on function decls
See #1964
2019-05-08 22:05:59 -04:00
Andrew Kelley
9bbd71c9ab
add --bundle-compiler-rt function to link options
and use it when building libuserland.a

The self-hosted part of stage1 relies on zig's compiler-rt, and so we
include it in libuserland.a.

This should potentially be the default, but for now it's behind a linker
option.

self-hosted translate-c: small progress on translating functions.
2019-05-08 20:51:49 -04:00
Andrew Kelley
3bd5c16f39
stage1: remove unneeded extern function 2019-05-08 19:33:57 -04:00
Andrew Kelley
e3542196c0
translate-c: NULL pointers translate to null
See #1967
2019-05-08 19:21:54 -04:00
Andrew Kelley
a4aee8b24d
C pointers support if and orelse
See #1967
2019-05-08 18:47:14 -04:00