From 7b5151d1322419872074f6d9d0a3e95dc87d2faf Mon Sep 17 00:00:00 2001 From: Edgar Date: Wed, 24 Jan 2024 10:06:10 -0300 Subject: [PATCH] progress --- .../src/scope_context.rs | 38 ++++++++++++++++++- examples/aabb.con | 20 ++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 examples/aabb.con diff --git a/crates/concrete_codegen_mlir/src/scope_context.rs b/crates/concrete_codegen_mlir/src/scope_context.rs index a016af9..6d077c9 100644 --- a/crates/concrete_codegen_mlir/src/scope_context.rs +++ b/crates/concrete_codegen_mlir/src/scope_context.rs @@ -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, @@ -260,4 +265,35 @@ impl<'ctx, 'parent> ScopeContext<'ctx, 'parent> { TypeSpec::Array { .. } => unreachable!(), } } + + pub fn get_expr_type(&self, exp: &Expression) -> Option { + 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!(), + } + } } diff --git a/examples/aabb.con b/examples/aabb.con new file mode 100644 index 0000000..40762a2 --- /dev/null +++ b/examples/aabb.con @@ -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; + } + } +}