forked from biwascheme/biwascheme
-
Notifications
You must be signed in to change notification settings - Fork 1
/
repl.html
119 lines (112 loc) · 3.23 KB
/
repl.html
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<title>BiwaScheme REPL</title>
<style type="text/css">
div#bs-repl{
border:1px solid black;
padding:1em;
width:100%;
}
div#bs-console{
border:1px solid black;
padding:1em;
margin-top:1em;
}
div#bs-opecode{
border:1px solid black;
padding:1em;
margin-top:1em;
}
span.dump_opecode{ color:orange; }
span.dump_constant{ color:red; }
div.bs-snippet{
white-space:pre;
cursor:pointer;
}
div.bs-snippet:hover {
white-space:pre;
cursor:pointer;
background-color:darkseagreen;
}
</style>
</head>
<body>
<h1><a href='http://www.biwascheme.org/'>BiwaScheme</a> REPL</h1>
<!--<button id="test">foo</button>-->
<div id="bs-repl">
<table><tr><td valign="top">
<form>
<textarea id="bs-input" rows="10" cols="60">(print "Hello, world!")</textarea><br>
<div style="float:right;">
<span id="time"></span>
<input type="button" value="eval" onclick="bs_eval()">
</div>
<br style="clear:both"/>
</form>
<div id="bs-console">
</div>
<div id="bs-opecode">
</div>
</td>
<td valign="top">
<div id="bs-sample">
<h2>Sample</h2>
<ul>
<li><div class="bs-snippet">(+ 1 2)</div></li>
<li><div class="bs-snippet">(not #t) </div></li>
<li><div class="bs-snippet">(boolean=? #t #t #t) </div></li>
<li><div class="bs-snippet">;; length by Y combinator
(((lambda (f)
((lambda (proc) (f (lambda (arg) ((proc proc) arg))))
(lambda (proc) (f (lambda (arg) ((proc proc) arg))))))
(lambda (self)
(lambda (ls)
(if (null? ls) 0 (+ 1 (self (cdr ls)))))))
'(1 2 3 4 5))
</div></li>
<li><div class="bs-snippet">;; length by Y combinator (tail recursive)
(((lambda (f)
((lambda (proc) (f (lambda (arg1 arg2) ((proc proc) arg1 arg2))))
(lambda (proc) (f (lambda (arg1 arg2) ((proc proc) arg1 arg2))))))
(lambda (self)
(lambda (ls acc)
(if (null? ls) acc (self (cdr ls) (+ 1 acc))))))
'(1 2 3 4 5) 0)
</div></li>
</ul>
</div>
</td></tr></table>
</div>
<script type="text/javascript" src="src/development_loader.js">// <![CDATA[
var biwascheme = new BiwaScheme.Interpreter();
function bs_eval(){
$('bs-console').innerHTML = "";
var str = $("bs-input").value;
try{
var opc = biwascheme.compile(str);
$('bs-opecode').innerHTML = (new BiwaScheme.Dumper()).dump_opc(opc);
var before = new Date();
biwascheme.evaluate(str, function(result){
var after = new Date();
$('time').innerHTML = "Time: " + (after-before)/1000 + "sec";
BiwaScheme.Port.current_output.put_string(BiwaScheme.to_write(result));
});
}
catch(e){
BiwaScheme.Port.current_output.put_string(e.message);
throw(e);
}
return false;
}
$$("div.bs-snippet").each(function(div){
Event.observe(div, "click", function(e){
$('bs-input').innerHTML = "";
$('bs-input').value = div.firstChild.data;
});
});
// ]]></script>
</body>
</html>
<!-- vim:set ft=javascript: -->