start support for java interface

bug fixes


git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1093 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
vsc 2004-07-15 15:47:08 +00:00
parent 33bd3a9385
commit 08b9f55f9c
10 changed files with 88 additions and 36 deletions

View File

@ -127,6 +127,13 @@ do_execute(Term t, Term mod)
/* first do predicate expansion, even before you process signals. /* first do predicate expansion, even before you process signals.
This way you don't get to spy goal_expansion(). */ This way you don't get to spy goal_expansion(). */
if (PRED_GOAL_EXPANSION_ON) { if (PRED_GOAL_EXPANSION_ON) {
LOCK(SignalLock);
/* disable creeping when we do goal expansion */
if (ActiveSignals & YAP_CREEP_SIGNAL) {
ActiveSignals &= ~YAP_CREEP_SIGNAL;
DelayedTrace = TRUE;
}
UNLOCK(SignalLock);
return CallMetaCall(mod); return CallMetaCall(mod);
} else if (ActiveSignals) { } else if (ActiveSignals) {
return EnterCreepMode(t, mod); return EnterCreepMode(t, mod);
@ -244,7 +251,11 @@ p_execute0(void)
unsigned int arity; unsigned int arity;
Prop pe; Prop pe;
if (ActiveSignals) { if (ActiveSignals || DelayedTrace) {
if (DelayedTrace) {
DelayedTrace = FALSE;
ActiveSignals |= YAP_CREEP_SIGNAL;
}
return EnterCreepMode(t, mod); return EnterCreepMode(t, mod);
} }
restart_exec: restart_exec:
@ -1517,6 +1528,7 @@ Yap_InitYaamRegs(void)
WPP = NULL; WPP = NULL;
PREG_ADDR = NULL; PREG_ADDR = NULL;
#endif #endif
DelayedTrace = FALSE;
} }

View File

@ -158,7 +158,6 @@ STATIC_PROTO (Int p_add_alias_to_stream, (void));
STATIC_PROTO (Int p_change_alias_to_stream, (void)); STATIC_PROTO (Int p_change_alias_to_stream, (void));
STATIC_PROTO (Int p_check_if_valid_new_alias, (void)); STATIC_PROTO (Int p_check_if_valid_new_alias, (void));
STATIC_PROTO (Int p_fetch_stream_alias, (void)); STATIC_PROTO (Int p_fetch_stream_alias, (void));
STATIC_PROTO (int format_print_str, (Int, Int, int, Term));
STATIC_PROTO (Int p_format, (void)); STATIC_PROTO (Int p_format, (void));
STATIC_PROTO (Int p_startline, (void)); STATIC_PROTO (Int p_startline, (void));
STATIC_PROTO (Int p_change_type_of_char, (void)); STATIC_PROTO (Int p_change_type_of_char, (void));
@ -3593,7 +3592,7 @@ static void fill_pads(int nchars)
} }
static int static int
format_print_str (Int sno, Int size, Int has_size, Term args) format_print_str (Int sno, Int size, Int has_size, Term args, int (* f_putc)(int, int))
{ {
Term arghd; Term arghd;
while (!has_size || size > 0) { while (!has_size || size > 0) {
@ -3616,7 +3615,7 @@ format_print_str (Int sno, Int size, Int has_size, Term args)
Yap_Error(TYPE_ERROR_LIST, arghd, "format/2"); Yap_Error(TYPE_ERROR_LIST, arghd, "format/2");
return FALSE; return FALSE;
} }
format_putc(sno, (int) IntOfTerm (arghd)); f_putc(sno, (int) IntOfTerm (arghd));
size--; size--;
} }
return TRUE; return TRUE;
@ -4013,7 +4012,7 @@ format(Term tail, Term args, int sno)
if (targ > tnum-1) if (targ > tnum-1)
goto do_consistency_error; goto do_consistency_error;
t = targs[targ++]; t = targs[targ++];
if (!format_print_str (sno, repeats, has_repeats, t)) { if (!format_print_str (sno, repeats, has_repeats, t, f_putc)) {
goto do_default_error; goto do_default_error;
} }
break; break;

View File

@ -1301,7 +1301,9 @@ static void
RestoreHeap(OPCODE old_ops[]) RestoreHeap(OPCODE old_ops[])
{ {
int heap_moved = (OldHeapBase != Yap_HeapBase), opcodes_moved; int heap_moved = (OldHeapBase != Yap_HeapBase), opcodes_moved;
Term mod = CurrentModule;
CurrentModule = PROLOG_MODULE;
opcodes_moved = check_opcodes(old_ops); opcodes_moved = check_opcodes(old_ops);
/* opcodes_moved has side-effects and should be tried first */ /* opcodes_moved has side-effects and should be tried first */
if (heap_moved || opcodes_moved) { if (heap_moved || opcodes_moved) {
@ -1324,6 +1326,7 @@ RestoreHeap(OPCODE old_ops[])
#ifdef DEBUG_RESTORE1 #ifdef DEBUG_RESTORE1
fprintf(errout, "phase 1 done\n"); fprintf(errout, "phase 1 done\n");
#endif #endif
CurrentModule = mod;
} }
/* /*

View File

@ -163,12 +163,42 @@ p_create_thread(void)
return FALSE; return FALSE;
} }
static Int
Yap_new_thread(void)
{
UInt ssize = IntegerOfTerm(Deref(ARG2));
UInt tsize = IntegerOfTerm(Deref(ARG3));
/* UInt systemsize = IntegerOfTerm(Deref(ARG4)); */
Term tgoal = Deref(ARG1);
Term tdetach = Deref(ARG5);
int new_worker_id = IntegerOfTerm(Deref(ARG6));
if (new_worker_id == -1) {
/* YAP ERROR */
return FALSE;
}
ThreadHandle[new_worker_id].id = new_worker_id;
store_specs(new_worker_id, ssize, tsize, tgoal, tdetach);
pthread_mutex_init(&ThreadHandle[new_worker_id].tlock, NULL);
if ((ThreadHandle[new_worker_id].ret = pthread_create(&ThreadHandle[new_worker_id].handle, NULL, thread_run, (void *)(&(ThreadHandle[new_worker_id].id)))) == 0) {
return TRUE;
}
/* YAP ERROR */
return FALSE;
}
static Int static Int
p_thread_self(void) p_thread_self(void)
{ {
return Yap_unify(MkIntegerTerm(worker_id), ARG1); return Yap_unify(MkIntegerTerm(worker_id), ARG1);
} }
int
Yap_self(void)
{
return worker_id;
}
static Int static Int
p_thread_join(void) p_thread_join(void)
{ {

View File

@ -10,7 +10,7 @@
* File: Heap.h * * File: Heap.h *
* mods: * * mods: *
* comments: Heap Init Structure * * comments: Heap Init Structure *
* version: $Id: Heap.h,v 1.62 2004-04-22 20:07:05 vsc Exp $ * * version: $Id: Heap.h,v 1.63 2004-07-15 15:47:08 vsc Exp $ *
*************************************************************************/ *************************************************************************/
/* information that can be stored in Code Space */ /* information that can be stored in Code Space */
@ -50,6 +50,7 @@ typedef struct worker_local_struct {
struct pred_entry *wpp; struct pred_entry *wpp;
#endif #endif
UInt active_signals; UInt active_signals;
UInt delayed_trace;
UInt i_pred_arity; UInt i_pred_arity;
yamop *prof_end; yamop *prof_end;
Int start_line; Int start_line;
@ -636,6 +637,7 @@ struct various_codes *heap_regs;
#define SignalLock heap_regs->wl[worker_id].signal_lock #define SignalLock heap_regs->wl[worker_id].signal_lock
#define WPP heap_regs->wl[worker_id].wpp #define WPP heap_regs->wl[worker_id].wpp
#define ActiveSignals heap_regs->wl[worker_id].active_signals #define ActiveSignals heap_regs->wl[worker_id].active_signals
#define DelayedTrace heap_regs->wl[worker_id].delayed_trace
#define IPredArity heap_regs->wl[worker_id].i_pred_arity #define IPredArity heap_regs->wl[worker_id].i_pred_arity
#define ProfEnd heap_regs->wl[worker_id].prof_end #define ProfEnd heap_regs->wl[worker_id].prof_end
#define StartLine heap_regs->wl[worker_id].start_line #define StartLine heap_regs->wl[worker_id].start_line
@ -647,6 +649,7 @@ struct various_codes *heap_regs;
#endif #endif
#else #else
#define ActiveSignals heap_regs->wl.active_signals #define ActiveSignals heap_regs->wl.active_signals
#define DelayedTrace heap_regs->wl.delayed_trace
#define IPredArity heap_regs->wl.i_pred_arity #define IPredArity heap_regs->wl.i_pred_arity
#define ProfEnd heap_regs->wl.prof_end #define ProfEnd heap_regs->wl.prof_end
#define StartLine heap_regs->wl.start_line #define StartLine heap_regs->wl.start_line

View File

@ -86,6 +86,9 @@ typedef struct _PL_extension
/* end from pl-itf.h */ /* end from pl-itf.h */
/* copied from old SICStus/SWI interface */
typedef int foreign_t;
typedef void install_t;
extern X_API PL_agc_hook_t PL_agc_hook(PL_agc_hook_t); extern X_API PL_agc_hook_t PL_agc_hook(PL_agc_hook_t);
extern X_API char* PL_atom_chars(atom_t); extern X_API char* PL_atom_chars(atom_t);

View File

@ -10,7 +10,7 @@
* File: Yap.h.m4 * * File: Yap.h.m4 *
* mods: * * mods: *
* comments: main header file for YAP * * comments: main header file for YAP *
* version: $Id: Yap.h.m4,v 1.58 2004-06-29 19:04:45 vsc Exp $ * * version: $Id: Yap.h.m4,v 1.59 2004-07-15 15:47:08 vsc Exp $ *
*************************************************************************/ *************************************************************************/
#include "config.h" #include "config.h"
@ -257,7 +257,7 @@ extern char Yap_Option[20];
#elif __APPLE__ #elif __APPLE__
#define MMAP_ADDR 0x20000000 #define MMAP_ADDR 0x20000000
#else #else
#define MMAP_ADDR 0x09000000 #define MMAP_ADDR 0x08800000
#endif #endif
#elif __svr4__ || defined(__SVR4) #elif __svr4__ || defined(__SVR4)
#define MMAP_ADDR 0x02000000 #define MMAP_ADDR 0x02000000

View File

@ -124,7 +124,7 @@ read_sig.
'$system_catch'('$do_yes_no'((G->true),user),user,Error,user:'$Error'(Error)), '$system_catch'('$do_yes_no'((G->true),user),user,Error,user:'$Error'(Error)),
fail. fail.
'$enter_top_level' :- '$enter_top_level' :-
( recorded('$trace', on, _) -> ( recorded('$trace',on,_) ->
'$format'(user_error, '% trace~n', []) '$format'(user_error, '% trace~n', [])
; ;
recorded('$debug', on, _) -> recorded('$debug', on, _) ->
@ -388,7 +388,7 @@ repeat :- '$repeat'.
'$yes_no'(G,(?-)). '$yes_no'(G,(?-)).
'$query'(G,V) :- '$query'(G,V) :-
( (
'$start_creep', ( recorded('$trace',on,_) -> '$creep' ; true),
'$execute'(G), '$execute'(G),
'$do_stop_creep', '$do_stop_creep',
'$extract_goal_vars_for_dump'(V,LIV), '$extract_goal_vars_for_dump'(V,LIV),
@ -431,16 +431,10 @@ repeat :- '$repeat'.
'$stop_creep'. '$stop_creep'.
'$start_creep' :-
( recorded('$trace', on, _) ->
'$creep'
;
true
).
'$do_yes_no'([X|L], M) :- !, '$csult'([X|L], M). '$do_yes_no'([X|L], M) :- !, '$csult'([X|L], M).
'$do_yes_no'(G, M) :- '$start_creep', '$execute'(M:G). '$do_yes_no'(G, M) :-
( recorded('$trace',on,_) -> '$creep' ; true),
'$execute'(M:G).
'$extract_goal_vars_for_dump'([],[]). '$extract_goal_vars_for_dump'([],[]).
'$extract_goal_vars_for_dump'([[_|V]|VL],[V|LIV]) :- '$extract_goal_vars_for_dump'([[_|V]|VL],[V|LIV]) :-
'$extract_goal_vars_for_dump'(VL,LIV). '$extract_goal_vars_for_dump'(VL,LIV).
@ -1071,7 +1065,7 @@ catch(G, C, A) :-
'$catch'(C,A,_), '$catch'(C,A,_),
'$execute'(G). '$execute'(G).
%
% system_catch is like catch, but it avoids the overhead of a full % system_catch is like catch, but it avoids the overhead of a full
% meta-call by calling '$execute0' instead of $execute. % meta-call by calling '$execute0' instead of $execute.
% This way it % This way it
@ -1125,7 +1119,6 @@ throw(Ball) :-
fail. fail.
'$exec_initialisation_goals'. '$exec_initialisation_goals'.
'$run_toplevel_hooks' :- '$run_toplevel_hooks' :-
get_value('$break',0), get_value('$break',0),
recorded('$toplevel_hooks',H,_), !, recorded('$toplevel_hooks',H,_), !,

View File

@ -142,11 +142,11 @@ trace :-
trace :- trace :-
recorded('$spy_skip',_,R), erase(R), fail. recorded('$spy_skip',_,R), erase(R), fail.
trace :- trace :-
'$print_message'(informational,debug(trace)),
( recordaifnot('$trace',on,_) -> true ; true), ( recordaifnot('$trace',on,_) -> true ; true),
( recordaifnot('$debug',on,_) -> true ; true), ( recordaifnot('$debug',on,_) -> true ; true),
( recordaifnot('$spy_stop',on,_) -> true ; true), ( recordaifnot('$spy_stop',on,_) -> true ; true),
'$set_yap_flags'(10,1), '$set_yap_flags'(10,1),
'$print_message'(informational,debug(trace)),
'$creep'. '$creep'.
notrace :- notrace :-
@ -257,10 +257,12 @@ debugging :-
% $spy may be called from user code, so be careful. % $spy may be called from user code, so be careful.
'$spy'([Mod|G]) :- '$spy'([Mod|G]) :-
CP is '$last_choice_pt', CP is '$last_choice_pt',
'$do_spy'(G, Mod, CP, no). '$do_spy'(G, Mod, CP, yes).
% last argument to do_spy says that we are at the end of a context. It % last argument to do_spy says that we are at the end of a context. It
% is required to know whether we are controlled by the debugger. % is required to know whether we are controlled by the debugger.
'$do_spy'(_, _, _, _) :-
'$stop_debugging', fail.
'$do_spy'(!, _, CP, _) :- !, '$cut_by'(CP). '$do_spy'(!, _, CP, _) :- !, '$cut_by'(CP).
'$do_spy'('$cut_by'(M), _, _, _) :- !, '$cut_by'(M). '$do_spy'('$cut_by'(M), _, _, _) :- !, '$cut_by'(M).
'$do_spy'(true, _, _, _) :- !. '$do_spy'(true, _, _, _) :- !.
@ -309,6 +311,8 @@ debugging :-
'$loop_spy_event'(Event, GoalNumber, G, Module, InControl)). '$loop_spy_event'(Event, GoalNumber, G, Module, InControl)).
% handle weird things happening in the debugger. % handle weird things happening in the debugger.
'$loop_spy_event'(_, _, _, _, _) :-
'$stop_debugging', fail.
'$loop_spy_event'('$retry_spy'(G0), GoalNumber, G, Module, InControl) :- '$loop_spy_event'('$retry_spy'(G0), GoalNumber, G, Module, InControl) :-
G0 >= GoalNumber, !, G0 >= GoalNumber, !,
'$loop_spy'(GoalNumber, G, Module, InControl). '$loop_spy'(GoalNumber, G, Module, InControl).
@ -395,10 +399,11 @@ debugging :-
% use the interpreter % use the interpreter
CP is '$last_choice_pt', CP is '$last_choice_pt',
'$clause'(G, M, Cl), '$clause'(G, M, Cl),
'$stop_debugging',
'$do_spy'(Cl, M, CP, InControl). '$do_spy'(Cl, M, CP, InControl).
'$spycall'(G, M, _) :- '$spycall'(G, M, InControl) :-
% I lost control here. % I lost control here.
'$continue_debugging'(no), '$continue_debugging'(InControl),
'$execute_nonstop'(G, M). '$execute_nonstop'(G, M).
@ -474,7 +479,7 @@ debugging :-
'$action'(0'e,_,_,_,_) :- !, % e exit '$action'(0'e,_,_,_,_) :- !, % e exit
'$skipeol'(0'e), '$skipeol'(0'e),
halt. halt.
'$action'(0'f,P,CallId,_,_) :- !, % f fail '$action'(0'f,_,CallId,_,_) :- !, % f fail
'$scan_number'(0'f, CallId, GoalId), '$scan_number'(0'f, CallId, GoalId),
throw('$fail_spy'(GoalId)). throw('$fail_spy'(GoalId)).
'$action'(0'h,_,_,_,_) :- !, % h help '$action'(0'h,_,_,_,_) :- !, % h help
@ -503,9 +508,9 @@ debugging :-
fail. fail.
'$action'(0'l,_,CallNumber,_,_) :- !, % l leap '$action'(0'l,_,CallNumber,_,_) :- !, % l leap
'$skipeol'(0'l), '$skipeol'(0'l),
'$set_yap_flags'(10,1),
( recorded('$spy_skip',_,R), erase(R), fail ; recorda('$spy_skip',CallNumber,_) ), ( recorded('$spy_skip',_,R), erase(R), fail ; recorda('$spy_skip',CallNumber,_) ),
( recordaifnot('$spy_stop',on,_) -> true ; true ). ( recordaifnot('$spy_stop',on,_) -> true ; true ),
'$set_yap_flags'(10,1).
'$action'(0'n,_,_,_,_) :- !, % n nodebug '$action'(0'n,_,_,_,_) :- !, % n nodebug
'$skipeol'(0'n), '$skipeol'(0'n),
'$set_yap_flags'(10,0), '$set_yap_flags'(10,0),
@ -513,9 +518,9 @@ debugging :-
nodebug. nodebug.
'$action'(0'k,_,CallNumber,_,_) :- !, % k quasi leap '$action'(0'k,_,CallNumber,_,_) :- !, % k quasi leap
'$skipeol'(0'k), '$skipeol'(0'k),
'$set_yap_flags'(10,0),
( recorded('$spy_skip',_,R), erase(R), fail ; recorda('$spy_skip',CallNumber,_) ), ( recorded('$spy_skip',_,R), erase(R), fail ; recorda('$spy_skip',CallNumber,_) ),
( recordaifnot('$spy_stop',on,_) -> true ; true ). ( recordaifnot('$spy_stop',on,_) -> true ; true ),
'$set_yap_flags'(10,0).
% skip first call (for current goal), % skip first call (for current goal),
% stop next time. % stop next time.
'$action'(0'r,P,CallId,_,_) :- !, % r retry '$action'(0'r,P,CallId,_,_) :- !, % r retry
@ -534,8 +539,8 @@ debugging :-
'$skipeol'(0't), '$skipeol'(0't),
( (P=call; P=redo) -> ( (P=call; P=redo) ->
( recorded('$spy_skip',_,R), erase(R), fail ; recorda('$spy_skip',CallNumber,_) ), ( recorded('$spy_skip',_,R), erase(R), fail ; recorda('$spy_skip',CallNumber,_) ),
'$set_yap_flags'(10,0), ( recorded('$spy_stop',_,R), erase(R), fail ; true),
( recorded('$spy_stop',_,R), erase(R), fail ; true) '$set_yap_flags'(10,0)
; ;
'$ilgl'(0't) '$ilgl'(0't)
). ).
@ -553,6 +558,9 @@ debugging :-
fail. fail.
% if we are in the interpreter, don't need to care about forcing a trace, do we? % if we are in the interpreter, don't need to care about forcing a trace, do we?
'$continue_debugging'(_) :-
recorded('$trace',on, _),
fail.
'$continue_debugging'(no) :- !. '$continue_debugging'(no) :- !.
'$continue_debugging'(_) :- '$continue_debugging'(_) :-
'$access_yap_flags'(10,1), !, '$access_yap_flags'(10,1), !,
@ -579,7 +587,8 @@ debugging :-
'$ilgl'(C) :- '$ilgl'(C) :-
'$print_message'(warning, trace_command(C)), '$print_message'(warning, trace_command(C)),
'$print_message'(help, trace_help). '$print_message'(help, trace_help),
fail.
'$skipeol'(10) :- !. '$skipeol'(10) :- !.
'$skipeol'(_) :- get0(user,C), '$skipeol'(C). '$skipeol'(_) :- get0(user,C), '$skipeol'(C).

View File

@ -69,7 +69,7 @@
'$start_creep'([Mod|G]) :- '$start_creep'([Mod|G]) :-
'$stop_debugging', '$stop_debugging',
CP is '$last_choice_pt', CP is '$last_choice_pt',
'$do_spy'(G, Mod, CP, no). '$do_spy'(G, Mod, CP, yes).
'$signal_do'(Sig, Goal) :- '$signal_do'(Sig, Goal) :-
recorded('$signal_handler', action(Sig,Goal), _), !. recorded('$signal_handler', action(Sig,Goal), _), !.