Skip to content

Commit

Permalink
feature to uwu-ify compile errors and warnings (#714)
Browse files Browse the repository at this point in the history
* optional uwu mode

* fix compiler error
  • Loading branch information
sezna authored Jan 27, 2022
1 parent 258e926 commit 3012191
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 6 deletions.
44 changes: 44 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions forc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ tokio = { version = "1.8.0", features = ["macros", "rt-multi-thread", "process"]
toml = "0.5"
ureq = "2.4"
whoami = "1.1"
uwuify = { version = "^0.2", optional = true }

[features]
default = []
test = []
util = []
uwu = ["uwuify"]
20 changes: 18 additions & 2 deletions forc/src/utils/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ fn format_err(err: &sway_core::CompileError) {
// if start/pos are same we will not get that arrow pointing to code, so we add +1.
end_pos += 1;
}
let friendly_str = err.to_friendly_error_string();
let friendly_str = maybe_uwuify(&err.to_friendly_error_string());
let snippet = Snippet {
title: Some(Annotation {
label: None,
Expand Down Expand Up @@ -246,7 +246,7 @@ fn format_warning(err: &sway_core::CompileWarning) {
let path = err.path();

let (start_pos, mut end_pos) = err.span();
let friendly_str = err.to_friendly_warning_string();
let friendly_str = maybe_uwuify(&err.to_friendly_warning_string());
if start_pos == end_pos {
// if start/pos are same we will not get that arrow pointing to code, so we add +1.
end_pos += 1;
Expand Down Expand Up @@ -276,3 +276,19 @@ fn format_warning(err: &sway_core::CompileWarning) {
};
eprintln!("{}", DisplayList::from(snippet))
}

#[cfg(all(feature = "uwu", any(target_arch = "x86", target_arch = "x86_64")))]
fn maybe_uwuify(raw: &str) -> String {
use uwuifier::uwuify_str_sse;
uwuify_str_sse(raw)
}
#[cfg(all(feature = "uwu", not(any(target_arch = "x86", target_arch = "x86_64"))))]
fn maybe_uwuify(raw: &str) -> String {
compile_error!("The `uwu` feature only works on x86 or x86_64 processors.");
Default::default()
}

#[cfg(not(feature = "uwu"))]
fn maybe_uwuify(raw: &str) -> String {
raw.to_string()
}
6 changes: 2 additions & 4 deletions test/src/e2e_vm_tests/test_programs/if_elseif_enum/Forc.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
[project]
author = "Fuel Labs <[email protected]>"
entry = "main.sw"
license = "Apache-2.0"
name = "if_elseif_enum"
entry = "main.sw"


[dependencies]
std = { git = "http://github.com/FuelLabs/sway-lib-std", version = "v0.0.1" }
core = { git = "http://github.com/FuelLabs/sway-lib-core", version = "v0.0.1" }


std = { git = "http://github.com/FuelLabs/sway-lib-std", version = "v0.0.1" }

0 comments on commit 3012191

Please sign in to comment.