View output.ll
; ModuleID = 'test.ll'
source_filename = "./test.zig"
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
%MultibootHeader = type <{ i64, i64, i64 }>
!llvm.module.flags = !{!0}
!llvm.dbg.cu = !{!1}
View output.txt
./test.zig:2:7: error: incompatible types: 'i32' and 'f64'
a + b
^
./test.zig:6:8: note: called from here
add(a, b)
^
./test.zig:10:8: note: called from here
foo(a, b)
^
./test.zig:14:8: note: called from here
View bug.ll
; ModuleID = '../example/hello_world/hello.zig'
source_filename = "../example/hello_world/hello.zig"
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
%OutStream = type { i32, [4096 x i8], i64 }
%"[]u8" = type { i8*, i64 }
%"[][]u8" = type { %"[]u8"*, i64 }
@0 = internal unnamed_addr constant i1 true
View example.zig
fn List(inline T: type) -> type {
struct {
items: []T,
len: usize,
}
}
fn foo() -> bool {
const A = List(i32);
const B = List(i32);
View gist:1bb6d8343ad3a5941a3229469fc07445
=============== zig code =====================
extern fn something();
export fn doSomethingTenTimes(x: i32) {
{var i: i32 = 0; while (i < 10; i += 1) {
if (i == 4) i += x;
something();
}}
}
View gist:306522a196c67cb2d5a5a11ffa6b5edb
extern fn something();
fn doSomethingTenTimes() {
{var i: i32 = 0; while (i < 10; i += 1) {
something();
}}
}
fn doSomethingTenTimes {
Entry_0:
View gist:74b19472eb9587a5936de1cb9a45eab6
fn assert(ok: bool) {
if (!ok) @unreachable();
}
fn assert {
Entry_0:
#1 | bool | 1 | ok
#2 | (unknown) | 1 | ! #1
#6 | unreachable | - | if (#2) $Then_3 else $Else_4
View comparison
Zig 0.371 sec
C 0.604 sec
implementations of the RNG are equivalent implementations of MT64
note: I achieved the same performance with zig and C when I used clang with -O3 -fomit-frame-pointer and LTO.
View output.txt
0 = 17
1 = 48
2 = 92
3 = 130
4 = 178
5 = 187
6 = 267
8 = 302
7 = 308
9 = 361
View fizzbuzz.zig
const io = @import("std").io;
pub fn main(args: [][]u8) -> %void {
%%io.stdout.printf(fizzbuzz(100));
}
fn fizzbuzz(n: usize) -> []u8 {
// note: variant type variables not supported yet
var result: var = []u8{};
{var i: usize = 1; while (i <= 100; i += 1) {