This commit is contained in:
Edgar 2024-02-16 11:48:15 +01:00
parent 64a4665dfd
commit 4dabaf070b
No known key found for this signature in database
GPG key ID: 70ADAE8F35904387
4 changed files with 42 additions and 10 deletions

View file

@ -218,11 +218,45 @@ fn compile_fn_signature(ctx: &ModuleCompileCtx<'_, '_>, fn_id: DefId) {
}), }),
); );
// https://llvm.org/doxygen/group__LLVMCCoreTypes.html
/* starting from 1 to 80
allocalign allocptr alwaysinline builtin cold convergent disable_sanitizer_instrumentation fn_ret_thunk_extern hot
immarg inreg inlinehint jumptable minsize mustprogress naked nest noalias
nobuiltin nocallback nocapture nocf_check noduplicate nofree noimplicitfloat
noinline nomerge noprofile norecurse noredzone noreturn nosanitize_bounds
nosanitize_coverage nosync noundef nounwind nonlazybind nonnull null_pointer_is_valid
optforfuzzing optsize optnone presplitcoroutine readnone readonly returned returns_twice
signext safestack sanitize_address sanitize_hwaddress sanitize_memtag sanitize_memory
sanitize_thread shadowcallstack skipprofile speculatable speculative_load_hardening ssp
sspreq sspstrong strictfp swiftasync swifterror swiftself willreturn writeonly (67) zeroext byref byval elementtype inalloca
preallocated sret align 0 allockind(\"\") allocsize(0,0) dereferenceable(0) dereferenceable_or_null(0
*/
// nounwind
fn_value.add_attribute(
inkwell::attributes::AttributeLoc::Function,
ctx.ctx.context.create_enum_attribute(36, 0),
);
// nonlazybind // nonlazybind
fn_value.add_attribute( fn_value.add_attribute(
inkwell::attributes::AttributeLoc::Function, inkwell::attributes::AttributeLoc::Function,
ctx.ctx.context.create_enum_attribute(37, 0), ctx.ctx.context.create_enum_attribute(37, 0),
); );
// willreturn
fn_value.add_attribute(
inkwell::attributes::AttributeLoc::Function,
ctx.ctx.context.create_enum_attribute(66, 0),
);
if body.name == "main" {
fn_value.set_call_conventions(0);
} else {
fn_value.set_call_conventions(1);
}
let (_, line, _col) = ctx let (_, line, _col) = ctx
.ctx .ctx
.session .session

View file

@ -2,7 +2,7 @@ use std::{
borrow::Cow, borrow::Cow,
fmt, fmt,
path::{Path, PathBuf}, path::{Path, PathBuf},
process::Output, process::Child,
}; };
use ariadne::Source; use ariadne::Source;
@ -80,9 +80,6 @@ pub fn compile_program(
}) })
} }
pub fn run_program(program: &Path, args: &[&str]) -> Result<Output, std::io::Error> { pub fn run_program(program: &Path, args: &[&str]) -> Result<Child, std::io::Error> {
std::process::Command::new(program) std::process::Command::new(dbg!(program)).args(args).spawn()
.args(args)
.spawn()?
.wait_with_output()
} }

View file

@ -18,13 +18,14 @@ mod common;
#[test_case(TEST_IF_NO_ELSE, "TEST_IF_NO_ELSE", false, 1, &[] ; "TEST_IF_NO_ELSE")] #[test_case(TEST_IF_NO_ELSE, "TEST_IF_NO_ELSE", false, 1, &[] ; "TEST_IF_NO_ELSE")]
#[test_case(TEST_IF_NO_ELSE, "TEST_IF_NO_ELSE", false, 2, &["a"] ; "TEST_IF_NO_ELSE args")] #[test_case(TEST_IF_NO_ELSE, "TEST_IF_NO_ELSE", false, 2, &["a"] ; "TEST_IF_NO_ELSE args")]
fn example_tests(source: &str, name: &str, is_library: bool, status_code: i32, args: &[&str]) { fn example_tests(source: &str, name: &str, is_library: bool, status_code: i32, args: &[&str]) {
dbg!(source);
let program = compile_program(source, name, is_library).unwrap(); let program = compile_program(source, name, is_library).unwrap();
assert!(program.binary_file.exists(), "program not compiled"); assert!(program.binary_file.exists(), "program not compiled");
let mut result = run_program(&program.binary_file, args).unwrap();
let result = run_program(&program.binary_file, args).unwrap(); let status = result.wait().unwrap();
assert_eq!( assert_eq!(
result.status.code().unwrap(), status.code().unwrap(),
status_code, status_code,
"Program {} returned a unexpected status code", "Program {} returned a unexpected status code",
name name

View file

@ -5,7 +5,7 @@ mod Main {
} }
fn factorial(n: i32) -> i32 { fn factorial(n: i32) -> i32 {
if n == 0 { if n == 1 {
return n; return n;
} else { } else {
return n * factorial(n - 1); return n * factorial(n - 1);