Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge for-declaration with the previous declaration #371

Merged
merged 1 commit into from
May 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/rewriter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,9 @@ module private RewriterImpl =
| []-> []
| Decl(ty1, li1) :: Decl(ty2, li2) :: l when ty1 = ty2 ->
squeezeConsecutiveDeclarations (Decl(ty1, li1 @ li2) :: l)
// int a=2; for (int b=3; ...) -> int a=2, b=3; for (; ...)
| Decl(ty1, li1) :: ForD((ty2, li2), cond, inc, body) :: l when ty1 = ty2 ->
squeezeConsecutiveDeclarations (Decl(ty1, li1 @ li2) :: ForE(None, cond, inc, body) :: l)
| e::l -> e :: squeezeConsecutiveDeclarations l

// Squeeze top-level declarations, e.g. uniforms
Expand Down
16 changes: 8 additions & 8 deletions tests/compression_results.log
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ mouton/mouton.vert... 16951 => 2447.462
audio-flight-v2.frag 4509 => 881.311
buoy.frag 4051 => 607.428
controllable-machinery.frag 7703 => 1216.907
ed-209.frag 7702 => 1341.619
elevated.hlsl 3405 => 603.218
endeavour.frag 2589 => 529.811
ed-209.frag 7697 => 1340.743
elevated.hlsl 3400 => 602.269
endeavour.frag 2584 => 532.679
from-the-seas-to-the-stars.frag 14250 => 2308.842
frozen-wasteland.frag 4566 => 806.475
kinder_painter.frag 2847 => 442.771
leizex.frag 2270 => 510.375
lunaquatic.frag 5239 => 1044.087
mandelbulb.frag 2347 => 537.664
lunaquatic.frag 5234 => 1043.382
mandelbulb.frag 2342 => 537.655
ohanami.frag 3255 => 723.732
orchard.frag 5510 => 1027.042
orchard.frag 5505 => 1027.273
oscars_chair.frag 4651 => 986.364
robin.frag 6257 => 1047.684
robin.frag 6254 => 1047.419
slisesix.frag 4549 => 913.642
terrarium.frag 3593 => 741.557
the_real_party_is_in_your_pocket.frag 12087 => 1780.714
valley_ball.glsl 4307 => 881.820
yx_long_way_from_home.frag 2942 => 598.650
Total: 134416 => 23495.003
Total: 134383 => 23495.298
4 changes: 2 additions & 2 deletions tests/real/ed-209.frag.expected
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,8 @@ MarchData map(vec3 p)
float calcShadow(vec3 p,vec3 lightPos)
{
lightPos=normalize(lightPos-p);
float res=1.,t=.1;
for(float i=0.;i<SHADOW_STEPS;i++)
float res=1.,t=.1,i=0.;
for(;i<SHADOW_STEPS;i++)
{
float h=map(p+lightPos*t).d;
res=min(res,12.*h/t);
Expand Down
10 changes: 5 additions & 5 deletions tests/real/elevated.hlsl.expected
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ const char *elevated_hlsl =
"float D(float2 f,float y)"
"{"
"float2 z=0;"
"float x=0,w=3;"
"for(float r=0;r<y;r++)"
"float x=0,w=3,t=0;"
"for(;t<y;t++)"
"{"
"float3 t=D(.25*f);"
"z+=t.yz;"
"x+=(w*=.5)*t.x/(1+mul(z,z));"
"float3 s=D(.25*f);"
"z+=s.yz;"
"x+=(w*=.5)*s.x/(1+mul(z,z));"
"f=mul(float2x2(1.6,-1.2,1.2,1.6),f);"
"}"
"return x;"
Expand Down
4 changes: 2 additions & 2 deletions tests/real/endeavour.frag.expected
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ void lfnoise(vec2 t,out float num)
void mfnoise(vec2 x,float fmin,float fmax,float alpha,out float num)
{
num=0.;
float a=1.,nf=0.,buf;
for(float f=fmin;f<fmax;f*=2.)
float a=1.,nf=0.,buf,f=fmin;
for(;f<fmax;f*=2.)
lfnoise(f*x,buf),num+=a*buf,a*=alpha,nf+=1.;
num*=(1.-alpha)/(1.-pow(alpha,nf));
}
Expand Down
4 changes: 2 additions & 2 deletions tests/real/lunaquatic.frag.expected
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ vec3 getWaterNormal(vec3 p)
}
int traceTerrain(vec3 ro,vec3 rd,float maxt,out float depth)
{
float lh,ly,delt=0.;
for(float t=.1;t<maxt;t+=delt)
float lh,ly,delt=0.,t=.1;
for(;t<maxt;t+=delt)
{
ro+=rd*delt;
depth=height(ro.xz);
Expand Down
4 changes: 2 additions & 2 deletions tests/real/mandelbulb.expected
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ const char *mandelbulb_frag =
"s.y=1e20;"
"float x;"
"vec3 z;"
"float t=1./sqrt(2.);"
"for(float d=s.x;d<s.y;)"
"float t=1./sqrt(2.),d=s.x;"
"for(;d<s.y;)"
"{"
"vec3 w=v+o*d;"
"float r=clamp(.001*d*t,1e-6,.005),g=r*.1;"
Expand Down
4 changes: 2 additions & 2 deletions tests/real/orchard.frag.expected
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ float shadow(vec3 ro,vec3 rd,float dis)
}
float calcOcc(vec3 pos,vec3 nor,float d)
{
float occ=0.,sca=1.;
for(float h=.05;h<.3;h+=.07)
float occ=0.,sca=1.,h=.05;
for(;h<.3;h+=.07)
{
vec3 opos=pos+h*nor;
float d=map(opos,d).x;
Expand Down
4 changes: 2 additions & 2 deletions tests/real/robin.frag.expected
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ float Scene(vec3 rO,vec3 rD,vec2 fragCoord)
{
float t=2.+.1*Hash(fragCoord.xy*fract(iTime)),alphaAcc=0.;
vec3 p=vec3(0);
int hits=0;
for(int j=0;j<40;j++)
int hits=0,j=0;
for(;j<40;j++)
{
if(hits==8||alphaAcc>=1.||t>45.)
break;
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/blocks.expected
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ const char *blocks_frag =
"int k=5;"
"float test_for()"
"{"
"int foo=2,n=0;"
"for(int i=0;i<4;i++)"
"int foo=2,n=0,i=0;"
"for(;i<4;i++)"
"foo+=i;"
"for(foo++;n<4;n++)"
"{"
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/loop.frag.expected
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ const char *loop_frag =
"float a;"
"void main()"
"{"
"float c;"
"for(float d=0.;d<50.;++d)"
"float c,d=0.;"
"for(;d<50.;++d)"
"c+=cos(d);"
"float b;"
"for(b=0.;b<50.;++b)"
Expand Down