AnyDSL/impala

assertion failed trying to specialize function that invokes closure passed as a struct field

wizzard0 opened this issue · 6 comments

Note the @ in call to fac; removing it makes the code compile fine

impala: /home/user/anydsl/thorin/src/thorin/be/llvm/llvm.cpp:988: llvm::Type* thorin::CodeGen::convert(const thorin::Type*): Assertion `ret' failed.
Aborted (core dumped)
type char = u8;
type str = [char];


extern "C" {
    fn atoi(&str) -> int;
    fn print_int(int) -> ();
}


fn subber(a: int, b: int) -> int {
	a - b
}

fn invocator(a:fn(int) -> int, b: int) -> int {
	a(b)
}

fn fac_rec(n : int, d:explicit_delegate)->int {
    if (n <= 0) {
        1
    } else {
        n * fac_rec(d.callable(n), d)
    }
}

struct explicit_delegate {
    callable: fn(int) -> int
}

fn fac_nrec(n : int, delta: int) -> int {
    let subber1 = |x: int| subber(x, delta);
    let ci = explicit_delegate{
        callable : subber1
    };
    @fac_rec(n, ci)
}

fn main(argc: int, argv: &[&str]) -> int {
    let n = if argc >= 2 { atoi(argv(1)) } else { 1 };
    let res = fac_nrec(10, n);
    print_int(res);
    res
}

There seems to sth missing. Where is subber?

My bad, fixed the example.

There is still a main missing. Anyway, can you try on master? The eurollvm branch is not considered stable.

Um... but then it hangs (diverges?) exactly like #58 :)

Can you please add a main function?
Then, I can have a look, whether this is supposed to work when the new eurollvm branch is merged or whether this is a duplicate of AnyDSL/thorin#3.

Updated with main function.