Skip to content

Commit

Permalink
Use template string for JS output
Browse files Browse the repository at this point in the history
Fixes #14
  • Loading branch information
laurentlb committed May 8, 2021
1 parent 2f1e0a5 commit 44e1edf
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 39 deletions.
2 changes: 1 addition & 1 deletion src/cGen.fs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ let private printJSHeader out data =
fprintfn out ""
for file : string, code in data do
let name = (Path.GetFileName file).Replace(".", "_")
fprintfn out "var %s =%s \"%s\"" name Environment.NewLine (Printer.print code)
fprintfn out "var %s = `%s`" name (Printer.print code)
fprintfn out ""

let private printNasmHeader out data =
Expand Down
6 changes: 3 additions & 3 deletions src/printer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ module private PrinterImpl =

let backslashN() =
match options.targetOutput with
| Options.Text -> "\n"
| Options.Text | Options.JS -> "\n"
| Options.Nasm -> "', 10, '"
| _ -> "\\n"

Expand Down Expand Up @@ -156,14 +156,14 @@ module private PrinterImpl =
else
let spaces = new string(' ', indent * 2 + 1)
match options.targetOutput with
| Options.Text -> ""
| Options.Text | Options.JS -> ""
| Options.CHeader | Options.CList -> out "\"%s%s\"" Environment.NewLine spaces
| Options.JS -> out "\" +%s%s\"" Environment.NewLine spaces
| Options.Nasm -> out "'%s\tdb%s'" Environment.NewLine spaces

let escape (s: string) =
match options.targetOutput with
| Options.Text -> s
| Options.JS -> s
| Options.CHeader | Options.CList | Options.JS -> s.Replace("\"", "\\\"").Replace("\n", "\\n")
| Options.Nasm -> s.Replace("'", "\'").Replace("\n", "', 10, '")

Expand Down
36 changes: 1 addition & 35 deletions tests/real/disco.expected
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,5 @@
* http://www.ctrl-alt-test.fr
*/

var disco_frag =
"uniform vec2 resolution;" +
"uniform float time;" +
"uniform sampler2D tex0,tex1,tex2,tex3;" +
"vec4 s(vec2 px,float z)" +
"{" +
"float l=3.1415,k=time*sign(z),x=px.x*320.*.0065*z,y=px.y*240.*.006*z,c=sqrt(x*x+y*y);" +
"if(c>1.)" +
"return vec4(0.);" +
"else" +
"{" +
"float u=-.4*sign(z)+sin(k*.05),v=sqrt(1.-x*x-y*y),q=y*sin(u)-v*cos(u);" +
"y=y*cos(u)+v*sin(u);" +
"v=acos(y);" +
"u=acos(x/sin(v))/(2.*l)*120.*sign(q)-k;" +
"v=v*60./l;" +
"q=cos(floor(v/l));" +
"c=pow(abs(cos(u)*sin(v)),.2)*.1/(q+sin(float(int((u+l/2.)/l))+k*.6+cos(q*25.)))*pow(1.-c,.9);" +
"vec4 res;" +
"if(c<0.)" +
"res=vec4(-c/2.*abs(cos(k*.1)),0.,-c*2.*abs(sin(k*.04)),1.);" +
"else" +
" res=vec4(c,c*2.,c*2.,1.);" +
"return res;" +
"}" +
"}" +
"void main()" +
"{" +
"vec2 p=-1.+2.*gl_FragCoord.xy/resolution.xy;" +
"vec4 c=vec4(0.);" +
"for(int i=80;i>0;i--)" +
"c+=s(p,1.-float(i)/80.)*(.008-float(i)*5e-05);" +
"vec4 d=s(p,1.);" +
"gl_FragColor=(d.w==0.?s(p,-.2)*.02:d)+sqrt(c);" +
"}"
var disco_frag = `uniform vec2 resolution;uniform float time;uniform sampler2D tex0,tex1,tex2,tex3;vec4 s(vec2 px,float z){float l=3.1415,k=time*sign(z),x=px.x*320.*.0065*z,y=px.y*240.*.006*z,c=sqrt(x*x+y*y);if(c>1.)return vec4(0.);else{float u=-.4*sign(z)+sin(k*.05),v=sqrt(1.-x*x-y*y),q=y*sin(u)-v*cos(u);y=y*cos(u)+v*sin(u);v=acos(y);u=acos(x/sin(v))/(2.*l)*120.*sign(q)-k;v=v*60./l;q=cos(floor(v/l));c=pow(abs(cos(u)*sin(v)),.2)*.1/(q+sin(float(int((u+l/2.)/l))+k*.6+cos(q*25.)))*pow(1.-c,.9);vec4 res;if(c<0.)res=vec4(-c/2.*abs(cos(k*.1)),0.,-c*2.*abs(sin(k*.04)),1.);else res=vec4(c,c*2.,c*2.,1.);return res;}}void main(){vec2 p=-1.+2.*gl_FragCoord.xy/resolution.xy;vec4 c=vec4(0.);for(int i=80;i>0;i--)c+=s(p,1.-float(i)/80.)*(.008-float(i)*5e-05);vec4 d=s(p,1.);gl_FragColor=(d.w==0.?s(p,-.2)*.02:d)+sqrt(c);}`

0 comments on commit 44e1edf

Please sign in to comment.