diff --git a/Cargo.lock b/Cargo.lock index 95e70c886..7f88adf63 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -297,21 +297,21 @@ dependencies = [ [[package]] name = "edlang" -version = "0.0.1-alpha.6" +version = "0.0.1-alpha.7" dependencies = [ "edlang_driver", ] [[package]] name = "edlang_ast" -version = "0.0.1-alpha.6" +version = "0.0.1-alpha.7" dependencies = [ "edlang_span", ] [[package]] name = "edlang_check" -version = "0.0.1-alpha.6" +version = "0.0.1-alpha.7" dependencies = [ "ariadne", "edlang_ast", @@ -320,7 +320,7 @@ dependencies = [ [[package]] name = "edlang_codegen_llvm" -version = "0.0.1-alpha.6" +version = "0.0.1-alpha.7" dependencies = [ "edlang_ir", "edlang_parser", @@ -333,7 +333,7 @@ dependencies = [ [[package]] name = "edlang_driver" -version = "0.0.1-alpha.6" +version = "0.0.1-alpha.7" dependencies = [ "ariadne", "clap", @@ -353,7 +353,7 @@ dependencies = [ [[package]] name = "edlang_ir" -version = "0.0.1-alpha.6" +version = "0.0.1-alpha.7" dependencies = [ "edlang_span", "smallvec", @@ -361,7 +361,7 @@ dependencies = [ [[package]] name = "edlang_lowering" -version = "0.0.1-alpha.6" +version = "0.0.1-alpha.7" dependencies = [ "edlang_ast", "edlang_ir", @@ -370,7 +370,7 @@ dependencies = [ [[package]] name = "edlang_parser" -version = "0.0.1-alpha.6" +version = "0.0.1-alpha.7" dependencies = [ "ariadne", "edlang_ast", @@ -383,14 +383,14 @@ dependencies = [ [[package]] name = "edlang_session" -version = "0.0.1-alpha.6" +version = "0.0.1-alpha.7" dependencies = [ "ariadne", ] [[package]] name = "edlang_span" -version = "0.0.1-alpha.6" +version = "0.0.1-alpha.7" [[package]] name = "either" diff --git a/bin/edlang/Cargo.toml b/bin/edlang/Cargo.toml index 91d7056d0..5c1582b0f 100644 --- a/bin/edlang/Cargo.toml +++ b/bin/edlang/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "edlang" -version = "0.0.1-alpha.6" +version = "0.0.1-alpha.7" authors = ["Edgar Luque "] description = "A experimental language using LLVM." edition = "2021" @@ -14,4 +14,4 @@ repository = "https://github.com/edg-l/edlang" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -edlang_driver = { version = "0.0.1-alpha.6", path = "../../lib/edlang_driver" } +edlang_driver = { version = "0.0.1-alpha.7", path = "../../lib/edlang_driver" } diff --git a/lib/edlang_ast/Cargo.toml b/lib/edlang_ast/Cargo.toml index 32923e407..f8e8bc59d 100644 --- a/lib/edlang_ast/Cargo.toml +++ b/lib/edlang_ast/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "edlang_ast" -version = "0.0.1-alpha.6" +version = "0.0.1-alpha.7" authors = ["Edgar Luque "] description = "edlang AST" edition = "2021" @@ -13,4 +13,4 @@ repository = "https://github.com/edg-l/edlang" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -edlang_span = { version = "0.0.1-alpha.6", path = "../edlang_span" } +edlang_span = { version = "0.0.1-alpha.7", path = "../edlang_span" } diff --git a/lib/edlang_check/Cargo.toml b/lib/edlang_check/Cargo.toml index 9566136a1..cf67621cf 100644 --- a/lib/edlang_check/Cargo.toml +++ b/lib/edlang_check/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "edlang_check" -version = "0.0.1-alpha.6" +version = "0.0.1-alpha.7" authors = ["Edgar Luque "] description = "edlang check" edition = "2021" @@ -14,5 +14,5 @@ repository = "https://github.com/edg-l/edlang" [dependencies] ariadne = { version = "0.4.0", features = ["auto-color"] } -edlang_ast = { version = "0.0.1-alpha.6", path = "../edlang_ast" } +edlang_ast = { version = "0.0.1-alpha.7", path = "../edlang_ast" } tracing = { workspace = true } diff --git a/lib/edlang_codegen_llvm/Cargo.toml b/lib/edlang_codegen_llvm/Cargo.toml index 730c96a26..8fbb87710 100644 --- a/lib/edlang_codegen_llvm/Cargo.toml +++ b/lib/edlang_codegen_llvm/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "edlang_codegen_llvm" -version = "0.0.1-alpha.6" +version = "0.0.1-alpha.7" authors = ["Edgar Luque "] description = "edlang LLVM codegen" edition = "2021" @@ -13,10 +13,10 @@ repository = "https://github.com/edg-l/edlang" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -edlang_ir = { version = "0.0.1-alpha.6", path = "../edlang_ir" } -edlang_parser = { version = "0.0.1-alpha.6", path = "../edlang_parser" } -edlang_session = { version = "0.0.1-alpha.6", path = "../edlang_session" } +edlang_ir = { version = "0.0.1-alpha.7", path = "../edlang_ir" } +edlang_parser = { version = "0.0.1-alpha.7", path = "../edlang_parser" } +edlang_session = { version = "0.0.1-alpha.7", path = "../edlang_session" } llvm-sys = "170.0.1" inkwell = { git = "https://github.com/TheDan64/inkwell", rev = "c044e3cd8d92972ca75b374fb6c5a2794f5b53ca", features = ["llvm17-0"] } tracing = { workspace = true } -edlang_span = { version = "0.0.1-alpha.6", path = "../edlang_span" } +edlang_span = { version = "0.0.1-alpha.7", path = "../edlang_span" } diff --git a/lib/edlang_driver/Cargo.toml b/lib/edlang_driver/Cargo.toml index 42faeed1b..d2e0336e8 100644 --- a/lib/edlang_driver/Cargo.toml +++ b/lib/edlang_driver/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "edlang_driver" -version = "0.0.1-alpha.6" +version = "0.0.1-alpha.7" authors = ["Edgar Luque "] description = "edlang compiler driver library" edition = "2021" @@ -16,13 +16,13 @@ repository = "https://github.com/edg-l/edlang" ariadne = { version = "0.4.0", features = ["auto-color"] } clap = { version = "4.4.16", features = ["derive"] } color-eyre = "0.6.2" -edlang_ast = { version = "0.0.1-alpha.6", path = "../edlang_ast" } -edlang_check = { version = "0.0.1-alpha.6", path = "../edlang_check" } -edlang_codegen_llvm = { version = "0.0.1-alpha.6", path = "../edlang_codegen_llvm" } -edlang_ir = { version = "0.0.1-alpha.6", path = "../edlang_ir" } -edlang_lowering = { version = "0.0.1-alpha.6", path = "../edlang_lowering" } -edlang_parser = { version = "0.0.1-alpha.6", path = "../edlang_parser" } -edlang_session = { version = "0.0.1-alpha.6", path = "../edlang_session" } +edlang_ast = { version = "0.0.1-alpha.7", path = "../edlang_ast" } +edlang_check = { version = "0.0.1-alpha.7", path = "../edlang_check" } +edlang_codegen_llvm = { version = "0.0.1-alpha.7", path = "../edlang_codegen_llvm" } +edlang_ir = { version = "0.0.1-alpha.7", path = "../edlang_ir" } +edlang_lowering = { version = "0.0.1-alpha.7", path = "../edlang_lowering" } +edlang_parser = { version = "0.0.1-alpha.7", path = "../edlang_parser" } +edlang_session = { version = "0.0.1-alpha.7", path = "../edlang_session" } tracing = { workspace = true } tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } diff --git a/lib/edlang_driver/tests/programs.rs b/lib/edlang_driver/tests/programs.rs index 4f040ee13..4c16ff348 100644 --- a/lib/edlang_driver/tests/programs.rs +++ b/lib/edlang_driver/tests/programs.rs @@ -8,6 +8,7 @@ mod common; #[test_case(include_str!("programs/basic_ifs.ed"), "basic_ifs", false, 9, &[] ; "basic_ifs")] #[test_case(include_str!("programs/while.ed"), "while", false, 10, &[] ; "r#while")] #[test_case(include_str!("programs/factorial.ed"), "factorial", false, 24, &[] ; "factorial")] +#[test_case(include_str!("programs/refs.ed"), "refs", false, 2, &[] ; "refs")] #[test_case(TEST_ADD, "TEST_ADD", false, 2, &[] ; "TEST_ADD")] #[test_case(TEST_SUB, "TEST_SUB", false, 1, &[] ; "TEST_SUB")] #[test_case(TEST_MUL, "TEST_MUL", false, 4, &[] ; "TEST_MUL")] diff --git a/lib/edlang_driver/tests/programs/refs.ed b/lib/edlang_driver/tests/programs/refs.ed new file mode 100644 index 000000000..b7b376211 --- /dev/null +++ b/lib/edlang_driver/tests/programs/refs.ed @@ -0,0 +1,13 @@ +mod Main { + pub fn main() -> i64 { + let mut a: i64 = 0; + + hello(&mut a); + + return a; + } + + pub fn hello(a: &mut i32) { + *a = 2; + } +} diff --git a/lib/edlang_ir/Cargo.toml b/lib/edlang_ir/Cargo.toml index 59756b3b2..14a8ff1f5 100644 --- a/lib/edlang_ir/Cargo.toml +++ b/lib/edlang_ir/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "edlang_ir" -version = "0.0.1-alpha.6" +version = "0.0.1-alpha.7" authors = ["Edgar Luque "] description = "edlang IR" edition = "2021" @@ -13,5 +13,5 @@ repository = "https://github.com/edg-l/edlang" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -edlang_span = { version = "0.0.1-alpha.6", path = "../edlang_span" } +edlang_span = { version = "0.0.1-alpha.7", path = "../edlang_span" } smallvec = "1.13.1" diff --git a/lib/edlang_lowering/Cargo.toml b/lib/edlang_lowering/Cargo.toml index 35f83f33c..b24b8c7ef 100644 --- a/lib/edlang_lowering/Cargo.toml +++ b/lib/edlang_lowering/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "edlang_lowering" -version = "0.0.1-alpha.6" +version = "0.0.1-alpha.7" authors = ["Edgar Luque "] description = "edlang lowering" edition = "2021" @@ -13,6 +13,6 @@ repository = "https://github.com/edg-l/edlang" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -edlang_ast = { version = "0.0.1-alpha.6", path = "../edlang_ast" } -edlang_ir = { version = "0.0.1-alpha.6", path = "../edlang_ir" } +edlang_ast = { version = "0.0.1-alpha.7", path = "../edlang_ast" } +edlang_ir = { version = "0.0.1-alpha.7", path = "../edlang_ir" } tracing.workspace = true diff --git a/lib/edlang_lowering/src/lib.rs b/lib/edlang_lowering/src/lib.rs index 2e3b242a5..4c083275a 100644 --- a/lib/edlang_lowering/src/lib.rs +++ b/lib/edlang_lowering/src/lib.rs @@ -159,6 +159,15 @@ fn lower_function(ctx: BuildCtx, func: &ast::Function, module_id: DefId) -> Buil lower_statement(&mut builder, stmt, &ret_ty.kind); } + if !builder.statements.is_empty() { + let statements = std::mem::take(&mut builder.statements); + builder.body.blocks.push(BasicBlock { + statements: statements.into(), + terminator: Terminator::Return, + terminator_span: None, + }); + } + let (mut ctx, body) = (builder.ctx, builder.body); ctx.unresolved_function_signatures.remove(&body.def_id); ctx.body.functions.insert(body.def_id, body); diff --git a/lib/edlang_parser/Cargo.toml b/lib/edlang_parser/Cargo.toml index c739da131..f8b5a4f10 100644 --- a/lib/edlang_parser/Cargo.toml +++ b/lib/edlang_parser/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "edlang_parser" -version = "0.0.1-alpha.6" +version = "0.0.1-alpha.7" authors = ["Edgar Luque "] description = "edlang parser" edition = "2021" @@ -14,7 +14,7 @@ repository = "https://github.com/edg-l/edlang" [dependencies] ariadne = { version = "0.4.0", features = ["auto-color"] } -edlang_ast = { version = "0.0.1-alpha.6", path = "../edlang_ast" } +edlang_ast = { version = "0.0.1-alpha.7", path = "../edlang_ast" } itertools = "0.12.0" lalrpop-util = { version = "0.20.0", features = ["lexer"] } logos = "0.14.0" diff --git a/lib/edlang_session/Cargo.toml b/lib/edlang_session/Cargo.toml index b001fa38c..556c36eaf 100644 --- a/lib/edlang_session/Cargo.toml +++ b/lib/edlang_session/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "edlang_session" -version = "0.0.1-alpha.6" +version = "0.0.1-alpha.7" authors = ["Edgar Luque "] description = "edlang session" edition = "2021" diff --git a/lib/edlang_span/Cargo.toml b/lib/edlang_span/Cargo.toml index c98db9576..c2b6167f6 100644 --- a/lib/edlang_span/Cargo.toml +++ b/lib/edlang_span/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "edlang_span" -version = "0.0.1-alpha.6" +version = "0.0.1-alpha.7" authors = ["Edgar Luque "] description = "edlang span" edition = "2021" diff --git a/programs/refs.ed b/programs/refs.ed new file mode 100644 index 000000000..b7b376211 --- /dev/null +++ b/programs/refs.ed @@ -0,0 +1,13 @@ +mod Main { + pub fn main() -> i64 { + let mut a: i64 = 0; + + hello(&mut a); + + return a; + } + + pub fn hello(a: &mut i32) { + *a = 2; + } +}