I have some GADT code that fails at the C compilation stage. It's a variant of:
https://gist.github.com/doublec/a3cc8f3431cabe9a319c8e7ba27e7890
But the Eq constructor of Expr uses the type index instead of being
'int' so equality can be done against booleans and ints. The full code
is:
----------------8<---------------
#include "share/atspre_define.hats"
#include "share/atspre_staload.hats"
datatype Expr(a:t@ype) =
| I(int) of int
| B(bool) of bool
| Add(int) of (Expr int, Expr int)
| Mul(int) of (Expr int, Expr int)
| Eq(bool) of (Expr a, Expr a)
extern fun{a:t@ype} equals(t1:a, t2:a): bool
implement equals<int>(t1,t2) = g0int_eq(t1,t2)
implement equals<bool>(t1,t2) = eq_bool0_bool0(t1,t2)
fun{a:t@ype} eval(x:Expr a): a =
case+ x of
| I i => i
| B b => b
| Add (t1, t2) => eval(t1) + eval(t2)
| Mul (t1, t2) => eval(t1) * eval(t2)
| Eq (t1, t2) => equals(t1, t2)
implement main0() = let
val term1 = Eq(I(5), Add(I(1), I(4)))
val term2 = Mul(I(2), I(4))
val res1 = eval(term1)
val res2 = eval(term2)
in
println!("res1=", res1, " and res2=", res2)
end
----------------8<---------------
This fails to compile at the C stage with:
In file included from arith3_dats.c:15:0:
arith3_dats.c: In function ‘eval_2__2__1’:
arith3_dats.c:1098:24: error: ‘PMVtmpltcstmat’ undeclared (first use
in this function)
ATSINSmove(tmpret2__1,
PMVtmpltcstmat[0](equals<S2EVar(5554)>)(tmp9__1, tmp10__1)) ;
^
ATS2-Postiats-0.3.11//ccomp/runtime/pats_ccomp_instrset.h:276:37:
note: in definition of macro ‘ATSINSmove’
#define ATSINSmove(tmp, val) (tmp = val)
....
Any thoughts on what I'm doing wrong?
--
https://bluishcoder.co.nz