From b454383e3058045ee614a2c37ba380a1678576e7 Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Tue, 14 Feb 2012 07:46:37 +0000 Subject: [PATCH] more write updates. --- BEAM/toeam.c | 4 ++-- C/heapgc.c | 2 +- C/iopreds.c | 4 ++-- C/tracer.c | 2 +- C/write.c | 30 ++++++++++++++++++++---------- H/Yapproto.h | 2 +- os/pl-write.c | 5 ++--- 7 files changed, 29 insertions(+), 20 deletions(-) diff --git a/BEAM/toeam.c b/BEAM/toeam.c index 96480aa61..6cf69d8ce 100644 --- a/BEAM/toeam.c +++ b/BEAM/toeam.c @@ -742,10 +742,10 @@ void ShowCode_new2(int op, int new1,CELL new4) switch (ch = *f++) { case '1': - Yap_plwrite(MkIntTerm(new1), NULL, 0, 1200); + Yap_plwrite(MkIntTerm(new1), NULL, 30, 0, 1200); break; case '4': - Yap_plwrite(MkIntTerm(new4), NULL, 0, 1200); + Yap_plwrite(MkIntTerm(new4), NULL, 20, 0, 1200); break; default: Yap_DebugPutc (LOCAL_c_error_stream,'%'); diff --git a/C/heapgc.c b/C/heapgc.c index 3c4f52a8a..e00e556f1 100644 --- a/C/heapgc.c +++ b/C/heapgc.c @@ -4136,7 +4136,7 @@ call_gc(UInt gc_lim, Int predarity, CELL *current_env, yamop *nextop USES_REGS) } /* * debug for(save_total=1; save_total<=N; ++save_total) - * plwrite(XREGS[save_total],Yap_DebugPutc,0); + * plwrite(XREGS[save_total],NULL,30,0,0); */ return TRUE; } diff --git a/C/iopreds.c b/C/iopreds.c index a12603a80..877b40ec3 100644 --- a/C/iopreds.c +++ b/C/iopreds.c @@ -199,7 +199,7 @@ Yap_DebugPutc(int sno, wchar_t ch) void Yap_DebugPlWrite(Term t) { - Yap_plwrite(t, NULL, 0, 1200); + Yap_plwrite(t, NULL, 15, 0, 1200); } void @@ -238,7 +238,7 @@ typedef struct stream_ref int beam_write (void) { Yap_StartSlots(); - Yap_plwrite (ARG1, NULL, 0, 1200); + Yap_plwrite (ARG1, NULL, 0, 0, 1200); Yap_CloseSlots(); if (EX != 0L) { Term ball = Yap_PopTermFromDB(EX); diff --git a/C/tracer.c b/C/tracer.c index 6c7376451..74da2a1bc 100644 --- a/C/tracer.c +++ b/C/tracer.c @@ -57,7 +57,7 @@ send_tracer_message(char *start, char *name, Int arity, char *mname, CELL *args) Yap_Portray_delays = TRUE; #endif #endif - Yap_plwrite(args[i], NULL, Handle_vars_f, 1200); + Yap_plwrite(args[i], NULL, 15, Handle_vars_f, 1200); #if DEBUG #if COROUTINING Yap_Portray_delays = FALSE; diff --git a/C/write.c b/C/write.c index 09ceb2a7f..536f0a2ae 100644 --- a/C/write.c +++ b/C/write.c @@ -76,7 +76,6 @@ typedef struct write_globs { } wglbs; STATIC_PROTO(void wrputn, (Int, wrf)); -STATIC_PROTO(void wrputs, (char *, wrf)); STATIC_PROTO(void wrputf, (Float, wrf)); STATIC_PROTO(void wrputref, (CODEADDR, int, wrf)); STATIC_PROTO(int legalAtom, (unsigned char *)); @@ -193,19 +192,21 @@ writebig(Term t, int p, int depth, int rinfixarg, struct write_globs *wglb, stru { CACHE_REGS CELL *pt = RepAppl(t)+1; + CELL big_tag = pt[0]; + #ifdef USE_GMP - if (pt[0] == BIG_INT) + if (big_tag == BIG_INT) { MP_INT *big = Yap_BigIntOfTerm(t); write_mpint(big, wglb->stream); return; - } else if (pt[0] == BIG_RATIONAL) { + } else if (big_tag == BIG_RATIONAL) { Term trat = Yap_RatTermToApplTerm(t); writeTerm(trat, p, depth, rinfixarg, wglb, rwt); return; } #endif - if (pt[0] == BLOB_STRING) { + if (big_tag == BLOB_STRING) { if (wglb->Write_strings) wrputc('`',wglb->stream); else @@ -216,7 +217,7 @@ writebig(Term t, int p, int depth, int rinfixarg, struct write_globs *wglb, stru else wrputc('"',wglb->stream); return; - } else if (pt[0] == BLOB_WIDE_STRING) { + } else if (big_tag == BLOB_WIDE_STRING) { wchar_t *s = Yap_BlobWideStringOfTerm(t); if (wglb->Write_strings) wrputc('`',wglb->stream); @@ -230,6 +231,15 @@ writebig(Term t, int p, int depth, int rinfixarg, struct write_globs *wglb, stru else wrputc('"',wglb->stream); return; + } else if (big_tag >= USER_BLOB_START && big_tag < USER_BLOB_END) { + Opaque_CallOnWrite f; + CELL blob_info; + + blob_info = big_tag - USER_BLOB_START; + if (GLOBAL_OpaqueHandlers && + (f= GLOBAL_OpaqueHandlers[blob_info].write_handler)) { + (f)(wglb->stream, big_tag, (void *)((MP_INT *)(pt+1)), 0); + } } wrputs("0",wglb->stream); } @@ -987,7 +997,7 @@ writeTerm(Term t, int p, int depth, int rinfixarg, struct write_globs *wglb, str if (lastw == alphanum) { wrputc(' ', wglb->stream); } - if (!IsVarTerm(ti) && (IsIntTerm(ti) || IsStringTerm(ti)) || IsAtomTerm(ti)) { + if (!IsVarTerm(ti) && (IsIntTerm(ti) || IsStringTerm(ti) || IsAtomTerm(ti))) { if (IsIntTerm(ti)) { Int k = IntOfTerm(ti); if (k == -1) { @@ -1041,7 +1051,7 @@ writeTerm(Term t, int p, int depth, int rinfixarg, struct write_globs *wglb, str lastw = separator; for (op = 1; op <= Arity; ++op) { if (op == wglb->MaxArgs) { - wrputs('...', wglb->stream); + wrputs("...", wglb->stream); break; } if (wglb->keep_terms) { @@ -1098,7 +1108,7 @@ writeTerm(Term t, int p, int depth, int rinfixarg, struct write_globs *wglb, str } void -Yap_plwrite(Term t, void *mywrite, int flags, int priority) +Yap_plwrite(Term t, void *mywrite, int max_depth, int flags, int priority) /* term to be written */ /* consumer */ /* write options */ @@ -1115,8 +1125,8 @@ Yap_plwrite(Term t, void *mywrite, int flags, int priority) wglb.Quote_illegal = flags & Quote_illegal_f; wglb.Handle_vars = flags & Handle_vars_f; wglb.Use_portray = flags & Use_portray_f; - wglb.MaxDepth = 15L; - wglb.MaxArgs = 60L; + wglb.MaxDepth = max_depth; + wglb.MaxArgs = max_depth; /* notice: we must have ASP well set when using portray, otherwise we cannot make recursive Prolog calls */ wglb.keep_terms = (flags & (Use_portray_f|To_heap_f)); diff --git a/H/Yapproto.h b/H/Yapproto.h index 7049d290f..1454d9fba 100644 --- a/H/Yapproto.h +++ b/H/Yapproto.h @@ -406,7 +406,7 @@ Int STD_PROTO(Yap_SkipList,(Term *, Term **)); /* write.c */ -void STD_PROTO(Yap_plwrite,(Term, void *, int, int)); +void STD_PROTO(Yap_plwrite,(Term, void *, int, int, int)); /* MYDDAS */ diff --git a/os/pl-write.c b/os/pl-write.c index 34b1e6a5e..2fa6c1eb7 100644 --- a/os/pl-write.c +++ b/os/pl-write.c @@ -207,18 +207,17 @@ writeTerm(term_t t, int prec, write_options *options) yap_flag |= Blob_Portray_f; old_module = CurrentModule; CurrentModule = options->module; - Yap_plwrite(Yap_GetFromSlot(t), options->out, yap_flag, prec); + Yap_plwrite(Yap_GetFromSlot(t), options->out, options->max_depth, yap_flag, prec); CurrentModule = old_module; return TRUE; } int writeAtomToStream(IOSTREAM *s, atom_t atom) -{ Yap_plwrite(MkAtomTerm(YAP_AtomFromSWIAtom(atom)), s, 0, 1200); +{ Yap_plwrite(MkAtomTerm(YAP_AtomFromSWIAtom(atom)), s, 0, 0, 1200); return 1; } - int writeAttributeMask(atom_t a) { if ( a == ATOM_ignore )