-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Robert-M-Lucas
committed
Jun 4, 2024
1 parent
ad71b6d
commit 1c03e3e
Showing
12 changed files
with
166 additions
and
50 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
|
||
fn main() -> int { | ||
return 12; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use std::fmt::{Display, Formatter}; | ||
use color_print::cformat; | ||
use crate::root::parser::parse::Location; | ||
|
||
pub mod parser_errors; | ||
pub mod name_resolver_errors; | ||
|
||
pub struct WError { | ||
error: String, | ||
location: Option<Location> // ! Important, don't do file reads unless necessary (i.e. Display) | ||
} | ||
|
||
impl WError { | ||
pub fn n(error: impl Display, location: Location) -> WError { | ||
WError { | ||
error: format!("{error}"), | ||
location: Some(location) | ||
} | ||
} | ||
|
||
pub fn locationless(error: impl Display) -> WError { | ||
WError { | ||
error: format!("{error}"), | ||
location: None | ||
} | ||
} | ||
} | ||
|
||
impl Display for WError { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { | ||
let text = if let Some(location) = &self.location { | ||
cformat!("<r,bold>Error:</>\n {}\n<c,bold>At:</>\n{}", self.error, location) | ||
} | ||
else { | ||
cformat!("<r,bold>Error:</>\n {}", self.error) | ||
}; | ||
f.write_str(&text) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use thiserror::Error; | ||
|
||
#[derive(Error, Debug)] | ||
pub enum NRErrors { | ||
#[error("No top-level main function found")] | ||
NoMain, | ||
#[error("Cannot create 'impl' for an indirect type")] | ||
IndirectImpl | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
use thiserror::Error; | ||
|
||
#[derive(Error, Debug)] | ||
pub enum ParseError { | ||
// #[error("Names cannot contain character '{0}' (UTF-8 Code: {1:?})")] | ||
// BadName(char, Vec<u8>), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,21 @@ | ||
use std::collections::HashMap; | ||
use crate::root::builtin::register_builtin; | ||
use crate::root::errors::name_resolver_errors::NRErrors; | ||
use crate::root::errors::WError; | ||
use crate::root::name_resolver::name_resolvers::GlobalDefinitionTable; | ||
use crate::root::name_resolver::resolve_names::resolve_names; | ||
use crate::root::parser::parse_function::FunctionToken; | ||
use crate::root::parser::parse_toplevel::TopLevelTokens; | ||
use crate::root::shared::common::FunctionID; | ||
|
||
pub fn resolve(ast: Vec<TopLevelTokens>) -> (GlobalDefinitionTable, HashMap<FunctionID, FunctionToken>) { | ||
pub fn resolve(ast: Vec<TopLevelTokens>) -> Result<(GlobalDefinitionTable, HashMap<FunctionID, FunctionToken>), WError> { | ||
let mut global_table = GlobalDefinitionTable::new(); | ||
register_builtin(&mut global_table); | ||
let unprocessed_functions = resolve_names(ast, &mut global_table); | ||
let unprocessed_functions = resolve_names(ast, &mut global_table)?; | ||
|
||
if !global_table.function_signatures().contains_key(&FunctionID(0)) { | ||
// NO MAIN! | ||
todo!() | ||
return Err(WError::locationless(NRErrors::NoMain)) | ||
} | ||
|
||
(global_table, unprocessed_functions) | ||
Ok((global_table, unprocessed_functions)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters