summaryrefslogtreecommitdiff
path: root/test_state
diff options
context:
space:
mode:
authorCamil Staps2015-07-06 21:06:51 +0200
committerCamil Staps2015-07-06 21:06:51 +0200
commit4a31652c90eb68344b189d3885b110511d8db73b (patch)
treee0c3d33ca11ca7e8551f81b05004bd3039cb2820 /test_state
parentgtk test (diff)
Test state
Diffstat (limited to 'test_state')
-rw-r--r--test_state/.gitignore5
-rw-r--r--test_state/Clean.h43
-rw-r--r--test_state/Makefile7
-rw-r--r--test_state/test_state.c9
-rw-r--r--test_state/test_state.h8
-rw-r--r--test_state/test_state_test.icl10
6 files changed, 82 insertions, 0 deletions
diff --git a/test_state/.gitignore b/test_state/.gitignore
new file mode 100644
index 0000000..c25b198
--- /dev/null
+++ b/test_state/.gitignore
@@ -0,0 +1,5 @@
+Clean System Files
+*.o
+test_state.icl
+test_state.dcl
+test_state_test
diff --git a/test_state/Clean.h b/test_state/Clean.h
new file mode 100644
index 0000000..7429934
--- /dev/null
+++ b/test_state/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/test_state/Makefile b/test_state/Makefile
new file mode 100644
index 0000000..70d8fbe
--- /dev/null
+++ b/test_state/Makefile
@@ -0,0 +1,7 @@
+all:
+ htoclean test_state.h
+ cc -O -c test_state.c
+ clm -l test_state.o test_state_test -o test_state_test
+
+run:
+ ./test_state_test
diff --git a/test_state/test_state.c b/test_state/test_state.c
new file mode 100644
index 0000000..a88a534
--- /dev/null
+++ b/test_state/test_state.c
@@ -0,0 +1,9 @@
+#include "Clean.h"
+#include "test_state.h"
+#include <stdio.h>
+
+int store(int* p, int offset, int value) {
+ printf("Storing %d at %p + %d\n", value, p, offset);
+ return 0;
+}
+
diff --git a/test_state/test_state.h b/test_state/test_state.h
new file mode 100644
index 0000000..764728e
--- /dev/null
+++ b/test_state/test_state.h
@@ -0,0 +1,8 @@
+Clean(
+ :: *State :== Int;
+ :: IntPointer :== Int
+)
+
+int store(int* p, int offset, int value);
+Clean(store :: IntPointer Int Int State -> (IntPointer,State))
+
diff --git a/test_state/test_state_test.icl b/test_state/test_state_test.icl
new file mode 100644
index 0000000..680370e
--- /dev/null
+++ b/test_state/test_state_test.icl
@@ -0,0 +1,10 @@
+module test_state_test
+
+import StdEnv, test_state
+
+Start :: *World -> Int
+Start world
+# state = 10
+# (i, state) = store 5 10 15 state
+# (i, state) = store 10 20 30 state
+= i