Skip to content

Commit

Permalink
Merge branch 'main' into ignore-ctrl-c-in-repl
Browse files Browse the repository at this point in the history
  • Loading branch information
ageron authored Sep 21, 2024
2 parents 2014221 + 6c846a5 commit 6a0eb80
Show file tree
Hide file tree
Showing 65 changed files with 1,645 additions and 1,365 deletions.
23 changes: 20 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ members = [
"crates/wasm_module",
"crates/wasm_interp",
"crates/language_server",
"crates/roc_std_heap",
]

exclude = [
Expand Down
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,8 @@ You can 💜 **sponsor** 💜 Roc on:
- [GitHub](https://github.com/sponsors/roc-lang)
- [Liberapay](https://liberapay.com/roc_lang)

We are very grateful for our corporate sponsors [Vendr](https://www.vendr.com/), [RWX](https://www.rwx.com), [Tweede golf](https://tweedegolf.nl/en), [ohne-makler](https://www.ohne-makler.net), and [Decem](https://www.decem.com.au):
We are very grateful for our corporate sponsors [Tweede golf](https://tweedegolf.nl/en), [ohne-makler](https://www.ohne-makler.net), and [Decem](https://www.decem.com.au):

[<img src="https://user-images.githubusercontent.com/1094080/223597445-81755626-a080-4299-a38c-3c92e7548489.png" height="60" alt="Vendr logo"/>](https://www.vendr.com)
&nbsp;&nbsp;&nbsp;&nbsp;
[<img src="https://github.com/roc-lang/roc/assets/1094080/82c0868e-d23f-42a0-ac2d-c6e6b2e16575" height="60" alt="RWX logo"/>](https://www.rwx.com)
&nbsp;&nbsp;&nbsp;&nbsp;
[<img src="https://user-images.githubusercontent.com/1094080/183123052-856815b1-8cc9-410a-83b0-589f03613188.svg" height="60" alt="tweede golf logo"/>](https://tweedegolf.nl/en)
&nbsp;&nbsp;&nbsp;&nbsp;
[<img src="https://www.ohne-makler.net/static/img/brand/logo.svg" height="60" alt="ohne-makler logo"/>](https://www.ohne-makler.net)
Expand All @@ -35,6 +31,7 @@ If you would like your company to become a corporate sponsor of Roc's developmen

We'd also like to express our gratitude to our generous [individual sponsors](https://github.com/sponsors/roc-lang/)! A special thanks to those sponsoring $25/month or more:

- [Peter Marreck](https://github.com/pmarreck)
- [Barry Moore](https://github.com/chiroptical)
- Eric Andresen
- [Jackson Lucky](https://github.com/jluckyiv)
Expand Down
2 changes: 1 addition & 1 deletion crates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ Surgical linker that links platforms to Roc applications. We created our own lin

## `repl_cli/` - `roc_repl_cli`

Command Line Interface(CLI) functionality for the Read-Evaluate-Print-Loop (REPL).
Command Line Interface (CLI) functionality for the Read-Evaluate-Print-Loop (REPL).

## `repl_eval/` - `roc_repl_eval`

Expand Down
13 changes: 8 additions & 5 deletions crates/cli/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,20 +266,23 @@ mod tests {
const FORMATTED_ROC: &str = r#"app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.15.0/SlwdbJ-3GR7uBWQo6zlmYWNYOxnvo8r6YABXD-45UOw.tar.br" }
import pf.Stdout
import pf.Task
import pf.Stdin
main =
Stdout.line! "I'm a Roc application!""#;
Stdout.line! "What's your name?"
name = Stdin.line!
Stdout.line! "Hi $(name)!""#;

const UNFORMATTED_ROC: &str = r#"app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.15.0/SlwdbJ-3GR7uBWQo6zlmYWNYOxnvo8r6YABXD-45UOw.tar.br" }
import pf.Stdout
import pf.Task
import pf.Stdin
main =
Stdout.line! "I'm a Roc application!"
Stdout.line! "What's your name?"
name = Stdin.line!
Stdout.line! "Hi $(name)!"
"#;

fn setup_test_file(dir: &Path, file_name: &str, contents: &str) -> PathBuf {
Expand Down
20 changes: 18 additions & 2 deletions crates/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ pub const FLAG_NO_LINK: &str = "no-link";
pub const FLAG_TARGET: &str = "target";
pub const FLAG_TIME: &str = "time";
pub const FLAG_VERBOSE: &str = "verbose";
pub const FLAG_NO_COLOR: &str = "no-color";
pub const FLAG_NO_HEADER: &str = "no-header";
pub const FLAG_LINKER: &str = "linker";
pub const FLAG_PREBUILT: &str = "prebuilt-platform";
pub const FLAG_CHECK: &str = "check";
Expand Down Expand Up @@ -271,6 +273,20 @@ pub fn build_app() -> Command {
)
.subcommand(Command::new(CMD_REPL)
.about("Launch the interactive Read Eval Print Loop (REPL)")
.arg(
Arg::new(FLAG_NO_COLOR)
.long(FLAG_NO_COLOR)
.help("Do not use any ANSI color codes in the repl output")
.action(ArgAction::SetTrue)
.required(false)
)
.arg(
Arg::new(FLAG_NO_HEADER)
.long(FLAG_NO_HEADER)
.help("Do not print the repl header")
.action(ArgAction::SetTrue)
.required(false)
)
)
.subcommand(Command::new(CMD_RUN)
.about("Run a .roc file even if it has build errors")
Expand Down Expand Up @@ -1279,8 +1295,8 @@ fn roc_dev_native(
break if libc::WIFEXITED(status) {
libc::WEXITSTATUS(status)
} else {
// we don't have an exit code, so we probably shouldn't make one up
0
// we don't have an exit code, but something went wrong if we're in this else
1
};
}
ChildProcessMsg::Expect => {
Expand Down
12 changes: 9 additions & 3 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ use roc_cli::{
build_app, format_files, format_src, test, BuildConfig, FormatMode, CMD_BUILD, CMD_CHECK,
CMD_DEV, CMD_DOCS, CMD_FORMAT, CMD_GEN_STUB_LIB, CMD_GLUE, CMD_PREPROCESS_HOST, CMD_REPL,
CMD_RUN, CMD_TEST, CMD_VERSION, DIRECTORY_OR_FILES, FLAG_CHECK, FLAG_DEV, FLAG_LIB, FLAG_MAIN,
FLAG_NO_LINK, FLAG_OUTPUT, FLAG_PP_DYLIB, FLAG_PP_HOST, FLAG_PP_PLATFORM, FLAG_STDIN,
FLAG_STDOUT, FLAG_TARGET, FLAG_TIME, GLUE_DIR, GLUE_SPEC, ROC_FILE,
FLAG_NO_COLOR, FLAG_NO_HEADER, FLAG_NO_LINK, FLAG_OUTPUT, FLAG_PP_DYLIB, FLAG_PP_HOST,
FLAG_PP_PLATFORM, FLAG_STDIN, FLAG_STDOUT, FLAG_TARGET, FLAG_TIME, GLUE_DIR, GLUE_SPEC,
ROC_FILE,
};
use roc_docs::generate_docs_html;
use roc_error_macros::user_error;
Expand Down Expand Up @@ -242,7 +243,12 @@ fn main() -> io::Result<()> {
}
}
}
Some((CMD_REPL, _)) => Ok(roc_repl_cli::main()),
Some((CMD_REPL, matches)) => {
let has_color = !matches.get_one::<bool>(FLAG_NO_COLOR).unwrap();
let has_header = !matches.get_one::<bool>(FLAG_NO_HEADER).unwrap();

Ok(roc_repl_cli::main(has_color, has_header))
}
Some((CMD_DOCS, matches)) => {
let root_path = matches.get_one::<PathBuf>(ROC_FILE).unwrap();
let out_dir = matches.get_one::<OsString>(FLAG_OUTPUT).unwrap();
Expand Down
19 changes: 19 additions & 0 deletions crates/cli/tests/cli_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,25 @@ mod cli_run {
);
}

#[test]
#[cfg_attr(windows, ignore)]
fn module_params_multiline_pattern() {
test_roc_app(
"crates/cli/tests/module_params",
"multiline_params.roc",
&[],
&[],
&[],
indoc!(
r#"
hi
"#
),
UseValgrind::No,
TestCliCommands::Dev,
);
}

#[test]
#[cfg_attr(windows, ignore)]
fn transitive_expects() {
Expand Down
8 changes: 8 additions & 0 deletions crates/cli/tests/module_params/MultilineParams.roc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module {
sendHttpReq,
getEnvVar
} -> [hi]

hi : Str
hi =
"hi"
11 changes: 11 additions & 0 deletions crates/cli/tests/module_params/multiline_params.roc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
app [main] {
pf: platform "../fixtures/multi-dep-str/platform/main.roc",
}

import MultilineParams {
sendHttpReq: \_ -> crash "todo",
getEnvVar: \_ -> crash "todo",
}

main =
MultilineParams.hi
35 changes: 18 additions & 17 deletions crates/compiler/builtins/bitcode/src/list.zig
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,16 @@ pub fn listDropAt(
) callconv(.C) RocList {
const size = list.len();
const size_u64 = @as(u64, @intCast(size));

// NOTE
// we need to return an empty list explicitly,
// because we rely on the pointer field being null if the list is empty
// which also requires duplicating the utils.decref call to spend the RC token
if (size <= 1) {
list.decref(alignment, element_width, elements_refcounted, dec);
return RocList.empty();
}

// If droping the first or last element, return a seamless slice.
// For simplicity, do this by calling listSublist.
// In the future, we can test if it is faster to manually inline the important parts here.
Expand All @@ -638,25 +648,16 @@ pub fn listDropAt(
// were >= than `size`, and we know `size` fits in usize.
const drop_index: usize = @intCast(drop_index_u64);

if (elements_refcounted) {
const element = source_ptr + drop_index * element_width;
dec(element);
}

// NOTE
// we need to return an empty list explicitly,
// because we rely on the pointer field being null if the list is empty
// which also requires duplicating the utils.decref call to spend the RC token
if (size < 2) {
list.decref(alignment, element_width, elements_refcounted, dec);
return RocList.empty();
}

if (list.isUnique()) {
var i = drop_index;
const copy_target = source_ptr;
if (elements_refcounted) {
const element = source_ptr + drop_index * element_width;
dec(element);
}

const copy_target = source_ptr + (drop_index * element_width);
const copy_source = copy_target + element_width;
std.mem.copyForwards(u8, copy_target[i..size], copy_source[i..size]);
const copy_size = (size - drop_index - 1) * element_width;
std.mem.copyForwards(u8, copy_target[0..copy_size], copy_source[0..copy_size]);

var new_list = list;

Expand Down
Loading

0 comments on commit 6a0eb80

Please sign in to comment.