]> git.mdlowis.com Git - archive/tide-ocaml.git/commitdiff
initial commit of c/ovaml interaction
authorMichael D. Lowis <mike@mdlowis.com>
Tue, 22 Aug 2017 01:50:14 +0000 (21:50 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Tue, 22 Aug 2017 01:50:14 +0000 (21:50 -0400)
Makefile [new file with mode: 0644]
env.ml [new file with mode: 0644]
envprims.c [new file with mode: 0644]
tide [new file with mode: 0755]
tide.ml [new file with mode: 0644]

diff --git a/Makefile b/Makefile
new file mode 100644 (file)
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 (file)
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 (file)
index 0000000..882c194
--- /dev/null
@@ -0,0 +1,24 @@
+#include <curses.h>
+#include <caml/mlvalues.h>
+#include <caml/memory.h>
+#include <caml/alloc.h>
+#include <caml/custom.h>
+#include <stdlib.h>
+
+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 (executable)
index 0000000..0b32a2d
Binary files /dev/null and b/tide differ
diff --git a/tide.ml b/tide.ml
new file mode 100644 (file)
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
+  ()