Skip to content

Commit

Permalink
Units example expanded, Python 3.5 compatibility fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
JdeH committed Feb 20, 2018
1 parent 120159e commit 568415d
Show file tree
Hide file tree
Showing 22 changed files with 361 additions and 81 deletions.
4 changes: 3 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ Each release, on the other hand, is preceded by at least the following tests:
What's new in the latest commits
================================

- Units, making it possible to create compact native JavaScript component frameworks with Transcrypt.
- Unit example expanded to show combination of units and modules, docs adapted accordingly
- Python 3.5 imcompatibility bug fixed
- Units, making it possible to create compact native JavaScript component frameworks with Transcrypt
- String formatting mini language added as an option (-sf / --sform switch) + autotest
- Div internal improvements and fixes
- Time module made suitable for use in combination with Node.js
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"use strict";
// Transcrypt'ed from Python, 2018-02-20 19:59:17
// Transcrypt'ed from Python, 2018-02-20 20:51:46
function animals () {
var __symbols__ = ['__runit__', '__py3.6__', '__esv5__'];
var __all__ = {};
Expand Down Expand Up @@ -141,7 +141,7 @@ function animals () {
get __init__ () {return __get__ (this, function (self) {
self.interpreter_name = 'python';
self.transpiler_name = 'transcrypt';
self.transpiler_version = '3.6.97';
self.transpiler_version = '3.6.98';
self.target_subdir = '__javascript__';
});}
});
Expand Down Expand Up @@ -389,6 +389,123 @@ function animals () {
return __accu0__;
}) ();
};
var complex = __class__ ('complex', [object], {
__module__: __name__,
get __init__ () {return __get__ (this, function (self, real, imag) {
if (typeof imag == 'undefined' || (imag != null && imag .hasOwnProperty ("__kwargtrans__"))) {;
var imag = null;
};
if (imag == null) {
if (py_typeof (real) == complex) {
self.real = real.real;
self.imag = real.imag;
}
else {
self.real = real;
self.imag = 0;
}
}
else {
self.real = real;
self.imag = imag;
}
});},
get __neg__ () {return __get__ (this, function (self) {
return complex (-(self.real), -(self.imag));
});},
get __exp__ () {return __get__ (this, function (self) {
var modulus = Math.exp (self.real);
return complex (modulus * Math.cos (self.imag), modulus * Math.sin (self.imag));
});},
get __log__ () {return __get__ (this, function (self) {
return complex (Math.log (Math.sqrt (self.real * self.real + self.imag * self.imag)), Math.atan2 (self.imag, self.real));
});},
get __pow__ () {return __get__ (this, function (self, other) {
return self.__log__ ().__mul__ (other).__exp__ ();
});},
get __rpow__ () {return __get__ (this, function (self, real) {
return self.__mul__ (Math.log (real)).__exp__ ();
});},
get __mul__ () {return __get__ (this, function (self, other) {
if (typeof other === 'number') {
return complex (self.real * other, self.imag * other);
}
else {
return complex (self.real * other.real - self.imag * other.imag, self.real * other.imag + self.imag * other.real);
}
});},
get __rmul__ () {return __get__ (this, function (self, real) {
return complex (self.real * real, self.imag * real);
});},
get __div__ () {return __get__ (this, function (self, other) {
if (typeof other === 'number') {
return complex (self.real / other, self.imag / other);
}
else {
var denom = other.real * other.real + other.imag * other.imag;
return complex ((self.real * other.real + self.imag * other.imag) / denom, (self.imag * other.real - self.real * other.imag) / denom);
}
});},
get __rdiv__ () {return __get__ (this, function (self, real) {
var denom = self.real * self.real;
return complex ((real * self.real) / denom, (real * self.imag) / denom);
});},
get __add__ () {return __get__ (this, function (self, other) {
if (typeof other === 'number') {
return complex (self.real + other, self.imag);
}
else {
return complex (self.real + other.real, self.imag + other.imag);
}
});},
get __radd__ () {return __get__ (this, function (self, real) {
return complex (self.real + real, self.imag);
});},
get __sub__ () {return __get__ (this, function (self, other) {
if (typeof other === 'number') {
return complex (self.real - other, self.imag);
}
else {
return complex (self.real - other.real, self.imag - other.imag);
}
});},
get __rsub__ () {return __get__ (this, function (self, real) {
return complex (real - self.real, -(self.imag));
});},
get __repr__ () {return __get__ (this, function (self) {
return '({}{}{}j)'.format (self.real, (self.imag >= 0 ? '+' : ''), self.imag);
});},
get __str__ () {return __get__ (this, function (self) {
return __repr__ (self).__getslice__ (1, -(1), 1);
});},
get __eq__ () {return __get__ (this, function (self, other) {
if (typeof other === 'number') {
return self.real == other;
}
else {
return self.real == other.real && self.imag == other.imag;
}
});},
get __ne__ () {return __get__ (this, function (self, other) {
if (typeof other === 'number') {
return self.real != other;
}
else {
return self.real != other.real || self.imag != other.imag;
}
});},
get conjugate () {return __get__ (this, function (self) {
return complex (self.real, -(self.imag));
});}
});
var __conj__ = function (aNumber) {
if (isinstance (aNumber, complex)) {
return complex (aNumber.real, -(aNumber.imag));
}
else {
return complex (aNumber, 0);
}
};
var __Terminal__ = __class__ ('__Terminal__', [object], {
__module__: __name__,
get __init__ () {return __get__ (this, function (self) {
Expand Down Expand Up @@ -489,9 +606,11 @@ function animals () {
__all__.ValueError = ValueError;
__all__.Warning = Warning;
__all__.__Terminal__ = __Terminal__;
__all__.__conj__ = __conj__;
__all__.__name__ = __name__;
__all__.__sort__ = __sort__;
__all__.__terminal__ = __terminal__;
__all__.complex = complex;
__all__.filter = filter;
__all__.map = map;
__all__.sorted = sorted;
Expand Down Expand Up @@ -2200,8 +2319,27 @@ function animals () {
}
};
__all__.__setslice__ = __setslice__;
__nest__ (
__all__,
'animals_submodule', {
__all__: {
__inited__: false,
__init__: function (__all__) {
var __name__ = 'animals_submodule';
var getTaxoTag = function () {
return 'animal';
};
__pragma__ ('<all>')
__all__.__name__ = __name__;
__all__.getTaxoTag = getTaxoTag;
__pragma__ ('</all>')
}
}
}
);
(function () {
var __name__ = '__main__';
var asm = __init__ (__world__.animals_submodule);
var _individuals = dict ({});
var find = function (py_name) {
return _individuals [py_name];
Expand All @@ -2214,7 +2352,7 @@ function animals () {
self.food = food;
self.sound = sound;
self.fed = false;
document.getElementById (self.py_name).innerHTML = self.speak ('I was born just now!');
document.getElementById (self.py_name).innerHTML = self.speak ('I was born just now! My kingdom is: {}. My species is {}'.format (asm.getTaxoTag (), self.species));
});},
get speak () {return __get__ (this, function (self, text) {
return '{} says: '.format (self.py_name) + text;
Expand All @@ -2228,6 +2366,9 @@ function animals () {
self.fed = false;
});}
});
__pragma__ ('<use>' +
'animals_submodule' +
'</use>')
__pragma__ ('<all>')
__all__.Animal = Animal;
__all__.__name__ = __name__;
Expand All @@ -2236,7 +2377,6 @@ function animals () {
__pragma__ ('</all>')
__pragma__ ('<components>')
}) ();

return __all__;
}
window ['animals'] = animals ();
Loading

0 comments on commit 568415d

Please sign in to comment.