Skip to content

Commit

Permalink
Merge pull request #81 from lambdaclass/references
Browse files Browse the repository at this point in the history
[Codegen / Parsing] Add basic codegen for references, add parsing for arrays
  • Loading branch information
igaray authored Jan 23, 2024
2 parents 4d5f4a8 + a7bc019 commit 35506b6
Show file tree
Hide file tree
Showing 10 changed files with 278 additions and 98 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 11 additions & 6 deletions crates/concrete_ast/src/expressions.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
use crate::{common::Ident, statements::Statement, types::TypeSpec};
use crate::{
common::Ident,
statements::Statement,
types::{RefType, TypeSpec},
};

#[derive(Clone, Debug, Eq, PartialEq)]
pub enum Expression {
Simple(SimpleExpr),
Value(ValueExpr),
FnCall(FnCallOp),
Match(MatchExpr),
If(IfExpr),
UnaryOp(UnaryOp, Box<Self>),
BinaryOp(Box<Self>, BinaryOp, Box<Self>),
}

// needed for match variants and array accesses
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum SimpleExpr {
pub enum ValueExpr {
ConstBool(bool),
ConstChar(char),
ConstInt(u64),
ConstFloat(()),
ConstStr(String),
Path(PathOp),
Deref(PathOp),
AsRef { path: PathOp, ref_type: RefType },
}

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
Expand Down Expand Up @@ -83,14 +88,14 @@ pub struct IfExpr {

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct MatchVariant {
pub case: SimpleExpr,
pub case: ValueExpr,
pub block: Vec<Statement>,
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub enum PathSegment {
FieldAccess(Ident),
ArrayIndex(SimpleExpr),
ArrayIndex(ValueExpr),
}

#[derive(Clone, Debug, Eq, PartialEq)]
Expand Down
25 changes: 25 additions & 0 deletions crates/concrete_ast/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,40 @@
use crate::common::{DocString, Ident, Span};

#[derive(Clone, Debug, Eq, Hash, PartialEq, Copy)]
pub enum RefType {
Borrow,
MutBorrow,
}

#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub enum TypeSpec {
Simple {
name: Ident,
is_ref: Option<RefType>,
span: Span,
},
Generic {
name: Ident,
is_ref: Option<RefType>,
type_params: Vec<TypeSpec>,
span: Span,
},
Array {
of_type: Box<Self>,
size: Option<u64>,
is_ref: Option<RefType>,
span: Span,
},
}

impl TypeSpec {
pub fn is_ref(&self) -> Option<RefType> {
match self {
TypeSpec::Simple { is_ref, .. } => *is_ref,
TypeSpec::Generic { is_ref, .. } => *is_ref,
TypeSpec::Array { is_ref, .. } => *is_ref,
}
}
}

#[derive(Clone, Debug, Eq, Hash, PartialEq)]
Expand Down
2 changes: 1 addition & 1 deletion crates/concrete_codegen_mlir/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ concrete_ast = { path = "../concrete_ast"}
concrete_session = { path = "../concrete_session"}
itertools = "0.12.0"
llvm-sys = "170.0.1"
melior = { version = "0.15.0", features = ["ods-dialects"] }
melior = { version = "0.15.2", features = ["ods-dialects"] }
mlir-sys = "0.2.1"
tracing.workspace = true

Expand Down
Loading

0 comments on commit 35506b6

Please sign in to comment.