diff options
author | alon@honor <none@none> | 2010-09-05 17:05:35 -0700 |
---|---|---|
committer | alon@honor <none@none> | 2010-09-05 17:05:35 -0700 |
commit | ed6f0355817810a757e4e464474e03c69264ce5f (patch) | |
tree | 322d707b22cd75d594d78652920da05cca1b1c67 /src | |
parent | 3e6c745b828932f237e472c484bb2ac2abfb8e3e (diff) |
snippets work
Diffstat (limited to 'src')
-rw-r--r-- | src/parser.js | 5 | ||||
-rw-r--r-- | src/preamble.js | 7 | ||||
-rw-r--r-- | src/snippets.js | 16 |
3 files changed, 21 insertions, 7 deletions
diff --git a/src/parser.js b/src/parser.js index 491e31f5..b9873175 100644 --- a/src/parser.js +++ b/src/parser.js @@ -1942,8 +1942,9 @@ function JSify(data) { substrate.addZyme('FunctionStub', { selectItem: function(item) { return item.intertype == 'functionStub' && !item.JS }, processItem: function(item) { - if (item.ident in Snippets) { - item.JS = item.ident + ' = ' + Snippets[item.ident].toString(); + var shortident = item.ident.substr(1); + if (shortident in Snippets) { + item.JS = item.ident + ' = ' + Snippets[shortident].toString(); } else { item.JS = '// stub for ' + item.ident; } diff --git a/src/preamble.js b/src/preamble.js index c6752c8f..8b10b3c2 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -132,7 +132,7 @@ function _putchar(p) { } function _strlen(p) { -// XXX hardcoded ptr impl + // XXX hardcoded ptr impl var q = p; while (HEAP[q] != 0) q++; return q - p; @@ -140,6 +140,11 @@ function _strlen(p) { // return p.slab.length; // XXX might want to find the null terminator... } +function String_copy(p) { + // XXX hardcoded ptr impl + return HEAP.slice(p, p+_strlen(p)).concat([0]); +} + // stdlib.h // Get a pointer, return int value of the string it points to diff --git a/src/snippets.js b/src/snippets.js index b9f6267f..a93fd0fd 100644 --- a/src/snippets.js +++ b/src/snippets.js @@ -1,5 +1,5 @@ var Snippets = { - _vsnprintf: function(dst, num, src, ptr) { + vsnprintf: function(dst, num, src, ptr) { var args = []; while (HEAP[ptr] != 0) { args.push(HEAP[ptr]); @@ -12,11 +12,19 @@ var Snippets = { } }, - _atexit: function(func) { + atexit: function(func) { __ATEXIT__.push(func); }, + + strspn: function(pstr, pset) { + var str = String_copy(pstr); + var set = String_copy(pset); + var i = 0; + while (set.indexOf(str[i]) != -1) i++; // Must halt, as 0 is in both + return i; + }, }; -// Synonyms -Snippets.___cxa_atexit = Snippets._atexit; +// Aliases +Snippets.__cxa_atexit = Snippets.atexit; |