From: Michael D. Lowis Date: Tue, 22 Aug 2017 01:50:14 +0000 (-0400) Subject: initial commit of c/ovaml interaction X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=d6884d22e108c3aea2272c23ac2b3a65ad729cce;p=archive%2Ftide-ocaml.git initial commit of c/ovaml interaction --- d6884d22e108c3aea2272c23ac2b3a65ad729cce diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..750fca8 --- /dev/null +++ b/Makefile @@ -0,0 +1,25 @@ +OC = ocamlopt +OCMKLIB = ocamlmklib + +.PHONY: all clean + +env.cmxa: env.cmx envprims.o +tide: env.cmxa tide.cmx + +all: tide + +clean: + $(RM) *.cm* *.o *.a + +%: + $(OC) -o $@ $^ -I . + +%.cmxa: + $(OCMKLIB) -custom -o $* $^ + +%.cmx: %.ml + $(OC) -c -o $@ $^ + +%.o: %.c + $(OC) $(OCFLAGS) -c -o $@ $^ + diff --git a/env.ml b/env.ml new file mode 100644 index 0000000..0dd6c17 --- /dev/null +++ b/env.ml @@ -0,0 +1,4 @@ +(* Environment variable management routines *) +external set : string -> string -> int = "caml_env_set" +external get : string -> string = "caml_env_get" +external unset : string -> int = "caml_env_unset" diff --git a/envprims.c b/envprims.c new file mode 100644 index 0000000..882c194 --- /dev/null +++ b/envprims.c @@ -0,0 +1,24 @@ +#include +#include +#include +#include +#include +#include + +CAMLprim value caml_env_set(value var, value val) { + CAMLparam2(var, val); + puts("foo"); + CAMLreturn(Val_int(0)); +} + +CAMLprim value caml_env_get(value var) { + CAMLparam1(var); + puts("bar"); + CAMLreturn(caml_copy_string("")); +} + +CAMLprim value caml_env_unset(value var) { + CAMLparam1(var); + puts("baz"); + CAMLreturn(Val_int(0)); +} diff --git a/tide b/tide new file mode 100755 index 0000000..0b32a2d Binary files /dev/null and b/tide differ diff --git a/tide.ml b/tide.ml new file mode 100644 index 0000000..f2fe740 --- /dev/null +++ b/tide.ml @@ -0,0 +1,7 @@ +open Env + +let () = + let foo = Env.set "foo" "bar" in + let bar = Env.get "foo" in + let baz = Env.unset "foo" in + ()