This whole "strings" thing isn't quite working...

This commit is contained in:
Mitchell Plamann
2015-04-12 00:56:07 -04:00
parent ee99956b52
commit 65197535bc
3 changed files with 55 additions and 11 deletions

View File

@@ -20,6 +20,30 @@ callbacks[c0ffi.NATIVE_PRINTLN] = function(args) {
return 0;
}
callbacks[c0ffi.NATIVE_STRING_LENGTH] = function(args) {
return args[0].length;
}
callbacks[c0ffi.NATIVE_STRING_TO_CHARARRAY] = function(args) {
return args[0];
}
callbacks[c0ffi.NATIVE_STRING_FROM_CHARARRAY] = function(args) {
console.log("string_from_chararray: " + args);
return args[0];
}
callbacks[c0ffi.NATIVE_CHAR_CHR] = function(args) {
return String.fromCharCode(args[0]);
}
callbacks[c0ffi.NATIVE_CHAR_ORD] = function(args) {
console.log("native_car_ord: " + args);
if (typeof args[0] == "string")
return args[0].charCodeAt(0);
return args[0];
}
function doTest(filename, expected_result) {
return function(test) {
var result = c0vm.execute(parser.parse(filename), callbacks, false);
@@ -98,3 +122,14 @@ exports.testArith = function(test) {
printout);
test.done();
}
exports.testPIAZZA1 = doTest("piazza1.c0.bc0", 18);
exports.testSTRINGS = function(test) {
printout = "";
var result = c0vm.execute(parser.parse("strings.c0.bc0"), callbacks, false);
test.ok(printout == "hello there!?",
"strings.c0.bc0 - Did not print to screen correctly, result was " +
printout);
test.done();
}