Added an example of how to import external functions
This commit is contained in:
parent
d3fea3aad3
commit
ac8dce35dc
5 changed files with 28 additions and 0 deletions
6
examples/extern_C/README
Normal file
6
examples/extern_C/README
Normal file
|
@ -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
|
6
examples/extern_C/imports.ept
Normal file
6
examples/extern_C/imports.ept
Normal file
|
@ -0,0 +1,6 @@
|
|||
open Mathext
|
||||
|
||||
fun f(a:float) returns (o:float)
|
||||
let
|
||||
o = mycos(a);
|
||||
tel
|
7
examples/extern_C/mathext.c
Normal file
7
examples/extern_C/mathext.c
Normal file
|
@ -0,0 +1,7 @@
|
|||
#include <math.h>
|
||||
#include "mathext.h"
|
||||
|
||||
void mycos(float a, mycos_out *out)
|
||||
{
|
||||
out->o = cos(a);
|
||||
}
|
1
examples/extern_C/mathext.epi
Normal file
1
examples/extern_C/mathext.epi
Normal file
|
@ -0,0 +1 @@
|
|||
val fun mycos(a:float) returns (o:float)
|
8
examples/extern_C/mathext.h
Normal file
8
examples/extern_C/mathext.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
#ifdef MATHEXT_H
|
||||
#define MATHEXT_H
|
||||
|
||||
struct mycos_out {
|
||||
float o;
|
||||
};
|
||||
|
||||
void mycos(float a, mycos_out *o);
|
Loading…
Reference in a new issue