Пример #1
0
void test2()
{
  VC vc = vc_createValidityChecker(NULL);

  // Check x = y -> g(x,y) = g(y,x)

  Type r = vc_realType(vc);

  Expr x = vc_varExpr(vc, "x", r);
  Expr y = vc_varExpr(vc, "y", r);

  Type realxreal2real = vc_funType2(vc, r, r, r);
  Op g = vc_createOp(vc, "g", realxreal2real);

  Expr gxy = vc_funExpr2(vc, g, x, y);
  Expr gyx = vc_funExpr2(vc, g, y, x);

  Expr xeqy = vc_eqExpr(vc, x, y);
  Expr gxyeqgyx = vc_eqExpr(vc, gxy, gyx);

  Expr e = vc_impliesExpr(vc, xeqy, gxyeqgyx);
  Type v[2];
  Op h;
  Expr hxy, hyx, hxyeqhyx;
  int res;

  res = check(vc, e);
  FatalAssert(res == 1, "Expected Valid");

  vc_deleteType(realxreal2real);
  vc_deleteOp(g);
  vc_deleteExpr(gxy);
  vc_deleteExpr(gyx);
  vc_deleteExpr(gxyeqgyx);
  vc_deleteExpr(e);

  v[0] = r;
  v[1] = r;

  realxreal2real = vc_funTypeN(vc, v, r, 2);
  h = vc_createOp(vc, "h", realxreal2real);

  hxy = vc_funExpr2(vc, h, x, y);
  hyx = vc_funExpr2(vc, h, y, x);
  hxyeqhyx = vc_eqExpr(vc, hxy, hyx);

  e = vc_impliesExpr(vc, xeqy, hxyeqhyx);
  res = check(vc, e);
  FatalAssert(res == 1, "Expected Valid");

  vc_deleteType(r);
  vc_deleteExpr(x);
  vc_deleteExpr(y);
  vc_deleteType(realxreal2real);
  vc_deleteExpr(hxy);
  vc_deleteExpr(hxyeqhyx);
  vc_deleteExpr(e);

  vc_destroyValidityChecker(vc);
}
Пример #2
0
value caml_vc_funTypeN(value vc, value args, value r, value num)
{
  Type *ts;
  int i;

  CAMLparam4(vc,args,r,num);
  CAMLlocal1(result);

  ts = (Type *)malloc(Int_val(num) * sizeof(Type));
  if( !ts )
    caml_failwith("malloc returned NULL in vc_funTypeN wrapper");

  for( i = 0; i < Int_val(num); i++ ) {
    ts[i] = Type_val(Field(args,i));
  }

  result = alloc_Type(vc_funTypeN(VC_val(vc), ts, Type_val(r),
				  Int_val(num)));

  free( ts );

  CAMLreturn(result);
}