Skip to content

Commit

Permalink
Implement suggested improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
LostKobrakai committed Nov 10, 2024
1 parent 1ed0576 commit 6796a61
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
9 changes: 4 additions & 5 deletions compiler-core/src/build/package_compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,6 @@ where
app_file_config: Option<&ErlangAppCodegenConfiguration>,
) -> Result<(), Error> {
let mut written = HashSet::new();
let native_modules: Vec<EcoString>;
let build_dir = self.out.join(paths::ARTEFACT_DIRECTORY_NAME);
let include_dir = self.out.join("include");
let io = self.io.clone();
Expand All @@ -349,13 +348,13 @@ where
// version and not the newly compiled version.
Erlang::new(&build_dir, &include_dir).render(io.clone(), modules)?;

if self.compile_beam_bytecode {
let native_modules: Vec<EcoString> = if self.compile_beam_bytecode {
written.extend(modules.iter().map(Module::compiled_erlang_path));
native_modules = self.compile_erlang_to_beam(&written)?;
self.compile_erlang_to_beam(&written)?
} else {
tracing::debug!("skipping_erlang_bytecode_compilation");
native_modules = Vec::new();
}
Vec::new()
};

if let Some(config) = app_file_config {
ErlangApp::new(&self.out.join("ebin"), config).render(
Expand Down
25 changes: 10 additions & 15 deletions compiler-core/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,23 +154,18 @@ impl<'a> ErlangApp<'a> {
}

fn format_atom(s: &EcoString) -> EcoString {
match s.chars().next() {
Some(first_char) => {
// Check if first character is not lowercase
let needs_quotes = !first_char.is_ascii_lowercase();
let mut chars = s.chars();

// Check if string contains any characters other than alphanumeric, underscore, or @
let contains_special = s
.chars()
.any(|c| !(c.is_alphanumeric() || c == '_' || c == '@'));
let Some(first) = chars.next() else {
return "''".into();
};

if needs_quotes || contains_special {
EcoString::from(format!("'{}'", s))
} else {
s.clone()
}
}
None => EcoString::from("''"),
let needs_escape = |c: char| !(c.is_alphanumeric() || c == '_' || c == '@');

if !first.is_ascii_lowercase() || chars.any(needs_escape) {
format!("'{}'", s).into()
} else {
s.clone()
}
}
}
Expand Down

0 comments on commit 6796a61

Please sign in to comment.