1. Takafumi Arakaki
  2. cexp

Source

cexp / cexp / ext / src / fill01.c

#include <stdbool.h>

typedef struct fill01_{
  int num_i;
  int* int1d;
  unsigned int* uint1d;
  char* char1d;
  bool* bool1d;
} Fill01;

/*[[[cog
import cog

template = """\
int
Fill01_run_%(arr)s(Fill01 *self, int repeat)
{
  int i, r;
  for (r = 0; r < repeat; ++r){
    for (i = 0; i < self->num_i; ++i){
      if (i %% 2){
        self->%(arr)s[i] = %(v0)s;
      }else{
        self->%(arr)s[i] = %(v1)s;
      }
    }
  }
  return 0;
}
"""

l_arr = ['int1d', 'uint1d', 'char1d', 'bool1d']
l_v0 = ["0", "0", "'0'", "false"]
l_v1 = ["0", "1", "'1'", "true"]

for (arr, v0, v1) in zip(l_arr, l_v0, l_v1):
    cog.outl(template % dict(arr=arr, v0=v0, v1=v1))
]]]*/
int
Fill01_run_int1d(Fill01 *self, int repeat)
{
  int i, r;
  for (r = 0; r < repeat; ++r){
    for (i = 0; i < self->num_i; ++i){
      if (i % 2){
        self->int1d[i] = 0;
      }else{
        self->int1d[i] = 0;
      }
    }
  }
  return 0;
}

int
Fill01_run_uint1d(Fill01 *self, int repeat)
{
  int i, r;
  for (r = 0; r < repeat; ++r){
    for (i = 0; i < self->num_i; ++i){
      if (i % 2){
        self->uint1d[i] = 0;
      }else{
        self->uint1d[i] = 1;
      }
    }
  }
  return 0;
}

int
Fill01_run_char1d(Fill01 *self, int repeat)
{
  int i, r;
  for (r = 0; r < repeat; ++r){
    for (i = 0; i < self->num_i; ++i){
      if (i % 2){
        self->char1d[i] = '0';
      }else{
        self->char1d[i] = '1';
      }
    }
  }
  return 0;
}

int
Fill01_run_bool1d(Fill01 *self, int repeat)
{
  int i, r;
  for (r = 0; r < repeat; ++r){
    for (i = 0; i < self->num_i; ++i){
      if (i % 2){
        self->bool1d[i] = false;
      }else{
        self->bool1d[i] = true;
      }
    }
  }
  return 0;
}

/*[[[end]]]*/