Andrew Kelley
8aba0643a5
peer result locations with mixed runtime/comptime
...
```zig
export fn entry() void {
var c = true;
var a = u8(4);
const x = if (c) a else u32(8);
}
```
```llvm
define void @entry() #2 !dbg !35 {
Entry:
%c = alloca i1, align 1
%a = alloca i8, align 1
%x = alloca i32, align 4
store i1 true, i1* %c, align 1, !dbg !45
call void @llvm.dbg.declare(metadata i1* %c, metadata !39 , metadata !DIExpression()), !dbg !46
store i8 4, i8* %a, align 1, !dbg !47
call void @llvm.dbg.declare(metadata i8* %a, metadata !42 , metadata !DIExpression()), !dbg !48
%0 = load i1, i1* %c, align 1, !dbg !49
br i1 %0, label %Then, label %Else, !dbg !49
Then: ; preds = %Entry
%1 = load i8, i8* %a, align 1, !dbg !50
%2 = zext i8 %1 to i32, !dbg !50
br label %EndIf, !dbg !51
Else: ; preds = %Entry
br label %EndIf, !dbg !51
EndIf: ; preds = %Else, %Then
%3 = phi i32 [ %2, %Then ], [ 8, %Else ], !dbg !51
store i32 %3, i32* %x, align 4, !dbg !51
call void @llvm.dbg.declare(metadata i32* %x, metadata !43 , metadata !DIExpression()), !dbg !52
ret void, !dbg !53
}
```
2019-05-31 00:54:10 -04:00
Andrew Kelley
3702c278e3
local consts with comptime init exprs
...
```zig
export fn entry() void {
const x = if (true) u8(4) else u32(8);
}
```
```llvm
define void @entry() #2 !dbg !35 {
Entry:
call void @llvm.dbg.declare(metadata i8* @0, metadata !39 , metadata !DIExpression()), !dbg !41
ret void, !dbg !42
}
```
2019-05-31 00:22:12 -04:00
Andrew Kelley
95d9835898
no-copy semantics for nested if
...
```zig
export fn entry() void {
var c = true;
var x = if (c) u8(4) else if (c) u16(100) else u32(10);
}
```
```llvm
define void @entry() #2 !dbg !35 {
Entry:
%c = alloca i1, align 1
%x = alloca i32, align 4
store i1 true, i1* %c, align 1, !dbg !44
call void @llvm.dbg.declare(metadata i1* %c, metadata !39 , metadata !DIExpression()), !dbg !45
%0 = load i1, i1* %c, align 1, !dbg !46
br i1 %0, label %Then2, label %Else, !dbg !46
Else: ; preds = %Entry
%1 = load i1, i1* %c, align 1, !dbg !47
br i1 %1, label %Then, label %Else1, !dbg !47
Then: ; preds = %Else
br label %EndIf, !dbg !48
Else1: ; preds = %Else
br label %EndIf, !dbg !48
Then2: ; preds = %Entry
br label %EndIf3, !dbg !49
EndIf: ; preds = %Else1, %Then
%2 = phi i32 [ 100, %Then ], [ 10, %Else1 ], !dbg !48
br label %EndIf3, !dbg !49
EndIf3: ; preds = %EndIf, %Then2
%3 = phi i32 [ 4, %Then2 ], [ %2, %EndIf ], !dbg !49
store i32 %3, i32* %x, align 4, !dbg !49
call void @llvm.dbg.declare(metadata i32* %x, metadata !42 , metadata !DIExpression()), !dbg !50
ret void, !dbg !51
}
```
2019-05-30 23:25:37 -04:00
Andrew Kelley
a4aca78722
no-copy semantics for if expr
...
```zig
export fn entry() void {
var c = true;
var x = if (c) u8(4) else u32(10);
}
```
```llvm
define void @entry() #2 !dbg !35 {
Entry:
%c = alloca i1, align 1
%x = alloca i32, align 4
store i1 true, i1* %c, align 1, !dbg !44
call void @llvm.dbg.declare(metadata i1* %c, metadata !39 , metadata !DIExpression()), !dbg !45
%0 = load i1, i1* %c, align 1, !dbg !46
br i1 %0, label %Then, label %Else, !dbg !46
Then: ; preds = %Entry
br label %EndIf, !dbg !47
Else: ; preds = %Entry
br label %EndIf, !dbg !47
EndIf: ; preds = %Else, %Then
%1 = phi i32 [ 4, %Then ], [ 10, %Else ], !dbg !47
store i32 %1, i32* %x, align 4, !dbg !47
call void @llvm.dbg.declare(metadata i32* %x, metadata !42 , metadata !DIExpression()), !dbg !48
ret void, !dbg !49
}
```
2019-05-30 23:16:11 -04:00
Andrew Kelley
5e1003bc81
no-copy semantics for basic runtime function call variable init
...
```zig
export fn entry() void {
var x: Foo = foo();
}
```
```llvm
define void @entry() #2 !dbg !37 {
Entry:
%x = alloca %Foo, align 4
call fastcc void @foo(%Foo* sret %x), !dbg !48
call void @llvm.dbg.declare(metadata %Foo* %x, metadata !41 , metadata !DIExpression()), !dbg !49
ret void, !dbg !50
}
```
2019-05-30 17:11:14 -04:00
Andrew Kelley
78f32259da
default struct field initialization expressions
...
closes #485
2019-05-30 15:46:11 -04:00
tgschultz
f9e7bd2682
std.meta/trait: def/definition => decl/declaration
...
TypeInfo: defs/Definition => decls/Declarations
2019-05-29 20:43:07 -04:00
Shawn Landden
4188faeac5
stage1: AstNodes cannot be casted, but are rather accessed via a union.
...
Unlike IrInstruction[Foo]s, which all start with:
IrInstruction base;
AstNodes do not work like this, and instead use a pointer to their
specializations. The code assumed otherwise.
2019-05-29 20:21:07 -04:00
Andrew Kelley
1ccbd1fb67
use works on unions and enums in addition to structs
2019-05-29 16:31:49 -04:00
Andrew Kelley
b66438eb80
no "use of undeclared identifer" in dead comptime branches
2019-05-28 18:19:27 -04:00
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
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
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
Andrew Kelley
fee0e6c8b9
fix hang for some compile errors
...
see #2467
2019-05-10 16:39:50 -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
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
a4aee8b24d
C pointers support if and orelse
...
See #1967
2019-05-08 18:47:14 -04:00
Andrew Kelley
0099583bd3
C pointers support .? operator
...
see #1967
2019-05-08 17:39:00 -04:00
Andrew Kelley
50bbb34594
C pointers support null
...
See #1967
2019-05-08 16:06:34 -04:00
LemonBoy
9902b604cb
Fix generation of container initializers
...
The code creates temporary ConstExprValue with global_refs set to
nullptr and that's carried over to the final value. Doing so prevents
the deduplication mechanism to work correctly, causing all sorts of
runtime crashes.
Fixes #1636
Fixes #1608 (Even though it was already fixed by #1991 )
2019-04-28 13:13:42 -04:00
Andrew Kelley
e1bf74fca3
translate-c: put -x c back in there, it's necessary
2019-04-25 00:06:58 -04:00
Andrew Kelley
712274997e
translate-c: unify API for self-hosted and C++ translate-c
...
See #1964
2019-04-25 00:06:57 -04:00
Andrew Kelley
976080462c
translate-c: a little closer to self-hosted implementation
2019-04-25 00:06:54 -04:00
Andrew Kelley
fb2acaff06
@sizeOf returns 0 for comptime types
...
This defines `@sizeOf` to be the runtime size of a type, which means
that it is zero for types such as comptime_int, type, and (enum
literal).
See #2209
2019-04-24 22:31:53 -04:00
Andrew Kelley
ad994c9642
Merge pull request #2296 from LemonBoy/translate-c-stuff
...
Handle implicit casts in translate-c
2019-04-24 14:43:46 -04:00
Jimmi HC
1a2e02e267
fixed #2356
...
const_ptr_pointee_unchecked did not take into account that if the
pointer is zero sized, then const_val->data.x_ptr.special would be
ConstPtrSpecialInvalid. This commit fixes this by also checking
that the child type of the pointer only have one possible value
and just returns that value.
2019-04-24 15:04:58 +02:00
LemonBoy
a44ad08954
Add some zig_panic for 80-bit float codepaths
2019-04-22 22:23:41 +02:00
Shritesh Bhattarai
9465c6d538
link: exemption for wasm instead of wasi
2019-04-15 16:59:34 -05:00
Andrew Kelley
63a970a548
Merge pull request #2268 from shritesh/wasi
...
wasm: preliminary WASI OS support
2019-04-14 10:45:30 -04:00
Shritesh Bhattarai
ecd0f89254
wasi: better extern wasi logic
2019-04-13 23:49:02 -05:00
Shritesh Bhattarai
a2d8f03092
support extern "wasi" functions
2019-04-13 22:28:58 -05:00
Andrew Kelley
68d7e4a1b6
better handle quota of setEvalBranchQuota
...
Now that c58b80203443dcbf8b737ebdaa1f17fb20c77711 has removed
the "top of the comptime stack" requirement, the branch quota
can be modified somewhere other than the top of the comptime stack.
This means that the quota of a parent IrExecutable has to be
modifiable by an instruction in the child.
Closes #2261
2019-04-13 16:55:59 -04:00
kristopher tate
627b52fe65
src/ir.cpp: don't call-out to analyze_type_expr;
...
replaces `analyze_type_expr` with `ir_analyze_type_expr`
2019-04-07 10:37:43 +09:00
Jimmi Holst Christensen
65cf5a8e44
removed todo comment and added test
2019-04-06 11:04:55 +02:00
Jimmi Holst Christensen
3109c89850
fixed 1726
2019-04-06 10:56:07 +02:00
Andrew Kelley
f00adb47f5
ir: avoid dependency on isnan
...
there's a simple way to check for nan that does not need this header.
hryx on IRC reported that Linux Mint based on ubuntu 16.04, kernel
4.15.0, x86_64 did not have the isnan function.
2019-04-06 01:03:30 -04:00
Andrew Kelley
83390bdfdd
fix dereferencing a zero bit type
...
Before only u0 was special cased in handling a dereference;
now all zero bit types are handled the same way. Dereferencing
a pointer to a zero bit type always gives a comptime-known
result.
This previously had been failing on master branch but went unnoticed
because until 846f72b57cb5 the CI server was mistakenly not actually
running the single-threaded tests with --single-threaded.
This fixes the standard library tests with --single-threaded
--release-fast.
2019-04-05 20:18:26 -04:00
Andrew Kelley
1dc6751721
fix NaN comparing equal to itself
...
This was broken both in comptime code and in runtime code.
closes #1174
2019-04-04 22:07:15 -04:00
Andrew Kelley
ddb8aa73f5
more regression fixes
2019-04-02 18:31:18 -04:00
Andrew Kelley
d3f2fe2cef
remove the lazy value stuff
...
let's try to keep this branch to solving one problem at a time
2019-04-02 18:31:18 -04:00
Andrew Kelley
3dc8448680
introduce lazy values
...
but I think it's a bad idea, so I'm going to back out the change
2019-04-02 18:31:18 -04:00