diff --git a/examples/extern_C/README b/examples/extern_C/README new file mode 100644 index 0000000..fcdcb1e --- /dev/null +++ b/examples/extern_C/README @@ -0,0 +1,6 @@ +This example show how to import an external function written in C in an Heptagon program. + +- The .epi file contains the signature of the function in Heptagon. +- Only functions with no side effects can be safely imported. +- The imported function must have the same calling convention as generated code (inputs given by value, outputs in a f_out structure). +- The generated code will include "mathext.h", that should define the step function diff --git a/examples/extern_C/imports.ept b/examples/extern_C/imports.ept new file mode 100644 index 0000000..19aab75 --- /dev/null +++ b/examples/extern_C/imports.ept @@ -0,0 +1,6 @@ +open Mathext + +fun f(a:float) returns (o:float) +let + o = mycos(a); +tel \ No newline at end of file diff --git a/examples/extern_C/mathext.c b/examples/extern_C/mathext.c new file mode 100644 index 0000000..f3f7367 --- /dev/null +++ b/examples/extern_C/mathext.c @@ -0,0 +1,7 @@ +#include +#include "mathext.h" + +void mycos(float a, mycos_out *out) +{ + out->o = cos(a); +} diff --git a/examples/extern_C/mathext.epi b/examples/extern_C/mathext.epi new file mode 100644 index 0000000..3eb4f32 --- /dev/null +++ b/examples/extern_C/mathext.epi @@ -0,0 +1 @@ +val fun mycos(a:float) returns (o:float) \ No newline at end of file diff --git a/examples/extern_C/mathext.h b/examples/extern_C/mathext.h new file mode 100644 index 0000000..9c01477 --- /dev/null +++ b/examples/extern_C/mathext.h @@ -0,0 +1,8 @@ +#ifdef MATHEXT_H +#define MATHEXT_H + +struct mycos_out { + float o; +}; + +void mycos(float a, mycos_out *o);