diff --git a/src/intertyper.js b/src/intertyper.js index b20f9391f..fa3b1f458 100644 --- a/src/intertyper.js +++ b/src/intertyper.js @@ -600,7 +600,7 @@ function intertyper(data) { __result__: true, intertype: 'return', type: item.tokens[1].text, - value: item.tokens[2] ? item.tokens[2].text : null, + value: item.tokens[2] ? parseLLVMSegment(item.tokens.slice(2)) : null, lineNum: item.lineNum, }]; }, diff --git a/src/jsifier.js b/src/jsifier.js index 66cf22e7c..e73a58614 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -571,7 +571,7 @@ function JSify(data) { if (LABEL_DEBUG) ret += "INDENT = INDENT.substr(0, INDENT.length-2);\n"; ret += 'return'; if (item.value) { - ret += ' ' + toNiceIdent(item.value); + ret += ' ' + finalizeLLVMParameter(item.value); } return ret + ';'; }); diff --git a/src/library.js b/src/library.js index c064b928b..b276eba8d 100644 --- a/src/library.js +++ b/src/library.js @@ -40,12 +40,6 @@ var Library = { // string.h - strlen: function(p) { - var q = p; - while (IHEAP[q] != 0) q++; - return q - p; - }, - strspn: function(pstr, pset) { var str = String_copy(pstr, true); var set = String_copy(pset); @@ -78,12 +72,6 @@ var Library = { } }, - strlen: function(ptr) { - var i = 0; - while (IHEAP[ptr+i] != 0) i++; - return i; - }, - strcat: function(pdest, psrc) { var len = Pointer_stringify(pdest).length; // TODO: use strlen, but need dependencies system var i = 0; diff --git a/src/preamble.js b/src/preamble.js index 303ece972..2df8afdb6 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -277,6 +277,12 @@ function llvm_memset_i32(ptr, value, num) { } _llvm_memset_p0i8_i32 = llvm_memset_i32; +function _strlen(ptr) { + var i = 0; + while (IHEAP[ptr+i] != 0) i++; + return i; +} + // Tools PRINTBUFFER = ''; diff --git a/tests/runner.py b/tests/runner.py index 54836ee70..67e3cfbab 100644 --- a/tests/runner.py +++ b/tests/runner.py @@ -678,6 +678,22 @@ if 'benchmark' not in sys.argv: ''' self.do_test(src, '*2,2,5,8,8***8,8,5,8,8***7,2,6,990,7,2*', [], lambda x: x.replace('\n', '*')) + def test_tinyfuncstr(self): + src = ''' + #include + + struct Class { + static char *name1() { return "nameA"; } + char *name2() { return "nameB"; } + }; + + int main() { + printf("*%s,%s*\\n", Class::name1(), (new Class())->name2()); + return 0; + } + ''' + self.do_test(src, '*nameA,nameB*') + def test_llvmswitch(self): src = ''' #include