Skip to content

Commit

Permalink
kernel: rename ELM2_LIST -> ELM_MAT, etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin committed Jul 11, 2019
1 parent d5f7ab2 commit 507da64
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 126 deletions.
4 changes: 2 additions & 2 deletions src/code.c
Original file line number Diff line number Diff line change
Expand Up @@ -2365,7 +2365,7 @@ void CodeAssList ( Int narg )
if (narg == 1)
ass = NewStat( STAT_ASS_LIST, 3 * sizeof(Stat) );
else /* if (narg == 2) */
ass = NewStat( STAT_ASS2_LIST, 4 * sizeof(Stat));
ass = NewStat( STAT_ASS_MAT, 4 * sizeof(Stat));

/* let 'CodeAssListUniv' do the rest */
CodeAssListUniv( ass, narg );
Expand Down Expand Up @@ -2478,7 +2478,7 @@ void CodeElmList ( Int narg )
if (narg == 1)
ref = NewExpr( EXPR_ELM_LIST, 2 * sizeof(Expr) );
else /* if (narg == 2) */
ref = NewExpr( EXPR_ELM2_LIST, 3 * sizeof(Expr) );
ref = NewExpr( EXPR_ELM_MAT, 3 * sizeof(Expr) );

/* let 'CodeElmListUniv' to the rest */
CodeElmListUniv( ref, narg );
Expand Down
4 changes: 2 additions & 2 deletions src/code.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ enum STAT_TNUM {
STAT_UNB_GVAR,

STAT_ASS_LIST,
STAT_ASS2_LIST,
STAT_ASS_MAT,
STAT_ASSS_LIST,
STAT_ASS_LIST_LEV,
STAT_ASSS_LIST_LEV,
Expand Down Expand Up @@ -498,7 +498,7 @@ enum EXPR_TNUM {
EXPR_ISB_GVAR,

EXPR_ELM_LIST,
EXPR_ELM2_LIST,
EXPR_ELM_MAT,
EXPR_ELMS_LIST,
EXPR_ELM_LIST_LEV,
EXPR_ELMS_LIST_LEV,
Expand Down
24 changes: 12 additions & 12 deletions src/intrprtr.c
Original file line number Diff line number Diff line change
Expand Up @@ -2826,11 +2826,11 @@ void IntrAssList ( Int narg )
}
}
else if (narg == 2) {
Obj pos2 = PopObj();
Obj pos1 = PopObj();
Obj col = PopObj();
Obj row = PopObj();
list = PopObj();

ASS2_LIST(list, pos1, pos2, rhs);
ASS_MAT(list, row, col, rhs);
}

/* push the right hand side again */
Expand Down Expand Up @@ -2966,11 +2966,11 @@ void IntrUnbList ( Int narg )
}
}
else if (narg == 2) {
Obj pos2 = PopObj();
Obj pos1 = PopObj();
Obj col = PopObj();
Obj row = PopObj();
list = PopObj();

UNB2_LIST(list, pos1, pos2);
UNB_MAT(list, row, col);
}

/* push void */
Expand Down Expand Up @@ -3014,11 +3014,11 @@ void IntrElmList ( Int narg )
}
}
else /*if (narg == 2)*/ {
Obj pos2 = PopObj();
Obj pos1 = PopObj();
Obj col = PopObj();
Obj row = PopObj();
list = PopObj();

elm = ELM2_LIST(list, pos1, pos2);
elm = ELM_MAT(list, row, col);
}

/* push the element */
Expand Down Expand Up @@ -3140,11 +3140,11 @@ void IntrIsbList ( Int narg )
}
}
else /*if (narg == 2)*/ {
Obj pos2 = PopObj();
Obj pos1 = PopObj();
Obj col = PopObj();
Obj row = PopObj();
list = PopObj();

isb = ISB2_LIST(list, pos1, pos2) ? True : False;
isb = ISB_MAT(list, row, col) ? True : False;
}

/* push the result */
Expand Down
74 changes: 38 additions & 36 deletions src/lists.c
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,9 @@ Int ISBB_LIST (
return DoOperation2Args( IsbListOper, list, pos ) == True;
}

Int ISB2_LIST(Obj list, Obj pos1, Obj pos2)
Int ISB_MAT(Obj list, Obj row, Obj col)
{
return DoOperation3Args( IsbListOper, list, pos1, pos2 ) == True;
return DoOperation3Args(IsbListOper, list, row, col) == True;
}


Expand Down Expand Up @@ -500,25 +500,25 @@ Obj ELMB_LIST(Obj list, Obj pos)
return elm;
}

Obj ELM2_LIST(Obj list, Obj pos1, Obj pos2)
Obj ELM_MAT(Obj list, Obj row, Obj col)
{
if (IS_POS_INTOBJ(pos1) && IS_POS_INTOBJ(pos2) && IS_PLIST(list)) {
Int p1 = INT_INTOBJ(pos1);
if ( p1 <= LEN_PLIST(list) ) {
Obj row = ELM_PLIST( list, p1 );
Int p2 = INT_INTOBJ(pos2);
if (IS_POS_INTOBJ(row) && IS_POS_INTOBJ(col) && IS_PLIST(list)) {
Int r = INT_INTOBJ(row);
if (r <= LEN_PLIST(list)) {
Obj rowlist = ELM_PLIST(list, r);
Int c = INT_INTOBJ(col);

if ( IS_PLIST(row) && p2 <= LEN_PLIST(row) ) {
return ELM_PLIST( row, p2 );
if (IS_PLIST(rowlist) && c <= LEN_PLIST(rowlist)) {
return ELM_PLIST(rowlist, c);
}

// fallback to generic list access code (also triggers error if
// row isn't a list)
return ELM_LIST( row, p2 );
return ELM_LIST(rowlist, c);
}
}

Obj elm = DoOperation3Args( ElmListOper, list, pos1, pos2 );
Obj elm = DoOperation3Args(ElmListOper, list, row, col);
if (elm == 0) {
ErrorMayQuit("List access method must return a value", 0, 0);
}
Expand Down Expand Up @@ -800,11 +800,12 @@ void UNBB_LIST (
DoOperation2Args( UnbListOper, list, pos );
}

void UNB2_LIST(Obj list, Obj pos1, Obj pos2)
void UNB_MAT(Obj list, Obj row, Obj col)
{
DoOperation3Args( UnbListOper, list, pos1, pos2 );
DoOperation3Args(UnbListOper, list, row, col);
}


/****************************************************************************
**
*F ASS_LIST(<list>,<pos>,<obj>) . . . . . . . . assign an element to a list
Expand Down Expand Up @@ -863,25 +864,24 @@ void ASSB_LIST (
DoOperation3Args( AssListOper, list, pos, obj );
}

void ASS2_LIST(Obj mat, Obj pos1, Obj pos2, Obj obj)
void ASS_MAT(Obj mat, Obj row, Obj col, Obj obj)
{
RequireMutable("Matrix Assignment", mat, "matrix");
if (IS_POS_INTOBJ(pos1) && IS_POS_INTOBJ(pos2) && IS_PLIST(mat)) {
Int p1 = INT_INTOBJ(pos1);
if (p1 <= LEN_PLIST(mat)) {
Obj row = ELM_PLIST(mat, p1);
Int p2 = INT_INTOBJ(pos2);
if (IS_POS_INTOBJ(row) && IS_POS_INTOBJ(col) && IS_PLIST(mat)) {
Int r = INT_INTOBJ(row);
if (r <= LEN_PLIST(mat)) {
Obj rowlist = ELM_PLIST(mat, r);
Int c = INT_INTOBJ(col);

ASS_LIST( row, p2, obj );
ASS_LIST(rowlist, c, obj);
return;
}
}

DoOperation4Args(AssListOper, mat, pos1, pos2, obj);
DoOperation4Args(AssListOper, mat, row, col, obj);
}



/****************************************************************************
**
*F ASSS_LIST(<list>,<poss>,<objs>) . . . . assign several elements to a list
Expand Down Expand Up @@ -1393,10 +1393,10 @@ void ElmListLevel (
Obj list; /* one list from <lists> */
Obj elm; /* selected element from <list> */
Int i; /* loop variable */
Obj pos;
Obj pos1;
Obj pos2;
Obj pos;
Obj row;
Obj col;


/* if <level> is one, perform the replacements */
if ( level == 1 ) {
Expand All @@ -1419,10 +1419,10 @@ void ElmListLevel (
break;

case 2:
pos1 = ELM_PLIST(ixs,1);
pos2 = ELM_PLIST(ixs,2);
elm = ELM2_LIST(list, pos1, pos2);
break;
row = ELM_PLIST(ixs, 1);
col = ELM_PLIST(ixs, 2);
elm = ELM_MAT(list, row, col);
break;

default:
elm = ELMB_LIST(list, ixs);
Expand Down Expand Up @@ -1556,7 +1556,9 @@ void AssListLevel (
Obj list; /* one list of <lists> */
Obj obj; /* one value from <objs> */
Int i; /* loop variable */
Obj pos,pos1,pos2;
Obj pos;
Obj row;
Obj col;

/* check <objs> */
RequireDenseList("List Assignments", objs);
Expand Down Expand Up @@ -1586,10 +1588,10 @@ void AssListLevel (
break;

case 2:
pos1 = ELM_PLIST(ixs,1);
pos2 = ELM_PLIST(ixs,2);
ASS2_LIST(list, pos1, pos2, obj);
break;
row = ELM_PLIST(ixs, 1);
col = ELM_PLIST(ixs, 2);
ASS_MAT(list, row, col, obj);
break;

default:
ASSB_LIST(list, ixs, obj);
Expand Down
24 changes: 12 additions & 12 deletions src/lists.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ EXPORT_INLINE Int ISB_LIST(Obj list, Int pos)

Int ISBB_LIST(Obj list, Obj pos);

Int ISB2_LIST(Obj list, Obj pos1, Obj pos2);
Int ISB_MAT(Obj list, Obj row, Obj col);


/****************************************************************************
Expand Down Expand Up @@ -324,14 +324,14 @@ EXPORT_INLINE Obj ELM_LIST(Obj list, Int pos)

/****************************************************************************
**
*F ELM2_LIST( <list>, <pos1>, <pos2> ) . . . . select an element from a list
*F ELM_MAT( <list>, <row>, <col> ) . . . . select an element from a list
**
** 'ELM2_LIST' implements 'list[pos1,pos2]', which for lists of lists is
** defined as 'list[pos1][pos2]', and for other kind of objects is handled
** by method dispatch through the GAP attribute 'ELM_LIST' with three
** 'ELM_MAT' implements 'list[row,col]', which for lists of lists is
** defined as 'list[row][col]', and for other kind of objects is handled
** by method dispatch through the GAP operation 'ELM_LIST' with three
** arguments.
*/
Obj ELM2_LIST(Obj list, Obj pos1, Obj pos2);
Obj ELM_MAT(Obj list, Obj row, Obj col);


/****************************************************************************
Expand Down Expand Up @@ -481,7 +481,7 @@ EXPORT_INLINE void UNB_LIST(Obj list, Int pos)
(*UnbListFuncs[TNUM_OBJ(list)])(list, pos);
}

void UNB2_LIST(Obj list, Obj pos1, Obj pos2);
void UNB_MAT(Obj list, Obj row, Obj col);


/****************************************************************************
Expand Down Expand Up @@ -521,14 +521,14 @@ EXPORT_INLINE void ASS_LIST(Obj list, Int pos, Obj obj)

/****************************************************************************
**
*F ASS2_LIST( <list>, <pos1>, <pos2>, <obj> )
*F ASS_MAT( <mat>, <row>, <col>, <obj> )
**
** 'ASS2_LIST' implements 'list[pos1,pos2]:=obj', which for lists of lists
** is defined as 'list[pos1][pos2]:=obj', and for other kind of objects is
** handled by method dispatch through the GAP attribute 'ASS_LIST' with
** 'ASS_MAT' implements 'mat[row,col]:=obj', which for lists of lists
** is defined as 'mat[row][col]:=obj', and for other kind of objects is
** handled by method dispatch through the GAP operation 'ASS_LIST' with
** three arguments.
*/
void ASS2_LIST(Obj list, Obj pos1, Obj pos2, Obj obj);
void ASS_MAT(Obj list, Obj row, Obj col, Obj obj);


/****************************************************************************
Expand Down
4 changes: 2 additions & 2 deletions src/syntaxtree.c
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ static const CompilerT Compilers[] = {
COMPILER_(
STAT_ASS_LIST, ARG_EXPR_("list"), ARG_EXPR_("pos"), ARG_EXPR_("rhs")),
COMPILER_(
STAT_ASS2_LIST, ARG_EXPR_("list"), ARG_EXPR_("pos"), ARG_EXPR_("rhs")),
STAT_ASS_MAT, ARG_EXPR_("list"), ARG_EXPR_("row"), ARG_EXPR_("col"), ARG_EXPR_("rhs")),
COMPILER_(
STAT_ASSS_LIST, ARG_EXPR_("list"), ARG_EXPR_("poss"), ARG_EXPR_("rhss")),
COMPILER_(STAT_ASS_LIST_LEV,
Expand Down Expand Up @@ -863,7 +863,7 @@ static const CompilerT Compilers[] = {
// TODO: can this be unified?
COMPILER_(EXPR_ELM_LIST, ARG_EXPR_("list"), ARG_EXPR_("pos")),
COMPILER_(
EXPR_ELM2_LIST, ARG_EXPR_("list"), ARG_EXPR_("pos1"), ARG_EXPR_("pos2")),
EXPR_ELM_MAT, ARG_EXPR_("list"), ARG_EXPR_("row"), ARG_EXPR_("col")),
COMPILER_(EXPR_ELMS_LIST, ARG_EXPR_("list"), ARG_EXPR_("poss")),
COMPILER_(EXPR_ELM_LIST_LEV,
ARG_EXPR_("lists"),
Expand Down
Loading

0 comments on commit 507da64

Please sign in to comment.