From acf60ada87c70bc22adae5e760c354f1a7f33e6d Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Tue, 26 Jan 2016 16:21:28 +0100 Subject: ctoclean --- ctoclean/.gitignore | 2 ++ ctoclean/Makefile | 13 +++++++++++++ ctoclean/call.c | 10 ++++++++++ ctoclean/square.dcl | 5 +++++ ctoclean/square.icl | 15 +++++++++++++++ 5 files changed, 45 insertions(+) create mode 100644 ctoclean/.gitignore create mode 100644 ctoclean/Makefile create mode 100644 ctoclean/call.c create mode 100644 ctoclean/square.dcl create mode 100644 ctoclean/square.icl diff --git a/ctoclean/.gitignore b/ctoclean/.gitignore new file mode 100644 index 0000000..886dd19 --- /dev/null +++ b/ctoclean/.gitignore @@ -0,0 +1,2 @@ +square + diff --git a/ctoclean/Makefile b/ctoclean/Makefile new file mode 100644 index 0000000..7c7047a --- /dev/null +++ b/ctoclean/Makefile @@ -0,0 +1,13 @@ +all: + mkdir -p Clean\ System\ Files + $(CC) -c call.c -o Clean\ System\ Files/call.o + clm square -o square + +run: + ./square + +clean: + rm -rf Clean\ System\ Files square + +.PHONY: clean + diff --git a/ctoclean/call.c b/ctoclean/call.c new file mode 100644 index 0000000..be5fe48 --- /dev/null +++ b/ctoclean/call.c @@ -0,0 +1,10 @@ +#include +#include + +extern int64_t square(int64_t); + +int64_t call_square(int64_t); +int64_t call_square(int64_t x) { + return square(x); +} + diff --git a/ctoclean/square.dcl b/ctoclean/square.dcl new file mode 100644 index 0000000..ea9aaa2 --- /dev/null +++ b/ctoclean/square.dcl @@ -0,0 +1,5 @@ +definition module square + +square :: !Int -> Int +call_square :: !Int -> Int + diff --git a/ctoclean/square.icl b/ctoclean/square.icl new file mode 100644 index 0000000..3fd9723 --- /dev/null +++ b/ctoclean/square.icl @@ -0,0 +1,15 @@ +implementation module square + +import StdEnv + +foreign export square +square :: !Int -> Int +square x = x * x + +call_square :: !Int -> Int +call_square x = code { + ccall square "GI:I" +}; + +Start = map call_square [1..10] + -- cgit v1.2.3