aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/compiler.js13
-rw-r--r--src/framework.js20
-rw-r--r--src/intertyper.js6
-rw-r--r--src/jsifier.js4
-rw-r--r--src/parseTools.js10
-rw-r--r--src/settings.js5
6 files changed, 43 insertions, 15 deletions
diff --git a/src/compiler.js b/src/compiler.js
index b4e9530a..72ef554c 100644
--- a/src/compiler.js
+++ b/src/compiler.js
@@ -8,6 +8,10 @@ if (!this['read']) {
read = function(f) { snarf(f) };
}
+// Basic utilities
+
+load('utility.js');
+
// Load settings, can be overridden by commandline
load('settings.js');
@@ -18,9 +22,16 @@ for (setting in settings) {
}
var CONSTANTS = { 'QUANTUM_SIZE': QUANTUM_SIZE };
+if (CORRECT_SIGNS === 2) {
+ CORRECT_SIGNS_LINES = set(CORRECT_SIGNS_LINES); // for fast checking
+}
+
+if (CORRECT_OVERFLOWS === 2) {
+ CORRECT_OVERFLOWS_LINES = set(CORRECT_OVERFLOWS_LINES); // for fast checking
+}
+
// Load compiler code
-load('utility.js');
load('framework.js');
load('parseTools.js');
load('intertyper.js');
diff --git a/src/framework.js b/src/framework.js
index e9ff592e..959d73fd 100644
--- a/src/framework.js
+++ b/src/framework.js
@@ -140,6 +140,12 @@ Substrate.prototype = {
}
};
+// Global access to the currently-being processed item.
+// Note that if you overload process in Actor, this will need to be set if you rely on it.
+var Framework = {
+ currItem: null
+};
+
Actor = function() { };
Actor.prototype = {
process: function(items) {
@@ -147,7 +153,9 @@ Actor.prototype = {
for (var i = 0; i < items.length; i++) {
var item = items[i];
try {
+ Framework.currItem = item;
var outputs = this.processItem(item);
+ Framework.currItem = null; // Do not keep an unneeded reference. Note that we don't care about this if an exception is thrown
if (outputs) {
ret = ret.concat(outputs);
}
@@ -157,18 +165,6 @@ Actor.prototype = {
}
}
return ret;
- },
- processPairs: function(items, func) {
- var ret = [];
- for (var i = 0; i < items.length; i += 2) {
- try {
- ret = ret.concat(func(items[i], items[i+1]));
- } catch (e) {
- print("Exception in processPairs(), current items are: " + dump(items[i]) + ' :::: ' + dump(items[i+1]));
- throw e;
- }
- }
- return ret;
}
};
diff --git a/src/intertyper.js b/src/intertyper.js
index e4a3cf4b..a8254b30 100644
--- a/src/intertyper.js
+++ b/src/intertyper.js
@@ -86,6 +86,12 @@ var Debugging = {
getComment: function(lineNum) {
return lineNum in this.llvmLineToSourceLine ? ' //@line ' + this.llvmLineToSourceLine[lineNum] + ' "' +
this.llvmLineToSourceFile[lineNum] + '"' : '';
+ },
+
+ getIdentifier: function(lineNum) {
+ var sourceFile = this.llvmLineToSourceFile[lineNum];
+ if (!sourceFile) return null;
+ return sourceFile.split('/').slice(-1)[0] + ':' + this.llvmLineToSourceLine[lineNum];
}
};
diff --git a/src/jsifier.js b/src/jsifier.js
index a6ce4c6a..f3e55a39 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -758,7 +758,7 @@ function JSify(data, functionsOnly, givenTypes, givenFunctions, givenGlobalVaria
function makeSignOp(value, type, op) { // TODO: If value isNumber, do this at compile time
if (!value) return value;
- if (!CORRECT_SIGNS && !CHECK_SIGNS) return value;
+ if (!correctSigns() && !CHECK_SIGNS) return value;
if (type in Runtime.INT_TYPES) {
var bits = parseInt(type.substr(1));
// shortcuts for 32-bit case
@@ -777,7 +777,7 @@ function JSify(data, functionsOnly, givenTypes, givenFunctions, givenGlobalVaria
function handleOverflow(text, bits) {
if (!bits) return text;
- if (CORRECT_OVERFLOWS && bits <= 32) text = '(' + text + ')&' + (Math.pow(2, bits) - 1);
+ if (bits <= 32 && correctOverflows()) text = '(' + text + ')&' + (Math.pow(2, bits) - 1);
if (!CHECK_OVERFLOWS) return text;
return 'CHECK_OVERFLOW(' + text + ', ' + bits + ')';
}
diff --git a/src/parseTools.js b/src/parseTools.js
index fed1ee7c..81831d75 100644
--- a/src/parseTools.js
+++ b/src/parseTools.js
@@ -537,3 +537,13 @@ function indentify(text, indent) {
return text.split('\n').map(function(line) { return indent + line }).join('\n');
}
+// Correction tools
+
+function correctSigns() {
+ return CORRECT_SIGNS === 1 || (CORRECT_SIGNS === 2 && Debugging.getIdentifier(Framework.currItem.lineNum) in CORRECT_SIGNS_LINES);
+}
+
+function correctOverflows() {
+ return CORRECT_OVERFLOWS === 1 || (CORRECT_OVERFLOWS === 2 && Debugging.getIdentifier(Framework.currItem.lineNum) in CORRECT_OVERFLOWS_LINES);
+}
+
diff --git a/src/settings.js b/src/settings.js
index 4eb6b6a4..38e75baa 100644
--- a/src/settings.js
+++ b/src/settings.js
@@ -16,6 +16,8 @@ QUANTUM_SIZE = 4; // This is the size of an individual field in a structure. 1 w
CORRECT_SIGNS = 1; // Whether we make sure to convert unsigned values to signed values.
// Decreases performance with additional runtime checks. Might not be
// needed in some kinds of code.
+ // If equal to 2, done on a line-by-line basis according to
+ // CORRECT_SIGNS_LINES
CHECK_SIGNS = 0; // Runtime errors for signing issues that need correcting.
// It is recommended to use this in
// order to find if your code needs CORRECT_SIGNS. If you can get your
@@ -56,6 +58,9 @@ CORRECT_OVERFLOWS = 1; // Experimental code that tries to prevent unexpected JS
// not rely on overflows in your C/C++ code, as even if this option works,
// it slows things down.
//
+ // If equal to 2, done on a line-by-line basis according to
+ // CORRECT_OVERFLOWS_LINES
+ //
// NOTE: You can introduce signing issues by using this option. If you
// take a large enough 32-bit value, and correct it for overflows,
// you may get a negative number, as JS & operations are signed.