-
Notifications
You must be signed in to change notification settings - Fork 2
/
asmjs.html
150 lines (137 loc) · 6.96 KB
/
asmjs.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>asm.js Verification Service</title>
<link href="benchmark/3rdParty/bootstrap/css/bootstrap.min.css"
rel="stylesheet" media="screen">
<style>
.asmjs-input textarea {
resize: vertical;
}
.asmjs-input .control-group.error {
background: #b94a48;
}
.asmjs-input .control-group.error .asmjs-output {
color: white;
}
.asmjs-output {
font-weight: bold;
padding: 0 0.5em;
}
.asmjs-input .control-group.success textarea { color: #555; }
</style>
<!-- now include all our javascript -->
<script type="text/javascript" src="./global.js"></script>
<script type="text/javascript" src="./global-es5.js"></script>
<script type="text/javascript" src="./extensions.js"></script>
<script type="text/javascript" data-main="asm-llvm.js"
src="require.js"></script>
</head>
<body>
<div class="navbar navbar-inverse">
<div class="navbar-inner">
<a class="brand" href="./">TurtleScript</a>
</div>
</div>
<div class="container">
<div class="page-header">
<h1>asm.js Verification Service <small>by C. Scott Ananian</small>
</h1>
</div>
<div class="row-fluid"><div class="span12">
This is a single-pass type-checker and verification service for <tt>asm.js</tt>
using the <a
href="http://turtlescript.github.cscott.net">TurtleScript</a>
implementation in <a
href="http://turtlescript.github.cscott.net/docco/asm-llvm.html">asm-llvm.js</a>
(<a href="https://github.com/cscott/TurtleScript">github</a>).
It is based on the
17 March 2013 <a href="http://asmjs.org">asm.js</a>
<a href="http://asmjs.org/spec/latest/">spec</a>
with the following fixes:
</div></div>
<div class="row-fluid"><div class="span6">
<ul>
<li><a href="https://github.com/dherman/asm.js/issues/69">Result of
% should be intish<a></li>
<li><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=878433#c9">Add
a special case for <tt>expr % constant</tt>.</a></li>
<li><a href="https://github.com/dherman/asm.js/issues/68">Redundant
parameter type coercions are disallowed</a></li>
<li><a href="https://github.com/dherman/asm.js/issues/67">Negative
numeric literals</a></li>
<li><a href="https://github.com/dherman/asm.js/issues/66">Semicolon
insertion explicitly allowed</a></li>
<li><a href="https://github.com/dherman/asm.js/issues/65">Arbitrary
parenthesization of expressions</a></li>
<li><a href="https://github.com/dherman/asm.js/issues/64">Mutable
foreign imports</a></li>
<li><a
href="https://github.com/dherman/asm.js/issues/63">Comma-separated
global program variable declarations</a></li>
</ul></div><div class="span6"><ul>
<li><a href="https://github.com/dherman/asm.js/issues/62">! and ~~</a></li>
<li><a href="https://github.com/dherman/asm.js/issues/61">Required
coercion of call parameters</a></li>
<li><a href="https://github.com/dherman/asm.js/issues/56">Unsigned
is not a subtype of extern</a></li>
<li><a href="https://github.com/dherman/asm.js/issues/70">Call
expressions coerced based on grammatical form</a></li>
<li><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=883175">Remove
'unknown' type for foreign function returns</a></li>
<li><a href="https://github.com/dherman/asm.js/issues/57">1e3 is a
valid integer literal, but 1e-3 is not</a></li>
<li><a href="https://github.com/dherman/asm.js/issues/72">Operands
of binary - should be double, not doublish</a></li>
</ul>
</div></div>
<form class="asmjs-input">
<label class="control-label" for="asmjs-textarea">Paste your
<code>asm.js</code> code here:</label>
<div class="control-group">
<div class="controls clearfix">
<textarea autocapitalize="off" autocorrect="off" wrap="off"
placeholder="Enter asm.js code here" rows="10"
id="asmjs-textarea" class="span12">
</textarea>
<button class="asmjs-button btn btn-primary pull-right">Type check</button>
<div class="asmjs-output help-block"></div>
</div>
</form>
</div><!-- container -->
<script type="text/javascript">
// Add a simple demo.
var democode = "// This is sample asm.js, borrowed from the README for\n// https://github.com/dherman/asm.js\n\nfunction mymodule(stdlib, foreign, heap) {\n \"use asm\";\n\n // -------------------------------------------------------------------------\n // SECTION 1: globals\n\n var H32 = new stdlib.Int32Array(heap);\n var HU32 = new stdlib.Uint32Array(heap);\n\n var dbltest = +foreign.dblTest;\n var log = foreign.consoleDotLog;\n var inttest = foreign.intTest|0;\n\n var importedInfinity = stdlib.Infinity;\n var importedAbs = stdlib.Math.abs;\n\n var g_i = 0; // int global\n var g_f = 0.0; // double global\n\n // -------------------------------------------------------------------------\n // SECTION 2: functions\n\n function f(x, y) {\n // SECTION A: parameter type declarations\n x = x|0; // int parameter\n y = +y; // double parameter\n\n // SECTION B: function body\n x = (x+3)|0; // signed addition\n log(x|0); // call into FFI -- must force the sign\n log(y); // call into FFI -- already know it's a double\n\n // SECTION C: unconditional return\n return ((((x+1)|0)/(x|0))>>>0)|0; // compound expression\n }\n\n function g() {\n g_f = +(g_i>>>0); // read/write globals\n return;\n }\n\n function g2() {\n return;\n }\n\n function h(i, x) {\n i = i|0;\n x = x|0;\n H32[i>>2] = x; // shifted by log2(byte count)\n ftable_2[(x-2)&1](); // dynamic call of functions in table 2\n\n // no return necessary when return type is void\n }\n\n function i(j) {\n j = +j;\n var k = 3.;\n j = j + k;\n return +k;\n }\n\n // -------------------------------------------------------------------------\n // SECTION 3: function tables\n\n var ftable_1 = [f];\n var ftable_2 = [g, g2]; // all of the same type\n\n // -------------------------------------------------------------------------\n // SECTION 4: exports\n\n return { f_export: f, goop: g };\n}\n";
require(['asm-llvm'], function(asm_llvm) {
var tarea = document.querySelector('.asmjs-input textarea');
var out = document.querySelector('.asmjs-output');
var controls = document.querySelector('.control-group');
var update = function() {
var c = tarea.value;
var valid = true, message = "";
try {
asm_llvm.compile(c);
} catch (e) {
valid = false;
message = e.message;
}
controls.classList.remove('error');
controls.classList.remove('success');
if (valid) {
controls.classList.add('success');
out.textContent = "Valid asm.js";
} else {
controls.classList.add('error');
out.textContent = message;
}
};
var button = document.querySelector('.asmjs-button');
button.addEventListener('click', function() { update(); });
tarea.value = democode;
tarea.addEventListener('input', function() { update(); });
update();
});
</script>
</body>
</html>