Skip to content

Commit 92a90bc

Browse files
author
hartsantler
committed
optimized calling, new with fastdef to declare functions with optimized calling (but not automagicly callable from javascript)
1 parent 0ba9d32 commit 92a90bc

4 files changed

Lines changed: 131 additions & 58 deletions

File tree

pythonjs.js

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// PythonScript Runtime - regenerated on: Thu Nov 7 21:54:00 2013
1+
// PythonScript Runtime - regenerated on: Sat Nov 9 21:41:45 2013
2+
__NULL_OBJECT__ = Object.create(null);
23
var jsrange = function(num) {
34
"Emulates Python's range function";
45
var i, r;
@@ -677,7 +678,7 @@ return true;
677678
bases = C.__bases__;
678679
i = 0;
679680
while(i < get_attribute(bases, "length")) {
680-
if(get_attribute(issubclass, "__call__")([get_attribute(bases, "__getitem__")([i], Object()), B], Object())) {
681+
if(issubclass([get_attribute(bases, "__getitem__")([i], Object()), B], __NULL_OBJECT__)) {
681682
return true;
682683
}
683684

@@ -713,7 +714,7 @@ if(ob_class === undefined) {
713714
return false;
714715
}
715716
else {
716-
return get_attribute(issubclass, "__call__")([ob_class, klass], Object());
717+
return issubclass([ob_class, klass], __NULL_OBJECT__);
717718
}
718719

719720
}
@@ -1017,7 +1018,7 @@ _setup_str_prototype.args_signature = [];
10171018
_setup_str_prototype.kwargs_signature = { };
10181019
_setup_str_prototype.types_signature = { };
10191020
_setup_str_prototype.pythonscript_function = true;
1020-
get_attribute(_setup_str_prototype, "__call__")(create_array(), Object());
1021+
_setup_str_prototype();
10211022
var _setup_array_prototype = function(args, kwargs) {
10221023
var func = function(a) {
10231024
if(this.indexOf(a) == -1) {
@@ -1069,7 +1070,7 @@ _setup_array_prototype.args_signature = [];
10691070
_setup_array_prototype.kwargs_signature = { };
10701071
_setup_array_prototype.types_signature = { };
10711072
_setup_array_prototype.pythonscript_function = true;
1072-
get_attribute(_setup_array_prototype, "__call__")(create_array(), Object());
1073+
_setup_array_prototype();
10731074
var range = function(args, kwargs) {
10741075
var i, r;
10751076
if(args instanceof Array && {}.toString.call(kwargs) === '[object Object]' && arguments.length == 2) {
@@ -1088,7 +1089,7 @@ var num = arguments['num'];
10881089
"Emulates Python's range function";
10891090
var i, r;
10901091
i = 0;
1091-
r = get_attribute(list, "__call__")(create_array(), Object());
1092+
r = get_attribute(list, "__call__")();
10921093
while(i < num) {
10931094
get_attribute(get_attribute(r, "append"), "__call__")([i], Object());
10941095
i += 1
@@ -1121,7 +1122,7 @@ signature = {"kwargs": Object(), "args": create_array("obj")};
11211122
signature["function_name"] = "len";
11221123
arguments = get_arguments(signature, args, kwargs);
11231124
var obj = arguments['obj'];
1124-
return get_attribute(get_attribute(obj, "__len__"), "__call__")(create_array(), Object());
1125+
return get_attribute(get_attribute(obj, "__len__"), "__call__")();
11251126
}
11261127
window["len"] = len
11271128

@@ -1144,7 +1145,7 @@ signature = {"kwargs": Object(), "args": create_array("obj")};
11441145
signature["function_name"] = "next";
11451146
arguments = get_arguments(signature, args, kwargs);
11461147
var obj = arguments['obj'];
1147-
return get_attribute(get_attribute(obj, "next"), "__call__")(create_array(), Object());
1148+
return get_attribute(get_attribute(obj, "next"), "__call__")();
11481149
}
11491150
window["next"] = next
11501151

@@ -1169,8 +1170,8 @@ signature["function_name"] = "map";
11691170
arguments = get_arguments(signature, args, kwargs);
11701171
var func = arguments['func'];
11711172
var objs = arguments['objs'];
1172-
out = get_attribute(list, "__call__")(create_array(), Object());
1173-
set_attribute(out, "js_object", get_attribute(map, "__call__")([func, get_attribute(objs, "js_object")], Object()));
1173+
out = get_attribute(list, "__call__")();
1174+
set_attribute(out, "js_object", map([func, get_attribute(objs, "js_object")], __NULL_OBJECT__));
11741175
return out;
11751176
}
11761177
window["map"] = map
@@ -1355,7 +1356,7 @@ var obj = arguments['obj'];
13551356
var index = arguments['index'];
13561357
self["__dict__"]["obj"] = obj;
13571358
self["__dict__"]["index"] = index;
1358-
self["__dict__"]["length"] = get_attribute(len, "__call__")([obj], Object());
1359+
self["__dict__"]["length"] = len([obj], __NULL_OBJECT__);
13591360
self["__dict__"]["obj_get"] = get_attribute(obj, "get");
13601361
}
13611362
window["__Iterator___init__"] = __Iterator___init__
@@ -1382,7 +1383,7 @@ signature["function_name"] = "__Iterator_next";
13821383
arguments = get_arguments(signature, args, kwargs);
13831384
var self = arguments['self'];
13841385
index = self["__dict__"]["index"];
1385-
length = get_attribute(len, "__call__")([self["__dict__"]["obj"]], Object());
1386+
length = len([self["__dict__"]["obj"]], __NULL_OBJECT__);
13861387
if(index == length) {
13871388
throw StopIteration;
13881389
}
@@ -1459,15 +1460,15 @@ i += 1
14591460
}
14601461
else {
14611462
if(js_object) {
1462-
if(get_attribute(isinstance, "__call__")([js_object, list], Object())) {
1463+
if(isinstance([js_object, list], __NULL_OBJECT__)) {
14631464
self["__dict__"]["js_object"] = get_attribute(get_attribute(get_attribute(js_object, "js_object"), "slice"), "__call__")([0], Object());
14641465
}
14651466
else {
1466-
if(get_attribute(isinstance, "__call__")([js_object, tuple], Object())) {
1467+
if(isinstance([js_object, tuple], __NULL_OBJECT__)) {
14671468
self["__dict__"]["js_object"] = get_attribute(get_attribute(get_attribute(js_object, "js_object"), "slice"), "__call__")([0], Object());
14681469
}
14691470
else {
1470-
if(get_attribute(isinstance, "__call__")([js_object, array], Object())) {
1471+
if(isinstance([js_object, array], __NULL_OBJECT__)) {
14711472
arr = create_array();
14721473
var __iterator__, v;
14731474
__iterator__ = get_attribute(get_attribute(js_object, "__iter__"), "__call__")(create_array(), Object());
@@ -1736,7 +1737,7 @@ if(js_object instanceof Array) {
17361737
set_attribute(self, "js_object", js_object);
17371738
}
17381739
else {
1739-
if(get_attribute(isinstance, "__call__")([js_object, list], Object()) || get_attribute(isinstance, "__call__")([js_object, tuple], Object()) || get_attribute(isinstance, "__call__")([js_object, array], Object())) {
1740+
if(isinstance([js_object, list], __NULL_OBJECT__) || isinstance([js_object, tuple], __NULL_OBJECT__) || isinstance([js_object, array], __NULL_OBJECT__)) {
17401741
set_attribute(self, "js_object", create_array());
17411742
var __iterator__, v;
17421743
__iterator__ = get_attribute(get_attribute(js_object, "__iter__"), "__call__")(create_array(), Object());
@@ -2623,7 +2624,7 @@ arguments = get_arguments(signature, args, kwargs);
26232624
var self = arguments['self'];
26242625
__dict = get_attribute(self, "js_object");
26252626
__keys = Object.keys(__dict);
2626-
out = get_attribute(list, "__call__")(create_array(), Object());
2627+
out = get_attribute(list, "__call__")();
26272628
i = 0;
26282629
while(i < get_attribute(__keys, "length")) {
26292630
get_attribute(get_attribute(out, "append"), "__call__")([__dict[ __keys[i] ]], Object());
@@ -2693,7 +2694,7 @@ signature = {"kwargs": Object(), "args": create_array("self")};
26932694
signature["function_name"] = "__dict___iter__";
26942695
arguments = get_arguments(signature, args, kwargs);
26952696
var self = arguments['self'];
2696-
return get_attribute(Iterator, "__call__")([get_attribute(get_attribute(self, "keys"), "__call__")(create_array(), Object()), 0], Object());
2697+
return get_attribute(Iterator, "__call__")([get_attribute(get_attribute(self, "keys"), "__call__")(), 0], Object());
26972698
}
26982699
window["__dict___iter__"] = __dict___iter__
26992700

@@ -2735,16 +2736,16 @@ self["__dict__"]["typecode"] = typecode;
27352736
self["__dict__"]["itemsize"] = get_attribute(get_attribute(self, "typecodes"), "__getitem__")([typecode], Object());
27362737
self["__dict__"]["little_endian"] = little_endian;
27372738
if(initializer) {
2738-
self["__dict__"]["length"] = get_attribute(len, "__call__")([initializer], Object());
2739+
self["__dict__"]["length"] = len([initializer], __NULL_OBJECT__);
27392740
self["__dict__"]["bytes"] = self["__dict__"]["length"] * self["__dict__"]["itemsize"];
27402741
if(self["__dict__"]["typecode"] == "float8") {
2741-
self["__dict__"]["_scale"] = get_attribute(max, "__call__")([get_attribute(list, "__call__")([], {"js_object": [get_attribute(abs, "__call__")([get_attribute(min, "__call__")([initializer], Object())], Object()), get_attribute(max, "__call__")([initializer], Object())]})], Object());
2742+
self["__dict__"]["_scale"] = max([get_attribute(list, "__call__")([], {"js_object": [abs([min([initializer], __NULL_OBJECT__)], __NULL_OBJECT__), max([initializer], __NULL_OBJECT__)]})], __NULL_OBJECT__);
27422743
self["__dict__"]["_norm_get"] = self["__dict__"]["_scale"] / 127;
27432744
self["__dict__"]["_norm_set"] = 1.0 / self["__dict__"]["_norm_get"];
27442745
}
27452746
else {
27462747
if(self["__dict__"]["typecode"] == "float16") {
2747-
self["__dict__"]["_scale"] = get_attribute(max, "__call__")([get_attribute(list, "__call__")([], {"js_object": [get_attribute(abs, "__call__")([get_attribute(min, "__call__")([initializer], Object())], Object()), get_attribute(max, "__call__")([initializer], Object())]})], Object());
2748+
self["__dict__"]["_scale"] = max([get_attribute(list, "__call__")([], {"js_object": [abs([min([initializer], __NULL_OBJECT__)], __NULL_OBJECT__), max([initializer], __NULL_OBJECT__)]})], __NULL_OBJECT__);
27482749
self["__dict__"]["_norm_get"] = self["__dict__"]["_scale"] / 32767;
27492750
self["__dict__"]["_norm_set"] = 1.0 / self["__dict__"]["_norm_get"];
27502751
}
@@ -2811,7 +2812,7 @@ signature["function_name"] = "__array___contains__";
28112812
arguments = get_arguments(signature, args, kwargs);
28122813
var self = arguments['self'];
28132814
var value = arguments['value'];
2814-
arr = get_attribute(get_attribute(self, "to_array"), "__call__")(create_array(), Object());
2815+
arr = get_attribute(get_attribute(self, "to_array"), "__call__")();
28152816
if(arr.indexOf(value) == -1) {
28162817
return false;
28172818
}
@@ -2994,7 +2995,7 @@ signature["function_name"] = "__array_fromlist";
29942995
arguments = get_arguments(signature, args, kwargs);
29952996
var self = arguments['self'];
29962997
var lst = arguments['lst'];
2997-
length = get_attribute(len, "__call__")([lst], Object());
2998+
length = len([lst], __NULL_OBJECT__);
29982999
step = self["__dict__"]["itemsize"];
29993000
typecode = self["__dict__"]["typecode"];
30003001
size = length * step;
@@ -3176,8 +3177,8 @@ signature = {"kwargs": Object(), "args": create_array("self")};
31763177
signature["function_name"] = "__array_to_list";
31773178
arguments = get_arguments(signature, args, kwargs);
31783179
var self = arguments['self'];
3179-
lst = get_attribute(list, "__call__")(create_array(), Object());
3180-
set_attribute(lst, "js_object", get_attribute(get_attribute(self, "to_array"), "__call__")(create_array(), Object()));
3180+
lst = get_attribute(list, "__call__")();
3181+
set_attribute(lst, "js_object", get_attribute(get_attribute(self, "to_array"), "__call__")());
31813182
return lst;
31823183
}
31833184
window["__array_to_list"] = __array_to_list
@@ -3204,7 +3205,7 @@ signature["function_name"] = "__array_to_ascii";
32043205
arguments = get_arguments(signature, args, kwargs);
32053206
var self = arguments['self'];
32063207
string = "";
3207-
arr = get_attribute(get_attribute(self, "to_array"), "__call__")(create_array(), Object());
3208+
arr = get_attribute(get_attribute(self, "to_array"), "__call__")();
32083209
i = 0;
32093210
length = get_attribute(arr, "length");
32103211
while(i < length) {
@@ -3250,8 +3251,8 @@ return json;
32503251
}
32513252

32523253
if(Object.prototype.toString.call(json) === '[object Array]') {
3253-
output = get_attribute(list, "__call__")(create_array(), Object());
3254-
raw = get_attribute(list, "__call__")(create_array(), Object());
3254+
output = get_attribute(list, "__call__")();
3255+
raw = get_attribute(list, "__call__")();
32553256
set_attribute(raw, "js_object", json);
32563257
var append;
32573258
append = get_attribute(output, "append");
@@ -3261,23 +3262,23 @@ var __next__;
32613262
__next__ = get_attribute(__iterator__, "next_fast");
32623263
while(__iterator__.__dict__.index < __iterator__.__dict__.length) {
32633264
item = __next__();
3264-
get_attribute(append, "__call__")([get_attribute(_to_pythonjs, "__call__")([item], Object())], Object());
3265+
get_attribute(append, "__call__")([_to_pythonjs([item], __NULL_OBJECT__)], Object());
32653266
}
32663267
return output;
32673268
}
32683269

3269-
output = get_attribute(dict, "__call__")(create_array(), Object());
3270+
output = get_attribute(dict, "__call__")();
32703271
var set;
32713272
set = get_attribute(output, "set");
3272-
keys = get_attribute(list, "__call__")(create_array(), Object());
3273+
keys = get_attribute(list, "__call__")();
32733274
set_attribute(keys, "js_object", Object.keys(json));
32743275
var __iterator__, key;
32753276
__iterator__ = get_attribute(get_attribute(keys, "__iter__"), "__call__")(create_array(), Object());
32763277
var __next__;
32773278
__next__ = get_attribute(__iterator__, "next_fast");
32783279
while(__iterator__.__dict__.index < __iterator__.__dict__.length) {
32793280
key = __next__();
3280-
get_attribute(set, "__call__")([key, get_attribute(_to_pythonjs, "__call__")([json[key]], Object())], Object());
3281+
get_attribute(set, "__call__")([key, _to_pythonjs([json[key]], __NULL_OBJECT__)], Object());
32813282
}
32823283
return output;
32833284
}
@@ -3302,7 +3303,7 @@ signature = {"kwargs": Object(), "args": create_array("json")};
33023303
signature["function_name"] = "json_to_pythonjs";
33033304
arguments = get_arguments(signature, args, kwargs);
33043305
var json = arguments['json'];
3305-
return get_attribute(_to_pythonjs, "__call__")([get_attribute(get_attribute(JSON, "parse"), "__call__")([json], Object())], Object());
3306+
return _to_pythonjs([get_attribute(get_attribute(JSON, "parse"), "__call__")([json], Object())], __NULL_OBJECT__);
33063307
}
33073308
window["json_to_pythonjs"] = json_to_pythonjs
33083309

@@ -3326,29 +3327,29 @@ signature = {"kwargs": Object(), "args": create_array("pythonjs")};
33263327
signature["function_name"] = "_to_json";
33273328
arguments = get_arguments(signature, args, kwargs);
33283329
var pythonjs = arguments['pythonjs'];
3329-
if(get_attribute(isinstance, "__call__")([pythonjs, list], Object())) {
3330+
if(isinstance([pythonjs, list], __NULL_OBJECT__)) {
33303331
r = create_array();
33313332
var __iterator__, i;
33323333
__iterator__ = get_attribute(get_attribute(pythonjs, "__iter__"), "__call__")(create_array(), Object());
33333334
var __next__;
33343335
__next__ = get_attribute(__iterator__, "next_fast");
33353336
while(__iterator__.__dict__.index < __iterator__.__dict__.length) {
33363337
i = __next__();
3337-
get_attribute(get_attribute(r, "push"), "__call__")([get_attribute(_to_json, "__call__")([i], Object())], Object());
3338+
get_attribute(get_attribute(r, "push"), "__call__")([_to_json([i], __NULL_OBJECT__)], Object());
33383339
}
33393340
}
33403341
else {
3341-
if(get_attribute(isinstance, "__call__")([pythonjs, dict], Object())) {
3342+
if(isinstance([pythonjs, dict], __NULL_OBJECT__)) {
33423343
var r;
33433344
r = Object();
33443345
var __iterator__, key;
3345-
__iterator__ = get_attribute(get_attribute(get_attribute(get_attribute(pythonjs, "keys"), "__call__")(create_array(), Object()), "__iter__"), "__call__")(create_array(), Object());
3346+
__iterator__ = get_attribute(get_attribute(get_attribute(get_attribute(pythonjs, "keys"), "__call__")(), "__iter__"), "__call__")(create_array(), Object());
33463347
var __next__;
33473348
__next__ = get_attribute(__iterator__, "next_fast");
33483349
while(__iterator__.__dict__.index < __iterator__.__dict__.length) {
33493350
key = __next__();
3350-
value = get_attribute(_to_json, "__call__")([get_attribute(get_attribute(pythonjs, "get"), "__call__")([key], Object())], Object());
3351-
key = get_attribute(_to_json, "__call__")([key], Object());
3351+
value = _to_json([get_attribute(get_attribute(pythonjs, "get"), "__call__")([key], Object())], __NULL_OBJECT__);
3352+
key = _to_json([key], __NULL_OBJECT__);
33523353
r[ key ] = value;
33533354
}
33543355
}
@@ -3381,7 +3382,7 @@ signature = {"kwargs": Object(), "args": create_array("pythonjs")};
33813382
signature["function_name"] = "pythonjs_to_json";
33823383
arguments = get_arguments(signature, args, kwargs);
33833384
var pythonjs = arguments['pythonjs'];
3384-
return get_attribute(get_attribute(JSON, "stringify"), "__call__")([get_attribute(_to_json, "__call__")([pythonjs], Object())], Object());
3385+
return get_attribute(get_attribute(JSON, "stringify"), "__call__")([_to_json([pythonjs], __NULL_OBJECT__)], Object());
33853386
}
33863387
window["pythonjs_to_json"] = pythonjs_to_json
33873388

0 commit comments

Comments
 (0)