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

version» Context lines:

pike.git/src/post_modules/GL/gen.pike:6:    F=float    E=enum    B=bitfield    O=bool    R=double/float    Q=int/float    Z=(byte/)double/float/int/short       +XXXX = 3/4/array(3/4)    +XXX = 2/3/4/array(2/3/4) +  +X = 1/2/3/4/array(1/2/3/4)    =XXXX = 4/array(4)    =XXX = 3/array(3)    @X = 1/array(n)       # = 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 +  i = image data +    */      inherit "features";   inherit "constants";      void error(string msg, mixed ... args)   {    if(sizeof(args))    msg = sprintf(msg, @args);    werror(msg+"\n");
pike.git/src/post_modules/GL/gen.pike:77:    typ+=({t});    }    return ({typ,tm,rows((['i':"ZT_INT",'f':"ZT_FLOAT",'d':"ZT_DOUBLE"]),    values(rt))*"|",rt});   }      array(string) gen_func(string name, string ty)   {    string res="", got="", prot, vdec, vret, fu=name;    array novec, args=({}), argt=({}); -  int r234, argt_cut=-1; +  int r234, argt_cut=-1, img_obj=0;    string rtypes;       switch(ty[0]) {    case 'V':    prot=":void";    break;    case 'I':    case 'O':    prot=":int";    vdec="INT32";    vret="push_int";    break;    default:    error("%s: Unknown return type '%c'.", name, ty[0]);    }       res += "static void f_"+name+"(INT32 args)\n{\n"+    (vdec?(" "+vdec+" res;\n"):"");    -  +  int a=1;    for(int i=1; i<sizeof(ty); i++)    switch(ty[i]) {    case 'B':    case 'E':    case 'O':    case 'I':    argt += ({"int"}); -  args += ({ "arg"+i }); -  res += " INT32 arg"+i+";\n"; -  got += " arg"+i+"=sp["+(i-1)+"-args].u.integer;\n"; +  args += ({ "arg"+a }); +  res += " INT32 arg"+a+";\n"; +  got += " arg"+a+"=sp["+(a-1)+"-args].u.integer;\n"; +  a++;    break;    case 'D':    argt += ({"float"}); -  args += ({ "arg"+i }); -  res += " double arg"+i+";\n"; -  got += " arg"+i+"=sp["+(i-1)+"-args].u.float_number;\n"; +  args += ({ "arg"+a }); +  res += " double arg"+a+";\n"; +  got += " arg"+a+"=sp["+(a-1)+"-args].u.float_number;\n"; +  a++;    break;    case 'F':    argt += ({"float"}); -  args += ({ "arg"+i }); -  res += " float arg"+i+";\n"; -  got += " arg"+i+"=sp["+(i-1)+"-args].u.float_number;\n"; +  args += ({ "arg"+a }); +  res += " float arg"+a+";\n"; +  got += " arg"+a+"=sp["+(a-1)+"-args].u.float_number;\n"; +  a++;    break;    case '+':    int mi, mx;    switch(sizeof(ty[i+1..])) { -  +  case 1: +  mi = 1; mx = 4; break;    case 3:    mi = 2; mx = 4; break;    case 4:    mi = 3; mx = 4; break;    default:    error("Can't understand + followed by %d chars.\n", sizeof(ty[i+1..]));    }    array plusfix = special_234(mi, mx, ty[i+1..]);    res += " struct zvalue4 zv4;\n";    argt_cut = sizeof(argt);    argt += plusfix[0]; -  res += "\n int r234=check_234_args(\""+name+"\", args-"+(i-1)+", "+ +  res += "\n int r234=check_234_args(\""+name+"\", args-"+(a-1)+", "+    mi+", "+mx+", "+plusfix[1]+", "+plusfix[2]+", &zv4);\n";    r234=1;    rtypes=plusfix[3];    i=sizeof(ty);    novec=indices(allocate(mx+1))[mi..];    break;    case '#':    fu += sizeof(ty[i+1..]);    /* fallthrough */    case '!':    case '=':    array eqfix = special_234(sizeof(ty[i+1..]), sizeof(ty[i+1..]),    ty[i+1..]);    res += " struct zvalue4 zv4;\n";    argt_cut = sizeof(argt);    argt += eqfix[0]; -  res += "\n check_234_args(\""+name+"\", args-"+(i-1)+", "+ +  res += "\n check_234_args(\""+name+"\", args-"+(a-1)+", "+    sizeof(ty[i+1..])+", "+sizeof(ty[i+1..])+", "+eqfix[1]+", "+    eqfix[2]+", &zv4);\n";    r234=2;    rtypes=eqfix[3];    if(ty[i]=='!')    novec=indices(ty[i+1..]);    i=sizeof(ty);    break;    case '@':    array atfix = special_234(1, 1, ty[i+1..]);    res += " union zvalue16 zv16;\n";    argt_cut = sizeof(argt);    argt += atfix[0]; -  res += "\n int r1n=check_1n_args(\""+name+"\", args-"+(i-1)+", "+ +  res += "\n int r1n=check_1n_args(\""+name+"\", args-"+(a-1)+", "+    atfix[1]+", "+atfix[2]+", &zv16);\n";    r234=3;    rtypes=atfix[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; +  args += ({ "img.format" }); +  break; +  case 't': +  img_obj=1; +  args += ({ "img.type" }); +  break; +  case 'i': +  img_obj=1; +  args += ({ "img.pixels" }); +  break;       default:    error("%s: Unknown parameter type '%c'.", name, ty[i]);    }    -  +  if(img_obj) { +  argt += ({"object"}); +  res += " struct zimage img;\n"; +  got += " check_img_arg(sp["+(a-1)+"-args].u.object, &img);\n"; +  } +     prot = (argt*",")+prot;       if(sizeof(argt))    res += "\n check_all_args(\""+name+"\", args, "+    ((Array.map((argt_cut<0?argt:argt[..argt_cut-1]),    lambda(string t) {    return Array.map(t/"|",    lambda(string t) {    return "BIT_"+upper_case(t);    })*"|";
pike.git/src/post_modules/GL/gen.pike:277:    ((args+({"zv16."+r[i..i]+"[0]"}))*",")+"); break;\n"+    " case ZT_ARRAY|ZT_"+    (['i':"INT",'f':"FLOAT",'d':"DOUBLE"])[r[i]]+": "+    (vret?"res=":"")+fu+r[i..i]+"v("+    ((args+({"zv16."+r[i..i]}))*",")+"); break;";    }, rtypes, fu, vret, args, novec)*"\n"+    "\n }\n";    break;    }    +  if(img_obj) { +  res += " release_img(&img);\n"; +  }    res += " pop_n_elems(args);\n";    res += (vret? " "+vret+"(res);\n":/*" push_int(0);\n"*/"");    res += "}\n\n";    return ({res,prot});   }      string gen()   {    string res = "";    array t = Array.transpose(func_misc);
pike.git/src/post_modules/GL/gen.pike:302:    ty |= mkmapping(func_cat[cat],    rows(({cat}), allocate(sizeof(func_cat[cat]))));    }    sort(fn);    foreach(fn, string f) {    array(string) r = gen_func(f, ty[f]);    res += r[0];    prot[f]=r[1];    }    res += "void add_auto_funcs()\n{\n"; +  res += " pre_init();\n";    foreach(fn, string f)    res += " add_function_constant(\""+f+"\", f_"+f+",\n\t\t\t\"function("+    prot[f]+")\", OPT_SIDE_EFFECT);\n";    foreach(sort(indices(constants)), string co)    res += " add_integer_constant(\""+co+"\", "+constants[co]+", 0);\n"; -  +  res += " post_init();\n";    res += "}\n";    return res;   }      void main(int argc, array(string) argv)   {    array(string) f = Stdio.File("stdin")->read()/"@@";    write(({f[0],gen(),@f[1..]})*"");   }