From 7d5fe9e4de472b460125bcb834ef1b3eb8f89f54 Mon Sep 17 00:00:00 2001 From: Hugo Meens Date: Thu, 3 Apr 2025 14:31:53 +0200 Subject: [PATCH] feat(tp2-obj2) --- tp2-obj2-meens/Makefile | 21 +++++++++++++++++++++ tp2-obj2-meens/extern.c | 29 +++++++++++++++++++++++++++++ tp2-obj2-meens/extern.epi | 5 +++++ tp2-obj2-meens/extern.h | 12 ++++++++++++ tp2-obj2-meens/extern_types.h | 6 ++++++ tp2-obj2-meens/hs_handler.ept | 27 +++++++++++++++++++++++++++ tp2-obj2-meens/main.c | 11 +++++++++++ 7 files changed, 111 insertions(+) create mode 100644 tp2-obj2-meens/Makefile create mode 100644 tp2-obj2-meens/extern.c create mode 100644 tp2-obj2-meens/extern.epi create mode 100644 tp2-obj2-meens/extern.h create mode 100644 tp2-obj2-meens/extern_types.h create mode 100644 tp2-obj2-meens/hs_handler.ept create mode 100644 tp2-obj2-meens/main.c diff --git a/tp2-obj2-meens/Makefile b/tp2-obj2-meens/Makefile new file mode 100644 index 0000000..804306f --- /dev/null +++ b/tp2-obj2-meens/Makefile @@ -0,0 +1,21 @@ +LIB_PATH=$(shell heptc -where) +OBJ=extern.c hs_handler_c/hs_handler.c hs_handler_c/hs_handler_types.c + +all: main + +b: hs_handler.ept + heptc -target c $< + +a: extern.epi + heptc $< + +main: $(OBJ) a b + gcc -I $(LIB_PATH)/c -I . main.c $(OBJ) + +clean: + $(RM) *.log + $(RM) *.epci + $(RM) *.mls + $(RM) *.o *.obj *.obc + $(RM) -r *_c + $(RM) *.out diff --git a/tp2-obj2-meens/extern.c b/tp2-obj2-meens/extern.c new file mode 100644 index 0000000..2a13206 --- /dev/null +++ b/tp2-obj2-meens/extern.c @@ -0,0 +1,29 @@ +#include "extern.h" +#include + +void Extern__read_bool_step(int addr, + Extern__read_bool_out*_out) { + printf("read_bool(%d):",addr) ; fflush(stdout) ; + scanf("%d",&(_out->value)) ; +} + +void Extern__f1_step(int i,Extern__f1_out*_out) { + _out->o = i + 5 ; + printf("F1(%d)=%d\n",i,_out->o) ; +} + +void Extern__g_step(Extern__g_out*_out) { + static int s = 250 ; + s += 50 ; + _out->o = s ; + printf("G()=%d\n",_out->o) ; +} + +void Extern__act_step(int addr, Extern__act_out*_out) { + +} + +void Extern__f2_step(int i,Extern__f2_out*_out) { + _out->o = i + 100 ; + printf("F2(%d)=%d\n",i,_out->o) ; +} diff --git a/tp2-obj2-meens/extern.epi b/tp2-obj2-meens/extern.epi new file mode 100644 index 0000000..1db7b60 --- /dev/null +++ b/tp2-obj2-meens/extern.epi @@ -0,0 +1,5 @@ +fun read_bool(addr:int) returns (value:bool) +fun f1 (i:int) returns (o:int) +fun f2 (i:int) returns (o:int) +fun g () returns (o:int) +fun act (i:int) returns () diff --git a/tp2-obj2-meens/extern.h b/tp2-obj2-meens/extern.h new file mode 100644 index 0000000..ff1eefe --- /dev/null +++ b/tp2-obj2-meens/extern.h @@ -0,0 +1,12 @@ +typedef struct { int value ; } Extern__read_bool_out ; +typedef struct { int o ; } Extern__f1_out ; +typedef struct { int o ; } Extern__f2_out ; +typedef struct { int o ; } Extern__g_out ; +typedef struct { } Extern__act_out ; + +void Extern__f1_step(int i,Extern__f1_out*_out) ; +void Extern__f2_step(int i,Extern__f2_out*_out) ; +void Extern__g_step(Extern__g_out*_out) ; +void Extern__read_bool_step(int addr, +Extern__read_bool_out*_out) ; +void Extern__act_step(int addr, Extern__act_out*_out) ; diff --git a/tp2-obj2-meens/extern_types.h b/tp2-obj2-meens/extern_types.h new file mode 100644 index 0000000..863ab7d --- /dev/null +++ b/tp2-obj2-meens/extern_types.h @@ -0,0 +1,6 @@ +#ifndef EXTERN_TYPES_H +#define EXTERN_TYPES_H + + + +#endif /* EXTERN_TYPES_H */ diff --git a/tp2-obj2-meens/hs_handler.ept b/tp2-obj2-meens/hs_handler.ept new file mode 100644 index 0000000..fb192fa --- /dev/null +++ b/tp2-obj2-meens/hs_handler.ept @@ -0,0 +1,27 @@ +open Extern + + +node hs_handler(hs:bool) + returns (id:int) +let + if hs then + id = g() ; + else + var x,y : int; in + y = 15 fby x ; + id = f1(y) ; + x = f2(id) ; + end ; +tel + +const addr_hs:int = 0x2000 (* global constant *) + +node main () returns () +var + hs: bool ; + id : int ; +let + hs = read_bool(addr_hs) ; + id = hs_handler(hs) ; + () = act(id) ; +tel diff --git a/tp2-obj2-meens/main.c b/tp2-obj2-meens/main.c new file mode 100644 index 0000000..0e1a0d6 --- /dev/null +++ b/tp2-obj2-meens/main.c @@ -0,0 +1,11 @@ +#include "hs_handler_c/hs_handler.h" +#include "hs_handler_c/hs_handler_types.h" + +int main() { + Hs_handler__main_out _out; + Hs_handler__main_mem self; + Hs_handler__main_reset(&self); + for (;;) { + Hs_handler__main_step(&_out, &self); + } +}