-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
66 lines (66 loc) · 1.89 KB
/
index.html
File metadata and controls
66 lines (66 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
</head>
<body>
<textarea id = "input">
run
[
(ctx).fillStyle = "white",
(ctx).fillRect 0 0 2000 1000,
(ctx).fillStyle = "blue",
pos = (cis t/1000).map v>10+100*(1+v),
(math)=(ctx).fillRect pos.0 pos.1 20 20,
](a>a),
t = (callJS_new window.Date []).getTime(),
(callJS_new window.Date [])
{toJS evalFully toExp callJS_new math} = global,
cis = x>[global.math.cos x,global.math.sin x],
run =l>(global)= do (evalFully,l.reduce[s v]>(do,evalFully s,v)),
{window} = global.js,
{ctx} = window,
</textarea>
<pre id = "output1"></pre>
<pre id = "output"></pre>
<canvas id = "canvas"></canvas>
<script src="compile.js"></script>
<script id = "textFile" src="test.llcp"></script>
<script>
window.error="";
window.ctx = canvas.getContext("2d");
window.ans;
window.duration = {compile:-1,eval:-1};
var loopFrames = (60/4)|0;
let loop = async()=>{
let timer = 0;
while(true){
await new Promise((resolve,reject)=>
window.requestAnimationFrame(()=>{
if((timer=(timer+1)%loopFrames)!=0){resolve();return}
let ans;
files.reset();
let ans1 = tryCatch(()=>{
let t0 = new Date().getTime();
let a=compile(input.value,null);
window.duration.compile = new Date().getTime()-t0;
a=a.evalFully();
window.duration.eval = new Date().getTime()-window.duration.compile-t0;
output1.innerText = "compile:"+window.duration.compile+"\neval:"+window.duration.eval;
return a;
},error=>ans=window.error=error,compile("","null"));
window.ans=ans1;
if(compile.isExpression(ans1))try{ans1 = JSON.stringify(ans1);}catch(e){console.log(ans1);throw e}
ans ??= ans1;
if(output.innerText!=ans)output.innerText = ans;
resolve();
})
);
}
};
loop();
</script>
</body>
</html>