Plan 9 from Bell Labs’s /usr/web/sources/contrib/fernan/nhc98/src/runtime/Builtin/primIntFromInteger.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.



#include "haskell2c.h"

#ifdef PROFILE
static SInfo nodeProfInfo = { "Builtin","Builtin.primIntFromInteger","Prelude.Int"};
#endif

C_HEADER(primIntFromInteger)
{
  Int tag,size;
  NodePtr nodeptr,res;
  C_CHECK(SIZE_INT);
  nodeptr = C_GETARG1(1);
  IND_REMOVE(nodeptr);
  tag = *nodeptr;
  size = CONINFO_LARGESIZES(tag);
  if(!size) {
    res = GET_INT(0);
  } else {
    Int value = GET_INT_VALUE(nodeptr);
    res = C_ALLOC(SIZE_INT);
    if(CONINFO_LARGEEXTRA(tag))
      value = -value;
    MK_INT(res,value);
    INIT_PROFINFO(res,&nodeProfInfo)
  }
  C_RETURN(res);
}

int primIntFromIntegerC (NodePtr integer)
{
  Int tag,size,result;
  tag = *integer;
  size = CONINFO_LARGESIZES(tag);
  if(!size) {
    result = 0;
  } else {
    result = GET_INT_VALUE(integer);
    if(CONINFO_LARGEEXTRA(tag))
      result = -result;
  }
  return (result);
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.