feat(tp1)

This commit is contained in:
Hugo Meens 2025-03-27 12:42:38 +01:00
commit cdbd983b03
9 changed files with 117 additions and 0 deletions

18
tp1-obj1-meens/Makefile Normal file
View File

@ -0,0 +1,18 @@
LIB_PATH=$(shell heptc -where)
OBJ=first_c/first.c
all: main
$(OBJ): first.ept
heptc -target c $<
main: $(OBJ)
gcc -I $(LIB_PATH)/c -I . main.c $<
clean:
$(RM) *.log
$(RM) *.epci
$(RM) *.mls
$(RM) *.o *.obj *.obc
$(RM) -r *_c
$(RM) *.out

7
tp1-obj1-meens/first.ept Normal file
View File

@ -0,0 +1,7 @@
fun myfun (x:int;y:int) returns (z:int;t:int)
var x2 : int;
let
x2 = x*x ;
t = x2 + 3*x ;
z= t + y ;
tel

15
tp1-obj1-meens/main.c Normal file
View File

@ -0,0 +1,15 @@
#include <stdio.h>
#include "first_c/first.h"
#include "first_c/first_types.h"
void main() {
int x,y ; /* Allocation des entrées */
First__myfun_out o ; /* Allocation des sorties */
for(;;) { /* Boucle infinie */
printf("Inputs:"); scanf("%d%d",&x,&y) ; /* Lecture des entrées */
First__myfun_step(x,y,&o) ; /* Calculs */
printf("Result: z=%d t=%d\n",o.z,o.t) ; /* Ecriture des sorties */
}
}

18
tp1-obj2-meens/Makefile Normal file
View File

@ -0,0 +1,18 @@
LIB_PATH=$(shell heptc -where)
OBJ=first_c/first.c
all: main
$(OBJ): first.ept
heptc -target c $<
main: $(OBJ)
gcc -I $(LIB_PATH)/c -I . main.c $<
clean:
$(RM) *.log
$(RM) *.epci
$(RM) *.mls
$(RM) *.o *.obj *.obc
$(RM) -r *_c
$(RM) *.out

4
tp1-obj2-meens/first.ept Normal file
View File

@ -0,0 +1,4 @@
node sum2(i:int) returns (o:int)
let
o = i + (0 fby i) ;
tel

16
tp1-obj2-meens/main.c Normal file
View File

@ -0,0 +1,16 @@
#include <stdio.h>
#include "first_c/first.h"
#include "first_c/first_types.h"
void main() {
int i ; /* Allocation des entrées */
First__sum2_out o ; /* Allocation des sorties */
First__sum2_mem s ; /* Allocation d l'état */
First__sum2_reset(&s) ; /* Initialisation de l'état */
for(;;) { /* Boucle infinie */
printf("Inputs:"); scanf("%d",&i) ; /* Lecture des entrées */
First__sum2_step(i,&o,&s) ; /* Calculs */
printf("Result: o=%d\n",o.o) ; /* Ecriture des sorties */
}
}

19
tp1-obj3-meens/Makefile Normal file
View File

@ -0,0 +1,19 @@
LIB_PATH=$(shell heptc -where)
OBJ=first_c/first.c
all: main
$(OBJ): first.ept
heptc -target c $<
main: $(OBJ)
gcc -I $(LIB_PATH)/c -I . main.c $<
clean:
$(RM) *.log
$(RM) *.epci
$(RM) *.mls
$(RM) *.o *.obj *.obc
$(RM) -r *_c
$(RM) *.out

4
tp1-obj3-meens/first.ept Normal file
View File

@ -0,0 +1,4 @@
node counter () returns (cnt:int)
let
cnt = 0 fby (cnt+1) ;
tel

16
tp1-obj3-meens/main.c Normal file
View File

@ -0,0 +1,16 @@
#include <stdio.h>
#include <unistd.h>
#include "first_c/first.h"
#include "first_c/first_types.h"
void main() {
First__counter_out o ; /* Allocation des sorties */
First__counter_mem s ; /* Allocation d l'état */
First__counter_reset(&s) ; /* Initialisation de l'état */
for(;;) { /* Boucle infinie */
usleep(10) ; /* A vous d'en choisir un (timer, input, etc.) */
First__counter_step(&o,&s) ;
printf(" Result: cnt=%d\n",o.cnt) ;
}
}