Compare commits
63 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b0ba8b728f | ||
|
|
404a057f77 | ||
|
|
7a29161e8e | ||
|
|
236fb915cc | ||
|
|
e9388fde64 | ||
|
|
46a28175b3 | ||
|
|
59dd7a0fbd | ||
|
|
0aeeff0d94 | ||
|
|
ce9d2eda73 | ||
|
|
d6eac43a5b | ||
|
|
0039cb7ef2 | ||
|
|
88146ea704 | ||
|
|
6e469bc44d | ||
|
|
2d4b264527 | ||
|
|
95845ba2ac | ||
|
|
4a09703f62 | ||
|
|
82908b525d | ||
|
|
aba1dbc954 | ||
|
|
6ce3c2423e | ||
|
|
52150b701c | ||
|
|
869880adac | ||
|
|
511aa28983 | ||
|
|
e57c9c0931 | ||
|
|
d37182383d | ||
|
|
1216050520 | ||
|
|
8832314acf | ||
|
|
4616fb0937 | ||
|
|
fa4a626fac | ||
|
|
33c3bf0631 | ||
|
|
2563d32425 | ||
|
|
33809a0c53 | ||
|
|
2648e3651e | ||
|
|
d09afc08da | ||
|
|
ddde99bdfa | ||
|
|
f2110b0c0d | ||
|
|
7ce03acb9d | ||
|
|
c3aa32e984 | ||
|
|
efe06c5f31 | ||
|
|
7b908cb024 | ||
|
|
16d3f7b2fa | ||
|
|
fa5011aa31 | ||
|
|
595a7f8b08 | ||
|
|
6c482b8033 | ||
|
|
ad63be7eb9 | ||
|
|
704f8f4013 | ||
|
|
ef9fb428b7 | ||
|
|
600b652825 | ||
|
|
e36bf2baff | ||
|
|
4babedf1be | ||
|
|
0dc64d9064 | ||
|
|
5d29b9fad6 | ||
|
|
6de152ec7c | ||
|
|
cc25f75478 | ||
|
|
eb28c8aa35 | ||
|
|
f6773232ac | ||
|
|
9deea9b1d8 | ||
|
|
8e0a802ea1 | ||
|
|
eb5d67b146 | ||
|
|
082e5091af | ||
|
|
3b1f9b476c | ||
|
|
2478b5bb0e | ||
|
|
7974576967 | ||
|
|
011a78325e |
2
.github/workflows/ci.yaml
vendored
2
.github/workflows/ci.yaml
vendored
@@ -4,7 +4,7 @@ on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- llvm18
|
||||
- 0.12.x
|
||||
concurrency:
|
||||
# Cancels pending runs when a PR gets updated.
|
||||
group: ${{ github.head_ref || github.run_id }}-${{ github.actor }}
|
||||
|
||||
6
.gitignore
vendored
6
.gitignore
vendored
@@ -9,14 +9,10 @@
|
||||
# Cheers!
|
||||
# -andrewrk
|
||||
|
||||
.zig-cache/
|
||||
zig-cache/
|
||||
zig-out/
|
||||
/release/
|
||||
/debug/
|
||||
/build/
|
||||
/build-*/
|
||||
/docgen_tmp/
|
||||
|
||||
# Although this was renamed to .zig-cache, let's leave it here for a few
|
||||
# releases to make it less annoying to work with multiple branches.
|
||||
zig-cache/
|
||||
|
||||
1240
CMakeLists.txt
1240
CMakeLists.txt
File diff suppressed because it is too large
Load Diff
@@ -47,9 +47,9 @@ mechanism supports that use case too (i.e. `/usr/bin/zig` and `/usr/lib/zig/`).
|
||||
|
||||
Ensure you have the required dependencies:
|
||||
|
||||
* CMake >= 3.15
|
||||
* CMake >= 3.5
|
||||
* System C/C++ Toolchain
|
||||
* LLVM, Clang, LLD development libraries == 18.x
|
||||
* LLVM, Clang, LLD development libraries == 17.x
|
||||
|
||||
Then it is the standard CMake build process:
|
||||
|
||||
|
||||
92
build.zig
92
build.zig
@@ -9,7 +9,7 @@ const fs = std.fs;
|
||||
const InstallDirectoryOptions = std.Build.InstallDirectoryOptions;
|
||||
const assert = std.debug.assert;
|
||||
|
||||
const zig_version: std.SemanticVersion = .{ .major = 0, .minor = 13, .patch = 0 };
|
||||
const zig_version = std.SemanticVersion{ .major = 0, .minor = 12, .patch = 1 };
|
||||
const stack_size = 32 * 1024 * 1024;
|
||||
|
||||
pub fn build(b: *std.Build) !void {
|
||||
@@ -32,7 +32,22 @@ pub fn build(b: *std.Build) !void {
|
||||
const std_docs = b.option(bool, "std-docs", "include standard library autodocs") orelse false;
|
||||
const no_bin = b.option(bool, "no-bin", "skip emitting compiler binary") orelse false;
|
||||
|
||||
const langref_file = generateLangRef(b);
|
||||
const docgen_exe = b.addExecutable(.{
|
||||
.name = "docgen",
|
||||
.root_source_file = b.path("tools/docgen.zig"),
|
||||
.target = b.host,
|
||||
.optimize = .Debug,
|
||||
.single_threaded = single_threaded,
|
||||
});
|
||||
|
||||
const docgen_cmd = b.addRunArtifact(docgen_exe);
|
||||
docgen_cmd.addArgs(&.{ "--zig", b.graph.zig_exe });
|
||||
if (b.zig_lib_dir) |p| {
|
||||
docgen_cmd.addArg("--zig-lib-dir");
|
||||
docgen_cmd.addDirectoryArg(p);
|
||||
}
|
||||
docgen_cmd.addFileArg(b.path("doc/langref.html.in"));
|
||||
const langref_file = docgen_cmd.addOutputFileArg("langref.html");
|
||||
const install_langref = b.addInstallFileWithDir(langref_file, .prefix, "doc/langref.html");
|
||||
if (!skip_install_langref) {
|
||||
b.getInstallStep().dependOn(&install_langref.step);
|
||||
@@ -334,9 +349,6 @@ pub fn build(b: *std.Build) !void {
|
||||
}
|
||||
if (target.result.os.tag == .windows) {
|
||||
inline for (.{ exe, check_case_exe }) |artifact| {
|
||||
// LLVM depends on networking as of version 18.
|
||||
artifact.linkSystemLibrary("ws2_32");
|
||||
|
||||
artifact.linkSystemLibrary("version");
|
||||
artifact.linkSystemLibrary("uuid");
|
||||
artifact.linkSystemLibrary("ole32");
|
||||
@@ -489,7 +501,6 @@ pub fn build(b: *std.Build) !void {
|
||||
.skip_single_threaded = true,
|
||||
.skip_non_native = skip_non_native,
|
||||
.skip_libc = true,
|
||||
.no_builtin = true,
|
||||
}));
|
||||
|
||||
test_step.dependOn(tests.addModuleTests(b, .{
|
||||
@@ -502,7 +513,6 @@ pub fn build(b: *std.Build) !void {
|
||||
.skip_single_threaded = true,
|
||||
.skip_non_native = skip_non_native,
|
||||
.skip_libc = true,
|
||||
.no_builtin = true,
|
||||
}));
|
||||
|
||||
test_step.dependOn(tests.addCompareOutputTests(b, test_filters, optimization_modes));
|
||||
@@ -652,11 +662,10 @@ const exe_cflags = [_][]const u8{
|
||||
"-D__STDC_FORMAT_MACROS",
|
||||
"-D__STDC_LIMIT_MACROS",
|
||||
"-D_GNU_SOURCE",
|
||||
"-fvisibility-inlines-hidden",
|
||||
"-fno-exceptions",
|
||||
"-fno-rtti",
|
||||
"-fno-stack-protector",
|
||||
"-fvisibility-inlines-hidden",
|
||||
"-Wno-type-limits",
|
||||
"-Werror=type-limits",
|
||||
"-Wno-missing-braces",
|
||||
"-Wno-comment",
|
||||
};
|
||||
@@ -708,7 +717,7 @@ fn addCmakeCfgOptionsToExe(
|
||||
};
|
||||
exe.linkSystemLibrary("unwind");
|
||||
},
|
||||
.ios, .macos, .watchos, .tvos, .visionos => {
|
||||
.ios, .macos, .watchos, .tvos => {
|
||||
exe.linkLibCpp();
|
||||
},
|
||||
.windows => {
|
||||
@@ -1045,7 +1054,6 @@ const clang_libs = [_][]const u8{
|
||||
"clangAST",
|
||||
"clangParse",
|
||||
"clangSema",
|
||||
"clangAPINotes",
|
||||
"clangBasic",
|
||||
"clangEdit",
|
||||
"clangLex",
|
||||
@@ -1075,7 +1083,6 @@ const llvm_libs = [_][]const u8{
|
||||
"LLVMXRay",
|
||||
"LLVMLibDriver",
|
||||
"LLVMDlltoolDriver",
|
||||
"LLVMTextAPIBinaryReader",
|
||||
"LLVMCoverage",
|
||||
"LLVMLineEditor",
|
||||
"LLVMXCoreDisassembler",
|
||||
@@ -1177,7 +1184,6 @@ const llvm_libs = [_][]const u8{
|
||||
"LLVMAArch64Desc",
|
||||
"LLVMAArch64Utils",
|
||||
"LLVMAArch64Info",
|
||||
"LLVMOrcDebugging",
|
||||
"LLVMOrcJIT",
|
||||
"LLVMWindowsDriver",
|
||||
"LLVMMCJIT",
|
||||
@@ -1197,7 +1203,6 @@ const llvm_libs = [_][]const u8{
|
||||
"LLVMMCDisassembler",
|
||||
"LLVMLTO",
|
||||
"LLVMPasses",
|
||||
"LLVMHipStdPar",
|
||||
"LLVMCFGuard",
|
||||
"LLVMCoroutines",
|
||||
"LLVMipo",
|
||||
@@ -1205,13 +1210,10 @@ const llvm_libs = [_][]const u8{
|
||||
"LLVMLinker",
|
||||
"LLVMInstrumentation",
|
||||
"LLVMFrontendOpenMP",
|
||||
"LLVMFrontendOffloading",
|
||||
"LLVMFrontendOpenACC",
|
||||
"LLVMFrontendHLSL",
|
||||
"LLVMFrontendDriver",
|
||||
"LLVMExtensions",
|
||||
"LLVMDWARFLinkerParallel",
|
||||
"LLVMDWARFLinkerClassic",
|
||||
"LLVMDWARFLinker",
|
||||
"LLVMGlobalISel",
|
||||
"LLVMMIRParser",
|
||||
@@ -1254,57 +1256,3 @@ const llvm_libs = [_][]const u8{
|
||||
"LLVMSupport",
|
||||
"LLVMDemangle",
|
||||
};
|
||||
|
||||
fn generateLangRef(b: *std.Build) std.Build.LazyPath {
|
||||
const doctest_exe = b.addExecutable(.{
|
||||
.name = "doctest",
|
||||
.root_source_file = b.path("tools/doctest.zig"),
|
||||
.target = b.host,
|
||||
.optimize = .Debug,
|
||||
});
|
||||
|
||||
var dir = b.build_root.handle.openDir("doc/langref", .{ .iterate = true }) catch |err| {
|
||||
std.debug.panic("unable to open 'doc/langref' directory: {s}", .{@errorName(err)});
|
||||
};
|
||||
defer dir.close();
|
||||
|
||||
var wf = b.addWriteFiles();
|
||||
|
||||
var it = dir.iterateAssumeFirstIteration();
|
||||
while (it.next() catch @panic("failed to read dir")) |entry| {
|
||||
if (std.mem.startsWith(u8, entry.name, ".") or entry.kind != .file)
|
||||
continue;
|
||||
|
||||
const out_basename = b.fmt("{s}.out", .{std.fs.path.stem(entry.name)});
|
||||
const cmd = b.addRunArtifact(doctest_exe);
|
||||
cmd.addArgs(&.{
|
||||
"--zig", b.graph.zig_exe,
|
||||
// TODO: enhance doctest to use "--listen=-" rather than operating
|
||||
// in a temporary directory
|
||||
"--cache-root", b.cache_root.path orelse ".",
|
||||
});
|
||||
if (b.zig_lib_dir) |p| {
|
||||
cmd.addArg("--zig-lib-dir");
|
||||
cmd.addDirectoryArg(p);
|
||||
}
|
||||
cmd.addArgs(&.{"-i"});
|
||||
cmd.addFileArg(b.path(b.fmt("doc/langref/{s}", .{entry.name})));
|
||||
|
||||
cmd.addArgs(&.{"-o"});
|
||||
_ = wf.addCopyFile(cmd.addOutputFileArg(out_basename), out_basename);
|
||||
}
|
||||
|
||||
const docgen_exe = b.addExecutable(.{
|
||||
.name = "docgen",
|
||||
.root_source_file = b.path("tools/docgen.zig"),
|
||||
.target = b.host,
|
||||
.optimize = .Debug,
|
||||
});
|
||||
|
||||
const docgen_cmd = b.addRunArtifact(docgen_exe);
|
||||
docgen_cmd.addArgs(&.{"--code-dir"});
|
||||
docgen_cmd.addDirectoryArg(wf.getDirectory());
|
||||
|
||||
docgen_cmd.addFileArg(b.path("doc/langref.html.in"));
|
||||
return docgen_cmd.addOutputFileArg("langref.html");
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ set -e
|
||||
ARCH="$(uname -m)"
|
||||
TARGET="$ARCH-linux-musl"
|
||||
MCPU="baseline"
|
||||
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.13.0-dev.130+98a30acad"
|
||||
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.12.0-dev.203+d3bc1cfc4"
|
||||
PREFIX="$HOME/deps/$CACHE_BASENAME"
|
||||
ZIG="$PREFIX/bin/zig"
|
||||
|
||||
@@ -53,7 +53,6 @@ ninja install
|
||||
echo "Looking for non-conforming code formatting..."
|
||||
stage3-debug/bin/zig fmt --check .. \
|
||||
--exclude ../test/cases/ \
|
||||
--exclude ../doc/ \
|
||||
--exclude ../build-debug
|
||||
|
||||
# simultaneously test building self-hosted without LLVM and with 32-bit arm
|
||||
|
||||
@@ -8,7 +8,7 @@ set -e
|
||||
ARCH="$(uname -m)"
|
||||
TARGET="$ARCH-linux-musl"
|
||||
MCPU="baseline"
|
||||
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.13.0-dev.130+98a30acad"
|
||||
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.12.0-dev.203+d3bc1cfc4"
|
||||
PREFIX="$HOME/deps/$CACHE_BASENAME"
|
||||
ZIG="$PREFIX/bin/zig"
|
||||
|
||||
@@ -53,7 +53,6 @@ ninja install
|
||||
echo "Looking for non-conforming code formatting..."
|
||||
stage3-release/bin/zig fmt --check .. \
|
||||
--exclude ../test/cases/ \
|
||||
--exclude ../doc/ \
|
||||
--exclude ../build-release
|
||||
|
||||
# simultaneously test building self-hosted without LLVM and with 32-bit arm
|
||||
|
||||
@@ -9,16 +9,10 @@ set -e
|
||||
ZIGDIR="$PWD"
|
||||
TARGET="$ARCH-macos-none"
|
||||
MCPU="baseline"
|
||||
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.13.0-dev.130+98a30acad"
|
||||
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.12.0-dev.467+0345d7866"
|
||||
PREFIX="$HOME/$CACHE_BASENAME"
|
||||
ZIG="$PREFIX/bin/zig"
|
||||
|
||||
if [ ! -d "$PREFIX" ]; then
|
||||
cd $HOME
|
||||
curl -L -O "https://ziglang.org/deps/$CACHE_BASENAME.tar.xz"
|
||||
tar xf "$CACHE_BASENAME.tar.xz"
|
||||
fi
|
||||
|
||||
cd $ZIGDIR
|
||||
|
||||
# Make the `zig version` number consistent.
|
||||
|
||||
@@ -9,16 +9,10 @@ set -e
|
||||
ZIGDIR="$PWD"
|
||||
TARGET="$ARCH-macos-none"
|
||||
MCPU="baseline"
|
||||
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.13.0-dev.130+98a30acad"
|
||||
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.12.0-dev.467+0345d7866"
|
||||
PREFIX="$HOME/$CACHE_BASENAME"
|
||||
ZIG="$PREFIX/bin/zig"
|
||||
|
||||
if [ ! -d "$PREFIX" ]; then
|
||||
cd $HOME
|
||||
curl -L -O "https://ziglang.org/deps/$CACHE_BASENAME.tar.xz"
|
||||
tar xf "$CACHE_BASENAME.tar.xz"
|
||||
fi
|
||||
|
||||
cd $ZIGDIR
|
||||
|
||||
# Make the `zig version` number consistent.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
$TARGET = "$($Env:ARCH)-windows-gnu"
|
||||
$ZIG_LLVM_CLANG_LLD_NAME = "zig+llvm+lld+clang-$TARGET-0.13.0-dev.130+98a30acad"
|
||||
$ZIG_LLVM_CLANG_LLD_NAME = "zig+llvm+lld+clang-$TARGET-0.12.0-dev.2087+e9a18010b"
|
||||
$MCPU = "baseline"
|
||||
$ZIG_LLVM_CLANG_LLD_URL = "https://ziglang.org/deps/$ZIG_LLVM_CLANG_LLD_NAME.zip"
|
||||
$PREFIX_PATH = "$(Get-Location)\..\$ZIG_LLVM_CLANG_LLD_NAME"
|
||||
|
||||
@@ -8,7 +8,7 @@ set -e
|
||||
ARCH="$(uname -m)"
|
||||
TARGET="$ARCH-linux-musl"
|
||||
MCPU="baseline"
|
||||
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.13.0-dev.130+98a30acad"
|
||||
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.12.0-dev.203+d3bc1cfc4"
|
||||
PREFIX="$HOME/deps/$CACHE_BASENAME"
|
||||
ZIG="$PREFIX/bin/zig"
|
||||
|
||||
@@ -61,7 +61,6 @@ ninja install
|
||||
echo "Looking for non-conforming code formatting..."
|
||||
stage3-debug/bin/zig fmt --check .. \
|
||||
--exclude ../test/cases/ \
|
||||
--exclude ../doc/ \
|
||||
--exclude ../build-debug
|
||||
|
||||
# simultaneously test building self-hosted without LLVM and with 32-bit arm
|
||||
|
||||
@@ -8,7 +8,7 @@ set -e
|
||||
ARCH="$(uname -m)"
|
||||
TARGET="$ARCH-linux-musl"
|
||||
MCPU="baseline"
|
||||
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.13.0-dev.130+98a30acad"
|
||||
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.12.0-dev.203+d3bc1cfc4"
|
||||
PREFIX="$HOME/deps/$CACHE_BASENAME"
|
||||
ZIG="$PREFIX/bin/zig"
|
||||
|
||||
@@ -61,7 +61,6 @@ ninja install
|
||||
echo "Looking for non-conforming code formatting..."
|
||||
stage3-release/bin/zig fmt --check .. \
|
||||
--exclude ../test/cases/ \
|
||||
--exclude ../doc/ \
|
||||
--exclude ../build-debug \
|
||||
--exclude ../build-release
|
||||
|
||||
|
||||
@@ -6,16 +6,17 @@ set -e
|
||||
ZIGDIR="$PWD"
|
||||
TARGET="$ARCH-macos-none"
|
||||
MCPU="baseline"
|
||||
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.13.0-dev.130+98a30acad"
|
||||
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.12.0-dev.467+0345d7866"
|
||||
PREFIX="$HOME/$CACHE_BASENAME"
|
||||
JOBS="-j3"
|
||||
ZIG="$PREFIX/bin/zig"
|
||||
|
||||
if [ ! -d "$PREFIX" ]; then
|
||||
cd $HOME
|
||||
curl -L -O "https://ziglang.org/deps/$CACHE_BASENAME.tar.xz"
|
||||
tar xf "$CACHE_BASENAME.tar.xz"
|
||||
fi
|
||||
rm -rf $PREFIX
|
||||
cd $HOME
|
||||
|
||||
curl -L -O "https://ziglang.org/deps/$CACHE_BASENAME.tar.xz"
|
||||
tar xf "$CACHE_BASENAME.tar.xz"
|
||||
|
||||
ZIG="$PREFIX/bin/zig"
|
||||
|
||||
cd $ZIGDIR
|
||||
|
||||
|
||||
@@ -1,20 +1,10 @@
|
||||
$TARGET = "$($Env:ARCH)-windows-gnu"
|
||||
$ZIG_LLVM_CLANG_LLD_NAME = "zig+llvm+lld+clang-$TARGET-0.13.0-dev.130+98a30acad"
|
||||
$ZIG_LLVM_CLANG_LLD_NAME = "zig+llvm+lld+clang-$TARGET-0.12.0-dev.2073+402fe565a"
|
||||
$MCPU = "baseline"
|
||||
$ZIG_LLVM_CLANG_LLD_URL = "https://ziglang.org/deps/$ZIG_LLVM_CLANG_LLD_NAME.zip"
|
||||
$PREFIX_PATH = "$($Env:USERPROFILE)\$ZIG_LLVM_CLANG_LLD_NAME"
|
||||
$ZIG = "$PREFIX_PATH\bin\zig.exe"
|
||||
$ZIG_LIB_DIR = "$(Get-Location)\lib"
|
||||
|
||||
if (!(Test-Path "$PREFIX_PATH.zip")) {
|
||||
Write-Output "Downloading $ZIG_LLVM_CLANG_LLD_URL"
|
||||
Invoke-WebRequest -Uri "$ZIG_LLVM_CLANG_LLD_URL" -OutFile "$PREFIX_PATH.zip"
|
||||
|
||||
Write-Output "Extracting..."
|
||||
Add-Type -AssemblyName System.IO.Compression.FileSystem ;
|
||||
[System.IO.Compression.ZipFile]::ExtractToDirectory("$PREFIX_PATH.zip", "$PREFIX_PATH\..")
|
||||
}
|
||||
|
||||
function CheckLastExitCode {
|
||||
if (!$?) {
|
||||
exit 1
|
||||
@@ -35,12 +25,6 @@ Remove-Item -Path 'build-debug' -Recurse -Force -ErrorAction Ignore
|
||||
New-Item -Path 'build-debug' -ItemType Directory
|
||||
Set-Location -Path 'build-debug'
|
||||
|
||||
# Override the cache directories because they won't actually help other CI runs
|
||||
# which will be testing alternate versions of zig, and ultimately would just
|
||||
# fill up space on the hard drive for no reason.
|
||||
$Env:ZIG_GLOBAL_CACHE_DIR="$(Get-Location)\zig-global-cache"
|
||||
$Env:ZIG_LOCAL_CACHE_DIR="$(Get-Location)\zig-local-cache"
|
||||
|
||||
# CMake gives a syntax error when file paths with backward slashes are used.
|
||||
# Here, we use forward slashes only to work around this.
|
||||
& cmake .. `
|
||||
|
||||
@@ -1,20 +1,10 @@
|
||||
$TARGET = "$($Env:ARCH)-windows-gnu"
|
||||
$ZIG_LLVM_CLANG_LLD_NAME = "zig+llvm+lld+clang-$TARGET-0.13.0-dev.130+98a30acad"
|
||||
$ZIG_LLVM_CLANG_LLD_NAME = "zig+llvm+lld+clang-$TARGET-0.12.0-dev.2073+402fe565a"
|
||||
$MCPU = "baseline"
|
||||
$ZIG_LLVM_CLANG_LLD_URL = "https://ziglang.org/deps/$ZIG_LLVM_CLANG_LLD_NAME.zip"
|
||||
$PREFIX_PATH = "$($Env:USERPROFILE)\$ZIG_LLVM_CLANG_LLD_NAME"
|
||||
$ZIG = "$PREFIX_PATH\bin\zig.exe"
|
||||
$ZIG_LIB_DIR = "$(Get-Location)\lib"
|
||||
|
||||
if (!(Test-Path "$PREFIX_PATH.zip")) {
|
||||
Write-Output "Downloading $ZIG_LLVM_CLANG_LLD_URL"
|
||||
Invoke-WebRequest -Uri "$ZIG_LLVM_CLANG_LLD_URL" -OutFile "$PREFIX_PATH.zip"
|
||||
|
||||
Write-Output "Extracting..."
|
||||
Add-Type -AssemblyName System.IO.Compression.FileSystem ;
|
||||
[System.IO.Compression.ZipFile]::ExtractToDirectory("$PREFIX_PATH.zip", "$PREFIX_PATH\..")
|
||||
}
|
||||
|
||||
function CheckLastExitCode {
|
||||
if (!$?) {
|
||||
exit 1
|
||||
@@ -35,12 +25,6 @@ Remove-Item -Path 'build-release' -Recurse -Force -ErrorAction Ignore
|
||||
New-Item -Path 'build-release' -ItemType Directory
|
||||
Set-Location -Path 'build-release'
|
||||
|
||||
# Override the cache directories because they won't actually help other CI runs
|
||||
# which will be testing alternate versions of zig, and ultimately would just
|
||||
# fill up space on the hard drive for no reason.
|
||||
$Env:ZIG_GLOBAL_CACHE_DIR="$(Get-Location)\zig-global-cache"
|
||||
$Env:ZIG_LOCAL_CACHE_DIR="$(Get-Location)\zig-local-cache"
|
||||
|
||||
# CMake gives a syntax error when file paths with backward slashes are used.
|
||||
# Here, we use forward slashes only to work around this.
|
||||
& cmake .. `
|
||||
|
||||
@@ -17,9 +17,9 @@ find_path(CLANG_INCLUDE_DIRS NAMES clang/Frontend/ASTUnit.h
|
||||
if(${LLVM_LINK_MODE} STREQUAL "shared")
|
||||
find_library(CLANG_LIBRARIES
|
||||
NAMES
|
||||
libclang-cpp.so.18
|
||||
clang-cpp-18.0
|
||||
clang-cpp180
|
||||
libclang-cpp.so.17
|
||||
clang-cpp-17.0
|
||||
clang-cpp170
|
||||
clang-cpp
|
||||
NAMES_PER_DIR
|
||||
HINTS "${LLVM_LIBDIRS}"
|
||||
@@ -55,7 +55,6 @@ else()
|
||||
FIND_AND_ADD_CLANG_LIB(clangAST)
|
||||
FIND_AND_ADD_CLANG_LIB(clangParse)
|
||||
FIND_AND_ADD_CLANG_LIB(clangSema)
|
||||
FIND_AND_ADD_CLANG_LIB(clangAPINotes)
|
||||
FIND_AND_ADD_CLANG_LIB(clangBasic)
|
||||
FIND_AND_ADD_CLANG_LIB(clangEdit)
|
||||
FIND_AND_ADD_CLANG_LIB(clangLex)
|
||||
|
||||
@@ -9,21 +9,21 @@
|
||||
find_path(LLD_INCLUDE_DIRS NAMES lld/Common/Driver.h
|
||||
HINTS ${LLVM_INCLUDE_DIRS}
|
||||
PATHS
|
||||
/usr/lib/llvm-18/include
|
||||
/usr/local/llvm180/include
|
||||
/usr/local/llvm18/include
|
||||
/usr/local/opt/llvm@18/include
|
||||
/opt/homebrew/opt/llvm@18/include
|
||||
/usr/lib/llvm-17/include
|
||||
/usr/local/llvm170/include
|
||||
/usr/local/llvm17/include
|
||||
/usr/local/opt/llvm@17/include
|
||||
/opt/homebrew/opt/llvm@17/include
|
||||
/mingw64/include)
|
||||
|
||||
find_library(LLD_LIBRARY NAMES lld-18.0 lld180 lld NAMES_PER_DIR
|
||||
find_library(LLD_LIBRARY NAMES lld-17.0 lld170 lld NAMES_PER_DIR
|
||||
HINTS ${LLVM_LIBDIRS}
|
||||
PATHS
|
||||
/usr/lib/llvm-18/lib
|
||||
/usr/local/llvm180/lib
|
||||
/usr/local/llvm18/lib
|
||||
/usr/local/opt/llvm@18/lib
|
||||
/opt/homebrew/opt/llvm@18/lib
|
||||
/usr/lib/llvm-17/lib
|
||||
/usr/local/llvm170/lib
|
||||
/usr/local/llvm17/lib
|
||||
/usr/local/opt/llvm@17/lib
|
||||
/opt/homebrew/opt/llvm@17/lib
|
||||
)
|
||||
if(EXISTS ${LLD_LIBRARY})
|
||||
set(LLD_LIBRARIES ${LLD_LIBRARY})
|
||||
@@ -34,11 +34,11 @@ else()
|
||||
HINTS ${LLVM_LIBDIRS}
|
||||
PATHS
|
||||
${LLD_LIBDIRS}
|
||||
/usr/lib/llvm-18/lib
|
||||
/usr/local/llvm180/lib
|
||||
/usr/local/llvm18/lib
|
||||
/usr/local/opt/llvm@18/lib
|
||||
/opt/homebrew/opt/llvm@18/lib
|
||||
/usr/lib/llvm-17/lib
|
||||
/usr/local/llvm170/lib
|
||||
/usr/local/llvm17/lib
|
||||
/usr/local/opt/llvm@17/lib
|
||||
/opt/homebrew/opt/llvm@17/lib
|
||||
/mingw64/lib
|
||||
/c/msys64/mingw64/lib
|
||||
c:/msys64/mingw64/lib)
|
||||
|
||||
@@ -12,17 +12,14 @@
|
||||
if(ZIG_USE_LLVM_CONFIG)
|
||||
set(LLVM_CONFIG_ERROR_MESSAGES "")
|
||||
while(1)
|
||||
# If this variable is not unset, the same result is returned even though
|
||||
# the ignore list has changed, causing the configure process to not
|
||||
# terminate when the right LLVM version is not found.
|
||||
unset(LLVM_CONFIG_EXE CACHE)
|
||||
find_program(LLVM_CONFIG_EXE
|
||||
NAMES llvm-config-18 llvm-config-18.0 llvm-config180 llvm-config18 llvm-config NAMES_PER_DIR
|
||||
NAMES llvm-config-17 llvm-config-17.0 llvm-config170 llvm-config17 llvm-config NAMES_PER_DIR
|
||||
PATHS
|
||||
"/mingw64/bin"
|
||||
"/c/msys64/mingw64/bin"
|
||||
"c:/msys64/mingw64/bin"
|
||||
"C:/Libraries/llvm-18.0.0/bin")
|
||||
"C:/Libraries/llvm-17.0.0/bin")
|
||||
|
||||
if ("${LLVM_CONFIG_EXE}" STREQUAL "LLVM_CONFIG_EXE-NOTFOUND")
|
||||
if (NOT LLVM_CONFIG_ERROR_MESSAGES STREQUAL "")
|
||||
@@ -40,9 +37,9 @@ if(ZIG_USE_LLVM_CONFIG)
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
|
||||
get_filename_component(LLVM_CONFIG_DIR "${LLVM_CONFIG_EXE}" DIRECTORY)
|
||||
if("${LLVM_CONFIG_VERSION}" VERSION_LESS 18 OR "${LLVM_CONFIG_VERSION}" VERSION_EQUAL 19 OR "${LLVM_CONFIG_VERSION}" VERSION_GREATER 19)
|
||||
if("${LLVM_CONFIG_VERSION}" VERSION_LESS 17 OR "${LLVM_CONFIG_VERSION}" VERSION_EQUAL 18 OR "${LLVM_CONFIG_VERSION}" VERSION_GREATER 18)
|
||||
# Save the error message, in case this is the last llvm-config we find
|
||||
list(APPEND LLVM_CONFIG_ERROR_MESSAGES "expected LLVM 18.x but found ${LLVM_CONFIG_VERSION} using ${LLVM_CONFIG_EXE}")
|
||||
list(APPEND LLVM_CONFIG_ERROR_MESSAGES "expected LLVM 17.x but found ${LLVM_CONFIG_VERSION} using ${LLVM_CONFIG_EXE}")
|
||||
|
||||
# Ignore this directory and try the search again
|
||||
list(APPEND CMAKE_IGNORE_PATH "${LLVM_CONFIG_DIR}")
|
||||
@@ -66,9 +63,9 @@ if(ZIG_USE_LLVM_CONFIG)
|
||||
if (LLVM_CONFIG_ERROR)
|
||||
# Save the error message, in case this is the last llvm-config we find
|
||||
if (ZIG_SHARED_LLVM)
|
||||
list(APPEND LLVM_CONFIG_ERROR_MESSAGES "LLVM 18.x found at ${LLVM_CONFIG_EXE} does not support linking as a shared library")
|
||||
list(APPEND LLVM_CONFIG_ERROR_MESSAGES "LLVM 17.x found at ${LLVM_CONFIG_EXE} does not support linking as a shared library")
|
||||
else()
|
||||
list(APPEND LLVM_CONFIG_ERROR_MESSAGES "LLVM 18.x found at ${LLVM_CONFIG_EXE} does not support linking as a static library")
|
||||
list(APPEND LLVM_CONFIG_ERROR_MESSAGES "LLVM 17.x found at ${LLVM_CONFIG_EXE} does not support linking as a static library")
|
||||
endif()
|
||||
|
||||
# Ignore this directory and try the search again
|
||||
@@ -198,7 +195,6 @@ else()
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMXRay)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMLibDriver)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMDlltoolDriver)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMTextAPIBinaryReader)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMCoverage)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMLineEditor)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMXCoreDisassembler)
|
||||
@@ -300,7 +296,6 @@ else()
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMAArch64Desc)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMAArch64Utils)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMAArch64Info)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMOrcDebugging)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMOrcJIT)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMWindowsDriver)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMMCJIT)
|
||||
@@ -320,7 +315,6 @@ else()
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMMCDisassembler)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMLTO)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMPasses)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMHipStdPar)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMCFGuard)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMCoroutines)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMipo)
|
||||
@@ -328,13 +322,10 @@ else()
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMLinker)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMInstrumentation)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMFrontendOpenMP)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMFrontendOffloading)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMFrontendOpenACC)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMFrontendHLSL)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMFrontendDriver)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMExtensions)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMDWARFLinkerParallel)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMDWARFLinkerClassic)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMDWARFLinker)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMGlobalISel)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMMIRParser)
|
||||
|
||||
13
cmake/c_flag_overrides.cmake
Normal file
13
cmake/c_flag_overrides.cmake
Normal file
@@ -0,0 +1,13 @@
|
||||
if(MSVC)
|
||||
set(CMAKE_C_FLAGS_DEBUG_INIT
|
||||
"/D_DEBUG /MTd /Zi /Ob0 /Od /RTC1")
|
||||
|
||||
set(CMAKE_C_FLAGS_MINSIZEREL_INIT
|
||||
"/MT /O1 /Ob1 /D NDEBUG")
|
||||
|
||||
set(CMAKE_C_FLAGS_RELEASE_INIT
|
||||
"/MT /O2 /Ob1 /D NDEBUG")
|
||||
|
||||
set(CMAKE_C_FLAGS_RELWITHDEBINFO_INIT
|
||||
"/MT /Zi /O2 /Ob1 /D NDEBUG")
|
||||
endif()
|
||||
13
cmake/cxx_flag_overrides.cmake
Normal file
13
cmake/cxx_flag_overrides.cmake
Normal file
@@ -0,0 +1,13 @@
|
||||
if(MSVC)
|
||||
set(CMAKE_CXX_FLAGS_DEBUG_INIT
|
||||
"/D_DEBUG /MTd /Zi /Ob0 /Od /RTC1")
|
||||
|
||||
set(CMAKE_CXX_FLAGS_MINSIZEREL_INIT
|
||||
"/MT /O1 /Ob1 /D NDEBUG")
|
||||
|
||||
set(CMAKE_CXX_FLAGS_RELEASE_INIT
|
||||
"/MT /O2 /Ob1 /D NDEBUG")
|
||||
|
||||
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT
|
||||
"/MT /Zi /O2 /Ob1 /D NDEBUG")
|
||||
endif()
|
||||
@@ -1,7 +1,7 @@
|
||||
set(ZIG_INSTALL_ARGS build --prefix "${CMAKE_INSTALL_PREFIX}" ${ZIG_BUILD_ARGS})
|
||||
set(ZIG_INSTALL_ARGS build ${ZIG_BUILD_ARGS} --prefix "${CMAKE_INSTALL_PREFIX}")
|
||||
execute_process(
|
||||
COMMAND "${ZIG_EXECUTABLE}" ${ZIG_INSTALL_ARGS}
|
||||
WORKING_DIRECTORY "${ZIG2_WORKING_DIR}"
|
||||
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
|
||||
RESULT_VARIABLE _result)
|
||||
|
||||
if(_result)
|
||||
|
||||
5414
doc/langref.html.in
5414
doc/langref.html.in
File diff suppressed because it is too large
Load Diff
@@ -1,60 +0,0 @@
|
||||
pub fn syscall1(number: usize, arg1: usize) usize {
|
||||
// Inline assembly is an expression which returns a value.
|
||||
// the `asm` keyword begins the expression.
|
||||
return asm
|
||||
// `volatile` is an optional modifier that tells Zig this
|
||||
// inline assembly expression has side-effects. Without
|
||||
// `volatile`, Zig is allowed to delete the inline assembly
|
||||
// code if the result is unused.
|
||||
volatile (
|
||||
// Next is a comptime string which is the assembly code.
|
||||
// Inside this string one may use `%[ret]`, `%[number]`,
|
||||
// or `%[arg1]` where a register is expected, to specify
|
||||
// the register that Zig uses for the argument or return value,
|
||||
// if the register constraint strings are used. However in
|
||||
// the below code, this is not used. A literal `%` can be
|
||||
// obtained by escaping it with a double percent: `%%`.
|
||||
// Often multiline string syntax comes in handy here.
|
||||
\\syscall
|
||||
// Next is the output. It is possible in the future Zig will
|
||||
// support multiple outputs, depending on how
|
||||
// https://github.com/ziglang/zig/issues/215 is resolved.
|
||||
// It is allowed for there to be no outputs, in which case
|
||||
// this colon would be directly followed by the colon for the inputs.
|
||||
:
|
||||
// This specifies the name to be used in `%[ret]` syntax in
|
||||
// the above assembly string. This example does not use it,
|
||||
// but the syntax is mandatory.
|
||||
[ret]
|
||||
// Next is the output constraint string. This feature is still
|
||||
// considered unstable in Zig, and so LLVM/GCC documentation
|
||||
// must be used to understand the semantics.
|
||||
// http://releases.llvm.org/10.0.0/docs/LangRef.html#inline-asm-constraint-string
|
||||
// https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html
|
||||
// In this example, the constraint string means "the result value of
|
||||
// this inline assembly instruction is whatever is in $rax".
|
||||
"={rax}"
|
||||
// Next is either a value binding, or `->` and then a type. The
|
||||
// type is the result type of the inline assembly expression.
|
||||
// If it is a value binding, then `%[ret]` syntax would be used
|
||||
// to refer to the register bound to the value.
|
||||
(-> usize),
|
||||
// Next is the list of inputs.
|
||||
// The constraint for these inputs means, "when the assembly code is
|
||||
// executed, $rax shall have the value of `number` and $rdi shall have
|
||||
// the value of `arg1`". Any number of input parameters is allowed,
|
||||
// including none.
|
||||
: [number] "{rax}" (number),
|
||||
[arg1] "{rdi}" (arg1),
|
||||
// Next is the list of clobbers. These declare a set of registers whose
|
||||
// values will not be preserved by the execution of this assembly code.
|
||||
// These do not include output or input registers. The special clobber
|
||||
// value of "memory" means that the assembly writes to arbitrary undeclared
|
||||
// memory locations - not only the memory pointed to by a declared indirect
|
||||
// output. In this example we list $rcx and $r11 because it is known the
|
||||
// kernel syscall does not preserve these registers.
|
||||
: "rcx", "r11"
|
||||
);
|
||||
}
|
||||
|
||||
// syntax
|
||||
@@ -1,13 +0,0 @@
|
||||
const print = @import("std").debug.print;
|
||||
pub fn main() void {
|
||||
const byte: u8 = 255;
|
||||
|
||||
const ov = @addWithOverflow(byte, 10);
|
||||
if (ov[1] != 0) {
|
||||
print("overflowed result: {}\n", .{ov[0]});
|
||||
} else {
|
||||
print("result: {}\n", .{ov[0]});
|
||||
}
|
||||
}
|
||||
|
||||
// exe=succeed
|
||||
@@ -1,16 +0,0 @@
|
||||
const Node = struct {
|
||||
next: ?*Node,
|
||||
name: []const u8,
|
||||
};
|
||||
|
||||
var node_a = Node{
|
||||
.next = null,
|
||||
.name = "Node A",
|
||||
};
|
||||
|
||||
var node_b = Node{
|
||||
.next = &node_a,
|
||||
.name = "Node B",
|
||||
};
|
||||
|
||||
// syntax
|
||||
@@ -1,9 +0,0 @@
|
||||
const print = @import("std").debug.print;
|
||||
|
||||
pub fn main() void {
|
||||
var x: i32 = undefined;
|
||||
x = 1;
|
||||
print("{d}", .{x});
|
||||
}
|
||||
|
||||
// exe=succeed
|
||||
@@ -1,26 +0,0 @@
|
||||
const Threshold = struct {
|
||||
minimum: f32 = 0.25,
|
||||
maximum: f32 = 0.75,
|
||||
|
||||
const Category = enum { low, medium, high };
|
||||
|
||||
fn categorize(t: Threshold, value: f32) Category {
|
||||
assert(t.maximum >= t.minimum);
|
||||
if (value < t.minimum) return .low;
|
||||
if (value > t.maximum) return .high;
|
||||
return .medium;
|
||||
}
|
||||
};
|
||||
|
||||
pub fn main() !void {
|
||||
var threshold: Threshold = .{
|
||||
.maximum = 0.20,
|
||||
};
|
||||
const category = threshold.categorize(0.90);
|
||||
try std.io.getStdOut().writeAll(@tagName(category));
|
||||
}
|
||||
|
||||
const std = @import("std");
|
||||
const assert = std.debug.assert;
|
||||
|
||||
// exe=fail
|
||||
@@ -1,17 +0,0 @@
|
||||
const base64 = @import("std").base64;
|
||||
|
||||
export fn decode_base_64(
|
||||
dest_ptr: [*]u8,
|
||||
dest_len: usize,
|
||||
source_ptr: [*]const u8,
|
||||
source_len: usize,
|
||||
) usize {
|
||||
const src = source_ptr[0..source_len];
|
||||
const dest = dest_ptr[0..dest_len];
|
||||
const base64_decoder = base64.standard.Decoder;
|
||||
const decoded_size = base64_decoder.calcSizeForSlice(src) catch unreachable;
|
||||
base64_decoder.decode(dest[0..decoded_size], src) catch unreachable;
|
||||
return decoded_size;
|
||||
}
|
||||
|
||||
// syntax
|
||||
@@ -1,13 +0,0 @@
|
||||
const std = @import("std");
|
||||
|
||||
pub fn build(b: *std.Build) void {
|
||||
const optimize = b.standardOptimizeOption(.{});
|
||||
const exe = b.addExecutable(.{
|
||||
.name = "example",
|
||||
.root_source_file = b.path("example.zig"),
|
||||
.optimize = optimize,
|
||||
});
|
||||
b.default_step.dependOn(&exe.step);
|
||||
}
|
||||
|
||||
// syntax
|
||||
@@ -1,24 +0,0 @@
|
||||
const std = @import("std");
|
||||
|
||||
pub fn build(b: *std.Build) void {
|
||||
const lib = b.addSharedLibrary(.{
|
||||
.name = "mathtest",
|
||||
.root_source_file = b.path("mathtest.zig"),
|
||||
.version = .{ .major = 1, .minor = 0, .patch = 0 },
|
||||
});
|
||||
const exe = b.addExecutable(.{
|
||||
.name = "test",
|
||||
});
|
||||
exe.addCSourceFile(.{ .file = b.path("test.c"), .flags = &.{"-std=c99"} });
|
||||
exe.linkLibrary(lib);
|
||||
exe.linkSystemLibrary("c");
|
||||
|
||||
b.default_step.dependOn(&exe.step);
|
||||
|
||||
const run_cmd = exe.run();
|
||||
|
||||
const test_step = b.step("test", "Test the program");
|
||||
test_step.dependOn(&run_cmd.step);
|
||||
}
|
||||
|
||||
// syntax
|
||||
@@ -1,18 +0,0 @@
|
||||
const std = @import("std");
|
||||
|
||||
pub fn build(b: *std.Build) void {
|
||||
const obj = b.addObject(.{
|
||||
.name = "base64",
|
||||
.root_source_file = b.path("base64.zig"),
|
||||
});
|
||||
|
||||
const exe = b.addExecutable(.{
|
||||
.name = "test",
|
||||
});
|
||||
exe.addCSourceFile(.{ .file = b.path("test.c"), .flags = &.{"-std=c99"} });
|
||||
exe.addObject(obj);
|
||||
exe.linkSystemLibrary("c");
|
||||
b.installArtifact(exe);
|
||||
}
|
||||
|
||||
// syntax
|
||||
@@ -1,35 +0,0 @@
|
||||
pub const CallModifier = enum {
|
||||
/// Equivalent to function call syntax.
|
||||
auto,
|
||||
|
||||
/// Equivalent to async keyword used with function call syntax.
|
||||
async_kw,
|
||||
|
||||
/// Prevents tail call optimization. This guarantees that the return
|
||||
/// address will point to the callsite, as opposed to the callsite's
|
||||
/// callsite. If the call is otherwise required to be tail-called
|
||||
/// or inlined, a compile error is emitted instead.
|
||||
never_tail,
|
||||
|
||||
/// Guarantees that the call will not be inlined. If the call is
|
||||
/// otherwise required to be inlined, a compile error is emitted instead.
|
||||
never_inline,
|
||||
|
||||
/// Asserts that the function call will not suspend. This allows a
|
||||
/// non-async function to call an async function.
|
||||
no_async,
|
||||
|
||||
/// Guarantees that the call will be generated with tail call optimization.
|
||||
/// If this is not possible, a compile error is emitted instead.
|
||||
always_tail,
|
||||
|
||||
/// Guarantees that the call will inlined at the callsite.
|
||||
/// If this is not possible, a compile error is emitted instead.
|
||||
always_inline,
|
||||
|
||||
/// Evaluates the call at compile-time. If the call cannot be completed at
|
||||
/// compile-time, a compile error is emitted instead.
|
||||
compile_time,
|
||||
};
|
||||
|
||||
// syntax
|
||||
@@ -1,11 +0,0 @@
|
||||
const c = @cImport({
|
||||
// See https://github.com/ziglang/zig/issues/515
|
||||
@cDefine("_NO_CRT_STDIO_INLINE", "1");
|
||||
@cInclude("stdio.h");
|
||||
});
|
||||
pub fn main() void {
|
||||
_ = c.printf("hello\n");
|
||||
}
|
||||
|
||||
// exe=succeed
|
||||
// link_libc
|
||||
@@ -1,8 +0,0 @@
|
||||
const parseU64 = @import("error_union_parsing_u64.zig").parseU64;
|
||||
|
||||
fn doAThing(str: []u8) void {
|
||||
const number = parseU64(str, 10) catch 13;
|
||||
_ = number; // ...
|
||||
}
|
||||
|
||||
// syntax
|
||||
@@ -1,8 +0,0 @@
|
||||
const parseU64 = @import("error_union_parsing_u64.zig").parseU64;
|
||||
|
||||
fn doAThing(str: []u8) !void {
|
||||
const number = parseU64(str, 10) catch |err| return err;
|
||||
_ = number; // ...
|
||||
}
|
||||
|
||||
// syntax
|
||||
@@ -1,18 +0,0 @@
|
||||
const std = @import("std");
|
||||
|
||||
const Foo = union {
|
||||
float: f32,
|
||||
int: u32,
|
||||
};
|
||||
|
||||
pub fn main() void {
|
||||
var f = Foo{ .int = 42 };
|
||||
bar(&f);
|
||||
}
|
||||
|
||||
fn bar(f: *Foo) void {
|
||||
f.* = Foo{ .float = 12.34 };
|
||||
std.debug.print("value: {}\n", .{f.float});
|
||||
}
|
||||
|
||||
// exe=succeed
|
||||
@@ -1,16 +0,0 @@
|
||||
const Foo = struct {};
|
||||
fn doSomethingWithFoo(foo: *Foo) void {
|
||||
_ = foo;
|
||||
}
|
||||
|
||||
fn doAThing(optional_foo: ?*Foo) void {
|
||||
// do some stuff
|
||||
|
||||
if (optional_foo) |foo| {
|
||||
doSomethingWithFoo(foo);
|
||||
}
|
||||
|
||||
// do some stuff
|
||||
}
|
||||
|
||||
// syntax
|
||||
@@ -1,13 +0,0 @@
|
||||
const std = @import("std");
|
||||
|
||||
pub fn main() !void {
|
||||
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
|
||||
defer arena.deinit();
|
||||
|
||||
const allocator = arena.allocator();
|
||||
|
||||
const ptr = try allocator.create(i32);
|
||||
std.debug.print("ptr={*}\n", .{ptr});
|
||||
}
|
||||
|
||||
// exe=succeed
|
||||
@@ -1,12 +0,0 @@
|
||||
const print = @import("std").debug.print;
|
||||
|
||||
pub fn main() void {
|
||||
// Comments in Zig start with "//" and end at the next LF byte (end of line).
|
||||
// The line below is a comment and won't be executed.
|
||||
|
||||
//print("Hello?", .{});
|
||||
|
||||
print("Hello, world!\n", .{}); // another comment
|
||||
}
|
||||
|
||||
// exe=succeed
|
||||
@@ -1,11 +0,0 @@
|
||||
fn max(comptime T: type, a: T, b: T) T {
|
||||
return if (a > b) a else b;
|
||||
}
|
||||
fn gimmeTheBiggerFloat(a: f32, b: f32) f32 {
|
||||
return max(f32, a, b);
|
||||
}
|
||||
fn gimmeTheBiggerInteger(a: u64, b: u64) u64 {
|
||||
return max(u64, a, b);
|
||||
}
|
||||
|
||||
// syntax
|
||||
@@ -1,4 +0,0 @@
|
||||
const builtin = @import("builtin");
|
||||
const separator = if (builtin.os.tag == .windows) '\\' else '/';
|
||||
|
||||
// syntax
|
||||
@@ -1,7 +0,0 @@
|
||||
fn max(a: bool, b: bool) bool {
|
||||
{
|
||||
return a or b;
|
||||
}
|
||||
}
|
||||
|
||||
// syntax
|
||||
@@ -1,15 +0,0 @@
|
||||
const x = 1234;
|
||||
|
||||
fn foo() void {
|
||||
// It works at file scope as well as inside functions.
|
||||
const y = 5678;
|
||||
|
||||
// Once assigned, an identifier cannot be changed.
|
||||
y += 1;
|
||||
}
|
||||
|
||||
pub fn main() void {
|
||||
foo();
|
||||
}
|
||||
|
||||
// exe=build_fail
|
||||
@@ -1,22 +0,0 @@
|
||||
const std = @import("std");
|
||||
const expect = std.testing.expect;
|
||||
const print = std.debug.print;
|
||||
|
||||
test "defer unwinding" {
|
||||
print("\n", .{});
|
||||
|
||||
defer {
|
||||
print("1 ", .{});
|
||||
}
|
||||
defer {
|
||||
print("2 ", .{});
|
||||
}
|
||||
if (false) {
|
||||
// defers are not run if they are never executed.
|
||||
defer {
|
||||
print("3 ", .{});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// test
|
||||
@@ -1,19 +0,0 @@
|
||||
/// A structure for storing a timestamp, with nanosecond precision (this is a
|
||||
/// multiline doc comment).
|
||||
const Timestamp = struct {
|
||||
/// The number of seconds since the epoch (this is also a doc comment).
|
||||
seconds: i64, // signed so we can represent pre-1970 (not a doc comment)
|
||||
/// The number of nanoseconds past the second (doc comment again).
|
||||
nanos: u32,
|
||||
|
||||
/// Returns a `Timestamp` struct representing the Unix epoch; that is, the
|
||||
/// moment of 1970 Jan 1 00:00:00 UTC (this is a doc comment too).
|
||||
pub fn unixEpoch() Timestamp {
|
||||
return Timestamp{
|
||||
.seconds = 0,
|
||||
.nanos = 0,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
// syntax
|
||||
@@ -1,6 +0,0 @@
|
||||
const Foo = enum(c_int) { a, b, c };
|
||||
export fn entry(foo: Foo) void {
|
||||
_ = foo;
|
||||
}
|
||||
|
||||
// obj
|
||||
@@ -1,6 +0,0 @@
|
||||
const Foo = enum { a, b, c };
|
||||
export fn entry(foo: Foo) void {
|
||||
_ = foo;
|
||||
}
|
||||
|
||||
// obj=parameter of type 'enum_export_error.Foo' not allowed in function with calling convention 'C'
|
||||
@@ -1,41 +0,0 @@
|
||||
pub fn main() !void {
|
||||
try foo(12);
|
||||
}
|
||||
|
||||
fn foo(x: i32) !void {
|
||||
if (x >= 5) {
|
||||
try bar();
|
||||
} else {
|
||||
try bang2();
|
||||
}
|
||||
}
|
||||
|
||||
fn bar() !void {
|
||||
if (baz()) {
|
||||
try quux();
|
||||
} else |err| switch (err) {
|
||||
error.FileNotFound => try hello(),
|
||||
}
|
||||
}
|
||||
|
||||
fn baz() !void {
|
||||
try bang1();
|
||||
}
|
||||
|
||||
fn quux() !void {
|
||||
try bang2();
|
||||
}
|
||||
|
||||
fn hello() !void {
|
||||
try bang2();
|
||||
}
|
||||
|
||||
fn bang1() !void {
|
||||
return error.FileNotFound;
|
||||
}
|
||||
|
||||
fn bang2() !void {
|
||||
return error.PermissionDenied;
|
||||
}
|
||||
|
||||
// exe=fail
|
||||
@@ -1,41 +0,0 @@
|
||||
const std = @import("std");
|
||||
const maxInt = std.math.maxInt;
|
||||
|
||||
pub fn parseU64(buf: []const u8, radix: u8) !u64 {
|
||||
var x: u64 = 0;
|
||||
|
||||
for (buf) |c| {
|
||||
const digit = charToDigit(c);
|
||||
|
||||
if (digit >= radix) {
|
||||
return error.InvalidChar;
|
||||
}
|
||||
|
||||
// x *= radix
|
||||
var ov = @mulWithOverflow(x, radix);
|
||||
if (ov[1] != 0) return error.OverFlow;
|
||||
|
||||
// x += digit
|
||||
ov = @addWithOverflow(ov[0], digit);
|
||||
if (ov[1] != 0) return error.OverFlow;
|
||||
x = ov[0];
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
fn charToDigit(c: u8) u8 {
|
||||
return switch (c) {
|
||||
'0'...'9' => c - '0',
|
||||
'A'...'Z' => c - 'A' + 10,
|
||||
'a'...'z' => c - 'a' + 10,
|
||||
else => maxInt(u8),
|
||||
};
|
||||
}
|
||||
|
||||
test "parse u64" {
|
||||
const result = try parseU64("1234", 10);
|
||||
try std.testing.expect(result == 1234);
|
||||
}
|
||||
|
||||
// test
|
||||
@@ -1,3 +0,0 @@
|
||||
export fn @"A function name that is a complete sentence."() void {}
|
||||
|
||||
// obj
|
||||
@@ -1,7 +0,0 @@
|
||||
comptime {
|
||||
@export(internalName, .{ .name = "foo", .linkage = .strong });
|
||||
}
|
||||
|
||||
fn internalName() callconv(.C) void {}
|
||||
|
||||
// obj
|
||||
@@ -1,3 +0,0 @@
|
||||
export fn foo() void {}
|
||||
|
||||
// obj
|
||||
@@ -1,12 +0,0 @@
|
||||
const assert = @import("std").debug.assert;
|
||||
|
||||
fn fibonacci(index: i32) i32 {
|
||||
//if (index < 2) return index;
|
||||
return fibonacci(index - 1) + fibonacci(index - 2);
|
||||
}
|
||||
|
||||
test "fibonacci" {
|
||||
try comptime assert(fibonacci(7) == 13);
|
||||
}
|
||||
|
||||
// syntax
|
||||
@@ -1,14 +0,0 @@
|
||||
const floating_point = 123.0E+77;
|
||||
const another_float = 123.0;
|
||||
const yet_another = 123.0e+77;
|
||||
|
||||
const hex_floating_point = 0x103.70p-5;
|
||||
const another_hex_float = 0x103.70;
|
||||
const yet_another_hex_float = 0x103.70P-5;
|
||||
|
||||
// underscores may be placed between two digits as a visual separator
|
||||
const lightspeed = 299_792_458.000_000;
|
||||
const nanosecond = 0.000_000_001;
|
||||
const more_hex = 0x1234_5678.9ABC_CDEFp-10;
|
||||
|
||||
// syntax
|
||||
@@ -1,12 +0,0 @@
|
||||
const print = @import("std").debug.print;
|
||||
|
||||
extern fn foo_strict(x: f64) f64;
|
||||
extern fn foo_optimized(x: f64) f64;
|
||||
|
||||
pub fn main() void {
|
||||
const x = 0.001;
|
||||
print("optimized = {}\n", .{foo_optimized(x)});
|
||||
print("strict = {}\n", .{foo_strict(x)});
|
||||
}
|
||||
|
||||
// syntax
|
||||
@@ -1,15 +0,0 @@
|
||||
const std = @import("std");
|
||||
const big = @as(f64, 1 << 40);
|
||||
|
||||
export fn foo_strict(x: f64) f64 {
|
||||
return x + big - big;
|
||||
}
|
||||
|
||||
export fn foo_optimized(x: f64) f64 {
|
||||
@setFloatMode(.optimized);
|
||||
return x + big - big;
|
||||
}
|
||||
|
||||
// obj
|
||||
// optimize=ReleaseFast
|
||||
// disable_cache
|
||||
@@ -1,7 +0,0 @@
|
||||
const std = @import("std");
|
||||
|
||||
const inf = std.math.inf(f32);
|
||||
const negative_inf = -std.math.inf(f64);
|
||||
const nan = std.math.nan(f128);
|
||||
|
||||
// syntax
|
||||
@@ -1,15 +0,0 @@
|
||||
fn List(comptime T: type) type {
|
||||
return struct {
|
||||
items: []T,
|
||||
len: usize,
|
||||
};
|
||||
}
|
||||
|
||||
// The generic List data structure can be instantiated by passing in a type:
|
||||
var buffer: [10]i32 = undefined;
|
||||
var list = List(i32){
|
||||
.items = &buffer,
|
||||
.len = 0,
|
||||
};
|
||||
|
||||
// syntax
|
||||
@@ -1,11 +0,0 @@
|
||||
const parseU64 = @import("error_union_parsing_u64.zig").parseU64;
|
||||
|
||||
fn doAThing(str: []u8) void {
|
||||
const number = parseU64(str, 10) catch blk: {
|
||||
// do things
|
||||
break :blk 13;
|
||||
};
|
||||
_ = number; // number is now initialized
|
||||
}
|
||||
|
||||
// syntax
|
||||
@@ -1,8 +0,0 @@
|
||||
const std = @import("std");
|
||||
|
||||
pub fn main() !void {
|
||||
const stdout = std.io.getStdOut().writer();
|
||||
try stdout.print("Hello, {s}!\n", .{"world"});
|
||||
}
|
||||
|
||||
// exe=succeed
|
||||
@@ -1,7 +0,0 @@
|
||||
const std = @import("std");
|
||||
|
||||
pub fn main() void {
|
||||
std.debug.print("Hello, world!\n", .{});
|
||||
}
|
||||
|
||||
// exe=succeed
|
||||
@@ -1,14 +0,0 @@
|
||||
const @"identifier with spaces in it" = 0xff;
|
||||
const @"1SmallStep4Man" = 112358;
|
||||
|
||||
const c = @import("std").c;
|
||||
pub extern "c" fn @"error"() void;
|
||||
pub extern "c" fn @"fstat$INODE64"(fd: c.fd_t, buf: *c.Stat) c_int;
|
||||
|
||||
const Color = enum {
|
||||
red,
|
||||
@"really red",
|
||||
};
|
||||
const color: Color = .@"really red";
|
||||
|
||||
// syntax
|
||||
@@ -1,34 +0,0 @@
|
||||
pub fn main() noreturn {
|
||||
const msg = "hello world\n";
|
||||
_ = syscall3(SYS_write, STDOUT_FILENO, @intFromPtr(msg), msg.len);
|
||||
_ = syscall1(SYS_exit, 0);
|
||||
unreachable;
|
||||
}
|
||||
|
||||
pub const SYS_write = 1;
|
||||
pub const SYS_exit = 60;
|
||||
|
||||
pub const STDOUT_FILENO = 1;
|
||||
|
||||
pub fn syscall1(number: usize, arg1: usize) usize {
|
||||
return asm volatile ("syscall"
|
||||
: [ret] "={rax}" (-> usize),
|
||||
: [number] "{rax}" (number),
|
||||
[arg1] "{rdi}" (arg1),
|
||||
: "rcx", "r11"
|
||||
);
|
||||
}
|
||||
|
||||
pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize {
|
||||
return asm volatile ("syscall"
|
||||
: [ret] "={rax}" (-> usize),
|
||||
: [number] "{rax}" (number),
|
||||
[arg1] "{rdi}" (arg1),
|
||||
[arg2] "{rsi}" (arg2),
|
||||
[arg3] "{rdx}" (arg3),
|
||||
: "rcx", "r11"
|
||||
);
|
||||
}
|
||||
|
||||
// exe=succeed
|
||||
// target=x86_64-linux
|
||||
@@ -1,11 +0,0 @@
|
||||
test "inline function call" {
|
||||
if (foo(1200, 34) != 1234) {
|
||||
@compileError("bad");
|
||||
}
|
||||
}
|
||||
|
||||
inline fn foo(a: i32, b: i32) i32 {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
// test
|
||||
@@ -1,9 +0,0 @@
|
||||
fn isFieldOptional(comptime T: type, field_index: usize) !bool {
|
||||
const fields = @typeInfo(T).Struct.fields;
|
||||
return switch (field_index) {
|
||||
inline 0...fields.len - 1 => |idx| @typeInfo(fields[idx].type) == .Optional,
|
||||
else => return error.IndexOutOfBounds,
|
||||
};
|
||||
}
|
||||
|
||||
// syntax
|
||||
@@ -1,13 +0,0 @@
|
||||
const decimal_int = 98222;
|
||||
const hex_int = 0xff;
|
||||
const another_hex_int = 0xFF;
|
||||
const octal_int = 0o755;
|
||||
const binary_int = 0b11110000;
|
||||
|
||||
// underscores may be placed between two digits as a visual separator
|
||||
const one_billion = 1_000_000_000;
|
||||
const binary_mask = 0b1_1111_1111;
|
||||
const permissions = 0o7_5_5;
|
||||
const big_address = 0xFF80_0000_0000_0000;
|
||||
|
||||
// syntax
|
||||
@@ -1,5 +0,0 @@
|
||||
/// doc-comment
|
||||
//! top-level doc-comment
|
||||
const std = @import("std");
|
||||
|
||||
// obj=expected type expression, found 'a document comment'
|
||||
@@ -1,10 +0,0 @@
|
||||
pub export fn foo() c_int {
|
||||
var a: c_int = 1;
|
||||
_ = &a;
|
||||
var b: c_int = 2;
|
||||
_ = &b;
|
||||
return a + b;
|
||||
}
|
||||
pub const MAKELOCAL = @compileError("unable to translate C expr: unexpected token .Equal"); // macro.c:1:9
|
||||
|
||||
// syntax
|
||||
@@ -1,10 +0,0 @@
|
||||
extern fn print(i32) void;
|
||||
|
||||
export fn add(a: i32, b: i32) void {
|
||||
print(a + b);
|
||||
}
|
||||
|
||||
// exe=succeed
|
||||
// target=wasm32-freestanding
|
||||
// additional_option=-fno-entry
|
||||
// additional_option=--export=add
|
||||
@@ -1,14 +0,0 @@
|
||||
const math = @import("std").math;
|
||||
const print = @import("std").debug.print;
|
||||
pub fn main() !void {
|
||||
var byte: u8 = 255;
|
||||
|
||||
byte = if (math.add(u8, byte, 1)) |result| result else |err| {
|
||||
print("unable to add one: {s}\n", .{@errorName(err)});
|
||||
return err;
|
||||
};
|
||||
|
||||
print("result: {}\n", .{byte});
|
||||
}
|
||||
|
||||
// exe=fail
|
||||
@@ -1,5 +0,0 @@
|
||||
export fn add(a: i32, b: i32) i32 {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
// syntax
|
||||
@@ -1,10 +0,0 @@
|
||||
const hello_world_in_c =
|
||||
\\#include <stdio.h>
|
||||
\\
|
||||
\\int main(int argc, char **argv) {
|
||||
\\ printf("hello world\n");
|
||||
\\ return 0;
|
||||
\\}
|
||||
;
|
||||
|
||||
// syntax
|
||||
@@ -1,11 +0,0 @@
|
||||
const print = @import("std").debug.print;
|
||||
|
||||
pub fn main() void {
|
||||
var y: i32 = 5678;
|
||||
|
||||
y += 1;
|
||||
|
||||
print("{d}", .{y});
|
||||
}
|
||||
|
||||
// exe=succeed
|
||||
@@ -1,11 +0,0 @@
|
||||
fn cmpxchgStrongButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_value: T) ?T {
|
||||
const old_value = ptr.*;
|
||||
if (old_value == expected_value) {
|
||||
ptr.* = new_value;
|
||||
return null;
|
||||
} else {
|
||||
return old_value;
|
||||
}
|
||||
}
|
||||
|
||||
// syntax
|
||||
@@ -1,3 +0,0 @@
|
||||
const optional_value: ?i32 = null;
|
||||
|
||||
// syntax
|
||||
@@ -1,7 +0,0 @@
|
||||
// normal integer
|
||||
const normal_int: i32 = 1234;
|
||||
|
||||
// optional integer
|
||||
const optional_int: ?i32 = 5678;
|
||||
|
||||
// syntax
|
||||
@@ -1,33 +0,0 @@
|
||||
const Writer = struct {
|
||||
pub fn printValue(self: *Writer, value: anytype) !void {
|
||||
switch (@typeInfo(@TypeOf(value))) {
|
||||
.Int => {
|
||||
return self.writeInt(value);
|
||||
},
|
||||
.Float => {
|
||||
return self.writeFloat(value);
|
||||
},
|
||||
.Pointer => {
|
||||
return self.write(value);
|
||||
},
|
||||
else => {
|
||||
@compileError("Unable to print type '" ++ @typeName(@TypeOf(value)) ++ "'");
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn write(self: *Writer, value: []const u8) !void {
|
||||
_ = self;
|
||||
_ = value;
|
||||
}
|
||||
fn writeInt(self: *Writer, value: anytype) !void {
|
||||
_ = self;
|
||||
_ = value;
|
||||
}
|
||||
fn writeFloat(self: *Writer, value: anytype) !void {
|
||||
_ = self;
|
||||
_ = value;
|
||||
}
|
||||
};
|
||||
|
||||
// syntax
|
||||
@@ -1,79 +0,0 @@
|
||||
const Writer = struct {
|
||||
/// Calls print and then flushes the buffer.
|
||||
pub fn print(self: *Writer, comptime format: []const u8, args: anytype) anyerror!void {
|
||||
const State = enum {
|
||||
start,
|
||||
open_brace,
|
||||
close_brace,
|
||||
};
|
||||
|
||||
comptime var start_index: usize = 0;
|
||||
comptime var state = State.start;
|
||||
comptime var next_arg: usize = 0;
|
||||
|
||||
inline for (format, 0..) |c, i| {
|
||||
switch (state) {
|
||||
State.start => switch (c) {
|
||||
'{' => {
|
||||
if (start_index < i) try self.write(format[start_index..i]);
|
||||
state = State.open_brace;
|
||||
},
|
||||
'}' => {
|
||||
if (start_index < i) try self.write(format[start_index..i]);
|
||||
state = State.close_brace;
|
||||
},
|
||||
else => {},
|
||||
},
|
||||
State.open_brace => switch (c) {
|
||||
'{' => {
|
||||
state = State.start;
|
||||
start_index = i;
|
||||
},
|
||||
'}' => {
|
||||
try self.printValue(args[next_arg]);
|
||||
next_arg += 1;
|
||||
state = State.start;
|
||||
start_index = i + 1;
|
||||
},
|
||||
's' => {
|
||||
continue;
|
||||
},
|
||||
else => @compileError("Unknown format character: " ++ [1]u8{c}),
|
||||
},
|
||||
State.close_brace => switch (c) {
|
||||
'}' => {
|
||||
state = State.start;
|
||||
start_index = i;
|
||||
},
|
||||
else => @compileError("Single '}' encountered in format string"),
|
||||
},
|
||||
}
|
||||
}
|
||||
comptime {
|
||||
if (args.len != next_arg) {
|
||||
@compileError("Unused arguments");
|
||||
}
|
||||
if (state != State.start) {
|
||||
@compileError("Incomplete format string: " ++ format);
|
||||
}
|
||||
}
|
||||
if (start_index < format.len) {
|
||||
try self.write(format[start_index..format.len]);
|
||||
}
|
||||
try self.flush();
|
||||
}
|
||||
|
||||
fn write(self: *Writer, value: []const u8) !void {
|
||||
_ = self;
|
||||
_ = value;
|
||||
}
|
||||
pub fn printValue(self: *Writer, value: anytype) !void {
|
||||
_ = self;
|
||||
_ = value;
|
||||
}
|
||||
fn flush(self: *Writer) !void {
|
||||
_ = self;
|
||||
}
|
||||
};
|
||||
|
||||
// syntax
|
||||
@@ -1,10 +0,0 @@
|
||||
const print = @import("std").debug.print;
|
||||
|
||||
const a_number: i32 = 1234;
|
||||
const a_string = "foobar";
|
||||
|
||||
pub fn main() void {
|
||||
print("here is a string: '{s}' here is a number: {}\n", .{ a_string, a_number });
|
||||
}
|
||||
|
||||
// exe=succeed
|
||||
@@ -1,11 +0,0 @@
|
||||
const print = @import("std").debug.print;
|
||||
|
||||
const a_number: i32 = 1234;
|
||||
const a_string = "foobar";
|
||||
const fmt = "here is a string: '{s}' here is a number: {}\n";
|
||||
|
||||
pub fn main() void {
|
||||
print(fmt, .{ a_string, a_number });
|
||||
}
|
||||
|
||||
// exe=succeed
|
||||
@@ -1,15 +0,0 @@
|
||||
const std = @import("std");
|
||||
|
||||
pub const json = struct {
|
||||
pub const JsonValue = union(enum) {
|
||||
number: f64,
|
||||
boolean: bool,
|
||||
// ...
|
||||
};
|
||||
};
|
||||
|
||||
pub fn main() void {
|
||||
std.debug.print("{s}\n", .{@typeName(json.JsonValue)});
|
||||
}
|
||||
|
||||
// exe=succeed
|
||||
@@ -1,13 +0,0 @@
|
||||
const expect = @import("std").testing.expect;
|
||||
test "attempt to swap array elements with array initializer" {
|
||||
var arr: [2]u32 = .{ 1, 2 };
|
||||
arr = .{ arr[1], arr[0] };
|
||||
// The previous line is equivalent to the following two lines:
|
||||
// arr[0] = arr[1];
|
||||
// arr[1] = arr[0];
|
||||
// So this fails!
|
||||
try expect(arr[0] == 2); // succeeds
|
||||
try expect(arr[1] == 1); // fails
|
||||
}
|
||||
|
||||
// test_error=
|
||||
@@ -1,12 +0,0 @@
|
||||
const expectEqual = @import("std").testing.expectEqual;
|
||||
test "result type propagates through struct initializer" {
|
||||
const S = struct { x: u32 };
|
||||
const val: u64 = 123;
|
||||
const s: S = .{ .x = @intCast(val) };
|
||||
// .{ .x = @intCast(val) } has result type `S` due to the type annotation
|
||||
// @intCast(val) has result type `u32` due to the type of the field `S.x`
|
||||
// val has no result type, as it is permitted to be any integer type
|
||||
try expectEqual(@as(u32, 123), s.x);
|
||||
}
|
||||
|
||||
// test
|
||||
@@ -1,11 +0,0 @@
|
||||
const std = @import("std");
|
||||
|
||||
pub fn main() void {
|
||||
var a: u32 = 10;
|
||||
var b: u32 = 3;
|
||||
_ = .{ &a, &b };
|
||||
const c = @divExact(a, b);
|
||||
std.debug.print("value: {}\n", .{c});
|
||||
}
|
||||
|
||||
// exe=fail
|
||||
@@ -1,11 +0,0 @@
|
||||
const std = @import("std");
|
||||
|
||||
pub fn main() void {
|
||||
var a: u32 = 1;
|
||||
var b: u32 = 0;
|
||||
_ = .{ &a, &b };
|
||||
const c = a / b;
|
||||
std.debug.print("value: {}\n", .{c});
|
||||
}
|
||||
|
||||
// exe=fail
|
||||
@@ -1,13 +0,0 @@
|
||||
const mem = @import("std").mem;
|
||||
pub fn main() !void {
|
||||
var array align(4) = [_]u32{ 0x11111111, 0x11111111 };
|
||||
const bytes = mem.sliceAsBytes(array[0..]);
|
||||
if (foo(bytes) != 0x11111111) return error.Wrong;
|
||||
}
|
||||
fn foo(bytes: []u8) u32 {
|
||||
const slice4 = bytes[1..5];
|
||||
const int_slice = mem.bytesAsSlice(u32, @as([]align(4) u8, @alignCast(slice4)));
|
||||
return int_slice[0];
|
||||
}
|
||||
|
||||
// exe=fail
|
||||
@@ -1,10 +0,0 @@
|
||||
pub fn main() void {
|
||||
const x = foo("hello");
|
||||
_ = x;
|
||||
}
|
||||
|
||||
fn foo(x: []const u8) u8 {
|
||||
return x[5];
|
||||
}
|
||||
|
||||
// exe=fail
|
||||
@@ -1,10 +0,0 @@
|
||||
const std = @import("std");
|
||||
|
||||
pub fn main() void {
|
||||
var value: i32 = -1; // runtime-known
|
||||
_ = &value;
|
||||
const unsigned: u32 = @intCast(value);
|
||||
std.debug.print("value: {}\n", .{unsigned});
|
||||
}
|
||||
|
||||
// exe=fail
|
||||
@@ -1,10 +0,0 @@
|
||||
const std = @import("std");
|
||||
|
||||
pub fn main() void {
|
||||
var spartan_count: u16 = 300; // runtime-known
|
||||
_ = &spartan_count;
|
||||
const byte: u8 = @intCast(spartan_count);
|
||||
std.debug.print("value: {}\n", .{byte});
|
||||
}
|
||||
|
||||
// exe=fail
|
||||
@@ -1,16 +0,0 @@
|
||||
const std = @import("std");
|
||||
|
||||
const Foo = enum {
|
||||
a,
|
||||
b,
|
||||
c,
|
||||
};
|
||||
|
||||
pub fn main() void {
|
||||
var a: u2 = 3;
|
||||
_ = &a;
|
||||
const b: Foo = @enumFromInt(a);
|
||||
std.debug.print("value: {s}\n", .{@tagName(b)});
|
||||
}
|
||||
|
||||
// exe=fail
|
||||
@@ -1,11 +0,0 @@
|
||||
const std = @import("std");
|
||||
|
||||
pub fn main() void {
|
||||
const err = error.AnError;
|
||||
var number = @intFromError(err) + 500;
|
||||
_ = &number;
|
||||
const invalid_err = @errorFromInt(number);
|
||||
std.debug.print("value: {}\n", .{invalid_err});
|
||||
}
|
||||
|
||||
// exe=fail
|
||||
@@ -1,19 +0,0 @@
|
||||
const std = @import("std");
|
||||
|
||||
const Set1 = error{
|
||||
A,
|
||||
B,
|
||||
};
|
||||
const Set2 = error{
|
||||
A,
|
||||
C,
|
||||
};
|
||||
pub fn main() void {
|
||||
foo(Set1.B);
|
||||
}
|
||||
fn foo(set1: Set1) void {
|
||||
const x: Set2 = @errorCast(set1);
|
||||
std.debug.print("value: {}\n", .{x});
|
||||
}
|
||||
|
||||
// exe=fail
|
||||
@@ -1,8 +0,0 @@
|
||||
pub fn main() void {
|
||||
var opt_ptr: ?*i32 = null;
|
||||
_ = &opt_ptr;
|
||||
const ptr: *i32 = @ptrCast(opt_ptr);
|
||||
_ = ptr;
|
||||
}
|
||||
|
||||
// exe=fail
|
||||
@@ -1,8 +0,0 @@
|
||||
pub fn main() void {
|
||||
var float: f32 = 4294967296; // runtime-known
|
||||
_ = &float;
|
||||
const int: i32 = @intFromFloat(float);
|
||||
_ = int;
|
||||
}
|
||||
|
||||
// exe=fail
|
||||
@@ -1,9 +0,0 @@
|
||||
const std = @import("std");
|
||||
|
||||
pub fn main() void {
|
||||
var byte: u8 = 255;
|
||||
byte += 1;
|
||||
std.debug.print("value: {}\n", .{byte});
|
||||
}
|
||||
|
||||
// exe=fail
|
||||
@@ -1,7 +0,0 @@
|
||||
const std = @import("std");
|
||||
|
||||
pub fn main() void {
|
||||
std.debug.assert(false);
|
||||
}
|
||||
|
||||
// exe=fail
|
||||
@@ -1,11 +0,0 @@
|
||||
const std = @import("std");
|
||||
|
||||
pub fn main() void {
|
||||
var a: u32 = 10;
|
||||
var b: u32 = 0;
|
||||
_ = .{ &a, &b };
|
||||
const c = a % b;
|
||||
std.debug.print("value: {}\n", .{c});
|
||||
}
|
||||
|
||||
// exe=fail
|
||||
@@ -1,10 +0,0 @@
|
||||
const std = @import("std");
|
||||
|
||||
pub fn main() void {
|
||||
var x: u8 = 0b01010101; // runtime-known
|
||||
_ = &x;
|
||||
const y = @shlExact(x, 2);
|
||||
std.debug.print("value: {}\n", .{y});
|
||||
}
|
||||
|
||||
// exe=fail
|
||||
@@ -1,10 +0,0 @@
|
||||
const std = @import("std");
|
||||
|
||||
pub fn main() void {
|
||||
var x: u8 = 0b10101010; // runtime-known
|
||||
_ = &x;
|
||||
const y = @shrExact(x, 2);
|
||||
std.debug.print("value: {}\n", .{y});
|
||||
}
|
||||
|
||||
// exe=fail
|
||||
@@ -1,12 +0,0 @@
|
||||
const std = @import("std");
|
||||
|
||||
pub fn main() void {
|
||||
const number = getNumberOrFail() catch unreachable;
|
||||
std.debug.print("value: {}\n", .{number});
|
||||
}
|
||||
|
||||
fn getNumberOrFail() !i32 {
|
||||
return error.UnableToReturnNumber;
|
||||
}
|
||||
|
||||
// exe=fail
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user