aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/compiler.html12
-rw-r--r--src/compiler.js4
2 files changed, 14 insertions, 2 deletions
diff --git a/src/compiler.html b/src/compiler.html
index d73da941..76d2dc33 100644
--- a/src/compiler.html
+++ b/src/compiler.html
@@ -8,12 +8,22 @@ Open the web console to see stderr output
arguments = ['', 'hello_world.ll'];
var outputElement = document.getElementById('output');
+ var compilerOutput = '';
print = function(x) {
- outputElement.innerHTML += x;
+ //outputElement.innerHTML += x;
+ compilerOutput += x;
+ };
+
+ // For generated code
+ var Module = {
+ print: function(x) {
+ outputElement.innerHTML += x;
+ }
};
</script>
<script src="compiler.js">
</script>
+<input type="button" value="run!" onclick="eval(compilerOutput)">
</body>
</html>
diff --git a/src/compiler.js b/src/compiler.js
index e87ff760..e4bd8964 100644
--- a/src/compiler.js
+++ b/src/compiler.js
@@ -76,10 +76,12 @@ if (ENVIRONMENT_IS_NODE) {
}
} else if (ENVIRONMENT_IS_WEB) {
- this['print'] = printErr = function(x) {
+ printErr = function(x) {
console.log(x);
};
+ if (!this['print']) this['print'] = printErr;
+
this['read'] = function(url) {
var xhr = new XMLHttpRequest();
xhr.open('GET', url, false);