aboutsummaryrefslogtreecommitdiff
path: root/src/preamble.js
diff options
context:
space:
mode:
authoralon@honor <none@none>2010-09-11 14:15:46 -0700
committeralon@honor <none@none>2010-09-11 14:15:46 -0700
commitac805ebf0af3ad7873dbed0f0f28e5f6d481c464 (patch)
tree29d01717b6c05cfb43749fd6a88610079447dc74 /src/preamble.js
parentc91d6e20014b124c32d29d301e39a5782570300e (diff)
Catch a corner case with 0 in varargs
Diffstat (limited to 'src/preamble.js')
-rw-r--r--src/preamble.js15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/preamble.js b/src/preamble.js
index 4d473ee3..2ededac1 100644
--- a/src/preamble.js
+++ b/src/preamble.js
@@ -173,9 +173,18 @@ function _strlen(p) {
// return p.slab.length; // XXX might want to find the null terminator...
}
-function String_copy(p, addZero) {
+// Copies a list of num items on the HEAP into a
+// a normal JavaScript array of numbers
+function Array_copy(ptr, num) {
// XXX hardcoded ptr impl
- return HEAP.slice(p, p+_strlen(p)).concat(addZero ? [0] : []);
+ return HEAP.slice(ptr, ptr+num);
+}
+
+// Copies a C-style string, terminated by a zero, from the HEAP into
+// a normal JavaScript array of numbers
+function String_copy(ptr, addZero) {
+ // XXX hardcoded ptr impl
+ return Array_copy(ptr, _strlen(ptr)).concat(addZero ? [0] : []);
}
// stdlib.h
@@ -215,6 +224,8 @@ function jrint(label, obj) {
print(label + JSON.stringify(obj));
}
+// This processes a 'normal' string into a C-line array of numbers.
+// For LLVM-originating strings, see parser.js:parseLLVMString function
function intArrayFromString(stringy) {
var ret = [];
var t;