Skip to content

Commit

Permalink
progress
Browse files Browse the repository at this point in the history
  • Loading branch information
edg-l committed Jan 24, 2024
1 parent e94e2ee commit 7b5151d
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
38 changes: 37 additions & 1 deletion crates/concrete_codegen_mlir/src/scope_context.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
use std::{collections::HashMap, error::Error};

use concrete_ast::{functions::FunctionDef, structs::StructDecl, types::TypeSpec};
use concrete_ast::{
expressions::{Expression, PathSegment, ValueExpr},
functions::FunctionDef,
structs::StructDecl,
types::TypeSpec,
};
use concrete_check::ast_helper::ModuleInfo;
use melior::{
dialect::llvm,
Expand Down Expand Up @@ -260,4 +265,35 @@ impl<'ctx, 'parent> ScopeContext<'ctx, 'parent> {
TypeSpec::Array { .. } => unreachable!(),
}
}

pub fn get_expr_type(&self, exp: &Expression) -> Option<TypeSpec> {
match exp {
Expression::Value(value) => match value {
ValueExpr::Path(path) => {
let first = self.locals.get(&path.first.name)?;

if path.extra.is_empty() {
Some(first.type_spec.clone())
} else {
let mut current = &first.type_spec;
for extra in &path.extra {
match extra {
PathSegment::FieldAccess(ident) => {
let st = self.module_info.structs.get(&ident.name)?;
let field = st.fields.get(ident.name);
}
PathSegment::ArrayIndex(_) => todo!(),
}
}
}
}
_ => None,
},
Expression::FnCall(_) => todo!(),
Expression::Match(_) => todo!(),
Expression::If(_) => todo!(),
Expression::UnaryOp(_, _) => todo!(),
Expression::BinaryOp(_, _, _) => todo!(),
}
}
}
20 changes: 20 additions & 0 deletions examples/aabb.con
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
mod RectCheck {
struct Point2D {
x: i64,
y: i64,
}

struct Rect2D {
pos: Point2D,
size: Point2D,
}

pub fn is_point_inbounds(rect: &Rect2D, point: &Point2D) -> bool {
if point.x >= rect.pos.x && point.x <= (rect.pos.x + rect.size.x)
&& point.y >= rect.pos.y && point.y <= (rect.pos.y + rect.size.y) {
return true;
} else {
return false;
}
}
}

0 comments on commit 7b5151d

Please sign in to comment.