oops, writing the wrong stuff :(
This commit is contained in:
parent
1573d5ebd2
commit
ea7d247ec8
188
os/writeterm.c
188
os/writeterm.c
@ -25,11 +25,11 @@ static char SccsId[] = "%W% %G%";
|
||||
*/
|
||||
|
||||
#include "Yap.h"
|
||||
#include "Yatom.h"
|
||||
#include "YapHeap.h"
|
||||
#include "yapio.h"
|
||||
#include "eval.h"
|
||||
#include "YapText.h"
|
||||
#include "Yatom.h"
|
||||
#include "eval.h"
|
||||
#include "yapio.h"
|
||||
#include <stdlib.h>
|
||||
#if HAVE_STDARG_H
|
||||
#include <stdarg.h>
|
||||
@ -94,12 +94,11 @@ static char SccsId[] = "%W% %G%";
|
||||
#define SYSTEM_STAT stat
|
||||
#endif
|
||||
|
||||
|
||||
#undef PAR
|
||||
|
||||
#define WRITE_DEFS() \
|
||||
PAR( "module", isatom, WRITE_MODULE ), \
|
||||
PAR( "attributes", isatom, WRITE_ATTRIBUTES ), \
|
||||
PAR("module", isatom, WRITE_MODULE) \
|
||||
, PAR("attributes", isatom, WRITE_ATTRIBUTES), \
|
||||
PAR("cycles", booleanFlag, WRITE_CYCLES), \
|
||||
PAR("quoted", booleanFlag, WRITE_QUOTED), \
|
||||
PAR("ignore_ops", booleanFlag, WRITE_IGNORE_OPS), \
|
||||
@ -118,47 +117,35 @@ static char SccsId[] = "%W% %G%";
|
||||
|
||||
#define PAR(x, y, z) z
|
||||
|
||||
typedef enum open_enum_choices
|
||||
{
|
||||
WRITE_DEFS()
|
||||
} open_choices_t;
|
||||
typedef enum open_enum_choices { WRITE_DEFS() } open_choices_t;
|
||||
|
||||
#undef PAR
|
||||
|
||||
#define PAR(x,y,z) { x , y, z }
|
||||
#define PAR(x, y, z) \
|
||||
{ x, y, z }
|
||||
|
||||
|
||||
static const param_t write_defs[] =
|
||||
{
|
||||
WRITE_DEFS()
|
||||
};
|
||||
static const param_t write_defs[] = {WRITE_DEFS()};
|
||||
#undef PAR
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef BEAM
|
||||
int beam_write ( USES_REGS1 )
|
||||
{
|
||||
int beam_write(USES_REGS1) {
|
||||
Yap_StartSlots();
|
||||
Yap_plwrite (ARG1, GLOBAL_Stream+LOCAL_c_output_stream, 0, 0, GLOBAL_MaxPriority);
|
||||
Yap_plwrite(ARG1, GLOBAL_Stream + LOCAL_c_output_stream, 0, 0,
|
||||
GLOBAL_MaxPriority);
|
||||
Yap_CloseSlots();
|
||||
Yap_RaiseException();
|
||||
return (TRUE);
|
||||
}
|
||||
#endif
|
||||
|
||||
static bool
|
||||
bind_variable_names(Term t USES_REGS)
|
||||
{
|
||||
static bool bind_variable_names(Term t USES_REGS) {
|
||||
while (!IsVarTerm(t) && IsPairTerm(t)) {
|
||||
Term tl = HeadOfTerm(t);
|
||||
Functor f;
|
||||
Term tv, t2, t1;
|
||||
|
||||
if (!IsApplTerm(tl)) return FALSE;
|
||||
if (!IsApplTerm(tl))
|
||||
return FALSE;
|
||||
if ((f = FunctorOfTerm(tl)) != FunctorEq) {
|
||||
return FALSE;
|
||||
}
|
||||
@ -177,16 +164,14 @@ bind_variable_names(Term t USES_REGS)
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
unbind_variable_names(Term t USES_REGS)
|
||||
{
|
||||
static int unbind_variable_names(Term t USES_REGS) {
|
||||
while (!IsVarTerm(t) && IsPairTerm(t)) {
|
||||
Term tl = HeadOfTerm(t);
|
||||
Functor f;
|
||||
Term *tp2, t1;
|
||||
|
||||
if (!IsApplTerm(tl)) return FALSE;
|
||||
if (!IsApplTerm(tl))
|
||||
return FALSE;
|
||||
if ((f = FunctorOfTerm(tl)) != FunctorEq) {
|
||||
return FALSE;
|
||||
}
|
||||
@ -201,10 +186,7 @@ unbind_variable_names(Term t USES_REGS)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
static bool
|
||||
write_term ( int output_stream, Term t, xarg *args USES_REGS )
|
||||
{
|
||||
static bool write_term(int output_stream, Term t, xarg *args USES_REGS) {
|
||||
bool rc;
|
||||
Term cm = CurrentModule;
|
||||
int depth, prio, flags = 0;
|
||||
@ -229,29 +211,27 @@ write_term ( int output_stream, Term t, xarg *args USES_REGS )
|
||||
} else if (ctl == TermDots) {
|
||||
flags |= AttVar_Dots_f;
|
||||
} else if (ctl != TermIgnore) {
|
||||
Yap_Error(DOMAIN_ERROR_OUT_OF_RANGE, ctl, "write attributes should be one of {dots,ignore,portray,write}");
|
||||
Yap_Error(
|
||||
DOMAIN_ERROR_OUT_OF_RANGE, ctl,
|
||||
"write attributes should be one of {dots,ignore,portray,write}");
|
||||
rc = false;
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
if (args[WRITE_CYCLES].used &&
|
||||
args[WRITE_CYCLES].tvalue == TermFalse) {
|
||||
if (args[WRITE_CYCLES].used && args[WRITE_CYCLES].tvalue == TermFalse) {
|
||||
flags |= Unfold_cyclics_f;
|
||||
}
|
||||
if (args[WRITE_QUOTED].used &&
|
||||
args[WRITE_QUOTED].tvalue == TermTrue) {
|
||||
if (args[WRITE_QUOTED].used && args[WRITE_QUOTED].tvalue == TermTrue) {
|
||||
flags |= Quote_illegal_f;
|
||||
}
|
||||
if (args[WRITE_IGNORE_OPS].used &&
|
||||
args[WRITE_IGNORE_OPS].tvalue == TermTrue) {
|
||||
flags |= Ignore_ops_f;
|
||||
}
|
||||
if (args[WRITE_PORTRAY].used &&
|
||||
args[WRITE_IGNORE_OPS].tvalue == TermTrue) {
|
||||
if (args[WRITE_PORTRAY].used && args[WRITE_IGNORE_OPS].tvalue == TermTrue) {
|
||||
flags |= Ignore_ops_f;
|
||||
}
|
||||
if (args[WRITE_PORTRAYED].used &&
|
||||
args[WRITE_PORTRAYED].tvalue == TermTrue) {
|
||||
if (args[WRITE_PORTRAYED].used && args[WRITE_PORTRAYED].tvalue == TermTrue) {
|
||||
flags |= Use_portray_f;
|
||||
}
|
||||
if (args[WRITE_CHARACTER_ESCAPES].used &&
|
||||
@ -266,12 +246,10 @@ write_term ( int output_stream, Term t, xarg *args USES_REGS )
|
||||
args[WRITE_BRACE_TERMS].tvalue == TermFalse) {
|
||||
flags |= No_Brace_Terms_f;
|
||||
}
|
||||
if (args[WRITE_FULLSTOP].used &&
|
||||
args[WRITE_FULLSTOP].tvalue == TermTrue) {
|
||||
if (args[WRITE_FULLSTOP].used && args[WRITE_FULLSTOP].tvalue == TermTrue) {
|
||||
flags |= Fullstop_f;
|
||||
}
|
||||
if (args[WRITE_NL].used &&
|
||||
args[WRITE_NL].tvalue == TermTrue) {
|
||||
if (args[WRITE_NL].used && args[WRITE_NL].tvalue == TermTrue) {
|
||||
flags |= New_Line_f;
|
||||
}
|
||||
|
||||
@ -297,9 +275,7 @@ write_term ( int output_stream, Term t, xarg *args USES_REGS )
|
||||
return rc;
|
||||
}
|
||||
|
||||
static Int
|
||||
write_term2 ( USES_REGS1 )
|
||||
{
|
||||
static Int write_term2(USES_REGS1) {
|
||||
|
||||
/* '$write'(+Flags,?Term) */
|
||||
/* notice: we must have ASP well set when using portray, otherwise
|
||||
@ -314,19 +290,17 @@ write_term2 ( USES_REGS1 )
|
||||
}
|
||||
yhandle_t mySlots = Yap_StartSlots();
|
||||
int output_stream = LOCAL_c_output_stream;
|
||||
if (output_stream == -1) output_stream = 1;
|
||||
if (output_stream == -1)
|
||||
output_stream = 1;
|
||||
LOCK(GLOBAL_Stream[output_stream].streamlock);
|
||||
write_term( output_stream, ARG2, args PASS_REGS);
|
||||
write_term(output_stream, ARG1, args PASS_REGS);
|
||||
UNLOCK(GLOBAL_Stream[output_stream].streamlock);
|
||||
Yap_CloseSlots(mySlots);
|
||||
Yap_RaiseException();
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
|
||||
static Int
|
||||
write_term3 ( USES_REGS1 )
|
||||
{
|
||||
static Int write_term3(USES_REGS1) {
|
||||
|
||||
/* notice: we must have ASP well set when using portray, otherwise
|
||||
we cannot make recursive Prolog calls */
|
||||
@ -349,14 +323,11 @@ write_term3 ( USES_REGS1 )
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
static Int
|
||||
write2 ( USES_REGS1 )
|
||||
{
|
||||
static Int write2(USES_REGS1) {
|
||||
|
||||
/* notice: we must have ASP well set when using portray, otherwise
|
||||
we cannot make recursive Prolog calls */
|
||||
|
||||
|
||||
xarg *args;
|
||||
yhandle_t mySlots;
|
||||
int output_stream = Yap_CheckTextStream(ARG1, Output_Stream_f, "write/2");
|
||||
@ -380,14 +351,13 @@ write2 ( USES_REGS1 )
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
static Int
|
||||
write1 ( USES_REGS1 )
|
||||
{
|
||||
static Int write1(USES_REGS1) {
|
||||
|
||||
/* notice: we must have ASP well set when using portray, otherwise
|
||||
we cannot make recursive Prolog calls */
|
||||
int output_stream = LOCAL_c_output_stream;
|
||||
if (output_stream == -1) output_stream = 1;
|
||||
if (output_stream == -1)
|
||||
output_stream = 1;
|
||||
xarg *args = Yap_ArgListToVector(TermNil, write_defs, WRITE_END);
|
||||
if (args == NULL) {
|
||||
if (LOCAL_Error_TYPE == DOMAIN_ERROR_OUT_OF_RANGE)
|
||||
@ -407,14 +377,13 @@ write1 ( USES_REGS1 )
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
static Int
|
||||
write_canonical1 ( USES_REGS1 )
|
||||
{
|
||||
static Int write_canonical1(USES_REGS1) {
|
||||
|
||||
/* notice: we must have ASP well set when using portray, otherwise
|
||||
we cannot make recursive Prolog calls */
|
||||
int output_stream = LOCAL_c_output_stream;
|
||||
if (output_stream == -1) output_stream = 1;
|
||||
if (output_stream == -1)
|
||||
output_stream = 1;
|
||||
xarg *args = Yap_ArgListToVector(TermNil, write_defs, WRITE_END);
|
||||
if (args == NULL) {
|
||||
if (LOCAL_Error_TYPE == DOMAIN_ERROR_OUT_OF_RANGE)
|
||||
@ -436,9 +405,7 @@ write_canonical1 ( USES_REGS1 )
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
static Int
|
||||
write_canonical ( USES_REGS1 )
|
||||
{
|
||||
static Int write_canonical(USES_REGS1) {
|
||||
|
||||
/* notice: we must have ASP well set when using portray, otherwise
|
||||
we cannot make recursive Prolog calls */
|
||||
@ -465,9 +432,7 @@ write_canonical ( USES_REGS1 )
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
static Int
|
||||
writeq1 ( USES_REGS1 )
|
||||
{
|
||||
static Int writeq1(USES_REGS1) {
|
||||
|
||||
/* notice: we must have ASP well set when using portray, otherwise
|
||||
we cannot make recursive Prolog calls */
|
||||
@ -481,7 +446,8 @@ writeq1 ( USES_REGS1 )
|
||||
}
|
||||
yhandle_t mySlots = Yap_StartSlots();
|
||||
int output_stream = LOCAL_c_output_stream;
|
||||
if (output_stream == -1) output_stream = 1;
|
||||
if (output_stream == -1)
|
||||
output_stream = 1;
|
||||
args[WRITE_NUMBERVARS].used = true;
|
||||
args[WRITE_NUMBERVARS].tvalue = TermTrue;
|
||||
args[WRITE_QUOTED].used = true;
|
||||
@ -494,10 +460,7 @@ writeq1 ( USES_REGS1 )
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
|
||||
static Int
|
||||
writeq ( USES_REGS1 )
|
||||
{
|
||||
static Int writeq(USES_REGS1) {
|
||||
|
||||
/* notice: we must have ASP well set when using portray, otherwise
|
||||
we cannot make recursive Prolog calls */
|
||||
@ -524,10 +487,7 @@ writeq ( USES_REGS1 )
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
|
||||
static Int
|
||||
print1 ( USES_REGS1 )
|
||||
{
|
||||
static Int print1(USES_REGS1) {
|
||||
|
||||
/* notice: we must have ASP well set when using portray, otherwise
|
||||
we cannot make recursive Prolog calls */
|
||||
@ -541,7 +501,8 @@ print1 ( USES_REGS1 )
|
||||
}
|
||||
yhandle_t mySlots = Yap_StartSlots();
|
||||
int output_stream = LOCAL_c_output_stream;
|
||||
if (output_stream == -1) output_stream = 1;
|
||||
if (output_stream == -1)
|
||||
output_stream = 1;
|
||||
args[WRITE_PORTRAY].used = true;
|
||||
args[WRITE_PORTRAY].tvalue = TermTrue;
|
||||
args[WRITE_NUMBERVARS].used = true;
|
||||
@ -554,10 +515,7 @@ print1 ( USES_REGS1 )
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
|
||||
static Int
|
||||
print ( USES_REGS1 )
|
||||
{
|
||||
static Int print(USES_REGS1) {
|
||||
|
||||
/* notice: we must have ASP well set when using portray, otherwise
|
||||
we cannot make recursive Prolog calls */
|
||||
@ -584,14 +542,13 @@ print ( USES_REGS1 )
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
static Int
|
||||
writeln1 ( USES_REGS1 )
|
||||
{
|
||||
static Int writeln1(USES_REGS1) {
|
||||
|
||||
/* notice: we must have ASP well set when using portray, otherwise
|
||||
we cannot make recursive Prolog calls */
|
||||
int output_stream = LOCAL_c_output_stream;
|
||||
if (output_stream == -1) output_stream = 1;
|
||||
if (output_stream == -1)
|
||||
output_stream = 1;
|
||||
xarg *args = Yap_ArgListToVector(TermNil, write_defs, WRITE_END);
|
||||
if (args == NULL) {
|
||||
if (LOCAL_Error_TYPE)
|
||||
@ -611,10 +568,7 @@ writeln1 ( USES_REGS1 )
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
|
||||
static Int
|
||||
writeln ( USES_REGS1 )
|
||||
{
|
||||
static Int writeln(USES_REGS1) {
|
||||
|
||||
/* notice: we must have ASP well set when using portray, otherwise
|
||||
we cannot make recursive Prolog calls */
|
||||
@ -639,11 +593,7 @@ writeln ( USES_REGS1 )
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static Int
|
||||
p_write_depth ( USES_REGS1 )
|
||||
{ /* write_depth(Old,New) */
|
||||
static Int p_write_depth(USES_REGS1) { /* write_depth(Old,New) */
|
||||
Term t1 = Deref(ARG1);
|
||||
Term t2 = Deref(ARG2);
|
||||
Term t3 = Deref(ARG3);
|
||||
@ -660,42 +610,33 @@ p_write_depth ( USES_REGS1 )
|
||||
Yap_Error(TYPE_ERROR_INTEGER, t3, "write_depth/3");
|
||||
return FALSE;
|
||||
}
|
||||
if (IsVarTerm (t1))
|
||||
{
|
||||
if (IsVarTerm(t1)) {
|
||||
Term t = MkIntegerTerm(LOCAL_max_depth);
|
||||
if (!Yap_unify_constant(t1, t))
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
} else
|
||||
LOCAL_max_depth = IntegerOfTerm(t1);
|
||||
if (IsVarTerm (t2))
|
||||
{
|
||||
if (IsVarTerm(t2)) {
|
||||
Term t = MkIntegerTerm(LOCAL_max_list);
|
||||
if (!Yap_unify_constant(t2, t))
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
} else
|
||||
LOCAL_max_list = IntegerOfTerm(t2);
|
||||
if (IsVarTerm (t3))
|
||||
{
|
||||
if (IsVarTerm(t3)) {
|
||||
Term t = MkIntegerTerm(LOCAL_max_write_args);
|
||||
if (!Yap_unify_constant(t3, t))
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
} else
|
||||
LOCAL_max_write_args = IntegerOfTerm(t3);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static Int
|
||||
dollar_var( USES_REGS1 )
|
||||
{
|
||||
static Int dollar_var(USES_REGS1) {
|
||||
Term in = Deref(ARG1);
|
||||
if (IsVarTerm(in)) {
|
||||
Term t2;
|
||||
if (!IsVarTerm(t2 = Deref(ARG2))) {
|
||||
if (IsApplTerm(t2) &&
|
||||
FunctorOfTerm( t2 ) == FunctorDollarVar ) {
|
||||
if (IsApplTerm(t2) && FunctorOfTerm(t2) == FunctorDollarVar) {
|
||||
return Yap_unify(ArgOfTerm(1, t2), ARG1);
|
||||
}
|
||||
Yap_Error(TYPE_ERROR_COMPOUND, ARG2, "");
|
||||
@ -709,10 +650,7 @@ dollar_var( USES_REGS1 )
|
||||
return Yap_unify(tv, ARG2);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Yap_InitWriteTPreds(void)
|
||||
{
|
||||
void Yap_InitWriteTPreds(void) {
|
||||
Yap_InitCPred("write_term", 2, write_term2, SyncPredFlag);
|
||||
Yap_InitCPred("write_term", 3, write_term3, SyncPredFlag);
|
||||
Yap_InitCPred("write", 1, write1, SyncPredFlag);
|
||||
|
Reference in New Issue
Block a user