diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 26531ac728e7ebf70339b2de4b305137fba0be7a..695e28d46a95d6ed5478e2cbd6155b1025c40082 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,4 +1,4 @@ -image: ocaml/opam2:ubuntu +image: ocaml/opam2:ubuntu-18.04 variables: GIT_STRATEGY: clone diff --git a/lib/luciole.ml b/lib/luciole.ml index 915b2483044b3aa54c7a1c7a7d261ea133d23959..e8127119cf3bd317b3cddd98296f1cf1f2bfaad9 100644 --- a/lib/luciole.ml +++ b/lib/luciole.ml @@ -1,4 +1,4 @@ -(* Time-stamp: <modified the 23/08/2019 (at 11:34) by Erwan Jahier> *) +(* Time-stamp: <modified the 23/07/2020 (at 11:35) by Erwan Jahier> *) (*----------------------------------------------------------------------- ** This file may only be copied under the terms of the CeCill ** Public License @@ -57,41 +57,41 @@ let (_gen_makefile :string -> unit) = (* exported *) -let (gen_stubs : string -> vn_ct list -> vn_ct list -> unit) = - fun str inputs outputs -> - let oc = open_out (str^"_luciole.c") in - let p s = output_string oc s in - let pn s = p (s^"\n") in - - let d2r = function - | "_real" | "real" | "float" | "double" -> "real" - | "_bool" | "bool" -> "bool" - | "_int" -> "int" - | _e -> "int" - in - let vn_ct_to_array (vn, ct) = - pn (" {\""^vn^"\", \""^(d2r ct)^"\", NULL},") - in - let _vn_ct_to_output_functions i (vn,ct) = - pn ("void "^str^"_O_"^vn^"("^str^"_ctx* cdata, "^ - (ct)^" val){"); - pn (" _THIS->_"^vn^" = val;"); - pn "}"; - (i+1) - in +let (gen_stubs : ?boot: bool -> string -> vn_ct list -> vn_ct list -> unit) = + fun ?(boot=true) str inputs outputs -> + let oc = open_out (str^"_luciole.c") in + let p s = output_string oc s in + let pn s = p (s^"\n") in - let vn_ct_to_input_init i (vn,_ct) = - pn (" _intab["^(string_of_int i)^"].valptr = (void*)(& _THIS->_"^vn^");"); - (i+1) - in - let vn_ct_to_output_init i (vn,_ct) = - pn (" _outab["^(string_of_int i)^"].valptr = (void*)(& _THIS->_"^vn^");"); - (i+1) - in - let simec_version_number = "1.1" in - - p (Mypervasives.entete "// " LutilsVersion.str LutilsVersion.sha); - pn "/* droconf.h begins */ + let d2r = function + | "_real" | "real" | "float" | "double" -> "real" + | "_bool" | "bool" -> "bool" + | "_int" -> "int" + | _e -> "int" + in + let vn_ct_to_array (vn, ct) = + pn (" {\""^vn^"\", \""^(d2r ct)^"\", NULL},") + in + let _vn_ct_to_output_functions i (vn,ct) = + pn ("void "^str^"_O_"^vn^"("^str^"_ctx* cdata, "^ + (ct)^" val){"); + pn (" _THIS->_"^vn^" = val;"); + pn "}"; + (i+1) + in + + let vn_ct_to_input_init i (vn,_ct) = + pn (" _intab["^(string_of_int i)^"].valptr = (void*)(& _THIS->_"^vn^");"); + (i+1) + in + let vn_ct_to_output_init i (vn,_ct) = + pn (" _outab["^(string_of_int i)^"].valptr = (void*)(& _THIS->_"^vn^");"); + (i+1) + in + let simec_version_number = "1.1" in + + p (Mypervasives.entete "// " LutilsVersion.str LutilsVersion.sha); + pn "/* droconf.h begins */ /* Struct necessary for building a DRO archive (Dynamically linkable Reactive Object) @@ -103,67 +103,59 @@ Such an archive can be loaded by simec/luciole /* should be of type type dro_desc_t */ #define DRO_DESC_NAME dro_desc struct dro_var_t { - const char* ident; - const char* type; - void* valptr; +const char* ident; +const char* type; +void* valptr; }; struct dro_desc_t { - const char* version; - const char* name; - int nbins; - struct dro_var_t* intab; - int nbouts; - struct dro_var_t* outab; - int ( *step )(); - void ( *reset )(); - void ( *init )(); +const char* version; +const char* name; +int nbins; +struct dro_var_t* intab; +int nbouts; +struct dro_var_t* outab; +int ( *step )(); +void ( *reset )(); +void ( *init )(); }; /* droconf.h ends */ "; - pn "#include \"stdlib.h\""; - pn "#include <stdio.h>"; - pn "#include <string.h>"; + pn "#include \"stdlib.h\""; + pn "#include <stdio.h>"; + pn "#include <string.h>"; - pn "typedef int _bool;"; - pn "typedef int _int;"; - pn "typedef double _real;"; - pn "struct _luciole_ctx {"; - pn "// INPUTS"; - List.iter - (fun (vn,t) -> pn (" _"^ t ^ " _" ^ vn ^";")) - inputs; - pn "// OUTPUTS"; - List.iter - (fun (vn,t) -> pn (" _"^ t ^ " _" ^ vn ^";")) - outputs; - pn "};"; - pn "typedef struct _luciole_ctx luciole_ctx;"; - pn "static luciole_ctx* _THIS = NULL;"; - - pn "// inputs array"; - pn "struct dro_var_t _intab[] = {"; - List.iter vn_ct_to_array inputs; - pn "}; "; - pn ""; - pn "// outputs array "; - pn "struct dro_var_t _outab[] = {"; - List.iter vn_ct_to_array outputs; - pn "};"; - pn ""; + pn "typedef int _bool;"; + pn "typedef int _int;"; + pn "typedef double _real;"; + pn "struct _luciole_ctx {"; + pn "// INPUTS"; + List.iter + (fun (vn,t) -> pn (" _"^ t ^ " _" ^ vn ^";")) + inputs; + pn "// OUTPUTS"; + List.iter + (fun (vn,t) -> pn (" _"^ t ^ " _" ^ vn ^";")) + outputs; + pn "};"; + pn "typedef struct _luciole_ctx luciole_ctx;"; + pn "static luciole_ctx* _THIS = NULL;"; - pn "void __do_reset(){"; - pn "// create"; - pn " fprintf(stdout,\"#reset\\n\");"; - pn " fprintf(stderr,\"reseting !!!\\n\");"; - pn "fflush(stdout);"; - pn " _THIS = malloc(sizeof(luciole_ctx));"; - ignore (List.fold_left vn_ct_to_input_init 0 inputs); - ignore (List.fold_left vn_ct_to_output_init 0 outputs); - - pn "}"; + pn "// inputs array"; + pn "struct dro_var_t _intab[] = {"; + List.iter vn_ct_to_array inputs; + pn "}; "; + pn ""; + pn "// outputs array "; + pn "struct dro_var_t _outab[] = {"; + List.iter vn_ct_to_array outputs; + pn "};"; + pn ""; + + pn "void __do_reset();"; + pn "void __do_init();"; - pn " + pn " #define LINEMAXSIZE 256 void _read_pragma(char b[LINEMAXSIZE]) { int s = 1; @@ -236,55 +228,67 @@ void _put_real(_real _V){ printf(\"%f\\n\", _V); } "; - pn "int __do_step();"; - pn "int internal_step(){"; - pn " return __do_step();"; - pn "}"; - pn "void __do_reset();"; - pn "void internal_reset(){"; - pn " return __do_reset();"; - pn "}"; - pn "void __do_init();"; - pn "void internal_init(){"; - pn " return __do_init();"; - pn "}"; + pn "void __do_reset(){"; + pn "fprintf(stdout,\"#reset\\n\");"; + pn " fprintf(stderr,\"reseting !!!\\n\");"; + pn "fflush(stdout);"; + pn " _THIS = malloc(sizeof(luciole_ctx));"; + ignore (List.fold_left vn_ct_to_input_init 0 inputs); + ignore (List.fold_left vn_ct_to_output_init 0 outputs); + pn "}"; - pn "// "; - pn "struct dro_desc_t DRO_DESC_NAME = {"; - pn (" \""^simec_version_number^"\","); - pn (" \""^str^"\","); - pn (" "^(string_of_int (List.length inputs))^","); - pn " _intab,"; - pn (" "^(string_of_int (List.length outputs))^","); - pn " _outab,"; - pn " internal_step,"; - pn " internal_reset,"; - pn " internal_init"; - pn "};"; - pn ""; - pn "int __do_step(){"; - pn "if(_THIS) {"; + pn "void __do_init(){"; + pn " //reset or create"; + pn " if(_THIS) {"; + pn " // nop"; + pn " } else {"; + pn " fprintf(stderr,\"initing !!!\\n\");"; + pn " _THIS = malloc(sizeof(luciole_ctx));"; + ignore (List.fold_left vn_ct_to_input_init 0 inputs); + ignore (List.fold_left vn_ct_to_output_init 0 outputs); + if not boot then + List.iter (fun (vn,vt) -> pn (" _THIS->_" ^ vn ^ " = _get_"^vt^"();")) outputs; + pn " }"; + pn "}"; - List.iter (fun (vn,vt) -> pn (" _put_"^vt^"(_THIS->_" ^ vn ^");")) inputs; - pn " fflush(stdout);"; - List.iter (fun (vn,vt) -> pn (" _THIS->_" ^ vn ^ " = _get_"^vt^"();")) outputs; - pn " //always happy..."; - pn " return 0;"; - pn " } else {"; - pn " printf(\"initialisation problem\\n\");"; - pn " return 2;"; - pn " }"; - pn "}"; + pn "int __do_step();"; + pn "int internal_step(){"; + pn " return __do_step();"; + pn "}"; + pn "void internal_reset(){"; + pn " return __do_reset();"; + pn "}"; + pn "void internal_init(){"; + pn " return __do_init();"; + pn "}"; - pn "void __do_init(){"; - pn " //reset or create"; - pn " if(_THIS) {"; - pn " // nop"; - pn " } else {"; - pn " __do_reset();"; - pn " }"; - pn " }"; - flush oc; - close_out oc; - print_string ("File " ^ str ^ "_luciole.c has been created\n"); - flush stdout + pn "// "; + pn "struct dro_desc_t DRO_DESC_NAME = {"; + pn (" \""^simec_version_number^"\","); + pn (" \""^str^"\","); + pn (" "^(string_of_int (List.length inputs))^","); + pn " _intab,"; + pn (" "^(string_of_int (List.length outputs))^","); + pn " _outab,"; + pn " internal_step,"; + pn " internal_reset,"; + pn " internal_init"; + pn "};"; + pn ""; + pn "int __do_step(){"; + pn "if(_THIS) {"; + List.iter (fun (vn,vt) -> pn (" _put_"^vt^"(_THIS->_" ^ vn ^");")) inputs; + pn " fflush(stdout);"; + List.iter (fun (vn,vt) -> pn (" _THIS->_" ^ vn ^ " = _get_"^vt^"();")) outputs; + pn " //always happy..."; + pn " return 0;"; + pn " } else {"; + pn " printf(\"initialisation problem\\n\");"; + pn " return 2;"; + pn " }"; + pn "}"; + + flush oc; + close_out oc; + print_string ("File " ^ str ^ "_luciole.c has been created\n"); + flush stdout diff --git a/lib/luciole.mli b/lib/luciole.mli index 73b88a7ef44942b11bec3506b5bca74f98627561..f18088952e1d83f9caec58c9784d1ae1cfb52567 100644 --- a/lib/luciole.mli +++ b/lib/luciole.mli @@ -10,7 +10,10 @@ type vn_ct = string * string - inputs is the list or the luciole process var names and types - outputs ditto for outputs +if the optional argument boot is set to false (it is true by default), inputs are +read before output are produced + *) -val gen_stubs : string -> vn_ct list -> vn_ct list -> unit +val gen_stubs : ?boot: bool -> string -> vn_ct list -> vn_ct list -> unit diff --git a/lib/rifIO.ml b/lib/rifIO.ml index 99f16f44cce639c2119245dc5f2e901352f79388..511b20cd1ed1889c97cbbf64cfdbff3114ac9441 100644 --- a/lib/rifIO.ml +++ b/lib/rifIO.ml @@ -1,4 +1,4 @@ -(* Time-stamp: <modified the 13/03/2020 (at 10:18) by Erwan Jahier> *) +(* Time-stamp: <modified the 11/06/2020 (at 11:06) by Erwan Jahier> *) (*----------------------------------------------------------------------- ** This file may only be copied under the terms of the CeCILL ** Public License @@ -226,8 +226,8 @@ and (parse_rif_stream : I(i) | e -> print_string ("\n*** Type Error: float found, "^ - (Data.type_to_string e) ^ "expected\n"); - assert false + (Data.type_to_string e) ^ " expected\n"); + exit 2 in let tbl = tbl@ [fst (hd vntl), v] in parse_rif_stream label ic oc (tl vntl) (str,stream) tbl pragma @@ -248,8 +248,8 @@ and (parse_rif_stream : | Data.String -> Data.Str (string_of_int i) | e -> print_string ("\n*** Type Error: int found, "^ (Data.type_to_string e) - ^ "expected \n"); - assert false + ^ "e xpected \n"); + exit 2 in let tbl = tbl @[fst (hd vntl), v] in parse_rif_stream label ic oc (tl vntl) (str,stream) tbl pragma @@ -264,7 +264,6 @@ and (parse_rif_stream : Stream.junk stream ; let v = if mem b ["f"; "F";"false"] then B(false) else if mem b ["t"; "T";"true"] then B(true) - else if mem b ["nil";"?";" ?"] then assert false else Str(b) in let tbl = tbl @ [fst (hd vntl), v] in