Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to call methods without a let statement. #161

Merged
merged 24 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ build/

*.so
*.a
*.mlir
*.ast
*.ll
*.ir
159 changes: 17 additions & 142 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ ariadne = { version = "0.5.0", features = ["auto-color"] }
unescaper = "0.1.5"
logos-display = "0.1.3"

melior = { version = "0.20.2", features = ["ods-dialects", "helpers"] }
melior = { version = "0.21.0", features = ["ods-dialects", "helpers"] }
llvm-sys = "191.0.0"
mlir-sys = "0.4.1"
anyhow = "1.0.95"
Expand Down
21 changes: 21 additions & 0 deletions examples/impl_block.con
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
mod ImplBlock {
struct A {
a: i64,
b: i64,
}

impl A {
pub fn hello(&self, other: i64) -> i64 {
return self.a * other;
}
}

pub fn main() -> i64 {
let x: A = A {
a: 2,
b: 3,
};

return x.hello(4);
}
}
28 changes: 28 additions & 0 deletions examples/impl_block_mut.con
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
mod ImplBlockMut {
struct A {
a: i32,
b: i32,
}

impl A {
pub fn hello(&self, other: i32) -> i32 {
return self.a * other;
}

pub fn set_a(&mut self, value: i32) {
self.a = value;
return;
}
}

pub fn main() -> i32 {
let mut x: A = A {
a: 2,
b: 3,
};

x.set_a(4);

return x.a;
}
}
2 changes: 1 addition & 1 deletion src/ast/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub struct Ident {
}

/// A type name, supporting fully qualified paths and generics:
/// ```
/// ```text
/// std::module::X<T>
/// ```
/// Used only when specifying types.
Expand Down
2 changes: 1 addition & 1 deletion src/ast/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub struct Param {

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ImplBlock {
pub target: Ident,
pub target: TypeDescriptor,
pub methods: Vec<FunctionDef>,
pub span: Span,
}
2 changes: 2 additions & 0 deletions src/ast/statements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ pub enum Statement {
Return(ReturnStmt),
While(WhileStmt),
FnCall(FnCallOp),
// To allow method calls.
PathOp(PathOp),
}

#[derive(Clone, Debug, Eq, PartialEq)]
Expand Down
Loading
Loading