summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCamil Staps2015-07-06 21:04:42 +0200
committerCamil Staps2015-07-06 21:04:42 +0200
commit379a413032bc5efd0fc3cd118d63470fd18e819e (patch)
treeab8771c73c3c962e26e5f4464c2bd4b066c43d21
int example
-rw-r--r--example_int/.gitignore5
-rw-r--r--example_int/Clean.h43
-rw-r--r--example_int/Makefile6
-rw-r--r--example_int/example_int.c6
-rw-r--r--example_int/example_int.h2
-rw-r--r--example_int/verify.icl5
6 files changed, 67 insertions, 0 deletions
diff --git a/example_int/.gitignore b/example_int/.gitignore
new file mode 100644
index 0000000..bff9392
--- /dev/null
+++ b/example_int/.gitignore
@@ -0,0 +1,5 @@
+Clean System Files
+*.o
+verify
+example_int.icl
+example_int.dcl
diff --git a/example_int/Clean.h b/example_int/Clean.h
new file mode 100644
index 0000000..7429934
--- /dev/null
+++ b/example_int/Clean.h
@@ -0,0 +1,43 @@
+
+#define Clean(a)
+
+typedef struct clean_string *CleanString;
+
+/* a string in Clean is:
+ struct clean_string {
+ int clean_string_length;
+ char clean_string_characters[clean_string_length];
+ };
+ The string does not end with a '\0' !
+*/
+
+/* CleanStringLength(clean_string) returns the length of the clean_string in characters */
+#define CleanStringLength(clean_string) (*(unsigned int *)(clean_string))
+
+/* CleanStringCharacters(clean_string) returns a pointer to the characters of the clean_string */
+#define CleanStringCharacters(clean_string) ((char*)(1+(unsigned int *)(clean_string)))
+
+/* CleanStringSizeInts(string_length) return size of *CleanString in integers */
+#define CleanStringSizeInts(string_length) (1+(((unsigned int)(string_length)+3)>>2))
+
+/* CleanStringVariable(clean_string,string_length) defines variable clean_string with length string_length,
+ before using the clean_string variable, cast to CleanString, except for the macros above */
+#define CleanStringVariable(clean_string,string_length) unsigned int clean_string[CleanStringSizeInts(string_length)]
+
+/* CleanStringSizeBytes(string_length) return size of *CleanString in bytes */
+#define CleanStringSizeBytes(string_length) (4+(((unsigned int)(string_length)+3) & -4))
+
+typedef int *CleanIntArray;
+
+/* CleanIntArraySize(clean_array) returns the size (number of elements) of the clean_int_array */
+#define CleanIntArraySize(clean_int_array) (((unsigned int *)(clean_int_array))[-2])
+
+typedef double *CleanRealArray;
+
+/* CleanRealArraySize(clean_real_array) returns the size (number of elements) of the clean_real_array */
+#define CleanRealArraySize(clean_real_array) (((unsigned int *)(clean_real_array))[-2])
+
+typedef unsigned char *CleanCharArray;
+
+/* CleanCharArraySize(clean_char_array) returns the size (number of elements) of the clean_char_array */
+#define CleanCharArraySize(clean_char_array) (((unsigned int *)(clean_char_array))[-1])
diff --git a/example_int/Makefile b/example_int/Makefile
new file mode 100644
index 0000000..d3df8bb
--- /dev/null
+++ b/example_int/Makefile
@@ -0,0 +1,6 @@
+all:
+ cc -O -c example_int.c
+ clm -l example_int.o verify -o verify
+
+run:
+ ./verify
diff --git a/example_int/example_int.c b/example_int/example_int.c
new file mode 100644
index 0000000..aa6b616
--- /dev/null
+++ b/example_int/example_int.c
@@ -0,0 +1,6 @@
+#include "example_int.h"
+
+int add(int v1, int v2) {
+ return v1 + v2;
+}
+
diff --git a/example_int/example_int.h b/example_int/example_int.h
new file mode 100644
index 0000000..84f021f
--- /dev/null
+++ b/example_int/example_int.h
@@ -0,0 +1,2 @@
+int add(int v1, int v2);
+
diff --git a/example_int/verify.icl b/example_int/verify.icl
new file mode 100644
index 0000000..cf0d0a1
--- /dev/null
+++ b/example_int/verify.icl
@@ -0,0 +1,5 @@
+module verify
+
+import StdEnv, example_int
+
+Start = add 5 10