Skip to content

Commit

Permalink
kernel: add {Ass,Elm,Isb,Unb}PosObj helpers
Browse files Browse the repository at this point in the history
Note the `MEMBAR_READ` call in `ElmPosObj` which is "essential" according
to a comment: this call was previously only present in the interpreter,
but missing in the executor.

Also, the code generated by the GAP compiler was more or less completely
broken in HPC-GAP, and lacked input validation in `C_ELM_POSOBJ`, which
`ElmPosObj` now provides "for free".
  • Loading branch information
fingolfin committed Oct 8, 2018
1 parent 35e4193 commit 44f1a0c
Show file tree
Hide file tree
Showing 13 changed files with 233 additions and 521 deletions.
6 changes: 2 additions & 4 deletions lib/compiler.g
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@ end );
## "FastPlainLists"
## "CheckTypes"
## "CheckListElements"
## "CheckPosObjElements"
##
CompileFunc := function( arg )
local output, func, name, arguments;
Expand All @@ -262,16 +261,15 @@ CompileFunc := function( arg )
fastintarith := "switch/true",
fastplainlists := "switch/true",
checktypes := "switch/true",
checklistelements := "switch/true",
checkposobjelements := "switch/true" );
checklistelements := "switch/true" );

arguments := ParseArguments( arguments, arg, 4 );

return COMPILE_FUNC(
output, func, name,
arguments.magic1, arguments.magic2, arguments.fastintarith,
arguments.fastplainlists, arguments.checktypes,
arguments.checklistelements, arguments.checkposobjelements );
arguments.checklistelements );

end;

Expand Down
6 changes: 3 additions & 3 deletions src/c_oper1.c
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ static Obj HdlrFunc2 (
l_type = t_1;

/* flags := type![2]; */
C_ELM_POSOBJ_NLE( t_1, l_type, 2 );
t_1 = ElmPosObj( l_type, 2 );
a_flags = t_1;

/* RUN_IMMEDIATE_METHODS_RUNS := RUN_IMMEDIATE_METHODS_RUNS + 1; */
Expand Down Expand Up @@ -543,7 +543,7 @@ static Obj HdlrFunc2 (

/* newflags := SUB_FLAGS( type![2], IMM_FLAGS ); */
t_10 = GF_SUB__FLAGS;
C_ELM_POSOBJ_NLE( t_11, l_type, 2 );
t_11 = ElmPosObj( l_type, 2 );
t_12 = GC_IMM__FLAGS;
CHECK_BOUND( t_12, "IMM_FLAGS" )
t_9 = CALL_2ARGS( t_10, t_11, t_12 );
Expand All @@ -564,7 +564,7 @@ static Obj HdlrFunc2 (
CALL_2ARGS( t_9, l_flagspos, t_10 );

/* flags := type![2]; */
C_ELM_POSOBJ_NLE( t_9, l_type, 2 );
t_9 = ElmPosObj( l_type, 2 );
a_flags = t_9;

}
Expand Down
128 changes: 34 additions & 94 deletions src/c_type1.c
Original file line number Diff line number Diff line change
Expand Up @@ -918,20 +918,20 @@ static Obj HdlrFunc11 (

/* if IS_EQUAL_FLAGS( flags, cached![2] ) then */
t_3 = GF_IS__EQUAL__FLAGS;
C_ELM_POSOBJ_NLE( t_4, l_cached, 2 );
t_4 = ElmPosObj( l_cached, 2 );
t_2 = CALL_2ARGS( t_3, a_flags, t_4 );
CHECK_FUNC_RESULT( t_2 )
CHECK_BOOL( t_2 )
t_1 = (Obj)(UInt)(t_2 != False);
if ( t_1 ) {

/* flags := cached![2]; */
C_ELM_POSOBJ_NLE( t_1, l_cached, 2 );
t_1 = ElmPosObj( l_cached, 2 );
a_flags = t_1;

/* if IS_IDENTICAL_OBJ( data, cached![3] ) and IS_IDENTICAL_OBJ( typeOfTypes, TYPE_OBJ( cached ) ) then */
t_4 = GF_IS__IDENTICAL__OBJ;
C_ELM_POSOBJ_NLE( t_5, l_cached, 3 );
t_5 = ElmPosObj( l_cached, 3 );
t_3 = CALL_2ARGS( t_4, a_data, t_5 );
CHECK_FUNC_RESULT( t_3 )
CHECK_BOOL( t_3 )
Expand Down Expand Up @@ -975,17 +975,7 @@ static Obj HdlrFunc11 (
l_i = t_1;

/* if IsBound( cached![i] ) then */
if ( TNUM_OBJ(l_cached) == T_POSOBJ ) {
t_4 = (INT_INTOBJ(l_i) <= SIZE_OBJ(l_cached)/sizeof(Obj)-1
&& ELM_PLIST(l_cached,INT_INTOBJ(l_i)) != 0 ? True : False);
#ifdef HPCGAP
} else if ( TNUM_OBJ(l_cached) == T_APOSOBJ ) {
t_4 = Elm0AList(l_cached,INT_INTOBJ(l_i)) != 0 ? True : False;
#endif
}
else {
t_4 = (ISB_LIST( l_cached, INT_INTOBJ(l_i) ) ? True : False);
}
t_4 = IsbPosObj( l_cached, INT_INTOBJ(l_i) ) ? True : False;
t_3 = (Obj)(UInt)(t_4 != False);
if ( t_3 ) {

Expand Down Expand Up @@ -1048,28 +1038,8 @@ static Obj HdlrFunc11 (
l_i = t_1;

/* if IsBound( parent![i] ) <> IsBound( cached![i] ) then */
if ( TNUM_OBJ(a_parent) == T_POSOBJ ) {
t_4 = (INT_INTOBJ(l_i) <= SIZE_OBJ(a_parent)/sizeof(Obj)-1
&& ELM_PLIST(a_parent,INT_INTOBJ(l_i)) != 0 ? True : False);
#ifdef HPCGAP
} else if ( TNUM_OBJ(a_parent) == T_APOSOBJ ) {
t_4 = Elm0AList(a_parent,INT_INTOBJ(l_i)) != 0 ? True : False;
#endif
}
else {
t_4 = (ISB_LIST( a_parent, INT_INTOBJ(l_i) ) ? True : False);
}
if ( TNUM_OBJ(l_cached) == T_POSOBJ ) {
t_5 = (INT_INTOBJ(l_i) <= SIZE_OBJ(l_cached)/sizeof(Obj)-1
&& ELM_PLIST(l_cached,INT_INTOBJ(l_i)) != 0 ? True : False);
#ifdef HPCGAP
} else if ( TNUM_OBJ(l_cached) == T_APOSOBJ ) {
t_5 = Elm0AList(l_cached,INT_INTOBJ(l_i)) != 0 ? True : False;
#endif
}
else {
t_5 = (ISB_LIST( l_cached, INT_INTOBJ(l_i) ) ? True : False);
}
t_4 = IsbPosObj( a_parent, INT_INTOBJ(l_i) ) ? True : False;
t_5 = IsbPosObj( l_cached, INT_INTOBJ(l_i) ) ? True : False;
t_3 = (Obj)(UInt)( ! EQ( t_4, t_5 ));
if ( t_3 ) {

Expand All @@ -1084,39 +1054,19 @@ static Obj HdlrFunc11 (
/* fi */

/* if IsBound( parent![i] ) and IsBound( cached![i] ) and not IS_IDENTICAL_OBJ( parent![i], cached![i] ) then */
if ( TNUM_OBJ(a_parent) == T_POSOBJ ) {
t_6 = (INT_INTOBJ(l_i) <= SIZE_OBJ(a_parent)/sizeof(Obj)-1
&& ELM_PLIST(a_parent,INT_INTOBJ(l_i)) != 0 ? True : False);
#ifdef HPCGAP
} else if ( TNUM_OBJ(a_parent) == T_APOSOBJ ) {
t_6 = Elm0AList(a_parent,INT_INTOBJ(l_i)) != 0 ? True : False;
#endif
}
else {
t_6 = (ISB_LIST( a_parent, INT_INTOBJ(l_i) ) ? True : False);
}
t_6 = IsbPosObj( a_parent, INT_INTOBJ(l_i) ) ? True : False;
t_5 = (Obj)(UInt)(t_6 != False);
t_4 = t_5;
if ( t_4 ) {
if ( TNUM_OBJ(l_cached) == T_POSOBJ ) {
t_7 = (INT_INTOBJ(l_i) <= SIZE_OBJ(l_cached)/sizeof(Obj)-1
&& ELM_PLIST(l_cached,INT_INTOBJ(l_i)) != 0 ? True : False);
#ifdef HPCGAP
} else if ( TNUM_OBJ(l_cached) == T_APOSOBJ ) {
t_7 = Elm0AList(l_cached,INT_INTOBJ(l_i)) != 0 ? True : False;
#endif
}
else {
t_7 = (ISB_LIST( l_cached, INT_INTOBJ(l_i) ) ? True : False);
}
t_7 = IsbPosObj( l_cached, INT_INTOBJ(l_i) ) ? True : False;
t_6 = (Obj)(UInt)(t_7 != False);
t_4 = t_6;
}
t_3 = t_4;
if ( t_3 ) {
t_8 = GF_IS__IDENTICAL__OBJ;
C_ELM_POSOBJ_NLE( t_9, a_parent, INT_INTOBJ(l_i) );
C_ELM_POSOBJ_NLE( t_10, l_cached, INT_INTOBJ(l_i) );
t_9 = ElmPosObj( a_parent, INT_INTOBJ(l_i) );
t_10 = ElmPosObj( l_cached, INT_INTOBJ(l_i) );
t_7 = CALL_2ARGS( t_8, t_9, t_10 );
CHECK_FUNC_RESULT( t_7 )
CHECK_BOOL( t_7 )
Expand Down Expand Up @@ -1246,17 +1196,7 @@ static Obj HdlrFunc11 (
l_i = t_1;

/* if IsBound( parent![i] ) and not IsBound( type[i] ) then */
if ( TNUM_OBJ(a_parent) == T_POSOBJ ) {
t_5 = (INT_INTOBJ(l_i) <= SIZE_OBJ(a_parent)/sizeof(Obj)-1
&& ELM_PLIST(a_parent,INT_INTOBJ(l_i)) != 0 ? True : False);
#ifdef HPCGAP
} else if ( TNUM_OBJ(a_parent) == T_APOSOBJ ) {
t_5 = Elm0AList(a_parent,INT_INTOBJ(l_i)) != 0 ? True : False;
#endif
}
else {
t_5 = (ISB_LIST( a_parent, INT_INTOBJ(l_i) ) ? True : False);
}
t_5 = IsbPosObj( a_parent, INT_INTOBJ(l_i) ) ? True : False;
t_4 = (Obj)(UInt)(t_5 != False);
t_3 = t_4;
if ( t_3 ) {
Expand All @@ -1268,7 +1208,7 @@ static Obj HdlrFunc11 (
if ( t_3 ) {

/* type[i] := parent![i]; */
C_ELM_POSOBJ_NLE( t_3, a_parent, INT_INTOBJ(l_i) );
t_3 = ElmPosObj( a_parent, INT_INTOBJ(l_i) );
C_ASS_LIST_FPL( l_type, l_i, t_3 )

}
Expand Down Expand Up @@ -1327,7 +1267,7 @@ static Obj HdlrFunc11 (

/* ncache[HASH_FLAGS( t![2] ) mod ncl + 1] := t; */
t_8 = GF_HASH__FLAGS;
C_ELM_POSOBJ_NLE( t_9, l_t, 2 );
t_9 = ElmPosObj( l_t, 2 );
t_7 = CALL_1ARGS( t_8, t_9 );
CHECK_FUNC_RESULT( t_7 )
t_6 = MOD( t_7, l_ncl );
Expand Down Expand Up @@ -1615,18 +1555,18 @@ static Obj HdlrFunc15 (
t_2 = GF_NEW__TYPE;
t_3 = GC_TypeOfTypes;
CHECK_BOUND( t_3, "TypeOfTypes" )
C_ELM_POSOBJ_NLE( t_4, a_type, 1 );
t_4 = ElmPosObj( a_type, 1 );
t_6 = GF_WITH__IMPS__FLAGS;
t_8 = GF_AND__FLAGS;
C_ELM_POSOBJ_NLE( t_9, a_type, 2 );
t_9 = ElmPosObj( a_type, 2 );
t_11 = GF_FLAGS__FILTER;
t_10 = CALL_1ARGS( t_11, a_filter );
CHECK_FUNC_RESULT( t_10 )
t_7 = CALL_2ARGS( t_8, t_9, t_10 );
CHECK_FUNC_RESULT( t_7 )
t_5 = CALL_1ARGS( t_6, t_7 );
CHECK_FUNC_RESULT( t_5 )
C_ELM_POSOBJ_NLE( t_6, a_type, 3 );
t_6 = ElmPosObj( a_type, 3 );
t_1 = CALL_5ARGS( t_2, t_3, t_4, t_5, t_6, a_type );
CHECK_FUNC_RESULT( t_1 )
RES_BRK_CURR_STAT();
Expand Down Expand Up @@ -1669,10 +1609,10 @@ static Obj HdlrFunc16 (
t_2 = GF_NEW__TYPE;
t_3 = GC_TypeOfTypes;
CHECK_BOUND( t_3, "TypeOfTypes" )
C_ELM_POSOBJ_NLE( t_4, a_type, 1 );
t_4 = ElmPosObj( a_type, 1 );
t_6 = GF_WITH__IMPS__FLAGS;
t_8 = GF_AND__FLAGS;
C_ELM_POSOBJ_NLE( t_9, a_type, 2 );
t_9 = ElmPosObj( a_type, 2 );
t_11 = GF_FLAGS__FILTER;
t_10 = CALL_1ARGS( t_11, a_filter );
CHECK_FUNC_RESULT( t_10 )
Expand Down Expand Up @@ -1802,15 +1742,15 @@ static Obj HdlrFunc18 (
t_2 = GF_NEW__TYPE;
t_3 = GC_TypeOfTypes;
CHECK_BOUND( t_3, "TypeOfTypes" )
C_ELM_POSOBJ_NLE( t_4, a_type, 1 );
t_4 = ElmPosObj( a_type, 1 );
t_6 = GF_SUB__FLAGS;
C_ELM_POSOBJ_NLE( t_7, a_type, 2 );
t_7 = ElmPosObj( a_type, 2 );
t_9 = GF_FLAGS__FILTER;
t_8 = CALL_1ARGS( t_9, a_filter );
CHECK_FUNC_RESULT( t_8 )
t_5 = CALL_2ARGS( t_6, t_7, t_8 );
CHECK_FUNC_RESULT( t_5 )
C_ELM_POSOBJ_NLE( t_6, a_type, 3 );
t_6 = ElmPosObj( a_type, 3 );
t_1 = CALL_5ARGS( t_2, t_3, t_4, t_5, t_6, a_type );
CHECK_FUNC_RESULT( t_1 )
RES_BRK_CURR_STAT();
Expand Down Expand Up @@ -1851,9 +1791,9 @@ static Obj HdlrFunc19 (
t_2 = GF_NEW__TYPE;
t_3 = GC_TypeOfTypes;
CHECK_BOUND( t_3, "TypeOfTypes" )
C_ELM_POSOBJ_NLE( t_4, a_type, 1 );
t_4 = ElmPosObj( a_type, 1 );
t_6 = GF_SUB__FLAGS;
C_ELM_POSOBJ_NLE( t_7, a_type, 2 );
t_7 = ElmPosObj( a_type, 2 );
t_9 = GF_FLAGS__FILTER;
t_8 = CALL_1ARGS( t_9, a_filter );
CHECK_FUNC_RESULT( t_8 )
Expand Down Expand Up @@ -1969,7 +1909,7 @@ static Obj HdlrFunc21 (
SET_BRK_CURR_STAT(0);

/* return K![1]; */
C_ELM_POSOBJ_NLE( t_1, a_K, 1 );
t_1 = ElmPosObj( a_K, 1 );
RES_BRK_CURR_STAT();
SWITCH_TO_OLD_FRAME(oldFrame);
return t_1;
Expand All @@ -1995,7 +1935,7 @@ static Obj HdlrFunc22 (
SET_BRK_CURR_STAT(0);

/* return K![2]; */
C_ELM_POSOBJ_NLE( t_1, a_K, 2 );
t_1 = ElmPosObj( a_K, 2 );
RES_BRK_CURR_STAT();
SWITCH_TO_OLD_FRAME(oldFrame);
return t_1;
Expand All @@ -2021,7 +1961,7 @@ static Obj HdlrFunc23 (
SET_BRK_CURR_STAT(0);

/* return K![3]; */
C_ELM_POSOBJ_NLE( t_1, a_K, 3 );
t_1 = ElmPosObj( a_K, 3 );
RES_BRK_CURR_STAT();
SWITCH_TO_OLD_FRAME(oldFrame);
return t_1;
Expand All @@ -2047,7 +1987,7 @@ static Obj HdlrFunc24 (
SET_BRK_CURR_STAT(0);

/* K![3] := data; */
C_ASS_POSOBJ( a_K, 3, a_data )
AssPosObj( a_K, 3, a_data );

/* return; */
RES_BRK_CURR_STAT();
Expand Down Expand Up @@ -2207,7 +2147,7 @@ static Obj HdlrFunc27 (

/* RunImmediateMethods( obj, type![2] ); */
t_1 = GF_RunImmediateMethods;
C_ELM_POSOBJ_NLE( t_2, a_type, 2 );
t_2 = ElmPosObj( a_type, 2 );
CALL_2ARGS( t_1, a_obj, t_2 );

}
Expand Down Expand Up @@ -2292,8 +2232,8 @@ static Obj HdlrFunc28 (
/* RunImmediateMethods( obj, SUB_FLAGS( newtype![2], type![2] ) ); */
t_1 = GF_RunImmediateMethods;
t_3 = GF_SUB__FLAGS;
C_ELM_POSOBJ_NLE( t_4, l_newtype, 2 );
C_ELM_POSOBJ_NLE( t_5, l_type, 2 );
t_4 = ElmPosObj( l_newtype, 2 );
t_5 = ElmPosObj( l_type, 2 );
t_2 = CALL_2ARGS( t_3, t_4, t_5 );
CHECK_FUNC_RESULT( t_2 )
CALL_2ARGS( t_1, a_obj, t_2 );
Expand Down Expand Up @@ -2348,8 +2288,8 @@ static Obj HdlrFunc28 (
/* RunImmediateMethods( obj, SUB_FLAGS( newtype![2], type![2] ) ); */
t_1 = GF_RunImmediateMethods;
t_3 = GF_SUB__FLAGS;
C_ELM_POSOBJ_NLE( t_4, l_newtype, 2 );
C_ELM_POSOBJ_NLE( t_5, l_type, 2 );
t_4 = ElmPosObj( l_newtype, 2 );
t_5 = ElmPosObj( l_type, 2 );
t_2 = CALL_2ARGS( t_3, t_4, t_5 );
CHECK_FUNC_RESULT( t_2 )
CALL_2ARGS( t_1, a_obj, t_2 );
Expand Down Expand Up @@ -2404,8 +2344,8 @@ static Obj HdlrFunc28 (
/* RunImmediateMethods( obj, SUB_FLAGS( newtype![2], type![2] ) ); */
t_1 = GF_RunImmediateMethods;
t_3 = GF_SUB__FLAGS;
C_ELM_POSOBJ_NLE( t_4, l_newtype, 2 );
C_ELM_POSOBJ_NLE( t_5, l_type, 2 );
t_4 = ElmPosObj( l_newtype, 2 );
t_5 = ElmPosObj( l_type, 2 );
t_2 = CALL_2ARGS( t_3, t_4, t_5 );
CHECK_FUNC_RESULT( t_2 )
CALL_2ARGS( t_1, a_obj, t_2 );
Expand Down
39 changes: 0 additions & 39 deletions src/compiled.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,45 +120,6 @@ typedef UInt RNam;
#define SWITCH_TO_OLD_FRAME SWITCH_TO_OLD_LVARS


/* objects, should into 'objects.c' * * * * * * * * * * * * * * * * * * * */

/* there should be a function for C_ELM_POSOBJ */
#define C_ELM_POSOBJ( elm, list, pos ) NOT_READY_YET


#define C_ELM_POSOBJ_NLE( elm, list, pos ) \
if ( TNUM_OBJ(list) == T_POSOBJ ) { \
elm = ELM_PLIST( list, pos ); \
} \
else { \
elm = ELMW_LIST( list, pos ); \
}

#define C_ASS_POSOBJ_INTOBJ( list, pos, elm ) \
if ( TNUM_OBJ(list) == T_POSOBJ ) { \
if ( SIZE_OBJ(list)/sizeof(Obj)-1 < pos ) { \
ResizeBag( list, (pos+1)*sizeof(Obj) ); \
} \
SET_ELM_PLIST( list, pos, elm ); \
} \
else { \
ASS_LIST( list, pos, elm ); \
}

#define C_ASS_POSOBJ( list, pos, elm ) \
if ( TNUM_OBJ(list) == T_POSOBJ ) { \
if ( SIZE_OBJ(list)/sizeof(Obj)-1 < pos ) { \
ResizeBag( list, (pos+1)*sizeof(Obj) ); \
} \
SET_ELM_PLIST( list, pos, elm ); \
CHANGED_BAG(list); \
} \
else { \
ASS_LIST( list, pos, elm ); \
}



/* lists, should go into 'lists.c' * * * * * * * * * * * * * * * * * * * * */
#define C_LEN_LIST(len,list) \
len = LENGTH(list);
Expand Down
Loading

0 comments on commit 44f1a0c

Please sign in to comment.