From 0256b571f7fd30c07cf980df82759b669ea8c33c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Pasteur?= Date: Tue, 3 May 2011 13:35:13 +0200 Subject: [PATCH] Added pervasives C header It only defines the between function for now --- lib/c/pervasives.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 lib/c/pervasives.h diff --git a/lib/c/pervasives.h b/lib/c/pervasives.h new file mode 100644 index 0000000..a0b353e --- /dev/null +++ b/lib/c/pervasives.h @@ -0,0 +1,14 @@ +/* Pervasives module for the Decades compiler */ + +#ifndef DECADES_PERVASIVES_H +#define DECADES_PERVASIVES_H + +/* between(i, n) returns idx between 0 and n-1. */ +inline int between(int idx, int n) +{ + int o = (idx >= n) ? n-1 : (idx < 0 ? 0 : idx); + return o; +} + +#endif +