Merge remote-tracking branch 'upstream/main' into list-walkBckwardsUntil

This commit is contained in:
Anton-4 2022-10-08 19:55:47 +02:00
commit a44f692563
No known key found for this signature in database
GPG key ID: A13F4A6E21141925
197 changed files with 799 additions and 994 deletions

View file

@ -28,7 +28,7 @@ jobs:
run: ls | grep "roc_nightly.*tar\.gz" | xargs tar -xzvf
- name: test roc hello world
run: ./roc examples/hello-world/main.roc
run: ./roc examples/helloWorld.roc

View file

@ -41,7 +41,7 @@ jobs:
run: ls | grep "roc_nightly.*tar\.gz" | xargs tar -xzvf
- name: test roc hello world
run: ./roc examples/hello-world/main.roc
run: ./roc examples/helloWorld.roc

35
Cargo.lock generated
View file

@ -620,10 +620,10 @@ dependencies = [
[[package]]
name = "confy"
version = "0.4.0"
source = "git+https://github.com/rust-cli/confy#c6b62039281b8643539b436440bcea1b0d634bc7"
version = "0.5.0"
source = "git+https://github.com/rust-cli/confy#fd069f062aa3373c846f0d8c6e3b5e2a5cd0096b"
dependencies = [
"directories-next",
"directories",
"serde",
"serde_yaml",
"thiserror",
@ -1160,13 +1160,13 @@ dependencies = [
]
[[package]]
name = "directories-next"
version = "2.0.0"
name = "directories"
version = "2.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "339ee130d97a610ea5a5872d2bbb130fdf68884ff09d3028b81bec8a1ac23bbc"
checksum = "551a778172a450d7fc12e629ca3b0428d00f6afa9a43da1b630d54604e97371c"
dependencies = [
"cfg-if 1.0.0",
"dirs-sys-next",
"cfg-if 0.1.10",
"dirs-sys",
]
[[package]]
@ -1179,6 +1179,17 @@ dependencies = [
"dirs-sys-next",
]
[[package]]
name = "dirs-sys"
version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6"
dependencies = [
"libc",
"redox_users",
"winapi",
]
[[package]]
name = "dirs-sys-next"
version = "0.1.2"
@ -3466,8 +3477,6 @@ dependencies = [
"roc_tracing",
"serial_test",
"signal-hook",
"strum",
"strum_macros",
"target-lexicon",
"tempfile",
"ven_pretty",
@ -4766,9 +4775,9 @@ checksum = "063e6045c0e62079840579a7e47a355ae92f60eb74daaf156fb1e84ba164e63f"
[[package]]
name = "strum_macros"
version = "0.24.2"
version = "0.24.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4faebde00e8ff94316c01800f9054fd2ba77d30d9e922541913051d1d978918b"
checksum = "1e385be0d24f186b4ce2f9982191e7101bb737312ad61c1f2f984f34bcf85d59"
dependencies = [
"heck",
"proc-macro2",
@ -5154,7 +5163,7 @@ version = "1.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675"
dependencies = [
"cfg-if 1.0.0",
"cfg-if 0.1.10",
"rand",
"static_assertions",
]

View file

@ -57,9 +57,10 @@ members = [
"crates/wasi-libc-sys",
]
exclude = [
# Examples sometimes have Rust hosts in their platforms. The compiler should ignore those.
"examples",
"ci/bench-runner",
# Examples sometimes have Rust hosts in their platforms. The compiler should ignore those.
"crates/cli_testing_examples",
"examples",
# Ignore building these normally. They are only imported by tests.
# The tests will still correctly build them.
"crates/cli_utils",

View file

@ -50,7 +50,7 @@ install-zig-llvm-valgrind:
copy-dirs:
FROM +install-zig-llvm-valgrind
COPY --dir crates examples Cargo.toml Cargo.lock version.txt www ./
COPY --dir crates Cargo.toml Cargo.lock version.txt www ./
# compile everything needed for benchmarks and output a self-contained dir from which benchmarks can be run.
prep-bench-folder:
@ -60,11 +60,11 @@ prep-bench-folder:
ARG BENCH_SUFFIX=branch
RUN cargo criterion -V
RUN --mount=type=cache,target=$SCCACHE_DIR cd crates/cli && cargo criterion --no-run
RUN mkdir -p bench-folder/crates/cli_testing_examples/benchmarks
RUN mkdir -p bench-folder/crates/compiler/builtins/bitcode/src
RUN mkdir -p bench-folder/target/release/deps
RUN mkdir -p bench-folder/examples/benchmarks
RUN cp examples/benchmarks/*.roc bench-folder/examples/benchmarks/
RUN cp -r examples/benchmarks/platform bench-folder/examples/benchmarks/
RUN cp crates/cli_testing_examples/benchmarks/*.roc bench-folder/crates/cli_testing_examples/benchmarks/
RUN cp -r crates/cli_testing_examples/benchmarks/platform bench-folder/crates/cli_testing_examples/benchmarks/
RUN cp crates/compiler/builtins/bitcode/src/str.zig bench-folder/crates/compiler/builtins/bitcode/src
RUN cp target/release/roc bench-folder/target/release
# copy the most recent time bench to bench-folder

View file

@ -115,7 +115,7 @@ Create a new file called `Hello.roc` and put this inside it:
```coffee
app "hello"
packages { pf: "examples/interactive/cli-platform/main.roc" }
packages { pf: "examples/cli/cli-platform/main.roc" }
imports [pf.Stdout, pf.Program]
provides [main] to pf
@ -124,8 +124,8 @@ main = Stdout.line "I'm a Roc application!" |> Program.quick
> **NOTE:** This assumes you've put Hello.roc in the root directory of the Roc
> source code. If you'd like to put it somewhere else, you'll need to replace
> `"examples/interactive/cli-platform/main.roc"` with the path to the
> `examples/interactive/cli-platform/main.roc` file in that source code. In the future,
> `"examples/cli/cli-platform/main.roc"` with the path to the
> `examples/cli/cli-platform/main.roc` file in that source code. In the future,
> Roc will have the tutorial built in, and this aside will no longer be
> necessary!
@ -1273,7 +1273,7 @@ Let's take a closer look at the part of `Hello.roc` above `main`:
```coffee
app "hello"
packages { pf: "examples/interactive/cli-platform/main.roc" }
packages { pf: "examples/cli/cli-platform/main.roc" }
imports [pf.Stdout, pf.Program]
provides main to pf
```
@ -1291,14 +1291,14 @@ without running it by running `roc build Hello.roc`.
The remaining lines all involve the *platform* this application is built on:
```coffee
packages { pf: "examples/interactive/cli-platform/main.roc" }
packages { pf: "examples/cli/cli-platform/main.roc" }
imports [pf.Stdout, pf.Program]
provides main to pf
```
The `packages { pf: "examples/interactive/cli-platform/main.roc" }` part says two things:
The `packages { pf: "examples/cli/cli-platform/main.roc" }` part says two things:
- We're going to be using a *package* (that is, a collection of modules) called `"examples/interactive/cli-platform/main.roc"`
- We're going to be using a *package* (that is, a collection of modules) called `"examples/cli/cli-platform/main.roc"`
- We're going to name that package `pf` so we can refer to it more concisely in the future.
The `imports [pf.Stdout, pf.Program]` line says that we want to import the `Stdout` and `Program` modules
@ -1320,16 +1320,16 @@ which effectively makes it a simple Roc program.
When we write `imports [pf.Stdout, pf.Program]`, it specifies that the `Stdout`
and `Program` modules come from the `pf` package.
Since `pf` was the name we chose for the `examples/interactive/cli-platform/main.roc`
package (when we wrote `packages { pf: "examples/interactive/cli-platform/main.roc" }`),
Since `pf` was the name we chose for the `examples/cli/cli-platform/main.roc`
package (when we wrote `packages { pf: "examples/cli/cli-platform/main.roc" }`),
this `imports` line tells the Roc compiler that when we call `Stdout.line`, it
should look for that `line` function in the `Stdout` module of the
`examples/interactive/cli-platform/main.roc` package.
`examples/cli/cli-platform/main.roc` package.
## Tasks
Tasks are technically not part of the Roc language, but they're very common in
platforms. Let's use the CLI platform in `examples/interactive/cli-platform/main.roc` as an example!
platforms. Let's use the CLI platform in `examples/cli/cli-platform/main.roc` as an example!
In the CLI platform, we have four operations we can do:
@ -1344,7 +1344,7 @@ First, let's do a basic "Hello World" using the tutorial app.
```coffee
app "cli-tutorial"
packages { pf: "examples/interactive/cli-platform/main.roc" }
packages { pf: "examples/cli/cli-platform/main.roc" }
imports [pf.Stdout, pf.Program]
provides [main] to pf
@ -1382,7 +1382,7 @@ Let's change `main` to read a line from `stdin`, and then print it back out agai
```swift
app "cli-tutorial"
packages { pf: "examples/interactive/cli-platform/main.roc" }
packages { pf: "examples/cli/cli-platform/main.roc" }
imports [pf.Stdout, pf.Stdin, pf.Task, pf.Program]
provides [main] to pf
@ -1434,7 +1434,7 @@ This works, but we can make it a little nicer to read. Let's change it to the fo
```haskell
app "cli-tutorial"
packages { pf: "examples/interactive/cli-platform/main.roc" }
packages { pf: "examples/cli/cli-platform/main.roc" }
imports [pf.Stdout, pf.Stdin, pf.Task.{ await }, pf.Program]
provides [main] to pf

View file

@ -227,9 +227,10 @@ fn calc_hashes_for_folder(benches_path_str: &str) -> HashMap<String, String> {
}
fn check_if_bench_executables_changed() -> bool {
let bench_folder_str = "/examples/benchmarks/";
let bench_folder_str = "/crates/cli_testing_examples/benchmarks/";
let main_benches_path_str = [BENCH_FOLDER_MAIN, bench_folder_str].join("");
let main_bench_hashes = calc_hashes_for_folder(&main_benches_path_str);
let branch_benches_path_str = [BENCH_FOLDER_BRANCH, bench_folder_str].join("");

View file

@ -1,4 +1,4 @@
#!/usr/bin/env bash
cp target/release/roc ./roc # to be able to exclude "target" later in the tar command
cp -r target/release/lib ./lib
tar -czvf $1 --exclude="target" --exclude="zig-cache" roc lib LICENSE LEGAL_DETAILS examples/hello-world crates/roc_std
tar -czvf $1 --exclude="target" --exclude="zig-cache" roc lib LICENSE LEGAL_DETAILS examples/helloWorld.roc examples/cli crates/roc_std

View file

@ -99,8 +99,6 @@ indoc = "1.0.7"
serial_test = "0.9.0"
criterion = { git = "https://github.com/Anton-4/criterion.rs"}
cli_utils = { path = "../cli_utils" }
strum = "0.24.0"
strum_macros = "0.24"
once_cell = "1.14.0"
parking_lot = "0.12"

File diff suppressed because it is too large Load diff

View file

@ -1,5 +1,5 @@
app "type-error"
packages { pf: "../../../../examples/interactive/cli-platform/main.roc" }
packages { pf: "../../../../examples/cli/cli-platform/main.roc" }
imports [pf.Stdout.{ line }, pf.Task.{ await }, pf.Program]
provides [main] to pf

View file

@ -0,0 +1,6 @@
*.dSYM
libhost.a
libapp.so
dynhost
preprocessedhost
metadata

View file

@ -16,7 +16,7 @@ name = "host"
path = "src/main.rs"
[dependencies]
roc_std = { path = "../../../crates/roc_std" }
roc_std = { path = "../../../../crates/roc_std" }
libc = "0.2"
[workspace]

View file

@ -3,12 +3,12 @@
To run this website, first compile either of these identical apps:
```bash
# Option A: Compile examples/platform-switching/rocLovesWebAssembly.roc
cargo run -- build --target=wasm32 examples/platform-switching/rocLovesWebAssembly.roc
# Option A: Compile crates/cli_testing_examples/platform-switching/rocLovesWebAssembly.roc
cargo run -- build --target=wasm32 crates/cli_testing_examples/platform-switching/rocLovesWebAssembly.roc
# Option B: Compile examples/platform-switching/main.roc with `pf: "web-assembly-platform/main.roc"` and move the result
cargo run -- build --target=wasm32 examples/platform-switching/main.roc
(cd examples/platform-switching && mv rocLovesPlatforms.wasm web-assembly-platform/rocLovesWebAssembly.wasm)
# Option B: Compile crates/cli_testing_examples/platform-switching/main.roc with `pf: "web-assembly-platform/main.roc"` and move the result
cargo run -- build --target=wasm32 crates/cli_testing_examples/platform-switching/main.roc
(cd crates/cli_testing_examples/platform-switching && mv rocLovesPlatforms.wasm web-assembly-platform/rocLovesWebAssembly.wasm)
```
Then `cd` into the website directory
@ -16,7 +16,7 @@ and run any web server that can handle WebAssembly.
For example, with `http-server`:
```bash
cd examples/platform-switching/web-assembly-platform
cd crates/cli_testing_examples/platform-switching/web-assembly-platform
npm install -g http-server
http-server
```

File diff suppressed because one or more lines are too long

View file

@ -381,20 +381,31 @@ pub fn root_dir() -> PathBuf {
path
}
// start the dir with crates/cli_testing_examples
#[allow(dead_code)]
pub fn examples_dir(dir_name: &str) -> PathBuf {
pub fn cli_testing_dir(dir_name: &str) -> PathBuf {
let mut path = root_dir();
// Descend into examples/{dir_name}
path.push("examples");
path.push("crates");
path.push("cli_testing_examples");
path.extend(dir_name.split("/")); // Make slashes cross-target
path
}
#[allow(dead_code)]
pub fn example_file(dir_name: &str, file_name: &str) -> PathBuf {
let mut path = examples_dir(dir_name);
pub fn dir_path_from_root(dir_name: &str) -> PathBuf {
let mut path = root_dir();
path.extend(dir_name.split("/")); // Make slashes cross-target
path
}
#[allow(dead_code)]
pub fn file_path_from_root(dir_name: &str, file_name: &str) -> PathBuf {
let mut path = dir_path_from_root(dir_name);
path.push(file_name);

View file

@ -374,7 +374,7 @@ pub fn build_zig_host_wasm32(
"c",
"-target",
zig_target,
// "-femit-llvm-ir=/home/folkertdev/roc/roc/examples/benchmarks/platform/host.ll",
// "-femit-llvm-ir=/home/folkertdev/roc/roc/crates/cli_testing_examples/benchmarks/platform/host.ll",
"-fPIC",
"--strip",
];
@ -635,6 +635,7 @@ pub fn rebuild_host(
} else if cargo_host_src.exists() {
// Compile and link Cargo.toml, if it exists
let cargo_dir = host_input_path.parent().unwrap();
let cargo_out_dir = cargo_dir.join("target").join(
if matches!(opt_level, OptLevel::Optimize | OptLevel::Size) {
"release"
@ -1215,7 +1216,7 @@ fn link_wasm32(
"-O",
"ReleaseSmall",
// useful for debugging
// "-femit-llvm-ir=/home/folkertdev/roc/roc/examples/benchmarks/platform/host.ll",
// "-femit-llvm-ir=/home/folkertdev/roc/roc/crates/cli_testing_examples/benchmarks/platform/host.ll",
])
.spawn()?;

View file

@ -521,7 +521,7 @@ fn read_main_roc_file(project_dir_path_opt: Option<&Path>) -> (PathBuf, String)
// returns path and content of app file
fn init_new_roc_project(project_dir_path: &Path) -> (PathBuf, String) {
let orig_platform_path = Path::new("./examples/hello-world").join(PLATFORM_DIR_NAME);
let orig_platform_path = Path::new("./examples/cli").join(PLATFORM_DIR_NAME);
let roc_file_path = Path::new("./new-roc-project/main.roc");

View file

@ -730,16 +730,24 @@ test1 =
file_to_string(&file_path)
}
fn cli_testing_path(sub_path: &str) -> String {
let examples_dir = "../cli_testing_examples/".to_string();
let file_path = examples_dir + sub_path;
file_to_string(&file_path)
}
#[test]
fn test_hello() {
let tokens = tokenize(&example_path("hello-world/main.roc"));
let tokens = tokenize(&example_path("helloWorld.roc"));
assert_eq!(tokenparser::module(&tokens), Ok(()));
}
#[test]
fn test_fibo() {
let tokens = tokenize(&example_path("algorithms/fibonacci.roc"));
let tokens = tokenize(&cli_testing_path("algorithms/fibonacci.roc"));
assert_eq!(tokenparser::module(&tokens), Ok(()));
}
@ -831,14 +839,14 @@ test1 =
#[test]
fn test_base64() {
let tokens = tokenize(&example_path("benchmarks/Base64.roc"));
let tokens = tokenize(&cli_testing_path("benchmarks/Base64.roc"));
assert_eq!(tokenparser::module(&tokens), Ok(()));
}
#[test]
fn test_base64_test() {
let tokens = tokenize(&example_path("benchmarks/TestBase64.roc"));
let tokens = tokenize(&cli_testing_path("benchmarks/TestBase64.roc"));
assert_eq!(tokenparser::module(&tokens), Ok(()));
}
@ -874,14 +882,14 @@ test1 =
#[test]
fn test_astar_test() {
let tokens = tokenize(&example_path("benchmarks/TestAStar.roc"));
let tokens = tokenize(&cli_testing_path("benchmarks/TestAStar.roc"));
assert_eq!(tokenparser::module(&tokens), Ok(()));
}
#[test]
fn test_cli_echo() {
let tokens = tokenize(&example_path("interactive/echo.roc"));
let tokens = tokenize(&example_path("cli/echo.roc"));
assert_eq!(tokenparser::module(&tokens), Ok(()));
}
@ -1106,7 +1114,7 @@ test1 =
#[test]
fn test_closure_file() {
let tokens = tokenize(&example_path("benchmarks/Closure.roc"));
let tokens = tokenize(&cli_testing_path("benchmarks/Closure.roc"));
assert_eq!(tokenparser::module(&tokens), Ok(()));
}
@ -1126,7 +1134,7 @@ test1 =
#[test]
fn test_nqueens() {
let tokens = tokenize(&example_path("benchmarks/NQueens.roc"));
let tokens = tokenize(&cli_testing_path("benchmarks/NQueens.roc"));
assert_eq!(tokenparser::module(&tokens), Ok(()));
}
@ -1149,7 +1157,7 @@ test1 =
#[test]
fn test_quicksort() {
let tokens = tokenize(&example_path("benchmarks/Quicksort.roc"));
let tokens = tokenize(&cli_testing_path("benchmarks/Quicksort.roc"));
assert_eq!(tokenparser::module(&tokens), Ok(()));
}
@ -1176,7 +1184,7 @@ test1 =
#[test]
fn test_task() {
let tokens = tokenize(&example_path("benchmarks/platform/Task.roc"));
let tokens = tokenize(&cli_testing_path("benchmarks/platform/Task.roc"));
assert_eq!(tokenparser::module(&tokens), Ok(()));
}
@ -1221,7 +1229,7 @@ test1 =
#[test]
fn test_cfold() {
let tokens = tokenize(&example_path("benchmarks/CFold.roc"));
let tokens = tokenize(&cli_testing_path("benchmarks/CFold.roc"));
assert_eq!(tokenparser::module(&tokens), Ok(()));
}
@ -1291,7 +1299,7 @@ balance = \color ->
#[test]
fn test_rbtree_insert() {
let tokens = tokenize(&example_path("benchmarks/RBTreeInsert.roc"));
let tokens = tokenize(&cli_testing_path("benchmarks/RBTreeInsert.roc"));
assert_eq!(tokenparser::module(&tokens), Ok(()));
}
@ -1357,7 +1365,7 @@ balance = \color ->
#[test]
fn test_rbtree_ck() {
let tokens = tokenize(&example_path("benchmarks/RBTreeCk.roc"));
let tokens = tokenize(&cli_testing_path("benchmarks/RBTreeCk.roc"));
assert_eq!(tokenparser::module(&tokens), Ok(()));
}
@ -1390,7 +1398,7 @@ balance = \color ->
#[test]
fn test_astar() {
let tokens = tokenize(&example_path("benchmarks/AStar.roc"));
let tokens = tokenize(&cli_testing_path("benchmarks/AStar.roc"));
assert_eq!(tokenparser::module(&tokens), Ok(()));
}
@ -1409,7 +1417,7 @@ balance = \color ->
#[test]
fn test_false_interpreter_context() {
let tokens = tokenize(&example_path("false-interpreter/Context.roc"));
let tokens = tokenize(&example_path("cli/false-interpreter/Context.roc"));
assert_eq!(tokenparser::module(&tokens), Ok(()));
}
@ -1437,7 +1445,7 @@ balance = \color ->
#[test]
fn test_deriv() {
let tokens = tokenize(&example_path("benchmarks/Deriv.roc"));
let tokens = tokenize(&cli_testing_path("benchmarks/Deriv.roc"));
assert_eq!(tokenparser::module(&tokens), Ok(()));
}

2
examples/.gitignore vendored
View file

@ -4,3 +4,5 @@ libapp.so
dynhost
preprocessedhost
metadata
helloWorld

View file

@ -14,7 +14,7 @@ Run examples as follows:
roc run hello-world/main.roc
```
`examples/benchmarks/` contains some larger examples.
`crates/cli_testing_examples/benchmarks/` contains some larger examples.
Some examples like `examples/benchmarks/NQueens.roc` require input after running.
Some examples like `crates/cli_testing_examples/benchmarks/NQueens.roc` require input after running.
For NQueens, input 10 in the terminal and press enter.

View file

@ -1,4 +1,4 @@
# Interactive examples
# CLI examples
These are examples of how to make basic CLI (command-line interface) and TUI (terminal user interface) apps in Roc.

Some files were not shown because too many files have changed in this diff Show more