support inline arithemtic builtins as non-inlined.

This commit is contained in:
Costa Vitor 2009-07-22 17:01:30 -05:00
parent d9a48c4014
commit c8946e1e4e
2 changed files with 78 additions and 8 deletions

View File

@ -1151,6 +1151,76 @@ p_binary_is(void)
return FALSE;
}
static Int
do_arith23(arith2_op op)
{ /* X is Y */
Term t = Deref(ARG1);
Int out;
Term t1, t2;
if (IsVarTerm(t)) {
Yap_ArithError(INSTANTIATION_ERROR,t, "X is Y");
return(FALSE);
}
t1 = Yap_Eval(t);
if (t1 == 0L)
return FALSE;
t2 = Yap_Eval(Deref(ARG2));
if (t2 == 0L)
return FALSE;
if (!(out=Yap_FoundArithError(eval2(op, t1, t2), 0L)))
return FALSE;
return Yap_unify_constant(ARG3,out);
}
static Int
export_p_plus(void)
{ /* X is Y */
return do_arith23(op_plus);
}
static Int
export_p_minus(void)
{ /* X is Y */
return do_arith23(op_minus);
}
static Int
export_p_times(void)
{ /* X is Y */
return do_arith23(op_times);
}
static Int
export_p_div(void)
{ /* X is Y */
return do_arith23(op_div);
}
static Int
export_p_and(void)
{ /* X is Y */
return do_arith23(op_and);
}
static Int
export_p_or(void)
{ /* X is Y */
return do_arith23(op_or);
}
static Int
export_p_slr(void)
{ /* X is Y */
return do_arith23(op_slr);
}
static Int
export_p_sll(void)
{ /* X is Y */
return do_arith23(op_sll);
}
static Int
p_binary_op_as_integer(void)
{ /* X is Y */
@ -1214,6 +1284,14 @@ Yap_InitBinaryExps(void)
}
Yap_InitCPred("is", 4, p_binary_is, TestPredFlag | SafePredFlag);
Yap_InitCPred("$binary_op_as_integer", 2, p_binary_op_as_integer, TestPredFlag|SafePredFlag);
Yap_InitAsmPred("$plus", 3, _plus, export_p_plus, SafePredFlag);
Yap_InitAsmPred("$minus", 3, _minus, export_p_minus, SafePredFlag);
Yap_InitAsmPred("$times", 3, _times, export_p_times, SafePredFlag);
Yap_InitAsmPred("$div", 3, _div, export_p_div, SafePredFlag);
Yap_InitAsmPred("$and", 3, _and, export_p_and, SafePredFlag);
Yap_InitAsmPred("$or", 3, _or, export_p_or, SafePredFlag);
Yap_InitAsmPred("$sll", 3, _sll, export_p_sll, SafePredFlag);
Yap_InitAsmPred("$slr", 3, _slr, export_p_slr, SafePredFlag);
}
/* This routine is called from Restore to make sure we have the same arithmetic operators */

View File

@ -921,14 +921,6 @@ Yap_InitInlines(void)
Yap_InitAsmPred("==", 2, _eq, p_eq, SafePredFlag);
Yap_InitAsmPred("arg", 3, _arg, p_arg, SafePredFlag);
Yap_InitAsmPred("functor", 3, _functor, p_functor, 0);
Yap_InitAsmPred("$plus", 3, _plus, p_erroneous_call, SafePredFlag);
Yap_InitAsmPred("$minus", 3, _minus, p_erroneous_call, SafePredFlag);
Yap_InitAsmPred("$times", 3, _times, p_erroneous_call, SafePredFlag);
Yap_InitAsmPred("$div", 3, _div, p_erroneous_call, SafePredFlag);
Yap_InitAsmPred("$and", 3, _and, p_erroneous_call, SafePredFlag);
Yap_InitAsmPred("$or", 3, _or, p_erroneous_call, SafePredFlag);
Yap_InitAsmPred("$sll", 3, _sll, p_erroneous_call, SafePredFlag);
Yap_InitAsmPred("$slr", 3, _slr, p_erroneous_call, SafePredFlag);
Yap_InitAsmPred("$label_ctl", 2, _p_label_ctl, p_erroneous_call, SafePredFlag);
CurrentModule = ARG_MODULE;
Yap_InitCPredBack("genarg", 3, 3, init_genarg, cont_genarg,SafePredFlag);