diff --git a/public/vm/index.js b/public/vm/index.js
index d85afc0..0941090 100644
--- a/public/vm/index.js
+++ b/public/vm/index.js
@@ -13,30 +13,45 @@ c0ffi = require("./c0ffi.js");
// UI interaction functions
function print(arg) {
- $("#output").append(arg);
+ // $("#output").append(arg);
+
+ $("#output").val($("#output").val() + arg);
}
callbacks = c0ffi.default_callbacks;
+
+// conio
callbacks[c0ffi.NATIVE_PRINT] = function(args) {
print(args[0]);
- print("
");
return 0;
}
+callbacks[c0ffi.NATIVE_PRINTLN] = function(args) {
+ print(args[0]);
+ print("\n");
+}
+callbacks[c0ffi.NATIVE_PRINTBOOL] = function(args) {
+ if (args[0])
+ print("false");
+ else
+ print("true");
+}
+callbacks[c0ffi.NATIVE_PRINTCHAR] = function(args) {
+ print(String.fromCharCode(args[0]));
+}
+
callbacks[c0ffi.NATIVE_PRINTINT] = function(args) {
print(args[0]);
- print("
");
return 0;
}
console.log(callbacks);
$("#run").click(function() {
- var input = $("#bytecode").html().replace(/(\r\n|\n|\r)/gm,"");
+ var input = $("#bytecode").val().replace(/(\r\n|\n|\r)/gm,"");
- $("#output").text("");
+ $("#output").val("");
- var file = parser.parse($("#bytecode").text());
- print("
");
+ var file = parser.parse($("#bytecode").val());
print(c0vm.execute(file, callbacks));
});
diff --git a/public/vm/vm.js b/public/vm/vm.js
index c8981af..37ce26a 100644
--- a/public/vm/vm.js
+++ b/public/vm/vm.js
@@ -860,31 +860,47 @@ c0ffi = require("./c0ffi.js");
// UI interaction functions
function print(arg) {
- $("#output").append(arg);
+ // $("#output").append(arg);
+
+ $("#output").val($("#output").val() + arg);
}
callbacks = c0ffi.default_callbacks;
+
+// conio
callbacks[c0ffi.NATIVE_PRINT] = function(args) {
print(args[0]);
- print("
");
return 0;
}
+callbacks[c0ffi.NATIVE_PRINTLN] = function(args) {
+ print(args[0]);
+ print("\n");
+}
+callbacks[c0ffi.NATIVE_PRINTBOOL] = function(args) {
+ if (args[0])
+ print("false");
+ else
+ print("true");
+}
+callbacks[c0ffi.NATIVE_PRINTCHAR] = function(args) {
+ print(String.fromCharCode(args[0]));
+}
+
+
callbacks[c0ffi.NATIVE_PRINTINT] = function(args) {
print(args[0]);
- print("
");
return 0;
}
console.log(callbacks);
$("#run").click(function() {
- var input = $("#bytecode").html().replace(/(\r\n|\n|\r)/gm,"");
+ var input = $("#bytecode").val().replace(/(\r\n|\n|\r)/gm,"");
- $("#output").text("");
+ $("#output").val("");
- var file = parser.parse($("#bytecode").text());
- print("
");
+ var file = parser.parse($("#bytecode").val());
print(c0vm.execute(file, callbacks));
});
diff --git a/views/index.jade b/views/index.jade
index 7cf1626..0e2e974 100644
--- a/views/index.jade
+++ b/views/index.jade
@@ -23,14 +23,14 @@ block body
.col-md-6
p.lbl.
Bytecode
- pre#bytecode.panel.panel-default.code.sh_c.
+ textarea#bytecode.panel.panel-default.code.sh_c.
.row
.col-md-12
p.lbl.
Output
button(type="button")#run.btn.btn-default.btm-btn.pull-right Run
- pre#output.panel.panel-default.code
+ textarea#output.panel.panel-default.code