diff --git a/doc/ref/create.xml b/doc/ref/create.xml index 7d9f116b5f..8582dc82b3 100644 --- a/doc/ref/create.xml +++ b/doc/ref/create.xml @@ -1026,7 +1026,7 @@ gap> l := [1,2,4]; gap> MakeImmutable(l); [ 1, 2, 4 ] gap> l[3] := 5; -Error, Lists Assignment: must be a mutable list +Error, List Assignment: must be a mutable list ]]>

For external objects, the situation is different. An external object which diff --git a/doc/tut/lists.xml b/doc/tut/lists.xml index e43359eb62..05cecc8971 100644 --- a/doc/tut/lists.xml +++ b/doc/tut/lists.xml @@ -342,7 +342,7 @@ gap> list[3][5] := 'w';; list; copy; [ 1, 2, "threw", [ 4 ] ] [ 1, 2, "three", [ 4 ] ] gap> copy[3][5] := 'w'; -Lists Assignment: must be a mutable list +List Assignment: must be a mutable list not in any function Entering break read-eval-print loop ... you can 'quit;' to quit to outer loop, or diff --git a/src/blister.c b/src/blister.c index 4eaa5338fc..6b488b4375 100644 --- a/src/blister.c +++ b/src/blister.c @@ -105,69 +105,39 @@ Obj TYPE_BLIST_SSORT_IMM; Obj TYPE_BLIST_EMPTY_MUT; Obj TYPE_BLIST_EMPTY_IMM; -Obj TypeBlistMut ( - Obj list ) -{ - /* special case for the empty blist */ - if ( LEN_BLIST(list) == 0 ) { - return TYPE_BLIST_EMPTY_MUT; - } else { - return TYPE_BLIST_MUT; - } -} - -Obj TypeBlistImm ( - Obj list ) -{ - /* special case for the empty blist */ - if ( LEN_BLIST(list) == 0 ) { - return TYPE_BLIST_EMPTY_IMM; - } else { - return TYPE_BLIST_IMM; - } -} - -Obj TypeBlistNSortMut ( - Obj list ) +Obj TypeBlist(Obj list) { /* special case for the empty blist */ if ( LEN_BLIST(list) == 0 ) { - return TYPE_BLIST_EMPTY_MUT; + return IS_MUTABLE_PLAIN_OBJ(list) ? TYPE_BLIST_EMPTY_MUT + : TYPE_BLIST_EMPTY_IMM; } else { - return TYPE_BLIST_NSORT_MUT; + return IS_MUTABLE_PLAIN_OBJ(list) ? TYPE_BLIST_MUT + : TYPE_BLIST_IMM; } } -Obj TypeBlistNSortImm ( - Obj list ) +Obj TypeBlistNSort(Obj list) { /* special case for the empty blist */ if ( LEN_BLIST(list) == 0 ) { - return TYPE_BLIST_EMPTY_IMM; + return IS_MUTABLE_PLAIN_OBJ(list) ? TYPE_BLIST_EMPTY_MUT + : TYPE_BLIST_EMPTY_IMM; } else { - return TYPE_BLIST_NSORT_IMM; + return IS_MUTABLE_PLAIN_OBJ(list) ? TYPE_BLIST_NSORT_MUT + : TYPE_BLIST_NSORT_IMM; } } -Obj TypeBlistSSortMut ( - Obj list ) +Obj TypeBlistSSort(Obj list) { /* special case for the empty blist */ if ( LEN_BLIST(list) == 0 ) { - return TYPE_BLIST_EMPTY_MUT; + return IS_MUTABLE_PLAIN_OBJ(list) ? TYPE_BLIST_EMPTY_MUT + : TYPE_BLIST_EMPTY_IMM; } else { - return TYPE_BLIST_SSORT_MUT; - } -} - -Obj TypeBlistSSortImm ( - Obj list ) -{ - /* special case for the empty blist */ - if ( LEN_BLIST(list) == 0 ) { - return TYPE_BLIST_EMPTY_IMM; - } else { - return TYPE_BLIST_SSORT_IMM; + return IS_MUTABLE_PLAIN_OBJ(list) ? TYPE_BLIST_SSORT_MUT + : TYPE_BLIST_SSORT_IMM; } } @@ -261,12 +231,6 @@ Obj DoCopyBlist(Obj list, Int mut) #if !defined(USE_THREADSAFE_COPYING) -Obj CopyBlistImm(Obj list, Int mut) -{ - GAP_ASSERT(!IS_MUTABLE_OBJ(list)); - return list; -} - Obj CopyBlist ( Obj list, Int mut ) @@ -274,10 +238,9 @@ Obj CopyBlist ( Obj copy; Obj tmp; - /* immutable objects should never end up here, because - * they have their own handler defined above - */ - GAP_ASSERT(IS_MUTABLE_OBJ(list)); + if (!IS_MUTABLE_OBJ(list)) { + return list; + } copy = DoCopyBlist(list, mut); /* leave a forwarding pointer */ @@ -689,22 +652,6 @@ void AssBlist ( } -/**************************************************************************** -** -*F AssBlistImm( , , ) . assign to an immutable boolean list -*/ -void AssBlistImm ( - Obj list, - Int pos, - Obj val ) -{ - ErrorReturnVoid( - "Lists Assignment: must be a mutable list", - 0L, 0L, - "you can 'return;' and ignore the assignment" ); -} - - /**************************************************************************** ** *F AsssBlist( , , ) . assign several elements to a blist @@ -738,22 +685,6 @@ void AsssBlist ( /* currently not used */ } -/**************************************************************************** -** -*F AsssBlistImm( , , ) . . assign to an immutable blist -*/ -void AsssBlistImm ( - Obj list, - Obj poss, - Obj val ) -{ - ErrorReturnVoid( - "Lists Assignments: must be a mutable list", - 0L, 0L, - "you can 'return;' and ignore the assignment" ); -} - - /**************************************************************************** ** *F PosBlist( , , ) position of an elm in a boolean list @@ -2452,12 +2383,12 @@ static Int InitKernel ( } /* install the type methods */ - TypeObjFuncs[ T_BLIST ] = TypeBlistMut; - TypeObjFuncs[ T_BLIST +IMMUTABLE ] = TypeBlistImm; - TypeObjFuncs[ T_BLIST_NSORT ] = TypeBlistNSortMut; - TypeObjFuncs[ T_BLIST_NSORT +IMMUTABLE ] = TypeBlistNSortImm; - TypeObjFuncs[ T_BLIST_SSORT ] = TypeBlistSSortMut; - TypeObjFuncs[ T_BLIST_SSORT +IMMUTABLE ] = TypeBlistSSortImm; + TypeObjFuncs[ T_BLIST ] = TypeBlist; + TypeObjFuncs[ T_BLIST +IMMUTABLE ] = TypeBlist; + TypeObjFuncs[ T_BLIST_NSORT ] = TypeBlistNSort; + TypeObjFuncs[ T_BLIST_NSORT +IMMUTABLE ] = TypeBlistNSort; + TypeObjFuncs[ T_BLIST_SSORT ] = TypeBlistSSort; + TypeObjFuncs[ T_BLIST_SSORT +IMMUTABLE ] = TypeBlistSSort; /* initialise list tables */ InitClearFiltsTNumsFromTable ( ClearFiltsTab ); @@ -2477,7 +2408,7 @@ static Int InitKernel ( for ( t1 = T_BLIST; t1 <= T_BLIST_SSORT; t1 += 2 ) { #if !defined(USE_THREADSAFE_COPYING) CopyObjFuncs [ t1 ] = CopyBlist; - CopyObjFuncs [ t1 +IMMUTABLE ] = CopyBlistImm; + CopyObjFuncs [ t1 +IMMUTABLE ] = CopyBlist; CopyObjFuncs [ t1 +COPYING ] = CopyBlistCopy; CopyObjFuncs [ t1 +IMMUTABLE +COPYING ] = CopyBlistCopy; CleanObjFuncs[ t1 ] = CleanBlist; @@ -2515,9 +2446,7 @@ static Int InitKernel ( ElmsListFuncs [ t1 ] = ElmsBlist; ElmsListFuncs [ t1 +IMMUTABLE ] = ElmsBlist; AssListFuncs [ t1 ] = AssBlist; - AssListFuncs [ t1 +IMMUTABLE ] = AssBlistImm; AsssListFuncs [ t1 ] = AsssListDefault; - AsssListFuncs [ t1 +IMMUTABLE ] = AsssBlistImm; IsDenseListFuncs[ t1 ] = AlwaysYes; IsDenseListFuncs[ t1 +IMMUTABLE ] = AlwaysYes; IsHomogListFuncs[ t1 ] = IsHomogBlist; diff --git a/src/listfunc.c b/src/listfunc.c index 2a71516d57..ab6714345b 100644 --- a/src/listfunc.c +++ b/src/listfunc.c @@ -85,7 +85,7 @@ void AddPlist3 ( if ( ! IS_MUTABLE_PLIST(list) ) { list = ErrorReturnObj( - "Lists Assignment: must be a mutable list", + "List Assignment: must be a mutable list", 0L, 0L, "you may replace via 'return ;'" ); FuncADD_LIST( 0, list, obj ); diff --git a/src/lists.c b/src/lists.c index 5c67293a34..63e8ea0549 100644 --- a/src/lists.c +++ b/src/lists.c @@ -2613,10 +2613,8 @@ static Int InitKernel ( } - /* install the generic mutability test function */ + /* install tests for being copyable */ for ( type = FIRST_LIST_TNUM; type <= LAST_LIST_TNUM; type += 2 ) { - IsMutableObjFuncs[ type ] = AlwaysYes; - IsMutableObjFuncs[ type+IMMUTABLE ] = AlwaysNo; IsCopyableObjFuncs[ type ] = AlwaysYes; IsCopyableObjFuncs[ type+IMMUTABLE ] = AlwaysYes; } diff --git a/src/lists.h b/src/lists.h index 037d0c9945..5ac690594e 100644 --- a/src/lists.h +++ b/src/lists.h @@ -18,6 +18,7 @@ #ifndef GAP_LISTS_H #define GAP_LISTS_H +#include #include /**************************************************************************** @@ -510,6 +511,12 @@ static inline void ASS_LIST(Obj list, Int pos, Obj obj) { GAP_ASSERT(pos > 0); GAP_ASSERT(obj != 0); + UInt tnum = TNUM_OBJ(list); + if (FIRST_LIST_TNUM <= tnum && tnum <= LAST_IMM_MUT_TNUM && + (tnum & IMMUTABLE)) { + ErrorReturnVoid("List Assignment: must be a mutable list", 0, + 0, "you can 'return;' and ignore the assignment"); + } (*AssListFuncs[TNUM_OBJ(list)])(list, pos, obj); } @@ -556,6 +563,12 @@ static inline void ASSS_LIST(Obj list, Obj poss, Obj objs) GAP_ASSERT(IS_POSS_LIST(poss)); GAP_ASSERT(IS_DENSE_LIST(objs)); GAP_ASSERT(LEN_LIST(poss) == LEN_LIST(objs)); + UInt tnum = TNUM_OBJ(list); + if (FIRST_LIST_TNUM <= tnum && tnum <= LAST_IMM_MUT_TNUM && + (tnum & IMMUTABLE)) { + ErrorReturnVoid("List Assignments: must be a mutable list", 0, + 0, "you can 'return;' and ignore the assignment"); + } (*AsssListFuncs[TNUM_OBJ(list)])(list, poss, objs); } diff --git a/src/objects.h b/src/objects.h index 9e8a3c236a..89852f0602 100644 --- a/src/objects.h +++ b/src/objects.h @@ -518,10 +518,33 @@ extern void CheckedMakeImmutable( Obj obj ); ** 'IS_MUTABLE_OBJ' returns 1 if the object is mutable (i.e., can ** change due to assignments), and 0 otherwise. */ -#define IS_MUTABLE_OBJ(obj) \ - ((*IsMutableObjFuncs[ TNUM_OBJ(obj) ])( obj )) - extern Int (*IsMutableObjFuncs[LAST_REAL_TNUM+1]) ( Obj obj ); +static inline Int IS_MUTABLE_OBJ(Obj obj) +{ + UInt tnum = TNUM_OBJ(obj); + if (/*FIRST_CONSTANT_TNUM <= tnum &&*/ tnum <= LAST_CONSTANT_TNUM) + return 0; + if (FIRST_IMM_MUT_TNUM <= tnum && tnum <= LAST_IMM_MUT_TNUM) + return !(tnum & IMMUTABLE); + return ((*IsMutableObjFuncs[tnum])(obj)); +} + + +/**************************************************************************** +** +*F IS_MUTABLE_PLAIN_OBJ( ) . . . . . . is an object plain and mutable +** +** 'IS_MUTABLE_PLAIN_OBJ' returns 1 if the object is a plain object +** (i.e., built into GAP), and mutable (i.e., can change due to assignments), +** and 0 otherwise. +*/ +static inline Int IS_MUTABLE_PLAIN_OBJ(Obj obj) +{ + UInt type = TNUM_OBJ(obj); + return (FIRST_IMM_MUT_TNUM <= type) && (type <= LAST_IMM_MUT_TNUM) + && !(type & IMMUTABLE); +} + /**************************************************************************** ** diff --git a/src/objset.c b/src/objset.c index f89a586725..ad1ac86851 100644 --- a/src/objset.c +++ b/src/objset.c @@ -1037,11 +1037,6 @@ static Int InitKernel ( PrintObjFuncs[ T_OBJSET+IMMUTABLE ] = PrintObjSet; PrintObjFuncs[ T_OBJMAP ] = PrintObjMap; PrintObjFuncs[ T_OBJMAP+IMMUTABLE ] = PrintObjMap; - /* install mutability functions */ - IsMutableObjFuncs [ T_OBJSET ] = AlwaysYes; - IsMutableObjFuncs [ T_OBJSET+IMMUTABLE ] = AlwaysNo; - IsMutableObjFuncs [ T_OBJMAP ] = AlwaysYes; - IsMutableObjFuncs [ T_OBJMAP+IMMUTABLE ] = AlwaysNo; #ifdef USE_THREADSAFE_COPYING SetTraversalMethod(T_OBJSET, TRAVERSE_BY_FUNCTION, TraverseObjSet, CopyObjSet); diff --git a/src/plist.c b/src/plist.c index 1c5c158dea..97df1b8eec 100644 --- a/src/plist.c +++ b/src/plist.c @@ -142,12 +142,12 @@ Int GrowPlist ( ** ** There are 10 functions entered in TypeObjFuncs: ** 1. TypePlist -** 2. TypePlistNDenseMut/Imm -** 3. TypePlistDenseMut/Imm -** 4. TypePlistDenseNHomMut/Imm -** 5. TypePlistDenseNHomSSortMut/Imm -** 6. TypePlistDenseNHomNSortMut/Imm -** 7. TypePlistEmptyMut/Imm +** 2. TypePlistNDense +** 3. TypePlistDense +** 4. TypePlistDenseNHom +** 5. TypePlistDenseNHomSSort +** 6. TypePlistDenseNHomNSort +** 7. TypePlistEmpty ** 8. TypePlistHom -- also handles Tab and RectTab ** 9. TypePlistCyc ** 10.TypePlistFfe @@ -688,65 +688,46 @@ static Obj TypePlistWithKTNum ( #endif } -Obj TypePlistNDenseMut ( - Obj list ) +Obj TypePlistNDense(Obj list) { - return TYPE_LIST_NDENSE_MUTABLE; -} - -Obj TypePlistNDenseImm ( - Obj list ) -{ - return TYPE_LIST_NDENSE_IMMUTABLE; + if (IS_MUTABLE_PLAIN_OBJ(list)) + return TYPE_LIST_NDENSE_MUTABLE; + else + return TYPE_LIST_NDENSE_IMMUTABLE; } -#define TypePlistDenseMut TypePlist -#define TypePlistDenseImm TypePlist +#define TypePlistDense TypePlist -Obj TypePlistDenseNHomMut ( - Obj list ) +Obj TypePlistDenseNHom(Obj list) { - return TYPE_LIST_DENSE_NHOM_MUTABLE; -} - -Obj TypePlistDenseNHomImm ( - Obj list ) -{ - return TYPE_LIST_DENSE_NHOM_IMMUTABLE; -} -Obj TypePlistDenseNHomSSortMut ( - Obj list ) -{ - return TYPE_LIST_DENSE_NHOM_SSORT_MUTABLE; -} - -Obj TypePlistDenseNHomSSortImm ( - Obj list ) -{ - return TYPE_LIST_DENSE_NHOM_SSORT_IMMUTABLE; -} -Obj TypePlistDenseNHomNSortMut ( - Obj list ) -{ - return TYPE_LIST_DENSE_NHOM_NSORT_MUTABLE; + if (IS_MUTABLE_PLAIN_OBJ(list)) + return TYPE_LIST_DENSE_NHOM_MUTABLE; + else + return TYPE_LIST_DENSE_NHOM_IMMUTABLE; } -Obj TypePlistDenseNHomNSortImm ( - Obj list ) +Obj TypePlistDenseNHomSSort(Obj list) { - return TYPE_LIST_DENSE_NHOM_NSORT_IMMUTABLE; + if (IS_MUTABLE_PLAIN_OBJ(list)) + return TYPE_LIST_DENSE_NHOM_SSORT_MUTABLE; + else + return TYPE_LIST_DENSE_NHOM_SSORT_IMMUTABLE; } -Obj TypePlistEmptyMut ( - Obj list ) +Obj TypePlistDenseNHomNSort(Obj list) { - return TYPE_LIST_EMPTY_MUTABLE; + if (IS_MUTABLE_PLAIN_OBJ(list)) + return TYPE_LIST_DENSE_NHOM_NSORT_MUTABLE; + else + return TYPE_LIST_DENSE_NHOM_NSORT_IMMUTABLE; } -Obj TypePlistEmptyImm ( - Obj list ) +Obj TypePlistEmpty(Obj list) { - return TYPE_LIST_EMPTY_IMMUTABLE; + if (IS_MUTABLE_PLAIN_OBJ(list)) + return TYPE_LIST_EMPTY_MUTABLE; + else + return TYPE_LIST_EMPTY_IMMUTABLE; } Obj TypePlistHom(Obj list) @@ -1897,18 +1878,6 @@ void AssPlistHomog ( } -void AssPlistImm ( - Obj list, - Int pos, - Obj val ) -{ - ErrorReturnVoid( - "Lists Assignment: must be a mutable list", - 0L, 0L, - "you can 'return;' and ignore the assignment" ); -} - - /**************************************************************************** ** *F AssPlistEmpty( , , ) . . . . . assignment to empty list @@ -2084,17 +2053,6 @@ void AsssPlistXXX ( AsssPlist( list, poss, vals ); } -void AsssPlistImm ( - Obj list, - Obj poss, - Obj val ) -{ - ErrorReturnVoid( - "Lists Assignments: must be a mutable list", - 0L, 0L, - "you can 'return;' and ignore the assignment" ); -} - /**************************************************************************** ** @@ -3753,18 +3711,18 @@ static Int InitKernel ( /* install the type methods */ TypeObjFuncs[ T_PLIST ] = TypePlist; TypeObjFuncs[ T_PLIST +IMMUTABLE ] = TypePlist; - TypeObjFuncs[ T_PLIST_NDENSE ] = TypePlistNDenseMut; - TypeObjFuncs[ T_PLIST_NDENSE +IMMUTABLE ] = TypePlistNDenseImm; - TypeObjFuncs[ T_PLIST_DENSE ] = TypePlistDenseMut; - TypeObjFuncs[ T_PLIST_DENSE +IMMUTABLE ] = TypePlistDenseImm; - TypeObjFuncs[ T_PLIST_DENSE_NHOM ] = TypePlistDenseNHomMut; - TypeObjFuncs[ T_PLIST_DENSE_NHOM +IMMUTABLE ] = TypePlistDenseNHomImm; - TypeObjFuncs[ T_PLIST_DENSE_NHOM_SSORT ] = TypePlistDenseNHomSSortMut; - TypeObjFuncs[ T_PLIST_DENSE_NHOM_SSORT+IMMUTABLE ] = TypePlistDenseNHomSSortImm; - TypeObjFuncs[ T_PLIST_DENSE_NHOM_NSORT ] = TypePlistDenseNHomNSortMut; - TypeObjFuncs[ T_PLIST_DENSE_NHOM_NSORT +IMMUTABLE ] = TypePlistDenseNHomNSortImm; - TypeObjFuncs[ T_PLIST_EMPTY ] = TypePlistEmptyMut; - TypeObjFuncs[ T_PLIST_EMPTY +IMMUTABLE ] = TypePlistEmptyImm; + TypeObjFuncs[ T_PLIST_NDENSE ] = TypePlistNDense; + TypeObjFuncs[ T_PLIST_NDENSE +IMMUTABLE ] = TypePlistNDense; + TypeObjFuncs[ T_PLIST_DENSE ] = TypePlistDense; + TypeObjFuncs[ T_PLIST_DENSE +IMMUTABLE ] = TypePlistDense; + TypeObjFuncs[ T_PLIST_DENSE_NHOM ] = TypePlistDenseNHom; + TypeObjFuncs[ T_PLIST_DENSE_NHOM +IMMUTABLE ] = TypePlistDenseNHom; + TypeObjFuncs[ T_PLIST_DENSE_NHOM_SSORT ] = TypePlistDenseNHomSSort; + TypeObjFuncs[ T_PLIST_DENSE_NHOM_SSORT +IMMUTABLE ] = TypePlistDenseNHomSSort; + TypeObjFuncs[ T_PLIST_DENSE_NHOM_NSORT ] = TypePlistDenseNHomNSort; + TypeObjFuncs[ T_PLIST_DENSE_NHOM_NSORT +IMMUTABLE ] = TypePlistDenseNHomNSort; + TypeObjFuncs[ T_PLIST_EMPTY ] = TypePlistEmpty; + TypeObjFuncs[ T_PLIST_EMPTY +IMMUTABLE ] = TypePlistEmpty; for ( t1 = T_PLIST; t1 <= LAST_PLIST_TNUM; t1 += 2 ) { SetTypeObjFuncs[ t1 ] = SetTypePlistToPosObj; @@ -3905,40 +3863,28 @@ static Int InitKernel ( /* install the list assignment methods */ AssListFuncs [ T_PLIST ] = AssPlist; - AssListFuncs [ T_PLIST+IMMUTABLE ] = AssPlistImm; AssListFuncs [ T_PLIST_NDENSE ] = AssPlistXXX; - AssListFuncs [ T_PLIST_NDENSE+IMMUTABLE ] = AssPlistImm; AssListFuncs [ T_PLIST_DENSE ] = AssPlistDense; - AssListFuncs [ T_PLIST_DENSE+IMMUTABLE ] = AssPlistImm; AssListFuncs [ T_PLIST_DENSE_NHOM ] = AssPlistDense; - AssListFuncs [ T_PLIST_DENSE_NHOM+IMMUTABLE ] = AssPlistImm; AssListFuncs [ T_PLIST_DENSE_NHOM_SSORT ] = AssPlistDense; - AssListFuncs [ T_PLIST_DENSE_NHOM_SSORT+IMMUTABLE ] = AssPlistImm; AssListFuncs [ T_PLIST_DENSE_NHOM_NSORT ] = AssPlistDense; - AssListFuncs [ T_PLIST_DENSE_NHOM_NSORT+IMMUTABLE ] = AssPlistImm; AssListFuncs [ T_PLIST_EMPTY ] = AssPlistEmpty; - AssListFuncs [ T_PLIST_EMPTY+IMMUTABLE ] = AssPlistImm; for ( t1 = T_PLIST_HOM; t1 < T_PLIST_CYC; t1 += 2 ) { AssListFuncs[ t1 ] = AssPlistHomog; - AssListFuncs[ t1+IMMUTABLE ] = AssPlistImm; } for ( t1 = T_PLIST_CYC; t1 <= T_PLIST_CYC_SSORT; t1 += 2 ) { AssListFuncs[ t1 ] = AssPlistCyc; - AssListFuncs[ t1+IMMUTABLE ] = AssPlistImm; } AssListFuncs[ T_PLIST_FFE ] = AssPlistFfe; - AssListFuncs[ T_PLIST_FFE+IMMUTABLE ] = AssPlistImm; /* install the list assignments methods */ AsssListFuncs [ T_PLIST ] = AsssPlist; - AsssListFuncs [ T_PLIST +IMMUTABLE ] = AsssPlistImm; for ( t1 = T_PLIST_NDENSE; t1 <= LAST_PLIST_TNUM; t1 += 2 ) { AsssListFuncs [ t1 ] = AsssPlistXXX; - AsssListFuncs [ t1 +IMMUTABLE ] = AsssPlistImm; } diff --git a/src/precord.c b/src/precord.c index 030c4f181e..15afac4b81 100644 --- a/src/precord.c +++ b/src/precord.c @@ -61,20 +61,11 @@ ** 'TypePRec' is the function in 'TypeObjFuncs' for plain records. */ Obj TYPE_PREC_MUTABLE; - -Obj TypePRecMut ( - Obj prec ) -{ - return TYPE_PREC_MUTABLE; -} - - Obj TYPE_PREC_IMMUTABLE; -Obj TypePRecImm ( - Obj prec ) +Obj TypePRec(Obj prec) { - return TYPE_PREC_IMMUTABLE; + return IS_MUTABLE_PLAIN_OBJ(prec) ? TYPE_PREC_MUTABLE : TYPE_PREC_IMMUTABLE; } /**************************************************************************** @@ -365,7 +356,7 @@ Obj ElmPRec ( return GET_ELM_PREC( rec, i ); else { ErrorReturnVoid( - "Record: '.%g' must have an assigned value", + "Record Element: '.%g' must have an assigned value", (Int)NAME_RNAM(rnam), 0L, "you can 'return;' after assigning a value" ); return ELM_REC( rec, rnam ); @@ -387,6 +378,14 @@ void UnbPRec ( UInt len; /* length of */ UInt i; /* loop variable */ + // Accept T_PREC and T_COMOBJ, reject T_PREC+IMMUTABLE + if (TNUM_OBJ(rec) == T_PREC+IMMUTABLE) { + ErrorReturnVoid( + "Record Unbind: must be a mutable record", + 0L, 0L, + "you can 'return;' and ignore the unbind" ); + } + if (FindPRec( rec, rnam, &i, 1 )) { /* otherwise move everything forward */ len = LEN_PREC( rec ); @@ -406,16 +405,6 @@ void UnbPRec ( return; } -void UnbPRecImm ( - Obj rec, - UInt rnam ) -{ - ErrorReturnVoid( - "Record Unbind: must be a mutable record", - 0L, 0L, - "you can 'return;' and ignore the unbind" ); -} - /**************************************************************************** ** @@ -432,6 +421,14 @@ void AssPRec ( UInt len; /* length of */ UInt i; /* loop variable */ + // Accept T_PREC and T_COMOBJ, reject T_PREC+IMMUTABLE + if (TNUM_OBJ(rec) == T_PREC+IMMUTABLE) { + ErrorReturnVoid( + "Record Assignment: must be a mutable record", + 0L, 0L, + "you can 'return;' and ignore the assignment" ); + } + /* get the length of the record */ len = LEN_PREC( rec ); @@ -453,17 +450,6 @@ void AssPRec ( CHANGED_BAG( rec ); } -void AssPRecImm ( - Obj rec, - UInt rnam, - Obj val ) -{ - ErrorReturnVoid( - "Records Assignment: must be a mutable record", - 0L, 0L, - "you can 'return;' and ignore the assignment" ); -} - /**************************************************************************** ** *F PrintPRec( ) . . . . . . . . . . . . . . . . . . . print a record @@ -911,13 +897,11 @@ static Int InitKernel ( IsbRecFuncs[ T_PREC ] = IsbPRec; IsbRecFuncs[ T_PREC +IMMUTABLE ] = IsbPRec; AssRecFuncs[ T_PREC ] = AssPRec; - AssRecFuncs[ T_PREC +IMMUTABLE ] = AssPRecImm; + AssRecFuncs[ T_PREC +IMMUTABLE ] = AssPRec; UnbRecFuncs[ T_PREC ] = UnbPRec; - UnbRecFuncs[ T_PREC +IMMUTABLE ] = UnbPRecImm; + UnbRecFuncs[ T_PREC +IMMUTABLE ] = UnbPRec; - /* install mutability test */ - IsMutableObjFuncs[ T_PREC ] = AlwaysYes; - IsMutableObjFuncs[ T_PREC +IMMUTABLE ] = AlwaysNo; + /* install tests for being copyable */ IsCopyableObjFuncs[ T_PREC ] = AlwaysYes; IsCopyableObjFuncs[ T_PREC +IMMUTABLE ] = AlwaysYes; @@ -946,8 +930,8 @@ static Int InitKernel ( ImportGVarFromLibrary( "TYPE_PREC_MUTABLE", &TYPE_PREC_MUTABLE ); ImportGVarFromLibrary( "TYPE_PREC_IMMUTABLE", &TYPE_PREC_IMMUTABLE ); - TypeObjFuncs[ T_PREC ] = TypePRecMut; - TypeObjFuncs[ T_PREC +IMMUTABLE ] = TypePRecImm; + TypeObjFuncs[ T_PREC ] = TypePRec; + TypeObjFuncs[ T_PREC +IMMUTABLE ] = TypePRec; SetTypeObjFuncs[ T_PREC ] = SetTypePRecToComObj; diff --git a/src/range.c b/src/range.c index 8652a433f3..bcdb5948f0 100644 --- a/src/range.c +++ b/src/range.c @@ -66,65 +66,38 @@ /**************************************************************************** ** -*F TypeRangeNSortImmutable( ) . . . . . . . . . . . type of a range +*F TypeRangeNSort( ) . . . . . . . . . . . . . . . . type of a range ** -** 'TypeRangeNSortMutable' is the function in 'TypeObjFuncs' for immutable -** ranges which are not strictly sorted. +** 'TypeRangeNSort' is the function in 'TypeObjFuncs' for ranges which are +** not strictly sorted. */ Obj TYPE_RANGE_NSORT_IMMUTABLE; - -Obj TypeRangeNSortImmutable ( - Obj list ) -{ - return TYPE_RANGE_NSORT_IMMUTABLE; -} - -/**************************************************************************** -** -*F TypeRangeNSortMutable( ) . . . . . . . . . . . . type of a range -** -** 'TypeRangeNSortMutable' is the function in 'TypeObjFuncs' for mutable -** ranges which are not strictly sorted. -*/ Obj TYPE_RANGE_NSORT_MUTABLE; -Obj TypeRangeNSortMutable ( - Obj list ) +Obj TypeRangeNSort(Obj list) { - return TYPE_RANGE_NSORT_MUTABLE; + return IS_MUTABLE_PLAIN_OBJ(list) ? TYPE_RANGE_NSORT_MUTABLE + : TYPE_RANGE_NSORT_IMMUTABLE; } + /**************************************************************************** ** -*F TypeRangeSSortImmutable( ) . . . . . . . . . . . type of a range +*F TypeRangeSSort( ) . . . . . . . . . . . . . . . . type of a range ** -** 'TypeRangeNSortMutable' is the function in 'TypeObjFuncs' for immutable -** ranges which are strictly sorted. +** 'TypeRangeSSort' is the function in 'TypeObjFuncs' for ranges which are +** strictly sorted. */ Obj TYPE_RANGE_SSORT_IMMUTABLE; +Obj TYPE_RANGE_SSORT_MUTABLE; -Obj TypeRangeSSortImmutable ( - Obj list ) +Obj TypeRangeSSort(Obj list) { - return TYPE_RANGE_SSORT_IMMUTABLE; + return IS_MUTABLE_PLAIN_OBJ(list) ? TYPE_RANGE_SSORT_MUTABLE + : TYPE_RANGE_SSORT_IMMUTABLE; } -/**************************************************************************** -** -*F TypeRangeSSortMutable( ) . . . . . . . . . . . . type of a range -** -** 'TypeRangeNSortMutable' is the function in 'TypeObjFuncs' for mutable -** ranges which are strictly sorted. -*/ -Obj TYPE_RANGE_SSORT_MUTABLE; - -Obj TypeRangeSSortMutable ( - Obj list ) -{ - return TYPE_RANGE_SSORT_MUTABLE; -} - #if !defined(USE_THREADSAFE_COPYING) /**************************************************************************** @@ -538,17 +511,6 @@ void AssRange ( CHANGED_BAG( list ); } -void AssRangeImm ( - Obj list, - Int pos, - Obj val ) -{ - ErrorReturnVoid( - "Lists Assignment: must be a mutable list", - 0L, 0L, - "you can 'return;' and ignore the assignment" ); -} - /**************************************************************************** ** @@ -579,17 +541,6 @@ void AsssRange ( ASSS_LIST( list, poss, vals ); } -void AsssRangeImm ( - Obj list, - Obj poss, - Obj val ) -{ - ErrorReturnVoid( - "Lists Assignments: must be a mutable list", - 0L, 0L, - "you can 'return;' and ignore the assignment" ); -} - /**************************************************************************** ** @@ -1304,10 +1255,10 @@ static Int InitKernel ( ImportGVarFromLibrary( "TYPE_RANGE_SSORT_IMMUTABLE", &TYPE_RANGE_SSORT_IMMUTABLE ); - TypeObjFuncs[ T_RANGE_NSORT ] = TypeRangeNSortMutable; - TypeObjFuncs[ T_RANGE_NSORT +IMMUTABLE ] = TypeRangeNSortImmutable; - TypeObjFuncs[ T_RANGE_SSORT ] = TypeRangeSSortMutable; - TypeObjFuncs[ T_RANGE_SSORT +IMMUTABLE ] = TypeRangeSSortImmutable; + TypeObjFuncs[ T_RANGE_NSORT ] = TypeRangeNSort; + TypeObjFuncs[ T_RANGE_NSORT +IMMUTABLE ] = TypeRangeNSort; + TypeObjFuncs[ T_RANGE_SSORT ] = TypeRangeSSort; + TypeObjFuncs[ T_RANGE_SSORT +IMMUTABLE ] = TypeRangeSSort; /* init filters and functions */ InitHdlrFiltsFromTable( GVarFilts ); @@ -1403,13 +1354,9 @@ static Int InitKernel ( ElmsListFuncs [ T_RANGE_SSORT ] = ElmsRange; ElmsListFuncs [ T_RANGE_SSORT +IMMUTABLE ] = ElmsRange; AssListFuncs [ T_RANGE_NSORT ] = AssRange; - AssListFuncs [ T_RANGE_NSORT +IMMUTABLE ] = AssRangeImm; AssListFuncs [ T_RANGE_SSORT ] = AssRange; - AssListFuncs [ T_RANGE_SSORT +IMMUTABLE ] = AssRangeImm; AsssListFuncs [ T_RANGE_NSORT ] = AsssRange; - AsssListFuncs [ T_RANGE_NSORT +IMMUTABLE ] = AsssRangeImm; AsssListFuncs [ T_RANGE_SSORT ] = AsssRange; - AsssListFuncs [ T_RANGE_SSORT +IMMUTABLE ] = AsssRangeImm; IsDenseListFuncs[ T_RANGE_NSORT ] = AlwaysYes; IsDenseListFuncs[ T_RANGE_NSORT +IMMUTABLE ] = AlwaysYes; IsDenseListFuncs[ T_RANGE_SSORT ] = AlwaysYes; diff --git a/src/records.c b/src/records.c index dd9f90bc62..bb5dd61c10 100644 --- a/src/records.c +++ b/src/records.c @@ -414,7 +414,7 @@ Int IsbRecError ( UInt rnam ) { rec = ErrorReturnObj( - "IsBound: must be a record (not a %s)", + "Record IsBound: must be a record (not a %s)", (Int)TNAM_OBJ(rec), 0L, "you can replace via 'return ;'" ); return ISB_REC( rec, rnam ); @@ -509,7 +509,7 @@ void UnbRecError ( UInt rnam ) { rec = ErrorReturnObj( - "Unbind: must be a record (not a %s)", + "Record Unbind: must be a record (not a %s)", (Int)TNAM_OBJ(rec), 0L, "you can replace via 'return ;'" ); UNB_REC( rec, rnam ); diff --git a/src/stringobj.c b/src/stringobj.c index a1a8c7ffcc..9a052c3a87 100644 --- a/src/stringobj.c +++ b/src/stringobj.c @@ -1072,17 +1072,6 @@ void AssString ( } } -void AssStringImm ( - Obj list, - Int pos, - Obj val ) -{ - ErrorReturnVoid( - "Lists Assignment: must be a mutable list", - 0L, 0L, - "you can 'return;' and ignore the assignment" ); -} - /**************************************************************************** ** @@ -1111,17 +1100,6 @@ void AsssString ( } } -void AsssStringImm ( - Obj list, - Obj poss, - Obj val ) -{ - ErrorReturnVoid( - "Lists Assignments: must be a mutable list", - 0L, 0L, - "you can 'return;' and ignore the assignment" ); -} - /**************************************************************************** ** @@ -2402,9 +2380,7 @@ static Int InitKernel ( ElmsListFuncs [ t1 ] = ElmsString; ElmsListFuncs [ t1 +IMMUTABLE ] = ElmsString; AssListFuncs [ t1 ] = AssString; - AssListFuncs [ t1 +IMMUTABLE ] = AssStringImm; AsssListFuncs [ t1 ] = AsssString; - AsssListFuncs [ t1 +IMMUTABLE ] = AsssStringImm; IsDenseListFuncs[ t1 ] = AlwaysYes; IsDenseListFuncs[ t1 +IMMUTABLE ] = AlwaysYes; IsHomogListFuncs[ t1 ] = IsHomogString; diff --git a/src/vec8bit.c b/src/vec8bit.c index a1f4be4394..b0dc7e80ee 100644 --- a/src/vec8bit.c +++ b/src/vec8bit.c @@ -2971,7 +2971,7 @@ Obj FuncASS_VEC8BIT ( /* check that is mutable */ if (! IS_MUTABLE_OBJ(list)) { ErrorReturnVoid( - "Lists Assignment: must be a mutable list", + "List Assignment: must be a mutable list", 0L, 0L, "you can 'return;' and ignore the assignment"); return 0; @@ -3081,9 +3081,9 @@ Obj FuncUNB_VEC8BIT ( /* check that is mutable */ if (! IS_MUTABLE_OBJ(list)) { ErrorReturnVoid( - "Lists Assignment: must be a mutable list", + "List Unbind: must be a mutable list", 0L, 0L, - "you can 'return;' and ignore the assignment"); + "you can 'return;' and ignore the unbind"); return 0; } if (True == DoFilter(IsLockedRepresentationVector, list)) { diff --git a/src/vecgf2.c b/src/vecgf2.c index 947607215d..cb5935f86b 100644 --- a/src/vecgf2.c +++ b/src/vecgf2.c @@ -1933,7 +1933,7 @@ Obj FuncASS_GF2VEC ( /* check that is mutable */ if ( ! IS_MUTABLE_OBJ(list) ) { ErrorReturnVoid( - "Lists Assignment: must be a mutable list", + "List Assignment: must be a mutable list", 0L, 0L, "you can 'return;' and ignore the assignment" ); return 0; @@ -2016,7 +2016,7 @@ Obj FuncASS_GF2MAT ( /* check that is mutable */ if ( ! IS_MUTABLE_OBJ(list) ) { ErrorReturnVoid( - "Lists Assignment: must be a mutable list", + "List Assignment: must be a mutable list", 0L, 0L, "you can 'return;' and ignore the assignment" ); return 0; @@ -2098,9 +2098,9 @@ Obj FuncUNB_GF2VEC ( /* check that is mutable */ if ( ! IS_MUTABLE_OBJ(list) ) { ErrorReturnVoid( - "Unbind: must be a mutable list", + "List Unbind: must be a mutable list", 0L, 0L, - "you can 'return;' and ignore the operation" ); + "you can 'return;' and ignore the unbind" ); return 0; } @@ -2153,9 +2153,9 @@ Obj FuncUNB_GF2MAT ( /* check that is mutable */ if ( ! IS_MUTABLE_OBJ(list) ) { ErrorReturnVoid( - "Lists Assignment: must be a mutable list", + "List Unbind: must be a mutable list", 0L, 0L, - "you can 'return;' and ignore the assignment" ); + "you can 'return;' and ignore the unbind" ); return 0; } diff --git a/tst/testinstall/function.tst b/tst/testinstall/function.tst index 8be2e83cb7..3d45d0b231 100644 --- a/tst/testinstall/function.tst +++ b/tst/testinstall/function.tst @@ -91,7 +91,7 @@ gap> Info(InfoWarning, 1000, f()); gap> r.(f()); Error, Function call: must return a value gap> r.(g()); -Error, Record: '.2' must have an assigned value +Error, Record Element: '.2' must have an assigned value gap> (function() end)(); gap> (function() return 2; end)(); 2 diff --git a/tst/testinstall/listindex.tst b/tst/testinstall/listindex.tst index b3eb1ef52a..37641c8e7a 100644 --- a/tst/testinstall/listindex.tst +++ b/tst/testinstall/listindex.tst @@ -272,7 +272,7 @@ gap> l[2,1]; Error, List Element: [2] must have an assigned value gap> MakeImmutable(l[1]);; gap> l[1,1] := 2;; -Error, Lists Assignment: must be a mutable list +Error, List Assignment: must be a mutable list gap> l; [ [ 3, 4 ] ] diff --git a/tst/testinstall/matblock.tst b/tst/testinstall/matblock.tst index c4319dbd05..ce1b9f115d 100644 --- a/tst/testinstall/matblock.tst +++ b/tst/testinstall/matblock.tst @@ -34,7 +34,7 @@ gap> Length( z ); DimensionsMat( z ); gap> m1[3]; [ 0, 0, 0, 1, 0, 0, 0, 0 ] gap> m1[3][4] := 4; -Error, Lists Assignment: must be a mutable list +Error, List Assignment: must be a mutable list gap> m1[3]; [ 0, 0, 0, 1, 0, 0, 0, 0 ] gap> z[2]; diff --git a/tst/testinstall/range.tst b/tst/testinstall/range.tst index 11a0e13b3c..460569d67a 100644 --- a/tst/testinstall/range.tst +++ b/tst/testinstall/range.tst @@ -80,7 +80,7 @@ Error, List Elements: [7] must have an assigned value gap> [-5,-3..5]{[1..6]}; [ -5, -3 .. 5 ] gap> Immutable([-5,-3..5])[3] := 2; -Error, Lists Assignment: must be a mutable list +Error, List Assignment: must be a mutable list gap> x := [-5,-3..5]; [ -5, -3 .. 5 ] gap> x[2] := 7; @@ -88,7 +88,7 @@ gap> x[2] := 7; gap> x; [ -5, 7, -1, 1, 3, 5 ] gap> Immutable([-5,-3..5]){[2,4]} := [2..3]; -Error, Lists Assignments: must be a mutable list +Error, List Assignments: must be a mutable list gap> x := [-5,-3..5]; [ -5, -3 .. 5 ] gap> x{[2,5,3]}; @@ -100,7 +100,7 @@ gap> x; gap> x{[2,4]} := [2..4]; Error, List Assignment: must have the same length as (2) gap> Immutable([-5,-3..5]){[2..3]} := [2..3]; -Error, Lists Assignments: must be a mutable list +Error, List Assignments: must be a mutable list gap> x := [-5,-3..5]; [ -5, -3 .. 5 ] gap> x{[2..3]}; diff --git a/tst/testinstall/recordname.tst b/tst/testinstall/recordname.tst index 9de95cff74..2a83884e0f 100644 --- a/tst/testinstall/recordname.tst +++ b/tst/testinstall/recordname.tst @@ -10,9 +10,9 @@ rec( x := 2 ) gap> Unbind(x.x); Error, Record Unbind: must be a mutable record gap> x.y := 2; -Error, Records Assignment: must be a mutable record +Error, Record Assignment: must be a mutable record gap> x.x := 2; -Error, Records Assignment: must be a mutable record +Error, Record Assignment: must be a mutable record gap> r := rec(x := 2, y := 3); rec( x := 2, y := 3 ) gap> r.x;