Jianzhou Zhao
2010-Feb-28 16:38 UTC
[LLVMdev] Tag number of OCaml Variant in executionengine
Hi, At the code below from ./bindings/ocaml/executionengine/executionengine_ocaml.c, we create an OCaml Variant from C. It is from 2.6, the latest 2.7 has the same code. Line 240 Option = alloc(1, 1) assigns tag1 to the 'some' constructor. In term of http://caml.inria.fr/pub/docs/manual-ocaml/manual032.html, I think the 'some' should have a tag 0. We dont have a runtime error for this, the reason might be there is only two constructors, one is None represented as unboxed int, the other is Some represented as a tagged block, and OCaml runtime may only distinguish them as the structures, but not the tag number. Zjz 233 /* string -> ExecutionEngine.t -> llvalue option */ 234 CAMLprim value llvm_ee_find_function(value Name, LLVMExecutionEngineRef EE) { 235 CAMLparam1(Name); 236 CAMLlocal1(Option); 237 LLVMValueRef Found; 238 if (LLVMFindFunction(EE, String_val(Name), &Found)) 239 CAMLreturn(Val_unit); 240 Option = alloc(1, 1); 241 Field(Option, 0) = Val_op(Found); 242 CAMLreturn(Option); 243 }
Erick Tryzelaar
2010-Feb-28 23:48 UTC
[LLVMdev] Tag number of OCaml Variant in executionengine
On Sun, Feb 28, 2010 at 8:38 AM, Jianzhou Zhao <jianzhou at seas.upenn.edu> wrote:> Hi, > > At the code below from > ./bindings/ocaml/executionengine/executionengine_ocaml.c, > we create an OCaml Variant from C. It is from 2.6, the latest 2.7 has > the same code. > > Line 240 Option = alloc(1, 1) assigns tag1 to the 'some' constructor. > In term of http://caml.inria.fr/pub/docs/manual-ocaml/manual032.html, > I think the 'some' should have a tag 0. We dont have a runtime error > for this, the reason might be there is only two constructors, one > is None represented as unboxed int, the other is Some represented > as a tagged block, and OCaml runtime may only distinguish them > as the structures, but not the tag number.Sounds reasonable. I'll make the change to make things more consistent. Also, I see that we aren't properly protecting our option values against the GC in a couple places. I'll make those changes too. -e
Jianzhou Zhao
2010-Mar-01 15:34 UTC
[LLVMdev] Tag number of OCaml Variant in executionengine
Another quick question. In ./bindings/ocaml/Makefile.ocaml, the configurations when ENABLE_OPTIMIZED<>1 are commented, which set -g flag to $(OCAMLC). Is that for back-compatibility to support OCaml < 3.10.0? On Sun, Feb 28, 2010 at 6:48 PM, Erick Tryzelaar <idadesub at users.sourceforge.net> wrote:> On Sun, Feb 28, 2010 at 8:38 AM, Jianzhou Zhao <jianzhou at seas.upenn.edu> wrote: >> Hi, >> >> At the code below from >> ./bindings/ocaml/executionengine/executionengine_ocaml.c, >> we create an OCaml Variant from C. It is from 2.6, the latest 2.7 has >> the same code. >> >> Line 240 Option = alloc(1, 1) assigns tag1 to the 'some' constructor. >> In term of http://caml.inria.fr/pub/docs/manual-ocaml/manual032.html, >> I think the 'some' should have a tag 0. We dont have a runtime error >> for this, the reason might be there is only two constructors, one >> is None represented as unboxed int, the other is Some represented >> as a tagged block, and OCaml runtime may only distinguish them >> as the structures, but not the tag number. > > Sounds reasonable. I'll make the change to make things more > consistent. Also, I see that we aren't properly protecting our option > values against the GC in a couple places. I'll make those changes too. > > -e >-- Jianzhou
Maybe Matching Threads
- [LLVMdev] Tag number of OCaml Variant in executionengine
- [LLVMdev] Tag number of OCaml Variant in executionengine
- [LLVMdev] Tag number of OCaml Variant in executionengine
- [LLVMdev] Tag number of OCaml Variant in executionengine
- [LLVMdev] Ocaml bindings in 2.8