aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <azakai@mozilla.com>2010-11-27 20:58:19 -0800
committerAlon Zakai <azakai@mozilla.com>2010-11-27 20:58:19 -0800
commite0f339fe650ade07087f3e8df8e468bdb5b46a35 (patch)
tree1d773e832969226245cfb623d487320252d63a0e /src
parentc3f19a35f46dfc0879862212140867cb1998cc65 (diff)
fix bug in laying out of constant structures +tests
Diffstat (limited to 'src')
-rw-r--r--src/analyzer.js2
-rw-r--r--src/jsifier.js30
-rw-r--r--src/library.js15
-rw-r--r--src/utility.js7
4 files changed, 34 insertions, 20 deletions
diff --git a/src/analyzer.js b/src/analyzer.js
index 0d0915b0..c57b3be9 100644
--- a/src/analyzer.js
+++ b/src/analyzer.js
@@ -113,7 +113,7 @@ function analyzer(data, givenTypes) {
if (!data.types[zerod]) {
data.types[zerod] = {
name_: zerod,
- fields: [subType],
+ fields: [subType, subType], // Two, so we get the flatFactor right. We care about the flatFactor, not the size here
lineNum: '?',
};
}
diff --git a/src/jsifier.js b/src/jsifier.js
index e465647c..b504cb9d 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -125,28 +125,22 @@ function JSify(data, functionsOnly, givenTypes, givenFunctions) {
}
function alignStruct(values, type) {
- // XXX Need to add padding at the end of structures, using alignMemory()?
- dprint('types', 'alignStruct: ' + dump(type));
- var ret = [];
var typeData = TYPES[type];
assertTrue(typeData);
- var i = 0;
+ var ret = [];
+ var i = 0, soFar = 0;
while (i < values.length) {
- var currField = typeData.fields[i];
- var currValue = values[i];
- if (isStructType[currField]) {
- var fieldTypeData = TYPES[currField];
- assertTrue(fieldTypeData);
- ret = ret.concat(alignStruct(values.slice(i, fieldTypeData.fields.length), currField));
- i += fieldTypeData.fields.length;
- } else {
- ret.push(currValue);
- // pad to align, unless it's a structure and already aligned
- if (typeof currValue !== 'object') {
- ret = ret.concat(zeros(getNativeFieldSize(currField)-1));
- }
- i += 1;
+ // Pad until the right place
+ var padded = typeData.flatFactor ? typeData.flatFactor*i : typeData.flatIndexes[i];
+ while (soFar < padded) {
+ ret.push(0);
+ soFar++;
}
+ // Add current value(s)
+ var currValue = values[i];
+ ret.push(currValue);
+ i += 1;
+ soFar += typeof currValue === 'object' ? currValue.length : 1;
}
return ret;
}
diff --git a/src/library.js b/src/library.js
index 1d64b914..fc5932d9 100644
--- a/src/library.js
+++ b/src/library.js
@@ -70,6 +70,14 @@ var Library = {
}
},
+ fileno: function(file) {
+ return 1; // XXX
+ },
+
+ isatty: function(file) {
+ return 0; // XXX
+ },
+
// stdlib.h
abs: 'Math.abs',
@@ -253,6 +261,10 @@ var Library = {
return chr in { 32: 0, 9: 0, 10: 0, 11: 0, 12: 0, 13: 0 };
},
+ iscntrl: function(chr) {
+ return (chr >= 0 && chr <= 0x1f) || chr === 0x7f;
+ },
+
toupper: function(chr) {
if (chr >= 'a'.charCodeAt(0) && chr <= 'z'.charCodeAt(0)) {
return chr - 'a'.charCodeAt(0) + 'A'.charCodeAt(0);
@@ -279,6 +291,9 @@ var Library = {
return _malloc(size); // warning: leaked
},
__cxa_throw: function(ptr, data, dunno) {
+#if EXCEPTION_DEBUG
+ print('Compiled code throwing an exception, ' + [ptr,data,dunno] + ', at ' + new Error().stack);
+#endif
throw ptr;
},
llvm_eh_exception: function() {
diff --git a/src/utility.js b/src/utility.js
index 391efb14..5020c911 100644
--- a/src/utility.js
+++ b/src/utility.js
@@ -8,7 +8,12 @@ function safeQuote(x) {
function dump(item) {
var CHUNK = 500;
function lineify(text) {
- return text.replace(/.{80}/g, '$&\n');
+ var ret = '';
+ while (text.length > 80) {
+ ret += '// ' + text.substr(0,80) + '\n';
+ text = text.substr(80);
+ }
+ return ret + '// ' + text;
}
try {
return lineify(JSON.stringify(item));