Source

hello / ocaml / chello.c

#include <caml/mlvalues.h>
#include <caml/memory.h>
#include <caml/threads.h>

#define Nothing ((value) 0)

#include <caml/alloc.h>
#include <caml/fail.h>

#include <stdio.h>

#ifndef __APPLE__
#error "use MacOSX. *BSD and Linux is in progress"
#endif
//__GNUC__ 4
//__amd64 1
//__x86_64 1
//__x86_64__ 1

#define PIN \
  printf("%s:%d entered into %s\n", __FILE__, __LINE__, __func__ );
#define POUT \
  printf("%s:%d get out from %s\n", __FILE__, __LINE__, __func__ );
#define HERE(x) \
  printf("%s:%d in %s -> %p\n", __FILE__, __LINE__, __func__, x );

CAMLprim value hello(value arg){
  CAMLparam1(arg);
  printf("hello %s!\n", String_val(arg));
  CAMLreturn(Val_unit);
}

CAMLprim value env(void){
  CAMLparam0();
  CAMLreturn(caml_copy_string(__VERSION__));
}

CAMLprim value hoge(void){
  CAMLparam0();
  CAMLlocal2(v_res, v_flags);
  int i=10;
  PIN;
  //  printf("len=%d : %p\n", i, v_res);
  v_res = caml_alloc(i, 0);
  while (--i >= 0) {
    value v_ev;
    //    v_flags = caml_copy_int32(23);
    v_ev = caml_alloc_small(2,0); 
    Field(v_ev, 0) = Val_int(i);
    Field(v_ev, 1) = Val_int(23);
    printf("putting (%d,%d)\n", i, 23);
    Store_field(v_res, i, v_ev);
  }
  POUT;
  CAMLreturn(v_res);
}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.