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

Printer: put "else if" on a single line, for readability #262

Merged
merged 1 commit into from
Mar 24, 2023
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
5 changes: 4 additions & 1 deletion src/printer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,10 @@ type PrinterImpl(outputFormat) =
let th = if el <> None && hasDanglingElseProblem th then Block [th] else th
let el = match el with
| None -> ""
| Some el -> out "%selse%s%s" (nl indent) (nl (indent+1)) (stmtToS' (indent+1) el |> sp)
| Some (If _ as el) ->
out "%selse%s" (nl indent) (stmtToS' indent el |> sp)
| Some el ->
out "%selse%s%s" (nl indent) (nl (indent+1)) (stmtToS' (indent+1) el |> sp)
out "if(%s)%s%s" (exprToS indent cond) (stmtToSInd indent th) el
| ForD(init, cond, inc, body) ->
let cond = exprToSOpt indent "" cond
Expand Down
5 changes: 2 additions & 3 deletions tests/real/audio-flight-v2.frag.expected
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,8 @@ void mainImage(out vec4 O,vec2 F)
h=vec3(.012);
if(tm>ths)
C=h*diff+spec;
else
if(m==3.||m==4.)
C=hsv2rgb(vec3(s_hp.z*.01,.8,.6))*diff;
else if(m==3.||m==4.)
C=hsv2rgb(vec3(s_hp.z*.01,.8,.6))*diff;
}
if(tm>ths)
{
Expand Down
86 changes: 39 additions & 47 deletions tests/real/controllable-machinery.frag.expected
Original file line number Diff line number Diff line change
Expand Up @@ -392,54 +392,46 @@ vec3 ShowScene(vec3 ro,vec3 rd)
col4*=.7+.3*SmoothBump(.05,.95,.01,a);
isMet=true;
}
else
if(idObj==1)
col4=vec4(.9,.8,.4,.2),isMet=true;
else
if(idObj==8)
col4=vec4(.8,.8,.85,.2)*(1.-.4*step(abs(ro.z),.1)),isMet=true;
else if(idObj==1)
col4=vec4(.9,.8,.4,.2),isMet=true;
else if(idObj==8)
col4=vec4(.8,.8,.85,.2)*(1.-.4*step(abs(ro.z),.1)),isMet=true;
else if(idObj==5)
col4=vec4(.8,.8,.85,.2),isMet=true;
else if(idObj==2)
col4=abs(vn.y)>.99?
vec4(.5,.6,.2,.05):
vec4(.7,.5,.4,.1);
else if(idObj==3)
{
q=ro-vec3(-.05,-.21,0);
col4=vec4(.8,.8,.4,0);
if(sign(vn.y)!=sign(q.y))
{
if(abs(q.x)<1.&&abs(vn.y)>.5)
col4*=1.-.1*SmoothBump(.45,.55,.03,fract(10.*(q.x-sign(q.y)*mod(tMov,20.)*2.1/5.)));
}
else
col4*=.8+.2*smoothstep(0.,.01,abs(abs(q.z)-.07));
}
else if(idObj==4)
col4=vec4(.7,.5,.4,.1),isMet=true;
else if(idObj==6)
{
q=ro;
q.z-=.9;
if(Maxv2(abs(q.xz)-vec2(1.65,1.45))>0.)
col4=vec4(.9,.9,.9,.2),isMet=true;
else
if(idObj==5)
col4=vec4(.8,.8,.85,.2),isMet=true;
else
if(idObj==2)
col4=abs(vn.y)>.99?
vec4(.5,.6,.2,.05):
vec4(.7,.5,.4,.1);
else
if(idObj==3)
{
q=ro-vec3(-.05,-.21,0);
col4=vec4(.8,.8,.4,0);
if(sign(vn.y)!=sign(q.y))
{
if(abs(q.x)<1.&&abs(vn.y)>.5)
col4*=1.-.1*SmoothBump(.45,.55,.03,fract(10.*(q.x-sign(q.y)*mod(tMov,20.)*2.1/5.)));
}
else
col4*=.8+.2*smoothstep(0.,.01,abs(abs(q.z)-.07));
}
else
if(idObj==4)
col4=vec4(.7,.5,.4,.1),isMet=true;
else
if(idObj==6)
{
q=ro;
q.z-=.9;
if(Maxv2(abs(q.xz)-vec2(1.65,1.45))>0.)
col4=vec4(.9,.9,.9,.2),isMet=true;
else
col4=vec4(.3,.5,.4,0);
col4*=(.5+.5*step(0.,Maxv2(abs(vec2(q.x,q.z+1.3))-vec2(.4,.02))))*(.7+.3*step(0.,abs(PrCaps2Df(vec2(q.z+1.3,q),.08,.5))-.01));
}
else
if(idObj==9)
{
col4=vec4(0,1,1,.2);
if(length(ro.xz-wgObj.xz)<.6*wgObj.w)
col4=mix(.8*col4,vec4(1,0,1,.2),step(0.,sin(6.2831854*tCur)));
}
col4=vec4(.3,.5,.4,0);
col4*=(.5+.5*step(0.,Maxv2(abs(vec2(q.x,q.z+1.3))-vec2(.4,.02))))*(.7+.3*step(0.,abs(PrCaps2Df(vec2(q.z+1.3,q),.08,.5))-.01));
}
else if(idObj==9)
{
col4=vec4(0,1,1,.2);
if(length(ro.xz-wgObj.xz)<.6*wgObj.w)
col4=mix(.8*col4,vec4(1,0,1,.2),step(0.,sin(6.2831854*tCur)));
}
}
sh=min(ObjSShadow(ro,ltDir),GearSShadow(ro,ltDir));
sh=.6+.4*min(sh,BlkHitSh(ro+.01*ltDir,ltDir,6.));
Expand Down
84 changes: 40 additions & 44 deletions tests/real/ed-209.frag.expected
Original file line number Diff line number Diff line change
Expand Up @@ -372,50 +372,46 @@ void mainImage(out vec4 fragColor,vec2 fragCoord)
float startScene,endScene,time=mod(iTime,55.);
if(time<12.)
startScene=0.,endScene=12.,edWalk=0.,ro=vec3(0,-1.5,-.625),lookAt=vec3(0,-1,edZ()),doorOpen=smoothstep(0.,1.,time/5.),stretch=remap(time,7.,10.,0.,1.);
else
if(time<25.)
{
startScene=12.;
endScene=25.;
float t=time-startScene;
edWalk=smoothstep(0.,1.,remap(t,3.,8.,0.,1.));
ro=vec3(-.5*cos(t*.7),.5-t*.1,edZ()-3.);
lookAt=vec3(0,0,edZ());
}
else
if(time<29.)
{
startScene=25.;
endScene=29.;
float t=time-startScene;
ro=vec3(-2,.5+t*.1,edZ()-3.);
lookAt=vec3(0,0,edZ());
}
else
if(time<37.)
{
startScene=29.;
endScene=37.;
float t=time-startScene;
ro=vec3(1.5,-1.-t*.05,edZ()-5.);
lookAt=vec3(0,-1,edZ());
stretch=remap(t,2.,5.,1.,0.);
}
else
if(time<55.)
{
startScene=37.;
endScene=55.;
float t=time-startScene;
ro=vec3(-1.8,-.5,edZ()-2.5);
stretch=remap(t,2.,3.,0.,1.)-remap(t,11.5,14.5,0.,1.);
lookAt=vec3(0,stretch*.5-.5,edZ());
edTwist=remap(t,3.,3.2,0.,1.)*stretch;
edDown=remap(t,3.2,3.4,0.,1.)*stretch;
edShoot=t<=9.5?
remap(t,4.,9.5,0.,1.):
0.;
}
else if(time<25.)
{
startScene=12.;
endScene=25.;
float t=time-startScene;
edWalk=smoothstep(0.,1.,remap(t,3.,8.,0.,1.));
ro=vec3(-.5*cos(t*.7),.5-t*.1,edZ()-3.);
lookAt=vec3(0,0,edZ());
}
else if(time<29.)
{
startScene=25.;
endScene=29.;
float t=time-startScene;
ro=vec3(-2,.5+t*.1,edZ()-3.);
lookAt=vec3(0,0,edZ());
}
else if(time<37.)
{
startScene=29.;
endScene=37.;
float t=time-startScene;
ro=vec3(1.5,-1.-t*.05,edZ()-5.);
lookAt=vec3(0,-1,edZ());
stretch=remap(t,2.,5.,1.,0.);
}
else if(time<55.)
{
startScene=37.;
endScene=55.;
float t=time-startScene;
ro=vec3(-1.8,-.5,edZ()-2.5);
stretch=remap(t,2.,3.,0.,1.)-remap(t,11.5,14.5,0.,1.);
lookAt=vec3(0,stretch*.5-.5,edZ());
edTwist=remap(t,3.,3.2,0.,1.)*stretch;
edDown=remap(t,3.2,3.4,0.,1.)*stretch;
edShoot=t<=9.5?
remap(t,4.,9.5,0.,1.):
0.;
}
float dim=1.-cos(min(1.,2.*min(abs(time-startScene),abs(time-endScene)))*3.141/2.);
vec3 col=vec3(0);

Expand Down
5 changes: 2 additions & 3 deletions tests/real/endeavour.frag.expected
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,8 @@ void mainImage(out vec4 fragColor,vec2 fragCoord)
col=mix(col,.3*col,smoothstep(-.01,.01,-ya));
}
}
else
if(s.y==2.)
planet_texture(x.xy,c1),col=.3*c1+.3*c1*abs(dot(l,n))+(1.3*c1+.1*c.xyy)*pow(abs(dot(reflect(-l,n),dir)),3.),col=mix(col,.4*length(col)*c.xyy,.7);
else if(s.y==2.)
planet_texture(x.xy,c1),col=.3*c1+.3*c1*abs(dot(l,n))+(1.3*c1+.1*c.xyy)*pow(abs(dot(reflect(-l,n),dir)),3.),col=mix(col,.4*length(col)*c.xyy,.7);
}
col=clamp(col,0.,1.);
fragColor=vec4(col,1);
Expand Down
Loading