aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <azakai@mozilla.com>2010-11-20 18:38:44 -0800
committerAlon Zakai <azakai@mozilla.com>2010-11-20 18:38:44 -0800
commitd61473b75862c62293318ced24a638d322ff2bd9 (patch)
treeffc9a68267a5543a280568f8842bc2f4eb696c67 /src
parent6c91ad62cdc7026bfe89539770da2c1200359d35 (diff)
misc minor fixes and additions
Diffstat (limited to 'src')
-rw-r--r--src/intertyper.js1
-rw-r--r--src/library.js70
-rw-r--r--src/postamble.js1
-rw-r--r--src/preamble.js6
4 files changed, 78 insertions, 0 deletions
diff --git a/src/intertyper.js b/src/intertyper.js
index a19ed17a..e98012f9 100644
--- a/src/intertyper.js
+++ b/src/intertyper.js
@@ -590,6 +590,7 @@ function intertyper(data, parseFunctions, baseLineNum) {
item.variant = item.tokens[1].text;
item.tokens.splice(1, 1);
}
+ if (item.tokens[1].text == 'exact') item.tokens.splice(1, 1); // XXX - do we need a check at runtime?
var segments = splitTokenList(item.tokens.slice(1));
for (var i = 1; i <= 4; i++) {
if (segments[i-1]) {
diff --git a/src/library.js b/src/library.js
index 3e337c9d..424d00b4 100644
--- a/src/library.js
+++ b/src/library.js
@@ -5,15 +5,53 @@ var Library = {
__print__(Pointer_stringify(__formatString.apply(null, arguments)));
},
+ fprintf: function() {
+ var file = arguments[0]; // TODO: something clever with this
+ var args = Array.prototype.slice.call(arguments, 1);
+ __print__(Pointer_stringify(__formatString.apply(null, args)));
+ },
+
+ fflush: function(file) {
+ __print__(null);
+ },
+
puts: function(p) {
__print__(Pointer_stringify(p) + '\n');
},
+ fputs: function(file, p) {
+ __print__(Pointer_stringify(p) + '\n');
+ },
+
putchar: function(p) {
__print__(String.fromCharCode(p));
},
_ZNSo3putEc: 'putchar',
+ fopen: function(filename, mode) {
+ return 1; // XXX
+ },
+
+ _IO_getc: function(file) {
+ return -1; // EOF
+ },
+
+ ungetc: function(chr, stream) {
+ return chr;
+ },
+
+ feof: function(stream) {
+ return 1;
+ },
+
+ ferror: function(stream) {
+ return 0;
+ },
+
+ fclose: function(stream) {
+ return 0;
+ },
+
_ZNSo5flushEv: function() {
__print__('\n');
},
@@ -54,6 +92,11 @@ var Library = {
return ret;
},
+ getenv: function(name_) {
+ print('getenv: ' + name_); // XXX
+ return 0; // TODO
+ },
+
// string.h
strspn: function(pstr, pset) {
@@ -128,6 +171,16 @@ var Library = {
return 0;
},
+ strchr: function(ptr, chr) {
+ ptr--;
+ do {
+ ptr++;
+ var val = IHEAP[ptr];
+ if (val == chr) return ptr;
+ } while (val);
+ return 0;
+ },
+
// ctype.h
isdigit: function(chr) {
@@ -145,6 +198,16 @@ var Library = {
(chr >= 'A'.charCodeAt(0) && chr <= 'Z'.charCodeAt(0));
},
+ isalnum: function(chr) {
+ return (chr >= '0'.charCodeAt(0) && chr <= '9'.charCodeAt(0)) ||
+ (chr >= 'a'.charCodeAt(0) && chr <= 'z'.charCodeAt(0)) ||
+ (chr >= 'A'.charCodeAt(0) && chr <= 'Z'.charCodeAt(0));
+ },
+
+ isspace: function(chr) {
+ return chr in { 32: 0, 9: 0, 10: 0, 11: 0, 12: 0, 13: 0 };
+ },
+
toupper: function(chr) {
if (chr >= 'a'.charCodeAt(0) && chr <= 'z'.charCodeAt(0)) {
return chr - 'a'.charCodeAt(0) + 'A'.charCodeAt(0);
@@ -330,6 +393,13 @@ var Library = {
// not really working...
assert(0);
},
+
+ // signal.h
+
+ signal: function(sig, func) {
+ // TODO
+ return 0;
+ },
};
load('library_sdl.js');
diff --git a/src/postamble.js b/src/postamble.js
index 010e6e66..b9ccb69b 100644
--- a/src/postamble.js
+++ b/src/postamble.js
@@ -34,6 +34,7 @@ function run(args) {
argv.push(Pointer_make(intArrayFromString(args[i]), null));
pad();
}
+ argv.push(0);
argv = Pointer_make(argv, null);
__globalConstructor__();
diff --git a/src/preamble.js b/src/preamble.js
index a39fc515..1623d387 100644
--- a/src/preamble.js
+++ b/src/preamble.js
@@ -337,6 +337,12 @@ function _strlen(ptr) {
PRINTBUFFER = '';
function __print__(text) {
+ if (text === null) {
+ // Flush
+ print(PRINTBUFFER);
+ PRINTBUFFER = '';
+ return;
+ }
// We print only when we see a '\n', as console JS engines always add
// one anyhow.
PRINTBUFFER = PRINTBUFFER + text;