Skip to content

Commit

Permalink
fix errors from changes introduced by code review
Browse files Browse the repository at this point in the history
  • Loading branch information
lucidashygirl committed Aug 10, 2024
1 parent 18b5876 commit 98ecf85
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 32 deletions.
43 changes: 22 additions & 21 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,29 +59,29 @@ fn handle_compile(cli: Cli) -> Result<(), Box<dyn Error>> {
String::from(input.to_string_lossy().trim())
} else {
return Ok(());
}
};

let code = if valid_input == "-" {
let mut buf = String::new();
match stdin().read_to_string(&mut buf) {
Ok(_) => buf,
Err(err) => handle_err(err),
}
} else {
match fs::read_to_string(&valid_input) {
Ok(code) => code,
Err(err) => handle_err(err),
}
let mut buf = String::new();
match stdin().read_to_string(&mut buf) {
Ok(_) => buf,
Err(err) => handle_err(err),
}
} else {
match fs::read_to_string(&valid_input) {
Ok(code) => code,
Err(err) => handle_err(err),
}
};

let (valid_messages, valid_code) = match AmberCompiler::new(code, Some(valid_input), cli.clone()).compile() {
Ok(result) => result
Err(err) => {
err.show();
std::process::exit(1);
}
}
let (valid_messages, valid_code) =
match AmberCompiler::new(code, Some(valid_input), cli.clone()).compile() {
Ok(result) => result,
Err(err) => {
err.show();
std::process::exit(1);
}
};
valid_messages.iter().for_each(|m| m.show());
// Save to the output file
let valid_output = if let Some(output) = cli.output {
Expand All @@ -91,7 +91,7 @@ fn handle_compile(cli: Cli) -> Result<(), Box<dyn Error>> {
(!valid_messages.is_empty()).then(render_dash);
let exit_status = AmberCompiler::execute(valid_code, &[])?;
std::process::exit(exit_status.code().unwrap_or(1));
}
};

if valid_output == "--silent" {
return Ok(());
Expand Down Expand Up @@ -140,14 +140,13 @@ fn handle_docs(cli: Cli) -> Result<(), Box<dyn Error>> {
)
.show();
std::process::exit(1);
}
};

let output = {
let out = cli.output.clone().unwrap_or_else(|| PathBuf::from("docs"));
String::from(out.to_string_lossy())
};


let valid_code: String = match fs::read_to_string(&valid_input) {
Ok(code) => code,
Err(err) => {
Expand All @@ -165,10 +164,12 @@ fn handle_docs(cli: Cli) -> Result<(), Box<dyn Error>> {
}
}

/*
#[cfg(target_os = "windows")]
fn set_file_permission(_file: &fs::File, _output: String) {
// We don't need to set permission on Windows
}
*/

#[cfg(not(target_os = "windows"))]
fn set_file_permission(file: &std::fs::File, path: String) {
Expand Down
22 changes: 11 additions & 11 deletions src/utils/context.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
use heraclitus_compiler::prelude::*;
use std::collections::{HashMap, HashSet};
use crate::modules::expression::expr::Expr;
use crate::modules::types::Type;
use heraclitus_compiler::prelude::*;
use std::collections::{HashMap, HashSet};

use super::{function_interface::FunctionInterface, cc_flags::CCFlags};
use super::{cc_flags::CCFlags, function_interface::FunctionInterface};

#[derive(Clone, Debug)]
pub struct FunctionDecl {
pub name: String,
pub arg_names: Vec<String>,
pub arg_types: Vec<Type>,
pub arg_refs: Vec<bool>,
pub arg_optionals : Vec<Expr>,
pub arg_optionals: Vec<Expr>,
pub returns: Type,
pub is_args_typed: bool,
pub is_public: bool,
pub is_failable: bool,
pub id: usize
pub id: usize,
}

impl FunctionDecl {
Expand All @@ -30,7 +30,7 @@ impl FunctionDecl {
arg_optionals: self.arg_optionals,
returns: self.returns,
is_public: self.is_public,
is_failable: self.is_failable
is_failable: self.is_failable,
}
}
}
Expand All @@ -40,21 +40,21 @@ pub struct VariableDecl {
pub name: String,
pub kind: Type,
pub global_id: Option<usize>,
pub is_ref: bool
pub is_ref: bool,
}

#[derive(Clone, Debug)]
pub struct ScopeUnit {
pub vars: HashMap<String, VariableDecl>,
pub funs: HashMap<String, FunctionDecl>
pub funs: HashMap<String, FunctionDecl>,
}

/// Perform methods just on the scope
impl ScopeUnit {
pub fn new() -> ScopeUnit {
ScopeUnit {
vars: HashMap::new(),
funs: HashMap::new()
funs: HashMap::new(),
}
}

Expand Down Expand Up @@ -119,7 +119,7 @@ pub struct Context {
/// The return type of the currently parsed function
pub fun_ret_type: Option<Type>,
/// List of compiler flags
pub cc_flags: HashSet<CCFlags>
pub cc_flags: HashSet<CCFlags>,
}

// FIXME: Move the scope related structures to the separate file
Expand All @@ -137,7 +137,7 @@ impl Context {
is_unsafe_ctx: false,
pub_funs: vec![],
fun_ret_type: None,
cc_flags: HashSet::new()
cc_flags: HashSet::new(),
}
}

Expand Down

0 comments on commit 98ecf85

Please sign in to comment.