Skip to content

Commit

Permalink
refactor(resolve): rename inference crate to resolve.
Browse files Browse the repository at this point in the history
  • Loading branch information
rzvxa committed Mar 13, 2024
1 parent 2e8d2f2 commit 4a469fa
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fuse_codegen = { version = "0.0.0", path = "crates/fuse-codegen" }
fuse_common = { version = "0.0.0", path = "crates/fuse-common" }
fuse_common_proc = { version = "0.0.0", path = "crates/fuse-common-proc" }
fuse_parser = { version = "0.0.0", path = "crates/fuse-parser" }
fuse_inference = { version = "0.0.0", path = "crates/fuse-inference" }
fuse_resolve = { version = "0.0.0", path = "crates/fuse-resolve" }
fuse_visitor = { version = "0.0.0", path = "crates/fuse-visitor" }
fusec = { version = "0.0.0", path = "crates/fusec" }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "fuse_inference"
name = "fuse_resolve"
version = "0.0.0"
description.workspace = true
authors.workspace = true
Expand Down
42 changes: 24 additions & 18 deletions crates/fuse-inference/src/lib.rs → crates/fuse-resolve/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::collections::HashMap;

use fuse_ast::{
Atom, BinaryOperator, BinaryOperatorKind, BindingPatternKind, CallExpression, Chunk, Function,
Identifier, VariableDeclaration,
Atom, BinaryOperator, BinaryOperatorKind, BindingPatternKind, CallExpression, Chunk,
Expression, Function, Identifier, VariableDeclaration,
};
use fuse_common::ReferenceType;
use fuse_visitor::{
Expand Down Expand Up @@ -31,21 +31,19 @@ impl PartialEq<ReferenceType> for ScopeId {
}
}

struct IdentifierMap {
map: HashMap<Atom, ReferenceType>,
}
struct IdentifierMap(HashMap<Atom, ReferenceType>);

impl IdentifierMap {
fn new() -> Self {
Self{ map: HashMap::new() }
Self(HashMap::new())
}

fn insert(&mut self, atom: Atom, ref_id: ReferenceType) -> Option<ReferenceType> {
self.map.insert(atom, ref_id)
self.0.insert(atom, ref_id)
}

fn get(&self, atom: &Atom) -> Option<ReferenceType> {
self.map.get(atom).map(|r| r.clone())
self.0.get(atom).map(|r| r.clone())
}
}

Expand Down Expand Up @@ -128,13 +126,13 @@ impl ScopeTree {
}
}

pub struct Inference<'ast> {
pub struct Resolver<'ast> {
source: &'ast str,
scope: ScopeTree,
last_reference: ReferenceType,
}

impl<'ast> Inference<'ast> {
impl<'ast> Resolver<'ast> {
pub fn new(source: &'ast str) -> Self {
Self {
source,
Expand All @@ -143,9 +141,9 @@ impl<'ast> Inference<'ast> {
}
}

pub fn resolve(&mut self, chunk: &'ast mut Chunk) -> InferenceResult {
pub fn resolve(&mut self, chunk: &'ast mut Chunk) -> ResolverResult {
self.visit_chunk_mut(chunk);
InferenceResult {
ResolverResult {
errors: Vec::default(),
}
}
Expand All @@ -163,7 +161,7 @@ impl<'ast> Inference<'ast> {
}
}

impl<'ast> VisitorMut<'ast> for Inference<'ast> {
impl<'ast> VisitorMut<'ast> for Resolver<'ast> {
fn visit_identifier_mut(&mut self, ident: &'ast mut Identifier) {
if ident.reference.get_mut().is_none() {
self.reference_identifier(ident);
Expand Down Expand Up @@ -191,14 +189,22 @@ impl<'ast> VisitorMut<'ast> for Inference<'ast> {

fn visit_binary_operator_mut(&mut self, op: &'ast mut BinaryOperator) {
match &op.kind {
BinaryOperatorKind::Member(_) => {}
BinaryOperatorKind::Member(_) => {
println!("{:?}", op);
// let rhs = match &op.rhs {
// Expression::Identifier(rhs) => rhs,
// Expression::BinaryOperator(op) => match op {
// },
// _ => panic!("Right hand side of a member(.) operator should be an identifier"),
// };
}
_ => {}
}
walk_binary_operator_mut(self, op)
}
}

impl<'ast> ScopeVisitor for Inference<'ast> {
impl<'ast> ScopeVisitor for Resolver<'ast> {
fn enter_scope(&mut self) {
self.scope.push_stack();
}
Expand All @@ -208,8 +214,8 @@ impl<'ast> ScopeVisitor for Inference<'ast> {
}
}

pub struct InferenceResult {
pub errors: Vec<InferenceError>,
pub struct ResolverResult {
pub errors: Vec<ResolverError>,
}

pub struct InferenceError {}
pub struct ResolverError {}
2 changes: 1 addition & 1 deletion crates/fusec/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ edition.workspace = true

[dependencies]
fuse_parser = { workspace = true }
fuse_inference = { workspace = true }
fuse_resolve = { workspace = true }
5 changes: 3 additions & 2 deletions crates/fusec/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use fuse_parser::Parser;
use fuse_inference::Inference;
use fuse_resolve::Resolver;

fn compile_chunk(source: &str) {
let parsed = Parser::new(source).parse();
assert!(!parsed.paniced);
assert!(parsed.errors.len() == 0);
let mut chunk = parsed.chunk.unwrap();
let inference = Inference::new(source).resolve(&mut chunk);
let resolution = Resolver::new(source).resolve(&mut chunk);
// panic!("{:#?}", chunk)
}

Expand All @@ -15,6 +15,7 @@ fn manual_test() {
compile_chunk(
r#"
let a = 0
let c = 1
let d = a.b.c
"#,
)
Expand Down

0 comments on commit 4a469fa

Please sign in to comment.