mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 14:24:45 +00:00
Merge branch 'update_zig' into name-functions-with-morphic
This commit is contained in:
commit
4151dac452
24 changed files with 216 additions and 343 deletions
2
.llvmenv
2
.llvmenv
|
@ -1 +1 @@
|
||||||
10.0.0
|
12.0.0
|
||||||
|
|
|
@ -40,23 +40,41 @@ sudo apt-get install libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev
|
||||||
```
|
```
|
||||||
|
|
||||||
### Zig
|
### Zig
|
||||||
**version: 0.7.x**
|
**version: 0.8.0**
|
||||||
|
|
||||||
If you're on MacOS, you can install with `brew install zig`
|
For any OS, you can use [`zigup`](https://github.com/marler8997/zigup) to manage zig installations.
|
||||||
If you're on Ubuntu and use Snap, you can install with `snap install zig --classic --beta`
|
|
||||||
For any other OS, checkout the [Zig installation page](https://github.com/ziglang/zig/wiki/Install-Zig-from-a-Package-Manager)
|
If you prefer a package manager, you can try the following:
|
||||||
|
- For MacOS, you can install with `brew install zig`
|
||||||
|
- For, Ubuntu, you can use Snap, you can install with `snap install zig --classic --beta`
|
||||||
|
- For other systems, checkout this [page](https://github.com/ziglang/zig/wiki/Install-Zig-from-a-Package-Manager)
|
||||||
|
|
||||||
|
If you want to install it manually, you can also download Zig directly [here](https://ziglang.org/download/). Just make sure you download the right version, the bleeding edge master build is the first download link on this page.
|
||||||
|
|
||||||
### LLVM
|
### LLVM
|
||||||
**version: 10.0.x**
|
**version: 12.0.x**
|
||||||
|
|
||||||
|
For macOS, you can install LLVM 12 using `brew install llvm@12` and then adding
|
||||||
|
`/usr/local/opt/llvm/bin` to your `PATH`. You can confirm this worked by
|
||||||
|
running `llc --version` - it should mention "LLVM version 12.0.0" at the top.
|
||||||
|
|
||||||
For Ubuntu and Debian, you can use the `Automatic installation script` at [apt.llvm.org](https://apt.llvm.org):
|
For Ubuntu and Debian, you can use the `Automatic installation script` at [apt.llvm.org](https://apt.llvm.org):
|
||||||
```
|
```
|
||||||
sudo bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)"
|
sudo bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)"
|
||||||
```
|
```
|
||||||
|
|
||||||
For macOS, check the troubleshooting section below.
|
If you use this script, you'll need to add `clang` and `llvm-as` to your `PATH`.
|
||||||
|
By default, the script installs them as `llvm-as-12` and `clang-12`,
|
||||||
|
respectively. You can address this with symlinks like so:
|
||||||
|
|
||||||
There are also plenty of alternative options at http://releases.llvm.org/download.html
|
```
|
||||||
|
sudo ln -s /usr/bin/clang-12 /usr/bin/clang
|
||||||
|
```
|
||||||
|
```
|
||||||
|
sudo ln -s /usr/bin/llvm-as-12 /usr/bin/llvm-as
|
||||||
|
````
|
||||||
|
|
||||||
|
There are also alternative installation options at http://releases.llvm.org/download.html
|
||||||
|
|
||||||
## Using Nix
|
## Using Nix
|
||||||
|
|
||||||
|
@ -138,31 +156,15 @@ If you encounter `cannot find -lz` run `sudo apt install zlib1g-dev`.
|
||||||
|
|
||||||
### LLVM installation on macOS
|
### LLVM installation on macOS
|
||||||
|
|
||||||
By default homebrew will try to install llvm 11, which is currently
|
If installing LLVM fails, it might help to run `sudo xcode-select -r` before installing again.
|
||||||
unsupported. You need to install an older version (10.0.0_3) by doing:
|
|
||||||
|
|
||||||
```
|
|
||||||
$ brew edit llvm
|
|
||||||
|
|
||||||
# Replace the contents of the file with https://raw.githubusercontent.com/Homebrew/homebrew-core/6616d50fb0b24dbe30f5e975210bdad63257f517/Formula/llvm.rb
|
|
||||||
|
|
||||||
# we expect llvm-as-10 to be present
|
|
||||||
$ ln -s /usr/local/opt/llvm/bin/{llvm-as,llvm-as-10}
|
|
||||||
|
|
||||||
# "pinning" ensures that homebrew doesn't update it automatically
|
|
||||||
$ brew pin llvm
|
|
||||||
```
|
|
||||||
|
|
||||||
It might also be useful to add these exports to your shell:
|
It might also be useful to add these exports to your shell:
|
||||||
|
|
||||||
```
|
```
|
||||||
export PATH="/usr/local/opt/llvm/bin:$PATH"
|
|
||||||
export LDFLAGS="-L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib"
|
export LDFLAGS="-L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib"
|
||||||
export CPPFLAGS="-I/usr/local/opt/llvm/include"
|
export CPPFLAGS="-I/usr/local/opt/llvm/include"
|
||||||
```
|
```
|
||||||
|
|
||||||
If installing LLVM still fails, it might help to run `sudo xcode-select -r` before installing again.
|
|
||||||
|
|
||||||
### LLVM installation on Windows
|
### LLVM installation on Windows
|
||||||
|
|
||||||
Installing LLVM's prebuilt binaries doesn't seem to be enough for the `llvm-sys` crate that Roc depends on, so I had to build LLVM from source
|
Installing LLVM's prebuilt binaries doesn't seem to be enough for the `llvm-sys` crate that Roc depends on, so I had to build LLVM from source
|
||||||
|
|
31
Cargo.lock
generated
31
Cargo.lock
generated
|
@ -1618,13 +1618,13 @@ dependencies = [
|
||||||
name = "inkwell"
|
name = "inkwell"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"inkwell 0.1.0 (git+https://github.com/rtfeldman/inkwell?tag=llvm12-0.release2)",
|
"inkwell 0.1.0 (git+https://github.com/rtfeldman/inkwell?tag=llvm12-0.release4)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "inkwell"
|
name = "inkwell"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/rtfeldman/inkwell?tag=llvm12-0.release2#2f9bfb728cb5713b39fe527838969dcc8e184c4d"
|
source = "git+https://github.com/rtfeldman/inkwell?tag=llvm12-0.release4#8d7174fc8da4d2e6f2555f9ec2b3f7464ec5026b"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"either",
|
"either",
|
||||||
"inkwell_internals",
|
"inkwell_internals",
|
||||||
|
@ -1638,7 +1638,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "inkwell_internals"
|
name = "inkwell_internals"
|
||||||
version = "0.3.0"
|
version = "0.3.0"
|
||||||
source = "git+https://github.com/rtfeldman/inkwell?tag=llvm12-0.release2#2f9bfb728cb5713b39fe527838969dcc8e184c4d"
|
source = "git+https://github.com/rtfeldman/inkwell?tag=llvm12-0.release4#8d7174fc8da4d2e6f2555f9ec2b3f7464ec5026b"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2 1.0.27",
|
"proc-macro2 1.0.27",
|
||||||
"quote 1.0.9",
|
"quote 1.0.9",
|
||||||
|
@ -1795,15 +1795,15 @@ checksum = "7fb9b38af92608140b86b693604b9ffcc5824240a484d1ecd4795bacb2fe88f3"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "llvm-sys"
|
name = "llvm-sys"
|
||||||
version = "100.2.1"
|
version = "120.0.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "15d9c00ce56221b2150e2d4d51887ff139fce5a0e50346c744861d1e66d2f7c4"
|
checksum = "7b883556196140c6b6e7a18b19236b9a699c8611aad2e48a0a6403cf1123945a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cc",
|
"cc",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"libc",
|
"libc",
|
||||||
"regex",
|
"regex",
|
||||||
"semver 0.9.0",
|
"semver",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -3469,7 +3469,7 @@ version = "0.3.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f0dfe2087c51c460008730de8b57e6a320782fbfb312e1f4d520e6c6fae155ee"
|
checksum = "f0dfe2087c51c460008730de8b57e6a320782fbfb312e1f4d520e6c6fae155ee"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"semver 0.11.0",
|
"semver",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -3536,30 +3536,15 @@ version = "1.1.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
|
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "semver"
|
|
||||||
version = "0.9.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
|
|
||||||
dependencies = [
|
|
||||||
"semver-parser 0.7.0",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "semver"
|
name = "semver"
|
||||||
version = "0.11.0"
|
version = "0.11.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f301af10236f6df4160f7c3f04eec6dbc70ace82d23326abad5edee88801c6b6"
|
checksum = "f301af10236f6df4160f7c3f04eec6dbc70ace82d23326abad5edee88801c6b6"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"semver-parser 0.10.2",
|
"semver-parser",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "semver-parser"
|
|
||||||
version = "0.7.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "semver-parser"
|
name = "semver-parser"
|
||||||
version = "0.10.2"
|
version = "0.10.2"
|
||||||
|
|
13
Earthfile
13
Earthfile
|
@ -13,17 +13,18 @@ install-other-libs:
|
||||||
install-zig-llvm-valgrind-clippy-rustfmt:
|
install-zig-llvm-valgrind-clippy-rustfmt:
|
||||||
FROM +install-other-libs
|
FROM +install-other-libs
|
||||||
# zig
|
# zig
|
||||||
RUN wget -c https://ziglang.org/download/0.7.1/zig-linux-x86_64-0.7.1.tar.xz --no-check-certificate
|
RUN wget -c https://ziglang.org/download/0.8.0/zig-linux-x86_64-0.8.0.tar.xz --no-check-certificate
|
||||||
RUN tar -xf zig-linux-x86_64-0.7.1.tar.xz
|
RUN tar -xf zig-linux-x86_64-0.8.0.tar.xz
|
||||||
RUN ln -s /earthbuild/zig-linux-x86_64-0.7.1/zig /usr/bin/zig
|
RUN ln -s /earthbuild/zig-linux-x86_64-0.8.0/zig /usr/bin/zig
|
||||||
# llvm
|
# llvm
|
||||||
RUN apt -y install lsb-release software-properties-common gnupg
|
RUN apt -y install lsb-release software-properties-common gnupg
|
||||||
RUN wget https://apt.llvm.org/llvm.sh
|
RUN wget https://apt.llvm.org/llvm.sh
|
||||||
RUN chmod +x llvm.sh
|
RUN chmod +x llvm.sh
|
||||||
RUN ./llvm.sh 10
|
RUN ./llvm.sh 12
|
||||||
RUN ln -s /usr/bin/clang-10 /usr/bin/clang
|
RUN ln -s /usr/bin/clang-12 /usr/bin/clang
|
||||||
|
RUN ln -s /usr/bin/llvm-as-12 /usr/bin/llvm-as
|
||||||
# use lld as linker
|
# use lld as linker
|
||||||
RUN ln -s /usr/bin/lld-10 /usr/bin/ld.lld
|
RUN ln -s /usr/bin/lld-12 /usr/bin/ld.lld
|
||||||
ENV RUSTFLAGS="-C link-arg=-fuse-ld=lld -C target-cpu=native"
|
ENV RUSTFLAGS="-C link-arg=-fuse-ld=lld -C target-cpu=native"
|
||||||
# valgrind
|
# valgrind
|
||||||
RUN apt -y install autotools-dev cmake automake libc6-dbg
|
RUN apt -y install autotools-dev cmake automake libc6-dbg
|
||||||
|
|
|
@ -59,7 +59,7 @@ pub export fn main() i32 {
|
||||||
roc__mainForHost_1_exposed(&callresult);
|
roc__mainForHost_1_exposed(&callresult);
|
||||||
|
|
||||||
// stdout the result
|
// stdout the result
|
||||||
stdout.print("{}\n", .{callresult.content.asSlice()}) catch unreachable;
|
stdout.print("{s}\n", .{callresult.content.asSlice()}) catch unreachable;
|
||||||
|
|
||||||
callresult.content.deinit();
|
callresult.content.deinit();
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,7 @@ pub export fn main() i32 {
|
||||||
roc__mainForHost_1_exposed(&callresult);
|
roc__mainForHost_1_exposed(&callresult);
|
||||||
|
|
||||||
// stdout the result
|
// stdout the result
|
||||||
stdout.print("{}\n", .{callresult.content.asSlice()}) catch unreachable;
|
stdout.print("{s}\n", .{callresult.content.asSlice()}) catch unreachable;
|
||||||
|
|
||||||
callresult.content.deinit();
|
callresult.content.deinit();
|
||||||
|
|
||||||
|
|
|
@ -204,7 +204,7 @@ pub fn gen_from_mono_module(
|
||||||
}
|
}
|
||||||
|
|
||||||
// assemble the .ll into a .bc
|
// assemble the .ll into a .bc
|
||||||
let _ = Command::new("llvm-as-10")
|
let _ = Command::new("llvm-as")
|
||||||
.env_clear()
|
.env_clear()
|
||||||
.args(&[
|
.args(&[
|
||||||
app_ll_dbg_file.to_str().unwrap(),
|
app_ll_dbg_file.to_str().unwrap(),
|
||||||
|
@ -216,7 +216,7 @@ pub fn gen_from_mono_module(
|
||||||
|
|
||||||
// write the .o file. Note that this builds the .o for the local machine,
|
// write the .o file. Note that this builds the .o for the local machine,
|
||||||
// and ignores the `target_machine` entirely.
|
// and ignores the `target_machine` entirely.
|
||||||
let _ = Command::new("llc-10")
|
let _ = Command::new("llc-12")
|
||||||
.env_clear()
|
.env_clear()
|
||||||
.args(&[
|
.args(&[
|
||||||
"-filetype=obj",
|
"-filetype=obj",
|
||||||
|
|
|
@ -1,16 +1,15 @@
|
||||||
const builtin = @import("builtin");
|
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const mem = std.mem;
|
const mem = std.mem;
|
||||||
const Builder = std.build.Builder;
|
const Builder = std.build.Builder;
|
||||||
|
|
||||||
pub fn build(b: *Builder) void {
|
pub fn build(b: *Builder) void {
|
||||||
// b.setPreferredReleaseMode(builtin.Mode.Debug);
|
// b.setPreferredReleaseMode(builtin.Mode.Debug
|
||||||
b.setPreferredReleaseMode(builtin.Mode.ReleaseFast);
|
b.setPreferredReleaseMode(.ReleaseFast);
|
||||||
const mode = b.standardReleaseOptions();
|
const mode = b.standardReleaseOptions();
|
||||||
|
|
||||||
// Options
|
// Options
|
||||||
const fallback_main_path = "./src/main.zig";
|
const fallback_main_path = "./src/main.zig";
|
||||||
const main_path_desc = b.fmt("Override path to main.zig. Used by \"ir\" and \"test\". Defaults to \"{}\". ", .{fallback_main_path});
|
const main_path_desc = b.fmt("Override path to main.zig. Used by \"ir\" and \"test\". Defaults to \"{s}\". ", .{fallback_main_path});
|
||||||
const main_path = b.option([]const u8, "main-path", main_path_desc) orelse fallback_main_path;
|
const main_path = b.option([]const u8, "main-path", main_path_desc) orelse fallback_main_path;
|
||||||
|
|
||||||
// Tests
|
// Tests
|
||||||
|
|
|
@ -16,7 +16,7 @@ pub const RocDec = struct {
|
||||||
pub const one_point_zero: comptime RocDec = .{ .num = one_point_zero_i128 };
|
pub const one_point_zero: comptime RocDec = .{ .num = one_point_zero_i128 };
|
||||||
|
|
||||||
pub fn fromU64(num: u64) RocDec {
|
pub fn fromU64(num: u64) RocDec {
|
||||||
return .{ .num = @intCast(i128, num) * one_point_zero_i128 };
|
return .{ .num = num * one_point_zero_i128 };
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fromString(roc_str: RocStr) ?RocDec {
|
pub fn fromString(roc_str: RocStr) ?RocDec {
|
||||||
|
@ -323,140 +323,140 @@ const expectEqual = testing.expectEqual;
|
||||||
test "fromU64" {
|
test "fromU64" {
|
||||||
var dec = RocDec.fromU64(25);
|
var dec = RocDec.fromU64(25);
|
||||||
|
|
||||||
expectEqual(RocDec{ .num = 25000000000000000000 }, dec);
|
try expectEqual(RocDec{ .num = 25000000000000000000 }, dec);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "fromString: empty" {
|
test "fromString: empty" {
|
||||||
var roc_str = RocStr.init("", 0);
|
var roc_str = RocStr.init("", 0);
|
||||||
var dec = RocDec.fromString(roc_str);
|
var dec = RocDec.fromString(roc_str);
|
||||||
|
|
||||||
expectEqual(dec, null);
|
try expectEqual(dec, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "fromString: 0" {
|
test "fromString: 0" {
|
||||||
var roc_str = RocStr.init("0", 1);
|
var roc_str = RocStr.init("0", 1);
|
||||||
var dec = RocDec.fromString(roc_str);
|
var dec = RocDec.fromString(roc_str);
|
||||||
|
|
||||||
expectEqual(RocDec{ .num = 0 }, dec.?);
|
try expectEqual(RocDec{ .num = 0 }, dec.?);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "fromString: 1" {
|
test "fromString: 1" {
|
||||||
var roc_str = RocStr.init("1", 1);
|
var roc_str = RocStr.init("1", 1);
|
||||||
var dec = RocDec.fromString(roc_str);
|
var dec = RocDec.fromString(roc_str);
|
||||||
|
|
||||||
expectEqual(RocDec.one_point_zero, dec.?);
|
try expectEqual(RocDec.one_point_zero, dec.?);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "fromString: 123.45" {
|
test "fromString: 123.45" {
|
||||||
var roc_str = RocStr.init("123.45", 6);
|
var roc_str = RocStr.init("123.45", 6);
|
||||||
var dec = RocDec.fromString(roc_str);
|
var dec = RocDec.fromString(roc_str);
|
||||||
|
|
||||||
expectEqual(RocDec{ .num = 123450000000000000000 }, dec.?);
|
try expectEqual(RocDec{ .num = 123450000000000000000 }, dec.?);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "fromString: .45" {
|
test "fromString: .45" {
|
||||||
var roc_str = RocStr.init(".45", 3);
|
var roc_str = RocStr.init(".45", 3);
|
||||||
var dec = RocDec.fromString(roc_str);
|
var dec = RocDec.fromString(roc_str);
|
||||||
|
|
||||||
expectEqual(RocDec{ .num = 450000000000000000 }, dec.?);
|
try expectEqual(RocDec{ .num = 450000000000000000 }, dec.?);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "fromString: 0.45" {
|
test "fromString: 0.45" {
|
||||||
var roc_str = RocStr.init("0.45", 4);
|
var roc_str = RocStr.init("0.45", 4);
|
||||||
var dec = RocDec.fromString(roc_str);
|
var dec = RocDec.fromString(roc_str);
|
||||||
|
|
||||||
expectEqual(RocDec{ .num = 450000000000000000 }, dec.?);
|
try expectEqual(RocDec{ .num = 450000000000000000 }, dec.?);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "fromString: 123" {
|
test "fromString: 123" {
|
||||||
var roc_str = RocStr.init("123", 3);
|
var roc_str = RocStr.init("123", 3);
|
||||||
var dec = RocDec.fromString(roc_str);
|
var dec = RocDec.fromString(roc_str);
|
||||||
|
|
||||||
expectEqual(RocDec{ .num = 123000000000000000000 }, dec.?);
|
try expectEqual(RocDec{ .num = 123000000000000000000 }, dec.?);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "fromString: -.45" {
|
test "fromString: -.45" {
|
||||||
var roc_str = RocStr.init("-.45", 4);
|
var roc_str = RocStr.init("-.45", 4);
|
||||||
var dec = RocDec.fromString(roc_str);
|
var dec = RocDec.fromString(roc_str);
|
||||||
|
|
||||||
expectEqual(RocDec{ .num = -450000000000000000 }, dec.?);
|
try expectEqual(RocDec{ .num = -450000000000000000 }, dec.?);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "fromString: -0.45" {
|
test "fromString: -0.45" {
|
||||||
var roc_str = RocStr.init("-0.45", 5);
|
var roc_str = RocStr.init("-0.45", 5);
|
||||||
var dec = RocDec.fromString(roc_str);
|
var dec = RocDec.fromString(roc_str);
|
||||||
|
|
||||||
expectEqual(RocDec{ .num = -450000000000000000 }, dec.?);
|
try expectEqual(RocDec{ .num = -450000000000000000 }, dec.?);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "fromString: -123" {
|
test "fromString: -123" {
|
||||||
var roc_str = RocStr.init("-123", 4);
|
var roc_str = RocStr.init("-123", 4);
|
||||||
var dec = RocDec.fromString(roc_str);
|
var dec = RocDec.fromString(roc_str);
|
||||||
|
|
||||||
expectEqual(RocDec{ .num = -123000000000000000000 }, dec.?);
|
try expectEqual(RocDec{ .num = -123000000000000000000 }, dec.?);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "fromString: -123.45" {
|
test "fromString: -123.45" {
|
||||||
var roc_str = RocStr.init("-123.45", 7);
|
var roc_str = RocStr.init("-123.45", 7);
|
||||||
var dec = RocDec.fromString(roc_str);
|
var dec = RocDec.fromString(roc_str);
|
||||||
|
|
||||||
expectEqual(RocDec{ .num = -123450000000000000000 }, dec.?);
|
try expectEqual(RocDec{ .num = -123450000000000000000 }, dec.?);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "fromString: abc" {
|
test "fromString: abc" {
|
||||||
var roc_str = RocStr.init("abc", 3);
|
var roc_str = RocStr.init("abc", 3);
|
||||||
var dec = RocDec.fromString(roc_str);
|
var dec = RocDec.fromString(roc_str);
|
||||||
|
|
||||||
expectEqual(dec, null);
|
try expectEqual(dec, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "fromString: 123.abc" {
|
test "fromString: 123.abc" {
|
||||||
var roc_str = RocStr.init("123.abc", 7);
|
var roc_str = RocStr.init("123.abc", 7);
|
||||||
var dec = RocDec.fromString(roc_str);
|
var dec = RocDec.fromString(roc_str);
|
||||||
|
|
||||||
expectEqual(dec, null);
|
try expectEqual(dec, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "fromString: abc.123" {
|
test "fromString: abc.123" {
|
||||||
var roc_str = RocStr.init("abc.123", 7);
|
var roc_str = RocStr.init("abc.123", 7);
|
||||||
var dec = RocDec.fromString(roc_str);
|
var dec = RocDec.fromString(roc_str);
|
||||||
|
|
||||||
expectEqual(dec, null);
|
try expectEqual(dec, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "fromString: .123.1" {
|
test "fromString: .123.1" {
|
||||||
var roc_str = RocStr.init(".123.1", 6);
|
var roc_str = RocStr.init(".123.1", 6);
|
||||||
var dec = RocDec.fromString(roc_str);
|
var dec = RocDec.fromString(roc_str);
|
||||||
|
|
||||||
expectEqual(dec, null);
|
try expectEqual(dec, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "add: 0" {
|
test "add: 0" {
|
||||||
var dec: RocDec = .{ .num = 0 };
|
var dec: RocDec = .{ .num = 0 };
|
||||||
|
|
||||||
expectEqual(RocDec{ .num = 0 }, dec.add(.{ .num = 0 }));
|
try expectEqual(RocDec{ .num = 0 }, dec.add(.{ .num = 0 }));
|
||||||
}
|
}
|
||||||
|
|
||||||
test "add: 1" {
|
test "add: 1" {
|
||||||
var dec: RocDec = .{ .num = 0 };
|
var dec: RocDec = .{ .num = 0 };
|
||||||
|
|
||||||
expectEqual(RocDec{ .num = 1 }, dec.add(.{ .num = 1 }));
|
try expectEqual(RocDec{ .num = 1 }, dec.add(.{ .num = 1 }));
|
||||||
}
|
}
|
||||||
|
|
||||||
test "mul: by 0" {
|
test "mul: by 0" {
|
||||||
var dec: RocDec = .{ .num = 0 };
|
var dec: RocDec = .{ .num = 0 };
|
||||||
|
|
||||||
expectEqual(RocDec{ .num = 0 }, dec.mul(.{ .num = 0 }));
|
try expectEqual(RocDec{ .num = 0 }, dec.mul(.{ .num = 0 }));
|
||||||
}
|
}
|
||||||
|
|
||||||
test "mul: by 1" {
|
test "mul: by 1" {
|
||||||
var dec: RocDec = RocDec.fromU64(15);
|
var dec: RocDec = RocDec.fromU64(15);
|
||||||
|
|
||||||
expectEqual(RocDec.fromU64(15), dec.mul(RocDec.fromU64(1)));
|
try expectEqual(RocDec.fromU64(15), dec.mul(RocDec.fromU64(1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
test "mul: by 2" {
|
test "mul: by 2" {
|
||||||
var dec: RocDec = RocDec.fromU64(15);
|
var dec: RocDec = RocDec.fromU64(15);
|
||||||
|
|
||||||
expectEqual(RocDec.fromU64(30), dec.mul(RocDec.fromU64(2)));
|
try expectEqual(RocDec.fromU64(30), dec.mul(RocDec.fromU64(2)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,13 +20,9 @@ const Slot = packed enum(u8) {
|
||||||
PreviouslyFilled,
|
PreviouslyFilled,
|
||||||
};
|
};
|
||||||
|
|
||||||
const MaybeIndexTag = enum {
|
const MaybeIndexTag = enum { index, not_found };
|
||||||
index, not_found
|
|
||||||
};
|
|
||||||
|
|
||||||
const MaybeIndex = union(MaybeIndexTag) {
|
const MaybeIndex = union(MaybeIndexTag) { index: usize, not_found: void };
|
||||||
index: usize, not_found: void
|
|
||||||
};
|
|
||||||
|
|
||||||
fn nextSeed(seed: u64) u64 {
|
fn nextSeed(seed: u64) u64 {
|
||||||
// TODO is this a valid way to get a new seed? are there better ways?
|
// TODO is this a valid way to get a new seed? are there better ways?
|
||||||
|
@ -795,9 +791,7 @@ pub fn dictWalk(
|
||||||
|
|
||||||
caller(data, key, value, b2, b1);
|
caller(data, key, value, b2, b1);
|
||||||
|
|
||||||
const temp = b1;
|
std.mem.swap([*]u8, &b1, &b2);
|
||||||
b2 = b1;
|
|
||||||
b1 = temp;
|
|
||||||
},
|
},
|
||||||
else => {},
|
else => {},
|
||||||
}
|
}
|
||||||
|
|
|
@ -202,13 +202,13 @@ const expectEqual = std.testing.expectEqual;
|
||||||
test "test vectors" {
|
test "test vectors" {
|
||||||
const hash = Wyhash.hash;
|
const hash = Wyhash.hash;
|
||||||
|
|
||||||
expectEqual(hash(0, ""), 0x0);
|
try expectEqual(hash(0, ""), 0x0);
|
||||||
expectEqual(hash(1, "a"), 0xbed235177f41d328);
|
try expectEqual(hash(1, "a"), 0xbed235177f41d328);
|
||||||
expectEqual(hash(2, "abc"), 0xbe348debe59b27c3);
|
try expectEqual(hash(2, "abc"), 0xbe348debe59b27c3);
|
||||||
expectEqual(hash(3, "message digest"), 0x37320f657213a290);
|
try expectEqual(hash(3, "message digest"), 0x37320f657213a290);
|
||||||
expectEqual(hash(4, "abcdefghijklmnopqrstuvwxyz"), 0xd0b270e1d8a7019c);
|
try expectEqual(hash(4, "abcdefghijklmnopqrstuvwxyz"), 0xd0b270e1d8a7019c);
|
||||||
expectEqual(hash(5, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"), 0x602a1894d3bbfe7f);
|
try expectEqual(hash(5, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"), 0x602a1894d3bbfe7f);
|
||||||
expectEqual(hash(6, "12345678901234567890123456789012345678901234567890123456789012345678901234567890"), 0x829e9c148b75970e);
|
try expectEqual(hash(6, "12345678901234567890123456789012345678901234567890123456789012345678901234567890"), 0x829e9c148b75970e);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "test vectors streaming" {
|
test "test vectors streaming" {
|
||||||
|
@ -216,19 +216,19 @@ test "test vectors streaming" {
|
||||||
for ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") |e| {
|
for ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") |e| {
|
||||||
wh.update(mem.asBytes(&e));
|
wh.update(mem.asBytes(&e));
|
||||||
}
|
}
|
||||||
expectEqual(wh.final(), 0x602a1894d3bbfe7f);
|
try expectEqual(wh.final(), 0x602a1894d3bbfe7f);
|
||||||
|
|
||||||
const pattern = "1234567890";
|
const pattern = "1234567890";
|
||||||
const count = 8;
|
const count = 8;
|
||||||
const result = 0x829e9c148b75970e;
|
const result = 0x829e9c148b75970e;
|
||||||
expectEqual(Wyhash.hash(6, pattern ** 8), result);
|
try expectEqual(Wyhash.hash(6, pattern ** 8), result);
|
||||||
|
|
||||||
wh = Wyhash.init(6);
|
wh = Wyhash.init(6);
|
||||||
var i: u32 = 0;
|
var i: u32 = 0;
|
||||||
while (i < count) : (i += 1) {
|
while (i < count) : (i += 1) {
|
||||||
wh.update(pattern);
|
wh.update(pattern);
|
||||||
}
|
}
|
||||||
expectEqual(wh.final(), result);
|
try expectEqual(wh.final(), result);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "iterative non-divisible update" {
|
test "iterative non-divisible update" {
|
||||||
|
@ -250,6 +250,6 @@ test "iterative non-divisible update" {
|
||||||
}
|
}
|
||||||
const iterative_hash = wy.final();
|
const iterative_hash = wy.final();
|
||||||
|
|
||||||
std.testing.expectEqual(iterative_hash, non_iterative_hash);
|
try std.testing.expectEqual(iterative_hash, non_iterative_hash);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ pub const BoundClass = enum(u8) {
|
||||||
};
|
};
|
||||||
|
|
||||||
test "Bound Class" {
|
test "Bound Class" {
|
||||||
expectEqual(0, @enumToInt(BoundClass.START));
|
try expectEqual(0, @enumToInt(BoundClass.START));
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://github.com/JuliaStrings/utf8proc/blob/master/utf8proc.c#L261
|
// https://github.com/JuliaStrings/utf8proc/blob/master/utf8proc.c#L261
|
||||||
|
@ -112,7 +112,7 @@ fn unsafeCodepointToBoundClass(codepoint: u21) *const BoundClass {
|
||||||
}
|
}
|
||||||
|
|
||||||
test "unsafeCodepointToBoundClass: valid" {
|
test "unsafeCodepointToBoundClass: valid" {
|
||||||
expectEqual(BoundClass.CONTROL, unsafeCodepointToBoundClass(8).*);
|
try expectEqual(BoundClass.CONTROL, unsafeCodepointToBoundClass(8).*);
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://github.com/JuliaStrings/utf8proc/blob/master/utf8proc.c#L242
|
// https://github.com/JuliaStrings/utf8proc/blob/master/utf8proc.c#L242
|
||||||
|
@ -125,11 +125,11 @@ fn codepointToBoundClass(codepoint: u21) *const BoundClass {
|
||||||
}
|
}
|
||||||
|
|
||||||
test "codepointToBoundClass: valid" {
|
test "codepointToBoundClass: valid" {
|
||||||
expectEqual(BoundClass.CONTROL, codepointToBoundClass(8).*);
|
try expectEqual(BoundClass.CONTROL, codepointToBoundClass(8).*);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "codepointToBoundClass: invalid" {
|
test "codepointToBoundClass: invalid" {
|
||||||
expectEqual(BoundClass.OTHER, codepointToBoundClass(codepoint_max + 5).*);
|
try expectEqual(BoundClass.OTHER, codepointToBoundClass(codepoint_max + 5).*);
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://github.com/JuliaStrings/utf8proc/blob/master/utf8proc.c#L319
|
// https://github.com/JuliaStrings/utf8proc/blob/master/utf8proc.c#L319
|
||||||
|
|
|
@ -542,9 +542,7 @@ pub fn listWalk(
|
||||||
const element = source_ptr + i * element_width;
|
const element = source_ptr + i * element_width;
|
||||||
caller(data, element, b2, b1);
|
caller(data, element, b2, b1);
|
||||||
|
|
||||||
const temp = b1;
|
std.mem.swap([*]u8, &b1, &b2);
|
||||||
b2 = b1;
|
|
||||||
b1 = temp;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -591,9 +589,7 @@ pub fn listWalkBackwards(
|
||||||
const element = source_ptr + i * element_width;
|
const element = source_ptr + i * element_width;
|
||||||
caller(data, element, b2, b1);
|
caller(data, element, b2, b1);
|
||||||
|
|
||||||
const temp = b1;
|
std.mem.swap([*]u8, &b1, &b2);
|
||||||
b2 = b1;
|
|
||||||
b1 = temp;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -781,43 +777,19 @@ pub fn listDrop(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn listRange(width: utils.IntWidth, low: Opaque, high: Opaque) callconv(.C) RocList {
|
pub fn listRange(width: utils.IntWidth, low: Opaque, high: Opaque) callconv(.C) RocList {
|
||||||
const IntWidth = utils.IntWidth;
|
return switch (width) {
|
||||||
|
.U8 => helper1(u8, low, high),
|
||||||
switch (width) {
|
.U16 => helper1(u16, low, high),
|
||||||
IntWidth.U8 => {
|
.U32 => helper1(u32, low, high),
|
||||||
return helper1(u8, low, high);
|
.U64 => helper1(u64, low, high),
|
||||||
},
|
.U128 => helper1(u128, low, high),
|
||||||
IntWidth.U16 => {
|
.I8 => helper1(i8, low, high),
|
||||||
return helper1(u16, low, high);
|
.I16 => helper1(i16, low, high),
|
||||||
},
|
.I32 => helper1(i32, low, high),
|
||||||
IntWidth.U32 => {
|
.I64 => helper1(i64, low, high),
|
||||||
return helper1(u32, low, high);
|
.I128 => helper1(i128, low, high),
|
||||||
},
|
.Usize => helper1(usize, low, high),
|
||||||
IntWidth.U64 => {
|
};
|
||||||
return helper1(u64, low, high);
|
|
||||||
},
|
|
||||||
IntWidth.U128 => {
|
|
||||||
return helper1(u128, low, high);
|
|
||||||
},
|
|
||||||
IntWidth.I8 => {
|
|
||||||
return helper1(i8, low, high);
|
|
||||||
},
|
|
||||||
IntWidth.I16 => {
|
|
||||||
return helper1(i16, low, high);
|
|
||||||
},
|
|
||||||
IntWidth.I32 => {
|
|
||||||
return helper1(i32, low, high);
|
|
||||||
},
|
|
||||||
IntWidth.I64 => {
|
|
||||||
return helper1(i64, low, high);
|
|
||||||
},
|
|
||||||
IntWidth.I128 => {
|
|
||||||
return helper1(i128, low, high);
|
|
||||||
},
|
|
||||||
IntWidth.Usize => {
|
|
||||||
return helper1(usize, low, high);
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn helper1(comptime T: type, low: Opaque, high: Opaque) RocList {
|
fn helper1(comptime T: type, low: Opaque, high: Opaque) RocList {
|
||||||
|
|
|
@ -273,7 +273,7 @@ pub const RocStr = extern struct {
|
||||||
const str2_ptr: [*]u8 = &str2;
|
const str2_ptr: [*]u8 = &str2;
|
||||||
var roc_str2 = RocStr.init(str2_ptr, str2_len);
|
var roc_str2 = RocStr.init(str2_ptr, str2_len);
|
||||||
|
|
||||||
expect(roc_str1.eq(roc_str2));
|
try expect(roc_str1.eq(roc_str2));
|
||||||
|
|
||||||
roc_str1.deinit();
|
roc_str1.deinit();
|
||||||
roc_str2.deinit();
|
roc_str2.deinit();
|
||||||
|
@ -295,7 +295,7 @@ pub const RocStr = extern struct {
|
||||||
roc_str2.deinit();
|
roc_str2.deinit();
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(!roc_str1.eq(roc_str2));
|
try expect(!roc_str1.eq(roc_str2));
|
||||||
}
|
}
|
||||||
|
|
||||||
test "RocStr.eq: not equal same length" {
|
test "RocStr.eq: not equal same length" {
|
||||||
|
@ -314,7 +314,7 @@ pub const RocStr = extern struct {
|
||||||
roc_str2.deinit();
|
roc_str2.deinit();
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(!roc_str1.eq(roc_str2));
|
try expect(!roc_str1.eq(roc_str2));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -449,8 +449,8 @@ test "strSplitInPlace: no delimiter" {
|
||||||
delimiter.deinit();
|
delimiter.deinit();
|
||||||
}
|
}
|
||||||
|
|
||||||
expectEqual(array.len, expected.len);
|
try expectEqual(array.len, expected.len);
|
||||||
expect(array[0].eq(expected[0]));
|
try expect(array[0].eq(expected[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
test "strSplitInPlace: empty end" {
|
test "strSplitInPlace: empty end" {
|
||||||
|
@ -490,10 +490,10 @@ test "strSplitInPlace: empty end" {
|
||||||
delimiter.deinit();
|
delimiter.deinit();
|
||||||
}
|
}
|
||||||
|
|
||||||
expectEqual(array.len, expected.len);
|
try expectEqual(array.len, expected.len);
|
||||||
expect(array[0].eq(expected[0]));
|
try expect(array[0].eq(expected[0]));
|
||||||
expect(array[1].eq(expected[1]));
|
try expect(array[1].eq(expected[1]));
|
||||||
expect(array[2].eq(expected[2]));
|
try expect(array[2].eq(expected[2]));
|
||||||
}
|
}
|
||||||
|
|
||||||
test "strSplitInPlace: delimiter on sides" {
|
test "strSplitInPlace: delimiter on sides" {
|
||||||
|
@ -532,10 +532,10 @@ test "strSplitInPlace: delimiter on sides" {
|
||||||
delimiter.deinit();
|
delimiter.deinit();
|
||||||
}
|
}
|
||||||
|
|
||||||
expectEqual(array.len, expected.len);
|
try expectEqual(array.len, expected.len);
|
||||||
expect(array[0].eq(expected[0]));
|
try expect(array[0].eq(expected[0]));
|
||||||
expect(array[1].eq(expected[1]));
|
try expect(array[1].eq(expected[1]));
|
||||||
expect(array[2].eq(expected[2]));
|
try expect(array[2].eq(expected[2]));
|
||||||
}
|
}
|
||||||
|
|
||||||
test "strSplitInPlace: three pieces" {
|
test "strSplitInPlace: three pieces" {
|
||||||
|
@ -573,10 +573,10 @@ test "strSplitInPlace: three pieces" {
|
||||||
delimiter.deinit();
|
delimiter.deinit();
|
||||||
}
|
}
|
||||||
|
|
||||||
expectEqual(expected_array.len, array.len);
|
try expectEqual(expected_array.len, array.len);
|
||||||
expect(array[0].eq(expected_array[0]));
|
try expect(array[0].eq(expected_array[0]));
|
||||||
expect(array[1].eq(expected_array[1]));
|
try expect(array[1].eq(expected_array[1]));
|
||||||
expect(array[2].eq(expected_array[2]));
|
try expect(array[2].eq(expected_array[2]));
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is used for `Str.split : Str, Str -> Array Str
|
// This is used for `Str.split : Str, Str -> Array Str
|
||||||
|
@ -639,7 +639,7 @@ test "countSegments: long delimiter" {
|
||||||
}
|
}
|
||||||
|
|
||||||
const segments_count = countSegments(str, delimiter);
|
const segments_count = countSegments(str, delimiter);
|
||||||
expectEqual(segments_count, 1);
|
try expectEqual(segments_count, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "countSegments: delimiter at start" {
|
test "countSegments: delimiter at start" {
|
||||||
|
@ -658,7 +658,7 @@ test "countSegments: delimiter at start" {
|
||||||
|
|
||||||
const segments_count = countSegments(str, delimiter);
|
const segments_count = countSegments(str, delimiter);
|
||||||
|
|
||||||
expectEqual(segments_count, 2);
|
try expectEqual(segments_count, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "countSegments: delimiter interspered" {
|
test "countSegments: delimiter interspered" {
|
||||||
|
@ -677,7 +677,7 @@ test "countSegments: delimiter interspered" {
|
||||||
|
|
||||||
const segments_count = countSegments(str, delimiter);
|
const segments_count = countSegments(str, delimiter);
|
||||||
|
|
||||||
expectEqual(segments_count, 3);
|
try expectEqual(segments_count, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Str.countGraphemeClusters
|
// Str.countGraphemeClusters
|
||||||
|
@ -721,7 +721,7 @@ fn rocStrFromLiteral(bytes_arr: *const []u8) RocStr {}
|
||||||
|
|
||||||
test "countGraphemeClusters: empty string" {
|
test "countGraphemeClusters: empty string" {
|
||||||
const count = countGraphemeClusters(RocStr.empty());
|
const count = countGraphemeClusters(RocStr.empty());
|
||||||
expectEqual(count, 0);
|
try expectEqual(count, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "countGraphemeClusters: ascii characters" {
|
test "countGraphemeClusters: ascii characters" {
|
||||||
|
@ -731,7 +731,7 @@ test "countGraphemeClusters: ascii characters" {
|
||||||
defer str.deinit();
|
defer str.deinit();
|
||||||
|
|
||||||
const count = countGraphemeClusters(str);
|
const count = countGraphemeClusters(str);
|
||||||
expectEqual(count, 4);
|
try expectEqual(count, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "countGraphemeClusters: utf8 characters" {
|
test "countGraphemeClusters: utf8 characters" {
|
||||||
|
@ -741,7 +741,7 @@ test "countGraphemeClusters: utf8 characters" {
|
||||||
defer str.deinit();
|
defer str.deinit();
|
||||||
|
|
||||||
const count = countGraphemeClusters(str);
|
const count = countGraphemeClusters(str);
|
||||||
expectEqual(count, 3);
|
try expectEqual(count, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "countGraphemeClusters: emojis" {
|
test "countGraphemeClusters: emojis" {
|
||||||
|
@ -751,7 +751,7 @@ test "countGraphemeClusters: emojis" {
|
||||||
defer str.deinit();
|
defer str.deinit();
|
||||||
|
|
||||||
const count = countGraphemeClusters(str);
|
const count = countGraphemeClusters(str);
|
||||||
expectEqual(count, 3);
|
try expectEqual(count, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "countGraphemeClusters: emojis and ut8 characters" {
|
test "countGraphemeClusters: emojis and ut8 characters" {
|
||||||
|
@ -761,7 +761,7 @@ test "countGraphemeClusters: emojis and ut8 characters" {
|
||||||
defer str.deinit();
|
defer str.deinit();
|
||||||
|
|
||||||
const count = countGraphemeClusters(str);
|
const count = countGraphemeClusters(str);
|
||||||
expectEqual(count, 6);
|
try expectEqual(count, 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "countGraphemeClusters: emojis, ut8, and ascii characters" {
|
test "countGraphemeClusters: emojis, ut8, and ascii characters" {
|
||||||
|
@ -771,7 +771,7 @@ test "countGraphemeClusters: emojis, ut8, and ascii characters" {
|
||||||
defer str.deinit();
|
defer str.deinit();
|
||||||
|
|
||||||
const count = countGraphemeClusters(str);
|
const count = countGraphemeClusters(str);
|
||||||
expectEqual(count, 10);
|
try expectEqual(count, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Str.startsWith
|
// Str.startsWith
|
||||||
|
@ -821,27 +821,27 @@ pub fn startsWithCodePoint(string: RocStr, prefix: u32) callconv(.C) bool {
|
||||||
test "startsWithCodePoint: ascii char" {
|
test "startsWithCodePoint: ascii char" {
|
||||||
const whole = RocStr.init("foobar", 6);
|
const whole = RocStr.init("foobar", 6);
|
||||||
const prefix = 'f';
|
const prefix = 'f';
|
||||||
expect(startsWithCodePoint(whole, prefix));
|
try expect(startsWithCodePoint(whole, prefix));
|
||||||
}
|
}
|
||||||
|
|
||||||
test "startsWithCodePoint: emoji" {
|
test "startsWithCodePoint: emoji" {
|
||||||
const yes = RocStr.init("💖foobar", 10);
|
const yes = RocStr.init("💖foobar", 10);
|
||||||
const no = RocStr.init("foobar", 6);
|
const no = RocStr.init("foobar", 6);
|
||||||
const prefix = '💖';
|
const prefix = '💖';
|
||||||
expect(startsWithCodePoint(yes, prefix));
|
try expect(startsWithCodePoint(yes, prefix));
|
||||||
expect(!startsWithCodePoint(no, prefix));
|
try expect(!startsWithCodePoint(no, prefix));
|
||||||
}
|
}
|
||||||
|
|
||||||
test "startsWith: foo starts with fo" {
|
test "startsWith: foo starts with fo" {
|
||||||
const foo = RocStr.init("foo", 3);
|
const foo = RocStr.init("foo", 3);
|
||||||
const fo = RocStr.init("fo", 2);
|
const fo = RocStr.init("fo", 2);
|
||||||
expect(startsWith(foo, fo));
|
try expect(startsWith(foo, fo));
|
||||||
}
|
}
|
||||||
|
|
||||||
test "startsWith: 123456789123456789 starts with 123456789123456789" {
|
test "startsWith: 123456789123456789 starts with 123456789123456789" {
|
||||||
const str = RocStr.init("123456789123456789", 18);
|
const str = RocStr.init("123456789123456789", 18);
|
||||||
defer str.deinit();
|
defer str.deinit();
|
||||||
expect(startsWith(str, str));
|
try expect(startsWith(str, str));
|
||||||
}
|
}
|
||||||
|
|
||||||
test "startsWith: 12345678912345678910 starts with 123456789123456789" {
|
test "startsWith: 12345678912345678910 starts with 123456789123456789" {
|
||||||
|
@ -850,7 +850,7 @@ test "startsWith: 12345678912345678910 starts with 123456789123456789" {
|
||||||
const prefix = RocStr.init("123456789123456789", 18);
|
const prefix = RocStr.init("123456789123456789", 18);
|
||||||
defer prefix.deinit();
|
defer prefix.deinit();
|
||||||
|
|
||||||
expect(startsWith(str, prefix));
|
try expect(startsWith(str, prefix));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Str.endsWith
|
// Str.endsWith
|
||||||
|
@ -882,13 +882,13 @@ test "endsWith: foo ends with oo" {
|
||||||
defer foo.deinit();
|
defer foo.deinit();
|
||||||
defer oo.deinit();
|
defer oo.deinit();
|
||||||
|
|
||||||
expect(endsWith(foo, oo));
|
try expect(endsWith(foo, oo));
|
||||||
}
|
}
|
||||||
|
|
||||||
test "endsWith: 123456789123456789 ends with 123456789123456789" {
|
test "endsWith: 123456789123456789 ends with 123456789123456789" {
|
||||||
const str = RocStr.init("123456789123456789", 18);
|
const str = RocStr.init("123456789123456789", 18);
|
||||||
defer str.deinit();
|
defer str.deinit();
|
||||||
expect(endsWith(str, str));
|
try expect(endsWith(str, str));
|
||||||
}
|
}
|
||||||
|
|
||||||
test "endsWith: 12345678912345678910 ends with 345678912345678910" {
|
test "endsWith: 12345678912345678910 ends with 345678912345678910" {
|
||||||
|
@ -897,7 +897,7 @@ test "endsWith: 12345678912345678910 ends with 345678912345678910" {
|
||||||
defer str.deinit();
|
defer str.deinit();
|
||||||
defer suffix.deinit();
|
defer suffix.deinit();
|
||||||
|
|
||||||
expect(endsWith(str, suffix));
|
try expect(endsWith(str, suffix));
|
||||||
}
|
}
|
||||||
|
|
||||||
test "endsWith: hello world ends with world" {
|
test "endsWith: hello world ends with world" {
|
||||||
|
@ -906,7 +906,7 @@ test "endsWith: hello world ends with world" {
|
||||||
defer str.deinit();
|
defer str.deinit();
|
||||||
defer suffix.deinit();
|
defer suffix.deinit();
|
||||||
|
|
||||||
expect(endsWith(str, suffix));
|
try expect(endsWith(str, suffix));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Str.concat
|
// Str.concat
|
||||||
|
@ -978,7 +978,7 @@ test "RocStr.concat: small concat small" {
|
||||||
|
|
||||||
defer result.deinit();
|
defer result.deinit();
|
||||||
|
|
||||||
expect(roc_str3.eq(result));
|
try expect(roc_str3.eq(result));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const RocListStr = extern struct {
|
pub const RocListStr = extern struct {
|
||||||
|
@ -1057,7 +1057,7 @@ test "RocStr.joinWith: result is big" {
|
||||||
|
|
||||||
defer result.deinit();
|
defer result.deinit();
|
||||||
|
|
||||||
expect(roc_result.eq(result));
|
try expect(roc_result.eq(result));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Str.toBytes
|
// Str.toBytes
|
||||||
|
@ -1191,8 +1191,8 @@ fn validateUtf8BytesX(str: RocList) FromUtf8Result {
|
||||||
return fromUtf8(str);
|
return fromUtf8(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expectOk(result: FromUtf8Result) void {
|
fn expectOk(result: FromUtf8Result) !void {
|
||||||
expectEqual(result.is_ok, true);
|
try expectEqual(result.is_ok, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sliceHelp(bytes: [*]const u8, length: usize) RocList {
|
fn sliceHelp(bytes: [*]const u8, length: usize) RocList {
|
||||||
|
@ -1217,7 +1217,7 @@ test "validateUtf8Bytes: ascii" {
|
||||||
const ptr: [*]const u8 = @ptrCast([*]const u8, raw);
|
const ptr: [*]const u8 = @ptrCast([*]const u8, raw);
|
||||||
const list = sliceHelp(ptr, raw.len);
|
const list = sliceHelp(ptr, raw.len);
|
||||||
|
|
||||||
expectOk(validateUtf8BytesX(list));
|
try expectOk(validateUtf8BytesX(list));
|
||||||
}
|
}
|
||||||
|
|
||||||
test "validateUtf8Bytes: unicode œ" {
|
test "validateUtf8Bytes: unicode œ" {
|
||||||
|
@ -1225,7 +1225,7 @@ test "validateUtf8Bytes: unicode œ" {
|
||||||
const ptr: [*]const u8 = @ptrCast([*]const u8, raw);
|
const ptr: [*]const u8 = @ptrCast([*]const u8, raw);
|
||||||
const list = sliceHelp(ptr, raw.len);
|
const list = sliceHelp(ptr, raw.len);
|
||||||
|
|
||||||
expectOk(validateUtf8BytesX(list));
|
try expectOk(validateUtf8BytesX(list));
|
||||||
}
|
}
|
||||||
|
|
||||||
test "validateUtf8Bytes: unicode ∆" {
|
test "validateUtf8Bytes: unicode ∆" {
|
||||||
|
@ -1233,7 +1233,7 @@ test "validateUtf8Bytes: unicode ∆" {
|
||||||
const ptr: [*]const u8 = @ptrCast([*]const u8, raw);
|
const ptr: [*]const u8 = @ptrCast([*]const u8, raw);
|
||||||
const list = sliceHelp(ptr, raw.len);
|
const list = sliceHelp(ptr, raw.len);
|
||||||
|
|
||||||
expectOk(validateUtf8BytesX(list));
|
try expectOk(validateUtf8BytesX(list));
|
||||||
}
|
}
|
||||||
|
|
||||||
test "validateUtf8Bytes: emoji" {
|
test "validateUtf8Bytes: emoji" {
|
||||||
|
@ -1241,7 +1241,7 @@ test "validateUtf8Bytes: emoji" {
|
||||||
const ptr: [*]const u8 = @ptrCast([*]const u8, raw);
|
const ptr: [*]const u8 = @ptrCast([*]const u8, raw);
|
||||||
const list = sliceHelp(ptr, raw.len);
|
const list = sliceHelp(ptr, raw.len);
|
||||||
|
|
||||||
expectOk(validateUtf8BytesX(list));
|
try expectOk(validateUtf8BytesX(list));
|
||||||
}
|
}
|
||||||
|
|
||||||
test "validateUtf8Bytes: unicode ∆ in middle of array" {
|
test "validateUtf8Bytes: unicode ∆ in middle of array" {
|
||||||
|
@ -1249,15 +1249,15 @@ test "validateUtf8Bytes: unicode ∆ in middle of array" {
|
||||||
const ptr: [*]const u8 = @ptrCast([*]const u8, raw);
|
const ptr: [*]const u8 = @ptrCast([*]const u8, raw);
|
||||||
const list = sliceHelp(ptr, raw.len);
|
const list = sliceHelp(ptr, raw.len);
|
||||||
|
|
||||||
expectOk(validateUtf8BytesX(list));
|
try expectOk(validateUtf8BytesX(list));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expectErr(list: RocList, index: usize, err: Utf8DecodeError, problem: Utf8ByteProblem) void {
|
fn expectErr(list: RocList, index: usize, err: Utf8DecodeError, problem: Utf8ByteProblem) !void {
|
||||||
const str_ptr = @ptrCast([*]u8, list.bytes);
|
const str_ptr = @ptrCast([*]u8, list.bytes);
|
||||||
const str_len = list.length;
|
const str_len = list.length;
|
||||||
|
|
||||||
expectError(err, numberOfNextCodepointBytes(str_ptr, str_len, index));
|
try expectError(err, numberOfNextCodepointBytes(str_ptr, str_len, index));
|
||||||
expectEqual(toErrUtf8ByteResponse(index, problem), validateUtf8Bytes(str_ptr, str_len));
|
try expectEqual(toErrUtf8ByteResponse(index, problem), validateUtf8Bytes(str_ptr, str_len));
|
||||||
}
|
}
|
||||||
|
|
||||||
test "validateUtf8Bytes: invalid start byte" {
|
test "validateUtf8Bytes: invalid start byte" {
|
||||||
|
@ -1266,7 +1266,7 @@ test "validateUtf8Bytes: invalid start byte" {
|
||||||
const ptr: [*]const u8 = @ptrCast([*]const u8, raw);
|
const ptr: [*]const u8 = @ptrCast([*]const u8, raw);
|
||||||
const list = sliceHelp(ptr, raw.len);
|
const list = sliceHelp(ptr, raw.len);
|
||||||
|
|
||||||
expectErr(list, 2, error.Utf8InvalidStartByte, Utf8ByteProblem.InvalidStartByte);
|
try expectErr(list, 2, error.Utf8InvalidStartByte, Utf8ByteProblem.InvalidStartByte);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "validateUtf8Bytes: unexpected eof for 2 byte sequence" {
|
test "validateUtf8Bytes: unexpected eof for 2 byte sequence" {
|
||||||
|
@ -1275,7 +1275,7 @@ test "validateUtf8Bytes: unexpected eof for 2 byte sequence" {
|
||||||
const ptr: [*]const u8 = @ptrCast([*]const u8, raw);
|
const ptr: [*]const u8 = @ptrCast([*]const u8, raw);
|
||||||
const list = sliceHelp(ptr, raw.len);
|
const list = sliceHelp(ptr, raw.len);
|
||||||
|
|
||||||
expectErr(list, 3, error.UnexpectedEof, Utf8ByteProblem.UnexpectedEndOfSequence);
|
try expectErr(list, 3, error.UnexpectedEof, Utf8ByteProblem.UnexpectedEndOfSequence);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "validateUtf8Bytes: expected continuation for 2 byte sequence" {
|
test "validateUtf8Bytes: expected continuation for 2 byte sequence" {
|
||||||
|
@ -1284,7 +1284,7 @@ test "validateUtf8Bytes: expected continuation for 2 byte sequence" {
|
||||||
const ptr: [*]const u8 = @ptrCast([*]const u8, raw);
|
const ptr: [*]const u8 = @ptrCast([*]const u8, raw);
|
||||||
const list = sliceHelp(ptr, raw.len);
|
const list = sliceHelp(ptr, raw.len);
|
||||||
|
|
||||||
expectErr(list, 3, error.Utf8ExpectedContinuation, Utf8ByteProblem.ExpectedContinuation);
|
try expectErr(list, 3, error.Utf8ExpectedContinuation, Utf8ByteProblem.ExpectedContinuation);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "validateUtf8Bytes: unexpected eof for 3 byte sequence" {
|
test "validateUtf8Bytes: unexpected eof for 3 byte sequence" {
|
||||||
|
@ -1293,7 +1293,7 @@ test "validateUtf8Bytes: unexpected eof for 3 byte sequence" {
|
||||||
const ptr: [*]const u8 = @ptrCast([*]const u8, raw);
|
const ptr: [*]const u8 = @ptrCast([*]const u8, raw);
|
||||||
const list = sliceHelp(ptr, raw.len);
|
const list = sliceHelp(ptr, raw.len);
|
||||||
|
|
||||||
expectErr(list, 3, error.UnexpectedEof, Utf8ByteProblem.UnexpectedEndOfSequence);
|
try expectErr(list, 3, error.UnexpectedEof, Utf8ByteProblem.UnexpectedEndOfSequence);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "validateUtf8Bytes: expected continuation for 3 byte sequence" {
|
test "validateUtf8Bytes: expected continuation for 3 byte sequence" {
|
||||||
|
@ -1302,7 +1302,7 @@ test "validateUtf8Bytes: expected continuation for 3 byte sequence" {
|
||||||
const ptr: [*]const u8 = @ptrCast([*]const u8, raw);
|
const ptr: [*]const u8 = @ptrCast([*]const u8, raw);
|
||||||
const list = sliceHelp(ptr, raw.len);
|
const list = sliceHelp(ptr, raw.len);
|
||||||
|
|
||||||
expectErr(list, 3, error.Utf8ExpectedContinuation, Utf8ByteProblem.ExpectedContinuation);
|
try expectErr(list, 3, error.Utf8ExpectedContinuation, Utf8ByteProblem.ExpectedContinuation);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "validateUtf8Bytes: unexpected eof for 4 byte sequence" {
|
test "validateUtf8Bytes: unexpected eof for 4 byte sequence" {
|
||||||
|
@ -1311,7 +1311,7 @@ test "validateUtf8Bytes: unexpected eof for 4 byte sequence" {
|
||||||
const ptr: [*]const u8 = @ptrCast([*]const u8, raw);
|
const ptr: [*]const u8 = @ptrCast([*]const u8, raw);
|
||||||
const list = sliceHelp(ptr, raw.len);
|
const list = sliceHelp(ptr, raw.len);
|
||||||
|
|
||||||
expectErr(list, 3, error.UnexpectedEof, Utf8ByteProblem.UnexpectedEndOfSequence);
|
try expectErr(list, 3, error.UnexpectedEof, Utf8ByteProblem.UnexpectedEndOfSequence);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "validateUtf8Bytes: expected continuation for 4 byte sequence" {
|
test "validateUtf8Bytes: expected continuation for 4 byte sequence" {
|
||||||
|
@ -1320,7 +1320,7 @@ test "validateUtf8Bytes: expected continuation for 4 byte sequence" {
|
||||||
const ptr: [*]const u8 = @ptrCast([*]const u8, raw);
|
const ptr: [*]const u8 = @ptrCast([*]const u8, raw);
|
||||||
const list = sliceHelp(ptr, raw.len);
|
const list = sliceHelp(ptr, raw.len);
|
||||||
|
|
||||||
expectErr(list, 3, error.Utf8ExpectedContinuation, Utf8ByteProblem.ExpectedContinuation);
|
try expectErr(list, 3, error.Utf8ExpectedContinuation, Utf8ByteProblem.ExpectedContinuation);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "validateUtf8Bytes: overlong" {
|
test "validateUtf8Bytes: overlong" {
|
||||||
|
@ -1329,7 +1329,7 @@ test "validateUtf8Bytes: overlong" {
|
||||||
const ptr: [*]const u8 = @ptrCast([*]const u8, raw);
|
const ptr: [*]const u8 = @ptrCast([*]const u8, raw);
|
||||||
const list = sliceHelp(ptr, raw.len);
|
const list = sliceHelp(ptr, raw.len);
|
||||||
|
|
||||||
expectErr(list, 3, error.Utf8OverlongEncoding, Utf8ByteProblem.OverlongEncoding);
|
try expectErr(list, 3, error.Utf8OverlongEncoding, Utf8ByteProblem.OverlongEncoding);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "validateUtf8Bytes: codepoint out too large" {
|
test "validateUtf8Bytes: codepoint out too large" {
|
||||||
|
@ -1338,7 +1338,7 @@ test "validateUtf8Bytes: codepoint out too large" {
|
||||||
const ptr: [*]const u8 = @ptrCast([*]const u8, raw);
|
const ptr: [*]const u8 = @ptrCast([*]const u8, raw);
|
||||||
const list = sliceHelp(ptr, raw.len);
|
const list = sliceHelp(ptr, raw.len);
|
||||||
|
|
||||||
expectErr(list, 3, error.Utf8CodepointTooLarge, Utf8ByteProblem.CodepointTooLarge);
|
try expectErr(list, 3, error.Utf8CodepointTooLarge, Utf8ByteProblem.CodepointTooLarge);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "validateUtf8Bytes: surrogate halves" {
|
test "validateUtf8Bytes: surrogate halves" {
|
||||||
|
@ -1347,5 +1347,5 @@ test "validateUtf8Bytes: surrogate halves" {
|
||||||
const ptr: [*]const u8 = @ptrCast([*]const u8, raw);
|
const ptr: [*]const u8 = @ptrCast([*]const u8, raw);
|
||||||
const list = sliceHelp(ptr, raw.len);
|
const list = sliceHelp(ptr, raw.len);
|
||||||
|
|
||||||
expectErr(list, 3, error.Utf8EncodesSurrogateHalf, Utf8ByteProblem.EncodesSurrogateHalf);
|
try expectErr(list, 3, error.Utf8EncodesSurrogateHalf, Utf8ByteProblem.EncodesSurrogateHalf);
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,44 +71,6 @@ pub const IntWidth = enum(u8) {
|
||||||
Usize,
|
Usize,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn intWidth(width: IntWidth) anytype {
|
|
||||||
switch (width) {
|
|
||||||
IntWidth.U8 => {
|
|
||||||
return u8;
|
|
||||||
},
|
|
||||||
IntWidth.U16 => {
|
|
||||||
return u16;
|
|
||||||
},
|
|
||||||
IntWidth.U32 => {
|
|
||||||
return u32;
|
|
||||||
},
|
|
||||||
IntWidth.U64 => {
|
|
||||||
return u64;
|
|
||||||
},
|
|
||||||
IntWidth.U128 => {
|
|
||||||
return u128;
|
|
||||||
},
|
|
||||||
IntWidth.I8 => {
|
|
||||||
return i8;
|
|
||||||
},
|
|
||||||
IntWidth.I16 => {
|
|
||||||
return i16;
|
|
||||||
},
|
|
||||||
IntWidth.I32 => {
|
|
||||||
return i32;
|
|
||||||
},
|
|
||||||
IntWidth.I64 => {
|
|
||||||
return i64;
|
|
||||||
},
|
|
||||||
IntWidth.I128 => {
|
|
||||||
return i128;
|
|
||||||
},
|
|
||||||
IntWidth.Usize => {
|
|
||||||
return usize;
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn decref(
|
pub fn decref(
|
||||||
bytes_or_null: ?[*]u8,
|
bytes_or_null: ?[*]u8,
|
||||||
data_bytes: usize,
|
data_bytes: usize,
|
||||||
|
|
|
@ -56,11 +56,7 @@ fn main() {
|
||||||
let dest_bc = dest_bc_path.to_str().expect("Invalid dest bc path");
|
let dest_bc = dest_bc_path.to_str().expect("Invalid dest bc path");
|
||||||
println!("Compiling bitcode to: {}", dest_bc);
|
println!("Compiling bitcode to: {}", dest_bc);
|
||||||
|
|
||||||
run_command(
|
run_command(build_script_dir_path, "llvm-as", &[dest_ir, "-o", dest_bc]);
|
||||||
build_script_dir_path,
|
|
||||||
"llvm-as-10",
|
|
||||||
&[dest_ir, "-o", dest_bc],
|
|
||||||
);
|
|
||||||
|
|
||||||
get_zig_files(bitcode_path.as_path(), &|path| {
|
get_zig_files(bitcode_path.as_path(), &|path| {
|
||||||
let path: &Path = path;
|
let path: &Path = path;
|
||||||
|
|
|
@ -302,6 +302,8 @@ impl<'a, 'ctx, 'env> Env<'a, 'ctx, 'env> {
|
||||||
/* dwo_id */ 0,
|
/* dwo_id */ 0,
|
||||||
/* split_debug_inling */ false,
|
/* split_debug_inling */ false,
|
||||||
/* debug_info_for_profiling */ false,
|
/* debug_info_for_profiling */ false,
|
||||||
|
"",
|
||||||
|
"",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -163,7 +163,7 @@ pub export fn roc_fx_getInt() GetInt {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn roc_fx_getInt_help() !i64 {
|
fn roc_fx_getInt_help() !i64 {
|
||||||
const stdin = std.io.getStdIn().inStream();
|
const stdin = std.io.getStdIn().reader();
|
||||||
var buf: [40]u8 = undefined;
|
var buf: [40]u8 = undefined;
|
||||||
|
|
||||||
const line: []u8 = (try stdin.readUntilDelimiterOrEof(&buf, '\n')) orelse "";
|
const line: []u8 = (try stdin.readUntilDelimiterOrEof(&buf, '\n')) orelse "";
|
||||||
|
|
|
@ -59,7 +59,7 @@ pub export fn main() i32 {
|
||||||
roc__mainForHost_1_exposed(&callresult);
|
roc__mainForHost_1_exposed(&callresult);
|
||||||
|
|
||||||
// stdout the result
|
// stdout the result
|
||||||
stdout.print("{}\n", .{callresult.content.asSlice()}) catch unreachable;
|
stdout.print("{s}\n", .{callresult.content.asSlice()}) catch unreachable;
|
||||||
|
|
||||||
callresult.content.deinit();
|
callresult.content.deinit();
|
||||||
|
|
||||||
|
|
|
@ -1,2 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
llvm-as "$@"
|
|
|
@ -1,50 +0,0 @@
|
||||||
{ pkgs }:
|
|
||||||
|
|
||||||
let
|
|
||||||
# system helpers
|
|
||||||
splitSystem = builtins.split "-" builtins.currentSystem;
|
|
||||||
arch = builtins.elemAt splitSystem 0;
|
|
||||||
isAarch64 = arch == "aarch64";
|
|
||||||
setForSystem = { darwin, darwinAarch64, linux, linuxAarch64 }:
|
|
||||||
if pkgs.stdenv.isDarwin
|
|
||||||
then (
|
|
||||||
if isAarch64
|
|
||||||
then darwinAarch64
|
|
||||||
else darwin
|
|
||||||
)
|
|
||||||
else (
|
|
||||||
if isAarch64
|
|
||||||
then linuxAarch64
|
|
||||||
else linux
|
|
||||||
);
|
|
||||||
|
|
||||||
version = "0.8.0-dev.2711+11ae6c42c";
|
|
||||||
osName =
|
|
||||||
if pkgs.stdenv.isDarwin
|
|
||||||
then "macos" else "linux";
|
|
||||||
archiveName = "zig-${osName}-${arch}-${version}";
|
|
||||||
sha256 = setForSystem {
|
|
||||||
darwin = "bf2a4cd1516d202cfbbcaa7b1308d36aa21a9f9284b39297e70f98c003f479e3";
|
|
||||||
darwinAarch64 = "6bc35c3b40b853cd351c890c94c4a6043f5ca492ff6d704bdb1544fe1fe54d9a";
|
|
||||||
linux = "b443cc2259fe7712ffc954745266e3ec846e27854713d817bcec35fefd655a8c";
|
|
||||||
linuxAarch64 = "229830e6dc92f641a1106af3a8ee96fdef379ffd3a3d7db7ed62d2b46bd8ed45";
|
|
||||||
};
|
|
||||||
in
|
|
||||||
pkgs.stdenv.mkDerivation {
|
|
||||||
pname = "zig-unstable";
|
|
||||||
version = version;
|
|
||||||
src = pkgs.fetchurl {
|
|
||||||
inherit sha256;
|
|
||||||
name = "${archiveName}.tar.xz";
|
|
||||||
url = "https://ziglang.org/builds/${archiveName}.tar.xz";
|
|
||||||
};
|
|
||||||
phases = [ "unpackPhase" ];
|
|
||||||
unpackPhase = ''
|
|
||||||
mkdir -p $out/bin
|
|
||||||
tar -xf $src
|
|
||||||
cp ${archiveName}/zig $out/zig
|
|
||||||
cp -r ${archiveName}/lib $out/lib
|
|
||||||
ln -s "$out/zig" "$out/bin/zig"
|
|
||||||
chmod +x $out/bin/zig
|
|
||||||
'';
|
|
||||||
}
|
|
32
nix/zig.nix
32
nix/zig.nix
|
@ -1,10 +1,32 @@
|
||||||
{ pkgs }:
|
{ pkgs }:
|
||||||
|
|
||||||
if pkgs.stdenv.isDarwin then
|
|
||||||
let
|
let
|
||||||
version = "0.7.1";
|
version = "0.8.0";
|
||||||
archiveName = "zig-macos-x86_64-${version}";
|
|
||||||
sha256 = "845cb17562978af0cf67e3993f4e33330525eaf01ead9386df9105111e3bc519";
|
osName =
|
||||||
|
if pkgs.stdenv.isDarwin then
|
||||||
|
"macos"
|
||||||
|
else
|
||||||
|
"linux";
|
||||||
|
|
||||||
|
splitSystem = builtins.split "-" builtins.currentSystem;
|
||||||
|
arch = builtins.elemAt splitSystem 0;
|
||||||
|
isAarch64 = arch == "aarch64";
|
||||||
|
|
||||||
|
archiveName = "zig-${osName}-${arch}-${version}";
|
||||||
|
|
||||||
|
# If you're system is not aarch64, we assume it's x86_64
|
||||||
|
sha256 =
|
||||||
|
if pkgs.stdenv.isDarwin then
|
||||||
|
if isAarch64 then
|
||||||
|
"b32d13f66d0e1ff740b3326d66a469ee6baddbd7211fa111c066d3bd57683111"
|
||||||
|
else
|
||||||
|
"279f9360b5cb23103f0395dc4d3d0d30626e699b1b4be55e98fd985b62bc6fbe"
|
||||||
|
else
|
||||||
|
if isAarch64 then
|
||||||
|
"ee204ca2c2037952cf3f8b10c609373a08a291efa4af7b3c73be0f2b27720470"
|
||||||
|
else
|
||||||
|
"502625d3da3ae595c5f44a809a87714320b7a40e6dff4a895b5fa7df3391d01e";
|
||||||
in
|
in
|
||||||
pkgs.stdenv.mkDerivation {
|
pkgs.stdenv.mkDerivation {
|
||||||
pname = "zig";
|
pname = "zig";
|
||||||
|
@ -24,5 +46,3 @@ if pkgs.stdenv.isDarwin then
|
||||||
chmod +x $out/bin/zig
|
chmod +x $out/bin/zig
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
else
|
|
||||||
pkgs.zig
|
|
||||||
|
|
12
shell.nix
12
shell.nix
|
@ -42,9 +42,8 @@ let
|
||||||
xorg.libxcb
|
xorg.libxcb
|
||||||
];
|
];
|
||||||
|
|
||||||
llvmPkgs = pkgs.llvmPackages_10;
|
llvmPkgs = pkgs.llvmPackages_12;
|
||||||
|
|
||||||
# zig = import ./nix/zig-unstable.nix { inherit pkgs; };
|
|
||||||
zig = import ./nix/zig.nix { inherit pkgs; };
|
zig = import ./nix/zig.nix { inherit pkgs; };
|
||||||
|
|
||||||
inputs = with pkgs;[
|
inputs = with pkgs;[
|
||||||
|
@ -80,7 +79,7 @@ pkgs.mkShell
|
||||||
buildInputs = inputs ++ darwinInputs ++ linuxInputs;
|
buildInputs = inputs ++ darwinInputs ++ linuxInputs;
|
||||||
|
|
||||||
# Additional Env vars
|
# Additional Env vars
|
||||||
LLVM_SYS_100_PREFIX = "${llvmPkgs.llvm}";
|
LLVM_SYS_120_PREFIX = "${llvmPkgs.llvm}";
|
||||||
LD_LIBRARY_PATH =
|
LD_LIBRARY_PATH =
|
||||||
with pkgs;
|
with pkgs;
|
||||||
lib.makeLibraryPath
|
lib.makeLibraryPath
|
||||||
|
@ -97,11 +96,4 @@ pkgs.mkShell
|
||||||
]
|
]
|
||||||
++ linuxInputs
|
++ linuxInputs
|
||||||
);
|
);
|
||||||
|
|
||||||
# Non Nix llvm installs names the bin llvm-as-${version}, so we
|
|
||||||
# alias `llvm` to `llvm-as-${version}` here.
|
|
||||||
# This the name of the file in nix/bin will need to be updated whenever llvm is updated
|
|
||||||
shellHook = ''
|
|
||||||
export PATH="$PATH:$PWD/nix/bin"
|
|
||||||
'';
|
|
||||||
}
|
}
|
||||||
|
|
2
vendor/inkwell/Cargo.toml
vendored
2
vendor/inkwell/Cargo.toml
vendored
|
@ -23,7 +23,7 @@ edition = "2018"
|
||||||
# commit of TheDan64/inkwell, push a new tag which points to the latest commit,
|
# commit of TheDan64/inkwell, push a new tag which points to the latest commit,
|
||||||
# change the tag value in this Cargo.toml to point to that tag, and `cargo update`.
|
# change the tag value in this Cargo.toml to point to that tag, and `cargo update`.
|
||||||
# This way, GitHub Actions works and nobody's builds get broken.
|
# This way, GitHub Actions works and nobody's builds get broken.
|
||||||
inkwell = { git = "https://github.com/rtfeldman/inkwell", tag = "llvm12-0.release2", features = [ "llvm10-0" ] }
|
inkwell = { git = "https://github.com/rtfeldman/inkwell", tag = "llvm12-0.release4", features = [ "llvm12-0" ] }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
target-arm = []
|
target-arm = []
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue