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

Polymorphic function fails to compile in C #215

Open
jrfondren opened this issue Sep 14, 2018 · 1 comment
Open

Polymorphic function fails to compile in C #215

jrfondren opened this issue Sep 14, 2018 · 1 comment

Comments

@jrfondren
Copy link

jrfondren commented Sep 14, 2018

This foldl with some usage:

#include "share/atspre_staload.hats"

fun foldl{a,b:t@ype}(f: (a, b) -> a, acc: a, list: List(b)): a =
        case+ list of
        | list_nil() => acc
        | list_cons(x, xs) => foldl(f, f(acc, x), xs)

implement main0() =
        let
                val list = $list{int}(1, 2, 3, 4, 5)
                //val sum = foldl(lam (acc, n) => acc + n, 0, list)
                val sum = foldl(f, 0, list): int where {
                        fun f(a: int, b: int): int = a + b
                }
        in
                println!("sum1: ", sum);
        end

Fails to compile with these errors:

patscc -DATS_MEMALLOC_GCBDW -o foldlgc foldlgc.dats -latslib -lgc
foldlgc_dats.c:317:1: error: ‘foldl_0’ declared as function returning an array
 foldl_0(atstype_funptr, atstyvar_type(a), atstype_boxed) ;
 ^~~~~~~
foldlgc_dats.c:340:1: error: ‘foldl_0’ declared as function returning an array
 foldl_0(atstype_funptr arg0, atstyvar_type(a) arg1, atstype_boxed arg2)
 ^~~~~~~
In file included from foldlgc_dats.c:15:0:
foldlgc_dats.c: In function ‘foldl_0’:
/home/fondren/sea/ats/ATS2/ccomp/runtime/pats_ccomp_instrset.h:276:35: error: assignment to expression with array type
 #define ATSINSmove(tmp, val) (tmp = val)
                                   ^
foldlgc_dats.c:385:1: note: in expansion of macro ‘ATSINSmove’
 ATSINSmove(tmpret0, arg1) ;
 ^~~~~~~~~~
/home/fondren/sea/ats/ATS2/ccomp/runtime/pats_ccomp_instrset.h:276:35: error: assignment to expression with array type
 #define ATSINSmove(tmp, val) (tmp = val)
                                   ^
foldlgc_dats.c:406:1: note: in expansion of macro ‘ATSINSmove’
 ATSINSmove(tmp1, ATSSELcon(arg2, postiats_tysum_0, atslab__0)) ;
 ^~~~~~~~~~
foldlgc_dats.c:420:1: error: type name declared as function returning an array
 ATSINSmove(tmp3, ATSfunclo_fun(arg0, (atstyvar_type(a), atstyvar_type(b)), atstyvar_type(a))(arg1, tmp1)) ;
 ^~~~~~~~~~
In file included from foldlgc_dats.c:15:0:
/home/fondren/sea/ats/ATS2/ccomp/runtime/pats_ccomp_instrset.h:276:35: error: assignment to expression with array type
 #define ATSINSmove(tmp, val) (tmp = val)
                                   ^
foldlgc_dats.c:420:1: note: in expansion of macro ‘ATSINSmove’
 ATSINSmove(tmp3, ATSfunclo_fun(arg0, (atstyvar_type(a), atstyvar_type(b)), atstyvar_type(a))(arg1, tmp1)) ;
 ^~~~~~~~~~
/home/fondren/sea/ats/ATS2/ccomp/runtime/pats_ccomp_instrset.h:320:41: error: assignment to expression with array type
 #define ATSINSmove_tlcal(apy, tmp) (apy = tmp)
                                         ^
foldlgc_dats.c:427:1: note: in expansion of macro ‘ATSINSmove_tlcal’
 ATSINSmove_tlcal(apy1, tmp3) ;
 ^~~~~~~~~~~~~~~~
/home/fondren/sea/ats/ATS2/ccomp/runtime/pats_ccomp_instrset.h:97:28: warning: return makes integer from pointer without a cast [-Wint-conversion]
 #define ATSreturn(x) return(x)
                            ^
foldlgc_dats.c:443:1: note: in expansion of macro ‘ATSreturn’
 ATSreturn(tmpret0) ;
 ^~~~~~~~~
/home/fondren/sea/ats/ATS2/ccomp/runtime/pats_ccomp_instrset.h:97:28: warning: function returns address of local variable [-Wreturn-local-addr]
 #define ATSreturn(x) return(x)
                            ^
foldlgc_dats.c:443:1: note: in expansion of macro ‘ATSreturn’
 ATSreturn(tmpret0) ;
 ^~~~~~~~~
Makefile:13: recipe for target 'foldlgc' failed
make: *** [foldlgc] Error 1
@githwxi
Copy link
Owner

githwxi commented Sep 14, 2018

The following poly function cannot be compiled into C code
because a and b are of unknown size:

fun foldl{a,b:t@ype}(f: (a, b) -> a, acc: a, list: List(b)): a = ...

It needs to be written as a function template:

fun{a,b:t@ype}  foldl(f: (a, b) -> a, acc: a, list: List(b)): a = ...

Or 't@ype' needs to be changed to 'type', which is for boxed types.

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