Permalink
Browse files

finished tuple implementation

  • Loading branch information...
hartsantler committed Oct 10, 2013
1 parent d59559e commit 7316b4d06ef9603597ca4adea9d1585c5d0fb73e
Showing with 33 additions and 11 deletions.
  1. +14 −4 pythonscript.js
  2. +9 −2 pythonscript/python_to_pythonjs.py
  3. +9 −4 runtime/builtins.py
  4. +1 −1 tests/test_tuple.html
View
@@ -1,4 +1,4 @@
// PythonScript Runtime - regenerated on: Wed Oct 9 20:55:21 2013
// PythonScript Runtime - regenerated on: Thu Oct 10 00:32:54 2013
var jsrange = function(num) {
"Emulates Python's range function";
var i, r;
@@ -642,11 +642,21 @@ signature = {"kwargs": {"js_object": undefined}, "args": create_array("self", "j
arguments = get_arguments(signature, args, kwargs);
var self = arguments['self'];
var js_object = arguments['js_object'];
if(js_object) {
self["__dict__"]["js_object"] = js_object;
self["__dict__"]["js_object"] = create_array();
if(js_object instanceof Array) {
arr = self["__dict__"]["js_object"];
i = 0;
length = js_object.length;
while(i < length) {
arr.push( js_object[i] );
i += 1
}
}
else {
self["__dict__"]["js_object"] = create_array();
if(js_object) {
throw TypeError;
}
}
}
@@ -677,24 +677,31 @@ def visit_Call(self, node):
else:
call_has_args = len(node.args) or len(node.keywords) or node.starargs or node.kwargs
name = self.visit(node.func)
if call_has_args:
args = ', '.join(map(self.visit, node.args))
kwargs = ', '.join(map(lambda x: '%s=%s' % (x.arg, self.visit(x.value)), node.keywords))
args_name = '__args_%s' % self.identifier
kwargs_name = '__kwargs_%s' % self.identifier
writer.append('var(%s, %s)' % (args_name, kwargs_name))
self.identifier += 1
writer.append('%s = JSArray(%s)' % (args_name, args))
if name in ('list', 'tuple'):
writer.write( '%s = JS("%s.__dict__.js_object")' % (args_name, args))
else:
writer.append('%s = JSArray(%s)' % (args_name, args))
if node.starargs:
writer.append('%s.push.apply(%s, %s)' % (args_name, args_name, self.visit(node.starargs)))
writer.append('%s = JSObject(%s)' % (kwargs_name, kwargs))
if node.kwargs:
kwargs = self.visit(node.kwargs)
code = "JS('for (var name in %s) { %s[name] = %s[name]; }')" % (kwargs, kwargs_name, kwargs)
writer.append(code)
name = self.visit(node.func)
if call_has_args:
if name == 'dict':
return 'get_attribute(%s, "__call__")(%s, JSObject(js_object=%s))' % (name, args_name, kwargs_name)
View
@@ -50,10 +50,15 @@ def next(self):
class tuple:
def __init__(self, js_object=None):
if js_object:
self.js_object = js_object
else:
self.js_object = JSArray()
self.js_object = JSArray()
if JS('js_object instanceof Array'):
arr = self.js_object
i = 0; length = JS('js_object.length')
while i < length:
JS('arr.push( js_object[i] )')
i += 1
elif js_object:
raise TypeError
def __getitem__(self, index):
__array = self.js_object
View
@@ -16,7 +16,7 @@
j += 1
def test():
global a, b
global a, b, c, d
print('--testing literal style--')
a = (1,2,3) ## literal style
show( a )

0 comments on commit 7316b4d

Please sign in to comment.