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

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

Open
wizzard0 opened this issue Mar 30, 2017 · 6 comments

Comments

@wizzard0
Copy link

wizzard0 commented Mar 30, 2017

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
}
@leissa
Copy link
Member

leissa commented Mar 31, 2017

There seems to sth missing. Where is subber?

@wizzard0
Copy link
Author

My bad, fixed the example.

@leissa
Copy link
Member

leissa commented Mar 31, 2017

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

@wizzard0
Copy link
Author

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

@leissa
Copy link
Member

leissa commented Mar 31, 2017

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.

@wizzard0
Copy link
Author

wizzard0 commented Apr 1, 2017

Updated with main function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants