Lines Matching refs:ty

63 def stub_fn_name(ty, name):  argument
64 return "stub_xl_%s_%s" % (ty.rawname,name)
66 def ocaml_type_of(ty): argument
67 if ty.rawname in ["domid","devid"]:
68 return ty.rawname
69 elif isinstance(ty,idl.UInt):
70 if ty.width in [8, 16]:
73 elif ty.width in [32, 64]:
74 width = ty.width
76 raise NotImplementedError("Cannot handle %d-bit int" % ty.width)
78 return "int%d" % ty.width
81 elif isinstance(ty,idl.Array):
82 return "%s array" % ocaml_type_of(ty.elem_type)
83 elif isinstance(ty,idl.Builtin):
84 if ty.typename not in builtins:
85 raise NotImplementedError("Unknown Builtin %s (%s)" % (ty.typename, type(ty)))
86 typename,_,_ = builtins[ty.typename]
88 raise NotImplementedError("No typename for Builtin %s (%s)" % (ty.typename, type(ty)))
90 elif isinstance(ty,idl.KeyedUnion):
91 return ty.union_name
92 elif isinstance(ty,idl.Aggregate):
93 if ty.rawname is None:
94 return ty.anon_struct
96 return ty.rawname.capitalize() + ".t"
98 return ty.rawname
120 def gen_struct(ty, indent): argument
122 for f in ty.fields:
130 def gen_ocaml_keyedunions(ty, interface, indent, parent = None): argument
134 if ty.rawname is not None:
137 elif isinstance(ty, idl.KeyedUnion):
139 nparent = ty.keyvar.name
141 nparent = parent + "_" + ty.keyvar.name
143 for f in ty.fields:
152 name = "%s__union" % ty.keyvar.name
156 for f in ty.fields:
170 ty.union_name = name
172 union_type = "?%s:%s" % (munge_name(nparent), ty.keyvar.type.rawname)
178 def gen_ocaml_anonstruct(ty, interface, indent, parent = None): argument
181 if ty.rawname is not None:
184 elif isinstance(ty, idl.Struct):
187 s += gen_struct(ty, indent)
189 ty.anon_struct = name
195 def gen_ocaml_ml(ty, interface, indent=""): argument
198 s = ("""(* %s interface *)\n""" % ty.typename)
200 s = ("""(* %s implementation *)\n""" % ty.typename)
202 if isinstance(ty, idl.Enumeration):
203 s += "type %s = \n" % ty.rawname
204 for v in ty.values:
208 s += "\nval string_of_%s : %s -> string\n" % (ty.rawname, ty.rawname)
210 s += "\nlet string_of_%s = function\n" % ty.rawname
211 for v in ty.values:
214 elif isinstance(ty, idl.Aggregate):
217 if ty.typename is None:
218 raise NotImplementedError("%s has no typename" % type(ty))
221 module_name = ty.rawname[0].upper() + ty.rawname[1:]
230 for f in ty.fields:
239 for f in ty.fields:
247 s += gen_struct(ty, "\t\t")
250 if ty.init_fn is not None:
255 … += "\texternal default : ctx -> %sunit -> t = \"stub_libxl_%s_init\"\n" % (union_args, ty.rawname)
257 if ty.rawname in functions:
258 for name,args in functions[ty.rawname]:
261 s += " = \"%s\"\n" % stub_fn_name(ty,name)
266 raise NotImplementedError("%s" % type(ty))
269 def c_val(ty, c, o, indent="", parent = None): argument
271 if isinstance(ty,idl.UInt):
272 if ty.width in [8, 16]:
275 elif ty.width in [32, 64]:
276 width = ty.width
278 raise NotImplementedError("Cannot handle %d-bit int" % ty.width)
283 elif isinstance(ty,idl.Builtin):
284 if ty.typename not in builtins:
285 raise NotImplementedError("Unknown Builtin %s (%s)" % (ty.typename, type(ty)))
286 _,fn,_ = builtins[ty.typename]
288 raise NotImplementedError("No c_val fn for Builtin %s (%s)" % (ty.typename, type(ty)))
290 elif isinstance (ty,idl.Array):
293 s += "\t%s = Wosize_val(%s);\n" % (parent + ty.lenvar.name, o)
294 s += "\t%s = (%s) calloc(%s, sizeof(*%s));\n" % (c, ty.typename, parent + ty.lenvar.name, c)
295 s += "\tfor(i=0; i<%s; i++) {\n" % (parent + ty.lenvar.name)
296 s += c_val(ty.elem_type, c+"[i]", "Field(%s, i)" % o, indent="\t\t", parent=parent) + "\n"
299 elif isinstance(ty,idl.Enumeration) and (parent is None):
302 for e in ty.values:
305 …s += " default: failwith_xl(ERROR_FAIL, \"cannot convert value to %s\"); break;\n" % ty.typename
307 elif isinstance(ty, idl.KeyedUnion):
312 for f in ty.fields:
315 parent + ty.keyvar.name,
318 …failwith_xl(ERROR_FAIL, \"variant handling bug %s%s (long)\"); break;\n" % (parent, ty.keyvar.name)
324 for f in ty.fields:
329 s += "\t\t %s = %s;\n" % (parent + ty.keyvar.name, f.enumname)
330 (nparent,fexpr) = ty.member(c, f, False)
334 …ailwith_xl(ERROR_FAIL, \"variant handling bug %s%s (block)\"); break;\n" % (parent, ty.keyvar.name)
338 elif isinstance(ty, idl.Aggregate) and (parent is None or ty.rawname is None):
340 for f in ty.fields:
343 (nparent,fexpr) = ty.member(c, f, ty.rawname is not None)
347 …s += "%s_val(ctx, %s, %s);" % (ty.rawname, ty.pass_arg(c, parent is None, passby=idl.PASS_BY_REFER…
351 def gen_c_val(ty, indent=""): argument
352 s = "/* Convert caml value to %s */\n" % ty.rawname
354 …s += "static int %s_val (libxl_ctx *ctx, %s, value v)\n" % (ty.rawname, ty.make_arg("c_val", passb…
359 s += c_val(ty, "c_val", "v", indent="\t") + "\n"
366 def ocaml_Val(ty, o, c, indent="", parent = None): argument
368 if isinstance(ty,idl.UInt):
369 if ty.width in [8, 16]:
372 elif ty.width in [32, 64]:
373 width = ty.width
375 raise NotImplementedError("Cannot handle %d-bit int" % ty.width)
380 elif isinstance(ty,idl.Builtin):
381 if ty.typename not in builtins:
382 raise NotImplementedError("Unknown Builtin %s (%s)" % (ty.typename, type(ty)))
383 _,_,fn = builtins[ty.typename]
385 … raise NotImplementedError("No ocaml Val fn for Builtin %s (%s)" % (ty.typename, type(ty)))
387 elif isinstance(ty, idl.Array):
391 s += "\t %s = caml_alloc(%s,0);\n" % (o, parent + ty.lenvar.name)
392 s += "\t for(i=0; i<%s; i++) {\n" % (parent + ty.lenvar.name)
393 s += "\t %s\n" % ocaml_Val(ty.elem_type, "array_elem", c + "[i]", "", parent=parent)
397 elif isinstance(ty,idl.Enumeration) and (parent is None):
400 for e in ty.values:
403 …+= " default: failwith_xl(ERROR_FAIL, \"cannot convert value from %s\"); break;\n" % ty.typename
405 elif isinstance(ty, idl.KeyedUnion):
408 s += "switch(%s) {\n" % (parent + ty.keyvar.name)
409 for f in ty.fields:
421 (nparent,fexpr) = ty.member(c, f, parent is None)
432 … "\t default: failwith_xl(ERROR_FAIL, \"cannot convert value from %s\"); break;\n" % ty.typename
434 elif isinstance(ty,idl.Aggregate) and (parent is None or ty.rawname is None):
436 if ty.rawname is None:
439 fn = "%s_field" % ty.rawname
442 s += "\t%s = caml_alloc_tuple(%d);\n" % (o, len(ty.fields))
445 for f in ty.fields:
449 (nparent,fexpr) = ty.member(c, f, parent is None)
452 s += "\t%s\n" % ocaml_Val(f.type, fn, ty.pass_arg(fexpr, c), parent=nparent)
457 s += "%s = Val_%s(%s);" % (o, ty.rawname, ty.pass_arg(c, parent is None))
461 def gen_Val_ocaml(ty, indent=""): argument
462 s = "/* Convert %s to a caml value */\n" % ty.rawname
464 s += "static value Val_%s (%s)\n" % (ty.rawname, ty.make_arg(ty.rawname+"_c"))
467 s += "\tCAMLlocal1(%s_ocaml);\n" % ty.rawname
469 s += ocaml_Val(ty, "%s_ocaml" % ty.rawname, "%s_c" % ty.rawname, indent="\t") + "\n"
471 s += "\tCAMLreturn(%s_ocaml);\n" % ty.rawname
475 def gen_c_stub_prototype(ty, fns): argument
476 s = "/* Stubs for %s */\n" % ty.rawname
479 s += "value %s(" % stub_fn_name(ty, name)
484 def gen_c_default(ty): argument
485 s = "/* Get the defaults for %s */\n" % ty.rawname
488 for f in ty.fields:
492 s += "value stub_libxl_%s_init(value ctx, %svalue unit)\n" % (ty.rawname,
497 s += "\tlibxl_%s c_val;\n" % ty.rawname
498 s += "\tlibxl_%s_init(&c_val);\n" % ty.rawname
503 s += "\t\tlibxl_%s_init_%s(&c_val, c);\n" % (ty.rawname, u.name)
505 s += "\tval = Val_%s(&c_val);\n" % ty.rawname
506 if ty.dispose_fn:
507 s += "\tlibxl_%s_dispose(&c_val);\n" % ty.rawname
512 def gen_c_defaults(ty): argument
513 s = gen_c_default(ty)
538 if t not in [ty.rawname for ty in types]:
541 types = [ty for ty in types if not ty.rawname in blacklist]
555 for ty in types:
556 if ty.private:
559 ml.write(gen_ocaml_ml(ty, False))
562 mli.write(gen_ocaml_ml(ty, True))
565 if ty.marshal_in():
566 cinc.write(gen_c_val(ty))
568 cinc.write(gen_Val_ocaml(ty))
570 if ty.rawname in functions:
571 cinc.write(gen_c_stub_prototype(ty, functions[ty.rawname]))
573 if ty.init_fn is not None:
574 cinc.write(gen_c_defaults(ty))