pike.git / src / post_modules / GL / gen.pike

version» Context lines:

pike.git/src/post_modules/GL/gen.pike:11:    Q=int/float    Z=(byte/)double/float/int/short       +XXXX = 3/4/array(3/4)    +XXX = 2/3/4/array(2/3/4)    +XX = 1/2/array(1/2)    +X = 1/2/3/4/array(1/2/3/4)    =XXXX = 4/array(4)    =XXX = 3/array(3)    @X = 1/array(n) -  [nnX = array(nn) +  ]X = array() (No size limit) +  [nnX = array() (Limited to nn elements)       # = like =, but add count    ! = like =, but no vector version available       image object support:       w = width of image    h = height of image    f = format of image    t = type of image
pike.git/src/post_modules/GL/gen.pike:37:   inherit "constants";      void error(string msg, mixed ... args)   {    if(sizeof(args))    msg = sprintf(msg, @args);    werror(msg+"\n");    exit(1);   }    + /* +  *! Generate an array with information about how the function may +  *! be called. This function is used to generate prototype information +  *! for functions which may accept 1/2/3/4/array() parameters. +  *! +  *! @arg mi +  *! Minimum number of arguments which should be accepted. Only the mi first +  *! arguments will be required, the rest may be void. +  *! +  *! @arg mx +  *! Maximum number of arguments which should be accepted. +  *! +  *! @arg a +  *! If 0, output allows for non-arrays. +  *! If 1, output only allows for arrays. +  *! +  *! @arg ty +  *! Argument type, one of E, B, I, O, D, F, R, Z, Q. +  *! +  *! @returns +  *! array(array(string), string, string, string) where +  *! the first element is an array containing the prototype for +  *! each paramter for this function. +  *! +  *! The second element is some strange thing. +  *! +  *! The third element is the types of values that may be passed +  *! as parameters to the function. This is used to check input to +  *! the function. +  *! +  *! The fourth element describes, as a string, what types of input the +  *! function accepts. This value is used to choose which lowlevel GL function +  *! to call. +  */   array(string|array(string)) special_234(int mi, int mx, string ty, int|void a)   {    string tm="BIT_FLOAT|BIT_INT", baset="float|int", rt="if";    array(string) typ=({});    int i, ad;    if(sizeof(Array.uniq(values(ty)))!=1)    error("Unparsable 234 type '%s'.", ty);    switch(ty[0]) {    case 'E':    case 'B':
pike.git/src/post_modules/GL/gen.pike:82:    if(a)    typ+=({"array("+baset+")"});    else for(i=0; i<mx; i++) {    string t = baset;    if(!i)    t+="|array("+baset+")";    if(i>=mi || i>0)    t+="|void";    typ+=({t});    } -  return ({typ,tm,rows((['i':"ZT_INT",'f':"ZT_FLOAT",'d':"ZT_DOUBLE"]), +  array ret = ({typ,tm,rows((['i':"ZT_INT",'f':"ZT_FLOAT",'d':"ZT_DOUBLE"]),    values(rt))*"|",rt}); -  +  return ret;   }      array(string) gen_func(string name, string ty)   {    string res="", got="", prot, vdec, vret, vcast, fu=name;    array novec, args=({}), argt=({});    int r234, argt_cut=-1, img_obj=0, polya=-1;    string rtypes;       switch(ty[0]) {
pike.git/src/post_modules/GL/gen.pike:212:    i=sizeof(ty);    break;    case '[':    int nn;    string rst;    sscanf(ty[i+1..], "%d%s", nn, rst);    array arrfix = special_234(nn, nn, rst, 1);    res += " union zvalue16 zv16;\n int r1n;\n";    argt += arrfix[0];    got += " if(Pike_sp["+(a-1)+"-args].u.array->size != "+nn+")\n" -  " Pike_error(\""+name+": Array length is wrong (is %d, should be "+nn+ -  ")\\n\", Pike_sp["+(a-1)+"-args].u.array->size);\n\n"; +  " Pike_error(\""+name+": Array length is wrong (is %d, should be "+nn+")\\n\", Pike_sp["+(a-1)+"-args].u.array->size);\n\n";    got += " r1n=check_1n_args(\""+name+"\", args-"+(a-1)+", "+    arrfix[1]+", "+arrfix[2]+", &zv16);\n";    r234=-1;    rtypes=arrfix[3];    i=sizeof(ty);    break; -  +  case ']': +  arrfix = special_234(0, 0, ty[i+1..], 1); +  res += " union zvalue *zv;\n int r1n;\n"; +  argt += arrfix[0]; +  got += " r1n=check_1unlimited_args(\""+name+"\", args-"+(a-1)+", "+ +  arrfix[1]+", "+arrfix[2]+", &zv);\n"; +  r234=-2; +  rtypes=arrfix[3]; +  i=sizeof(ty); +  break;    case 'w':    img_obj=1;    args += ({ "img.width" });    break;    case 'h':    img_obj=1;    args += ({ "img.height" });    break;    case 'f':    img_obj=1;
pike.git/src/post_modules/GL/gen.pike:386:    Array.map(indices(rtypes),    lambda(int i, string r, string fu, string vret,    array(string) args, array(int) novec) {    return " case ZT_ARRAY|ZT_"+    (['i':"INT",'f':"FLOAT",'d':"DOUBLE"])[r[i]]+": "+    (vret?"res=":"")+fu+r[i..i]+"("+    ((args+({"zv16."+r[i..i]}))*",")+"); break;";    }, rtypes, fu, vret, args, novec)*"\n"+    "\n }\n";    break; +  +  case -2: +  res += " switch(r1n) {\n"+ +  Array.map(indices(rtypes), +  lambda(int i, string r, string fu, string vret, +  array(string) args, array(int) novec) { +  return " case ZT_ARRAY|ZT_"+ +  (['i':"INT",'f':"FLOAT",'d':"DOUBLE"])[r[i]]+": "+ +  (vret?"res=":"")+fu+r[i..i]+"("+ +  ((args+({ "(void *)zv" }))*",")+"); break;"; +  }, rtypes, fu, vret, args, novec)*"\n"+ +  "\n }\n"; +  res += " if (zv != NULL)\n free(zv);\n"; +  break;    }       if(img_obj) {    res += " release_img(&img);\n";    }    res += " pop_n_elems(args);\n";    res += (vret? " "+vret+"("+(vcast||"")+"res);\n":/*" push_int(0);\n"*/"");    res += "}\n\n";    return ({res,prot});   }