aboutsummaryrefslogtreecommitdiffstats
path: root/tools/ocaml/libs/xl/genwrap.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools/ocaml/libs/xl/genwrap.py')
-rw-r--r--tools/ocaml/libs/xl/genwrap.py15
1 files changed, 14 insertions, 1 deletions
diff --git a/tools/ocaml/libs/xl/genwrap.py b/tools/ocaml/libs/xl/genwrap.py
index b379b57108..42f374eaee 100644
--- a/tools/ocaml/libs/xl/genwrap.py
+++ b/tools/ocaml/libs/xl/genwrap.py
@@ -55,7 +55,8 @@ def ocaml_type_of(ty):
return "int%d" % ty.width
else:
return "int"
-
+ elif isinstance(ty,idl.Array):
+ return "%s array" % ocaml_type_of(ty.elem_type)
elif isinstance(ty,idl.Builtin):
if not builtins.has_key(ty.typename):
raise NotImplementedError("Unknown Builtin %s (%s)" % (ty.typename, type(ty)))
@@ -138,6 +139,8 @@ def c_val(ty, c, o, indent="", parent = None):
if not fn:
raise NotImplementedError("No c_val fn for Builtin %s (%s)" % (ty.typename, type(ty)))
s += "%s;" % (fn % { "o": o, "c": c })
+ elif isinstance (ty,idl.Array):
+ raise("Cannot handle Array type\n")
elif isinstance(ty,idl.Enumeration) and (parent is None):
n = 0
s += "switch(Int_val(%s)) {\n" % o
@@ -195,6 +198,16 @@ def ocaml_Val(ty, o, c, indent="", parent = None):
if not fn:
raise NotImplementedError("No ocaml Val fn for Builtin %s (%s)" % (ty.typename, type(ty)))
s += "%s = %s;" % (o, fn % { "c": c })
+ elif isinstance(ty, idl.Array):
+ s += "{\n"
+ s += "\t int i;\n"
+ s += "\t value array_elem;\n"
+ s += "\t %s = caml_alloc(%s,0);\n" % (o, parent + ty.lenvar.name)
+ s += "\t for(i=0; i<%s; i++) {\n" % (parent + ty.lenvar.name)
+ s += "\t %s\n" % ocaml_Val(ty.elem_type, "array_elem", c + "[i]", "")
+ s += "\t Store_field(%s, i, array_elem);\n" % o
+ s += "\t }\n"
+ s += "\t}"
elif isinstance(ty,idl.Enumeration) and (parent is None):
n = 0
s += "switch(%s) {\n" % c