mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 16:21:11 +00:00
Add some comments to main.rs
This commit is contained in:
parent
7165f55d6e
commit
32f19428ac
1 changed files with 12 additions and 3 deletions
|
@ -29,27 +29,35 @@ fn process_task(evaluated: Evaluated) -> std::io::Result<()> {
|
||||||
ApplyVariant(name, Some(mut vals)) => {
|
ApplyVariant(name, Some(mut vals)) => {
|
||||||
match name.as_str() {
|
match name.as_str() {
|
||||||
"Echo" => {
|
"Echo" => {
|
||||||
let string_to_echo = match vals.pop() {
|
// Extract the string from the Echo variant.
|
||||||
|
let string_to_be_displayed = match vals.pop() {
|
||||||
Some(Str(payload)) => payload,
|
Some(Str(payload)) => payload,
|
||||||
Some(EvalError(err)) => { panic!("RUNTIME ERROR in Echo: {}", format!("{}", err)); },
|
Some(EvalError(err)) => { panic!("RUNTIME ERROR in Echo: {}", format!("{}", err)); },
|
||||||
Some(val) => { panic!("TYPE MISMATCH in Echo: {}", format!("{}", val)); },
|
Some(val) => { panic!("TYPE MISMATCH in Echo: {}", format!("{}", val)); },
|
||||||
None => { panic!("TYPE MISMATCH in Echo: None"); }
|
None => { panic!("TYPE MISMATCH in Echo: None"); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Print the string to the console, since that's what Echo does!
|
||||||
|
println!("{}", string_to_be_displayed);
|
||||||
|
|
||||||
|
// Continue with the callback.
|
||||||
let callback = vals.pop().unwrap();
|
let callback = vals.pop().unwrap();
|
||||||
println!("{}", string_to_echo);
|
|
||||||
|
|
||||||
process_task(call(callback, vec![Expr::EmptyRecord]))
|
process_task(call(callback, vec![Expr::EmptyRecord]))
|
||||||
},
|
},
|
||||||
"Read" => {
|
"Read" => {
|
||||||
let callback = vals.pop().unwrap();
|
// Read a line from from stdin, since that's what Read does!
|
||||||
let mut input = String::new();
|
let mut input = String::new();
|
||||||
|
|
||||||
io::stdin().read_line(&mut input)?;
|
io::stdin().read_line(&mut input)?;
|
||||||
|
|
||||||
|
// Continue with the callback.
|
||||||
|
let callback = vals.pop().unwrap();
|
||||||
|
|
||||||
process_task(call(callback, vec![Expr::Str(input.trim().to_string())]))
|
process_task(call(callback, vec![Expr::Str(input.trim().to_string())]))
|
||||||
},
|
},
|
||||||
_ => {
|
_ => {
|
||||||
|
// We don't recognize this variant, so display it and exit.
|
||||||
display_val(ApplyVariant(name, Some(vals)));
|
display_val(ApplyVariant(name, Some(vals)));
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -57,6 +65,7 @@ fn process_task(evaluated: Evaluated) -> std::io::Result<()> {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
output => {
|
output => {
|
||||||
|
// We don't recognize this value, so display it and exit.
|
||||||
display_val(output);
|
display_val(output);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue