diff options
author | Camil Staps | 2015-07-06 21:09:07 +0200 |
---|---|---|
committer | Camil Staps | 2015-07-06 21:09:07 +0200 |
commit | e57799ca28f6f6b5474a0a1a4b3e14e241c2abd2 (patch) | |
tree | 659bde0e613e3a24e86eca7ecef3966c0282f0ba | |
parent | Test tuple (diff) |
Bitlength & ccall
-rw-r--r-- | bitlength/.gitignore | 5 | ||||
-rw-r--r-- | bitlength/Clean.h | 43 | ||||
-rw-r--r-- | bitlength/Makefile | 10 | ||||
-rw-r--r-- | bitlength/consumer.icl | 20 | ||||
-rw-r--r-- | bitlength/producer.c | 7 | ||||
-rw-r--r-- | bitlength/producer.h | 1 |
6 files changed, 86 insertions, 0 deletions
diff --git a/bitlength/.gitignore b/bitlength/.gitignore new file mode 100644 index 0000000..31cae00 --- /dev/null +++ b/bitlength/.gitignore @@ -0,0 +1,5 @@ +Clean System Files +*.o +producer.dcl +producer.icl +consumer diff --git a/bitlength/Clean.h b/bitlength/Clean.h new file mode 100644 index 0000000..7429934 --- /dev/null +++ b/bitlength/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/bitlength/Makefile b/bitlength/Makefile new file mode 100644 index 0000000..4d9ba47 --- /dev/null +++ b/bitlength/Makefile @@ -0,0 +1,10 @@ +all: consumer run + +producer.o: + cc -c producer.c + +consumer: producer.o + clm -tst -l producer.o consumer -o consumer + +run: + ./consumer diff --git a/bitlength/consumer.icl b/bitlength/consumer.icl new file mode 100644 index 0000000..67a61ec --- /dev/null +++ b/bitlength/consumer.icl @@ -0,0 +1,20 @@ +module consumer + +import StdEnv +import producer + +Start :: *World -> *World +Start w +# (io,w) = stdio w +# io = fwrites ("See, I can have 64 bits! " +++ toString (2^63-1) +++ "\n") io +# io = consume 0 1 io +# (ok,w) = fclose io w += w +where + consume :: !Int !Int *File -> *File + consume i n io + # (n,io) = (produce n, io) + # io = fwrites (toString i +++ " : " +++ toString n +++ "\n") io + | n <> 0 = consume (i+1) n io + | otherwise = io + diff --git a/bitlength/producer.c b/bitlength/producer.c new file mode 100644 index 0000000..114c743 --- /dev/null +++ b/bitlength/producer.c @@ -0,0 +1,7 @@ +#include "Clean.h" +#include "producer.h" + +int produce(int old) +{ + return 2 * old; +} diff --git a/bitlength/producer.h b/bitlength/producer.h new file mode 100644 index 0000000..efb4a93 --- /dev/null +++ b/bitlength/producer.h @@ -0,0 +1 @@ +int produce(int); |