From 06e5371afddacea8270e91a622cd5f927b3bb5c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Santos=20Costa?= Date: Tue, 29 Mar 2016 01:57:55 +0100 Subject: [PATCH] exceptions --- os/format.c | 11 +++--- os/iopreds.c | 11 +++--- os/writeterm.c | 95 ++++++++------------------------------------------ os/yapio.h | 2 +- 4 files changed, 26 insertions(+), 93 deletions(-) diff --git a/os/format.c b/os/format.c index 0a8500b6d..08684e412 100644 --- a/os/format.c +++ b/os/format.c @@ -892,7 +892,7 @@ static Int doformat(volatile Term otail, volatile Term oargs, ts = Yap_MkApplTerm(FunctorGFormatAt, 2, ta); res = Yap_execute_goal(ts, 0, CurrentModule, true); args = Yap_GetFromSlot(sl); - if (EX) + if (Yap_HasException()) goto ex_handler; if (!res) return FALSE; @@ -914,12 +914,9 @@ static Int doformat(volatile Term otail, volatile Term oargs, args = Yap_GetFromSlot(sl); Yap_CloseSlots(sl); } - if (EX != 0L) { - Term ball; + if (Yap_HasException()) { ex_handler: - ball = Yap_PopTermFromDB(EX); - EX = NULL; if (tnum <= 8) targs = NULL; if (IsAtomTerm(tail)) { @@ -929,8 +926,8 @@ static Int doformat(volatile Term otail, volatile Term oargs, GLOBAL_Stream[sno].u.mem_string.error_handler = old_handler; } format_clean_up(sno, (char *)fstr, targs); - Yap_JumpToEnv(ball); - return FALSE; + Yap_RaiseException(); + return false; } break; case 'q': diff --git a/os/iopreds.c b/os/iopreds.c index 2635b0a42..89bcca213 100644 --- a/os/iopreds.c +++ b/os/iopreds.c @@ -1577,7 +1577,6 @@ int PlGetc(int sno) { return -1; } else { LOCK(GLOBAL_Stream[sno].streamlock); - return sno; } } else if (IsApplTerm(arg) && FunctorOfTerm(arg) == FunctorStream) { arg = ArgOfTerm(1, arg); @@ -1587,24 +1586,26 @@ int PlGetc(int sno) { } if (sno < 0) { Yap_Error(DOMAIN_ERROR_STREAM_OR_ALIAS, arg, msg); - return (-1); + return -1; } if (GLOBAL_Stream[sno].status & Free_Stream_f) { PlIOError__(file, f, line, EXISTENCE_ERROR_STREAM, arg, msg); - return (-1); + return -1; } LOCK(GLOBAL_Stream[sno].streamlock); if ((GLOBAL_Stream[sno].status & Input_Stream_f) && !(kind & Input_Stream_f)) { UNLOCK(GLOBAL_Stream[sno].streamlock); PlIOError__(file, f, line, PERMISSION_ERROR_OUTPUT_STREAM, arg, msg); + return -1; } if ((GLOBAL_Stream[sno].status & (Append_Stream_f | Output_Stream_f)) && !(kind & Output_Stream_f)) { UNLOCK(GLOBAL_Stream[sno].streamlock); PlIOError__(file, f, line, PERMISSION_ERROR_INPUT_STREAM, arg, msg); + return -1; } - return (sno); + return sno; } int Yap_CheckStream__(const char *file, const char *f, int line, Term arg, @@ -1618,13 +1619,13 @@ int PlGetc(int sno) { if ((sno = CheckStream__(file, f, line, arg, kind, msg)) < 0) return -1; if ((GLOBAL_Stream[sno].status & Binary_Stream_f)) { + UNLOCK(GLOBAL_Stream[sno].streamlock); if (kind == Input_Stream_f) PlIOError__(file, f, line, PERMISSION_ERROR_INPUT_BINARY_STREAM, arg, msg); else PlIOError__(file, f, line, PERMISSION_ERROR_OUTPUT_BINARY_STREAM, arg, msg); - UNLOCK(GLOBAL_Stream[sno].streamlock); return -1; } return sno; diff --git a/os/writeterm.c b/os/writeterm.c index fdb00df6d..ee5bbd13f 100644 --- a/os/writeterm.c +++ b/os/writeterm.c @@ -145,12 +145,7 @@ int beam_write ( USES_REGS1 ) Yap_StartSlots(); Yap_plwrite (ARG1, GLOBAL_Stream+LOCAL_c_output_stream, 0, 0, GLOBAL_MaxPriority); Yap_CloseSlots(); - if (EX != 0L) { - Term ball = Yap_PopTermFromDB(EX); - EX = 0L; - Yap_JumpToEnv(ball); - return(FALSE); - } + Yap_RaiseException(); return (TRUE); } #endif @@ -324,13 +319,8 @@ write_term2 ( USES_REGS1 ) write_term( output_stream, ARG2, args PASS_REGS); UNLOCK(GLOBAL_Stream[output_stream].streamlock); Yap_CloseSlots( mySlots ); - if (EX != 0L) { - Term ball = Yap_PopTermFromDB(EX); - EX = NULL; - Yap_JumpToEnv(ball); - return(FALSE); - } - return (TRUE); + Yap_RaiseException(); + return (TRUE); } @@ -355,12 +345,7 @@ write_term3 ( USES_REGS1 ) write_term( output_stream, ARG2, args PASS_REGS); UNLOCK(GLOBAL_Stream[output_stream].streamlock); Yap_CloseSlots( mySlots ); - if (EX != 0L) { - Term ball = Yap_PopTermFromDB(EX); - EX = NULL; - Yap_JumpToEnv(ball); - return(FALSE); - } + Yap_RaiseException(); return (TRUE); } @@ -391,12 +376,7 @@ write2 ( USES_REGS1 ) write_term( output_stream, ARG2, args PASS_REGS); UNLOCK(GLOBAL_Stream[output_stream].streamlock); Yap_CloseSlots( mySlots ); - if (EX != 0L) { - Term ball = Yap_PopTermFromDB(EX); - EX = NULL; - Yap_JumpToEnv(ball); - return(FALSE); - } + Yap_RaiseException(); return (TRUE); } @@ -421,12 +401,7 @@ write1 ( USES_REGS1 ) write_term( output_stream, ARG1, args PASS_REGS); UNLOCK(GLOBAL_Stream[output_stream].streamlock); Yap_CloseSlots( mySlots ); - if (EX != 0L) { - Term ball = Yap_PopTermFromDB(EX); - EX = NULL; - Yap_JumpToEnv(ball); - return(FALSE); - } + Yap_RaiseException(); return (TRUE); } @@ -453,12 +428,7 @@ write_canonical1 ( USES_REGS1 ) write_term( output_stream, ARG1, args PASS_REGS); UNLOCK(GLOBAL_Stream[output_stream].streamlock); Yap_CloseSlots( mySlots ); - if (EX != 0L) { - Term ball = Yap_PopTermFromDB(EX); - EX = NULL; - Yap_JumpToEnv(ball); - return(FALSE); - } + Yap_RaiseException(); return (TRUE); } @@ -485,12 +455,7 @@ write_canonical ( USES_REGS1 ) write_term( output_stream, ARG2, args PASS_REGS); UNLOCK(GLOBAL_Stream[output_stream].streamlock); Yap_CloseSlots( mySlots ); - if (EX != 0L) { - Term ball = Yap_PopTermFromDB(EX); - EX = NULL; - Yap_JumpToEnv(ball); - return(FALSE); - } + Yap_RaiseException(); return (TRUE); } @@ -517,12 +482,7 @@ writeq1 ( USES_REGS1 ) UNLOCK(GLOBAL_Stream[output_stream].streamlock); Yap_CloseSlots( mySlots ); - if (EX != 0L) { - Term ball = Yap_PopTermFromDB(EX); - EX = NULL; - Yap_JumpToEnv(ball); - return(FALSE); - } + Yap_RaiseException(); return (TRUE); } @@ -550,12 +510,7 @@ writeq ( USES_REGS1 ) write_term( output_stream, ARG2, args PASS_REGS); UNLOCK(GLOBAL_Stream[output_stream].streamlock); Yap_CloseSlots( mySlots ); - if (EX != 0L) { - Term ball = Yap_PopTermFromDB(EX); - EX = NULL; - Yap_JumpToEnv(ball); - return(FALSE); - } + Yap_RaiseException(); return (TRUE); } @@ -583,12 +538,7 @@ print1 ( USES_REGS1 ) write_term( output_stream, ARG1, args PASS_REGS); UNLOCK(GLOBAL_Stream[output_stream].streamlock); Yap_CloseSlots( mySlots ); - if (EX != 0L) { - Term ball = Yap_PopTermFromDB(EX); - EX = NULL; - Yap_JumpToEnv(ball); - return(FALSE); - } + Yap_RaiseException(); return (TRUE); } @@ -616,13 +566,8 @@ print ( USES_REGS1 ) write_term( output_stream, ARG2, args PASS_REGS); UNLOCK(GLOBAL_Stream[output_stream].streamlock); Yap_CloseSlots( mySlots ); - if (EX != 0L) { - Term ball = Yap_PopTermFromDB(EX); - EX = NULL; - Yap_JumpToEnv(ball); - return(FALSE); - } - return (TRUE); + Yap_RaiseException(); + return (TRUE); } static Int @@ -648,12 +593,7 @@ writeln1 ( USES_REGS1 ) write_term( output_stream, ARG1, args PASS_REGS); UNLOCK(GLOBAL_Stream[output_stream].streamlock); Yap_CloseSlots( mySlots ); - if (EX != 0L) { - Term ball = Yap_PopTermFromDB(EX); - EX = NULL; - Yap_JumpToEnv(ball); - return(FALSE); - } + Yap_RaiseException(); return (TRUE); } @@ -681,12 +621,7 @@ writeln ( USES_REGS1 ) write_term( output_stream, ARG2, args PASS_REGS); UNLOCK(GLOBAL_Stream[output_stream].streamlock); Yap_CloseSlots( mySlots ); - if (EX != 0L) { - Term ball = Yap_PopTermFromDB(EX); - EX = NULL; - Yap_JumpToEnv(ball); - return(FALSE); - } + Yap_RaiseException(); return (TRUE); } diff --git a/os/yapio.h b/os/yapio.h index 9613a9fc9..dcc27bc00 100644 --- a/os/yapio.h +++ b/os/yapio.h @@ -163,7 +163,7 @@ INLINE_ONLY inline EXTERN Term MkCharTerm(Int c); INLINE_ONLY inline EXTERN Term MkCharTerm(Int c) { wchar_t cs[2]; if (c < 0) - return MkAtomTerm(AtomEof); + return TermEof; cs[0] = c; cs[1] = '\0'; return MkAtomTerm(Yap_LookupMaybeWideAtom(cs));