Skip to content

Commit

Permalink
new linedit completion using new map implementation
Browse files Browse the repository at this point in the history
important when loading (consult) large files with a lot of atoms (put in the completion table)
new files: completion.c and completion.h
  • Loading branch information
didoudiaz committed Apr 21, 2023
1 parent 5c18ace commit 7adebe2
Show file tree
Hide file tree
Showing 26 changed files with 1,673 additions and 908 deletions.
481 changes: 246 additions & 235 deletions ChangeLog

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
Change in GNU Prolog version 1.6.0

* fix issue #32: remove duplicate warning message
* improve consult speed on large Prolog data bases
(use new map implementation to improve the linedit completion: new file completion.c)
* improve compiler speed on large Prolog data bases
(speed up generation of indexing instructions switch_on_atom/integer/structure)
(use new map implementation (based on red-black trees) for wam2ma and ma2asm)
* speed up bind_variables/2 (also speed up the compiler for byte-code)
* increase max vars in a term to 2^20 (MAX_VAR_IN_TERM)
* increase default Prolog stack sizes and MAX_ATOMS
Expand Down
32 changes: 13 additions & 19 deletions src/BipsPl/le_interf_c.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
* Global Variables *
*---------------------------------*/

static ComplMatch compl_match;

/*---------------------------------*
* Function Prototypes *
*---------------------------------*/
Expand Down Expand Up @@ -133,26 +135,22 @@ Pl_Add_Linedit_Completion_1(WamWord compl_word)
Bool
Pl_Find_Linedit_Completion_2(WamWord prefix_word, WamWord compl_word)
{
char *prefix = Pl_Rd_String_Check(prefix_word);
int nb_match, max_lg, is_last;
char *compl;
int prefix_atom = Pl_Rd_Atom_Check(prefix_word);
char *prefix = pl_atom_tbl[prefix_atom].name;
int prefix_length = pl_atom_tbl[prefix_atom].prop.length;

Pl_Check_For_Un_Atom(compl_word);

if (Pl_LE_Compl_Init_Match(prefix, &nb_match, &max_lg) == NULL)
if (!Pl_LE_Compl_Match_First(&compl_match, prefix, prefix_length))
return FALSE;

compl = Pl_LE_Compl_Find_Match(&is_last);

if (!is_last) /* non deterministic case */
if (compl_match.nb_match > 1) /* non deterministic case */
{
A(0) = compl_word;
Pl_Create_Choice_Point((CodePtr)
Prolog_Predicate(FIND_LINEDIT_COMPLETION_ALT, 0),
1);
Pl_Create_Choice_Point((CodePtr) Prolog_Predicate(FIND_LINEDIT_COMPLETION_ALT, 0), 1);
}

return Pl_Get_Atom(Pl_Create_Atom(compl), compl_word);
return Pl_Get_Atom(Pl_Create_Atom(compl_match.cur_word), compl_word);
}


Expand All @@ -166,18 +164,14 @@ Bool
Pl_Find_Linedit_Completion_Alt_0(void)
{
WamWord compl_word;
int is_last;
char *compl;

Pl_Update_Choice_Point((CodePtr)
Prolog_Predicate(FIND_LINEDIT_COMPLETION_ALT, 0), 0);

Pl_Update_Choice_Point((CodePtr) Prolog_Predicate(FIND_LINEDIT_COMPLETION_ALT, 0), 0);
compl_word = AB(B, 0);

compl = Pl_LE_Compl_Find_Match(&is_last);
Pl_LE_Compl_Match_Next(&compl_match);

if (is_last)
if (compl_match.cur_no >= compl_match.nb_match - 1)
Delete_Last_Choice_Point();

return Pl_Get_Atom(Pl_Create_Atom(compl), compl_word);
return Pl_Get_Atom(Pl_Create_Atom(compl_match.cur_word), compl_word);
}
26 changes: 9 additions & 17 deletions src/BipsPl/t.pl
Original file line number Diff line number Diff line change
Expand Up @@ -213,24 +213,8 @@
*/




/*
lgt_current_output(S) :-
current_output(S), !.
lgt_current_output(S) :-
current_stream(S), !,
fail.
lgt_current_output(S) :-
set_bip_name(current_output, 1),
'$pl_err_existence'(stream, S).
*/


:- multifile(p/0).
:- dynamic(p/0).
Expand All @@ -239,8 +223,11 @@
%:- initialization((trace, p)).
%foo:-write(a),write(b),nl.
*/
%foo:-write(a),write(b),nl. % %

/*
test(Goal) :-
open('/tmp/foo.out', write, Stream),
set_output(Stream),
Expand Down Expand Up @@ -325,3 +312,8 @@
m :-
exec(ls, null, user_output, null).
*/

:- multifile(p/0).

p.
3 changes: 2 additions & 1 deletion src/BipsPl/top_level_c.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ Pl_Set_Ctrl_C_Handler_0(void)




/*-------------------------------------------------------------------------*
* CTRL_C_MANAGER *
* PL_SAVE_REGS_FOR_SIGNAL *
* *
*-------------------------------------------------------------------------*/
void
Expand Down
8 changes: 4 additions & 4 deletions src/EnginePl/engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,17 +198,17 @@ Pl_Start_Prolog(int argc, char *argv[])
/* must be changed to store global info (see the debugger) */
heap_actual_start = Global_Stack;

Pl_Init_Atom();
Pl_Init_Pred();
Pl_Init_Oper();

pl_le_mode = 0; /* not compiled with linedit or deactivated (using env var) */

#ifndef NO_USE_LINEDIT
if (pl_le_initialize != NULL)
pl_le_mode = (*pl_le_initialize)();
#endif

Pl_Init_Atom();
Pl_Init_Pred();
Pl_Init_Oper();

if (copy_of_pl_init_stream_supp)
(*copy_of_pl_init_stream_supp)();

Expand Down
1 change: 1 addition & 0 deletions src/Linedit/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ lccmake
makefile.lcc
test_linedit
test_noecho
completion



Expand Down
7 changes: 6 additions & 1 deletion src/Linedit/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ AR_RC = @AR_RC@
RANLIB = @RANLIB@

LIBNAME = $(LIB_LINEDIT)
OBJLIB = linedit@OBJ_SUFFIX@ terminal@OBJ_SUFFIX@ ctrl_c@OBJ_SUFFIX@
OBJLIB = linedit@OBJ_SUFFIX@ terminal@OBJ_SUFFIX@ ctrl_c@OBJ_SUFFIX@ completion@OBJ_SUFFIX@ ../Tools/rbtree@OBJ_SUFFIX@

.SUFFIXES:
.SUFFIXES: @OBJ_SUFFIX@ .c $(SUFFIXES)
Expand All @@ -28,6 +28,11 @@ terminal@OBJ_SUFFIX@: terminal.h

linedit@OBJ_SUFFIX@: linedit.h terminal.h ctrl_c.h

completion@OBJ_SUFFIX@: completion.h ../Tools/map_rbtree.h

../Tools/rbtree@OBJ_SUFFIX@:
(cd ../Tools; $(MAKE))


clean:
rm -f *@OBJ_SUFFIX@ *.ilk *.pdb *.pch *.idb *.exp $(LIBNAME)
Expand Down
Loading

0 comments on commit 7adebe2

Please sign in to comment.