+
+ rhs = makeStgPrim(n,addState,extra_args,
+ descriptor->arg_tys,
+ descriptor->result_tys);
+ v = mkStgVar(rhs,NIL);
+ name(n).defn = NIL;
+ name(n).closure = v;
+ addToCodeList ( currentModule, n );
+ }
+
+ /* At this point the descriptor contains a tag for each arg,
+ because that makes makeStgPrim generate the correct unwrap
+ code. From now on, the descriptor is only used at the time
+ the actual ccall is made. So we need to zap the leading
+ addr arg IF this is a f-i-dynamic call.
+ */
+ if (dynamic) {
+ descriptor->arg_tys++;
+ descriptor->num_args--;
+ }
+}
+
+
+
+/* Generate code:
+ *
+ * \ fun ->
+ let e1 = A# "...."
+ e3 = C# 'c' -- (ccall), or 's' (stdcall)
+ in primMkAdjThunk fun e1 e3
+
+ we require, and check that,
+ fun :: prim_arg* -> IO prim_result
+ */
+Text makeTypeDescrText ( Type t )
+{
+ List argTys = NIL;
+ List resultTys = NIL;
+ List tdList;
+
+#if 0
+ // I don't understand what this achieves.
+ if (getHead(t)==typeArrow && argCount==2) {
+ t = arg(fun(t));
+ } else {
+ return NIL;
+ }
+#endif
+ while (getHead(t)==typeArrow && argCount==2) {
+ Type ta = fullExpand(arg(fun(t)));
+ Type tr = arg(t);
+ argTys = cons(ta,argTys);
+ t = tr;
+ }
+ argTys = rev(argTys);
+ if (getHead(t) == typeIO) {
+ resultTys = getArgs(t);
+ assert(length(resultTys) == 1);
+ resultTys = hd(resultTys);
+ } else {
+ return NIL;