Fixed strings
This commit is contained in:
@@ -28,7 +28,6 @@ function i32_to_array(i32) {
|
|||||||
((i32 >> 8) & 0xFF),
|
((i32 >> 8) & 0xFF),
|
||||||
((i32 >> 16) & 0xFF),
|
((i32 >> 16) & 0xFF),
|
||||||
((i32 >> 24) & 0xFF)];
|
((i32 >> 24) & 0xFF)];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function array_to_i32(array) {
|
function array_to_i32(array) {
|
||||||
@@ -63,7 +62,7 @@ var ProgramState = function(parsed_file, callback_dict) {
|
|||||||
try {
|
try {
|
||||||
this.natives[i] = callback_dict[i];
|
this.natives[i] = callback_dict[i];
|
||||||
} catch (key_not_found) {
|
} catch (key_not_found) {
|
||||||
dict[i] = function (arg) {
|
this.natives[i] = function (arg) {
|
||||||
console.log("Native function " + name + " called, ran method stub.");
|
console.log("Native function " + name + " called, ran method stub.");
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
@@ -342,7 +341,7 @@ ProgramState.prototype.step = function() {
|
|||||||
}
|
}
|
||||||
log("Calling native function with index " + index + " with arguments " +
|
log("Calling native function with index " + index + " with arguments " +
|
||||||
arg_array);
|
arg_array);
|
||||||
this.push(native_function(arg_array));
|
this.push(native_function(arg_array, this));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Memory allocation operations:
|
// Memory allocation operations:
|
||||||
|
|||||||
@@ -24,13 +24,25 @@ callbacks[c0ffi.NATIVE_STRING_LENGTH] = function(args) {
|
|||||||
return args[0].length;
|
return args[0].length;
|
||||||
}
|
}
|
||||||
|
|
||||||
callbacks[c0ffi.NATIVE_STRING_TO_CHARARRAY] = function(args) {
|
callbacks[c0ffi.NATIVE_STRING_TO_CHARARRAY] = function(args, vm) {
|
||||||
return args[0];
|
var address = vm.heap.length;
|
||||||
|
vm.heap.push(args[0].length+1);
|
||||||
|
vm.heap.push(1);
|
||||||
|
for (var i = 0; i < args[0].length; i++) {
|
||||||
|
vm.heap.push(args[0][i]);
|
||||||
|
}
|
||||||
|
vm.heap.push(0);
|
||||||
|
return address;
|
||||||
}
|
}
|
||||||
|
|
||||||
callbacks[c0ffi.NATIVE_STRING_FROM_CHARARRAY] = function(args) {
|
callbacks[c0ffi.NATIVE_STRING_FROM_CHARARRAY] = function(args, vm) {
|
||||||
console.log("string_from_chararray: " + args);
|
var i = args[0] + 2;
|
||||||
return args[0];
|
var result = "";
|
||||||
|
while (vm.heap[i] !== 0) {
|
||||||
|
result += vm.heap[i];
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
callbacks[c0ffi.NATIVE_CHAR_CHR] = function(args) {
|
callbacks[c0ffi.NATIVE_CHAR_CHR] = function(args) {
|
||||||
@@ -38,7 +50,6 @@ callbacks[c0ffi.NATIVE_CHAR_CHR] = function(args) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
callbacks[c0ffi.NATIVE_CHAR_ORD] = function(args) {
|
callbacks[c0ffi.NATIVE_CHAR_ORD] = function(args) {
|
||||||
console.log("native_car_ord: " + args);
|
|
||||||
if (typeof args[0] == "string")
|
if (typeof args[0] == "string")
|
||||||
return args[0].charCodeAt(0);
|
return args[0].charCodeAt(0);
|
||||||
return args[0];
|
return args[0];
|
||||||
|
|||||||
Reference in New Issue
Block a user