Skip to content

Commit

Permalink
Tack location of InstallImmediateMethod
Browse files Browse the repository at this point in the history
Before:

    gap> TraceImmediateMethods( );
    gap> g:= Group( (1,2,3), (1,2) );;
    #I  immediate: Size
    #I  immediate: IsCyclic
    #I  immediate: IsCommutative
    #I  immediate: IsTrivial
    gap>
    gap> M0:=Magma(FamilyObj([1]), []);;
    gap> AsSSortedList(M0);
    #I  immediate: RepresentativeSmallest
    #I  immediate: AsList
    #I  immediate: EnumeratorSorted
    #I  immediate: GeneratorsOfDomain
    #I  immediate: Size
    #I  immediate: RepresentativeSmallest
    #I  immediate: IsFinite
    #I  immediate: IsTrivial
    #I  immediate: IsEmpty
    #I  immediate: IsNonTrivial
    #I  immediate: Size
    #I  immediate: RepresentativeSmallest
    [  ]

After (note how e.g. the entry for EnumeratorSorted points at
coll.gi:379, and not at the location where the method function
was defined):

    gap> TraceImmediateMethods( );
    gap> g:= Group( (1,2,3), (1,2) );;
    #I RunImmediateMethods
    #I  immediate: Size at GAPROOT/lib/coll.gi:179
    #I  immediate: IsCyclic at GAPROOT/lib/grp.gi:40
    #I  immediate: IsCommutative at GAPROOT/lib/magma.gi:196
    #I  immediate: IsTrivial at GAPROOT/lib/magma.gi:130
    gap>
    gap> M0:=Magma(FamilyObj([1]), []);;
    #I RunImmediateMethods
    #I RunImmediateMethods
    gap> AsSSortedList(M0);
    #I RunImmediateMethods
    #I  immediate: RepresentativeSmallest at GAPROOT/lib/coll.gi:226
    #I  immediate: AsList at GAPROOT/lib/domain.gi:206
    #I  immediate: EnumeratorSorted at GAPROOT/lib/coll.gi:379
    #I  immediate: GeneratorsOfDomain at GAPROOT/lib/domain.gi:181
    #I  immediate: Size at GAPROOT/lib/coll.gi:183
    #I  immediate: RepresentativeSmallest at GAPROOT/lib/coll.gi:215
    #I  immediate: IsFinite at GAPROOT/lib/coll.gi:148
    #I  immediate: IsTrivial at GAPROOT/lib/coll.gi:116
    #I  immediate: IsEmpty at GAPROOT/lib/coll.gi:97
    #I  immediate: IsNonTrivial at GAPROOT/lib/coll.gi:134
    #I RunImmediateMethods
    #I  immediate: Size at GAPROOT/lib/coll.gi:179
    #I RunImmediateMethods
    #I  immediate: RepresentativeSmallest at GAPROOT/lib/coll.gi:215
    [  ]
  • Loading branch information
fingolfin committed Apr 23, 2018
1 parent ecb5760 commit feb533d
Show file tree
Hide file tree
Showing 8 changed files with 329 additions and 204 deletions.
239 changes: 144 additions & 95 deletions hpcgap/src/c_oper1.c

Large diffs are not rendered by default.

15 changes: 10 additions & 5 deletions lib/oper.g
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ IGNORE_IMMEDIATE_METHODS := false;
## </Description>
## </ManSection>
##
BIND_CONSTANT("SIZE_IMMEDIATE_METHOD_ENTRY", 8);
BIND_GLOBAL( "INSTALL_IMMEDIATE_METHOD",
function( oper, info, filter, rank, method )

Expand Down Expand Up @@ -377,7 +378,7 @@ BIND_GLOBAL( "INSTALL_IMMEDIATE_METHOD",
fi;
i := 0;
while i < LEN_LIST(imm) and rank < imm[i+5] do
i := i + 7;
i := i + SIZE_IMMEDIATE_METHOD_ENTRY;
od;

# Now is a good time to see if the method is already there
Expand All @@ -391,13 +392,13 @@ BIND_GLOBAL( "INSTALL_IMMEDIATE_METHOD",
i := k;
break;
fi;
k := k+7;
k := k+SIZE_IMMEDIATE_METHOD_ENTRY;
od;
fi;

# push the other functions back
if not REREADING or not replace then
imm{[i+8..7+LEN_LIST(imm)]} := imm{[i+1..LEN_LIST(imm)]};
imm{[SIZE_IMMEDIATE_METHOD_ENTRY+i+1..SIZE_IMMEDIATE_METHOD_ENTRY+LEN_LIST(imm)]} := imm{[i+1..LEN_LIST(imm)]};
fi;

# install the new method
Expand All @@ -408,6 +409,9 @@ BIND_GLOBAL( "INSTALL_IMMEDIATE_METHOD",
imm[i+5] := rank;
imm[i+6] := pos;
imm[i+7] := IMMUTABLE_COPY_OBJ(info);
if SIZE_IMMEDIATE_METHOD_ENTRY >= 8 then
imm[i+8] := MakeImmutable([INPUT_FILENAME(), INPUT_LINENUMBER()]);
fi;

if IsHPCGAP then
IMMEDIATES[j]:=MakeImmutable(imm);
Expand Down Expand Up @@ -553,9 +557,10 @@ end );
## <Ref Func="UntraceImmediateMethods"/>, or <Ref Func="TraceImmediateMethods"/>
## with <A>flag</A> equal <K>false</K> turns tracing off.
## (There is no facility to trace <E>specific</E> immediate methods.)
## <Example><![CDATA[
## <Log><![CDATA[
## gap> TraceImmediateMethods( );
## gap> g:= Group( (1,2,3), (1,2) );;
## #I RunImmediateMethods
## #I immediate: Size
## #I immediate: IsCyclic
## #I immediate: IsCommutative
Expand All @@ -573,7 +578,7 @@ end );
## 6
## gap> UntraceImmediateMethods( );
## gap> UntraceMethods( [ Size ] );
## ]]></Example>
## ]]></Log>
## <P/>
## This example gives an explanation for the two calls of the
## <Q>system getter</Q> for <Ref Func="Size"/>.
Expand Down
21 changes: 15 additions & 6 deletions lib/oper1.g
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
## have been discovered recently.
## So possible consequences of other filters are not checked.
##
RUN_IMMEDIATE_METHODS_RUNS := 0;
RUN_IMMEDIATE_METHODS_CHECKS := 0;
RUN_IMMEDIATE_METHODS_HITS := 0;

Expand All @@ -31,7 +32,9 @@ BIND_GLOBAL( "RunImmediateMethods", function ( obj, flags )
j, # loop over `flagspos'
imm, # immediate methods for filter `j'
i, # loop over `imm'
meth,
res, # result of an immediate method
loc,
newflags; # newly found filters

# Avoid recursive calls from inside a setter,
Expand All @@ -49,6 +52,11 @@ BIND_GLOBAL( "RunImmediateMethods", function ( obj, flags )
type := TYPE_OBJ( obj );
flags := type![2];

RUN_IMMEDIATE_METHODS_RUNS := RUN_IMMEDIATE_METHODS_RUNS + 1;
if TRACE_IMMEDIATE_METHODS then
Print( "#I RunImmediateMethods\n");
fi;

# Check the immediate methods for all in `flagspos'.
# (Note that new information is handled via appending to that list.)
for j in flagspos do
Expand All @@ -63,24 +71,25 @@ BIND_GLOBAL( "RunImmediateMethods", function ( obj, flags )
if IsBound( IMMEDIATES[j] ) then
#T the `if' statement can disappear when `IMM_FLAGS' is improved ...
imm := IMMEDIATES[j];
for i in [ 0, 7 .. LEN_LIST(imm)-7 ] do
for i in [ 0, SIZE_IMMEDIATE_METHOD_ENTRY .. LEN_LIST(imm)-SIZE_IMMEDIATE_METHOD_ENTRY ] do

if IS_SUBSET_FLAGS( flags, imm[i+4] )
and not IS_SUBSET_FLAGS( flags, imm[i+3] )
and not imm[i+6] in tried
then

# Call the method, and store that it was used.
res := IMMEDIATE_METHODS[ imm[i+6] ]( obj );
meth := IMMEDIATE_METHODS[ imm[i+6] ];
res := meth( obj );
ADD_LIST( tried, imm[i+6] );
RUN_IMMEDIATE_METHODS_CHECKS :=
RUN_IMMEDIATE_METHODS_CHECKS+1;
if TRACE_IMMEDIATE_METHODS then
if imm[i+7] = false then
Print( "#I immediate: ", NAME_FUNC( imm[i+1] ), "\n");
else
Print( "#I immediate: ", NAME_FUNC( imm[i+1] ), ": ", imm[i+7], "\n" );
Print( "#I immediate: ", NAME_FUNC( imm[i+1] ));
if imm[i+7] <> false then
Print( ": ", imm[i+7] );
fi;
Print(" at ", imm[i+8][1], ":", imm[i+8][2], "\n");
fi;

if res <> TRY_NEXT_METHOD then
Expand Down
Loading

0 comments on commit feb533d

Please sign in to comment.