diff options
author | Camil Staps | 2015-07-07 14:58:07 +0200 |
---|---|---|
committer | Camil Staps | 2015-07-07 14:58:07 +0200 |
commit | ff5b2a3d554e28779c6c1b244ebe949608706f23 (patch) | |
tree | 2e58fb34ea3da76f99fe6b6feb4076b3948af1b7 | |
parent | Htoclean in makefile (diff) |
Using pointers
-rw-r--r-- | bitlength/Makefile | 11 | ||||
-rw-r--r-- | bitlength/consumer.icl | 26 | ||||
-rw-r--r-- | bitlength/producer.c | 9 | ||||
-rw-r--r-- | bitlength/producer.h | 4 |
4 files changed, 33 insertions, 17 deletions
diff --git a/bitlength/Makefile b/bitlength/Makefile index 8562788..fdbc706 100644 --- a/bitlength/Makefile +++ b/bitlength/Makefile @@ -1,13 +1,16 @@ -all: consumer run +all: clean consumer run -producer.o: +clean: + rm -f producer.o producer.dcl producer.icl consumer + +producer.o: producer.c producer.h cc -c producer.c -producer.dcl: producer.o +producer.dcl: producer.o producer.h htoclean producer consumer: producer.dcl clm -tst -l producer.o consumer -o consumer run: - ./consumer + ./consumer -nt -nr diff --git a/bitlength/consumer.icl b/bitlength/consumer.icl index 67a61ec..7d5c373 100644 --- a/bitlength/consumer.icl +++ b/bitlength/consumer.icl @@ -3,18 +3,24 @@ module consumer import StdEnv import producer -Start :: *World -> *World -Start w +echo :: a *World -> *World | toString a +echo s w # (io,w) = stdio w -# io = fwrites ("See, I can have 64 bits! " +++ toString (2^63-1) +++ "\n") io -# io = consume 0 1 io +# io = io <<< toString s <<< "\n" # (ok,w) = fclose io w +| not ok = abort "Couldn't close stdio" +| otherwise = w + +Start :: *World -> *World +Start w +# w = echo " Producer - Consumer" w +# w = consume 0 1 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 + consume :: !Int !Int *World -> *World + consume i n w + # n = abs (produce n) + # w = echo n w + | n <> 0 = consume (i+1) n w + | otherwise = w diff --git a/bitlength/producer.c b/bitlength/producer.c index 114c743..b67aea1 100644 --- a/bitlength/producer.c +++ b/bitlength/producer.c @@ -1,7 +1,12 @@ +#include <inttypes.h> +#include <stdio.h> #include "Clean.h" #include "producer.h" -int produce(int old) +int* produce(int* n) { - return 2 * old; + n = (int*) ((int64_t) n << 1); + printf("%20p - ", n); + return n; } + diff --git a/bitlength/producer.h b/bitlength/producer.h index efb4a93..fce70d7 100644 --- a/bitlength/producer.h +++ b/bitlength/producer.h @@ -1 +1,3 @@ -int produce(int); +int* produce(int*); +Clean(produce :: Int -> Int) + |