Added most of conio, changed bytecode and output to textareas

This commit is contained in:
2015-04-21 18:17:40 -04:00
parent 609b6e17d4
commit 10f5a43a17
3 changed files with 47 additions and 16 deletions

View File

@@ -13,30 +13,45 @@ c0ffi = require("./c0ffi.js");
// UI interaction functions // UI interaction functions
function print(arg) { function print(arg) {
$("#output").append(arg); // $("#output").append(arg);
$("#output").val($("#output").val() + arg);
} }
callbacks = c0ffi.default_callbacks; callbacks = c0ffi.default_callbacks;
// conio
callbacks[c0ffi.NATIVE_PRINT] = function(args) { callbacks[c0ffi.NATIVE_PRINT] = function(args) {
print(args[0]); print(args[0]);
print("<br />");
return 0; 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) { callbacks[c0ffi.NATIVE_PRINTINT] = function(args) {
print(args[0]); print(args[0]);
print("<br />");
return 0; return 0;
} }
console.log(callbacks); console.log(callbacks);
$("#run").click(function() { $("#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()); var file = parser.parse($("#bytecode").val());
print("<br />");
print(c0vm.execute(file, callbacks)); print(c0vm.execute(file, callbacks));
}); });

View File

@@ -860,31 +860,47 @@ c0ffi = require("./c0ffi.js");
// UI interaction functions // UI interaction functions
function print(arg) { function print(arg) {
$("#output").append(arg); // $("#output").append(arg);
$("#output").val($("#output").val() + arg);
} }
callbacks = c0ffi.default_callbacks; callbacks = c0ffi.default_callbacks;
// conio
callbacks[c0ffi.NATIVE_PRINT] = function(args) { callbacks[c0ffi.NATIVE_PRINT] = function(args) {
print(args[0]); print(args[0]);
print("<br />");
return 0; 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) { callbacks[c0ffi.NATIVE_PRINTINT] = function(args) {
print(args[0]); print(args[0]);
print("<br />");
return 0; return 0;
} }
console.log(callbacks); console.log(callbacks);
$("#run").click(function() { $("#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()); var file = parser.parse($("#bytecode").val());
print("<br />");
print(c0vm.execute(file, callbacks)); print(c0vm.execute(file, callbacks));
}); });

View File

@@ -23,14 +23,14 @@ block body
.col-md-6 .col-md-6
p.lbl. p.lbl.
Bytecode Bytecode
pre#bytecode.panel.panel-default.code.sh_c. textarea#bytecode.panel.panel-default.code.sh_c.
&nbsp; &nbsp;
.row .row
.col-md-12 .col-md-12
p.lbl. p.lbl.
Output Output
button(type="button")#run.btn.btn-default.btm-btn.pull-right Run button(type="button")#run.btn.btn-default.btm-btn.pull-right Run
pre#output.panel.panel-default.code textarea#output.panel.panel-default.code
&nbsp; &nbsp;