feat(tp2-obj3)
This commit is contained in:
parent
7d5fe9e4de
commit
43d7ae87d6
21
tp2-obj3-meens/Makefile
Normal file
21
tp2-obj3-meens/Makefile
Normal file
@ -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
|
||||
|
||||
a: extern.epi
|
||||
heptc $<
|
||||
|
||||
$(OBJ): hs_handler.ept a
|
||||
heptc -target c $<
|
||||
|
||||
main: $(OBJ)
|
||||
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
|
29
tp2-obj3-meens/extern.c
Normal file
29
tp2-obj3-meens/extern.c
Normal file
@ -0,0 +1,29 @@
|
||||
#include "extern.h"
|
||||
#include <stdio.h>
|
||||
|
||||
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) ;
|
||||
}
|
5
tp2-obj3-meens/extern.epi
Normal file
5
tp2-obj3-meens/extern.epi
Normal file
@ -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 ()
|
12
tp2-obj3-meens/extern.h
Normal file
12
tp2-obj3-meens/extern.h
Normal file
@ -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) ;
|
6
tp2-obj3-meens/extern_types.h
Normal file
6
tp2-obj3-meens/extern_types.h
Normal file
@ -0,0 +1,6 @@
|
||||
#ifndef EXTERN_TYPES_H
|
||||
#define EXTERN_TYPES_H
|
||||
|
||||
|
||||
|
||||
#endif /* EXTERN_TYPES_H */
|
29
tp2-obj3-meens/hs_handler.ept
Normal file
29
tp2-obj3-meens/hs_handler.ept
Normal file
@ -0,0 +1,29 @@
|
||||
open Extern
|
||||
|
||||
|
||||
node hs_handler(hs:bool)
|
||||
returns (id:int)
|
||||
var x,y,id1,id2 : int;
|
||||
let
|
||||
id1 = g() when hs;
|
||||
|
||||
y = (15 fby x);
|
||||
id2 = f1(y);
|
||||
x = f2(id2);
|
||||
|
||||
id = merge hs
|
||||
(true -> id1)
|
||||
(false -> id2);
|
||||
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
|
11
tp2-obj3-meens/main.c
Normal file
11
tp2-obj3-meens/main.c
Normal file
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user