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

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


#include <string.h>
#include "haskell2c.h"

/* primIndex :: Vector a -> Int -> a */
/* The index must be evaluated before calling cPrimVector */
/* Index must be in range */

#ifdef PROFILE
static SInfo nodeProfInfo = { "Builtin","Builtin.primIndex","Builtin.Vector"};
#endif

C_HEADER(primIndex)
{
  int i;
  NodePtr res;
  NodePtr dstptr;

  res = C_GETARG1(2);
  IND_REMOVE(res);
  UPDATE_PROFINFO(res)
  i = GET_INT_VALUE(res);

  res = C_GETARG1(1);
  IND_REMOVE(res);
  UPDATE_PROFINFO(res)
  dstptr = (NodePtr)&res[1+EXTRA];

  C_RETURN((NodePtr)dstptr[i]);
}	


/* foreign import primVectorIndexC :: Vector a -> Int -> a */
NodePtr primVectorIndexC (NodePtr vec, int i)
{
  /* fprintf(stderr,"vectorIndex: idx=%d\n",i); */
  return (NodePtr)vec[1+EXTRA+i];
}



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.