Esempio n. 1
0
File: records.c Progetto: vbraun/gap
/****************************************************************************
**
*F  RNamObj(<obj>)  . . . . . . . . . . .  convert an object to a record name
**
**  'RNamObj' returns the record name  corresponding  to  the  object  <obj>,
**  which currently must be a string or an integer.
*/
UInt            RNamObj (
    Obj                 obj )
{
    /* convert integer object                                              */
    if ( IS_INTOBJ(obj) ) {
        return RNamIntg( INT_INTOBJ(obj) );
    }

    /* convert string object (empty string may have type T_PLIST)          */
    else if ( IsStringConv(obj) && IS_STRING_REP(obj) ) {
        return RNamName( CSTR_STRING(obj) );
    }

    /* otherwise fail                                                      */
    else {
        obj = ErrorReturnObj(
            "Record: '<rec>.(<obj>)' <obj> must be a string or an integer",
            0L, 0L,
            "you can replace <obj> via 'return <obj>;'" );
        return RNamObj( obj );
    }
}
Esempio n. 2
0
/* handler for function 2 */
static Obj  HdlrFunc2 (
 Obj  self )
{
 Obj t_1 = 0;
 Obj t_2 = 0;
 Obj t_3 = 0;
 Bag oldFrame;
 
 /* allocate new stack frame */
 SWITCH_TO_NEW_FRAME(self,0,0,oldFrame);
 
 /* Print( AssertionLevel(  ), "\n" ); */
 t_1 = GF_Print;
 t_3 = GF_AssertionLevel;
 t_2 = CALL_0ARGS( t_3 );
 CHECK_FUNC_RESULT( t_2 )
 t_3 = MakeString( "\n" );
 CALL_2ARGS( t_1, t_2, t_3 );
 
 /* Assert( ... ); */
 if ( ! LT(CurrentAssertionLevel, INTOBJ_INT(1)) ) {
  t_2 = False;
  t_1 = (Obj)(UInt)(t_2 != False);
  if ( ! t_1 ) {
   t_2 = MakeString( "fail-A" );
   if ( t_2 != (Obj)(UInt)0 ){
     if ( IS_STRING_REP ( t_2 ) )
       PrintString1( t_2);
     else
       PrintObj(t_2);
   }
  }
 }
 
 /* Assert( ... ); */
 if ( ! LT(CurrentAssertionLevel, INTOBJ_INT(1)) ) {
  t_2 = False;
  t_1 = (Obj)(UInt)(t_2 != False);
  if ( ! t_1 ) {
   ErrorReturnVoid("Assertion failure",0L,0L,"you may 'return;'");
  }
 }
 
 /* Assert( ... ); */
 if ( ! LT(CurrentAssertionLevel, INTOBJ_INT(0)) ) {
  t_2 = True;
  t_1 = (Obj)(UInt)(t_2 != False);
  if ( ! t_1 ) {
   t_2 = MakeString( "fail-B" );
   if ( t_2 != (Obj)(UInt)0 ){
     if ( IS_STRING_REP ( t_2 ) )
       PrintString1( t_2);
     else
       PrintObj(t_2);
   }
  }
 }
 
 /* Assert( ... ); */
 if ( ! LT(CurrentAssertionLevel, INTOBJ_INT(0)) ) {
  t_2 = True;
  t_1 = (Obj)(UInt)(t_2 != False);
  if ( ! t_1 ) {
   ErrorReturnVoid("Assertion failure",0L,0L,"you may 'return;'");
  }
 }
 
 /* SetAssertionLevel( 2 ); */
 t_1 = GF_SetAssertionLevel;
 CALL_1ARGS( t_1, INTOBJ_INT(2) );
 
 /* Print( AssertionLevel(  ), "\n" ); */
 t_1 = GF_Print;
 t_3 = GF_AssertionLevel;
 t_2 = CALL_0ARGS( t_3 );
 CHECK_FUNC_RESULT( t_2 )
 t_3 = MakeString( "\n" );
 CALL_2ARGS( t_1, t_2, t_3 );
 
 /* Assert( ... ); */
 if ( ! LT(CurrentAssertionLevel, INTOBJ_INT(3)) ) {
  t_2 = False;
  t_1 = (Obj)(UInt)(t_2 != False);
  if ( ! t_1 ) {
   t_2 = MakeString( "fail-C" );
   if ( t_2 != (Obj)(UInt)0 ){
     if ( IS_STRING_REP ( t_2 ) )
       PrintString1( t_2);
     else
       PrintObj(t_2);
   }
  }
 }
 
 /* Assert( ... ); */
 if ( ! LT(CurrentAssertionLevel, INTOBJ_INT(3)) ) {
  t_2 = False;
  t_1 = (Obj)(UInt)(t_2 != False);
  if ( ! t_1 ) {
   ErrorReturnVoid("Assertion failure",0L,0L,"you may 'return;'");
  }
 }
 
 /* Assert( ... ); */
 if ( ! LT(CurrentAssertionLevel, INTOBJ_INT(2)) ) {
  t_2 = True;
  t_1 = (Obj)(UInt)(t_2 != False);
  if ( ! t_1 ) {
   t_2 = MakeString( "fail-D" );
   if ( t_2 != (Obj)(UInt)0 ){
     if ( IS_STRING_REP ( t_2 ) )
       PrintString1( t_2);
     else
       PrintObj(t_2);
   }
  }
 }
 
 /* Assert( ... ); */
 if ( ! LT(CurrentAssertionLevel, INTOBJ_INT(2)) ) {
  t_2 = True;
  t_1 = (Obj)(UInt)(t_2 != False);
  if ( ! t_1 ) {
   ErrorReturnVoid("Assertion failure",0L,0L,"you may 'return;'");
  }
 }
 
 /* Assert( ... ); */
 if ( ! LT(CurrentAssertionLevel, INTOBJ_INT(2)) ) {
  t_2 = False;
  t_1 = (Obj)(UInt)(t_2 != False);
  if ( ! t_1 ) {
   t_2 = MakeString( "pass!\n" );
   if ( t_2 != (Obj)(UInt)0 ){
     if ( IS_STRING_REP ( t_2 ) )
       PrintString1( t_2);
     else
       PrintObj(t_2);
   }
  }
 }
 
 /* Print( "end of function\n" ); */
 t_1 = GF_Print;
 t_2 = MakeString( "end of function\n" );
 CALL_1ARGS( t_1, t_2 );
 
 /* return; */
 SWITCH_TO_OLD_FRAME(oldFrame);
 return 0;
 
 /* return; */
 SWITCH_TO_OLD_FRAME(oldFrame);
 return 0;
}
Esempio n. 3
0
 bool isa(Obj recval) const
 { return IS_STRING(recval) && IS_STRING_REP(recval); }
Esempio n. 4
0
char * GAP_CSTR_STRING(Obj string)
{
    if (!IS_STRING_REP(string))
        return 0;
    return CSTR_STRING(string);
}
Esempio n. 5
0
int GAP_IsString(Obj obj)
{
    return obj && IS_STRING_REP(obj);
}