aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/preamble.js42
-rw-r--r--src/snippets.js25
-rw-r--r--tests/runner.py65
3 files changed, 46 insertions, 86 deletions
diff --git a/src/preamble.js b/src/preamble.js
index 9dfacca7..a2ceaa0c 100644
--- a/src/preamble.js
+++ b/src/preamble.js
@@ -154,33 +154,6 @@ function __formatString() {
return Pointer_make(ret);
}
-function _printf() {
- var text = Pointer_stringify(__formatString.apply(null, arguments));
- // Our print() will print a \n anyhow... remove dupes
- if (text[text.length-1] == '\n') {
- text = text.substr(0, text.length-1);
- }
- print(text);
-}
-
-function _puts(p) {
- _printf(p);
-// print("\n"); // XXX print already always adds one
-}
-
-function _putchar(p) {
- print(String.fromCharCode(p));
-}
-
-function _strlen(p) {
- // XXX hardcoded ptr impl
- var q = p;
- while (HEAP[q] != 0) q++;
- return q - p;
-// p = Pointer_niceify(p);
-// return p.slab.length; // XXX might want to find the null terminator...
-}
-
// Copies a list of num items on the HEAP into a
// a normal JavaScript array of numbers
function Array_copy(ptr, num) {
@@ -218,13 +191,20 @@ function _llvm_memcpy_i32(dest, src, num, idunno) {
_llvm_memcpy_i64 = _llvm_memcpy_i32;
// Tools
-// println((new Error).stack); // for stack traces
-function println(text) {
- print(text);// + "\n"); // XXX print already always adds one
+PRINTBUFFER = '';
+function __print__(text) {
+ // We print only when we see a '\n', as console JS engines always add
+ // one anyhow.
+ PRINTBUFFER = PRINTBUFFER + text;
+ var endIndex;
+ while ((endIndex = PRINTBUFFER.indexOf('\n')) != -1) {
+ print(PRINTBUFFER.substr(0, endIndex));
+ PRINTBUFFER = PRINTBUFFER.substr(endIndex + 1);
+ }
}
-function jrint(label, obj) {
+function jrint(label, obj) { // XXX manual debugging
if (!obj) {
obj = label;
label = '';
diff --git a/src/snippets.js b/src/snippets.js
index ddcb6d37..ec29f371 100644
--- a/src/snippets.js
+++ b/src/snippets.js
@@ -1,4 +1,20 @@
var Snippets = {
+ // stdio.h
+
+ printf: function() {
+ __print__(Pointer_stringify(__formatString.apply(null, arguments)));
+ },
+
+ puts: function(p) {
+ __print__(Pointer_stringify(p) + '\n');
+ },
+
+ putchar: function(p) {
+ __print__(String.fromCharCode(p));
+ },
+
+ // ?
+
vsnprintf: function(dst, num, src, ptr) {
var args = Array_copy(ptr+1, HEAP[ptr]); // # of args in in first place
var text = __formatString.apply(null, [src].concat(args));
@@ -12,6 +28,14 @@ var Snippets = {
__ATEXIT__.push(func);
},
+ // string.h
+
+ strlen: function(p) {
+ var q = p;
+ while (HEAP[q] != 0) q++;
+ return q - p;
+ },
+
strspn: function(pstr, pset) {
var str = String_copy(pstr, true);
var set = String_copy(pset);
@@ -119,4 +143,5 @@ var Snippets = {
Snippets.__cxa_atexit = Snippets.atexit;
// iostream
Snippets._ZNSolsEi = Snippets._ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc = Snippets._ZNSolsEd = Snippets._ZNSolsEPFRSoS_E = function(stream, data) { print(data) };
+Snippets._ZNSt8ios_base4InitD1Ev = Snippets._ZNSt8ios_base4InitC1Ev;
diff --git a/tests/runner.py b/tests/runner.py
index 84ff4bf6..186d4bbc 100644
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -74,59 +74,14 @@ class T(unittest.TestCase):
output_processor(output)
if output is not None and 'Traceback' in output: print output; assert (0) # 'generating JavaScript failed'
if DEBUG: print "\nGenerated JavaScript:\n\n===\n\n%s\n\n===\n\n" % output
- # if not DEBUG:
+ #assert(0)
js_output = timeout_run(Popen([JS_ENGINE] + JS_ENGINE_OPTS + [filename + '.o.js'] + args, stdout=PIPE, stderr=STDOUT), 60, 'Execution')
if output_nicerizer is not None:
js_output = output_nicerizer(js_output)
- # else:
- # print "[[JS output]]"
- # ret = "Output shown on screen, test not actually run!"
- # Popen([JS_ENGINE, filename + '.o.js'] + args, stderr=STDOUT).communicate()[0]
self.assertContained(expected_output, js_output)
self.assertNotContained('ERROR', js_output)
- return
-
- if not no_python:
- #DEBUG = True
- SPIDERMONKEY = True
- if SPIDERMONKEY:
- if DEBUG: print "[[RJS ==> SpiderMonkey parsed tree]]"
- args = [SPIDERMONKEY_SHELL, '-e', 'parse(snarf(\"%s\"))' % (filename + '.o.js')]
- output = Popen(args, stdout=PIPE, stderr=STDOUT).communicate()[0]
- f = open(filename + 'o.js.sm', 'w')
- f.write(output)
- f.close()
- else:
- if DEBUG: print "[[RJS ==> RPython]]"
- output = Popen(['python', RJS_RPYTHON, filename + '.o.js', filename + '.o.js.py'], stdout=PIPE, stderr=STDOUT).communicate()[0]
- if DEBUG: print output
-
- py_output = Popen(['python', filename + '.o.js.py'] + args, stdout=PIPE, stderr=STDOUT).communicate()[0]
- if output_nicerizer is not None:
- py_output = output_nicerizer(py_output)
- self.assertContained(expected_output, py_output)
- if js_output != py_output:
- print "WARNING: js and py outputs not identical (but each is similar enough to the expected_output)"
-
- PYPY = True
-# PYPY = False
- if PYPY:
- pypy_source = filename.replace('.', '_') + '_o_js_py.py'
- if DEBUG: print "[[RPython ==> PyPy]]"
- output = Popen(['python', RJS_PYPY, filename + '.o.js.py', pypy_source], stdout=PIPE, stderr=STDOUT).communicate()[0]
- print output
-
-# # Python on pypy-ready source
- # pypy_output = Popen(['python', pypy_source] + args, stdout=PIPE, stderr=STDOUT).communicate()[0]
- # if output_nicerizer is not None:
- # pypy_output = output_nicerizer(pypy_output)
- # self.assertContained(expected_output, pypy_output)
- # if js_output != pypy_output:
- # print "WARNING: js and PYpy outputs not identical (but each is similar enough to the expected_output)"
-
- # PyPy compilation of source to binary
-
-# shutil.rmtree(dirname)
+
+# shutil.rmtree(dirname) # TODO: leave no trace in memory. But for now nice for debugging
def assertContained(self, value, string):
if value not in string:
@@ -228,13 +183,13 @@ class T(unittest.TestCase):
int main(int argc, char **argv)
{
- printf("*%d", argc);
+ printf("*%d\\n", argc);
puts(argv[1]);
puts(argv[2]);
- printf("%d", atoi(argv[3])+2);
+ printf("%d\\n", atoi(argv[3])+2);
const char *foolingthecompiler = "\\rabcd";
- printf("%d", strlen(foolingthecompiler)); // Tests parsing /0D in llvm - should not be a 0 (end string) then a D!
- printf("%s*", NULL); // Should print '(null)', not the string at address 0, which is a real address for us!
+ printf("%d\\n", strlen(foolingthecompiler)); // Tests parsing /0D in llvm - should not be a 0 (end string) then a D!
+ printf("%s\\n", NULL); // Should print '(null)', not the string at address 0, which is a real address for us!
return 0;
}
'''
@@ -728,11 +683,11 @@ class T(unittest.TestCase):
def zzztest_raytrace(self):
src = open(path_from_root(['tests', 'raytrace.cpp']), 'r').read()
output = open(path_from_root(['tests', 'raytrace.ppm']), 'r').read()
- self.do_test(src, output, ['3'])
+ self.do_test(src, output, ['1'])
def test_fasta(self):
- results = [ (1,'''GG*ctt*tgagc*'''), (20,'''GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTT*cttBtatcatatgctaKggNcataaaSatgtaaaDcDRtBggDtctttataattcBgtcg*tacgtgtagcctagtgtttgtgttgcgttatagtctatttgtggacacagtatggtcaaa*tgacgtcttttgatctgacggcgttaacaaagatactctg*'''),
-(50,'''GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGGGAGGCCGAGGCGGGCGGA*TCACCTGAGGTCAGGAGTTCGAGACCAGCCTGGCCAACAT*cttBtatcatatgctaKggNcataaaSatgtaaaDcDRtBggDtctttataattcBgtcg*tactDtDagcctatttSVHtHttKtgtHMaSattgWaHKHttttagacatWatgtRgaaa*NtactMcSMtYtcMgRtacttctWBacgaa*agatactctgggcaacacacatacttctctcatgttgtttcttcggacctttcataacct*ttcctggcacatggttagctgcacatcacaggattgtaagggtctagtggttcagtgagc*ggaatatcattcgtcggtggtgttaatctatctcggtgtagcttataaatgcatccgtaa*gaatattatgtttatttgtcggtacgttcatggtagtggtgtcgccgatttagacgtaaa*ggcatgtatg*''') ]
+ results = [ (1,'''GG*ctt**tgagc*'''), (20,'''GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTT*cttBtatcatatgctaKggNcataaaSatgtaaaDcDRtBggDtctttataattcBgtcg**tacgtgtagcctagtgtttgtgttgcgttatagtctatttgtggacacagtatggtcaaa**tgacgtcttttgatctgacggcgttaacaaagatactctg*'''),
+(50,'''GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGGGAGGCCGAGGCGGGCGGA*TCACCTGAGGTCAGGAGTTCGAGACCAGCCTGGCCAACAT*cttBtatcatatgctaKggNcataaaSatgtaaaDcDRtBggDtctttataattcBgtcg**tactDtDagcctatttSVHtHttKtgtHMaSattgWaHKHttttagacatWatgtRgaaa**NtactMcSMtYtcMgRtacttctWBacgaa**agatactctgggcaacacacatacttctctcatgttgtttcttcggacctttcataacct**ttcctggcacatggttagctgcacatcacaggattgtaagggtctagtggttcagtgagc**ggaatatcattcgtcggtggtgttaatctatctcggtgtagcttataaatgcatccgtaa**gaatattatgtttatttgtcggtacgttcatggtagtggtgtcgccgatttagacgtaaa**ggcatgtatg*''') ]
for i, j in results:
src = open(path_from_root(['tests', 'fasta.cpp']), 'r').read()
self.do_test(src, j, [str(i)], lambda x: x.replace('\n', '*'), no_python=True, no_build=i>1)