aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compiler.js1
-rw-r--r--src/modules.js7
-rw-r--r--src/parseTools.js10
-rw-r--r--tests/runner.py11
4 files changed, 26 insertions, 3 deletions
diff --git a/src/compiler.js b/src/compiler.js
index 699b0393..46d6b5cf 100644
--- a/src/compiler.js
+++ b/src/compiler.js
@@ -74,6 +74,7 @@ var inter = intertyper(lines);
for (suffix in set('', '_sdl', '_gl', '_browser')) {
eval(processMacros(preprocess(read('library' + suffix + '.js'), CONSTANTS)));
}
+LibraryManager.init();
JSify(analyzer(inter));
diff --git a/src/modules.js b/src/modules.js
index a91a41ec..fd18fc72 100644
--- a/src/modules.js
+++ b/src/modules.js
@@ -145,9 +145,16 @@ var Functions = {
};
var LibraryManager = {
+ ready: false,
+
+ init: function() {
+ this.ready = true;
+ },
+
// Given an ident, see if it is an alias for something, and so forth, returning
// the earliest ancestor (the root)
getRootIdent: function(ident) {
+ if (!this.ready) return null;
var ret = Library[ident];
if (!ret) return null;
var last = ident;
diff --git a/src/parseTools.js b/src/parseTools.js
index 60ebf309..19aaa63d 100644
--- a/src/parseTools.js
+++ b/src/parseTools.js
@@ -634,9 +634,15 @@ function makeGetValue(ptr, pos, type, noNeedFirst) {
}
}
-function indexizeFunctions(value) { // TODO: Also check for other functions (externals, library, etc.)
+function indexizeFunctions(value) { // TODO: Also check for externals
if (value in Functions.currFunctions) {
- value = Functions.getIndex(value); // Store integer value
+ return Functions.getIndex(value);
+ }
+ if (value && value[0] == '_') {
+ var rootIdent = LibraryManager.getRootIdent(value.slice(1));
+ if (rootIdent && typeof Library[rootIdent] === 'function') {
+ return Functions.getIndex('_' + rootIdent);
+ }
}
return value;
}
diff --git a/tests/runner.py b/tests/runner.py
index 4ce0746d..a2864aac 100644
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -969,6 +969,8 @@ if 'benchmark' not in sys.argv:
fp_t globally1 = calc1;
fp_t globally2 = calc2;
+ int nothing(const char *str) { return 0; }
+
int main()
{
fp_t fp = calc1;
@@ -983,10 +985,17 @@ if 'benchmark' not in sys.argv:
printf("*%d,%d", t == calc1, t == calc2);
t = calc2;
printf(",%d,%d*\\n", t == calc1, t == calc2);
+
+ int (*other)(const char *str);
+ other = nothing;
+ other("*hello!*");
+ other = puts;
+ other("*goodbye!*");
+
return 0;
}
'''
- self.do_test(src, '*26,26,90,90,26,90*\n*1,0,0,1*')
+ self.do_test(src, '*26,26,90,90,26,90*\n*1,0,0,1*\n*goodbye!*')
def test_emptyclass(self):
src = '''