aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <azakai@mozilla.com>2010-12-13 20:35:45 -0800
committerAlon Zakai <azakai@mozilla.com>2010-12-13 20:35:45 -0800
commit8783a09b1d0a02a378406b9d879818a6c02a6358 (patch)
treea37ed35e94d7e5404e2fe90edaa82f30e80e42f4
parent45c53b2520a326b8d870321a6f39ac17fbc297c9 (diff)
minor fixes for python demo
-rw-r--r--demos/python.html15
-rw-r--r--demos/python.js41
-rw-r--r--src/library.js7
-rw-r--r--src/preamble.js9
4 files changed, 67 insertions, 5 deletions
diff --git a/demos/python.html b/demos/python.html
index d56fc436..d785de70 100644
--- a/demos/python.html
+++ b/demos/python.html
@@ -73,8 +73,12 @@
</p>
<p>
<ul>
- <li>Most core language stuff should work, except for importing modules. Please report bugs if you find them!</li>
- <li>Note that this is an unoptimized build (see <a href="http://code.google.com/p/emscripten/issues/detail?id=8">issue 8</a>)</li>
+ <li>Most core language stuff should work, except for importing non-static modules (in other words, <code>import sys</code> will
+ work, but other modules won't).</li>
+ <li>Please report bugs if you find them!</li>
+ <li>Note that this is an unoptimized build (see <a href="http://code.google.com/p/emscripten/issues/detail?id=8">issue 8</a>),
+ so it may run slowly. Speed may depend on the browser - Chrome 8 in particular is slow, dunno why (maybe
+ <a href="http://code.google.com/p/v8/issues/detail?id=947">V8 issue 947</a>?). Firefox 4 beta 7+ is recommended.</li>
<li>The editor is <a href="https://mozillalabs.com/skywriter/">Skywriter</a>.
</ul>
</p>
@@ -83,9 +87,10 @@
<form onsubmit="execute(editor.value); return false">
<b>Enter some Python</b>:
<input type="submit" value="execute">
- <div id="the_input">
-print "Hello world! Here are some numbers:", [2*x for x in range(5)][:4]
-print "Here is a random language feature:", dir(None)
+ <div id="the_input">import sys
+print 'Hello world! This is Python {} on {}'.format(sys.version, sys.platform)
+
+print 'Here are some numbers:', [2*x for x in range(5)][:4]
</div>
</form>
<hr>
diff --git a/demos/python.js b/demos/python.js
index 1c28f8c8..4efb4515 100644
--- a/demos/python.js
+++ b/demos/python.js
@@ -1,6 +1,47 @@
// This is CPython compiled to JavaScript using Emscripten.
// Python licensing info: http://docs.python.org/license.html
+
+// late additions
+ function Pointer_stringify(ptr) {
+ var ret = "";
+ var i2 = 0;
+ var t;
+ while (1) {
+ t = String.fromCharCode(i[ptr + i2]);
+ if (t == "\0") { break; } else {}
+ ret += t;
+ i2 += 1;
+ }
+ return ret;
+ }
+
+ _strstr = function(ptr1, ptr2) {
+ var str1 = Pointer_stringify(ptr1);
+ var str2 = Pointer_stringify(ptr2);
+ var ret = str1.search(str2);
+ return ret >= 0 ? ptr1 + ret : 0;
+ };
+
+ function _llvm_memcpy_i32(dest, src, num, idunno) {
+ for (var k = 0; k < num; k++) {
+ i[dest + k] = i[src + k];
+ j[dest + k] = j[src + k];
+ }
+ }
+ _memcpy = _llvm_memcpy_i64 = _llvm_memcpy_p0i8_p0i8_i32 = _llvm_memcpy_p0i8_p0i8_i64 = _llvm_memcpy_i32;
+
+ function _llvm_memmove_i32(dest, src, num, idunno) {
+ // not optimized!
+ var tmp = la(num);
+ _memcpy(tmp, src, num);
+ _memcpy(dest, tmp, num);
+ w(tmp);
+ }
+ _memmove = _llvm_memmove_i64 = _llvm_memmove_p0i8_p0i8_i32 = _llvm_memmove_p0i8_p0i8_i64 = _llvm_memmove_i32;
+
+// ==============
+
function ba(c){throw c;}var ca=true,da=null,ea=false;function fa(){return function(){}}function ga(c){return function(){return c}}this.Module={};
Runtime={p:function(c){for(var e=a,b=0;b<c;b++)i[a+b]=j[a+b]=0;a+=c;a=Math.ceil(a/4)*4;return e},g:function(c){for(var e=ha,b=0;b<c;b++)i[ha+b]=j[ha+b]=0;ha+=c;ha=Math.ceil(ha/4)*4;return e},d:function(c,e){return Math.ceil(c/(e?e:4))*(e?e:4)},a:function(c,e){var b=n.length;n[b]=c;n[b+1]=da;Module[e]=c;return b},f:function(c){return c in Runtime.i||c in Runtime.h},m:function(c){return pointingLevels(c)>0},n:function(c){if(isPointerType(c))return ea;if(RegExp(/^\[\d+\ x\ (.*)\]/g).test(c))return ca;
return!Runtime.f(c)&&c[0]=="%"},i:{i1:0,i8:0,i16:0,i32:0,i64:0},h:{"float":0,"double":0},l:function(c,e){var b;(b={i1:e?1:4,i8:e?1:4,i16:e?2:4,i32:4,i64:8,"float":4,"double":8}[c])||(b=4);return b},j:function(c,e){var b={};return e?c.filter(function(d){if(b[d[e]])return ea;return b[d[e]]=ca}):c.filter(function(d){if(b[d])return ea;return b[d]=ca})},o:function(){if(typeof arguments[0]==="object")arguments=arguments[0];for(var c={},e=0;e<arguments.length;e++)c[arguments[e]]=0;return c},r:function(c,
diff --git a/src/library.js b/src/library.js
index f894141e..0fb73611 100644
--- a/src/library.js
+++ b/src/library.js
@@ -315,6 +315,13 @@ var Library = {
return 0;
},
+ strstr: function(ptr1, ptr2) {
+ var str1 = Pointer_stringify(ptr1);
+ var str2 = Pointer_stringify(ptr2);
+ var ret = str1.search(str2);
+ return ret >= 0 ? ptr1 + ret : 0;
+ },
+
strchr: function(ptr, chr) {
ptr--;
do {
diff --git a/src/preamble.js b/src/preamble.js
index 844c0bba..ef29bf82 100644
--- a/src/preamble.js
+++ b/src/preamble.js
@@ -367,6 +367,15 @@ function _llvm_memcpy_i32(dest, src, num, idunno) {
}
_memcpy = _llvm_memcpy_i64 = _llvm_memcpy_p0i8_p0i8_i32 = _llvm_memcpy_p0i8_p0i8_i64 = _llvm_memcpy_i32;
+function _llvm_memmove_i32(dest, src, num, idunno) {
+ // not optimized!
+ var tmp = _malloc(num);
+ _memcpy(tmp, src, num);
+ _memcpy(dest, tmp, num);
+ _free(tmp);
+}
+_memmove = _llvm_memmove_i64 = _llvm_memmove_p0i8_p0i8_i32 = _llvm_memmove_p0i8_p0i8_i64 = _llvm_memmove_i32;
+
function llvm_memset_i32(ptr, value, num) {
for (var i = 0; i < num; i++) {
#if USE_TYPED_ARRAYS