aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/parser.js2
-rw-r--r--src/postamble.js4
-rw-r--r--src/preamble.js4
-rw-r--r--src/snippets.js4
-rw-r--r--tests/runner.py17
5 files changed, 28 insertions, 3 deletions
diff --git a/src/parser.js b/src/parser.js
index 22fdd3e6..c231e538 100644
--- a/src/parser.js
+++ b/src/parser.js
@@ -1937,7 +1937,7 @@ function JSify(data) {
substrate.addZyme('FunctionStub', {
selectItem: function(item) { return item.intertype == 'functionStub' && !item.JS },
processItem: function(item) {
- if (['_vsnprintf'].indexOf(item.ident) != -1) {
+ if (item.ident in Snippets) {
item.JS = item.ident + ' = ' + Snippets[item.ident].toString();
} else {
item.JS = '// stub for ' + item.ident;
diff --git a/src/postamble.js b/src/postamble.js
index fe5d91f9..f65d51d1 100644
--- a/src/postamble.js
+++ b/src/postamble.js
@@ -12,6 +12,10 @@ function run(args) {
__globalConstructor__();
_main(argc, argv);
+
+ while( __ATEXIT__.length > 0) {
+ __ATEXIT__.pop()();
+ }
}
try {
diff --git a/src/preamble.js b/src/preamble.js
index 21179750..c6752c8f 100644
--- a/src/preamble.js
+++ b/src/preamble.js
@@ -6,6 +6,8 @@ function __globalConstructor__() {
var __THREW__ = false; // Used in checking for thrown exceptions.
+var __ATEXIT__ = [];
+
var HEAP = [];
var HEAPTOP = 0;
@@ -62,8 +64,6 @@ function Pointer_stringify(ptr) {
return ret;
}
-NULL = Pointer_make([]);
-
function _malloc(size) {
// XXX hardcoded ptr impl
var ret = HEAPTOP;
diff --git a/src/snippets.js b/src/snippets.js
index f2fa9440..a97321f9 100644
--- a/src/snippets.js
+++ b/src/snippets.js
@@ -11,5 +11,9 @@ var Snippets = {
if (HEAP[dst+i] == 0) break;
}
},
+
+ _atexit: function(func) {
+ __ATEXIT__.push(func);
+ },
};
diff --git a/tests/runner.py b/tests/runner.py
index bc97cc01..e48ff69d 100644
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -579,6 +579,23 @@ class T(unittest.TestCase):
'''
self.do_test(src, '*cheez: 10+24*')
+ def test_atexit(self):
+ src = '''
+ #include <stdio.h>
+ #include <stdlib.h>
+
+ void clean()
+ {
+ printf("*cleaned*\\n");
+ }
+
+ int main() {
+ atexit(clean);
+ return 0;
+ }
+ '''
+ self.do_test(src, '*cleaned*')
+
def test_fannkuch(self):
results = [ (1,0), (2,1), (3,2), (4,4), (5,7), (6,10), (7, 16), (8,22) ]
for i, j in results: