Skip to content

Commit

Permalink
Resolved types (#29)
Browse files Browse the repository at this point in the history
* begin swappnig over to resolved types

* progress in refactore

* progress on converting types

* progress in switching to resolved types

* progress in switching to resolved types

* finalize refactor to resolved types

* remove unused type variants

* fix tests
  • Loading branch information
sezna authored Apr 12, 2021
1 parent 84f58f0 commit f3efd9d
Show file tree
Hide file tree
Showing 16 changed files with 557 additions and 331 deletions.
2 changes: 1 addition & 1 deletion parser/src/control_flow_analysis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//!
//! The graph construction algorithm is as follows:
//!
//! ```
//! ```ignore
//! For every node in the syntax tree:
//! if it is non-branching:
//! push it onto all current not-yet-terminated tree leaves, thus adding it to the end of every path
Expand Down
12 changes: 5 additions & 7 deletions parser/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::parser::Rule;
use crate::types::TypeInfo;
use crate::{parser::Rule, types::ResolvedType};
use inflector::cases::classcase::to_class_case;
use inflector::cases::snakecase::to_snake_case;
use pest::Span;
Expand Down Expand Up @@ -116,10 +116,8 @@ impl<'sc, T> CompileResult<'sc, T> {
pub fn ok(&self) -> Option<&T> {
match self {
CompileResult::Ok { value, .. } => Some(value),
_ => None

_ => None,
}

}
}

Expand Down Expand Up @@ -160,11 +158,11 @@ pub enum Warning<'sc> {
name: &'sc str,
},
LossOfPrecision {
initial_type: TypeInfo<'sc>,
cast_to: TypeInfo<'sc>,
initial_type: ResolvedType<'sc>,
cast_to: ResolvedType<'sc>,
},
UnusedReturnValue {
r#type: TypeInfo<'sc>,
r#type: ResolvedType<'sc>,
},
SimilarMethodFound {
lib: String,
Expand Down
3 changes: 2 additions & 1 deletion parser/src/hll.pest
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ func_app = { fn_name ~ "(" ~ (expr ~ ("," ~ expr)* )? ~ ")" }
fn_name = {var_exp}
var_exp = { unary_op? ~ var_name_ident }
method_exp = { subfield_exp ~ "(" ~ (expr ~ ("," ~ expr)* )? ~ ")" }
subfield_exp = { (ident ~ ".")+ ~ ident }
subfield_exp = { (call_item ~ ".")+ ~ call_item }
call_item = { ident }
delineated_path = { path_component ~ ( "(" ~ expr ~ ")" )? }
path_component = { path_ident ~ (path_separator ~ path_ident )+ }
path_ident = { ident }
Expand Down
5 changes: 4 additions & 1 deletion parser/src/parse_tree/call_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl<'sc> CallPath<'sc> {
let mut warnings = vec![];
let mut errors = vec![];
let mut pairs_buf = vec![];
for pair in pair.into_inner() {
for pair in pair.clone().into_inner() {
if pair.as_rule() != Rule::path_separator {
pairs_buf.push(eval!(
Ident::parse_from_pair,
Expand All @@ -46,6 +46,9 @@ impl<'sc> CallPath<'sc> {
));
}
}
if pairs_buf.len() == 0 {
dbg!(&pair);
}
assert!(pairs_buf.len() > 0);
let suffix = pairs_buf.pop().unwrap();
let prefixes = pairs_buf;
Expand Down
8 changes: 4 additions & 4 deletions parser/src/parse_tree/expression/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub(crate) enum Expression<'sc> {
span: Span<'sc>,
},
/// A subfield expression is anything of the form:
/// ```
/// ```ignore
/// <ident>.<ident>
/// ```
///
Expand All @@ -84,19 +84,19 @@ pub(crate) enum Expression<'sc> {
unary_op: Option<UnaryOp>,
},
/// A [DelineatedPath] is anything of the form:
/// ```
/// ```ignore
/// <ident>::<ident>
/// ```
/// Where there are `n >= 2` idents.
/// These could be either enum variant constructions, or they could be
/// references to some sort of module in the module tree.
/// For example, a reference to a module:
/// ```
/// ```ignore
/// std::ops::add
/// ```
///
/// And, an enum declaration:
/// ```
/// ```ignore
/// enum MyEnum {
/// Variant1,
/// Variant2
Expand Down
8 changes: 4 additions & 4 deletions parser/src/semantics/ast_node/code_block.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::*;
use crate::types::TypeInfo;
use crate::types::{ResolvedType, TypeInfo};
use crate::CodeBlock;

#[derive(Clone, Debug)]
Expand All @@ -12,9 +12,9 @@ impl<'sc> TypedCodeBlock<'sc> {
other: CodeBlock<'sc>,
namespace: &Namespace<'sc>,
// this is for the return or implicit return
type_annotation: Option<TypeInfo<'sc>>,
type_annotation: Option<ResolvedType<'sc>>,
help_text: impl Into<String> + Clone,
) -> CompileResult<'sc, (Self, TypeInfo<'sc>)> {
) -> CompileResult<'sc, (Self, ResolvedType<'sc>)> {
let mut warnings = Vec::new();
let mut errors = Vec::new();
let mut evaluated_contents = Vec::new();
Expand Down Expand Up @@ -70,7 +70,7 @@ impl<'sc> TypedCodeBlock<'sc> {
} => Some(return_type.clone()),
_ => None,
})
.unwrap_or(TypeInfo::Unit);
.unwrap_or(ResolvedType::Unit);
if let Some(type_annotation) = type_annotation {
let convertability = return_type.is_convertable(
&type_annotation,
Expand Down
Loading

0 comments on commit f3efd9d

Please sign in to comment.