whiroth
Version:
Whiroth ====================
73 lines (66 loc) • 2.51 kB
HTML
<!--suppress HtmlFormInputWithoutLabel, JSUnusedAssignment, JSCheckFunctionSignatures -->
<head>
<link rel="stylesheet" href="browser.css" type="text/css">
</head>
<body>
<table style="width: 100%;" spellcheck="false">
<tr style="width: 100%;">
<td rowspan="3" style="width: 50%;">
<textarea id="inputTextArea">
"Hello World!" (pc) 10 pc
"This is an awesome language (nope) whiroth" (pc) 10 pc
"Type and execute it" (pc) 10 pc
</textarea>
</td>
<td>
<textarea id="output">
</textarea>
</td>
</tr>
<tr style="width: 50%;">
<td style="width: 50%;">
<textarea id="outputInfo">
</textarea>
</td>
</tr>
<tr style="width: 50%;">
<td style="width: 50%;">
<textarea id="outputPure">
</textarea>
</td>
</tr>
</table>
<script src="../whiroth.js"></script>
<script>
var inputTextArea = document.getElementById("inputTextArea");
var output = document.getElementById("output");
var outputInfo = document.getElementById("outputInfo");
var outputPure = document.getElementById("outputPure");
inputTextArea.onkeyup = function () {
try {
var compiled = whiroth(inputTextArea.value);
try {
var executed = compiled.fn();
output.style.backgroundColor = "";
outputInfo.style.backgroundColor = "";
output.value = executed.out ? executed.out : isNaN(executed) ? executed.out : executed;
outputInfo.value = 'execution time: ' + executed.executionTime;
outputInfo.value += '\ncompile time: ' + compiled.compileTime;
outputInfo.value += '\nstack: ' + JSON.stringify(executed.stack, 4, ' ');
outputPure.value = compiled.fnPure;
} catch (e) {
output.style.backgroundColor = "red";
outputInfo.style.backgroundColor = "";
output.value = 'Execution error! :' + e.message;
outputInfo.value = '\ncompile time: ' + compiled.compileTime;
outputPure.value = compiled.fnPure;
}
} catch (e) {
output.style.backgroundColor = "";
outputInfo.style.backgroundColor = "red";
outputInfo.value = e.message;
}
};
inputTextArea.onkeyup(); // trigger for start
</script>
</body>