From 618a40391f353f236c007038147a7b3771032f15 Mon Sep 17 00:00:00 2001 From: Ian Campbell Date: Fri, 6 Jul 2012 13:17:40 +0100 Subject: libxl: add a new Array type to the IDL And make all the required infrastructure updates to enable this. Since there are currently no uses of this type there is no change to the generated code. Signed-off-by: Ian Campbell Tested-by: Dario Faggioli Acked-by: Ian Jackson Committed-by: Ian Campbell --- tools/ocaml/libs/xl/genwrap.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'tools/ocaml') 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 -- cgit v1.2.3