Skip to content

Commit

Permalink
Fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
dfellis committed Mar 7, 2024
1 parent 70eb13f commit 022ed50
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 24 deletions.
13 changes: 10 additions & 3 deletions src/lntors/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ use ordered_hash_map::OrderedHashMap;
use crate::lntors::function::from_microstatement;
use crate::program::{Function, Microstatement, Program};

pub fn generate(program: &Program, mut normal_fns: OrderedHashMap<String, String>) -> Result<(String, OrderedHashMap<String, String>), Box<dyn std::error::Error>> {
pub fn generate(
program: &Program,
mut normal_fns: OrderedHashMap<String, String>,
) -> Result<(String, OrderedHashMap<String, String>), Box<dyn std::error::Error>> {
// The events will all go into an `event` sub-module with every function marked public. These
// event functions are what the `emit <eventName> <optionalValue>;` statements will call, so
// something like:
Expand Down Expand Up @@ -105,8 +108,12 @@ pub fn generate(program: &Program, mut normal_fns: OrderedHashMap<String, String
} else {
// Inline the microstatements if it's an Alan function
for microstatement in &handler_fn.microstatements {
let (stmt, f) =
from_microstatement(microstatement, handlerscope, program, normal_fns)?;
let (stmt, f) = from_microstatement(
microstatement,
handlerscope,
program,
normal_fns,
)?;
normal_fns = f;
if stmt != "" {
out = format!("{} {};\n", out, stmt);
Expand Down
36 changes: 16 additions & 20 deletions src/lntors/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,11 @@ pub fn from_microstatement(
match microstatement {
Microstatement::Arg { .. } => Ok(("".to_string(), out)), // Skip arg microstatements that are just used for discovery during generation
Microstatement::Assignment { name, value } => {
let (val, o) = from_microstatement(value, scope, program, out)?;
// I wish I didn't have to write the following line because you can't re-assign a
// variable in a let destructuring, afaict
out = o;
Ok((format!(
"let {} = {}",
name,
val,
)
.to_string(), out))
let (val, o) = from_microstatement(value, scope, program, out)?;
// I wish I didn't have to write the following line because you can't re-assign a
// variable in a let destructuring, afaict
out = o;
Ok((format!("let {} = {}", name, val,).to_string(), out))
}
Microstatement::Value {
typen,
Expand Down Expand Up @@ -54,16 +49,22 @@ pub fn from_microstatement(
out = o;
argstrs.push(a);
}
Ok((format!("{}({})", rustname, argstrs.join(", ")).to_string(), out))
},
Ok((
format!("{}({})", rustname, argstrs.join(", ")).to_string(),
out,
))
}
Some(rustname) => {
let mut argstrs = Vec::new();
for arg in args {
let (a, o) = from_microstatement(arg, scope, program, out)?;
out = o;
argstrs.push(a);
}
Ok((format!("{}({})", rustname, argstrs.join(", ")).to_string(), out))
Ok((
format!("{}({})", rustname, argstrs.join(", ")).to_string(),
out,
))
}
},
}
Expand All @@ -80,13 +81,8 @@ pub fn from_microstatement(
Some(val) => {
let (emitval, o) = from_microstatement(val, scope, program, out)?;
out = o;
Ok((format!(
"event::{}({})",
event,
emitval,
)
.to_string(), out))
},
Ok((format!("event::{}({})", event, emitval,).to_string(), out))
}
None => Ok((format!("event::{}()", event).to_string(), out)),
},
}
Expand Down
8 changes: 7 additions & 1 deletion src/lntors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,11 @@ pub fn lntors(entry_file: String) -> Result<String, Box<dyn std::error::Error>>
assert_eq!(func[0].args.len(), 0);
// Assertion proven, start emitting the Rust `main` function
fns = fn_generate("main".to_string(), &func[0], &scope, &program, fns)?;
Ok(format!("{}\n{}\n{}", preamble, event_fns, fns.into_values().collect::<Vec<String>>().join("\n")).to_string())
Ok(format!(
"{}\n{}\n{}",
preamble,
event_fns,
fns.into_values().collect::<Vec<String>>().join("\n")
)
.to_string())
}

0 comments on commit 022ed50

Please sign in to comment.